mol_time_all 1.1.232 → 1.1.235

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
@@ -1092,28 +1092,52 @@ var $;
1092
1092
  const Button = (props, target) => {
1093
1093
  return $mol_jsx("button", { title: props.hint }, target());
1094
1094
  };
1095
- const dom = $mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
1096
- $mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
1095
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
1096
+ $mol_assert_equal(dom.outerHTML, '<button title="click me" id="foo" class="Button">hey!</button>');
1097
1097
  },
1098
1098
  'Nested guid generation'() {
1099
1099
  const Foo = () => {
1100
1100
  return $mol_jsx("div", null,
1101
- $mol_jsx(Bar, { id: "/bar" },
1102
- $mol_jsx("img", { id: "/icon" })));
1101
+ $mol_jsx(Bar, { id: "bar" },
1102
+ $mol_jsx("img", { id: "icon" })));
1103
1103
  };
1104
1104
  const Bar = (props, icon) => {
1105
- return $mol_jsx("span", null, icon);
1105
+ return $mol_jsx("span", null,
1106
+ icon,
1107
+ $mol_jsx("i", { id: "label" }));
1106
1108
  };
1107
- const dom = $mol_jsx(Foo, { id: "/foo" });
1108
- $mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
1109
+ const dom = $mol_jsx(Foo, { id: "foo" });
1110
+ $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>');
1109
1111
  },
1110
1112
  'Fail on non unique ids'() {
1111
1113
  const App = () => {
1112
1114
  return $mol_jsx("div", null,
1113
- $mol_jsx("span", { id: "/bar" }),
1114
- $mol_jsx("span", { id: "/bar" }));
1115
+ $mol_jsx("span", { id: "bar" }),
1116
+ $mol_jsx("span", { id: "bar" }));
1115
1117
  };
1116
- $mol_assert_fail(() => $mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
1118
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
1119
+ },
1120
+ 'Owner based guid generationn'() {
1121
+ const Foo = () => {
1122
+ return $mol_jsx("div", null,
1123
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
1124
+ };
1125
+ const Bar = (props) => {
1126
+ return $mol_jsx("span", null, props.icon());
1127
+ };
1128
+ const dom = $mol_jsx(Foo, { id: "app" });
1129
+ $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>');
1130
+ },
1131
+ 'Fail on same ids from different caller'() {
1132
+ const Foo = () => {
1133
+ return $mol_jsx("div", null,
1134
+ $mol_jsx("img", { id: "icon" }),
1135
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
1136
+ };
1137
+ const Bar = (props) => {
1138
+ return $mol_jsx("span", null, props.icon());
1139
+ };
1140
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
1117
1141
  },
1118
1142
  });
1119
1143
  })($ || ($ = {}));
@@ -1123,6 +1147,7 @@ var $;
1123
1147
  var $;
1124
1148
  (function ($) {
1125
1149
  $.$mol_jsx_prefix = '';
1150
+ $.$mol_jsx_crumbs = '';
1126
1151
  $.$mol_jsx_booked = null;
1127
1152
  $.$mol_jsx_document = {
1128
1153
  getElementById: () => null,
@@ -1132,16 +1157,45 @@ var $;
1132
1157
  $.$mol_jsx_frag = '';
1133
1158
  function $mol_jsx(Elem, props, ...childNodes) {
1134
1159
  const id = props && props.id || '';
1160
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1161
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id}`) : $.$mol_jsx_crumbs;
1135
1162
  if (Elem && $.$mol_jsx_booked) {
1136
1163
  if ($.$mol_jsx_booked.has(id)) {
1137
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
1164
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1138
1165
  }
1139
1166
  else {
1140
1167
  $.$mol_jsx_booked.add(id);
1141
1168
  }
1142
1169
  }
1143
- const guid = $.$mol_jsx_prefix + id;
1144
1170
  let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
1171
+ if ($.$mol_jsx_prefix) {
1172
+ const prefix_ext = $.$mol_jsx_prefix;
1173
+ const booked_ext = $.$mol_jsx_booked;
1174
+ const crumbs_ext = $.$mol_jsx_crumbs;
1175
+ for (const field in props) {
1176
+ const func = props[field];
1177
+ if (typeof func !== 'function')
1178
+ continue;
1179
+ const wrapper = function (...args) {
1180
+ const prefix = $.$mol_jsx_prefix;
1181
+ const booked = $.$mol_jsx_booked;
1182
+ const crumbs = $.$mol_jsx_crumbs;
1183
+ try {
1184
+ $.$mol_jsx_prefix = prefix_ext;
1185
+ $.$mol_jsx_booked = booked_ext;
1186
+ $.$mol_jsx_crumbs = crumbs_ext;
1187
+ return func.call(this, ...args);
1188
+ }
1189
+ finally {
1190
+ $.$mol_jsx_prefix = prefix;
1191
+ $.$mol_jsx_booked = booked;
1192
+ $.$mol_jsx_crumbs = crumbs;
1193
+ }
1194
+ };
1195
+ $mol_func_name_from(wrapper, func);
1196
+ props[field] = wrapper;
1197
+ }
1198
+ }
1145
1199
  if (typeof Elem !== 'string') {
1146
1200
  if ('prototype' in Elem) {
1147
1201
  const view = node && node[Elem] || new Elem;
@@ -1150,6 +1204,7 @@ var $;
1150
1204
  view.childNodes = childNodes;
1151
1205
  if (!view.ownerDocument)
1152
1206
  view.ownerDocument = $.$mol_jsx_document;
1207
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1153
1208
  node = view.valueOf();
1154
1209
  node[Elem] = view;
1155
1210
  return node;
@@ -1157,14 +1212,17 @@ var $;
1157
1212
  else {
1158
1213
  const prefix = $.$mol_jsx_prefix;
1159
1214
  const booked = $.$mol_jsx_booked;
1215
+ const crumbs = $.$mol_jsx_crumbs;
1160
1216
  try {
1161
1217
  $.$mol_jsx_prefix = guid;
1162
1218
  $.$mol_jsx_booked = new Set;
1219
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1163
1220
  return Elem(props, ...childNodes);
1164
1221
  }
1165
1222
  finally {
1166
1223
  $.$mol_jsx_prefix = prefix;
1167
1224
  $.$mol_jsx_booked = booked;
1225
+ $.$mol_jsx_crumbs = crumbs;
1168
1226
  }
1169
1227
  }
1170
1228
  }
@@ -1195,6 +1253,8 @@ var $;
1195
1253
  }
1196
1254
  if (guid)
1197
1255
  node.id = guid;
1256
+ if ($.$mol_jsx_crumbs)
1257
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1198
1258
  return node;
1199
1259
  }
1200
1260
  $.$mol_jsx = $mol_jsx;
@@ -2190,6 +2250,48 @@ var $;
2190
2250
  ;
2191
2251
  "use strict";
2192
2252
  var $;
2253
+ (function ($_1) {
2254
+ $mol_test({
2255
+ 'FQN of anon function'($) {
2256
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
2257
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
2258
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
2259
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
2260
+ },
2261
+ });
2262
+ })($ || ($ = {}));
2263
+ //mol/func/name/name.test.ts
2264
+ ;
2265
+ "use strict";
2266
+ var $;
2267
+ (function ($) {
2268
+ function $mol_func_name(func) {
2269
+ let name = func.name;
2270
+ if (name?.length > 1)
2271
+ return name;
2272
+ for (let key in this) {
2273
+ try {
2274
+ if (this[key] !== func)
2275
+ continue;
2276
+ name = key;
2277
+ Object.defineProperty(func, 'name', { value: name });
2278
+ break;
2279
+ }
2280
+ catch { }
2281
+ }
2282
+ return name;
2283
+ }
2284
+ $.$mol_func_name = $mol_func_name;
2285
+ function $mol_func_name_from(target, source) {
2286
+ Object.defineProperty(target, 'name', { value: source.name });
2287
+ return target;
2288
+ }
2289
+ $.$mol_func_name_from = $mol_func_name_from;
2290
+ })($ || ($ = {}));
2291
+ //mol/func/name/name.ts
2292
+ ;
2293
+ "use strict";
2294
+ var $;
2193
2295
  (function ($) {
2194
2296
  $mol_test({
2195
2297
  'parse and serial'() {