okno 1.0.0-beta.47 → 1.0.0-beta.49

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.
@@ -113,7 +113,7 @@ function ke(n) {
113
113
  (!o[a] || typeof o[a] != "object") && (o[a] = {}), o = o[a];
114
114
  }
115
115
  const i = t[t.length - 1];
116
- o[i] = s.value !== void 0 && s.value !== null ? s.value : Q(s.type);
116
+ o[i] = s.value !== void 0 && s.value !== null ? s.value : s.multiple ? [] : Q(s.type);
117
117
  }
118
118
  return e;
119
119
  }
@@ -157,9 +157,9 @@ function be(n, e, s) {
157
157
  return typeof r == "string";
158
158
  }
159
159
  }, i = (r, a, l, u = !1) => {
160
- for (const [p, f] of Object.entries(a)) {
160
+ for (const [w, f] of Object.entries(a)) {
161
161
  if (f.type === "divider") continue;
162
- const y = r[p], $ = `${l}.${p}`;
162
+ const y = r[w], $ = `${l}.${w}`;
163
163
  if (ee(y)) {
164
164
  !u && f.required && t.push({ path: $, message: "required value is missing", fatal: !0, code: "required_missing" });
165
165
  continue;
@@ -176,13 +176,13 @@ function be(n, e, s) {
176
176
  continue;
177
177
  }
178
178
  if (f.type === "enum") {
179
- const w = (f.options ?? []).map((b) => typeof b == "string" ? b : b.value).filter(Boolean);
180
- w.length && !w.includes(d) && t.push({ path: g, message: `unknown option ${JSON.stringify(d)}` });
179
+ const p = (f.options ?? []).map((b) => typeof b == "string" ? b : b.value).filter(Boolean);
180
+ p.length && !p.includes(d) && t.push({ path: g, message: `unknown option ${JSON.stringify(d)}` });
181
181
  }
182
182
  if (f.type === "reference" && f.collection && (s.get(f.collection)?.has(d) || t.push({ path: g, message: `references missing ${f.collection}.${d}`, fatal: !0 })), f.type === "group" && f.fields && i(d, f.fields, g, u), f.type === "block") {
183
- const w = Array.isArray(f.blocks) ? f.blocks : f.block ? [f.block] : [], b = d.__block, A = typeof b == "string" ? b : f.block;
183
+ const p = Array.isArray(f.blocks) ? f.blocks : f.block ? [f.block] : [], b = d.__block, A = typeof b == "string" ? b : f.block;
184
184
  if (Array.isArray(f.blocks) && typeof b != "string") t.push({ path: g, message: "polymorphic block is missing __block", fatal: !0 });
185
- else if (!A || !w.includes(A)) t.push({ path: g, message: `unknown block ${JSON.stringify(A)}`, fatal: !0 });
185
+ else if (!A || !p.includes(A)) t.push({ path: g, message: `unknown block ${JSON.stringify(A)}`, fatal: !0 });
186
186
  else {
187
187
  const O = n.blocks?.[A]?.fields;
188
188
  O && i(d, O, g, u);
@@ -192,12 +192,12 @@ function be(n, e, s) {
192
192
  }
193
193
  };
194
194
  for (const { kind: r, name: a, locale: l, value: u } of e) {
195
- const p = n[r]?.[a], f = l !== void 0, y = `${r}.${a}.${f ? `${l}.` : ""}${typeof u.slug == "string" ? u.slug : a}`;
195
+ const w = n[r]?.[a], f = l !== void 0, y = `${r}.${a}.${f ? `${l}.` : ""}${typeof u.slug == "string" ? u.slug : a}`;
196
196
  if (r === "collections" && Object.hasOwn(u, "draft") && typeof u.draft != "boolean") {
197
197
  const $ = !!u.draft && typeof u.draft == "object" && !Array.isArray(u.draft);
198
198
  t.push({ path: `${y}.draft`, message: $ ? "legacy draft envelope remains readable and needs migration" : "collection draft must be a boolean", ...$ ? {} : { fatal: !0 } });
199
199
  }
200
- i(u, p?.fields ?? {}, y, f);
200
+ i(u, w?.fields ?? {}, y, f);
201
201
  }
202
202
  return t;
203
203
  }
@@ -437,13 +437,13 @@ function fe(n, e, s) {
437
437
  }
438
438
  function de(n, e, s, t, o, i = {}) {
439
439
  let r = !1;
440
- const a = [], l = (k, h, d, g = {}, w = "") => {
440
+ const a = [], l = (k, h, d, g = {}, p = "") => {
441
441
  if (!m(k)) return k;
442
442
  const b = { ...k };
443
443
  for (const [A, O] of Object.entries(h)) {
444
444
  const j = d[g[A] ?? A];
445
445
  if (!m(O) || !m(j) || !(A in k)) continue;
446
- const x = w ? `${w}.${A}` : A;
446
+ const x = p ? `${p}.${A}` : A;
447
447
  let v = k[A];
448
448
  if (O.multiple === !0 && j.multiple !== !0 && Array.isArray(v))
449
449
  if (v.length > 1) {
@@ -468,7 +468,7 @@ function de(n, e, s, t, o, i = {}) {
468
468
  b[A] = Array.isArray(v) && (O.type === "group" || O.type === "block") ? v.map(L) : L(v);
469
469
  }
470
470
  return b;
471
- }, u = n[t]?.[o]?.fields ?? {}, p = e.kind === t && e.name === o, f = p ? e.fields : u, y = p ? e.renames : {}, $ = l(s, u, f, y);
471
+ }, u = n[t]?.[o]?.fields ?? {}, w = e.kind === t && e.name === o, f = w ? e.fields : u, y = w ? e.renames : {}, $ = l(s, u, f, y);
472
472
  if (m(s) && m($))
473
473
  for (const k of ["data", "draft"]) !(k in u) && m(s[k]) && ($[k] = l(s[k], u, f, y, k));
474
474
  return { out: $, changed: r, conflicts: a };
@@ -496,8 +496,8 @@ function he(n, e, s, t, o) {
496
496
  if (!m(i) && !(r.kind === "collections" && Array.isArray(i) && i.every(m))) throw new c(409, `Cannot migrate malformed content: ${e}`);
497
497
  const a = s[r.kind]?.[r.name]?.fields ?? {}, l = [], u = (h, d, g) => {
498
498
  if (m(h))
499
- for (const [w, b] of Object.entries(d)) {
500
- if (!m(b) || !(w in h) || h[w] == null) continue;
499
+ for (const [p, b] of Object.entries(d)) {
500
+ if (!m(b) || !(p in h) || h[p] == null) continue;
501
501
  const A = (O, j) => {
502
502
  if (b.type !== "group" && b.type !== "block") return;
503
503
  if (!m(O)) throw new c(409, `Cannot migrate malformed content: ${e}`);
@@ -513,17 +513,17 @@ function he(n, e, s, t, o) {
513
513
  }
514
514
  u(O, s.blocks[x].fields ?? {}, j);
515
515
  };
516
- Array.isArray(h[w]) ? h[w].forEach((O, j) => A(O, [...g, w, j])) : A(h[w], [...g, w]);
516
+ Array.isArray(h[p]) ? h[p].forEach((O, j) => A(O, [...g, p, j])) : A(h[p], [...g, p]);
517
517
  }
518
- }, p = (h, d) => {
518
+ }, w = (h, d) => {
519
519
  if (u(h, a, d), m(h))
520
520
  for (const g of ["data", "draft"]) !(g in a) && m(h[g]) && u(h[g], a, [...d, g]);
521
521
  };
522
- if (Array.isArray(i) ? i.forEach((h, d) => p(h, [d])) : p(i, []), !l.length) return n;
522
+ if (Array.isArray(i) ? i.forEach((h, d) => w(h, [d])) : w(i, []), !l.length) return n;
523
523
  const f = /export\s+default\s+/.exec(n), y = W(n, f.index + f[0].length, { ecmaVersion: "latest" }), $ = l.map((h) => {
524
524
  let d = y;
525
525
  for (const g of h)
526
- if (typeof g == "number" && d.type === "ArrayExpression" ? d = d.elements[g] : typeof g == "string" && d.type === "ObjectExpression" ? d = d.properties.filter((w) => w.type === "Property" && !w.computed && (w.key.name ?? String(w.key.value)) === g).at(-1)?.value : d = void 0, !d) throw new c(409, `Cannot migrate malformed block content: ${e}`);
526
+ if (typeof g == "number" && d.type === "ArrayExpression" ? d = d.elements[g] : typeof g == "string" && d.type === "ObjectExpression" ? d = d.properties.filter((p) => p.type === "Property" && !p.computed && (p.key.name ?? String(p.key.value)) === g).at(-1)?.value : d = void 0, !d) throw new c(409, `Cannot migrate malformed block content: ${e}`);
527
527
  return { start: d.start, end: d.end };
528
528
  });
529
529
  let k = n;
@@ -537,24 +537,24 @@ function ge(n, e, s) {
537
537
  };
538
538
  for (const o of ["pages", "globals", "collections", "blocks"]) for (const i of Object.values(n[o] ?? {})) m(i) && t(i.fields ?? {});
539
539
  }
540
- function we(n, e, s, t) {
540
+ function pe(n, e, s, t) {
541
541
  const o = E(n, "schema.ts");
542
542
  if (!m(o)) throw new c(409, "Schema must contain an object");
543
543
  const i = o, r = [], a = [];
544
544
  if (s === "rename-entry") {
545
545
  if (t.name === t.to) return { schema: i, writes: r, removals: a, unchanged: !0 };
546
546
  const u = JSON.parse(JSON.stringify(i));
547
- if (J(u, t.kind, t.name, t.to), Object.keys(e).some((p) => z(p, t.kind, t.to))) throw new c(409, `${t.kind}/${t.to} content already exists`);
548
- for (const [p, f] of Object.entries(e))
549
- if (z(p, t.kind, t.name)) {
550
- if (!m(E(f, p))) throw new c(409, `Cannot migrate malformed content: ${p}`);
551
- r.push({ path: p.slice(0, -`${t.name}.ts`.length) + `${t.to}.ts`, content: f }), a.push(p);
547
+ if (J(u, t.kind, t.name, t.to), Object.keys(e).some((w) => z(w, t.kind, t.to))) throw new c(409, `${t.kind}/${t.to} content already exists`);
548
+ for (const [w, f] of Object.entries(e))
549
+ if (z(w, t.kind, t.name)) {
550
+ if (!m(E(f, w))) throw new c(409, `Cannot migrate malformed content: ${w}`);
551
+ r.push({ path: w.slice(0, -`${t.name}.ts`.length) + `${t.to}.ts`, content: f }), a.push(w);
552
552
  }
553
553
  if (t.kind === "blocks") {
554
- for (const [p, f] of Object.entries(e)) {
555
- if (!me(p, "blocks", t.name)) continue;
556
- const y = he(f, p, i, t.name, t.to);
557
- y !== f && r.push({ path: p, content: y });
554
+ for (const [w, f] of Object.entries(e)) {
555
+ if (!me(w, "blocks", t.name)) continue;
556
+ const y = he(f, w, i, t.name, t.to);
557
+ y !== f && r.push({ path: w, content: y });
558
558
  }
559
559
  ge(i, t.name, t.to);
560
560
  }
@@ -567,10 +567,10 @@ function we(n, e, s, t) {
567
567
  const y = i.collections?.[t.name]?.fields ?? {};
568
568
  for (const [$, k] of Object.entries(e)) {
569
569
  if (!ce($, i, t)) continue;
570
- const h = E(k, $), d = (w) => {
571
- if (!m(w)) throw new c(409, `Cannot migrate malformed content: ${$}`);
572
- if (Object.hasOwn(w, "draft") && typeof w.draft != "boolean") throw new c(409, `Resolve legacy draft content before adding status: ${$}`);
573
- return q(w, y);
570
+ const h = E(k, $), d = (p) => {
571
+ if (!m(p)) throw new c(409, `Cannot migrate malformed content: ${$}`);
572
+ if (Object.hasOwn(p, "draft") && typeof p.draft != "boolean") throw new c(409, `Resolve legacy draft content before adding status: ${$}`);
573
+ return q(p, y);
574
574
  }, g = Array.isArray(h) ? h.map(d) : d(h);
575
575
  JSON.stringify(g) !== JSON.stringify(h) && r.push({ path: $, content: _(g) });
576
576
  }
@@ -582,25 +582,25 @@ function we(n, e, s, t) {
582
582
  if (!k) continue;
583
583
  const h = r.find((A) => A.path === y), d = E(h?.content ?? $, y);
584
584
  let g = !1;
585
- const w = (A) => {
585
+ const p = (A) => {
586
586
  const O = de(i, t, A, k.kind, k.name);
587
587
  return g ||= O.changed, O.out;
588
- }, b = Array.isArray(d) ? d.map(w) : w(d);
588
+ }, b = Array.isArray(d) ? d.map(p) : p(d);
589
589
  g && (h ? h.content = _(b) : r.push({ path: y, content: _(b) }));
590
590
  }
591
591
  K(i, t.kind, t.name, t.fields);
592
- const p = t.renames ?? {}, f = new Set(t.deletes ?? []);
593
- if (Object.keys(p).length || f.size)
592
+ const w = t.renames ?? {}, f = new Set(t.deletes ?? []);
593
+ if (Object.keys(w).length || f.size)
594
594
  for (const [y, $] of Object.entries(e)) {
595
595
  if (!F(y, t.kind, t.name) || t.kind === "collections" && C(y, i)?.name !== t.name) continue;
596
596
  const k = r.find((b) => b.path === y), h = E(k?.content ?? $, y);
597
597
  let d = !1;
598
598
  const g = (b) => {
599
599
  if (!m(b)) return b;
600
- const A = Y(b, p, f);
600
+ const A = Y(b, w, f);
601
601
  return d ||= A.changed, A.out;
602
- }, w = Array.isArray(h) ? h.map(g) : g(h);
603
- d && (k ? k.content = _(w) : r.push({ path: y, content: _(w) }));
602
+ }, p = Array.isArray(h) ? h.map(g) : g(h);
603
+ d && (k ? k.content = _(p) : r.push({ path: y, content: _(p) }));
604
604
  }
605
605
  } else s === "set-order" ? ne(i, t.name, t.order) : oe(i, t.name, t.drafts);
606
606
  const l = n.indexOf("export default");
@@ -613,17 +613,17 @@ function _e(n, e, s) {
613
613
  for (const a of ["pages", "globals", "collections", "blocks"])
614
614
  for (const [l, u] of Object.entries(s[a] ?? {})) {
615
615
  if (!m(u)) continue;
616
- const p = u.fields ?? {};
617
- if (!m(p)) throw new c(400, "Fields must contain an object");
618
- o[a] ??= {}, o[a][l] ??= { fields: {} }, K(o, a, l, p);
616
+ const w = u.fields ?? {};
617
+ if (!m(w)) throw new c(400, "Fields must contain an object");
618
+ o[a] ??= {}, o[a][l] ??= { fields: {} }, K(o, a, l, w);
619
619
  }
620
620
  const i = /* @__PURE__ */ new Map();
621
621
  for (const [a, l] of Object.entries(s.collections ?? {})) {
622
622
  if (!m(l) || !t.collections?.[a]) continue;
623
623
  const u = ie("save-fields", { kind: "collections", name: a, fields: l.fields ?? {} });
624
624
  if (H(t, e, u), !D(t, u)) continue;
625
- const p = we(n, e, "save-fields", u);
626
- for (const f of p.writes) f.path !== "schema.ts" && i.set(f.path, f.content);
625
+ const w = pe(n, e, "save-fields", u);
626
+ for (const f of w.writes) f.path !== "schema.ts" && i.set(f.path, f.content);
627
627
  }
628
628
  const r = n.indexOf("export default");
629
629
  return i.set("schema.ts", R(s, r > 0 ? n.slice(0, r) : void 0)), { schema: s, writes: [...i].map(([a, l]) => ({ path: a, content: l })), removals: [] };
@@ -655,7 +655,7 @@ export {
655
655
  V as g,
656
656
  D as h,
657
657
  Se as i,
658
- we as j,
658
+ pe as j,
659
659
  me as k,
660
660
  ue as l,
661
661
  F as m,
@@ -1,7 +1,7 @@
1
1
  import { readFileSync as w, existsSync as g, lstatSync as S, readdirSync as M, unlinkSync as v, writeFileSync as b } from "node:fs";
2
2
  import { join as a } from "node:path";
3
3
  import "./acorn-oIjaFBVA.js";
4
- import { E as p, a as L, v as T, h as E, b as F, c as x, d as R, f as j, g as N, j as W, k as P, l as H, m as _, o as q } from "./schema-mutation-BWtb40Qj.js";
4
+ import { E as p, a as L, v as T, h as E, b as F, c as x, d as R, f as j, g as N, j as W, k as P, l as H, m as _, o as q } from "./schema-mutation-DQ7d4rmd.js";
5
5
  import { createHash as z } from "node:crypto";
6
6
  const $ = /* @__PURE__ */ new Map(), C = (s) => z("sha256").update(s).digest("hex");
7
7
  function k(s, n) {
@@ -1,4 +1,4 @@
1
- import { o as a } from "../plugin-DNXklUmq.js";
1
+ import { o as a } from "../plugin-BAurTuo8.js";
2
2
  export {
3
3
  a as okno
4
4
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "okno",
3
3
  "description": "Git-backed CMS with live editing for any Vite framework",
4
4
  "author": "Gabriel Uhlíř",
5
- "version": "1.0.0-beta.47",
5
+ "version": "1.0.0-beta.49",
6
6
  "homepage": "https://okno.build",
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",
@@ -6,7 +6,7 @@ description: >
6
6
  working through Okno MCP, or wiring spread-to-edit rendering and typed props.
7
7
  metadata:
8
8
  author: okno
9
- version: "1.1.0"
9
+ version: "1.2.0"
10
10
  ---
11
11
 
12
12
  # Connect Okno
@@ -71,8 +71,9 @@ Slotted Text fields are callable and spreadable: `<h1 {...home.greeting({ name:
71
71
  Match schema `url` values to its real routes; the framework owns routing.
72
72
  Give collections a slug field and store reference targets as slugs, not
73
73
  resolved objects. For polymorphic blocks, keep each instance's `__block` key.
74
- 5. Run the consumer's relevant checks, such as `bun run build` and its declared
75
- type-check script. Verify written content and rendered hooks; a successful
74
+ 5. Run the consumer's relevant checks, such as `bun run build`, its declared
75
+ type-check script and `bunx --no-install okno check` (the contract rules a type
76
+ checker accepts). Verify written content and rendered hooks; a successful
76
77
  tool response alone does not prove a connected page or a live deployment.
77
78
 
78
79
  ## Keep wrapped content through the component
@@ -5,6 +5,24 @@ that schema in a framework content collection, loader, or component props schema
5
5
  Components still declare which content they accept; the field shape comes from
6
6
  Okno rather than a second handwritten definition.
7
7
 
8
+ ## Rules at a glance
9
+
10
+ Every rule below is detailed further down. `npx okno check` reports the ones
11
+ marked ✓ in the project's templates.
12
+
13
+ 1. **Imports:** content from `okno/pages`, `okno/collections`, `okno/globals`; block types with `import type` from `okno/blocks` (✓). Never the old `okno:*` syntax (✓).
14
+ 2. **Types:** derive props from Okno (`typeof home.card`, `(typeof articles)[number]`, `okno/blocks`). Never repeat a schema's fields in an interface.
15
+ 3. **Whole block, one prop:** `<Card {card} />`, with the prop required. A bare `<Card {...card} />` passes only edit hooks.
16
+ 4. **Spread on the native element:** `<h1 {...home.title}>{home.title}</h1>`, `<img {...home.cover}>`, `<a {...home.cta}>{home.cta}</a>`. Components forward the spread to their DOM root.
17
+ 5. **No hand-written hooks:** spreads supply `data-okno`, `data-okno-item` and locale attributes (✓). Forwarding a wrapper's own hook value is fine.
18
+ 6. **Presence:** wrappers are always truthy. Test `field.exists` (or `list.length`), never `field && …` or `if (field)` (✓).
19
+ 7. **Raw values:** `.value` for comparisons and primitive props, `.name` for an Option's label. Rendering already shows the stored value, so no `{String(field)}` (✓).
20
+ 8. **Lists:** Multiple fields are real arrays (`[]` when empty). Spread each item on its native root; `.drag` only for a different wrapper element.
21
+ 9. **Empty media:** guard optimized images with `.exists` and keep a marked `<img {...cover} alt="" />` for the empty slot.
22
+ 10. **Dates:** `const d = article.date.format(…)` then `<time {...d} datetime={d.value}>{d}</time>`.
23
+ 11. **Creation preview:** append `collection.new` to the dynamic route's paths after filtering records.
24
+ 12. **List order:** keep a section's `<script>` and other non-item siblings out of a rendered list, so the editor can add, reorder and remove items live.
25
+
8
26
  ## Infer from content you already import
9
27
 
10
28
  ```ts
@@ -286,11 +304,11 @@ Components must forward spread attributes onto their actual DOM element to prese
286
304
 
287
305
  ## Presence, localization and native attributes
288
306
 
289
- - **Unset content:** wrappers are objects and therefore truthy. Use `field.exists`, not `if (field)`, to determine whether a value is present. Option name/value are empty strings when unselected; a Multiple field is a real array and an empty selection is `[]`.
307
+ - **Unset content:** wrappers are objects and therefore truthy. Use `field.exists`, not `if (field)`, to determine whether a value is present. An empty string is no value for media, date, link, reference, number, color and boolean fields (`.exists` is false); a text field holding `""` still exists. Option name/value are empty strings when unselected; a Multiple field is a real array and an empty selection is `[]`.
290
308
  - **Locale:** read an entry with `home.locale("es")` or select entries with `const { home } = pages.locale("es")` before rendering. The same fields and props remain typed; forwarded native spreads retain locale identity. Okno does not own framework routing.
291
309
  - **Native media/link fields:** `<img {...home.cover} />` forwards src, shared alt and dimensions; `<a {...home.link}>{home.link}</a>` forwards href and external-link attributes. Do not overwrite shared alt accidentally. HTML-intended text uses the field spread together with framework HTML rendering, such as `set:html`.
292
310
  - **Multiline text keeps its line breaks:** a Text field with Multiline on spreads `style` with `white-space: pre-line`, so `<p {...home.intro}>{home.intro}</p>` renders each typed line. The spread's `style` is an object (`{ whiteSpace: "pre-line" }`) that reads as `white-space:pre-line` where a string is expected, so React, Vue, Svelte and Astro all accept it. **Attributes written after a spread replace it:** put your own `style` after the spread and include `white-space: pre-line` yourself (`<p {...home.intro} style="color: red; white-space: pre-line">`); a `style` written before the spread is replaced by the spread's. Single-line and HTML-enabled Text spread no `style`.
293
- - **Lists:** spread `{...card}` on each native item. Okno infers the list container and sibling units from the generated membership hooks; no manual container attribute is required. Inside a component, spread the complete block prop onto its native root. `.drag` places membership hooks on a different semantic wrapper, such as a list item containing a linked field. After an observed empty list receives its first item without a compatible live layout, the editor shows a save-and-refresh helper beneath the field or collection listing. Existing item layouts continue to preview additions immediately; removing and restoring items can reuse the current preview cache.
311
+ - **Lists:** spread `{...card}` on each native item. Okno infers the list container and sibling units from the generated membership hooks; no manual container attribute is required. Rendered items must be adjacent siblings for live add, reorder and remove: an element between them, such as a component's `<script>` rendered after its root, makes the editor ask for a refresh instead. Put such elements inside the item's root. Inside a component, spread the complete block prop onto its native root. `.drag` places membership hooks on a different semantic wrapper, such as a list item containing a linked field. After an observed empty list receives its first item without a compatible live layout, the editor shows a save-and-refresh helper beneath the field or collection listing. Existing item layouts continue to preview additions immediately; removing and restoring items can reuse the current preview cache.
294
312
  - **Component reactivity:** server-rendered component props establish initial output. Editor hooks update supported DOM values/lists; they do not recompute arbitrary component JavaScript or animation logic. Use the existing preview-renderer API where immediate custom component behavior is needed.
295
313
 
296
314
  ## Required fields while authoring
@@ -132,6 +132,8 @@ function readItem(node: HTMLElement, path: string, index: number, desired?: Prev
132
132
  for (const leaf of leaves) {
133
133
  const marker = leaf.getAttribute(contentAttr)!
134
134
  if (marker !== contentPath && !marker.startsWith(contentPath + ".")) continue
135
+ // A block or group spread wraps its bound fields; its value is read from them.
136
+ if (leaf.querySelector(`[${contentAttr}]`)) continue
135
137
  const field = snapshot?.values[marker]
136
138
  let observed: unknown = leaf.textContent ?? ""
137
139
  if (["IMG", "VIDEO", "AUDIO", "SOURCE"].includes(leaf.tagName)) observed = { src: leaf.getAttribute("src") ?? "", ...(leaf.tagName === "IMG" ? { alt: leaf.getAttribute("alt") ?? "" } : {}) }
@@ -492,6 +492,8 @@ interface WrapCtx {
492
492
  icon?: boolean
493
493
  /** Date-only presentation; stored values and subscriptions remain raw. */
494
494
  date?: boolean
495
+ /** An empty string is no value for this field type (`.exists` is false). */
496
+ emptyUnset?: boolean
495
497
  dateFormat?: DateFormatDescriptor
496
498
  dateFormatExplicitLocale?: boolean
497
499
  /** Bound arguments belong to this rendered call, never the source callable. */
@@ -541,7 +543,7 @@ function valueContext(ctx: WrapCtx | undefined, value: unknown): WrapCtx | undef
541
543
  // Keep the options until each repeated member reaches wrapValue. Nested
542
544
  // records keep stored strings and resolve only the Option that is read.
543
545
  if (def.type === "enum") return { ...ctx, fields: undefined, html: undefined, multiline: undefined, icon: false, option: true, date: false, dateFormat: undefined }
544
- return { ...ctx, fields: undefined, valueDef: undefined, html: def.type === "string" && def.html === true, multiline: def.type === "string" && def.multiline === true && def.html !== true, icon: def.type === "icon", option: false, date: def.type === "date", dateFormat: undefined }
546
+ return { ...ctx, fields: undefined, valueDef: undefined, html: def.type === "string" && def.html === true, multiline: def.type === "string" && def.multiline === true && def.html !== true, icon: def.type === "icon", option: false, date: def.type === "date", dateFormat: undefined, emptyUnset: UNSET_WHEN_EMPTY.has(def.type) }
545
547
  }
546
548
 
547
549
  /** Lift the slot defs out of an entry's `fields` (schema) into a map keyed by
@@ -577,6 +579,9 @@ export function __oknoLiftSlots(fields: unknown): Record<string, SlotDefs> {
577
579
  * — the §2 rule, shared with the strings store. Omitted when the entry has no
578
580
  * slots, keeping the common path untouched.
579
581
  */
582
+ /** Field types for which an empty string is not a value. */
583
+ const UNSET_WHEN_EMPTY = new Set(["media", "date", "link", "reference", "icon", "number", "color", "boolean"])
584
+
580
585
  export function __oknoWrap(data: unknown, prefix: string, drag?: string, ctx?: WrapCtx): any {
581
586
  const wrapper = { __raw: data, __path: prefix, __drag: drag }
582
587
  const domLocale = localeAttribute(ctx)
@@ -663,7 +668,9 @@ export function __oknoWrap(data: unknown, prefix: string, drag?: string, ctx?: W
663
668
  // is the explicit emptiness check: an unset ref / missing field has a
664
669
  // null/undefined raw → false. (Reserved key: a content field literally
665
670
  // named "exists" is shadowed by this — rename it if you hit that.)
666
- if (prop === "exists") return target.__raw !== null && target.__raw !== undefined
671
+ // The editor stores "" for an unset media, date, link or reference; "" is
672
+ // never a value of those types, so it reads as unset too.
673
+ if (prop === "exists") return target.__raw !== null && target.__raw !== undefined && !(target.__raw === "" && ctx?.emptyUnset)
667
674
 
668
675
  // `.value` — the RAW, correctly-typed primitive (string / number / boolean),
669
676
  // for the few spots that need a real string and won't coerce a wrapper: a
@@ -809,7 +816,7 @@ export function __oknoWrap(data: unknown, prefix: string, drag?: string, ctx?: W
809
816
  raw !== null && typeof raw === "object" && !Array.isArray(raw)
810
817
  ? (raw as Record<string, unknown>)[String(prop)]
811
818
  : undefined
812
- const childCtx = valueContext(ctx ? { ...ctx, rel: childRel, valueDef: childDef, html: undefined, multiline: undefined, icon: undefined, option: undefined, date: undefined, dateFormat: undefined, dateFormatExplicitLocale: undefined, collection: false } : undefined, rawChild)
819
+ const childCtx = valueContext(ctx ? { ...ctx, rel: childRel, valueDef: childDef, html: undefined, multiline: undefined, icon: undefined, option: undefined, date: undefined, dateFormat: undefined, dateFormatExplicitLocale: undefined, emptyUnset: undefined, collection: false } : undefined, rawChild)
813
820
 
814
821
  // Slotted plain-text field → a FUNCTION (the §2 rule, shared with strings).
815
822
  // The stored value is a template (or a per-CLDR-category plural object);
@@ -877,7 +884,8 @@ export function __oknoWrap(data: unknown, prefix: string, drag?: string, ctx?: W
877
884
  let childValue = (raw as Record<string, unknown>)[String(prop)]
878
885
  if (childDef?.type === "reference") childValue = resolveLazyReferences(childValue, childDef, ctx)
879
886
 
880
- if (childValue === undefined || childValue === null) {
887
+ // Older editors stored "" for an unset Multiple field; it reads as an empty list too.
888
+ if (childValue === undefined || childValue === null || childDef?.multiple && childValue === "") {
881
889
  // Non-existing field — an empty array for a Multiple field (its
882
890
  // contract is a real array), otherwise an empty proxy.
883
891
  if (childDef?.multiple) return wrapValue([], childPath, undefined, childCtx)