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
|
@@ -316,7 +316,6 @@ function signal(initial) {
|
|
|
316
316
|
function isSignal(value) {
|
|
317
317
|
return value != null && typeof value === "object" && SIGNAL_BRAND in value;
|
|
318
318
|
}
|
|
319
|
-
|
|
320
319
|
// src/reactivity/computed.ts
|
|
321
320
|
var COMPUTED_BRAND = Symbol("Sinwan:computed");
|
|
322
321
|
|
|
@@ -368,7 +367,32 @@ function computed(getter) {
|
|
|
368
367
|
function isComputed(value) {
|
|
369
368
|
return value != null && typeof value === "object" && COMPUTED_BRAND in value;
|
|
370
369
|
}
|
|
371
|
-
|
|
370
|
+
// src/reactivity/batch.ts
|
|
371
|
+
var batchDepth = 0;
|
|
372
|
+
function batch(fn) {
|
|
373
|
+
batchDepth++;
|
|
374
|
+
try {
|
|
375
|
+
fn();
|
|
376
|
+
} finally {
|
|
377
|
+
batchDepth--;
|
|
378
|
+
if (batchDepth === 0) {
|
|
379
|
+
flushSync();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// src/reactivity/normalization.ts
|
|
384
|
+
function isReactive(value) {
|
|
385
|
+
return isSignal(value) || isComputed(value) || typeof value === "function";
|
|
386
|
+
}
|
|
387
|
+
function resolve(value) {
|
|
388
|
+
if (isSignal(value) || isComputed(value)) {
|
|
389
|
+
return value.value;
|
|
390
|
+
}
|
|
391
|
+
if (typeof value === "function") {
|
|
392
|
+
return value();
|
|
393
|
+
}
|
|
394
|
+
return value;
|
|
395
|
+
}
|
|
372
396
|
// src/renderer/events.ts
|
|
373
397
|
function isEventProp(key) {
|
|
374
398
|
return key.length > 2 && key[0] === "o" && key[1] === "n" && key[2] >= "A" && key[2] <= "Z";
|
|
@@ -510,10 +534,11 @@ function applyAttributes(el, props) {
|
|
|
510
534
|
for (const [key, value] of Object.entries(props)) {
|
|
511
535
|
if (SKIP_PROPS.has(key) || isEventProp(key))
|
|
512
536
|
continue;
|
|
513
|
-
if (
|
|
537
|
+
if (isReactive(value)) {
|
|
538
|
+
const state = { previousStyleProps: new Set };
|
|
514
539
|
let initialized = false;
|
|
515
540
|
const dispose = effect(() => {
|
|
516
|
-
setSingleAttribute(el, key, value
|
|
541
|
+
setSingleAttribute(el, key, resolve(value), state);
|
|
517
542
|
if (initialized) {
|
|
518
543
|
queueUpdatedHooks(owner);
|
|
519
544
|
}
|
|
@@ -526,10 +551,10 @@ function applyAttributes(el, props) {
|
|
|
526
551
|
}
|
|
527
552
|
return disposers;
|
|
528
553
|
}
|
|
529
|
-
function setSingleAttribute(el, key, value) {
|
|
530
|
-
const attrName =
|
|
554
|
+
function setSingleAttribute(el, key, value, state) {
|
|
555
|
+
const attrName = resolveAttributeName(key);
|
|
531
556
|
if (attrName === "style" && typeof value === "object" && value !== null) {
|
|
532
|
-
applyStyle(el, value);
|
|
557
|
+
applyStyle(el, value, state);
|
|
533
558
|
return;
|
|
534
559
|
}
|
|
535
560
|
if (attrName === "class" && typeof value === "object" && value !== null) {
|
|
@@ -538,6 +563,9 @@ function setSingleAttribute(el, key, value) {
|
|
|
538
563
|
}
|
|
539
564
|
if (value == null || value === false) {
|
|
540
565
|
domOps.removeAttribute(el, attrName);
|
|
566
|
+
if (attrName === "style" && state) {
|
|
567
|
+
state.previousStyleProps.clear();
|
|
568
|
+
}
|
|
541
569
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
542
570
|
domOps.setProperty(el, attrName, attrName === "value" ? "" : false);
|
|
543
571
|
}
|
|
@@ -545,25 +573,59 @@ function setSingleAttribute(el, key, value) {
|
|
|
545
573
|
}
|
|
546
574
|
if (value === true) {
|
|
547
575
|
domOps.setAttribute(el, attrName, "");
|
|
576
|
+
if (attrName === "style" && state) {
|
|
577
|
+
state.previousStyleProps.clear();
|
|
578
|
+
}
|
|
548
579
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
549
580
|
domOps.setProperty(el, attrName, true);
|
|
550
581
|
}
|
|
551
582
|
return;
|
|
552
583
|
}
|
|
553
584
|
if (DOM_PROPERTIES.has(attrName)) {
|
|
585
|
+
if (attrName === "style" && state) {
|
|
586
|
+
state.previousStyleProps.clear();
|
|
587
|
+
}
|
|
554
588
|
domOps.setProperty(el, attrName, value);
|
|
555
589
|
return;
|
|
556
590
|
}
|
|
591
|
+
if (attrName === "style" && state) {
|
|
592
|
+
state.previousStyleProps.clear();
|
|
593
|
+
}
|
|
557
594
|
domOps.setAttribute(el, attrName, String(value));
|
|
558
595
|
}
|
|
559
|
-
function
|
|
596
|
+
function resolveAttributeName(key) {
|
|
597
|
+
return PROP_ALIASES[key] ?? key;
|
|
598
|
+
}
|
|
599
|
+
function applyStyle(el, styles, state) {
|
|
600
|
+
const nextProps = new Set;
|
|
560
601
|
for (const [prop, val] of Object.entries(styles)) {
|
|
602
|
+
nextProps.add(prop);
|
|
603
|
+
if (val == null) {
|
|
604
|
+
removeStyleProperty(el, prop);
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
561
607
|
if (prop.includes("-")) {
|
|
562
|
-
el.style.setProperty(prop, val);
|
|
608
|
+
el.style.setProperty(prop, String(val));
|
|
563
609
|
} else {
|
|
564
610
|
el.style[prop] = val;
|
|
565
611
|
}
|
|
566
612
|
}
|
|
613
|
+
if (!state) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
for (const previousProp of state.previousStyleProps) {
|
|
617
|
+
if (!nextProps.has(previousProp)) {
|
|
618
|
+
removeStyleProperty(el, previousProp);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
state.previousStyleProps = nextProps;
|
|
622
|
+
}
|
|
623
|
+
function removeStyleProperty(el, prop) {
|
|
624
|
+
if (prop.includes("-")) {
|
|
625
|
+
el.style.removeProperty(prop);
|
|
626
|
+
} else {
|
|
627
|
+
el.style[prop] = "";
|
|
628
|
+
}
|
|
567
629
|
}
|
|
568
630
|
function applyClass(el, value) {
|
|
569
631
|
let classStr;
|
|
@@ -580,6 +642,12 @@ function applyClass(el, value) {
|
|
|
580
642
|
// src/component/control-flow.ts
|
|
581
643
|
var SHOW_TYPE = Symbol.for("Sinwan.Show");
|
|
582
644
|
var FOR_TYPE = Symbol.for("Sinwan.For");
|
|
645
|
+
var SWITCH_TYPE = Symbol.for("Sinwan.Switch");
|
|
646
|
+
var MATCH_TYPE = Symbol.for("Sinwan.Match");
|
|
647
|
+
var INDEX_TYPE = Symbol.for("Sinwan.Index");
|
|
648
|
+
var KEY_TYPE = Symbol.for("Sinwan.Key");
|
|
649
|
+
var DYNAMIC_TYPE = Symbol.for("Sinwan.Dynamic");
|
|
650
|
+
var PORTAL_TYPE = Symbol.for("Sinwan.Portal");
|
|
583
651
|
function Show(props) {
|
|
584
652
|
return {
|
|
585
653
|
tag: SHOW_TYPE,
|
|
@@ -594,12 +662,114 @@ function For(props) {
|
|
|
594
662
|
children: []
|
|
595
663
|
};
|
|
596
664
|
}
|
|
665
|
+
function Switch(props) {
|
|
666
|
+
return {
|
|
667
|
+
tag: SWITCH_TYPE,
|
|
668
|
+
props,
|
|
669
|
+
children: []
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function Match(props) {
|
|
673
|
+
return {
|
|
674
|
+
tag: MATCH_TYPE,
|
|
675
|
+
props,
|
|
676
|
+
children: []
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
function Index(props) {
|
|
680
|
+
return {
|
|
681
|
+
tag: INDEX_TYPE,
|
|
682
|
+
props,
|
|
683
|
+
children: []
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
function Key(props) {
|
|
687
|
+
return {
|
|
688
|
+
tag: KEY_TYPE,
|
|
689
|
+
props,
|
|
690
|
+
children: []
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function Dynamic(props) {
|
|
694
|
+
return {
|
|
695
|
+
tag: DYNAMIC_TYPE,
|
|
696
|
+
props,
|
|
697
|
+
children: []
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
function Visible(props) {
|
|
701
|
+
const {
|
|
702
|
+
when,
|
|
703
|
+
as = "span",
|
|
704
|
+
style,
|
|
705
|
+
children,
|
|
706
|
+
...rest
|
|
707
|
+
} = props;
|
|
708
|
+
const visibleStyle = computed(() => {
|
|
709
|
+
const base = readReactive(style);
|
|
710
|
+
const visible = Boolean(readReactive(when));
|
|
711
|
+
if (typeof base === "string") {
|
|
712
|
+
return visible ? base : appendHiddenDisplay(base);
|
|
713
|
+
}
|
|
714
|
+
const styleObject = base && typeof base === "object" ? { ...base } : {};
|
|
715
|
+
styleObject.display = visible ? styleObject.display : "none";
|
|
716
|
+
return styleObject;
|
|
717
|
+
});
|
|
718
|
+
return {
|
|
719
|
+
tag: as,
|
|
720
|
+
props: {
|
|
721
|
+
...rest,
|
|
722
|
+
style: visibleStyle,
|
|
723
|
+
children
|
|
724
|
+
},
|
|
725
|
+
children: normalizeChildren2(children)
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
function Portal(props) {
|
|
729
|
+
return {
|
|
730
|
+
tag: PORTAL_TYPE,
|
|
731
|
+
props,
|
|
732
|
+
children: []
|
|
733
|
+
};
|
|
734
|
+
}
|
|
597
735
|
function isShowElement(element) {
|
|
598
736
|
return element.tag === SHOW_TYPE;
|
|
599
737
|
}
|
|
600
738
|
function isForElement(element) {
|
|
601
739
|
return element.tag === FOR_TYPE;
|
|
602
740
|
}
|
|
741
|
+
function isSwitchElement(element) {
|
|
742
|
+
return element.tag === SWITCH_TYPE;
|
|
743
|
+
}
|
|
744
|
+
function isMatchElement(element) {
|
|
745
|
+
return element.tag === MATCH_TYPE;
|
|
746
|
+
}
|
|
747
|
+
function isIndexElement(element) {
|
|
748
|
+
return element.tag === INDEX_TYPE;
|
|
749
|
+
}
|
|
750
|
+
function isKeyElement(element) {
|
|
751
|
+
return element.tag === KEY_TYPE;
|
|
752
|
+
}
|
|
753
|
+
function isDynamicElement(element) {
|
|
754
|
+
return element.tag === DYNAMIC_TYPE;
|
|
755
|
+
}
|
|
756
|
+
function isPortalElement(element) {
|
|
757
|
+
return element.tag === PORTAL_TYPE;
|
|
758
|
+
}
|
|
759
|
+
function normalizeChildren2(children) {
|
|
760
|
+
if (children == null || typeof children === "boolean") {
|
|
761
|
+
return [];
|
|
762
|
+
}
|
|
763
|
+
return Array.isArray(children) ? children : [children];
|
|
764
|
+
}
|
|
765
|
+
function readReactive(value) {
|
|
766
|
+
return resolve(value);
|
|
767
|
+
}
|
|
768
|
+
function appendHiddenDisplay(style) {
|
|
769
|
+
const trimmed = style.trim();
|
|
770
|
+
const separator = trimmed.length > 0 && !trimmed.endsWith(";") ? ";" : "";
|
|
771
|
+
return `${trimmed}${separator}display:none`;
|
|
772
|
+
}
|
|
603
773
|
|
|
604
774
|
// src/renderer/unmount.ts
|
|
605
775
|
function getMountedDomNodes(node) {
|
|
@@ -622,6 +792,8 @@ function getMountedDomNodes(node) {
|
|
|
622
792
|
];
|
|
623
793
|
case "component":
|
|
624
794
|
return node.children.flatMap((child) => getMountedDomNodes(child));
|
|
795
|
+
case "portal":
|
|
796
|
+
return [node.anchor];
|
|
625
797
|
}
|
|
626
798
|
}
|
|
627
799
|
function unmountNode(node) {
|
|
@@ -666,6 +838,13 @@ function unmountNode(node) {
|
|
|
666
838
|
unmountNode(child);
|
|
667
839
|
}
|
|
668
840
|
break;
|
|
841
|
+
case "portal":
|
|
842
|
+
node.dispose();
|
|
843
|
+
for (const child of node.children) {
|
|
844
|
+
removeMountedNode(child);
|
|
845
|
+
}
|
|
846
|
+
node.children = [];
|
|
847
|
+
break;
|
|
669
848
|
}
|
|
670
849
|
}
|
|
671
850
|
function removeMountedNode(node) {
|
|
@@ -680,6 +859,9 @@ function removeMountedNode(node) {
|
|
|
680
859
|
|
|
681
860
|
// src/renderer/render-control-flow.ts
|
|
682
861
|
function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
862
|
+
if (isPortalElement(element)) {
|
|
863
|
+
return renderPortal(element, parent, anchor, namespace);
|
|
864
|
+
}
|
|
683
865
|
const startAnchor = domOps.createComment("Sinwan-b");
|
|
684
866
|
const endAnchor = domOps.createComment("/Sinwan-b");
|
|
685
867
|
insertNode(parent, startAnchor, anchor);
|
|
@@ -697,6 +879,14 @@ function renderControlFlowToDOM(element, parent, anchor, namespace) {
|
|
|
697
879
|
disposeEffect = renderShowBlock(element, block, parent, namespace, owner);
|
|
698
880
|
} else if (isForElement(element)) {
|
|
699
881
|
disposeEffect = renderForBlock(element, block, parent, namespace, owner);
|
|
882
|
+
} else if (isSwitchElement(element)) {
|
|
883
|
+
disposeEffect = renderSwitchBlock(element, block, parent, namespace, owner);
|
|
884
|
+
} else if (isIndexElement(element)) {
|
|
885
|
+
disposeEffect = renderIndexBlock(element, block, parent, namespace, owner);
|
|
886
|
+
} else if (isKeyElement(element)) {
|
|
887
|
+
disposeEffect = renderKeyBlock(element, block, parent, namespace, owner);
|
|
888
|
+
} else if (isDynamicElement(element)) {
|
|
889
|
+
disposeEffect = renderDynamicBlock(element, block, parent, namespace, owner);
|
|
700
890
|
}
|
|
701
891
|
return block;
|
|
702
892
|
}
|
|
@@ -704,7 +894,7 @@ function renderShowBlock(element, block, parent, namespace, owner) {
|
|
|
704
894
|
let initialized = false;
|
|
705
895
|
return effect(() => {
|
|
706
896
|
clearChildren(block);
|
|
707
|
-
const when =
|
|
897
|
+
const when = readReactive2(element.props.when);
|
|
708
898
|
const content = withOptionalInstance(owner, () => when ? resolveShowChildren(element, when) : element.props.fallback);
|
|
709
899
|
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
710
900
|
if (initialized) {
|
|
@@ -718,7 +908,7 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
718
908
|
let records = [];
|
|
719
909
|
return effect(() => {
|
|
720
910
|
const props = element.props;
|
|
721
|
-
const items =
|
|
911
|
+
const items = readReactive2(props.each);
|
|
722
912
|
const list = Array.isArray(items) ? items : [];
|
|
723
913
|
const renderChild = props.children;
|
|
724
914
|
if (typeof renderChild !== "function") {
|
|
@@ -730,6 +920,19 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
730
920
|
initialized = true;
|
|
731
921
|
return;
|
|
732
922
|
}
|
|
923
|
+
if (list.length === 0) {
|
|
924
|
+
clearChildren(block);
|
|
925
|
+
records = [];
|
|
926
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
927
|
+
if (initialized) {
|
|
928
|
+
fireMountedAndQueueUpdated(owner);
|
|
929
|
+
}
|
|
930
|
+
initialized = true;
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
934
|
+
clearChildren(block);
|
|
935
|
+
}
|
|
733
936
|
const oldByKey = new Map;
|
|
734
937
|
for (const record of records) {
|
|
735
938
|
oldByKey.set(record.key, record);
|
|
@@ -769,6 +972,137 @@ function renderForBlock(element, block, parent, namespace, owner) {
|
|
|
769
972
|
initialized = true;
|
|
770
973
|
});
|
|
771
974
|
}
|
|
975
|
+
function renderSwitchBlock(element, block, parent, namespace, owner) {
|
|
976
|
+
let initialized = false;
|
|
977
|
+
return effect(() => {
|
|
978
|
+
clearChildren(block);
|
|
979
|
+
const content = withOptionalInstance(owner, () => resolveSwitchContent(element));
|
|
980
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
981
|
+
if (initialized) {
|
|
982
|
+
fireMountedAndQueueUpdated(owner);
|
|
983
|
+
}
|
|
984
|
+
initialized = true;
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
function renderIndexBlock(element, block, parent, namespace, owner) {
|
|
988
|
+
let initialized = false;
|
|
989
|
+
let records = [];
|
|
990
|
+
return effect(() => {
|
|
991
|
+
const props = element.props;
|
|
992
|
+
const items = readReactive2(props.each);
|
|
993
|
+
const list = Array.isArray(items) ? items : [];
|
|
994
|
+
const renderChild = props.children;
|
|
995
|
+
if (typeof renderChild !== "function") {
|
|
996
|
+
clearChildren(block);
|
|
997
|
+
records = [];
|
|
998
|
+
if (initialized) {
|
|
999
|
+
queueUpdatedHooks(owner);
|
|
1000
|
+
}
|
|
1001
|
+
initialized = true;
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
if (list.length === 0) {
|
|
1005
|
+
clearChildren(block);
|
|
1006
|
+
records = [];
|
|
1007
|
+
block.children = renderBlockContent(props.fallback, parent, block.endAnchor, namespace, owner);
|
|
1008
|
+
if (initialized) {
|
|
1009
|
+
fireMountedAndQueueUpdated(owner);
|
|
1010
|
+
}
|
|
1011
|
+
initialized = true;
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (records.length === 0 && block.children.length > 0) {
|
|
1015
|
+
clearChildren(block);
|
|
1016
|
+
}
|
|
1017
|
+
for (let index = 0;index < list.length; index++) {
|
|
1018
|
+
const existing = records[index];
|
|
1019
|
+
if (existing) {
|
|
1020
|
+
existing.item.value = list[index];
|
|
1021
|
+
continue;
|
|
1022
|
+
}
|
|
1023
|
+
const itemSignal = signal(list[index]);
|
|
1024
|
+
const record = {
|
|
1025
|
+
item: itemSignal,
|
|
1026
|
+
mounted: withOptionalInstance(owner, () => renderNodeToDOM(renderChild(() => itemSignal.value, index), parent, block.endAnchor, namespace))
|
|
1027
|
+
};
|
|
1028
|
+
records.push(record);
|
|
1029
|
+
}
|
|
1030
|
+
while (records.length > list.length) {
|
|
1031
|
+
const removed = records.pop();
|
|
1032
|
+
removeMountedNode(removed.mounted);
|
|
1033
|
+
}
|
|
1034
|
+
block.children = records.map((record) => record.mounted);
|
|
1035
|
+
if (initialized) {
|
|
1036
|
+
fireMountedAndQueueUpdated(owner);
|
|
1037
|
+
}
|
|
1038
|
+
initialized = true;
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
function renderKeyBlock(element, block, parent, namespace, owner) {
|
|
1042
|
+
let initialized = false;
|
|
1043
|
+
let hasKey = false;
|
|
1044
|
+
let currentKey;
|
|
1045
|
+
return effect(() => {
|
|
1046
|
+
const key = readReactive2(element.props.when);
|
|
1047
|
+
if (hasKey && Object.is(currentKey, key)) {
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
currentKey = key;
|
|
1051
|
+
hasKey = true;
|
|
1052
|
+
clearChildren(block);
|
|
1053
|
+
const content = withOptionalInstance(owner, () => resolveKeyChildren(element, key));
|
|
1054
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1055
|
+
if (initialized) {
|
|
1056
|
+
fireMountedAndQueueUpdated(owner);
|
|
1057
|
+
}
|
|
1058
|
+
initialized = true;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function renderDynamicBlock(element, block, parent, namespace, owner) {
|
|
1062
|
+
let initialized = false;
|
|
1063
|
+
let hasTag = false;
|
|
1064
|
+
let currentTag;
|
|
1065
|
+
return effect(() => {
|
|
1066
|
+
const tag = readReactive2(element.props.component);
|
|
1067
|
+
if (hasTag && Object.is(currentTag, tag)) {
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
currentTag = tag;
|
|
1071
|
+
hasTag = true;
|
|
1072
|
+
clearChildren(block);
|
|
1073
|
+
const content = tag ? createDynamicElement(element, tag) : null;
|
|
1074
|
+
block.children = renderBlockContent(content, parent, block.endAnchor, namespace, owner);
|
|
1075
|
+
if (initialized) {
|
|
1076
|
+
fireMountedAndQueueUpdated(owner);
|
|
1077
|
+
}
|
|
1078
|
+
initialized = true;
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
function renderPortal(element, parent, anchor, namespace) {
|
|
1082
|
+
const placeholder = domOps.createComment("Sinwan-p");
|
|
1083
|
+
insertNode(parent, placeholder, anchor);
|
|
1084
|
+
const owner = getCurrentInstance();
|
|
1085
|
+
let disposeEffect = () => {};
|
|
1086
|
+
const portal = {
|
|
1087
|
+
type: "portal",
|
|
1088
|
+
anchor: placeholder,
|
|
1089
|
+
children: [],
|
|
1090
|
+
dispose: () => disposeEffect()
|
|
1091
|
+
};
|
|
1092
|
+
let initialized = false;
|
|
1093
|
+
disposeEffect = effect(() => {
|
|
1094
|
+
clearPortalChildren(portal);
|
|
1095
|
+
const target = resolvePortalTarget(element.props.mount);
|
|
1096
|
+
if (target) {
|
|
1097
|
+
portal.children = renderBlockContent(element.props.children ?? element.children, target, null, namespace, owner);
|
|
1098
|
+
}
|
|
1099
|
+
if (initialized) {
|
|
1100
|
+
fireMountedAndQueueUpdated(owner);
|
|
1101
|
+
}
|
|
1102
|
+
initialized = true;
|
|
1103
|
+
});
|
|
1104
|
+
return portal;
|
|
1105
|
+
}
|
|
772
1106
|
function resolveShowChildren(element, value) {
|
|
773
1107
|
const children = element.props.children ?? element.children;
|
|
774
1108
|
if (typeof children === "function") {
|
|
@@ -776,6 +1110,47 @@ function resolveShowChildren(element, value) {
|
|
|
776
1110
|
}
|
|
777
1111
|
return children;
|
|
778
1112
|
}
|
|
1113
|
+
function resolveSwitchContent(element) {
|
|
1114
|
+
const props = element.props;
|
|
1115
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1116
|
+
for (const child of children) {
|
|
1117
|
+
const match = getMatchElement(child);
|
|
1118
|
+
if (!match) {
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
const when = readReactive2(match.props.when);
|
|
1122
|
+
if (when) {
|
|
1123
|
+
return resolveMatchChildren(match, when);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return props.fallback;
|
|
1127
|
+
}
|
|
1128
|
+
function resolveMatchChildren(element, value) {
|
|
1129
|
+
const children = element.props.children ?? element.children;
|
|
1130
|
+
if (typeof children === "function") {
|
|
1131
|
+
return children(value);
|
|
1132
|
+
}
|
|
1133
|
+
return children;
|
|
1134
|
+
}
|
|
1135
|
+
function resolveKeyChildren(element, value) {
|
|
1136
|
+
const children = element.props.children ?? element.children;
|
|
1137
|
+
if (typeof children === "function") {
|
|
1138
|
+
return children(value);
|
|
1139
|
+
}
|
|
1140
|
+
return children;
|
|
1141
|
+
}
|
|
1142
|
+
function createDynamicElement(element, tag) {
|
|
1143
|
+
if (typeof tag !== "string" && typeof tag !== "function") {
|
|
1144
|
+
return null;
|
|
1145
|
+
}
|
|
1146
|
+
const { component, ...props } = element.props;
|
|
1147
|
+
const children = normalizeContent(props.children ?? element.children);
|
|
1148
|
+
return {
|
|
1149
|
+
tag,
|
|
1150
|
+
props,
|
|
1151
|
+
children
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
779
1154
|
function renderBlockContent(content, parent, anchor, namespace, owner) {
|
|
780
1155
|
if (content == null || typeof content === "boolean") {
|
|
781
1156
|
return [];
|
|
@@ -789,6 +1164,12 @@ function clearChildren(block) {
|
|
|
789
1164
|
}
|
|
790
1165
|
block.children = [];
|
|
791
1166
|
}
|
|
1167
|
+
function clearPortalChildren(portal) {
|
|
1168
|
+
for (const child of portal.children) {
|
|
1169
|
+
removeMountedNode(child);
|
|
1170
|
+
}
|
|
1171
|
+
portal.children = [];
|
|
1172
|
+
}
|
|
792
1173
|
function moveBeforeEnd(parent, mounted, endAnchor) {
|
|
793
1174
|
for (const node of getMountedDomNodes(mounted)) {
|
|
794
1175
|
domOps.insertBefore(parent, node, endAnchor);
|
|
@@ -803,8 +1184,42 @@ function fireMountedAndQueueUpdated(owner) {
|
|
|
803
1184
|
function withOptionalInstance(owner, fn) {
|
|
804
1185
|
return owner ? withInstance(owner, fn) : fn();
|
|
805
1186
|
}
|
|
806
|
-
function
|
|
807
|
-
return
|
|
1187
|
+
function readReactive2(value) {
|
|
1188
|
+
return resolve(value);
|
|
1189
|
+
}
|
|
1190
|
+
function normalizeContent(content) {
|
|
1191
|
+
if (content == null || typeof content === "boolean") {
|
|
1192
|
+
return [];
|
|
1193
|
+
}
|
|
1194
|
+
return Array.isArray(content) ? content : [content];
|
|
1195
|
+
}
|
|
1196
|
+
function isElementLike(value) {
|
|
1197
|
+
return value != null && typeof value === "object" && "tag" in value;
|
|
1198
|
+
}
|
|
1199
|
+
function getMatchElement(value) {
|
|
1200
|
+
if (!isElementLike(value)) {
|
|
1201
|
+
return null;
|
|
1202
|
+
}
|
|
1203
|
+
if (isMatchElement(value)) {
|
|
1204
|
+
return value;
|
|
1205
|
+
}
|
|
1206
|
+
return value.tag === Match ? Match(value.props) : null;
|
|
1207
|
+
}
|
|
1208
|
+
function resolvePortalTarget(value) {
|
|
1209
|
+
const target = readReactive2(value);
|
|
1210
|
+
if (target == null) {
|
|
1211
|
+
return typeof document === "undefined" ? null : document.body;
|
|
1212
|
+
}
|
|
1213
|
+
if (typeof target === "string") {
|
|
1214
|
+
return document.querySelector(target);
|
|
1215
|
+
}
|
|
1216
|
+
if (typeof target === "function") {
|
|
1217
|
+
return target();
|
|
1218
|
+
}
|
|
1219
|
+
if (typeof target === "object" && "nodeType" in target) {
|
|
1220
|
+
return target;
|
|
1221
|
+
}
|
|
1222
|
+
return null;
|
|
808
1223
|
}
|
|
809
1224
|
function insertNode(parent, child, anchor) {
|
|
810
1225
|
if (anchor) {
|
|
@@ -838,10 +1253,13 @@ function renderElementToDOM(element, parent, anchor = null, namespace = null) {
|
|
|
838
1253
|
if (tag === "" || tag === Fragment) {
|
|
839
1254
|
return renderFragmentToDOM(children, parent, anchor, namespace);
|
|
840
1255
|
}
|
|
841
|
-
if (tag === Show || tag === For) {
|
|
1256
|
+
if (tag === Show || tag === For || tag === Switch || tag === Index || tag === Key || tag === Dynamic || tag === Portal) {
|
|
842
1257
|
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
843
1258
|
}
|
|
844
|
-
if (
|
|
1259
|
+
if (tag === Visible) {
|
|
1260
|
+
return renderElementToDOM(tag(props), parent, anchor, namespace);
|
|
1261
|
+
}
|
|
1262
|
+
if (isShowElement(element) || isForElement(element) || isSwitchElement(element) || isIndexElement(element) || isKeyElement(element) || isDynamicElement(element) || isPortalElement(element)) {
|
|
845
1263
|
return renderControlFlowToDOM(element, parent, anchor, namespace);
|
|
846
1264
|
}
|
|
847
1265
|
if (typeof tag === "function") {
|
|
@@ -988,19 +1406,8 @@ function renderNodeToDOM(node, parent, anchor = null, namespace = null) {
|
|
|
988
1406
|
insertNode2(parent, text2, anchor);
|
|
989
1407
|
return { type: "text", node: text2 };
|
|
990
1408
|
}
|
|
991
|
-
if (
|
|
992
|
-
|
|
993
|
-
insertNode2(parent, text2, anchor);
|
|
994
|
-
const owner = getCurrentInstance();
|
|
995
|
-
let initialized = false;
|
|
996
|
-
const dispose = effect(() => {
|
|
997
|
-
domOps.setTextContent(text2, String(node.value));
|
|
998
|
-
if (initialized) {
|
|
999
|
-
queueUpdatedHooks(owner);
|
|
1000
|
-
}
|
|
1001
|
-
initialized = true;
|
|
1002
|
-
});
|
|
1003
|
-
return { type: "reactive-text", node: text2, dispose };
|
|
1409
|
+
if (isReactive(node)) {
|
|
1410
|
+
return renderReactiveNodeToDOM(node, parent, anchor, namespace);
|
|
1004
1411
|
}
|
|
1005
1412
|
if (Array.isArray(node)) {
|
|
1006
1413
|
return renderArrayToDOM(node, parent, anchor, namespace);
|
|
@@ -1037,6 +1444,37 @@ function renderChildrenToDOM(children, parent, namespace = null) {
|
|
|
1037
1444
|
}
|
|
1038
1445
|
return mounted;
|
|
1039
1446
|
}
|
|
1447
|
+
function renderReactiveNodeToDOM(reactive, parent, anchor, namespace) {
|
|
1448
|
+
const startAnchor = domOps.createComment("Sinwan-r");
|
|
1449
|
+
const endAnchor = domOps.createComment("/Sinwan-r");
|
|
1450
|
+
insertNode2(parent, startAnchor, anchor);
|
|
1451
|
+
insertNode2(parent, endAnchor, anchor);
|
|
1452
|
+
const owner = getCurrentInstance();
|
|
1453
|
+
let mountedContent = null;
|
|
1454
|
+
let initialized = false;
|
|
1455
|
+
const block = {
|
|
1456
|
+
type: "reactive-block",
|
|
1457
|
+
startAnchor,
|
|
1458
|
+
endAnchor,
|
|
1459
|
+
children: [],
|
|
1460
|
+
dispose: () => {}
|
|
1461
|
+
};
|
|
1462
|
+
block.dispose = effect(() => {
|
|
1463
|
+
if (mountedContent) {
|
|
1464
|
+
removeMountedNode(mountedContent);
|
|
1465
|
+
}
|
|
1466
|
+
const value = resolve(reactive);
|
|
1467
|
+
mountedContent = renderNodeToDOM(value, parent, endAnchor, namespace);
|
|
1468
|
+
block.children = [mountedContent];
|
|
1469
|
+
if (initialized) {
|
|
1470
|
+
if (owner)
|
|
1471
|
+
fireMountedHooks(owner);
|
|
1472
|
+
queueUpdatedHooks(owner);
|
|
1473
|
+
}
|
|
1474
|
+
initialized = true;
|
|
1475
|
+
});
|
|
1476
|
+
return block;
|
|
1477
|
+
}
|
|
1040
1478
|
function insertNode2(parent, child, anchor) {
|
|
1041
1479
|
if (anchor) {
|
|
1042
1480
|
domOps.insertBefore(parent, child, anchor);
|
|
@@ -1120,5 +1558,5 @@ export {
|
|
|
1120
1558
|
applyAttributes
|
|
1121
1559
|
};
|
|
1122
1560
|
|
|
1123
|
-
//# debugId=
|
|
1561
|
+
//# debugId=ECCB38F4A76AE39C64756E2164756E21
|
|
1124
1562
|
//# sourceMappingURL=index.development.js.map
|