@bladeberg/editor 0.2.0 → 0.2.1

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