@bloklabs/react 1.3.0 → 1.4.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,52 +1,53 @@
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";
1
+ import { Component as e, Fragment as t, createContext as n, createElement as r, forwardRef as i, isValidElement as a, useCallback as o, useContext as s, useEffect as c, useImperativeHandle as l, useMemo as u, useRef as d, useState as f, useSyncExternalStore as p } from "react";
2
+ import { Blok as m } from "@bloklabs/core";
3
+ import { DATA_ATTR as h, EMPTY_API as g, createBlocksApiForEditor as _, createEmittedEchoWindow as v, deepEqual as y, deepEqual as b, fillDefaults as x, markSanitizerConfig as S, mountChildBlocks as C, normalizeReadOnlyConfig as ee } from "@bloklabs/core/adapters";
4
+ import { Fragment as w, jsx as T } from "react/jsx-runtime";
5
+ import { createPortal as E, flushSync as D } from "react-dom";
6
+ import { blocksToViewNodes as O } from "@bloklabs/core/view";
7
+ import { createRoot as k } from "react-dom/client";
7
8
  //#region src/holder-map.ts
8
- var D = /* @__PURE__ */ new WeakMap();
9
- function ee(e, t) {
10
- D.set(e, t);
9
+ var A = /* @__PURE__ */ new WeakMap();
10
+ function te(e, t) {
11
+ A.set(e, t);
11
12
  }
12
- function O(e) {
13
- return D.get(e);
13
+ function j(e) {
14
+ return A.get(e);
14
15
  }
15
- function k(e) {
16
- D.delete(e);
16
+ function M(e) {
17
+ A.delete(e);
17
18
  }
18
19
  //#endregion
19
20
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
20
- function A(e) {
21
+ function N(e) {
21
22
  "@babel/helpers - typeof";
22
- return A = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
23
+ return N = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
23
24
  return typeof e;
24
25
  } : function(e) {
25
26
  return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
26
- }, A(e);
27
+ }, N(e);
27
28
  }
28
29
  //#endregion
29
30
  //#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
+ function P(e, t) {
32
+ if (N(e) != "object" || !e) return e;
32
33
  var n = e[Symbol.toPrimitive];
33
34
  if (n !== void 0) {
34
35
  var r = n.call(e, t || "default");
35
- if (A(r) != "object") return r;
36
+ if (N(r) != "object") return r;
36
37
  throw TypeError("@@toPrimitive must return a primitive value.");
37
38
  }
38
39
  return (t === "string" ? String : Number)(e);
39
40
  }
40
41
  //#endregion
41
42
  //#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 + "";
43
+ function F(e) {
44
+ var t = P(e, "string");
45
+ return N(t) == "symbol" ? t : t + "";
45
46
  }
46
47
  //#endregion
47
48
  //#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
+ function I(e, t, n) {
50
+ return (t = F(t)) in e ? Object.defineProperty(e, t, {
50
51
  value: n,
51
52
  enumerable: !0,
52
53
  configurable: !0,
@@ -55,7 +56,7 @@ function N(e, t, n) {
55
56
  }
56
57
  //#endregion
57
58
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectSpread2.js
58
- function P(e, t) {
59
+ function L(e, t) {
59
60
  var n = Object.keys(e);
60
61
  if (Object.getOwnPropertySymbols) {
61
62
  var r = Object.getOwnPropertySymbols(e);
@@ -65,12 +66,12 @@ function P(e, t) {
65
66
  }
66
67
  return n;
67
68
  }
68
- function F(e) {
69
+ function R(e) {
69
70
  for (var t = 1; t < arguments.length; t++) {
70
71
  var n = arguments[t] == null ? {} : arguments[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) {
72
+ t % 2 ? L(Object(n), !0).forEach(function(t) {
73
+ I(e, t, n[t]);
74
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) : L(Object(n)).forEach(function(t) {
74
75
  Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
75
76
  });
76
77
  }
@@ -78,35 +79,35 @@ function F(e) {
78
79
  }
79
80
  //#endregion
80
81
  //#region src/provide-blok.tsx
81
- var I = t({});
82
- function L({ defaults: e, children: t }) {
83
- return /* @__PURE__ */ C(I.Provider, {
82
+ var z = n({});
83
+ function B({ defaults: e, children: t }) {
84
+ return /* @__PURE__ */ T(z.Provider, {
84
85
  value: e,
85
86
  children: t
86
87
  });
87
88
  }
88
- function R() {
89
- return a(I);
89
+ function V() {
90
+ return s(z);
90
91
  }
91
- function te(e, t) {
92
+ function ne(e, t) {
92
93
  if (Object.keys(e).length === 0) return t;
93
- let n = F({}, e);
94
+ let n = R({}, e);
94
95
  for (let e of Object.keys(t)) {
95
96
  let r = t[e];
96
97
  r !== void 0 && (n[e] = r);
97
98
  }
98
- return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = F(F({}, e.tools), t.tools)), n;
99
+ return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = R(R({}, e.tools), t.tools)), n;
99
100
  }
100
101
  //#endregion
101
102
  //#region src/block-portal-registry.ts
102
- var z = "__blokPortalRegistry", B = "__blokToolName", V = () => {
103
+ var H = "__blokPortalRegistry", U = "__blokToolName", W = () => {
103
104
  let e = { snapshot: /* @__PURE__ */ new Map() }, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = (n) => {
104
105
  e.snapshot = n, t.forEach((e) => e());
105
106
  };
106
107
  return {
107
108
  register(t, i) {
108
109
  let a = new Map(e.snapshot), o = i.toolName === void 0 ? void 0 : n.get(i.toolName);
109
- a.set(t, o === void 0 ? i : F(F({}, i), {}, { props: F(F({}, i.props), {}, { config: o }) })), r(a);
110
+ a.set(t, o === void 0 ? i : R(R({}, i), {}, { props: R(R({}, i.props), {}, { config: o }) })), r(a);
110
111
  },
111
112
  unregister(t) {
112
113
  if (!e.snapshot.has(t)) return;
@@ -117,14 +118,14 @@ var z = "__blokPortalRegistry", B = "__blokToolName", V = () => {
117
118
  let i = e.snapshot.get(t);
118
119
  if (i === void 0) return;
119
120
  let a = new Map(e.snapshot);
120
- a.set(t, F(F({}, i), {}, { props: F(F({}, i.props), n) })), r(a);
121
+ a.set(t, R(R({}, i), {}, { props: R(R({}, i.props), n) })), r(a);
121
122
  },
122
123
  setToolConfig(t, i) {
123
124
  n.set(t, i);
124
125
  let a = [...e.snapshot].filter(([, e]) => e.toolName === t);
125
126
  if (a.length === 0) return;
126
127
  let o = new Map(e.snapshot);
127
- for (let [e, t] of a) o.set(e, F(F({}, t), {}, { props: F(F({}, t.props), {}, { config: i }) }));
128
+ for (let [e, t] of a) o.set(e, R(R({}, t), {}, { props: R(R({}, t.props), {}, { config: i }) }));
128
129
  r(o);
129
130
  },
130
131
  subscribe(e) {
@@ -136,45 +137,45 @@ var z = "__blokPortalRegistry", B = "__blokToolName", V = () => {
136
137
  return e.snapshot;
137
138
  }
138
139
  };
139
- }, H = /* @__PURE__ */ new WeakMap();
140
- function U(e, t) {
141
- H.set(e, t);
140
+ }, G = /* @__PURE__ */ new WeakMap();
141
+ function re(e, t) {
142
+ G.set(e, t);
142
143
  }
143
- function W(e) {
144
- return H.get(e);
144
+ function ie(e) {
145
+ return G.get(e);
145
146
  }
146
- function G(e) {
147
- H.delete(e);
147
+ function K(e) {
148
+ G.delete(e);
148
149
  }
149
150
  //#endregion
150
151
  //#region src/live-tool-config.ts
151
- var K = (e) => {
152
+ var q = (e) => {
152
153
  if (typeof e != "object" || !e) return !1;
153
154
  let t = Object.getPrototypeOf(e);
154
155
  return t === Object.prototype || t === null;
155
- }, ne = (e, t) => t.reduce((e, t) => {
156
+ }, ae = (e, t) => t.reduce((e, t) => {
156
157
  if (Array.isArray(e)) return typeof t == "number" ? e[t] : void 0;
157
- if (K(e)) return e[t];
158
- }, e), re = (e, t) => {
158
+ if (q(e)) return e[t];
159
+ }, e), oe = (e, t) => {
159
160
  let n = (e, t) => {
160
161
  if (typeof e == "function") return typeof t == "function" ? t : e;
161
162
  if (Array.isArray(e)) {
162
163
  let r = Array.isArray(t) ? t : [];
163
164
  return e.map((e, t) => n(e, r[t]));
164
165
  }
165
- if (K(e)) {
166
- let r = K(t) ? t : {}, i = {};
166
+ if (q(e)) {
167
+ let r = q(t) ? t : {}, i = {};
167
168
  for (let [t, a] of Object.entries(e)) i[t] = n(a, r[t]);
168
169
  return i;
169
170
  }
170
171
  return e;
171
172
  }, r = n(t, e);
172
- return K(r) ? r : {};
173
- }, ie = (e, t) => {
174
- if (!K(e)) return e;
173
+ return q(r) ? r : {};
174
+ }, se = (e, t) => {
175
+ if (!q(e)) return e;
175
176
  let n = {};
176
177
  for (let [r, i] of Object.entries(e)) {
177
- if (!K(i) || !K(i.config)) {
178
+ if (!q(i) || !q(i.config)) {
178
179
  n[r] = i;
179
180
  continue;
180
181
  }
@@ -182,12 +183,12 @@ var K = (e) => {
182
183
  if (typeof n == "function") {
183
184
  let e = n;
184
185
  return function(...n) {
185
- let a = t(), o = K(a) ? a[r] : void 0, s = ne(K(o) ? o.config : void 0, i);
186
+ let a = t(), o = q(a) ? a[r] : void 0, s = ae(q(o) ? o.config : void 0, i);
186
187
  return Reflect.apply(typeof s == "function" ? s : e, this, n);
187
188
  };
188
189
  }
189
190
  if (Array.isArray(n)) return e.has(n) ? n : (e.add(n), n.map((e, t) => a(e, [...i, t])));
190
- if (K(n)) {
191
+ if (q(n)) {
191
192
  if (e.has(n)) return n;
192
193
  e.add(n);
193
194
  let t = {};
@@ -196,171 +197,191 @@ var K = (e) => {
196
197
  }
197
198
  return n;
198
199
  };
199
- n[r] = F(F({}, i), {}, { config: a(i.config, []) });
200
+ n[r] = R(R({}, i), {}, { config: a(i.config, []) });
200
201
  }
201
202
  return n;
202
- }, q = (e) => {
203
+ }, J = (e) => {
203
204
  let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
204
205
  return typeof t == "function" && t.__isBlokReactBlock === !0;
205
- }, ae = (e) => {
206
+ }, ce = (e) => {
206
207
  let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
207
208
  return typeof t == "function" && t.__isBlokReactInlineTool === !0;
208
- }, oe = (e, t) => {
209
+ }, le = (e, t) => {
209
210
  if (typeof e != "object" || !e) return e;
210
211
  let n = {};
211
212
  for (let [i, a] of Object.entries(e)) {
212
213
  var r;
213
- if (!q(a) && !ae(a)) {
214
+ if (!J(a) && !ce(a)) {
214
215
  n[i] = a;
215
216
  continue;
216
217
  }
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
218
+ let e = typeof a == "function" ? { class: a } : R({}, a);
219
+ e.config = R(R({}, (r = e.config) == null ? {} : r), {}, {
220
+ [H]: t,
221
+ [U]: i
221
222
  }), n[i] = e;
222
223
  }
223
224
  return n;
224
225
  };
225
- function J(e, t) {
226
+ function Y(e, t) {
226
227
  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
+ let i = ne(s(z), e), [a, o] = f(null), l = d(i);
229
+ l.current = i;
230
+ let p = d({
230
231
  editor: null,
231
232
  holder: null,
232
233
  destroyTimeout: null,
233
234
  isDestroyed: !1,
234
235
  isEditorReady: !1,
235
236
  depsToken: null
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(() => {
237
+ }), h = u(() => ({}), t == null ? [] : t), g = d(i.data), _ = d(v()), y = d(null), x = d(i.data), S = d(Promise.resolve()), C = d(void 0), w = d(null), T = d(void 0), E = d(/* @__PURE__ */ new Map()), D = d(/* @__PURE__ */ new Map());
238
+ c(() => {
238
239
  var e;
239
240
  if (typeof window > "u") return;
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);
241
+ let t = p.current;
242
+ if (t.destroyTimeout !== null && (clearTimeout(t.destroyTimeout), t.destroyTimeout = null), t.editor !== null && !t.isDestroyed && t.depsToken === h) return t.isEditorReady && o(t.editor), () => {
243
+ X(t, o);
243
244
  };
244
245
  if (t.editor !== null && !t.isDestroyed) {
245
- k(t.editor), G(t.editor);
246
+ M(t.editor), K(t.editor);
246
247
  try {
247
248
  t.editor.destroy();
248
249
  } catch (e) {}
249
- t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, d(null);
250
+ t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, o(null);
250
251
  }
251
252
  let n = document.createElement("div");
252
253
  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 }), {}, {
254
+ let r = l.current, i = W(), a = r.tools === void 0 ? void 0 : se(r.tools, () => l.current.tools), s = a === void 0 ? void 0 : le(a, i);
255
+ w.current = i, T.current = a, E.current = /* @__PURE__ */ new Map(), D.current = new Map(Object.entries((e = r.tools) == null ? {} : e).map(([e, t]) => [e, typeof t == "object" && t ? t.toolbox : void 0]));
256
+ let c = R(R(R({}, r), s === void 0 ? {} : { tools: s }), {}, {
256
257
  holder: n,
257
258
  onReady: (...e) => {
258
259
  var t, n;
259
- (t = (n = p.current).onReady) == null || t.call(n, ...e);
260
+ (t = (n = l.current).onReady) == null || t.call(n, ...e);
260
261
  },
261
262
  onChange: (...e) => {
262
263
  var t, n;
263
- (t = (n = p.current).onChange) == null || t.call(n, ...e);
264
+ (t = (n = l.current).onChange) == null || t.call(n, ...e);
264
265
  },
265
266
  onEnter: (...e) => {
266
267
  var t, n;
267
- return (t = (n = p.current).onEnter) == null ? void 0 : t.call(n, ...e);
268
+ return (t = (n = l.current).onEnter) == null ? void 0 : t.call(n, ...e);
268
269
  }
269
270
  });
270
- r.onSave && (s.onSave = (...e) => {
271
+ r.onSave && (c.onSave = (...e) => {
271
272
  var t, n;
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) => {
273
+ g.current = e[0], _.current.record(e[0]), (t = (n = l.current).onSave) == null || t.call(n, ...e);
274
+ }), r.onBeforeRender && (c.onBeforeRender = (...e) => {
274
275
  var t, n, r;
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) => {
276
+ return (t = (n = (r = l.current).onBeforeRender) == null ? void 0 : n.call(r, ...e)) == null ? e[0] : t;
277
+ }), r.onAfterRender && (c.onAfterRender = (...e) => {
277
278
  var t, n;
278
- (t = (n = p.current).onAfterRender) == null || t.call(n, ...e);
279
+ (t = (n = l.current).onAfterRender) == null || t.call(n, ...e);
279
280
  });
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));
281
+ let u = new m(c);
282
+ return t.editor = u, x.current = r.data, te(u, n), re(u, i), u.isReady.then(() => {
283
+ t.editor === u && !t.isDestroyed && (t.isEditorReady = !0, o(u));
283
284
  }).catch(() => {
284
- if (t.editor === c && !t.isDestroyed) {
285
- k(c), G(c);
285
+ if (t.editor === u && !t.isDestroyed) {
286
+ M(u), K(u);
286
287
  try {
287
- c.destroy();
288
+ u.destroy();
288
289
  } catch (e) {}
289
- t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, d(null);
290
+ t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, o(null);
290
291
  }
291
292
  }), () => {
292
- Y(t, d);
293
+ X(t, o);
293
294
  };
294
- }, [h]), o(() => {
295
- let e = T.current, t = m.current;
295
+ }, [h]), c(() => {
296
+ let e = w.current, t = p.current;
296
297
  if (e === null || t.editor === null || t.isDestroyed) return;
297
- let n = p.current.tools;
298
+ let n = l.current.tools;
298
299
  if (typeof n != "object" || !n) return;
299
- let r = E.current;
300
+ let r = T.current;
300
301
  for (let [t, a] of Object.entries(n)) {
301
302
  var i;
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;
303
+ if (!J(a)) continue;
304
+ let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s = oe(typeof o == "object" && o ? o.config : void 0, n), c = E.current.get(t);
305
+ if (c !== void 0 && b(s, c)) continue;
305
306
  let l = Object.freeze(s);
306
- D.current.set(t, l), e.setToolConfig(t, l);
307
+ E.current.set(t, l), e.setToolConfig(t, l);
307
308
  }
308
- }), o(() => {
309
- let e = m.current;
309
+ }), c(() => {
310
+ let e = p.current;
310
311
  if (e.editor === null || e.isDestroyed || !e.isEditorReady) return;
311
- let t = p.current.tools;
312
+ let t = l.current.tools;
312
313
  if (!(typeof t != "object" || !t)) for (let [r, i] of Object.entries(t)) {
313
314
  var n;
314
- if (!O.current.has(r)) continue;
315
+ if (!D.current.has(r)) continue;
315
316
  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 }));
317
+ b(t, D.current.get(r)) || (D.current.set(r, t), (n = e.editor.tools) == null || n.update(r, { toolbox: t }));
317
318
  }
318
319
  });
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;
320
+ let O = typeof i.readOnly == "object" && i.readOnly !== null, { enabled: k, hideControls: A } = ee(i.readOnly);
321
+ c(() => {
322
+ a !== null && (O ? a.readOnly.set(k, { hideControls: A }) : a.readOnly.set(k));
323
+ }, [
324
+ a,
325
+ k,
326
+ A,
327
+ O
328
+ ]);
329
+ let { hideToolbar: j } = i;
330
+ c(() => {
331
+ a === null || j === void 0 || a.toolbar.setHidden(j);
332
+ }, [a, j]);
333
+ let { inlineToolbar: N } = i;
334
+ c(() => {
335
+ a === null || N === void 0 || a.tools.setInlineToolbar(N);
336
+ }, [a, N === void 0 ? void 0 : JSON.stringify(N)]);
337
+ let { autofocus: P } = i;
338
+ c(() => {
339
+ a === null || !P || a.focus();
340
+ }, [a, P]);
341
+ let { theme: F } = i;
342
+ c(() => {
343
+ a === null || F === void 0 || a.theme.set(F);
344
+ }, [a, F]);
345
+ let { width: I } = i;
346
+ c(() => {
347
+ a === null || I === void 0 || a.width.set(I);
348
+ }, [a, I]);
349
+ let L = (n = i.style) == null ? void 0 : n.tokens, B = d((r = i.style) == null ? void 0 : r.tokens);
350
+ c(() => {
351
+ a === null || L === void 0 || b(L, B.current) || (B.current = L, a.tokens.set(L));
352
+ }, [a, L]);
353
+ let { i18n: V } = i, H = d(i.i18n);
354
+ c(() => {
355
+ if (a === null || V === void 0 || b(V, H.current)) return;
356
+ H.current = V;
357
+ let { locale: e, messages: t, direction: n } = V;
358
+ a.i18n.update(R(R(R({}, e === void 0 ? {} : { locale: e }), t === void 0 ? {} : { messages: t }), n === void 0 ? {} : { direction: n }));
359
+ }, [a, V]);
360
+ let { placeholder: U } = i;
361
+ c(() => {
362
+ a === null || U === void 0 || a.placeholder.set(U);
363
+ }, [a, U]);
364
+ let { data: G } = i;
365
+ return c(() => {
366
+ if (a === null || G === void 0) return;
367
+ let e = p.current;
368
+ if (!(e.editor !== a || e.isDestroyed)) {
369
+ if (y.current !== a && (y.current = a, C.current = void 0, _.current.clear(), b(G, x.current))) {
370
+ g.current = G;
350
371
  return;
351
372
  }
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;
373
+ b(G, g.current) || b(G, C.current) || _.current.matches(G) || (_.current.clear(), C.current = G, S.current = S.current.catch(() => void 0).then(() => a.render(G)).then(() => {
374
+ g.current = G;
354
375
  }, () => {}).then(() => {
355
- w.current === z && (w.current = void 0);
376
+ C.current === G && (C.current = void 0);
356
377
  }));
357
378
  }
358
- }, [s, z]), s;
379
+ }, [a, G]), a;
359
380
  }
360
- function Y(e, t) {
381
+ function X(e, t) {
361
382
  e.destroyTimeout = setTimeout(() => {
362
383
  if (e.editor !== null) {
363
- k(e.editor), G(e.editor);
384
+ M(e.editor), K(e.editor);
364
385
  try {
365
386
  e.editor.destroy();
366
387
  } catch (e) {}
@@ -370,7 +391,7 @@ function Y(e, t) {
370
391
  }
371
392
  //#endregion
372
393
  //#region src/BlockPortalHost.tsx
373
- var se = class extends e {
394
+ var ue = class extends e {
374
395
  constructor(...e) {
375
396
  super(...e), this.state = { failed: !1 };
376
397
  }
@@ -382,16 +403,16 @@ var se = class extends e {
382
403
  return this.state.failed ? null : this.props.children;
383
404
  }
384
405
  };
385
- function X({ registry: e }) {
386
- let t = d(e.subscribe, e.getSnapshot, e.getSnapshot);
387
- return /* @__PURE__ */ C(S, { children: Array.from(t.entries()).map(([e, t]) => {
406
+ function Z({ registry: e }) {
407
+ let t = p(e.subscribe, e.getSnapshot, e.getSnapshot);
408
+ return /* @__PURE__ */ T(w, { children: Array.from(t.entries()).map(([e, t]) => {
388
409
  let n = t.component;
389
- return w(/* @__PURE__ */ C(se, { children: /* @__PURE__ */ C(n, F({}, t.props)) }), t.hostEl, e);
410
+ return E(/* @__PURE__ */ T(ue, { children: /* @__PURE__ */ T(n, R({}, t.props)) }), t.hostEl, e);
390
411
  }) });
391
412
  }
392
413
  //#endregion
393
414
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutPropertiesLoose.js
394
- function ce(e, t) {
415
+ function de(e, t) {
395
416
  if (e == null) return {};
396
417
  var n = {};
397
418
  for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
@@ -402,9 +423,9 @@ function ce(e, t) {
402
423
  }
403
424
  //#endregion
404
425
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutProperties.js
405
- function Z(e, t) {
426
+ function Q(e, t) {
406
427
  if (e == null) return {};
407
- var n, r, i = ce(e, t);
428
+ var n, r, i = de(e, t);
408
429
  if (Object.getOwnPropertySymbols) {
409
430
  var a = Object.getOwnPropertySymbols(e);
410
431
  for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
@@ -413,51 +434,51 @@ function Z(e, t) {
413
434
  }
414
435
  //#endregion
415
436
  //#region src/BlokContent.tsx
416
- var le = ["editor"], Q = n(function(e, t) {
417
- let { editor: n } = e, r = Z(e, le), i = l(null), a = (e) => {
437
+ var fe = ["editor"], pe = i(function(e, t) {
438
+ let { editor: n } = e, r = Q(e, fe), i = d(null), a = (e) => {
418
439
  if (i.current = e, typeof t == "function") t(e);
419
440
  else if (t != null) {
420
441
  let n = t;
421
442
  n.current = e;
422
443
  }
423
444
  };
424
- o(() => {
445
+ c(() => {
425
446
  if (n === null || i.current === null) return;
426
- let e = O(n);
447
+ let e = j(n);
427
448
  if (e !== void 0) return i.current.appendChild(e), () => {
428
449
  e.remove();
429
450
  };
430
451
  }, [n]);
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 = [
452
+ let o = n === null ? void 0 : ie(n);
453
+ return /* @__PURE__ */ T("div", R(R({ ref: a }, r), {}, { children: o === void 0 ? null : /* @__PURE__ */ T(Z, { registry: o }) }));
454
+ }), me = /* @__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("."), he = [
434
455
  "deps",
435
456
  "onReady",
436
457
  "onBlocksRendered",
437
458
  "onBlockRendered"
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;
459
+ ], ge = new Set(me), _e = i(function(e, t) {
460
+ let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered: a } = e, o = Q(e, he), s = {}, u = {};
461
+ for (let e of Object.keys(o)) {
462
+ let t = o[e];
463
+ ge.has(e) ? s[e] = t : u[e] = t;
443
464
  }
444
- let f = J(u, n);
445
- s(t, () => f, [f]);
446
- let p = l(r);
465
+ let f = Y(s, n);
466
+ l(t, () => f, [f]);
467
+ let p = d(r);
447
468
  p.current = r;
448
- let m = l(null);
449
- o(() => {
469
+ let m = d(null);
470
+ c(() => {
450
471
  if (f !== null && m.current !== f) {
451
472
  var e;
452
473
  m.current = f, (e = p.current) == null || e.call(p, f);
453
474
  }
454
475
  }, [f]);
455
- let h = l(i);
476
+ let h = d(i);
456
477
  h.current = i;
457
- let g = l(a);
478
+ let g = d(a);
458
479
  g.current = a;
459
480
  let _ = !!i, v = !!a;
460
- return o(() => {
481
+ return c(() => {
461
482
  if (f === null) return;
462
483
  let e = [];
463
484
  if (_) {
@@ -481,65 +502,192 @@ var le = ["editor"], Q = n(function(e, t) {
481
502
  f,
482
503
  _,
483
504
  v
484
- ]), /* @__PURE__ */ C(Q, F({ editor: f }, d));
485
- }), $ = "block changed";
486
- function me(e) {
487
- let t = l(0), n = l(e);
505
+ ]), /* @__PURE__ */ T(pe, R({ editor: f }, u));
506
+ }), ve = "block changed";
507
+ function ye(e) {
508
+ let t = d(0), n = d(e);
488
509
  n.current !== e && (n.current = e, t.current = 0);
489
- let r = i((n) => {
510
+ let r = o((n) => {
490
511
  if (e === null) return () => void 0;
491
512
  let r = () => {
492
513
  t.current += 1, n();
493
514
  };
494
- return e.on($, r), () => e.off($, r);
495
- }, [e]), a = i(() => t.current, []);
496
- return d(r, a, a), c(() => e === null ? m : h(e), [e]);
515
+ return e.on(ve, r), () => e.off(ve, r);
516
+ }, [e]), i = o(() => t.current, []);
517
+ return p(r, i, i), u(() => e === null ? g : _(e), [e]);
518
+ }
519
+ //#endregion
520
+ //#region src/useBlokReady.ts
521
+ function be(e = {}) {
522
+ let { within: t, settleOn: n } = e, [r, i] = f(!1);
523
+ return c(() => {
524
+ let e = () => {
525
+ var e;
526
+ let r = t instanceof Element ? t : (e = t == null ? void 0 : t.current) == null ? null : e;
527
+ i(t !== void 0 && r === null ? !1 : m.readyState({
528
+ within: r,
529
+ settleOn: n
530
+ }).ready);
531
+ };
532
+ return e(), m.subscribeReady(e);
533
+ }, [t, n]), r;
497
534
  }
498
535
  //#endregion
499
- //#region src/createReactBlock.tsx
500
- var he = ["commit", "readOnly"], ge = [z, B];
501
- function _e(e) {
536
+ //#region src/view-nodes-to-react.ts
537
+ var xe = /* @__PURE__ */ new Set([
538
+ "area",
539
+ "base",
540
+ "br",
541
+ "col",
542
+ "embed",
543
+ "hr",
544
+ "img",
545
+ "input",
546
+ "link",
547
+ "meta",
548
+ "param",
549
+ "source",
550
+ "track",
551
+ "wbr"
552
+ ]), Se = /* @__PURE__ */ new Set([
553
+ "disabled",
554
+ "open",
555
+ "controls",
556
+ "autoplay",
557
+ "loop",
558
+ "muted",
559
+ "required",
560
+ "multiple",
561
+ "playsinline",
562
+ "reversed",
563
+ "hidden",
564
+ "default",
565
+ "novalidate",
566
+ "allowfullscreen",
567
+ "itemscope"
568
+ ]), Ce = {
569
+ class: "className",
570
+ for: "htmlFor",
571
+ colspan: "colSpan",
572
+ rowspan: "rowSpan",
573
+ tabindex: "tabIndex",
574
+ readonly: "readOnly",
575
+ srcset: "srcSet",
576
+ srclang: "srcLang",
577
+ datetime: "dateTime",
578
+ autoplay: "autoPlay",
579
+ playsinline: "playsInline",
580
+ novalidate: "noValidate",
581
+ allowfullscreen: "allowFullScreen",
582
+ crossorigin: "crossOrigin",
583
+ referrerpolicy: "referrerPolicy",
584
+ contenteditable: "contentEditable",
585
+ spellcheck: "spellCheck",
586
+ maxlength: "maxLength",
587
+ minlength: "minLength",
588
+ usemap: "useMap",
589
+ itemscope: "itemScope"
590
+ }, we = (e) => {
591
+ let t = {};
592
+ for (let n of e.split(";")) {
593
+ let e = n.indexOf(":");
594
+ if (e === -1) continue;
595
+ let r = n.slice(0, e).trim(), i = n.slice(e + 1).trim();
596
+ if (r === "" || i === "") continue;
597
+ let a = r.startsWith("--") ? r : r.toLowerCase().replace(/-([a-z])/g, (e, t) => t.toUpperCase());
598
+ t[a] = i;
599
+ }
600
+ return t;
601
+ }, Te = (e, t) => {
602
+ let n = { key: t };
603
+ for (let [t, a] of Object.entries(e)) {
604
+ var r;
605
+ if (t === "style") {
606
+ n.style = we(a);
607
+ continue;
608
+ }
609
+ if (t === "checked") {
610
+ n.defaultChecked = !0;
611
+ continue;
612
+ }
613
+ if (t === "value") {
614
+ n.defaultValue = a;
615
+ continue;
616
+ }
617
+ if (Se.has(t)) {
618
+ var i;
619
+ n[(i = Ce[t]) == null ? t : i] = !0;
620
+ continue;
621
+ }
622
+ n[(r = Ce[t]) == null ? t : r] = a;
623
+ }
624
+ return n;
625
+ }, Ee = (e) => e.map((e, t) => {
626
+ if ("text" in e) return e.text;
627
+ let n = Te(e.attrs, t);
628
+ return xe.has(e.tag) || e.children.length === 0 ? r(e.tag, n) : r(e.tag, n, ...Ee(e.children));
629
+ }), De = (e, n) => {
630
+ let i = n == null ? void 0 : n.schema, a = n == null ? void 0 : n.renderers, o = n == null ? void 0 : n.onUnknownBlock;
631
+ return u(() => r(t, null, ...Ee(O(e, {
632
+ schema: i,
633
+ renderers: a,
634
+ onUnknownBlock: o
635
+ }))), [
636
+ e,
637
+ i,
638
+ a,
639
+ o
640
+ ]);
641
+ }, Oe = ({ data: e, schema: t, renderers: n, onUnknownBlock: r, className: i }) => /* @__PURE__ */ T("div", {
642
+ className: i,
643
+ children: De(e, {
644
+ schema: t,
645
+ renderers: n,
646
+ onUnknownBlock: r
647
+ })
648
+ }), ke = ["commit", "readOnly"], Ae = [H, U];
649
+ function je(e) {
502
650
  var t;
503
651
  let n = (e) => {
504
652
  if (typeof document > "u") return null;
505
- let t = document.createElement("div"), n = E(t);
506
- T(() => {
653
+ let t = document.createElement("div"), n = k(t);
654
+ D(() => {
507
655
  n.render(e);
508
656
  });
509
657
  let r = t.innerHTML;
510
658
  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 });
659
+ }, r = () => {
660
+ let t = { complete: !0 }, r = (e) => {
661
+ if (!a(e.icon)) return e;
662
+ let r = n(e.icon);
663
+ return r === null ? (t.complete = !1, e) : R(R({}, e), {}, { icon: r });
516
664
  };
517
665
  return e.toolbox === void 0 ? {
518
666
  value: void 0,
519
667
  complete: t.complete
520
668
  } : {
521
- value: Array.isArray(e.toolbox) ? e.toolbox.map(i) : i(e.toolbox),
669
+ value: Array.isArray(e.toolbox) ? e.toolbox.map(r) : r(e.toolbox),
522
670
  complete: t.complete
523
671
  };
524
- }, a = {
672
+ }, i = {
525
673
  resolved: !1,
526
674
  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) => {
675
+ }, o = () => {
676
+ if (i.resolved) return i.value;
677
+ let { value: e, complete: t } = r();
678
+ return t && (i.value = e, i.resolved = !0), e;
679
+ }, s = e.viewComponent === void 0 ? e.component : (t) => {
532
680
  let n = e.viewComponent;
533
681
  if (t.readOnly && n !== void 0) {
534
682
  let { commit: e, readOnly: r } = t;
535
- return /* @__PURE__ */ C(n, F({}, Z(t, he)));
683
+ return /* @__PURE__ */ T(n, R({}, Q(t, ke)));
536
684
  }
537
685
  let r = e.component;
538
- return /* @__PURE__ */ C(r, F({}, t));
686
+ return /* @__PURE__ */ T(r, R({}, t));
539
687
  };
540
688
  return t = class {
541
689
  static get toolbox() {
542
- return s();
690
+ return o();
543
691
  }
544
692
  static get isReadOnlySupported() {
545
693
  return !0;
@@ -548,29 +696,29 @@ function _e(e) {
548
696
  var n, r;
549
697
  this.hostEl = null, this.pendingDispatch = !1, this.commit = (t) => {
550
698
  var n;
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());
699
+ let r = x(e.propSchema, R(R({}, this.mirror), t));
700
+ y(r, this.mirror) || (this.mirror = r, this.lastRendered = r, (n = this.registry) == null || n.setProps(this.blockApi.id, { data: r }), this.flushDispatch());
553
701
  }, this.blockApi = t.block;
554
702
  let i = (n = t.config) == null ? {} : n;
555
- this.registry = i[z];
556
- let a = i[B];
703
+ this.registry = i[H];
704
+ let a = i[U];
557
705
  this.toolName = typeof a == "string" ? a : void 0;
558
- let s = {};
559
- for (let [e, t] of Object.entries(i)) ge.includes(e) || (s[e] = t);
560
- this.toolConfig = Object.freeze(s);
561
- let c = t.api;
706
+ let o = {};
707
+ for (let [e, t] of Object.entries(i)) Ae.includes(e) || (o[e] = t);
708
+ this.toolConfig = Object.freeze(o);
709
+ let s = t.api;
562
710
  this.pointerDrag = () => {
563
711
  var e;
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;
566
- let u = this.blockApi;
712
+ return (s == null || (e = s.blocks) == null ? void 0 : e.isPointerDragActive) === !0;
713
+ }, this.mirror = x(e.propSchema, (r = t.data) == null ? {} : r), this.lastRendered = this.mirror, this.readOnly = t.readOnly;
714
+ let l = this.blockApi;
567
715
  this.childrenComponent = function() {
568
- let e = l(null);
569
- return o(() => {
570
- e.current !== null && b(e.current, u.getChildren());
571
- }), /* @__PURE__ */ C("div", {
716
+ let e = d(null);
717
+ return c(() => {
718
+ e.current !== null && C(e.current, l.getChildren());
719
+ }), /* @__PURE__ */ T("div", {
572
720
  ref: e,
573
- [p.nestedBlocks]: ""
721
+ [h.nestedBlocks]: ""
574
722
  });
575
723
  };
576
724
  }
@@ -579,7 +727,7 @@ function _e(e) {
579
727
  let t = document.createElement("div");
580
728
  return t.setAttribute("data-blok-mutation-free", "true"), this.hostEl = t, (e = this.registry) == null || e.register(this.blockApi.id, {
581
729
  hostEl: t,
582
- component: c,
730
+ component: s,
583
731
  props: this.buildProps(),
584
732
  toolName: this.toolName
585
733
  }), t;
@@ -593,8 +741,8 @@ function _e(e) {
593
741
  }
594
742
  async setData(t) {
595
743
  var n = this;
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);
744
+ let r = x(e.propSchema, t == null ? {} : t);
745
+ return y(r, n.lastRendered) ? !0 : (n.mirror = r, n.lastRendered = r, n.pushProps({ data: r }), !0);
598
746
  }
599
747
  setReadOnly(e) {
600
748
  this.readOnly = e, this.pushProps({ readOnly: e });
@@ -623,7 +771,7 @@ function _e(e) {
623
771
  }
624
772
  pushProps(e) {
625
773
  let t = this.registry;
626
- t !== void 0 && T(() => {
774
+ t !== void 0 && D(() => {
627
775
  t.setProps(this.blockApi.id, e);
628
776
  });
629
777
  }
@@ -647,8 +795,13 @@ function _e(e) {
647
795
  }
648
796
  //#endregion
649
797
  //#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) {
798
+ var Me = [H, U], Ne = (e) => `__blok-inline-tool__:${e}:${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`, $ = n(null);
799
+ function Pe() {
800
+ let e = s($);
801
+ if (e === null) throw Error("useInlineTool() must be called from a component rendered by createReactInlineTool");
802
+ return e;
803
+ }
804
+ function Fe(e) {
652
805
  var t;
653
806
  return t = class {
654
807
  static get title() {
@@ -661,7 +814,7 @@ function be(e) {
661
814
  return e.shortcut;
662
815
  }
663
816
  static get sanitize() {
664
- return e.sanitize;
817
+ return e.sanitize === void 0 ? e.mark === void 0 ? void 0 : S(e.mark) : e.sanitize;
665
818
  }
666
819
  static get isReadOnlySupported() {
667
820
  var t;
@@ -671,18 +824,18 @@ function be(e) {
671
824
  var n;
672
825
  this.active = !1, this.registered = !1;
673
826
  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);
827
+ this.api = t == null ? void 0 : t.api, this.registry = r[H];
828
+ let i = r[U];
829
+ this.toolName = typeof i == "string" ? i : e.type, this.portalKey = Ne(this.toolName);
677
830
  let a = {};
678
- for (let [e, t] of Object.entries(r)) ve.includes(e) || (a[e] = t);
679
- this.toolConfig = Object.freeze(a);
831
+ for (let [e, t] of Object.entries(r)) Me.includes(e) || (a[e] = t);
832
+ this.toolConfig = Object.freeze(a), this.portalComponent = this.createPortalComponent();
680
833
  }
681
834
  render() {
682
835
  let t = document.createElement("div");
683
836
  return t.setAttribute("data-blok-mutation-free", "true"), this.registry !== void 0 && (this.registry.register(this.portalKey, {
684
837
  hostEl: t,
685
- component: e.component,
838
+ component: this.portalComponent,
686
839
  props: {
687
840
  active: this.active,
688
841
  config: this.toolConfig
@@ -693,9 +846,7 @@ function be(e) {
693
846
  title: e.title,
694
847
  icon: t,
695
848
  onActivate: () => {
696
- if (typeof e.surround != "function") return;
697
- let t = window.getSelection();
698
- !t || t.rangeCount === 0 || e.surround(t.getRangeAt(0));
849
+ this.activate();
699
850
  },
700
851
  isActive: () => this.refreshActiveState()
701
852
  };
@@ -704,15 +855,53 @@ function be(e) {
704
855
  var e;
705
856
  this.registered && (this.registered = !1, (e = this.registry) == null || e.unregister(this.portalKey));
706
857
  }
858
+ activate() {
859
+ var t;
860
+ if (typeof e.surround == "function") {
861
+ let t = window.getSelection();
862
+ if (!t || t.rangeCount === 0) return;
863
+ e.surround(t.getRangeAt(0), this.api);
864
+ return;
865
+ }
866
+ e.mark !== void 0 && ((t = this.api) == null ? void 0 : t.marks) !== void 0 && this.api.marks.toggle(e.mark);
867
+ }
707
868
  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 });
869
+ let e = this.computeActiveState();
870
+ if (e !== this.active && (this.active = e, this.registered)) {
871
+ var t;
872
+ (t = this.registry) == null || t.setProps(this.portalKey, { active: e });
712
873
  }
713
- return t;
874
+ return e;
875
+ }
876
+ computeActiveState() {
877
+ var t;
878
+ return typeof e.checkState == "function" ? !!e.checkState(window.getSelection(), this.api) : e.mark !== void 0 && ((t = this.api) == null ? void 0 : t.marks) !== void 0 && this.api.marks.has(e.mark);
879
+ }
880
+ createPortalComponent() {
881
+ let t = this.api, n = e.mark, r = e.component, i = n !== void 0 && (t == null ? void 0 : t.marks) !== void 0 ? {
882
+ has: () => t.marks.has(n),
883
+ toggle: (e) => t.marks.toggle(n, e),
884
+ apply: (e) => t.marks.apply(n, e),
885
+ remove: () => t.marks.remove(n),
886
+ read: () => t.marks.read(n)
887
+ } : null, a = (e) => {
888
+ let n = u(() => ({
889
+ active: e.active,
890
+ config: e.config,
891
+ api: t,
892
+ mark: i
893
+ }), [e.active, e.config]);
894
+ return /* @__PURE__ */ T($.Provider, {
895
+ value: n,
896
+ children: /* @__PURE__ */ T(r, {
897
+ active: e.active,
898
+ config: e.config
899
+ })
900
+ });
901
+ };
902
+ return a.displayName = `BlokInlineTool(${this.toolName})`, a;
714
903
  }
715
904
  }, t.__isBlokReactInlineTool = !0, t.isInline = !0, t;
716
905
  }
717
906
  //#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 };
907
+ export { H as BLOK_PORTAL_REGISTRY_CONFIG_KEY, U as BLOK_TOOL_NAME_CONFIG_KEY, Z as BlockPortalHost, pe as BlokContent, _e as BlokEditor, B as BlokProvider, Oe as BlokView, W as createBlockPortalRegistry, je as createReactBlock, Fe as createReactInlineTool, ye as useBlocks, Y as useBlok, V as useBlokDefaults, be as useBlokReady, De as useBlokView, Pe as useInlineTool };