@bloklabs/react 1.3.0 → 1.4.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 +69 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +433 -244
- package/package.json +25 -4
- package/src/BlokEditor.tsx +3 -1
- package/src/BlokView.tsx +37 -0
- package/src/config-keys.ts +1 -0
- package/src/createReactInlineTool.tsx +185 -28
- package/src/index.ts +8 -1
- package/src/types.ts +5 -1
- package/src/useBlok.ts +80 -4
- package/src/useBlokReady.ts +60 -0
- package/src/useBlokView.ts +38 -0
- package/src/view-nodes-to-react.ts +138 -0
- package/types/index.d.ts +164 -12
package/dist/index.mjs
CHANGED
|
@@ -1,52 +1,53 @@
|
|
|
1
|
-
import { Component as e,
|
|
2
|
-
import { Blok as
|
|
3
|
-
import { DATA_ATTR as
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import { createPortal as
|
|
6
|
-
import {
|
|
1
|
+
import { Component as e, Fragment as t, createContext as n, createElement as r, forwardRef as i, isValidElement as a, useCallback as o, useContext as s, useEffect as c, useImperativeHandle as l, useMemo as u, useRef as d, useState as f, useSyncExternalStore as p } from "react";
|
|
2
|
+
import { Blok as m } from "@bloklabs/core";
|
|
3
|
+
import { DATA_ATTR as h, EMPTY_API as g, createBlocksApiForEditor as _, createEmittedEchoWindow as v, deepEqual as y, deepEqual as b, fillDefaults as x, markSanitizerConfig as S, mountChildBlocks as C, normalizeReadOnlyConfig as ee } from "@bloklabs/core/adapters";
|
|
4
|
+
import { Fragment as w, jsx as T } from "react/jsx-runtime";
|
|
5
|
+
import { createPortal as E, flushSync as D } from "react-dom";
|
|
6
|
+
import { blocksToViewNodes as O } from "@bloklabs/core/view";
|
|
7
|
+
import { createRoot as k } from "react-dom/client";
|
|
7
8
|
//#region src/holder-map.ts
|
|
8
|
-
var
|
|
9
|
-
function
|
|
10
|
-
|
|
9
|
+
var A = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function te(e, t) {
|
|
11
|
+
A.set(e, t);
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
return
|
|
13
|
+
function j(e) {
|
|
14
|
+
return A.get(e);
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
16
|
+
function M(e) {
|
|
17
|
+
A.delete(e);
|
|
17
18
|
}
|
|
18
19
|
//#endregion
|
|
19
20
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
|
|
20
|
-
function
|
|
21
|
+
function N(e) {
|
|
21
22
|
"@babel/helpers - typeof";
|
|
22
|
-
return
|
|
23
|
+
return N = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
23
24
|
return typeof e;
|
|
24
25
|
} : function(e) {
|
|
25
26
|
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
26
|
-
},
|
|
27
|
+
}, N(e);
|
|
27
28
|
}
|
|
28
29
|
//#endregion
|
|
29
30
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
|
|
30
|
-
function
|
|
31
|
-
if (
|
|
31
|
+
function P(e, t) {
|
|
32
|
+
if (N(e) != "object" || !e) return e;
|
|
32
33
|
var n = e[Symbol.toPrimitive];
|
|
33
34
|
if (n !== void 0) {
|
|
34
35
|
var r = n.call(e, t || "default");
|
|
35
|
-
if (
|
|
36
|
+
if (N(r) != "object") return r;
|
|
36
37
|
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
37
38
|
}
|
|
38
39
|
return (t === "string" ? String : Number)(e);
|
|
39
40
|
}
|
|
40
41
|
//#endregion
|
|
41
42
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
|
|
42
|
-
function
|
|
43
|
-
var t =
|
|
44
|
-
return
|
|
43
|
+
function F(e) {
|
|
44
|
+
var t = P(e, "string");
|
|
45
|
+
return N(t) == "symbol" ? t : t + "";
|
|
45
46
|
}
|
|
46
47
|
//#endregion
|
|
47
48
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
|
|
48
|
-
function
|
|
49
|
-
return (t =
|
|
49
|
+
function I(e, t, n) {
|
|
50
|
+
return (t = F(t)) in e ? Object.defineProperty(e, t, {
|
|
50
51
|
value: n,
|
|
51
52
|
enumerable: !0,
|
|
52
53
|
configurable: !0,
|
|
@@ -55,7 +56,7 @@ function N(e, t, n) {
|
|
|
55
56
|
}
|
|
56
57
|
//#endregion
|
|
57
58
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectSpread2.js
|
|
58
|
-
function
|
|
59
|
+
function L(e, t) {
|
|
59
60
|
var n = Object.keys(e);
|
|
60
61
|
if (Object.getOwnPropertySymbols) {
|
|
61
62
|
var r = Object.getOwnPropertySymbols(e);
|
|
@@ -65,12 +66,12 @@ function P(e, t) {
|
|
|
65
66
|
}
|
|
66
67
|
return n;
|
|
67
68
|
}
|
|
68
|
-
function
|
|
69
|
+
function R(e) {
|
|
69
70
|
for (var t = 1; t < arguments.length; t++) {
|
|
70
71
|
var n = arguments[t] == null ? {} : arguments[t];
|
|
71
|
-
t % 2 ?
|
|
72
|
-
|
|
73
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) :
|
|
72
|
+
t % 2 ? L(Object(n), !0).forEach(function(t) {
|
|
73
|
+
I(e, t, n[t]);
|
|
74
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : L(Object(n)).forEach(function(t) {
|
|
74
75
|
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
|
|
75
76
|
});
|
|
76
77
|
}
|
|
@@ -78,35 +79,35 @@ function F(e) {
|
|
|
78
79
|
}
|
|
79
80
|
//#endregion
|
|
80
81
|
//#region src/provide-blok.tsx
|
|
81
|
-
var
|
|
82
|
-
function
|
|
83
|
-
return /* @__PURE__ */
|
|
82
|
+
var z = n({});
|
|
83
|
+
function B({ defaults: e, children: t }) {
|
|
84
|
+
return /* @__PURE__ */ T(z.Provider, {
|
|
84
85
|
value: e,
|
|
85
86
|
children: t
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
function
|
|
89
|
-
return
|
|
89
|
+
function V() {
|
|
90
|
+
return s(z);
|
|
90
91
|
}
|
|
91
|
-
function
|
|
92
|
+
function ne(e, t) {
|
|
92
93
|
if (Object.keys(e).length === 0) return t;
|
|
93
|
-
let n =
|
|
94
|
+
let n = R({}, e);
|
|
94
95
|
for (let e of Object.keys(t)) {
|
|
95
96
|
let r = t[e];
|
|
96
97
|
r !== void 0 && (n[e] = r);
|
|
97
98
|
}
|
|
98
|
-
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools =
|
|
99
|
+
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = R(R({}, e.tools), t.tools)), n;
|
|
99
100
|
}
|
|
100
101
|
//#endregion
|
|
101
102
|
//#region src/block-portal-registry.ts
|
|
102
|
-
var
|
|
103
|
+
var H = "__blokPortalRegistry", U = "__blokToolName", W = () => {
|
|
103
104
|
let e = { snapshot: /* @__PURE__ */ new Map() }, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = (n) => {
|
|
104
105
|
e.snapshot = n, t.forEach((e) => e());
|
|
105
106
|
};
|
|
106
107
|
return {
|
|
107
108
|
register(t, i) {
|
|
108
109
|
let a = new Map(e.snapshot), o = i.toolName === void 0 ? void 0 : n.get(i.toolName);
|
|
109
|
-
a.set(t, o === void 0 ? i :
|
|
110
|
+
a.set(t, o === void 0 ? i : R(R({}, i), {}, { props: R(R({}, i.props), {}, { config: o }) })), r(a);
|
|
110
111
|
},
|
|
111
112
|
unregister(t) {
|
|
112
113
|
if (!e.snapshot.has(t)) return;
|
|
@@ -117,14 +118,14 @@ var z = "__blokPortalRegistry", B = "__blokToolName", V = () => {
|
|
|
117
118
|
let i = e.snapshot.get(t);
|
|
118
119
|
if (i === void 0) return;
|
|
119
120
|
let a = new Map(e.snapshot);
|
|
120
|
-
a.set(t,
|
|
121
|
+
a.set(t, R(R({}, i), {}, { props: R(R({}, i.props), n) })), r(a);
|
|
121
122
|
},
|
|
122
123
|
setToolConfig(t, i) {
|
|
123
124
|
n.set(t, i);
|
|
124
125
|
let a = [...e.snapshot].filter(([, e]) => e.toolName === t);
|
|
125
126
|
if (a.length === 0) return;
|
|
126
127
|
let o = new Map(e.snapshot);
|
|
127
|
-
for (let [e, t] of a) o.set(e,
|
|
128
|
+
for (let [e, t] of a) o.set(e, R(R({}, t), {}, { props: R(R({}, t.props), {}, { config: i }) }));
|
|
128
129
|
r(o);
|
|
129
130
|
},
|
|
130
131
|
subscribe(e) {
|
|
@@ -136,45 +137,45 @@ var z = "__blokPortalRegistry", B = "__blokToolName", V = () => {
|
|
|
136
137
|
return e.snapshot;
|
|
137
138
|
}
|
|
138
139
|
};
|
|
139
|
-
},
|
|
140
|
-
function
|
|
141
|
-
|
|
140
|
+
}, G = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
function re(e, t) {
|
|
142
|
+
G.set(e, t);
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
-
return
|
|
144
|
+
function ie(e) {
|
|
145
|
+
return G.get(e);
|
|
145
146
|
}
|
|
146
|
-
function
|
|
147
|
-
|
|
147
|
+
function K(e) {
|
|
148
|
+
G.delete(e);
|
|
148
149
|
}
|
|
149
150
|
//#endregion
|
|
150
151
|
//#region src/live-tool-config.ts
|
|
151
|
-
var
|
|
152
|
+
var q = (e) => {
|
|
152
153
|
if (typeof e != "object" || !e) return !1;
|
|
153
154
|
let t = Object.getPrototypeOf(e);
|
|
154
155
|
return t === Object.prototype || t === null;
|
|
155
|
-
},
|
|
156
|
+
}, ae = (e, t) => t.reduce((e, t) => {
|
|
156
157
|
if (Array.isArray(e)) return typeof t == "number" ? e[t] : void 0;
|
|
157
|
-
if (
|
|
158
|
-
}, e),
|
|
158
|
+
if (q(e)) return e[t];
|
|
159
|
+
}, e), oe = (e, t) => {
|
|
159
160
|
let n = (e, t) => {
|
|
160
161
|
if (typeof e == "function") return typeof t == "function" ? t : e;
|
|
161
162
|
if (Array.isArray(e)) {
|
|
162
163
|
let r = Array.isArray(t) ? t : [];
|
|
163
164
|
return e.map((e, t) => n(e, r[t]));
|
|
164
165
|
}
|
|
165
|
-
if (
|
|
166
|
-
let r =
|
|
166
|
+
if (q(e)) {
|
|
167
|
+
let r = q(t) ? t : {}, i = {};
|
|
167
168
|
for (let [t, a] of Object.entries(e)) i[t] = n(a, r[t]);
|
|
168
169
|
return i;
|
|
169
170
|
}
|
|
170
171
|
return e;
|
|
171
172
|
}, r = n(t, e);
|
|
172
|
-
return
|
|
173
|
-
},
|
|
174
|
-
if (!
|
|
173
|
+
return q(r) ? r : {};
|
|
174
|
+
}, se = (e, t) => {
|
|
175
|
+
if (!q(e)) return e;
|
|
175
176
|
let n = {};
|
|
176
177
|
for (let [r, i] of Object.entries(e)) {
|
|
177
|
-
if (!
|
|
178
|
+
if (!q(i) || !q(i.config)) {
|
|
178
179
|
n[r] = i;
|
|
179
180
|
continue;
|
|
180
181
|
}
|
|
@@ -182,12 +183,12 @@ var K = (e) => {
|
|
|
182
183
|
if (typeof n == "function") {
|
|
183
184
|
let e = n;
|
|
184
185
|
return function(...n) {
|
|
185
|
-
let a = t(), o =
|
|
186
|
+
let a = t(), o = q(a) ? a[r] : void 0, s = ae(q(o) ? o.config : void 0, i);
|
|
186
187
|
return Reflect.apply(typeof s == "function" ? s : e, this, n);
|
|
187
188
|
};
|
|
188
189
|
}
|
|
189
190
|
if (Array.isArray(n)) return e.has(n) ? n : (e.add(n), n.map((e, t) => a(e, [...i, t])));
|
|
190
|
-
if (
|
|
191
|
+
if (q(n)) {
|
|
191
192
|
if (e.has(n)) return n;
|
|
192
193
|
e.add(n);
|
|
193
194
|
let t = {};
|
|
@@ -196,171 +197,191 @@ var K = (e) => {
|
|
|
196
197
|
}
|
|
197
198
|
return n;
|
|
198
199
|
};
|
|
199
|
-
n[r] =
|
|
200
|
+
n[r] = R(R({}, i), {}, { config: a(i.config, []) });
|
|
200
201
|
}
|
|
201
202
|
return n;
|
|
202
|
-
},
|
|
203
|
+
}, J = (e) => {
|
|
203
204
|
let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
|
|
204
205
|
return typeof t == "function" && t.__isBlokReactBlock === !0;
|
|
205
|
-
},
|
|
206
|
+
}, ce = (e) => {
|
|
206
207
|
let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
|
|
207
208
|
return typeof t == "function" && t.__isBlokReactInlineTool === !0;
|
|
208
|
-
},
|
|
209
|
+
}, le = (e, t) => {
|
|
209
210
|
if (typeof e != "object" || !e) return e;
|
|
210
211
|
let n = {};
|
|
211
212
|
for (let [i, a] of Object.entries(e)) {
|
|
212
213
|
var r;
|
|
213
|
-
if (!
|
|
214
|
+
if (!J(a) && !ce(a)) {
|
|
214
215
|
n[i] = a;
|
|
215
216
|
continue;
|
|
216
217
|
}
|
|
217
|
-
let e = typeof a == "function" ? { class: a } :
|
|
218
|
-
e.config =
|
|
219
|
-
[
|
|
220
|
-
[
|
|
218
|
+
let e = typeof a == "function" ? { class: a } : R({}, a);
|
|
219
|
+
e.config = R(R({}, (r = e.config) == null ? {} : r), {}, {
|
|
220
|
+
[H]: t,
|
|
221
|
+
[U]: i
|
|
221
222
|
}), n[i] = e;
|
|
222
223
|
}
|
|
223
224
|
return n;
|
|
224
225
|
};
|
|
225
|
-
function
|
|
226
|
+
function Y(e, t) {
|
|
226
227
|
var n, r;
|
|
227
|
-
let i =
|
|
228
|
-
|
|
229
|
-
let
|
|
228
|
+
let i = ne(s(z), e), [a, o] = f(null), l = d(i);
|
|
229
|
+
l.current = i;
|
|
230
|
+
let p = d({
|
|
230
231
|
editor: null,
|
|
231
232
|
holder: null,
|
|
232
233
|
destroyTimeout: null,
|
|
233
234
|
isDestroyed: !1,
|
|
234
235
|
isEditorReady: !1,
|
|
235
236
|
depsToken: null
|
|
236
|
-
}), h =
|
|
237
|
-
|
|
237
|
+
}), h = u(() => ({}), t == null ? [] : t), g = d(i.data), _ = d(v()), y = d(null), x = d(i.data), S = d(Promise.resolve()), C = d(void 0), w = d(null), T = d(void 0), E = d(/* @__PURE__ */ new Map()), D = d(/* @__PURE__ */ new Map());
|
|
238
|
+
c(() => {
|
|
238
239
|
var e;
|
|
239
240
|
if (typeof window > "u") return;
|
|
240
|
-
let t =
|
|
241
|
-
if (t.destroyTimeout !== null && (clearTimeout(t.destroyTimeout), t.destroyTimeout = null), t.editor !== null && !t.isDestroyed && t.depsToken === h) return t.isEditorReady &&
|
|
242
|
-
|
|
241
|
+
let t = p.current;
|
|
242
|
+
if (t.destroyTimeout !== null && (clearTimeout(t.destroyTimeout), t.destroyTimeout = null), t.editor !== null && !t.isDestroyed && t.depsToken === h) return t.isEditorReady && o(t.editor), () => {
|
|
243
|
+
X(t, o);
|
|
243
244
|
};
|
|
244
245
|
if (t.editor !== null && !t.isDestroyed) {
|
|
245
|
-
|
|
246
|
+
M(t.editor), K(t.editor);
|
|
246
247
|
try {
|
|
247
248
|
t.editor.destroy();
|
|
248
249
|
} catch (e) {}
|
|
249
|
-
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1,
|
|
250
|
+
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, o(null);
|
|
250
251
|
}
|
|
251
252
|
let n = document.createElement("div");
|
|
252
253
|
t.holder = n, t.isDestroyed = !1, t.isEditorReady = !1, t.depsToken = h;
|
|
253
|
-
let r =
|
|
254
|
-
|
|
255
|
-
let
|
|
254
|
+
let r = l.current, i = W(), a = r.tools === void 0 ? void 0 : se(r.tools, () => l.current.tools), s = a === void 0 ? void 0 : le(a, i);
|
|
255
|
+
w.current = i, T.current = a, E.current = /* @__PURE__ */ new Map(), D.current = new Map(Object.entries((e = r.tools) == null ? {} : e).map(([e, t]) => [e, typeof t == "object" && t ? t.toolbox : void 0]));
|
|
256
|
+
let c = R(R(R({}, r), s === void 0 ? {} : { tools: s }), {}, {
|
|
256
257
|
holder: n,
|
|
257
258
|
onReady: (...e) => {
|
|
258
259
|
var t, n;
|
|
259
|
-
(t = (n =
|
|
260
|
+
(t = (n = l.current).onReady) == null || t.call(n, ...e);
|
|
260
261
|
},
|
|
261
262
|
onChange: (...e) => {
|
|
262
263
|
var t, n;
|
|
263
|
-
(t = (n =
|
|
264
|
+
(t = (n = l.current).onChange) == null || t.call(n, ...e);
|
|
264
265
|
},
|
|
265
266
|
onEnter: (...e) => {
|
|
266
267
|
var t, n;
|
|
267
|
-
return (t = (n =
|
|
268
|
+
return (t = (n = l.current).onEnter) == null ? void 0 : t.call(n, ...e);
|
|
268
269
|
}
|
|
269
270
|
});
|
|
270
|
-
r.onSave && (
|
|
271
|
+
r.onSave && (c.onSave = (...e) => {
|
|
271
272
|
var t, n;
|
|
272
|
-
|
|
273
|
-
}), r.onBeforeRender && (
|
|
273
|
+
g.current = e[0], _.current.record(e[0]), (t = (n = l.current).onSave) == null || t.call(n, ...e);
|
|
274
|
+
}), r.onBeforeRender && (c.onBeforeRender = (...e) => {
|
|
274
275
|
var t, n, r;
|
|
275
|
-
return (t = (n = (r =
|
|
276
|
-
}), r.onAfterRender && (
|
|
276
|
+
return (t = (n = (r = l.current).onBeforeRender) == null ? void 0 : n.call(r, ...e)) == null ? e[0] : t;
|
|
277
|
+
}), r.onAfterRender && (c.onAfterRender = (...e) => {
|
|
277
278
|
var t, n;
|
|
278
|
-
(t = (n =
|
|
279
|
+
(t = (n = l.current).onAfterRender) == null || t.call(n, ...e);
|
|
279
280
|
});
|
|
280
|
-
let
|
|
281
|
-
return t.editor =
|
|
282
|
-
t.editor ===
|
|
281
|
+
let u = new m(c);
|
|
282
|
+
return t.editor = u, x.current = r.data, te(u, n), re(u, i), u.isReady.then(() => {
|
|
283
|
+
t.editor === u && !t.isDestroyed && (t.isEditorReady = !0, o(u));
|
|
283
284
|
}).catch(() => {
|
|
284
|
-
if (t.editor ===
|
|
285
|
-
|
|
285
|
+
if (t.editor === u && !t.isDestroyed) {
|
|
286
|
+
M(u), K(u);
|
|
286
287
|
try {
|
|
287
|
-
|
|
288
|
+
u.destroy();
|
|
288
289
|
} catch (e) {}
|
|
289
|
-
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1,
|
|
290
|
+
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, o(null);
|
|
290
291
|
}
|
|
291
292
|
}), () => {
|
|
292
|
-
|
|
293
|
+
X(t, o);
|
|
293
294
|
};
|
|
294
|
-
}, [h]),
|
|
295
|
-
let e =
|
|
295
|
+
}, [h]), c(() => {
|
|
296
|
+
let e = w.current, t = p.current;
|
|
296
297
|
if (e === null || t.editor === null || t.isDestroyed) return;
|
|
297
|
-
let n =
|
|
298
|
+
let n = l.current.tools;
|
|
298
299
|
if (typeof n != "object" || !n) return;
|
|
299
|
-
let r =
|
|
300
|
+
let r = T.current;
|
|
300
301
|
for (let [t, a] of Object.entries(n)) {
|
|
301
302
|
var i;
|
|
302
|
-
if (!
|
|
303
|
-
let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s =
|
|
304
|
-
if (c !== void 0 &&
|
|
303
|
+
if (!J(a)) continue;
|
|
304
|
+
let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s = oe(typeof o == "object" && o ? o.config : void 0, n), c = E.current.get(t);
|
|
305
|
+
if (c !== void 0 && b(s, c)) continue;
|
|
305
306
|
let l = Object.freeze(s);
|
|
306
|
-
|
|
307
|
+
E.current.set(t, l), e.setToolConfig(t, l);
|
|
307
308
|
}
|
|
308
|
-
}),
|
|
309
|
-
let e =
|
|
309
|
+
}), c(() => {
|
|
310
|
+
let e = p.current;
|
|
310
311
|
if (e.editor === null || e.isDestroyed || !e.isEditorReady) return;
|
|
311
|
-
let t =
|
|
312
|
+
let t = l.current.tools;
|
|
312
313
|
if (!(typeof t != "object" || !t)) for (let [r, i] of Object.entries(t)) {
|
|
313
314
|
var n;
|
|
314
|
-
if (!
|
|
315
|
+
if (!D.current.has(r)) continue;
|
|
315
316
|
let t = typeof i == "object" && i ? i.toolbox : void 0;
|
|
316
|
-
|
|
317
|
+
b(t, D.current.get(r)) || (D.current.set(r, t), (n = e.editor.tools) == null || n.update(r, { toolbox: t }));
|
|
317
318
|
}
|
|
318
319
|
});
|
|
319
|
-
let A =
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}, [
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
320
|
+
let O = typeof i.readOnly == "object" && i.readOnly !== null, { enabled: k, hideControls: A } = ee(i.readOnly);
|
|
321
|
+
c(() => {
|
|
322
|
+
a !== null && (O ? a.readOnly.set(k, { hideControls: A }) : a.readOnly.set(k));
|
|
323
|
+
}, [
|
|
324
|
+
a,
|
|
325
|
+
k,
|
|
326
|
+
A,
|
|
327
|
+
O
|
|
328
|
+
]);
|
|
329
|
+
let { hideToolbar: j } = i;
|
|
330
|
+
c(() => {
|
|
331
|
+
a === null || j === void 0 || a.toolbar.setHidden(j);
|
|
332
|
+
}, [a, j]);
|
|
333
|
+
let { inlineToolbar: N } = i;
|
|
334
|
+
c(() => {
|
|
335
|
+
a === null || N === void 0 || a.tools.setInlineToolbar(N);
|
|
336
|
+
}, [a, N === void 0 ? void 0 : JSON.stringify(N)]);
|
|
337
|
+
let { autofocus: P } = i;
|
|
338
|
+
c(() => {
|
|
339
|
+
a === null || !P || a.focus();
|
|
340
|
+
}, [a, P]);
|
|
341
|
+
let { theme: F } = i;
|
|
342
|
+
c(() => {
|
|
343
|
+
a === null || F === void 0 || a.theme.set(F);
|
|
344
|
+
}, [a, F]);
|
|
345
|
+
let { width: I } = i;
|
|
346
|
+
c(() => {
|
|
347
|
+
a === null || I === void 0 || a.width.set(I);
|
|
348
|
+
}, [a, I]);
|
|
349
|
+
let L = (n = i.style) == null ? void 0 : n.tokens, B = d((r = i.style) == null ? void 0 : r.tokens);
|
|
350
|
+
c(() => {
|
|
351
|
+
a === null || L === void 0 || b(L, B.current) || (B.current = L, a.tokens.set(L));
|
|
352
|
+
}, [a, L]);
|
|
353
|
+
let { i18n: V } = i, H = d(i.i18n);
|
|
354
|
+
c(() => {
|
|
355
|
+
if (a === null || V === void 0 || b(V, H.current)) return;
|
|
356
|
+
H.current = V;
|
|
357
|
+
let { locale: e, messages: t, direction: n } = V;
|
|
358
|
+
a.i18n.update(R(R(R({}, e === void 0 ? {} : { locale: e }), t === void 0 ? {} : { messages: t }), n === void 0 ? {} : { direction: n }));
|
|
359
|
+
}, [a, V]);
|
|
360
|
+
let { placeholder: U } = i;
|
|
361
|
+
c(() => {
|
|
362
|
+
a === null || U === void 0 || a.placeholder.set(U);
|
|
363
|
+
}, [a, U]);
|
|
364
|
+
let { data: G } = i;
|
|
365
|
+
return c(() => {
|
|
366
|
+
if (a === null || G === void 0) return;
|
|
367
|
+
let e = p.current;
|
|
368
|
+
if (!(e.editor !== a || e.isDestroyed)) {
|
|
369
|
+
if (y.current !== a && (y.current = a, C.current = void 0, _.current.clear(), b(G, x.current))) {
|
|
370
|
+
g.current = G;
|
|
350
371
|
return;
|
|
351
372
|
}
|
|
352
|
-
|
|
353
|
-
|
|
373
|
+
b(G, g.current) || b(G, C.current) || _.current.matches(G) || (_.current.clear(), C.current = G, S.current = S.current.catch(() => void 0).then(() => a.render(G)).then(() => {
|
|
374
|
+
g.current = G;
|
|
354
375
|
}, () => {}).then(() => {
|
|
355
|
-
|
|
376
|
+
C.current === G && (C.current = void 0);
|
|
356
377
|
}));
|
|
357
378
|
}
|
|
358
|
-
}, [
|
|
379
|
+
}, [a, G]), a;
|
|
359
380
|
}
|
|
360
|
-
function
|
|
381
|
+
function X(e, t) {
|
|
361
382
|
e.destroyTimeout = setTimeout(() => {
|
|
362
383
|
if (e.editor !== null) {
|
|
363
|
-
|
|
384
|
+
M(e.editor), K(e.editor);
|
|
364
385
|
try {
|
|
365
386
|
e.editor.destroy();
|
|
366
387
|
} catch (e) {}
|
|
@@ -370,7 +391,7 @@ function Y(e, t) {
|
|
|
370
391
|
}
|
|
371
392
|
//#endregion
|
|
372
393
|
//#region src/BlockPortalHost.tsx
|
|
373
|
-
var
|
|
394
|
+
var ue = class extends e {
|
|
374
395
|
constructor(...e) {
|
|
375
396
|
super(...e), this.state = { failed: !1 };
|
|
376
397
|
}
|
|
@@ -382,16 +403,16 @@ var se = class extends e {
|
|
|
382
403
|
return this.state.failed ? null : this.props.children;
|
|
383
404
|
}
|
|
384
405
|
};
|
|
385
|
-
function
|
|
386
|
-
let t =
|
|
387
|
-
return /* @__PURE__ */
|
|
406
|
+
function Z({ registry: e }) {
|
|
407
|
+
let t = p(e.subscribe, e.getSnapshot, e.getSnapshot);
|
|
408
|
+
return /* @__PURE__ */ T(w, { children: Array.from(t.entries()).map(([e, t]) => {
|
|
388
409
|
let n = t.component;
|
|
389
|
-
return
|
|
410
|
+
return E(/* @__PURE__ */ T(ue, { children: /* @__PURE__ */ T(n, R({}, t.props)) }), t.hostEl, e);
|
|
390
411
|
}) });
|
|
391
412
|
}
|
|
392
413
|
//#endregion
|
|
393
414
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
394
|
-
function
|
|
415
|
+
function de(e, t) {
|
|
395
416
|
if (e == null) return {};
|
|
396
417
|
var n = {};
|
|
397
418
|
for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
|
|
@@ -402,9 +423,9 @@ function ce(e, t) {
|
|
|
402
423
|
}
|
|
403
424
|
//#endregion
|
|
404
425
|
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutProperties.js
|
|
405
|
-
function
|
|
426
|
+
function Q(e, t) {
|
|
406
427
|
if (e == null) return {};
|
|
407
|
-
var n, r, i =
|
|
428
|
+
var n, r, i = de(e, t);
|
|
408
429
|
if (Object.getOwnPropertySymbols) {
|
|
409
430
|
var a = Object.getOwnPropertySymbols(e);
|
|
410
431
|
for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
|
|
@@ -413,51 +434,51 @@ function Z(e, t) {
|
|
|
413
434
|
}
|
|
414
435
|
//#endregion
|
|
415
436
|
//#region src/BlokContent.tsx
|
|
416
|
-
var
|
|
417
|
-
let { editor: n } = e, r =
|
|
437
|
+
var fe = ["editor"], pe = i(function(e, t) {
|
|
438
|
+
let { editor: n } = e, r = Q(e, fe), i = d(null), a = (e) => {
|
|
418
439
|
if (i.current = e, typeof t == "function") t(e);
|
|
419
440
|
else if (t != null) {
|
|
420
441
|
let n = t;
|
|
421
442
|
n.current = e;
|
|
422
443
|
}
|
|
423
444
|
};
|
|
424
|
-
|
|
445
|
+
c(() => {
|
|
425
446
|
if (n === null || i.current === null) return;
|
|
426
|
-
let e =
|
|
447
|
+
let e = j(n);
|
|
427
448
|
if (e !== void 0) return i.current.appendChild(e), () => {
|
|
428
449
|
e.remove();
|
|
429
450
|
};
|
|
430
451
|
}, [n]);
|
|
431
|
-
let
|
|
432
|
-
return /* @__PURE__ */
|
|
433
|
-
}),
|
|
452
|
+
let o = n === null ? void 0 : ie(n);
|
|
453
|
+
return /* @__PURE__ */ T("div", R(R({ ref: a }, r), {}, { children: o === void 0 ? null : /* @__PURE__ */ T(Z, { registry: o }) }));
|
|
454
|
+
}), me = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onError.onEnter.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width".split("."), he = [
|
|
434
455
|
"deps",
|
|
435
456
|
"onReady",
|
|
436
457
|
"onBlocksRendered",
|
|
437
458
|
"onBlockRendered"
|
|
438
|
-
],
|
|
439
|
-
let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: a } = e,
|
|
440
|
-
for (let e of Object.keys(
|
|
441
|
-
let t =
|
|
442
|
-
|
|
459
|
+
], ge = new Set(me), _e = i(function(e, t) {
|
|
460
|
+
let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: a } = e, o = Q(e, he), s = {}, u = {};
|
|
461
|
+
for (let e of Object.keys(o)) {
|
|
462
|
+
let t = o[e];
|
|
463
|
+
ge.has(e) ? s[e] = t : u[e] = t;
|
|
443
464
|
}
|
|
444
|
-
let f =
|
|
445
|
-
|
|
446
|
-
let p =
|
|
465
|
+
let f = Y(s, n);
|
|
466
|
+
l(t, () => f, [f]);
|
|
467
|
+
let p = d(r);
|
|
447
468
|
p.current = r;
|
|
448
|
-
let m =
|
|
449
|
-
|
|
469
|
+
let m = d(null);
|
|
470
|
+
c(() => {
|
|
450
471
|
if (f !== null && m.current !== f) {
|
|
451
472
|
var e;
|
|
452
473
|
m.current = f, (e = p.current) == null || e.call(p, f);
|
|
453
474
|
}
|
|
454
475
|
}, [f]);
|
|
455
|
-
let h =
|
|
476
|
+
let h = d(i);
|
|
456
477
|
h.current = i;
|
|
457
|
-
let g =
|
|
478
|
+
let g = d(a);
|
|
458
479
|
g.current = a;
|
|
459
480
|
let _ = !!i, v = !!a;
|
|
460
|
-
return
|
|
481
|
+
return c(() => {
|
|
461
482
|
if (f === null) return;
|
|
462
483
|
let e = [];
|
|
463
484
|
if (_) {
|
|
@@ -481,65 +502,192 @@ var le = ["editor"], Q = n(function(e, t) {
|
|
|
481
502
|
f,
|
|
482
503
|
_,
|
|
483
504
|
v
|
|
484
|
-
]), /* @__PURE__ */
|
|
485
|
-
}),
|
|
486
|
-
function
|
|
487
|
-
let t =
|
|
505
|
+
]), /* @__PURE__ */ T(pe, R({ editor: f }, u));
|
|
506
|
+
}), ve = "block changed";
|
|
507
|
+
function ye(e) {
|
|
508
|
+
let t = d(0), n = d(e);
|
|
488
509
|
n.current !== e && (n.current = e, t.current = 0);
|
|
489
|
-
let r =
|
|
510
|
+
let r = o((n) => {
|
|
490
511
|
if (e === null) return () => void 0;
|
|
491
512
|
let r = () => {
|
|
492
513
|
t.current += 1, n();
|
|
493
514
|
};
|
|
494
|
-
return e.on(
|
|
495
|
-
}, [e]),
|
|
496
|
-
return
|
|
515
|
+
return e.on(ve, r), () => e.off(ve, r);
|
|
516
|
+
}, [e]), i = o(() => t.current, []);
|
|
517
|
+
return p(r, i, i), u(() => e === null ? g : _(e), [e]);
|
|
518
|
+
}
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/useBlokReady.ts
|
|
521
|
+
function be(e = {}) {
|
|
522
|
+
let { within: t, settleOn: n } = e, [r, i] = f(!1);
|
|
523
|
+
return c(() => {
|
|
524
|
+
let e = () => {
|
|
525
|
+
var e;
|
|
526
|
+
let r = t instanceof Element ? t : (e = t == null ? void 0 : t.current) == null ? null : e;
|
|
527
|
+
i(t !== void 0 && r === null ? !1 : m.readyState({
|
|
528
|
+
within: r,
|
|
529
|
+
settleOn: n
|
|
530
|
+
}).ready);
|
|
531
|
+
};
|
|
532
|
+
return e(), m.subscribeReady(e);
|
|
533
|
+
}, [t, n]), r;
|
|
497
534
|
}
|
|
498
535
|
//#endregion
|
|
499
|
-
//#region src/
|
|
500
|
-
var
|
|
501
|
-
|
|
536
|
+
//#region src/view-nodes-to-react.ts
|
|
537
|
+
var xe = /* @__PURE__ */ new Set([
|
|
538
|
+
"area",
|
|
539
|
+
"base",
|
|
540
|
+
"br",
|
|
541
|
+
"col",
|
|
542
|
+
"embed",
|
|
543
|
+
"hr",
|
|
544
|
+
"img",
|
|
545
|
+
"input",
|
|
546
|
+
"link",
|
|
547
|
+
"meta",
|
|
548
|
+
"param",
|
|
549
|
+
"source",
|
|
550
|
+
"track",
|
|
551
|
+
"wbr"
|
|
552
|
+
]), Se = /* @__PURE__ */ new Set([
|
|
553
|
+
"disabled",
|
|
554
|
+
"open",
|
|
555
|
+
"controls",
|
|
556
|
+
"autoplay",
|
|
557
|
+
"loop",
|
|
558
|
+
"muted",
|
|
559
|
+
"required",
|
|
560
|
+
"multiple",
|
|
561
|
+
"playsinline",
|
|
562
|
+
"reversed",
|
|
563
|
+
"hidden",
|
|
564
|
+
"default",
|
|
565
|
+
"novalidate",
|
|
566
|
+
"allowfullscreen",
|
|
567
|
+
"itemscope"
|
|
568
|
+
]), Ce = {
|
|
569
|
+
class: "className",
|
|
570
|
+
for: "htmlFor",
|
|
571
|
+
colspan: "colSpan",
|
|
572
|
+
rowspan: "rowSpan",
|
|
573
|
+
tabindex: "tabIndex",
|
|
574
|
+
readonly: "readOnly",
|
|
575
|
+
srcset: "srcSet",
|
|
576
|
+
srclang: "srcLang",
|
|
577
|
+
datetime: "dateTime",
|
|
578
|
+
autoplay: "autoPlay",
|
|
579
|
+
playsinline: "playsInline",
|
|
580
|
+
novalidate: "noValidate",
|
|
581
|
+
allowfullscreen: "allowFullScreen",
|
|
582
|
+
crossorigin: "crossOrigin",
|
|
583
|
+
referrerpolicy: "referrerPolicy",
|
|
584
|
+
contenteditable: "contentEditable",
|
|
585
|
+
spellcheck: "spellCheck",
|
|
586
|
+
maxlength: "maxLength",
|
|
587
|
+
minlength: "minLength",
|
|
588
|
+
usemap: "useMap",
|
|
589
|
+
itemscope: "itemScope"
|
|
590
|
+
}, we = (e) => {
|
|
591
|
+
let t = {};
|
|
592
|
+
for (let n of e.split(";")) {
|
|
593
|
+
let e = n.indexOf(":");
|
|
594
|
+
if (e === -1) continue;
|
|
595
|
+
let r = n.slice(0, e).trim(), i = n.slice(e + 1).trim();
|
|
596
|
+
if (r === "" || i === "") continue;
|
|
597
|
+
let a = r.startsWith("--") ? r : r.toLowerCase().replace(/-([a-z])/g, (e, t) => t.toUpperCase());
|
|
598
|
+
t[a] = i;
|
|
599
|
+
}
|
|
600
|
+
return t;
|
|
601
|
+
}, Te = (e, t) => {
|
|
602
|
+
let n = { key: t };
|
|
603
|
+
for (let [t, a] of Object.entries(e)) {
|
|
604
|
+
var r;
|
|
605
|
+
if (t === "style") {
|
|
606
|
+
n.style = we(a);
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
if (t === "checked") {
|
|
610
|
+
n.defaultChecked = !0;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (t === "value") {
|
|
614
|
+
n.defaultValue = a;
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (Se.has(t)) {
|
|
618
|
+
var i;
|
|
619
|
+
n[(i = Ce[t]) == null ? t : i] = !0;
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
n[(r = Ce[t]) == null ? t : r] = a;
|
|
623
|
+
}
|
|
624
|
+
return n;
|
|
625
|
+
}, Ee = (e) => e.map((e, t) => {
|
|
626
|
+
if ("text" in e) return e.text;
|
|
627
|
+
let n = Te(e.attrs, t);
|
|
628
|
+
return xe.has(e.tag) || e.children.length === 0 ? r(e.tag, n) : r(e.tag, n, ...Ee(e.children));
|
|
629
|
+
}), De = (e, n) => {
|
|
630
|
+
let i = n == null ? void 0 : n.schema, a = n == null ? void 0 : n.renderers, o = n == null ? void 0 : n.onUnknownBlock;
|
|
631
|
+
return u(() => r(t, null, ...Ee(O(e, {
|
|
632
|
+
schema: i,
|
|
633
|
+
renderers: a,
|
|
634
|
+
onUnknownBlock: o
|
|
635
|
+
}))), [
|
|
636
|
+
e,
|
|
637
|
+
i,
|
|
638
|
+
a,
|
|
639
|
+
o
|
|
640
|
+
]);
|
|
641
|
+
}, Oe = ({ data: e, schema: t, renderers: n, onUnknownBlock: r, className: i }) => /* @__PURE__ */ T("div", {
|
|
642
|
+
className: i,
|
|
643
|
+
children: De(e, {
|
|
644
|
+
schema: t,
|
|
645
|
+
renderers: n,
|
|
646
|
+
onUnknownBlock: r
|
|
647
|
+
})
|
|
648
|
+
}), ke = ["commit", "readOnly"], Ae = [H, U];
|
|
649
|
+
function je(e) {
|
|
502
650
|
var t;
|
|
503
651
|
let n = (e) => {
|
|
504
652
|
if (typeof document > "u") return null;
|
|
505
|
-
let t = document.createElement("div"), n =
|
|
506
|
-
|
|
653
|
+
let t = document.createElement("div"), n = k(t);
|
|
654
|
+
D(() => {
|
|
507
655
|
n.render(e);
|
|
508
656
|
});
|
|
509
657
|
let r = t.innerHTML;
|
|
510
658
|
return n.unmount(), r === "" ? null : r;
|
|
511
|
-
},
|
|
512
|
-
let t = { complete: !0 },
|
|
513
|
-
if (!
|
|
514
|
-
let
|
|
515
|
-
return
|
|
659
|
+
}, r = () => {
|
|
660
|
+
let t = { complete: !0 }, r = (e) => {
|
|
661
|
+
if (!a(e.icon)) return e;
|
|
662
|
+
let r = n(e.icon);
|
|
663
|
+
return r === null ? (t.complete = !1, e) : R(R({}, e), {}, { icon: r });
|
|
516
664
|
};
|
|
517
665
|
return e.toolbox === void 0 ? {
|
|
518
666
|
value: void 0,
|
|
519
667
|
complete: t.complete
|
|
520
668
|
} : {
|
|
521
|
-
value: Array.isArray(e.toolbox) ? e.toolbox.map(
|
|
669
|
+
value: Array.isArray(e.toolbox) ? e.toolbox.map(r) : r(e.toolbox),
|
|
522
670
|
complete: t.complete
|
|
523
671
|
};
|
|
524
|
-
},
|
|
672
|
+
}, i = {
|
|
525
673
|
resolved: !1,
|
|
526
674
|
value: void 0
|
|
527
|
-
},
|
|
528
|
-
if (
|
|
529
|
-
let { value: e, complete: t } =
|
|
530
|
-
return t && (
|
|
531
|
-
},
|
|
675
|
+
}, o = () => {
|
|
676
|
+
if (i.resolved) return i.value;
|
|
677
|
+
let { value: e, complete: t } = r();
|
|
678
|
+
return t && (i.value = e, i.resolved = !0), e;
|
|
679
|
+
}, s = e.viewComponent === void 0 ? e.component : (t) => {
|
|
532
680
|
let n = e.viewComponent;
|
|
533
681
|
if (t.readOnly && n !== void 0) {
|
|
534
682
|
let { commit: e, readOnly: r } = t;
|
|
535
|
-
return /* @__PURE__ */
|
|
683
|
+
return /* @__PURE__ */ T(n, R({}, Q(t, ke)));
|
|
536
684
|
}
|
|
537
685
|
let r = e.component;
|
|
538
|
-
return /* @__PURE__ */
|
|
686
|
+
return /* @__PURE__ */ T(r, R({}, t));
|
|
539
687
|
};
|
|
540
688
|
return t = class {
|
|
541
689
|
static get toolbox() {
|
|
542
|
-
return
|
|
690
|
+
return o();
|
|
543
691
|
}
|
|
544
692
|
static get isReadOnlySupported() {
|
|
545
693
|
return !0;
|
|
@@ -548,29 +696,29 @@ function _e(e) {
|
|
|
548
696
|
var n, r;
|
|
549
697
|
this.hostEl = null, this.pendingDispatch = !1, this.commit = (t) => {
|
|
550
698
|
var n;
|
|
551
|
-
let r =
|
|
552
|
-
|
|
699
|
+
let r = x(e.propSchema, R(R({}, this.mirror), t));
|
|
700
|
+
y(r, this.mirror) || (this.mirror = r, this.lastRendered = r, (n = this.registry) == null || n.setProps(this.blockApi.id, { data: r }), this.flushDispatch());
|
|
553
701
|
}, this.blockApi = t.block;
|
|
554
702
|
let i = (n = t.config) == null ? {} : n;
|
|
555
|
-
this.registry = i[
|
|
556
|
-
let a = i[
|
|
703
|
+
this.registry = i[H];
|
|
704
|
+
let a = i[U];
|
|
557
705
|
this.toolName = typeof a == "string" ? a : void 0;
|
|
558
|
-
let
|
|
559
|
-
for (let [e, t] of Object.entries(i))
|
|
560
|
-
this.toolConfig = Object.freeze(
|
|
561
|
-
let
|
|
706
|
+
let o = {};
|
|
707
|
+
for (let [e, t] of Object.entries(i)) Ae.includes(e) || (o[e] = t);
|
|
708
|
+
this.toolConfig = Object.freeze(o);
|
|
709
|
+
let s = t.api;
|
|
562
710
|
this.pointerDrag = () => {
|
|
563
711
|
var e;
|
|
564
|
-
return (
|
|
565
|
-
}, this.mirror =
|
|
566
|
-
let
|
|
712
|
+
return (s == null || (e = s.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
|
|
713
|
+
}, this.mirror = x(e.propSchema, (r = t.data) == null ? {} : r), this.lastRendered = this.mirror, this.readOnly = t.readOnly;
|
|
714
|
+
let l = this.blockApi;
|
|
567
715
|
this.childrenComponent = function() {
|
|
568
|
-
let e =
|
|
569
|
-
return
|
|
570
|
-
e.current !== null &&
|
|
571
|
-
}), /* @__PURE__ */
|
|
716
|
+
let e = d(null);
|
|
717
|
+
return c(() => {
|
|
718
|
+
e.current !== null && C(e.current, l.getChildren());
|
|
719
|
+
}), /* @__PURE__ */ T("div", {
|
|
572
720
|
ref: e,
|
|
573
|
-
[
|
|
721
|
+
[h.nestedBlocks]: ""
|
|
574
722
|
});
|
|
575
723
|
};
|
|
576
724
|
}
|
|
@@ -579,7 +727,7 @@ function _e(e) {
|
|
|
579
727
|
let t = document.createElement("div");
|
|
580
728
|
return t.setAttribute("data-blok-mutation-free", "true"), this.hostEl = t, (e = this.registry) == null || e.register(this.blockApi.id, {
|
|
581
729
|
hostEl: t,
|
|
582
|
-
component:
|
|
730
|
+
component: s,
|
|
583
731
|
props: this.buildProps(),
|
|
584
732
|
toolName: this.toolName
|
|
585
733
|
}), t;
|
|
@@ -593,8 +741,8 @@ function _e(e) {
|
|
|
593
741
|
}
|
|
594
742
|
async setData(t) {
|
|
595
743
|
var n = this;
|
|
596
|
-
let r =
|
|
597
|
-
return
|
|
744
|
+
let r = x(e.propSchema, t == null ? {} : t);
|
|
745
|
+
return y(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.pushProps({ data: r }), !0);
|
|
598
746
|
}
|
|
599
747
|
setReadOnly(e) {
|
|
600
748
|
this.readOnly = e, this.pushProps({ readOnly: e });
|
|
@@ -623,7 +771,7 @@ function _e(e) {
|
|
|
623
771
|
}
|
|
624
772
|
pushProps(e) {
|
|
625
773
|
let t = this.registry;
|
|
626
|
-
t !== void 0 &&
|
|
774
|
+
t !== void 0 && D(() => {
|
|
627
775
|
t.setProps(this.blockApi.id, e);
|
|
628
776
|
});
|
|
629
777
|
}
|
|
@@ -647,8 +795,13 @@ function _e(e) {
|
|
|
647
795
|
}
|
|
648
796
|
//#endregion
|
|
649
797
|
//#region src/createReactInlineTool.tsx
|
|
650
|
-
var
|
|
651
|
-
function
|
|
798
|
+
var Me = [H, U], Ne = (e) => `__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, $ = n(null);
|
|
799
|
+
function Pe() {
|
|
800
|
+
let e = s($);
|
|
801
|
+
if (e === null) throw Error("useInlineTool() must be called from a component rendered by createReactInlineTool");
|
|
802
|
+
return e;
|
|
803
|
+
}
|
|
804
|
+
function Fe(e) {
|
|
652
805
|
var t;
|
|
653
806
|
return t = class {
|
|
654
807
|
static get title() {
|
|
@@ -661,7 +814,7 @@ function be(e) {
|
|
|
661
814
|
return e.shortcut;
|
|
662
815
|
}
|
|
663
816
|
static get sanitize() {
|
|
664
|
-
return e.sanitize;
|
|
817
|
+
return e.sanitize === void 0 ? e.mark === void 0 ? void 0 : S(e.mark) : e.sanitize;
|
|
665
818
|
}
|
|
666
819
|
static get isReadOnlySupported() {
|
|
667
820
|
var t;
|
|
@@ -671,18 +824,18 @@ function be(e) {
|
|
|
671
824
|
var n;
|
|
672
825
|
this.active = !1, this.registered = !1;
|
|
673
826
|
let r = (n = t == null ? void 0 : t.config) == null ? {} : n;
|
|
674
|
-
this.registry = r[
|
|
675
|
-
let i = r[
|
|
676
|
-
this.toolName = typeof i == "string" ? i : e.type, this.portalKey =
|
|
827
|
+
this.api = t == null ? void 0 : t.api, this.registry = r[H];
|
|
828
|
+
let i = r[U];
|
|
829
|
+
this.toolName = typeof i == "string" ? i : e.type, this.portalKey = Ne(this.toolName);
|
|
677
830
|
let a = {};
|
|
678
|
-
for (let [e, t] of Object.entries(r))
|
|
679
|
-
this.toolConfig = Object.freeze(a);
|
|
831
|
+
for (let [e, t] of Object.entries(r)) Me.includes(e) || (a[e] = t);
|
|
832
|
+
this.toolConfig = Object.freeze(a), this.portalComponent = this.createPortalComponent();
|
|
680
833
|
}
|
|
681
834
|
render() {
|
|
682
835
|
let t = document.createElement("div");
|
|
683
836
|
return t.setAttribute("data-blok-mutation-free", "true"), this.registry !== void 0 && (this.registry.register(this.portalKey, {
|
|
684
837
|
hostEl: t,
|
|
685
|
-
component:
|
|
838
|
+
component: this.portalComponent,
|
|
686
839
|
props: {
|
|
687
840
|
active: this.active,
|
|
688
841
|
config: this.toolConfig
|
|
@@ -693,9 +846,7 @@ function be(e) {
|
|
|
693
846
|
title: e.title,
|
|
694
847
|
icon: t,
|
|
695
848
|
onActivate: () => {
|
|
696
|
-
|
|
697
|
-
let t = window.getSelection();
|
|
698
|
-
!t || t.rangeCount === 0 || e.surround(t.getRangeAt(0));
|
|
849
|
+
this.activate();
|
|
699
850
|
},
|
|
700
851
|
isActive: () => this.refreshActiveState()
|
|
701
852
|
};
|
|
@@ -704,15 +855,53 @@ function be(e) {
|
|
|
704
855
|
var e;
|
|
705
856
|
this.registered && (this.registered = !1, (e = this.registry) == null || e.unregister(this.portalKey));
|
|
706
857
|
}
|
|
858
|
+
activate() {
|
|
859
|
+
var t;
|
|
860
|
+
if (typeof e.surround == "function") {
|
|
861
|
+
let t = window.getSelection();
|
|
862
|
+
if (!t || t.rangeCount === 0) return;
|
|
863
|
+
e.surround(t.getRangeAt(0), this.api);
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
e.mark !== void 0 && ((t = this.api) == null ? void 0 : t.marks) !== void 0 && this.api.marks.toggle(e.mark);
|
|
867
|
+
}
|
|
707
868
|
refreshActiveState() {
|
|
708
|
-
let
|
|
709
|
-
if (
|
|
710
|
-
var
|
|
711
|
-
(
|
|
869
|
+
let e = this.computeActiveState();
|
|
870
|
+
if (e !== this.active && (this.active = e, this.registered)) {
|
|
871
|
+
var t;
|
|
872
|
+
(t = this.registry) == null || t.setProps(this.portalKey, { active: e });
|
|
712
873
|
}
|
|
713
|
-
return
|
|
874
|
+
return e;
|
|
875
|
+
}
|
|
876
|
+
computeActiveState() {
|
|
877
|
+
var t;
|
|
878
|
+
return typeof e.checkState == "function" ? !!e.checkState(window.getSelection(), this.api) : e.mark !== void 0 && ((t = this.api) == null ? void 0 : t.marks) !== void 0 && this.api.marks.has(e.mark);
|
|
879
|
+
}
|
|
880
|
+
createPortalComponent() {
|
|
881
|
+
let t = this.api, n = e.mark, r = e.component, i = n !== void 0 && (t == null ? void 0 : t.marks) !== void 0 ? {
|
|
882
|
+
has: () => t.marks.has(n),
|
|
883
|
+
toggle: (e) => t.marks.toggle(n, e),
|
|
884
|
+
apply: (e) => t.marks.apply(n, e),
|
|
885
|
+
remove: () => t.marks.remove(n),
|
|
886
|
+
read: () => t.marks.read(n)
|
|
887
|
+
} : null, a = (e) => {
|
|
888
|
+
let n = u(() => ({
|
|
889
|
+
active: e.active,
|
|
890
|
+
config: e.config,
|
|
891
|
+
api: t,
|
|
892
|
+
mark: i
|
|
893
|
+
}), [e.active, e.config]);
|
|
894
|
+
return /* @__PURE__ */ T($.Provider, {
|
|
895
|
+
value: n,
|
|
896
|
+
children: /* @__PURE__ */ T(r, {
|
|
897
|
+
active: e.active,
|
|
898
|
+
config: e.config
|
|
899
|
+
})
|
|
900
|
+
});
|
|
901
|
+
};
|
|
902
|
+
return a.displayName = `BlokInlineTool(${this.toolName})`, a;
|
|
714
903
|
}
|
|
715
904
|
}, t.__isBlokReactInlineTool = !0, t.isInline = !0, t;
|
|
716
905
|
}
|
|
717
906
|
//#endregion
|
|
718
|
-
export {
|
|
907
|
+
export { H as BLOK_PORTAL_REGISTRY_CONFIG_KEY, U as BLOK_TOOL_NAME_CONFIG_KEY, Z as BlockPortalHost, pe as BlokContent, _e as BlokEditor, B as BlokProvider, Oe as BlokView, W as createBlockPortalRegistry, je as createReactBlock, Fe as createReactInlineTool, ye as useBlocks, Y as useBlok, V as useBlokDefaults, be as useBlokReady, De as useBlokView, Pe as useInlineTool };
|