native-document 1.0.77 → 1.0.79
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 +146 -120
- package/dist/native-document.dev.js +171 -125
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.devtools.min.js +1 -1
- package/dist/native-document.min.js +1 -1
- package/package.json +1 -1
- package/rollup.config.js +0 -16
- package/src/components/$traits/HasItems.js +1 -1
- package/src/components/accordion/Accordion.js +2 -2
- package/src/components/accordion/AccordionItem.js +2 -2
- package/src/components/alert/Alert.js +2 -2
- package/src/components/avatar/Avatar.js +2 -2
- package/src/components/badge/Badge.js +2 -2
- package/src/components/breadcrumb/BreadCrumb.js +2 -2
- package/src/components/button/Button.js +2 -2
- package/src/components/card/Card.js +1 -1
- package/src/components/context-menu/ContextMenu.js +2 -2
- package/src/components/context-menu/ContextMenuGroup.js +1 -1
- package/src/components/context-menu/ContextMenuItem.js +1 -1
- package/src/components/divider/Divider.js +1 -1
- package/src/components/dropdown/Dropdown.js +2 -2
- package/src/components/dropdown/DropdownDivider.js +1 -1
- package/src/components/dropdown/DropdownGroup.js +1 -1
- package/src/components/dropdown/DropdownItem.js +1 -1
- package/src/components/dropdown/DropdownTrigger.js +1 -1
- package/src/components/form/FormControl.js +5 -5
- package/src/components/form/field/DefaultRender.js +2 -2
- package/src/components/form/field/Field.js +4 -4
- package/src/components/form/field/FieldCollection.js +5 -5
- package/src/components/form/field/types/CheckboxField.js +1 -1
- package/src/components/form/field/types/ColorField.js +1 -1
- package/src/components/form/field/types/DateField.js +1 -1
- package/src/components/form/field/types/EmailField.js +1 -1
- package/src/components/form/field/types/FileField.js +1 -1
- package/src/components/form/field/types/ImageField.js +1 -1
- package/src/components/form/field/types/NumberField.js +1 -1
- package/src/components/form/field/types/PasswordField.js +1 -1
- package/src/components/form/field/types/RadioField.js +1 -1
- package/src/components/form/field/types/StringField.js +1 -1
- package/src/components/form/field/types/TelField.js +1 -1
- package/src/components/form/field/types/TimeField.js +1 -1
- package/src/components/form/field/types/UrlField.js +1 -1
- package/src/components/form/validation/Validation.js +1 -1
- package/src/components/list/List.js +4 -4
- package/src/components/list/ListGroup.js +2 -2
- package/src/components/list/ListItem.js +2 -2
- package/src/components/menu/Menu.js +3 -3
- package/src/components/menu/MenuDivider.js +1 -1
- package/src/components/menu/MenuGroup.js +2 -2
- package/src/components/menu/MenuItem.js +2 -2
- package/src/components/modal/Modal.js +2 -2
- package/src/components/pagination/Pagination.js +2 -2
- package/src/components/popover/Popover.js +2 -2
- package/src/components/popover/PopoverFooter.js +1 -1
- package/src/components/popover/PopoverHeader.js +1 -1
- package/src/components/progress/Progress.js +3 -3
- package/src/components/slider/Slider.js +2 -2
- package/src/components/splitter/Splitter.js +3 -4
- package/src/components/splitter/SplitterPanel.js +1 -1
- package/src/components/stepper/Stepper.js +3 -3
- package/src/components/stepper/StepperStep.js +2 -2
- package/src/components/switch/Switch.js +2 -2
- package/src/components/table/ColumnGroup.js +1 -1
- package/src/components/table/DataTable.js +1 -1
- package/src/components/table/SimpleTable.js +1 -1
- package/src/components/tabs/Tabs.js +2 -2
- package/src/components/toast/Toast.js +2 -2
- package/src/components/tooltip/prototypes.js +1 -1
- package/src/core/data/MemoryManager.js +1 -2
- package/src/core/data/Observable.js +1 -1
- package/src/core/data/ObservableArray.js +4 -4
- package/src/core/data/ObservableItem.js +5 -5
- package/src/core/data/observable-helpers/array.js +2 -2
- package/src/core/data/observable-helpers/batch.js +2 -2
- package/src/core/data/observable-helpers/computed.js +6 -6
- package/src/core/data/observable-helpers/object.js +2 -2
- package/src/core/elements/anchor.js +3 -3
- package/src/core/elements/content-formatter.js +1 -1
- package/src/core/elements/control/for-each-array.js +5 -6
- package/src/core/elements/control/for-each.js +7 -7
- package/src/core/elements/control/show-if.js +5 -5
- package/src/core/elements/control/show-when.js +2 -2
- package/src/core/elements/control/switch.js +4 -4
- package/src/core/elements/description-list.js +1 -1
- package/src/core/elements/form.js +1 -1
- package/src/core/elements/html5-semantics.js +1 -1
- package/src/core/elements/img.js +3 -3
- package/src/core/elements/index.js +1 -1
- package/src/core/elements/interactive.js +1 -1
- package/src/core/elements/list.js +1 -1
- package/src/core/elements/medias.js +1 -1
- package/src/core/elements/meta-data.js +1 -1
- package/src/core/elements/table.js +1 -1
- package/src/core/utils/EventEmitter.js +1 -1
- package/src/core/utils/args-types.js +2 -2
- package/src/core/utils/filters/standard.js +1 -1
- package/src/core/utils/filters/utils.js +1 -1
- package/src/core/utils/prototypes.js +2 -2
- package/src/core/utils/validator.js +5 -5
- package/src/core/wrappers/AttributesWrapper.js +3 -3
- package/src/core/wrappers/DocumentObserver.js +0 -1
- package/src/core/wrappers/ElementCreator.js +3 -3
- package/src/core/wrappers/HtmlElementWrapper.js +2 -2
- package/src/core/wrappers/NDElement.js +3 -3
- package/src/core/wrappers/NdPrototype.js +1 -1
- package/src/core/wrappers/SingletonView.js +1 -1
- package/src/core/wrappers/TemplateCloner.js +1 -2
- package/src/core/wrappers/prototypes/attributes-extensions.js +4 -4
- package/src/core/wrappers/prototypes/bind-class-extensions.js +4 -4
- package/src/core/wrappers/prototypes/nd-element-extensions.js +6 -6
- package/src/devtools/app/App.js +2 -2
- package/src/devtools/hrm/ComponentRegistry.js +2 -2
- package/src/devtools/plugin.js +1 -1
- package/src/devtools/widget/DevToolsWidget.js +2 -2
- package/src/router/Route.js +1 -1
- package/src/router/RouteGroupHelper.js +1 -1
- package/src/router/Router.js +4 -4
- package/src/router/RouterComponent.js +1 -1
- package/src/router/link.js +4 -4
- package/src/router/modes/HistoryRouter.js +1 -1
- package/types/control-flow.d.ts +0 -1
- package/types/filters/dates.d.ts +1 -1
- package/types/filters/types.d.ts +1 -1
- package/utils.js +3 -3
- package/jsconfig.json +0 -15
- /package/src/{core → router}/errors/RouterError.js +0 -0
|
@@ -259,15 +259,18 @@ var NativeDocument = (function (exports) {
|
|
|
259
259
|
* @returns {*}
|
|
260
260
|
*/
|
|
261
261
|
const getKey = (item, defaultKey, key) => {
|
|
262
|
-
if(Validator.
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
return (
|
|
262
|
+
if (Validator.isString(key)) {
|
|
263
|
+
const val = Validator.isObservable(item) ? item.val() : item;
|
|
264
|
+
const result = val?.[key];
|
|
265
|
+
return Validator.isObservable(result) ? result.val() : (result ?? defaultKey);
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
|
|
268
|
+
if (Validator.isFunction(key)) {
|
|
269
|
+
return key(item, defaultKey);
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
+
|
|
272
|
+
const val = Validator.isObservable(item) ? item.val() : item;
|
|
273
|
+
return val ?? defaultKey;
|
|
271
274
|
};
|
|
272
275
|
|
|
273
276
|
const trim = function(str, char) {
|
|
@@ -1050,6 +1053,7 @@ var NativeDocument = (function (exports) {
|
|
|
1050
1053
|
};
|
|
1051
1054
|
{
|
|
1052
1055
|
Validator.validateAttributes = function(attributes) {
|
|
1056
|
+
console.log('AttributesWrapper', attributes);
|
|
1053
1057
|
if (!attributes || typeof attributes !== 'object') {
|
|
1054
1058
|
return attributes;
|
|
1055
1059
|
}
|
|
@@ -1215,7 +1219,38 @@ var NativeDocument = (function (exports) {
|
|
|
1215
1219
|
return anchor;
|
|
1216
1220
|
}
|
|
1217
1221
|
|
|
1218
|
-
const BOOLEAN_ATTRIBUTES = [
|
|
1222
|
+
const BOOLEAN_ATTRIBUTES = new Set([
|
|
1223
|
+
'checked',
|
|
1224
|
+
'selected',
|
|
1225
|
+
'disabled',
|
|
1226
|
+
'readonly',
|
|
1227
|
+
'required',
|
|
1228
|
+
'autofocus',
|
|
1229
|
+
'multiple',
|
|
1230
|
+
'autocomplete',
|
|
1231
|
+
'hidden',
|
|
1232
|
+
'contenteditable',
|
|
1233
|
+
'spellcheck',
|
|
1234
|
+
'translate',
|
|
1235
|
+
'draggable',
|
|
1236
|
+
'async',
|
|
1237
|
+
'defer',
|
|
1238
|
+
'autoplay',
|
|
1239
|
+
'controls',
|
|
1240
|
+
'loop',
|
|
1241
|
+
'muted',
|
|
1242
|
+
'download',
|
|
1243
|
+
'reversed',
|
|
1244
|
+
'open',
|
|
1245
|
+
'default',
|
|
1246
|
+
'formnovalidate',
|
|
1247
|
+
'novalidate',
|
|
1248
|
+
'scoped',
|
|
1249
|
+
'itemscope',
|
|
1250
|
+
'allowfullscreen',
|
|
1251
|
+
'allowpaymentrequest',
|
|
1252
|
+
'playsinline'
|
|
1253
|
+
]);
|
|
1219
1254
|
|
|
1220
1255
|
/**
|
|
1221
1256
|
*
|
|
@@ -1404,6 +1439,12 @@ var NativeDocument = (function (exports) {
|
|
|
1404
1439
|
}
|
|
1405
1440
|
}
|
|
1406
1441
|
|
|
1442
|
+
const NdBindings = {
|
|
1443
|
+
class: (element, value) => bindClassAttribute(element, value),
|
|
1444
|
+
style: (element, value) => bindStyleAttribute(element, value),
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
|
|
1407
1448
|
/**
|
|
1408
1449
|
*
|
|
1409
1450
|
* @param {HTMLElement} element
|
|
@@ -1419,41 +1460,27 @@ var NativeDocument = (function (exports) {
|
|
|
1419
1460
|
|
|
1420
1461
|
for(let key in attributes) {
|
|
1421
1462
|
const attributeName = key.toLowerCase();
|
|
1422
|
-
let value = attributes[
|
|
1423
|
-
if(value
|
|
1463
|
+
let value = attributes[key];
|
|
1464
|
+
if(value == null) {
|
|
1424
1465
|
continue;
|
|
1425
1466
|
}
|
|
1426
1467
|
if(value.handleNdAttribute) {
|
|
1427
1468
|
value.handleNdAttribute(element, attributeName, value);
|
|
1428
1469
|
continue;
|
|
1429
1470
|
}
|
|
1430
|
-
if(
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
continue;
|
|
1437
|
-
}
|
|
1438
|
-
if(attributeName === 'style' && Validator.isObject(value)) {
|
|
1439
|
-
bindStyleAttribute(element, value);
|
|
1440
|
-
continue;
|
|
1471
|
+
if(typeof value === 'object') {
|
|
1472
|
+
const binding = NdBindings[attributeName];
|
|
1473
|
+
if(binding) {
|
|
1474
|
+
binding(element, value);
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1441
1477
|
}
|
|
1442
|
-
if(BOOLEAN_ATTRIBUTES.
|
|
1478
|
+
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
1443
1479
|
bindBooleanAttribute(element, attributeName, value);
|
|
1444
1480
|
continue;
|
|
1445
1481
|
}
|
|
1446
|
-
if(Validator.isObservable(value)) {
|
|
1447
|
-
bindAttributeWithObservable(element, attributeName, value);
|
|
1448
|
-
continue;
|
|
1449
|
-
}
|
|
1450
|
-
if(value.$hydrate) {
|
|
1451
|
-
value.$hydrate(element, attributeName);
|
|
1452
|
-
continue;
|
|
1453
|
-
}
|
|
1454
1482
|
|
|
1455
1483
|
element.setAttribute(attributeName, value);
|
|
1456
|
-
|
|
1457
1484
|
}
|
|
1458
1485
|
return element;
|
|
1459
1486
|
}
|
|
@@ -1514,8 +1541,16 @@ var NativeDocument = (function (exports) {
|
|
|
1514
1541
|
element.setAttribute(attributeName, this);
|
|
1515
1542
|
};
|
|
1516
1543
|
|
|
1544
|
+
Number.prototype.handleNdAttribute = function(element, attributeName) {
|
|
1545
|
+
element.setAttribute(attributeName, this);
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
Boolean.prototype.handleNdAttribute = function(element, attrName) {
|
|
1549
|
+
bindBooleanAttribute(element, attrName, this);
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1517
1552
|
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
1518
|
-
if(BOOLEAN_ATTRIBUTES.
|
|
1553
|
+
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
1519
1554
|
bindBooleanAttribute(element, attributeName, this);
|
|
1520
1555
|
return;
|
|
1521
1556
|
}
|
|
@@ -1605,22 +1640,14 @@ var NativeDocument = (function (exports) {
|
|
|
1605
1640
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
1606
1641
|
},
|
|
1607
1642
|
getChild(child) {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
child = child.toNdElement();
|
|
1614
|
-
if(Validator.isElement(child)) {
|
|
1615
|
-
return child;
|
|
1616
|
-
}
|
|
1617
|
-
if(child == null) {
|
|
1618
|
-
return null;
|
|
1619
|
-
}
|
|
1620
|
-
} while (child.toNdElement);
|
|
1643
|
+
while (child?.toNdElement) {
|
|
1644
|
+
child = child.toNdElement();
|
|
1645
|
+
|
|
1646
|
+
if (Validator.isElement(child)) return child;
|
|
1647
|
+
if (!child) return null;
|
|
1621
1648
|
}
|
|
1622
1649
|
|
|
1623
|
-
return ElementCreator.createStaticTextNode(null, child);
|
|
1650
|
+
return child ? ElementCreator.createStaticTextNode(null, child) : null;
|
|
1624
1651
|
},
|
|
1625
1652
|
/**
|
|
1626
1653
|
*
|
|
@@ -2088,7 +2115,7 @@ var NativeDocument = (function (exports) {
|
|
|
2088
2115
|
if(bindDingData.attributes) {
|
|
2089
2116
|
attributes = {};
|
|
2090
2117
|
for (const attr in bindDingData.attributes) {
|
|
2091
|
-
attributes[attr] = bindDingData.attributes[attr](
|
|
2118
|
+
attributes[attr] = bindDingData.attributes[attr].apply(null, data);
|
|
2092
2119
|
}
|
|
2093
2120
|
}
|
|
2094
2121
|
|
|
@@ -2096,7 +2123,7 @@ var NativeDocument = (function (exports) {
|
|
|
2096
2123
|
attributes = attributes || {};
|
|
2097
2124
|
attributes.class = {};
|
|
2098
2125
|
for (const className in bindDingData.classes) {
|
|
2099
|
-
attributes.class[className] = bindDingData.classes[className](
|
|
2126
|
+
attributes.class[className] = bindDingData.classes[className].apply(null, data);
|
|
2100
2127
|
}
|
|
2101
2128
|
}
|
|
2102
2129
|
|
|
@@ -2104,7 +2131,7 @@ var NativeDocument = (function (exports) {
|
|
|
2104
2131
|
attributes = attributes || {};
|
|
2105
2132
|
attributes.style = {};
|
|
2106
2133
|
for (const property in bindDingData.styles) {
|
|
2107
|
-
attributes.style[property] = bindDingData.styles[property](
|
|
2134
|
+
attributes.style[property] = bindDingData.styles[property].apply(null, data);
|
|
2108
2135
|
}
|
|
2109
2136
|
}
|
|
2110
2137
|
|
|
@@ -2116,6 +2143,14 @@ var NativeDocument = (function (exports) {
|
|
|
2116
2143
|
return null;
|
|
2117
2144
|
};
|
|
2118
2145
|
|
|
2146
|
+
const findByPath = (root, path) => {
|
|
2147
|
+
let target = root;
|
|
2148
|
+
for (let i = 0, len = path.length; i < len; i++) {
|
|
2149
|
+
target = target.childNodes[path[i]];
|
|
2150
|
+
}
|
|
2151
|
+
return target;
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2119
2154
|
const $hydrateFn = function(hydrateFunction, targetType, element, property) {
|
|
2120
2155
|
if(!cloneBindingsDataCache.has(element)) {
|
|
2121
2156
|
// { classes, styles, attributes, value, attach }
|
|
@@ -2136,7 +2171,7 @@ var NativeDocument = (function (exports) {
|
|
|
2136
2171
|
}
|
|
2137
2172
|
for(const methodName in bindDingData.attach) {
|
|
2138
2173
|
node.nd[methodName](function(...args) {
|
|
2139
|
-
bindDingData.attach[methodName].
|
|
2174
|
+
bindDingData.attach[methodName].apply(this, [...args, ...data]);
|
|
2140
2175
|
});
|
|
2141
2176
|
}
|
|
2142
2177
|
};
|
|
@@ -2145,44 +2180,78 @@ var NativeDocument = (function (exports) {
|
|
|
2145
2180
|
let $node = null;
|
|
2146
2181
|
let $hasBindingData = false;
|
|
2147
2182
|
|
|
2148
|
-
const
|
|
2183
|
+
const $bindingPaths = [];
|
|
2184
|
+
|
|
2185
|
+
const clone = (node, data, path) => {
|
|
2149
2186
|
const bindDingData = cloneBindingsDataCache.get(node);
|
|
2150
2187
|
if(node.nodeType === 3) {
|
|
2151
2188
|
if(bindDingData && bindDingData.value) {
|
|
2189
|
+
$bindingPaths.push({
|
|
2190
|
+
path: [...path],
|
|
2191
|
+
fn: (data, targetNode, currentRoot) => {
|
|
2192
|
+
const newNode = bindDingData.value(data);
|
|
2193
|
+
targetNode.replaceWith(newNode);
|
|
2194
|
+
if (targetNode === currentRoot) {
|
|
2195
|
+
return newNode;
|
|
2196
|
+
}
|
|
2197
|
+
return null;
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2152
2200
|
return bindDingData.value(data);
|
|
2153
2201
|
}
|
|
2154
2202
|
return node.cloneNode(true);
|
|
2155
2203
|
}
|
|
2156
2204
|
const nodeCloned = node.cloneNode(node.fullCloneNode);
|
|
2205
|
+
if(node.fullCloneNode) {
|
|
2206
|
+
return nodeCloned;
|
|
2207
|
+
}
|
|
2157
2208
|
if(bindDingData) {
|
|
2158
2209
|
bindAttributes(nodeCloned, bindDingData, data);
|
|
2159
2210
|
bindAttachMethods(nodeCloned, bindDingData, data);
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2211
|
+
$bindingPaths.push({
|
|
2212
|
+
path: [...path],
|
|
2213
|
+
fn: (data, targetNode) => {
|
|
2214
|
+
bindAttributes(targetNode, bindDingData, data);
|
|
2215
|
+
bindAttachMethods(targetNode, bindDingData, data);
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2163
2218
|
}
|
|
2164
2219
|
const childNodes = node.childNodes;
|
|
2165
2220
|
for(let i = 0, length = childNodes.length; i < length; i++) {
|
|
2166
2221
|
const childNode = childNodes[i];
|
|
2167
|
-
|
|
2222
|
+
path.push(i);
|
|
2223
|
+
const childNodeCloned = clone(childNode, data, path);
|
|
2224
|
+
path.pop();
|
|
2168
2225
|
nodeCloned.appendChild(childNodeCloned);
|
|
2169
2226
|
}
|
|
2170
2227
|
return nodeCloned;
|
|
2171
2228
|
};
|
|
2172
2229
|
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2230
|
+
const cloneWithBindingPaths = (data) => {
|
|
2231
|
+
let root = $node.cloneNode(true);
|
|
2232
|
+
|
|
2233
|
+
for (let i = 0, len = $bindingPaths.length; i < len; i++) {
|
|
2234
|
+
const binding = $bindingPaths[i];
|
|
2235
|
+
const target = findByPath(root, binding.path);
|
|
2236
|
+
const newRoot = binding.fn(data, target, root);
|
|
2237
|
+
if(newRoot) {
|
|
2238
|
+
root = newRoot;
|
|
2180
2239
|
}
|
|
2181
2240
|
}
|
|
2241
|
+
|
|
2242
|
+
return root;
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
this.clone = (data) => {
|
|
2246
|
+
$node = $fn(this);
|
|
2182
2247
|
if(!$hasBindingData) {
|
|
2248
|
+
this.clone = () => $node.cloneNode(true);
|
|
2183
2249
|
return $node.cloneNode(true);
|
|
2184
2250
|
}
|
|
2185
|
-
|
|
2251
|
+
|
|
2252
|
+
const firstClone = clone($node, data, []);
|
|
2253
|
+
this.clone = cloneWithBindingPaths;
|
|
2254
|
+
return firstClone;
|
|
2186
2255
|
};
|
|
2187
2256
|
|
|
2188
2257
|
|
|
@@ -2835,6 +2904,9 @@ var NativeDocument = (function (exports) {
|
|
|
2835
2904
|
});
|
|
2836
2905
|
|
|
2837
2906
|
ObservableArray.prototype.clear = function() {
|
|
2907
|
+
if(this.$currentValue.length === 0) {
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2838
2910
|
this.$currentValue.length = 0;
|
|
2839
2911
|
this.trigger({ action: 'clear' });
|
|
2840
2912
|
return true;
|
|
@@ -3444,7 +3516,7 @@ var NativeDocument = (function (exports) {
|
|
|
3444
3516
|
return element;
|
|
3445
3517
|
}
|
|
3446
3518
|
|
|
3447
|
-
function ForEachArray(data, callback,
|
|
3519
|
+
function ForEachArray(data, callback, configs = {}) {
|
|
3448
3520
|
const element = Anchor('ForEach Array');
|
|
3449
3521
|
const blockEnd = element.endElement();
|
|
3450
3522
|
const blockStart = element.startElement();
|
|
@@ -3453,23 +3525,14 @@ var NativeDocument = (function (exports) {
|
|
|
3453
3525
|
let lastNumberOfItems = 0;
|
|
3454
3526
|
const isIndexRequired = callback.length >= 2;
|
|
3455
3527
|
|
|
3456
|
-
const
|
|
3457
|
-
|
|
3458
|
-
const clear = () => {
|
|
3528
|
+
const clear = (items) => {
|
|
3459
3529
|
element.removeChildren();
|
|
3460
|
-
cleanCache();
|
|
3530
|
+
cleanCache(items);
|
|
3461
3531
|
lastNumberOfItems = 0;
|
|
3462
3532
|
};
|
|
3463
3533
|
|
|
3464
|
-
const getItemKey = (item, indexKey) => {
|
|
3465
|
-
if(keysCache.has(item)) {
|
|
3466
|
-
return keysCache.get(item);
|
|
3467
|
-
}
|
|
3468
|
-
return getKey(item, indexKey, key);
|
|
3469
|
-
};
|
|
3470
|
-
|
|
3471
3534
|
const getItemChild = (item) => {
|
|
3472
|
-
return
|
|
3535
|
+
return cache.get(item)?.child;
|
|
3473
3536
|
};
|
|
3474
3537
|
|
|
3475
3538
|
const updateIndexObservers = (items, startFrom = 0) => {
|
|
@@ -3478,16 +3541,17 @@ var NativeDocument = (function (exports) {
|
|
|
3478
3541
|
}
|
|
3479
3542
|
let index = startFrom;
|
|
3480
3543
|
for(let i = startFrom, length = items?.length; i < length; i++) {
|
|
3481
|
-
const cacheItem = cache.get(
|
|
3544
|
+
const cacheItem = cache.get(items[i]);
|
|
3482
3545
|
if(!cacheItem) {
|
|
3483
3546
|
continue;
|
|
3484
3547
|
}
|
|
3485
|
-
cacheItem.indexObserver?.
|
|
3548
|
+
cacheItem.indexObserver?.set(index);
|
|
3486
3549
|
index++;
|
|
3487
3550
|
}
|
|
3488
3551
|
};
|
|
3489
3552
|
|
|
3490
|
-
const removeCacheItem = (
|
|
3553
|
+
const removeCacheItem = (item, removeChild = true) => {
|
|
3554
|
+
const cacheItem = cache.get(item);
|
|
3491
3555
|
if(!cacheItem) {
|
|
3492
3556
|
return;
|
|
3493
3557
|
}
|
|
@@ -3496,14 +3560,10 @@ var NativeDocument = (function (exports) {
|
|
|
3496
3560
|
child?.remove();
|
|
3497
3561
|
cache.delete(cacheItem.keyId);
|
|
3498
3562
|
}
|
|
3499
|
-
cacheItem.indexObserver?.
|
|
3563
|
+
cacheItem.indexObserver?.cleanup();
|
|
3500
3564
|
};
|
|
3501
3565
|
|
|
3502
|
-
const
|
|
3503
|
-
removeCacheItem(cache.get(keyId), removeChild);
|
|
3504
|
-
};
|
|
3505
|
-
|
|
3506
|
-
const cleanCache = () => {
|
|
3566
|
+
const cleanCache = (items) => {
|
|
3507
3567
|
if(configs.shouldKeepItemsInCache) {
|
|
3508
3568
|
return;
|
|
3509
3569
|
}
|
|
@@ -3511,53 +3571,41 @@ var NativeDocument = (function (exports) {
|
|
|
3511
3571
|
cache.clear();
|
|
3512
3572
|
return;
|
|
3513
3573
|
}
|
|
3514
|
-
for (const [
|
|
3515
|
-
|
|
3574
|
+
for (const [itemAsKey, _] of cache.entries()) {
|
|
3575
|
+
if(items && items.contains(itemAsKey)) {
|
|
3576
|
+
continue;
|
|
3577
|
+
}
|
|
3578
|
+
removeCacheItem(itemAsKey, false);
|
|
3516
3579
|
}
|
|
3517
3580
|
cache.clear();
|
|
3518
3581
|
};
|
|
3519
3582
|
|
|
3520
3583
|
const buildItem = (item, indexKey) => {
|
|
3521
|
-
const
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
const cacheItem = cache.get(keyId);
|
|
3525
|
-
cacheItem.indexObserver?.deref()?.set(indexKey);
|
|
3584
|
+
const cacheItem = cache.get(item);
|
|
3585
|
+
if(cacheItem) {
|
|
3586
|
+
cacheItem.indexObserver?.set(indexKey);
|
|
3526
3587
|
const child = cacheItem.child;
|
|
3527
3588
|
if(child) {
|
|
3528
3589
|
return child;
|
|
3529
3590
|
}
|
|
3530
|
-
cache.delete(
|
|
3591
|
+
cache.delete(item);
|
|
3531
3592
|
}
|
|
3532
3593
|
|
|
3533
3594
|
const indexObserver = isIndexRequired ? Observable(indexKey) : null;
|
|
3534
3595
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
3535
|
-
if(
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
|
|
3542
|
-
});
|
|
3543
|
-
keysCache.set(item, keyId);
|
|
3544
|
-
return child;
|
|
3545
|
-
};
|
|
3546
|
-
const getChildByKey = function(keyId) {
|
|
3547
|
-
const cacheItem = cache.get(keyId);
|
|
3548
|
-
if(!cacheItem) {
|
|
3549
|
-
return null;
|
|
3550
|
-
}
|
|
3551
|
-
const child = cacheItem.child;
|
|
3552
|
-
if(!child) {
|
|
3553
|
-
removeCacheItem(cacheItem, false);
|
|
3554
|
-
return null;
|
|
3596
|
+
if(child) {
|
|
3597
|
+
cache.set(item, {
|
|
3598
|
+
child,
|
|
3599
|
+
indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
|
|
3600
|
+
});
|
|
3601
|
+
return child;
|
|
3555
3602
|
}
|
|
3556
|
-
|
|
3603
|
+
|
|
3604
|
+
throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
|
|
3557
3605
|
};
|
|
3558
3606
|
|
|
3559
|
-
const
|
|
3560
|
-
const cacheItem = cache.get(
|
|
3607
|
+
const removeByItem = function(item, fragment) {
|
|
3608
|
+
const cacheItem = cache.get(item);
|
|
3561
3609
|
if(!cacheItem) {
|
|
3562
3610
|
return null;
|
|
3563
3611
|
}
|
|
@@ -3583,11 +3631,10 @@ var NativeDocument = (function (exports) {
|
|
|
3583
3631
|
return fragment;
|
|
3584
3632
|
},
|
|
3585
3633
|
add(items, delay = 2) {
|
|
3586
|
-
|
|
3587
|
-
element.appendElement(fragment);
|
|
3634
|
+
element.appendElement(Actions.toFragment(items));
|
|
3588
3635
|
},
|
|
3589
3636
|
replace(items) {
|
|
3590
|
-
clear();
|
|
3637
|
+
clear(items);
|
|
3591
3638
|
Actions.add(items);
|
|
3592
3639
|
},
|
|
3593
3640
|
reOrder(items) {
|
|
@@ -3603,7 +3650,7 @@ var NativeDocument = (function (exports) {
|
|
|
3603
3650
|
element.appendElement(fragment, blockEnd);
|
|
3604
3651
|
},
|
|
3605
3652
|
removeOne(element, index) {
|
|
3606
|
-
|
|
3653
|
+
removeCacheItem(element, true);
|
|
3607
3654
|
},
|
|
3608
3655
|
clear,
|
|
3609
3656
|
merge(items) {
|
|
@@ -3637,16 +3684,15 @@ var NativeDocument = (function (exports) {
|
|
|
3637
3684
|
const garbageFragment = document.createDocumentFragment();
|
|
3638
3685
|
|
|
3639
3686
|
if(deleted.length > 0) {
|
|
3640
|
-
let
|
|
3687
|
+
let firstItem = deleted[0];
|
|
3641
3688
|
if(deleted.length === 1) {
|
|
3642
|
-
|
|
3689
|
+
removeByItem(firstItem, garbageFragment);
|
|
3643
3690
|
} else if(deleted.length > 1) {
|
|
3644
|
-
const firstChildRemoved =
|
|
3691
|
+
const firstChildRemoved = getItemChild(deleted[0]);
|
|
3645
3692
|
elementBeforeFirst = firstChildRemoved?.previousSibling;
|
|
3646
3693
|
|
|
3647
3694
|
for(let i = 0; i < deleted.length; i++) {
|
|
3648
|
-
|
|
3649
|
-
removeByKey(keyId, garbageFragment);
|
|
3695
|
+
firstItem(deleted[i], garbageFragment);
|
|
3650
3696
|
}
|
|
3651
3697
|
}
|
|
3652
3698
|
} else {
|