mol_wire_lib 1.0.196 → 1.0.197
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 +114 -12
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +114 -12
- package/web.test.js.map +1 -1
package/package.json
CHANGED
package/web.test.js
CHANGED
|
@@ -228,28 +228,52 @@ var $;
|
|
|
228
228
|
const Button = (props, target) => {
|
|
229
229
|
return $mol_jsx("button", { title: props.hint }, target());
|
|
230
230
|
};
|
|
231
|
-
const dom = $mol_jsx(Button, { id: "
|
|
232
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="
|
|
231
|
+
const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
|
|
232
|
+
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
|
|
233
233
|
},
|
|
234
234
|
'Nested guid generation'() {
|
|
235
235
|
const Foo = () => {
|
|
236
236
|
return $mol_jsx("div", null,
|
|
237
|
-
$mol_jsx(Bar, { id: "
|
|
238
|
-
$mol_jsx("img", { id: "
|
|
237
|
+
$mol_jsx(Bar, { id: "bar" },
|
|
238
|
+
$mol_jsx("img", { id: "icon" })));
|
|
239
239
|
};
|
|
240
240
|
const Bar = (props, icon) => {
|
|
241
|
-
return $mol_jsx("span", null,
|
|
241
|
+
return $mol_jsx("span", null,
|
|
242
|
+
icon,
|
|
243
|
+
$mol_jsx("i", { id: "label" }));
|
|
242
244
|
};
|
|
243
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
244
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
245
|
+
const dom = $mol_jsx(Foo, { id: "foo" });
|
|
246
|
+
$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>');
|
|
245
247
|
},
|
|
246
248
|
'Fail on non unique ids'() {
|
|
247
249
|
const App = () => {
|
|
248
250
|
return $mol_jsx("div", null,
|
|
249
|
-
$mol_jsx("span", { id: "
|
|
250
|
-
$mol_jsx("span", { id: "
|
|
251
|
+
$mol_jsx("span", { id: "bar" }),
|
|
252
|
+
$mol_jsx("span", { id: "bar" }));
|
|
251
253
|
};
|
|
252
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "
|
|
254
|
+
$mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
|
|
255
|
+
},
|
|
256
|
+
'Owner based guid generationn'() {
|
|
257
|
+
const Foo = () => {
|
|
258
|
+
return $mol_jsx("div", null,
|
|
259
|
+
$mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
260
|
+
};
|
|
261
|
+
const Bar = (props) => {
|
|
262
|
+
return $mol_jsx("span", null, props.icon());
|
|
263
|
+
};
|
|
264
|
+
const dom = $mol_jsx(Foo, { id: "app" });
|
|
265
|
+
$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>');
|
|
266
|
+
},
|
|
267
|
+
'Fail on same ids from different caller'() {
|
|
268
|
+
const Foo = () => {
|
|
269
|
+
return $mol_jsx("div", null,
|
|
270
|
+
$mol_jsx("img", { id: "icon" }),
|
|
271
|
+
$mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
|
|
272
|
+
};
|
|
273
|
+
const Bar = (props) => {
|
|
274
|
+
return $mol_jsx("span", null, props.icon());
|
|
275
|
+
};
|
|
276
|
+
$mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
|
|
253
277
|
},
|
|
254
278
|
});
|
|
255
279
|
})($ || ($ = {}));
|
|
@@ -259,6 +283,7 @@ var $;
|
|
|
259
283
|
var $;
|
|
260
284
|
(function ($) {
|
|
261
285
|
$.$mol_jsx_prefix = '';
|
|
286
|
+
$.$mol_jsx_crumbs = '';
|
|
262
287
|
$.$mol_jsx_booked = null;
|
|
263
288
|
$.$mol_jsx_document = {
|
|
264
289
|
getElementById: () => null,
|
|
@@ -268,16 +293,45 @@ var $;
|
|
|
268
293
|
$.$mol_jsx_frag = '';
|
|
269
294
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
270
295
|
const id = props && props.id || '';
|
|
296
|
+
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
297
|
+
const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id}`) : $.$mol_jsx_crumbs;
|
|
271
298
|
if (Elem && $.$mol_jsx_booked) {
|
|
272
299
|
if ($.$mol_jsx_booked.has(id)) {
|
|
273
|
-
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(
|
|
300
|
+
$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
|
|
274
301
|
}
|
|
275
302
|
else {
|
|
276
303
|
$.$mol_jsx_booked.add(id);
|
|
277
304
|
}
|
|
278
305
|
}
|
|
279
|
-
const guid = $.$mol_jsx_prefix + id;
|
|
280
306
|
let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
|
|
307
|
+
if ($.$mol_jsx_prefix) {
|
|
308
|
+
const prefix_ext = $.$mol_jsx_prefix;
|
|
309
|
+
const booked_ext = $.$mol_jsx_booked;
|
|
310
|
+
const crumbs_ext = $.$mol_jsx_crumbs;
|
|
311
|
+
for (const field in props) {
|
|
312
|
+
const func = props[field];
|
|
313
|
+
if (typeof func !== 'function')
|
|
314
|
+
continue;
|
|
315
|
+
const wrapper = function (...args) {
|
|
316
|
+
const prefix = $.$mol_jsx_prefix;
|
|
317
|
+
const booked = $.$mol_jsx_booked;
|
|
318
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
319
|
+
try {
|
|
320
|
+
$.$mol_jsx_prefix = prefix_ext;
|
|
321
|
+
$.$mol_jsx_booked = booked_ext;
|
|
322
|
+
$.$mol_jsx_crumbs = crumbs_ext;
|
|
323
|
+
return func.call(this, ...args);
|
|
324
|
+
}
|
|
325
|
+
finally {
|
|
326
|
+
$.$mol_jsx_prefix = prefix;
|
|
327
|
+
$.$mol_jsx_booked = booked;
|
|
328
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
$mol_func_name_from(wrapper, func);
|
|
332
|
+
props[field] = wrapper;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
281
335
|
if (typeof Elem !== 'string') {
|
|
282
336
|
if ('prototype' in Elem) {
|
|
283
337
|
const view = node && node[Elem] || new Elem;
|
|
@@ -286,6 +340,7 @@ var $;
|
|
|
286
340
|
view.childNodes = childNodes;
|
|
287
341
|
if (!view.ownerDocument)
|
|
288
342
|
view.ownerDocument = $.$mol_jsx_document;
|
|
343
|
+
view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
289
344
|
node = view.valueOf();
|
|
290
345
|
node[Elem] = view;
|
|
291
346
|
return node;
|
|
@@ -293,14 +348,17 @@ var $;
|
|
|
293
348
|
else {
|
|
294
349
|
const prefix = $.$mol_jsx_prefix;
|
|
295
350
|
const booked = $.$mol_jsx_booked;
|
|
351
|
+
const crumbs = $.$mol_jsx_crumbs;
|
|
296
352
|
try {
|
|
297
353
|
$.$mol_jsx_prefix = guid;
|
|
298
354
|
$.$mol_jsx_booked = new Set;
|
|
355
|
+
$.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
|
|
299
356
|
return Elem(props, ...childNodes);
|
|
300
357
|
}
|
|
301
358
|
finally {
|
|
302
359
|
$.$mol_jsx_prefix = prefix;
|
|
303
360
|
$.$mol_jsx_booked = booked;
|
|
361
|
+
$.$mol_jsx_crumbs = crumbs;
|
|
304
362
|
}
|
|
305
363
|
}
|
|
306
364
|
}
|
|
@@ -331,6 +389,8 @@ var $;
|
|
|
331
389
|
}
|
|
332
390
|
if (guid)
|
|
333
391
|
node.id = guid;
|
|
392
|
+
if ($.$mol_jsx_crumbs)
|
|
393
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
334
394
|
return node;
|
|
335
395
|
}
|
|
336
396
|
$.$mol_jsx = $mol_jsx;
|
|
@@ -588,6 +648,48 @@ var $;
|
|
|
588
648
|
;
|
|
589
649
|
"use strict";
|
|
590
650
|
var $;
|
|
651
|
+
(function ($_1) {
|
|
652
|
+
$mol_test({
|
|
653
|
+
'FQN of anon function'($) {
|
|
654
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
655
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
656
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
657
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
658
|
+
},
|
|
659
|
+
});
|
|
660
|
+
})($ || ($ = {}));
|
|
661
|
+
//mol/func/name/name.test.ts
|
|
662
|
+
;
|
|
663
|
+
"use strict";
|
|
664
|
+
var $;
|
|
665
|
+
(function ($) {
|
|
666
|
+
function $mol_func_name(func) {
|
|
667
|
+
let name = func.name;
|
|
668
|
+
if (name?.length > 1)
|
|
669
|
+
return name;
|
|
670
|
+
for (let key in this) {
|
|
671
|
+
try {
|
|
672
|
+
if (this[key] !== func)
|
|
673
|
+
continue;
|
|
674
|
+
name = key;
|
|
675
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
676
|
+
break;
|
|
677
|
+
}
|
|
678
|
+
catch { }
|
|
679
|
+
}
|
|
680
|
+
return name;
|
|
681
|
+
}
|
|
682
|
+
$.$mol_func_name = $mol_func_name;
|
|
683
|
+
function $mol_func_name_from(target, source) {
|
|
684
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
685
|
+
return target;
|
|
686
|
+
}
|
|
687
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
688
|
+
})($ || ($ = {}));
|
|
689
|
+
//mol/func/name/name.ts
|
|
690
|
+
;
|
|
691
|
+
"use strict";
|
|
692
|
+
var $;
|
|
591
693
|
(function ($_1) {
|
|
592
694
|
$mol_test({
|
|
593
695
|
'Collect deps'() {
|