@b10cks/client 1.12.0 → 2.0.0
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 +28 -0
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +148 -4
- package/dist/index.mjs +315 -207
- 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)), u.appendChild(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,7 +473,7 @@ 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
478
|
h(!1), u.insertBefore(m, f.get("delete") ?? null), s.append(c, l, u), o.appendChild(s);
|
|
467
479
|
let g = b("div", "indicator");
|
|
@@ -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, 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) {
|
|
@@ -520,168 +532,168 @@ function x(e) {
|
|
|
520
532
|
}
|
|
521
533
|
//#endregion
|
|
522
534
|
//#region src/preview-overlay.ts
|
|
523
|
-
var
|
|
535
|
+
var ge = {
|
|
524
536
|
selected: "b10cks-selected",
|
|
525
537
|
hover: "b10cks-hover"
|
|
526
|
-
},
|
|
538
|
+
}, _e = "b10cks-hidden", S = 2, ve = 24, C = 3, w = /* @__PURE__ */ new Map(), T = {
|
|
527
539
|
selected: null,
|
|
528
540
|
hover: null
|
|
529
|
-
},
|
|
530
|
-
function
|
|
531
|
-
return
|
|
532
|
-
if (
|
|
533
|
-
|
|
534
|
-
for (let t of ["selected", "hover"])
|
|
535
|
-
|
|
541
|
+
}, E = null, D = null, O = null, k = null, A = null, j = !1, M = !1, N = !1, P = null;
|
|
542
|
+
function F(e, t) {
|
|
543
|
+
return w.set(e, t), t.kind === "block" && e.classList.toggle(_e, ze(t.id) === !0), D ||= ye(), t.kind === "block" && t.id === E && W(), () => {
|
|
544
|
+
if (w.get(e) === t) {
|
|
545
|
+
w.delete(e), t.kind === "block" && e.classList.remove(_e);
|
|
546
|
+
for (let t of ["selected", "hover"]) T[t] === e && (T[t] = null, e.classList.remove(ge[t]));
|
|
547
|
+
w.size === 0 ? (D?.(), D = null) : W();
|
|
536
548
|
}
|
|
537
549
|
};
|
|
538
550
|
}
|
|
539
|
-
function
|
|
540
|
-
|
|
551
|
+
function ye() {
|
|
552
|
+
E = v.latest("SELECT_UPDATE")?.selectedItem ?? E, E && W();
|
|
541
553
|
let e = v.on("SELECT_UPDATE", ({ selectedItem: e }) => {
|
|
542
|
-
|
|
543
|
-
let t =
|
|
544
|
-
(t?.kind !== "field" || e && e !== t.id) &&
|
|
554
|
+
E = e || null;
|
|
555
|
+
let t = T.selected && w.get(T.selected);
|
|
556
|
+
(t?.kind !== "field" || e && e !== t.id) && G("selected", z(E));
|
|
545
557
|
}), t = v.on("HOVER_UPDATE", ({ selectedItem: e }) => {
|
|
546
|
-
|
|
547
|
-
}), n = v.on("BLOCK_LABELS",
|
|
558
|
+
G("hover", z(e || null));
|
|
559
|
+
}), n = v.on("BLOCK_LABELS", K), r = v.on("HIDDEN_BLOCKS", ({ ids: e }) => {
|
|
548
560
|
let t = new Set(e);
|
|
549
|
-
for (let [e, n] of
|
|
550
|
-
|
|
561
|
+
for (let [e, n] of w) n.kind === "block" && e.classList.toggle(_e, t.has(n.id));
|
|
562
|
+
K();
|
|
551
563
|
}), i = {
|
|
552
564
|
capture: !0,
|
|
553
565
|
passive: !0
|
|
554
566
|
};
|
|
555
|
-
return window.addEventListener("click",
|
|
556
|
-
|
|
567
|
+
return window.addEventListener("click", I, !0), window.addEventListener("auxclick", I, !0), window.addEventListener("keydown", be, !0), document.addEventListener("pointerover", we, !0), document.addEventListener("pointerout", Te, !0), window.addEventListener("scroll", q, i), window.addEventListener("resize", q), k = typeof ResizeObserver > "u" ? null : new ResizeObserver(q), A = typeof MutationObserver > "u" ? null : new MutationObserver(K), () => {
|
|
568
|
+
U(), e(), t(), n(), r(), window.removeEventListener("click", I, !0), window.removeEventListener("auxclick", I, !0), window.removeEventListener("keydown", be, !0), document.removeEventListener("pointerover", we, !0), document.removeEventListener("pointerout", Te, !0), window.removeEventListener("scroll", q, i), window.removeEventListener("resize", q), k?.disconnect(), k = null, A?.disconnect(), A = null, T.selected = null, T.hover = null, O?.host.remove(), O = null;
|
|
557
569
|
};
|
|
558
570
|
}
|
|
559
|
-
function
|
|
571
|
+
function I(e) {
|
|
560
572
|
if (e.altKey) return;
|
|
561
|
-
let t =
|
|
562
|
-
t && (
|
|
573
|
+
let t = Ee(e);
|
|
574
|
+
t && !w.get(t)?.isEditing?.() && (L(e), e.type === "click" && R(t, e));
|
|
563
575
|
}
|
|
564
|
-
function
|
|
565
|
-
if (
|
|
566
|
-
e.key === "Escape" && (
|
|
576
|
+
function be(e) {
|
|
577
|
+
if (P) {
|
|
578
|
+
e.key === "Escape" && (L(e), U());
|
|
567
579
|
return;
|
|
568
580
|
}
|
|
569
|
-
let t =
|
|
570
|
-
if (!t?.isConnected || e.defaultPrevented ||
|
|
581
|
+
let t = T.selected;
|
|
582
|
+
if (!t?.isConnected || e.defaultPrevented || xe(e) || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
571
583
|
let n = null;
|
|
572
|
-
e.key === "Escape" ? n =
|
|
584
|
+
e.key === "Escape" ? n = V(t)[0] ?? null : e.key === "ArrowUp" ? n = H(t, -1) : e.key === "ArrowDown" && (n = H(t, 1)), n && (L(e), R(n));
|
|
573
585
|
}
|
|
574
|
-
function
|
|
586
|
+
function xe(e) {
|
|
575
587
|
let t = e.composedPath()[0];
|
|
576
588
|
return t instanceof HTMLElement && (t.isContentEditable || t.matches("input, textarea, select"));
|
|
577
589
|
}
|
|
578
|
-
function
|
|
590
|
+
function L(e) {
|
|
579
591
|
e.preventDefault(), e.stopImmediatePropagation();
|
|
580
592
|
}
|
|
581
|
-
function
|
|
582
|
-
let n =
|
|
583
|
-
n && (n.activate(t), n.kind === "block" && (
|
|
593
|
+
function R(e, t) {
|
|
594
|
+
let n = w.get(e);
|
|
595
|
+
n && (n.activate(t), n.kind === "block" && (E = n.id), G("selected", e));
|
|
584
596
|
}
|
|
585
|
-
function
|
|
586
|
-
let t =
|
|
587
|
-
t &&
|
|
597
|
+
function Se(e) {
|
|
598
|
+
let t = z(e);
|
|
599
|
+
t && R(t);
|
|
588
600
|
}
|
|
589
|
-
function
|
|
590
|
-
let t =
|
|
601
|
+
function Ce(e) {
|
|
602
|
+
let t = T.selected && w.get(T.selected);
|
|
591
603
|
t?.kind === "block" && v.blockAction(t.id, e);
|
|
592
604
|
}
|
|
593
|
-
function
|
|
594
|
-
|
|
605
|
+
function we(e) {
|
|
606
|
+
G("hover", Ee(e));
|
|
595
607
|
}
|
|
596
|
-
function
|
|
597
|
-
e.relatedTarget ||
|
|
608
|
+
function Te(e) {
|
|
609
|
+
e.relatedTarget || G("hover", null);
|
|
598
610
|
}
|
|
599
|
-
function
|
|
600
|
-
for (let t of e.composedPath()) if (t instanceof HTMLElement &&
|
|
611
|
+
function Ee(e) {
|
|
612
|
+
for (let t of e.composedPath()) if (t instanceof HTMLElement && w.has(t)) return t;
|
|
601
613
|
return null;
|
|
602
614
|
}
|
|
603
|
-
function
|
|
615
|
+
function z(e) {
|
|
604
616
|
if (!e) return null;
|
|
605
617
|
let t = null;
|
|
606
|
-
for (let [n, r] of
|
|
618
|
+
for (let [n, r] of w) r.kind === "block" && r.id === e && n.isConnected && (!t || t.contains(n)) && (t = n);
|
|
607
619
|
return t;
|
|
608
620
|
}
|
|
609
|
-
function
|
|
621
|
+
function B(e) {
|
|
610
622
|
if (e.parentElement) return e.parentElement;
|
|
611
623
|
let t = e.parentNode;
|
|
612
624
|
return t instanceof ShadowRoot ? t.host : null;
|
|
613
625
|
}
|
|
614
|
-
function
|
|
615
|
-
let t = [], n =
|
|
616
|
-
for (let n =
|
|
626
|
+
function V(e) {
|
|
627
|
+
let t = [], n = w.get(e), r = n?.kind === "block" ? n.id : null;
|
|
628
|
+
for (let n = B(e); n; n = B(n)) {
|
|
617
629
|
if (!(n instanceof HTMLElement)) continue;
|
|
618
|
-
let e =
|
|
630
|
+
let e = w.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
|
|
624
|
-
let t =
|
|
625
|
-
return (t &&
|
|
635
|
+
function De(e) {
|
|
636
|
+
let t = V(e)[0];
|
|
637
|
+
return (t && w.get(t)?.id) ?? null;
|
|
626
638
|
}
|
|
627
|
-
function
|
|
628
|
-
let n =
|
|
639
|
+
function H(e, t) {
|
|
640
|
+
let n = w.get(e);
|
|
629
641
|
if (n?.kind !== "block") return null;
|
|
630
|
-
let r =
|
|
631
|
-
for (let [t, o] of
|
|
632
|
-
return a &&
|
|
642
|
+
let r = De(e), i = t === 1 ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING, a = null;
|
|
643
|
+
for (let [t, o] of w) o.kind === "block" && o.id !== n.id && t.isConnected && e.compareDocumentPosition(t) & i && (!a || t.compareDocumentPosition(a) & i) && De(t) === r && (a = t);
|
|
644
|
+
return a && z(w.get(a)?.id ?? null);
|
|
633
645
|
}
|
|
634
|
-
function
|
|
635
|
-
let t =
|
|
646
|
+
function Oe(e) {
|
|
647
|
+
let t = w.get(e);
|
|
636
648
|
if (!t) return null;
|
|
637
|
-
let n =
|
|
638
|
-
let t =
|
|
649
|
+
let n = V(e).reverse().flatMap((e) => {
|
|
650
|
+
let t = w.get(e);
|
|
639
651
|
return t ? [{
|
|
640
652
|
id: t.id,
|
|
641
|
-
label:
|
|
653
|
+
label: J(t) || "Block"
|
|
642
654
|
}] : [];
|
|
643
655
|
});
|
|
644
656
|
return {
|
|
645
|
-
label:
|
|
657
|
+
label: J(t),
|
|
646
658
|
crumbs: n,
|
|
647
|
-
actions: t.kind === "block" &&
|
|
648
|
-
canMoveUp: !!
|
|
649
|
-
canMoveDown: !!
|
|
650
|
-
hidden:
|
|
659
|
+
actions: t.kind === "block" && Re() ? {
|
|
660
|
+
canMoveUp: !!H(e, -1),
|
|
661
|
+
canMoveDown: !!H(e, 1),
|
|
662
|
+
hidden: ze(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 ke(e, t) {
|
|
667
|
+
let n = T.selected, r = n && w.get(n);
|
|
668
|
+
n && r?.kind === "block" && e.button === 0 && (e.preventDefault(), e.isTrusted && t.setPointerCapture(e.pointerId), P = {
|
|
657
669
|
id: r.id,
|
|
658
670
|
el: n,
|
|
659
671
|
drop: null
|
|
660
|
-
},
|
|
672
|
+
}, O?.setDragging(!0), window.addEventListener("pointermove", Ae, !0), window.addEventListener("pointerup", je, !0), window.addEventListener("pointercancel", U, !0));
|
|
661
673
|
}
|
|
662
|
-
function
|
|
663
|
-
|
|
674
|
+
function Ae(e) {
|
|
675
|
+
P && (P.drop = Me(P, e.clientX, e.clientY), G("hover", P.drop?.el ?? null), q());
|
|
664
676
|
}
|
|
665
|
-
function
|
|
666
|
-
let t =
|
|
667
|
-
|
|
677
|
+
function je(e) {
|
|
678
|
+
let t = P, n = t && Me(t, e.clientX, e.clientY);
|
|
679
|
+
U(), t && n && v.moveBlock(t.id, n.id, n.position);
|
|
668
680
|
}
|
|
669
|
-
function
|
|
670
|
-
|
|
681
|
+
function U() {
|
|
682
|
+
P && (P = null, window.removeEventListener("pointermove", Ae, !0), window.removeEventListener("pointerup", je, !0), window.removeEventListener("pointercancel", U, !0), O?.setDragging(!1), G("hover", null), q());
|
|
671
683
|
}
|
|
672
|
-
function
|
|
673
|
-
let r = document.elementsFromPoint(t, n).find((e) => e !==
|
|
674
|
-
for (let t = r ?? null; t; t =
|
|
684
|
+
function Me(e, t, n) {
|
|
685
|
+
let r = document.elementsFromPoint(t, n).find((e) => e !== O?.host), i = null;
|
|
686
|
+
for (let t = r ?? null; t; t = B(t)) {
|
|
675
687
|
if (!(t instanceof HTMLElement)) continue;
|
|
676
|
-
let n =
|
|
688
|
+
let n = w.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 && w.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 : Ne(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
|
|
693
|
-
let n =
|
|
704
|
+
function Ne(e, t) {
|
|
705
|
+
let n = H(e, 1) ?? H(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
|
-
function
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
let e =
|
|
702
|
-
e?.isConnected &&
|
|
710
|
+
function W() {
|
|
711
|
+
M || (M = !0, queueMicrotask(() => {
|
|
712
|
+
M = !1;
|
|
713
|
+
let e = T.selected;
|
|
714
|
+
e?.isConnected && w.get(e)?.kind === "field" || G("selected", z(E));
|
|
703
715
|
}));
|
|
704
716
|
}
|
|
705
|
-
function
|
|
706
|
-
let n =
|
|
707
|
-
n !== t && (
|
|
717
|
+
function G(e, t) {
|
|
718
|
+
let n = T[e];
|
|
719
|
+
n !== t && (T[e] = t, n && (n.classList.remove(ge[e]), Pe(n, e, !1)), t && (t.classList.add(ge[e]), Pe(t, e, !0), e === "selected" && w.get(t)?.scrollOnSelect && t.scrollIntoView?.({
|
|
708
720
|
block: "nearest",
|
|
709
721
|
behavior: "smooth"
|
|
710
|
-
})),
|
|
722
|
+
})), k && (k.disconnect(), k.observe(document.documentElement), T.selected && k.observe(T.selected), T.hover && k.observe(T.hover)), e === "selected" && (A?.disconnect(), t && A?.observe(document.body, {
|
|
711
723
|
childList: !0,
|
|
712
724
|
subtree: !0
|
|
713
|
-
}),
|
|
725
|
+
}), N = !0), q());
|
|
714
726
|
}
|
|
715
|
-
function
|
|
716
|
-
let r =
|
|
727
|
+
function Pe(e, t, n) {
|
|
728
|
+
let r = w.get(e);
|
|
717
729
|
t === "selected" ? r?.onSelectChange?.(n) : r?.onHoverChange?.(n);
|
|
718
730
|
}
|
|
719
|
-
function
|
|
720
|
-
|
|
731
|
+
function K() {
|
|
732
|
+
N = !0, q();
|
|
721
733
|
}
|
|
722
|
-
function
|
|
723
|
-
|
|
724
|
-
|
|
734
|
+
function q() {
|
|
735
|
+
j || (j = !0, requestAnimationFrame(() => {
|
|
736
|
+
j = !1, Fe();
|
|
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 Fe() {
|
|
740
|
+
if (!D) return;
|
|
741
|
+
let { selected: e } = T, t = T.hover === e ? null : T.hover;
|
|
742
|
+
if (!O && !e && !t) return;
|
|
743
|
+
O ??= fe({
|
|
744
|
+
onAction: Ce,
|
|
745
|
+
onSelect: Se,
|
|
746
|
+
onDragStart: ke
|
|
747
|
+
}), N && (N = !1, O.renderBar(e?.isConnected ? Oe(e) : null));
|
|
748
|
+
let n = J(t ? w.get(t) : void 0);
|
|
749
|
+
O.hover.name.textContent !== n && (O.hover.name.textContent = n), Ie(O.selected, e), O.selected.label.style.visibility = e && w.get(e)?.isEditing?.() ? "hidden" : "", Ie(O.hover, t), Le(O.indicator, P?.drop ?? null);
|
|
750
|
+
}
|
|
751
|
+
function Ie(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 - S}px, ${i.top - S}px)`, n.style.width = `${i.width + 4}px`, n.style.height = `${i.height + 4}px`;
|
|
758
|
+
let c = i.top < ve;
|
|
747
759
|
n.toggleAttribute("data-inside", c);
|
|
748
|
-
let l = Math.min(
|
|
760
|
+
let l = Math.min(S - 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 - S + 8, d = u + a - s;
|
|
751
763
|
r.style.marginLeft = d > 0 ? `${-Math.min(d, u)}px` : "";
|
|
752
764
|
}
|
|
753
|
-
function
|
|
765
|
+
function Le(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) - C / 2}px, ${n.top}px)`, i.width = `${C}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 - C / 2}px)`, i.width = `${n.width}px`, i.height = `${C}px`;
|
|
763
775
|
}
|
|
764
776
|
}
|
|
765
|
-
function
|
|
777
|
+
function Re() {
|
|
766
778
|
return v.latest("BLOCK_LABELS") !== void 0;
|
|
767
779
|
}
|
|
768
|
-
function
|
|
780
|
+
function ze(e) {
|
|
769
781
|
return v.latest("HIDDEN_BLOCKS")?.ids.includes(e) ?? null;
|
|
770
782
|
}
|
|
771
|
-
function
|
|
783
|
+
function J(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 = F(e, {
|
|
803
815
|
id: n,
|
|
804
816
|
kind: "block",
|
|
805
817
|
label: r,
|
|
@@ -812,15 +824,15 @@ 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
829
|
let { id: n, field: r, path: i, mode: a = "inline", label: o } = t;
|
|
818
830
|
if (a === "select") {
|
|
819
|
-
|
|
820
|
-
let t =
|
|
831
|
+
Y(), e.classList.add("b10cks-preview");
|
|
832
|
+
let t = F(e, {
|
|
821
833
|
id: n,
|
|
822
834
|
kind: "field",
|
|
823
|
-
label: o ??
|
|
835
|
+
label: o ?? Ke(i) ?? r,
|
|
824
836
|
activate: () => i ? v.selectField(n, i) : v.selectItem(n)
|
|
825
837
|
});
|
|
826
838
|
return () => {
|
|
@@ -836,12 +848,12 @@ function He(e, t) {
|
|
|
836
848
|
e.removeEventListener("input", s), e.removeAttribute("contenteditable");
|
|
837
849
|
};
|
|
838
850
|
}
|
|
839
|
-
function
|
|
851
|
+
function Ke(e) {
|
|
840
852
|
return e?.findLast((e) => typeof e == "string");
|
|
841
853
|
}
|
|
842
854
|
//#endregion
|
|
843
855
|
//#region src/preview-store.ts
|
|
844
|
-
function
|
|
856
|
+
function qe(e, t) {
|
|
845
857
|
let n = e;
|
|
846
858
|
for (let e of t) {
|
|
847
859
|
if (typeof n != "object" || !n) return;
|
|
@@ -849,18 +861,18 @@ function We(e, t) {
|
|
|
849
861
|
}
|
|
850
862
|
return n;
|
|
851
863
|
}
|
|
852
|
-
function
|
|
864
|
+
function X(e, t, n) {
|
|
853
865
|
if (t.length === 0) return n;
|
|
854
866
|
let [r, ...i] = t;
|
|
855
867
|
if (r === void 0) return n;
|
|
856
868
|
if (typeof r == "number") {
|
|
857
869
|
let t = Array.isArray(e) ? e.slice() : [];
|
|
858
|
-
return t[r] =
|
|
870
|
+
return t[r] = X(t[r], i, n), t;
|
|
859
871
|
}
|
|
860
872
|
let a = e && typeof e == "object" && !Array.isArray(e) ? { ...e } : {};
|
|
861
|
-
return a[r] =
|
|
873
|
+
return a[r] = X(a[r], i, n), a;
|
|
862
874
|
}
|
|
863
|
-
function
|
|
875
|
+
function Je(e, t) {
|
|
864
876
|
let n = (e, r) => {
|
|
865
877
|
if (Array.isArray(e)) {
|
|
866
878
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -883,16 +895,16 @@ function Q(e, t) {
|
|
|
883
895
|
};
|
|
884
896
|
return n(e, []);
|
|
885
897
|
}
|
|
886
|
-
function
|
|
898
|
+
function Ye(e, t) {
|
|
887
899
|
if (!t || typeof t != "object") return e;
|
|
888
900
|
let n = typeof t.id == "string" ? t.id : void 0;
|
|
889
901
|
if (!n || !e || typeof e != "object") return t;
|
|
890
902
|
let r = e, i = typeof r.id == "string" ? r.id : void 0;
|
|
891
903
|
if (i === n) return t;
|
|
892
|
-
let a =
|
|
893
|
-
return a ?
|
|
904
|
+
let a = Je(e, n);
|
|
905
|
+
return a ? X(e, a, t) : !i && r.block !== void 0 && r.block === t.block ? t : e;
|
|
894
906
|
}
|
|
895
|
-
var
|
|
907
|
+
var Xe = class {
|
|
896
908
|
content;
|
|
897
909
|
listeners = /* @__PURE__ */ new Set();
|
|
898
910
|
constructor(e) {
|
|
@@ -906,23 +918,23 @@ var Ke = class {
|
|
|
906
918
|
this.content = e, this.emit();
|
|
907
919
|
}
|
|
908
920
|
applyContentUpdate(e) {
|
|
909
|
-
let t =
|
|
921
|
+
let t = Ye(this.content, e);
|
|
910
922
|
t !== this.content && (this.content = t, this.emit());
|
|
911
923
|
}
|
|
912
924
|
patch(e, t, n) {
|
|
913
925
|
let r = [];
|
|
914
926
|
if (n && this.content?.id !== n) {
|
|
915
|
-
let e =
|
|
927
|
+
let e = Je(this.content, n);
|
|
916
928
|
if (!e) return;
|
|
917
929
|
r = e;
|
|
918
930
|
}
|
|
919
|
-
this.content =
|
|
931
|
+
this.content = X(this.content, [...r, ...e], t), this.emit();
|
|
920
932
|
}
|
|
921
933
|
emit() {
|
|
922
934
|
for (let e of this.listeners) e();
|
|
923
935
|
}
|
|
924
936
|
};
|
|
925
|
-
function
|
|
937
|
+
function Ze(e) {
|
|
926
938
|
let t = v.on("CONTENT_UPDATE", ({ content: t }) => {
|
|
927
939
|
e.applyContentUpdate(t);
|
|
928
940
|
}), n = v.on("CONTENT_PATCH", ({ itemId: t, path: n, value: r }) => {
|
|
@@ -933,18 +945,114 @@ function qe(e) {
|
|
|
933
945
|
};
|
|
934
946
|
}
|
|
935
947
|
//#endregion
|
|
948
|
+
//#region src/rich-text-field.ts
|
|
949
|
+
var Qe = 300, $e = 2e3, et = {
|
|
950
|
+
type: "doc",
|
|
951
|
+
content: []
|
|
952
|
+
}, tt = null;
|
|
953
|
+
function nt() {
|
|
954
|
+
return tt ??= import("@b10cks/richtext/editor").catch(() => (tt = null, null)), tt;
|
|
955
|
+
}
|
|
956
|
+
function rt(e, t) {
|
|
957
|
+
if (!v.isInPreviewMode() || !t.id) return {
|
|
958
|
+
update() {},
|
|
959
|
+
destroy() {}
|
|
960
|
+
};
|
|
961
|
+
Y();
|
|
962
|
+
let { id: n, path: r, render: i, onEditingChange: a } = t, o = t.document ?? et, s = null, c = 0, l = o, u = null, d, f = () => {
|
|
963
|
+
clearTimeout(d), d = void 0;
|
|
964
|
+
let e = u;
|
|
965
|
+
u = null, e && !Z(e, l) && (l = e, o = e, v.updateFieldAt(n, r, e), v.patchLocal({
|
|
966
|
+
itemId: n,
|
|
967
|
+
path: r,
|
|
968
|
+
value: e
|
|
969
|
+
}));
|
|
970
|
+
}, p = (e) => {
|
|
971
|
+
u = e, d ??= setTimeout(f, Qe);
|
|
972
|
+
}, m = () => {
|
|
973
|
+
c++, s && (f(), s.destroy(), s = null, a?.(!1));
|
|
974
|
+
}, h = async (t) => {
|
|
975
|
+
if (s) return;
|
|
976
|
+
let u = ++c, d = it(n, r);
|
|
977
|
+
v.selectField(n, r);
|
|
978
|
+
let [h, g] = await Promise.all([nt(), d]);
|
|
979
|
+
u === c && h && g && e.isConnected && (s = h.createRichTextEditor(e, {
|
|
980
|
+
document: o,
|
|
981
|
+
config: g,
|
|
982
|
+
render: i,
|
|
983
|
+
at: t && {
|
|
984
|
+
x: t.clientX,
|
|
985
|
+
y: t.clientY
|
|
986
|
+
},
|
|
987
|
+
onChange: p,
|
|
988
|
+
onBlur: f,
|
|
989
|
+
onExit: () => {
|
|
990
|
+
m(), Se(n);
|
|
991
|
+
}
|
|
992
|
+
}), s && (l = o, a?.(!0)));
|
|
993
|
+
};
|
|
994
|
+
e.classList.add("b10cks-preview");
|
|
995
|
+
let g = F(e, {
|
|
996
|
+
id: n,
|
|
997
|
+
kind: "field",
|
|
998
|
+
label: t.label ?? r.findLast((e) => typeof e == "string"),
|
|
999
|
+
activate: (e) => void h(e),
|
|
1000
|
+
isEditing: () => s !== null,
|
|
1001
|
+
onSelectChange: (e) => {
|
|
1002
|
+
e || m();
|
|
1003
|
+
},
|
|
1004
|
+
onHoverChange: (e) => {
|
|
1005
|
+
e && nt();
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
return {
|
|
1009
|
+
update(e) {
|
|
1010
|
+
let t = e ?? et;
|
|
1011
|
+
if (!s) {
|
|
1012
|
+
o = l = t;
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
if (!Z(t, l)) {
|
|
1016
|
+
if (!s.setDocument(t)) {
|
|
1017
|
+
m();
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
o = l = t, u &&= s.getDocument();
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
destroy() {
|
|
1024
|
+
m(), g(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
function it(e, t) {
|
|
1029
|
+
return new Promise((n) => {
|
|
1030
|
+
let r = (e) => {
|
|
1031
|
+
i(), clearTimeout(a), n(e);
|
|
1032
|
+
}, i = v.on("FIELD_CONFIG", (n) => {
|
|
1033
|
+
n.itemId === e && Z(n.path, t) && r(n.richtext);
|
|
1034
|
+
}), a = setTimeout(() => r(null), $e);
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
function Z(e, t) {
|
|
1038
|
+
if (e === t) return !0;
|
|
1039
|
+
if (typeof e != "object" || typeof t != "object" || e === null || t === null || Array.isArray(e) !== Array.isArray(t)) return !1;
|
|
1040
|
+
let n = Object.entries(e), r = { ...t };
|
|
1041
|
+
return n.length === Object.keys(r).length && n.every(([e, t]) => e in r && Z(t, r[e]));
|
|
1042
|
+
}
|
|
1043
|
+
//#endregion
|
|
936
1044
|
//#region src/sitemap.ts
|
|
937
|
-
function
|
|
1045
|
+
function at(e) {
|
|
938
1046
|
return (e ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
939
1047
|
}
|
|
940
|
-
function
|
|
941
|
-
let n =
|
|
1048
|
+
function ot(e, t) {
|
|
1049
|
+
let n = at(e), r = at(t);
|
|
942
1050
|
if (!r) return n && n !== "home" ? `/${n}` : "/";
|
|
943
1051
|
if (!n || n === "home") return `/${r}`;
|
|
944
1052
|
let i = `${r}/`;
|
|
945
1053
|
return n === r || n.startsWith(i) ? `/${n}` : `/${r}/${n}`;
|
|
946
1054
|
}
|
|
947
|
-
function
|
|
1055
|
+
function st(e, t) {
|
|
948
1056
|
if (!t) return null;
|
|
949
1057
|
try {
|
|
950
1058
|
return new URL(e, t).toString();
|
|
@@ -952,51 +1060,51 @@ function Xe(e, t) {
|
|
|
952
1060
|
return null;
|
|
953
1061
|
}
|
|
954
1062
|
}
|
|
955
|
-
function
|
|
1063
|
+
function Q(e) {
|
|
956
1064
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
957
1065
|
}
|
|
958
|
-
function
|
|
1066
|
+
function ct(e, t, n) {
|
|
959
1067
|
let { localePrefix: r = "auto", defaultLocale: i } = t;
|
|
960
|
-
return r === "always" || r === "auto" && n || r === "except-default" && e.language_iso !== i ?
|
|
1068
|
+
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
1069
|
}
|
|
962
|
-
function
|
|
1070
|
+
function lt(e) {
|
|
963
1071
|
let t = /* @__PURE__ */ new Set();
|
|
964
1072
|
for (let n of e) if (n.language_iso && t.add(n.language_iso), t.size > 1) return !0;
|
|
965
1073
|
return !1;
|
|
966
1074
|
}
|
|
967
|
-
function
|
|
968
|
-
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set(), a =
|
|
1075
|
+
function ut(e, t = {}) {
|
|
1076
|
+
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set(), a = lt(e);
|
|
969
1077
|
return e.filter((e) => {
|
|
970
1078
|
if (r && e.language_iso !== r) return !1;
|
|
971
1079
|
let o = e.meta?.robots?.toLowerCase();
|
|
972
1080
|
if (o?.includes("noindex") || o?.includes("none")) return !1;
|
|
973
|
-
let s =
|
|
1081
|
+
let s = ct(e, t, a), c = n ? st(s, n) ?? s : s;
|
|
974
1082
|
return !i.has(c) && (i.add(c), !0);
|
|
975
1083
|
});
|
|
976
1084
|
}
|
|
977
|
-
function
|
|
978
|
-
let r =
|
|
1085
|
+
function dt(e, t, n = {}) {
|
|
1086
|
+
let r = lt(e);
|
|
979
1087
|
return [
|
|
980
1088
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
981
1089
|
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
982
1090
|
e.map((e) => {
|
|
983
|
-
let i =
|
|
1091
|
+
let i = ct(e, n, r), a = t ? st(i, t) : i;
|
|
984
1092
|
if (!a) return "";
|
|
985
|
-
let o = [" <url>", ` <loc>${
|
|
986
|
-
return e.published_at && o.push(` <lastmod>${
|
|
1093
|
+
let o = [" <url>", ` <loc>${Q(a)}</loc>`];
|
|
1094
|
+
return e.published_at && o.push(` <lastmod>${Q(e.published_at)}</lastmod>`), o.push(" </url>"), o.join("\n");
|
|
987
1095
|
}).filter(Boolean).join("\n"),
|
|
988
1096
|
"</urlset>"
|
|
989
1097
|
].join("\n");
|
|
990
1098
|
}
|
|
991
|
-
function
|
|
1099
|
+
function ft(e, t) {
|
|
992
1100
|
return [
|
|
993
1101
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
994
1102
|
"<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
995
1103
|
e.map((e) => {
|
|
996
|
-
let n = t ?
|
|
1104
|
+
let n = t ? st(e, t) : e;
|
|
997
1105
|
return n ? [
|
|
998
1106
|
" <sitemap>",
|
|
999
|
-
` <loc>${
|
|
1107
|
+
` <loc>${Q(n)}</loc>`,
|
|
1000
1108
|
" </sitemap>"
|
|
1001
1109
|
].join("\n") : "";
|
|
1002
1110
|
}).filter(Boolean).join("\n"),
|
|
@@ -1005,14 +1113,14 @@ function nt(e, t) {
|
|
|
1005
1113
|
}
|
|
1006
1114
|
//#endregion
|
|
1007
1115
|
//#region src/types.ts
|
|
1008
|
-
var
|
|
1116
|
+
var pt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
1009
1117
|
status;
|
|
1010
1118
|
endpoint;
|
|
1011
1119
|
body;
|
|
1012
1120
|
constructor(e, t, n, r) {
|
|
1013
1121
|
super(e), this.status = t, this.endpoint = n, this.body = r, this.name = "ApiError";
|
|
1014
1122
|
}
|
|
1015
|
-
},
|
|
1123
|
+
}, mt = (e) => e === 429 || e >= 500 && e <= 599, ht = (e) => new Promise((t) => setTimeout(t, e)), gt = class {
|
|
1016
1124
|
baseUrl;
|
|
1017
1125
|
token;
|
|
1018
1126
|
vid;
|
|
@@ -1075,8 +1183,8 @@ var rt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
|
1075
1183
|
let n = await this.fetchWithTimeout(e);
|
|
1076
1184
|
return await this.parseResponse(n, t);
|
|
1077
1185
|
} catch (e) {
|
|
1078
|
-
if (n = e, !(r < this.retries && (!(e instanceof $) || e.status === 0 ||
|
|
1079
|
-
await
|
|
1186
|
+
if (n = e, !(r < this.retries && (!(e instanceof $) || e.status === 0 || mt(e.status)))) throw e;
|
|
1187
|
+
await ht(200 * 2 ** r);
|
|
1080
1188
|
}
|
|
1081
1189
|
throw n;
|
|
1082
1190
|
}
|
|
@@ -1178,6 +1286,6 @@ var rt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
|
1178
1286
|
}
|
|
1179
1287
|
};
|
|
1180
1288
|
//#endregion
|
|
1181
|
-
export {
|
|
1289
|
+
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
1290
|
|
|
1183
1291
|
//# sourceMappingURL=index.mjs.map
|