native-document 1.0.119 → 1.0.120

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.
@@ -36,6 +36,9 @@ export function ForEachArray(data, callback, configs = {}) {
36
36
 
37
37
  const clear = (items) => {
38
38
  element.removeChildren();
39
+ clearCacheOnly(items)
40
+ };
41
+ const clearCacheOnly = (items) => {
39
42
  cleanCache(items);
40
43
  lastNumberOfItems = 0;
41
44
  };
@@ -159,11 +162,16 @@ export function ForEachArray(data, callback, configs = {}) {
159
162
  return fragment;
160
163
  },
161
164
  add: (items) => {
162
- element.appendElement(Actions.toFragment(items));
165
+ element.appendChildRaw(Actions.toFragment(items));
163
166
  },
164
167
  replace: (items) => {
165
- clear(items);
166
- Actions.add(items);
168
+ clearCacheOnly(items);
169
+ element.replaceContentRaw(Actions.toFragment(items));
170
+ },
171
+ set: () => {
172
+ const items = data.val();
173
+ clearCacheOnly(items);
174
+ element.replaceContentRaw(Actions.toFragment(items));
167
175
  },
168
176
  reOrder: (items) => {
169
177
  let child = null;
@@ -175,23 +183,12 @@ export function ForEachArray(data, callback, configs = {}) {
175
183
  }
176
184
  }
177
185
  child = null;
178
- element.appendElement(fragment, blockEnd);
186
+ element.appendElementRaw(fragment);
179
187
  },
180
188
  removeOne: (element, index) => {
181
189
  removeCacheItem(element, true);
182
190
  },
183
191
  clear,
184
- merge: (items) => {
185
- Actions.add(items);
186
- },
187
- push: (items) => {
188
- let delay = 0;
189
- if(configs.pushDelay) {
190
- delay = configs.pushDelay(items) ?? 0;
191
- }
192
-
193
- Actions.add(items, delay);
194
- },
195
192
  populate: ([target, iteration, callback]) => {
196
193
  const fragment = document.createDocumentFragment();
197
194
  for (let i = 0; i < iteration; i++) {
@@ -200,11 +197,11 @@ export function ForEachArray(data, callback, configs = {}) {
200
197
  fragment.append(buildItem(data, i));
201
198
  lastNumberOfItems++;
202
199
  }
203
- element.appendChild(fragment);
200
+ element.appendChildRaw(fragment);
204
201
  fragment.replaceChildren();
205
202
  },
206
203
  unshift: (values) => {
207
- element.insertBefore(Actions.toFragment(values), blockStart.nextSibling);
204
+ element.insertAtStartRaw(Actions.toFragment(values));
208
205
  },
209
206
  splice: (args, deleted) => {
210
207
  const [start, deleteCount, ...values] = args;
@@ -229,7 +226,7 @@ export function ForEachArray(data, callback, configs = {}) {
229
226
  garbageFragment.replaceChildren();
230
227
 
231
228
  if(values && values.length && elementBeforeFirst) {
232
- element.insertBefore(Actions.toFragment(values), elementBeforeFirst.nextSibling);
229
+ element.insertBeforeRaw(Actions.toFragment(values), elementBeforeFirst.nextSibling);
233
230
  }
234
231
 
235
232
  },
@@ -249,7 +246,7 @@ export function ForEachArray(data, callback, configs = {}) {
249
246
  Actions.removeOne(deleted);
250
247
  },
251
248
  swap: (args, elements) => {
252
- const parent = blockEnd.parentNode;
249
+ const parent = element.getParent();
253
250
 
254
251
  let childA = getItemChild(elements[0]);
255
252
  let childB = getItemChild(elements[1]);
@@ -264,37 +261,22 @@ export function ForEachArray(data, callback, configs = {}) {
264
261
  childB = null;
265
262
  }
266
263
  };
264
+ Actions.merge = Actions.add;
265
+ Actions.push = Actions.add;
267
266
 
268
- const buildContent = (items, _, operations) => {
269
- if(operations?.action === 'clear' || !items.length) {
270
- if(lastNumberOfItems === 0) {
271
- return;
272
- }
273
- clear();
274
- return;
275
- }
276
- selectBuildStrategy(operations?.action);
267
+ const buildContent = (items, _, operations = {}) => {
268
+ selectBuildStrategy(operations.action);
277
269
 
278
- if(!operations?.action) {
279
- if(lastNumberOfItems === 0) {
280
- Actions.add(items);
281
- return;
282
- }
283
- Actions.replace(items);
284
- }
285
- else if(Actions[operations.action]) {
270
+ if(Actions[operations.action]) {
286
271
  Actions[operations.action](operations.args, operations.result);
287
272
  }
288
-
289
273
  updateIndexObservers(items, 0);
290
274
  };
291
275
 
292
276
  if(data.val().length) {
293
277
  buildContent(data.val(), null, {action: null});
294
278
  }
295
- if(Validator.isObservable(data)) {
296
- data.subscribe(buildContent);
297
- }
279
+ data.subscribe(buildContent);
298
280
 
299
281
  return element;
300
282
  }