mol_jsx_lib 0.0.56 → 0.0.59
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/node.d.ts +7 -0
- package/node.deps.json +1 -1
- package/node.esm.js +70 -2
- package/node.esm.js.map +1 -1
- package/node.js +70 -2
- package/node.js.map +1 -1
- package/node.test.js +131 -27
- package/node.test.js.map +1 -1
- package/package.json +3 -1
- package/web.d.ts +7 -0
- package/web.deps.json +1 -1
- package/web.esm.js +70 -2
- package/web.esm.js.map +1 -1
- package/web.js +70 -2
- package/web.js.map +1 -1
- package/web.test.js +61 -25
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -721,6 +721,34 @@ var $;
|
|
|
721
721
|
;
|
|
722
722
|
"use strict";
|
|
723
723
|
var $;
|
|
724
|
+
(function ($) {
|
|
725
|
+
function $mol_func_name(func) {
|
|
726
|
+
let name = func.name;
|
|
727
|
+
if (name?.length > 1)
|
|
728
|
+
return name;
|
|
729
|
+
for (let key in this) {
|
|
730
|
+
try {
|
|
731
|
+
if (this[key] !== func)
|
|
732
|
+
continue;
|
|
733
|
+
name = key;
|
|
734
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
catch { }
|
|
738
|
+
}
|
|
739
|
+
return name;
|
|
740
|
+
}
|
|
741
|
+
$.$mol_func_name = $mol_func_name;
|
|
742
|
+
function $mol_func_name_from(target, source) {
|
|
743
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
744
|
+
return target;
|
|
745
|
+
}
|
|
746
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
747
|
+
})($ || ($ = {}));
|
|
748
|
+
//mol/func/name/name.ts
|
|
749
|
+
;
|
|
750
|
+
"use strict";
|
|
751
|
+
var $;
|
|
724
752
|
(function ($) {
|
|
725
753
|
function $mol_dom_render_children(el, childNodes) {
|
|
726
754
|
const node_set = new Set(childNodes);
|
|
@@ -781,6 +809,7 @@ var $;
|
|
|
781
809
|
var $;
|
|
782
810
|
(function ($) {
|
|
783
811
|
$.$mol_jsx_prefix = '';
|
|
812
|
+
$.$mol_jsx_crumbs = '';
|
|
784
813
|
$.$mol_jsx_booked = null;
|
|
785
814
|
$.$mol_jsx_document = {
|
|
786
815
|
getElementById: () => null,
|
|
@@ -790,16 +819,45 @@ var $;
|
|
|
790
819
|
$.$mol_jsx_frag = '';
|
|
791
820
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
792
821
|
const id = props && props.id || '';
|
|
822
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
823
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/([^ ]+)/, `$1_${id}`) : $.$mol_jsx_crumbs;
|
|
793
824
|
if (Elem && $.$mol_jsx_booked) {
|
|
794
825
|
if ($.$mol_jsx_booked.has(id)) {
|
|
795
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
826
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
796
827
|
}
|
|
797
828
|
else {
|
|
798
829
|
$.$mol_jsx_booked.add(id);
|
|
799
830
|
}
|
|
800
831
|
}
|
|
801
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
802
832
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
833
|
+
if ($.$mol_jsx_prefix) {
|
|
834
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
835
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
836
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
837
|
+
for (const field in props) {
|
|
838
|
+
const func = props[field];
|
|
839
|
+
if (typeof func !== 'function')
|
|
840
|
+
continue;
|
|
841
|
+
const wrapper = function (...args) {
|
|
842
|
+
const prefix = $.$mol_jsx_prefix;
|
|
843
|
+
const booked = $.$mol_jsx_booked;
|
|
844
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
845
|
+
try {
|
|
846
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
847
|
+
$.$mol_jsx_booked = booked_ext;
|
|
848
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
849
|
+
return func.call(this, ...args);
|
|
850
|
+
}
|
|
851
|
+
finally {
|
|
852
|
+
$.$mol_jsx_prefix = prefix;
|
|
853
|
+
$.$mol_jsx_booked = booked;
|
|
854
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
$mol_func_name_from(wrapper, func);
|
|
858
|
+
props[field] = wrapper;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
803
861
|
if (typeof Elem !== 'string') {
|
|
804
862
|
if ('prototype' in Elem) {
|
|
805
863
|
const view = node && node[Elem] || new Elem;
|
|
@@ -808,6 +866,7 @@ var $;
|
|
|
808
866
|
view.childNodes = childNodes;
|
|
809
867
|
if (!view.ownerDocument)
|
|
810
868
|
view.ownerDocument = $.$mol_jsx_document;
|
|
869
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
811
870
|
node = view.valueOf();
|
|
812
871
|
node[Elem] = view;
|
|
813
872
|
return node;
|
|
@@ -815,14 +874,17 @@ var $;
|
|
|
815
874
|
else {
|
|
816
875
|
const prefix = $.$mol_jsx_prefix;
|
|
817
876
|
const booked = $.$mol_jsx_booked;
|
|
877
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
818
878
|
try {
|
|
819
879
|
$.$mol_jsx_prefix = guid;
|
|
820
880
|
$.$mol_jsx_booked = new Set;
|
|
881
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
821
882
|
return Elem(props, ...childNodes);
|
|
822
883
|
}
|
|
823
884
|
finally {
|
|
824
885
|
$.$mol_jsx_prefix = prefix;
|
|
825
886
|
$.$mol_jsx_booked = booked;
|
|
887
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
826
888
|
}
|
|
827
889
|
}
|
|
828
890
|
}
|
|
@@ -853,6 +915,8 @@ var $;
|
|
|
853
915
|
}
|
|
854
916
|
if (guid)
|
|
855
917
|
node.id = guid;
|
|
918
|
+
if ($.$mol_jsx_crumbs)
|
|
919
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
856
920
|
return node;
|
|
857
921
|
}
|
|
858
922
|
$.$mol_jsx = $mol_jsx;
|
|
@@ -1863,6 +1927,7 @@ var $;
|
|
|
1863
1927
|
}
|
|
1864
1928
|
attributes;
|
|
1865
1929
|
ownerDocument;
|
|
1930
|
+
className;
|
|
1866
1931
|
get childNodes() {
|
|
1867
1932
|
return this._kids();
|
|
1868
1933
|
}
|
|
@@ -1873,16 +1938,19 @@ var $;
|
|
|
1873
1938
|
valueOf() {
|
|
1874
1939
|
const prefix = $mol_jsx_prefix;
|
|
1875
1940
|
const booked = $mol_jsx_booked;
|
|
1941
|
+
const crumbs = $mol_jsx_crumbs;
|
|
1876
1942
|
const document = $mol_jsx_document;
|
|
1877
1943
|
try {
|
|
1878
1944
|
$mol_jsx_prefix = this[Symbol.toStringTag];
|
|
1879
1945
|
$mol_jsx_booked = new Set;
|
|
1946
|
+
$mol_jsx_crumbs = this.className;
|
|
1880
1947
|
$mol_jsx_document = this.ownerDocument;
|
|
1881
1948
|
return this.render();
|
|
1882
1949
|
}
|
|
1883
1950
|
finally {
|
|
1884
1951
|
$mol_jsx_prefix = prefix;
|
|
1885
1952
|
$mol_jsx_booked = booked;
|
|
1953
|
+
$mol_jsx_crumbs = crumbs;
|
|
1886
1954
|
$mol_jsx_document = document;
|
|
1887
1955
|
}
|
|
1888
1956
|
}
|
|
@@ -2560,6 +2628,20 @@ var $;
|
|
|
2560
2628
|
//mol/assert/assert.ts
|
|
2561
2629
|
;
|
|
2562
2630
|
"use strict";
|
|
2631
|
+
var $;
|
|
2632
|
+
(function ($_1) {
|
|
2633
|
+
$mol_test({
|
|
2634
|
+
'FQN of anon function'($) {
|
|
2635
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2636
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2637
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2638
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2639
|
+
},
|
|
2640
|
+
});
|
|
2641
|
+
})($ || ($ = {}));
|
|
2642
|
+
//mol/func/name/name.test.ts
|
|
2643
|
+
;
|
|
2644
|
+
"use strict";
|
|
2563
2645
|
//mol/type/error/error.ts
|
|
2564
2646
|
;
|
|
2565
2647
|
"use strict";
|
|
@@ -2742,28 +2824,50 @@ var $;
|
|
|
2742
2824
|
const Button = (props, target) => {
|
|
2743
2825
|
return $mol_jsx("button", { title: props.hint }, target());
|
|
2744
2826
|
};
|
|
2745
|
-
const dom = $mol_jsx(Button, { id: "
|
|
2746
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="
|
|
2827
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
2828
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
|
|
2747
2829
|
},
|
|
2748
2830
|
'Nested guid generation'() {
|
|
2749
2831
|
const Foo = () => {
|
|
2750
2832
|
return $mol_jsx("div", null,
|
|
2751
|
-
$mol_jsx(Bar, { id: "
|
|
2752
|
-
$mol_jsx("img", { id: "
|
|
2833
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
2834
|
+
$mol_jsx("img", { id: "icon" })));
|
|
2753
2835
|
};
|
|
2754
2836
|
const Bar = (props, icon) => {
|
|
2755
2837
|
return $mol_jsx("span", null, icon);
|
|
2756
2838
|
};
|
|
2757
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
2758
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
2839
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
2840
|
+
$mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"></span></div>');
|
|
2759
2841
|
},
|
|
2760
2842
|
'Fail on non unique ids'() {
|
|
2761
2843
|
const App = () => {
|
|
2762
2844
|
return $mol_jsx("div", null,
|
|
2763
|
-
$mol_jsx("span", { id: "
|
|
2764
|
-
$mol_jsx("span", { id: "
|
|
2845
|
+
$mol_jsx("span", { id: "bar" }),
|
|
2846
|
+
$mol_jsx("span", { id: "bar" }));
|
|
2847
|
+
};
|
|
2848
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
2849
|
+
},
|
|
2850
|
+
'Owner based guid generationn'() {
|
|
2851
|
+
const Foo = () => {
|
|
2852
|
+
return $mol_jsx("div", null,
|
|
2853
|
+
$mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
2854
|
+
};
|
|
2855
|
+
const Bar = (props) => {
|
|
2856
|
+
return $mol_jsx("span", null, props.icon());
|
|
2857
|
+
};
|
|
2858
|
+
const dom = $mol_jsx(Foo, { id: "app" });
|
|
2859
|
+
$mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
|
|
2860
|
+
},
|
|
2861
|
+
'Fail on same ids from different caller'() {
|
|
2862
|
+
const Foo = () => {
|
|
2863
|
+
return $mol_jsx("div", null,
|
|
2864
|
+
$mol_jsx("img", { id: "icon" }),
|
|
2865
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
2866
|
+
};
|
|
2867
|
+
const Bar = (props) => {
|
|
2868
|
+
return $mol_jsx("span", null, props.icon());
|
|
2765
2869
|
};
|
|
2766
|
-
$mol_assert_fail(() => $mol_jsx(
|
|
2870
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
2767
2871
|
},
|
|
2768
2872
|
});
|
|
2769
2873
|
})($ || ($ = {}));
|
|
@@ -2789,9 +2893,9 @@ var $;
|
|
|
2789
2893
|
(function ($) {
|
|
2790
2894
|
$mol_test({
|
|
2791
2895
|
'Attach to document'() {
|
|
2792
|
-
const doc = $mol_dom_parse('<html><body id="
|
|
2793
|
-
$mol_jsx_attach(doc, () => $mol_jsx("body", { id: "
|
|
2794
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="
|
|
2896
|
+
const doc = $mol_dom_parse('<html><body id="foo"></body></html>');
|
|
2897
|
+
$mol_jsx_attach(doc, () => $mol_jsx("body", { id: "foo" }, "bar"));
|
|
2898
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo">bar</body></html>');
|
|
2795
2899
|
},
|
|
2796
2900
|
});
|
|
2797
2901
|
})($ || ($ = {}));
|
|
@@ -3777,10 +3881,10 @@ var $;
|
|
|
3777
3881
|
this.childNodes.join('-'));
|
|
3778
3882
|
}
|
|
3779
3883
|
}
|
|
3780
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
3884
|
+
const dom = $mol_jsx(Foo, { id: "foo", title: "bar" },
|
|
3781
3885
|
"xxx",
|
|
3782
3886
|
123);
|
|
3783
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
3887
|
+
$mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo">bar xxx-123</div>');
|
|
3784
3888
|
},
|
|
3785
3889
|
'View by element'() {
|
|
3786
3890
|
let br;
|
|
@@ -3788,7 +3892,7 @@ var $;
|
|
|
3788
3892
|
class Br extends $mol_jsx_view {
|
|
3789
3893
|
render() {
|
|
3790
3894
|
br = this;
|
|
3791
|
-
return $mol_jsx("br", { id: "
|
|
3895
|
+
return $mol_jsx("br", { id: "foo" });
|
|
3792
3896
|
}
|
|
3793
3897
|
}
|
|
3794
3898
|
class Brr extends $mol_jsx_view {
|
|
@@ -3801,7 +3905,7 @@ var $;
|
|
|
3801
3905
|
$mol_assert_equal(Brr.of($mol_jsx(Brr, null)), brr);
|
|
3802
3906
|
},
|
|
3803
3907
|
async 'Attached view rerender'() {
|
|
3804
|
-
const doc = $mol_dom_parse('<html><body id="
|
|
3908
|
+
const doc = $mol_dom_parse('<html><body id="foo"></body></html>');
|
|
3805
3909
|
class Title extends $mol_jsx_view {
|
|
3806
3910
|
value(next = 'foo') { return next; }
|
|
3807
3911
|
render() {
|
|
@@ -3811,13 +3915,13 @@ var $;
|
|
|
3811
3915
|
__decorate([
|
|
3812
3916
|
$mol_mem
|
|
3813
3917
|
], Title.prototype, "value", null);
|
|
3814
|
-
const dom = $mol_jsx_attach(doc, () => $mol_jsx(Title, { id: "
|
|
3918
|
+
const dom = $mol_jsx_attach(doc, () => $mol_jsx(Title, { id: "foo" }));
|
|
3815
3919
|
const title = Title.of(dom);
|
|
3816
3920
|
$mol_assert_equal(title.ownerDocument, doc);
|
|
3817
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="
|
|
3921
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo" class="Title">foo</body></html>');
|
|
3818
3922
|
title.value('bar');
|
|
3819
3923
|
await $mol_wire_fiber.sync();
|
|
3820
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="
|
|
3924
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo" class="Title">bar</body></html>');
|
|
3821
3925
|
},
|
|
3822
3926
|
async 'Nested bound views'($) {
|
|
3823
3927
|
class Task extends $mol_jsx_view {
|
|
@@ -3837,23 +3941,23 @@ var $;
|
|
|
3837
3941
|
class App extends $mol_jsx_view {
|
|
3838
3942
|
title(next = '') { return next; }
|
|
3839
3943
|
render() {
|
|
3840
|
-
return ($mol_jsx(List, null, this.title() && $mol_jsx(Task, { id: "
|
|
3944
|
+
return ($mol_jsx(List, null, this.title() && $mol_jsx(Task, { id: "task", title: next => this.title(next) })));
|
|
3841
3945
|
}
|
|
3842
3946
|
}
|
|
3843
3947
|
__decorate([
|
|
3844
3948
|
$mol_mem
|
|
3845
3949
|
], App.prototype, "title", null);
|
|
3846
|
-
const doc = $mol_dom_parse('<html xmlns="http://www.w3.org/1999/xhtml"><body id="
|
|
3847
|
-
const root = $.$mol_jsx_attach(doc, () => $mol_jsx(App, { "$": $, id: "
|
|
3848
|
-
$mol_assert_equal($mol_dom_serialize(doc.documentElement), '<html xmlns="http://www.w3.org/1999/xhtml"><body id="
|
|
3950
|
+
const doc = $mol_dom_parse('<html xmlns="http://www.w3.org/1999/xhtml"><body id="root"></body></html>');
|
|
3951
|
+
const root = $.$mol_jsx_attach(doc, () => $mol_jsx(App, { "$": $, id: "root" }));
|
|
3952
|
+
$mol_assert_equal($mol_dom_serialize(doc.documentElement), '<html xmlns="http://www.w3.org/1999/xhtml"><body id="root" class="list App List"></body></html>');
|
|
3849
3953
|
App.of(root).title('barbar');
|
|
3850
3954
|
await $mol_wire_fiber.sync();
|
|
3851
3955
|
$mol_assert_equal(Task.of(root.firstElementChild).title(), 'barbar');
|
|
3852
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body id="
|
|
3956
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body id="root" class="list App List"><h1 id="root/task" class="App_task Task">barbar</h1></body></html>');
|
|
3853
3957
|
Task.of(root.firstElementChild).title('foofoo');
|
|
3854
3958
|
await $mol_wire_fiber.sync();
|
|
3855
3959
|
$mol_assert_equal(App.of(root).title(), 'foofoo');
|
|
3856
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body id="
|
|
3960
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body id="root" class="list App List"><h1 id="root/task" class="App_task Task">foofoo</h1></body></html>');
|
|
3857
3961
|
},
|
|
3858
3962
|
});
|
|
3859
3963
|
})($ || ($ = {}));
|