sinwan 1.1.1 → 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 +296 -192
- package/dist/cjs/index.development.js.map +9 -9
- package/dist/cjs/index.production.min.js +2 -2
- package/dist/cjs/index.production.min.js.map +9 -9
- package/dist/cjs/renderer/index.development.js +239 -87
- package/dist/cjs/renderer/index.development.js.map +8 -8
- package/dist/cjs/renderer/index.production.min.js +2 -2
- package/dist/cjs/renderer/index.production.min.js.map +8 -8
- package/dist/cjs/server/index.development.js +132 -67
- package/dist/cjs/server/index.development.js.map +6 -6
- package/dist/cjs/server/index.production.min.js +2 -2
- package/dist/cjs/server/index.production.min.js.map +6 -6
- 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 +296 -192
- package/dist/esm/index.development.js.map +9 -9
- package/dist/esm/index.production.min.js +2 -2
- package/dist/esm/index.production.min.js.map +9 -9
- package/dist/esm/renderer/index.development.js +239 -87
- package/dist/esm/renderer/index.development.js.map +8 -8
- package/dist/esm/renderer/index.production.min.js +2 -2
- package/dist/esm/renderer/index.production.min.js.map +8 -8
- package/dist/esm/server/index.development.js +132 -67
- package/dist/esm/server/index.development.js.map +6 -6
- package/dist/esm/server/index.production.min.js +2 -2
- package/dist/esm/server/index.production.min.js.map +6 -6
- package/dist/reactivity/index.d.ts +1 -1
- package/dist/reactivity/index.d.ts.map +1 -1
- package/dist/renderer/attributes.d.ts.map +1 -1
- package/dist/renderer/events.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/package.json +5 -2
|
@@ -500,7 +500,7 @@ function resetDOMOps() {
|
|
|
500
500
|
|
|
501
501
|
// src/renderer/events.ts
|
|
502
502
|
function isEventProp(key) {
|
|
503
|
-
return key.length > 2 && key
|
|
503
|
+
return key.length > 2 && key.startsWith("on");
|
|
504
504
|
}
|
|
505
505
|
function toEventName(key) {
|
|
506
506
|
return key.slice(2).toLowerCase();
|
|
@@ -643,6 +643,9 @@ function Portal(props) {
|
|
|
643
643
|
children: []
|
|
644
644
|
};
|
|
645
645
|
}
|
|
646
|
+
function isElementLike(value) {
|
|
647
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
648
|
+
}
|
|
646
649
|
function isShowElement(element) {
|
|
647
650
|
return element.tag === SHOW_TYPE;
|
|
648
651
|
}
|
|
@@ -667,6 +670,107 @@ function isDynamicElement(element) {
|
|
|
667
670
|
function isPortalElement(element) {
|
|
668
671
|
return element.tag === PORTAL_TYPE;
|
|
669
672
|
}
|
|
673
|
+
function resolveSwitchContent(element) {
|
|
674
|
+
const props = element.props;
|
|
675
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
676
|
+
const match = findTruthyMatch(children);
|
|
677
|
+
return match !== undefined ? match : props.fallback;
|
|
678
|
+
}
|
|
679
|
+
function findTruthyMatch(nodes) {
|
|
680
|
+
for (const node of nodes) {
|
|
681
|
+
if (node == null || typeof node === "boolean")
|
|
682
|
+
continue;
|
|
683
|
+
if (Array.isArray(node)) {
|
|
684
|
+
const match = findTruthyMatch(node);
|
|
685
|
+
if (match !== undefined)
|
|
686
|
+
return match;
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
if (isElementLike(node)) {
|
|
690
|
+
let element = node;
|
|
691
|
+
if (typeof element.tag === "function") {
|
|
692
|
+
const tag = element.tag;
|
|
693
|
+
if (tag === Match || tag === Show || tag === For || tag === Index || tag === Key || tag === Switch) {
|
|
694
|
+
element = tag(element.props);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (isMatchElement(element)) {
|
|
698
|
+
const when = readReactive(element.props.when);
|
|
699
|
+
if (when) {
|
|
700
|
+
return resolveMatchChildren(element, when);
|
|
701
|
+
}
|
|
702
|
+
} else if (isShowElement(element)) {
|
|
703
|
+
const when = readReactive(element.props.when);
|
|
704
|
+
if (when) {
|
|
705
|
+
const content = resolveShowChildren(element, when);
|
|
706
|
+
const match = findTruthyMatch(normalizeContent(content));
|
|
707
|
+
if (match !== undefined)
|
|
708
|
+
return match;
|
|
709
|
+
} else if (element.props.fallback) {
|
|
710
|
+
const match = findTruthyMatch(normalizeContent(element.props.fallback));
|
|
711
|
+
if (match !== undefined)
|
|
712
|
+
return match;
|
|
713
|
+
}
|
|
714
|
+
} else if (isForElement(element)) {
|
|
715
|
+
const props = element.props;
|
|
716
|
+
const items = readReactive(props.each);
|
|
717
|
+
if (Array.isArray(items)) {
|
|
718
|
+
for (let i = 0;i < items.length; i++) {
|
|
719
|
+
const child = props.children(items[i], () => i);
|
|
720
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
721
|
+
if (match !== undefined)
|
|
722
|
+
return match;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
} else if (isIndexElement(element)) {
|
|
726
|
+
const props = element.props;
|
|
727
|
+
const items = readReactive(props.each);
|
|
728
|
+
if (Array.isArray(items)) {
|
|
729
|
+
for (let i = 0;i < items.length; i++) {
|
|
730
|
+
const child = props.children(() => items[i], i);
|
|
731
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
732
|
+
if (match !== undefined)
|
|
733
|
+
return match;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
} else if (isKeyElement(element)) {
|
|
737
|
+
const key = readReactive(element.props.when);
|
|
738
|
+
const child = resolveKeyChildren(element, key);
|
|
739
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
740
|
+
if (match !== undefined)
|
|
741
|
+
return match;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
function resolveMatchChildren(element, value) {
|
|
748
|
+
const children = element.props.children ?? element.children;
|
|
749
|
+
if (typeof children === "function") {
|
|
750
|
+
return children(value);
|
|
751
|
+
}
|
|
752
|
+
return children;
|
|
753
|
+
}
|
|
754
|
+
function resolveShowChildren(element, value) {
|
|
755
|
+
const children = element.props.children ?? element.children;
|
|
756
|
+
if (typeof children === "function") {
|
|
757
|
+
return children(value);
|
|
758
|
+
}
|
|
759
|
+
return children;
|
|
760
|
+
}
|
|
761
|
+
function resolveKeyChildren(element, value) {
|
|
762
|
+
const children = element.props.children ?? element.children;
|
|
763
|
+
if (typeof children === "function") {
|
|
764
|
+
return children(value);
|
|
765
|
+
}
|
|
766
|
+
return children;
|
|
767
|
+
}
|
|
768
|
+
function normalizeContent(content) {
|
|
769
|
+
if (content == null || typeof content === "boolean") {
|
|
770
|
+
return [];
|
|
771
|
+
}
|
|
772
|
+
return Array.isArray(content) ? content : [content];
|
|
773
|
+
}
|
|
670
774
|
function normalizeChildren2(children) {
|
|
671
775
|
if (children == null || typeof children === "boolean") {
|
|
672
776
|
return [];
|
|
@@ -844,75 +948,27 @@ async function renderIndexElement(element) {
|
|
|
844
948
|
const rendered = await Promise.all(each.map((item, index) => renderToString(props.children(() => item, index))));
|
|
845
949
|
return rendered.join("");
|
|
846
950
|
}
|
|
847
|
-
function resolveSwitchContent(element) {
|
|
848
|
-
const props = element.props;
|
|
849
|
-
const children = normalizeContent(props.children ?? element.children);
|
|
850
|
-
for (const child of children) {
|
|
851
|
-
const match = getMatchElement(child);
|
|
852
|
-
if (!match) {
|
|
853
|
-
continue;
|
|
854
|
-
}
|
|
855
|
-
const when = readReactive2(match.props.when);
|
|
856
|
-
if (when) {
|
|
857
|
-
return resolveMatchChildren(match, when);
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
return props.fallback;
|
|
861
|
-
}
|
|
862
|
-
function resolveMatchChildren(element, value) {
|
|
863
|
-
const children = element.props.children ?? element.children;
|
|
864
|
-
if (typeof children === "function") {
|
|
865
|
-
return children(value);
|
|
866
|
-
}
|
|
867
|
-
return children;
|
|
868
|
-
}
|
|
869
|
-
function resolveKeyChildren(element, value) {
|
|
870
|
-
const children = element.props.children ?? element.children;
|
|
871
|
-
if (typeof children === "function") {
|
|
872
|
-
return children(value);
|
|
873
|
-
}
|
|
874
|
-
return children;
|
|
875
|
-
}
|
|
876
951
|
function createDynamicElement(element, tag) {
|
|
877
952
|
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
878
953
|
return null;
|
|
879
954
|
}
|
|
880
955
|
const { component, ...props } = element.props;
|
|
881
|
-
const children =
|
|
956
|
+
const children = normalizeContent2(props.children ?? element.children);
|
|
882
957
|
return {
|
|
883
958
|
tag,
|
|
884
959
|
props,
|
|
885
960
|
children
|
|
886
961
|
};
|
|
887
962
|
}
|
|
888
|
-
function resolveShowChildren(element, value) {
|
|
889
|
-
const children = element.props.children ?? element.children;
|
|
890
|
-
if (typeof children === "function") {
|
|
891
|
-
return children(value);
|
|
892
|
-
}
|
|
893
|
-
return children;
|
|
894
|
-
}
|
|
895
963
|
function readReactive2(value) {
|
|
896
964
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
897
965
|
}
|
|
898
|
-
function
|
|
966
|
+
function normalizeContent2(content) {
|
|
899
967
|
if (content == null || typeof content === "boolean") {
|
|
900
968
|
return [];
|
|
901
969
|
}
|
|
902
970
|
return Array.isArray(content) ? content : [content];
|
|
903
971
|
}
|
|
904
|
-
function isElementLike(value) {
|
|
905
|
-
return value != null && typeof value === "object" && "tag" in value;
|
|
906
|
-
}
|
|
907
|
-
function getMatchElement(value) {
|
|
908
|
-
if (!isElementLike(value)) {
|
|
909
|
-
return null;
|
|
910
|
-
}
|
|
911
|
-
if (isMatchElement(value)) {
|
|
912
|
-
return value;
|
|
913
|
-
}
|
|
914
|
-
return value.tag === Match ? Match(value.props) : null;
|
|
915
|
-
}
|
|
916
972
|
// src/component/instance.ts
|
|
917
973
|
var uidCounter = 0;
|
|
918
974
|
function createComponentInstance(component, props, parent) {
|
|
@@ -965,19 +1021,28 @@ function fireMountedHooks(instance) {
|
|
|
965
1021
|
}
|
|
966
1022
|
}
|
|
967
1023
|
function fireUnmountedHooks(instance) {
|
|
968
|
-
|
|
1024
|
+
const children = [...instance.children];
|
|
1025
|
+
for (const child of children) {
|
|
969
1026
|
fireUnmountedHooks(child);
|
|
970
1027
|
}
|
|
971
|
-
if (
|
|
1028
|
+
if (!instance.isUnmounted) {
|
|
972
1029
|
instance.isUnmounted = true;
|
|
973
|
-
instance.isMounted
|
|
974
|
-
|
|
975
|
-
hook
|
|
1030
|
+
if (instance.isMounted) {
|
|
1031
|
+
instance.isMounted = false;
|
|
1032
|
+
for (const hook of instance._unmountedHooks) {
|
|
1033
|
+
hook();
|
|
1034
|
+
}
|
|
976
1035
|
}
|
|
977
1036
|
for (const dispose of instance.effects) {
|
|
978
1037
|
dispose();
|
|
979
1038
|
}
|
|
980
1039
|
instance.effects.length = 0;
|
|
1040
|
+
if (instance.parent) {
|
|
1041
|
+
const idx = instance.parent.children.indexOf(instance);
|
|
1042
|
+
if (idx !== -1) {
|
|
1043
|
+
instance.parent.children.splice(idx, 1);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
981
1046
|
}
|
|
982
1047
|
}
|
|
983
1048
|
function fireUpdatedHooks(instance) {
|
|
@@ -1462,9 +1527,9 @@ function resolveShowChildren2(element, value) {
|
|
|
1462
1527
|
}
|
|
1463
1528
|
function resolveSwitchContent2(element) {
|
|
1464
1529
|
const props = element.props;
|
|
1465
|
-
const children =
|
|
1530
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1466
1531
|
for (const child of children) {
|
|
1467
|
-
const match =
|
|
1532
|
+
const match = getMatchElement(child);
|
|
1468
1533
|
if (!match) {
|
|
1469
1534
|
continue;
|
|
1470
1535
|
}
|
|
@@ -1494,7 +1559,7 @@ function createDynamicElement2(element, tag) {
|
|
|
1494
1559
|
return null;
|
|
1495
1560
|
}
|
|
1496
1561
|
const { component, ...props } = element.props;
|
|
1497
|
-
const children =
|
|
1562
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1498
1563
|
return {
|
|
1499
1564
|
tag,
|
|
1500
1565
|
props,
|
|
@@ -1504,7 +1569,7 @@ function createDynamicElement2(element, tag) {
|
|
|
1504
1569
|
function readReactive3(value) {
|
|
1505
1570
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1506
1571
|
}
|
|
1507
|
-
function
|
|
1572
|
+
function normalizeContent3(content) {
|
|
1508
1573
|
if (content == null || typeof content === "boolean") {
|
|
1509
1574
|
return [];
|
|
1510
1575
|
}
|
|
@@ -1513,7 +1578,7 @@ function normalizeContent2(content) {
|
|
|
1513
1578
|
function isElementLike2(value) {
|
|
1514
1579
|
return value != null && typeof value === "object" && "tag" in value;
|
|
1515
1580
|
}
|
|
1516
|
-
function
|
|
1581
|
+
function getMatchElement(value) {
|
|
1517
1582
|
if (!isElementLike2(value)) {
|
|
1518
1583
|
return null;
|
|
1519
1584
|
}
|
|
@@ -1725,9 +1790,9 @@ function resolveShowChildren3(element, value) {
|
|
|
1725
1790
|
}
|
|
1726
1791
|
function resolveSwitchContent3(element) {
|
|
1727
1792
|
const props = element.props;
|
|
1728
|
-
const children =
|
|
1793
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
1729
1794
|
for (const child of children) {
|
|
1730
|
-
const match =
|
|
1795
|
+
const match = getMatchElement2(child);
|
|
1731
1796
|
if (!match) {
|
|
1732
1797
|
continue;
|
|
1733
1798
|
}
|
|
@@ -1757,7 +1822,7 @@ function createDynamicElement3(element, tag) {
|
|
|
1757
1822
|
return null;
|
|
1758
1823
|
}
|
|
1759
1824
|
const { component, ...props } = element.props;
|
|
1760
|
-
const children =
|
|
1825
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
1761
1826
|
return {
|
|
1762
1827
|
tag,
|
|
1763
1828
|
props,
|
|
@@ -1767,7 +1832,7 @@ function createDynamicElement3(element, tag) {
|
|
|
1767
1832
|
function readReactive4(value) {
|
|
1768
1833
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1769
1834
|
}
|
|
1770
|
-
function
|
|
1835
|
+
function normalizeContent4(content) {
|
|
1771
1836
|
if (content == null || typeof content === "boolean") {
|
|
1772
1837
|
return [];
|
|
1773
1838
|
}
|
|
@@ -1776,7 +1841,7 @@ function normalizeContent3(content) {
|
|
|
1776
1841
|
function isElementLike3(value) {
|
|
1777
1842
|
return value != null && typeof value === "object" && "tag" in value;
|
|
1778
1843
|
}
|
|
1779
|
-
function
|
|
1844
|
+
function getMatchElement2(value) {
|
|
1780
1845
|
if (!isElementLike3(value)) {
|
|
1781
1846
|
return null;
|
|
1782
1847
|
}
|
|
@@ -1786,5 +1851,5 @@ function getMatchElement3(value) {
|
|
|
1786
1851
|
return value.tag === Match ? Match(value.props) : null;
|
|
1787
1852
|
}
|
|
1788
1853
|
|
|
1789
|
-
//# debugId=
|
|
1854
|
+
//# debugId=E58B3ECE3457B48064756E2164756E21
|
|
1790
1855
|
//# sourceMappingURL=index.development.js.map
|