@b10cks/client 1.12.0 → 2.0.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/README.md +34 -1
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +151 -7
- package/dist/index.mjs +297 -187
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.mjs
CHANGED
|
@@ -261,14 +261,23 @@ function f(e) {
|
|
|
261
261
|
}
|
|
262
262
|
//#endregion
|
|
263
263
|
//#region src/preview-bridge.ts
|
|
264
|
-
var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Array.isArray(e) && e.every((e) => typeof e == "string" || typeof e == "number" && Number.isInteger(e) && e >= 0), h =
|
|
264
|
+
var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Array.isArray(e) && e.every((e) => typeof e == "string" || typeof e == "number" && Number.isInteger(e) && e >= 0), h = [
|
|
265
|
+
"h1",
|
|
266
|
+
"h2",
|
|
267
|
+
"h3",
|
|
268
|
+
"h4",
|
|
269
|
+
"h5",
|
|
270
|
+
"h6",
|
|
271
|
+
"p"
|
|
272
|
+
], g = (e) => p(e) && (e.features === void 0 || p(e.features) && Object.values(e.features).every((e) => typeof e == "boolean")) && (e.headingLevels === void 0 || Array.isArray(e.headingLevels) && e.headingLevels.every((e) => h.some((t) => t === e))), _ = (e) => e.selectedItem === null || typeof e.selectedItem == "string", ee = {
|
|
265
273
|
CONTENT_UPDATE: (e) => p(e.content),
|
|
266
274
|
CONTENT_PATCH: (e) => m(e.path) && "value" in e && (e.itemId === void 0 || typeof e.itemId == "string"),
|
|
267
|
-
SELECT_UPDATE:
|
|
268
|
-
HOVER_UPDATE:
|
|
275
|
+
SELECT_UPDATE: _,
|
|
276
|
+
HOVER_UPDATE: _,
|
|
277
|
+
FIELD_CONFIG: (e) => typeof e.itemId == "string" && e.itemId !== "" && m(e.path) && g(e.richtext),
|
|
269
278
|
BLOCK_LABELS: (e) => p(e.labels) && Object.values(e.labels).every((e) => typeof e == "string"),
|
|
270
279
|
HIDDEN_BLOCKS: (e) => Array.isArray(e.ids) && e.ids.every((e) => typeof e == "string")
|
|
271
|
-
},
|
|
280
|
+
}, te = (e) => typeof e == "string" && Object.hasOwn(ee, e), ne = "B10CKS_BRIDGE_READY", re = 3, ie = class e {
|
|
272
281
|
static instance;
|
|
273
282
|
listeners = {};
|
|
274
283
|
received = {};
|
|
@@ -286,8 +295,8 @@ var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Arra
|
|
|
286
295
|
return;
|
|
287
296
|
}
|
|
288
297
|
this.allowedOrigins = e.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({
|
|
289
|
-
type:
|
|
290
|
-
payload: { protocol:
|
|
298
|
+
type: ne,
|
|
299
|
+
payload: { protocol: 3 }
|
|
291
300
|
}, "*");
|
|
292
301
|
}
|
|
293
302
|
}
|
|
@@ -331,6 +340,9 @@ var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Arra
|
|
|
331
340
|
value: n
|
|
332
341
|
});
|
|
333
342
|
}
|
|
343
|
+
patchLocal(e) {
|
|
344
|
+
this.isInPreviewMode() && this.notify("CONTENT_PATCH", e);
|
|
345
|
+
}
|
|
334
346
|
blockAction(e, t) {
|
|
335
347
|
this.post("BLOCK_ACTION", {
|
|
336
348
|
itemId: e,
|
|
@@ -353,7 +365,7 @@ var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Arra
|
|
|
353
365
|
handleMessage = (e) => {
|
|
354
366
|
if (!this.isOriginTrusted(e.origin) || !e.data || typeof e.data != "object") return;
|
|
355
367
|
let { type: t, payload: n } = e.data;
|
|
356
|
-
|
|
368
|
+
te(t) && p(n) && ee[t](n) && (!this.parentOrigin && e.origin && e.origin !== "null" && (this.parentOrigin = e.origin), this.notify(t, n));
|
|
357
369
|
};
|
|
358
370
|
isOriginTrusted(e) {
|
|
359
371
|
return this.parentOrigin ? e === this.parentOrigin : !this.allowedOrigins || this.allowedOrigins.includes(e);
|
|
@@ -363,16 +375,16 @@ var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Arra
|
|
|
363
375
|
let n = this.listeners[e];
|
|
364
376
|
if (n) for (let e of n) e(t);
|
|
365
377
|
}
|
|
366
|
-
}, v =
|
|
378
|
+
}, v = ie.getInstance(), y = "rgb(59, 130, 246)", ae = 2, oe = `
|
|
367
379
|
:host { all: initial; position: fixed; inset: 0; pointer-events: none; z-index: 2147483647; }
|
|
368
380
|
[hidden] { display: none !important; }
|
|
369
381
|
.box {
|
|
370
382
|
position: fixed; top: 0; left: 0; box-sizing: border-box;
|
|
371
|
-
border: ${
|
|
383
|
+
border: ${ae}px solid ${y}; border-radius: 2px;
|
|
372
384
|
}
|
|
373
385
|
.box.hover { border-style: dashed; border-color: rgba(59, 130, 246, 0.6); }
|
|
374
386
|
.label {
|
|
375
|
-
position: absolute; left: 6px; bottom: 100%; margin-bottom: ${
|
|
387
|
+
position: absolute; left: 6px; bottom: 100%; margin-bottom: ${ae}px;
|
|
376
388
|
display: flex; align-items: center; padding: 0 6px; border-radius: 3px 3px 0 0; white-space: nowrap;
|
|
377
389
|
font: 500 11px/16px system-ui, -apple-system, sans-serif;
|
|
378
390
|
color: #fff; background: ${y};
|
|
@@ -402,7 +414,7 @@ var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Arra
|
|
|
402
414
|
position: fixed; top: 0; left: 0; border-radius: 2px;
|
|
403
415
|
background: ${y}; box-shadow: 0 0 0 1px #fff;
|
|
404
416
|
}
|
|
405
|
-
`,
|
|
417
|
+
`, se = [
|
|
406
418
|
{
|
|
407
419
|
action: "move-up",
|
|
408
420
|
label: "Move up",
|
|
@@ -433,12 +445,12 @@ var p = (e) => typeof e == "object" && !!e && !Array.isArray(e), m = (e) => Arra
|
|
|
433
445
|
label: "Delete",
|
|
434
446
|
icon: "<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>"
|
|
435
447
|
}
|
|
436
|
-
],
|
|
437
|
-
function
|
|
448
|
+
], ce = "<path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>", le = "<path d=\"M10.7 5.1A10.4 10.4 0 0 1 12 5c6.5 0 10 7 10 7a17 17 0 0 1-1.7 2.6M6.6 6.6A17 17 0 0 0 2 12s3.5 7 10 7a9.7 9.7 0 0 0 5.4-1.6M9.9 9.9a3 3 0 0 0 4.2 4.2M2 2l20 20\"/>", ue = "<g fill=\"currentColor\" stroke=\"none\"><circle cx=\"9\" cy=\"6\" r=\"1.5\"/><circle cx=\"15\" cy=\"6\" r=\"1.5\"/><circle cx=\"9\" cy=\"12\" r=\"1.5\"/><circle cx=\"15\" cy=\"12\" r=\"1.5\"/><circle cx=\"9\" cy=\"18\" r=\"1.5\"/><circle cx=\"15\" cy=\"18\" r=\"1.5\"/></g>", de = "Alt/Option-click to use links and buttons on the page";
|
|
449
|
+
function fe(e) {
|
|
438
450
|
let t = document.createElement("div");
|
|
439
451
|
t.id = "b10cks-overlay";
|
|
440
452
|
let n = t.attachShadow({ mode: "open" }), r = document.createElement("style");
|
|
441
|
-
r.textContent =
|
|
453
|
+
r.textContent = oe, n.appendChild(r);
|
|
442
454
|
let i = b("div", "box hover");
|
|
443
455
|
i.hidden = !0;
|
|
444
456
|
let a = b("div", "label name");
|
|
@@ -446,13 +458,13 @@ function ue(e) {
|
|
|
446
458
|
let o = b("div", "box selected");
|
|
447
459
|
o.hidden = !0;
|
|
448
460
|
let s = b("div", "label bar"), c = b("span", "crumbs"), l = b("span", "name");
|
|
449
|
-
l.title =
|
|
461
|
+
l.title = de;
|
|
450
462
|
let u = b("div", "tools");
|
|
451
463
|
u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Block actions");
|
|
452
464
|
let d = b("div", "tool handle");
|
|
453
|
-
d.title = "Drag to move", d.setAttribute("aria-hidden", "true"), d.innerHTML = x(
|
|
465
|
+
d.title = "Drag to move", d.setAttribute("aria-hidden", "true"), d.innerHTML = x(ue), d.addEventListener("pointerdown", (t) => e.onDragStart(t, d));
|
|
454
466
|
let f = /* @__PURE__ */ new Map();
|
|
455
|
-
for (let t of
|
|
467
|
+
for (let t of se) {
|
|
456
468
|
let n = b("button", "tool");
|
|
457
469
|
n.type = "button", n.title = t.label, n.setAttribute("aria-label", t.label), n.innerHTML = x(t.icon), n.addEventListener("click", () => e.onAction(t.action)), f.set(t.action, n), u.appendChild(n);
|
|
458
470
|
}
|
|
@@ -461,9 +473,9 @@ function ue(e) {
|
|
|
461
473
|
let h = (e) => {
|
|
462
474
|
p = e;
|
|
463
475
|
let t = p ? "Show" : "Hide";
|
|
464
|
-
m.title = t, m.setAttribute("aria-label", t), m.setAttribute("aria-pressed", String(p)), m.innerHTML = x(p ?
|
|
476
|
+
m.title = t, m.setAttribute("aria-label", t), m.setAttribute("aria-pressed", String(p)), m.innerHTML = x(p ? le : ce);
|
|
465
477
|
};
|
|
466
|
-
h(!1), u.insertBefore(m, f.get("delete") ?? null), s.append(c, l, u), o.appendChild(s);
|
|
478
|
+
h(!1), u.insertBefore(m, f.get("delete") ?? null), s.append(d, c, l, u), o.appendChild(s);
|
|
467
479
|
let g = b("div", "indicator");
|
|
468
480
|
g.hidden = !0, n.append(i, o, g), document.body.appendChild(t);
|
|
469
481
|
let _ = "";
|
|
@@ -483,7 +495,7 @@ function ue(e) {
|
|
|
483
495
|
renderBar(t) {
|
|
484
496
|
if (s.hidden = !t || !t.label && t.crumbs.length === 0 && !t.actions, !t) return;
|
|
485
497
|
let n = t.crumbs.map((e) => `${e.id}\u0000${e.label}`).join("");
|
|
486
|
-
n !== _ && (_ = n, c.replaceChildren(...
|
|
498
|
+
n !== _ && (_ = n, c.replaceChildren(...pe(t.crumbs, e.onSelect))), l.textContent = t.label, u.hidden = !t.actions, d.hidden = !t.actions, he(f.get("move-up"), !t.actions?.canMoveUp), he(f.get("move-down"), !t.actions?.canMoveDown);
|
|
487
499
|
let r = t.actions?.hidden ?? null;
|
|
488
500
|
m.hidden = r === null, r !== null && r !== p && h(r);
|
|
489
501
|
},
|
|
@@ -492,23 +504,23 @@ function ue(e) {
|
|
|
492
504
|
}
|
|
493
505
|
};
|
|
494
506
|
}
|
|
495
|
-
function
|
|
507
|
+
function pe(e, t) {
|
|
496
508
|
let n = [], r = e.slice(0, -3);
|
|
497
509
|
if (r.length > 0) {
|
|
498
510
|
let e = b("span", "more");
|
|
499
|
-
e.textContent = "…", e.title = r.map((e) => e.label).join(" › "), n.push(e,
|
|
511
|
+
e.textContent = "…", e.title = r.map((e) => e.label).join(" › "), n.push(e, me());
|
|
500
512
|
}
|
|
501
513
|
for (let r of e.slice(-3)) {
|
|
502
514
|
let e = b("button", "crumb");
|
|
503
|
-
e.type = "button", e.textContent = r.label, e.title = `Select ${r.label}`, e.addEventListener("click", () => t(r.id)), n.push(e,
|
|
515
|
+
e.type = "button", e.textContent = r.label, e.title = `Select ${r.label}`, e.addEventListener("click", () => t(r.id)), n.push(e, me());
|
|
504
516
|
}
|
|
505
517
|
return n;
|
|
506
518
|
}
|
|
507
|
-
function
|
|
519
|
+
function me() {
|
|
508
520
|
let e = b("span", "sep");
|
|
509
521
|
return e.textContent = "›", e.setAttribute("aria-hidden", "true"), e;
|
|
510
522
|
}
|
|
511
|
-
function
|
|
523
|
+
function he(e, t) {
|
|
512
524
|
e && (e.disabled = t);
|
|
513
525
|
}
|
|
514
526
|
function b(e, t) {
|
|
@@ -523,55 +535,55 @@ function x(e) {
|
|
|
523
535
|
var S = {
|
|
524
536
|
selected: "b10cks-selected",
|
|
525
537
|
hover: "b10cks-hover"
|
|
526
|
-
},
|
|
538
|
+
}, ge = "b10cks-hidden", C = 2, _e = 24, w = 3, T = /* @__PURE__ */ new Map(), E = {
|
|
527
539
|
selected: null,
|
|
528
540
|
hover: null
|
|
529
|
-
}, O = null, k = null, A = null, j = null, M =
|
|
530
|
-
function
|
|
531
|
-
return
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
for (let t of ["selected", "hover"])
|
|
535
|
-
|
|
541
|
+
}, D = null, O = null, k = null, A = null, j = null, M = !1, N = !1, P = !1, F = null;
|
|
542
|
+
function I(e, t) {
|
|
543
|
+
return T.set(e, t), t.kind === "block" && e.classList.toggle(ge, Re(t.id) === !0), O ||= ve(), t.kind === "block" && t.id === D && G(), () => {
|
|
544
|
+
if (T.get(e) === t) {
|
|
545
|
+
T.delete(e), t.kind === "block" && e.classList.remove(ge);
|
|
546
|
+
for (let t of ["selected", "hover"]) E[t] === e && (E[t] = null, e.classList.remove(S[t]));
|
|
547
|
+
T.size === 0 ? (O?.(), O = null) : G();
|
|
536
548
|
}
|
|
537
549
|
};
|
|
538
550
|
}
|
|
539
|
-
function
|
|
540
|
-
|
|
551
|
+
function ve() {
|
|
552
|
+
D = v.latest("SELECT_UPDATE")?.selectedItem ?? D, D && G();
|
|
541
553
|
let e = v.on("SELECT_UPDATE", ({ selectedItem: e }) => {
|
|
542
|
-
|
|
543
|
-
let t =
|
|
544
|
-
(t?.kind !== "field" || e && e !== t.id) && K("selected", B(
|
|
554
|
+
D = e || null;
|
|
555
|
+
let t = E.selected && T.get(E.selected);
|
|
556
|
+
(t?.kind !== "field" || e && e !== t.id) && K("selected", B(D));
|
|
545
557
|
}), t = v.on("HOVER_UPDATE", ({ selectedItem: e }) => {
|
|
546
558
|
K("hover", B(e || null));
|
|
547
559
|
}), n = v.on("BLOCK_LABELS", q), r = v.on("HIDDEN_BLOCKS", ({ ids: e }) => {
|
|
548
560
|
let t = new Set(e);
|
|
549
|
-
for (let [e, n] of
|
|
561
|
+
for (let [e, n] of T) n.kind === "block" && e.classList.toggle(ge, t.has(n.id));
|
|
550
562
|
q();
|
|
551
563
|
}), i = {
|
|
552
564
|
capture: !0,
|
|
553
565
|
passive: !0
|
|
554
566
|
};
|
|
555
|
-
return window.addEventListener("click", L, !0), window.addEventListener("auxclick", L, !0), window.addEventListener("keydown",
|
|
556
|
-
W(), e(), t(), n(), r(), window.removeEventListener("click", L, !0), window.removeEventListener("auxclick", L, !0), window.removeEventListener("keydown",
|
|
567
|
+
return window.addEventListener("click", L, !0), window.addEventListener("auxclick", L, !0), window.addEventListener("keydown", ye, !0), document.addEventListener("pointerover", Ce, !0), document.addEventListener("pointerout", we, !0), window.addEventListener("scroll", J, i), window.addEventListener("resize", J), A = typeof ResizeObserver > "u" ? null : new ResizeObserver(J), j = typeof MutationObserver > "u" ? null : new MutationObserver(q), () => {
|
|
568
|
+
W(), e(), t(), n(), r(), window.removeEventListener("click", L, !0), window.removeEventListener("auxclick", L, !0), window.removeEventListener("keydown", ye, !0), document.removeEventListener("pointerover", Ce, !0), document.removeEventListener("pointerout", we, !0), window.removeEventListener("scroll", J, i), window.removeEventListener("resize", J), A?.disconnect(), A = null, j?.disconnect(), j = null, E.selected = null, E.hover = null, k?.host.remove(), k = null;
|
|
557
569
|
};
|
|
558
570
|
}
|
|
559
571
|
function L(e) {
|
|
560
|
-
if (e.altKey) return;
|
|
561
|
-
let t =
|
|
562
|
-
t && (R(e), e.type === "click" && z(t, e));
|
|
572
|
+
if (e.altKey || k?.host && e.composedPath().includes(k.host) || e.composedPath().some((e) => e instanceof HTMLElement && e.isContentEditable)) return;
|
|
573
|
+
let t = Te(e);
|
|
574
|
+
t && !T.get(t)?.isEditing?.() && (R(e), e.type === "click" && z(t, e));
|
|
563
575
|
}
|
|
564
|
-
function
|
|
565
|
-
if (
|
|
576
|
+
function ye(e) {
|
|
577
|
+
if (F) {
|
|
566
578
|
e.key === "Escape" && (R(e), W());
|
|
567
579
|
return;
|
|
568
580
|
}
|
|
569
|
-
let t =
|
|
570
|
-
if (!t?.isConnected || e.defaultPrevented ||
|
|
581
|
+
let t = E.selected;
|
|
582
|
+
if (!t?.isConnected || e.defaultPrevented || be(e) || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
571
583
|
let n = null;
|
|
572
584
|
e.key === "Escape" ? n = H(t)[0] ?? null : e.key === "ArrowUp" ? n = U(t, -1) : e.key === "ArrowDown" && (n = U(t, 1)), n && (R(e), z(n));
|
|
573
585
|
}
|
|
574
|
-
function
|
|
586
|
+
function be(e) {
|
|
575
587
|
let t = e.composedPath()[0];
|
|
576
588
|
return t instanceof HTMLElement && (t.isContentEditable || t.matches("input, textarea, select"));
|
|
577
589
|
}
|
|
@@ -579,31 +591,31 @@ function R(e) {
|
|
|
579
591
|
e.preventDefault(), e.stopImmediatePropagation();
|
|
580
592
|
}
|
|
581
593
|
function z(e, t) {
|
|
582
|
-
let n =
|
|
583
|
-
n && (n.activate(t), n.kind === "block" && (
|
|
594
|
+
let n = T.get(e);
|
|
595
|
+
n && (n.activate(t), n.kind === "block" && (D = n.id), K("selected", e));
|
|
584
596
|
}
|
|
585
|
-
function
|
|
597
|
+
function xe(e) {
|
|
586
598
|
let t = B(e);
|
|
587
599
|
t && z(t);
|
|
588
600
|
}
|
|
589
|
-
function
|
|
590
|
-
let t =
|
|
601
|
+
function Se(e) {
|
|
602
|
+
let t = E.selected && T.get(E.selected);
|
|
591
603
|
t?.kind === "block" && v.blockAction(t.id, e);
|
|
592
604
|
}
|
|
593
|
-
function
|
|
594
|
-
K("hover",
|
|
605
|
+
function Ce(e) {
|
|
606
|
+
K("hover", Te(e));
|
|
595
607
|
}
|
|
596
|
-
function
|
|
608
|
+
function we(e) {
|
|
597
609
|
e.relatedTarget || K("hover", null);
|
|
598
610
|
}
|
|
599
|
-
function
|
|
600
|
-
for (let t of e.composedPath()) if (t instanceof HTMLElement &&
|
|
611
|
+
function Te(e) {
|
|
612
|
+
for (let t of e.composedPath()) if (t instanceof HTMLElement && T.has(t)) return t;
|
|
601
613
|
return null;
|
|
602
614
|
}
|
|
603
615
|
function B(e) {
|
|
604
616
|
if (!e) return null;
|
|
605
617
|
let t = null;
|
|
606
|
-
for (let [n, r] of
|
|
618
|
+
for (let [n, r] of T) r.kind === "block" && r.id === e && n.isConnected && (!t || t.contains(n)) && (t = n);
|
|
607
619
|
return t;
|
|
608
620
|
}
|
|
609
621
|
function V(e) {
|
|
@@ -612,76 +624,76 @@ function V(e) {
|
|
|
612
624
|
return t instanceof ShadowRoot ? t.host : null;
|
|
613
625
|
}
|
|
614
626
|
function H(e) {
|
|
615
|
-
let t = [], n =
|
|
627
|
+
let t = [], n = T.get(e), r = n?.kind === "block" ? n.id : null;
|
|
616
628
|
for (let n = V(e); n; n = V(n)) {
|
|
617
629
|
if (!(n instanceof HTMLElement)) continue;
|
|
618
|
-
let e =
|
|
630
|
+
let e = T.get(n);
|
|
619
631
|
e?.kind === "block" && e.id !== r && (t.push(n), r = e.id);
|
|
620
632
|
}
|
|
621
633
|
return t;
|
|
622
634
|
}
|
|
623
|
-
function
|
|
635
|
+
function Ee(e) {
|
|
624
636
|
let t = H(e)[0];
|
|
625
|
-
return (t &&
|
|
637
|
+
return (t && T.get(t)?.id) ?? null;
|
|
626
638
|
}
|
|
627
639
|
function U(e, t) {
|
|
628
|
-
let n =
|
|
640
|
+
let n = T.get(e);
|
|
629
641
|
if (n?.kind !== "block") return null;
|
|
630
|
-
let r =
|
|
631
|
-
for (let [t, o] of
|
|
632
|
-
return a && B(
|
|
642
|
+
let r = Ee(e), i = t === 1 ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING, a = null;
|
|
643
|
+
for (let [t, o] of T) o.kind === "block" && o.id !== n.id && t.isConnected && e.compareDocumentPosition(t) & i && (!a || t.compareDocumentPosition(a) & i) && Ee(t) === r && (a = t);
|
|
644
|
+
return a && B(T.get(a)?.id ?? null);
|
|
633
645
|
}
|
|
634
|
-
function
|
|
635
|
-
let t =
|
|
646
|
+
function De(e) {
|
|
647
|
+
let t = T.get(e);
|
|
636
648
|
if (!t) return null;
|
|
637
649
|
let n = H(e).reverse().flatMap((e) => {
|
|
638
|
-
let t =
|
|
650
|
+
let t = T.get(e);
|
|
639
651
|
return t ? [{
|
|
640
652
|
id: t.id,
|
|
641
|
-
label:
|
|
653
|
+
label: ze(t) || "Block"
|
|
642
654
|
}] : [];
|
|
643
655
|
});
|
|
644
656
|
return {
|
|
645
|
-
label:
|
|
657
|
+
label: ze(t),
|
|
646
658
|
crumbs: n,
|
|
647
|
-
actions: t.kind === "block" &&
|
|
659
|
+
actions: t.kind === "block" && H(e).length > 0 && Le() ? {
|
|
648
660
|
canMoveUp: !!U(e, -1),
|
|
649
661
|
canMoveDown: !!U(e, 1),
|
|
650
|
-
hidden:
|
|
662
|
+
hidden: Re(t.id)
|
|
651
663
|
} : null
|
|
652
664
|
};
|
|
653
665
|
}
|
|
654
|
-
function
|
|
655
|
-
let n =
|
|
656
|
-
n && r?.kind === "block" && e.button === 0 && (e.preventDefault(), e.isTrusted && t.setPointerCapture(e.pointerId),
|
|
666
|
+
function Oe(e, t) {
|
|
667
|
+
let n = E.selected, r = n && T.get(n);
|
|
668
|
+
n && r?.kind === "block" && e.button === 0 && (e.preventDefault(), e.isTrusted && t.setPointerCapture(e.pointerId), F = {
|
|
657
669
|
id: r.id,
|
|
658
670
|
el: n,
|
|
659
671
|
drop: null
|
|
660
|
-
},
|
|
672
|
+
}, k?.setDragging(!0), window.addEventListener("pointermove", ke, !0), window.addEventListener("pointerup", Ae, !0), window.addEventListener("pointercancel", W, !0));
|
|
661
673
|
}
|
|
662
|
-
function
|
|
663
|
-
|
|
674
|
+
function ke(e) {
|
|
675
|
+
F && (F.drop = je(F, e.clientX, e.clientY), K("hover", F.drop?.el ?? null), J());
|
|
664
676
|
}
|
|
665
|
-
function
|
|
666
|
-
let t =
|
|
677
|
+
function Ae(e) {
|
|
678
|
+
let t = F, n = t && je(t, e.clientX, e.clientY);
|
|
667
679
|
W(), t && n && v.moveBlock(t.id, n.id, n.position);
|
|
668
680
|
}
|
|
669
681
|
function W() {
|
|
670
|
-
|
|
682
|
+
F && (F = null, window.removeEventListener("pointermove", ke, !0), window.removeEventListener("pointerup", Ae, !0), window.removeEventListener("pointercancel", W, !0), k?.setDragging(!1), K("hover", null), J());
|
|
671
683
|
}
|
|
672
|
-
function
|
|
673
|
-
let r = document.elementsFromPoint(t, n).find((e) => e !==
|
|
684
|
+
function je(e, t, n) {
|
|
685
|
+
let r = document.elementsFromPoint(t, n).find((e) => e !== k?.host), i = null;
|
|
674
686
|
for (let t = r ?? null; t; t = V(t)) {
|
|
675
687
|
if (!(t instanceof HTMLElement)) continue;
|
|
676
|
-
let n =
|
|
688
|
+
let n = T.get(t);
|
|
677
689
|
if (n?.kind === "block") {
|
|
678
690
|
if (n.id === e.id) return null;
|
|
679
691
|
i ??= t;
|
|
680
692
|
}
|
|
681
693
|
}
|
|
682
|
-
let a = i &&
|
|
694
|
+
let a = i && T.get(i);
|
|
683
695
|
if (!i || !a || i.contains(e.el)) return null;
|
|
684
|
-
let o = i.getBoundingClientRect(), s = e.drop?.el === i ? e.drop.horizontal :
|
|
696
|
+
let o = i.getBoundingClientRect(), s = e.drop?.el === i ? e.drop.horizontal : Me(i, o), c = s ? t < o.left + o.width / 2 : n < o.top + o.height / 2;
|
|
685
697
|
return {
|
|
686
698
|
el: i,
|
|
687
699
|
id: a.id,
|
|
@@ -689,90 +701,90 @@ function ke(e, t, n) {
|
|
|
689
701
|
horizontal: s
|
|
690
702
|
};
|
|
691
703
|
}
|
|
692
|
-
function
|
|
704
|
+
function Me(e, t) {
|
|
693
705
|
let n = U(e, 1) ?? U(e, -1);
|
|
694
706
|
if (!n) return !1;
|
|
695
707
|
let r = n.getBoundingClientRect();
|
|
696
708
|
return r.top < t.bottom && r.bottom > t.top;
|
|
697
709
|
}
|
|
698
710
|
function G() {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
let e =
|
|
702
|
-
e?.isConnected &&
|
|
711
|
+
N || (N = !0, queueMicrotask(() => {
|
|
712
|
+
N = !1;
|
|
713
|
+
let e = E.selected;
|
|
714
|
+
e?.isConnected && T.get(e)?.kind === "field" || K("selected", B(D));
|
|
703
715
|
}));
|
|
704
716
|
}
|
|
705
717
|
function K(e, t) {
|
|
706
|
-
let n =
|
|
707
|
-
n !== t && (
|
|
718
|
+
let n = E[e];
|
|
719
|
+
n !== t && (E[e] = t, n && (n.classList.remove(S[e]), Ne(n, e, !1)), t && (t.classList.add(S[e]), Ne(t, e, !0), e === "selected" && T.get(t)?.scrollOnSelect && t.scrollIntoView?.({
|
|
708
720
|
block: "nearest",
|
|
709
721
|
behavior: "smooth"
|
|
710
|
-
})),
|
|
722
|
+
})), A && (A.disconnect(), A.observe(document.documentElement), E.selected && A.observe(E.selected), E.hover && A.observe(E.hover)), e === "selected" && (j?.disconnect(), t && j?.observe(document.body, {
|
|
711
723
|
childList: !0,
|
|
712
724
|
subtree: !0
|
|
713
|
-
}),
|
|
725
|
+
}), P = !0), J());
|
|
714
726
|
}
|
|
715
|
-
function
|
|
716
|
-
let r =
|
|
727
|
+
function Ne(e, t, n) {
|
|
728
|
+
let r = T.get(e);
|
|
717
729
|
t === "selected" ? r?.onSelectChange?.(n) : r?.onHoverChange?.(n);
|
|
718
730
|
}
|
|
719
731
|
function q() {
|
|
720
|
-
|
|
732
|
+
P = !0, J();
|
|
721
733
|
}
|
|
722
734
|
function J() {
|
|
723
|
-
|
|
724
|
-
|
|
735
|
+
M || (M = !0, requestAnimationFrame(() => {
|
|
736
|
+
M = !1, Pe();
|
|
725
737
|
}));
|
|
726
738
|
}
|
|
727
|
-
function
|
|
728
|
-
if (!
|
|
729
|
-
let { selected: e } =
|
|
730
|
-
if (!
|
|
731
|
-
|
|
732
|
-
onAction:
|
|
733
|
-
onSelect:
|
|
734
|
-
onDragStart:
|
|
735
|
-
}),
|
|
736
|
-
let n =
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
function
|
|
739
|
+
function Pe() {
|
|
740
|
+
if (!O) return;
|
|
741
|
+
let { selected: e } = E, t = E.hover === e ? null : E.hover;
|
|
742
|
+
if (!k && !e && !t) return;
|
|
743
|
+
k ??= fe({
|
|
744
|
+
onAction: Se,
|
|
745
|
+
onSelect: xe,
|
|
746
|
+
onDragStart: Oe
|
|
747
|
+
}), P && (P = !1, k.renderBar(e?.isConnected ? De(e) : null));
|
|
748
|
+
let n = ze(t ? T.get(t) : void 0);
|
|
749
|
+
k.hover.name.textContent !== n && (k.hover.name.textContent = n), Fe(k.selected, e), k.selected.label.style.visibility = e && T.get(e)?.isEditing?.() ? "hidden" : "", Fe(k.hover, t), Ie(k.indicator, F?.drop ?? null);
|
|
750
|
+
}
|
|
751
|
+
function Fe(e, t) {
|
|
740
752
|
if (!t?.isConnected) {
|
|
741
753
|
e.box.hidden = !0;
|
|
742
754
|
return;
|
|
743
755
|
}
|
|
744
756
|
let { box: n, label: r } = e, i = t.getBoundingClientRect(), a = r.offsetWidth, o = r.offsetHeight, s = document.documentElement.clientWidth;
|
|
745
|
-
n.hidden = !1, n.style.transform = `translate(${i.left -
|
|
746
|
-
let c = i.top <
|
|
757
|
+
n.hidden = !1, n.style.transform = `translate(${i.left - C}px, ${i.top - C}px)`, n.style.width = `${i.width + 4}px`, n.style.height = `${i.height + 4}px`;
|
|
758
|
+
let c = i.top < _e;
|
|
747
759
|
n.toggleAttribute("data-inside", c);
|
|
748
|
-
let l = Math.min(
|
|
760
|
+
let l = Math.min(C - i.top, i.height + 4 - o);
|
|
749
761
|
r.style.top = c ? `${Math.max(0, l)}px` : "";
|
|
750
|
-
let u = i.left -
|
|
762
|
+
let u = i.left - C + 8, d = u + a - s;
|
|
751
763
|
r.style.marginLeft = d > 0 ? `${-Math.min(d, u)}px` : "";
|
|
752
764
|
}
|
|
753
|
-
function
|
|
765
|
+
function Ie(e, t) {
|
|
754
766
|
if (!t?.el.isConnected) {
|
|
755
767
|
e.hidden = !0;
|
|
756
768
|
return;
|
|
757
769
|
}
|
|
758
770
|
let n = t.el.getBoundingClientRect(), r = t.position === "before", { style: i } = e;
|
|
759
|
-
if (e.hidden = !1, t.horizontal) i.transform = `translate(${(r ? n.left : n.right) -
|
|
771
|
+
if (e.hidden = !1, t.horizontal) i.transform = `translate(${(r ? n.left : n.right) - w / 2}px, ${n.top}px)`, i.width = `${w}px`, i.height = `${n.height}px`;
|
|
760
772
|
else {
|
|
761
773
|
let e = r ? n.top : n.bottom;
|
|
762
|
-
i.transform = `translate(${n.left}px, ${e -
|
|
774
|
+
i.transform = `translate(${n.left}px, ${e - w / 2}px)`, i.width = `${n.width}px`, i.height = `${w}px`;
|
|
763
775
|
}
|
|
764
776
|
}
|
|
765
|
-
function
|
|
777
|
+
function Le() {
|
|
766
778
|
return v.latest("BLOCK_LABELS") !== void 0;
|
|
767
779
|
}
|
|
768
|
-
function
|
|
780
|
+
function Re(e) {
|
|
769
781
|
return v.latest("HIDDEN_BLOCKS")?.ids.includes(e) ?? null;
|
|
770
782
|
}
|
|
771
|
-
function
|
|
783
|
+
function ze(e) {
|
|
772
784
|
let t = e?.label;
|
|
773
|
-
return t ? (e.kind === "block" ? v.latest("BLOCK_LABELS")?.labels[t] : void 0) ??
|
|
785
|
+
return t ? (e.kind === "block" ? v.latest("BLOCK_LABELS")?.labels[t] : void 0) ?? Be(t) : "";
|
|
774
786
|
}
|
|
775
|
-
function
|
|
787
|
+
function Be(e) {
|
|
776
788
|
if (!e) return "";
|
|
777
789
|
if (!/^[a-z][a-z0-9]*([_-][a-z0-9]+)*$/.test(e)) return e;
|
|
778
790
|
let t = e.replace(/[_-]+/g, " ");
|
|
@@ -780,26 +792,26 @@ function Le(e) {
|
|
|
780
792
|
}
|
|
781
793
|
//#endregion
|
|
782
794
|
//#region src/editable.ts
|
|
783
|
-
var
|
|
784
|
-
function
|
|
785
|
-
if (typeof document > "u" || document.getElementById(
|
|
795
|
+
var Ve = "b10cks-preview-style", He = "--b10cks-scroll-offset";
|
|
796
|
+
function Y() {
|
|
797
|
+
if (typeof document > "u" || document.getElementById(Ve)) return;
|
|
786
798
|
let e = document.createElement("style");
|
|
787
|
-
e.id =
|
|
788
|
-
.b10cks-preview { scroll-margin-top: var(${
|
|
799
|
+
e.id = Ve, e.textContent = `
|
|
800
|
+
.b10cks-preview { scroll-margin-top: var(${He}, 0px); }
|
|
789
801
|
.b10cks-preview.b10cks-hidden { opacity: 0.4 !important; }
|
|
790
802
|
`, document.head.appendChild(e);
|
|
791
803
|
}
|
|
792
|
-
function
|
|
804
|
+
function Ue(e) {
|
|
793
805
|
if (typeof document > "u") return;
|
|
794
806
|
let t = typeof e == "number" ? `${e}px` : e;
|
|
795
|
-
document.documentElement.style.setProperty(
|
|
807
|
+
document.documentElement.style.setProperty(He, t);
|
|
796
808
|
}
|
|
797
|
-
function
|
|
809
|
+
function We(e, t) {
|
|
798
810
|
if (!v.isInPreviewMode() || !t.id) return () => {};
|
|
799
|
-
|
|
811
|
+
Y();
|
|
800
812
|
let { id: n, label: r, onSelectChange: i, onHoverChange: a, scrollOnSelect: o = !0 } = t;
|
|
801
813
|
e.classList.add("b10cks-preview");
|
|
802
|
-
let s =
|
|
814
|
+
let s = I(e, {
|
|
803
815
|
id: n,
|
|
804
816
|
kind: "block",
|
|
805
817
|
label: r,
|
|
@@ -812,36 +824,38 @@ function Ve(e, t) {
|
|
|
812
824
|
s(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
813
825
|
};
|
|
814
826
|
}
|
|
815
|
-
function
|
|
827
|
+
function Ge(e, t) {
|
|
816
828
|
if (!v.isInPreviewMode() || !t.id) return () => {};
|
|
817
|
-
let { id: n, field: r, path: i,
|
|
818
|
-
if (a === "select") {
|
|
819
|
-
|
|
820
|
-
let t =
|
|
829
|
+
let { id: n, field: r, path: i, label: a } = t;
|
|
830
|
+
if ((t.mode ?? (r && !e.querySelector("a, button, input, select, textarea") ? "inline" : "select")) === "select") {
|
|
831
|
+
Y(), e.classList.add("b10cks-preview");
|
|
832
|
+
let t = i ?? (r ? [r] : void 0), o = I(e, {
|
|
821
833
|
id: n,
|
|
822
834
|
kind: "field",
|
|
823
|
-
label:
|
|
824
|
-
activate: () =>
|
|
835
|
+
label: a ?? Ke(i) ?? r,
|
|
836
|
+
activate: () => t ? v.selectField(n, t) : v.selectItem(n)
|
|
825
837
|
});
|
|
826
838
|
return () => {
|
|
827
|
-
|
|
839
|
+
o(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
828
840
|
};
|
|
829
841
|
}
|
|
830
842
|
e.setAttribute("contenteditable", "true");
|
|
831
|
-
let
|
|
843
|
+
let o = (t) => {
|
|
844
|
+
t.preventDefault(), t.stopPropagation(), e.focus();
|
|
845
|
+
}, s = (e) => {
|
|
832
846
|
let t = e.target.innerText;
|
|
833
847
|
i ? v.updateFieldAt(n, i, t) : v.updateField(n, r ?? "", t);
|
|
834
848
|
};
|
|
835
|
-
return e.addEventListener("input", s), () => {
|
|
836
|
-
e.removeEventListener("input", s), e.removeAttribute("contenteditable");
|
|
849
|
+
return e.addEventListener("input", s), e.addEventListener("click", o), () => {
|
|
850
|
+
e.removeEventListener("input", s), e.removeEventListener("click", o), e.removeAttribute("contenteditable");
|
|
837
851
|
};
|
|
838
852
|
}
|
|
839
|
-
function
|
|
853
|
+
function Ke(e) {
|
|
840
854
|
return e?.findLast((e) => typeof e == "string");
|
|
841
855
|
}
|
|
842
856
|
//#endregion
|
|
843
857
|
//#region src/preview-store.ts
|
|
844
|
-
function
|
|
858
|
+
function qe(e, t) {
|
|
845
859
|
let n = e;
|
|
846
860
|
for (let e of t) {
|
|
847
861
|
if (typeof n != "object" || !n) return;
|
|
@@ -849,18 +863,18 @@ function We(e, t) {
|
|
|
849
863
|
}
|
|
850
864
|
return n;
|
|
851
865
|
}
|
|
852
|
-
function
|
|
866
|
+
function X(e, t, n) {
|
|
853
867
|
if (t.length === 0) return n;
|
|
854
868
|
let [r, ...i] = t;
|
|
855
869
|
if (r === void 0) return n;
|
|
856
870
|
if (typeof r == "number") {
|
|
857
871
|
let t = Array.isArray(e) ? e.slice() : [];
|
|
858
|
-
return t[r] =
|
|
872
|
+
return t[r] = X(t[r], i, n), t;
|
|
859
873
|
}
|
|
860
874
|
let a = e && typeof e == "object" && !Array.isArray(e) ? { ...e } : {};
|
|
861
|
-
return a[r] =
|
|
875
|
+
return a[r] = X(a[r], i, n), a;
|
|
862
876
|
}
|
|
863
|
-
function
|
|
877
|
+
function Je(e, t) {
|
|
864
878
|
let n = (e, r) => {
|
|
865
879
|
if (Array.isArray(e)) {
|
|
866
880
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -883,16 +897,16 @@ function Q(e, t) {
|
|
|
883
897
|
};
|
|
884
898
|
return n(e, []);
|
|
885
899
|
}
|
|
886
|
-
function
|
|
900
|
+
function Ye(e, t) {
|
|
887
901
|
if (!t || typeof t != "object") return e;
|
|
888
902
|
let n = typeof t.id == "string" ? t.id : void 0;
|
|
889
903
|
if (!n || !e || typeof e != "object") return t;
|
|
890
904
|
let r = e, i = typeof r.id == "string" ? r.id : void 0;
|
|
891
905
|
if (i === n) return t;
|
|
892
|
-
let a =
|
|
893
|
-
return a ?
|
|
906
|
+
let a = Je(e, n);
|
|
907
|
+
return a ? X(e, a, t) : !i && r.block !== void 0 && r.block === t.block ? t : e;
|
|
894
908
|
}
|
|
895
|
-
var
|
|
909
|
+
var Xe = class {
|
|
896
910
|
content;
|
|
897
911
|
listeners = /* @__PURE__ */ new Set();
|
|
898
912
|
constructor(e) {
|
|
@@ -906,23 +920,23 @@ var Ke = class {
|
|
|
906
920
|
this.content = e, this.emit();
|
|
907
921
|
}
|
|
908
922
|
applyContentUpdate(e) {
|
|
909
|
-
let t =
|
|
923
|
+
let t = Ye(this.content, e);
|
|
910
924
|
t !== this.content && (this.content = t, this.emit());
|
|
911
925
|
}
|
|
912
926
|
patch(e, t, n) {
|
|
913
927
|
let r = [];
|
|
914
928
|
if (n && this.content?.id !== n) {
|
|
915
|
-
let e =
|
|
929
|
+
let e = Je(this.content, n);
|
|
916
930
|
if (!e) return;
|
|
917
931
|
r = e;
|
|
918
932
|
}
|
|
919
|
-
this.content =
|
|
933
|
+
this.content = X(this.content, [...r, ...e], t), this.emit();
|
|
920
934
|
}
|
|
921
935
|
emit() {
|
|
922
936
|
for (let e of this.listeners) e();
|
|
923
937
|
}
|
|
924
938
|
};
|
|
925
|
-
function
|
|
939
|
+
function Ze(e) {
|
|
926
940
|
let t = v.on("CONTENT_UPDATE", ({ content: t }) => {
|
|
927
941
|
e.applyContentUpdate(t);
|
|
928
942
|
}), n = v.on("CONTENT_PATCH", ({ itemId: t, path: n, value: r }) => {
|
|
@@ -933,18 +947,114 @@ function qe(e) {
|
|
|
933
947
|
};
|
|
934
948
|
}
|
|
935
949
|
//#endregion
|
|
950
|
+
//#region src/rich-text-field.ts
|
|
951
|
+
var Qe = 300, $e = 2e3, et = {
|
|
952
|
+
type: "doc",
|
|
953
|
+
content: []
|
|
954
|
+
}, tt = null;
|
|
955
|
+
function nt() {
|
|
956
|
+
return tt ??= import("@b10cks/richtext/editor").catch(() => (tt = null, null)), tt;
|
|
957
|
+
}
|
|
958
|
+
function rt(e, t) {
|
|
959
|
+
if (!v.isInPreviewMode() || !t.id) return {
|
|
960
|
+
update() {},
|
|
961
|
+
destroy() {}
|
|
962
|
+
};
|
|
963
|
+
Y();
|
|
964
|
+
let { id: n, path: r, render: i, onEditingChange: a } = t, o = t.document ?? et, s = null, c = 0, l = o, u = null, d, f = () => {
|
|
965
|
+
clearTimeout(d), d = void 0;
|
|
966
|
+
let e = u;
|
|
967
|
+
u = null, e && !Z(e, l) && (l = e, o = e, v.updateFieldAt(n, r, e), v.patchLocal({
|
|
968
|
+
itemId: n,
|
|
969
|
+
path: r,
|
|
970
|
+
value: e
|
|
971
|
+
}));
|
|
972
|
+
}, p = (e) => {
|
|
973
|
+
u = e, d ??= setTimeout(f, Qe);
|
|
974
|
+
}, m = () => {
|
|
975
|
+
c++, s && (f(), s.destroy(), s = null, a?.(!1));
|
|
976
|
+
}, h = async (t) => {
|
|
977
|
+
if (s) return;
|
|
978
|
+
let u = ++c, d = it(n, r);
|
|
979
|
+
v.selectField(n, r);
|
|
980
|
+
let [h, g] = await Promise.all([nt(), d]);
|
|
981
|
+
u === c && h && g && e.isConnected && (s = h.createRichTextEditor(e, {
|
|
982
|
+
document: o,
|
|
983
|
+
config: g,
|
|
984
|
+
render: i,
|
|
985
|
+
at: t && {
|
|
986
|
+
x: t.clientX,
|
|
987
|
+
y: t.clientY
|
|
988
|
+
},
|
|
989
|
+
onChange: p,
|
|
990
|
+
onBlur: f,
|
|
991
|
+
onExit: () => {
|
|
992
|
+
m(), xe(n);
|
|
993
|
+
}
|
|
994
|
+
}), s && (l = o, a?.(!0)));
|
|
995
|
+
};
|
|
996
|
+
e.classList.add("b10cks-preview");
|
|
997
|
+
let g = I(e, {
|
|
998
|
+
id: n,
|
|
999
|
+
kind: "field",
|
|
1000
|
+
label: t.label ?? r.findLast((e) => typeof e == "string"),
|
|
1001
|
+
activate: (e) => void h(e),
|
|
1002
|
+
isEditing: () => s !== null,
|
|
1003
|
+
onSelectChange: (e) => {
|
|
1004
|
+
e || m();
|
|
1005
|
+
},
|
|
1006
|
+
onHoverChange: (e) => {
|
|
1007
|
+
e && nt();
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
return {
|
|
1011
|
+
update(e) {
|
|
1012
|
+
let t = e ?? et;
|
|
1013
|
+
if (!s) {
|
|
1014
|
+
o = l = t;
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (!Z(t, l)) {
|
|
1018
|
+
if (!s.setDocument(t)) {
|
|
1019
|
+
m();
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
o = l = t, u &&= s.getDocument();
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
destroy() {
|
|
1026
|
+
m(), g(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
function it(e, t) {
|
|
1031
|
+
return new Promise((n) => {
|
|
1032
|
+
let r = (e) => {
|
|
1033
|
+
i(), clearTimeout(a), n(e);
|
|
1034
|
+
}, i = v.on("FIELD_CONFIG", (n) => {
|
|
1035
|
+
n.itemId === e && Z(n.path, t) && r(n.richtext);
|
|
1036
|
+
}), a = setTimeout(() => r(null), $e);
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
function Z(e, t) {
|
|
1040
|
+
if (e === t) return !0;
|
|
1041
|
+
if (typeof e != "object" || typeof t != "object" || e === null || t === null || Array.isArray(e) !== Array.isArray(t)) return !1;
|
|
1042
|
+
let n = Object.entries(e), r = { ...t };
|
|
1043
|
+
return n.length === Object.keys(r).length && n.every(([e, t]) => e in r && Z(t, r[e]));
|
|
1044
|
+
}
|
|
1045
|
+
//#endregion
|
|
936
1046
|
//#region src/sitemap.ts
|
|
937
|
-
function
|
|
1047
|
+
function at(e) {
|
|
938
1048
|
return (e ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
939
1049
|
}
|
|
940
|
-
function
|
|
941
|
-
let n =
|
|
1050
|
+
function ot(e, t) {
|
|
1051
|
+
let n = at(e), r = at(t);
|
|
942
1052
|
if (!r) return n && n !== "home" ? `/${n}` : "/";
|
|
943
1053
|
if (!n || n === "home") return `/${r}`;
|
|
944
1054
|
let i = `${r}/`;
|
|
945
1055
|
return n === r || n.startsWith(i) ? `/${n}` : `/${r}/${n}`;
|
|
946
1056
|
}
|
|
947
|
-
function
|
|
1057
|
+
function st(e, t) {
|
|
948
1058
|
if (!t) return null;
|
|
949
1059
|
try {
|
|
950
1060
|
return new URL(e, t).toString();
|
|
@@ -952,51 +1062,51 @@ function Xe(e, t) {
|
|
|
952
1062
|
return null;
|
|
953
1063
|
}
|
|
954
1064
|
}
|
|
955
|
-
function
|
|
1065
|
+
function Q(e) {
|
|
956
1066
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
957
1067
|
}
|
|
958
|
-
function
|
|
1068
|
+
function ct(e, t, n) {
|
|
959
1069
|
let { localePrefix: r = "auto", defaultLocale: i } = t;
|
|
960
|
-
return r === "always" || r === "auto" && n || r === "except-default" && e.language_iso !== i ?
|
|
1070
|
+
return r === "always" || r === "auto" && n || r === "except-default" && e.language_iso !== i ? ot(e.full_slug, e.language_iso) : ot(e.full_slug, null);
|
|
961
1071
|
}
|
|
962
|
-
function
|
|
1072
|
+
function lt(e) {
|
|
963
1073
|
let t = /* @__PURE__ */ new Set();
|
|
964
1074
|
for (let n of e) if (n.language_iso && t.add(n.language_iso), t.size > 1) return !0;
|
|
965
1075
|
return !1;
|
|
966
1076
|
}
|
|
967
|
-
function
|
|
968
|
-
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set(), a =
|
|
1077
|
+
function ut(e, t = {}) {
|
|
1078
|
+
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set(), a = lt(e);
|
|
969
1079
|
return e.filter((e) => {
|
|
970
1080
|
if (r && e.language_iso !== r) return !1;
|
|
971
1081
|
let o = e.meta?.robots?.toLowerCase();
|
|
972
1082
|
if (o?.includes("noindex") || o?.includes("none")) return !1;
|
|
973
|
-
let s =
|
|
1083
|
+
let s = ct(e, t, a), c = n ? st(s, n) ?? s : s;
|
|
974
1084
|
return !i.has(c) && (i.add(c), !0);
|
|
975
1085
|
});
|
|
976
1086
|
}
|
|
977
|
-
function
|
|
978
|
-
let r =
|
|
1087
|
+
function dt(e, t, n = {}) {
|
|
1088
|
+
let r = lt(e);
|
|
979
1089
|
return [
|
|
980
1090
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
981
1091
|
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
982
1092
|
e.map((e) => {
|
|
983
|
-
let i =
|
|
1093
|
+
let i = ct(e, n, r), a = t ? st(i, t) : i;
|
|
984
1094
|
if (!a) return "";
|
|
985
|
-
let o = [" <url>", ` <loc>${
|
|
986
|
-
return e.published_at && o.push(` <lastmod>${
|
|
1095
|
+
let o = [" <url>", ` <loc>${Q(a)}</loc>`];
|
|
1096
|
+
return e.published_at && o.push(` <lastmod>${Q(e.published_at)}</lastmod>`), o.push(" </url>"), o.join("\n");
|
|
987
1097
|
}).filter(Boolean).join("\n"),
|
|
988
1098
|
"</urlset>"
|
|
989
1099
|
].join("\n");
|
|
990
1100
|
}
|
|
991
|
-
function
|
|
1101
|
+
function ft(e, t) {
|
|
992
1102
|
return [
|
|
993
1103
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
994
1104
|
"<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
995
1105
|
e.map((e) => {
|
|
996
|
-
let n = t ?
|
|
1106
|
+
let n = t ? st(e, t) : e;
|
|
997
1107
|
return n ? [
|
|
998
1108
|
" <sitemap>",
|
|
999
|
-
` <loc>${
|
|
1109
|
+
` <loc>${Q(n)}</loc>`,
|
|
1000
1110
|
" </sitemap>"
|
|
1001
1111
|
].join("\n") : "";
|
|
1002
1112
|
}).filter(Boolean).join("\n"),
|
|
@@ -1005,14 +1115,14 @@ function nt(e, t) {
|
|
|
1005
1115
|
}
|
|
1006
1116
|
//#endregion
|
|
1007
1117
|
//#region src/types.ts
|
|
1008
|
-
var
|
|
1118
|
+
var pt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
1009
1119
|
status;
|
|
1010
1120
|
endpoint;
|
|
1011
1121
|
body;
|
|
1012
1122
|
constructor(e, t, n, r) {
|
|
1013
1123
|
super(e), this.status = t, this.endpoint = n, this.body = r, this.name = "ApiError";
|
|
1014
1124
|
}
|
|
1015
|
-
},
|
|
1125
|
+
}, mt = (e) => e === 429 || e >= 500 && e <= 599, ht = (e) => new Promise((t) => setTimeout(t, e)), gt = class {
|
|
1016
1126
|
baseUrl;
|
|
1017
1127
|
token;
|
|
1018
1128
|
vid;
|
|
@@ -1075,8 +1185,8 @@ var rt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
|
1075
1185
|
let n = await this.fetchWithTimeout(e);
|
|
1076
1186
|
return await this.parseResponse(n, t);
|
|
1077
1187
|
} catch (e) {
|
|
1078
|
-
if (n = e, !(r < this.retries && (!(e instanceof $) || e.status === 0 ||
|
|
1079
|
-
await
|
|
1188
|
+
if (n = e, !(r < this.retries && (!(e instanceof $) || e.status === 0 || mt(e.status)))) throw e;
|
|
1189
|
+
await ht(200 * 2 ** r);
|
|
1080
1190
|
}
|
|
1081
1191
|
throw n;
|
|
1082
1192
|
}
|
|
@@ -1178,6 +1288,6 @@ var rt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
|
1178
1288
|
}
|
|
1179
1289
|
};
|
|
1180
1290
|
//#endregion
|
|
1181
|
-
export {
|
|
1291
|
+
export { gt as ApiClient, $ as ApiError, d as B10cksDataApi, re as BRIDGE_PROTOCOL, ie as PreviewBridge, Xe as PreviewStore, We as attachEditable, Ge as attachEditableField, rt as attachRichTextField, Ze as bindPreviewStore, o as blockAnchorAttrs, r as breadcrumbJsonLd, ot as buildLocalizedPath, f as createB10cksDataApi, Y as ensurePreviewStyles, ut as filterSitemapEntries, Je as findPathById, qe as getAtPath, Ye as mergeContentUpdate, at as normalizePathSegment, v as previewBridge, ft as renderSitemapIndex, dt as renderSitemapXml, a as resolveB10cksLink, c as serializeFilter, X as setAtPath, Ue as setPreviewScrollOffset, i as toRootBlock, pt as types };
|
|
1182
1292
|
|
|
1183
1293
|
//# sourceMappingURL=index.mjs.map
|