@juo/blocks 1.15.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-VhmfGB3N.js → block-DnhzyZ1H.js} +38 -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 +2429 -399
- 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/customer/adapter.d.ts +8 -0
- package/dist/services/customer/adapter.d.ts.map +1 -0
- package/dist/services/customer/customerService.d.ts +3 -2
- package/dist/services/customer/customerService.d.ts.map +1 -1
- package/dist/services/customer/index.d.ts +1 -0
- package/dist/services/customer/index.d.ts.map +1 -1
- package/dist/services/customer/types.d.ts +4 -1
- package/dist/services/customer/types.d.ts.map +1 -1
- package/dist/services/index.d.ts +4 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/login/adapter.d.ts +33 -0
- package/dist/services/login/adapter.d.ts.map +1 -0
- package/dist/services/login/index.d.ts +3 -1
- package/dist/services/login/index.d.ts.map +1 -1
- package/dist/services/login/loginService.d.ts +6 -2
- package/dist/services/login/loginService.d.ts.map +1 -1
- package/dist/services/order/adapter.d.ts +10 -0
- package/dist/services/order/adapter.d.ts.map +1 -0
- package/dist/services/order/index.d.ts +4 -0
- package/dist/services/order/index.d.ts.map +1 -0
- package/dist/services/order/orderService.d.ts +6 -0
- package/dist/services/order/orderService.d.ts.map +1 -0
- package/dist/services/order/orderService.test.d.ts +2 -0
- package/dist/services/order/orderService.test.d.ts.map +1 -0
- package/dist/services/{orders → order}/types.d.ts +3 -3
- package/dist/services/order/types.d.ts.map +1 -0
- package/dist/services/product/adapter.d.ts +27 -2
- package/dist/services/product/adapter.d.ts.map +1 -1
- package/dist/services/product/adapter.test.d.ts +2 -0
- package/dist/services/product/adapter.test.d.ts.map +1 -0
- package/dist/services/product/index.d.ts +1 -1
- package/dist/services/product/index.d.ts.map +1 -1
- package/dist/services/product/productService.d.ts.map +1 -1
- package/dist/services/product/types.d.ts +68 -0
- package/dist/services/product/types.d.ts.map +1 -1
- package/dist/services/schedules/adapter.d.ts +94 -0
- package/dist/services/schedules/adapter.d.ts.map +1 -0
- package/dist/services/schedules/adapter.test.d.ts +2 -0
- package/dist/services/schedules/adapter.test.d.ts.map +1 -0
- package/dist/services/schedules/apiSchedulesAdapter.test.d.ts +2 -0
- package/dist/services/schedules/apiSchedulesAdapter.test.d.ts.map +1 -0
- package/dist/services/schedules/index.d.ts +5 -0
- package/dist/services/schedules/index.d.ts.map +1 -0
- package/dist/services/schedules/schedulesService.d.ts +11 -0
- package/dist/services/schedules/schedulesService.d.ts.map +1 -0
- package/dist/services/schedules/schedulesService.test.d.ts +2 -0
- package/dist/services/schedules/schedulesService.test.d.ts.map +1 -0
- package/dist/services/schedules/types.d.ts +290 -0
- package/dist/services/schedules/types.d.ts.map +1 -0
- package/dist/services/settings/index.d.ts +3 -0
- package/dist/services/settings/index.d.ts.map +1 -0
- package/dist/services/settings/settingsService.d.ts +7 -0
- package/dist/services/settings/settingsService.d.ts.map +1 -0
- package/dist/services/settings/settingsService.test.d.ts +2 -0
- package/dist/services/settings/settingsService.test.d.ts.map +1 -0
- package/dist/services/settings/types.d.ts +35 -0
- package/dist/services/settings/types.d.ts.map +1 -0
- package/dist/services/shop/index.d.ts +3 -0
- package/dist/services/shop/index.d.ts.map +1 -0
- package/dist/services/shop/shopService.d.ts +12 -0
- package/dist/services/shop/shopService.d.ts.map +1 -0
- package/dist/services/shop/shopService.test.d.ts +2 -0
- package/dist/services/shop/shopService.test.d.ts.map +1 -0
- package/dist/services/shop/types.d.ts +7 -0
- package/dist/services/shop/types.d.ts.map +1 -0
- package/dist/services/subscription/adapter.d.ts +77 -2
- package/dist/services/subscription/adapter.d.ts.map +1 -1
- package/dist/services/subscription/adapter.test.d.ts +2 -0
- package/dist/services/subscription/adapter.test.d.ts.map +1 -0
- package/dist/services/subscription/index.d.ts +1 -1
- package/dist/services/subscription/index.d.ts.map +1 -1
- package/dist/services/subscription/subscriptionService.d.ts +1 -6
- package/dist/services/subscription/subscriptionService.d.ts.map +1 -1
- package/dist/services/subscription/types.d.ts +220 -9
- package/dist/services/subscription/types.d.ts.map +1 -1
- package/dist/services/subscription/types.test.d.ts +2 -0
- package/dist/services/subscription/types.test.d.ts.map +1 -0
- 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/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/vue/block.d.ts.map +1 -1
- package/dist/vue/context.d.ts +1 -0
- package/dist/vue/context.d.ts.map +1 -1
- package/dist/vue.js +28 -15
- 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 -8
- 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.map +0 -1
|
@@ -1,1570 +0,0 @@
|
|
|
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 { g as getInstrumentation, _ as __setDefinedBlocksReader } from "./index-JSv6UH_o.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
|
-
getInstrumentation().onContextProvided(context);
|
|
25
|
-
const ev = new ContextProvideEvent(context, init);
|
|
26
|
-
target.dispatchEvent(ev);
|
|
27
|
-
}
|
|
28
|
-
function injectContext(target, context) {
|
|
29
|
-
let value = void 0;
|
|
30
|
-
getInstrumentation().onContextRequested(context);
|
|
31
|
-
const ev = new ContextRequestEvent(context, (received) => {
|
|
32
|
-
value = received;
|
|
33
|
-
});
|
|
34
|
-
target.dispatchEvent(ev);
|
|
35
|
-
if (value === void 0) {
|
|
36
|
-
throw new Error(`Context '${context}' not defined`);
|
|
37
|
-
}
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
function subscribeContext(target, context, callback) {
|
|
41
|
-
let unsubscribeFunction = null;
|
|
42
|
-
getInstrumentation().onContextRequested(context);
|
|
43
|
-
const protocolCallback = (value, unsubscribe) => {
|
|
44
|
-
if (unsubscribe) {
|
|
45
|
-
unsubscribeFunction = unsubscribe;
|
|
46
|
-
}
|
|
47
|
-
callback(value);
|
|
48
|
-
};
|
|
49
|
-
const ev = new ContextRequestEvent(context, protocolCallback, true);
|
|
50
|
-
target.dispatchEvent(ev);
|
|
51
|
-
return () => {
|
|
52
|
-
if (unsubscribeFunction) {
|
|
53
|
-
unsubscribeFunction();
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
class ContextRoot extends HTMLElement {
|
|
58
|
-
constructor() {
|
|
59
|
-
super(...arguments);
|
|
60
|
-
__publicField(this, "store", /* @__PURE__ */ new Map());
|
|
61
|
-
__publicField(this, "callbacks", /* @__PURE__ */ new Map());
|
|
62
|
-
}
|
|
63
|
-
connectedCallback() {
|
|
64
|
-
this.addEventListener("context-provide", (ev) => {
|
|
65
|
-
ev.stopPropagation();
|
|
66
|
-
this.store.set(ev.context, ev.value);
|
|
67
|
-
const registeredCallbacks = this.callbacks.get(ev.context) ?? [];
|
|
68
|
-
registeredCallbacks.forEach((cb) => {
|
|
69
|
-
const unsubscribe = () => {
|
|
70
|
-
const callbacks = this.callbacks.get(ev.context);
|
|
71
|
-
if (callbacks) {
|
|
72
|
-
const cbIndex = callbacks.indexOf(cb);
|
|
73
|
-
if (cbIndex > -1) {
|
|
74
|
-
callbacks.splice(cbIndex, 1);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
cb(ev.value, unsubscribe);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
this.addEventListener("context-request", (ev) => {
|
|
82
|
-
ev.stopPropagation();
|
|
83
|
-
const storedValue = this.store.get(ev.context);
|
|
84
|
-
if (ev.subscribe) {
|
|
85
|
-
let callbacks = this.callbacks.get(ev.context);
|
|
86
|
-
if (!callbacks) {
|
|
87
|
-
callbacks = [];
|
|
88
|
-
this.callbacks.set(ev.context, callbacks);
|
|
89
|
-
}
|
|
90
|
-
const unsubscribe = () => {
|
|
91
|
-
const currentCallbacks = this.callbacks.get(ev.context);
|
|
92
|
-
if (currentCallbacks) {
|
|
93
|
-
const index = currentCallbacks.indexOf(ev.callback);
|
|
94
|
-
if (index > -1) {
|
|
95
|
-
currentCallbacks.splice(index, 1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
callbacks.push(ev.callback);
|
|
100
|
-
if (storedValue !== void 0) {
|
|
101
|
-
ev.callback(storedValue, unsubscribe);
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
if (storedValue !== void 0) {
|
|
105
|
-
ev.callback(storedValue);
|
|
106
|
-
} else {
|
|
107
|
-
console.warn("Context not present in store: " + String(ev.context));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
var i = Symbol.for("preact-signals");
|
|
114
|
-
function t() {
|
|
115
|
-
if (!(s > 1)) {
|
|
116
|
-
var i2, t2 = false;
|
|
117
|
-
while (void 0 !== h) {
|
|
118
|
-
var r2 = h;
|
|
119
|
-
h = void 0;
|
|
120
|
-
f++;
|
|
121
|
-
while (void 0 !== r2) {
|
|
122
|
-
var o2 = r2.o;
|
|
123
|
-
r2.o = void 0;
|
|
124
|
-
r2.f &= -3;
|
|
125
|
-
if (!(8 & r2.f) && c(r2)) try {
|
|
126
|
-
r2.c();
|
|
127
|
-
} catch (r3) {
|
|
128
|
-
if (!t2) {
|
|
129
|
-
i2 = r3;
|
|
130
|
-
t2 = true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
r2 = o2;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
f = 0;
|
|
137
|
-
s--;
|
|
138
|
-
if (t2) throw i2;
|
|
139
|
-
} else s--;
|
|
140
|
-
}
|
|
141
|
-
function r(i2) {
|
|
142
|
-
if (s > 0) return i2();
|
|
143
|
-
s++;
|
|
144
|
-
try {
|
|
145
|
-
return i2();
|
|
146
|
-
} finally {
|
|
147
|
-
t();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
var o = void 0;
|
|
151
|
-
function n(i2) {
|
|
152
|
-
var t2 = o;
|
|
153
|
-
o = void 0;
|
|
154
|
-
try {
|
|
155
|
-
return i2();
|
|
156
|
-
} finally {
|
|
157
|
-
o = t2;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
var h = void 0, s = 0, f = 0, v = 0;
|
|
161
|
-
function e(i2) {
|
|
162
|
-
if (void 0 !== o) {
|
|
163
|
-
var t2 = i2.n;
|
|
164
|
-
if (void 0 === t2 || t2.t !== o) {
|
|
165
|
-
t2 = { i: 0, S: i2, p: o.s, n: void 0, t: o, e: void 0, x: void 0, r: t2 };
|
|
166
|
-
if (void 0 !== o.s) o.s.n = t2;
|
|
167
|
-
o.s = t2;
|
|
168
|
-
i2.n = t2;
|
|
169
|
-
if (32 & o.f) i2.S(t2);
|
|
170
|
-
return t2;
|
|
171
|
-
} else if (-1 === t2.i) {
|
|
172
|
-
t2.i = 0;
|
|
173
|
-
if (void 0 !== t2.n) {
|
|
174
|
-
t2.n.p = t2.p;
|
|
175
|
-
if (void 0 !== t2.p) t2.p.n = t2.n;
|
|
176
|
-
t2.p = o.s;
|
|
177
|
-
t2.n = void 0;
|
|
178
|
-
o.s.n = t2;
|
|
179
|
-
o.s = t2;
|
|
180
|
-
}
|
|
181
|
-
return t2;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function u(i2, t2) {
|
|
186
|
-
this.v = i2;
|
|
187
|
-
this.i = 0;
|
|
188
|
-
this.n = void 0;
|
|
189
|
-
this.t = void 0;
|
|
190
|
-
this.W = null == t2 ? void 0 : t2.watched;
|
|
191
|
-
this.Z = null == t2 ? void 0 : t2.unwatched;
|
|
192
|
-
}
|
|
193
|
-
u.prototype.brand = i;
|
|
194
|
-
u.prototype.h = function() {
|
|
195
|
-
return true;
|
|
196
|
-
};
|
|
197
|
-
u.prototype.S = function(i2) {
|
|
198
|
-
var t2 = this, r2 = this.t;
|
|
199
|
-
if (r2 !== i2 && void 0 === i2.e) {
|
|
200
|
-
i2.x = r2;
|
|
201
|
-
this.t = i2;
|
|
202
|
-
if (void 0 !== r2) r2.e = i2;
|
|
203
|
-
else n(function() {
|
|
204
|
-
var i3;
|
|
205
|
-
null == (i3 = t2.W) || i3.call(t2);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
u.prototype.U = function(i2) {
|
|
210
|
-
var t2 = this;
|
|
211
|
-
if (void 0 !== this.t) {
|
|
212
|
-
var r2 = i2.e, o2 = i2.x;
|
|
213
|
-
if (void 0 !== r2) {
|
|
214
|
-
r2.x = o2;
|
|
215
|
-
i2.e = void 0;
|
|
216
|
-
}
|
|
217
|
-
if (void 0 !== o2) {
|
|
218
|
-
o2.e = r2;
|
|
219
|
-
i2.x = void 0;
|
|
220
|
-
}
|
|
221
|
-
if (i2 === this.t) {
|
|
222
|
-
this.t = o2;
|
|
223
|
-
if (void 0 === o2) n(function() {
|
|
224
|
-
var i3;
|
|
225
|
-
null == (i3 = t2.Z) || i3.call(t2);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
u.prototype.subscribe = function(i2) {
|
|
231
|
-
var t2 = this;
|
|
232
|
-
return E(function() {
|
|
233
|
-
var r2 = t2.value, n2 = o;
|
|
234
|
-
o = void 0;
|
|
235
|
-
try {
|
|
236
|
-
i2(r2);
|
|
237
|
-
} finally {
|
|
238
|
-
o = n2;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
u.prototype.valueOf = function() {
|
|
243
|
-
return this.value;
|
|
244
|
-
};
|
|
245
|
-
u.prototype.toString = function() {
|
|
246
|
-
return this.value + "";
|
|
247
|
-
};
|
|
248
|
-
u.prototype.toJSON = function() {
|
|
249
|
-
return this.value;
|
|
250
|
-
};
|
|
251
|
-
u.prototype.peek = function() {
|
|
252
|
-
var i2 = o;
|
|
253
|
-
o = void 0;
|
|
254
|
-
try {
|
|
255
|
-
return this.value;
|
|
256
|
-
} finally {
|
|
257
|
-
o = i2;
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
Object.defineProperty(u.prototype, "value", { get: function() {
|
|
261
|
-
var i2 = e(this);
|
|
262
|
-
if (void 0 !== i2) i2.i = this.i;
|
|
263
|
-
return this.v;
|
|
264
|
-
}, set: function(i2) {
|
|
265
|
-
if (i2 !== this.v) {
|
|
266
|
-
if (f > 100) throw new Error("Cycle detected");
|
|
267
|
-
this.v = i2;
|
|
268
|
-
this.i++;
|
|
269
|
-
v++;
|
|
270
|
-
s++;
|
|
271
|
-
try {
|
|
272
|
-
for (var r2 = this.t; void 0 !== r2; r2 = r2.x) r2.t.N();
|
|
273
|
-
} finally {
|
|
274
|
-
t();
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
} });
|
|
278
|
-
function d(i2, t2) {
|
|
279
|
-
return new u(i2, t2);
|
|
280
|
-
}
|
|
281
|
-
function c(i2) {
|
|
282
|
-
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;
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
function a(i2) {
|
|
286
|
-
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) {
|
|
287
|
-
var r2 = t2.S.n;
|
|
288
|
-
if (void 0 !== r2) t2.r = r2;
|
|
289
|
-
t2.S.n = t2;
|
|
290
|
-
t2.i = -1;
|
|
291
|
-
if (void 0 === t2.n) {
|
|
292
|
-
i2.s = t2;
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function l(i2) {
|
|
298
|
-
var t2 = i2.s, r2 = void 0;
|
|
299
|
-
while (void 0 !== t2) {
|
|
300
|
-
var o2 = t2.p;
|
|
301
|
-
if (-1 === t2.i) {
|
|
302
|
-
t2.S.U(t2);
|
|
303
|
-
if (void 0 !== o2) o2.n = t2.n;
|
|
304
|
-
if (void 0 !== t2.n) t2.n.p = o2;
|
|
305
|
-
} else r2 = t2;
|
|
306
|
-
t2.S.n = t2.r;
|
|
307
|
-
if (void 0 !== t2.r) t2.r = void 0;
|
|
308
|
-
t2 = o2;
|
|
309
|
-
}
|
|
310
|
-
i2.s = r2;
|
|
311
|
-
}
|
|
312
|
-
function y(i2, t2) {
|
|
313
|
-
u.call(this, void 0);
|
|
314
|
-
this.x = i2;
|
|
315
|
-
this.s = void 0;
|
|
316
|
-
this.g = v - 1;
|
|
317
|
-
this.f = 4;
|
|
318
|
-
this.W = null == t2 ? void 0 : t2.watched;
|
|
319
|
-
this.Z = null == t2 ? void 0 : t2.unwatched;
|
|
320
|
-
}
|
|
321
|
-
y.prototype = new u();
|
|
322
|
-
y.prototype.h = function() {
|
|
323
|
-
this.f &= -3;
|
|
324
|
-
if (1 & this.f) return false;
|
|
325
|
-
if (32 == (36 & this.f)) return true;
|
|
326
|
-
this.f &= -5;
|
|
327
|
-
if (this.g === v) return true;
|
|
328
|
-
this.g = v;
|
|
329
|
-
this.f |= 1;
|
|
330
|
-
if (this.i > 0 && !c(this)) {
|
|
331
|
-
this.f &= -2;
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
var i2 = o;
|
|
335
|
-
try {
|
|
336
|
-
a(this);
|
|
337
|
-
o = this;
|
|
338
|
-
var t2 = this.x();
|
|
339
|
-
if (16 & this.f || this.v !== t2 || 0 === this.i) {
|
|
340
|
-
this.v = t2;
|
|
341
|
-
this.f &= -17;
|
|
342
|
-
this.i++;
|
|
343
|
-
}
|
|
344
|
-
} catch (i3) {
|
|
345
|
-
this.v = i3;
|
|
346
|
-
this.f |= 16;
|
|
347
|
-
this.i++;
|
|
348
|
-
}
|
|
349
|
-
o = i2;
|
|
350
|
-
l(this);
|
|
351
|
-
this.f &= -2;
|
|
352
|
-
return true;
|
|
353
|
-
};
|
|
354
|
-
y.prototype.S = function(i2) {
|
|
355
|
-
if (void 0 === this.t) {
|
|
356
|
-
this.f |= 36;
|
|
357
|
-
for (var t2 = this.s; void 0 !== t2; t2 = t2.n) t2.S.S(t2);
|
|
358
|
-
}
|
|
359
|
-
u.prototype.S.call(this, i2);
|
|
360
|
-
};
|
|
361
|
-
y.prototype.U = function(i2) {
|
|
362
|
-
if (void 0 !== this.t) {
|
|
363
|
-
u.prototype.U.call(this, i2);
|
|
364
|
-
if (void 0 === this.t) {
|
|
365
|
-
this.f &= -33;
|
|
366
|
-
for (var t2 = this.s; void 0 !== t2; t2 = t2.n) t2.S.U(t2);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
y.prototype.N = function() {
|
|
371
|
-
if (!(2 & this.f)) {
|
|
372
|
-
this.f |= 6;
|
|
373
|
-
for (var i2 = this.t; void 0 !== i2; i2 = i2.x) i2.t.N();
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
Object.defineProperty(y.prototype, "value", { get: function() {
|
|
377
|
-
if (1 & this.f) throw new Error("Cycle detected");
|
|
378
|
-
var i2 = e(this);
|
|
379
|
-
this.h();
|
|
380
|
-
if (void 0 !== i2) i2.i = this.i;
|
|
381
|
-
if (16 & this.f) throw this.v;
|
|
382
|
-
return this.v;
|
|
383
|
-
} });
|
|
384
|
-
function w(i2, t2) {
|
|
385
|
-
return new y(i2, t2);
|
|
386
|
-
}
|
|
387
|
-
function _(i2) {
|
|
388
|
-
var r2 = i2.u;
|
|
389
|
-
i2.u = void 0;
|
|
390
|
-
if ("function" == typeof r2) {
|
|
391
|
-
s++;
|
|
392
|
-
var n2 = o;
|
|
393
|
-
o = void 0;
|
|
394
|
-
try {
|
|
395
|
-
r2();
|
|
396
|
-
} catch (t2) {
|
|
397
|
-
i2.f &= -2;
|
|
398
|
-
i2.f |= 8;
|
|
399
|
-
b(i2);
|
|
400
|
-
throw t2;
|
|
401
|
-
} finally {
|
|
402
|
-
o = n2;
|
|
403
|
-
t();
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
function b(i2) {
|
|
408
|
-
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n) t2.S.U(t2);
|
|
409
|
-
i2.x = void 0;
|
|
410
|
-
i2.s = void 0;
|
|
411
|
-
_(i2);
|
|
412
|
-
}
|
|
413
|
-
function g(i2) {
|
|
414
|
-
if (o !== this) throw new Error("Out-of-order effect");
|
|
415
|
-
l(this);
|
|
416
|
-
o = i2;
|
|
417
|
-
this.f &= -2;
|
|
418
|
-
if (8 & this.f) b(this);
|
|
419
|
-
t();
|
|
420
|
-
}
|
|
421
|
-
function p(i2) {
|
|
422
|
-
this.x = i2;
|
|
423
|
-
this.u = void 0;
|
|
424
|
-
this.s = void 0;
|
|
425
|
-
this.o = void 0;
|
|
426
|
-
this.f = 32;
|
|
427
|
-
}
|
|
428
|
-
p.prototype.c = function() {
|
|
429
|
-
var i2 = this.S();
|
|
430
|
-
try {
|
|
431
|
-
if (8 & this.f) return;
|
|
432
|
-
if (void 0 === this.x) return;
|
|
433
|
-
var t2 = this.x();
|
|
434
|
-
if ("function" == typeof t2) this.u = t2;
|
|
435
|
-
} finally {
|
|
436
|
-
i2();
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
p.prototype.S = function() {
|
|
440
|
-
if (1 & this.f) throw new Error("Cycle detected");
|
|
441
|
-
this.f |= 1;
|
|
442
|
-
this.f &= -9;
|
|
443
|
-
_(this);
|
|
444
|
-
a(this);
|
|
445
|
-
s++;
|
|
446
|
-
var i2 = o;
|
|
447
|
-
o = this;
|
|
448
|
-
return g.bind(this, i2);
|
|
449
|
-
};
|
|
450
|
-
p.prototype.N = function() {
|
|
451
|
-
if (!(2 & this.f)) {
|
|
452
|
-
this.f |= 2;
|
|
453
|
-
this.o = h;
|
|
454
|
-
h = this;
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
p.prototype.d = function() {
|
|
458
|
-
this.f |= 8;
|
|
459
|
-
if (!(1 & this.f)) b(this);
|
|
460
|
-
};
|
|
461
|
-
p.prototype.dispose = function() {
|
|
462
|
-
this.d();
|
|
463
|
-
};
|
|
464
|
-
function E(i2) {
|
|
465
|
-
var t2 = new p(i2);
|
|
466
|
-
try {
|
|
467
|
-
t2.c();
|
|
468
|
-
} catch (i3) {
|
|
469
|
-
t2.d();
|
|
470
|
-
throw i3;
|
|
471
|
-
}
|
|
472
|
-
var r2 = t2.d.bind(t2);
|
|
473
|
-
r2[Symbol.dispose] = r2;
|
|
474
|
-
return r2;
|
|
475
|
-
}
|
|
476
|
-
function isEditorPreview() {
|
|
477
|
-
if (typeof window === "undefined") return false;
|
|
478
|
-
return new URLSearchParams(window.location.search).get("editor") === "true";
|
|
479
|
-
}
|
|
480
|
-
const layoutSystemEnabled = d(false);
|
|
481
|
-
function setLayoutSystemEnabled(enabled) {
|
|
482
|
-
if (layoutSystemEnabled.peek() === enabled) return;
|
|
483
|
-
layoutSystemEnabled.value = enabled;
|
|
484
|
-
}
|
|
485
|
-
function hasRenderedContent(scope) {
|
|
486
|
-
var _a;
|
|
487
|
-
for (const child of scope.children) {
|
|
488
|
-
if (!(child instanceof HTMLElement)) {
|
|
489
|
-
continue;
|
|
490
|
-
}
|
|
491
|
-
const display = (_a = child.ownerDocument.defaultView) == null ? void 0 : _a.getComputedStyle(child).display;
|
|
492
|
-
if (display === "contents") {
|
|
493
|
-
if (hasRenderedContent(child)) {
|
|
494
|
-
return true;
|
|
495
|
-
}
|
|
496
|
-
continue;
|
|
497
|
-
}
|
|
498
|
-
if (child.checkVisibility()) {
|
|
499
|
-
return true;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
function attachEmptyTracking(host, scope) {
|
|
505
|
-
let observer = null;
|
|
506
|
-
let disposed = false;
|
|
507
|
-
queueMicrotask(() => {
|
|
508
|
-
if (disposed) return;
|
|
509
|
-
const observed = scope ?? host.shadowRoot ?? host;
|
|
510
|
-
const sync = () => host.toggleAttribute("data-empty", !hasRenderedContent(observed));
|
|
511
|
-
observer = new MutationObserver(sync);
|
|
512
|
-
observer.observe(observed, { childList: true, subtree: true });
|
|
513
|
-
sync();
|
|
514
|
-
});
|
|
515
|
-
return () => {
|
|
516
|
-
disposed = true;
|
|
517
|
-
observer == null ? void 0 : observer.disconnect();
|
|
518
|
-
observer = null;
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
function serializeBlocks(blocks) {
|
|
522
|
-
return blocks.map((block) => serializeBlock(block));
|
|
523
|
-
}
|
|
524
|
-
function serializeBlock(block) {
|
|
525
|
-
return {
|
|
526
|
-
id: block.id,
|
|
527
|
-
type: block.type,
|
|
528
|
-
props: JSON.parse(JSON.stringify(block.props)),
|
|
529
|
-
slots: Object.fromEntries(
|
|
530
|
-
Object.entries(block.slots ?? {}).map(([key, value]) => [
|
|
531
|
-
key,
|
|
532
|
-
Array.isArray(value) ? value.map(
|
|
533
|
-
(v2) => typeof v2 === "string" ? v2 : serializeBlock(v2)
|
|
534
|
-
) : typeof value === "string" ? value : serializeBlock(value)
|
|
535
|
-
])
|
|
536
|
-
)
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
function createSelectedBlock() {
|
|
540
|
-
const selected = d(null);
|
|
541
|
-
function setSelection(block) {
|
|
542
|
-
selected.value = null;
|
|
543
|
-
selected.value = block;
|
|
544
|
-
}
|
|
545
|
-
function clearSelection(block) {
|
|
546
|
-
var _a;
|
|
547
|
-
if (block == null || ((_a = selected.value) == null ? void 0 : _a.id) === block.id) {
|
|
548
|
-
selected.value = null;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
return { selected, setSelection, clearSelection };
|
|
552
|
-
}
|
|
553
|
-
const SelectedBlockContext = createContext("selectedBlock");
|
|
554
|
-
const blockDefinitions = (() => {
|
|
555
|
-
if (typeof window !== "undefined") {
|
|
556
|
-
window._juoBlocks = window._juoBlocks || /* @__PURE__ */ new Map();
|
|
557
|
-
return window._juoBlocks;
|
|
558
|
-
}
|
|
559
|
-
return /* @__PURE__ */ new Map();
|
|
560
|
-
})();
|
|
561
|
-
class BlockWrapperEvent extends Event {
|
|
562
|
-
constructor(block, callback) {
|
|
563
|
-
super("juo:block-wrapper-render", {
|
|
564
|
-
bubbles: true,
|
|
565
|
-
composed: true,
|
|
566
|
-
cancelable: true
|
|
567
|
-
});
|
|
568
|
-
this.block = block;
|
|
569
|
-
this.callback = callback;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
function withWrapper(fn) {
|
|
573
|
-
let wrapper = null;
|
|
574
|
-
return (block) => {
|
|
575
|
-
var _a;
|
|
576
|
-
let rendered;
|
|
577
|
-
try {
|
|
578
|
-
rendered = fn(block);
|
|
579
|
-
} catch (error) {
|
|
580
|
-
reportBlockError(error, {
|
|
581
|
-
site: "block.withWrapper",
|
|
582
|
-
block: { id: block.id, type: block.type, definition: block.definition },
|
|
583
|
-
keys: {
|
|
584
|
-
props: Object.keys(block.props ?? {}),
|
|
585
|
-
slots: Object.keys(block.slots ?? {})
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
rendered = createStubDefinition(block.type).render(block);
|
|
589
|
-
}
|
|
590
|
-
getInstrumentation().onBlockRendered(block, rendered);
|
|
591
|
-
if (wrapper === null) {
|
|
592
|
-
if (isEditorPreview()) {
|
|
593
|
-
wrapper = document.createElement(
|
|
594
|
-
layoutSystemEnabled.value ? "juo-editor-layout-block-wrapper" : "juo-editor-block-wrapper"
|
|
595
|
-
);
|
|
596
|
-
wrapper.setAttribute("data-block-id", block.id);
|
|
597
|
-
(_a = wrapper.setBlock) == null ? void 0 : _a.call(wrapper, block);
|
|
598
|
-
wrapper.appendChild(rendered);
|
|
599
|
-
} else {
|
|
600
|
-
const evt = new BlockWrapperEvent(block, (evtWrapper) => {
|
|
601
|
-
wrapper = evtWrapper;
|
|
602
|
-
});
|
|
603
|
-
document.dispatchEvent(evt);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
if (!wrapper) {
|
|
607
|
-
return rendered;
|
|
608
|
-
}
|
|
609
|
-
wrapper.replaceChildren(rendered);
|
|
610
|
-
return wrapper;
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
const registerBlockListeners = [];
|
|
614
|
-
function registerBlock(block) {
|
|
615
|
-
blockDefinitions.set(block.name, block);
|
|
616
|
-
stubDefinitionCache.delete(block.name);
|
|
617
|
-
registerBlockListeners.forEach((cb) => cb(block.name, block));
|
|
618
|
-
getInstrumentation().onBlockRegistered(block);
|
|
619
|
-
}
|
|
620
|
-
function onRegisterBlock(cb) {
|
|
621
|
-
registerBlockListeners.push(cb);
|
|
622
|
-
return () => {
|
|
623
|
-
const idx = registerBlockListeners.indexOf(cb);
|
|
624
|
-
if (idx >= 0) registerBlockListeners.splice(idx, 1);
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function defineBlock(name, opts) {
|
|
628
|
-
const definition = {
|
|
629
|
-
name,
|
|
630
|
-
displayName: opts.displayName,
|
|
631
|
-
group: opts.group,
|
|
632
|
-
schema: opts.schema,
|
|
633
|
-
initialValue: opts.initialValue,
|
|
634
|
-
render: opts.renderer,
|
|
635
|
-
presets: opts.presets,
|
|
636
|
-
locales: opts.locales
|
|
637
|
-
};
|
|
638
|
-
return definition;
|
|
639
|
-
}
|
|
640
|
-
function defineBlockRuntime(name, opts) {
|
|
641
|
-
const definition = {
|
|
642
|
-
name,
|
|
643
|
-
displayName: opts.displayName,
|
|
644
|
-
group: opts.group,
|
|
645
|
-
schema: {},
|
|
646
|
-
initialValue() {
|
|
647
|
-
throw new Error("Initial value cannot be called in runtime mode");
|
|
648
|
-
},
|
|
649
|
-
render: opts.renderer
|
|
650
|
-
};
|
|
651
|
-
return definition;
|
|
652
|
-
}
|
|
653
|
-
function getDefinedBlocks() {
|
|
654
|
-
return [...blockDefinitions.values()];
|
|
655
|
-
}
|
|
656
|
-
__setDefinedBlocksReader(getDefinedBlocks);
|
|
657
|
-
function createCeRenderer(name) {
|
|
658
|
-
function renderSlots(slots, block) {
|
|
659
|
-
if (!slots) {
|
|
660
|
-
return slots;
|
|
661
|
-
}
|
|
662
|
-
return Object.entries(slots).flatMap(([key, value]) => {
|
|
663
|
-
const values = Array.isArray(value) ? value : [value];
|
|
664
|
-
return values.flatMap((value2) => {
|
|
665
|
-
if (typeof value2 === "string") {
|
|
666
|
-
const el = document.createElement("span");
|
|
667
|
-
if (key !== "default") {
|
|
668
|
-
el.slot = key;
|
|
669
|
-
}
|
|
670
|
-
el.innerText = value2;
|
|
671
|
-
return [el];
|
|
672
|
-
}
|
|
673
|
-
try {
|
|
674
|
-
const el = value2.definition.render({
|
|
675
|
-
...value2,
|
|
676
|
-
props: {
|
|
677
|
-
...value2.props,
|
|
678
|
-
parentProps: block.props
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
if (key !== "default") {
|
|
682
|
-
el.slot = key;
|
|
683
|
-
}
|
|
684
|
-
return [el];
|
|
685
|
-
} catch (error) {
|
|
686
|
-
reportBlockError(error, {
|
|
687
|
-
site: "block.createCeRenderer.renderSlots",
|
|
688
|
-
block: { id: value2.id, type: value2.type, definition: value2.definition },
|
|
689
|
-
extra: {
|
|
690
|
-
parentBlockId: block.id,
|
|
691
|
-
parentBlockType: block.type,
|
|
692
|
-
slotKey: key
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
return [];
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
return (block) => {
|
|
701
|
-
const el = document.createElement(name);
|
|
702
|
-
el.setAttribute("data-block-id", block.id);
|
|
703
|
-
el.setAttribute("data-block-type", block.type);
|
|
704
|
-
Object.entries(getInstrumentation().resolveProps(block)).forEach(
|
|
705
|
-
([key, value]) => {
|
|
706
|
-
el[key] = value;
|
|
707
|
-
}
|
|
708
|
-
);
|
|
709
|
-
el.replaceChildren(...renderSlots(block.slots, block));
|
|
710
|
-
attachEmptyTracking(el);
|
|
711
|
-
return el;
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
const stubDefinitionCache = /* @__PURE__ */ new Map();
|
|
715
|
-
function createStubDefinition(name) {
|
|
716
|
-
const cached = stubDefinitionCache.get(name);
|
|
717
|
-
if (cached) return cached;
|
|
718
|
-
const stub = {
|
|
719
|
-
name,
|
|
720
|
-
group: "internal",
|
|
721
|
-
schema: {},
|
|
722
|
-
initialValue: { props: {}, slots: {} },
|
|
723
|
-
__stub: true,
|
|
724
|
-
render() {
|
|
725
|
-
const el = document.createElement("div");
|
|
726
|
-
el.dataset.stubBlock = name;
|
|
727
|
-
if (isEditorPreview()) {
|
|
728
|
-
el.textContent = `Block definition not found: ${name}`;
|
|
729
|
-
} else {
|
|
730
|
-
el.style.display = "none";
|
|
731
|
-
}
|
|
732
|
-
return el;
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
stubDefinitionCache.set(name, stub);
|
|
736
|
-
reportBlockWarning(`Block definition '${name}' not found`, {
|
|
737
|
-
site: "block.createStubDefinition",
|
|
738
|
-
block: { id: "(none)", type: name }
|
|
739
|
-
});
|
|
740
|
-
console.warn(
|
|
741
|
-
`[juo/blocks] Block definition '${name}' not found. This block may have been removed or renamed. Rendering a hidden stub.`
|
|
742
|
-
);
|
|
743
|
-
return stub;
|
|
744
|
-
}
|
|
745
|
-
function isStubDefinition(definition) {
|
|
746
|
-
return definition.__stub === true;
|
|
747
|
-
}
|
|
748
|
-
function backfillInstanceDefaults(block) {
|
|
749
|
-
if (Object.keys(block.props ?? {}).length > 0) return false;
|
|
750
|
-
if (Object.keys(block.slots ?? {}).length > 0) return false;
|
|
751
|
-
if (isStubDefinition(block.definition)) return false;
|
|
752
|
-
let defaults;
|
|
753
|
-
try {
|
|
754
|
-
const iv = block.definition.initialValue;
|
|
755
|
-
defaults = (typeof iv === "function" ? iv() : iv) ?? {};
|
|
756
|
-
} catch (error) {
|
|
757
|
-
reportBlockError(error, {
|
|
758
|
-
site: "block.backfillInstanceDefaults",
|
|
759
|
-
block: { id: block.id, type: block.type, definition: block.definition }
|
|
760
|
-
});
|
|
761
|
-
return false;
|
|
762
|
-
}
|
|
763
|
-
const propsDefault = defaults.props ?? {};
|
|
764
|
-
const slotsDefault = defaults.slots ?? {};
|
|
765
|
-
const hasProps = Object.keys(propsDefault).length > 0;
|
|
766
|
-
const hasSlots = Object.keys(slotsDefault).length > 0;
|
|
767
|
-
if (!hasProps && !hasSlots) return false;
|
|
768
|
-
if (hasProps) Object.assign(block.props, propsDefault);
|
|
769
|
-
if (hasSlots) Object.assign(block.slots, slotsDefault);
|
|
770
|
-
return true;
|
|
771
|
-
}
|
|
772
|
-
function getDefinitionByName(name) {
|
|
773
|
-
const definition = blockDefinitions.get(name);
|
|
774
|
-
if (definition != null) {
|
|
775
|
-
return definition;
|
|
776
|
-
}
|
|
777
|
-
return createStubDefinition(name);
|
|
778
|
-
}
|
|
779
|
-
function createBlockInstance(name, opts) {
|
|
780
|
-
const initialValue = (() => {
|
|
781
|
-
const value = getDefinitionByName(name).initialValue ?? {};
|
|
782
|
-
if (typeof value === "function") {
|
|
783
|
-
return value();
|
|
784
|
-
}
|
|
785
|
-
return value;
|
|
786
|
-
})();
|
|
787
|
-
if ((opts == null ? void 0 : opts.props) == null && initialValue == null) {
|
|
788
|
-
const error = new Error(
|
|
789
|
-
`Block '${name}' cannot be created without value in runtime mode`
|
|
790
|
-
);
|
|
791
|
-
reportBlockError(error, {
|
|
792
|
-
site: "block.createBlockInstance",
|
|
793
|
-
block: { id: "(none)", type: name }
|
|
794
|
-
});
|
|
795
|
-
throw error;
|
|
796
|
-
}
|
|
797
|
-
const slots = {
|
|
798
|
-
...initialValue.slots,
|
|
799
|
-
...(opts == null ? void 0 : opts.slots) ?? {}
|
|
800
|
-
};
|
|
801
|
-
const props = {
|
|
802
|
-
...initialValue.props ?? {},
|
|
803
|
-
...(opts == null ? void 0 : opts.props) ?? {}
|
|
804
|
-
};
|
|
805
|
-
return {
|
|
806
|
-
// TODO: This should be unique
|
|
807
|
-
id: (opts == null ? void 0 : opts.id) ?? Math.round(1e3 * Math.random()).toString(10),
|
|
808
|
-
type: name,
|
|
809
|
-
props,
|
|
810
|
-
slots,
|
|
811
|
-
get definition() {
|
|
812
|
-
return getDefinitionByName(name);
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
function createBlockInstanceFromObject(input) {
|
|
817
|
-
const { id, type, props, slots } = input;
|
|
818
|
-
return createBlockInstance(type, {
|
|
819
|
-
props,
|
|
820
|
-
slots: Object.fromEntries(
|
|
821
|
-
Object.entries(slots).map(([key, value]) => [
|
|
822
|
-
key,
|
|
823
|
-
(Array.isArray(value) ? value : [value]).map(
|
|
824
|
-
(child) => createBlockInstanceFromObject(child)
|
|
825
|
-
)
|
|
826
|
-
])
|
|
827
|
-
),
|
|
828
|
-
id
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
function createBlockInstanceFromJSON(input) {
|
|
832
|
-
try {
|
|
833
|
-
return createBlockInstanceFromObject(JSON.parse(input));
|
|
834
|
-
} catch (error) {
|
|
835
|
-
reportBlockError(error, {
|
|
836
|
-
site: "block.createBlockInstanceFromJSON",
|
|
837
|
-
extra: { inputLength: input.length }
|
|
838
|
-
});
|
|
839
|
-
throw error;
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
const DEFAULT_GLOBAL_STYLES = {
|
|
843
|
-
volume: "comfort",
|
|
844
|
-
style: "ghost",
|
|
845
|
-
corners: "round",
|
|
846
|
-
buttonCorners: "round",
|
|
847
|
-
thumbnailCorners: "circle",
|
|
848
|
-
theme: "preset",
|
|
849
|
-
themeType: "neutral",
|
|
850
|
-
colors: {
|
|
851
|
-
accent: "#000000",
|
|
852
|
-
secondary: "#000000",
|
|
853
|
-
tint: "#111111",
|
|
854
|
-
callout: "#F5F5F5",
|
|
855
|
-
success: "#287a25",
|
|
856
|
-
error: "#a93c3c",
|
|
857
|
-
information: "#0075a3",
|
|
858
|
-
warning: "#8a5e00",
|
|
859
|
-
background: "#FFFFFF"
|
|
860
|
-
}
|
|
861
|
-
};
|
|
862
|
-
const ThemeStateContext = createContext("theme-state");
|
|
863
|
-
function normalizeLocale(locale) {
|
|
864
|
-
return locale.trim().toLowerCase().split("-")[0] || "en";
|
|
865
|
-
}
|
|
866
|
-
function toStringRecord$1(input) {
|
|
867
|
-
if (input == null) return {};
|
|
868
|
-
return Object.fromEntries(
|
|
869
|
-
Object.entries(input).filter(([, value]) => typeof value === "string")
|
|
870
|
-
);
|
|
871
|
-
}
|
|
872
|
-
function parseBlockLocaleFile(file) {
|
|
873
|
-
if (file == null) {
|
|
874
|
-
return { defaults: {}, modes: {} };
|
|
875
|
-
}
|
|
876
|
-
const entries = Object.entries(file).filter(
|
|
877
|
-
([key, value]) => key !== "overrides" && typeof value === "string"
|
|
878
|
-
);
|
|
879
|
-
const topLevel = Object.fromEntries(entries);
|
|
880
|
-
const overrides = toStringRecord$1(file.overrides);
|
|
881
|
-
return {
|
|
882
|
-
defaults: { ...topLevel, ...overrides },
|
|
883
|
-
modes: {
|
|
884
|
-
...Object.fromEntries(
|
|
885
|
-
Object.keys(topLevel).map((key) => [key, "default"])
|
|
886
|
-
),
|
|
887
|
-
...Object.fromEntries(
|
|
888
|
-
Object.keys(overrides).map((key) => [key, "override"])
|
|
889
|
-
)
|
|
890
|
-
}
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
function indexOverrides(overrides) {
|
|
894
|
-
const indexed = {
|
|
895
|
-
theme: {},
|
|
896
|
-
blocks: {}
|
|
897
|
-
};
|
|
898
|
-
for (const item of overrides) {
|
|
899
|
-
if (item.scope.kind === "theme") {
|
|
900
|
-
indexed.theme[item.key] = item.value;
|
|
901
|
-
continue;
|
|
902
|
-
}
|
|
903
|
-
if (indexed.blocks[item.scope.blockId] == null) {
|
|
904
|
-
indexed.blocks[item.scope.blockId] = {};
|
|
905
|
-
}
|
|
906
|
-
indexed.blocks[item.scope.blockId][item.key] = item.value;
|
|
907
|
-
}
|
|
908
|
-
return indexed;
|
|
909
|
-
}
|
|
910
|
-
function createThemeState(deps) {
|
|
911
|
-
var _a;
|
|
912
|
-
const surfaces = {
|
|
913
|
-
page: {
|
|
914
|
-
blocks: d([]),
|
|
915
|
-
layout: d(null)
|
|
916
|
-
},
|
|
917
|
-
overlay: {
|
|
918
|
-
blocks: d([]),
|
|
919
|
-
layout: d(null)
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
const locale = d("en");
|
|
923
|
-
const catalogs = d(null);
|
|
924
|
-
const globalStyles = d(
|
|
925
|
-
deps.initialGlobalStyles ?? DEFAULT_GLOBAL_STYLES
|
|
926
|
-
);
|
|
927
|
-
function setGlobalStyles(styles) {
|
|
928
|
-
globalStyles.value = styles;
|
|
929
|
-
}
|
|
930
|
-
E(() => {
|
|
931
|
-
setLayoutSystemEnabled(globalStyles.value.layoutEngine === "grid-v1");
|
|
932
|
-
});
|
|
933
|
-
async function collectBlockDefaults(loc) {
|
|
934
|
-
const nextDefaults = {};
|
|
935
|
-
const nextModes = {};
|
|
936
|
-
for (const block of getDefinedBlocks()) {
|
|
937
|
-
if (block.locales == null) continue;
|
|
938
|
-
let file = null;
|
|
939
|
-
try {
|
|
940
|
-
file = await block.locales.load(loc);
|
|
941
|
-
} catch {
|
|
942
|
-
file = null;
|
|
943
|
-
}
|
|
944
|
-
const parsed = parseBlockLocaleFile(file);
|
|
945
|
-
nextDefaults[block.name] = parsed.defaults;
|
|
946
|
-
nextModes[block.name] = parsed.modes;
|
|
947
|
-
}
|
|
948
|
-
return { defaults: nextDefaults, modes: nextModes };
|
|
949
|
-
}
|
|
950
|
-
async function setLocale(nextLocaleRaw) {
|
|
951
|
-
var _a2;
|
|
952
|
-
const nextLocale = normalizeLocale(nextLocaleRaw);
|
|
953
|
-
const [blockData, loadedOverrides] = await Promise.all([
|
|
954
|
-
collectBlockDefaults(nextLocale),
|
|
955
|
-
((_a2 = deps.translations) == null ? void 0 : _a2.resolveTranslations(nextLocale).catch(() => [])) ?? Promise.resolve([])
|
|
956
|
-
]);
|
|
957
|
-
const overrides = loadedOverrides.filter(
|
|
958
|
-
(item) => normalizeLocale(item.locale) === nextLocale
|
|
959
|
-
);
|
|
960
|
-
const indexed = indexOverrides(overrides);
|
|
961
|
-
catalogs.value = {
|
|
962
|
-
theme: {
|
|
963
|
-
defaults: {},
|
|
964
|
-
overrides: indexed.theme
|
|
965
|
-
},
|
|
966
|
-
blocks: {
|
|
967
|
-
defaults: blockData.defaults,
|
|
968
|
-
modes: blockData.modes,
|
|
969
|
-
overrides: indexed.blocks
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
locale.value = nextLocale;
|
|
973
|
-
}
|
|
974
|
-
async function resolve(surface, path) {
|
|
975
|
-
var _a2, _b, _c, _d;
|
|
976
|
-
r(() => {
|
|
977
|
-
surfaces[surface].blocks.value = [];
|
|
978
|
-
surfaces[surface].layout.value = null;
|
|
979
|
-
});
|
|
980
|
-
const stored = await deps.resolve(surface, path);
|
|
981
|
-
if (stored != null) {
|
|
982
|
-
const hydratedBlocks = stored.blocks.flatMap((block) => {
|
|
983
|
-
try {
|
|
984
|
-
return [createBlockInstanceFromObject(block)];
|
|
985
|
-
} catch (error) {
|
|
986
|
-
reportBlockError(error, {
|
|
987
|
-
site: "theme-state.resolve.hydrate",
|
|
988
|
-
extra: {
|
|
989
|
-
surface,
|
|
990
|
-
path,
|
|
991
|
-
blockType: typeof (block == null ? void 0 : block.type) === "string" ? block.type : "(unknown)"
|
|
992
|
-
}
|
|
993
|
-
});
|
|
994
|
-
return [];
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
r(() => {
|
|
998
|
-
surfaces[surface].blocks.value = hydratedBlocks;
|
|
999
|
-
surfaces[surface].layout.value = stored.layout ?? null;
|
|
1000
|
-
});
|
|
1001
|
-
return stored;
|
|
1002
|
-
}
|
|
1003
|
-
const blockToUse = surface === "page" ? (_b = (_a2 = deps.routerService) == null ? void 0 : _a2.getPages().find((p2) => p2.path === path)) == null ? void 0 : _b.block : (_c = getDefinedBlocks().find((b2) => b2.name === path)) == null ? void 0 : _c.name;
|
|
1004
|
-
if (blockToUse != null) {
|
|
1005
|
-
const instance = createBlockInstance(blockToUse);
|
|
1006
|
-
surfaces[surface].blocks.value = [instance];
|
|
1007
|
-
const serialized = serializeBlocks([instance]);
|
|
1008
|
-
(_d = deps.upsertState) == null ? void 0 : _d.call(deps, surface, path, serialized);
|
|
1009
|
-
return { blocks: serialized };
|
|
1010
|
-
}
|
|
1011
|
-
return { blocks: [] };
|
|
1012
|
-
}
|
|
1013
|
-
onRegisterBlock(async (_2, block) => {
|
|
1014
|
-
if (block.locales == null || catalogs.value == null) return;
|
|
1015
|
-
const localeAtLoadStart = locale.value;
|
|
1016
|
-
let file = null;
|
|
1017
|
-
try {
|
|
1018
|
-
file = await block.locales.load(localeAtLoadStart);
|
|
1019
|
-
} catch {
|
|
1020
|
-
file = null;
|
|
1021
|
-
}
|
|
1022
|
-
if (catalogs.value == null || locale.value !== localeAtLoadStart) return;
|
|
1023
|
-
const parsed = parseBlockLocaleFile(file);
|
|
1024
|
-
const current = catalogs.value;
|
|
1025
|
-
catalogs.value = {
|
|
1026
|
-
...current,
|
|
1027
|
-
blocks: {
|
|
1028
|
-
...current.blocks,
|
|
1029
|
-
defaults: {
|
|
1030
|
-
...current.blocks.defaults,
|
|
1031
|
-
[block.name]: parsed.defaults
|
|
1032
|
-
},
|
|
1033
|
-
modes: {
|
|
1034
|
-
...current.blocks.modes,
|
|
1035
|
-
[block.name]: parsed.modes
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
1039
|
-
});
|
|
1040
|
-
(_a = deps.routerService) == null ? void 0 : _a.subscribe(({ path }) => {
|
|
1041
|
-
resolve("page", path);
|
|
1042
|
-
});
|
|
1043
|
-
return {
|
|
1044
|
-
page: surfaces.page,
|
|
1045
|
-
overlay: surfaces.overlay,
|
|
1046
|
-
locales: { locale, catalogs, setLocale },
|
|
1047
|
-
globalStyles,
|
|
1048
|
-
setGlobalStyles,
|
|
1049
|
-
resolve
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
const TranslationContext = createContext("translation");
|
|
1053
|
-
function toStringRecord(input) {
|
|
1054
|
-
if (input == null) return {};
|
|
1055
|
-
return Object.fromEntries(
|
|
1056
|
-
Object.entries(input).filter(([, value]) => typeof value === "string")
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1059
|
-
function createTranslationService(locales, options = {}) {
|
|
1060
|
-
const loadedThemeDefaults = d({});
|
|
1061
|
-
if (options.loadDefaultTranslations) {
|
|
1062
|
-
let loadVersion = 0;
|
|
1063
|
-
E(() => {
|
|
1064
|
-
const locale = locales.locale.value;
|
|
1065
|
-
const currentVersion = ++loadVersion;
|
|
1066
|
-
void options.loadDefaultTranslations(locale).then((result) => toStringRecord(result)).catch(() => ({})).then((result) => {
|
|
1067
|
-
if (currentVersion !== loadVersion) return;
|
|
1068
|
-
loadedThemeDefaults.value = result;
|
|
1069
|
-
});
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
return {
|
|
1073
|
-
locale: locales.locale,
|
|
1074
|
-
resolve(blockType, blockId, key) {
|
|
1075
|
-
var _a, _b, _c;
|
|
1076
|
-
const data = locales.catalogs.value;
|
|
1077
|
-
const themeDefault = loadedThemeDefaults.value[key] ?? (data == null ? void 0 : data.theme.defaults[key]);
|
|
1078
|
-
if (data == null) {
|
|
1079
|
-
return themeDefault ?? key;
|
|
1080
|
-
}
|
|
1081
|
-
if (blockId && ((_a = data.blocks.overrides[blockId]) == null ? void 0 : _a[key]) !== void 0) {
|
|
1082
|
-
return data.blocks.overrides[blockId][key];
|
|
1083
|
-
}
|
|
1084
|
-
const blockDefault = blockType != null ? (_b = data.blocks.defaults[blockType]) == null ? void 0 : _b[key] : void 0;
|
|
1085
|
-
const mode = (blockType != null ? (_c = data.blocks.modes[blockType]) == null ? void 0 : _c[key] : void 0) ?? "override";
|
|
1086
|
-
if (blockDefault !== void 0 && mode === "override") {
|
|
1087
|
-
return blockDefault;
|
|
1088
|
-
}
|
|
1089
|
-
if (data.theme.overrides[key] !== void 0) {
|
|
1090
|
-
return data.theme.overrides[key];
|
|
1091
|
-
}
|
|
1092
|
-
if (themeDefault !== void 0) {
|
|
1093
|
-
return themeDefault;
|
|
1094
|
-
}
|
|
1095
|
-
if (blockDefault !== void 0) {
|
|
1096
|
-
return blockDefault;
|
|
1097
|
-
}
|
|
1098
|
-
return key;
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
const GRID_V1_ENGINE_ID = "grid-v1";
|
|
1103
|
-
const PAGE_ROOT_SLOT = "content";
|
|
1104
|
-
const DEFAULT_GRID = { cols: 12, gap: 16, rowUnit: 40 };
|
|
1105
|
-
const MAX_BLOCKS_PER_ROW = 3;
|
|
1106
|
-
const DEFAULT_BREAKPOINTS = [
|
|
1107
|
-
{ id: "desktop", cols: 12 },
|
|
1108
|
-
{ id: "mobile", cols: 1, query: { maxWidth: 600 } }
|
|
1109
|
-
];
|
|
1110
|
-
function sharesRowBand$1(a2, b2) {
|
|
1111
|
-
return a2.r < b2.r + b2.h && a2.r + a2.h > b2.r;
|
|
1112
|
-
}
|
|
1113
|
-
function minFillCols(cols) {
|
|
1114
|
-
return Math.max(1, Math.ceil(Math.max(1, cols) / MAX_BLOCKS_PER_ROW));
|
|
1115
|
-
}
|
|
1116
|
-
function clampRect(rect, cols) {
|
|
1117
|
-
const w2 = Math.max(1, Math.min(rect.w, cols));
|
|
1118
|
-
const c2 = Math.max(0, Math.min(rect.c, cols - w2));
|
|
1119
|
-
const h2 = Math.max(1, rect.h);
|
|
1120
|
-
const r2 = Math.max(0, rect.r);
|
|
1121
|
-
return { ...rect, c: c2, r: r2, w: w2, h: h2 };
|
|
1122
|
-
}
|
|
1123
|
-
function rectsOverlap(a2, b2) {
|
|
1124
|
-
return a2.c < b2.c + b2.w && a2.c + a2.w > b2.c && a2.r < b2.r + b2.h && a2.r + a2.h > b2.r;
|
|
1125
|
-
}
|
|
1126
|
-
function readingOrder(items) {
|
|
1127
|
-
return Object.keys(items).sort((idA, idB) => {
|
|
1128
|
-
const a2 = items[idA];
|
|
1129
|
-
const b2 = items[idB];
|
|
1130
|
-
if (a2.r !== b2.r) return a2.r - b2.r;
|
|
1131
|
-
return a2.c - b2.c;
|
|
1132
|
-
});
|
|
1133
|
-
}
|
|
1134
|
-
function compactItems(items, cols) {
|
|
1135
|
-
const columnBottoms = new Array(Math.max(1, cols)).fill(0);
|
|
1136
|
-
const compacted = {};
|
|
1137
|
-
for (const id of readingOrder(items)) {
|
|
1138
|
-
const rect = clampRect(items[id], cols);
|
|
1139
|
-
let top = 0;
|
|
1140
|
-
for (let c2 = rect.c; c2 < rect.c + rect.w; c2++) {
|
|
1141
|
-
top = Math.max(top, columnBottoms[c2] ?? 0);
|
|
1142
|
-
}
|
|
1143
|
-
compacted[id] = { ...rect, r: top };
|
|
1144
|
-
for (let c2 = rect.c; c2 < rect.c + rect.w; c2++) {
|
|
1145
|
-
columnBottoms[c2] = top + rect.h;
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
return compacted;
|
|
1149
|
-
}
|
|
1150
|
-
function rowBandBounds(items, target, cols, excludeId) {
|
|
1151
|
-
let left = 0;
|
|
1152
|
-
let right = Math.max(1, cols);
|
|
1153
|
-
for (const [id, rect] of Object.entries(items)) {
|
|
1154
|
-
if (id === excludeId) continue;
|
|
1155
|
-
const sharesRow = rect.r < target.r + target.h && rect.r + rect.h > target.r;
|
|
1156
|
-
if (!sharesRow) continue;
|
|
1157
|
-
const rectRight = rect.c + rect.w;
|
|
1158
|
-
if (rectRight <= target.c) {
|
|
1159
|
-
left = Math.max(left, rectRight);
|
|
1160
|
-
} else if (rect.c >= target.c + target.w) {
|
|
1161
|
-
right = Math.min(right, rect.c);
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
return { left, right };
|
|
1165
|
-
}
|
|
1166
|
-
function fillSegmentBounds(target, nonFill, cols) {
|
|
1167
|
-
let left = 0;
|
|
1168
|
-
let right = Math.max(1, cols);
|
|
1169
|
-
for (const rect of nonFill) {
|
|
1170
|
-
if (!sharesRowBand$1(rect, target)) continue;
|
|
1171
|
-
const rectRight = rect.c + rect.w;
|
|
1172
|
-
if (rectRight <= target.c) {
|
|
1173
|
-
left = Math.max(left, rectRight);
|
|
1174
|
-
} else if (rect.c >= target.c) {
|
|
1175
|
-
right = Math.min(right, rect.c);
|
|
1176
|
-
} else {
|
|
1177
|
-
left = Math.max(left, rectRight);
|
|
1178
|
-
}
|
|
1179
|
-
}
|
|
1180
|
-
return { left, right: Math.max(left, right) };
|
|
1181
|
-
}
|
|
1182
|
-
function applyFillExpansion(items, cols) {
|
|
1183
|
-
const next = {};
|
|
1184
|
-
for (const id of readingOrder(items)) {
|
|
1185
|
-
next[id] = items[id];
|
|
1186
|
-
}
|
|
1187
|
-
const fillIds = readingOrder(next).filter((id) => next[id].fill === true);
|
|
1188
|
-
if (fillIds.length === 0) return next;
|
|
1189
|
-
const nonFill = Object.values(next).filter((rect) => rect.fill !== true);
|
|
1190
|
-
const groups = [];
|
|
1191
|
-
for (const id of fillIds) {
|
|
1192
|
-
const rect = next[id];
|
|
1193
|
-
const seg = fillSegmentBounds(rect, nonFill, cols);
|
|
1194
|
-
const group = groups.find(
|
|
1195
|
-
(g2) => g2.left === seg.left && g2.right === seg.right && g2.members.some((memberId) => sharesRowBand$1(next[memberId], rect))
|
|
1196
|
-
);
|
|
1197
|
-
if (group) group.members.push(id);
|
|
1198
|
-
else groups.push({ left: seg.left, right: seg.right, members: [id] });
|
|
1199
|
-
}
|
|
1200
|
-
const minCols = minFillCols(cols);
|
|
1201
|
-
const overflow = [];
|
|
1202
|
-
for (const group of groups) {
|
|
1203
|
-
const span = Math.max(1, group.right - group.left);
|
|
1204
|
-
const fit = Math.min(group.members.length, Math.floor(span / minCols));
|
|
1205
|
-
if (fit <= 0) {
|
|
1206
|
-
overflow.push(...group.members);
|
|
1207
|
-
continue;
|
|
1208
|
-
}
|
|
1209
|
-
const staying = group.members.slice(0, fit);
|
|
1210
|
-
overflow.push(...group.members.slice(fit));
|
|
1211
|
-
const base = Math.floor(span / fit);
|
|
1212
|
-
const remainder = span - base * fit;
|
|
1213
|
-
let pos = group.left;
|
|
1214
|
-
staying.forEach((id, index) => {
|
|
1215
|
-
const w2 = base + (index < remainder ? 1 : 0);
|
|
1216
|
-
next[id] = { ...next[id], c: pos, w: Math.max(1, w2) };
|
|
1217
|
-
pos += w2;
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
if (overflow.length === 0) return next;
|
|
1221
|
-
for (const id of overflow) {
|
|
1222
|
-
const rect = next[id];
|
|
1223
|
-
let bandBottom = rect.r;
|
|
1224
|
-
for (const [otherId, other] of Object.entries(next)) {
|
|
1225
|
-
if (otherId === id || overflow.includes(otherId)) continue;
|
|
1226
|
-
if (sharesRowBand$1(other, rect)) {
|
|
1227
|
-
bandBottom = Math.max(bandBottom, other.r + other.h);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
next[id] = { ...next[id], c: 0, r: bandBottom, w: cols };
|
|
1231
|
-
}
|
|
1232
|
-
return compactItems(next, cols);
|
|
1233
|
-
}
|
|
1234
|
-
function findFreeRect(items, size, cols) {
|
|
1235
|
-
const w2 = Math.max(1, Math.min(size.w, cols));
|
|
1236
|
-
const h2 = Math.max(1, size.h);
|
|
1237
|
-
const existing = Object.values(items);
|
|
1238
|
-
for (let r2 = 0; ; r2++) {
|
|
1239
|
-
for (let c2 = 0; c2 <= cols - w2; c2++) {
|
|
1240
|
-
const candidate = { c: c2, r: r2, w: w2, h: h2 };
|
|
1241
|
-
if (!existing.some((rect) => rectsOverlap(candidate, rect))) {
|
|
1242
|
-
return candidate;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
function deriveLayout(base, target) {
|
|
1248
|
-
const cols = target.cols;
|
|
1249
|
-
const items = {};
|
|
1250
|
-
let r2 = 0;
|
|
1251
|
-
for (const id of readingOrder(base.items)) {
|
|
1252
|
-
const h2 = Math.max(1, base.items[id].h);
|
|
1253
|
-
items[id] = clampRect({ c: 0, r: r2, w: cols, h: h2 }, cols);
|
|
1254
|
-
r2 += h2;
|
|
1255
|
-
}
|
|
1256
|
-
return { grid: { ...base.grid, cols }, items };
|
|
1257
|
-
}
|
|
1258
|
-
function resolveLayout(doc, breakpointId) {
|
|
1259
|
-
var _a;
|
|
1260
|
-
const present = doc.layouts[breakpointId];
|
|
1261
|
-
if (present) return present;
|
|
1262
|
-
const baseId = (_a = doc.breakpoints[0]) == null ? void 0 : _a.id;
|
|
1263
|
-
const baseLayout = baseId ? doc.layouts[baseId] : void 0;
|
|
1264
|
-
const target = doc.breakpoints.find((b2) => b2.id === breakpointId);
|
|
1265
|
-
if (!baseLayout || !target) {
|
|
1266
|
-
return { grid: { ...DEFAULT_GRID, cols: (target == null ? void 0 : target.cols) ?? 1 }, items: {} };
|
|
1267
|
-
}
|
|
1268
|
-
return deriveLayout(baseLayout, target);
|
|
1269
|
-
}
|
|
1270
|
-
function classifyRowDividers(items, blockIds) {
|
|
1271
|
-
const leaderBlockIds = /* @__PURE__ */ new Set();
|
|
1272
|
-
const rowBlockIds = /* @__PURE__ */ new Set();
|
|
1273
|
-
const placed = blockIds.filter((id) => items[id] != null);
|
|
1274
|
-
if (placed.length === 0) return { leaderBlockIds, rowBlockIds };
|
|
1275
|
-
const rects = placed.map((id) => items[id]);
|
|
1276
|
-
const minRow = Math.min(...rects.map((rect) => rect.r));
|
|
1277
|
-
const boundaryIsCrossed = (boundary) => rects.some((rect) => rect.r < boundary && rect.r + rect.h > boundary);
|
|
1278
|
-
const ordered = [...placed].sort((a2, b2) => {
|
|
1279
|
-
const ra = items[a2];
|
|
1280
|
-
const rb = items[b2];
|
|
1281
|
-
return ra.r - rb.r || ra.c - rb.c;
|
|
1282
|
-
});
|
|
1283
|
-
let lastLeaderRow = null;
|
|
1284
|
-
for (const id of ordered) {
|
|
1285
|
-
const { r: r2 } = items[id];
|
|
1286
|
-
if (r2 <= minRow || boundaryIsCrossed(r2)) continue;
|
|
1287
|
-
rowBlockIds.add(id);
|
|
1288
|
-
if (r2 !== lastLeaderRow) {
|
|
1289
|
-
leaderBlockIds.add(id);
|
|
1290
|
-
lastLeaderRow = r2;
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
return { leaderBlockIds, rowBlockIds };
|
|
1294
|
-
}
|
|
1295
|
-
function containerRule(scope, grid) {
|
|
1296
|
-
return `${scope}{display:grid;grid-template-columns:repeat(${grid.cols},minmax(0,1fr));--juo-layout-cols:${grid.cols};--juo-layout-gap:var(--juo-layout-spacing,${grid.gap}px);column-gap:var(--juo-layout-gap);row-gap:0;margin-block-end:calc(-1 * var(--juo-layout-gap));}`;
|
|
1297
|
-
}
|
|
1298
|
-
function baseSpacingRule(scope) {
|
|
1299
|
-
return `${scope} > [data-block-id]{margin-block-end:var(--juo-layout-gap);}`;
|
|
1300
|
-
}
|
|
1301
|
-
function collapseRule(scope) {
|
|
1302
|
-
return `${scope} > [data-empty],${scope} > :has(> [data-empty]){margin-block-end:0;}`;
|
|
1303
|
-
}
|
|
1304
|
-
function itemRule(scope, blockId, rect, divider) {
|
|
1305
|
-
return `${scope} > [data-block-id="${blockId}"]{grid-column:${rect.c + 1}/span ${rect.w};grid-row:${rect.r + 1}/span ${rect.h};--juo-layout-c:${rect.c};--juo-divider-row:${divider.row ? 1 : 0};--juo-divider-line:${divider.line ? 1 : 0};}`;
|
|
1306
|
-
}
|
|
1307
|
-
function breakpointCss(scope, layout, domOrder) {
|
|
1308
|
-
const { leaderBlockIds, rowBlockIds } = classifyRowDividers(
|
|
1309
|
-
layout.items,
|
|
1310
|
-
domOrder
|
|
1311
|
-
);
|
|
1312
|
-
const rules = [containerRule(scope, layout.grid)];
|
|
1313
|
-
for (const blockId of Object.keys(layout.items)) {
|
|
1314
|
-
rules.push(
|
|
1315
|
-
itemRule(scope, blockId, layout.items[blockId], {
|
|
1316
|
-
row: rowBlockIds.has(blockId),
|
|
1317
|
-
line: leaderBlockIds.has(blockId)
|
|
1318
|
-
})
|
|
1319
|
-
);
|
|
1320
|
-
}
|
|
1321
|
-
return rules.join("");
|
|
1322
|
-
}
|
|
1323
|
-
function sharesRowBand(a2, b2) {
|
|
1324
|
-
return a2.r < b2.r + b2.h && a2.r + a2.h > b2.r;
|
|
1325
|
-
}
|
|
1326
|
-
function nonEmptySubsets(ids) {
|
|
1327
|
-
const out = [];
|
|
1328
|
-
for (let mask = 1; mask < 1 << ids.length; mask++) {
|
|
1329
|
-
const subset = [];
|
|
1330
|
-
for (let i2 = 0; i2 < ids.length; i2++) {
|
|
1331
|
-
if (mask & 1 << i2) subset.push(ids[i2]);
|
|
1332
|
-
}
|
|
1333
|
-
out.push(subset);
|
|
1334
|
-
}
|
|
1335
|
-
return out;
|
|
1336
|
-
}
|
|
1337
|
-
function reclaimSelector(scope, fillId, emptyMates, domIndex) {
|
|
1338
|
-
const fillIdx = domIndex.get(fillId) ?? 0;
|
|
1339
|
-
const byDom = (a2, b2) => (domIndex.get(a2) ?? 0) - (domIndex.get(b2) ?? 0);
|
|
1340
|
-
const before = emptyMates.filter((id) => (domIndex.get(id) ?? 0) < fillIdx).sort(byDom);
|
|
1341
|
-
const after = emptyMates.filter((id) => (domIndex.get(id) ?? 0) > fillIdx).sort(byDom);
|
|
1342
|
-
const emptyBefore = (id) => `[data-block-id="${id}"]:is([data-empty],:has(> [data-empty]))`;
|
|
1343
|
-
const emptyAfterHas = (id) => `~ [data-block-id="${id}"][data-empty],~ [data-block-id="${id}"] > [data-empty]`;
|
|
1344
|
-
let sel = "";
|
|
1345
|
-
for (const id of before) sel += `${emptyBefore(id)} ~ `;
|
|
1346
|
-
sel += `[data-block-id="${fillId}"]`;
|
|
1347
|
-
for (const id of after) sel += `:has(${emptyAfterHas(id)})`;
|
|
1348
|
-
return `${scope} > ${sel}`;
|
|
1349
|
-
}
|
|
1350
|
-
function reclaimCss(scope, layout, domOrder) {
|
|
1351
|
-
const items = layout.items;
|
|
1352
|
-
const cols = layout.grid.cols;
|
|
1353
|
-
const domIndex = new Map(domOrder.map((id, index) => [id, index]));
|
|
1354
|
-
const rules = [];
|
|
1355
|
-
for (const [fillId, fillRect] of Object.entries(items)) {
|
|
1356
|
-
if (fillRect.fill !== true) continue;
|
|
1357
|
-
const mateIds = Object.entries(items).filter(([id, rect]) => id !== fillId && sharesRowBand(rect, fillRect)).map(([id]) => id);
|
|
1358
|
-
if (mateIds.length === 0 || mateIds.length > 4) continue;
|
|
1359
|
-
for (const emptyMates of nonEmptySubsets(mateIds)) {
|
|
1360
|
-
const remaining = {};
|
|
1361
|
-
for (const [id, rect] of Object.entries(items)) {
|
|
1362
|
-
if (id === fillId || emptyMates.includes(id)) continue;
|
|
1363
|
-
remaining[id] = rect;
|
|
1364
|
-
}
|
|
1365
|
-
const { left, right } = rowBandBounds(remaining, fillRect, cols);
|
|
1366
|
-
if (left >= fillRect.c && right <= fillRect.c + fillRect.w) continue;
|
|
1367
|
-
const selector = reclaimSelector(scope, fillId, emptyMates, domIndex);
|
|
1368
|
-
rules.push(
|
|
1369
|
-
`${selector}{grid-column:${left + 1}/span ${Math.max(1, right - left)};--juo-layout-c:${left};}`
|
|
1370
|
-
);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
return rules.join("");
|
|
1374
|
-
}
|
|
1375
|
-
function projectToCss(doc, opts) {
|
|
1376
|
-
const base = doc.breakpoints[0];
|
|
1377
|
-
if (!base) return "";
|
|
1378
|
-
const baseLayout = resolveLayout(doc, base.id);
|
|
1379
|
-
const domOrder = opts.domOrder ?? Object.keys(baseLayout.items);
|
|
1380
|
-
const parts = [
|
|
1381
|
-
breakpointCss(opts.scope, baseLayout, domOrder),
|
|
1382
|
-
baseSpacingRule(opts.scope),
|
|
1383
|
-
collapseRule(opts.scope),
|
|
1384
|
-
reclaimCss(opts.scope, baseLayout, domOrder)
|
|
1385
|
-
];
|
|
1386
|
-
for (const bp of doc.breakpoints.slice(1)) {
|
|
1387
|
-
if (!bp.query) continue;
|
|
1388
|
-
parts.push(
|
|
1389
|
-
`@container (max-width:${bp.query.maxWidth}px){` + breakpointCss(opts.scope, resolveLayout(doc, bp.id), domOrder) + `}`
|
|
1390
|
-
);
|
|
1391
|
-
}
|
|
1392
|
-
return parts.join("");
|
|
1393
|
-
}
|
|
1394
|
-
function createDefaultLayoutDocument(blockIds) {
|
|
1395
|
-
const items = {};
|
|
1396
|
-
blockIds.forEach((id, index) => {
|
|
1397
|
-
items[id] = { c: 0, r: index, w: DEFAULT_GRID.cols, h: 1 };
|
|
1398
|
-
});
|
|
1399
|
-
return {
|
|
1400
|
-
version: 1,
|
|
1401
|
-
engine: GRID_V1_ENGINE_ID,
|
|
1402
|
-
breakpoints: structuredClone([...DEFAULT_BREAKPOINTS]),
|
|
1403
|
-
layouts: {
|
|
1404
|
-
[DEFAULT_BREAKPOINTS[0].id]: { grid: { ...DEFAULT_GRID }, items }
|
|
1405
|
-
}
|
|
1406
|
-
};
|
|
1407
|
-
}
|
|
1408
|
-
function colsForBreakpoint(doc, breakpointId, layout) {
|
|
1409
|
-
var _a;
|
|
1410
|
-
return ((_a = doc.breakpoints.find((b2) => b2.id === breakpointId)) == null ? void 0 : _a.cols) ?? layout.grid.cols;
|
|
1411
|
-
}
|
|
1412
|
-
function reconcileBreakpointLayout(layout, blockIds, cols) {
|
|
1413
|
-
const known = new Set(blockIds);
|
|
1414
|
-
for (const id of Object.keys(layout.items)) {
|
|
1415
|
-
if (!known.has(id)) delete layout.items[id];
|
|
1416
|
-
}
|
|
1417
|
-
for (const id of blockIds) {
|
|
1418
|
-
if (!layout.items[id]) {
|
|
1419
|
-
layout.items[id] = findFreeRect(layout.items, { w: cols, h: 1 }, cols);
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
function reconcileLayout(doc, blockIds) {
|
|
1424
|
-
var _a;
|
|
1425
|
-
if (!doc) return createDefaultLayoutDocument(blockIds);
|
|
1426
|
-
const next = structuredClone(doc);
|
|
1427
|
-
const baseId = (_a = next.breakpoints[0]) == null ? void 0 : _a.id;
|
|
1428
|
-
if (!baseId) return createDefaultLayoutDocument(blockIds);
|
|
1429
|
-
for (const def of DEFAULT_BREAKPOINTS) {
|
|
1430
|
-
if (!next.breakpoints.some((b2) => b2.id === def.id)) {
|
|
1431
|
-
next.breakpoints.push(structuredClone(def));
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
next.layouts[baseId] = next.layouts[baseId] ?? {
|
|
1435
|
-
grid: { ...DEFAULT_GRID },
|
|
1436
|
-
items: {}
|
|
1437
|
-
};
|
|
1438
|
-
for (const breakpointId of Object.keys(next.layouts)) {
|
|
1439
|
-
const layout = next.layouts[breakpointId];
|
|
1440
|
-
if (!layout) continue;
|
|
1441
|
-
reconcileBreakpointLayout(
|
|
1442
|
-
layout,
|
|
1443
|
-
blockIds,
|
|
1444
|
-
colsForBreakpoint(next, breakpointId, layout)
|
|
1445
|
-
);
|
|
1446
|
-
}
|
|
1447
|
-
return next;
|
|
1448
|
-
}
|
|
1449
|
-
function compactLayoutDocument(doc) {
|
|
1450
|
-
if (!doc) return doc;
|
|
1451
|
-
const next = structuredClone(doc);
|
|
1452
|
-
for (const breakpointId of Object.keys(next.layouts)) {
|
|
1453
|
-
const layout = next.layouts[breakpointId];
|
|
1454
|
-
if (!layout) continue;
|
|
1455
|
-
layout.items = compactItems(
|
|
1456
|
-
layout.items,
|
|
1457
|
-
colsForBreakpoint(next, breakpointId, layout)
|
|
1458
|
-
);
|
|
1459
|
-
}
|
|
1460
|
-
return next;
|
|
1461
|
-
}
|
|
1462
|
-
function expandFillLayoutDocument(doc) {
|
|
1463
|
-
if (!doc) return doc;
|
|
1464
|
-
const next = structuredClone(doc);
|
|
1465
|
-
for (const breakpointId of Object.keys(next.layouts)) {
|
|
1466
|
-
const layout = next.layouts[breakpointId];
|
|
1467
|
-
if (!layout) continue;
|
|
1468
|
-
layout.items = applyFillExpansion(
|
|
1469
|
-
layout.items,
|
|
1470
|
-
colsForBreakpoint(next, breakpointId, layout)
|
|
1471
|
-
);
|
|
1472
|
-
}
|
|
1473
|
-
return next;
|
|
1474
|
-
}
|
|
1475
|
-
const LAYOUT_SCOPE_ATTR = "data-juo-layout";
|
|
1476
|
-
function layoutScopeSelector(scopeId) {
|
|
1477
|
-
return `[${LAYOUT_SCOPE_ATTR}="${scopeId}"]`;
|
|
1478
|
-
}
|
|
1479
|
-
function buildLayoutCss(layout, blockIds, scopeId) {
|
|
1480
|
-
const reconciled = reconcileLayout(layout, blockIds);
|
|
1481
|
-
return projectToCss(reconciled, {
|
|
1482
|
-
scope: layoutScopeSelector(scopeId),
|
|
1483
|
-
domOrder: blockIds
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
function buildGridLayout(layout, blockIds, scopeId) {
|
|
1487
|
-
var _a, _b;
|
|
1488
|
-
const scope = layoutScopeSelector(scopeId);
|
|
1489
|
-
const reconciled = reconcileLayout(layout, blockIds);
|
|
1490
|
-
const baseId = (_a = reconciled.breakpoints[0]) == null ? void 0 : _a.id;
|
|
1491
|
-
const layoutItems = (baseId != null ? (_b = reconciled.layouts[baseId]) == null ? void 0 : _b.items : null) ?? {};
|
|
1492
|
-
const { leaderBlockIds, rowBlockIds } = classifyRowDividers(
|
|
1493
|
-
layoutItems,
|
|
1494
|
-
blockIds
|
|
1495
|
-
);
|
|
1496
|
-
const fullWidthBlockIds = /* @__PURE__ */ new Set();
|
|
1497
|
-
for (const [id, rect] of Object.entries(layoutItems)) {
|
|
1498
|
-
if (rect.fill === true) fullWidthBlockIds.add(id);
|
|
1499
|
-
}
|
|
1500
|
-
return {
|
|
1501
|
-
css: projectToCss(reconciled, { scope, domOrder: blockIds }),
|
|
1502
|
-
dividerBlockIds: leaderBlockIds,
|
|
1503
|
-
dividerRowBlockIds: rowBlockIds,
|
|
1504
|
-
fullWidthBlockIds
|
|
1505
|
-
};
|
|
1506
|
-
}
|
|
1507
|
-
export {
|
|
1508
|
-
layoutScopeSelector as $,
|
|
1509
|
-
attachEmptyTracking as A,
|
|
1510
|
-
BlockWrapperEvent as B,
|
|
1511
|
-
ContextRoot as C,
|
|
1512
|
-
DEFAULT_GRID as D,
|
|
1513
|
-
E,
|
|
1514
|
-
buildLayoutCss as F,
|
|
1515
|
-
GRID_V1_ENGINE_ID as G,
|
|
1516
|
-
classifyRowDividers as H,
|
|
1517
|
-
compactLayoutDocument as I,
|
|
1518
|
-
createBlockInstanceFromJSON as J,
|
|
1519
|
-
createBlockInstanceFromObject as K,
|
|
1520
|
-
LAYOUT_SCOPE_ATTR as L,
|
|
1521
|
-
MAX_BLOCKS_PER_ROW as M,
|
|
1522
|
-
createCeRenderer as N,
|
|
1523
|
-
createDefaultLayoutDocument as O,
|
|
1524
|
-
PAGE_ROOT_SLOT as P,
|
|
1525
|
-
createSelectedBlock as Q,
|
|
1526
|
-
createThemeState as R,
|
|
1527
|
-
SelectedBlockContext as S,
|
|
1528
|
-
TranslationContext as T,
|
|
1529
|
-
createTranslationService as U,
|
|
1530
|
-
defineBlockRuntime as V,
|
|
1531
|
-
deriveLayout as W,
|
|
1532
|
-
expandFillLayoutDocument as X,
|
|
1533
|
-
hasRenderedContent as Y,
|
|
1534
|
-
indexOverrides as Z,
|
|
1535
|
-
isEditorPreview as _,
|
|
1536
|
-
isStubDefinition as a,
|
|
1537
|
-
layoutSystemEnabled as a0,
|
|
1538
|
-
projectToCss as a1,
|
|
1539
|
-
provideContext as a2,
|
|
1540
|
-
readingOrder as a3,
|
|
1541
|
-
rectsOverlap as a4,
|
|
1542
|
-
serializeBlocks as a5,
|
|
1543
|
-
setLayoutSystemEnabled as a6,
|
|
1544
|
-
n as a7,
|
|
1545
|
-
buildGridLayout as b,
|
|
1546
|
-
ThemeStateContext as c,
|
|
1547
|
-
backfillInstanceDefaults as d,
|
|
1548
|
-
reconcileLayout as e,
|
|
1549
|
-
createContext as f,
|
|
1550
|
-
d as g,
|
|
1551
|
-
w as h,
|
|
1552
|
-
injectContext as i,
|
|
1553
|
-
registerBlock as j,
|
|
1554
|
-
getDefinedBlocks as k,
|
|
1555
|
-
createBlockInstance as l,
|
|
1556
|
-
defineBlock as m,
|
|
1557
|
-
clampRect as n,
|
|
1558
|
-
onRegisterBlock as o,
|
|
1559
|
-
applyFillExpansion as p,
|
|
1560
|
-
compactItems as q,
|
|
1561
|
-
resolveLayout as r,
|
|
1562
|
-
subscribeContext as s,
|
|
1563
|
-
findFreeRect as t,
|
|
1564
|
-
u,
|
|
1565
|
-
ContextProvideEvent as v,
|
|
1566
|
-
withWrapper as w,
|
|
1567
|
-
ContextRequestEvent as x,
|
|
1568
|
-
DEFAULT_BREAKPOINTS as y,
|
|
1569
|
-
DEFAULT_GLOBAL_STYLES as z
|
|
1570
|
-
};
|