@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.mjs CHANGED
@@ -1,51 +1,52 @@
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";
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 w = /* @__PURE__ */ new WeakMap();
8
+ var D = /* @__PURE__ */ new WeakMap();
8
9
  function ee(e, t) {
9
- w.set(e, t);
10
+ D.set(e, t);
10
11
  }
11
- function T(e) {
12
- return w.get(e);
12
+ function O(e) {
13
+ return D.get(e);
13
14
  }
14
- function E(e) {
15
- w.delete(e);
15
+ function k(e) {
16
+ D.delete(e);
16
17
  }
17
18
  //#endregion
18
- //#region \0@oxc-project+runtime@0.126.0/helpers/typeof.js
19
- function D(e) {
19
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
20
+ function A(e) {
20
21
  "@babel/helpers - typeof";
21
- return D = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
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
- }, D(e);
26
+ }, A(e);
26
27
  }
27
28
  //#endregion
28
- //#region \0@oxc-project+runtime@0.126.0/helpers/toPrimitive.js
29
- function O(e, t) {
30
- if (D(e) != "object" || !e) return e;
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 (D(r) != "object") return r;
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.126.0/helpers/toPropertyKey.js
41
- function k(e) {
42
- var t = O(e, "string");
43
- return D(t) == "symbol" ? t : t + "";
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.126.0/helpers/defineProperty.js
47
- function A(e, t, n) {
48
- return (t = k(t)) in e ? Object.defineProperty(e, 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.126.0/helpers/objectSpread2.js
57
- function j(e, t) {
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 M(e) {
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 ? j(Object(n), !0).forEach(function(t) {
71
- A(e, t, n[t]);
72
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : j(Object(n)).forEach(function(t) {
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 N = t({});
81
- function P({ defaults: e, children: t }) {
82
- return /* @__PURE__ */ x(N.Provider, {
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 te() {
88
- return i(N);
88
+ function R() {
89
+ return a(I);
89
90
  }
90
- function ne(e, t) {
91
+ function te(e, t) {
91
92
  if (Object.keys(e).length === 0) return t;
92
- let n = M({}, e);
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 = M(M({}, e.tools), t.tools)), n;
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 F = "__blokPortalRegistry", I = "__blokToolName", L = () => {
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 : M(M({}, i), {}, { props: M(M({}, i.props), {}, { config: o }) })), r(a);
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, M(M({}, i), {}, { props: M(M({}, i.props), n) })), r(a);
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, M(M({}, t), {}, { props: M(M({}, t.props), {}, { config: i }) }));
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
- }, R = /* @__PURE__ */ new WeakMap();
139
- function z(e, t) {
140
- R.set(e, t);
139
+ }, H = /* @__PURE__ */ new WeakMap();
140
+ function U(e, t) {
141
+ H.set(e, t);
141
142
  }
142
- function B(e) {
143
- return R.get(e);
143
+ function W(e) {
144
+ return H.get(e);
144
145
  }
145
- function V(e) {
146
- R.delete(e);
146
+ function G(e) {
147
+ H.delete(e);
147
148
  }
148
149
  //#endregion
149
150
  //#region src/live-tool-config.ts
150
- var H = (e) => {
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
- }, re = (e, t) => t.reduce((e, t) => {
155
+ }, ne = (e, t) => t.reduce((e, t) => {
155
156
  if (Array.isArray(e)) return typeof t == "number" ? e[t] : void 0;
156
- if (H(e)) return e[t];
157
- }, e), ie = (e, t) => {
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 (H(e)) {
165
- let r = H(t) ? t : {}, i = {};
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 H(r) ? r : {};
172
- }, U = (e, t) => {
173
- if (!H(e)) return e;
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 (!H(i) || !H(i.config)) {
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 = H(a) ? a[r] : void 0, s = re(H(o) ? o.config : void 0, i);
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 (H(n)) {
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] = M(M({}, i), {}, { config: a(i.config, []) });
199
+ n[r] = F(F({}, i), {}, { config: a(i.config, []) });
199
200
  }
200
201
  return n;
201
- }, W = (e) => {
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
- }, G = (e) => {
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
- }, K = (e, t) => {
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 (!W(a) && !G(a)) {
213
+ if (!q(a) && !ae(a)) {
213
214
  n[i] = a;
214
215
  continue;
215
216
  }
216
- let e = typeof a == "function" ? { class: a } : M({}, a);
217
- e.config = M(M({}, (r = e.config) == null ? {} : r), {}, {
218
- [F]: t,
219
- [I]: i
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 q(e, t) {
225
- let n = ne(i(N), e), [r, o] = l(null), u = c(n);
226
- u.current = n;
227
- let f = c({
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
- }), 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());
235
- a(() => {
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 e = f.current;
238
- if (e.destroyTimeout !== null && (clearTimeout(e.destroyTimeout), e.destroyTimeout = null), e.editor !== null && !e.isDestroyed && e.depsToken === p) return e.isEditorReady && o(e.editor), () => {
239
- J(e, o);
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 (e.editor !== null && !e.isDestroyed) {
242
- E(e.editor), V(e.editor);
244
+ if (t.editor !== null && !t.isDestroyed) {
245
+ k(t.editor), G(t.editor);
243
246
  try {
244
- e.editor.destroy();
247
+ t.editor.destroy();
245
248
  } catch (e) {}
246
- e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1, o(null);
247
- }
248
- let t = document.createElement("div");
249
- e.holder = t, e.isDestroyed = !1, e.isEditorReady = !1, e.depsToken = p;
250
- let n = u.current, r = L(), i = n.tools === void 0 ? void 0 : U(n.tools, () => u.current.tools), a = i === void 0 ? void 0 : K(i, r);
251
- x.current = r, S.current = i, C.current = /* @__PURE__ */ new Map();
252
- let s = M(M(M({}, n), a === void 0 ? {} : { tools: a }), {}, {
253
- holder: t,
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 = u.current).onReady) == null || t.call(n, ...e);
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 = u.current).onChange) == null || t.call(n, ...e);
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 = u.current).onEnter) == null ? void 0 : t.call(n, ...e);
267
+ return (t = (n = p.current).onEnter) == null ? void 0 : t.call(n, ...e);
265
268
  }
266
269
  });
267
- n.onSave && (s.onSave = (...e) => {
270
+ r.onSave && (s.onSave = (...e) => {
268
271
  var t, n;
269
- m.current = e[0], (t = (n = u.current).onSave) == null || t.call(n, ...e);
270
- }), n.onBeforeRender && (s.onBeforeRender = (...e) => {
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 = u.current).onBeforeRender) == null ? void 0 : n.call(r, ...e)) == null ? e[0] : t;
273
- }), n.onAfterRender && (s.onAfterRender = (...e) => {
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 = u.current).onAfterRender) == null || t.call(n, ...e);
278
+ (t = (n = p.current).onAfterRender) == null || t.call(n, ...e);
276
279
  });
277
- let c = new d(s);
278
- return e.editor = c, _.current = n.data, ee(c, t), z(c, r), c.isReady.then(() => {
279
- e.editor === c && !e.isDestroyed && (e.isEditorReady = !0, o(c));
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 (e.editor === c && !e.isDestroyed) {
282
- E(c), V(c);
284
+ if (t.editor === c && !t.isDestroyed) {
285
+ k(c), G(c);
283
286
  try {
284
287
  c.destroy();
285
288
  } catch (e) {}
286
- e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1, o(null);
289
+ t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, d(null);
287
290
  }
288
291
  }), () => {
289
- J(e, o);
292
+ Y(t, d);
290
293
  };
291
- }, [p]), a(() => {
292
- let e = x.current, t = f.current;
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 = u.current.tools;
297
+ let n = p.current.tools;
295
298
  if (typeof n != "object" || !n) return;
296
- let r = S.current;
299
+ let r = E.current;
297
300
  for (let [t, a] of Object.entries(n)) {
298
301
  var i;
299
- if (!W(a)) continue;
300
- let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s = ie(typeof o == "object" && o ? o.config : void 0, n), c = C.current.get(t);
301
- if (c !== void 0 && g(s, c)) continue;
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
- C.current.set(t, l), e.setToolConfig(t, l);
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 w = y(n.readOnly).enabled;
307
- a(() => {
308
- r !== null && r.readOnly.set(w);
309
- }, [r, w]);
310
- let { autofocus: T } = n;
311
- a(() => {
312
- r === null || !T || r.focus();
313
- }, [r, T]);
314
- let { theme: D } = n;
315
- a(() => {
316
- r === null || D === void 0 || r.theme.set(D);
317
- }, [r, D]);
318
- let { width: O } = n;
319
- a(() => {
320
- r === null || O === void 0 || r.width.set(O);
321
- }, [r, O]);
322
- let { placeholder: k } = n;
323
- a(() => {
324
- r === null || k === void 0 || r.placeholder.set(k);
325
- }, [r, k]);
326
- let { data: A } = n;
327
- return a(() => {
328
- if (r === null || A === void 0) return;
329
- let e = f.current;
330
- if (!(e.editor !== r || e.isDestroyed)) {
331
- if (h.current !== r && (h.current = r, b.current = void 0, g(A, _.current))) {
332
- m.current = A;
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
- g(A, m.current) || g(A, b.current) || (b.current = A, v.current = v.current.catch(() => void 0).then(() => r.render(A)).then(() => {
336
- m.current = A;
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
- b.current === A && (b.current = void 0);
355
+ w.current === z && (w.current = void 0);
339
356
  }));
340
357
  }
341
- }, [r, A]), r;
358
+ }, [s, z]), s;
342
359
  }
343
- function J(e, t) {
360
+ function Y(e, t) {
344
361
  e.destroyTimeout = setTimeout(() => {
345
362
  if (e.editor !== null) {
346
- E(e.editor), V(e.editor);
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 Y = class extends e {
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 = u(e.subscribe, e.getSnapshot, e.getSnapshot);
370
- return /* @__PURE__ */ x(b, { children: Array.from(t.entries()).map(([e, t]) => {
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 S(/* @__PURE__ */ x(Y, { children: /* @__PURE__ */ x(n, M({}, t.props)) }), t.hostEl, e);
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.126.0/helpers/objectWithoutPropertiesLoose.js
377
- function ae(e, t) {
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.126.0/helpers/objectWithoutProperties.js
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 = ae(e, t);
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 oe = ["editor"], Q = n(function(e, t) {
400
- let { editor: n } = e, r = Z(e, oe), i = c(null), o = (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
- a(() => {
424
+ o(() => {
408
425
  if (n === null || i.current === null) return;
409
- let e = T(n);
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 : B(n);
415
- return /* @__PURE__ */ x("div", M(M({ ref: o }, r), {}, { children: s === void 0 ? null : /* @__PURE__ */ x(X, { registry: s }) }));
416
- }), se = /* @__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("."), ce = [
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
- ], le = new Set(se), ue = n(function(e, t) {
422
- let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: s } = e, l = Z(e, ce), u = {}, d = {};
423
- for (let e of Object.keys(l)) {
424
- let t = l[e];
425
- le.has(e) ? u[e] = t : d[e] = t;
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 = q(u, n);
428
- o(t, () => f, [f]);
429
- let p = c(r);
444
+ let f = J(u, n);
445
+ s(t, () => f, [f]);
446
+ let p = l(r);
430
447
  p.current = r;
431
- let m = c(null);
432
- a(() => {
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 = c(i);
455
+ let h = l(i);
439
456
  h.current = i;
440
- let g = c(s);
441
- g.current = s;
442
- let _ = !!i, v = !!s;
443
- return a(() => {
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__ */ x(Q, M({ editor: f }, d));
484
+ ]), /* @__PURE__ */ C(Q, F({ editor: f }, d));
468
485
  }), $ = "block changed";
469
- function de(e) {
470
- let t = c(0), n = c(e);
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 i = r((n) => {
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 = r(() => t.current, []);
479
- return u(i, a, a), s(() => e === null ? p : m(e), [e]);
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 fe = [F, I];
484
- function pe(e) {
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 e.toolbox;
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 = _(e.propSchema, M(M({}, this.mirror), t));
498
- h(r, this.mirror) || (this.mirror = r, this.lastRendered = r, (n = this.registry) == null || n.setProps(this.blockApi.id, { data: r }), this.flushDispatch());
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[F];
502
- let o = i[I];
503
- this.toolName = typeof o == "string" ? o : void 0;
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)) fe.includes(e) || (s[e] = t);
559
+ for (let [e, t] of Object.entries(i)) ge.includes(e) || (s[e] = t);
506
560
  this.toolConfig = Object.freeze(s);
507
- let l = t.api;
561
+ let c = t.api;
508
562
  this.pointerDrag = () => {
509
563
  var e;
510
- return (l == null || (e = l.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
511
- }, this.mirror = _(e.propSchema, (r = t.data) == null ? {} : r), this.lastRendered = this.mirror, this.readOnly = t.readOnly;
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 = c(null);
515
- return a(() => {
516
- e.current !== null && v(e.current, u.getChildren());
517
- }), /* @__PURE__ */ x("div", {
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
- [f.nestedBlocks]: ""
573
+ [p.nestedBlocks]: ""
520
574
  });
521
575
  };
522
576
  }
523
577
  render() {
524
- var t;
525
- let n = document.createElement("div");
526
- return n.setAttribute("data-blok-mutation-free", "true"), this.hostEl = n, (t = this.registry) == null || t.register(this.blockApi.id, {
527
- hostEl: n,
528
- component: e.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
- }), n;
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 = _(e.propSchema, t == null ? {} : t);
543
- return h(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.pushProps({ data: r }), !0);
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 && C(() => {
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 me = [F, I], he = (e) => `__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
597
- function ge(e) {
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) == null ? !1 : t;
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[F];
618
- let i = r[I];
619
- this.toolName = typeof i == "string" ? i : e.type, this.portalKey = he(this.toolName);
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)) me.includes(e) || (a[e] = t);
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" ? !!e.checkState(window.getSelection()) : !1;
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 { F as BLOK_PORTAL_REGISTRY_CONFIG_KEY, I as BLOK_TOOL_NAME_CONFIG_KEY, X as BlockPortalHost, Q as BlokContent, ue as BlokEditor, P as BlokProvider, L as createBlockPortalRegistry, pe as createReactBlock, ge as createReactInlineTool, de as useBlocks, q as useBlok, te as useBlokDefaults };
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 };