@bladeberg/editor 0.2.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.
@@ -0,0 +1,588 @@
1
+ import M, { useState as h, useRef as O, useCallback as B, useEffect as X } from "react";
2
+ import z from "react-dom";
3
+ let R = null, k = null;
4
+ function K(e) {
5
+ R = e;
6
+ }
7
+ function V(e, t = 5e3, r = 50) {
8
+ return new Promise((o, n) => {
9
+ const i = Date.now(), s = () => {
10
+ if (e()) return o();
11
+ if (Date.now() - i >= t)
12
+ return n(new Error("[BladeBerg] Timed out waiting for the editor runtime."));
13
+ setTimeout(s, r);
14
+ };
15
+ s();
16
+ });
17
+ }
18
+ function Y() {
19
+ var e;
20
+ return (e = window.wp) != null && e.attachEditor ? Promise.resolve() : k || (k = (R ? R() : Promise.resolve()).then(() => V(() => {
21
+ var t;
22
+ return !!((t = window.wp) != null && t.attachEditor);
23
+ })).catch((t) => {
24
+ throw k = null, t;
25
+ }), k);
26
+ }
27
+ function G(e) {
28
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
29
+ }
30
+ function H({ blockPrefix: e, media: t } = {}) {
31
+ var n;
32
+ const r = window.BladebergConfig ?? {}, o = {
33
+ blockPrefix: e ?? r.blockPrefix ?? "bb",
34
+ mediaMode: (t == null ? void 0 : t.mode) ?? r.mediaMode ?? "disabled",
35
+ mediaApiUrl: (t == null ? void 0 : t.apiUrl) ?? r.mediaApiUrl ?? "",
36
+ csrfToken: (t == null ? void 0 : t.csrfToken) ?? r.csrfToken ?? ((n = document.querySelector('meta[name="csrf-token"]')) == null ? void 0 : n.getAttribute("content")) ?? ""
37
+ };
38
+ return window.BladebergConfig = { ...r, ...o }, o;
39
+ }
40
+ function j(e, t) {
41
+ return ((e == null ? void 0 : e.value) ?? "").replace(/<!--\s*(\/?)wp:/g, `<!-- $1${t}:`);
42
+ }
43
+ function J(e, t) {
44
+ if (!e) return e;
45
+ const r = new RegExp(`<!--\\s*(\\/?)\\s*${G(t)}:`, "g");
46
+ return e.replace(r, "<!-- $1wp:");
47
+ }
48
+ function L(e) {
49
+ var t;
50
+ return e ?? ((t = window.BladebergConfig) == null ? void 0 : t.blockPrefix) ?? "bb";
51
+ }
52
+ function Q(e) {
53
+ const t = L(e);
54
+ if (window.__bbBrandingInstalled) {
55
+ C(document.body, t);
56
+ return;
57
+ }
58
+ window.__bbBrandingInstalled = !0, C(document.body, t);
59
+ const r = new MutationObserver((o) => {
60
+ for (const { addedNodes: n } of o)
61
+ for (const i of n)
62
+ i.nodeType === Node.ELEMENT_NODE && C(i, t);
63
+ });
64
+ r.observe(document.body, { childList: !0, subtree: !0 }), window.Bladeberg = window.Bladeberg ?? {}, window.Bladeberg._brandingObserver = r, ee(t);
65
+ }
66
+ function Z(e) {
67
+ return [
68
+ { from: /WordPress/g, to: "BladeBerg" },
69
+ { from: /\bWP\b(?![-_])/g, to: "BB" },
70
+ { from: /\bwp:([\w-]+)/g, to: `${e}:$1` },
71
+ { from: /\bcore\/([\w-]+)/g, to: `${e}/$1` }
72
+ ];
73
+ }
74
+ function C(e, t) {
75
+ if (!e) return;
76
+ const r = Z(t);
77
+ if (e.nodeType === Node.TEXT_NODE) {
78
+ S(e, r);
79
+ return;
80
+ }
81
+ const o = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, {
82
+ acceptNode(s) {
83
+ var c;
84
+ const a = ((c = s.parentElement) == null ? void 0 : c.tagName) ?? "";
85
+ return ["SCRIPT", "STYLE", "INPUT", "TEXTAREA"].includes(a) ? NodeFilter.FILTER_REJECT : r.some((u) => (u.from.lastIndex = 0, u.from.test(s.textContent))) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
86
+ }
87
+ }), n = [];
88
+ let i;
89
+ for (; i = o.nextNode(); ) n.push(i);
90
+ n.forEach((s) => S(s, r));
91
+ }
92
+ function S(e, t) {
93
+ let r = e.textContent;
94
+ for (const { from: o, to: n } of t)
95
+ o.lastIndex = 0, r = r.replace(o, n);
96
+ r !== e.textContent && (e.textContent = r);
97
+ }
98
+ function ee(e) {
99
+ const t = L(e), r = "data-bb-code-overlay";
100
+ function o(a) {
101
+ return a.replace(/wp:([\w-]+)/g, `${t}:$1`).replace(/WordPress/g, "BladeBerg").replace(/core\/([\w-]+)/g, `${t}/$1`);
102
+ }
103
+ function n(a) {
104
+ var u;
105
+ if (a.hasAttribute(r)) return;
106
+ a.setAttribute(r, "1");
107
+ const d = a.parentElement;
108
+ d && getComputedStyle(d).position === "static" && (d.style.position = "relative");
109
+ const c = document.createElement("pre");
110
+ c.className = "bb-code-editor-overlay", c.textContent = o(a.value), c.setAttribute("aria-hidden", "true"), (u = a.parentNode) == null || u.insertBefore(c, a.nextSibling), a.addEventListener("input", () => {
111
+ c.textContent = o(a.value);
112
+ });
113
+ }
114
+ const i = ".editor-post-text-editor, .block-editor-plain-text";
115
+ if (document.querySelectorAll(i).forEach(n), window.__bbOverlayInstalled) return;
116
+ window.__bbOverlayInstalled = !0;
117
+ const s = new MutationObserver((a) => {
118
+ var d, c;
119
+ for (const { addedNodes: u } of a)
120
+ for (const l of u)
121
+ l.nodeType === Node.ELEMENT_NODE && ((d = l.querySelectorAll) == null || d.call(l, i).forEach(n), (c = l.matches) != null && c.call(l, i) && n(l));
122
+ });
123
+ s.observe(document.body, { childList: !0, subtree: !0 }), window.Bladeberg = window.Bladeberg ?? {}, window.Bladeberg._overlayObserver = s;
124
+ }
125
+ function te() {
126
+ if (window.__bbContextMenuInstalled) return;
127
+ window.__bbContextMenuInstalled = !0;
128
+ const e = ".block-editor-block-list__layout, .editor-styles-wrapper, .iso-editor";
129
+ function t(r = 0) {
130
+ const o = document.querySelector(".block-editor-block-settings-menu__toggle") || document.querySelector(".block-editor-block-settings-menu button") || document.querySelector('button[aria-label="Options"]') || document.querySelector('.block-editor-block-settings-menu [role="button"]');
131
+ if (o) {
132
+ o.click();
133
+ return;
134
+ }
135
+ r < 10 && setTimeout(() => t(r + 1), 30);
136
+ }
137
+ document.addEventListener(
138
+ "contextmenu",
139
+ (r) => {
140
+ var s;
141
+ const o = r.target, n = (s = o == null ? void 0 : o.closest) == null ? void 0 : s.call(o, "[data-block]");
142
+ if (!n || !n.closest(e))
143
+ return;
144
+ r.preventDefault();
145
+ const i = { bubbles: !0, cancelable: !0, view: window, button: 0 };
146
+ if (o.dispatchEvent(new MouseEvent("mousedown", i)), o.dispatchEvent(new MouseEvent("mouseup", i)), typeof n.focus == "function")
147
+ try {
148
+ n.focus({ preventScroll: !0 });
149
+ } catch {
150
+ }
151
+ setTimeout(() => t(), 30);
152
+ },
153
+ { capture: !0 }
154
+ );
155
+ }
156
+ function re(e) {
157
+ var t, r;
158
+ return {
159
+ ...e,
160
+ alt: e.alt_text ?? "",
161
+ caption: ((t = e.caption) == null ? void 0 : t.raw) ?? "",
162
+ title: ((r = e.title) == null ? void 0 : r.raw) ?? e.title ?? "",
163
+ url: e.source_url ?? e.url ?? ""
164
+ };
165
+ }
166
+ async function oe(e, t = {}, r) {
167
+ var u, l, m;
168
+ const o = window.BladebergConfig ?? {}, n = o.mediaApiUrl, i = o.csrfToken ?? ((u = document.querySelector('meta[name="csrf-token"]')) == null ? void 0 : u.getAttribute("content"));
169
+ if (!n)
170
+ throw new Error("[BladeBerg] mediaApiUrl is not configured. Set media.enabled = true in config/bladeberg.php.");
171
+ const s = new FormData();
172
+ s.append("file", e, e.name || "upload");
173
+ const a = ["alt_text", "title", "caption"];
174
+ for (const p of a)
175
+ t[p] !== void 0 && t[p] !== null && s.append(p, t[p]);
176
+ const d = {};
177
+ i && (d["X-CSRF-TOKEN"] = i);
178
+ const c = await fetch(n, {
179
+ method: "POST",
180
+ headers: d,
181
+ body: s,
182
+ credentials: "same-origin",
183
+ signal: r
184
+ });
185
+ if (!c.ok) {
186
+ const p = await c.json().catch(() => ({})), w = (p == null ? void 0 : p.message) ?? ((m = (l = p == null ? void 0 : p.errors) == null ? void 0 : l.file) == null ? void 0 : m[0]) ?? `HTTP ${c.status}`;
187
+ throw new Error(`[BladeBerg] Upload failed: ${w}`);
188
+ }
189
+ return re(await c.json());
190
+ }
191
+ async function U({
192
+ filesList: e,
193
+ onFileChange: t,
194
+ onSuccess: r,
195
+ onError: o,
196
+ additionalData: n = {},
197
+ signal: i
198
+ }) {
199
+ const s = Array.from(e), a = [];
200
+ for (const d of s) {
201
+ const c = URL.createObjectURL(d), u = { url: c, media_type: d.type };
202
+ t([u]);
203
+ try {
204
+ const l = await oe(d, n, i);
205
+ URL.revokeObjectURL(c), t([l]), a.push(l);
206
+ } catch (l) {
207
+ URL.revokeObjectURL(c), typeof o == "function" ? o({ code: "upload_error", message: l.message, file: d }) : console.error("[BladeBerg] Media upload error:", l);
208
+ }
209
+ }
210
+ a.length > 0 && typeof r == "function" && r(a);
211
+ }
212
+ const ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
213
+ __proto__: null,
214
+ bladebergMediaUpload: U
215
+ }, Symbol.toStringTag, { value: "Module" }));
216
+ function ae(e) {
217
+ const t = window.BladebergConfig ?? {}, r = t.mediaApiUrl ? new URL(t.mediaApiUrl).pathname : "/bladeberg/media", o = e.replace(/^\/wp\/v2\/media/, ""), n = o.indexOf("?"), i = n >= 0 ? o.slice(0, n) : o, s = n >= 0 ? o.slice(n + 1) : "", a = new URLSearchParams(s), d = new URLSearchParams(), c = ["page", "per_page", "search", "media_type", "orderby", "order"];
218
+ for (const m of c)
219
+ a.has(m) && d.set(m, a.get(m));
220
+ const u = d.toString();
221
+ return r + i + (u ? "?" + u : "");
222
+ }
223
+ function ie() {
224
+ var t;
225
+ const e = (t = window.wp) == null ? void 0 : t.apiFetch;
226
+ if (!e) {
227
+ console.warn("[BladeBerg] window.wp.apiFetch not found — media API middleware not registered.");
228
+ return;
229
+ }
230
+ e.use((r, o) => {
231
+ const n = r.path ?? "";
232
+ return typeof n == "string" && n.startsWith("/wp/v2/media") ? o({ ...r, path: ae(n) }) : o(r);
233
+ });
234
+ }
235
+ var I = { exports: {} }, T = {};
236
+ /**
237
+ * @license React
238
+ * react-jsx-runtime.production.min.js
239
+ *
240
+ * Copyright (c) Facebook, Inc. and its affiliates.
241
+ *
242
+ * This source code is licensed under the MIT license found in the
243
+ * LICENSE file in the root directory of this source tree.
244
+ */
245
+ var le = M, se = Symbol.for("react.element"), ce = Symbol.for("react.fragment"), de = Object.prototype.hasOwnProperty, ue = le.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, fe = { key: !0, ref: !0, __self: !0, __source: !0 };
246
+ function A(e, t, r) {
247
+ var o, n = {}, i = null, s = null;
248
+ r !== void 0 && (i = "" + r), t.key !== void 0 && (i = "" + t.key), t.ref !== void 0 && (s = t.ref);
249
+ for (o in t) de.call(t, o) && !fe.hasOwnProperty(o) && (n[o] = t[o]);
250
+ if (e && e.defaultProps) for (o in t = e.defaultProps, t) n[o] === void 0 && (n[o] = t[o]);
251
+ return { $$typeof: se, type: e, key: i, ref: s, props: n, _owner: ue.current };
252
+ }
253
+ T.Fragment = ce;
254
+ T.jsx = A;
255
+ T.jsxs = A;
256
+ I.exports = T;
257
+ var f = I.exports;
258
+ const pe = [
259
+ { label: "All", value: "" },
260
+ { label: "Images", value: "image" },
261
+ { label: "Video", value: "video" },
262
+ { label: "Audio", value: "audio" },
263
+ { label: "Documents", value: "application" }
264
+ ];
265
+ async function be({ page: e = 1, perPage: t = 20, search: r = "", mediaType: o = "" } = {}) {
266
+ var m;
267
+ const n = window.BladebergConfig ?? {}, i = n.csrfToken ?? ((m = document.querySelector('meta[name="csrf-token"]')) == null ? void 0 : m.content), s = n.mediaApiUrl ?? "/bladeberg/media", a = new URLSearchParams({ page: e, per_page: t });
268
+ r && a.set("search", r), o && a.set("media_type", o);
269
+ const d = await fetch(`${s}?${a}`, {
270
+ headers: {
271
+ Accept: "application/json",
272
+ ...i ? { "X-CSRF-TOKEN": i } : {}
273
+ },
274
+ credentials: "same-origin"
275
+ });
276
+ if (!d.ok) throw new Error(`[BladeBerg] Media fetch failed: ${d.status}`);
277
+ const c = await d.json(), u = parseInt(d.headers.get("X-WP-Total") ?? "0", 10), l = parseInt(d.headers.get("X-WP-TotalPages") ?? "1", 10);
278
+ return { items: c, total: u, totalPages: l };
279
+ }
280
+ function me({ item: e, isSelected: t, onSelect: r }) {
281
+ var i, s, a, d, c, u;
282
+ const o = (i = e.mime_type) == null ? void 0 : i.startsWith("image/"), n = e.source_url ?? e.url ?? "";
283
+ return /* @__PURE__ */ f.jsxs(
284
+ "button",
285
+ {
286
+ type: "button",
287
+ className: `bb-media-grid__item${t ? " bb-media-grid__item--selected" : ""}`,
288
+ onClick: () => r(e),
289
+ title: ((s = e.title) == null ? void 0 : s.rendered) ?? e.title ?? n,
290
+ "aria-pressed": t,
291
+ children: [
292
+ o ? /* @__PURE__ */ f.jsx(
293
+ "img",
294
+ {
295
+ src: ((c = (d = (a = e.media_details) == null ? void 0 : a.sizes) == null ? void 0 : d.thumbnail) == null ? void 0 : c.source_url) ?? n,
296
+ alt: e.alt_text ?? "",
297
+ loading: "lazy",
298
+ className: "bb-media-grid__thumb"
299
+ }
300
+ ) : /* @__PURE__ */ f.jsx("div", { className: "bb-media-grid__icon", "aria-hidden": "true", children: we(e.mime_type) }),
301
+ /* @__PURE__ */ f.jsx("span", { className: "bb-media-grid__name", children: ((u = e.title) == null ? void 0 : u.rendered) ?? e.title ?? "" })
302
+ ]
303
+ }
304
+ );
305
+ }
306
+ function we(e = "") {
307
+ return e.startsWith("video/") ? "🎬" : e.startsWith("audio/") ? "🎵" : e.includes("pdf") ? "📄" : "📁";
308
+ }
309
+ function ge({ onUploaded: e }) {
310
+ const t = O(null), [r, o] = h(!1), [n, i] = h(!1), s = B(async (a) => {
311
+ if (a.length) {
312
+ i(!0);
313
+ try {
314
+ const { bladebergMediaUpload: d } = await Promise.resolve().then(() => ne);
315
+ await d({
316
+ filesList: a,
317
+ onFileChange: (c) => {
318
+ var u;
319
+ (u = c[0]) != null && u.id && e(c[0]);
320
+ },
321
+ onError: (c) => console.error("[BladeBerg] Upload error:", c)
322
+ });
323
+ } finally {
324
+ i(!1);
325
+ }
326
+ }
327
+ }, [e]);
328
+ return /* @__PURE__ */ f.jsxs(
329
+ "div",
330
+ {
331
+ className: `bb-media-upload-zone${r ? " bb-media-upload-zone--drag" : ""}`,
332
+ onDragOver: (a) => {
333
+ a.preventDefault(), o(!0);
334
+ },
335
+ onDragLeave: () => o(!1),
336
+ onDrop: (a) => {
337
+ a.preventDefault(), o(!1), s(Array.from(a.dataTransfer.files));
338
+ },
339
+ onClick: () => {
340
+ var a;
341
+ return (a = t.current) == null ? void 0 : a.click();
342
+ },
343
+ role: "button",
344
+ tabIndex: 0,
345
+ onKeyDown: (a) => {
346
+ var d;
347
+ return a.key === "Enter" && ((d = t.current) == null ? void 0 : d.click());
348
+ },
349
+ children: [
350
+ /* @__PURE__ */ f.jsx(
351
+ "input",
352
+ {
353
+ ref: t,
354
+ type: "file",
355
+ multiple: !0,
356
+ accept: "image/*,video/*,audio/*,application/pdf",
357
+ style: { display: "none" },
358
+ onChange: (a) => s(Array.from(a.target.files))
359
+ }
360
+ ),
361
+ n ? /* @__PURE__ */ f.jsx("span", { children: "Uploading…" }) : /* @__PURE__ */ f.jsx("span", { children: "Drop files here or click to upload" })
362
+ ]
363
+ }
364
+ );
365
+ }
366
+ function he({ onSelect: e, allowedTypes: t = [], allowUpload: r = !0 }) {
367
+ const [o, n] = h([]), [i, s] = h(1), [a, d] = h(1), [c, u] = h(""), [l, m] = h(
368
+ t.length === 1 ? t[0] : ""
369
+ ), [p, w] = h(!1), [y, v] = h(null), [g, _] = h(null), x = O(null), N = B(async (b = 1, P = !1) => {
370
+ w(!0), v(null);
371
+ try {
372
+ const E = await be({ page: b, search: c, mediaType: l });
373
+ n((W) => P ? E.items : [...W, ...E.items]), d(E.totalPages), s(b);
374
+ } catch (E) {
375
+ v(E.message);
376
+ } finally {
377
+ w(!1);
378
+ }
379
+ }, [c, l]);
380
+ X(() => {
381
+ N(1, !0);
382
+ }, [N]);
383
+ const $ = (b) => {
384
+ clearTimeout(x.current), x.current = setTimeout(() => u(b), 350);
385
+ }, F = (b) => {
386
+ _(b.id), e(b);
387
+ }, q = (b) => {
388
+ n((P) => [b, ...P]);
389
+ }, D = t.length !== 1;
390
+ return /* @__PURE__ */ f.jsxs("div", { className: "bb-media-grid-wrap", children: [
391
+ /* @__PURE__ */ f.jsxs("div", { className: "bb-media-grid-toolbar", children: [
392
+ /* @__PURE__ */ f.jsx(
393
+ "input",
394
+ {
395
+ type: "search",
396
+ className: "bb-media-grid-search",
397
+ placeholder: "Search media…",
398
+ onChange: (b) => $(b.target.value)
399
+ }
400
+ ),
401
+ D && /* @__PURE__ */ f.jsx("div", { className: "bb-media-grid-filters", role: "tablist", children: pe.map((b) => /* @__PURE__ */ f.jsx(
402
+ "button",
403
+ {
404
+ type: "button",
405
+ role: "tab",
406
+ "aria-selected": l === b.value,
407
+ className: `bb-media-grid-filter${l === b.value ? " bb-media-grid-filter--active" : ""}`,
408
+ onClick: () => m(b.value),
409
+ children: b.label
410
+ },
411
+ b.value
412
+ )) })
413
+ ] }),
414
+ r && /* @__PURE__ */ f.jsx(ge, { onUploaded: q }),
415
+ y && /* @__PURE__ */ f.jsx("p", { className: "bb-media-grid-error", children: y }),
416
+ /* @__PURE__ */ f.jsx("div", { className: "bb-media-grid", role: "listbox", "aria-label": "Media library", children: o.map((b) => /* @__PURE__ */ f.jsx(
417
+ me,
418
+ {
419
+ item: b,
420
+ isSelected: g === b.id,
421
+ onSelect: F
422
+ },
423
+ b.id
424
+ )) }),
425
+ !p && o.length === 0 && /* @__PURE__ */ f.jsx("p", { className: "bb-media-grid-empty", children: r ? "No media found. Drop files above to upload." : "No media found in the configured storage directory." }),
426
+ p && /* @__PURE__ */ f.jsx("p", { className: "bb-media-grid-loading", children: "Loading…" }),
427
+ !p && i < a && /* @__PURE__ */ f.jsx(
428
+ "button",
429
+ {
430
+ type: "button",
431
+ className: "bb-media-grid-load-more",
432
+ onClick: () => N(i + 1),
433
+ children: "Load more"
434
+ }
435
+ )
436
+ ] });
437
+ }
438
+ function ye({ isOpen: e, onClose: t, title: r, children: o }) {
439
+ return e ? /* @__PURE__ */ f.jsx(
440
+ "div",
441
+ {
442
+ className: "bb-media-modal-overlay",
443
+ role: "dialog",
444
+ "aria-modal": "true",
445
+ "aria-label": r,
446
+ onClick: (n) => {
447
+ n.target === n.currentTarget && t();
448
+ },
449
+ children: /* @__PURE__ */ f.jsxs("div", { className: "bb-media-modal", children: [
450
+ /* @__PURE__ */ f.jsxs("div", { className: "bb-media-modal__header", children: [
451
+ /* @__PURE__ */ f.jsx("h2", { className: "bb-media-modal__title", children: r }),
452
+ /* @__PURE__ */ f.jsx(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ className: "bb-media-modal__close",
457
+ onClick: t,
458
+ "aria-label": "Close media library",
459
+ children: "✕"
460
+ }
461
+ )
462
+ ] }),
463
+ /* @__PURE__ */ f.jsx("div", { className: "bb-media-modal__body", children: o })
464
+ ] })
465
+ }
466
+ ) : null;
467
+ }
468
+ function _e({ onSelect: e, allowedTypes: t = [], multiple: r = !1, render: o }) {
469
+ var p;
470
+ const [n, i] = h(!1), a = (((p = window.BladebergConfig) == null ? void 0 : p.mediaMode) ?? "upload") === "upload", d = a ? "BladeBerg Media Library" : "BladeBerg Media — Browse", c = B(() => i(!0), []), u = B(() => i(!1), []), l = B((w) => {
471
+ e(w), u();
472
+ }, [e, u]), m = [...new Set(
473
+ (t ?? []).map((w) => w.split("/")[0]).filter(Boolean)
474
+ )];
475
+ return /* @__PURE__ */ f.jsxs(f.Fragment, { children: [
476
+ typeof o == "function" && o({ open: c }),
477
+ /* @__PURE__ */ f.jsx(
478
+ ye,
479
+ {
480
+ isOpen: n,
481
+ onClose: u,
482
+ title: d,
483
+ children: /* @__PURE__ */ f.jsx(
484
+ he,
485
+ {
486
+ onSelect: l,
487
+ allowedTypes: m,
488
+ allowUpload: a
489
+ }
490
+ )
491
+ }
492
+ )
493
+ ] });
494
+ }
495
+ function Te(e, t) {
496
+ var r, o;
497
+ window.Bladeberg = window.Bladeberg ?? { _queue: [] }, window.Bladeberg._queue = window.Bladeberg._queue ?? [], (o = (r = window.wp) == null ? void 0 : r.blocks) != null && o.registerBlockType ? window.wp.blocks.registerBlockType(e, t) : window.Bladeberg._queue.push({ name: e, settings: t });
498
+ }
499
+ function ve() {
500
+ var t, r, o;
501
+ if (!((r = (t = window.wp) == null ? void 0 : t.blocks) != null && r.registerBlockType)) return;
502
+ (((o = window.Bladeberg) == null ? void 0 : o._queue) ?? []).forEach(({ name: n, settings: i }) => window.wp.blocks.registerBlockType(n, i)), window.Bladeberg && (window.Bladeberg._queue = []);
503
+ }
504
+ function xe(e) {
505
+ const t = typeof e == "string" ? document.querySelector(e) : e;
506
+ if (!t)
507
+ throw new Error("[BladeBerg] createEditor: target element not found.");
508
+ if (t.tagName === "TEXTAREA")
509
+ return t;
510
+ const r = document.createElement("textarea");
511
+ return t.appendChild(r), r;
512
+ }
513
+ function Ee(e, t) {
514
+ var r, o, n, i, s;
515
+ if (e !== "select" && e !== "upload")
516
+ return t;
517
+ if (ie(), (o = (r = window.wp) == null ? void 0 : r.hooks) != null && o.addFilter && window.wp.hooks.addFilter(
518
+ "editor.MediaUpload",
519
+ "bladeberg/media-upload",
520
+ () => _e
521
+ ), e === "upload" && (t.editor = {
522
+ ...t.editor ?? {},
523
+ mediaUpload: U
524
+ }, (n = window.wp) != null && n.data))
525
+ try {
526
+ (s = (i = window.wp.data.dispatch("core")) == null ? void 0 : i.receiveUserPermission) == null || s.call(i, "create/media", !0);
527
+ } catch {
528
+ }
529
+ return t;
530
+ }
531
+ async function Ne(e = {}) {
532
+ const {
533
+ target: t,
534
+ value: r,
535
+ settings: o = {},
536
+ blockPrefix: n,
537
+ media: i,
538
+ branding: s = !0,
539
+ contextMenu: a = !0,
540
+ onChange: d
541
+ } = e;
542
+ await Y(), ve();
543
+ const c = H({ blockPrefix: n, media: i }), u = c.blockPrefix, l = xe(t);
544
+ l.dataset.bladebergMounted = "1", r != null && (l.value = r), l.value && (l.value = J(l.value, u));
545
+ const m = Ee(c.mediaMode, { ...o });
546
+ window.wp.attachEditor(l, m), s && Q(u), a && te();
547
+ const p = /* @__PURE__ */ new Set();
548
+ typeof d == "function" && p.add(d);
549
+ let w = l.value, y = null;
550
+ function v() {
551
+ y || p.size === 0 || (y = window.setInterval(() => {
552
+ if (l.value === w) return;
553
+ w = l.value;
554
+ const g = j(l, u);
555
+ p.forEach((_) => {
556
+ try {
557
+ _(g);
558
+ } catch (x) {
559
+ console.error("[BladeBerg] onChange handler error:", x);
560
+ }
561
+ });
562
+ }, 300));
563
+ }
564
+ return v(), {
565
+ textarea: l,
566
+ getContent: () => j(l, u),
567
+ onChange(g) {
568
+ return p.add(g), v(), () => p.delete(g);
569
+ },
570
+ destroy() {
571
+ var g, _;
572
+ y && (window.clearInterval(y), y = null), p.clear();
573
+ try {
574
+ (_ = (g = window.wp) == null ? void 0 : g.detachEditor) == null || _.call(g, l);
575
+ } catch {
576
+ }
577
+ delete l.dataset.bladebergMounted;
578
+ }
579
+ };
580
+ }
581
+ K(() => (window.React = window.React ?? M, window.ReactDOM = window.ReactDOM ?? z, import("./isolated-block-editor-FqFbPhep.js").then((e) => e.i)));
582
+ export {
583
+ Q as applyBranding,
584
+ Ne as createEditor,
585
+ te as installBlockContextMenu,
586
+ ee as installCodeEditorOverlay,
587
+ Te as registerBlock
588
+ };