mol_db 0.0.308 → 0.0.311
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 +118 -14
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.test.js +118 -14
- package/web.test.js.map +1 -1
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: "
|
|
1180
|
-
$mol_assert_equal(dom.outerHTML, '<button title="click me" id="
|
|
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: "
|
|
1186
|
-
$mol_jsx("img", { id: "
|
|
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,
|
|
1189
|
+
return $mol_jsx("span", null,
|
|
1190
|
+
icon,
|
|
1191
|
+
$mol_jsx("i", { id: "label" }));
|
|
1190
1192
|
};
|
|
1191
|
-
const dom = $mol_jsx(Foo, { id: "
|
|
1192
|
-
$mol_assert_equal(dom.outerHTML, '<div id="
|
|
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: "
|
|
1198
|
-
$mol_jsx("span", { id: "
|
|
1199
|
+
$mol_jsx("span", { id: "bar" }),
|
|
1200
|
+
$mol_jsx("span", { id: "bar" }));
|
|
1199
1201
|
};
|
|
1200
|
-
$mol_assert_fail(() => $mol_jsx(App, { id: "
|
|
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.replace(/\/.*/i, '')}`) : $.$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(
|
|
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
|
}
|
|
@@ -1260,7 +1318,11 @@ var $;
|
|
|
1260
1318
|
$mol_dom_render_children(node, [].concat(...childNodes));
|
|
1261
1319
|
if (!Elem)
|
|
1262
1320
|
return node;
|
|
1321
|
+
if (guid)
|
|
1322
|
+
node.id = guid;
|
|
1263
1323
|
for (const key in props) {
|
|
1324
|
+
if (key === 'id')
|
|
1325
|
+
continue;
|
|
1264
1326
|
if (typeof props[key] === 'string') {
|
|
1265
1327
|
;
|
|
1266
1328
|
node.setAttribute(key, props[key]);
|
|
@@ -1277,8 +1339,8 @@ var $;
|
|
|
1277
1339
|
node[key] = props[key];
|
|
1278
1340
|
}
|
|
1279
1341
|
}
|
|
1280
|
-
if (
|
|
1281
|
-
node.
|
|
1342
|
+
if ($.$mol_jsx_crumbs)
|
|
1343
|
+
node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
|
|
1282
1344
|
return node;
|
|
1283
1345
|
}
|
|
1284
1346
|
$.$mol_jsx = $mol_jsx;
|
|
@@ -1710,6 +1772,48 @@ var $;
|
|
|
1710
1772
|
;
|
|
1711
1773
|
"use strict";
|
|
1712
1774
|
var $;
|
|
1775
|
+
(function ($_1) {
|
|
1776
|
+
$mol_test({
|
|
1777
|
+
'FQN of anon function'($) {
|
|
1778
|
+
const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
|
|
1779
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '');
|
|
1780
|
+
$mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
|
|
1781
|
+
$mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
|
|
1782
|
+
},
|
|
1783
|
+
});
|
|
1784
|
+
})($ || ($ = {}));
|
|
1785
|
+
//mol/func/name/name.test.ts
|
|
1786
|
+
;
|
|
1787
|
+
"use strict";
|
|
1788
|
+
var $;
|
|
1789
|
+
(function ($) {
|
|
1790
|
+
function $mol_func_name(func) {
|
|
1791
|
+
let name = func.name;
|
|
1792
|
+
if (name?.length > 1)
|
|
1793
|
+
return name;
|
|
1794
|
+
for (let key in this) {
|
|
1795
|
+
try {
|
|
1796
|
+
if (this[key] !== func)
|
|
1797
|
+
continue;
|
|
1798
|
+
name = key;
|
|
1799
|
+
Object.defineProperty(func, 'name', { value: name });
|
|
1800
|
+
break;
|
|
1801
|
+
}
|
|
1802
|
+
catch { }
|
|
1803
|
+
}
|
|
1804
|
+
return name;
|
|
1805
|
+
}
|
|
1806
|
+
$.$mol_func_name = $mol_func_name;
|
|
1807
|
+
function $mol_func_name_from(target, source) {
|
|
1808
|
+
Object.defineProperty(target, 'name', { value: source.name });
|
|
1809
|
+
return target;
|
|
1810
|
+
}
|
|
1811
|
+
$.$mol_func_name_from = $mol_func_name_from;
|
|
1812
|
+
})($ || ($ = {}));
|
|
1813
|
+
//mol/func/name/name.ts
|
|
1814
|
+
;
|
|
1815
|
+
"use strict";
|
|
1816
|
+
var $;
|
|
1713
1817
|
(function ($_1) {
|
|
1714
1818
|
$mol_test({
|
|
1715
1819
|
'tree parsing'() {
|