@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,804 @@
|
|
|
1
|
+
/** biome-ignore-all lint/a11y/noStaticElementInteractions: <explanation> */
|
|
2
|
+
/** biome-ignore-all lint/a11y/useKeyWithClickEvents: <explanation> */
|
|
3
|
+
'use client'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
7
|
+
*
|
|
8
|
+
* This source code is licensed under the MIT license found in the
|
|
9
|
+
* LICENSE file in the root directory of this source tree.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type * as React from 'react'
|
|
14
|
+
import { type ReactPortal, useCallback, useEffect, useRef, useState } from 'react'
|
|
15
|
+
|
|
16
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'
|
|
17
|
+
import { useLexicalEditable } from '@lexical/react/useLexicalEditable'
|
|
18
|
+
import {
|
|
19
|
+
$deleteTableColumnAtSelection,
|
|
20
|
+
$deleteTableRowAtSelection,
|
|
21
|
+
$getNodeTriplet,
|
|
22
|
+
$getTableCellNodeFromLexicalNode,
|
|
23
|
+
$getTableColumnIndexFromTableCellNode,
|
|
24
|
+
$getTableNodeFromLexicalNodeOrThrow,
|
|
25
|
+
$getTableRowIndexFromTableCellNode,
|
|
26
|
+
$insertTableColumnAtSelection,
|
|
27
|
+
$insertTableRowAtSelection,
|
|
28
|
+
$isTableCellNode,
|
|
29
|
+
$isTableRowNode,
|
|
30
|
+
$isTableSelection,
|
|
31
|
+
$unmergeCell,
|
|
32
|
+
getTableObserverFromTableElement,
|
|
33
|
+
type HTMLTableElementWithWithTableSelectionState,
|
|
34
|
+
TableCellHeaderStates,
|
|
35
|
+
TableCellNode,
|
|
36
|
+
type TableRowNode,
|
|
37
|
+
type TableSelection,
|
|
38
|
+
} from '@lexical/table'
|
|
39
|
+
import type { ElementNode, LexicalEditor } from 'lexical'
|
|
40
|
+
import {
|
|
41
|
+
$createParagraphNode,
|
|
42
|
+
$getRoot,
|
|
43
|
+
$getSelection,
|
|
44
|
+
$isElementNode,
|
|
45
|
+
$isParagraphNode,
|
|
46
|
+
$isRangeSelection,
|
|
47
|
+
$isTextNode,
|
|
48
|
+
} from 'lexical'
|
|
49
|
+
import { createPortal } from 'react-dom'
|
|
50
|
+
|
|
51
|
+
import useModal from '../../hooks/use-modal'
|
|
52
|
+
import invariant from '../../shared/invariant'
|
|
53
|
+
import ColorPicker from '../../ui/color-picker'
|
|
54
|
+
|
|
55
|
+
function computeSelectionCount(selection: TableSelection): {
|
|
56
|
+
columns: number
|
|
57
|
+
rows: number
|
|
58
|
+
} {
|
|
59
|
+
const selectionShape = selection.getShape()
|
|
60
|
+
return {
|
|
61
|
+
columns: selectionShape.toX - selectionShape.fromX + 1,
|
|
62
|
+
rows: selectionShape.toY - selectionShape.fromY + 1,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// This is important when merging cells as there is no good way to re-merge weird shapes (a result
|
|
67
|
+
// of selecting merged cells and non-merged)
|
|
68
|
+
function isTableSelectionRectangular(selection: TableSelection): boolean {
|
|
69
|
+
const nodes = selection.getNodes()
|
|
70
|
+
const currentRows: number[] = []
|
|
71
|
+
let currentRow = null
|
|
72
|
+
let expectedColumns = null
|
|
73
|
+
let currentColumns = 0
|
|
74
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
75
|
+
const node = nodes[i]
|
|
76
|
+
if ($isTableCellNode(node)) {
|
|
77
|
+
const row = node.getParentOrThrow()
|
|
78
|
+
invariant($isTableRowNode(row), 'Expected CellNode to have a RowNode parent')
|
|
79
|
+
if (currentRow !== row) {
|
|
80
|
+
if (expectedColumns !== null && currentColumns !== expectedColumns) {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
if (currentRow !== null) {
|
|
84
|
+
expectedColumns = currentColumns
|
|
85
|
+
}
|
|
86
|
+
currentRow = row
|
|
87
|
+
currentColumns = 0
|
|
88
|
+
}
|
|
89
|
+
const colSpan = node.__colSpan
|
|
90
|
+
for (let j = 0; j < colSpan; j++) {
|
|
91
|
+
if (currentRows[currentColumns + j] === undefined) {
|
|
92
|
+
currentRows[currentColumns + j] = 0
|
|
93
|
+
}
|
|
94
|
+
currentRows[currentColumns + j] += node.__rowSpan
|
|
95
|
+
}
|
|
96
|
+
currentColumns += colSpan
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
(expectedColumns === null || currentColumns === expectedColumns) &&
|
|
101
|
+
currentRows.every((v) => v === currentRows[0])
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function $canUnmerge(): boolean {
|
|
106
|
+
const selection = $getSelection()
|
|
107
|
+
if (
|
|
108
|
+
($isRangeSelection(selection) && !selection.isCollapsed()) ||
|
|
109
|
+
($isTableSelection(selection) && !selection.anchor.is(selection.focus)) ||
|
|
110
|
+
(!$isRangeSelection(selection) && !$isTableSelection(selection))
|
|
111
|
+
) {
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
const [cell] = $getNodeTriplet(selection.anchor)
|
|
115
|
+
return cell.__colSpan > 1 || cell.__rowSpan > 1
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function $cellContainsEmptyParagraph(cell: TableCellNode): boolean {
|
|
119
|
+
if (cell.getChildrenSize() !== 1) {
|
|
120
|
+
return false
|
|
121
|
+
}
|
|
122
|
+
const firstChild = cell.getFirstChildOrThrow()
|
|
123
|
+
if (!$isParagraphNode(firstChild) || !firstChild.isEmpty()) {
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function $selectLastDescendant(node: ElementNode): void {
|
|
130
|
+
const lastDescendant = node.getLastDescendant()
|
|
131
|
+
if ($isTextNode(lastDescendant)) {
|
|
132
|
+
lastDescendant.select()
|
|
133
|
+
} else if ($isElementNode(lastDescendant)) {
|
|
134
|
+
lastDescendant.selectEnd()
|
|
135
|
+
} else if (lastDescendant !== null) {
|
|
136
|
+
lastDescendant.selectNext()
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function currentCellBackgroundColor(editor: LexicalEditor): null | string {
|
|
141
|
+
return editor.getEditorState().read(() => {
|
|
142
|
+
const selection = $getSelection()
|
|
143
|
+
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
144
|
+
const [cell] = $getNodeTriplet(selection.anchor)
|
|
145
|
+
if ($isTableCellNode(cell)) {
|
|
146
|
+
return cell.getBackgroundColor()
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
type TableCellActionMenuProps = Readonly<{
|
|
154
|
+
contextRef: { current: null | HTMLElement }
|
|
155
|
+
onClose: () => void
|
|
156
|
+
setIsMenuOpen: (isOpen: boolean) => void
|
|
157
|
+
showColorPickerModal: (
|
|
158
|
+
title: string,
|
|
159
|
+
showModal: (onClose: () => void) => React.JSX.Element
|
|
160
|
+
) => void
|
|
161
|
+
tableCellNode: TableCellNode
|
|
162
|
+
cellMerge: boolean
|
|
163
|
+
}>
|
|
164
|
+
|
|
165
|
+
function TableActionMenu({
|
|
166
|
+
onClose,
|
|
167
|
+
tableCellNode: _tableCellNode,
|
|
168
|
+
setIsMenuOpen,
|
|
169
|
+
contextRef,
|
|
170
|
+
cellMerge,
|
|
171
|
+
showColorPickerModal,
|
|
172
|
+
}: TableCellActionMenuProps): React.ReactPortal {
|
|
173
|
+
const [editor] = useLexicalComposerContext()
|
|
174
|
+
const dropDownRef = useRef<HTMLDivElement | null>(null)
|
|
175
|
+
const [tableCellNode, updateTableCellNode] = useState(_tableCellNode)
|
|
176
|
+
const [selectionCounts, updateSelectionCounts] = useState({
|
|
177
|
+
columns: 1,
|
|
178
|
+
rows: 1,
|
|
179
|
+
})
|
|
180
|
+
const [canMergeCells, setCanMergeCells] = useState(false)
|
|
181
|
+
const [canUnmergeCell, setCanUnmergeCell] = useState(false)
|
|
182
|
+
const [backgroundColor, setBackgroundColor] = useState(
|
|
183
|
+
() => currentCellBackgroundColor(editor) ?? ''
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
useEffect(() => {
|
|
187
|
+
return editor.registerMutationListener(TableCellNode, (nodeMutations) => {
|
|
188
|
+
const nodeUpdated = nodeMutations.get(tableCellNode.getKey()) === 'updated'
|
|
189
|
+
|
|
190
|
+
if (nodeUpdated) {
|
|
191
|
+
editor.getEditorState().read(() => {
|
|
192
|
+
updateTableCellNode(tableCellNode.getLatest())
|
|
193
|
+
})
|
|
194
|
+
setBackgroundColor(currentCellBackgroundColor(editor) ?? '')
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
}, [editor, tableCellNode])
|
|
198
|
+
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
editor.getEditorState().read(() => {
|
|
201
|
+
const selection = $getSelection()
|
|
202
|
+
// Merge cells
|
|
203
|
+
if ($isTableSelection(selection)) {
|
|
204
|
+
const currentSelectionCounts = computeSelectionCount(selection)
|
|
205
|
+
updateSelectionCounts(computeSelectionCount(selection))
|
|
206
|
+
setCanMergeCells(
|
|
207
|
+
isTableSelectionRectangular(selection) &&
|
|
208
|
+
(currentSelectionCounts.columns > 1 || currentSelectionCounts.rows > 1)
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
// Unmerge cell
|
|
212
|
+
setCanUnmergeCell($canUnmerge())
|
|
213
|
+
})
|
|
214
|
+
}, [editor])
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
const menuButtonElement = contextRef.current
|
|
218
|
+
const dropDownElement = dropDownRef.current
|
|
219
|
+
const rootElement = editor.getRootElement()
|
|
220
|
+
|
|
221
|
+
if (menuButtonElement != null && dropDownElement != null && rootElement != null) {
|
|
222
|
+
const rootEleRect = rootElement.getBoundingClientRect()
|
|
223
|
+
const menuButtonRect = menuButtonElement.getBoundingClientRect()
|
|
224
|
+
dropDownElement.style.opacity = '1'
|
|
225
|
+
const dropDownElementRect = dropDownElement.getBoundingClientRect()
|
|
226
|
+
const margin = 5
|
|
227
|
+
let leftPosition = menuButtonRect.right + margin
|
|
228
|
+
if (
|
|
229
|
+
leftPosition + dropDownElementRect.width > window.innerWidth ||
|
|
230
|
+
leftPosition + dropDownElementRect.width > rootEleRect.right
|
|
231
|
+
) {
|
|
232
|
+
const position = menuButtonRect.left - dropDownElementRect.width - margin
|
|
233
|
+
// leftPosition = (position < 0 ? margin : position) + window.pageXOffset
|
|
234
|
+
leftPosition = position < 0 ? margin : position
|
|
235
|
+
}
|
|
236
|
+
// TODO: Revisit - this almost seems too easy as a fix for correct x / y position
|
|
237
|
+
// dropDownElement.style.left = `${leftPosition + window.pageXOffset}px`
|
|
238
|
+
dropDownElement.style.left = `${leftPosition}px`
|
|
239
|
+
|
|
240
|
+
let topPosition = menuButtonRect.top
|
|
241
|
+
if (topPosition + dropDownElementRect.height > window.innerHeight) {
|
|
242
|
+
const position = menuButtonRect.bottom - dropDownElementRect.height
|
|
243
|
+
// topPosition = (position < 0 ? margin : position) + window.pageYOffset
|
|
244
|
+
topPosition = position < 0 ? margin : position
|
|
245
|
+
}
|
|
246
|
+
// TODO: Revisit - this almost seems too easy as a fix for correct x / y position
|
|
247
|
+
// dropDownElement.style.top = `${topPosition + +window.pageYOffset}px`
|
|
248
|
+
dropDownElement.style.top = `${topPosition}px`
|
|
249
|
+
}
|
|
250
|
+
}, [contextRef, editor])
|
|
251
|
+
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
function handleClickOutside(event: MouseEvent): void {
|
|
254
|
+
if (
|
|
255
|
+
dropDownRef.current != null &&
|
|
256
|
+
contextRef.current != null &&
|
|
257
|
+
!dropDownRef.current.contains(event.target as Node) &&
|
|
258
|
+
!contextRef.current.contains(event.target as Node)
|
|
259
|
+
) {
|
|
260
|
+
setIsMenuOpen(false)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
window.addEventListener('click', handleClickOutside)
|
|
265
|
+
|
|
266
|
+
return () => {
|
|
267
|
+
window.removeEventListener('click', handleClickOutside)
|
|
268
|
+
}
|
|
269
|
+
}, [setIsMenuOpen, contextRef])
|
|
270
|
+
|
|
271
|
+
const clearTableSelection = useCallback(() => {
|
|
272
|
+
editor.update(() => {
|
|
273
|
+
if (tableCellNode.isAttached()) {
|
|
274
|
+
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode)
|
|
275
|
+
const tableElement = editor.getElementByKey(
|
|
276
|
+
tableNode.getKey()
|
|
277
|
+
) as HTMLTableElementWithWithTableSelectionState
|
|
278
|
+
|
|
279
|
+
if (tableElement == null) {
|
|
280
|
+
throw new Error('Expected to find tableElement in DOM')
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const tableSelection = getTableObserverFromTableElement(tableElement)
|
|
284
|
+
if (tableSelection !== null) {
|
|
285
|
+
tableSelection.$clearHighlight()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
tableNode.markDirty()
|
|
289
|
+
updateTableCellNode(tableCellNode.getLatest())
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const rootNode = $getRoot()
|
|
293
|
+
rootNode.selectStart()
|
|
294
|
+
})
|
|
295
|
+
}, [editor, tableCellNode])
|
|
296
|
+
|
|
297
|
+
const mergeTableCellsAtSelection = (): void => {
|
|
298
|
+
editor.update(() => {
|
|
299
|
+
const selection = $getSelection()
|
|
300
|
+
if ($isTableSelection(selection)) {
|
|
301
|
+
const { columns, rows } = computeSelectionCount(selection)
|
|
302
|
+
const nodes = selection.getNodes()
|
|
303
|
+
let firstCell: null | TableCellNode = null
|
|
304
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
305
|
+
const node = nodes[i]
|
|
306
|
+
if ($isTableCellNode(node)) {
|
|
307
|
+
if (firstCell === null) {
|
|
308
|
+
node.setColSpan(columns).setRowSpan(rows)
|
|
309
|
+
firstCell = node
|
|
310
|
+
const isEmpty = $cellContainsEmptyParagraph(node)
|
|
311
|
+
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
|
|
312
|
+
let firstChild
|
|
313
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
|
|
314
|
+
if (isEmpty && $isParagraphNode((firstChild = node.getFirstChild()))) {
|
|
315
|
+
firstChild.remove()
|
|
316
|
+
}
|
|
317
|
+
} else if ($isTableCellNode(firstCell)) {
|
|
318
|
+
const isEmpty = $cellContainsEmptyParagraph(node)
|
|
319
|
+
if (!isEmpty) {
|
|
320
|
+
firstCell.append(...node.getChildren())
|
|
321
|
+
}
|
|
322
|
+
node.remove()
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (firstCell !== null) {
|
|
327
|
+
if (firstCell.getChildrenSize() === 0) {
|
|
328
|
+
firstCell.append($createParagraphNode())
|
|
329
|
+
}
|
|
330
|
+
$selectLastDescendant(firstCell)
|
|
331
|
+
}
|
|
332
|
+
onClose()
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const unmergeTableCellsAtSelection = (): void => {
|
|
338
|
+
editor.update(() => {
|
|
339
|
+
$unmergeCell()
|
|
340
|
+
})
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const insertTableRowAtSelection = useCallback(
|
|
344
|
+
(shouldInsertAfter: boolean) => {
|
|
345
|
+
editor.update(() => {
|
|
346
|
+
$insertTableRowAtSelection(shouldInsertAfter)
|
|
347
|
+
onClose()
|
|
348
|
+
})
|
|
349
|
+
},
|
|
350
|
+
[editor, onClose]
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
const insertTableColumnAtSelection = useCallback(
|
|
354
|
+
(shouldInsertAfter: boolean) => {
|
|
355
|
+
editor.update(() => {
|
|
356
|
+
for (let i = 0; i < selectionCounts.columns; i++) {
|
|
357
|
+
$insertTableColumnAtSelection(shouldInsertAfter)
|
|
358
|
+
}
|
|
359
|
+
onClose()
|
|
360
|
+
})
|
|
361
|
+
},
|
|
362
|
+
[editor, onClose, selectionCounts.columns]
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
const deleteTableRowAtSelection = useCallback(() => {
|
|
366
|
+
editor.update(() => {
|
|
367
|
+
$deleteTableRowAtSelection()
|
|
368
|
+
onClose()
|
|
369
|
+
})
|
|
370
|
+
}, [editor, onClose])
|
|
371
|
+
|
|
372
|
+
const deleteTableAtSelection = useCallback(() => {
|
|
373
|
+
editor.update(() => {
|
|
374
|
+
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode)
|
|
375
|
+
tableNode.remove()
|
|
376
|
+
|
|
377
|
+
clearTableSelection()
|
|
378
|
+
onClose()
|
|
379
|
+
})
|
|
380
|
+
}, [editor, tableCellNode, clearTableSelection, onClose])
|
|
381
|
+
|
|
382
|
+
const deleteTableColumnAtSelection = useCallback(() => {
|
|
383
|
+
editor.update(() => {
|
|
384
|
+
$deleteTableColumnAtSelection()
|
|
385
|
+
onClose()
|
|
386
|
+
})
|
|
387
|
+
}, [editor, onClose])
|
|
388
|
+
|
|
389
|
+
const toggleTableRowIsHeader = useCallback(() => {
|
|
390
|
+
editor.update(() => {
|
|
391
|
+
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode)
|
|
392
|
+
|
|
393
|
+
const tableRowIndex = $getTableRowIndexFromTableCellNode(tableCellNode)
|
|
394
|
+
|
|
395
|
+
const tableRows = tableNode.getChildren()
|
|
396
|
+
|
|
397
|
+
if (tableRowIndex >= tableRows.length || tableRowIndex < 0) {
|
|
398
|
+
throw new Error('Expected table cell to be inside of table row.')
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const tableRow = tableRows[tableRowIndex]
|
|
402
|
+
|
|
403
|
+
if (!$isTableRowNode(tableRow)) {
|
|
404
|
+
throw new Error('Expected table row')
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
tableRow.getChildren().forEach((tableCell) => {
|
|
408
|
+
if (!$isTableCellNode(tableCell)) {
|
|
409
|
+
throw new Error('Expected table cell')
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
tableCell.toggleHeaderStyle(TableCellHeaderStates.ROW)
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
clearTableSelection()
|
|
416
|
+
onClose()
|
|
417
|
+
})
|
|
418
|
+
}, [editor, tableCellNode, clearTableSelection, onClose])
|
|
419
|
+
|
|
420
|
+
const toggleTableColumnIsHeader = useCallback(() => {
|
|
421
|
+
editor.update(() => {
|
|
422
|
+
const tableNode = $getTableNodeFromLexicalNodeOrThrow(tableCellNode)
|
|
423
|
+
|
|
424
|
+
const tableColumnIndex = $getTableColumnIndexFromTableCellNode(tableCellNode)
|
|
425
|
+
|
|
426
|
+
const tableRows = tableNode.getChildren<TableRowNode>()
|
|
427
|
+
const maxRowsLength = Math.max(...tableRows.map((row) => row.getChildren().length))
|
|
428
|
+
|
|
429
|
+
if (tableColumnIndex >= maxRowsLength || tableColumnIndex < 0) {
|
|
430
|
+
throw new Error('Expected table cell to be inside of table row.')
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
for (let r = 0; r < tableRows.length; r++) {
|
|
434
|
+
const tableRow = tableRows[r]
|
|
435
|
+
|
|
436
|
+
if (!$isTableRowNode(tableRow)) {
|
|
437
|
+
throw new Error('Expected table row')
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const tableCells = tableRow.getChildren()
|
|
441
|
+
if (tableColumnIndex >= tableCells.length) {
|
|
442
|
+
// if cell is outside of bounds for the current row (for example various merge cell cases) we shouldn't highlight it
|
|
443
|
+
continue
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const tableCell = tableCells[tableColumnIndex]
|
|
447
|
+
|
|
448
|
+
if (!$isTableCellNode(tableCell)) {
|
|
449
|
+
throw new Error('Expected table cell')
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
tableCell.toggleHeaderStyle(TableCellHeaderStates.COLUMN)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
clearTableSelection()
|
|
456
|
+
onClose()
|
|
457
|
+
})
|
|
458
|
+
}, [editor, tableCellNode, clearTableSelection, onClose])
|
|
459
|
+
|
|
460
|
+
const handleCellBackgroundColor = useCallback(
|
|
461
|
+
(value: string) => {
|
|
462
|
+
editor.update(() => {
|
|
463
|
+
const selection = $getSelection()
|
|
464
|
+
if ($isRangeSelection(selection) || $isTableSelection(selection)) {
|
|
465
|
+
const [cell] = $getNodeTriplet(selection.anchor)
|
|
466
|
+
if ($isTableCellNode(cell)) {
|
|
467
|
+
cell.setBackgroundColor(value)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if ($isTableSelection(selection)) {
|
|
471
|
+
const nodes = selection.getNodes()
|
|
472
|
+
|
|
473
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
474
|
+
const node = nodes[i]
|
|
475
|
+
if ($isTableCellNode(node)) {
|
|
476
|
+
node.setBackgroundColor(value)
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
})
|
|
482
|
+
},
|
|
483
|
+
[editor]
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
let mergeCellButton: null | React.JSX.Element = null
|
|
487
|
+
if (cellMerge) {
|
|
488
|
+
if (canMergeCells) {
|
|
489
|
+
mergeCellButton = (
|
|
490
|
+
<button
|
|
491
|
+
type="button"
|
|
492
|
+
className="item"
|
|
493
|
+
onClick={() => {
|
|
494
|
+
mergeTableCellsAtSelection()
|
|
495
|
+
}}
|
|
496
|
+
data-test-id="table-merge-cells"
|
|
497
|
+
>
|
|
498
|
+
Merge cells
|
|
499
|
+
</button>
|
|
500
|
+
)
|
|
501
|
+
} else if (canUnmergeCell) {
|
|
502
|
+
mergeCellButton = (
|
|
503
|
+
<button
|
|
504
|
+
type="button"
|
|
505
|
+
className="item"
|
|
506
|
+
onClick={() => {
|
|
507
|
+
unmergeTableCellsAtSelection()
|
|
508
|
+
}}
|
|
509
|
+
data-test-id="table-unmerge-cells"
|
|
510
|
+
>
|
|
511
|
+
Unmerge cells
|
|
512
|
+
</button>
|
|
513
|
+
)
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return createPortal(
|
|
518
|
+
<div
|
|
519
|
+
className="dropdown"
|
|
520
|
+
ref={dropDownRef}
|
|
521
|
+
onClick={(e) => {
|
|
522
|
+
e.stopPropagation()
|
|
523
|
+
}}
|
|
524
|
+
>
|
|
525
|
+
{mergeCellButton}
|
|
526
|
+
<button
|
|
527
|
+
type="button"
|
|
528
|
+
className="item"
|
|
529
|
+
onClick={() => {
|
|
530
|
+
showColorPickerModal('Cell background color', () => (
|
|
531
|
+
<ColorPicker color={backgroundColor} onChange={handleCellBackgroundColor} />
|
|
532
|
+
))
|
|
533
|
+
}}
|
|
534
|
+
data-test-id="table-background-color"
|
|
535
|
+
>
|
|
536
|
+
<span className="text">Background color</span>
|
|
537
|
+
</button>
|
|
538
|
+
<hr />
|
|
539
|
+
<button
|
|
540
|
+
type="button"
|
|
541
|
+
className="item"
|
|
542
|
+
onClick={() => {
|
|
543
|
+
insertTableRowAtSelection(false)
|
|
544
|
+
}}
|
|
545
|
+
data-test-id="table-insert-row-above"
|
|
546
|
+
>
|
|
547
|
+
<span className="text">
|
|
548
|
+
Insert {selectionCounts.rows === 1 ? 'row' : `${selectionCounts.rows} rows`} above
|
|
549
|
+
</span>
|
|
550
|
+
</button>
|
|
551
|
+
<button
|
|
552
|
+
type="button"
|
|
553
|
+
className="item"
|
|
554
|
+
onClick={() => {
|
|
555
|
+
insertTableRowAtSelection(true)
|
|
556
|
+
}}
|
|
557
|
+
data-test-id="table-insert-row-below"
|
|
558
|
+
>
|
|
559
|
+
<span className="text">
|
|
560
|
+
Insert {selectionCounts.rows === 1 ? 'row' : `${selectionCounts.rows} rows`} below
|
|
561
|
+
</span>
|
|
562
|
+
</button>
|
|
563
|
+
<hr />
|
|
564
|
+
<button
|
|
565
|
+
type="button"
|
|
566
|
+
className="item"
|
|
567
|
+
onClick={() => {
|
|
568
|
+
insertTableColumnAtSelection(false)
|
|
569
|
+
}}
|
|
570
|
+
data-test-id="table-insert-column-before"
|
|
571
|
+
>
|
|
572
|
+
<span className="text">
|
|
573
|
+
Insert {selectionCounts.columns === 1 ? 'column' : `${selectionCounts.columns} columns`}{' '}
|
|
574
|
+
left
|
|
575
|
+
</span>
|
|
576
|
+
</button>
|
|
577
|
+
<button
|
|
578
|
+
type="button"
|
|
579
|
+
className="item"
|
|
580
|
+
onClick={() => {
|
|
581
|
+
insertTableColumnAtSelection(true)
|
|
582
|
+
}}
|
|
583
|
+
data-test-id="table-insert-column-after"
|
|
584
|
+
>
|
|
585
|
+
<span className="text">
|
|
586
|
+
Insert {selectionCounts.columns === 1 ? 'column' : `${selectionCounts.columns} columns`}{' '}
|
|
587
|
+
right
|
|
588
|
+
</span>
|
|
589
|
+
</button>
|
|
590
|
+
<hr />
|
|
591
|
+
<button
|
|
592
|
+
type="button"
|
|
593
|
+
className="item"
|
|
594
|
+
onClick={() => {
|
|
595
|
+
deleteTableColumnAtSelection()
|
|
596
|
+
}}
|
|
597
|
+
data-test-id="table-delete-columns"
|
|
598
|
+
>
|
|
599
|
+
<span className="text">Delete column</span>
|
|
600
|
+
</button>
|
|
601
|
+
<button
|
|
602
|
+
type="button"
|
|
603
|
+
className="item"
|
|
604
|
+
onClick={() => {
|
|
605
|
+
deleteTableRowAtSelection()
|
|
606
|
+
}}
|
|
607
|
+
data-test-id="table-delete-rows"
|
|
608
|
+
>
|
|
609
|
+
<span className="text">Delete row</span>
|
|
610
|
+
</button>
|
|
611
|
+
<button
|
|
612
|
+
type="button"
|
|
613
|
+
className="item"
|
|
614
|
+
onClick={() => {
|
|
615
|
+
deleteTableAtSelection()
|
|
616
|
+
}}
|
|
617
|
+
data-test-id="table-delete"
|
|
618
|
+
>
|
|
619
|
+
<span className="text">Delete table</span>
|
|
620
|
+
</button>
|
|
621
|
+
<hr />
|
|
622
|
+
<button
|
|
623
|
+
type="button"
|
|
624
|
+
className="item"
|
|
625
|
+
onClick={() => {
|
|
626
|
+
toggleTableRowIsHeader()
|
|
627
|
+
}}
|
|
628
|
+
>
|
|
629
|
+
<span className="text">
|
|
630
|
+
{(tableCellNode.__headerState & TableCellHeaderStates.ROW) === TableCellHeaderStates.ROW
|
|
631
|
+
? 'Remove'
|
|
632
|
+
: 'Add'}{' '}
|
|
633
|
+
row header
|
|
634
|
+
</span>
|
|
635
|
+
</button>
|
|
636
|
+
<button
|
|
637
|
+
type="button"
|
|
638
|
+
className="item"
|
|
639
|
+
onClick={() => {
|
|
640
|
+
toggleTableColumnIsHeader()
|
|
641
|
+
}}
|
|
642
|
+
data-test-id="table-column-header"
|
|
643
|
+
>
|
|
644
|
+
<span className="text">
|
|
645
|
+
{(tableCellNode.__headerState & TableCellHeaderStates.COLUMN) ===
|
|
646
|
+
TableCellHeaderStates.COLUMN
|
|
647
|
+
? 'Remove'
|
|
648
|
+
: 'Add'}{' '}
|
|
649
|
+
column header
|
|
650
|
+
</span>
|
|
651
|
+
</button>
|
|
652
|
+
</div>,
|
|
653
|
+
document.body
|
|
654
|
+
)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function TableCellActionMenuContainer({
|
|
658
|
+
anchorElem,
|
|
659
|
+
cellMerge,
|
|
660
|
+
}: {
|
|
661
|
+
anchorElem: HTMLElement
|
|
662
|
+
cellMerge: boolean
|
|
663
|
+
}): React.JSX.Element {
|
|
664
|
+
const [editor] = useLexicalComposerContext()
|
|
665
|
+
|
|
666
|
+
const menuButtonRef = useRef(null)
|
|
667
|
+
const menuRootRef = useRef(null)
|
|
668
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false)
|
|
669
|
+
|
|
670
|
+
const [tableCellNode, setTableMenuCellNode] = useState<TableCellNode | null>(null)
|
|
671
|
+
|
|
672
|
+
const [colorPickerModal, showColorPickerModal] = useModal()
|
|
673
|
+
|
|
674
|
+
const moveMenu = useCallback(() => {
|
|
675
|
+
const menu = menuButtonRef.current
|
|
676
|
+
const selection = $getSelection()
|
|
677
|
+
const nativeSelection = window.getSelection()
|
|
678
|
+
const activeElement = document.activeElement
|
|
679
|
+
|
|
680
|
+
if (selection == null || menu == null) {
|
|
681
|
+
setTableMenuCellNode(null)
|
|
682
|
+
return
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const rootElement = editor.getRootElement()
|
|
686
|
+
|
|
687
|
+
if (
|
|
688
|
+
$isRangeSelection(selection) &&
|
|
689
|
+
rootElement !== null &&
|
|
690
|
+
nativeSelection !== null &&
|
|
691
|
+
rootElement.contains(nativeSelection.anchorNode)
|
|
692
|
+
) {
|
|
693
|
+
const tableCellNodeFromSelection = $getTableCellNodeFromLexicalNode(
|
|
694
|
+
selection.anchor.getNode()
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
if (tableCellNodeFromSelection == null) {
|
|
698
|
+
setTableMenuCellNode(null)
|
|
699
|
+
return
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const tableCellParentNodeDOM = editor.getElementByKey(tableCellNodeFromSelection.getKey())
|
|
703
|
+
|
|
704
|
+
if (tableCellParentNodeDOM == null) {
|
|
705
|
+
setTableMenuCellNode(null)
|
|
706
|
+
return
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
setTableMenuCellNode(tableCellNodeFromSelection)
|
|
710
|
+
} else if (activeElement == null) {
|
|
711
|
+
setTableMenuCellNode(null)
|
|
712
|
+
}
|
|
713
|
+
}, [editor])
|
|
714
|
+
|
|
715
|
+
useEffect(() => {
|
|
716
|
+
return editor.registerUpdateListener(() => {
|
|
717
|
+
editor.getEditorState().read(() => {
|
|
718
|
+
moveMenu()
|
|
719
|
+
})
|
|
720
|
+
})
|
|
721
|
+
})
|
|
722
|
+
|
|
723
|
+
useEffect(() => {
|
|
724
|
+
const menuButtonDOM = menuButtonRef.current as HTMLButtonElement | null
|
|
725
|
+
|
|
726
|
+
if (menuButtonDOM != null && tableCellNode != null) {
|
|
727
|
+
const tableCellNodeDOM = editor.getElementByKey(tableCellNode.getKey())
|
|
728
|
+
|
|
729
|
+
if (tableCellNodeDOM != null) {
|
|
730
|
+
const tableCellRect = tableCellNodeDOM.getBoundingClientRect()
|
|
731
|
+
const menuRect = menuButtonDOM.getBoundingClientRect()
|
|
732
|
+
const anchorRect = anchorElem.getBoundingClientRect()
|
|
733
|
+
|
|
734
|
+
const top = tableCellRect.top - anchorRect.top + 4
|
|
735
|
+
const left = tableCellRect.right - menuRect.width - 10 - anchorRect.left
|
|
736
|
+
|
|
737
|
+
menuButtonDOM.style.opacity = '1'
|
|
738
|
+
menuButtonDOM.style.transform = `translate(${left}px, ${top}px)`
|
|
739
|
+
} else {
|
|
740
|
+
menuButtonDOM.style.opacity = '0'
|
|
741
|
+
menuButtonDOM.style.transform = 'translate(-10000px, -10000px)'
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}, [tableCellNode, editor, anchorElem])
|
|
745
|
+
|
|
746
|
+
const prevTableCellDOM = useRef(tableCellNode)
|
|
747
|
+
|
|
748
|
+
useEffect(() => {
|
|
749
|
+
if (prevTableCellDOM.current !== tableCellNode) {
|
|
750
|
+
setIsMenuOpen(false)
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
prevTableCellDOM.current = tableCellNode
|
|
754
|
+
}, [tableCellNode])
|
|
755
|
+
|
|
756
|
+
return (
|
|
757
|
+
<div className="table-cell-action-button-container" ref={menuButtonRef}>
|
|
758
|
+
{tableCellNode != null && (
|
|
759
|
+
<>
|
|
760
|
+
<button
|
|
761
|
+
type="button"
|
|
762
|
+
className="table-cell-action-button chevron-down"
|
|
763
|
+
onClick={(e) => {
|
|
764
|
+
e.stopPropagation()
|
|
765
|
+
setIsMenuOpen(!isMenuOpen)
|
|
766
|
+
}}
|
|
767
|
+
ref={menuRootRef}
|
|
768
|
+
>
|
|
769
|
+
<i className="chevron-down" />
|
|
770
|
+
</button>
|
|
771
|
+
{colorPickerModal}
|
|
772
|
+
{isMenuOpen && (
|
|
773
|
+
<TableActionMenu
|
|
774
|
+
contextRef={menuRootRef}
|
|
775
|
+
setIsMenuOpen={setIsMenuOpen}
|
|
776
|
+
onClose={() => {
|
|
777
|
+
setIsMenuOpen(false)
|
|
778
|
+
}}
|
|
779
|
+
tableCellNode={tableCellNode}
|
|
780
|
+
cellMerge={cellMerge}
|
|
781
|
+
showColorPickerModal={showColorPickerModal}
|
|
782
|
+
/>
|
|
783
|
+
)}
|
|
784
|
+
</>
|
|
785
|
+
)}
|
|
786
|
+
</div>
|
|
787
|
+
)
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
export function TableActionMenuPlugin({
|
|
791
|
+
anchorElem = document.body,
|
|
792
|
+
cellMerge = false,
|
|
793
|
+
}: {
|
|
794
|
+
anchorElem?: HTMLElement
|
|
795
|
+
cellMerge?: boolean
|
|
796
|
+
}): null | ReactPortal {
|
|
797
|
+
const isEditable = useLexicalEditable()
|
|
798
|
+
return createPortal(
|
|
799
|
+
isEditable ? (
|
|
800
|
+
<TableCellActionMenuContainer anchorElem={anchorElem} cellMerge={cellMerge} />
|
|
801
|
+
) : null,
|
|
802
|
+
anchorElem
|
|
803
|
+
)
|
|
804
|
+
}
|