@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
|
@@ -1,28 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getContentAPIClient,
|
|
3
|
+
StaleWriteError,
|
|
3
4
|
type UpdateResult,
|
|
4
5
|
useLocalizedContent,
|
|
5
6
|
useSitesConfig,
|
|
6
7
|
useUpdateLocalized,
|
|
7
8
|
} from '@conloca/content-api-client';
|
|
9
|
+
import cn from 'clsx';
|
|
8
10
|
import { AlertTriangle } from 'lucide-react';
|
|
9
|
-
import { type ElementType, useEffect, useRef, useState } from 'react';
|
|
10
|
-
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
|
11
|
+
import { type ElementType, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
12
|
+
import { parsePath, useHref, useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
|
11
13
|
import { notifyEditorDirtyChanged, registerEditorFlushHandler } from '../../editor-flush.js';
|
|
12
14
|
import { useEditorPref } from '../../hooks/useEditorPref.js';
|
|
13
15
|
import { useErrorModal } from '../../hooks/useErrorModal.js';
|
|
14
16
|
import { useTheme } from '../../hooks/useTheme.js';
|
|
15
17
|
import { useUnsavedChangesGuard } from '../../hooks/useUnsavedChangesGuard.js';
|
|
18
|
+
import { useDocChannel } from '../../live/doc-channel.js';
|
|
19
|
+
import { heldFragmentEdit, setHeldFragmentEdit, setNotAppliedFragmentEdit } from '../../live/held-fragment-edits.js';
|
|
20
|
+
import { markdownLivePlugin } from '../../live/markdown-live-plugin.js';
|
|
21
|
+
import { useLiveDoc } from '../../live/use-live.js';
|
|
22
|
+
import { setSelectedBlock } from '../../selected-block.js';
|
|
23
|
+
import { useSiteRender } from '../../site-render.js';
|
|
24
|
+
import type { SaveState } from '../../types.js';
|
|
16
25
|
import { getUIConfig } from '../../ui-config.js';
|
|
26
|
+
import { DraftNoticeStrip } from '../conflicts/EditorNoticeStrip.js';
|
|
27
|
+
import { PageDraftMenu } from '../conflicts/PageDraftMenu.js';
|
|
28
|
+
import { PeerAvatars } from '../conflicts/PeerAvatars.js';
|
|
29
|
+
import { draftToolsPage } from '../conflicts/use-page-conflicts.js';
|
|
17
30
|
import { ConflictDialog } from '../dialogs/ConflictDialog.js';
|
|
18
31
|
import { ErrorModal } from '../dialogs/ErrorModal.js';
|
|
19
|
-
import { UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
|
|
32
|
+
import { LiveLeaveGuard, UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
|
|
20
33
|
import { CMSMDXEditor, type CMSMDXEditorProps } from './CMSMDXEditor.js';
|
|
21
34
|
import { EditorChromeToggles } from './EditorChromeToggles.js';
|
|
35
|
+
import { FRAGMENT_STATUS_ID, FragmentEditorHeaderActions, fragmentStatusText } from './FragmentEditorHeaderActions.js';
|
|
36
|
+
import { checkFragmentSave } from './fragment-save-check.js';
|
|
37
|
+
import {
|
|
38
|
+
pendingFragmentSave,
|
|
39
|
+
trackFragmentSave,
|
|
40
|
+
useFragmentContent,
|
|
41
|
+
waitForFragmentSave,
|
|
42
|
+
} from './fragment-save-lifetime.js';
|
|
43
|
+
import { JsxPropsPanel } from './JsxPropsPanel.js';
|
|
22
44
|
import { LocaleSelector } from './LocaleSelector.js';
|
|
23
|
-
import { MDXLivePreview } from './MDXLivePreview.js';
|
|
45
|
+
import { fragmentPreviewPathname, MDXLivePreview } from './MDXLivePreview.js';
|
|
46
|
+
import { usePeerBlockOutlines } from './MdxPageEditor.js';
|
|
47
|
+
import { useOfferedMdxComponents } from './offered-mdx-components.js';
|
|
24
48
|
|
|
25
|
-
type SaveState = 'idle' | 'saving' | 'saved' | 'error' | 'conflict';
|
|
26
49
|
type PersistStatus = 'saved' | 'conflict' | 'error';
|
|
27
50
|
|
|
28
51
|
/**
|
|
@@ -30,36 +53,272 @@ type PersistStatus = 'saved' | 'conflict' | 'error';
|
|
|
30
53
|
*
|
|
31
54
|
* Inline page layout (mirrors MdxPageEditor). Routed via /fragments/:id which
|
|
32
55
|
* lives outside CMSLayout in App.tsx so the editor occupies the full viewport.
|
|
56
|
+
* Inside a parent frame with a doc channel the body is co-edited live and there
|
|
57
|
+
* is nothing to save.
|
|
33
58
|
*/
|
|
34
59
|
interface FragmentEditorProps {
|
|
35
|
-
/** Editor surface override for parent-state tests; production uses CMSMDXEditor. */
|
|
60
|
+
/** Editor surface override for parent-state tests of the Save editor; production uses CMSMDXEditor. */
|
|
36
61
|
EditorComponent?: ElementType<CMSMDXEditorProps>;
|
|
37
62
|
}
|
|
38
63
|
|
|
39
64
|
export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEditorProps = {}) {
|
|
65
|
+
const { id } = useParams<{ id: string }>();
|
|
66
|
+
// The guard sits above the loading, missing and failed screens too: a locale switch reopens, and the old doc may still owe work.
|
|
67
|
+
return useDocChannel() ? (
|
|
68
|
+
<>
|
|
69
|
+
<LiveLeaveGuard />
|
|
70
|
+
<LiveFragmentEditor key={id} />
|
|
71
|
+
</>
|
|
72
|
+
) : (
|
|
73
|
+
<SavedFragmentEditor EditorComponent={EditorComponent} />
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const NOT_MDX = 'This fragment is not MDX, so it cannot be edited here.';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The co-editing branch: the body is bound to the fragment's shared doc, an MDX doc as on MDX pages. The site's save
|
|
81
|
+
* check gates each write: an edit it refuses is held in the editor unsent, and the frame reports it held, so flushes
|
|
82
|
+
* answer not ok and leaving asks.
|
|
83
|
+
*/
|
|
84
|
+
function LiveFragmentEditor() {
|
|
85
|
+
const { id } = useParams<{ id: string }>();
|
|
86
|
+
const [searchParams] = useSearchParams();
|
|
87
|
+
const navigate = useNavigate();
|
|
88
|
+
const { resolvedTheme } = useTheme();
|
|
89
|
+
const { vocabulary } = useSiteRender();
|
|
90
|
+
const descriptors = useOfferedMdxComponents();
|
|
91
|
+
const { fromPage, backTarget, backLabel } = fragmentOrigin(searchParams);
|
|
92
|
+
const { defaultLocale, availableLocales } = useFragmentLocales();
|
|
93
|
+
const [chosenLocale, setChosenLocale] = useState<string | null>(null);
|
|
94
|
+
const currentLocale = chosenLocale ?? defaultLocale;
|
|
95
|
+
const [previewOpen, setPreviewOpen] = useEditorPref('conloca.mdxeditor.previewOpen');
|
|
96
|
+
// The fragment as stored: its name and type; its body comes from the shared doc, opened only for an MDX row.
|
|
97
|
+
const { data: loaded, isPending, error } = useLocalizedContent(id || '', currentLocale);
|
|
98
|
+
const isMdx = loaded?.type === 'mdx';
|
|
99
|
+
const liveDoc = useLiveDoc(id && isMdx ? { kind: 'mdx', id, locale: currentLocale } : null);
|
|
100
|
+
const live = liveDoc.state === 'ready' ? liveDoc.live : undefined;
|
|
101
|
+
const channel = useDocChannel();
|
|
102
|
+
const [editorRoot, setEditorRoot] = useState<HTMLElement | null>(null);
|
|
103
|
+
usePeerBlockOutlines(live?.docKey ?? '', editorRoot);
|
|
104
|
+
const [preview, setPreview] = useState('');
|
|
105
|
+
// The check reads the site's vocabulary as it is at each edit, without rebinding the editor.
|
|
106
|
+
const checkInput = useRef({ vocabulary, descriptors });
|
|
107
|
+
useLayoutEffect(() => {
|
|
108
|
+
checkInput.current = { vocabulary, descriptors };
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// The entry is the locale the doc was opened in: `live` changes only once a switched locale's doc is open, so a render
|
|
112
|
+
// between the switch and that open must not tag the open editor's holds with the new locale.
|
|
113
|
+
const entry = `${id}:${currentLocale}`;
|
|
114
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `entry` is read when `live` changes, see above.
|
|
115
|
+
const bound = useMemo(() => {
|
|
116
|
+
if (!live) return null;
|
|
117
|
+
const text = live.doc.getText('body');
|
|
118
|
+
const plugin = markdownLivePlugin({
|
|
119
|
+
text,
|
|
120
|
+
undoScope: [text],
|
|
121
|
+
onSelectionBlock: (block) => channel?.setSelection(live.docKey, block === null ? null : `block:${block}`),
|
|
122
|
+
onRootElement: setEditorRoot,
|
|
123
|
+
held: channel
|
|
124
|
+
? {
|
|
125
|
+
notice: () => (live.held ? channel.held() : null),
|
|
126
|
+
content: () => channel.heldContent(live.docKey)?.mdx ?? '',
|
|
127
|
+
subscribe: (onChange) => channel.on('status', onChange),
|
|
128
|
+
}
|
|
129
|
+
: undefined,
|
|
130
|
+
check: (markdown) =>
|
|
131
|
+
checkFragmentSave(markdown, checkInput.current.vocabulary, checkInput.current.descriptors)?.message ?? null,
|
|
132
|
+
onHeld: (notice, markdown) => setHeldFragmentEdit(entry, live.docKey, notice, markdown),
|
|
133
|
+
});
|
|
134
|
+
return { text, value: text.toJSON(), plugins: [plugin] };
|
|
135
|
+
}, [live, channel]);
|
|
136
|
+
|
|
137
|
+
// A held edit from an earlier editor (a replaced doc, a locale switched back) is not put back: written over the body
|
|
138
|
+
// now stored, it could undo a discard or restore or a teammate's change. It is offered to copy instead, still held;
|
|
139
|
+
// a later one queues behind it, so none is dropped unseen.
|
|
140
|
+
const [notAppliedQueue, setNotAppliedQueue] = useState<{ reason: string; markdown: string; docKey: string }[]>([]);
|
|
141
|
+
const notApplied = notAppliedQueue[0];
|
|
142
|
+
// Leaving asks until each text is copied or dismissed: it exists nowhere else.
|
|
143
|
+
const closeNotApplied = () => {
|
|
144
|
+
if (!notApplied) return;
|
|
145
|
+
const rest = notAppliedQueue.slice(1);
|
|
146
|
+
if (!rest.some((edit) => edit.docKey === notApplied.docKey)) setNotAppliedFragmentEdit(notApplied.docKey, null);
|
|
147
|
+
setNotAppliedQueue(rest);
|
|
148
|
+
};
|
|
149
|
+
const boundEntry = useRef<string | null>(null);
|
|
150
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs once per new editor; `entry` is its locale, see above.
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (!live) return;
|
|
153
|
+
const markdown = heldFragmentEdit(entry);
|
|
154
|
+
const reason =
|
|
155
|
+
boundEntry.current === entry ? 'the fragment was replaced (discarded or restored)' : 'the locale was switched';
|
|
156
|
+
boundEntry.current = entry;
|
|
157
|
+
if (markdown === undefined) return;
|
|
158
|
+
setHeldFragmentEdit(entry, live.docKey, null, null);
|
|
159
|
+
setNotAppliedFragmentEdit(live.docKey, 'Your unsent edit was not applied: copy it before you leave.');
|
|
160
|
+
setNotAppliedQueue((queue) => [...queue, { reason, markdown, docKey: live.docKey }]);
|
|
161
|
+
}, [live]);
|
|
162
|
+
|
|
163
|
+
// The preview follows the shared body, teammates' changes included; the editor's own onChange adds a held edit.
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (!bound) return undefined;
|
|
166
|
+
const show = () => setPreview(bound.text.toJSON());
|
|
167
|
+
show();
|
|
168
|
+
bound.text.observe(show);
|
|
169
|
+
return () => bound.text.unobserve(show);
|
|
170
|
+
}, [bound]);
|
|
171
|
+
|
|
172
|
+
const fragmentName = fragmentDisplayName(loaded, id);
|
|
173
|
+
const filePath = `fragments/${fragmentName}`;
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
const prev = document.title;
|
|
176
|
+
document.title = `Edit: ${filePath} · Conloca CMS`;
|
|
177
|
+
return () => {
|
|
178
|
+
document.title = prev;
|
|
179
|
+
};
|
|
180
|
+
}, [filePath]);
|
|
181
|
+
|
|
182
|
+
// A locale with no version is only "missing" after a switch; the locale the editor opens in must exist.
|
|
183
|
+
const absent = !!currentLocale && !isPending && !loaded;
|
|
184
|
+
const failure =
|
|
185
|
+
error?.message ??
|
|
186
|
+
(absent && chosenLocale === null ? 'Not found' : null) ??
|
|
187
|
+
(loaded && !isMdx ? NOT_MDX : null) ??
|
|
188
|
+
(liveDoc.state === 'failed' ? liveDoc.message : null);
|
|
189
|
+
if (failure !== null) {
|
|
190
|
+
return (
|
|
191
|
+
<div className="flex flex-col items-center justify-center h-full bg-page gap-4">
|
|
192
|
+
<div className="text-red-04 dark:text-red-08">Failed to load fragment: {failure}</div>
|
|
193
|
+
<button
|
|
194
|
+
type="button"
|
|
195
|
+
onClick={() => navigate('/fragments')}
|
|
196
|
+
className="px-4 py-2 bg-azure-04 text-white rounded-md hover:bg-azure-03 transition-colors"
|
|
197
|
+
>
|
|
198
|
+
Back to Fragments
|
|
199
|
+
</button>
|
|
200
|
+
</div>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const editing = !absent && live && bound ? { live, bound } : null;
|
|
205
|
+
if (!absent && !editing) {
|
|
206
|
+
return (
|
|
207
|
+
<div className="flex items-center justify-center h-full bg-page">
|
|
208
|
+
<div className="flex items-center gap-3 text-muted" role="status">
|
|
209
|
+
<div className="animate-spin rounded-full h-6 w-6 border-b-2 border-azure-04" />
|
|
210
|
+
<span>Loading fragment…</span>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const draftPage = editing ? draftToolsPage(id, currentLocale) : null;
|
|
217
|
+
return (
|
|
218
|
+
<div className="h-full flex flex-col bg-page">
|
|
219
|
+
<header className="flex items-center justify-between gap-4 px-4 py-2 border-b border-line bg-overlay shrink-0">
|
|
220
|
+
<div className="flex items-center gap-2 min-w-0">
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
onClick={() => navigate(backTarget)}
|
|
224
|
+
aria-label={backLabel}
|
|
225
|
+
className="p-2 rounded text-muted hover:bg-hover"
|
|
226
|
+
>
|
|
227
|
+
←
|
|
228
|
+
</button>
|
|
229
|
+
<h1 className="text-base font-medium text-foreground truncate">Edit: {filePath}</h1>
|
|
230
|
+
</div>
|
|
231
|
+
<div className="flex items-center gap-2">
|
|
232
|
+
{editing && <PeerAvatars live={editing.live} />}
|
|
233
|
+
<LocaleSelector
|
|
234
|
+
currentLocale={currentLocale}
|
|
235
|
+
availableLocales={availableLocales}
|
|
236
|
+
onChange={setChosenLocale}
|
|
237
|
+
/>
|
|
238
|
+
{editing && (
|
|
239
|
+
<EditorChromeToggles previewOpen={previewOpen} onTogglePreview={() => setPreviewOpen(!previewOpen)} />
|
|
240
|
+
)}
|
|
241
|
+
{draftPage && <PageDraftMenu page={draftPage} label={fragmentName} />}
|
|
242
|
+
</div>
|
|
243
|
+
</header>
|
|
244
|
+
{editing ? (
|
|
245
|
+
<>
|
|
246
|
+
<DraftNoticeStrip id={id} locale={currentLocale} docKey={editing.live.docKey} />
|
|
247
|
+
<SharedFragmentBanner fromPage={fromPage} live />
|
|
248
|
+
{notApplied && (
|
|
249
|
+
<div
|
|
250
|
+
role="alert"
|
|
251
|
+
data-testid="held-edit-not-applied"
|
|
252
|
+
className="flex items-center gap-3 px-4 py-2 bg-yellow-11 text-yellow-02 text-sm"
|
|
253
|
+
>
|
|
254
|
+
<span>
|
|
255
|
+
Your unsent edit was not applied because {notApplied.reason}. This shows the fragment as stored now.
|
|
256
|
+
</span>
|
|
257
|
+
<button
|
|
258
|
+
type="button"
|
|
259
|
+
className="px-3 py-1 border border-line rounded"
|
|
260
|
+
onClick={() => void navigator.clipboard.writeText(notApplied.markdown).then(closeNotApplied)}
|
|
261
|
+
>
|
|
262
|
+
Copy changes
|
|
263
|
+
</button>
|
|
264
|
+
<button type="button" className="px-3 py-1" onClick={closeNotApplied}>
|
|
265
|
+
Dismiss
|
|
266
|
+
</button>
|
|
267
|
+
</div>
|
|
268
|
+
)}
|
|
269
|
+
<FragmentEditorSurface
|
|
270
|
+
EditorComponent={CMSMDXEditor}
|
|
271
|
+
editorKey={editing.live.docKey}
|
|
272
|
+
content={editing.bound.value}
|
|
273
|
+
// Live writes every change as made: the Diff view compares with the text opened, as the page editor's does.
|
|
274
|
+
savedContent={editing.bound.value}
|
|
275
|
+
preview={preview}
|
|
276
|
+
resolvedTheme={resolvedTheme}
|
|
277
|
+
previewOpen={previewOpen}
|
|
278
|
+
editorClassName={resolvedTheme === 'dark' ? 'dark-theme' : undefined}
|
|
279
|
+
// The live plugin writes every change; there is nothing to save.
|
|
280
|
+
onChange={(next) => setPreview(next)}
|
|
281
|
+
onSave={undefined}
|
|
282
|
+
extraPlugins={editing.bound.plugins}
|
|
283
|
+
/>
|
|
284
|
+
</>
|
|
285
|
+
) : (
|
|
286
|
+
<p className="p-8 text-center text-muted">No {currentLocale} version of this fragment yet.</p>
|
|
287
|
+
)}
|
|
288
|
+
</div>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function SavedFragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEditorProps) {
|
|
40
293
|
const { id } = useParams<{ id: string }>();
|
|
41
294
|
const [searchParams] = useSearchParams();
|
|
42
295
|
const navigate = useNavigate();
|
|
296
|
+
const contentClient = getContentAPIClient();
|
|
43
297
|
const updateContent = useUpdateLocalized();
|
|
44
298
|
const { resolvedTheme } = useTheme();
|
|
299
|
+
const { vocabulary } = useSiteRender();
|
|
300
|
+
const descriptors = useOfferedMdxComponents();
|
|
301
|
+
// Why the last save was refused without writing, for the host flush to report.
|
|
302
|
+
const refusalRef = useRef<string | undefined>(undefined);
|
|
45
303
|
|
|
46
304
|
// When the editor is opened from inside the Puck page editor (via the
|
|
47
305
|
// "Open fragment editor" button on the page's right-hand panel), `?from=page`
|
|
48
306
|
// signals we should surface a shared-content warning and offer an explicit
|
|
49
|
-
//
|
|
50
|
-
const fromPage = searchParams
|
|
51
|
-
const
|
|
307
|
+
// back path to the originating page rather than back to /fragments.
|
|
308
|
+
const { fromPage, backTarget, backLabel } = fragmentOrigin(searchParams);
|
|
309
|
+
const backHref = useHref(backTarget);
|
|
52
310
|
|
|
53
311
|
const localeConfig = getUIConfig().locales;
|
|
54
312
|
const [currentLocale, setCurrentLocale] = useState<string>(
|
|
55
313
|
() => localeConfig?.defaultLocale ?? localeConfig?.list[0] ?? '',
|
|
56
314
|
);
|
|
57
|
-
const
|
|
315
|
+
const currentEtagRef = useRef('');
|
|
58
316
|
const [pendingLocaleSwitch, setPendingLocaleSwitch] = useState<string | null>(null);
|
|
59
317
|
const [showLocaleUnsavedDialog, setShowLocaleUnsavedDialog] = useState(false);
|
|
60
318
|
|
|
61
319
|
const [conflict, setConflict] = useState<UpdateResult | null>(null);
|
|
62
320
|
const { showError, errorModalProps } = useErrorModal();
|
|
321
|
+
const [errorOperation, setErrorOperation] = useState<'save' | 'locale'>('save');
|
|
63
322
|
|
|
64
323
|
const [content, setContent] = useState<string>('');
|
|
65
324
|
// MDXEditorLib only reads `markdown` once on mount, so defer rendering the
|
|
@@ -68,21 +327,23 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
68
327
|
const savedContentRef = useRef<string>('');
|
|
69
328
|
|
|
70
329
|
const [saveState, setSaveState] = useState<SaveState>('idle');
|
|
330
|
+
// A save has landed since this fragment and locale were opened: lets the status line keep saying the draft
|
|
331
|
+
// is saved (and not necessarily published) once the button has settled back from "Saved".
|
|
332
|
+
const [savedSinceOpen, setSavedSinceOpen] = useState(false);
|
|
71
333
|
const [previewOpen, setPreviewOpen] = useEditorPref('conloca.mdxeditor.previewOpen');
|
|
72
334
|
|
|
73
|
-
const {
|
|
74
|
-
const siteDefaultLocale = Object.values(sitesConfig?.sites ?? {})[0]?.defaultLocale;
|
|
75
|
-
const defaultLocale =
|
|
76
|
-
localeConfig?.defaultLocale ?? siteDefaultLocale ?? sitesConfig?.globalLocales[0] ?? (sitesConfig ? 'en' : '');
|
|
77
|
-
const availableLocales = localeConfig?.list?.length
|
|
78
|
-
? localeConfig.list
|
|
79
|
-
: sitesConfig?.globalLocales.length
|
|
80
|
-
? sitesConfig.globalLocales
|
|
81
|
-
: defaultLocale
|
|
82
|
-
? [defaultLocale]
|
|
83
|
-
: [];
|
|
335
|
+
const { defaultLocale, availableLocales } = useFragmentLocales();
|
|
84
336
|
|
|
85
|
-
const {
|
|
337
|
+
const {
|
|
338
|
+
data: loadedContent,
|
|
339
|
+
isLoading,
|
|
340
|
+
error,
|
|
341
|
+
waitingForSave,
|
|
342
|
+
waitError,
|
|
343
|
+
retrySaveWait,
|
|
344
|
+
markLocaleLoaded,
|
|
345
|
+
} = useFragmentContent(id || '', currentLocale);
|
|
346
|
+
const saveIdentityRef = useFragmentSaveIdentity(id, currentLocale);
|
|
86
347
|
const fragmentIdentityRef = useRef(id);
|
|
87
348
|
const routeIdentityChanged = fragmentIdentityRef.current !== id;
|
|
88
349
|
|
|
@@ -90,13 +351,14 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
90
351
|
if (!routeIdentityChanged) return;
|
|
91
352
|
fragmentIdentityRef.current = id;
|
|
92
353
|
setCurrentLocale(defaultLocale);
|
|
93
|
-
|
|
354
|
+
currentEtagRef.current = '';
|
|
94
355
|
setPendingLocaleSwitch(null);
|
|
95
356
|
setShowLocaleUnsavedDialog(false);
|
|
96
357
|
setConflict(null);
|
|
97
358
|
setContent('');
|
|
98
359
|
setIsContentLoaded(false);
|
|
99
360
|
savedContentRef.current = '';
|
|
361
|
+
setSavedSinceOpen(false);
|
|
100
362
|
setSaveState('idle');
|
|
101
363
|
}, [id, routeIdentityChanged, defaultLocale]);
|
|
102
364
|
|
|
@@ -119,8 +381,8 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
119
381
|
// arrived, seeding an empty buffer that then overwrites the document
|
|
120
382
|
// on the next save.
|
|
121
383
|
if (!routeIdentityChanged && !isContentLoaded && loadedContent?.localized?.content && loadedContent.id === id) {
|
|
122
|
-
|
|
123
|
-
const data = loadedContent.localized.content
|
|
384
|
+
currentEtagRef.current = loadedContent.localized.etag;
|
|
385
|
+
const data = loadedContent.localized.content;
|
|
124
386
|
const mdx = data?.mdx || '';
|
|
125
387
|
savedContentRef.current = mdx;
|
|
126
388
|
setContent(mdx);
|
|
@@ -129,10 +391,19 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
129
391
|
}, [id, loadedContent, isContentLoaded, routeIdentityChanged]);
|
|
130
392
|
|
|
131
393
|
const isDirty = isContentLoaded && content !== savedContentRef.current;
|
|
132
|
-
const
|
|
394
|
+
const {
|
|
395
|
+
save: queueSave,
|
|
396
|
+
pendingRef: pendingSaveRef,
|
|
397
|
+
blocksExit,
|
|
398
|
+
} = useFragmentSaveQueue(saveIdentityRef.current, saveState, isDirty);
|
|
399
|
+
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
if (!isDirty && saveState === 'error') setSaveState('idle');
|
|
402
|
+
}, [isDirty, saveState]);
|
|
403
|
+
const blocker = useUnsavedChangesGuard(blocksExit);
|
|
133
404
|
|
|
134
405
|
const editorClassName = resolvedTheme === 'dark' ? 'dark-theme' : undefined;
|
|
135
|
-
const fragmentName = loadedContent
|
|
406
|
+
const fragmentName = fragmentDisplayName(loadedContent, id);
|
|
136
407
|
const filePath = `fragments/${fragmentName}`;
|
|
137
408
|
|
|
138
409
|
useEffect(() => {
|
|
@@ -144,26 +415,39 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
144
415
|
}, [filePath]);
|
|
145
416
|
|
|
146
417
|
useEffect(() => {
|
|
147
|
-
if (saveState !== 'saved') return;
|
|
418
|
+
if (saveState !== 'saved') return undefined;
|
|
148
419
|
const timer = setTimeout(() => setSaveState('idle'), 2000);
|
|
149
420
|
return () => clearTimeout(timer);
|
|
150
421
|
}, [saveState]);
|
|
151
422
|
|
|
152
|
-
const
|
|
423
|
+
const writeContent = async (
|
|
424
|
+
newContent: string,
|
|
425
|
+
saveIdentity: typeof saveIdentityRef.current,
|
|
426
|
+
forceEtag?: string,
|
|
427
|
+
): Promise<PersistStatus> => {
|
|
153
428
|
if (!id) return 'error';
|
|
154
429
|
setSaveState('saving');
|
|
155
430
|
|
|
156
431
|
try {
|
|
157
|
-
const result = await
|
|
432
|
+
const result = await trackFragmentSave(
|
|
433
|
+
contentClient,
|
|
158
434
|
id,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
435
|
+
currentLocale,
|
|
436
|
+
updateContent.mutateAsync({
|
|
437
|
+
id,
|
|
438
|
+
locale: currentLocale,
|
|
439
|
+
data: { content: { mdx: newContent } },
|
|
440
|
+
etag: forceEtag ?? currentEtagRef.current,
|
|
441
|
+
}),
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
// A reply for another fragment or locale must not rebaseline this editor.
|
|
445
|
+
if (saveIdentityRef.current !== saveIdentity) return 'error';
|
|
163
446
|
|
|
164
447
|
if (result.success && result.etag) {
|
|
165
|
-
|
|
448
|
+
currentEtagRef.current = result.etag;
|
|
166
449
|
savedContentRef.current = newContent;
|
|
450
|
+
setSavedSinceOpen(true);
|
|
167
451
|
setSaveState('saved');
|
|
168
452
|
return 'saved';
|
|
169
453
|
}
|
|
@@ -176,39 +460,97 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
176
460
|
|
|
177
461
|
throw new Error(`Save failed: ${result.reason}`);
|
|
178
462
|
} catch (err) {
|
|
463
|
+
if (saveIdentityRef.current !== saveIdentity) return 'error';
|
|
464
|
+
// HTTP clients throw stale writes; storage adapters may resolve the same conflict as a result.
|
|
465
|
+
if (err instanceof StaleWriteError) {
|
|
466
|
+
setConflict({ success: false, reason: 'stale_write', currentEtag: err.currentEtag });
|
|
467
|
+
setSaveState('conflict');
|
|
468
|
+
return 'conflict';
|
|
469
|
+
}
|
|
179
470
|
console.error('Failed to save fragment:', err);
|
|
471
|
+
setErrorOperation('save');
|
|
180
472
|
showError('Failed to save fragment', err);
|
|
181
473
|
setSaveState('error');
|
|
182
474
|
return 'error';
|
|
183
475
|
}
|
|
184
476
|
};
|
|
185
477
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
478
|
+
const persist = (newContent: string, forceEtag?: string): Promise<PersistStatus> => {
|
|
479
|
+
const identity = saveIdentityRef.current;
|
|
480
|
+
return queueSave(
|
|
481
|
+
identity,
|
|
482
|
+
() => {
|
|
483
|
+
refusalRef.current = undefined;
|
|
484
|
+
if (!isContentLoaded || routeIdentityChanged || identity.id !== id || identity.locale !== currentLocale) {
|
|
485
|
+
return Promise.resolve('error');
|
|
486
|
+
}
|
|
487
|
+
if (forceEtag === undefined && newContent === savedContentRef.current) return Promise.resolve('saved');
|
|
488
|
+
const committed = flushRef.current;
|
|
489
|
+
const refusal = checkFragmentSave(newContent, committed.vocabulary, committed.descriptors);
|
|
490
|
+
if (refusal) {
|
|
491
|
+
setErrorOperation('save');
|
|
492
|
+
showError(refusal.message);
|
|
493
|
+
setSaveState('error');
|
|
494
|
+
refusalRef.current = refusal.message;
|
|
495
|
+
return Promise.resolve('error');
|
|
496
|
+
}
|
|
497
|
+
return writeContent(newContent, identity, forceEtag);
|
|
498
|
+
},
|
|
499
|
+
() => saveIdentityRef.current === identity,
|
|
500
|
+
);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
const discardedBufferRef = useRef<{ identity: typeof saveIdentityRef.current; content: string } | null>(null);
|
|
504
|
+
const flushRef = useRef({ content, isDirty, persist, waitingForSave, contentClient, vocabulary, descriptors });
|
|
505
|
+
useLayoutEffect(() => {
|
|
506
|
+
// The host must read the committed buffer and request, never an abandoned route render.
|
|
507
|
+
const discarded = discardedBufferRef.current;
|
|
508
|
+
const bufferDiscarded = discarded?.identity === saveIdentityRef.current && discarded.content === content;
|
|
509
|
+
const hostDirty = isDirty && !routeIdentityChanged && !bufferDiscarded;
|
|
510
|
+
const dirtyChanged = flushRef.current.isDirty !== hostDirty;
|
|
511
|
+
flushRef.current = {
|
|
512
|
+
content,
|
|
513
|
+
isDirty: hostDirty,
|
|
514
|
+
persist,
|
|
515
|
+
waitingForSave,
|
|
516
|
+
contentClient,
|
|
517
|
+
vocabulary,
|
|
518
|
+
descriptors,
|
|
519
|
+
};
|
|
520
|
+
if (dirtyChanged) notifyEditorDirtyChanged();
|
|
521
|
+
});
|
|
193
522
|
|
|
194
523
|
useEffect(() => {
|
|
195
524
|
return registerEditorFlushHandler(
|
|
196
525
|
async () => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
526
|
+
const identity = saveIdentityRef.current;
|
|
527
|
+
let committed = flushRef.current;
|
|
528
|
+
// A previous editor's write can be discovered before its queued waiting-state render commits.
|
|
529
|
+
const previousEditorSave =
|
|
530
|
+
pendingSaveRef.current?.identity !== identity &&
|
|
531
|
+
pendingFragmentSave(committed.contentClient, identity.id || '', identity.locale);
|
|
532
|
+
if (committed.waitingForSave || previousEditorSave) {
|
|
533
|
+
return { ok: false, message: 'Fragment changes are still loading.' };
|
|
534
|
+
}
|
|
535
|
+
while (committed.isDirty || pendingSaveRef.current?.identity === identity) {
|
|
536
|
+
// oxlint-disable-next-line no-await-in-loop -- Each write needs the ETag returned by the previous save.
|
|
537
|
+
const status = await committed.persist(committed.content);
|
|
538
|
+
if (status !== 'saved' || saveIdentityRef.current !== identity) {
|
|
539
|
+
return { ok: false, message: refusalRef.current ?? 'Could not save editor changes.' };
|
|
540
|
+
}
|
|
541
|
+
// A completed write changes the baseline before React necessarily commits a new dirty flag.
|
|
542
|
+
committed = flushRef.current;
|
|
543
|
+
const discarded = discardedBufferRef.current;
|
|
544
|
+
const bufferDiscarded = discarded?.identity === identity && discarded.content === committed.content;
|
|
545
|
+
const needsSave = !bufferDiscarded && committed.content !== savedContentRef.current;
|
|
546
|
+
if (!needsSave && pendingSaveRef.current?.identity !== identity) break;
|
|
547
|
+
committed = { ...committed, isDirty: needsSave };
|
|
201
548
|
}
|
|
202
549
|
return { ok: true };
|
|
203
550
|
},
|
|
204
|
-
{ isDirty: () =>
|
|
551
|
+
{ isDirty: () => flushRef.current.isDirty },
|
|
205
552
|
);
|
|
206
|
-
}, []);
|
|
207
|
-
|
|
208
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: The dependency change is the event; handlers read current state through refs.
|
|
209
|
-
useEffect(() => {
|
|
210
|
-
notifyEditorDirtyChanged();
|
|
211
|
-
}, [isDirty]);
|
|
553
|
+
}, [pendingSaveRef, saveIdentityRef]);
|
|
212
554
|
|
|
213
555
|
const ui = getUIConfig();
|
|
214
556
|
const hideSave = ui.hideEditorSave === true;
|
|
@@ -217,29 +559,38 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
217
559
|
const bindSaveShortcut = !hideSave && ui.hosted !== true;
|
|
218
560
|
|
|
219
561
|
const handleSaveClick = () => {
|
|
220
|
-
void
|
|
562
|
+
void saveDraft(content);
|
|
221
563
|
};
|
|
222
564
|
|
|
223
|
-
// Back
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
const
|
|
565
|
+
// Back leaves without saving or publishing. The unsaved-changes guard
|
|
566
|
+
// (`useUnsavedChangesGuard`) intercepts the navigation and opens the
|
|
567
|
+
// dialog if the user has unsaved edits, so we don't duplicate the check.
|
|
568
|
+
const handleBack = () => {
|
|
569
|
+
void navigate(backTarget);
|
|
570
|
+
};
|
|
227
571
|
|
|
228
|
-
const
|
|
229
|
-
|
|
572
|
+
const revokeLocaleIntent = () => {
|
|
573
|
+
if (exitIntentRef.current?.kind !== 'locale') return;
|
|
574
|
+
exitIntentRef.current = null;
|
|
575
|
+
const discarded = discardedBufferRef.current;
|
|
576
|
+
if (discarded?.identity !== saveIdentityRef.current || discarded.content !== flushRef.current.content) return;
|
|
577
|
+
// Revoking a destination leaves this exact draft visible and owned by Save/Publish again.
|
|
578
|
+
discardedBufferRef.current = null;
|
|
579
|
+
flushRef.current = { ...flushRef.current, isDirty: flushRef.current.content !== savedContentRef.current };
|
|
580
|
+
notifyEditorDirtyChanged();
|
|
230
581
|
};
|
|
231
582
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
navigate(backTarget);
|
|
583
|
+
const saveDraft = (newContent: string) => {
|
|
584
|
+
// Explicit Save reclaims a discarded draft, but a clean shortcut must leave an ordinary locale read alone.
|
|
585
|
+
const discarded = discardedBufferRef.current;
|
|
586
|
+
if (discarded?.identity === saveIdentityRef.current && discarded.content === newContent) revokeLocaleIntent();
|
|
587
|
+
return persist(newContent);
|
|
238
588
|
};
|
|
239
589
|
|
|
240
590
|
const handleLocaleChange = async (newLocale: string) => {
|
|
241
|
-
if (newLocale === currentLocale) return;
|
|
591
|
+
if (newLocale === currentLocale || blocker.state !== 'unblocked' || routeIdentityChanged) return;
|
|
242
592
|
if (isDirty) {
|
|
593
|
+
revokeLocaleIntent();
|
|
243
594
|
setPendingLocaleSwitch(newLocale);
|
|
244
595
|
setShowLocaleUnsavedDialog(true);
|
|
245
596
|
return;
|
|
@@ -248,63 +599,108 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
248
599
|
};
|
|
249
600
|
|
|
250
601
|
const switchLocale = async (newLocale: string) => {
|
|
251
|
-
if (!id) return;
|
|
602
|
+
if (!id || routeIdentityChanged) return;
|
|
603
|
+
const identity = saveIdentityRef.current;
|
|
604
|
+
const intent: FragmentExitIntent = { kind: 'locale', locale: newLocale };
|
|
605
|
+
exitIntentRef.current = intent;
|
|
606
|
+
const ownsIntent = () => exitIntentRef.current === intent && saveIdentityRef.current === identity;
|
|
252
607
|
|
|
253
608
|
try {
|
|
254
|
-
|
|
255
|
-
|
|
609
|
+
await waitForFragmentSave(pendingFragmentSave(contentClient, id, newLocale));
|
|
610
|
+
if (!ownsIntent()) return;
|
|
611
|
+
const newLocaleContent = await contentClient.getLocalized(id, newLocale);
|
|
612
|
+
if (!ownsIntent()) return;
|
|
613
|
+
if (newLocaleContent && (newLocaleContent.id !== id || newLocaleContent.localized.locale !== newLocale)) {
|
|
614
|
+
throw new Error('The locale reply does not match the requested fragment and locale.');
|
|
615
|
+
}
|
|
616
|
+
exitIntentRef.current = null;
|
|
256
617
|
|
|
257
618
|
if (!newLocaleContent) {
|
|
258
|
-
|
|
619
|
+
currentEtagRef.current = '';
|
|
259
620
|
savedContentRef.current = '';
|
|
260
621
|
setContent('');
|
|
261
622
|
} else {
|
|
262
|
-
|
|
263
|
-
const newData = newLocaleContent.localized.content
|
|
623
|
+
currentEtagRef.current = newLocaleContent.localized.etag;
|
|
624
|
+
const newData = newLocaleContent.localized.content;
|
|
264
625
|
const mdx = newData?.mdx || '';
|
|
265
626
|
savedContentRef.current = mdx;
|
|
266
627
|
setContent(mdx);
|
|
267
628
|
}
|
|
268
629
|
|
|
630
|
+
setSavedSinceOpen(false);
|
|
631
|
+
setSaveState('idle');
|
|
632
|
+
markLocaleLoaded(newLocale);
|
|
269
633
|
setCurrentLocale(newLocale);
|
|
270
634
|
setPendingLocaleSwitch(null);
|
|
271
635
|
} catch (err) {
|
|
636
|
+
if (!ownsIntent()) return;
|
|
637
|
+
revokeLocaleIntent();
|
|
638
|
+
setErrorOperation('locale');
|
|
639
|
+
showError(localeSwitchErrorMessage(flushRef.current.isDirty), err);
|
|
272
640
|
console.error('Failed to switch locale:', err);
|
|
273
641
|
}
|
|
274
642
|
};
|
|
275
643
|
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
278
|
-
|
|
279
|
-
if (status === 'saved') {
|
|
280
|
-
setShowLocaleUnsavedDialog(false);
|
|
281
|
-
await switchLocale(pendingLocaleSwitch);
|
|
282
|
-
} else if (status === 'conflict') {
|
|
283
|
-
// Conflict dialog has opened; back out of the locale-switch flow so
|
|
284
|
-
// the two dialogs don't stack. User resolves the conflict first,
|
|
285
|
-
// then can re-attempt the locale switch.
|
|
286
|
-
setShowLocaleUnsavedDialog(false);
|
|
287
|
-
setPendingLocaleSwitch(null);
|
|
288
|
-
}
|
|
644
|
+
const handleUnsavedSave = async () => {
|
|
645
|
+
if (exitIntentRef.current?.kind === 'proceeding' || exitIntentRef.current?.kind === 'cancelled') return;
|
|
646
|
+
await persist(content);
|
|
289
647
|
};
|
|
290
648
|
|
|
291
|
-
const
|
|
649
|
+
const maskBufferFromHost = () => {
|
|
650
|
+
// Mask this committed buffer before the locale read or router transition can yield to host Publish.
|
|
651
|
+
discardedBufferRef.current = { identity: saveIdentityRef.current, content };
|
|
652
|
+
flushRef.current = { ...flushRef.current, isDirty: false };
|
|
653
|
+
notifyEditorDirtyChanged();
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
const continueLocaleSwitch = async () => {
|
|
292
657
|
if (!pendingLocaleSwitch) return;
|
|
293
658
|
setShowLocaleUnsavedDialog(false);
|
|
659
|
+
setPendingLocaleSwitch(null);
|
|
294
660
|
await switchLocale(pendingLocaleSwitch);
|
|
295
661
|
};
|
|
296
662
|
|
|
663
|
+
const handleLocaleUnsavedDiscard = async () => {
|
|
664
|
+
if (!pendingLocaleSwitch) return;
|
|
665
|
+
maskBufferFromHost();
|
|
666
|
+
await continueLocaleSwitch();
|
|
667
|
+
};
|
|
668
|
+
|
|
297
669
|
const handleLocaleUnsavedCancel = () => {
|
|
670
|
+
revokeLocaleIntent();
|
|
298
671
|
setShowLocaleUnsavedDialog(false);
|
|
299
672
|
setPendingLocaleSwitch(null);
|
|
300
673
|
};
|
|
301
674
|
|
|
675
|
+
const {
|
|
676
|
+
intentRef: exitIntentRef,
|
|
677
|
+
showNavigationDialog,
|
|
678
|
+
continueNavigation,
|
|
679
|
+
cancelNavigation,
|
|
680
|
+
} = useFragmentExit({
|
|
681
|
+
routeIdentityChanged,
|
|
682
|
+
isDirty,
|
|
683
|
+
saveState,
|
|
684
|
+
blocker,
|
|
685
|
+
onLocaleContinue: continueLocaleSwitch,
|
|
686
|
+
onLocaleCancel: handleLocaleUnsavedCancel,
|
|
687
|
+
});
|
|
688
|
+
|
|
302
689
|
// The failure branch must come BEFORE the loading splash: a failed
|
|
303
690
|
// load never produces content, so a splash-first ordering spins
|
|
304
691
|
// forever and the user gets no error and no way back.
|
|
305
692
|
// `getLocalized` resolves null (no error) for a missing entry, so a
|
|
306
693
|
// settled query with nothing loaded is a failure too, not "loading".
|
|
307
|
-
if (
|
|
694
|
+
if (
|
|
695
|
+
fragmentLoadFailed({
|
|
696
|
+
routeIdentityChanged,
|
|
697
|
+
currentLocale,
|
|
698
|
+
error,
|
|
699
|
+
isLoading,
|
|
700
|
+
loadedContent,
|
|
701
|
+
savedContent: savedContentRef.current,
|
|
702
|
+
})
|
|
703
|
+
) {
|
|
308
704
|
return (
|
|
309
705
|
<div className="flex flex-col items-center justify-center h-full bg-page gap-4">
|
|
310
706
|
<div className="text-red-04 dark:text-red-08">Failed to load fragment: {error?.message || 'Not found'}</div>
|
|
@@ -324,159 +720,95 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
324
720
|
// with a placeholder empty string and update it later.
|
|
325
721
|
if (routeIdentityChanged || !currentLocale || isLoading || !isContentLoaded) {
|
|
326
722
|
return (
|
|
327
|
-
<
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
723
|
+
<FragmentLoading
|
|
724
|
+
waitingForSave={waitingForSave}
|
|
725
|
+
waitError={waitError}
|
|
726
|
+
onRetry={retrySaveWait}
|
|
727
|
+
backLabel={backLabel}
|
|
728
|
+
onBack={handleBack}
|
|
729
|
+
/>
|
|
333
730
|
);
|
|
334
731
|
}
|
|
335
732
|
|
|
336
|
-
const saveButtonLabel =
|
|
337
|
-
saveState === 'saving'
|
|
338
|
-
? 'Saving…'
|
|
339
|
-
: saveState === 'saved'
|
|
340
|
-
? '✓ Saved'
|
|
341
|
-
: saveState === 'error'
|
|
342
|
-
? 'Retry save'
|
|
343
|
-
: saveState === 'conflict'
|
|
344
|
-
? 'Conflict'
|
|
345
|
-
: 'Save';
|
|
346
|
-
|
|
347
733
|
return (
|
|
348
734
|
<div className="h-full flex flex-col bg-page">
|
|
349
735
|
<header className="flex items-center justify-between gap-4 px-4 py-2 border-b border-line bg-overlay shrink-0">
|
|
350
736
|
<div className="flex items-center gap-2 min-w-0">
|
|
351
737
|
<button
|
|
352
738
|
type="button"
|
|
353
|
-
onClick={
|
|
354
|
-
aria-label={
|
|
739
|
+
onClick={handleBack}
|
|
740
|
+
aria-label={backLabel}
|
|
355
741
|
className="p-2 rounded text-muted hover:bg-hover"
|
|
356
742
|
>
|
|
357
743
|
←
|
|
358
744
|
</button>
|
|
359
|
-
<
|
|
745
|
+
<div className="min-w-0">
|
|
746
|
+
<h1 className="text-base font-medium text-foreground truncate">Edit: {filePath}</h1>
|
|
747
|
+
<p
|
|
748
|
+
id={FRAGMENT_STATUS_ID}
|
|
749
|
+
role="status"
|
|
750
|
+
className="text-xs text-muted truncate"
|
|
751
|
+
data-testid="fragment-editor-status"
|
|
752
|
+
>
|
|
753
|
+
{fragmentStatusText({ saveState, isDirty, savedSinceOpen })}
|
|
754
|
+
</p>
|
|
755
|
+
</div>
|
|
360
756
|
</div>
|
|
361
757
|
<div className="flex items-center gap-2">
|
|
362
758
|
<LocaleSelector
|
|
759
|
+
disabled={saveState === 'saving'}
|
|
363
760
|
currentLocale={currentLocale}
|
|
364
761
|
availableLocales={availableLocales}
|
|
365
762
|
onChange={handleLocaleChange}
|
|
366
763
|
/>
|
|
367
764
|
<EditorChromeToggles previewOpen={previewOpen} onTogglePreview={() => setPreviewOpen(!previewOpen)} />
|
|
368
|
-
<
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
>
|
|
374
|
-
Cancel
|
|
375
|
-
</button>
|
|
376
|
-
{!hideSave && (
|
|
377
|
-
<button
|
|
378
|
-
type="button"
|
|
379
|
-
onClick={handleSaveClick}
|
|
380
|
-
disabled={saveState === 'saving' || (!isDirty && saveState === 'idle')}
|
|
381
|
-
className="px-3 py-1.5 text-sm bg-accent text-accent-foreground rounded hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
382
|
-
>
|
|
383
|
-
{saveButtonLabel}
|
|
384
|
-
</button>
|
|
385
|
-
)}
|
|
386
|
-
{fromPage && (
|
|
387
|
-
<button
|
|
388
|
-
type="button"
|
|
389
|
-
onClick={handleDone}
|
|
390
|
-
disabled={saveState === 'saving'}
|
|
391
|
-
className="px-3 py-1.5 text-sm border border-line rounded text-foreground hover:bg-hover disabled:opacity-50"
|
|
392
|
-
data-testid="fragment-editor-done"
|
|
393
|
-
>
|
|
394
|
-
Done
|
|
395
|
-
</button>
|
|
396
|
-
)}
|
|
397
|
-
</div>
|
|
398
|
-
</header>
|
|
399
|
-
{fromPage && (
|
|
400
|
-
<div
|
|
401
|
-
className="flex items-start gap-2 px-4 py-2 border-b border-yellow-08 dark:border-yellow-03 bg-yellow-11 dark:bg-yellow-02 text-sm text-yellow-02 dark:text-yellow-09 shrink-0"
|
|
402
|
-
role="status"
|
|
403
|
-
data-testid="shared-fragment-banner"
|
|
404
|
-
>
|
|
405
|
-
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0" />
|
|
406
|
-
<span>This is a shared fragment. Saving updates every page that uses it.</span>
|
|
407
|
-
</div>
|
|
408
|
-
)}
|
|
409
|
-
<div className="flex-1 overflow-hidden flex flex-row min-h-0">
|
|
410
|
-
{/* `conloca-mdx-editor-surround` paints the area around the
|
|
411
|
-
prose card with the host site's body bg (via the
|
|
412
|
-
`--conloca-host-body-bg` bridge in site-styles). Same class
|
|
413
|
-
MdxPageEditor uses — the two surfaces now share the
|
|
414
|
-
surround treatment so a fragment visually matches the page
|
|
415
|
-
it'll ultimately appear in. */}
|
|
416
|
-
<div
|
|
417
|
-
className={`flex-1 min-w-0 overflow-hidden conloca-mdx-editor-surround${resolvedTheme === 'dark' ? ' dark' : ''}`}
|
|
418
|
-
data-theme={resolvedTheme}
|
|
419
|
-
>
|
|
420
|
-
<EditorComponent
|
|
421
|
-
// Re-mount on locale switch so the editor re-initializes with
|
|
422
|
-
// the new locale's markdown — `value` is read once on first
|
|
423
|
-
// mount (the underlying BaseMDXEditor seeds its Lexical state
|
|
424
|
-
// from the initial prop and doesn't reactively swap it).
|
|
425
|
-
key={`${id}-${currentLocale}`}
|
|
426
|
-
value={content}
|
|
427
|
-
// Fragment content has no canonical page route, so we
|
|
428
|
-
// synthesize one from the integration's
|
|
429
|
-
// `fragmentPreviewRoute` option (defaults to `/` — see
|
|
430
|
-
// `ConlocaCMSOptions` in `plugin-spa.ts`). The editor
|
|
431
|
-
// then fetches that route's CSS and content-root wrapper
|
|
432
|
-
// the same way it does for pages, so authoring a fragment
|
|
433
|
-
// visually matches the host site instead of falling back
|
|
434
|
-
// to the editor's bare chrome. Per-fragment overrides via
|
|
435
|
-
// frontmatter (`previewRoute`) are on the roadmap for the
|
|
436
|
-
// case where one fragment is tied to a specific layout.
|
|
437
|
-
previewRouteUrl={import.meta.env.CONLOCA_FRAGMENT_PREVIEW_ROUTE || '/'}
|
|
438
|
-
onChange={(next, initialNormalize) => {
|
|
439
|
-
setContent(next);
|
|
440
|
-
// See MdxPageEditor: the library's first onChange call after
|
|
441
|
-
// parse round-trip-rewrites the markdown; rebaseline rather
|
|
442
|
-
// than flag dirty.
|
|
443
|
-
if (initialNormalize) {
|
|
444
|
-
savedContentRef.current = next;
|
|
445
|
-
}
|
|
446
|
-
}}
|
|
447
|
-
onSave={bindSaveShortcut ? persist : undefined}
|
|
448
|
-
className={editorClassName}
|
|
449
|
-
autoFocus
|
|
450
|
-
placeholder="Start writing your fragment…"
|
|
765
|
+
<FragmentEditorHeaderActions
|
|
766
|
+
saveState={saveState}
|
|
767
|
+
isDirty={isDirty}
|
|
768
|
+
saveHidden={hideSave}
|
|
769
|
+
onSave={handleSaveClick}
|
|
451
770
|
/>
|
|
452
771
|
</div>
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
772
|
+
</header>
|
|
773
|
+
<DraftNoticeStrip id={id} locale={currentLocale} />
|
|
774
|
+
<SharedFragmentBanner fromPage={fromPage} />
|
|
775
|
+
<FragmentEditorSurface
|
|
776
|
+
EditorComponent={EditorComponent}
|
|
777
|
+
editorKey={`${id}-${currentLocale}`}
|
|
778
|
+
content={content}
|
|
779
|
+
savedContent={savedContentRef.current}
|
|
780
|
+
resolvedTheme={resolvedTheme}
|
|
781
|
+
previewOpen={previewOpen}
|
|
782
|
+
editorClassName={editorClassName}
|
|
783
|
+
onChange={(next, initialNormalize) => {
|
|
784
|
+
if (!initialNormalize && next !== content) discardedBufferRef.current = null;
|
|
785
|
+
if (!initialNormalize && next !== content && exitIntentRef.current?.kind === 'locale') {
|
|
786
|
+
exitIntentRef.current = null;
|
|
787
|
+
}
|
|
788
|
+
setContent(next);
|
|
789
|
+
// Normalize the initial parse without making the fragment dirty.
|
|
790
|
+
if (initialNormalize) savedContentRef.current = next;
|
|
791
|
+
}}
|
|
792
|
+
onSave={bindSaveShortcut ? saveDraft : undefined}
|
|
793
|
+
/>
|
|
459
794
|
|
|
460
|
-
{
|
|
795
|
+
{showNavigationDialog && (
|
|
461
796
|
<UnsavedChangesDialog
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
// doesn't sit underneath the conflict modal.
|
|
469
|
-
blocker.reset?.();
|
|
470
|
-
}
|
|
797
|
+
backNavigation={isFragmentBackNavigation(blocker, backHref)}
|
|
798
|
+
pending={saveState === 'saving'}
|
|
799
|
+
onSave={handleUnsavedSave}
|
|
800
|
+
onDiscard={() => {
|
|
801
|
+
maskBufferFromHost();
|
|
802
|
+
continueNavigation();
|
|
471
803
|
}}
|
|
472
|
-
|
|
473
|
-
onCancel={() => blocker.reset?.()}
|
|
804
|
+
onCancel={cancelNavigation}
|
|
474
805
|
/>
|
|
475
806
|
)}
|
|
476
807
|
|
|
477
|
-
{showLocaleUnsavedDialog && (
|
|
808
|
+
{showLocaleUnsavedDialog && blocker.state === 'unblocked' && (
|
|
478
809
|
<UnsavedChangesDialog
|
|
479
|
-
|
|
810
|
+
pending={saveState === 'saving'}
|
|
811
|
+
onSave={handleUnsavedSave}
|
|
480
812
|
onDiscard={handleLocaleUnsavedDiscard}
|
|
481
813
|
onCancel={handleLocaleUnsavedCancel}
|
|
482
814
|
/>
|
|
@@ -491,7 +823,7 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
491
823
|
}}
|
|
492
824
|
onForceSave={async (newEtag) => {
|
|
493
825
|
setConflict(null);
|
|
494
|
-
|
|
826
|
+
currentEtagRef.current = newEtag;
|
|
495
827
|
await persist(content, newEtag);
|
|
496
828
|
}}
|
|
497
829
|
onCancel={() => {
|
|
@@ -500,7 +832,361 @@ export function FragmentEditor({ EditorComponent = CMSMDXEditor }: FragmentEdito
|
|
|
500
832
|
}}
|
|
501
833
|
/>
|
|
502
834
|
)}
|
|
503
|
-
<ErrorModal {...errorModalProps} title=
|
|
835
|
+
<ErrorModal {...errorModalProps} title={errorOperation === 'locale' ? 'Locale Switch Failed' : 'Save Failed'} />
|
|
504
836
|
</div>
|
|
505
837
|
);
|
|
506
838
|
}
|
|
839
|
+
|
|
840
|
+
function localeSwitchErrorMessage(isDirty: boolean) {
|
|
841
|
+
return isDirty
|
|
842
|
+
? 'Failed to switch locale. Your changes are still here.'
|
|
843
|
+
: 'Failed to switch locale. Please try again.';
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
function useFragmentLocales() {
|
|
847
|
+
const localeConfig = getUIConfig().locales;
|
|
848
|
+
const { data: sitesConfig } = useSitesConfig();
|
|
849
|
+
const siteDefaultLocale = Object.values(sitesConfig?.sites ?? {})[0]?.defaultLocale;
|
|
850
|
+
const defaultLocale =
|
|
851
|
+
localeConfig?.defaultLocale ?? siteDefaultLocale ?? sitesConfig?.globalLocales[0] ?? (sitesConfig ? 'en' : '');
|
|
852
|
+
const availableLocales = localeConfig?.list?.length
|
|
853
|
+
? localeConfig.list
|
|
854
|
+
: sitesConfig?.globalLocales.length
|
|
855
|
+
? sitesConfig.globalLocales
|
|
856
|
+
: defaultLocale
|
|
857
|
+
? [defaultLocale]
|
|
858
|
+
: [];
|
|
859
|
+
|
|
860
|
+
return { defaultLocale, availableLocales };
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
interface FragmentSaveIdentity {
|
|
864
|
+
id: string | undefined;
|
|
865
|
+
locale: string;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
function useFragmentSaveIdentity(id: string | undefined, currentLocale: string) {
|
|
869
|
+
const saveIdentityRef = useRef<FragmentSaveIdentity>({ id, locale: currentLocale });
|
|
870
|
+
useLayoutEffect(() => {
|
|
871
|
+
// Only committed identity changes invalidate pending replies; suspended renders can be abandoned.
|
|
872
|
+
if (saveIdentityRef.current.id !== id || saveIdentityRef.current.locale !== currentLocale) {
|
|
873
|
+
saveIdentityRef.current = { id, locale: currentLocale };
|
|
874
|
+
}
|
|
875
|
+
}, [id, currentLocale]);
|
|
876
|
+
useEffect(() => {
|
|
877
|
+
// Passive cleanup runs on unmount, while a Suspense hide only disconnects layout effects.
|
|
878
|
+
return () => {
|
|
879
|
+
saveIdentityRef.current = { ...saveIdentityRef.current };
|
|
880
|
+
};
|
|
881
|
+
}, []);
|
|
882
|
+
|
|
883
|
+
return saveIdentityRef;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/** Serialize writes for the committed fragment/locale and share each result with concurrent save callers. */
|
|
887
|
+
function useFragmentSaveQueue(currentIdentity: FragmentSaveIdentity, saveState: SaveState, isDirty: boolean) {
|
|
888
|
+
const pendingRef = useRef<{ identity: FragmentSaveIdentity; promise: Promise<PersistStatus> } | null>(null);
|
|
889
|
+
const save = async (
|
|
890
|
+
identity: FragmentSaveIdentity,
|
|
891
|
+
write: () => Promise<PersistStatus>,
|
|
892
|
+
isCurrent: () => boolean,
|
|
893
|
+
): Promise<PersistStatus> => {
|
|
894
|
+
while (pendingRef.current?.identity === identity) {
|
|
895
|
+
// oxlint-disable-next-line no-await-in-loop -- Wait for this identity's active write before enqueueing another.
|
|
896
|
+
const status = await pendingRef.current.promise;
|
|
897
|
+
if (!isCurrent()) return 'error';
|
|
898
|
+
if (status !== 'saved') return status;
|
|
899
|
+
}
|
|
900
|
+
if (!isCurrent()) return 'error';
|
|
901
|
+
const promise = write().finally(() => {
|
|
902
|
+
if (pendingRef.current?.promise === promise) pendingRef.current = null;
|
|
903
|
+
});
|
|
904
|
+
pendingRef.current = { identity, promise };
|
|
905
|
+
return promise;
|
|
906
|
+
};
|
|
907
|
+
return {
|
|
908
|
+
save,
|
|
909
|
+
pendingRef,
|
|
910
|
+
// The previous baseline cannot make an exit safe while a write for this identity is still settling.
|
|
911
|
+
blocksExit: isDirty || (saveState === 'saving' && pendingRef.current?.identity === currentIdentity),
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
type FragmentExitIntent =
|
|
916
|
+
| { kind: 'navigation' | 'proceeding' | 'cancelled'; blocker: ReturnType<typeof useUnsavedChangesGuard> }
|
|
917
|
+
| { kind: 'locale'; locale: string }
|
|
918
|
+
| null;
|
|
919
|
+
|
|
920
|
+
/** A save completes only the intent still owned by the committed UI; Cancel removes that intent. */
|
|
921
|
+
function useFragmentExit({
|
|
922
|
+
routeIdentityChanged,
|
|
923
|
+
isDirty,
|
|
924
|
+
saveState,
|
|
925
|
+
blocker,
|
|
926
|
+
onLocaleContinue,
|
|
927
|
+
onLocaleCancel,
|
|
928
|
+
}: {
|
|
929
|
+
routeIdentityChanged: boolean;
|
|
930
|
+
isDirty: boolean;
|
|
931
|
+
saveState: SaveState;
|
|
932
|
+
blocker: ReturnType<typeof useUnsavedChangesGuard>;
|
|
933
|
+
onLocaleContinue: () => Promise<void>;
|
|
934
|
+
onLocaleCancel: () => void;
|
|
935
|
+
}) {
|
|
936
|
+
const intentRef = useRef<FragmentExitIntent>(null);
|
|
937
|
+
const [dismissedBlocker, setDismissedBlocker] = useState<typeof blocker | null>(null);
|
|
938
|
+
|
|
939
|
+
const navigationConsumed = useCallback(
|
|
940
|
+
() =>
|
|
941
|
+
intentRef.current?.kind !== 'locale' &&
|
|
942
|
+
intentRef.current?.blocker === blocker &&
|
|
943
|
+
(intentRef.current.kind === 'proceeding' || intentRef.current.kind === 'cancelled'),
|
|
944
|
+
[blocker],
|
|
945
|
+
);
|
|
946
|
+
|
|
947
|
+
const continueNavigation = useCallback(() => {
|
|
948
|
+
if (blocker.state !== 'blocked' || navigationConsumed()) return;
|
|
949
|
+
intentRef.current = { kind: 'proceeding', blocker };
|
|
950
|
+
setDismissedBlocker(blocker);
|
|
951
|
+
onLocaleCancel();
|
|
952
|
+
blocker.proceed();
|
|
953
|
+
}, [blocker, navigationConsumed, onLocaleCancel]);
|
|
954
|
+
|
|
955
|
+
const cancelNavigation = useCallback(() => {
|
|
956
|
+
if (blocker.state !== 'blocked' || navigationConsumed()) return;
|
|
957
|
+
// RouterProvider commits reset in a transition; revoke ownership before that render can suspend.
|
|
958
|
+
intentRef.current = { kind: 'cancelled', blocker };
|
|
959
|
+
setDismissedBlocker(blocker);
|
|
960
|
+
blocker.reset();
|
|
961
|
+
}, [blocker, navigationConsumed]);
|
|
962
|
+
|
|
963
|
+
useEffect(() => {
|
|
964
|
+
if (routeIdentityChanged || saveState === 'conflict') {
|
|
965
|
+
// Conflict consumes a pending navigation through the same synchronous owner as Cancel.
|
|
966
|
+
cancelNavigation();
|
|
967
|
+
onLocaleCancel();
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
if (blocker.state !== 'unblocked') {
|
|
971
|
+
onLocaleCancel();
|
|
972
|
+
if (blocker.state !== 'blocked') return;
|
|
973
|
+
if (navigationConsumed()) return;
|
|
974
|
+
intentRef.current = { kind: 'navigation', blocker };
|
|
975
|
+
if (isDirty || saveState === 'saving') return;
|
|
976
|
+
continueNavigation();
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
if (intentRef.current?.kind !== 'locale') intentRef.current = null;
|
|
980
|
+
if (!isDirty && saveState !== 'saving') void onLocaleContinue();
|
|
981
|
+
}, [
|
|
982
|
+
routeIdentityChanged,
|
|
983
|
+
isDirty,
|
|
984
|
+
saveState,
|
|
985
|
+
blocker,
|
|
986
|
+
onLocaleContinue,
|
|
987
|
+
onLocaleCancel,
|
|
988
|
+
navigationConsumed,
|
|
989
|
+
continueNavigation,
|
|
990
|
+
cancelNavigation,
|
|
991
|
+
]);
|
|
992
|
+
return {
|
|
993
|
+
intentRef,
|
|
994
|
+
showNavigationDialog: blocker.state === 'blocked' && dismissedBlocker !== blocker,
|
|
995
|
+
continueNavigation,
|
|
996
|
+
cancelNavigation,
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function FragmentLoading({
|
|
1001
|
+
waitingForSave,
|
|
1002
|
+
waitError,
|
|
1003
|
+
onRetry,
|
|
1004
|
+
backLabel,
|
|
1005
|
+
onBack,
|
|
1006
|
+
}: {
|
|
1007
|
+
waitingForSave: boolean;
|
|
1008
|
+
waitError: string | undefined;
|
|
1009
|
+
onRetry: () => void;
|
|
1010
|
+
backLabel: string;
|
|
1011
|
+
onBack: () => void;
|
|
1012
|
+
}) {
|
|
1013
|
+
return (
|
|
1014
|
+
<div className={cn('flex flex-col items-center justify-center h-full bg-page gap-4')}>
|
|
1015
|
+
{waitError ? (
|
|
1016
|
+
<>
|
|
1017
|
+
<p className={cn('px-4 text-center text-muted')} role="alert">
|
|
1018
|
+
{waitError}
|
|
1019
|
+
</p>
|
|
1020
|
+
<button
|
|
1021
|
+
type="button"
|
|
1022
|
+
onClick={onRetry}
|
|
1023
|
+
className={cn('px-4 py-2 bg-azure-04 text-white rounded-md hover:bg-azure-03 transition-colors')}
|
|
1024
|
+
>
|
|
1025
|
+
Retry
|
|
1026
|
+
</button>
|
|
1027
|
+
</>
|
|
1028
|
+
) : (
|
|
1029
|
+
<div className={cn('flex items-center gap-3 text-muted')} role="status">
|
|
1030
|
+
<div className={cn('animate-spin rounded-full h-6 w-6 border-b-2 border-azure-04')} />
|
|
1031
|
+
<span>{waitingForSave ? 'Finishing previous save…' : 'Loading fragment…'}</span>
|
|
1032
|
+
</div>
|
|
1033
|
+
)}
|
|
1034
|
+
{waitingForSave && (
|
|
1035
|
+
<button
|
|
1036
|
+
type="button"
|
|
1037
|
+
onClick={onBack}
|
|
1038
|
+
className={cn(
|
|
1039
|
+
'px-4 py-2 text-muted rounded-md hover:bg-hover focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 transition-colors',
|
|
1040
|
+
)}
|
|
1041
|
+
>
|
|
1042
|
+
{backLabel}
|
|
1043
|
+
</button>
|
|
1044
|
+
)}
|
|
1045
|
+
</div>
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
type FragmentLoad = ReturnType<typeof useFragmentContent>;
|
|
1050
|
+
|
|
1051
|
+
function fragmentLoadFailed({
|
|
1052
|
+
routeIdentityChanged,
|
|
1053
|
+
currentLocale,
|
|
1054
|
+
error,
|
|
1055
|
+
isLoading,
|
|
1056
|
+
loadedContent,
|
|
1057
|
+
savedContent,
|
|
1058
|
+
}: {
|
|
1059
|
+
routeIdentityChanged: boolean;
|
|
1060
|
+
currentLocale: string;
|
|
1061
|
+
error: FragmentLoad['error'];
|
|
1062
|
+
isLoading: boolean;
|
|
1063
|
+
loadedContent: FragmentLoad['data'];
|
|
1064
|
+
savedContent: string;
|
|
1065
|
+
}) {
|
|
1066
|
+
return !routeIdentityChanged && currentLocale && (error || !isLoading) && !loadedContent && !savedContent;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
function fragmentDisplayName(loadedContent: FragmentLoad['data'], id: string | undefined) {
|
|
1070
|
+
return loadedContent?.localized?.name || id || 'fragment';
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
function SharedFragmentBanner({ fromPage, live = false }: { fromPage: boolean; live?: boolean }) {
|
|
1074
|
+
return (
|
|
1075
|
+
fromPage && (
|
|
1076
|
+
<div
|
|
1077
|
+
className="flex items-start gap-2 px-4 py-2 border-b border-yellow-08 dark:border-yellow-03 bg-yellow-11 dark:bg-yellow-02 text-sm text-yellow-02 dark:text-yellow-09 shrink-0"
|
|
1078
|
+
role="status"
|
|
1079
|
+
data-testid="shared-fragment-banner"
|
|
1080
|
+
>
|
|
1081
|
+
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0" />
|
|
1082
|
+
<span>
|
|
1083
|
+
{live
|
|
1084
|
+
? 'This is a shared fragment. Your changes reach every page that uses it.'
|
|
1085
|
+
: 'This is a shared fragment. Saving updates every page that uses it.'}
|
|
1086
|
+
</span>
|
|
1087
|
+
</div>
|
|
1088
|
+
)
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
interface FragmentEditorSurfaceProps {
|
|
1093
|
+
EditorComponent: ElementType<CMSMDXEditorProps>;
|
|
1094
|
+
editorKey: string;
|
|
1095
|
+
content: string;
|
|
1096
|
+
savedContent: string;
|
|
1097
|
+
resolvedTheme: ReturnType<typeof useTheme>['resolvedTheme'];
|
|
1098
|
+
previewOpen: boolean;
|
|
1099
|
+
editorClassName: string | undefined;
|
|
1100
|
+
onChange: CMSMDXEditorProps['onChange'];
|
|
1101
|
+
onSave: CMSMDXEditorProps['onSave'];
|
|
1102
|
+
/** What the live preview renders; `content` by default. */
|
|
1103
|
+
preview?: string;
|
|
1104
|
+
extraPlugins?: CMSMDXEditorProps['extraPlugins'];
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function FragmentEditorSurface({
|
|
1108
|
+
EditorComponent,
|
|
1109
|
+
editorKey,
|
|
1110
|
+
content,
|
|
1111
|
+
savedContent,
|
|
1112
|
+
resolvedTheme,
|
|
1113
|
+
previewOpen,
|
|
1114
|
+
editorClassName,
|
|
1115
|
+
onChange,
|
|
1116
|
+
onSave,
|
|
1117
|
+
preview = content,
|
|
1118
|
+
extraPlugins,
|
|
1119
|
+
}: FragmentEditorSurfaceProps) {
|
|
1120
|
+
// The props panel reads a selection shared across editors; a block from another or a disposed editor must not show.
|
|
1121
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: clear again when the editor remounts under a new key.
|
|
1122
|
+
useEffect(() => {
|
|
1123
|
+
setSelectedBlock(null);
|
|
1124
|
+
return () => setSelectedBlock(null);
|
|
1125
|
+
}, [editorKey]);
|
|
1126
|
+
return (
|
|
1127
|
+
<div className="flex-1 overflow-hidden flex flex-row min-h-0">
|
|
1128
|
+
{/* `conloca-mdx-editor-surround` paints the area around the
|
|
1129
|
+
prose card with the host site's body bg (via the
|
|
1130
|
+
`--conloca-host-body-bg` bridge in site-styles). Same class
|
|
1131
|
+
MdxPageEditor uses — the two surfaces now share the
|
|
1132
|
+
surround treatment so a fragment visually matches the page
|
|
1133
|
+
it'll ultimately appear in. */}
|
|
1134
|
+
<div
|
|
1135
|
+
className={`flex-1 min-w-0 overflow-hidden conloca-mdx-editor-surround${resolvedTheme === 'dark' ? ' dark' : ''}`}
|
|
1136
|
+
data-theme={resolvedTheme}
|
|
1137
|
+
>
|
|
1138
|
+
<EditorComponent
|
|
1139
|
+
// Re-mount on locale switch so the editor re-initializes with
|
|
1140
|
+
// the new locale's markdown — `value` is read once on first
|
|
1141
|
+
// mount (the underlying BaseMDXEditor seeds its Lexical state
|
|
1142
|
+
// from the initial prop and doesn't reactively swap it).
|
|
1143
|
+
key={editorKey}
|
|
1144
|
+
value={content}
|
|
1145
|
+
fragment
|
|
1146
|
+
// Fragment content has no canonical page route, so we
|
|
1147
|
+
// synthesize one from the integration's
|
|
1148
|
+
// `fragmentPreviewRoute` option (defaults to `/` — see
|
|
1149
|
+
// `ConlocaCMSOptions` in `plugin-spa.ts`). The editor
|
|
1150
|
+
// then fetches that route's CSS and content-root wrapper
|
|
1151
|
+
// the same way it does for pages, so authoring a fragment
|
|
1152
|
+
// visually matches the host site instead of falling back
|
|
1153
|
+
// to the editor's bare chrome. Per-fragment overrides via
|
|
1154
|
+
// frontmatter (`previewRoute`) are on the roadmap for the
|
|
1155
|
+
// case where one fragment is tied to a specific layout.
|
|
1156
|
+
diffMarkdown={savedContent}
|
|
1157
|
+
previewRouteUrl={fragmentPreviewPathname()}
|
|
1158
|
+
onChange={onChange}
|
|
1159
|
+
onSave={onSave}
|
|
1160
|
+
extraPlugins={extraPlugins}
|
|
1161
|
+
className={editorClassName}
|
|
1162
|
+
autoFocus
|
|
1163
|
+
placeholder="Start writing your fragment…"
|
|
1164
|
+
/>
|
|
1165
|
+
</div>
|
|
1166
|
+
<JsxPropsPanel />
|
|
1167
|
+
{previewOpen && (
|
|
1168
|
+
<div className="w-1/2 min-w-0 overflow-auto border-l border-line bg-panel">
|
|
1169
|
+
<MDXLivePreview markdown={preview} />
|
|
1170
|
+
</div>
|
|
1171
|
+
)}
|
|
1172
|
+
</div>
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
function isFragmentBackNavigation(blocker: ReturnType<typeof useUnsavedChangesGuard>, backHref: string) {
|
|
1177
|
+
const blockedPath = blocker.location?.pathname;
|
|
1178
|
+
const targetPath = parsePath(backHref).pathname;
|
|
1179
|
+
if (!blockedPath || !targetPath) return false;
|
|
1180
|
+
// Browser history percent-encodes Unicode; memory history may keep the same path literal.
|
|
1181
|
+
const pathBase = 'http://localhost';
|
|
1182
|
+
return new URL(blockedPath, pathBase).pathname === new URL(targetPath, pathBase).pathname;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function fragmentOrigin(searchParams: URLSearchParams) {
|
|
1186
|
+
const fromPage = searchParams.get('from') === 'page';
|
|
1187
|
+
const returnPageId = searchParams.get('pageId') || '';
|
|
1188
|
+
const returnsToPage = fromPage && returnPageId !== '';
|
|
1189
|
+
const backTarget = returnsToPage ? `/pages/${encodeURIComponent(returnPageId)}` : '/fragments';
|
|
1190
|
+
const backLabel = returnsToPage ? 'Back to page' : 'Back to fragments';
|
|
1191
|
+
return { fromPage, backTarget, backLabel };
|
|
1192
|
+
}
|