mol_key 0.0.130 → 0.0.131

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 CHANGED
@@ -545,6 +545,48 @@ var $;
545
545
  ;
546
546
  "use strict";
547
547
  var $;
548
+ (function ($_1) {
549
+ $mol_test({
550
+ 'FQN of anon function'($) {
551
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
552
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
553
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
554
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
555
+ },
556
+ });
557
+ })($ || ($ = {}));
558
+ //mol/func/name/name.test.ts
559
+ ;
560
+ "use strict";
561
+ var $;
562
+ (function ($) {
563
+ function $mol_func_name(func) {
564
+ let name = func.name;
565
+ if (name?.length > 1)
566
+ return name;
567
+ for (let key in this) {
568
+ try {
569
+ if (this[key] !== func)
570
+ continue;
571
+ name = key;
572
+ Object.defineProperty(func, 'name', { value: name });
573
+ break;
574
+ }
575
+ catch { }
576
+ }
577
+ return name;
578
+ }
579
+ $.$mol_func_name = $mol_func_name;
580
+ function $mol_func_name_from(target, source) {
581
+ Object.defineProperty(target, 'name', { value: source.name });
582
+ return target;
583
+ }
584
+ $.$mol_func_name_from = $mol_func_name_from;
585
+ })($ || ($ = {}));
586
+ //mol/func/name/name.ts
587
+ ;
588
+ "use strict";
589
+ var $;
548
590
  (function ($) {
549
591
  function $mol_dom_render_children(el, childNodes) {
550
592
  const node_set = new Set(childNodes);
@@ -1264,28 +1306,52 @@ var $;
1264
1306
  const Button = (props, target) => {
1265
1307
  return $mol_jsx("button", { title: props.hint }, target());
1266
1308
  };
1267
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
1268
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
1309
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
1310
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
1269
1311
  },
1270
1312
  'Nested guid generation'() {
1271
1313
  const Foo = () => {
1272
1314
  return $mol_jsx("div", null,
1273
- $mol_jsx(Bar, { id: "/bar" },
1274
- $mol_jsx("img", { id: "/icon" })));
1315
+ $mol_jsx(Bar, { id: "bar" },
1316
+ $mol_jsx("img", { id: "icon" })));
1275
1317
  };
1276
1318
  const Bar = (props, icon) => {
1277
- return $mol_jsx("span", null, icon);
1319
+ return $mol_jsx("span", null,
1320
+ icon,
1321
+ $mol_jsx("i", { id: "label" }));
1278
1322
  };
1279
- const dom = $mol_jsx(Foo, { id: "/foo" });
1280
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
1323
+ const dom = $mol_jsx(Foo, { id: "foo" });
1324
+ $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>');
1281
1325
  },
1282
1326
  'Fail on non unique ids'() {
1283
1327
  const App = () => {
1284
1328
  return $mol_jsx("div", null,
1285
- $mol_jsx("span", { id: "/bar" }),
1286
- $mol_jsx("span", { id: "/bar" }));
1329
+ $mol_jsx("span", { id: "bar" }),
1330
+ $mol_jsx("span", { id: "bar" }));
1331
+ };
1332
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
1333
+ },
1334
+ 'Owner based guid generationn'() {
1335
+ const Foo = () => {
1336
+ return $mol_jsx("div", null,
1337
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
1338
+ };
1339
+ const Bar = (props) => {
1340
+ return $mol_jsx("span", null, props.icon());
1341
+ };
1342
+ const dom = $mol_jsx(Foo, { id: "app" });
1343
+ $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>');
1344
+ },
1345
+ 'Fail on same ids from different caller'() {
1346
+ const Foo = () => {
1347
+ return $mol_jsx("div", null,
1348
+ $mol_jsx("img", { id: "icon" }),
1349
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
1350
+ };
1351
+ const Bar = (props) => {
1352
+ return $mol_jsx("span", null, props.icon());
1287
1353
  };
1288
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
1354
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
1289
1355
  },
1290
1356
  });
1291
1357
  })($ || ($ = {}));
@@ -1295,6 +1361,7 @@ var $;
1295
1361
  var $;
1296
1362
  (function ($) {
1297
1363
  $.$mol_jsx_prefix = '';
1364
+ $.$mol_jsx_crumbs = '';
1298
1365
  $.$mol_jsx_booked = null;
1299
1366
  $.$mol_jsx_document = {
1300
1367
  getElementById: () => null,
@@ -1304,16 +1371,45 @@ var $;
1304
1371
  $.$mol_jsx_frag = '';
1305
1372
  function $mol_jsx(Elem, props, ...childNodes) {
1306
1373
  const id = props && props.id || '';
1374
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1375
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id}`) : $.$mol_jsx_crumbs;
1307
1376
  if (Elem && $.$mol_jsx_booked) {
1308
1377
  if ($.$mol_jsx_booked.has(id)) {
1309
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
1378
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1310
1379
  }
1311
1380
  else {
1312
1381
  $.$mol_jsx_booked.add(id);
1313
1382
  }
1314
1383
  }
1315
- const guid = $.$mol_jsx_prefix + id;
1316
1384
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
1385
+ if ($.$mol_jsx_prefix) {
1386
+ const prefix_ext = $.$mol_jsx_prefix;
1387
+ const booked_ext = $.$mol_jsx_booked;
1388
+ const crumbs_ext = $.$mol_jsx_crumbs;
1389
+ for (const field in props) {
1390
+ const func = props[field];
1391
+ if (typeof func !== 'function')
1392
+ continue;
1393
+ const wrapper = function (...args) {
1394
+ const prefix = $.$mol_jsx_prefix;
1395
+ const booked = $.$mol_jsx_booked;
1396
+ const crumbs = $.$mol_jsx_crumbs;
1397
+ try {
1398
+ $.$mol_jsx_prefix = prefix_ext;
1399
+ $.$mol_jsx_booked = booked_ext;
1400
+ $.$mol_jsx_crumbs = crumbs_ext;
1401
+ return func.call(this, ...args);
1402
+ }
1403
+ finally {
1404
+ $.$mol_jsx_prefix = prefix;
1405
+ $.$mol_jsx_booked = booked;
1406
+ $.$mol_jsx_crumbs = crumbs;
1407
+ }
1408
+ };
1409
+ $mol_func_name_from(wrapper, func);
1410
+ props[field] = wrapper;
1411
+ }
1412
+ }
1317
1413
  if (typeof Elem !== 'string') {
1318
1414
  if ('prototype' in Elem) {
1319
1415
  const view = node && node[Elem] || new Elem;
@@ -1322,6 +1418,7 @@ var $;
1322
1418
  view.childNodes = childNodes;
1323
1419
  if (!view.ownerDocument)
1324
1420
  view.ownerDocument = $.$mol_jsx_document;
1421
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1325
1422
  node = view.valueOf();
1326
1423
  node[Elem] = view;
1327
1424
  return node;
@@ -1329,14 +1426,17 @@ var $;
1329
1426
  else {
1330
1427
  const prefix = $.$mol_jsx_prefix;
1331
1428
  const booked = $.$mol_jsx_booked;
1429
+ const crumbs = $.$mol_jsx_crumbs;
1332
1430
  try {
1333
1431
  $.$mol_jsx_prefix = guid;
1334
1432
  $.$mol_jsx_booked = new Set;
1433
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1335
1434
  return Elem(props, ...childNodes);
1336
1435
  }
1337
1436
  finally {
1338
1437
  $.$mol_jsx_prefix = prefix;
1339
1438
  $.$mol_jsx_booked = booked;
1439
+ $.$mol_jsx_crumbs = crumbs;
1340
1440
  }
1341
1441
  }
1342
1442
  }
@@ -1367,6 +1467,8 @@ var $;
1367
1467
  }
1368
1468
  if (guid)
1369
1469
  node.id = guid;
1470
+ if ($.$mol_jsx_crumbs)
1471
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1370
1472
  return node;
1371
1473
  }
1372
1474
  $.$mol_jsx = $mol_jsx;