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.
Files changed (190) hide show
  1. package/package.json +5 -1
  2. package/src/client/assets/css/components/table.less +3 -0
  3. package/src/client/components/Form.ts +2 -6
  4. package/src/client/components/Table/index.tsx +24 -79
  5. package/src/client/components/button.tsx +2 -1
  6. package/src/client/components/containers/Popover/index.tsx +2 -2
  7. package/src/client/components/dropdown/index.tsx +16 -6
  8. package/src/client/components/input/Slider/index.tsx +0 -2
  9. package/src/client/components/inputv3/Rte/Editor.tsx +271 -0
  10. package/src/client/components/inputv3/Rte/ToolbarPlugin/BlockFormat.tsx +220 -0
  11. package/src/client/components/inputv3/Rte/ToolbarPlugin/ElementFormat.tsx +107 -0
  12. package/src/client/components/inputv3/Rte/ToolbarPlugin/index.tsx +768 -0
  13. package/src/client/components/inputv3/Rte/appSettings.ts +36 -0
  14. package/src/client/components/inputv3/Rte/context/FlashMessageContext.tsx +68 -0
  15. package/src/client/components/inputv3/Rte/context/SettingsContext.tsx +71 -0
  16. package/src/client/components/inputv3/Rte/context/SharedAutocompleteContext.tsx +71 -0
  17. package/src/client/components/inputv3/Rte/context/SharedHistoryContext.tsx +35 -0
  18. package/src/client/components/inputv3/Rte/currentEditor.ts +42 -0
  19. package/src/client/components/inputv3/Rte/hooks/useFlashMessage.tsx +16 -0
  20. package/src/client/components/inputv3/Rte/hooks/useReport.ts +67 -0
  21. package/src/client/components/inputv3/Rte/images/emoji/1F600.png +0 -0
  22. package/src/client/components/inputv3/Rte/images/emoji/1F641.png +0 -0
  23. package/src/client/components/inputv3/Rte/images/emoji/1F642.png +0 -0
  24. package/src/client/components/inputv3/Rte/images/emoji/2764.png +0 -0
  25. package/src/client/components/inputv3/Rte/images/emoji/LICENSE.md +5 -0
  26. package/src/client/components/inputv3/Rte/images/icons/draggable-block-menu.svg +1 -0
  27. package/src/client/components/inputv3/Rte/images/icons/prettier-error.svg +1 -0
  28. package/src/client/components/inputv3/Rte/images/icons/prettier.svg +1 -0
  29. package/src/client/components/inputv3/Rte/images/image/LICENSE.md +5 -0
  30. package/src/client/components/inputv3/Rte/images/image-broken.svg +4 -0
  31. package/src/client/components/inputv3/Rte/images/logo.svg +1 -0
  32. package/src/client/components/inputv3/Rte/index.tsx +63 -79
  33. package/src/client/components/inputv3/Rte/nodes/AutocompleteNode.tsx +119 -0
  34. package/src/client/components/inputv3/Rte/nodes/EmojiNode.tsx +102 -0
  35. package/src/client/components/inputv3/Rte/nodes/EquationComponent.tsx +141 -0
  36. package/src/client/components/inputv3/Rte/nodes/EquationNode.tsx +174 -0
  37. package/src/client/components/inputv3/Rte/nodes/FigmaNode.tsx +135 -0
  38. package/src/client/components/inputv3/Rte/nodes/ImageComponent.tsx +468 -0
  39. package/src/client/components/inputv3/Rte/nodes/ImageNode.css +43 -0
  40. package/src/client/components/inputv3/Rte/nodes/ImageNode.tsx +266 -0
  41. package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageComponent.tsx +402 -0
  42. package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.css +94 -0
  43. package/src/client/components/inputv3/Rte/nodes/InlineImageNode/InlineImageNode.tsx +294 -0
  44. package/src/client/components/inputv3/Rte/nodes/KeywordNode.ts +67 -0
  45. package/src/client/components/inputv3/Rte/nodes/LayoutContainerNode.ts +137 -0
  46. package/src/client/components/inputv3/Rte/nodes/LayoutItemNode.ts +71 -0
  47. package/src/client/components/inputv3/Rte/nodes/MentionNode.ts +130 -0
  48. package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.css +62 -0
  49. package/src/client/components/inputv3/Rte/nodes/PageBreakNode/index.tsx +170 -0
  50. package/src/client/components/inputv3/Rte/nodes/PlaygroundNodes.ts +76 -0
  51. package/src/client/components/inputv3/Rte/nodes/PollComponent.tsx +249 -0
  52. package/src/client/components/inputv3/Rte/nodes/PollNode.css +187 -0
  53. package/src/client/components/inputv3/Rte/nodes/PollNode.tsx +209 -0
  54. package/src/client/components/inputv3/Rte/nodes/StickyComponent.tsx +261 -0
  55. package/src/client/components/inputv3/Rte/nodes/StickyNode.css +37 -0
  56. package/src/client/components/inputv3/Rte/nodes/StickyNode.tsx +150 -0
  57. package/src/client/components/inputv3/Rte/nodes/TweetNode.tsx +223 -0
  58. package/src/client/components/inputv3/Rte/nodes/YouTubeNode.tsx +184 -0
  59. package/src/client/components/inputv3/Rte/plugins/ActionsPlugin/index.tsx +334 -0
  60. package/src/client/components/inputv3/Rte/plugins/AutoEmbedPlugin/index.tsx +352 -0
  61. package/src/client/components/inputv3/Rte/plugins/AutoLinkPlugin/index.tsx +32 -0
  62. package/src/client/components/inputv3/Rte/plugins/AutocompletePlugin/index.tsx +2529 -0
  63. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +70 -0
  64. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.css +14 -0
  65. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +156 -0
  66. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.css +54 -0
  67. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/index.tsx +190 -0
  68. package/src/client/components/inputv3/Rte/plugins/CodeActionMenuPlugin/utils.ts +33 -0
  69. package/src/client/components/inputv3/Rte/plugins/CodeHighlightPlugin/index.ts +21 -0
  70. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/Collapsible.css +57 -0
  71. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContainerNode.ts +168 -0
  72. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleContentNode.ts +127 -0
  73. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleTitleNode.ts +152 -0
  74. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/CollapsibleUtils.ts +17 -0
  75. package/src/client/components/inputv3/Rte/plugins/CollapsiblePlugin/index.ts +284 -0
  76. package/src/client/components/inputv3/Rte/plugins/ComponentPickerPlugin/index.tsx +370 -0
  77. package/src/client/components/inputv3/Rte/plugins/ContextMenuPlugin/index.tsx +270 -0
  78. package/src/client/components/inputv3/Rte/plugins/DocsPlugin/index.tsx +20 -0
  79. package/src/client/components/inputv3/Rte/plugins/DragDropPastePlugin/index.ts +51 -0
  80. package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.css +36 -0
  81. package/src/client/components/inputv3/Rte/plugins/DraggableBlockPlugin/index.tsx +43 -0
  82. package/src/client/components/inputv3/Rte/plugins/EmojiPickerPlugin/index.tsx +198 -0
  83. package/src/client/components/inputv3/Rte/plugins/EmojisPlugin/index.ts +75 -0
  84. package/src/client/components/inputv3/Rte/plugins/EquationsPlugin/index.tsx +82 -0
  85. package/src/client/components/inputv3/Rte/plugins/FigmaPlugin/index.tsx +40 -0
  86. package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.css +41 -0
  87. package/src/client/components/inputv3/Rte/plugins/FloatingLinkEditorPlugin/index.tsx +393 -0
  88. package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.css +141 -0
  89. package/src/client/components/inputv3/Rte/plugins/FloatingTextFormatToolbarPlugin/index.tsx +388 -0
  90. package/src/client/components/inputv3/Rte/plugins/ImagesPlugin/index.tsx +350 -0
  91. package/src/client/components/inputv3/Rte/plugins/InlineImagePlugin/index.tsx +336 -0
  92. package/src/client/components/inputv3/Rte/plugins/KeywordsPlugin/index.ts +56 -0
  93. package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/InsertLayoutDialog.tsx +58 -0
  94. package/src/client/components/inputv3/Rte/plugins/LayoutPlugin/LayoutPlugin.tsx +219 -0
  95. package/src/client/components/inputv3/Rte/plugins/LinkPlugin/index.tsx +34 -0
  96. package/src/client/components/inputv3/Rte/plugins/ListMaxIndentLevelPlugin/index.ts +85 -0
  97. package/src/client/components/inputv3/Rte/plugins/MarkdownShortcutPlugin/index.tsx +16 -0
  98. package/src/client/components/inputv3/Rte/plugins/MarkdownTransformers/index.ts +324 -0
  99. package/src/client/components/inputv3/Rte/plugins/MaxLengthPlugin/index.tsx +53 -0
  100. package/src/client/components/inputv3/Rte/plugins/MentionsPlugin/index.tsx +696 -0
  101. package/src/client/components/inputv3/Rte/plugins/PageBreakPlugin/index.tsx +57 -0
  102. package/src/client/components/inputv3/Rte/plugins/PasteLogPlugin/index.tsx +54 -0
  103. package/src/client/components/inputv3/Rte/plugins/PollPlugin/index.tsx +86 -0
  104. package/src/client/components/inputv3/Rte/plugins/SpeechToTextPlugin/index.ts +125 -0
  105. package/src/client/components/inputv3/Rte/plugins/StickyPlugin/index.ts +22 -0
  106. package/src/client/components/inputv3/Rte/plugins/TabFocusPlugin/index.tsx +65 -0
  107. package/src/client/components/inputv3/Rte/plugins/TableActionMenuPlugin/index.tsx +773 -0
  108. package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.css +12 -0
  109. package/src/client/components/inputv3/Rte/plugins/TableCellResizer/index.tsx +436 -0
  110. package/src/client/components/inputv3/Rte/plugins/TableHoverActionsPlugin/index.tsx +287 -0
  111. package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.css +95 -0
  112. package/src/client/components/inputv3/Rte/plugins/TableOfContentsPlugin/index.tsx +197 -0
  113. package/src/client/components/inputv3/Rte/plugins/TablePlugin.tsx +178 -0
  114. package/src/client/components/inputv3/Rte/plugins/TestRecorderPlugin/index.tsx +468 -0
  115. package/src/client/components/inputv3/Rte/plugins/TreeViewPlugin/index.tsx +26 -0
  116. package/src/client/components/inputv3/Rte/plugins/TwitterPlugin/index.ts +41 -0
  117. package/src/client/components/inputv3/Rte/plugins/TypingPerfPlugin/index.ts +117 -0
  118. package/src/client/components/inputv3/Rte/plugins/YouTubePlugin/index.ts +41 -0
  119. package/src/client/components/inputv3/Rte/shared/canUseDOM.ts +4 -0
  120. package/src/client/components/inputv3/Rte/shared/caretFromPoint.ts +40 -0
  121. package/src/client/components/inputv3/Rte/shared/environment.ts +56 -0
  122. package/src/client/components/inputv3/Rte/shared/invariant.ts +26 -0
  123. package/src/client/components/inputv3/Rte/shared/normalizeClassNames.ts +21 -0
  124. package/src/client/components/inputv3/Rte/shared/react-test-utils.ts +18 -0
  125. package/src/client/components/inputv3/Rte/shared/reactPatches.ts +22 -0
  126. package/src/client/components/inputv3/Rte/shared/simpleDiffWithCursor.ts +49 -0
  127. package/src/client/components/inputv3/Rte/shared/useLayoutEffect.ts +19 -0
  128. package/src/client/components/inputv3/Rte/shared/warnOnlyOnce.ts +20 -0
  129. package/src/client/components/inputv3/Rte/style.less +30 -60
  130. package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.css +13 -0
  131. package/src/client/components/inputv3/Rte/themes/CommentEditorTheme.ts +20 -0
  132. package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.css +447 -0
  133. package/src/client/components/inputv3/Rte/themes/PlaygroundEditorTheme.ts +120 -0
  134. package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.css +13 -0
  135. package/src/client/components/inputv3/Rte/themes/StickyEditorTheme.ts +20 -0
  136. package/src/client/components/inputv3/Rte/ui/ColorPicker.css +88 -0
  137. package/src/client/components/inputv3/Rte/ui/ColorPicker.tsx +365 -0
  138. package/src/client/components/inputv3/Rte/ui/ContentEditable.css +44 -0
  139. package/src/client/components/inputv3/Rte/ui/ContentEditable.tsx +36 -0
  140. package/src/client/components/inputv3/Rte/ui/DropDown.tsx +259 -0
  141. package/src/client/components/inputv3/Rte/ui/DropdownColorPicker.tsx +41 -0
  142. package/src/client/components/inputv3/Rte/ui/EquationEditor.css +38 -0
  143. package/src/client/components/inputv3/Rte/ui/EquationEditor.tsx +56 -0
  144. package/src/client/components/inputv3/Rte/ui/FileInput.tsx +38 -0
  145. package/src/client/components/inputv3/Rte/ui/FlashMessage.css +28 -0
  146. package/src/client/components/inputv3/Rte/ui/FlashMessage.tsx +29 -0
  147. package/src/client/components/inputv3/Rte/ui/ImageResizer.tsx +316 -0
  148. package/src/client/components/inputv3/Rte/ui/Input.css +32 -0
  149. package/src/client/components/inputv3/Rte/ui/KatexRenderer.tsx +54 -0
  150. package/src/client/components/inputv3/Rte/ui/Switch.tsx +36 -0
  151. package/src/client/components/inputv3/Rte/utils/docSerialization.ts +77 -0
  152. package/src/client/components/inputv3/Rte/utils/emoji-list.ts +16615 -0
  153. package/src/client/components/inputv3/Rte/utils/getDOMRangeRect.ts +27 -0
  154. package/src/client/components/inputv3/Rte/utils/getSelectedNode.ts +27 -0
  155. package/src/client/components/inputv3/Rte/utils/guard.ts +10 -0
  156. package/src/client/components/inputv3/Rte/utils/isMobileWidth.ts +7 -0
  157. package/src/client/components/inputv3/Rte/utils/joinClasses.ts +13 -0
  158. package/src/client/components/inputv3/Rte/utils/setFloatingElemPosition.ts +51 -0
  159. package/src/client/components/inputv3/Rte/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
  160. package/src/client/components/inputv3/Rte/utils/swipe.ts +127 -0
  161. package/src/client/components/inputv3/Rte/utils/url.ts +38 -0
  162. package/src/client/components/inputv3/base.tsx +10 -7
  163. package/src/client/components/inputv3/file/index.tsx +11 -5
  164. package/src/client/components/inputv3/index.tsx +2 -2
  165. package/src/common/data/rte/nodes.ts +60 -9
  166. package/src/common/validation/index.ts +21 -2
  167. package/src/common/validation/schema.ts +34 -11
  168. package/src/common/validation/validator.ts +12 -4
  169. package/src/common/validation/validators.ts +112 -63
  170. package/src/server/services/router/http/multipart.ts +0 -1
  171. package/src/server/services/router/request/index.ts +1 -1
  172. package/src/server/services/schema/index.ts +26 -4
  173. package/src/server/services/schema/request.ts +3 -2
  174. package/src/server/services/schema/rte.ts +110 -0
  175. package/src/{common/data/rte/index.ts → server/utils/rte.ts} +27 -16
  176. package/src/client/components/inputv3/Rte/ExampleTheme.tsx +0 -42
  177. package/src/client/components/inputv3/Rte/ToolbarPlugin.tsx +0 -167
  178. package/src/client/components/inputv3/Rte/icons/LICENSE.md +0 -5
  179. package/src/client/components/inputv3/Rte/icons/arrow-clockwise.svg +0 -4
  180. package/src/client/components/inputv3/Rte/icons/arrow-counterclockwise.svg +0 -4
  181. package/src/client/components/inputv3/Rte/icons/journal-text.svg +0 -5
  182. package/src/client/components/inputv3/Rte/icons/justify.svg +0 -3
  183. package/src/client/components/inputv3/Rte/icons/text-center.svg +0 -3
  184. package/src/client/components/inputv3/Rte/icons/text-left.svg +0 -3
  185. package/src/client/components/inputv3/Rte/icons/text-paragraph.svg +0 -3
  186. package/src/client/components/inputv3/Rte/icons/text-right.svg +0 -3
  187. package/src/client/components/inputv3/Rte/icons/type-bold.svg +0 -3
  188. package/src/client/components/inputv3/Rte/icons/type-italic.svg +0 -3
  189. package/src/client/components/inputv3/Rte/icons/type-strikethrough.svg +0 -3
  190. 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
+ }