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
@@ -1,26 +1,35 @@
1
- import { createHeadlessEditor } from '@lexical/headless';
2
- import { $generateNodesFromDOM, $generateHtmlFromNodes } from '@lexical/html';
3
- import { $getRoot } from 'lexical';
1
+ /*----------------------------------
2
+ - DEPENDANCES
3
+ ----------------------------------*/
4
4
 
5
+ // Npm
6
+ import { createHeadlessEditor } from '@lexical/headless';
7
+ import { $generateNodesFromDOM, $generateHtmlFromNodes } from '@lexical/html';
8
+ import { $getRoot, SerializedEditorState } from 'lexical';
5
9
  import { JSDOM } from 'jsdom';
6
10
 
7
- import editorNodes from './nodes';
11
+ // Core
12
+ import editorNodes from '@common/data/rte/nodes';
13
+ import ExampleTheme from '@client/components/inputv3/Rte/themes/PlaygroundEditorTheme';
8
14
 
9
- export const htmlToJson = async (htmlString: string) => {
15
+ /*----------------------------------
16
+ - FUNCTIONS
17
+ ----------------------------------*/
18
+ export const htmlToJson = async (htmlString: string): Promise<SerializedEditorState> => {
10
19
 
11
- const editor = createHeadlessEditor({
12
- nodes: editorNodes
20
+ const editor = createHeadlessEditor({
21
+ nodes: editorNodes,
22
+ theme: ExampleTheme,
13
23
  });
14
-
24
+
15
25
  await editor.update(() => {
16
26
 
17
27
  const root = $getRoot();
18
28
 
19
- // In a headless environment you can use a package such as JSDom to parse the HTML string.
20
29
  const dom = new JSDOM(htmlString);
21
30
 
22
31
  // Once you have the DOM instance it's easy to generate LexicalNodes.
23
- const lexicalNodes = $generateNodesFromDOM(editor, dom.window.document);
32
+ const lexicalNodes = $generateNodesFromDOM(editor, dom ? dom.window.document : window.document);
24
33
 
25
34
  lexicalNodes.forEach((node) => root.append(node));
26
35
  });
@@ -30,18 +39,20 @@ export const htmlToJson = async (htmlString: string) => {
30
39
  };
31
40
 
32
41
  export const jsonToHtml = async (jsonString: string) => {
33
-
34
42
 
43
+ // Server side: simulate DOM environment
35
44
  const dom = new JSDOM(`<!DOCTYPE html><body></body>`);
36
45
  global.window = dom.window;
37
46
  global.document = dom.window.document;
38
47
  global.DOMParser = dom.window.DOMParser;
39
48
  global.MutationObserver = dom.window.MutationObserver;
40
-
49
+
41
50
  // Create a headless Lexical editor instance
42
51
  const editor = createHeadlessEditor({
43
52
  namespace: 'headless',
44
53
  editable: false,
54
+ nodes: editorNodes,
55
+ theme: ExampleTheme,
45
56
  });
46
57
 
47
58
  // Set the editor state from JSON
@@ -49,14 +60,14 @@ export const jsonToHtml = async (jsonString: string) => {
49
60
  if (state.isEmpty())
50
61
  return null;
51
62
 
52
- editor.setEditorState( state );
63
+ editor.setEditorState(state);
53
64
 
54
65
  // Generate HTML from the Lexical nodes
55
66
  const html = await editor.getEditorState().read(() => {
56
67
  return $generateHtmlFromNodes(editor);
57
- });
58
-
59
- // Clean up global variables set for JSDOM to avoid memory leaks
68
+ });
69
+
70
+ // Clean up global variables set for JSDOM to avoid memory leaks
60
71
  delete global.window;
61
72
  delete global.document;
62
73
  delete global.DOMParser;
@@ -1,42 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
- export default {
9
- code: 'editor-code',
10
- heading: {
11
- h1: 'editor-heading-h1',
12
- h2: 'editor-heading-h2',
13
- h3: 'editor-heading-h3',
14
- h4: 'editor-heading-h4',
15
- h5: 'editor-heading-h5',
16
- },
17
- image: 'editor-image',
18
- link: 'editor-link',
19
- list: {
20
- listitem: 'editor-listitem',
21
- nested: {
22
- listitem: 'editor-nested-listitem',
23
- },
24
- ol: 'editor-list-ol',
25
- ul: 'editor-list-ul',
26
- },
27
- ltr: 'ltr',
28
- paragraph: 'editor-paragraph',
29
- placeholder: 'editor-placeholder',
30
- quote: 'editor-quote',
31
- rtl: 'rtl',
32
- text: {
33
- bold: 'editor-text-bold',
34
- code: 'editor-text-code',
35
- hashtag: 'editor-text-hashtag',
36
- italic: 'editor-text-italic',
37
- overflowed: 'editor-text-overflowed',
38
- strikethrough: 'editor-text-strikethrough',
39
- underline: 'editor-text-underline',
40
- underlineStrikethrough: 'editor-text-underlineStrikethrough',
41
- },
42
- };
@@ -1,167 +0,0 @@
1
- import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
2
- import { mergeRegister } from '@lexical/utils';
3
- import {
4
- $getSelection,
5
- $isRangeSelection,
6
- CAN_REDO_COMMAND,
7
- CAN_UNDO_COMMAND,
8
- FORMAT_ELEMENT_COMMAND,
9
- FORMAT_TEXT_COMMAND,
10
- REDO_COMMAND,
11
- SELECTION_CHANGE_COMMAND,
12
- UNDO_COMMAND,
13
- } from 'lexical';
14
-
15
- import React from 'react';
16
- import { useCallback, useEffect, useRef, useState } from 'react';
17
-
18
- const LowPriority = 1;
19
-
20
- function Divider() {
21
- return <div className="divider" />;
22
- }
23
-
24
- export default function ToolbarPlugin() {
25
- const [editor] = useLexicalComposerContext();
26
- const toolbarRef = useRef(null);
27
- const [canUndo, setCanUndo] = useState(false);
28
- const [canRedo, setCanRedo] = useState(false);
29
- const [isBold, setIsBold] = useState(false);
30
- const [isItalic, setIsItalic] = useState(false);
31
- const [isUnderline, setIsUnderline] = useState(false);
32
- const [isStrikethrough, setIsStrikethrough] = useState(false);
33
-
34
- const $updateToolbar = useCallback(() => {
35
- const selection = $getSelection();
36
- if ($isRangeSelection(selection)) {
37
- // Update text format
38
- setIsBold(selection.hasFormat('bold'));
39
- setIsItalic(selection.hasFormat('italic'));
40
- setIsUnderline(selection.hasFormat('underline'));
41
- setIsStrikethrough(selection.hasFormat('strikethrough'));
42
- }
43
- }, []);
44
-
45
- useEffect(() => {
46
- return mergeRegister(
47
- editor.registerUpdateListener(({ editorState }) => {
48
- editorState.read(() => {
49
- $updateToolbar();
50
- });
51
- }),
52
- editor.registerCommand(
53
- SELECTION_CHANGE_COMMAND,
54
- (_payload, _newEditor) => {
55
- $updateToolbar();
56
- return false;
57
- },
58
- LowPriority,
59
- ),
60
- editor.registerCommand(
61
- CAN_UNDO_COMMAND,
62
- (payload) => {
63
- setCanUndo(payload);
64
- return false;
65
- },
66
- LowPriority,
67
- ),
68
- editor.registerCommand(
69
- CAN_REDO_COMMAND,
70
- (payload) => {
71
- setCanRedo(payload);
72
- return false;
73
- },
74
- LowPriority,
75
- ),
76
- );
77
- }, [editor, $updateToolbar]);
78
-
79
- return (
80
- <div className="toolbar" ref={toolbarRef}>
81
- <button
82
- disabled={!canUndo}
83
- onClick={() => {
84
- editor.dispatchCommand(UNDO_COMMAND, undefined);
85
- }}
86
- className="toolbar-item spaced"
87
- aria-label="Undo">
88
- <i className="format undo" />
89
- </button>
90
- <button
91
- disabled={!canRedo}
92
- onClick={() => {
93
- editor.dispatchCommand(REDO_COMMAND, undefined);
94
- }}
95
- className="toolbar-item"
96
- aria-label="Redo">
97
- <i className="format redo" />
98
- </button>
99
- <Divider />
100
- <button
101
- onClick={() => {
102
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold');
103
- }}
104
- className={'toolbar-item spaced ' + (isBold ? 'active' : '')}
105
- aria-label="Format Bold">
106
- <i className="format bold" />
107
- </button>
108
- <button
109
- onClick={() => {
110
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic');
111
- }}
112
- className={'toolbar-item spaced ' + (isItalic ? 'active' : '')}
113
- aria-label="Format Italics">
114
- <i className="format italic" />
115
- </button>
116
- <button
117
- onClick={() => {
118
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline');
119
- }}
120
- className={'toolbar-item spaced ' + (isUnderline ? 'active' : '')}
121
- aria-label="Format Underline">
122
- <i className="format underline" />
123
- </button>
124
- <button
125
- onClick={() => {
126
- editor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough');
127
- }}
128
- className={'toolbar-item spaced ' + (isStrikethrough ? 'active' : '')}
129
- aria-label="Format Strikethrough">
130
- <i className="format strikethrough" />
131
- </button>
132
- <Divider />
133
- <button
134
- onClick={() => {
135
- editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left');
136
- }}
137
- className="toolbar-item spaced"
138
- aria-label="Left Align">
139
- <i className="format left-align" />
140
- </button>
141
- <button
142
- onClick={() => {
143
- editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center');
144
- }}
145
- className="toolbar-item spaced"
146
- aria-label="Center Align">
147
- <i className="format center-align" />
148
- </button>
149
- <button
150
- onClick={() => {
151
- editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right');
152
- }}
153
- className="toolbar-item spaced"
154
- aria-label="Right Align">
155
- <i className="format right-align" />
156
- </button>
157
- <button
158
- onClick={() => {
159
- editor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'justify');
160
- }}
161
- className="toolbar-item"
162
- aria-label="Justify Align">
163
- <i className="format justify-align" />
164
- </button>{' '}
165
- </div>
166
- );
167
- }
@@ -1,5 +0,0 @@
1
- Bootstrap Icons
2
- https://icons.getbootstrap.com
3
-
4
- Licensed under MIT license
5
- https://github.com/twbs/icons/blob/main/LICENSE.md
@@ -1,4 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
3
- <path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
4
- </svg>
@@ -1,4 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-counterclockwise" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2v1z"/>
3
- <path d="M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466z"/>
4
- </svg>
@@ -1,5 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-journal-text" viewBox="0 0 16 16">
2
- <path d="M5 10.5a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5zm0-2a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5z"/>
3
- <path d="M3 0h10a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-1h1v1a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H3a1 1 0 0 0-1 1v1H1V2a2 2 0 0 1 2-2z"/>
4
- <path d="M1 5v-.5a.5.5 0 0 1 1 0V5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1zm0 3v-.5a.5.5 0 0 1 1 0V8h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1zm0 3v-.5a.5.5 0 0 1 1 0v.5h.5a.5.5 0 0 1 0 1h-2a.5.5 0 0 1 0-1H1z"/>
5
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-justify" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-center" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M4 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-left" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-paragraph" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M2 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-text-right" viewBox="0 0 16 16">
2
- <path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm4-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-bold" viewBox="0 0 16 16">
2
- <path d="M8.21 13c2.106 0 3.412-1.087 3.412-2.823 0-1.306-.984-2.283-2.324-2.386v-.055a2.176 2.176 0 0 0 1.852-2.14c0-1.51-1.162-2.46-3.014-2.46H3.843V13H8.21zM5.908 4.674h1.696c.963 0 1.517.451 1.517 1.244 0 .834-.629 1.32-1.73 1.32H5.908V4.673zm0 6.788V8.598h1.73c1.217 0 1.88.492 1.88 1.415 0 .943-.643 1.449-1.832 1.449H5.907z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-italic" viewBox="0 0 16 16">
2
- <path d="M7.991 11.674 9.53 4.455c.123-.595.246-.71 1.347-.807l.11-.52H7.211l-.11.52c1.06.096 1.128.212 1.005.807L6.57 11.674c-.123.595-.246.71-1.346.806l-.11.52h3.774l.11-.52c-1.06-.095-1.129-.211-1.006-.806z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-strikethrough" viewBox="0 0 16 16">
2
- <path d="M6.333 5.686c0 .31.083.581.27.814H5.166a2.776 2.776 0 0 1-.099-.76c0-1.627 1.436-2.768 3.48-2.768 1.969 0 3.39 1.175 3.445 2.85h-1.23c-.11-1.08-.964-1.743-2.25-1.743-1.23 0-2.18.602-2.18 1.607zm2.194 7.478c-2.153 0-3.589-1.107-3.705-2.81h1.23c.144 1.06 1.129 1.703 2.544 1.703 1.34 0 2.31-.705 2.31-1.675 0-.827-.547-1.374-1.914-1.675L8.046 8.5H1v-1h14v1h-3.504c.468.437.675.994.675 1.697 0 1.826-1.436 2.967-3.644 2.967z"/>
3
- </svg>
@@ -1,3 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-type-underline" viewBox="0 0 16 16">
2
- <path d="M5.313 3.136h-1.23V9.54c0 2.105 1.47 3.623 3.917 3.623s3.917-1.518 3.917-3.623V3.136h-1.23v6.323c0 1.49-.978 2.57-2.687 2.57-1.709 0-2.687-1.08-2.687-2.57V3.136zM12.5 15h-9v-1h9v1z"/>
3
- </svg>