@byline/richtext-lexical 0.9.3
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/LICENSE +373 -0
- package/README.md +18 -0
- package/dist/field/apply-value-plugin.d.ts +10 -0
- package/dist/field/apply-value-plugin.d.ts.map +1 -0
- package/dist/field/apply-value-plugin.js +60 -0
- package/dist/field/config/default.d.ts +6 -0
- package/dist/field/config/default.d.ts.map +1 -0
- package/dist/field/config/default.js +53 -0
- package/dist/field/config/editor-config-context.d.ts +14 -0
- package/dist/field/config/editor-config-context.d.ts.map +1 -0
- package/dist/field/config/editor-config-context.js +51 -0
- package/dist/field/config/types.d.ts +28 -0
- package/dist/field/config/types.d.ts.map +1 -0
- package/dist/field/config/types.js +1 -0
- package/dist/field/constants.d.ts +2 -0
- package/dist/field/constants.d.ts.map +1 -0
- package/dist/field/constants.js +2 -0
- package/dist/field/content-editable-inline.d.ts +13 -0
- package/dist/field/content-editable-inline.d.ts.map +1 -0
- package/dist/field/content-editable-inline.js +11 -0
- package/dist/field/content-editable.css +23 -0
- package/dist/field/content-editable.d.ts +13 -0
- package/dist/field/content-editable.d.ts.map +1 -0
- package/dist/field/content-editable.js +14 -0
- package/dist/field/context/shared-autocomplete-context.js +44 -0
- package/dist/field/context/shared-history-context.d.ts +19 -0
- package/dist/field/context/shared-history-context.d.ts.map +1 -0
- package/dist/field/context/shared-history-context.js +16 -0
- package/dist/field/context/shared-on-change-context.d.ts +13 -0
- package/dist/field/context/shared-on-change-context.d.ts.map +1 -0
- package/dist/field/context/shared-on-change-context.js +21 -0
- package/dist/field/debug.d.ts +10 -0
- package/dist/field/debug.d.ts.map +1 -0
- package/dist/field/debug.js +30 -0
- package/dist/field/editor-component.css +33 -0
- package/dist/field/editor-component.d.ts +13 -0
- package/dist/field/editor-component.d.ts.map +1 -0
- package/dist/field/editor-component.js +115 -0
- package/dist/field/editor-context.d.ts +23 -0
- package/dist/field/editor-context.d.ts.map +1 -0
- package/dist/field/editor-context.js +57 -0
- package/dist/field/editor-field.d.ts +34 -0
- package/dist/field/editor-field.d.ts.map +1 -0
- package/dist/field/editor-field.js +18 -0
- package/dist/field/editor.css +1449 -0
- package/dist/field/editor.d.ts +14 -0
- package/dist/field/editor.d.ts.map +1 -0
- package/dist/field/editor.js +190 -0
- package/dist/field/hooks/use-modal.d.ts +13 -0
- package/dist/field/hooks/use-modal.d.ts.map +1 -0
- package/dist/field/hooks/use-modal.js +37 -0
- package/dist/field/hooks/use-report.js +39 -0
- package/dist/field/lexical-populate-shared.d.ts +97 -0
- package/dist/field/lexical-populate-shared.d.ts.map +1 -0
- package/dist/field/lexical-populate-shared.js +60 -0
- package/dist/field/nodes/admonition-node/admonition-node-component.css +119 -0
- package/dist/field/nodes/admonition-node/admonition-node-component.d.ts +18 -0
- package/dist/field/nodes/admonition-node/admonition-node-component.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/admonition-node-component.js +190 -0
- package/dist/field/nodes/admonition-node/admonition-node.d.ts +35 -0
- package/dist/field/nodes/admonition-node/admonition-node.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/admonition-node.js +129 -0
- package/dist/field/nodes/admonition-node/icons/danger-icon.css +12 -0
- package/dist/field/nodes/admonition-node/icons/danger-icon.d.ts +8 -0
- package/dist/field/nodes/admonition-node/icons/danger-icon.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/icons/danger-icon.js +18 -0
- package/dist/field/nodes/admonition-node/icons/index.d.ts +5 -0
- package/dist/field/nodes/admonition-node/icons/index.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/icons/index.js +4 -0
- package/dist/field/nodes/admonition-node/icons/note-icon.css +12 -0
- package/dist/field/nodes/admonition-node/icons/note-icon.d.ts +8 -0
- package/dist/field/nodes/admonition-node/icons/note-icon.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/icons/note-icon.js +18 -0
- package/dist/field/nodes/admonition-node/icons/tip-icon.css +12 -0
- package/dist/field/nodes/admonition-node/icons/tip-icon.d.ts +8 -0
- package/dist/field/nodes/admonition-node/icons/tip-icon.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/icons/tip-icon.js +18 -0
- package/dist/field/nodes/admonition-node/icons/warning-icon.css +12 -0
- package/dist/field/nodes/admonition-node/icons/warning-icon.d.ts +8 -0
- package/dist/field/nodes/admonition-node/icons/warning-icon.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/icons/warning-icon.js +18 -0
- package/dist/field/nodes/admonition-node/index.d.ts +10 -0
- package/dist/field/nodes/admonition-node/index.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/index.js +2 -0
- package/dist/field/nodes/admonition-node/types.d.ts +21 -0
- package/dist/field/nodes/admonition-node/types.d.ts.map +1 -0
- package/dist/field/nodes/admonition-node/types.js +1 -0
- package/dist/field/nodes/document-relation.d.ts +33 -0
- package/dist/field/nodes/document-relation.d.ts.map +1 -0
- package/dist/field/nodes/document-relation.js +1 -0
- package/dist/field/nodes/index.d.ts +10 -0
- package/dist/field/nodes/index.d.ts.map +1 -0
- package/dist/field/nodes/index.js +37 -0
- package/dist/field/nodes/inline-image-node/index.d.ts +10 -0
- package/dist/field/nodes/inline-image-node/index.d.ts.map +1 -0
- package/dist/field/nodes/inline-image-node/index.js +2 -0
- package/dist/field/nodes/inline-image-node/inline-image-node-component.css +204 -0
- package/dist/field/nodes/inline-image-node/inline-image-node-component.d.ts +24 -0
- package/dist/field/nodes/inline-image-node/inline-image-node-component.d.ts.map +1 -0
- package/dist/field/nodes/inline-image-node/inline-image-node-component.js +221 -0
- package/dist/field/nodes/inline-image-node/inline-image-node.d.ts +45 -0
- package/dist/field/nodes/inline-image-node/inline-image-node.d.ts.map +1 -0
- package/dist/field/nodes/inline-image-node/inline-image-node.js +187 -0
- package/dist/field/nodes/inline-image-node/types.d.ts +30 -0
- package/dist/field/nodes/inline-image-node/types.d.ts.map +1 -0
- package/dist/field/nodes/inline-image-node/types.js +1 -0
- package/dist/field/nodes/layout-container-node/layout-container-node.d.ts +29 -0
- package/dist/field/nodes/layout-container-node/layout-container-node.d.ts.map +1 -0
- package/dist/field/nodes/layout-container-node/layout-container-node.js +54 -0
- package/dist/field/nodes/layout-container-node/layout-item-node.d.ts +23 -0
- package/dist/field/nodes/layout-container-node/layout-item-node.d.ts.map +1 -0
- package/dist/field/nodes/layout-container-node/layout-item-node.js +41 -0
- package/dist/field/nodes/link-nodes/auto-link-node.d.ts +17 -0
- package/dist/field/nodes/link-nodes/auto-link-node.d.ts.map +1 -0
- package/dist/field/nodes/link-nodes/auto-link-node.js +52 -0
- package/dist/field/nodes/link-nodes/index.d.ts +4 -0
- package/dist/field/nodes/link-nodes/index.d.ts.map +1 -0
- package/dist/field/nodes/link-nodes/index.js +3 -0
- package/dist/field/nodes/link-nodes/link-node.d.ts +49 -0
- package/dist/field/nodes/link-nodes/link-node.d.ts.map +1 -0
- package/dist/field/nodes/link-nodes/link-node.js +253 -0
- package/dist/field/nodes/link-nodes/types.d.ts +26 -0
- package/dist/field/nodes/link-nodes/types.d.ts.map +1 -0
- package/dist/field/nodes/link-nodes/types.js +1 -0
- package/dist/field/nodes/vimeo-node/index.d.ts +30 -0
- package/dist/field/nodes/vimeo-node/index.d.ts.map +1 -0
- package/dist/field/nodes/vimeo-node/index.js +109 -0
- package/dist/field/nodes/youtube-node/index.d.ts +30 -0
- package/dist/field/nodes/youtube-node/index.d.ts.map +1 -0
- package/dist/field/nodes/youtube-node/index.js +110 -0
- package/dist/field/plugins/admonition-plugin/admonition-modal.css +26 -0
- package/dist/field/plugins/admonition-plugin/admonition-modal.d.ts +12 -0
- package/dist/field/plugins/admonition-plugin/admonition-modal.d.ts.map +1 -0
- package/dist/field/plugins/admonition-plugin/admonition-modal.js +165 -0
- package/dist/field/plugins/admonition-plugin/fields.d.ts +21 -0
- package/dist/field/plugins/admonition-plugin/fields.d.ts.map +1 -0
- package/dist/field/plugins/admonition-plugin/fields.js +55 -0
- package/dist/field/plugins/admonition-plugin/index.d.ts +15 -0
- package/dist/field/plugins/admonition-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/admonition-plugin/index.js +54 -0
- package/dist/field/plugins/admonition-plugin/types.d.ts +34 -0
- package/dist/field/plugins/admonition-plugin/types.d.ts.map +1 -0
- package/dist/field/plugins/admonition-plugin/types.js +1 -0
- package/dist/field/plugins/auto-embed-plugin/auto-embed-modal.css +16 -0
- package/dist/field/plugins/auto-embed-plugin/auto-embed-modal.d.ts +8 -0
- package/dist/field/plugins/auto-embed-plugin/auto-embed-modal.d.ts.map +1 -0
- package/dist/field/plugins/auto-embed-plugin/auto-embed-modal.js +105 -0
- package/dist/field/plugins/auto-embed-plugin/index.d.ts +21 -0
- package/dist/field/plugins/auto-embed-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/auto-embed-plugin/index.js +152 -0
- package/dist/field/plugins/code-highlight-plugin/index.d.ts +10 -0
- package/dist/field/plugins/code-highlight-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/code-highlight-plugin/index.js +11 -0
- package/dist/field/plugins/drag-drop-paste-plugin/index.js +1 -0
- package/dist/field/plugins/floating-text-format-toolbar-plugin/index.css +148 -0
- package/dist/field/plugins/floating-text-format-toolbar-plugin/index.d.ts +13 -0
- package/dist/field/plugins/floating-text-format-toolbar-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/floating-text-format-toolbar-plugin/index.js +279 -0
- package/dist/field/plugins/inline-image-plugin/fields.d.ts +12 -0
- package/dist/field/plugins/inline-image-plugin/fields.d.ts.map +1 -0
- package/dist/field/plugins/inline-image-plugin/fields.js +22 -0
- package/dist/field/plugins/inline-image-plugin/index.d.ts +34 -0
- package/dist/field/plugins/inline-image-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/inline-image-plugin/index.js +107 -0
- package/dist/field/plugins/inline-image-plugin/inline-image-modal.css +25 -0
- package/dist/field/plugins/inline-image-plugin/inline-image-modal.d.ts +11 -0
- package/dist/field/plugins/inline-image-plugin/inline-image-modal.d.ts.map +1 -0
- package/dist/field/plugins/inline-image-plugin/inline-image-modal.js +271 -0
- package/dist/field/plugins/inline-image-plugin/populate.d.ts +10 -0
- package/dist/field/plugins/inline-image-plugin/populate.d.ts.map +1 -0
- package/dist/field/plugins/inline-image-plugin/populate.js +28 -0
- package/dist/field/plugins/inline-image-plugin/types.d.ts +37 -0
- package/dist/field/plugins/inline-image-plugin/types.d.ts.map +1 -0
- package/dist/field/plugins/inline-image-plugin/types.js +1 -0
- package/dist/field/plugins/inline-image-plugin/utils.d.ts +42 -0
- package/dist/field/plugins/inline-image-plugin/utils.d.ts.map +1 -0
- package/dist/field/plugins/inline-image-plugin/utils.js +46 -0
- package/dist/field/plugins/layout-plugin/insert-layout-modal.css +20 -0
- package/dist/field/plugins/layout-plugin/insert-layout-modal.d.ts +22 -0
- package/dist/field/plugins/layout-plugin/insert-layout-modal.d.ts.map +1 -0
- package/dist/field/plugins/layout-plugin/insert-layout-modal.js +97 -0
- package/dist/field/plugins/layout-plugin/layout-plugin.d.ts +10 -0
- package/dist/field/plugins/layout-plugin/layout-plugin.d.ts.map +1 -0
- package/dist/field/plugins/layout-plugin/layout-plugin.js +81 -0
- package/dist/field/plugins/link-plugin/auto-link/auto-link-plugin.d.ts +22 -0
- package/dist/field/plugins/link-plugin/auto-link/auto-link-plugin.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/auto-link/auto-link-plugin.js +185 -0
- package/dist/field/plugins/link-plugin/auto-link/index.d.ts +10 -0
- package/dist/field/plugins/link-plugin/auto-link/index.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/auto-link/index.js +15 -0
- package/dist/field/plugins/link-plugin/link/floating-link-editor.css +124 -0
- package/dist/field/plugins/link-plugin/link/floating-link-editor.d.ts +15 -0
- package/dist/field/plugins/link-plugin/link/floating-link-editor.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/link/floating-link-editor.js +234 -0
- package/dist/field/plugins/link-plugin/link/index.d.ts +2 -0
- package/dist/field/plugins/link-plugin/link/index.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/link/index.js +43 -0
- package/dist/field/plugins/link-plugin/link/link-modal.d.ts +11 -0
- package/dist/field/plugins/link-plugin/link/link-modal.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/link/link-modal.js +311 -0
- package/dist/field/plugins/link-plugin/link/types.d.ts +19 -0
- package/dist/field/plugins/link-plugin/link/types.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/link/types.js +1 -0
- package/dist/field/plugins/link-plugin/populate.d.ts +22 -0
- package/dist/field/plugins/link-plugin/populate.d.ts.map +1 -0
- package/dist/field/plugins/link-plugin/populate.js +28 -0
- package/dist/field/plugins/table-action-menu-plugin/index.d.ts +6 -0
- package/dist/field/plugins/table-action-menu-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/table-action-menu-plugin/index.js +598 -0
- package/dist/field/plugins/table-plugin/index.d.ts +4 -0
- package/dist/field/plugins/table-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/table-plugin/index.js +26 -0
- package/dist/field/plugins/table-plugin/table-modal.css +20 -0
- package/dist/field/plugins/table-plugin/table-modal.d.ts +21 -0
- package/dist/field/plugins/table-plugin/table-modal.d.ts.map +1 -0
- package/dist/field/plugins/table-plugin/table-modal.js +111 -0
- package/dist/field/plugins/toolbar-plugin/index.d.ts +17 -0
- package/dist/field/plugins/toolbar-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/toolbar-plugin/index.js +837 -0
- package/dist/field/plugins/treeview-plugin/index.d.ts +10 -0
- package/dist/field/plugins/treeview-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/treeview-plugin/index.js +17 -0
- package/dist/field/plugins/vimeo-plugin/index.d.ts +4 -0
- package/dist/field/plugins/vimeo-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/vimeo-plugin/index.js +24 -0
- package/dist/field/plugins/youtube-plugin/index.d.ts +4 -0
- package/dist/field/plugins/youtube-plugin/index.d.ts.map +1 -0
- package/dist/field/plugins/youtube-plugin/index.js +24 -0
- package/dist/field/shared/canUseDOM.d.ts +9 -0
- package/dist/field/shared/canUseDOM.d.ts.map +1 -0
- package/dist/field/shared/canUseDOM.js +2 -0
- package/dist/field/shared/environment.d.ts +23 -0
- package/dist/field/shared/environment.d.ts.map +1 -0
- package/dist/field/shared/environment.js +10 -0
- package/dist/field/shared/invariant.d.ts +9 -0
- package/dist/field/shared/invariant.d.ts.map +1 -0
- package/dist/field/shared/invariant.js +6 -0
- package/dist/field/shared/simpleDiffWithCursor.js +15 -0
- package/dist/field/shared/useLayoutEffect.js +5 -0
- package/dist/field/shared/useModalFormState.d.ts +23 -0
- package/dist/field/shared/useModalFormState.d.ts.map +1 -0
- package/dist/field/shared/useModalFormState.js +23 -0
- package/dist/field/shared/warnOnlyOnce.js +9 -0
- package/dist/field/themes/lexical-editor-theme.css +537 -0
- package/dist/field/themes/lexical-editor-theme.d.ts +10 -0
- package/dist/field/themes/lexical-editor-theme.d.ts.map +1 -0
- package/dist/field/themes/lexical-editor-theme.js +105 -0
- package/dist/field/toolbar-extensions.d.ts +32 -0
- package/dist/field/toolbar-extensions.d.ts.map +1 -0
- package/dist/field/toolbar-extensions.js +56 -0
- package/dist/field/types.js +1 -0
- package/dist/field/ui/button.css +31 -0
- package/dist/field/ui/button.js +19 -0
- package/dist/field/ui/checkbox.css +46 -0
- package/dist/field/ui/color-picker.css +75 -0
- package/dist/field/ui/color-picker.d.ts +21 -0
- package/dist/field/ui/color-picker.d.ts.map +1 -0
- package/dist/field/ui/color-picker.js +360 -0
- package/dist/field/ui/dialog.css +18 -0
- package/dist/field/ui/dialog.js +17 -0
- package/dist/field/ui/dropdown.d.ts +25 -0
- package/dist/field/ui/dropdown.d.ts.map +1 -0
- package/dist/field/ui/dropdown.js +150 -0
- package/dist/field/ui/file-input.js +27 -0
- package/dist/field/ui/input.css +23 -0
- package/dist/field/ui/modal.css +73 -0
- package/dist/field/ui/modal.d.ts +17 -0
- package/dist/field/ui/modal.d.ts.map +1 -0
- package/dist/field/ui/modal.js +69 -0
- package/dist/field/ui/placeholder-inline.d.ts +14 -0
- package/dist/field/ui/placeholder-inline.d.ts.map +1 -0
- package/dist/field/ui/placeholder-inline.js +12 -0
- package/dist/field/ui/placeholder.css +26 -0
- package/dist/field/ui/placeholder.d.ts +14 -0
- package/dist/field/ui/placeholder.d.ts.map +1 -0
- package/dist/field/ui/placeholder.js +14 -0
- package/dist/field/ui/select.css +32 -0
- package/dist/field/ui/select.js +28 -0
- package/dist/field/ui/switch.js +25 -0
- package/dist/field/ui/text-area.css +31 -0
- package/dist/field/ui/text-area.js +28 -0
- package/dist/field/ui/text-input.d.ts +20 -0
- package/dist/field/ui/text-input.d.ts.map +1 -0
- package/dist/field/ui/text-input.js +29 -0
- package/dist/field/utils/cloneDeep.js +26 -0
- package/dist/field/utils/deepEqual.js +19 -0
- package/dist/field/utils/emoji-list.js +21389 -0
- package/dist/field/utils/getDOMRangeRect.d.ts +9 -0
- package/dist/field/utils/getDOMRangeRect.d.ts.map +1 -0
- package/dist/field/utils/getDOMRangeRect.js +11 -0
- package/dist/field/utils/getSelectedNode.d.ts +3 -0
- package/dist/field/utils/getSelectedNode.d.ts.map +1 -0
- package/dist/field/utils/getSelectedNode.js +12 -0
- package/dist/field/utils/guard.js +4 -0
- package/dist/field/utils/hashSerializedState.d.ts +3 -0
- package/dist/field/utils/hashSerializedState.d.ts.map +1 -0
- package/dist/field/utils/hashSerializedState.js +22 -0
- package/dist/field/utils/isMobileWidth.js +1 -0
- package/dist/field/utils/joinClasses.js +4 -0
- package/dist/field/utils/point.js +34 -0
- package/dist/field/utils/rect.js +95 -0
- package/dist/field/utils/setFloatingElemPosition.d.ts +2 -0
- package/dist/field/utils/setFloatingElemPosition.d.ts.map +1 -0
- package/dist/field/utils/setFloatingElemPosition.js +22 -0
- package/dist/field/utils/setFloatingElemPositionForLinkEditor.d.ts +2 -0
- package/dist/field/utils/setFloatingElemPositionForLinkEditor.d.ts.map +1 -0
- package/dist/field/utils/setFloatingElemPositionForLinkEditor.js +22 -0
- package/dist/field/utils/swipe.js +77 -0
- package/dist/field/utils/url.d.ts +11 -0
- package/dist/field/utils/url.d.ts.map +1 -0
- package/dist/field/utils/url.js +30 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/lexical-editor.d.ts +41 -0
- package/dist/lexical-editor.d.ts.map +1 -0
- package/dist/lexical-editor.js +13 -0
- package/dist/richtext-field.d.ts +25 -0
- package/dist/richtext-field.d.ts.map +1 -0
- package/dist/richtext-field.js +62 -0
- package/dist/richtext-field.module.js +8 -0
- package/dist/richtext-field_module.css +18 -0
- package/dist/server.d.ts +64 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +20 -0
- package/dist/static/svg/3-columns.svg +3 -0
- package/dist/static/svg/admonition.svg +1 -0
- package/dist/static/svg/ai.svg +5 -0
- package/dist/static/svg/arrow-clockwise.svg +1 -0
- package/dist/static/svg/arrow-counterclockwise.svg +1 -0
- package/dist/static/svg/bg-color.svg +1 -0
- package/dist/static/svg/camera.svg +1 -0
- package/dist/static/svg/caret-right-fill.svg +1 -0
- package/dist/static/svg/chat-square-quote.svg +1 -0
- package/dist/static/svg/chevron-down.svg +1 -0
- package/dist/static/svg/clipboard.svg +1 -0
- package/dist/static/svg/close.svg +1 -0
- package/dist/static/svg/code.svg +1 -0
- package/dist/static/svg/copy.svg +1 -0
- package/dist/static/svg/diagram-2.svg +1 -0
- package/dist/static/svg/download.svg +1 -0
- package/dist/static/svg/dropdown-more.svg +1 -0
- package/dist/static/svg/file-image.svg +1 -0
- package/dist/static/svg/filetype-gif.svg +1 -0
- package/dist/static/svg/font-color.svg +1 -0
- package/dist/static/svg/font-family.svg +1 -0
- package/dist/static/svg/gear.svg +1 -0
- package/dist/static/svg/horizontal-rule.svg +1 -0
- package/dist/static/svg/indent.svg +1 -0
- package/dist/static/svg/journal-code.svg +1 -0
- package/dist/static/svg/justify.svg +1 -0
- package/dist/static/svg/link.svg +1 -0
- package/dist/static/svg/list-ol.svg +1 -0
- package/dist/static/svg/list-ul.svg +1 -0
- package/dist/static/svg/lock-fill.svg +1 -0
- package/dist/static/svg/lock.svg +1 -0
- package/dist/static/svg/markdown.svg +1 -0
- package/dist/static/svg/mic.svg +1 -0
- package/dist/static/svg/outdent.svg +1 -0
- package/dist/static/svg/paint-bucket.svg +1 -0
- package/dist/static/svg/palette.svg +1 -0
- package/dist/static/svg/pencil-fill.svg +1 -0
- package/dist/static/svg/plug-fill.svg +1 -0
- package/dist/static/svg/plug.svg +1 -0
- package/dist/static/svg/plus.svg +1 -0
- package/dist/static/svg/prettier-error.svg +1 -0
- package/dist/static/svg/prettier.svg +1 -0
- package/dist/static/svg/square-check.svg +1 -0
- package/dist/static/svg/success.svg +1 -0
- package/dist/static/svg/table.svg +1 -0
- package/dist/static/svg/text-center.svg +1 -0
- package/dist/static/svg/text-left.svg +1 -0
- package/dist/static/svg/text-paragraph.svg +1 -0
- package/dist/static/svg/text-right.svg +1 -0
- package/dist/static/svg/trash.svg +1 -0
- package/dist/static/svg/type-bold.svg +1 -0
- package/dist/static/svg/type-h1.svg +1 -0
- package/dist/static/svg/type-h2.svg +1 -0
- package/dist/static/svg/type-h3.svg +1 -0
- package/dist/static/svg/type-h4.svg +1 -0
- package/dist/static/svg/type-h5.svg +1 -0
- package/dist/static/svg/type-h6.svg +1 -0
- package/dist/static/svg/type-italic.svg +1 -0
- package/dist/static/svg/type-strikethrough.svg +1 -0
- package/dist/static/svg/type-subscript.svg +1 -0
- package/dist/static/svg/type-superscript.svg +1 -0
- package/dist/static/svg/type-underline.svg +1 -0
- package/dist/static/svg/upload.svg +1 -0
- package/dist/static/svg/user.svg +1 -0
- package/dist/static/svg/vimeo.svg +1 -0
- package/dist/static/svg/youtube.svg +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/validate/createEmptyEditorState.d.ts +25 -0
- package/dist/validate/createEmptyEditorState.d.ts.map +1 -0
- package/dist/validate/createEmptyEditorState.js +26 -0
- package/dist/validate/hasText.d.ts +3 -0
- package/dist/validate/hasText.d.ts.map +1 -0
- package/dist/validate/hasText.js +20 -0
- package/dist/validate/validate.d.ts +5 -0
- package/dist/validate/validate.d.ts.map +1 -0
- package/dist/validate/validate.js +7 -0
- package/package.json +120 -0
- package/src/declarations.d.ts +4 -0
- package/src/field/apply-value-plugin.tsx +104 -0
- package/src/field/config/default.ts +58 -0
- package/src/field/config/editor-config-context.tsx +60 -0
- package/src/field/config/types.ts +67 -0
- package/src/field/constants.ts +1 -0
- package/src/field/content-editable-inline.tsx +27 -0
- package/src/field/content-editable.css +29 -0
- package/src/field/content-editable.tsx +27 -0
- package/src/field/context/shared-autocomplete-context.tsx +61 -0
- package/src/field/context/shared-history-context.tsx +30 -0
- package/src/field/context/shared-on-change-context.tsx +32 -0
- package/src/field/debug.tsx +39 -0
- package/src/field/editor-component.css +46 -0
- package/src/field/editor-component.md +87 -0
- package/src/field/editor-component.test.tsx +170 -0
- package/src/field/editor-component.tsx +207 -0
- package/src/field/editor-context.tsx +102 -0
- package/src/field/editor-field.tsx +51 -0
- package/src/field/editor.css +1481 -0
- package/src/field/editor.tsx +245 -0
- package/src/field/hooks/use-media-queryts +21 -0
- package/src/field/hooks/use-modal.tsx +59 -0
- package/src/field/hooks/use-report.ts +62 -0
- package/src/field/images/LICENSE.md +5 -0
- package/src/field/images/assets.d.ts +27 -0
- package/src/field/images/cat-typing.gif +0 -0
- package/src/field/images/emoji/1F600.png +0 -0
- package/src/field/images/emoji/1F641.png +0 -0
- package/src/field/images/emoji/1F642.png +0 -0
- package/src/field/images/emoji/2764.png +0 -0
- package/src/field/images/emoji/LICENSE.md +5 -0
- package/src/field/images/icons/3-columns.svg +3 -0
- package/src/field/images/icons/LICENSE.md +5 -0
- package/src/field/images/icons/admonition.svg +1 -0
- package/src/field/images/icons/ai.svg +5 -0
- package/src/field/images/icons/arrow-clockwise.svg +1 -0
- package/src/field/images/icons/arrow-counterclockwise.svg +1 -0
- package/src/field/images/icons/bg-color.svg +1 -0
- package/src/field/images/icons/camera.svg +1 -0
- package/src/field/images/icons/card-checklist.svg +1 -0
- package/src/field/images/icons/caret-right-fill.svg +1 -0
- package/src/field/images/icons/chat-left-text.svg +1 -0
- package/src/field/images/icons/chat-right-dots.svg +1 -0
- package/src/field/images/icons/chat-right-text.svg +1 -0
- package/src/field/images/icons/chat-right.svg +1 -0
- package/src/field/images/icons/chat-square-quote.svg +1 -0
- package/src/field/images/icons/chevron-down.svg +1 -0
- package/src/field/images/icons/clipboard.svg +1 -0
- package/src/field/images/icons/close.svg +1 -0
- package/src/field/images/icons/code.svg +1 -0
- package/src/field/images/icons/comments.svg +1 -0
- package/src/field/images/icons/copy.svg +1 -0
- package/src/field/images/icons/diagram-2.svg +1 -0
- package/src/field/images/icons/download.svg +1 -0
- package/src/field/images/icons/draggable-block-menu.svg +1 -0
- package/src/field/images/icons/dropdown-more.svg +1 -0
- package/src/field/images/icons/figma.svg +1 -0
- package/src/field/images/icons/file-earmark-text.svg +4 -0
- package/src/field/images/icons/file-image.svg +1 -0
- package/src/field/images/icons/filetype-gif.svg +1 -0
- package/src/field/images/icons/font-color.svg +1 -0
- package/src/field/images/icons/font-family.svg +1 -0
- package/src/field/images/icons/gear.svg +1 -0
- package/src/field/images/icons/horizontal-rule.svg +1 -0
- package/src/field/images/icons/indent.svg +1 -0
- package/src/field/images/icons/journal-code.svg +1 -0
- package/src/field/images/icons/journal-text.svg +1 -0
- package/src/field/images/icons/justify.svg +1 -0
- package/src/field/images/icons/link.svg +1 -0
- package/src/field/images/icons/list-ol.svg +1 -0
- package/src/field/images/icons/list-ul.svg +1 -0
- package/src/field/images/icons/lock-fill.svg +1 -0
- package/src/field/images/icons/lock.svg +1 -0
- package/src/field/images/icons/markdown.svg +1 -0
- package/src/field/images/icons/mic.svg +1 -0
- package/src/field/images/icons/outdent.svg +1 -0
- package/src/field/images/icons/paint-bucket.svg +1 -0
- package/src/field/images/icons/palette.svg +1 -0
- package/src/field/images/icons/pencil-fill.svg +1 -0
- package/src/field/images/icons/plug-fill.svg +1 -0
- package/src/field/images/icons/plug.svg +1 -0
- package/src/field/images/icons/plus-slash-minus.svg +1 -0
- package/src/field/images/icons/plus.svg +1 -0
- package/src/field/images/icons/prettier-error.svg +1 -0
- package/src/field/images/icons/prettier.svg +1 -0
- package/src/field/images/icons/send.svg +1 -0
- package/src/field/images/icons/square-check.svg +1 -0
- package/src/field/images/icons/sticky.svg +1 -0
- package/src/field/images/icons/success-alt.svg +1 -0
- package/src/field/images/icons/success.svg +1 -0
- package/src/field/images/icons/table.svg +1 -0
- package/src/field/images/icons/text-center.svg +1 -0
- package/src/field/images/icons/text-left.svg +1 -0
- package/src/field/images/icons/text-paragraph.svg +1 -0
- package/src/field/images/icons/text-right.svg +1 -0
- package/src/field/images/icons/trash.svg +1 -0
- package/src/field/images/icons/trash3.svg +1 -0
- package/src/field/images/icons/tweet.svg +1 -0
- package/src/field/images/icons/type-bold.svg +1 -0
- package/src/field/images/icons/type-h1.svg +1 -0
- package/src/field/images/icons/type-h2.svg +1 -0
- package/src/field/images/icons/type-h3.svg +1 -0
- package/src/field/images/icons/type-h4.svg +1 -0
- package/src/field/images/icons/type-h5.svg +1 -0
- package/src/field/images/icons/type-h6.svg +1 -0
- package/src/field/images/icons/type-italic.svg +1 -0
- package/src/field/images/icons/type-strikethrough.svg +1 -0
- package/src/field/images/icons/type-subscript.svg +1 -0
- package/src/field/images/icons/type-superscript.svg +1 -0
- package/src/field/images/icons/type-underline.svg +1 -0
- package/src/field/images/icons/upload.svg +1 -0
- package/src/field/images/icons/user.svg +1 -0
- package/src/field/images/icons/vimeo.svg +1 -0
- package/src/field/images/icons/youtube.svg +1 -0
- package/src/field/images/landscape.jpg +0 -0
- package/src/field/images/logo.svg +1 -0
- package/src/field/images/yellow-flower-small.jpg +0 -0
- package/src/field/images/yellow-flower.jpg +0 -0
- package/src/field/lexical-populate-shared.ts +188 -0
- package/src/field/nodes/admonition-node/admonition-node-component.css +115 -0
- package/src/field/nodes/admonition-node/admonition-node-component.tsx +256 -0
- package/src/field/nodes/admonition-node/admonition-node.tsx +189 -0
- package/src/field/nodes/admonition-node/icons/danger-icon.css +11 -0
- package/src/field/nodes/admonition-node/icons/danger-icon.js +17 -0
- package/src/field/nodes/admonition-node/icons/danger-icon.tsx +19 -0
- package/src/field/nodes/admonition-node/icons/index.js +4 -0
- package/src/field/nodes/admonition-node/icons/index.ts +4 -0
- package/src/field/nodes/admonition-node/icons/note-icon.css +11 -0
- package/src/field/nodes/admonition-node/icons/note-icon.js +17 -0
- package/src/field/nodes/admonition-node/icons/note-icon.tsx +19 -0
- package/src/field/nodes/admonition-node/icons/tip-icon.css +11 -0
- package/src/field/nodes/admonition-node/icons/tip-icon.js +17 -0
- package/src/field/nodes/admonition-node/icons/tip-icon.tsx +19 -0
- package/src/field/nodes/admonition-node/icons/warning-icon.css +11 -0
- package/src/field/nodes/admonition-node/icons/warning-icon.js +17 -0
- package/src/field/nodes/admonition-node/icons/warning-icon.tsx +19 -0
- package/src/field/nodes/admonition-node/index.ts +14 -0
- package/src/field/nodes/admonition-node/types.ts +33 -0
- package/src/field/nodes/document-relation.ts +33 -0
- package/src/field/nodes/index.ts +47 -0
- package/src/field/nodes/inline-image-node/index.ts +10 -0
- package/src/field/nodes/inline-image-node/inline-image-node-component.css +205 -0
- package/src/field/nodes/inline-image-node/inline-image-node-component.tsx +342 -0
- package/src/field/nodes/inline-image-node/inline-image-node.tsx +328 -0
- package/src/field/nodes/inline-image-node/types.ts +43 -0
- package/src/field/nodes/layout-container-node/layout-container-node.ts +97 -0
- package/src/field/nodes/layout-container-node/layout-item-node.ts +63 -0
- package/src/field/nodes/link-nodes/auto-link-node.ts +64 -0
- package/src/field/nodes/link-nodes/index.ts +3 -0
- package/src/field/nodes/link-nodes/link-node.ts +426 -0
- package/src/field/nodes/link-nodes/types.ts +33 -0
- package/src/field/nodes/vimeo-node/index.tsx +172 -0
- package/src/field/nodes/youtube-node/index.tsx +178 -0
- package/src/field/plugins/admonition-plugin/admonition-modal.css +25 -0
- package/src/field/plugins/admonition-plugin/admonition-modal.tsx +187 -0
- package/src/field/plugins/admonition-plugin/fields.ts +103 -0
- package/src/field/plugins/admonition-plugin/index.tsx +105 -0
- package/src/field/plugins/admonition-plugin/types.ts +37 -0
- package/src/field/plugins/auto-embed-plugin/auto-embed-modal.css +15 -0
- package/src/field/plugins/auto-embed-plugin/auto-embed-modal.tsx +110 -0
- package/src/field/plugins/auto-embed-plugin/index.tsx +323 -0
- package/src/field/plugins/code-highlight-plugin/index.ts +23 -0
- package/src/field/plugins/drag-drop-paste-plugin/index.ts +47 -0
- package/src/field/plugins/floating-text-format-toolbar-plugin/index.css +148 -0
- package/src/field/plugins/floating-text-format-toolbar-plugin/index.tsx +398 -0
- package/src/field/plugins/inline-image-plugin/fields.ts +21 -0
- package/src/field/plugins/inline-image-plugin/index.tsx +202 -0
- package/src/field/plugins/inline-image-plugin/inline-image-modal.css +29 -0
- package/src/field/plugins/inline-image-plugin/inline-image-modal.tsx +314 -0
- package/src/field/plugins/inline-image-plugin/populate.ts +48 -0
- package/src/field/plugins/inline-image-plugin/types.ts +39 -0
- package/src/field/plugins/inline-image-plugin/utils.ts +113 -0
- package/src/field/plugins/layout-plugin/insert-layout-modal.css +19 -0
- package/src/field/plugins/layout-plugin/insert-layout-modal.tsx +100 -0
- package/src/field/plugins/layout-plugin/layout-plugin.tsx +162 -0
- package/src/field/plugins/link-plugin/auto-link/auto-link-plugin.tsx +327 -0
- package/src/field/plugins/link-plugin/auto-link/index.tsx +35 -0
- package/src/field/plugins/link-plugin/link/floating-link-editor.css +128 -0
- package/src/field/plugins/link-plugin/link/floating-link-editor.tsx +348 -0
- package/src/field/plugins/link-plugin/link/index.tsx +99 -0
- package/src/field/plugins/link-plugin/link/link-modal.tsx +376 -0
- package/src/field/plugins/link-plugin/link/types.ts +20 -0
- package/src/field/plugins/link-plugin/populate.ts +48 -0
- package/src/field/plugins/table-action-menu-plugin/index.tsx +804 -0
- package/src/field/plugins/table-plugin/index.tsx +33 -0
- package/src/field/plugins/table-plugin/table-modal.css +19 -0
- package/src/field/plugins/table-plugin/table-modal.tsx +127 -0
- package/src/field/plugins/toolbar-plugin/index.tsx +937 -0
- package/src/field/plugins/treeview-plugin/index.tsx +29 -0
- package/src/field/plugins/vimeo-plugin/index.ts +42 -0
- package/src/field/plugins/youtube-plugin/index.ts +43 -0
- package/src/field/shared/canUseDOM.ts +10 -0
- package/src/field/shared/caretFromPoint.bak +40 -0
- package/src/field/shared/environment.ts +44 -0
- package/src/field/shared/invariant.ts +25 -0
- package/src/field/shared/simpleDiffWithCursor.ts +40 -0
- package/src/field/shared/useLayoutEffect.ts +15 -0
- package/src/field/shared/useModalFormState.ts +48 -0
- package/src/field/shared/warnOnlyOnce.ts +21 -0
- package/src/field/themes/lexical-editor-theme.css +565 -0
- package/src/field/themes/lexical-editor-theme.js +104 -0
- package/src/field/themes/lexical-editor-theme.tsx +115 -0
- package/src/field/toolbar-extensions.tsx +93 -0
- package/src/field/types.ts +19 -0
- package/src/field/ui/button.css +45 -0
- package/src/field/ui/button.tsx +51 -0
- package/src/field/ui/checkbox.css +52 -0
- package/src/field/ui/color-picker.css +88 -0
- package/src/field/ui/color-picker.tsx +395 -0
- package/src/field/ui/dialog.css +17 -0
- package/src/field/ui/dialog.tsx +29 -0
- package/src/field/ui/dropdown.tsx +217 -0
- package/src/field/ui/file-input.tsx +44 -0
- package/src/field/ui/input.css +32 -0
- package/src/field/ui/modal.css +84 -0
- package/src/field/ui/modal.tsx +106 -0
- package/src/field/ui/placeholder-inline.tsx +28 -0
- package/src/field/ui/placeholder.css +33 -0
- package/src/field/ui/placeholder.tsx +32 -0
- package/src/field/ui/select.css +34 -0
- package/src/field/ui/select.tsx +38 -0
- package/src/field/ui/switch.tsx +33 -0
- package/src/field/ui/text-area.css +45 -0
- package/src/field/ui/text-area.tsx +50 -0
- package/src/field/ui/text-input.tsx +51 -0
- package/src/field/utils/cloneDeep.ts +57 -0
- package/src/field/utils/deepEqual.ts +54 -0
- package/src/field/utils/emoji-list.ts +16615 -0
- package/src/field/utils/getDOMRangeRect.ts +24 -0
- package/src/field/utils/getSelectedNode.ts +25 -0
- package/src/field/utils/guard.ts +10 -0
- package/src/field/utils/hashSerializedState.ts +34 -0
- package/src/field/utils/isMobileWidth.ts +7 -0
- package/src/field/utils/joinClasses.ts +11 -0
- package/src/field/utils/point.ts +52 -0
- package/src/field/utils/rect.ts +142 -0
- package/src/field/utils/setFloatingElemPosition.ts +48 -0
- package/src/field/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
- package/src/field/utils/swipe.ts +129 -0
- package/src/field/utils/url.ts +49 -0
- package/src/index.ts +26 -0
- package/src/lexical-editor.tsx +56 -0
- package/src/richtext-field.module.css +29 -0
- package/src/richtext-field.tsx +113 -0
- package/src/server.ts +85 -0
- package/src/types.ts +43 -0
- package/src/validate/createEmptyEditorState.ts +52 -0
- package/src/validate/hasText.test.ts +89 -0
- package/src/validate/hasText.ts +34 -0
- package/src/validate/validate.ts +18 -0
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the MIT license found in the
|
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
import type * as React from 'react'
|
|
19
|
+
import { Fragment, useCallback, useEffect, useState } from 'react'
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
$createCodeNode,
|
|
23
|
+
$isCodeNode,
|
|
24
|
+
CODE_LANGUAGE_FRIENDLY_NAME_MAP,
|
|
25
|
+
CODE_LANGUAGE_MAP,
|
|
26
|
+
getLanguageFriendlyName,
|
|
27
|
+
} from '@lexical/code'
|
|
28
|
+
import {
|
|
29
|
+
$isListNode,
|
|
30
|
+
INSERT_CHECK_LIST_COMMAND,
|
|
31
|
+
INSERT_ORDERED_LIST_COMMAND,
|
|
32
|
+
INSERT_UNORDERED_LIST_COMMAND,
|
|
33
|
+
ListNode,
|
|
34
|
+
REMOVE_LIST_COMMAND,
|
|
35
|
+
} from '@lexical/list'
|
|
36
|
+
import { INSERT_EMBED_COMMAND } from '@lexical/react/LexicalAutoEmbedPlugin'
|
|
37
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
|
38
|
+
import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode'
|
|
39
|
+
import { INSERT_HORIZONTAL_RULE_COMMAND } from '@lexical/react/LexicalHorizontalRuleNode'
|
|
40
|
+
import {
|
|
41
|
+
$createHeadingNode,
|
|
42
|
+
$createQuoteNode,
|
|
43
|
+
$isHeadingNode,
|
|
44
|
+
$isQuoteNode,
|
|
45
|
+
type HeadingTagType,
|
|
46
|
+
} from '@lexical/rich-text'
|
|
47
|
+
import { $setBlocksType } from '@lexical/selection'
|
|
48
|
+
import { $isTableNode } from '@lexical/table'
|
|
49
|
+
import {
|
|
50
|
+
$findMatchingParent,
|
|
51
|
+
$getNearestBlockElementAncestorOrThrow,
|
|
52
|
+
$getNearestNodeOfType,
|
|
53
|
+
mergeRegister,
|
|
54
|
+
} from '@lexical/utils'
|
|
55
|
+
// import { formatDrawerSlug, useEditDepth, useModal as usePayloadModal } from '@payloadcms/ui'
|
|
56
|
+
import type { LexicalCommand, LexicalEditor, NodeKey } from 'lexical'
|
|
57
|
+
import {
|
|
58
|
+
$createParagraphNode,
|
|
59
|
+
$getNodeByKey,
|
|
60
|
+
$getSelection,
|
|
61
|
+
$isRangeSelection,
|
|
62
|
+
$isRootOrShadowRoot,
|
|
63
|
+
$isTextNode,
|
|
64
|
+
CAN_REDO_COMMAND,
|
|
65
|
+
CAN_UNDO_COMMAND,
|
|
66
|
+
COMMAND_PRIORITY_CRITICAL,
|
|
67
|
+
COMMAND_PRIORITY_NORMAL,
|
|
68
|
+
FORMAT_ELEMENT_COMMAND,
|
|
69
|
+
FORMAT_TEXT_COMMAND,
|
|
70
|
+
INDENT_CONTENT_COMMAND,
|
|
71
|
+
KEY_MODIFIER_COMMAND,
|
|
72
|
+
OUTDENT_CONTENT_COMMAND,
|
|
73
|
+
REDO_COMMAND,
|
|
74
|
+
SELECTION_CHANGE_COMMAND,
|
|
75
|
+
UNDO_COMMAND,
|
|
76
|
+
} from 'lexical'
|
|
77
|
+
|
|
78
|
+
import { useEditorConfig } from '../../config/editor-config-context'
|
|
79
|
+
import {
|
|
80
|
+
$isLinkNode,
|
|
81
|
+
type LinkAttributes,
|
|
82
|
+
OPEN_LINK_MODAL_COMMAND,
|
|
83
|
+
TOGGLE_LINK_COMMAND,
|
|
84
|
+
} from '../../nodes/link-nodes'
|
|
85
|
+
import { IS_APPLE } from '../../shared/environment'
|
|
86
|
+
import { useToolbarExtensions } from '../../toolbar-extensions'
|
|
87
|
+
import { DropDown, DropDownItem } from '../../ui/dropdown'
|
|
88
|
+
import { getSelectedNode } from '../../utils/getSelectedNode'
|
|
89
|
+
import { sanitizeUrl } from '../../utils/url'
|
|
90
|
+
import { OPEN_ADMONITION_MODAL_COMMAND } from '../admonition-plugin'
|
|
91
|
+
import { EmbedConfigs } from '../auto-embed-plugin'
|
|
92
|
+
import { OPEN_INLINE_IMAGE_MODAL_COMMAND } from '../inline-image-plugin'
|
|
93
|
+
import { OPEN_INSERT_LAYOUT_MODAL_COMMAND } from '../layout-plugin/layout-plugin'
|
|
94
|
+
import { OPEN_TABLE_MODAL_COMMAND } from '../table-plugin'
|
|
95
|
+
|
|
96
|
+
const blockTypeToBlockName = {
|
|
97
|
+
bullet: 'Bulleted List',
|
|
98
|
+
check: 'Check List',
|
|
99
|
+
code: 'Code Block',
|
|
100
|
+
h1: 'Heading 1',
|
|
101
|
+
h2: 'Heading 2',
|
|
102
|
+
h3: 'Heading 3',
|
|
103
|
+
h4: 'Heading 4',
|
|
104
|
+
h5: 'Heading 5',
|
|
105
|
+
h6: 'Heading 6',
|
|
106
|
+
number: 'Numbered List',
|
|
107
|
+
paragraph: 'Normal',
|
|
108
|
+
quote: 'Quote',
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const rootTypeToRootName = {
|
|
112
|
+
root: 'Root',
|
|
113
|
+
table: 'Table',
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getCodeLanguageOptions(): Array<[string, string]> {
|
|
117
|
+
const options: Array<[string, string]> = []
|
|
118
|
+
|
|
119
|
+
for (const [lang, friendlyName] of Object.entries(CODE_LANGUAGE_FRIENDLY_NAME_MAP)) {
|
|
120
|
+
options.push([lang, friendlyName])
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return options
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const CODE_LANGUAGE_OPTIONS = getCodeLanguageOptions()
|
|
127
|
+
|
|
128
|
+
function dropDownActiveClass(active: boolean): string {
|
|
129
|
+
if (active) return 'active dropdown-item-active'
|
|
130
|
+
return ''
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function BlockFormatDropDown({
|
|
134
|
+
editor,
|
|
135
|
+
blockType,
|
|
136
|
+
rootType,
|
|
137
|
+
disabled = false,
|
|
138
|
+
}: {
|
|
139
|
+
blockType: keyof typeof blockTypeToBlockName
|
|
140
|
+
rootType: keyof typeof rootTypeToRootName
|
|
141
|
+
editor: LexicalEditor
|
|
142
|
+
disabled?: boolean
|
|
143
|
+
}): React.JSX.Element {
|
|
144
|
+
const {
|
|
145
|
+
config: {
|
|
146
|
+
options: { checkListPlugin, listPlugin, codeHighlightPlugin },
|
|
147
|
+
},
|
|
148
|
+
} = useEditorConfig()
|
|
149
|
+
|
|
150
|
+
const formatParagraph = (): void => {
|
|
151
|
+
editor.update(() => {
|
|
152
|
+
const selection = $getSelection()
|
|
153
|
+
if ($isRangeSelection(selection)) {
|
|
154
|
+
$setBlocksType(selection, () => $createParagraphNode())
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const formatHeading = (headingSize: HeadingTagType): void => {
|
|
160
|
+
if (blockType !== headingSize) {
|
|
161
|
+
editor.update(() => {
|
|
162
|
+
const selection = $getSelection()
|
|
163
|
+
if ($isRangeSelection(selection)) {
|
|
164
|
+
$setBlocksType(selection, () => $createHeadingNode(headingSize))
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const formatBulletList = (): void => {
|
|
171
|
+
if (blockType !== 'bullet') {
|
|
172
|
+
editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined)
|
|
173
|
+
} else {
|
|
174
|
+
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const formatCheckList = (): void => {
|
|
179
|
+
if (blockType !== 'check') {
|
|
180
|
+
editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined)
|
|
181
|
+
} else {
|
|
182
|
+
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const formatNumberedList = (): void => {
|
|
187
|
+
if (blockType !== 'number') {
|
|
188
|
+
editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined)
|
|
189
|
+
} else {
|
|
190
|
+
editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const formatQuote = (): void => {
|
|
195
|
+
if (blockType !== 'quote') {
|
|
196
|
+
editor.update(() => {
|
|
197
|
+
const selection = $getSelection()
|
|
198
|
+
if ($isRangeSelection(selection)) {
|
|
199
|
+
$setBlocksType(selection, () => $createQuoteNode())
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const formatCode = (): void => {
|
|
206
|
+
if (blockType !== 'code') {
|
|
207
|
+
editor.update(() => {
|
|
208
|
+
let selection = $getSelection()
|
|
209
|
+
|
|
210
|
+
if ($isRangeSelection(selection)) {
|
|
211
|
+
if (selection.isCollapsed()) {
|
|
212
|
+
$setBlocksType(selection, () => $createCodeNode())
|
|
213
|
+
} else {
|
|
214
|
+
const textContent = selection.getTextContent()
|
|
215
|
+
const codeNode = $createCodeNode()
|
|
216
|
+
selection.insertNodes([codeNode])
|
|
217
|
+
selection = $getSelection()
|
|
218
|
+
if ($isRangeSelection(selection)) {
|
|
219
|
+
selection.insertRawText(textContent)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return (
|
|
228
|
+
<DropDown
|
|
229
|
+
disabled={disabled}
|
|
230
|
+
buttonClassName="toolbar-item block-controls"
|
|
231
|
+
buttonIconClassName={`icon block-type ${blockType}`}
|
|
232
|
+
buttonLabel={blockTypeToBlockName[blockType]}
|
|
233
|
+
buttonAriaLabel="Formatting options for text style"
|
|
234
|
+
>
|
|
235
|
+
<DropDownItem
|
|
236
|
+
className={`item ${dropDownActiveClass(blockType === 'paragraph')}`}
|
|
237
|
+
onClick={formatParagraph}
|
|
238
|
+
>
|
|
239
|
+
<i className="icon paragraph" />
|
|
240
|
+
<span className="text">Normal</span>
|
|
241
|
+
</DropDownItem>
|
|
242
|
+
<DropDownItem
|
|
243
|
+
className={`item ${dropDownActiveClass(blockType === 'h1')}`}
|
|
244
|
+
onClick={() => {
|
|
245
|
+
formatHeading('h1')
|
|
246
|
+
}}
|
|
247
|
+
>
|
|
248
|
+
<i className="icon h1" />
|
|
249
|
+
<span className="text">Heading 1</span>
|
|
250
|
+
</DropDownItem>
|
|
251
|
+
<DropDownItem
|
|
252
|
+
className={`item ${dropDownActiveClass(blockType === 'h2')}`}
|
|
253
|
+
onClick={() => {
|
|
254
|
+
formatHeading('h2')
|
|
255
|
+
}}
|
|
256
|
+
>
|
|
257
|
+
<i className="icon h2" />
|
|
258
|
+
<span className="text">Heading 2</span>
|
|
259
|
+
</DropDownItem>
|
|
260
|
+
<DropDownItem
|
|
261
|
+
className={`item ${dropDownActiveClass(blockType === 'h3')}`}
|
|
262
|
+
onClick={() => {
|
|
263
|
+
formatHeading('h3')
|
|
264
|
+
}}
|
|
265
|
+
>
|
|
266
|
+
<i className="icon h3" />
|
|
267
|
+
<span className="text">Heading 3</span>
|
|
268
|
+
</DropDownItem>
|
|
269
|
+
<DropDownItem
|
|
270
|
+
className={`item ${dropDownActiveClass(blockType === 'h4')}`}
|
|
271
|
+
onClick={() => {
|
|
272
|
+
formatHeading('h4')
|
|
273
|
+
}}
|
|
274
|
+
>
|
|
275
|
+
<i className="icon h4" />
|
|
276
|
+
<span className="text">Heading 4</span>
|
|
277
|
+
</DropDownItem>
|
|
278
|
+
{listPlugin && (
|
|
279
|
+
<>
|
|
280
|
+
<DropDownItem
|
|
281
|
+
className={`item ${dropDownActiveClass(blockType === 'bullet')}`}
|
|
282
|
+
onClick={formatBulletList}
|
|
283
|
+
>
|
|
284
|
+
<i className="icon bullet-list" />
|
|
285
|
+
<span className="text">Bullet List</span>
|
|
286
|
+
</DropDownItem>
|
|
287
|
+
<DropDownItem
|
|
288
|
+
className={`item ${dropDownActiveClass(blockType === 'number')}`}
|
|
289
|
+
onClick={formatNumberedList}
|
|
290
|
+
>
|
|
291
|
+
<i className="icon numbered-list" />
|
|
292
|
+
<span className="text">Numbered List</span>
|
|
293
|
+
</DropDownItem>
|
|
294
|
+
</>
|
|
295
|
+
)}
|
|
296
|
+
|
|
297
|
+
{checkListPlugin && (
|
|
298
|
+
<DropDownItem
|
|
299
|
+
className={`item ${dropDownActiveClass(blockType === 'check')}`}
|
|
300
|
+
onClick={formatCheckList}
|
|
301
|
+
>
|
|
302
|
+
<i className="icon check-list" />
|
|
303
|
+
<span className="text">Check List</span>
|
|
304
|
+
</DropDownItem>
|
|
305
|
+
)}
|
|
306
|
+
|
|
307
|
+
<DropDownItem
|
|
308
|
+
className={`item ${dropDownActiveClass(blockType === 'quote')}`}
|
|
309
|
+
onClick={formatQuote}
|
|
310
|
+
>
|
|
311
|
+
<i className="icon quote" />
|
|
312
|
+
<span className="text">Quote</span>
|
|
313
|
+
</DropDownItem>
|
|
314
|
+
{codeHighlightPlugin && (
|
|
315
|
+
<DropDownItem
|
|
316
|
+
className={`item ${dropDownActiveClass(blockType === 'code')}`}
|
|
317
|
+
onClick={formatCode}
|
|
318
|
+
>
|
|
319
|
+
<i className="icon code" />
|
|
320
|
+
<span className="text">Code Block</span>
|
|
321
|
+
</DropDownItem>
|
|
322
|
+
)}
|
|
323
|
+
</DropDown>
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function Divider(): React.JSX.Element {
|
|
328
|
+
return <div className="divider" />
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function ToolbarPlugin(): React.JSX.Element {
|
|
332
|
+
const [editor] = useLexicalComposerContext()
|
|
333
|
+
const [activeEditor, setActiveEditor] = useState(editor)
|
|
334
|
+
const [blockType, setBlockType] = useState<keyof typeof blockTypeToBlockName>('paragraph')
|
|
335
|
+
const [rootType, setRootType] = useState<keyof typeof rootTypeToRootName>('root')
|
|
336
|
+
const [selectedElementKey, setSelectedElementKey] = useState<NodeKey | null>(null)
|
|
337
|
+
const [_toggleAiDrawerCommand, _setToggleAiDrawerCommand] = useState<LexicalCommand<void> | null>(
|
|
338
|
+
null
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
const [isLink, setIsLink] = useState(false)
|
|
342
|
+
const [isBold, setIsBold] = useState(false)
|
|
343
|
+
const [isItalic, setIsItalic] = useState(false)
|
|
344
|
+
const [isUnderline, setIsUnderline] = useState(false)
|
|
345
|
+
const [isStrikethrough, setIsStrikethrough] = useState(false)
|
|
346
|
+
const [isSubscript, setIsSubscript] = useState(false)
|
|
347
|
+
const [isSuperscript, setIsSuperscript] = useState(false)
|
|
348
|
+
const [isCode, setIsCode] = useState(false)
|
|
349
|
+
const [canUndo, setCanUndo] = useState(false)
|
|
350
|
+
const [canRedo, setCanRedo] = useState(false)
|
|
351
|
+
const [isRTL, _setIsRTL] = useState(false)
|
|
352
|
+
const [codeLanguage, setCodeLanguage] = useState<string>('')
|
|
353
|
+
const [isEditable, setIsEditable] = useState(() => editor.isEditable())
|
|
354
|
+
const { items: toolbarExtensionItems } = useToolbarExtensions()
|
|
355
|
+
const {
|
|
356
|
+
uuid,
|
|
357
|
+
config: {
|
|
358
|
+
options: {
|
|
359
|
+
textAlignment,
|
|
360
|
+
tablePlugin,
|
|
361
|
+
inlineImagePlugin,
|
|
362
|
+
admonitionPlugin,
|
|
363
|
+
horizontalRulePlugin,
|
|
364
|
+
layoutPlugin,
|
|
365
|
+
autoEmbedPlugin,
|
|
366
|
+
undoRedo,
|
|
367
|
+
textStyle,
|
|
368
|
+
inlineCode,
|
|
369
|
+
links,
|
|
370
|
+
},
|
|
371
|
+
},
|
|
372
|
+
} = useEditorConfig()
|
|
373
|
+
// const { openModal } = usePayloadModal()
|
|
374
|
+
// const editDepth = useEditDepth()
|
|
375
|
+
|
|
376
|
+
const $updateToolbar = useCallback(() => {
|
|
377
|
+
const selection = $getSelection()
|
|
378
|
+
if ($isRangeSelection(selection)) {
|
|
379
|
+
const anchorNode = selection.anchor.getNode()
|
|
380
|
+
let element =
|
|
381
|
+
anchorNode.getKey() === 'root'
|
|
382
|
+
? anchorNode
|
|
383
|
+
: $findMatchingParent(anchorNode, (e) => {
|
|
384
|
+
const parent = e.getParent()
|
|
385
|
+
return parent !== null && $isRootOrShadowRoot(parent)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
if (element === null) {
|
|
389
|
+
element = anchorNode.getTopLevelElementOrThrow()
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const elementKey = element.getKey()
|
|
393
|
+
const elementDOM = activeEditor.getElementByKey(elementKey)
|
|
394
|
+
|
|
395
|
+
// Update text format
|
|
396
|
+
setIsBold(selection.hasFormat('bold'))
|
|
397
|
+
setIsItalic(selection.hasFormat('italic'))
|
|
398
|
+
setIsUnderline(selection.hasFormat('underline'))
|
|
399
|
+
setIsStrikethrough(selection.hasFormat('strikethrough'))
|
|
400
|
+
setIsSubscript(selection.hasFormat('subscript'))
|
|
401
|
+
setIsSuperscript(selection.hasFormat('superscript'))
|
|
402
|
+
setIsCode(selection.hasFormat('code'))
|
|
403
|
+
// setIsRTL($isParentElementRTL(selection))
|
|
404
|
+
|
|
405
|
+
// Update links
|
|
406
|
+
const node = getSelectedNode(selection)
|
|
407
|
+
const parent = node.getParent()
|
|
408
|
+
if ($isLinkNode(parent) || $isLinkNode(node)) {
|
|
409
|
+
setIsLink(true)
|
|
410
|
+
} else {
|
|
411
|
+
setIsLink(false)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const tableNode = $findMatchingParent(node, $isTableNode)
|
|
415
|
+
if ($isTableNode(tableNode)) {
|
|
416
|
+
setRootType('table')
|
|
417
|
+
} else {
|
|
418
|
+
setRootType('root')
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (elementDOM !== null) {
|
|
422
|
+
setSelectedElementKey(elementKey)
|
|
423
|
+
if ($isListNode(element)) {
|
|
424
|
+
const parentList = $getNearestNodeOfType<ListNode>(anchorNode, ListNode)
|
|
425
|
+
const type = parentList != null ? parentList.getListType() : element.getListType()
|
|
426
|
+
setBlockType(type)
|
|
427
|
+
} else {
|
|
428
|
+
const type = $isHeadingNode(element) ? element.getTag() : element.getType()
|
|
429
|
+
if (type in blockTypeToBlockName) {
|
|
430
|
+
setBlockType(type as keyof typeof blockTypeToBlockName)
|
|
431
|
+
}
|
|
432
|
+
if ($isCodeNode(element)) {
|
|
433
|
+
const language = element.getLanguage() as keyof typeof CODE_LANGUAGE_MAP
|
|
434
|
+
setCodeLanguage(language != null ? (CODE_LANGUAGE_MAP[language] ?? language) : '')
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}, [activeEditor])
|
|
440
|
+
|
|
441
|
+
useEffect(() => {
|
|
442
|
+
return editor.registerCommand(
|
|
443
|
+
SELECTION_CHANGE_COMMAND,
|
|
444
|
+
(_payload, newEditor) => {
|
|
445
|
+
$updateToolbar()
|
|
446
|
+
setActiveEditor(newEditor)
|
|
447
|
+
return false
|
|
448
|
+
},
|
|
449
|
+
COMMAND_PRIORITY_CRITICAL
|
|
450
|
+
)
|
|
451
|
+
}, [editor, $updateToolbar])
|
|
452
|
+
|
|
453
|
+
useEffect(() => {
|
|
454
|
+
return mergeRegister(
|
|
455
|
+
editor.registerEditableListener((editable) => {
|
|
456
|
+
setIsEditable(editable)
|
|
457
|
+
}),
|
|
458
|
+
activeEditor.registerUpdateListener(({ editorState }) => {
|
|
459
|
+
editorState.read(() => {
|
|
460
|
+
$updateToolbar()
|
|
461
|
+
})
|
|
462
|
+
}),
|
|
463
|
+
activeEditor.registerCommand<boolean>(
|
|
464
|
+
CAN_UNDO_COMMAND,
|
|
465
|
+
(payload) => {
|
|
466
|
+
setCanUndo(payload)
|
|
467
|
+
return false
|
|
468
|
+
},
|
|
469
|
+
COMMAND_PRIORITY_CRITICAL
|
|
470
|
+
),
|
|
471
|
+
activeEditor.registerCommand<boolean>(
|
|
472
|
+
CAN_REDO_COMMAND,
|
|
473
|
+
(payload) => {
|
|
474
|
+
setCanRedo(payload)
|
|
475
|
+
return false
|
|
476
|
+
},
|
|
477
|
+
COMMAND_PRIORITY_CRITICAL
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
}, [$updateToolbar, activeEditor, editor])
|
|
481
|
+
|
|
482
|
+
useEffect(() => {
|
|
483
|
+
return activeEditor.registerCommand(
|
|
484
|
+
KEY_MODIFIER_COMMAND,
|
|
485
|
+
(payload) => {
|
|
486
|
+
const event: KeyboardEvent = payload
|
|
487
|
+
const { code, ctrlKey, metaKey } = event
|
|
488
|
+
|
|
489
|
+
if (code === 'KeyK' && (ctrlKey || metaKey)) {
|
|
490
|
+
event.preventDefault()
|
|
491
|
+
return activeEditor.dispatchCommand(
|
|
492
|
+
TOGGLE_LINK_COMMAND,
|
|
493
|
+
sanitizeUrl('https://') as LinkAttributes
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
return false
|
|
497
|
+
},
|
|
498
|
+
COMMAND_PRIORITY_NORMAL
|
|
499
|
+
)
|
|
500
|
+
}, [activeEditor])
|
|
501
|
+
|
|
502
|
+
const clearFormatting = useCallback(() => {
|
|
503
|
+
activeEditor.update(() => {
|
|
504
|
+
const selection = $getSelection()
|
|
505
|
+
if ($isRangeSelection(selection)) {
|
|
506
|
+
const anchor = selection.anchor
|
|
507
|
+
const focus = selection.focus
|
|
508
|
+
const nodes = selection.getNodes()
|
|
509
|
+
|
|
510
|
+
if (anchor.key === focus.key && anchor.offset === focus.offset) {
|
|
511
|
+
return
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
nodes.forEach((node, idx) => {
|
|
515
|
+
// We split the first and last node by the selection
|
|
516
|
+
// So that we don't format unselected text inside those nodes
|
|
517
|
+
if ($isTextNode(node)) {
|
|
518
|
+
// Use a separate variable to ensure TS does not lose the refinement
|
|
519
|
+
let textNode = node
|
|
520
|
+
if (idx === 0 && anchor.offset !== 0) {
|
|
521
|
+
textNode = textNode.splitText(anchor.offset)[1] ?? textNode
|
|
522
|
+
}
|
|
523
|
+
if (idx === nodes.length - 1) {
|
|
524
|
+
textNode = textNode.splitText(focus.offset)[0] ?? textNode
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (textNode.__style !== '') {
|
|
528
|
+
textNode.setStyle('')
|
|
529
|
+
}
|
|
530
|
+
if (textNode.__format !== 0) {
|
|
531
|
+
textNode.setFormat(0)
|
|
532
|
+
$getNearestBlockElementAncestorOrThrow(textNode).setFormat('')
|
|
533
|
+
}
|
|
534
|
+
} else if ($isHeadingNode(node) || $isQuoteNode(node)) {
|
|
535
|
+
node.replace($createParagraphNode(), true)
|
|
536
|
+
} else if ($isDecoratorBlockNode(node)) {
|
|
537
|
+
node.setFormat('')
|
|
538
|
+
}
|
|
539
|
+
})
|
|
540
|
+
}
|
|
541
|
+
})
|
|
542
|
+
}, [activeEditor])
|
|
543
|
+
|
|
544
|
+
// const linkDrawerSlug = formatDrawerSlug({
|
|
545
|
+
// slug: `rich-text-link-lexical-${uuid}`,
|
|
546
|
+
// depth: editDepth,
|
|
547
|
+
// })
|
|
548
|
+
|
|
549
|
+
const insertLink = useCallback(() => {
|
|
550
|
+
if (!isLink) {
|
|
551
|
+
// Only insert a placeholder LinkNode (and open the modal) if there is
|
|
552
|
+
// text selected (at least one character) — empty selections can't be
|
|
553
|
+
// wrapped in a link.
|
|
554
|
+
const editorState = activeEditor.getEditorState()
|
|
555
|
+
editorState.read(() => {
|
|
556
|
+
const selection = $getSelection()
|
|
557
|
+
if ($isRangeSelection(selection)) {
|
|
558
|
+
if (selection.focus.offset !== selection.anchor.offset) {
|
|
559
|
+
const linkAttributes: LinkAttributes = {
|
|
560
|
+
linkType: 'custom',
|
|
561
|
+
url: 'https://',
|
|
562
|
+
}
|
|
563
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, linkAttributes)
|
|
564
|
+
editor.dispatchCommand(OPEN_LINK_MODAL_COMMAND, undefined)
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
})
|
|
568
|
+
} else {
|
|
569
|
+
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null)
|
|
570
|
+
}
|
|
571
|
+
}, [editor, isLink, activeEditor])
|
|
572
|
+
|
|
573
|
+
const onCodeLanguageSelect = useCallback(
|
|
574
|
+
(value: string) => {
|
|
575
|
+
activeEditor.update(() => {
|
|
576
|
+
if (selectedElementKey !== null) {
|
|
577
|
+
const node = $getNodeByKey(selectedElementKey)
|
|
578
|
+
if ($isCodeNode(node)) {
|
|
579
|
+
node.setLanguage(value)
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
})
|
|
583
|
+
},
|
|
584
|
+
[activeEditor, selectedElementKey]
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
return (
|
|
588
|
+
<div className="toolbar">
|
|
589
|
+
{undoRedo && (
|
|
590
|
+
<>
|
|
591
|
+
<button
|
|
592
|
+
disabled={!canUndo || !isEditable}
|
|
593
|
+
onClick={() => {
|
|
594
|
+
activeEditor.dispatchCommand(UNDO_COMMAND, undefined)
|
|
595
|
+
}}
|
|
596
|
+
title={IS_APPLE ? 'Undo (⌘Z)' : 'Undo (Ctrl+Z)'}
|
|
597
|
+
type="button"
|
|
598
|
+
className="toolbar-item spaced"
|
|
599
|
+
aria-label="Undo"
|
|
600
|
+
>
|
|
601
|
+
<i className="format undo" />
|
|
602
|
+
</button>
|
|
603
|
+
<button
|
|
604
|
+
disabled={!canRedo || !isEditable}
|
|
605
|
+
onClick={() => {
|
|
606
|
+
activeEditor.dispatchCommand(REDO_COMMAND, undefined)
|
|
607
|
+
}}
|
|
608
|
+
title={IS_APPLE ? 'Redo (⌘Y)' : 'Redo (Ctrl+Y)'}
|
|
609
|
+
type="button"
|
|
610
|
+
className="toolbar-item"
|
|
611
|
+
aria-label="Redo"
|
|
612
|
+
>
|
|
613
|
+
<i className="format redo" />
|
|
614
|
+
</button>
|
|
615
|
+
<Divider />
|
|
616
|
+
</>
|
|
617
|
+
)}
|
|
618
|
+
|
|
619
|
+
{blockType in blockTypeToBlockName && activeEditor === editor && (
|
|
620
|
+
<>
|
|
621
|
+
{textStyle && (
|
|
622
|
+
<>
|
|
623
|
+
<BlockFormatDropDown
|
|
624
|
+
disabled={!isEditable}
|
|
625
|
+
blockType={blockType}
|
|
626
|
+
rootType={rootType}
|
|
627
|
+
editor={editor}
|
|
628
|
+
/>
|
|
629
|
+
<Divider />
|
|
630
|
+
</>
|
|
631
|
+
)}
|
|
632
|
+
|
|
633
|
+
{textAlignment && (
|
|
634
|
+
<>
|
|
635
|
+
<DropDown
|
|
636
|
+
disabled={!isEditable}
|
|
637
|
+
buttonLabel="Align"
|
|
638
|
+
buttonIconClassName="icon left-align"
|
|
639
|
+
buttonClassName="toolbar-item spaced alignment"
|
|
640
|
+
buttonAriaLabel="Formatting options for text alignment"
|
|
641
|
+
>
|
|
642
|
+
<DropDownItem
|
|
643
|
+
onClick={() => {
|
|
644
|
+
activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left')
|
|
645
|
+
}}
|
|
646
|
+
className="item"
|
|
647
|
+
>
|
|
648
|
+
<i className="icon left-align" />
|
|
649
|
+
<span className="text">Left Align</span>
|
|
650
|
+
</DropDownItem>
|
|
651
|
+
<DropDownItem
|
|
652
|
+
onClick={() => {
|
|
653
|
+
activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center')
|
|
654
|
+
}}
|
|
655
|
+
className="item"
|
|
656
|
+
>
|
|
657
|
+
<i className="icon center-align" />
|
|
658
|
+
<span className="text">Center Align</span>
|
|
659
|
+
</DropDownItem>
|
|
660
|
+
<DropDownItem
|
|
661
|
+
onClick={() => {
|
|
662
|
+
activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right')
|
|
663
|
+
}}
|
|
664
|
+
className="item"
|
|
665
|
+
>
|
|
666
|
+
<i className="icon right-align" />
|
|
667
|
+
<span className="text">Right Align</span>
|
|
668
|
+
</DropDownItem>
|
|
669
|
+
<DropDownItem
|
|
670
|
+
onClick={() => {
|
|
671
|
+
activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'justify')
|
|
672
|
+
}}
|
|
673
|
+
className="item"
|
|
674
|
+
>
|
|
675
|
+
<i className="icon justify-align" />
|
|
676
|
+
<span className="text">Justify Align</span>
|
|
677
|
+
</DropDownItem>
|
|
678
|
+
<Divider />
|
|
679
|
+
<DropDownItem
|
|
680
|
+
onClick={() => {
|
|
681
|
+
activeEditor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined)
|
|
682
|
+
}}
|
|
683
|
+
className="item"
|
|
684
|
+
>
|
|
685
|
+
<i className={`icon ${isRTL ? 'indent' : 'outdent'}`} />
|
|
686
|
+
<span className="text">Outdent</span>
|
|
687
|
+
</DropDownItem>
|
|
688
|
+
<DropDownItem
|
|
689
|
+
onClick={() => {
|
|
690
|
+
activeEditor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined)
|
|
691
|
+
}}
|
|
692
|
+
className="item"
|
|
693
|
+
>
|
|
694
|
+
<i className={`icon ${isRTL ? 'outdent' : 'indent'}`} />
|
|
695
|
+
<span className="text">Indent</span>
|
|
696
|
+
</DropDownItem>
|
|
697
|
+
</DropDown>
|
|
698
|
+
<Divider />
|
|
699
|
+
</>
|
|
700
|
+
)}
|
|
701
|
+
</>
|
|
702
|
+
)}
|
|
703
|
+
{blockType === 'code' ? (
|
|
704
|
+
<DropDown
|
|
705
|
+
disabled={!isEditable}
|
|
706
|
+
buttonClassName="toolbar-item code-language"
|
|
707
|
+
buttonLabel={getLanguageFriendlyName(codeLanguage)}
|
|
708
|
+
buttonAriaLabel="Select language"
|
|
709
|
+
>
|
|
710
|
+
{CODE_LANGUAGE_OPTIONS.map(([value, name]) => {
|
|
711
|
+
return (
|
|
712
|
+
<DropDownItem
|
|
713
|
+
className={`item ${dropDownActiveClass(value === codeLanguage)}`}
|
|
714
|
+
onClick={() => {
|
|
715
|
+
onCodeLanguageSelect(value)
|
|
716
|
+
}}
|
|
717
|
+
key={value}
|
|
718
|
+
>
|
|
719
|
+
<span className="text">{name}</span>
|
|
720
|
+
</DropDownItem>
|
|
721
|
+
)
|
|
722
|
+
})}
|
|
723
|
+
</DropDown>
|
|
724
|
+
) : (
|
|
725
|
+
<>
|
|
726
|
+
<button
|
|
727
|
+
disabled={!isEditable}
|
|
728
|
+
onClick={() => {
|
|
729
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold')
|
|
730
|
+
}}
|
|
731
|
+
className={`toolbar-item spaced ${isBold ? 'active' : ''}`}
|
|
732
|
+
title={IS_APPLE ? 'Bold (⌘B)' : 'Bold (Ctrl+B)'}
|
|
733
|
+
type="button"
|
|
734
|
+
aria-label={`Format text as bold. Shortcut: ${IS_APPLE ? '⌘B' : 'Ctrl+B'}`}
|
|
735
|
+
>
|
|
736
|
+
<i className="format bold" />
|
|
737
|
+
</button>
|
|
738
|
+
<button
|
|
739
|
+
disabled={!isEditable}
|
|
740
|
+
onClick={() => {
|
|
741
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic')
|
|
742
|
+
}}
|
|
743
|
+
className={`toolbar-item spaced ${isItalic ? 'active' : ''}`}
|
|
744
|
+
title={IS_APPLE ? 'Italic (⌘I)' : 'Italic (Ctrl+I)'}
|
|
745
|
+
type="button"
|
|
746
|
+
aria-label={`Format text as italics. Shortcut: ${IS_APPLE ? '⌘I' : 'Ctrl+I'}`}
|
|
747
|
+
>
|
|
748
|
+
<i className="format italic" />
|
|
749
|
+
</button>
|
|
750
|
+
<button
|
|
751
|
+
disabled={!isEditable}
|
|
752
|
+
onClick={() => {
|
|
753
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline')
|
|
754
|
+
}}
|
|
755
|
+
className={`toolbar-item spaced ${isUnderline ? 'active' : ''}`}
|
|
756
|
+
title={IS_APPLE ? 'Underline (⌘U)' : 'Underline (Ctrl+U)'}
|
|
757
|
+
type="button"
|
|
758
|
+
aria-label={`Format text to underlined. Shortcut: ${IS_APPLE ? '⌘U' : 'Ctrl+U'}`}
|
|
759
|
+
>
|
|
760
|
+
<i className="format underline" />
|
|
761
|
+
</button>
|
|
762
|
+
{inlineCode && (
|
|
763
|
+
<button
|
|
764
|
+
disabled={!isEditable}
|
|
765
|
+
onClick={() => {
|
|
766
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code')
|
|
767
|
+
}}
|
|
768
|
+
className={`toolbar-item spaced ${isCode ? 'active' : ''}`}
|
|
769
|
+
title="Insert code block"
|
|
770
|
+
type="button"
|
|
771
|
+
aria-label="Insert code block"
|
|
772
|
+
>
|
|
773
|
+
<i className="format code" />
|
|
774
|
+
</button>
|
|
775
|
+
)}
|
|
776
|
+
{links && (
|
|
777
|
+
<button
|
|
778
|
+
key="link"
|
|
779
|
+
type="button"
|
|
780
|
+
disabled={!isEditable}
|
|
781
|
+
onClick={insertLink}
|
|
782
|
+
className={`toolbar-item spaced ${isLink ? 'active' : ''}`}
|
|
783
|
+
aria-label="Insert link"
|
|
784
|
+
title="Insert link"
|
|
785
|
+
>
|
|
786
|
+
<i className="format link" />
|
|
787
|
+
</button>
|
|
788
|
+
)}
|
|
789
|
+
|
|
790
|
+
<DropDown
|
|
791
|
+
disabled={!isEditable}
|
|
792
|
+
buttonClassName="toolbar-item spaced"
|
|
793
|
+
buttonLabel=""
|
|
794
|
+
buttonAriaLabel="Formatting options for additional text styles"
|
|
795
|
+
buttonIconClassName="icon dropdown-more"
|
|
796
|
+
>
|
|
797
|
+
<DropDownItem
|
|
798
|
+
onClick={() => {
|
|
799
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough')
|
|
800
|
+
}}
|
|
801
|
+
className={`item ${dropDownActiveClass(isStrikethrough)}`}
|
|
802
|
+
title="Strikethrough"
|
|
803
|
+
aria-label="Format text with a strikethrough"
|
|
804
|
+
>
|
|
805
|
+
<i className="icon strikethrough" />
|
|
806
|
+
<span className="text">Strikethrough</span>
|
|
807
|
+
</DropDownItem>
|
|
808
|
+
<DropDownItem
|
|
809
|
+
onClick={() => {
|
|
810
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript')
|
|
811
|
+
}}
|
|
812
|
+
className={`item ${dropDownActiveClass(isSubscript)}`}
|
|
813
|
+
title="Subscript"
|
|
814
|
+
aria-label="Format text with a subscript"
|
|
815
|
+
>
|
|
816
|
+
<i className="icon subscript" />
|
|
817
|
+
<span className="text">Subscript</span>
|
|
818
|
+
</DropDownItem>
|
|
819
|
+
<DropDownItem
|
|
820
|
+
onClick={() => {
|
|
821
|
+
activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript')
|
|
822
|
+
}}
|
|
823
|
+
className={`item ${dropDownActiveClass(isSuperscript)}`}
|
|
824
|
+
title="Superscript"
|
|
825
|
+
aria-label="Format text with a superscript"
|
|
826
|
+
>
|
|
827
|
+
<i className="icon superscript" />
|
|
828
|
+
<span className="text">Superscript</span>
|
|
829
|
+
</DropDownItem>
|
|
830
|
+
<DropDownItem
|
|
831
|
+
onClick={clearFormatting}
|
|
832
|
+
className="item"
|
|
833
|
+
title="Clear text formatting"
|
|
834
|
+
aria-label="Clear all text formatting"
|
|
835
|
+
>
|
|
836
|
+
<i className="icon clear" />
|
|
837
|
+
<span className="text">Clear Formatting</span>
|
|
838
|
+
</DropDownItem>
|
|
839
|
+
</DropDown>
|
|
840
|
+
|
|
841
|
+
{activeEditor === editor &&
|
|
842
|
+
(horizontalRulePlugin || inlineImagePlugin || tablePlugin || admonitionPlugin) && (
|
|
843
|
+
<>
|
|
844
|
+
<Divider />
|
|
845
|
+
<DropDown
|
|
846
|
+
disabled={!isEditable}
|
|
847
|
+
buttonClassName="toolbar-item spaced"
|
|
848
|
+
buttonLabel="Insert"
|
|
849
|
+
buttonAriaLabel="Insert specialized editor node"
|
|
850
|
+
buttonIconClassName="icon plus"
|
|
851
|
+
>
|
|
852
|
+
{horizontalRulePlugin && (
|
|
853
|
+
<DropDownItem
|
|
854
|
+
onClick={() => {
|
|
855
|
+
activeEditor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, undefined)
|
|
856
|
+
}}
|
|
857
|
+
className="item"
|
|
858
|
+
>
|
|
859
|
+
<i className="icon horizontal-rule" />
|
|
860
|
+
<span className="text">Horizontal Rule</span>
|
|
861
|
+
</DropDownItem>
|
|
862
|
+
)}
|
|
863
|
+
|
|
864
|
+
{layoutPlugin && (
|
|
865
|
+
<DropDownItem
|
|
866
|
+
onClick={() => {
|
|
867
|
+
activeEditor.dispatchCommand(OPEN_INSERT_LAYOUT_MODAL_COMMAND, null)
|
|
868
|
+
}}
|
|
869
|
+
className="item"
|
|
870
|
+
>
|
|
871
|
+
<i className="icon columns" />
|
|
872
|
+
<span className="text">Columns Layout</span>
|
|
873
|
+
</DropDownItem>
|
|
874
|
+
)}
|
|
875
|
+
|
|
876
|
+
{admonitionPlugin && (
|
|
877
|
+
<DropDownItem
|
|
878
|
+
onClick={() => {
|
|
879
|
+
activeEditor.dispatchCommand(OPEN_ADMONITION_MODAL_COMMAND, null)
|
|
880
|
+
}}
|
|
881
|
+
className="item"
|
|
882
|
+
>
|
|
883
|
+
<i className="icon admonition" />
|
|
884
|
+
<span className="text">Admonition</span>
|
|
885
|
+
</DropDownItem>
|
|
886
|
+
)}
|
|
887
|
+
|
|
888
|
+
{inlineImagePlugin && (
|
|
889
|
+
<DropDownItem
|
|
890
|
+
onClick={() => {
|
|
891
|
+
activeEditor.dispatchCommand(OPEN_INLINE_IMAGE_MODAL_COMMAND, null)
|
|
892
|
+
}}
|
|
893
|
+
className="item"
|
|
894
|
+
>
|
|
895
|
+
<i className="icon image" />
|
|
896
|
+
<span className="text">Inline Image</span>
|
|
897
|
+
</DropDownItem>
|
|
898
|
+
)}
|
|
899
|
+
{tablePlugin && (
|
|
900
|
+
<DropDownItem
|
|
901
|
+
onClick={() => {
|
|
902
|
+
activeEditor.dispatchCommand(OPEN_TABLE_MODAL_COMMAND, null)
|
|
903
|
+
}}
|
|
904
|
+
className="item"
|
|
905
|
+
>
|
|
906
|
+
<i className="icon table" />
|
|
907
|
+
<span className="text">Table</span>
|
|
908
|
+
</DropDownItem>
|
|
909
|
+
)}
|
|
910
|
+
{autoEmbedPlugin &&
|
|
911
|
+
EmbedConfigs.map((embedConfig) => (
|
|
912
|
+
<DropDownItem
|
|
913
|
+
key={embedConfig.type}
|
|
914
|
+
onClick={() => {
|
|
915
|
+
activeEditor.dispatchCommand(INSERT_EMBED_COMMAND, embedConfig.type)
|
|
916
|
+
}}
|
|
917
|
+
className="item"
|
|
918
|
+
>
|
|
919
|
+
{embedConfig.icon}
|
|
920
|
+
<span className="text">{embedConfig.contentName}</span>
|
|
921
|
+
</DropDownItem>
|
|
922
|
+
))}
|
|
923
|
+
</DropDown>
|
|
924
|
+
</>
|
|
925
|
+
)}
|
|
926
|
+
</>
|
|
927
|
+
)}
|
|
928
|
+
|
|
929
|
+
{toolbarExtensionItems
|
|
930
|
+
.slice()
|
|
931
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
|
932
|
+
.map((item) => (
|
|
933
|
+
<Fragment key={item.id}>{item.node}</Fragment>
|
|
934
|
+
))}
|
|
935
|
+
</div>
|
|
936
|
+
)
|
|
937
|
+
}
|