native-document 1.0.118 → 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.
- package/dist/native-document.components.min.js +197 -38
- package/dist/native-document.dev.js +277 -134
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/docs/lifecycle-events.md +1 -1
- package/elements.js +2 -2
- package/package.json +1 -1
- package/src/core/data/ObservableArray.js +3 -1
- package/src/core/data/ObservableItem.js +3 -1
- package/src/core/elements/anchor/anchor-with-sentinel.js +41 -0
- package/src/core/elements/{anchor.js → anchor/anchor.js} +66 -19
- package/src/core/elements/anchor/one-child-anchor-overwriting.js +66 -0
- package/src/core/elements/control/for-each-array.js +53 -69
- package/src/core/elements/control/for-each.js +1 -1
- package/src/core/elements/control/show-if.js +1 -1
- package/src/core/elements/control/switch.js +1 -1
- package/src/core/wrappers/ElementCreator.js +1 -1
- package/src/core/wrappers/HtmlElementWrapper.js +5 -4
- package/src/core/wrappers/SingletonView.js +1 -1
- package/src/core/wrappers/prototypes/nd-element-extensions.js +4 -0
- package/src/core/wrappers/template-cloner/NodeCloner.js +2 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {Validator} from "../../../../index";
|
|
2
|
+
import {ElementCreator} from "../../wrappers/ElementCreator";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default function oneChildAnchorOverwriting(anchor, parent) {
|
|
6
|
+
|
|
7
|
+
anchor.remove = () => {
|
|
8
|
+
anchor.append.apply(anchor, parent.childNodes);
|
|
9
|
+
};
|
|
10
|
+
anchor.getParent = () => parent;
|
|
11
|
+
|
|
12
|
+
anchor.appendChild = (child) => {
|
|
13
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
14
|
+
parent.appendChild(child);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
anchor.appendChildRaw = parent.appendChild.bind(parent);
|
|
18
|
+
anchor.append = anchor.appendChild;
|
|
19
|
+
anchor.appendRaw = anchor.appendChildRaw;
|
|
20
|
+
|
|
21
|
+
anchor.insertAtStart = (child) => {
|
|
22
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
23
|
+
parent.firstChild ? parent.insertBefore(child, parent.firstChild) : parent.appendChild(child);
|
|
24
|
+
};
|
|
25
|
+
anchor.insertAtStartRaw = (child) => {
|
|
26
|
+
parent.firstChild ? parent.insertBefore(child, parent.firstChild) : parent.appendChild(child);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
anchor.appendElement = anchor.appendChild;
|
|
30
|
+
|
|
31
|
+
anchor.removeChildren = () => {
|
|
32
|
+
parent.textContent = '';
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
anchor.replaceContent = function(content) {
|
|
36
|
+
const child = Validator.isElement(content) ? content : ElementCreator.getChild(content);
|
|
37
|
+
parent.replaceChildren(child);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
anchor.replaceContentRaw = function(child) {
|
|
41
|
+
parent.replaceChildren(child);
|
|
42
|
+
};
|
|
43
|
+
anchor.setContent = anchor.replaceContent;
|
|
44
|
+
|
|
45
|
+
anchor.insertBefore = (child, anchor) => {
|
|
46
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
47
|
+
parent.insertBefore(child, anchor);
|
|
48
|
+
};
|
|
49
|
+
anchor.insertBeforeRaw = (child, anchor) => {
|
|
50
|
+
parent.insertBefore(child, anchor);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
anchor.appendChildBefore = anchor.insertBefore;
|
|
54
|
+
anchor.appendChildBeforeRaw = anchor.insertBeforeRaw;
|
|
55
|
+
|
|
56
|
+
anchor.clear = anchor.remove;
|
|
57
|
+
anchor.detach = anchor.remove;
|
|
58
|
+
|
|
59
|
+
anchor.replaceChildren = function() {
|
|
60
|
+
parent.replaceChildren(...arguments);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
anchor.getByIndex = (index) => {
|
|
64
|
+
return parent.childNodes[index];
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Anchor from "
|
|
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";
|
|
@@ -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
|
};
|
|
@@ -114,21 +117,23 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
114
117
|
};
|
|
115
118
|
|
|
116
119
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
let cleanCache;
|
|
121
|
+
|
|
122
|
+
if(!isIndexRequired) {
|
|
123
|
+
cleanCache = cache.clear.bind(cache);
|
|
124
|
+
}
|
|
125
|
+
else if(configs.shouldKeepItemsInCache) {
|
|
126
|
+
cleanCache = () => {};
|
|
127
|
+
} else {
|
|
128
|
+
cleanCache = (items) => {
|
|
129
|
+
for (const [itemAsKey, _] of cache.entries()) {
|
|
130
|
+
if(items && items.includes(itemAsKey)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
removeCacheItem(itemAsKey, false);
|
|
128
134
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
135
|
+
};
|
|
136
|
+
}
|
|
132
137
|
|
|
133
138
|
const removeByItem = (item, fragment) => {
|
|
134
139
|
const cacheItem = cache.get(item);
|
|
@@ -148,7 +153,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
148
153
|
};
|
|
149
154
|
|
|
150
155
|
const Actions = {
|
|
151
|
-
toFragment(items){
|
|
156
|
+
toFragment: (items) =>{
|
|
152
157
|
const fragment = document.createDocumentFragment();
|
|
153
158
|
for(let i = 0, length = items.length; i < length; i++) {
|
|
154
159
|
fragment.appendChild(buildItem(items[i], lastNumberOfItems));
|
|
@@ -156,14 +161,19 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
156
161
|
}
|
|
157
162
|
return fragment;
|
|
158
163
|
},
|
|
159
|
-
add(items) {
|
|
160
|
-
element.
|
|
164
|
+
add: (items) => {
|
|
165
|
+
element.appendChildRaw(Actions.toFragment(items));
|
|
166
|
+
},
|
|
167
|
+
replace: (items) => {
|
|
168
|
+
clearCacheOnly(items);
|
|
169
|
+
element.replaceContentRaw(Actions.toFragment(items));
|
|
161
170
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
set: () => {
|
|
172
|
+
const items = data.val();
|
|
173
|
+
clearCacheOnly(items);
|
|
174
|
+
element.replaceContentRaw(Actions.toFragment(items));
|
|
165
175
|
},
|
|
166
|
-
reOrder(items) {
|
|
176
|
+
reOrder: (items) => {
|
|
167
177
|
let child = null;
|
|
168
178
|
const fragment = document.createDocumentFragment();
|
|
169
179
|
for(const item of items) {
|
|
@@ -173,24 +183,13 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
173
183
|
}
|
|
174
184
|
}
|
|
175
185
|
child = null;
|
|
176
|
-
element.
|
|
186
|
+
element.appendElementRaw(fragment);
|
|
177
187
|
},
|
|
178
|
-
removeOne(element, index) {
|
|
188
|
+
removeOne: (element, index) => {
|
|
179
189
|
removeCacheItem(element, true);
|
|
180
190
|
},
|
|
181
191
|
clear,
|
|
182
|
-
|
|
183
|
-
Actions.add(items);
|
|
184
|
-
},
|
|
185
|
-
push(items) {
|
|
186
|
-
let delay = 0;
|
|
187
|
-
if(configs.pushDelay) {
|
|
188
|
-
delay = configs.pushDelay(items) ?? 0;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
Actions.add(items, delay);
|
|
192
|
-
},
|
|
193
|
-
populate([target, iteration, callback]) {
|
|
192
|
+
populate: ([target, iteration, callback]) => {
|
|
194
193
|
const fragment = document.createDocumentFragment();
|
|
195
194
|
for (let i = 0; i < iteration; i++) {
|
|
196
195
|
const data = callback(i);
|
|
@@ -198,13 +197,13 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
198
197
|
fragment.append(buildItem(data, i));
|
|
199
198
|
lastNumberOfItems++;
|
|
200
199
|
}
|
|
201
|
-
element.
|
|
200
|
+
element.appendChildRaw(fragment);
|
|
202
201
|
fragment.replaceChildren();
|
|
203
202
|
},
|
|
204
|
-
unshift(values){
|
|
205
|
-
element.
|
|
203
|
+
unshift: (values) => {
|
|
204
|
+
element.insertAtStartRaw(Actions.toFragment(values));
|
|
206
205
|
},
|
|
207
|
-
splice(args, deleted) {
|
|
206
|
+
splice: (args, deleted) => {
|
|
208
207
|
const [start, deleteCount, ...values] = args;
|
|
209
208
|
let elementBeforeFirst = null;
|
|
210
209
|
const garbageFragment = document.createDocumentFragment();
|
|
@@ -227,27 +226,27 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
227
226
|
garbageFragment.replaceChildren();
|
|
228
227
|
|
|
229
228
|
if(values && values.length && elementBeforeFirst) {
|
|
230
|
-
element.
|
|
229
|
+
element.insertBeforeRaw(Actions.toFragment(values), elementBeforeFirst.nextSibling);
|
|
231
230
|
}
|
|
232
231
|
|
|
233
232
|
},
|
|
234
|
-
reverse(_, reversed) {
|
|
233
|
+
reverse: (_, reversed) => {
|
|
235
234
|
Actions.reOrder(reversed);
|
|
236
235
|
},
|
|
237
|
-
sort(_, sorted) {
|
|
236
|
+
sort: (_, sorted) => {
|
|
238
237
|
Actions.reOrder(sorted);
|
|
239
238
|
},
|
|
240
|
-
remove(_, deleted) {
|
|
239
|
+
remove: (_, deleted)=> {
|
|
241
240
|
Actions.removeOne(deleted);
|
|
242
241
|
},
|
|
243
|
-
pop(_, deleted) {
|
|
242
|
+
pop: (_, deleted) => {
|
|
244
243
|
Actions.removeOne(deleted);
|
|
245
244
|
},
|
|
246
|
-
shift(_, deleted) {
|
|
245
|
+
shift: (_, deleted) => {
|
|
247
246
|
Actions.removeOne(deleted);
|
|
248
247
|
},
|
|
249
|
-
swap(args, elements) {
|
|
250
|
-
const parent =
|
|
248
|
+
swap: (args, elements) => {
|
|
249
|
+
const parent = element.getParent();
|
|
251
250
|
|
|
252
251
|
let childA = getItemChild(elements[0]);
|
|
253
252
|
let childB = getItemChild(elements[1]);
|
|
@@ -262,37 +261,22 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
262
261
|
childB = null;
|
|
263
262
|
}
|
|
264
263
|
};
|
|
264
|
+
Actions.merge = Actions.add;
|
|
265
|
+
Actions.push = Actions.add;
|
|
265
266
|
|
|
266
|
-
const buildContent = (items, _, operations) => {
|
|
267
|
-
|
|
268
|
-
if(lastNumberOfItems === 0) {
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
clear();
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
selectBuildStrategy(operations?.action);
|
|
267
|
+
const buildContent = (items, _, operations = {}) => {
|
|
268
|
+
selectBuildStrategy(operations.action);
|
|
275
269
|
|
|
276
|
-
if(
|
|
277
|
-
if(lastNumberOfItems === 0) {
|
|
278
|
-
Actions.add(items);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
Actions.replace(items);
|
|
282
|
-
}
|
|
283
|
-
else if(Actions[operations.action]) {
|
|
270
|
+
if(Actions[operations.action]) {
|
|
284
271
|
Actions[operations.action](operations.args, operations.result);
|
|
285
272
|
}
|
|
286
|
-
|
|
287
273
|
updateIndexObservers(items, 0);
|
|
288
274
|
};
|
|
289
275
|
|
|
290
276
|
if(data.val().length) {
|
|
291
277
|
buildContent(data.val(), null, {action: null});
|
|
292
278
|
}
|
|
293
|
-
|
|
294
|
-
data.subscribe(buildContent);
|
|
295
|
-
}
|
|
279
|
+
data.subscribe(buildContent);
|
|
296
280
|
|
|
297
281
|
return element;
|
|
298
282
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Observable} from "../../data/Observable";
|
|
2
2
|
import Validator from "../../utils/validator";
|
|
3
|
-
import Anchor from "
|
|
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 "
|
|
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 "
|
|
3
|
+
import Anchor from "../anchor/anchor";
|
|
4
4
|
import {ElementCreator} from "../../wrappers/ElementCreator";
|
|
5
5
|
|
|
6
6
|
|
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if(value) {
|
|
14
|
+
return value.toNdElement();
|
|
15
|
+
}
|
|
16
|
+
return ElementCreator.createTextNode();
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
|
|
@@ -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
|
};
|
|
@@ -50,8 +50,9 @@ NodeCloner.prototype.resolve = function() {
|
|
|
50
50
|
const methods = Object.keys(this.$ndMethods);
|
|
51
51
|
if(methods.length === 1) {
|
|
52
52
|
const methodName = methods[0];
|
|
53
|
+
const callback = this.$ndMethods[methodName];
|
|
53
54
|
steps.push((clonedNode, data) => {
|
|
54
|
-
clonedNode.nd[methodName](
|
|
55
|
+
clonedNode.nd[methodName](callback.bind(clonedNode, ...data));
|
|
55
56
|
});
|
|
56
57
|
} else {
|
|
57
58
|
steps.push((clonedNode, data) => {
|