native-document 1.0.25 → 1.0.27

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.
@@ -331,6 +331,10 @@ var NativeDocument = (function (exports) {
331
331
  };
332
332
  ObservableItem.prototype.get = ObservableItem.prototype.check;
333
333
 
334
+ ObservableItem.prototype.when = function(value) {
335
+ return {$target: value, $observer: this};
336
+ };
337
+
334
338
  ObservableItem.prototype.toString = function() {
335
339
  if(!this.$memoryId) {
336
340
  MemoryManager.register(this);
@@ -501,7 +505,22 @@ var NativeDocument = (function (exports) {
501
505
  "Suspend",
502
506
  "TimeUpdate",
503
507
  "VolumeChange",
504
- "Waiting"
508
+ "Waiting",
509
+
510
+ "TouchCancel",
511
+ "TouchEnd",
512
+ "TouchMove",
513
+ "TouchStart",
514
+ "AnimationEnd",
515
+ "AnimationIteration",
516
+ "AnimationStart",
517
+ "TransitionEnd",
518
+ "Copy",
519
+ "Cut",
520
+ "Paste",
521
+ "FocusIn",
522
+ "FocusOut",
523
+ "ContextMenu"
505
524
  ];
506
525
 
507
526
  function NDElement(element) {
@@ -519,14 +538,14 @@ var NativeDocument = (function (exports) {
519
538
  NDElement.prototype['onPrevent'+event] = function(callback) {
520
539
  this.$element.addEventListener(eventName, function(event) {
521
540
  event.preventDefault();
522
- callback(event);
541
+ callback && callback(event);
523
542
  });
524
543
  return this;
525
544
  };
526
545
  NDElement.prototype['onStop'+event] = function(callback) {
527
546
  this.$element.addEventListener(eventName, function(event) {
528
547
  event.stopPropagation();
529
- callback(event);
548
+ callback && callback(event);
530
549
  });
531
550
  return this;
532
551
  };
@@ -534,7 +553,7 @@ var NativeDocument = (function (exports) {
534
553
  this.$element.addEventListener(eventName, function(event) {
535
554
  event.stopPropagation();
536
555
  event.preventDefault();
537
- callback(event);
556
+ callback && callback(event);
538
557
  });
539
558
  return this;
540
559
  };
@@ -887,6 +906,13 @@ var NativeDocument = (function (exports) {
887
906
  value.subscribe(newValue => element.classList.toggle(className, newValue));
888
907
  continue;
889
908
  }
909
+ if(value.$observer) {
910
+ element.classList.toggle(className, value.$observer.val());
911
+ value.$observer.on(value.$target, function(isTargetValue) {
912
+ element.classList.toggle(className, isTargetValue);
913
+ });
914
+ continue;
915
+ }
890
916
  element.classList.toggle(className, value);
891
917
  }
892
918
  }
@@ -983,8 +1009,8 @@ var NativeDocument = (function (exports) {
983
1009
  for(let key in attributes) {
984
1010
  const attributeName = key.toLowerCase();
985
1011
  let value = attributes[attributeName];
986
- if(Validator.isString(value) && Validator.isFunction(value.resolveObservableTemplate)) {
987
- value = value.resolveObservableTemplate();
1012
+ if(Validator.isString(value)) {
1013
+ value = value.resolveObservableTemplate ? value.resolveObservableTemplate() : value;
988
1014
  if(Validator.isString(value)) {
989
1015
  element.setAttribute(attributeName, value);
990
1016
  continue;
@@ -1087,15 +1113,21 @@ var NativeDocument = (function (exports) {
1087
1113
  if(child === null) {
1088
1114
  return null;
1089
1115
  }
1090
- if(Validator.isString(child) && Validator.isFunction(child.resolveObservableTemplate)) {
1091
- child = child.resolveObservableTemplate();
1092
- }
1093
1116
  if(Validator.isString(child)) {
1094
- return ElementCreator.createStaticTextNode(null, child);
1117
+ child = child.resolveObservableTemplate ? child.resolveObservableTemplate() : child;
1118
+ if(Validator.isString(child)) {
1119
+ return ElementCreator.createStaticTextNode(null, child);
1120
+ }
1121
+ }
1122
+ if (Validator.isElement(child)) {
1123
+ return child;
1095
1124
  }
1096
1125
  if (Validator.isObservable(child)) {
1097
1126
  return ElementCreator.createObservableNode(null, child);
1098
1127
  }
1128
+ if(Validator.isNDElement(child)) {
1129
+ return child.$element ?? child.$build?.() ?? null;
1130
+ }
1099
1131
  if(Validator.isArray(child)) {
1100
1132
  const fragment = document.createDocumentFragment();
1101
1133
  for(let i = 0, length = child.length; i < length; i++) {
@@ -1106,12 +1138,6 @@ var NativeDocument = (function (exports) {
1106
1138
  if(Validator.isFunction(child)) {
1107
1139
  return this.getChild(child());
1108
1140
  }
1109
- if (Validator.isElement(child)) {
1110
- return child;
1111
- }
1112
- if(Validator.isNDElement(child)) {
1113
- return child.$element ?? child.$build?.() ?? null;
1114
- }
1115
1141
  return ElementCreator.createStaticTextNode(null, child);
1116
1142
  },
1117
1143
  /**
@@ -1899,8 +1925,9 @@ var NativeDocument = (function (exports) {
1899
1925
  return fragment;
1900
1926
  },
1901
1927
  add(items, delay = 0) {
1928
+ const fragment = Actions.toFragment(items);
1902
1929
  setTimeout(() => {
1903
- element.appendElement(Actions.toFragment(items));
1930
+ element.appendElement(fragment);
1904
1931
  }, delay);
1905
1932
  },
1906
1933
  replace(items) {
@@ -2013,26 +2040,23 @@ var NativeDocument = (function (exports) {
2013
2040
  };
2014
2041
 
2015
2042
  const buildContent = (items, _, operations) => {
2016
- if(operations?.action === 'populate') {
2017
- Actions.populate(operations.args, operations.result);
2018
- } else {
2019
- if(operations.action === 'clear' || !items.length) {
2020
- if(lastNumberOfItems === 0) {
2021
- return;
2022
- }
2023
- clear();
2043
+ if(operations.action === 'clear' || !items.length) {
2044
+ if(lastNumberOfItems === 0) {
2045
+ return;
2024
2046
  }
2047
+ clear();
2048
+ return;
2049
+ }
2025
2050
 
2026
- if(!operations?.action) {
2027
- if(lastNumberOfItems === 0) {
2028
- Actions.add(items);
2029
- return;
2030
- }
2031
- Actions.replace(items);
2032
- }
2033
- else if(Actions[operations.action]) {
2034
- Actions[operations.action](operations.args, operations.result);
2051
+ if(!operations?.action) {
2052
+ if(lastNumberOfItems === 0) {
2053
+ Actions.add(items);
2054
+ return;
2035
2055
  }
2056
+ Actions.replace(items);
2057
+ }
2058
+ else if(Actions[operations.action]) {
2059
+ Actions[operations.action](operations.args, operations.result);
2036
2060
  }
2037
2061
 
2038
2062
  updateIndexObservers(items, 0);