@bloklabs/react 1.2.6 → 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/README.md +69 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +485 -239
- package/package.json +25 -4
- package/src/BlokEditor.tsx +1 -1
- package/src/BlokView.tsx +37 -0
- package/src/createReactBlock.tsx +151 -8
- package/src/createReactInlineTool.tsx +197 -28
- package/src/index.ts +11 -1
- package/src/provide-blok.tsx +1 -1
- package/src/types.ts +5 -1
- package/src/useBlok.ts +182 -7
- package/src/useBlokReady.ts +60 -0
- package/src/useBlokView.ts +38 -0
- package/src/view-nodes-to-react.ts +138 -0
- package/types/index.d.ts +204 -14
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
import { Component as e,
|
|
2
|
-
import { Blok as
|
|
3
|
-
import { DATA_ATTR as
|
|
4
|
-
import { Fragment as
|
|
5
|
-
import { createPortal as
|
|
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";
|
|
6
8
|
//#region src/holder-map.ts
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
|
|
9
|
+
var A = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function te(e, t) {
|
|
11
|
+
A.set(e, t);
|
|
10
12
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
+
function j(e) {
|
|
14
|
+
return A.get(e);
|
|
13
15
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
+
function M(e) {
|
|
17
|
+
A.delete(e);
|
|
16
18
|
}
|
|
17
19
|
//#endregion
|
|
18
|
-
//#region \0@oxc-project+runtime@0.
|
|
19
|
-
function
|
|
20
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
|
|
21
|
+
function N(e) {
|
|
20
22
|
"@babel/helpers - typeof";
|
|
21
|
-
return
|
|
23
|
+
return N = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
22
24
|
return typeof e;
|
|
23
25
|
} : function(e) {
|
|
24
26
|
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
25
|
-
},
|
|
27
|
+
}, N(e);
|
|
26
28
|
}
|
|
27
29
|
//#endregion
|
|
28
|
-
//#region \0@oxc-project+runtime@0.
|
|
29
|
-
function
|
|
30
|
-
if (
|
|
30
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
|
|
31
|
+
function P(e, t) {
|
|
32
|
+
if (N(e) != "object" || !e) return e;
|
|
31
33
|
var n = e[Symbol.toPrimitive];
|
|
32
34
|
if (n !== void 0) {
|
|
33
35
|
var r = n.call(e, t || "default");
|
|
34
|
-
if (
|
|
36
|
+
if (N(r) != "object") return r;
|
|
35
37
|
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
36
38
|
}
|
|
37
39
|
return (t === "string" ? String : Number)(e);
|
|
38
40
|
}
|
|
39
41
|
//#endregion
|
|
40
|
-
//#region \0@oxc-project+runtime@0.
|
|
41
|
-
function
|
|
42
|
-
var t =
|
|
43
|
-
return
|
|
42
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
|
|
43
|
+
function F(e) {
|
|
44
|
+
var t = P(e, "string");
|
|
45
|
+
return N(t) == "symbol" ? t : t + "";
|
|
44
46
|
}
|
|
45
47
|
//#endregion
|
|
46
|
-
//#region \0@oxc-project+runtime@0.
|
|
47
|
-
function
|
|
48
|
-
return (t =
|
|
48
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
|
|
49
|
+
function I(e, t, n) {
|
|
50
|
+
return (t = F(t)) in e ? Object.defineProperty(e, t, {
|
|
49
51
|
value: n,
|
|
50
52
|
enumerable: !0,
|
|
51
53
|
configurable: !0,
|
|
@@ -53,8 +55,8 @@ function A(e, t, n) {
|
|
|
53
55
|
}) : e[t] = n, e;
|
|
54
56
|
}
|
|
55
57
|
//#endregion
|
|
56
|
-
//#region \0@oxc-project+runtime@0.
|
|
57
|
-
function
|
|
58
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectSpread2.js
|
|
59
|
+
function L(e, t) {
|
|
58
60
|
var n = Object.keys(e);
|
|
59
61
|
if (Object.getOwnPropertySymbols) {
|
|
60
62
|
var r = Object.getOwnPropertySymbols(e);
|
|
@@ -64,12 +66,12 @@ function j(e, t) {
|
|
|
64
66
|
}
|
|
65
67
|
return n;
|
|
66
68
|
}
|
|
67
|
-
function
|
|
69
|
+
function R(e) {
|
|
68
70
|
for (var t = 1; t < arguments.length; t++) {
|
|
69
71
|
var n = arguments[t] == null ? {} : arguments[t];
|
|
70
|
-
t % 2 ?
|
|
71
|
-
|
|
72
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(n)) :
|
|
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) {
|
|
73
75
|
Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(n, t));
|
|
74
76
|
});
|
|
75
77
|
}
|
|
@@ -77,35 +79,35 @@ function M(e) {
|
|
|
77
79
|
}
|
|
78
80
|
//#endregion
|
|
79
81
|
//#region src/provide-blok.tsx
|
|
80
|
-
var
|
|
81
|
-
function
|
|
82
|
-
return /* @__PURE__ */
|
|
82
|
+
var z = n({});
|
|
83
|
+
function B({ defaults: e, children: t }) {
|
|
84
|
+
return /* @__PURE__ */ T(z.Provider, {
|
|
83
85
|
value: e,
|
|
84
86
|
children: t
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
89
|
+
function V() {
|
|
90
|
+
return s(z);
|
|
89
91
|
}
|
|
90
92
|
function ne(e, t) {
|
|
91
93
|
if (Object.keys(e).length === 0) return t;
|
|
92
|
-
let n =
|
|
94
|
+
let n = R({}, e);
|
|
93
95
|
for (let e of Object.keys(t)) {
|
|
94
96
|
let r = t[e];
|
|
95
97
|
r !== void 0 && (n[e] = r);
|
|
96
98
|
}
|
|
97
|
-
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools =
|
|
99
|
+
return (e.tools !== void 0 || t.tools !== void 0) && (n.tools = R(R({}, e.tools), t.tools)), n;
|
|
98
100
|
}
|
|
99
101
|
//#endregion
|
|
100
102
|
//#region src/block-portal-registry.ts
|
|
101
|
-
var
|
|
103
|
+
var H = "__blokPortalRegistry", U = "__blokToolName", W = () => {
|
|
102
104
|
let e = { snapshot: /* @__PURE__ */ new Map() }, t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map(), r = (n) => {
|
|
103
105
|
e.snapshot = n, t.forEach((e) => e());
|
|
104
106
|
};
|
|
105
107
|
return {
|
|
106
108
|
register(t, i) {
|
|
107
109
|
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 :
|
|
110
|
+
a.set(t, o === void 0 ? i : R(R({}, i), {}, { props: R(R({}, i.props), {}, { config: o }) })), r(a);
|
|
109
111
|
},
|
|
110
112
|
unregister(t) {
|
|
111
113
|
if (!e.snapshot.has(t)) return;
|
|
@@ -116,14 +118,14 @@ var F = "__blokPortalRegistry", I = "__blokToolName", L = () => {
|
|
|
116
118
|
let i = e.snapshot.get(t);
|
|
117
119
|
if (i === void 0) return;
|
|
118
120
|
let a = new Map(e.snapshot);
|
|
119
|
-
a.set(t,
|
|
121
|
+
a.set(t, R(R({}, i), {}, { props: R(R({}, i.props), n) })), r(a);
|
|
120
122
|
},
|
|
121
123
|
setToolConfig(t, i) {
|
|
122
124
|
n.set(t, i);
|
|
123
125
|
let a = [...e.snapshot].filter(([, e]) => e.toolName === t);
|
|
124
126
|
if (a.length === 0) return;
|
|
125
127
|
let o = new Map(e.snapshot);
|
|
126
|
-
for (let [e, t] of a) o.set(e,
|
|
128
|
+
for (let [e, t] of a) o.set(e, R(R({}, t), {}, { props: R(R({}, t.props), {}, { config: i }) }));
|
|
127
129
|
r(o);
|
|
128
130
|
},
|
|
129
131
|
subscribe(e) {
|
|
@@ -135,45 +137,45 @@ var F = "__blokPortalRegistry", I = "__blokToolName", L = () => {
|
|
|
135
137
|
return e.snapshot;
|
|
136
138
|
}
|
|
137
139
|
};
|
|
138
|
-
},
|
|
139
|
-
function
|
|
140
|
-
|
|
140
|
+
}, G = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
function re(e, t) {
|
|
142
|
+
G.set(e, t);
|
|
141
143
|
}
|
|
142
|
-
function
|
|
143
|
-
return
|
|
144
|
+
function ie(e) {
|
|
145
|
+
return G.get(e);
|
|
144
146
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
147
|
+
function K(e) {
|
|
148
|
+
G.delete(e);
|
|
147
149
|
}
|
|
148
150
|
//#endregion
|
|
149
151
|
//#region src/live-tool-config.ts
|
|
150
|
-
var
|
|
152
|
+
var q = (e) => {
|
|
151
153
|
if (typeof e != "object" || !e) return !1;
|
|
152
154
|
let t = Object.getPrototypeOf(e);
|
|
153
155
|
return t === Object.prototype || t === null;
|
|
154
|
-
},
|
|
156
|
+
}, ae = (e, t) => t.reduce((e, t) => {
|
|
155
157
|
if (Array.isArray(e)) return typeof t == "number" ? e[t] : void 0;
|
|
156
|
-
if (
|
|
157
|
-
}, e),
|
|
158
|
+
if (q(e)) return e[t];
|
|
159
|
+
}, e), oe = (e, t) => {
|
|
158
160
|
let n = (e, t) => {
|
|
159
161
|
if (typeof e == "function") return typeof t == "function" ? t : e;
|
|
160
162
|
if (Array.isArray(e)) {
|
|
161
163
|
let r = Array.isArray(t) ? t : [];
|
|
162
164
|
return e.map((e, t) => n(e, r[t]));
|
|
163
165
|
}
|
|
164
|
-
if (
|
|
165
|
-
let r =
|
|
166
|
+
if (q(e)) {
|
|
167
|
+
let r = q(t) ? t : {}, i = {};
|
|
166
168
|
for (let [t, a] of Object.entries(e)) i[t] = n(a, r[t]);
|
|
167
169
|
return i;
|
|
168
170
|
}
|
|
169
171
|
return e;
|
|
170
172
|
}, r = n(t, e);
|
|
171
|
-
return
|
|
172
|
-
},
|
|
173
|
-
if (!
|
|
173
|
+
return q(r) ? r : {};
|
|
174
|
+
}, se = (e, t) => {
|
|
175
|
+
if (!q(e)) return e;
|
|
174
176
|
let n = {};
|
|
175
177
|
for (let [r, i] of Object.entries(e)) {
|
|
176
|
-
if (!
|
|
178
|
+
if (!q(i) || !q(i.config)) {
|
|
177
179
|
n[r] = i;
|
|
178
180
|
continue;
|
|
179
181
|
}
|
|
@@ -181,12 +183,12 @@ var H = (e) => {
|
|
|
181
183
|
if (typeof n == "function") {
|
|
182
184
|
let e = n;
|
|
183
185
|
return function(...n) {
|
|
184
|
-
let a = t(), o =
|
|
186
|
+
let a = t(), o = q(a) ? a[r] : void 0, s = ae(q(o) ? o.config : void 0, i);
|
|
185
187
|
return Reflect.apply(typeof s == "function" ? s : e, this, n);
|
|
186
188
|
};
|
|
187
189
|
}
|
|
188
190
|
if (Array.isArray(n)) return e.has(n) ? n : (e.add(n), n.map((e, t) => a(e, [...i, t])));
|
|
189
|
-
if (
|
|
191
|
+
if (q(n)) {
|
|
190
192
|
if (e.has(n)) return n;
|
|
191
193
|
e.add(n);
|
|
192
194
|
let t = {};
|
|
@@ -195,155 +197,191 @@ var H = (e) => {
|
|
|
195
197
|
}
|
|
196
198
|
return n;
|
|
197
199
|
};
|
|
198
|
-
n[r] =
|
|
200
|
+
n[r] = R(R({}, i), {}, { config: a(i.config, []) });
|
|
199
201
|
}
|
|
200
202
|
return n;
|
|
201
|
-
},
|
|
203
|
+
}, J = (e) => {
|
|
202
204
|
let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
|
|
203
205
|
return typeof t == "function" && t.__isBlokReactBlock === !0;
|
|
204
|
-
},
|
|
206
|
+
}, ce = (e) => {
|
|
205
207
|
let t = typeof e == "function" ? e : e == null ? void 0 : e.class;
|
|
206
208
|
return typeof t == "function" && t.__isBlokReactInlineTool === !0;
|
|
207
|
-
},
|
|
209
|
+
}, le = (e, t) => {
|
|
208
210
|
if (typeof e != "object" || !e) return e;
|
|
209
211
|
let n = {};
|
|
210
212
|
for (let [i, a] of Object.entries(e)) {
|
|
211
213
|
var r;
|
|
212
|
-
if (!
|
|
214
|
+
if (!J(a) && !ce(a)) {
|
|
213
215
|
n[i] = a;
|
|
214
216
|
continue;
|
|
215
217
|
}
|
|
216
|
-
let e = typeof a == "function" ? { class: a } :
|
|
217
|
-
e.config =
|
|
218
|
-
[
|
|
219
|
-
[
|
|
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
|
|
220
222
|
}), n[i] = e;
|
|
221
223
|
}
|
|
222
224
|
return n;
|
|
223
225
|
};
|
|
224
|
-
function
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
function Y(e, t) {
|
|
227
|
+
var n, r;
|
|
228
|
+
let i = ne(s(z), e), [a, o] = f(null), l = d(i);
|
|
229
|
+
l.current = i;
|
|
230
|
+
let p = d({
|
|
228
231
|
editor: null,
|
|
229
232
|
holder: null,
|
|
230
233
|
destroyTimeout: null,
|
|
231
234
|
isDestroyed: !1,
|
|
232
235
|
isEditorReady: !1,
|
|
233
236
|
depsToken: null
|
|
234
|
-
}),
|
|
235
|
-
|
|
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(() => {
|
|
239
|
+
var e;
|
|
236
240
|
if (typeof window > "u") return;
|
|
237
|
-
let
|
|
238
|
-
if (
|
|
239
|
-
|
|
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);
|
|
240
244
|
};
|
|
241
|
-
if (
|
|
242
|
-
|
|
245
|
+
if (t.editor !== null && !t.isDestroyed) {
|
|
246
|
+
M(t.editor), K(t.editor);
|
|
243
247
|
try {
|
|
244
|
-
|
|
248
|
+
t.editor.destroy();
|
|
245
249
|
} catch (e) {}
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
let
|
|
249
|
-
|
|
250
|
-
let
|
|
251
|
-
|
|
252
|
-
let
|
|
253
|
-
holder:
|
|
250
|
+
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, o(null);
|
|
251
|
+
}
|
|
252
|
+
let n = document.createElement("div");
|
|
253
|
+
t.holder = n, t.isDestroyed = !1, t.isEditorReady = !1, t.depsToken = h;
|
|
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 }), {}, {
|
|
257
|
+
holder: n,
|
|
254
258
|
onReady: (...e) => {
|
|
255
259
|
var t, n;
|
|
256
|
-
(t = (n =
|
|
260
|
+
(t = (n = l.current).onReady) == null || t.call(n, ...e);
|
|
257
261
|
},
|
|
258
262
|
onChange: (...e) => {
|
|
259
263
|
var t, n;
|
|
260
|
-
(t = (n =
|
|
264
|
+
(t = (n = l.current).onChange) == null || t.call(n, ...e);
|
|
261
265
|
},
|
|
262
266
|
onEnter: (...e) => {
|
|
263
267
|
var t, n;
|
|
264
|
-
return (t = (n =
|
|
268
|
+
return (t = (n = l.current).onEnter) == null ? void 0 : t.call(n, ...e);
|
|
265
269
|
}
|
|
266
270
|
});
|
|
267
|
-
|
|
271
|
+
r.onSave && (c.onSave = (...e) => {
|
|
268
272
|
var t, n;
|
|
269
|
-
|
|
270
|
-
}),
|
|
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) => {
|
|
271
275
|
var t, n, r;
|
|
272
|
-
return (t = (n = (r =
|
|
273
|
-
}),
|
|
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) => {
|
|
274
278
|
var t, n;
|
|
275
|
-
(t = (n =
|
|
279
|
+
(t = (n = l.current).onAfterRender) == null || t.call(n, ...e);
|
|
276
280
|
});
|
|
277
|
-
let
|
|
278
|
-
return
|
|
279
|
-
|
|
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));
|
|
280
284
|
}).catch(() => {
|
|
281
|
-
if (
|
|
282
|
-
|
|
285
|
+
if (t.editor === u && !t.isDestroyed) {
|
|
286
|
+
M(u), K(u);
|
|
283
287
|
try {
|
|
284
|
-
|
|
288
|
+
u.destroy();
|
|
285
289
|
} catch (e) {}
|
|
286
|
-
|
|
290
|
+
t.editor = null, t.holder = null, t.isDestroyed = !0, t.isEditorReady = !1, o(null);
|
|
287
291
|
}
|
|
288
292
|
}), () => {
|
|
289
|
-
|
|
293
|
+
X(t, o);
|
|
290
294
|
};
|
|
291
|
-
}, [
|
|
292
|
-
let e =
|
|
295
|
+
}, [h]), c(() => {
|
|
296
|
+
let e = w.current, t = p.current;
|
|
293
297
|
if (e === null || t.editor === null || t.isDestroyed) return;
|
|
294
|
-
let n =
|
|
298
|
+
let n = l.current.tools;
|
|
295
299
|
if (typeof n != "object" || !n) return;
|
|
296
|
-
let r =
|
|
300
|
+
let r = T.current;
|
|
297
301
|
for (let [t, a] of Object.entries(n)) {
|
|
298
302
|
var i;
|
|
299
|
-
if (!
|
|
300
|
-
let n = typeof a == "function" || (i = a.config) == null ? {} : i, o = r == null ? void 0 : r[t], s =
|
|
301
|
-
if (c !== void 0 &&
|
|
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;
|
|
302
306
|
let l = Object.freeze(s);
|
|
303
|
-
|
|
307
|
+
E.current.set(t, l), e.setToolConfig(t, l);
|
|
308
|
+
}
|
|
309
|
+
}), c(() => {
|
|
310
|
+
let e = p.current;
|
|
311
|
+
if (e.editor === null || e.isDestroyed || !e.isEditorReady) return;
|
|
312
|
+
let t = l.current.tools;
|
|
313
|
+
if (!(typeof t != "object" || !t)) for (let [r, i] of Object.entries(t)) {
|
|
314
|
+
var n;
|
|
315
|
+
if (!D.current.has(r)) continue;
|
|
316
|
+
let t = typeof i == "object" && i ? i.toolbox : void 0;
|
|
317
|
+
b(t, D.current.get(r)) || (D.current.set(r, t), (n = e.editor.tools) == null || n.update(r, { toolbox: t }));
|
|
304
318
|
}
|
|
305
319
|
});
|
|
306
|
-
let
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}, [
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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;
|
|
333
371
|
return;
|
|
334
372
|
}
|
|
335
|
-
|
|
336
|
-
|
|
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;
|
|
337
375
|
}, () => {}).then(() => {
|
|
338
|
-
|
|
376
|
+
C.current === G && (C.current = void 0);
|
|
339
377
|
}));
|
|
340
378
|
}
|
|
341
|
-
}, [
|
|
379
|
+
}, [a, G]), a;
|
|
342
380
|
}
|
|
343
|
-
function
|
|
381
|
+
function X(e, t) {
|
|
344
382
|
e.destroyTimeout = setTimeout(() => {
|
|
345
383
|
if (e.editor !== null) {
|
|
346
|
-
|
|
384
|
+
M(e.editor), K(e.editor);
|
|
347
385
|
try {
|
|
348
386
|
e.editor.destroy();
|
|
349
387
|
} catch (e) {}
|
|
@@ -353,7 +391,7 @@ function J(e, t) {
|
|
|
353
391
|
}
|
|
354
392
|
//#endregion
|
|
355
393
|
//#region src/BlockPortalHost.tsx
|
|
356
|
-
var
|
|
394
|
+
var ue = class extends e {
|
|
357
395
|
constructor(...e) {
|
|
358
396
|
super(...e), this.state = { failed: !1 };
|
|
359
397
|
}
|
|
@@ -365,16 +403,16 @@ var Y = class extends e {
|
|
|
365
403
|
return this.state.failed ? null : this.props.children;
|
|
366
404
|
}
|
|
367
405
|
};
|
|
368
|
-
function
|
|
369
|
-
let t =
|
|
370
|
-
return /* @__PURE__ */
|
|
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]) => {
|
|
371
409
|
let n = t.component;
|
|
372
|
-
return
|
|
410
|
+
return E(/* @__PURE__ */ T(ue, { children: /* @__PURE__ */ T(n, R({}, t.props)) }), t.hostEl, e);
|
|
373
411
|
}) });
|
|
374
412
|
}
|
|
375
413
|
//#endregion
|
|
376
|
-
//#region \0@oxc-project+runtime@0.
|
|
377
|
-
function
|
|
414
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutPropertiesLoose.js
|
|
415
|
+
function de(e, t) {
|
|
378
416
|
if (e == null) return {};
|
|
379
417
|
var n = {};
|
|
380
418
|
for (var r in e) if ({}.hasOwnProperty.call(e, r)) {
|
|
@@ -384,10 +422,10 @@ function ae(e, t) {
|
|
|
384
422
|
return n;
|
|
385
423
|
}
|
|
386
424
|
//#endregion
|
|
387
|
-
//#region \0@oxc-project+runtime@0.
|
|
388
|
-
function
|
|
425
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/objectWithoutProperties.js
|
|
426
|
+
function Q(e, t) {
|
|
389
427
|
if (e == null) return {};
|
|
390
|
-
var n, r, i =
|
|
428
|
+
var n, r, i = de(e, t);
|
|
391
429
|
if (Object.getOwnPropertySymbols) {
|
|
392
430
|
var a = Object.getOwnPropertySymbols(e);
|
|
393
431
|
for (r = 0; r < a.length; r++) n = a[r], t.includes(n) || {}.propertyIsEnumerable.call(e, n) && (i[n] = e[n]);
|
|
@@ -396,51 +434,51 @@ function Z(e, t) {
|
|
|
396
434
|
}
|
|
397
435
|
//#endregion
|
|
398
436
|
//#region src/BlokContent.tsx
|
|
399
|
-
var
|
|
400
|
-
let { editor: n } = e, r =
|
|
437
|
+
var fe = ["editor"], pe = i(function(e, t) {
|
|
438
|
+
let { editor: n } = e, r = Q(e, fe), i = d(null), a = (e) => {
|
|
401
439
|
if (i.current = e, typeof t == "function") t(e);
|
|
402
440
|
else if (t != null) {
|
|
403
441
|
let n = t;
|
|
404
442
|
n.current = e;
|
|
405
443
|
}
|
|
406
444
|
};
|
|
407
|
-
|
|
445
|
+
c(() => {
|
|
408
446
|
if (n === null || i.current === null) return;
|
|
409
|
-
let e =
|
|
447
|
+
let e = j(n);
|
|
410
448
|
if (e !== void 0) return i.current.appendChild(e), () => {
|
|
411
449
|
e.remove();
|
|
412
450
|
};
|
|
413
451
|
}, [n]);
|
|
414
|
-
let
|
|
415
|
-
return /* @__PURE__ */
|
|
416
|
-
}),
|
|
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 = [
|
|
417
455
|
"deps",
|
|
418
456
|
"onReady",
|
|
419
457
|
"onBlocksRendered",
|
|
420
458
|
"onBlockRendered"
|
|
421
|
-
],
|
|
422
|
-
let { deps: n, onReady: r, onBlocksRendered: i, onBlockRendered:
|
|
423
|
-
for (let e of Object.keys(
|
|
424
|
-
let t =
|
|
425
|
-
|
|
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;
|
|
426
464
|
}
|
|
427
|
-
let f =
|
|
428
|
-
|
|
429
|
-
let p =
|
|
465
|
+
let f = Y(s, n);
|
|
466
|
+
l(t, () => f, [f]);
|
|
467
|
+
let p = d(r);
|
|
430
468
|
p.current = r;
|
|
431
|
-
let m =
|
|
432
|
-
|
|
469
|
+
let m = d(null);
|
|
470
|
+
c(() => {
|
|
433
471
|
if (f !== null && m.current !== f) {
|
|
434
472
|
var e;
|
|
435
473
|
m.current = f, (e = p.current) == null || e.call(p, f);
|
|
436
474
|
}
|
|
437
475
|
}, [f]);
|
|
438
|
-
let h =
|
|
476
|
+
let h = d(i);
|
|
439
477
|
h.current = i;
|
|
440
|
-
let g =
|
|
441
|
-
g.current =
|
|
442
|
-
let _ = !!i, v = !!
|
|
443
|
-
return
|
|
478
|
+
let g = d(a);
|
|
479
|
+
g.current = a;
|
|
480
|
+
let _ = !!i, v = !!a;
|
|
481
|
+
return c(() => {
|
|
444
482
|
if (f === null) return;
|
|
445
483
|
let e = [];
|
|
446
484
|
if (_) {
|
|
@@ -464,28 +502,192 @@ var oe = ["editor"], Q = n(function(e, t) {
|
|
|
464
502
|
f,
|
|
465
503
|
_,
|
|
466
504
|
v
|
|
467
|
-
]), /* @__PURE__ */
|
|
468
|
-
}),
|
|
469
|
-
function
|
|
470
|
-
let t =
|
|
505
|
+
]), /* @__PURE__ */ T(pe, R({ editor: f }, u));
|
|
506
|
+
}), ve = "block changed";
|
|
507
|
+
function ye(e) {
|
|
508
|
+
let t = d(0), n = d(e);
|
|
471
509
|
n.current !== e && (n.current = e, t.current = 0);
|
|
472
|
-
let
|
|
510
|
+
let r = o((n) => {
|
|
473
511
|
if (e === null) return () => void 0;
|
|
474
512
|
let r = () => {
|
|
475
513
|
t.current += 1, n();
|
|
476
514
|
};
|
|
477
|
-
return e.on(
|
|
478
|
-
}, [e]),
|
|
479
|
-
return
|
|
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]);
|
|
480
518
|
}
|
|
481
519
|
//#endregion
|
|
482
|
-
//#region src/
|
|
483
|
-
|
|
484
|
-
|
|
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;
|
|
534
|
+
}
|
|
535
|
+
//#endregion
|
|
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) {
|
|
485
650
|
var t;
|
|
651
|
+
let n = (e) => {
|
|
652
|
+
if (typeof document > "u") return null;
|
|
653
|
+
let t = document.createElement("div"), n = k(t);
|
|
654
|
+
D(() => {
|
|
655
|
+
n.render(e);
|
|
656
|
+
});
|
|
657
|
+
let r = t.innerHTML;
|
|
658
|
+
return n.unmount(), r === "" ? null : r;
|
|
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 });
|
|
664
|
+
};
|
|
665
|
+
return e.toolbox === void 0 ? {
|
|
666
|
+
value: void 0,
|
|
667
|
+
complete: t.complete
|
|
668
|
+
} : {
|
|
669
|
+
value: Array.isArray(e.toolbox) ? e.toolbox.map(r) : r(e.toolbox),
|
|
670
|
+
complete: t.complete
|
|
671
|
+
};
|
|
672
|
+
}, i = {
|
|
673
|
+
resolved: !1,
|
|
674
|
+
value: void 0
|
|
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) => {
|
|
680
|
+
let n = e.viewComponent;
|
|
681
|
+
if (t.readOnly && n !== void 0) {
|
|
682
|
+
let { commit: e, readOnly: r } = t;
|
|
683
|
+
return /* @__PURE__ */ T(n, R({}, Q(t, ke)));
|
|
684
|
+
}
|
|
685
|
+
let r = e.component;
|
|
686
|
+
return /* @__PURE__ */ T(r, R({}, t));
|
|
687
|
+
};
|
|
486
688
|
return t = class {
|
|
487
689
|
static get toolbox() {
|
|
488
|
-
return
|
|
690
|
+
return o();
|
|
489
691
|
}
|
|
490
692
|
static get isReadOnlySupported() {
|
|
491
693
|
return !0;
|
|
@@ -494,41 +696,41 @@ function pe(e) {
|
|
|
494
696
|
var n, r;
|
|
495
697
|
this.hostEl = null, this.pendingDispatch = !1, this.commit = (t) => {
|
|
496
698
|
var n;
|
|
497
|
-
let r =
|
|
498
|
-
|
|
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());
|
|
499
701
|
}, this.blockApi = t.block;
|
|
500
702
|
let i = (n = t.config) == null ? {} : n;
|
|
501
|
-
this.registry = i[
|
|
502
|
-
let
|
|
503
|
-
this.toolName = typeof
|
|
504
|
-
let
|
|
505
|
-
for (let [e, t] of Object.entries(i))
|
|
506
|
-
this.toolConfig = Object.freeze(
|
|
507
|
-
let
|
|
703
|
+
this.registry = i[H];
|
|
704
|
+
let a = i[U];
|
|
705
|
+
this.toolName = typeof a == "string" ? a : void 0;
|
|
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;
|
|
508
710
|
this.pointerDrag = () => {
|
|
509
711
|
var e;
|
|
510
|
-
return (
|
|
511
|
-
}, this.mirror =
|
|
512
|
-
let
|
|
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;
|
|
513
715
|
this.childrenComponent = function() {
|
|
514
|
-
let e =
|
|
515
|
-
return
|
|
516
|
-
e.current !== null &&
|
|
517
|
-
}), /* @__PURE__ */
|
|
716
|
+
let e = d(null);
|
|
717
|
+
return c(() => {
|
|
718
|
+
e.current !== null && C(e.current, l.getChildren());
|
|
719
|
+
}), /* @__PURE__ */ T("div", {
|
|
518
720
|
ref: e,
|
|
519
|
-
[
|
|
721
|
+
[h.nestedBlocks]: ""
|
|
520
722
|
});
|
|
521
723
|
};
|
|
522
724
|
}
|
|
523
725
|
render() {
|
|
524
|
-
var
|
|
525
|
-
let
|
|
526
|
-
return
|
|
527
|
-
hostEl:
|
|
528
|
-
component:
|
|
726
|
+
var e;
|
|
727
|
+
let t = document.createElement("div");
|
|
728
|
+
return t.setAttribute("data-blok-mutation-free", "true"), this.hostEl = t, (e = this.registry) == null || e.register(this.blockApi.id, {
|
|
729
|
+
hostEl: t,
|
|
730
|
+
component: s,
|
|
529
731
|
props: this.buildProps(),
|
|
530
732
|
toolName: this.toolName
|
|
531
|
-
}),
|
|
733
|
+
}), t;
|
|
532
734
|
}
|
|
533
735
|
rendered() {
|
|
534
736
|
var t;
|
|
@@ -539,8 +741,8 @@ function pe(e) {
|
|
|
539
741
|
}
|
|
540
742
|
async setData(t) {
|
|
541
743
|
var n = this;
|
|
542
|
-
let r =
|
|
543
|
-
return
|
|
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);
|
|
544
746
|
}
|
|
545
747
|
setReadOnly(e) {
|
|
546
748
|
this.readOnly = e, this.pushProps({ readOnly: e });
|
|
@@ -569,7 +771,7 @@ function pe(e) {
|
|
|
569
771
|
}
|
|
570
772
|
pushProps(e) {
|
|
571
773
|
let t = this.registry;
|
|
572
|
-
t !== void 0 &&
|
|
774
|
+
t !== void 0 && D(() => {
|
|
573
775
|
t.setProps(this.blockApi.id, e);
|
|
574
776
|
});
|
|
575
777
|
}
|
|
@@ -593,39 +795,47 @@ function pe(e) {
|
|
|
593
795
|
}
|
|
594
796
|
//#endregion
|
|
595
797
|
//#region src/createReactInlineTool.tsx
|
|
596
|
-
var
|
|
597
|
-
function
|
|
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) {
|
|
598
805
|
var t;
|
|
599
806
|
return t = class {
|
|
600
807
|
static get title() {
|
|
601
808
|
return e.title;
|
|
602
809
|
}
|
|
810
|
+
static get titleKey() {
|
|
811
|
+
return e.titleKey;
|
|
812
|
+
}
|
|
603
813
|
static get shortcut() {
|
|
604
814
|
return e.shortcut;
|
|
605
815
|
}
|
|
606
816
|
static get sanitize() {
|
|
607
|
-
return e.sanitize;
|
|
817
|
+
return e.sanitize === void 0 ? e.mark === void 0 ? void 0 : S(e.mark) : e.sanitize;
|
|
608
818
|
}
|
|
609
819
|
static get isReadOnlySupported() {
|
|
610
820
|
var t;
|
|
611
|
-
return (t = e.isReadOnlySupported)
|
|
821
|
+
return (t = e.isReadOnlySupported) != null && t;
|
|
612
822
|
}
|
|
613
823
|
constructor(t) {
|
|
614
824
|
var n;
|
|
615
825
|
this.active = !1, this.registered = !1;
|
|
616
826
|
let r = (n = t == null ? void 0 : t.config) == null ? {} : n;
|
|
617
|
-
this.registry = r[
|
|
618
|
-
let i = r[
|
|
619
|
-
this.toolName = typeof i == "string" ? i : e.type, this.portalKey =
|
|
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);
|
|
620
830
|
let a = {};
|
|
621
|
-
for (let [e, t] of Object.entries(r))
|
|
622
|
-
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();
|
|
623
833
|
}
|
|
624
834
|
render() {
|
|
625
835
|
let t = document.createElement("div");
|
|
626
836
|
return t.setAttribute("data-blok-mutation-free", "true"), this.registry !== void 0 && (this.registry.register(this.portalKey, {
|
|
627
837
|
hostEl: t,
|
|
628
|
-
component:
|
|
838
|
+
component: this.portalComponent,
|
|
629
839
|
props: {
|
|
630
840
|
active: this.active,
|
|
631
841
|
config: this.toolConfig
|
|
@@ -636,9 +846,7 @@ function ge(e) {
|
|
|
636
846
|
title: e.title,
|
|
637
847
|
icon: t,
|
|
638
848
|
onActivate: () => {
|
|
639
|
-
|
|
640
|
-
let t = window.getSelection();
|
|
641
|
-
!t || t.rangeCount === 0 || e.surround(t.getRangeAt(0));
|
|
849
|
+
this.activate();
|
|
642
850
|
},
|
|
643
851
|
isActive: () => this.refreshActiveState()
|
|
644
852
|
};
|
|
@@ -647,15 +855,53 @@ function ge(e) {
|
|
|
647
855
|
var e;
|
|
648
856
|
this.registered && (this.registered = !1, (e = this.registry) == null || e.unregister(this.portalKey));
|
|
649
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
|
+
}
|
|
650
868
|
refreshActiveState() {
|
|
651
|
-
let
|
|
652
|
-
if (
|
|
653
|
-
var
|
|
654
|
-
(
|
|
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 });
|
|
655
873
|
}
|
|
656
|
-
return
|
|
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;
|
|
657
903
|
}
|
|
658
904
|
}, t.__isBlokReactInlineTool = !0, t.isInline = !0, t;
|
|
659
905
|
}
|
|
660
906
|
//#endregion
|
|
661
|
-
export {
|
|
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 };
|