native-document 1.0.25 → 1.0.26

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.is = 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);
@@ -887,6 +891,13 @@ var NativeDocument = (function (exports) {
887
891
  value.subscribe(newValue => element.classList.toggle(className, newValue));
888
892
  continue;
889
893
  }
894
+ if(value.$observer) {
895
+ element.classList.toggle(className, value.$observer.val());
896
+ value.$observer.on(value.$target, function(isTargetValue) {
897
+ element.classList.toggle(className, isTargetValue);
898
+ });
899
+ continue;
900
+ }
890
901
  element.classList.toggle(className, value);
891
902
  }
892
903
  }
@@ -983,8 +994,8 @@ var NativeDocument = (function (exports) {
983
994
  for(let key in attributes) {
984
995
  const attributeName = key.toLowerCase();
985
996
  let value = attributes[attributeName];
986
- if(Validator.isString(value) && Validator.isFunction(value.resolveObservableTemplate)) {
987
- value = value.resolveObservableTemplate();
997
+ if(Validator.isString(value)) {
998
+ value = value.resolveObservableTemplate ? value.resolveObservableTemplate() : value;
988
999
  if(Validator.isString(value)) {
989
1000
  element.setAttribute(attributeName, value);
990
1001
  continue;
@@ -1087,15 +1098,21 @@ var NativeDocument = (function (exports) {
1087
1098
  if(child === null) {
1088
1099
  return null;
1089
1100
  }
1090
- if(Validator.isString(child) && Validator.isFunction(child.resolveObservableTemplate)) {
1091
- child = child.resolveObservableTemplate();
1092
- }
1093
1101
  if(Validator.isString(child)) {
1094
- return ElementCreator.createStaticTextNode(null, child);
1102
+ child = child.resolveObservableTemplate ? child.resolveObservableTemplate() : child;
1103
+ if(Validator.isString(child)) {
1104
+ return ElementCreator.createStaticTextNode(null, child);
1105
+ }
1106
+ }
1107
+ if (Validator.isElement(child)) {
1108
+ return child;
1095
1109
  }
1096
1110
  if (Validator.isObservable(child)) {
1097
1111
  return ElementCreator.createObservableNode(null, child);
1098
1112
  }
1113
+ if(Validator.isNDElement(child)) {
1114
+ return child.$element ?? child.$build?.() ?? null;
1115
+ }
1099
1116
  if(Validator.isArray(child)) {
1100
1117
  const fragment = document.createDocumentFragment();
1101
1118
  for(let i = 0, length = child.length; i < length; i++) {
@@ -1106,12 +1123,6 @@ var NativeDocument = (function (exports) {
1106
1123
  if(Validator.isFunction(child)) {
1107
1124
  return this.getChild(child());
1108
1125
  }
1109
- if (Validator.isElement(child)) {
1110
- return child;
1111
- }
1112
- if(Validator.isNDElement(child)) {
1113
- return child.$element ?? child.$build?.() ?? null;
1114
- }
1115
1126
  return ElementCreator.createStaticTextNode(null, child);
1116
1127
  },
1117
1128
  /**
@@ -1899,8 +1910,9 @@ var NativeDocument = (function (exports) {
1899
1910
  return fragment;
1900
1911
  },
1901
1912
  add(items, delay = 0) {
1913
+ const fragment = Actions.toFragment(items);
1902
1914
  setTimeout(() => {
1903
- element.appendElement(Actions.toFragment(items));
1915
+ element.appendElement(fragment);
1904
1916
  }, delay);
1905
1917
  },
1906
1918
  replace(items) {
@@ -2013,26 +2025,23 @@ var NativeDocument = (function (exports) {
2013
2025
  };
2014
2026
 
2015
2027
  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();
2028
+ if(operations.action === 'clear' || !items.length) {
2029
+ if(lastNumberOfItems === 0) {
2030
+ return;
2024
2031
  }
2032
+ clear();
2033
+ return;
2034
+ }
2025
2035
 
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);
2036
+ if(!operations?.action) {
2037
+ if(lastNumberOfItems === 0) {
2038
+ Actions.add(items);
2039
+ return;
2035
2040
  }
2041
+ Actions.replace(items);
2042
+ }
2043
+ else if(Actions[operations.action]) {
2044
+ Actions[operations.action](operations.args, operations.result);
2036
2045
  }
2037
2046
 
2038
2047
  updateIndexObservers(items, 0);