@eldrajs/theme-core 0.3.6 → 0.4.1
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/CHANGELOG.md +54 -7
- package/dist/{bridge-DSH4N82G.js → bridge-CCF1LxsP.js} +9 -3
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +1 -1
- package/dist/{index-C3tgQ-hG.d.ts → index-C_Kx7Vq9.d.ts} +36 -3
- package/dist/index.d.ts +20 -7
- package/dist/index.js +158 -25
- package/dist/links.d.ts +51 -2
- package/dist/links.js +80 -6
- package/dist/{overlay-a8pghnYy.js → overlay-C6lCvEGm.js} +312 -22
- package/dist/{overlay-mKeZLljc.d.ts → overlay-D7gS7OY1.d.ts} +26 -3
- package/dist/overlay.d.ts +1 -1
- package/dist/overlay.js +2 -2
- package/dist/preview-router.d.ts +1 -1
- package/dist/preview-router.js +13 -3
- package/dist/reusable.d.ts +45 -0
- package/dist/reusable.js +125 -1
- package/dist/stega.d.ts +21 -0
- package/dist/stega.js +7 -1
- package/dist/template-layout.d.ts +1 -1
- package/dist/{templateLayout-Dp3KYV2b.d.ts → templateLayout-BWNs1ZYt.d.ts} +61 -2
- package/package.json +1 -1
package/dist/reusable.js
CHANGED
|
@@ -88,4 +88,128 @@ function componentPerspectiveKey(perspective, siteId, componentId) {
|
|
|
88
88
|
function snapshotKey(perspective, componentId, siteId, revision) {
|
|
89
89
|
return `${componentPerspectiveKey(perspective, siteId, componentId)}\0${revision}`;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
/**
|
|
92
|
+
* A layout document with reusable placements, in the shape Core's **public** read serves it: each
|
|
93
|
+
* placement replaced in place by its component's content, the component's root taking the
|
|
94
|
+
* placement id and every node inside it the `r` + SHA-256 render id
|
|
95
|
+
* (`docs/theme-reusable-components.md`), and no projection left anywhere.
|
|
96
|
+
*
|
|
97
|
+
* A preview read keeps the placements and the projection, because Studio's overlay addresses a
|
|
98
|
+
* node inside a component by its authored id and its placement. A draft preview session has no
|
|
99
|
+
* overlay, and must render exactly what the published page renders, so it renders this shape
|
|
100
|
+
* instead (`@eldrajs/theme-nuxt`, WS-1358). Throws a `LayoutValidationError` for what the render
|
|
101
|
+
* would refuse; the caller keeps the document as it was, and the render then fails closed on it.
|
|
102
|
+
*
|
|
103
|
+
* `routeTemplate` admits placements in a version-1 document, as a route template does.
|
|
104
|
+
*/
|
|
105
|
+
function expandReusableLayout(value, projection, options = {}) {
|
|
106
|
+
const envelope = asObject(value, "");
|
|
107
|
+
if (envelope.version !== 1 && envelope.version !== 2 && envelope.version !== 3) failLayout("/version", "INVALID_VALUE");
|
|
108
|
+
const expansion = expandReusablePlacements({
|
|
109
|
+
root: envelope.root,
|
|
110
|
+
path: "/root",
|
|
111
|
+
projection,
|
|
112
|
+
allowReusable: options.routeTemplate === true || envelope.version !== 1
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
version: envelope.version,
|
|
116
|
+
root: expansion.root
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function isPlainRecord(value) {
|
|
120
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A preview read's answer, in the shape Core's public read gives the same records (WS-1358): every
|
|
124
|
+
* entry in it — the answer itself, every list item, every resolved reference at any depth (a page's
|
|
125
|
+
* `parent`, a block, a list field's entries) — that carries a `reusableComponentProjection` is
|
|
126
|
+
* turned into its public read (`expandReusableComponentsForPublic` in Core's cms-service):
|
|
127
|
+
*
|
|
128
|
+
* - every placement expanded in place (`expandReusableLayout`; a document with `routePattern` is a
|
|
129
|
+
* route template, whose version-1 layout may place a component), and the projection dropped;
|
|
130
|
+
* - `blocks` put in the expanded layout's depth-first order (slot children by sorted slot id);
|
|
131
|
+
* - every node naming a block that is not among `blocks` removed, slot children with it, and
|
|
132
|
+
* `blocks` rebuilt from what remains;
|
|
133
|
+
* - every entry's `status` dropped (an object with `id`, `schemaId` and `data`, the envelope Core
|
|
134
|
+
* writes around a record): the public read has none.
|
|
135
|
+
*
|
|
136
|
+
* Anything else is left as it is: a document with no projection is served the same by both reads
|
|
137
|
+
* (Core prunes only a document that places a component), and a projection that does not expand is
|
|
138
|
+
* left for the render to fail closed on, as it would have. What the two reads differ in beyond
|
|
139
|
+
* this — an entry's `publishedAt` and `updatedAt` (Publish sets them) and a media item's `linkId`
|
|
140
|
+
* (one link row per owner) — is the draft's own and stays.
|
|
141
|
+
*
|
|
142
|
+
* A draft preview session's client applies it to every CMS answer (`enableSessionPreview`): a
|
|
143
|
+
* session has no overlay to address a component's nodes by their authored ids, and what it must
|
|
144
|
+
* render is what Publish puts live.
|
|
145
|
+
*/
|
|
146
|
+
function asPublicRead(value) {
|
|
147
|
+
if (Array.isArray(value)) return value.map((item) => asPublicRead(item));
|
|
148
|
+
if (!isPlainRecord(value)) return value;
|
|
149
|
+
const walked = {};
|
|
150
|
+
for (const [key, child] of Object.entries(value)) walked[key] = key === "reusableComponentProjection" ? child : asPublicRead(child);
|
|
151
|
+
return publicDocument(withoutEntryStatus(walked));
|
|
152
|
+
}
|
|
153
|
+
/** An entry's envelope without `status`: the public read drops it, a preview read keeps it. */
|
|
154
|
+
function withoutEntryStatus(record) {
|
|
155
|
+
if (!("status" in record && "id" in record && "schemaId" in record && "data" in record)) return record;
|
|
156
|
+
const { status: _status, ...rest } = record;
|
|
157
|
+
return rest;
|
|
158
|
+
}
|
|
159
|
+
function publicDocument(doc) {
|
|
160
|
+
if (!("reusableComponentProjection" in doc) || !isPlainRecord(doc.data)) return doc;
|
|
161
|
+
const { reusableComponentProjection, ...rest } = doc;
|
|
162
|
+
const data = doc.data;
|
|
163
|
+
let layout;
|
|
164
|
+
try {
|
|
165
|
+
layout = expandReusableLayout(data.layout, reusableComponentProjection, { routeTemplate: typeof data.routePattern === "string" });
|
|
166
|
+
} catch {
|
|
167
|
+
return doc;
|
|
168
|
+
}
|
|
169
|
+
if (!Array.isArray(data.blocks)) return {
|
|
170
|
+
...rest,
|
|
171
|
+
data: {
|
|
172
|
+
...data,
|
|
173
|
+
layout
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const byId = /* @__PURE__ */ new Map();
|
|
177
|
+
for (const block of data.blocks) if (isPlainRecord(block) && typeof block.id === "string" && !byId.has(block.id)) byId.set(block.id, block);
|
|
178
|
+
const missing = new Set(layoutBlockEntryIds(layout.root).filter((id) => !byId.has(id)));
|
|
179
|
+
const root = missing.size === 0 ? layout.root : pruneLayoutBlocks(layout.root, missing);
|
|
180
|
+
const blocks = layoutBlockEntryIds(root).map((id) => byId.get(id));
|
|
181
|
+
return {
|
|
182
|
+
...rest,
|
|
183
|
+
data: {
|
|
184
|
+
...data,
|
|
185
|
+
layout: {
|
|
186
|
+
...layout,
|
|
187
|
+
root
|
|
188
|
+
},
|
|
189
|
+
blocks
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/** A layout's block entry ids, depth-first, slot children by sorted slot id (Core's order). */
|
|
194
|
+
function layoutBlockEntryIds(node, into = []) {
|
|
195
|
+
if (!isPlainRecord(node)) return into;
|
|
196
|
+
if (typeof node.entryId === "string" && node.entryId !== "") into.push(node.entryId);
|
|
197
|
+
if (Array.isArray(node.children)) for (const child of node.children) layoutBlockEntryIds(child, into);
|
|
198
|
+
if (isPlainRecord(node.slots)) {
|
|
199
|
+
const slots = node.slots;
|
|
200
|
+
for (const slot of Object.keys(slots).sort()) {
|
|
201
|
+
const children = slots[slot];
|
|
202
|
+
if (Array.isArray(children)) for (const child of children) layoutBlockEntryIds(child, into);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return into;
|
|
206
|
+
}
|
|
207
|
+
function pruneLayoutBlocks(node, missing) {
|
|
208
|
+
if (!isPlainRecord(node)) return node;
|
|
209
|
+
const keep = (children) => children.filter((child) => !(isPlainRecord(child) && typeof child.entryId === "string" && missing.has(child.entryId))).map((child) => pruneLayoutBlocks(child, missing));
|
|
210
|
+
const out = { ...node };
|
|
211
|
+
if (Array.isArray(node.children)) out.children = keep(node.children);
|
|
212
|
+
if (isPlainRecord(node.slots)) out.slots = Object.fromEntries(Object.entries(node.slots).map(([slot, children]) => [slot, Array.isArray(children) ? keep(children) : children]));
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
export { ReusableComponentSnapshotCache, asPublicRead, createProjectionResolver, createReusableLayoutRenderModel, expandReusableLayout };
|
package/dist/stega.d.ts
CHANGED
|
@@ -3,7 +3,28 @@ export interface StegaMeta {
|
|
|
3
3
|
/** Dot path within entry data, e.g. "title" or "cta.label". List indices numeric: "items.2.title". */
|
|
4
4
|
fieldPath: string;
|
|
5
5
|
locale: string | null;
|
|
6
|
+
/**
|
|
7
|
+
* `false` when the text on the page is not the text the field stores — a theme wrote out price
|
|
8
|
+
* tokens (`@eldrajs/sdk/tokens`) in it — so the overlay must not make it editable in place:
|
|
9
|
+
* typing there would save the written-out price over the token. A click still selects the
|
|
10
|
+
* field, for the inspector to edit. Absent means editable, as before.
|
|
11
|
+
*/
|
|
12
|
+
inline?: false;
|
|
13
|
+
/**
|
|
14
|
+
* The field's **stored** text, for a theme that writes price tokens out: plain runs as strings,
|
|
15
|
+
* each token as its stored text with the label the page shows for it (`missing` when the
|
|
16
|
+
* shopper's currency has no amount). With `price-tokens-inline` negotiated, the overlay lets
|
|
17
|
+
* the operator edit such a field in place: the text around the prices is editable, each price
|
|
18
|
+
* is a chip, and every edit is posted as stored text, tokens intact.
|
|
19
|
+
*/
|
|
20
|
+
parts?: StegaPricePart[];
|
|
6
21
|
}
|
|
22
|
+
/** One run of a priced field's stored text: `StegaMeta.parts`. */
|
|
23
|
+
export type StegaPricePart = string | {
|
|
24
|
+
token: string;
|
|
25
|
+
label: string;
|
|
26
|
+
missing?: true;
|
|
27
|
+
};
|
|
7
28
|
/** value + zero-width payload suffix. Bits are emitted MSB-first per UTF-8 byte. */
|
|
8
29
|
export declare function encodeStega(value: string, meta: StegaMeta): string;
|
|
9
30
|
/** cleaned only, fast path — removes any U+FEFF…U+FEFF zero-width run (the
|
package/dist/stega.js
CHANGED
|
@@ -63,6 +63,12 @@ function decodeStega(value) {
|
|
|
63
63
|
function isStegaMeta(v) {
|
|
64
64
|
if (typeof v !== "object" || v === null) return false;
|
|
65
65
|
const m = v;
|
|
66
|
-
return typeof m.entryId === "string" && typeof m.fieldPath === "string" && (m.locale === null || typeof m.locale === "string");
|
|
66
|
+
return typeof m.entryId === "string" && typeof m.fieldPath === "string" && (m.locale === null || typeof m.locale === "string") && (m.inline === void 0 || m.inline === false) && (m.parts === void 0 || Array.isArray(m.parts) && m.parts.every(isPricePart));
|
|
67
|
+
}
|
|
68
|
+
function isPricePart(v) {
|
|
69
|
+
if (typeof v === "string") return true;
|
|
70
|
+
if (typeof v !== "object" || v === null) return false;
|
|
71
|
+
const p = v;
|
|
72
|
+
return typeof p.token === "string" && typeof p.label === "string" && (p.missing === void 0 || p.missing === true);
|
|
67
73
|
}
|
|
68
74
|
export { decodeStega, encodeStega, stripStega };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as TemplateLayoutDocument, c as TemplateLayoutRenderNode, i as TemplateLayoutContext, l as buildTemplateBlockRenames, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel } from "./templateLayout-
|
|
1
|
+
import { a as TemplateLayoutDocument, c as TemplateLayoutRenderNode, i as TemplateLayoutContext, l as buildTemplateBlockRenames, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel } from "./templateLayout-BWNs1ZYt.js";
|
|
2
2
|
import { n as ReusableComponentPlacement, o as ReusableRenderIdentity, r as ReusableComponentProjection } from "./reusableExpansion-CqrqpK4A.js";
|
|
3
3
|
export { type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableRenderIdentity, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, buildTemplateBlockRenames, createTemplateLayoutRenderModel };
|
|
@@ -47,7 +47,34 @@ interface EldraClientOptions {
|
|
|
47
47
|
declare class EldraClientError extends Error {
|
|
48
48
|
readonly status: number;
|
|
49
49
|
readonly path: string;
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* The refusal's `errorId`, when the answer named one. Read only from a draft preview session's
|
|
52
|
+
* reads (`enableSessionPreview`), where the preview router answers `application/problem+json` and
|
|
53
|
+
* the id says which notice to show (`SITE_PREVIEW_SESSION_EXPIRED`, `_REVOKED`, …). `null`
|
|
54
|
+
* everywhere else: an ordinary read's failure body is never read.
|
|
55
|
+
*/
|
|
56
|
+
readonly errorId: string | null;
|
|
57
|
+
/** Whether the failed request was a draft preview session read through the same-origin proxy. */
|
|
58
|
+
readonly sessionPreview: boolean;
|
|
59
|
+
constructor(status: number, statusText: string, path: string, details?: {
|
|
60
|
+
errorId?: string | null;
|
|
61
|
+
sessionPreview?: boolean;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** The site settings `getSiteSetting` reads. */
|
|
65
|
+
type EldraSiteReadPath = '/site/v1/design-tokens' | '/site/v1/theme-messages';
|
|
66
|
+
/**
|
|
67
|
+
* A draft preview session (`enableSessionPreview`): the page is served by Eldra's preview router on
|
|
68
|
+
* a host of its own, and the router holds the session's credential in an HttpOnly cookie.
|
|
69
|
+
*/
|
|
70
|
+
interface EldraSessionPreviewOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Where the router's draft read proxy lives: an absolute URL **on the page's own origin** (the
|
|
73
|
+
* router serves it at `/__eldra/gateway`), with no trailing path beyond it. A gateway path is
|
|
74
|
+
* appended without its `/api` prefix, exactly as `gatewayUrl` takes it. Anything that is not the
|
|
75
|
+
* page's own origin is refused, because the reads carry the session cookie.
|
|
76
|
+
*/
|
|
77
|
+
proxyBase: string;
|
|
51
78
|
}
|
|
52
79
|
interface PageMeta {
|
|
53
80
|
hasNext: boolean;
|
|
@@ -143,6 +170,38 @@ interface EldraClient {
|
|
|
143
170
|
enablePreview(token: string): void;
|
|
144
171
|
disablePreview(): void;
|
|
145
172
|
readonly previewEnabled: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Switch the CMS reads to a draft preview session's same-origin proxy, for good: every
|
|
175
|
+
* `getEntries`/`getEntry`/`getEntryByUniqueField`/`resolveEntryListField`/`resolveEntryList` goes
|
|
176
|
+
* to `proxyBase` + the gateway path, with `cache: 'no-store'`, `credentials: 'same-origin'` and
|
|
177
|
+
* **no credential header** (no `X-Org-Id`, `X-Preview-Token` or build token; the router adds what
|
|
178
|
+
* Core needs). A CMS answer without `Eldra-Preview: draft` is refused (`502`,
|
|
179
|
+
* `PREVIEW_UPSTREAM_NOT_PREVIEW`) rather than shown, so a published answer never passes for a
|
|
180
|
+
* draft. Catalog reads stay on `gatewayUrl`, published and unchanged. From then on no request
|
|
181
|
+
* carries `X-Preview-Token`, whatever `enablePreview` is given.
|
|
182
|
+
*
|
|
183
|
+
* **Optional**, like `onRequestError`: a hand-written client predates it, and a caller that cannot
|
|
184
|
+
* find it has no session preview to offer.
|
|
185
|
+
*/
|
|
186
|
+
enableSessionPreview?(options: EldraSessionPreviewOptions): void;
|
|
187
|
+
/** Whether `enableSessionPreview` has been called. Optional for the same reason. */
|
|
188
|
+
readonly sessionPreviewEnabled?: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* One of the site's own settings, as the gateway serves it (`EldraSiteReadPath`): the saved design
|
|
191
|
+
* tokens (`{ revision, resolved }`) or the resolved theme texts (`{ defaultLocale, locales }`),
|
|
192
|
+
* parsed JSON, unchecked. A build reads these once and bakes them in; a draft preview session reads
|
|
193
|
+
* them again at runtime, so a saved change shows at once (WS-1394).
|
|
194
|
+
*
|
|
195
|
+
* Outside a session, an ordinary gateway read (`X-Org-Id`, the build token). In a session, through
|
|
196
|
+
* the router's proxy like the CMS reads (`no-store`, `credentials: 'same-origin'`, no credential
|
|
197
|
+
* header), but a site setting is not a draft: no `Eldra-Preview: draft` is asked for, the answer is
|
|
198
|
+
* not reshaped, and a failure is thrown to the caller only, never reported to `onRequestError`'s
|
|
199
|
+
* listeners — the CMS reads are what say whether the session holds, and a router that does not
|
|
200
|
+
* forward a site read yet must not end the session.
|
|
201
|
+
*
|
|
202
|
+
* **Optional**, like `enableSessionPreview`: a hand-written client predates it.
|
|
203
|
+
*/
|
|
204
|
+
getSiteSetting?(path: EldraSiteReadPath): Promise<unknown>;
|
|
146
205
|
/**
|
|
147
206
|
* Subscribe to failed gateway requests; returns an unsubscribe.
|
|
148
207
|
*
|
|
@@ -256,4 +315,4 @@ interface TemplateLayoutContext {
|
|
|
256
315
|
reusableComponentProjection?: ReusableComponentProjection;
|
|
257
316
|
}
|
|
258
317
|
declare function createTemplateLayoutRenderModel(value: unknown, context: TemplateLayoutContext): TemplateLayoutRenderModel;
|
|
259
|
-
export {
|
|
318
|
+
export { EntryQuery as C, EntryList as S, ResolveEntryListBody as T, EldraClientOptions as _, TemplateLayoutDocument as a, EldraSiteReadPath as b, TemplateLayoutRenderNode as c, CatalogDoc as d, CatalogList as f, EldraClientError as g, EldraClient as h, TemplateLayoutContext as i, buildTemplateBlockRenames as l, EldraCatalogReader as m, TemplateBlockFieldDefinition as n, TemplateLayoutNode as o, CatalogQuery as p, TemplateBlockNode as r, TemplateLayoutRenderModel as s, TemplateBlockDefinition as t, createTemplateLayoutRenderModel as u, EldraRetryOptions as v, PageMeta as w, EntryDoc as x, EldraSessionPreviewOptions as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Framework-free core of the Eldra theme SDK: the Studio preview bridge, stega encoding, the overlay runtime, layout CSS, rich-text positions, design tokens and image framing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|