5htp-core 0.4.8 → 0.4.9-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -1
- package/src/client/assets/css/components/table.less +3 -0
- package/src/client/components/Form.ts +2 -6
- package/src/client/components/Table/index.tsx +24 -79
- package/src/client/components/button.tsx +2 -1
- package/src/client/components/containers/Popover/index.tsx +2 -2
- package/src/client/components/dropdown/index.tsx +16 -6
- package/src/client/components/input/Slider/index.tsx +0 -2
- package/src/client/components/inputv3/Rte/Editor.tsx +271 -0
- package/src/client/components/inputv3/Rte/ToolbarPlugin/BlockFormat.tsx +220 -0
- package/src/client/components/inputv3/Rte/ToolbarPlugin/ElementFormat.tsx +107 -0
- package/src/client/components/inputv3/Rte/ToolbarPlugin/index.tsx +768 -0
- package/src/client/components/inputv3/Rte/appSettings.ts +36 -0
- package/src/client/components/inputv3/Rte/context/FlashMessageContext.tsx +68 -0
- package/src/client/components/inputv3/Rte/context/SettingsContext.tsx +71 -0
- package/src/client/components/inputv3/Rte/context/SharedAutocompleteContext.tsx +71 -0
- package/src/client/components/inputv3/Rte/context/SharedHistoryContext.tsx +35 -0
- package/src/client/components/inputv3/Rte/currentEditor.ts +42 -0
- package/src/client/components/inputv3/Rte/hooks/useFlashMessage.tsx +16 -0
- package/src/client/components/inputv3/Rte/hooks/useReport.ts +67 -0
- package/src/client/components/inputv3/Rte/images/emoji/1F600.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/1F641.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/1F642.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/2764.png +0 -0
- package/src/client/components/inputv3/Rte/images/emoji/LICENSE.md +5 -0
- package/src/client/components/inputv3/Rte/images/icons/draggable-block-menu.svg +1 -0
- package/src/client/components/inputv3/Rte/images/icons/prettier-error.svg +1 -0
- package/src/client/components/inputv3/Rte/images/icons/prettier.svg +1 -0
- package/src/client/components/inputv3/Rte/images/image/LICENSE.md +5 -0
- package/src/client/components/inputv3/Rte/images/image-broken.svg +4 -0
- package/src/client/components/inputv3/Rte/images/logo.svg +1 -0
- package/src/client/components/inputv3/Rte/index.tsx +63 -79
- package/src/client/components/inputv3/Rte/nodes/AutocompleteNode.tsx +119 -0
- package/src/client/components/inputv3/Rte/nodes/EmojiNode.tsx +102 -0
- package/src/client/components/inputv3/Rte/nodes/EquationComponent.tsx +141 -0
- package/src/client/components/inputv3/Rte/nodes/EquationNode.tsx +174 -0
- package/src/client/components/inputv3/Rte/nodes/FigmaNode.tsx +135 -0
- package/src/client/components/inputv3/Rte/nodes/ImageComponent.tsx +468 -0
- package/src/client/components/inputv3/Rte/nodes/ImageNode.css +43 -0
- package/src/client/components/inputv3/Rte/nodes/ImageNode.tsx +266 -0
- package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageComponent.tsx +402 -0
- package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.css +94 -0
- package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.tsx +294 -0
- package/src/client/components/inputv3/Rte/nodes/KeywordNode.ts +67 -0
- package/src/client/components/inputv3/Rte/nodes/LayoutContainerNode.ts +137 -0
- package/src/client/components/inputv3/Rte/nodes/LayoutItemNode.ts +71 -0
- package/src/client/components/inputv3/Rte/nodes/MentionNode.ts +130 -0
- package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.css +62 -0
- package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.tsx +170 -0
- package/src/client/components/inputv3/Rte/nodes/PlaygroundNodes.ts +76 -0
- package/src/client/components/inputv3/Rte/nodes/PollComponent.tsx +249 -0
- package/src/client/components/inputv3/Rte/nodes/PollNode.css +187 -0
- package/src/client/components/inputv3/Rte/nodes/PollNode.tsx +209 -0
- package/src/client/components/inputv3/Rte/nodes/StickyComponent.tsx +261 -0
- package/src/client/components/inputv3/Rte/nodes/StickyNode.css +37 -0
- package/src/client/components/inputv3/Rte/nodes/StickyNode.tsx +150 -0
- package/src/client/components/inputv3/Rte/nodes/TweetNode.tsx +223 -0
- package/src/client/components/inputv3/Rte/nodes/YouTubeNode.tsx +184 -0
- package/src/client/components/inputv3/Rte/plugins/ActionsPlugin/index.tsx +334 -0
- package/src/client/components/inputv3/Rte/plugins/AutoEmbedPlugin/index.tsx +352 -0
- package/src/client/components/inputv3/Rte/plugins/AutoLinkPlugin/index.tsx +32 -0
- package/src/client/components/inputv3/Rte/plugins/AutocompletePlugin/index.tsx +2529 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +70 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +14 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +156 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.css +54 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.tsx +190 -0
- package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/utils.ts +33 -0
- package/src/client/components/inputv3/Rte/plugins/CodeHighlightPlugin/index.ts +21 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/Collapsible.css +57 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts +168 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContentNode.ts +127 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts +152 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleUtils.ts +17 -0
- package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/index.ts +284 -0
- package/src/client/components/inputv3/Rte/plugins/ComponentPickerPlugin/index.tsx +370 -0
- package/src/client/components/inputv3/Rte/plugins/ContextMenuPlugin/index.tsx +270 -0
- package/src/client/components/inputv3/Rte/plugins/DocsPlugin/index.tsx +20 -0
- package/src/client/components/inputv3/Rte/plugins/DragDropPastePlugin/index.ts +51 -0
- package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.css +36 -0
- package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.tsx +43 -0
- package/src/client/components/inputv3/Rte/plugins/EmojiPickerPlugin/index.tsx +198 -0
- package/src/client/components/inputv3/Rte/plugins/EmojisPlugin/index.ts +75 -0
- package/src/client/components/inputv3/Rte/plugins/EquationsPlugin/index.tsx +82 -0
- package/src/client/components/inputv3/Rte/plugins/FigmaPlugin/index.tsx +40 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.css +41 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.tsx +393 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.css +141 -0
- package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.tsx +388 -0
- package/src/client/components/inputv3/Rte/plugins/ImagesPlugin/index.tsx +350 -0
- package/src/client/components/inputv3/Rte/plugins/InlineImagePlugin/index.tsx +336 -0
- package/src/client/components/inputv3/Rte/plugins/KeywordsPlugin/index.ts +56 -0
- package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/InsertLayoutDialog.tsx +58 -0
- package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/LayoutPlugin.tsx +219 -0
- package/src/client/components/inputv3/Rte/plugins/LinkPlugin/index.tsx +34 -0
- package/src/client/components/inputv3/Rte/plugins/ListMaxIndentLevelPlugin/index.ts +85 -0
- package/src/client/components/inputv3/Rte/plugins/MarkdownShortcutPlugin/index.tsx +16 -0
- package/src/client/components/inputv3/Rte/plugins/MarkdownTransformers/index.ts +324 -0
- package/src/client/components/inputv3/Rte/plugins/MaxLengthPlugin/index.tsx +53 -0
- package/src/client/components/inputv3/Rte/plugins/MentionsPlugin/index.tsx +696 -0
- package/src/client/components/inputv3/Rte/plugins/PageBreakPlugin/index.tsx +57 -0
- package/src/client/components/inputv3/Rte/plugins/PasteLogPlugin/index.tsx +54 -0
- package/src/client/components/inputv3/Rte/plugins/PollPlugin/index.tsx +86 -0
- package/src/client/components/inputv3/Rte/plugins/SpeechToTextPlugin/index.ts +125 -0
- package/src/client/components/inputv3/Rte/plugins/StickyPlugin/index.ts +22 -0
- package/src/client/components/inputv3/Rte/plugins/TabFocusPlugin/index.tsx +65 -0
- package/src/client/components/inputv3/Rte/plugins/TableActionMenuPlugin/index.tsx +773 -0
- package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.css +12 -0
- package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.tsx +436 -0
- package/src/client/components/inputv3/Rte/plugins/TableHoverActionsPlugin/index.tsx +287 -0
- package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.css +95 -0
- package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.tsx +197 -0
- package/src/client/components/inputv3/Rte/plugins/TablePlugin.tsx +178 -0
- package/src/client/components/inputv3/Rte/plugins/TestRecorderPlugin/index.tsx +468 -0
- package/src/client/components/inputv3/Rte/plugins/TreeViewPlugin/index.tsx +26 -0
- package/src/client/components/inputv3/Rte/plugins/TwitterPlugin/index.ts +41 -0
- package/src/client/components/inputv3/Rte/plugins/TypingPerfPlugin/index.ts +117 -0
- package/src/client/components/inputv3/Rte/plugins/YouTubePlugin/index.ts +41 -0
- package/src/client/components/inputv3/Rte/shared/canUseDOM.ts +4 -0
- package/src/client/components/inputv3/Rte/shared/caretFromPoint.ts +40 -0
- package/src/client/components/inputv3/Rte/shared/environment.ts +56 -0
- package/src/client/components/inputv3/Rte/shared/invariant.ts +26 -0
- package/src/client/components/inputv3/Rte/shared/normalizeClassNames.ts +21 -0
- package/src/client/components/inputv3/Rte/shared/react-test-utils.ts +18 -0
- package/src/client/components/inputv3/Rte/shared/reactPatches.ts +22 -0
- package/src/client/components/inputv3/Rte/shared/simpleDiffWithCursor.ts +49 -0
- package/src/client/components/inputv3/Rte/shared/useLayoutEffect.ts +19 -0
- package/src/client/components/inputv3/Rte/shared/warnOnlyOnce.ts +20 -0
- package/src/client/components/inputv3/Rte/style.less +30 -60
- package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.css +13 -0
- package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.ts +20 -0
- package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.css +447 -0
- package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.ts +120 -0
- package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.css +13 -0
- package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.ts +20 -0
- package/src/client/components/inputv3/Rte/ui/ColorPicker.css +88 -0
- package/src/client/components/inputv3/Rte/ui/ColorPicker.tsx +365 -0
- package/src/client/components/inputv3/Rte/ui/ContentEditable.css +44 -0
- package/src/client/components/inputv3/Rte/ui/ContentEditable.tsx +36 -0
- package/src/client/components/inputv3/Rte/ui/DropDown.tsx +259 -0
- package/src/client/components/inputv3/Rte/ui/DropdownColorPicker.tsx +41 -0
- package/src/client/components/inputv3/Rte/ui/EquationEditor.css +38 -0
- package/src/client/components/inputv3/Rte/ui/EquationEditor.tsx +56 -0
- package/src/client/components/inputv3/Rte/ui/FileInput.tsx +38 -0
- package/src/client/components/inputv3/Rte/ui/FlashMessage.css +28 -0
- package/src/client/components/inputv3/Rte/ui/FlashMessage.tsx +29 -0
- package/src/client/components/inputv3/Rte/ui/ImageResizer.tsx +316 -0
- package/src/client/components/inputv3/Rte/ui/Input.css +32 -0
- package/src/client/components/inputv3/Rte/ui/KatexRenderer.tsx +54 -0
- package/src/client/components/inputv3/Rte/ui/Switch.tsx +36 -0
- package/src/client/components/inputv3/Rte/utils/docSerialization.ts +77 -0
- package/src/client/components/inputv3/Rte/utils/emoji-list.ts +16615 -0
- package/src/client/components/inputv3/Rte/utils/getDOMRangeRect.ts +27 -0
- package/src/client/components/inputv3/Rte/utils/getSelectedNode.ts +27 -0
- package/src/client/components/inputv3/Rte/utils/guard.ts +10 -0
- package/src/client/components/inputv3/Rte/utils/isMobileWidth.ts +7 -0
- package/src/client/components/inputv3/Rte/utils/joinClasses.ts +13 -0
- package/src/client/components/inputv3/Rte/utils/setFloatingElemPosition.ts +51 -0
- package/src/client/components/inputv3/Rte/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
- package/src/client/components/inputv3/Rte/utils/swipe.ts +127 -0
- package/src/client/components/inputv3/Rte/utils/url.ts +38 -0
- package/src/client/components/inputv3/base.tsx +10 -7
- package/src/client/components/inputv3/file/index.tsx +11 -5
- package/src/client/components/inputv3/index.tsx +2 -2
- package/src/common/data/rte/nodes.ts +60 -9
- package/src/common/validation/index.ts +21 -2
- package/src/common/validation/schema.ts +34 -11
- package/src/common/validation/validator.ts +12 -4
- package/src/common/validation/validators.ts +112 -63
- package/src/server/services/router/http/multipart.ts +0 -1
- package/src/server/services/router/request/index.ts +1 -1
- package/src/server/services/schema/index.ts +26 -4
- package/src/server/services/schema/request.ts +3 -2
- package/src/server/services/schema/rte.ts +110 -0
- package/src/{common/data/rte/index.ts → server/utils/rte.ts} +27 -16
- package/src/client/components/inputv3/Rte/ExampleTheme.tsx +0 -42
- package/src/client/components/inputv3/Rte/ToolbarPlugin.tsx +0 -167
- package/src/client/components/inputv3/Rte/icons/LICENSE.md +0 -5
- package/src/client/components/inputv3/Rte/icons/arrow-clockwise.svg +0 -4
- package/src/client/components/inputv3/Rte/icons/arrow-counterclockwise.svg +0 -4
- package/src/client/components/inputv3/Rte/icons/journal-text.svg +0 -5
- package/src/client/components/inputv3/Rte/icons/justify.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-center.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-left.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-paragraph.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/text-right.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-bold.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-italic.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-strikethrough.svg +0 -3
- package/src/client/components/inputv3/Rte/icons/type-underline.svg +0 -3
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// npm
|
|
6
|
+
import React, { JSX } from 'react';
|
|
7
|
+
import {
|
|
8
|
+
$createParagraphNode,
|
|
9
|
+
$getSelection,
|
|
10
|
+
$isRangeSelection,
|
|
11
|
+
LexicalEditor,
|
|
12
|
+
} from 'lexical';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
$setBlocksType,
|
|
16
|
+
} from '@lexical/selection';
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
$createHeadingNode,
|
|
20
|
+
$createQuoteNode,
|
|
21
|
+
HeadingTagType,
|
|
22
|
+
} from '@lexical/rich-text';
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
INSERT_CHECK_LIST_COMMAND,
|
|
26
|
+
INSERT_ORDERED_LIST_COMMAND,
|
|
27
|
+
INSERT_UNORDERED_LIST_COMMAND,
|
|
28
|
+
} from '@lexical/list';
|
|
29
|
+
|
|
30
|
+
import {
|
|
31
|
+
$createCodeNode,
|
|
32
|
+
} from '@lexical/code';
|
|
33
|
+
|
|
34
|
+
// Core
|
|
35
|
+
import Button from '@client/components/button';
|
|
36
|
+
import DropDown from '@client/components/dropdown';
|
|
37
|
+
|
|
38
|
+
/*----------------------------------
|
|
39
|
+
- TYPES
|
|
40
|
+
----------------------------------*/
|
|
41
|
+
|
|
42
|
+
const formatParagraph = (editor: LexicalEditor) => {
|
|
43
|
+
editor.update(() => {
|
|
44
|
+
const selection = $getSelection();
|
|
45
|
+
if ($isRangeSelection(selection)) {
|
|
46
|
+
$setBlocksType(selection, () => $createParagraphNode());
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const formatHeading = (headingSize: HeadingTagType) => (editor: LexicalEditor, blockType: typeof blockTypeNames[number]) => {
|
|
52
|
+
if (blockType !== headingSize) {
|
|
53
|
+
editor.update(() => {
|
|
54
|
+
const selection = $getSelection();
|
|
55
|
+
$setBlocksType(selection, () => $createHeadingNode(headingSize));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const formatBulletList = (editor: LexicalEditor, blockType: typeof blockTypeNames[number]) => {
|
|
61
|
+
if (blockType !== 'bullet') {
|
|
62
|
+
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
|
|
63
|
+
} else {
|
|
64
|
+
formatParagraph(editor);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const formatCheckList = (editor: LexicalEditor, blockType: typeof blockTypeNames[number]) => {
|
|
69
|
+
if (blockType !== 'check') {
|
|
70
|
+
editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined);
|
|
71
|
+
} else {
|
|
72
|
+
formatParagraph(editor);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const formatNumberedList = (editor: LexicalEditor, blockType: typeof blockTypeNames[number]) => {
|
|
77
|
+
if (blockType !== 'number') {
|
|
78
|
+
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
|
|
79
|
+
} else {
|
|
80
|
+
formatParagraph(editor);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const formatQuote = (editor: LexicalEditor, blockType: typeof blockTypeNames[number]) => {
|
|
85
|
+
if (blockType !== 'quote') {
|
|
86
|
+
editor.update(() => {
|
|
87
|
+
const selection = $getSelection();
|
|
88
|
+
$setBlocksType(selection, () => $createQuoteNode());
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const formatCode = (editor: LexicalEditor, blockType: typeof blockTypeNames[number]) => {
|
|
94
|
+
if (blockType !== 'code') {
|
|
95
|
+
editor.update(() => {
|
|
96
|
+
let selection = $getSelection();
|
|
97
|
+
|
|
98
|
+
if (selection !== null) {
|
|
99
|
+
if (selection.isCollapsed()) {
|
|
100
|
+
$setBlocksType(selection, () => $createCodeNode());
|
|
101
|
+
} else {
|
|
102
|
+
const textContent = selection.getTextContent();
|
|
103
|
+
const codeNode = $createCodeNode();
|
|
104
|
+
selection.insertNodes([codeNode]);
|
|
105
|
+
selection = $getSelection();
|
|
106
|
+
if ($isRangeSelection(selection)) {
|
|
107
|
+
selection.insertRawText(textContent);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const blockTypes: {
|
|
116
|
+
label: string;
|
|
117
|
+
value: string;
|
|
118
|
+
icon: string;
|
|
119
|
+
onClick: (editor: LexicalEditor, blockType: string) => void;
|
|
120
|
+
}[] = [{
|
|
121
|
+
label: 'Bulleted List',
|
|
122
|
+
value: 'bullet',
|
|
123
|
+
icon: /* @icon */'list-ul',
|
|
124
|
+
onClick: formatBulletList,
|
|
125
|
+
}, {
|
|
126
|
+
label: 'Check List',
|
|
127
|
+
value: 'check',
|
|
128
|
+
icon: /* @icon */'check-square',
|
|
129
|
+
onClick: formatCheckList,
|
|
130
|
+
}, {
|
|
131
|
+
label: 'Code Block',
|
|
132
|
+
value: 'code',
|
|
133
|
+
icon: /* @icon */'code',
|
|
134
|
+
onClick: formatCode,
|
|
135
|
+
}, {
|
|
136
|
+
label: 'Heading 1',
|
|
137
|
+
value: 'h1',
|
|
138
|
+
icon: /* @icon */'h1',
|
|
139
|
+
onClick: formatHeading('h1'),
|
|
140
|
+
}, {
|
|
141
|
+
label: 'Heading 2',
|
|
142
|
+
value: 'h2',
|
|
143
|
+
icon: /* @icon */'h2',
|
|
144
|
+
onClick: formatHeading('h2'),
|
|
145
|
+
}, {
|
|
146
|
+
label: 'Heading 3',
|
|
147
|
+
value: 'h3',
|
|
148
|
+
icon: /* @icon */'h3',
|
|
149
|
+
onClick: formatHeading('h3'),
|
|
150
|
+
}, {
|
|
151
|
+
label: 'Heading 4',
|
|
152
|
+
value: 'h4',
|
|
153
|
+
icon: /* @icon */'h4',
|
|
154
|
+
onClick: formatHeading('h4'),
|
|
155
|
+
}, {
|
|
156
|
+
label: 'Heading 5',
|
|
157
|
+
value: 'h5',
|
|
158
|
+
icon: /* @icon */'h5',
|
|
159
|
+
onClick: formatHeading('h5'),
|
|
160
|
+
}, {
|
|
161
|
+
label: 'Heading 6',
|
|
162
|
+
value: 'h6',
|
|
163
|
+
icon: /* @icon */'h6',
|
|
164
|
+
onClick: formatHeading('h6'),
|
|
165
|
+
}, {
|
|
166
|
+
label: 'Numbered List',
|
|
167
|
+
value: 'number',
|
|
168
|
+
icon: /* @icon */'list-ol',
|
|
169
|
+
onClick: formatNumberedList,
|
|
170
|
+
|
|
171
|
+
}, {
|
|
172
|
+
label: 'Normal',
|
|
173
|
+
value: 'paragraph',
|
|
174
|
+
icon: /* @icon */'paragraph',
|
|
175
|
+
onClick: formatParagraph,
|
|
176
|
+
}, {
|
|
177
|
+
label: 'Quote',
|
|
178
|
+
value: 'quote',
|
|
179
|
+
icon: /* @icon */'quote-left',
|
|
180
|
+
onClick: formatQuote,
|
|
181
|
+
}];
|
|
182
|
+
|
|
183
|
+
export const blockTypeNames = blockTypes.map((type) => type.value);
|
|
184
|
+
|
|
185
|
+
export const rootTypeToRootName = {
|
|
186
|
+
root: 'Root',
|
|
187
|
+
table: 'Table',
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/*----------------------------------
|
|
191
|
+
- COMPONENT
|
|
192
|
+
----------------------------------*/
|
|
193
|
+
export default function BlockFormatDropDown({
|
|
194
|
+
editor,
|
|
195
|
+
blockType,
|
|
196
|
+
rootType,
|
|
197
|
+
disabled = false,
|
|
198
|
+
}: {
|
|
199
|
+
blockType: typeof blockTypeNames[number];
|
|
200
|
+
rootType: keyof typeof rootTypeToRootName;
|
|
201
|
+
editor: LexicalEditor;
|
|
202
|
+
disabled?: boolean;
|
|
203
|
+
}): JSX.Element {
|
|
204
|
+
|
|
205
|
+
const currentBlockType = blockTypes.find((type) => type.value === blockType);
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<DropDown disabled={disabled} icon={currentBlockType ? currentBlockType.icon : 'question'} size="s"
|
|
209
|
+
label={currentBlockType ? currentBlockType.label : 'Unknown Block Type'}
|
|
210
|
+
popover={{ tag: 'li' }}
|
|
211
|
+
>
|
|
212
|
+
{blockTypes.map((block) => (
|
|
213
|
+
<Button icon={block.icon}
|
|
214
|
+
onClick={() => block.onClick(editor, blockType)}>
|
|
215
|
+
{block.label}
|
|
216
|
+
</Button>
|
|
217
|
+
))}
|
|
218
|
+
</DropDown>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/*----------------------------------
|
|
2
|
+
- DEPENDANCES
|
|
3
|
+
----------------------------------*/
|
|
4
|
+
|
|
5
|
+
// npm
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import {
|
|
8
|
+
ElementFormatType,
|
|
9
|
+
FORMAT_ELEMENT_COMMAND,
|
|
10
|
+
INDENT_CONTENT_COMMAND,
|
|
11
|
+
LexicalEditor,
|
|
12
|
+
OUTDENT_CONTENT_COMMAND,
|
|
13
|
+
} from 'lexical';
|
|
14
|
+
|
|
15
|
+
// Core
|
|
16
|
+
import Button from '@client/components/button';
|
|
17
|
+
import DropDown from '@client/components/dropdown';
|
|
18
|
+
|
|
19
|
+
/*----------------------------------
|
|
20
|
+
- TYPES
|
|
21
|
+
----------------------------------*/
|
|
22
|
+
const FormatOptions: {
|
|
23
|
+
label: string;
|
|
24
|
+
value: ElementFormatType | 'indent' | 'outdent';
|
|
25
|
+
icon: string;
|
|
26
|
+
iconRTL: string;
|
|
27
|
+
}[] = [{
|
|
28
|
+
label: 'Left Align',
|
|
29
|
+
value: 'left',
|
|
30
|
+
icon: /* @icon */'align-left',
|
|
31
|
+
iconRTL: /* @icon */'align-left',
|
|
32
|
+
}, {
|
|
33
|
+
label: 'Center Align',
|
|
34
|
+
value: 'center',
|
|
35
|
+
icon: /* @icon */'align-center',
|
|
36
|
+
iconRTL: /* @icon */'align-center',
|
|
37
|
+
}, {
|
|
38
|
+
label: 'Right Align',
|
|
39
|
+
value: 'right',
|
|
40
|
+
icon: /* @icon */'align-right',
|
|
41
|
+
iconRTL: /* @icon */'align-right',
|
|
42
|
+
}, {
|
|
43
|
+
label: 'Justify Align',
|
|
44
|
+
value: 'justify',
|
|
45
|
+
icon: /* @icon */'align-justify',
|
|
46
|
+
iconRTL: /* @icon */'align-justify',
|
|
47
|
+
}, {
|
|
48
|
+
label: 'Start Align',
|
|
49
|
+
value: 'start',
|
|
50
|
+
icon: /* @icon */'align-left',
|
|
51
|
+
iconRTL: /* @icon */'align-right',
|
|
52
|
+
}, {
|
|
53
|
+
label: 'End Align',
|
|
54
|
+
value: 'end',
|
|
55
|
+
icon: /* @icon */'align-right',
|
|
56
|
+
iconRTL: /* @icon */'align-left',
|
|
57
|
+
}, {
|
|
58
|
+
label: 'Indent',
|
|
59
|
+
value: 'indent',
|
|
60
|
+
icon: /* @icon */'indent',
|
|
61
|
+
iconRTL: /* @icon */'outdent',
|
|
62
|
+
}, {
|
|
63
|
+
label: 'Outdent',
|
|
64
|
+
value: 'outdent',
|
|
65
|
+
icon: /* @icon */'outdent',
|
|
66
|
+
iconRTL: /* @icon */'indent',
|
|
67
|
+
},]
|
|
68
|
+
|
|
69
|
+
/*----------------------------------
|
|
70
|
+
- COMPONENT
|
|
71
|
+
----------------------------------*/
|
|
72
|
+
export default function ElementFormatDropdown({
|
|
73
|
+
editor,
|
|
74
|
+
value,
|
|
75
|
+
isRTL,
|
|
76
|
+
disabled = false,
|
|
77
|
+
}: {
|
|
78
|
+
editor: LexicalEditor;
|
|
79
|
+
value: ElementFormatType;
|
|
80
|
+
isRTL: boolean;
|
|
81
|
+
disabled: boolean;
|
|
82
|
+
}) {
|
|
83
|
+
|
|
84
|
+
const currentValue = value || 'left';
|
|
85
|
+
const formatOption = FormatOptions.find((option) => option.value === currentValue) || FormatOptions[0];
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<DropDown disabled={disabled} icon={isRTL ? formatOption.iconRTL : formatOption.icon} size="s"
|
|
89
|
+
label={formatOption.label}
|
|
90
|
+
popover={{ tag: 'li' }}
|
|
91
|
+
>
|
|
92
|
+
{FormatOptions.map((option) => (
|
|
93
|
+
<Button icon={isRTL ? option.iconRTL : option.icon}
|
|
94
|
+
onClick={() => {
|
|
95
|
+
if (option.value === 'indent')
|
|
96
|
+
editor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
|
|
97
|
+
else if (option.value === 'outdent')
|
|
98
|
+
editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
|
|
99
|
+
else
|
|
100
|
+
editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, option.value);
|
|
101
|
+
}}>
|
|
102
|
+
{option.label}
|
|
103
|
+
</Button>
|
|
104
|
+
))}
|
|
105
|
+
</DropDown>
|
|
106
|
+
)
|
|
107
|
+
}
|