@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.
@@ -1,4 +1,4 @@
1
- import { l as RICH_TEXT_COMMAND_NAMES } from "./bridge-DSH4N82G.js";
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]")) if (editable) {
1150
- element.setAttribute("contenteditable", "true");
1151
- element.setAttribute("spellcheck", "false");
1152
- applyRichTextWhiteSpace(element);
1153
- } else {
1154
- element.removeAttribute("contenteditable");
1155
- element.removeAttribute("spellcheck");
1156
- restoreRichTextWhiteSpace(element);
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
- if (stripStega(value === null || value === void 0 ? "" : String(value)) === stripStega(read.call(this) ?? "")) return;
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
- const meta = metadataOf(span);
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-C3tgQ-hG.js";
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-mKeZLljc.js";
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
- import "./image-framing.js";
3
- import { n as createOverlayRuntime, t as classifyBeforeInput } from "./overlay-a8pghnYy.js";
4
2
  import "./layout.js";
3
+ import "./image-framing.js";
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 };
@@ -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-mKeZLljc.js";
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 };
@@ -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));
@@ -61,4 +61,49 @@ export declare class ReusableComponentSnapshotCache {
61
61
  * output. The returned model is shared by Vue preview and SSR/static output.
62
62
  */
63
63
  export declare function createReusableLayoutRenderModel(value: unknown, options: ReusableLayoutOptions): ReusableLayoutRenderModel;
64
+ /**
65
+ * A layout document with reusable placements, in the shape Core's **public** read serves it: each
66
+ * placement replaced in place by its component's content, the component's root taking the
67
+ * placement id and every node inside it the `r` + SHA-256 render id
68
+ * (`docs/theme-reusable-components.md`), and no projection left anywhere.
69
+ *
70
+ * A preview read keeps the placements and the projection, because Studio's overlay addresses a
71
+ * node inside a component by its authored id and its placement. A draft preview session has no
72
+ * overlay, and must render exactly what the published page renders, so it renders this shape
73
+ * instead (`@eldrajs/theme-nuxt`, WS-1358). Throws a `LayoutValidationError` for what the render
74
+ * would refuse; the caller keeps the document as it was, and the render then fails closed on it.
75
+ *
76
+ * `routeTemplate` admits placements in a version-1 document, as a route template does.
77
+ */
78
+ export declare function expandReusableLayout(value: unknown, projection: unknown, options?: {
79
+ routeTemplate?: boolean;
80
+ }): {
81
+ version: 1 | 2 | 3;
82
+ root: unknown;
83
+ };
84
+ /**
85
+ * A preview read's answer, in the shape Core's public read gives the same records (WS-1358): every
86
+ * entry in it — the answer itself, every list item, every resolved reference at any depth (a page's
87
+ * `parent`, a block, a list field's entries) — that carries a `reusableComponentProjection` is
88
+ * turned into its public read (`expandReusableComponentsForPublic` in Core's cms-service):
89
+ *
90
+ * - every placement expanded in place (`expandReusableLayout`; a document with `routePattern` is a
91
+ * route template, whose version-1 layout may place a component), and the projection dropped;
92
+ * - `blocks` put in the expanded layout's depth-first order (slot children by sorted slot id);
93
+ * - every node naming a block that is not among `blocks` removed, slot children with it, and
94
+ * `blocks` rebuilt from what remains;
95
+ * - every entry's `status` dropped (an object with `id`, `schemaId` and `data`, the envelope Core
96
+ * writes around a record): the public read has none.
97
+ *
98
+ * Anything else is left as it is: a document with no projection is served the same by both reads
99
+ * (Core prunes only a document that places a component), and a projection that does not expand is
100
+ * left for the render to fail closed on, as it would have. What the two reads differ in beyond
101
+ * this — an entry's `publishedAt` and `updatedAt` (Publish sets them) and a media item's `linkId`
102
+ * (one link row per owner) — is the draft's own and stays.
103
+ *
104
+ * A draft preview session's client applies it to every CMS answer (`enableSessionPreview`): a
105
+ * session has no overlay to address a component's nodes by their authored ids, and what it must
106
+ * render is what Publish puts live.
107
+ */
108
+ export declare function asPublicRead<T>(value: T): T;
64
109
  export { type ReusableComponentBinding, type ReusableComponentPlacement, type ReusableComponentProjection, type ReusableComponentResolver, type ReusableComponentRevision, type ReusableRenderIdentity, createProjectionResolver };