native-document 1.0.73 → 1.0.75

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.
@@ -1,16 +1,16 @@
1
1
  var NativeComponents = (function (exports) {
2
2
  'use strict';
3
3
 
4
- let DebugManager = {};
4
+ let DebugManager$1 = {};
5
5
  {
6
- DebugManager = {
6
+ DebugManager$1 = {
7
7
  log() {},
8
8
  warn() {},
9
9
  error() {},
10
10
  disable() {}
11
11
  };
12
12
  }
13
- var DebugManager$1 = DebugManager;
13
+ var DebugManager = DebugManager$1;
14
14
 
15
15
  const MemoryManager = (function() {
16
16
 
@@ -59,7 +59,7 @@ var NativeComponents = (function (exports) {
59
59
  }
60
60
  }
61
61
  if (cleanedCount > 0) {
62
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
62
+ DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
63
63
  }
64
64
  }
65
65
  };
@@ -182,7 +182,7 @@ var NativeComponents = (function (exports) {
182
182
  try{
183
183
  callback.call(plugin, ...data);
184
184
  } catch (error) {
185
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
185
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
186
186
  }
187
187
  }
188
188
  }
@@ -486,7 +486,7 @@ var NativeComponents = (function (exports) {
486
486
  ObservableItem.prototype.subscribe = function(callback, target = null) {
487
487
  this.$listeners = this.$listeners ?? [];
488
488
  if (this.$isCleanedUp) {
489
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
489
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
490
490
  return () => {};
491
491
  }
492
492
  if (typeof callback !== 'function') {
@@ -862,17 +862,17 @@ var NativeComponents = (function (exports) {
862
862
  const method = methods[name];
863
863
 
864
864
  if (typeof method !== 'function') {
865
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
865
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
866
866
  continue;
867
867
  }
868
868
 
869
869
  if (protectedMethods.has(name)) {
870
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
870
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
871
871
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
872
872
  }
873
873
 
874
874
  if (NDElement.prototype[name]) {
875
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
875
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
876
876
  }
877
877
 
878
878
  NDElement.prototype[name] = method;
@@ -1062,7 +1062,7 @@ var NativeComponents = (function (exports) {
1062
1062
  anchorFragment.appendChild = function(child, before = null) {
1063
1063
  const parent = anchorEnd.parentNode;
1064
1064
  if(!parent) {
1065
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1065
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
1066
1066
  return;
1067
1067
  }
1068
1068
  before = before ?? anchorEnd;
@@ -1171,7 +1171,7 @@ var NativeComponents = (function (exports) {
1171
1171
  return new ObservableItem(value, configs);
1172
1172
  }
1173
1173
 
1174
- const $$1 = Observable;
1174
+ const $ = Observable;
1175
1175
 
1176
1176
  /**
1177
1177
  *
@@ -1232,9 +1232,11 @@ var NativeComponents = (function (exports) {
1232
1232
  function toggleElementClass(element, className, shouldAdd) {
1233
1233
  element.classes.toggle(className, shouldAdd);
1234
1234
  }
1235
+
1235
1236
  function toggleElementStyle(element, styleName, newValue) {
1236
1237
  element.style[styleName] = newValue;
1237
1238
  }
1239
+
1238
1240
  function updateInputFromObserver(element, attributeName, newValue) {
1239
1241
  if(Validator.isBoolean(newValue)) {
1240
1242
  element[attributeName] = newValue;
@@ -1242,6 +1244,7 @@ var NativeComponents = (function (exports) {
1242
1244
  }
1243
1245
  element[attributeName] = newValue === element.value;
1244
1246
  }
1247
+
1245
1248
  function updateObserverFromInput(element, attributeName, defaultValue, value) {
1246
1249
  if(Validator.isBoolean(defaultValue)) {
1247
1250
  value.set(element[attributeName]);
@@ -1249,6 +1252,7 @@ var NativeComponents = (function (exports) {
1249
1252
  }
1250
1253
  value.set(element.value);
1251
1254
  }
1255
+
1252
1256
  /**
1253
1257
  *
1254
1258
  * @param {HTMLElement} element
@@ -1355,37 +1359,19 @@ var NativeComponents = (function (exports) {
1355
1359
  if(value === null || value === undefined) {
1356
1360
  continue;
1357
1361
  }
1358
- if(Validator.isString(value)) {
1359
- value = value.resolveObservableTemplate ? value.resolveObservableTemplate() : value;
1360
- if(Validator.isString(value)) {
1361
- element.setAttribute(attributeName, value);
1362
- continue;
1363
- }
1364
- const observables = value.filter(item => Validator.isObservable(item));
1365
- value = Observable.computed(() => {
1366
- return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
1367
- }, observables);
1368
- }
1369
- if(attributeName === 'class' && Validator.isObject(value)) {
1370
- bindClassAttribute(element, value);
1371
- continue;
1372
- }
1373
- if(attributeName === 'style' && Validator.isObject(value)) {
1374
- bindStyleAttribute(element, value);
1362
+ if(value.handleNdAttribute) {
1363
+ value.handleNdAttribute(element, attributeName, value);
1375
1364
  continue;
1376
1365
  }
1377
1366
  if(BOOLEAN_ATTRIBUTES.includes(attributeName)) {
1378
1367
  bindBooleanAttribute(element, attributeName, value);
1379
- continue;
1368
+ return;
1380
1369
  }
1381
1370
  if(Validator.isObservable(value)) {
1382
1371
  bindAttributeWithObservable(element, attributeName, value);
1383
1372
  continue;
1384
1373
  }
1385
- if(value.$hydrate) {
1386
- value.$hydrate(element, attributeName);
1387
- continue;
1388
- }
1374
+
1389
1375
  element.setAttribute(attributeName, value);
1390
1376
 
1391
1377
  }
@@ -1427,7 +1413,9 @@ var NativeComponents = (function (exports) {
1427
1413
  Array.prototype.toNdElement = function () {
1428
1414
  const fragment = document.createDocumentFragment();
1429
1415
  for(let i = 0, length = this.length; i < length; i++) {
1430
- fragment.appendChild(ElementCreator.getChild(this[i]));
1416
+ const child = ElementCreator.getChild(this[i]);
1417
+ if(child === null) continue;
1418
+ fragment.appendChild(child);
1431
1419
  }
1432
1420
  return fragment;
1433
1421
  };
@@ -1442,6 +1430,44 @@ var NativeComponents = (function (exports) {
1442
1430
  return ElementCreator.createHydratableNode(null, this);
1443
1431
  };
1444
1432
 
1433
+ Object.prototype.handleNdAttribute = function(element, attributeName) {
1434
+ if(attributeName === 'class') {
1435
+ bindClassAttribute(element, this);
1436
+ return;
1437
+ }
1438
+ if(attributeName === 'style') {
1439
+ bindStyleAttribute(element, this);
1440
+
1441
+ }
1442
+ };
1443
+
1444
+ String.prototype.handleNdAttribute = function(element, attributeName) {
1445
+ let value = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
1446
+ if(Validator.isString(value)) {
1447
+ element.setAttribute(attributeName, value);
1448
+ return;
1449
+ }
1450
+ const observables = value.filter(item => Validator.isObservable(item));
1451
+ value = Observable.computed(() => {
1452
+ return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
1453
+ }, observables);
1454
+
1455
+ if(BOOLEAN_ATTRIBUTES.includes(attributeName)) {
1456
+ bindBooleanAttribute(element, attributeName, value);
1457
+ return;
1458
+ }
1459
+
1460
+ bindAttributeWithObservable(element, attributeName, value);
1461
+ };
1462
+
1463
+ ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1464
+ bindAttributeWithObservable(element, attributeName, this);
1465
+ };
1466
+
1467
+ TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
1468
+ this.$hydrate(element, attributeName);
1469
+ };
1470
+
1445
1471
  const $nodeCache = new Map();
1446
1472
  let $textNodeCache = null;
1447
1473
 
@@ -1513,20 +1539,10 @@ var NativeComponents = (function (exports) {
1513
1539
  processChildren(children, parent) {
1514
1540
  if(children === null) return;
1515
1541
  PluginsManager.emit('BeforeProcessChildren', parent);
1516
- if(!Array.isArray(children)) {
1517
- let child = this.getChild(children);
1518
- if(child) {
1519
- parent.appendChild(child);
1520
- }
1542
+ let child = this.getChild(children);
1543
+ if(child) {
1544
+ parent.appendChild(child);
1521
1545
  }
1522
- else {
1523
- for(let i = 0, length = children.length; i < length; i++) {
1524
- let child = this.getChild(children[i]);
1525
- if (child === null) continue;
1526
- parent.appendChild(child);
1527
- }
1528
- }
1529
-
1530
1546
  PluginsManager.emit('AfterProcessChildren', parent);
1531
1547
  },
1532
1548
  getChild(child) {
@@ -2367,7 +2383,7 @@ var NativeComponents = (function (exports) {
2367
2383
  */
2368
2384
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
2369
2385
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
2370
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
2386
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
2371
2387
  }
2372
2388
  const element = Anchor('Show if : '+(comment || ''));
2373
2389
 
@@ -2476,7 +2492,7 @@ var NativeComponents = (function (exports) {
2476
2492
  HtmlElementWrapper('meter');
2477
2493
 
2478
2494
 
2479
- const Button$1 = HtmlElementWrapper('button');
2495
+ const Button = HtmlElementWrapper('button');
2480
2496
 
2481
2497
  HtmlElementWrapper('main');
2482
2498
  HtmlElementWrapper('section');
@@ -3085,7 +3101,7 @@ var NativeComponents = (function (exports) {
3085
3101
 
3086
3102
  const ErrorDisplayer = (errors) => {
3087
3103
 
3088
- const shouldDisplayError = $$1.computed(() => {
3104
+ const shouldDisplayError = $.computed(() => {
3089
3105
  const val = errors.val();
3090
3106
  return (val && val.length > 0);
3091
3107
  }, [errors]);
@@ -3116,15 +3132,15 @@ var NativeComponents = (function (exports) {
3116
3132
  };
3117
3133
 
3118
3134
  if(description.showErrors) {
3119
- description.errors = description.errors || $$1(null);
3135
+ description.errors = description.errors || $(null);
3120
3136
  field.errors(description.errors);
3121
3137
  }
3122
3138
 
3123
- const hasErrors = description.showErrors ? $$1.computed(() => {
3139
+ const hasErrors = description.showErrors ? $.computed(() => {
3124
3140
  const errs = description.errors?.val();
3125
3141
  return errs && errs.length > 0;
3126
3142
  }, [description.errors]) : null;
3127
- const hasFocus = $$1(false);
3143
+ const hasFocus = $(false);
3128
3144
 
3129
3145
  const wrapperClasses = {
3130
3146
  [suffix+'-wrapper']: true,
@@ -3627,7 +3643,7 @@ var NativeComponents = (function (exports) {
3627
3643
  function DefaultLayout({ fields, form }) {
3628
3644
  return Form([
3629
3645
  Object.values(fields),
3630
- Button$1({ type: 'submit', disabled: form.submitting }, 'Submit')
3646
+ Button({ type: 'submit', disabled: form.submitting }, 'Submit')
3631
3647
  ]);
3632
3648
  }
3633
3649
 
@@ -4749,7 +4765,7 @@ var NativeComponents = (function (exports) {
4749
4765
 
4750
4766
  return Div({ class: 'field-collection-layout'}, [
4751
4767
  Div({ class: 'field-collection-layout-header'}, [
4752
- Button$1({ class: 'field-collection-layout-add-btn', type: 'button' }, ['Add +'])
4768
+ Button({ class: 'field-collection-layout-add-btn', type: 'button' }, ['Add +'])
4753
4769
  .nd.onClick(() => collection.add())
4754
4770
  ]),
4755
4771
  ForEachArray(data, Template)
@@ -1290,9 +1290,11 @@ var NativeDocument = (function (exports) {
1290
1290
  function toggleElementClass(element, className, shouldAdd) {
1291
1291
  element.classes.toggle(className, shouldAdd);
1292
1292
  }
1293
+
1293
1294
  function toggleElementStyle(element, styleName, newValue) {
1294
1295
  element.style[styleName] = newValue;
1295
1296
  }
1297
+
1296
1298
  function updateInputFromObserver(element, attributeName, newValue) {
1297
1299
  if(Validator.isBoolean(newValue)) {
1298
1300
  element[attributeName] = newValue;
@@ -1300,6 +1302,7 @@ var NativeDocument = (function (exports) {
1300
1302
  }
1301
1303
  element[attributeName] = newValue === element.value;
1302
1304
  }
1305
+
1303
1306
  function updateObserverFromInput(element, attributeName, defaultValue, value) {
1304
1307
  if(Validator.isBoolean(defaultValue)) {
1305
1308
  value.set(element[attributeName]);
@@ -1307,6 +1310,7 @@ var NativeDocument = (function (exports) {
1307
1310
  }
1308
1311
  value.set(element.value);
1309
1312
  }
1313
+
1310
1314
  /**
1311
1315
  *
1312
1316
  * @param {HTMLElement} element
@@ -1415,37 +1419,19 @@ var NativeDocument = (function (exports) {
1415
1419
  if(value === null || value === undefined) {
1416
1420
  continue;
1417
1421
  }
1418
- if(Validator.isString(value)) {
1419
- value = value.resolveObservableTemplate ? value.resolveObservableTemplate() : value;
1420
- if(Validator.isString(value)) {
1421
- element.setAttribute(attributeName, value);
1422
- continue;
1423
- }
1424
- const observables = value.filter(item => Validator.isObservable(item));
1425
- value = Observable.computed(() => {
1426
- return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
1427
- }, observables);
1428
- }
1429
- if(attributeName === 'class' && Validator.isObject(value)) {
1430
- bindClassAttribute(element, value);
1431
- continue;
1432
- }
1433
- if(attributeName === 'style' && Validator.isObject(value)) {
1434
- bindStyleAttribute(element, value);
1422
+ if(value.handleNdAttribute) {
1423
+ value.handleNdAttribute(element, attributeName, value);
1435
1424
  continue;
1436
1425
  }
1437
1426
  if(BOOLEAN_ATTRIBUTES.includes(attributeName)) {
1438
1427
  bindBooleanAttribute(element, attributeName, value);
1439
- continue;
1428
+ return;
1440
1429
  }
1441
1430
  if(Validator.isObservable(value)) {
1442
1431
  bindAttributeWithObservable(element, attributeName, value);
1443
1432
  continue;
1444
1433
  }
1445
- if(value.$hydrate) {
1446
- value.$hydrate(element, attributeName);
1447
- continue;
1448
- }
1434
+
1449
1435
  element.setAttribute(attributeName, value);
1450
1436
 
1451
1437
  }
@@ -1487,7 +1473,9 @@ var NativeDocument = (function (exports) {
1487
1473
  Array.prototype.toNdElement = function () {
1488
1474
  const fragment = document.createDocumentFragment();
1489
1475
  for(let i = 0, length = this.length; i < length; i++) {
1490
- fragment.appendChild(ElementCreator.getChild(this[i]));
1476
+ const child = ElementCreator.getChild(this[i]);
1477
+ if(child === null) continue;
1478
+ fragment.appendChild(child);
1491
1479
  }
1492
1480
  return fragment;
1493
1481
  };
@@ -1502,6 +1490,44 @@ var NativeDocument = (function (exports) {
1502
1490
  return ElementCreator.createHydratableNode(null, this);
1503
1491
  };
1504
1492
 
1493
+ Object.prototype.handleNdAttribute = function(element, attributeName) {
1494
+ if(attributeName === 'class') {
1495
+ bindClassAttribute(element, this);
1496
+ return;
1497
+ }
1498
+ if(attributeName === 'style') {
1499
+ bindStyleAttribute(element, this);
1500
+
1501
+ }
1502
+ };
1503
+
1504
+ String.prototype.handleNdAttribute = function(element, attributeName) {
1505
+ let value = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
1506
+ if(Validator.isString(value)) {
1507
+ element.setAttribute(attributeName, value);
1508
+ return;
1509
+ }
1510
+ const observables = value.filter(item => Validator.isObservable(item));
1511
+ value = Observable.computed(() => {
1512
+ return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
1513
+ }, observables);
1514
+
1515
+ if(BOOLEAN_ATTRIBUTES.includes(attributeName)) {
1516
+ bindBooleanAttribute(element, attributeName, value);
1517
+ return;
1518
+ }
1519
+
1520
+ bindAttributeWithObservable(element, attributeName, value);
1521
+ };
1522
+
1523
+ ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1524
+ bindAttributeWithObservable(element, attributeName, this);
1525
+ };
1526
+
1527
+ TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
1528
+ this.$hydrate(element, attributeName);
1529
+ };
1530
+
1505
1531
  const $nodeCache = new Map();
1506
1532
  let $textNodeCache = null;
1507
1533
 
@@ -1573,20 +1599,10 @@ var NativeDocument = (function (exports) {
1573
1599
  processChildren(children, parent) {
1574
1600
  if(children === null) return;
1575
1601
  PluginsManager.emit('BeforeProcessChildren', parent);
1576
- if(!Array.isArray(children)) {
1577
- let child = this.getChild(children);
1578
- if(child) {
1579
- parent.appendChild(child);
1580
- }
1602
+ let child = this.getChild(children);
1603
+ if(child) {
1604
+ parent.appendChild(child);
1581
1605
  }
1582
- else {
1583
- for(let i = 0, length = children.length; i < length; i++) {
1584
- let child = this.getChild(children[i]);
1585
- if (child === null) continue;
1586
- parent.appendChild(child);
1587
- }
1588
- }
1589
-
1590
1606
  PluginsManager.emit('AfterProcessChildren', parent);
1591
1607
  },
1592
1608
  getChild(child) {
@@ -3512,9 +3528,7 @@ var NativeDocument = (function (exports) {
3512
3528
  },
3513
3529
  add(items, delay = 2) {
3514
3530
  const fragment = Actions.toFragment(items);
3515
- Promise.resolve().then(() => {
3516
- element.appendElement(fragment);
3517
- });
3531
+ element.appendElement(fragment);
3518
3532
  },
3519
3533
  replace(items) {
3520
3534
  clear();