sinwan 1.0.0 → 1.1.1
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 +1012 -112
- package/dist/cjs/index.development.js.map +16 -14
- package/dist/cjs/index.production.min.js +2 -2
- package/dist/cjs/index.production.min.js.map +16 -14
- package/dist/cjs/renderer/index.development.js +467 -29
- package/dist/cjs/renderer/index.development.js.map +11 -9
- package/dist/cjs/renderer/index.production.min.js +2 -2
- package/dist/cjs/renderer/index.production.min.js.map +11 -9
- package/dist/cjs/server/index.development.js +573 -48
- package/dist/cjs/server/index.development.js.map +10 -7
- package/dist/cjs/server/index.production.min.js +2 -2
- package/dist/cjs/server/index.production.min.js.map +10 -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 +1010 -110
- package/dist/esm/index.development.js.map +16 -14
- package/dist/esm/index.production.min.js +2 -2
- package/dist/esm/index.production.min.js.map +16 -14
- package/dist/esm/renderer/index.development.js +467 -29
- package/dist/esm/renderer/index.development.js.map +11 -9
- package/dist/esm/renderer/index.production.min.js +2 -2
- package/dist/esm/renderer/index.production.min.js.map +11 -9
- package/dist/esm/server/index.development.js +573 -48
- package/dist/esm/server/index.development.js.map +10 -7
- package/dist/esm/server/index.production.min.js +2 -2
- package/dist/esm/server/index.production.min.js.map +10 -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/reactivity/index.d.ts +1 -0
- 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 +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-children.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/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -383,7 +383,6 @@ function signal(initial) {
|
|
|
383
383
|
function isSignal(value) {
|
|
384
384
|
return value != null && typeof value === "object" && SIGNAL_BRAND in value;
|
|
385
385
|
}
|
|
386
|
-
|
|
387
386
|
// src/reactivity/computed.ts
|
|
388
387
|
var COMPUTED_BRAND = Symbol("Sinwan:computed");
|
|
389
388
|
|
|
@@ -435,7 +434,32 @@ function computed(getter) {
|
|
|
435
434
|
function isComputed(value) {
|
|
436
435
|
return value != null && typeof value === "object" && COMPUTED_BRAND in value;
|
|
437
436
|
}
|
|
438
|
-
|
|
437
|
+
// src/reactivity/batch.ts
|
|
438
|
+
var batchDepth = 0;
|
|
439
|
+
function batch(fn) {
|
|
440
|
+
batchDepth++;
|
|
441
|
+
try {
|
|
442
|
+
fn();
|
|
443
|
+
} finally {
|
|
444
|
+
batchDepth--;
|
|
445
|
+
if (batchDepth === 0) {
|
|
446
|
+
flushSync();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
// src/reactivity/normalization.ts
|
|
451
|
+
function isReactive(value) {
|
|
452
|
+
return isSignal(value) || isComputed(value) || typeof value === "function";
|
|
453
|
+
}
|
|
454
|
+
function resolve(value) {
|
|
455
|
+
if (isSignal(value) || isComputed(value)) {
|
|
456
|
+
return value.value;
|
|
457
|
+
}
|
|
458
|
+
if (typeof value === "function") {
|
|
459
|
+
return value();
|
|
460
|
+
}
|
|
461
|
+
return value;
|
|
462
|
+
}
|
|
439
463
|
// src/renderer/events.ts
|
|
440
464
|
function isEventProp(key) {
|
|
441
465
|
return key.length > 2 && key[0] === "o" && key[1] === "n" && key[2] >= "A" && key[2] <= "Z";
|
|
@@ -577,10 +601,11 @@ function applyAttributes(el, props) {
|
|
|
577
601
|
for (const [key, value] of Object.entries(props)) {
|
|
578
602
|
if (SKIP_PROPS.has(key) || isEventProp(key))
|
|
579
603
|
continue;
|
|
580
|
-
if (
|
|
604
|
+
if (isReactive(value)) {
|
|
605
|
+
const state = { previousStyleProps: new Set };
|
|
581
606
|
let initialized = false;
|
|
582
607
|
const dispose = effect(() => {
|
|
583
|
-
setSingleAttribute(el, key, value
|
|
608
|
+
setSingleAttribute(el, key, resolve(value), state);
|
|
584
609
|
if (initialized) {
|
|
585
610
|
queueUpdatedHooks(owner);
|
|
586
611
|
}
|
|
@@ -593,10 +618,10 @@ function applyAttributes(el, props) {
|
|
|
593
618
|
}
|
|
594
619
|
return disposers;
|
|
595
620
|
}
|
|
596
|
-
function setSingleAttribute(el, key, value) {
|
|
597
|
-
const attrName =
|
|
621
|
+
function setSingleAttribute(el, key, value, state) {
|
|
622
|
+
const attrName = resolveAttributeName(key);
|
|
598
623
|
if (attrName === "style" && typeof value === "object" && value !== null) {
|
|
599
|
-
applyStyle(el, value);
|
|
624
|
+
applyStyle(el, value, state);
|
|
600
625
|
return;
|
|
601
626
|
}
|
|
602
627
|
if (attrName === "class" && typeof value === "object" && value !== null) {
|
|
@@ -605,6 +630,9 @@ function setSingleAttribute(el, key, value) {
|
|
|
605
630
|
}
|
|
606
631
|
if (value == null || value === false) {
|
|
607
632
|
domOps.removeAttribute(el, attrName);
|
|
633
|
+
if (attrName === "style" && state) {
|
|
634
|
+
state.previousStyleProps.clear();
|
|
635
|
+
}
|
|
608
636
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
609
637
|
domOps.setProperty(el, attrName, attrName === "value" ? "" : false);
|
|
610
638
|
}
|
|
@@ -612,25 +640,59 @@ function setSingleAttribute(el, key, value) {
|
|
|
612
640
|
}
|
|
613
641
|
if (value === true) {
|
|
614
642
|
domOps.setAttribute(el, attrName, "");
|
|
643
|
+
if (attrName === "style" && state) {
|
|
644
|
+
state.previousStyleProps.clear();
|
|
645
|
+
}
|
|
615
646
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
616
647
|
domOps.setProperty(el, attrName, true);
|
|
617
648
|
}
|
|
618
649
|
return;
|
|
619
650
|
}
|
|
620
651
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
652
|
+
if (attrName === "style" && state) {
|
|
653
|
+
state.previousStyleProps.clear();
|
|
654
|
+
}
|
|
621
655
|
domOps.setProperty(el, attrName, value);
|
|
622
656
|
return;
|
|
623
657
|
}
|
|
658
|
+
if (attrName === "style" && state) {
|
|
659
|
+
state.previousStyleProps.clear();
|
|
660
|
+
}
|
|
624
661
|
domOps.setAttribute(el, attrName, String(value));
|
|
625
662
|
}
|
|
626
|
-
function
|
|
663
|
+
function resolveAttributeName(key) {
|
|
664
|
+
return PROP_ALIASES[key] ?? key;
|
|
665
|
+
}
|
|
666
|
+
function applyStyle(el, styles, state) {
|
|
667
|
+
const nextProps = new Set;
|
|
627
668
|
for (const [prop, val] of Object.entries(styles)) {
|
|
669
|
+
nextProps.add(prop);
|
|
670
|
+
if (val == null) {
|
|
671
|
+
removeStyleProperty(el, prop);
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
628
674
|
if (prop.includes("-")) {
|
|
629
|
-
el.style.setProperty(prop, val);
|
|
675
|
+
el.style.setProperty(prop, String(val));
|
|
630
676
|
} else {
|
|
631
677
|
el.style[prop] = val;
|
|
632
678
|
}
|
|
633
679
|
}
|
|
680
|
+
if (!state) {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
for (const previousProp of state.previousStyleProps) {
|
|
684
|
+
if (!nextProps.has(previousProp)) {
|
|
685
|
+
removeStyleProperty(el, previousProp);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
state.previousStyleProps = nextProps;
|
|
689
|
+
}
|
|
690
|
+
function removeStyleProperty(el, prop) {
|
|
691
|
+
if (prop.includes("-")) {
|
|
692
|
+
el.style.removeProperty(prop);
|
|
693
|
+
} else {
|
|
694
|
+
el.style[prop] = "";
|
|
695
|
+
}
|
|
634
696
|
}
|
|
635
697
|
function applyClass(el, value) {
|
|
636
698
|
let classStr;
|
|
@@ -647,6 +709,12 @@ function applyClass(el, value) {
|
|
|
647
709
|
// src/component/control-flow.ts
|
|
648
710
|
var SHOW_TYPE = Symbol.for("Sinwan.Show");
|
|
649
711
|
var FOR_TYPE = Symbol.for("Sinwan.For");
|
|
712
|
+
var SWITCH_TYPE = Symbol.for("Sinwan.Switch");
|
|
713
|
+
var MATCH_TYPE = Symbol.for("Sinwan.Match");
|
|
714
|
+
var INDEX_TYPE = Symbol.for("Sinwan.Index");
|
|
715
|
+
var KEY_TYPE = Symbol.for("Sinwan.Key");
|
|
716
|
+
var DYNAMIC_TYPE = Symbol.for("Sinwan.Dynamic");
|
|
717
|
+
var PORTAL_TYPE = Symbol.for("Sinwan.Portal");
|
|
650
718
|
function Show(props) {
|
|
651
719
|
return {
|
|
652
720
|
tag: SHOW_TYPE,
|
|
@@ -661,12 +729,114 @@ function For(props) {
|
|
|
661
729
|
children: []
|
|
662
730
|
};
|
|
663
731
|
}
|
|
732
|
+
function Switch(props) {
|
|
733
|
+
return {
|
|
734
|
+
tag: SWITCH_TYPE,
|
|
735
|
+
props,
|
|
736
|
+
children: []
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function Match(props) {
|
|
740
|
+
return {
|
|
741
|
+
tag: MATCH_TYPE,
|
|
742
|
+
props,
|
|
743
|
+
children: []
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function Index(props) {
|
|
747
|
+
return {
|
|
748
|
+
tag: INDEX_TYPE,
|
|
749
|
+
props,
|
|
750
|
+
children: []
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function Key(props) {
|
|
754
|
+
return {
|
|
755
|
+
tag: KEY_TYPE,
|
|
756
|
+
props,
|
|
757
|
+
children: []
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
function Dynamic(props) {
|
|
761
|
+
return {
|
|
762
|
+
tag: DYNAMIC_TYPE,
|
|
763
|
+
props,
|
|
764
|
+
children: []
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function Visible(props) {
|
|
768
|
+
const {
|
|
769
|
+
when,
|
|
770
|
+
as = "span",
|
|
771
|
+
style,
|
|
772
|
+
children,
|
|
773
|
+
...rest
|
|
774
|
+
} = props;
|
|
775
|
+
const visibleStyle = computed(() => {
|
|
776
|
+
const base = readReactive(style);
|
|
777
|
+
const visible = Boolean(readReactive(when));
|
|
778
|
+
if (typeof base === "string") {
|
|
779
|
+
return visible ? base : appendHiddenDisplay(base);
|
|
780
|
+
}
|
|
781
|
+
const styleObject = base && typeof base === "object" ? { ...base } : {};
|
|
782
|
+
styleObject.display = visible ? styleObject.display : "none";
|
|
783
|
+
return styleObject;
|
|
784
|
+
});
|
|
785
|
+
return {
|
|
786
|
+
tag: as,
|
|
787
|
+
props: {
|
|
788
|
+
...rest,
|
|
789
|
+
style: visibleStyle,
|
|
790
|
+
children
|
|
791
|
+
},
|
|
792
|
+
children: normalizeChildren2(children)
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function Portal(props) {
|
|
796
|
+
return {
|
|
797
|
+
tag: PORTAL_TYPE,
|
|
798
|
+
props,
|
|
799
|
+
children: []
|
|
800
|
+
};
|
|
801
|
+
}
|
|
664
802
|
function isShowElement(element) {
|
|
665
803
|
return element.tag === SHOW_TYPE;
|
|
666
804
|
}
|
|
667
805
|
function isForElement(element) {
|
|
668
806
|
return element.tag === FOR_TYPE;
|
|
669
807
|
}
|
|
808
|
+
function isSwitchElement(element) {
|
|
809
|
+
return element.tag === SWITCH_TYPE;
|
|
810
|
+
}
|
|
811
|
+
function isMatchElement(element) {
|
|
812
|
+
return element.tag === MATCH_TYPE;
|
|
813
|
+
}
|
|
814
|
+
function isIndexElement(element) {
|
|
815
|
+
return element.tag === INDEX_TYPE;
|
|
816
|
+
}
|
|
817
|
+
function isKeyElement(element) {
|
|
818
|
+
return element.tag === KEY_TYPE;
|
|
819
|
+
}
|
|
820
|
+
function isDynamicElement(element) {
|
|
821
|
+
return element.tag === DYNAMIC_TYPE;
|
|
822
|
+
}
|
|
823
|
+
function isPortalElement(element) {
|
|
824
|
+
return element.tag === PORTAL_TYPE;
|
|
825
|
+
}
|
|
826
|
+
function normalizeChildren2(children) {
|
|
827
|
+
if (children == null || typeof children === "boolean") {
|
|
828
|
+
return [];
|
|
829
|
+
}
|
|
830
|
+
return Array.isArray(children) ? children : [children];
|
|
831
|
+
}
|
|
832
|
+
function readReactive(value) {
|
|
833
|
+
return resolve(value);
|
|
834
|
+
}
|
|
835
|
+
function appendHiddenDisplay(style) {
|
|
836
|
+
const trimmed = style.trim();
|
|
837
|
+
const separator = trimmed.length > 0 && !trimmed.endsWith(";") ? ";" : "";
|
|
838
|
+
return `${trimmed}${separator}display:none`;
|
|
839
|
+
}
|
|
670
840
|
|
|
671
841
|
// src/renderer/unmount.ts
|
|
672
842
|
function getMountedDomNodes(node) {
|
|
@@ -689,6 +859,8 @@ function getMountedDomNodes(node) {
|
|
|
689
859
|
];
|
|
690
860
|
case "component":
|
|
691
861
|
return node.children.flatMap((child) => getMountedDomNodes(child));
|
|
862
|
+
case "portal":
|
|
863
|
+
return [node.anchor];
|
|
692
864
|
}
|
|
693
865
|
}
|
|
694
866
|
function unmountNode(node) {
|
|
@@ -733,6 +905,13 @@ function unmountNode(node) {
|
|
|
733
905
|
unmountNode(child);
|
|
734
906
|
}
|
|
735
907
|
break;
|
|
908
|
+
case "portal":
|
|
909
|
+
node.dispose();
|
|
910
|
+
for (const child of node.children) {
|
|
911
|
+
removeMountedNode(child);
|
|
912
|
+
}
|
|
913
|
+
node.children = [];
|
|
914
|
+
break;
|
|
736
915
|
}
|
|
737
916
|
}
|
|
738
917
|
function removeMountedNode(node) {
|
|
@@ -747,6 +926,9 @@ function removeMountedNode(node) {
|
|
|
747
926
|
|
|
748
927
|
// src/renderer/render-control-flow.ts
|
|
749
928
|
function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
929
|
+
if (isPortalElement(element)) {
|
|
930
|
+
return renderPortal(element, parent, anchor, namespace);
|
|
931
|
+
}
|
|
750
932
|
const startAnchor = domOps.createComment("Sinwan-b");
|
|
751
933
|
const endAnchor = domOps.createComment("/Sinwan-b");
|
|
752
934
|
insertNode(parent, startAnchor, anchor);
|
|
@@ -764,6 +946,14 @@ function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
|
764
946
|
disposeEffect = renderShowBlock(element, block, parent, namespace, owner);
|
|
765
947
|
} else if (isForElement(element)) {
|
|
766
948
|
disposeEffect = renderForBlock(element, block, parent, namespace, owner);
|
|
949
|
+
} else if (isSwitchElement(element)) {
|
|
950
|
+
disposeEffect = renderSwitchBlock(element, block, parent, namespace, owner);
|
|
951
|
+
} else if (isIndexElement(element)) {
|
|
952
|
+
disposeEffect = renderIndexBlock(element, block, parent, namespace, owner);
|
|
953
|
+
} else if (isKeyElement(element)) {
|
|
954
|
+
disposeEffect = renderKeyBlock(element, block, parent, namespace, owner);
|
|
955
|
+
} else if (isDynamicElement(element)) {
|
|
956
|
+
disposeEffect = renderDynamicBlock(element, block, parent, namespace, owner);
|
|
767
957
|
}
|
|
768
958
|
return block;
|
|
769
959
|
}
|
|
@@ -771,7 +961,7 @@ function renderShowBlock(element, block, parent, namespace, owner) {
|
|
|
771
961
|
let initialized = false;
|
|
772
962
|
return effect(() => {
|
|
773
963
|
clearChildren(block);
|
|
774
|
-
const when =
|
|
964
|
+
const when = readReactive2(element.props.when);
|
|
775
965
|
const content = withOptionalInstance(owner, () => when ? resolveShowChildren(element, when) : element.props.fallback);
|
|
776
966
|
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
777
967
|
if (initialized) {
|
|
@@ -785,7 +975,7 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
785
975
|
let records = [];
|
|
786
976
|
return effect(() => {
|
|
787
977
|
const props = element.props;
|
|
788
|
-
const items =
|
|
978
|
+
const items = readReactive2(props.each);
|
|
789
979
|
const list = Array.isArray(items) ? items : [];
|
|
790
980
|
const renderChild = props.children;
|
|
791
981
|
if (typeof renderChild !== "function") {
|
|
@@ -797,6 +987,19 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
797
987
|
initialized = true;
|
|
798
988
|
return;
|
|
799
989
|
}
|
|
990
|
+
if (list.length === 0) {
|
|
991
|
+
clearChildren(block);
|
|
992
|
+
records = [];
|
|
993
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
994
|
+
if (initialized) {
|
|
995
|
+
fireMountedAndQueueUpdated(owner);
|
|
996
|
+
}
|
|
997
|
+
initialized = true;
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
1001
|
+
clearChildren(block);
|
|
1002
|
+
}
|
|
800
1003
|
const oldByKey = new Map;
|
|
801
1004
|
for (const record of records) {
|
|
802
1005
|
oldByKey.set(record.key, record);
|
|
@@ -836,6 +1039,137 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
836
1039
|
initialized = true;
|
|
837
1040
|
});
|
|
838
1041
|
}
|
|
1042
|
+
function renderSwitchBlock(element, block, parent, namespace, owner) {
|
|
1043
|
+
let initialized = false;
|
|
1044
|
+
return effect(() => {
|
|
1045
|
+
clearChildren(block);
|
|
1046
|
+
const content = withOptionalInstance(owner, () => resolveSwitchContent(element));
|
|
1047
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1048
|
+
if (initialized) {
|
|
1049
|
+
fireMountedAndQueueUpdated(owner);
|
|
1050
|
+
}
|
|
1051
|
+
initialized = true;
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
function renderIndexBlock(element, block, parent, namespace, owner) {
|
|
1055
|
+
let initialized = false;
|
|
1056
|
+
let records = [];
|
|
1057
|
+
return effect(() => {
|
|
1058
|
+
const props = element.props;
|
|
1059
|
+
const items = readReactive2(props.each);
|
|
1060
|
+
const list = Array.isArray(items) ? items : [];
|
|
1061
|
+
const renderChild = props.children;
|
|
1062
|
+
if (typeof renderChild !== "function") {
|
|
1063
|
+
clearChildren(block);
|
|
1064
|
+
records = [];
|
|
1065
|
+
if (initialized) {
|
|
1066
|
+
queueUpdatedHooks(owner);
|
|
1067
|
+
}
|
|
1068
|
+
initialized = true;
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
if (list.length === 0) {
|
|
1072
|
+
clearChildren(block);
|
|
1073
|
+
records = [];
|
|
1074
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
1075
|
+
if (initialized) {
|
|
1076
|
+
fireMountedAndQueueUpdated(owner);
|
|
1077
|
+
}
|
|
1078
|
+
initialized = true;
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
1082
|
+
clearChildren(block);
|
|
1083
|
+
}
|
|
1084
|
+
for (let index = 0;index < list.length; index++) {
|
|
1085
|
+
const existing = records[index];
|
|
1086
|
+
if (existing) {
|
|
1087
|
+
existing.item.value = list[index];
|
|
1088
|
+
continue;
|
|
1089
|
+
}
|
|
1090
|
+
const itemSignal = signal(list[index]);
|
|
1091
|
+
const record = {
|
|
1092
|
+
item: itemSignal,
|
|
1093
|
+
mounted: withOptionalInstance(owner, () => renderNodeToDOM(renderChild(() => itemSignal.value, index), parent, block.endAnchor, namespace))
|
|
1094
|
+
};
|
|
1095
|
+
records.push(record);
|
|
1096
|
+
}
|
|
1097
|
+
while (records.length > list.length) {
|
|
1098
|
+
const removed = records.pop();
|
|
1099
|
+
removeMountedNode(removed.mounted);
|
|
1100
|
+
}
|
|
1101
|
+
block.children = records.map((record) => record.mounted);
|
|
1102
|
+
if (initialized) {
|
|
1103
|
+
fireMountedAndQueueUpdated(owner);
|
|
1104
|
+
}
|
|
1105
|
+
initialized = true;
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
function renderKeyBlock(element, block, parent, namespace, owner) {
|
|
1109
|
+
let initialized = false;
|
|
1110
|
+
let hasKey = false;
|
|
1111
|
+
let currentKey;
|
|
1112
|
+
return effect(() => {
|
|
1113
|
+
const key = readReactive2(element.props.when);
|
|
1114
|
+
if (hasKey && Object.is(currentKey, key)) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
currentKey = key;
|
|
1118
|
+
hasKey = true;
|
|
1119
|
+
clearChildren(block);
|
|
1120
|
+
const content = withOptionalInstance(owner, () => resolveKeyChildren(element, key));
|
|
1121
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1122
|
+
if (initialized) {
|
|
1123
|
+
fireMountedAndQueueUpdated(owner);
|
|
1124
|
+
}
|
|
1125
|
+
initialized = true;
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
function renderDynamicBlock(element, block, parent, namespace, owner) {
|
|
1129
|
+
let initialized = false;
|
|
1130
|
+
let hasTag = false;
|
|
1131
|
+
let currentTag;
|
|
1132
|
+
return effect(() => {
|
|
1133
|
+
const tag = readReactive2(element.props.component);
|
|
1134
|
+
if (hasTag && Object.is(currentTag, tag)) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
currentTag = tag;
|
|
1138
|
+
hasTag = true;
|
|
1139
|
+
clearChildren(block);
|
|
1140
|
+
const content = tag ? createDynamicElement(element, tag) : null;
|
|
1141
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1142
|
+
if (initialized) {
|
|
1143
|
+
fireMountedAndQueueUpdated(owner);
|
|
1144
|
+
}
|
|
1145
|
+
initialized = true;
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
function renderPortal(element, parent, anchor, namespace) {
|
|
1149
|
+
const placeholder = domOps.createComment("Sinwan-p");
|
|
1150
|
+
insertNode(parent, placeholder, anchor);
|
|
1151
|
+
const owner = getCurrentInstance();
|
|
1152
|
+
let disposeEffect = () => {};
|
|
1153
|
+
const portal = {
|
|
1154
|
+
type: "portal",
|
|
1155
|
+
anchor: placeholder,
|
|
1156
|
+
children: [],
|
|
1157
|
+
dispose: () => disposeEffect()
|
|
1158
|
+
};
|
|
1159
|
+
let initialized = false;
|
|
1160
|
+
disposeEffect = effect(() => {
|
|
1161
|
+
clearPortalChildren(portal);
|
|
1162
|
+
const target = resolvePortalTarget(element.props.mount);
|
|
1163
|
+
if (target) {
|
|
1164
|
+
portal.children = renderBlockContent(element.props.children ?? element.children, target, null, namespace, owner);
|
|
1165
|
+
}
|
|
1166
|
+
if (initialized) {
|
|
1167
|
+
fireMountedAndQueueUpdated(owner);
|
|
1168
|
+
}
|
|
1169
|
+
initialized = true;
|
|
1170
|
+
});
|
|
1171
|
+
return portal;
|
|
1172
|
+
}
|
|
839
1173
|
function resolveShowChildren(element, value) {
|
|
840
1174
|
const children = element.props.children ?? element.children;
|
|
841
1175
|
if (typeof children === "function") {
|
|
@@ -843,6 +1177,47 @@ function resolveShowChildren(element, value) {
|
|
|
843
1177
|
}
|
|
844
1178
|
return children;
|
|
845
1179
|
}
|
|
1180
|
+
function resolveSwitchContent(element) {
|
|
1181
|
+
const props = element.props;
|
|
1182
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1183
|
+
for (const child of children) {
|
|
1184
|
+
const match = getMatchElement(child);
|
|
1185
|
+
if (!match) {
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
const when = readReactive2(match.props.when);
|
|
1189
|
+
if (when) {
|
|
1190
|
+
return resolveMatchChildren(match, when);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return props.fallback;
|
|
1194
|
+
}
|
|
1195
|
+
function resolveMatchChildren(element, value) {
|
|
1196
|
+
const children = element.props.children ?? element.children;
|
|
1197
|
+
if (typeof children === "function") {
|
|
1198
|
+
return children(value);
|
|
1199
|
+
}
|
|
1200
|
+
return children;
|
|
1201
|
+
}
|
|
1202
|
+
function resolveKeyChildren(element, value) {
|
|
1203
|
+
const children = element.props.children ?? element.children;
|
|
1204
|
+
if (typeof children === "function") {
|
|
1205
|
+
return children(value);
|
|
1206
|
+
}
|
|
1207
|
+
return children;
|
|
1208
|
+
}
|
|
1209
|
+
function createDynamicElement(element, tag) {
|
|
1210
|
+
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
const { component, ...props } = element.props;
|
|
1214
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1215
|
+
return {
|
|
1216
|
+
tag,
|
|
1217
|
+
props,
|
|
1218
|
+
children
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
846
1221
|
function renderBlockContent(content, parent, anchor, namespace, owner) {
|
|
847
1222
|
if (content == null || typeof content === "boolean") {
|
|
848
1223
|
return [];
|
|
@@ -856,6 +1231,12 @@ function clearChildren(block) {
|
|
|
856
1231
|
}
|
|
857
1232
|
block.children = [];
|
|
858
1233
|
}
|
|
1234
|
+
function clearPortalChildren(portal) {
|
|
1235
|
+
for (const child of portal.children) {
|
|
1236
|
+
removeMountedNode(child);
|
|
1237
|
+
}
|
|
1238
|
+
portal.children = [];
|
|
1239
|
+
}
|
|
859
1240
|
function moveBeforeEnd(parent, mounted, endAnchor) {
|
|
860
1241
|
for (const node of getMountedDomNodes(mounted)) {
|
|
861
1242
|
domOps.insertBefore(parent, node, endAnchor);
|
|
@@ -870,8 +1251,42 @@ function fireMountedAndQueueUpdated(owner) {
|
|
|
870
1251
|
function withOptionalInstance(owner, fn) {
|
|
871
1252
|
return owner ? withInstance(owner, fn) : fn();
|
|
872
1253
|
}
|
|
873
|
-
function
|
|
874
|
-
return
|
|
1254
|
+
function readReactive2(value) {
|
|
1255
|
+
return resolve(value);
|
|
1256
|
+
}
|
|
1257
|
+
function normalizeContent(content) {
|
|
1258
|
+
if (content == null || typeof content === "boolean") {
|
|
1259
|
+
return [];
|
|
1260
|
+
}
|
|
1261
|
+
return Array.isArray(content) ? content : [content];
|
|
1262
|
+
}
|
|
1263
|
+
function isElementLike(value) {
|
|
1264
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
1265
|
+
}
|
|
1266
|
+
function getMatchElement(value) {
|
|
1267
|
+
if (!isElementLike(value)) {
|
|
1268
|
+
return null;
|
|
1269
|
+
}
|
|
1270
|
+
if (isMatchElement(value)) {
|
|
1271
|
+
return value;
|
|
1272
|
+
}
|
|
1273
|
+
return value.tag === Match ? Match(value.props) : null;
|
|
1274
|
+
}
|
|
1275
|
+
function resolvePortalTarget(value) {
|
|
1276
|
+
const target = readReactive2(value);
|
|
1277
|
+
if (target == null) {
|
|
1278
|
+
return typeof document === "undefined" ? null : document.body;
|
|
1279
|
+
}
|
|
1280
|
+
if (typeof target === "string") {
|
|
1281
|
+
return document.querySelector(target);
|
|
1282
|
+
}
|
|
1283
|
+
if (typeof target === "function") {
|
|
1284
|
+
return target();
|
|
1285
|
+
}
|
|
1286
|
+
if (typeof target === "object" && "nodeType" in target) {
|
|
1287
|
+
return target;
|
|
1288
|
+
}
|
|
1289
|
+
return null;
|
|
875
1290
|
}
|
|
876
1291
|
function insertNode(parent, child, anchor) {
|
|
877
1292
|
if (anchor) {
|
|
@@ -905,10 +1320,13 @@ function renderElementToDOM(element, parent, anchor = null, namespace = null) {
|
|
|
905
1320
|
if (tag === "" || tag === Fragment) {
|
|
906
1321
|
return renderFragmentToDOM(children, parent, anchor, namespace);
|
|
907
1322
|
}
|
|
908
|
-
if (tag === Show || tag === For) {
|
|
1323
|
+
if (tag === Show || tag === For || tag === Switch || tag === Index || tag === Key || tag === Dynamic || tag === Portal) {
|
|
909
1324
|
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
910
1325
|
}
|
|
911
|
-
if (
|
|
1326
|
+
if (tag === Visible) {
|
|
1327
|
+
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
1328
|
+
}
|
|
1329
|
+
if (isShowElement(element) || isForElement(element) || isSwitchElement(element) || isIndexElement(element) || isKeyElement(element) || isDynamicElement(element) || isPortalElement(element)) {
|
|
912
1330
|
return renderControlFlowToDOM(element, parent, anchor, namespace);
|
|
913
1331
|
}
|
|
914
1332
|
if (typeof tag === "function") {
|
|
@@ -1055,19 +1473,8 @@ function renderNodeToDOM(node, parent, anchor = null, namespace = null) {
|
|
|
1055
1473
|
insertNode2(parent, text2, anchor);
|
|
1056
1474
|
return { type: "text", node: text2 };
|
|
1057
1475
|
}
|
|
1058
|
-
if (
|
|
1059
|
-
|
|
1060
|
-
insertNode2(parent, text2, anchor);
|
|
1061
|
-
const owner = getCurrentInstance();
|
|
1062
|
-
let initialized = false;
|
|
1063
|
-
const dispose = effect(() => {
|
|
1064
|
-
domOps.setTextContent(text2, String(node.value));
|
|
1065
|
-
if (initialized) {
|
|
1066
|
-
queueUpdatedHooks(owner);
|
|
1067
|
-
}
|
|
1068
|
-
initialized = true;
|
|
1069
|
-
});
|
|
1070
|
-
return { type: "reactive-text", node: text2, dispose };
|
|
1476
|
+
if (isReactive(node)) {
|
|
1477
|
+
return renderReactiveNodeToDOM(node, parent, anchor, namespace);
|
|
1071
1478
|
}
|
|
1072
1479
|
if (Array.isArray(node)) {
|
|
1073
1480
|
return renderArrayToDOM(node, parent, anchor, namespace);
|
|
@@ -1104,6 +1511,37 @@ function renderChildrenToDOM(children, parent, namespace = null) {
|
|
|
1104
1511
|
}
|
|
1105
1512
|
return mounted;
|
|
1106
1513
|
}
|
|
1514
|
+
function renderReactiveNodeToDOM(reactive, parent, anchor, namespace) {
|
|
1515
|
+
const startAnchor = domOps.createComment("Sinwan-r");
|
|
1516
|
+
const endAnchor = domOps.createComment("/Sinwan-r");
|
|
1517
|
+
insertNode2(parent, startAnchor, anchor);
|
|
1518
|
+
insertNode2(parent, endAnchor, anchor);
|
|
1519
|
+
const owner = getCurrentInstance();
|
|
1520
|
+
let mountedContent = null;
|
|
1521
|
+
let initialized = false;
|
|
1522
|
+
const block = {
|
|
1523
|
+
type: "reactive-block",
|
|
1524
|
+
startAnchor,
|
|
1525
|
+
endAnchor,
|
|
1526
|
+
children: [],
|
|
1527
|
+
dispose: () => {}
|
|
1528
|
+
};
|
|
1529
|
+
block.dispose = effect(() => {
|
|
1530
|
+
if (mountedContent) {
|
|
1531
|
+
removeMountedNode(mountedContent);
|
|
1532
|
+
}
|
|
1533
|
+
const value = resolve(reactive);
|
|
1534
|
+
mountedContent = renderNodeToDOM(value, parent, endAnchor, namespace);
|
|
1535
|
+
block.children = [mountedContent];
|
|
1536
|
+
if (initialized) {
|
|
1537
|
+
if (owner)
|
|
1538
|
+
fireMountedHooks(owner);
|
|
1539
|
+
queueUpdatedHooks(owner);
|
|
1540
|
+
}
|
|
1541
|
+
initialized = true;
|
|
1542
|
+
});
|
|
1543
|
+
return block;
|
|
1544
|
+
}
|
|
1107
1545
|
function insertNode2(parent, child, anchor) {
|
|
1108
1546
|
if (anchor) {
|
|
1109
1547
|
domOps.insertBefore(parent, child, anchor);
|
|
@@ -1171,5 +1609,5 @@ function render(node, container) {
|
|
|
1171
1609
|
};
|
|
1172
1610
|
}
|
|
1173
1611
|
|
|
1174
|
-
//# debugId=
|
|
1612
|
+
//# debugId=2D5A4F08E5DE065564756E2164756E21
|
|
1175
1613
|
//# sourceMappingURL=index.development.js.map
|