mol_data_all 1.1.356 → 1.1.359

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 title="click me" id="foo" 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}`) : $.$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
  }
@@ -938,6 +996,8 @@ var $;
938
996
  }
939
997
  if (guid)
940
998
  node.id = guid;
999
+ if ($.$mol_jsx_crumbs)
1000
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
941
1001
  return node;
942
1002
  }
943
1003
  $.$mol_jsx = $mol_jsx;
@@ -1339,6 +1399,48 @@ var $;
1339
1399
  ;
1340
1400
  "use strict";
1341
1401
  var $;
1402
+ (function ($_1) {
1403
+ $mol_test({
1404
+ 'FQN of anon function'($) {
1405
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1406
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
1407
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1408
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1409
+ },
1410
+ });
1411
+ })($ || ($ = {}));
1412
+ //mol/func/name/name.test.ts
1413
+ ;
1414
+ "use strict";
1415
+ var $;
1416
+ (function ($) {
1417
+ function $mol_func_name(func) {
1418
+ let name = func.name;
1419
+ if (name?.length > 1)
1420
+ return name;
1421
+ for (let key in this) {
1422
+ try {
1423
+ if (this[key] !== func)
1424
+ continue;
1425
+ name = key;
1426
+ Object.defineProperty(func, 'name', { value: name });
1427
+ break;
1428
+ }
1429
+ catch { }
1430
+ }
1431
+ return name;
1432
+ }
1433
+ $.$mol_func_name = $mol_func_name;
1434
+ function $mol_func_name_from(target, source) {
1435
+ Object.defineProperty(target, 'name', { value: source.name });
1436
+ return target;
1437
+ }
1438
+ $.$mol_func_name_from = $mol_func_name_from;
1439
+ })($ || ($ = {}));
1440
+ //mol/func/name/name.ts
1441
+ ;
1442
+ "use strict";
1443
+ var $;
1342
1444
  (function ($) {
1343
1445
  $mol_test({
1344
1446
  'Is number'() {