@bloklabs/react 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +277 -220
- package/package.json +2 -2
- package/src/BlokEditor.tsx +1 -1
- package/src/createReactBlock.tsx +151 -8
- package/src/createReactInlineTool.tsx +12 -0
- package/src/index.ts +3 -0
- package/src/provide-blok.tsx +1 -1
- package/src/useBlok.ts +102 -3
- package/types/index.d.ts +40 -2
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
import { Component as e, createContext as t, forwardRef as n,
|
|
2
|
-
import { Blok as
|
|
3
|
-
import { DATA_ATTR as
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import { createPortal as
|
|
1
|
+
import { Component as e, createContext as t, forwardRef as n, isValidElement as r, useCallback as i, useContext as a, useEffect as o, useImperativeHandle as s, useMemo as c, useRef as l, useState as u, useSyncExternalStore as d } from "react";
|
|
2
|
+
import { Blok as f } from "@bloklabs/core";
|
|
3
|
+
import { DATA_ATTR as p, EMPTY_API as m, createBlocksApiForEditor as h, createEmittedEchoWindow as g, deepEqual as _, deepEqual as v, fillDefaults as y, mountChildBlocks as b, normalizeReadOnlyConfig as x } from "@bloklabs/core/adapters";
|
|
4
|
+
import { Fragment as S, jsx as C } from "react/jsx-runtime";
|
|
5
|
+
import { createPortal as w, flushSync as T } from "react-dom";
|
|
6
|
+
import { createRoot as E } from "react-dom/client";
|
|
6
7
|
//#region src/holder-map.ts
|
|
7
|
-
var
|
|
8
|
+
var D = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
function ee(e, t) {
|
|
9
|
-
|
|
10
|
+
D.set(e, t);
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
12
|
+
function O(e) {
|
|
13
|
+
return D.get(e);
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
15
|
+
function k(e) {
|
|
16
|
+
D.delete(e);
|
|
16
17
|
}
|
|
17
18
|
//#endregion
|
|
18
|
-
//#region \0@oxc-project+runtime@0.
|
|
19
|
-
function
|
|
19
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
|
|
20
|
+
function A(e) {
|
|
20
21
|
"@babel/helpers - typeof";
|
|
21
|
-
return
|
|
22
|
+
return A = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
22
23
|
return typeof e;
|
|
23
24
|
} : function(e) {
|
|
24
25
|
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
25
|
-
},
|
|
26
|
+
}, A(e);
|
|
26
27
|
}
|
|
27
28
|
//#endregion
|
|
28
|
-
//#region \0@oxc-project+runtime@0.
|
|
29
|
-
function
|
|
30
|
-
if (
|
|
29
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
|
|
30
|
+
function j(e, t) {
|
|
31
|
+
if (A(e) != "object" || !e) return e;
|
|
31
32
|
var n = e[Symbol.toPrimitive];
|
|
32
33
|
if (n !== void 0) {
|
|
33
34
|
var r = n.call(e, t || "default");
|
|
34
|
-
if (
|
|
35
|
+
if (A(r) != "object") return r;
|
|
35
36
|
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
36
37
|
}
|
|
37
38
|
return (t === "string" ? String : Number)(e);
|
|
38
39
|
}
|
|
39
40
|
//#endregion
|
|
40
|
-
//#region \0@oxc-project+runtime@0.
|
|
41
|
-
function
|
|
42
|
-
var t =
|
|
43
|
-
return
|
|
41
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
|
|
42
|
+
function M(e) {
|
|
43
|
+
var t = j(e, "string");
|
|
44
|
+
return A(t) == "symbol" ? t : t + "";
|
|
44
45
|
}
|
|
45
46
|
//#endregion
|
|
46
|
-
//#region \0@oxc-project+runtime@0.
|
|
47
|
-
function
|
|
48
|
-
return (t =
|
|
47
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
|
|
48
|
+
function N(e, t, n) {
|
|
49
|
+
return (t = M(t)) in e ? Object.defineProperty(e, t, {
|
|
49
50
|
value: n,
|
|
50
51
|
enumerable: !0,
|
|
51
52
|
configurable: !0,
|
|
@@ -53,8 +54,8 @@ function A(e, t, n) {
|
|
|
53
54
|
}) : e[t] = n, e;
|
|
54
55
|
}
|
|
55
56
|
//#endregion
|
|
56
|
-
//#region \0@oxc-project+runtime@0.
|
|
57
|
-
function
|
|
57
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectSpread2.js
|
|
58
|
+
function P(e, t) {
|
|
58
59
|
var n = Object.keys(e);
|
|
59
60
|
if (Object.getOwnPropertySymbols) {
|
|
60
61
|
var r = Object.getOwnPropertySymbols(e);
|
|
@@ -64,12 +65,12 @@ function j(e, t) {
|
|
|
64
65
|
}
|
|
65
66
|
return n;
|
|
66
67
|
}
|
|
67
|
-
function
|
|
68
|
+
function F(e) {
|
|
68
69
|
for (var t = 1; t < arguments.length; t++) {
|
|
69
70
|
var n = arguments[t] == null ? {} : arguments[t];
|
|
70
|
-
t % 2 ?
|
|
71
|
-
|
|
72
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) :
|
|
71
|
+
t % 2 ? P(Object(n), !0).forEach(function(t) {
|
|
72
|
+
N(e, t, n[t]);
|
|
73
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : P(Object(n)).forEach(function(t) {
|
|
73
74
|
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
|
|
74
75
|
});
|
|
75
76
|
}
|
|
@@ -77,35 +78,35 @@ function M(e) {
|
|
|
77
78
|
}
|
|
78
79
|
//#endregion
|
|
79
80
|
//#region src/provide-blok.tsx
|
|
80
|
-
var
|
|
81
|
-
function
|
|
82
|
-
return /* @__PURE__ */
|
|
81
|
+
var I = t({});
|
|
82
|
+
function L({ defaults: e, children: t }) {
|
|
83
|
+
return /* @__PURE__ */ C(I.Provider, {
|
|
83
84
|
value: e,
|
|
84
85
|
children: t
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
88
|
+
function R() {
|
|
89
|
+
return a(I);
|
|
89
90
|
}
|
|
90
|
-
function
|
|
91
|
+
function te(e, t) {
|
|
91
92
|
if (Object.keys(e).length === 0) return t;
|
|
92
|
-
let n =
|
|
93
|
+
let n = F({}, e);
|
|
93
94
|
for (let e of Object.keys(t)) {
|
|
94
95
|
let r = t[e];
|
|
95
96
|
r !== void 0 && (n[e] = r);
|
|
96
97
|
}
|
|
97
|
-
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools =
|
|
98
|
+
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = F(F({}, e.tools), t.tools)), n;
|
|
98
99
|
}
|
|
99
100
|
//#endregion
|
|
100
101
|
//#region src/block-portal-registry.ts
|
|
101
|
-
var
|
|
102
|
+
var z = "__blokPortalRegistry", B = "__blokToolName", V = () => {
|
|
102
103
|
let e = { snapshot: /* @__PURE__ */ new Map() }, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = (n) => {
|
|
103
104
|
e.snapshot = n, t.forEach((e) => e());
|
|
104
105
|
};
|
|
105
106
|
return {
|
|
106
107
|
register(t, i) {
|
|
107
108
|
let a = new Map(e.snapshot), o = i.toolName === void 0 ? void 0 : n.get(i.toolName);
|
|
108
|
-
a.set(t, o === void 0 ? i :
|
|
109
|
+
a.set(t, o === void 0 ? i : F(F({}, i), {}, { props: F(F({}, i.props), {}, { config: o }) })), r(a);
|
|
109
110
|
},
|
|
110
111
|
unregister(t) {
|
|
111
112
|
if (!e.snapshot.has(t)) return;
|
|
@@ -116,14 +117,14 @@ var F = "__blokPortalRegistry", I = "__blokToolName", L = () => {
|
|
|
116
117
|
let i = e.snapshot.get(t);
|
|
117
118
|
if (i === void 0) return;
|
|
118
119
|
let a = new Map(e.snapshot);
|
|
119
|
-
a.set(t,
|
|
120
|
+
a.set(t, F(F({}, i), {}, { props: F(F({}, i.props), n) })), r(a);
|
|
120
121
|
},
|
|
121
122
|
setToolConfig(t, i) {
|
|
122
123
|
n.set(t, i);
|
|
123
124
|
let a = [...e.snapshot].filter(([, e]) => e.toolName === t);
|
|
124
125
|
if (a.length === 0) return;
|
|
125
126
|
let o = new Map(e.snapshot);
|
|
126
|
-
for (let [e, t] of a) o.set(e,
|
|
127
|
+
for (let [e, t] of a) o.set(e, F(F({}, t), {}, { props: F(F({}, t.props), {}, { config: i }) }));
|
|
127
128
|
r(o);
|
|
128
129
|
},
|
|
129
130
|
subscribe(e) {
|
|
@@ -135,45 +136,45 @@ var F = "__blokPortalRegistry", I = "__blokToolName", L = () => {
|
|
|
135
136
|
return e.snapshot;
|
|
136
137
|
}
|
|
137
138
|
};
|
|
138
|
-
},
|
|
139
|
-
function
|
|
140
|
-
|
|
139
|
+
}, H = /* @__PURE__ */ new WeakMap();
|
|
140
|
+
function U(e, t) {
|
|
141
|
+
H.set(e, t);
|
|
141
142
|
}
|
|
142
|
-
function
|
|
143
|
-
return
|
|
143
|
+
function W(e) {
|
|
144
|
+
return H.get(e);
|
|
144
145
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
146
|
+
function G(e) {
|
|
147
|
+
H.delete(e);
|
|
147
148
|
}
|
|
148
149
|
//#endregion
|
|
149
150
|
//#region src/live-tool-config.ts
|
|
150
|
-
var
|
|
151
|
+
var K = (e) => {
|
|
151
152
|
if (typeof e != "object" || !e) return !1;
|
|
152
153
|
let t = Object.getPrototypeOf(e);
|
|
153
154
|
return t === Object.prototype || t === null;
|
|
154
|
-
},
|
|
155
|
+
}, ne = (e, t) => t.reduce((e, t) => {
|
|
155
156
|
if (Array.isArray(e)) return typeof t == "number" ? e[t] : void 0;
|
|
156
|
-
if (
|
|
157
|
-
}, e),
|
|
157
|
+
if (K(e)) return e[t];
|
|
158
|
+
}, e), re = (e, t) => {
|
|
158
159
|
let n = (e, t) => {
|
|
159
160
|
if (typeof e == "function") return typeof t == "function" ? t : e;
|
|
160
161
|
if (Array.isArray(e)) {
|
|
161
162
|
let r = Array.isArray(t) ? t : [];
|
|
162
163
|
return e.map((e, t) => n(e, r[t]));
|
|
163
164
|
}
|
|
164
|
-
if (
|
|
165
|
-
let r =
|
|
165
|
+
if (K(e)) {
|
|
166
|
+
let r = K(t) ? t : {}, i = {};
|
|
166
167
|
for (let [t, a] of Object.entries(e)) i[t] = n(a, r[t]);
|
|
167
168
|
return i;
|
|
168
169
|
}
|
|
169
170
|
return e;
|
|
170
171
|
}, r = n(t, e);
|
|
171
|
-
return
|
|
172
|
-
},
|
|
173
|
-
if (!
|
|
172
|
+
return K(r) ? r : {};
|
|
173
|
+
}, ie = (e, t) => {
|
|
174
|
+
if (!K(e)) return e;
|
|
174
175
|
let n = {};
|
|
175
176
|
for (let [r, i] of Object.entries(e)) {
|
|
176
|
-
if (!
|
|
177
|
+
if (!K(i) || !K(i.config)) {
|
|
177
178
|
n[r] = i;
|
|
178
179
|
continue;
|
|
179
180
|
}
|
|
@@ -181,12 +182,12 @@ var H = (e) => {
|
|
|
181
182
|
if (typeof n == "function") {
|
|
182
183
|
let e = n;
|
|
183
184
|
return function(...n) {
|
|
184
|
-
let a = t(), o =
|
|
185
|
+
let a = t(), o = K(a) ? a[r] : void 0, s = ne(K(o) ? o.config : void 0, i);
|
|
185
186
|
return Reflect.apply(typeof s == "function" ? s : e, this, n);
|
|
186
187
|
};
|
|
187
188
|
}
|
|
188
189
|
if (Array.isArray(n)) return e.has(n) ? n : (e.add(n), n.map((e, t) => a(e, [...i, t])));
|
|
189
|
-
if (
|
|
190
|
+
if (K(n)) {
|
|
190
191
|
if (e.has(n)) return n;
|
|
191
192
|
e.add(n);
|
|
192
193
|
let t = {};
|
|
@@ -195,155 +196,171 @@ var H = (e) => {
|
|
|
195
196
|
}
|
|
196
197
|
return n;
|
|
197
198
|
};
|
|
198
|
-
n[r] =
|
|
199
|
+
n[r] = F(F({}, i), {}, { config: a(i.config, []) });
|
|
199
200
|
}
|
|
200
201
|
return n;
|
|
201
|
-
},
|
|
202
|
+
}, q = (e) => {
|
|
202
203
|
let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
|
|
203
204
|
return typeof t == "function" && t.__isBlokReactBlock === !0;
|
|
204
|
-
},
|
|
205
|
+
}, ae = (e) => {
|
|
205
206
|
let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
|
|
206
207
|
return typeof t == "function" && t.__isBlokReactInlineTool === !0;
|
|
207
|
-
},
|
|
208
|
+
}, oe = (e, t) => {
|
|
208
209
|
if (typeof e != "object" || !e) return e;
|
|
209
210
|
let n = {};
|
|
210
211
|
for (let [i, a] of Object.entries(e)) {
|
|
211
212
|
var r;
|
|
212
|
-
if (!
|
|
213
|
+
if (!q(a) && !ae(a)) {
|
|
213
214
|
n[i] = a;
|
|
214
215
|
continue;
|
|
215
216
|
}
|
|
216
|
-
let e = typeof a == "function" ? { class: a } :
|
|
217
|
-
e.config =
|
|
218
|
-
[
|
|
219
|
-
[
|
|
217
|
+
let e = typeof a == "function" ? { class: a } : F({}, a);
|
|
218
|
+
e.config = F(F({}, (r = e.config) == null ? {} : r), {}, {
|
|
219
|
+
[z]: t,
|
|
220
|
+
[B]: i
|
|
220
221
|
}), n[i] = e;
|
|
221
222
|
}
|
|
222
223
|
return n;
|
|
223
224
|
};
|
|
224
|
-
function
|
|
225
|
-
|
|
226
|
-
u
|
|
227
|
-
|
|
225
|
+
function J(e, t) {
|
|
226
|
+
var n, r;
|
|
227
|
+
let i = te(a(I), e), [s, d] = u(null), p = l(i);
|
|
228
|
+
p.current = i;
|
|
229
|
+
let m = l({
|
|
228
230
|
editor: null,
|
|
229
231
|
holder: null,
|
|
230
232
|
destroyTimeout: null,
|
|
231
233
|
isDestroyed: !1,
|
|
232
234
|
isEditorReady: !1,
|
|
233
235
|
depsToken: null
|
|
234
|
-
}),
|
|
235
|
-
|
|
236
|
+
}), h = c(() => ({}), t == null ? [] : t), _ = l(i.data), y = l(g()), b = l(null), S = l(i.data), C = l(Promise.resolve()), w = l(void 0), T = l(null), E = l(void 0), D = l(/* @__PURE__ */ new Map()), O = l(/* @__PURE__ */ new Map());
|
|
237
|
+
o(() => {
|
|
238
|
+
var e;
|
|
236
239
|
if (typeof window > "u") return;
|
|
237
|
-
let
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
+
let t = m.current;
|
|
241
|
+
if (t.destroyTimeout !== null && (clearTimeout(t.destroyTimeout), t.destroyTimeout = null), t.editor !== null && !t.isDestroyed && t.depsToken === h) return t.isEditorReady && d(t.editor), () => {
|
|
242
|
+
Y(t, d);
|
|
240
243
|
};
|
|
241
|
-
if (
|
|
242
|
-
|
|
244
|
+
if (t.editor !== null && !t.isDestroyed) {
|
|
245
|
+
k(t.editor), G(t.editor);
|
|
243
246
|
try {
|
|
244
|
-
|
|
247
|
+
t.editor.destroy();
|
|
245
248
|
} catch (e) {}
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
let
|
|
249
|
-
|
|
250
|
-
let
|
|
251
|
-
|
|
252
|
-
let s =
|
|
253
|
-
holder:
|
|
249
|
+
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, d(null);
|
|
250
|
+
}
|
|
251
|
+
let n = document.createElement("div");
|
|
252
|
+
t.holder = n, t.isDestroyed = !1, t.isEditorReady = !1, t.depsToken = h;
|
|
253
|
+
let r = p.current, i = V(), a = r.tools === void 0 ? void 0 : ie(r.tools, () => p.current.tools), o = a === void 0 ? void 0 : oe(a, i);
|
|
254
|
+
T.current = i, E.current = a, D.current = /* @__PURE__ */ new Map(), O.current = new Map(Object.entries((e = r.tools) == null ? {} : e).map(([e, t]) => [e, typeof t == "object" && t ? t.toolbox : void 0]));
|
|
255
|
+
let s = F(F(F({}, r), o === void 0 ? {} : { tools: o }), {}, {
|
|
256
|
+
holder: n,
|
|
254
257
|
onReady: (...e) => {
|
|
255
258
|
var t, n;
|
|
256
|
-
(t = (n =
|
|
259
|
+
(t = (n = p.current).onReady) == null || t.call(n, ...e);
|
|
257
260
|
},
|
|
258
261
|
onChange: (...e) => {
|
|
259
262
|
var t, n;
|
|
260
|
-
(t = (n =
|
|
263
|
+
(t = (n = p.current).onChange) == null || t.call(n, ...e);
|
|
261
264
|
},
|
|
262
265
|
onEnter: (...e) => {
|
|
263
266
|
var t, n;
|
|
264
|
-
return (t = (n =
|
|
267
|
+
return (t = (n = p.current).onEnter) == null ? void 0 : t.call(n, ...e);
|
|
265
268
|
}
|
|
266
269
|
});
|
|
267
|
-
|
|
270
|
+
r.onSave && (s.onSave = (...e) => {
|
|
268
271
|
var t, n;
|
|
269
|
-
|
|
270
|
-
}),
|
|
272
|
+
_.current = e[0], y.current.record(e[0]), (t = (n = p.current).onSave) == null || t.call(n, ...e);
|
|
273
|
+
}), r.onBeforeRender && (s.onBeforeRender = (...e) => {
|
|
271
274
|
var t, n, r;
|
|
272
|
-
return (t = (n = (r =
|
|
273
|
-
}),
|
|
275
|
+
return (t = (n = (r = p.current).onBeforeRender) == null ? void 0 : n.call(r, ...e)) == null ? e[0] : t;
|
|
276
|
+
}), r.onAfterRender && (s.onAfterRender = (...e) => {
|
|
274
277
|
var t, n;
|
|
275
|
-
(t = (n =
|
|
278
|
+
(t = (n = p.current).onAfterRender) == null || t.call(n, ...e);
|
|
276
279
|
});
|
|
277
|
-
let c = new
|
|
278
|
-
return
|
|
279
|
-
|
|
280
|
+
let c = new f(s);
|
|
281
|
+
return t.editor = c, S.current = r.data, ee(c, n), U(c, i), c.isReady.then(() => {
|
|
282
|
+
t.editor === c && !t.isDestroyed && (t.isEditorReady = !0, d(c));
|
|
280
283
|
}).catch(() => {
|
|
281
|
-
if (
|
|
282
|
-
|
|
284
|
+
if (t.editor === c && !t.isDestroyed) {
|
|
285
|
+
k(c), G(c);
|
|
283
286
|
try {
|
|
284
287
|
c.destroy();
|
|
285
288
|
} catch (e) {}
|
|
286
|
-
|
|
289
|
+
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, d(null);
|
|
287
290
|
}
|
|
288
291
|
}), () => {
|
|
289
|
-
|
|
292
|
+
Y(t, d);
|
|
290
293
|
};
|
|
291
|
-
}, [
|
|
292
|
-
let e =
|
|
294
|
+
}, [h]), o(() => {
|
|
295
|
+
let e = T.current, t = m.current;
|
|
293
296
|
if (e === null || t.editor === null || t.isDestroyed) return;
|
|
294
|
-
let n =
|
|
297
|
+
let n = p.current.tools;
|
|
295
298
|
if (typeof n != "object" || !n) return;
|
|
296
|
-
let r =
|
|
299
|
+
let r = E.current;
|
|
297
300
|
for (let [t, a] of Object.entries(n)) {
|
|
298
301
|
var i;
|
|
299
|
-
if (!
|
|
300
|
-
let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s =
|
|
301
|
-
if (c !== void 0 &&
|
|
302
|
+
if (!q(a)) continue;
|
|
303
|
+
let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s = re(typeof o == "object" && o ? o.config : void 0, n), c = D.current.get(t);
|
|
304
|
+
if (c !== void 0 && v(s, c)) continue;
|
|
302
305
|
let l = Object.freeze(s);
|
|
303
|
-
|
|
306
|
+
D.current.set(t, l), e.setToolConfig(t, l);
|
|
307
|
+
}
|
|
308
|
+
}), o(() => {
|
|
309
|
+
let e = m.current;
|
|
310
|
+
if (e.editor === null || e.isDestroyed || !e.isEditorReady) return;
|
|
311
|
+
let t = p.current.tools;
|
|
312
|
+
if (!(typeof t != "object" || !t)) for (let [r, i] of Object.entries(t)) {
|
|
313
|
+
var n;
|
|
314
|
+
if (!O.current.has(r)) continue;
|
|
315
|
+
let t = typeof i == "object" && i ? i.toolbox : void 0;
|
|
316
|
+
v(t, O.current.get(r)) || (O.current.set(r, t), (n = e.editor.tools) == null || n.update(r, { toolbox: t }));
|
|
304
317
|
}
|
|
305
318
|
});
|
|
306
|
-
let
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}, [
|
|
310
|
-
let { autofocus:
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}, [
|
|
314
|
-
let { theme:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}, [
|
|
318
|
-
let { width:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}, [
|
|
322
|
-
let
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}, [
|
|
326
|
-
let {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
319
|
+
let A = x(i.readOnly).enabled;
|
|
320
|
+
o(() => {
|
|
321
|
+
s !== null && s.readOnly.set(A);
|
|
322
|
+
}, [s, A]);
|
|
323
|
+
let { autofocus: j } = i;
|
|
324
|
+
o(() => {
|
|
325
|
+
s === null || !j || s.focus();
|
|
326
|
+
}, [s, j]);
|
|
327
|
+
let { theme: M } = i;
|
|
328
|
+
o(() => {
|
|
329
|
+
s === null || M === void 0 || s.theme.set(M);
|
|
330
|
+
}, [s, M]);
|
|
331
|
+
let { width: N } = i;
|
|
332
|
+
o(() => {
|
|
333
|
+
s === null || N === void 0 || s.width.set(N);
|
|
334
|
+
}, [s, N]);
|
|
335
|
+
let P = (n = i.style) == null ? void 0 : n.tokens, L = l((r = i.style) == null ? void 0 : r.tokens);
|
|
336
|
+
o(() => {
|
|
337
|
+
s === null || P === void 0 || v(P, L.current) || (L.current = P, s.tokens.set(P));
|
|
338
|
+
}, [s, P]);
|
|
339
|
+
let { placeholder: R } = i;
|
|
340
|
+
o(() => {
|
|
341
|
+
s === null || R === void 0 || s.placeholder.set(R);
|
|
342
|
+
}, [s, R]);
|
|
343
|
+
let { data: z } = i;
|
|
344
|
+
return o(() => {
|
|
345
|
+
if (s === null || z === void 0) return;
|
|
346
|
+
let e = m.current;
|
|
347
|
+
if (!(e.editor !== s || e.isDestroyed)) {
|
|
348
|
+
if (b.current !== s && (b.current = s, w.current = void 0, y.current.clear(), v(z, S.current))) {
|
|
349
|
+
_.current = z;
|
|
333
350
|
return;
|
|
334
351
|
}
|
|
335
|
-
|
|
336
|
-
|
|
352
|
+
v(z, _.current) || v(z, w.current) || y.current.matches(z) || (y.current.clear(), w.current = z, C.current = C.current.catch(() => void 0).then(() => s.render(z)).then(() => {
|
|
353
|
+
_.current = z;
|
|
337
354
|
}, () => {}).then(() => {
|
|
338
|
-
|
|
355
|
+
w.current === z && (w.current = void 0);
|
|
339
356
|
}));
|
|
340
357
|
}
|
|
341
|
-
}, [
|
|
358
|
+
}, [s, z]), s;
|
|
342
359
|
}
|
|
343
|
-
function
|
|
360
|
+
function Y(e, t) {
|
|
344
361
|
e.destroyTimeout = setTimeout(() => {
|
|
345
362
|
if (e.editor !== null) {
|
|
346
|
-
|
|
363
|
+
k(e.editor), G(e.editor);
|
|
347
364
|
try {
|
|
348
365
|
e.editor.destroy();
|
|
349
366
|
} catch (e) {}
|
|
@@ -353,7 +370,7 @@ function J(e, t) {
|
|
|
353
370
|
}
|
|
354
371
|
//#endregion
|
|
355
372
|
//#region src/BlockPortalHost.tsx
|
|
356
|
-
var
|
|
373
|
+
var se = class extends e {
|
|
357
374
|
constructor(...e) {
|
|
358
375
|
super(...e), this.state = { failed: !1 };
|
|
359
376
|
}
|
|
@@ -366,15 +383,15 @@ var Y = class extends e {
|
|
|
366
383
|
}
|
|
367
384
|
};
|
|
368
385
|
function X({ registry: e }) {
|
|
369
|
-
let t =
|
|
370
|
-
return /* @__PURE__ */
|
|
386
|
+
let t = d(e.subscribe, e.getSnapshot, e.getSnapshot);
|
|
387
|
+
return /* @__PURE__ */ C(S, { children: Array.from(t.entries()).map(([e, t]) => {
|
|
371
388
|
let n = t.component;
|
|
372
|
-
return
|
|
389
|
+
return w(/* @__PURE__ */ C(se, { children: /* @__PURE__ */ C(n, F({}, t.props)) }), t.hostEl, e);
|
|
373
390
|
}) });
|
|
374
391
|
}
|
|
375
392
|
//#endregion
|
|
376
|
-
//#region \0@oxc-project+runtime@0.
|
|
377
|
-
function
|
|
393
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
394
|
+
function ce(e, t) {
|
|
378
395
|
if (e == null) return {};
|
|
379
396
|
var n = {};
|
|
380
397
|
for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
|
|
@@ -384,10 +401,10 @@ function ae(e, t) {
|
|
|
384
401
|
return n;
|
|
385
402
|
}
|
|
386
403
|
//#endregion
|
|
387
|
-
//#region \0@oxc-project+runtime@0.
|
|
404
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutProperties.js
|
|
388
405
|
function Z(e, t) {
|
|
389
406
|
if (e == null) return {};
|
|
390
|
-
var n, r, i =
|
|
407
|
+
var n, r, i = ce(e, t);
|
|
391
408
|
if (Object.getOwnPropertySymbols) {
|
|
392
409
|
var a = Object.getOwnPropertySymbols(e);
|
|
393
410
|
for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
|
|
@@ -396,51 +413,51 @@ function Z(e, t) {
|
|
|
396
413
|
}
|
|
397
414
|
//#endregion
|
|
398
415
|
//#region src/BlokContent.tsx
|
|
399
|
-
var
|
|
400
|
-
let { editor: n } = e, r = Z(e,
|
|
416
|
+
var le = ["editor"], Q = n(function(e, t) {
|
|
417
|
+
let { editor: n } = e, r = Z(e, le), i = l(null), a = (e) => {
|
|
401
418
|
if (i.current = e, typeof t == "function") t(e);
|
|
402
419
|
else if (t != null) {
|
|
403
420
|
let n = t;
|
|
404
421
|
n.current = e;
|
|
405
422
|
}
|
|
406
423
|
};
|
|
407
|
-
|
|
424
|
+
o(() => {
|
|
408
425
|
if (n === null || i.current === null) return;
|
|
409
|
-
let e =
|
|
426
|
+
let e = O(n);
|
|
410
427
|
if (e !== void 0) return i.current.appendChild(e), () => {
|
|
411
428
|
e.remove();
|
|
412
429
|
};
|
|
413
430
|
}, [n]);
|
|
414
|
-
let s = n === null ? void 0 :
|
|
415
|
-
return /* @__PURE__ */
|
|
416
|
-
}),
|
|
431
|
+
let s = n === null ? void 0 : W(n);
|
|
432
|
+
return /* @__PURE__ */ C("div", F(F({ ref: a }, r), {}, { children: s === void 0 ? null : /* @__PURE__ */ C(X, { registry: s }) }));
|
|
433
|
+
}), ue = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onEnter.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width".split("."), de = [
|
|
417
434
|
"deps",
|
|
418
435
|
"onReady",
|
|
419
436
|
"onBlocksRendered",
|
|
420
437
|
"onBlockRendered"
|
|
421
|
-
],
|
|
422
|
-
let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered:
|
|
423
|
-
for (let e of Object.keys(
|
|
424
|
-
let t =
|
|
425
|
-
|
|
438
|
+
], fe = new Set(ue), pe = n(function(e, t) {
|
|
439
|
+
let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: a } = e, c = Z(e, de), u = {}, d = {};
|
|
440
|
+
for (let e of Object.keys(c)) {
|
|
441
|
+
let t = c[e];
|
|
442
|
+
fe.has(e) ? u[e] = t : d[e] = t;
|
|
426
443
|
}
|
|
427
|
-
let f =
|
|
428
|
-
|
|
429
|
-
let p =
|
|
444
|
+
let f = J(u, n);
|
|
445
|
+
s(t, () => f, [f]);
|
|
446
|
+
let p = l(r);
|
|
430
447
|
p.current = r;
|
|
431
|
-
let m =
|
|
432
|
-
|
|
448
|
+
let m = l(null);
|
|
449
|
+
o(() => {
|
|
433
450
|
if (f !== null && m.current !== f) {
|
|
434
451
|
var e;
|
|
435
452
|
m.current = f, (e = p.current) == null || e.call(p, f);
|
|
436
453
|
}
|
|
437
454
|
}, [f]);
|
|
438
|
-
let h =
|
|
455
|
+
let h = l(i);
|
|
439
456
|
h.current = i;
|
|
440
|
-
let g =
|
|
441
|
-
g.current =
|
|
442
|
-
let _ = !!i, v = !!
|
|
443
|
-
return
|
|
457
|
+
let g = l(a);
|
|
458
|
+
g.current = a;
|
|
459
|
+
let _ = !!i, v = !!a;
|
|
460
|
+
return o(() => {
|
|
444
461
|
if (f === null) return;
|
|
445
462
|
let e = [];
|
|
446
463
|
if (_) {
|
|
@@ -464,28 +481,65 @@ var oe = ["editor"], Q = n(function(e, t) {
|
|
|
464
481
|
f,
|
|
465
482
|
_,
|
|
466
483
|
v
|
|
467
|
-
]), /* @__PURE__ */
|
|
484
|
+
]), /* @__PURE__ */ C(Q, F({ editor: f }, d));
|
|
468
485
|
}), $ = "block changed";
|
|
469
|
-
function
|
|
470
|
-
let t =
|
|
486
|
+
function me(e) {
|
|
487
|
+
let t = l(0), n = l(e);
|
|
471
488
|
n.current !== e && (n.current = e, t.current = 0);
|
|
472
|
-
let
|
|
489
|
+
let r = i((n) => {
|
|
473
490
|
if (e === null) return () => void 0;
|
|
474
491
|
let r = () => {
|
|
475
492
|
t.current += 1, n();
|
|
476
493
|
};
|
|
477
494
|
return e.on($, r), () => e.off($, r);
|
|
478
|
-
}, [e]), a =
|
|
479
|
-
return
|
|
495
|
+
}, [e]), a = i(() => t.current, []);
|
|
496
|
+
return d(r, a, a), c(() => e === null ? m : h(e), [e]);
|
|
480
497
|
}
|
|
481
498
|
//#endregion
|
|
482
499
|
//#region src/createReactBlock.tsx
|
|
483
|
-
var
|
|
484
|
-
function
|
|
500
|
+
var he = ["commit", "readOnly"], ge = [z, B];
|
|
501
|
+
function _e(e) {
|
|
485
502
|
var t;
|
|
503
|
+
let n = (e) => {
|
|
504
|
+
if (typeof document > "u") return null;
|
|
505
|
+
let t = document.createElement("div"), n = E(t);
|
|
506
|
+
T(() => {
|
|
507
|
+
n.render(e);
|
|
508
|
+
});
|
|
509
|
+
let r = t.innerHTML;
|
|
510
|
+
return n.unmount(), r === "" ? null : r;
|
|
511
|
+
}, i = () => {
|
|
512
|
+
let t = { complete: !0 }, i = (e) => {
|
|
513
|
+
if (!r(e.icon)) return e;
|
|
514
|
+
let i = n(e.icon);
|
|
515
|
+
return i === null ? (t.complete = !1, e) : F(F({}, e), {}, { icon: i });
|
|
516
|
+
};
|
|
517
|
+
return e.toolbox === void 0 ? {
|
|
518
|
+
value: void 0,
|
|
519
|
+
complete: t.complete
|
|
520
|
+
} : {
|
|
521
|
+
value: Array.isArray(e.toolbox) ? e.toolbox.map(i) : i(e.toolbox),
|
|
522
|
+
complete: t.complete
|
|
523
|
+
};
|
|
524
|
+
}, a = {
|
|
525
|
+
resolved: !1,
|
|
526
|
+
value: void 0
|
|
527
|
+
}, s = () => {
|
|
528
|
+
if (a.resolved) return a.value;
|
|
529
|
+
let { value: e, complete: t } = i();
|
|
530
|
+
return t && (a.value = e, a.resolved = !0), e;
|
|
531
|
+
}, c = e.viewComponent === void 0 ? e.component : (t) => {
|
|
532
|
+
let n = e.viewComponent;
|
|
533
|
+
if (t.readOnly && n !== void 0) {
|
|
534
|
+
let { commit: e, readOnly: r } = t;
|
|
535
|
+
return /* @__PURE__ */ C(n, F({}, Z(t, he)));
|
|
536
|
+
}
|
|
537
|
+
let r = e.component;
|
|
538
|
+
return /* @__PURE__ */ C(r, F({}, t));
|
|
539
|
+
};
|
|
486
540
|
return t = class {
|
|
487
541
|
static get toolbox() {
|
|
488
|
-
return
|
|
542
|
+
return s();
|
|
489
543
|
}
|
|
490
544
|
static get isReadOnlySupported() {
|
|
491
545
|
return !0;
|
|
@@ -494,41 +548,41 @@ function pe(e) {
|
|
|
494
548
|
var n, r;
|
|
495
549
|
this.hostEl = null, this.pendingDispatch = !1, this.commit = (t) => {
|
|
496
550
|
var n;
|
|
497
|
-
let r =
|
|
498
|
-
|
|
551
|
+
let r = y(e.propSchema, F(F({}, this.mirror), t));
|
|
552
|
+
_(r, this.mirror) || (this.mirror = r, this.lastRendered = r, (n = this.registry) == null || n.setProps(this.blockApi.id, { data: r }), this.flushDispatch());
|
|
499
553
|
}, this.blockApi = t.block;
|
|
500
554
|
let i = (n = t.config) == null ? {} : n;
|
|
501
|
-
this.registry = i[
|
|
502
|
-
let
|
|
503
|
-
this.toolName = typeof
|
|
555
|
+
this.registry = i[z];
|
|
556
|
+
let a = i[B];
|
|
557
|
+
this.toolName = typeof a == "string" ? a : void 0;
|
|
504
558
|
let s = {};
|
|
505
|
-
for (let [e, t] of Object.entries(i))
|
|
559
|
+
for (let [e, t] of Object.entries(i)) ge.includes(e) || (s[e] = t);
|
|
506
560
|
this.toolConfig = Object.freeze(s);
|
|
507
|
-
let
|
|
561
|
+
let c = t.api;
|
|
508
562
|
this.pointerDrag = () => {
|
|
509
563
|
var e;
|
|
510
|
-
return (
|
|
511
|
-
}, this.mirror =
|
|
564
|
+
return (c == null || (e = c.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
|
|
565
|
+
}, this.mirror = y(e.propSchema, (r = t.data) == null ? {} : r), this.lastRendered = this.mirror, this.readOnly = t.readOnly;
|
|
512
566
|
let u = this.blockApi;
|
|
513
567
|
this.childrenComponent = function() {
|
|
514
|
-
let e =
|
|
515
|
-
return
|
|
516
|
-
e.current !== null &&
|
|
517
|
-
}), /* @__PURE__ */
|
|
568
|
+
let e = l(null);
|
|
569
|
+
return o(() => {
|
|
570
|
+
e.current !== null && b(e.current, u.getChildren());
|
|
571
|
+
}), /* @__PURE__ */ C("div", {
|
|
518
572
|
ref: e,
|
|
519
|
-
[
|
|
573
|
+
[p.nestedBlocks]: ""
|
|
520
574
|
});
|
|
521
575
|
};
|
|
522
576
|
}
|
|
523
577
|
render() {
|
|
524
|
-
var
|
|
525
|
-
let
|
|
526
|
-
return
|
|
527
|
-
hostEl:
|
|
528
|
-
component:
|
|
578
|
+
var e;
|
|
579
|
+
let t = document.createElement("div");
|
|
580
|
+
return t.setAttribute("data-blok-mutation-free", "true"), this.hostEl = t, (e = this.registry) == null || e.register(this.blockApi.id, {
|
|
581
|
+
hostEl: t,
|
|
582
|
+
component: c,
|
|
529
583
|
props: this.buildProps(),
|
|
530
584
|
toolName: this.toolName
|
|
531
|
-
}),
|
|
585
|
+
}), t;
|
|
532
586
|
}
|
|
533
587
|
rendered() {
|
|
534
588
|
var t;
|
|
@@ -539,8 +593,8 @@ function pe(e) {
|
|
|
539
593
|
}
|
|
540
594
|
async setData(t) {
|
|
541
595
|
var n = this;
|
|
542
|
-
let r =
|
|
543
|
-
return
|
|
596
|
+
let r = y(e.propSchema, t == null ? {} : t);
|
|
597
|
+
return _(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.pushProps({ data: r }), !0);
|
|
544
598
|
}
|
|
545
599
|
setReadOnly(e) {
|
|
546
600
|
this.readOnly = e, this.pushProps({ readOnly: e });
|
|
@@ -569,7 +623,7 @@ function pe(e) {
|
|
|
569
623
|
}
|
|
570
624
|
pushProps(e) {
|
|
571
625
|
let t = this.registry;
|
|
572
|
-
t !== void 0 &&
|
|
626
|
+
t !== void 0 && T(() => {
|
|
573
627
|
t.setProps(this.blockApi.id, e);
|
|
574
628
|
});
|
|
575
629
|
}
|
|
@@ -593,13 +647,16 @@ function pe(e) {
|
|
|
593
647
|
}
|
|
594
648
|
//#endregion
|
|
595
649
|
//#region src/createReactInlineTool.tsx
|
|
596
|
-
var
|
|
597
|
-
function
|
|
650
|
+
var ve = [z, B], ye = (e) => `__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
651
|
+
function be(e) {
|
|
598
652
|
var t;
|
|
599
653
|
return t = class {
|
|
600
654
|
static get title() {
|
|
601
655
|
return e.title;
|
|
602
656
|
}
|
|
657
|
+
static get titleKey() {
|
|
658
|
+
return e.titleKey;
|
|
659
|
+
}
|
|
603
660
|
static get shortcut() {
|
|
604
661
|
return e.shortcut;
|
|
605
662
|
}
|
|
@@ -608,17 +665,17 @@ function ge(e) {
|
|
|
608
665
|
}
|
|
609
666
|
static get isReadOnlySupported() {
|
|
610
667
|
var t;
|
|
611
|
-
return (t = e.isReadOnlySupported)
|
|
668
|
+
return (t = e.isReadOnlySupported) != null && t;
|
|
612
669
|
}
|
|
613
670
|
constructor(t) {
|
|
614
671
|
var n;
|
|
615
672
|
this.active = !1, this.registered = !1;
|
|
616
673
|
let r = (n = t == null ? void 0 : t.config) == null ? {} : n;
|
|
617
|
-
this.registry = r[
|
|
618
|
-
let i = r[
|
|
619
|
-
this.toolName = typeof i == "string" ? i : e.type, this.portalKey =
|
|
674
|
+
this.registry = r[z];
|
|
675
|
+
let i = r[B];
|
|
676
|
+
this.toolName = typeof i == "string" ? i : e.type, this.portalKey = ye(this.toolName);
|
|
620
677
|
let a = {};
|
|
621
|
-
for (let [e, t] of Object.entries(r))
|
|
678
|
+
for (let [e, t] of Object.entries(r)) ve.includes(e) || (a[e] = t);
|
|
622
679
|
this.toolConfig = Object.freeze(a);
|
|
623
680
|
}
|
|
624
681
|
render() {
|
|
@@ -648,7 +705,7 @@ function ge(e) {
|
|
|
648
705
|
this.registered && (this.registered = !1, (e = this.registry) == null || e.unregister(this.portalKey));
|
|
649
706
|
}
|
|
650
707
|
refreshActiveState() {
|
|
651
|
-
let t = typeof e.checkState == "function"
|
|
708
|
+
let t = typeof e.checkState == "function" && !!e.checkState(window.getSelection());
|
|
652
709
|
if (t !== this.active && (this.active = t, this.registered)) {
|
|
653
710
|
var n;
|
|
654
711
|
(n = this.registry) == null || n.setProps(this.portalKey, { active: t });
|
|
@@ -658,4 +715,4 @@ function ge(e) {
|
|
|
658
715
|
}, t.__isBlokReactInlineTool = !0, t.isInline = !0, t;
|
|
659
716
|
}
|
|
660
717
|
//#endregion
|
|
661
|
-
export {
|
|
718
|
+
export { z as BLOK_PORTAL_REGISTRY_CONFIG_KEY, B as BLOK_TOOL_NAME_CONFIG_KEY, X as BlockPortalHost, Q as BlokContent, pe as BlokEditor, L as BlokProvider, V as createBlockPortalRegistry, _e as createReactBlock, be as createReactInlineTool, me as useBlocks, J as useBlok, R as useBlokDefaults };
|