native-document 1.0.117 → 1.0.119

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,4 +1,4 @@
1
- import Anchor from "../../elements/anchor";
1
+ import Anchor from "../anchor/anchor";
2
2
  import {Observable} from "../../data/Observable";
3
3
  import Validator from "../../utils/validator";
4
4
  import { ElementCreator } from "../../wrappers/ElementCreator";
@@ -114,21 +114,23 @@ export function ForEachArray(data, callback, configs = {}) {
114
114
  };
115
115
 
116
116
 
117
- const cleanCache = (items) => {
118
- if(!isIndexRequired) {
119
- cache.clear();
120
- return;
121
- }
122
- if(configs.shouldKeepItemsInCache) {
123
- return;
124
- }
125
- for (const [itemAsKey, _] of cache.entries()) {
126
- if(items && items.includes(itemAsKey)) {
127
- continue;
117
+ let cleanCache;
118
+
119
+ if(!isIndexRequired) {
120
+ cleanCache = cache.clear.bind(cache);
121
+ }
122
+ else if(configs.shouldKeepItemsInCache) {
123
+ cleanCache = () => {};
124
+ } else {
125
+ cleanCache = (items) => {
126
+ for (const [itemAsKey, _] of cache.entries()) {
127
+ if(items && items.includes(itemAsKey)) {
128
+ continue;
129
+ }
130
+ removeCacheItem(itemAsKey, false);
128
131
  }
129
- removeCacheItem(itemAsKey, false);
130
- }
131
- };
132
+ };
133
+ }
132
134
 
133
135
  const removeByItem = (item, fragment) => {
134
136
  const cacheItem = cache.get(item);
@@ -148,7 +150,7 @@ export function ForEachArray(data, callback, configs = {}) {
148
150
  };
149
151
 
150
152
  const Actions = {
151
- toFragment(items){
153
+ toFragment: (items) =>{
152
154
  const fragment = document.createDocumentFragment();
153
155
  for(let i = 0, length = items.length; i < length; i++) {
154
156
  fragment.appendChild(buildItem(items[i], lastNumberOfItems));
@@ -156,14 +158,14 @@ export function ForEachArray(data, callback, configs = {}) {
156
158
  }
157
159
  return fragment;
158
160
  },
159
- add(items) {
161
+ add: (items) => {
160
162
  element.appendElement(Actions.toFragment(items));
161
163
  },
162
- replace(items) {
164
+ replace: (items) => {
163
165
  clear(items);
164
166
  Actions.add(items);
165
167
  },
166
- reOrder(items) {
168
+ reOrder: (items) => {
167
169
  let child = null;
168
170
  const fragment = document.createDocumentFragment();
169
171
  for(const item of items) {
@@ -175,14 +177,14 @@ export function ForEachArray(data, callback, configs = {}) {
175
177
  child = null;
176
178
  element.appendElement(fragment, blockEnd);
177
179
  },
178
- removeOne(element, index) {
180
+ removeOne: (element, index) => {
179
181
  removeCacheItem(element, true);
180
182
  },
181
183
  clear,
182
- merge(items) {
184
+ merge: (items) => {
183
185
  Actions.add(items);
184
186
  },
185
- push(items) {
187
+ push: (items) => {
186
188
  let delay = 0;
187
189
  if(configs.pushDelay) {
188
190
  delay = configs.pushDelay(items) ?? 0;
@@ -190,7 +192,7 @@ export function ForEachArray(data, callback, configs = {}) {
190
192
 
191
193
  Actions.add(items, delay);
192
194
  },
193
- populate([target, iteration, callback]) {
195
+ populate: ([target, iteration, callback]) => {
194
196
  const fragment = document.createDocumentFragment();
195
197
  for (let i = 0; i < iteration; i++) {
196
198
  const data = callback(i);
@@ -201,10 +203,10 @@ export function ForEachArray(data, callback, configs = {}) {
201
203
  element.appendChild(fragment);
202
204
  fragment.replaceChildren();
203
205
  },
204
- unshift(values){
206
+ unshift: (values) => {
205
207
  element.insertBefore(Actions.toFragment(values), blockStart.nextSibling);
206
208
  },
207
- splice(args, deleted) {
209
+ splice: (args, deleted) => {
208
210
  const [start, deleteCount, ...values] = args;
209
211
  let elementBeforeFirst = null;
210
212
  const garbageFragment = document.createDocumentFragment();
@@ -231,22 +233,22 @@ export function ForEachArray(data, callback, configs = {}) {
231
233
  }
232
234
 
233
235
  },
234
- reverse(_, reversed) {
236
+ reverse: (_, reversed) => {
235
237
  Actions.reOrder(reversed);
236
238
  },
237
- sort(_, sorted) {
239
+ sort: (_, sorted) => {
238
240
  Actions.reOrder(sorted);
239
241
  },
240
- remove(_, deleted) {
242
+ remove: (_, deleted)=> {
241
243
  Actions.removeOne(deleted);
242
244
  },
243
- pop(_, deleted) {
245
+ pop: (_, deleted) => {
244
246
  Actions.removeOne(deleted);
245
247
  },
246
- shift(_, deleted) {
248
+ shift: (_, deleted) => {
247
249
  Actions.removeOne(deleted);
248
250
  },
249
- swap(args, elements) {
251
+ swap: (args, elements) => {
250
252
  const parent = blockEnd.parentNode;
251
253
 
252
254
  let childA = getItemChild(elements[0]);
@@ -1,6 +1,6 @@
1
1
  import {Observable} from "../../data/Observable";
2
2
  import Validator from "../../utils/validator";
3
- import Anchor from "../../elements/anchor";
3
+ import Anchor from "../anchor/anchor";
4
4
  import DebugManager from "../../utils/debug-manager";
5
5
  import {getKey} from "../../utils/helpers";
6
6
  import { ElementCreator } from "../../wrappers/ElementCreator";
@@ -1,7 +1,7 @@
1
1
  import { Observable } from "../../data/Observable";
2
2
  import Validator from "../../utils/validator";
3
3
  import DebugManager from "../../utils/debug-manager.js";
4
- import Anchor from "../../elements/anchor";
4
+ import Anchor from "../anchor/anchor";
5
5
  import {ElementCreator} from "../../wrappers/ElementCreator";
6
6
 
7
7
  /**
@@ -1,6 +1,6 @@
1
1
  import NativeDocumentError from "../../errors/NativeDocumentError";
2
2
  import Validator from "../../utils/validator";
3
- import Anchor from "../../elements/anchor";
3
+ import Anchor from "../anchor/anchor";
4
4
  import {ElementCreator} from "../../wrappers/ElementCreator";
5
5
 
6
6
 
@@ -27,7 +27,6 @@ export const bindClassAttribute = (element, data) => {
27
27
  }
28
28
  element.classes.toggle(className, value)
29
29
  }
30
- data = null;
31
30
  }
32
31
 
33
32
  /**
@@ -1,4 +1,4 @@
1
- import Anchor from "../elements/anchor";
1
+ import Anchor from "../elements/anchor/anchor";
2
2
  import Validator from "../utils/validator";
3
3
  import AttributesWrapper, { bindClassAttribute, bindStyleAttribute } from "./AttributesWrapper";
4
4
  import PluginsManager from "../utils/plugins-manager";
@@ -1,5 +1,5 @@
1
1
  import Validator from "../utils/validator";
2
- import Anchor from "../elements/anchor";
2
+ import Anchor from "../elements/anchor/anchor";
3
3
  import {ElementCreator} from "./ElementCreator";
4
4
  import './NdPrototype';
5
5
  import {normalizeComponentArgs} from "../utils/args-types";
@@ -10,9 +10,10 @@ import {normalizeComponentArgs} from "../utils/args-types";
10
10
  * @returns {Text}
11
11
  */
12
12
  export const createTextNode = (value) => {
13
- return (Validator.isObservable(value))
14
- ? ElementCreator.createObservableNode(null, value)
15
- : ElementCreator.createStaticTextNode(null, value);
13
+ if(value) {
14
+ return value.toNdElement();
15
+ }
16
+ return ElementCreator.createTextNode();
16
17
  };
17
18
 
18
19
 
@@ -1,4 +1,4 @@
1
- import Anchor from "../elements/anchor";
1
+ import Anchor from "../elements/anchor/anchor";
2
2
 
3
3
 
4
4
  export function SingletonView($viewCreator) {
@@ -9,6 +9,10 @@ String.prototype.toNdElement = function () {
9
9
  return ElementCreator.createStaticTextNode(null, this);
10
10
  };
11
11
 
12
+ Number.prototype.toNdElement = function () {
13
+ return ElementCreator.createStaticTextNode(null, this.toString());
14
+ };
15
+
12
16
  Element.prototype.toNdElement = function () {
13
17
  return this;
14
18
  };
@@ -47,29 +47,72 @@ NodeCloner.prototype.resolve = function() {
47
47
  }
48
48
  const steps = [];
49
49
  if(this.$ndMethods) {
50
- steps.push((clonedNode, data) => {
51
- for(const methodName in this.$ndMethods) {
52
- clonedNode.nd[methodName](this.$ndMethods[methodName].bind(clonedNode, ...data));
53
- }
54
- });
50
+ const methods = Object.keys(this.$ndMethods);
51
+ if(methods.length === 1) {
52
+ const methodName = methods[0];
53
+ const callback = this.$ndMethods[methodName];
54
+ steps.push((clonedNode, data) => {
55
+ clonedNode.nd[methodName](callback.bind(clonedNode, ...data));
56
+ });
57
+ } else {
58
+ steps.push((clonedNode, data) => {
59
+ const nd = clonedNode.nd;
60
+ for(const methodName in this.$ndMethods) {
61
+ nd[methodName](this.$ndMethods[methodName].bind(clonedNode, ...data));
62
+ }
63
+ });
64
+ }
55
65
  }
56
66
  if(this.$classes) {
57
67
  const cache = {};
58
- steps.push((clonedNode, data) => {
59
- ElementCreator.processClassAttribute(clonedNode, buildProperties(cache, this.$classes, data));
60
- });
68
+ const keys = Object.keys(this.$classes);
69
+
70
+ if(keys.length === 1) {
71
+ const key = keys[0];
72
+ const callback = this.$classes[key];
73
+ steps.push((clonedNode, data) => {
74
+ cache[key] = callback.apply(null, data);
75
+ ElementCreator.processClassAttribute(clonedNode, cache);
76
+ });
77
+ } else {
78
+ steps.push((clonedNode, data) => {
79
+ ElementCreator.processClassAttribute(clonedNode, buildProperties(cache, this.$classes, data));
80
+ });
81
+ }
61
82
  }
62
83
  if(this.$styles) {
63
84
  const cache = {};
64
- steps.push((clonedNode, data) => {
65
- ElementCreator.processStyleAttribute(clonedNode, buildProperties(cache, this.$styles, data));
66
- });
85
+ const keys = Object.keys(this.$styles);
86
+
87
+ if(keys.length === 1) {
88
+ const key = keys[0];
89
+ const callback = this.$styles[key];
90
+ steps.push((clonedNode, data) => {
91
+ cache[key] = callback.apply(null, data);
92
+ ElementCreator.processStyleAttribute(clonedNode, cache);
93
+ });
94
+ } else {
95
+ steps.push((clonedNode, data) => {
96
+ ElementCreator.processStyleAttribute(clonedNode, buildProperties(cache, this.$styles, data));
97
+ });
98
+ }
67
99
  }
68
100
  if(this.$attrs) {
69
101
  const cache = {};
70
- steps.push((clonedNode, data) => {
71
- ElementCreator.processAttributes(clonedNode, buildProperties(cache, this.$attrs, data));
72
- });
102
+ const keys = Object.keys(this.$attrs);
103
+
104
+ if(keys.length === 1) {
105
+ const key = keys[0];
106
+ const callback = this.$attrs[key];
107
+ steps.push((clonedNode, data) => {
108
+ cache[key] = callback.apply(null, data);
109
+ ElementCreator.processAttributes(clonedNode, cache);
110
+ });
111
+ } else {
112
+ steps.push((clonedNode, data) => {
113
+ ElementCreator.processAttributes(clonedNode, buildProperties(cache, this.$attrs, data));
114
+ });
115
+ }
73
116
  }
74
117
 
75
118
  const stepsCount = steps.length;
@@ -28,8 +28,7 @@ export function TemplateCloner($fn) {
28
28
  $node.dynamicCloneNode = (data) => {
29
29
  const clonedNode = $node.nodeCloner.cloneNode(data);
30
30
  for(let i = 0; i < childNodesLength; i++) {
31
- const child = childNodes[i].dynamicCloneNode(data);
32
- clonedNode.appendChild(child);
31
+ clonedNode.appendChild(childNodes[i].dynamicCloneNode(data));
33
32
  }
34
33
  return clonedNode;
35
34
  };
@@ -37,8 +36,7 @@ export function TemplateCloner($fn) {
37
36
  $node.dynamicCloneNode = (data) => {
38
37
  const clonedNode = $node.cloneNode();
39
38
  for(let i = 0; i < childNodesLength; i++) {
40
- const child = childNodes[i].dynamicCloneNode(data);
41
- clonedNode.appendChild(child);
39
+ clonedNode.appendChild(childNodes[i].dynamicCloneNode(data));
42
40
  }
43
41
  return clonedNode;
44
42
  };