xote 6.4.0 → 7.0.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/README.md +146 -36
- package/dist/RuntimeAttr.res-Cr5Qmz0i.js +1 -0
- package/dist/RuntimeAttr.res-DAZkL5CF.mjs +539 -0
- package/dist/RuntimeHydrationMarkers.res-C5-ieaOS.js +1 -0
- package/dist/RuntimeHydrationMarkers.res-DHikAvHr.mjs +6 -0
- package/dist/RuntimeJsxProp.res-A6N-qWoK.js +1 -0
- package/dist/RuntimeJsxProp.res-D3W5GXqT.mjs +64 -0
- package/dist/Stdlib_Array-1YCQzU_Y.mjs +22 -0
- package/dist/Stdlib_Array-BeBVUIuY.js +1 -0
- package/dist/View.res-C36--SJD.js +1 -0
- package/dist/View.res-SuqJrQPC.mjs +777 -0
- package/dist/client.cjs +1 -0
- package/dist/client.mjs +131 -0
- package/dist/hydration.cjs +1 -0
- package/dist/hydration.mjs +385 -0
- package/dist/mdx.cjs +1 -0
- package/dist/mdx.mjs +50 -0
- package/dist/router.cjs +1 -0
- package/dist/router.mjs +276 -0
- package/dist/ssr.cjs +17 -0
- package/dist/ssr.mjs +321 -0
- package/dist/xote.cjs +1 -17
- package/dist/xote.mjs +1456 -2467
- package/dist/xote.umd.js +1 -17
- package/package.json +42 -10
- package/rescript.json +2 -2
- package/src/Mdx.res +77 -0
- package/src/Mdx.res.mjs +93 -0
- package/src/Router.res +62 -8
- package/src/Router.res.mjs +60 -6
- package/src/RuntimeDom.res +7 -0
- package/src/RuntimeDom.res.mjs +8 -0
- package/src/RuntimeJsxProp.res +5 -8
- package/src/RuntimeJsxProp.res.mjs +9 -10
- package/src/RuntimeValue.res +35 -0
- package/src/RuntimeValue.res.mjs +67 -0
- package/src/SSRState.res +1 -4
- package/src/SSRState.res.mjs +4 -10
- package/src/View.res +224 -34
- package/src/View.res.mjs +306 -32
- package/src/jsx-dev-runtime.mjs +7 -0
- package/src/jsx-runtime.mjs +276 -0
- package/src/Node.res +0 -2
- package/src/Node.res.mjs +0 -82
- package/src/ReactiveProp.res +0 -2
- package/src/ReactiveProp.res.mjs +0 -19
package/src/View.res.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Core__Type from "@rescript/core/src/Core__Type.res.mjs";
|
|
4
|
+
import * as Core__Array from "@rescript/core/src/Core__Array.res.mjs";
|
|
3
5
|
import * as Effect$Xote from "./Effect.res.mjs";
|
|
4
6
|
import * as Signal$Xote from "./Signal.res.mjs";
|
|
5
7
|
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
@@ -8,6 +10,7 @@ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
|
8
10
|
import * as RuntimeDom$Xote from "./RuntimeDom.res.mjs";
|
|
9
11
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
10
12
|
import * as RuntimeOwner$Xote from "./RuntimeOwner.res.mjs";
|
|
13
|
+
import * as RuntimeValue$Xote from "./RuntimeValue.res.mjs";
|
|
11
14
|
|
|
12
15
|
function $$static(key, value) {
|
|
13
16
|
return [
|
|
@@ -56,25 +59,37 @@ function disposeElement(el) {
|
|
|
56
59
|
if (owner !== undefined) {
|
|
57
60
|
RuntimeOwner$Xote.disposeOwner(owner);
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
childNodes.forEach(disposeElement);
|
|
62
|
+
RuntimeDom$Xote.childNodesToArray(el).forEach(disposeElement);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
function shallowEqualIdentity(a, b) {
|
|
64
66
|
if (a === b) {
|
|
65
67
|
return true;
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
let match = Core__Type.Classify.classify(a);
|
|
70
|
+
let match$1 = Core__Type.Classify.classify(b);
|
|
71
|
+
if (typeof match !== "object") {
|
|
68
72
|
return false;
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
if (match.TAG !== "Object") {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (typeof match$1 !== "object") {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
if (match$1.TAG !== "Object") {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
let objB = match$1._0;
|
|
84
|
+
let objA = match._0;
|
|
85
|
+
let keysA = Object.keys(objA);
|
|
86
|
+
let keysB = Object.keys(objB);
|
|
72
87
|
if (keysA.length !== keysB.length) {
|
|
73
88
|
return false;
|
|
74
89
|
} else {
|
|
75
90
|
return keysA.every(key => {
|
|
76
|
-
let match =
|
|
77
|
-
let match$1 =
|
|
91
|
+
let match = objA[key];
|
|
92
|
+
let match$1 = objB[key];
|
|
78
93
|
if (match !== undefined && match$1 !== undefined) {
|
|
79
94
|
return Primitive_option.valFromOption(match) === Primitive_option.valFromOption(match$1);
|
|
80
95
|
} else {
|
|
@@ -94,22 +109,16 @@ function getKeyedChildren(children) {
|
|
|
94
109
|
if (children.length === 0) {
|
|
95
110
|
return;
|
|
96
111
|
}
|
|
97
|
-
let keyedChildren =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return;
|
|
112
|
+
let keyedChildren = Core__Array.filterMap(children, child => {
|
|
113
|
+
if (child.TAG === "Keyed") {
|
|
114
|
+
return {
|
|
115
|
+
key: child.key,
|
|
116
|
+
identity: child.identity,
|
|
117
|
+
child: child.child
|
|
118
|
+
};
|
|
105
119
|
}
|
|
106
|
-
keyedChildren.push({
|
|
107
|
-
key: child.key,
|
|
108
|
-
identity: child.identity,
|
|
109
|
-
child: child.child
|
|
110
|
-
});
|
|
111
120
|
});
|
|
112
|
-
if (
|
|
121
|
+
if (keyedChildren.length === children.length) {
|
|
113
122
|
return keyedChildren;
|
|
114
123
|
}
|
|
115
124
|
}
|
|
@@ -305,8 +314,7 @@ function render(_node) {
|
|
|
305
314
|
reconcileKeyedChildren(keyedChildren, keyedItems, container);
|
|
306
315
|
} else {
|
|
307
316
|
clearKeyedItems(keyedItems);
|
|
308
|
-
|
|
309
|
-
childNodes.forEach(disposeElement);
|
|
317
|
+
RuntimeDom$Xote.childNodesToArray(container).forEach(disposeElement);
|
|
310
318
|
container.innerHTML = "";
|
|
311
319
|
children.forEach(child => {
|
|
312
320
|
let childEl = render(child);
|
|
@@ -505,6 +513,13 @@ function float(value) {
|
|
|
505
513
|
};
|
|
506
514
|
}
|
|
507
515
|
|
|
516
|
+
function bool(value) {
|
|
517
|
+
return {
|
|
518
|
+
TAG: "Text",
|
|
519
|
+
_0: value ? "true" : "false"
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
508
523
|
function fragment(children) {
|
|
509
524
|
return {
|
|
510
525
|
TAG: "Fragment",
|
|
@@ -519,6 +534,18 @@ function signalFragment(signal) {
|
|
|
519
534
|
};
|
|
520
535
|
}
|
|
521
536
|
|
|
537
|
+
function childrenToArray(child) {
|
|
538
|
+
if (child !== undefined) {
|
|
539
|
+
if (child.TAG === "Fragment") {
|
|
540
|
+
return child._0;
|
|
541
|
+
} else {
|
|
542
|
+
return [child];
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
return [];
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
522
549
|
function each(signal, renderItem) {
|
|
523
550
|
let nodesSignal = Computed$Xote.make(() => Signal$Xote.get(signal).map(renderItem), undefined, undefined);
|
|
524
551
|
return {
|
|
@@ -536,10 +563,151 @@ function eachWithKey(signal, keyFn, renderItem) {
|
|
|
536
563
|
};
|
|
537
564
|
}
|
|
538
565
|
|
|
566
|
+
function make(props) {
|
|
567
|
+
let match = props.each;
|
|
568
|
+
let match$1 = props.by;
|
|
569
|
+
if (match.TAG === "Reactive") {
|
|
570
|
+
let signal = match._0;
|
|
571
|
+
if (match$1 !== undefined) {
|
|
572
|
+
return {
|
|
573
|
+
TAG: "KeyedList",
|
|
574
|
+
signal: signal,
|
|
575
|
+
keyFn: match$1,
|
|
576
|
+
renderItem: props.render
|
|
577
|
+
};
|
|
578
|
+
} else {
|
|
579
|
+
return each(signal, props.render);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
let items = match._0;
|
|
583
|
+
if (match$1 !== undefined) {
|
|
584
|
+
return {
|
|
585
|
+
TAG: "Fragment",
|
|
586
|
+
_0: items.map(item => ({
|
|
587
|
+
TAG: "Keyed",
|
|
588
|
+
key: match$1(item),
|
|
589
|
+
identity: item,
|
|
590
|
+
child: props.render(item)
|
|
591
|
+
}))
|
|
592
|
+
};
|
|
593
|
+
} else {
|
|
594
|
+
return {
|
|
595
|
+
TAG: "Fragment",
|
|
596
|
+
_0: items.map(props.render)
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
let For = {
|
|
602
|
+
make: make
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
function make$1(props) {
|
|
606
|
+
let items = props.each;
|
|
607
|
+
if (items.TAG === "Reactive") {
|
|
608
|
+
return {
|
|
609
|
+
TAG: "KeyedList",
|
|
610
|
+
signal: items._0,
|
|
611
|
+
keyFn: props.by,
|
|
612
|
+
renderItem: props.render
|
|
613
|
+
};
|
|
614
|
+
} else {
|
|
615
|
+
return {
|
|
616
|
+
TAG: "Fragment",
|
|
617
|
+
_0: items._0.map(item => ({
|
|
618
|
+
TAG: "Keyed",
|
|
619
|
+
key: props.by(item),
|
|
620
|
+
identity: item,
|
|
621
|
+
child: props.render(item)
|
|
622
|
+
}))
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
let KeyedFor = {
|
|
628
|
+
make: make$1
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
function make$2(props) {
|
|
632
|
+
let signal = props.when_;
|
|
633
|
+
if (signal.TAG !== "Reactive") {
|
|
634
|
+
if (signal._0) {
|
|
635
|
+
return {
|
|
636
|
+
TAG: "Fragment",
|
|
637
|
+
_0: childrenToArray(props.children)
|
|
638
|
+
};
|
|
639
|
+
} else {
|
|
640
|
+
return {
|
|
641
|
+
TAG: "Fragment",
|
|
642
|
+
_0: childrenToArray(props.fallback)
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
let signal$1 = signal._0;
|
|
647
|
+
return {
|
|
648
|
+
TAG: "SignalFragment",
|
|
649
|
+
_0: Computed$Xote.make(() => {
|
|
650
|
+
if (Signal$Xote.get(signal$1)) {
|
|
651
|
+
return childrenToArray(props.children);
|
|
652
|
+
} else {
|
|
653
|
+
return childrenToArray(props.fallback);
|
|
654
|
+
}
|
|
655
|
+
}, undefined, undefined)
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
let Show = {
|
|
660
|
+
make: make$2
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
function renderValue(props, value) {
|
|
664
|
+
if (value !== undefined) {
|
|
665
|
+
return [props.render(Primitive_option.valFromOption(value))];
|
|
666
|
+
} else {
|
|
667
|
+
return childrenToArray(props.fallback);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function make$3(props) {
|
|
672
|
+
let value = props.value;
|
|
673
|
+
if (value.TAG !== "Reactive") {
|
|
674
|
+
return {
|
|
675
|
+
TAG: "Fragment",
|
|
676
|
+
_0: renderValue(props, value._0)
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
let signal = value._0;
|
|
680
|
+
return {
|
|
681
|
+
TAG: "SignalFragment",
|
|
682
|
+
_0: Computed$Xote.make(() => renderValue(props, Signal$Xote.get(signal)), undefined, undefined)
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
let Maybe = {
|
|
687
|
+
renderValue: renderValue,
|
|
688
|
+
make: make$3
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
function make$4(props) {
|
|
692
|
+
let value = props.value;
|
|
693
|
+
if (value.TAG !== "Reactive") {
|
|
694
|
+
return props.render(value._0);
|
|
695
|
+
}
|
|
696
|
+
let signal = value._0;
|
|
697
|
+
return {
|
|
698
|
+
TAG: "SignalFragment",
|
|
699
|
+
_0: Computed$Xote.make(() => [props.render(Signal$Xote.get(signal))], undefined, undefined)
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
let Value = {
|
|
704
|
+
make: make$4
|
|
705
|
+
};
|
|
706
|
+
|
|
539
707
|
function element(tag, attrsOpt, eventsOpt, childrenOpt, param) {
|
|
540
|
-
let attrs = attrsOpt !== undefined ? attrsOpt : []
|
|
541
|
-
let events = eventsOpt !== undefined ? eventsOpt : []
|
|
542
|
-
let children = childrenOpt !== undefined ? childrenOpt : []
|
|
708
|
+
let attrs = attrsOpt !== undefined ? attrsOpt : [];
|
|
709
|
+
let events = eventsOpt !== undefined ? eventsOpt : [];
|
|
710
|
+
let children = childrenOpt !== undefined ? childrenOpt : [];
|
|
543
711
|
return {
|
|
544
712
|
TAG: "Element",
|
|
545
713
|
tag: tag,
|
|
@@ -571,25 +739,119 @@ function mountById(node, containerId) {
|
|
|
571
739
|
}
|
|
572
740
|
}
|
|
573
741
|
|
|
742
|
+
function valuePrimitive(value, stringify) {
|
|
743
|
+
if (RuntimeValue$Xote.isReactiveProp(value)) {
|
|
744
|
+
if (value.TAG !== "Reactive") {
|
|
745
|
+
return {
|
|
746
|
+
TAG: "Text",
|
|
747
|
+
_0: stringify(value._0)
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
let signal = value._0;
|
|
751
|
+
return {
|
|
752
|
+
TAG: "SignalText",
|
|
753
|
+
_0: Computed$Xote.make(() => stringify(Signal$Xote.get(signal)), undefined, undefined)
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
let match = Core__Type.Classify.classify(value);
|
|
757
|
+
if (typeof match !== "object") {
|
|
758
|
+
return {
|
|
759
|
+
TAG: "Text",
|
|
760
|
+
_0: ""
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
switch (match.TAG) {
|
|
764
|
+
case "Object" :
|
|
765
|
+
return {
|
|
766
|
+
TAG: "SignalText",
|
|
767
|
+
_0: Computed$Xote.make(() => stringify(Signal$Xote.get(value)), undefined, undefined)
|
|
768
|
+
};
|
|
769
|
+
case "Function" :
|
|
770
|
+
return signalText(() => stringify(value()));
|
|
771
|
+
default:
|
|
772
|
+
return {
|
|
773
|
+
TAG: "Text",
|
|
774
|
+
_0: stringify(value)
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
function renderValuePrimitiveProps(props, stringify) {
|
|
780
|
+
let match = RuntimeValue$Xote.getField(props, "children");
|
|
781
|
+
let match$1 = RuntimeValue$Xote.getField(props, "value");
|
|
782
|
+
if (match !== undefined) {
|
|
783
|
+
return valuePrimitive(Primitive_option.valFromOption(match), stringify);
|
|
784
|
+
} else if (match$1 !== undefined) {
|
|
785
|
+
return valuePrimitive(Primitive_option.valFromOption(match$1), stringify);
|
|
786
|
+
} else {
|
|
787
|
+
return {
|
|
788
|
+
TAG: "Text",
|
|
789
|
+
_0: ""
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function make$5(props) {
|
|
795
|
+
return renderValuePrimitiveProps(props, value => value);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
let Text = {
|
|
799
|
+
make: make$5
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
function make$6(props) {
|
|
803
|
+
return renderValuePrimitiveProps(props, value => value.toString());
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
let Int = {
|
|
807
|
+
make: make$6
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
function make$7(props) {
|
|
811
|
+
return renderValuePrimitiveProps(props, value => value.toString());
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
let Float = {
|
|
815
|
+
make: make$7
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
function toString(value) {
|
|
819
|
+
if (value) {
|
|
820
|
+
return "true";
|
|
821
|
+
} else {
|
|
822
|
+
return "false";
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function make$8(props) {
|
|
827
|
+
return renderValuePrimitiveProps(props, toString);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
let Bool = {
|
|
831
|
+
toString: toString,
|
|
832
|
+
make: make$8
|
|
833
|
+
};
|
|
834
|
+
|
|
574
835
|
let DOM;
|
|
575
836
|
|
|
576
837
|
let Reactivity;
|
|
577
838
|
|
|
839
|
+
let Core;
|
|
840
|
+
|
|
578
841
|
let attr = $$static;
|
|
579
842
|
|
|
580
843
|
let signalAttr = signal;
|
|
581
844
|
|
|
582
845
|
let computedAttr = computed;
|
|
583
846
|
|
|
584
|
-
let list = each;
|
|
585
|
-
|
|
586
|
-
let keyedList = eachWithKey;
|
|
587
|
-
|
|
588
847
|
let empty = $$null;
|
|
589
848
|
|
|
849
|
+
let isReactiveProp = RuntimeValue$Xote.isReactiveProp;
|
|
850
|
+
|
|
590
851
|
export {
|
|
591
852
|
DOM,
|
|
592
853
|
Reactivity,
|
|
854
|
+
Core,
|
|
593
855
|
Attributes,
|
|
594
856
|
attr,
|
|
595
857
|
signalAttr,
|
|
@@ -602,16 +864,28 @@ export {
|
|
|
602
864
|
signalFloat,
|
|
603
865
|
int,
|
|
604
866
|
float,
|
|
867
|
+
bool,
|
|
605
868
|
fragment,
|
|
606
869
|
signalFragment,
|
|
870
|
+
childrenToArray,
|
|
607
871
|
each,
|
|
608
|
-
list,
|
|
609
872
|
eachWithKey,
|
|
610
|
-
|
|
873
|
+
For,
|
|
874
|
+
KeyedFor,
|
|
875
|
+
Show,
|
|
876
|
+
Maybe,
|
|
877
|
+
Value,
|
|
611
878
|
element,
|
|
612
879
|
$$null,
|
|
613
880
|
empty,
|
|
614
881
|
mount,
|
|
615
882
|
mountById,
|
|
883
|
+
isReactiveProp,
|
|
884
|
+
valuePrimitive,
|
|
885
|
+
renderValuePrimitiveProps,
|
|
886
|
+
Text,
|
|
887
|
+
Int,
|
|
888
|
+
Float,
|
|
889
|
+
Bool,
|
|
616
890
|
}
|
|
617
891
|
/* RuntimeDom-Xote Not a pure module */
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import * as Computed from "./Computed.res.mjs";
|
|
2
|
+
import * as Signal from "./Signal.res.mjs";
|
|
3
|
+
import * as View from "./View.res.mjs";
|
|
4
|
+
|
|
5
|
+
export const Fragment = Symbol.for("xote.fragment");
|
|
6
|
+
|
|
7
|
+
const nodeTags = new Set([
|
|
8
|
+
"Element",
|
|
9
|
+
"Text",
|
|
10
|
+
"SignalText",
|
|
11
|
+
"Fragment",
|
|
12
|
+
"SignalFragment",
|
|
13
|
+
"Keyed",
|
|
14
|
+
"LazyComponent",
|
|
15
|
+
"KeyedList",
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const eventAliases = {
|
|
19
|
+
onChange: "change",
|
|
20
|
+
onClick: "click",
|
|
21
|
+
onContextMenu: "contextmenu",
|
|
22
|
+
onDoubleClick: "dblclick",
|
|
23
|
+
onInput: "input",
|
|
24
|
+
onSubmit: "submit",
|
|
25
|
+
onFocus: "focus",
|
|
26
|
+
onBlur: "blur",
|
|
27
|
+
onKeyDown: "keydown",
|
|
28
|
+
onKeyUp: "keyup",
|
|
29
|
+
onMouseDown: "mousedown",
|
|
30
|
+
onMouseEnter: "mouseenter",
|
|
31
|
+
onMouseLeave: "mouseleave",
|
|
32
|
+
onMouseMove: "mousemove",
|
|
33
|
+
onMouseUp: "mouseup",
|
|
34
|
+
onDrag: "drag",
|
|
35
|
+
onDragStart: "dragstart",
|
|
36
|
+
onDragEnd: "dragend",
|
|
37
|
+
onDragOver: "dragover",
|
|
38
|
+
onDragEnter: "dragenter",
|
|
39
|
+
onDragLeave: "dragleave",
|
|
40
|
+
onDrop: "drop",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const attrAliases = {
|
|
44
|
+
acceptCharset: "accept-charset",
|
|
45
|
+
autoFocus: "autofocus",
|
|
46
|
+
className: "class",
|
|
47
|
+
contentEditable: "contenteditable",
|
|
48
|
+
htmlFor: "for",
|
|
49
|
+
httpEquiv: "http-equiv",
|
|
50
|
+
maxLength: "maxlength",
|
|
51
|
+
minLength: "minlength",
|
|
52
|
+
preserveAspectRatio: "preserveAspectRatio",
|
|
53
|
+
readOnly: "readonly",
|
|
54
|
+
spellCheck: "spellcheck",
|
|
55
|
+
srcSet: "srcset",
|
|
56
|
+
strokeDasharray: "stroke-dasharray",
|
|
57
|
+
strokeDashoffset: "stroke-dashoffset",
|
|
58
|
+
strokeLinecap: "stroke-linecap",
|
|
59
|
+
strokeLinejoin: "stroke-linejoin",
|
|
60
|
+
strokeMiterlimit: "stroke-miterlimit",
|
|
61
|
+
strokeWidth: "stroke-width",
|
|
62
|
+
tabIndex: "tabindex",
|
|
63
|
+
viewBox: "viewBox",
|
|
64
|
+
xlinkHref: "xlink:href",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const internalProps = new Set([
|
|
68
|
+
"children",
|
|
69
|
+
"components",
|
|
70
|
+
"key",
|
|
71
|
+
"mdxType",
|
|
72
|
+
"originalType",
|
|
73
|
+
"parentName",
|
|
74
|
+
"ref",
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
function isXoteNode(value) {
|
|
78
|
+
return value && typeof value === "object" && nodeTags.has(value.TAG);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isReactiveProp(value) {
|
|
82
|
+
return (
|
|
83
|
+
value &&
|
|
84
|
+
typeof value === "object" &&
|
|
85
|
+
(value.TAG === "Static" || value.TAG === "Reactive")
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isSignal(value) {
|
|
90
|
+
return (
|
|
91
|
+
value &&
|
|
92
|
+
typeof value === "object" &&
|
|
93
|
+
"subs" in value &&
|
|
94
|
+
"value" in value &&
|
|
95
|
+
typeof value.equals === "function"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function toKebab(name) {
|
|
100
|
+
return name.replace(/[A-Z]/g, char => `-${char.toLowerCase()}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function normalizeAttrName(name) {
|
|
104
|
+
if (attrAliases[name]) {
|
|
105
|
+
return attrAliases[name];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (/^(aria|data)[A-Z]/.test(name)) {
|
|
109
|
+
return toKebab(name);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return name;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function normalizeStyle(style) {
|
|
116
|
+
if (typeof style === "string") {
|
|
117
|
+
return style;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!style || typeof style !== "object") {
|
|
121
|
+
return String(style ?? "");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return Object.entries(style)
|
|
125
|
+
.filter(([, value]) => value !== null && value !== undefined && value !== false)
|
|
126
|
+
.map(([key, value]) => `${toKebab(key)}:${String(value)}`)
|
|
127
|
+
.join(";");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function stringifyAttrValue(name, value) {
|
|
131
|
+
if (name === "style") {
|
|
132
|
+
return normalizeStyle(value);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return String(value);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function attrFromValue(name, value) {
|
|
139
|
+
if (isReactiveProp(value)) {
|
|
140
|
+
if (value.TAG === "Static") {
|
|
141
|
+
return View.attr(name, stringifyAttrValue(name, value._0));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const signal = value._0;
|
|
145
|
+
return View.signalAttr(
|
|
146
|
+
name,
|
|
147
|
+
Computed.make(() => stringifyAttrValue(name, Signal.get(signal)), undefined, undefined),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (isSignal(value)) {
|
|
152
|
+
return View.signalAttr(
|
|
153
|
+
name,
|
|
154
|
+
Computed.make(() => stringifyAttrValue(name, Signal.get(value)), undefined, undefined),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (typeof value === "function") {
|
|
159
|
+
return View.computedAttr(name, () => stringifyAttrValue(name, value()));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return View.attr(name, stringifyAttrValue(name, value));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function eventNameFromProp(name, value) {
|
|
166
|
+
if (typeof value !== "function" || !/^on[A-Z]/.test(name)) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return eventAliases[name] ?? name.slice(2).toLowerCase();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function normalizeChildren(children) {
|
|
174
|
+
if (children === null || children === undefined || typeof children === "boolean") {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (Array.isArray(children)) {
|
|
179
|
+
return children.flatMap(normalizeChildren);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isXoteNode(children)) {
|
|
183
|
+
return [children];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return [View.text(String(children))];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function normalizeNode(value) {
|
|
190
|
+
if (isXoteNode(value)) {
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return View.fragment(normalizeChildren(value));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function buildElement(tag, props = {}) {
|
|
198
|
+
const attrs = [];
|
|
199
|
+
const events = [];
|
|
200
|
+
|
|
201
|
+
for (const [rawName, value] of Object.entries(props)) {
|
|
202
|
+
if (internalProps.has(rawName) || value === null || value === undefined) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const eventName = eventNameFromProp(rawName, value);
|
|
207
|
+
if (eventName) {
|
|
208
|
+
events.push([eventName, value]);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const attrName = normalizeAttrName(rawName);
|
|
213
|
+
attrs.push(attrFromValue(attrName, value));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return View.element(tag, attrs, events, normalizeChildren(props.children), undefined);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function getReservedKey(props, key) {
|
|
220
|
+
if (key !== undefined && key !== null) {
|
|
221
|
+
return key;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return props?.key;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function stripReservedKey(props) {
|
|
228
|
+
if (!props || !Object.prototype.hasOwnProperty.call(props, "key")) {
|
|
229
|
+
return props ?? {};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const { key: _key, ...nextProps } = props;
|
|
233
|
+
return nextProps;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function withKey(node, key, props) {
|
|
237
|
+
const reservedKey = getReservedKey(props, key);
|
|
238
|
+
|
|
239
|
+
if (reservedKey === undefined || reservedKey === null) {
|
|
240
|
+
return node;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
TAG: "Keyed",
|
|
245
|
+
key: String(reservedKey),
|
|
246
|
+
identity: props ?? {},
|
|
247
|
+
child: node,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function jsx(type, props, key) {
|
|
252
|
+
const nextProps = stripReservedKey(props);
|
|
253
|
+
|
|
254
|
+
if (type === Fragment) {
|
|
255
|
+
return withKey(View.fragment(normalizeChildren(nextProps.children)), key, props);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (typeof type === "string") {
|
|
259
|
+
return withKey(buildElement(type, nextProps), key, props);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (typeof type === "function") {
|
|
263
|
+
return withKey(
|
|
264
|
+
{
|
|
265
|
+
TAG: "LazyComponent",
|
|
266
|
+
_0: () => normalizeNode(type(nextProps)),
|
|
267
|
+
},
|
|
268
|
+
key,
|
|
269
|
+
props,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
throw new TypeError(`Unsupported Xote JSX element type: ${String(type)}`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export const jsxs = jsx;
|