@b10cks/client 1.10.0 → 1.12.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 +35 -5
- package/dist/index.cjs +45 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +116 -15
- package/dist/index.mjs +559 -118
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -53,15 +53,22 @@ function a(e) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
if (e.type === "asset") return;
|
|
56
|
-
let t = e.target ?? "_self", n = e.url ?? "";
|
|
57
|
-
|
|
56
|
+
let t = e.target ?? "_self", n = (e.url ?? "").trimEnd(), r = e.params ? new URLSearchParams(e.params).toString() : "";
|
|
57
|
+
if (r) {
|
|
58
|
+
let e = n.indexOf("#"), t = e === -1 ? n : n.slice(0, e), i = e === -1 ? "" : n.slice(e);
|
|
59
|
+
n = `${t}${t.includes("?") ? "&" : "?"}${r}${i}`;
|
|
60
|
+
}
|
|
61
|
+
return e.anchor && !n.includes("#") && (n = `${n}#${encodeURIComponent(e.anchor)}`), {
|
|
58
62
|
href: n,
|
|
59
63
|
target: t
|
|
60
64
|
};
|
|
61
65
|
}
|
|
66
|
+
function o(e) {
|
|
67
|
+
return e?.id ? { id: e.id } : {};
|
|
68
|
+
}
|
|
62
69
|
//#endregion
|
|
63
70
|
//#region src/data-api.ts
|
|
64
|
-
function
|
|
71
|
+
function s(e) {
|
|
65
72
|
if (e != null) {
|
|
66
73
|
if (typeof e == "boolean" || typeof e == "number") return String(e);
|
|
67
74
|
if (typeof e == "string") return e;
|
|
@@ -97,23 +104,23 @@ function o(e) {
|
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
|
-
function
|
|
107
|
+
function c(e) {
|
|
101
108
|
let t = {};
|
|
102
109
|
for (let [n, r] of Object.entries(e)) {
|
|
103
|
-
let e =
|
|
110
|
+
let e = s(r);
|
|
104
111
|
e !== void 0 && (t[n] = e);
|
|
105
112
|
}
|
|
106
113
|
return t;
|
|
107
114
|
}
|
|
108
|
-
function
|
|
109
|
-
let r = t && typeof t == "object" ?
|
|
115
|
+
function l(e, t, n) {
|
|
116
|
+
let r = t && typeof t == "object" ? c(t) : {}, i = Array.isArray(n) ? { sort: n.join(",") } : n == null ? {} : { sort: n };
|
|
110
117
|
return {
|
|
111
118
|
...e,
|
|
112
119
|
...r,
|
|
113
120
|
...i
|
|
114
121
|
};
|
|
115
122
|
}
|
|
116
|
-
var
|
|
123
|
+
var u = 128, d = class {
|
|
117
124
|
client;
|
|
118
125
|
redirectsCache = /* @__PURE__ */ new Map();
|
|
119
126
|
configCache = /* @__PURE__ */ new Map();
|
|
@@ -135,7 +142,7 @@ var l = 128, u = class {
|
|
|
135
142
|
}
|
|
136
143
|
async getContents(e = {}, t = {}) {
|
|
137
144
|
let { filter: n, sort: r, ...i } = e;
|
|
138
|
-
return this.getCollection("contents",
|
|
145
|
+
return this.getCollection("contents", l(i, n, r), t);
|
|
139
146
|
}
|
|
140
147
|
async getBreadcrumb(e, t = {}) {
|
|
141
148
|
return (await this.getBreadcrumbResponse(e, t))?.breadcrumb ?? [];
|
|
@@ -149,7 +156,7 @@ var l = 128, u = class {
|
|
|
149
156
|
}
|
|
150
157
|
async getBlocks(e = {}, t = {}) {
|
|
151
158
|
let { filter: n, ...r } = e;
|
|
152
|
-
return this.getCollection("blocks",
|
|
159
|
+
return this.getCollection("blocks", l(r, n, void 0), t);
|
|
153
160
|
}
|
|
154
161
|
async search(e) {
|
|
155
162
|
let t = await this.client.get("search", e);
|
|
@@ -191,7 +198,7 @@ var l = 128, u = class {
|
|
|
191
198
|
let e = this.redirectsCache.get(i);
|
|
192
199
|
if (e) return e;
|
|
193
200
|
}
|
|
194
|
-
let { filter: a, ...o } = e, s =
|
|
201
|
+
let { filter: a, ...o } = e, s = l(o, a, void 0), c = await this.getCollection("redirects", s, { allPages: n }), u = Object.fromEntries(c.map(({ source: e, target: t, status_code: n }) => [e, {
|
|
195
202
|
target: t,
|
|
196
203
|
status_code: n
|
|
197
204
|
}]));
|
|
@@ -225,7 +232,7 @@ var l = 128, u = class {
|
|
|
225
232
|
return r || this.configInflight.set(o, c), c;
|
|
226
233
|
}
|
|
227
234
|
setConfigCache(e, t) {
|
|
228
|
-
if (this.configCache.delete(e), this.configCache.set(e, t), this.configCache.size >
|
|
235
|
+
if (this.configCache.delete(e), this.configCache.set(e, t), this.configCache.size > u) {
|
|
229
236
|
let e = this.configCache.keys().next().value;
|
|
230
237
|
e !== void 0 && this.configCache.delete(e);
|
|
231
238
|
}
|
|
@@ -249,21 +256,22 @@ var l = 128, u = class {
|
|
|
249
256
|
return [];
|
|
250
257
|
}
|
|
251
258
|
};
|
|
252
|
-
function
|
|
253
|
-
return new
|
|
259
|
+
function f(e) {
|
|
260
|
+
return new d(e);
|
|
254
261
|
}
|
|
255
262
|
//#endregion
|
|
256
263
|
//#region src/preview-bridge.ts
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
"
|
|
263
|
-
"
|
|
264
|
-
|
|
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 = (e) => e.selectedItem === null || typeof e.selectedItem == "string", g = {
|
|
265
|
+
CONTENT_UPDATE: (e) => p(e.content),
|
|
266
|
+
CONTENT_PATCH: (e) => m(e.path) && "value" in e && (e.itemId === void 0 || typeof e.itemId == "string"),
|
|
267
|
+
SELECT_UPDATE: h,
|
|
268
|
+
HOVER_UPDATE: h,
|
|
269
|
+
BLOCK_LABELS: (e) => p(e.labels) && Object.values(e.labels).every((e) => typeof e == "string"),
|
|
270
|
+
HIDDEN_BLOCKS: (e) => Array.isArray(e.ids) && e.ids.every((e) => typeof e == "string")
|
|
271
|
+
}, _ = (e) => typeof e == "string" && Object.hasOwn(g, e), ee = "B10CKS_BRIDGE_READY", te = 2, ne = class e {
|
|
265
272
|
static instance;
|
|
266
273
|
listeners = {};
|
|
274
|
+
received = {};
|
|
267
275
|
initialized = !1;
|
|
268
276
|
allowedOrigins = null;
|
|
269
277
|
parentOrigin = null;
|
|
@@ -277,12 +285,15 @@ var f = /* @__PURE__ */ new Set([
|
|
|
277
285
|
e.allowedOrigins && !this.allowedOrigins && (this.allowedOrigins = e.allowedOrigins, this.parentOrigin && !this.allowedOrigins.includes(this.parentOrigin) && (this.parentOrigin = null));
|
|
278
286
|
return;
|
|
279
287
|
}
|
|
280
|
-
this.allowedOrigins = e.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({
|
|
288
|
+
this.allowedOrigins = e.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({
|
|
289
|
+
type: ee,
|
|
290
|
+
payload: { protocol: 2 }
|
|
291
|
+
}, "*");
|
|
281
292
|
}
|
|
282
293
|
}
|
|
283
294
|
destroy() {
|
|
284
295
|
this.initialized && typeof window < "u" && window.removeEventListener("message", this.handleMessage), this.initialized = !1, this.parentOrigin = null;
|
|
285
|
-
for (let e of Object.keys(this.listeners)) this.listeners[e]?.clear();
|
|
296
|
+
for (let e of Object.keys(this.listeners)) this.listeners[e]?.clear(), delete this.received[e];
|
|
286
297
|
}
|
|
287
298
|
isInPreviewMode() {
|
|
288
299
|
return typeof window < "u" && window.self !== window.top;
|
|
@@ -294,6 +305,9 @@ var f = /* @__PURE__ */ new Set([
|
|
|
294
305
|
n.delete(t);
|
|
295
306
|
};
|
|
296
307
|
}
|
|
308
|
+
latest(e) {
|
|
309
|
+
return this.received[e];
|
|
310
|
+
}
|
|
297
311
|
selectItem(e) {
|
|
298
312
|
this.post("SELECT_UPDATE", { selectedItem: e });
|
|
299
313
|
}
|
|
@@ -317,6 +331,19 @@ var f = /* @__PURE__ */ new Set([
|
|
|
317
331
|
value: n
|
|
318
332
|
});
|
|
319
333
|
}
|
|
334
|
+
blockAction(e, t) {
|
|
335
|
+
this.post("BLOCK_ACTION", {
|
|
336
|
+
itemId: e,
|
|
337
|
+
action: t
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
moveBlock(e, t, n) {
|
|
341
|
+
this.post("BLOCK_MOVE", {
|
|
342
|
+
itemId: e,
|
|
343
|
+
targetId: t,
|
|
344
|
+
position: n
|
|
345
|
+
});
|
|
346
|
+
}
|
|
320
347
|
post(e, t) {
|
|
321
348
|
this.isInPreviewMode() && window.parent.postMessage({
|
|
322
349
|
type: e,
|
|
@@ -326,87 +353,495 @@ var f = /* @__PURE__ */ new Set([
|
|
|
326
353
|
handleMessage = (e) => {
|
|
327
354
|
if (!this.isOriginTrusted(e.origin) || !e.data || typeof e.data != "object") return;
|
|
328
355
|
let { type: t, payload: n } = e.data;
|
|
329
|
-
|
|
356
|
+
_(t) && p(n) && g[t](n) && (!this.parentOrigin && e.origin && e.origin !== "null" && (this.parentOrigin = e.origin), this.notify(t, n));
|
|
330
357
|
};
|
|
331
358
|
isOriginTrusted(e) {
|
|
332
359
|
return this.parentOrigin ? e === this.parentOrigin : !this.allowedOrigins || this.allowedOrigins.includes(e);
|
|
333
360
|
}
|
|
334
361
|
notify(e, t) {
|
|
362
|
+
this.received[e] = t;
|
|
335
363
|
let n = this.listeners[e];
|
|
336
364
|
if (n) for (let e of n) e(t);
|
|
337
365
|
}
|
|
338
|
-
},
|
|
339
|
-
|
|
340
|
-
|
|
366
|
+
}, v = ne.getInstance(), y = "rgb(59, 130, 246)", re = 2, ie = `
|
|
367
|
+
:host { all: initial; position: fixed; inset: 0; pointer-events: none; z-index: 2147483647; }
|
|
368
|
+
[hidden] { display: none !important; }
|
|
369
|
+
.box {
|
|
370
|
+
position: fixed; top: 0; left: 0; box-sizing: border-box;
|
|
371
|
+
border: ${re}px solid ${y}; border-radius: 2px;
|
|
372
|
+
}
|
|
373
|
+
.box.hover { border-style: dashed; border-color: rgba(59, 130, 246, 0.6); }
|
|
374
|
+
.label {
|
|
375
|
+
position: absolute; left: 6px; bottom: 100%; margin-bottom: ${re}px;
|
|
376
|
+
display: flex; align-items: center; padding: 0 6px; border-radius: 3px 3px 0 0; white-space: nowrap;
|
|
377
|
+
font: 500 11px/16px system-ui, -apple-system, sans-serif;
|
|
378
|
+
color: #fff; background: ${y};
|
|
379
|
+
}
|
|
380
|
+
.label:empty, .name:empty, .crumbs:empty { display: none; }
|
|
381
|
+
.box.hover .label { background: rgba(59, 130, 246, 0.8); }
|
|
382
|
+
.box[data-inside] .label { bottom: auto; top: 0; margin: 0; border-radius: 0 0 3px 3px; }
|
|
383
|
+
.bar { pointer-events: auto; line-height: 20px; padding-right: 2px; user-select: none; -webkit-user-select: none; }
|
|
384
|
+
.crumbs { display: flex; align-items: center; }
|
|
385
|
+
.crumb { all: unset; cursor: pointer; opacity: 0.75; max-width: 12em; overflow: hidden; text-overflow: ellipsis; border-radius: 2px; }
|
|
386
|
+
.crumb:hover { opacity: 1; text-decoration: underline; }
|
|
387
|
+
.sep, .more { opacity: 0.6; padding: 0 4px; }
|
|
388
|
+
.name { max-width: 16em; overflow: hidden; text-overflow: ellipsis; }
|
|
389
|
+
.tools { display: flex; margin-left: 6px; padding-left: 2px; border-left: 1px solid rgba(255, 255, 255, 0.35); }
|
|
390
|
+
.tool {
|
|
391
|
+
all: unset; box-sizing: border-box; display: grid; place-items: center;
|
|
392
|
+
width: 20px; height: 20px; border-radius: 2px; cursor: pointer;
|
|
393
|
+
}
|
|
394
|
+
.tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
|
|
395
|
+
.tool[aria-pressed='true'] { background: rgba(255, 255, 255, 0.3); }
|
|
396
|
+
.tool:disabled { opacity: 0.4; cursor: default; }
|
|
397
|
+
.tool svg { width: 14px; height: 14px; }
|
|
398
|
+
.handle { cursor: grab; touch-action: none; }
|
|
399
|
+
:host([data-dragging]) .handle { cursor: grabbing; }
|
|
400
|
+
.crumb:focus-visible, .tool:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
|
|
401
|
+
.indicator {
|
|
402
|
+
position: fixed; top: 0; left: 0; border-radius: 2px;
|
|
403
|
+
background: ${y}; box-shadow: 0 0 0 1px #fff;
|
|
404
|
+
}
|
|
405
|
+
`, ae = [
|
|
406
|
+
{
|
|
407
|
+
action: "move-up",
|
|
408
|
+
label: "Move up",
|
|
409
|
+
icon: "<path d=\"M12 19V5M6 11l6-6 6 6\"/>"
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
action: "move-down",
|
|
413
|
+
label: "Move down",
|
|
414
|
+
icon: "<path d=\"M12 5v14M6 13l6 6 6-6\"/>"
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
action: "insert-before",
|
|
418
|
+
label: "Add block before",
|
|
419
|
+
icon: "<path d=\"M4 4h16M12 9v10M7 14h10\"/>"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
action: "insert-after",
|
|
423
|
+
label: "Add block after",
|
|
424
|
+
icon: "<path d=\"M4 20h16M12 5v10M7 10h10\"/>"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
action: "duplicate",
|
|
428
|
+
label: "Duplicate",
|
|
429
|
+
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\"/>"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
action: "delete",
|
|
433
|
+
label: "Delete",
|
|
434
|
+
icon: "<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>"
|
|
435
|
+
}
|
|
436
|
+
], oe = "<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\"/>", se = "<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\"/>", ce = "<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>", le = "Alt/Option-click to use links and buttons on the page";
|
|
437
|
+
function ue(e) {
|
|
438
|
+
let t = document.createElement("div");
|
|
439
|
+
t.id = "b10cks-overlay";
|
|
440
|
+
let n = t.attachShadow({ mode: "open" }), r = document.createElement("style");
|
|
441
|
+
r.textContent = ie, n.appendChild(r);
|
|
442
|
+
let i = b("div", "box hover");
|
|
443
|
+
i.hidden = !0;
|
|
444
|
+
let a = b("div", "label name");
|
|
445
|
+
i.appendChild(a);
|
|
446
|
+
let o = b("div", "box selected");
|
|
447
|
+
o.hidden = !0;
|
|
448
|
+
let s = b("div", "label bar"), c = b("span", "crumbs"), l = b("span", "name");
|
|
449
|
+
l.title = le;
|
|
450
|
+
let u = b("div", "tools");
|
|
451
|
+
u.setAttribute("role", "toolbar"), u.setAttribute("aria-label", "Block actions");
|
|
452
|
+
let d = b("div", "tool handle");
|
|
453
|
+
d.title = "Drag to move", d.setAttribute("aria-hidden", "true"), d.innerHTML = x(ce), d.addEventListener("pointerdown", (t) => e.onDragStart(t, d)), u.appendChild(d);
|
|
454
|
+
let f = /* @__PURE__ */ new Map();
|
|
455
|
+
for (let t of ae) {
|
|
456
|
+
let n = b("button", "tool");
|
|
457
|
+
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
|
+
}
|
|
459
|
+
let p = !1, m = b("button", "tool");
|
|
460
|
+
m.type = "button", m.addEventListener("click", () => e.onAction(p ? "show" : "hide"));
|
|
461
|
+
let h = (e) => {
|
|
462
|
+
p = e;
|
|
463
|
+
let t = p ? "Show" : "Hide";
|
|
464
|
+
m.title = t, m.setAttribute("aria-label", t), m.setAttribute("aria-pressed", String(p)), m.innerHTML = x(p ? se : oe);
|
|
465
|
+
};
|
|
466
|
+
h(!1), u.insertBefore(m, f.get("delete") ?? null), s.append(c, l, u), o.appendChild(s);
|
|
467
|
+
let g = b("div", "indicator");
|
|
468
|
+
g.hidden = !0, n.append(i, o, g), document.body.appendChild(t);
|
|
469
|
+
let _ = "";
|
|
470
|
+
return {
|
|
471
|
+
host: t,
|
|
472
|
+
selected: {
|
|
473
|
+
box: o,
|
|
474
|
+
label: s,
|
|
475
|
+
name: l
|
|
476
|
+
},
|
|
477
|
+
hover: {
|
|
478
|
+
box: i,
|
|
479
|
+
label: a,
|
|
480
|
+
name: a
|
|
481
|
+
},
|
|
482
|
+
indicator: g,
|
|
483
|
+
renderBar(t) {
|
|
484
|
+
if (s.hidden = !t || !t.label && t.crumbs.length === 0 && !t.actions, !t) return;
|
|
485
|
+
let n = t.crumbs.map((e) => `${e.id}\u0000${e.label}`).join("");
|
|
486
|
+
n !== _ && (_ = n, c.replaceChildren(...de(t.crumbs, e.onSelect))), l.textContent = t.label, u.hidden = !t.actions, pe(f.get("move-up"), !t.actions?.canMoveUp), pe(f.get("move-down"), !t.actions?.canMoveDown);
|
|
487
|
+
let r = t.actions?.hidden ?? null;
|
|
488
|
+
m.hidden = r === null, r !== null && r !== p && h(r);
|
|
489
|
+
},
|
|
490
|
+
setDragging(e) {
|
|
491
|
+
t.toggleAttribute("data-dragging", e);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function de(e, t) {
|
|
496
|
+
let n = [], r = e.slice(0, -3);
|
|
497
|
+
if (r.length > 0) {
|
|
498
|
+
let e = b("span", "more");
|
|
499
|
+
e.textContent = "…", e.title = r.map((e) => e.label).join(" › "), n.push(e, fe());
|
|
500
|
+
}
|
|
501
|
+
for (let r of e.slice(-3)) {
|
|
502
|
+
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, fe());
|
|
504
|
+
}
|
|
505
|
+
return n;
|
|
506
|
+
}
|
|
507
|
+
function fe() {
|
|
508
|
+
let e = b("span", "sep");
|
|
509
|
+
return e.textContent = "›", e.setAttribute("aria-hidden", "true"), e;
|
|
510
|
+
}
|
|
511
|
+
function pe(e, t) {
|
|
512
|
+
e && (e.disabled = t);
|
|
513
|
+
}
|
|
514
|
+
function b(e, t) {
|
|
515
|
+
let n = document.createElement(e);
|
|
516
|
+
return n.className = t, n;
|
|
517
|
+
}
|
|
518
|
+
function x(e) {
|
|
519
|
+
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>`;
|
|
520
|
+
}
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/preview-overlay.ts
|
|
523
|
+
var S = {
|
|
524
|
+
selected: "b10cks-selected",
|
|
525
|
+
hover: "b10cks-hover"
|
|
526
|
+
}, C = "b10cks-hidden", w = 2, me = 24, T = 3, E = /* @__PURE__ */ new Map(), D = {
|
|
527
|
+
selected: null,
|
|
528
|
+
hover: null
|
|
529
|
+
}, O = null, k = null, A = null, j = null, M = null, N = !1, P = !1, F = !1, I = null;
|
|
530
|
+
function he(e, t) {
|
|
531
|
+
return E.set(e, t), t.kind === "block" && e.classList.toggle(C, Ie(t.id) === !0), k ||= ge(), t.kind === "block" && t.id === O && G(), () => {
|
|
532
|
+
if (E.get(e) === t) {
|
|
533
|
+
E.delete(e), t.kind === "block" && e.classList.remove(C);
|
|
534
|
+
for (let t of ["selected", "hover"]) D[t] === e && (D[t] = null, e.classList.remove(S[t]));
|
|
535
|
+
E.size === 0 ? (k?.(), k = null) : G();
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
function ge() {
|
|
540
|
+
O = v.latest("SELECT_UPDATE")?.selectedItem ?? O, O && G();
|
|
541
|
+
let e = v.on("SELECT_UPDATE", ({ selectedItem: e }) => {
|
|
542
|
+
O = e || null;
|
|
543
|
+
let t = D.selected && E.get(D.selected);
|
|
544
|
+
(t?.kind !== "field" || e && e !== t.id) && K("selected", B(O));
|
|
545
|
+
}), t = v.on("HOVER_UPDATE", ({ selectedItem: e }) => {
|
|
546
|
+
K("hover", B(e || null));
|
|
547
|
+
}), n = v.on("BLOCK_LABELS", q), r = v.on("HIDDEN_BLOCKS", ({ ids: e }) => {
|
|
548
|
+
let t = new Set(e);
|
|
549
|
+
for (let [e, n] of E) n.kind === "block" && e.classList.toggle(C, t.has(n.id));
|
|
550
|
+
q();
|
|
551
|
+
}), i = {
|
|
552
|
+
capture: !0,
|
|
553
|
+
passive: !0
|
|
554
|
+
};
|
|
555
|
+
return window.addEventListener("click", L, !0), window.addEventListener("auxclick", L, !0), window.addEventListener("keydown", _e, !0), document.addEventListener("pointerover", xe, !0), document.addEventListener("pointerout", Se, !0), window.addEventListener("scroll", J, i), window.addEventListener("resize", J), j = typeof ResizeObserver > "u" ? null : new ResizeObserver(J), M = typeof MutationObserver > "u" ? null : new MutationObserver(q), () => {
|
|
556
|
+
W(), e(), t(), n(), r(), window.removeEventListener("click", L, !0), window.removeEventListener("auxclick", L, !0), window.removeEventListener("keydown", _e, !0), document.removeEventListener("pointerover", xe, !0), document.removeEventListener("pointerout", Se, !0), window.removeEventListener("scroll", J, i), window.removeEventListener("resize", J), j?.disconnect(), j = null, M?.disconnect(), M = null, D.selected = null, D.hover = null, A?.host.remove(), A = null;
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
function L(e) {
|
|
560
|
+
if (e.altKey) return;
|
|
561
|
+
let t = Ce(e);
|
|
562
|
+
t && (R(e), e.type === "click" && z(t, e));
|
|
563
|
+
}
|
|
564
|
+
function _e(e) {
|
|
565
|
+
if (I) {
|
|
566
|
+
e.key === "Escape" && (R(e), W());
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
let t = D.selected;
|
|
570
|
+
if (!t?.isConnected || e.defaultPrevented || ve(e) || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
571
|
+
let n = null;
|
|
572
|
+
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
|
+
}
|
|
574
|
+
function ve(e) {
|
|
575
|
+
let t = e.composedPath()[0];
|
|
576
|
+
return t instanceof HTMLElement && (t.isContentEditable || t.matches("input, textarea, select"));
|
|
577
|
+
}
|
|
578
|
+
function R(e) {
|
|
579
|
+
e.preventDefault(), e.stopImmediatePropagation();
|
|
580
|
+
}
|
|
581
|
+
function z(e, t) {
|
|
582
|
+
let n = E.get(e);
|
|
583
|
+
n && (n.activate(t), n.kind === "block" && (O = n.id), K("selected", e));
|
|
584
|
+
}
|
|
585
|
+
function ye(e) {
|
|
586
|
+
let t = B(e);
|
|
587
|
+
t && z(t);
|
|
588
|
+
}
|
|
589
|
+
function be(e) {
|
|
590
|
+
let t = D.selected && E.get(D.selected);
|
|
591
|
+
t?.kind === "block" && v.blockAction(t.id, e);
|
|
592
|
+
}
|
|
593
|
+
function xe(e) {
|
|
594
|
+
K("hover", Ce(e));
|
|
595
|
+
}
|
|
596
|
+
function Se(e) {
|
|
597
|
+
e.relatedTarget || K("hover", null);
|
|
598
|
+
}
|
|
599
|
+
function Ce(e) {
|
|
600
|
+
for (let t of e.composedPath()) if (t instanceof HTMLElement && E.has(t)) return t;
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
function B(e) {
|
|
604
|
+
if (!e) return null;
|
|
605
|
+
let t = null;
|
|
606
|
+
for (let [n, r] of E) r.kind === "block" && r.id === e && n.isConnected && (!t || t.contains(n)) && (t = n);
|
|
607
|
+
return t;
|
|
608
|
+
}
|
|
609
|
+
function V(e) {
|
|
610
|
+
if (e.parentElement) return e.parentElement;
|
|
611
|
+
let t = e.parentNode;
|
|
612
|
+
return t instanceof ShadowRoot ? t.host : null;
|
|
613
|
+
}
|
|
614
|
+
function H(e) {
|
|
615
|
+
let t = [], n = E.get(e), r = n?.kind === "block" ? n.id : null;
|
|
616
|
+
for (let n = V(e); n; n = V(n)) {
|
|
617
|
+
if (!(n instanceof HTMLElement)) continue;
|
|
618
|
+
let e = E.get(n);
|
|
619
|
+
e?.kind === "block" && e.id !== r && (t.push(n), r = e.id);
|
|
620
|
+
}
|
|
621
|
+
return t;
|
|
622
|
+
}
|
|
623
|
+
function we(e) {
|
|
624
|
+
let t = H(e)[0];
|
|
625
|
+
return (t && E.get(t)?.id) ?? null;
|
|
626
|
+
}
|
|
627
|
+
function U(e, t) {
|
|
628
|
+
let n = E.get(e);
|
|
629
|
+
if (n?.kind !== "block") return null;
|
|
630
|
+
let r = we(e), i = t === 1 ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING, a = null;
|
|
631
|
+
for (let [t, o] of E) o.kind === "block" && o.id !== n.id && t.isConnected && e.compareDocumentPosition(t) & i && (!a || t.compareDocumentPosition(a) & i) && we(t) === r && (a = t);
|
|
632
|
+
return a && B(E.get(a)?.id ?? null);
|
|
633
|
+
}
|
|
634
|
+
function Te(e) {
|
|
635
|
+
let t = E.get(e);
|
|
636
|
+
if (!t) return null;
|
|
637
|
+
let n = H(e).reverse().flatMap((e) => {
|
|
638
|
+
let t = E.get(e);
|
|
639
|
+
return t ? [{
|
|
640
|
+
id: t.id,
|
|
641
|
+
label: Y(t) || "Block"
|
|
642
|
+
}] : [];
|
|
643
|
+
});
|
|
644
|
+
return {
|
|
645
|
+
label: Y(t),
|
|
646
|
+
crumbs: n,
|
|
647
|
+
actions: t.kind === "block" && Fe() ? {
|
|
648
|
+
canMoveUp: !!U(e, -1),
|
|
649
|
+
canMoveDown: !!U(e, 1),
|
|
650
|
+
hidden: Ie(t.id)
|
|
651
|
+
} : null
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
function Ee(e, t) {
|
|
655
|
+
let n = D.selected, r = n && E.get(n);
|
|
656
|
+
n && r?.kind === "block" && e.button === 0 && (e.preventDefault(), e.isTrusted && t.setPointerCapture(e.pointerId), I = {
|
|
657
|
+
id: r.id,
|
|
658
|
+
el: n,
|
|
659
|
+
drop: null
|
|
660
|
+
}, A?.setDragging(!0), window.addEventListener("pointermove", De, !0), window.addEventListener("pointerup", Oe, !0), window.addEventListener("pointercancel", W, !0));
|
|
661
|
+
}
|
|
662
|
+
function De(e) {
|
|
663
|
+
I && (I.drop = ke(I, e.clientX, e.clientY), K("hover", I.drop?.el ?? null), J());
|
|
664
|
+
}
|
|
665
|
+
function Oe(e) {
|
|
666
|
+
let t = I, n = t && ke(t, e.clientX, e.clientY);
|
|
667
|
+
W(), t && n && v.moveBlock(t.id, n.id, n.position);
|
|
668
|
+
}
|
|
669
|
+
function W() {
|
|
670
|
+
I && (I = null, window.removeEventListener("pointermove", De, !0), window.removeEventListener("pointerup", Oe, !0), window.removeEventListener("pointercancel", W, !0), A?.setDragging(!1), K("hover", null), J());
|
|
671
|
+
}
|
|
672
|
+
function ke(e, t, n) {
|
|
673
|
+
let r = document.elementsFromPoint(t, n).find((e) => e !== A?.host), i = null;
|
|
674
|
+
for (let t = r ?? null; t; t = V(t)) {
|
|
675
|
+
if (!(t instanceof HTMLElement)) continue;
|
|
676
|
+
let n = E.get(t);
|
|
677
|
+
if (n?.kind === "block") {
|
|
678
|
+
if (n.id === e.id) return null;
|
|
679
|
+
i ??= t;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
let a = i && E.get(i);
|
|
683
|
+
if (!i || !a || i.contains(e.el)) return null;
|
|
684
|
+
let o = i.getBoundingClientRect(), s = e.drop?.el === i ? e.drop.horizontal : Ae(i, o), c = s ? t < o.left + o.width / 2 : n < o.top + o.height / 2;
|
|
685
|
+
return {
|
|
686
|
+
el: i,
|
|
687
|
+
id: a.id,
|
|
688
|
+
position: c ? "before" : "after",
|
|
689
|
+
horizontal: s
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function Ae(e, t) {
|
|
693
|
+
let n = U(e, 1) ?? U(e, -1);
|
|
694
|
+
if (!n) return !1;
|
|
695
|
+
let r = n.getBoundingClientRect();
|
|
696
|
+
return r.top < t.bottom && r.bottom > t.top;
|
|
697
|
+
}
|
|
698
|
+
function G() {
|
|
699
|
+
P || (P = !0, queueMicrotask(() => {
|
|
700
|
+
P = !1;
|
|
701
|
+
let e = D.selected;
|
|
702
|
+
e?.isConnected && E.get(e)?.kind === "field" || K("selected", B(O));
|
|
703
|
+
}));
|
|
704
|
+
}
|
|
705
|
+
function K(e, t) {
|
|
706
|
+
let n = D[e];
|
|
707
|
+
n !== t && (D[e] = t, n && (n.classList.remove(S[e]), je(n, e, !1)), t && (t.classList.add(S[e]), je(t, e, !0), e === "selected" && E.get(t)?.scrollOnSelect && t.scrollIntoView?.({
|
|
708
|
+
block: "nearest",
|
|
709
|
+
behavior: "smooth"
|
|
710
|
+
})), j && (j.disconnect(), j.observe(document.documentElement), D.selected && j.observe(D.selected), D.hover && j.observe(D.hover)), e === "selected" && (M?.disconnect(), t && M?.observe(document.body, {
|
|
711
|
+
childList: !0,
|
|
712
|
+
subtree: !0
|
|
713
|
+
}), F = !0), J());
|
|
714
|
+
}
|
|
715
|
+
function je(e, t, n) {
|
|
716
|
+
let r = E.get(e);
|
|
717
|
+
t === "selected" ? r?.onSelectChange?.(n) : r?.onHoverChange?.(n);
|
|
718
|
+
}
|
|
719
|
+
function q() {
|
|
720
|
+
F = !0, J();
|
|
721
|
+
}
|
|
722
|
+
function J() {
|
|
723
|
+
N || (N = !0, requestAnimationFrame(() => {
|
|
724
|
+
N = !1, Me();
|
|
725
|
+
}));
|
|
726
|
+
}
|
|
727
|
+
function Me() {
|
|
728
|
+
if (!k) return;
|
|
729
|
+
let { selected: e } = D, t = D.hover === e ? null : D.hover;
|
|
730
|
+
if (!A && !e && !t) return;
|
|
731
|
+
A ??= ue({
|
|
732
|
+
onAction: be,
|
|
733
|
+
onSelect: ye,
|
|
734
|
+
onDragStart: Ee
|
|
735
|
+
}), F && (F = !1, A.renderBar(e?.isConnected ? Te(e) : null));
|
|
736
|
+
let n = Y(t ? E.get(t) : void 0);
|
|
737
|
+
A.hover.name.textContent !== n && (A.hover.name.textContent = n), Ne(A.selected, e), Ne(A.hover, t), Pe(A.indicator, I?.drop ?? null);
|
|
738
|
+
}
|
|
739
|
+
function Ne(e, t) {
|
|
740
|
+
if (!t?.isConnected) {
|
|
741
|
+
e.box.hidden = !0;
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
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 - w}px, ${i.top - w}px)`, n.style.width = `${i.width + 4}px`, n.style.height = `${i.height + 4}px`;
|
|
746
|
+
let c = i.top < me;
|
|
747
|
+
n.toggleAttribute("data-inside", c);
|
|
748
|
+
let l = Math.min(w - i.top, i.height + 4 - o);
|
|
749
|
+
r.style.top = c ? `${Math.max(0, l)}px` : "";
|
|
750
|
+
let u = i.left - w + 8, d = u + a - s;
|
|
751
|
+
r.style.marginLeft = d > 0 ? `${-Math.min(d, u)}px` : "";
|
|
752
|
+
}
|
|
753
|
+
function Pe(e, t) {
|
|
754
|
+
if (!t?.el.isConnected) {
|
|
755
|
+
e.hidden = !0;
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
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) - T / 2}px, ${n.top}px)`, i.width = `${T}px`, i.height = `${n.height}px`;
|
|
760
|
+
else {
|
|
761
|
+
let e = r ? n.top : n.bottom;
|
|
762
|
+
i.transform = `translate(${n.left}px, ${e - T / 2}px)`, i.width = `${n.width}px`, i.height = `${T}px`;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function Fe() {
|
|
766
|
+
return v.latest("BLOCK_LABELS") !== void 0;
|
|
767
|
+
}
|
|
768
|
+
function Ie(e) {
|
|
769
|
+
return v.latest("HIDDEN_BLOCKS")?.ids.includes(e) ?? null;
|
|
770
|
+
}
|
|
771
|
+
function Y(e) {
|
|
772
|
+
let t = e?.label;
|
|
773
|
+
return t ? (e.kind === "block" ? v.latest("BLOCK_LABELS")?.labels[t] : void 0) ?? Le(t) : "";
|
|
774
|
+
}
|
|
775
|
+
function Le(e) {
|
|
776
|
+
if (!e) return "";
|
|
777
|
+
if (!/^[a-z][a-z0-9]*([_-][a-z0-9]+)*$/.test(e)) return e;
|
|
778
|
+
let t = e.replace(/[_-]+/g, " ");
|
|
779
|
+
return t.charAt(0).toUpperCase() + t.slice(1);
|
|
780
|
+
}
|
|
781
|
+
//#endregion
|
|
782
|
+
//#region src/editable.ts
|
|
783
|
+
var Re = "b10cks-preview-style", ze = "--b10cks-scroll-offset";
|
|
784
|
+
function X() {
|
|
785
|
+
if (typeof document > "u" || document.getElementById(Re)) return;
|
|
341
786
|
let e = document.createElement("style");
|
|
342
|
-
e.id =
|
|
343
|
-
.b10cks-preview { scroll-margin-top: var(${
|
|
344
|
-
.b10cks-
|
|
345
|
-
.b10cks-preview:hover {
|
|
346
|
-
outline: 2px dashed rgba(59, 130, 246, 0.5);
|
|
347
|
-
outline-offset: 2px;
|
|
348
|
-
}
|
|
349
|
-
.b10cks-selected {
|
|
350
|
-
outline: 2px solid rgb(59, 130, 246) !important;
|
|
351
|
-
outline-offset: 2px;
|
|
352
|
-
}
|
|
787
|
+
e.id = Re, e.textContent = `
|
|
788
|
+
.b10cks-preview { scroll-margin-top: var(${ze}, 0px); }
|
|
789
|
+
.b10cks-preview.b10cks-hidden { opacity: 0.4 !important; }
|
|
353
790
|
`, document.head.appendChild(e);
|
|
354
791
|
}
|
|
355
|
-
function
|
|
792
|
+
function Be(e) {
|
|
356
793
|
if (typeof document > "u") return;
|
|
357
794
|
let t = typeof e == "number" ? `${e}px` : e;
|
|
358
|
-
document.documentElement.style.setProperty(
|
|
795
|
+
document.documentElement.style.setProperty(ze, t);
|
|
359
796
|
}
|
|
360
|
-
function
|
|
361
|
-
if (!
|
|
362
|
-
|
|
363
|
-
let { id: n,
|
|
797
|
+
function Ve(e, t) {
|
|
798
|
+
if (!v.isInPreviewMode() || !t.id) return () => {};
|
|
799
|
+
X();
|
|
800
|
+
let { id: n, label: r, onSelectChange: i, onHoverChange: a, scrollOnSelect: o = !0 } = t;
|
|
364
801
|
e.classList.add("b10cks-preview");
|
|
365
|
-
let
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
};
|
|
374
|
-
e.addEventListener("click", o);
|
|
375
|
-
let l = h.on("SELECT_UPDATE", s), u = h.on("HOVER_UPDATE", c);
|
|
802
|
+
let s = he(e, {
|
|
803
|
+
id: n,
|
|
804
|
+
kind: "block",
|
|
805
|
+
label: r,
|
|
806
|
+
scrollOnSelect: o,
|
|
807
|
+
onSelectChange: i,
|
|
808
|
+
onHoverChange: a,
|
|
809
|
+
activate: () => v.selectItem(n)
|
|
810
|
+
});
|
|
376
811
|
return () => {
|
|
377
|
-
|
|
812
|
+
s(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
378
813
|
};
|
|
379
814
|
}
|
|
380
|
-
function
|
|
381
|
-
if (!
|
|
382
|
-
let { id: n, field: r, path: i, mode: a = "inline" } = t;
|
|
815
|
+
function He(e, t) {
|
|
816
|
+
if (!v.isInPreviewMode() || !t.id) return () => {};
|
|
817
|
+
let { id: n, field: r, path: i, mode: a = "inline", label: o } = t;
|
|
383
818
|
if (a === "select") {
|
|
384
|
-
|
|
385
|
-
let t = (e
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
819
|
+
X(), e.classList.add("b10cks-preview");
|
|
820
|
+
let t = he(e, {
|
|
821
|
+
id: n,
|
|
822
|
+
kind: "field",
|
|
823
|
+
label: o ?? Ue(i) ?? r,
|
|
824
|
+
activate: () => i ? v.selectField(n, i) : v.selectItem(n)
|
|
825
|
+
});
|
|
826
|
+
return () => {
|
|
827
|
+
t(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
390
828
|
};
|
|
391
829
|
}
|
|
392
830
|
e.setAttribute("contenteditable", "true");
|
|
393
|
-
let
|
|
831
|
+
let s = (e) => {
|
|
394
832
|
let t = e.target.innerText;
|
|
395
|
-
i ?
|
|
833
|
+
i ? v.updateFieldAt(n, i, t) : v.updateField(n, r ?? "", t);
|
|
396
834
|
};
|
|
397
|
-
return e.addEventListener("input",
|
|
398
|
-
e.removeEventListener("input",
|
|
835
|
+
return e.addEventListener("input", s), () => {
|
|
836
|
+
e.removeEventListener("input", s), e.removeAttribute("contenteditable");
|
|
399
837
|
};
|
|
400
838
|
}
|
|
401
|
-
function
|
|
402
|
-
typeof e
|
|
403
|
-
block: "nearest",
|
|
404
|
-
behavior: "smooth"
|
|
405
|
-
});
|
|
839
|
+
function Ue(e) {
|
|
840
|
+
return e?.findLast((e) => typeof e == "string");
|
|
406
841
|
}
|
|
407
842
|
//#endregion
|
|
408
843
|
//#region src/preview-store.ts
|
|
409
|
-
function
|
|
844
|
+
function We(e, t) {
|
|
410
845
|
let n = e;
|
|
411
846
|
for (let e of t) {
|
|
412
847
|
if (typeof n != "object" || !n) return;
|
|
@@ -414,18 +849,18 @@ function C(e, t) {
|
|
|
414
849
|
}
|
|
415
850
|
return n;
|
|
416
851
|
}
|
|
417
|
-
function
|
|
852
|
+
function Z(e, t, n) {
|
|
418
853
|
if (t.length === 0) return n;
|
|
419
854
|
let [r, ...i] = t;
|
|
420
855
|
if (r === void 0) return n;
|
|
421
856
|
if (typeof r == "number") {
|
|
422
857
|
let t = Array.isArray(e) ? e.slice() : [];
|
|
423
|
-
return t[r] =
|
|
858
|
+
return t[r] = Z(t[r], i, n), t;
|
|
424
859
|
}
|
|
425
860
|
let a = e && typeof e == "object" && !Array.isArray(e) ? { ...e } : {};
|
|
426
|
-
return a[r] =
|
|
861
|
+
return a[r] = Z(a[r], i, n), a;
|
|
427
862
|
}
|
|
428
|
-
function
|
|
863
|
+
function Q(e, t) {
|
|
429
864
|
let n = (e, r) => {
|
|
430
865
|
if (Array.isArray(e)) {
|
|
431
866
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -448,16 +883,16 @@ function T(e, t) {
|
|
|
448
883
|
};
|
|
449
884
|
return n(e, []);
|
|
450
885
|
}
|
|
451
|
-
function
|
|
886
|
+
function Ge(e, t) {
|
|
452
887
|
if (!t || typeof t != "object") return e;
|
|
453
888
|
let n = typeof t.id == "string" ? t.id : void 0;
|
|
454
889
|
if (!n || !e || typeof e != "object") return t;
|
|
455
890
|
let r = e, i = typeof r.id == "string" ? r.id : void 0;
|
|
456
891
|
if (i === n) return t;
|
|
457
|
-
let a =
|
|
458
|
-
return a ?
|
|
892
|
+
let a = Q(e, n);
|
|
893
|
+
return a ? Z(e, a, t) : !i && r.block !== void 0 && r.block === t.block ? t : e;
|
|
459
894
|
}
|
|
460
|
-
var
|
|
895
|
+
var Ke = class {
|
|
461
896
|
content;
|
|
462
897
|
listeners = /* @__PURE__ */ new Set();
|
|
463
898
|
constructor(e) {
|
|
@@ -471,21 +906,27 @@ var D = class {
|
|
|
471
906
|
this.content = e, this.emit();
|
|
472
907
|
}
|
|
473
908
|
applyContentUpdate(e) {
|
|
474
|
-
let t =
|
|
909
|
+
let t = Ge(this.content, e);
|
|
475
910
|
t !== this.content && (this.content = t, this.emit());
|
|
476
911
|
}
|
|
477
|
-
patch(e, t) {
|
|
478
|
-
|
|
912
|
+
patch(e, t, n) {
|
|
913
|
+
let r = [];
|
|
914
|
+
if (n && this.content?.id !== n) {
|
|
915
|
+
let e = Q(this.content, n);
|
|
916
|
+
if (!e) return;
|
|
917
|
+
r = e;
|
|
918
|
+
}
|
|
919
|
+
this.content = Z(this.content, [...r, ...e], t), this.emit();
|
|
479
920
|
}
|
|
480
921
|
emit() {
|
|
481
922
|
for (let e of this.listeners) e();
|
|
482
923
|
}
|
|
483
924
|
};
|
|
484
|
-
function
|
|
485
|
-
let t =
|
|
925
|
+
function qe(e) {
|
|
926
|
+
let t = v.on("CONTENT_UPDATE", ({ content: t }) => {
|
|
486
927
|
e.applyContentUpdate(t);
|
|
487
|
-
}), n =
|
|
488
|
-
e.patch(
|
|
928
|
+
}), n = v.on("CONTENT_PATCH", ({ itemId: t, path: n, value: r }) => {
|
|
929
|
+
e.patch(n, r, t);
|
|
489
930
|
});
|
|
490
931
|
return () => {
|
|
491
932
|
t(), n();
|
|
@@ -493,17 +934,17 @@ function O(e) {
|
|
|
493
934
|
}
|
|
494
935
|
//#endregion
|
|
495
936
|
//#region src/sitemap.ts
|
|
496
|
-
function
|
|
937
|
+
function Je(e) {
|
|
497
938
|
return (e ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
498
939
|
}
|
|
499
|
-
function
|
|
500
|
-
let n =
|
|
940
|
+
function Ye(e, t) {
|
|
941
|
+
let n = Je(e), r = Je(t);
|
|
501
942
|
if (!r) return n && n !== "home" ? `/${n}` : "/";
|
|
502
943
|
if (!n || n === "home") return `/${r}`;
|
|
503
944
|
let i = `${r}/`;
|
|
504
945
|
return n === r || n.startsWith(i) ? `/${n}` : `/${r}/${n}`;
|
|
505
946
|
}
|
|
506
|
-
function
|
|
947
|
+
function Xe(e, t) {
|
|
507
948
|
if (!t) return null;
|
|
508
949
|
try {
|
|
509
950
|
return new URL(e, t).toString();
|
|
@@ -511,51 +952,51 @@ function j(e, t) {
|
|
|
511
952
|
return null;
|
|
512
953
|
}
|
|
513
954
|
}
|
|
514
|
-
function
|
|
955
|
+
function Ze(e) {
|
|
515
956
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
516
957
|
}
|
|
517
|
-
function
|
|
958
|
+
function Qe(e, t, n) {
|
|
518
959
|
let { localePrefix: r = "auto", defaultLocale: i } = t;
|
|
519
|
-
return r === "always" || r === "auto" && n || r === "except-default" && e.language_iso !== i ?
|
|
960
|
+
return r === "always" || r === "auto" && n || r === "except-default" && e.language_iso !== i ? Ye(e.full_slug, e.language_iso) : Ye(e.full_slug, null);
|
|
520
961
|
}
|
|
521
|
-
function
|
|
962
|
+
function $e(e) {
|
|
522
963
|
let t = /* @__PURE__ */ new Set();
|
|
523
964
|
for (let n of e) if (n.language_iso && t.add(n.language_iso), t.size > 1) return !0;
|
|
524
965
|
return !1;
|
|
525
966
|
}
|
|
526
|
-
function
|
|
527
|
-
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set(), a =
|
|
967
|
+
function et(e, t = {}) {
|
|
968
|
+
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set(), a = $e(e);
|
|
528
969
|
return e.filter((e) => {
|
|
529
970
|
if (r && e.language_iso !== r) return !1;
|
|
530
971
|
let o = e.meta?.robots?.toLowerCase();
|
|
531
972
|
if (o?.includes("noindex") || o?.includes("none")) return !1;
|
|
532
|
-
let s =
|
|
533
|
-
return i.has(c)
|
|
973
|
+
let s = Qe(e, t, a), c = n ? Xe(s, n) ?? s : s;
|
|
974
|
+
return !i.has(c) && (i.add(c), !0);
|
|
534
975
|
});
|
|
535
976
|
}
|
|
536
|
-
function
|
|
537
|
-
let r =
|
|
977
|
+
function tt(e, t, n = {}) {
|
|
978
|
+
let r = $e(e);
|
|
538
979
|
return [
|
|
539
980
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
540
981
|
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
541
982
|
e.map((e) => {
|
|
542
|
-
let i =
|
|
983
|
+
let i = Qe(e, n, r), a = t ? Xe(i, t) : i;
|
|
543
984
|
if (!a) return "";
|
|
544
|
-
let o = [" <url>", ` <loc>${
|
|
545
|
-
return e.published_at && o.push(` <lastmod>${
|
|
985
|
+
let o = [" <url>", ` <loc>${Ze(a)}</loc>`];
|
|
986
|
+
return e.published_at && o.push(` <lastmod>${Ze(e.published_at)}</lastmod>`), o.push(" </url>"), o.join("\n");
|
|
546
987
|
}).filter(Boolean).join("\n"),
|
|
547
988
|
"</urlset>"
|
|
548
989
|
].join("\n");
|
|
549
990
|
}
|
|
550
|
-
function
|
|
991
|
+
function nt(e, t) {
|
|
551
992
|
return [
|
|
552
993
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
553
994
|
"<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
554
995
|
e.map((e) => {
|
|
555
|
-
let n = t ?
|
|
996
|
+
let n = t ? Xe(e, t) : e;
|
|
556
997
|
return n ? [
|
|
557
998
|
" <sitemap>",
|
|
558
|
-
` <loc>${
|
|
999
|
+
` <loc>${Ze(n)}</loc>`,
|
|
559
1000
|
" </sitemap>"
|
|
560
1001
|
].join("\n") : "";
|
|
561
1002
|
}).filter(Boolean).join("\n"),
|
|
@@ -564,14 +1005,14 @@ function L(e, t) {
|
|
|
564
1005
|
}
|
|
565
1006
|
//#endregion
|
|
566
1007
|
//#region src/types.ts
|
|
567
|
-
var
|
|
1008
|
+
var rt = /* @__PURE__ */ t({}), $ = class extends Error {
|
|
568
1009
|
status;
|
|
569
1010
|
endpoint;
|
|
570
1011
|
body;
|
|
571
1012
|
constructor(e, t, n, r) {
|
|
572
1013
|
super(e), this.status = t, this.endpoint = n, this.body = r, this.name = "ApiError";
|
|
573
1014
|
}
|
|
574
|
-
},
|
|
1015
|
+
}, it = (e) => e === 429 || e >= 500 && e <= 599, at = (e) => new Promise((t) => setTimeout(t, e)), ot = class {
|
|
575
1016
|
baseUrl;
|
|
576
1017
|
token;
|
|
577
1018
|
vid;
|
|
@@ -623,7 +1064,7 @@ var R = /* @__PURE__ */ t({}), z = class extends Error {
|
|
|
623
1064
|
signal: n.signal
|
|
624
1065
|
});
|
|
625
1066
|
} catch (t) {
|
|
626
|
-
throw t instanceof Error && t.name === "AbortError" ? new
|
|
1067
|
+
throw t instanceof Error && t.name === "AbortError" ? new $(`Request timed out after ${this.timeoutMs}ms`, 0, e) : t;
|
|
627
1068
|
} finally {
|
|
628
1069
|
clearTimeout(r);
|
|
629
1070
|
}
|
|
@@ -634,8 +1075,8 @@ var R = /* @__PURE__ */ t({}), z = class extends Error {
|
|
|
634
1075
|
let n = await this.fetchWithTimeout(e);
|
|
635
1076
|
return await this.parseResponse(n, t);
|
|
636
1077
|
} catch (e) {
|
|
637
|
-
if (n = e, !(r < this.retries && (!(e instanceof
|
|
638
|
-
await
|
|
1078
|
+
if (n = e, !(r < this.retries && (!(e instanceof $) || e.status === 0 || it(e.status)))) throw e;
|
|
1079
|
+
await at(200 * 2 ** r);
|
|
639
1080
|
}
|
|
640
1081
|
throw n;
|
|
641
1082
|
}
|
|
@@ -670,7 +1111,7 @@ var R = /* @__PURE__ */ t({}), z = class extends Error {
|
|
|
670
1111
|
if (this.isFetchResponse(e)) {
|
|
671
1112
|
if (!e.ok) {
|
|
672
1113
|
let n = await this.readErrorBody(e);
|
|
673
|
-
throw new
|
|
1114
|
+
throw new $(`Request to "${t}" failed with status ${e.status}`, e.status, t, n);
|
|
674
1115
|
}
|
|
675
1116
|
return await e.json();
|
|
676
1117
|
}
|
|
@@ -737,6 +1178,6 @@ var R = /* @__PURE__ */ t({}), z = class extends Error {
|
|
|
737
1178
|
}
|
|
738
1179
|
};
|
|
739
1180
|
//#endregion
|
|
740
|
-
export {
|
|
1181
|
+
export { ot as ApiClient, $ as ApiError, d as B10cksDataApi, te as BRIDGE_PROTOCOL, ne as PreviewBridge, Ke as PreviewStore, Ve as attachEditable, He as attachEditableField, qe as bindPreviewStore, o as blockAnchorAttrs, r as breadcrumbJsonLd, Ye as buildLocalizedPath, f as createB10cksDataApi, X as ensurePreviewStyles, et as filterSitemapEntries, Q as findPathById, We as getAtPath, Ge as mergeContentUpdate, Je as normalizePathSegment, v as previewBridge, nt as renderSitemapIndex, tt as renderSitemapXml, a as resolveB10cksLink, c as serializeFilter, Z as setAtPath, Be as setPreviewScrollOffset, i as toRootBlock, rt as types };
|
|
741
1182
|
|
|
742
1183
|
//# sourceMappingURL=index.mjs.map
|