@elytracms/studio 0.0.78 → 0.0.79
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/components/app-views/default-modules.js +5 -1
- package/dist/components/app-views/default-modules.js.map +1 -1
- package/dist/components/assets/asset-thumb.js +12 -11
- package/dist/components/assets/asset-thumb.js.map +1 -1
- package/dist/components/builder/blocks-panel.d.ts +11 -5
- package/dist/components/builder/blocks-panel.js +18 -24
- package/dist/components/builder/blocks-panel.js.map +1 -1
- package/dist/components/builder/canvas-render-context.d.ts +22 -0
- package/dist/components/builder/canvas-render-context.js +65 -9
- package/dist/components/builder/canvas-render-context.js.map +1 -1
- package/dist/components/builder/reuse.d.ts +25 -0
- package/dist/components/builder/reuse.js +11 -2
- package/dist/components/builder/reuse.js.map +1 -1
- package/dist/components/cms/asset-field.js +52 -19
- package/dist/components/cms/asset-field.js.map +1 -1
- package/dist/components/cms/asset-picker-core.d.ts +40 -0
- package/dist/components/cms/asset-picker-core.js +21 -0
- package/dist/components/cms/asset-picker-core.js.map +1 -1
- package/dist/components/cms/asset-picker.d.ts +11 -2
- package/dist/components/cms/asset-picker.js +34 -13
- package/dist/components/cms/asset-picker.js.map +1 -1
- package/dist/components/cms/cell.js +2 -1
- package/dist/components/cms/cell.js.map +1 -1
- package/dist/components/cms/cms-store.d.ts +8 -1
- package/dist/components/cms/cms-store.js +8 -7
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.js +7 -1
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/date-input-core.d.ts +64 -0
- package/dist/components/cms/date-input-core.js +78 -0
- package/dist/components/cms/date-input-core.js.map +1 -0
- package/dist/components/cms/date-input.d.ts +43 -0
- package/dist/components/cms/date-input.js +109 -0
- package/dist/components/cms/date-input.js.map +1 -0
- package/dist/components/cms/document-diff-view.js +2 -1
- package/dist/components/cms/document-diff-view.js.map +1 -1
- package/dist/components/cms/document-staging.d.ts +15 -4
- package/dist/components/cms/document-staging.js +26 -15
- package/dist/components/cms/document-staging.js.map +1 -1
- package/dist/components/cms/editable-cell.js +39 -5
- package/dist/components/cms/editable-cell.js.map +1 -1
- package/dist/components/cms/field-control.js +38 -7
- package/dist/components/cms/field-control.js.map +1 -1
- package/dist/components/cms/scalar-value-editor.js +4 -1
- package/dist/components/cms/scalar-value-editor.js.map +1 -1
- package/dist/components/cms/slug-auto-derive.d.ts +41 -0
- package/dist/components/cms/slug-auto-derive.js +14 -0
- package/dist/components/cms/slug-auto-derive.js.map +1 -0
- package/dist/components/components/transfer-dialog.js +3 -1
- package/dist/components/components/transfer-dialog.js.map +1 -1
- package/dist/components/project-session.d.ts +44 -22
- package/dist/components/project-session.js +72 -36
- package/dist/components/project-session.js.map +1 -1
- package/dist/lib/assets/asset-url.d.ts +20 -0
- package/dist/lib/assets/asset-url.js +25 -0
- package/dist/lib/assets/asset-url.js.map +1 -0
- package/dist/lib/assets/browser-blob-storage.d.ts +80 -0
- package/dist/lib/assets/browser-blob-storage.js +86 -0
- package/dist/lib/assets/browser-blob-storage.js.map +1 -0
- package/dist/lib/assets/index.d.ts +2 -0
- package/dist/lib/assets/index.js +2 -0
- package/dist/lib/assets/index.js.map +1 -1
- package/dist/lib/data/collection-content.d.ts +20 -1
- package/dist/lib/data/collection-content.js +51 -1
- package/dist/lib/data/collection-content.js.map +1 -1
- package/dist/lib/data/content-session-refresh.d.ts +74 -0
- package/dist/lib/data/content-session-refresh.js +138 -0
- package/dist/lib/data/content-session-refresh.js.map +1 -0
- package/dist/lib/data/index.d.ts +2 -0
- package/dist/lib/data/index.js +2 -0
- package/dist/lib/data/index.js.map +1 -1
- package/dist/lib/data/playground-unload-guard.d.ts +22 -0
- package/dist/lib/data/playground-unload-guard.js +73 -0
- package/dist/lib/data/playground-unload-guard.js.map +1 -0
- package/dist/lib/i18n/messages.de.js +3 -1
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +2 -0
- package/dist/lib/i18n/messages.en.js +5 -1
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/persistence/index.js +6 -1
- package/dist/lib/persistence/index.js.map +1 -1
- package/dist/ui/input.d.ts +8 -3
- package/dist/ui/input.js +6 -1
- package/dist/ui/input.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scalar-value-editor.js","sourceRoot":"","sources":["../../../src/components/cms/scalar-value-editor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"scalar-value-editor.js","sourceRoot":"","sources":["../../../src/components/cms/scalar-value-editor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAA;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,GAAG,SAAS,CAAC,iBAAiB,CAAC,EACxC,QAAQ,GAQT;IACC,QAAQ,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;QAC1B,KAAK,SAAS;YACZ,OAAO,CACL,MAAC,MAAM,kBACO,SAAS,EACrB,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,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,EAAE,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAC1C,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GACtD,CACH,CAAA;QACH;YACE,OAAO,CACL,KAAC,eAAe,IACd,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EACtB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GACtD,CACH,CAAA;IACL,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,OAAO,EACP,IAAI,GAAG,MAAM,EACb,WAAW,EACX,SAAS,GAAG,SAAS,CAAC,iBAAiB,CAAC,EACxC,MAAM,EACN,MAAM,GAQP;IACC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC3C,OAAO,CACL,KAAC,KAAK,kBACQ,SAAS,EACrB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,IAAI,SAAS,CAAC,4BAA4B,CAAC,EACnE,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC5B,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC5B,CAAC,EACD,SAAS,EAAC,kBAAkB,iBACf,MAAM,GACnB,CACH,CAAA;AACH,CAAC","sourcesContent":["import { useState } from 'react'\nimport type { FilterScalar } from '@elytracms/core/content'\nimport { Input, Select } from '@elytracms/studio/ui'\nimport { localizedLabel, translate } from '@elytracms/studio/lib/i18n'\nimport { scalarFromText } from '@elytracms/studio/lib/cms-views'\nimport type { FilterableFieldOption } from '@elytracms/studio/lib/cms-views'\nimport { DateInput } from './date-input'\n\n/**\n * The closed single-scalar value control (EC-247), shared by the filter\n * builder's `eq`/comparison clauses and the bulk set-field action so both\n * surfaces enter a value the SAME way. It renders exactly the input the field's\n * schema type warrants — a select for boolean/select, a date input, a\n * number/text input otherwise. The `in` multi-value list and the\n * publication-state pseudo field stay in the filter builder: they are\n * filter-only and never a set-field target.\n *\n * It is deliberately *closed* — no field type invents a new control — keeping\n * value entry consistent and agent-inspectable across the two surfaces.\n */\nexport function ScalarFieldValueEditor({\n option,\n value,\n testId,\n ariaLabel = translate('cms.field.value'),\n onChange,\n}: {\n /** The field whose value is being entered (its `def` drives the control). */\n option: FilterableFieldOption | undefined\n value: FilterScalar\n testId: string\n ariaLabel?: string\n onChange: (value: FilterScalar) => void\n}) {\n switch (option?.def?.type) {\n case 'boolean':\n return (\n <Select\n aria-label={ariaLabel}\n value={value === true ? 'true' : 'false'}\n onChange={(event) => onChange(event.target.value === 'true')}\n className=\"h-7 w-auto py-0 text-xs\"\n data-testid={testId}\n >\n <option value=\"true\">{translate('common.true')}</option>\n <option value=\"false\">{translate('common.false')}</option>\n </Select>\n )\n case 'select':\n return (\n <Select\n aria-label={ariaLabel}\n value={String(value)}\n onChange={(event) => onChange(event.target.value)}\n className=\"h-7 w-auto py-0 text-xs\"\n data-testid={testId}\n >\n <option value=\"\">—</option>\n {option.def.options.map((opt) => (\n <option key={opt.value} value={opt.value}>\n {localizedLabel(opt.label, opt.value)}\n </option>\n ))}\n </Select>\n )\n case 'date':\n // EC-463: the shared date control — a segment keystroke never commits a\n // partial year, and pasting/filling an ISO date works.\n return (\n <DateInput\n ariaLabel={ariaLabel}\n value={value}\n onChange={(stored) => onChange(stored ?? '')}\n className=\"h-7 w-36 text-xs\"\n testId={testId}\n />\n )\n case 'number':\n return (\n <DraftValueInput\n type=\"number\"\n initial={value === '' ? '' : String(value)}\n ariaLabel={ariaLabel}\n testId={testId}\n onText={(raw) => onChange(scalarFromText(option, raw))}\n />\n )\n default:\n return (\n <DraftValueInput\n initial={String(value)}\n ariaLabel={ariaLabel}\n testId={testId}\n onText={(raw) => onChange(scalarFromText(option, raw))}\n />\n )\n }\n}\n\n/**\n * Text input with a local draft so typing is never re-normalized mid-keystroke\n * (e.g. a trailing comma in a filter `in` list). Remount (key it) when the\n * field/operator changes so the draft resets to the new initial.\n */\nexport function DraftValueInput({\n initial,\n type = 'text',\n placeholder,\n ariaLabel = translate('cms.field.value'),\n testId,\n onText,\n}: {\n initial: string\n type?: 'text' | 'number'\n placeholder?: string\n ariaLabel?: string\n testId: string\n onText: (raw: string) => void\n}) {\n const [draft, setDraft] = useState(initial)\n return (\n <Input\n aria-label={ariaLabel}\n type={type}\n value={draft}\n placeholder={placeholder ?? translate('cms.field.valuePlaceholder')}\n onChange={(event) => {\n setDraft(event.target.value)\n onText(event.target.value)\n }}\n className=\"h-7 w-36 text-xs\"\n data-testid={testId}\n />\n )\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EC-461 — the smart-slug auto-derive DECISION, extracted pure.
|
|
3
|
+
*
|
|
4
|
+
* The old rule ("derive whenever the slug is empty and a source value exists")
|
|
5
|
+
* fired on the very first render of an untouched document: opening a slug-less
|
|
6
|
+
* document (e.g. the home page, whose route is `/` and whose fixture carries no
|
|
7
|
+
* slug) mutated the draft immediately, so `dirty` flipped true and the 1s
|
|
8
|
+
* autosave WROTE the document — "open" became "edit". In the playground that
|
|
9
|
+
* mount-write was the destructive half of the EC-461 loss family: a remounted
|
|
10
|
+
* CMS session (re-seeded from its baseline) that merely OPENED such a page
|
|
11
|
+
* autosaved the stale baseline draft over the adapter's newer record, wiping
|
|
12
|
+
* same-session composition + field edits. In connected mode the same write
|
|
13
|
+
* spuriously stamped `updatedAt`/`hasUnpublishedChanges` on every open.
|
|
14
|
+
*
|
|
15
|
+
* The new rule keeps the auto-slug UX (type a title, watch the slug follow)
|
|
16
|
+
* but never mutates an untouched draft: derivation only fires once the derived
|
|
17
|
+
* value has MOVED away from what it was at mount — i.e. the editor actually
|
|
18
|
+
* changed a source field this session. The `latchOpen` flag keeps derivation
|
|
19
|
+
* live after the first divergence, so editing a title away and back still
|
|
20
|
+
* lands the (re-)derived slug rather than silently skipping the final state.
|
|
21
|
+
*/
|
|
22
|
+
export interface SlugAutoDeriveInput {
|
|
23
|
+
/** The value derived from the source fields this render (already slugified). */
|
|
24
|
+
derived: string;
|
|
25
|
+
/** The slug currently stored in the draft (empty string when absent). */
|
|
26
|
+
current: string;
|
|
27
|
+
/** The derived value captured on the control's first render. */
|
|
28
|
+
initialDerived: string;
|
|
29
|
+
/** True once a previous render observed `derived !== initialDerived`. */
|
|
30
|
+
latchOpen: boolean;
|
|
31
|
+
/** The editor manually set the slug — auto-derive never overwrites it. */
|
|
32
|
+
manuallyEdited: boolean;
|
|
33
|
+
readOnly: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface SlugAutoDeriveDecision {
|
|
36
|
+
/** Write `derived` into the draft now. */
|
|
37
|
+
write: boolean;
|
|
38
|
+
/** Persist `latchOpen: true` for subsequent renders. */
|
|
39
|
+
openLatch: boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare function slugAutoDeriveDecision(input: SlugAutoDeriveInput): SlugAutoDeriveDecision;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function slugAutoDeriveDecision(input) {
|
|
2
|
+
const { derived, current, initialDerived, latchOpen, manuallyEdited, readOnly } = input;
|
|
3
|
+
const diverged = latchOpen || derived !== initialDerived;
|
|
4
|
+
if (readOnly || manuallyEdited)
|
|
5
|
+
return { write: false, openLatch: diverged };
|
|
6
|
+
if (!derived || derived === current)
|
|
7
|
+
return { write: false, openLatch: diverged };
|
|
8
|
+
// The mount state of an untouched document: derived exists, slug differs —
|
|
9
|
+
// but nothing changed this session. Opening a document is not an edit.
|
|
10
|
+
if (!diverged)
|
|
11
|
+
return { write: false, openLatch: false };
|
|
12
|
+
return { write: true, openLatch: true };
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=slug-auto-derive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slug-auto-derive.js","sourceRoot":"","sources":["../../../src/components/cms/slug-auto-derive.ts"],"names":[],"mappings":"AA0CA,MAAM,UAAU,sBAAsB,CAAC,KAA0B;IAC/D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IACvF,MAAM,QAAQ,GAAG,SAAS,IAAI,OAAO,KAAK,cAAc,CAAA;IACxD,IAAI,QAAQ,IAAI,cAAc;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;IAC5E,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,OAAO;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;IACjF,2EAA2E;IAC3E,uEAAuE;IACvE,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;IACxD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;AACzC,CAAC","sourcesContent":["/**\n * EC-461 — the smart-slug auto-derive DECISION, extracted pure.\n *\n * The old rule (\"derive whenever the slug is empty and a source value exists\")\n * fired on the very first render of an untouched document: opening a slug-less\n * document (e.g. the home page, whose route is `/` and whose fixture carries no\n * slug) mutated the draft immediately, so `dirty` flipped true and the 1s\n * autosave WROTE the document — \"open\" became \"edit\". In the playground that\n * mount-write was the destructive half of the EC-461 loss family: a remounted\n * CMS session (re-seeded from its baseline) that merely OPENED such a page\n * autosaved the stale baseline draft over the adapter's newer record, wiping\n * same-session composition + field edits. In connected mode the same write\n * spuriously stamped `updatedAt`/`hasUnpublishedChanges` on every open.\n *\n * The new rule keeps the auto-slug UX (type a title, watch the slug follow)\n * but never mutates an untouched draft: derivation only fires once the derived\n * value has MOVED away from what it was at mount — i.e. the editor actually\n * changed a source field this session. The `latchOpen` flag keeps derivation\n * live after the first divergence, so editing a title away and back still\n * lands the (re-)derived slug rather than silently skipping the final state.\n */\nexport interface SlugAutoDeriveInput {\n /** The value derived from the source fields this render (already slugified). */\n derived: string\n /** The slug currently stored in the draft (empty string when absent). */\n current: string\n /** The derived value captured on the control's first render. */\n initialDerived: string\n /** True once a previous render observed `derived !== initialDerived`. */\n latchOpen: boolean\n /** The editor manually set the slug — auto-derive never overwrites it. */\n manuallyEdited: boolean\n readOnly: boolean\n}\n\nexport interface SlugAutoDeriveDecision {\n /** Write `derived` into the draft now. */\n write: boolean\n /** Persist `latchOpen: true` for subsequent renders. */\n openLatch: boolean\n}\n\nexport function slugAutoDeriveDecision(input: SlugAutoDeriveInput): SlugAutoDeriveDecision {\n const { derived, current, initialDerived, latchOpen, manuallyEdited, readOnly } = input\n const diverged = latchOpen || derived !== initialDerived\n if (readOnly || manuallyEdited) return { write: false, openLatch: diverged }\n if (!derived || derived === current) return { write: false, openLatch: diverged }\n // The mount state of an untouched document: derived exists, slug differs —\n // but nothing changed this session. Opening a document is not an edit.\n if (!diverged) return { write: false, openLatch: false }\n return { write: true, openLatch: true }\n}\n"]}
|
|
@@ -40,7 +40,9 @@ export function TransferToDocumentDialog({ projectId, manifest, node, open, onOp
|
|
|
40
40
|
// the shared, tested resolver (also used by the CMS/Assets tabs) keeps
|
|
41
41
|
// this dialog's targets in sync with what those tabs show.
|
|
42
42
|
const collections = resolveCmsInitialCollections(cms, kit);
|
|
43
|
-
return (_jsx(CmsProvider, { projectId: projectId, initialCollections: collections, initialDocuments: cms?.documents ?? kit?.documents, initialPublishedKeys: cms?.publishedKeys,
|
|
43
|
+
return (_jsx(CmsProvider, { projectId: projectId, initialCollections: collections, initialDocuments: cms?.documents ?? kit?.documents, initialPublishedKeys: cms?.publishedKeys,
|
|
44
|
+
// EC-461: hydrated seed (both modes now) supersedes staged docs.
|
|
45
|
+
seedReflectsWrites: cms !== null, children: _jsx(TransferPicker, { projectId: projectId, node: node, onClose: () => onOpenChange(false) }) }));
|
|
44
46
|
} })) : null] }) }));
|
|
45
47
|
}
|
|
46
48
|
/** A pending transfer's in-flight target key: `<collectionId>/new` or `<collectionId>/<docId>`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transfer-dialog.js","sourceRoot":"","sources":["../../../src/components/components/transfer-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAKnE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACxF,OAAO,EACL,MAAM,EACN,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,EACL,GAAG,EACH,KAAK,EACL,IAAI,GACL,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAA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AAC,EAAE,EAAE,CAAC,EACpE,OAAO,EAAE,UAAU,KAAK,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,EACtD,QAAQ,EAAE,UAAU,KAAK,IAAI,EAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,IANxC,GAAG,CAAC,EAAE,CAOX,CACH,CAAC,IACI,KAvCE,MAAM,CAAC,UAAU,CAAC,EAAE,CAwCxB,CACT,CAAA;gBACH,CAAC,CAAC,GACI,EACR,KAAC,YAAY,cACX,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAC,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,KAAK,IAAI,YAClF,SAAS,CAAC,eAAe,CAAC,GACpB,GACI,IACd,CACJ,CAAA;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,iBAAiB,CAAC,EACzB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,GAQR;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,iBACA,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,EAAE,CACX,gIAAgI,EAChI,QAAQ,IAAI,+BAA+B,CAC5C,aAED,eAAM,SAAS,EAAC,mFAAmF,YAChG,OAAO,CAAC,CAAC,CAAC,KAAC,OAAO,IAAC,SAAS,EAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,IAAI,GACxD,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,QAAQ,EAAC,SAAS,EAAC,yBAAyB,YAChE,KAAK,GACD,IACA,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useMemo, useState } from 'react'\nimport { FilePlus2, FileText, Loader2, Search } from 'lucide-react'\nimport type { ReactNode } from 'react'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport type { CmsDocument } from '@elytracms/core/cms-core'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { STUDIO_PROJECT_ROUTE, studioPath, useNavigate } from '@elytracms/studio/router'\nimport {\n Button,\n Code,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Input,\n Row,\n Stack,\n Text,\n} from '@elytracms/studio/ui'\nimport { cn } from '@elytracms/studio/lib/utils'\nimport { localizedLabel, translate } from '@elytracms/studio/lib/i18n'\nimport { getInstantiatedKit } from '@elytracms/studio/lib/starters/kit-session'\nimport { CmsSessionGate } from '../project-session'\nimport { CmsProvider, useCms } from '../cms/cms-store'\nimport { stageDocument } from '../cms/document-staging'\nimport { resolveCmsInitialCollections } from '../app-views/default-modules'\nimport {\n appendToBlockDocument,\n buildBlockDocument,\n canAppendTo,\n collectionsWithBlocks,\n isComponentAllowed,\n} from './transfer'\nimport type { CollectionBlocksTarget } from './transfer'\n\n/** Existing documents offered per target, beyond which the rest are hidden (filter to find them). */\nconst MAX_EXISTING_TARGETS = 8\n\n/**\n * EC-320 (+ 0.0.44 follow-up) — \"Use in document…\". Transfers the current\n * component combination (the live preview {@link ComponentNode}, edited props\n * and all) into a document's blocks field, then opens that document. Each\n * eligible collection+field target offers a NEW draft AND its existing\n * documents to append into.\n *\n * The dialog mounts a CMS session (so it reuses the store's create/save machinery,\n * collision-free ids and persistence) only while open. On confirm it builds the\n * draft or the append (pure {@link buildBlockDocument} / {@link appendToBlockDocument}),\n * saves it and AWAITS the persisted write landing (belt and braces alongside the\n * STAGE for the next CMS mount, see `document-staging` — both matter: staging\n * covers the very next mount regardless of mode, the await guards any later\n * reload), then navigates to the document — focused on its blocks field so it\n * opens on the canvas.\n */\nexport function TransferToDocumentDialog({\n projectId,\n manifest,\n node,\n open,\n onOpenChange,\n}: {\n projectId: string\n manifest: ComponentManifest\n node: ComponentNode\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-md\">\n <DialogHeader>\n <DialogTitle>\n {translate('components.transfer.title', { name: localizedLabel(manifest.title, manifest.id) })}\n </DialogTitle>\n <DialogDescription>{translate('components.transfer.description')}</DialogDescription>\n </DialogHeader>\n {open ? (\n <CmsSessionGate>\n {(cms) => {\n const kit = getInstantiatedKit(projectId)\n // Bug fix: this used to reimplement `resolveCmsInitialCollections`'s\n // fallback chain inline with a final `[]` instead of `undefined` — `[]`\n // is \"present\" to `CmsProvider`'s `initialCollections ??\n // sampleFilterableCollections`, so it suppressed the fixture fallback a\n // fresh Convex-mode project (`cms === null`, no kit) needs. Delegating to\n // the shared, tested resolver (also used by the CMS/Assets tabs) keeps\n // this dialog's targets in sync with what those tabs show.\n const collections = resolveCmsInitialCollections(cms, kit)\n return (\n <CmsProvider\n projectId={projectId}\n initialCollections={collections}\n initialDocuments={cms?.documents ?? kit?.documents}\n initialPublishedKeys={cms?.publishedKeys}\n >\n <TransferPicker projectId={projectId} node={node} onClose={() => onOpenChange(false)} />\n </CmsProvider>\n )\n }}\n </CmsSessionGate>\n ) : null}\n </DialogContent>\n </Dialog>\n )\n}\n\n/** A pending transfer's in-flight target key: `<collectionId>/new` or `<collectionId>/<docId>`. */\nfunction newTargetKey(target: CollectionBlocksTarget): string {\n return `${target.collection.id}/new`\n}\nfunction existingTargetKey(target: CollectionBlocksTarget, doc: CmsDocument): string {\n return `${target.collection.id}/${doc.id}`\n}\n\n/**\n * Exported for the fresh-Convex-project regression test (bug fix,\n * transfer-dialog.test.tsx) — `TransferToDocumentDialog` is otherwise its only\n * caller.\n */\nexport function TransferPicker({\n projectId,\n node,\n onClose,\n}: {\n projectId: string\n node: ComponentNode\n onClose: () => void\n}) {\n const cms = useCms()\n const navigate = useNavigate()\n const [query, setQuery] = useState('')\n // The in-flight target's key while its save is awaited (disables every row\n // + shows a spinner on the clicked one) — `null` when idle.\n const [pendingKey, setPendingKey] = useState<string | null>(null)\n\n // Read the LIVE store schema (`cms.collections`) rather than re-deriving it\n // from the same `resolveCmsInitialCollections` result passed to `CmsProvider`\n // above — `cms.collections` is what the provider actually resolved to\n // (its OWN `initialCollections ?? sampleFilterableCollections` fallback,\n // EC-320), so the targets list can never drift from — or reintroduce the\n // `[]`-suppresses-the-fixture-fallback bug against — what the CMS/Assets\n // tabs show for this same session. Allow-gated (0.0.44 follow-up): a target\n // whose field's `allow` vocabulary rejects this component is never offered,\n // new-document or existing-document alike — the validator would flag it.\n const targets = useMemo(\n () => collectionsWithBlocks(cms.collections).filter((t) => isComponentAllowed(t.field, node.componentId)),\n [cms.collections, node.componentId],\n )\n\n /** Persist (awaited) + stage + navigate — shared by both transfer paths. */\n async function persistAndOpen(doc: CmsDocument, target: CollectionBlocksTarget) {\n // Optimistic session apply + queues the persisted upsert (EC-141's normal\n // fire-and-forget autosave path — unchanged for every OTHER caller).\n cms.saveDocument(doc)\n // Cross-mount handoff for the very next `CmsProvider` mount, in EVERY mode\n // (see document-staging.ts) — covers the instant after this write, before\n // any later hydration is guaranteed to observe it.\n stageDocument(projectId, doc)\n // Belt and braces: AWAIT the queued persistence command landing (the same\n // `flushPersistence` publish/unpublish already await) so a reload of the\n // destination editor — not just its very next mount — also finds the\n // document. `saveDocument` itself stays fire-and-forget for every other\n // caller; only this explicit await makes the transfer's save synchronous.\n await cms.flushPersistence()\n onClose()\n void navigate({\n to: STUDIO_PROJECT_ROUTE,\n params: { projectId, _splat: studioPath.cmsDocument(target.collection.id, doc.id) },\n search: { field: `values/${target.field.name}` },\n })\n }\n\n async function transferNew(target: CollectionBlocksTarget) {\n const key = newTargetKey(target)\n setPendingKey(key)\n try {\n const existingIds = new Set(cms.documentsOf(target.collection.id).map((d) => d.id))\n const doc = buildBlockDocument({\n collection: target.collection,\n blocksField: target.field,\n node,\n existingIds,\n seq: { current: 0 },\n })\n await persistAndOpen(doc, target)\n } finally {\n setPendingKey(null)\n }\n }\n\n async function transferInto(target: CollectionBlocksTarget, existing: CmsDocument) {\n const key = existingTargetKey(target, existing)\n setPendingKey(key)\n try {\n const doc = appendToBlockDocument({\n collection: target.collection,\n document: existing,\n blocksField: target.field,\n node,\n locale: cms.activeLocale,\n })\n await persistAndOpen(doc, target)\n } finally {\n setPendingKey(null)\n }\n }\n\n if (targets.length === 0) {\n return (\n <Text size=\"sm\" tone=\"muted\" data-testid=\"transfer-no-targets\">\n {translate('components.transfer.noTargets')}\n </Text>\n )\n }\n\n const trimmedQuery = query.trim().toLowerCase()\n const hasAnyExistingDocs = targets.some((t) => cms.documentsOf(t.collection.id).length > 0)\n\n return (\n <>\n {hasAnyExistingDocs ? (\n <div className=\"relative\">\n <Search className=\"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground\" />\n <Input\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={translate('common.searchPlaceholder')}\n className=\"pl-8\"\n />\n </div>\n ) : null}\n <Stack gap=\"4\" className=\"max-h-[50vh] overflow-y-auto\">\n {targets.map((target) => {\n const existing = cms\n .documentsOf(target.collection.id)\n .filter((doc) => canAppendTo({ collection: target.collection, document: doc, blocksField: target.field, locale: cms.activeLocale }))\n .filter(\n (doc) =>\n trimmedQuery === '' ||\n cms.titleOf({ collection: target.collection.id, id: doc.id }).toLowerCase().includes(trimmedQuery),\n )\n .slice(0, MAX_EXISTING_TARGETS)\n\n return (\n <Stack key={target.collection.id} gap=\"2\">\n <Stack gap=\"px\">\n <Text size=\"sm\" weight=\"medium\" className=\"truncate\">\n {localizedLabel(target.collection.form?.label, target.collection.id)}\n </Text>\n <Row gap=\"1\" align=\"center\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('components.transfer.intoField')}\n </Text>\n <Code tone=\"muted\">{target.field.name}</Code>\n </Row>\n </Stack>\n <Stack gap=\"1\">\n <TransferTargetRow\n testId=\"transfer-target\"\n icon={<FilePlus2 className=\"size-4\" />}\n label={translate('components.transfer.newDocument', {\n collection: localizedLabel(target.collection.form?.labelSingular, target.collection.id),\n })}\n pending={pendingKey === newTargetKey(target)}\n disabled={pendingKey !== null}\n onClick={() => void transferNew(target)}\n />\n {existing.length > 0 ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-1 pt-1\">\n {translate('components.transfer.orExisting')}\n </Text>\n ) : null}\n {existing.map((doc) => (\n <TransferTargetRow\n key={doc.id}\n testId=\"transfer-target-existing\"\n icon={<FileText className=\"size-4\" />}\n label={cms.titleOf({ collection: target.collection.id, id: doc.id })}\n pending={pendingKey === existingTargetKey(target, doc)}\n disabled={pendingKey !== null}\n onClick={() => void transferInto(target, doc)}\n />\n ))}\n </Stack>\n </Stack>\n )\n })}\n </Stack>\n <DialogFooter>\n <Button type=\"button\" variant=\"ghost\" onClick={onClose} disabled={pendingKey !== null}>\n {translate('common.cancel')}\n </Button>\n </DialogFooter>\n </>\n )\n}\n\n/** One selectable transfer target row — a new draft, or an existing document to append into. */\nfunction TransferTargetRow({\n testId,\n icon,\n label,\n pending,\n disabled,\n onClick,\n}: {\n testId: string\n icon: ReactNode\n label: string\n pending: boolean\n disabled: boolean\n onClick: () => void\n}) {\n return (\n <button\n type=\"button\"\n data-testid={testId}\n disabled={disabled}\n onClick={onClick}\n className={cn(\n 'flex items-center gap-3 rounded-md border border-border p-3 text-left transition-colors hover:border-primary/40 hover:bg-muted',\n disabled && 'cursor-not-allowed opacity-60',\n )}\n >\n <span className=\"grid size-8 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground\">\n {pending ? <Loader2 className=\"size-4 animate-spin\" /> : icon}\n </span>\n <Text size=\"sm\" weight=\"medium\" className=\"min-w-0 flex-1 truncate\">\n {label}\n </Text>\n </button>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transfer-dialog.js","sourceRoot":"","sources":["../../../src/components/components/transfer-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAA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CAAC,GACpB,GACI,IACd,CACJ,CAAA;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,iBAAiB,CAAC,EACzB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,GAQR;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,iBACA,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,EAAE,CACX,gIAAgI,EAChI,QAAQ,IAAI,+BAA+B,CAC5C,aAED,eAAM,SAAS,EAAC,mFAAmF,YAChG,OAAO,CAAC,CAAC,CAAC,KAAC,OAAO,IAAC,SAAS,EAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,IAAI,GACxD,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,QAAQ,EAAC,SAAS,EAAC,yBAAyB,YAChE,KAAK,GACD,IACA,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useMemo, useState } from 'react'\nimport { FilePlus2, FileText, Loader2, Search } from 'lucide-react'\nimport type { ReactNode } from 'react'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport type { CmsDocument } from '@elytracms/core/cms-core'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { STUDIO_PROJECT_ROUTE, studioPath, useNavigate } from '@elytracms/studio/router'\nimport {\n Button,\n Code,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Input,\n Row,\n Stack,\n Text,\n} from '@elytracms/studio/ui'\nimport { cn } from '@elytracms/studio/lib/utils'\nimport { localizedLabel, translate } from '@elytracms/studio/lib/i18n'\nimport { getInstantiatedKit } from '@elytracms/studio/lib/starters/kit-session'\nimport { CmsSessionGate } from '../project-session'\nimport { CmsProvider, useCms } from '../cms/cms-store'\nimport { stageDocument } from '../cms/document-staging'\nimport { resolveCmsInitialCollections } from '../app-views/default-modules'\nimport {\n appendToBlockDocument,\n buildBlockDocument,\n canAppendTo,\n collectionsWithBlocks,\n isComponentAllowed,\n} from './transfer'\nimport type { CollectionBlocksTarget } from './transfer'\n\n/** Existing documents offered per target, beyond which the rest are hidden (filter to find them). */\nconst MAX_EXISTING_TARGETS = 8\n\n/**\n * EC-320 (+ 0.0.44 follow-up) — \"Use in document…\". Transfers the current\n * component combination (the live preview {@link ComponentNode}, edited props\n * and all) into a document's blocks field, then opens that document. Each\n * eligible collection+field target offers a NEW draft AND its existing\n * documents to append into.\n *\n * The dialog mounts a CMS session (so it reuses the store's create/save machinery,\n * collision-free ids and persistence) only while open. On confirm it builds the\n * draft or the append (pure {@link buildBlockDocument} / {@link appendToBlockDocument}),\n * saves it and AWAITS the persisted write landing (belt and braces alongside the\n * STAGE for the next CMS mount, see `document-staging` — both matter: staging\n * covers the very next mount regardless of mode, the await guards any later\n * reload), then navigates to the document — focused on its blocks field so it\n * opens on the canvas.\n */\nexport function TransferToDocumentDialog({\n projectId,\n manifest,\n node,\n open,\n onOpenChange,\n}: {\n projectId: string\n manifest: ComponentManifest\n node: ComponentNode\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-md\">\n <DialogHeader>\n <DialogTitle>\n {translate('components.transfer.title', { name: localizedLabel(manifest.title, manifest.id) })}\n </DialogTitle>\n <DialogDescription>{translate('components.transfer.description')}</DialogDescription>\n </DialogHeader>\n {open ? (\n <CmsSessionGate>\n {(cms) => {\n const kit = getInstantiatedKit(projectId)\n // Bug fix: this used to reimplement `resolveCmsInitialCollections`'s\n // fallback chain inline with a final `[]` instead of `undefined` — `[]`\n // is \"present\" to `CmsProvider`'s `initialCollections ??\n // sampleFilterableCollections`, so it suppressed the fixture fallback a\n // fresh Convex-mode project (`cms === null`, no kit) needs. Delegating to\n // the shared, tested resolver (also used by the CMS/Assets tabs) keeps\n // this dialog's targets in sync with what those tabs show.\n const collections = resolveCmsInitialCollections(cms, kit)\n return (\n <CmsProvider\n projectId={projectId}\n initialCollections={collections}\n initialDocuments={cms?.documents ?? kit?.documents}\n initialPublishedKeys={cms?.publishedKeys}\n // EC-461: hydrated seed (both modes now) supersedes staged docs.\n seedReflectsWrites={cms !== null}\n >\n <TransferPicker projectId={projectId} node={node} onClose={() => onOpenChange(false)} />\n </CmsProvider>\n )\n }}\n </CmsSessionGate>\n ) : null}\n </DialogContent>\n </Dialog>\n )\n}\n\n/** A pending transfer's in-flight target key: `<collectionId>/new` or `<collectionId>/<docId>`. */\nfunction newTargetKey(target: CollectionBlocksTarget): string {\n return `${target.collection.id}/new`\n}\nfunction existingTargetKey(target: CollectionBlocksTarget, doc: CmsDocument): string {\n return `${target.collection.id}/${doc.id}`\n}\n\n/**\n * Exported for the fresh-Convex-project regression test (bug fix,\n * transfer-dialog.test.tsx) — `TransferToDocumentDialog` is otherwise its only\n * caller.\n */\nexport function TransferPicker({\n projectId,\n node,\n onClose,\n}: {\n projectId: string\n node: ComponentNode\n onClose: () => void\n}) {\n const cms = useCms()\n const navigate = useNavigate()\n const [query, setQuery] = useState('')\n // The in-flight target's key while its save is awaited (disables every row\n // + shows a spinner on the clicked one) — `null` when idle.\n const [pendingKey, setPendingKey] = useState<string | null>(null)\n\n // Read the LIVE store schema (`cms.collections`) rather than re-deriving it\n // from the same `resolveCmsInitialCollections` result passed to `CmsProvider`\n // above — `cms.collections` is what the provider actually resolved to\n // (its OWN `initialCollections ?? sampleFilterableCollections` fallback,\n // EC-320), so the targets list can never drift from — or reintroduce the\n // `[]`-suppresses-the-fixture-fallback bug against — what the CMS/Assets\n // tabs show for this same session. Allow-gated (0.0.44 follow-up): a target\n // whose field's `allow` vocabulary rejects this component is never offered,\n // new-document or existing-document alike — the validator would flag it.\n const targets = useMemo(\n () => collectionsWithBlocks(cms.collections).filter((t) => isComponentAllowed(t.field, node.componentId)),\n [cms.collections, node.componentId],\n )\n\n /** Persist (awaited) + stage + navigate — shared by both transfer paths. */\n async function persistAndOpen(doc: CmsDocument, target: CollectionBlocksTarget) {\n // Optimistic session apply + queues the persisted upsert (EC-141's normal\n // fire-and-forget autosave path — unchanged for every OTHER caller).\n cms.saveDocument(doc)\n // Cross-mount handoff for the very next `CmsProvider` mount, in EVERY mode\n // (see document-staging.ts) — covers the instant after this write, before\n // any later hydration is guaranteed to observe it.\n stageDocument(projectId, doc)\n // Belt and braces: AWAIT the queued persistence command landing (the same\n // `flushPersistence` publish/unpublish already await) so a reload of the\n // destination editor — not just its very next mount — also finds the\n // document. `saveDocument` itself stays fire-and-forget for every other\n // caller; only this explicit await makes the transfer's save synchronous.\n await cms.flushPersistence()\n onClose()\n void navigate({\n to: STUDIO_PROJECT_ROUTE,\n params: { projectId, _splat: studioPath.cmsDocument(target.collection.id, doc.id) },\n search: { field: `values/${target.field.name}` },\n })\n }\n\n async function transferNew(target: CollectionBlocksTarget) {\n const key = newTargetKey(target)\n setPendingKey(key)\n try {\n const existingIds = new Set(cms.documentsOf(target.collection.id).map((d) => d.id))\n const doc = buildBlockDocument({\n collection: target.collection,\n blocksField: target.field,\n node,\n existingIds,\n seq: { current: 0 },\n })\n await persistAndOpen(doc, target)\n } finally {\n setPendingKey(null)\n }\n }\n\n async function transferInto(target: CollectionBlocksTarget, existing: CmsDocument) {\n const key = existingTargetKey(target, existing)\n setPendingKey(key)\n try {\n const doc = appendToBlockDocument({\n collection: target.collection,\n document: existing,\n blocksField: target.field,\n node,\n locale: cms.activeLocale,\n })\n await persistAndOpen(doc, target)\n } finally {\n setPendingKey(null)\n }\n }\n\n if (targets.length === 0) {\n return (\n <Text size=\"sm\" tone=\"muted\" data-testid=\"transfer-no-targets\">\n {translate('components.transfer.noTargets')}\n </Text>\n )\n }\n\n const trimmedQuery = query.trim().toLowerCase()\n const hasAnyExistingDocs = targets.some((t) => cms.documentsOf(t.collection.id).length > 0)\n\n return (\n <>\n {hasAnyExistingDocs ? (\n <div className=\"relative\">\n <Search className=\"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground\" />\n <Input\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={translate('common.searchPlaceholder')}\n className=\"pl-8\"\n />\n </div>\n ) : null}\n <Stack gap=\"4\" className=\"max-h-[50vh] overflow-y-auto\">\n {targets.map((target) => {\n const existing = cms\n .documentsOf(target.collection.id)\n .filter((doc) => canAppendTo({ collection: target.collection, document: doc, blocksField: target.field, locale: cms.activeLocale }))\n .filter(\n (doc) =>\n trimmedQuery === '' ||\n cms.titleOf({ collection: target.collection.id, id: doc.id }).toLowerCase().includes(trimmedQuery),\n )\n .slice(0, MAX_EXISTING_TARGETS)\n\n return (\n <Stack key={target.collection.id} gap=\"2\">\n <Stack gap=\"px\">\n <Text size=\"sm\" weight=\"medium\" className=\"truncate\">\n {localizedLabel(target.collection.form?.label, target.collection.id)}\n </Text>\n <Row gap=\"1\" align=\"center\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('components.transfer.intoField')}\n </Text>\n <Code tone=\"muted\">{target.field.name}</Code>\n </Row>\n </Stack>\n <Stack gap=\"1\">\n <TransferTargetRow\n testId=\"transfer-target\"\n icon={<FilePlus2 className=\"size-4\" />}\n label={translate('components.transfer.newDocument', {\n collection: localizedLabel(target.collection.form?.labelSingular, target.collection.id),\n })}\n pending={pendingKey === newTargetKey(target)}\n disabled={pendingKey !== null}\n onClick={() => void transferNew(target)}\n />\n {existing.length > 0 ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-1 pt-1\">\n {translate('components.transfer.orExisting')}\n </Text>\n ) : null}\n {existing.map((doc) => (\n <TransferTargetRow\n key={doc.id}\n testId=\"transfer-target-existing\"\n icon={<FileText className=\"size-4\" />}\n label={cms.titleOf({ collection: target.collection.id, id: doc.id })}\n pending={pendingKey === existingTargetKey(target, doc)}\n disabled={pendingKey !== null}\n onClick={() => void transferInto(target, doc)}\n />\n ))}\n </Stack>\n </Stack>\n )\n })}\n </Stack>\n <DialogFooter>\n <Button type=\"button\" variant=\"ghost\" onClick={onClose} disabled={pendingKey !== null}>\n {translate('common.cancel')}\n </Button>\n </DialogFooter>\n </>\n )\n}\n\n/** One selectable transfer target row — a new draft, or an existing document to append into. */\nfunction TransferTargetRow({\n testId,\n icon,\n label,\n pending,\n disabled,\n onClick,\n}: {\n testId: string\n icon: ReactNode\n label: string\n pending: boolean\n disabled: boolean\n onClick: () => void\n}) {\n return (\n <button\n type=\"button\"\n data-testid={testId}\n disabled={disabled}\n onClick={onClick}\n className={cn(\n 'flex items-center gap-3 rounded-md border border-border p-3 text-left transition-colors hover:border-primary/40 hover:bg-muted',\n disabled && 'cursor-not-allowed opacity-60',\n )}\n >\n <span className=\"grid size-8 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground\">\n {pending ? <Loader2 className=\"size-4 animate-spin\" /> : icon}\n </span>\n <Text size=\"sm\" weight=\"medium\" className=\"min-w-0 flex-1 truncate\">\n {label}\n </Text>\n </button>\n )\n}\n"]}
|
|
@@ -31,10 +31,16 @@ import type { ContentSessionState } from '@elytracms/studio/lib/data';
|
|
|
31
31
|
* listing/relation population therefore resolves from in-memory session
|
|
32
32
|
* documents with connected-mode semantics (published-ness = the version
|
|
33
33
|
* pointer; the Draft view resolves live rows) instead of the blanket-empty
|
|
34
|
-
* session the playground used to run with.
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
34
|
+
* session the playground used to run with.
|
|
35
|
+
*
|
|
36
|
+
* EC-461 — `CmsSessionGate`/`loadCms` hydrate the CMS surfaces from the
|
|
37
|
+
* adapter in the playground too now. The old EC-320 "static-baseline rule"
|
|
38
|
+
* (gate value pinned `null`; CMS sessions re-seeded the fixture baseline on
|
|
39
|
+
* every mount) is retired: it made every cross-section navigation silently
|
|
40
|
+
* revert the visible world to the seed, and a subsequent autosave from that
|
|
41
|
+
* re-seeded session destroyed the adapter's newer record — the EC-276/EC-461
|
|
42
|
+
* playground loss family. Only this provider's OWN `session` value keeps the
|
|
43
|
+
* playground `null` fast-path (boot determinism, EC-138 below).
|
|
38
44
|
*
|
|
39
45
|
* EC-308/AD-17 note — this gate deliberately does NOT read through the
|
|
40
46
|
* `useOperationQuery` cache seam. It is boot/session orchestration, not a
|
|
@@ -53,7 +59,9 @@ export interface ProjectSessionStore {
|
|
|
53
59
|
/**
|
|
54
60
|
* Load the CURRENT persisted CMS state (fresh query — the CMS section
|
|
55
61
|
* remounts per visit and must show edits persisted since project open).
|
|
56
|
-
*
|
|
62
|
+
* EC-461: the playground resolves the seeded in-memory adapter's state the
|
|
63
|
+
* same way (`null` only while nothing is persisted — e.g. an un-baselined
|
|
64
|
+
* kit project), so remounted CMS sessions carry same-session edits.
|
|
57
65
|
*/
|
|
58
66
|
loadCms(): Promise<OperationResult<HydratedCms | null>>;
|
|
59
67
|
}
|
|
@@ -78,32 +86,46 @@ declare const useProjectSession: () => ProjectSessionStore;
|
|
|
78
86
|
export declare function contentSessionOf(cms: HydratedCms | null, routes?: readonly RouteRecord[], localeConfig?: LocaleConfig | undefined): ContentSessionState | null;
|
|
79
87
|
/**
|
|
80
88
|
* Load the CURRENT persisted CMS state and point the preview content engine at
|
|
81
|
-
* it — the framework-free core of `loadCms` (both modes run it; EC-361).
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
89
|
+
* it — the framework-free core of `loadCms` (both modes run it; EC-361).
|
|
90
|
+
*
|
|
91
|
+
* EC-461 — the gate value is the REAL hydration result in BOTH modes now. The
|
|
92
|
+
* old EC-320 playground contract (`{ ok: true, value: null }` — CMS surfaces
|
|
93
|
+
* keep their static config/fixture baseline forever) was the root of the
|
|
94
|
+
* playground loss family: every cross-section navigation remounted
|
|
95
|
+
* `CmsProvider` from the static seed, so same-session edits vanished from the
|
|
96
|
+
* CMS surfaces even though the in-memory adapter still held them — and any
|
|
97
|
+
* write issued from that re-seeded session (e.g. an autosave) then clobbered
|
|
98
|
+
* the adapter's newer record with the stale baseline. The seeded in-memory
|
|
99
|
+
* adapter IS a persisted backend behind the operations seam (AD-17), so the
|
|
100
|
+
* playground hydrates from it per CMS mount exactly like connected mode
|
|
101
|
+
* hydrates from Convex; a fresh boot returns the deterministic seed, so
|
|
102
|
+
* fixture reproducibility (EC-138) is preserved in substance. A failure is
|
|
103
|
+
* loud twice over: logged here (for the fire-and-forget refresh callers) and
|
|
104
|
+
* rendered as the gate's retryable error state.
|
|
87
105
|
*/
|
|
88
|
-
export declare function loadCmsIntoSession(operations: OperationsClient, projectId: string
|
|
106
|
+
export declare function loadCmsIntoSession(operations: OperationsClient, projectId: string): Promise<OperationResult<HydratedCms | null>>;
|
|
89
107
|
export declare function ProjectSessionProvider({ projectId, children, }: {
|
|
90
108
|
projectId: string;
|
|
91
109
|
children: ReactNode;
|
|
92
110
|
}): import("react").JSX.Element;
|
|
93
111
|
export { useProjectSession };
|
|
94
112
|
/**
|
|
95
|
-
* Gate one CMS surface mount on a FRESH persisted CMS load
|
|
113
|
+
* Gate one CMS surface mount on a FRESH persisted CMS load — BOTH modes.
|
|
96
114
|
* Render-prop: hands the hydrated content (or `null` → fixture fallback,
|
|
97
|
-
* first-run) to the caller once it resolved.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* `onResolved`/`enabled` is passed here.
|
|
115
|
+
* first-run / un-baselined kit) to the caller once it resolved. Unlike
|
|
116
|
+
* `ProjectSessionProvider`, this gate owns no `configureContentSession` side
|
|
117
|
+
* effect of its own — `loadCms` (from `useProjectSession`) already calls it
|
|
118
|
+
* internally when it resolves — so no `onResolved`/`enabled` is passed here.
|
|
102
119
|
*
|
|
103
|
-
* EC-
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
120
|
+
* EC-461: the playground gates on the SAME async hydration as connected mode
|
|
121
|
+
* (over the seeded in-memory adapter, resolved in microtasks). The old
|
|
122
|
+
* synchronous `null` fast-path (EC-320/EC-361) made every remounted CMS
|
|
123
|
+
* session re-seed the STATIC baseline, which both hid and then destroyed
|
|
124
|
+
* same-session edits — the playground loss family. A fresh playground boot
|
|
125
|
+
* hydrates the deterministic seed, so fixture reproducibility is unchanged in
|
|
126
|
+
* substance; only a microtask-long loading frame replaced the synchronous
|
|
127
|
+
* first render HERE (`ProjectSessionProvider`'s EC-138 playground fast-path is
|
|
128
|
+
* untouched).
|
|
107
129
|
*/
|
|
108
130
|
export declare function CmsSessionGate({ children, }: {
|
|
109
131
|
children: (cms: HydratedCms | null) => ReactNode;
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useCallback, useEffect } from 'react';
|
|
3
3
|
import { getStudioOperations, loadHydratedCms, loadProjectSession } from '@elytracms/studio/lib/operations';
|
|
4
4
|
import { isPlaygroundMode } from '@elytracms/studio/lib/persistence';
|
|
5
|
-
import { configureContentSession } from '@elytracms/studio/lib/data';
|
|
5
|
+
import { configureContentSession, isContentSessionWrite, markContentSessionStale, notePlaygroundWriteForUnloadGuard, registerContentSessionRefresher, } from '@elytracms/studio/lib/data';
|
|
6
6
|
import { resolveDeploymentLocaleConfig, resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace';
|
|
7
7
|
import { createRequiredContext } from '@elytracms/studio/lib/required-context';
|
|
8
8
|
import { HydrationBoundary, useHydrationPhase } from './use-hydration-phase.js';
|
|
@@ -31,23 +31,30 @@ export function contentSessionOf(cms, routes = resolveDeploymentRoutes(), locale
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Load the CURRENT persisted CMS state and point the preview content engine at
|
|
34
|
-
* it — the framework-free core of `loadCms` (both modes run it; EC-361).
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
34
|
+
* it — the framework-free core of `loadCms` (both modes run it; EC-361).
|
|
35
|
+
*
|
|
36
|
+
* EC-461 — the gate value is the REAL hydration result in BOTH modes now. The
|
|
37
|
+
* old EC-320 playground contract (`{ ok: true, value: null }` — CMS surfaces
|
|
38
|
+
* keep their static config/fixture baseline forever) was the root of the
|
|
39
|
+
* playground loss family: every cross-section navigation remounted
|
|
40
|
+
* `CmsProvider` from the static seed, so same-session edits vanished from the
|
|
41
|
+
* CMS surfaces even though the in-memory adapter still held them — and any
|
|
42
|
+
* write issued from that re-seeded session (e.g. an autosave) then clobbered
|
|
43
|
+
* the adapter's newer record with the stale baseline. The seeded in-memory
|
|
44
|
+
* adapter IS a persisted backend behind the operations seam (AD-17), so the
|
|
45
|
+
* playground hydrates from it per CMS mount exactly like connected mode
|
|
46
|
+
* hydrates from Convex; a fresh boot returns the deterministic seed, so
|
|
47
|
+
* fixture reproducibility (EC-138) is preserved in substance. A failure is
|
|
48
|
+
* loud twice over: logged here (for the fire-and-forget refresh callers) and
|
|
49
|
+
* rendered as the gate's retryable error state.
|
|
40
50
|
*/
|
|
41
|
-
export async function loadCmsIntoSession(operations, projectId
|
|
51
|
+
export async function loadCmsIntoSession(operations, projectId) {
|
|
42
52
|
const result = await loadHydratedCms(operations, projectId);
|
|
43
53
|
// Keep the preview engine in sync with the freshest persisted content.
|
|
44
54
|
if (result.ok && result.value !== null)
|
|
45
55
|
configureContentSession(contentSessionOf(result.value));
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
console.error('[elytra] playground content-session load failed', result.error);
|
|
49
|
-
return { ok: true, value: null };
|
|
50
|
-
}
|
|
56
|
+
if (!result.ok)
|
|
57
|
+
console.error('[elytra] content-session load failed', result.error);
|
|
51
58
|
return result;
|
|
52
59
|
}
|
|
53
60
|
export function ProjectSessionProvider({ projectId, children, }) {
|
|
@@ -71,15 +78,45 @@ export function ProjectSessionProvider({ projectId, children, }) {
|
|
|
71
78
|
// Leaving the project resets the preview engine to fixtures; the next
|
|
72
79
|
// project's gate reconfigures it before rendering its own children.
|
|
73
80
|
useEffect(() => () => configureContentSession(null), []);
|
|
74
|
-
// EC-361:
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
// pure core (`loadCmsIntoSession`, above) carries + pins that contract.
|
|
81
|
+
// EC-361/EC-461: both modes run the SAME load — the content-session side
|
|
82
|
+
// effect plus the REAL hydration value for the CMS gates. (EC-320's
|
|
83
|
+
// playground null-mask is retired: it was the loss family's root — see
|
|
84
|
+
// `loadCmsIntoSession`.)
|
|
79
85
|
const loadCms = useCallback(async () => {
|
|
80
86
|
const { operations } = await getStudioOperations();
|
|
81
|
-
return loadCmsIntoSession(operations, projectId
|
|
82
|
-
}, [
|
|
87
|
+
return loadCmsIntoSession(operations, projectId);
|
|
88
|
+
}, [projectId]);
|
|
89
|
+
// EC-460: keep the preview content session in sync with WRITES. Every
|
|
90
|
+
// succeeded content-bearing command (documents/schema/assets) on the shared
|
|
91
|
+
// operations event bus marks the session stale; the registered refresher —
|
|
92
|
+
// this provider's own `loadCms`, i.e. the identical hydration path both
|
|
93
|
+
// modes already run — re-points it (debounced, and only while a preview
|
|
94
|
+
// consumer is mounted; see `content-session-refresh.ts`). Before this, the
|
|
95
|
+
// session refreshed only at boot + CMS-surface mounts, so a canvas opened
|
|
96
|
+
// after authoring/publishing resolved listings and relation picks against a
|
|
97
|
+
// stale snapshot: the EC-276 empty-listing / 1-of-3-relations family.
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const unregister = registerContentSessionRefresher(() => loadCms());
|
|
100
|
+
let unsubscribe;
|
|
101
|
+
let cancelled = false;
|
|
102
|
+
void getStudioOperations().then(({ operations }) => {
|
|
103
|
+
if (cancelled)
|
|
104
|
+
return;
|
|
105
|
+
unsubscribe = operations.events.subscribe((event) => {
|
|
106
|
+
if (isContentSessionWrite(event))
|
|
107
|
+
markContentSessionStale();
|
|
108
|
+
// EC-461: the first authored playground write arms the beforeunload
|
|
109
|
+
// guard for the rest of the page's life (module-level — surviving this
|
|
110
|
+
// provider's unmount, because the in-memory world does too).
|
|
111
|
+
notePlaygroundWriteForUnloadGuard(event);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return () => {
|
|
115
|
+
cancelled = true;
|
|
116
|
+
unregister();
|
|
117
|
+
unsubscribe?.();
|
|
118
|
+
};
|
|
119
|
+
}, [loadCms]);
|
|
83
120
|
// EC-361: playground boot hydration for the content preview engine — the same
|
|
84
121
|
// loader connected mode gates on, fired WITHOUT gating so the synchronous
|
|
85
122
|
// playground first render (EC-138) is preserved. `loadCms` owns the
|
|
@@ -94,28 +131,27 @@ export function ProjectSessionProvider({ projectId, children, }) {
|
|
|
94
131
|
}
|
|
95
132
|
export { useProjectSession };
|
|
96
133
|
/**
|
|
97
|
-
* Gate one CMS surface mount on a FRESH persisted CMS load
|
|
134
|
+
* Gate one CMS surface mount on a FRESH persisted CMS load — BOTH modes.
|
|
98
135
|
* Render-prop: hands the hydrated content (or `null` → fixture fallback,
|
|
99
|
-
* first-run) to the caller once it resolved.
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* `onResolved`/`enabled` is passed here.
|
|
136
|
+
* first-run / un-baselined kit) to the caller once it resolved. Unlike
|
|
137
|
+
* `ProjectSessionProvider`, this gate owns no `configureContentSession` side
|
|
138
|
+
* effect of its own — `loadCms` (from `useProjectSession`) already calls it
|
|
139
|
+
* internally when it resolves — so no `onResolved`/`enabled` is passed here.
|
|
104
140
|
*
|
|
105
|
-
* EC-
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
141
|
+
* EC-461: the playground gates on the SAME async hydration as connected mode
|
|
142
|
+
* (over the seeded in-memory adapter, resolved in microtasks). The old
|
|
143
|
+
* synchronous `null` fast-path (EC-320/EC-361) made every remounted CMS
|
|
144
|
+
* session re-seed the STATIC baseline, which both hid and then destroyed
|
|
145
|
+
* same-session edits — the playground loss family. A fresh playground boot
|
|
146
|
+
* hydrates the deterministic seed, so fixture reproducibility is unchanged in
|
|
147
|
+
* substance; only a microtask-long loading frame replaced the synchronous
|
|
148
|
+
* first render HERE (`ProjectSessionProvider`'s EC-138 playground fast-path is
|
|
149
|
+
* untouched).
|
|
109
150
|
*/
|
|
110
151
|
export function CmsSessionGate({ children, }) {
|
|
111
152
|
const { loadCms } = useProjectSession();
|
|
112
|
-
const playground = isPlaygroundMode();
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
if (playground)
|
|
115
|
-
void loadCms();
|
|
116
|
-
}, [playground, loadCms]);
|
|
117
153
|
const { phase, retry } = useHydrationPhase(loadCms, {
|
|
118
|
-
playground,
|
|
154
|
+
playground: false,
|
|
119
155
|
playgroundValue: null,
|
|
120
156
|
});
|
|
121
157
|
return (_jsx(HydrationBoundary, { phase: phase, retry: retry, children: children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-session.js","sourceRoot":"","sources":["../../src/components/project-session.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAG9C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAO3G,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AA2D5E,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,iBAAiB,EAAE,GACtE,qBAAqB,CAAsB,gBAAgB,CAAC,CAAA;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAuB,EACvB,SAAiC,uBAAuB,EAAE,EAC1D,eAAyC,6BAA6B,EAAE;IAExE,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAA;IACrB,OAAO,EAAE,GA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aG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,GAGT;IACC,MAAM,EAAE,OAAO,EAAE,GAAG,iBAAiB,EAAE,CAAA;IACvC,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAA;IACrC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,UAAU;YAAE,KAAK,OAAO,EAAE,CAAA;IAChC,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;IACzB,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,iBAAiB,CAAqB,OAAO,EAAE;QACtE,UAAU;QACV,eAAe,EAAE,IAAI;KACtB,CAAC,CAAA;IACF,OAAO,CACL,KAAC,iBAAiB,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAC1C,QAAQ,GACS,CACrB,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect } from 'react'\nimport type { ReactNode } from 'react'\nimport type { LocaleConfig, RouteRecord } from '@elytracms/core/cms-core'\nimport { getStudioOperations, loadHydratedCms, loadProjectSession } from '@elytracms/studio/lib/operations'\nimport type {\n HydratedCms,\n HydratedProjectSession,\n OperationResult,\n OperationsClient,\n} from '@elytracms/studio/lib/operations'\nimport { isPlaygroundMode } from '@elytracms/studio/lib/persistence'\nimport { configureContentSession } from '@elytracms/studio/lib/data'\nimport type { ContentSessionState } from '@elytracms/studio/lib/data'\nimport { resolveDeploymentLocaleConfig, resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace'\nimport { createRequiredContext } from '@elytracms/studio/lib/required-context'\nimport { HydrationBoundary, useHydrationPhase } from './use-hydration-phase'\n\n/**\n * Project-session hydration gate (Milestone B sign-off fix, EC-177 gap 1).\n *\n * In Convex mode every project session must BOOT from persistence: the\n * builder from the latest persisted graph revision, the CMS from the saved\n * schema + documents, publishing from the persisted environment states.\n * This provider runs the `@elytracms/core/operations` hydration queries\n * (`lib/operations/session-hydration`) and — like `DeploymentSetupGate` — gates its\n * children on a deterministic loading state, so fixture content never\n * flashes (and is never editable) before the persisted state arrives.\n *\n * Playground mode renders children synchronously with `session: null`\n * (fixtures), byte-identical to the pre-hydration behavior — the EC-138\n * determinism contract.\n *\n * Side effect on hydration: the content preview engine\n * (`lib/data/collection-content`) is pointed at the hydrated documents\n * BEFORE children render, so \"Preview with\" lists and section previews show\n * live entries, not fixture titles.\n *\n * EC-361 — the playground gets the SAME side effect, without the render gate:\n * the seeded in-memory adapter IS a persisted backend behind the operations\n * seam (AD-17), so the content session hydrates from it through the identical\n * `loadHydratedCms` loader connected mode uses — fire-and-forget after the\n * synchronous first render (EC-138 stays intact), refreshed per CMS surface\n * mount exactly like connected's `CmsSessionGate` → `loadCms` rhythm. Canvas\n * listing/relation population therefore resolves from in-memory session\n * documents with connected-mode semantics (published-ness = the version\n * pointer; the Draft view resolves live rows) instead of the blanket-empty\n * session the playground used to run with. The React `session`/`loadCms`\n * VALUES stay `null` in playground — the CMS surfaces keep their fixture\n * baseline (EC-320's static-baseline rule); only the preview content engine\n * reads persisted state.\n *\n * EC-308/AD-17 note — this gate deliberately does NOT read through the\n * `useOperationQuery` cache seam. It is boot/session orchestration, not a\n * cacheable server read: (1) the synchronous playground first-render is the\n * EC-138 determinism contract (a pull-query is async even when disabled);\n * (2) `configureContentSession` must run synchronously BEFORE children mount,\n * which a post-render query effect cannot guarantee; (3) `CmsSessionGate` is\n * intentionally fresh-per-visit (it remounts to show edits persisted since\n * project open) — the opposite of a cached read. It still reads through the\n * operations client (no transport bypass), and uses a user-driven retry epoch,\n * not freshness machinery — so it is outside the patchwork AD-17 retires.\n */\n\nexport interface ProjectSessionStore {\n /** Hydrated persisted state (Convex mode); `null` in playground (fixtures). */\n session: HydratedProjectSession | null\n /**\n * Load the CURRENT persisted CMS state (fresh query — the CMS section\n * remounts per visit and must show edits persisted since project open).\n * Playground resolves `null` immediately (fixtures).\n */\n loadCms(): Promise<OperationResult<HydratedCms | null>>\n}\n\nconst { Context: ProjectSessionContext, useRequired: useProjectSession } =\n createRequiredContext<ProjectSessionStore>('ProjectSession')\n\n/**\n * Compose the preview content-session state from a hydrated CMS load plus the\n * config-owned deployment seams — the ONE place hydrated content meets config:\n *\n * - `routes` (EC-291): the config-sourced routes, so the canvas `resolveLink`\n * derives a rich-text link's URL exactly as delivery does.\n * - `localeConfig` (EC-385): the active config project's declared locales\n * (AD-11 — locales are structure, structure is code), so canvas content\n * clients evaluate locale-shaped values (EC-018 fallback, localized\n * filter/sort) over the PROJECT's locale set, never the sample `en/de`\n * fixture. Without a config project (env-only wiring) the key stays absent\n * and the preview engine keeps its sample-config default, mirroring the CMS\n * surface ladder (`resolveCmsInitialLocaleConfig`).\n *\n * The parameters exist purely as a unit-test seam (house pattern, same as\n * `resolveCmsInitialCollections`); app code always uses the defaults.\n */\nexport function contentSessionOf(\n cms: HydratedCms | null,\n routes: readonly RouteRecord[] = resolveDeploymentRoutes(),\n localeConfig: LocaleConfig | undefined = resolveDeploymentLocaleConfig(),\n): ContentSessionState | null {\n if (!cms) return null\n return { ...cms, routes, ...(localeConfig ? { localeConfig } : {}) }\n}\n\n/**\n * Load the CURRENT persisted CMS state and point the preview content engine at\n * it — the framework-free core of `loadCms` (both modes run it; EC-361). The\n * playground return contract (EC-320) is pinned here: the GATE value is always\n * `{ ok: true, value: null }` in playground — CMS surfaces keep their\n * config/fixture baseline — while the content session above still hydrates\n * from the in-memory adapter (a load failure is loud, never a silent empty\n * preview).\n */\nexport async function loadCmsIntoSession(\n operations: OperationsClient,\n projectId: string,\n playground: boolean,\n): Promise<OperationResult<HydratedCms | null>> {\n const result = await loadHydratedCms(operations, projectId)\n // Keep the preview engine in sync with the freshest persisted content.\n if (result.ok && result.value !== null) configureContentSession(contentSessionOf(result.value))\n if (playground) {\n if (!result.ok) console.error('[elytra] playground content-session load failed', result.error)\n return { ok: true, value: null }\n }\n return result\n}\n\nexport function ProjectSessionProvider({\n projectId,\n children,\n}: {\n projectId: string\n children: ReactNode\n}) {\n const playground = isPlaygroundMode()\n\n const loader = useCallback(\n () => getStudioOperations().then(({ operations }) => loadProjectSession(operations, projectId)),\n [projectId],\n )\n // Point the preview content engine at the hydrated documents BEFORE any\n // child renders (panels read it module-level, synchronously), composed with\n // the config-owned routes (EC-291) + locale config (EC-385) via\n // `contentSessionOf`. `enabled: true` below runs this in the playground\n // fast-path too (with `session: null`) — the one divergence from\n // `CmsSessionGate`, which owns no such side effect.\n const onResolved = useCallback((session: HydratedProjectSession | null) => {\n configureContentSession(contentSessionOf(session?.cms ?? null))\n }, [])\n const { phase, retry } = useHydrationPhase<HydratedProjectSession | null>(loader, {\n playground,\n playgroundValue: null,\n enabled: true,\n onResolved,\n })\n\n // Leaving the project resets the preview engine to fixtures; the next\n // project's gate reconfigures it before rendering its own children.\n useEffect(() => () => configureContentSession(null), [])\n\n // EC-361: the playground runs the SAME load (over the seeded in-memory\n // adapter) for the content-session side effect, but the GATE value stays\n // `null` — CMS surfaces keep their config/fixture baseline (EC-320's\n // static-baseline rule), matching the pre-EC-361 playground contract. The\n // pure core (`loadCmsIntoSession`, above) carries + pins that contract.\n const loadCms = useCallback(async (): Promise<OperationResult<HydratedCms | null>> => {\n const { operations } = await getStudioOperations()\n return loadCmsIntoSession(operations, projectId, playground)\n }, [playground, projectId])\n\n // EC-361: playground boot hydration for the content preview engine — the same\n // loader connected mode gates on, fired WITHOUT gating so the synchronous\n // playground first render (EC-138) is preserved. `loadCms` owns the\n // `configureContentSession` side effect; the resolved value is discarded here.\n // Runs after `useHydrationPhase`'s fast-path effect (registered above) has\n // reset the session, so the hydrated state always lands last.\n useEffect(() => {\n if (playground) void loadCms()\n }, [playground, loadCms])\n\n return (\n <HydrationBoundary phase={phase} retry={retry}>\n {(session) => (\n <ProjectSessionContext.Provider value={{ session, loadCms }}>\n {children}\n </ProjectSessionContext.Provider>\n )}\n </HydrationBoundary>\n )\n}\n\nexport { useProjectSession }\n\n/**\n * Gate one CMS surface mount on a FRESH persisted CMS load (Convex mode).\n * Render-prop: hands the hydrated content (or `null` → fixture fallback,\n * first-run) to the caller once it resolved. Playground renders synchronously\n * with `null`. Unlike `ProjectSessionProvider`, this gate owns no\n * `configureContentSession` side effect of its own — `loadCms` (from\n * `useProjectSession`) already calls it internally when it resolves — so no\n * `onResolved`/`enabled` is passed here.\n *\n * EC-361: in playground the gate stays synchronous (fixture baseline, EC-138),\n * but `loadCms` is still fired per mount for its content-session side effect —\n * the preview engine refreshes from the in-memory adapter on the same\n * per-CMS-mount rhythm connected mode gets from the gated load.\n */\nexport function CmsSessionGate({\n children,\n}: {\n children: (cms: HydratedCms | null) => ReactNode\n}) {\n const { loadCms } = useProjectSession()\n const playground = isPlaygroundMode()\n useEffect(() => {\n if (playground) void loadCms()\n }, [playground, loadCms])\n const { phase, retry } = useHydrationPhase<HydratedCms | null>(loadCms, {\n playground,\n playgroundValue: null,\n })\n return (\n <HydrationBoundary phase={phase} retry={retry}>\n {children}\n </HydrationBoundary>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"project-session.js","sourceRoot":"","sources":["../../src/components/project-session.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAG9C,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAO3G,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACpE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,iCAAiC,EACjC,+BAA+B,GAChC,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAmE5E,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,iBAAi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,CACL,KAAC,iBAAiB,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAC1C,QAAQ,GACS,CACrB,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect } from 'react'\nimport type { ReactNode } from 'react'\nimport type { LocaleConfig, RouteRecord } from '@elytracms/core/cms-core'\nimport { getStudioOperations, loadHydratedCms, loadProjectSession } from '@elytracms/studio/lib/operations'\nimport type {\n HydratedCms,\n HydratedProjectSession,\n OperationResult,\n OperationsClient,\n} from '@elytracms/studio/lib/operations'\nimport { isPlaygroundMode } from '@elytracms/studio/lib/persistence'\nimport {\n configureContentSession,\n isContentSessionWrite,\n markContentSessionStale,\n notePlaygroundWriteForUnloadGuard,\n registerContentSessionRefresher,\n} from '@elytracms/studio/lib/data'\nimport type { ContentSessionState } from '@elytracms/studio/lib/data'\nimport { resolveDeploymentLocaleConfig, resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace'\nimport { createRequiredContext } from '@elytracms/studio/lib/required-context'\nimport { HydrationBoundary, useHydrationPhase } from './use-hydration-phase'\n\n/**\n * Project-session hydration gate (Milestone B sign-off fix, EC-177 gap 1).\n *\n * In Convex mode every project session must BOOT from persistence: the\n * builder from the latest persisted graph revision, the CMS from the saved\n * schema + documents, publishing from the persisted environment states.\n * This provider runs the `@elytracms/core/operations` hydration queries\n * (`lib/operations/session-hydration`) and — like `DeploymentSetupGate` — gates its\n * children on a deterministic loading state, so fixture content never\n * flashes (and is never editable) before the persisted state arrives.\n *\n * Playground mode renders children synchronously with `session: null`\n * (fixtures), byte-identical to the pre-hydration behavior — the EC-138\n * determinism contract.\n *\n * Side effect on hydration: the content preview engine\n * (`lib/data/collection-content`) is pointed at the hydrated documents\n * BEFORE children render, so \"Preview with\" lists and section previews show\n * live entries, not fixture titles.\n *\n * EC-361 — the playground gets the SAME side effect, without the render gate:\n * the seeded in-memory adapter IS a persisted backend behind the operations\n * seam (AD-17), so the content session hydrates from it through the identical\n * `loadHydratedCms` loader connected mode uses — fire-and-forget after the\n * synchronous first render (EC-138 stays intact), refreshed per CMS surface\n * mount exactly like connected's `CmsSessionGate` → `loadCms` rhythm. Canvas\n * listing/relation population therefore resolves from in-memory session\n * documents with connected-mode semantics (published-ness = the version\n * pointer; the Draft view resolves live rows) instead of the blanket-empty\n * session the playground used to run with.\n *\n * EC-461 — `CmsSessionGate`/`loadCms` hydrate the CMS surfaces from the\n * adapter in the playground too now. The old EC-320 \"static-baseline rule\"\n * (gate value pinned `null`; CMS sessions re-seeded the fixture baseline on\n * every mount) is retired: it made every cross-section navigation silently\n * revert the visible world to the seed, and a subsequent autosave from that\n * re-seeded session destroyed the adapter's newer record — the EC-276/EC-461\n * playground loss family. Only this provider's OWN `session` value keeps the\n * playground `null` fast-path (boot determinism, EC-138 below).\n *\n * EC-308/AD-17 note — this gate deliberately does NOT read through the\n * `useOperationQuery` cache seam. It is boot/session orchestration, not a\n * cacheable server read: (1) the synchronous playground first-render is the\n * EC-138 determinism contract (a pull-query is async even when disabled);\n * (2) `configureContentSession` must run synchronously BEFORE children mount,\n * which a post-render query effect cannot guarantee; (3) `CmsSessionGate` is\n * intentionally fresh-per-visit (it remounts to show edits persisted since\n * project open) — the opposite of a cached read. It still reads through the\n * operations client (no transport bypass), and uses a user-driven retry epoch,\n * not freshness machinery — so it is outside the patchwork AD-17 retires.\n */\n\nexport interface ProjectSessionStore {\n /** Hydrated persisted state (Convex mode); `null` in playground (fixtures). */\n session: HydratedProjectSession | null\n /**\n * Load the CURRENT persisted CMS state (fresh query — the CMS section\n * remounts per visit and must show edits persisted since project open).\n * EC-461: the playground resolves the seeded in-memory adapter's state the\n * same way (`null` only while nothing is persisted — e.g. an un-baselined\n * kit project), so remounted CMS sessions carry same-session edits.\n */\n loadCms(): Promise<OperationResult<HydratedCms | null>>\n}\n\nconst { Context: ProjectSessionContext, useRequired: useProjectSession } =\n createRequiredContext<ProjectSessionStore>('ProjectSession')\n\n/**\n * Compose the preview content-session state from a hydrated CMS load plus the\n * config-owned deployment seams — the ONE place hydrated content meets config:\n *\n * - `routes` (EC-291): the config-sourced routes, so the canvas `resolveLink`\n * derives a rich-text link's URL exactly as delivery does.\n * - `localeConfig` (EC-385): the active config project's declared locales\n * (AD-11 — locales are structure, structure is code), so canvas content\n * clients evaluate locale-shaped values (EC-018 fallback, localized\n * filter/sort) over the PROJECT's locale set, never the sample `en/de`\n * fixture. Without a config project (env-only wiring) the key stays absent\n * and the preview engine keeps its sample-config default, mirroring the CMS\n * surface ladder (`resolveCmsInitialLocaleConfig`).\n *\n * The parameters exist purely as a unit-test seam (house pattern, same as\n * `resolveCmsInitialCollections`); app code always uses the defaults.\n */\nexport function contentSessionOf(\n cms: HydratedCms | null,\n routes: readonly RouteRecord[] = resolveDeploymentRoutes(),\n localeConfig: LocaleConfig | undefined = resolveDeploymentLocaleConfig(),\n): ContentSessionState | null {\n if (!cms) return null\n return { ...cms, routes, ...(localeConfig ? { localeConfig } : {}) }\n}\n\n/**\n * Load the CURRENT persisted CMS state and point the preview content engine at\n * it — the framework-free core of `loadCms` (both modes run it; EC-361).\n *\n * EC-461 — the gate value is the REAL hydration result in BOTH modes now. The\n * old EC-320 playground contract (`{ ok: true, value: null }` — CMS surfaces\n * keep their static config/fixture baseline forever) was the root of the\n * playground loss family: every cross-section navigation remounted\n * `CmsProvider` from the static seed, so same-session edits vanished from the\n * CMS surfaces even though the in-memory adapter still held them — and any\n * write issued from that re-seeded session (e.g. an autosave) then clobbered\n * the adapter's newer record with the stale baseline. The seeded in-memory\n * adapter IS a persisted backend behind the operations seam (AD-17), so the\n * playground hydrates from it per CMS mount exactly like connected mode\n * hydrates from Convex; a fresh boot returns the deterministic seed, so\n * fixture reproducibility (EC-138) is preserved in substance. A failure is\n * loud twice over: logged here (for the fire-and-forget refresh callers) and\n * rendered as the gate's retryable error state.\n */\nexport async function loadCmsIntoSession(\n operations: OperationsClient,\n projectId: string,\n): Promise<OperationResult<HydratedCms | null>> {\n const result = await loadHydratedCms(operations, projectId)\n // Keep the preview engine in sync with the freshest persisted content.\n if (result.ok && result.value !== null) configureContentSession(contentSessionOf(result.value))\n if (!result.ok) console.error('[elytra] content-session load failed', result.error)\n return result\n}\n\nexport function ProjectSessionProvider({\n projectId,\n children,\n}: {\n projectId: string\n children: ReactNode\n}) {\n const playground = isPlaygroundMode()\n\n const loader = useCallback(\n () => getStudioOperations().then(({ operations }) => loadProjectSession(operations, projectId)),\n [projectId],\n )\n // Point the preview content engine at the hydrated documents BEFORE any\n // child renders (panels read it module-level, synchronously), composed with\n // the config-owned routes (EC-291) + locale config (EC-385) via\n // `contentSessionOf`. `enabled: true` below runs this in the playground\n // fast-path too (with `session: null`) — the one divergence from\n // `CmsSessionGate`, which owns no such side effect.\n const onResolved = useCallback((session: HydratedProjectSession | null) => {\n configureContentSession(contentSessionOf(session?.cms ?? null))\n }, [])\n const { phase, retry } = useHydrationPhase<HydratedProjectSession | null>(loader, {\n playground,\n playgroundValue: null,\n enabled: true,\n onResolved,\n })\n\n // Leaving the project resets the preview engine to fixtures; the next\n // project's gate reconfigures it before rendering its own children.\n useEffect(() => () => configureContentSession(null), [])\n\n // EC-361/EC-461: both modes run the SAME load — the content-session side\n // effect plus the REAL hydration value for the CMS gates. (EC-320's\n // playground null-mask is retired: it was the loss family's root — see\n // `loadCmsIntoSession`.)\n const loadCms = useCallback(async (): Promise<OperationResult<HydratedCms | null>> => {\n const { operations } = await getStudioOperations()\n return loadCmsIntoSession(operations, projectId)\n }, [projectId])\n\n // EC-460: keep the preview content session in sync with WRITES. Every\n // succeeded content-bearing command (documents/schema/assets) on the shared\n // operations event bus marks the session stale; the registered refresher —\n // this provider's own `loadCms`, i.e. the identical hydration path both\n // modes already run — re-points it (debounced, and only while a preview\n // consumer is mounted; see `content-session-refresh.ts`). Before this, the\n // session refreshed only at boot + CMS-surface mounts, so a canvas opened\n // after authoring/publishing resolved listings and relation picks against a\n // stale snapshot: the EC-276 empty-listing / 1-of-3-relations family.\n useEffect(() => {\n const unregister = registerContentSessionRefresher(() => loadCms())\n let unsubscribe: (() => void) | undefined\n let cancelled = false\n void getStudioOperations().then(({ operations }) => {\n if (cancelled) return\n unsubscribe = operations.events.subscribe((event) => {\n if (isContentSessionWrite(event)) markContentSessionStale()\n // EC-461: the first authored playground write arms the beforeunload\n // guard for the rest of the page's life (module-level — surviving this\n // provider's unmount, because the in-memory world does too).\n notePlaygroundWriteForUnloadGuard(event)\n })\n })\n return () => {\n cancelled = true\n unregister()\n unsubscribe?.()\n }\n }, [loadCms])\n\n // EC-361: playground boot hydration for the content preview engine — the same\n // loader connected mode gates on, fired WITHOUT gating so the synchronous\n // playground first render (EC-138) is preserved. `loadCms` owns the\n // `configureContentSession` side effect; the resolved value is discarded here.\n // Runs after `useHydrationPhase`'s fast-path effect (registered above) has\n // reset the session, so the hydrated state always lands last.\n useEffect(() => {\n if (playground) void loadCms()\n }, [playground, loadCms])\n\n return (\n <HydrationBoundary phase={phase} retry={retry}>\n {(session) => (\n <ProjectSessionContext.Provider value={{ session, loadCms }}>\n {children}\n </ProjectSessionContext.Provider>\n )}\n </HydrationBoundary>\n )\n}\n\nexport { useProjectSession }\n\n/**\n * Gate one CMS surface mount on a FRESH persisted CMS load — BOTH modes.\n * Render-prop: hands the hydrated content (or `null` → fixture fallback,\n * first-run / un-baselined kit) to the caller once it resolved. Unlike\n * `ProjectSessionProvider`, this gate owns no `configureContentSession` side\n * effect of its own — `loadCms` (from `useProjectSession`) already calls it\n * internally when it resolves — so no `onResolved`/`enabled` is passed here.\n *\n * EC-461: the playground gates on the SAME async hydration as connected mode\n * (over the seeded in-memory adapter, resolved in microtasks). The old\n * synchronous `null` fast-path (EC-320/EC-361) made every remounted CMS\n * session re-seed the STATIC baseline, which both hid and then destroyed\n * same-session edits — the playground loss family. A fresh playground boot\n * hydrates the deterministic seed, so fixture reproducibility is unchanged in\n * substance; only a microtask-long loading frame replaced the synchronous\n * first render HERE (`ProjectSessionProvider`'s EC-138 playground fast-path is\n * untouched).\n */\nexport function CmsSessionGate({\n children,\n}: {\n children: (cms: HydratedCms | null) => ReactNode\n}) {\n const { loadCms } = useProjectSession()\n const { phase, retry } = useHydrationPhase<HydratedCms | null>(loadCms, {\n playground: false,\n playgroundValue: null,\n })\n return (\n <HydrationBoundary phase={phase} retry={retry}>\n {children}\n </HydrationBoundary>\n )\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset URL scheme classification (EC-459). `InMemoryBlobStorage` (playground's
|
|
3
|
+
* default blob backend, `@elytracms/core/persistence`) mints an opaque
|
|
4
|
+
* `memory://blobs/<key>` locator for stored bytes — correct for Node tests and
|
|
5
|
+
* inspection, but not a resource a browser can ever fetch. Every studio surface
|
|
6
|
+
* that puts an asset's `url` in an `<img src>` must gate on "is this actually
|
|
7
|
+
* displayable", not "is this specifically `http(s)`" — the fix wiring
|
|
8
|
+
* (`browser-blob-storage.ts`) replaces `memory://` with a `blob:` object URL,
|
|
9
|
+
* which the OLD `url.startsWith('http')` gates here would have kept rejecting.
|
|
10
|
+
*
|
|
11
|
+
* Pure and dependency-free so it is trivially Node-testable; every surface that
|
|
12
|
+
* decides "show the `<img>` or the placeholder" imports this one predicate so
|
|
13
|
+
* the decision can never drift between call sites again.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* True when `url` is a scheme a browser can fetch/render (`http(s):`, `blob:`,
|
|
17
|
+
* `data:`) — false for `undefined`, empty, and opaque backend-internal locators
|
|
18
|
+
* like `memory://blobs/…` that must never reach an `<img>`/`<a href>`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isDisplayableAssetUrl(url: string | undefined | null): url is string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset URL scheme classification (EC-459). `InMemoryBlobStorage` (playground's
|
|
3
|
+
* default blob backend, `@elytracms/core/persistence`) mints an opaque
|
|
4
|
+
* `memory://blobs/<key>` locator for stored bytes — correct for Node tests and
|
|
5
|
+
* inspection, but not a resource a browser can ever fetch. Every studio surface
|
|
6
|
+
* that puts an asset's `url` in an `<img src>` must gate on "is this actually
|
|
7
|
+
* displayable", not "is this specifically `http(s)`" — the fix wiring
|
|
8
|
+
* (`browser-blob-storage.ts`) replaces `memory://` with a `blob:` object URL,
|
|
9
|
+
* which the OLD `url.startsWith('http')` gates here would have kept rejecting.
|
|
10
|
+
*
|
|
11
|
+
* Pure and dependency-free so it is trivially Node-testable; every surface that
|
|
12
|
+
* decides "show the `<img>` or the placeholder" imports this one predicate so
|
|
13
|
+
* the decision can never drift between call sites again.
|
|
14
|
+
*/
|
|
15
|
+
/** Schemes a browser can actually load pixels from in an `<img src>`. */
|
|
16
|
+
const DISPLAYABLE_URL_PATTERN = /^(https?:|blob:|data:)/i;
|
|
17
|
+
/**
|
|
18
|
+
* True when `url` is a scheme a browser can fetch/render (`http(s):`, `blob:`,
|
|
19
|
+
* `data:`) — false for `undefined`, empty, and opaque backend-internal locators
|
|
20
|
+
* like `memory://blobs/…` that must never reach an `<img>`/`<a href>`.
|
|
21
|
+
*/
|
|
22
|
+
export function isDisplayableAssetUrl(url) {
|
|
23
|
+
return typeof url === 'string' && DISPLAYABLE_URL_PATTERN.test(url);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=asset-url.js.map
|