@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.
- package/README.md +113 -637
- package/README.npm.md +208 -0
- package/dist-npm/bladeberg.js +206 -193
- package/dist-npm/isolated-block-editor.js +9 -0
- package/dist-npm/style.css +2327 -3113
- package/package.json +2 -4
- package/dist-npm/isolated-block-editor-FqFbPhep.js +0 -61842
package/dist-npm/bladeberg.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import M, { useState as h, useRef as O, useCallback as
|
|
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,
|
|
3
|
+
let R = null, B = null;
|
|
4
4
|
function K(e) {
|
|
5
5
|
R = e;
|
|
6
6
|
}
|
|
7
|
-
function V(e, t = 5e3,
|
|
8
|
-
return new Promise((
|
|
9
|
-
const
|
|
10
|
-
if (e()) return
|
|
11
|
-
if (Date.now() -
|
|
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,
|
|
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() :
|
|
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
|
|
25
|
-
}),
|
|
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
|
|
33
|
-
blockPrefix: e ??
|
|
34
|
-
mediaMode: (t == null ? void 0 : t.mode) ??
|
|
35
|
-
mediaApiUrl: (t == null ? void 0 : t.apiUrl) ??
|
|
36
|
-
csrfToken: (t == null ? void 0 : t.csrfToken) ??
|
|
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 = { ...
|
|
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
|
|
46
|
-
return e.replace(
|
|
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
|
|
60
|
-
for (const { addedNodes: n } of
|
|
61
|
-
for (const
|
|
62
|
-
|
|
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
|
-
|
|
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
|
|
76
|
+
const o = Z(t);
|
|
77
77
|
if (e.nodeType === Node.TEXT_NODE) {
|
|
78
|
-
S(e,
|
|
78
|
+
S(e, o);
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
const
|
|
81
|
+
const r = document.createTreeWalker(e, NodeFilter.SHOW_TEXT, {
|
|
82
82
|
acceptNode(s) {
|
|
83
|
-
var
|
|
84
|
-
const
|
|
85
|
-
return ["SCRIPT", "STYLE", "INPUT", "TEXTAREA"].includes(
|
|
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
|
|
89
|
-
for (;
|
|
90
|
-
n.forEach((s) => S(s,
|
|
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
|
|
94
|
-
for (const { from:
|
|
95
|
-
|
|
96
|
-
|
|
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),
|
|
100
|
-
function
|
|
101
|
-
return
|
|
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(
|
|
103
|
+
function n(i) {
|
|
104
104
|
var u;
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
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
|
|
115
|
-
if (document.querySelectorAll(
|
|
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((
|
|
118
|
-
var
|
|
119
|
-
for (const { addedNodes: u } of
|
|
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 && ((
|
|
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(
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
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
|
-
|
|
135
|
+
o < 10 && setTimeout(() => t(o + 1), 30);
|
|
136
136
|
}
|
|
137
137
|
document.addEventListener(
|
|
138
138
|
"contextmenu",
|
|
139
|
-
(
|
|
139
|
+
(o) => {
|
|
140
140
|
var s;
|
|
141
|
-
const
|
|
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
|
-
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
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,
|
|
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: ((
|
|
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 = {},
|
|
166
|
+
async function oe(e, t = {}, o) {
|
|
167
167
|
var u, l, m;
|
|
168
|
-
const
|
|
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
|
|
174
|
-
for (const p of
|
|
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
|
|
177
|
-
|
|
178
|
-
const
|
|
176
|
+
const c = {};
|
|
177
|
+
a && (c["X-CSRF-TOKEN"] = a);
|
|
178
|
+
const d = await fetch(n, {
|
|
179
179
|
method: "POST",
|
|
180
|
-
headers:
|
|
180
|
+
headers: c,
|
|
181
181
|
body: s,
|
|
182
182
|
credentials: "same-origin",
|
|
183
|
-
signal:
|
|
183
|
+
signal: o
|
|
184
184
|
});
|
|
185
|
-
if (!
|
|
186
|
-
const p = await
|
|
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
|
|
189
|
+
return re(await d.json());
|
|
190
190
|
}
|
|
191
191
|
async function U({
|
|
192
192
|
filesList: e,
|
|
193
193
|
onFileChange: t,
|
|
194
|
-
onSuccess:
|
|
195
|
-
onError:
|
|
194
|
+
onSuccess: o,
|
|
195
|
+
onError: r,
|
|
196
196
|
additionalData: n = {},
|
|
197
|
-
signal:
|
|
197
|
+
signal: a
|
|
198
198
|
}) {
|
|
199
|
-
const s = Array.from(e),
|
|
200
|
-
for (const
|
|
201
|
-
const
|
|
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(
|
|
205
|
-
URL.revokeObjectURL(
|
|
204
|
+
const l = await oe(c, n, a);
|
|
205
|
+
URL.revokeObjectURL(d), t([l]), i.push(l);
|
|
206
206
|
} catch (l) {
|
|
207
|
-
URL.revokeObjectURL(
|
|
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
|
-
|
|
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 ?? {},
|
|
218
|
-
for (const m of
|
|
219
|
-
|
|
220
|
-
const u =
|
|
221
|
-
return
|
|
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((
|
|
231
|
-
const n =
|
|
232
|
-
return typeof n == "string" && n.startsWith("/wp/v2/media") ?
|
|
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"),
|
|
246
|
-
function A(e, t,
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
for (
|
|
250
|
-
if (e && e.defaultProps) for (
|
|
251
|
-
return { $$typeof: se, type: e, key:
|
|
252
|
-
}
|
|
253
|
-
T.Fragment =
|
|
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:
|
|
265
|
+
async function be({ page: e = 1, perPage: t = 20, search: o = "", mediaType: r = "" } = {}) {
|
|
266
266
|
var m;
|
|
267
|
-
const n = window.BladebergConfig ?? {},
|
|
268
|
-
|
|
269
|
-
const
|
|
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
|
-
...
|
|
272
|
+
...a ? { "X-CSRF-TOKEN": a } : {}
|
|
273
273
|
},
|
|
274
274
|
credentials: "same-origin"
|
|
275
275
|
});
|
|
276
|
-
if (!
|
|
277
|
-
const
|
|
278
|
-
return { items:
|
|
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:
|
|
281
|
-
var
|
|
282
|
-
const
|
|
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: () =>
|
|
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
|
-
|
|
292
|
+
r ? /* @__PURE__ */ f.jsx(
|
|
293
293
|
"img",
|
|
294
294
|
{
|
|
295
|
-
src: ((
|
|
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), [
|
|
311
|
-
if (
|
|
312
|
-
|
|
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:
|
|
315
|
-
await
|
|
316
|
-
filesList:
|
|
317
|
-
onFileChange: (
|
|
314
|
+
const { bladebergMediaUpload: c } = await Promise.resolve().then(() => ne);
|
|
315
|
+
await c({
|
|
316
|
+
filesList: i,
|
|
317
|
+
onFileChange: (d) => {
|
|
318
318
|
var u;
|
|
319
|
-
(u =
|
|
319
|
+
(u = d[0]) != null && u.id && e(d[0]);
|
|
320
320
|
},
|
|
321
|
-
onError: (
|
|
321
|
+
onError: (d) => console.error("[BladeBerg] Upload error:", d)
|
|
322
322
|
});
|
|
323
323
|
} finally {
|
|
324
|
-
|
|
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${
|
|
332
|
-
onDragOver: (
|
|
333
|
-
|
|
331
|
+
className: `bb-media-upload-zone${o ? " bb-media-upload-zone--drag" : ""}`,
|
|
332
|
+
onDragOver: (i) => {
|
|
333
|
+
i.preventDefault(), r(!0);
|
|
334
334
|
},
|
|
335
|
-
onDragLeave: () =>
|
|
336
|
-
onDrop: (
|
|
337
|
-
|
|
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
|
|
341
|
-
return (
|
|
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: (
|
|
346
|
-
var
|
|
347
|
-
return
|
|
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: (
|
|
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:
|
|
367
|
-
const [
|
|
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),
|
|
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
|
|
373
|
-
n((W) => P ?
|
|
374
|
-
} catch (
|
|
375
|
-
v(
|
|
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
|
-
}, [
|
|
379
|
+
}, [d, l]);
|
|
380
380
|
X(() => {
|
|
381
381
|
N(1, !0);
|
|
382
382
|
}, [N]);
|
|
383
|
-
const
|
|
384
|
-
clearTimeout(
|
|
385
|
-
},
|
|
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) =>
|
|
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
|
-
|
|
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:
|
|
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:
|
|
421
|
+
onSelect: $
|
|
422
422
|
},
|
|
423
423
|
b.id
|
|
424
424
|
)) }),
|
|
425
|
-
!p &&
|
|
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 &&
|
|
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(
|
|
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:
|
|
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":
|
|
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:
|
|
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:
|
|
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:
|
|
468
|
+
function _e({ onSelect: e, allowedTypes: t = [], multiple: o = !1, render: r }) {
|
|
469
469
|
var p;
|
|
470
|
-
const [n,
|
|
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
|
|
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:
|
|
482
|
+
title: c,
|
|
483
483
|
children: /* @__PURE__ */ f.jsx(
|
|
484
484
|
he,
|
|
485
485
|
{
|
|
486
486
|
onSelect: l,
|
|
487
487
|
allowedTypes: m,
|
|
488
|
-
allowUpload:
|
|
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
|
|
497
|
-
window.Bladeberg = window.Bladeberg ?? { _queue: [] }, window.Bladeberg._queue = window.Bladeberg._queue ?? [], (
|
|
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,
|
|
501
|
-
if (!((
|
|
502
|
-
(((
|
|
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
|
|
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
|
|
511
|
-
return t.appendChild(
|
|
510
|
+
const o = document.createElement("textarea");
|
|
511
|
+
return t.appendChild(o), o;
|
|
512
512
|
}
|
|
513
|
-
function
|
|
514
|
-
var
|
|
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(), (
|
|
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 = (
|
|
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:
|
|
535
|
-
settings:
|
|
534
|
+
value: o,
|
|
535
|
+
settings: r = {},
|
|
536
536
|
blockPrefix: n,
|
|
537
|
-
media:
|
|
537
|
+
media: a,
|
|
538
538
|
branding: s = !0,
|
|
539
|
-
contextMenu:
|
|
540
|
-
onChange:
|
|
539
|
+
contextMenu: i = !0,
|
|
540
|
+
onChange: c
|
|
541
541
|
} = e;
|
|
542
542
|
await Y(), ve();
|
|
543
|
-
const
|
|
544
|
-
l.dataset.bladebergMounted = "1",
|
|
545
|
-
const m =
|
|
546
|
-
window.wp.attachEditor(l, m), s && Q(u),
|
|
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
|
|
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 (
|
|
559
|
-
console.error("[BladeBerg] onChange handler error:",
|
|
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(() =>
|
|
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,
|