@bloklabs/react 1.2.5 → 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
- function T(e, t) {
9
- w.set(e, t);
8
+ var D = /* @__PURE__ */ new WeakMap();
9
+ function ee(e, t) {
10
+ D.set(e, t);
10
11
  }
11
- function E(e) {
12
- return w.get(e);
12
+ function O(e) {
13
+ return D.get(e);
13
14
  }
14
- function D(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 O(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 O = 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
- }, O(e);
26
+ }, A(e);
26
27
  }
27
28
  //#endregion
28
- //#region \0@oxc-project+runtime@0.126.0/helpers/toPrimitive.js
29
- function k(e, t) {
30
- if (O(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 (O(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 A(e) {
42
- var t = k(e, "string");
43
- return O(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 j(e, t, n) {
48
- return (t = A(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 j(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 M(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 M(e, t) {
64
65
  }
65
66
  return n;
66
67
  }
67
- function N(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 ? 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) {
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 N(e) {
77
78
  }
78
79
  //#endregion
79
80
  //#region src/provide-blok.tsx
80
- var P = t({});
81
- function F({ defaults: e, children: t }) {
82
- return /* @__PURE__ */ x(P.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 I() {
88
- return i(P);
88
+ function R() {
89
+ return a(I);
89
90
  }
90
- function ee(e, t) {
91
+ function te(e, t) {
91
92
  if (Object.keys(e).length === 0) return t;
92
- let n = N({}, 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 = N(N({}, 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 L = "__blokPortalRegistry", R = "__blokToolName", z = () => {
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 : N(N({}, i), {}, { props: N(N({}, 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 L = "__blokPortalRegistry", R = "__blokToolName", z = () => {
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, N(N({}, i), {}, { props: N(N({}, 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, N(N({}, t), {}, { props: N(N({}, 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 L = "__blokPortalRegistry", R = "__blokToolName", z = () => {
135
136
  return e.snapshot;
136
137
  }
137
138
  };
138
- }, B = /* @__PURE__ */ new WeakMap();
139
- function V(e, t) {
140
- B.set(e, t);
139
+ }, H = /* @__PURE__ */ new WeakMap();
140
+ function U(e, t) {
141
+ H.set(e, t);
141
142
  }
142
- function H(e) {
143
- return B.get(e);
143
+ function W(e) {
144
+ return H.get(e);
144
145
  }
145
- function U(e) {
146
- B.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 W = (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
- }, G = (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 (W(e)) return e[t];
157
- }, e), K = (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 (W(e)) {
165
- let r = W(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 W(r) ? r : {};
172
- }, te = (e, t) => {
173
- if (!W(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 (!W(i) || !W(i.config)) {
177
+ if (!K(i) || !K(i.config)) {
177
178
  n[r] = i;
178
179
  continue;
179
180
  }
@@ -181,12 +182,12 @@ var W = (e) => {
181
182
  if (typeof n == "function") {
182
183
  let e = n;
183
184
  return function(...n) {
184
- let a = t(), o = W(a) ? a[r] : void 0, s = G(W(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 (W(n)) {
190
+ if (K(n)) {
190
191
  if (e.has(n)) return n;
191
192
  e.add(n);
192
193
  let t = {};
@@ -195,152 +196,171 @@ var W = (e) => {
195
196
  }
196
197
  return n;
197
198
  };
198
- n[r] = N(N({}, i), {}, { config: a(i.config, []) });
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
- }, ne = (e, t) => {
205
+ }, ae = (e) => {
206
+ let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
207
+ return typeof t == "function" && t.__isBlokReactInlineTool === !0;
208
+ }, oe = (e, t) => {
205
209
  if (typeof e != "object" || !e) return e;
206
210
  let n = {};
207
211
  for (let [i, a] of Object.entries(e)) {
208
212
  var r;
209
- if (!q(a)) {
213
+ if (!q(a) && !ae(a)) {
210
214
  n[i] = a;
211
215
  continue;
212
216
  }
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
+ 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
217
221
  }), n[i] = e;
218
222
  }
219
223
  return n;
220
224
  };
221
225
  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({
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({
225
230
  editor: null,
226
231
  holder: null,
227
232
  destroyTimeout: null,
228
233
  isDestroyed: !1,
229
234
  isEditorReady: !1,
230
235
  depsToken: null
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(() => {
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;
233
239
  if (typeof window > "u") return;
234
- let e = f.current;
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);
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);
237
243
  };
238
- if (e.editor !== null && !e.isDestroyed) {
239
- D(e.editor), U(e.editor);
244
+ if (t.editor !== null && !t.isDestroyed) {
245
+ k(t.editor), G(t.editor);
240
246
  try {
241
- e.editor.destroy();
247
+ t.editor.destroy();
242
248
  } catch (e) {}
243
- e.editor = null, e.holder = null, e.isDestroyed = !0, e.isEditorReady = !1, o(null);
244
- }
245
- let t = document.createElement("div");
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 }), {}, {
250
- 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,
251
257
  onReady: (...e) => {
252
258
  var t, n;
253
- (t = (n = u.current).onReady) == null || t.call(n, ...e);
259
+ (t = (n = p.current).onReady) == null || t.call(n, ...e);
254
260
  },
255
261
  onChange: (...e) => {
256
262
  var t, n;
257
- (t = (n = u.current).onChange) == null || t.call(n, ...e);
263
+ (t = (n = p.current).onChange) == null || t.call(n, ...e);
258
264
  },
259
265
  onEnter: (...e) => {
260
266
  var t, n;
261
- 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);
262
268
  }
263
269
  });
264
- n.onSave && (s.onSave = (...e) => {
270
+ r.onSave && (s.onSave = (...e) => {
265
271
  var t, n;
266
- m.current = e[0], (t = (n = u.current).onSave) == null || t.call(n, ...e);
267
- }), 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) => {
268
274
  var t, n, r;
269
- return (t = (n = (r = u.current).onBeforeRender) == null ? void 0 : n.call(r, ...e)) == null ? e[0] : t;
270
- }), 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) => {
271
277
  var t, n;
272
- (t = (n = u.current).onAfterRender) == null || t.call(n, ...e);
278
+ (t = (n = p.current).onAfterRender) == null || t.call(n, ...e);
273
279
  });
274
- let c = new d(s);
275
- return e.editor = c, _.current = n.data, T(c, t), V(c, r), c.isReady.then(() => {
276
- 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));
277
283
  }).catch(() => {
278
- if (e.editor === c && !e.isDestroyed) {
279
- D(c), U(c);
284
+ if (t.editor === c && !t.isDestroyed) {
285
+ k(c), G(c);
280
286
  try {
281
287
  c.destroy();
282
288
  } catch (e) {}
283
- 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);
284
290
  }
285
291
  }), () => {
286
- Y(e, o);
292
+ Y(t, d);
287
293
  };
288
- }, [p]), a(() => {
289
- let e = x.current, t = f.current;
294
+ }, [h]), o(() => {
295
+ let e = T.current, t = m.current;
290
296
  if (e === null || t.editor === null || t.isDestroyed) return;
291
- let n = u.current.tools;
297
+ let n = p.current.tools;
292
298
  if (typeof n != "object" || !n) return;
293
- let r = S.current;
299
+ let r = E.current;
294
300
  for (let [t, a] of Object.entries(n)) {
295
301
  var i;
296
302
  if (!q(a)) continue;
297
- 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);
298
- if (c !== void 0 && g(s, c)) 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;
299
305
  let l = Object.freeze(s);
300
- 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 }));
301
317
  }
302
318
  });
303
- let w = y(n.readOnly).enabled;
304
- a(() => {
305
- r !== null && r.readOnly.set(w);
306
- }, [r, w]);
307
- let { autofocus: E } = n;
308
- a(() => {
309
- r === null || !E || r.focus();
310
- }, [r, E]);
311
- let { theme: O } = n;
312
- a(() => {
313
- r === null || O === void 0 || r.theme.set(O);
314
- }, [r, O]);
315
- let { width: k } = n;
316
- a(() => {
317
- r === null || k === void 0 || r.width.set(k);
318
- }, [r, k]);
319
- let { placeholder: A } = n;
320
- a(() => {
321
- r === null || A === void 0 || r.placeholder.set(A);
322
- }, [r, A]);
323
- let { data: j } = n;
324
- return a(() => {
325
- if (r === null || j === void 0) return;
326
- let e = f.current;
327
- if (!(e.editor !== r || e.isDestroyed)) {
328
- if (h.current !== r && (h.current = r, b.current = void 0, g(j, _.current))) {
329
- m.current = j;
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;
330
350
  return;
331
351
  }
332
- g(j, m.current) || g(j, b.current) || (b.current = j, v.current = v.current.catch(() => void 0).then(() => r.render(j)).then(() => {
333
- m.current = j;
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;
334
354
  }, () => {}).then(() => {
335
- b.current === j && (b.current = void 0);
355
+ w.current === z && (w.current = void 0);
336
356
  }));
337
357
  }
338
- }, [r, j]), r;
358
+ }, [s, z]), s;
339
359
  }
340
360
  function Y(e, t) {
341
361
  e.destroyTimeout = setTimeout(() => {
342
362
  if (e.editor !== null) {
343
- D(e.editor), U(e.editor);
363
+ k(e.editor), G(e.editor);
344
364
  try {
345
365
  e.editor.destroy();
346
366
  } catch (e) {}
@@ -350,7 +370,7 @@ function Y(e, t) {
350
370
  }
351
371
  //#endregion
352
372
  //#region src/BlockPortalHost.tsx
353
- var re = class extends e {
373
+ var se = class extends e {
354
374
  constructor(...e) {
355
375
  super(...e), this.state = { failed: !1 };
356
376
  }
@@ -363,15 +383,15 @@ var re = class extends e {
363
383
  }
364
384
  };
365
385
  function X({ registry: e }) {
366
- let t = u(e.subscribe, e.getSnapshot, e.getSnapshot);
367
- 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]) => {
368
388
  let n = t.component;
369
- return S(/* @__PURE__ */ x(re, { children: /* @__PURE__ */ x(n, N({}, t.props)) }), t.hostEl, e);
389
+ return w(/* @__PURE__ */ C(se, { children: /* @__PURE__ */ C(n, F({}, t.props)) }), t.hostEl, e);
370
390
  }) });
371
391
  }
372
392
  //#endregion
373
- //#region \0@oxc-project+runtime@0.126.0/helpers/objectWithoutPropertiesLoose.js
374
- function ie(e, t) {
393
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutPropertiesLoose.js
394
+ function ce(e, t) {
375
395
  if (e == null) return {};
376
396
  var n = {};
377
397
  for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
@@ -381,10 +401,10 @@ function ie(e, t) {
381
401
  return n;
382
402
  }
383
403
  //#endregion
384
- //#region \0@oxc-project+runtime@0.126.0/helpers/objectWithoutProperties.js
404
+ //#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutProperties.js
385
405
  function Z(e, t) {
386
406
  if (e == null) return {};
387
- var n, r, i = ie(e, t);
407
+ var n, r, i = ce(e, t);
388
408
  if (Object.getOwnPropertySymbols) {
389
409
  var a = Object.getOwnPropertySymbols(e);
390
410
  for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
@@ -393,51 +413,51 @@ function Z(e, t) {
393
413
  }
394
414
  //#endregion
395
415
  //#region src/BlokContent.tsx
396
- var ae = ["editor"], Q = n(function(e, t) {
397
- let { editor: n } = e, r = Z(e, ae), 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) => {
398
418
  if (i.current = e, typeof t == "function") t(e);
399
419
  else if (t != null) {
400
420
  let n = t;
401
421
  n.current = e;
402
422
  }
403
423
  };
404
- a(() => {
424
+ o(() => {
405
425
  if (n === null || i.current === null) return;
406
- let e = E(n);
426
+ let e = O(n);
407
427
  if (e !== void 0) return i.current.appendChild(e), () => {
408
428
  e.remove();
409
429
  };
410
430
  }, [n]);
411
- let s = n === null ? void 0 : H(n);
412
- return /* @__PURE__ */ x("div", N(N({ ref: o }, r), {}, { children: s === void 0 ? null : /* @__PURE__ */ x(X, { registry: s }) }));
413
- }), oe = /* @__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("."), se = [
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 = [
414
434
  "deps",
415
435
  "onReady",
416
436
  "onBlocksRendered",
417
437
  "onBlockRendered"
418
- ], ce = new Set(oe), le = n(function(e, t) {
419
- let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: s } = e, l = Z(e, se), u = {}, d = {};
420
- for (let e of Object.keys(l)) {
421
- let t = l[e];
422
- ce.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;
423
443
  }
424
444
  let f = J(u, n);
425
- o(t, () => f, [f]);
426
- let p = c(r);
445
+ s(t, () => f, [f]);
446
+ let p = l(r);
427
447
  p.current = r;
428
- let m = c(null);
429
- a(() => {
448
+ let m = l(null);
449
+ o(() => {
430
450
  if (f !== null && m.current !== f) {
431
451
  var e;
432
452
  m.current = f, (e = p.current) == null || e.call(p, f);
433
453
  }
434
454
  }, [f]);
435
- let h = c(i);
455
+ let h = l(i);
436
456
  h.current = i;
437
- let g = c(s);
438
- g.current = s;
439
- let _ = !!i, v = !!s;
440
- return a(() => {
457
+ let g = l(a);
458
+ g.current = a;
459
+ let _ = !!i, v = !!a;
460
+ return o(() => {
441
461
  if (f === null) return;
442
462
  let e = [];
443
463
  if (_) {
@@ -461,28 +481,65 @@ var ae = ["editor"], Q = n(function(e, t) {
461
481
  f,
462
482
  _,
463
483
  v
464
- ]), /* @__PURE__ */ x(Q, N({ editor: f }, d));
484
+ ]), /* @__PURE__ */ C(Q, F({ editor: f }, d));
465
485
  }), $ = "block changed";
466
- function ue(e) {
467
- let t = c(0), n = c(e);
486
+ function me(e) {
487
+ let t = l(0), n = l(e);
468
488
  n.current !== e && (n.current = e, t.current = 0);
469
- let i = r((n) => {
489
+ let r = i((n) => {
470
490
  if (e === null) return () => void 0;
471
491
  let r = () => {
472
492
  t.current += 1, n();
473
493
  };
474
494
  return e.on($, r), () => e.off($, r);
475
- }, [e]), a = r(() => t.current, []);
476
- 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]);
477
497
  }
478
498
  //#endregion
479
499
  //#region src/createReactBlock.tsx
480
- var de = [L, R];
481
- function fe(e) {
500
+ var he = ["commit", "readOnly"], ge = [z, B];
501
+ function _e(e) {
482
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
+ };
483
540
  return t = class {
484
541
  static get toolbox() {
485
- return e.toolbox;
542
+ return s();
486
543
  }
487
544
  static get isReadOnlySupported() {
488
545
  return !0;
@@ -491,41 +548,41 @@ function fe(e) {
491
548
  var n, r;
492
549
  this.hostEl = null, this.pendingDispatch = !1, this.commit = (t) => {
493
550
  var n;
494
- let r = _(e.propSchema, N(N({}, this.mirror), t));
495
- 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());
496
553
  }, this.blockApi = t.block;
497
554
  let i = (n = t.config) == null ? {} : n;
498
- this.registry = i[L];
499
- let o = i[R];
500
- 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;
501
558
  let s = {};
502
- for (let [e, t] of Object.entries(i)) de.includes(e) || (s[e] = t);
559
+ for (let [e, t] of Object.entries(i)) ge.includes(e) || (s[e] = t);
503
560
  this.toolConfig = Object.freeze(s);
504
- let l = t.api;
561
+ let c = t.api;
505
562
  this.pointerDrag = () => {
506
563
  var e;
507
- return (l == null || (e = l.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
508
- }, 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;
509
566
  let u = this.blockApi;
510
567
  this.childrenComponent = function() {
511
- let e = c(null);
512
- return a(() => {
513
- e.current !== null && v(e.current, u.getChildren());
514
- }), /* @__PURE__ */ x("div", {
568
+ let e = l(null);
569
+ return o(() => {
570
+ e.current !== null && b(e.current, u.getChildren());
571
+ }), /* @__PURE__ */ C("div", {
515
572
  ref: e,
516
- [f.nestedBlocks]: ""
573
+ [p.nestedBlocks]: ""
517
574
  });
518
575
  };
519
576
  }
520
577
  render() {
521
- var t;
522
- let n = document.createElement("div");
523
- return n.setAttribute("data-blok-mutation-free", "true"), this.hostEl = n, (t = this.registry) == null || t.register(this.blockApi.id, {
524
- hostEl: n,
525
- 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,
526
583
  props: this.buildProps(),
527
584
  toolName: this.toolName
528
- }), n;
585
+ }), t;
529
586
  }
530
587
  rendered() {
531
588
  var t;
@@ -536,8 +593,8 @@ function fe(e) {
536
593
  }
537
594
  async setData(t) {
538
595
  var n = this;
539
- let r = _(e.propSchema, t == null ? {} : t);
540
- 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);
541
598
  }
542
599
  setReadOnly(e) {
543
600
  this.readOnly = e, this.pushProps({ readOnly: e });
@@ -566,7 +623,7 @@ function fe(e) {
566
623
  }
567
624
  pushProps(e) {
568
625
  let t = this.registry;
569
- t !== void 0 && C(() => {
626
+ t !== void 0 && T(() => {
570
627
  t.setProps(this.blockApi.id, e);
571
628
  });
572
629
  }
@@ -589,4 +646,73 @@ function fe(e) {
589
646
  }, t.__isBlokReactBlock = !0, t;
590
647
  }
591
648
  //#endregion
592
- 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 };
649
+ //#region src/createReactInlineTool.tsx
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) {
652
+ var t;
653
+ return t = class {
654
+ static get title() {
655
+ return e.title;
656
+ }
657
+ static get titleKey() {
658
+ return e.titleKey;
659
+ }
660
+ static get shortcut() {
661
+ return e.shortcut;
662
+ }
663
+ static get sanitize() {
664
+ return e.sanitize;
665
+ }
666
+ static get isReadOnlySupported() {
667
+ var t;
668
+ return (t = e.isReadOnlySupported) != null && t;
669
+ }
670
+ constructor(t) {
671
+ var n;
672
+ this.active = !1, this.registered = !1;
673
+ let r = (n = t == null ? void 0 : t.config) == null ? {} : n;
674
+ this.registry = r[z];
675
+ let i = r[B];
676
+ this.toolName = typeof i == "string" ? i : e.type, this.portalKey = ye(this.toolName);
677
+ let a = {};
678
+ for (let [e, t] of Object.entries(r)) ve.includes(e) || (a[e] = t);
679
+ this.toolConfig = Object.freeze(a);
680
+ }
681
+ render() {
682
+ let t = document.createElement("div");
683
+ return t.setAttribute("data-blok-mutation-free", "true"), this.registry !== void 0 && (this.registry.register(this.portalKey, {
684
+ hostEl: t,
685
+ component: e.component,
686
+ props: {
687
+ active: this.active,
688
+ config: this.toolConfig
689
+ },
690
+ toolName: this.toolName
691
+ }), this.registered = !0), {
692
+ name: this.toolName,
693
+ title: e.title,
694
+ icon: t,
695
+ onActivate: () => {
696
+ if (typeof e.surround != "function") return;
697
+ let t = window.getSelection();
698
+ !t || t.rangeCount === 0 || e.surround(t.getRangeAt(0));
699
+ },
700
+ isActive: () => this.refreshActiveState()
701
+ };
702
+ }
703
+ destroy() {
704
+ var e;
705
+ this.registered && (this.registered = !1, (e = this.registry) == null || e.unregister(this.portalKey));
706
+ }
707
+ refreshActiveState() {
708
+ let t = typeof e.checkState == "function" && !!e.checkState(window.getSelection());
709
+ if (t !== this.active && (this.active = t, this.registered)) {
710
+ var n;
711
+ (n = this.registry) == null || n.setProps(this.portalKey, { active: t });
712
+ }
713
+ return t;
714
+ }
715
+ }, t.__isBlokReactInlineTool = !0, t.isInline = !0, t;
716
+ }
717
+ //#endregion
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 };