mol_data_all 1.1.357 → 1.1.360

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mol_data_all",
3
- "version": "1.1.357",
3
+ "version": "1.1.360",
4
4
  "main": "node.js",
5
5
  "module": "node.esm.js",
6
6
  "browser": "web.js",
package/web.test.js CHANGED
@@ -225,28 +225,52 @@ var $;
225
225
  const Button = (props, target) => {
226
226
  return $mol_jsx("button", { title: props.hint }, target());
227
227
  };
228
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
229
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
228
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
229
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
230
230
  },
231
231
  'Nested guid generation'() {
232
232
  const Foo = () => {
233
233
  return $mol_jsx("div", null,
234
- $mol_jsx(Bar, { id: "/bar" },
235
- $mol_jsx("img", { id: "/icon" })));
234
+ $mol_jsx(Bar, { id: "bar" },
235
+ $mol_jsx("img", { id: "icon" })));
236
236
  };
237
237
  const Bar = (props, icon) => {
238
- return $mol_jsx("span", null, icon);
238
+ return $mol_jsx("span", null,
239
+ icon,
240
+ $mol_jsx("i", { id: "label" }));
239
241
  };
240
- const dom = $mol_jsx(Foo, { id: "/foo" });
241
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
242
+ const dom = $mol_jsx(Foo, { id: "foo" });
243
+ $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>');
242
244
  },
243
245
  'Fail on non unique ids'() {
244
246
  const App = () => {
245
247
  return $mol_jsx("div", null,
246
- $mol_jsx("span", { id: "/bar" }),
247
- $mol_jsx("span", { id: "/bar" }));
248
+ $mol_jsx("span", { id: "bar" }),
249
+ $mol_jsx("span", { id: "bar" }));
248
250
  };
249
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
251
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
252
+ },
253
+ 'Owner based guid generationn'() {
254
+ const Foo = () => {
255
+ return $mol_jsx("div", null,
256
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
257
+ };
258
+ const Bar = (props) => {
259
+ return $mol_jsx("span", null, props.icon());
260
+ };
261
+ const dom = $mol_jsx(Foo, { id: "app" });
262
+ $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>');
263
+ },
264
+ 'Fail on same ids from different caller'() {
265
+ const Foo = () => {
266
+ return $mol_jsx("div", null,
267
+ $mol_jsx("img", { id: "icon" }),
268
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
269
+ };
270
+ const Bar = (props) => {
271
+ return $mol_jsx("span", null, props.icon());
272
+ };
273
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
250
274
  },
251
275
  });
252
276
  })($ || ($ = {}));
@@ -256,6 +280,7 @@ var $;
256
280
  var $;
257
281
  (function ($) {
258
282
  $.$mol_jsx_prefix = '';
283
+ $.$mol_jsx_crumbs = '';
259
284
  $.$mol_jsx_booked = null;
260
285
  $.$mol_jsx_document = {
261
286
  getElementById: () => null,
@@ -265,16 +290,45 @@ var $;
265
290
  $.$mol_jsx_frag = '';
266
291
  function $mol_jsx(Elem, props, ...childNodes) {
267
292
  const id = props && props.id || '';
293
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
294
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
268
295
  if (Elem && $.$mol_jsx_booked) {
269
296
  if ($.$mol_jsx_booked.has(id)) {
270
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
297
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
271
298
  }
272
299
  else {
273
300
  $.$mol_jsx_booked.add(id);
274
301
  }
275
302
  }
276
- const guid = $.$mol_jsx_prefix + id;
277
303
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
304
+ if ($.$mol_jsx_prefix) {
305
+ const prefix_ext = $.$mol_jsx_prefix;
306
+ const booked_ext = $.$mol_jsx_booked;
307
+ const crumbs_ext = $.$mol_jsx_crumbs;
308
+ for (const field in props) {
309
+ const func = props[field];
310
+ if (typeof func !== 'function')
311
+ continue;
312
+ const wrapper = function (...args) {
313
+ const prefix = $.$mol_jsx_prefix;
314
+ const booked = $.$mol_jsx_booked;
315
+ const crumbs = $.$mol_jsx_crumbs;
316
+ try {
317
+ $.$mol_jsx_prefix = prefix_ext;
318
+ $.$mol_jsx_booked = booked_ext;
319
+ $.$mol_jsx_crumbs = crumbs_ext;
320
+ return func.call(this, ...args);
321
+ }
322
+ finally {
323
+ $.$mol_jsx_prefix = prefix;
324
+ $.$mol_jsx_booked = booked;
325
+ $.$mol_jsx_crumbs = crumbs;
326
+ }
327
+ };
328
+ $mol_func_name_from(wrapper, func);
329
+ props[field] = wrapper;
330
+ }
331
+ }
278
332
  if (typeof Elem !== 'string') {
279
333
  if ('prototype' in Elem) {
280
334
  const view = node && node[Elem] || new Elem;
@@ -283,6 +337,7 @@ var $;
283
337
  view.childNodes = childNodes;
284
338
  if (!view.ownerDocument)
285
339
  view.ownerDocument = $.$mol_jsx_document;
340
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
286
341
  node = view.valueOf();
287
342
  node[Elem] = view;
288
343
  return node;
@@ -290,14 +345,17 @@ var $;
290
345
  else {
291
346
  const prefix = $.$mol_jsx_prefix;
292
347
  const booked = $.$mol_jsx_booked;
348
+ const crumbs = $.$mol_jsx_crumbs;
293
349
  try {
294
350
  $.$mol_jsx_prefix = guid;
295
351
  $.$mol_jsx_booked = new Set;
352
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
296
353
  return Elem(props, ...childNodes);
297
354
  }
298
355
  finally {
299
356
  $.$mol_jsx_prefix = prefix;
300
357
  $.$mol_jsx_booked = booked;
358
+ $.$mol_jsx_crumbs = crumbs;
301
359
  }
302
360
  }
303
361
  }
@@ -309,7 +367,11 @@ var $;
309
367
  $mol_dom_render_children(node, [].concat(...childNodes));
310
368
  if (!Elem)
311
369
  return node;
370
+ if (guid)
371
+ node.id = guid;
312
372
  for (const key in props) {
373
+ if (key === 'id')
374
+ continue;
313
375
  if (typeof props[key] === 'string') {
314
376
  ;
315
377
  node.setAttribute(key, props[key]);
@@ -326,8 +388,8 @@ var $;
326
388
  node[key] = props[key];
327
389
  }
328
390
  }
329
- if (guid)
330
- node.id = guid;
391
+ if ($.$mol_jsx_crumbs)
392
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
331
393
  return node;
332
394
  }
333
395
  $.$mol_jsx = $mol_jsx;
@@ -729,6 +791,48 @@ var $;
729
791
  ;
730
792
  "use strict";
731
793
  var $;
794
+ (function ($_1) {
795
+ $mol_test({
796
+ 'FQN of anon function'($) {
797
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
798
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
799
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
800
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
801
+ },
802
+ });
803
+ })($ || ($ = {}));
804
+ //mol/func/name/name.test.ts
805
+ ;
806
+ "use strict";
807
+ var $;
808
+ (function ($) {
809
+ function $mol_func_name(func) {
810
+ let name = func.name;
811
+ if (name?.length > 1)
812
+ return name;
813
+ for (let key in this) {
814
+ try {
815
+ if (this[key] !== func)
816
+ continue;
817
+ name = key;
818
+ Object.defineProperty(func, 'name', { value: name });
819
+ break;
820
+ }
821
+ catch { }
822
+ }
823
+ return name;
824
+ }
825
+ $.$mol_func_name = $mol_func_name;
826
+ function $mol_func_name_from(target, source) {
827
+ Object.defineProperty(target, 'name', { value: source.name });
828
+ return target;
829
+ }
830
+ $.$mol_func_name_from = $mol_func_name_from;
831
+ })($ || ($ = {}));
832
+ //mol/func/name/name.ts
833
+ ;
834
+ "use strict";
835
+ var $;
732
836
  (function ($) {
733
837
  $mol_test({
734
838
  'Is number'() {