@elytracms/studio 0.0.24 → 0.0.26
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/convex/cms.ts +49 -7
- package/convex/delivery.ts +14 -16
- package/convex/references.ts +38 -2
- package/convex/schema.ts +6 -1
- package/dist/components/assets/asset-library.js +5 -2
- package/dist/components/assets/asset-library.js.map +1 -1
- package/dist/components/assets/assets-store.js +45 -30
- package/dist/components/assets/assets-store.js.map +1 -1
- package/dist/components/auth-context.d.ts +4 -2
- package/dist/components/auth-context.js +19 -19
- package/dist/components/auth-context.js.map +1 -1
- package/dist/components/cms/cms-store.js +5 -4
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.js +10 -3
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/detail-editor.js +36 -9
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/field-control.d.ts +2 -1
- package/dist/components/cms/field-control.js +166 -74
- package/dist/components/cms/field-control.js.map +1 -1
- package/dist/components/cms/versions-pane.js +28 -16
- package/dist/components/cms/versions-pane.js.map +1 -1
- package/dist/components/project-session.d.ts +11 -0
- package/dist/components/project-session.js.map +1 -1
- package/dist/components/routes/routes-shell.js +22 -22
- package/dist/components/routes/routes-shell.js.map +1 -1
- package/dist/components/studio-context.js +5 -1
- package/dist/components/studio-context.js.map +1 -1
- package/dist/lib/assets/delete-asset.js +7 -3
- package/dist/lib/assets/delete-asset.js.map +1 -1
- package/dist/lib/cms/published-documents.d.ts +6 -6
- package/dist/lib/cms/published-documents.js +21 -58
- package/dist/lib/cms/published-documents.js.map +1 -1
- package/dist/lib/cms-views/view-model.d.ts +7 -3
- package/dist/lib/cms-views/view-model.js +11 -5
- package/dist/lib/cms-views/view-model.js.map +1 -1
- package/dist/lib/data/collection-content.js +7 -5
- package/dist/lib/data/collection-content.js.map +1 -1
- package/dist/lib/data/data-store.js +34 -24
- package/dist/lib/data/data-store.js.map +1 -1
- package/dist/lib/persistence/convex-adapter.js +22 -0
- package/dist/lib/persistence/convex-adapter.js.map +1 -1
- package/dist/lib/persistence/index.js +6 -2
- package/dist/lib/persistence/index.js.map +1 -1
- package/dist/lib/query/index.d.ts +6 -0
- package/dist/lib/query/index.js +6 -0
- package/dist/lib/query/index.js.map +1 -0
- package/dist/lib/query/operations-query.d.ts +85 -0
- package/dist/lib/query/operations-query.js +124 -0
- package/dist/lib/query/operations-query.js.map +1 -0
- package/dist/lib/references/reference-model.js +7 -1
- package/dist/lib/references/reference-model.js.map +1 -1
- package/dist/lib/references/references-store.d.ts +5 -10
- package/dist/lib/references/references-store.js +61 -77
- package/dist/lib/references/references-store.js.map +1 -1
- package/dist/ui/collapsible-section.d.ts +20 -0
- package/dist/ui/collapsible-section.js +18 -0
- package/dist/ui/collapsible-section.js.map +1 -0
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versions-pane.js","sourceRoot":"","sources":["../../../src/components/cms/versions-pane.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAE/E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,MAAM,EAAE,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,QAAQ,EACd,SAAS,EAAC,kDAAkD,aAE5D,MAAC,IAAI,IAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,kBAAI,KAAK,CAAC,OAAO,IAAQ,EAChE,MAAM,CAAC,CAAC,CAAC,KAAC,KAAK,IAAC,OAAO,EAAC,SAAS,0BAAkB,CAAC,CAAC,CAAC,IAAI,EAC3D,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,QAAC,SAAS,EAAC,UAAU,YACpD,sBAAsB,CAAC,KAAK,CAAC,SAAS,CAAC,GACnC,EACP,KAAC,MAAM,KAAG,EACT,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACf,MAAC,MAAM,IACL,IAAI,EAAC,IAAI,EACT,OAAO,EAAC,SAAS,EACjB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,EAChD,QAAQ,EAAE,IAAI,IAAI,YAAY,EAC9B,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,SAAS,aAE9D,KAAC,SAAS,KAAG,gBACN,CACV,KArBI,KAAK,CAAC,OAAO,CAsBd,CACP,CAAA;gBACH,CAAC,CAAC,CACH,GACK,IACF,CACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useState } from 'react'\nimport { Eye, RotateCcw } from 'lucide-react'\nimport { Badge, Button, Code, Row, Spacer, Stack, Text } from '@elytracms/studio/ui'\nimport { useCms } from './cms-store'\nimport type { DocumentVersionsView } from './cms-store'\nimport { useDocumentEditor } from './document-editor-context'\nimport { formatVersionTimestamp, snapshotMatchesDraft } from './versions-model'\n\n/**\n * EC-224 — the document-level **Versions** inspector pane. Re-homes the EC-180\n * VersionsPanel at the document level (the Sanity model): the continuous draft\n * on top with **Publish**, then the recorded version history (the live pin\n * badged), each older version **restorable** into the draft.\n *\n * Publish routes through the same pointer op as the header control\n * (`cms.publishDocument`); restore loads a recorded snapshot as the new working\n * draft (the operation snapshots the current draft first, so a rollback is\n * itself undoable) and the open editor adopts it via `replaceDraft`. Unpublish\n * deliberately stays in the header — it routes through the EC-173\n * reference-aware confirmation, which this pane does not duplicate.\n */\nexport function VersionsPane() {\n const cms = useCms()\n const { docRef, draft, dirty, hasErrors, viewReadOnly, save, replaceDraft } = useDocumentEditor()\n const [view, setView] = useState<DocumentVersionsView | null>(null)\n const [busy, setBusy] = useState(false)\n const published = cms.isPublished(docRef)\n\n const reload = useCallback(async () => {\n // Flush any queued publish/save so the listed history is authoritative\n // regardless of which surface (header or pane) triggered the change.\n await cms.flushPersistence()\n setView(await cms.loadDocumentVersions(docRef))\n }, [cms, docRef])\n\n useEffect(() => {\n void reload()\n // Re-load when publish-ness flips from anywhere (e.g. the header control).\n }, [reload, published])\n\n const liveSnapshot =\n view?.publishedVersion !== undefined\n ? view.versions.find((v) => v.version === view.publishedVersion)?.snapshot\n : undefined\n // Value-equality (key-order-insensitive) so a just-published, unchanged doc\n // doesn't read as \"unpublished changes\" — see snapshotMatchesDraft.\n const liveMatchesDraft = liveSnapshot !== undefined && snapshotMatchesDraft(liveSnapshot, draft)\n const canPublish = !liveMatchesDraft\n\n const handlePublish = useCallback(async () => {\n setBusy(true)\n try {\n // Publish snapshots the SAVED draft — capture any unsaved edits first so\n // the published version is exactly what the editor shows. Await the\n // publish (it flushes + reconciles the pin, EC-225) before re-reading the\n // version list so the new version shows.\n if (dirty) save()\n await cms.publishDocument(docRef)\n await reload()\n } finally {\n setBusy(false)\n }\n }, [cms, docRef, dirty, save, reload])\n\n const handleRestore = useCallback(\n async (version: number) => {\n setBusy(true)\n try {\n // Capture any unsaved buffer edits FIRST so the operation's pre-restore\n // snapshot records them — otherwise they'd be lost and the rollback\n // wouldn't be undoable (restore snapshots the persisted draft).\n if (dirty) save()\n const restored = await cms.restoreDocumentVersion(docRef, version)\n if (restored) replaceDraft(restored)\n await reload()\n } finally {\n setBusy(false)\n }\n },\n [cms, docRef, dirty, save, replaceDraft, reload],\n )\n\n return (\n <Stack gap=\"3\" className=\"p-3\">\n {canPublish ? (\n <Row gap=\"2\" align=\"center\" className=\"rounded-md border border-primary/40 bg-primary/5 px-2.5 py-2\">\n <Stack gap=\"none\" className=\"min-w-0\">\n <Text size=\"sm\" weight=\"medium\">\n Draft\n </Text>\n <Text size=\"xs\" tone=\"muted\">\n {published ? 'Unpublished changes' : 'Not published yet'}\n </Text>\n </Stack>\n <Spacer />\n <Button\n size=\"sm\"\n onClick={handlePublish}\n disabled={busy || hasErrors || viewReadOnly}\n title={\n viewReadOnly\n ? 'Switch to Draft to publish'\n : hasErrors\n ? 'Fix the document’s validation issues to publish'\n : undefined\n }\n >\n <Eye /> Publish\n </Button>\n </Row>\n ) : (\n <Text size=\"xs\" tone=\"muted\" className=\"px-0.5\">\n The live version is up to date — nothing to publish.\n </Text>\n )}\n\n <Stack gap=\"1\">\n {view === null ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-0.5\">\n Loading…\n </Text>\n ) : view.versions.length === 0 ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-0.5\">\n No published versions yet.\n </Text>\n ) : (\n view.versions.map((entry) => {\n const isLive = entry.version === view.publishedVersion\n return (\n <Row\n key={entry.version}\n gap=\"2\"\n align=\"center\"\n className=\"rounded-md border border-border/60 px-2.5 py-1.5\"\n >\n <Code tone={isLive ? 'primary' : 'muted'}>v{entry.version}</Code>\n {isLive ? <Badge variant=\"success\">Published</Badge> : null}\n <Text size=\"xs\" tone=\"subtle\" mono className=\"truncate\">\n {formatVersionTimestamp(entry.createdAt)}\n </Text>\n <Spacer />\n {isLive ? null : (\n <Button\n size=\"sm\"\n variant=\"outline\"\n onClick={() => void handleRestore(entry.version)}\n disabled={busy || viewReadOnly}\n title={viewReadOnly ? 'Switch to Draft to restore' : undefined}\n >\n <RotateCcw /> Restore\n </Button>\n )}\n </Row>\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AAC,OAAO,kBAAI,KAAK,CAAC,OAAO,IAAQ,EAChE,MAAM,CAAC,CAAC,CAAC,KAAC,KAAK,IAAC,OAAO,EAAC,SAAS,0BAAkB,CAAC,CAAC,CAAC,IAAI,EAC3D,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,QAAC,SAAS,EAAC,UAAU,YACpD,sBAAsB,CAAC,KAAK,CAAC,SAAS,CAAC,GACnC,EACP,KAAC,MAAM,KAAG,EACT,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACf,MAAC,MAAM,IACL,IAAI,EAAC,IAAI,EACT,OAAO,EAAC,SAAS,EACjB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,EAChD,QAAQ,EAAE,IAAI,IAAI,YAAY,EAC9B,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,SAAS,aAE9D,KAAC,SAAS,KAAG,gBACN,CACV,KArBI,KAAK,CAAC,OAAO,CAsBd,CACP,CAAA;gBACH,CAAC,CAAC,CACH,GACK,IACF,CACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport { Eye, RotateCcw } from 'lucide-react'\nimport { Badge, Button, Code, Row, Spacer, Stack, Text } from '@elytracms/studio/ui'\nimport { useOperationCache, useOperationQuery } from '@elytracms/studio/lib/query'\nimport { useCms } from './cms-store'\nimport type { DocumentVersionsView } from './cms-store'\nimport { useDocumentEditor } from './document-editor-context'\nimport { formatVersionTimestamp, snapshotMatchesDraft } from './versions-model'\n\n/** Recorded-version freshness: any document command (publish/restore/upsert)\n * may change the history, so re-read on the whole `documents` domain. */\nconst VERSION_RELOAD_OPS = ['documents'] as const\n\n/**\n * EC-224 — the document-level **Versions** inspector pane. Re-homes the EC-180\n * VersionsPanel at the document level (the Sanity model): the continuous draft\n * on top with **Publish**, then the recorded version history (the live pin\n * badged), each older version **restorable** into the draft.\n *\n * Publish routes through the same pointer op as the header control\n * (`cms.publishDocument`); restore loads a recorded snapshot as the new working\n * draft (the operation snapshots the current draft first, so a rollback is\n * itself undoable) and the open editor adopts it via `replaceDraft`. Unpublish\n * deliberately stays in the header — it routes through the EC-173\n * reference-aware confirmation, which this pane does not duplicate.\n */\nexport function VersionsPane() {\n const cms = useCms()\n const { docRef, draft, dirty, hasErrors, viewReadOnly, save, replaceDraft } = useDocumentEditor()\n const [busy, setBusy] = useState(false)\n const published = cms.isPublished(docRef)\n const cache = useOperationCache()\n\n // The recorded version history, read through the one operations-backed query\n // cache (EC-308/AD-17). The flush-before-read ordering (so the listed history\n // is authoritative regardless of which surface triggered the change) lives IN\n // the loader, so every fetch — initial, invalidated, or a manual refetch —\n // is correctly sequenced. `invalidateOn: documents` refreshes it whenever a\n // publish/restore/save lands from anywhere (replacing the old `published`-flip\n // reload). The editor draft/dirty/busy state stays local — it is not server\n // state (principle 12).\n const versionKey = useMemo(\n () => ['documentVersions', cms.projectId ?? '∅', docRef.collection, docRef.id],\n [cms.projectId, docRef.collection, docRef.id],\n )\n const versionsQuery = useOperationQuery<DocumentVersionsView>({\n queryKey: versionKey,\n loader: async () => {\n await cms.flushPersistence()\n return cms.loadDocumentVersions(docRef)\n },\n invalidateOn: VERSION_RELOAD_OPS,\n })\n const view = versionsQuery.data ?? null\n\n const liveSnapshot =\n view?.publishedVersion !== undefined\n ? view.versions.find((v) => v.version === view.publishedVersion)?.snapshot\n : undefined\n // Value-equality (key-order-insensitive) so a just-published, unchanged doc\n // doesn't read as \"unpublished changes\" — see snapshotMatchesDraft.\n const liveMatchesDraft = liveSnapshot !== undefined && snapshotMatchesDraft(liveSnapshot, draft)\n const canPublish = !liveMatchesDraft\n\n const handlePublish = useCallback(async () => {\n setBusy(true)\n try {\n // Publish snapshots the SAVED draft — capture any unsaved edits first so\n // the published version is exactly what the editor shows. Await the\n // publish (it flushes + reconciles the pin, EC-225) before re-reading the\n // version list so the new version shows.\n if (dirty) save()\n await cms.publishDocument(docRef)\n await cache.invalidate(versionKey)\n } finally {\n setBusy(false)\n }\n }, [cms, docRef, dirty, save, cache, versionKey])\n\n const handleRestore = useCallback(\n async (version: number) => {\n setBusy(true)\n try {\n // Capture any unsaved buffer edits FIRST so the operation's pre-restore\n // snapshot records them — otherwise they'd be lost and the rollback\n // wouldn't be undoable (restore snapshots the persisted draft).\n if (dirty) save()\n const restored = await cms.restoreDocumentVersion(docRef, version)\n if (restored) replaceDraft(restored)\n await cache.invalidate(versionKey)\n } finally {\n setBusy(false)\n }\n },\n [cms, docRef, dirty, save, replaceDraft, cache, versionKey],\n )\n\n return (\n <Stack gap=\"3\" className=\"p-3\">\n {canPublish ? (\n <Row gap=\"2\" align=\"center\" className=\"rounded-md border border-primary/40 bg-primary/5 px-2.5 py-2\">\n <Stack gap=\"none\" className=\"min-w-0\">\n <Text size=\"sm\" weight=\"medium\">\n Draft\n </Text>\n <Text size=\"xs\" tone=\"muted\">\n {published ? 'Unpublished changes' : 'Not published yet'}\n </Text>\n </Stack>\n <Spacer />\n <Button\n size=\"sm\"\n onClick={handlePublish}\n disabled={busy || hasErrors || viewReadOnly}\n title={\n viewReadOnly\n ? 'Switch to Draft to publish'\n : hasErrors\n ? 'Fix the document’s validation issues to publish'\n : undefined\n }\n >\n <Eye /> Publish\n </Button>\n </Row>\n ) : (\n <Text size=\"xs\" tone=\"muted\" className=\"px-0.5\">\n The live version is up to date — nothing to publish.\n </Text>\n )}\n\n <Stack gap=\"1\">\n {view === null ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-0.5\">\n Loading…\n </Text>\n ) : view.versions.length === 0 ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-0.5\">\n No published versions yet.\n </Text>\n ) : (\n view.versions.map((entry) => {\n const isLive = entry.version === view.publishedVersion\n return (\n <Row\n key={entry.version}\n gap=\"2\"\n align=\"center\"\n className=\"rounded-md border border-border/60 px-2.5 py-1.5\"\n >\n <Code tone={isLive ? 'primary' : 'muted'}>v{entry.version}</Code>\n {isLive ? <Badge variant=\"success\">Published</Badge> : null}\n <Text size=\"xs\" tone=\"subtle\" mono className=\"truncate\">\n {formatVersionTimestamp(entry.createdAt)}\n </Text>\n <Spacer />\n {isLive ? null : (\n <Button\n size=\"sm\"\n variant=\"outline\"\n onClick={() => void handleRestore(entry.version)}\n disabled={busy || viewReadOnly}\n title={viewReadOnly ? 'Switch to Draft to restore' : undefined}\n >\n <RotateCcw /> Restore\n </Button>\n )}\n </Row>\n )\n })\n )}\n </Stack>\n </Stack>\n )\n}\n"]}
|
|
@@ -19,6 +19,17 @@ import type { HydratedCms, HydratedProjectSession, OperationResult } from '@elyt
|
|
|
19
19
|
* (`lib/data/collection-content`) is pointed at the hydrated documents
|
|
20
20
|
* BEFORE children render, so "Preview with" lists and section previews show
|
|
21
21
|
* live entries, not fixture titles.
|
|
22
|
+
*
|
|
23
|
+
* EC-308/AD-17 note — this gate deliberately does NOT read through the
|
|
24
|
+
* `useOperationQuery` cache seam. It is boot/session orchestration, not a
|
|
25
|
+
* cacheable server read: (1) the synchronous playground first-render is the
|
|
26
|
+
* EC-138 determinism contract (a pull-query is async even when disabled);
|
|
27
|
+
* (2) `configureContentSession` must run synchronously BEFORE children mount,
|
|
28
|
+
* which a post-render query effect cannot guarantee; (3) `CmsSessionGate` is
|
|
29
|
+
* intentionally fresh-per-visit (it remounts to show edits persisted since
|
|
30
|
+
* project open) — the opposite of a cached read. It still reads through the
|
|
31
|
+
* operations client (no transport bypass), and uses a user-driven retry epoch,
|
|
32
|
+
* not freshness machinery — so it is outside the patchwork AD-17 retires.
|
|
22
33
|
*/
|
|
23
34
|
export interface ProjectSessionStore {
|
|
24
35
|
/** Hydrated persisted state (Convex mode); `null` in playground (fixtures). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-session.js","sourceRoot":"","sources":["../../src/components/project-session.tsx"],"names":[],"mappings":";AAAA,OAAO,EA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CAAC,GAAG,CAAC,GAAI,CAAA;AACnC,CAAC;AAED,0FAA0F;AAC1F,SAAS,gBAAgB;IACvB,OAAO,CACL,cAAK,SAAS,EAAC,oDAAoD,iBAAa,mBAAmB,YACjG,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,sCAErB,GACH,CACP,CAAA;AACH,CAAC;AAED,mFAAmF;AACnF,SAAS,qBAAqB,CAAC,EAC7B,KAAK,EACL,OAAO,GAIR;IACC,OAAO,CACL,cAAK,SAAS,EAAC,oDAAoD,YACjE,MAAC,KAAK,IAAC,GAAG,EAAC,GAAG,EAAC,SAAS,EAAC,iBAAiB,aACxC,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,UAAU,mEAE1B,EACP,KAAC,oBAAoB,IAAC,KAAK,EAAE,KAAK,GAAI,EACtC,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,oJAGrB,EACP,KAAC,MAAM,IAAC,OAAO,EAAC,SAAS,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,YAAY,sBAEnE,IACH,GACJ,CACP,CAAA;AACH,CAAC","sourcesContent":["import { createContext, useCallback, useContext, useEffect, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport { Button, Stack, Text } from '@elytracms/studio/ui'\nimport { getStudioOperations, loadHydratedCms, loadProjectSession } from '@elytracms/studio/lib/operations'\nimport type {\n HydratedCms,\n HydratedProjectSession,\n OperationError,\n OperationResult,\n} from '@elytracms/studio/lib/operations'\nimport { isPlaygroundMode } from '@elytracms/studio/lib/persistence'\nimport { configureContentSession } from '@elytracms/studio/lib/data'\nimport { resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace'\nimport { OperationErrorBanner } from './operation-error'\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 `BackendGate` — 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\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 ProjectSessionContext = createContext<ProjectSessionStore | null>(null)\n\ntype Phase =\n | { kind: 'loading' }\n | { kind: 'ready'; session: HydratedProjectSession | null }\n | { kind: 'error'; error: OperationError }\n\nexport function ProjectSessionProvider({\n projectId,\n children,\n}: {\n projectId: string\n children: ReactNode\n}) {\n const playground = isPlaygroundMode()\n // Playground renders children on the FIRST render (no effect round-trip):\n // fixture boots stay synchronous and deterministic.\n const [phase, setPhase] = useState<Phase>(() =>\n playground ? { kind: 'ready', session: null } : { kind: 'loading' },\n )\n const [attempt, setAttempt] = useState(0)\n\n useEffect(() => {\n if (playground) {\n configureContentSession(null)\n return\n }\n let cancelled = false\n setPhase({ kind: 'loading' })\n void getStudioOperations()\n .then(({ operations }) => loadProjectSession(operations, projectId))\n .then((result) => {\n if (cancelled) return\n if (!result.ok) {\n setPhase({ kind: 'error', error: result.error })\n return\n }\n // Point the preview content engine at the hydrated documents before\n // any child renders (panels read it module-level, synchronously). EC-291:\n // include the config-sourced routes so the canvas `resolveLink` derives a\n // rich-text link's URL exactly as delivery does.\n configureContentSession(\n result.value.cms\n ? { ...result.value.cms, routes: resolveDeploymentRoutes() }\n : null,\n )\n setPhase({ kind: 'ready', session: result.value })\n })\n return () => {\n cancelled = true\n }\n }, [projectId, playground, attempt])\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 const loadCms = useCallback(async (): Promise<OperationResult<HydratedCms | null>> => {\n if (playground) return { ok: true, value: null }\n const { operations } = await getStudioOperations()\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)\n configureContentSession({ ...result.value, routes: resolveDeploymentRoutes() })\n return result\n }, [playground, projectId])\n\n if (phase.kind === 'loading') return <SessionHydrating />\n if (phase.kind === 'error') {\n return (\n <SessionHydrationError error={phase.error} onRetry={() => setAttempt((n) => n + 1)} />\n )\n }\n return (\n <ProjectSessionContext.Provider value={{ session: phase.session, loadCms }}>\n {children}\n </ProjectSessionContext.Provider>\n )\n}\n\nexport function useProjectSession(): ProjectSessionStore {\n const store = useContext(ProjectSessionContext)\n if (!store) {\n throw new Error('useProjectSession must be used within a <ProjectSessionProvider>.')\n }\n return store\n}\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`.\n */\nexport function CmsSessionGate({\n children,\n}: {\n children: (cms: HydratedCms | null) => ReactNode\n}) {\n const { loadCms } = useProjectSession()\n const playground = isPlaygroundMode()\n const [phase, setPhase] = useState<\n | { kind: 'loading' }\n | { kind: 'ready'; cms: HydratedCms | null }\n | { kind: 'error'; error: OperationError }\n >(() => (playground ? { kind: 'ready', cms: null } : { kind: 'loading' }))\n const [attempt, setAttempt] = useState(0)\n\n useEffect(() => {\n if (playground) return\n let cancelled = false\n setPhase({ kind: 'loading' })\n void loadCms().then((result) => {\n if (cancelled) return\n setPhase(result.ok ? { kind: 'ready', cms: result.value } : { kind: 'error', error: result.error })\n })\n return () => {\n cancelled = true\n }\n }, [playground, loadCms, attempt])\n\n if (phase.kind === 'loading') return <SessionHydrating />\n if (phase.kind === 'error') {\n return (\n <SessionHydrationError error={phase.error} onRetry={() => setAttempt((n) => n + 1)} />\n )\n }\n return <>{children(phase.cms)}</>\n}\n\n/** Deterministic loading frame while persisted state is fetched (mirrors BackendGate). */\nfunction SessionHydrating() {\n return (\n <div className=\"grid h-full min-h-64 flex-1 place-items-center p-8\" data-testid=\"session-hydrating\">\n <Text size=\"sm\" tone=\"muted\">\n Loading project…\n </Text>\n </div>\n )\n}\n\n/** A failed hydration is a visible, retryable state — never a fixture fallback. */\nfunction SessionHydrationError({\n error,\n onRetry,\n}: {\n error: OperationError\n onRetry: () => void\n}) {\n return (\n <div className=\"grid h-full min-h-64 flex-1 place-items-center p-8\">\n <Stack gap=\"3\" className=\"w-full max-w-xl\">\n <Text size=\"sm\" weight=\"semibold\">\n Couldn’t load this project’s saved state\n </Text>\n <OperationErrorBanner error={error} />\n <Text size=\"xs\" tone=\"muted\">\n The studio never falls back to sample content against a live backend — your data is\n safe; retry once the backend is reachable.\n </Text>\n <Button variant=\"outline\" size=\"sm\" onClick={onRetry} className=\"self-start\">\n Retry\n </Button>\n </Stack>\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"project-session.js","sourceRoot":"","sources":["../../src/components/project-session.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEnF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAO3G,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AACpE,OAAO,EAAE,uBAAuB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L,cAAK,SAAS,EAAC,oDAAoD,YACjE,MAAC,KAAK,IAAC,GAAG,EAAC,GAAG,EAAC,SAAS,EAAC,iBAAiB,aACxC,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,UAAU,mEAE1B,EACP,KAAC,oBAAoB,IAAC,KAAK,EAAE,KAAK,GAAI,EACtC,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,oJAGrB,EACP,KAAC,MAAM,IAAC,OAAO,EAAC,SAAS,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,YAAY,sBAEnE,IACH,GACJ,CACP,CAAA;AACH,CAAC","sourcesContent":["import { createContext, useCallback, useContext, useEffect, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport { Button, Stack, Text } from '@elytracms/studio/ui'\nimport { getStudioOperations, loadHydratedCms, loadProjectSession } from '@elytracms/studio/lib/operations'\nimport type {\n HydratedCms,\n HydratedProjectSession,\n OperationError,\n OperationResult,\n} from '@elytracms/studio/lib/operations'\nimport { isPlaygroundMode } from '@elytracms/studio/lib/persistence'\nimport { configureContentSession } from '@elytracms/studio/lib/data'\nimport { resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace'\nimport { OperationErrorBanner } from './operation-error'\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 `BackendGate` — 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-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 ProjectSessionContext = createContext<ProjectSessionStore | null>(null)\n\ntype Phase =\n | { kind: 'loading' }\n | { kind: 'ready'; session: HydratedProjectSession | null }\n | { kind: 'error'; error: OperationError }\n\nexport function ProjectSessionProvider({\n projectId,\n children,\n}: {\n projectId: string\n children: ReactNode\n}) {\n const playground = isPlaygroundMode()\n // Playground renders children on the FIRST render (no effect round-trip):\n // fixture boots stay synchronous and deterministic.\n const [phase, setPhase] = useState<Phase>(() =>\n playground ? { kind: 'ready', session: null } : { kind: 'loading' },\n )\n const [attempt, setAttempt] = useState(0)\n\n useEffect(() => {\n if (playground) {\n configureContentSession(null)\n return\n }\n let cancelled = false\n setPhase({ kind: 'loading' })\n void getStudioOperations()\n .then(({ operations }) => loadProjectSession(operations, projectId))\n .then((result) => {\n if (cancelled) return\n if (!result.ok) {\n setPhase({ kind: 'error', error: result.error })\n return\n }\n // Point the preview content engine at the hydrated documents before\n // any child renders (panels read it module-level, synchronously). EC-291:\n // include the config-sourced routes so the canvas `resolveLink` derives a\n // rich-text link's URL exactly as delivery does.\n configureContentSession(\n result.value.cms\n ? { ...result.value.cms, routes: resolveDeploymentRoutes() }\n : null,\n )\n setPhase({ kind: 'ready', session: result.value })\n })\n return () => {\n cancelled = true\n }\n }, [projectId, playground, attempt])\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 const loadCms = useCallback(async (): Promise<OperationResult<HydratedCms | null>> => {\n if (playground) return { ok: true, value: null }\n const { operations } = await getStudioOperations()\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)\n configureContentSession({ ...result.value, routes: resolveDeploymentRoutes() })\n return result\n }, [playground, projectId])\n\n if (phase.kind === 'loading') return <SessionHydrating />\n if (phase.kind === 'error') {\n return (\n <SessionHydrationError error={phase.error} onRetry={() => setAttempt((n) => n + 1)} />\n )\n }\n return (\n <ProjectSessionContext.Provider value={{ session: phase.session, loadCms }}>\n {children}\n </ProjectSessionContext.Provider>\n )\n}\n\nexport function useProjectSession(): ProjectSessionStore {\n const store = useContext(ProjectSessionContext)\n if (!store) {\n throw new Error('useProjectSession must be used within a <ProjectSessionProvider>.')\n }\n return store\n}\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`.\n */\nexport function CmsSessionGate({\n children,\n}: {\n children: (cms: HydratedCms | null) => ReactNode\n}) {\n const { loadCms } = useProjectSession()\n const playground = isPlaygroundMode()\n const [phase, setPhase] = useState<\n | { kind: 'loading' }\n | { kind: 'ready'; cms: HydratedCms | null }\n | { kind: 'error'; error: OperationError }\n >(() => (playground ? { kind: 'ready', cms: null } : { kind: 'loading' }))\n const [attempt, setAttempt] = useState(0)\n\n useEffect(() => {\n if (playground) return\n let cancelled = false\n setPhase({ kind: 'loading' })\n void loadCms().then((result) => {\n if (cancelled) return\n setPhase(result.ok ? { kind: 'ready', cms: result.value } : { kind: 'error', error: result.error })\n })\n return () => {\n cancelled = true\n }\n }, [playground, loadCms, attempt])\n\n if (phase.kind === 'loading') return <SessionHydrating />\n if (phase.kind === 'error') {\n return (\n <SessionHydrationError error={phase.error} onRetry={() => setAttempt((n) => n + 1)} />\n )\n }\n return <>{children(phase.cms)}</>\n}\n\n/** Deterministic loading frame while persisted state is fetched (mirrors BackendGate). */\nfunction SessionHydrating() {\n return (\n <div className=\"grid h-full min-h-64 flex-1 place-items-center p-8\" data-testid=\"session-hydrating\">\n <Text size=\"sm\" tone=\"muted\">\n Loading project…\n </Text>\n </div>\n )\n}\n\n/** A failed hydration is a visible, retryable state — never a fixture fallback. */\nfunction SessionHydrationError({\n error,\n onRetry,\n}: {\n error: OperationError\n onRetry: () => void\n}) {\n return (\n <div className=\"grid h-full min-h-64 flex-1 place-items-center p-8\">\n <Stack gap=\"3\" className=\"w-full max-w-xl\">\n <Text size=\"sm\" weight=\"semibold\">\n Couldn’t load this project’s saved state\n </Text>\n <OperationErrorBanner error={error} />\n <Text size=\"xs\" tone=\"muted\">\n The studio never falls back to sample content against a live backend — your data is\n safe; retry once the backend is reachable.\n </Text>\n <Button variant=\"outline\" size=\"sm\" onClick={onRetry} className=\"self-start\">\n Retry\n </Button>\n </Stack>\n </div>\n )\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
3
|
import { createRouter } from '@elytracms/core/cms-core';
|
|
4
4
|
import { Badge, Heading, Row, Spacer, Stack, Text } from '@elytracms/studio/ui';
|
|
5
|
-
import {
|
|
5
|
+
import { useOperationQuery } from '@elytracms/studio/lib/query';
|
|
6
6
|
import { conflictsByRoute } from '@elytracms/studio/lib/routing';
|
|
7
7
|
import { resolveDeploymentRedirects, resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace';
|
|
8
8
|
import { OperationErrorBanner } from '../operation-error';
|
|
@@ -10,6 +10,9 @@ import { RouteList } from './route-list';
|
|
|
10
10
|
import { RedirectManager } from './redirect-manager';
|
|
11
11
|
/** The body-is-a-canvas page collection (EC-187): routable page documents. */
|
|
12
12
|
const PAGE_COLLECTION = 'page';
|
|
13
|
+
/** Page-label freshness: re-read the labels when any document command lands. */
|
|
14
|
+
const PAGE_LABEL_RELOAD_OPS = ['documents'];
|
|
15
|
+
const EMPTY_PAGES = [];
|
|
13
16
|
/**
|
|
14
17
|
* Routable pages come from the `page` CMS collection (EC-192) — the documents an
|
|
15
18
|
* editor actually creates — not the builder's single synthetic working page.
|
|
@@ -22,6 +25,12 @@ function pageSummaries(records) {
|
|
|
22
25
|
return { id: document.id, name: typeof name === 'string' && name.length > 0 ? name : document.id };
|
|
23
26
|
});
|
|
24
27
|
}
|
|
28
|
+
async function loadPageLabels(operations, projectId) {
|
|
29
|
+
const result = await operations.documents.list({ projectId, collection: PAGE_COLLECTION });
|
|
30
|
+
if (result.ok)
|
|
31
|
+
return { pages: pageSummaries(result.value), error: null };
|
|
32
|
+
return { pages: [], error: result.error };
|
|
33
|
+
}
|
|
25
34
|
/**
|
|
26
35
|
* The Routes surface (EC-170, made read-only by EC-207 "routes as code"):
|
|
27
36
|
* every route and redirect of the project, with the engine's structured issues
|
|
@@ -38,31 +47,22 @@ export function RoutesShell({ project }) {
|
|
|
38
47
|
// the active `elytra.config.ts` project, never fetched from the backend.
|
|
39
48
|
const routes = useMemo(() => resolveDeploymentRoutes(), []);
|
|
40
49
|
const redirects = useMemo(() => resolveDeploymentRedirects(), []);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
setLoadError(null);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
setLoadError(pageDocs.error);
|
|
55
|
-
}
|
|
56
|
-
}, [projectId]);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
void reloadPages();
|
|
59
|
-
}, [reloadPages]);
|
|
50
|
+
// Page documents feed the route target labels (read-only display), read through
|
|
51
|
+
// the one operations-backed query cache (EC-308/AD-17) and kept fresh as
|
|
52
|
+
// documents change. A failure is non-fatal — see `loadPageLabels`.
|
|
53
|
+
const pagesQuery = useOperationQuery({
|
|
54
|
+
queryKey: ['routePageLabels', projectId],
|
|
55
|
+
loader: (operations) => loadPageLabels(operations, projectId),
|
|
56
|
+
invalidateOn: PAGE_LABEL_RELOAD_OPS,
|
|
57
|
+
});
|
|
58
|
+
const pages = pagesQuery.data?.pages ?? EMPTY_PAGES;
|
|
59
|
+
const loadError = pagesQuery.data?.error ?? null;
|
|
60
60
|
// The engine: one router over the config-resolved records. Its structured
|
|
61
61
|
// issues are the single source of conflict/loop truth for this surface.
|
|
62
62
|
const router = useMemo(() => createRouter(routes, redirects, {
|
|
63
63
|
defaultLocale: project.settings.defaultLocale,
|
|
64
64
|
}), [routes, redirects, project.settings.defaultLocale]);
|
|
65
65
|
const conflicts = useMemo(() => conflictsByRoute(router.issues), [router]);
|
|
66
|
-
return (_jsxs(Stack, { gap: "none", className: "min-h-full", "data-testid": "routes-shell", children: [_jsxs(Row, { gap: "3", className: "shrink-0 border-b border-border px-4 py-3 sm:px-6", children: [_jsxs(Stack, { gap: "1", children: [_jsx(Heading, { level: 2, size: "h3", children: "Routes & redirects" }), _jsxs(Text, { size: "xs", tone: "muted", children: ["Routes & redirects are defined in ", _jsx("code", { children: "elytra.config.ts" }), ". Conflicts and loops are detected by the canonical route engine \u2014 never silently."] })] }), _jsx(Spacer, {}), loadError ? (_jsx(OperationErrorBanner, { error: loadError, onDismiss: () => void
|
|
66
|
+
return (_jsxs(Stack, { gap: "none", className: "min-h-full", "data-testid": "routes-shell", children: [_jsxs(Row, { gap: "3", className: "shrink-0 border-b border-border px-4 py-3 sm:px-6", children: [_jsxs(Stack, { gap: "1", children: [_jsx(Heading, { level: 2, size: "h3", children: "Routes & redirects" }), _jsxs(Text, { size: "xs", tone: "muted", children: ["Routes & redirects are defined in ", _jsx("code", { children: "elytra.config.ts" }), ". Conflicts and loops are detected by the canonical route engine \u2014 never silently."] })] }), _jsx(Spacer, {}), loadError ? (_jsx(OperationErrorBanner, { error: loadError, onDismiss: () => void pagesQuery.refetch() })) : null, router.issues.length > 0 ? (_jsxs(Badge, { variant: "error", "data-testid": "routing-issue-count", children: [router.issues.length, " issue", router.issues.length === 1 ? '' : 's'] })) : (_jsx(Badge, { variant: "success", children: "no issues" }))] }), _jsxs("div", { className: "grid min-h-0 flex-1 grid-cols-1 xl:grid-cols-[minmax(0,5fr)_minmax(0,4fr)]", children: [_jsx("section", { "aria-label": "Routes", className: "min-w-0 border-b border-border xl:border-b-0 xl:border-r", children: _jsx(RouteList, { projectId: projectId, routes: routes, conflicts: conflicts, pages: pages }) }), _jsx("section", { "aria-label": "Redirects", className: "min-w-0", children: _jsx(RedirectManager, { redirects: redirects, followRedirects: router.followRedirects }) })] })] }));
|
|
67
67
|
}
|
|
68
68
|
//# sourceMappingURL=routes-shell.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes-shell.js","sourceRoot":"","sources":["../../../src/components/routes/routes-shell.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"routes-shell.js","sourceRoot":"","sources":["../../../src/components/routes/routes-shell.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAGvD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,gBAAg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nimport { createRouter } from '@elytracms/core/cms-core'\nimport type { CmsDocument } from '@elytracms/core/cms-core'\nimport type { Project } from '@elytracms/core/studio-core'\nimport { Badge, Heading, Row, Spacer, Stack, Text } from '@elytracms/studio/ui'\nimport type { OperationError, OperationsClient } from '@elytracms/studio/lib/operations'\nimport { useOperationQuery } from '@elytracms/studio/lib/query'\nimport { conflictsByRoute } from '@elytracms/studio/lib/routing'\nimport { resolveDeploymentRedirects, resolveDeploymentRoutes } from '@elytracms/studio/lib/workspace'\nimport { OperationErrorBanner } from '../operation-error'\nimport { RouteList } from './route-list'\nimport type { PageSummary } from './route-list'\nimport { RedirectManager } from './redirect-manager'\n\n/** The body-is-a-canvas page collection (EC-187): routable page documents. */\nconst PAGE_COLLECTION = 'page'\n\n/** Page-label freshness: re-read the labels when any document command lands. */\nconst PAGE_LABEL_RELOAD_OPS = ['documents'] as const\nconst EMPTY_PAGES: readonly PageSummary[] = []\n\n/**\n * Routable pages come from the `page` CMS collection (EC-192) — the documents an\n * editor actually creates — not the builder's single synthetic working page.\n * `documents.list` returns persisted records wrapping each document; map each to\n * a `{ id, name }` summary for the route target labels.\n */\nfunction pageSummaries(records: ReadonlyArray<{ document: CmsDocument }>): PageSummary[] {\n return records.map(({ document }) => {\n const name = document.values?.['name']\n return { id: document.id, name: typeof name === 'string' && name.length > 0 ? name : document.id }\n })\n}\n\n/** The page-label load result. A read failure is non-fatal (EC-207): the routes\n * still render; the labels fall back to ids and the structured error surfaces in\n * a dismissible banner. So the failure rides IN the data, not as a thrown query\n * error that would collapse the surface. */\ninterface PageLabelData {\n pages: PageSummary[]\n error: OperationError | null\n}\n\nasync function loadPageLabels(\n operations: OperationsClient,\n projectId: string,\n): Promise<PageLabelData> {\n const result = await operations.documents.list({ projectId, collection: PAGE_COLLECTION })\n if (result.ok) return { pages: pageSummaries(result.value), error: null }\n return { pages: [], error: result.error }\n}\n\n/**\n * The Routes surface (EC-170, made read-only by EC-207 \"routes as code\"):\n * every route and redirect of the project, with the engine's structured issues\n * (route conflicts, redirect loops) rendered inline. Routes and redirects are\n * authored in `elytra.config.ts` and read from the resolved config project\n * (`resolveDeploymentRoutes`/`resolveDeploymentRedirects`) — NEVER from the\n * backend. This surface only views them; conflict/loop detection comes from the\n * canonical `@elytracms/core/cms-core` router, never from parallel UI-side logic. The\n * page list (CMS `page` collection) is read only to label route targets.\n */\nexport function RoutesShell({ project }: { project: Project }) {\n const projectId = project.id\n\n // Routes & redirects are config-sourced (EC-207): resolved synchronously from\n // the active `elytra.config.ts` project, never fetched from the backend.\n const routes = useMemo(() => resolveDeploymentRoutes(), [])\n const redirects = useMemo(() => resolveDeploymentRedirects(), [])\n\n // Page documents feed the route target labels (read-only display), read through\n // the one operations-backed query cache (EC-308/AD-17) and kept fresh as\n // documents change. A failure is non-fatal — see `loadPageLabels`.\n const pagesQuery = useOperationQuery<PageLabelData>({\n queryKey: ['routePageLabels', projectId],\n loader: (operations) => loadPageLabels(operations, projectId),\n invalidateOn: PAGE_LABEL_RELOAD_OPS,\n })\n const pages = pagesQuery.data?.pages ?? EMPTY_PAGES\n const loadError = pagesQuery.data?.error ?? null\n\n // The engine: one router over the config-resolved records. Its structured\n // issues are the single source of conflict/loop truth for this surface.\n const router = useMemo(\n () =>\n createRouter(routes, redirects, {\n defaultLocale: project.settings.defaultLocale,\n }),\n [routes, redirects, project.settings.defaultLocale],\n )\n const conflicts = useMemo(() => conflictsByRoute(router.issues), [router])\n\n return (\n <Stack gap=\"none\" className=\"min-h-full\" data-testid=\"routes-shell\">\n <Row gap=\"3\" className=\"shrink-0 border-b border-border px-4 py-3 sm:px-6\">\n <Stack gap=\"1\">\n <Heading level={2} size=\"h3\">\n Routes & redirects\n </Heading>\n <Text size=\"xs\" tone=\"muted\">\n Routes & redirects are defined in <code>elytra.config.ts</code>. Conflicts and loops\n are detected by the canonical route engine — never silently.\n </Text>\n </Stack>\n <Spacer />\n {loadError ? (\n <OperationErrorBanner error={loadError} onDismiss={() => void pagesQuery.refetch()} />\n ) : null}\n {router.issues.length > 0 ? (\n <Badge variant=\"error\" data-testid=\"routing-issue-count\">\n {router.issues.length} issue{router.issues.length === 1 ? '' : 's'}\n </Badge>\n ) : (\n <Badge variant=\"success\">no issues</Badge>\n )}\n </Row>\n\n <div className=\"grid min-h-0 flex-1 grid-cols-1 xl:grid-cols-[minmax(0,5fr)_minmax(0,4fr)]\">\n <section\n aria-label=\"Routes\"\n className=\"min-w-0 border-b border-border xl:border-b-0 xl:border-r\"\n >\n <RouteList projectId={projectId} routes={routes} conflicts={conflicts} pages={pages} />\n </section>\n <section aria-label=\"Redirects\" className=\"min-w-0\">\n <RedirectManager redirects={redirects} followRedirects={router.followRedirects} />\n </section>\n </div>\n </Stack>\n )\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createContext, useCallback, useContext, useMemo, useState } from 'react';
|
|
3
3
|
import { activateProject, configProject, emptyContext } from '@elytracms/core/studio-core';
|
|
4
4
|
import { getWorkspaceState } from '@elytracms/studio/lib/workspace';
|
|
5
|
+
import { StudioQueryProvider } from '@elytracms/studio/lib/query';
|
|
5
6
|
const StudioContext = createContext(null);
|
|
6
7
|
/** Resolve the config-declared projects into studio `Project`s (slug-keyed). */
|
|
7
8
|
function configProjects() {
|
|
@@ -37,7 +38,10 @@ export function StudioProvider({ children }) {
|
|
|
37
38
|
setContext((prev) => (prev.activeProjectId === id ? prev : activateProject(prev, id)));
|
|
38
39
|
}, []);
|
|
39
40
|
const store = useMemo(() => ({ projects, context, getProject, activate }), [projects, context, getProject, activate]);
|
|
40
|
-
|
|
41
|
+
// EC-308/AD-17: the single client query cache mounts here (package-owned,
|
|
42
|
+
// above every per-project provider, surviving project switches) so every
|
|
43
|
+
// studio server read flows through `useOperationQuery`.
|
|
44
|
+
return (_jsx(StudioContext.Provider, { value: store, children: _jsx(StudioQueryProvider, { children: children }) }));
|
|
41
45
|
}
|
|
42
46
|
export function useStudio() {
|
|
43
47
|
const store = useContext(StudioContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio-context.js","sourceRoot":"","sources":["../../src/components/studio-context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEjF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"studio-context.js","sourceRoot":"","sources":["../../src/components/studio-context.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEjF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAoBjE,MAAM,aAAa,GAAG,aAAa,CAAqB,IAAI,CAAC,CAAA;AAE7D,gFAAgF;AAChF,SAAS,cAAc;IACrB,MAAM,KAAK,GAAG,iBAAiB,EAAE,CAAA;IACjC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAA;IACtC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;QACpC,oEAAoE;QACpE,mEAAmE;QACnE,4EAA4E;QAC5E,8EAA8E;QAC9E,8EAA8E;QAC9E,OAAO;YACL,GAAG,OAAO;YACV,QAAQ,EAAE;gBACR,GAAG,OAAO,CAAC,QAAQ;gBACnB,mBAAmB,EAAE;oBACnB,GAAG,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ED,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IAChF,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { createContext, useCallback, useContext, useMemo, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport { activateProject, configProject, emptyContext } from '@elytracms/core/studio-core'\nimport type { ActiveProjectContext, Project, ProjectId } from '@elytracms/core/studio-core'\nimport { getWorkspaceState } from '@elytracms/studio/lib/workspace'\nimport { StudioQueryProvider } from '@elytracms/studio/lib/query'\n\n/**\n * Project read store (vision AD-8). Project *identity* is owned by\n * `elytra.config.ts` — the studio reads the project list from the resolved\n * workspace config, never from the backend. The active project id is route-\n * driven; this store holds the config-derived list + the recents context.\n * Lifecycle (create/rename/archive/delete) lives in code/CLI, not the UI.\n */\n\nexport interface StudioStore {\n /** Projects declared in `elytra.config.ts`, in config order. */\n projects: readonly Project[]\n /** Active-project context (recents); the active id itself is route-driven. */\n context: ActiveProjectContext\n getProject(id: ProjectId): Project | undefined\n /** Record a project as active + most-recent (idempotent). */\n activate(id: ProjectId): void\n}\n\nconst StudioContext = createContext<StudioStore | null>(null)\n\n/** Resolve the config-declared projects into studio `Project`s (slug-keyed). */\nfunction configProjects(): readonly Project[] {\n const state = getWorkspaceState()\n if (state.kind !== 'config') return []\n return state.projects.map((entry) => {\n const project = configProject(entry)\n // EC-221: the plugin marketplace UI is cut from v1 (vision §5). The\n // Extensions surface is pulled from the nav by marking the section\n // unavailable — the rail omits unavailable sections. The @elytracms/plugins\n // package, ExtensionsView, and the `/extensions` route all remain in the tree\n // for Milestone E revival (reachable by URL, just not advertised in the nav).\n return {\n ...project,\n settings: {\n ...project.settings,\n sectionAvailability: {\n ...project.settings.sectionAvailability,\n extensions: 'unavailable',\n },\n },\n }\n })\n}\n\nexport function StudioProvider({ children }: { children: ReactNode }) {\n // The workspace config is static for the app's lifetime (bundled at build or\n // injected via env), so the project list is computed once.\n const [projects] = useState<readonly Project[]>(() => configProjects())\n const [context, setContext] = useState<ActiveProjectContext>(emptyContext)\n\n const getProject = useCallback((id: ProjectId) => projects.find((p) => p.id === id), [projects])\n\n const activate = useCallback((id: ProjectId) => {\n setContext((prev) => (prev.activeProjectId === id ? prev : activateProject(prev, id)))\n }, [])\n\n const store = useMemo<StudioStore>(\n () => ({ projects, context, getProject, activate }),\n [projects, context, getProject, activate],\n )\n\n // EC-308/AD-17: the single client query cache mounts here (package-owned,\n // above every per-project provider, surviving project switches) so every\n // studio server read flows through `useOperationQuery`.\n return (\n <StudioContext.Provider value={store}>\n <StudioQueryProvider>{children}</StudioQueryProvider>\n </StudioContext.Provider>\n )\n}\n\nexport function useStudio(): StudioStore {\n const store = useContext(StudioContext)\n if (!store) throw new Error('useStudio must be used within a <StudioProvider>.')\n return store\n}\n"]}
|
|
@@ -4,9 +4,13 @@ export async function deleteAsset(deps, projectId, assetId, options = {}) {
|
|
|
4
4
|
const asset = await deps.assets.findAsset(projectId, assetId);
|
|
5
5
|
if (!asset)
|
|
6
6
|
return { outcome: 'not-found' };
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
// Only consult the reference index when the caller has NOT already confirmed.
|
|
8
|
+
// The delete dialog enumerates usages up-front and confirms with `confirmInUse`,
|
|
9
|
+
// so a confirmed delete skips this redundant inbound query entirely (EC-301 perf).
|
|
10
|
+
if (options.confirmInUse !== true) {
|
|
11
|
+
const usageCount = await assetUsageCount(deps, projectId, assetId);
|
|
12
|
+
if (usageCount > 0)
|
|
13
|
+
return { outcome: 'blocked', usageCount };
|
|
10
14
|
}
|
|
11
15
|
// Bytes first, metadata last: a failure midway leaves a visible metadata
|
|
12
16
|
// record (re-deletable) rather than invisible orphaned bytes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-asset.js","sourceRoot":"","sources":["../../../src/lib/assets/delete-asset.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AAK,CAAC,UAAU,CAAC,CAAA;QACzC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QACjD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAA;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,mBAAmB;YAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAA;QACzE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;IAC9F,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,eAAe,CAC5B,IAAqB,EACrB,SAAiB,EACjB,OAAe;IAEf,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IACxF,MAAM,QAAQ,GAAG,IAAI,GAAG,CACtB,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAChF,CAAA;IACD,OAAO,QAAQ,CAAC,IAAI,CAAA;AACtB,CAAC","sourcesContent":["import { RecordNotFoundError } from '@elytracms/core/persistence'\nimport type {\n AssetRepository,\n BlobStorageAdapter,\n ReferenceIndexRepository,\n} from '@elytracms/core/persistence'\n\n/**\n * Reference-respecting asset deletion (EC-151, reworked EC-202). Deleting an\n * asset that is referenced is blocked until explicitly confirmed; the usage\n * count comes from the **EC-155 reference index** (`references.inbound` for the\n * `{ type: 'asset' }` target) — index-accurate, replacing the interim string\n * scan (`find-asset-usages`), which could miss rich-text asset hrefs and\n * false-positive on unrelated strings. Deleting an unused asset removes bytes\n * (blob) AND the metadata record. Results are structured data — never throws.\n */\n\nexport interface DeleteAssetDeps {\n assets: AssetRepository\n blobs: BlobStorageAdapter\n /** The EC-155 reference index — the accurate inbound-usage source (EC-202). */\n references: Pick<ReferenceIndexRepository, 'inbound'>\n}\n\nexport type DeleteAssetResult =\n | { outcome: 'deleted' }\n /** The asset is referenced and `confirmInUse` was not set: nothing was removed. */\n | { outcome: 'blocked'; usageCount: number }\n | { outcome: 'not-found' }\n | { outcome: 'error'; message: string }\n\nexport interface DeleteAssetOptions {\n /** Caller has seen the usage count and explicitly confirmed deletion. */\n confirmInUse?: boolean\n}\n\nexport async function deleteAsset(\n deps: DeleteAssetDeps,\n projectId: string,\n assetId: string,\n options: DeleteAssetOptions = {},\n): Promise<DeleteAssetResult> {\n try {\n const asset = await deps.assets.findAsset(projectId, assetId)\n if (!asset) return { outcome: 'not-found' }\n\n // Only consult the reference index when the caller has NOT already confirmed.\n // The delete dialog enumerates usages up-front and confirms with `confirmInUse`,\n // so a confirmed delete skips this redundant inbound query entirely (EC-301 perf).\n if (options.confirmInUse !== true) {\n const usageCount = await assetUsageCount(deps, projectId, assetId)\n if (usageCount > 0) return { outcome: 'blocked', usageCount }\n }\n\n // Bytes first, metadata last: a failure midway leaves a visible metadata\n // record (re-deletable) rather than invisible orphaned bytes.\n await deps.blobs.delete(asset.storageKey)\n await deps.assets.removeAsset(projectId, assetId)\n return { outcome: 'deleted' }\n } catch (error) {\n if (error instanceof RecordNotFoundError) return { outcome: 'not-found' }\n return { outcome: 'error', message: error instanceof Error ? error.message : String(error) }\n }\n}\n\n/**\n * Distinct inbound usages of an asset from the reference index (EC-202). One\n * `source + path` (e.g. `post:hello · values/cover`) can carry both a draft and\n * a published index entry — that is a single usage, so variants collapse before\n * counting (the gate is \"is this referenced\", not \"how many index rows\").\n */\nasync function assetUsageCount(\n deps: DeleteAssetDeps,\n projectId: string,\n assetId: string,\n): Promise<number> {\n const inbound = await deps.references.inbound(projectId, { type: 'asset', id: assetId })\n const distinct = new Set(\n inbound.map((entry) => `${entry.source.type}:${entry.source.id}:${entry.path}`),\n )\n return distinct.size\n}\n"]}
|
|
@@ -9,11 +9,10 @@ import type { OperationsClient } from '../operations';
|
|
|
9
9
|
* pool is exactly the set the live site would serve, so composing a nested page's
|
|
10
10
|
* URL from these ancestors yields the URL the live site actually resolves.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* EC-308/AD-17: loaded + kept fresh through the one `useOperationQuery` cache
|
|
13
|
+
* seam — invalidated only when a publish/unpublish/restore/delete command
|
|
13
14
|
* succeeds (NOT on every autosave upsert — a draft edit doesn't change what's
|
|
14
|
-
* published). Cost:
|
|
15
|
-
* published-content query yet) — fine for v1 collections; a bulk
|
|
16
|
-
* `documents.listPublished` is the perf follow-up for large collections.
|
|
15
|
+
* published). Cost: ONE bulk `documents.listPublished` read (EC-307).
|
|
17
16
|
*/
|
|
18
17
|
export interface PublishedDocuments {
|
|
19
18
|
/** Pinned published snapshot per published document id. Empty while loading. */
|
|
@@ -23,8 +22,9 @@ export interface PublishedDocuments {
|
|
|
23
22
|
/**
|
|
24
23
|
* Build the published pool of a collection (pure over the operations client): the
|
|
25
24
|
* pinned published snapshot of every currently-published document, keyed by id.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* EC-307: one bulk `documents.listPublished` read — the backend resolves each
|
|
26
|
+
* `publishedVersion` pointer to its recorded snapshot — instead of a `list` plus a
|
|
27
|
+
* per-document `listVersions` fan-out. Read failures degrade to an empty pool.
|
|
28
28
|
*/
|
|
29
29
|
export declare function loadPublishedDocuments(operations: OperationsClient, projectId: string, collectionId: string): Promise<Map<string, CmsDocument>>;
|
|
30
30
|
export declare function usePublishedDocuments(projectId: string | undefined, collectionId: string): PublishedDocuments;
|
|
@@ -1,75 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getStudioOperations } from '../operations';
|
|
1
|
+
import { useOperationQuery } from '@elytracms/studio/lib/query';
|
|
3
2
|
/** Commands that change which version is pinned live (and thus the pool). */
|
|
4
|
-
const
|
|
3
|
+
const PUBLISHED_RELOAD_OPS = [
|
|
5
4
|
'documents.publish',
|
|
6
5
|
'documents.unpublish',
|
|
7
6
|
'documents.restore',
|
|
8
7
|
'documents.delete',
|
|
9
|
-
]
|
|
8
|
+
];
|
|
9
|
+
const EMPTY_POOL = new Map();
|
|
10
10
|
/**
|
|
11
11
|
* Build the published pool of a collection (pure over the operations client): the
|
|
12
12
|
* pinned published snapshot of every currently-published document, keyed by id.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* EC-307: one bulk `documents.listPublished` read — the backend resolves each
|
|
14
|
+
* `publishedVersion` pointer to its recorded snapshot — instead of a `list` plus a
|
|
15
|
+
* per-document `listVersions` fan-out. Read failures degrade to an empty pool.
|
|
15
16
|
*/
|
|
16
17
|
export async function loadPublishedDocuments(operations, projectId, collectionId) {
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
18
|
+
const result = await operations.documents.listPublished({ projectId, collection: collectionId });
|
|
19
|
+
if (!result.ok)
|
|
19
20
|
return new Map();
|
|
20
|
-
const published = listed.value.filter((record) => record.publishedVersion !== undefined);
|
|
21
|
-
const snapshots = await Promise.all(published.map(async (record) => {
|
|
22
|
-
const ref = { collection: record.document.collection, id: record.document.id };
|
|
23
|
-
const versions = await operations.documents.listVersions({ projectId, ref });
|
|
24
|
-
if (!versions.ok)
|
|
25
|
-
return null;
|
|
26
|
-
return versions.value.find((v) => v.version === record.publishedVersion)?.snapshot ?? null;
|
|
27
|
-
}));
|
|
28
21
|
const byId = new Map();
|
|
29
|
-
for (const snapshot of
|
|
30
|
-
|
|
31
|
-
byId.set(snapshot.id, snapshot);
|
|
22
|
+
for (const snapshot of result.value)
|
|
23
|
+
byId.set(snapshot.id, snapshot);
|
|
32
24
|
return byId;
|
|
33
25
|
}
|
|
34
26
|
export function usePublishedDocuments(projectId, collectionId) {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
settle(new Map());
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const { operations } = await getStudioOperations();
|
|
49
|
-
settle(await loadPublishedDocuments(operations, projectId, collectionId));
|
|
50
|
-
}, [projectId, collectionId]);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
setState((prev) => ({ byId: prev.byId, status: 'loading' }));
|
|
53
|
-
void load();
|
|
54
|
-
let disposed = false;
|
|
55
|
-
let unsubscribe;
|
|
56
|
-
void getStudioOperations().then((studio) => {
|
|
57
|
-
if (disposed)
|
|
58
|
-
return;
|
|
59
|
-
unsubscribe = studio.operations.events.subscribe((event) => {
|
|
60
|
-
if (event.kind !== 'command' || event.status !== 'succeeded')
|
|
61
|
-
return;
|
|
62
|
-
if (!RELOAD_OPS.has(event.operation))
|
|
63
|
-
return;
|
|
64
|
-
void load();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
return () => {
|
|
68
|
-
disposed = true;
|
|
69
|
-
epochRef.current += 1;
|
|
70
|
-
unsubscribe?.();
|
|
71
|
-
};
|
|
72
|
-
}, [load]);
|
|
73
|
-
return state;
|
|
27
|
+
const query = useOperationQuery({
|
|
28
|
+
// Playground/fixture mode (no backend) is `enabled: false` → never queried.
|
|
29
|
+
queryKey: ['publishedDocuments', projectId ?? '∅', collectionId],
|
|
30
|
+
loader: (operations) => loadPublishedDocuments(operations, projectId, collectionId),
|
|
31
|
+
invalidateOn: PUBLISHED_RELOAD_OPS,
|
|
32
|
+
enabled: projectId !== undefined,
|
|
33
|
+
});
|
|
34
|
+
if (projectId === undefined)
|
|
35
|
+
return { byId: EMPTY_POOL, status: 'ready' };
|
|
36
|
+
return { byId: query.data ?? EMPTY_POOL, status: query.isPending ? 'loading' : 'ready' };
|
|
74
37
|
}
|
|
75
38
|
//# sourceMappingURL=published-documents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"published-documents.js","sourceRoot":"","sources":["../../../src/lib/cms/published-documents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"published-documents.js","sourceRoot":"","sources":["../../../src/lib/cms/published-documents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAsB/D,6EAA6E;AAC7E,MAAM,oBAAoB,GAAG;IAC3B,mBAAmB;IACnB,qBAAqB;IACrB,mBAAmB;IACnB,kBAAkB;CACV,CAAA;AAEV,MAAM,UAAU,GAAqC,IAAI,GAAG,EAAE,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAA4B,EAC5B,SAAiB,EACjB,YAAoB;IAEpB,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAA;IAChG,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,IAAI,GAAG,EAAE,CAAA;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC3C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,KAAK;QAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;IACpE,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,SAA6B,EAC7B,YAAoB;IAEpB,MAAM,KAAK,GAAG,iBAAiB,CAA2B;QACxD,4EAA4E;QAC5E,QAAQ,EAAE,CAAC,oBAAoB,EAAE,SAAS,IAAI,GAAG,EAAE,YAAY,CAAC;QAChE,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,sBAAsB,CAAC,UAAU,EAAE,SAAmB,EAAE,YAAY,CAAC;QAC7F,YAAY,EAAE,oBAAoB;QAClC,OAAO,EAAE,SAAS,KAAK,SAAS;KACjC,CAAC,CAAA;IACF,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;IACzE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;AAC1F,CAAC","sourcesContent":["import type { CmsDocument } from '@elytracms/core/cms-core'\nimport type { OperationsClient } from '../operations'\nimport { useOperationQuery } from '@elytracms/studio/lib/query'\n\n/**\n * The PUBLISHED-perspective documents of a collection (EC-205, \"live = published\")\n * — the pinned published snapshot of each currently-published document, keyed by\n * id. Live surfaces (a document's live URL + \"View live\", EC-216) MUST derive\n * from this, never from the draft rows the studio edits: an unpublished document,\n * or an unpublished `slug`/`parent` edit, must never leak into a \"live\" URL. The\n * pool is exactly the set the live site would serve, so composing a nested page's\n * URL from these ancestors yields the URL the live site actually resolves.\n *\n * EC-308/AD-17: loaded + kept fresh through the one `useOperationQuery` cache\n * seam — invalidated only when a publish/unpublish/restore/delete command\n * succeeds (NOT on every autosave upsert — a draft edit doesn't change what's\n * published). Cost: ONE bulk `documents.listPublished` read (EC-307).\n */\nexport interface PublishedDocuments {\n /** Pinned published snapshot per published document id. Empty while loading. */\n byId: ReadonlyMap<string, CmsDocument>\n status: 'loading' | 'ready'\n}\n\n/** Commands that change which version is pinned live (and thus the pool). */\nconst PUBLISHED_RELOAD_OPS = [\n 'documents.publish',\n 'documents.unpublish',\n 'documents.restore',\n 'documents.delete',\n] as const\n\nconst EMPTY_POOL: ReadonlyMap<string, CmsDocument> = new Map()\n\n/**\n * Build the published pool of a collection (pure over the operations client): the\n * pinned published snapshot of every currently-published document, keyed by id.\n * EC-307: one bulk `documents.listPublished` read — the backend resolves each\n * `publishedVersion` pointer to its recorded snapshot — instead of a `list` plus a\n * per-document `listVersions` fan-out. Read failures degrade to an empty pool.\n */\nexport async function loadPublishedDocuments(\n operations: OperationsClient,\n projectId: string,\n collectionId: string,\n): Promise<Map<string, CmsDocument>> {\n const result = await operations.documents.listPublished({ projectId, collection: collectionId })\n if (!result.ok) return new Map()\n const byId = new Map<string, CmsDocument>()\n for (const snapshot of result.value) byId.set(snapshot.id, snapshot)\n return byId\n}\n\nexport function usePublishedDocuments(\n projectId: string | undefined,\n collectionId: string,\n): PublishedDocuments {\n const query = useOperationQuery<Map<string, CmsDocument>>({\n // Playground/fixture mode (no backend) is `enabled: false` → never queried.\n queryKey: ['publishedDocuments', projectId ?? '∅', collectionId],\n loader: (operations) => loadPublishedDocuments(operations, projectId as string, collectionId),\n invalidateOn: PUBLISHED_RELOAD_OPS,\n enabled: projectId !== undefined,\n })\n if (projectId === undefined) return { byId: EMPTY_POOL, status: 'ready' }\n return { byId: query.data ?? EMPTY_POOL, status: query.isPending ? 'loading' : 'ready' }\n}\n"]}
|
|
@@ -167,9 +167,13 @@ export declare function resolveColumns(collection: CollectionDef, state: TableVi
|
|
|
167
167
|
/** The visible columns of a view, in render order (EC-213). */
|
|
168
168
|
export declare function visibleColumns(collection: CollectionDef, state: TableViewState): string[];
|
|
169
169
|
/**
|
|
170
|
-
* The title/link column
|
|
171
|
-
*
|
|
172
|
-
*
|
|
170
|
+
* The title/link column — the document IDENTITY column (EC-242): the schema title
|
|
171
|
+
* field, shown as the leftmost linked cell whose content is `resolveDocumentTitle`
|
|
172
|
+
* (a string `titleField` or a function pattern). Always present regardless of
|
|
173
|
+
* column visibility — it is the document's identity, not a toggleable data column —
|
|
174
|
+
* and excluded from the data columns so the title never shows twice. Falls back to
|
|
175
|
+
* the first visible column, then the first field, then `id`, when no title field
|
|
176
|
+
* is resolvable (e.g. a function title with no backing `title` field).
|
|
173
177
|
*/
|
|
174
178
|
export declare function primaryColumn(collection: CollectionDef, state: TableViewState): string;
|
|
175
179
|
/**
|
|
@@ -289,13 +289,19 @@ export function visibleColumns(collection, state) {
|
|
|
289
289
|
.map((column) => column.field);
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
|
-
* The title/link column
|
|
293
|
-
*
|
|
294
|
-
*
|
|
292
|
+
* The title/link column — the document IDENTITY column (EC-242): the schema title
|
|
293
|
+
* field, shown as the leftmost linked cell whose content is `resolveDocumentTitle`
|
|
294
|
+
* (a string `titleField` or a function pattern). Always present regardless of
|
|
295
|
+
* column visibility — it is the document's identity, not a toggleable data column —
|
|
296
|
+
* and excluded from the data columns so the title never shows twice. Falls back to
|
|
297
|
+
* the first visible column, then the first field, then `id`, when no title field
|
|
298
|
+
* is resolvable (e.g. a function title with no backing `title` field).
|
|
295
299
|
*/
|
|
296
300
|
export function primaryColumn(collection, state) {
|
|
297
|
-
|
|
298
|
-
|
|
301
|
+
return (titleFieldOf(collection)?.name ??
|
|
302
|
+
visibleColumns(collection, state)[0] ??
|
|
303
|
+
collection.fields[0]?.name ??
|
|
304
|
+
'id');
|
|
299
305
|
}
|
|
300
306
|
/**
|
|
301
307
|
* Reconcile `columns` to the full resolved order so column edits operate on a
|