@conloca/cms-spa 0.2.6 → 0.3.0
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/dist/spa/main.css +262 -21
- package/dist/ts/.build-inputs.json +99 -57
- package/dist/ts/CmsSpaApp.d.ts +4 -6
- package/dist/ts/CmsSpaApp.d.ts.map +1 -1
- package/dist/ts/CmsSpaApp.js +19 -8
- package/dist/ts/CmsSpaApp.js.map +1 -1
- package/dist/ts/components/conflicts/EditorNoticeStrip.d.ts +44 -0
- package/dist/ts/components/conflicts/EditorNoticeStrip.d.ts.map +1 -0
- package/dist/ts/components/conflicts/EditorNoticeStrip.js +55 -0
- package/dist/ts/components/conflicts/EditorNoticeStrip.js.map +1 -0
- package/dist/ts/components/conflicts/FieldConflictList.d.ts +20 -0
- package/dist/ts/components/conflicts/FieldConflictList.d.ts.map +1 -0
- package/dist/ts/components/conflicts/FieldConflictList.js +14 -0
- package/dist/ts/components/conflicts/FieldConflictList.js.map +1 -0
- package/dist/ts/components/conflicts/FieldConflictPicker.d.ts +28 -0
- package/dist/ts/components/conflicts/FieldConflictPicker.d.ts.map +1 -0
- package/dist/ts/components/conflicts/FieldConflictPicker.js +52 -0
- package/dist/ts/components/conflicts/FieldConflictPicker.js.map +1 -0
- package/dist/ts/components/conflicts/OverwriteNotice.d.ts +11 -0
- package/dist/ts/components/conflicts/OverwriteNotice.d.ts.map +1 -0
- package/dist/ts/components/conflicts/OverwriteNotice.js +8 -0
- package/dist/ts/components/conflicts/OverwriteNotice.js.map +1 -0
- package/dist/ts/components/conflicts/PageDraftMenu.d.ts +11 -0
- package/dist/ts/components/conflicts/PageDraftMenu.d.ts.map +1 -0
- package/dist/ts/components/conflicts/PageDraftMenu.js +20 -0
- package/dist/ts/components/conflicts/PageDraftMenu.js.map +1 -0
- package/dist/ts/components/conflicts/PeerAvatars.d.ts +9 -0
- package/dist/ts/components/conflicts/PeerAvatars.d.ts.map +1 -0
- package/dist/ts/components/conflicts/PeerAvatars.js +29 -0
- package/dist/ts/components/conflicts/PeerAvatars.js.map +1 -0
- package/dist/ts/components/conflicts/PuckConflicts.d.ts +13 -0
- package/dist/ts/components/conflicts/PuckConflicts.d.ts.map +1 -0
- package/dist/ts/components/conflicts/PuckConflicts.js +59 -0
- package/dist/ts/components/conflicts/PuckConflicts.js.map +1 -0
- package/dist/ts/components/conflicts/RecentVersionsDialog.d.ts +15 -0
- package/dist/ts/components/conflicts/RecentVersionsDialog.d.ts.map +1 -0
- package/dist/ts/components/conflicts/RecentVersionsDialog.js +94 -0
- package/dist/ts/components/conflicts/RecentVersionsDialog.js.map +1 -0
- package/dist/ts/components/conflicts/conflict-label.d.ts +12 -0
- package/dist/ts/components/conflicts/conflict-label.d.ts.map +1 -0
- package/dist/ts/components/conflicts/conflict-label.js +120 -0
- package/dist/ts/components/conflicts/conflict-label.js.map +1 -0
- package/dist/ts/components/conflicts/use-page-conflicts.d.ts +26 -0
- package/dist/ts/components/conflicts/use-page-conflicts.d.ts.map +1 -0
- package/dist/ts/components/conflicts/use-page-conflicts.js +93 -0
- package/dist/ts/components/conflicts/use-page-conflicts.js.map +1 -0
- package/dist/ts/components/conflicts/version-copy.d.ts +7 -0
- package/dist/ts/components/conflicts/version-copy.d.ts.map +1 -0
- package/dist/ts/components/conflicts/version-copy.js +31 -0
- package/dist/ts/components/conflicts/version-copy.js.map +1 -0
- package/dist/ts/components/dashboard/RecentActivity.d.ts.map +1 -1
- package/dist/ts/components/dashboard/RecentActivity.js +2 -1
- package/dist/ts/components/dashboard/RecentActivity.js.map +1 -1
- package/dist/ts/components/dialogs/CreatePageDialog.js +1 -1
- package/dist/ts/components/dialogs/CreatePageDialog.js.map +1 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts +2 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.js +15 -3
- package/dist/ts/components/dialogs/DataPropertiesDialog.js.map +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +2 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.js +16 -3
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.js.map +1 -1
- package/dist/ts/components/dialogs/PageMetadataDialog.d.ts +9 -2
- package/dist/ts/components/dialogs/PageMetadataDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/PageMetadataDialog.js +63 -16
- package/dist/ts/components/dialogs/PageMetadataDialog.js.map +1 -1
- package/dist/ts/components/dialogs/UnsavedChangesDialog.d.ts +16 -1
- package/dist/ts/components/dialogs/UnsavedChangesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/UnsavedChangesDialog.js +90 -2
- package/dist/ts/components/dialogs/UnsavedChangesDialog.js.map +1 -1
- package/dist/ts/components/dialogs/unsaved-guard.d.ts +9 -0
- package/dist/ts/components/dialogs/unsaved-guard.d.ts.map +1 -0
- package/dist/ts/components/dialogs/unsaved-guard.js +14 -0
- package/dist/ts/components/dialogs/unsaved-guard.js.map +1 -0
- package/dist/ts/components/editor/CMSMDXEditor.d.ts +6 -1
- package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.js +32 -15
- package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
- package/dist/ts/components/editor/EditorFrame.d.ts +22 -0
- package/dist/ts/components/editor/EditorFrame.d.ts.map +1 -0
- package/dist/ts/components/editor/EditorFrame.js +72 -0
- package/dist/ts/components/editor/EditorFrame.js.map +1 -0
- package/dist/ts/components/editor/FragmentBlockTypeSelect.d.ts +10 -0
- package/dist/ts/components/editor/FragmentBlockTypeSelect.d.ts.map +1 -0
- package/dist/ts/components/editor/FragmentBlockTypeSelect.js +187 -0
- package/dist/ts/components/editor/FragmentBlockTypeSelect.js.map +1 -0
- package/dist/ts/components/editor/FragmentComponentBlock.d.ts +7 -0
- package/dist/ts/components/editor/FragmentComponentBlock.d.ts.map +1 -0
- package/dist/ts/components/editor/FragmentComponentBlock.js +180 -0
- package/dist/ts/components/editor/FragmentComponentBlock.js.map +1 -0
- package/dist/ts/components/editor/FragmentEditor.d.ts +3 -1
- package/dist/ts/components/editor/FragmentEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/FragmentEditor.js +545 -130
- package/dist/ts/components/editor/FragmentEditor.js.map +1 -1
- package/dist/ts/components/editor/FragmentEditorHeaderActions.d.ts +20 -0
- package/dist/ts/components/editor/FragmentEditorHeaderActions.d.ts.map +1 -0
- package/dist/ts/components/editor/FragmentEditorHeaderActions.js +49 -0
- package/dist/ts/components/editor/FragmentEditorHeaderActions.js.map +1 -0
- package/dist/ts/components/editor/GenericBlock.d.ts.map +1 -1
- package/dist/ts/components/editor/GenericBlock.js +109 -12
- package/dist/ts/components/editor/GenericBlock.js.map +1 -1
- package/dist/ts/components/editor/InlinePreviewFrame.d.ts +19 -0
- package/dist/ts/components/editor/InlinePreviewFrame.d.ts.map +1 -0
- package/dist/ts/components/editor/InlinePreviewFrame.js +65 -0
- package/dist/ts/components/editor/InlinePreviewFrame.js.map +1 -0
- package/dist/ts/components/editor/JsxPropsPanel.d.ts.map +1 -1
- package/dist/ts/components/editor/JsxPropsPanel.js +62 -2
- package/dist/ts/components/editor/JsxPropsPanel.js.map +1 -1
- package/dist/ts/components/editor/LocaleSelector.d.ts +2 -1
- package/dist/ts/components/editor/LocaleSelector.d.ts.map +1 -1
- package/dist/ts/components/editor/LocaleSelector.js +2 -2
- package/dist/ts/components/editor/LocaleSelector.js.map +1 -1
- package/dist/ts/components/editor/MDXLivePreview.d.ts +2 -0
- package/dist/ts/components/editor/MDXLivePreview.d.ts.map +1 -1
- package/dist/ts/components/editor/MDXLivePreview.js +30 -38
- package/dist/ts/components/editor/MDXLivePreview.js.map +1 -1
- package/dist/ts/components/editor/MdxPageEditor.d.ts +7 -2
- package/dist/ts/components/editor/MdxPageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/MdxPageEditor.js +136 -10
- package/dist/ts/components/editor/MdxPageEditor.js.map +1 -1
- package/dist/ts/components/editor/PageEditor.d.ts +4 -1
- package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.js +78 -100
- package/dist/ts/components/editor/PageEditor.js.map +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.d.ts +15 -4
- package/dist/ts/components/editor/PageEditorHeaderActions.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.js +13 -7
- package/dist/ts/components/editor/PageEditorHeaderActions.js.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.d.ts +8 -2
- package/dist/ts/components/editor/PageEditorWrapper.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.js +99 -41
- package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
- package/dist/ts/components/editor/body-sync-plugin.d.ts +2 -0
- package/dist/ts/components/editor/body-sync-plugin.d.ts.map +1 -0
- package/dist/ts/components/editor/body-sync-plugin.js +32 -0
- package/dist/ts/components/editor/body-sync-plugin.js.map +1 -0
- package/dist/ts/components/editor/draft-media-config.d.ts +6 -0
- package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -1
- package/dist/ts/components/editor/draft-media-config.js +21 -0
- package/dist/ts/components/editor/draft-media-config.js.map +1 -1
- package/dist/ts/components/editor/fragment-save-check.d.ts +7 -0
- package/dist/ts/components/editor/fragment-save-check.d.ts.map +1 -0
- package/dist/ts/components/editor/fragment-save-check.js +13 -0
- package/dist/ts/components/editor/fragment-save-check.js.map +1 -0
- package/dist/ts/components/editor/fragment-save-lifetime.d.ts +18 -0
- package/dist/ts/components/editor/fragment-save-lifetime.d.ts.map +1 -0
- package/dist/ts/components/editor/fragment-save-lifetime.js +115 -0
- package/dist/ts/components/editor/fragment-save-lifetime.js.map +1 -0
- package/dist/ts/components/editor/host-wrapper-plugin.d.ts.map +1 -1
- package/dist/ts/components/editor/host-wrapper-plugin.js +20 -7
- package/dist/ts/components/editor/host-wrapper-plugin.js.map +1 -1
- package/dist/ts/components/editor/index.d.ts +0 -1
- package/dist/ts/components/editor/index.d.ts.map +1 -1
- package/dist/ts/components/editor/index.js +0 -1
- package/dist/ts/components/editor/index.js.map +1 -1
- package/dist/ts/components/editor/insert-menu/InsertMdxComponentButton.d.ts.map +1 -1
- package/dist/ts/components/editor/insert-menu/InsertMdxComponentButton.js +6 -11
- package/dist/ts/components/editor/insert-menu/InsertMdxComponentButton.js.map +1 -1
- package/dist/ts/components/editor/insert-menu/SlashMenuPlugin.d.ts.map +1 -1
- package/dist/ts/components/editor/insert-menu/SlashMenuPlugin.js +66 -12
- package/dist/ts/components/editor/insert-menu/SlashMenuPlugin.js.map +1 -1
- package/dist/ts/components/editor/insert-menu/insert-payload.d.ts +16 -21
- package/dist/ts/components/editor/insert-menu/insert-payload.d.ts.map +1 -1
- package/dist/ts/components/editor/insert-menu/insert-payload.js +75 -22
- package/dist/ts/components/editor/insert-menu/insert-payload.js.map +1 -1
- package/dist/ts/components/editor/insert-menu/mdx-components-plugin.d.ts +3 -1
- package/dist/ts/components/editor/insert-menu/mdx-components-plugin.d.ts.map +1 -1
- package/dist/ts/components/editor/insert-menu/mdx-components-plugin.js +5 -3
- package/dist/ts/components/editor/insert-menu/mdx-components-plugin.js.map +1 -1
- package/dist/ts/components/editor/jsx-layout-plugin.d.ts +25 -0
- package/dist/ts/components/editor/jsx-layout-plugin.d.ts.map +1 -0
- package/dist/ts/components/editor/jsx-layout-plugin.js +77 -0
- package/dist/ts/components/editor/jsx-layout-plugin.js.map +1 -0
- package/dist/ts/components/editor/offered-mdx-components.d.ts +11 -0
- package/dist/ts/components/editor/offered-mdx-components.d.ts.map +1 -0
- package/dist/ts/components/editor/offered-mdx-components.js +27 -0
- package/dist/ts/components/editor/offered-mdx-components.js.map +1 -0
- package/dist/ts/components/editor/page-setting-targets.d.ts.map +1 -1
- package/dist/ts/components/editor/page-setting-targets.js +2 -1
- package/dist/ts/components/editor/page-setting-targets.js.map +1 -1
- package/dist/ts/components/editor/preview-availability.d.ts +16 -1
- package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
- package/dist/ts/components/editor/preview-availability.js +16 -1
- package/dist/ts/components/editor/preview-availability.js.map +1 -1
- package/dist/ts/components/editor/prop-field-hint.d.ts +13 -0
- package/dist/ts/components/editor/prop-field-hint.d.ts.map +1 -0
- package/dist/ts/components/editor/prop-field-hint.js +70 -0
- package/dist/ts/components/editor/prop-field-hint.js.map +1 -0
- package/dist/ts/components/editor/soft-break-plugin.d.ts +21 -0
- package/dist/ts/components/editor/soft-break-plugin.d.ts.map +1 -0
- package/dist/ts/components/editor/soft-break-plugin.js +52 -0
- package/dist/ts/components/editor/soft-break-plugin.js.map +1 -0
- package/dist/ts/components/editor/use-live-page-settings.d.ts +13 -0
- package/dist/ts/components/editor/use-live-page-settings.d.ts.map +1 -0
- package/dist/ts/components/editor/use-live-page-settings.js +76 -0
- package/dist/ts/components/editor/use-live-page-settings.js.map +1 -0
- package/dist/ts/components/editor/usePagePreview.d.ts +32 -0
- package/dist/ts/components/editor/usePagePreview.d.ts.map +1 -0
- package/dist/ts/components/editor/usePagePreview.js +252 -0
- package/dist/ts/components/editor/usePagePreview.js.map +1 -0
- package/dist/ts/components/editors/DataEditor.d.ts +6 -3
- package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
- package/dist/ts/components/editors/DataEditor.js +153 -19
- package/dist/ts/components/editors/DataEditor.js.map +1 -1
- package/dist/ts/components/fields/MDXEditField.d.ts +1 -1
- package/dist/ts/components/fields/MDXEditField.js +2 -2
- package/dist/ts/components/fields/MDXEditField.js.map +1 -1
- package/dist/ts/components/forms/SchemaForm.d.ts.map +1 -1
- package/dist/ts/components/forms/SchemaForm.js +1 -9
- package/dist/ts/components/forms/SchemaForm.js.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.js +43 -5
- package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
- package/dist/ts/components/pages/DataList.d.ts.map +1 -1
- package/dist/ts/components/pages/DataList.js +16 -4
- package/dist/ts/components/pages/DataList.js.map +1 -1
- package/dist/ts/components/pages/FragmentList.d.ts.map +1 -1
- package/dist/ts/components/pages/FragmentList.js +10 -0
- package/dist/ts/components/pages/FragmentList.js.map +1 -1
- package/dist/ts/components/pages/PageList.d.ts.map +1 -1
- package/dist/ts/components/pages/PageList.js +54 -118
- package/dist/ts/components/pages/PageList.js.map +1 -1
- package/dist/ts/components/pages/PageRow.d.ts +21 -0
- package/dist/ts/components/pages/PageRow.d.ts.map +1 -0
- package/dist/ts/components/pages/PageRow.js +70 -0
- package/dist/ts/components/pages/PageRow.js.map +1 -0
- package/dist/ts/components/pages/PageTable.d.ts +21 -0
- package/dist/ts/components/pages/PageTable.d.ts.map +1 -0
- package/dist/ts/components/pages/PageTable.js +12 -0
- package/dist/ts/components/pages/PageTable.js.map +1 -0
- package/dist/ts/components/pages/page-list-model.d.ts +20 -0
- package/dist/ts/components/pages/page-list-model.d.ts.map +1 -0
- package/dist/ts/components/pages/page-list-model.js +78 -0
- package/dist/ts/components/pages/page-list-model.js.map +1 -0
- package/dist/ts/components/puck/MDXContent.d.ts +3 -3
- package/dist/ts/components/puck/MDXContent.d.ts.map +1 -1
- package/dist/ts/components/puck/MDXContent.js +24 -72
- package/dist/ts/components/puck/MDXContent.js.map +1 -1
- package/dist/ts/components/puck/csp-frame-harness.d.ts +14 -0
- package/dist/ts/components/puck/csp-frame-harness.d.ts.map +1 -0
- package/dist/ts/components/puck/csp-frame-harness.js +85 -0
- package/dist/ts/components/puck/csp-frame-harness.js.map +1 -0
- package/dist/ts/components/puck/use-fragment-render.d.ts +9 -0
- package/dist/ts/components/puck/use-fragment-render.d.ts.map +1 -0
- package/dist/ts/components/puck/use-fragment-render.js +70 -0
- package/dist/ts/components/puck/use-fragment-render.js.map +1 -0
- package/dist/ts/components/sandbox/ContentSandbox.d.ts +3 -5
- package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.js +6 -8
- package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
- package/dist/ts/components/sandbox/frame-runtime.d.ts +1 -1
- package/dist/ts/components/sandbox/frame-runtime.d.ts.map +1 -1
- package/dist/ts/components/sandbox/frame-runtime.js +1 -1
- package/dist/ts/components/sandbox/frame-runtime.js.map +1 -1
- package/dist/ts/components/toast.d.ts +8 -4
- package/dist/ts/components/toast.d.ts.map +1 -1
- package/dist/ts/components/toast.js +6 -1
- package/dist/ts/components/toast.js.map +1 -1
- package/dist/ts/components/ui/Card.d.ts +3 -5
- package/dist/ts/components/ui/Card.d.ts.map +1 -1
- package/dist/ts/components/ui/Card.js +3 -5
- package/dist/ts/components/ui/Card.js.map +1 -1
- package/dist/ts/components/ui/Select.d.ts.map +1 -1
- package/dist/ts/components/ui/Select.js +12 -3
- package/dist/ts/components/ui/Select.js.map +1 -1
- package/dist/ts/draft-tools.d.ts +76 -0
- package/dist/ts/draft-tools.d.ts.map +1 -0
- package/dist/ts/draft-tools.js +2 -0
- package/dist/ts/draft-tools.js.map +1 -0
- package/dist/ts/frame/channel.d.ts +1 -1
- package/dist/ts/frame/channel.d.ts.map +1 -1
- package/dist/ts/frame/channel.js +3 -0
- package/dist/ts/frame/channel.js.map +1 -1
- package/dist/ts/frame/editor-frame.d.ts.map +1 -1
- package/dist/ts/frame/editor-frame.js +188 -30
- package/dist/ts/frame/editor-frame.js.map +1 -1
- package/dist/ts/frame/protocol.d.ts +73 -4
- package/dist/ts/frame/protocol.d.ts.map +1 -1
- package/dist/ts/frame/protocol.js +54 -16
- package/dist/ts/frame/protocol.js.map +1 -1
- package/dist/ts/hooks/useUnsavedChangesGuard.d.ts +5 -3
- package/dist/ts/hooks/useUnsavedChangesGuard.d.ts.map +1 -1
- package/dist/ts/hooks/useUnsavedChangesGuard.js +17 -7
- package/dist/ts/hooks/useUnsavedChangesGuard.js.map +1 -1
- package/dist/ts/host-style-probe.d.ts.map +1 -1
- package/dist/ts/host-style-probe.js +160 -40
- package/dist/ts/host-style-probe.js.map +1 -1
- package/dist/ts/index.d.ts +13 -0
- package/dist/ts/index.d.ts.map +1 -1
- package/dist/ts/index.js +14 -0
- package/dist/ts/index.js.map +1 -1
- package/dist/ts/live/data-binding.d.ts +67 -0
- package/dist/ts/live/data-binding.d.ts.map +1 -0
- package/dist/ts/live/data-binding.js +215 -0
- package/dist/ts/live/data-binding.js.map +1 -0
- package/dist/ts/live/doc-channel.d.ts +74 -0
- package/dist/ts/live/doc-channel.d.ts.map +1 -0
- package/dist/ts/live/doc-channel.js +293 -0
- package/dist/ts/live/doc-channel.js.map +1 -0
- package/dist/ts/live/held-fragment-edits.d.ts +15 -0
- package/dist/ts/live/held-fragment-edits.d.ts.map +1 -0
- package/dist/ts/live/held-fragment-edits.js +47 -0
- package/dist/ts/live/held-fragment-edits.js.map +1 -0
- package/dist/ts/live/markdown-binding.d.ts +54 -0
- package/dist/ts/live/markdown-binding.d.ts.map +1 -0
- package/dist/ts/live/markdown-binding.js +618 -0
- package/dist/ts/live/markdown-binding.js.map +1 -0
- package/dist/ts/live/markdown-live-plugin.d.ts +42 -0
- package/dist/ts/live/markdown-live-plugin.d.ts.map +1 -0
- package/dist/ts/live/markdown-live-plugin.js +918 -0
- package/dist/ts/live/markdown-live-plugin.js.map +1 -0
- package/dist/ts/live/messages.d.ts +142 -0
- package/dist/ts/live/messages.d.ts.map +1 -0
- package/dist/ts/live/messages.js +266 -0
- package/dist/ts/live/messages.js.map +1 -0
- package/dist/ts/live/puck-binding.d.ts +88 -0
- package/dist/ts/live/puck-binding.d.ts.map +1 -0
- package/dist/ts/live/puck-binding.js +467 -0
- package/dist/ts/live/puck-binding.js.map +1 -0
- package/dist/ts/live/undo.d.ts +29 -0
- package/dist/ts/live/undo.d.ts.map +1 -0
- package/dist/ts/live/undo.js +104 -0
- package/dist/ts/live/undo.js.map +1 -0
- package/dist/ts/live/use-live.d.ts +77 -0
- package/dist/ts/live/use-live.d.ts.map +1 -0
- package/dist/ts/live/use-live.js +207 -0
- package/dist/ts/live/use-live.js.map +1 -0
- package/dist/ts/mdx-components-define.d.ts +52 -15
- package/dist/ts/mdx-components-define.d.ts.map +1 -1
- package/dist/ts/mdx-components-define.js +136 -0
- package/dist/ts/mdx-components-define.js.map +1 -1
- package/dist/ts/mdx-components.d.ts +11 -19
- package/dist/ts/mdx-components.d.ts.map +1 -1
- package/dist/ts/mdx-components.js +23 -32
- package/dist/ts/mdx-components.js.map +1 -1
- package/dist/ts/media/AssetScopePill.d.ts.map +1 -1
- package/dist/ts/media/AssetScopePill.js +2 -1
- package/dist/ts/media/AssetScopePill.js.map +1 -1
- package/dist/ts/merge-default-props.d.ts.map +1 -1
- package/dist/ts/merge-default-props.js +3 -0
- package/dist/ts/merge-default-props.js.map +1 -1
- package/dist/ts/selected-block.d.ts +27 -2
- package/dist/ts/selected-block.d.ts.map +1 -1
- package/dist/ts/selected-block.js +43 -1
- package/dist/ts/selected-block.js.map +1 -1
- package/dist/ts/site-render.d.ts +60 -0
- package/dist/ts/site-render.d.ts.map +1 -0
- package/dist/ts/site-render.js +87 -0
- package/dist/ts/site-render.js.map +1 -0
- package/dist/ts/types.d.ts +3 -0
- package/dist/ts/types.d.ts.map +1 -1
- package/dist/ts/ui-config.d.ts +29 -13
- package/dist/ts/ui-config.d.ts.map +1 -1
- package/dist/ts/ui-config.js +14 -3
- package/dist/ts/ui-config.js.map +1 -1
- package/dist/ts/utils/apply-clash.d.ts +44 -0
- package/dist/ts/utils/apply-clash.d.ts.map +1 -0
- package/dist/ts/utils/apply-clash.js +102 -0
- package/dist/ts/utils/apply-clash.js.map +1 -0
- package/dist/ts/utils/mdast-tree.d.ts +5 -7
- package/dist/ts/utils/mdast-tree.d.ts.map +1 -1
- package/dist/ts/utils/mdast-tree.js +8 -13
- package/dist/ts/utils/mdast-tree.js.map +1 -1
- package/dist/ts/utils/pageMetadata.d.ts +6 -2
- package/dist/ts/utils/pageMetadata.d.ts.map +1 -1
- package/dist/ts/utils/pageMetadata.js +25 -7
- package/dist/ts/utils/pageMetadata.js.map +1 -1
- package/dist/ts/utils/schema-fields.d.ts +2 -0
- package/dist/ts/utils/schema-fields.d.ts.map +1 -1
- package/dist/ts/utils/schema-fields.js +8 -0
- package/dist/ts/utils/schema-fields.js.map +1 -1
- package/dist/ts/write-access.d.ts +2 -0
- package/dist/ts/write-access.d.ts.map +1 -1
- package/dist/ts/write-access.js +9 -4
- package/dist/ts/write-access.js.map +1 -1
- package/package.json +18 -7
- package/src/CmsSpaApp.tsx +20 -11
- package/src/components/conflicts/EditorNoticeStrip.tsx +135 -0
- package/src/components/conflicts/FieldConflictList.tsx +59 -0
- package/src/components/conflicts/FieldConflictPicker.tsx +158 -0
- package/src/components/conflicts/OverwriteNotice.tsx +30 -0
- package/src/components/conflicts/PageDraftMenu.tsx +51 -0
- package/src/components/conflicts/PeerAvatars.tsx +51 -0
- package/src/components/conflicts/PuckConflicts.tsx +92 -0
- package/src/components/conflicts/RecentVersionsDialog.tsx +154 -0
- package/src/components/conflicts/conflict-label.ts +124 -0
- package/src/components/conflicts/use-page-conflicts.ts +112 -0
- package/src/components/conflicts/version-copy.ts +33 -0
- package/src/components/dashboard/RecentActivity.tsx +3 -2
- package/src/components/dialogs/CreatePageDialog.tsx +1 -1
- package/src/components/dialogs/DataPropertiesDialog.tsx +22 -4
- package/src/components/dialogs/FragmentPropertiesDialog.tsx +23 -4
- package/src/components/dialogs/PageMetadataDialog.tsx +157 -65
- package/src/components/dialogs/UnsavedChangesDialog.tsx +171 -21
- package/src/components/dialogs/unsaved-guard.ts +15 -0
- package/src/components/editor/CMSMDXEditor.tsx +238 -198
- package/src/components/editor/EditorFrame.tsx +116 -0
- package/src/components/editor/FragmentBlockTypeSelect.tsx +245 -0
- package/src/components/editor/FragmentComponentBlock.tsx +257 -0
- package/src/components/editor/FragmentEditor.tsx +899 -213
- package/src/components/editor/FragmentEditorHeaderActions.tsx +77 -0
- package/src/components/editor/GenericBlock.tsx +127 -16
- package/src/components/editor/InlinePreviewFrame.tsx +78 -0
- package/src/components/editor/JsxPropsPanel.tsx +90 -6
- package/src/components/editor/LocaleSelector.tsx +4 -2
- package/src/components/editor/MDXLivePreview.tsx +44 -46
- package/src/components/editor/MdxPageEditor.tsx +247 -7
- package/src/components/editor/PageEditor.tsx +154 -121
- package/src/components/editor/PageEditorHeaderActions.tsx +65 -27
- package/src/components/editor/PageEditorWrapper.tsx +122 -45
- package/src/components/editor/body-sync-plugin.ts +44 -0
- package/src/components/editor/draft-media-config.ts +22 -0
- package/src/components/editor/fragment-save-check.ts +26 -0
- package/src/components/editor/fragment-save-lifetime.ts +142 -0
- package/src/components/editor/host-wrapper-plugin.ts +28 -7
- package/src/components/editor/index.ts +0 -1
- package/src/components/editor/insert-menu/InsertMdxComponentButton.tsx +7 -11
- package/src/components/editor/insert-menu/SlashMenuPlugin.tsx +95 -18
- package/src/components/editor/insert-menu/insert-payload.ts +79 -30
- package/src/components/editor/insert-menu/mdx-components-plugin.ts +5 -3
- package/src/components/editor/jsx-layout-plugin.ts +103 -0
- package/src/components/editor/offered-mdx-components.ts +35 -0
- package/src/components/editor/page-setting-targets.tsx +2 -0
- package/src/components/editor/preview-availability.ts +21 -1
- package/src/components/editor/prop-field-hint.ts +75 -0
- package/src/components/editor/soft-break-plugin.ts +55 -0
- package/src/components/editor/use-live-page-settings.ts +80 -0
- package/src/components/editor/usePagePreview.ts +291 -0
- package/src/components/editors/DataEditor.tsx +257 -22
- package/src/components/fields/MDXEditField.tsx +2 -2
- package/src/components/forms/SchemaForm.tsx +1 -10
- package/src/components/media/AssetDetailSidebar.tsx +47 -6
- package/src/components/pages/DataList.tsx +14 -4
- package/src/components/pages/FragmentList.tsx +8 -0
- package/src/components/pages/PageList.tsx +90 -337
- package/src/components/pages/PageRow.tsx +290 -0
- package/src/components/pages/PageTable.tsx +71 -0
- package/src/components/pages/page-list-model.ts +98 -0
- package/src/components/puck/MDXContent.tsx +37 -113
- package/src/components/puck/csp-frame-harness.tsx +99 -0
- package/src/components/puck/use-fragment-render.ts +82 -0
- package/src/components/sandbox/ContentSandbox.tsx +6 -11
- package/src/components/sandbox/frame-runtime.ts +0 -2
- package/src/components/toast.tsx +23 -5
- package/src/components/ui/Card.tsx +3 -5
- package/src/components/ui/Select.tsx +14 -6
- package/src/draft-tools.ts +77 -0
- package/src/frame/channel.ts +3 -1
- package/src/frame/editor-frame.ts +210 -30
- package/src/frame/protocol.ts +98 -15
- package/src/hooks/useUnsavedChangesGuard.ts +17 -6
- package/src/host-style-probe.ts +157 -37
- package/src/index.ts +90 -0
- package/src/live/data-binding.ts +252 -0
- package/src/live/doc-channel.ts +343 -0
- package/src/live/held-fragment-edits.ts +47 -0
- package/src/live/markdown-binding.ts +630 -0
- package/src/live/markdown-live-plugin.tsx +1037 -0
- package/src/live/messages.ts +370 -0
- package/src/live/puck-binding.tsx +579 -0
- package/src/live/undo.ts +112 -0
- package/src/live/use-live.ts +264 -0
- package/src/main.css +184 -4
- package/src/mdx-components-define.ts +170 -24
- package/src/mdx-components.ts +29 -30
- package/src/media/AssetScopePill.tsx +2 -1
- package/src/merge-default-props.ts +4 -0
- package/src/selected-block.ts +55 -3
- package/src/site-render.ts +146 -0
- package/src/types.ts +3 -0
- package/src/ui-config.ts +51 -15
- package/src/utils/apply-clash.ts +113 -0
- package/src/utils/mdast-tree.ts +8 -12
- package/src/utils/pageMetadata.ts +25 -7
- package/src/utils/schema-fields.ts +9 -0
- package/src/write-access.ts +10 -4
- package/styles/tailwind-theme.css +11 -0
- package/dist/ts/components/editor/ContentDiff.d.ts +0 -10
- package/dist/ts/components/editor/ContentDiff.d.ts.map +0 -1
- package/dist/ts/components/editor/ContentDiff.js +0 -52
- package/dist/ts/components/editor/ContentDiff.js.map +0 -1
- package/src/components/editor/ContentDiff.tsx +0 -251
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Binds an MDXEditor to a shared doc's body text: local edits go out through an editor replica, remote ones come in. */
|
|
3
|
+
import { parseMdx, splitEsm } from '@conloca/mdx';
|
|
4
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
5
|
+
import { activeEditor$, addComposerChild$, addNestedEditorChild$, addTableCellEditorChild$, addTopAreaChild$, Cell, inFocus$, initialMarkdownNormalize$, isPartOftheEditorUI, markdown$, markdownProcessingError$, markdownSourceEditorValue$, muteChange$, NESTED_EDITOR_UPDATED_COMMAND, readOnly$, realmPlugin, rootEditor$, setMarkdown$, useCellValue, usePublisher, viewMode$, } from '@mdxeditor/editor';
|
|
6
|
+
import { $createParagraphNode, $createTextNode, $getNearestNodeFromDOMNode, $getNodeByKey, $getRoot, $getSelection, $isElementNode, $isRangeSelection, $setSelection, COMMAND_PRIORITY_CRITICAL, FOCUS_COMMAND, getNearestEditorFromDOMNode, REDO_COMMAND, SKIP_DOM_SELECTION_TAG, UNDO_COMMAND, } from 'lexical';
|
|
7
|
+
import { useEffect, useLayoutEffect, useReducer, useRef, useSyncExternalStore } from 'react';
|
|
8
|
+
import { flushSync } from 'react-dom';
|
|
9
|
+
import * as Y from 'yjs';
|
|
10
|
+
import { notifyEditorDirtyChanged } from '../editor-flush.js';
|
|
11
|
+
import { commitDrafts, getSelectedBlock, markLiveEditing, setSelectedBlock } from '../selected-block.js';
|
|
12
|
+
import { LOCAL_ORIGIN } from './doc-channel.js';
|
|
13
|
+
import { anchorCaret, caretAfterRemoteEdit, caretAtAnchor, createEditorReplica, syncEditorReplica, writeEditorEdit, } from './markdown-binding.js';
|
|
14
|
+
import { createLocalUndo } from './undo.js';
|
|
15
|
+
export const HTML_COMMENT_NOTICE = 'This page has an HTML comment. Replace it here in the Source view with {/* */} to edit it live again.';
|
|
16
|
+
// Source text is read as MDX (O(page)) and written once typing pauses this long, not on every key.
|
|
17
|
+
const SOURCE_WRITE_DELAY_MS = 300;
|
|
18
|
+
const STALE_FIX = 'A teammate changed this page while you were fixing it in the Source view, so what you typed there is not written. Copy it to redo your fix on their version.';
|
|
19
|
+
// Stable, so the store is not resubscribed on each render of an editor that has no hold to watch.
|
|
20
|
+
const noSubscribe = () => () => { };
|
|
21
|
+
const notHeld = () => null;
|
|
22
|
+
/** The text a run of held keys types, and how many characters before it their Backspaces erase (more than typed). */
|
|
23
|
+
function typedText(keys) {
|
|
24
|
+
let typed = '';
|
|
25
|
+
let erased = 0;
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
if (key !== 'Backspace')
|
|
28
|
+
typed += key === 'Enter' ? '\n' : key;
|
|
29
|
+
else if (typed === '')
|
|
30
|
+
erased++;
|
|
31
|
+
else
|
|
32
|
+
typed = typed.slice(0, -1);
|
|
33
|
+
}
|
|
34
|
+
return { typed, erased };
|
|
35
|
+
}
|
|
36
|
+
// The keys each bound editor holds for a body on its way back; they exist nowhere else.
|
|
37
|
+
const heldKeyLists = new Set();
|
|
38
|
+
// Per bound editor: whether it holds a stale Source fix to copy, which exists nowhere else.
|
|
39
|
+
const heldFixes = new Set();
|
|
40
|
+
/** Some editor holds typed keys for a body not back yet, or a stale Source fix to copy; a leave guard counts them. */
|
|
41
|
+
export function hasHeldWork() {
|
|
42
|
+
return [...heldKeyLists].some((keys) => keys.length > 0) || [...heldFixes].some((holds) => holds());
|
|
43
|
+
}
|
|
44
|
+
/** A component block, whose MDAST holds its body: only mdxeditor's `jsx` nodes have that type, and both methods. */
|
|
45
|
+
function isComponentNode(node) {
|
|
46
|
+
return node?.getType() === 'jsx';
|
|
47
|
+
}
|
|
48
|
+
function writeBody(body) {
|
|
49
|
+
body.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, undefined);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* mdxeditor writes a cell with the handler Tab, Enter and blur leave it by, which also makes no cell active: the cell
|
|
53
|
+
* the user is still in is made active again, as focusing it does.
|
|
54
|
+
*/
|
|
55
|
+
function writeCell(cell) {
|
|
56
|
+
cell.dispatchCommand(NESTED_EDITOR_UPDATED_COMMAND, undefined);
|
|
57
|
+
if (cell.getRootElement()?.contains(document.activeElement)) {
|
|
58
|
+
cell.dispatchCommand(FOCUS_COMMAND, new FocusEvent('focus'));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Where `part` sits in `within` when it sits there once, else null. */
|
|
62
|
+
function once(within, part) {
|
|
63
|
+
return part !== '' && within.indexOf(part) === within.lastIndexOf(part) ? within.indexOf(part) : null;
|
|
64
|
+
}
|
|
65
|
+
/** Why the editor opened the Source view: a body it cannot import is fixed there, by anyone, never locked. */
|
|
66
|
+
function fixNotice(body, error) {
|
|
67
|
+
if (body.includes('<!--'))
|
|
68
|
+
return HTML_COMMENT_NOTICE;
|
|
69
|
+
return `This page has MDX that needs fixing (${error}). Fix it here in the Source view to edit it live again.`;
|
|
70
|
+
}
|
|
71
|
+
function $readCaret() {
|
|
72
|
+
const selection = $getSelection();
|
|
73
|
+
if (!$isRangeSelection(selection))
|
|
74
|
+
return null;
|
|
75
|
+
const anchor = selection.anchor.getNode();
|
|
76
|
+
const block = anchor.getTopLevelElement();
|
|
77
|
+
if (!block)
|
|
78
|
+
return null;
|
|
79
|
+
let offset = 0;
|
|
80
|
+
for (const node of block.getAllTextNodes()) {
|
|
81
|
+
if (node.is(anchor))
|
|
82
|
+
return { block: block.getIndexWithinParent(), offset: offset + selection.anchor.offset };
|
|
83
|
+
offset += node.getTextContentSize();
|
|
84
|
+
}
|
|
85
|
+
return { block: block.getIndexWithinParent(), offset: 0 };
|
|
86
|
+
}
|
|
87
|
+
/** Puts the caret back at `offset` in top-level block `block`, clamped to the block's text. */
|
|
88
|
+
function $restoreCaret({ block, offset }) {
|
|
89
|
+
const element = $getRoot().getChildAtIndex(block);
|
|
90
|
+
if (!$isElementNode(element))
|
|
91
|
+
return;
|
|
92
|
+
let rest = offset;
|
|
93
|
+
for (const node of element.getAllTextNodes()) {
|
|
94
|
+
if (rest <= node.getTextContentSize()) {
|
|
95
|
+
node.select(rest, rest);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
rest -= node.getTextContentSize();
|
|
99
|
+
}
|
|
100
|
+
element.selectEnd();
|
|
101
|
+
}
|
|
102
|
+
/** Each top-level block's text as the editor shows it. */
|
|
103
|
+
function $blockTexts() {
|
|
104
|
+
return $getRoot()
|
|
105
|
+
.getChildren()
|
|
106
|
+
.map((block) => block.getTextContent());
|
|
107
|
+
}
|
|
108
|
+
function $selectedBlock() {
|
|
109
|
+
const selection = $getSelection();
|
|
110
|
+
if (!$isRangeSelection(selection))
|
|
111
|
+
return null;
|
|
112
|
+
return selection.anchor.getNode().getTopLevelElement()?.getIndexWithinParent() ?? null;
|
|
113
|
+
}
|
|
114
|
+
/** A block as Lexical holds it, minus source positions and parser data, which shift when the text above them changes. */
|
|
115
|
+
function $signature(node) {
|
|
116
|
+
return JSON.stringify($serialize(node), (key, value) => (key === 'position' || key === 'data' ? undefined : value));
|
|
117
|
+
}
|
|
118
|
+
function $serialize(node) {
|
|
119
|
+
const json = node.exportJSON();
|
|
120
|
+
return $isElementNode(node) ? { ...json, children: node.getChildren().map($serialize) } : json;
|
|
121
|
+
}
|
|
122
|
+
/** The longest run of equal blocks, in order: for each kept block, its index in `after` → its index in `before`. */
|
|
123
|
+
function keptBlocks(before, after) {
|
|
124
|
+
// rest[i][j]: how many blocks the run keeps from before[i..] and after[j..].
|
|
125
|
+
const rest = Array.from({ length: before.length + 1 }, () => Array.from({ length: after.length + 1 }, () => 0));
|
|
126
|
+
const at = (i, j) => rest[i]?.[j] ?? 0;
|
|
127
|
+
for (let i = before.length - 1; i >= 0; i--) {
|
|
128
|
+
const row = rest[i] ?? [];
|
|
129
|
+
for (let j = after.length - 1; j >= 0; j--) {
|
|
130
|
+
row[j] = before[i] === after[j] ? at(i + 1, j + 1) + 1 : Math.max(at(i + 1, j), at(i, j + 1));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const kept = new Map();
|
|
134
|
+
for (let i = 0, j = 0; i < before.length && j < after.length;) {
|
|
135
|
+
if (before[i] === after[j])
|
|
136
|
+
kept.set(j++, i++);
|
|
137
|
+
else if (at(i + 1, j) >= at(i, j + 1))
|
|
138
|
+
i++;
|
|
139
|
+
else
|
|
140
|
+
j++;
|
|
141
|
+
}
|
|
142
|
+
return kept;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The blocks of `before` that are not kept, each paired in order with a new block between the same kept neighbours
|
|
146
|
+
* (null when that gap has fewer new blocks): where a rebuilt block's caret, focus and panel selection go.
|
|
147
|
+
*/
|
|
148
|
+
function successors(beforeCount, afterCount, kept) {
|
|
149
|
+
const paired = new Map();
|
|
150
|
+
let i = 0;
|
|
151
|
+
let j = 0;
|
|
152
|
+
for (const [nextJ, nextI] of [...kept, [afterCount, beforeCount]]) {
|
|
153
|
+
for (let k = 0; i + k < nextI; k++)
|
|
154
|
+
paired.set(i + k, j + k < nextJ ? j + k : null);
|
|
155
|
+
i = nextI + 1;
|
|
156
|
+
j = nextJ + 1;
|
|
157
|
+
}
|
|
158
|
+
return paired;
|
|
159
|
+
}
|
|
160
|
+
/** Where a caret at `offset` in `before` sits in `after`: kept while the text before it is unchanged, else by the text after it. */
|
|
161
|
+
function shiftedOffset(before, after, offset) {
|
|
162
|
+
if (after.startsWith(before.slice(0, offset)))
|
|
163
|
+
return offset;
|
|
164
|
+
const tail = before.slice(offset);
|
|
165
|
+
return after.endsWith(tail) ? after.length - tail.length : Math.min(offset, after.length);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The text `text` would hold after `undo`'s next step off `stack`, or null with nothing to step: the step runs on a copy
|
|
169
|
+
* of the doc (its stack items name structs by ID, which the copy keeps), so nothing is written to the shared doc.
|
|
170
|
+
*/
|
|
171
|
+
function stepResult(text, undo, stack) {
|
|
172
|
+
const items = undo[stack];
|
|
173
|
+
const item = items[items.length - 1];
|
|
174
|
+
const doc = text.doc;
|
|
175
|
+
if (!item)
|
|
176
|
+
return null;
|
|
177
|
+
const name = doc ? [...doc.share].find(([, type]) => Object.is(type, text))?.[0] : undefined;
|
|
178
|
+
if (!doc || name === undefined)
|
|
179
|
+
throw new Error('the text is no root type of its doc');
|
|
180
|
+
// No gc: an undo of an erase restores content the copy would otherwise drop as deleted when it loads the update.
|
|
181
|
+
const copy = new Y.Doc({ gc: false });
|
|
182
|
+
try {
|
|
183
|
+
Y.applyUpdate(copy, Y.encodeStateAsUpdate(doc));
|
|
184
|
+
const copied = copy.getText(name);
|
|
185
|
+
const manager = new Y.UndoManager(copied);
|
|
186
|
+
manager[stack].push(item);
|
|
187
|
+
if (stack === 'undoStack')
|
|
188
|
+
manager.undo();
|
|
189
|
+
else
|
|
190
|
+
manager.redo();
|
|
191
|
+
return copied.toJSON();
|
|
192
|
+
}
|
|
193
|
+
finally {
|
|
194
|
+
copy.destroy();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* The editor side of an MDX body in a shared doc. Per mount it keeps `shadow` (the markdown the editor last showed) and
|
|
199
|
+
* a replica of the doc as the editor last showed it. A local change is diffed into the replica and sent as one update,
|
|
200
|
+
* so Yjs merges it with remote changes the editor has not shown. A remote change is shown on the next frame, and every
|
|
201
|
+
* block it did not change stays the same node: a body being typed in keeps its focus and caret, the toolbar its target
|
|
202
|
+
* and the side panel its block. Input that would be lost with a rebuilt block is written first. Undo and redo run its
|
|
203
|
+
* own undo manager over `undoScope`, so they revert only this user's edits.
|
|
204
|
+
*/
|
|
205
|
+
export function markdownLivePlugin(input) {
|
|
206
|
+
const { text, held, check } = input;
|
|
207
|
+
/** Why `markdown` may not be written; a check that throws holds (fails closed) rather than sending unchecked. */
|
|
208
|
+
const problemWith = (markdown) => {
|
|
209
|
+
try {
|
|
210
|
+
return check?.(markdown) ?? null;
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return 'the check failed';
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
/** Whether the check returned a reason for `markdown`; a throw is no refusal, so it never lets an edit through. */
|
|
217
|
+
const refused = (markdown) => {
|
|
218
|
+
try {
|
|
219
|
+
return (check?.(markdown) ?? null) !== null;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const notice$ = Cell(null);
|
|
226
|
+
// The notice of an edit held unsent because it fails `check`.
|
|
227
|
+
const unsent$ = Cell(null);
|
|
228
|
+
// A body the editor cannot import: the Source view is open, editable, to fix it in.
|
|
229
|
+
const fix$ = Cell(null);
|
|
230
|
+
// Keys typed for a body that went before they could be typed into it, now at the end of the page: said, to copy.
|
|
231
|
+
const unplaced$ = Cell(null);
|
|
232
|
+
// Source text a teammate's change made stale before it was written: never written, held here to copy until let go.
|
|
233
|
+
const stale$ = Cell(null);
|
|
234
|
+
// What the host reads to show, in the same render that builds this plugin; the editor starts later.
|
|
235
|
+
const opened = text.toJSON();
|
|
236
|
+
function LiveNotice() {
|
|
237
|
+
const notice = useCellValue(notice$);
|
|
238
|
+
const unsent = useCellValue(unsent$);
|
|
239
|
+
const fix = useCellValue(fix$);
|
|
240
|
+
const unplaced = useCellValue(unplaced$);
|
|
241
|
+
const setUnplaced = usePublisher(unplaced$);
|
|
242
|
+
const stale = useCellValue(stale$);
|
|
243
|
+
const setStale = usePublisher(stale$);
|
|
244
|
+
// A hold that comes after another notice locked the editor leaves `notice$` as it is, so it is watched on its own.
|
|
245
|
+
const heldNotice = useSyncExternalStore(held?.subscribe ?? noSubscribe, held?.notice ?? notHeld);
|
|
246
|
+
const shown = notice ?? unsent;
|
|
247
|
+
return (_jsxs(_Fragment, { children: [shown !== null && (_jsxs("div", { role: "alert", className: "flex items-center gap-3 px-4 py-2 bg-yellow-11 text-yellow-02 text-sm", children: [_jsx("span", { children: shown }), held && notice !== null && heldNotice !== null && (_jsx("button", { type: "button", className: "px-3 py-1 border border-line rounded", onClick: () => void navigator.clipboard.writeText(held.content()), children: "Copy changes" }))] })), unsent === null && fix !== null && (_jsx("div", { role: "alert", className: "flex items-center gap-3 px-4 py-2 bg-yellow-11 text-yellow-02 text-sm", children: _jsx("span", { children: fix }) })), unsent === null && stale !== null && (_jsxs("div", { role: "alert", className: "flex items-center gap-3 px-4 py-2 bg-yellow-11 text-yellow-02 text-sm", children: [_jsx("span", { children: STALE_FIX }), _jsx("button", { type: "button", className: "px-3 py-1 border border-line rounded", onClick: () => void navigator.clipboard.writeText(stale).then(() => setStale(null)), children: "Copy text" }), _jsx("button", { type: "button", className: "px-3 py-1 border border-line rounded", onClick: () => setStale(null), children: "Dismiss" })] })), unplaced !== null && (_jsxs("div", { role: "alert", className: "flex items-center gap-3 px-4 py-2 bg-yellow-11 text-yellow-02 text-sm", children: [_jsxs("span", { children: ["The component you were typing in went, so this text was added at the end of the page: ", unplaced] }), _jsx("button", { type: "button", className: "px-3 py-1 border border-line rounded", onClick: () => void navigator.clipboard.writeText(unplaced).then(() => setUnplaced(null)), children: "Copy text" }), _jsx("button", { type: "button", className: "px-3 py-1 border border-line rounded", onClick: () => setUnplaced(null), children: "Dismiss" })] }))] }));
|
|
248
|
+
}
|
|
249
|
+
return realmPlugin({
|
|
250
|
+
init(realm) {
|
|
251
|
+
// Typed text nothing has written yet, each with what writes it: a body's or cell's before its handler is there.
|
|
252
|
+
const unwritten = new Map();
|
|
253
|
+
// Bodies and cells whose DOM is live but whose passive effects, where mdxeditor registers the handler that writes
|
|
254
|
+
// them, have not run yet, each with a render of its own. A dispatch before then finds no handler, or bubbles up to
|
|
255
|
+
// an outer body's, which writes only its own text.
|
|
256
|
+
const mounting = new Map();
|
|
257
|
+
/**
|
|
258
|
+
* A component body or table cell writes to the page on every change, as a code block does, so none of its text
|
|
259
|
+
* waits for the user to leave it: teammates see it as it is typed, and no way out of the page can drop it.
|
|
260
|
+
*/
|
|
261
|
+
function useWriteThrough(write) {
|
|
262
|
+
const [nested] = useLexicalComposerContext();
|
|
263
|
+
const [, rerender] = useReducer((renders) => renders + 1, 0);
|
|
264
|
+
// A layout effect can run again without its passive one (a Suspense boundary showing the body again).
|
|
265
|
+
const effectsRan = useRef(false);
|
|
266
|
+
// Live with the editor's DOM, so a key typed before its passive effects run is still seen.
|
|
267
|
+
useLayoutEffect(() => {
|
|
268
|
+
if (!effectsRan.current)
|
|
269
|
+
mounting.set(nested, rerender);
|
|
270
|
+
return nested.registerUpdateListener(({ dirtyElements, dirtyLeaves }) => {
|
|
271
|
+
if (dirtyElements.size === 0 && dirtyLeaves.size === 0)
|
|
272
|
+
return;
|
|
273
|
+
if (mounting.has(nested))
|
|
274
|
+
unwritten.set(nested, () => write(nested));
|
|
275
|
+
else
|
|
276
|
+
write(nested);
|
|
277
|
+
});
|
|
278
|
+
}, [nested, write]);
|
|
279
|
+
useEffect(() => {
|
|
280
|
+
effectsRan.current = true;
|
|
281
|
+
// mdxeditor's handler registers later in this same passive flush: its editor's effects run after this child's.
|
|
282
|
+
mounting.delete(nested);
|
|
283
|
+
queueMicrotask(() => {
|
|
284
|
+
const pending = unwritten.get(nested);
|
|
285
|
+
unwritten.delete(nested);
|
|
286
|
+
pending?.();
|
|
287
|
+
});
|
|
288
|
+
}, [nested]);
|
|
289
|
+
}
|
|
290
|
+
function WriteThroughBody() {
|
|
291
|
+
useWriteThrough(writeBody);
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function WriteThroughCell() {
|
|
295
|
+
useWriteThrough(writeCell);
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
/** Writes what the user typed but nothing has written yet: side-panel and inline field drafts, table cells, bodies. */
|
|
299
|
+
const writeInput = () => {
|
|
300
|
+
commitDrafts();
|
|
301
|
+
for (const [nested, write] of unwritten) {
|
|
302
|
+
// flushSync makes React first run the passive effects it still owes, mdxeditor's write handler among them.
|
|
303
|
+
const rerender = mounting.get(nested);
|
|
304
|
+
if (rerender)
|
|
305
|
+
flushSync(rerender);
|
|
306
|
+
write();
|
|
307
|
+
}
|
|
308
|
+
unwritten.clear();
|
|
309
|
+
};
|
|
310
|
+
const lock = (notice) => {
|
|
311
|
+
realm.pubIn({ [notice$]: notice, [readOnly$]: true });
|
|
312
|
+
};
|
|
313
|
+
// mdxeditor never calls a root editor subscription's teardown, so the binding lives in an effect of the editor's: a
|
|
314
|
+
// layout effect, so its teardown runs while the editor's blocks and fields are still there to write.
|
|
315
|
+
function LiveBinding() {
|
|
316
|
+
const editor = useCellValue(rootEditor$);
|
|
317
|
+
useLayoutEffect(() => (editor ? bind(editor) : undefined), [editor]);
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
realm.pub(addTopAreaChild$, LiveNotice);
|
|
321
|
+
realm.pub(addComposerChild$, LiveBinding);
|
|
322
|
+
realm.pub(addNestedEditorChild$, WriteThroughBody);
|
|
323
|
+
realm.pub(addTableCellEditorChild$, WriteThroughCell);
|
|
324
|
+
function bind(editor) {
|
|
325
|
+
let shadow = realm.getValue(markdown$);
|
|
326
|
+
const replica = createEditorReplica(text);
|
|
327
|
+
const releaseLive = markLiveEditing();
|
|
328
|
+
let frame = 0;
|
|
329
|
+
let restoring = 0;
|
|
330
|
+
// Keys typed while a rebuilt body is on its way back: focus is on the page then, where a key does nothing.
|
|
331
|
+
const heldKeys = [];
|
|
332
|
+
heldKeyLists.add(heldKeys);
|
|
333
|
+
// The rebuilt body waited for: its block's key, moved along by later rebuilds, the caret to put back in it, and
|
|
334
|
+
// the frames left to wait while no key waits for it.
|
|
335
|
+
let pending = null;
|
|
336
|
+
let selected = null;
|
|
337
|
+
// A teammate change that would rebuild the block a toolbar or dialog acts on waits for that action to end.
|
|
338
|
+
let waitingForUi = false;
|
|
339
|
+
// A toolbar button held down: its action applies on release, often with focus still in the body it acts on.
|
|
340
|
+
let pressedUi = false;
|
|
341
|
+
const show = (afterUi = false) => {
|
|
342
|
+
if (frame === 0)
|
|
343
|
+
frame = requestAnimationFrame(() => showRemote(afterUi));
|
|
344
|
+
};
|
|
345
|
+
// The text of an edit held unsent (see `check`), which the editor shows in place of `shadow`.
|
|
346
|
+
let heldText = null;
|
|
347
|
+
// A remote change that came while an edit was held: shown once the hold ends.
|
|
348
|
+
let remotePending = false;
|
|
349
|
+
// Counts the edits taken, so a caller can tell its editor update produced one.
|
|
350
|
+
let takes = 0;
|
|
351
|
+
const setUnsent = (notice, markdown = null) => {
|
|
352
|
+
heldText = markdown;
|
|
353
|
+
if (notice === null && realm.getValue(unsent$) === null)
|
|
354
|
+
return;
|
|
355
|
+
if (realm.getValue(unsent$) !== notice)
|
|
356
|
+
realm.pub(unsent$, notice);
|
|
357
|
+
input.onHeld?.(notice, markdown);
|
|
358
|
+
};
|
|
359
|
+
const releaseHold = () => {
|
|
360
|
+
setUnsent(null);
|
|
361
|
+
if (!remotePending)
|
|
362
|
+
return;
|
|
363
|
+
remotePending = false;
|
|
364
|
+
cancelAnimationFrame(frame);
|
|
365
|
+
frame = 0;
|
|
366
|
+
show();
|
|
367
|
+
};
|
|
368
|
+
/** Sends a local edit, or holds it while it makes a passing body fail. */
|
|
369
|
+
const takeEdit = (next) => {
|
|
370
|
+
takes++;
|
|
371
|
+
const problem = check ? problemWith(next) : null;
|
|
372
|
+
// Held while it fails, unless the check refused the text last sent too.
|
|
373
|
+
if (problem !== null && (realm.getValue(unsent$) !== null || !refused(shadow))) {
|
|
374
|
+
setUnsent(`Not saved: ${problem}`, next);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (next !== shadow) {
|
|
378
|
+
writeEditorEdit(replica, text, shadow, next, LOCAL_ORIGIN);
|
|
379
|
+
shadow = next;
|
|
380
|
+
}
|
|
381
|
+
releaseHold();
|
|
382
|
+
};
|
|
383
|
+
// `muteChange$` set means the change is the editor showing a remote text, not the user typing.
|
|
384
|
+
const stopMarkdown = realm.sub(markdown$, (next) => {
|
|
385
|
+
if (realm.getValue(muteChange$) || realm.getValue(notice$) !== null)
|
|
386
|
+
return;
|
|
387
|
+
if (realm.getValue(initialMarkdownNormalize$)) {
|
|
388
|
+
shadow = next;
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (next === shadow && heldText === null)
|
|
392
|
+
return;
|
|
393
|
+
takeEdit(next);
|
|
394
|
+
});
|
|
395
|
+
// Source text not written yet: it is read as MDX once typing pauses, and written if a teammate's editor could
|
|
396
|
+
// show it; text that does not parse yet (a tag still being typed) waits for the switch back or the user leaving.
|
|
397
|
+
let source = null;
|
|
398
|
+
let sourceTimer = 0;
|
|
399
|
+
// Fixing in the Source view, a teammate changed the page while this user's fix waited: that fix was typed
|
|
400
|
+
// against a page that is gone, so it is never written; it is held in `stale$` to copy, and the switch back
|
|
401
|
+
// shows the teammate's.
|
|
402
|
+
let staleFix = false;
|
|
403
|
+
const holdsFix = () => realm.getValue(stale$) !== null;
|
|
404
|
+
heldFixes.add(holdsFix);
|
|
405
|
+
const stopStale = realm.sub(stale$, notifyEditorDirtyChanged);
|
|
406
|
+
const writeSource = (next) => {
|
|
407
|
+
clearTimeout(sourceTimer);
|
|
408
|
+
// Held, nothing writes; the text stays for a later write.
|
|
409
|
+
if (realm.getValue(notice$) !== null || staleFix)
|
|
410
|
+
return;
|
|
411
|
+
source = null;
|
|
412
|
+
// With a check, Source text passes it as any edit does: refused, it is held unsent with its reason shown.
|
|
413
|
+
if (check) {
|
|
414
|
+
takeEdit(next);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (next === shadow)
|
|
418
|
+
return;
|
|
419
|
+
writeEditorEdit(replica, text, shadow, next, LOCAL_ORIGIN);
|
|
420
|
+
shadow = next;
|
|
421
|
+
};
|
|
422
|
+
const flushSource = () => {
|
|
423
|
+
if (source !== null)
|
|
424
|
+
writeSource(source);
|
|
425
|
+
};
|
|
426
|
+
// The Source and Diff views type into CodeMirror, whose text mdxeditor gives the editor only on the switch back to
|
|
427
|
+
// rich text: it is written as it is typed instead.
|
|
428
|
+
const stopSource = realm.sub(markdownSourceEditorValue$, (next) => {
|
|
429
|
+
if (realm.getValue(viewMode$) === 'rich-text' || realm.getValue(notice$) !== null)
|
|
430
|
+
return;
|
|
431
|
+
source = next;
|
|
432
|
+
if (staleFix)
|
|
433
|
+
realm.pub(stale$, next);
|
|
434
|
+
clearTimeout(sourceTimer);
|
|
435
|
+
sourceTimer = window.setTimeout(() => {
|
|
436
|
+
if (parseMdx(next))
|
|
437
|
+
writeSource(next);
|
|
438
|
+
}, SOURCE_WRITE_DELAY_MS);
|
|
439
|
+
});
|
|
440
|
+
// A teammate's change made meanwhile shows on the switch back (see `showRemote`).
|
|
441
|
+
const stopViewMode = realm.sub(viewMode$, (mode) => {
|
|
442
|
+
if (mode !== 'rich-text')
|
|
443
|
+
return;
|
|
444
|
+
if (staleFix) {
|
|
445
|
+
staleFix = false;
|
|
446
|
+
source = null;
|
|
447
|
+
}
|
|
448
|
+
flushSource();
|
|
449
|
+
show();
|
|
450
|
+
});
|
|
451
|
+
/** A body the editor cannot import opens the Source view, editable, to fix it in; nothing ever locks on it. */
|
|
452
|
+
const settleImport = (body) => {
|
|
453
|
+
const error = realm.getValue(markdownProcessingError$);
|
|
454
|
+
if (!error) {
|
|
455
|
+
realm.pub(fix$, null);
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
realm.pubIn({ [fix$]: fixNotice(body, error.error), [viewMode$]: 'source' });
|
|
459
|
+
return true;
|
|
460
|
+
};
|
|
461
|
+
/** The top-level block holding focus, or for a toolbar or dialog the block its action targets (`ui`). */
|
|
462
|
+
function busyBlock(root) {
|
|
463
|
+
const focused = document.activeElement;
|
|
464
|
+
if (!(focused instanceof HTMLElement))
|
|
465
|
+
return null;
|
|
466
|
+
const ui = pressedUi || (!root.contains(focused) && isPartOftheEditorUI(focused, root));
|
|
467
|
+
const at = root.contains(focused) ? focused : ui ? realm.getValue(activeEditor$)?.getRootElement() : null;
|
|
468
|
+
if (!at || at === root)
|
|
469
|
+
return null;
|
|
470
|
+
const key = editor.read(() => $getNearestNodeFromDOMNode(at)?.getTopLevelElement()?.getKey() ?? null);
|
|
471
|
+
return key === null ? null : { key, ui };
|
|
472
|
+
}
|
|
473
|
+
/** Empties `heldKeys`, returning what they were; a leave asks only while some are held. */
|
|
474
|
+
function takeHeld() {
|
|
475
|
+
const keys = heldKeys.splice(0);
|
|
476
|
+
if (keys.length > 0)
|
|
477
|
+
notifyEditorDirtyChanged();
|
|
478
|
+
return keys;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Writes keys held for a body that cannot take them at its caret at the end of its block's body, or, with the
|
|
482
|
+
* block gone, at the end of the page with a notice saying so. Backspaces past what they typed are dropped: their
|
|
483
|
+
* targets are text already in the doc, never a typed key.
|
|
484
|
+
*/
|
|
485
|
+
function placeHeld() {
|
|
486
|
+
const key = pending?.key;
|
|
487
|
+
pending = null;
|
|
488
|
+
const { typed } = typedText(takeHeld());
|
|
489
|
+
if (typed === '')
|
|
490
|
+
return;
|
|
491
|
+
const before = takes;
|
|
492
|
+
let inBody = false;
|
|
493
|
+
// The markdown this exports is written to the doc by `stopMarkdown`, as the user's typing is.
|
|
494
|
+
editor.update(() => {
|
|
495
|
+
const node = key === undefined ? null : $getNodeByKey(key);
|
|
496
|
+
if (!isComponentNode(node)) {
|
|
497
|
+
$getRoot().append($createParagraphNode().append($createTextNode(typed)));
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
inBody = true;
|
|
501
|
+
const mdast = node.getMdastNode();
|
|
502
|
+
node.setMdastNode(mdast.type === 'mdxJsxFlowElement'
|
|
503
|
+
? {
|
|
504
|
+
...mdast,
|
|
505
|
+
children: [...mdast.children, { type: 'paragraph', children: [{ type: 'text', value: typed }] }],
|
|
506
|
+
}
|
|
507
|
+
: { ...mdast, children: [...mdast.children, { type: 'text', value: typed }] });
|
|
508
|
+
}, { discrete: true });
|
|
509
|
+
if (takes === before) {
|
|
510
|
+
// Nothing took the export (the editor locked or not exporting): the text goes at the end of the page.
|
|
511
|
+
inBody = false;
|
|
512
|
+
takeEdit(`${(heldText ?? shadow).trimEnd()}\n\n${typed}\n`);
|
|
513
|
+
}
|
|
514
|
+
if (!inBody)
|
|
515
|
+
realm.pub(unplaced$, typed);
|
|
516
|
+
}
|
|
517
|
+
/** The editor is closing with keys held for a body not back yet: they go into the text where its caret was. */
|
|
518
|
+
function writeHeldToText() {
|
|
519
|
+
if (!pending || heldKeys.length === 0)
|
|
520
|
+
return placeHeld();
|
|
521
|
+
const { caret, text: was } = pending.at;
|
|
522
|
+
// What the editor shows: a held edit's text, else the text last sent.
|
|
523
|
+
const shown = heldText ?? shadow;
|
|
524
|
+
const head = was.slice(0, caret.offset);
|
|
525
|
+
const headAt = once(shown, head);
|
|
526
|
+
const at = headAt === null ? once(shown, was.slice(caret.offset)) : headAt + head.length;
|
|
527
|
+
const { typed, erased } = typedText(heldKeys);
|
|
528
|
+
// Backspaces past the typed keys erase only characters known to be the caret's own text before it.
|
|
529
|
+
if (at === null || erased > head.length || shown.slice(at - erased, at) !== head.slice(head.length - erased))
|
|
530
|
+
return placeHeld();
|
|
531
|
+
takeEdit(shown.slice(0, at - erased) + typed + shown.slice(at));
|
|
532
|
+
pending = null;
|
|
533
|
+
takeHeld();
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Puts the caret back in the `pending` body once it is mounted again (its preview can take a while), types there
|
|
537
|
+
* the keys held meanwhile, and focuses it unless the user went somewhere else.
|
|
538
|
+
*/
|
|
539
|
+
function restoreBody() {
|
|
540
|
+
restoring = requestAnimationFrame(() => {
|
|
541
|
+
restoring = 0;
|
|
542
|
+
if (!pending)
|
|
543
|
+
return;
|
|
544
|
+
const { key, at } = pending;
|
|
545
|
+
const focusMoved = document.activeElement !== null && document.activeElement !== document.body;
|
|
546
|
+
if (focusMoved && heldKeys.length === 0) {
|
|
547
|
+
pending = null;
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (!editor.read(() => $getNodeByKey(key))) {
|
|
551
|
+
placeHeld();
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const el = editor.getElementByKey(key)?.querySelectorAll('[data-lexical-editor="true"]')[at.ordinal];
|
|
555
|
+
const body = el ? getNearestEditorFromDOMNode(el) : null;
|
|
556
|
+
if (!body || body === editor) {
|
|
557
|
+
// Held keys wait as long as their block is there: a slow or failing preview still mounts the body.
|
|
558
|
+
if (heldKeys.length > 0 || pending.frames-- > 0)
|
|
559
|
+
restoreBody();
|
|
560
|
+
else
|
|
561
|
+
pending = null;
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
pending = null;
|
|
565
|
+
const keys = takeHeld();
|
|
566
|
+
body.update(() => {
|
|
567
|
+
const now = $blockTexts()[at.caret.block] ?? '';
|
|
568
|
+
$restoreCaret({ block: at.caret.block, offset: shiftedOffset(at.text, now, at.caret.offset) });
|
|
569
|
+
const selection = $getSelection();
|
|
570
|
+
if (!$isRangeSelection(selection))
|
|
571
|
+
return;
|
|
572
|
+
for (const typed of keys) {
|
|
573
|
+
if (typed === 'Enter')
|
|
574
|
+
selection.insertParagraph();
|
|
575
|
+
else if (typed === 'Backspace')
|
|
576
|
+
selection.deleteCharacter(true);
|
|
577
|
+
else
|
|
578
|
+
selection.insertText(typed);
|
|
579
|
+
}
|
|
580
|
+
// A body with a caret puts the page's selection in it, which would take focus from where the user went.
|
|
581
|
+
if (focusMoved)
|
|
582
|
+
$setSelection(null);
|
|
583
|
+
}, { discrete: true });
|
|
584
|
+
if (!focusMoved)
|
|
585
|
+
body.focus();
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
const holdKey = (event) => {
|
|
589
|
+
if (restoring === 0 || document.activeElement !== document.body)
|
|
590
|
+
return;
|
|
591
|
+
if (event.isComposing || event.ctrlKey || event.metaKey || event.altKey)
|
|
592
|
+
return;
|
|
593
|
+
if (event.key.length !== 1 && event.key !== 'Enter' && event.key !== 'Backspace')
|
|
594
|
+
return;
|
|
595
|
+
event.preventDefault();
|
|
596
|
+
if (heldKeys.push(event.key) === 1)
|
|
597
|
+
notifyEditorDirtyChanged();
|
|
598
|
+
};
|
|
599
|
+
document.addEventListener('keydown', holdKey, true);
|
|
600
|
+
function showRemote(afterUi) {
|
|
601
|
+
frame = 0;
|
|
602
|
+
if (realm.getValue(notice$) !== null)
|
|
603
|
+
return;
|
|
604
|
+
if (realm.getValue(unsent$) !== null) {
|
|
605
|
+
remotePending = true;
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
// In the Source or Diff view, showing it would rebuild the view under the caret; it shows on the switch back.
|
|
609
|
+
if (realm.getValue(viewMode$) !== 'rich-text') {
|
|
610
|
+
// Fixing a text the editor cannot read, a teammate's text shows here while nothing of this user's waits;
|
|
611
|
+
// with a fix waiting, merging it into a page it was not typed against would garble both: it is said instead.
|
|
612
|
+
if (realm.getValue(fix$) === null || staleFix)
|
|
613
|
+
return;
|
|
614
|
+
if (source === null)
|
|
615
|
+
apply(afterUi, false);
|
|
616
|
+
else {
|
|
617
|
+
staleFix = true;
|
|
618
|
+
// The page this fix was typed against is gone: its "needs fixing" notice says no more than this one.
|
|
619
|
+
realm.pubIn({ [fix$]: null, [stale$]: source });
|
|
620
|
+
}
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
// A side-panel field writes its draft first: that changes nothing it shows, and its block may be rebuilt.
|
|
624
|
+
if (!editor.getRootElement()?.contains(document.activeElement))
|
|
625
|
+
commitDrafts();
|
|
626
|
+
apply(afterUi, false);
|
|
627
|
+
}
|
|
628
|
+
/** Shows the shared text. `written`: input in the block holding focus is written, so that block may be rebuilt. */
|
|
629
|
+
function apply(afterUi, written) {
|
|
630
|
+
const root = editor.getRootElement();
|
|
631
|
+
if (!root)
|
|
632
|
+
return;
|
|
633
|
+
const inBlock = root.contains(document.activeElement) && document.activeElement !== root;
|
|
634
|
+
const busy = busyBlock(root);
|
|
635
|
+
// The caret is anchored in the replica's text, which is what the editor shows, before the remote change lands.
|
|
636
|
+
const caret = inBlock
|
|
637
|
+
? null
|
|
638
|
+
: editor.getEditorState().read(() => {
|
|
639
|
+
const read = $readCaret();
|
|
640
|
+
return read && { read, anchor: anchorCaret(replica.text, read, $blockTexts()) };
|
|
641
|
+
});
|
|
642
|
+
const body = splitEsm(text.toJSON()).body;
|
|
643
|
+
// setMarkdown$ drops a text equal to the editor's after trimming, and no onChange follows.
|
|
644
|
+
if (body.trim() === shadow.trim()) {
|
|
645
|
+
syncEditorReplica(replica, text);
|
|
646
|
+
settleImport(body);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const blocks = editor.getEditorState().read(() => $getRoot()
|
|
650
|
+
.getChildren()
|
|
651
|
+
.map((node) => ({ key: node.getKey(), signature: $signature(node) })));
|
|
652
|
+
const focusedBody = busy && !busy.ui ? getNearestEditorFromDOMNode(document.activeElement) : null;
|
|
653
|
+
const bodyCaret = focusedBody && focusedBody !== editor
|
|
654
|
+
? focusedBody.read(() => {
|
|
655
|
+
const read = $readCaret();
|
|
656
|
+
const ordinal = [
|
|
657
|
+
...(editor.getElementByKey(busy?.key ?? '')?.querySelectorAll('[data-lexical-editor="true"]') ??
|
|
658
|
+
[]),
|
|
659
|
+
].indexOf(focusedBody.getRootElement() ?? root);
|
|
660
|
+
return read && ordinal >= 0 ? { ordinal, caret: read, text: $blockTexts()[read.block] ?? '' } : null;
|
|
661
|
+
})
|
|
662
|
+
: null;
|
|
663
|
+
const inFocus = realm.getValue(inFocus$);
|
|
664
|
+
// setMarkdown focuses the root while the editor has focus, which would pull focus out of the block.
|
|
665
|
+
if (inBlock)
|
|
666
|
+
realm.pub(inFocus$, false);
|
|
667
|
+
const rebuilt = new Map();
|
|
668
|
+
// SAFETY: widened on purpose; TS cannot see the assignment inside the `editor.update` closure.
|
|
669
|
+
let outcome = 'shown';
|
|
670
|
+
// setMarkdown rebuilds every block. Run inside one update, the update queued after its own still sees the
|
|
671
|
+
// blocks it took out (Lexical drops them only once the update ends), and puts back each one the change left.
|
|
672
|
+
editor.update(() => {
|
|
673
|
+
realm.pub(setMarkdown$, body);
|
|
674
|
+
editor.update(() => {
|
|
675
|
+
if (realm.getValue(markdownProcessingError$))
|
|
676
|
+
return;
|
|
677
|
+
const fresh = $getRoot().getChildren();
|
|
678
|
+
const kept = keptBlocks(blocks.map((block) => block.signature), fresh.map($signature));
|
|
679
|
+
const old = blocks.map(({ key }) => $getNodeByKey(key));
|
|
680
|
+
for (const [i, j] of successors(blocks.length, fresh.length, kept)) {
|
|
681
|
+
const next = j === null ? undefined : fresh[j];
|
|
682
|
+
rebuilt.set(blocks[i]?.key ?? '', next && next.getType() === old[i]?.getType() ? next.getKey() : null);
|
|
683
|
+
}
|
|
684
|
+
if (busy && rebuilt.has(busy.key) && (busy.ui ? !afterUi : !written)) {
|
|
685
|
+
// Rebuilding would drop the block's unwritten input or the target of a toolbar click: put all back.
|
|
686
|
+
outcome = busy.ui ? 'wait' : 'write';
|
|
687
|
+
$getRoot()
|
|
688
|
+
.clear()
|
|
689
|
+
.append(...old.filter((node) => node !== null));
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
for (const [j, i] of kept) {
|
|
693
|
+
const keep = old[i];
|
|
694
|
+
if (keep)
|
|
695
|
+
fresh[j]?.replace(keep);
|
|
696
|
+
}
|
|
697
|
+
// A selection in a rebuilt block points at removed nodes, which Lexical's production build rejects.
|
|
698
|
+
const selection = $getSelection();
|
|
699
|
+
if ($isRangeSelection(selection) &&
|
|
700
|
+
![selection.anchor.key, selection.focus.key].every((key) => $getNodeByKey(key)?.isAttached()))
|
|
701
|
+
$setSelection(null);
|
|
702
|
+
});
|
|
703
|
+
}, { discrete: true });
|
|
704
|
+
if (inBlock)
|
|
705
|
+
realm.pub(inFocus$, inFocus);
|
|
706
|
+
if (outcome === 'write') {
|
|
707
|
+
writeInput();
|
|
708
|
+
apply(afterUi, true);
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
if (outcome === 'wait') {
|
|
712
|
+
waitingForUi = true;
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
// The replica follows what the editor shows; one that went ahead of a put-back editor would misplace its writes.
|
|
716
|
+
syncEditorReplica(replica, text);
|
|
717
|
+
if (settleImport(body)) {
|
|
718
|
+
shadow = body;
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
const before = shadow;
|
|
722
|
+
shadow = realm.getValue(markdown$);
|
|
723
|
+
if (pending && rebuilt.has(pending.key)) {
|
|
724
|
+
const next = rebuilt.get(pending.key);
|
|
725
|
+
if (next)
|
|
726
|
+
pending.key = next;
|
|
727
|
+
else
|
|
728
|
+
placeHeld();
|
|
729
|
+
}
|
|
730
|
+
const selection = getSelectedBlock();
|
|
731
|
+
const [selectedTop = '', ...path] = selection?.key.split(':') ?? [];
|
|
732
|
+
if (selection && rebuilt.has(selectedTop)) {
|
|
733
|
+
// The rebuilt block republishes the panel's fields once it mounts under this key.
|
|
734
|
+
const next = rebuilt.get(selectedTop);
|
|
735
|
+
setSelectedBlock(next ? { ...selection, key: [next, ...path].join(':') } : null);
|
|
736
|
+
}
|
|
737
|
+
const busyNext = busy && rebuilt.get(busy.key);
|
|
738
|
+
if (busyNext && bodyCaret) {
|
|
739
|
+
// Taking out the focused body drops the page's caret into the root, which Lexical takes as the root's
|
|
740
|
+
// selection; the root's next update (a body writing to it) then focuses the root at that point, before the
|
|
741
|
+
// body is back, and the keys typed after go there. With no caret in the root, focus waits for the body.
|
|
742
|
+
window.getSelection()?.removeAllRanges();
|
|
743
|
+
editor.update(() => $setSelection(null), { discrete: true });
|
|
744
|
+
cancelAnimationFrame(restoring);
|
|
745
|
+
pending = { key: busyNext, at: bodyCaret, frames: 120 };
|
|
746
|
+
restoreBody();
|
|
747
|
+
}
|
|
748
|
+
if (!caret)
|
|
749
|
+
return;
|
|
750
|
+
editor.update(() => {
|
|
751
|
+
const anchored = caret.anchor && caretAtAnchor(replica.text, caret.anchor, $blockTexts());
|
|
752
|
+
$restoreCaret(anchored ?? caretAfterRemoteEdit(before, shadow, caret.read));
|
|
753
|
+
}, { discrete: true });
|
|
754
|
+
}
|
|
755
|
+
// A toolbar or dialog action ends with a click, or focus moving on; a change that waited for it shows then.
|
|
756
|
+
const uiDone = (event) => {
|
|
757
|
+
if (!waitingForUi)
|
|
758
|
+
return;
|
|
759
|
+
waitingForUi = false;
|
|
760
|
+
cancelAnimationFrame(frame);
|
|
761
|
+
frame = 0;
|
|
762
|
+
show(event.type === 'click');
|
|
763
|
+
};
|
|
764
|
+
document.addEventListener('click', uiDone);
|
|
765
|
+
document.addEventListener('focusin', uiDone);
|
|
766
|
+
// Focus moved to a form field outside the editor and its toolbars and dialogs (the side panel's): the editor's
|
|
767
|
+
// selection goes, so no later update of the editor (a teammate's change, a body or a draft writing) puts the
|
|
768
|
+
// page's selection, and with it focus, back in the editor while the user types in that field.
|
|
769
|
+
const leaveSelection = (event) => {
|
|
770
|
+
const root = editor.getRootElement();
|
|
771
|
+
const target = event.target;
|
|
772
|
+
if (!root || !(target instanceof HTMLElement) || !target.matches('input, textarea, select'))
|
|
773
|
+
return;
|
|
774
|
+
if (root.contains(target) || isPartOftheEditorUI(target, root))
|
|
775
|
+
return;
|
|
776
|
+
editor.update(() => $setSelection(null), { discrete: true, tag: SKIP_DOM_SELECTION_TAG });
|
|
777
|
+
};
|
|
778
|
+
document.addEventListener('focusin', leaveSelection);
|
|
779
|
+
const press = (event) => {
|
|
780
|
+
const root = editor.getRootElement();
|
|
781
|
+
pressedUi =
|
|
782
|
+
root !== null &&
|
|
783
|
+
event.target instanceof HTMLElement &&
|
|
784
|
+
!root.contains(event.target) &&
|
|
785
|
+
isPartOftheEditorUI(event.target, root);
|
|
786
|
+
};
|
|
787
|
+
const release = () => {
|
|
788
|
+
pressedUi = false;
|
|
789
|
+
};
|
|
790
|
+
document.addEventListener('pointerdown', press);
|
|
791
|
+
document.addEventListener('pointerup', release);
|
|
792
|
+
// Closing the tab or leaving the page without leaving the field: its text is written while it still can be. It
|
|
793
|
+
// reaches the parent after the parent's own pagehide, which then sends it unbatched.
|
|
794
|
+
const leave = () => {
|
|
795
|
+
writeInput();
|
|
796
|
+
flushSource();
|
|
797
|
+
};
|
|
798
|
+
const hidden = () => {
|
|
799
|
+
if (document.visibilityState === 'hidden')
|
|
800
|
+
leave();
|
|
801
|
+
};
|
|
802
|
+
window.addEventListener('pagehide', leave);
|
|
803
|
+
document.addEventListener('visibilitychange', hidden);
|
|
804
|
+
// Held from the open, the editor is read-only before the Source view a text it cannot read opens mounts.
|
|
805
|
+
const lockIfHeld = () => {
|
|
806
|
+
const notice = held?.notice();
|
|
807
|
+
if (notice != null && realm.getValue(notice$) === null)
|
|
808
|
+
lock(notice);
|
|
809
|
+
};
|
|
810
|
+
lockIfHeld();
|
|
811
|
+
settleImport(shadow);
|
|
812
|
+
const stopHeld = held?.subscribe(lockIfHeld);
|
|
813
|
+
const observer = (_event, transaction) => {
|
|
814
|
+
if (transaction.origin !== LOCAL_ORIGIN)
|
|
815
|
+
show();
|
|
816
|
+
};
|
|
817
|
+
text.observe(observer);
|
|
818
|
+
// A change that came between the host reading the text and binding: the editor shows `opened`.
|
|
819
|
+
if (text.toJSON() !== opened)
|
|
820
|
+
show();
|
|
821
|
+
const undo = createLocalUndo(input.undoScope);
|
|
822
|
+
// Read-only writes nothing, undo included; the editor's own history never runs either way.
|
|
823
|
+
const unlessLocked = (step) => () => {
|
|
824
|
+
if (realm.getValue(notice$) === null && realm.getValue(fix$) === null && !staleFix)
|
|
825
|
+
step();
|
|
826
|
+
return true;
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Undo and redo write the shared text directly, so with a check a step is first worked out on a copy: one whose
|
|
830
|
+
* body the check refuses is never written, its body held unsent instead, as a typed edit that fails it would be.
|
|
831
|
+
*/
|
|
832
|
+
const checkedStep = (stack) => {
|
|
833
|
+
const step = () => (stack === 'undoStack' ? undo.undo() : undo.redo());
|
|
834
|
+
if (!check || refused(shadow)) {
|
|
835
|
+
step();
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
let after;
|
|
839
|
+
try {
|
|
840
|
+
after = stepResult(text, undo, stack);
|
|
841
|
+
}
|
|
842
|
+
catch {
|
|
843
|
+
// No verdict on the step's text: it fails closed, unwritten, as a check that throws does.
|
|
844
|
+
setUnsent('Not saved: the check failed', heldText ?? shadow);
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
if (after === null)
|
|
848
|
+
return;
|
|
849
|
+
const body = splitEsm(after).body;
|
|
850
|
+
if (problemWith(body) === null) {
|
|
851
|
+
step();
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
realm.pub(setMarkdown$, body);
|
|
855
|
+
editor.update(() => { }, { discrete: true });
|
|
856
|
+
takeEdit(body);
|
|
857
|
+
};
|
|
858
|
+
// Undo of a held edit shows the text last sent again; there is nothing to redo.
|
|
859
|
+
const undoHeld = () => {
|
|
860
|
+
realm.pub(setMarkdown$, shadow);
|
|
861
|
+
editor.update(() => { }, { discrete: true });
|
|
862
|
+
shadow = realm.getValue(markdown$);
|
|
863
|
+
releaseHold();
|
|
864
|
+
};
|
|
865
|
+
const stopUndo = editor.registerCommand(UNDO_COMMAND, unlessLocked(() => (realm.getValue(unsent$) === null ? checkedStep('undoStack') : undoHeld())), COMMAND_PRIORITY_CRITICAL);
|
|
866
|
+
const stopRedo = editor.registerCommand(REDO_COMMAND, unlessLocked(() => realm.getValue(unsent$) === null && checkedStep('redoStack')), COMMAND_PRIORITY_CRITICAL);
|
|
867
|
+
const stopSelection = editor.registerUpdateListener(({ editorState }) => {
|
|
868
|
+
const block = editorState.read($selectedBlock);
|
|
869
|
+
if (block === selected)
|
|
870
|
+
return;
|
|
871
|
+
selected = block;
|
|
872
|
+
input.onSelectionBlock(block);
|
|
873
|
+
});
|
|
874
|
+
const stopRoot = editor.registerRootListener((root) => input.onRootElement?.(root));
|
|
875
|
+
return () => {
|
|
876
|
+
// The editor is closing: what the user typed but nothing wrote yet is written while the binding still listens.
|
|
877
|
+
writeInput();
|
|
878
|
+
flushSource();
|
|
879
|
+
cancelAnimationFrame(restoring);
|
|
880
|
+
// Before `stopMarkdown`, which writes held keys placed through the editor.
|
|
881
|
+
writeHeldToText();
|
|
882
|
+
heldKeyLists.delete(heldKeys);
|
|
883
|
+
text.unobserve(observer);
|
|
884
|
+
stopMarkdown();
|
|
885
|
+
stopSource();
|
|
886
|
+
stopViewMode();
|
|
887
|
+
stopStale();
|
|
888
|
+
heldFixes.delete(holdsFix);
|
|
889
|
+
cancelAnimationFrame(frame);
|
|
890
|
+
frame = 0;
|
|
891
|
+
document.removeEventListener('click', uiDone);
|
|
892
|
+
document.removeEventListener('focusin', uiDone);
|
|
893
|
+
document.removeEventListener('focusin', leaveSelection);
|
|
894
|
+
document.removeEventListener('keydown', holdKey, true);
|
|
895
|
+
document.removeEventListener('pointerdown', press);
|
|
896
|
+
document.removeEventListener('pointerup', release);
|
|
897
|
+
window.removeEventListener('pagehide', leave);
|
|
898
|
+
document.removeEventListener('visibilitychange', hidden);
|
|
899
|
+
stopUndo();
|
|
900
|
+
undo.destroy();
|
|
901
|
+
stopHeld?.();
|
|
902
|
+
stopRedo();
|
|
903
|
+
stopSelection();
|
|
904
|
+
stopRoot();
|
|
905
|
+
input.onRootElement?.(null);
|
|
906
|
+
replica.doc.destroy();
|
|
907
|
+
releaseLive();
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
},
|
|
911
|
+
update(realm) {
|
|
912
|
+
// The editor's own update republishes its `readOnly` prop; a locked body stays read-only until it unlocks.
|
|
913
|
+
if (realm.getValue(notice$) !== null)
|
|
914
|
+
realm.pub(readOnly$, true);
|
|
915
|
+
},
|
|
916
|
+
})();
|
|
917
|
+
}
|
|
918
|
+
//# sourceMappingURL=markdown-live-plugin.js.map
|