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
|
@@ -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();
|
|
@@ -537,6 +537,19 @@ function batch(fn) {
|
|
|
537
537
|
}
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
+
// src/reactivity/normalization.ts
|
|
541
|
+
function isReactive(value) {
|
|
542
|
+
return isSignal(value) || isComputed(value) || typeof value === "function";
|
|
543
|
+
}
|
|
544
|
+
function resolve(value) {
|
|
545
|
+
if (isSignal(value) || isComputed(value)) {
|
|
546
|
+
return value.value;
|
|
547
|
+
}
|
|
548
|
+
if (typeof value === "function") {
|
|
549
|
+
return value();
|
|
550
|
+
}
|
|
551
|
+
return value;
|
|
552
|
+
}
|
|
540
553
|
// src/component/control-flow.ts
|
|
541
554
|
var SHOW_TYPE = Symbol.for("Sinwan.Show");
|
|
542
555
|
var FOR_TYPE = Symbol.for("Sinwan.For");
|
|
@@ -630,6 +643,9 @@ function Portal(props) {
|
|
|
630
643
|
children: []
|
|
631
644
|
};
|
|
632
645
|
}
|
|
646
|
+
function isElementLike(value) {
|
|
647
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
648
|
+
}
|
|
633
649
|
function isShowElement(element) {
|
|
634
650
|
return element.tag === SHOW_TYPE;
|
|
635
651
|
}
|
|
@@ -654,6 +670,107 @@ function isDynamicElement(element) {
|
|
|
654
670
|
function isPortalElement(element) {
|
|
655
671
|
return element.tag === PORTAL_TYPE;
|
|
656
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
|
+
}
|
|
657
774
|
function normalizeChildren2(children) {
|
|
658
775
|
if (children == null || typeof children === "boolean") {
|
|
659
776
|
return [];
|
|
@@ -661,7 +778,7 @@ function normalizeChildren2(children) {
|
|
|
661
778
|
return Array.isArray(children) ? children : [children];
|
|
662
779
|
}
|
|
663
780
|
function readReactive(value) {
|
|
664
|
-
return
|
|
781
|
+
return resolve(value);
|
|
665
782
|
}
|
|
666
783
|
function appendHiddenDisplay(style) {
|
|
667
784
|
const trimmed = style.trim();
|
|
@@ -831,75 +948,27 @@ async function renderIndexElement(element) {
|
|
|
831
948
|
const rendered = await Promise.all(each.map((item, index) => renderToString(props.children(() => item, index))));
|
|
832
949
|
return rendered.join("");
|
|
833
950
|
}
|
|
834
|
-
function resolveSwitchContent(element) {
|
|
835
|
-
const props = element.props;
|
|
836
|
-
const children = normalizeContent(props.children ?? element.children);
|
|
837
|
-
for (const child of children) {
|
|
838
|
-
const match = getMatchElement(child);
|
|
839
|
-
if (!match) {
|
|
840
|
-
continue;
|
|
841
|
-
}
|
|
842
|
-
const when = readReactive2(match.props.when);
|
|
843
|
-
if (when) {
|
|
844
|
-
return resolveMatchChildren(match, when);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return props.fallback;
|
|
848
|
-
}
|
|
849
|
-
function resolveMatchChildren(element, value) {
|
|
850
|
-
const children = element.props.children ?? element.children;
|
|
851
|
-
if (typeof children === "function") {
|
|
852
|
-
return children(value);
|
|
853
|
-
}
|
|
854
|
-
return children;
|
|
855
|
-
}
|
|
856
|
-
function resolveKeyChildren(element, value) {
|
|
857
|
-
const children = element.props.children ?? element.children;
|
|
858
|
-
if (typeof children === "function") {
|
|
859
|
-
return children(value);
|
|
860
|
-
}
|
|
861
|
-
return children;
|
|
862
|
-
}
|
|
863
951
|
function createDynamicElement(element, tag) {
|
|
864
952
|
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
865
953
|
return null;
|
|
866
954
|
}
|
|
867
955
|
const { component, ...props } = element.props;
|
|
868
|
-
const children =
|
|
956
|
+
const children = normalizeContent2(props.children ?? element.children);
|
|
869
957
|
return {
|
|
870
958
|
tag,
|
|
871
959
|
props,
|
|
872
960
|
children
|
|
873
961
|
};
|
|
874
962
|
}
|
|
875
|
-
function resolveShowChildren(element, value) {
|
|
876
|
-
const children = element.props.children ?? element.children;
|
|
877
|
-
if (typeof children === "function") {
|
|
878
|
-
return children(value);
|
|
879
|
-
}
|
|
880
|
-
return children;
|
|
881
|
-
}
|
|
882
963
|
function readReactive2(value) {
|
|
883
964
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
884
965
|
}
|
|
885
|
-
function
|
|
966
|
+
function normalizeContent2(content) {
|
|
886
967
|
if (content == null || typeof content === "boolean") {
|
|
887
968
|
return [];
|
|
888
969
|
}
|
|
889
970
|
return Array.isArray(content) ? content : [content];
|
|
890
971
|
}
|
|
891
|
-
function isElementLike(value) {
|
|
892
|
-
return value != null && typeof value === "object" && "tag" in value;
|
|
893
|
-
}
|
|
894
|
-
function getMatchElement(value) {
|
|
895
|
-
if (!isElementLike(value)) {
|
|
896
|
-
return null;
|
|
897
|
-
}
|
|
898
|
-
if (isMatchElement(value)) {
|
|
899
|
-
return value;
|
|
900
|
-
}
|
|
901
|
-
return value.tag === Match ? Match(value.props) : null;
|
|
902
|
-
}
|
|
903
972
|
// src/component/instance.ts
|
|
904
973
|
var uidCounter = 0;
|
|
905
974
|
function createComponentInstance(component, props, parent) {
|
|
@@ -952,19 +1021,28 @@ function fireMountedHooks(instance) {
|
|
|
952
1021
|
}
|
|
953
1022
|
}
|
|
954
1023
|
function fireUnmountedHooks(instance) {
|
|
955
|
-
|
|
1024
|
+
const children = [...instance.children];
|
|
1025
|
+
for (const child of children) {
|
|
956
1026
|
fireUnmountedHooks(child);
|
|
957
1027
|
}
|
|
958
|
-
if (
|
|
1028
|
+
if (!instance.isUnmounted) {
|
|
959
1029
|
instance.isUnmounted = true;
|
|
960
|
-
instance.isMounted
|
|
961
|
-
|
|
962
|
-
hook
|
|
1030
|
+
if (instance.isMounted) {
|
|
1031
|
+
instance.isMounted = false;
|
|
1032
|
+
for (const hook of instance._unmountedHooks) {
|
|
1033
|
+
hook();
|
|
1034
|
+
}
|
|
963
1035
|
}
|
|
964
1036
|
for (const dispose of instance.effects) {
|
|
965
1037
|
dispose();
|
|
966
1038
|
}
|
|
967
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
|
+
}
|
|
968
1046
|
}
|
|
969
1047
|
}
|
|
970
1048
|
function fireUpdatedHooks(instance) {
|
|
@@ -1449,9 +1527,9 @@ function resolveShowChildren2(element, value) {
|
|
|
1449
1527
|
}
|
|
1450
1528
|
function resolveSwitchContent2(element) {
|
|
1451
1529
|
const props = element.props;
|
|
1452
|
-
const children =
|
|
1530
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1453
1531
|
for (const child of children) {
|
|
1454
|
-
const match =
|
|
1532
|
+
const match = getMatchElement(child);
|
|
1455
1533
|
if (!match) {
|
|
1456
1534
|
continue;
|
|
1457
1535
|
}
|
|
@@ -1481,7 +1559,7 @@ function createDynamicElement2(element, tag) {
|
|
|
1481
1559
|
return null;
|
|
1482
1560
|
}
|
|
1483
1561
|
const { component, ...props } = element.props;
|
|
1484
|
-
const children =
|
|
1562
|
+
const children = normalizeContent3(props.children ?? element.children);
|
|
1485
1563
|
return {
|
|
1486
1564
|
tag,
|
|
1487
1565
|
props,
|
|
@@ -1491,7 +1569,7 @@ function createDynamicElement2(element, tag) {
|
|
|
1491
1569
|
function readReactive3(value) {
|
|
1492
1570
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1493
1571
|
}
|
|
1494
|
-
function
|
|
1572
|
+
function normalizeContent3(content) {
|
|
1495
1573
|
if (content == null || typeof content === "boolean") {
|
|
1496
1574
|
return [];
|
|
1497
1575
|
}
|
|
@@ -1500,7 +1578,7 @@ function normalizeContent2(content) {
|
|
|
1500
1578
|
function isElementLike2(value) {
|
|
1501
1579
|
return value != null && typeof value === "object" && "tag" in value;
|
|
1502
1580
|
}
|
|
1503
|
-
function
|
|
1581
|
+
function getMatchElement(value) {
|
|
1504
1582
|
if (!isElementLike2(value)) {
|
|
1505
1583
|
return null;
|
|
1506
1584
|
}
|
|
@@ -1712,9 +1790,9 @@ function resolveShowChildren3(element, value) {
|
|
|
1712
1790
|
}
|
|
1713
1791
|
function resolveSwitchContent3(element) {
|
|
1714
1792
|
const props = element.props;
|
|
1715
|
-
const children =
|
|
1793
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
1716
1794
|
for (const child of children) {
|
|
1717
|
-
const match =
|
|
1795
|
+
const match = getMatchElement2(child);
|
|
1718
1796
|
if (!match) {
|
|
1719
1797
|
continue;
|
|
1720
1798
|
}
|
|
@@ -1744,7 +1822,7 @@ function createDynamicElement3(element, tag) {
|
|
|
1744
1822
|
return null;
|
|
1745
1823
|
}
|
|
1746
1824
|
const { component, ...props } = element.props;
|
|
1747
|
-
const children =
|
|
1825
|
+
const children = normalizeContent4(props.children ?? element.children);
|
|
1748
1826
|
return {
|
|
1749
1827
|
tag,
|
|
1750
1828
|
props,
|
|
@@ -1754,7 +1832,7 @@ function createDynamicElement3(element, tag) {
|
|
|
1754
1832
|
function readReactive4(value) {
|
|
1755
1833
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
1756
1834
|
}
|
|
1757
|
-
function
|
|
1835
|
+
function normalizeContent4(content) {
|
|
1758
1836
|
if (content == null || typeof content === "boolean") {
|
|
1759
1837
|
return [];
|
|
1760
1838
|
}
|
|
@@ -1763,7 +1841,7 @@ function normalizeContent3(content) {
|
|
|
1763
1841
|
function isElementLike3(value) {
|
|
1764
1842
|
return value != null && typeof value === "object" && "tag" in value;
|
|
1765
1843
|
}
|
|
1766
|
-
function
|
|
1844
|
+
function getMatchElement2(value) {
|
|
1767
1845
|
if (!isElementLike3(value)) {
|
|
1768
1846
|
return null;
|
|
1769
1847
|
}
|
|
@@ -1773,5 +1851,5 @@ function getMatchElement3(value) {
|
|
|
1773
1851
|
return value.tag === Match ? Match(value.props) : null;
|
|
1774
1852
|
}
|
|
1775
1853
|
|
|
1776
|
-
//# debugId=
|
|
1854
|
+
//# debugId=E58B3ECE3457B48064756E2164756E21
|
|
1777
1855
|
//# sourceMappingURL=index.development.js.map
|