@juo/blocks 1.16.0 → 2.0.0-alpha.1
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/{ExtensionRoot-C3lVJEBl.js → ExtensionRoot-DRpD5EcC.js} +24 -6
- package/dist/block-BjJztStr.js +993 -0
- package/dist/{block-dVP4Rqgz.js → block-DnhzyZ1H.js} +29 -3
- package/dist/block.d.ts +56 -0
- package/dist/block.d.ts.map +1 -1
- package/dist/{bridge-xiKEzCGR.js → bridge-Mz0CqG6E.js} +39 -30
- package/dist/core.js +336 -222
- package/dist/css-runtime-B7tZrBIp.js +749 -0
- package/dist/devtools/hook.d.ts +0 -5
- package/dist/devtools/hook.d.ts.map +1 -1
- package/dist/devtools/index.d.ts +0 -1
- package/dist/devtools/index.d.ts.map +1 -1
- package/dist/devtools/protocol.d.ts +15 -1
- package/dist/devtools/protocol.d.ts.map +1 -1
- package/dist/devtools.js +42 -9
- package/dist/editor/bridge.d.ts +7 -0
- package/dist/editor/bridge.d.ts.map +1 -1
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/main.d.ts +2 -1
- package/dist/editor/main.d.ts.map +1 -1
- package/dist/editor/messages.d.ts +13 -2
- package/dist/editor/messages.d.ts.map +1 -1
- package/dist/editor/overlays.d.ts +14 -0
- package/dist/editor/overlays.d.ts.map +1 -0
- package/dist/editor/overlays.test.d.ts +2 -0
- package/dist/editor/overlays.test.d.ts.map +1 -0
- package/dist/editor.js +52 -33
- package/dist/{gridstack-adapter-CDWbSpbt.js → gridstack-adapter-BGKGC-eO.js} +2 -2
- package/dist/main.d.ts +3 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/{morph-n4LMxOYo.js → morph-CT5hc5Qp.js} +1 -1
- package/dist/overlay-wrapper.d.ts +69 -0
- package/dist/overlay-wrapper.d.ts.map +1 -0
- package/dist/overlay-wrapper.test.d.ts +2 -0
- package/dist/overlay-wrapper.test.d.ts.map +1 -0
- package/dist/overlays/OverlayService.d.ts +34 -0
- package/dist/overlays/OverlayService.d.ts.map +1 -0
- package/dist/overlays/OverlayService.test.d.ts +2 -0
- package/dist/overlays/OverlayService.test.d.ts.map +1 -0
- package/dist/preact/block.d.ts.map +1 -1
- package/dist/preact/context.d.ts.map +1 -1
- package/dist/preact/context.test.d.ts +2 -0
- package/dist/preact/context.test.d.ts.map +1 -0
- package/dist/preact/signals.d.ts +19 -0
- package/dist/preact/signals.d.ts.map +1 -1
- package/dist/preact/useContextSubscription.test.d.ts +2 -0
- package/dist/preact/useContextSubscription.test.d.ts.map +1 -0
- package/dist/preact.js +33 -7
- package/dist/{project-gridstack-CM783oKI.js → project-gridstack-PxN_DIfP.js} +1 -1
- package/dist/react/block.d.ts.map +1 -1
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/context.test.d.ts +2 -0
- package/dist/react/context.test.d.ts.map +1 -0
- package/dist/react/signals.d.ts +19 -0
- package/dist/react/signals.d.ts.map +1 -1
- package/dist/react/useContextSubscription.test.d.ts +2 -0
- package/dist/react/useContextSubscription.test.d.ts.map +1 -0
- package/dist/react.js +40 -8
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/order/adapter.d.ts +7 -6
- package/dist/services/order/adapter.d.ts.map +1 -1
- package/dist/services/order/index.d.ts +2 -3
- package/dist/services/order/index.d.ts.map +1 -1
- package/dist/services/order/orderService.d.ts +2 -3
- package/dist/services/order/orderService.d.ts.map +1 -1
- package/dist/services/order/orderService.test.d.ts +2 -0
- package/dist/services/order/orderService.test.d.ts.map +1 -0
- package/dist/services/order/types.d.ts +53 -14
- package/dist/services/order/types.d.ts.map +1 -1
- package/dist/shared/context.d.ts +10 -3
- package/dist/shared/context.d.ts.map +1 -1
- package/dist/shared/touchSignals.d.ts +17 -0
- package/dist/shared/touchSignals.d.ts.map +1 -0
- package/dist/shared/touchSignals.test.d.ts +2 -0
- package/dist/shared/touchSignals.test.d.ts.map +1 -0
- package/dist/theme-state.d.ts +2 -1
- package/dist/theme-state.d.ts.map +1 -1
- package/dist/theme-state.params.test.d.ts +2 -0
- package/dist/theme-state.params.test.d.ts.map +1 -0
- package/dist/theme-state.translations.test.d.ts +2 -0
- package/dist/theme-state.translations.test.d.ts.map +1 -0
- package/dist/vue/block.d.ts.map +1 -1
- package/dist/vue.js +16 -13
- package/dist/web-components/ExtensionRoot.d.ts +1 -0
- package/dist/web-components/ExtensionRoot.d.ts.map +1 -1
- package/dist/web-components-editor.js +6 -5
- package/dist/web-components-runtime.js +3 -2
- package/package.json +1 -1
- package/dist/css-runtime-ClH0MEYr.js +0 -1570
- package/dist/devtools/instrumentation.d.ts +0 -47
- package/dist/devtools/instrumentation.d.ts.map +0 -1
- package/dist/index-JSv6UH_o.js +0 -169
- package/dist/services/orders/adapter.d.ts +0 -10
- package/dist/services/orders/adapter.d.ts.map +0 -1
- package/dist/services/orders/index.d.ts +0 -4
- package/dist/services/orders/index.d.ts.map +0 -1
- package/dist/services/orders/ordersService.d.ts +0 -6
- package/dist/services/orders/ordersService.d.ts.map +0 -1
- package/dist/services/orders/ordersService.test.d.ts +0 -2
- package/dist/services/orders/ordersService.test.d.ts.map +0 -1
- package/dist/services/orders/types.d.ts +0 -60
- package/dist/services/orders/types.d.ts.map +0 -1
|
@@ -0,0 +1,993 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
import { getHook } from "./devtools.js";
|
|
5
|
+
import { reportBlockError, reportBlockWarning } from "./observability.js";
|
|
6
|
+
const createContext = (key) => key;
|
|
7
|
+
class ContextRequestEvent extends Event {
|
|
8
|
+
constructor(context, callback, subscribe) {
|
|
9
|
+
super("context-request", { bubbles: true, composed: true });
|
|
10
|
+
this.context = context;
|
|
11
|
+
this.callback = callback;
|
|
12
|
+
this.subscribe = subscribe;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class ContextProvideEvent extends Event {
|
|
16
|
+
constructor(context, value, subscribe) {
|
|
17
|
+
super("context-provide", { bubbles: true, composed: true });
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.value = value;
|
|
20
|
+
this.subscribe = subscribe;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function provideContext(target, context, init) {
|
|
24
|
+
var _a;
|
|
25
|
+
(_a = getHook()) == null ? void 0 : _a.emit("context:provide", { context: String(context) });
|
|
26
|
+
const ev = new ContextProvideEvent(context, init);
|
|
27
|
+
target.dispatchEvent(ev);
|
|
28
|
+
}
|
|
29
|
+
function injectContext(target, context) {
|
|
30
|
+
var _a;
|
|
31
|
+
let value = void 0;
|
|
32
|
+
(_a = getHook()) == null ? void 0 : _a.emit("context:request", { context: String(context) });
|
|
33
|
+
const ev = new ContextRequestEvent(context, (received) => {
|
|
34
|
+
value = received;
|
|
35
|
+
});
|
|
36
|
+
target.dispatchEvent(ev);
|
|
37
|
+
if (value === void 0) {
|
|
38
|
+
throw new Error(`Context '${context}' not defined`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function subscribeContext(target, context, callback) {
|
|
43
|
+
var _a;
|
|
44
|
+
let unsubscribeFunction = null;
|
|
45
|
+
(_a = getHook()) == null ? void 0 : _a.emit("context:request", { context: String(context) });
|
|
46
|
+
const protocolCallback = (value, unsubscribe) => {
|
|
47
|
+
if (unsubscribe) {
|
|
48
|
+
unsubscribeFunction = unsubscribe;
|
|
49
|
+
}
|
|
50
|
+
callback(value);
|
|
51
|
+
};
|
|
52
|
+
const ev = new ContextRequestEvent(context, protocolCallback, true);
|
|
53
|
+
target.dispatchEvent(ev);
|
|
54
|
+
return () => {
|
|
55
|
+
if (unsubscribeFunction) {
|
|
56
|
+
unsubscribeFunction();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
class ContextRoot extends HTMLElement {
|
|
61
|
+
constructor() {
|
|
62
|
+
super(...arguments);
|
|
63
|
+
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
64
|
+
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
65
|
+
}
|
|
66
|
+
connectedCallback() {
|
|
67
|
+
this.addEventListener("context-provide", (ev) => {
|
|
68
|
+
ev.stopPropagation();
|
|
69
|
+
this.store.set(ev.context, ev.value);
|
|
70
|
+
const registeredCallbacks = this.callbacks.get(ev.context) ?? [];
|
|
71
|
+
registeredCallbacks.forEach((cb) => {
|
|
72
|
+
const unsubscribe = () => {
|
|
73
|
+
const callbacks = this.callbacks.get(ev.context);
|
|
74
|
+
if (callbacks) {
|
|
75
|
+
const cbIndex = callbacks.indexOf(cb);
|
|
76
|
+
if (cbIndex > -1) {
|
|
77
|
+
callbacks.splice(cbIndex, 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
cb(ev.value, unsubscribe);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
this.addEventListener("context-request", (ev) => {
|
|
85
|
+
ev.stopPropagation();
|
|
86
|
+
const storedValue = this.store.get(ev.context);
|
|
87
|
+
if (ev.subscribe) {
|
|
88
|
+
let callbacks = this.callbacks.get(ev.context);
|
|
89
|
+
if (!callbacks) {
|
|
90
|
+
callbacks = [];
|
|
91
|
+
this.callbacks.set(ev.context, callbacks);
|
|
92
|
+
}
|
|
93
|
+
const unsubscribe = () => {
|
|
94
|
+
const currentCallbacks = this.callbacks.get(ev.context);
|
|
95
|
+
if (currentCallbacks) {
|
|
96
|
+
const index = currentCallbacks.indexOf(ev.callback);
|
|
97
|
+
if (index > -1) {
|
|
98
|
+
currentCallbacks.splice(index, 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
callbacks.push(ev.callback);
|
|
103
|
+
if (storedValue !== void 0) {
|
|
104
|
+
ev.callback(storedValue, unsubscribe);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
if (storedValue !== void 0) {
|
|
108
|
+
ev.callback(storedValue);
|
|
109
|
+
} else {
|
|
110
|
+
console.warn("Context not present in store: " + String(ev.context));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
var i = Symbol.for("preact-signals");
|
|
117
|
+
function t() {
|
|
118
|
+
if (!(s > 1)) {
|
|
119
|
+
var i2, t2 = false;
|
|
120
|
+
while (void 0 !== h) {
|
|
121
|
+
var r2 = h;
|
|
122
|
+
h = void 0;
|
|
123
|
+
f++;
|
|
124
|
+
while (void 0 !== r2) {
|
|
125
|
+
var o2 = r2.o;
|
|
126
|
+
r2.o = void 0;
|
|
127
|
+
r2.f &= -3;
|
|
128
|
+
if (!(8 & r2.f) && c(r2)) try {
|
|
129
|
+
r2.c();
|
|
130
|
+
} catch (r3) {
|
|
131
|
+
if (!t2) {
|
|
132
|
+
i2 = r3;
|
|
133
|
+
t2 = true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
r2 = o2;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
f = 0;
|
|
140
|
+
s--;
|
|
141
|
+
if (t2) throw i2;
|
|
142
|
+
} else s--;
|
|
143
|
+
}
|
|
144
|
+
function r(i2) {
|
|
145
|
+
if (s > 0) return i2();
|
|
146
|
+
s++;
|
|
147
|
+
try {
|
|
148
|
+
return i2();
|
|
149
|
+
} finally {
|
|
150
|
+
t();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
var o = void 0;
|
|
154
|
+
function n(i2) {
|
|
155
|
+
var t2 = o;
|
|
156
|
+
o = void 0;
|
|
157
|
+
try {
|
|
158
|
+
return i2();
|
|
159
|
+
} finally {
|
|
160
|
+
o = t2;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
var h = void 0, s = 0, f = 0, v = 0;
|
|
164
|
+
function e(i2) {
|
|
165
|
+
if (void 0 !== o) {
|
|
166
|
+
var t2 = i2.n;
|
|
167
|
+
if (void 0 === t2 || t2.t !== o) {
|
|
168
|
+
t2 = { i: 0, S: i2, p: o.s, n: void 0, t: o, e: void 0, x: void 0, r: t2 };
|
|
169
|
+
if (void 0 !== o.s) o.s.n = t2;
|
|
170
|
+
o.s = t2;
|
|
171
|
+
i2.n = t2;
|
|
172
|
+
if (32 & o.f) i2.S(t2);
|
|
173
|
+
return t2;
|
|
174
|
+
} else if (-1 === t2.i) {
|
|
175
|
+
t2.i = 0;
|
|
176
|
+
if (void 0 !== t2.n) {
|
|
177
|
+
t2.n.p = t2.p;
|
|
178
|
+
if (void 0 !== t2.p) t2.p.n = t2.n;
|
|
179
|
+
t2.p = o.s;
|
|
180
|
+
t2.n = void 0;
|
|
181
|
+
o.s.n = t2;
|
|
182
|
+
o.s = t2;
|
|
183
|
+
}
|
|
184
|
+
return t2;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function u(i2, t2) {
|
|
189
|
+
this.v = i2;
|
|
190
|
+
this.i = 0;
|
|
191
|
+
this.n = void 0;
|
|
192
|
+
this.t = void 0;
|
|
193
|
+
this.W = null == t2 ? void 0 : t2.watched;
|
|
194
|
+
this.Z = null == t2 ? void 0 : t2.unwatched;
|
|
195
|
+
}
|
|
196
|
+
u.prototype.brand = i;
|
|
197
|
+
u.prototype.h = function() {
|
|
198
|
+
return true;
|
|
199
|
+
};
|
|
200
|
+
u.prototype.S = function(i2) {
|
|
201
|
+
var t2 = this, r2 = this.t;
|
|
202
|
+
if (r2 !== i2 && void 0 === i2.e) {
|
|
203
|
+
i2.x = r2;
|
|
204
|
+
this.t = i2;
|
|
205
|
+
if (void 0 !== r2) r2.e = i2;
|
|
206
|
+
else n(function() {
|
|
207
|
+
var i3;
|
|
208
|
+
null == (i3 = t2.W) || i3.call(t2);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
u.prototype.U = function(i2) {
|
|
213
|
+
var t2 = this;
|
|
214
|
+
if (void 0 !== this.t) {
|
|
215
|
+
var r2 = i2.e, o2 = i2.x;
|
|
216
|
+
if (void 0 !== r2) {
|
|
217
|
+
r2.x = o2;
|
|
218
|
+
i2.e = void 0;
|
|
219
|
+
}
|
|
220
|
+
if (void 0 !== o2) {
|
|
221
|
+
o2.e = r2;
|
|
222
|
+
i2.x = void 0;
|
|
223
|
+
}
|
|
224
|
+
if (i2 === this.t) {
|
|
225
|
+
this.t = o2;
|
|
226
|
+
if (void 0 === o2) n(function() {
|
|
227
|
+
var i3;
|
|
228
|
+
null == (i3 = t2.Z) || i3.call(t2);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
u.prototype.subscribe = function(i2) {
|
|
234
|
+
var t2 = this;
|
|
235
|
+
return E(function() {
|
|
236
|
+
var r2 = t2.value, n2 = o;
|
|
237
|
+
o = void 0;
|
|
238
|
+
try {
|
|
239
|
+
i2(r2);
|
|
240
|
+
} finally {
|
|
241
|
+
o = n2;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
u.prototype.valueOf = function() {
|
|
246
|
+
return this.value;
|
|
247
|
+
};
|
|
248
|
+
u.prototype.toString = function() {
|
|
249
|
+
return this.value + "";
|
|
250
|
+
};
|
|
251
|
+
u.prototype.toJSON = function() {
|
|
252
|
+
return this.value;
|
|
253
|
+
};
|
|
254
|
+
u.prototype.peek = function() {
|
|
255
|
+
var i2 = o;
|
|
256
|
+
o = void 0;
|
|
257
|
+
try {
|
|
258
|
+
return this.value;
|
|
259
|
+
} finally {
|
|
260
|
+
o = i2;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
Object.defineProperty(u.prototype, "value", { get: function() {
|
|
264
|
+
var i2 = e(this);
|
|
265
|
+
if (void 0 !== i2) i2.i = this.i;
|
|
266
|
+
return this.v;
|
|
267
|
+
}, set: function(i2) {
|
|
268
|
+
if (i2 !== this.v) {
|
|
269
|
+
if (f > 100) throw new Error("Cycle detected");
|
|
270
|
+
this.v = i2;
|
|
271
|
+
this.i++;
|
|
272
|
+
v++;
|
|
273
|
+
s++;
|
|
274
|
+
try {
|
|
275
|
+
for (var r2 = this.t; void 0 !== r2; r2 = r2.x) r2.t.N();
|
|
276
|
+
} finally {
|
|
277
|
+
t();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} });
|
|
281
|
+
function d(i2, t2) {
|
|
282
|
+
return new u(i2, t2);
|
|
283
|
+
}
|
|
284
|
+
function c(i2) {
|
|
285
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) if (t2.S.i !== t2.i || !t2.S.h() || t2.S.i !== t2.i) return true;
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
function a(i2) {
|
|
289
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) {
|
|
290
|
+
var r2 = t2.S.n;
|
|
291
|
+
if (void 0 !== r2) t2.r = r2;
|
|
292
|
+
t2.S.n = t2;
|
|
293
|
+
t2.i = -1;
|
|
294
|
+
if (void 0 === t2.n) {
|
|
295
|
+
i2.s = t2;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function l(i2) {
|
|
301
|
+
var t2 = i2.s, r2 = void 0;
|
|
302
|
+
while (void 0 !== t2) {
|
|
303
|
+
var o2 = t2.p;
|
|
304
|
+
if (-1 === t2.i) {
|
|
305
|
+
t2.S.U(t2);
|
|
306
|
+
if (void 0 !== o2) o2.n = t2.n;
|
|
307
|
+
if (void 0 !== t2.n) t2.n.p = o2;
|
|
308
|
+
} else r2 = t2;
|
|
309
|
+
t2.S.n = t2.r;
|
|
310
|
+
if (void 0 !== t2.r) t2.r = void 0;
|
|
311
|
+
t2 = o2;
|
|
312
|
+
}
|
|
313
|
+
i2.s = r2;
|
|
314
|
+
}
|
|
315
|
+
function y(i2, t2) {
|
|
316
|
+
u.call(this, void 0);
|
|
317
|
+
this.x = i2;
|
|
318
|
+
this.s = void 0;
|
|
319
|
+
this.g = v - 1;
|
|
320
|
+
this.f = 4;
|
|
321
|
+
this.W = null == t2 ? void 0 : t2.watched;
|
|
322
|
+
this.Z = null == t2 ? void 0 : t2.unwatched;
|
|
323
|
+
}
|
|
324
|
+
y.prototype = new u();
|
|
325
|
+
y.prototype.h = function() {
|
|
326
|
+
this.f &= -3;
|
|
327
|
+
if (1 & this.f) return false;
|
|
328
|
+
if (32 == (36 & this.f)) return true;
|
|
329
|
+
this.f &= -5;
|
|
330
|
+
if (this.g === v) return true;
|
|
331
|
+
this.g = v;
|
|
332
|
+
this.f |= 1;
|
|
333
|
+
if (this.i > 0 && !c(this)) {
|
|
334
|
+
this.f &= -2;
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
var i2 = o;
|
|
338
|
+
try {
|
|
339
|
+
a(this);
|
|
340
|
+
o = this;
|
|
341
|
+
var t2 = this.x();
|
|
342
|
+
if (16 & this.f || this.v !== t2 || 0 === this.i) {
|
|
343
|
+
this.v = t2;
|
|
344
|
+
this.f &= -17;
|
|
345
|
+
this.i++;
|
|
346
|
+
}
|
|
347
|
+
} catch (i3) {
|
|
348
|
+
this.v = i3;
|
|
349
|
+
this.f |= 16;
|
|
350
|
+
this.i++;
|
|
351
|
+
}
|
|
352
|
+
o = i2;
|
|
353
|
+
l(this);
|
|
354
|
+
this.f &= -2;
|
|
355
|
+
return true;
|
|
356
|
+
};
|
|
357
|
+
y.prototype.S = function(i2) {
|
|
358
|
+
if (void 0 === this.t) {
|
|
359
|
+
this.f |= 36;
|
|
360
|
+
for (var t2 = this.s; void 0 !== t2; t2 = t2.n) t2.S.S(t2);
|
|
361
|
+
}
|
|
362
|
+
u.prototype.S.call(this, i2);
|
|
363
|
+
};
|
|
364
|
+
y.prototype.U = function(i2) {
|
|
365
|
+
if (void 0 !== this.t) {
|
|
366
|
+
u.prototype.U.call(this, i2);
|
|
367
|
+
if (void 0 === this.t) {
|
|
368
|
+
this.f &= -33;
|
|
369
|
+
for (var t2 = this.s; void 0 !== t2; t2 = t2.n) t2.S.U(t2);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
y.prototype.N = function() {
|
|
374
|
+
if (!(2 & this.f)) {
|
|
375
|
+
this.f |= 6;
|
|
376
|
+
for (var i2 = this.t; void 0 !== i2; i2 = i2.x) i2.t.N();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
Object.defineProperty(y.prototype, "value", { get: function() {
|
|
380
|
+
if (1 & this.f) throw new Error("Cycle detected");
|
|
381
|
+
var i2 = e(this);
|
|
382
|
+
this.h();
|
|
383
|
+
if (void 0 !== i2) i2.i = this.i;
|
|
384
|
+
if (16 & this.f) throw this.v;
|
|
385
|
+
return this.v;
|
|
386
|
+
} });
|
|
387
|
+
function w(i2, t2) {
|
|
388
|
+
return new y(i2, t2);
|
|
389
|
+
}
|
|
390
|
+
function _(i2) {
|
|
391
|
+
var r2 = i2.u;
|
|
392
|
+
i2.u = void 0;
|
|
393
|
+
if ("function" == typeof r2) {
|
|
394
|
+
s++;
|
|
395
|
+
var n2 = o;
|
|
396
|
+
o = void 0;
|
|
397
|
+
try {
|
|
398
|
+
r2();
|
|
399
|
+
} catch (t2) {
|
|
400
|
+
i2.f &= -2;
|
|
401
|
+
i2.f |= 8;
|
|
402
|
+
b(i2);
|
|
403
|
+
throw t2;
|
|
404
|
+
} finally {
|
|
405
|
+
o = n2;
|
|
406
|
+
t();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function b(i2) {
|
|
411
|
+
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) t2.S.U(t2);
|
|
412
|
+
i2.x = void 0;
|
|
413
|
+
i2.s = void 0;
|
|
414
|
+
_(i2);
|
|
415
|
+
}
|
|
416
|
+
function g(i2) {
|
|
417
|
+
if (o !== this) throw new Error("Out-of-order effect");
|
|
418
|
+
l(this);
|
|
419
|
+
o = i2;
|
|
420
|
+
this.f &= -2;
|
|
421
|
+
if (8 & this.f) b(this);
|
|
422
|
+
t();
|
|
423
|
+
}
|
|
424
|
+
function p(i2) {
|
|
425
|
+
this.x = i2;
|
|
426
|
+
this.u = void 0;
|
|
427
|
+
this.s = void 0;
|
|
428
|
+
this.o = void 0;
|
|
429
|
+
this.f = 32;
|
|
430
|
+
}
|
|
431
|
+
p.prototype.c = function() {
|
|
432
|
+
var i2 = this.S();
|
|
433
|
+
try {
|
|
434
|
+
if (8 & this.f) return;
|
|
435
|
+
if (void 0 === this.x) return;
|
|
436
|
+
var t2 = this.x();
|
|
437
|
+
if ("function" == typeof t2) this.u = t2;
|
|
438
|
+
} finally {
|
|
439
|
+
i2();
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
p.prototype.S = function() {
|
|
443
|
+
if (1 & this.f) throw new Error("Cycle detected");
|
|
444
|
+
this.f |= 1;
|
|
445
|
+
this.f &= -9;
|
|
446
|
+
_(this);
|
|
447
|
+
a(this);
|
|
448
|
+
s++;
|
|
449
|
+
var i2 = o;
|
|
450
|
+
o = this;
|
|
451
|
+
return g.bind(this, i2);
|
|
452
|
+
};
|
|
453
|
+
p.prototype.N = function() {
|
|
454
|
+
if (!(2 & this.f)) {
|
|
455
|
+
this.f |= 2;
|
|
456
|
+
this.o = h;
|
|
457
|
+
h = this;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
p.prototype.d = function() {
|
|
461
|
+
this.f |= 8;
|
|
462
|
+
if (!(1 & this.f)) b(this);
|
|
463
|
+
};
|
|
464
|
+
p.prototype.dispose = function() {
|
|
465
|
+
this.d();
|
|
466
|
+
};
|
|
467
|
+
function E(i2) {
|
|
468
|
+
var t2 = new p(i2);
|
|
469
|
+
try {
|
|
470
|
+
t2.c();
|
|
471
|
+
} catch (i3) {
|
|
472
|
+
t2.d();
|
|
473
|
+
throw i3;
|
|
474
|
+
}
|
|
475
|
+
var r2 = t2.d.bind(t2);
|
|
476
|
+
r2[Symbol.dispose] = r2;
|
|
477
|
+
return r2;
|
|
478
|
+
}
|
|
479
|
+
function isEditorPreview() {
|
|
480
|
+
if (typeof window === "undefined") return false;
|
|
481
|
+
return new URLSearchParams(window.location.search).get("editor") === "true";
|
|
482
|
+
}
|
|
483
|
+
const layoutSystemEnabled = d(false);
|
|
484
|
+
function setLayoutSystemEnabled(enabled) {
|
|
485
|
+
if (layoutSystemEnabled.peek() === enabled) return;
|
|
486
|
+
layoutSystemEnabled.value = enabled;
|
|
487
|
+
}
|
|
488
|
+
function hasRenderedContent(scope) {
|
|
489
|
+
var _a;
|
|
490
|
+
for (const child of scope.children) {
|
|
491
|
+
if (!(child instanceof HTMLElement)) {
|
|
492
|
+
continue;
|
|
493
|
+
}
|
|
494
|
+
const display = (_a = child.ownerDocument.defaultView) == null ? void 0 : _a.getComputedStyle(child).display;
|
|
495
|
+
if (display === "contents") {
|
|
496
|
+
if (hasRenderedContent(child)) {
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (child.checkVisibility()) {
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
function attachEmptyTracking(host, scope) {
|
|
508
|
+
let observer = null;
|
|
509
|
+
let disposed = false;
|
|
510
|
+
queueMicrotask(() => {
|
|
511
|
+
if (disposed) return;
|
|
512
|
+
const observed = scope ?? host.shadowRoot ?? host;
|
|
513
|
+
const sync = () => host.toggleAttribute("data-empty", !hasRenderedContent(observed));
|
|
514
|
+
observer = new MutationObserver(sync);
|
|
515
|
+
observer.observe(observed, { childList: true, subtree: true });
|
|
516
|
+
sync();
|
|
517
|
+
});
|
|
518
|
+
return () => {
|
|
519
|
+
disposed = true;
|
|
520
|
+
observer == null ? void 0 : observer.disconnect();
|
|
521
|
+
observer = null;
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
function serializeBlocks(blocks) {
|
|
525
|
+
return blocks.map((block) => serializeBlock(block));
|
|
526
|
+
}
|
|
527
|
+
function serializeBlock(block) {
|
|
528
|
+
return {
|
|
529
|
+
id: block.id,
|
|
530
|
+
type: block.type,
|
|
531
|
+
props: JSON.parse(JSON.stringify(block.props)),
|
|
532
|
+
slots: Object.fromEntries(
|
|
533
|
+
Object.entries(block.slots ?? {}).map(([key, value]) => [
|
|
534
|
+
key,
|
|
535
|
+
Array.isArray(value) ? value.map(
|
|
536
|
+
(v2) => typeof v2 === "string" ? v2 : serializeBlock(v2)
|
|
537
|
+
) : typeof value === "string" ? value : serializeBlock(value)
|
|
538
|
+
])
|
|
539
|
+
)
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function createSelectedBlock() {
|
|
543
|
+
const selected = d(null);
|
|
544
|
+
function setSelection(block) {
|
|
545
|
+
selected.value = null;
|
|
546
|
+
selected.value = block;
|
|
547
|
+
}
|
|
548
|
+
function clearSelection(block) {
|
|
549
|
+
var _a;
|
|
550
|
+
if (block == null || ((_a = selected.value) == null ? void 0 : _a.id) === block.id) {
|
|
551
|
+
selected.value = null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return { selected, setSelection, clearSelection };
|
|
555
|
+
}
|
|
556
|
+
const SelectedBlockContext = createContext("selectedBlock");
|
|
557
|
+
const blockDefinitions = (() => {
|
|
558
|
+
if (typeof window !== "undefined") {
|
|
559
|
+
window._juoBlocks = window._juoBlocks || /* @__PURE__ */ new Map();
|
|
560
|
+
return window._juoBlocks;
|
|
561
|
+
}
|
|
562
|
+
return /* @__PURE__ */ new Map();
|
|
563
|
+
})();
|
|
564
|
+
class BlockWrapperEvent extends Event {
|
|
565
|
+
constructor(block, callback) {
|
|
566
|
+
super("juo:block-wrapper-render", {
|
|
567
|
+
bubbles: true,
|
|
568
|
+
composed: true,
|
|
569
|
+
cancelable: true
|
|
570
|
+
});
|
|
571
|
+
this.block = block;
|
|
572
|
+
this.callback = callback;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function getDevtoolsState() {
|
|
576
|
+
const hook = getHook();
|
|
577
|
+
if (!hook) return null;
|
|
578
|
+
const holder = hook;
|
|
579
|
+
if (!holder.__blockDevtoolsState) {
|
|
580
|
+
holder.__blockDevtoolsState = {
|
|
581
|
+
instances: /* @__PURE__ */ new Map(),
|
|
582
|
+
propSetters: /* @__PURE__ */ new Map(),
|
|
583
|
+
propOverrides: /* @__PURE__ */ new Map()
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
return holder.__blockDevtoolsState;
|
|
587
|
+
}
|
|
588
|
+
function applyDevtoolsPropOverride(id, props) {
|
|
589
|
+
var _a;
|
|
590
|
+
const override = (_a = getDevtoolsState()) == null ? void 0 : _a.propOverrides.get(id);
|
|
591
|
+
return override ? { ...props, ...override } : props;
|
|
592
|
+
}
|
|
593
|
+
function __recordDevtoolsPropSetter(id, setProp) {
|
|
594
|
+
var _a;
|
|
595
|
+
(_a = getDevtoolsState()) == null ? void 0 : _a.propSetters.set(id, setProp);
|
|
596
|
+
}
|
|
597
|
+
function __recordDevtoolsInstance(inst) {
|
|
598
|
+
var _a;
|
|
599
|
+
(_a = getDevtoolsState()) == null ? void 0 : _a.instances.set(inst.id, {
|
|
600
|
+
type: inst.type,
|
|
601
|
+
props: inst.props,
|
|
602
|
+
el: inst.el
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function __clearDevtoolsBlockState(id) {
|
|
606
|
+
const state = getDevtoolsState();
|
|
607
|
+
if (!state) return;
|
|
608
|
+
state.instances.delete(id);
|
|
609
|
+
state.propSetters.delete(id);
|
|
610
|
+
state.propOverrides.delete(id);
|
|
611
|
+
}
|
|
612
|
+
function getDevtoolsPropsSchema(type) {
|
|
613
|
+
var _a;
|
|
614
|
+
const def = blockDefinitions.get(type);
|
|
615
|
+
const schema = def == null ? void 0 : def.schema;
|
|
616
|
+
const props = (_a = schema == null ? void 0 : schema.properties) == null ? void 0 : _a.props;
|
|
617
|
+
return props && typeof props === "object" ? props : null;
|
|
618
|
+
}
|
|
619
|
+
function getDevtoolsBlockState(id) {
|
|
620
|
+
var _a;
|
|
621
|
+
const inst = (_a = getDevtoolsState()) == null ? void 0 : _a.instances.get(id);
|
|
622
|
+
if (!inst) return null;
|
|
623
|
+
return {
|
|
624
|
+
props: applyDevtoolsPropOverride(id, inst.props),
|
|
625
|
+
propsSchema: getDevtoolsPropsSchema(inst.type)
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function setDevtoolsBlockProp(id, key, value) {
|
|
629
|
+
const state = getDevtoolsState();
|
|
630
|
+
const inst = state == null ? void 0 : state.instances.get(id);
|
|
631
|
+
if (!state || !inst) return null;
|
|
632
|
+
state.propOverrides.set(id, {
|
|
633
|
+
...state.propOverrides.get(id) ?? {},
|
|
634
|
+
[key]: value
|
|
635
|
+
});
|
|
636
|
+
const setter = state.propSetters.get(id);
|
|
637
|
+
if (setter) {
|
|
638
|
+
setter(key, value);
|
|
639
|
+
} else if (inst.el) {
|
|
640
|
+
inst.el[key] = value;
|
|
641
|
+
}
|
|
642
|
+
return { props: applyDevtoolsPropOverride(id, inst.props) };
|
|
643
|
+
}
|
|
644
|
+
function getDevtoolsBlockCatalog() {
|
|
645
|
+
const catalog = {};
|
|
646
|
+
for (const def of getDefinedBlocks()) {
|
|
647
|
+
catalog[def.name] = def.displayName ?? def.name;
|
|
648
|
+
}
|
|
649
|
+
return catalog;
|
|
650
|
+
}
|
|
651
|
+
function attachDevtoolsResolvers(hook) {
|
|
652
|
+
if (hook.resolvers) return;
|
|
653
|
+
hook.resolvers = {
|
|
654
|
+
getBlockState: getDevtoolsBlockState,
|
|
655
|
+
setBlockProp: setDevtoolsBlockProp,
|
|
656
|
+
getBlockCatalog: getDevtoolsBlockCatalog
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function withWrapper(fn) {
|
|
660
|
+
let wrapper = null;
|
|
661
|
+
return (block) => {
|
|
662
|
+
var _a;
|
|
663
|
+
let rendered;
|
|
664
|
+
try {
|
|
665
|
+
rendered = fn(block);
|
|
666
|
+
} catch (error) {
|
|
667
|
+
reportBlockError(error, {
|
|
668
|
+
site: "block.withWrapper",
|
|
669
|
+
block: { id: block.id, type: block.type, definition: block.definition },
|
|
670
|
+
keys: {
|
|
671
|
+
props: Object.keys(block.props ?? {}),
|
|
672
|
+
slots: Object.keys(block.slots ?? {})
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
rendered = createStubDefinition(block.type).render(block);
|
|
676
|
+
}
|
|
677
|
+
const devtoolsHook = getHook();
|
|
678
|
+
if (devtoolsHook) {
|
|
679
|
+
attachDevtoolsResolvers(devtoolsHook);
|
|
680
|
+
__recordDevtoolsInstance({
|
|
681
|
+
id: block.id,
|
|
682
|
+
type: block.type,
|
|
683
|
+
props: block.props ?? {},
|
|
684
|
+
el: rendered
|
|
685
|
+
});
|
|
686
|
+
devtoolsHook.emit("block:mounted", {
|
|
687
|
+
id: block.id,
|
|
688
|
+
type: block.type,
|
|
689
|
+
slot: null,
|
|
690
|
+
parentId: null,
|
|
691
|
+
propKeys: Object.keys(block.props ?? {})
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
if (wrapper === null) {
|
|
695
|
+
if (isEditorPreview()) {
|
|
696
|
+
wrapper = document.createElement(
|
|
697
|
+
layoutSystemEnabled.value ? "juo-editor-layout-block-wrapper" : "juo-editor-block-wrapper"
|
|
698
|
+
);
|
|
699
|
+
wrapper.setAttribute("data-block-id", block.id);
|
|
700
|
+
(_a = wrapper.setBlock) == null ? void 0 : _a.call(wrapper, block);
|
|
701
|
+
wrapper.appendChild(rendered);
|
|
702
|
+
} else {
|
|
703
|
+
const evt = new BlockWrapperEvent(block, (evtWrapper) => {
|
|
704
|
+
wrapper = evtWrapper;
|
|
705
|
+
});
|
|
706
|
+
document.dispatchEvent(evt);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (!wrapper) {
|
|
710
|
+
return rendered;
|
|
711
|
+
}
|
|
712
|
+
wrapper.replaceChildren(rendered);
|
|
713
|
+
return wrapper;
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
const registerBlockListeners = [];
|
|
717
|
+
function registerBlock(block) {
|
|
718
|
+
blockDefinitions.set(block.name, block);
|
|
719
|
+
stubDefinitionCache.delete(block.name);
|
|
720
|
+
registerBlockListeners.forEach((cb) => cb(block.name, block));
|
|
721
|
+
const regHook = getHook();
|
|
722
|
+
if (regHook) {
|
|
723
|
+
attachDevtoolsResolvers(regHook);
|
|
724
|
+
regHook.emit("block:registered", {
|
|
725
|
+
name: block.name,
|
|
726
|
+
group: block.group,
|
|
727
|
+
displayName: block.displayName ?? block.name
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
function onRegisterBlock(cb) {
|
|
732
|
+
registerBlockListeners.push(cb);
|
|
733
|
+
return () => {
|
|
734
|
+
const idx = registerBlockListeners.indexOf(cb);
|
|
735
|
+
if (idx >= 0) registerBlockListeners.splice(idx, 1);
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function defineBlock(name, opts) {
|
|
739
|
+
const definition = {
|
|
740
|
+
name,
|
|
741
|
+
displayName: opts.displayName,
|
|
742
|
+
group: opts.group,
|
|
743
|
+
schema: opts.schema,
|
|
744
|
+
initialValue: opts.initialValue,
|
|
745
|
+
render: opts.renderer,
|
|
746
|
+
presets: opts.presets,
|
|
747
|
+
locales: opts.locales
|
|
748
|
+
};
|
|
749
|
+
return definition;
|
|
750
|
+
}
|
|
751
|
+
function defineBlockRuntime(name, opts) {
|
|
752
|
+
const definition = {
|
|
753
|
+
name,
|
|
754
|
+
displayName: opts.displayName,
|
|
755
|
+
group: opts.group,
|
|
756
|
+
schema: {},
|
|
757
|
+
initialValue() {
|
|
758
|
+
throw new Error("Initial value cannot be called in runtime mode");
|
|
759
|
+
},
|
|
760
|
+
render: opts.renderer
|
|
761
|
+
};
|
|
762
|
+
return definition;
|
|
763
|
+
}
|
|
764
|
+
function getDefinedBlocks() {
|
|
765
|
+
return [...blockDefinitions.values()];
|
|
766
|
+
}
|
|
767
|
+
function createCeRenderer(name) {
|
|
768
|
+
function renderSlots(slots, block) {
|
|
769
|
+
if (!slots) {
|
|
770
|
+
return slots;
|
|
771
|
+
}
|
|
772
|
+
return Object.entries(slots).flatMap(([key, value]) => {
|
|
773
|
+
const values = Array.isArray(value) ? value : [value];
|
|
774
|
+
return values.flatMap((value2) => {
|
|
775
|
+
if (typeof value2 === "string") {
|
|
776
|
+
const el = document.createElement("span");
|
|
777
|
+
if (key !== "default") {
|
|
778
|
+
el.slot = key;
|
|
779
|
+
}
|
|
780
|
+
el.innerText = value2;
|
|
781
|
+
return [el];
|
|
782
|
+
}
|
|
783
|
+
try {
|
|
784
|
+
const el = value2.definition.render({
|
|
785
|
+
...value2,
|
|
786
|
+
props: {
|
|
787
|
+
...value2.props,
|
|
788
|
+
parentProps: block.props
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
if (key !== "default") {
|
|
792
|
+
el.slot = key;
|
|
793
|
+
}
|
|
794
|
+
return [el];
|
|
795
|
+
} catch (error) {
|
|
796
|
+
reportBlockError(error, {
|
|
797
|
+
site: "block.createCeRenderer.renderSlots",
|
|
798
|
+
block: { id: value2.id, type: value2.type, definition: value2.definition },
|
|
799
|
+
extra: {
|
|
800
|
+
parentBlockId: block.id,
|
|
801
|
+
parentBlockType: block.type,
|
|
802
|
+
slotKey: key
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
return [];
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
return (block) => {
|
|
811
|
+
const el = document.createElement(name);
|
|
812
|
+
el.setAttribute("data-block-id", block.id);
|
|
813
|
+
el.setAttribute("data-block-type", block.type);
|
|
814
|
+
Object.entries(applyDevtoolsPropOverride(block.id, block.props)).forEach(
|
|
815
|
+
([key, value]) => {
|
|
816
|
+
el[key] = value;
|
|
817
|
+
}
|
|
818
|
+
);
|
|
819
|
+
el.replaceChildren(...renderSlots(block.slots, block));
|
|
820
|
+
attachEmptyTracking(el);
|
|
821
|
+
return el;
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
const stubDefinitionCache = /* @__PURE__ */ new Map();
|
|
825
|
+
function createStubDefinition(name) {
|
|
826
|
+
const cached = stubDefinitionCache.get(name);
|
|
827
|
+
if (cached) return cached;
|
|
828
|
+
const stub = {
|
|
829
|
+
name,
|
|
830
|
+
group: "internal",
|
|
831
|
+
schema: {},
|
|
832
|
+
initialValue: { props: {}, slots: {} },
|
|
833
|
+
__stub: true,
|
|
834
|
+
render() {
|
|
835
|
+
const el = document.createElement("div");
|
|
836
|
+
el.dataset.stubBlock = name;
|
|
837
|
+
if (isEditorPreview()) {
|
|
838
|
+
el.textContent = `Block definition not found: ${name}`;
|
|
839
|
+
} else {
|
|
840
|
+
el.style.display = "none";
|
|
841
|
+
}
|
|
842
|
+
return el;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
stubDefinitionCache.set(name, stub);
|
|
846
|
+
reportBlockWarning(`Block definition '${name}' not found`, {
|
|
847
|
+
site: "block.createStubDefinition",
|
|
848
|
+
block: { id: "(none)", type: name }
|
|
849
|
+
});
|
|
850
|
+
console.warn(
|
|
851
|
+
`[juo/blocks] Block definition '${name}' not found. This block may have been removed or renamed. Rendering a hidden stub.`
|
|
852
|
+
);
|
|
853
|
+
return stub;
|
|
854
|
+
}
|
|
855
|
+
function isStubDefinition(definition) {
|
|
856
|
+
return definition.__stub === true;
|
|
857
|
+
}
|
|
858
|
+
function backfillInstanceDefaults(block) {
|
|
859
|
+
if (Object.keys(block.props ?? {}).length > 0) return false;
|
|
860
|
+
if (Object.keys(block.slots ?? {}).length > 0) return false;
|
|
861
|
+
if (isStubDefinition(block.definition)) return false;
|
|
862
|
+
let defaults;
|
|
863
|
+
try {
|
|
864
|
+
const iv = block.definition.initialValue;
|
|
865
|
+
defaults = (typeof iv === "function" ? iv() : iv) ?? {};
|
|
866
|
+
} catch (error) {
|
|
867
|
+
reportBlockError(error, {
|
|
868
|
+
site: "block.backfillInstanceDefaults",
|
|
869
|
+
block: { id: block.id, type: block.type, definition: block.definition }
|
|
870
|
+
});
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
const propsDefault = defaults.props ?? {};
|
|
874
|
+
const slotsDefault = defaults.slots ?? {};
|
|
875
|
+
const hasProps = Object.keys(propsDefault).length > 0;
|
|
876
|
+
const hasSlots = Object.keys(slotsDefault).length > 0;
|
|
877
|
+
if (!hasProps && !hasSlots) return false;
|
|
878
|
+
if (hasProps) Object.assign(block.props, propsDefault);
|
|
879
|
+
if (hasSlots) Object.assign(block.slots, slotsDefault);
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
882
|
+
function getDefinitionByName(name) {
|
|
883
|
+
const definition = blockDefinitions.get(name);
|
|
884
|
+
if (definition != null) {
|
|
885
|
+
return definition;
|
|
886
|
+
}
|
|
887
|
+
return createStubDefinition(name);
|
|
888
|
+
}
|
|
889
|
+
function createBlockInstance(name, opts) {
|
|
890
|
+
const initialValue = (() => {
|
|
891
|
+
const value = getDefinitionByName(name).initialValue ?? {};
|
|
892
|
+
if (typeof value === "function") {
|
|
893
|
+
return value();
|
|
894
|
+
}
|
|
895
|
+
return value;
|
|
896
|
+
})();
|
|
897
|
+
if ((opts == null ? void 0 : opts.props) == null && initialValue == null) {
|
|
898
|
+
const error = new Error(
|
|
899
|
+
`Block '${name}' cannot be created without value in runtime mode`
|
|
900
|
+
);
|
|
901
|
+
reportBlockError(error, {
|
|
902
|
+
site: "block.createBlockInstance",
|
|
903
|
+
block: { id: "(none)", type: name }
|
|
904
|
+
});
|
|
905
|
+
throw error;
|
|
906
|
+
}
|
|
907
|
+
const slots = {
|
|
908
|
+
...initialValue.slots,
|
|
909
|
+
...(opts == null ? void 0 : opts.slots) ?? {}
|
|
910
|
+
};
|
|
911
|
+
const props = {
|
|
912
|
+
...initialValue.props ?? {},
|
|
913
|
+
...(opts == null ? void 0 : opts.props) ?? {}
|
|
914
|
+
};
|
|
915
|
+
return {
|
|
916
|
+
// TODO: This should be unique
|
|
917
|
+
id: (opts == null ? void 0 : opts.id) ?? Math.round(1e3 * Math.random()).toString(10),
|
|
918
|
+
type: name,
|
|
919
|
+
props,
|
|
920
|
+
slots,
|
|
921
|
+
get definition() {
|
|
922
|
+
return getDefinitionByName(name);
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
function createBlockInstanceFromObject(input) {
|
|
927
|
+
const { id, type, props, slots } = input;
|
|
928
|
+
return createBlockInstance(type, {
|
|
929
|
+
props,
|
|
930
|
+
slots: Object.fromEntries(
|
|
931
|
+
Object.entries(slots).map(([key, value]) => [
|
|
932
|
+
key,
|
|
933
|
+
(Array.isArray(value) ? value : [value]).map(
|
|
934
|
+
(child) => createBlockInstanceFromObject(child)
|
|
935
|
+
)
|
|
936
|
+
])
|
|
937
|
+
),
|
|
938
|
+
id
|
|
939
|
+
});
|
|
940
|
+
}
|
|
941
|
+
function createBlockInstanceFromJSON(input) {
|
|
942
|
+
try {
|
|
943
|
+
return createBlockInstanceFromObject(JSON.parse(input));
|
|
944
|
+
} catch (error) {
|
|
945
|
+
reportBlockError(error, {
|
|
946
|
+
site: "block.createBlockInstanceFromJSON",
|
|
947
|
+
extra: { inputLength: input.length }
|
|
948
|
+
});
|
|
949
|
+
throw error;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
export {
|
|
953
|
+
createSelectedBlock as A,
|
|
954
|
+
BlockWrapperEvent as B,
|
|
955
|
+
ContextRoot as C,
|
|
956
|
+
defineBlockRuntime as D,
|
|
957
|
+
E,
|
|
958
|
+
getDevtoolsBlockState as F,
|
|
959
|
+
hasRenderedContent as G,
|
|
960
|
+
isEditorPreview as H,
|
|
961
|
+
layoutSystemEnabled as I,
|
|
962
|
+
provideContext as J,
|
|
963
|
+
setDevtoolsBlockProp as K,
|
|
964
|
+
n as L,
|
|
965
|
+
SelectedBlockContext as S,
|
|
966
|
+
__recordDevtoolsPropSetter as _,
|
|
967
|
+
applyDevtoolsPropOverride as a,
|
|
968
|
+
isStubDefinition as b,
|
|
969
|
+
backfillInstanceDefaults as c,
|
|
970
|
+
__clearDevtoolsBlockState as d,
|
|
971
|
+
createContext as e,
|
|
972
|
+
d as f,
|
|
973
|
+
createBlockInstanceFromObject as g,
|
|
974
|
+
createBlockInstance as h,
|
|
975
|
+
injectContext as i,
|
|
976
|
+
getDefinedBlocks as j,
|
|
977
|
+
serializeBlocks as k,
|
|
978
|
+
setLayoutSystemEnabled as l,
|
|
979
|
+
w as m,
|
|
980
|
+
defineBlock as n,
|
|
981
|
+
onRegisterBlock as o,
|
|
982
|
+
registerBlock as p,
|
|
983
|
+
ContextProvideEvent as q,
|
|
984
|
+
r,
|
|
985
|
+
subscribeContext as s,
|
|
986
|
+
ContextRequestEvent as t,
|
|
987
|
+
u,
|
|
988
|
+
__recordDevtoolsInstance as v,
|
|
989
|
+
withWrapper as w,
|
|
990
|
+
attachEmptyTracking as x,
|
|
991
|
+
createBlockInstanceFromJSON as y,
|
|
992
|
+
createCeRenderer as z
|
|
993
|
+
};
|