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
|
@@ -436,7 +436,7 @@ function resetDOMOps() {
|
|
|
436
436
|
|
|
437
437
|
// src/renderer/events.ts
|
|
438
438
|
function isEventProp(key) {
|
|
439
|
-
return key.length > 2 && key
|
|
439
|
+
return key.length > 2 && key.startsWith("on");
|
|
440
440
|
}
|
|
441
441
|
function toEventName(key) {
|
|
442
442
|
return key.slice(2).toLowerCase();
|
|
@@ -579,6 +579,9 @@ function Portal(props) {
|
|
|
579
579
|
children: []
|
|
580
580
|
};
|
|
581
581
|
}
|
|
582
|
+
function isElementLike(value) {
|
|
583
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
584
|
+
}
|
|
582
585
|
function isShowElement(element) {
|
|
583
586
|
return element.tag === SHOW_TYPE;
|
|
584
587
|
}
|
|
@@ -603,6 +606,107 @@ function isDynamicElement(element) {
|
|
|
603
606
|
function isPortalElement(element) {
|
|
604
607
|
return element.tag === PORTAL_TYPE;
|
|
605
608
|
}
|
|
609
|
+
function resolveSwitchContent(element) {
|
|
610
|
+
const props = element.props;
|
|
611
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
612
|
+
const match = findTruthyMatch(children);
|
|
613
|
+
return match !== undefined ? match : props.fallback;
|
|
614
|
+
}
|
|
615
|
+
function findTruthyMatch(nodes) {
|
|
616
|
+
for (const node of nodes) {
|
|
617
|
+
if (node == null || typeof node === "boolean")
|
|
618
|
+
continue;
|
|
619
|
+
if (Array.isArray(node)) {
|
|
620
|
+
const match = findTruthyMatch(node);
|
|
621
|
+
if (match !== undefined)
|
|
622
|
+
return match;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
if (isElementLike(node)) {
|
|
626
|
+
let element = node;
|
|
627
|
+
if (typeof element.tag === "function") {
|
|
628
|
+
const tag = element.tag;
|
|
629
|
+
if (tag === Match || tag === Show || tag === For || tag === Index || tag === Key || tag === Switch) {
|
|
630
|
+
element = tag(element.props);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (isMatchElement(element)) {
|
|
634
|
+
const when = readReactive(element.props.when);
|
|
635
|
+
if (when) {
|
|
636
|
+
return resolveMatchChildren(element, when);
|
|
637
|
+
}
|
|
638
|
+
} else if (isShowElement(element)) {
|
|
639
|
+
const when = readReactive(element.props.when);
|
|
640
|
+
if (when) {
|
|
641
|
+
const content = resolveShowChildren(element, when);
|
|
642
|
+
const match = findTruthyMatch(normalizeContent(content));
|
|
643
|
+
if (match !== undefined)
|
|
644
|
+
return match;
|
|
645
|
+
} else if (element.props.fallback) {
|
|
646
|
+
const match = findTruthyMatch(normalizeContent(element.props.fallback));
|
|
647
|
+
if (match !== undefined)
|
|
648
|
+
return match;
|
|
649
|
+
}
|
|
650
|
+
} else if (isForElement(element)) {
|
|
651
|
+
const props = element.props;
|
|
652
|
+
const items = readReactive(props.each);
|
|
653
|
+
if (Array.isArray(items)) {
|
|
654
|
+
for (let i = 0;i < items.length; i++) {
|
|
655
|
+
const child = props.children(items[i], () => i);
|
|
656
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
657
|
+
if (match !== undefined)
|
|
658
|
+
return match;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
} else if (isIndexElement(element)) {
|
|
662
|
+
const props = element.props;
|
|
663
|
+
const items = readReactive(props.each);
|
|
664
|
+
if (Array.isArray(items)) {
|
|
665
|
+
for (let i = 0;i < items.length; i++) {
|
|
666
|
+
const child = props.children(() => items[i], i);
|
|
667
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
668
|
+
if (match !== undefined)
|
|
669
|
+
return match;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
} else if (isKeyElement(element)) {
|
|
673
|
+
const key = readReactive(element.props.when);
|
|
674
|
+
const child = resolveKeyChildren(element, key);
|
|
675
|
+
const match = findTruthyMatch(normalizeContent(child));
|
|
676
|
+
if (match !== undefined)
|
|
677
|
+
return match;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
function resolveMatchChildren(element, value) {
|
|
684
|
+
const children = element.props.children ?? element.children;
|
|
685
|
+
if (typeof children === "function") {
|
|
686
|
+
return children(value);
|
|
687
|
+
}
|
|
688
|
+
return children;
|
|
689
|
+
}
|
|
690
|
+
function resolveShowChildren(element, value) {
|
|
691
|
+
const children = element.props.children ?? element.children;
|
|
692
|
+
if (typeof children === "function") {
|
|
693
|
+
return children(value);
|
|
694
|
+
}
|
|
695
|
+
return children;
|
|
696
|
+
}
|
|
697
|
+
function resolveKeyChildren(element, value) {
|
|
698
|
+
const children = element.props.children ?? element.children;
|
|
699
|
+
if (typeof children === "function") {
|
|
700
|
+
return children(value);
|
|
701
|
+
}
|
|
702
|
+
return children;
|
|
703
|
+
}
|
|
704
|
+
function normalizeContent(content) {
|
|
705
|
+
if (content == null || typeof content === "boolean") {
|
|
706
|
+
return [];
|
|
707
|
+
}
|
|
708
|
+
return Array.isArray(content) ? content : [content];
|
|
709
|
+
}
|
|
606
710
|
function normalizeChildren2(children) {
|
|
607
711
|
if (children == null || typeof children === "boolean") {
|
|
608
712
|
return [];
|
|
@@ -780,75 +884,27 @@ async function renderIndexElement(element) {
|
|
|
780
884
|
const rendered = await Promise.all(each.map((item, index) => renderToString(props.children(() => item, index))));
|
|
781
885
|
return rendered.join("");
|
|
782
886
|
}
|
|
783
|
-
function resolveSwitchContent(element) {
|
|
784
|
-
const props = element.props;
|
|
785
|
-
const children = normalizeContent(props.children ?? element.children);
|
|
786
|
-
for (const child of children) {
|
|
787
|
-
const match = getMatchElement(child);
|
|
788
|
-
if (!match) {
|
|
789
|
-
continue;
|
|
790
|
-
}
|
|
791
|
-
const when = readReactive2(match.props.when);
|
|
792
|
-
if (when) {
|
|
793
|
-
return resolveMatchChildren(match, when);
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
return props.fallback;
|
|
797
|
-
}
|
|
798
|
-
function resolveMatchChildren(element, value) {
|
|
799
|
-
const children = element.props.children ?? element.children;
|
|
800
|
-
if (typeof children === "function") {
|
|
801
|
-
return children(value);
|
|
802
|
-
}
|
|
803
|
-
return children;
|
|
804
|
-
}
|
|
805
|
-
function resolveKeyChildren(element, value) {
|
|
806
|
-
const children = element.props.children ?? element.children;
|
|
807
|
-
if (typeof children === "function") {
|
|
808
|
-
return children(value);
|
|
809
|
-
}
|
|
810
|
-
return children;
|
|
811
|
-
}
|
|
812
887
|
function createDynamicElement(element, tag) {
|
|
813
888
|
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
814
889
|
return null;
|
|
815
890
|
}
|
|
816
891
|
const { component, ...props } = element.props;
|
|
817
|
-
const children =
|
|
892
|
+
const children = normalizeContent2(props.children ?? element.children);
|
|
818
893
|
return {
|
|
819
894
|
tag,
|
|
820
895
|
props,
|
|
821
896
|
children
|
|
822
897
|
};
|
|
823
898
|
}
|
|
824
|
-
function resolveShowChildren(element, value) {
|
|
825
|
-
const children = element.props.children ?? element.children;
|
|
826
|
-
if (typeof children === "function") {
|
|
827
|
-
return children(value);
|
|
828
|
-
}
|
|
829
|
-
return children;
|
|
830
|
-
}
|
|
831
899
|
function readReactive2(value) {
|
|
832
900
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
833
901
|
}
|
|
834
|
-
function
|
|
902
|
+
function normalizeContent2(content) {
|
|
835
903
|
if (content == null || typeof content === "boolean") {
|
|
836
904
|
return [];
|
|
837
905
|
}
|
|
838
906
|
return Array.isArray(content) ? content : [content];
|
|
839
907
|
}
|
|
840
|
-
function isElementLike(value) {
|
|
841
|
-
return value != null && typeof value === "object" && "tag" in value;
|
|
842
|
-
}
|
|
843
|
-
function getMatchElement(value) {
|
|
844
|
-
if (!isElementLike(value)) {
|
|
845
|
-
return null;
|
|
846
|
-
}
|
|
847
|
-
if (isMatchElement(value)) {
|
|
848
|
-
return value;
|
|
849
|
-
}
|
|
850
|
-
return value.tag === Match ? Match(value.props) : null;
|
|
851
|
-
}
|
|
852
908
|
// src/component/instance.ts
|
|
853
909
|
var uidCounter = 0;
|
|
854
910
|
function createComponentInstance(component, props, parent) {
|
|
@@ -901,19 +957,28 @@ function fireMountedHooks(instance) {
|
|
|
901
957
|
}
|
|
902
958
|
}
|
|
903
959
|
function fireUnmountedHooks(instance) {
|
|
904
|
-
|
|
960
|
+
const children = [...instance.children];
|
|
961
|
+
for (const child of children) {
|
|
905
962
|
fireUnmountedHooks(child);
|
|
906
963
|
}
|
|
907
|
-
if (
|
|
964
|
+
if (!instance.isUnmounted) {
|
|
908
965
|
instance.isUnmounted = true;
|
|
909
|
-
instance.isMounted
|
|
910
|
-
|
|
911
|
-
hook
|
|
966
|
+
if (instance.isMounted) {
|
|
967
|
+
instance.isMounted = false;
|
|
968
|
+
for (const hook of instance._unmountedHooks) {
|
|
969
|
+
hook();
|
|
970
|
+
}
|
|
912
971
|
}
|
|
913
972
|
for (const dispose of instance.effects) {
|
|
914
973
|
dispose();
|
|
915
974
|
}
|
|
916
975
|
instance.effects.length = 0;
|
|
976
|
+
if (instance.parent) {
|
|
977
|
+
const idx = instance.parent.children.indexOf(instance);
|
|
978
|
+
if (idx !== -1) {
|
|
979
|
+
instance.parent.children.splice(idx, 1);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
917
982
|
}
|
|
918
983
|
}
|
|
919
984
|
function fireUpdatedHooks(instance) {
|
|
@@ -1398,9 +1463,9 @@ function resolveShowChildren2(element, value) {
|
|
|
1398
1463
|
}
|
|
1399
1464
|
function resolveSwitchContent2(element) {
|
|
1400
1465
|
const props = element.props;
|
|
1401
|
-
const children =
|
|
1466
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1402
1467
|
for (const child of children) {
|
|
1403
|
-
const match =
|
|
1468
|
+
const match = getMatchElement(child);
|
|
1404
1469
|
if (!match) {
|
|
1405
1470
|
continue;
|
|
1406
1471
|
}
|
|
@@ -1430,7 +1495,7 @@ function createDynamicElement2(element, tag) {
|
|
|
1430
1495
|
return null;
|
|
1431
1496
|
}
|
|
1432
1497
|
const { component, ...props } = element.props;
|
|
1433
|
-
const children =
|
|
1498
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1434
1499
|
return {
|
|
1435
1500
|
tag,
|
|
1436
1501
|
props,
|
|
@@ -1440,7 +1505,7 @@ function createDynamicElement2(element, tag) {
|
|
|
1440
1505
|
function readReactive3(value) {
|
|
1441
1506
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1442
1507
|
}
|
|
1443
|
-
function
|
|
1508
|
+
function normalizeContent3(content) {
|
|
1444
1509
|
if (content == null || typeof content === "boolean") {
|
|
1445
1510
|
return [];
|
|
1446
1511
|
}
|
|
@@ -1449,7 +1514,7 @@ function normalizeContent2(content) {
|
|
|
1449
1514
|
function isElementLike2(value) {
|
|
1450
1515
|
return value != null && typeof value === "object" && "tag" in value;
|
|
1451
1516
|
}
|
|
1452
|
-
function
|
|
1517
|
+
function getMatchElement(value) {
|
|
1453
1518
|
if (!isElementLike2(value)) {
|
|
1454
1519
|
return null;
|
|
1455
1520
|
}
|
|
@@ -1661,9 +1726,9 @@ function resolveShowChildren3(element, value) {
|
|
|
1661
1726
|
}
|
|
1662
1727
|
function resolveSwitchContent3(element) {
|
|
1663
1728
|
const props = element.props;
|
|
1664
|
-
const children =
|
|
1729
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
1665
1730
|
for (const child of children) {
|
|
1666
|
-
const match =
|
|
1731
|
+
const match = getMatchElement2(child);
|
|
1667
1732
|
if (!match) {
|
|
1668
1733
|
continue;
|
|
1669
1734
|
}
|
|
@@ -1693,7 +1758,7 @@ function createDynamicElement3(element, tag) {
|
|
|
1693
1758
|
return null;
|
|
1694
1759
|
}
|
|
1695
1760
|
const { component, ...props } = element.props;
|
|
1696
|
-
const children =
|
|
1761
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
1697
1762
|
return {
|
|
1698
1763
|
tag,
|
|
1699
1764
|
props,
|
|
@@ -1703,7 +1768,7 @@ function createDynamicElement3(element, tag) {
|
|
|
1703
1768
|
function readReactive4(value) {
|
|
1704
1769
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1705
1770
|
}
|
|
1706
|
-
function
|
|
1771
|
+
function normalizeContent4(content) {
|
|
1707
1772
|
if (content == null || typeof content === "boolean") {
|
|
1708
1773
|
return [];
|
|
1709
1774
|
}
|
|
@@ -1712,7 +1777,7 @@ function normalizeContent3(content) {
|
|
|
1712
1777
|
function isElementLike3(value) {
|
|
1713
1778
|
return value != null && typeof value === "object" && "tag" in value;
|
|
1714
1779
|
}
|
|
1715
|
-
function
|
|
1780
|
+
function getMatchElement2(value) {
|
|
1716
1781
|
if (!isElementLike3(value)) {
|
|
1717
1782
|
return null;
|
|
1718
1783
|
}
|
|
@@ -1735,5 +1800,5 @@ export {
|
|
|
1735
1800
|
getPage
|
|
1736
1801
|
};
|
|
1737
1802
|
|
|
1738
|
-
//# debugId=
|
|
1803
|
+
//# debugId=ED2C426FA5DC589D64756E2164756E21
|
|
1739
1804
|
//# sourceMappingURL=index.development.js.map
|