mol_db 0.0.307 → 0.0.310

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
@@ -1176,28 +1176,52 @@ var $;
1176
1176
  const Button = (props, target) => {
1177
1177
  return $mol_jsx("button", { title: props.hint }, target());
1178
1178
  };
1179
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
1180
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
1179
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
1180
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
1181
1181
  },
1182
1182
  'Nested guid generation'() {
1183
1183
  const Foo = () => {
1184
1184
  return $mol_jsx("div", null,
1185
- $mol_jsx(Bar, { id: "/bar" },
1186
- $mol_jsx("img", { id: "/icon" })));
1185
+ $mol_jsx(Bar, { id: "bar" },
1186
+ $mol_jsx("img", { id: "icon" })));
1187
1187
  };
1188
1188
  const Bar = (props, icon) => {
1189
- return $mol_jsx("span", null, icon);
1189
+ return $mol_jsx("span", null,
1190
+ icon,
1191
+ $mol_jsx("i", { id: "label" }));
1190
1192
  };
1191
- const dom = $mol_jsx(Foo, { id: "/foo" });
1192
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
1193
+ const dom = $mol_jsx(Foo, { id: "foo" });
1194
+ $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>');
1193
1195
  },
1194
1196
  'Fail on non unique ids'() {
1195
1197
  const App = () => {
1196
1198
  return $mol_jsx("div", null,
1197
- $mol_jsx("span", { id: "/bar" }),
1198
- $mol_jsx("span", { id: "/bar" }));
1199
+ $mol_jsx("span", { id: "bar" }),
1200
+ $mol_jsx("span", { id: "bar" }));
1199
1201
  };
1200
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
1202
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
1203
+ },
1204
+ 'Owner based guid generationn'() {
1205
+ const Foo = () => {
1206
+ return $mol_jsx("div", null,
1207
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
1208
+ };
1209
+ const Bar = (props) => {
1210
+ return $mol_jsx("span", null, props.icon());
1211
+ };
1212
+ const dom = $mol_jsx(Foo, { id: "app" });
1213
+ $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>');
1214
+ },
1215
+ 'Fail on same ids from different caller'() {
1216
+ const Foo = () => {
1217
+ return $mol_jsx("div", null,
1218
+ $mol_jsx("img", { id: "icon" }),
1219
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
1220
+ };
1221
+ const Bar = (props) => {
1222
+ return $mol_jsx("span", null, props.icon());
1223
+ };
1224
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
1201
1225
  },
1202
1226
  });
1203
1227
  })($ || ($ = {}));
@@ -1207,6 +1231,7 @@ var $;
1207
1231
  var $;
1208
1232
  (function ($) {
1209
1233
  $.$mol_jsx_prefix = '';
1234
+ $.$mol_jsx_crumbs = '';
1210
1235
  $.$mol_jsx_booked = null;
1211
1236
  $.$mol_jsx_document = {
1212
1237
  getElementById: () => null,
@@ -1216,16 +1241,45 @@ var $;
1216
1241
  $.$mol_jsx_frag = '';
1217
1242
  function $mol_jsx(Elem, props, ...childNodes) {
1218
1243
  const id = props && props.id || '';
1244
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1245
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id}`) : $.$mol_jsx_crumbs;
1219
1246
  if (Elem && $.$mol_jsx_booked) {
1220
1247
  if ($.$mol_jsx_booked.has(id)) {
1221
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
1248
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1222
1249
  }
1223
1250
  else {
1224
1251
  $.$mol_jsx_booked.add(id);
1225
1252
  }
1226
1253
  }
1227
- const guid = $.$mol_jsx_prefix + id;
1228
1254
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
1255
+ if ($.$mol_jsx_prefix) {
1256
+ const prefix_ext = $.$mol_jsx_prefix;
1257
+ const booked_ext = $.$mol_jsx_booked;
1258
+ const crumbs_ext = $.$mol_jsx_crumbs;
1259
+ for (const field in props) {
1260
+ const func = props[field];
1261
+ if (typeof func !== 'function')
1262
+ continue;
1263
+ const wrapper = function (...args) {
1264
+ const prefix = $.$mol_jsx_prefix;
1265
+ const booked = $.$mol_jsx_booked;
1266
+ const crumbs = $.$mol_jsx_crumbs;
1267
+ try {
1268
+ $.$mol_jsx_prefix = prefix_ext;
1269
+ $.$mol_jsx_booked = booked_ext;
1270
+ $.$mol_jsx_crumbs = crumbs_ext;
1271
+ return func.call(this, ...args);
1272
+ }
1273
+ finally {
1274
+ $.$mol_jsx_prefix = prefix;
1275
+ $.$mol_jsx_booked = booked;
1276
+ $.$mol_jsx_crumbs = crumbs;
1277
+ }
1278
+ };
1279
+ $mol_func_name_from(wrapper, func);
1280
+ props[field] = wrapper;
1281
+ }
1282
+ }
1229
1283
  if (typeof Elem !== 'string') {
1230
1284
  if ('prototype' in Elem) {
1231
1285
  const view = node && node[Elem] || new Elem;
@@ -1234,6 +1288,7 @@ var $;
1234
1288
  view.childNodes = childNodes;
1235
1289
  if (!view.ownerDocument)
1236
1290
  view.ownerDocument = $.$mol_jsx_document;
1291
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1237
1292
  node = view.valueOf();
1238
1293
  node[Elem] = view;
1239
1294
  return node;
@@ -1241,14 +1296,17 @@ var $;
1241
1296
  else {
1242
1297
  const prefix = $.$mol_jsx_prefix;
1243
1298
  const booked = $.$mol_jsx_booked;
1299
+ const crumbs = $.$mol_jsx_crumbs;
1244
1300
  try {
1245
1301
  $.$mol_jsx_prefix = guid;
1246
1302
  $.$mol_jsx_booked = new Set;
1303
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1247
1304
  return Elem(props, ...childNodes);
1248
1305
  }
1249
1306
  finally {
1250
1307
  $.$mol_jsx_prefix = prefix;
1251
1308
  $.$mol_jsx_booked = booked;
1309
+ $.$mol_jsx_crumbs = crumbs;
1252
1310
  }
1253
1311
  }
1254
1312
  }
@@ -1279,6 +1337,8 @@ var $;
1279
1337
  }
1280
1338
  if (guid)
1281
1339
  node.id = guid;
1340
+ if ($.$mol_jsx_crumbs)
1341
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1282
1342
  return node;
1283
1343
  }
1284
1344
  $.$mol_jsx = $mol_jsx;
@@ -1710,6 +1770,48 @@ var $;
1710
1770
  ;
1711
1771
  "use strict";
1712
1772
  var $;
1773
+ (function ($_1) {
1774
+ $mol_test({
1775
+ 'FQN of anon function'($) {
1776
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1777
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
1778
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1779
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1780
+ },
1781
+ });
1782
+ })($ || ($ = {}));
1783
+ //mol/func/name/name.test.ts
1784
+ ;
1785
+ "use strict";
1786
+ var $;
1787
+ (function ($) {
1788
+ function $mol_func_name(func) {
1789
+ let name = func.name;
1790
+ if (name?.length > 1)
1791
+ return name;
1792
+ for (let key in this) {
1793
+ try {
1794
+ if (this[key] !== func)
1795
+ continue;
1796
+ name = key;
1797
+ Object.defineProperty(func, 'name', { value: name });
1798
+ break;
1799
+ }
1800
+ catch { }
1801
+ }
1802
+ return name;
1803
+ }
1804
+ $.$mol_func_name = $mol_func_name;
1805
+ function $mol_func_name_from(target, source) {
1806
+ Object.defineProperty(target, 'name', { value: source.name });
1807
+ return target;
1808
+ }
1809
+ $.$mol_func_name_from = $mol_func_name_from;
1810
+ })($ || ($ = {}));
1811
+ //mol/func/name/name.ts
1812
+ ;
1813
+ "use strict";
1814
+ var $;
1713
1815
  (function ($_1) {
1714
1816
  $mol_test({
1715
1817
  'tree parsing'() {