mol_wire_lib 1.0.195 → 1.0.198
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.test.js +118 -14
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +118 -14
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -2334,28 +2334,52 @@ var $;
|
|
|
2334
2334
|
const Button = (props, target) => {
|
|
2335
2335
|
return $mol_jsx("button", { title: props.hint }, target());
|
|
2336
2336
|
};
|
|
2337
|
-
const dom = $mol_jsx(Button, { id: "
|
|
2338
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="
|
|
2337
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
2338
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
|
|
2339
2339
|
},
|
|
2340
2340
|
'Nested guid generation'() {
|
|
2341
2341
|
const Foo = () => {
|
|
2342
2342
|
return $mol_jsx("div", null,
|
|
2343
|
-
$mol_jsx(Bar, { id: "
|
|
2344
|
-
$mol_jsx("img", { id: "
|
|
2343
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
2344
|
+
$mol_jsx("img", { id: "icon" })));
|
|
2345
2345
|
};
|
|
2346
2346
|
const Bar = (props, icon) => {
|
|
2347
|
-
return $mol_jsx("span", null,
|
|
2347
|
+
return $mol_jsx("span", null,
|
|
2348
|
+
icon,
|
|
2349
|
+
$mol_jsx("i", { id: "label" }));
|
|
2348
2350
|
};
|
|
2349
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
2350
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
2351
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
2352
|
+
$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"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
|
|
2351
2353
|
},
|
|
2352
2354
|
'Fail on non unique ids'() {
|
|
2353
2355
|
const App = () => {
|
|
2354
2356
|
return $mol_jsx("div", null,
|
|
2355
|
-
$mol_jsx("span", { id: "
|
|
2356
|
-
$mol_jsx("span", { id: "
|
|
2357
|
+
$mol_jsx("span", { id: "bar" }),
|
|
2358
|
+
$mol_jsx("span", { id: "bar" }));
|
|
2357
2359
|
};
|
|
2358
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "
|
|
2360
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
2361
|
+
},
|
|
2362
|
+
'Owner based guid generationn'() {
|
|
2363
|
+
const Foo = () => {
|
|
2364
|
+
return $mol_jsx("div", null,
|
|
2365
|
+
$mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
2366
|
+
};
|
|
2367
|
+
const Bar = (props) => {
|
|
2368
|
+
return $mol_jsx("span", null, props.icon());
|
|
2369
|
+
};
|
|
2370
|
+
const dom = $mol_jsx(Foo, { id: "app" });
|
|
2371
|
+
$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>');
|
|
2372
|
+
},
|
|
2373
|
+
'Fail on same ids from different caller'() {
|
|
2374
|
+
const Foo = () => {
|
|
2375
|
+
return $mol_jsx("div", null,
|
|
2376
|
+
$mol_jsx("img", { id: "icon" }),
|
|
2377
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
2378
|
+
};
|
|
2379
|
+
const Bar = (props) => {
|
|
2380
|
+
return $mol_jsx("span", null, props.icon());
|
|
2381
|
+
};
|
|
2382
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
2359
2383
|
},
|
|
2360
2384
|
});
|
|
2361
2385
|
})($ || ($ = {}));
|
|
@@ -2365,6 +2389,7 @@ var $;
|
|
|
2365
2389
|
var $;
|
|
2366
2390
|
(function ($) {
|
|
2367
2391
|
$.$mol_jsx_prefix = '';
|
|
2392
|
+
$.$mol_jsx_crumbs = '';
|
|
2368
2393
|
$.$mol_jsx_booked = null;
|
|
2369
2394
|
$.$mol_jsx_document = {
|
|
2370
2395
|
getElementById: () => null,
|
|
@@ -2374,16 +2399,45 @@ var $;
|
|
|
2374
2399
|
$.$mol_jsx_frag = '';
|
|
2375
2400
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
2376
2401
|
const id = props && props.id || '';
|
|
2402
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
2403
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
|
|
2377
2404
|
if (Elem && $.$mol_jsx_booked) {
|
|
2378
2405
|
if ($.$mol_jsx_booked.has(id)) {
|
|
2379
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
2406
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
2380
2407
|
}
|
|
2381
2408
|
else {
|
|
2382
2409
|
$.$mol_jsx_booked.add(id);
|
|
2383
2410
|
}
|
|
2384
2411
|
}
|
|
2385
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
2386
2412
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
2413
|
+
if ($.$mol_jsx_prefix) {
|
|
2414
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
2415
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
2416
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
2417
|
+
for (const field in props) {
|
|
2418
|
+
const func = props[field];
|
|
2419
|
+
if (typeof func !== 'function')
|
|
2420
|
+
continue;
|
|
2421
|
+
const wrapper = function (...args) {
|
|
2422
|
+
const prefix = $.$mol_jsx_prefix;
|
|
2423
|
+
const booked = $.$mol_jsx_booked;
|
|
2424
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
2425
|
+
try {
|
|
2426
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
2427
|
+
$.$mol_jsx_booked = booked_ext;
|
|
2428
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
2429
|
+
return func.call(this, ...args);
|
|
2430
|
+
}
|
|
2431
|
+
finally {
|
|
2432
|
+
$.$mol_jsx_prefix = prefix;
|
|
2433
|
+
$.$mol_jsx_booked = booked;
|
|
2434
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
2435
|
+
}
|
|
2436
|
+
};
|
|
2437
|
+
$mol_func_name_from(wrapper, func);
|
|
2438
|
+
props[field] = wrapper;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2387
2441
|
if (typeof Elem !== 'string') {
|
|
2388
2442
|
if ('prototype' in Elem) {
|
|
2389
2443
|
const view = node && node[Elem] || new Elem;
|
|
@@ -2392,6 +2446,7 @@ var $;
|
|
|
2392
2446
|
view.childNodes = childNodes;
|
|
2393
2447
|
if (!view.ownerDocument)
|
|
2394
2448
|
view.ownerDocument = $.$mol_jsx_document;
|
|
2449
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
2395
2450
|
node = view.valueOf();
|
|
2396
2451
|
node[Elem] = view;
|
|
2397
2452
|
return node;
|
|
@@ -2399,14 +2454,17 @@ var $;
|
|
|
2399
2454
|
else {
|
|
2400
2455
|
const prefix = $.$mol_jsx_prefix;
|
|
2401
2456
|
const booked = $.$mol_jsx_booked;
|
|
2457
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
2402
2458
|
try {
|
|
2403
2459
|
$.$mol_jsx_prefix = guid;
|
|
2404
2460
|
$.$mol_jsx_booked = new Set;
|
|
2461
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
2405
2462
|
return Elem(props, ...childNodes);
|
|
2406
2463
|
}
|
|
2407
2464
|
finally {
|
|
2408
2465
|
$.$mol_jsx_prefix = prefix;
|
|
2409
2466
|
$.$mol_jsx_booked = booked;
|
|
2467
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
2410
2468
|
}
|
|
2411
2469
|
}
|
|
2412
2470
|
}
|
|
@@ -2418,7 +2476,11 @@ var $;
|
|
|
2418
2476
|
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
2419
2477
|
if (!Elem)
|
|
2420
2478
|
return node;
|
|
2479
|
+
if (guid)
|
|
2480
|
+
node.id = guid;
|
|
2421
2481
|
for (const key in props) {
|
|
2482
|
+
if (key === 'id')
|
|
2483
|
+
continue;
|
|
2422
2484
|
if (typeof props[key] === 'string') {
|
|
2423
2485
|
;
|
|
2424
2486
|
node.setAttribute(key, props[key]);
|
|
@@ -2435,8 +2497,8 @@ var $;
|
|
|
2435
2497
|
node[key] = props[key];
|
|
2436
2498
|
}
|
|
2437
2499
|
}
|
|
2438
|
-
if (
|
|
2439
|
-
node.
|
|
2500
|
+
if ($.$mol_jsx_crumbs)
|
|
2501
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
2440
2502
|
return node;
|
|
2441
2503
|
}
|
|
2442
2504
|
$.$mol_jsx = $mol_jsx;
|
|
@@ -2803,6 +2865,48 @@ var $;
|
|
|
2803
2865
|
;
|
|
2804
2866
|
"use strict";
|
|
2805
2867
|
var $;
|
|
2868
|
+
(function ($_1) {
|
|
2869
|
+
$mol_test({
|
|
2870
|
+
'FQN of anon function'($) {
|
|
2871
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
2872
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
2873
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
2874
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
2875
|
+
},
|
|
2876
|
+
});
|
|
2877
|
+
})($ || ($ = {}));
|
|
2878
|
+
//mol/func/name/name.test.ts
|
|
2879
|
+
;
|
|
2880
|
+
"use strict";
|
|
2881
|
+
var $;
|
|
2882
|
+
(function ($) {
|
|
2883
|
+
function $mol_func_name(func) {
|
|
2884
|
+
let name = func.name;
|
|
2885
|
+
if (name?.length > 1)
|
|
2886
|
+
return name;
|
|
2887
|
+
for (let key in this) {
|
|
2888
|
+
try {
|
|
2889
|
+
if (this[key] !== func)
|
|
2890
|
+
continue;
|
|
2891
|
+
name = key;
|
|
2892
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
2893
|
+
break;
|
|
2894
|
+
}
|
|
2895
|
+
catch { }
|
|
2896
|
+
}
|
|
2897
|
+
return name;
|
|
2898
|
+
}
|
|
2899
|
+
$.$mol_func_name = $mol_func_name;
|
|
2900
|
+
function $mol_func_name_from(target, source) {
|
|
2901
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
2902
|
+
return target;
|
|
2903
|
+
}
|
|
2904
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
2905
|
+
})($ || ($ = {}));
|
|
2906
|
+
//mol/func/name/name.ts
|
|
2907
|
+
;
|
|
2908
|
+
"use strict";
|
|
2909
|
+
var $;
|
|
2806
2910
|
(function ($_1) {
|
|
2807
2911
|
$mol_test({
|
|
2808
2912
|
'Collect deps'() {
|