mol_data_all 1.1.358 → 1.1.361

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
@@ -835,28 +835,52 @@ var $;
835
835
  const Button = (props, target) => {
836
836
  return $mol_jsx("button", { title: props.hint }, target());
837
837
  };
838
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
839
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
838
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
839
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
840
840
  },
841
841
  'Nested guid generation'() {
842
842
  const Foo = () => {
843
843
  return $mol_jsx("div", null,
844
- $mol_jsx(Bar, { id: "/bar" },
845
- $mol_jsx("img", { id: "/icon" })));
844
+ $mol_jsx(Bar, { id: "bar" },
845
+ $mol_jsx("img", { id: "icon" })));
846
846
  };
847
847
  const Bar = (props, icon) => {
848
- return $mol_jsx("span", null, icon);
848
+ return $mol_jsx("span", null,
849
+ icon,
850
+ $mol_jsx("i", { id: "label" }));
849
851
  };
850
- const dom = $mol_jsx(Foo, { id: "/foo" });
851
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
852
+ const dom = $mol_jsx(Foo, { id: "foo" });
853
+ $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>');
852
854
  },
853
855
  'Fail on non unique ids'() {
854
856
  const App = () => {
855
857
  return $mol_jsx("div", null,
856
- $mol_jsx("span", { id: "/bar" }),
857
- $mol_jsx("span", { id: "/bar" }));
858
+ $mol_jsx("span", { id: "bar" }),
859
+ $mol_jsx("span", { id: "bar" }));
858
860
  };
859
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
861
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
862
+ },
863
+ 'Owner based guid generationn'() {
864
+ const Foo = () => {
865
+ return $mol_jsx("div", null,
866
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
867
+ };
868
+ const Bar = (props) => {
869
+ return $mol_jsx("span", null, props.icon());
870
+ };
871
+ const dom = $mol_jsx(Foo, { id: "app" });
872
+ $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>');
873
+ },
874
+ 'Fail on same ids from different caller'() {
875
+ const Foo = () => {
876
+ return $mol_jsx("div", null,
877
+ $mol_jsx("img", { id: "icon" }),
878
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
879
+ };
880
+ const Bar = (props) => {
881
+ return $mol_jsx("span", null, props.icon());
882
+ };
883
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
860
884
  },
861
885
  });
862
886
  })($ || ($ = {}));
@@ -866,6 +890,7 @@ var $;
866
890
  var $;
867
891
  (function ($) {
868
892
  $.$mol_jsx_prefix = '';
893
+ $.$mol_jsx_crumbs = '';
869
894
  $.$mol_jsx_booked = null;
870
895
  $.$mol_jsx_document = {
871
896
  getElementById: () => null,
@@ -875,16 +900,45 @@ var $;
875
900
  $.$mol_jsx_frag = '';
876
901
  function $mol_jsx(Elem, props, ...childNodes) {
877
902
  const id = props && props.id || '';
903
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
904
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
878
905
  if (Elem && $.$mol_jsx_booked) {
879
906
  if ($.$mol_jsx_booked.has(id)) {
880
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
907
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
881
908
  }
882
909
  else {
883
910
  $.$mol_jsx_booked.add(id);
884
911
  }
885
912
  }
886
- const guid = $.$mol_jsx_prefix + id;
887
913
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
914
+ if ($.$mol_jsx_prefix) {
915
+ const prefix_ext = $.$mol_jsx_prefix;
916
+ const booked_ext = $.$mol_jsx_booked;
917
+ const crumbs_ext = $.$mol_jsx_crumbs;
918
+ for (const field in props) {
919
+ const func = props[field];
920
+ if (typeof func !== 'function')
921
+ continue;
922
+ const wrapper = function (...args) {
923
+ const prefix = $.$mol_jsx_prefix;
924
+ const booked = $.$mol_jsx_booked;
925
+ const crumbs = $.$mol_jsx_crumbs;
926
+ try {
927
+ $.$mol_jsx_prefix = prefix_ext;
928
+ $.$mol_jsx_booked = booked_ext;
929
+ $.$mol_jsx_crumbs = crumbs_ext;
930
+ return func.call(this, ...args);
931
+ }
932
+ finally {
933
+ $.$mol_jsx_prefix = prefix;
934
+ $.$mol_jsx_booked = booked;
935
+ $.$mol_jsx_crumbs = crumbs;
936
+ }
937
+ };
938
+ $mol_func_name_from(wrapper, func);
939
+ props[field] = wrapper;
940
+ }
941
+ }
888
942
  if (typeof Elem !== 'string') {
889
943
  if ('prototype' in Elem) {
890
944
  const view = node && node[Elem] || new Elem;
@@ -893,6 +947,7 @@ var $;
893
947
  view.childNodes = childNodes;
894
948
  if (!view.ownerDocument)
895
949
  view.ownerDocument = $.$mol_jsx_document;
950
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
896
951
  node = view.valueOf();
897
952
  node[Elem] = view;
898
953
  return node;
@@ -900,14 +955,17 @@ var $;
900
955
  else {
901
956
  const prefix = $.$mol_jsx_prefix;
902
957
  const booked = $.$mol_jsx_booked;
958
+ const crumbs = $.$mol_jsx_crumbs;
903
959
  try {
904
960
  $.$mol_jsx_prefix = guid;
905
961
  $.$mol_jsx_booked = new Set;
962
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
906
963
  return Elem(props, ...childNodes);
907
964
  }
908
965
  finally {
909
966
  $.$mol_jsx_prefix = prefix;
910
967
  $.$mol_jsx_booked = booked;
968
+ $.$mol_jsx_crumbs = crumbs;
911
969
  }
912
970
  }
913
971
  }
@@ -919,7 +977,11 @@ var $;
919
977
  $mol_dom_render_children(node, [].concat(...childNodes));
920
978
  if (!Elem)
921
979
  return node;
980
+ if (guid)
981
+ node.id = guid;
922
982
  for (const key in props) {
983
+ if (key === 'id')
984
+ continue;
923
985
  if (typeof props[key] === 'string') {
924
986
  ;
925
987
  node.setAttribute(key, props[key]);
@@ -936,8 +998,8 @@ var $;
936
998
  node[key] = props[key];
937
999
  }
938
1000
  }
939
- if (guid)
940
- node.id = guid;
1001
+ if ($.$mol_jsx_crumbs)
1002
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
941
1003
  return node;
942
1004
  }
943
1005
  $.$mol_jsx = $mol_jsx;
@@ -1339,6 +1401,48 @@ var $;
1339
1401
  ;
1340
1402
  "use strict";
1341
1403
  var $;
1404
+ (function ($_1) {
1405
+ $mol_test({
1406
+ 'FQN of anon function'($) {
1407
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1408
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
1409
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1410
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1411
+ },
1412
+ });
1413
+ })($ || ($ = {}));
1414
+ //mol/func/name/name.test.ts
1415
+ ;
1416
+ "use strict";
1417
+ var $;
1418
+ (function ($) {
1419
+ function $mol_func_name(func) {
1420
+ let name = func.name;
1421
+ if (name?.length > 1)
1422
+ return name;
1423
+ for (let key in this) {
1424
+ try {
1425
+ if (this[key] !== func)
1426
+ continue;
1427
+ name = key;
1428
+ Object.defineProperty(func, 'name', { value: name });
1429
+ break;
1430
+ }
1431
+ catch { }
1432
+ }
1433
+ return name;
1434
+ }
1435
+ $.$mol_func_name = $mol_func_name;
1436
+ function $mol_func_name_from(target, source) {
1437
+ Object.defineProperty(target, 'name', { value: source.name });
1438
+ return target;
1439
+ }
1440
+ $.$mol_func_name_from = $mol_func_name_from;
1441
+ })($ || ($ = {}));
1442
+ //mol/func/name/name.ts
1443
+ ;
1444
+ "use strict";
1445
+ var $;
1342
1446
  (function ($) {
1343
1447
  $mol_test({
1344
1448
  'Is number'() {