okno 1.0.0-alpha.15 → 1.0.0-alpha.16

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 +1 @@
1
- {"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/runtime/wrap.ts"],"names":[],"mappings":"AAyGA;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAChD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CA2L5E;AA0CD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,EACvC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC9B,OAAO,CA4BT;AAiBD,MAAM,WAAW,mBAAmB;IACnC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAA;IACnC,cAAc;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;kFAG8E;IAC9E,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC;;kEAE8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,C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C,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B;AAsGD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CA6DtE;AA6DD;2EAC2E;AAC3E,wBAAgB,mBAAmB,IAAI,IAAI,CAK1C"}
@@ -1,13 +1,13 @@
1
1
  const y = /* @__PURE__ */ new Map();
2
2
  let b = !1;
3
- function T() {
3
+ function E() {
4
4
  const t = globalThis;
5
5
  b || typeof t.document > "u" || (b = !0, t.document.addEventListener("okno:change", (r) => {
6
6
  const { path: i, value: c } = r.detail;
7
7
  y.get(i)?.forEach((n) => n(c));
8
8
  }));
9
9
  }
10
- const E = /* @__PURE__ */ new Set([
10
+ const j = /* @__PURE__ */ new Set([
11
11
  "src",
12
12
  "href",
13
13
  "alt",
@@ -20,14 +20,14 @@ const E = /* @__PURE__ */ new Set([
20
20
  "name",
21
21
  "value"
22
22
  ]);
23
- function j(t) {
23
+ function O(t) {
24
24
  return t.replace(/[-_]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim().replace(/^./, (r) => r.toUpperCase());
25
25
  }
26
26
  function v(t, r = "") {
27
27
  if (t == null) {
28
28
  if (!r) return "";
29
29
  const i = r.split(".").pop() ?? "";
30
- return !i || E.has(i) ? "" : j(i);
30
+ return !i || j.has(i) ? "" : O(i);
31
31
  }
32
32
  return typeof t != "object" ? String(t) : m(t) ? t.text ?? "" : "";
33
33
  }
@@ -37,19 +37,19 @@ function w(t) {
37
37
  function m(t) {
38
38
  return typeof t == "object" && t !== null && !Array.isArray(t) && "url" in t && "text" in t && "external" in t;
39
39
  }
40
- function k(t, r) {
40
+ function S(t, r) {
41
41
  if (r === void 0) return t;
42
42
  if (t === null || typeof t != "object" || Array.isArray(t) || r === null || typeof r != "object" || Array.isArray(r))
43
43
  return r;
44
44
  const i = { ...t };
45
45
  for (const c of Object.keys(r))
46
- i[c] = k(t[c], r[c]);
46
+ i[c] = S(t[c], r[c]);
47
47
  return i;
48
48
  }
49
49
  function z(t, r) {
50
50
  const i = { ...t };
51
51
  for (const c of Object.keys(r))
52
- i[c] = k(t, r[c]);
52
+ i[c] = S(t, r[c]);
53
53
  return i;
54
54
  }
55
55
  function _(t, r, i) {
@@ -70,7 +70,7 @@ function _(t, r, i) {
70
70
  if (e === "toJSON") return () => n.__raw;
71
71
  if (e === "on")
72
72
  return (u) => {
73
- T();
73
+ E();
74
74
  const s = n.__path;
75
75
  return y.has(s) || y.set(s, /* @__PURE__ */ new Set()), y.get(s).add(u), () => {
76
76
  y.get(s)?.delete(u), y.get(s)?.size === 0 && y.delete(s);
@@ -96,7 +96,7 @@ function _(t, r, i) {
96
96
  }
97
97
  if (o != null && typeof o == "object" && !Array.isArray(o)) {
98
98
  const u = o[String(e)];
99
- return u == null ? _(null, f) : S(u, f);
99
+ return u == null ? _(null, f) : T(u, f);
100
100
  }
101
101
  return _(null, f);
102
102
  },
@@ -129,15 +129,22 @@ function _(t, r, i) {
129
129
  }
130
130
  });
131
131
  }
132
- function x(t) {
132
+ function k(t) {
133
133
  return t !== null && typeof t == "object" && !Array.isArray(t) && "__oknoRef" in t;
134
134
  }
135
- function S(t, r, i) {
136
- if (x(t)) {
135
+ function T(t, r, i) {
136
+ if (k(t)) {
137
137
  const { path: c, data: n } = t.__oknoRef;
138
138
  return _(n, c, i ?? c);
139
139
  }
140
- return Array.isArray(t) ? t.map((c, n) => S(c, `${r}.${n}`, `${r}.${n}`)) : _(t, r, i);
140
+ if (Array.isArray(t)) {
141
+ const c = t.map((n, e) => T(n, `${r}.${e}`, `${r}.${e}`));
142
+ return Object.defineProperty(c, "toJSON", {
143
+ value: () => t.map((n) => k(n) ? n.__oknoRef.data : n),
144
+ enumerable: !1
145
+ }), c;
146
+ }
147
+ return _(t, r, i);
141
148
  }
142
149
  function B(t, r, i) {
143
150
  if (!t || typeof t != "object" || Array.isArray(t) || !r) return t;
@@ -147,20 +154,20 @@ function B(t, r, i) {
147
154
  if (!e || e.type !== "reference" || typeof e.collection != "string") continue;
148
155
  const o = i?.[e.collection] ?? i?.[e.collection.replace(/-/g, "_")] ?? [], f = (s) => {
149
156
  if (typeof s != "string" || !s) return null;
150
- const l = o.find((g) => {
157
+ const a = o.find((g) => {
151
158
  const A = typeof g?.toJSON == "function" ? g.toJSON() : g;
152
159
  return A && typeof A == "object" && A.slug === s;
153
160
  });
154
- if (!l) return null;
155
- const a = typeof l.toJSON == "function" ? l.toJSON() : l;
156
- return { __oknoRef: { path: `${e.collection}.${s}`, data: a } };
161
+ if (!a) return null;
162
+ const l = typeof a.toJSON == "function" ? a.toJSON() : a;
163
+ return { __oknoRef: { path: `${e.collection}.${s}`, data: l } };
157
164
  }, u = t[n];
158
165
  c[n] = Array.isArray(u) ? u.map(f).filter(Boolean) : f(u);
159
166
  }
160
167
  return c;
161
168
  }
162
- const p = "data-okno-item", d = "data-okno", O = [d, p];
163
- function h(t, r, i, c = O) {
169
+ const p = "data-okno-item", h = "data-okno", x = [h, p];
170
+ function d(t, r, i, c = x) {
164
171
  if (r === i) return;
165
172
  const n = (e) => {
166
173
  for (const o of c) {
@@ -186,70 +193,70 @@ function L(t) {
186
193
  wrappers: e.sort((o, f) => c(o) - c(f))
187
194
  }));
188
195
  }
189
- function M(t) {
190
- t.querySelectorAll(`[${d}]`).forEach((r) => {
196
+ function N(t) {
197
+ t.querySelectorAll(`[${h}]`).forEach((r) => {
191
198
  r.children.length === 0 && (r.textContent = "");
192
199
  });
193
200
  }
194
- function N(t, r) {
195
- t.querySelectorAll(`[${d}]`).forEach((i) => {
196
- const c = i.getAttribute(d);
201
+ function R(t, r) {
202
+ t.querySelectorAll(`[${h}]`).forEach((i) => {
203
+ const c = i.getAttribute(h);
197
204
  c && c in r && i.children.length === 0 && (i.textContent = r[c] ?? "");
198
205
  });
199
206
  }
200
- function R() {
207
+ function M() {
201
208
  return typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
202
209
  }
203
210
  function C(t) {
204
211
  const r = document;
205
- return typeof r.startViewTransition != "function" || R() ? (t(), Promise.resolve()) : r.startViewTransition(t).finished.catch(() => {
212
+ return typeof r.startViewTransition != "function" || M() ? (t(), Promise.resolve()) : r.startViewTransition(t).finished.catch(() => {
206
213
  });
207
214
  }
208
215
  let H = 0;
209
216
  function I(t) {
210
217
  if (typeof document > "u" || !t?.list || !t.op) return;
211
218
  const { list: r, op: i } = t, c = L(r);
212
- if (i === "insert" && c.every((l) => l.wrappers.length === 0) || c.length === 0) return;
213
- const n = [], e = (l) => {
214
- l.style.viewTransitionName = `okno-vt-${++H}`, n.push(l);
219
+ if (i === "insert" && c.every((a) => a.wrappers.length === 0) || c.length === 0) return;
220
+ const n = [], e = (a) => {
221
+ a.style.viewTransitionName = `okno-vt-${++H}`, n.push(a);
215
222
  };
216
- for (const l of c) for (const a of l.wrappers) e(a);
223
+ for (const a of c) for (const l of a.wrappers) e(l);
217
224
  const o = document.documentElement;
218
225
  o.classList.add("okno-vt-active");
219
226
  const f = document.getElementById("okno-shadow-root"), u = f instanceof HTMLElement ? f.style.cssText : null;
220
227
  f instanceof HTMLElement && (f.style.cssText = `${u};position:fixed;inset:0;pointer-events:none;view-transition-name:okno-editor`), C(() => {
221
- for (const l of c)
222
- i === "reorder" ? V(l, r, t.from, t.to) : i === "remove" ? q(l, r, t.index) : i === "insert" && J(l, r, t, e);
228
+ for (const a of c)
229
+ i === "reorder" ? J(a, r, t.from, t.to) : i === "remove" ? V(a, r, t.index) : i === "insert" && q(a, r, t, e);
223
230
  }).finally(() => {
224
- for (const l of n) l.style.viewTransitionName = "";
231
+ for (const a of n) a.style.viewTransitionName = "";
225
232
  o.classList.remove("okno-vt-active"), f instanceof HTMLElement && u !== null && (f.style.cssText = u);
226
233
  });
227
234
  }
228
- function V(t, r, i, c) {
235
+ function J(t, r, i, c) {
229
236
  const n = t.wrappers, e = n.length;
230
237
  if (i < 0 || i >= e || c < 0 || c >= e || i === c) return;
231
238
  const o = n.slice(), [f] = o.splice(i, 1);
232
239
  o.splice(c, 0, f);
233
- const u = o.map((l) => l.getAttribute(p));
234
- o.forEach((l, a) => h(l, u[a], `${r}.${a}`));
240
+ const u = o.map((a) => a.getAttribute(p));
241
+ o.forEach((a, l) => d(a, u[l], `${r}.${l}`));
235
242
  const s = n[e - 1].nextSibling;
236
- for (const l of o) t.parent.insertBefore(l, s);
243
+ for (const a of o) t.parent.insertBefore(a, s);
237
244
  }
238
- function q(t, r, i) {
245
+ function V(t, r, i) {
239
246
  const c = t.wrappers;
240
247
  if (!(i < 0 || i >= c.length)) {
241
248
  c[i].remove();
242
- for (let n = i + 1; n < c.length; n++) h(c[n], `${r}.${n}`, `${r}.${n - 1}`);
249
+ for (let n = i + 1; n < c.length; n++) d(c[n], `${r}.${n}`, `${r}.${n - 1}`);
243
250
  }
244
251
  }
245
- function J(t, r, i, c) {
252
+ function q(t, r, i, c) {
246
253
  const n = t.wrappers, e = n.length;
247
254
  if (e === 0) return;
248
255
  const o = Math.max(0, Math.min(i.index ?? e, e)), f = o < e ? o : e - 1, u = n[f].getAttribute(p), s = n[f].cloneNode(!0);
249
- for (let a = e - 1; a >= o; a--) h(n[a], `${r}.${a}`, `${r}.${a + 1}`);
250
- h(s, u, `${r}.${o}`), i.remap && h(s, i.remap.from, i.remap.to, [d]), i.values ? N(s, i.values) : M(s), s.style.viewTransitionName = "", c(s);
251
- const l = o < e ? n[o] : n[e - 1].nextSibling;
252
- t.parent.insertBefore(s, l);
256
+ for (let l = e - 1; l >= o; l--) d(n[l], `${r}.${l}`, `${r}.${l + 1}`);
257
+ d(s, u, `${r}.${o}`), i.remap && d(s, i.remap.from, i.remap.to, [h]), i.values ? R(s, i.values) : N(s), s.style.viewTransitionName = "", c(s);
258
+ const a = o < e ? n[o] : n[e - 1].nextSibling;
259
+ t.parent.insertBefore(s, a);
253
260
  }
254
261
  let $ = !1;
255
262
  function P() {
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-alpha.15",
5
+ "version": "1.0.0-alpha.16",
6
6
  "homepage": "https://okno.build",
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",
@@ -353,7 +353,17 @@ function wrapValue(value: unknown, fallbackPath: string, slot?: string): any {
353
353
  return __oknoWrap(data, path, slot ?? path)
354
354
  }
355
355
  if (Array.isArray(value)) {
356
- return value.map((el, i) => wrapValue(el, `${fallbackPath}.${i}`, `${fallbackPath}.${i}`))
356
+ const wrapped = value.map((el, i) => wrapValue(el, `${fallbackPath}.${i}`, `${fallbackPath}.${i}`))
357
+ // Keep the field API on array fields: `.toJSON()` yields the RAW items, the
358
+ // supported way to read a `multiple` block array (e.g. okno.build's homepage
359
+ // `headlines`). The wrapped value is a real array so `.map()`/iteration/spread
360
+ // keep working; `toJSON` is non-enumerable so it never leaks into those.
361
+ // Resolved references unwrap to their data so callers get clean raw items.
362
+ Object.defineProperty(wrapped, "toJSON", {
363
+ value: () => value.map((el) => (isOknoRef(el) ? el.__oknoRef.data : el)),
364
+ enumerable: false,
365
+ })
366
+ return wrapped
357
367
  }
358
368
  return __oknoWrap(value, fallbackPath, slot)
359
369
  }