@b10cks/client 1.11.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 +49 -5
- package/dist/index.cjs +45 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +238 -12
- package/dist/index.mjs +646 -104
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -7
package/dist/index.mjs
CHANGED
|
@@ -261,16 +261,26 @@ function f(e) {
|
|
|
261
261
|
}
|
|
262
262
|
//#endregion
|
|
263
263
|
//#region src/preview-bridge.ts
|
|
264
|
-
var p =
|
|
265
|
-
"
|
|
266
|
-
"
|
|
267
|
-
"
|
|
268
|
-
"
|
|
269
|
-
"
|
|
270
|
-
"
|
|
271
|
-
|
|
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 = {
|
|
273
|
+
CONTENT_UPDATE: (e) => p(e.content),
|
|
274
|
+
CONTENT_PATCH: (e) => m(e.path) && "value" in e && (e.itemId === void 0 || typeof e.itemId == "string"),
|
|
275
|
+
SELECT_UPDATE: _,
|
|
276
|
+
HOVER_UPDATE: _,
|
|
277
|
+
FIELD_CONFIG: (e) => typeof e.itemId == "string" && e.itemId !== "" && m(e.path) && g(e.richtext),
|
|
278
|
+
BLOCK_LABELS: (e) => p(e.labels) && Object.values(e.labels).every((e) => typeof e == "string"),
|
|
279
|
+
HIDDEN_BLOCKS: (e) => Array.isArray(e.ids) && e.ids.every((e) => typeof e == "string")
|
|
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 = {};
|
|
283
|
+
received = {};
|
|
274
284
|
initialized = !1;
|
|
275
285
|
allowedOrigins = null;
|
|
276
286
|
parentOrigin = null;
|
|
@@ -284,12 +294,15 @@ var p = /* @__PURE__ */ new Set([
|
|
|
284
294
|
e.allowedOrigins && !this.allowedOrigins && (this.allowedOrigins = e.allowedOrigins, this.parentOrigin && !this.allowedOrigins.includes(this.parentOrigin) && (this.parentOrigin = null));
|
|
285
295
|
return;
|
|
286
296
|
}
|
|
287
|
-
this.allowedOrigins = e.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({
|
|
297
|
+
this.allowedOrigins = e.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({
|
|
298
|
+
type: ne,
|
|
299
|
+
payload: { protocol: 3 }
|
|
300
|
+
}, "*");
|
|
288
301
|
}
|
|
289
302
|
}
|
|
290
303
|
destroy() {
|
|
291
304
|
this.initialized && typeof window < "u" && window.removeEventListener("message", this.handleMessage), this.initialized = !1, this.parentOrigin = null;
|
|
292
|
-
for (let e of Object.keys(this.listeners)) this.listeners[e]?.clear();
|
|
305
|
+
for (let e of Object.keys(this.listeners)) this.listeners[e]?.clear(), delete this.received[e];
|
|
293
306
|
}
|
|
294
307
|
isInPreviewMode() {
|
|
295
308
|
return typeof window < "u" && window.self !== window.top;
|
|
@@ -301,6 +314,9 @@ var p = /* @__PURE__ */ new Set([
|
|
|
301
314
|
n.delete(t);
|
|
302
315
|
};
|
|
303
316
|
}
|
|
317
|
+
latest(e) {
|
|
318
|
+
return this.received[e];
|
|
319
|
+
}
|
|
304
320
|
selectItem(e) {
|
|
305
321
|
this.post("SELECT_UPDATE", { selectedItem: e });
|
|
306
322
|
}
|
|
@@ -324,6 +340,22 @@ var p = /* @__PURE__ */ new Set([
|
|
|
324
340
|
value: n
|
|
325
341
|
});
|
|
326
342
|
}
|
|
343
|
+
patchLocal(e) {
|
|
344
|
+
this.isInPreviewMode() && this.notify("CONTENT_PATCH", e);
|
|
345
|
+
}
|
|
346
|
+
blockAction(e, t) {
|
|
347
|
+
this.post("BLOCK_ACTION", {
|
|
348
|
+
itemId: e,
|
|
349
|
+
action: t
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
moveBlock(e, t, n) {
|
|
353
|
+
this.post("BLOCK_MOVE", {
|
|
354
|
+
itemId: e,
|
|
355
|
+
targetId: t,
|
|
356
|
+
position: n
|
|
357
|
+
});
|
|
358
|
+
}
|
|
327
359
|
post(e, t) {
|
|
328
360
|
this.isInPreviewMode() && window.parent.postMessage({
|
|
329
361
|
type: e,
|
|
@@ -333,87 +365,495 @@ var p = /* @__PURE__ */ new Set([
|
|
|
333
365
|
handleMessage = (e) => {
|
|
334
366
|
if (!this.isOriginTrusted(e.origin) || !e.data || typeof e.data != "object") return;
|
|
335
367
|
let { type: t, payload: n } = e.data;
|
|
336
|
-
|
|
368
|
+
te(t) && p(n) && ee[t](n) && (!this.parentOrigin && e.origin && e.origin !== "null" && (this.parentOrigin = e.origin), this.notify(t, n));
|
|
337
369
|
};
|
|
338
370
|
isOriginTrusted(e) {
|
|
339
371
|
return this.parentOrigin ? e === this.parentOrigin : !this.allowedOrigins || this.allowedOrigins.includes(e);
|
|
340
372
|
}
|
|
341
373
|
notify(e, t) {
|
|
374
|
+
this.received[e] = t;
|
|
342
375
|
let n = this.listeners[e];
|
|
343
376
|
if (n) for (let e of n) e(t);
|
|
344
377
|
}
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
|
|
378
|
+
}, v = ie.getInstance(), y = "rgb(59, 130, 246)", ae = 2, oe = `
|
|
379
|
+
:host { all: initial; position: fixed; inset: 0; pointer-events: none; z-index: 2147483647; }
|
|
380
|
+
[hidden] { display: none !important; }
|
|
381
|
+
.box {
|
|
382
|
+
position: fixed; top: 0; left: 0; box-sizing: border-box;
|
|
383
|
+
border: ${ae}px solid ${y}; border-radius: 2px;
|
|
384
|
+
}
|
|
385
|
+
.box.hover { border-style: dashed; border-color: rgba(59, 130, 246, 0.6); }
|
|
386
|
+
.label {
|
|
387
|
+
position: absolute; left: 6px; bottom: 100%; margin-bottom: ${ae}px;
|
|
388
|
+
display: flex; align-items: center; padding: 0 6px; border-radius: 3px 3px 0 0; white-space: nowrap;
|
|
389
|
+
font: 500 11px/16px system-ui, -apple-system, sans-serif;
|
|
390
|
+
color: #fff; background: ${y};
|
|
391
|
+
}
|
|
392
|
+
.label:empty, .name:empty, .crumbs:empty { display: none; }
|
|
393
|
+
.box.hover .label { background: rgba(59, 130, 246, 0.8); }
|
|
394
|
+
.box[data-inside] .label { bottom: auto; top: 0; margin: 0; border-radius: 0 0 3px 3px; }
|
|
395
|
+
.bar { pointer-events: auto; line-height: 20px; padding-right: 2px; user-select: none; -webkit-user-select: none; }
|
|
396
|
+
.crumbs { display: flex; align-items: center; }
|
|
397
|
+
.crumb { all: unset; cursor: pointer; opacity: 0.75; max-width: 12em; overflow: hidden; text-overflow: ellipsis; border-radius: 2px; }
|
|
398
|
+
.crumb:hover { opacity: 1; text-decoration: underline; }
|
|
399
|
+
.sep, .more { opacity: 0.6; padding: 0 4px; }
|
|
400
|
+
.name { max-width: 16em; overflow: hidden; text-overflow: ellipsis; }
|
|
401
|
+
.tools { display: flex; margin-left: 6px; padding-left: 2px; border-left: 1px solid rgba(255, 255, 255, 0.35); }
|
|
402
|
+
.tool {
|
|
403
|
+
all: unset; box-sizing: border-box; display: grid; place-items: center;
|
|
404
|
+
width: 20px; height: 20px; border-radius: 2px; cursor: pointer;
|
|
405
|
+
}
|
|
406
|
+
.tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
|
|
407
|
+
.tool[aria-pressed='true'] { background: rgba(255, 255, 255, 0.3); }
|
|
408
|
+
.tool:disabled { opacity: 0.4; cursor: default; }
|
|
409
|
+
.tool svg { width: 14px; height: 14px; }
|
|
410
|
+
.handle { cursor: grab; touch-action: none; }
|
|
411
|
+
:host([data-dragging]) .handle { cursor: grabbing; }
|
|
412
|
+
.crumb:focus-visible, .tool:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
|
|
413
|
+
.indicator {
|
|
414
|
+
position: fixed; top: 0; left: 0; border-radius: 2px;
|
|
415
|
+
background: ${y}; box-shadow: 0 0 0 1px #fff;
|
|
416
|
+
}
|
|
417
|
+
`, se = [
|
|
418
|
+
{
|
|
419
|
+
action: "move-up",
|
|
420
|
+
label: "Move up",
|
|
421
|
+
icon: "<path d=\"M12 19V5M6 11l6-6 6 6\"/>"
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
action: "move-down",
|
|
425
|
+
label: "Move down",
|
|
426
|
+
icon: "<path d=\"M12 5v14M6 13l6 6 6-6\"/>"
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
action: "insert-before",
|
|
430
|
+
label: "Add block before",
|
|
431
|
+
icon: "<path d=\"M4 4h16M12 9v10M7 14h10\"/>"
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
action: "insert-after",
|
|
435
|
+
label: "Add block after",
|
|
436
|
+
icon: "<path d=\"M4 20h16M12 5v10M7 10h10\"/>"
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
action: "duplicate",
|
|
440
|
+
label: "Duplicate",
|
|
441
|
+
icon: "<rect x=\"8\" y=\"8\" width=\"12\" height=\"12\" rx=\"2\"/><path d=\"M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2\"/>"
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
action: "delete",
|
|
445
|
+
label: "Delete",
|
|
446
|
+
icon: "<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>"
|
|
447
|
+
}
|
|
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) {
|
|
450
|
+
let t = document.createElement("div");
|
|
451
|
+
t.id = "b10cks-overlay";
|
|
452
|
+
let n = t.attachShadow({ mode: "open" }), r = document.createElement("style");
|
|
453
|
+
r.textContent = oe, n.appendChild(r);
|
|
454
|
+
let i = b("div", "box hover");
|
|
455
|
+
i.hidden = !0;
|
|
456
|
+
let a = b("div", "label name");
|
|
457
|
+
i.appendChild(a);
|
|
458
|
+
let o = b("div", "box selected");
|
|
459
|
+
o.hidden = !0;
|
|
460
|
+
let s = b("div", "label bar"), c = b("span", "crumbs"), l = b("span", "name");
|
|
461
|
+
l.title = de;
|
|
462
|
+
let u = b("div", "tools");
|
|
463
|
+
u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Block actions");
|
|
464
|
+
let d = b("div", "tool handle");
|
|
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);
|
|
466
|
+
let f = /* @__PURE__ */ new Map();
|
|
467
|
+
for (let t of se) {
|
|
468
|
+
let n = b("button", "tool");
|
|
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);
|
|
470
|
+
}
|
|
471
|
+
let p = !1, m = b("button", "tool");
|
|
472
|
+
m.type = "button", m.addEventListener("click", () => e.onAction(p ? "show" : "hide"));
|
|
473
|
+
let h = (e) => {
|
|
474
|
+
p = e;
|
|
475
|
+
let t = p ? "Show" : "Hide";
|
|
476
|
+
m.title = t, m.setAttribute("aria-label", t), m.setAttribute("aria-pressed", String(p)), m.innerHTML = x(p ? le : ce);
|
|
477
|
+
};
|
|
478
|
+
h(!1), u.insertBefore(m, f.get("delete") ?? null), s.append(c, l, u), o.appendChild(s);
|
|
479
|
+
let g = b("div", "indicator");
|
|
480
|
+
g.hidden = !0, n.append(i, o, g), document.body.appendChild(t);
|
|
481
|
+
let _ = "";
|
|
482
|
+
return {
|
|
483
|
+
host: t,
|
|
484
|
+
selected: {
|
|
485
|
+
box: o,
|
|
486
|
+
label: s,
|
|
487
|
+
name: l
|
|
488
|
+
},
|
|
489
|
+
hover: {
|
|
490
|
+
box: i,
|
|
491
|
+
label: a,
|
|
492
|
+
name: a
|
|
493
|
+
},
|
|
494
|
+
indicator: g,
|
|
495
|
+
renderBar(t) {
|
|
496
|
+
if (s.hidden = !t || !t.label && t.crumbs.length === 0 && !t.actions, !t) return;
|
|
497
|
+
let n = t.crumbs.map((e) => `${e.id}\u0000${e.label}`).join("");
|
|
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);
|
|
499
|
+
let r = t.actions?.hidden ?? null;
|
|
500
|
+
m.hidden = r === null, r !== null && r !== p && h(r);
|
|
501
|
+
},
|
|
502
|
+
setDragging(e) {
|
|
503
|
+
t.toggleAttribute("data-dragging", e);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
function pe(e, t) {
|
|
508
|
+
let n = [], r = e.slice(0, -3);
|
|
509
|
+
if (r.length > 0) {
|
|
510
|
+
let e = b("span", "more");
|
|
511
|
+
e.textContent = "…", e.title = r.map((e) => e.label).join(" › "), n.push(e, me());
|
|
512
|
+
}
|
|
513
|
+
for (let r of e.slice(-3)) {
|
|
514
|
+
let e = b("button", "crumb");
|
|
515
|
+
e.type = "button", e.textContent = r.label, e.title = `Select ${r.label}`, e.addEventListener("click", () => t(r.id)), n.push(e, me());
|
|
516
|
+
}
|
|
517
|
+
return n;
|
|
518
|
+
}
|
|
519
|
+
function me() {
|
|
520
|
+
let e = b("span", "sep");
|
|
521
|
+
return e.textContent = "›", e.setAttribute("aria-hidden", "true"), e;
|
|
522
|
+
}
|
|
523
|
+
function he(e, t) {
|
|
524
|
+
e && (e.disabled = t);
|
|
525
|
+
}
|
|
526
|
+
function b(e, t) {
|
|
527
|
+
let n = document.createElement(e);
|
|
528
|
+
return n.className = t, n;
|
|
529
|
+
}
|
|
530
|
+
function x(e) {
|
|
531
|
+
return `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`;
|
|
532
|
+
}
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/preview-overlay.ts
|
|
535
|
+
var ge = {
|
|
536
|
+
selected: "b10cks-selected",
|
|
537
|
+
hover: "b10cks-hover"
|
|
538
|
+
}, _e = "b10cks-hidden", S = 2, ve = 24, C = 3, w = /* @__PURE__ */ new Map(), T = {
|
|
539
|
+
selected: null,
|
|
540
|
+
hover: null
|
|
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();
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function ye() {
|
|
552
|
+
E = v.latest("SELECT_UPDATE")?.selectedItem ?? E, E && W();
|
|
553
|
+
let e = v.on("SELECT_UPDATE", ({ selectedItem: e }) => {
|
|
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));
|
|
557
|
+
}), t = v.on("HOVER_UPDATE", ({ selectedItem: e }) => {
|
|
558
|
+
G("hover", z(e || null));
|
|
559
|
+
}), n = v.on("BLOCK_LABELS", K), r = v.on("HIDDEN_BLOCKS", ({ ids: e }) => {
|
|
560
|
+
let t = new Set(e);
|
|
561
|
+
for (let [e, n] of w) n.kind === "block" && e.classList.toggle(_e, t.has(n.id));
|
|
562
|
+
K();
|
|
563
|
+
}), i = {
|
|
564
|
+
capture: !0,
|
|
565
|
+
passive: !0
|
|
566
|
+
};
|
|
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;
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
function I(e) {
|
|
572
|
+
if (e.altKey) return;
|
|
573
|
+
let t = Ee(e);
|
|
574
|
+
t && !w.get(t)?.isEditing?.() && (L(e), e.type === "click" && R(t, e));
|
|
575
|
+
}
|
|
576
|
+
function be(e) {
|
|
577
|
+
if (P) {
|
|
578
|
+
e.key === "Escape" && (L(e), U());
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
let t = T.selected;
|
|
582
|
+
if (!t?.isConnected || e.defaultPrevented || xe(e) || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
583
|
+
let n = null;
|
|
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));
|
|
585
|
+
}
|
|
586
|
+
function xe(e) {
|
|
587
|
+
let t = e.composedPath()[0];
|
|
588
|
+
return t instanceof HTMLElement && (t.isContentEditable || t.matches("input, textarea, select"));
|
|
589
|
+
}
|
|
590
|
+
function L(e) {
|
|
591
|
+
e.preventDefault(), e.stopImmediatePropagation();
|
|
592
|
+
}
|
|
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));
|
|
596
|
+
}
|
|
597
|
+
function Se(e) {
|
|
598
|
+
let t = z(e);
|
|
599
|
+
t && R(t);
|
|
600
|
+
}
|
|
601
|
+
function Ce(e) {
|
|
602
|
+
let t = T.selected && w.get(T.selected);
|
|
603
|
+
t?.kind === "block" && v.blockAction(t.id, e);
|
|
604
|
+
}
|
|
605
|
+
function we(e) {
|
|
606
|
+
G("hover", Ee(e));
|
|
607
|
+
}
|
|
608
|
+
function Te(e) {
|
|
609
|
+
e.relatedTarget || G("hover", null);
|
|
610
|
+
}
|
|
611
|
+
function Ee(e) {
|
|
612
|
+
for (let t of e.composedPath()) if (t instanceof HTMLElement && w.has(t)) return t;
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
function z(e) {
|
|
616
|
+
if (!e) return null;
|
|
617
|
+
let t = null;
|
|
618
|
+
for (let [n, r] of w) r.kind === "block" && r.id === e && n.isConnected && (!t || t.contains(n)) && (t = n);
|
|
619
|
+
return t;
|
|
620
|
+
}
|
|
621
|
+
function B(e) {
|
|
622
|
+
if (e.parentElement) return e.parentElement;
|
|
623
|
+
let t = e.parentNode;
|
|
624
|
+
return t instanceof ShadowRoot ? t.host : null;
|
|
625
|
+
}
|
|
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)) {
|
|
629
|
+
if (!(n instanceof HTMLElement)) continue;
|
|
630
|
+
let e = w.get(n);
|
|
631
|
+
e?.kind === "block" && e.id !== r && (t.push(n), r = e.id);
|
|
632
|
+
}
|
|
633
|
+
return t;
|
|
634
|
+
}
|
|
635
|
+
function De(e) {
|
|
636
|
+
let t = V(e)[0];
|
|
637
|
+
return (t && w.get(t)?.id) ?? null;
|
|
638
|
+
}
|
|
639
|
+
function H(e, t) {
|
|
640
|
+
let n = w.get(e);
|
|
641
|
+
if (n?.kind !== "block") return null;
|
|
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);
|
|
645
|
+
}
|
|
646
|
+
function Oe(e) {
|
|
647
|
+
let t = w.get(e);
|
|
648
|
+
if (!t) return null;
|
|
649
|
+
let n = V(e).reverse().flatMap((e) => {
|
|
650
|
+
let t = w.get(e);
|
|
651
|
+
return t ? [{
|
|
652
|
+
id: t.id,
|
|
653
|
+
label: J(t) || "Block"
|
|
654
|
+
}] : [];
|
|
655
|
+
});
|
|
656
|
+
return {
|
|
657
|
+
label: J(t),
|
|
658
|
+
crumbs: n,
|
|
659
|
+
actions: t.kind === "block" && Re() ? {
|
|
660
|
+
canMoveUp: !!H(e, -1),
|
|
661
|
+
canMoveDown: !!H(e, 1),
|
|
662
|
+
hidden: ze(t.id)
|
|
663
|
+
} : null
|
|
664
|
+
};
|
|
665
|
+
}
|
|
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 = {
|
|
669
|
+
id: r.id,
|
|
670
|
+
el: n,
|
|
671
|
+
drop: null
|
|
672
|
+
}, O?.setDragging(!0), window.addEventListener("pointermove", Ae, !0), window.addEventListener("pointerup", je, !0), window.addEventListener("pointercancel", U, !0));
|
|
673
|
+
}
|
|
674
|
+
function Ae(e) {
|
|
675
|
+
P && (P.drop = Me(P, e.clientX, e.clientY), G("hover", P.drop?.el ?? null), q());
|
|
676
|
+
}
|
|
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);
|
|
680
|
+
}
|
|
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());
|
|
683
|
+
}
|
|
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)) {
|
|
687
|
+
if (!(t instanceof HTMLElement)) continue;
|
|
688
|
+
let n = w.get(t);
|
|
689
|
+
if (n?.kind === "block") {
|
|
690
|
+
if (n.id === e.id) return null;
|
|
691
|
+
i ??= t;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
let a = i && w.get(i);
|
|
695
|
+
if (!i || !a || i.contains(e.el)) return null;
|
|
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;
|
|
697
|
+
return {
|
|
698
|
+
el: i,
|
|
699
|
+
id: a.id,
|
|
700
|
+
position: c ? "before" : "after",
|
|
701
|
+
horizontal: s
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function Ne(e, t) {
|
|
705
|
+
let n = H(e, 1) ?? H(e, -1);
|
|
706
|
+
if (!n) return !1;
|
|
707
|
+
let r = n.getBoundingClientRect();
|
|
708
|
+
return r.top < t.bottom && r.bottom > t.top;
|
|
709
|
+
}
|
|
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));
|
|
715
|
+
}));
|
|
716
|
+
}
|
|
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?.({
|
|
720
|
+
block: "nearest",
|
|
721
|
+
behavior: "smooth"
|
|
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, {
|
|
723
|
+
childList: !0,
|
|
724
|
+
subtree: !0
|
|
725
|
+
}), N = !0), q());
|
|
726
|
+
}
|
|
727
|
+
function Pe(e, t, n) {
|
|
728
|
+
let r = w.get(e);
|
|
729
|
+
t === "selected" ? r?.onSelectChange?.(n) : r?.onHoverChange?.(n);
|
|
730
|
+
}
|
|
731
|
+
function K() {
|
|
732
|
+
N = !0, q();
|
|
733
|
+
}
|
|
734
|
+
function q() {
|
|
735
|
+
j || (j = !0, requestAnimationFrame(() => {
|
|
736
|
+
j = !1, Fe();
|
|
737
|
+
}));
|
|
738
|
+
}
|
|
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) {
|
|
752
|
+
if (!t?.isConnected) {
|
|
753
|
+
e.box.hidden = !0;
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
let { box: n, label: r } = e, i = t.getBoundingClientRect(), a = r.offsetWidth, o = r.offsetHeight, s = document.documentElement.clientWidth;
|
|
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;
|
|
759
|
+
n.toggleAttribute("data-inside", c);
|
|
760
|
+
let l = Math.min(S - i.top, i.height + 4 - o);
|
|
761
|
+
r.style.top = c ? `${Math.max(0, l)}px` : "";
|
|
762
|
+
let u = i.left - S + 8, d = u + a - s;
|
|
763
|
+
r.style.marginLeft = d > 0 ? `${-Math.min(d, u)}px` : "";
|
|
764
|
+
}
|
|
765
|
+
function Le(e, t) {
|
|
766
|
+
if (!t?.el.isConnected) {
|
|
767
|
+
e.hidden = !0;
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
let n = t.el.getBoundingClientRect(), r = t.position === "before", { style: i } = e;
|
|
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`;
|
|
772
|
+
else {
|
|
773
|
+
let e = r ? n.top : n.bottom;
|
|
774
|
+
i.transform = `translate(${n.left}px, ${e - C / 2}px)`, i.width = `${n.width}px`, i.height = `${C}px`;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function Re() {
|
|
778
|
+
return v.latest("BLOCK_LABELS") !== void 0;
|
|
779
|
+
}
|
|
780
|
+
function ze(e) {
|
|
781
|
+
return v.latest("HIDDEN_BLOCKS")?.ids.includes(e) ?? null;
|
|
782
|
+
}
|
|
783
|
+
function J(e) {
|
|
784
|
+
let t = e?.label;
|
|
785
|
+
return t ? (e.kind === "block" ? v.latest("BLOCK_LABELS")?.labels[t] : void 0) ?? Be(t) : "";
|
|
786
|
+
}
|
|
787
|
+
function Be(e) {
|
|
788
|
+
if (!e) return "";
|
|
789
|
+
if (!/^[a-z][a-z0-9]*([_-][a-z0-9]+)*$/.test(e)) return e;
|
|
790
|
+
let t = e.replace(/[_-]+/g, " ");
|
|
791
|
+
return t.charAt(0).toUpperCase() + t.slice(1);
|
|
792
|
+
}
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region src/editable.ts
|
|
795
|
+
var Ve = "b10cks-preview-style", He = "--b10cks-scroll-offset";
|
|
796
|
+
function Y() {
|
|
797
|
+
if (typeof document > "u" || document.getElementById(Ve)) return;
|
|
348
798
|
let e = document.createElement("style");
|
|
349
|
-
e.id =
|
|
350
|
-
.b10cks-preview { scroll-margin-top: var(${
|
|
351
|
-
.b10cks-
|
|
352
|
-
.b10cks-preview:hover {
|
|
353
|
-
outline: 2px dashed rgba(59, 130, 246, 0.5);
|
|
354
|
-
outline-offset: 2px;
|
|
355
|
-
}
|
|
356
|
-
.b10cks-selected {
|
|
357
|
-
outline: 2px solid rgb(59, 130, 246) !important;
|
|
358
|
-
outline-offset: 2px;
|
|
359
|
-
}
|
|
799
|
+
e.id = Ve, e.textContent = `
|
|
800
|
+
.b10cks-preview { scroll-margin-top: var(${He}, 0px); }
|
|
801
|
+
.b10cks-preview.b10cks-hidden { opacity: 0.4 !important; }
|
|
360
802
|
`, document.head.appendChild(e);
|
|
361
803
|
}
|
|
362
|
-
function
|
|
804
|
+
function Ue(e) {
|
|
363
805
|
if (typeof document > "u") return;
|
|
364
806
|
let t = typeof e == "number" ? `${e}px` : e;
|
|
365
|
-
document.documentElement.style.setProperty(
|
|
807
|
+
document.documentElement.style.setProperty(He, t);
|
|
366
808
|
}
|
|
367
|
-
function
|
|
368
|
-
if (!
|
|
369
|
-
|
|
370
|
-
let { id: n,
|
|
809
|
+
function We(e, t) {
|
|
810
|
+
if (!v.isInPreviewMode() || !t.id) return () => {};
|
|
811
|
+
Y();
|
|
812
|
+
let { id: n, label: r, onSelectChange: i, onHoverChange: a, scrollOnSelect: o = !0 } = t;
|
|
371
813
|
e.classList.add("b10cks-preview");
|
|
372
|
-
let
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
};
|
|
381
|
-
e.addEventListener("click", o);
|
|
382
|
-
let l = g.on("SELECT_UPDATE", s), u = g.on("HOVER_UPDATE", c);
|
|
814
|
+
let s = F(e, {
|
|
815
|
+
id: n,
|
|
816
|
+
kind: "block",
|
|
817
|
+
label: r,
|
|
818
|
+
scrollOnSelect: o,
|
|
819
|
+
onSelectChange: i,
|
|
820
|
+
onHoverChange: a,
|
|
821
|
+
activate: () => v.selectItem(n)
|
|
822
|
+
});
|
|
383
823
|
return () => {
|
|
384
|
-
|
|
824
|
+
s(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
385
825
|
};
|
|
386
826
|
}
|
|
387
|
-
function
|
|
388
|
-
if (!
|
|
389
|
-
let { id: n, field: r, path: i, mode: a = "inline" } = t;
|
|
827
|
+
function Ge(e, t) {
|
|
828
|
+
if (!v.isInPreviewMode() || !t.id) return () => {};
|
|
829
|
+
let { id: n, field: r, path: i, mode: a = "inline", label: o } = t;
|
|
390
830
|
if (a === "select") {
|
|
391
|
-
|
|
392
|
-
let t = (e
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
831
|
+
Y(), e.classList.add("b10cks-preview");
|
|
832
|
+
let t = F(e, {
|
|
833
|
+
id: n,
|
|
834
|
+
kind: "field",
|
|
835
|
+
label: o ?? Ke(i) ?? r,
|
|
836
|
+
activate: () => i ? v.selectField(n, i) : v.selectItem(n)
|
|
837
|
+
});
|
|
838
|
+
return () => {
|
|
839
|
+
t(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
397
840
|
};
|
|
398
841
|
}
|
|
399
842
|
e.setAttribute("contenteditable", "true");
|
|
400
|
-
let
|
|
843
|
+
let s = (e) => {
|
|
401
844
|
let t = e.target.innerText;
|
|
402
|
-
i ?
|
|
845
|
+
i ? v.updateFieldAt(n, i, t) : v.updateField(n, r ?? "", t);
|
|
403
846
|
};
|
|
404
|
-
return e.addEventListener("input",
|
|
405
|
-
e.removeEventListener("input",
|
|
847
|
+
return e.addEventListener("input", s), () => {
|
|
848
|
+
e.removeEventListener("input", s), e.removeAttribute("contenteditable");
|
|
406
849
|
};
|
|
407
850
|
}
|
|
408
|
-
function
|
|
409
|
-
typeof e
|
|
410
|
-
block: "nearest",
|
|
411
|
-
behavior: "smooth"
|
|
412
|
-
});
|
|
851
|
+
function Ke(e) {
|
|
852
|
+
return e?.findLast((e) => typeof e == "string");
|
|
413
853
|
}
|
|
414
854
|
//#endregion
|
|
415
855
|
//#region src/preview-store.ts
|
|
416
|
-
function
|
|
856
|
+
function qe(e, t) {
|
|
417
857
|
let n = e;
|
|
418
858
|
for (let e of t) {
|
|
419
859
|
if (typeof n != "object" || !n) return;
|
|
@@ -421,18 +861,18 @@ function w(e, t) {
|
|
|
421
861
|
}
|
|
422
862
|
return n;
|
|
423
863
|
}
|
|
424
|
-
function
|
|
864
|
+
function X(e, t, n) {
|
|
425
865
|
if (t.length === 0) return n;
|
|
426
866
|
let [r, ...i] = t;
|
|
427
867
|
if (r === void 0) return n;
|
|
428
868
|
if (typeof r == "number") {
|
|
429
869
|
let t = Array.isArray(e) ? e.slice() : [];
|
|
430
|
-
return t[r] =
|
|
870
|
+
return t[r] = X(t[r], i, n), t;
|
|
431
871
|
}
|
|
432
872
|
let a = e && typeof e == "object" && !Array.isArray(e) ? { ...e } : {};
|
|
433
|
-
return a[r] =
|
|
873
|
+
return a[r] = X(a[r], i, n), a;
|
|
434
874
|
}
|
|
435
|
-
function
|
|
875
|
+
function Je(e, t) {
|
|
436
876
|
let n = (e, r) => {
|
|
437
877
|
if (Array.isArray(e)) {
|
|
438
878
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -455,16 +895,16 @@ function E(e, t) {
|
|
|
455
895
|
};
|
|
456
896
|
return n(e, []);
|
|
457
897
|
}
|
|
458
|
-
function
|
|
898
|
+
function Ye(e, t) {
|
|
459
899
|
if (!t || typeof t != "object") return e;
|
|
460
900
|
let n = typeof t.id == "string" ? t.id : void 0;
|
|
461
901
|
if (!n || !e || typeof e != "object") return t;
|
|
462
902
|
let r = e, i = typeof r.id == "string" ? r.id : void 0;
|
|
463
903
|
if (i === n) return t;
|
|
464
|
-
let a =
|
|
465
|
-
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;
|
|
466
906
|
}
|
|
467
|
-
var
|
|
907
|
+
var Xe = class {
|
|
468
908
|
content;
|
|
469
909
|
listeners = /* @__PURE__ */ new Set();
|
|
470
910
|
constructor(e) {
|
|
@@ -478,39 +918,141 @@ var O = class {
|
|
|
478
918
|
this.content = e, this.emit();
|
|
479
919
|
}
|
|
480
920
|
applyContentUpdate(e) {
|
|
481
|
-
let t =
|
|
921
|
+
let t = Ye(this.content, e);
|
|
482
922
|
t !== this.content && (this.content = t, this.emit());
|
|
483
923
|
}
|
|
484
|
-
patch(e, t) {
|
|
485
|
-
|
|
924
|
+
patch(e, t, n) {
|
|
925
|
+
let r = [];
|
|
926
|
+
if (n && this.content?.id !== n) {
|
|
927
|
+
let e = Je(this.content, n);
|
|
928
|
+
if (!e) return;
|
|
929
|
+
r = e;
|
|
930
|
+
}
|
|
931
|
+
this.content = X(this.content, [...r, ...e], t), this.emit();
|
|
486
932
|
}
|
|
487
933
|
emit() {
|
|
488
934
|
for (let e of this.listeners) e();
|
|
489
935
|
}
|
|
490
936
|
};
|
|
491
|
-
function
|
|
492
|
-
let t =
|
|
937
|
+
function Ze(e) {
|
|
938
|
+
let t = v.on("CONTENT_UPDATE", ({ content: t }) => {
|
|
493
939
|
e.applyContentUpdate(t);
|
|
494
|
-
}), n =
|
|
495
|
-
e.patch(
|
|
940
|
+
}), n = v.on("CONTENT_PATCH", ({ itemId: t, path: n, value: r }) => {
|
|
941
|
+
e.patch(n, r, t);
|
|
496
942
|
});
|
|
497
943
|
return () => {
|
|
498
944
|
t(), n();
|
|
499
945
|
};
|
|
500
946
|
}
|
|
501
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
|
|
502
1044
|
//#region src/sitemap.ts
|
|
503
|
-
function
|
|
1045
|
+
function at(e) {
|
|
504
1046
|
return (e ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
505
1047
|
}
|
|
506
|
-
function
|
|
507
|
-
let n =
|
|
1048
|
+
function ot(e, t) {
|
|
1049
|
+
let n = at(e), r = at(t);
|
|
508
1050
|
if (!r) return n && n !== "home" ? `/${n}` : "/";
|
|
509
1051
|
if (!n || n === "home") return `/${r}`;
|
|
510
1052
|
let i = `${r}/`;
|
|
511
1053
|
return n === r || n.startsWith(i) ? `/${n}` : `/${r}/${n}`;
|
|
512
1054
|
}
|
|
513
|
-
function
|
|
1055
|
+
function st(e, t) {
|
|
514
1056
|
if (!t) return null;
|
|
515
1057
|
try {
|
|
516
1058
|
return new URL(e, t).toString();
|
|
@@ -518,51 +1060,51 @@ function M(e, t) {
|
|
|
518
1060
|
return null;
|
|
519
1061
|
}
|
|
520
1062
|
}
|
|
521
|
-
function
|
|
1063
|
+
function Q(e) {
|
|
522
1064
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
523
1065
|
}
|
|
524
|
-
function
|
|
1066
|
+
function ct(e, t, n) {
|
|
525
1067
|
let { localePrefix: r = "auto", defaultLocale: i } = t;
|
|
526
|
-
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);
|
|
527
1069
|
}
|
|
528
|
-
function
|
|
1070
|
+
function lt(e) {
|
|
529
1071
|
let t = /* @__PURE__ */ new Set();
|
|
530
1072
|
for (let n of e) if (n.language_iso && t.add(n.language_iso), t.size > 1) return !0;
|
|
531
1073
|
return !1;
|
|
532
1074
|
}
|
|
533
|
-
function
|
|
534
|
-
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);
|
|
535
1077
|
return e.filter((e) => {
|
|
536
1078
|
if (r && e.language_iso !== r) return !1;
|
|
537
1079
|
let o = e.meta?.robots?.toLowerCase();
|
|
538
1080
|
if (o?.includes("noindex") || o?.includes("none")) return !1;
|
|
539
|
-
let s =
|
|
540
|
-
return i.has(c)
|
|
1081
|
+
let s = ct(e, t, a), c = n ? st(s, n) ?? s : s;
|
|
1082
|
+
return !i.has(c) && (i.add(c), !0);
|
|
541
1083
|
});
|
|
542
1084
|
}
|
|
543
|
-
function
|
|
544
|
-
let r =
|
|
1085
|
+
function dt(e, t, n = {}) {
|
|
1086
|
+
let r = lt(e);
|
|
545
1087
|
return [
|
|
546
1088
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
547
1089
|
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
548
1090
|
e.map((e) => {
|
|
549
|
-
let i =
|
|
1091
|
+
let i = ct(e, n, r), a = t ? st(i, t) : i;
|
|
550
1092
|
if (!a) return "";
|
|
551
|
-
let o = [" <url>", ` <loc>${
|
|
552
|
-
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");
|
|
553
1095
|
}).filter(Boolean).join("\n"),
|
|
554
1096
|
"</urlset>"
|
|
555
1097
|
].join("\n");
|
|
556
1098
|
}
|
|
557
|
-
function
|
|
1099
|
+
function ft(e, t) {
|
|
558
1100
|
return [
|
|
559
1101
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
560
1102
|
"<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
561
1103
|
e.map((e) => {
|
|
562
|
-
let n = t ?
|
|
1104
|
+
let n = t ? st(e, t) : e;
|
|
563
1105
|
return n ? [
|
|
564
1106
|
" <sitemap>",
|
|
565
|
-
` <loc>${
|
|
1107
|
+
` <loc>${Q(n)}</loc>`,
|
|
566
1108
|
" </sitemap>"
|
|
567
1109
|
].join("\n") : "";
|
|
568
1110
|
}).filter(Boolean).join("\n"),
|
|
@@ -571,14 +1113,14 @@ function R(e, t) {
|
|
|
571
1113
|
}
|
|
572
1114
|
//#endregion
|
|
573
1115
|
//#region src/types.ts
|
|
574
|
-
var
|
|
1116
|
+
var pt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
575
1117
|
status;
|
|
576
1118
|
endpoint;
|
|
577
1119
|
body;
|
|
578
1120
|
constructor(e, t, n, r) {
|
|
579
1121
|
super(e), this.status = t, this.endpoint = n, this.body = r, this.name = "ApiError";
|
|
580
1122
|
}
|
|
581
|
-
},
|
|
1123
|
+
}, mt = (e) => e === 429 || e >= 500 && e <= 599, ht = (e) => new Promise((t) => setTimeout(t, e)), gt = class {
|
|
582
1124
|
baseUrl;
|
|
583
1125
|
token;
|
|
584
1126
|
vid;
|
|
@@ -630,7 +1172,7 @@ var z = /* @__PURE__ */ t({}), B = class extends Error {
|
|
|
630
1172
|
signal: n.signal
|
|
631
1173
|
});
|
|
632
1174
|
} catch (t) {
|
|
633
|
-
throw t instanceof Error && t.name === "AbortError" ? new
|
|
1175
|
+
throw t instanceof Error && t.name === "AbortError" ? new $(`Request timed out after ${this.timeoutMs}ms`, 0, e) : t;
|
|
634
1176
|
} finally {
|
|
635
1177
|
clearTimeout(r);
|
|
636
1178
|
}
|
|
@@ -641,8 +1183,8 @@ var z = /* @__PURE__ */ t({}), B = class extends Error {
|
|
|
641
1183
|
let n = await this.fetchWithTimeout(e);
|
|
642
1184
|
return await this.parseResponse(n, t);
|
|
643
1185
|
} catch (e) {
|
|
644
|
-
if (n = e, !(r < this.retries && (!(e instanceof
|
|
645
|
-
await
|
|
1186
|
+
if (n = e, !(r < this.retries && (!(e instanceof $) || e.status === 0 || mt(e.status)))) throw e;
|
|
1187
|
+
await ht(200 * 2 ** r);
|
|
646
1188
|
}
|
|
647
1189
|
throw n;
|
|
648
1190
|
}
|
|
@@ -677,7 +1219,7 @@ var z = /* @__PURE__ */ t({}), B = class extends Error {
|
|
|
677
1219
|
if (this.isFetchResponse(e)) {
|
|
678
1220
|
if (!e.ok) {
|
|
679
1221
|
let n = await this.readErrorBody(e);
|
|
680
|
-
throw new
|
|
1222
|
+
throw new $(`Request to "${t}" failed with status ${e.status}`, e.status, t, n);
|
|
681
1223
|
}
|
|
682
1224
|
return await e.json();
|
|
683
1225
|
}
|
|
@@ -744,6 +1286,6 @@ var z = /* @__PURE__ */ t({}), B = class extends Error {
|
|
|
744
1286
|
}
|
|
745
1287
|
};
|
|
746
1288
|
//#endregion
|
|
747
|
-
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 };
|
|
748
1290
|
|
|
749
1291
|
//# sourceMappingURL=index.mjs.map
|