mol_plot_all 1.2.257 → 1.2.260

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_plot_all",
3
- "version": "1.2.257",
3
+ "version": "1.2.260",
4
4
  "main": "node.js",
5
5
  "module": "node.esm.js",
6
6
  "browser": "web.js",
package/web.test.js CHANGED
@@ -160,28 +160,52 @@ var $;
160
160
  const Button = (props, target) => {
161
161
  return $mol_jsx("button", { title: props.hint }, target());
162
162
  };
163
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
164
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
163
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
164
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
165
165
  },
166
166
  'Nested guid generation'() {
167
167
  const Foo = () => {
168
168
  return $mol_jsx("div", null,
169
- $mol_jsx(Bar, { id: "/bar" },
170
- $mol_jsx("img", { id: "/icon" })));
169
+ $mol_jsx(Bar, { id: "bar" },
170
+ $mol_jsx("img", { id: "icon" })));
171
171
  };
172
172
  const Bar = (props, icon) => {
173
- return $mol_jsx("span", null, icon);
173
+ return $mol_jsx("span", null,
174
+ icon,
175
+ $mol_jsx("i", { id: "label" }));
174
176
  };
175
- const dom = $mol_jsx(Foo, { id: "/foo" });
176
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
177
+ const dom = $mol_jsx(Foo, { id: "foo" });
178
+ $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>');
177
179
  },
178
180
  'Fail on non unique ids'() {
179
181
  const App = () => {
180
182
  return $mol_jsx("div", null,
181
- $mol_jsx("span", { id: "/bar" }),
182
- $mol_jsx("span", { id: "/bar" }));
183
+ $mol_jsx("span", { id: "bar" }),
184
+ $mol_jsx("span", { id: "bar" }));
183
185
  };
184
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
186
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
187
+ },
188
+ 'Owner based guid generationn'() {
189
+ const Foo = () => {
190
+ return $mol_jsx("div", null,
191
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
192
+ };
193
+ const Bar = (props) => {
194
+ return $mol_jsx("span", null, props.icon());
195
+ };
196
+ const dom = $mol_jsx(Foo, { id: "app" });
197
+ $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>');
198
+ },
199
+ 'Fail on same ids from different caller'() {
200
+ const Foo = () => {
201
+ return $mol_jsx("div", null,
202
+ $mol_jsx("img", { id: "icon" }),
203
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
204
+ };
205
+ const Bar = (props) => {
206
+ return $mol_jsx("span", null, props.icon());
207
+ };
208
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
185
209
  },
186
210
  });
187
211
  })($ || ($ = {}));
@@ -191,6 +215,7 @@ var $;
191
215
  var $;
192
216
  (function ($) {
193
217
  $.$mol_jsx_prefix = '';
218
+ $.$mol_jsx_crumbs = '';
194
219
  $.$mol_jsx_booked = null;
195
220
  $.$mol_jsx_document = {
196
221
  getElementById: () => null,
@@ -200,16 +225,45 @@ var $;
200
225
  $.$mol_jsx_frag = '';
201
226
  function $mol_jsx(Elem, props, ...childNodes) {
202
227
  const id = props && props.id || '';
228
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
229
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
203
230
  if (Elem && $.$mol_jsx_booked) {
204
231
  if ($.$mol_jsx_booked.has(id)) {
205
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
232
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
206
233
  }
207
234
  else {
208
235
  $.$mol_jsx_booked.add(id);
209
236
  }
210
237
  }
211
- const guid = $.$mol_jsx_prefix + id;
212
238
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
239
+ if ($.$mol_jsx_prefix) {
240
+ const prefix_ext = $.$mol_jsx_prefix;
241
+ const booked_ext = $.$mol_jsx_booked;
242
+ const crumbs_ext = $.$mol_jsx_crumbs;
243
+ for (const field in props) {
244
+ const func = props[field];
245
+ if (typeof func !== 'function')
246
+ continue;
247
+ const wrapper = function (...args) {
248
+ const prefix = $.$mol_jsx_prefix;
249
+ const booked = $.$mol_jsx_booked;
250
+ const crumbs = $.$mol_jsx_crumbs;
251
+ try {
252
+ $.$mol_jsx_prefix = prefix_ext;
253
+ $.$mol_jsx_booked = booked_ext;
254
+ $.$mol_jsx_crumbs = crumbs_ext;
255
+ return func.call(this, ...args);
256
+ }
257
+ finally {
258
+ $.$mol_jsx_prefix = prefix;
259
+ $.$mol_jsx_booked = booked;
260
+ $.$mol_jsx_crumbs = crumbs;
261
+ }
262
+ };
263
+ $mol_func_name_from(wrapper, func);
264
+ props[field] = wrapper;
265
+ }
266
+ }
213
267
  if (typeof Elem !== 'string') {
214
268
  if ('prototype' in Elem) {
215
269
  const view = node && node[Elem] || new Elem;
@@ -218,6 +272,7 @@ var $;
218
272
  view.childNodes = childNodes;
219
273
  if (!view.ownerDocument)
220
274
  view.ownerDocument = $.$mol_jsx_document;
275
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
221
276
  node = view.valueOf();
222
277
  node[Elem] = view;
223
278
  return node;
@@ -225,14 +280,17 @@ var $;
225
280
  else {
226
281
  const prefix = $.$mol_jsx_prefix;
227
282
  const booked = $.$mol_jsx_booked;
283
+ const crumbs = $.$mol_jsx_crumbs;
228
284
  try {
229
285
  $.$mol_jsx_prefix = guid;
230
286
  $.$mol_jsx_booked = new Set;
287
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
231
288
  return Elem(props, ...childNodes);
232
289
  }
233
290
  finally {
234
291
  $.$mol_jsx_prefix = prefix;
235
292
  $.$mol_jsx_booked = booked;
293
+ $.$mol_jsx_crumbs = crumbs;
236
294
  }
237
295
  }
238
296
  }
@@ -244,7 +302,11 @@ var $;
244
302
  $mol_dom_render_children(node, [].concat(...childNodes));
245
303
  if (!Elem)
246
304
  return node;
305
+ if (guid)
306
+ node.id = guid;
247
307
  for (const key in props) {
308
+ if (key === 'id')
309
+ continue;
248
310
  if (typeof props[key] === 'string') {
249
311
  ;
250
312
  node.setAttribute(key, props[key]);
@@ -261,8 +323,8 @@ var $;
261
323
  node[key] = props[key];
262
324
  }
263
325
  }
264
- if (guid)
265
- node.id = guid;
326
+ if ($.$mol_jsx_crumbs)
327
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
266
328
  return node;
267
329
  }
268
330
  $.$mol_jsx = $mol_jsx;
@@ -503,6 +565,20 @@ var $;
503
565
  ;
504
566
  "use strict";
505
567
  var $;
568
+ (function ($_1) {
569
+ $mol_test({
570
+ 'FQN of anon function'($) {
571
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
572
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
573
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
574
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
575
+ },
576
+ });
577
+ })($ || ($ = {}));
578
+ //mol/func/name/name.test.ts
579
+ ;
580
+ "use strict";
581
+ var $;
506
582
  (function ($) {
507
583
  $mol_test({
508
584
  'get'() {
@@ -1827,20 +1903,6 @@ var $;
1827
1903
  ;
1828
1904
  "use strict";
1829
1905
  var $;
1830
- (function ($_1) {
1831
- $mol_test({
1832
- 'FQN of anon function'($) {
1833
- const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
1834
- $mol_assert_equal($$.$mol_func_name_test.name, '');
1835
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
1836
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
1837
- },
1838
- });
1839
- })($ || ($ = {}));
1840
- //mol/func/name/name.test.ts
1841
- ;
1842
- "use strict";
1843
- var $;
1844
1906
  (function ($_1) {
1845
1907
  $mol_test({
1846
1908
  'id auto generation'($) {