@bloklabs/react 1.2.1 → 1.2.3

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