@elytracms/studio 0.0.80 → 0.0.82
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/contract-parity.test.ts +1 -1
- package/convex/functions.ts +13 -3
- package/convex/http-routes.test.ts +143 -0
- package/convex/http.ts +19 -9
- package/convex/redirect-revalidate.test.ts +130 -0
- package/convex/revalidate.ts +9 -7
- package/convex/schema.ts +0 -19
- package/convex/triggers.ts +33 -3
- package/convex/users.ts +1 -1
- package/dist/components/ai/ai-chat-panel.js +26 -4
- package/dist/components/ai/ai-chat-panel.js.map +1 -1
- package/dist/components/ai/proposal-card.d.ts +27 -0
- package/dist/components/ai/proposal-card.js +31 -3
- package/dist/components/ai/proposal-card.js.map +1 -1
- package/dist/components/ai/proposal-issues.d.ts +55 -0
- package/dist/components/ai/proposal-issues.js +69 -0
- package/dist/components/ai/proposal-issues.js.map +1 -0
- package/dist/components/ai/translate-document-dialog.js +38 -3
- package/dist/components/ai/translate-document-dialog.js.map +1 -1
- package/dist/components/app-views/default-modules.d.ts +141 -44
- package/dist/components/app-views/default-modules.js +229 -65
- package/dist/components/app-views/default-modules.js.map +1 -1
- package/dist/components/app-views/module.d.ts +38 -0
- package/dist/components/app-views/module.js.map +1 -1
- package/dist/components/app-views/sidebar.d.ts +5 -2
- package/dist/components/app-views/sidebar.js +16 -5
- package/dist/components/app-views/sidebar.js.map +1 -1
- package/dist/components/app-views/studio-config.d.ts +28 -1
- package/dist/components/app-views/studio-config.js +1 -1
- package/dist/components/app-views/studio-config.js.map +1 -1
- package/dist/components/builder/canvas-render-context.js +10 -2
- package/dist/components/builder/canvas-render-context.js.map +1 -1
- package/dist/components/builder/clipboard-actions.js +5 -3
- package/dist/components/builder/clipboard-actions.js.map +1 -1
- package/dist/components/builder/reuse-context.js +7 -1
- package/dist/components/builder/reuse-context.js.map +1 -1
- package/dist/components/builder/reuse.d.ts +94 -16
- package/dist/components/builder/reuse.js +201 -19
- package/dist/components/builder/reuse.js.map +1 -1
- package/dist/components/cms/bulk-actions.js +10 -5
- package/dist/components/cms/bulk-actions.js.map +1 -1
- package/dist/components/cms/cell-edit.d.ts +18 -3
- package/dist/components/cms/cell-edit.js +29 -7
- package/dist/components/cms/cell-edit.js.map +1 -1
- package/dist/components/cms/cms-store.d.ts +54 -14
- package/dist/components/cms/cms-store.js +142 -45
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.js +2 -2
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/detail-editor.js +15 -14
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/document-editor-context.d.ts +12 -1
- package/dist/components/cms/document-editor-context.js.map +1 -1
- package/dist/components/cms/field-control.js +22 -8
- package/dist/components/cms/field-control.js.map +1 -1
- package/dist/components/cms/field-renderer.js +8 -1
- package/dist/components/cms/field-renderer.js.map +1 -1
- package/dist/components/cms/gate-validation.d.ts +36 -0
- package/dist/components/cms/gate-validation.js +17 -0
- package/dist/components/cms/gate-validation.js.map +1 -0
- package/dist/components/cms/import-export.js +2 -1
- package/dist/components/cms/import-export.js.map +1 -1
- package/dist/components/cms/inline-field-errors.d.ts +8 -0
- package/dist/components/cms/inline-field-errors.js +52 -0
- package/dist/components/cms/inline-field-errors.js.map +1 -0
- package/dist/components/cms/issues-pane.d.ts +4 -2
- package/dist/components/cms/issues-pane.js +13 -7
- package/dist/components/cms/issues-pane.js.map +1 -1
- package/dist/components/cms/slug-collision-report.d.ts +41 -0
- package/dist/components/cms/slug-collision-report.js +52 -0
- package/dist/components/cms/slug-collision-report.js.map +1 -0
- package/dist/components/components/transfer-dialog.js +10 -12
- package/dist/components/components/transfer-dialog.js.map +1 -1
- package/dist/components/deployment-setup-gate.d.ts +24 -0
- package/dist/components/deployment-setup-gate.js +29 -4
- package/dist/components/deployment-setup-gate.js.map +1 -1
- package/dist/components/issue-severity.d.ts +73 -0
- package/dist/components/issue-severity.js +56 -0
- package/dist/components/issue-severity.js.map +1 -0
- package/dist/components/nav-issues.d.ts +68 -0
- package/dist/components/nav-issues.js +78 -0
- package/dist/components/nav-issues.js.map +1 -0
- package/dist/components/operation-error.js +3 -3
- package/dist/components/operation-error.js.map +1 -1
- package/dist/components/project-list.d.ts +9 -3
- package/dist/components/project-list.js +11 -5
- package/dist/components/project-list.js.map +1 -1
- package/dist/components/project-switcher.d.ts +3 -1
- package/dist/components/project-switcher.js +4 -2
- package/dist/components/project-switcher.js.map +1 -1
- package/dist/components/redirects/redirects-store.d.ts +21 -0
- package/dist/components/redirects/redirects-store.js +17 -4
- package/dist/components/redirects/redirects-store.js.map +1 -1
- package/dist/components/section-nav.js +75 -10
- package/dist/components/section-nav.js.map +1 -1
- package/dist/customization.d.ts +7 -0
- package/dist/customization.js.map +1 -1
- package/dist/lib/ai/apply-content.js +6 -7
- package/dist/lib/ai/apply-content.js.map +1 -1
- package/dist/lib/ai/chat-context.d.ts +32 -26
- package/dist/lib/ai/chat-context.js +81 -9
- package/dist/lib/ai/chat-context.js.map +1 -1
- package/dist/lib/ai/constraints.d.ts +42 -0
- package/dist/lib/ai/constraints.js +259 -0
- package/dist/lib/ai/constraints.js.map +1 -0
- package/dist/lib/ai/index.d.ts +2 -0
- package/dist/lib/ai/index.js +2 -0
- package/dist/lib/ai/index.js.map +1 -1
- package/dist/lib/ai/proposal-validation.d.ts +26 -0
- package/dist/lib/ai/proposal-validation.js +17 -0
- package/dist/lib/ai/proposal-validation.js.map +1 -0
- package/dist/lib/ai/shape.js +60 -13
- package/dist/lib/ai/shape.js.map +1 -1
- package/dist/lib/ai/tools.d.ts +8 -4
- package/dist/lib/ai/tools.js +43 -14
- package/dist/lib/ai/tools.js.map +1 -1
- package/dist/lib/ai/translate-document.d.ts +35 -1
- package/dist/lib/ai/translate-document.js +16 -1
- package/dist/lib/ai/translate-document.js.map +1 -1
- package/dist/lib/ai/types.d.ts +11 -6
- package/dist/lib/ai/types.js.map +1 -1
- package/dist/lib/ai/update-fields.d.ts +8 -6
- package/dist/lib/ai/update-fields.js +9 -22
- package/dist/lib/ai/update-fields.js.map +1 -1
- package/dist/lib/clipboard/paste-issues.d.ts +5 -0
- package/dist/lib/clipboard/paste-issues.js +16 -6
- package/dist/lib/clipboard/paste-issues.js.map +1 -1
- package/dist/lib/cms/document-gate.d.ts +37 -0
- package/dist/lib/cms/document-gate.js +40 -0
- package/dist/lib/cms/document-gate.js.map +1 -0
- package/dist/lib/cms-views/view-model.d.ts +5 -0
- package/dist/lib/cms-views/view-model.js +10 -4
- package/dist/lib/cms-views/view-model.js.map +1 -1
- package/dist/lib/data/collection-content.d.ts +6 -1
- package/dist/lib/data/collection-content.js +51 -15
- package/dist/lib/data/collection-content.js.map +1 -1
- package/dist/lib/i18n/i18n.d.ts +51 -16
- package/dist/lib/i18n/i18n.js +119 -43
- package/dist/lib/i18n/i18n.js.map +1 -1
- package/dist/lib/i18n/index.d.ts +8 -1
- package/dist/lib/i18n/index.js +1 -1
- package/dist/lib/i18n/index.js.map +1 -1
- package/dist/lib/i18n/messages.de.js +200 -0
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +162 -0
- package/dist/lib/i18n/messages.en.js +226 -0
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/i18n/types.d.ts +15 -9
- package/dist/lib/i18n/types.js.map +1 -1
- package/dist/lib/locale/binding-fallback.d.ts +8 -1
- package/dist/lib/locale/binding-fallback.js +8 -1
- package/dist/lib/locale/binding-fallback.js.map +1 -1
- package/dist/lib/locale/locale-store.d.ts +41 -9
- package/dist/lib/locale/locale-store.js +34 -15
- package/dist/lib/locale/locale-store.js.map +1 -1
- package/dist/lib/locale/locale-switcher.d.ts +3 -1
- package/dist/lib/locale/locale-switcher.js +4 -2
- package/dist/lib/locale/locale-switcher.js.map +1 -1
- package/dist/lib/locale/use-studio-locale.d.ts +9 -4
- package/dist/lib/locale/use-studio-locale.js.map +1 -1
- package/dist/lib/operations/studio-operations.js +19 -2
- package/dist/lib/operations/studio-operations.js.map +1 -1
- package/dist/lib/persistence/convex-adapter.d.ts +1 -3
- package/dist/lib/persistence/convex-adapter.js +0 -55
- package/dist/lib/persistence/convex-adapter.js.map +1 -1
- package/dist/lib/persistence/deployment-readiness.js +10 -0
- package/dist/lib/persistence/deployment-readiness.js.map +1 -1
- package/dist/lib/persona/labels.d.ts +85 -9
- package/dist/lib/persona/labels.js +198 -58
- package/dist/lib/persona/labels.js.map +1 -1
- package/dist/lib/routes/route-issues.d.ts +9 -0
- package/dist/lib/routes/route-issues.js +117 -0
- package/dist/lib/routes/route-issues.js.map +1 -0
- package/dist/lib/webhooks/dispatcher.d.ts +5 -2
- package/dist/lib/webhooks/dispatcher.js.map +1 -1
- package/dist/lib/webhooks/tags.js +150 -17
- package/dist/lib/webhooks/tags.js.map +1 -1
- package/dist/lib/workspace/config-issues.d.ts +56 -0
- package/dist/lib/workspace/config-issues.js +72 -0
- package/dist/lib/workspace/config-issues.js.map +1 -0
- package/dist/lib/workspace/index.d.ts +24 -8
- package/dist/lib/workspace/index.js +28 -18
- package/dist/lib/workspace/index.js.map +1 -1
- package/dist/lib/workspace/switcher-source.d.ts +20 -3
- package/dist/lib/workspace/switcher-source.js.map +1 -1
- package/dist/lib/workspace/workspace-source.js +27 -0
- package/dist/lib/workspace/workspace-source.js.map +1 -1
- package/dist/previews/manifest-format.d.ts +13 -6
- package/dist/previews/manifest-format.js +9 -2
- package/dist/previews/manifest-format.js.map +1 -1
- package/dist/router/root.d.ts +36 -1
- package/dist/router/root.js +54 -7
- package/dist/router/root.js.map +1 -1
- package/package.json +2 -2
- package/convex/cliTokens.ts +0 -63
- package/convex/sync.ts +0 -297
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import type { ComponentManifest } from '@elytracms/core/component-registry';
|
|
2
2
|
import type { CollectionDef, DocumentRef } from '@elytracms/core/cms-core';
|
|
3
3
|
import type { ComponentNode } from '@elytracms/core/project-graph';
|
|
4
|
+
import type { CustomizationIssue } from '@elytracms/core/studio-core';
|
|
4
5
|
/**
|
|
5
6
|
* The reuse capability (EC-282): the engine-generic description of how a project
|
|
6
|
-
* models reusable elements
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* models reusable elements. **AD-a (EC-467): reusable elements are SINGULAR per
|
|
8
|
+
* project** — exactly one embed component and exactly one reusable collection.
|
|
9
|
+
* Multiple reuse collections are deliberately not supported, which is why this is
|
|
10
|
+
* one value and never a list.
|
|
9
11
|
*
|
|
10
|
-
* The
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* The capability is normally DERIVED from config (manifests + collections) — no
|
|
13
|
+
* declaration needed, so a consumer that already has a transcluding embed gets the
|
|
14
|
+
* in-canvas gestures for free (the EC-296 "works automatically" pattern). The
|
|
15
|
+
* derivation predicate for a "reusable embed" component: it contributes no slots of
|
|
16
|
+
* its own and has exactly ONE `relation` prop (cardinality `one`) whose target
|
|
17
|
+
* collection holds a `blocks` field — i.e. it embeds a single document and renders
|
|
18
|
+
* that document's composition by transclusion (EC-254/EC-281). For Konditorei that
|
|
19
|
+
* is uniquely `project.Reusable` → `element` → `reusable.content`.
|
|
17
20
|
*
|
|
18
21
|
* EC-462 — the predicate additionally DISQUALIFIES a candidate whose own manifest
|
|
19
22
|
* explicitly declares its relation prop to be something other than an embed
|
|
@@ -34,11 +37,12 @@ import type { ComponentNode } from '@elytracms/core/project-graph';
|
|
|
34
37
|
*
|
|
35
38
|
* Both read only the CANDIDATE manifest's own declarations (never the target's
|
|
36
39
|
* contents) and can only EXCLUDE, so a genuine pure embed (which declares
|
|
37
|
-
* neither) is always kept.
|
|
40
|
+
* neither) is always kept. EC-462's residual — a bare unconditional
|
|
38
41
|
* single-relation display component (e.g. a page teaser) is at rest
|
|
39
|
-
* indistinguishable from a genuine embed — is
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
+
* indistinguishable from a genuine embed — is closed by EC-467's optional
|
|
43
|
+
* {@link StudioReuseConfig} declaration: a project that hits ambiguity declares
|
|
44
|
+
* its way out, and the ambiguity is LOUD instead of silently disabling the
|
|
45
|
+
* gestures. See {@link resolveReuse}.
|
|
42
46
|
*/
|
|
43
47
|
export interface ReuseCapability {
|
|
44
48
|
/** The embed component, e.g. `project.Reusable`. */
|
|
@@ -52,8 +56,82 @@ export interface ReuseCapability {
|
|
|
52
56
|
/** Whether that field holds a single block or a list. */
|
|
53
57
|
contentCardinality: 'one' | 'many';
|
|
54
58
|
}
|
|
55
|
-
/**
|
|
56
|
-
|
|
59
|
+
/**
|
|
60
|
+
* EC-467 (AD-b) — the OPTIONAL studio-config declaration of the reuse embed:
|
|
61
|
+
* `defineStudio({ reuse: { component: 'project.Reusable' } })`. See
|
|
62
|
+
* {@link import('../app-views/studio-config').StudioConfig.reuse} for the
|
|
63
|
+
* consumer-facing contract; this is the shape {@link resolveReuse} consumes.
|
|
64
|
+
*
|
|
65
|
+
* One identifier is enough because the rest DERIVES from it (its single-document
|
|
66
|
+
* relation prop → that prop's target collection → that collection's `blocks`
|
|
67
|
+
* field), and because reusable elements are singular per project (AD-a).
|
|
68
|
+
*/
|
|
69
|
+
export interface StudioReuseConfig {
|
|
70
|
+
/** The embed component's registry id, e.g. `'project.Reusable'`. */
|
|
71
|
+
component: string;
|
|
72
|
+
/**
|
|
73
|
+
* Which relation prop points at the reusable document. Needed ONLY when the
|
|
74
|
+
* declared component legitimately has more than one single-document relation
|
|
75
|
+
* prop — otherwise the sole one is derived.
|
|
76
|
+
*/
|
|
77
|
+
relationProp?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* EC-467 — the resolution of the project's reuse capability: the capability (or
|
|
81
|
+
* `null`), plus the config issues a developer must SEE.
|
|
82
|
+
*
|
|
83
|
+
* The issues ride the EC-236 {@link CustomizationIssue} surface (`point: 'reuse'`),
|
|
84
|
+
* exactly like the sidebar's and the field renderers' — so they render at the
|
|
85
|
+
* studio rail foot on every surface, which is the studio's home for
|
|
86
|
+
* project-CONFIGURATION problems (the document-scoped Issues pane is the wrong
|
|
87
|
+
* home: this is not a content problem in one document).
|
|
88
|
+
*
|
|
89
|
+
* EC-478: each issue carries a `messageRef` (catalog key + identifier values)
|
|
90
|
+
* alongside its prebuilt English, so the rail foot renders it in the active UI
|
|
91
|
+
* locale. This module stays pure — it names a key, it never calls `translate`;
|
|
92
|
+
* `lib/persona/labels.ts` resolves it at the render site. That is what makes the
|
|
93
|
+
* whole list localize together, which is the mixed-language outcome EC-467
|
|
94
|
+
* declined to create by localizing only its own half.
|
|
95
|
+
*/
|
|
96
|
+
export interface ReuseResolution {
|
|
97
|
+
capability: ReuseCapability | null;
|
|
98
|
+
/** Empty whenever the capability is unambiguous — including "this project has none". */
|
|
99
|
+
issues: CustomizationIssue[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The components whose SHAPE makes them plausible reuse embeds (the zero-config
|
|
103
|
+
* heuristic + EC-462's disqualifiers), in manifest order. Exported for the tests
|
|
104
|
+
* and for issue copy; the resolution rule lives in {@link resolveReuse}.
|
|
105
|
+
*/
|
|
106
|
+
export declare function inferredEmbedCandidates(manifests: readonly ComponentManifest[], collections: readonly CollectionDef[]): ReuseCapability[];
|
|
107
|
+
/**
|
|
108
|
+
* Resolve the project's ONE reuse capability (AD-a) plus any config issues —
|
|
109
|
+
* EC-467's full matrix (AD-c):
|
|
110
|
+
*
|
|
111
|
+
* | Declaration | Candidates | Result |
|
|
112
|
+
* | --- | --- | --- |
|
|
113
|
+
* | present, resolves | any | the declared capability, no issue |
|
|
114
|
+
* | present, does not resolve | any | `null` + an ERROR issue (misconfiguration) |
|
|
115
|
+
* | absent | exactly 1 | that candidate, no issue (the zero-config default) |
|
|
116
|
+
* | absent | 2 or more | `null` + a WARNING issue naming every candidate |
|
|
117
|
+
* | absent | 0 | `null`, **no issue** — a project need not use reusable elements |
|
|
118
|
+
*
|
|
119
|
+
* Severity is the honest split: a declaration that cannot resolve is broken
|
|
120
|
+
* config the developer asked for (error); inference ambiguity is nothing broken —
|
|
121
|
+
* the engine declines to guess and asks for one line (warning). Both disable the
|
|
122
|
+
* gestures, and both render identically in the rail's issue list.
|
|
123
|
+
*
|
|
124
|
+
* The zero-candidate row is deliberately silent: crying wolf at every project
|
|
125
|
+
* that has no reusable elements would train developers to ignore the surface.
|
|
126
|
+
*/
|
|
127
|
+
export declare function resolveReuse(manifests: readonly ComponentManifest[], collections: readonly CollectionDef[], declaration?: StudioReuseConfig): ReuseResolution;
|
|
128
|
+
/**
|
|
129
|
+
* The project's reuse capability alone, or `null` when it is absent, ambiguous, or
|
|
130
|
+
* misdeclared — for callers that act on the capability and do not surface config
|
|
131
|
+
* issues themselves (the publish-integrity walk). The issues are surfaced ONCE, by
|
|
132
|
+
* the shell rail; see {@link resolveReuse}.
|
|
133
|
+
*/
|
|
134
|
+
export declare function resolveReuseCapability(manifests: readonly ComponentManifest[], collections: readonly CollectionDef[], declaration?: StudioReuseConfig): ReuseCapability | null;
|
|
57
135
|
/** A slug for `name`, suffixed `-2`/`-3`/… until it is free among `taken`. */
|
|
58
136
|
export declare function uniqueSlug(name: string, taken: ReadonlySet<string>): string;
|
|
59
137
|
/**
|
|
@@ -2,21 +2,72 @@ import { manifestPropFields } from '@elytracms/core/component-registry';
|
|
|
2
2
|
import { readDocumentRef, seedDefaults, titleFieldOf } from '@elytracms/core/cms-core';
|
|
3
3
|
import { isStaticProp } from '@elytracms/core/project-graph';
|
|
4
4
|
import { slugify } from '@elytracms/studio/lib/utils';
|
|
5
|
-
/** The
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
/** The customization point name stamped onto every reuse issue (EC-236 locator). */
|
|
6
|
+
const REUSE_POINT = 'reuse';
|
|
7
|
+
/** Every `relation` prop of a manifest, in declaration order. */
|
|
8
|
+
function relationPropsOf(manifest) {
|
|
9
|
+
const props = [];
|
|
10
|
+
for (const field of manifestPropFields(manifest)) {
|
|
11
|
+
if (field.type !== 'relation')
|
|
12
|
+
continue;
|
|
13
|
+
const hidden = field.form?.hidden;
|
|
14
|
+
props.push({
|
|
15
|
+
name: field.name,
|
|
16
|
+
target: field.target,
|
|
17
|
+
multiple: field.multiple === true,
|
|
18
|
+
conditional: hidden !== undefined && hidden !== false,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return props;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The relation props a DECLARED embed could plausibly transclude through: targeted
|
|
25
|
+
* and cardinality-one. A cardinality-`many` (or targetless) relation is excluded
|
|
26
|
+
* structurally, not heuristically — an embed transcludes exactly one document and
|
|
27
|
+
* {@link makeEmbedNode} writes exactly one `{collection,id}`, which a list-valued
|
|
28
|
+
* or target-less prop cannot hold.
|
|
29
|
+
*/
|
|
30
|
+
function embeddableRelationProps(manifest) {
|
|
31
|
+
return relationPropsOf(manifest).filter((r) => r.target !== undefined && !r.multiple);
|
|
32
|
+
}
|
|
33
|
+
/** The collection's first composition field — what an embed of it transcludes. */
|
|
34
|
+
function blocksFieldOf(collection) {
|
|
35
|
+
const field = collection.fields.find((f) => f.type === 'blocks');
|
|
36
|
+
return field?.type === 'blocks' ? field : undefined;
|
|
17
37
|
}
|
|
18
|
-
/**
|
|
19
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The catalog keys for the reuse config issues (EC-478), in the `builder.reuse.config.*`
|
|
40
|
+
* namespace. Named here so the producer and the catalog-parity test agree on one list.
|
|
41
|
+
*/
|
|
42
|
+
const REUSE_KEYS = {
|
|
43
|
+
unknownComponent: 'builder.reuse.config.unknownComponent',
|
|
44
|
+
noRelationProp: 'builder.reuse.config.noRelationProp',
|
|
45
|
+
unknownRelationProp: 'builder.reuse.config.unknownRelationProp',
|
|
46
|
+
ambiguousRelationProp: 'builder.reuse.config.ambiguousRelationProp',
|
|
47
|
+
unknownCollection: 'builder.reuse.config.unknownCollection',
|
|
48
|
+
noBlocksField: 'builder.reuse.config.noBlocksField',
|
|
49
|
+
ambiguousInference: 'builder.reuse.config.ambiguousInference',
|
|
50
|
+
};
|
|
51
|
+
function reuseIssue(code, severity, message, messageRef, id) {
|
|
52
|
+
return {
|
|
53
|
+
code,
|
|
54
|
+
severity,
|
|
55
|
+
message,
|
|
56
|
+
messageRef,
|
|
57
|
+
point: REUSE_POINT,
|
|
58
|
+
...(id === undefined ? {} : { id }),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** `"a", "b"` — a readable list of prop/component ids for an issue message. */
|
|
62
|
+
function quotedList(names) {
|
|
63
|
+
return names.map((name) => `"${name}"`).join(', ');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The components whose SHAPE makes them plausible reuse embeds (the zero-config
|
|
67
|
+
* heuristic + EC-462's disqualifiers), in manifest order. Exported for the tests
|
|
68
|
+
* and for issue copy; the resolution rule lives in {@link resolveReuse}.
|
|
69
|
+
*/
|
|
70
|
+
export function inferredEmbedCandidates(manifests, collections) {
|
|
20
71
|
const matches = [];
|
|
21
72
|
for (const manifest of manifests) {
|
|
22
73
|
if (manifest.slots.length > 0)
|
|
@@ -25,14 +76,20 @@ export function resolveReuseCapability(manifests, collections) {
|
|
|
25
76
|
// relation prop is the filter source, never an embed pointer.
|
|
26
77
|
if (manifest.listing)
|
|
27
78
|
continue;
|
|
28
|
-
|
|
29
|
-
|
|
79
|
+
// The heuristic requires the relation to be UNAMBIGUOUS within the manifest:
|
|
80
|
+
// exactly ONE relation prop of any kind, which must then be targeted,
|
|
81
|
+
// cardinality-one and unconditional. (Counting all relation props — not just
|
|
82
|
+
// the embeddable ones — is deliberate: a component with a second, list-valued
|
|
83
|
+
// relation is not the single-purpose shape the heuristic is allowed to claim.)
|
|
84
|
+
const relations = relationPropsOf(manifest);
|
|
85
|
+
const relation = relations.length === 1 ? relations[0] : undefined;
|
|
86
|
+
if (!relation || relation.target === undefined || relation.multiple || relation.conditional)
|
|
30
87
|
continue;
|
|
31
88
|
const collection = collections.find((c) => c.id === relation.target);
|
|
32
89
|
if (!collection)
|
|
33
90
|
continue;
|
|
34
|
-
const blocksField = collection
|
|
35
|
-
if (!blocksField
|
|
91
|
+
const blocksField = blocksFieldOf(collection);
|
|
92
|
+
if (!blocksField)
|
|
36
93
|
continue;
|
|
37
94
|
matches.push({
|
|
38
95
|
embedComponentId: manifest.id,
|
|
@@ -42,7 +99,132 @@ export function resolveReuseCapability(manifests, collections) {
|
|
|
42
99
|
contentCardinality: blocksField.multiple === false ? 'one' : 'many',
|
|
43
100
|
});
|
|
44
101
|
}
|
|
45
|
-
return matches
|
|
102
|
+
return matches;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Resolve the DECLARED embed (EC-467, AD-b). An explicit declaration is the
|
|
106
|
+
* developer's authority, so the inference disqualifiers are NOT applied here: a
|
|
107
|
+
* declared component may have slots, may declare `listing`, and its relation prop
|
|
108
|
+
* may be `form.hidden` — those exist to stop the engine GUESSING, not to overrule
|
|
109
|
+
* a stated intent. Only structural impossibilities are issues (see AD-c row 2):
|
|
110
|
+
* an unknown component id, no usable relation prop (or an ambiguous set with no
|
|
111
|
+
* `relationProp`), an undefined target collection, or a target with no `blocks`
|
|
112
|
+
* field — each of which would leave nothing coherent to transclude.
|
|
113
|
+
*/
|
|
114
|
+
function resolveDeclaredReuse(declaration, manifests, collections) {
|
|
115
|
+
const { component, relationProp } = declaration;
|
|
116
|
+
const fail = (message, messageRef) => ({
|
|
117
|
+
capability: null,
|
|
118
|
+
issues: [reuseIssue('invalid-override', 'error', message, messageRef, component)],
|
|
119
|
+
});
|
|
120
|
+
const manifest = manifests.find((m) => m.id === component);
|
|
121
|
+
if (!manifest) {
|
|
122
|
+
return {
|
|
123
|
+
capability: null,
|
|
124
|
+
issues: [
|
|
125
|
+
reuseIssue('unknown-override-target', 'error', `Reusable elements: studio config declares reuse.component "${component}", which is not a registered component. Fix the id, or remove the reuse block to let the studio infer the embed.`, { key: REUSE_KEYS.unknownComponent, vars: { component } }, component),
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const relations = embeddableRelationProps(manifest);
|
|
130
|
+
if (relations.length === 0) {
|
|
131
|
+
return fail(`Reusable elements: the declared embed "${component}" has no single-document relation prop, so it cannot point at a reusable document. An embed needs one relation prop with cardinality one.`, { key: REUSE_KEYS.noRelationProp, vars: { component } });
|
|
132
|
+
}
|
|
133
|
+
const names = relations.map((r) => r.name);
|
|
134
|
+
let relation;
|
|
135
|
+
if (relationProp !== undefined) {
|
|
136
|
+
const named = relations.find((r) => r.name === relationProp);
|
|
137
|
+
if (!named) {
|
|
138
|
+
return fail(`Reusable elements: the declared embed "${component}" has no single-document relation prop named "${relationProp}". Its relation props are: ${quotedList(names)}.`, {
|
|
139
|
+
key: REUSE_KEYS.unknownRelationProp,
|
|
140
|
+
vars: { component, relationProp, props: quotedList(names) },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
relation = named;
|
|
144
|
+
}
|
|
145
|
+
else if (relations.length === 1) {
|
|
146
|
+
relation = relations[0];
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return fail(`Reusable elements: the declared embed "${component}" has ${relations.length} single-document relation props (${quotedList(names)}) — add reuse.relationProp to say which one points at the reusable document.`, {
|
|
150
|
+
key: REUSE_KEYS.ambiguousRelationProp,
|
|
151
|
+
vars: { component, count: relations.length, props: quotedList(names) },
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
const collection = collections.find((c) => c.id === relation.target);
|
|
155
|
+
if (!collection) {
|
|
156
|
+
return fail(`Reusable elements: "${component}.${relation.name}" targets the collection "${relation.target}", which this project does not define.`, {
|
|
157
|
+
key: REUSE_KEYS.unknownCollection,
|
|
158
|
+
vars: { component, relationProp: relation.name, collection: relation.target },
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const blocksField = blocksFieldOf(collection);
|
|
162
|
+
if (!blocksField) {
|
|
163
|
+
return fail(`Reusable elements: the collection "${collection.id}" behind "${component}.${relation.name}" has no blocks (composition) field, so there is nothing for the embed to transclude.`, {
|
|
164
|
+
key: REUSE_KEYS.noBlocksField,
|
|
165
|
+
vars: { component, relationProp: relation.name, collection: collection.id },
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
capability: {
|
|
170
|
+
embedComponentId: manifest.id,
|
|
171
|
+
relationProp: relation.name,
|
|
172
|
+
collectionId: collection.id,
|
|
173
|
+
contentField: blocksField.name,
|
|
174
|
+
contentCardinality: blocksField.multiple === false ? 'one' : 'many',
|
|
175
|
+
},
|
|
176
|
+
issues: [],
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Resolve the project's ONE reuse capability (AD-a) plus any config issues —
|
|
181
|
+
* EC-467's full matrix (AD-c):
|
|
182
|
+
*
|
|
183
|
+
* | Declaration | Candidates | Result |
|
|
184
|
+
* | --- | --- | --- |
|
|
185
|
+
* | present, resolves | any | the declared capability, no issue |
|
|
186
|
+
* | present, does not resolve | any | `null` + an ERROR issue (misconfiguration) |
|
|
187
|
+
* | absent | exactly 1 | that candidate, no issue (the zero-config default) |
|
|
188
|
+
* | absent | 2 or more | `null` + a WARNING issue naming every candidate |
|
|
189
|
+
* | absent | 0 | `null`, **no issue** — a project need not use reusable elements |
|
|
190
|
+
*
|
|
191
|
+
* Severity is the honest split: a declaration that cannot resolve is broken
|
|
192
|
+
* config the developer asked for (error); inference ambiguity is nothing broken —
|
|
193
|
+
* the engine declines to guess and asks for one line (warning). Both disable the
|
|
194
|
+
* gestures, and both render identically in the rail's issue list.
|
|
195
|
+
*
|
|
196
|
+
* The zero-candidate row is deliberately silent: crying wolf at every project
|
|
197
|
+
* that has no reusable elements would train developers to ignore the surface.
|
|
198
|
+
*/
|
|
199
|
+
export function resolveReuse(manifests, collections, declaration) {
|
|
200
|
+
if (declaration)
|
|
201
|
+
return resolveDeclaredReuse(declaration, manifests, collections);
|
|
202
|
+
const candidates = inferredEmbedCandidates(manifests, collections);
|
|
203
|
+
if (candidates.length === 1)
|
|
204
|
+
return { capability: candidates[0], issues: [] };
|
|
205
|
+
if (candidates.length === 0)
|
|
206
|
+
return { capability: null, issues: [] };
|
|
207
|
+
return {
|
|
208
|
+
capability: null,
|
|
209
|
+
issues: [
|
|
210
|
+
reuseIssue('ambiguous-inference', 'warning', `Reusable elements: ${candidates.length} components have the reusable-embed shape (${quotedList(candidates.map((c) => c.embedComponentId))}). A project has exactly one reusable-element embed, so the studio will not guess — declare it in studio.config as reuse: { component: '<id>' }. Until then the reuse gestures are off.`, {
|
|
211
|
+
key: REUSE_KEYS.ambiguousInference,
|
|
212
|
+
vars: {
|
|
213
|
+
count: candidates.length,
|
|
214
|
+
components: quotedList(candidates.map((c) => c.embedComponentId)),
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The project's reuse capability alone, or `null` when it is absent, ambiguous, or
|
|
222
|
+
* misdeclared — for callers that act on the capability and do not surface config
|
|
223
|
+
* issues themselves (the publish-integrity walk). The issues are surfaced ONCE, by
|
|
224
|
+
* the shell rail; see {@link resolveReuse}.
|
|
225
|
+
*/
|
|
226
|
+
export function resolveReuseCapability(manifests, collections, declaration) {
|
|
227
|
+
return resolveReuse(manifests, collections, declaration).capability;
|
|
46
228
|
}
|
|
47
229
|
/** A slug for `name`, suffixed `-2`/`-3`/… until it is free among `taken`. */
|
|
48
230
|
export function uniqueSlug(name, taken) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reuse.js","sourceRoot":"","sources":["../../../src/components/builder/reuse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EAAE,eAAe,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AU,CAAC,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE;aAC/D;SACF;KACF,CAAA;AACH,CAAC","sourcesContent":["import { manifestPropFields } from '@elytracms/core/component-registry'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport { readDocumentRef, seedDefaults, titleFieldOf } from '@elytracms/core/cms-core'\nimport type { CollectionDef, DocumentRef } from '@elytracms/core/cms-core'\nimport { isStaticProp } from '@elytracms/core/project-graph'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { slugify } from '@elytracms/studio/lib/utils'\n\n/**\n * The reuse capability (EC-282): the engine-generic description of how a project\n * models reusable elements, DERIVED from config (manifests + collections) — no\n * new declaration, so a consumer that already has a transcluding embed gets the\n * in-canvas gestures for free (the EC-296 \"works automatically\" pattern).\n *\n * The derivation predicate for a \"reusable embed\" component: it contributes no\n * slots of its own and has exactly ONE `relation` prop (cardinality `one`) whose\n * target collection holds a `blocks` field — i.e. it embeds a single document and\n * renders that document's composition by transclusion (EC-254/EC-281). For\n * Konditorei that is uniquely `project.Reusable` → `element` → `reusable.content`.\n * If zero or more than one component matches, the capability is null and the\n * gestures stay hidden rather than guessing.\n *\n * EC-462 — the predicate additionally DISQUALIFIES a candidate whose own manifest\n * explicitly declares its relation prop to be something other than an embed\n * pointer. The shape test alone proved unsound the moment a relation prop's\n * target collection gains a `blocks` field of its own (a category/page with a\n * canvas — a completely natural content shape): the EC-276 sprint's ProductGrid\n * and the demo's OptionBox were both claimed as \"the embed\", so their ordinary\n * relation picks rendered the reusable-element placeholder, grew Detach/Make-\n * reusable gestures, and fed embed-worded publish-integrity issues. Two\n * explicit-declaration disqualifiers close the observed class:\n *\n * - a manifest with a `listing` declaration is a QUERY host (EC-255) — its\n * relation prop is the query's filter source (`listing.filter.fromProp`),\n * never a transclusion pointer;\n * - a relation prop with `form.hidden` (predicate or `true`) is conditional/\n * auxiliary — EC-394 strips a hidden relation's ref at publish, so it cannot\n * coherently be what the component transcludes.\n *\n * Both read only the CANDIDATE manifest's own declarations (never the target's\n * contents) and can only EXCLUDE, so a genuine pure embed (which declares\n * neither) is always kept. Residual ambiguity — a bare unconditional\n * single-relation display component (e.g. a page teaser) is at rest\n * indistinguishable from a genuine embed — is a data-model finding recorded in\n * `tasks/EC-462-relation-prop-reusable-embed-hijack.md` (resolution needs an\n * explicit manifest-level declaration, an owner decision).\n */\nexport interface ReuseCapability {\n /** The embed component, e.g. `project.Reusable`. */\n embedComponentId: string\n /** The embed's relation prop that points at the reusable document, e.g. `element`. */\n relationProp: string\n /** The collection reusable documents live in, e.g. `reusable`. */\n collectionId: string\n /** The collection's composition field the embed transcludes, e.g. `content`. */\n contentField: string\n /** Whether that field holds a single block or a list. */\n contentCardinality: 'one' | 'many'\n}\n\n/** The lone `relation` prop of a manifest (with its name), or null unless exactly one. */\nfunction soleRelationProp(\n manifest: ComponentManifest,\n): { name: string; target: string; multiple: boolean; conditional: boolean } | null {\n const relations = manifestPropFields(manifest).filter((f) => f.type === 'relation')\n const only = relations.length === 1 ? relations[0] : undefined\n if (!only || only.type !== 'relation' || !only.target) return null\n // EC-462: `form.hidden` present and not literally `false` — a predicate-hidden\n // relation is publish-stripped when hidden (EC-394), an always-hidden one is\n // never editor-pickable; neither can be a transclusion source.\n const hidden = only.form?.hidden\n const conditional = hidden !== undefined && hidden !== false\n return { name: only.name, target: only.target, multiple: only.multiple, conditional }\n}\n\n/** Derive the project's reuse capability, or null when it is absent/ambiguous. */\nexport function resolveReuseCapability(\n manifests: readonly ComponentManifest[],\n collections: readonly CollectionDef[],\n): ReuseCapability | null {\n const matches: ReuseCapability[] = []\n for (const manifest of manifests) {\n if (manifest.slots.length > 0) continue\n // EC-462: a `listing` manifest is a query host by its own declaration — its\n // relation prop is the filter source, never an embed pointer.\n if (manifest.listing) continue\n const relation = soleRelationProp(manifest)\n if (!relation || relation.multiple === true || relation.conditional) continue\n const collection = collections.find((c) => c.id === relation.target)\n if (!collection) continue\n const blocksField = collection.fields.find((f) => f.type === 'blocks')\n if (!blocksField || blocksField.type !== 'blocks') continue\n matches.push({\n embedComponentId: manifest.id,\n relationProp: relation.name,\n collectionId: collection.id,\n contentField: blocksField.name,\n contentCardinality: blocksField.multiple === false ? 'one' : 'many',\n })\n }\n return matches.length === 1 ? matches[0]! : null\n}\n\n/** A slug for `name`, suffixed `-2`/`-3`/… until it is free among `taken`. */\nexport function uniqueSlug(name: string, taken: ReadonlySet<string>): string {\n const base = slugify(name) || 'element'\n let id = base\n for (let n = 2; taken.has(id); n += 1) id = `${base}-${n}`\n return id\n}\n\n/**\n * The values for a new reusable document promoted from `node` (EC-282): seeded\n * defaults, the given `name` on the title field, the node on the content field,\n * and a collision-safe slug on any UNIQUE text field (e.g. Konditorei's\n * `internalId`) so the created document is publish-valid without hardcoding that\n * field's name. Other required fields, if any, are completed by the editor when\n * they open the new reusable.\n */\nexport function buildReusableValues(\n collection: CollectionDef,\n capability: ReuseCapability,\n name: string,\n node: ComponentNode,\n existing: readonly { values?: Record<string, unknown> }[],\n): Record<string, unknown> {\n const values: Record<string, unknown> = { ...seedDefaults(collection) }\n const titleField = titleFieldOf(collection)?.name\n if (titleField) values[titleField] = name\n for (const field of collection.fields) {\n if (\n field.type === 'text' &&\n field.validation?.unique === true &&\n field.name !== titleField &&\n field.name !== capability.contentField\n ) {\n const taken = new Set(\n existing\n .map((d) => d.values?.[field.name])\n .filter((v): v is string => typeof v === 'string'),\n )\n values[field.name] = uniqueSlug(name, taken)\n }\n }\n values[capability.contentField] = capability.contentCardinality === 'one' ? node : [node]\n return values\n}\n\n/**\n * The document a reuse-embed `node` targets (EC-300), or null when `node` is not the\n * embed component or has no static pick yet. Lets the canvas detect a HARD reference\n * whose target doesn't resolve (→ placeholder) without reaching into prop internals.\n */\nexport function reuseEmbedRef(node: ComponentNode, capability: ReuseCapability): DocumentRef | null {\n if (node.componentId !== capability.embedComponentId) return null\n const prop = node.props?.[capability.relationProp]\n const ref = isStaticProp(prop) ? readDocumentRef(prop.value) : undefined\n return ref ?? null\n}\n\n/**\n * Every reuse-embed target ref in a composition `blocks` value, at any depth\n * (EC-300) — the hard references a publish-integrity check walks to find\n * unpublished targets. Recurses slots; order is document order. Duplicates are\n * kept (the caller dedupes by key if needed).\n */\nexport function collectEmbedRefs(\n blocks: readonly ComponentNode[],\n capability: ReuseCapability,\n): DocumentRef[] {\n const refs: DocumentRef[] = []\n const visit = (node: ComponentNode): void => {\n const ref = reuseEmbedRef(node, capability)\n if (ref) refs.push(ref)\n for (const children of Object.values(node.slots ?? {})) for (const child of children) visit(child)\n }\n for (const node of blocks) visit(node)\n return refs\n}\n\n/** The `Reusable` embed node referencing the new document (id minted by the action). */\nexport function makeEmbedNode(capability: ReuseCapability, documentId: string): ComponentNode {\n return {\n id: 'reuse-embed',\n componentId: capability.embedComponentId,\n props: {\n [capability.relationProp]: {\n kind: 'static',\n value: { collection: capability.collectionId, id: documentId },\n },\n },\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"reuse.js","sourceRoot":"","sources":["../../../src/components/builder/reuse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAG5D,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAqGrD,oFAAoF;AACpF,MAAM,WAAW,GAAG,OAAO,CAAA;AAY3B,iEAAiE;AACjE,SAAS,eAAe,CAAC,QAA2B;IAClD,MAAM,KAAK,GAAmB,EAAE,CAAA;IAChC,KAAK,MAAM,KAAK,IAAI,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjD,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,SAAQ;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,MAAM,CAAA;QACjC,KAAK,CAAC,IAAI,CA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QAAQ;gBACd,KAAK,EAAE,EAAE,UAAU,EAAE,UAAU,CAAC,YAAY,EAAE,EAAE,EAAE,UAAU,EAAE;aAC/D;SACF;KACF,CAAA;AACH,CAAC","sourcesContent":["import { manifestPropFields } from '@elytracms/core/component-registry'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport { readDocumentRef, seedDefaults, titleFieldOf } from '@elytracms/core/cms-core'\nimport type { CollectionDef, DocumentRef } from '@elytracms/core/cms-core'\nimport { isStaticProp } from '@elytracms/core/project-graph'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport type { CustomizationIssue, CustomizationMessageRef } from '@elytracms/core/studio-core'\nimport { slugify } from '@elytracms/studio/lib/utils'\n\n/**\n * The reuse capability (EC-282): the engine-generic description of how a project\n * models reusable elements. **AD-a (EC-467): reusable elements are SINGULAR per\n * project** — exactly one embed component and exactly one reusable collection.\n * Multiple reuse collections are deliberately not supported, which is why this is\n * one value and never a list.\n *\n * The capability is normally DERIVED from config (manifests + collections) — no\n * declaration needed, so a consumer that already has a transcluding embed gets the\n * in-canvas gestures for free (the EC-296 \"works automatically\" pattern). The\n * derivation predicate for a \"reusable embed\" component: it contributes no slots of\n * its own and has exactly ONE `relation` prop (cardinality `one`) whose target\n * collection holds a `blocks` field — i.e. it embeds a single document and renders\n * that document's composition by transclusion (EC-254/EC-281). For Konditorei that\n * is uniquely `project.Reusable` → `element` → `reusable.content`.\n *\n * EC-462 — the predicate additionally DISQUALIFIES a candidate whose own manifest\n * explicitly declares its relation prop to be something other than an embed\n * pointer. The shape test alone proved unsound the moment a relation prop's\n * target collection gains a `blocks` field of its own (a category/page with a\n * canvas — a completely natural content shape): the EC-276 sprint's ProductGrid\n * and the demo's OptionBox were both claimed as \"the embed\", so their ordinary\n * relation picks rendered the reusable-element placeholder, grew Detach/Make-\n * reusable gestures, and fed embed-worded publish-integrity issues. Two\n * explicit-declaration disqualifiers close the observed class:\n *\n * - a manifest with a `listing` declaration is a QUERY host (EC-255) — its\n * relation prop is the query's filter source (`listing.filter.fromProp`),\n * never a transclusion pointer;\n * - a relation prop with `form.hidden` (predicate or `true`) is conditional/\n * auxiliary — EC-394 strips a hidden relation's ref at publish, so it cannot\n * coherently be what the component transcludes.\n *\n * Both read only the CANDIDATE manifest's own declarations (never the target's\n * contents) and can only EXCLUDE, so a genuine pure embed (which declares\n * neither) is always kept. EC-462's residual — a bare unconditional\n * single-relation display component (e.g. a page teaser) is at rest\n * indistinguishable from a genuine embed — is closed by EC-467's optional\n * {@link StudioReuseConfig} declaration: a project that hits ambiguity declares\n * its way out, and the ambiguity is LOUD instead of silently disabling the\n * gestures. See {@link resolveReuse}.\n */\nexport interface ReuseCapability {\n /** The embed component, e.g. `project.Reusable`. */\n embedComponentId: string\n /** The embed's relation prop that points at the reusable document, e.g. `element`. */\n relationProp: string\n /** The collection reusable documents live in, e.g. `reusable`. */\n collectionId: string\n /** The collection's composition field the embed transcludes, e.g. `content`. */\n contentField: string\n /** Whether that field holds a single block or a list. */\n contentCardinality: 'one' | 'many'\n}\n\n/**\n * EC-467 (AD-b) — the OPTIONAL studio-config declaration of the reuse embed:\n * `defineStudio({ reuse: { component: 'project.Reusable' } })`. See\n * {@link import('../app-views/studio-config').StudioConfig.reuse} for the\n * consumer-facing contract; this is the shape {@link resolveReuse} consumes.\n *\n * One identifier is enough because the rest DERIVES from it (its single-document\n * relation prop → that prop's target collection → that collection's `blocks`\n * field), and because reusable elements are singular per project (AD-a).\n */\nexport interface StudioReuseConfig {\n /** The embed component's registry id, e.g. `'project.Reusable'`. */\n component: string\n /**\n * Which relation prop points at the reusable document. Needed ONLY when the\n * declared component legitimately has more than one single-document relation\n * prop — otherwise the sole one is derived.\n */\n relationProp?: string\n}\n\n/**\n * EC-467 — the resolution of the project's reuse capability: the capability (or\n * `null`), plus the config issues a developer must SEE.\n *\n * The issues ride the EC-236 {@link CustomizationIssue} surface (`point: 'reuse'`),\n * exactly like the sidebar's and the field renderers' — so they render at the\n * studio rail foot on every surface, which is the studio's home for\n * project-CONFIGURATION problems (the document-scoped Issues pane is the wrong\n * home: this is not a content problem in one document).\n *\n * EC-478: each issue carries a `messageRef` (catalog key + identifier values)\n * alongside its prebuilt English, so the rail foot renders it in the active UI\n * locale. This module stays pure — it names a key, it never calls `translate`;\n * `lib/persona/labels.ts` resolves it at the render site. That is what makes the\n * whole list localize together, which is the mixed-language outcome EC-467\n * declined to create by localizing only its own half.\n */\nexport interface ReuseResolution {\n capability: ReuseCapability | null\n /** Empty whenever the capability is unambiguous — including \"this project has none\". */\n issues: CustomizationIssue[]\n}\n\n/** The customization point name stamped onto every reuse issue (EC-236 locator). */\nconst REUSE_POINT = 'reuse'\n\n/** A `relation` prop of a manifest, normalized for both resolution paths. */\ninterface RelationProp {\n name: string\n /** The target collection id; `undefined` when the manifest declares none. */\n target: string | undefined\n multiple: boolean\n /** EC-462: `form.hidden` present and not literally `false` (predicate or `true`). */\n conditional: boolean\n}\n\n/** Every `relation` prop of a manifest, in declaration order. */\nfunction relationPropsOf(manifest: ComponentManifest): RelationProp[] {\n const props: RelationProp[] = []\n for (const field of manifestPropFields(manifest)) {\n if (field.type !== 'relation') continue\n const hidden = field.form?.hidden\n props.push({\n name: field.name,\n target: field.target,\n multiple: field.multiple === true,\n conditional: hidden !== undefined && hidden !== false,\n })\n }\n return props\n}\n\n/**\n * The relation props a DECLARED embed could plausibly transclude through: targeted\n * and cardinality-one. A cardinality-`many` (or targetless) relation is excluded\n * structurally, not heuristically — an embed transcludes exactly one document and\n * {@link makeEmbedNode} writes exactly one `{collection,id}`, which a list-valued\n * or target-less prop cannot hold.\n */\nfunction embeddableRelationProps(manifest: ComponentManifest): TargetedRelationProp[] {\n return relationPropsOf(manifest).filter(\n (r): r is TargetedRelationProp => r.target !== undefined && !r.multiple,\n )\n}\ntype TargetedRelationProp = RelationProp & { target: string }\n\n/** The collection's first composition field — what an embed of it transcludes. */\nfunction blocksFieldOf(collection: CollectionDef) {\n const field = collection.fields.find((f) => f.type === 'blocks')\n return field?.type === 'blocks' ? field : undefined\n}\n\n/**\n * The catalog keys for the reuse config issues (EC-478), in the `builder.reuse.config.*`\n * namespace. Named here so the producer and the catalog-parity test agree on one list.\n */\nconst REUSE_KEYS = {\n unknownComponent: 'builder.reuse.config.unknownComponent',\n noRelationProp: 'builder.reuse.config.noRelationProp',\n unknownRelationProp: 'builder.reuse.config.unknownRelationProp',\n ambiguousRelationProp: 'builder.reuse.config.ambiguousRelationProp',\n unknownCollection: 'builder.reuse.config.unknownCollection',\n noBlocksField: 'builder.reuse.config.noBlocksField',\n ambiguousInference: 'builder.reuse.config.ambiguousInference',\n} as const\n\nfunction reuseIssue(\n code: CustomizationIssue['code'],\n severity: CustomizationIssue['severity'],\n message: string,\n messageRef: CustomizationMessageRef,\n id?: string,\n): CustomizationIssue {\n return {\n code,\n severity,\n message,\n messageRef,\n point: REUSE_POINT,\n ...(id === undefined ? {} : { id }),\n }\n}\n\n/** `\"a\", \"b\"` — a readable list of prop/component ids for an issue message. */\nfunction quotedList(names: readonly string[]): string {\n return names.map((name) => `\"${name}\"`).join(', ')\n}\n\n/**\n * The components whose SHAPE makes them plausible reuse embeds (the zero-config\n * heuristic + EC-462's disqualifiers), in manifest order. Exported for the tests\n * and for issue copy; the resolution rule lives in {@link resolveReuse}.\n */\nexport function inferredEmbedCandidates(\n manifests: readonly ComponentManifest[],\n collections: readonly CollectionDef[],\n): ReuseCapability[] {\n const matches: ReuseCapability[] = []\n for (const manifest of manifests) {\n if (manifest.slots.length > 0) continue\n // EC-462: a `listing` manifest is a query host by its own declaration — its\n // relation prop is the filter source, never an embed pointer.\n if (manifest.listing) continue\n // The heuristic requires the relation to be UNAMBIGUOUS within the manifest:\n // exactly ONE relation prop of any kind, which must then be targeted,\n // cardinality-one and unconditional. (Counting all relation props — not just\n // the embeddable ones — is deliberate: a component with a second, list-valued\n // relation is not the single-purpose shape the heuristic is allowed to claim.)\n const relations = relationPropsOf(manifest)\n const relation = relations.length === 1 ? relations[0]! : undefined\n if (!relation || relation.target === undefined || relation.multiple || relation.conditional)\n continue\n const collection = collections.find((c) => c.id === relation.target)\n if (!collection) continue\n const blocksField = blocksFieldOf(collection)\n if (!blocksField) continue\n matches.push({\n embedComponentId: manifest.id,\n relationProp: relation.name,\n collectionId: collection.id,\n contentField: blocksField.name,\n contentCardinality: blocksField.multiple === false ? 'one' : 'many',\n })\n }\n return matches\n}\n\n/**\n * Resolve the DECLARED embed (EC-467, AD-b). An explicit declaration is the\n * developer's authority, so the inference disqualifiers are NOT applied here: a\n * declared component may have slots, may declare `listing`, and its relation prop\n * may be `form.hidden` — those exist to stop the engine GUESSING, not to overrule\n * a stated intent. Only structural impossibilities are issues (see AD-c row 2):\n * an unknown component id, no usable relation prop (or an ambiguous set with no\n * `relationProp`), an undefined target collection, or a target with no `blocks`\n * field — each of which would leave nothing coherent to transclude.\n */\nfunction resolveDeclaredReuse(\n declaration: StudioReuseConfig,\n manifests: readonly ComponentManifest[],\n collections: readonly CollectionDef[],\n): ReuseResolution {\n const { component, relationProp } = declaration\n const fail = (message: string, messageRef: CustomizationMessageRef): ReuseResolution => ({\n capability: null,\n issues: [reuseIssue('invalid-override', 'error', message, messageRef, component)],\n })\n\n const manifest = manifests.find((m) => m.id === component)\n if (!manifest) {\n return {\n capability: null,\n issues: [\n reuseIssue(\n 'unknown-override-target',\n 'error',\n `Reusable elements: studio config declares reuse.component \"${component}\", which is not a registered component. Fix the id, or remove the reuse block to let the studio infer the embed.`,\n { key: REUSE_KEYS.unknownComponent, vars: { component } },\n component,\n ),\n ],\n }\n }\n\n const relations = embeddableRelationProps(manifest)\n if (relations.length === 0) {\n return fail(\n `Reusable elements: the declared embed \"${component}\" has no single-document relation prop, so it cannot point at a reusable document. An embed needs one relation prop with cardinality one.`,\n { key: REUSE_KEYS.noRelationProp, vars: { component } },\n )\n }\n const names = relations.map((r) => r.name)\n let relation: TargetedRelationProp\n if (relationProp !== undefined) {\n const named = relations.find((r) => r.name === relationProp)\n if (!named) {\n return fail(\n `Reusable elements: the declared embed \"${component}\" has no single-document relation prop named \"${relationProp}\". Its relation props are: ${quotedList(names)}.`,\n {\n key: REUSE_KEYS.unknownRelationProp,\n vars: { component, relationProp, props: quotedList(names) },\n },\n )\n }\n relation = named\n } else if (relations.length === 1) {\n relation = relations[0]!\n } else {\n return fail(\n `Reusable elements: the declared embed \"${component}\" has ${relations.length} single-document relation props (${quotedList(names)}) — add reuse.relationProp to say which one points at the reusable document.`,\n {\n key: REUSE_KEYS.ambiguousRelationProp,\n vars: { component, count: relations.length, props: quotedList(names) },\n },\n )\n }\n\n const collection = collections.find((c) => c.id === relation.target)\n if (!collection) {\n return fail(\n `Reusable elements: \"${component}.${relation.name}\" targets the collection \"${relation.target}\", which this project does not define.`,\n {\n key: REUSE_KEYS.unknownCollection,\n vars: { component, relationProp: relation.name, collection: relation.target },\n },\n )\n }\n const blocksField = blocksFieldOf(collection)\n if (!blocksField) {\n return fail(\n `Reusable elements: the collection \"${collection.id}\" behind \"${component}.${relation.name}\" has no blocks (composition) field, so there is nothing for the embed to transclude.`,\n {\n key: REUSE_KEYS.noBlocksField,\n vars: { component, relationProp: relation.name, collection: collection.id },\n },\n )\n }\n\n return {\n capability: {\n embedComponentId: manifest.id,\n relationProp: relation.name,\n collectionId: collection.id,\n contentField: blocksField.name,\n contentCardinality: blocksField.multiple === false ? 'one' : 'many',\n },\n issues: [],\n }\n}\n\n/**\n * Resolve the project's ONE reuse capability (AD-a) plus any config issues —\n * EC-467's full matrix (AD-c):\n *\n * | Declaration | Candidates | Result |\n * | --- | --- | --- |\n * | present, resolves | any | the declared capability, no issue |\n * | present, does not resolve | any | `null` + an ERROR issue (misconfiguration) |\n * | absent | exactly 1 | that candidate, no issue (the zero-config default) |\n * | absent | 2 or more | `null` + a WARNING issue naming every candidate |\n * | absent | 0 | `null`, **no issue** — a project need not use reusable elements |\n *\n * Severity is the honest split: a declaration that cannot resolve is broken\n * config the developer asked for (error); inference ambiguity is nothing broken —\n * the engine declines to guess and asks for one line (warning). Both disable the\n * gestures, and both render identically in the rail's issue list.\n *\n * The zero-candidate row is deliberately silent: crying wolf at every project\n * that has no reusable elements would train developers to ignore the surface.\n */\nexport function resolveReuse(\n manifests: readonly ComponentManifest[],\n collections: readonly CollectionDef[],\n declaration?: StudioReuseConfig,\n): ReuseResolution {\n if (declaration) return resolveDeclaredReuse(declaration, manifests, collections)\n\n const candidates = inferredEmbedCandidates(manifests, collections)\n if (candidates.length === 1) return { capability: candidates[0]!, issues: [] }\n if (candidates.length === 0) return { capability: null, issues: [] }\n return {\n capability: null,\n issues: [\n reuseIssue(\n 'ambiguous-inference',\n 'warning',\n `Reusable elements: ${candidates.length} components have the reusable-embed shape (${quotedList(\n candidates.map((c) => c.embedComponentId),\n )}). A project has exactly one reusable-element embed, so the studio will not guess — declare it in studio.config as reuse: { component: '<id>' }. Until then the reuse gestures are off.`,\n {\n key: REUSE_KEYS.ambiguousInference,\n vars: {\n count: candidates.length,\n components: quotedList(candidates.map((c) => c.embedComponentId)),\n },\n },\n ),\n ],\n }\n}\n\n/**\n * The project's reuse capability alone, or `null` when it is absent, ambiguous, or\n * misdeclared — for callers that act on the capability and do not surface config\n * issues themselves (the publish-integrity walk). The issues are surfaced ONCE, by\n * the shell rail; see {@link resolveReuse}.\n */\nexport function resolveReuseCapability(\n manifests: readonly ComponentManifest[],\n collections: readonly CollectionDef[],\n declaration?: StudioReuseConfig,\n): ReuseCapability | null {\n return resolveReuse(manifests, collections, declaration).capability\n}\n\n/** A slug for `name`, suffixed `-2`/`-3`/… until it is free among `taken`. */\nexport function uniqueSlug(name: string, taken: ReadonlySet<string>): string {\n const base = slugify(name) || 'element'\n let id = base\n for (let n = 2; taken.has(id); n += 1) id = `${base}-${n}`\n return id\n}\n\n/**\n * The values for a new reusable document promoted from `node` (EC-282): seeded\n * defaults, the given `name` on the title field, the node on the content field,\n * and a collision-safe slug on any UNIQUE text field (e.g. Konditorei's\n * `internalId`) so the created document is publish-valid without hardcoding that\n * field's name. Other required fields, if any, are completed by the editor when\n * they open the new reusable.\n */\nexport function buildReusableValues(\n collection: CollectionDef,\n capability: ReuseCapability,\n name: string,\n node: ComponentNode,\n existing: readonly { values?: Record<string, unknown> }[],\n): Record<string, unknown> {\n const values: Record<string, unknown> = { ...seedDefaults(collection) }\n const titleField = titleFieldOf(collection)?.name\n if (titleField) values[titleField] = name\n for (const field of collection.fields) {\n if (\n field.type === 'text' &&\n field.validation?.unique === true &&\n field.name !== titleField &&\n field.name !== capability.contentField\n ) {\n const taken = new Set(\n existing\n .map((d) => d.values?.[field.name])\n .filter((v): v is string => typeof v === 'string'),\n )\n values[field.name] = uniqueSlug(name, taken)\n }\n }\n values[capability.contentField] = capability.contentCardinality === 'one' ? node : [node]\n return values\n}\n\n/**\n * The document a reuse-embed `node` targets (EC-300), or null when `node` is not the\n * embed component or has no static pick yet. Lets the canvas detect a HARD reference\n * whose target doesn't resolve (→ placeholder) without reaching into prop internals.\n */\nexport function reuseEmbedRef(node: ComponentNode, capability: ReuseCapability): DocumentRef | null {\n if (node.componentId !== capability.embedComponentId) return null\n const prop = node.props?.[capability.relationProp]\n const ref = isStaticProp(prop) ? readDocumentRef(prop.value) : undefined\n return ref ?? null\n}\n\n/**\n * Every reuse-embed target ref in a composition `blocks` value, at any depth\n * (EC-300) — the hard references a publish-integrity check walks to find\n * unpublished targets. Recurses slots; order is document order. Duplicates are\n * kept (the caller dedupes by key if needed).\n */\nexport function collectEmbedRefs(\n blocks: readonly ComponentNode[],\n capability: ReuseCapability,\n): DocumentRef[] {\n const refs: DocumentRef[] = []\n const visit = (node: ComponentNode): void => {\n const ref = reuseEmbedRef(node, capability)\n if (ref) refs.push(ref)\n for (const children of Object.values(node.slots ?? {})) for (const child of children) visit(child)\n }\n for (const node of blocks) visit(node)\n return refs\n}\n\n/** The `Reusable` embed node referencing the new document (id minted by the action). */\nexport function makeEmbedNode(capability: ReuseCapability, documentId: string): ComponentNode {\n return {\n id: 'reuse-embed',\n componentId: capability.embedComponentId,\n props: {\n [capability.relationProp]: {\n kind: 'static',\n value: { collection: capability.collectionId, id: documentId },\n },\n },\n }\n}\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { matchesRef } from './document-ref-utils.js';
|
|
2
|
+
import { translate } from '@elytracms/studio/lib/i18n';
|
|
3
|
+
import { cmsValidationIssueMessage, operationErrorMessage, operationIssueMessage, } from '@elytracms/studio/lib/persona/labels';
|
|
2
4
|
export function bulkSummary(report) {
|
|
3
5
|
let succeeded = 0;
|
|
4
6
|
for (const result of report.results)
|
|
@@ -8,10 +10,12 @@ export function bulkSummary(report) {
|
|
|
8
10
|
}
|
|
9
11
|
/** The failure reason a report row shows: validation issues beat the envelope. */
|
|
10
12
|
export function bulkErrorReason(error) {
|
|
13
|
+
// EC-494: resolve the carried catalog refs — a bulk publish rejected by the
|
|
14
|
+
// SERVER-side field-rule gate reports in the editor's language, not English.
|
|
11
15
|
if (error.code === 'validation' && error.issues.length > 0) {
|
|
12
|
-
return error.issues.map((issue) => issue
|
|
16
|
+
return error.issues.map((issue) => operationIssueMessage(issue)).join(' · ');
|
|
13
17
|
}
|
|
14
|
-
return error
|
|
18
|
+
return operationErrorMessage(error);
|
|
15
19
|
}
|
|
16
20
|
const ACTION_STATE = {
|
|
17
21
|
publish: 'published',
|
|
@@ -38,7 +42,7 @@ export async function runBulkAction(context, collectionId, ids, action, setField
|
|
|
38
42
|
if (!doc) {
|
|
39
43
|
fail({
|
|
40
44
|
code: 'not-found',
|
|
41
|
-
message: '
|
|
45
|
+
message: translate('cms.list.bulk.error.notInSession'),
|
|
42
46
|
entity: 'cms-document',
|
|
43
47
|
key: `${collectionId}:${id}`,
|
|
44
48
|
});
|
|
@@ -49,10 +53,11 @@ export async function runBulkAction(context, collectionId, ids, action, setField
|
|
|
49
53
|
if (errors.length > 0) {
|
|
50
54
|
fail({
|
|
51
55
|
code: 'validation',
|
|
52
|
-
message: '
|
|
56
|
+
message: translate('cms.list.bulk.error.notValidToPublish'),
|
|
53
57
|
issues: errors.map((issue) => ({
|
|
54
58
|
code: issue.code,
|
|
55
|
-
|
|
59
|
+
// EC-487 — resolved here, the last point that still has the structured issue.
|
|
60
|
+
message: cmsValidationIssueMessage(issue),
|
|
56
61
|
path: [...issue.path],
|
|
57
62
|
domain: 'cms',
|
|
58
63
|
})),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulk-actions.js","sourceRoot":"","sources":["../../../src/components/cms/bulk-actions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AA8CjD,MAAM,UAAU,WAAW,CAAC,MAAkB;IAC5C,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO;QAAE,IAAI,MAAM,CAAC,EAAE;YAAE,SAAS,IAAI,CAAC,CAAA;IAClE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,SAAS,EAAE,CAAA;AACjE,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,KAAqB;IACnD,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3D,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/D,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAA;AACtB,CAAC;AAwCD,MAAM,YAAY,GAAsD;IACtE,OAAO,EAAE,WAAW;IACpB,SAAS,EAAE,OAAO;CACnB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAoB,EACpB,YAAoB,EACpB,GAAsB,EACtB,MAAkB,EAClB,QAAuB;IAEvB,MAAM,OAA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H,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBACf,oEAAoE;gBACpE,gEAAgE;gBAChE,mEAAmE;gBACnE,yDAAyD;gBACzD,MAAM,gBAAgB,GAAG,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAA;gBACjF,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,SAAQ;gBACV,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,KAAK,QAAQ;YAAE,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;aAC5C,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,IAAI,QAAQ;gBAAE,OAAO,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QACtD,CAAC;;YAAM,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;QACpD,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;AAC/D,CAAC","sourcesContent":["import type {\n CmsDocument,\n CmsValidationIssue,\n DocumentRef,\n PublicationState,\n} from '@elytracms/core/cms-core'\nimport type { FilterScalar } from '@elytracms/core/content'\nimport type { OperationError, OperationResult } from '@elytracms/studio/lib/operations'\nimport { matchesRef } from './document-ref-utils'\n\n/**\n * Bulk actions over a table selection (EC-169) — the pure half.\n *\n * Each selected document gets its OWN operations command\n * (`documents.publish` / `documents.unpublish` / `documents.delete`, EC-224;\n * `documents.upsert` for a set-field, EC-247), awaited in selection order, and\n * its own per-item outcome. The report enumerates every failure with its\n * reason (validation gate, authorization denial, not-found, …) — a partial\n * failure is never silent and never collapsed into one toast. Session state is\n * only updated for items whose command succeeded.\n */\n\nexport type BulkAction = 'publish' | 'unpublish' | 'delete' | 'set-field'\n\n/**\n * The payload of a `set-field` bulk action (EC-247): assign one filterable\n * scalar field the same value across every selected document. The value is\n * folded into each document the locale-aware way (`applyCellValue`) by the\n * caller's `applySetField`/`dispatch`; this module only carries it.\n */\nexport interface BulkSetField {\n field: string\n value: FilterScalar\n}\n\n/** The outcome of one document's command within a bulk run. */\nexport interface BulkItemOutcome {\n ref: DocumentRef\n /** Display title at dispatch time (deleted docs still get named in the report). */\n title: string\n ok: boolean\n /** Human-readable failure reason — present exactly when `ok` is false. */\n reason?: string\n /** The structured error behind the reason (operation result / validation gate). */\n error?: OperationError\n}\n\nexport interface BulkReport {\n action: BulkAction\n /** Present for `set-field`: the field + value that was applied (report label). */\n setField?: BulkSetField\n results: BulkItemOutcome[]\n}\n\nexport function bulkSummary(report: BulkReport): { succeeded: number; failed: number } {\n let succeeded = 0\n for (const result of report.results) if (result.ok) succeeded += 1\n return { succeeded, failed: report.results.length - succeeded }\n}\n\n/** The failure reason a report row shows: validation issues beat the envelope. */\nexport function bulkErrorReason(error: OperationError): string {\n if (error.code === 'validation' && error.issues.length > 0) {\n return error.issues.map((issue) => issue.message).join(' · ')\n }\n return error.message\n}\n\nexport interface BulkContext {\n /** Current session documents (lookup + validation input). */\n documents: readonly CmsDocument[]\n titleOf(ref: DocumentRef): string\n /** Full document validation — gates publish: invalid documents never dispatch. */\n validate(doc: CmsDocument): CmsValidationIssue[]\n /** Apply one succeeded state transition to the session. */\n applyState(ref: DocumentRef, state: PublicationState): void\n /** Apply one succeeded delete to the session. */\n applyDelete(ref: DocumentRef): void\n /**\n * Apply one succeeded set-field to the session (locale-aware fold). Required\n * when the action is `set-field`; unused otherwise.\n */\n applySetField?(ref: DocumentRef, set: BulkSetField): void\n /**\n * EC-425: the publish-time hidden-strip (EC-273 clearHiddenValues + EC-394\n * clearHiddenProps, the SAME shared clean step the single-document `doPublish`\n * runs) — returns the document a publish should snapshot. Identity-preserving:\n * returns the input when nothing clears. Absent ⇒ publish the draft as stored\n * (fixture harnesses without a clean point).\n */\n cleanForPublish?(doc: CmsDocument): CmsDocument\n /**\n * EC-425: land a cleaned draft (session + persistence) BEFORE its publish\n * command dispatches, so the snapshot the publish pins — and the reference\n * index derived from the stored draft (EC-286) — are clean. Awaited; only\n * called when {@link cleanForPublish} actually changed the document\n * (save-if-changed, mirroring `doPublish`).\n */\n applyCleaned?(ref: DocumentRef, doc: CmsDocument): Promise<void> | void\n /**\n * Dispatch the ONE operations command for an item. Absent in fixture-only\n * sessions (no project scope) — items then mutate the session directly.\n */\n dispatch?: (action: BulkAction, ref: DocumentRef) => Promise<OperationResult<unknown>>\n}\n\nconst ACTION_STATE: Record<'publish' | 'unpublish', PublicationState> = {\n publish: 'published',\n unpublish: 'draft',\n}\n\n/**\n * Run one bulk action over a selection, item by item:\n * 1. publish gates on validation — an invalid document fails with its issues\n * and dispatches NOTHING (a set-field is a draft edit, EC-225 — never gated),\n * 2. publish joins the single-document clean point (EC-425): the hidden-strip\n * runs per item and a changed draft is saved (awaited) BEFORE the publish\n * command, so bulk-published snapshots go out as clean as editor publishes,\n * 3. each remaining item dispatches exactly one operations command, awaited,\n * 4. only succeeded items mutate the session,\n * 5. the report carries one honest outcome per item, in selection order.\n */\nexport async function runBulkAction(\n context: BulkContext,\n collectionId: string,\n ids: readonly string[],\n action: BulkAction,\n setField?: BulkSetField,\n): Promise<BulkReport> {\n const results: BulkItemOutcome[] = []\n\n for (const id of ids) {\n const ref: DocumentRef = { collection: collectionId, id }\n const title = context.titleOf(ref)\n const fail = (error: OperationError) =>\n results.push({ ref, title, ok: false, reason: bulkErrorReason(error), error })\n\n const doc = context.documents.find((d) => matchesRef(d, ref))\n if (!doc) {\n fail({\n code: 'not-found',\n message: 'Document is no longer in the session.',\n entity: 'cms-document',\n key: `${collectionId}:${id}`,\n })\n continue\n }\n\n if (action === 'publish') {\n const errors = context.validate(doc).filter((issue) => issue.severity === 'error')\n if (errors.length > 0) {\n fail({\n code: 'validation',\n message: 'Document is not valid to publish.',\n issues: errors.map((issue) => ({\n code: issue.code,\n message: issue.message,\n path: [...issue.path],\n domain: 'cms',\n })),\n })\n continue\n }\n // EC-425: the SAME clean-then-save sequence the single-document `doPublish`\n // runs, per item — validation gated on the live draft above (matching the\n // editor's pre-strip gate), then the hidden-strip; a changed draft lands\n // (awaited) before the publish command so the pinned snapshot and the\n // EC-286-derived reference index are clean. A failing save is an honest\n // per-item failure and the publish never dispatches on the dirty draft.\n if (context.cleanForPublish) {\n const cleaned = context.cleanForPublish(doc)\n if (cleaned !== doc) {\n try {\n await context.applyCleaned?.(ref, cleaned)\n } catch (cause) {\n fail({\n code: 'unknown',\n message: cause instanceof Error ? cause.message : String(cause),\n })\n continue\n }\n }\n }\n }\n\n if (context.dispatch) {\n let result: OperationResult<unknown>\n try {\n result = await context.dispatch(action, ref)\n } catch (cause) {\n // Operations never throw by contract; a broken transport still becomes\n // a visible per-item failure instead of an aborted bulk run.\n result = {\n ok: false,\n error: {\n code: 'unknown',\n message: cause instanceof Error ? cause.message : String(cause),\n },\n }\n }\n if (!result.ok) {\n // Idempotent delete: the document was never persisted (e.g. a draft\n // whose baseline upsert was rejected) or another editor already\n // deleted it. The desired end state — gone — holds, so removing it\n // from the session is the honest outcome, not a failure.\n const idempotentDelete = action === 'delete' && result.error.code === 'not-found'\n if (!idempotentDelete) {\n fail(result.error)\n continue\n }\n }\n }\n\n if (action === 'delete') context.applyDelete(ref)\n else if (action === 'set-field') {\n if (setField) context.applySetField?.(ref, setField)\n } else context.applyState(ref, ACTION_STATE[action])\n results.push({ ref, title, ok: true })\n }\n\n return { action, ...(setField ? { setField } : {}), results }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bulk-actions.js","sourceRoot":"","sources":["../../../src/components/cms/bulk-actions.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AAC;gBACf,oEAAoE;gBACpE,gEAAgE;gBAChE,mEAAmE;gBACnE,yDAAyD;gBACzD,MAAM,gBAAgB,GAAG,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAA;gBACjF,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;oBAClB,SAAQ;gBACV,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,KAAK,QAAQ;YAAE,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;aAC5C,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;YAChC,IAAI,QAAQ;gBAAE,OAAO,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;QACtD,CAAC;;YAAM,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;QACpD,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAA;AAC/D,CAAC","sourcesContent":["import type {\n CmsDocument,\n CmsValidationIssue,\n DocumentRef,\n PublicationState,\n} from '@elytracms/core/cms-core'\nimport type { FilterScalar } from '@elytracms/core/content'\nimport type { OperationError, OperationResult } from '@elytracms/studio/lib/operations'\nimport { matchesRef } from './document-ref-utils'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport {\n cmsValidationIssueMessage,\n operationErrorMessage,\n operationIssueMessage,\n} from '@elytracms/studio/lib/persona/labels'\n\n/**\n * Bulk actions over a table selection (EC-169) — the pure half.\n *\n * Each selected document gets its OWN operations command\n * (`documents.publish` / `documents.unpublish` / `documents.delete`, EC-224;\n * `documents.upsert` for a set-field, EC-247), awaited in selection order, and\n * its own per-item outcome. The report enumerates every failure with its\n * reason (validation gate, authorization denial, not-found, …) — a partial\n * failure is never silent and never collapsed into one toast. Session state is\n * only updated for items whose command succeeded.\n */\n\nexport type BulkAction = 'publish' | 'unpublish' | 'delete' | 'set-field'\n\n/**\n * The payload of a `set-field` bulk action (EC-247): assign one filterable\n * scalar field the same value across every selected document. The value is\n * folded into each document the locale-aware way (`applyCellValue`) by the\n * caller's `applySetField`/`dispatch`; this module only carries it.\n */\nexport interface BulkSetField {\n field: string\n value: FilterScalar\n}\n\n/** The outcome of one document's command within a bulk run. */\nexport interface BulkItemOutcome {\n ref: DocumentRef\n /** Display title at dispatch time (deleted docs still get named in the report). */\n title: string\n ok: boolean\n /** Human-readable failure reason — present exactly when `ok` is false. */\n reason?: string\n /** The structured error behind the reason (operation result / validation gate). */\n error?: OperationError\n}\n\nexport interface BulkReport {\n action: BulkAction\n /** Present for `set-field`: the field + value that was applied (report label). */\n setField?: BulkSetField\n results: BulkItemOutcome[]\n}\n\nexport function bulkSummary(report: BulkReport): { succeeded: number; failed: number } {\n let succeeded = 0\n for (const result of report.results) if (result.ok) succeeded += 1\n return { succeeded, failed: report.results.length - succeeded }\n}\n\n/** The failure reason a report row shows: validation issues beat the envelope. */\nexport function bulkErrorReason(error: OperationError): string {\n // EC-494: resolve the carried catalog refs — a bulk publish rejected by the\n // SERVER-side field-rule gate reports in the editor's language, not English.\n if (error.code === 'validation' && error.issues.length > 0) {\n return error.issues.map((issue) => operationIssueMessage(issue)).join(' · ')\n }\n return operationErrorMessage(error)\n}\n\nexport interface BulkContext {\n /** Current session documents (lookup + validation input). */\n documents: readonly CmsDocument[]\n titleOf(ref: DocumentRef): string\n /** Full document validation — gates publish: invalid documents never dispatch. */\n validate(doc: CmsDocument): CmsValidationIssue[]\n /** Apply one succeeded state transition to the session. */\n applyState(ref: DocumentRef, state: PublicationState): void\n /** Apply one succeeded delete to the session. */\n applyDelete(ref: DocumentRef): void\n /**\n * Apply one succeeded set-field to the session (locale-aware fold). Required\n * when the action is `set-field`; unused otherwise.\n */\n applySetField?(ref: DocumentRef, set: BulkSetField): void\n /**\n * EC-425: the publish-time hidden-strip (EC-273 clearHiddenValues + EC-394\n * clearHiddenProps, the SAME shared clean step the single-document `doPublish`\n * runs) — returns the document a publish should snapshot. Identity-preserving:\n * returns the input when nothing clears. Absent ⇒ publish the draft as stored\n * (fixture harnesses without a clean point).\n */\n cleanForPublish?(doc: CmsDocument): CmsDocument\n /**\n * EC-425: land a cleaned draft (session + persistence) BEFORE its publish\n * command dispatches, so the snapshot the publish pins — and the reference\n * index derived from the stored draft (EC-286) — are clean. Awaited; only\n * called when {@link cleanForPublish} actually changed the document\n * (save-if-changed, mirroring `doPublish`).\n */\n applyCleaned?(ref: DocumentRef, doc: CmsDocument): Promise<void> | void\n /**\n * Dispatch the ONE operations command for an item. Absent in fixture-only\n * sessions (no project scope) — items then mutate the session directly.\n */\n dispatch?: (action: BulkAction, ref: DocumentRef) => Promise<OperationResult<unknown>>\n}\n\nconst ACTION_STATE: Record<'publish' | 'unpublish', PublicationState> = {\n publish: 'published',\n unpublish: 'draft',\n}\n\n/**\n * Run one bulk action over a selection, item by item:\n * 1. publish gates on validation — an invalid document fails with its issues\n * and dispatches NOTHING (a set-field is a draft edit, EC-225 — never gated),\n * 2. publish joins the single-document clean point (EC-425): the hidden-strip\n * runs per item and a changed draft is saved (awaited) BEFORE the publish\n * command, so bulk-published snapshots go out as clean as editor publishes,\n * 3. each remaining item dispatches exactly one operations command, awaited,\n * 4. only succeeded items mutate the session,\n * 5. the report carries one honest outcome per item, in selection order.\n */\nexport async function runBulkAction(\n context: BulkContext,\n collectionId: string,\n ids: readonly string[],\n action: BulkAction,\n setField?: BulkSetField,\n): Promise<BulkReport> {\n const results: BulkItemOutcome[] = []\n\n for (const id of ids) {\n const ref: DocumentRef = { collection: collectionId, id }\n const title = context.titleOf(ref)\n const fail = (error: OperationError) =>\n results.push({ ref, title, ok: false, reason: bulkErrorReason(error), error })\n\n const doc = context.documents.find((d) => matchesRef(d, ref))\n if (!doc) {\n fail({\n code: 'not-found',\n message: translate('cms.list.bulk.error.notInSession'),\n entity: 'cms-document',\n key: `${collectionId}:${id}`,\n })\n continue\n }\n\n if (action === 'publish') {\n const errors = context.validate(doc).filter((issue) => issue.severity === 'error')\n if (errors.length > 0) {\n fail({\n code: 'validation',\n message: translate('cms.list.bulk.error.notValidToPublish'),\n issues: errors.map((issue) => ({\n code: issue.code,\n // EC-487 — resolved here, the last point that still has the structured issue.\n message: cmsValidationIssueMessage(issue),\n path: [...issue.path],\n domain: 'cms',\n })),\n })\n continue\n }\n // EC-425: the SAME clean-then-save sequence the single-document `doPublish`\n // runs, per item — validation gated on the live draft above (matching the\n // editor's pre-strip gate), then the hidden-strip; a changed draft lands\n // (awaited) before the publish command so the pinned snapshot and the\n // EC-286-derived reference index are clean. A failing save is an honest\n // per-item failure and the publish never dispatches on the dirty draft.\n if (context.cleanForPublish) {\n const cleaned = context.cleanForPublish(doc)\n if (cleaned !== doc) {\n try {\n await context.applyCleaned?.(ref, cleaned)\n } catch (cause) {\n fail({\n code: 'unknown',\n message: cause instanceof Error ? cause.message : String(cause),\n })\n continue\n }\n }\n }\n }\n\n if (context.dispatch) {\n let result: OperationResult<unknown>\n try {\n result = await context.dispatch(action, ref)\n } catch (cause) {\n // Operations never throw by contract; a broken transport still becomes\n // a visible per-item failure instead of an aborted bulk run.\n result = {\n ok: false,\n error: {\n code: 'unknown',\n message: cause instanceof Error ? cause.message : String(cause),\n },\n }\n }\n if (!result.ok) {\n // Idempotent delete: the document was never persisted (e.g. a draft\n // whose baseline upsert was rejected) or another editor already\n // deleted it. The desired end state — gone — holds, so removing it\n // from the session is the honest outcome, not a failure.\n const idempotentDelete = action === 'delete' && result.error.code === 'not-found'\n if (!idempotentDelete) {\n fail(result.error)\n continue\n }\n }\n }\n\n if (action === 'delete') context.applyDelete(ref)\n else if (action === 'set-field') {\n if (setField) context.applySetField?.(ref, setField)\n } else context.applyState(ref, ACTION_STATE[action])\n results.push({ ref, title, ok: true })\n }\n\n return { action, ...(setField ? { setField } : {}), results }\n}\n"]}
|