@columnus/sdk 0.0.0-stage → 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/blocknote-editor-547WFBXP.js +7 -0
- package/dist/blocknote-editor-547WFBXP.js.map +1 -0
- package/dist/blocknote-editor-YZEFMXLC.css +47 -0
- package/dist/blocknote-editor-YZEFMXLC.css.map +1 -0
- package/dist/blocknote-preview-6WRENQZD.css +47 -0
- package/dist/blocknote-preview-6WRENQZD.css.map +1 -0
- package/dist/blocknote-preview-CTMNUSYX.js +7 -0
- package/dist/blocknote-preview-CTMNUSYX.js.map +1 -0
- package/dist/chunk-5IPH2A64.js +23337 -0
- package/dist/chunk-5IPH2A64.js.map +1 -0
- package/dist/chunk-BQCD5MEV.js +225 -0
- package/dist/chunk-BQCD5MEV.js.map +1 -0
- package/dist/chunk-BXTTCBIK.js +11 -0
- package/dist/chunk-BXTTCBIK.js.map +1 -0
- package/dist/chunk-ICKWVUW7.js +134 -0
- package/dist/chunk-ICKWVUW7.js.map +1 -0
- package/dist/chunk-IMYSQX2X.js +58 -0
- package/dist/chunk-IMYSQX2X.js.map +1 -0
- package/dist/chunk-JYSABU33.js +494 -0
- package/dist/chunk-JYSABU33.js.map +1 -0
- package/dist/chunk-PX6F3LHL.js +37 -0
- package/dist/chunk-PX6F3LHL.js.map +1 -0
- package/dist/chunk-QPQRNIKG.js +142 -0
- package/dist/chunk-QPQRNIKG.js.map +1 -0
- package/dist/chunk-SKE2RDD2.js +4217 -0
- package/dist/chunk-SKE2RDD2.js.map +1 -0
- package/dist/chunk-XWMTXQF3.js +18727 -0
- package/dist/chunk-XWMTXQF3.js.map +1 -0
- package/dist/chunk-ZTWPGA37.js +68 -0
- package/dist/chunk-ZTWPGA37.js.map +1 -0
- package/dist/cms/builder/diff-view.js +70 -0
- package/dist/cms/builder/diff-view.js.map +1 -0
- package/dist/cms/builder/panel.js +1316 -0
- package/dist/cms/builder/panel.js.map +1 -0
- package/dist/cms/convex/index.css +47 -0
- package/dist/cms/convex/index.css.map +1 -0
- package/dist/cms/convex/index.js +370 -0
- package/dist/cms/convex/index.js.map +1 -0
- package/dist/cms/index.css +47 -0
- package/dist/cms/index.css.map +1 -0
- package/dist/cms/index.js +9 -0
- package/dist/cms/index.js.map +1 -0
- package/dist/cms/server/index.js +5 -0
- package/dist/cms/server/index.js.map +1 -0
- package/dist/cms/tables/tables-dialog.css +47 -0
- package/dist/cms/tables/tables-dialog.css.map +1 -0
- package/dist/cms/tables/tables-dialog.js +590 -0
- package/dist/cms/tables/tables-dialog.js.map +1 -0
- package/dist/cms/tailwind.css +4 -0
- package/dist/editor-543ARQ6S.js +427 -0
- package/dist/editor-543ARQ6S.js.map +1 -0
- package/dist/editor-54UG7BSP.css +47 -0
- package/dist/editor-54UG7BSP.css.map +1 -0
- package/dist/mcp-cli.js +61218 -0
- package/dist/primitives.css +143 -0
- package/dist/rich-text-editor/blocknote-preview-studio.css +54 -0
- package/dist/richtext.css +4 -0
- package/dist/types/cms/src/adapters/default-richtext.d.ts +24 -0
- package/dist/types/cms/src/adapters/projected-fields-adapter.d.ts +22 -0
- package/dist/types/cms/src/adapters/table-rows-context.d.ts +4 -0
- package/dist/types/cms/src/adapters/table-rows-richtext.d.ts +8 -0
- package/dist/types/cms/src/builder/annotate.d.ts +13 -0
- package/dist/types/cms/src/builder/diff-view.d.ts +10 -0
- package/dist/types/cms/src/builder/inspect.d.ts +32 -0
- package/dist/types/cms/src/builder/panel.d.ts +11 -0
- package/dist/types/cms/src/builder/sessions-menu.d.ts +37 -0
- package/dist/types/cms/src/builder/sidecar-json.d.ts +2 -0
- package/dist/types/cms/src/cache/html-cache.d.ts +12 -0
- package/dist/types/cms/src/chrome/changes-view.d.ts +15 -0
- package/dist/types/cms/src/chrome/confirm-panel.d.ts +10 -0
- package/dist/types/cms/src/chrome/floating-toolbar.d.ts +25 -0
- package/dist/types/cms/src/chrome/icons.d.ts +13 -0
- package/dist/types/cms/src/chrome/overlay-styles.d.ts +38 -0
- package/dist/types/cms/src/chrome/resolve-dialog.d.ts +26 -0
- package/dist/types/cms/src/chrome/session-storage.d.ts +3 -0
- package/dist/types/cms/src/convex/cms-convex-proposals.d.ts +19 -0
- package/dist/types/cms/src/convex/cms-convex-shell.d.ts +8 -0
- package/dist/types/cms/src/convex/cms-host-refs.d.ts +15 -0
- package/dist/types/cms/src/convex/index.d.ts +7 -0
- package/dist/types/cms/src/convex/proposal-refs.d.ts +20 -0
- package/dist/types/cms/src/convex/use-cms-display-fields-adapter.d.ts +17 -0
- package/dist/types/cms/src/convex/use-cms-display-values.d.ts +12 -0
- package/dist/types/cms/src/convex/use-cms-editor-auth.d.ts +12 -0
- package/dist/types/cms/src/convex/use-cms-storage-display.d.ts +19 -0
- package/dist/types/cms/src/convex/use-cms-storage-fields-adapter.d.ts +63 -0
- package/dist/types/cms/src/convex/use-fields-adapter-host.d.ts +4 -0
- package/dist/types/cms/src/create/compound-create.d.ts +56 -0
- package/dist/types/cms/src/draft/merge-draft.d.ts +31 -0
- package/dist/types/cms/src/edit/cms-compound-create.d.ts +12 -0
- package/dist/types/cms/src/edit/cms-create-button.d.ts +9 -0
- package/dist/types/cms/src/edit/edit-surface.d.ts +16 -0
- package/dist/types/cms/src/edit/field-editor-dialog.d.ts +22 -0
- package/dist/types/cms/src/edit/inplace-field-editor.d.ts +21 -0
- package/dist/types/cms/src/edit/inplace-switch-modal.d.ts +5 -0
- package/dist/types/cms/src/edit/insert-row-dialog.d.ts +20 -0
- package/dist/types/cms/src/index.d.ts +35 -0
- package/dist/types/cms/src/list/build-insert-draft.d.ts +13 -0
- package/dist/types/cms/src/manifest-index.d.ts +5 -0
- package/dist/types/cms/src/nav/content-ref-integrity.d.ts +18 -0
- package/dist/types/cms/src/nav/content-ref.d.ts +6 -0
- package/dist/types/cms/src/nav/infer-navigation-table.d.ts +20 -0
- package/dist/types/cms/src/nav/slugify-de.d.ts +4 -0
- package/dist/types/cms/src/pages/login-page.d.ts +5 -0
- package/dist/types/cms/src/profile/propose-gates.d.ts +12 -0
- package/dist/types/cms/src/profile/readable-tables.d.ts +13 -0
- package/dist/types/cms/src/projection/cms-projection.d.ts +63 -0
- package/dist/types/cms/src/proposals/types.d.ts +59 -0
- package/dist/types/cms/src/provider/builder-draft.d.ts +14 -0
- package/dist/types/cms/src/provider/cms-provider.d.ts +240 -0
- package/dist/types/cms/src/rich-doc/cms-rich-doc-view.d.ts +4 -0
- package/dist/types/cms/src/server/cookie.d.ts +11 -0
- package/dist/types/cms/src/server/index.d.ts +2 -0
- package/dist/types/cms/src/server/session.d.ts +53 -0
- package/dist/types/cms/src/stamps/attrs.d.ts +17 -0
- package/dist/types/cms/src/stamps/related.d.ts +11 -0
- package/dist/types/cms/src/stamps/resolve-display.d.ts +41 -0
- package/dist/types/cms/src/stamps/row.d.ts +41 -0
- package/dist/types/cms/src/stamps/stamp-media-drop.d.ts +23 -0
- package/dist/types/cms/src/stamps/stamp.d.ts +44 -0
- package/dist/types/cms/src/stamps/storage-display.d.ts +4 -0
- package/dist/types/cms/src/stamps/use-cms-projected-field.d.ts +6 -0
- package/dist/types/cms/src/stamps/use-cms-projected-table.d.ts +7 -0
- package/dist/types/cms/src/stamps/use-cms-related-row.d.ts +2 -0
- package/dist/types/cms/src/tables/tables-dialog.d.ts +6 -0
- package/dist/types/cms/src/tables/use-cms-grid.d.ts +78 -0
- package/dist/types/cms/src/tables/use-draft-commands.d.ts +35 -0
- package/dist/types/data-grid/src/components/balanced-preview-columns.d.ts +7 -0
- package/dist/types/data-grid/src/components/cell-formula-bar.d.ts +40 -0
- package/dist/types/data-grid/src/components/cell-renderer.d.ts +10 -0
- package/dist/types/data-grid/src/components/cell-selection.d.ts +72 -0
- package/dist/types/data-grid/src/components/column-filter-popover.d.ts +29 -0
- package/dist/types/data-grid/src/components/context-menu-selection.d.ts +24 -0
- package/dist/types/data-grid/src/components/data-grid-table.d.ts +49 -0
- package/dist/types/data-grid/src/components/delete-confirm-copy.d.ts +6 -0
- package/dist/types/data-grid/src/components/display-search-scope-notice.d.ts +4 -0
- package/dist/types/data-grid/src/components/draft-rows.d.ts +14 -0
- package/dist/types/data-grid/src/components/field-condition-editor.d.ts +71 -0
- package/dist/types/data-grid/src/components/fill-handle.d.ts +22 -0
- package/dist/types/data-grid/src/components/grid-action-bar.d.ts +8 -0
- package/dist/types/data-grid/src/components/grid-body-layout.d.ts +27 -0
- package/dist/types/data-grid/src/components/grid-body-row.d.ts +83 -0
- package/dist/types/data-grid/src/components/grid-editing.d.ts +158 -0
- package/dist/types/data-grid/src/components/grid-event-utils.d.ts +10 -0
- package/dist/types/data-grid/src/components/grid-filter-search-chips.d.ts +7 -0
- package/dist/types/data-grid/src/components/grid-filter-search-context.d.ts +135 -0
- package/dist/types/data-grid/src/components/grid-filter-search.d.ts +6 -0
- package/dist/types/data-grid/src/components/grid-row-menu.d.ts +23 -0
- package/dist/types/data-grid/src/components/grid-seam-island.d.ts +23 -0
- package/dist/types/data-grid/src/components/grid-sort-group.d.ts +25 -0
- package/dist/types/data-grid/src/components/grid-toolbar.d.ts +54 -0
- package/dist/types/data-grid/src/components/index-suggestion-banner.d.ts +11 -0
- package/dist/types/data-grid/src/components/inline-edit-draft.d.ts +18 -0
- package/dist/types/data-grid/src/components/keyboard-shortcuts-overlay.d.ts +7 -0
- package/dist/types/data-grid/src/components/measure-column-auto-width.d.ts +6 -0
- package/dist/types/data-grid/src/components/pending-edits.d.ts +25 -0
- package/dist/types/data-grid/src/components/perform-grid-row-delete.d.ts +27 -0
- package/dist/types/data-grid/src/components/query-plan-banner.d.ts +13 -0
- package/dist/types/data-grid/src/components/query-predicate-builder.d.ts +53 -0
- package/dist/types/data-grid/src/components/row-detail-dialog.d.ts +17 -0
- package/dist/types/data-grid/src/components/row-preview-content.d.ts +21 -0
- package/dist/types/data-grid/src/components/row-preview-drawer.d.ts +24 -0
- package/dist/types/data-grid/src/components/selection-value-chips.d.ts +12 -0
- package/dist/types/data-grid/src/components/selection.d.ts +46 -0
- package/dist/types/data-grid/src/components/table-cell-overlays.d.ts +33 -0
- package/dist/types/data-grid/src/components/table-color-marker.d.ts +10 -0
- package/dist/types/data-grid/src/components/use-column-visibility.d.ts +5 -0
- package/dist/types/data-grid/src/components/use-column-widths.d.ts +6 -0
- package/dist/types/data-grid/src/components/use-undo-redo.d.ts +46 -0
- package/dist/types/data-grid/src/hooks/plan-pending-edits.d.ts +41 -0
- package/dist/types/data-grid/src/hooks/use-grid-interactions.d.ts +100 -0
- package/dist/types/data-grid/src/hooks/use-grid-pending-state.d.ts +41 -0
- package/dist/types/data-grid/src/hooks/use-grid-selection-model.d.ts +28 -0
- package/dist/types/data-grid/src/hooks/use-grid-table-layout.d.ts +39 -0
- package/dist/types/data-grid/src/hooks/use-true-after-delay.d.ts +10 -0
- package/dist/types/data-grid/src/index.d.ts +47 -0
- package/dist/types/data-grid/src/lib/column-filter.d.ts +43 -0
- package/dist/types/data-grid/src/lib/display-search-scope.d.ts +2 -0
- package/dist/types/data-grid/src/lib/format-query-chips.d.ts +28 -0
- package/dist/types/data-grid/src/lib/grid-items.d.ts +63 -0
- package/dist/types/data-grid/src/lib/persistent-state.d.ts +6 -0
- package/dist/types/data-grid/src/lib/query-editor-draft.d.ts +15 -0
- package/dist/types/data-grid/src/lib/use-row-preview-collapsed.d.ts +9 -0
- package/dist/types/data-grid/src/lib/use-row-preview-title.d.ts +1 -0
- package/dist/types/fields/src/components/batch-edit-sheet.d.ts +10 -0
- package/dist/types/fields/src/components/cell-editor.d.ts +29 -0
- package/dist/types/fields/src/components/date-time-input.d.ts +21 -0
- package/dist/types/fields/src/components/date-time-picker-logic.d.ts +13 -0
- package/dist/types/fields/src/components/field-input-chrome.d.ts +11 -0
- package/dist/types/fields/src/components/field-input-inline.d.ts +30 -0
- package/dist/types/fields/src/components/field-input.d.ts +36 -0
- package/dist/types/fields/src/components/field-value-view.d.ts +10 -0
- package/dist/types/fields/src/components/file-array-cell.d.ts +5 -0
- package/dist/types/fields/src/components/file-array-upload-dialog.d.ts +19 -0
- package/dist/types/fields/src/components/file-cell.d.ts +5 -0
- package/dist/types/fields/src/components/file-input.d.ts +21 -0
- package/dist/types/fields/src/components/file-upload-dialog.d.ts +19 -0
- package/dist/types/fields/src/components/focus-text-input.d.ts +5 -0
- package/dist/types/fields/src/components/id-array-cell.d.ts +9 -0
- package/dist/types/fields/src/components/id-array-values.d.ts +1 -0
- package/dist/types/fields/src/components/id-cell.d.ts +4 -0
- package/dist/types/fields/src/components/id-picker.d.ts +28 -0
- package/dist/types/fields/src/components/image-array-cell.d.ts +7 -0
- package/dist/types/fields/src/components/image-cell.d.ts +7 -0
- package/dist/types/fields/src/components/image-preview-dialog.d.ts +8 -0
- package/dist/types/fields/src/components/media-compact-preview.d.ts +17 -0
- package/dist/types/fields/src/components/media-library-picker-dialog.d.ts +16 -0
- package/dist/types/fields/src/components/multi-id-picker.d.ts +24 -0
- package/dist/types/fields/src/components/picker-chrome.d.ts +28 -0
- package/dist/types/fields/src/components/picker-density.d.ts +5 -0
- package/dist/types/fields/src/components/picker-list-placeholder.d.ts +13 -0
- package/dist/types/fields/src/components/picker-menu-keyboard.d.ts +16 -0
- package/dist/types/fields/src/components/picker-menu-layout.d.ts +12 -0
- package/dist/types/fields/src/components/picker-menu-portal.d.ts +19 -0
- package/dist/types/fields/src/components/picker-option-row.d.ts +10 -0
- package/dist/types/fields/src/components/picker-overlay.d.ts +35 -0
- package/dist/types/fields/src/components/record-link-chip.d.ts +21 -0
- package/dist/types/fields/src/components/row-edit-panel.d.ts +36 -0
- package/dist/types/fields/src/components/row-editor.d.ts +19 -0
- package/dist/types/fields/src/components/row-popover.d.ts +11 -0
- package/dist/types/fields/src/components/use-flush-ref.d.ts +3 -0
- package/dist/types/fields/src/components/use-picker-combobox.d.ts +86 -0
- package/dist/types/fields/src/components/use-picker-highlight-scroll.d.ts +4 -0
- package/dist/types/fields/src/components/use-picker-menu-overlay.d.ts +7 -0
- package/dist/types/fields/src/fields-data-adapter.d.ts +111 -0
- package/dist/types/fields/src/fields-data-provider.d.ts +45 -0
- package/dist/types/fields/src/hooks/use-debounced-value.d.ts +1 -0
- package/dist/types/fields/src/hooks/use-row-edit-shortcuts.d.ts +15 -0
- package/dist/types/fields/src/index.d.ts +38 -0
- package/dist/types/fields/src/lib/is-row-doc-dirty.d.ts +2 -0
- package/dist/types/fields/src/lib/scroll-to-form-field.d.ts +6 -0
- package/dist/types/fields/src/media-library-query.d.ts +34 -0
- package/dist/types/fields/src/media-upload-limits.d.ts +18 -0
- package/dist/types/fields/src/record-actions-context.d.ts +17 -0
- package/dist/types/fields/src/storage-upload.d.ts +21 -0
- package/dist/types/primitives/src/components/ui/accordion.d.ts +6 -0
- package/dist/types/primitives/src/components/ui/alert-dialog.d.ts +12 -0
- package/dist/types/primitives/src/components/ui/badge.d.ts +9 -0
- package/dist/types/primitives/src/components/ui/button.d.ts +11 -0
- package/dist/types/primitives/src/components/ui/calendar.d.ts +8 -0
- package/dist/types/primitives/src/components/ui/card.d.ts +7 -0
- package/dist/types/primitives/src/components/ui/checkbox.d.ts +3 -0
- package/dist/types/primitives/src/components/ui/dialog.d.ts +15 -0
- package/dist/types/primitives/src/components/ui/dropdown-menu.d.ts +10 -0
- package/dist/types/primitives/src/components/ui/info-hint.d.ts +37 -0
- package/dist/types/primitives/src/components/ui/input.d.ts +2 -0
- package/dist/types/primitives/src/components/ui/label.d.ts +3 -0
- package/dist/types/primitives/src/components/ui/popover.d.ts +6 -0
- package/dist/types/primitives/src/components/ui/save-bar.d.ts +43 -0
- package/dist/types/primitives/src/components/ui/select.d.ts +8 -0
- package/dist/types/primitives/src/components/ui/separator.d.ts +3 -0
- package/dist/types/primitives/src/components/ui/sheet.d.ts +18 -0
- package/dist/types/primitives/src/components/ui/sonner.d.ts +1 -0
- package/dist/types/primitives/src/components/ui/switch.d.ts +3 -0
- package/dist/types/primitives/src/components/ui/table.d.ts +7 -0
- package/dist/types/primitives/src/components/ui/tabs.d.ts +6 -0
- package/dist/types/primitives/src/components/ui/tooltip.d.ts +6 -0
- package/dist/types/primitives/src/index.d.ts +28 -0
- package/dist/types/primitives/src/lib/animation-frame-batcher.d.ts +11 -0
- package/dist/types/primitives/src/lib/locale-week-start.d.ts +5 -0
- package/dist/types/primitives/src/lib/save-bar-logic.d.ts +52 -0
- package/dist/types/primitives/src/lib/use-raf-batched-pointer-drag.d.ts +31 -0
- package/dist/types/primitives/src/lib/use-save-bar.d.ts +36 -0
- package/dist/types/primitives/src/lib/use-unsaved-changes-guard.d.ts +15 -0
- package/dist/types/primitives/src/lib/utils.d.ts +6 -0
- package/dist/types/richtext/src/editor.d.ts +16 -0
- package/dist/types/richtext/src/host-adapter.d.ts +66 -0
- package/dist/types/richtext/src/index.d.ts +11 -0
- package/dist/types/richtext/src/markdown-editor/editor-styles.d.ts +7 -0
- package/dist/types/richtext/src/markdown-editor/markdown-editor-dialog.d.ts +16 -0
- package/dist/types/richtext/src/markdown-editor/markdown-editor.d.ts +2 -0
- package/dist/types/richtext/src/markdown-editor/markdown-field-input.d.ts +11 -0
- package/dist/types/richtext/src/markdown-editor/markdown-field-trigger.d.ts +8 -0
- package/dist/types/richtext/src/markdown-editor/markdown-insert-pickers-session.d.ts +5 -0
- package/dist/types/richtext/src/markdown-editor/markdown-insert-pickers.d.ts +9 -0
- package/dist/types/richtext/src/markdown-editor/markdown-preview.d.ts +7 -0
- package/dist/types/richtext/src/markdown-editor/markdown-rich-preview.d.ts +5 -0
- package/dist/types/richtext/src/markdown-editor/record-link-picker-session.d.ts +7 -0
- package/dist/types/richtext/src/markdown-editor/record-link-picker.d.ts +9 -0
- package/dist/types/richtext/src/markdown-editor/record-table-picker.d.ts +21 -0
- package/dist/types/richtext/src/markdown-editor/use-markdown-insert-pickers.d.ts +33 -0
- package/dist/types/richtext/src/record-table-view.d.ts +17 -0
- package/dist/types/richtext/src/rich-doc-view.d.ts +30 -0
- package/dist/types/richtext/src/rich-text-editor/blocknote-editor.d.ts +25 -0
- package/dist/types/richtext/src/rich-text-editor/blocknote-portaled-dropdown.d.ts +2 -0
- package/dist/types/richtext/src/rich-text-editor/blocknote-preview.d.ts +12 -0
- package/dist/types/richtext/src/rich-text-editor/record-link-inline.d.ts +15 -0
- package/dist/types/richtext/src/rich-text-editor/record-link-rows-context.d.ts +9 -0
- package/dist/types/richtext/src/rich-text-editor/record-table-block.d.ts +18 -0
- package/dist/types/richtext/src/rich-text-editor/studio-schema.d.ts +283 -0
- package/dist/types/richtext/src/rich-text-editor/studio-slash-menu.d.ts +8 -0
- package/dist/types/richtext/src/rich-text-editor/use-sync-blocknote-value.d.ts +2 -0
- package/dist/types/shared/src/apiProfile.d.ts +164 -0
- package/dist/types/shared/src/apiProfileDiscovery.d.ts +88 -0
- package/dist/types/shared/src/apiProfileSlug.d.ts +11 -0
- package/dist/types/shared/src/apiProfileSources.d.ts +112 -0
- package/dist/types/shared/src/apiProfileValidators.d.ts +310 -0
- package/dist/types/shared/src/apiToken.d.ts +6 -0
- package/dist/types/shared/src/assetFamily.d.ts +38 -0
- package/dist/types/shared/src/assetFieldValues.d.ts +21 -0
- package/dist/types/shared/src/assetGraph.d.ts +221 -0
- package/dist/types/shared/src/assetJobs.d.ts +99 -0
- package/dist/types/shared/src/assetSettings.d.ts +147 -0
- package/dist/types/shared/src/auditRedact.d.ts +36 -0
- package/dist/types/shared/src/betterAuthSession.d.ts +12 -0
- package/dist/types/shared/src/bffHost.d.ts +36 -0
- package/dist/types/shared/src/bffProtocol.d.ts +563 -0
- package/dist/types/shared/src/bffRedact.d.ts +30 -0
- package/dist/types/shared/src/ciPreviewEnv.d.ts +21 -0
- package/dist/types/shared/src/clipboardTransfer.d.ts +25 -0
- package/dist/types/shared/src/convexFacade.d.ts +44 -0
- package/dist/types/shared/src/convexSiteUrl.d.ts +73 -0
- package/dist/types/shared/src/csv.d.ts +65 -0
- package/dist/types/shared/src/dataTransfer.d.ts +21 -0
- package/dist/types/shared/src/dateValues.d.ts +21 -0
- package/dist/types/shared/src/deployOutput.d.ts +3 -0
- package/dist/types/shared/src/displayLabel.d.ts +17 -0
- package/dist/types/shared/src/displayTemplateGenerator.d.ts +11 -0
- package/dist/types/shared/src/displayTypes.d.ts +10 -0
- package/dist/types/shared/src/erdLayout.d.ts +27 -0
- package/dist/types/shared/src/facets.d.ts +109 -0
- package/dist/types/shared/src/failureMessage.d.ts +5 -0
- package/dist/types/shared/src/fieldTypeMeta.d.ts +110 -0
- package/dist/types/shared/src/fieldTypeText.d.ts +34 -0
- package/dist/types/shared/src/fieldValueEqual.d.ts +10 -0
- package/dist/types/shared/src/fieldValueShape.d.ts +24 -0
- package/dist/types/shared/src/fieldValueText.d.ts +32 -0
- package/dist/types/shared/src/gridQuery.d.ts +103 -0
- package/dist/types/shared/src/importMatch.d.ts +80 -0
- package/dist/types/shared/src/index.d.ts +78 -0
- package/dist/types/shared/src/inferIdentifier.d.ts +18 -0
- package/dist/types/shared/src/keyboard.d.ts +16 -0
- package/dist/types/shared/src/manifestDeploy.d.ts +31 -0
- package/dist/types/shared/src/manifestHash.d.ts +12 -0
- package/dist/types/shared/src/mcpOAuth.d.ts +182 -0
- package/dist/types/shared/src/postLoginPath.d.ts +21 -0
- package/dist/types/shared/src/previewDeployName.d.ts +27 -0
- package/dist/types/shared/src/proposalDraftMerge.d.ts +35 -0
- package/dist/types/shared/src/proposePolicy.d.ts +17 -0
- package/dist/types/shared/src/proposeRateLimit.d.ts +27 -0
- package/dist/types/shared/src/queryBetween.d.ts +21 -0
- package/dist/types/shared/src/queryConditions.d.ts +46 -0
- package/dist/types/shared/src/queryExecution.d.ts +12 -0
- package/dist/types/shared/src/queryFieldOps.d.ts +123 -0
- package/dist/types/shared/src/queryMerge.d.ts +30 -0
- package/dist/types/shared/src/queryPlan.d.ts +86 -0
- package/dist/types/shared/src/queryStudio.d.ts +28 -0
- package/dist/types/shared/src/queryTypes.d.ts +184 -0
- package/dist/types/shared/src/queryValidators.d.ts +233 -0
- package/dist/types/shared/src/readApiQuery.d.ts +10 -0
- package/dist/types/shared/src/readModelLimits.d.ts +23 -0
- package/dist/types/shared/src/recordTableColumns.d.ts +24 -0
- package/dist/types/shared/src/recordTablePreload.d.ts +19 -0
- package/dist/types/shared/src/refDisplayRequests.d.ts +17 -0
- package/dist/types/shared/src/refGraph.d.ts +97 -0
- package/dist/types/shared/src/refsRecompute.d.ts +16 -0
- package/dist/types/shared/src/richDoc.d.ts +80 -0
- package/dist/types/shared/src/rowPatchWire.d.ts +12 -0
- package/dist/types/shared/src/rowTrash.d.ts +26 -0
- package/dist/types/shared/src/savedView.d.ts +37 -0
- package/dist/types/shared/src/schemaGenerator.d.ts +36 -0
- package/dist/types/shared/src/schemaShrink.d.ts +82 -0
- package/dist/types/shared/src/schemaShrinkValidators.d.ts +72 -0
- package/dist/types/shared/src/schemaTypes.d.ts +311 -0
- package/dist/types/shared/src/share.d.ts +8 -0
- package/dist/types/shared/src/shareApiBridge.d.ts +13 -0
- package/dist/types/shared/src/shareGuestPolicy.d.ts +14 -0
- package/dist/types/shared/src/shareProposal.d.ts +141 -0
- package/dist/types/shared/src/shareProposalDiff.d.ts +13 -0
- package/dist/types/shared/src/shareScopes.d.ts +19 -0
- package/dist/types/shared/src/shareTokenCrypto.d.ts +9 -0
- package/dist/types/shared/src/shareTokens.d.ts +6 -0
- package/dist/types/shared/src/shareTypes.d.ts +113 -0
- package/dist/types/shared/src/shareWizard.d.ts +23 -0
- package/dist/types/shared/src/spaceBundle.d.ts +89 -0
- package/dist/types/shared/src/stagedApiAccess.d.ts +104 -0
- package/dist/types/shared/src/studioBoot.d.ts +63 -0
- package/dist/types/shared/src/syncChannel.d.ts +25 -0
- package/dist/types/shared/src/syncClampMembership.d.ts +22 -0
- package/dist/types/shared/src/tableSearch.d.ts +52 -0
- package/dist/types/shared/src/tenantHosts.d.ts +34 -0
- package/dist/types/shared/src/tenantSecretsCrypto.d.ts +31 -0
- package/dist/types/shared/src/useDebouncedCommit.d.ts +15 -0
- package/dist/types/shared/src/useDebouncedValue.d.ts +1 -0
- package/dist/types/shared/src/useModifierHeld.d.ts +2 -0
- package/package.json +85 -3
- package/README.md +0 -3
|
@@ -0,0 +1,4217 @@
|
|
|
1
|
+
import { useMarkdownInsertPickers } from './chunk-ZTWPGA37.js';
|
|
2
|
+
import { readSessionCookie } from './chunk-QPQRNIKG.js';
|
|
3
|
+
import { cmsBackdrop, cmsBox, cmsButton, ghostBtn, CMS_FIELD_EDITOR_Z_INDEX, buildStampAttrs, ACCENT_FG, ACCENT, primaryBtn, IconPublish, dangerBtn, IconTrash, cmsMuted, CMS_ROW_EDITOR_Z_INDEX, Icon, CMS_MARKDOWN_EDITOR_Z_INDEX } from './chunk-ICKWVUW7.js';
|
|
4
|
+
import { createInertFieldsDataAdapter, inertRichtextHostAdapter, RichtextHostProvider, FieldsDataProvider, ImageCell, FieldInput, isPickerOverlayTarget, RowEditor, Dialog, DialogContent, preventDismissOnPickerOverlay, DialogHeader, DialogTitle, DialogDescription, DialogFooter, Button, Label, RichDocView, previewLabel, MarkdownFieldTrigger, validateFileForKind, CellRenderer } from './chunk-XWMTXQF3.js';
|
|
5
|
+
import { fallbackPreviewLabel, filterSortDocuments, myDraft, toDocumentId, isValidAssetId, stripSystemFields, tableDisplayName, fieldDisplayName, editorAccessEnabled, richContentPlainText, newProvisionalRowId, findTableAccess, findProposalIdsOverlappingTarget, validatePatch, stringifyRichDoc, SHARE_LIST_LIMIT, collectRichDocAssetIds, formatNumericDate, looksLikeId, normalizeRichField, emptyToUndefined, isHttpUrl, focalObjectPosition, formatIdShort, refTarget, staleFieldNames, proposalDiffFieldNames, computeProposalRecordDiff, plainTextIfRichDoc } from './chunk-5IPH2A64.js';
|
|
6
|
+
import { createContext, lazy, useMemo, useState, useRef, useCallback, useEffect, useContext, useId, useLayoutEffect, Suspense } from 'react';
|
|
7
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
import { createPortal } from 'react-dom';
|
|
9
|
+
|
|
10
|
+
// packages/@columnus/cms/src/stamps/resolve-display.ts
|
|
11
|
+
function effectiveStampValue(hasEditor, projectedValue, live, overlayIsActive = false) {
|
|
12
|
+
if (!hasEditor) return live;
|
|
13
|
+
if (overlayIsActive) return projectedValue;
|
|
14
|
+
if (projectedValue === void 0) return live;
|
|
15
|
+
return projectedValue;
|
|
16
|
+
}
|
|
17
|
+
function isEmptyStampValue(value) {
|
|
18
|
+
return value == null || value === "";
|
|
19
|
+
}
|
|
20
|
+
function displayStampValue(value) {
|
|
21
|
+
if (value == null) return null;
|
|
22
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function formatDateValue(value, preset, locale) {
|
|
28
|
+
const ms = typeof value === "number" ? value : Number(value);
|
|
29
|
+
if (!Number.isFinite(ms)) return displayStampValue(value);
|
|
30
|
+
return formatNumericDate(ms, locale, preset);
|
|
31
|
+
}
|
|
32
|
+
function kindDateDisplay(effectiveValue, fieldKind, locale) {
|
|
33
|
+
if (fieldKind === "date") return formatDateValue(effectiveValue, "date", locale);
|
|
34
|
+
if (fieldKind === "datetime") return formatDateValue(effectiveValue, "datetime", locale);
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
function applyStampFormat(effectiveValue, format, locale, empty) {
|
|
38
|
+
if (typeof format === "function") {
|
|
39
|
+
const formatted = format(effectiveValue);
|
|
40
|
+
if (isEmptyStampValue(effectiveValue) && (formatted == null || formatted === "") && empty != null) {
|
|
41
|
+
return empty;
|
|
42
|
+
}
|
|
43
|
+
return formatted;
|
|
44
|
+
}
|
|
45
|
+
if (format === "plain") {
|
|
46
|
+
if (typeof effectiveValue !== "string") return displayStampValue(effectiveValue);
|
|
47
|
+
const plain = richContentPlainText(effectiveValue);
|
|
48
|
+
return plain ?? empty ?? null;
|
|
49
|
+
}
|
|
50
|
+
if (format === "date" || format === "datetime" || format === "time") {
|
|
51
|
+
if (isEmptyStampValue(effectiveValue)) return empty ?? null;
|
|
52
|
+
return formatDateValue(effectiveValue, format, locale);
|
|
53
|
+
}
|
|
54
|
+
return displayStampValue(effectiveValue);
|
|
55
|
+
}
|
|
56
|
+
function resolveStampDisplay({
|
|
57
|
+
children,
|
|
58
|
+
format,
|
|
59
|
+
value,
|
|
60
|
+
empty,
|
|
61
|
+
projectedValue,
|
|
62
|
+
hasEditor,
|
|
63
|
+
overlayIsActive,
|
|
64
|
+
relatedRow,
|
|
65
|
+
relatedPreview,
|
|
66
|
+
fieldKind,
|
|
67
|
+
locale
|
|
68
|
+
}) {
|
|
69
|
+
const effectiveValue = effectiveStampValue(hasEditor, projectedValue, value, overlayIsActive);
|
|
70
|
+
if (typeof children === "function") {
|
|
71
|
+
return children(effectiveValue, relatedRow);
|
|
72
|
+
}
|
|
73
|
+
if (format != null) {
|
|
74
|
+
return applyStampFormat(effectiveValue, format, locale, empty);
|
|
75
|
+
}
|
|
76
|
+
if (children != null && typeof children !== "string") {
|
|
77
|
+
return children;
|
|
78
|
+
}
|
|
79
|
+
if (isEmptyStampValue(effectiveValue)) return empty ?? null;
|
|
80
|
+
if (hasEditor && relatedPreview != null) return relatedPreview;
|
|
81
|
+
return kindDateDisplay(effectiveValue, fieldKind, locale) ?? displayStampValue(effectiveValue);
|
|
82
|
+
}
|
|
83
|
+
var CmsTableRowsContext = createContext({});
|
|
84
|
+
function useCmsTableRows() {
|
|
85
|
+
return useContext(CmsTableRowsContext);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// packages/@columnus/cms/src/manifest-index.ts
|
|
89
|
+
var EMPTY_FIELDS = [];
|
|
90
|
+
var indexes = /* @__PURE__ */ new WeakMap();
|
|
91
|
+
function indexFor(manifest) {
|
|
92
|
+
let index = indexes.get(manifest);
|
|
93
|
+
if (!index) {
|
|
94
|
+
index = {
|
|
95
|
+
byName: new Map(
|
|
96
|
+
manifest.tables.map((table) => [
|
|
97
|
+
table.name,
|
|
98
|
+
new Map(table.fields.map((field) => [field.name, field]))
|
|
99
|
+
])
|
|
100
|
+
),
|
|
101
|
+
fieldsByTable: new Map(manifest.tables.map((table) => [table.name, table.fields]))
|
|
102
|
+
};
|
|
103
|
+
indexes.set(manifest, index);
|
|
104
|
+
}
|
|
105
|
+
return index;
|
|
106
|
+
}
|
|
107
|
+
function manifestField(manifest, table, field) {
|
|
108
|
+
return indexFor(manifest).byName.get(table)?.get(field);
|
|
109
|
+
}
|
|
110
|
+
function manifestFields(manifest, table) {
|
|
111
|
+
return indexFor(manifest).fieldsByTable.get(table) ?? EMPTY_FIELDS;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// packages/@columnus/cms/src/adapters/table-rows-richtext.ts
|
|
115
|
+
var rowIndexes = /* @__PURE__ */ new WeakMap();
|
|
116
|
+
function indexesFor(tableRows) {
|
|
117
|
+
let entry = rowIndexes.get(tableRows);
|
|
118
|
+
if (!entry) {
|
|
119
|
+
entry = { byTable: /* @__PURE__ */ new Map() };
|
|
120
|
+
rowIndexes.set(tableRows, entry);
|
|
121
|
+
}
|
|
122
|
+
return entry;
|
|
123
|
+
}
|
|
124
|
+
function flattenRows(tableRows) {
|
|
125
|
+
const entry = indexesFor(tableRows);
|
|
126
|
+
if (entry.all) return entry.all;
|
|
127
|
+
const byId = /* @__PURE__ */ new Map();
|
|
128
|
+
for (const rows of Object.values(tableRows)) {
|
|
129
|
+
for (const row of rows) {
|
|
130
|
+
byId.set(String(row._id), row);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
entry.all = byId;
|
|
134
|
+
return byId;
|
|
135
|
+
}
|
|
136
|
+
function rowsById(tableRows, table) {
|
|
137
|
+
const entry = indexesFor(tableRows);
|
|
138
|
+
let byId = entry.byTable.get(table);
|
|
139
|
+
if (!byId) {
|
|
140
|
+
byId = new Map((tableRows[table] ?? []).map((row) => [String(row._id), row]));
|
|
141
|
+
entry.byTable.set(table, byId);
|
|
142
|
+
}
|
|
143
|
+
return byId;
|
|
144
|
+
}
|
|
145
|
+
function displayMapForIds(tableRows, table, ids, fields) {
|
|
146
|
+
const byId = rowsById(tableRows, table);
|
|
147
|
+
const map = /* @__PURE__ */ new Map();
|
|
148
|
+
for (const id of ids) {
|
|
149
|
+
const row = byId.get(id);
|
|
150
|
+
map.set(id, { id, preview: row ? fallbackPreviewLabel(row, fields) : id });
|
|
151
|
+
}
|
|
152
|
+
return map;
|
|
153
|
+
}
|
|
154
|
+
function tableIsLoaded(tableRows, table) {
|
|
155
|
+
return Object.hasOwn(tableRows, table);
|
|
156
|
+
}
|
|
157
|
+
var NO_MORE = () => void 0;
|
|
158
|
+
function useArrayPage(items, table, loaded, initialNumItems) {
|
|
159
|
+
const [visible, setVisible] = useState(initialNumItems);
|
|
160
|
+
const loadMore = useCallback((n) => setVisible((v) => v + n), []);
|
|
161
|
+
if (!table) return { results: [], status: "Exhausted", loadMore: NO_MORE };
|
|
162
|
+
if (!loaded) return { results: [], status: "LoadingFirstPage", loadMore: NO_MORE };
|
|
163
|
+
return {
|
|
164
|
+
results: items.slice(0, visible),
|
|
165
|
+
status: visible >= items.length ? "Exhausted" : "CanLoadMore",
|
|
166
|
+
loadMore
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function createTableRowsRichtextHostAdapter(manifest) {
|
|
170
|
+
return {
|
|
171
|
+
...inertRichtextHostAdapter,
|
|
172
|
+
useIsDark: () => false,
|
|
173
|
+
useManifest: () => ({ manifest, loading: false }),
|
|
174
|
+
useRowsByIds: (ids) => {
|
|
175
|
+
const tableRows = useCmsTableRows();
|
|
176
|
+
const byId = flattenRows(tableRows);
|
|
177
|
+
const out = {};
|
|
178
|
+
for (const id of ids) {
|
|
179
|
+
const row = byId.get(id);
|
|
180
|
+
if (row) out[id] = row;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
},
|
|
184
|
+
useDisplayValues: (table, ids) => displayMapForIds(useCmsTableRows(), table, ids, manifestFields(manifest, table)),
|
|
185
|
+
useRefDisplayMaps: (requests) => {
|
|
186
|
+
const tableRows = useCmsTableRows();
|
|
187
|
+
const maps = /* @__PURE__ */ new Map();
|
|
188
|
+
for (const req of requests) {
|
|
189
|
+
maps.set(
|
|
190
|
+
req.table,
|
|
191
|
+
displayMapForIds(tableRows, req.table, req.ids, manifestFields(manifest, req.table))
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
return maps;
|
|
195
|
+
},
|
|
196
|
+
useListRows: (args, initialNumItems) => {
|
|
197
|
+
const tableRows = useCmsTableRows();
|
|
198
|
+
const table = args === "skip" ? null : args.table;
|
|
199
|
+
const query = args === "skip" || args.query === void 0 ? null : args.query;
|
|
200
|
+
const loaded = table !== null && tableIsLoaded(tableRows, table);
|
|
201
|
+
const all = useMemo(
|
|
202
|
+
() => table && loaded ? filterSortDocuments(tableRows[table] ?? [], query) : [],
|
|
203
|
+
[table, loaded, query, tableRows]
|
|
204
|
+
);
|
|
205
|
+
return useArrayPage(all, table, loaded, initialNumItems);
|
|
206
|
+
},
|
|
207
|
+
useSearchDisplayValues: (args, initialNumItems) => {
|
|
208
|
+
const tableRows = useCmsTableRows();
|
|
209
|
+
const table = args === "skip" ? null : args.table;
|
|
210
|
+
const q = args === "skip" ? "" : args.query.trim().toLowerCase();
|
|
211
|
+
const loaded = table !== null && tableIsLoaded(tableRows, table);
|
|
212
|
+
const hits = useMemo(() => {
|
|
213
|
+
if (!table || !loaded) return [];
|
|
214
|
+
return (tableRows[table] ?? []).map((row) => {
|
|
215
|
+
const documentId = String(row._id);
|
|
216
|
+
const value = fallbackPreviewLabel(row, manifestFields(manifest, table));
|
|
217
|
+
return { documentId, value };
|
|
218
|
+
}).filter((hit) => !q || hit.value.toLowerCase().includes(q) || hit.documentId.includes(q));
|
|
219
|
+
}, [table, loaded, q, tableRows]);
|
|
220
|
+
return useArrayPage(hits, table, loaded, initialNumItems);
|
|
221
|
+
},
|
|
222
|
+
useInsertRow: () => null
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function createDefaultRichtextHostAdapter(manifest) {
|
|
226
|
+
return createTableRowsRichtextHostAdapter(manifest);
|
|
227
|
+
}
|
|
228
|
+
function DefaultRichtextHostProvider({
|
|
229
|
+
manifest,
|
|
230
|
+
adapter,
|
|
231
|
+
children
|
|
232
|
+
}) {
|
|
233
|
+
const resolved = useMemo(
|
|
234
|
+
() => adapter ?? createDefaultRichtextHostAdapter(manifest),
|
|
235
|
+
[adapter, manifest]
|
|
236
|
+
);
|
|
237
|
+
return /* @__PURE__ */ jsx(RichtextHostProvider, { adapter: resolved, children });
|
|
238
|
+
}
|
|
239
|
+
var MarkdownEditorDialogLazy = lazy(
|
|
240
|
+
() => import('./editor-543ARQ6S.js').then((m) => ({ default: m.MarkdownEditorDialog }))
|
|
241
|
+
);
|
|
242
|
+
function defaultRenderMarkdownField(props) {
|
|
243
|
+
return /* @__PURE__ */ jsx(CmsMarkdownFieldInput, { ...props });
|
|
244
|
+
}
|
|
245
|
+
function CmsMarkdownFieldInput({
|
|
246
|
+
manifest,
|
|
247
|
+
value,
|
|
248
|
+
onChange,
|
|
249
|
+
optional,
|
|
250
|
+
inline
|
|
251
|
+
}) {
|
|
252
|
+
const [open, setOpen] = useState(false);
|
|
253
|
+
const stringValue = typeof value === "string" ? value : normalizeRichField(value);
|
|
254
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
255
|
+
/* @__PURE__ */ jsx(MarkdownFieldTrigger, { value: stringValue, onEdit: () => setOpen(true), inline }),
|
|
256
|
+
open ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
|
|
257
|
+
MarkdownEditorDialogLazy,
|
|
258
|
+
{
|
|
259
|
+
open: true,
|
|
260
|
+
onOpenChange: setOpen,
|
|
261
|
+
manifest,
|
|
262
|
+
value: stringValue,
|
|
263
|
+
optional,
|
|
264
|
+
overlayZIndex: CMS_MARKDOWN_EDITOR_Z_INDEX,
|
|
265
|
+
onSave: (next) => onChange(emptyToUndefined(next, optional))
|
|
266
|
+
}
|
|
267
|
+
) }) : null
|
|
268
|
+
] });
|
|
269
|
+
}
|
|
270
|
+
function DefaultMarkdownFieldEditor({
|
|
271
|
+
manifest,
|
|
272
|
+
table,
|
|
273
|
+
field,
|
|
274
|
+
value,
|
|
275
|
+
onComplete
|
|
276
|
+
}) {
|
|
277
|
+
const schemaTable = manifest.tables.find((t) => t.name === table);
|
|
278
|
+
const schemaField = schemaTable?.fields.find((f) => f.name === field);
|
|
279
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
|
|
280
|
+
MarkdownEditorDialogLazy,
|
|
281
|
+
{
|
|
282
|
+
open: true,
|
|
283
|
+
onOpenChange: (next) => {
|
|
284
|
+
if (!next) onComplete();
|
|
285
|
+
},
|
|
286
|
+
manifest,
|
|
287
|
+
value,
|
|
288
|
+
onSave: onComplete,
|
|
289
|
+
table: schemaTable,
|
|
290
|
+
field: schemaField
|
|
291
|
+
}
|
|
292
|
+
) });
|
|
293
|
+
}
|
|
294
|
+
function createDefaultCmsRichtextAdapters(manifest) {
|
|
295
|
+
return {
|
|
296
|
+
renderMarkdownEditor: ({ table, field, value, onComplete }) => /* @__PURE__ */ jsx(
|
|
297
|
+
DefaultMarkdownFieldEditor,
|
|
298
|
+
{
|
|
299
|
+
manifest,
|
|
300
|
+
table,
|
|
301
|
+
field,
|
|
302
|
+
value,
|
|
303
|
+
onComplete
|
|
304
|
+
}
|
|
305
|
+
)
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// packages/@columnus/cms/src/adapters/projected-fields-adapter.ts
|
|
310
|
+
function overlayDisplayMap(fromBase, ids, rows, fields) {
|
|
311
|
+
let changed = false;
|
|
312
|
+
const out = new Map(fromBase);
|
|
313
|
+
for (const id of ids) {
|
|
314
|
+
const cached = out.get(id);
|
|
315
|
+
if (cached?.preview) continue;
|
|
316
|
+
const row = rows.get(id);
|
|
317
|
+
if (!row) continue;
|
|
318
|
+
out.set(id, { id, ...cached, preview: fallbackPreviewLabel(row, fields) });
|
|
319
|
+
changed = true;
|
|
320
|
+
}
|
|
321
|
+
return changed ? out : fromBase;
|
|
322
|
+
}
|
|
323
|
+
function useMergedRowLookup({ base, projection, mergedLookups }, table) {
|
|
324
|
+
const baseRows = base.useRowLookup(table);
|
|
325
|
+
const cached = mergedLookups.get(table);
|
|
326
|
+
if (cached && cached.base === baseRows) return cached.merged;
|
|
327
|
+
const merged = new Map([
|
|
328
|
+
...baseRows,
|
|
329
|
+
...projection.table(table).map(({ value }) => [value._id, value])
|
|
330
|
+
]);
|
|
331
|
+
mergedLookups.set(table, { base: baseRows, merged });
|
|
332
|
+
return merged;
|
|
333
|
+
}
|
|
334
|
+
function useOverlayDisplayValues(sources, table, ids) {
|
|
335
|
+
const fromBase = sources.base.useDisplayValues(table, ids);
|
|
336
|
+
const rows = useMergedRowLookup(sources, table);
|
|
337
|
+
return overlayDisplayMap(fromBase, ids, rows, manifestFields(sources.manifest, table));
|
|
338
|
+
}
|
|
339
|
+
function withProjectedRows(base, projection, manifest) {
|
|
340
|
+
const sources = { base, projection, manifest, mergedLookups: /* @__PURE__ */ new Map() };
|
|
341
|
+
return {
|
|
342
|
+
...base,
|
|
343
|
+
manifest: base.manifest ?? manifest,
|
|
344
|
+
useDisplayValues: (table, ids) => useOverlayDisplayValues(sources, table, ids),
|
|
345
|
+
useReferenceSearch: (table, query) => {
|
|
346
|
+
const baseResult = base.useReferenceSearch(table, query);
|
|
347
|
+
const q = query.trim().toLowerCase();
|
|
348
|
+
const fields = manifestFields(manifest, table);
|
|
349
|
+
const projectedHits = projection.table(table).map(({ value }) => ({
|
|
350
|
+
documentId: value._id,
|
|
351
|
+
value: fallbackPreviewLabel(value, fields)
|
|
352
|
+
})).filter(
|
|
353
|
+
(hit) => !q || hit.value.toLowerCase().includes(q) || hit.documentId.toLowerCase().includes(q)
|
|
354
|
+
).slice(0, 50);
|
|
355
|
+
const projectedById = new Map(projectedHits.map((hit) => [hit.documentId, hit]));
|
|
356
|
+
const baseIds = new Set(baseResult.hits.map((hit) => hit.documentId));
|
|
357
|
+
const mergedHits = [
|
|
358
|
+
...baseResult.hits.map((hit) => projectedById.get(hit.documentId) ?? hit),
|
|
359
|
+
...projectedHits.filter((hit) => !baseIds.has(hit.documentId))
|
|
360
|
+
];
|
|
361
|
+
const displayMap = useOverlayDisplayValues(
|
|
362
|
+
sources,
|
|
363
|
+
table,
|
|
364
|
+
mergedHits.map((hit) => hit.documentId)
|
|
365
|
+
);
|
|
366
|
+
return {
|
|
367
|
+
...baseResult,
|
|
368
|
+
hits: mergedHits.map((hit) => ({
|
|
369
|
+
...hit,
|
|
370
|
+
value: previewLabel(displayMap, hit.documentId) ?? hit.value
|
|
371
|
+
}))
|
|
372
|
+
};
|
|
373
|
+
},
|
|
374
|
+
// Called once per reference cell per render — merge only when the host rows change.
|
|
375
|
+
useRowLookup: (table) => useMergedRowLookup(sources, table)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// packages/@columnus/cms/src/nav/infer-navigation-table.ts
|
|
380
|
+
function selfIdFields(table) {
|
|
381
|
+
return table.fields.filter(
|
|
382
|
+
(field) => field.type.kind === "id" && field.type.table === table.name
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
function inferNavigationTable(manifest, navigationTable) {
|
|
386
|
+
const override = navigationTable?.trim();
|
|
387
|
+
if (override) {
|
|
388
|
+
const table = manifest.tables.find((t) => t.name === override);
|
|
389
|
+
if (!table) {
|
|
390
|
+
return { ok: false, reason: "override_missing", candidates: [] };
|
|
391
|
+
}
|
|
392
|
+
const selfFields = selfIdFields(table);
|
|
393
|
+
const parentField = selfFields.find((f) => f.name === "parent") ?? selfFields[0];
|
|
394
|
+
if (!parentField) {
|
|
395
|
+
return { ok: false, reason: "override_missing", candidates: [override] };
|
|
396
|
+
}
|
|
397
|
+
return { ok: true, table: override, parentField: parentField.name };
|
|
398
|
+
}
|
|
399
|
+
const withSelfId = [];
|
|
400
|
+
for (const table of manifest.tables) {
|
|
401
|
+
const selfFields = selfIdFields(table);
|
|
402
|
+
if (selfFields.length === 0) continue;
|
|
403
|
+
const literalParent = selfFields.find((f) => f.name === "parent");
|
|
404
|
+
withSelfId.push({
|
|
405
|
+
table: table.name,
|
|
406
|
+
parentField: (literalParent ?? selfFields[0]).name,
|
|
407
|
+
hasLiteralParent: literalParent !== void 0
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
const literalParents = withSelfId.filter((c) => c.hasLiteralParent);
|
|
411
|
+
const candidates = literalParents.length > 0 ? literalParents : withSelfId;
|
|
412
|
+
if (candidates.length === 1) {
|
|
413
|
+
const only = candidates[0];
|
|
414
|
+
return { ok: true, table: only.table, parentField: only.parentField };
|
|
415
|
+
}
|
|
416
|
+
if (candidates.length > 1) {
|
|
417
|
+
return { ok: false, reason: "ambiguous", candidates: candidates.map((c) => c.table) };
|
|
418
|
+
}
|
|
419
|
+
return { ok: false, reason: "none", candidates: [] };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// packages/@columnus/cms/src/list/build-insert-draft.ts
|
|
423
|
+
function labelFromFields(fields, title2) {
|
|
424
|
+
if (typeof fields?.title === "string" && fields.title.trim()) return fields.title.trim();
|
|
425
|
+
if (typeof fields?.name === "string" && fields.name.trim()) return fields.name.trim();
|
|
426
|
+
if (title2?.trim()) return title2.trim();
|
|
427
|
+
return "Untitled";
|
|
428
|
+
}
|
|
429
|
+
function isUsableRowId(id) {
|
|
430
|
+
return looksLikeId(id) || id.startsWith("new:");
|
|
431
|
+
}
|
|
432
|
+
function resolveInsertRowId(requested) {
|
|
433
|
+
if (!requested || requested === "new") return newProvisionalRowId();
|
|
434
|
+
if (isUsableRowId(requested)) return requested;
|
|
435
|
+
return newProvisionalRowId();
|
|
436
|
+
}
|
|
437
|
+
function buildInsertDraft(args) {
|
|
438
|
+
const { manifest, table, title: title2, fields: inputFields } = args;
|
|
439
|
+
const schema = manifest.tables.find((t) => t.name === table);
|
|
440
|
+
if (!schema) throw new Error(`Unknown table ${table}`);
|
|
441
|
+
const label2 = labelFromFields(inputFields, title2);
|
|
442
|
+
const rowId = resolveInsertRowId(args.rowId);
|
|
443
|
+
const fields = { ...inputFields };
|
|
444
|
+
const titleField = schema.fields.find((f) => f.name === "title" || f.name === "name");
|
|
445
|
+
if (titleField && (fields[titleField.name] === void 0 || fields[titleField.name] === "")) {
|
|
446
|
+
fields[titleField.name] = label2;
|
|
447
|
+
}
|
|
448
|
+
return [{ table, rowId, op: "insert", fields }];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// packages/@columnus/shared/src/proposalDraftMerge.ts
|
|
452
|
+
function draftRowKey(patch) {
|
|
453
|
+
return JSON.stringify([patch.table, patch.rowId]);
|
|
454
|
+
}
|
|
455
|
+
function withoutKeys(fields, keys) {
|
|
456
|
+
if (!keys?.length) return { ...fields };
|
|
457
|
+
const drop = new Set(keys);
|
|
458
|
+
return Object.fromEntries(Object.entries(fields).filter(([key]) => !drop.has(key)));
|
|
459
|
+
}
|
|
460
|
+
function patchOf(base, extras) {
|
|
461
|
+
return {
|
|
462
|
+
...base,
|
|
463
|
+
...extras.clearFields?.length ? { clearFields: extras.clearFields } : {},
|
|
464
|
+
...extras.baseFields ? { baseFields: extras.baseFields } : {},
|
|
465
|
+
...extras.nativeScope ? { nativeScope: extras.nativeScope } : {}
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function mergeRow(current, patch) {
|
|
469
|
+
const kept = current ? { baseFields: current.baseFields, nativeScope: current.nativeScope ?? patch.nativeScope } : { baseFields: patch.baseFields, nativeScope: patch.nativeScope };
|
|
470
|
+
if (current?.op === "insert" && patch.op === "delete") return void 0;
|
|
471
|
+
if (current?.op === "insert" && patch.op === "update") {
|
|
472
|
+
const fields = withoutKeys({ ...current.fields, ...patch.fields }, patch.clearFields);
|
|
473
|
+
return patchOf({ table: current.table, rowId: current.rowId, op: "insert", fields }, kept);
|
|
474
|
+
}
|
|
475
|
+
if (current?.op === "update" && patch.op === "update") {
|
|
476
|
+
const fields = withoutKeys({ ...current.fields, ...patch.fields }, patch.clearFields);
|
|
477
|
+
const clearFields = [
|
|
478
|
+
.../* @__PURE__ */ new Set([
|
|
479
|
+
...(current.clearFields ?? []).filter((field) => !(field in patch.fields)),
|
|
480
|
+
...patch.clearFields ?? []
|
|
481
|
+
])
|
|
482
|
+
];
|
|
483
|
+
return patchOf(
|
|
484
|
+
{ table: current.table, rowId: current.rowId, op: "update", fields },
|
|
485
|
+
{ ...kept, clearFields }
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
return patchOf(
|
|
489
|
+
{ table: patch.table, rowId: patch.rowId, op: patch.op, fields: { ...patch.fields } },
|
|
490
|
+
{ ...kept, clearFields: patch.op === "update" ? patch.clearFields : void 0 }
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
function mergeDraftPatches(existing, delta) {
|
|
494
|
+
const rows = /* @__PURE__ */ new Map();
|
|
495
|
+
for (const patch of [...existing, ...delta]) {
|
|
496
|
+
const key = draftRowKey(patch);
|
|
497
|
+
const next = mergeRow(rows.get(key), patch);
|
|
498
|
+
if (next) rows.set(key, next);
|
|
499
|
+
else rows.delete(key);
|
|
500
|
+
}
|
|
501
|
+
return [...rows.values()];
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// packages/@columnus/cms/src/draft/merge-draft.ts
|
|
505
|
+
function mergeDraftIntoProposal(existing, draft) {
|
|
506
|
+
const plain = (patch) => ({
|
|
507
|
+
table: patch.table,
|
|
508
|
+
rowId: patch.rowId,
|
|
509
|
+
op: patch.op,
|
|
510
|
+
fields: patch.fields,
|
|
511
|
+
...patch.clearFields?.length ? { clearFields: patch.clearFields } : {}
|
|
512
|
+
});
|
|
513
|
+
return mergeDraftPatches(existing.map(plain), draft.map(plain)).map(plain);
|
|
514
|
+
}
|
|
515
|
+
function applyFieldToDraft(draft, input2) {
|
|
516
|
+
const patch = {
|
|
517
|
+
table: input2.table,
|
|
518
|
+
rowId: input2.rowId,
|
|
519
|
+
op: "update",
|
|
520
|
+
fields: { [input2.field]: input2.value }
|
|
521
|
+
};
|
|
522
|
+
return mergeDraftIntoProposal(draft, [patch]);
|
|
523
|
+
}
|
|
524
|
+
function applyRowToDraft(draft, input2) {
|
|
525
|
+
return mergeDraftIntoProposal(draft, [
|
|
526
|
+
{
|
|
527
|
+
table: input2.table,
|
|
528
|
+
rowId: input2.rowId,
|
|
529
|
+
op: "update",
|
|
530
|
+
fields: { ...input2.fields },
|
|
531
|
+
...input2.clearFields?.length ? { clearFields: input2.clearFields } : {}
|
|
532
|
+
}
|
|
533
|
+
]);
|
|
534
|
+
}
|
|
535
|
+
function applyDeleteToDraft(draft, input2) {
|
|
536
|
+
return mergeDraftIntoProposal(draft, [
|
|
537
|
+
{ table: input2.table, rowId: input2.rowId, op: "delete", fields: {} }
|
|
538
|
+
]);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// packages/@columnus/cms/src/profile/propose-gates.ts
|
|
542
|
+
function editorCanWrite(tableAccess, table) {
|
|
543
|
+
const access = findTableAccess(tableAccess, table);
|
|
544
|
+
return access != null && editorAccessEnabled(access);
|
|
545
|
+
}
|
|
546
|
+
function canProposeOp(tableAccess, table, _op) {
|
|
547
|
+
return editorCanWrite(tableAccess, table);
|
|
548
|
+
}
|
|
549
|
+
function canProposeField(tableAccess, table, _field) {
|
|
550
|
+
return editorCanWrite(tableAccess, table);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// packages/@columnus/cms/src/projection/cms-projection.ts
|
|
554
|
+
function draftTitle(proposal, mine) {
|
|
555
|
+
if (!mine) return proposal.createdByName ?? "Another editor";
|
|
556
|
+
return proposal.draftLabel ?? (proposal.draftKey ? "Builder session" : "Toolbar edits");
|
|
557
|
+
}
|
|
558
|
+
var EMPTY_FIELD = { value: void 0, origin: null };
|
|
559
|
+
function tableRowsFor(tables, table) {
|
|
560
|
+
let rows = tables.get(table);
|
|
561
|
+
if (!rows) {
|
|
562
|
+
rows = /* @__PURE__ */ new Map();
|
|
563
|
+
tables.set(table, rows);
|
|
564
|
+
}
|
|
565
|
+
return rows;
|
|
566
|
+
}
|
|
567
|
+
function rowFor(tables, table, rowId) {
|
|
568
|
+
const rows = tableRowsFor(tables, table);
|
|
569
|
+
let row = rows.get(rowId);
|
|
570
|
+
if (!row) {
|
|
571
|
+
row = {
|
|
572
|
+
rowId,
|
|
573
|
+
live: false,
|
|
574
|
+
value: { _id: rowId },
|
|
575
|
+
origins: /* @__PURE__ */ new Map(),
|
|
576
|
+
placement: null,
|
|
577
|
+
deletedBy: null,
|
|
578
|
+
shadowedDelete: null
|
|
579
|
+
};
|
|
580
|
+
rows.set(rowId, row);
|
|
581
|
+
}
|
|
582
|
+
return row;
|
|
583
|
+
}
|
|
584
|
+
function applyFields(row, patch, origin) {
|
|
585
|
+
for (const [field, value] of Object.entries(patch.fields)) {
|
|
586
|
+
if (field === "_id") continue;
|
|
587
|
+
row.value[field] = value;
|
|
588
|
+
row.origins.set(field, origin);
|
|
589
|
+
}
|
|
590
|
+
for (const field of patch.clearFields ?? []) {
|
|
591
|
+
if (field === "_id") continue;
|
|
592
|
+
delete row.value[field];
|
|
593
|
+
row.origins.set(field, origin);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
function applyPatch(row, patch, origin, placement) {
|
|
597
|
+
if (patch.op === "delete") {
|
|
598
|
+
row.deletedBy = origin;
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
if (patch.op === "update" && !row.placement) {
|
|
602
|
+
row.deletedBy = null;
|
|
603
|
+
applyFields(row, patch, origin);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (patch.op === "insert" && !row.live) {
|
|
607
|
+
row.value = { _id: row.rowId };
|
|
608
|
+
row.origins.clear();
|
|
609
|
+
row.placement = placement;
|
|
610
|
+
}
|
|
611
|
+
row.deletedBy = null;
|
|
612
|
+
applyFields(row, patch, origin);
|
|
613
|
+
}
|
|
614
|
+
function sortedProposalPatches(proposal) {
|
|
615
|
+
return proposal.patches.map((patch, index) => ({ patch, index })).sort(
|
|
616
|
+
(a, b) => (a.patch.seq ?? 0) - (b.patch.seq ?? 0) || (a.patch.id ?? "").localeCompare(b.patch.id ?? "") || a.index - b.index
|
|
617
|
+
).map(({ patch }) => patch);
|
|
618
|
+
}
|
|
619
|
+
function createCmsProjection({
|
|
620
|
+
liveRows,
|
|
621
|
+
draft,
|
|
622
|
+
proposals,
|
|
623
|
+
editorUserId,
|
|
624
|
+
draftKey
|
|
625
|
+
}) {
|
|
626
|
+
const tables = /* @__PURE__ */ new Map();
|
|
627
|
+
for (const [table, rows] of Object.entries(liveRows)) {
|
|
628
|
+
rows.forEach((value, order) => {
|
|
629
|
+
const rowId = String(value._id);
|
|
630
|
+
tableRowsFor(tables, table).set(rowId, {
|
|
631
|
+
rowId,
|
|
632
|
+
live: true,
|
|
633
|
+
value: { ...value, _id: rowId },
|
|
634
|
+
origins: /* @__PURE__ */ new Map(),
|
|
635
|
+
placement: [2, order],
|
|
636
|
+
deletedBy: null,
|
|
637
|
+
shadowedDelete: null
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
const isMine = (proposal) => editorUserId !== null && proposal.createdByUserId === editorUserId;
|
|
642
|
+
const activeProposals = proposals.filter((proposal) => proposal.status === "active").sort((a, b) => a.createdAt - b.createdAt || a.id.localeCompare(b.id));
|
|
643
|
+
activeProposals.filter((proposal) => !isMine(proposal) || proposal.draftKey === draftKey).forEach((proposal, rank) => {
|
|
644
|
+
const mine2 = isMine(proposal);
|
|
645
|
+
const origin = {
|
|
646
|
+
kind: "proposal",
|
|
647
|
+
proposalId: proposal.id,
|
|
648
|
+
mine: mine2,
|
|
649
|
+
draftKey: proposal.draftKey,
|
|
650
|
+
label: draftTitle(proposal, mine2)
|
|
651
|
+
};
|
|
652
|
+
for (const patch of sortedProposalPatches(proposal)) {
|
|
653
|
+
applyPatch(rowFor(tables, patch.table, patch.rowId), patch, origin, [1, -rank]);
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
const proposalDeletes = /* @__PURE__ */ new Map();
|
|
657
|
+
for (const rows of tables.values()) {
|
|
658
|
+
for (const row of rows.values()) {
|
|
659
|
+
if (row.deletedBy?.kind === "proposal") proposalDeletes.set(row, row.deletedBy);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
draft.forEach((patch, order) => {
|
|
663
|
+
const row = rowFor(tables, patch.table, patch.rowId);
|
|
664
|
+
applyPatch(row, patch, { kind: "local" }, [0, order]);
|
|
665
|
+
row.shadowedDelete = patch.op !== "delete" && row.placement && !row.deletedBy ? proposalDeletes.get(row) ?? null : null;
|
|
666
|
+
});
|
|
667
|
+
const tableCache = /* @__PURE__ */ new Map();
|
|
668
|
+
const projectedRow = (row) => ({
|
|
669
|
+
value: row.value,
|
|
670
|
+
provisional: !row.live,
|
|
671
|
+
origins: row.origins,
|
|
672
|
+
shadowedDelete: row.shadowedDelete
|
|
673
|
+
});
|
|
674
|
+
const mine = draftKey === null ? void 0 : myDraft(activeProposals, editorUserId, draftKey);
|
|
675
|
+
const conflictsWithMine = mine == null ? /* @__PURE__ */ new Set() : findProposalIdsOverlappingTarget(
|
|
676
|
+
{ id: mine.id, patches: mine.patches },
|
|
677
|
+
activeProposals.map((proposal) => ({ id: proposal.id, patches: proposal.patches }))
|
|
678
|
+
);
|
|
679
|
+
return {
|
|
680
|
+
conflictsWithMine,
|
|
681
|
+
field({ table, rowId, field }) {
|
|
682
|
+
const row = tables.get(table)?.get(rowId);
|
|
683
|
+
if (!row) return EMPTY_FIELD;
|
|
684
|
+
if (row.deletedBy) return { value: void 0, origin: row.deletedBy };
|
|
685
|
+
const origin = row.origins.get(field) ?? null;
|
|
686
|
+
if (!row.placement && origin == null) return EMPTY_FIELD;
|
|
687
|
+
return {
|
|
688
|
+
value: row.value[field],
|
|
689
|
+
origin
|
|
690
|
+
};
|
|
691
|
+
},
|
|
692
|
+
row({ table, rowId }) {
|
|
693
|
+
const row = tables.get(table)?.get(rowId);
|
|
694
|
+
return row ? projectedRow(row) : null;
|
|
695
|
+
},
|
|
696
|
+
table(table) {
|
|
697
|
+
const cached = tableCache.get(table);
|
|
698
|
+
if (cached) return cached;
|
|
699
|
+
const rows = [...tables.get(table)?.values() ?? []].filter((row) => row.placement && !row.deletedBy).sort((a, b) => {
|
|
700
|
+
const [aGroup, aOrder] = a.placement;
|
|
701
|
+
const [bGroup, bOrder] = b.placement;
|
|
702
|
+
return aGroup - bGroup || aOrder - bOrder || a.rowId.localeCompare(b.rowId);
|
|
703
|
+
}).map(projectedRow);
|
|
704
|
+
tableCache.set(table, rows);
|
|
705
|
+
return rows;
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
var DEFAULT_DRAFT = {};
|
|
710
|
+
var BUILDER_UNREACHABLE = "The builder isn't reachable: try again";
|
|
711
|
+
async function readBuilderDraft(builderUrl) {
|
|
712
|
+
const response = await fetch(`${builderUrl}/session`).catch(() => void 0);
|
|
713
|
+
const body = await response?.json().catch(() => void 0);
|
|
714
|
+
if (body?.error === "editor" || body?.error === "other-editor") return DEFAULT_DRAFT;
|
|
715
|
+
if (response?.ok && body?.draftKey === null) return DEFAULT_DRAFT;
|
|
716
|
+
if (response?.ok && typeof body?.draftKey === "string") {
|
|
717
|
+
return { key: body.draftKey, label: body.draftLabel };
|
|
718
|
+
}
|
|
719
|
+
throw new Error(BUILDER_UNREACHABLE);
|
|
720
|
+
}
|
|
721
|
+
function madeFor(madeUnder, draft) {
|
|
722
|
+
return madeUnder === null || madeUnder.key === draft.key;
|
|
723
|
+
}
|
|
724
|
+
function useBuilderDraft() {
|
|
725
|
+
const [builderUrl, setBuilderUrl] = useState();
|
|
726
|
+
const [currentDraft, setCurrentDraft] = useState(DEFAULT_DRAFT);
|
|
727
|
+
const currentDraftRef = useRef(currentDraft);
|
|
728
|
+
currentDraftRef.current = currentDraft;
|
|
729
|
+
const seq = useRef(0);
|
|
730
|
+
const connectBuilder = useCallback((url) => {
|
|
731
|
+
seq.current++;
|
|
732
|
+
setBuilderUrl(url);
|
|
733
|
+
setCurrentDraft(url ? null : DEFAULT_DRAFT);
|
|
734
|
+
}, []);
|
|
735
|
+
const lookupDraft = useCallback(async () => {
|
|
736
|
+
if (!builderUrl) return DEFAULT_DRAFT;
|
|
737
|
+
const mine = ++seq.current;
|
|
738
|
+
const next = await readBuilderDraft(builderUrl);
|
|
739
|
+
if (mine !== seq.current) throw new Error(BUILDER_UNREACHABLE);
|
|
740
|
+
setCurrentDraft(
|
|
741
|
+
(prev) => prev && prev.key === next.key && prev.label === next.label ? prev : next
|
|
742
|
+
);
|
|
743
|
+
return next;
|
|
744
|
+
}, [builderUrl]);
|
|
745
|
+
const refreshBuilderSession = useCallback(async () => {
|
|
746
|
+
await lookupDraft().catch(() => {
|
|
747
|
+
});
|
|
748
|
+
}, [lookupDraft]);
|
|
749
|
+
useEffect(() => {
|
|
750
|
+
void refreshBuilderSession();
|
|
751
|
+
}, [refreshBuilderSession]);
|
|
752
|
+
return { currentDraft, currentDraftRef, connectBuilder, lookupDraft, refreshBuilderSession };
|
|
753
|
+
}
|
|
754
|
+
var backdropStyle = {
|
|
755
|
+
...cmsBackdrop,
|
|
756
|
+
zIndex: 10050,
|
|
757
|
+
fontFamily: "system-ui, sans-serif",
|
|
758
|
+
fontSize: 14
|
|
759
|
+
};
|
|
760
|
+
var boxStyle = {
|
|
761
|
+
...cmsBox,
|
|
762
|
+
width: "min(360px, 92vw)"
|
|
763
|
+
};
|
|
764
|
+
var btnStyle = cmsButton;
|
|
765
|
+
var primaryBtnStyle = {
|
|
766
|
+
...btnStyle,
|
|
767
|
+
background: "var(--columnus-cms-editor-accent, color-mix(in oklab, CanvasText 12%, transparent))",
|
|
768
|
+
color: "var(--columnus-cms-editor-accent-fg, CanvasText)",
|
|
769
|
+
fontWeight: 600
|
|
770
|
+
};
|
|
771
|
+
function InPlaceSwitchModal({
|
|
772
|
+
onChoose
|
|
773
|
+
}) {
|
|
774
|
+
return /* @__PURE__ */ jsx("span", { role: "dialog", "aria-modal": "true", "aria-label": "Unsaved field edits", style: backdropStyle, children: /* @__PURE__ */ jsxs("span", { style: boxStyle, onClick: (e) => e.stopPropagation(), children: [
|
|
775
|
+
/* @__PURE__ */ jsx("span", { style: { display: "block", fontWeight: 600, marginBottom: 8 }, children: "Unsaved edits in this field" }),
|
|
776
|
+
/* @__PURE__ */ jsx("span", { style: { display: "block", opacity: 0.8, marginBottom: 16, lineHeight: 1.4 }, children: "Apply them to the draft, discard them, or stay on this field." }),
|
|
777
|
+
/* @__PURE__ */ jsxs("span", { style: { display: "flex", justifyContent: "flex-end", gap: 8, flexWrap: "wrap" }, children: [
|
|
778
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: btnStyle, onClick: () => onChoose("stay"), children: "Stay" }),
|
|
779
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: btnStyle, onClick: () => onChoose("discard"), children: "Discard" }),
|
|
780
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: primaryBtnStyle, onClick: () => onChoose("apply"), children: "Apply" })
|
|
781
|
+
] })
|
|
782
|
+
] }) });
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// packages/@columnus/cms/src/edit/edit-surface.ts
|
|
786
|
+
var INPLACE_KINDS = /* @__PURE__ */ new Set(["markdown", "string", "number", "boolean"]);
|
|
787
|
+
function isCmsInPlaceFieldType(fieldType) {
|
|
788
|
+
return fieldType !== void 0 && INPLACE_KINDS.has(fieldType.kind);
|
|
789
|
+
}
|
|
790
|
+
function stampEditKey(table, rowId, field) {
|
|
791
|
+
return `${table}\0${rowId}\0${field}`;
|
|
792
|
+
}
|
|
793
|
+
function resolveEditSurface(requested, fieldType) {
|
|
794
|
+
if (requested === "dialog") return "dialog";
|
|
795
|
+
if (requested === "inplace") return isCmsInPlaceFieldType(fieldType) ? "inplace" : "dialog";
|
|
796
|
+
if (fieldType?.kind === "markdown") return "inplace";
|
|
797
|
+
return "dialog";
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// packages/@columnus/cms/src/create/compound-create.ts
|
|
801
|
+
function fail(message) {
|
|
802
|
+
throw new Error(`Invalid CMS compound-create recipe: ${message}`);
|
|
803
|
+
}
|
|
804
|
+
function tableFor(manifest, tableName) {
|
|
805
|
+
const table = manifest.tables.find((candidate) => candidate.name === tableName);
|
|
806
|
+
if (!table) fail(`unknown table "${tableName}"`);
|
|
807
|
+
return table;
|
|
808
|
+
}
|
|
809
|
+
function fieldFor(table, fieldName) {
|
|
810
|
+
const field = table.fields.find((candidate) => candidate.name === fieldName);
|
|
811
|
+
if (!field) fail(`unknown field "${table.name}.${fieldName}"`);
|
|
812
|
+
return field;
|
|
813
|
+
}
|
|
814
|
+
function topologicalOrder(records, bindings) {
|
|
815
|
+
const outgoing = new Map([...records.keys()].map((key) => [key, /* @__PURE__ */ new Set()]));
|
|
816
|
+
const indegree = new Map([...records.keys()].map((key) => [key, 0]));
|
|
817
|
+
for (const binding of bindings) {
|
|
818
|
+
if (binding.source.kind !== "recordId") continue;
|
|
819
|
+
const source = binding.source.record;
|
|
820
|
+
const target = binding.target.record;
|
|
821
|
+
const edges = outgoing.get(source);
|
|
822
|
+
if (edges.has(target)) continue;
|
|
823
|
+
edges.add(target);
|
|
824
|
+
indegree.set(target, (indegree.get(target) ?? 0) + 1);
|
|
825
|
+
}
|
|
826
|
+
const ready = [...records.keys()].filter((key) => indegree.get(key) === 0);
|
|
827
|
+
const ordered = [];
|
|
828
|
+
while (ready.length > 0) {
|
|
829
|
+
const key = ready.shift();
|
|
830
|
+
ordered.push(key);
|
|
831
|
+
for (const target of outgoing.get(key) ?? []) {
|
|
832
|
+
const next = (indegree.get(target) ?? 0) - 1;
|
|
833
|
+
indegree.set(target, next);
|
|
834
|
+
if (next === 0) ready.push(target);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
if (ordered.length !== records.size) {
|
|
838
|
+
const blocked = [...records.keys()].filter((key) => (indegree.get(key) ?? 0) > 0);
|
|
839
|
+
fail(`cyclic record-id bindings (${blocked.join(", ")})`);
|
|
840
|
+
}
|
|
841
|
+
return ordered;
|
|
842
|
+
}
|
|
843
|
+
function resolveCompoundCreateRecipe(manifest, recipe) {
|
|
844
|
+
if (recipe.records.length === 0) fail("at least one record is required");
|
|
845
|
+
const records = /* @__PURE__ */ new Map();
|
|
846
|
+
for (const record of recipe.records) {
|
|
847
|
+
if (!record.key.trim()) fail("record keys must not be empty");
|
|
848
|
+
if (records.has(record.key)) fail(`duplicate record key "${record.key}"`);
|
|
849
|
+
records.set(record.key, { key: record.key, table: tableFor(manifest, record.table) });
|
|
850
|
+
}
|
|
851
|
+
const bindings = recipe.bindings ?? [];
|
|
852
|
+
const relationFields = /* @__PURE__ */ new Map();
|
|
853
|
+
for (const binding of bindings) {
|
|
854
|
+
const target = records.get(binding.target.record);
|
|
855
|
+
if (!target) fail(`binding target record "${binding.target.record}" is not configured`);
|
|
856
|
+
const targetField = fieldFor(target.table, binding.target.field);
|
|
857
|
+
if (targetField.type.kind !== "id") {
|
|
858
|
+
fail(`binding target "${target.table.name}.${targetField.name}" must be an id field`);
|
|
859
|
+
}
|
|
860
|
+
if (relationFields.get(binding.target.record)?.has(binding.target.field)) {
|
|
861
|
+
fail(`multiple bindings target "${target.table.name}.${targetField.name}"`);
|
|
862
|
+
}
|
|
863
|
+
const fields = relationFields.get(binding.target.record) ?? /* @__PURE__ */ new Set();
|
|
864
|
+
fields.add(binding.target.field);
|
|
865
|
+
relationFields.set(binding.target.record, fields);
|
|
866
|
+
const sourceTable = binding.source.kind === "recordId" ? records.get(binding.source.record)?.table : tableFor(manifest, binding.source.table);
|
|
867
|
+
if (binding.source.kind === "recordId" && !sourceTable) {
|
|
868
|
+
fail(`binding source record "${binding.source.record}" is not configured`);
|
|
869
|
+
}
|
|
870
|
+
if (sourceTable.name !== targetField.type.table) {
|
|
871
|
+
fail(
|
|
872
|
+
`binding for "${target.table.name}.${targetField.name}" expects ${targetField.type.table}, received ${sourceTable.name}`
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
return {
|
|
877
|
+
recipe,
|
|
878
|
+
records,
|
|
879
|
+
bindings,
|
|
880
|
+
relationFields,
|
|
881
|
+
orderedRecordKeys: topologicalOrder(records, bindings)
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
function editableCompoundFields(resolved, recordKey, canProposeField2) {
|
|
885
|
+
const record = resolved.records.get(recordKey);
|
|
886
|
+
if (!record) throw new Error(`Unknown compound-create record "${recordKey}"`);
|
|
887
|
+
const relationFields = resolved.relationFields.get(recordKey) ?? /* @__PURE__ */ new Set();
|
|
888
|
+
return record.table.fields.filter(
|
|
889
|
+
(field) => !relationFields.has(field.name) && canProposeField2(record.table.name, field.name)
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
function compoundCreateUnavailableReason(recipeId, recipe, canProposeOp2, canProposeField2) {
|
|
893
|
+
if (!recipe) return `Unknown compound-create recipe "${recipeId}".`;
|
|
894
|
+
for (const key of recipe.orderedRecordKeys) {
|
|
895
|
+
const record = recipe.records.get(key);
|
|
896
|
+
if (!record) return `Unknown compound-create record "${key}".`;
|
|
897
|
+
if (!canProposeOp2(record.table.name, "insert")) {
|
|
898
|
+
return `You cannot create ${tableDisplayName(record.table)} records.`;
|
|
899
|
+
}
|
|
900
|
+
for (const field of record.table.fields) {
|
|
901
|
+
if (!field.optional && !canProposeField2(record.table.name, field.name)) {
|
|
902
|
+
return `You cannot set required field ${record.table.name}.${field.name}.`;
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
function buildCompoundCreateDraft(args) {
|
|
909
|
+
const ids = /* @__PURE__ */ new Map();
|
|
910
|
+
for (const key of args.resolved.orderedRecordKeys) ids.set(key, newProvisionalRowId());
|
|
911
|
+
const patches = [];
|
|
912
|
+
for (const key of args.resolved.orderedRecordKeys) {
|
|
913
|
+
const record = args.resolved.records.get(key);
|
|
914
|
+
if (!args.canProposeOp(record.table.name, "insert")) {
|
|
915
|
+
throw new Error(`Cannot insert into ${record.table.name}`);
|
|
916
|
+
}
|
|
917
|
+
const fields = { ...args.values[key] };
|
|
918
|
+
const relationFields = args.resolved.relationFields.get(key) ?? /* @__PURE__ */ new Set();
|
|
919
|
+
for (const field of relationFields) {
|
|
920
|
+
if (field in fields) {
|
|
921
|
+
throw new Error(`${record.table.name}.${field} is controlled by the compound recipe`);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
for (const fieldName of Object.keys(fields)) {
|
|
925
|
+
const field = fieldFor(record.table, fieldName);
|
|
926
|
+
if (!args.canProposeField(record.table.name, field.name)) {
|
|
927
|
+
throw new Error(`Cannot edit ${record.table.name}.${field.name}`);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
for (const binding of args.resolved.bindings) {
|
|
931
|
+
if (binding.target.record !== key) continue;
|
|
932
|
+
const value = binding.source.kind === "recordId" ? ids.get(binding.source.record) : args.context[binding.source.key];
|
|
933
|
+
const field = fieldFor(record.table, binding.target.field);
|
|
934
|
+
if ((value === void 0 || value === null || value === "") && !field.optional) {
|
|
935
|
+
throw new Error(
|
|
936
|
+
`Missing required compound-create context "${binding.source.kind === "contextId" ? binding.source.key : binding.source.record}"`
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
940
|
+
if (typeof value !== "string") {
|
|
941
|
+
throw new Error(
|
|
942
|
+
`Compound-create relation ${record.table.name}.${field.name} must be a string id`
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
if (!args.canProposeField(record.table.name, field.name)) {
|
|
946
|
+
throw new Error(`Cannot edit ${record.table.name}.${field.name}`);
|
|
947
|
+
}
|
|
948
|
+
fields[field.name] = value;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
for (const field of record.table.fields) {
|
|
952
|
+
if (!field.optional && !args.canProposeField(record.table.name, field.name)) {
|
|
953
|
+
throw new Error(`Required field ${record.table.name}.${field.name} is not editable`);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
const errors = validatePatch(fields, record.table.fields);
|
|
957
|
+
const first = Object.entries(errors)[0];
|
|
958
|
+
if (first) throw new Error(`${record.table.name}.${first[0]}: ${first[1]}`);
|
|
959
|
+
patches.push({ table: record.table.name, rowId: ids.get(key), op: "insert", fields });
|
|
960
|
+
}
|
|
961
|
+
return patches;
|
|
962
|
+
}
|
|
963
|
+
var SESSION_CHANGED = "The builder session changed since these changes were made: check the page, then try again";
|
|
964
|
+
var WORK_ELSEWHERE = "This page holds unsaved work from another builder session: discard it first";
|
|
965
|
+
var stagedFor = (key) => (entry) => entry.madeUnder !== null && entry.madeUnder.key === key;
|
|
966
|
+
var CmsContext = createContext(null);
|
|
967
|
+
var OUTCOME_DISPLAY_MS = 5e3;
|
|
968
|
+
var EMPTY_PROPOSALS = [];
|
|
969
|
+
var EMPTY_TABLE_ROWS = {};
|
|
970
|
+
function CmsProvider(props) {
|
|
971
|
+
const sessionKey = `${props.profileSlug}\0${props.editor?.user.id ?? "signed-out"}`;
|
|
972
|
+
return /* @__PURE__ */ jsx(CmsProviderSession, { ...props }, sessionKey);
|
|
973
|
+
}
|
|
974
|
+
function CmsProviderSession({
|
|
975
|
+
children,
|
|
976
|
+
editor,
|
|
977
|
+
readableTables,
|
|
978
|
+
manifest,
|
|
979
|
+
navigationTable,
|
|
980
|
+
createRecipes: createRecipesProp,
|
|
981
|
+
authActions,
|
|
982
|
+
profileSlug,
|
|
983
|
+
tableAccess,
|
|
984
|
+
proposalActions,
|
|
985
|
+
proposals = EMPTY_PROPOSALS,
|
|
986
|
+
proposalsLoading: proposalsLoadingProp,
|
|
987
|
+
proposalFeedError,
|
|
988
|
+
onProposalsChanged,
|
|
989
|
+
tableRows = EMPTY_TABLE_ROWS,
|
|
990
|
+
adapters: adaptersProp,
|
|
991
|
+
richtextHostAdapter
|
|
992
|
+
}) {
|
|
993
|
+
const [editMode, setEditModeState] = useState(false);
|
|
994
|
+
const [activeInPlaceKey, setActiveInPlaceKey] = useState(null);
|
|
995
|
+
const [pendingInPlaceKey, setPendingInPlaceKey] = useState(null);
|
|
996
|
+
const inPlaceHandlersRef = useRef(null);
|
|
997
|
+
const [inPlaceDirty, setInPlaceDirty] = useState(false);
|
|
998
|
+
const clearInPlaceSession = useCallback(() => {
|
|
999
|
+
inPlaceHandlersRef.current = null;
|
|
1000
|
+
setInPlaceDirty(false);
|
|
1001
|
+
setActiveInPlaceKey(null);
|
|
1002
|
+
setPendingInPlaceKey(null);
|
|
1003
|
+
}, []);
|
|
1004
|
+
const setEditMode = useCallback(
|
|
1005
|
+
(next) => {
|
|
1006
|
+
setEditModeState(next);
|
|
1007
|
+
if (!next) clearInPlaceSession();
|
|
1008
|
+
},
|
|
1009
|
+
[clearInPlaceSession]
|
|
1010
|
+
);
|
|
1011
|
+
const toggleEditMode = useCallback(() => setEditMode(!editMode), [editMode, setEditMode]);
|
|
1012
|
+
const registerInPlaceHandlers = useCallback((handlers) => {
|
|
1013
|
+
inPlaceHandlersRef.current = handlers;
|
|
1014
|
+
setInPlaceDirty(handlers?.isDirty() ?? false);
|
|
1015
|
+
}, []);
|
|
1016
|
+
const closeInPlaceEdit = useCallback(() => {
|
|
1017
|
+
clearInPlaceSession();
|
|
1018
|
+
}, [clearInPlaceSession]);
|
|
1019
|
+
const requestInPlaceEdit = useCallback(
|
|
1020
|
+
(table, rowId, field) => {
|
|
1021
|
+
const key = stampEditKey(table, rowId, field);
|
|
1022
|
+
if (activeInPlaceKey === key) return;
|
|
1023
|
+
if (activeInPlaceKey && inPlaceHandlersRef.current?.isDirty()) {
|
|
1024
|
+
setPendingInPlaceKey(key);
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
setPendingInPlaceKey(null);
|
|
1028
|
+
setActiveInPlaceKey(key);
|
|
1029
|
+
},
|
|
1030
|
+
[activeInPlaceKey]
|
|
1031
|
+
);
|
|
1032
|
+
const resolveInPlaceSwitch = useCallback(
|
|
1033
|
+
(choice) => {
|
|
1034
|
+
const pending = pendingInPlaceKey;
|
|
1035
|
+
if (choice === "stay") {
|
|
1036
|
+
setPendingInPlaceKey(null);
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
if (choice === "apply") {
|
|
1040
|
+
inPlaceHandlersRef.current?.apply();
|
|
1041
|
+
} else {
|
|
1042
|
+
inPlaceHandlersRef.current?.discard();
|
|
1043
|
+
}
|
|
1044
|
+
setPendingInPlaceKey(null);
|
|
1045
|
+
if (pending) {
|
|
1046
|
+
setActiveInPlaceKey(pending);
|
|
1047
|
+
}
|
|
1048
|
+
},
|
|
1049
|
+
[pendingInPlaceKey]
|
|
1050
|
+
);
|
|
1051
|
+
const navigation = useMemo(
|
|
1052
|
+
() => inferNavigationTable(manifest, navigationTable),
|
|
1053
|
+
[manifest, navigationTable]
|
|
1054
|
+
);
|
|
1055
|
+
const createRecipes = useMemo(
|
|
1056
|
+
() => new Map(
|
|
1057
|
+
Object.entries(createRecipesProp ?? {}).map(([id, recipe]) => [
|
|
1058
|
+
id,
|
|
1059
|
+
resolveCompoundCreateRecipe(manifest, recipe)
|
|
1060
|
+
])
|
|
1061
|
+
),
|
|
1062
|
+
[createRecipesProp, manifest]
|
|
1063
|
+
);
|
|
1064
|
+
const { currentDraft, currentDraftRef, connectBuilder, lookupDraft, refreshBuilderSession } = useBuilderDraft();
|
|
1065
|
+
const [changesOpen, setChangesOpen] = useState(false);
|
|
1066
|
+
const [highlight, setHighlight] = useState(null);
|
|
1067
|
+
const [draft, setDraft] = useState([]);
|
|
1068
|
+
const draftRef = useRef(draft);
|
|
1069
|
+
draftRef.current = draft;
|
|
1070
|
+
const editsMadeUnder = useRef(null);
|
|
1071
|
+
const [actionPhase, setActionPhase] = useState("idle");
|
|
1072
|
+
const [outcomes, setOutcomes] = useState(null);
|
|
1073
|
+
const [pendingReplaces, setPendingReplaces] = useState([]);
|
|
1074
|
+
const pendingReplacesRef = useRef(pendingReplaces);
|
|
1075
|
+
pendingReplacesRef.current = pendingReplaces;
|
|
1076
|
+
const localWorkFor = useCallback(
|
|
1077
|
+
(target) => (draftRef.current.length === 0 || madeFor(editsMadeUnder.current, target)) && pendingReplacesRef.current.every((entry) => madeFor(entry.madeUnder, target)),
|
|
1078
|
+
[]
|
|
1079
|
+
);
|
|
1080
|
+
useEffect(() => {
|
|
1081
|
+
if (currentDraft === null) return;
|
|
1082
|
+
editsMadeUnder.current ??= currentDraft;
|
|
1083
|
+
setPendingReplaces(
|
|
1084
|
+
(prev) => prev.some((entry) => entry.madeUnder === null) ? prev.map((entry) => ({ ...entry, madeUnder: entry.madeUnder ?? currentDraft })) : prev
|
|
1085
|
+
);
|
|
1086
|
+
}, [currentDraft]);
|
|
1087
|
+
const refuseWorkElsewhere = useCallback(() => {
|
|
1088
|
+
const current = currentDraftRef.current;
|
|
1089
|
+
if (current === null || localWorkFor(current)) return false;
|
|
1090
|
+
setOutcomes([{ id: "_error", outcome: "rejected", message: WORK_ELSEWHERE }]);
|
|
1091
|
+
return true;
|
|
1092
|
+
}, [currentDraftRef, localWorkFor]);
|
|
1093
|
+
const mutateDraft = useCallback(
|
|
1094
|
+
(next) => {
|
|
1095
|
+
if (refuseWorkElsewhere()) return;
|
|
1096
|
+
setDraft((prev) => {
|
|
1097
|
+
const value2 = next(prev);
|
|
1098
|
+
if (value2.length > 0 && prev.length === 0) {
|
|
1099
|
+
editsMadeUnder.current = currentDraftRef.current;
|
|
1100
|
+
}
|
|
1101
|
+
draftRef.current = value2;
|
|
1102
|
+
return value2;
|
|
1103
|
+
});
|
|
1104
|
+
},
|
|
1105
|
+
[currentDraftRef, refuseWorkElsewhere]
|
|
1106
|
+
);
|
|
1107
|
+
const clearDraft = useCallback(() => {
|
|
1108
|
+
draftRef.current = [];
|
|
1109
|
+
setDraft([]);
|
|
1110
|
+
}, []);
|
|
1111
|
+
const draftForWrite = useCallback(async () => {
|
|
1112
|
+
const shown = currentDraftRef.current;
|
|
1113
|
+
const target = await lookupDraft();
|
|
1114
|
+
if (shown && shown.key !== target.key || !localWorkFor(target)) {
|
|
1115
|
+
throw new Error(SESSION_CHANGED);
|
|
1116
|
+
}
|
|
1117
|
+
return target;
|
|
1118
|
+
}, [lookupDraft, currentDraftRef, localWorkFor]);
|
|
1119
|
+
const runProposalAction = useCallback(
|
|
1120
|
+
async (phase, work) => {
|
|
1121
|
+
setActionPhase(phase);
|
|
1122
|
+
try {
|
|
1123
|
+
await work();
|
|
1124
|
+
return true;
|
|
1125
|
+
} catch (err) {
|
|
1126
|
+
setOutcomes([
|
|
1127
|
+
{
|
|
1128
|
+
id: "_error",
|
|
1129
|
+
outcome: "rejected",
|
|
1130
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1131
|
+
}
|
|
1132
|
+
]);
|
|
1133
|
+
return false;
|
|
1134
|
+
} finally {
|
|
1135
|
+
setActionPhase("idle");
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
[]
|
|
1139
|
+
);
|
|
1140
|
+
const editorUserId = editor?.user.id ?? null;
|
|
1141
|
+
const projection = useMemo(
|
|
1142
|
+
() => createCmsProjection({
|
|
1143
|
+
liveRows: tableRows,
|
|
1144
|
+
draft,
|
|
1145
|
+
proposals,
|
|
1146
|
+
editorUserId,
|
|
1147
|
+
// Before the builder first answers, none of my drafts.
|
|
1148
|
+
draftKey: currentDraft ? currentDraft.key : null
|
|
1149
|
+
}),
|
|
1150
|
+
[tableRows, draft, proposals, editorUserId, currentDraft]
|
|
1151
|
+
);
|
|
1152
|
+
useEffect(() => {
|
|
1153
|
+
if (!proposalFeedError) return;
|
|
1154
|
+
setOutcomes([
|
|
1155
|
+
{
|
|
1156
|
+
id: "_error",
|
|
1157
|
+
outcome: "rejected",
|
|
1158
|
+
message: proposalFeedError
|
|
1159
|
+
}
|
|
1160
|
+
]);
|
|
1161
|
+
}, [proposalFeedError]);
|
|
1162
|
+
useEffect(() => {
|
|
1163
|
+
if (!outcomes) return;
|
|
1164
|
+
const timer = setTimeout(() => setOutcomes(null), OUTCOME_DISPLAY_MS);
|
|
1165
|
+
return () => clearTimeout(timer);
|
|
1166
|
+
}, [outcomes]);
|
|
1167
|
+
const myProposal = useMemo(
|
|
1168
|
+
() => (currentDraft && myDraft(proposals, editorUserId, currentDraft.key)) ?? null,
|
|
1169
|
+
[proposals, editorUserId, currentDraft]
|
|
1170
|
+
);
|
|
1171
|
+
const myProposalId = myProposal?.id ?? null;
|
|
1172
|
+
const labelledFor = useRef(null);
|
|
1173
|
+
useEffect(() => {
|
|
1174
|
+
if (!proposalActions || !currentDraft || proposalsLoadingProp) return;
|
|
1175
|
+
if (labelledFor.current === currentDraft) return;
|
|
1176
|
+
labelledFor.current = currentDraft;
|
|
1177
|
+
const label2 = currentDraft.label;
|
|
1178
|
+
if (!myProposal || label2 === void 0 || label2 === myProposal.draftLabel) return;
|
|
1179
|
+
void proposalActions.saveDraft({ patches: [], draftKey: currentDraft.key, draftLabel: label2 }).then(
|
|
1180
|
+
() => onProposalsChanged?.(),
|
|
1181
|
+
() => {
|
|
1182
|
+
}
|
|
1183
|
+
);
|
|
1184
|
+
}, [proposalActions, currentDraft, proposalsLoadingProp, myProposal, onProposalsChanged]);
|
|
1185
|
+
const applyFieldEdit = useCallback(
|
|
1186
|
+
(input2) => {
|
|
1187
|
+
mutateDraft((prev) => applyFieldToDraft(prev, input2));
|
|
1188
|
+
},
|
|
1189
|
+
[mutateDraft]
|
|
1190
|
+
);
|
|
1191
|
+
const registerPendingReplace = useCallback(
|
|
1192
|
+
(input2) => {
|
|
1193
|
+
if (refuseWorkElsewhere()) return;
|
|
1194
|
+
const kind = input2.kind ?? "file";
|
|
1195
|
+
setPendingReplaces((prev) => {
|
|
1196
|
+
const next = prev.filter((entry) => entry.assetId !== input2.assetId);
|
|
1197
|
+
const madeUnder = currentDraftRef.current;
|
|
1198
|
+
next.push({ assetId: input2.assetId, file: input2.file, kind, madeUnder });
|
|
1199
|
+
return next;
|
|
1200
|
+
});
|
|
1201
|
+
},
|
|
1202
|
+
[currentDraftRef, refuseWorkElsewhere]
|
|
1203
|
+
);
|
|
1204
|
+
const discardDraft = useCallback(() => {
|
|
1205
|
+
inPlaceHandlersRef.current?.discard();
|
|
1206
|
+
clearDraft();
|
|
1207
|
+
setPendingReplaces([]);
|
|
1208
|
+
setInPlaceDirty(false);
|
|
1209
|
+
}, [clearDraft]);
|
|
1210
|
+
const saveDraft = useCallback(async () => {
|
|
1211
|
+
if (inPlaceHandlersRef.current?.isDirty()) {
|
|
1212
|
+
inPlaceHandlersRef.current.apply();
|
|
1213
|
+
}
|
|
1214
|
+
const current = draftRef.current;
|
|
1215
|
+
if (!proposalActions || current.length === 0) return false;
|
|
1216
|
+
return runProposalAction("saving-draft", async () => {
|
|
1217
|
+
const target = await draftForWrite();
|
|
1218
|
+
const saved = await proposalActions.saveDraft({
|
|
1219
|
+
patches: current,
|
|
1220
|
+
draftKey: target.key,
|
|
1221
|
+
...target.label === void 0 ? {} : { draftLabel: target.label }
|
|
1222
|
+
});
|
|
1223
|
+
if (saved.status === "withdrawn") {
|
|
1224
|
+
setOutcomes([{ id: saved.proposalId, outcome: "withdrawn" }]);
|
|
1225
|
+
}
|
|
1226
|
+
if (draftRef.current === current) clearDraft();
|
|
1227
|
+
setInPlaceDirty(false);
|
|
1228
|
+
onProposalsChanged?.();
|
|
1229
|
+
});
|
|
1230
|
+
}, [proposalActions, runProposalAction, draftForWrite, onProposalsChanged, clearDraft]);
|
|
1231
|
+
const publishKeyed = useCallback(
|
|
1232
|
+
async (key, staged) => {
|
|
1233
|
+
if (!proposalActions) return;
|
|
1234
|
+
const mine = myDraft(proposals, editorUserId, key);
|
|
1235
|
+
if (!mine) throw new Error("This draft is no longer active");
|
|
1236
|
+
const result = await proposalActions.publishMine({
|
|
1237
|
+
draftKey: key,
|
|
1238
|
+
...mine.draftRevision === void 0 ? {} : { expectedRevision: mine.draftRevision }
|
|
1239
|
+
});
|
|
1240
|
+
const uploads = pendingReplacesRef.current.filter(staged);
|
|
1241
|
+
const replaceFile = adaptersProp?.fieldsDataAdapter?.replaceFile;
|
|
1242
|
+
if (result.outcome === "accepted" && uploads.length > 0) {
|
|
1243
|
+
if (!replaceFile) {
|
|
1244
|
+
throw new Error("Media replace is not available in this session");
|
|
1245
|
+
}
|
|
1246
|
+
for (const entry of uploads) {
|
|
1247
|
+
await replaceFile(entry.assetId, entry.file, entry.kind);
|
|
1248
|
+
}
|
|
1249
|
+
setPendingReplaces((prev) => prev.filter((entry) => !uploads.includes(entry)));
|
|
1250
|
+
}
|
|
1251
|
+
setOutcomes([result]);
|
|
1252
|
+
onProposalsChanged?.();
|
|
1253
|
+
},
|
|
1254
|
+
[proposalActions, proposals, editorUserId, onProposalsChanged, adaptersProp]
|
|
1255
|
+
);
|
|
1256
|
+
const withdrawKeyed = useCallback(
|
|
1257
|
+
async (key, staged) => {
|
|
1258
|
+
if (!proposalActions) return;
|
|
1259
|
+
const withdrawn = await proposalActions.withdrawMine({ draftKey: key });
|
|
1260
|
+
setPendingReplaces((prev) => prev.filter((entry) => !staged(entry)));
|
|
1261
|
+
setOutcomes([{ id: withdrawn.id, outcome: "withdrawn" }]);
|
|
1262
|
+
onProposalsChanged?.();
|
|
1263
|
+
},
|
|
1264
|
+
[proposalActions, onProposalsChanged]
|
|
1265
|
+
);
|
|
1266
|
+
const publishMine = useCallback(async () => {
|
|
1267
|
+
if (!proposalActions || !myProposalId) return;
|
|
1268
|
+
await runProposalAction("publishing", async () => {
|
|
1269
|
+
const target = await draftForWrite();
|
|
1270
|
+
await publishKeyed(target.key, (entry) => madeFor(entry.madeUnder, target));
|
|
1271
|
+
});
|
|
1272
|
+
}, [proposalActions, myProposalId, runProposalAction, draftForWrite, publishKeyed]);
|
|
1273
|
+
const withdrawMine = useCallback(async () => {
|
|
1274
|
+
if (!proposalActions || !myProposalId) return;
|
|
1275
|
+
await runProposalAction("withdrawing", async () => {
|
|
1276
|
+
const target = await draftForWrite();
|
|
1277
|
+
await withdrawKeyed(target.key, (entry) => madeFor(entry.madeUnder, target));
|
|
1278
|
+
});
|
|
1279
|
+
}, [proposalActions, myProposalId, runProposalAction, draftForWrite, withdrawKeyed]);
|
|
1280
|
+
const publishDraft = useCallback(
|
|
1281
|
+
(key) => runProposalAction("publishing", () => publishKeyed(key, stagedFor(key))),
|
|
1282
|
+
[runProposalAction, publishKeyed]
|
|
1283
|
+
);
|
|
1284
|
+
const withdrawDraft = useCallback(
|
|
1285
|
+
(key) => runProposalAction("withdrawing", () => withdrawKeyed(key, stagedFor(key))),
|
|
1286
|
+
[runProposalAction, withdrawKeyed]
|
|
1287
|
+
);
|
|
1288
|
+
const discard = useCallback(
|
|
1289
|
+
(key, items, patches = []) => runProposalAction("saving-draft", async () => {
|
|
1290
|
+
if (!proposalActions) return;
|
|
1291
|
+
const saved = await proposalActions.saveDraft({
|
|
1292
|
+
patches,
|
|
1293
|
+
discard: items,
|
|
1294
|
+
draftKey: key
|
|
1295
|
+
});
|
|
1296
|
+
if (saved.status === "withdrawn") {
|
|
1297
|
+
setOutcomes([{ id: saved.proposalId, outcome: "withdrawn" }]);
|
|
1298
|
+
}
|
|
1299
|
+
onProposalsChanged?.();
|
|
1300
|
+
}),
|
|
1301
|
+
[runProposalAction, proposalActions, onProposalsChanged]
|
|
1302
|
+
);
|
|
1303
|
+
const resolve = useCallback(
|
|
1304
|
+
(key, expectedRevision, choices) => runProposalAction("saving-draft", async () => {
|
|
1305
|
+
if (!proposalActions) return;
|
|
1306
|
+
await proposalActions.resolve({ draftKey: key, expectedRevision, choices });
|
|
1307
|
+
onProposalsChanged?.();
|
|
1308
|
+
}),
|
|
1309
|
+
[runProposalAction, proposalActions, onProposalsChanged]
|
|
1310
|
+
);
|
|
1311
|
+
const addInsert = useCallback(
|
|
1312
|
+
(input2) => {
|
|
1313
|
+
const patches = buildInsertDraft({
|
|
1314
|
+
manifest,
|
|
1315
|
+
table: input2.table,
|
|
1316
|
+
title: input2.title,
|
|
1317
|
+
fields: input2.fields
|
|
1318
|
+
});
|
|
1319
|
+
mutateDraft((prev) => mergeDraftIntoProposal(prev, patches));
|
|
1320
|
+
setEditMode(true);
|
|
1321
|
+
return patches;
|
|
1322
|
+
},
|
|
1323
|
+
[manifest, setEditMode, mutateDraft]
|
|
1324
|
+
);
|
|
1325
|
+
const adapters = useMemo(() => {
|
|
1326
|
+
const defaults = createDefaultCmsRichtextAdapters(manifest);
|
|
1327
|
+
const { resolveAssetUrls, fieldsDataAdapter: hostAdapter, ...hostRest } = adaptersProp ?? {};
|
|
1328
|
+
const base = hostAdapter ?? createInertFieldsDataAdapter(manifest);
|
|
1329
|
+
const projected = withProjectedRows(
|
|
1330
|
+
{
|
|
1331
|
+
...base,
|
|
1332
|
+
renderMarkdownField: base.renderMarkdownField ?? defaultRenderMarkdownField,
|
|
1333
|
+
createReferenceRow: async (table, fields) => {
|
|
1334
|
+
const patches = addInsert({ table, fields: stripSystemFields(fields) });
|
|
1335
|
+
const insert = patches.find((patch) => patch.op === "insert" && patch.table === table);
|
|
1336
|
+
if (!insert) throw new Error(`Draft insert for ${table} produced no row id`);
|
|
1337
|
+
return insert.rowId;
|
|
1338
|
+
},
|
|
1339
|
+
createRowDefaults: {
|
|
1340
|
+
saveLabel: "Add to draft",
|
|
1341
|
+
overlayZIndex: CMS_ROW_EDITOR_Z_INDEX
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1344
|
+
projection,
|
|
1345
|
+
manifest
|
|
1346
|
+
);
|
|
1347
|
+
const fieldsDataAdapter = editor ? projected : {
|
|
1348
|
+
...projected,
|
|
1349
|
+
useAssetDisplay: (assetIds) => {
|
|
1350
|
+
const resolved = resolveAssetUrls?.(assetIds);
|
|
1351
|
+
const urls = /* @__PURE__ */ new Map();
|
|
1352
|
+
const slots = /* @__PURE__ */ new Map();
|
|
1353
|
+
const focals = /* @__PURE__ */ new Map();
|
|
1354
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
1355
|
+
if (!resolved) {
|
|
1356
|
+
return { urls, slots, focals, metadata };
|
|
1357
|
+
}
|
|
1358
|
+
for (const id of assetIds) {
|
|
1359
|
+
const entry = resolved.get(id);
|
|
1360
|
+
if (entry === void 0) continue;
|
|
1361
|
+
if (typeof entry === "string" || entry === null) {
|
|
1362
|
+
urls.set(id, entry);
|
|
1363
|
+
slots.set(id, { url: entry, pending: false, failed: false });
|
|
1364
|
+
focals.set(id, { x: 0.5, y: 0.5 });
|
|
1365
|
+
continue;
|
|
1366
|
+
}
|
|
1367
|
+
urls.set(id, entry.url);
|
|
1368
|
+
slots.set(id, {
|
|
1369
|
+
url: entry.url,
|
|
1370
|
+
pending: entry.pending ?? false,
|
|
1371
|
+
failed: entry.failed ?? false
|
|
1372
|
+
});
|
|
1373
|
+
focals.set(id, entry.focalPoint ?? { x: 0.5, y: 0.5 });
|
|
1374
|
+
if (entry.size !== void 0) {
|
|
1375
|
+
metadata.set(id, { contentType: entry.contentType, size: entry.size });
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return { urls, slots, focals, metadata };
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
return {
|
|
1382
|
+
...defaults,
|
|
1383
|
+
...hostRest,
|
|
1384
|
+
renderMarkdownEditor: adaptersProp?.renderMarkdownEditor ?? defaults.renderMarkdownEditor,
|
|
1385
|
+
renderFieldEditor: adaptersProp?.renderFieldEditor,
|
|
1386
|
+
fieldsDataAdapter,
|
|
1387
|
+
inplaceEditorClassName: adaptersProp?.inplaceEditorClassName
|
|
1388
|
+
};
|
|
1389
|
+
}, [adaptersProp, addInsert, editor, manifest, projection]);
|
|
1390
|
+
const applyRowEdit = useCallback(
|
|
1391
|
+
(input2) => {
|
|
1392
|
+
mutateDraft((prev) => applyRowToDraft(prev, input2));
|
|
1393
|
+
setEditMode(true);
|
|
1394
|
+
},
|
|
1395
|
+
[setEditMode, mutateDraft]
|
|
1396
|
+
);
|
|
1397
|
+
const addDelete = useCallback(
|
|
1398
|
+
(input2) => {
|
|
1399
|
+
mutateDraft((prev) => applyDeleteToDraft(prev, input2));
|
|
1400
|
+
setEditMode(true);
|
|
1401
|
+
},
|
|
1402
|
+
[setEditMode, mutateDraft]
|
|
1403
|
+
);
|
|
1404
|
+
const canProposeOpFn = useCallback(
|
|
1405
|
+
(table, op) => canProposeOp(tableAccess, table),
|
|
1406
|
+
[tableAccess]
|
|
1407
|
+
);
|
|
1408
|
+
const canProposeFieldFn = useCallback(
|
|
1409
|
+
(table, field) => canProposeField(tableAccess, table),
|
|
1410
|
+
[tableAccess]
|
|
1411
|
+
);
|
|
1412
|
+
const createCompound = useCallback(
|
|
1413
|
+
(input2) => {
|
|
1414
|
+
const resolved = createRecipes.get(input2.recipeId);
|
|
1415
|
+
if (!resolved) throw new Error(`Unknown CMS compound-create recipe "${input2.recipeId}"`);
|
|
1416
|
+
const patches = buildCompoundCreateDraft({
|
|
1417
|
+
resolved,
|
|
1418
|
+
context: input2.context ?? {},
|
|
1419
|
+
values: input2.values,
|
|
1420
|
+
canProposeOp: canProposeOpFn,
|
|
1421
|
+
canProposeField: canProposeFieldFn
|
|
1422
|
+
});
|
|
1423
|
+
mutateDraft((prev) => mergeDraftIntoProposal(prev, patches));
|
|
1424
|
+
setEditMode(true);
|
|
1425
|
+
return patches;
|
|
1426
|
+
},
|
|
1427
|
+
[canProposeFieldFn, canProposeOpFn, createRecipes, mutateDraft, setEditMode]
|
|
1428
|
+
);
|
|
1429
|
+
const value = useMemo(
|
|
1430
|
+
() => ({
|
|
1431
|
+
editor,
|
|
1432
|
+
editMode: editor !== null && editMode,
|
|
1433
|
+
setEditMode,
|
|
1434
|
+
toggleEditMode,
|
|
1435
|
+
readableTables,
|
|
1436
|
+
manifest,
|
|
1437
|
+
navigation,
|
|
1438
|
+
createRecipes,
|
|
1439
|
+
authActions: authActions ?? null,
|
|
1440
|
+
profileSlug,
|
|
1441
|
+
tableAccess,
|
|
1442
|
+
proposalActions: proposalActions ?? null,
|
|
1443
|
+
tableRows,
|
|
1444
|
+
projection,
|
|
1445
|
+
adapters,
|
|
1446
|
+
draft,
|
|
1447
|
+
proposals,
|
|
1448
|
+
myProposalId,
|
|
1449
|
+
currentDraft,
|
|
1450
|
+
connectBuilder,
|
|
1451
|
+
refreshBuilderSession,
|
|
1452
|
+
publishDraft,
|
|
1453
|
+
withdrawDraft,
|
|
1454
|
+
discard,
|
|
1455
|
+
resolve,
|
|
1456
|
+
changesOpen,
|
|
1457
|
+
setChangesOpen,
|
|
1458
|
+
highlight,
|
|
1459
|
+
setHighlight,
|
|
1460
|
+
actionPhase,
|
|
1461
|
+
loadingProposals: Boolean(proposalsLoadingProp),
|
|
1462
|
+
outcomes,
|
|
1463
|
+
applyFieldEdit,
|
|
1464
|
+
discardDraft,
|
|
1465
|
+
saveDraft,
|
|
1466
|
+
publishMine,
|
|
1467
|
+
withdrawMine,
|
|
1468
|
+
addInsert,
|
|
1469
|
+
createCompound,
|
|
1470
|
+
applyRowEdit,
|
|
1471
|
+
addDelete,
|
|
1472
|
+
canProposeOp: canProposeOpFn,
|
|
1473
|
+
canProposeField: canProposeFieldFn,
|
|
1474
|
+
activeInPlaceKey,
|
|
1475
|
+
requestInPlaceEdit,
|
|
1476
|
+
closeInPlaceEdit,
|
|
1477
|
+
registerInPlaceHandlers,
|
|
1478
|
+
inPlaceDirty,
|
|
1479
|
+
setInPlaceDirty,
|
|
1480
|
+
inPlaceSwitchPending: pendingInPlaceKey !== null,
|
|
1481
|
+
registerPendingReplace,
|
|
1482
|
+
stagedReplaceCount: pendingReplaces.length
|
|
1483
|
+
}),
|
|
1484
|
+
[
|
|
1485
|
+
editor,
|
|
1486
|
+
editMode,
|
|
1487
|
+
toggleEditMode,
|
|
1488
|
+
readableTables,
|
|
1489
|
+
manifest,
|
|
1490
|
+
navigation,
|
|
1491
|
+
createRecipes,
|
|
1492
|
+
authActions,
|
|
1493
|
+
profileSlug,
|
|
1494
|
+
tableAccess,
|
|
1495
|
+
proposalActions,
|
|
1496
|
+
tableRows,
|
|
1497
|
+
projection,
|
|
1498
|
+
adapters,
|
|
1499
|
+
draft,
|
|
1500
|
+
proposals,
|
|
1501
|
+
myProposalId,
|
|
1502
|
+
currentDraft,
|
|
1503
|
+
connectBuilder,
|
|
1504
|
+
refreshBuilderSession,
|
|
1505
|
+
publishDraft,
|
|
1506
|
+
withdrawDraft,
|
|
1507
|
+
discard,
|
|
1508
|
+
resolve,
|
|
1509
|
+
changesOpen,
|
|
1510
|
+
highlight,
|
|
1511
|
+
actionPhase,
|
|
1512
|
+
proposalsLoadingProp,
|
|
1513
|
+
outcomes,
|
|
1514
|
+
applyFieldEdit,
|
|
1515
|
+
discardDraft,
|
|
1516
|
+
saveDraft,
|
|
1517
|
+
publishMine,
|
|
1518
|
+
withdrawMine,
|
|
1519
|
+
addInsert,
|
|
1520
|
+
createCompound,
|
|
1521
|
+
applyRowEdit,
|
|
1522
|
+
addDelete,
|
|
1523
|
+
canProposeOpFn,
|
|
1524
|
+
canProposeFieldFn,
|
|
1525
|
+
activeInPlaceKey,
|
|
1526
|
+
requestInPlaceEdit,
|
|
1527
|
+
closeInPlaceEdit,
|
|
1528
|
+
registerInPlaceHandlers,
|
|
1529
|
+
inPlaceDirty,
|
|
1530
|
+
pendingInPlaceKey,
|
|
1531
|
+
setEditMode,
|
|
1532
|
+
registerPendingReplace,
|
|
1533
|
+
pendingReplaces.length
|
|
1534
|
+
]
|
|
1535
|
+
);
|
|
1536
|
+
return /* @__PURE__ */ jsx(CmsContext.Provider, { value, children: /* @__PURE__ */ jsx(FieldsDataProvider, { adapter: adapters.fieldsDataAdapter, children: /* @__PURE__ */ jsx(CmsTableRowsContext.Provider, { value: tableRows, children: /* @__PURE__ */ jsxs(DefaultRichtextHostProvider, { manifest, adapter: richtextHostAdapter, children: [
|
|
1537
|
+
children,
|
|
1538
|
+
pendingInPlaceKey ? /* @__PURE__ */ jsx(InPlaceSwitchModal, { onChoose: resolveInPlaceSwitch }) : null
|
|
1539
|
+
] }) }) }) });
|
|
1540
|
+
}
|
|
1541
|
+
function useCms() {
|
|
1542
|
+
const ctx = useContext(CmsContext);
|
|
1543
|
+
if (!ctx) throw new Error("useCms must be used within CmsProvider");
|
|
1544
|
+
return ctx;
|
|
1545
|
+
}
|
|
1546
|
+
function useCmsOptional() {
|
|
1547
|
+
return useContext(CmsContext);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// packages/@columnus/cms/src/stamps/related.ts
|
|
1551
|
+
function idFieldRelatedTable(fieldType) {
|
|
1552
|
+
const target = fieldType ? refTarget(fieldType) : null;
|
|
1553
|
+
return target && !target.many ? target.table : void 0;
|
|
1554
|
+
}
|
|
1555
|
+
function stampRelatedId(value) {
|
|
1556
|
+
if (typeof value !== "string" || value === "") return null;
|
|
1557
|
+
return value;
|
|
1558
|
+
}
|
|
1559
|
+
function relatedRowPreview(args) {
|
|
1560
|
+
if (args.relatedRow) return fallbackPreviewLabel(args.relatedRow, args.relatedFields);
|
|
1561
|
+
if (args.displayPreview) return args.displayPreview;
|
|
1562
|
+
return formatIdShort(args.id);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// packages/@columnus/cms/src/stamps/storage-display.ts
|
|
1566
|
+
function stampMediaUrl(value, resolved) {
|
|
1567
|
+
if (typeof value !== "string" || value === "") return null;
|
|
1568
|
+
if (isHttpUrl(value)) return value;
|
|
1569
|
+
return resolved || null;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
// packages/@columnus/cms/src/stamps/use-cms-related-row.ts
|
|
1573
|
+
function useCmsRelatedRow(table, id) {
|
|
1574
|
+
const cms = useCmsOptional();
|
|
1575
|
+
const rowId = stampRelatedId(id);
|
|
1576
|
+
if (!cms?.editor || !table || !rowId) return null;
|
|
1577
|
+
return cms.projection.row({ table, rowId })?.value ?? null;
|
|
1578
|
+
}
|
|
1579
|
+
var fallbackFieldsAdapter = createInertFieldsDataAdapter();
|
|
1580
|
+
var MEDIA_VERSION_CONFIRM = "This creates a new Media version of the same item.";
|
|
1581
|
+
var backdropStyle2 = { ...cmsBackdrop, zIndex: CMS_FIELD_EDITOR_Z_INDEX };
|
|
1582
|
+
var boxStyle2 = {
|
|
1583
|
+
...cmsBox,
|
|
1584
|
+
width: "min(480px, 92vw)",
|
|
1585
|
+
maxHeight: "80vh",
|
|
1586
|
+
overflow: "auto",
|
|
1587
|
+
fontFamily: "system-ui, sans-serif",
|
|
1588
|
+
fontSize: 14,
|
|
1589
|
+
lineHeight: 1.4
|
|
1590
|
+
};
|
|
1591
|
+
var labelStyle = {
|
|
1592
|
+
display: "block",
|
|
1593
|
+
fontSize: 12,
|
|
1594
|
+
opacity: 0.75,
|
|
1595
|
+
marginBottom: 6
|
|
1596
|
+
};
|
|
1597
|
+
var footerStyle = {
|
|
1598
|
+
display: "flex",
|
|
1599
|
+
justifyContent: "flex-end",
|
|
1600
|
+
gap: 8,
|
|
1601
|
+
marginTop: 16
|
|
1602
|
+
};
|
|
1603
|
+
var buttonStyle = cmsButton;
|
|
1604
|
+
var primaryButtonStyle = {
|
|
1605
|
+
...buttonStyle,
|
|
1606
|
+
background: "color-mix(in oklab, CanvasText 12%, transparent)",
|
|
1607
|
+
fontWeight: 600
|
|
1608
|
+
};
|
|
1609
|
+
function isMediaFieldKind(type) {
|
|
1610
|
+
return type?.kind === "image" || type?.kind === "file";
|
|
1611
|
+
}
|
|
1612
|
+
function FieldEditorDialog({
|
|
1613
|
+
open,
|
|
1614
|
+
table,
|
|
1615
|
+
rowId,
|
|
1616
|
+
field,
|
|
1617
|
+
fieldType,
|
|
1618
|
+
optional,
|
|
1619
|
+
assetProfile,
|
|
1620
|
+
value,
|
|
1621
|
+
onApply,
|
|
1622
|
+
onClose
|
|
1623
|
+
}) {
|
|
1624
|
+
const cms = useCmsOptional();
|
|
1625
|
+
const [staged, setStaged] = useState(value);
|
|
1626
|
+
const markdownCompleted = useRef(false);
|
|
1627
|
+
const pendingReplaceFile = useRef(null);
|
|
1628
|
+
const pendingReplaceKind = useRef("file");
|
|
1629
|
+
const stagedRef = useRef(staged);
|
|
1630
|
+
stagedRef.current = staged;
|
|
1631
|
+
useEffect(() => {
|
|
1632
|
+
if (open) {
|
|
1633
|
+
setStaged(value);
|
|
1634
|
+
markdownCompleted.current = false;
|
|
1635
|
+
pendingReplaceFile.current = null;
|
|
1636
|
+
}
|
|
1637
|
+
}, [open, value]);
|
|
1638
|
+
const baseAdapter = cms?.adapters.fieldsDataAdapter ?? fallbackFieldsAdapter;
|
|
1639
|
+
const fieldsAdapter = useMemo(() => {
|
|
1640
|
+
if (!isMediaFieldKind(fieldType)) return baseAdapter;
|
|
1641
|
+
const baseUpload = baseAdapter.uploadFile;
|
|
1642
|
+
return {
|
|
1643
|
+
...baseAdapter,
|
|
1644
|
+
uploadFile: async (file, kind = "file", target) => {
|
|
1645
|
+
const existingId = toDocumentId(stagedRef.current);
|
|
1646
|
+
if (existingId && isValidAssetId(existingId)) {
|
|
1647
|
+
if (!window.confirm(MEDIA_VERSION_CONFIRM)) {
|
|
1648
|
+
throw new Error("Replace cancelled");
|
|
1649
|
+
}
|
|
1650
|
+
pendingReplaceFile.current = file;
|
|
1651
|
+
pendingReplaceKind.current = kind === "image" ? "image" : "file";
|
|
1652
|
+
return existingId;
|
|
1653
|
+
}
|
|
1654
|
+
if (!baseUpload) {
|
|
1655
|
+
throw new Error("Media upload is not available");
|
|
1656
|
+
}
|
|
1657
|
+
pendingReplaceFile.current = null;
|
|
1658
|
+
return baseUpload(file, kind, target);
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
}, [baseAdapter, fieldType]);
|
|
1662
|
+
if (!open) return null;
|
|
1663
|
+
const customEditor = cms?.adapters.renderFieldEditor?.({
|
|
1664
|
+
table,
|
|
1665
|
+
field,
|
|
1666
|
+
type: fieldType,
|
|
1667
|
+
value: staged,
|
|
1668
|
+
onChange: setStaged
|
|
1669
|
+
});
|
|
1670
|
+
const markdownEditor = !customEditor && fieldType?.kind === "markdown" ? cms?.adapters.renderMarkdownEditor?.({
|
|
1671
|
+
table,
|
|
1672
|
+
field,
|
|
1673
|
+
value: typeof staged === "string" ? staged : "",
|
|
1674
|
+
onComplete: (next) => {
|
|
1675
|
+
if (markdownCompleted.current) return;
|
|
1676
|
+
markdownCompleted.current = true;
|
|
1677
|
+
if (next !== void 0) onApply(next);
|
|
1678
|
+
onClose();
|
|
1679
|
+
}
|
|
1680
|
+
}) : null;
|
|
1681
|
+
if (markdownEditor) return markdownEditor;
|
|
1682
|
+
if (typeof document === "undefined") return null;
|
|
1683
|
+
const resolvedType = fieldType ?? { kind: "string" };
|
|
1684
|
+
const readOnly = resolvedType.kind === "literal" || resolvedType.kind === "null";
|
|
1685
|
+
const handleApply = () => {
|
|
1686
|
+
const replaceFile = pendingReplaceFile.current;
|
|
1687
|
+
const assetId = toDocumentId(staged);
|
|
1688
|
+
if (replaceFile && assetId && isValidAssetId(assetId)) {
|
|
1689
|
+
cms?.registerPendingReplace({
|
|
1690
|
+
assetId,
|
|
1691
|
+
file: replaceFile,
|
|
1692
|
+
kind: pendingReplaceKind.current
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
pendingReplaceFile.current = null;
|
|
1696
|
+
onApply(staged);
|
|
1697
|
+
onClose();
|
|
1698
|
+
};
|
|
1699
|
+
return createPortal(
|
|
1700
|
+
/* @__PURE__ */ jsx(
|
|
1701
|
+
"div",
|
|
1702
|
+
{
|
|
1703
|
+
role: "dialog",
|
|
1704
|
+
"aria-modal": "true",
|
|
1705
|
+
"aria-label": `Edit ${table}.${field} (row ${rowId})`,
|
|
1706
|
+
style: backdropStyle2,
|
|
1707
|
+
onClick: (event) => {
|
|
1708
|
+
if (isPickerOverlayTarget(event.target)) return;
|
|
1709
|
+
onClose();
|
|
1710
|
+
},
|
|
1711
|
+
children: /* @__PURE__ */ jsxs("div", { style: boxStyle2, onClick: (event) => event.stopPropagation(), children: [
|
|
1712
|
+
/* @__PURE__ */ jsxs("div", { style: { fontSize: 15, fontWeight: 600, marginBottom: 12 }, children: [
|
|
1713
|
+
table,
|
|
1714
|
+
" \xB7 ",
|
|
1715
|
+
field
|
|
1716
|
+
] }),
|
|
1717
|
+
/* @__PURE__ */ jsxs("div", { style: { fontSize: 11, opacity: 0.6, marginBottom: 12 }, children: [
|
|
1718
|
+
"Row ",
|
|
1719
|
+
/* @__PURE__ */ jsx("code", { children: rowId })
|
|
1720
|
+
] }),
|
|
1721
|
+
customEditor ?? /* @__PURE__ */ jsxs(FieldsDataProvider, { adapter: fieldsAdapter, children: [
|
|
1722
|
+
/* @__PURE__ */ jsx("label", { htmlFor: `cms-field-${field}`, style: labelStyle, children: field }),
|
|
1723
|
+
resolvedType.kind === "image" && staged != null ? /* @__PURE__ */ jsx("div", { style: { marginBottom: 12 }, children: /* @__PURE__ */ jsx(ImageCell, { assetId: staged, size: "preview" }) }) : null,
|
|
1724
|
+
/* @__PURE__ */ jsx(
|
|
1725
|
+
FieldInput,
|
|
1726
|
+
{
|
|
1727
|
+
type: resolvedType,
|
|
1728
|
+
value: staged,
|
|
1729
|
+
optional,
|
|
1730
|
+
assetProfile,
|
|
1731
|
+
onChange: setStaged,
|
|
1732
|
+
allowCreate: (refTable) => cms?.canProposeOp(refTable, "insert") ?? false,
|
|
1733
|
+
manifest: cms?.manifest,
|
|
1734
|
+
inputId: `cms-field-${field}`,
|
|
1735
|
+
uploadTarget: {
|
|
1736
|
+
table,
|
|
1737
|
+
field,
|
|
1738
|
+
...assetProfile ? { profile: assetProfile.profile } : {}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
)
|
|
1742
|
+
] }),
|
|
1743
|
+
/* @__PURE__ */ jsxs("div", { style: footerStyle, children: [
|
|
1744
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: buttonStyle, onClick: onClose, children: "Cancel" }),
|
|
1745
|
+
/* @__PURE__ */ jsx(
|
|
1746
|
+
"button",
|
|
1747
|
+
{
|
|
1748
|
+
type: "button",
|
|
1749
|
+
style: primaryButtonStyle,
|
|
1750
|
+
onClick: handleApply,
|
|
1751
|
+
disabled: readOnly && !customEditor,
|
|
1752
|
+
children: "Apply"
|
|
1753
|
+
}
|
|
1754
|
+
)
|
|
1755
|
+
] })
|
|
1756
|
+
] })
|
|
1757
|
+
}
|
|
1758
|
+
),
|
|
1759
|
+
document.body
|
|
1760
|
+
);
|
|
1761
|
+
}
|
|
1762
|
+
var MarkdownEditorLazy = lazy(
|
|
1763
|
+
() => import('./editor-543ARQ6S.js').then((m) => ({ default: m.MarkdownEditor }))
|
|
1764
|
+
);
|
|
1765
|
+
var MarkdownInsertPickersLazy = lazy(
|
|
1766
|
+
() => import('./editor-543ARQ6S.js').then((m) => ({ default: m.MarkdownInsertPickers }))
|
|
1767
|
+
);
|
|
1768
|
+
var shellStyle = {
|
|
1769
|
+
display: "block",
|
|
1770
|
+
width: "100%",
|
|
1771
|
+
minWidth: 0,
|
|
1772
|
+
background: "transparent",
|
|
1773
|
+
color: "inherit",
|
|
1774
|
+
padding: 0,
|
|
1775
|
+
boxSizing: "border-box",
|
|
1776
|
+
font: "inherit",
|
|
1777
|
+
lineHeight: "inherit"
|
|
1778
|
+
};
|
|
1779
|
+
var markdownShellStyle = {
|
|
1780
|
+
display: "block",
|
|
1781
|
+
width: "100%",
|
|
1782
|
+
minWidth: 0,
|
|
1783
|
+
background: "transparent",
|
|
1784
|
+
color: "var(--columnus-cms-editor-fg, CanvasText)",
|
|
1785
|
+
padding: 0,
|
|
1786
|
+
boxSizing: "border-box",
|
|
1787
|
+
fontFamily: "system-ui, sans-serif",
|
|
1788
|
+
fontSize: 14,
|
|
1789
|
+
lineHeight: 1.4
|
|
1790
|
+
};
|
|
1791
|
+
var footerStyle2 = {
|
|
1792
|
+
display: "flex",
|
|
1793
|
+
justifyContent: "flex-end",
|
|
1794
|
+
gap: 8,
|
|
1795
|
+
marginTop: 8
|
|
1796
|
+
};
|
|
1797
|
+
var markdownFooterStyle = {
|
|
1798
|
+
...footerStyle2,
|
|
1799
|
+
clear: "both",
|
|
1800
|
+
paddingTop: 8
|
|
1801
|
+
};
|
|
1802
|
+
var btnStyle2 = {
|
|
1803
|
+
padding: "6px 12px",
|
|
1804
|
+
fontFamily: "system-ui, sans-serif",
|
|
1805
|
+
fontSize: 13,
|
|
1806
|
+
borderRadius: 6,
|
|
1807
|
+
border: "1px solid color-mix(in oklab, currentColor 35%, transparent)",
|
|
1808
|
+
background: "transparent",
|
|
1809
|
+
color: "inherit",
|
|
1810
|
+
cursor: "pointer"
|
|
1811
|
+
};
|
|
1812
|
+
var primaryBtnStyle2 = {
|
|
1813
|
+
...btnStyle2,
|
|
1814
|
+
background: "var(--columnus-cms-editor-accent, color-mix(in oklab, CanvasText 12%, transparent))",
|
|
1815
|
+
color: "var(--columnus-cms-editor-accent-fg, CanvasText)",
|
|
1816
|
+
fontWeight: 600
|
|
1817
|
+
};
|
|
1818
|
+
var inputStyle = {
|
|
1819
|
+
width: "100%",
|
|
1820
|
+
padding: "4px 0",
|
|
1821
|
+
font: "inherit",
|
|
1822
|
+
lineHeight: "inherit",
|
|
1823
|
+
borderRadius: 0,
|
|
1824
|
+
border: "none",
|
|
1825
|
+
borderBottom: "1px solid color-mix(in oklab, currentColor 35%, transparent)",
|
|
1826
|
+
boxSizing: "border-box",
|
|
1827
|
+
background: "transparent",
|
|
1828
|
+
color: "inherit",
|
|
1829
|
+
outline: "none"
|
|
1830
|
+
};
|
|
1831
|
+
function InPlaceFieldEditor({
|
|
1832
|
+
table,
|
|
1833
|
+
rowId,
|
|
1834
|
+
field,
|
|
1835
|
+
fieldType,
|
|
1836
|
+
optional,
|
|
1837
|
+
value,
|
|
1838
|
+
onApplied,
|
|
1839
|
+
onCancelled
|
|
1840
|
+
}) {
|
|
1841
|
+
const cms = useCms();
|
|
1842
|
+
const initial = fieldType.kind === "boolean" ? value === true : fieldType.kind === "number" ? value === void 0 || value === null ? "" : String(value) : (fieldType.kind === "string" || fieldType.kind === "markdown") && typeof value !== "string" ? "" : value;
|
|
1843
|
+
const [staged, setStaged] = useState(initial);
|
|
1844
|
+
const stagedRef = useRef(staged);
|
|
1845
|
+
stagedRef.current = staged;
|
|
1846
|
+
const markdownRef = useRef(null);
|
|
1847
|
+
const initialRef = useRef(initial);
|
|
1848
|
+
const { applyFieldEdit, registerInPlaceHandlers, setInPlaceDirty } = cms;
|
|
1849
|
+
const insertPickers = useMarkdownInsertPickers(markdownRef);
|
|
1850
|
+
const isMarkdown = fieldType.kind === "markdown";
|
|
1851
|
+
const isDirty = useCallback(() => {
|
|
1852
|
+
if (fieldType.kind === "markdown") {
|
|
1853
|
+
const current = markdownRef.current?.flushPendingChange?.() ?? String(stagedRef.current ?? "");
|
|
1854
|
+
return !Object.is(current, initialRef.current);
|
|
1855
|
+
}
|
|
1856
|
+
return !Object.is(stagedRef.current, initialRef.current);
|
|
1857
|
+
}, [fieldType.kind]);
|
|
1858
|
+
const commitStaged = useCallback(
|
|
1859
|
+
(next) => {
|
|
1860
|
+
stagedRef.current = next;
|
|
1861
|
+
setStaged(next);
|
|
1862
|
+
setInPlaceDirty(!Object.is(next, initialRef.current));
|
|
1863
|
+
},
|
|
1864
|
+
[setInPlaceDirty]
|
|
1865
|
+
);
|
|
1866
|
+
const apply = useCallback(() => {
|
|
1867
|
+
let next = stagedRef.current;
|
|
1868
|
+
if (fieldType.kind === "markdown") {
|
|
1869
|
+
next = markdownRef.current?.flushPendingChange?.() ?? String(stagedRef.current ?? "");
|
|
1870
|
+
} else if (fieldType.kind === "number") {
|
|
1871
|
+
const raw = String(stagedRef.current ?? "").trim();
|
|
1872
|
+
if (raw === "") {
|
|
1873
|
+
next = optional ? void 0 : 0;
|
|
1874
|
+
} else {
|
|
1875
|
+
next = Number(raw);
|
|
1876
|
+
if (typeof next === "number" && Number.isNaN(next)) return;
|
|
1877
|
+
}
|
|
1878
|
+
} else if (fieldType.kind === "boolean") {
|
|
1879
|
+
next = stagedRef.current === true;
|
|
1880
|
+
} else if (fieldType.kind === "string" && optional && next === "") {
|
|
1881
|
+
next = void 0;
|
|
1882
|
+
}
|
|
1883
|
+
applyFieldEdit({ table, rowId, field, value: next });
|
|
1884
|
+
onApplied();
|
|
1885
|
+
}, [applyFieldEdit, field, fieldType.kind, onApplied, optional, rowId, table]);
|
|
1886
|
+
const discard = useCallback(() => {
|
|
1887
|
+
onCancelled();
|
|
1888
|
+
}, [onCancelled]);
|
|
1889
|
+
useEffect(() => {
|
|
1890
|
+
registerInPlaceHandlers({
|
|
1891
|
+
isDirty,
|
|
1892
|
+
apply,
|
|
1893
|
+
discard
|
|
1894
|
+
});
|
|
1895
|
+
return () => registerInPlaceHandlers(null);
|
|
1896
|
+
}, [apply, discard, isDirty, registerInPlaceHandlers]);
|
|
1897
|
+
useEffect(() => {
|
|
1898
|
+
if (!isMarkdown) return;
|
|
1899
|
+
function onKey(event) {
|
|
1900
|
+
if (event.key !== "Escape") return;
|
|
1901
|
+
if (insertPickers.shouldBlockDismiss()) return;
|
|
1902
|
+
event.preventDefault();
|
|
1903
|
+
onCancelled();
|
|
1904
|
+
}
|
|
1905
|
+
window.addEventListener("keydown", onKey);
|
|
1906
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
1907
|
+
}, [insertPickers.shouldBlockDismiss, isMarkdown, onCancelled]);
|
|
1908
|
+
function stop(event) {
|
|
1909
|
+
event.stopPropagation();
|
|
1910
|
+
}
|
|
1911
|
+
function onKeyDown(event) {
|
|
1912
|
+
if (event.key !== "Escape") return;
|
|
1913
|
+
if (isMarkdown && insertPickers.shouldBlockDismiss()) return;
|
|
1914
|
+
event.preventDefault();
|
|
1915
|
+
event.stopPropagation();
|
|
1916
|
+
discard();
|
|
1917
|
+
}
|
|
1918
|
+
const className = cms.adapters.inplaceEditorClassName;
|
|
1919
|
+
const inputId = `cms-inplace-${field}`;
|
|
1920
|
+
let body;
|
|
1921
|
+
if (isMarkdown) {
|
|
1922
|
+
body = /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("span", { style: { opacity: 0.6 }, children: "Loading editor\u2026" }), children: /* @__PURE__ */ jsx(
|
|
1923
|
+
MarkdownEditorLazy,
|
|
1924
|
+
{
|
|
1925
|
+
ref: markdownRef,
|
|
1926
|
+
manifest: cms.manifest,
|
|
1927
|
+
value: typeof staged === "string" ? staged : String(staged ?? ""),
|
|
1928
|
+
onChange: commitStaged,
|
|
1929
|
+
className,
|
|
1930
|
+
flowLayout: true,
|
|
1931
|
+
onInsertRecordLink: insertPickers.onInsertRecordLink,
|
|
1932
|
+
onInsertRecordTable: insertPickers.onInsertRecordTable
|
|
1933
|
+
}
|
|
1934
|
+
) });
|
|
1935
|
+
} else if (fieldType.kind === "boolean") {
|
|
1936
|
+
body = /* @__PURE__ */ jsxs("label", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
1937
|
+
/* @__PURE__ */ jsx(
|
|
1938
|
+
"input",
|
|
1939
|
+
{
|
|
1940
|
+
id: inputId,
|
|
1941
|
+
type: "checkbox",
|
|
1942
|
+
checked: staged === true,
|
|
1943
|
+
onChange: (e) => commitStaged(e.target.checked)
|
|
1944
|
+
}
|
|
1945
|
+
),
|
|
1946
|
+
field
|
|
1947
|
+
] });
|
|
1948
|
+
} else if (fieldType.kind === "number") {
|
|
1949
|
+
body = /* @__PURE__ */ jsx(
|
|
1950
|
+
"input",
|
|
1951
|
+
{
|
|
1952
|
+
id: inputId,
|
|
1953
|
+
style: inputStyle,
|
|
1954
|
+
type: "number",
|
|
1955
|
+
value: typeof staged === "string" || typeof staged === "number" ? String(staged) : "",
|
|
1956
|
+
onChange: (e) => commitStaged(e.target.value),
|
|
1957
|
+
onKeyDown
|
|
1958
|
+
}
|
|
1959
|
+
);
|
|
1960
|
+
} else {
|
|
1961
|
+
body = /* @__PURE__ */ jsx(
|
|
1962
|
+
"input",
|
|
1963
|
+
{
|
|
1964
|
+
id: inputId,
|
|
1965
|
+
style: inputStyle,
|
|
1966
|
+
type: "text",
|
|
1967
|
+
value: typeof staged === "string" ? staged : String(staged ?? ""),
|
|
1968
|
+
onChange: (e) => commitStaged(e.target.value),
|
|
1969
|
+
onKeyDown,
|
|
1970
|
+
placeholder: "string"
|
|
1971
|
+
}
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1975
|
+
/* @__PURE__ */ jsxs(
|
|
1976
|
+
"span",
|
|
1977
|
+
{
|
|
1978
|
+
role: "group",
|
|
1979
|
+
"aria-label": `Edit ${table}.${field}`,
|
|
1980
|
+
style: isMarkdown ? markdownShellStyle : shellStyle,
|
|
1981
|
+
className: isMarkdown ? className : void 0,
|
|
1982
|
+
"data-columnus-inplace": "true",
|
|
1983
|
+
"data-columnus-inplace-flow": isMarkdown ? "true" : void 0,
|
|
1984
|
+
onClick: stop,
|
|
1985
|
+
onKeyDown,
|
|
1986
|
+
children: [
|
|
1987
|
+
body,
|
|
1988
|
+
/* @__PURE__ */ jsxs("span", { style: isMarkdown ? markdownFooterStyle : footerStyle2, children: [
|
|
1989
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: btnStyle2, onClick: discard, children: "Cancel" }),
|
|
1990
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: primaryBtnStyle2, onClick: apply, children: "Apply" })
|
|
1991
|
+
] })
|
|
1992
|
+
]
|
|
1993
|
+
}
|
|
1994
|
+
),
|
|
1995
|
+
isMarkdown ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(MarkdownInsertPickersLazy, { manifest: cms.manifest, session: insertPickers }) }) : null
|
|
1996
|
+
] });
|
|
1997
|
+
}
|
|
1998
|
+
var IMAGE_REJECT = "Only image files are allowed";
|
|
1999
|
+
function mimeLooksLikeImage(mime) {
|
|
2000
|
+
return mime === "" || mime.startsWith("image/");
|
|
2001
|
+
}
|
|
2002
|
+
function pickFirstImage(files) {
|
|
2003
|
+
if (!files) return null;
|
|
2004
|
+
for (const file of Array.from(files)) {
|
|
2005
|
+
if (validateFileForKind(file, "image") === null) return file;
|
|
2006
|
+
}
|
|
2007
|
+
return null;
|
|
2008
|
+
}
|
|
2009
|
+
function transferLooksLikeImage(dt) {
|
|
2010
|
+
if (!dt) return false;
|
|
2011
|
+
const items = dt.items;
|
|
2012
|
+
if (items && items.length > 0) {
|
|
2013
|
+
for (let i = 0; i < items.length; i++) {
|
|
2014
|
+
const item2 = items[i];
|
|
2015
|
+
if (item2?.kind !== "file") continue;
|
|
2016
|
+
if (mimeLooksLikeImage(item2.type)) return true;
|
|
2017
|
+
}
|
|
2018
|
+
return false;
|
|
2019
|
+
}
|
|
2020
|
+
return Array.from(dt.types ?? []).includes("Files");
|
|
2021
|
+
}
|
|
2022
|
+
function relatedIsInside(current, related) {
|
|
2023
|
+
return current instanceof Node && related instanceof Node && current.contains(related);
|
|
2024
|
+
}
|
|
2025
|
+
function useStampMediaDrop(args) {
|
|
2026
|
+
const { enabled, uploadFile, apply, table, field, profile } = args;
|
|
2027
|
+
const [uploading, setUploading] = useState(false);
|
|
2028
|
+
const [error, setError] = useState(null);
|
|
2029
|
+
const [dragOver, setDragOver] = useState(false);
|
|
2030
|
+
const uploadingRef = useRef(false);
|
|
2031
|
+
const onDragAllow = useCallback(
|
|
2032
|
+
(event) => {
|
|
2033
|
+
if (!enabled) return;
|
|
2034
|
+
event.preventDefault();
|
|
2035
|
+
event.stopPropagation();
|
|
2036
|
+
if (uploadingRef.current) return;
|
|
2037
|
+
const looksLike = transferLooksLikeImage(event.dataTransfer);
|
|
2038
|
+
setDragOver(looksLike);
|
|
2039
|
+
if (looksLike && event.dataTransfer) event.dataTransfer.dropEffect = "copy";
|
|
2040
|
+
},
|
|
2041
|
+
[enabled]
|
|
2042
|
+
);
|
|
2043
|
+
const onDragLeave = useCallback(
|
|
2044
|
+
(event) => {
|
|
2045
|
+
if (!enabled) return;
|
|
2046
|
+
event.preventDefault();
|
|
2047
|
+
event.stopPropagation();
|
|
2048
|
+
if (relatedIsInside(event.currentTarget, event.relatedTarget)) return;
|
|
2049
|
+
setDragOver(false);
|
|
2050
|
+
},
|
|
2051
|
+
[enabled]
|
|
2052
|
+
);
|
|
2053
|
+
const onDrop = useCallback(
|
|
2054
|
+
(event) => {
|
|
2055
|
+
if (!enabled) return;
|
|
2056
|
+
event.preventDefault();
|
|
2057
|
+
event.stopPropagation();
|
|
2058
|
+
setDragOver(false);
|
|
2059
|
+
if (uploadingRef.current) return;
|
|
2060
|
+
const file = pickFirstImage(event.dataTransfer?.files);
|
|
2061
|
+
if (!file) {
|
|
2062
|
+
setError(IMAGE_REJECT);
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
if (!uploadFile) {
|
|
2066
|
+
setError("Upload is not available");
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
setError(null);
|
|
2070
|
+
uploadingRef.current = true;
|
|
2071
|
+
setUploading(true);
|
|
2072
|
+
void (async () => {
|
|
2073
|
+
try {
|
|
2074
|
+
const assetId = await uploadFile(file, "image", {
|
|
2075
|
+
table,
|
|
2076
|
+
field,
|
|
2077
|
+
...profile ? { profile } : {}
|
|
2078
|
+
});
|
|
2079
|
+
apply(assetId);
|
|
2080
|
+
} catch (err) {
|
|
2081
|
+
const message = err instanceof Error ? err.message : "Upload failed";
|
|
2082
|
+
console.error("[columnus/cms] stamp media upload failed", err);
|
|
2083
|
+
setError(message);
|
|
2084
|
+
} finally {
|
|
2085
|
+
uploadingRef.current = false;
|
|
2086
|
+
setUploading(false);
|
|
2087
|
+
}
|
|
2088
|
+
})();
|
|
2089
|
+
},
|
|
2090
|
+
[apply, enabled, field, profile, table, uploadFile]
|
|
2091
|
+
);
|
|
2092
|
+
return {
|
|
2093
|
+
uploading,
|
|
2094
|
+
error,
|
|
2095
|
+
dragOver,
|
|
2096
|
+
dropHandlers: { onDragEnter: onDragAllow, onDragOver: onDragAllow, onDragLeave, onDrop }
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
var EDIT_OUTLINE = {
|
|
2100
|
+
outline: "2px dashed color-mix(in oklab, CanvasText 35%, transparent)",
|
|
2101
|
+
outlineOffset: "2px"
|
|
2102
|
+
};
|
|
2103
|
+
var MY_CHANGE_OUTLINE = {
|
|
2104
|
+
outline: "2px dashed color-mix(in oklab, royalblue 75%, transparent)",
|
|
2105
|
+
outlineOffset: "2px"
|
|
2106
|
+
};
|
|
2107
|
+
var OTHER_CHANGE_OUTLINE = {
|
|
2108
|
+
outline: "2px dashed color-mix(in oklab, mediumorchid 75%, transparent)",
|
|
2109
|
+
outlineOffset: "2px"
|
|
2110
|
+
};
|
|
2111
|
+
var CHANGE_HIGHLIGHT = {
|
|
2112
|
+
outline: "3px solid color-mix(in oklab, darkorange 85%, transparent)",
|
|
2113
|
+
outlineOffset: "2px"
|
|
2114
|
+
};
|
|
2115
|
+
var badgeBaseStyle = {
|
|
2116
|
+
position: "absolute",
|
|
2117
|
+
top: 0,
|
|
2118
|
+
left: 0,
|
|
2119
|
+
zIndex: 2,
|
|
2120
|
+
display: "inline-flex",
|
|
2121
|
+
alignItems: "center",
|
|
2122
|
+
transform: "translate(-25%, -55%)",
|
|
2123
|
+
padding: "1px 6px",
|
|
2124
|
+
borderRadius: 999,
|
|
2125
|
+
fontSize: 10,
|
|
2126
|
+
fontWeight: 600,
|
|
2127
|
+
letterSpacing: "0.02em",
|
|
2128
|
+
textTransform: "uppercase",
|
|
2129
|
+
cursor: "pointer",
|
|
2130
|
+
border: "1px solid color-mix(in oklab, CanvasText 20%, transparent)",
|
|
2131
|
+
fontFamily: "system-ui, sans-serif",
|
|
2132
|
+
opacity: 0.7,
|
|
2133
|
+
pointerEvents: "auto",
|
|
2134
|
+
whiteSpace: "nowrap",
|
|
2135
|
+
lineHeight: 1.2,
|
|
2136
|
+
maxWidth: 220,
|
|
2137
|
+
overflow: "hidden",
|
|
2138
|
+
textOverflow: "ellipsis"
|
|
2139
|
+
};
|
|
2140
|
+
var draftBadgeStyle = {
|
|
2141
|
+
...badgeBaseStyle,
|
|
2142
|
+
background: "color-mix(in oklab, gold 55%, transparent)",
|
|
2143
|
+
color: "color-mix(in oklab, CanvasText 90%, black)"
|
|
2144
|
+
};
|
|
2145
|
+
var pendingBadgeStyle = {
|
|
2146
|
+
...badgeBaseStyle,
|
|
2147
|
+
background: "color-mix(in oklab, dodgerblue 50%, transparent)",
|
|
2148
|
+
color: "color-mix(in oklab, CanvasText 90%, black)"
|
|
2149
|
+
};
|
|
2150
|
+
var infoPopoverStyle = {
|
|
2151
|
+
position: "absolute",
|
|
2152
|
+
top: "100%",
|
|
2153
|
+
left: "50%",
|
|
2154
|
+
zIndex: 3,
|
|
2155
|
+
display: "flex",
|
|
2156
|
+
flexDirection: "column",
|
|
2157
|
+
gap: 2,
|
|
2158
|
+
marginTop: 4,
|
|
2159
|
+
transform: "translateX(-50%)",
|
|
2160
|
+
padding: "6px 8px",
|
|
2161
|
+
borderRadius: 6,
|
|
2162
|
+
background: "color-mix(in oklab, Canvas 92%, transparent)",
|
|
2163
|
+
border: "1px solid color-mix(in oklab, CanvasText 25%, transparent)",
|
|
2164
|
+
boxShadow: "0 2px 10px color-mix(in oklab, CanvasText 20%, transparent)",
|
|
2165
|
+
whiteSpace: "nowrap",
|
|
2166
|
+
fontFamily: "system-ui, sans-serif",
|
|
2167
|
+
fontSize: 11,
|
|
2168
|
+
fontWeight: 500,
|
|
2169
|
+
textTransform: "none",
|
|
2170
|
+
letterSpacing: "normal",
|
|
2171
|
+
maxWidth: 240
|
|
2172
|
+
};
|
|
2173
|
+
var infoDismissStyle = {
|
|
2174
|
+
appearance: "none",
|
|
2175
|
+
border: "none",
|
|
2176
|
+
background: "transparent",
|
|
2177
|
+
color: "inherit",
|
|
2178
|
+
cursor: "pointer",
|
|
2179
|
+
font: "inherit",
|
|
2180
|
+
fontSize: 11,
|
|
2181
|
+
padding: "2px 0 0",
|
|
2182
|
+
opacity: 0.7,
|
|
2183
|
+
textAlign: "left"
|
|
2184
|
+
};
|
|
2185
|
+
function authorLabelFor(proposal, mine, editorEmail) {
|
|
2186
|
+
if (mine) return editorEmail ? `You (${editorEmail})` : "You";
|
|
2187
|
+
if (proposal?.createdByUserId) return proposal.createdByUserId;
|
|
2188
|
+
return "Another editor";
|
|
2189
|
+
}
|
|
2190
|
+
function StampBadgeInfo({
|
|
2191
|
+
authorLabel,
|
|
2192
|
+
conflictHint,
|
|
2193
|
+
onDismiss
|
|
2194
|
+
}) {
|
|
2195
|
+
return /* @__PURE__ */ jsxs("span", { role: "dialog", "aria-label": "Proposal info", style: infoPopoverStyle, children: [
|
|
2196
|
+
/* @__PURE__ */ jsx("span", { children: authorLabel }),
|
|
2197
|
+
conflictHint ? /* @__PURE__ */ jsx("span", { style: { color: "color-mix(in oklab, darkorange 80%, CanvasText)" }, children: conflictHint }) : null,
|
|
2198
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: infoDismissStyle, onClick: onDismiss, children: "Close" })
|
|
2199
|
+
] });
|
|
2200
|
+
}
|
|
2201
|
+
var EMPTY_MEDIA_SLOT = {
|
|
2202
|
+
display: "block",
|
|
2203
|
+
minWidth: 48,
|
|
2204
|
+
minHeight: 48,
|
|
2205
|
+
borderRadius: 6,
|
|
2206
|
+
border: "2px dashed color-mix(in oklab, CanvasText 35%, transparent)"
|
|
2207
|
+
};
|
|
2208
|
+
var MEDIA_DRAG_OVER = {
|
|
2209
|
+
outline: "2px solid color-mix(in oklab, dodgerblue 65%, transparent)",
|
|
2210
|
+
outlineOffset: "2px",
|
|
2211
|
+
background: "color-mix(in oklab, dodgerblue 10%, transparent)"
|
|
2212
|
+
};
|
|
2213
|
+
var MEDIA_UPLOADING_OVERLAY = {
|
|
2214
|
+
position: "absolute",
|
|
2215
|
+
inset: 0,
|
|
2216
|
+
zIndex: 4,
|
|
2217
|
+
display: "flex",
|
|
2218
|
+
alignItems: "center",
|
|
2219
|
+
justifyContent: "center",
|
|
2220
|
+
background: "color-mix(in oklab, Canvas 75%, transparent)",
|
|
2221
|
+
fontFamily: "system-ui, sans-serif",
|
|
2222
|
+
fontSize: 12,
|
|
2223
|
+
fontWeight: 600
|
|
2224
|
+
};
|
|
2225
|
+
var MEDIA_DROP_ERROR = {
|
|
2226
|
+
position: "absolute",
|
|
2227
|
+
left: 0,
|
|
2228
|
+
right: 0,
|
|
2229
|
+
bottom: 0,
|
|
2230
|
+
zIndex: 4,
|
|
2231
|
+
padding: "4px 6px",
|
|
2232
|
+
background: "color-mix(in oklab, crimson 80%, Canvas)",
|
|
2233
|
+
color: "Canvas",
|
|
2234
|
+
fontFamily: "system-ui, sans-serif",
|
|
2235
|
+
fontSize: 11,
|
|
2236
|
+
fontWeight: 500
|
|
2237
|
+
};
|
|
2238
|
+
function StampMediaDisplay({
|
|
2239
|
+
cms,
|
|
2240
|
+
kind,
|
|
2241
|
+
effectiveValue,
|
|
2242
|
+
...display
|
|
2243
|
+
}) {
|
|
2244
|
+
const custom = typeof display.children === "function" || Boolean(display.format);
|
|
2245
|
+
const raw = typeof effectiveValue === "string" ? effectiveValue : "";
|
|
2246
|
+
const assetIds = !custom && raw && !isHttpUrl(raw) ? [raw] : [];
|
|
2247
|
+
const { urls, slots, focals } = cms.adapters.fieldsDataAdapter.useAssetDisplay(assetIds);
|
|
2248
|
+
if (custom) {
|
|
2249
|
+
return resolveStampDisplay({ ...display, hasEditor: Boolean(cms.editor) });
|
|
2250
|
+
}
|
|
2251
|
+
const slot = slots.get(raw);
|
|
2252
|
+
const focal = focals.get(raw) ?? { x: 0.5, y: 0.5 };
|
|
2253
|
+
const pending = slot?.pending ?? false;
|
|
2254
|
+
const failed = slot?.failed ?? false;
|
|
2255
|
+
if (kind === "image" && (pending || failed)) {
|
|
2256
|
+
return /* @__PURE__ */ jsx(
|
|
2257
|
+
"span",
|
|
2258
|
+
{
|
|
2259
|
+
"data-columnus-media-pending": pending ? "true" : void 0,
|
|
2260
|
+
"data-columnus-media-failed": failed ? "true" : void 0,
|
|
2261
|
+
"data-columnus-focal-x": String(focal.x),
|
|
2262
|
+
"data-columnus-focal-y": String(focal.y),
|
|
2263
|
+
style: {
|
|
2264
|
+
...EMPTY_MEDIA_SLOT,
|
|
2265
|
+
display: "grid",
|
|
2266
|
+
placeItems: "center",
|
|
2267
|
+
fontSize: 11,
|
|
2268
|
+
color: "color-mix(in oklab, CanvasText 55%, transparent)"
|
|
2269
|
+
},
|
|
2270
|
+
"aria-label": pending ? "Processing" : "Processing failed",
|
|
2271
|
+
children: pending ? "\u2026" : "!"
|
|
2272
|
+
}
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
const url = stampMediaUrl(effectiveValue, urls.get(raw));
|
|
2276
|
+
if (url) {
|
|
2277
|
+
return kind === "image" ? /* @__PURE__ */ jsx(
|
|
2278
|
+
"img",
|
|
2279
|
+
{
|
|
2280
|
+
src: url,
|
|
2281
|
+
alt: "",
|
|
2282
|
+
"data-columnus-focal-x": String(focal.x),
|
|
2283
|
+
"data-columnus-focal-y": String(focal.y),
|
|
2284
|
+
style: {
|
|
2285
|
+
width: "100%",
|
|
2286
|
+
height: "100%",
|
|
2287
|
+
objectFit: "cover",
|
|
2288
|
+
objectPosition: focalObjectPosition(focal)
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
) : /* @__PURE__ */ jsx("a", { href: url, children: formatIdShort(raw || url) });
|
|
2292
|
+
}
|
|
2293
|
+
if (isEmptyStampValue(effectiveValue) && cms.editMode) {
|
|
2294
|
+
return display.empty ?? /* @__PURE__ */ jsx("span", { "data-columnus-media-empty": "true", style: EMPTY_MEDIA_SLOT });
|
|
2295
|
+
}
|
|
2296
|
+
return display.empty ?? null;
|
|
2297
|
+
}
|
|
2298
|
+
function StampIdRelatedDisplay({
|
|
2299
|
+
cms,
|
|
2300
|
+
table,
|
|
2301
|
+
field,
|
|
2302
|
+
effectiveValue,
|
|
2303
|
+
...display
|
|
2304
|
+
}) {
|
|
2305
|
+
const hasEditor = Boolean(cms.editor);
|
|
2306
|
+
const relatedTable = idFieldRelatedTable(manifestField(cms.manifest, table, field)?.type);
|
|
2307
|
+
const id = stampRelatedId(effectiveValue);
|
|
2308
|
+
const relatedRow = useCmsRelatedRow(relatedTable, id);
|
|
2309
|
+
const displayIds = hasEditor && relatedTable && id && looksLikeId(id) && !relatedRow ? [id] : [];
|
|
2310
|
+
const displayMap = cms.adapters.fieldsDataAdapter.useDisplayValues(
|
|
2311
|
+
relatedTable ?? "",
|
|
2312
|
+
displayIds
|
|
2313
|
+
);
|
|
2314
|
+
const relatedPreview = hasEditor && relatedTable && id ? relatedRowPreview({
|
|
2315
|
+
relatedRow,
|
|
2316
|
+
relatedFields: manifestFields(cms.manifest, relatedTable),
|
|
2317
|
+
displayPreview: displayMap.get(id)?.preview,
|
|
2318
|
+
id
|
|
2319
|
+
}) : void 0;
|
|
2320
|
+
return resolveStampDisplay({
|
|
2321
|
+
...display,
|
|
2322
|
+
hasEditor,
|
|
2323
|
+
relatedRow: relatedTable ? relatedRow : void 0,
|
|
2324
|
+
relatedPreview
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
function StampKindDisplay({
|
|
2328
|
+
cms,
|
|
2329
|
+
table,
|
|
2330
|
+
field,
|
|
2331
|
+
effectiveValue,
|
|
2332
|
+
...display
|
|
2333
|
+
}) {
|
|
2334
|
+
const fieldKind = manifestField(cms.manifest, table, field)?.type.kind;
|
|
2335
|
+
if (fieldKind === "image" || fieldKind === "file") {
|
|
2336
|
+
return /* @__PURE__ */ jsx(StampMediaDisplay, { cms, kind: fieldKind, effectiveValue, ...display });
|
|
2337
|
+
}
|
|
2338
|
+
if (fieldKind === "id") {
|
|
2339
|
+
return /* @__PURE__ */ jsx(
|
|
2340
|
+
StampIdRelatedDisplay,
|
|
2341
|
+
{
|
|
2342
|
+
cms,
|
|
2343
|
+
table,
|
|
2344
|
+
field,
|
|
2345
|
+
effectiveValue,
|
|
2346
|
+
...display
|
|
2347
|
+
}
|
|
2348
|
+
);
|
|
2349
|
+
}
|
|
2350
|
+
return resolveStampDisplay({ ...display, hasEditor: Boolean(cms.editor) });
|
|
2351
|
+
}
|
|
2352
|
+
function CmsFieldStamp({
|
|
2353
|
+
children,
|
|
2354
|
+
format,
|
|
2355
|
+
value,
|
|
2356
|
+
empty,
|
|
2357
|
+
className,
|
|
2358
|
+
style,
|
|
2359
|
+
as: Tag = "span",
|
|
2360
|
+
editSurface,
|
|
2361
|
+
...stamp
|
|
2362
|
+
}) {
|
|
2363
|
+
const cms = useCmsOptional();
|
|
2364
|
+
const editMode = cms?.editMode === true;
|
|
2365
|
+
const attrs = buildStampAttrs(stamp);
|
|
2366
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
2367
|
+
const [infoOpen, setInfoOpen] = useState(false);
|
|
2368
|
+
const hasEditor = Boolean(cms?.editor);
|
|
2369
|
+
const projected = cms?.editor ? cms.projection.field(stamp) : null;
|
|
2370
|
+
const origin = projected?.origin;
|
|
2371
|
+
const shadowedDelete = Boolean(cms?.editor && cms.projection.row(stamp)?.shadowedDelete);
|
|
2372
|
+
let badge = null;
|
|
2373
|
+
if (origin?.kind === "local") {
|
|
2374
|
+
badge = {
|
|
2375
|
+
kind: "draft",
|
|
2376
|
+
label: "Draft",
|
|
2377
|
+
proposalId: cms?.myProposalId ?? null,
|
|
2378
|
+
authorLabel: authorLabelFor(void 0, true, cms?.editor?.user.email),
|
|
2379
|
+
conflictHint: shadowedDelete ? "Conflicts with a pending delete" : null
|
|
2380
|
+
};
|
|
2381
|
+
} else if (origin?.kind === "proposal") {
|
|
2382
|
+
const proposal = cms?.proposals.find((p) => p.id === origin.proposalId);
|
|
2383
|
+
badge = {
|
|
2384
|
+
kind: origin.mine ? "draft" : "pending",
|
|
2385
|
+
label: origin.label,
|
|
2386
|
+
proposalId: origin.proposalId,
|
|
2387
|
+
authorLabel: authorLabelFor(proposal, origin.mine, cms?.editor?.user.email),
|
|
2388
|
+
conflictHint: shadowedDelete ? "Conflicts with a pending delete" : !origin.mine && cms?.projection.conflictsWithMine.has(origin.proposalId) ? "Conflicts with your pending proposal" : null
|
|
2389
|
+
};
|
|
2390
|
+
}
|
|
2391
|
+
const overlayIsActive = origin != null;
|
|
2392
|
+
const projectedValue = hasEditor ? projected?.value : null;
|
|
2393
|
+
const effectiveValue = effectiveStampValue(hasEditor, projectedValue, value, overlayIsActive);
|
|
2394
|
+
const fieldDef = cms ? manifestField(cms.manifest, stamp.table, stamp.field) : void 0;
|
|
2395
|
+
const fieldType = fieldDef?.type;
|
|
2396
|
+
const display = {
|
|
2397
|
+
children,
|
|
2398
|
+
format,
|
|
2399
|
+
value,
|
|
2400
|
+
empty,
|
|
2401
|
+
projectedValue,
|
|
2402
|
+
hasEditor,
|
|
2403
|
+
overlayIsActive,
|
|
2404
|
+
fieldKind: fieldType?.kind,
|
|
2405
|
+
locale: cms?.adapters.locale
|
|
2406
|
+
};
|
|
2407
|
+
const displayChildren = cms ? /* @__PURE__ */ jsx(
|
|
2408
|
+
StampKindDisplay,
|
|
2409
|
+
{
|
|
2410
|
+
cms,
|
|
2411
|
+
table: stamp.table,
|
|
2412
|
+
field: stamp.field,
|
|
2413
|
+
effectiveValue,
|
|
2414
|
+
...display
|
|
2415
|
+
}
|
|
2416
|
+
) : resolveStampDisplay(display);
|
|
2417
|
+
const canEditField = editMode && (cms?.canProposeField(stamp.table, stamp.field) ?? false);
|
|
2418
|
+
const imageDropEnabled = canEditField && fieldType?.kind === "image";
|
|
2419
|
+
const mediaDrop = useStampMediaDrop({
|
|
2420
|
+
enabled: imageDropEnabled,
|
|
2421
|
+
uploadFile: cms?.adapters.fieldsDataAdapter.uploadFile,
|
|
2422
|
+
apply: (assetId) => cms?.applyFieldEdit({
|
|
2423
|
+
table: stamp.table,
|
|
2424
|
+
rowId: stamp.rowId,
|
|
2425
|
+
field: stamp.field,
|
|
2426
|
+
value: assetId
|
|
2427
|
+
}),
|
|
2428
|
+
table: stamp.table,
|
|
2429
|
+
field: stamp.field,
|
|
2430
|
+
profile: fieldDef?.asset?.profile
|
|
2431
|
+
});
|
|
2432
|
+
const surface = resolveEditSurface(editSurface, fieldType);
|
|
2433
|
+
const thisKey = stampEditKey(stamp.table, stamp.rowId, stamp.field);
|
|
2434
|
+
const inPlaceActive = Boolean(cms && cms.activeInPlaceKey === thisKey);
|
|
2435
|
+
function handleStampClick(event) {
|
|
2436
|
+
if (!canEditField || !cms || mediaDrop.uploading) return;
|
|
2437
|
+
if (event.defaultPrevented) return;
|
|
2438
|
+
event.preventDefault();
|
|
2439
|
+
if (inPlaceActive) return;
|
|
2440
|
+
if (surface === "inplace") {
|
|
2441
|
+
cms.requestInPlaceEdit(stamp.table, stamp.rowId, stamp.field);
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
setDialogOpen(true);
|
|
2445
|
+
}
|
|
2446
|
+
function handleBadgeClick(event) {
|
|
2447
|
+
event.preventDefault();
|
|
2448
|
+
event.stopPropagation();
|
|
2449
|
+
setInfoOpen((open) => !open);
|
|
2450
|
+
}
|
|
2451
|
+
const showChrome = Boolean(badge || infoOpen || mediaDrop.uploading || mediaDrop.error);
|
|
2452
|
+
const highlight = cms?.highlight;
|
|
2453
|
+
const changeOutline = cms?.changesOpen && origin?.kind === "proposal" ? highlight?.table === stamp.table && highlight.rowId === stamp.rowId && (highlight.field === void 0 || highlight.field === stamp.field) ? CHANGE_HIGHLIGHT : origin.mine ? MY_CHANGE_OUTLINE : OTHER_CHANGE_OUTLINE : null;
|
|
2454
|
+
const stampStyle = {
|
|
2455
|
+
...showChrome || editMode ? { position: "relative", overflow: "visible" } : {},
|
|
2456
|
+
...editMode ? EDIT_OUTLINE : {},
|
|
2457
|
+
...changeOutline,
|
|
2458
|
+
...canEditField && !inPlaceActive && !mediaDrop.uploading ? { cursor: "pointer" } : {},
|
|
2459
|
+
...mediaDrop.uploading ? { cursor: "wait" } : {},
|
|
2460
|
+
...mediaDrop.dragOver ? MEDIA_DRAG_OVER : {},
|
|
2461
|
+
...style
|
|
2462
|
+
};
|
|
2463
|
+
return /* @__PURE__ */ jsxs(
|
|
2464
|
+
Tag,
|
|
2465
|
+
{
|
|
2466
|
+
...attrs,
|
|
2467
|
+
className,
|
|
2468
|
+
style: stampStyle,
|
|
2469
|
+
"data-columnus-edit": editMode ? "true" : void 0,
|
|
2470
|
+
"data-columnus-overlay": overlayIsActive ? "true" : void 0,
|
|
2471
|
+
"data-columnus-surface": editMode ? surface : void 0,
|
|
2472
|
+
"data-columnus-media-drop": imageDropEnabled ? "true" : void 0,
|
|
2473
|
+
"data-columnus-media-dragover": mediaDrop.dragOver ? "true" : void 0,
|
|
2474
|
+
onClick: canEditField ? handleStampClick : void 0,
|
|
2475
|
+
...imageDropEnabled ? mediaDrop.dropHandlers : {},
|
|
2476
|
+
children: [
|
|
2477
|
+
inPlaceActive && cms && isCmsInPlaceFieldType(fieldType) ? /* @__PURE__ */ jsx(
|
|
2478
|
+
InPlaceFieldEditor,
|
|
2479
|
+
{
|
|
2480
|
+
table: stamp.table,
|
|
2481
|
+
rowId: stamp.rowId,
|
|
2482
|
+
field: stamp.field,
|
|
2483
|
+
fieldType,
|
|
2484
|
+
optional: fieldDef?.optional,
|
|
2485
|
+
value: effectiveValue,
|
|
2486
|
+
onApplied: () => cms.closeInPlaceEdit(),
|
|
2487
|
+
onCancelled: () => cms.closeInPlaceEdit()
|
|
2488
|
+
}
|
|
2489
|
+
) : displayChildren,
|
|
2490
|
+
badge && !inPlaceActive ? /* @__PURE__ */ jsx(
|
|
2491
|
+
"span",
|
|
2492
|
+
{
|
|
2493
|
+
style: badge.kind === "draft" ? draftBadgeStyle : pendingBadgeStyle,
|
|
2494
|
+
onClick: handleBadgeClick,
|
|
2495
|
+
"data-columnus-badge": badge.kind,
|
|
2496
|
+
children: badge.label
|
|
2497
|
+
}
|
|
2498
|
+
) : null,
|
|
2499
|
+
infoOpen && badge ? /* @__PURE__ */ jsx(
|
|
2500
|
+
StampBadgeInfo,
|
|
2501
|
+
{
|
|
2502
|
+
authorLabel: badge.authorLabel,
|
|
2503
|
+
conflictHint: badge.conflictHint,
|
|
2504
|
+
onDismiss: () => setInfoOpen(false)
|
|
2505
|
+
}
|
|
2506
|
+
) : null,
|
|
2507
|
+
mediaDrop.uploading ? /* @__PURE__ */ jsx("span", { "data-columnus-media-uploading": "true", style: MEDIA_UPLOADING_OVERLAY, "aria-busy": "true", children: "Uploading\u2026" }) : null,
|
|
2508
|
+
mediaDrop.error ? /* @__PURE__ */ jsx("span", { "data-columnus-media-error": "", role: "alert", style: MEDIA_DROP_ERROR, children: mediaDrop.error }) : null,
|
|
2509
|
+
dialogOpen && cms ? /* @__PURE__ */ jsx(
|
|
2510
|
+
FieldEditorDialog,
|
|
2511
|
+
{
|
|
2512
|
+
open: true,
|
|
2513
|
+
table: stamp.table,
|
|
2514
|
+
rowId: stamp.rowId,
|
|
2515
|
+
field: stamp.field,
|
|
2516
|
+
fieldType,
|
|
2517
|
+
optional: fieldDef?.optional,
|
|
2518
|
+
value: effectiveValue,
|
|
2519
|
+
onApply: (value2) => cms.applyFieldEdit({
|
|
2520
|
+
table: stamp.table,
|
|
2521
|
+
rowId: stamp.rowId,
|
|
2522
|
+
field: stamp.field,
|
|
2523
|
+
value: value2
|
|
2524
|
+
}),
|
|
2525
|
+
onClose: () => setDialogOpen(false)
|
|
2526
|
+
}
|
|
2527
|
+
) : null
|
|
2528
|
+
]
|
|
2529
|
+
}
|
|
2530
|
+
);
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
// packages/@columnus/cms/src/stamps/use-cms-projected-field.ts
|
|
2534
|
+
function useCmsProjectedField(stamp, live) {
|
|
2535
|
+
const cms = useCmsOptional();
|
|
2536
|
+
if (!stamp || !cms?.editor) return live;
|
|
2537
|
+
const projected = cms.projection.field(stamp);
|
|
2538
|
+
return effectiveStampValue(true, projected.value, live, projected.origin != null);
|
|
2539
|
+
}
|
|
2540
|
+
function useCmsProjectedString(stamp, live) {
|
|
2541
|
+
const value = useCmsProjectedField(stamp, live);
|
|
2542
|
+
return typeof value === "string" ? value : live;
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
// packages/@columnus/cms/src/stamps/use-cms-projected-table.ts
|
|
2546
|
+
var EMPTY_LIVE = [];
|
|
2547
|
+
function useCmsProjectedTable(table, live = EMPTY_LIVE) {
|
|
2548
|
+
const cms = useCmsOptional();
|
|
2549
|
+
if (!cms?.editor || !Object.hasOwn(cms.tableRows, table)) return live;
|
|
2550
|
+
return cms.projection.table(table).map((row) => row.value);
|
|
2551
|
+
}
|
|
2552
|
+
var CmsRowContext = createContext(null);
|
|
2553
|
+
function useCmsRowOptional() {
|
|
2554
|
+
return useContext(CmsRowContext);
|
|
2555
|
+
}
|
|
2556
|
+
function useCmsRow() {
|
|
2557
|
+
const ctx = useContext(CmsRowContext);
|
|
2558
|
+
if (!ctx) {
|
|
2559
|
+
throw new Error("CmsField must be used within CmsRow");
|
|
2560
|
+
}
|
|
2561
|
+
return ctx;
|
|
2562
|
+
}
|
|
2563
|
+
function CmsRow({ table, row, rowId, children }) {
|
|
2564
|
+
const id = rowId ?? (row._id != null ? String(row._id) : "");
|
|
2565
|
+
return /* @__PURE__ */ jsx(CmsRowContext.Provider, { value: { table, rowId: id, row }, children });
|
|
2566
|
+
}
|
|
2567
|
+
function CmsField({
|
|
2568
|
+
name,
|
|
2569
|
+
href,
|
|
2570
|
+
hideWhenEmpty,
|
|
2571
|
+
className,
|
|
2572
|
+
style,
|
|
2573
|
+
empty = href ? "\xA0" : void 0,
|
|
2574
|
+
...stampRest
|
|
2575
|
+
}) {
|
|
2576
|
+
const { table, rowId, row } = useCmsRow();
|
|
2577
|
+
const cms = useCmsOptional();
|
|
2578
|
+
const editMode = cms?.editMode === true;
|
|
2579
|
+
const live = row[name];
|
|
2580
|
+
const effective = useCmsProjectedField({ table, rowId, field: name }, live);
|
|
2581
|
+
const shouldHideEmpty = hideWhenEmpty ?? href != null;
|
|
2582
|
+
if (shouldHideEmpty && isEmptyStampValue(effective) && !editMode) {
|
|
2583
|
+
return null;
|
|
2584
|
+
}
|
|
2585
|
+
const stamp = /* @__PURE__ */ jsx(
|
|
2586
|
+
CmsFieldStamp,
|
|
2587
|
+
{
|
|
2588
|
+
table,
|
|
2589
|
+
rowId,
|
|
2590
|
+
field: name,
|
|
2591
|
+
value: live,
|
|
2592
|
+
empty,
|
|
2593
|
+
className: href != null ? void 0 : className,
|
|
2594
|
+
style: href != null ? void 0 : style,
|
|
2595
|
+
...stampRest
|
|
2596
|
+
}
|
|
2597
|
+
);
|
|
2598
|
+
if (href == null) return stamp;
|
|
2599
|
+
const resolved = editMode ? null : typeof href === "function" ? href(effective) : href;
|
|
2600
|
+
return resolved ? /* @__PURE__ */ jsx("a", { className, style, href: resolved, children: stamp }) : /* @__PURE__ */ jsx("span", { className, style, children: stamp });
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
// packages/@columnus/cms/src/nav/content-ref.ts
|
|
2604
|
+
function findContentRefField(manifest, navigationTable) {
|
|
2605
|
+
const nav = manifest.tables.find((t) => t.name === navigationTable);
|
|
2606
|
+
if (!nav) return null;
|
|
2607
|
+
for (const field of nav.fields) {
|
|
2608
|
+
if (field.type.kind !== "id") continue;
|
|
2609
|
+
const refTable = field.type.table;
|
|
2610
|
+
if (refTable === navigationTable) continue;
|
|
2611
|
+
const target = manifest.tables.find((t) => t.name === refTable);
|
|
2612
|
+
if (!target) continue;
|
|
2613
|
+
if (looksLikeContentTable(target)) {
|
|
2614
|
+
return { field: field.name, contentTable: target.name };
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
for (const field of nav.fields) {
|
|
2618
|
+
if (field.type.kind !== "id") continue;
|
|
2619
|
+
if (field.type.table === navigationTable) continue;
|
|
2620
|
+
return { field: field.name, contentTable: field.type.table };
|
|
2621
|
+
}
|
|
2622
|
+
return null;
|
|
2623
|
+
}
|
|
2624
|
+
function looksLikeContentTable(table) {
|
|
2625
|
+
return table.fields.some(
|
|
2626
|
+
(f) => f.type.kind === "markdown" || f.name === "content" || f.name === "body" || f.name === "title"
|
|
2627
|
+
);
|
|
2628
|
+
}
|
|
2629
|
+
|
|
2630
|
+
// packages/@columnus/cms/src/nav/content-ref-integrity.ts
|
|
2631
|
+
function markdownLooksEmpty(value) {
|
|
2632
|
+
if (value === void 0 || value === null) return true;
|
|
2633
|
+
if (typeof value === "string") {
|
|
2634
|
+
const plain = richContentPlainText(value);
|
|
2635
|
+
return !plain?.trim();
|
|
2636
|
+
}
|
|
2637
|
+
if (typeof value === "object" && value !== null && "blocks" in value) {
|
|
2638
|
+
const blocks = value.blocks;
|
|
2639
|
+
if (!Array.isArray(blocks) || blocks.length === 0) return true;
|
|
2640
|
+
const serialized = stringifyRichDoc(blocks);
|
|
2641
|
+
const plain = richContentPlainText(serialized);
|
|
2642
|
+
return !plain?.trim();
|
|
2643
|
+
}
|
|
2644
|
+
return false;
|
|
2645
|
+
}
|
|
2646
|
+
function describeContentRefIntegrity(args) {
|
|
2647
|
+
const contentRef = findContentRefField(args.manifest, args.navigationTable);
|
|
2648
|
+
if (!contentRef) {
|
|
2649
|
+
return { code: "ok", reason: null };
|
|
2650
|
+
}
|
|
2651
|
+
const nav = args.projection.row({ table: args.navigationTable, rowId: args.navRowId });
|
|
2652
|
+
if (!nav) {
|
|
2653
|
+
return { code: "ok", reason: null };
|
|
2654
|
+
}
|
|
2655
|
+
const raw = nav.value[contentRef.field];
|
|
2656
|
+
if (raw === void 0 || raw === null || raw === "") {
|
|
2657
|
+
return {
|
|
2658
|
+
code: "missing_ref",
|
|
2659
|
+
reason: "This page has no linked content row yet."
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
const contentId = String(raw);
|
|
2663
|
+
const content = args.projection.row({ table: contentRef.contentTable, rowId: contentId });
|
|
2664
|
+
if (!content) {
|
|
2665
|
+
return {
|
|
2666
|
+
code: "missing_row",
|
|
2667
|
+
reason: "Linked content row is missing from the projection (broken content ref)."
|
|
2668
|
+
};
|
|
2669
|
+
}
|
|
2670
|
+
const contentTable = args.manifest.tables.find((t) => t.name === contentRef.contentTable);
|
|
2671
|
+
const bodyField = contentTable?.fields.find((f) => f.type.kind === "markdown")?.name ?? contentTable?.fields.find((f) => f.name === "body" || f.name === "content")?.name;
|
|
2672
|
+
if (!bodyField) {
|
|
2673
|
+
return { code: "ok", reason: null };
|
|
2674
|
+
}
|
|
2675
|
+
if (markdownLooksEmpty(content.value[bodyField])) {
|
|
2676
|
+
return {
|
|
2677
|
+
code: "empty_body",
|
|
2678
|
+
reason: "Linked content body is empty."
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
return { code: "ok", reason: null };
|
|
2682
|
+
}
|
|
2683
|
+
var confirmPanel = {
|
|
2684
|
+
display: "flex",
|
|
2685
|
+
flexWrap: "wrap",
|
|
2686
|
+
gap: 6,
|
|
2687
|
+
alignItems: "center",
|
|
2688
|
+
width: "100%",
|
|
2689
|
+
fontSize: 12
|
|
2690
|
+
};
|
|
2691
|
+
function ConfirmPanel({
|
|
2692
|
+
label: label2,
|
|
2693
|
+
prompt,
|
|
2694
|
+
confirmLabel,
|
|
2695
|
+
dismissLabel,
|
|
2696
|
+
busy,
|
|
2697
|
+
onConfirm,
|
|
2698
|
+
onDismiss
|
|
2699
|
+
}) {
|
|
2700
|
+
return /* @__PURE__ */ jsxs("div", { style: confirmPanel, role: "group", "aria-label": `Confirm ${label2}`, children: [
|
|
2701
|
+
/* @__PURE__ */ jsx("span", { children: prompt }),
|
|
2702
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: dangerBtn, disabled: busy, onClick: onConfirm, children: confirmLabel }),
|
|
2703
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: ghostBtn, onClick: onDismiss, children: dismissLabel })
|
|
2704
|
+
] });
|
|
2705
|
+
}
|
|
2706
|
+
var raisedStyle = { zIndex: CMS_FIELD_EDITOR_Z_INDEX };
|
|
2707
|
+
var valueCard = (chosen) => ({
|
|
2708
|
+
flex: 1,
|
|
2709
|
+
minWidth: 0,
|
|
2710
|
+
padding: "8px 10px",
|
|
2711
|
+
borderRadius: 8,
|
|
2712
|
+
border: chosen ? "2px solid CanvasText" : "1px solid color-mix(in oklab, CanvasText 20%, transparent)"
|
|
2713
|
+
});
|
|
2714
|
+
var choiceBtn = (chosen) => ({
|
|
2715
|
+
...chosen ? primaryBtn : ghostBtn,
|
|
2716
|
+
padding: "3px 8px",
|
|
2717
|
+
fontSize: 12
|
|
2718
|
+
});
|
|
2719
|
+
function Value({ value, type }) {
|
|
2720
|
+
const shown = plainTextIfRichDoc(value);
|
|
2721
|
+
return type ? /* @__PURE__ */ jsx(CellRenderer, { value: shown, type, size: "compact" }) : /* @__PURE__ */ jsx(Fragment, { children: String(shown) });
|
|
2722
|
+
}
|
|
2723
|
+
var changeId = (change) => JSON.stringify([change.table, change.rowId, change.field ?? null]);
|
|
2724
|
+
function ResolveDialog({
|
|
2725
|
+
draftKey,
|
|
2726
|
+
revision,
|
|
2727
|
+
title: title2,
|
|
2728
|
+
fields,
|
|
2729
|
+
onClose
|
|
2730
|
+
}) {
|
|
2731
|
+
const { resolve, actionPhase } = useCms();
|
|
2732
|
+
const [choices, setChoices] = useState({});
|
|
2733
|
+
const picked = fields.flatMap((change) => {
|
|
2734
|
+
const keep = choices[changeId(change)];
|
|
2735
|
+
if (!keep) return [];
|
|
2736
|
+
const { table, rowId, field } = change;
|
|
2737
|
+
return [{ table, rowId, ...field === void 0 ? {} : { field }, keep }];
|
|
2738
|
+
});
|
|
2739
|
+
async function apply() {
|
|
2740
|
+
if (await resolve(draftKey, revision, picked)) onClose();
|
|
2741
|
+
}
|
|
2742
|
+
return /* @__PURE__ */ jsx(Dialog, { open: true, onOpenChange: (open) => open ? void 0 : onClose(), children: /* @__PURE__ */ jsxs(
|
|
2743
|
+
DialogContent,
|
|
2744
|
+
{
|
|
2745
|
+
className: "max-h-[85vh] max-w-2xl overflow-y-auto",
|
|
2746
|
+
style: { ...raisedStyle, fontSize: 13 },
|
|
2747
|
+
overlayStyle: raisedStyle,
|
|
2748
|
+
children: [
|
|
2749
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
2750
|
+
/* @__PURE__ */ jsxs(DialogTitle, { children: [
|
|
2751
|
+
"Resolve \u201C",
|
|
2752
|
+
title2,
|
|
2753
|
+
"\u201D"
|
|
2754
|
+
] }),
|
|
2755
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: "These fields changed on the live site after you drafted them. Pick the value to keep for each field; the rest of the draft stays as it is." })
|
|
2756
|
+
] }),
|
|
2757
|
+
/* @__PURE__ */ jsx("ul", { style: { listStyle: "none", margin: 0, padding: 0 }, children: fields.map((change) => {
|
|
2758
|
+
const id = changeId(change);
|
|
2759
|
+
const keep = choices[id];
|
|
2760
|
+
const choose = (next) => setChoices((prev) => ({ ...prev, [id]: next }));
|
|
2761
|
+
return /* @__PURE__ */ jsxs("li", { "aria-label": change.path, style: { padding: "10px 0" }, children: [
|
|
2762
|
+
/* @__PURE__ */ jsx("div", { style: { color: cmsMuted, marginBottom: 6 }, children: change.path }),
|
|
2763
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
2764
|
+
/* @__PURE__ */ jsxs("div", { style: valueCard(keep === "published"), children: [
|
|
2765
|
+
/* @__PURE__ */ jsx("div", { style: { color: cmsMuted, fontSize: 12 }, children: "Published" }),
|
|
2766
|
+
change.rowGone ? "Row deleted" : change.kind === "update" ? /* @__PURE__ */ jsx(Value, { value: change.before, type: change.type }) : "The row as it is now"
|
|
2767
|
+
] }),
|
|
2768
|
+
/* @__PURE__ */ jsxs("div", { style: valueCard(keep === "mine"), children: [
|
|
2769
|
+
/* @__PURE__ */ jsx("div", { style: { color: cmsMuted, fontSize: 12 }, children: "Yours" }),
|
|
2770
|
+
change.kind === "delete" ? "\u2212 delete row" : change.after === void 0 ? "(cleared)" : /* @__PURE__ */ jsx(Value, { value: change.after, type: change.type })
|
|
2771
|
+
] })
|
|
2772
|
+
] }),
|
|
2773
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 6, marginTop: 6 }, children: [
|
|
2774
|
+
/* @__PURE__ */ jsx(
|
|
2775
|
+
"button",
|
|
2776
|
+
{
|
|
2777
|
+
type: "button",
|
|
2778
|
+
"aria-pressed": keep === "published",
|
|
2779
|
+
style: choiceBtn(keep === "published"),
|
|
2780
|
+
onClick: () => choose("published"),
|
|
2781
|
+
children: "Use published"
|
|
2782
|
+
}
|
|
2783
|
+
),
|
|
2784
|
+
/* @__PURE__ */ jsx(
|
|
2785
|
+
"button",
|
|
2786
|
+
{
|
|
2787
|
+
type: "button",
|
|
2788
|
+
"aria-pressed": keep === "mine",
|
|
2789
|
+
style: choiceBtn(keep === "mine"),
|
|
2790
|
+
disabled: change.rowGone,
|
|
2791
|
+
onClick: () => choose("mine"),
|
|
2792
|
+
children: "Keep mine"
|
|
2793
|
+
}
|
|
2794
|
+
)
|
|
2795
|
+
] })
|
|
2796
|
+
] }, id);
|
|
2797
|
+
}) }),
|
|
2798
|
+
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
2799
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: ghostBtn, onClick: onClose, children: "Cancel" }),
|
|
2800
|
+
/* @__PURE__ */ jsx(
|
|
2801
|
+
"button",
|
|
2802
|
+
{
|
|
2803
|
+
type: "button",
|
|
2804
|
+
style: primaryBtn,
|
|
2805
|
+
disabled: picked.length === 0 || actionPhase !== "idle",
|
|
2806
|
+
onClick: () => void apply(),
|
|
2807
|
+
children: "Apply"
|
|
2808
|
+
}
|
|
2809
|
+
)
|
|
2810
|
+
] })
|
|
2811
|
+
]
|
|
2812
|
+
}
|
|
2813
|
+
) });
|
|
2814
|
+
}
|
|
2815
|
+
var WARN = "color-mix(in oklab, darkorange 80%, CanvasText)";
|
|
2816
|
+
var panel = {
|
|
2817
|
+
...cmsBox,
|
|
2818
|
+
position: "fixed",
|
|
2819
|
+
zIndex: 9998,
|
|
2820
|
+
right: 16,
|
|
2821
|
+
width: "min(440px, calc(100vw - 32px))",
|
|
2822
|
+
padding: 16,
|
|
2823
|
+
boxSizing: "border-box",
|
|
2824
|
+
overflowY: "auto",
|
|
2825
|
+
display: "flex",
|
|
2826
|
+
flexDirection: "column",
|
|
2827
|
+
gap: 12,
|
|
2828
|
+
fontFamily: "system-ui, sans-serif",
|
|
2829
|
+
fontSize: 13
|
|
2830
|
+
};
|
|
2831
|
+
var card = {
|
|
2832
|
+
border: "1px solid color-mix(in oklab, CanvasText 15%, transparent)",
|
|
2833
|
+
borderRadius: 8,
|
|
2834
|
+
padding: "10px 12px"
|
|
2835
|
+
};
|
|
2836
|
+
var smallBtn = { padding: "3px 8px", fontSize: 12 };
|
|
2837
|
+
var list = { listStyle: "none", margin: 0, padding: 0 };
|
|
2838
|
+
var item = {
|
|
2839
|
+
display: "flex",
|
|
2840
|
+
gap: 8,
|
|
2841
|
+
alignItems: "flex-start",
|
|
2842
|
+
padding: "8px 0",
|
|
2843
|
+
borderTop: "1px solid color-mix(in oklab, CanvasText 10%, transparent)"
|
|
2844
|
+
};
|
|
2845
|
+
var chip = {
|
|
2846
|
+
border: "1px solid currentColor",
|
|
2847
|
+
borderRadius: 999,
|
|
2848
|
+
padding: "0 6px",
|
|
2849
|
+
fontSize: 11
|
|
2850
|
+
};
|
|
2851
|
+
var before = {
|
|
2852
|
+
textDecoration: "line-through",
|
|
2853
|
+
color: "color-mix(in oklab, red 70%, CanvasText)"
|
|
2854
|
+
};
|
|
2855
|
+
var after = { color: "color-mix(in oklab, green 65%, CanvasText)" };
|
|
2856
|
+
function patchChangeCount(patch) {
|
|
2857
|
+
return patch.op === "update" ? Object.keys(patch.fields).length + (patch.clearFields?.length ?? 0) : 1;
|
|
2858
|
+
}
|
|
2859
|
+
function patchChanges(manifest, proposal, patch, drafts) {
|
|
2860
|
+
const table = manifest.tables.find((candidate) => candidate.name === patch.table);
|
|
2861
|
+
const baseline = patch.baseline ?? null;
|
|
2862
|
+
const tableName = table ? tableDisplayName(table) : patch.table;
|
|
2863
|
+
const row = patch.op === "insert" ? "new row" : fallbackPreviewLabel(baseline ?? { _id: patch.rowId }, table?.fields);
|
|
2864
|
+
const stale = staleFieldNames(patch, baseline);
|
|
2865
|
+
const sharedWith = (fields) => findProposalIdsOverlappingTarget(
|
|
2866
|
+
{ id: proposal.id, patches: [{ ...patch, fields, clearFields: void 0 }] },
|
|
2867
|
+
drafts
|
|
2868
|
+
).size > 0;
|
|
2869
|
+
const target = { table: patch.table, rowId: patch.rowId, rowGone: stale === "row-missing" };
|
|
2870
|
+
if (patch.op !== "update") {
|
|
2871
|
+
return [
|
|
2872
|
+
{
|
|
2873
|
+
...target,
|
|
2874
|
+
path: `${tableName} \u203A ${row}`,
|
|
2875
|
+
kind: patch.op,
|
|
2876
|
+
after: patch.op === "insert" ? fallbackPreviewLabel(patch.fields, table?.fields) : void 0,
|
|
2877
|
+
stale: stale === "row-missing" || stale.length > 0,
|
|
2878
|
+
shared: sharedWith(patch.fields)
|
|
2879
|
+
}
|
|
2880
|
+
];
|
|
2881
|
+
}
|
|
2882
|
+
const changed = /* @__PURE__ */ new Set([...Object.keys(patch.fields), ...patch.clearFields ?? []]);
|
|
2883
|
+
const names = proposalDiffFieldNames(table?.fields, baseline, patch.fields).filter(
|
|
2884
|
+
(name) => changed.has(name)
|
|
2885
|
+
);
|
|
2886
|
+
return computeProposalRecordDiff(names, baseline, patch.fields, "update").map((diff) => {
|
|
2887
|
+
const field = table?.fields.find((candidate) => candidate.name === diff.field);
|
|
2888
|
+
return {
|
|
2889
|
+
...target,
|
|
2890
|
+
field: diff.field,
|
|
2891
|
+
path: `${tableName} \u203A ${row} \u203A ${field ? fieldDisplayName(field) : diff.field}`,
|
|
2892
|
+
kind: "update",
|
|
2893
|
+
before: diff.before,
|
|
2894
|
+
after: Object.hasOwn(patch.fields, diff.field) ? diff.after : void 0,
|
|
2895
|
+
type: field?.type,
|
|
2896
|
+
stale: stale === "row-missing" || stale.includes(diff.field),
|
|
2897
|
+
shared: sharedWith({ [diff.field]: diff.after })
|
|
2898
|
+
};
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
function groupOf(manifest, drafts, me, currentDraft, proposal) {
|
|
2902
|
+
const mine = proposal.createdByUserId === me;
|
|
2903
|
+
return {
|
|
2904
|
+
proposal,
|
|
2905
|
+
mine,
|
|
2906
|
+
current: mine && currentDraft !== null && proposal.draftKey === currentDraft.key,
|
|
2907
|
+
title: draftTitle(proposal, mine),
|
|
2908
|
+
count: proposal.patches.reduce((sum, patch) => sum + patchChangeCount(patch), 0),
|
|
2909
|
+
changes: proposal.patches.flatMap((patch) => patchChanges(manifest, proposal, patch, drafts))
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
function useMySessionGroups() {
|
|
2913
|
+
const { editor, manifest, proposals, currentDraft } = useCms();
|
|
2914
|
+
const me = editor?.user.id;
|
|
2915
|
+
return useMemo(
|
|
2916
|
+
() => new Map(
|
|
2917
|
+
proposals.filter((proposal) => proposal.createdByUserId === me && proposal.draftKey !== void 0).map((proposal) => [
|
|
2918
|
+
proposal.draftKey,
|
|
2919
|
+
groupOf(manifest, proposals, me, currentDraft, proposal)
|
|
2920
|
+
])
|
|
2921
|
+
),
|
|
2922
|
+
[manifest, proposals, me, currentDraft]
|
|
2923
|
+
);
|
|
2924
|
+
}
|
|
2925
|
+
function useMySessionDrafts() {
|
|
2926
|
+
const groups = useMySessionGroups();
|
|
2927
|
+
return useMemo(
|
|
2928
|
+
() => new Map(
|
|
2929
|
+
[...groups].map(([key, group]) => [
|
|
2930
|
+
key,
|
|
2931
|
+
{ changes: group.count, conflicts: group.changes.filter((c) => c.stale).length }
|
|
2932
|
+
])
|
|
2933
|
+
),
|
|
2934
|
+
[groups]
|
|
2935
|
+
);
|
|
2936
|
+
}
|
|
2937
|
+
function ResolveSessionDraft({ draftKey, onClose }) {
|
|
2938
|
+
const group = useMySessionGroups().get(draftKey);
|
|
2939
|
+
return group ? /* @__PURE__ */ jsx(ResolveGroup, { group, onClose }) : null;
|
|
2940
|
+
}
|
|
2941
|
+
function ResolveGroup({ group, onClose }) {
|
|
2942
|
+
const revision = group.proposal.draftRevision;
|
|
2943
|
+
return /* @__PURE__ */ jsx(
|
|
2944
|
+
ResolveDialog,
|
|
2945
|
+
{
|
|
2946
|
+
draftKey: group.proposal.draftKey,
|
|
2947
|
+
revision: revision ?? 0,
|
|
2948
|
+
title: group.title,
|
|
2949
|
+
fields: group.changes.filter((change) => change.stale),
|
|
2950
|
+
onClose
|
|
2951
|
+
},
|
|
2952
|
+
revision
|
|
2953
|
+
);
|
|
2954
|
+
}
|
|
2955
|
+
function ChangeLine({ change }) {
|
|
2956
|
+
if (change.kind === "insert") return /* @__PURE__ */ jsxs("span", { style: after, children: [
|
|
2957
|
+
"+ ",
|
|
2958
|
+
String(change.after)
|
|
2959
|
+
] });
|
|
2960
|
+
if (change.kind === "delete") return /* @__PURE__ */ jsx("span", { style: before, children: "\u2212 delete row" });
|
|
2961
|
+
return /* @__PURE__ */ jsxs("span", { children: [
|
|
2962
|
+
change.before === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2963
|
+
/* @__PURE__ */ jsx("span", { style: before, children: /* @__PURE__ */ jsx(Value, { value: change.before, type: change.type }) }),
|
|
2964
|
+
" \u2192 "
|
|
2965
|
+
] }),
|
|
2966
|
+
/* @__PURE__ */ jsx("span", { style: after, children: change.after === void 0 ? "(cleared)" : /* @__PURE__ */ jsx(Value, { value: change.after, type: change.type }) })
|
|
2967
|
+
] });
|
|
2968
|
+
}
|
|
2969
|
+
function ChangesView({
|
|
2970
|
+
toolbarAtTop = false,
|
|
2971
|
+
onClose
|
|
2972
|
+
}) {
|
|
2973
|
+
const {
|
|
2974
|
+
editor,
|
|
2975
|
+
manifest,
|
|
2976
|
+
proposals,
|
|
2977
|
+
currentDraft,
|
|
2978
|
+
actionPhase,
|
|
2979
|
+
publishDraft,
|
|
2980
|
+
withdrawDraft,
|
|
2981
|
+
discard,
|
|
2982
|
+
setHighlight
|
|
2983
|
+
} = useCms();
|
|
2984
|
+
const [confirmWithdraw, setConfirmWithdraw] = useState(null);
|
|
2985
|
+
const [resolving, setResolving] = useState(null);
|
|
2986
|
+
const [hidden, setHidden] = useState(null);
|
|
2987
|
+
const busy = actionPhase !== "idle";
|
|
2988
|
+
const me = editor?.user.id;
|
|
2989
|
+
const rank = (group) => group.current ? 0 : !group.mine ? 3 : group.proposal.draftKey === void 0 ? 2 : 1;
|
|
2990
|
+
const groups = proposals.map((proposal) => groupOf(manifest, proposals, me, currentDraft, proposal)).sort(
|
|
2991
|
+
(a, b) => rank(a) - rank(b) || b.proposal.createdAt - a.proposal.createdAt || a.title.localeCompare(b.title)
|
|
2992
|
+
);
|
|
2993
|
+
const resolvingGroup = groups.find((group) => group.proposal.id === resolving);
|
|
2994
|
+
const pointAt = (group, change, id) => {
|
|
2995
|
+
if (group.mine && !group.current) setHidden(id);
|
|
2996
|
+
else setHighlight({ table: change.table, rowId: change.rowId, field: change.field });
|
|
2997
|
+
};
|
|
2998
|
+
const leave = () => {
|
|
2999
|
+
setHidden(null);
|
|
3000
|
+
setHighlight(null);
|
|
3001
|
+
};
|
|
3002
|
+
return /* @__PURE__ */ jsxs(
|
|
3003
|
+
"aside",
|
|
3004
|
+
{
|
|
3005
|
+
"aria-label": "Changes",
|
|
3006
|
+
style: { ...panel, top: toolbarAtTop ? 80 : 16, bottom: toolbarAtTop ? 16 : 80 },
|
|
3007
|
+
children: [
|
|
3008
|
+
/* @__PURE__ */ jsxs("header", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
|
|
3009
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: 15, flex: 1 }, children: "Changes" }),
|
|
3010
|
+
/* @__PURE__ */ jsx("button", { type: "button", style: ghostBtn, "aria-label": "Close changes", onClick: onClose, children: "\xD7" })
|
|
3011
|
+
] }),
|
|
3012
|
+
proposals.length >= SHARE_LIST_LIMIT ? /* @__PURE__ */ jsxs("p", { role: "status", style: { margin: 0, color: WARN }, children: [
|
|
3013
|
+
SHARE_LIST_LIMIT,
|
|
3014
|
+
" or more drafts: some may not be shown"
|
|
3015
|
+
] }) : null,
|
|
3016
|
+
groups.length === 0 ? /* @__PURE__ */ jsx("p", { style: { margin: 0, color: cmsMuted }, children: "No drafts." }) : null,
|
|
3017
|
+
groups.map((group) => {
|
|
3018
|
+
const { proposal } = group;
|
|
3019
|
+
const key = proposal.draftKey;
|
|
3020
|
+
const stale = group.changes.filter((change) => change.stale);
|
|
3021
|
+
const count = `${group.count} ${group.count === 1 ? "change" : "changes"}`;
|
|
3022
|
+
return /* @__PURE__ */ jsxs("section", { "aria-label": group.title, style: card, children: [
|
|
3023
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: 6, alignItems: "center" }, children: [
|
|
3024
|
+
/* @__PURE__ */ jsx("strong", { children: group.title }),
|
|
3025
|
+
group.mine ? null : /* @__PURE__ */ jsx("span", { style: chip, children: "read-only" }),
|
|
3026
|
+
stale.length > 0 ? /* @__PURE__ */ jsxs("span", { style: { ...chip, color: WARN }, children: [
|
|
3027
|
+
stale.length,
|
|
3028
|
+
" ",
|
|
3029
|
+
stale.length === 1 ? "conflict" : "conflicts"
|
|
3030
|
+
] }) : null,
|
|
3031
|
+
/* @__PURE__ */ jsx("span", { style: { color: cmsMuted, flex: 1 }, children: group.mine ? `${group.current ? "current draft \xB7 " : ""}${count}` : `${count} \xB7 reviewers accept or reject it in Studio` }),
|
|
3032
|
+
group.mine && confirmWithdraw !== proposal.id ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3033
|
+
/* @__PURE__ */ jsx(
|
|
3034
|
+
"button",
|
|
3035
|
+
{
|
|
3036
|
+
type: "button",
|
|
3037
|
+
style: { ...dangerBtn, ...smallBtn },
|
|
3038
|
+
disabled: busy,
|
|
3039
|
+
onClick: () => setConfirmWithdraw(proposal.id),
|
|
3040
|
+
children: "Withdraw"
|
|
3041
|
+
}
|
|
3042
|
+
),
|
|
3043
|
+
stale.length > 0 ? /* @__PURE__ */ jsx(
|
|
3044
|
+
"button",
|
|
3045
|
+
{
|
|
3046
|
+
type: "button",
|
|
3047
|
+
style: { ...ghostBtn, ...smallBtn, color: WARN },
|
|
3048
|
+
disabled: busy,
|
|
3049
|
+
onClick: () => setResolving(proposal.id),
|
|
3050
|
+
children: "Resolve"
|
|
3051
|
+
}
|
|
3052
|
+
) : /* @__PURE__ */ jsx(
|
|
3053
|
+
"button",
|
|
3054
|
+
{
|
|
3055
|
+
type: "button",
|
|
3056
|
+
style: { ...primaryBtn, ...smallBtn },
|
|
3057
|
+
disabled: busy,
|
|
3058
|
+
onClick: () => void publishDraft(key),
|
|
3059
|
+
children: "Publish"
|
|
3060
|
+
}
|
|
3061
|
+
)
|
|
3062
|
+
] }) : null
|
|
3063
|
+
] }),
|
|
3064
|
+
confirmWithdraw === proposal.id ? /* @__PURE__ */ jsx(
|
|
3065
|
+
ConfirmPanel,
|
|
3066
|
+
{
|
|
3067
|
+
label: "withdraw",
|
|
3068
|
+
prompt: `Withdraw \u201C${group.title}\u201D?`,
|
|
3069
|
+
confirmLabel: actionPhase === "withdrawing" ? "Withdrawing\u2026" : "Withdraw",
|
|
3070
|
+
dismissLabel: "Cancel",
|
|
3071
|
+
busy,
|
|
3072
|
+
onConfirm: () => void withdrawDraft(key).then(() => setConfirmWithdraw(null)),
|
|
3073
|
+
onDismiss: () => setConfirmWithdraw(null)
|
|
3074
|
+
}
|
|
3075
|
+
) : null,
|
|
3076
|
+
/* @__PURE__ */ jsx("ul", { style: list, children: group.changes.map((change) => {
|
|
3077
|
+
const id = `${proposal.id}\0${change.path}`;
|
|
3078
|
+
return /* @__PURE__ */ jsxs(
|
|
3079
|
+
"li",
|
|
3080
|
+
{
|
|
3081
|
+
"aria-label": change.path,
|
|
3082
|
+
style: item,
|
|
3083
|
+
onMouseEnter: () => pointAt(group, change, id),
|
|
3084
|
+
onMouseLeave: leave,
|
|
3085
|
+
children: [
|
|
3086
|
+
/* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
3087
|
+
/* @__PURE__ */ jsxs("div", { style: { color: cmsMuted }, children: [
|
|
3088
|
+
change.path,
|
|
3089
|
+
change.stale ? /* @__PURE__ */ jsx(Marker, { title: "Changed on the live site since it was drafted", children: "\u26A0 changed since drafted" }) : null,
|
|
3090
|
+
change.shared ? /* @__PURE__ */ jsx(Marker, { title: "Another draft also changes this", children: "\u21C4" }) : null
|
|
3091
|
+
] }),
|
|
3092
|
+
/* @__PURE__ */ jsx(ChangeLine, { change }),
|
|
3093
|
+
hidden === id ? /* @__PURE__ */ jsx("div", { role: "status", style: { color: cmsMuted, fontSize: 12 }, children: "Not shown on the page: resume the session to see it" }) : null
|
|
3094
|
+
] }),
|
|
3095
|
+
group.mine ? /* @__PURE__ */ jsx(
|
|
3096
|
+
"button",
|
|
3097
|
+
{
|
|
3098
|
+
type: "button",
|
|
3099
|
+
style: { ...ghostBtn, ...smallBtn },
|
|
3100
|
+
disabled: busy,
|
|
3101
|
+
onClick: () => void discard(key, [
|
|
3102
|
+
{
|
|
3103
|
+
table: change.table,
|
|
3104
|
+
rowId: change.rowId,
|
|
3105
|
+
...change.field === void 0 ? {} : { fields: [change.field] }
|
|
3106
|
+
}
|
|
3107
|
+
]),
|
|
3108
|
+
children: "Revert"
|
|
3109
|
+
}
|
|
3110
|
+
) : null
|
|
3111
|
+
]
|
|
3112
|
+
},
|
|
3113
|
+
id
|
|
3114
|
+
);
|
|
3115
|
+
}) })
|
|
3116
|
+
] }, proposal.id);
|
|
3117
|
+
}),
|
|
3118
|
+
resolvingGroup ? /* @__PURE__ */ jsx(ResolveGroup, { group: resolvingGroup, onClose: () => setResolving(null) }) : null
|
|
3119
|
+
]
|
|
3120
|
+
}
|
|
3121
|
+
);
|
|
3122
|
+
}
|
|
3123
|
+
function Marker({ title: title2, children }) {
|
|
3124
|
+
return /* @__PURE__ */ jsx("span", { title: title2, style: { marginLeft: 6, color: WARN }, children });
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
// packages/@columnus/cms/src/chrome/session-storage.ts
|
|
3128
|
+
function readSession(key) {
|
|
3129
|
+
try {
|
|
3130
|
+
return window.sessionStorage.getItem(key);
|
|
3131
|
+
} catch {
|
|
3132
|
+
return null;
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
function writeSession(key, value) {
|
|
3136
|
+
try {
|
|
3137
|
+
if (value === null) window.sessionStorage.removeItem(key);
|
|
3138
|
+
else window.sessionStorage.setItem(key, value);
|
|
3139
|
+
} catch {
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
var BuilderPanel = lazy(() => import('./cms/builder/panel.js'));
|
|
3143
|
+
var TablesDialog = lazy(() => import('./cms/tables/tables-dialog.js'));
|
|
3144
|
+
var COLLAPSE_STORAGE_KEY = "columnus-cms-toolbar-collapsed";
|
|
3145
|
+
var PANEL_STORAGE_KEY = "columnus-cms-panel";
|
|
3146
|
+
var collapsedChip = {
|
|
3147
|
+
appearance: "none",
|
|
3148
|
+
border: `1px solid ${ACCENT}`,
|
|
3149
|
+
background: ACCENT,
|
|
3150
|
+
color: ACCENT_FG,
|
|
3151
|
+
borderRadius: 999,
|
|
3152
|
+
padding: "10px 14px",
|
|
3153
|
+
cursor: "pointer",
|
|
3154
|
+
font: "inherit",
|
|
3155
|
+
fontWeight: 600,
|
|
3156
|
+
display: "inline-flex",
|
|
3157
|
+
alignItems: "center",
|
|
3158
|
+
gap: 6,
|
|
3159
|
+
boxShadow: "0 4px 24px color-mix(in oklab, CanvasText 18%, transparent)"
|
|
3160
|
+
};
|
|
3161
|
+
var iconOnlyBtn = {
|
|
3162
|
+
appearance: "none",
|
|
3163
|
+
border: "1px solid color-mix(in oklab, CanvasText 22%, transparent)",
|
|
3164
|
+
background: "transparent",
|
|
3165
|
+
color: "inherit",
|
|
3166
|
+
borderRadius: 6,
|
|
3167
|
+
padding: "6px",
|
|
3168
|
+
cursor: "pointer",
|
|
3169
|
+
font: "inherit",
|
|
3170
|
+
display: "inline-flex",
|
|
3171
|
+
alignItems: "center",
|
|
3172
|
+
justifyContent: "center",
|
|
3173
|
+
opacity: 0.75
|
|
3174
|
+
};
|
|
3175
|
+
function barPosition(placement, offset) {
|
|
3176
|
+
const o = {
|
|
3177
|
+
top: offset?.top ?? 16,
|
|
3178
|
+
right: offset?.right ?? 16,
|
|
3179
|
+
bottom: offset?.bottom ?? 16,
|
|
3180
|
+
left: offset?.left ?? 16
|
|
3181
|
+
};
|
|
3182
|
+
switch (placement) {
|
|
3183
|
+
case "bottom-left":
|
|
3184
|
+
return { bottom: o.bottom, left: o.left };
|
|
3185
|
+
case "top-right":
|
|
3186
|
+
return { top: o.top, right: o.right };
|
|
3187
|
+
case "top-left":
|
|
3188
|
+
return { top: o.top, left: o.left };
|
|
3189
|
+
case "bottom-right":
|
|
3190
|
+
return { bottom: o.bottom, right: o.right };
|
|
3191
|
+
default: {
|
|
3192
|
+
const _exhaustive = placement;
|
|
3193
|
+
return _exhaustive;
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
var barStyleBase = {
|
|
3198
|
+
position: "fixed",
|
|
3199
|
+
zIndex: 9999,
|
|
3200
|
+
display: "flex",
|
|
3201
|
+
flexWrap: "nowrap",
|
|
3202
|
+
gap: 8,
|
|
3203
|
+
alignItems: "center",
|
|
3204
|
+
padding: "8px 10px",
|
|
3205
|
+
borderRadius: 10,
|
|
3206
|
+
background: "Canvas",
|
|
3207
|
+
color: "CanvasText",
|
|
3208
|
+
border: "1px solid color-mix(in oklab, CanvasText 18%, transparent)",
|
|
3209
|
+
boxShadow: "0 4px 24px color-mix(in oklab, CanvasText 18%, transparent)",
|
|
3210
|
+
fontFamily: "system-ui, sans-serif",
|
|
3211
|
+
fontSize: 13,
|
|
3212
|
+
maxWidth: "min(92vw, 520px)"
|
|
3213
|
+
};
|
|
3214
|
+
var actionsCluster = {
|
|
3215
|
+
display: "flex",
|
|
3216
|
+
flexWrap: "wrap",
|
|
3217
|
+
gap: 8,
|
|
3218
|
+
alignItems: "center",
|
|
3219
|
+
minWidth: 0
|
|
3220
|
+
};
|
|
3221
|
+
var chromeCluster = {
|
|
3222
|
+
display: "flex",
|
|
3223
|
+
flexWrap: "nowrap",
|
|
3224
|
+
gap: 4,
|
|
3225
|
+
alignItems: "center",
|
|
3226
|
+
flexShrink: 0,
|
|
3227
|
+
marginLeft: "auto"
|
|
3228
|
+
};
|
|
3229
|
+
var countBadge = {
|
|
3230
|
+
minWidth: 18,
|
|
3231
|
+
padding: "0 5px",
|
|
3232
|
+
borderRadius: 999,
|
|
3233
|
+
background: ACCENT,
|
|
3234
|
+
color: ACCENT_FG,
|
|
3235
|
+
fontSize: 11,
|
|
3236
|
+
fontWeight: 600,
|
|
3237
|
+
textAlign: "center"
|
|
3238
|
+
};
|
|
3239
|
+
var dividerStyle = {
|
|
3240
|
+
width: 1,
|
|
3241
|
+
height: 22,
|
|
3242
|
+
background: "color-mix(in oklab, CanvasText 18%, transparent)"
|
|
3243
|
+
};
|
|
3244
|
+
var outcomeOk = {
|
|
3245
|
+
opacity: 0.75,
|
|
3246
|
+
fontSize: 12,
|
|
3247
|
+
maxWidth: "100%"
|
|
3248
|
+
};
|
|
3249
|
+
var outcomeErr = {
|
|
3250
|
+
...outcomeOk,
|
|
3251
|
+
color: "color-mix(in oklab, red 75%, CanvasText)",
|
|
3252
|
+
opacity: 1,
|
|
3253
|
+
fontWeight: 500
|
|
3254
|
+
};
|
|
3255
|
+
var integrityWarning = {
|
|
3256
|
+
opacity: 0.85,
|
|
3257
|
+
fontSize: 12,
|
|
3258
|
+
maxWidth: "100%",
|
|
3259
|
+
color: "color-mix(in oklab, CanvasText 55%, orange)",
|
|
3260
|
+
fontWeight: 500
|
|
3261
|
+
};
|
|
3262
|
+
var menuPanel = {
|
|
3263
|
+
position: "absolute",
|
|
3264
|
+
bottom: "calc(100% + 6px)",
|
|
3265
|
+
right: 0,
|
|
3266
|
+
minWidth: 220,
|
|
3267
|
+
padding: 8,
|
|
3268
|
+
borderRadius: 8,
|
|
3269
|
+
background: "Canvas",
|
|
3270
|
+
color: "CanvasText",
|
|
3271
|
+
border: "1px solid color-mix(in oklab, CanvasText 20%, transparent)",
|
|
3272
|
+
boxShadow: "0 8px 24px color-mix(in oklab, CanvasText 20%, transparent)",
|
|
3273
|
+
display: "flex",
|
|
3274
|
+
flexDirection: "column",
|
|
3275
|
+
gap: 4,
|
|
3276
|
+
zIndex: 1
|
|
3277
|
+
};
|
|
3278
|
+
var menuSectionLabel = {
|
|
3279
|
+
opacity: 0.55,
|
|
3280
|
+
fontSize: 11,
|
|
3281
|
+
fontWeight: 600,
|
|
3282
|
+
letterSpacing: "0.04em",
|
|
3283
|
+
textTransform: "uppercase",
|
|
3284
|
+
padding: "6px 8px 2px"
|
|
3285
|
+
};
|
|
3286
|
+
var menuItem = {
|
|
3287
|
+
...ghostBtn,
|
|
3288
|
+
width: "100%",
|
|
3289
|
+
justifyContent: "flex-start",
|
|
3290
|
+
border: "1px solid transparent",
|
|
3291
|
+
textAlign: "left"
|
|
3292
|
+
};
|
|
3293
|
+
function IconEdit() {
|
|
3294
|
+
return /* @__PURE__ */ jsxs(Icon, { children: [
|
|
3295
|
+
/* @__PURE__ */ jsx("path", { d: "M12 20h9" }),
|
|
3296
|
+
/* @__PURE__ */ jsx("path", { d: "M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z" })
|
|
3297
|
+
] });
|
|
3298
|
+
}
|
|
3299
|
+
function IconTables() {
|
|
3300
|
+
return /* @__PURE__ */ jsxs(Icon, { children: [
|
|
3301
|
+
/* @__PURE__ */ jsx("path", { d: "M3 5h18v14H3z" }),
|
|
3302
|
+
/* @__PURE__ */ jsx("path", { d: "M3 10h18" }),
|
|
3303
|
+
/* @__PURE__ */ jsx("path", { d: "M9 5v14" })
|
|
3304
|
+
] });
|
|
3305
|
+
}
|
|
3306
|
+
function IconSave() {
|
|
3307
|
+
return /* @__PURE__ */ jsxs(Icon, { children: [
|
|
3308
|
+
/* @__PURE__ */ jsx("path", { d: "M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2Z" }),
|
|
3309
|
+
/* @__PURE__ */ jsx("path", { d: "M17 21v-8H7v8" }),
|
|
3310
|
+
/* @__PURE__ */ jsx("path", { d: "M7 3v5h8" })
|
|
3311
|
+
] });
|
|
3312
|
+
}
|
|
3313
|
+
function IconX() {
|
|
3314
|
+
return /* @__PURE__ */ jsxs(Icon, { children: [
|
|
3315
|
+
/* @__PURE__ */ jsx("path", { d: "M18 6 6 18" }),
|
|
3316
|
+
/* @__PURE__ */ jsx("path", { d: "m6 6 12 12" })
|
|
3317
|
+
] });
|
|
3318
|
+
}
|
|
3319
|
+
function IconGear() {
|
|
3320
|
+
return /* @__PURE__ */ jsxs(Icon, { children: [
|
|
3321
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "3" }),
|
|
3322
|
+
/* @__PURE__ */ jsx("path", { d: "M12 1v2.5M12 20.5V23M4.2 4.2l1.8 1.8M18 18l1.8 1.8M1 12h2.5M20.5 12H23M4.2 19.8l1.8-1.8M18 6l1.8-1.8" })
|
|
3323
|
+
] });
|
|
3324
|
+
}
|
|
3325
|
+
function IconCollapse() {
|
|
3326
|
+
return /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" }) });
|
|
3327
|
+
}
|
|
3328
|
+
function IconExpand() {
|
|
3329
|
+
return /* @__PURE__ */ jsx(Icon, { children: /* @__PURE__ */ jsx("path", { d: "m18 15-6-6-6 6" }) });
|
|
3330
|
+
}
|
|
3331
|
+
function summarizeOutcomes(outcomes) {
|
|
3332
|
+
const actionError = outcomes.find((outcome) => outcome.id === "_error" && outcome.message);
|
|
3333
|
+
if (actionError?.message) return { text: actionError.message, error: true };
|
|
3334
|
+
const counts = {
|
|
3335
|
+
accepted: 0,
|
|
3336
|
+
rejected: 0,
|
|
3337
|
+
skipped_stale: 0,
|
|
3338
|
+
skipped_overlap: 0,
|
|
3339
|
+
withdrawn: 0
|
|
3340
|
+
};
|
|
3341
|
+
for (const outcome of outcomes) {
|
|
3342
|
+
if (outcome.outcome === "withdrawn") counts.withdrawn += 1;
|
|
3343
|
+
else counts[outcome.outcome] += 1;
|
|
3344
|
+
}
|
|
3345
|
+
const parts = [];
|
|
3346
|
+
if (counts.accepted > 0) parts.push(`${counts.accepted} published`);
|
|
3347
|
+
if (counts.withdrawn > 0) parts.push(`${counts.withdrawn} withdrawn`);
|
|
3348
|
+
if (counts.rejected > 0) parts.push(`${counts.rejected} rejected`);
|
|
3349
|
+
if (counts.skipped_stale > 0) parts.push(`${counts.skipped_stale} stale`);
|
|
3350
|
+
if (counts.skipped_overlap > 0) parts.push(`${counts.skipped_overlap} overlap`);
|
|
3351
|
+
return { text: parts.length > 0 ? parts.join(", ") : "No changes", error: false };
|
|
3352
|
+
}
|
|
3353
|
+
function CmsFloatingToolbar({
|
|
3354
|
+
placement = "bottom-right",
|
|
3355
|
+
offset,
|
|
3356
|
+
activeNavRowId = null,
|
|
3357
|
+
builderUrl,
|
|
3358
|
+
siteName
|
|
3359
|
+
} = {}) {
|
|
3360
|
+
const {
|
|
3361
|
+
editor,
|
|
3362
|
+
editMode,
|
|
3363
|
+
setEditMode,
|
|
3364
|
+
toggleEditMode,
|
|
3365
|
+
authActions,
|
|
3366
|
+
draft,
|
|
3367
|
+
proposals,
|
|
3368
|
+
myProposalId,
|
|
3369
|
+
proposalActions,
|
|
3370
|
+
actionPhase,
|
|
3371
|
+
loadingProposals,
|
|
3372
|
+
outcomes,
|
|
3373
|
+
saveDraft,
|
|
3374
|
+
discardDraft,
|
|
3375
|
+
publishMine,
|
|
3376
|
+
withdrawMine,
|
|
3377
|
+
inPlaceDirty,
|
|
3378
|
+
navigation,
|
|
3379
|
+
manifest,
|
|
3380
|
+
projection,
|
|
3381
|
+
connectBuilder,
|
|
3382
|
+
refreshBuilderSession,
|
|
3383
|
+
stagedReplaceCount,
|
|
3384
|
+
changesOpen,
|
|
3385
|
+
setChangesOpen,
|
|
3386
|
+
readableTables
|
|
3387
|
+
} = useCms();
|
|
3388
|
+
const sessionDrafts = useMySessionDrafts();
|
|
3389
|
+
const [resolvingKey, setResolvingKey] = useState(null);
|
|
3390
|
+
const [settingsOpen, setSettingsOpen] = useState(false);
|
|
3391
|
+
const [confirm, setConfirm] = useState(null);
|
|
3392
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
3393
|
+
const [panel2, setPanel] = useState(null);
|
|
3394
|
+
const [tablesLoaded, setTablesLoaded] = useState(false);
|
|
3395
|
+
const chatOpen = panel2 === "chat";
|
|
3396
|
+
const tablesOpen = panel2 === "tables";
|
|
3397
|
+
const settingsRef = useRef(null);
|
|
3398
|
+
const prevNeedsAttention = useRef(false);
|
|
3399
|
+
const settingsMenuId = useId();
|
|
3400
|
+
const setCollapsedPersist = useCallback((next) => {
|
|
3401
|
+
setCollapsed(next);
|
|
3402
|
+
writeSession(COLLAPSE_STORAGE_KEY, next ? "1" : null);
|
|
3403
|
+
}, []);
|
|
3404
|
+
const showPanel = (next) => {
|
|
3405
|
+
const shown = next === "changes" ? null : next;
|
|
3406
|
+
setPanel(shown);
|
|
3407
|
+
writeSession(PANEL_STORAGE_KEY, shown);
|
|
3408
|
+
if (next === "tables") setTablesLoaded(true);
|
|
3409
|
+
setChangesOpen(next === "changes");
|
|
3410
|
+
};
|
|
3411
|
+
useLayoutEffect(() => connectBuilder(builderUrl), [connectBuilder, builderUrl]);
|
|
3412
|
+
useEffect(() => {
|
|
3413
|
+
if (readSession(COLLAPSE_STORAGE_KEY) === "1") setCollapsed(true);
|
|
3414
|
+
const stored = readSession(PANEL_STORAGE_KEY);
|
|
3415
|
+
if (stored === "tables" || stored === "chat") setPanel(stored);
|
|
3416
|
+
setTablesLoaded(stored === "tables");
|
|
3417
|
+
}, []);
|
|
3418
|
+
useEffect(() => {
|
|
3419
|
+
if (!settingsOpen) return;
|
|
3420
|
+
const onPointer = (event) => {
|
|
3421
|
+
if (!settingsRef.current?.contains(event.target)) setSettingsOpen(false);
|
|
3422
|
+
};
|
|
3423
|
+
const onKey = (event) => {
|
|
3424
|
+
if (event.key === "Escape") setSettingsOpen(false);
|
|
3425
|
+
};
|
|
3426
|
+
document.addEventListener("mousedown", onPointer);
|
|
3427
|
+
document.addEventListener("keydown", onKey);
|
|
3428
|
+
return () => {
|
|
3429
|
+
document.removeEventListener("mousedown", onPointer);
|
|
3430
|
+
document.removeEventListener("keydown", onKey);
|
|
3431
|
+
};
|
|
3432
|
+
}, [settingsOpen]);
|
|
3433
|
+
const integrityReason = useMemo(() => {
|
|
3434
|
+
if (!activeNavRowId || !navigation.ok) return null;
|
|
3435
|
+
return describeContentRefIntegrity({
|
|
3436
|
+
manifest,
|
|
3437
|
+
navigationTable: navigation.table,
|
|
3438
|
+
projection,
|
|
3439
|
+
navRowId: activeNavRowId
|
|
3440
|
+
}).reason;
|
|
3441
|
+
}, [activeNavRowId, navigation, manifest, projection]);
|
|
3442
|
+
const hasProposalActions = proposalActions !== null;
|
|
3443
|
+
const draftCount = draft.length;
|
|
3444
|
+
const changeCount = proposals.flatMap((proposal) => proposal.patches).reduce((count, patch) => count + patchChangeCount(patch), 0);
|
|
3445
|
+
const hasMine = myProposalId !== null;
|
|
3446
|
+
const dirty = draftCount > 0 || inPlaceDirty;
|
|
3447
|
+
const pendingDraftCount = draftCount + (inPlaceDirty && draftCount === 0 ? 1 : 0);
|
|
3448
|
+
const busy = actionPhase !== "idle";
|
|
3449
|
+
const canPublish = Boolean(editor) && hasProposalActions && !dirty && hasMine && !loadingProposals;
|
|
3450
|
+
const hasIntegrityWarning = integrityReason !== null;
|
|
3451
|
+
const needsAttention = Boolean(editor) && (dirty || canPublish || busy || confirm !== null || hasIntegrityWarning);
|
|
3452
|
+
const forceExpandAttention = Boolean(editor) && (dirty || busy || confirm !== null || hasIntegrityWarning);
|
|
3453
|
+
useEffect(() => {
|
|
3454
|
+
if (forceExpandAttention && !prevNeedsAttention.current && collapsed) {
|
|
3455
|
+
setCollapsedPersist(false);
|
|
3456
|
+
}
|
|
3457
|
+
prevNeedsAttention.current = forceExpandAttention;
|
|
3458
|
+
}, [forceExpandAttention, collapsed, setCollapsedPersist]);
|
|
3459
|
+
if (!editor) return null;
|
|
3460
|
+
const barStyle = {
|
|
3461
|
+
...barStyleBase,
|
|
3462
|
+
...barPosition(placement, offset)
|
|
3463
|
+
};
|
|
3464
|
+
const chatPanel = builderUrl && chatOpen ? createPortal(
|
|
3465
|
+
/* @__PURE__ */ jsxs(Suspense, { fallback: null, children: [
|
|
3466
|
+
/* @__PURE__ */ jsx(
|
|
3467
|
+
BuilderPanel,
|
|
3468
|
+
{
|
|
3469
|
+
builderUrl,
|
|
3470
|
+
toolbarAtTop: placement.startsWith("top"),
|
|
3471
|
+
page: {
|
|
3472
|
+
// A session switch would abandon or mis-key it (E10).
|
|
3473
|
+
locked: dirty || stagedReplaceCount > 0 || busy,
|
|
3474
|
+
drafts: sessionDrafts,
|
|
3475
|
+
refreshSession: refreshBuilderSession,
|
|
3476
|
+
resolve: setResolvingKey
|
|
3477
|
+
},
|
|
3478
|
+
onClose: () => showPanel(null)
|
|
3479
|
+
}
|
|
3480
|
+
),
|
|
3481
|
+
resolvingKey ? /* @__PURE__ */ jsx(ResolveSessionDraft, { draftKey: resolvingKey, onClose: () => setResolvingKey(null) }) : null
|
|
3482
|
+
] }),
|
|
3483
|
+
document.body
|
|
3484
|
+
) : changesOpen ? createPortal(
|
|
3485
|
+
/* @__PURE__ */ jsx(
|
|
3486
|
+
ChangesView,
|
|
3487
|
+
{
|
|
3488
|
+
toolbarAtTop: placement.startsWith("top"),
|
|
3489
|
+
onClose: () => setChangesOpen(false)
|
|
3490
|
+
}
|
|
3491
|
+
),
|
|
3492
|
+
document.body
|
|
3493
|
+
) : null;
|
|
3494
|
+
const tablesDialog = tablesLoaded && readableTables.length > 0 ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(TablesDialog, { open: tablesOpen, onClose: () => showPanel(null), siteName }) }) : null;
|
|
3495
|
+
if (collapsed) {
|
|
3496
|
+
return /* @__PURE__ */ jsxs(
|
|
3497
|
+
"div",
|
|
3498
|
+
{
|
|
3499
|
+
style: {
|
|
3500
|
+
...barStyle,
|
|
3501
|
+
padding: 0,
|
|
3502
|
+
border: "none",
|
|
3503
|
+
background: "transparent",
|
|
3504
|
+
boxShadow: "none"
|
|
3505
|
+
},
|
|
3506
|
+
children: [
|
|
3507
|
+
chatPanel,
|
|
3508
|
+
tablesDialog,
|
|
3509
|
+
/* @__PURE__ */ jsxs(
|
|
3510
|
+
"button",
|
|
3511
|
+
{
|
|
3512
|
+
type: "button",
|
|
3513
|
+
style: collapsedChip,
|
|
3514
|
+
"aria-expanded": false,
|
|
3515
|
+
"aria-label": "Expand Columnus CMS toolbar",
|
|
3516
|
+
title: needsAttention ? "CMS \u2014 pending actions" : "Expand CMS toolbar",
|
|
3517
|
+
onClick: () => setCollapsedPersist(false),
|
|
3518
|
+
children: [
|
|
3519
|
+
/* @__PURE__ */ jsx(IconExpand, {}),
|
|
3520
|
+
"CMS",
|
|
3521
|
+
needsAttention ? /* @__PURE__ */ jsx(
|
|
3522
|
+
"span",
|
|
3523
|
+
{
|
|
3524
|
+
"aria-hidden": "true",
|
|
3525
|
+
style: {
|
|
3526
|
+
width: 8,
|
|
3527
|
+
height: 8,
|
|
3528
|
+
borderRadius: 999,
|
|
3529
|
+
background: "color-mix(in oklab, Canvas 70%, red)"
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
) : null
|
|
3533
|
+
]
|
|
3534
|
+
}
|
|
3535
|
+
)
|
|
3536
|
+
]
|
|
3537
|
+
}
|
|
3538
|
+
);
|
|
3539
|
+
}
|
|
3540
|
+
async function onSaveDraft() {
|
|
3541
|
+
if (await saveDraft()) {
|
|
3542
|
+
setEditMode(false);
|
|
3543
|
+
setConfirm(null);
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
function onDiscardConfirmed() {
|
|
3547
|
+
discardDraft();
|
|
3548
|
+
setEditMode(false);
|
|
3549
|
+
setConfirm(null);
|
|
3550
|
+
}
|
|
3551
|
+
function onCancelEdit() {
|
|
3552
|
+
setEditMode(false);
|
|
3553
|
+
setConfirm(null);
|
|
3554
|
+
}
|
|
3555
|
+
async function onPublishMine() {
|
|
3556
|
+
await publishMine();
|
|
3557
|
+
setConfirm(null);
|
|
3558
|
+
}
|
|
3559
|
+
async function onWithdrawConfirmed() {
|
|
3560
|
+
await withdrawMine();
|
|
3561
|
+
setConfirm(null);
|
|
3562
|
+
}
|
|
3563
|
+
const outcome = outcomes && outcomes.length > 0 ? summarizeOutcomes(outcomes) : null;
|
|
3564
|
+
return /* @__PURE__ */ jsxs("div", { style: barStyle, "data-columnus-cms-toolbar": "true", role: "toolbar", "aria-label": "Columnus CMS", children: [
|
|
3565
|
+
chatPanel,
|
|
3566
|
+
tablesDialog,
|
|
3567
|
+
confirm === "discard" ? /* @__PURE__ */ jsx(
|
|
3568
|
+
ConfirmPanel,
|
|
3569
|
+
{
|
|
3570
|
+
label: "discard",
|
|
3571
|
+
prompt: "Discard unsaved draft?",
|
|
3572
|
+
confirmLabel: "Discard",
|
|
3573
|
+
dismissLabel: "Keep editing",
|
|
3574
|
+
onConfirm: onDiscardConfirmed,
|
|
3575
|
+
onDismiss: () => setConfirm(null)
|
|
3576
|
+
}
|
|
3577
|
+
) : confirm === "withdraw" ? /* @__PURE__ */ jsx(
|
|
3578
|
+
ConfirmPanel,
|
|
3579
|
+
{
|
|
3580
|
+
label: "withdraw",
|
|
3581
|
+
prompt: "Withdraw your pending proposal?",
|
|
3582
|
+
confirmLabel: actionPhase === "withdrawing" ? "Withdrawing\u2026" : "Withdraw",
|
|
3583
|
+
dismissLabel: "Cancel",
|
|
3584
|
+
busy,
|
|
3585
|
+
onConfirm: () => void onWithdrawConfirmed(),
|
|
3586
|
+
onDismiss: () => setConfirm(null)
|
|
3587
|
+
}
|
|
3588
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3589
|
+
/* @__PURE__ */ jsxs("div", { style: actionsCluster, children: [
|
|
3590
|
+
changeCount > 0 || changesOpen ? /* @__PURE__ */ jsxs(
|
|
3591
|
+
"button",
|
|
3592
|
+
{
|
|
3593
|
+
type: "button",
|
|
3594
|
+
style: ghostBtn,
|
|
3595
|
+
"aria-pressed": changesOpen,
|
|
3596
|
+
onClick: () => showPanel(changesOpen ? null : "changes"),
|
|
3597
|
+
children: [
|
|
3598
|
+
"Changes ",
|
|
3599
|
+
/* @__PURE__ */ jsx("span", { style: countBadge, children: changeCount })
|
|
3600
|
+
]
|
|
3601
|
+
}
|
|
3602
|
+
) : null,
|
|
3603
|
+
!editMode && canPublish ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3604
|
+
/* @__PURE__ */ jsxs(
|
|
3605
|
+
"button",
|
|
3606
|
+
{
|
|
3607
|
+
type: "button",
|
|
3608
|
+
style: primaryBtn,
|
|
3609
|
+
disabled: busy,
|
|
3610
|
+
title: "Publish your current draft to the live site",
|
|
3611
|
+
onClick: () => void onPublishMine(),
|
|
3612
|
+
children: [
|
|
3613
|
+
/* @__PURE__ */ jsx(IconPublish, {}),
|
|
3614
|
+
actionPhase === "publishing" ? "Publishing\u2026" : "Publish mine"
|
|
3615
|
+
]
|
|
3616
|
+
}
|
|
3617
|
+
),
|
|
3618
|
+
/* @__PURE__ */ jsxs(
|
|
3619
|
+
"button",
|
|
3620
|
+
{
|
|
3621
|
+
type: "button",
|
|
3622
|
+
style: dangerBtn,
|
|
3623
|
+
disabled: busy,
|
|
3624
|
+
onClick: () => setConfirm("withdraw"),
|
|
3625
|
+
children: [
|
|
3626
|
+
/* @__PURE__ */ jsx(IconX, {}),
|
|
3627
|
+
"Withdraw mine"
|
|
3628
|
+
]
|
|
3629
|
+
}
|
|
3630
|
+
)
|
|
3631
|
+
] }) : null,
|
|
3632
|
+
!editMode ? /* @__PURE__ */ jsxs(
|
|
3633
|
+
"button",
|
|
3634
|
+
{
|
|
3635
|
+
type: "button",
|
|
3636
|
+
style: canPublish ? ghostBtn : primaryBtn,
|
|
3637
|
+
disabled: busy,
|
|
3638
|
+
onClick: toggleEditMode,
|
|
3639
|
+
children: [
|
|
3640
|
+
/* @__PURE__ */ jsx(IconEdit, {}),
|
|
3641
|
+
"Edit"
|
|
3642
|
+
]
|
|
3643
|
+
}
|
|
3644
|
+
) : null,
|
|
3645
|
+
editMode && !dirty ? /* @__PURE__ */ jsxs("button", { type: "button", style: ghostBtn, onClick: onCancelEdit, children: [
|
|
3646
|
+
/* @__PURE__ */ jsx(IconX, {}),
|
|
3647
|
+
"Cancel"
|
|
3648
|
+
] }) : null,
|
|
3649
|
+
editMode && dirty ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3650
|
+
hasProposalActions ? /* @__PURE__ */ jsxs(
|
|
3651
|
+
"button",
|
|
3652
|
+
{
|
|
3653
|
+
type: "button",
|
|
3654
|
+
style: primaryBtn,
|
|
3655
|
+
disabled: busy,
|
|
3656
|
+
title: "Propose local draft changes (applies open in-place edits first)",
|
|
3657
|
+
onClick: () => void onSaveDraft(),
|
|
3658
|
+
children: [
|
|
3659
|
+
/* @__PURE__ */ jsx(IconSave, {}),
|
|
3660
|
+
actionPhase === "saving-draft" ? "Saving\u2026" : `Save draft (${pendingDraftCount})`
|
|
3661
|
+
]
|
|
3662
|
+
}
|
|
3663
|
+
) : /* @__PURE__ */ jsxs(
|
|
3664
|
+
"button",
|
|
3665
|
+
{
|
|
3666
|
+
type: "button",
|
|
3667
|
+
style: primaryBtn,
|
|
3668
|
+
disabled: true,
|
|
3669
|
+
title: "Proposal actions unavailable \u2014 check editor session / Convex auth",
|
|
3670
|
+
children: [
|
|
3671
|
+
/* @__PURE__ */ jsx(IconSave, {}),
|
|
3672
|
+
"Save unavailable"
|
|
3673
|
+
]
|
|
3674
|
+
}
|
|
3675
|
+
),
|
|
3676
|
+
/* @__PURE__ */ jsxs(
|
|
3677
|
+
"button",
|
|
3678
|
+
{
|
|
3679
|
+
type: "button",
|
|
3680
|
+
style: dangerBtn,
|
|
3681
|
+
disabled: busy,
|
|
3682
|
+
onClick: () => setConfirm("discard"),
|
|
3683
|
+
children: [
|
|
3684
|
+
/* @__PURE__ */ jsx(IconTrash, {}),
|
|
3685
|
+
"Discard"
|
|
3686
|
+
]
|
|
3687
|
+
}
|
|
3688
|
+
)
|
|
3689
|
+
] }) : null
|
|
3690
|
+
] }),
|
|
3691
|
+
/* @__PURE__ */ jsxs("div", { style: chromeCluster, children: [
|
|
3692
|
+
/* @__PURE__ */ jsx("span", { style: dividerStyle, "aria-hidden": "true" }),
|
|
3693
|
+
readableTables.length > 0 ? /* @__PURE__ */ jsx(
|
|
3694
|
+
"button",
|
|
3695
|
+
{
|
|
3696
|
+
type: "button",
|
|
3697
|
+
style: iconOnlyBtn,
|
|
3698
|
+
title: "Tables",
|
|
3699
|
+
"aria-label": "Tables",
|
|
3700
|
+
"aria-pressed": tablesOpen,
|
|
3701
|
+
onClick: () => showPanel(tablesOpen ? null : "tables"),
|
|
3702
|
+
children: /* @__PURE__ */ jsx(IconTables, {})
|
|
3703
|
+
}
|
|
3704
|
+
) : null,
|
|
3705
|
+
builderUrl ? /* @__PURE__ */ jsx(
|
|
3706
|
+
"button",
|
|
3707
|
+
{
|
|
3708
|
+
type: "button",
|
|
3709
|
+
style: ghostBtn,
|
|
3710
|
+
"aria-pressed": chatOpen,
|
|
3711
|
+
onClick: () => showPanel(chatOpen ? null : "chat"),
|
|
3712
|
+
children: "Chat"
|
|
3713
|
+
}
|
|
3714
|
+
) : null,
|
|
3715
|
+
/* @__PURE__ */ jsxs("div", { ref: settingsRef, style: { position: "relative" }, children: [
|
|
3716
|
+
/* @__PURE__ */ jsx(
|
|
3717
|
+
"button",
|
|
3718
|
+
{
|
|
3719
|
+
type: "button",
|
|
3720
|
+
style: iconOnlyBtn,
|
|
3721
|
+
title: "Settings",
|
|
3722
|
+
"aria-label": "CMS settings",
|
|
3723
|
+
"aria-expanded": settingsOpen,
|
|
3724
|
+
"aria-controls": settingsMenuId,
|
|
3725
|
+
"aria-haspopup": "menu",
|
|
3726
|
+
onClick: () => setSettingsOpen((open) => !open),
|
|
3727
|
+
children: /* @__PURE__ */ jsx(IconGear, {})
|
|
3728
|
+
}
|
|
3729
|
+
),
|
|
3730
|
+
settingsOpen ? /* @__PURE__ */ jsxs("div", { id: settingsMenuId, role: "menu", style: menuPanel, children: [
|
|
3731
|
+
/* @__PURE__ */ jsx("div", { style: menuSectionLabel, children: "Account" }),
|
|
3732
|
+
/* @__PURE__ */ jsx(
|
|
3733
|
+
"div",
|
|
3734
|
+
{
|
|
3735
|
+
style: {
|
|
3736
|
+
opacity: 0.75,
|
|
3737
|
+
padding: "2px 8px 6px",
|
|
3738
|
+
wordBreak: "break-all",
|
|
3739
|
+
fontSize: 12
|
|
3740
|
+
},
|
|
3741
|
+
children: editor.user.email
|
|
3742
|
+
}
|
|
3743
|
+
),
|
|
3744
|
+
/* @__PURE__ */ jsx(
|
|
3745
|
+
"button",
|
|
3746
|
+
{
|
|
3747
|
+
type: "button",
|
|
3748
|
+
role: "menuitem",
|
|
3749
|
+
style: menuItem,
|
|
3750
|
+
disabled: !authActions,
|
|
3751
|
+
onClick: () => {
|
|
3752
|
+
setSettingsOpen(false);
|
|
3753
|
+
void authActions?.signOut();
|
|
3754
|
+
},
|
|
3755
|
+
children: "Logout"
|
|
3756
|
+
}
|
|
3757
|
+
)
|
|
3758
|
+
] }) : null
|
|
3759
|
+
] }),
|
|
3760
|
+
/* @__PURE__ */ jsx(
|
|
3761
|
+
"button",
|
|
3762
|
+
{
|
|
3763
|
+
type: "button",
|
|
3764
|
+
style: iconOnlyBtn,
|
|
3765
|
+
title: "Collapse toolbar",
|
|
3766
|
+
"aria-label": "Collapse Columnus CMS toolbar",
|
|
3767
|
+
"aria-expanded": true,
|
|
3768
|
+
onClick: () => {
|
|
3769
|
+
setSettingsOpen(false);
|
|
3770
|
+
setConfirm(null);
|
|
3771
|
+
setCollapsedPersist(true);
|
|
3772
|
+
},
|
|
3773
|
+
children: /* @__PURE__ */ jsx(IconCollapse, {})
|
|
3774
|
+
}
|
|
3775
|
+
)
|
|
3776
|
+
] })
|
|
3777
|
+
] }),
|
|
3778
|
+
integrityReason ? /* @__PURE__ */ jsx("span", { style: integrityWarning, role: "status", children: integrityReason }) : null,
|
|
3779
|
+
outcome ? /* @__PURE__ */ jsx(
|
|
3780
|
+
"span",
|
|
3781
|
+
{
|
|
3782
|
+
style: outcome.error ? outcomeErr : outcomeOk,
|
|
3783
|
+
role: outcome.error ? "alert" : "status",
|
|
3784
|
+
children: outcome.text
|
|
3785
|
+
}
|
|
3786
|
+
) : null
|
|
3787
|
+
] });
|
|
3788
|
+
}
|
|
3789
|
+
var card2 = {
|
|
3790
|
+
...cmsBox,
|
|
3791
|
+
maxWidth: 380,
|
|
3792
|
+
margin: "15vh auto",
|
|
3793
|
+
fontFamily: "system-ui, sans-serif",
|
|
3794
|
+
display: "flex",
|
|
3795
|
+
flexDirection: "column",
|
|
3796
|
+
gap: 12
|
|
3797
|
+
};
|
|
3798
|
+
var label = { display: "flex", flexDirection: "column", gap: 6 };
|
|
3799
|
+
var input = { ...ghostBtn, padding: "8px 10px", cursor: "text" };
|
|
3800
|
+
var title = { fontSize: 20, margin: 0 };
|
|
3801
|
+
function CmsLoginPage() {
|
|
3802
|
+
const { editor, authActions } = useCms();
|
|
3803
|
+
const [email, setEmail] = useState("");
|
|
3804
|
+
const [otp, setOtp] = useState("");
|
|
3805
|
+
const [step, setStep] = useState("email");
|
|
3806
|
+
const [error, setError] = useState(null);
|
|
3807
|
+
const [pending, setPending] = useState(false);
|
|
3808
|
+
useEffect(() => {
|
|
3809
|
+
if (editor) window.location.replace("/");
|
|
3810
|
+
}, [editor]);
|
|
3811
|
+
if (editor) return null;
|
|
3812
|
+
if (!authActions) {
|
|
3813
|
+
return /* @__PURE__ */ jsxs("div", { style: card2, children: [
|
|
3814
|
+
/* @__PURE__ */ jsx("h1", { style: title, children: "Columnus CMS" }),
|
|
3815
|
+
/* @__PURE__ */ jsx("p", { style: { margin: 0 }, children: "Auth actions are not configured on CmsProvider." })
|
|
3816
|
+
] });
|
|
3817
|
+
}
|
|
3818
|
+
const sending = step === "email";
|
|
3819
|
+
const onSubmit = (event) => {
|
|
3820
|
+
event.preventDefault();
|
|
3821
|
+
setError(null);
|
|
3822
|
+
setPending(true);
|
|
3823
|
+
(sending ? authActions.sendLoginCode(email.trim()).then(() => setStep("otp")) : authActions.verifyLoginCode(email.trim(), otp.trim()).then(() => window.location.assign("/"))).catch(
|
|
3824
|
+
(err) => setError(
|
|
3825
|
+
err instanceof Error ? err.message : sending ? "Failed to send code" : "Invalid code"
|
|
3826
|
+
)
|
|
3827
|
+
).finally(() => setPending(false));
|
|
3828
|
+
};
|
|
3829
|
+
return /* @__PURE__ */ jsxs("form", { style: card2, onSubmit, children: [
|
|
3830
|
+
/* @__PURE__ */ jsx("h1", { style: title, children: "Columnus CMS" }),
|
|
3831
|
+
sending ? /* @__PURE__ */ jsxs("label", { style: label, children: [
|
|
3832
|
+
"Email",
|
|
3833
|
+
/* @__PURE__ */ jsx(
|
|
3834
|
+
"input",
|
|
3835
|
+
{
|
|
3836
|
+
style: input,
|
|
3837
|
+
type: "email",
|
|
3838
|
+
autoComplete: "username",
|
|
3839
|
+
required: true,
|
|
3840
|
+
value: email,
|
|
3841
|
+
onChange: (e) => setEmail(e.target.value)
|
|
3842
|
+
}
|
|
3843
|
+
)
|
|
3844
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3845
|
+
/* @__PURE__ */ jsxs("p", { style: { margin: 0, color: cmsMuted }, children: [
|
|
3846
|
+
"Code sent to ",
|
|
3847
|
+
email
|
|
3848
|
+
] }),
|
|
3849
|
+
/* @__PURE__ */ jsxs("label", { style: label, children: [
|
|
3850
|
+
"One-time code",
|
|
3851
|
+
/* @__PURE__ */ jsx(
|
|
3852
|
+
"input",
|
|
3853
|
+
{
|
|
3854
|
+
style: input,
|
|
3855
|
+
type: "text",
|
|
3856
|
+
inputMode: "numeric",
|
|
3857
|
+
autoComplete: "one-time-code",
|
|
3858
|
+
required: true,
|
|
3859
|
+
value: otp,
|
|
3860
|
+
onChange: (e) => setOtp(e.target.value)
|
|
3861
|
+
}
|
|
3862
|
+
)
|
|
3863
|
+
] })
|
|
3864
|
+
] }),
|
|
3865
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
|
|
3866
|
+
/* @__PURE__ */ jsx("button", { style: primaryBtn, type: "submit", disabled: pending, children: sending ? pending ? "Sending\u2026" : "Send code" : pending ? "Verifying\u2026" : "Verify" }),
|
|
3867
|
+
sending ? null : /* @__PURE__ */ jsx(
|
|
3868
|
+
"button",
|
|
3869
|
+
{
|
|
3870
|
+
style: ghostBtn,
|
|
3871
|
+
type: "button",
|
|
3872
|
+
disabled: pending,
|
|
3873
|
+
onClick: () => {
|
|
3874
|
+
setStep("email");
|
|
3875
|
+
setOtp("");
|
|
3876
|
+
setError(null);
|
|
3877
|
+
},
|
|
3878
|
+
children: "Back"
|
|
3879
|
+
}
|
|
3880
|
+
)
|
|
3881
|
+
] }),
|
|
3882
|
+
error ? /* @__PURE__ */ jsx("p", { style: { margin: 0, color: "crimson" }, role: "alert", children: error }) : null
|
|
3883
|
+
] });
|
|
3884
|
+
}
|
|
3885
|
+
function proposeEditableTable(manifest, tableName, canProposeField2) {
|
|
3886
|
+
const schema = manifest.tables.find((entry) => entry.name === tableName);
|
|
3887
|
+
if (!schema) return null;
|
|
3888
|
+
return {
|
|
3889
|
+
...schema,
|
|
3890
|
+
fields: schema.fields.filter((field) => canProposeField2(tableName, field.name))
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
function DraftRowDialog({
|
|
3894
|
+
table,
|
|
3895
|
+
open,
|
|
3896
|
+
onOpenChange,
|
|
3897
|
+
rowId,
|
|
3898
|
+
initial,
|
|
3899
|
+
onSubmit
|
|
3900
|
+
}) {
|
|
3901
|
+
const cms = useCms();
|
|
3902
|
+
const editable = proposeEditableTable(cms.manifest, table, cms.canProposeField);
|
|
3903
|
+
const editing = Boolean(rowId);
|
|
3904
|
+
const initialDoc = useMemo(() => {
|
|
3905
|
+
if (!rowId) return void 0;
|
|
3906
|
+
return { _id: rowId, ...stripSystemFields(initial ?? {}) };
|
|
3907
|
+
}, [rowId, initial]);
|
|
3908
|
+
if (!editable || editable.fields.length === 0) {
|
|
3909
|
+
return null;
|
|
3910
|
+
}
|
|
3911
|
+
return /* @__PURE__ */ jsx(FieldsDataProvider, { adapter: cms.adapters.fieldsDataAdapter, children: /* @__PURE__ */ jsx(
|
|
3912
|
+
RowEditor,
|
|
3913
|
+
{
|
|
3914
|
+
open,
|
|
3915
|
+
onOpenChange,
|
|
3916
|
+
table: editable,
|
|
3917
|
+
mode: editing ? "edit" : "create",
|
|
3918
|
+
initial: initialDoc,
|
|
3919
|
+
saveLabel: "Add to draft",
|
|
3920
|
+
overlayZIndex: CMS_ROW_EDITOR_Z_INDEX,
|
|
3921
|
+
allowCreate: (refTable) => cms.canProposeOp(refTable, "insert"),
|
|
3922
|
+
onSubmit: async (doc) => {
|
|
3923
|
+
const fields = stripSystemFields(doc);
|
|
3924
|
+
if (onSubmit) {
|
|
3925
|
+
onSubmit(fields);
|
|
3926
|
+
} else if (rowId) {
|
|
3927
|
+
cms.applyRowEdit({ table, rowId, fields });
|
|
3928
|
+
} else {
|
|
3929
|
+
cms.addInsert({ table, fields });
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
) });
|
|
3934
|
+
}
|
|
3935
|
+
function InsertRowDialog(props) {
|
|
3936
|
+
return /* @__PURE__ */ jsx(DraftRowDialog, { ...props });
|
|
3937
|
+
}
|
|
3938
|
+
var EMPTY_CONTEXT = {};
|
|
3939
|
+
var EMPTY_DEFAULTS = {};
|
|
3940
|
+
function applyDefaults(args) {
|
|
3941
|
+
const next = { ...args.values };
|
|
3942
|
+
for (const [record, fields] of Object.entries(args.defaults)) {
|
|
3943
|
+
for (const [field, value] of Object.entries(fields ?? {})) {
|
|
3944
|
+
if (args.touched.has(`${record}\0${field}`)) continue;
|
|
3945
|
+
const current = next[record]?.[field];
|
|
3946
|
+
if (Object.is(current, value)) continue;
|
|
3947
|
+
next[record] = { ...next[record], [field]: value };
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
return next;
|
|
3951
|
+
}
|
|
3952
|
+
function CmsCompoundCreate({
|
|
3953
|
+
recipeId,
|
|
3954
|
+
context,
|
|
3955
|
+
open,
|
|
3956
|
+
onOpenChange,
|
|
3957
|
+
saveLabel = "Add to draft"
|
|
3958
|
+
}) {
|
|
3959
|
+
const cms = useCms();
|
|
3960
|
+
const recipe = cms.createRecipes.get(recipeId);
|
|
3961
|
+
const [values, setValues] = useState({});
|
|
3962
|
+
const [touched, setTouched] = useState(() => /* @__PURE__ */ new Set());
|
|
3963
|
+
const [error, setError] = useState(null);
|
|
3964
|
+
const contextSnapshotRef = useRef(EMPTY_CONTEXT);
|
|
3965
|
+
const initializedRecipeIdRef = useRef(null);
|
|
3966
|
+
const records = useMemo(() => {
|
|
3967
|
+
if (!recipe) return [];
|
|
3968
|
+
return recipe.orderedRecordKeys.map((key) => {
|
|
3969
|
+
const record = recipe.records.get(key);
|
|
3970
|
+
return {
|
|
3971
|
+
key,
|
|
3972
|
+
table: record.table,
|
|
3973
|
+
fields: editableCompoundFields(recipe, key, cms.canProposeField)
|
|
3974
|
+
};
|
|
3975
|
+
});
|
|
3976
|
+
}, [cms.canProposeField, recipe]);
|
|
3977
|
+
const unavailableReason = useMemo(
|
|
3978
|
+
() => compoundCreateUnavailableReason(recipeId, recipe, cms.canProposeOp, cms.canProposeField),
|
|
3979
|
+
[cms.canProposeField, cms.canProposeOp, recipe, recipeId]
|
|
3980
|
+
);
|
|
3981
|
+
useEffect(() => {
|
|
3982
|
+
if (!open) {
|
|
3983
|
+
initializedRecipeIdRef.current = null;
|
|
3984
|
+
return;
|
|
3985
|
+
}
|
|
3986
|
+
if (!recipe || unavailableReason || initializedRecipeIdRef.current === recipeId) return;
|
|
3987
|
+
initializedRecipeIdRef.current = recipeId;
|
|
3988
|
+
const contextSnapshot = context ?? EMPTY_CONTEXT;
|
|
3989
|
+
contextSnapshotRef.current = contextSnapshot;
|
|
3990
|
+
const initial = {};
|
|
3991
|
+
setTouched(/* @__PURE__ */ new Set());
|
|
3992
|
+
setValues(
|
|
3993
|
+
applyDefaults({
|
|
3994
|
+
values: initial,
|
|
3995
|
+
defaults: recipe.recipe.defaults?.({ context: contextSnapshot, values: initial }) ?? EMPTY_DEFAULTS,
|
|
3996
|
+
touched: /* @__PURE__ */ new Set()
|
|
3997
|
+
})
|
|
3998
|
+
);
|
|
3999
|
+
setError(null);
|
|
4000
|
+
}, [context, open, recipe, recipeId, unavailableReason]);
|
|
4001
|
+
const raisedStyle2 = { zIndex: CMS_ROW_EDITOR_Z_INDEX };
|
|
4002
|
+
if (unavailableReason) {
|
|
4003
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(
|
|
4004
|
+
DialogContent,
|
|
4005
|
+
{
|
|
4006
|
+
style: raisedStyle2,
|
|
4007
|
+
overlayStyle: raisedStyle2,
|
|
4008
|
+
onPointerDownOutside: preventDismissOnPickerOverlay,
|
|
4009
|
+
onInteractOutside: preventDismissOnPickerOverlay,
|
|
4010
|
+
onFocusOutside: preventDismissOnPickerOverlay,
|
|
4011
|
+
children: [
|
|
4012
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
4013
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: "Add records" }),
|
|
4014
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: unavailableReason })
|
|
4015
|
+
] }),
|
|
4016
|
+
/* @__PURE__ */ jsx(DialogFooter, { children: /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), children: "Close" }) })
|
|
4017
|
+
]
|
|
4018
|
+
}
|
|
4019
|
+
) });
|
|
4020
|
+
}
|
|
4021
|
+
const updateField = (recordKey, field, value) => {
|
|
4022
|
+
if (!recipe) return;
|
|
4023
|
+
const nextTouched = new Set(touched).add(`${recordKey}\0${field}`);
|
|
4024
|
+
setTouched(nextTouched);
|
|
4025
|
+
setValues((previous) => {
|
|
4026
|
+
const next = {
|
|
4027
|
+
...previous,
|
|
4028
|
+
[recordKey]: { ...previous[recordKey], [field]: value }
|
|
4029
|
+
};
|
|
4030
|
+
return applyDefaults({
|
|
4031
|
+
values: next,
|
|
4032
|
+
defaults: recipe.recipe.defaults?.({ context: contextSnapshotRef.current, values: next }) ?? EMPTY_DEFAULTS,
|
|
4033
|
+
touched: nextTouched
|
|
4034
|
+
});
|
|
4035
|
+
});
|
|
4036
|
+
};
|
|
4037
|
+
const submit = () => {
|
|
4038
|
+
try {
|
|
4039
|
+
cms.createCompound({
|
|
4040
|
+
recipeId,
|
|
4041
|
+
context: contextSnapshotRef.current,
|
|
4042
|
+
values
|
|
4043
|
+
});
|
|
4044
|
+
onOpenChange(false);
|
|
4045
|
+
} catch (cause) {
|
|
4046
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4047
|
+
}
|
|
4048
|
+
};
|
|
4049
|
+
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(
|
|
4050
|
+
DialogContent,
|
|
4051
|
+
{
|
|
4052
|
+
className: "max-h-[85vh] max-w-2xl overflow-y-auto",
|
|
4053
|
+
style: raisedStyle2,
|
|
4054
|
+
overlayStyle: raisedStyle2,
|
|
4055
|
+
onPointerDownOutside: preventDismissOnPickerOverlay,
|
|
4056
|
+
onInteractOutside: preventDismissOnPickerOverlay,
|
|
4057
|
+
onFocusOutside: preventDismissOnPickerOverlay,
|
|
4058
|
+
children: [
|
|
4059
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
4060
|
+
/* @__PURE__ */ jsx(DialogTitle, { children: "Add records" }),
|
|
4061
|
+
/* @__PURE__ */ jsx(DialogDescription, { children: "Create all configured records as one draft batch." })
|
|
4062
|
+
] }),
|
|
4063
|
+
/* @__PURE__ */ jsx(FieldsDataProvider, { adapter: cms.adapters.fieldsDataAdapter, children: /* @__PURE__ */ jsx("div", { className: "space-y-6", children: records.map((record) => /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
|
|
4064
|
+
/* @__PURE__ */ jsx("h3", { className: "border-b pb-2 text-sm font-semibold", children: tableDisplayName(record.table) }),
|
|
4065
|
+
record.fields.map((field) => {
|
|
4066
|
+
const inputId = `compound-${recipeId}-${record.key}-${field.name}`;
|
|
4067
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
|
|
4068
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: inputId, children: [
|
|
4069
|
+
fieldDisplayName(field),
|
|
4070
|
+
field.optional ? " (optional)" : null
|
|
4071
|
+
] }),
|
|
4072
|
+
/* @__PURE__ */ jsx(
|
|
4073
|
+
FieldInput,
|
|
4074
|
+
{
|
|
4075
|
+
type: field.type,
|
|
4076
|
+
value: values[record.key]?.[field.name],
|
|
4077
|
+
optional: field.optional,
|
|
4078
|
+
onChange: (value) => updateField(record.key, field.name, value),
|
|
4079
|
+
allowCreate: (refTable) => cms.canProposeOp(refTable, "insert"),
|
|
4080
|
+
manifest: cms.manifest,
|
|
4081
|
+
inputId,
|
|
4082
|
+
uploadTarget: {
|
|
4083
|
+
table: record.table.name,
|
|
4084
|
+
field: field.name,
|
|
4085
|
+
...field.asset ? { profile: field.asset.profile } : {}
|
|
4086
|
+
},
|
|
4087
|
+
assetProfile: field.asset
|
|
4088
|
+
}
|
|
4089
|
+
)
|
|
4090
|
+
] }, field.name);
|
|
4091
|
+
})
|
|
4092
|
+
] }, record.key)) }) }),
|
|
4093
|
+
error ? /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }) : null,
|
|
4094
|
+
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
4095
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
4096
|
+
/* @__PURE__ */ jsx(Button, { onClick: submit, children: saveLabel })
|
|
4097
|
+
] })
|
|
4098
|
+
]
|
|
4099
|
+
}
|
|
4100
|
+
) });
|
|
4101
|
+
}
|
|
4102
|
+
function CmsCreateButton({
|
|
4103
|
+
recipeId,
|
|
4104
|
+
context,
|
|
4105
|
+
label: label2,
|
|
4106
|
+
saveLabel,
|
|
4107
|
+
className
|
|
4108
|
+
}) {
|
|
4109
|
+
const cms = useCmsOptional();
|
|
4110
|
+
const [open, setOpen] = useState(false);
|
|
4111
|
+
if (!cms?.editMode) return null;
|
|
4112
|
+
if (compoundCreateUnavailableReason(
|
|
4113
|
+
recipeId,
|
|
4114
|
+
cms.createRecipes.get(recipeId),
|
|
4115
|
+
cms.canProposeOp,
|
|
4116
|
+
cms.canProposeField
|
|
4117
|
+
)) {
|
|
4118
|
+
return null;
|
|
4119
|
+
}
|
|
4120
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4121
|
+
/* @__PURE__ */ jsx("button", { type: "button", className, onClick: () => setOpen(true), children: label2 }),
|
|
4122
|
+
/* @__PURE__ */ jsx(
|
|
4123
|
+
CmsCompoundCreate,
|
|
4124
|
+
{
|
|
4125
|
+
recipeId,
|
|
4126
|
+
context,
|
|
4127
|
+
open,
|
|
4128
|
+
onOpenChange: setOpen,
|
|
4129
|
+
saveLabel
|
|
4130
|
+
}
|
|
4131
|
+
)
|
|
4132
|
+
] });
|
|
4133
|
+
}
|
|
4134
|
+
|
|
4135
|
+
// packages/@columnus/cms/src/nav/slugify-de.ts
|
|
4136
|
+
function slugifyDe(input2) {
|
|
4137
|
+
const base = input2.trim().toLowerCase().replace(/ä/g, "ae").replace(/ö/g, "oe").replace(/ü/g, "ue").replace(/ß/g, "ss").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").replace(/-+/g, "-");
|
|
4138
|
+
return base || "page";
|
|
4139
|
+
}
|
|
4140
|
+
function uniqueSlug(base, existing) {
|
|
4141
|
+
const taken = existing instanceof Set ? existing : new Set(existing);
|
|
4142
|
+
if (!taken.has(base)) return base;
|
|
4143
|
+
for (let n = 2; ; n++) {
|
|
4144
|
+
const candidate = `${base}-${n}`;
|
|
4145
|
+
if (!taken.has(candidate)) return candidate;
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4149
|
+
// packages/@columnus/cms/src/profile/readable-tables.ts
|
|
4150
|
+
function cmsReadableTables(profile) {
|
|
4151
|
+
if (profile.tableAccess && profile.tableAccess.length > 0) {
|
|
4152
|
+
const names = [];
|
|
4153
|
+
for (const access of profile.tableAccess) {
|
|
4154
|
+
if (!editorAccessEnabled(access)) continue;
|
|
4155
|
+
const table = access.table.trim();
|
|
4156
|
+
if (table) names.push(table);
|
|
4157
|
+
}
|
|
4158
|
+
return names;
|
|
4159
|
+
}
|
|
4160
|
+
return (profile.tables ?? []).map((t) => t.trim()).filter(Boolean);
|
|
4161
|
+
}
|
|
4162
|
+
|
|
4163
|
+
// packages/@columnus/cms/src/cache/html-cache.ts
|
|
4164
|
+
var HTML_CACHE_BYPASS_HEADER = "x-html-cache-bypass";
|
|
4165
|
+
function shouldBypassHtmlCache(request) {
|
|
4166
|
+
if (request.headers.get(HTML_CACHE_BYPASS_HEADER) === "1") return true;
|
|
4167
|
+
return readSessionCookie(request.headers.get("cookie")) !== null;
|
|
4168
|
+
}
|
|
4169
|
+
function isCmsPath(pathname) {
|
|
4170
|
+
const path = pathname.endsWith("/") && pathname.length > 1 ? pathname.slice(0, -1) : pathname;
|
|
4171
|
+
return path === "/cms" || path.startsWith("/cms/");
|
|
4172
|
+
}
|
|
4173
|
+
function CmsRichDocRecordLink({
|
|
4174
|
+
table,
|
|
4175
|
+
id,
|
|
4176
|
+
label: label2
|
|
4177
|
+
}) {
|
|
4178
|
+
const cms = useCmsOptional();
|
|
4179
|
+
const related = useCmsRelatedRow(table, id);
|
|
4180
|
+
if (!id) return null;
|
|
4181
|
+
if (!cms?.editor) return label2;
|
|
4182
|
+
return relatedRowPreview({
|
|
4183
|
+
relatedRow: related,
|
|
4184
|
+
relatedFields: manifestFields(cms.manifest, table),
|
|
4185
|
+
displayPreview: void 0,
|
|
4186
|
+
id
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
function CmsRichDocViewSession({
|
|
4190
|
+
cms,
|
|
4191
|
+
recordLink,
|
|
4192
|
+
resolveAssetUrl,
|
|
4193
|
+
locale,
|
|
4194
|
+
...props
|
|
4195
|
+
}) {
|
|
4196
|
+
const ids = typeof props.value === "string" ? collectRichDocAssetIds(props.value) : [];
|
|
4197
|
+
const { urls } = cms.adapters.fieldsDataAdapter.useAssetDisplay(ids);
|
|
4198
|
+
return /* @__PURE__ */ jsx(
|
|
4199
|
+
RichDocView,
|
|
4200
|
+
{
|
|
4201
|
+
headingBaseLevel: 2,
|
|
4202
|
+
locale: locale ?? cms.adapters.locale,
|
|
4203
|
+
...props,
|
|
4204
|
+
resolveAssetUrl: resolveAssetUrl ?? ((assetId) => urls.get(assetId)),
|
|
4205
|
+
recordLink: recordLink ?? ((table, id, label2) => /* @__PURE__ */ jsx(CmsRichDocRecordLink, { table, id, label: label2 }))
|
|
4206
|
+
}
|
|
4207
|
+
);
|
|
4208
|
+
}
|
|
4209
|
+
function CmsRichDocView(props) {
|
|
4210
|
+
const cms = useCmsOptional();
|
|
4211
|
+
if (!cms) return /* @__PURE__ */ jsx(RichDocView, { headingBaseLevel: 2, ...props });
|
|
4212
|
+
return /* @__PURE__ */ jsx(CmsRichDocViewSession, { cms, ...props });
|
|
4213
|
+
}
|
|
4214
|
+
|
|
4215
|
+
export { CmsCompoundCreate, CmsCreateButton, CmsField, CmsFieldStamp, CmsFloatingToolbar, CmsLoginPage, CmsProvider, CmsRichDocView, CmsRow, DefaultRichtextHostProvider, DraftRowDialog, FieldEditorDialog, HTML_CACHE_BYPASS_HEADER, InsertRowDialog, applyDeleteToDraft, applyFieldToDraft, applyRowToDraft, buildInsertDraft, canProposeField, canProposeOp, cmsReadableTables, createDefaultCmsRichtextAdapters, createDefaultRichtextHostAdapter, createTableRowsRichtextHostAdapter, describeContentRefIntegrity, findContentRefField, inferNavigationTable, isCmsPath, mergeDraftIntoProposal, proposeEditableTable, readSession, resolveEditSurface, resolveStampDisplay, shouldBypassHtmlCache, slugifyDe, stampEditKey, uniqueSlug, useCms, useCmsOptional, useCmsProjectedField, useCmsProjectedString, useCmsProjectedTable, useCmsRelatedRow, useCmsRow, useCmsRowOptional, writeSession };
|
|
4216
|
+
//# sourceMappingURL=chunk-SKE2RDD2.js.map
|
|
4217
|
+
//# sourceMappingURL=chunk-SKE2RDD2.js.map
|