@constela/runtime 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +53 -21
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15545,10 +15545,23 @@ function renderPortal(node, ctx) {
|
|
|
15545
15545
|
});
|
|
15546
15546
|
return document.createComment("portal");
|
|
15547
15547
|
}
|
|
15548
|
-
function createLocalStateStore(stateDefs) {
|
|
15548
|
+
function createLocalStateStore(stateDefs, ctx) {
|
|
15549
15549
|
const signals = {};
|
|
15550
15550
|
for (const [name, def] of Object.entries(stateDefs)) {
|
|
15551
|
-
|
|
15551
|
+
const initial = def.initial;
|
|
15552
|
+
let initialValue;
|
|
15553
|
+
if (initial && typeof initial === "object" && "expr" in initial) {
|
|
15554
|
+
const evalCtx = {
|
|
15555
|
+
state: ctx.state,
|
|
15556
|
+
locals: ctx.locals
|
|
15557
|
+
};
|
|
15558
|
+
if (ctx.route) evalCtx.route = ctx.route;
|
|
15559
|
+
if (ctx.imports) evalCtx.imports = ctx.imports;
|
|
15560
|
+
initialValue = evaluate(initial, evalCtx);
|
|
15561
|
+
} else {
|
|
15562
|
+
initialValue = initial;
|
|
15563
|
+
}
|
|
15564
|
+
signals[name] = createSignal(initialValue);
|
|
15552
15565
|
}
|
|
15553
15566
|
return {
|
|
15554
15567
|
get(name) {
|
|
@@ -15622,7 +15635,7 @@ function createStateWithLocalState(globalState, localStore) {
|
|
|
15622
15635
|
};
|
|
15623
15636
|
}
|
|
15624
15637
|
function renderLocalState(node, ctx) {
|
|
15625
|
-
const localStore = createLocalStateStore(node.state);
|
|
15638
|
+
const localStore = createLocalStateStore(node.state, ctx);
|
|
15626
15639
|
const mergedLocals = createLocalsWithLocalState(ctx.locals, localStore);
|
|
15627
15640
|
const mergedState = createStateWithLocalState(ctx.state, localStore);
|
|
15628
15641
|
const mergedActions = { ...ctx.actions };
|
|
@@ -15877,10 +15890,23 @@ function createReactiveLocals2(baseLocals, itemSignal, indexSignal, itemName, in
|
|
|
15877
15890
|
}
|
|
15878
15891
|
});
|
|
15879
15892
|
}
|
|
15880
|
-
function createLocalStateStore2(stateDefs) {
|
|
15893
|
+
function createLocalStateStore2(stateDefs, ctx) {
|
|
15881
15894
|
const signals = {};
|
|
15882
15895
|
for (const [name, def] of Object.entries(stateDefs)) {
|
|
15883
|
-
|
|
15896
|
+
const initial = def.initial;
|
|
15897
|
+
let initialValue;
|
|
15898
|
+
if (initial && typeof initial === "object" && "expr" in initial) {
|
|
15899
|
+
const evalCtx = {
|
|
15900
|
+
state: ctx.state,
|
|
15901
|
+
locals: ctx.locals
|
|
15902
|
+
};
|
|
15903
|
+
if (ctx.route) evalCtx.route = ctx.route;
|
|
15904
|
+
if (ctx.imports) evalCtx.imports = ctx.imports;
|
|
15905
|
+
initialValue = evaluate(initial, evalCtx);
|
|
15906
|
+
} else {
|
|
15907
|
+
initialValue = initial;
|
|
15908
|
+
}
|
|
15909
|
+
signals[name] = createSignal(initialValue);
|
|
15884
15910
|
}
|
|
15885
15911
|
return {
|
|
15886
15912
|
get(name) {
|
|
@@ -16059,7 +16085,7 @@ function hydrate(node, domNode, ctx) {
|
|
|
16059
16085
|
}
|
|
16060
16086
|
}
|
|
16061
16087
|
function hydrateLocalState(node, domNode, ctx) {
|
|
16062
|
-
const localStore = createLocalStateStore2(node.state);
|
|
16088
|
+
const localStore = createLocalStateStore2(node.state, ctx);
|
|
16063
16089
|
const mergedLocals = createLocalsWithLocalState2(ctx.locals, localStore);
|
|
16064
16090
|
const mergedState = createStateWithLocalState2(ctx.state, localStore);
|
|
16065
16091
|
const mergedActions = { ...ctx.actions };
|
|
@@ -16141,20 +16167,22 @@ function hydrateElement(node, el, ctx) {
|
|
|
16141
16167
|
hydrateChildren(node.children, el, ctx);
|
|
16142
16168
|
}
|
|
16143
16169
|
}
|
|
16144
|
-
function
|
|
16145
|
-
|
|
16146
|
-
|
|
16147
|
-
|
|
16148
|
-
|
|
16149
|
-
const text3 =
|
|
16150
|
-
if (text3 === "if:then")
|
|
16151
|
-
|
|
16152
|
-
if (text3 === "if:
|
|
16170
|
+
function collectIfMarkers(parent) {
|
|
16171
|
+
const markers = [];
|
|
16172
|
+
for (let i = 0; i < parent.childNodes.length; i++) {
|
|
16173
|
+
const child = parent.childNodes[i];
|
|
16174
|
+
if (child.nodeType === Node.COMMENT_NODE) {
|
|
16175
|
+
const text3 = child.textContent;
|
|
16176
|
+
if (text3 === "if:then") {
|
|
16177
|
+
markers.push({ branch: "then", marker: child });
|
|
16178
|
+
} else if (text3 === "if:else") {
|
|
16179
|
+
markers.push({ branch: "else", marker: child });
|
|
16180
|
+
} else if (text3 === "if:none") {
|
|
16181
|
+
markers.push({ branch: "none", marker: child });
|
|
16182
|
+
}
|
|
16153
16183
|
}
|
|
16154
|
-
if (current.nodeType === Node.ELEMENT_NODE) break;
|
|
16155
|
-
current = current.previousSibling;
|
|
16156
16184
|
}
|
|
16157
|
-
return
|
|
16185
|
+
return markers;
|
|
16158
16186
|
}
|
|
16159
16187
|
function hydrateChildren(children, parent, ctx) {
|
|
16160
16188
|
const domChildren = [];
|
|
@@ -16164,6 +16192,8 @@ function hydrateChildren(children, parent, ctx) {
|
|
|
16164
16192
|
domChildren.push(child);
|
|
16165
16193
|
}
|
|
16166
16194
|
}
|
|
16195
|
+
const ifMarkers = collectIfMarkers(parent);
|
|
16196
|
+
let ifMarkerIndex = 0;
|
|
16167
16197
|
let domIndex = 0;
|
|
16168
16198
|
for (let i = 0; i < children.length; i++) {
|
|
16169
16199
|
const childNode = children[i];
|
|
@@ -16198,14 +16228,15 @@ function hydrateChildren(children, parent, ctx) {
|
|
|
16198
16228
|
...ctx.route && { route: ctx.route }
|
|
16199
16229
|
});
|
|
16200
16230
|
const clientBranch = Boolean(clientCondition) ? "then" : ifNode.else ? "else" : "none";
|
|
16201
|
-
const
|
|
16202
|
-
|
|
16231
|
+
const ssrInfo = ifMarkerIndex < ifMarkers.length ? ifMarkers[ifMarkerIndex] : null;
|
|
16232
|
+
ifMarkerIndex++;
|
|
16203
16233
|
const ssrBranch = ssrInfo?.branch ?? null;
|
|
16204
16234
|
const ssrHasDom = ssrBranch === "then" || ssrBranch === "else";
|
|
16205
16235
|
if (ssrInfo?.marker) {
|
|
16206
16236
|
ssrInfo.marker.remove();
|
|
16207
16237
|
}
|
|
16208
|
-
if (ssrHasDom &&
|
|
16238
|
+
if (ssrHasDom && domChildren[domIndex]) {
|
|
16239
|
+
const domChild = domChildren[domIndex];
|
|
16209
16240
|
hydrateIf(ifNode, domChild, ctx, { ssrBranch, clientBranch });
|
|
16210
16241
|
domIndex++;
|
|
16211
16242
|
} else if (ssrBranch === "none") {
|
|
@@ -16214,6 +16245,7 @@ function hydrateChildren(children, parent, ctx) {
|
|
|
16214
16245
|
});
|
|
16215
16246
|
} else {
|
|
16216
16247
|
const hasDomForIf = Boolean(clientCondition) || Boolean(ifNode.else);
|
|
16248
|
+
const domChild = domChildren[domIndex];
|
|
16217
16249
|
if (hasDomForIf && domChild) {
|
|
16218
16250
|
hydrate(childNode, domChild, ctx);
|
|
16219
16251
|
domIndex++;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/runtime",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Runtime DOM renderer for Constela UI framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"tsup": "^8.0.0",
|
|
30
30
|
"typescript": "^5.3.0",
|
|
31
31
|
"vitest": "^2.0.0",
|
|
32
|
-
"@constela/server": "14.0.
|
|
32
|
+
"@constela/server": "14.0.3"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@constela/ai": "3.0.2"
|