mol_jsx_lib 0.0.55 → 0.0.58
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 +5 -0
- package/node.deps.json +1 -1
- package/node.esm.js +54 -2
- package/node.esm.js.map +1 -1
- package/node.js +54 -2
- package/node.js.map +1 -1
- package/node.test.js +115 -27
- package/node.test.js.map +1 -1
- package/package.json +3 -1
- package/web.d.ts +5 -0
- package/web.deps.json +1 -1
- package/web.esm.js +54 -2
- package/web.esm.js.map +1 -1
- package/web.js +54 -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);
|
|
@@ -790,16 +818,40 @@ var $;
|
|
|
790
818
|
$.$mol_jsx_frag = '';
|
|
791
819
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
792
820
|
const id = props && props.id || '';
|
|
821
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
793
822
|
if (Elem && $.$mol_jsx_booked) {
|
|
794
823
|
if ($.$mol_jsx_booked.has(id)) {
|
|
795
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
824
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
796
825
|
}
|
|
797
826
|
else {
|
|
798
827
|
$.$mol_jsx_booked.add(id);
|
|
799
828
|
}
|
|
800
829
|
}
|
|
801
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
802
830
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
831
|
+
if ($.$mol_jsx_prefix) {
|
|
832
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
833
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
834
|
+
for (const field in props) {
|
|
835
|
+
const func = props[field];
|
|
836
|
+
if (typeof func !== 'function')
|
|
837
|
+
continue;
|
|
838
|
+
const wrapper = function (...args) {
|
|
839
|
+
const prefix = $.$mol_jsx_prefix;
|
|
840
|
+
const booked = $.$mol_jsx_booked;
|
|
841
|
+
try {
|
|
842
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
843
|
+
$.$mol_jsx_booked = booked_ext;
|
|
844
|
+
return func.call(this, ...args);
|
|
845
|
+
}
|
|
846
|
+
finally {
|
|
847
|
+
$.$mol_jsx_prefix = prefix;
|
|
848
|
+
$.$mol_jsx_booked = booked;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
$mol_func_name_from(wrapper, func);
|
|
852
|
+
props[field] = wrapper;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
803
855
|
if (typeof Elem !== 'string') {
|
|
804
856
|
if ('prototype' in Elem) {
|
|
805
857
|
const view = node && node[Elem] || new Elem;
|
|
@@ -2560,6 +2612,20 @@ var $;
|
|
|
2560
2612
|
//mol/assert/assert.ts
|
|
2561
2613
|
;
|
|
2562
2614
|
"use strict";
|
|
2615
|
+
var $;
|
|
2616
|
+
(function ($_1) {
|
|
2617
|
+
$mol_test({
|
|
2618
|
+
'FQN of anon function'($) {
|
|
2619
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2620
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2621
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2622
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2623
|
+
},
|
|
2624
|
+
});
|
|
2625
|
+
})($ || ($ = {}));
|
|
2626
|
+
//mol/func/name/name.test.ts
|
|
2627
|
+
;
|
|
2628
|
+
"use strict";
|
|
2563
2629
|
//mol/type/error/error.ts
|
|
2564
2630
|
;
|
|
2565
2631
|
"use strict";
|
|
@@ -2742,28 +2808,50 @@ var $;
|
|
|
2742
2808
|
const Button = (props, target) => {
|
|
2743
2809
|
return $mol_jsx("button", { title: props.hint }, target());
|
|
2744
2810
|
};
|
|
2745
|
-
const dom = $mol_jsx(Button, { id: "
|
|
2746
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="
|
|
2811
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
2812
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo">hey!</button>');
|
|
2747
2813
|
},
|
|
2748
2814
|
'Nested guid generation'() {
|
|
2749
2815
|
const Foo = () => {
|
|
2750
2816
|
return $mol_jsx("div", null,
|
|
2751
|
-
$mol_jsx(Bar, { id: "
|
|
2752
|
-
$mol_jsx("img", { id: "
|
|
2817
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
2818
|
+
$mol_jsx("img", { id: "icon" })));
|
|
2753
2819
|
};
|
|
2754
2820
|
const Bar = (props, icon) => {
|
|
2755
2821
|
return $mol_jsx("span", null, icon);
|
|
2756
2822
|
};
|
|
2757
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
2758
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
2823
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
2824
|
+
$mol_assert_equal(dom.outerHTML, '<div id="foo"><span id="foo/bar"><img id="foo/icon"></span></div>');
|
|
2759
2825
|
},
|
|
2760
2826
|
'Fail on non unique ids'() {
|
|
2761
2827
|
const App = () => {
|
|
2762
2828
|
return $mol_jsx("div", null,
|
|
2763
|
-
$mol_jsx("span", { id: "
|
|
2764
|
-
$mol_jsx("span", { id: "
|
|
2829
|
+
$mol_jsx("span", { id: "bar" }),
|
|
2830
|
+
$mol_jsx("span", { id: "bar" }));
|
|
2831
|
+
};
|
|
2832
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
2833
|
+
},
|
|
2834
|
+
'Owner based guid generationn'() {
|
|
2835
|
+
const Foo = () => {
|
|
2836
|
+
return $mol_jsx("div", null,
|
|
2837
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
2838
|
+
};
|
|
2839
|
+
const Bar = (props) => {
|
|
2840
|
+
return $mol_jsx("span", null, props.icon());
|
|
2841
|
+
};
|
|
2842
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
2843
|
+
$mol_assert_equal(dom.outerHTML, '<div id="foo"><span id="foo/bar"><img id="foo/icon"></span></div>');
|
|
2844
|
+
},
|
|
2845
|
+
'Fail on same ids from different caller'() {
|
|
2846
|
+
const Foo = () => {
|
|
2847
|
+
return $mol_jsx("div", null,
|
|
2848
|
+
$mol_jsx("img", { id: "icon" }),
|
|
2849
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
2850
|
+
};
|
|
2851
|
+
const Bar = (props) => {
|
|
2852
|
+
return $mol_jsx("span", null, props.icon());
|
|
2765
2853
|
};
|
|
2766
|
-
$mol_assert_fail(() => $mol_jsx(
|
|
2854
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
2767
2855
|
},
|
|
2768
2856
|
});
|
|
2769
2857
|
})($ || ($ = {}));
|
|
@@ -2789,9 +2877,9 @@ var $;
|
|
|
2789
2877
|
(function ($) {
|
|
2790
2878
|
$mol_test({
|
|
2791
2879
|
'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="
|
|
2880
|
+
const doc = $mol_dom_parse('<html><body id="foo"></body></html>');
|
|
2881
|
+
$mol_jsx_attach(doc, () => $mol_jsx("body", { id: "foo" }, "bar"));
|
|
2882
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo">bar</body></html>');
|
|
2795
2883
|
},
|
|
2796
2884
|
});
|
|
2797
2885
|
})($ || ($ = {}));
|
|
@@ -3777,10 +3865,10 @@ var $;
|
|
|
3777
3865
|
this.childNodes.join('-'));
|
|
3778
3866
|
}
|
|
3779
3867
|
}
|
|
3780
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
3868
|
+
const dom = $mol_jsx(Foo, { id: "foo", title: "bar" },
|
|
3781
3869
|
"xxx",
|
|
3782
3870
|
123);
|
|
3783
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
3871
|
+
$mol_assert_equal(dom.outerHTML, '<div id="foo">bar xxx-123</div>');
|
|
3784
3872
|
},
|
|
3785
3873
|
'View by element'() {
|
|
3786
3874
|
let br;
|
|
@@ -3788,7 +3876,7 @@ var $;
|
|
|
3788
3876
|
class Br extends $mol_jsx_view {
|
|
3789
3877
|
render() {
|
|
3790
3878
|
br = this;
|
|
3791
|
-
return $mol_jsx("br", { id: "
|
|
3879
|
+
return $mol_jsx("br", { id: "foo" });
|
|
3792
3880
|
}
|
|
3793
3881
|
}
|
|
3794
3882
|
class Brr extends $mol_jsx_view {
|
|
@@ -3801,7 +3889,7 @@ var $;
|
|
|
3801
3889
|
$mol_assert_equal(Brr.of($mol_jsx(Brr, null)), brr);
|
|
3802
3890
|
},
|
|
3803
3891
|
async 'Attached view rerender'() {
|
|
3804
|
-
const doc = $mol_dom_parse('<html><body id="
|
|
3892
|
+
const doc = $mol_dom_parse('<html><body id="foo"></body></html>');
|
|
3805
3893
|
class Title extends $mol_jsx_view {
|
|
3806
3894
|
value(next = 'foo') { return next; }
|
|
3807
3895
|
render() {
|
|
@@ -3811,13 +3899,13 @@ var $;
|
|
|
3811
3899
|
__decorate([
|
|
3812
3900
|
$mol_mem
|
|
3813
3901
|
], Title.prototype, "value", null);
|
|
3814
|
-
const dom = $mol_jsx_attach(doc, () => $mol_jsx(Title, { id: "
|
|
3902
|
+
const dom = $mol_jsx_attach(doc, () => $mol_jsx(Title, { id: "foo" }));
|
|
3815
3903
|
const title = Title.of(dom);
|
|
3816
3904
|
$mol_assert_equal(title.ownerDocument, doc);
|
|
3817
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="
|
|
3905
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo">foo</body></html>');
|
|
3818
3906
|
title.value('bar');
|
|
3819
3907
|
await $mol_wire_fiber.sync();
|
|
3820
|
-
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="
|
|
3908
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html><body id="foo">bar</body></html>');
|
|
3821
3909
|
},
|
|
3822
3910
|
async 'Nested bound views'($) {
|
|
3823
3911
|
class Task extends $mol_jsx_view {
|
|
@@ -3837,23 +3925,23 @@ var $;
|
|
|
3837
3925
|
class App extends $mol_jsx_view {
|
|
3838
3926
|
title(next = '') { return next; }
|
|
3839
3927
|
render() {
|
|
3840
|
-
return ($mol_jsx(List, null, this.title() && $mol_jsx(Task, { id: "
|
|
3928
|
+
return ($mol_jsx(List, null, this.title() && $mol_jsx(Task, { id: "task", title: next => this.title(next) })));
|
|
3841
3929
|
}
|
|
3842
3930
|
}
|
|
3843
3931
|
__decorate([
|
|
3844
3932
|
$mol_mem
|
|
3845
3933
|
], 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="
|
|
3934
|
+
const doc = $mol_dom_parse('<html xmlns="http://www.w3.org/1999/xhtml"><body id="root"></body></html>');
|
|
3935
|
+
const root = $.$mol_jsx_attach(doc, () => $mol_jsx(App, { "$": $, id: "root" }));
|
|
3936
|
+
$mol_assert_equal($mol_dom_serialize(doc.documentElement), '<html xmlns="http://www.w3.org/1999/xhtml"><body id="root" class="list"></body></html>');
|
|
3849
3937
|
App.of(root).title('barbar');
|
|
3850
3938
|
await $mol_wire_fiber.sync();
|
|
3851
3939
|
$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="
|
|
3940
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body id="root" class="list"><h1 id="root/task">barbar</h1></body></html>');
|
|
3853
3941
|
Task.of(root.firstElementChild).title('foofoo');
|
|
3854
3942
|
await $mol_wire_fiber.sync();
|
|
3855
3943
|
$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="
|
|
3944
|
+
$mol_assert_equal(doc.documentElement.outerHTML, '<html xmlns="http://www.w3.org/1999/xhtml"><body id="root" class="list"><h1 id="root/task">foofoo</h1></body></html>');
|
|
3857
3945
|
},
|
|
3858
3946
|
});
|
|
3859
3947
|
})($ || ($ = {}));
|