-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/WAL-7939' into 'develop'
[WAL-7939] Drop draft-js (deprecated), migrate to markdown editors See merge request waldur/waldur-homeport!5410
- Loading branch information
Showing
10 changed files
with
2,337 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.mdxeditor { | ||
.mdxeditor-source-editor .cm-scroller, | ||
.mdxeditor-diff-editor, | ||
.editable-area { | ||
min-height: 200px; | ||
max-height: 400px; | ||
height: calc(100vh - 325px); | ||
overflow-y: auto; | ||
} | ||
} | ||
|
||
.mdxeditor-popup-container { | ||
z-index: 2000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { | ||
MDXEditor, | ||
headingsPlugin, | ||
listsPlugin, | ||
quotePlugin, | ||
thematicBreakPlugin, | ||
toolbarPlugin, | ||
UndoRedo, | ||
BoldItalicUnderlineToggles, | ||
BlockTypeSelect, | ||
ChangeCodeMirrorLanguage, | ||
CodeToggle, | ||
CreateLink, | ||
InsertCodeBlock, | ||
InsertTable, | ||
InsertThematicBreak, | ||
ListsToggle, | ||
linkPlugin, | ||
linkDialogPlugin, | ||
tablePlugin, | ||
codeBlockPlugin, | ||
codeMirrorPlugin, | ||
markdownShortcutPlugin, | ||
ConditionalContents, | ||
Separator, | ||
StrikeThroughSupSubToggles, | ||
diffSourcePlugin, | ||
DiffSourceToggleWrapper, | ||
} from '@mdxeditor/editor'; | ||
import { FC, useRef } from 'react'; | ||
|
||
import { FormField } from './types'; | ||
|
||
import '@mdxeditor/editor/style.css'; | ||
import './MarkdownEditor.scss'; | ||
|
||
interface MarkdownEditorProps extends FormField { | ||
placeholder?: string; | ||
className?: string; | ||
} | ||
|
||
const Toolbar = () => { | ||
return ( | ||
<DiffSourceToggleWrapper> | ||
<ConditionalContents | ||
options={[ | ||
{ | ||
when: (editor) => editor?.editorType === 'codeblock', | ||
contents: () => <ChangeCodeMirrorLanguage />, | ||
}, | ||
{ | ||
fallback: () => ( | ||
<> | ||
<UndoRedo /> | ||
|
||
<Separator /> | ||
<BoldItalicUnderlineToggles /> | ||
<CodeToggle /> | ||
|
||
<Separator /> | ||
<StrikeThroughSupSubToggles /> | ||
|
||
<Separator /> | ||
<ListsToggle /> | ||
|
||
<Separator /> | ||
<BlockTypeSelect /> | ||
|
||
<Separator /> | ||
<CreateLink /> | ||
|
||
<Separator /> | ||
<InsertTable /> | ||
<InsertThematicBreak /> | ||
|
||
<Separator /> | ||
<InsertCodeBlock /> | ||
</> | ||
), | ||
}, | ||
]} | ||
/> | ||
</DiffSourceToggleWrapper> | ||
); | ||
}; | ||
|
||
const MarkdownEditor: FC<MarkdownEditorProps> = (props) => { | ||
const initialValue = useRef(props.input?.value); | ||
|
||
return ( | ||
<MDXEditor | ||
className={props.className} | ||
contentEditableClassName="editable-area" | ||
markdown={props.input?.value || ''} | ||
autoFocus={props.autoFocus} | ||
placeholder={props.placeholder} | ||
onChange={props.input?.onChange} | ||
plugins={[ | ||
toolbarPlugin({ toolbarContents: () => <Toolbar /> }), | ||
listsPlugin(), | ||
quotePlugin(), | ||
headingsPlugin(), | ||
linkPlugin(), | ||
linkDialogPlugin(), | ||
tablePlugin(), | ||
thematicBreakPlugin(), | ||
codeBlockPlugin({ defaultCodeBlockLanguage: '' }), | ||
codeMirrorPlugin({ | ||
codeBlockLanguages: { | ||
py: 'Python', | ||
java: 'Java', | ||
js: 'JavaScript', | ||
tsx: 'TypeScript', | ||
php: 'PHP', | ||
txt: 'Plain Text', | ||
'': 'Unspecified', | ||
}, | ||
}), | ||
markdownShortcutPlugin(), | ||
diffSourcePlugin({ | ||
viewMode: 'rich-text', | ||
readOnlyDiff: true, | ||
diffMarkdown: initialValue.current, | ||
}), | ||
]} | ||
/> | ||
); | ||
}; | ||
|
||
export default MarkdownEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.