@eldrajs/theme-core 0.4.0 → 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 +12 -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 +18 -5
- package/dist/index.js +30 -13
- 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 +1 -1
- package/dist/preview-router.d.ts +1 -1
- package/dist/preview-router.js +13 -3
- package/dist/stega.d.ts +21 -0
- package/dist/stega.js +7 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,11 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- A price in a rich-text field edited on the canvas is a chip (`contenteditable=false`, styled like a plain-text field's) rather than editable page text. A click on it, once the field has focus, posts `theme:price-clicked` with the `price` node's `pos` and an empty `token` (WS-1474).
|
|
9
|
+
- `isBlockFieldLocalized` follows a data path into a `list` row (`items.0.answer`), as `isBlockFieldSelect` already did, so `EldraRichText` with `api-id` reports a list row's localized rich text with its locale. Before, it reported `locale: null`, Studio refused it, and typing on the canvas did nothing (WS-1474).
|
|
10
|
+
- **Priced text edited on the canvas (WS-1474).** New capability `price-tokens-inline`, new messages `theme:price-clicked` and `editor:insert-price`. A field whose stega carries `StegaMeta.parts` (its stored text, each price token with its label) is editable in place once both sides advertise it: focusing it shows each price as a non-editable chip (amber when missing), every edit is posted as stored text with its tokens intact, a chip click posts `theme:price-clicked` (the first click on a written-out price only focuses the field), and `editor:insert-price` inserts a price at the caret. The renderer's writes are held while the field is being edited; a price's new amounts update its chip in place. `OverlayRuntime` gains `setPriceTokensEnabled` and `insertPriceToken`; `StegaPricePart` is exported.
|
|
11
|
+
- The preview overlay no longer copies a draft's raw text over a field marked `inline: false` on `editor:content-update`: a field whose price tokens the theme wrote out showed the raw `⟦price#…⟧` in the builder after every edit (WS-1474).
|
|
12
|
+
- **Price tokens (WS-1474).** `buildRichTextTree` takes `resolvePrice`: a `price` node renders its written price as a leaf (one position, like a hard break), and a paragraph holding one that cannot be written stays in the tree, `hidden`, so the builder's positions still count it. `StegaMeta.inline: false` marks a field whose page text is not its stored text: the overlay keeps it selectable (`theme:field-clicked`) but never makes it editable in place.
|
|
8
13
|
- **`resolveLink` resolves cards (WS-1326).** A child or section link whose `display` is `card` (its
|
|
9
14
|
own, else its section's) carries `card: { image, title, price? }`: the image is the link's own
|
|
10
15
|
`imageUrl`, else the target's (`LinkTargetInfo.image`: a product's thumbnail, a collection's
|
|
@@ -96,16 +101,16 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
96
101
|
`catalog:product` and another theme's `starter:hero` pass through) and
|
|
97
102
|
`themeSchemaApiId(blockApiId, themeId)` (the reverse, idempotent), plus `THEME_ID_PATTERN`,
|
|
98
103
|
`RESERVED_THEME_IDS`, `registerThemeId`/`getRegisteredThemeId`. **Breaking:** `registerBlockFields(fields,
|
|
99
|
-
|
|
104
|
+
themeId)` now requires the theme's own id and registers it, so `isBlockFieldLocalized`,
|
|
100
105
|
`isBlockFieldSelect` (and the select unwrap and stega skip that use it) and a template block's
|
|
101
106
|
entry/placement match resolve a block entry whose `schemaApiId` is `<themeId>:<apiId>`. Bare ids
|
|
102
107
|
keep working. The bridge's `theme:ready` reports `manifestVersion: 2`.
|
|
103
108
|
|
|
104
109
|
- New subpath, `@eldrajs/theme-core/i18n`, framework-free: `flattenMessages`/`unflattenMessages`
|
|
105
110
|
(nested vue-i18n JSON ↔ the manifest's own flat dotted keys), `mergeMessageCatalogues(themeDefaults,
|
|
106
|
-
|
|
111
|
+
platform)` (the platform's theme-message overrides win per key; a locale the theme never shipped
|
|
107
112
|
is added whole), and `resolveMessageCatalogue(themeDefaults, platform, orgLocales,
|
|
108
|
-
|
|
113
|
+
orgDefaultLocale)`, implementing the contract's five-tier per-key fallback to the letter — tier 5
|
|
109
114
|
(`theme(themeDefault)`) always reads the theme's own unmerged default-locale text, never an
|
|
110
115
|
override of it, which is why `themeDefaults` and `platform` are taken separately rather than only
|
|
111
116
|
a pre-merged catalogue — so a build with **no** gateway still produces a full key set for every
|
|
@@ -121,7 +126,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
121
126
|
|
|
122
127
|
- **A `link` field's untranslated sub-fields fall back to the default locale's node, field by
|
|
123
128
|
field.** A `link` field's value is a per-locale record (`{ "en-US": {kind,label,group,children…},
|
|
124
|
-
|
|
129
|
+
"is-IS": {…} }`), and `createEldraClient` used to take the active locale's node whole (exact
|
|
125
130
|
locale, then language, then the first key) — a column heading set only on the English node
|
|
126
131
|
rendered as no heading at all on every other locale. `createEldraClient` now takes
|
|
127
132
|
`defaultLocale?: string | null` (the organisation's default content locale); when set and the
|
|
@@ -159,7 +164,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
159
164
|
- **A route template's trailing parameter may be a catch-all: `/categories/:path*`.** It must be the
|
|
160
165
|
last segment, it matches **one or more** segments, and the parameter's value is the remainder
|
|
161
166
|
joined with `/` and no leading slash (`/categories/billinn/bilstolar` → `path:
|
|
162
|
-
|
|
167
|
+
"billinn/bilstolar"`). `parseDynamicRoutePattern` reports it as `catchAll: true` and keeps the star
|
|
163
168
|
out of `paramName`, so a template's own `slugField` is still compared against `path`;
|
|
164
169
|
`matchDynamicRoutePattern`/`resolveRoute` match it, and `buildDynamicRoutePath` encodes each
|
|
165
170
|
segment of such a value while keeping the separators (and refuses an empty one — a leading,
|
|
@@ -203,7 +208,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
203
208
|
- Inline canvas editing no longer depends on when the overlay's own `input` handler runs relative
|
|
204
209
|
to the MutationObserver that sees the keystroke land, nor on how long the editor's round trip
|
|
205
210
|
takes. `restoreEditingFocus` answers every characterData mutation in the document, so it can run
|
|
206
|
-
|
|
211
|
+
_before_ `onInput` — a single `input` listener anywhere on the page registered ahead of the
|
|
207
212
|
overlay's own puts a microtask checkpoint between the two, and a checkpoint is where queued
|
|
208
213
|
observer records are delivered. It used to re-place the caret from the remembered offset on every
|
|
209
214
|
such pass, which put the caret back in front of the character just typed and, because the next
|
|
@@ -281,7 +286,7 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
281
286
|
- Feat: a new theme → editor bridge message, `theme:block-hovered`, reports the block the pointer
|
|
282
287
|
is over — `{ entryId, rect, layoutNodeId?, reusablePlacementId? }`, or `null` once it leaves — so
|
|
283
288
|
the editor can anchor an affordance (an "add block" control on the block's bottom edge) to the
|
|
284
|
-
same geometry the theme already outlines. It is posted when the hovered
|
|
289
|
+
same geometry the theme already outlines. It is posted when the hovered _block_ changes, not on
|
|
285
290
|
every pointer move inside it, and re-posted whenever the theme's geometry may have moved, so a
|
|
286
291
|
re-post can repeat the rect it last sent. Edit mode only, and gated on the new `block-hover`
|
|
287
292
|
capability: an editor that does not advertise it receives nothing. The theme's own hover outline
|
|
@@ -32,6 +32,7 @@ const KNOWN_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
|
32
32
|
"editor:design-tokens",
|
|
33
33
|
"editor:theme-messages",
|
|
34
34
|
"editor:select-block",
|
|
35
|
+
"editor:insert-price",
|
|
35
36
|
"editor:navigate",
|
|
36
37
|
"editor:set-mode",
|
|
37
38
|
"editor:set-viewport",
|
|
@@ -49,6 +50,7 @@ const KNOWN_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
|
49
50
|
"theme:block-clicked",
|
|
50
51
|
"theme:field-clicked",
|
|
51
52
|
"theme:text-edited",
|
|
53
|
+
"theme:price-clicked",
|
|
52
54
|
"theme:blocks-rendered",
|
|
53
55
|
"theme:block-hovered",
|
|
54
56
|
"theme:slots-rendered",
|
|
@@ -74,7 +76,8 @@ const EDITOR_CAPABILITIES = [
|
|
|
74
76
|
"block-slots",
|
|
75
77
|
"block-hover",
|
|
76
78
|
"image-framing",
|
|
77
|
-
"rich-text-inline"
|
|
79
|
+
"rich-text-inline",
|
|
80
|
+
"price-tokens-inline"
|
|
78
81
|
];
|
|
79
82
|
/** Capabilities the theme advertises in theme:ready. `block-slots` gates the
|
|
80
83
|
* editor-only slot markers and their theme:slots-rendered geometry reports.
|
|
@@ -83,13 +86,16 @@ const EDITOR_CAPABILITIES = [
|
|
|
83
86
|
* §18 v3 messages that let the operator edit rich text natively in the
|
|
84
87
|
* theme's own rendered DOM while Studio owns the document, the editor and
|
|
85
88
|
* the toolbar; a side that does not advertise it never sends, and must
|
|
86
|
-
* ignore, those messages.
|
|
89
|
+
* ignore, those messages. `price-tokens-inline` gates editing a plain-text field that holds price
|
|
90
|
+
* tokens on the canvas: the field shows each price as a chip, `theme:price-clicked` and
|
|
91
|
+
* `editor:insert-price`. Without it such a field stays selectable but not editable in place. */
|
|
87
92
|
const THEME_CAPABILITIES = [
|
|
88
93
|
"design-tokens",
|
|
89
94
|
"block-slots",
|
|
90
95
|
"block-hover",
|
|
91
96
|
"image-framing",
|
|
92
|
-
"rich-text-inline"
|
|
97
|
+
"rich-text-inline",
|
|
98
|
+
"price-tokens-inline"
|
|
93
99
|
];
|
|
94
100
|
// src/bridge/envelope.ts
|
|
95
101
|
function makeEnvelope(type, payload) {
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as RichTextDoc, D as ThemeRichTextCommandMessage, E as THEME_CAPABILITIES, O as ThemeRichTextInputMessage, S as RichTextCommandName, T as StructuralDragPayload, _ as EditorRichTextLocateMessage, a as BRIDGE_PROTOCOL, b as ResolvedDesignTokensPayload, c as BridgeHandler, d as DOMRectLike, f as DraftEntryPayload, g as EditorRichTextEditingMessage, h as EditorRichTextAppliedMessage, i as parseEnvelope, k as ThemeRichTextSelectionMessage, l as BridgeMessageType, m as EditorMode, n as createEditorBridge, o as BRIDGE_VERSION, p as EDITOR_CAPABILITIES, r as makeEnvelope, s as BridgeEnvelope, t as createThemeBridge, u as BridgePayloads, v as KNOWN_MESSAGE_TYPES, w as RichTextIdentity, x as ResolvedThemeMessagesPayload, y as RICH_TEXT_COMMAND_NAMES } from "./index-
|
|
1
|
+
import { C as RichTextDoc, D as ThemeRichTextCommandMessage, E as THEME_CAPABILITIES, O as ThemeRichTextInputMessage, S as RichTextCommandName, T as StructuralDragPayload, _ as EditorRichTextLocateMessage, a as BRIDGE_PROTOCOL, b as ResolvedDesignTokensPayload, c as BridgeHandler, d as DOMRectLike, f as DraftEntryPayload, g as EditorRichTextEditingMessage, h as EditorRichTextAppliedMessage, i as parseEnvelope, k as ThemeRichTextSelectionMessage, l as BridgeMessageType, m as EditorMode, n as createEditorBridge, o as BRIDGE_VERSION, p as EDITOR_CAPABILITIES, r as makeEnvelope, s as BridgeEnvelope, t as createThemeBridge, u as BridgePayloads, v as KNOWN_MESSAGE_TYPES, w as RichTextIdentity, x as ResolvedThemeMessagesPayload, y as RICH_TEXT_COMMAND_NAMES } from "./index-C_Kx7Vq9.js";
|
|
2
2
|
export { BRIDGE_PROTOCOL, BRIDGE_VERSION, type BridgeEnvelope, type BridgeHandler, type BridgeMessageType, type BridgePayloads, type DOMRectLike, type DraftEntryPayload, EDITOR_CAPABILITIES, type EditorMode, type EditorRichTextAppliedMessage, type EditorRichTextEditingMessage, type EditorRichTextLocateMessage, KNOWN_MESSAGE_TYPES, RICH_TEXT_COMMAND_NAMES, type ResolvedDesignTokensPayload, type ResolvedThemeMessagesPayload, type RichTextCommandName, type RichTextDoc, type RichTextIdentity, type StructuralDragPayload, THEME_CAPABILITIES, type ThemeRichTextCommandMessage, type ThemeRichTextInputMessage, type ThemeRichTextSelectionMessage, createEditorBridge, createThemeBridge, makeEnvelope, parseEnvelope };
|
package/dist/bridge.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { a as BRIDGE_PROTOCOL, o as BRIDGE_VERSION, s as EDITOR_CAPABILITIES, c as KNOWN_MESSAGE_TYPES, l as RICH_TEXT_COMMAND_NAMES, u as THEME_CAPABILITIES, n as createEditorBridge, t as createThemeBridge, r as makeEnvelope, i as parseEnvelope } from "./bridge-
|
|
1
|
+
export { a as BRIDGE_PROTOCOL, o as BRIDGE_VERSION, s as EDITOR_CAPABILITIES, c as KNOWN_MESSAGE_TYPES, l as RICH_TEXT_COMMAND_NAMES, u as THEME_CAPABILITIES, n as createEditorBridge, t as createThemeBridge, r as makeEnvelope, i as parseEnvelope } from "./bridge-CCF1LxsP.js";
|
|
@@ -216,6 +216,20 @@ interface BridgePayloads {
|
|
|
216
216
|
layoutNodeId?: string;
|
|
217
217
|
reusablePlacementId?: string;
|
|
218
218
|
};
|
|
219
|
+
/**
|
|
220
|
+
* `price-tokens-inline`: put a price token into a plain-text field at the operator's caret on
|
|
221
|
+
* the canvas (at the end when the field is not being edited there), as a chip reading `label`.
|
|
222
|
+
* The theme answers with `theme:text-edited` carrying the field's new stored text.
|
|
223
|
+
*/
|
|
224
|
+
'editor:insert-price': {
|
|
225
|
+
entryId: string;
|
|
226
|
+
fieldPath: string;
|
|
227
|
+
locale: string | null;
|
|
228
|
+
token: string;
|
|
229
|
+
label: string;
|
|
230
|
+
layoutNodeId?: string;
|
|
231
|
+
reusablePlacementId?: string;
|
|
232
|
+
};
|
|
219
233
|
'editor:navigate': {
|
|
220
234
|
path: string;
|
|
221
235
|
};
|
|
@@ -307,6 +321,23 @@ interface BridgePayloads {
|
|
|
307
321
|
layoutNodeId?: string;
|
|
308
322
|
reusablePlacementId?: string;
|
|
309
323
|
};
|
|
324
|
+
/**
|
|
325
|
+
* `price-tokens-inline`: the operator clicked a price chip in a field being edited on the
|
|
326
|
+
* canvas. `token` is the token's stored text (`⟦price#a3f EUR=10000⟧`, `⟦store
|
|
327
|
+
* freeShippingThreshold⟧`); Studio opens its price editor for it and writes the field's draft.
|
|
328
|
+
* In a rich-text field `token` is empty and `pos` is the `price` node's document position, which
|
|
329
|
+
* Studio reads from its own editor.
|
|
330
|
+
*/
|
|
331
|
+
'theme:price-clicked': {
|
|
332
|
+
entryId: string;
|
|
333
|
+
fieldPath: string;
|
|
334
|
+
locale: string | null;
|
|
335
|
+
token: string;
|
|
336
|
+
pos?: number;
|
|
337
|
+
rect: DOMRectLike;
|
|
338
|
+
layoutNodeId?: string;
|
|
339
|
+
reusablePlacementId?: string;
|
|
340
|
+
};
|
|
310
341
|
'theme:blocks-rendered': {
|
|
311
342
|
blocks: Array<{
|
|
312
343
|
entryId: string;
|
|
@@ -439,7 +470,7 @@ declare const KNOWN_MESSAGE_TYPES: ReadonlySet<string>;
|
|
|
439
470
|
* Capabilities advertised in editor:hello. Single source of truth is contracts §8b.1/§8b.13:
|
|
440
471
|
* the list below, matched verbatim by Studio's vendored app/types/bridge.ts.
|
|
441
472
|
*/
|
|
442
|
-
declare const EDITOR_CAPABILITIES: readonly ["content-update", "select-block", "inline-text", "block-slots", "block-hover", "image-framing", "rich-text-inline"];
|
|
473
|
+
declare const EDITOR_CAPABILITIES: readonly ["content-update", "select-block", "inline-text", "block-slots", "block-hover", "image-framing", "rich-text-inline", "price-tokens-inline"];
|
|
443
474
|
/** Capabilities the theme advertises in theme:ready. `block-slots` gates the
|
|
444
475
|
* editor-only slot markers and their theme:slots-rendered geometry reports.
|
|
445
476
|
* `block-hover` gates theme:block-hovered, the hovered block's identity and
|
|
@@ -447,8 +478,10 @@ declare const EDITOR_CAPABILITIES: readonly ["content-update", "select-block", "
|
|
|
447
478
|
* §18 v3 messages that let the operator edit rich text natively in the
|
|
448
479
|
* theme's own rendered DOM while Studio owns the document, the editor and
|
|
449
480
|
* the toolbar; a side that does not advertise it never sends, and must
|
|
450
|
-
* ignore, those messages.
|
|
451
|
-
|
|
481
|
+
* ignore, those messages. `price-tokens-inline` gates editing a plain-text field that holds price
|
|
482
|
+
* tokens on the canvas: the field shows each price as a chip, `theme:price-clicked` and
|
|
483
|
+
* `editor:insert-price`. Without it such a field stays selectable but not editable in place. */
|
|
484
|
+
declare const THEME_CAPABILITIES: readonly ["design-tokens", "block-slots", "block-hover", "image-framing", "rich-text-inline", "price-tokens-inline"];
|
|
452
485
|
declare function makeEnvelope<T extends BridgeMessageType>(type: T, payload: BridgePayloads[T]): BridgeEnvelope<T>;
|
|
453
486
|
/** Returns null for anything that must be ignored; logs per contracts §1.4. */
|
|
454
487
|
declare function parseEnvelope(data: unknown): BridgeEnvelope | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { StegaMeta, decodeStega, encodeStega, stripStega } from "./stega.js";
|
|
1
|
+
import { StegaMeta, StegaPricePart, decodeStega, encodeStega, stripStega } from "./stega.js";
|
|
2
2
|
import { C as EntryQuery, S as EntryList, T as ResolveEntryListBody, _ as EldraClientOptions, a as TemplateLayoutDocument, b as EldraSiteReadPath, c as TemplateLayoutRenderNode, d as CatalogDoc, f as CatalogList, g as EldraClientError, h as EldraClient, i as TemplateLayoutContext, l as buildTemplateBlockRenames, m as EldraCatalogReader, n as TemplateBlockFieldDefinition, o as TemplateLayoutNode, p as CatalogQuery, r as TemplateBlockNode, s as TemplateLayoutRenderModel, t as TemplateBlockDefinition, u as createTemplateLayoutRenderModel, v as EldraRetryOptions, w as PageMeta, x as EntryDoc, y as EldraSessionPreviewOptions } from "./templateLayout-BWNs1ZYt.js";
|
|
3
3
|
import { a as buildDynamicRoutePath, c as parseDynamicRoutePattern, d as resolvePagePath, i as RouteTemplateLike, l as resolveRoute, n as MAX_DYNAMIC_ROUTE_PATTERN_BYTES, o as catalogRouteTarget, r as ParsedDynamicRoutePattern, s as matchDynamicRoutePattern, t as DynamicRouteResolution, u as PageLike } from "./dynamicRoute-DzSNn4tV.js";
|
|
4
|
-
import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-
|
|
4
|
+
import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-D7gS7OY1.js";
|
|
5
5
|
import { A as generateLayoutCss, C as Responsive, D as WidthLength, E as Spacing, F as resolveLayoutBreakpoints, I as resolveLayoutDocument, L as validateLayoutDocument, M as layoutNodeClass, N as layoutRenderNodeId, O as activeLayoutBreakpoint, P as normalizeLayoutDocument, S as ResolvedLayoutStyle, T as SlotValidationContext, _ as LayoutValidationError, a as LAYOUT_BREAKPOINTS, b as ResolvedLayoutDocument, c as LayoutBreakpoints, d as LayoutNode, f as LayoutRenderBlockNode, g as LayoutValidationCode, h as LayoutStyle, i as EDIT_MODE_HIDDEN_OPACITY, j as hiddenLayoutBreakpoints, k as createLayoutRenderModel, l as LayoutContainerNode, m as LayoutRenderNode, n as CssLength, o as LayoutBlockNode, p as LayoutRenderModel, r as DEFAULT_LAYOUT_BREAKPOINTS, s as LayoutBreakpoint, t as BlockSlotDefinition, u as LayoutDocument, v as LayoutValidationIssue, w as SizingLength, x as ResolvedLayoutNode, y as NormalizedLayoutResult } from "./layout-CkPOfiOM.js";
|
|
6
6
|
import { PageLayoutDocument, PageLayoutNode, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, asPublicRead, createReusableLayoutRenderModel, expandReusableLayout } from "./reusable.js";
|
|
7
7
|
import { ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssTokenLength, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, ResponsiveTokenValue, SiteDesignTokenOverrides, ThemeColorToken, ThemeDesignTokens, applyDesignTokenOverrides, designTokenRevisionHash, generateDesignTokenCss, generateTailwindThemeCss, normalizeColorSelection, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, resolveColorSelection, resolveDesignTokenCatalog, responsiveValue } from "./design-tokens.js";
|
|
@@ -219,6 +219,18 @@ interface BuildRichTextTreeOptions {
|
|
|
219
219
|
* an `<h0>`/`<h7>` whatever a caller passes.
|
|
220
220
|
*/
|
|
221
221
|
minHeadingLevel?: number;
|
|
222
|
+
/**
|
|
223
|
+
* Writes a `price` node (a price token in rich text, WS-1474) in the shopper's currency, or
|
|
224
|
+
* answers `null` when it cannot be: no amount in that currency, an unknown store setting,
|
|
225
|
+
* malformed attributes. The theme supplies it (`@eldrajs/sdk/tokens`' `resolvePriceNode`, bound to
|
|
226
|
+
* its currency, regional locale and formatter); without one no price resolves.
|
|
227
|
+
*
|
|
228
|
+
* A paragraph or heading holding a price that does not resolve is rendered `hidden` rather than
|
|
229
|
+
* left out, so it still occupies its positions and native editing maps exactly as before: a
|
|
230
|
+
* missing amount reads as a shorter text, never as a sentence with a hole in it, and never as
|
|
231
|
+
* another currency's amount.
|
|
232
|
+
*/
|
|
233
|
+
resolvePrice?: (attrs: unknown) => string | null;
|
|
222
234
|
}
|
|
223
235
|
/**
|
|
224
236
|
* Build a TipTap JSON document's content as a render tree. Non-doc input
|
|
@@ -247,7 +259,7 @@ export declare function buildRichTextTree(doc: unknown, options: BuildRichTextTr
|
|
|
247
259
|
* it **closes** (+1) after them;
|
|
248
260
|
* - a text node occupies `text.length` — UTF-16 code units, which is what
|
|
249
261
|
* ProseMirror counts, so an astral-plane character (an emoji) is 2;
|
|
250
|
-
* - a leaf node (`image`, `hardBreak`, `horizontalRule`, `embed`) occupies 1.
|
|
262
|
+
* - a leaf node (`image`, `hardBreak`, `horizontalRule`, `embed`, `price`) occupies 1.
|
|
251
263
|
*
|
|
252
264
|
* `packages/theme-core/test/fixtures/rich-text-positions.fixture.json` pins
|
|
253
265
|
* the numbering for a set of documents and is copied byte-for-byte into
|
|
@@ -432,7 +444,8 @@ type BlockFieldsMap = Record<string, BlockFieldDefinition[]>;
|
|
|
432
444
|
*/
|
|
433
445
|
export declare function registerBlockFields(fields: BlockFieldsMap, themeId: string): void;
|
|
434
446
|
/**
|
|
435
|
-
* Whether the manifest marks this block field `localized
|
|
447
|
+
* Whether the manifest marks this block field `localized`: a top-level field id, or a data path
|
|
448
|
+
* into a `list`'s item (`items.0.answer`, see `resolveBlockField`). A rich-text
|
|
436
449
|
* renderer uses it to default an omitted `locale` to the preview's active
|
|
437
450
|
* content locale — a localized field's draft is keyed per locale, so the
|
|
438
451
|
* marking attributes (and therefore every §18 v3 rich-text report) must carry
|
|
@@ -860,4 +873,4 @@ export declare function offeredCurrencies(base: string, listed: readonly unknown
|
|
|
860
873
|
export declare const VISITOR_COUNTRY_PATH = "/_eldra/visitor";
|
|
861
874
|
/** A two-letter country from `CF-IPCountry`, or `null` for none, unknown (`XX`) or Tor (`T1`). */
|
|
862
875
|
export declare function countryFromHeader(value: string | null | undefined): string | null;
|
|
863
|
-
export { type BeforeInputClassification, type BlockFieldDefinition, type BlockFieldsMap, BlockSlotDefinition, type BuildRichTextTreeOptions, CatalogDoc, CatalogList, CatalogQuery, ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssLength, CssTokenLength, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, DynamicRouteResolution, EDIT_MODE_HIDDEN_OPACITY, EldraCatalogReader, EldraClient, EldraClientError, EldraClientOptions, EldraRetryOptions, EldraSessionPreviewOptions, EldraSiteReadPath, EntryDoc, EntryList, EntryQuery, FrameRect, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, ImageFraming, LAYOUT_BREAKPOINTS, LayoutBlockNode, LayoutBreakpoint, LayoutBreakpoints, LayoutContainerNode, LayoutDocument, LayoutNode, LayoutRenderBlockNode, LayoutRenderModel, LayoutRenderNode, LayoutStyle, LayoutValidationCode, LayoutValidationError, LayoutValidationIssue, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, type NegotiatedEditorCapabilities, NormalizedLayoutResult, type OverlayRuntime, type OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, PageLayoutDocument, PageLayoutNode, type PageLike, PageMeta, ParsedDynamicRoutePattern, type PreviewMessageRouter, type PreviewRouterMessageType, ResolveEntryListBody, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutStyle, Responsive, ResponsiveTokenValue, type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, type ReusableRenderIdentity, type RichTextDomPoint, type RichTextFieldIdentity, type RichTextMark, type RichTextNode, type RichTextPositionNode, type RichTextPositions, type RichTextRenderChild, type RichTextRenderNode, type RichTextRenderStateChange, type RichTextSelectionContext, type RichTextToolbarControl, RouteTemplateLike, SiteDesignTokenOverrides, SizingLength, SlotValidationContext, Spacing, type StegaMeta, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, ThemeColorToken, ThemeDesignTokens, WidthLength, activeLayoutBreakpoint, applyDesignTokenOverrides, asPublicRead, buildDynamicRoutePath, buildTemplateBlockRenames, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, designTokenRevisionHash, encodeStega, expandReusableLayout, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, layoutNodeClass, layoutRenderNodeId, matchDynamicRoutePattern, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, resolveColorSelection, resolveDesignTokenCatalog, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, responsiveValue, stripStega, unscaledFrameRect, validateLayoutDocument };
|
|
876
|
+
export { type BeforeInputClassification, type BlockFieldDefinition, type BlockFieldsMap, BlockSlotDefinition, type BuildRichTextTreeOptions, CatalogDoc, CatalogList, CatalogQuery, ColorLiteral, ColorSelection, ContainerOverride, ContainerPreset, CssLength, CssTokenLength, DEFAULT_IMAGE_FRAMING, DEFAULT_LAYOUT_BREAKPOINTS, DesignTokenCatalog, DesignTokenId, DesignTokenValidationCode, DesignTokenValidationError, DynamicRouteResolution, EDIT_MODE_HIDDEN_OPACITY, EldraCatalogReader, EldraClient, EldraClientError, EldraClientOptions, EldraRetryOptions, EldraSessionPreviewOptions, EldraSiteReadPath, EntryDoc, EntryList, EntryQuery, FrameRect, IMAGE_FRAMING_MAX_ZOOM, IMAGE_FRAMING_MIN_ZOOM, ImageFraming, LAYOUT_BREAKPOINTS, LayoutBlockNode, LayoutBreakpoint, LayoutBreakpoints, LayoutContainerNode, LayoutDocument, LayoutNode, LayoutRenderBlockNode, LayoutRenderModel, LayoutRenderNode, LayoutStyle, LayoutValidationCode, LayoutValidationError, LayoutValidationIssue, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, type NegotiatedEditorCapabilities, NormalizedLayoutResult, type OverlayRuntime, type OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, PageLayoutDocument, PageLayoutNode, type PageLike, PageMeta, ParsedDynamicRoutePattern, type PreviewMessageRouter, type PreviewRouterMessageType, ResolveEntryListBody, ResolvedLayoutDocument, ResolvedLayoutNode, ResolvedLayoutStyle, Responsive, ResponsiveTokenValue, type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, ReusableComponentSnapshotCache, ReusableLayoutOptions, ReusableLayoutRenderModel, ReusableLayoutRenderNode, ReusablePerspective, type ReusableRenderIdentity, type RichTextDomPoint, type RichTextFieldIdentity, type RichTextMark, type RichTextNode, type RichTextPositionNode, type RichTextPositions, type RichTextRenderChild, type RichTextRenderNode, type RichTextRenderStateChange, type RichTextSelectionContext, type RichTextToolbarControl, RouteTemplateLike, SiteDesignTokenOverrides, SizingLength, SlotValidationContext, Spacing, type StegaMeta, type StegaPricePart, TemplateBlockDefinition, TemplateBlockFieldDefinition, TemplateBlockNode, TemplateLayoutContext, TemplateLayoutDocument, TemplateLayoutNode, TemplateLayoutRenderModel, TemplateLayoutRenderNode, ThemeColorToken, ThemeDesignTokens, WidthLength, activeLayoutBreakpoint, applyDesignTokenOverrides, asPublicRead, buildDynamicRoutePath, buildTemplateBlockRenames, catalogRouteTarget, clampFocal, clampImageFraming, classifyBeforeInput, createLayoutRenderModel, createOverlayRuntime, createPreviewMessageRouter, createProjectionResolver, createReusableLayoutRenderModel, createTemplateLayoutRenderModel, decodeStega, designTokenRevisionHash, encodeStega, expandReusableLayout, focalBand, framingDrag, framingZoom, generateDesignTokenCss, generateLayoutCss, generateTailwindThemeCss, hiddenLayoutBreakpoints, imageFramingAttrs, imageFramingStyle, layoutNodeClass, layoutRenderNodeId, matchDynamicRoutePattern, normalizeColorSelection, normalizeImageFraming, normalizeLayoutDocument, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, parseDynamicRoutePattern, parseImageFramingValueAttr, resolveColorSelection, resolveDesignTokenCatalog, resolveLayoutBreakpoints, resolveLayoutDocument, resolvePagePath, resolveRoute, responsiveValue, stripStega, unscaledFrameRect, validateLayoutDocument };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { a as blockApiIdOf, c as registeredBlockApiId, i as THEME_ID_PATTERN, l
|
|
|
3
3
|
import { ReusableComponentSnapshotCache, asPublicRead, createReusableLayoutRenderModel, expandReusableLayout } from "./reusable.js";
|
|
4
4
|
import { r as createProjectionResolver } from "./reusableExpansion-Cg9AE8JX.js";
|
|
5
5
|
import { a as parseDynamicRoutePattern, i as matchDynamicRoutePattern, n as buildDynamicRoutePath, o as resolveRoute, r as catalogRouteTarget, s as resolvePagePath, t as MAX_DYNAMIC_ROUTE_PATTERN_BYTES } from "./dynamicRoute-k60idORj.js";
|
|
6
|
-
import { a as RICH_TEXT_PAD_ATTR, c as domRangeToPositions, d as restampRichTextPositions, f as richTextMarkNameOf, h as layoutIdentityOf, i as RICH_TEXT_MARK_ELEMENTS, l as resolveDomPoint, m as richTextText, n as createOverlayRuntime, o as computeRichTextPositions, p as richTextNodeSize, r as RICH_TEXT_LEAF_TYPES, s as describeSelectionContext, t as classifyBeforeInput, u as resolveDomPosition } from "./overlay-
|
|
6
|
+
import { a as RICH_TEXT_PAD_ATTR, c as domRangeToPositions, d as restampRichTextPositions, f as richTextMarkNameOf, h as layoutIdentityOf, i as RICH_TEXT_MARK_ELEMENTS, l as resolveDomPoint, m as richTextText, n as createOverlayRuntime, o as computeRichTextPositions, p as richTextNodeSize, r as RICH_TEXT_LEAF_TYPES, s as describeSelectionContext, t as classifyBeforeInput, u as resolveDomPosition } from "./overlay-C6lCvEGm.js";
|
|
7
7
|
import { PREVIEW_ROUTER_MESSAGE_TYPES, createPreviewMessageRouter } from "./preview-router.js";
|
|
8
8
|
import { DEFAULT_LAYOUT_BREAKPOINTS, EDIT_MODE_HIDDEN_OPACITY, LAYOUT_BREAKPOINTS, LayoutValidationError, activeLayoutBreakpoint, createLayoutRenderModel, generateLayoutCss, hiddenLayoutBreakpoints, layoutNodeClass, layoutRenderNodeId, normalizeLayoutDocument, resolveLayoutBreakpoints, resolveLayoutDocument, validateLayoutDocument } from "./layout.js";
|
|
9
9
|
import { DesignTokenValidationError, applyDesignTokenOverrides, designTokenRevisionHash, generateDesignTokenCss, generateTailwindThemeCss, normalizeColorSelection, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, resolveColorSelection, resolveDesignTokenCatalog, responsiveValue } from "./design-tokens.js";
|
|
@@ -29,7 +29,8 @@ function registerBlockFields(fields, themeId) {
|
|
|
29
29
|
registerThemeId(themeId);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* Whether the manifest marks this block field `localized
|
|
32
|
+
* Whether the manifest marks this block field `localized`: a top-level field id, or a data path
|
|
33
|
+
* into a `list`'s item (`items.0.answer`, see `resolveBlockField`). A rich-text
|
|
33
34
|
* renderer uses it to default an omitted `locale` to the preview's active
|
|
34
35
|
* content locale — a localized field's draft is keyed per locale, so the
|
|
35
36
|
* marking attributes (and therefore every §18 v3 rich-text report) must carry
|
|
@@ -42,10 +43,10 @@ function registerBlockFields(fields, themeId) {
|
|
|
42
43
|
*/
|
|
43
44
|
function isBlockFieldLocalized(apiId, fieldId) {
|
|
44
45
|
if (apiId === void 0) return false;
|
|
45
|
-
return registeredBlockFields[registeredBlockApiId(apiId)]
|
|
46
|
+
return resolveBlockField(registeredBlockFields[registeredBlockApiId(apiId)], fieldId.split("."))?.localized === true;
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
|
-
* Resolves the manifest
|
|
49
|
+
* Resolves the manifest definition of a block field from its dot-separated data
|
|
49
50
|
* path, descending into `list` (via `metadata.item`, projected verbatim by
|
|
50
51
|
* `blockFieldsModuleSource`) and `composite` (via `metadata.fields`) field
|
|
51
52
|
* definitions as the path requires. A path segment that is purely digits
|
|
@@ -61,31 +62,31 @@ function isBlockFieldLocalized(apiId, fieldId) {
|
|
|
61
62
|
* type other than `list`/`composite`, resolves to `undefined` — never a
|
|
62
63
|
* guess.
|
|
63
64
|
*/
|
|
64
|
-
function
|
|
65
|
+
function resolveBlockField(fields, segments) {
|
|
65
66
|
const [head, ...rest] = segments;
|
|
66
67
|
if (head === void 0) return void 0;
|
|
67
68
|
const field = fields?.find((f) => f.fieldId === head);
|
|
68
69
|
if (field === void 0) return void 0;
|
|
69
|
-
if (rest.length === 0) return field
|
|
70
|
+
if (rest.length === 0) return field;
|
|
70
71
|
if (field.type === "list") {
|
|
71
72
|
const item = field.metadata?.item;
|
|
72
73
|
if (item === null || typeof item !== "object" || Array.isArray(item)) return void 0;
|
|
73
74
|
const itemDef = item;
|
|
74
75
|
const afterIndex = /^\d+$/.test(rest[0] ?? "") ? rest.slice(1) : rest;
|
|
75
|
-
if (afterIndex.length === 0) return typeof itemDef.type === "string" ? itemDef
|
|
76
|
+
if (afterIndex.length === 0) return typeof itemDef.type === "string" ? itemDef : void 0;
|
|
76
77
|
if (itemDef.type !== "composite") return void 0;
|
|
77
|
-
return
|
|
78
|
+
return resolveBlockField(Array.isArray(itemDef.metadata?.fields) ? itemDef.metadata.fields : void 0, afterIndex);
|
|
78
79
|
}
|
|
79
80
|
if (field.type === "composite") {
|
|
80
81
|
const metaFields = field.metadata?.fields;
|
|
81
|
-
return
|
|
82
|
+
return resolveBlockField(Array.isArray(metaFields) ? metaFields : void 0, rest);
|
|
82
83
|
}
|
|
83
|
-
if (rest.every((segment) => /^\d+$/.test(segment))) return field
|
|
84
|
+
if (rest.every((segment) => /^\d+$/.test(segment))) return field;
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
87
|
* Whether the manifest marks the block field at `path` (a top-level field
|
|
87
88
|
* id, or a dot-separated data path reaching into a `list`'s composite item —
|
|
88
|
-
* see `
|
|
89
|
+
* see `resolveBlockField`) `type: "select"`. `encodeEntryDataStega` and
|
|
89
90
|
* the public/preview read path's `{value,label}` unwrap both use this to
|
|
90
91
|
* recognize a select field's resolved value (a plain string like
|
|
91
92
|
* `"primary"`/`"subtle"`, or `{value,label}` before unwrapping): a
|
|
@@ -101,7 +102,7 @@ function resolveBlockFieldType(fields, segments) {
|
|
|
101
102
|
*/
|
|
102
103
|
function isBlockFieldSelect(apiId, path) {
|
|
103
104
|
if (apiId === void 0) return false;
|
|
104
|
-
return
|
|
105
|
+
return resolveBlockField(registeredBlockFields[registeredBlockApiId(apiId)], path.split("."))?.type === "select";
|
|
105
106
|
}
|
|
106
107
|
/** Ceiling on the *computed* backoff. A `Retry-After` is honoured beyond it. */
|
|
107
108
|
const DEFAULT_RETRY_MAX_DELAY_MS = 5e3;
|
|
@@ -1162,7 +1163,10 @@ function buildNode(node, options, cursor, pos) {
|
|
|
1162
1163
|
}] : kids;
|
|
1163
1164
|
const textblockElement = (tag, attrs = {}) => [{
|
|
1164
1165
|
tag,
|
|
1165
|
-
attrs: stamp(
|
|
1166
|
+
attrs: stamp(holdsUnresolvedPrice(node.content, options) ? {
|
|
1167
|
+
...attrs,
|
|
1168
|
+
hidden: ""
|
|
1169
|
+
} : attrs),
|
|
1166
1170
|
children: padIfEmpty(children())
|
|
1167
1171
|
}];
|
|
1168
1172
|
switch (node.type) {
|
|
@@ -1195,12 +1199,25 @@ function buildNode(node, options, cursor, pos) {
|
|
|
1195
1199
|
case "tableRow": return element("tr");
|
|
1196
1200
|
case "tableHeader": return element("th", tableCellAttrs(node));
|
|
1197
1201
|
case "tableCell": return element("td", tableCellAttrs(node));
|
|
1202
|
+
case "price": {
|
|
1203
|
+
const written = options.resolvePrice?.(node.attrs) ?? null;
|
|
1204
|
+
return [{
|
|
1205
|
+
tag: "span",
|
|
1206
|
+
attrs: stamp({}),
|
|
1207
|
+
children: written === null ? [] : [written]
|
|
1208
|
+
}];
|
|
1209
|
+
}
|
|
1198
1210
|
case "image": return buildImage(node, options, stamp);
|
|
1199
1211
|
case "embed": return buildEmbed(node, options, stamp);
|
|
1200
1212
|
case "doc": return element("span");
|
|
1201
1213
|
default: return element("span");
|
|
1202
1214
|
}
|
|
1203
1215
|
}
|
|
1216
|
+
/** Whether a textblock holds a `price` node its theme cannot write: the block is then hidden. */
|
|
1217
|
+
function holdsUnresolvedPrice(content, options) {
|
|
1218
|
+
if (!Array.isArray(content)) return false;
|
|
1219
|
+
return content.some((child) => isNode(child) && child.type === "price" && (options.resolvePrice?.(child.attrs) ?? null) === null);
|
|
1220
|
+
}
|
|
1204
1221
|
function buildCodeBlock(node, attrs, children) {
|
|
1205
1222
|
const language = typeof node.attrs?.language === "string" ? node.attrs.language : null;
|
|
1206
1223
|
return [{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as RICH_TEXT_COMMAND_NAMES } from "./bridge-
|
|
1
|
+
import { l as RICH_TEXT_COMMAND_NAMES } from "./bridge-CCF1LxsP.js";
|
|
2
2
|
import { framingDrag, framingZoom, imageFramingStyle, parseImageFramingValueAttr, unscaledFrameRect } from "./image-framing.js";
|
|
3
3
|
import { activeLayoutBreakpoint } from "./layout.js";
|
|
4
4
|
import { decodeStega, stripStega } from "./stega.js";
|
|
@@ -40,7 +40,7 @@ function layoutIdentityOf(element) {
|
|
|
40
40
|
* it **closes** (+1) after them;
|
|
41
41
|
* - a text node occupies `text.length` — UTF-16 code units, which is what
|
|
42
42
|
* ProseMirror counts, so an astral-plane character (an emoji) is 2;
|
|
43
|
-
* - a leaf node (`image`, `hardBreak`, `horizontalRule`, `embed`) occupies 1.
|
|
43
|
+
* - a leaf node (`image`, `hardBreak`, `horizontalRule`, `embed`, `price`) occupies 1.
|
|
44
44
|
*
|
|
45
45
|
* `packages/theme-core/test/fixtures/rich-text-positions.fixture.json` pins
|
|
46
46
|
* the numbering for a set of documents and is copied byte-for-byte into
|
|
@@ -59,7 +59,8 @@ const RICH_TEXT_LEAF_TYPES = [
|
|
|
59
59
|
"image",
|
|
60
60
|
"hardBreak",
|
|
61
61
|
"horizontalRule",
|
|
62
|
-
"embed"
|
|
62
|
+
"embed",
|
|
63
|
+
"price"
|
|
63
64
|
];
|
|
64
65
|
const LEAF_TYPES = new Set(RICH_TEXT_LEAF_TYPES);
|
|
65
66
|
/**
|
|
@@ -745,6 +746,19 @@ function createOverlayRuntime(opts) {
|
|
|
745
746
|
/** §18 v3 capability gate: set via setRichTextEnabled, negotiated from the
|
|
746
747
|
* `rich-text-inline` capability. Defaults closed. */
|
|
747
748
|
let richTextEnabled = false;
|
|
749
|
+
/** `price-tokens-inline` gate: set via setPriceTokensEnabled. */
|
|
750
|
+
let priceTokensEnabled = false;
|
|
751
|
+
/** The rich-text root a press landed in while it already had focus: only then does a price in it open. */
|
|
752
|
+
let pressedInFocusedRichText = null;
|
|
753
|
+
/** A priced field's stored text, from its stega `parts`, kept for the editing surface. */
|
|
754
|
+
const pricedParts = /* @__PURE__ */ new WeakMap();
|
|
755
|
+
/**
|
|
756
|
+
* The priced field being edited on the canvas: its own child nodes, set aside while the surface
|
|
757
|
+
* (text plus price chips) stands in for them, and the renderer's newest text, held back until
|
|
758
|
+
* the surface ends. Putting the original nodes back keeps a renderer that patches its own text
|
|
759
|
+
* node (Vue's mixed-content case) writing to the node it owns.
|
|
760
|
+
*/
|
|
761
|
+
let priceSurface = null;
|
|
748
762
|
/** `block-hover` capability gate: set via setBlockHoverEnabled, negotiated
|
|
749
763
|
* from the editor's editor:hello capabilities. Defaults closed. */
|
|
750
764
|
let blockHoverEnabled = false;
|
|
@@ -1144,16 +1158,31 @@ function createOverlayRuntime(opts) {
|
|
|
1144
1158
|
setOrRemoveStyleProp(element, RICH_TEXT_WHITE_SPACE_PROP, prior.whiteSpace);
|
|
1145
1159
|
setOrRemoveStyleProp(element, RICH_TEXT_WORD_WRAP_PROP, prior.wordWrap);
|
|
1146
1160
|
}
|
|
1161
|
+
/** A rich-text price (a `price` leaf) drawn as a chip while its root is edited, else as page text. */
|
|
1162
|
+
function applyRichTextPrices(element, editable) {
|
|
1163
|
+
for (const price of element.querySelectorAll("[data-eldra-node=\"price\"]")) if (editable && priceTokensEnabled) {
|
|
1164
|
+
price.setAttribute("contenteditable", "false");
|
|
1165
|
+
price.setAttribute("data-eldra-rich-price", "");
|
|
1166
|
+
styleChip(price, (price.textContent ?? "") === "");
|
|
1167
|
+
} else if (price.hasAttribute("data-eldra-rich-price")) {
|
|
1168
|
+
price.removeAttribute("contenteditable");
|
|
1169
|
+
price.removeAttribute("data-eldra-rich-price");
|
|
1170
|
+
price.removeAttribute("style");
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1147
1173
|
function applyRichTextEditable() {
|
|
1148
1174
|
const editable = mode === "edit" && richTextEnabled;
|
|
1149
|
-
for (const element of root.querySelectorAll("[data-eldra-rich-text]"))
|
|
1150
|
-
element
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1175
|
+
for (const element of root.querySelectorAll("[data-eldra-rich-text]")) {
|
|
1176
|
+
applyRichTextPrices(element, editable);
|
|
1177
|
+
if (editable) {
|
|
1178
|
+
element.setAttribute("contenteditable", "true");
|
|
1179
|
+
element.setAttribute("spellcheck", "false");
|
|
1180
|
+
applyRichTextWhiteSpace(element);
|
|
1181
|
+
} else {
|
|
1182
|
+
element.removeAttribute("contenteditable");
|
|
1183
|
+
element.removeAttribute("spellcheck");
|
|
1184
|
+
restoreRichTextWhiteSpace(element);
|
|
1185
|
+
}
|
|
1157
1186
|
}
|
|
1158
1187
|
if (editable) reassertRichTextEditingRoot();
|
|
1159
1188
|
else {
|
|
@@ -1961,6 +1990,7 @@ function createOverlayRuntime(opts) {
|
|
|
1961
1990
|
existing.setAttribute("data-eldra-entry", meta.entryId);
|
|
1962
1991
|
if (meta.locale !== null) existing.setAttribute("data-eldra-locale", meta.locale);
|
|
1963
1992
|
else existing.removeAttribute("data-eldra-locale");
|
|
1993
|
+
markInline(existing, meta);
|
|
1964
1994
|
text.data = cleaned;
|
|
1965
1995
|
applyEditable(existing);
|
|
1966
1996
|
continue;
|
|
@@ -1970,6 +2000,7 @@ function createOverlayRuntime(opts) {
|
|
|
1970
2000
|
parent.setAttribute("data-eldra-field", meta.fieldPath);
|
|
1971
2001
|
parent.setAttribute("data-eldra-entry", meta.entryId);
|
|
1972
2002
|
if (meta.locale !== null) parent.setAttribute("data-eldra-locale", meta.locale);
|
|
2003
|
+
markInline(parent, meta);
|
|
1973
2004
|
text.data = cleaned;
|
|
1974
2005
|
applyEditable(parent);
|
|
1975
2006
|
continue;
|
|
@@ -1978,6 +2009,7 @@ function createOverlayRuntime(opts) {
|
|
|
1978
2009
|
span.setAttribute("data-eldra-field", meta.fieldPath);
|
|
1979
2010
|
span.setAttribute("data-eldra-entry", meta.entryId);
|
|
1980
2011
|
if (meta.locale !== null) span.setAttribute("data-eldra-locale", meta.locale);
|
|
2012
|
+
markInline(span, meta);
|
|
1981
2013
|
text.before(span);
|
|
1982
2014
|
span.append(text);
|
|
1983
2015
|
text.data = cleaned;
|
|
@@ -1985,6 +2017,139 @@ function createOverlayRuntime(opts) {
|
|
|
1985
2017
|
}
|
|
1986
2018
|
restoreEditingFocus();
|
|
1987
2019
|
}
|
|
2020
|
+
/** A field whose page text is not its stored text (`StegaMeta.inline`) is selectable, never
|
|
2021
|
+
* editable in place: `applyEditable` reads the mark. */
|
|
2022
|
+
function markInline(element, meta) {
|
|
2023
|
+
if (meta.inline === false) element.setAttribute("data-eldra-inline", "false");
|
|
2024
|
+
else element.removeAttribute("data-eldra-inline");
|
|
2025
|
+
if (meta.parts !== void 0) {
|
|
2026
|
+
pricedParts.set(element, meta.parts);
|
|
2027
|
+
element.setAttribute("data-eldra-priced", "");
|
|
2028
|
+
} else {
|
|
2029
|
+
pricedParts.delete(element);
|
|
2030
|
+
element.removeAttribute("data-eldra-priced");
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
function isPriced(element) {
|
|
2034
|
+
return element.hasAttribute("data-eldra-priced");
|
|
2035
|
+
}
|
|
2036
|
+
/** A price chip: never editable itself, labelled with what the page shows for the token. */
|
|
2037
|
+
function priceChip(part) {
|
|
2038
|
+
const chip = document.createElement("span");
|
|
2039
|
+
chip.setAttribute("contenteditable", "false");
|
|
2040
|
+
chip.setAttribute("data-eldra-price-token", part.token);
|
|
2041
|
+
if (part.missing === true) chip.setAttribute("data-eldra-price-missing", "");
|
|
2042
|
+
chip.textContent = part.label;
|
|
2043
|
+
styleChip(chip, part.missing === true);
|
|
2044
|
+
return chip;
|
|
2045
|
+
}
|
|
2046
|
+
function styleChip(chip, missing) {
|
|
2047
|
+
Object.assign(chip.style, {
|
|
2048
|
+
display: "inline-block",
|
|
2049
|
+
padding: "0 0.35em",
|
|
2050
|
+
margin: "0 0.1em",
|
|
2051
|
+
borderRadius: "0.375em",
|
|
2052
|
+
lineHeight: "inherit",
|
|
2053
|
+
whiteSpace: "nowrap",
|
|
2054
|
+
cursor: "pointer",
|
|
2055
|
+
userSelect: "none",
|
|
2056
|
+
background: missing ? "rgba(217, 119, 6, 0.16)" : "rgba(47, 111, 228, 0.14)",
|
|
2057
|
+
boxShadow: missing ? "inset 0 0 0 1px rgba(217, 119, 6, 0.55)" : "inset 0 0 0 1px rgba(47, 111, 228, 0.45)"
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
/** The stored text a surface stands for: its text as typed, each chip as its token. */
|
|
2061
|
+
function priceSurfaceValue(element) {
|
|
2062
|
+
let out = "";
|
|
2063
|
+
for (const node of element.childNodes) if (node.nodeType === Node.TEXT_NODE) out += node.data;
|
|
2064
|
+
else if (node instanceof HTMLElement) {
|
|
2065
|
+
const token = node.getAttribute("data-eldra-price-token");
|
|
2066
|
+
if (token !== null) out += token;
|
|
2067
|
+
else if (node.tagName !== "BR") out += priceSurfaceValue(node);
|
|
2068
|
+
}
|
|
2069
|
+
return stripStega(out);
|
|
2070
|
+
}
|
|
2071
|
+
/** Text offset to a caret position inside the surface, chips counted by their label. */
|
|
2072
|
+
function placeCaretInSurface(element, offset) {
|
|
2073
|
+
const selection = document.getSelection();
|
|
2074
|
+
if (selection === null) return;
|
|
2075
|
+
const range = document.createRange();
|
|
2076
|
+
let left = offset;
|
|
2077
|
+
for (const node of element.childNodes) {
|
|
2078
|
+
const length = node.textContent?.length ?? 0;
|
|
2079
|
+
if (node.nodeType === Node.TEXT_NODE && left <= length) {
|
|
2080
|
+
range.setStart(node, left);
|
|
2081
|
+
range.collapse(true);
|
|
2082
|
+
selection.removeAllRanges();
|
|
2083
|
+
selection.addRange(range);
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
if (node.nodeType !== Node.TEXT_NODE && left < length) {
|
|
2087
|
+
range.setStartAfter(node);
|
|
2088
|
+
range.collapse(true);
|
|
2089
|
+
selection.removeAllRanges();
|
|
2090
|
+
selection.addRange(range);
|
|
2091
|
+
return;
|
|
2092
|
+
}
|
|
2093
|
+
left -= length;
|
|
2094
|
+
}
|
|
2095
|
+
range.selectNodeContents(element);
|
|
2096
|
+
range.collapse(false);
|
|
2097
|
+
selection.removeAllRanges();
|
|
2098
|
+
selection.addRange(range);
|
|
2099
|
+
}
|
|
2100
|
+
/** Stands the surface in for a priced field's rendered text, keeping the caret near the click. */
|
|
2101
|
+
function startPriceSurface(element) {
|
|
2102
|
+
if (priceSurface?.element === element) return;
|
|
2103
|
+
endPriceSurface();
|
|
2104
|
+
const parts = pricedParts.get(element);
|
|
2105
|
+
if (parts === void 0) return;
|
|
2106
|
+
const caret = caretOffsetWithin(element);
|
|
2107
|
+
const saved = [...element.childNodes];
|
|
2108
|
+
element.replaceChildren(...parts.map((part) => typeof part === "string" ? document.createTextNode(part) : priceChip(part)));
|
|
2109
|
+
element.setAttribute("data-eldra-price-surface", "");
|
|
2110
|
+
priceSurface = {
|
|
2111
|
+
element,
|
|
2112
|
+
saved,
|
|
2113
|
+
pendingRender: null
|
|
2114
|
+
};
|
|
2115
|
+
placeCaretInSurface(element, caret);
|
|
2116
|
+
}
|
|
2117
|
+
/** Hands the field back to its renderer, with the newest text it tried to write meanwhile. */
|
|
2118
|
+
function endPriceSurface() {
|
|
2119
|
+
const surface = priceSurface;
|
|
2120
|
+
if (surface === null) return;
|
|
2121
|
+
flushTextEdit(surface.element);
|
|
2122
|
+
priceSurface = null;
|
|
2123
|
+
surface.element.removeAttribute("data-eldra-price-surface");
|
|
2124
|
+
surface.element.replaceChildren(...surface.saved);
|
|
2125
|
+
if (surface.pendingRender !== null) platformTextContent()?.set?.call(surface.element, surface.pendingRender);
|
|
2126
|
+
}
|
|
2127
|
+
/** A token's identity across amount edits: `price#a3f`, or `store freeShippingThreshold`. */
|
|
2128
|
+
function tokenIdentity(token) {
|
|
2129
|
+
const body = token.slice(1, -1);
|
|
2130
|
+
return body.startsWith("price#") ? body.split(" ")[0] ?? body : body;
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* The renderer re-stated the field while it is being edited (an amount changed in Studio's price
|
|
2134
|
+
* editor, a currency was added): the text is the operator's, but each chip takes its price's new
|
|
2135
|
+
* stored text and label.
|
|
2136
|
+
*/
|
|
2137
|
+
function refreshPriceChips(element, rendered) {
|
|
2138
|
+
const parts = decodeStega(rendered).meta?.parts;
|
|
2139
|
+
if (parts === void 0) return;
|
|
2140
|
+
const next = /* @__PURE__ */ new Map();
|
|
2141
|
+
for (const part of parts) if (typeof part !== "string") next.set(tokenIdentity(part.token), part);
|
|
2142
|
+
element.querySelectorAll("[data-eldra-price-token]").forEach((chip) => {
|
|
2143
|
+
const part = next.get(tokenIdentity(chip.getAttribute("data-eldra-price-token") ?? ""));
|
|
2144
|
+
if (part === void 0) return;
|
|
2145
|
+
chip.setAttribute("data-eldra-price-token", part.token);
|
|
2146
|
+
chip.textContent = part.label;
|
|
2147
|
+
if (part.missing === true) chip.setAttribute("data-eldra-price-missing", "");
|
|
2148
|
+
else chip.removeAttribute("data-eldra-price-missing");
|
|
2149
|
+
styleChip(chip, part.missing === true);
|
|
2150
|
+
});
|
|
2151
|
+
pricedParts.set(element, parts);
|
|
2152
|
+
}
|
|
1988
2153
|
function metadataOf(span) {
|
|
1989
2154
|
return {
|
|
1990
2155
|
entryId: span.getAttribute("data-eldra-entry") ?? "",
|
|
@@ -2116,7 +2281,7 @@ function createOverlayRuntime(opts) {
|
|
|
2116
2281
|
}
|
|
2117
2282
|
function applyEditable(span) {
|
|
2118
2283
|
if (span.hasAttribute("data-eldra-rich-text")) return;
|
|
2119
|
-
if (mode === "edit") {
|
|
2284
|
+
if (mode === "edit" && span.getAttribute("data-eldra-inline") !== "false" && (!isPriced(span) || priceTokensEnabled)) {
|
|
2120
2285
|
span.setAttribute("contenteditable", "true");
|
|
2121
2286
|
guardRendererText(span);
|
|
2122
2287
|
} else {
|
|
@@ -2174,7 +2339,13 @@ function createOverlayRuntime(opts) {
|
|
|
2174
2339
|
write.call(this, value);
|
|
2175
2340
|
return;
|
|
2176
2341
|
}
|
|
2177
|
-
|
|
2342
|
+
const next = value === null || value === void 0 ? "" : String(value);
|
|
2343
|
+
if (priceSurface?.element === this) {
|
|
2344
|
+
priceSurface.pendingRender = next;
|
|
2345
|
+
refreshPriceChips(this, next);
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
if (stripStega(next) === stripStega(read.call(this) ?? "")) return;
|
|
2178
2349
|
if (hasUnacknowledgedTextEdit(metadataOf(this))) return;
|
|
2179
2350
|
write.call(this, value);
|
|
2180
2351
|
}
|
|
@@ -2199,8 +2370,15 @@ function createOverlayRuntime(opts) {
|
|
|
2199
2370
|
root.querySelectorAll("[data-eldra-entry][data-eldra-field]").forEach((field) => {
|
|
2200
2371
|
if (field.closest("[data-eldra-template-block]") !== null) return;
|
|
2201
2372
|
if (field.closest("[data-eldra-rich-text]") !== null) return;
|
|
2373
|
+
if (field.getAttribute("data-eldra-inline") === "false") return;
|
|
2202
2374
|
const meta = metadataOf(field);
|
|
2203
2375
|
if (!accepted.has(meta.entryId)) return;
|
|
2376
|
+
if (isPriced(field)) {
|
|
2377
|
+
const draft = drafts[meta.entryId];
|
|
2378
|
+
const stored = draft === void 0 ? void 0 : ownValueAtPath(draft, meta.fieldPath);
|
|
2379
|
+
if (typeof stored === "string") acceptTextEditEcho(meta, stripStega(stored));
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2204
2382
|
if (!Object.prototype.hasOwnProperty.call(drafts, meta.entryId)) return;
|
|
2205
2383
|
const draft = drafts[meta.entryId];
|
|
2206
2384
|
if (draft === void 0) return;
|
|
@@ -2285,9 +2463,44 @@ function createOverlayRuntime(opts) {
|
|
|
2285
2463
|
function onNavigationSubmit(event) {
|
|
2286
2464
|
event.preventDefault();
|
|
2287
2465
|
}
|
|
2466
|
+
function postPriceClicked(field, chip) {
|
|
2467
|
+
opts.post("theme:price-clicked", {
|
|
2468
|
+
...metadataOf(field),
|
|
2469
|
+
...layoutIdentityOf(field),
|
|
2470
|
+
token: chip.getAttribute("data-eldra-price-token") ?? "",
|
|
2471
|
+
rect: rectOf(chip)
|
|
2472
|
+
});
|
|
2473
|
+
}
|
|
2474
|
+
function onPointerDown(event) {
|
|
2475
|
+
const richRoot = (event.target instanceof Element ? event.target : null)?.closest("[data-eldra-rich-text]") ?? null;
|
|
2476
|
+
pressedInFocusedRichText = richRoot !== null && richRoot === document.activeElement ? richRoot : null;
|
|
2477
|
+
}
|
|
2288
2478
|
function onClick(event) {
|
|
2479
|
+
const pressedRoot = pressedInFocusedRichText;
|
|
2480
|
+
pressedInFocusedRichText = null;
|
|
2289
2481
|
const target = event.target instanceof Element ? event.target : null;
|
|
2290
2482
|
if (target === null) return;
|
|
2483
|
+
const richPrice = mode === "edit" && priceTokensEnabled ? target.closest("[data-eldra-rich-price]") : null;
|
|
2484
|
+
if (richPrice !== null && pressedRoot !== null && pressedRoot.contains(richPrice)) {
|
|
2485
|
+
opts.post("theme:price-clicked", {
|
|
2486
|
+
...metadataOf(pressedRoot),
|
|
2487
|
+
...layoutIdentityOf(pressedRoot),
|
|
2488
|
+
token: "",
|
|
2489
|
+
pos: Number(richPrice.getAttribute("data-eldra-pos")),
|
|
2490
|
+
rect: rectOf(richPrice)
|
|
2491
|
+
});
|
|
2492
|
+
event.preventDefault();
|
|
2493
|
+
event.stopPropagation();
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
const chip = mode === "edit" && priceTokensEnabled ? target.closest("[data-eldra-price-token]") : null;
|
|
2497
|
+
const chipField = chip?.closest("[data-eldra-field]") ?? null;
|
|
2498
|
+
if (chip !== null && chipField !== null && priceSurface?.element === chipField) {
|
|
2499
|
+
postPriceClicked(chipField, chip);
|
|
2500
|
+
event.preventDefault();
|
|
2501
|
+
event.stopPropagation();
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2291
2504
|
if (mode === "edit") {
|
|
2292
2505
|
const framed = framingEnabled ? framingImageFor(target) : null;
|
|
2293
2506
|
if (framed !== null && ownsSelectedBlock(framed)) {
|
|
@@ -2448,21 +2661,33 @@ function createOverlayRuntime(opts) {
|
|
|
2448
2661
|
}
|
|
2449
2662
|
const span = target?.closest("[data-eldra-field]") ?? null;
|
|
2450
2663
|
if (span === null || mode !== "edit") return;
|
|
2451
|
-
rememberEditing(span, true);
|
|
2664
|
+
if (priceSurface?.element !== span) rememberEditing(span, true);
|
|
2452
2665
|
const pending = debounceTimers.get(span);
|
|
2453
2666
|
if (pending !== void 0) clearTimeout(pending);
|
|
2454
2667
|
debounceTimers.set(span, setTimeout(() => {
|
|
2455
2668
|
debounceTimers.delete(span);
|
|
2456
|
-
|
|
2457
|
-
const value = stripStega(span.textContent ?? "");
|
|
2458
|
-
postedText.set(textEditKey(meta), value);
|
|
2459
|
-
opts.post("theme:text-edited", {
|
|
2460
|
-
...meta,
|
|
2461
|
-
...layoutIdentityOf(span),
|
|
2462
|
-
value
|
|
2463
|
-
});
|
|
2669
|
+
postTextEdit(span);
|
|
2464
2670
|
}, TEXT_EDIT_DEBOUNCE_MS));
|
|
2465
2671
|
}
|
|
2672
|
+
/** The field's text as stored: a priced surface's tokens intact, else its text. */
|
|
2673
|
+
function postTextEdit(span) {
|
|
2674
|
+
const meta = metadataOf(span);
|
|
2675
|
+
const value = priceSurface?.element === span ? priceSurfaceValue(span) : stripStega(span.textContent ?? "");
|
|
2676
|
+
postedText.set(textEditKey(meta), value);
|
|
2677
|
+
opts.post("theme:text-edited", {
|
|
2678
|
+
...meta,
|
|
2679
|
+
...layoutIdentityOf(span),
|
|
2680
|
+
value
|
|
2681
|
+
});
|
|
2682
|
+
}
|
|
2683
|
+
/** Posts a field's armed text edit now rather than at the end of its debounce. */
|
|
2684
|
+
function flushTextEdit(span) {
|
|
2685
|
+
const pending = debounceTimers.get(span);
|
|
2686
|
+
if (pending === void 0) return;
|
|
2687
|
+
clearTimeout(pending);
|
|
2688
|
+
debounceTimers.delete(span);
|
|
2689
|
+
postTextEdit(span);
|
|
2690
|
+
}
|
|
2466
2691
|
/** An event's target as an element: a DOM event inside a contenteditable
|
|
2467
2692
|
* names the element in browsers, but a text node is a legal target and
|
|
2468
2693
|
* `closest` only exists on elements. */
|
|
@@ -2495,6 +2720,11 @@ function createOverlayRuntime(opts) {
|
|
|
2495
2720
|
return;
|
|
2496
2721
|
}
|
|
2497
2722
|
const span = target?.closest("[data-eldra-field]") ?? null;
|
|
2723
|
+
if (span !== null && mode === "edit" && priceTokensEnabled && isPriced(span)) {
|
|
2724
|
+
activeEdit = null;
|
|
2725
|
+
startPriceSurface(span);
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2498
2728
|
if (span !== null && mode === "edit") rememberEditing(span);
|
|
2499
2729
|
else activeEdit = null;
|
|
2500
2730
|
}
|
|
@@ -2510,6 +2740,10 @@ function createOverlayRuntime(opts) {
|
|
|
2510
2740
|
* focusin/selectionchange paths.
|
|
2511
2741
|
*/
|
|
2512
2742
|
function onFocusOut(event) {
|
|
2743
|
+
if (priceSurface !== null) {
|
|
2744
|
+
const next = event.relatedTarget;
|
|
2745
|
+
if (!(next instanceof Node && priceSurface.element.contains(next))) endPriceSurface();
|
|
2746
|
+
}
|
|
2513
2747
|
const richTextRoot = editableRichTextRootOf(elementTargetOf(event));
|
|
2514
2748
|
if (richTextRoot === null) return;
|
|
2515
2749
|
const relatedTarget = event.relatedTarget;
|
|
@@ -2668,6 +2902,7 @@ function createOverlayRuntime(opts) {
|
|
|
2668
2902
|
document.addEventListener("click", onNavigationClick, true);
|
|
2669
2903
|
document.addEventListener("auxclick", onNavigationClick, true);
|
|
2670
2904
|
document.addEventListener("submit", onNavigationSubmit, true);
|
|
2905
|
+
eventTarget.addEventListener("pointerdown", onPointerDown, true);
|
|
2671
2906
|
eventTarget.addEventListener("click", onClick, true);
|
|
2672
2907
|
eventTarget.addEventListener("pointerover", onPointerOver, true);
|
|
2673
2908
|
eventTarget.addEventListener("pointerout", onPointerOut, true);
|
|
@@ -2714,6 +2949,7 @@ function createOverlayRuntime(opts) {
|
|
|
2714
2949
|
document.removeEventListener("click", onNavigationClick, true);
|
|
2715
2950
|
document.removeEventListener("auxclick", onNavigationClick, true);
|
|
2716
2951
|
document.removeEventListener("submit", onNavigationSubmit, true);
|
|
2952
|
+
eventTarget.removeEventListener("pointerdown", onPointerDown, true);
|
|
2717
2953
|
eventTarget.removeEventListener("click", onClick, true);
|
|
2718
2954
|
eventTarget.removeEventListener("pointerover", onPointerOver, true);
|
|
2719
2955
|
eventTarget.removeEventListener("pointerout", onPointerOut, true);
|
|
@@ -2739,6 +2975,7 @@ function createOverlayRuntime(opts) {
|
|
|
2739
2975
|
dropIndicator = null;
|
|
2740
2976
|
framingBox = null;
|
|
2741
2977
|
framingBadge = null;
|
|
2978
|
+
endPriceSurface();
|
|
2742
2979
|
for (const timer of debounceTimers.values()) clearTimeout(timer);
|
|
2743
2980
|
debounceTimers.clear();
|
|
2744
2981
|
postedText.clear();
|
|
@@ -2750,6 +2987,7 @@ function createOverlayRuntime(opts) {
|
|
|
2750
2987
|
if (nextMode !== "edit") postedText.clear();
|
|
2751
2988
|
if (nextMode !== "edit") exitFraming();
|
|
2752
2989
|
if (nextMode !== "edit") clearRichTextEditing();
|
|
2990
|
+
if (nextMode !== "edit") endPriceSurface();
|
|
2753
2991
|
root.querySelectorAll("[data-eldra-field]").forEach(applyEditable);
|
|
2754
2992
|
applyRichTextEditable();
|
|
2755
2993
|
applyHiddenEditing();
|
|
@@ -2859,6 +3097,58 @@ function createOverlayRuntime(opts) {
|
|
|
2859
3097
|
element.focus?.({ preventScroll: true });
|
|
2860
3098
|
placeCaretAtEnd(element);
|
|
2861
3099
|
},
|
|
3100
|
+
setPriceTokensEnabled(enabled) {
|
|
3101
|
+
priceTokensEnabled = enabled;
|
|
3102
|
+
if (!enabled) endPriceSurface();
|
|
3103
|
+
root.querySelectorAll("[data-eldra-field]").forEach(applyEditable);
|
|
3104
|
+
applyRichTextEditable();
|
|
3105
|
+
},
|
|
3106
|
+
insertPriceToken(target, token, label) {
|
|
3107
|
+
if (!priceTokensEnabled || mode !== "edit") return;
|
|
3108
|
+
if (!/^⟦[^⟦⟧]+⟧$/.test(token) || label === "") return;
|
|
3109
|
+
const field = [...root.querySelectorAll("[data-eldra-field]")].find((element) => {
|
|
3110
|
+
if (!isPriced(element) && !element.hasAttribute("contenteditable")) return false;
|
|
3111
|
+
if (element.hasAttribute("data-eldra-rich-text")) return false;
|
|
3112
|
+
const meta = metadataOf(element);
|
|
3113
|
+
if (meta.entryId !== target.entryId || meta.fieldPath !== target.fieldPath) return false;
|
|
3114
|
+
if (meta.locale !== target.locale) return false;
|
|
3115
|
+
const identity = layoutIdentityOf(element);
|
|
3116
|
+
if (target.layoutNodeId !== void 0 && identity.layoutNodeId !== target.layoutNodeId) return false;
|
|
3117
|
+
return target.reusablePlacementId === void 0 || identity.reusablePlacementId === target.reusablePlacementId;
|
|
3118
|
+
});
|
|
3119
|
+
if (field === void 0) return;
|
|
3120
|
+
if (priceSurface?.element === field) {
|
|
3121
|
+
const chip = priceChip({
|
|
3122
|
+
token,
|
|
3123
|
+
label
|
|
3124
|
+
});
|
|
3125
|
+
const selection = document.getSelection();
|
|
3126
|
+
const range = selection !== null && selection.rangeCount > 0 ? selection.getRangeAt(0) : null;
|
|
3127
|
+
if (range !== null && field.contains(range.startContainer)) {
|
|
3128
|
+
range.deleteContents();
|
|
3129
|
+
range.insertNode(chip);
|
|
3130
|
+
range.setStartAfter(chip);
|
|
3131
|
+
range.collapse(true);
|
|
3132
|
+
selection?.removeAllRanges();
|
|
3133
|
+
selection?.addRange(range);
|
|
3134
|
+
} else field.append(chip);
|
|
3135
|
+
const pending = debounceTimers.get(field);
|
|
3136
|
+
if (pending !== void 0) clearTimeout(pending);
|
|
3137
|
+
debounceTimers.delete(field);
|
|
3138
|
+
postTextEdit(field);
|
|
3139
|
+
return;
|
|
3140
|
+
}
|
|
3141
|
+
const parts = pricedParts.get(field);
|
|
3142
|
+
const stored = parts !== void 0 ? parts.map((part) => typeof part === "string" ? part : part.token).join("") : stripStega(field.textContent ?? "");
|
|
3143
|
+
const meta = metadataOf(field);
|
|
3144
|
+
const value = `${stored.trimEnd()} ${token}`.trimStart();
|
|
3145
|
+
postedText.set(textEditKey(meta), value);
|
|
3146
|
+
opts.post("theme:text-edited", {
|
|
3147
|
+
...meta,
|
|
3148
|
+
...layoutIdentityOf(field),
|
|
3149
|
+
value
|
|
3150
|
+
});
|
|
3151
|
+
},
|
|
2862
3152
|
setRichTextEnabled(enabled) {
|
|
2863
3153
|
richTextEnabled = enabled;
|
|
2864
3154
|
if (!enabled) clearRichTextEditing();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as RichTextCommandName, T as StructuralDragPayload, u as BridgePayloads } from "./index-
|
|
1
|
+
import { S as RichTextCommandName, T as StructuralDragPayload, u as BridgePayloads } from "./index-C_Kx7Vq9.js";
|
|
2
2
|
import { n as FrameRect } from "./imageFraming-BgKBJiTB.js";
|
|
3
3
|
import { c as LayoutBreakpoints } from "./layout-CkPOfiOM.js";
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ import { c as LayoutBreakpoints } from "./layout-CkPOfiOM.js";
|
|
|
11
11
|
* mirrors the mode into the theme's own context before calling the overlay —
|
|
12
12
|
* `editor:navigate` and `editor:refresh`).
|
|
13
13
|
*/
|
|
14
|
-
declare const PREVIEW_ROUTER_MESSAGE_TYPES: readonly ["editor:select-block", "editor:drag-start", "editor:drag-end", "editor:framing-mode", "editor:rich-text-editing", "editor:rich-text-applied", "editor:rich-text-locate"];
|
|
14
|
+
declare const PREVIEW_ROUTER_MESSAGE_TYPES: readonly ["editor:select-block", "editor:drag-start", "editor:drag-end", "editor:framing-mode", "editor:rich-text-editing", "editor:rich-text-applied", "editor:rich-text-locate", "editor:insert-price"];
|
|
15
15
|
type PreviewRouterMessageType = (typeof PREVIEW_ROUTER_MESSAGE_TYPES)[number];
|
|
16
16
|
/** Capabilities negotiated from `editor:hello`, as flags an adapter can
|
|
17
17
|
* surface to its own components. `slots` is not acted on here — the
|
|
@@ -22,6 +22,8 @@ interface NegotiatedEditorCapabilities {
|
|
|
22
22
|
framing: boolean;
|
|
23
23
|
richText: boolean;
|
|
24
24
|
blockHover: boolean;
|
|
25
|
+
/** `price-tokens-inline`: price chips in plain-text fields edited on the canvas. */
|
|
26
|
+
priceTokens: boolean;
|
|
25
27
|
}
|
|
26
28
|
interface PreviewMessageRouter {
|
|
27
29
|
/** Re-negotiate from an `editor:hello` capability list (Studio re-sends it
|
|
@@ -85,7 +87,7 @@ interface BeforeInputClassification {
|
|
|
85
87
|
declare function classifyBeforeInput(event: InputEvent, root: Element): BeforeInputClassification;
|
|
86
88
|
interface OverlayRuntimeOptions {
|
|
87
89
|
/** Post a theme-to-editor bridge message. */
|
|
88
|
-
post: <T extends 'theme:block-clicked' | 'theme:field-clicked' | 'theme:text-edited' | 'theme:blocks-rendered' | 'theme:block-hovered' | 'theme:drop-candidate' | 'theme:node-dropped' | 'theme:framing-target' | 'theme:framing-changed' | 'theme:rich-text-selection' | 'theme:rich-text-input' | 'theme:rich-text-command'>(type: T, payload: BridgePayloads[T]) => void;
|
|
90
|
+
post: <T extends 'theme:block-clicked' | 'theme:field-clicked' | 'theme:text-edited' | 'theme:blocks-rendered' | 'theme:block-hovered' | 'theme:drop-candidate' | 'theme:node-dropped' | 'theme:framing-target' | 'theme:framing-changed' | 'theme:rich-text-selection' | 'theme:rich-text-input' | 'theme:rich-text-command' | 'theme:price-clicked'>(type: T, payload: BridgePayloads[T]) => void;
|
|
89
91
|
root?: ParentNode;
|
|
90
92
|
/**
|
|
91
93
|
* The theme's own layout breakpoints, so `hiddenAtBreakpoint` can say which
|
|
@@ -176,6 +178,27 @@ interface OverlayRuntime {
|
|
|
176
178
|
* editing mark (silently — the other side cannot receive a post either).
|
|
177
179
|
*/
|
|
178
180
|
setRichTextEnabled(enabled: boolean): void;
|
|
181
|
+
/**
|
|
182
|
+
* `price-tokens-inline`, negotiated from editor:hello like the other gates. Open, a plain-text
|
|
183
|
+
* field whose stega carries `parts` (a theme that writes price tokens out) is editable on the
|
|
184
|
+
* canvas: focusing it shows its stored text with each price as a chip, a chip click (or a first
|
|
185
|
+
* click on a price still written out) posts `theme:price-clicked`, and every edit is posted as
|
|
186
|
+
* stored text. Closed, such a field stays
|
|
187
|
+
* selectable but is never editable in place.
|
|
188
|
+
*/
|
|
189
|
+
setPriceTokensEnabled(enabled: boolean): void;
|
|
190
|
+
/**
|
|
191
|
+
* `editor:insert-price`: a price chip at the operator's caret in the named field, or at its end
|
|
192
|
+
* when it is not being edited on the canvas; the field's new stored text is posted as
|
|
193
|
+
* `theme:text-edited`. A field that does not hold prices (no `parts`) is left alone.
|
|
194
|
+
*/
|
|
195
|
+
insertPriceToken(target: {
|
|
196
|
+
entryId: string;
|
|
197
|
+
fieldPath: string;
|
|
198
|
+
locale: string | null;
|
|
199
|
+
layoutNodeId?: string;
|
|
200
|
+
reusablePlacementId?: string;
|
|
201
|
+
}, token: string, label: string): void;
|
|
179
202
|
/** Test-only accessor: the overlay's style text (the shadow root is closed). */
|
|
180
203
|
chromeStyles(): string;
|
|
181
204
|
/** Test-only accessor: hover/selected box visibility (the shadow root is closed). */
|
package/dist/overlay.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-
|
|
1
|
+
import { a as RichTextRenderStateChange, c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, i as RichTextFieldIdentity, l as PREVIEW_ROUTER_MESSAGE_TYPES, n as OverlayRuntime, o as classifyBeforeInput, r as OverlayRuntimeOptions, s as createOverlayRuntime, t as BeforeInputClassification, u as PreviewMessageRouter } from "./overlay-D7gS7OY1.js";
|
|
2
2
|
export { BeforeInputClassification, type NegotiatedEditorCapabilities, OverlayRuntime, OverlayRuntimeOptions, PREVIEW_ROUTER_MESSAGE_TYPES, type PreviewMessageRouter, type PreviewRouterMessageType, RichTextFieldIdentity, RichTextRenderStateChange, classifyBeforeInput, createOverlayRuntime, createPreviewMessageRouter };
|
package/dist/overlay.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./stega.js";
|
|
2
2
|
import "./layout.js";
|
|
3
3
|
import "./image-framing.js";
|
|
4
|
-
import { n as createOverlayRuntime, t as classifyBeforeInput } from "./overlay-
|
|
4
|
+
import { n as createOverlayRuntime, t as classifyBeforeInput } from "./overlay-C6lCvEGm.js";
|
|
5
5
|
import { PREVIEW_ROUTER_MESSAGE_TYPES, createPreviewMessageRouter } from "./preview-router.js";
|
|
6
6
|
export { PREVIEW_ROUTER_MESSAGE_TYPES, classifyBeforeInput, createOverlayRuntime, createPreviewMessageRouter };
|
package/dist/preview-router.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, l as PREVIEW_ROUTER_MESSAGE_TYPES, u as PreviewMessageRouter } from "./overlay-
|
|
1
|
+
import { c as NegotiatedEditorCapabilities, d as PreviewRouterMessageType, f as createPreviewMessageRouter, l as PREVIEW_ROUTER_MESSAGE_TYPES, u as PreviewMessageRouter } from "./overlay-D7gS7OY1.js";
|
|
2
2
|
export { NegotiatedEditorCapabilities, PREVIEW_ROUTER_MESSAGE_TYPES, PreviewMessageRouter, PreviewRouterMessageType, createPreviewMessageRouter };
|
package/dist/preview-router.js
CHANGED
|
@@ -16,13 +16,15 @@ const PREVIEW_ROUTER_MESSAGE_TYPES = [
|
|
|
16
16
|
"editor:framing-mode",
|
|
17
17
|
"editor:rich-text-editing",
|
|
18
18
|
"editor:rich-text-applied",
|
|
19
|
-
"editor:rich-text-locate"
|
|
19
|
+
"editor:rich-text-locate",
|
|
20
|
+
"editor:insert-price"
|
|
20
21
|
];
|
|
21
22
|
const CLOSED = {
|
|
22
23
|
slots: false,
|
|
23
24
|
framing: false,
|
|
24
25
|
richText: false,
|
|
25
|
-
blockHover: false
|
|
26
|
+
blockHover: false,
|
|
27
|
+
priceTokens: false
|
|
26
28
|
};
|
|
27
29
|
/**
|
|
28
30
|
* @param overlay resolved lazily, because adapters create the bridge (whose
|
|
@@ -36,6 +38,7 @@ function createPreviewMessageRouter(overlay) {
|
|
|
36
38
|
runtime.setFramingEnabled(capabilities.framing);
|
|
37
39
|
runtime.setRichTextEnabled(capabilities.richText);
|
|
38
40
|
runtime.setBlockHoverEnabled(capabilities.blockHover);
|
|
41
|
+
runtime.setPriceTokensEnabled(capabilities.priceTokens);
|
|
39
42
|
}
|
|
40
43
|
return {
|
|
41
44
|
get capabilities() {
|
|
@@ -46,7 +49,8 @@ function createPreviewMessageRouter(overlay) {
|
|
|
46
49
|
slots: list.includes("block-slots"),
|
|
47
50
|
framing: list.includes("image-framing"),
|
|
48
51
|
richText: list.includes("rich-text-inline"),
|
|
49
|
-
blockHover: list.includes("block-hover")
|
|
52
|
+
blockHover: list.includes("block-hover"),
|
|
53
|
+
priceTokens: list.includes("price-tokens-inline")
|
|
50
54
|
};
|
|
51
55
|
apply();
|
|
52
56
|
return capabilities;
|
|
@@ -96,6 +100,12 @@ function createPreviewMessageRouter(overlay) {
|
|
|
96
100
|
});
|
|
97
101
|
return true;
|
|
98
102
|
}
|
|
103
|
+
case "editor:insert-price": {
|
|
104
|
+
if (!capabilities.priceTokens) return true;
|
|
105
|
+
const message = payload !== null && typeof payload === "object" ? payload : {};
|
|
106
|
+
runtime.insertPriceToken(richTextTarget(payload), typeof message.token === "string" ? message.token : "", typeof message.label === "string" ? message.label : "");
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
99
109
|
case "editor:rich-text-locate":
|
|
100
110
|
if (!capabilities.richText) return true;
|
|
101
111
|
runtime.locateRichText(richTextTarget(payload));
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-core",
|
|
3
|
-
"version": "0.4.
|
|
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",
|