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
|
@@ -511,9 +511,10 @@ function applyAttributes(el, props) {
|
|
|
511
511
|
if (SKIP_PROPS.has(key) || isEventProp(key))
|
|
512
512
|
continue;
|
|
513
513
|
if (isSignal(value) || isComputed(value)) {
|
|
514
|
+
const state = { previousStyleProps: new Set };
|
|
514
515
|
let initialized = false;
|
|
515
516
|
const dispose = effect(() => {
|
|
516
|
-
setSingleAttribute(el, key, value.value);
|
|
517
|
+
setSingleAttribute(el, key, value.value, state);
|
|
517
518
|
if (initialized) {
|
|
518
519
|
queueUpdatedHooks(owner);
|
|
519
520
|
}
|
|
@@ -526,10 +527,10 @@ function applyAttributes(el, props) {
|
|
|
526
527
|
}
|
|
527
528
|
return disposers;
|
|
528
529
|
}
|
|
529
|
-
function setSingleAttribute(el, key, value) {
|
|
530
|
-
const attrName =
|
|
530
|
+
function setSingleAttribute(el, key, value, state) {
|
|
531
|
+
const attrName = resolveAttributeName(key);
|
|
531
532
|
if (attrName === "style" && typeof value === "object" && value !== null) {
|
|
532
|
-
applyStyle(el, value);
|
|
533
|
+
applyStyle(el, value, state);
|
|
533
534
|
return;
|
|
534
535
|
}
|
|
535
536
|
if (attrName === "class" && typeof value === "object" && value !== null) {
|
|
@@ -538,6 +539,9 @@ function setSingleAttribute(el, key, value) {
|
|
|
538
539
|
}
|
|
539
540
|
if (value == null || value === false) {
|
|
540
541
|
domOps.removeAttribute(el, attrName);
|
|
542
|
+
if (attrName === "style" && state) {
|
|
543
|
+
state.previousStyleProps.clear();
|
|
544
|
+
}
|
|
541
545
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
542
546
|
domOps.setProperty(el, attrName, attrName === "value" ? "" : false);
|
|
543
547
|
}
|
|
@@ -545,25 +549,59 @@ function setSingleAttribute(el, key, value) {
|
|
|
545
549
|
}
|
|
546
550
|
if (value === true) {
|
|
547
551
|
domOps.setAttribute(el, attrName, "");
|
|
552
|
+
if (attrName === "style" && state) {
|
|
553
|
+
state.previousStyleProps.clear();
|
|
554
|
+
}
|
|
548
555
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
549
556
|
domOps.setProperty(el, attrName, true);
|
|
550
557
|
}
|
|
551
558
|
return;
|
|
552
559
|
}
|
|
553
560
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
561
|
+
if (attrName === "style" && state) {
|
|
562
|
+
state.previousStyleProps.clear();
|
|
563
|
+
}
|
|
554
564
|
domOps.setProperty(el, attrName, value);
|
|
555
565
|
return;
|
|
556
566
|
}
|
|
567
|
+
if (attrName === "style" && state) {
|
|
568
|
+
state.previousStyleProps.clear();
|
|
569
|
+
}
|
|
557
570
|
domOps.setAttribute(el, attrName, String(value));
|
|
558
571
|
}
|
|
559
|
-
function
|
|
572
|
+
function resolveAttributeName(key) {
|
|
573
|
+
return PROP_ALIASES[key] ?? key;
|
|
574
|
+
}
|
|
575
|
+
function applyStyle(el, styles, state) {
|
|
576
|
+
const nextProps = new Set;
|
|
560
577
|
for (const [prop, val] of Object.entries(styles)) {
|
|
578
|
+
nextProps.add(prop);
|
|
579
|
+
if (val == null) {
|
|
580
|
+
removeStyleProperty(el, prop);
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
561
583
|
if (prop.includes("-")) {
|
|
562
|
-
el.style.setProperty(prop, val);
|
|
584
|
+
el.style.setProperty(prop, String(val));
|
|
563
585
|
} else {
|
|
564
586
|
el.style[prop] = val;
|
|
565
587
|
}
|
|
566
588
|
}
|
|
589
|
+
if (!state) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
for (const previousProp of state.previousStyleProps) {
|
|
593
|
+
if (!nextProps.has(previousProp)) {
|
|
594
|
+
removeStyleProperty(el, previousProp);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
state.previousStyleProps = nextProps;
|
|
598
|
+
}
|
|
599
|
+
function removeStyleProperty(el, prop) {
|
|
600
|
+
if (prop.includes("-")) {
|
|
601
|
+
el.style.removeProperty(prop);
|
|
602
|
+
} else {
|
|
603
|
+
el.style[prop] = "";
|
|
604
|
+
}
|
|
567
605
|
}
|
|
568
606
|
function applyClass(el, value) {
|
|
569
607
|
let classStr;
|
|
@@ -576,10 +614,28 @@ function applyClass(el, value) {
|
|
|
576
614
|
}
|
|
577
615
|
domOps.setAttribute(el, "class", classStr);
|
|
578
616
|
}
|
|
579
|
-
|
|
617
|
+
// src/reactivity/batch.ts
|
|
618
|
+
var batchDepth = 0;
|
|
619
|
+
function batch(fn) {
|
|
620
|
+
batchDepth++;
|
|
621
|
+
try {
|
|
622
|
+
fn();
|
|
623
|
+
} finally {
|
|
624
|
+
batchDepth--;
|
|
625
|
+
if (batchDepth === 0) {
|
|
626
|
+
flushSync();
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
580
630
|
// src/component/control-flow.ts
|
|
581
631
|
var SHOW_TYPE = Symbol.for("Sinwan.Show");
|
|
582
632
|
var FOR_TYPE = Symbol.for("Sinwan.For");
|
|
633
|
+
var SWITCH_TYPE = Symbol.for("Sinwan.Switch");
|
|
634
|
+
var MATCH_TYPE = Symbol.for("Sinwan.Match");
|
|
635
|
+
var INDEX_TYPE = Symbol.for("Sinwan.Index");
|
|
636
|
+
var KEY_TYPE = Symbol.for("Sinwan.Key");
|
|
637
|
+
var DYNAMIC_TYPE = Symbol.for("Sinwan.Dynamic");
|
|
638
|
+
var PORTAL_TYPE = Symbol.for("Sinwan.Portal");
|
|
583
639
|
function Show(props) {
|
|
584
640
|
return {
|
|
585
641
|
tag: SHOW_TYPE,
|
|
@@ -594,12 +650,114 @@ function For(props) {
|
|
|
594
650
|
children: []
|
|
595
651
|
};
|
|
596
652
|
}
|
|
653
|
+
function Switch(props) {
|
|
654
|
+
return {
|
|
655
|
+
tag: SWITCH_TYPE,
|
|
656
|
+
props,
|
|
657
|
+
children: []
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function Match(props) {
|
|
661
|
+
return {
|
|
662
|
+
tag: MATCH_TYPE,
|
|
663
|
+
props,
|
|
664
|
+
children: []
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function Index(props) {
|
|
668
|
+
return {
|
|
669
|
+
tag: INDEX_TYPE,
|
|
670
|
+
props,
|
|
671
|
+
children: []
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
function Key(props) {
|
|
675
|
+
return {
|
|
676
|
+
tag: KEY_TYPE,
|
|
677
|
+
props,
|
|
678
|
+
children: []
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
function Dynamic(props) {
|
|
682
|
+
return {
|
|
683
|
+
tag: DYNAMIC_TYPE,
|
|
684
|
+
props,
|
|
685
|
+
children: []
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
function Visible(props) {
|
|
689
|
+
const {
|
|
690
|
+
when,
|
|
691
|
+
as = "span",
|
|
692
|
+
style,
|
|
693
|
+
children,
|
|
694
|
+
...rest
|
|
695
|
+
} = props;
|
|
696
|
+
const visibleStyle = computed(() => {
|
|
697
|
+
const base = readReactive(style);
|
|
698
|
+
const visible = Boolean(readReactive(when));
|
|
699
|
+
if (typeof base === "string") {
|
|
700
|
+
return visible ? base : appendHiddenDisplay(base);
|
|
701
|
+
}
|
|
702
|
+
const styleObject = base && typeof base === "object" ? { ...base } : {};
|
|
703
|
+
styleObject.display = visible ? styleObject.display : "none";
|
|
704
|
+
return styleObject;
|
|
705
|
+
});
|
|
706
|
+
return {
|
|
707
|
+
tag: as,
|
|
708
|
+
props: {
|
|
709
|
+
...rest,
|
|
710
|
+
style: visibleStyle,
|
|
711
|
+
children
|
|
712
|
+
},
|
|
713
|
+
children: normalizeChildren2(children)
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
function Portal(props) {
|
|
717
|
+
return {
|
|
718
|
+
tag: PORTAL_TYPE,
|
|
719
|
+
props,
|
|
720
|
+
children: []
|
|
721
|
+
};
|
|
722
|
+
}
|
|
597
723
|
function isShowElement(element) {
|
|
598
724
|
return element.tag === SHOW_TYPE;
|
|
599
725
|
}
|
|
600
726
|
function isForElement(element) {
|
|
601
727
|
return element.tag === FOR_TYPE;
|
|
602
728
|
}
|
|
729
|
+
function isSwitchElement(element) {
|
|
730
|
+
return element.tag === SWITCH_TYPE;
|
|
731
|
+
}
|
|
732
|
+
function isMatchElement(element) {
|
|
733
|
+
return element.tag === MATCH_TYPE;
|
|
734
|
+
}
|
|
735
|
+
function isIndexElement(element) {
|
|
736
|
+
return element.tag === INDEX_TYPE;
|
|
737
|
+
}
|
|
738
|
+
function isKeyElement(element) {
|
|
739
|
+
return element.tag === KEY_TYPE;
|
|
740
|
+
}
|
|
741
|
+
function isDynamicElement(element) {
|
|
742
|
+
return element.tag === DYNAMIC_TYPE;
|
|
743
|
+
}
|
|
744
|
+
function isPortalElement(element) {
|
|
745
|
+
return element.tag === PORTAL_TYPE;
|
|
746
|
+
}
|
|
747
|
+
function normalizeChildren2(children) {
|
|
748
|
+
if (children == null || typeof children === "boolean") {
|
|
749
|
+
return [];
|
|
750
|
+
}
|
|
751
|
+
return Array.isArray(children) ? children : [children];
|
|
752
|
+
}
|
|
753
|
+
function readReactive(value) {
|
|
754
|
+
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
755
|
+
}
|
|
756
|
+
function appendHiddenDisplay(style) {
|
|
757
|
+
const trimmed = style.trim();
|
|
758
|
+
const separator = trimmed.length > 0 && !trimmed.endsWith(";") ? ";" : "";
|
|
759
|
+
return `${trimmed}${separator}display:none`;
|
|
760
|
+
}
|
|
603
761
|
|
|
604
762
|
// src/renderer/unmount.ts
|
|
605
763
|
function getMountedDomNodes(node) {
|
|
@@ -622,6 +780,8 @@ function getMountedDomNodes(node) {
|
|
|
622
780
|
];
|
|
623
781
|
case "component":
|
|
624
782
|
return node.children.flatMap((child) => getMountedDomNodes(child));
|
|
783
|
+
case "portal":
|
|
784
|
+
return [node.anchor];
|
|
625
785
|
}
|
|
626
786
|
}
|
|
627
787
|
function unmountNode(node) {
|
|
@@ -666,6 +826,13 @@ function unmountNode(node) {
|
|
|
666
826
|
unmountNode(child);
|
|
667
827
|
}
|
|
668
828
|
break;
|
|
829
|
+
case "portal":
|
|
830
|
+
node.dispose();
|
|
831
|
+
for (const child of node.children) {
|
|
832
|
+
removeMountedNode(child);
|
|
833
|
+
}
|
|
834
|
+
node.children = [];
|
|
835
|
+
break;
|
|
669
836
|
}
|
|
670
837
|
}
|
|
671
838
|
function removeMountedNode(node) {
|
|
@@ -680,6 +847,9 @@ function removeMountedNode(node) {
|
|
|
680
847
|
|
|
681
848
|
// src/renderer/render-control-flow.ts
|
|
682
849
|
function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
850
|
+
if (isPortalElement(element)) {
|
|
851
|
+
return renderPortal(element, parent, anchor, namespace);
|
|
852
|
+
}
|
|
683
853
|
const startAnchor = domOps.createComment("Sinwan-b");
|
|
684
854
|
const endAnchor = domOps.createComment("/Sinwan-b");
|
|
685
855
|
insertNode(parent, startAnchor, anchor);
|
|
@@ -697,6 +867,14 @@ function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
|
697
867
|
disposeEffect = renderShowBlock(element, block, parent, namespace, owner);
|
|
698
868
|
} else if (isForElement(element)) {
|
|
699
869
|
disposeEffect = renderForBlock(element, block, parent, namespace, owner);
|
|
870
|
+
} else if (isSwitchElement(element)) {
|
|
871
|
+
disposeEffect = renderSwitchBlock(element, block, parent, namespace, owner);
|
|
872
|
+
} else if (isIndexElement(element)) {
|
|
873
|
+
disposeEffect = renderIndexBlock(element, block, parent, namespace, owner);
|
|
874
|
+
} else if (isKeyElement(element)) {
|
|
875
|
+
disposeEffect = renderKeyBlock(element, block, parent, namespace, owner);
|
|
876
|
+
} else if (isDynamicElement(element)) {
|
|
877
|
+
disposeEffect = renderDynamicBlock(element, block, parent, namespace, owner);
|
|
700
878
|
}
|
|
701
879
|
return block;
|
|
702
880
|
}
|
|
@@ -704,7 +882,7 @@ function renderShowBlock(element, block, parent, namespace, owner) {
|
|
|
704
882
|
let initialized = false;
|
|
705
883
|
return effect(() => {
|
|
706
884
|
clearChildren(block);
|
|
707
|
-
const when =
|
|
885
|
+
const when = readReactive2(element.props.when);
|
|
708
886
|
const content = withOptionalInstance(owner, () => when ? resolveShowChildren(element, when) : element.props.fallback);
|
|
709
887
|
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
710
888
|
if (initialized) {
|
|
@@ -718,7 +896,7 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
718
896
|
let records = [];
|
|
719
897
|
return effect(() => {
|
|
720
898
|
const props = element.props;
|
|
721
|
-
const items =
|
|
899
|
+
const items = readReactive2(props.each);
|
|
722
900
|
const list = Array.isArray(items) ? items : [];
|
|
723
901
|
const renderChild = props.children;
|
|
724
902
|
if (typeof renderChild !== "function") {
|
|
@@ -730,6 +908,19 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
730
908
|
initialized = true;
|
|
731
909
|
return;
|
|
732
910
|
}
|
|
911
|
+
if (list.length === 0) {
|
|
912
|
+
clearChildren(block);
|
|
913
|
+
records = [];
|
|
914
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
915
|
+
if (initialized) {
|
|
916
|
+
fireMountedAndQueueUpdated(owner);
|
|
917
|
+
}
|
|
918
|
+
initialized = true;
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
922
|
+
clearChildren(block);
|
|
923
|
+
}
|
|
733
924
|
const oldByKey = new Map;
|
|
734
925
|
for (const record of records) {
|
|
735
926
|
oldByKey.set(record.key, record);
|
|
@@ -769,6 +960,137 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
769
960
|
initialized = true;
|
|
770
961
|
});
|
|
771
962
|
}
|
|
963
|
+
function renderSwitchBlock(element, block, parent, namespace, owner) {
|
|
964
|
+
let initialized = false;
|
|
965
|
+
return effect(() => {
|
|
966
|
+
clearChildren(block);
|
|
967
|
+
const content = withOptionalInstance(owner, () => resolveSwitchContent(element));
|
|
968
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
969
|
+
if (initialized) {
|
|
970
|
+
fireMountedAndQueueUpdated(owner);
|
|
971
|
+
}
|
|
972
|
+
initialized = true;
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
function renderIndexBlock(element, block, parent, namespace, owner) {
|
|
976
|
+
let initialized = false;
|
|
977
|
+
let records = [];
|
|
978
|
+
return effect(() => {
|
|
979
|
+
const props = element.props;
|
|
980
|
+
const items = readReactive2(props.each);
|
|
981
|
+
const list = Array.isArray(items) ? items : [];
|
|
982
|
+
const renderChild = props.children;
|
|
983
|
+
if (typeof renderChild !== "function") {
|
|
984
|
+
clearChildren(block);
|
|
985
|
+
records = [];
|
|
986
|
+
if (initialized) {
|
|
987
|
+
queueUpdatedHooks(owner);
|
|
988
|
+
}
|
|
989
|
+
initialized = true;
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (list.length === 0) {
|
|
993
|
+
clearChildren(block);
|
|
994
|
+
records = [];
|
|
995
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
996
|
+
if (initialized) {
|
|
997
|
+
fireMountedAndQueueUpdated(owner);
|
|
998
|
+
}
|
|
999
|
+
initialized = true;
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
1003
|
+
clearChildren(block);
|
|
1004
|
+
}
|
|
1005
|
+
for (let index = 0;index < list.length; index++) {
|
|
1006
|
+
const existing = records[index];
|
|
1007
|
+
if (existing) {
|
|
1008
|
+
existing.item.value = list[index];
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
const itemSignal = signal(list[index]);
|
|
1012
|
+
const record = {
|
|
1013
|
+
item: itemSignal,
|
|
1014
|
+
mounted: withOptionalInstance(owner, () => renderNodeToDOM(renderChild(() => itemSignal.value, index), parent, block.endAnchor, namespace))
|
|
1015
|
+
};
|
|
1016
|
+
records.push(record);
|
|
1017
|
+
}
|
|
1018
|
+
while (records.length > list.length) {
|
|
1019
|
+
const removed = records.pop();
|
|
1020
|
+
removeMountedNode(removed.mounted);
|
|
1021
|
+
}
|
|
1022
|
+
block.children = records.map((record) => record.mounted);
|
|
1023
|
+
if (initialized) {
|
|
1024
|
+
fireMountedAndQueueUpdated(owner);
|
|
1025
|
+
}
|
|
1026
|
+
initialized = true;
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
function renderKeyBlock(element, block, parent, namespace, owner) {
|
|
1030
|
+
let initialized = false;
|
|
1031
|
+
let hasKey = false;
|
|
1032
|
+
let currentKey;
|
|
1033
|
+
return effect(() => {
|
|
1034
|
+
const key = readReactive2(element.props.when);
|
|
1035
|
+
if (hasKey && Object.is(currentKey, key)) {
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
currentKey = key;
|
|
1039
|
+
hasKey = true;
|
|
1040
|
+
clearChildren(block);
|
|
1041
|
+
const content = withOptionalInstance(owner, () => resolveKeyChildren(element, key));
|
|
1042
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1043
|
+
if (initialized) {
|
|
1044
|
+
fireMountedAndQueueUpdated(owner);
|
|
1045
|
+
}
|
|
1046
|
+
initialized = true;
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function renderDynamicBlock(element, block, parent, namespace, owner) {
|
|
1050
|
+
let initialized = false;
|
|
1051
|
+
let hasTag = false;
|
|
1052
|
+
let currentTag;
|
|
1053
|
+
return effect(() => {
|
|
1054
|
+
const tag = readReactive2(element.props.component);
|
|
1055
|
+
if (hasTag && Object.is(currentTag, tag)) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
currentTag = tag;
|
|
1059
|
+
hasTag = true;
|
|
1060
|
+
clearChildren(block);
|
|
1061
|
+
const content = tag ? createDynamicElement(element, tag) : null;
|
|
1062
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1063
|
+
if (initialized) {
|
|
1064
|
+
fireMountedAndQueueUpdated(owner);
|
|
1065
|
+
}
|
|
1066
|
+
initialized = true;
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
function renderPortal(element, parent, anchor, namespace) {
|
|
1070
|
+
const placeholder = domOps.createComment("Sinwan-p");
|
|
1071
|
+
insertNode(parent, placeholder, anchor);
|
|
1072
|
+
const owner = getCurrentInstance();
|
|
1073
|
+
let disposeEffect = () => {};
|
|
1074
|
+
const portal = {
|
|
1075
|
+
type: "portal",
|
|
1076
|
+
anchor: placeholder,
|
|
1077
|
+
children: [],
|
|
1078
|
+
dispose: () => disposeEffect()
|
|
1079
|
+
};
|
|
1080
|
+
let initialized = false;
|
|
1081
|
+
disposeEffect = effect(() => {
|
|
1082
|
+
clearPortalChildren(portal);
|
|
1083
|
+
const target = resolvePortalTarget(element.props.mount);
|
|
1084
|
+
if (target) {
|
|
1085
|
+
portal.children = renderBlockContent(element.props.children ?? element.children, target, null, namespace, owner);
|
|
1086
|
+
}
|
|
1087
|
+
if (initialized) {
|
|
1088
|
+
fireMountedAndQueueUpdated(owner);
|
|
1089
|
+
}
|
|
1090
|
+
initialized = true;
|
|
1091
|
+
});
|
|
1092
|
+
return portal;
|
|
1093
|
+
}
|
|
772
1094
|
function resolveShowChildren(element, value) {
|
|
773
1095
|
const children = element.props.children ?? element.children;
|
|
774
1096
|
if (typeof children === "function") {
|
|
@@ -776,6 +1098,47 @@ function resolveShowChildren(element, value) {
|
|
|
776
1098
|
}
|
|
777
1099
|
return children;
|
|
778
1100
|
}
|
|
1101
|
+
function resolveSwitchContent(element) {
|
|
1102
|
+
const props = element.props;
|
|
1103
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1104
|
+
for (const child of children) {
|
|
1105
|
+
const match = getMatchElement(child);
|
|
1106
|
+
if (!match) {
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
const when = readReactive2(match.props.when);
|
|
1110
|
+
if (when) {
|
|
1111
|
+
return resolveMatchChildren(match, when);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
return props.fallback;
|
|
1115
|
+
}
|
|
1116
|
+
function resolveMatchChildren(element, value) {
|
|
1117
|
+
const children = element.props.children ?? element.children;
|
|
1118
|
+
if (typeof children === "function") {
|
|
1119
|
+
return children(value);
|
|
1120
|
+
}
|
|
1121
|
+
return children;
|
|
1122
|
+
}
|
|
1123
|
+
function resolveKeyChildren(element, value) {
|
|
1124
|
+
const children = element.props.children ?? element.children;
|
|
1125
|
+
if (typeof children === "function") {
|
|
1126
|
+
return children(value);
|
|
1127
|
+
}
|
|
1128
|
+
return children;
|
|
1129
|
+
}
|
|
1130
|
+
function createDynamicElement(element, tag) {
|
|
1131
|
+
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
1132
|
+
return null;
|
|
1133
|
+
}
|
|
1134
|
+
const { component, ...props } = element.props;
|
|
1135
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1136
|
+
return {
|
|
1137
|
+
tag,
|
|
1138
|
+
props,
|
|
1139
|
+
children
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
779
1142
|
function renderBlockContent(content, parent, anchor, namespace, owner) {
|
|
780
1143
|
if (content == null || typeof content === "boolean") {
|
|
781
1144
|
return [];
|
|
@@ -789,6 +1152,12 @@ function clearChildren(block) {
|
|
|
789
1152
|
}
|
|
790
1153
|
block.children = [];
|
|
791
1154
|
}
|
|
1155
|
+
function clearPortalChildren(portal) {
|
|
1156
|
+
for (const child of portal.children) {
|
|
1157
|
+
removeMountedNode(child);
|
|
1158
|
+
}
|
|
1159
|
+
portal.children = [];
|
|
1160
|
+
}
|
|
792
1161
|
function moveBeforeEnd(parent, mounted, endAnchor) {
|
|
793
1162
|
for (const node of getMountedDomNodes(mounted)) {
|
|
794
1163
|
domOps.insertBefore(parent, node, endAnchor);
|
|
@@ -803,9 +1172,43 @@ function fireMountedAndQueueUpdated(owner) {
|
|
|
803
1172
|
function withOptionalInstance(owner, fn) {
|
|
804
1173
|
return owner ? withInstance(owner, fn) : fn();
|
|
805
1174
|
}
|
|
806
|
-
function
|
|
1175
|
+
function readReactive2(value) {
|
|
807
1176
|
return isSignal(value) || isComputed(value) ? value.value : value;
|
|
808
1177
|
}
|
|
1178
|
+
function normalizeContent(content) {
|
|
1179
|
+
if (content == null || typeof content === "boolean") {
|
|
1180
|
+
return [];
|
|
1181
|
+
}
|
|
1182
|
+
return Array.isArray(content) ? content : [content];
|
|
1183
|
+
}
|
|
1184
|
+
function isElementLike(value) {
|
|
1185
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
1186
|
+
}
|
|
1187
|
+
function getMatchElement(value) {
|
|
1188
|
+
if (!isElementLike(value)) {
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
if (isMatchElement(value)) {
|
|
1192
|
+
return value;
|
|
1193
|
+
}
|
|
1194
|
+
return value.tag === Match ? Match(value.props) : null;
|
|
1195
|
+
}
|
|
1196
|
+
function resolvePortalTarget(value) {
|
|
1197
|
+
const target = readReactive2(value);
|
|
1198
|
+
if (target == null) {
|
|
1199
|
+
return typeof document === "undefined" ? null : document.body;
|
|
1200
|
+
}
|
|
1201
|
+
if (typeof target === "string") {
|
|
1202
|
+
return document.querySelector(target);
|
|
1203
|
+
}
|
|
1204
|
+
if (typeof target === "function") {
|
|
1205
|
+
return target();
|
|
1206
|
+
}
|
|
1207
|
+
if (typeof target === "object" && "nodeType" in target) {
|
|
1208
|
+
return target;
|
|
1209
|
+
}
|
|
1210
|
+
return null;
|
|
1211
|
+
}
|
|
809
1212
|
function insertNode(parent, child, anchor) {
|
|
810
1213
|
if (anchor) {
|
|
811
1214
|
domOps.insertBefore(parent, child, anchor);
|
|
@@ -838,10 +1241,13 @@ function renderElementToDOM(element, parent, anchor = null, namespace = null) {
|
|
|
838
1241
|
if (tag === "" || tag === Fragment) {
|
|
839
1242
|
return renderFragmentToDOM(children, parent, anchor, namespace);
|
|
840
1243
|
}
|
|
841
|
-
if (tag === Show || tag === For) {
|
|
1244
|
+
if (tag === Show || tag === For || tag === Switch || tag === Index || tag === Key || tag === Dynamic || tag === Portal) {
|
|
1245
|
+
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
1246
|
+
}
|
|
1247
|
+
if (tag === Visible) {
|
|
842
1248
|
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
843
1249
|
}
|
|
844
|
-
if (isShowElement(element) || isForElement(element)) {
|
|
1250
|
+
if (isShowElement(element) || isForElement(element) || isSwitchElement(element) || isIndexElement(element) || isKeyElement(element) || isDynamicElement(element) || isPortalElement(element)) {
|
|
845
1251
|
return renderControlFlowToDOM(element, parent, anchor, namespace);
|
|
846
1252
|
}
|
|
847
1253
|
if (typeof tag === "function") {
|
|
@@ -1120,5 +1526,5 @@ export {
|
|
|
1120
1526
|
applyAttributes
|
|
1121
1527
|
};
|
|
1122
1528
|
|
|
1123
|
-
//# debugId=
|
|
1529
|
+
//# debugId=5F0DDB77CC3157EE64756E2164756E21
|
|
1124
1530
|
//# sourceMappingURL=index.development.js.map
|