sinwan 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -3
- package/dist/cjs/index.development.js +357 -221
- package/dist/cjs/index.development.js.map +12 -11
- package/dist/cjs/index.production.min.js +2 -2
- package/dist/cjs/index.production.min.js.map +12 -11
- package/dist/cjs/renderer/index.development.js +300 -116
- package/dist/cjs/renderer/index.development.js.map +11 -10
- package/dist/cjs/renderer/index.production.min.js +2 -2
- package/dist/cjs/renderer/index.production.min.js.map +11 -10
- package/dist/cjs/server/index.development.js +146 -68
- package/dist/cjs/server/index.development.js.map +8 -7
- package/dist/cjs/server/index.production.min.js +2 -2
- package/dist/cjs/server/index.production.min.js.map +8 -7
- package/dist/component/control-flow.d.ts +6 -1
- package/dist/component/control-flow.d.ts.map +1 -1
- package/dist/component/instance.d.ts.map +1 -1
- package/dist/esm/index.development.js +357 -221
- package/dist/esm/index.development.js.map +12 -11
- package/dist/esm/index.production.min.js +2 -2
- package/dist/esm/index.production.min.js.map +12 -11
- package/dist/esm/renderer/index.development.js +300 -116
- package/dist/esm/renderer/index.development.js.map +11 -10
- package/dist/esm/renderer/index.production.min.js +2 -2
- package/dist/esm/renderer/index.production.min.js.map +11 -10
- package/dist/esm/server/index.development.js +146 -68
- package/dist/esm/server/index.development.js.map +8 -7
- package/dist/esm/server/index.production.min.js +2 -2
- package/dist/esm/server/index.production.min.js.map +8 -7
- package/dist/reactivity/index.d.ts +2 -1
- package/dist/reactivity/index.d.ts.map +1 -1
- package/dist/reactivity/normalization.d.ts +19 -0
- package/dist/reactivity/normalization.d.ts.map +1 -0
- package/dist/renderer/attributes.d.ts.map +1 -1
- package/dist/renderer/events.d.ts.map +1 -1
- package/dist/renderer/render-children.d.ts.map +1 -1
- package/dist/renderer/render-control-flow.d.ts.map +1 -1
- package/dist/renderer/render-element.d.ts.map +1 -1
- package/dist/renderer/types.d.ts +2 -0
- package/dist/renderer/types.d.ts.map +1 -1
- package/dist/server/renderer.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -3
|
@@ -316,7 +316,6 @@ function signal(initial) {
|
|
|
316
316
|
function isSignal(value) {
|
|
317
317
|
return value != null && typeof value === "object" && SIGNAL_BRAND in value;
|
|
318
318
|
}
|
|
319
|
-
|
|
320
319
|
// src/reactivity/computed.ts
|
|
321
320
|
var COMPUTED_BRAND = Symbol("Sinwan:computed");
|
|
322
321
|
|
|
@@ -368,10 +367,35 @@ function computed(getter) {
|
|
|
368
367
|
function isComputed(value) {
|
|
369
368
|
return value != null && typeof value === "object" && COMPUTED_BRAND in value;
|
|
370
369
|
}
|
|
371
|
-
|
|
370
|
+
// src/reactivity/batch.ts
|
|
371
|
+
var batchDepth = 0;
|
|
372
|
+
function batch(fn) {
|
|
373
|
+
batchDepth++;
|
|
374
|
+
try {
|
|
375
|
+
fn();
|
|
376
|
+
} finally {
|
|
377
|
+
batchDepth--;
|
|
378
|
+
if (batchDepth === 0) {
|
|
379
|
+
flushSync();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// src/reactivity/normalization.ts
|
|
384
|
+
function isReactive(value) {
|
|
385
|
+
return isSignal(value) || isComputed(value) || typeof value === "function";
|
|
386
|
+
}
|
|
387
|
+
function resolve(value) {
|
|
388
|
+
if (isSignal(value) || isComputed(value)) {
|
|
389
|
+
return value.value;
|
|
390
|
+
}
|
|
391
|
+
if (typeof value === "function") {
|
|
392
|
+
return value();
|
|
393
|
+
}
|
|
394
|
+
return value;
|
|
395
|
+
}
|
|
372
396
|
// src/renderer/events.ts
|
|
373
397
|
function isEventProp(key) {
|
|
374
|
-
return key.length > 2 && key
|
|
398
|
+
return key.length > 2 && key.startsWith("on");
|
|
375
399
|
}
|
|
376
400
|
function toEventName(key) {
|
|
377
401
|
return key.slice(2).toLowerCase();
|
|
@@ -448,19 +472,28 @@ function fireMountedHooks(instance) {
|
|
|
448
472
|
}
|
|
449
473
|
}
|
|
450
474
|
function fireUnmountedHooks(instance) {
|
|
451
|
-
|
|
475
|
+
const children = [...instance.children];
|
|
476
|
+
for (const child of children) {
|
|
452
477
|
fireUnmountedHooks(child);
|
|
453
478
|
}
|
|
454
|
-
if (
|
|
479
|
+
if (!instance.isUnmounted) {
|
|
455
480
|
instance.isUnmounted = true;
|
|
456
|
-
instance.isMounted
|
|
457
|
-
|
|
458
|
-
hook
|
|
481
|
+
if (instance.isMounted) {
|
|
482
|
+
instance.isMounted = false;
|
|
483
|
+
for (const hook of instance._unmountedHooks) {
|
|
484
|
+
hook();
|
|
485
|
+
}
|
|
459
486
|
}
|
|
460
487
|
for (const dispose of instance.effects) {
|
|
461
488
|
dispose();
|
|
462
489
|
}
|
|
463
490
|
instance.effects.length = 0;
|
|
491
|
+
if (instance.parent) {
|
|
492
|
+
const idx = instance.parent.children.indexOf(instance);
|
|
493
|
+
if (idx !== -1) {
|
|
494
|
+
instance.parent.children.splice(idx, 1);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
464
497
|
}
|
|
465
498
|
}
|
|
466
499
|
function fireUpdatedHooks(instance) {
|
|
@@ -510,11 +543,13 @@ function applyAttributes(el, props) {
|
|
|
510
543
|
for (const [key, value] of Object.entries(props)) {
|
|
511
544
|
if (SKIP_PROPS.has(key) || isEventProp(key))
|
|
512
545
|
continue;
|
|
513
|
-
|
|
546
|
+
const attrName = resolveAttributeName(key);
|
|
547
|
+
const isComplex = attrName === "class" || attrName === "style";
|
|
548
|
+
if (isReactive(value) || isComplex && containsReactive(value)) {
|
|
514
549
|
const state = { previousStyleProps: new Set };
|
|
515
550
|
let initialized = false;
|
|
516
551
|
const dispose = effect(() => {
|
|
517
|
-
setSingleAttribute(el, key, value
|
|
552
|
+
setSingleAttribute(el, key, resolve(value), state);
|
|
518
553
|
if (initialized) {
|
|
519
554
|
queueUpdatedHooks(owner);
|
|
520
555
|
}
|
|
@@ -572,19 +607,17 @@ function setSingleAttribute(el, key, value, state) {
|
|
|
572
607
|
function resolveAttributeName(key) {
|
|
573
608
|
return PROP_ALIASES[key] ?? key;
|
|
574
609
|
}
|
|
575
|
-
function applyStyle(el,
|
|
610
|
+
function applyStyle(el, value, state) {
|
|
611
|
+
const styleObj = normalizeStyle(value);
|
|
576
612
|
const nextProps = new Set;
|
|
577
|
-
for (const [prop, val] of Object.entries(
|
|
613
|
+
for (const [prop, val] of Object.entries(styleObj)) {
|
|
578
614
|
nextProps.add(prop);
|
|
579
615
|
if (val == null) {
|
|
580
616
|
removeStyleProperty(el, prop);
|
|
581
617
|
continue;
|
|
582
618
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
} else {
|
|
586
|
-
el.style[prop] = val;
|
|
587
|
-
}
|
|
619
|
+
const kebabProp = prop.startsWith("--") ? prop : camelToKebab(prop);
|
|
620
|
+
el.style.setProperty(kebabProp, String(val));
|
|
588
621
|
}
|
|
589
622
|
if (!state) {
|
|
590
623
|
return;
|
|
@@ -596,37 +629,77 @@ function applyStyle(el, styles, state) {
|
|
|
596
629
|
}
|
|
597
630
|
state.previousStyleProps = nextProps;
|
|
598
631
|
}
|
|
632
|
+
function normalizeStyle(value) {
|
|
633
|
+
const resolved = resolve(value);
|
|
634
|
+
if (!resolved)
|
|
635
|
+
return {};
|
|
636
|
+
if (typeof resolved === "string") {
|
|
637
|
+
return parseStyleString(resolved);
|
|
638
|
+
}
|
|
639
|
+
if (Array.isArray(resolved)) {
|
|
640
|
+
return resolved.reduce((acc, item) => {
|
|
641
|
+
const normalized = normalizeStyle(item);
|
|
642
|
+
return Object.assign(acc, normalized);
|
|
643
|
+
}, {});
|
|
644
|
+
}
|
|
645
|
+
if (typeof resolved === "object") {
|
|
646
|
+
const result = {};
|
|
647
|
+
for (const [k, v] of Object.entries(resolved)) {
|
|
648
|
+
result[k] = resolve(v);
|
|
649
|
+
}
|
|
650
|
+
return result;
|
|
651
|
+
}
|
|
652
|
+
return {};
|
|
653
|
+
}
|
|
654
|
+
function parseStyleString(style) {
|
|
655
|
+
const result = {};
|
|
656
|
+
style.split(";").forEach((rule) => {
|
|
657
|
+
const i = rule.indexOf(":");
|
|
658
|
+
if (i > 0) {
|
|
659
|
+
const prop = rule.slice(0, i).trim();
|
|
660
|
+
const val = rule.slice(i + 1).trim();
|
|
661
|
+
if (prop && val) {
|
|
662
|
+
result[prop] = val;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
return result;
|
|
667
|
+
}
|
|
599
668
|
function removeStyleProperty(el, prop) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
} else {
|
|
603
|
-
el.style[prop] = "";
|
|
604
|
-
}
|
|
669
|
+
const kebabProp = prop.startsWith("--") ? prop : camelToKebab(prop);
|
|
670
|
+
el.style.removeProperty(kebabProp);
|
|
605
671
|
}
|
|
606
672
|
function applyClass(el, value) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
673
|
+
domOps.setAttribute(el, "class", normalizeClass(value));
|
|
674
|
+
}
|
|
675
|
+
function normalizeClass(value) {
|
|
676
|
+
const resolved = resolve(value);
|
|
677
|
+
if (!resolved)
|
|
678
|
+
return "";
|
|
679
|
+
if (typeof resolved === "string")
|
|
680
|
+
return resolved;
|
|
681
|
+
if (Array.isArray(resolved)) {
|
|
682
|
+
return resolved.map(normalizeClass).filter(Boolean).join(" ");
|
|
614
683
|
}
|
|
615
|
-
|
|
684
|
+
if (typeof resolved === "object") {
|
|
685
|
+
return Object.entries(resolved).filter(([, v]) => Boolean(resolve(v))).map(([k]) => k).join(" ");
|
|
686
|
+
}
|
|
687
|
+
return String(resolved);
|
|
616
688
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
batchDepth--;
|
|
625
|
-
if (batchDepth === 0) {
|
|
626
|
-
flushSync();
|
|
627
|
-
}
|
|
689
|
+
function containsReactive(value) {
|
|
690
|
+
if (isReactive(value))
|
|
691
|
+
return true;
|
|
692
|
+
if (Array.isArray(value))
|
|
693
|
+
return value.some(containsReactive);
|
|
694
|
+
if (typeof value === "object" && value !== null) {
|
|
695
|
+
return Object.values(value).some(containsReactive);
|
|
628
696
|
}
|
|
697
|
+
return false;
|
|
629
698
|
}
|
|
699
|
+
function camelToKebab(str) {
|
|
700
|
+
return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
701
|
+
}
|
|
702
|
+
|
|
630
703
|
// src/component/control-flow.ts
|
|
631
704
|
var SHOW_TYPE = Symbol.for("Sinwan.Show");
|
|
632
705
|
var FOR_TYPE = Symbol.for("Sinwan.For");
|
|
@@ -720,6 +793,9 @@ function Portal(props) {
|
|
|
720
793
|
children: []
|
|
721
794
|
};
|
|
722
795
|
}
|
|
796
|
+
function isElementLike(value) {
|
|
797
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
798
|
+
}
|
|
723
799
|
function isShowElement(element) {
|
|
724
800
|
return element.tag === SHOW_TYPE;
|
|
725
801
|
}
|
|
@@ -744,6 +820,107 @@ function isDynamicElement(element) {
|
|
|
744
820
|
function isPortalElement(element) {
|
|
745
821
|
return element.tag === PORTAL_TYPE;
|
|
746
822
|
}
|
|
823
|
+
function resolveSwitchContent(element) {
|
|
824
|
+
const props = element.props;
|
|
825
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
826
|
+
const match = findTruthyMatch(children);
|
|
827
|
+
return match !== undefined ? match : props.fallback;
|
|
828
|
+
}
|
|
829
|
+
function findTruthyMatch(nodes) {
|
|
830
|
+
for (const node of nodes) {
|
|
831
|
+
if (node == null || typeof node === "boolean")
|
|
832
|
+
continue;
|
|
833
|
+
if (Array.isArray(node)) {
|
|
834
|
+
const match = findTruthyMatch(node);
|
|
835
|
+
if (match !== undefined)
|
|
836
|
+
return match;
|
|
837
|
+
continue;
|
|
838
|
+
}
|
|
839
|
+
if (isElementLike(node)) {
|
|
840
|
+
let element = node;
|
|
841
|
+
if (typeof element.tag === "function") {
|
|
842
|
+
const tag = element.tag;
|
|
843
|
+
if (tag === Match || tag === Show || tag === For || tag === Index || tag === Key || tag === Switch) {
|
|
844
|
+
element = tag(element.props);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (isMatchElement(element)) {
|
|
848
|
+
const when = readReactive(element.props.when);
|
|
849
|
+
if (when) {
|
|
850
|
+
return resolveMatchChildren(element, when);
|
|
851
|
+
}
|
|
852
|
+
} else if (isShowElement(element)) {
|
|
853
|
+
const when = readReactive(element.props.when);
|
|
854
|
+
if (when) {
|
|
855
|
+
const content = resolveShowChildren(element, when);
|
|
856
|
+
const match = findTruthyMatch(normalizeContent(content));
|
|
857
|
+
if (match !== undefined)
|
|
858
|
+
return match;
|
|
859
|
+
} else if (element.props.fallback) {
|
|
860
|
+
const match = findTruthyMatch(normalizeContent(element.props.fallback));
|
|
861
|
+
if (match !== undefined)
|
|
862
|
+
return match;
|
|
863
|
+
}
|
|
864
|
+
} else if (isForElement(element)) {
|
|
865
|
+
const props = element.props;
|
|
866
|
+
const items = readReactive(props.each);
|
|
867
|
+
if (Array.isArray(items)) {
|
|
868
|
+
for (let i = 0;i < items.length; i++) {
|
|
869
|
+
const child = props.children(items[i], () => i);
|
|
870
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
871
|
+
if (match !== undefined)
|
|
872
|
+
return match;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
} else if (isIndexElement(element)) {
|
|
876
|
+
const props = element.props;
|
|
877
|
+
const items = readReactive(props.each);
|
|
878
|
+
if (Array.isArray(items)) {
|
|
879
|
+
for (let i = 0;i < items.length; i++) {
|
|
880
|
+
const child = props.children(() => items[i], i);
|
|
881
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
882
|
+
if (match !== undefined)
|
|
883
|
+
return match;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
} else if (isKeyElement(element)) {
|
|
887
|
+
const key = readReactive(element.props.when);
|
|
888
|
+
const child = resolveKeyChildren(element, key);
|
|
889
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
890
|
+
if (match !== undefined)
|
|
891
|
+
return match;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
function resolveMatchChildren(element, value) {
|
|
898
|
+
const children = element.props.children ?? element.children;
|
|
899
|
+
if (typeof children === "function") {
|
|
900
|
+
return children(value);
|
|
901
|
+
}
|
|
902
|
+
return children;
|
|
903
|
+
}
|
|
904
|
+
function resolveShowChildren(element, value) {
|
|
905
|
+
const children = element.props.children ?? element.children;
|
|
906
|
+
if (typeof children === "function") {
|
|
907
|
+
return children(value);
|
|
908
|
+
}
|
|
909
|
+
return children;
|
|
910
|
+
}
|
|
911
|
+
function resolveKeyChildren(element, value) {
|
|
912
|
+
const children = element.props.children ?? element.children;
|
|
913
|
+
if (typeof children === "function") {
|
|
914
|
+
return children(value);
|
|
915
|
+
}
|
|
916
|
+
return children;
|
|
917
|
+
}
|
|
918
|
+
function normalizeContent(content) {
|
|
919
|
+
if (content == null || typeof content === "boolean") {
|
|
920
|
+
return [];
|
|
921
|
+
}
|
|
922
|
+
return Array.isArray(content) ? content : [content];
|
|
923
|
+
}
|
|
747
924
|
function normalizeChildren2(children) {
|
|
748
925
|
if (children == null || typeof children === "boolean") {
|
|
749
926
|
return [];
|
|
@@ -751,7 +928,7 @@ function normalizeChildren2(children) {
|
|
|
751
928
|
return Array.isArray(children) ? children : [children];
|
|
752
929
|
}
|
|
753
930
|
function readReactive(value) {
|
|
754
|
-
return
|
|
931
|
+
return resolve(value);
|
|
755
932
|
}
|
|
756
933
|
function appendHiddenDisplay(style) {
|
|
757
934
|
const trimmed = style.trim();
|
|
@@ -883,8 +1060,10 @@ function renderShowBlock(element, block, parent, namespace, owner) {
|
|
|
883
1060
|
return effect(() => {
|
|
884
1061
|
clearChildren(block);
|
|
885
1062
|
const when = readReactive2(element.props.when);
|
|
886
|
-
|
|
887
|
-
|
|
1063
|
+
block.children = withOptionalInstance(owner, () => {
|
|
1064
|
+
const content = when ? resolveShowChildren(element, when) : element.props.fallback;
|
|
1065
|
+
return renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1066
|
+
});
|
|
888
1067
|
if (initialized) {
|
|
889
1068
|
fireMountedAndQueueUpdated(owner);
|
|
890
1069
|
}
|
|
@@ -1071,18 +1250,31 @@ function renderPortal(element, parent, anchor, namespace) {
|
|
|
1071
1250
|
insertNode(parent, placeholder, anchor);
|
|
1072
1251
|
const owner = getCurrentInstance();
|
|
1073
1252
|
let disposeEffect = () => {};
|
|
1253
|
+
const targetAnchor = domOps.createComment("Sinwan-pa");
|
|
1254
|
+
let lastTarget = null;
|
|
1074
1255
|
const portal = {
|
|
1075
1256
|
type: "portal",
|
|
1076
1257
|
anchor: placeholder,
|
|
1077
1258
|
children: [],
|
|
1078
|
-
dispose: () => disposeEffect()
|
|
1259
|
+
dispose: () => disposeEffect(),
|
|
1260
|
+
targetAnchor
|
|
1079
1261
|
};
|
|
1080
1262
|
let initialized = false;
|
|
1081
1263
|
disposeEffect = effect(() => {
|
|
1082
|
-
clearPortalChildren(portal);
|
|
1083
1264
|
const target = resolvePortalTarget(element.props.mount);
|
|
1265
|
+
if (target !== lastTarget) {
|
|
1266
|
+
if (lastTarget) {
|
|
1267
|
+
domOps.remove(targetAnchor);
|
|
1268
|
+
}
|
|
1269
|
+
if (target) {
|
|
1270
|
+
domOps.appendChild(target, targetAnchor);
|
|
1271
|
+
}
|
|
1272
|
+
lastTarget = target;
|
|
1273
|
+
portal.target = target;
|
|
1274
|
+
}
|
|
1275
|
+
clearPortalChildren(portal);
|
|
1084
1276
|
if (target) {
|
|
1085
|
-
portal.children = renderBlockContent(element.props.children ?? element.children, target,
|
|
1277
|
+
portal.children = renderBlockContent(element.props.children ?? element.children, target, targetAnchor, namespace, owner);
|
|
1086
1278
|
}
|
|
1087
1279
|
if (initialized) {
|
|
1088
1280
|
fireMountedAndQueueUpdated(owner);
|
|
@@ -1091,48 +1283,12 @@ function renderPortal(element, parent, anchor, namespace) {
|
|
|
1091
1283
|
});
|
|
1092
1284
|
return portal;
|
|
1093
1285
|
}
|
|
1094
|
-
function resolveShowChildren(element, value) {
|
|
1095
|
-
const children = element.props.children ?? element.children;
|
|
1096
|
-
if (typeof children === "function") {
|
|
1097
|
-
return children(value);
|
|
1098
|
-
}
|
|
1099
|
-
return children;
|
|
1100
|
-
}
|
|
1101
|
-
function resolveSwitchContent(element) {
|
|
1102
|
-
const props = element.props;
|
|
1103
|
-
const children = normalizeContent(props.children ?? element.children);
|
|
1104
|
-
for (const child of children) {
|
|
1105
|
-
const match = getMatchElement(child);
|
|
1106
|
-
if (!match) {
|
|
1107
|
-
continue;
|
|
1108
|
-
}
|
|
1109
|
-
const when = readReactive2(match.props.when);
|
|
1110
|
-
if (when) {
|
|
1111
|
-
return resolveMatchChildren(match, when);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
return props.fallback;
|
|
1115
|
-
}
|
|
1116
|
-
function resolveMatchChildren(element, value) {
|
|
1117
|
-
const children = element.props.children ?? element.children;
|
|
1118
|
-
if (typeof children === "function") {
|
|
1119
|
-
return children(value);
|
|
1120
|
-
}
|
|
1121
|
-
return children;
|
|
1122
|
-
}
|
|
1123
|
-
function resolveKeyChildren(element, value) {
|
|
1124
|
-
const children = element.props.children ?? element.children;
|
|
1125
|
-
if (typeof children === "function") {
|
|
1126
|
-
return children(value);
|
|
1127
|
-
}
|
|
1128
|
-
return children;
|
|
1129
|
-
}
|
|
1130
1286
|
function createDynamicElement(element, tag) {
|
|
1131
1287
|
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
1132
1288
|
return null;
|
|
1133
1289
|
}
|
|
1134
1290
|
const { component, ...props } = element.props;
|
|
1135
|
-
const children =
|
|
1291
|
+
const children = normalizeContent2(props.children ?? element.children);
|
|
1136
1292
|
return {
|
|
1137
1293
|
tag,
|
|
1138
1294
|
props,
|
|
@@ -1140,11 +1296,14 @@ function createDynamicElement(element, tag) {
|
|
|
1140
1296
|
};
|
|
1141
1297
|
}
|
|
1142
1298
|
function renderBlockContent(content, parent, anchor, namespace, owner) {
|
|
1143
|
-
if (content == null || typeof content === "boolean")
|
|
1299
|
+
if (content == null || typeof content === "boolean")
|
|
1144
1300
|
return [];
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1301
|
+
return withOptionalInstance(owner, () => {
|
|
1302
|
+
if (Array.isArray(content)) {
|
|
1303
|
+
return content.map((child) => renderNodeToDOM(child, parent, anchor, namespace));
|
|
1304
|
+
}
|
|
1305
|
+
return [renderNodeToDOM(content, parent, anchor, namespace)];
|
|
1306
|
+
});
|
|
1148
1307
|
}
|
|
1149
1308
|
function clearChildren(block) {
|
|
1150
1309
|
for (const child of block.children) {
|
|
@@ -1162,6 +1321,23 @@ function moveBeforeEnd(parent, mounted, endAnchor) {
|
|
|
1162
1321
|
for (const node of getMountedDomNodes(mounted)) {
|
|
1163
1322
|
domOps.insertBefore(parent, node, endAnchor);
|
|
1164
1323
|
}
|
|
1324
|
+
syncPortalOrder(mounted);
|
|
1325
|
+
}
|
|
1326
|
+
function syncPortalOrder(mounted) {
|
|
1327
|
+
if (mounted.type === "portal") {
|
|
1328
|
+
if (mounted.target && mounted.targetAnchor) {
|
|
1329
|
+
for (const child of mounted.children) {
|
|
1330
|
+
for (const node of getMountedDomNodes(child)) {
|
|
1331
|
+
domOps.appendChild(mounted.target, node);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
domOps.appendChild(mounted.target, mounted.targetAnchor);
|
|
1335
|
+
}
|
|
1336
|
+
} else if ("children" in mounted && Array.isArray(mounted.children)) {
|
|
1337
|
+
for (const child of mounted.children) {
|
|
1338
|
+
syncPortalOrder(child);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1165
1341
|
}
|
|
1166
1342
|
function fireMountedAndQueueUpdated(owner) {
|
|
1167
1343
|
if (owner) {
|
|
@@ -1173,26 +1349,14 @@ function withOptionalInstance(owner, fn) {
|
|
|
1173
1349
|
return owner ? withInstance(owner, fn) : fn();
|
|
1174
1350
|
}
|
|
1175
1351
|
function readReactive2(value) {
|
|
1176
|
-
return
|
|
1352
|
+
return resolve(value);
|
|
1177
1353
|
}
|
|
1178
|
-
function
|
|
1354
|
+
function normalizeContent2(content) {
|
|
1179
1355
|
if (content == null || typeof content === "boolean") {
|
|
1180
1356
|
return [];
|
|
1181
1357
|
}
|
|
1182
1358
|
return Array.isArray(content) ? content : [content];
|
|
1183
1359
|
}
|
|
1184
|
-
function isElementLike(value) {
|
|
1185
|
-
return value != null && typeof value === "object" && "tag" in value;
|
|
1186
|
-
}
|
|
1187
|
-
function getMatchElement(value) {
|
|
1188
|
-
if (!isElementLike(value)) {
|
|
1189
|
-
return null;
|
|
1190
|
-
}
|
|
1191
|
-
if (isMatchElement(value)) {
|
|
1192
|
-
return value;
|
|
1193
|
-
}
|
|
1194
|
-
return value.tag === Match ? Match(value.props) : null;
|
|
1195
|
-
}
|
|
1196
1360
|
function resolvePortalTarget(value) {
|
|
1197
1361
|
const target = readReactive2(value);
|
|
1198
1362
|
if (target == null) {
|
|
@@ -1394,19 +1558,8 @@ function renderNodeToDOM(node, parent, anchor = null, namespace = null) {
|
|
|
1394
1558
|
insertNode2(parent, text2, anchor);
|
|
1395
1559
|
return { type: "text", node: text2 };
|
|
1396
1560
|
}
|
|
1397
|
-
if (
|
|
1398
|
-
|
|
1399
|
-
insertNode2(parent, text2, anchor);
|
|
1400
|
-
const owner = getCurrentInstance();
|
|
1401
|
-
let initialized = false;
|
|
1402
|
-
const dispose = effect(() => {
|
|
1403
|
-
domOps.setTextContent(text2, String(node.value));
|
|
1404
|
-
if (initialized) {
|
|
1405
|
-
queueUpdatedHooks(owner);
|
|
1406
|
-
}
|
|
1407
|
-
initialized = true;
|
|
1408
|
-
});
|
|
1409
|
-
return { type: "reactive-text", node: text2, dispose };
|
|
1561
|
+
if (isReactive(node)) {
|
|
1562
|
+
return renderReactiveNodeToDOM(node, parent, anchor, namespace);
|
|
1410
1563
|
}
|
|
1411
1564
|
if (Array.isArray(node)) {
|
|
1412
1565
|
return renderArrayToDOM(node, parent, anchor, namespace);
|
|
@@ -1443,6 +1596,37 @@ function renderChildrenToDOM(children, parent, namespace = null) {
|
|
|
1443
1596
|
}
|
|
1444
1597
|
return mounted;
|
|
1445
1598
|
}
|
|
1599
|
+
function renderReactiveNodeToDOM(reactive, parent, anchor, namespace) {
|
|
1600
|
+
const startAnchor = domOps.createComment("Sinwan-r");
|
|
1601
|
+
const endAnchor = domOps.createComment("/Sinwan-r");
|
|
1602
|
+
insertNode2(parent, startAnchor, anchor);
|
|
1603
|
+
insertNode2(parent, endAnchor, anchor);
|
|
1604
|
+
const owner = getCurrentInstance();
|
|
1605
|
+
let mountedContent = null;
|
|
1606
|
+
let initialized = false;
|
|
1607
|
+
const block = {
|
|
1608
|
+
type: "reactive-block",
|
|
1609
|
+
startAnchor,
|
|
1610
|
+
endAnchor,
|
|
1611
|
+
children: [],
|
|
1612
|
+
dispose: () => {}
|
|
1613
|
+
};
|
|
1614
|
+
block.dispose = effect(() => {
|
|
1615
|
+
if (mountedContent) {
|
|
1616
|
+
removeMountedNode(mountedContent);
|
|
1617
|
+
}
|
|
1618
|
+
const value = resolve(reactive);
|
|
1619
|
+
mountedContent = renderNodeToDOM(value, parent, endAnchor, namespace);
|
|
1620
|
+
block.children = [mountedContent];
|
|
1621
|
+
if (initialized) {
|
|
1622
|
+
if (owner)
|
|
1623
|
+
fireMountedHooks(owner);
|
|
1624
|
+
queueUpdatedHooks(owner);
|
|
1625
|
+
}
|
|
1626
|
+
initialized = true;
|
|
1627
|
+
});
|
|
1628
|
+
return block;
|
|
1629
|
+
}
|
|
1446
1630
|
function insertNode2(parent, child, anchor) {
|
|
1447
1631
|
if (anchor) {
|
|
1448
1632
|
domOps.insertBefore(parent, child, anchor);
|
|
@@ -1629,24 +1813,24 @@ async function renderElement(element) {
|
|
|
1629
1813
|
}
|
|
1630
1814
|
if (isShowElement(element)) {
|
|
1631
1815
|
const when = readReactive3(props.when);
|
|
1632
|
-
return renderToString(when ?
|
|
1816
|
+
return renderToString(when ? resolveShowChildren(element, when) : props.fallback);
|
|
1633
1817
|
}
|
|
1634
1818
|
if (isForElement(element)) {
|
|
1635
1819
|
return renderForElement(element);
|
|
1636
1820
|
}
|
|
1637
1821
|
if (isSwitchElement(element)) {
|
|
1638
|
-
return renderToString(
|
|
1822
|
+
return renderToString(resolveSwitchContent(element));
|
|
1639
1823
|
}
|
|
1640
1824
|
if (isMatchElement(element)) {
|
|
1641
1825
|
const when = readReactive3(props.when);
|
|
1642
|
-
return renderToString(when ?
|
|
1826
|
+
return renderToString(when ? resolveMatchChildren(element, when) : null);
|
|
1643
1827
|
}
|
|
1644
1828
|
if (isIndexElement(element)) {
|
|
1645
1829
|
return renderIndexElement(element);
|
|
1646
1830
|
}
|
|
1647
1831
|
if (isKeyElement(element)) {
|
|
1648
1832
|
const key = readReactive3(props.when);
|
|
1649
|
-
return renderToString(
|
|
1833
|
+
return renderToString(resolveKeyChildren(element, key));
|
|
1650
1834
|
}
|
|
1651
1835
|
if (isDynamicElement(element)) {
|
|
1652
1836
|
const tag2 = readReactive3(props.component);
|
|
@@ -1736,75 +1920,27 @@ async function renderIndexElement(element) {
|
|
|
1736
1920
|
const rendered = await Promise.all(each.map((item, index) => renderToString(props.children(() => item, index))));
|
|
1737
1921
|
return rendered.join("");
|
|
1738
1922
|
}
|
|
1739
|
-
function resolveSwitchContent2(element) {
|
|
1740
|
-
const props = element.props;
|
|
1741
|
-
const children = normalizeContent2(props.children ?? element.children);
|
|
1742
|
-
for (const child of children) {
|
|
1743
|
-
const match = getMatchElement2(child);
|
|
1744
|
-
if (!match) {
|
|
1745
|
-
continue;
|
|
1746
|
-
}
|
|
1747
|
-
const when = readReactive3(match.props.when);
|
|
1748
|
-
if (when) {
|
|
1749
|
-
return resolveMatchChildren2(match, when);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
return props.fallback;
|
|
1753
|
-
}
|
|
1754
|
-
function resolveMatchChildren2(element, value) {
|
|
1755
|
-
const children = element.props.children ?? element.children;
|
|
1756
|
-
if (typeof children === "function") {
|
|
1757
|
-
return children(value);
|
|
1758
|
-
}
|
|
1759
|
-
return children;
|
|
1760
|
-
}
|
|
1761
|
-
function resolveKeyChildren2(element, value) {
|
|
1762
|
-
const children = element.props.children ?? element.children;
|
|
1763
|
-
if (typeof children === "function") {
|
|
1764
|
-
return children(value);
|
|
1765
|
-
}
|
|
1766
|
-
return children;
|
|
1767
|
-
}
|
|
1768
1923
|
function createDynamicElement2(element, tag) {
|
|
1769
1924
|
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
1770
1925
|
return null;
|
|
1771
1926
|
}
|
|
1772
1927
|
const { component, ...props } = element.props;
|
|
1773
|
-
const children =
|
|
1928
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1774
1929
|
return {
|
|
1775
1930
|
tag,
|
|
1776
1931
|
props,
|
|
1777
1932
|
children
|
|
1778
1933
|
};
|
|
1779
1934
|
}
|
|
1780
|
-
function resolveShowChildren2(element, value) {
|
|
1781
|
-
const children = element.props.children ?? element.children;
|
|
1782
|
-
if (typeof children === "function") {
|
|
1783
|
-
return children(value);
|
|
1784
|
-
}
|
|
1785
|
-
return children;
|
|
1786
|
-
}
|
|
1787
1935
|
function readReactive3(value) {
|
|
1788
1936
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1789
1937
|
}
|
|
1790
|
-
function
|
|
1938
|
+
function normalizeContent3(content) {
|
|
1791
1939
|
if (content == null || typeof content === "boolean") {
|
|
1792
1940
|
return [];
|
|
1793
1941
|
}
|
|
1794
1942
|
return Array.isArray(content) ? content : [content];
|
|
1795
1943
|
}
|
|
1796
|
-
function isElementLike2(value) {
|
|
1797
|
-
return value != null && typeof value === "object" && "tag" in value;
|
|
1798
|
-
}
|
|
1799
|
-
function getMatchElement2(value) {
|
|
1800
|
-
if (!isElementLike2(value)) {
|
|
1801
|
-
return null;
|
|
1802
|
-
}
|
|
1803
|
-
if (isMatchElement(value)) {
|
|
1804
|
-
return value;
|
|
1805
|
-
}
|
|
1806
|
-
return value.tag === Match ? Match(value.props) : null;
|
|
1807
|
-
}
|
|
1808
1944
|
// src/hydration/markers.ts
|
|
1809
1945
|
var COMP_ID_ATTR = "data-sinwan-id";
|
|
1810
1946
|
var COMP_ID_PREFIX = "c";
|
|
@@ -1939,7 +2075,7 @@ async function streamElement(element, controller, encoder) {
|
|
|
1939
2075
|
}
|
|
1940
2076
|
if (isShowElement(element)) {
|
|
1941
2077
|
const when = readReactive4(props.when);
|
|
1942
|
-
await streamNode(when ?
|
|
2078
|
+
await streamNode(when ? resolveShowChildren2(element, when) : props.fallback, controller, encoder);
|
|
1943
2079
|
return;
|
|
1944
2080
|
}
|
|
1945
2081
|
if (isForElement(element)) {
|
|
@@ -1947,12 +2083,12 @@ async function streamElement(element, controller, encoder) {
|
|
|
1947
2083
|
return;
|
|
1948
2084
|
}
|
|
1949
2085
|
if (isSwitchElement(element)) {
|
|
1950
|
-
await streamNode(
|
|
2086
|
+
await streamNode(resolveSwitchContent2(element), controller, encoder);
|
|
1951
2087
|
return;
|
|
1952
2088
|
}
|
|
1953
2089
|
if (isMatchElement(element)) {
|
|
1954
2090
|
const when = readReactive4(props.when);
|
|
1955
|
-
await streamNode(when ?
|
|
2091
|
+
await streamNode(when ? resolveMatchChildren2(element, when) : null, controller, encoder);
|
|
1956
2092
|
return;
|
|
1957
2093
|
}
|
|
1958
2094
|
if (isIndexElement(element)) {
|
|
@@ -1961,7 +2097,7 @@ async function streamElement(element, controller, encoder) {
|
|
|
1961
2097
|
}
|
|
1962
2098
|
if (isKeyElement(element)) {
|
|
1963
2099
|
const key = readReactive4(props.when);
|
|
1964
|
-
await streamNode(
|
|
2100
|
+
await streamNode(resolveKeyChildren2(element, key), controller, encoder);
|
|
1965
2101
|
return;
|
|
1966
2102
|
}
|
|
1967
2103
|
if (isDynamicElement(element)) {
|
|
@@ -2067,7 +2203,7 @@ async function streamHydratableElement(element, controller, encoder, ctx, isComp
|
|
|
2067
2203
|
}
|
|
2068
2204
|
if (isShowElement(element)) {
|
|
2069
2205
|
const when = readReactive4(props.when);
|
|
2070
|
-
await streamHydratableNodeToController(when ?
|
|
2206
|
+
await streamHydratableNodeToController(when ? resolveShowChildren2(element, when) : props.fallback, controller, encoder, ctx, isComponentRoot);
|
|
2071
2207
|
return;
|
|
2072
2208
|
}
|
|
2073
2209
|
if (isForElement(element)) {
|
|
@@ -2075,12 +2211,12 @@ async function streamHydratableElement(element, controller, encoder, ctx, isComp
|
|
|
2075
2211
|
return;
|
|
2076
2212
|
}
|
|
2077
2213
|
if (isSwitchElement(element)) {
|
|
2078
|
-
await streamHydratableNodeToController(
|
|
2214
|
+
await streamHydratableNodeToController(resolveSwitchContent2(element), controller, encoder, ctx, isComponentRoot);
|
|
2079
2215
|
return;
|
|
2080
2216
|
}
|
|
2081
2217
|
if (isMatchElement(element)) {
|
|
2082
2218
|
const when = readReactive4(props.when);
|
|
2083
|
-
await streamHydratableNodeToController(when ?
|
|
2219
|
+
await streamHydratableNodeToController(when ? resolveMatchChildren2(element, when) : null, controller, encoder, ctx, isComponentRoot);
|
|
2084
2220
|
return;
|
|
2085
2221
|
}
|
|
2086
2222
|
if (isIndexElement(element)) {
|
|
@@ -2089,7 +2225,7 @@ async function streamHydratableElement(element, controller, encoder, ctx, isComp
|
|
|
2089
2225
|
}
|
|
2090
2226
|
if (isKeyElement(element)) {
|
|
2091
2227
|
const key = readReactive4(props.when);
|
|
2092
|
-
await streamHydratableNodeToController(
|
|
2228
|
+
await streamHydratableNodeToController(resolveKeyChildren2(element, key), controller, encoder, ctx, isComponentRoot);
|
|
2093
2229
|
return;
|
|
2094
2230
|
}
|
|
2095
2231
|
if (isDynamicElement(element)) {
|
|
@@ -2246,36 +2382,36 @@ async function streamIndexElement(element, controller, encoder) {
|
|
|
2246
2382
|
await streamNode(props.children(() => each[index], index), controller, encoder);
|
|
2247
2383
|
}
|
|
2248
2384
|
}
|
|
2249
|
-
function
|
|
2385
|
+
function resolveShowChildren2(element, value) {
|
|
2250
2386
|
const children = element.props.children ?? element.children;
|
|
2251
2387
|
if (typeof children === "function") {
|
|
2252
2388
|
return children(value);
|
|
2253
2389
|
}
|
|
2254
2390
|
return children;
|
|
2255
2391
|
}
|
|
2256
|
-
function
|
|
2392
|
+
function resolveSwitchContent2(element) {
|
|
2257
2393
|
const props = element.props;
|
|
2258
|
-
const children =
|
|
2394
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
2259
2395
|
for (const child of children) {
|
|
2260
|
-
const match =
|
|
2396
|
+
const match = getMatchElement(child);
|
|
2261
2397
|
if (!match) {
|
|
2262
2398
|
continue;
|
|
2263
2399
|
}
|
|
2264
2400
|
const when = readReactive4(match.props.when);
|
|
2265
2401
|
if (when) {
|
|
2266
|
-
return
|
|
2402
|
+
return resolveMatchChildren2(match, when);
|
|
2267
2403
|
}
|
|
2268
2404
|
}
|
|
2269
2405
|
return props.fallback;
|
|
2270
2406
|
}
|
|
2271
|
-
function
|
|
2407
|
+
function resolveMatchChildren2(element, value) {
|
|
2272
2408
|
const children = element.props.children ?? element.children;
|
|
2273
2409
|
if (typeof children === "function") {
|
|
2274
2410
|
return children(value);
|
|
2275
2411
|
}
|
|
2276
2412
|
return children;
|
|
2277
2413
|
}
|
|
2278
|
-
function
|
|
2414
|
+
function resolveKeyChildren2(element, value) {
|
|
2279
2415
|
const children = element.props.children ?? element.children;
|
|
2280
2416
|
if (typeof children === "function") {
|
|
2281
2417
|
return children(value);
|
|
@@ -2287,7 +2423,7 @@ function createDynamicElement3(element, tag) {
|
|
|
2287
2423
|
return null;
|
|
2288
2424
|
}
|
|
2289
2425
|
const { component, ...props } = element.props;
|
|
2290
|
-
const children =
|
|
2426
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
2291
2427
|
return {
|
|
2292
2428
|
tag,
|
|
2293
2429
|
props,
|
|
@@ -2297,17 +2433,17 @@ function createDynamicElement3(element, tag) {
|
|
|
2297
2433
|
function readReactive4(value) {
|
|
2298
2434
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
2299
2435
|
}
|
|
2300
|
-
function
|
|
2436
|
+
function normalizeContent4(content) {
|
|
2301
2437
|
if (content == null || typeof content === "boolean") {
|
|
2302
2438
|
return [];
|
|
2303
2439
|
}
|
|
2304
2440
|
return Array.isArray(content) ? content : [content];
|
|
2305
2441
|
}
|
|
2306
|
-
function
|
|
2442
|
+
function isElementLike2(value) {
|
|
2307
2443
|
return value != null && typeof value === "object" && "tag" in value;
|
|
2308
2444
|
}
|
|
2309
|
-
function
|
|
2310
|
-
if (!
|
|
2445
|
+
function getMatchElement(value) {
|
|
2446
|
+
if (!isElementLike2(value)) {
|
|
2311
2447
|
return null;
|
|
2312
2448
|
}
|
|
2313
2449
|
if (isMatchElement(value)) {
|
|
@@ -2392,25 +2528,25 @@ function renderElementH(element, ctx, isComponentRoot) {
|
|
|
2392
2528
|
}
|
|
2393
2529
|
if (isShowElement(element)) {
|
|
2394
2530
|
const when = readReactive5(props.when);
|
|
2395
|
-
const content = when ?
|
|
2531
|
+
const content = when ? resolveShowChildren3(element, when) : props.fallback;
|
|
2396
2532
|
return renderNodeMaybeRoot(content, ctx, isComponentRoot);
|
|
2397
2533
|
}
|
|
2398
2534
|
if (isForElement(element)) {
|
|
2399
2535
|
return renderForElementH(element, ctx);
|
|
2400
2536
|
}
|
|
2401
2537
|
if (isSwitchElement(element)) {
|
|
2402
|
-
return renderNodeMaybeRoot(
|
|
2538
|
+
return renderNodeMaybeRoot(resolveSwitchContent3(element), ctx, isComponentRoot);
|
|
2403
2539
|
}
|
|
2404
2540
|
if (isMatchElement(element)) {
|
|
2405
2541
|
const when = readReactive5(props.when);
|
|
2406
|
-
return renderNodeMaybeRoot(when ?
|
|
2542
|
+
return renderNodeMaybeRoot(when ? resolveMatchChildren3(element, when) : null, ctx, isComponentRoot);
|
|
2407
2543
|
}
|
|
2408
2544
|
if (isIndexElement(element)) {
|
|
2409
2545
|
return renderIndexElementH(element, ctx);
|
|
2410
2546
|
}
|
|
2411
2547
|
if (isKeyElement(element)) {
|
|
2412
2548
|
const key = readReactive5(props.when);
|
|
2413
|
-
return renderNodeMaybeRoot(
|
|
2549
|
+
return renderNodeMaybeRoot(resolveKeyChildren3(element, key), ctx, isComponentRoot);
|
|
2414
2550
|
}
|
|
2415
2551
|
if (isDynamicElement(element)) {
|
|
2416
2552
|
const dynamicTag = readReactive5(props.component);
|
|
@@ -2509,36 +2645,36 @@ function renderIndexElementH(element, ctx) {
|
|
|
2509
2645
|
}
|
|
2510
2646
|
return each.map((item, index) => renderNodeH(props.children(() => item, index), ctx)).join("");
|
|
2511
2647
|
}
|
|
2512
|
-
function
|
|
2648
|
+
function resolveShowChildren3(element, value) {
|
|
2513
2649
|
const children = element.props.children ?? element.children;
|
|
2514
2650
|
if (typeof children === "function") {
|
|
2515
2651
|
return children(value);
|
|
2516
2652
|
}
|
|
2517
2653
|
return children;
|
|
2518
2654
|
}
|
|
2519
|
-
function
|
|
2655
|
+
function resolveSwitchContent3(element) {
|
|
2520
2656
|
const props = element.props;
|
|
2521
|
-
const children =
|
|
2657
|
+
const children = normalizeContent5(props.children ?? element.children);
|
|
2522
2658
|
for (const child of children) {
|
|
2523
|
-
const match =
|
|
2659
|
+
const match = getMatchElement2(child);
|
|
2524
2660
|
if (!match) {
|
|
2525
2661
|
continue;
|
|
2526
2662
|
}
|
|
2527
2663
|
const when = readReactive5(match.props.when);
|
|
2528
2664
|
if (when) {
|
|
2529
|
-
return
|
|
2665
|
+
return resolveMatchChildren3(match, when);
|
|
2530
2666
|
}
|
|
2531
2667
|
}
|
|
2532
2668
|
return props.fallback;
|
|
2533
2669
|
}
|
|
2534
|
-
function
|
|
2670
|
+
function resolveMatchChildren3(element, value) {
|
|
2535
2671
|
const children = element.props.children ?? element.children;
|
|
2536
2672
|
if (typeof children === "function") {
|
|
2537
2673
|
return children(value);
|
|
2538
2674
|
}
|
|
2539
2675
|
return children;
|
|
2540
2676
|
}
|
|
2541
|
-
function
|
|
2677
|
+
function resolveKeyChildren3(element, value) {
|
|
2542
2678
|
const children = element.props.children ?? element.children;
|
|
2543
2679
|
if (typeof children === "function") {
|
|
2544
2680
|
return children(value);
|
|
@@ -2550,7 +2686,7 @@ function createDynamicElement4(element, tag) {
|
|
|
2550
2686
|
return null;
|
|
2551
2687
|
}
|
|
2552
2688
|
const { component, ...props } = element.props;
|
|
2553
|
-
const children =
|
|
2689
|
+
const children = normalizeContent5(props.children ?? element.children);
|
|
2554
2690
|
return {
|
|
2555
2691
|
tag,
|
|
2556
2692
|
props,
|
|
@@ -2560,17 +2696,17 @@ function createDynamicElement4(element, tag) {
|
|
|
2560
2696
|
function readReactive5(value) {
|
|
2561
2697
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
2562
2698
|
}
|
|
2563
|
-
function
|
|
2699
|
+
function normalizeContent5(content) {
|
|
2564
2700
|
if (content == null || typeof content === "boolean") {
|
|
2565
2701
|
return [];
|
|
2566
2702
|
}
|
|
2567
2703
|
return Array.isArray(content) ? content : [content];
|
|
2568
2704
|
}
|
|
2569
|
-
function
|
|
2705
|
+
function isElementLike3(value) {
|
|
2570
2706
|
return value != null && typeof value === "object" && "tag" in value;
|
|
2571
2707
|
}
|
|
2572
|
-
function
|
|
2573
|
-
if (!
|
|
2708
|
+
function getMatchElement2(value) {
|
|
2709
|
+
if (!isElementLike3(value)) {
|
|
2574
2710
|
return null;
|
|
2575
2711
|
}
|
|
2576
2712
|
if (isMatchElement(value)) {
|
|
@@ -2802,7 +2938,7 @@ function hydrateAttributes(el, props) {
|
|
|
2802
2938
|
function hydrateControlFlow(element, cursor) {
|
|
2803
2939
|
if (isShowElement(element)) {
|
|
2804
2940
|
const when = readReactive6(element.props.when);
|
|
2805
|
-
const content = when ?
|
|
2941
|
+
const content = when ? resolveShowChildren4(element, when) : element.props.fallback;
|
|
2806
2942
|
return hydrateContent(content, cursor);
|
|
2807
2943
|
}
|
|
2808
2944
|
if (isForElement(element)) {
|
|
@@ -2812,7 +2948,7 @@ function hydrateControlFlow(element, cursor) {
|
|
|
2812
2948
|
return hydrateArray(children, cursor);
|
|
2813
2949
|
}
|
|
2814
2950
|
if (isSwitchElement(element)) {
|
|
2815
|
-
return hydrateContent(
|
|
2951
|
+
return hydrateContent(resolveSwitchContent4(element), cursor);
|
|
2816
2952
|
}
|
|
2817
2953
|
if (isIndexElement(element)) {
|
|
2818
2954
|
const props = element.props;
|
|
@@ -2822,7 +2958,7 @@ function hydrateControlFlow(element, cursor) {
|
|
|
2822
2958
|
}
|
|
2823
2959
|
if (isKeyElement(element)) {
|
|
2824
2960
|
const key = readReactive6(element.props.when);
|
|
2825
|
-
return hydrateContent(
|
|
2961
|
+
return hydrateContent(resolveKeyChildren4(element, key), cursor);
|
|
2826
2962
|
}
|
|
2827
2963
|
if (isDynamicElement(element)) {
|
|
2828
2964
|
const tag = readReactive6(element.props.component);
|
|
@@ -2837,36 +2973,36 @@ function hydrateContent(content, cursor) {
|
|
|
2837
2973
|
}
|
|
2838
2974
|
return Array.isArray(content) ? hydrateArray(content, cursor) : hydrateNode(content, cursor);
|
|
2839
2975
|
}
|
|
2840
|
-
function
|
|
2976
|
+
function resolveShowChildren4(element, value) {
|
|
2841
2977
|
const children = element.props.children ?? element.children;
|
|
2842
2978
|
if (typeof children === "function") {
|
|
2843
2979
|
return children(value);
|
|
2844
2980
|
}
|
|
2845
2981
|
return children;
|
|
2846
2982
|
}
|
|
2847
|
-
function
|
|
2983
|
+
function resolveSwitchContent4(element) {
|
|
2848
2984
|
const props = element.props;
|
|
2849
|
-
const children =
|
|
2985
|
+
const children = normalizeContent6(props.children ?? element.children);
|
|
2850
2986
|
for (const child of children) {
|
|
2851
|
-
const match =
|
|
2987
|
+
const match = getMatchElement3(child);
|
|
2852
2988
|
if (!match) {
|
|
2853
2989
|
continue;
|
|
2854
2990
|
}
|
|
2855
2991
|
const when = readReactive6(match.props.when);
|
|
2856
2992
|
if (when) {
|
|
2857
|
-
return
|
|
2993
|
+
return resolveMatchChildren4(match, when);
|
|
2858
2994
|
}
|
|
2859
2995
|
}
|
|
2860
2996
|
return props.fallback;
|
|
2861
2997
|
}
|
|
2862
|
-
function
|
|
2998
|
+
function resolveMatchChildren4(element, value) {
|
|
2863
2999
|
const children = element.props.children ?? element.children;
|
|
2864
3000
|
if (typeof children === "function") {
|
|
2865
3001
|
return children(value);
|
|
2866
3002
|
}
|
|
2867
3003
|
return children;
|
|
2868
3004
|
}
|
|
2869
|
-
function
|
|
3005
|
+
function resolveKeyChildren4(element, value) {
|
|
2870
3006
|
const children = element.props.children ?? element.children;
|
|
2871
3007
|
if (typeof children === "function") {
|
|
2872
3008
|
return children(value);
|
|
@@ -2878,7 +3014,7 @@ function createDynamicElement5(element, tag) {
|
|
|
2878
3014
|
return null;
|
|
2879
3015
|
}
|
|
2880
3016
|
const { component, ...props } = element.props;
|
|
2881
|
-
const children =
|
|
3017
|
+
const children = normalizeContent6(props.children ?? element.children);
|
|
2882
3018
|
return {
|
|
2883
3019
|
tag,
|
|
2884
3020
|
props,
|
|
@@ -2888,17 +3024,17 @@ function createDynamicElement5(element, tag) {
|
|
|
2888
3024
|
function readReactive6(value) {
|
|
2889
3025
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
2890
3026
|
}
|
|
2891
|
-
function
|
|
3027
|
+
function normalizeContent6(content) {
|
|
2892
3028
|
if (content == null || typeof content === "boolean") {
|
|
2893
3029
|
return [];
|
|
2894
3030
|
}
|
|
2895
3031
|
return Array.isArray(content) ? content : [content];
|
|
2896
3032
|
}
|
|
2897
|
-
function
|
|
3033
|
+
function isElementLike4(value) {
|
|
2898
3034
|
return value != null && typeof value === "object" && "tag" in value;
|
|
2899
3035
|
}
|
|
2900
|
-
function
|
|
2901
|
-
if (!
|
|
3036
|
+
function getMatchElement3(value) {
|
|
3037
|
+
if (!isElementLike4(value)) {
|
|
2902
3038
|
return null;
|
|
2903
3039
|
}
|
|
2904
3040
|
if (isMatchElement(value)) {
|
|
@@ -3065,5 +3201,5 @@ export {
|
|
|
3065
3201
|
Dynamic
|
|
3066
3202
|
};
|
|
3067
3203
|
|
|
3068
|
-
//# debugId=
|
|
3204
|
+
//# debugId=325D4F9F85E0A68464756E2164756E21
|
|
3069
3205
|
//# sourceMappingURL=index.development.js.map
|