native-document 1.0.29 → 1.0.31
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/dist/native-document.dev.js +83 -29
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/index.d.ts +3 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/src/utils/args-types.js +10 -1
- package/src/utils/property-accumulator.js +6 -6
- package/src/wrappers/HtmlElementWrapper.js +3 -6
- package/src/wrappers/NDElement.js +4 -0
- package/types/args-types.d.ts +58 -0
- package/types/property-accumulator.d.ts +33 -0
- package/types/validator.ts +55 -0
|
@@ -637,6 +637,10 @@ var NativeDocument = (function (exports) {
|
|
|
637
637
|
};
|
|
638
638
|
}
|
|
639
639
|
|
|
640
|
+
NDElement.prototype.valueOf = function() {
|
|
641
|
+
return this.$element;
|
|
642
|
+
};
|
|
643
|
+
|
|
640
644
|
NDElement.prototype.ref = function(target, name) {
|
|
641
645
|
target[name] = this.$element;
|
|
642
646
|
return this;
|
|
@@ -1260,35 +1264,6 @@ var NativeDocument = (function (exports) {
|
|
|
1260
1264
|
}
|
|
1261
1265
|
});
|
|
1262
1266
|
|
|
1263
|
-
/**
|
|
1264
|
-
*
|
|
1265
|
-
* @param {string} name
|
|
1266
|
-
* @param {?Function} customWrapper
|
|
1267
|
-
* @returns {Function}
|
|
1268
|
-
*/
|
|
1269
|
-
function HtmlElementWrapper(name, customWrapper) {
|
|
1270
|
-
const $tagName = name.toLowerCase();
|
|
1271
|
-
|
|
1272
|
-
return function(attributes, children = null) {
|
|
1273
|
-
try {
|
|
1274
|
-
if(!Validator.isJson(attributes)) {
|
|
1275
|
-
const tempChildren = children;
|
|
1276
|
-
children = attributes;
|
|
1277
|
-
attributes = tempChildren;
|
|
1278
|
-
}
|
|
1279
|
-
const element = ElementCreator.createElement($tagName);
|
|
1280
|
-
const finalElement = (typeof customWrapper === 'function') ? customWrapper(element) : element;
|
|
1281
|
-
|
|
1282
|
-
ElementCreator.processAttributes(finalElement, attributes);
|
|
1283
|
-
ElementCreator.processChildren(children, finalElement);
|
|
1284
|
-
|
|
1285
|
-
return ElementCreator.setup(finalElement, attributes, customWrapper);
|
|
1286
|
-
} catch (error) {
|
|
1287
|
-
DebugManager$1.error('ElementCreation', `Error creating ${$tagName}`, error);
|
|
1288
|
-
}
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
1267
|
class ArgTypesError extends Error {
|
|
1293
1268
|
constructor(message, errors) {
|
|
1294
1269
|
super(`${message}\n\n${errors.join("\n")}\n\n`);
|
|
@@ -1392,6 +1367,40 @@ var NativeDocument = (function (exports) {
|
|
|
1392
1367
|
};
|
|
1393
1368
|
};
|
|
1394
1369
|
|
|
1370
|
+
const normalizeComponentArgs = function(props, children = null) {
|
|
1371
|
+
if(!Validator.isJson(props)) {
|
|
1372
|
+
const temp = children;
|
|
1373
|
+
children = props;
|
|
1374
|
+
props = temp;
|
|
1375
|
+
}
|
|
1376
|
+
return { props, children };
|
|
1377
|
+
};
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
*
|
|
1381
|
+
* @param {string} name
|
|
1382
|
+
* @param {?Function} customWrapper
|
|
1383
|
+
* @returns {Function}
|
|
1384
|
+
*/
|
|
1385
|
+
function HtmlElementWrapper(name, customWrapper) {
|
|
1386
|
+
const $tagName = name.toLowerCase();
|
|
1387
|
+
|
|
1388
|
+
return function(_attributes, _children = null) {
|
|
1389
|
+
try {
|
|
1390
|
+
const { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
|
|
1391
|
+
const element = ElementCreator.createElement($tagName);
|
|
1392
|
+
const finalElement = (typeof customWrapper === 'function') ? customWrapper(element) : element;
|
|
1393
|
+
|
|
1394
|
+
ElementCreator.processAttributes(finalElement, attributes);
|
|
1395
|
+
ElementCreator.processChildren(children, finalElement);
|
|
1396
|
+
|
|
1397
|
+
return ElementCreator.setup(finalElement, attributes, customWrapper);
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
DebugManager$1.error('ElementCreation', `Error creating ${$tagName}`, error);
|
|
1400
|
+
}
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1395
1404
|
Function.prototype.args = function(...args) {
|
|
1396
1405
|
return withValidation(this, args);
|
|
1397
1406
|
};
|
|
@@ -1433,6 +1442,48 @@ var NativeDocument = (function (exports) {
|
|
|
1433
1442
|
});
|
|
1434
1443
|
};
|
|
1435
1444
|
|
|
1445
|
+
const cssPropertyAccumulator = function(initialValue = {}) {
|
|
1446
|
+
let data = Validator.isString(initialValue) ? initialValue.split(';').filter(Boolean) : initialValue;
|
|
1447
|
+
const isArray = Validator.isArray(data);
|
|
1448
|
+
|
|
1449
|
+
return {
|
|
1450
|
+
add(key, value) {
|
|
1451
|
+
if(isArray) {
|
|
1452
|
+
data.push(key+' : '+value);
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1455
|
+
data[key] = value;
|
|
1456
|
+
},
|
|
1457
|
+
value() {
|
|
1458
|
+
if(isArray) {
|
|
1459
|
+
return data.join(';').concat(';');
|
|
1460
|
+
}
|
|
1461
|
+
return { ...data };
|
|
1462
|
+
},
|
|
1463
|
+
};
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
const classPropertyAccumulator = function(initialValue = []) {
|
|
1467
|
+
let data = Validator.isString(initialValue) ? initialValue.split(" ").filter(Boolean) : initialValue;
|
|
1468
|
+
const isArray = Validator.isArray(data);
|
|
1469
|
+
|
|
1470
|
+
return {
|
|
1471
|
+
add(key, value = true) {
|
|
1472
|
+
if(isArray) {
|
|
1473
|
+
data.push(key);
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
data[key] = value;
|
|
1477
|
+
},
|
|
1478
|
+
value() {
|
|
1479
|
+
if(isArray) {
|
|
1480
|
+
return data.join(' ');
|
|
1481
|
+
}
|
|
1482
|
+
return { ...data };
|
|
1483
|
+
},
|
|
1484
|
+
};
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1436
1487
|
const methods = ['push', 'pop', 'shift', 'unshift', 'reverse', 'sort', 'splice'];
|
|
1437
1488
|
|
|
1438
1489
|
/**
|
|
@@ -3331,7 +3382,10 @@ var NativeDocument = (function (exports) {
|
|
|
3331
3382
|
exports.NDElement = NDElement;
|
|
3332
3383
|
exports.Observable = Observable;
|
|
3333
3384
|
exports.Store = Store;
|
|
3385
|
+
exports.classPropertyAccumulator = classPropertyAccumulator;
|
|
3386
|
+
exports.cssPropertyAccumulator = cssPropertyAccumulator;
|
|
3334
3387
|
exports.elements = elements;
|
|
3388
|
+
exports.normalizeComponentArgs = normalizeComponentArgs;
|
|
3335
3389
|
exports.router = router;
|
|
3336
3390
|
exports.withValidation = withValidation;
|
|
3337
3391
|
|