@elytracms/studio 0.0.94 → 0.0.95

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.
Files changed (126) hide show
  1. package/convex/asset-alt-migration.test.ts +2 -2
  2. package/convex/asset-meta-patch.test.ts +218 -0
  3. package/convex/asset-replace-delete-race.test.ts +127 -0
  4. package/convex/assets.ts +27 -2
  5. package/convex/delivery-redirects.test.ts +167 -0
  6. package/convex/delivery.ts +15 -5
  7. package/convex/rail-write-parity.test.ts +6 -6
  8. package/convex/redirects.ts +1 -1
  9. package/convex/schema.ts +6 -0
  10. package/dist/addon.d.ts +1 -1
  11. package/dist/addon.js.map +1 -1
  12. package/dist/components/assets/asset-detail.js +26 -11
  13. package/dist/components/assets/asset-detail.js.map +1 -1
  14. package/dist/components/assets/asset-locale.d.ts +9 -0
  15. package/dist/components/assets/asset-locale.js +16 -0
  16. package/dist/components/assets/asset-locale.js.map +1 -0
  17. package/dist/components/assets/asset-meta-label.d.ts +12 -0
  18. package/dist/components/assets/asset-meta-label.js +15 -0
  19. package/dist/components/assets/asset-meta-label.js.map +1 -0
  20. package/dist/components/assets/asset-metadata.d.ts +69 -15
  21. package/dist/components/assets/asset-metadata.js +99 -11
  22. package/dist/components/assets/asset-metadata.js.map +1 -1
  23. package/dist/components/assets/asset-search.js +8 -2
  24. package/dist/components/assets/asset-search.js.map +1 -1
  25. package/dist/components/assets/asset-thumb.js +6 -2
  26. package/dist/components/assets/asset-thumb.js.map +1 -1
  27. package/dist/components/assets/assets-collection-view-source.d.ts +23 -9
  28. package/dist/components/assets/assets-collection-view-source.js +78 -26
  29. package/dist/components/assets/assets-collection-view-source.js.map +1 -1
  30. package/dist/components/assets/assets-store.js +17 -4
  31. package/dist/components/assets/assets-store.js.map +1 -1
  32. package/dist/components/builder/builder-store.d.ts +21 -0
  33. package/dist/components/builder/builder-store.js +22 -0
  34. package/dist/components/builder/builder-store.js.map +1 -1
  35. package/dist/components/builder/canvas-commit-boundary.d.ts +22 -0
  36. package/dist/components/builder/canvas-commit-boundary.js +27 -0
  37. package/dist/components/builder/canvas-commit-boundary.js.map +1 -0
  38. package/dist/components/builder/canvas-rebase.d.ts +77 -0
  39. package/dist/components/builder/canvas-rebase.js +169 -0
  40. package/dist/components/builder/canvas-rebase.js.map +1 -0
  41. package/dist/components/builder/canvas-render-context.d.ts +6 -3
  42. package/dist/components/builder/canvas-render-context.js +17 -9
  43. package/dist/components/builder/canvas-render-context.js.map +1 -1
  44. package/dist/components/builder/composition-field-editor.d.ts +20 -2
  45. package/dist/components/builder/composition-field-editor.js +45 -27
  46. package/dist/components/builder/composition-field-editor.js.map +1 -1
  47. package/dist/components/builder/node-factory.js +15 -3
  48. package/dist/components/builder/node-factory.js.map +1 -1
  49. package/dist/components/builder/property-inspector.js +3 -1
  50. package/dist/components/builder/property-inspector.js.map +1 -1
  51. package/dist/components/builder/run-inspector.js +10 -6
  52. package/dist/components/builder/run-inspector.js.map +1 -1
  53. package/dist/components/cms/asset-field.d.ts +5 -2
  54. package/dist/components/cms/asset-field.js +34 -17
  55. package/dist/components/cms/asset-field.js.map +1 -1
  56. package/dist/components/cms/asset-picker.js +3 -1
  57. package/dist/components/cms/asset-picker.js.map +1 -1
  58. package/dist/components/cms/canvas-commit.d.ts +56 -0
  59. package/dist/components/cms/canvas-commit.js +35 -0
  60. package/dist/components/cms/canvas-commit.js.map +1 -0
  61. package/dist/components/cms/collection-table.js +23 -7
  62. package/dist/components/cms/collection-table.js.map +1 -1
  63. package/dist/components/cms/commit-policy.d.ts +6 -2
  64. package/dist/components/cms/commit-policy.js +1 -1
  65. package/dist/components/cms/commit-policy.js.map +1 -1
  66. package/dist/components/cms/detail-editor.js +11 -1
  67. package/dist/components/cms/detail-editor.js.map +1 -1
  68. package/dist/components/cms/use-document-draft.d.ts +62 -4
  69. package/dist/components/cms/use-document-draft.js +102 -32
  70. package/dist/components/cms/use-document-draft.js.map +1 -1
  71. package/dist/components/cms/use-live-url.d.ts +6 -1
  72. package/dist/components/cms/use-live-url.js +12 -9
  73. package/dist/components/cms/use-live-url.js.map +1 -1
  74. package/dist/components/collection-view/cms-collection-view-source.js +9 -5
  75. package/dist/components/collection-view/cms-collection-view-source.js.map +1 -1
  76. package/dist/components/deployment-setup-gate.js +10 -1
  77. package/dist/components/deployment-setup-gate.js.map +1 -1
  78. package/dist/components/records/record-lens.js +3 -8
  79. package/dist/components/records/record-lens.js.map +1 -1
  80. package/dist/lib/assets/upload.d.ts +25 -7
  81. package/dist/lib/assets/upload.js +30 -21
  82. package/dist/lib/assets/upload.js.map +1 -1
  83. package/dist/lib/cms/published-documents.d.ts +24 -6
  84. package/dist/lib/cms/published-documents.js +39 -6
  85. package/dist/lib/cms/published-documents.js.map +1 -1
  86. package/dist/lib/cms-views/view-model.d.ts +14 -101
  87. package/dist/lib/cms-views/view-model.js +20 -101
  88. package/dist/lib/cms-views/view-model.js.map +1 -1
  89. package/dist/lib/collection-view/collection-view-source.d.ts +6 -1
  90. package/dist/lib/collection-view/collection-view-source.js.map +1 -1
  91. package/dist/lib/engine-version.d.ts +1 -1
  92. package/dist/lib/engine-version.js +1 -1
  93. package/dist/lib/engine-version.js.map +1 -1
  94. package/dist/lib/i18n/messages.de.js +7 -3
  95. package/dist/lib/i18n/messages.de.js.map +1 -1
  96. package/dist/lib/i18n/messages.en.d.ts +5 -1
  97. package/dist/lib/i18n/messages.en.js +8 -4
  98. package/dist/lib/i18n/messages.en.js.map +1 -1
  99. package/dist/lib/operations/config-manifest-lookup.d.ts +1 -1
  100. package/dist/lib/operations/config-manifest-lookup.js +3 -3
  101. package/dist/lib/operations/config-manifest-lookup.js.map +1 -1
  102. package/dist/lib/persistence/deployment-readiness.js +14 -11
  103. package/dist/lib/persistence/deployment-readiness.js.map +1 -1
  104. package/dist/lib/persona/labels.js +1 -0
  105. package/dist/lib/persona/labels.js.map +1 -1
  106. package/dist/lib/query/index.d.ts +2 -2
  107. package/dist/lib/query/index.js +1 -1
  108. package/dist/lib/query/index.js.map +1 -1
  109. package/dist/lib/query/operations-query.d.ts +26 -0
  110. package/dist/lib/query/operations-query.js +12 -0
  111. package/dist/lib/query/operations-query.js.map +1 -1
  112. package/dist/lib/registry/index.js +2 -2
  113. package/dist/lib/registry/index.js.map +1 -1
  114. package/dist/lib/registry/preview.d.ts +10 -0
  115. package/dist/lib/registry/preview.js +13 -4
  116. package/dist/lib/registry/preview.js.map +1 -1
  117. package/dist/lib/routes/route-issues.js +6 -3
  118. package/dist/lib/routes/route-issues.js.map +1 -1
  119. package/dist/lib/workspace/workspace-source.js +6 -7
  120. package/dist/lib/workspace/workspace-source.js.map +1 -1
  121. package/dist/previews/entry-node.d.ts +14 -0
  122. package/dist/previews/entry-node.js +22 -0
  123. package/dist/previews/entry-node.js.map +1 -0
  124. package/dist/previews/harness.js +2 -16
  125. package/dist/previews/harness.js.map +1 -1
  126. package/package.json +3 -3
@@ -1,6 +1,9 @@
1
1
  import type { PresenceEntry } from '@elytracms/core/persistence';
2
2
  import type { CmsDocument, CollectionDef, DocumentPatch, FieldDef, Locale, PropFieldLookup, ValuePath } from '@elytracms/core/cms-core';
3
3
  import type { CollectionViewSource } from '../../lib/collection-view/collection-view-source.js';
4
+ import type { CanvasFieldChange } from '../builder/canvas-rebase.js';
5
+ import type { CommitPolicy } from './commit-policy.js';
6
+ import type { CanvasControlPosition } from './canvas-commit.js';
4
7
  import type { Scheduler, UncommittedPosition } from './draft-commit.js';
5
8
  /**
6
9
  * EC-595 A2 — the detail editor's draft over the revisioned document (and, for the
@@ -10,7 +13,9 @@ import type { Scheduler, UncommittedPosition } from './draft-commit.js';
10
13
  * reads it); a field's edit is COMMITTED per its control kind's policy
11
14
  * ({@link commitPolicyOf} / {@link createDraftCommitter}) as the patch of the position it
12
15
  * wrote — never a document. The canvas commits each action's node patches at once
13
- * (`compositionPatches`). The draft REBASES whenever the session's document changes
16
+ * (`compositionPatches`); a burst of typing in one of its inspector controls is that
17
+ * control's uncommitted position, committed on its kind's policy like a form field
18
+ * (EC-630, `canvas-commit.ts`). The draft REBASES whenever the session's document changes
14
19
  * (a write result, a colleague's change by subscription, a resolved conflict): it is the
15
20
  * session's document with this editor's uncommitted positions laid over it — local wins
16
21
  * until committed, then the per-path check decides (EC-595 point 7).
@@ -42,6 +47,35 @@ export declare function positionPatch(doc: CmsDocument, path: ValuePath): Docume
42
47
  * over it, values from the editor's current draft.
43
48
  */
44
49
  export declare function rebaseDraft(sessionDoc: CmsDocument, draft: CmsDocument, uncommitted: readonly UncommittedPosition[]): CmsDocument;
50
+ /**
51
+ * EC-630 — the canvas's write into the draft (pure). The canvas writer's node patches,
52
+ * keyed by node id, are the canvas's OWN delta: from `base`, the value it last agreed on
53
+ * with the draft, to `value` — never a document diff, and never measured against the
54
+ * draft's CURRENT value (a colleague's change that reached the draft a moment before the
55
+ * edit lifted would read as part of the edit, and its patches would revert it). The draft
56
+ * takes the delta over whatever it holds now (normally `base` itself) and canonicalises the
57
+ * field through the write lens. `undefined` when the canvas changed nothing.
58
+ */
59
+ export declare function canvasWrite(input: {
60
+ collection: CollectionDef;
61
+ draft: CmsDocument;
62
+ field: string;
63
+ locale: Locale;
64
+ value: unknown;
65
+ base: unknown;
66
+ lookupManifest: PropFieldLookup;
67
+ }): {
68
+ next: CmsDocument;
69
+ patches: DocumentPatch[];
70
+ } | undefined;
71
+ /**
72
+ * EC-630 — the change of the canvas field made UNDERNEATH the canvas when the draft
73
+ * rebased from `previous` to `next` (pure), numbered after `last`; `undefined` when the
74
+ * field did not move. The canvas's own edits are in both values (the session's view holds
75
+ * every patch it committed, the draft overlays every position it has not), so the change
76
+ * is someone else's: a colleague's patch, a write's canonical row, a resolved conflict.
77
+ */
78
+ export declare function canvasFieldChange(previous: CmsDocument, next: CmsDocument, path: ValuePath, last: CanvasFieldChange | undefined): CanvasFieldChange | undefined;
45
79
  /**
46
80
  * The reader's "now" for presence liveness: THIS session's own latest heartbeat `at`
47
81
  * (written by the same store clock as everyone else's — the playground store runs a
@@ -61,22 +95,46 @@ export interface DocumentDraft {
61
95
  setFieldValue(field: FieldDef, value: unknown): void;
62
96
  /** A writer that transforms ONE field position (fill / reset from base). */
63
97
  editField(field: FieldDef, update: (draft: CmsDocument) => CmsDocument): void;
64
- /** The canvas emitted a new value for its field (node patches, committed at once). */
65
- setCanvasValue(field: FieldDef, value: unknown): void;
98
+ /**
99
+ * The canvas emitted a new value for its field (node patches, committed at once). `base`
100
+ * is the value the canvas last agreed on with the draft: the canvas writer's delta is
101
+ * `base` → `value`, applied over whatever the draft holds now (EC-630 — a change that
102
+ * landed underneath meanwhile is never reverted by the canvas's own write).
103
+ */
104
+ setCanvasValue(field: FieldDef, value: unknown, base: unknown): void;
66
105
  /** The slot alias (a document-level key: a whole-document write at the held revision). */
67
106
  setAlias(alias: string | undefined): void;
68
107
  /** Field boundary events (focus / blur / Enter) — the commit policy's triggers. */
69
108
  focused(field: FieldDef): void;
70
109
  blurred(field: FieldDef): void;
71
110
  entered(field: FieldDef): void;
111
+ /**
112
+ * EC-630 — the canvas inspector's boundary events: a control writing `position` of the
113
+ * canvas field `field`, committing on `policy` (THE declaration for its kind). A burst of
114
+ * typing in it is its uncommitted position until blur / Enter / the idle pause.
115
+ */
116
+ canvasFocused(field: FieldDef, position: CanvasControlPosition, policy: CommitPolicy): void;
117
+ canvasBlurred(field: FieldDef, position: CanvasControlPosition): void;
118
+ canvasEntered(field: FieldDef, position: CanvasControlPosition): void;
72
119
  /** The forced commit (sync; the persister serialises what follows) / the record model's Save. */
73
120
  save(): void;
74
121
  /** The FORCED FLUSH: commit everything uncommitted and await persistence. */
75
122
  flush(): Promise<void>;
76
123
  /** Adopt a draft from outside (a restored version). */
77
124
  replaceDraft(next: CmsDocument): void;
78
- /** Bumped when the canvas must remount from the draft (a restore, a colleague's change). */
125
+ /**
126
+ * Bumped when the canvas must remount from the draft: a restored version replaced the
127
+ * document, or a locale switch pointed the canvas at another bucket. (A change made
128
+ * underneath the canvas is NOT a remount — {@link canvasChange}.)
129
+ */
79
130
  canvasNonce: number;
131
+ /**
132
+ * EC-630 — the latest change of the canvas field's value made UNDERNEATH the canvas (a
133
+ * colleague's patch by subscription, a write's canonical row, a resolved conflict): the
134
+ * draft's value before and after it. The canvas REBASES onto it — the change lands, its
135
+ * undo history and selection survive — where it used to remount and lose both.
136
+ */
137
+ canvasChange: CanvasFieldChange | undefined;
80
138
  /** The OTHER sessions present on this document, live by the reader's clock. */
81
139
  presence: readonly PresenceEntry[];
82
140
  }
@@ -4,6 +4,7 @@ import { applyDocumentPatches, formatValuePath, readValueAt, semanticValueEqual,
4
4
  import { fieldPositionPath } from '../../lib/cms/field-patch.js';
5
5
  import { compositionPatches } from '../builder/composition-patches.js';
6
6
  import { commitPolicyOf } from './commit-policy.js';
7
+ import { canvasControl, routeCanvasWrite } from './canvas-commit.js';
7
8
  import { browserScheduler, createDraftCommitter } from './draft-commit.js';
8
9
  /**
9
10
  * EC-595 A2 — the detail editor's draft over the revisioned document (and, for the
@@ -13,7 +14,9 @@ import { browserScheduler, createDraftCommitter } from './draft-commit.js';
13
14
  * reads it); a field's edit is COMMITTED per its control kind's policy
14
15
  * ({@link commitPolicyOf} / {@link createDraftCommitter}) as the patch of the position it
15
16
  * wrote — never a document. The canvas commits each action's node patches at once
16
- * (`compositionPatches`). The draft REBASES whenever the session's document changes
17
+ * (`compositionPatches`); a burst of typing in one of its inspector controls is that
18
+ * control's uncommitted position, committed on its kind's policy like a form field
19
+ * (EC-630, `canvas-commit.ts`). The draft REBASES whenever the session's document changes
17
20
  * (a write result, a colleague's change by subscription, a resolved conflict): it is the
18
21
  * session's document with this editor's uncommitted positions laid over it — local wins
19
22
  * until committed, then the per-path check decides (EC-595 point 7).
@@ -59,6 +62,37 @@ export function rebaseDraft(sessionDoc, draft, uncommitted) {
59
62
  const patches = uncommitted.map((position) => positionPatch(draft, position.path));
60
63
  return applyDocumentPatches({ document: sessionDoc, patches, since: [] }).document;
61
64
  }
65
+ /**
66
+ * EC-630 — the canvas's write into the draft (pure). The canvas writer's node patches,
67
+ * keyed by node id, are the canvas's OWN delta: from `base`, the value it last agreed on
68
+ * with the draft, to `value` — never a document diff, and never measured against the
69
+ * draft's CURRENT value (a colleague's change that reached the draft a moment before the
70
+ * edit lifted would read as part of the edit, and its patches would revert it). The draft
71
+ * takes the delta over whatever it holds now (normally `base` itself) and canonicalises the
72
+ * field through the write lens. `undefined` when the canvas changed nothing.
73
+ */
74
+ export function canvasWrite(input) {
75
+ const { collection, draft, field, locale, lookupManifest } = input;
76
+ const path = fieldPositionPath(collection, field, locale);
77
+ const localized = path.length > 1 ? locale : undefined;
78
+ const patches = compositionPatches(input.base, input.value, field, localized);
79
+ if (patches.length === 0)
80
+ return undefined;
81
+ const applied = applyDocumentPatches({ document: draft, patches, since: [] }).document;
82
+ return { next: writeField(collection, draft, field, locale, readValueAt(applied, path), { lookupManifest }), patches };
83
+ }
84
+ /**
85
+ * EC-630 — the change of the canvas field made UNDERNEATH the canvas when the draft
86
+ * rebased from `previous` to `next` (pure), numbered after `last`; `undefined` when the
87
+ * field did not move. The canvas's own edits are in both values (the session's view holds
88
+ * every patch it committed, the draft overlays every position it has not), so the change
89
+ * is someone else's: a colleague's patch, a write's canonical row, a resolved conflict.
90
+ */
91
+ export function canvasFieldChange(previous, next, path, last) {
92
+ const from = readValueAt(previous, path);
93
+ const to = readValueAt(next, path);
94
+ return semanticValueEqual(from, to) ? undefined : { from, to, seq: (last?.seq ?? 0) + 1 };
95
+ }
62
96
  /**
63
97
  * The reader's "now" for presence liveness: THIS session's own latest heartbeat `at`
64
98
  * (written by the same store clock as everyone else's — the playground store runs a
@@ -102,10 +136,14 @@ export function useDocumentDraft(input) {
102
136
  // --- Committing --------------------------------------------------------------------
103
137
  const writesRef = useRef(documentModel);
104
138
  writesRef.current = documentModel;
139
+ /** EC-630 — the canvas inspector controls that took focus, by committer key (their position + policy). */
140
+ const canvasControls = useRef(new Map());
105
141
  const committer = useMemo(() => createDraftCommitter({
106
142
  policyOf: (name) => {
107
143
  const field = fieldsByName.get(name);
108
- return field ? commitPolicyOf(field) : 'blur-or-idle';
144
+ if (field)
145
+ return commitPolicyOf(field);
146
+ return canvasControls.current.get(name)?.policy ?? 'blur-or-idle';
109
147
  },
110
148
  commit: (positions) => {
111
149
  const target = writesRef.current;
@@ -118,29 +156,17 @@ export function useDocumentDraft(input) {
118
156
  }),
119
157
  // One committer per open document (the editor is keyed by it).
120
158
  [ref]);
121
- // --- The canvas's value and its remount ---------------------------------------------
159
+ // --- The canvas's value: its remount and its rebase ------------------------------------
122
160
  const canvasPath = canvasField ? fieldPositionPath(collection, canvasField.name, locale) : undefined;
123
161
  const canvasPathKey = canvasPath ? formatValuePath(canvasPath) : '';
124
- const canvasValueRef = useRef(canvasPath ? readValueAt(draft, canvasPath) : undefined);
125
162
  const [canvasNonce, setCanvasNonce] = useState(0);
126
- const syncCanvas = useCallback((next) => {
127
- if (!canvasPath)
128
- return;
129
- const value = readValueAt(next, canvasPath);
130
- if (semanticValueEqual(value, canvasValueRef.current))
131
- return;
132
- canvasValueRef.current = value;
133
- setCanvasNonce((n) => n + 1);
134
- },
135
- // The path is keyed by its string form.
136
- [canvasPathKey]);
163
+ const [canvasChange, setCanvasChange] = useState(undefined);
137
164
  // A locale switch points the canvas at another bucket: remount from it.
138
165
  const lastCanvasPathKey = useRef(canvasPathKey);
139
166
  useEffect(() => {
140
167
  if (lastCanvasPathKey.current === canvasPathKey)
141
168
  return;
142
169
  lastCanvasPathKey.current = canvasPathKey;
143
- canvasValueRef.current = canvasPath ? readValueAt(draftRef.current, canvasPath) : undefined;
144
170
  setCanvasNonce((n) => n + 1);
145
171
  }, [canvasPathKey]);
146
172
  // --- The rebase (document model) -------------------------------------------------------
@@ -152,9 +178,15 @@ export function useDocumentDraft(input) {
152
178
  }
153
179
  if (!documentModel)
154
180
  return;
155
- const next = rebaseDraft(doc, draftRef.current, committer.uncommitted());
181
+ const previous = draftRef.current;
182
+ const next = rebaseDraft(doc, previous, committer.uncommitted());
156
183
  setDraft(next);
157
- syncCanvas(next);
184
+ // EC-630: the canvas field moved underneath the canvas — the canvas rebases onto the
185
+ // change (its own edits are in both values: the session's view holds every patch it
186
+ // committed, and the draft overlays every position it has not).
187
+ if (!canvasPath)
188
+ return;
189
+ setCanvasChange((last) => canvasFieldChange(previous, next, canvasPath, last) ?? last);
158
190
  }, [doc]);
159
191
  // --- Writers ----------------------------------------------------------------------------
160
192
  const setFieldValue = useCallback((field, value) => {
@@ -168,20 +200,23 @@ export function useDocumentDraft(input) {
168
200
  if (documentModel)
169
201
  committer.edited(field.name, fieldPositionPath(collection, field.name, locale));
170
202
  }, [collection, locale, setDraft, documentModel, committer]);
171
- const setCanvasValue = useCallback((field, value) => {
172
- const path = fieldPositionPath(collection, field.name, locale);
173
- const before = readValueAt(draftRef.current, path);
174
- const next = writeField(collection, draftRef.current, field.name, locale, value, { lookupManifest });
175
- const after = readValueAt(next, path);
176
- setDraft(next);
177
- canvasValueRef.current = after;
203
+ const setCanvasValue = useCallback((field, value, base) => {
204
+ const write = canvasWrite({ collection, draft: draftRef.current, field: field.name, locale, value, base, lookupManifest });
205
+ if (!write)
206
+ return;
207
+ setDraft(write.next);
178
208
  if (!documentModel)
179
209
  return;
180
- // The canvas writer's node patches, keyed by node id (computed here, in its write
181
- // path, from the canonical values before and after the action — never a document diff).
182
- const localized = path.length > 1 ? locale : undefined;
183
- void documentModel.commit(ref, compositionPatches(before, after, field.name, localized));
184
- }, [collection, locale, lookupManifest, setDraft, documentModel, ref]);
210
+ // EC-630: a burst of typing in a focused inspector control is that control's
211
+ // uncommitted position (its policy commits it); a canvas action commits now.
212
+ const focus = committer.focusedField();
213
+ routeCanvasWrite({
214
+ patches: write.patches,
215
+ focused: focus === undefined ? undefined : canvasControls.current.get(focus),
216
+ committer,
217
+ commitNow: (patches) => void documentModel.commit(ref, patches),
218
+ });
219
+ }, [collection, locale, lookupManifest, setDraft, documentModel, ref, committer]);
185
220
  const setAlias = useCallback((alias) => {
186
221
  const next = { ...draftRef.current };
187
222
  if (alias === undefined)
@@ -271,10 +306,41 @@ export function useDocumentDraft(input) {
271
306
  if (documentModel)
272
307
  committer.entered(field.name);
273
308
  }, [documentModel, committer]);
309
+ // EC-630 — the canvas inspector's commit boundary: a control at a position of the canvas
310
+ // field gained focus, lost it, or saw Enter. Its policy is THE declaration's for its kind.
311
+ const canvasControlOf = useCallback((field, position, policy) => canvasControl(fieldPositionPath(collection, field.name, locale), position, policy), [collection, locale]);
312
+ const canvasFocused = useCallback((field, position, policy) => {
313
+ if (!documentModel)
314
+ return;
315
+ const control = canvasControlOf(field, position, policy);
316
+ canvasControls.current.set(control.key, control);
317
+ committer.focused(control.key);
318
+ focusedPathRef.current = control.path;
319
+ heartbeat();
320
+ }, [documentModel, committer, canvasControlOf, heartbeat]);
321
+ const canvasBlurred = useCallback((field, position) => {
322
+ if (!documentModel)
323
+ return;
324
+ const key = canvasControlOf(field, position, 'change').key;
325
+ committer.blurred(key);
326
+ canvasControls.current.delete(key);
327
+ focusedPathRef.current = undefined;
328
+ heartbeat();
329
+ }, [documentModel, committer, canvasControlOf, heartbeat]);
330
+ const canvasEntered = useCallback((field, position) => {
331
+ if (documentModel)
332
+ committer.entered(canvasControlOf(field, position, 'change').key);
333
+ }, [documentModel, committer, canvasControlOf]);
274
334
  const replaceDraft = useCallback((next) => {
335
+ // A restored version replaces the document: when it moved the canvas field, the
336
+ // canvas remounts from it (its history belonged to the replaced value).
337
+ const moved = canvasPath && !semanticValueEqual(readValueAt(draftRef.current, canvasPath), readValueAt(next, canvasPath));
275
338
  setDraft(next);
276
- syncCanvas(next);
277
- }, [setDraft, syncCanvas]);
339
+ if (moved)
340
+ setCanvasNonce((n) => n + 1);
341
+ },
342
+ // The path is keyed by its string form.
343
+ [setDraft, canvasPathKey]);
278
344
  const dirty = useMemo(() => !semanticValueEqual(draft, doc), [draft, doc]);
279
345
  return {
280
346
  draft,
@@ -287,10 +353,14 @@ export function useDocumentDraft(input) {
287
353
  focused,
288
354
  blurred,
289
355
  entered,
356
+ canvasFocused,
357
+ canvasBlurred,
358
+ canvasEntered,
290
359
  save,
291
360
  flush,
292
361
  replaceDraft,
293
362
  canvasNonce,
363
+ canvasChange,
294
364
  presence,
295
365
  };
296
366
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-document-draft.js","sourceRoot":"","sources":["../../../src/components/cms/use-document-draft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,EACL,eAAe,EACf,YAAY,GACb,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,UAAU,GACX,MAAM,0BAA0B,CAAA;AAYjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAGvE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,wGAAwG;AACxG,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAA;AAQ3C,MAAM,CAAC,MAAM,kBAAkB,GAAqB;IAClD,QAAQ,CAAC,QAAQ;QACf,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;QACpD,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ;gBAAE,QAAQ,EAAE,CAAA;QACvD,CAAC,CAAA;QACD,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAA;QACvD,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAA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AAE,MAAM,EAAE,SAAS,CAAC,CAC1D,CAAA;IACD,MAAM,OAAO,GAAG,WAAW,CACzB,CAAC,KAAe,EAAE,EAAE;QAClB,IAAI,CAAC,aAAa;YAAE,OAAM;QAC1B,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC7B,cAAc,CAAC,OAAO,GAAG,SAAS,CAAA;QAClC,SAAS,EAAE,CAAA;IACb,CAAC,EACD,CAAC,aAAa,EAAE,SAAS,EAAE,SAAS,CAAC,CACtC,CAAA;IACD,MAAM,OAAO,GAAG,WAAW,CACzB,CAAC,KAAe,EAAE,EAAE;QAClB,IAAI,aAAa;YAAE,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAClD,CAAC,EACD,CAAC,aAAa,EAAE,SAAS,CAAC,CAC3B,CAAA;IAED,MAAM,YAAY,GAAG,WAAW,CAC9B,CAAC,IAAiB,EAAE,EAAE;QACpB,QAAQ,CAAC,IAAI,CAAC,CAAA;QACd,UAAU,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC,EACD,CAAC,QAAQ,EAAE,UAAU,CAAC,CACvB,CAAA;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;IAE1E,OAAO;QACL,KAAK;QACL,KAAK;QACL,YAAY,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ;QACtC,aAAa;QACb,SAAS;QACT,cAAc;QACd,QAAQ;QACR,OAAO;QACP,OAAO;QACP,OAAO;QACP,IAAI;QACJ,KAAK;QACL,YAAY;QACZ,WAAW;QACX,QAAQ;KACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport {\n PRESENCE_TTL_MS,\n livePresence,\n} from '@elytracms/core/persistence'\nimport type { PresenceEntry } from '@elytracms/core/persistence'\nimport {\n applyDocumentPatches,\n formatValuePath,\n readValueAt,\n semanticValueEqual,\n writeField,\n} from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentPatch,\n DocumentRef,\n FieldDef,\n Locale,\n PropFieldLookup,\n ValuePath,\n} from '@elytracms/core/cms-core'\nimport type { CollectionViewSource } from '../../lib/collection-view/collection-view-source'\nimport { fieldPositionPath } from '../../lib/cms/field-patch'\nimport { compositionPatches } from '../builder/composition-patches'\nimport { commitPolicyOf } from './commit-policy'\nimport { browserScheduler, createDraftCommitter } from './draft-commit'\nimport type { DraftCommitter, Scheduler, UncommittedPosition } from './draft-commit'\n\n/**\n * EC-595 A2 — the detail editor's draft over the revisioned document (and, for the\n * explicit-save rails, over a record).\n *\n * **Document write model** (the CMS): the draft changes per keystroke (live validation\n * reads it); a field's edit is COMMITTED per its control kind's policy\n * ({@link commitPolicyOf} / {@link createDraftCommitter}) as the patch of the position it\n * wrote — never a document. The canvas commits each action's node patches at once\n * (`compositionPatches`). The draft REBASES whenever the session's document changes\n * (a write result, a colleague's change by subscription, a resolved conflict): it is the\n * session's document with this editor's uncommitted positions laid over it — local wins\n * until committed, then the per-path check decides (EC-595 point 7).\n *\n * **Forced flushes** (the ruling: before unmount, tab hide, publish, preview, an AI\n * proposal, duplicate, transfer): {@link DocumentDraft.flush} commits every uncommitted\n * position and awaits the persister. Unmount and tab hide run it here; the editor's\n * publish, duplicate and the AI tap call it.\n *\n * **Thin presence** (Stage A): a heartbeat naming the focused field's path on focus\n * change and every {@link PRESENCE_HEARTBEAT_MS} (under the 30 s TTL), cleared on\n * unmount; the other sessions' live heartbeats arrive with the subscription.\n *\n * **Record write model** (users, redirects, assets, the account): the draft is edited\n * in place and written whole on the editor's Save button (EC-240) — unchanged.\n */\n\n/** The presence heartbeat interval — under {@link PRESENCE_TTL_MS} so a present editor never lapses. */\nexport const PRESENCE_HEARTBEAT_MS = 10_000\n\n/** An injectable visibility source (the tab-hide flush; tests drive it). */\nexport interface VisibilitySource {\n /** Call `onHidden` whenever the tab becomes hidden; returns the unsubscribe. */\n onHidden(onHidden: () => void): () => void\n}\n\nexport const documentVisibility: VisibilitySource = {\n onHidden(onHidden) {\n if (typeof document === 'undefined') return () => {}\n const listener = () => {\n if (document.visibilityState === 'hidden') onHidden()\n }\n document.addEventListener('visibilitychange', listener)\n return () => document.removeEventListener('visibilitychange', listener)\n },\n}\n\n/** The patch that writes the value `doc` holds at `path` (unset when absent). */\nexport function positionPatch(doc: CmsDocument, path: ValuePath): DocumentPatch {\n const value = readValueAt(doc, path)\n return value === undefined ? { op: 'unset', path } : { op: 'set', path, value }\n}\n\n/**\n * THE rebase (pure): the session's document with the editor's uncommitted positions laid\n * over it, values from the editor's current draft.\n */\nexport function rebaseDraft(\n sessionDoc: CmsDocument,\n draft: CmsDocument,\n uncommitted: readonly UncommittedPosition[],\n): CmsDocument {\n if (uncommitted.length === 0) return sessionDoc\n const patches = uncommitted.map((position) => positionPatch(draft, position.path))\n return applyDocumentPatches({ document: sessionDoc, patches, since: [] }).document\n}\n\n/**\n * The reader's \"now\" for presence liveness: THIS session's own latest heartbeat `at`\n * (written by the same store clock as everyone else's — the playground store runs a\n * deterministic sequential clock, Convex the writers' wall clocks), falling back to the\n * injected clock before the first heartbeat lands. Comparing others' `at` against a\n * different time base would call every colleague stale (measured live in the\n * playground: the store's clock is months behind the browser's).\n */\nexport function presenceReaderNow(\n entries: readonly PresenceEntry[],\n sessionId: string,\n fallback: string,\n): string {\n const own = entries.filter((entry) => entry.sessionId === sessionId).map((entry) => entry.at)\n return own.length > 0 ? own.sort().at(-1)! : fallback\n}\n\nexport interface DocumentDraft {\n draft: CmsDocument\n /** Uncommitted (document model) / unsaved (record model) edits exist. */\n dirty: boolean\n /** The record model: the editor renders a Save button + navigation guard. */\n explicitSave: boolean\n /** A field's control wrote `value` (the active locale for a localized field). */\n setFieldValue(field: FieldDef, value: unknown): void\n /** A writer that transforms ONE field position (fill / reset from base). */\n editField(field: FieldDef, update: (draft: CmsDocument) => CmsDocument): void\n /** The canvas emitted a new value for its field (node patches, committed at once). */\n setCanvasValue(field: FieldDef, value: unknown): void\n /** The slot alias (a document-level key: a whole-document write at the held revision). */\n setAlias(alias: string | undefined): void\n /** Field boundary events (focus / blur / Enter) — the commit policy's triggers. */\n focused(field: FieldDef): void\n blurred(field: FieldDef): void\n entered(field: FieldDef): void\n /** The forced commit (sync; the persister serialises what follows) / the record model's Save. */\n save(): void\n /** The FORCED FLUSH: commit everything uncommitted and await persistence. */\n flush(): Promise<void>\n /** Adopt a draft from outside (a restored version). */\n replaceDraft(next: CmsDocument): void\n /** Bumped when the canvas must remount from the draft (a restore, a colleague's change). */\n canvasNonce: number\n /** The OTHER sessions present on this document, live by the reader's clock. */\n presence: readonly PresenceEntry[]\n}\n\nexport interface UseDocumentDraftInput {\n source: CollectionViewSource\n collection: CollectionDef\n doc: CmsDocument\n locale: Locale\n lookupManifest: PropFieldLookup\n /** The composition field the canvas edits on this screen, if any. */\n canvasField?: FieldDef\n scheduler?: Scheduler\n visibility?: VisibilitySource\n /** The reader's clock for presence liveness (ISO); `new Date().toISOString()` by default. */\n now?: () => string\n}\n\n/**\n * EC-616 — the base a record save is diffed against: the source's value whenever the draft\n * equals it (the record as opened, or as a save came back), else the previous base (the\n * editor has unsaved changes; a change from another writer meanwhile is not theirs). Pure.\n */\nexport function recordSaveBase(previous: CmsDocument, draft: CmsDocument, doc: CmsDocument): CmsDocument {\n return semanticValueEqual(draft, doc) ? doc : previous\n}\n\nexport function useDocumentDraft(input: UseDocumentDraftInput): DocumentDraft {\n const { source, collection, doc, locale, lookupManifest, canvasField } = input\n const writes = source.writes\n const documentModel = writes.kind === 'document' ? writes : undefined\n const ref: DocumentRef = useMemo(() => ({ collection: doc.collection, id: doc.id }), [doc.collection, doc.id])\n const [draft, setDraftState] = useState<CmsDocument>(doc)\n const draftRef = useRef(draft)\n // EC-616: the record as the editor opened it (or as of their last successful save) — the\n // BASE a record rail diffs a save against, so it writes only the editor's changes. It moves\n // only while the draft equals the source's value (at open, and once a save is reflected\n // back): another writer's change arriving mid-edit never becomes the editor's base.\n const baseRef = useRef<CmsDocument>(doc)\n baseRef.current = recordSaveBase(baseRef.current, draftRef.current, doc)\n const setDraft = useCallback((next: CmsDocument) => {\n draftRef.current = next\n setDraftState(next)\n }, [])\n const scheduler = input.scheduler ?? browserScheduler\n const now = input.now ?? (() => new Date().toISOString())\n const fieldsByName = useMemo(() => new Map(collection.fields.map((f) => [f.name, f])), [collection])\n\n // --- Committing --------------------------------------------------------------------\n const writesRef = useRef(documentModel)\n writesRef.current = documentModel\n const committer = useMemo<DraftCommitter>(\n () =>\n createDraftCommitter({\n policyOf: (name) => {\n const field = fieldsByName.get(name)\n return field ? commitPolicyOf(field) : 'blur-or-idle'\n },\n commit: (positions) => {\n const target = writesRef.current\n if (!target) return\n void target.commit(\n ref,\n positions.map((position) => positionPatch(draftRef.current, position.path)),\n positions.map((position) => position.base),\n )\n },\n baseOf: () => writesRef.current?.revisionOf(ref),\n scheduler,\n }),\n // One committer per open document (the editor is keyed by it).\n [ref],\n )\n\n // --- The canvas's value and its remount ---------------------------------------------\n const canvasPath = canvasField ? fieldPositionPath(collection, canvasField.name, locale) : undefined\n const canvasPathKey = canvasPath ? formatValuePath(canvasPath) : ''\n const canvasValueRef = useRef<unknown>(canvasPath ? readValueAt(draft, canvasPath) : undefined)\n const [canvasNonce, setCanvasNonce] = useState(0)\n const syncCanvas = useCallback(\n (next: CmsDocument) => {\n if (!canvasPath) return\n const value = readValueAt(next, canvasPath)\n if (semanticValueEqual(value, canvasValueRef.current)) return\n canvasValueRef.current = value\n setCanvasNonce((n) => n + 1)\n },\n // The path is keyed by its string form.\n [canvasPathKey],\n )\n // A locale switch points the canvas at another bucket: remount from it.\n const lastCanvasPathKey = useRef(canvasPathKey)\n useEffect(() => {\n if (lastCanvasPathKey.current === canvasPathKey) return\n lastCanvasPathKey.current = canvasPathKey\n canvasValueRef.current = canvasPath ? readValueAt(draftRef.current, canvasPath) : undefined\n setCanvasNonce((n) => n + 1)\n }, [canvasPathKey])\n\n // --- The rebase (document model) -------------------------------------------------------\n const firstDoc = useRef(true)\n useEffect(() => {\n if (firstDoc.current) {\n firstDoc.current = false\n return\n }\n if (!documentModel) return\n const next = rebaseDraft(doc, draftRef.current, committer.uncommitted())\n setDraft(next)\n syncCanvas(next)\n }, [doc])\n\n // --- Writers ----------------------------------------------------------------------------\n const setFieldValue = useCallback(\n (field: FieldDef, value: unknown) => {\n const next = writeField(collection, draftRef.current, field.name, locale, value, { lookupManifest })\n setDraft(next)\n if (documentModel) committer.edited(field.name, fieldPositionPath(collection, field.name, locale))\n },\n [collection, locale, lookupManifest, setDraft, documentModel, committer],\n )\n const editField = useCallback(\n (field: FieldDef, update: (current: CmsDocument) => CmsDocument) => {\n setDraft(update(draftRef.current))\n if (documentModel) committer.edited(field.name, fieldPositionPath(collection, field.name, locale))\n },\n [collection, locale, setDraft, documentModel, committer],\n )\n const setCanvasValue = useCallback(\n (field: FieldDef, value: unknown) => {\n const path = fieldPositionPath(collection, field.name, locale)\n const before = readValueAt(draftRef.current, path)\n const next = writeField(collection, draftRef.current, field.name, locale, value, { lookupManifest })\n const after = readValueAt(next, path)\n setDraft(next)\n canvasValueRef.current = after\n if (!documentModel) return\n // The canvas writer's node patches, keyed by node id (computed here, in its write\n // path, from the canonical values before and after the action — never a document diff).\n const localized = path.length > 1 ? locale : undefined\n void documentModel.commit(ref, compositionPatches(before, after, field.name, localized))\n },\n [collection, locale, lookupManifest, setDraft, documentModel, ref],\n )\n const setAlias = useCallback(\n (alias: string | undefined) => {\n const next = { ...draftRef.current }\n if (alias === undefined) delete next.alias\n else next.alias = alias\n setDraft(next)\n if (!documentModel) return\n committer.commitAll()\n documentModel.replace(next)\n },\n [setDraft, documentModel, committer],\n )\n\n // --- Forced flush ----------------------------------------------------------------------\n const save = useCallback(() => {\n if (documentModel) committer.commitAll()\n else if (writes.kind === 'record') writes.save(draftRef.current, baseRef.current)\n }, [documentModel, committer, writes])\n const flush = useCallback(async () => {\n save()\n if (documentModel) await documentModel.flush(ref)\n }, [save, documentModel, ref])\n\n // Tab hide: commit and flush. Unmount: the same, and leave the document.\n const visibility = input.visibility ?? documentVisibility\n useEffect(() => {\n if (!documentModel) return\n return visibility.onHidden(() => {\n committer.commitAll()\n void documentModel.flush(ref)\n })\n }, [ref])\n useEffect(\n () => () => {\n const target = writesRef.current\n if (!target) return\n committer.commitAll()\n committer.dispose()\n void target.flush(ref)\n target.clearPresence(ref)\n },\n [ref],\n )\n\n // --- Subscription + presence ------------------------------------------------------------\n const [presenceEntries, setPresenceEntries] = useState<readonly PresenceEntry[]>([])\n const [clock, setClock] = useState(now)\n useEffect(() => {\n if (!documentModel) return\n return documentModel.subscribe(ref, setPresenceEntries)\n }, [ref])\n const focusedPathRef = useRef<ValuePath | undefined>(undefined)\n const heartbeat = useCallback(() => {\n writesRef.current?.reportPresence(ref, focusedPathRef.current)\n setClock(now())\n }, [ref])\n useEffect(() => {\n if (!documentModel) return\n heartbeat()\n let handle: unknown\n const tick = () => {\n heartbeat()\n handle = scheduler.setTimeout(tick, PRESENCE_HEARTBEAT_MS)\n }\n handle = scheduler.setTimeout(tick, PRESENCE_HEARTBEAT_MS)\n return () => scheduler.clearTimeout(handle)\n }, [ref])\n const presence = useMemo(\n () =>\n documentModel\n ? livePresence(\n presenceEntries,\n presenceReaderNow(presenceEntries, documentModel.presenceSessionId, clock),\n PRESENCE_TTL_MS,\n ).filter((entry) => entry.sessionId !== documentModel.presenceSessionId)\n : [],\n [presenceEntries, clock, documentModel],\n )\n\n const focused = useCallback(\n (field: FieldDef) => {\n if (!documentModel) return\n committer.focused(field.name)\n focusedPathRef.current = fieldPositionPath(collection, field.name, locale)\n heartbeat()\n },\n [documentModel, committer, collection, locale, heartbeat],\n )\n const blurred = useCallback(\n (field: FieldDef) => {\n if (!documentModel) return\n committer.blurred(field.name)\n focusedPathRef.current = undefined\n heartbeat()\n },\n [documentModel, committer, heartbeat],\n )\n const entered = useCallback(\n (field: FieldDef) => {\n if (documentModel) committer.entered(field.name)\n },\n [documentModel, committer],\n )\n\n const replaceDraft = useCallback(\n (next: CmsDocument) => {\n setDraft(next)\n syncCanvas(next)\n },\n [setDraft, syncCanvas],\n )\n\n const dirty = useMemo(() => !semanticValueEqual(draft, doc), [draft, doc])\n\n return {\n draft,\n dirty,\n explicitSave: writes.kind === 'record',\n setFieldValue,\n editField,\n setCanvasValue,\n setAlias,\n focused,\n blurred,\n entered,\n save,\n flush,\n replaceDraft,\n canvasNonce,\n presence,\n }\n}\n"]}
1
+ {"version":3,"file":"use-document-draft.js","sourceRoot":"","sources":["../../../src/components/cms/use-document-draft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzE,OAAO,EACL,eAAe,EACf,YAAY,GACb,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,UAAU,GACX,MAAM,0BAA0B,CAAA;AAYjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEjE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAGvE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,wGAAwG;AACxG,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAA;AAQ3C,MAAM,CAAC,MAAM,kBAAkB,GAAqB;IAClD,QAAQ,CAAC,QAAQ;QACf,IAAI,OAAO,QAAQ,KAAK,WAAW;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AAG,CAAC,CAAC,CAAA;IACzC,CAAC;IACD,wCAAwC;IACxC,CAAC,QAAQ,EAAE,aAAa,CAAC,CAC1B,CAAA;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAA;IAE1E,OAAO;QACL,KAAK;QACL,KAAK;QACL,YAAY,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ;QACtC,aAAa;QACb,SAAS;QACT,cAAc;QACd,QAAQ;QACR,OAAO;QACP,OAAO;QACP,OAAO;QACP,aAAa;QACb,aAAa;QACb,aAAa;QACb,IAAI;QACJ,KAAK;QACL,YAAY;QACZ,WAAW;QACX,YAAY;QACZ,QAAQ;KACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport {\n PRESENCE_TTL_MS,\n livePresence,\n} from '@elytracms/core/persistence'\nimport type { PresenceEntry } from '@elytracms/core/persistence'\nimport {\n applyDocumentPatches,\n formatValuePath,\n readValueAt,\n semanticValueEqual,\n writeField,\n} from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentPatch,\n DocumentRef,\n FieldDef,\n Locale,\n PropFieldLookup,\n ValuePath,\n} from '@elytracms/core/cms-core'\nimport type { CollectionViewSource } from '../../lib/collection-view/collection-view-source'\nimport { fieldPositionPath } from '../../lib/cms/field-patch'\nimport { compositionPatches } from '../builder/composition-patches'\nimport type { CanvasFieldChange } from '../builder/canvas-rebase'\nimport { commitPolicyOf } from './commit-policy'\nimport type { CommitPolicy } from './commit-policy'\nimport { canvasControl, routeCanvasWrite } from './canvas-commit'\nimport type { CanvasControl, CanvasControlPosition } from './canvas-commit'\nimport { browserScheduler, createDraftCommitter } from './draft-commit'\nimport type { DraftCommitter, Scheduler, UncommittedPosition } from './draft-commit'\n\n/**\n * EC-595 A2 — the detail editor's draft over the revisioned document (and, for the\n * explicit-save rails, over a record).\n *\n * **Document write model** (the CMS): the draft changes per keystroke (live validation\n * reads it); a field's edit is COMMITTED per its control kind's policy\n * ({@link commitPolicyOf} / {@link createDraftCommitter}) as the patch of the position it\n * wrote — never a document. The canvas commits each action's node patches at once\n * (`compositionPatches`); a burst of typing in one of its inspector controls is that\n * control's uncommitted position, committed on its kind's policy like a form field\n * (EC-630, `canvas-commit.ts`). The draft REBASES whenever the session's document changes\n * (a write result, a colleague's change by subscription, a resolved conflict): it is the\n * session's document with this editor's uncommitted positions laid over it — local wins\n * until committed, then the per-path check decides (EC-595 point 7).\n *\n * **Forced flushes** (the ruling: before unmount, tab hide, publish, preview, an AI\n * proposal, duplicate, transfer): {@link DocumentDraft.flush} commits every uncommitted\n * position and awaits the persister. Unmount and tab hide run it here; the editor's\n * publish, duplicate and the AI tap call it.\n *\n * **Thin presence** (Stage A): a heartbeat naming the focused field's path on focus\n * change and every {@link PRESENCE_HEARTBEAT_MS} (under the 30 s TTL), cleared on\n * unmount; the other sessions' live heartbeats arrive with the subscription.\n *\n * **Record write model** (users, redirects, assets, the account): the draft is edited\n * in place and written whole on the editor's Save button (EC-240) — unchanged.\n */\n\n/** The presence heartbeat interval — under {@link PRESENCE_TTL_MS} so a present editor never lapses. */\nexport const PRESENCE_HEARTBEAT_MS = 10_000\n\n/** An injectable visibility source (the tab-hide flush; tests drive it). */\nexport interface VisibilitySource {\n /** Call `onHidden` whenever the tab becomes hidden; returns the unsubscribe. */\n onHidden(onHidden: () => void): () => void\n}\n\nexport const documentVisibility: VisibilitySource = {\n onHidden(onHidden) {\n if (typeof document === 'undefined') return () => {}\n const listener = () => {\n if (document.visibilityState === 'hidden') onHidden()\n }\n document.addEventListener('visibilitychange', listener)\n return () => document.removeEventListener('visibilitychange', listener)\n },\n}\n\n/** The patch that writes the value `doc` holds at `path` (unset when absent). */\nexport function positionPatch(doc: CmsDocument, path: ValuePath): DocumentPatch {\n const value = readValueAt(doc, path)\n return value === undefined ? { op: 'unset', path } : { op: 'set', path, value }\n}\n\n/**\n * THE rebase (pure): the session's document with the editor's uncommitted positions laid\n * over it, values from the editor's current draft.\n */\nexport function rebaseDraft(\n sessionDoc: CmsDocument,\n draft: CmsDocument,\n uncommitted: readonly UncommittedPosition[],\n): CmsDocument {\n if (uncommitted.length === 0) return sessionDoc\n const patches = uncommitted.map((position) => positionPatch(draft, position.path))\n return applyDocumentPatches({ document: sessionDoc, patches, since: [] }).document\n}\n\n/**\n * EC-630 — the canvas's write into the draft (pure). The canvas writer's node patches,\n * keyed by node id, are the canvas's OWN delta: from `base`, the value it last agreed on\n * with the draft, to `value` — never a document diff, and never measured against the\n * draft's CURRENT value (a colleague's change that reached the draft a moment before the\n * edit lifted would read as part of the edit, and its patches would revert it). The draft\n * takes the delta over whatever it holds now (normally `base` itself) and canonicalises the\n * field through the write lens. `undefined` when the canvas changed nothing.\n */\nexport function canvasWrite(input: {\n collection: CollectionDef\n draft: CmsDocument\n field: string\n locale: Locale\n value: unknown\n base: unknown\n lookupManifest: PropFieldLookup\n}): { next: CmsDocument; patches: DocumentPatch[] } | undefined {\n const { collection, draft, field, locale, lookupManifest } = input\n const path = fieldPositionPath(collection, field, locale)\n const localized = path.length > 1 ? locale : undefined\n const patches = compositionPatches(input.base, input.value, field, localized)\n if (patches.length === 0) return undefined\n const applied = applyDocumentPatches({ document: draft, patches, since: [] }).document\n return { next: writeField(collection, draft, field, locale, readValueAt(applied, path), { lookupManifest }), patches }\n}\n\n/**\n * EC-630 — the change of the canvas field made UNDERNEATH the canvas when the draft\n * rebased from `previous` to `next` (pure), numbered after `last`; `undefined` when the\n * field did not move. The canvas's own edits are in both values (the session's view holds\n * every patch it committed, the draft overlays every position it has not), so the change\n * is someone else's: a colleague's patch, a write's canonical row, a resolved conflict.\n */\nexport function canvasFieldChange(\n previous: CmsDocument,\n next: CmsDocument,\n path: ValuePath,\n last: CanvasFieldChange | undefined,\n): CanvasFieldChange | undefined {\n const from = readValueAt(previous, path)\n const to = readValueAt(next, path)\n return semanticValueEqual(from, to) ? undefined : { from, to, seq: (last?.seq ?? 0) + 1 }\n}\n\n/**\n * The reader's \"now\" for presence liveness: THIS session's own latest heartbeat `at`\n * (written by the same store clock as everyone else's — the playground store runs a\n * deterministic sequential clock, Convex the writers' wall clocks), falling back to the\n * injected clock before the first heartbeat lands. Comparing others' `at` against a\n * different time base would call every colleague stale (measured live in the\n * playground: the store's clock is months behind the browser's).\n */\nexport function presenceReaderNow(\n entries: readonly PresenceEntry[],\n sessionId: string,\n fallback: string,\n): string {\n const own = entries.filter((entry) => entry.sessionId === sessionId).map((entry) => entry.at)\n return own.length > 0 ? own.sort().at(-1)! : fallback\n}\n\nexport interface DocumentDraft {\n draft: CmsDocument\n /** Uncommitted (document model) / unsaved (record model) edits exist. */\n dirty: boolean\n /** The record model: the editor renders a Save button + navigation guard. */\n explicitSave: boolean\n /** A field's control wrote `value` (the active locale for a localized field). */\n setFieldValue(field: FieldDef, value: unknown): void\n /** A writer that transforms ONE field position (fill / reset from base). */\n editField(field: FieldDef, update: (draft: CmsDocument) => CmsDocument): void\n /**\n * The canvas emitted a new value for its field (node patches, committed at once). `base`\n * is the value the canvas last agreed on with the draft: the canvas writer's delta is\n * `base` → `value`, applied over whatever the draft holds now (EC-630 — a change that\n * landed underneath meanwhile is never reverted by the canvas's own write).\n */\n setCanvasValue(field: FieldDef, value: unknown, base: unknown): void\n /** The slot alias (a document-level key: a whole-document write at the held revision). */\n setAlias(alias: string | undefined): void\n /** Field boundary events (focus / blur / Enter) — the commit policy's triggers. */\n focused(field: FieldDef): void\n blurred(field: FieldDef): void\n entered(field: FieldDef): void\n /**\n * EC-630 — the canvas inspector's boundary events: a control writing `position` of the\n * canvas field `field`, committing on `policy` (THE declaration for its kind). A burst of\n * typing in it is its uncommitted position until blur / Enter / the idle pause.\n */\n canvasFocused(field: FieldDef, position: CanvasControlPosition, policy: CommitPolicy): void\n canvasBlurred(field: FieldDef, position: CanvasControlPosition): void\n canvasEntered(field: FieldDef, position: CanvasControlPosition): void\n /** The forced commit (sync; the persister serialises what follows) / the record model's Save. */\n save(): void\n /** The FORCED FLUSH: commit everything uncommitted and await persistence. */\n flush(): Promise<void>\n /** Adopt a draft from outside (a restored version). */\n replaceDraft(next: CmsDocument): void\n /**\n * Bumped when the canvas must remount from the draft: a restored version replaced the\n * document, or a locale switch pointed the canvas at another bucket. (A change made\n * underneath the canvas is NOT a remount — {@link canvasChange}.)\n */\n canvasNonce: number\n /**\n * EC-630 — the latest change of the canvas field's value made UNDERNEATH the canvas (a\n * colleague's patch by subscription, a write's canonical row, a resolved conflict): the\n * draft's value before and after it. The canvas REBASES onto it — the change lands, its\n * undo history and selection survive — where it used to remount and lose both.\n */\n canvasChange: CanvasFieldChange | undefined\n /** The OTHER sessions present on this document, live by the reader's clock. */\n presence: readonly PresenceEntry[]\n}\n\nexport interface UseDocumentDraftInput {\n source: CollectionViewSource\n collection: CollectionDef\n doc: CmsDocument\n locale: Locale\n lookupManifest: PropFieldLookup\n /** The composition field the canvas edits on this screen, if any. */\n canvasField?: FieldDef\n scheduler?: Scheduler\n visibility?: VisibilitySource\n /** The reader's clock for presence liveness (ISO); `new Date().toISOString()` by default. */\n now?: () => string\n}\n\n/**\n * EC-616 — the base a record save is diffed against: the source's value whenever the draft\n * equals it (the record as opened, or as a save came back), else the previous base (the\n * editor has unsaved changes; a change from another writer meanwhile is not theirs). Pure.\n */\nexport function recordSaveBase(previous: CmsDocument, draft: CmsDocument, doc: CmsDocument): CmsDocument {\n return semanticValueEqual(draft, doc) ? doc : previous\n}\n\nexport function useDocumentDraft(input: UseDocumentDraftInput): DocumentDraft {\n const { source, collection, doc, locale, lookupManifest, canvasField } = input\n const writes = source.writes\n const documentModel = writes.kind === 'document' ? writes : undefined\n const ref: DocumentRef = useMemo(() => ({ collection: doc.collection, id: doc.id }), [doc.collection, doc.id])\n const [draft, setDraftState] = useState<CmsDocument>(doc)\n const draftRef = useRef(draft)\n // EC-616: the record as the editor opened it (or as of their last successful save) — the\n // BASE a record rail diffs a save against, so it writes only the editor's changes. It moves\n // only while the draft equals the source's value (at open, and once a save is reflected\n // back): another writer's change arriving mid-edit never becomes the editor's base.\n const baseRef = useRef<CmsDocument>(doc)\n baseRef.current = recordSaveBase(baseRef.current, draftRef.current, doc)\n const setDraft = useCallback((next: CmsDocument) => {\n draftRef.current = next\n setDraftState(next)\n }, [])\n const scheduler = input.scheduler ?? browserScheduler\n const now = input.now ?? (() => new Date().toISOString())\n const fieldsByName = useMemo(() => new Map(collection.fields.map((f) => [f.name, f])), [collection])\n\n // --- Committing --------------------------------------------------------------------\n const writesRef = useRef(documentModel)\n writesRef.current = documentModel\n /** EC-630 — the canvas inspector controls that took focus, by committer key (their position + policy). */\n const canvasControls = useRef(new Map<string, CanvasControl>())\n const committer = useMemo<DraftCommitter>(\n () =>\n createDraftCommitter({\n policyOf: (name) => {\n const field = fieldsByName.get(name)\n if (field) return commitPolicyOf(field)\n return canvasControls.current.get(name)?.policy ?? 'blur-or-idle'\n },\n commit: (positions) => {\n const target = writesRef.current\n if (!target) return\n void target.commit(\n ref,\n positions.map((position) => positionPatch(draftRef.current, position.path)),\n positions.map((position) => position.base),\n )\n },\n baseOf: () => writesRef.current?.revisionOf(ref),\n scheduler,\n }),\n // One committer per open document (the editor is keyed by it).\n [ref],\n )\n\n // --- The canvas's value: its remount and its rebase ------------------------------------\n const canvasPath = canvasField ? fieldPositionPath(collection, canvasField.name, locale) : undefined\n const canvasPathKey = canvasPath ? formatValuePath(canvasPath) : ''\n const [canvasNonce, setCanvasNonce] = useState(0)\n const [canvasChange, setCanvasChange] = useState<CanvasFieldChange | undefined>(undefined)\n // A locale switch points the canvas at another bucket: remount from it.\n const lastCanvasPathKey = useRef(canvasPathKey)\n useEffect(() => {\n if (lastCanvasPathKey.current === canvasPathKey) return\n lastCanvasPathKey.current = canvasPathKey\n setCanvasNonce((n) => n + 1)\n }, [canvasPathKey])\n\n // --- The rebase (document model) -------------------------------------------------------\n const firstDoc = useRef(true)\n useEffect(() => {\n if (firstDoc.current) {\n firstDoc.current = false\n return\n }\n if (!documentModel) return\n const previous = draftRef.current\n const next = rebaseDraft(doc, previous, committer.uncommitted())\n setDraft(next)\n // EC-630: the canvas field moved underneath the canvas — the canvas rebases onto the\n // change (its own edits are in both values: the session's view holds every patch it\n // committed, and the draft overlays every position it has not).\n if (!canvasPath) return\n setCanvasChange((last) => canvasFieldChange(previous, next, canvasPath, last) ?? last)\n }, [doc])\n\n // --- Writers ----------------------------------------------------------------------------\n const setFieldValue = useCallback(\n (field: FieldDef, value: unknown) => {\n const next = writeField(collection, draftRef.current, field.name, locale, value, { lookupManifest })\n setDraft(next)\n if (documentModel) committer.edited(field.name, fieldPositionPath(collection, field.name, locale))\n },\n [collection, locale, lookupManifest, setDraft, documentModel, committer],\n )\n const editField = useCallback(\n (field: FieldDef, update: (current: CmsDocument) => CmsDocument) => {\n setDraft(update(draftRef.current))\n if (documentModel) committer.edited(field.name, fieldPositionPath(collection, field.name, locale))\n },\n [collection, locale, setDraft, documentModel, committer],\n )\n const setCanvasValue = useCallback(\n (field: FieldDef, value: unknown, base: unknown) => {\n const write = canvasWrite({ collection, draft: draftRef.current, field: field.name, locale, value, base, lookupManifest })\n if (!write) return\n setDraft(write.next)\n if (!documentModel) return\n // EC-630: a burst of typing in a focused inspector control is that control's\n // uncommitted position (its policy commits it); a canvas action commits now.\n const focus = committer.focusedField()\n routeCanvasWrite({\n patches: write.patches,\n focused: focus === undefined ? undefined : canvasControls.current.get(focus),\n committer,\n commitNow: (patches) => void documentModel.commit(ref, patches),\n })\n },\n [collection, locale, lookupManifest, setDraft, documentModel, ref, committer],\n )\n const setAlias = useCallback(\n (alias: string | undefined) => {\n const next = { ...draftRef.current }\n if (alias === undefined) delete next.alias\n else next.alias = alias\n setDraft(next)\n if (!documentModel) return\n committer.commitAll()\n documentModel.replace(next)\n },\n [setDraft, documentModel, committer],\n )\n\n // --- Forced flush ----------------------------------------------------------------------\n const save = useCallback(() => {\n if (documentModel) committer.commitAll()\n else if (writes.kind === 'record') writes.save(draftRef.current, baseRef.current)\n }, [documentModel, committer, writes])\n const flush = useCallback(async () => {\n save()\n if (documentModel) await documentModel.flush(ref)\n }, [save, documentModel, ref])\n\n // Tab hide: commit and flush. Unmount: the same, and leave the document.\n const visibility = input.visibility ?? documentVisibility\n useEffect(() => {\n if (!documentModel) return\n return visibility.onHidden(() => {\n committer.commitAll()\n void documentModel.flush(ref)\n })\n }, [ref])\n useEffect(\n () => () => {\n const target = writesRef.current\n if (!target) return\n committer.commitAll()\n committer.dispose()\n void target.flush(ref)\n target.clearPresence(ref)\n },\n [ref],\n )\n\n // --- Subscription + presence ------------------------------------------------------------\n const [presenceEntries, setPresenceEntries] = useState<readonly PresenceEntry[]>([])\n const [clock, setClock] = useState(now)\n useEffect(() => {\n if (!documentModel) return\n return documentModel.subscribe(ref, setPresenceEntries)\n }, [ref])\n const focusedPathRef = useRef<ValuePath | undefined>(undefined)\n const heartbeat = useCallback(() => {\n writesRef.current?.reportPresence(ref, focusedPathRef.current)\n setClock(now())\n }, [ref])\n useEffect(() => {\n if (!documentModel) return\n heartbeat()\n let handle: unknown\n const tick = () => {\n heartbeat()\n handle = scheduler.setTimeout(tick, PRESENCE_HEARTBEAT_MS)\n }\n handle = scheduler.setTimeout(tick, PRESENCE_HEARTBEAT_MS)\n return () => scheduler.clearTimeout(handle)\n }, [ref])\n const presence = useMemo(\n () =>\n documentModel\n ? livePresence(\n presenceEntries,\n presenceReaderNow(presenceEntries, documentModel.presenceSessionId, clock),\n PRESENCE_TTL_MS,\n ).filter((entry) => entry.sessionId !== documentModel.presenceSessionId)\n : [],\n [presenceEntries, clock, documentModel],\n )\n\n const focused = useCallback(\n (field: FieldDef) => {\n if (!documentModel) return\n committer.focused(field.name)\n focusedPathRef.current = fieldPositionPath(collection, field.name, locale)\n heartbeat()\n },\n [documentModel, committer, collection, locale, heartbeat],\n )\n const blurred = useCallback(\n (field: FieldDef) => {\n if (!documentModel) return\n committer.blurred(field.name)\n focusedPathRef.current = undefined\n heartbeat()\n },\n [documentModel, committer, heartbeat],\n )\n const entered = useCallback(\n (field: FieldDef) => {\n if (documentModel) committer.entered(field.name)\n },\n [documentModel, committer],\n )\n\n // EC-630 — the canvas inspector's commit boundary: a control at a position of the canvas\n // field gained focus, lost it, or saw Enter. Its policy is THE declaration's for its kind.\n const canvasControlOf = useCallback(\n (field: FieldDef, position: CanvasControlPosition, policy: CommitPolicy) =>\n canvasControl(fieldPositionPath(collection, field.name, locale), position, policy),\n [collection, locale],\n )\n const canvasFocused = useCallback(\n (field: FieldDef, position: CanvasControlPosition, policy: CommitPolicy) => {\n if (!documentModel) return\n const control = canvasControlOf(field, position, policy)\n canvasControls.current.set(control.key, control)\n committer.focused(control.key)\n focusedPathRef.current = control.path\n heartbeat()\n },\n [documentModel, committer, canvasControlOf, heartbeat],\n )\n const canvasBlurred = useCallback(\n (field: FieldDef, position: CanvasControlPosition) => {\n if (!documentModel) return\n const key = canvasControlOf(field, position, 'change').key\n committer.blurred(key)\n canvasControls.current.delete(key)\n focusedPathRef.current = undefined\n heartbeat()\n },\n [documentModel, committer, canvasControlOf, heartbeat],\n )\n const canvasEntered = useCallback(\n (field: FieldDef, position: CanvasControlPosition) => {\n if (documentModel) committer.entered(canvasControlOf(field, position, 'change').key)\n },\n [documentModel, committer, canvasControlOf],\n )\n\n const replaceDraft = useCallback(\n (next: CmsDocument) => {\n // A restored version replaces the document: when it moved the canvas field, the\n // canvas remounts from it (its history belonged to the replaced value).\n const moved = canvasPath && !semanticValueEqual(readValueAt(draftRef.current, canvasPath), readValueAt(next, canvasPath))\n setDraft(next)\n if (moved) setCanvasNonce((n) => n + 1)\n },\n // The path is keyed by its string form.\n [setDraft, canvasPathKey],\n )\n\n const dirty = useMemo(() => !semanticValueEqual(draft, doc), [draft, doc])\n\n return {\n draft,\n dirty,\n explicitSave: writes.kind === 'record',\n setFieldValue,\n editField,\n setCanvasValue,\n setAlias,\n focused,\n blurred,\n entered,\n canvasFocused,\n canvasBlurred,\n canvasEntered,\n save,\n flush,\n replaceDraft,\n canvasNonce,\n canvasChange,\n presence,\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { CmsDocument, CollectionDef, DocumentUrl, Locale, LocaleConfig, RouteRecord } from '@elytracms/core/cms-core';
2
2
  import type { CollectionViewSource } from '../../lib/collection-view/collection-view-source.js';
3
+ import type { ReadState } from '../../lib/query/index.js';
3
4
  import type { IssueSeverity } from '../issue-severity.js';
4
5
  /**
5
6
  * The header's live-link descriptor: an `href` (open live) + a title, or a
@@ -28,11 +29,15 @@ export interface HeaderLive {
28
29
  * consumed, not re-derived: the row shows the same `warning` the Issues pane shows
29
30
  * for it (`document-reachability.ts`), because a link titled "Open /de" a few
30
31
  * pixels from that warning is the stronger signal, and it is the wrong one.
32
+ *
33
+ * EC-628 — `pool` is the published pool's read state. A FAILED read is an `error`
34
+ * finding with the pool's sentence, whatever the document's own state: what is live
35
+ * cannot be known, and the old empty pool answered with a lifecycle hint instead.
31
36
  */
32
37
  export declare function resolveHeaderLive(input: {
33
38
  routableCollection: boolean;
34
39
  liveUrl: Pick<DocumentUrl, 'href' | 'path' | 'addressable'> | undefined;
35
- loading: boolean;
40
+ pool: ReadState<unknown>;
36
41
  published: boolean;
37
42
  }): HeaderLive | undefined;
38
43
  /**
@@ -17,10 +17,16 @@ import { usePublishedDocuments } from '../../lib/cms/published-documents.js';
17
17
  * consumed, not re-derived: the row shows the same `warning` the Issues pane shows
18
18
  * for it (`document-reachability.ts`), because a link titled "Open /de" a few
19
19
  * pixels from that warning is the stronger signal, and it is the wrong one.
20
+ *
21
+ * EC-628 — `pool` is the published pool's read state. A FAILED read is an `error`
22
+ * finding with the pool's sentence, whatever the document's own state: what is live
23
+ * cannot be known, and the old empty pool answered with a lifecycle hint instead.
20
24
  */
21
25
  export function resolveHeaderLive(input) {
22
26
  if (!input.routableCollection)
23
27
  return undefined;
28
+ if (input.pool.status === 'error')
29
+ return { title: input.pool.message, severity: 'error' };
24
30
  if (input.liveUrl && !input.liveUrl.addressable) {
25
31
  return { title: translate('cms.issue.unaddressable-url'), severity: 'warning' };
26
32
  }
@@ -28,7 +34,7 @@ export function resolveHeaderLive(input) {
28
34
  return { href: input.liveUrl.href, title: translate('cms.editor.openLiveUrl', { path: input.liveUrl.path }) };
29
35
  }
30
36
  return {
31
- title: input.loading
37
+ title: input.pool.status === 'loading'
32
38
  ? translate('cms.editor.loadingLiveUrl')
33
39
  : !input.published
34
40
  ? translate('cms.editor.publishToViewLive')
@@ -64,7 +70,9 @@ export function useLiveUrl(input) {
64
70
  const { source, collection, doc, locale, published, routableCollection } = input;
65
71
  const publishedDocs = usePublishedDocuments(source.projectId, collection.id);
66
72
  const liveUrl = useMemo(() => {
67
- const publishedDoc = publishedDocs.byId.get(doc.id);
73
+ if (publishedDocs.status !== 'ready')
74
+ return undefined;
75
+ const publishedDoc = publishedDocs.value.get(doc.id);
68
76
  if (!publishedDoc)
69
77
  return undefined;
70
78
  return resolveDocumentLiveUrl({
@@ -73,16 +81,11 @@ export function useLiveUrl(input) {
73
81
  frontendUrl: resolveDeploymentFrontendUrl(),
74
82
  collection,
75
83
  doc: publishedDoc,
76
- siblings: [...publishedDocs.byId.values()],
84
+ siblings: [...publishedDocs.value.values()],
77
85
  locale,
78
86
  });
79
87
  }, [publishedDocs, collection, doc.id, locale, source.localeConfig]);
80
- const headerLive = resolveHeaderLive({
81
- routableCollection,
82
- liveUrl,
83
- loading: publishedDocs.status === 'loading',
84
- published,
85
- });
88
+ const headerLive = resolveHeaderLive({ routableCollection, liveUrl, pool: publishedDocs, published });
86
89
  return { headerLive };
87
90
  }
88
91
  //# sourceMappingURL=use-live-url.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-live-url.js","sourceRoot":"","sources":["../../../src/components/cms/use-live-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAA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S;QAC3C,SAAS;KACV,CAAC,CAAA;IACF,OAAO,EAAE,UAAU,EAAE,CAAA;AACvB,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport { createRouter } from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentUrl,\n Locale,\n LocaleConfig,\n RouteRecord,\n} from '@elytracms/core/cms-core'\nimport type { CollectionViewSource } from '../../lib/collection-view/collection-view-source'\nimport { translate } from '../../lib/i18n'\nimport { resolveDeploymentFrontendUrl, resolveDeploymentRoutes } from '../../lib/workspace'\nimport { usePublishedDocuments } from '../../lib/cms/published-documents'\nimport type { IssueSeverity } from '../issue-severity'\n\n/**\n * The header's live-link descriptor: an `href` (open live) + a title, or a\n * reason-only title while it isn't openable (loading / publish-first / no\n * frontendUrl). `severity` is set when the reason is a FINDING about the URL\n * rather than a lifecycle state — the renderer then shows the shared issue glyph\n * (EC-507) in place of the muted open-live icon, so the row and the Issues pane\n * say the same thing (EC-518).\n */\nexport interface HeaderLive {\n href?: string\n title: string\n severity?: IssueSeverity\n}\n\n/**\n * 0.0.42 (round 3) — the header composed-URL row's open-live affordance, as a pure\n * decision. Only a routable collection shows the row; its leaf opens the live page\n * when the doc is published AND a frontendUrl is set (an absolute `href`),\n * otherwise it is a muted icon whose tooltip explains WHY (still loading, publish\n * first, or set the frontendUrl). The draft-derived path itself updates as you\n * type — only the OPEN-live action is published-gated, preserving draft/live.\n *\n * EC-518 — a URL the engine has computed as NOT `addressable` (EC-492: the host\n * re-derives a different `{locale, path}` pair from it, so no request reaches the\n * document) never becomes an `href`, frontendUrl or not. The engine's verdict is\n * consumed, not re-derived: the row shows the same `warning` the Issues pane shows\n * for it (`document-reachability.ts`), because a link titled \"Open /de\" a few\n * pixels from that warning is the stronger signal, and it is the wrong one.\n */\nexport function resolveHeaderLive(input: {\n routableCollection: boolean\n liveUrl: Pick<DocumentUrl, 'href' | 'path' | 'addressable'> | undefined\n loading: boolean\n published: boolean\n}): HeaderLive | undefined {\n if (!input.routableCollection) return undefined\n if (input.liveUrl && !input.liveUrl.addressable) {\n return { title: translate('cms.issue.unaddressable-url'), severity: 'warning' }\n }\n if (input.liveUrl?.href) {\n return { href: input.liveUrl.href, title: translate('cms.editor.openLiveUrl', { path: input.liveUrl.path }) }\n }\n return {\n title: input.loading\n ? translate('cms.editor.loadingLiveUrl')\n : !input.published\n ? translate('cms.editor.publishToViewLive')\n : translate('cms.editor.setFrontendUrlHint'),\n }\n}\n\n/**\n * EC-590 — derive a published document's live URL through THE router\n * (`createRouter(...).urlFor`), the same reverse direction delivery's links and sitemap\n * read, in the one precedence order — so the studio's live link can no longer advertise a\n * URL the site 404s (IDENTITY M4). The project's routes as declared: the engine derives no\n * home route any more (the former `mergeRouteRecords` + `fallbackHomeRoutes` merge went\n * with it). Pure (no React), so it is unit-tested directly rather than through the hook.\n */\nexport function resolveDocumentLiveUrl(input: {\n routes: readonly RouteRecord[]\n localeConfig: LocaleConfig\n frontendUrl: string | undefined\n collection: CollectionDef\n doc: CmsDocument\n siblings: readonly CmsDocument[]\n locale: Locale\n}): DocumentUrl | undefined {\n return createRouter({\n routes: input.routes,\n collections: [input.collection],\n locales: input.localeConfig,\n }).urlFor(input.doc, {\n siblings: input.siblings,\n locale: input.locale,\n ...(input.frontendUrl !== undefined ? { frontendUrl: input.frontendUrl } : {}),\n })\n}\n\n/**\n * EC-205 / EC-216 — the LIVE URL derives strictly from PUBLISHED data (the pinned\n * published snapshot + its published ancestors), never the draft, so an unpublished\n * slug/parent edit can't leak into the live URL. Resolves the header's live-link\n * descriptor for the composed-URL row; `undefined` for a non-routable collection.\n */\nexport function useLiveUrl(input: {\n source: CollectionViewSource\n collection: CollectionDef\n doc: CmsDocument\n locale: Locale\n published: boolean\n routableCollection: boolean\n}): { headerLive: HeaderLive | undefined } {\n const { source, collection, doc, locale, published, routableCollection } = input\n const publishedDocs = usePublishedDocuments(source.projectId, collection.id)\n const liveUrl = useMemo(() => {\n const publishedDoc = publishedDocs.byId.get(doc.id)\n if (!publishedDoc) return undefined\n return resolveDocumentLiveUrl({\n routes: resolveDeploymentRoutes(),\n localeConfig: source.localeConfig,\n frontendUrl: resolveDeploymentFrontendUrl(),\n collection,\n doc: publishedDoc,\n siblings: [...publishedDocs.byId.values()],\n locale,\n })\n }, [publishedDocs, collection, doc.id, locale, source.localeConfig])\n\n const headerLive = resolveHeaderLive({\n routableCollection,\n liveUrl,\n loading: publishedDocs.status === 'loading',\n published,\n })\n return { headerLive }\n}\n"]}
1
+ {"version":3,"file":"use-live-url.js","sourceRoot":"","sources":["../../../src/components/cms/use-live-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAUvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAC3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAA;AAkBzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAKjC;IACC,IAAI,CAAC,KAAK,CAAC,kBAAkB;QAAE,OAAO,SAAS,CAAA;IAC/C,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,OAAO;QAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;IAC1F,IAAI,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAChD,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,6BAA6B,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAA;IACjF,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC;QACxB,OAAO,EAAE,IAAI,EAAE,KAAK,CA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B,IAAI,aAAa,CAAC,MAAM,KAAK,OAAO;YAAE,OAAO,SAAS,CAAA;QACtD,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACpD,IAAI,CAAC,YAAY;YAAE,OAAO,SAAS,CAAA;QACnC,OAAO,sBAAsB,CAAC;YAC5B,MAAM,EAAE,uBAAuB,EAAE;YACjC,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,WAAW,EAAE,4BAA4B,EAAE;YAC3C,UAAU;YACV,GAAG,EAAE,YAAY;YACjB,QAAQ,EAAE,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC3C,MAAM;SACP,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,aAAa,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;IAEpE,MAAM,UAAU,GAAG,iBAAiB,CAAC,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAA;IACrG,OAAO,EAAE,UAAU,EAAE,CAAA;AACvB,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport { createRouter } from '@elytracms/core/cms-core'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentUrl,\n Locale,\n LocaleConfig,\n RouteRecord,\n} from '@elytracms/core/cms-core'\nimport type { CollectionViewSource } from '../../lib/collection-view/collection-view-source'\nimport { translate } from '../../lib/i18n'\nimport { resolveDeploymentFrontendUrl, resolveDeploymentRoutes } from '../../lib/workspace'\nimport { usePublishedDocuments } from '../../lib/cms/published-documents'\nimport type { ReadState } from '../../lib/query'\nimport type { IssueSeverity } from '../issue-severity'\n\n/**\n * The header's live-link descriptor: an `href` (open live) + a title, or a\n * reason-only title while it isn't openable (loading / publish-first / no\n * frontendUrl). `severity` is set when the reason is a FINDING about the URL\n * rather than a lifecycle state — the renderer then shows the shared issue glyph\n * (EC-507) in place of the muted open-live icon, so the row and the Issues pane\n * say the same thing (EC-518).\n */\nexport interface HeaderLive {\n href?: string\n title: string\n severity?: IssueSeverity\n}\n\n/**\n * 0.0.42 (round 3) — the header composed-URL row's open-live affordance, as a pure\n * decision. Only a routable collection shows the row; its leaf opens the live page\n * when the doc is published AND a frontendUrl is set (an absolute `href`),\n * otherwise it is a muted icon whose tooltip explains WHY (still loading, publish\n * first, or set the frontendUrl). The draft-derived path itself updates as you\n * type — only the OPEN-live action is published-gated, preserving draft/live.\n *\n * EC-518 — a URL the engine has computed as NOT `addressable` (EC-492: the host\n * re-derives a different `{locale, path}` pair from it, so no request reaches the\n * document) never becomes an `href`, frontendUrl or not. The engine's verdict is\n * consumed, not re-derived: the row shows the same `warning` the Issues pane shows\n * for it (`document-reachability.ts`), because a link titled \"Open /de\" a few\n * pixels from that warning is the stronger signal, and it is the wrong one.\n *\n * EC-628 — `pool` is the published pool's read state. A FAILED read is an `error`\n * finding with the pool's sentence, whatever the document's own state: what is live\n * cannot be known, and the old empty pool answered with a lifecycle hint instead.\n */\nexport function resolveHeaderLive(input: {\n routableCollection: boolean\n liveUrl: Pick<DocumentUrl, 'href' | 'path' | 'addressable'> | undefined\n pool: ReadState<unknown>\n published: boolean\n}): HeaderLive | undefined {\n if (!input.routableCollection) return undefined\n if (input.pool.status === 'error') return { title: input.pool.message, severity: 'error' }\n if (input.liveUrl && !input.liveUrl.addressable) {\n return { title: translate('cms.issue.unaddressable-url'), severity: 'warning' }\n }\n if (input.liveUrl?.href) {\n return { href: input.liveUrl.href, title: translate('cms.editor.openLiveUrl', { path: input.liveUrl.path }) }\n }\n return {\n title: input.pool.status === 'loading'\n ? translate('cms.editor.loadingLiveUrl')\n : !input.published\n ? translate('cms.editor.publishToViewLive')\n : translate('cms.editor.setFrontendUrlHint'),\n }\n}\n\n/**\n * EC-590 — derive a published document's live URL through THE router\n * (`createRouter(...).urlFor`), the same reverse direction delivery's links and sitemap\n * read, in the one precedence order — so the studio's live link can no longer advertise a\n * URL the site 404s (IDENTITY M4). The project's routes as declared: the engine derives no\n * home route any more (the former `mergeRouteRecords` + `fallbackHomeRoutes` merge went\n * with it). Pure (no React), so it is unit-tested directly rather than through the hook.\n */\nexport function resolveDocumentLiveUrl(input: {\n routes: readonly RouteRecord[]\n localeConfig: LocaleConfig\n frontendUrl: string | undefined\n collection: CollectionDef\n doc: CmsDocument\n siblings: readonly CmsDocument[]\n locale: Locale\n}): DocumentUrl | undefined {\n return createRouter({\n routes: input.routes,\n collections: [input.collection],\n locales: input.localeConfig,\n }).urlFor(input.doc, {\n siblings: input.siblings,\n locale: input.locale,\n ...(input.frontendUrl !== undefined ? { frontendUrl: input.frontendUrl } : {}),\n })\n}\n\n/**\n * EC-205 / EC-216 — the LIVE URL derives strictly from PUBLISHED data (the pinned\n * published snapshot + its published ancestors), never the draft, so an unpublished\n * slug/parent edit can't leak into the live URL. Resolves the header's live-link\n * descriptor for the composed-URL row; `undefined` for a non-routable collection.\n */\nexport function useLiveUrl(input: {\n source: CollectionViewSource\n collection: CollectionDef\n doc: CmsDocument\n locale: Locale\n published: boolean\n routableCollection: boolean\n}): { headerLive: HeaderLive | undefined } {\n const { source, collection, doc, locale, published, routableCollection } = input\n const publishedDocs = usePublishedDocuments(source.projectId, collection.id)\n const liveUrl = useMemo(() => {\n if (publishedDocs.status !== 'ready') return undefined\n const publishedDoc = publishedDocs.value.get(doc.id)\n if (!publishedDoc) return undefined\n return resolveDocumentLiveUrl({\n routes: resolveDeploymentRoutes(),\n localeConfig: source.localeConfig,\n frontendUrl: resolveDeploymentFrontendUrl(),\n collection,\n doc: publishedDoc,\n siblings: [...publishedDocs.value.values()],\n locale,\n })\n }, [publishedDocs, collection, doc.id, locale, source.localeConfig])\n\n const headerLive = resolveHeaderLive({ routableCollection, liveUrl, pool: publishedDocs, published })\n return { headerLive }\n}\n"]}