sinwan 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.development.js +962 -94
- package/dist/cjs/index.development.js.map +14 -13
- package/dist/cjs/index.production.min.js +2 -2
- package/dist/cjs/index.production.min.js.map +14 -13
- package/dist/cjs/renderer/index.development.js +419 -13
- package/dist/cjs/renderer/index.development.js.map +9 -8
- package/dist/cjs/renderer/index.production.min.js +2 -2
- package/dist/cjs/renderer/index.production.min.js.map +9 -8
- package/dist/cjs/server/index.development.js +560 -48
- package/dist/cjs/server/index.development.js.map +9 -7
- package/dist/cjs/server/index.production.min.js +2 -2
- package/dist/cjs/server/index.production.min.js.map +9 -7
- package/dist/component/control-flow.d.ts +54 -1
- package/dist/component/control-flow.d.ts.map +1 -1
- package/dist/component/index.d.ts +2 -2
- package/dist/component/index.d.ts.map +1 -1
- package/dist/esm/index.development.js +962 -94
- package/dist/esm/index.development.js.map +14 -13
- package/dist/esm/index.production.min.js +2 -2
- package/dist/esm/index.production.min.js.map +14 -13
- package/dist/esm/renderer/index.development.js +419 -13
- package/dist/esm/renderer/index.development.js.map +9 -8
- package/dist/esm/renderer/index.production.min.js +2 -2
- package/dist/esm/renderer/index.production.min.js.map +9 -8
- package/dist/esm/server/index.development.js +560 -48
- package/dist/esm/server/index.development.js.map +9 -7
- package/dist/esm/server/index.production.min.js +2 -2
- package/dist/esm/server/index.production.min.js.map +9 -7
- package/dist/hydration/walk.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/renderer/attributes.d.ts +11 -0
- package/dist/renderer/attributes.d.ts.map +1 -1
- package/dist/renderer/index.d.ts +1 -1
- package/dist/renderer/index.d.ts.map +1 -1
- package/dist/renderer/render-control-flow.d.ts +3 -3
- 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 +8 -1
- package/dist/renderer/types.d.ts.map +1 -1
- package/dist/renderer/unmount.d.ts.map +1 -1
- package/dist/server/attribute-utils.d.ts +2 -0
- package/dist/server/attribute-utils.d.ts.map +1 -0
- package/dist/server/hydration-markers.d.ts.map +1 -1
- package/dist/server/renderer.d.ts.map +1 -1
- package/dist/server/stream.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -578,9 +578,10 @@ function applyAttributes(el, props) {
|
|
|
578
578
|
if (SKIP_PROPS.has(key) || isEventProp(key))
|
|
579
579
|
continue;
|
|
580
580
|
if (isSignal(value) || isComputed(value)) {
|
|
581
|
+
const state = { previousStyleProps: new Set };
|
|
581
582
|
let initialized = false;
|
|
582
583
|
const dispose = effect(() => {
|
|
583
|
-
setSingleAttribute(el, key, value.value);
|
|
584
|
+
setSingleAttribute(el, key, value.value, state);
|
|
584
585
|
if (initialized) {
|
|
585
586
|
queueUpdatedHooks(owner);
|
|
586
587
|
}
|
|
@@ -593,10 +594,10 @@ function applyAttributes(el, props) {
|
|
|
593
594
|
}
|
|
594
595
|
return disposers;
|
|
595
596
|
}
|
|
596
|
-
function setSingleAttribute(el, key, value) {
|
|
597
|
-
const attrName =
|
|
597
|
+
function setSingleAttribute(el, key, value, state) {
|
|
598
|
+
const attrName = resolveAttributeName(key);
|
|
598
599
|
if (attrName === "style" && typeof value === "object" && value !== null) {
|
|
599
|
-
applyStyle(el, value);
|
|
600
|
+
applyStyle(el, value, state);
|
|
600
601
|
return;
|
|
601
602
|
}
|
|
602
603
|
if (attrName === "class" && typeof value === "object" && value !== null) {
|
|
@@ -605,6 +606,9 @@ function setSingleAttribute(el, key, value) {
|
|
|
605
606
|
}
|
|
606
607
|
if (value == null || value === false) {
|
|
607
608
|
domOps.removeAttribute(el, attrName);
|
|
609
|
+
if (attrName === "style" && state) {
|
|
610
|
+
state.previousStyleProps.clear();
|
|
611
|
+
}
|
|
608
612
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
609
613
|
domOps.setProperty(el, attrName, attrName === "value" ? "" : false);
|
|
610
614
|
}
|
|
@@ -612,25 +616,59 @@ function setSingleAttribute(el, key, value) {
|
|
|
612
616
|
}
|
|
613
617
|
if (value === true) {
|
|
614
618
|
domOps.setAttribute(el, attrName, "");
|
|
619
|
+
if (attrName === "style" && state) {
|
|
620
|
+
state.previousStyleProps.clear();
|
|
621
|
+
}
|
|
615
622
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
616
623
|
domOps.setProperty(el, attrName, true);
|
|
617
624
|
}
|
|
618
625
|
return;
|
|
619
626
|
}
|
|
620
627
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
628
|
+
if (attrName === "style" && state) {
|
|
629
|
+
state.previousStyleProps.clear();
|
|
630
|
+
}
|
|
621
631
|
domOps.setProperty(el, attrName, value);
|
|
622
632
|
return;
|
|
623
633
|
}
|
|
634
|
+
if (attrName === "style" && state) {
|
|
635
|
+
state.previousStyleProps.clear();
|
|
636
|
+
}
|
|
624
637
|
domOps.setAttribute(el, attrName, String(value));
|
|
625
638
|
}
|
|
626
|
-
function
|
|
639
|
+
function resolveAttributeName(key) {
|
|
640
|
+
return PROP_ALIASES[key] ?? key;
|
|
641
|
+
}
|
|
642
|
+
function applyStyle(el, styles, state) {
|
|
643
|
+
const nextProps = new Set;
|
|
627
644
|
for (const [prop, val] of Object.entries(styles)) {
|
|
645
|
+
nextProps.add(prop);
|
|
646
|
+
if (val == null) {
|
|
647
|
+
removeStyleProperty(el, prop);
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
628
650
|
if (prop.includes("-")) {
|
|
629
|
-
el.style.setProperty(prop, val);
|
|
651
|
+
el.style.setProperty(prop, String(val));
|
|
630
652
|
} else {
|
|
631
653
|
el.style[prop] = val;
|
|
632
654
|
}
|
|
633
655
|
}
|
|
656
|
+
if (!state) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
for (const previousProp of state.previousStyleProps) {
|
|
660
|
+
if (!nextProps.has(previousProp)) {
|
|
661
|
+
removeStyleProperty(el, previousProp);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
state.previousStyleProps = nextProps;
|
|
665
|
+
}
|
|
666
|
+
function removeStyleProperty(el, prop) {
|
|
667
|
+
if (prop.includes("-")) {
|
|
668
|
+
el.style.removeProperty(prop);
|
|
669
|
+
} else {
|
|
670
|
+
el.style[prop] = "";
|
|
671
|
+
}
|
|
634
672
|
}
|
|
635
673
|
function applyClass(el, value) {
|
|
636
674
|
let classStr;
|
|
@@ -643,10 +681,28 @@ function applyClass(el, value) {
|
|
|
643
681
|
}
|
|
644
682
|
domOps.setAttribute(el, "class", classStr);
|
|
645
683
|
}
|
|
646
|
-
|
|
684
|
+
// src/reactivity/batch.ts
|
|
685
|
+
var batchDepth = 0;
|
|
686
|
+
function batch(fn) {
|
|
687
|
+
batchDepth++;
|
|
688
|
+
try {
|
|
689
|
+
fn();
|
|
690
|
+
} finally {
|
|
691
|
+
batchDepth--;
|
|
692
|
+
if (batchDepth === 0) {
|
|
693
|
+
flushSync();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
647
697
|
// src/component/control-flow.ts
|
|
648
698
|
var SHOW_TYPE = Symbol.for("Sinwan.Show");
|
|
649
699
|
var FOR_TYPE = Symbol.for("Sinwan.For");
|
|
700
|
+
var SWITCH_TYPE = Symbol.for("Sinwan.Switch");
|
|
701
|
+
var MATCH_TYPE = Symbol.for("Sinwan.Match");
|
|
702
|
+
var INDEX_TYPE = Symbol.for("Sinwan.Index");
|
|
703
|
+
var KEY_TYPE = Symbol.for("Sinwan.Key");
|
|
704
|
+
var DYNAMIC_TYPE = Symbol.for("Sinwan.Dynamic");
|
|
705
|
+
var PORTAL_TYPE = Symbol.for("Sinwan.Portal");
|
|
650
706
|
function Show(props) {
|
|
651
707
|
return {
|
|
652
708
|
tag: SHOW_TYPE,
|
|
@@ -661,12 +717,114 @@ function For(props) {
|
|
|
661
717
|
children: []
|
|
662
718
|
};
|
|
663
719
|
}
|
|
720
|
+
function Switch(props) {
|
|
721
|
+
return {
|
|
722
|
+
tag: SWITCH_TYPE,
|
|
723
|
+
props,
|
|
724
|
+
children: []
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
function Match(props) {
|
|
728
|
+
return {
|
|
729
|
+
tag: MATCH_TYPE,
|
|
730
|
+
props,
|
|
731
|
+
children: []
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
function Index(props) {
|
|
735
|
+
return {
|
|
736
|
+
tag: INDEX_TYPE,
|
|
737
|
+
props,
|
|
738
|
+
children: []
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function Key(props) {
|
|
742
|
+
return {
|
|
743
|
+
tag: KEY_TYPE,
|
|
744
|
+
props,
|
|
745
|
+
children: []
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function Dynamic(props) {
|
|
749
|
+
return {
|
|
750
|
+
tag: DYNAMIC_TYPE,
|
|
751
|
+
props,
|
|
752
|
+
children: []
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
function Visible(props) {
|
|
756
|
+
const {
|
|
757
|
+
when,
|
|
758
|
+
as = "span",
|
|
759
|
+
style,
|
|
760
|
+
children,
|
|
761
|
+
...rest
|
|
762
|
+
} = props;
|
|
763
|
+
const visibleStyle = computed(() => {
|
|
764
|
+
const base = readReactive(style);
|
|
765
|
+
const visible = Boolean(readReactive(when));
|
|
766
|
+
if (typeof base === "string") {
|
|
767
|
+
return visible ? base : appendHiddenDisplay(base);
|
|
768
|
+
}
|
|
769
|
+
const styleObject = base && typeof base === "object" ? { ...base } : {};
|
|
770
|
+
styleObject.display = visible ? styleObject.display : "none";
|
|
771
|
+
return styleObject;
|
|
772
|
+
});
|
|
773
|
+
return {
|
|
774
|
+
tag: as,
|
|
775
|
+
props: {
|
|
776
|
+
...rest,
|
|
777
|
+
style: visibleStyle,
|
|
778
|
+
children
|
|
779
|
+
},
|
|
780
|
+
children: normalizeChildren2(children)
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
function Portal(props) {
|
|
784
|
+
return {
|
|
785
|
+
tag: PORTAL_TYPE,
|
|
786
|
+
props,
|
|
787
|
+
children: []
|
|
788
|
+
};
|
|
789
|
+
}
|
|
664
790
|
function isShowElement(element) {
|
|
665
791
|
return element.tag === SHOW_TYPE;
|
|
666
792
|
}
|
|
667
793
|
function isForElement(element) {
|
|
668
794
|
return element.tag === FOR_TYPE;
|
|
669
795
|
}
|
|
796
|
+
function isSwitchElement(element) {
|
|
797
|
+
return element.tag === SWITCH_TYPE;
|
|
798
|
+
}
|
|
799
|
+
function isMatchElement(element) {
|
|
800
|
+
return element.tag === MATCH_TYPE;
|
|
801
|
+
}
|
|
802
|
+
function isIndexElement(element) {
|
|
803
|
+
return element.tag === INDEX_TYPE;
|
|
804
|
+
}
|
|
805
|
+
function isKeyElement(element) {
|
|
806
|
+
return element.tag === KEY_TYPE;
|
|
807
|
+
}
|
|
808
|
+
function isDynamicElement(element) {
|
|
809
|
+
return element.tag === DYNAMIC_TYPE;
|
|
810
|
+
}
|
|
811
|
+
function isPortalElement(element) {
|
|
812
|
+
return element.tag === PORTAL_TYPE;
|
|
813
|
+
}
|
|
814
|
+
function normalizeChildren2(children) {
|
|
815
|
+
if (children == null || typeof children === "boolean") {
|
|
816
|
+
return [];
|
|
817
|
+
}
|
|
818
|
+
return Array.isArray(children) ? children : [children];
|
|
819
|
+
}
|
|
820
|
+
function readReactive(value) {
|
|
821
|
+
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
822
|
+
}
|
|
823
|
+
function appendHiddenDisplay(style) {
|
|
824
|
+
const trimmed = style.trim();
|
|
825
|
+
const separator = trimmed.length > 0 && !trimmed.endsWith(";") ? ";" : "";
|
|
826
|
+
return `${trimmed}${separator}display:none`;
|
|
827
|
+
}
|
|
670
828
|
|
|
671
829
|
// src/renderer/unmount.ts
|
|
672
830
|
function getMountedDomNodes(node) {
|
|
@@ -689,6 +847,8 @@ function getMountedDomNodes(node) {
|
|
|
689
847
|
];
|
|
690
848
|
case "component":
|
|
691
849
|
return node.children.flatMap((child) => getMountedDomNodes(child));
|
|
850
|
+
case "portal":
|
|
851
|
+
return [node.anchor];
|
|
692
852
|
}
|
|
693
853
|
}
|
|
694
854
|
function unmountNode(node) {
|
|
@@ -733,6 +893,13 @@ function unmountNode(node) {
|
|
|
733
893
|
unmountNode(child);
|
|
734
894
|
}
|
|
735
895
|
break;
|
|
896
|
+
case "portal":
|
|
897
|
+
node.dispose();
|
|
898
|
+
for (const child of node.children) {
|
|
899
|
+
removeMountedNode(child);
|
|
900
|
+
}
|
|
901
|
+
node.children = [];
|
|
902
|
+
break;
|
|
736
903
|
}
|
|
737
904
|
}
|
|
738
905
|
function removeMountedNode(node) {
|
|
@@ -747,6 +914,9 @@ function removeMountedNode(node) {
|
|
|
747
914
|
|
|
748
915
|
// src/renderer/render-control-flow.ts
|
|
749
916
|
function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
917
|
+
if (isPortalElement(element)) {
|
|
918
|
+
return renderPortal(element, parent, anchor, namespace);
|
|
919
|
+
}
|
|
750
920
|
const startAnchor = domOps.createComment("Sinwan-b");
|
|
751
921
|
const endAnchor = domOps.createComment("/Sinwan-b");
|
|
752
922
|
insertNode(parent, startAnchor, anchor);
|
|
@@ -764,6 +934,14 @@ function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
|
764
934
|
disposeEffect = renderShowBlock(element, block, parent, namespace, owner);
|
|
765
935
|
} else if (isForElement(element)) {
|
|
766
936
|
disposeEffect = renderForBlock(element, block, parent, namespace, owner);
|
|
937
|
+
} else if (isSwitchElement(element)) {
|
|
938
|
+
disposeEffect = renderSwitchBlock(element, block, parent, namespace, owner);
|
|
939
|
+
} else if (isIndexElement(element)) {
|
|
940
|
+
disposeEffect = renderIndexBlock(element, block, parent, namespace, owner);
|
|
941
|
+
} else if (isKeyElement(element)) {
|
|
942
|
+
disposeEffect = renderKeyBlock(element, block, parent, namespace, owner);
|
|
943
|
+
} else if (isDynamicElement(element)) {
|
|
944
|
+
disposeEffect = renderDynamicBlock(element, block, parent, namespace, owner);
|
|
767
945
|
}
|
|
768
946
|
return block;
|
|
769
947
|
}
|
|
@@ -771,7 +949,7 @@ function renderShowBlock(element, block, parent, namespace, owner) {
|
|
|
771
949
|
let initialized = false;
|
|
772
950
|
return effect(() => {
|
|
773
951
|
clearChildren(block);
|
|
774
|
-
const when =
|
|
952
|
+
const when = readReactive2(element.props.when);
|
|
775
953
|
const content = withOptionalInstance(owner, () => when ? resolveShowChildren(element, when) : element.props.fallback);
|
|
776
954
|
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
777
955
|
if (initialized) {
|
|
@@ -785,7 +963,7 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
785
963
|
let records = [];
|
|
786
964
|
return effect(() => {
|
|
787
965
|
const props = element.props;
|
|
788
|
-
const items =
|
|
966
|
+
const items = readReactive2(props.each);
|
|
789
967
|
const list = Array.isArray(items) ? items : [];
|
|
790
968
|
const renderChild = props.children;
|
|
791
969
|
if (typeof renderChild !== "function") {
|
|
@@ -797,6 +975,19 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
797
975
|
initialized = true;
|
|
798
976
|
return;
|
|
799
977
|
}
|
|
978
|
+
if (list.length === 0) {
|
|
979
|
+
clearChildren(block);
|
|
980
|
+
records = [];
|
|
981
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
982
|
+
if (initialized) {
|
|
983
|
+
fireMountedAndQueueUpdated(owner);
|
|
984
|
+
}
|
|
985
|
+
initialized = true;
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
989
|
+
clearChildren(block);
|
|
990
|
+
}
|
|
800
991
|
const oldByKey = new Map;
|
|
801
992
|
for (const record of records) {
|
|
802
993
|
oldByKey.set(record.key, record);
|
|
@@ -836,6 +1027,137 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
836
1027
|
initialized = true;
|
|
837
1028
|
});
|
|
838
1029
|
}
|
|
1030
|
+
function renderSwitchBlock(element, block, parent, namespace, owner) {
|
|
1031
|
+
let initialized = false;
|
|
1032
|
+
return effect(() => {
|
|
1033
|
+
clearChildren(block);
|
|
1034
|
+
const content = withOptionalInstance(owner, () => resolveSwitchContent(element));
|
|
1035
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1036
|
+
if (initialized) {
|
|
1037
|
+
fireMountedAndQueueUpdated(owner);
|
|
1038
|
+
}
|
|
1039
|
+
initialized = true;
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
function renderIndexBlock(element, block, parent, namespace, owner) {
|
|
1043
|
+
let initialized = false;
|
|
1044
|
+
let records = [];
|
|
1045
|
+
return effect(() => {
|
|
1046
|
+
const props = element.props;
|
|
1047
|
+
const items = readReactive2(props.each);
|
|
1048
|
+
const list = Array.isArray(items) ? items : [];
|
|
1049
|
+
const renderChild = props.children;
|
|
1050
|
+
if (typeof renderChild !== "function") {
|
|
1051
|
+
clearChildren(block);
|
|
1052
|
+
records = [];
|
|
1053
|
+
if (initialized) {
|
|
1054
|
+
queueUpdatedHooks(owner);
|
|
1055
|
+
}
|
|
1056
|
+
initialized = true;
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
if (list.length === 0) {
|
|
1060
|
+
clearChildren(block);
|
|
1061
|
+
records = [];
|
|
1062
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
1063
|
+
if (initialized) {
|
|
1064
|
+
fireMountedAndQueueUpdated(owner);
|
|
1065
|
+
}
|
|
1066
|
+
initialized = true;
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
1070
|
+
clearChildren(block);
|
|
1071
|
+
}
|
|
1072
|
+
for (let index = 0;index < list.length; index++) {
|
|
1073
|
+
const existing = records[index];
|
|
1074
|
+
if (existing) {
|
|
1075
|
+
existing.item.value = list[index];
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
const itemSignal = signal(list[index]);
|
|
1079
|
+
const record = {
|
|
1080
|
+
item: itemSignal,
|
|
1081
|
+
mounted: withOptionalInstance(owner, () => renderNodeToDOM(renderChild(() => itemSignal.value, index), parent, block.endAnchor, namespace))
|
|
1082
|
+
};
|
|
1083
|
+
records.push(record);
|
|
1084
|
+
}
|
|
1085
|
+
while (records.length > list.length) {
|
|
1086
|
+
const removed = records.pop();
|
|
1087
|
+
removeMountedNode(removed.mounted);
|
|
1088
|
+
}
|
|
1089
|
+
block.children = records.map((record) => record.mounted);
|
|
1090
|
+
if (initialized) {
|
|
1091
|
+
fireMountedAndQueueUpdated(owner);
|
|
1092
|
+
}
|
|
1093
|
+
initialized = true;
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
function renderKeyBlock(element, block, parent, namespace, owner) {
|
|
1097
|
+
let initialized = false;
|
|
1098
|
+
let hasKey = false;
|
|
1099
|
+
let currentKey;
|
|
1100
|
+
return effect(() => {
|
|
1101
|
+
const key = readReactive2(element.props.when);
|
|
1102
|
+
if (hasKey && Object.is(currentKey, key)) {
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
currentKey = key;
|
|
1106
|
+
hasKey = true;
|
|
1107
|
+
clearChildren(block);
|
|
1108
|
+
const content = withOptionalInstance(owner, () => resolveKeyChildren(element, key));
|
|
1109
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1110
|
+
if (initialized) {
|
|
1111
|
+
fireMountedAndQueueUpdated(owner);
|
|
1112
|
+
}
|
|
1113
|
+
initialized = true;
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
function renderDynamicBlock(element, block, parent, namespace, owner) {
|
|
1117
|
+
let initialized = false;
|
|
1118
|
+
let hasTag = false;
|
|
1119
|
+
let currentTag;
|
|
1120
|
+
return effect(() => {
|
|
1121
|
+
const tag = readReactive2(element.props.component);
|
|
1122
|
+
if (hasTag && Object.is(currentTag, tag)) {
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
currentTag = tag;
|
|
1126
|
+
hasTag = true;
|
|
1127
|
+
clearChildren(block);
|
|
1128
|
+
const content = tag ? createDynamicElement(element, tag) : null;
|
|
1129
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1130
|
+
if (initialized) {
|
|
1131
|
+
fireMountedAndQueueUpdated(owner);
|
|
1132
|
+
}
|
|
1133
|
+
initialized = true;
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
function renderPortal(element, parent, anchor, namespace) {
|
|
1137
|
+
const placeholder = domOps.createComment("Sinwan-p");
|
|
1138
|
+
insertNode(parent, placeholder, anchor);
|
|
1139
|
+
const owner = getCurrentInstance();
|
|
1140
|
+
let disposeEffect = () => {};
|
|
1141
|
+
const portal = {
|
|
1142
|
+
type: "portal",
|
|
1143
|
+
anchor: placeholder,
|
|
1144
|
+
children: [],
|
|
1145
|
+
dispose: () => disposeEffect()
|
|
1146
|
+
};
|
|
1147
|
+
let initialized = false;
|
|
1148
|
+
disposeEffect = effect(() => {
|
|
1149
|
+
clearPortalChildren(portal);
|
|
1150
|
+
const target = resolvePortalTarget(element.props.mount);
|
|
1151
|
+
if (target) {
|
|
1152
|
+
portal.children = renderBlockContent(element.props.children ?? element.children, target, null, namespace, owner);
|
|
1153
|
+
}
|
|
1154
|
+
if (initialized) {
|
|
1155
|
+
fireMountedAndQueueUpdated(owner);
|
|
1156
|
+
}
|
|
1157
|
+
initialized = true;
|
|
1158
|
+
});
|
|
1159
|
+
return portal;
|
|
1160
|
+
}
|
|
839
1161
|
function resolveShowChildren(element, value) {
|
|
840
1162
|
const children = element.props.children ?? element.children;
|
|
841
1163
|
if (typeof children === "function") {
|
|
@@ -843,6 +1165,47 @@ function resolveShowChildren(element, value) {
|
|
|
843
1165
|
}
|
|
844
1166
|
return children;
|
|
845
1167
|
}
|
|
1168
|
+
function resolveSwitchContent(element) {
|
|
1169
|
+
const props = element.props;
|
|
1170
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1171
|
+
for (const child of children) {
|
|
1172
|
+
const match = getMatchElement(child);
|
|
1173
|
+
if (!match) {
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
const when = readReactive2(match.props.when);
|
|
1177
|
+
if (when) {
|
|
1178
|
+
return resolveMatchChildren(match, when);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return props.fallback;
|
|
1182
|
+
}
|
|
1183
|
+
function resolveMatchChildren(element, value) {
|
|
1184
|
+
const children = element.props.children ?? element.children;
|
|
1185
|
+
if (typeof children === "function") {
|
|
1186
|
+
return children(value);
|
|
1187
|
+
}
|
|
1188
|
+
return children;
|
|
1189
|
+
}
|
|
1190
|
+
function resolveKeyChildren(element, value) {
|
|
1191
|
+
const children = element.props.children ?? element.children;
|
|
1192
|
+
if (typeof children === "function") {
|
|
1193
|
+
return children(value);
|
|
1194
|
+
}
|
|
1195
|
+
return children;
|
|
1196
|
+
}
|
|
1197
|
+
function createDynamicElement(element, tag) {
|
|
1198
|
+
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
1199
|
+
return null;
|
|
1200
|
+
}
|
|
1201
|
+
const { component, ...props } = element.props;
|
|
1202
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1203
|
+
return {
|
|
1204
|
+
tag,
|
|
1205
|
+
props,
|
|
1206
|
+
children
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
846
1209
|
function renderBlockContent(content, parent, anchor, namespace, owner) {
|
|
847
1210
|
if (content == null || typeof content === "boolean") {
|
|
848
1211
|
return [];
|
|
@@ -856,6 +1219,12 @@ function clearChildren(block) {
|
|
|
856
1219
|
}
|
|
857
1220
|
block.children = [];
|
|
858
1221
|
}
|
|
1222
|
+
function clearPortalChildren(portal) {
|
|
1223
|
+
for (const child of portal.children) {
|
|
1224
|
+
removeMountedNode(child);
|
|
1225
|
+
}
|
|
1226
|
+
portal.children = [];
|
|
1227
|
+
}
|
|
859
1228
|
function moveBeforeEnd(parent, mounted, endAnchor) {
|
|
860
1229
|
for (const node of getMountedDomNodes(mounted)) {
|
|
861
1230
|
domOps.insertBefore(parent, node, endAnchor);
|
|
@@ -870,9 +1239,43 @@ function fireMountedAndQueueUpdated(owner) {
|
|
|
870
1239
|
function withOptionalInstance(owner, fn) {
|
|
871
1240
|
return owner ? withInstance(owner, fn) : fn();
|
|
872
1241
|
}
|
|
873
|
-
function
|
|
1242
|
+
function readReactive2(value) {
|
|
874
1243
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
875
1244
|
}
|
|
1245
|
+
function normalizeContent(content) {
|
|
1246
|
+
if (content == null || typeof content === "boolean") {
|
|
1247
|
+
return [];
|
|
1248
|
+
}
|
|
1249
|
+
return Array.isArray(content) ? content : [content];
|
|
1250
|
+
}
|
|
1251
|
+
function isElementLike(value) {
|
|
1252
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
1253
|
+
}
|
|
1254
|
+
function getMatchElement(value) {
|
|
1255
|
+
if (!isElementLike(value)) {
|
|
1256
|
+
return null;
|
|
1257
|
+
}
|
|
1258
|
+
if (isMatchElement(value)) {
|
|
1259
|
+
return value;
|
|
1260
|
+
}
|
|
1261
|
+
return value.tag === Match ? Match(value.props) : null;
|
|
1262
|
+
}
|
|
1263
|
+
function resolvePortalTarget(value) {
|
|
1264
|
+
const target = readReactive2(value);
|
|
1265
|
+
if (target == null) {
|
|
1266
|
+
return typeof document === "undefined" ? null : document.body;
|
|
1267
|
+
}
|
|
1268
|
+
if (typeof target === "string") {
|
|
1269
|
+
return document.querySelector(target);
|
|
1270
|
+
}
|
|
1271
|
+
if (typeof target === "function") {
|
|
1272
|
+
return target();
|
|
1273
|
+
}
|
|
1274
|
+
if (typeof target === "object" && "nodeType" in target) {
|
|
1275
|
+
return target;
|
|
1276
|
+
}
|
|
1277
|
+
return null;
|
|
1278
|
+
}
|
|
876
1279
|
function insertNode(parent, child, anchor) {
|
|
877
1280
|
if (anchor) {
|
|
878
1281
|
domOps.insertBefore(parent, child, anchor);
|
|
@@ -905,10 +1308,13 @@ function renderElementToDOM(element, parent, anchor = null, namespace = null) {
|
|
|
905
1308
|
if (tag === "" || tag === Fragment) {
|
|
906
1309
|
return renderFragmentToDOM(children, parent, anchor, namespace);
|
|
907
1310
|
}
|
|
908
|
-
if (tag === Show || tag === For) {
|
|
1311
|
+
if (tag === Show || tag === For || tag === Switch || tag === Index || tag === Key || tag === Dynamic || tag === Portal) {
|
|
1312
|
+
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
1313
|
+
}
|
|
1314
|
+
if (tag === Visible) {
|
|
909
1315
|
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
910
1316
|
}
|
|
911
|
-
if (isShowElement(element) || isForElement(element)) {
|
|
1317
|
+
if (isShowElement(element) || isForElement(element) || isSwitchElement(element) || isIndexElement(element) || isKeyElement(element) || isDynamicElement(element) || isPortalElement(element)) {
|
|
912
1318
|
return renderControlFlowToDOM(element, parent, anchor, namespace);
|
|
913
1319
|
}
|
|
914
1320
|
if (typeof tag === "function") {
|
|
@@ -1171,5 +1577,5 @@ function render(node, container) {
|
|
|
1171
1577
|
};
|
|
1172
1578
|
}
|
|
1173
1579
|
|
|
1174
|
-
//# debugId=
|
|
1580
|
+
//# debugId=15A128AFFDA0548D64756E2164756E21
|
|
1175
1581
|
//# sourceMappingURL=index.development.js.map
|