@bloklabs/react 1.2.0 → 1.2.2
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 +361 -140
- package/package.json +2 -2
- package/src/BlockPortalHost.tsx +58 -0
- package/src/BlokContent.tsx +13 -1
- package/src/BlokEditor.tsx +6 -0
- package/src/block-portal-registry.ts +105 -0
- package/src/createReactBlock.tsx +304 -0
- package/src/index.ts +14 -0
- package/src/live-tool-config.ts +112 -0
- package/src/registry-map.ts +21 -0
- package/src/useBlok.ts +67 -0
- package/types/index.d.ts +112 -0
package/dist/index.mjs
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Blok as
|
|
3
|
-
import { EMPTY_API as
|
|
4
|
-
import { jsx as
|
|
1
|
+
import { Component as e, createContext as t, forwardRef as n, useCallback as r, useContext as i, useEffect as a, useImperativeHandle as o, useMemo as s, useRef as c, useState as l, useSyncExternalStore as u } from "react";
|
|
2
|
+
import { Blok as d } from "@bloklabs/core";
|
|
3
|
+
import { DATA_ATTR as f, EMPTY_API as p, createBlocksApiForEditor as m, deepEqual as h, deepEqual as g, fillDefaults as _, mountChildBlocks as v, normalizeReadOnlyConfig as ee } from "@bloklabs/core/adapters";
|
|
4
|
+
import { Fragment as y, jsx as b } from "react/jsx-runtime";
|
|
5
|
+
import { createPortal as x, flushSync as S } from "react-dom";
|
|
5
6
|
//#region src/holder-map.ts
|
|
6
|
-
var
|
|
7
|
-
function
|
|
8
|
-
|
|
7
|
+
var C = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function te(e, t) {
|
|
9
|
+
C.set(e, t);
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
11
|
+
function w(e) {
|
|
12
|
+
return C.get(e);
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
14
|
+
function T(e) {
|
|
15
|
+
C.delete(e);
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
17
18
|
//#region \0@oxc-project+runtime@0.126.0/helpers/typeof.js
|
|
18
|
-
function
|
|
19
|
+
function E(e) {
|
|
19
20
|
"@babel/helpers - typeof";
|
|
20
|
-
return
|
|
21
|
+
return E = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
21
22
|
return typeof e;
|
|
22
23
|
} : function(e) {
|
|
23
24
|
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
24
|
-
},
|
|
25
|
+
}, E(e);
|
|
25
26
|
}
|
|
26
27
|
//#endregion
|
|
27
28
|
//#region \0@oxc-project+runtime@0.126.0/helpers/toPrimitive.js
|
|
28
|
-
function
|
|
29
|
-
if (
|
|
29
|
+
function D(e, t) {
|
|
30
|
+
if (E(e) != "object" || !e) return e;
|
|
30
31
|
var n = e[Symbol.toPrimitive];
|
|
31
32
|
if (n !== void 0) {
|
|
32
33
|
var r = n.call(e, t || "default");
|
|
33
|
-
if (
|
|
34
|
+
if (E(r) != "object") return r;
|
|
34
35
|
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
35
36
|
}
|
|
36
37
|
return (t === "string" ? String : Number)(e);
|
|
37
38
|
}
|
|
38
39
|
//#endregion
|
|
39
40
|
//#region \0@oxc-project+runtime@0.126.0/helpers/toPropertyKey.js
|
|
40
|
-
function
|
|
41
|
-
var t =
|
|
42
|
-
return
|
|
41
|
+
function O(e) {
|
|
42
|
+
var t = D(e, "string");
|
|
43
|
+
return E(t) == "symbol" ? t : t + "";
|
|
43
44
|
}
|
|
44
45
|
//#endregion
|
|
45
46
|
//#region \0@oxc-project+runtime@0.126.0/helpers/defineProperty.js
|
|
46
|
-
function
|
|
47
|
-
return (t =
|
|
47
|
+
function k(e, t, n) {
|
|
48
|
+
return (t = O(t)) in e ? Object.defineProperty(e, t, {
|
|
48
49
|
value: n,
|
|
49
50
|
enumerable: !0,
|
|
50
51
|
configurable: !0,
|
|
@@ -53,7 +54,7 @@ function C(e, t, n) {
|
|
|
53
54
|
}
|
|
54
55
|
//#endregion
|
|
55
56
|
//#region \0@oxc-project+runtime@0.126.0/helpers/objectSpread2.js
|
|
56
|
-
function
|
|
57
|
+
function A(e, t) {
|
|
57
58
|
var n = Object.keys(e);
|
|
58
59
|
if (Object.getOwnPropertySymbols) {
|
|
59
60
|
var r = Object.getOwnPropertySymbols(e);
|
|
@@ -63,12 +64,12 @@ function w(e, t) {
|
|
|
63
64
|
}
|
|
64
65
|
return n;
|
|
65
66
|
}
|
|
66
|
-
function
|
|
67
|
+
function j(e) {
|
|
67
68
|
for (var t = 1; t < arguments.length; t++) {
|
|
68
69
|
var n = arguments[t] == null ? {} : arguments[t];
|
|
69
|
-
t % 2 ?
|
|
70
|
-
|
|
71
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) :
|
|
70
|
+
t % 2 ? A(Object(n), !0).forEach(function(t) {
|
|
71
|
+
k(e, t, n[t]);
|
|
72
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : A(Object(n)).forEach(function(t) {
|
|
72
73
|
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -76,130 +77,222 @@ function T(e) {
|
|
|
76
77
|
}
|
|
77
78
|
//#endregion
|
|
78
79
|
//#region src/provide-blok.tsx
|
|
79
|
-
var
|
|
80
|
-
function
|
|
81
|
-
return /* @__PURE__ */
|
|
80
|
+
var M = t({});
|
|
81
|
+
function N({ defaults: e, children: t }) {
|
|
82
|
+
return /* @__PURE__ */ b(M.Provider, {
|
|
82
83
|
value: e,
|
|
83
84
|
children: t
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
|
-
function
|
|
87
|
-
return
|
|
87
|
+
function P() {
|
|
88
|
+
return i(M);
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
+
function F(e, t) {
|
|
90
91
|
if (Object.keys(e).length === 0) return t;
|
|
91
|
-
let n =
|
|
92
|
+
let n = j({}, e);
|
|
92
93
|
for (let e of Object.keys(t)) {
|
|
93
94
|
let r = t[e];
|
|
94
95
|
r !== void 0 && (n[e] = r);
|
|
95
96
|
}
|
|
96
|
-
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools =
|
|
97
|
+
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = j(j({}, e.tools), t.tools)), n;
|
|
97
98
|
}
|
|
98
99
|
//#endregion
|
|
99
|
-
//#region src/
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
//#region src/block-portal-registry.ts
|
|
101
|
+
var I = "__blokPortalRegistry", L = () => {
|
|
102
|
+
let e = { snapshot: /* @__PURE__ */ new Map() }, t = /* @__PURE__ */ new Set(), n = (n) => {
|
|
103
|
+
e.snapshot = n, t.forEach((e) => e());
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
register(t, r) {
|
|
107
|
+
let i = new Map(e.snapshot);
|
|
108
|
+
i.set(t, r), n(i);
|
|
109
|
+
},
|
|
110
|
+
unregister(t) {
|
|
111
|
+
if (!e.snapshot.has(t)) return;
|
|
112
|
+
let r = new Map(e.snapshot);
|
|
113
|
+
r.delete(t), n(r);
|
|
114
|
+
},
|
|
115
|
+
setProps(t, r) {
|
|
116
|
+
let i = e.snapshot.get(t);
|
|
117
|
+
if (i === void 0) return;
|
|
118
|
+
let a = new Map(e.snapshot);
|
|
119
|
+
a.set(t, j(j({}, i), {}, { props: j(j({}, i.props), r) })), n(a);
|
|
120
|
+
},
|
|
121
|
+
subscribe(e) {
|
|
122
|
+
return t.add(e), () => {
|
|
123
|
+
t.delete(e);
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
getSnapshot() {
|
|
127
|
+
return e.snapshot;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}, R = /* @__PURE__ */ new WeakMap();
|
|
131
|
+
function z(e, t) {
|
|
132
|
+
R.set(e, t);
|
|
133
|
+
}
|
|
134
|
+
function B(e) {
|
|
135
|
+
return R.get(e);
|
|
136
|
+
}
|
|
137
|
+
function V(e) {
|
|
138
|
+
R.delete(e);
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/live-tool-config.ts
|
|
142
|
+
var H = (e) => {
|
|
143
|
+
if (typeof e != "object" || !e) return !1;
|
|
144
|
+
let t = Object.getPrototypeOf(e);
|
|
145
|
+
return t === Object.prototype || t === null;
|
|
146
|
+
}, U = (e, t) => t.reduce((e, t) => {
|
|
147
|
+
if (Array.isArray(e)) return typeof t == "number" ? e[t] : void 0;
|
|
148
|
+
if (H(e)) return e[t];
|
|
149
|
+
}, e), W = (e, t) => {
|
|
150
|
+
if (!H(e)) return e;
|
|
151
|
+
let n = {};
|
|
152
|
+
for (let [r, i] of Object.entries(e)) {
|
|
153
|
+
if (!H(i) || !H(i.config)) {
|
|
154
|
+
n[r] = i;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
let e = /* @__PURE__ */ new WeakSet(), a = (n, i) => {
|
|
158
|
+
if (typeof n == "function") {
|
|
159
|
+
let e = n;
|
|
160
|
+
return function(...n) {
|
|
161
|
+
let a = t(), o = H(a) ? a[r] : void 0, s = U(H(o) ? o.config : void 0, i);
|
|
162
|
+
return Reflect.apply(typeof s == "function" ? s : e, this, n);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (Array.isArray(n)) return e.has(n) ? n : (e.add(n), n.map((e, t) => a(e, [...i, t])));
|
|
166
|
+
if (H(n)) {
|
|
167
|
+
if (e.has(n)) return n;
|
|
168
|
+
e.add(n);
|
|
169
|
+
let t = {};
|
|
170
|
+
for (let [e, r] of Object.entries(n)) t[e] = a(r, [...i, e]);
|
|
171
|
+
return t;
|
|
172
|
+
}
|
|
173
|
+
return n;
|
|
174
|
+
};
|
|
175
|
+
n[r] = j(j({}, i), {}, { config: a(i.config, []) });
|
|
176
|
+
}
|
|
177
|
+
return n;
|
|
178
|
+
}, G = (e, t) => {
|
|
179
|
+
if (typeof e != "object" || !e) return e;
|
|
180
|
+
let n = {};
|
|
181
|
+
for (let [i, a] of Object.entries(e)) {
|
|
182
|
+
var r;
|
|
183
|
+
let e = typeof a == "function" ? a : a == null ? void 0 : a.class;
|
|
184
|
+
if (!(typeof e == "function" && e.__isBlokReactBlock === !0)) {
|
|
185
|
+
n[i] = a;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
let o = typeof a == "function" ? { class: a } : j({}, a);
|
|
189
|
+
o.config = j(j({}, (r = o.config) == null ? {} : r), {}, { [I]: t }), n[i] = o;
|
|
190
|
+
}
|
|
191
|
+
return n;
|
|
192
|
+
};
|
|
193
|
+
function K(e, t) {
|
|
194
|
+
let n = F(i(M), e), [r, o] = l(null), u = c(n);
|
|
195
|
+
u.current = n;
|
|
196
|
+
let f = c({
|
|
104
197
|
editor: null,
|
|
105
198
|
holder: null,
|
|
106
199
|
destroyTimeout: null,
|
|
107
200
|
isDestroyed: !1,
|
|
108
201
|
isEditorReady: !1,
|
|
109
202
|
depsToken: null
|
|
110
|
-
}),
|
|
111
|
-
|
|
203
|
+
}), p = s(() => ({}), t == null ? [] : t), m = c(n.data), h = c(null), _ = c(n.data), v = c(Promise.resolve()), y = c(void 0);
|
|
204
|
+
a(() => {
|
|
112
205
|
if (typeof window > "u") return;
|
|
113
206
|
let e = f.current;
|
|
114
|
-
if (e.destroyTimeout !== null && (clearTimeout(e.destroyTimeout), e.destroyTimeout = null), e.editor !== null && !e.isDestroyed && e.depsToken ===
|
|
115
|
-
|
|
207
|
+
if (e.destroyTimeout !== null && (clearTimeout(e.destroyTimeout), e.destroyTimeout = null), e.editor !== null && !e.isDestroyed && e.depsToken === p) return e.isEditorReady && o(e.editor), () => {
|
|
208
|
+
q(e, o);
|
|
116
209
|
};
|
|
117
210
|
if (e.editor !== null && !e.isDestroyed) {
|
|
118
|
-
|
|
211
|
+
T(e.editor), V(e.editor);
|
|
119
212
|
try {
|
|
120
213
|
e.editor.destroy();
|
|
121
214
|
} catch (e) {}
|
|
122
|
-
e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1,
|
|
215
|
+
e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1, o(null);
|
|
123
216
|
}
|
|
124
217
|
let t = document.createElement("div");
|
|
125
|
-
e.holder = t, e.isDestroyed = !1, e.isEditorReady = !1, e.depsToken =
|
|
126
|
-
let n =
|
|
218
|
+
e.holder = t, e.isDestroyed = !1, e.isEditorReady = !1, e.depsToken = p;
|
|
219
|
+
let n = u.current, r = L(), i = n.tools === void 0 ? void 0 : G(W(n.tools, () => u.current.tools), r), a = j(j(j({}, n), i === void 0 ? {} : { tools: i }), {}, {
|
|
127
220
|
holder: t,
|
|
128
221
|
onReady: (...e) => {
|
|
129
222
|
var t, n;
|
|
130
|
-
(t = (n =
|
|
223
|
+
(t = (n = u.current).onReady) == null || t.call(n, ...e);
|
|
131
224
|
},
|
|
132
225
|
onChange: (...e) => {
|
|
133
226
|
var t, n;
|
|
134
|
-
(t = (n =
|
|
227
|
+
(t = (n = u.current).onChange) == null || t.call(n, ...e);
|
|
135
228
|
}
|
|
136
229
|
});
|
|
137
|
-
n.onSave && (
|
|
230
|
+
n.onSave && (a.onSave = (...e) => {
|
|
138
231
|
var t, n;
|
|
139
|
-
|
|
140
|
-
}), n.onBeforeRender && (
|
|
232
|
+
m.current = e[0], (t = (n = u.current).onSave) == null || t.call(n, ...e);
|
|
233
|
+
}), n.onBeforeRender && (a.onBeforeRender = (...e) => {
|
|
141
234
|
var t, n, r;
|
|
142
|
-
return (t = (n = (r =
|
|
143
|
-
}), n.onAfterRender && (
|
|
235
|
+
return (t = (n = (r = u.current).onBeforeRender) == null ? void 0 : n.call(r, ...e)) == null ? e[0] : t;
|
|
236
|
+
}), n.onAfterRender && (a.onAfterRender = (...e) => {
|
|
144
237
|
var t, n;
|
|
145
|
-
(t = (n =
|
|
238
|
+
(t = (n = u.current).onAfterRender) == null || t.call(n, ...e);
|
|
146
239
|
});
|
|
147
|
-
let
|
|
148
|
-
return e.editor =
|
|
149
|
-
e.editor ===
|
|
240
|
+
let s = new d(a);
|
|
241
|
+
return e.editor = s, _.current = n.data, te(s, t), z(s, r), s.isReady.then(() => {
|
|
242
|
+
e.editor === s && !e.isDestroyed && (e.isEditorReady = !0, o(s));
|
|
150
243
|
}).catch(() => {
|
|
151
|
-
if (e.editor ===
|
|
152
|
-
|
|
244
|
+
if (e.editor === s && !e.isDestroyed) {
|
|
245
|
+
T(s), V(s);
|
|
153
246
|
try {
|
|
154
|
-
|
|
247
|
+
s.destroy();
|
|
155
248
|
} catch (e) {}
|
|
156
|
-
e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1,
|
|
249
|
+
e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1, o(null);
|
|
157
250
|
}
|
|
158
251
|
}), () => {
|
|
159
|
-
|
|
252
|
+
q(e, o);
|
|
160
253
|
};
|
|
161
|
-
}, [
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}, [
|
|
166
|
-
let { autofocus:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}, [
|
|
170
|
-
let { theme:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}, [
|
|
174
|
-
let { width:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}, [
|
|
178
|
-
let { placeholder:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}, [
|
|
182
|
-
let { data:
|
|
183
|
-
return
|
|
184
|
-
if (
|
|
254
|
+
}, [p]);
|
|
255
|
+
let b = ee(n.readOnly).enabled;
|
|
256
|
+
a(() => {
|
|
257
|
+
r !== null && r.readOnly.set(b);
|
|
258
|
+
}, [r, b]);
|
|
259
|
+
let { autofocus: x } = n;
|
|
260
|
+
a(() => {
|
|
261
|
+
r === null || !x || r.focus();
|
|
262
|
+
}, [r, x]);
|
|
263
|
+
let { theme: S } = n;
|
|
264
|
+
a(() => {
|
|
265
|
+
r === null || S === void 0 || r.theme.set(S);
|
|
266
|
+
}, [r, S]);
|
|
267
|
+
let { width: C } = n;
|
|
268
|
+
a(() => {
|
|
269
|
+
r === null || C === void 0 || r.width.set(C);
|
|
270
|
+
}, [r, C]);
|
|
271
|
+
let { placeholder: w } = n;
|
|
272
|
+
a(() => {
|
|
273
|
+
r === null || w === void 0 || r.placeholder.set(w);
|
|
274
|
+
}, [r, w]);
|
|
275
|
+
let { data: E } = n;
|
|
276
|
+
return a(() => {
|
|
277
|
+
if (r === null || E === void 0) return;
|
|
185
278
|
let e = f.current;
|
|
186
|
-
if (!(e.editor !==
|
|
187
|
-
if (
|
|
188
|
-
|
|
279
|
+
if (!(e.editor !== r || e.isDestroyed)) {
|
|
280
|
+
if (h.current !== r && (h.current = r, y.current = void 0, g(E, _.current))) {
|
|
281
|
+
m.current = E;
|
|
189
282
|
return;
|
|
190
283
|
}
|
|
191
|
-
|
|
192
|
-
|
|
284
|
+
g(E, m.current) || g(E, y.current) || (y.current = E, v.current = v.current.catch(() => void 0).then(() => r.render(E)).then(() => {
|
|
285
|
+
m.current = E;
|
|
193
286
|
}, () => {}).then(() => {
|
|
194
|
-
|
|
287
|
+
y.current === E && (y.current = void 0);
|
|
195
288
|
}));
|
|
196
289
|
}
|
|
197
|
-
}, [
|
|
290
|
+
}, [r, E]), r;
|
|
198
291
|
}
|
|
199
|
-
function
|
|
292
|
+
function q(e, t) {
|
|
200
293
|
e.destroyTimeout = setTimeout(() => {
|
|
201
294
|
if (e.editor !== null) {
|
|
202
|
-
|
|
295
|
+
T(e.editor), V(e.editor);
|
|
203
296
|
try {
|
|
204
297
|
e.editor.destroy();
|
|
205
298
|
} catch (e) {}
|
|
@@ -208,8 +301,29 @@ function j(e, t) {
|
|
|
208
301
|
}, 0);
|
|
209
302
|
}
|
|
210
303
|
//#endregion
|
|
304
|
+
//#region src/BlockPortalHost.tsx
|
|
305
|
+
var J = class extends e {
|
|
306
|
+
constructor(...e) {
|
|
307
|
+
super(...e), this.state = { failed: !1 };
|
|
308
|
+
}
|
|
309
|
+
static getDerivedStateFromError() {
|
|
310
|
+
return { failed: !0 };
|
|
311
|
+
}
|
|
312
|
+
componentDidCatch() {}
|
|
313
|
+
render() {
|
|
314
|
+
return this.state.failed ? null : this.props.children;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
function Y({ registry: e }) {
|
|
318
|
+
let t = u(e.subscribe, e.getSnapshot, e.getSnapshot);
|
|
319
|
+
return /* @__PURE__ */ b(y, { children: Array.from(t.entries()).map(([e, t]) => {
|
|
320
|
+
let n = t.component;
|
|
321
|
+
return x(/* @__PURE__ */ b(J, { children: /* @__PURE__ */ b(n, j({}, t.props)) }), t.hostEl, e);
|
|
322
|
+
}) });
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
211
325
|
//#region \0@oxc-project+runtime@0.126.0/helpers/objectWithoutPropertiesLoose.js
|
|
212
|
-
function
|
|
326
|
+
function X(e, t) {
|
|
213
327
|
if (e == null) return {};
|
|
214
328
|
var n = {};
|
|
215
329
|
for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
|
|
@@ -220,9 +334,9 @@ function M(e, t) {
|
|
|
220
334
|
}
|
|
221
335
|
//#endregion
|
|
222
336
|
//#region \0@oxc-project+runtime@0.126.0/helpers/objectWithoutProperties.js
|
|
223
|
-
function
|
|
337
|
+
function Z(e, t) {
|
|
224
338
|
if (e == null) return {};
|
|
225
|
-
var n, r, i =
|
|
339
|
+
var n, r, i = X(e, t);
|
|
226
340
|
if (Object.getOwnPropertySymbols) {
|
|
227
341
|
var a = Object.getOwnPropertySymbols(e);
|
|
228
342
|
for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
|
|
@@ -231,60 +345,62 @@ function N(e, t) {
|
|
|
231
345
|
}
|
|
232
346
|
//#endregion
|
|
233
347
|
//#region src/BlokContent.tsx
|
|
234
|
-
var
|
|
235
|
-
let { editor: n } = e, r =
|
|
236
|
-
|
|
237
|
-
if (n === null || a.current === null) return;
|
|
238
|
-
let e = v(n);
|
|
239
|
-
if (e !== void 0) return a.current.appendChild(e), () => {
|
|
240
|
-
e.remove();
|
|
241
|
-
};
|
|
242
|
-
}, [n]), /* @__PURE__ */ h("div", T({ ref: (e) => {
|
|
243
|
-
if (a.current = e, typeof t == "function") t(e);
|
|
348
|
+
var ne = ["editor"], Q = n(function(e, t) {
|
|
349
|
+
let { editor: n } = e, r = Z(e, ne), i = c(null), o = (e) => {
|
|
350
|
+
if (i.current = e, typeof t == "function") t(e);
|
|
244
351
|
else if (t != null) {
|
|
245
352
|
let n = t;
|
|
246
353
|
n.current = e;
|
|
247
354
|
}
|
|
248
|
-
}
|
|
249
|
-
|
|
355
|
+
};
|
|
356
|
+
a(() => {
|
|
357
|
+
if (n === null || i.current === null) return;
|
|
358
|
+
let e = w(n);
|
|
359
|
+
if (e !== void 0) return i.current.appendChild(e), () => {
|
|
360
|
+
e.remove();
|
|
361
|
+
};
|
|
362
|
+
}, [n]);
|
|
363
|
+
let s = n === null ? void 0 : B(n);
|
|
364
|
+
return /* @__PURE__ */ b("div", j(j({ ref: o }, r), {}, { children: s === void 0 ? null : /* @__PURE__ */ b(Y, { registry: s }) }));
|
|
365
|
+
}), re = /* @__PURE__ */ "autofocus.defaultBlock.dataModel.placeholder.sanitizer.hideToolbar.maxHistoryLength.historyDebounceTime.newGroupDelay.globalUndoRedo.tools.data.minHeight.logLevel.readOnly.i18n.link.linkPaste.onBeforePaste.onReady.onChange.onSave.onBeforeRender.onAfterRender.inlineToolbar.tunes.style.theme.onThemeChange.scrollToBlock.user.resolveUser.notifierPosition.notifier.width".split("."), ie = [
|
|
250
366
|
"deps",
|
|
251
367
|
"onReady",
|
|
252
368
|
"onBlocksRendered",
|
|
253
369
|
"onBlockRendered"
|
|
254
|
-
],
|
|
255
|
-
let { deps: n, onReady: r, onBlocksRendered:
|
|
370
|
+
], ae = new Set(re), oe = n(function(e, t) {
|
|
371
|
+
let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: s } = e, l = Z(e, ie), u = {}, d = {};
|
|
256
372
|
for (let e of Object.keys(l)) {
|
|
257
373
|
let t = l[e];
|
|
258
|
-
|
|
374
|
+
ae.has(e) ? u[e] = t : d[e] = t;
|
|
259
375
|
}
|
|
260
|
-
let f =
|
|
261
|
-
|
|
262
|
-
let p =
|
|
263
|
-
p.current = r,
|
|
376
|
+
let f = K(u, n);
|
|
377
|
+
o(t, () => f, [f]);
|
|
378
|
+
let p = c(r);
|
|
379
|
+
p.current = r, a(() => {
|
|
264
380
|
if (f !== null) {
|
|
265
381
|
var e;
|
|
266
382
|
(e = p.current) == null || e.call(p, f);
|
|
267
383
|
}
|
|
268
384
|
}, [f]);
|
|
269
|
-
let m =
|
|
270
|
-
m.current =
|
|
271
|
-
let
|
|
272
|
-
|
|
273
|
-
let
|
|
274
|
-
return
|
|
385
|
+
let m = c(i);
|
|
386
|
+
m.current = i;
|
|
387
|
+
let h = c(s);
|
|
388
|
+
h.current = s;
|
|
389
|
+
let g = !!i, _ = !!s;
|
|
390
|
+
return a(() => {
|
|
275
391
|
if (f === null) return;
|
|
276
392
|
let e = [];
|
|
277
|
-
if (
|
|
393
|
+
if (g) {
|
|
278
394
|
let t = (e) => {
|
|
279
395
|
var t;
|
|
280
396
|
return (t = m.current) == null ? void 0 : t.call(m, e);
|
|
281
397
|
};
|
|
282
398
|
f.on("blocks:rendered", t), e.push(["blocks:rendered", t]);
|
|
283
399
|
}
|
|
284
|
-
if (
|
|
400
|
+
if (_) {
|
|
285
401
|
let t = (e) => {
|
|
286
402
|
var t;
|
|
287
|
-
return (t =
|
|
403
|
+
return (t = h.current) == null ? void 0 : t.call(h, e);
|
|
288
404
|
};
|
|
289
405
|
f.on("block:rendered", t), e.push(["block:rendered", t]);
|
|
290
406
|
}
|
|
@@ -293,21 +409,126 @@ var P = ["editor"], F = t(function(e, t) {
|
|
|
293
409
|
};
|
|
294
410
|
}, [
|
|
295
411
|
f,
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
]), /* @__PURE__ */
|
|
299
|
-
}),
|
|
300
|
-
function
|
|
301
|
-
let t =
|
|
302
|
-
|
|
303
|
-
let i =
|
|
412
|
+
g,
|
|
413
|
+
_
|
|
414
|
+
]), /* @__PURE__ */ b(Q, j({ editor: f }, d));
|
|
415
|
+
}), $ = "block changed";
|
|
416
|
+
function se(e) {
|
|
417
|
+
let t = c(0), n = c(e);
|
|
418
|
+
n.current !== e && (n.current = e, t.current = 0);
|
|
419
|
+
let i = r((n) => {
|
|
304
420
|
if (e === null) return () => void 0;
|
|
305
421
|
let r = () => {
|
|
306
422
|
t.current += 1, n();
|
|
307
423
|
};
|
|
308
|
-
return e.on(
|
|
309
|
-
}, [e]), a =
|
|
310
|
-
return
|
|
424
|
+
return e.on($, r), () => e.off($, r);
|
|
425
|
+
}, [e]), a = r(() => t.current, []);
|
|
426
|
+
return u(i, a, a), s(() => e === null ? p : m(e), [e]);
|
|
427
|
+
}
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/createReactBlock.tsx
|
|
430
|
+
function ce(e) {
|
|
431
|
+
var t;
|
|
432
|
+
return t = class {
|
|
433
|
+
static get toolbox() {
|
|
434
|
+
return e.toolbox;
|
|
435
|
+
}
|
|
436
|
+
static get isReadOnlySupported() {
|
|
437
|
+
return !0;
|
|
438
|
+
}
|
|
439
|
+
constructor(t) {
|
|
440
|
+
var n, r;
|
|
441
|
+
this.hostEl = null, this.pendingDispatch = !1, this.commit = (t) => {
|
|
442
|
+
var n;
|
|
443
|
+
let r = _(e.propSchema, j(j({}, this.mirror), t));
|
|
444
|
+
this.mirror = r, this.lastRendered = r, (n = this.registry) == null || n.setProps(this.blockApi.id, { data: r }), this.flushDispatch();
|
|
445
|
+
}, this.blockApi = t.block;
|
|
446
|
+
let i = (n = t.config) == null ? {} : n;
|
|
447
|
+
this.registry = i[I];
|
|
448
|
+
let o = t.api;
|
|
449
|
+
this.pointerDrag = () => {
|
|
450
|
+
var e;
|
|
451
|
+
return (o == null || (e = o.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
|
|
452
|
+
}, this.mirror = _(e.propSchema, (r = t.data) == null ? {} : r), this.lastRendered = this.mirror, this.readOnly = t.readOnly;
|
|
453
|
+
let s = this.blockApi;
|
|
454
|
+
this.childrenComponent = function() {
|
|
455
|
+
let e = c(null);
|
|
456
|
+
return a(() => {
|
|
457
|
+
e.current !== null && v(e.current, s.getChildren());
|
|
458
|
+
}), /* @__PURE__ */ b("div", {
|
|
459
|
+
ref: e,
|
|
460
|
+
[f.nestedBlocks]: ""
|
|
461
|
+
});
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
render() {
|
|
465
|
+
var t;
|
|
466
|
+
let n = document.createElement("div");
|
|
467
|
+
return n.setAttribute("data-blok-mutation-free", "true"), this.hostEl = n, (t = this.registry) == null || t.register(this.blockApi.id, {
|
|
468
|
+
hostEl: n,
|
|
469
|
+
component: e.component,
|
|
470
|
+
props: this.buildProps()
|
|
471
|
+
}), n;
|
|
472
|
+
}
|
|
473
|
+
rendered() {
|
|
474
|
+
var t;
|
|
475
|
+
(t = e.onRendered) == null || t.call(e, this.blockApi);
|
|
476
|
+
}
|
|
477
|
+
save() {
|
|
478
|
+
return this.mirror;
|
|
479
|
+
}
|
|
480
|
+
async setData(t) {
|
|
481
|
+
var n = this;
|
|
482
|
+
let r = _(e.propSchema, t == null ? {} : t);
|
|
483
|
+
return h(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.pushProps({ data: r }), !0);
|
|
484
|
+
}
|
|
485
|
+
setReadOnly(e) {
|
|
486
|
+
this.readOnly = e, this.pushProps({ readOnly: e });
|
|
487
|
+
}
|
|
488
|
+
moved() {
|
|
489
|
+
var t;
|
|
490
|
+
(t = e.onMoved) == null || t.call(e, this.blockApi);
|
|
491
|
+
}
|
|
492
|
+
removed() {
|
|
493
|
+
var t, n;
|
|
494
|
+
(t = this.registry) == null || t.unregister(this.blockApi.id), (n = e.onRemoved) == null || n.call(e, this.blockApi);
|
|
495
|
+
}
|
|
496
|
+
destroy() {
|
|
497
|
+
var e;
|
|
498
|
+
(e = this.registry) == null || e.unregister(this.blockApi.id);
|
|
499
|
+
}
|
|
500
|
+
buildProps() {
|
|
501
|
+
return {
|
|
502
|
+
data: this.mirror,
|
|
503
|
+
commit: this.commit,
|
|
504
|
+
block: this.blockApi,
|
|
505
|
+
readOnly: this.readOnly,
|
|
506
|
+
BlockChildren: this.childrenComponent
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
pushProps(e) {
|
|
510
|
+
let t = this.registry;
|
|
511
|
+
t !== void 0 && S(() => {
|
|
512
|
+
t.setProps(this.blockApi.id, e);
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
flushDispatch() {
|
|
516
|
+
if (!this.pointerDrag()) {
|
|
517
|
+
this.pendingDispatch = !1, this.blockApi.dispatchChange();
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (this.pendingDispatch) return;
|
|
521
|
+
this.pendingDispatch = !0;
|
|
522
|
+
let e = () => {
|
|
523
|
+
if (this.pointerDrag()) {
|
|
524
|
+
requestAnimationFrame(e);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
this.pendingDispatch = !1, this.blockApi.dispatchChange();
|
|
528
|
+
};
|
|
529
|
+
requestAnimationFrame(e);
|
|
530
|
+
}
|
|
531
|
+
}, t.__isBlokReactBlock = !0, t;
|
|
311
532
|
}
|
|
312
533
|
//#endregion
|
|
313
|
-
export {
|
|
534
|
+
export { I as BLOK_PORTAL_REGISTRY_CONFIG_KEY, Y as BlockPortalHost, Q as BlokContent, oe as BlokEditor, N as BlokProvider, L as createBlockPortalRegistry, ce as createReactBlock, se as useBlocks, K as useBlok, P as useBlokDefaults };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloklabs/react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "React bindings for the Blok editor",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JackUait",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"build": "yarn run -T vite build --mode production"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@bloklabs/core": "^1.2.
|
|
36
|
+
"@bloklabs/core": "^1.2.2",
|
|
37
37
|
"react": "^18.0.0 || ^19.0.0",
|
|
38
38
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
39
39
|
}
|