native-document 1.0.73 → 1.0.76

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,16 +1359,13 @@ var NativeComponents = (function (exports) {
1355
1359
  if(value === null || value === undefined) {
1356
1360
  continue;
1357
1361
  }
1362
+ if(value.handleNdAttribute) {
1363
+ value.handleNdAttribute(element, attributeName, value);
1364
+ continue;
1365
+ }
1358
1366
  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);
1367
+ element.setAttribute(attributeName, value);
1368
+ return;
1368
1369
  }
1369
1370
  if(attributeName === 'class' && Validator.isObject(value)) {
1370
1371
  bindClassAttribute(element, value);
@@ -1386,6 +1387,7 @@ var NativeComponents = (function (exports) {
1386
1387
  value.$hydrate(element, attributeName);
1387
1388
  continue;
1388
1389
  }
1390
+
1389
1391
  element.setAttribute(attributeName, value);
1390
1392
 
1391
1393
  }
@@ -1427,7 +1429,9 @@ var NativeComponents = (function (exports) {
1427
1429
  Array.prototype.toNdElement = function () {
1428
1430
  const fragment = document.createDocumentFragment();
1429
1431
  for(let i = 0, length = this.length; i < length; i++) {
1430
- fragment.appendChild(ElementCreator.getChild(this[i]));
1432
+ const child = ElementCreator.getChild(this[i]);
1433
+ if(child === null) continue;
1434
+ fragment.appendChild(child);
1431
1435
  }
1432
1436
  return fragment;
1433
1437
  };
@@ -1442,6 +1446,18 @@ var NativeComponents = (function (exports) {
1442
1446
  return ElementCreator.createHydratableNode(null, this);
1443
1447
  };
1444
1448
 
1449
+ String.prototype.handleNdAttribute = function(element, attributeName) {
1450
+ element.setAttribute(attributeName, this);
1451
+ };
1452
+
1453
+ ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1454
+ bindAttributeWithObservable(element, attributeName, this);
1455
+ };
1456
+
1457
+ TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
1458
+ this.$hydrate(element, attributeName);
1459
+ };
1460
+
1445
1461
  const $nodeCache = new Map();
1446
1462
  let $textNodeCache = null;
1447
1463
 
@@ -1513,20 +1529,10 @@ var NativeComponents = (function (exports) {
1513
1529
  processChildren(children, parent) {
1514
1530
  if(children === null) return;
1515
1531
  PluginsManager.emit('BeforeProcessChildren', parent);
1516
- if(!Array.isArray(children)) {
1517
- let child = this.getChild(children);
1518
- if(child) {
1519
- parent.appendChild(child);
1520
- }
1532
+ let child = this.getChild(children);
1533
+ if(child) {
1534
+ parent.appendChild(child);
1521
1535
  }
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
1536
  PluginsManager.emit('AfterProcessChildren', parent);
1531
1537
  },
1532
1538
  getChild(child) {
@@ -2367,7 +2373,7 @@ var NativeComponents = (function (exports) {
2367
2373
  */
2368
2374
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
2369
2375
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
2370
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
2376
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
2371
2377
  }
2372
2378
  const element = Anchor('Show if : '+(comment || ''));
2373
2379
 
@@ -2476,7 +2482,7 @@ var NativeComponents = (function (exports) {
2476
2482
  HtmlElementWrapper('meter');
2477
2483
 
2478
2484
 
2479
- const Button$1 = HtmlElementWrapper('button');
2485
+ const Button = HtmlElementWrapper('button');
2480
2486
 
2481
2487
  HtmlElementWrapper('main');
2482
2488
  HtmlElementWrapper('section');
@@ -3085,7 +3091,7 @@ var NativeComponents = (function (exports) {
3085
3091
 
3086
3092
  const ErrorDisplayer = (errors) => {
3087
3093
 
3088
- const shouldDisplayError = $$1.computed(() => {
3094
+ const shouldDisplayError = $.computed(() => {
3089
3095
  const val = errors.val();
3090
3096
  return (val && val.length > 0);
3091
3097
  }, [errors]);
@@ -3116,15 +3122,15 @@ var NativeComponents = (function (exports) {
3116
3122
  };
3117
3123
 
3118
3124
  if(description.showErrors) {
3119
- description.errors = description.errors || $$1(null);
3125
+ description.errors = description.errors || $(null);
3120
3126
  field.errors(description.errors);
3121
3127
  }
3122
3128
 
3123
- const hasErrors = description.showErrors ? $$1.computed(() => {
3129
+ const hasErrors = description.showErrors ? $.computed(() => {
3124
3130
  const errs = description.errors?.val();
3125
3131
  return errs && errs.length > 0;
3126
3132
  }, [description.errors]) : null;
3127
- const hasFocus = $$1(false);
3133
+ const hasFocus = $(false);
3128
3134
 
3129
3135
  const wrapperClasses = {
3130
3136
  [suffix+'-wrapper']: true,
@@ -3627,7 +3633,7 @@ var NativeComponents = (function (exports) {
3627
3633
  function DefaultLayout({ fields, form }) {
3628
3634
  return Form([
3629
3635
  Object.values(fields),
3630
- Button$1({ type: 'submit', disabled: form.submitting }, 'Submit')
3636
+ Button({ type: 'submit', disabled: form.submitting }, 'Submit')
3631
3637
  ]);
3632
3638
  }
3633
3639
 
@@ -4749,7 +4755,7 @@ var NativeComponents = (function (exports) {
4749
4755
 
4750
4756
  return Div({ class: 'field-collection-layout'}, [
4751
4757
  Div({ class: 'field-collection-layout-header'}, [
4752
- Button$1({ class: 'field-collection-layout-add-btn', type: 'button' }, ['Add +'])
4758
+ Button({ class: 'field-collection-layout-add-btn', type: 'button' }, ['Add +'])
4753
4759
  .nd.onClick(() => collection.add())
4754
4760
  ]),
4755
4761
  ForEachArray(data, Template)
@@ -5268,9 +5274,9 @@ var NativeComponents = (function (exports) {
5268
5274
  ...configs
5269
5275
  });
5270
5276
 
5271
- this.$currentPage = null;
5272
- this.$selectedRows = [];
5273
- this.$expandedRows = [];
5277
+ this.$currentPage = Observable(1);
5278
+ this.$selectedRows = Observable.array();
5279
+ this.$expandedRows = Observable.array();
5274
5280
  }
5275
5281
 
5276
5282
  DataTable.defaultToolbarTemplate = null;
@@ -5289,9 +5295,6 @@ var NativeComponents = (function (exports) {
5289
5295
 
5290
5296
  DataTable.prototype.paginate = function(size) {
5291
5297
  this.$description.pageSize = size;
5292
- if(size > 0) {
5293
- this.$currentPage = Observable(1);
5294
- }
5295
5298
  return this;
5296
5299
  };
5297
5300
 
@@ -5361,7 +5364,7 @@ var NativeComponents = (function (exports) {
5361
5364
  return this;
5362
5365
  };
5363
5366
 
5364
- DataTable.prototype.goToFistPage = function(page) {
5367
+ DataTable.prototype.goToFirstPage = function(page) {
5365
5368
  // TODO: implement this action
5366
5369
  return this;
5367
5370
  };
@@ -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,16 +1419,13 @@ var NativeDocument = (function (exports) {
1415
1419
  if(value === null || value === undefined) {
1416
1420
  continue;
1417
1421
  }
1422
+ if(value.handleNdAttribute) {
1423
+ value.handleNdAttribute(element, attributeName, value);
1424
+ continue;
1425
+ }
1418
1426
  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);
1427
+ element.setAttribute(attributeName, value);
1428
+ return;
1428
1429
  }
1429
1430
  if(attributeName === 'class' && Validator.isObject(value)) {
1430
1431
  bindClassAttribute(element, value);
@@ -1446,6 +1447,7 @@ var NativeDocument = (function (exports) {
1446
1447
  value.$hydrate(element, attributeName);
1447
1448
  continue;
1448
1449
  }
1450
+
1449
1451
  element.setAttribute(attributeName, value);
1450
1452
 
1451
1453
  }
@@ -1487,7 +1489,9 @@ var NativeDocument = (function (exports) {
1487
1489
  Array.prototype.toNdElement = function () {
1488
1490
  const fragment = document.createDocumentFragment();
1489
1491
  for(let i = 0, length = this.length; i < length; i++) {
1490
- fragment.appendChild(ElementCreator.getChild(this[i]));
1492
+ const child = ElementCreator.getChild(this[i]);
1493
+ if(child === null) continue;
1494
+ fragment.appendChild(child);
1491
1495
  }
1492
1496
  return fragment;
1493
1497
  };
@@ -1502,6 +1506,18 @@ var NativeDocument = (function (exports) {
1502
1506
  return ElementCreator.createHydratableNode(null, this);
1503
1507
  };
1504
1508
 
1509
+ String.prototype.handleNdAttribute = function(element, attributeName) {
1510
+ element.setAttribute(attributeName, this);
1511
+ };
1512
+
1513
+ ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1514
+ bindAttributeWithObservable(element, attributeName, this);
1515
+ };
1516
+
1517
+ TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
1518
+ this.$hydrate(element, attributeName);
1519
+ };
1520
+
1505
1521
  const $nodeCache = new Map();
1506
1522
  let $textNodeCache = null;
1507
1523
 
@@ -1573,20 +1589,10 @@ var NativeDocument = (function (exports) {
1573
1589
  processChildren(children, parent) {
1574
1590
  if(children === null) return;
1575
1591
  PluginsManager.emit('BeforeProcessChildren', parent);
1576
- if(!Array.isArray(children)) {
1577
- let child = this.getChild(children);
1578
- if(child) {
1579
- parent.appendChild(child);
1580
- }
1592
+ let child = this.getChild(children);
1593
+ if(child) {
1594
+ parent.appendChild(child);
1581
1595
  }
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
1596
  PluginsManager.emit('AfterProcessChildren', parent);
1591
1597
  },
1592
1598
  getChild(child) {
@@ -3512,9 +3518,7 @@ var NativeDocument = (function (exports) {
3512
3518
  },
3513
3519
  add(items, delay = 2) {
3514
3520
  const fragment = Actions.toFragment(items);
3515
- Promise.resolve().then(() => {
3516
- element.appendElement(fragment);
3517
- });
3521
+ element.appendElement(fragment);
3518
3522
  },
3519
3523
  replace(items) {
3520
3524
  clear();