native-document 1.0.119 → 1.0.121
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 +122 -59
- package/dist/native-document.dev.js +195 -146
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- 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.js +40 -9
- package/src/core/elements/anchor/one-child-anchor-overwriting.js +23 -1
- package/src/core/elements/control/for-each-array.js +22 -40
- package/src/core/wrappers/AttributesWrapper.js +32 -40
- package/src/core/wrappers/ElementCreator.js +1 -0
- package/src/core/wrappers/prototypes/attributes-extensions.js +4 -5
- package/src/core/wrappers/prototypes/bind-class-extensions.js +10 -5
- package/src/core/wrappers/template-cloner/NodeCloner.js +7 -4
|
@@ -1486,6 +1486,8 @@ var NativeComponents = (function (exports) {
|
|
|
1486
1486
|
};
|
|
1487
1487
|
ObservableItem.prototype.trigger = noneTrigger;
|
|
1488
1488
|
|
|
1489
|
+
|
|
1490
|
+
const $setOperation = { action: 'set' };
|
|
1489
1491
|
ObservableItem.prototype.$updateWithNewValue = function(newValue) {
|
|
1490
1492
|
newValue = newValue?.__$isObservable ? newValue.val() : newValue;
|
|
1491
1493
|
if(this.$currentValue === newValue) {
|
|
@@ -1493,7 +1495,7 @@ var NativeComponents = (function (exports) {
|
|
|
1493
1495
|
}
|
|
1494
1496
|
this.$previousValue = this.$currentValue;
|
|
1495
1497
|
this.$currentValue = newValue;
|
|
1496
|
-
this.trigger();
|
|
1498
|
+
this.trigger($setOperation);
|
|
1497
1499
|
this.$previousValue = null;
|
|
1498
1500
|
};
|
|
1499
1501
|
|
|
@@ -1967,22 +1969,7 @@ var NativeComponents = (function (exports) {
|
|
|
1967
1969
|
*/
|
|
1968
1970
|
const bindClassAttribute = (element, data) => {
|
|
1969
1971
|
for(const className in data) {
|
|
1970
|
-
|
|
1971
|
-
if(value.__$isObservable) {
|
|
1972
|
-
element.classes.toggle(className, value.val());
|
|
1973
|
-
value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
1974
|
-
continue;
|
|
1975
|
-
}
|
|
1976
|
-
if(value.__$isObservableWhen) {
|
|
1977
|
-
element.classes.toggle(className, value.isActive());
|
|
1978
|
-
value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
1979
|
-
continue;
|
|
1980
|
-
}
|
|
1981
|
-
if(value.$hydrate) {
|
|
1982
|
-
value.$hydrate(element, className);
|
|
1983
|
-
continue;
|
|
1984
|
-
}
|
|
1985
|
-
element.classes.toggle(className, value);
|
|
1972
|
+
data[className].bindClassProperty(element, className);
|
|
1986
1973
|
}
|
|
1987
1974
|
};
|
|
1988
1975
|
|
|
@@ -2052,39 +2039,47 @@ var NativeComponents = (function (exports) {
|
|
|
2052
2039
|
element.setAttribute(attributeName, value.val());
|
|
2053
2040
|
};
|
|
2054
2041
|
|
|
2055
|
-
/**
|
|
2056
|
-
*
|
|
2057
|
-
* @param {HTMLElement} element
|
|
2058
|
-
* @param {Object} attributes
|
|
2059
|
-
*/
|
|
2060
|
-
const AttributesWrapper = (element, attributes) => {
|
|
2061
2042
|
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2043
|
+
const AttributeHandlers = {
|
|
2044
|
+
string: (element, attributeName, value) => element.setAttribute(attributeName, value),
|
|
2045
|
+
number: (element, attributeName, value) => element.setAttribute(attributeName, value),
|
|
2046
|
+
boolean: (element, attributeName, value) => bindBooleanAttribute(element, attributeName, value),
|
|
2047
|
+
object: (element, attributeName, value) => {
|
|
2065
2048
|
if(value == null) {
|
|
2066
|
-
|
|
2049
|
+
return;
|
|
2067
2050
|
}
|
|
2051
|
+
|
|
2068
2052
|
if(value.handleNdAttribute) {
|
|
2069
|
-
value.handleNdAttribute(element, attributeName
|
|
2070
|
-
|
|
2053
|
+
value.handleNdAttribute(element, attributeName);
|
|
2054
|
+
return;
|
|
2071
2055
|
}
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
}
|
|
2056
|
+
|
|
2057
|
+
if(attributeName === 'class') {
|
|
2058
|
+
bindClassAttribute(element, value);
|
|
2059
|
+
return;
|
|
2060
|
+
}
|
|
2061
|
+
if(attributeName === 'style') {
|
|
2062
|
+
bindStyleAttribute(element, value);
|
|
2063
|
+
return;
|
|
2081
2064
|
}
|
|
2082
2065
|
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
2083
2066
|
bindBooleanAttribute(element, attributeName, value);
|
|
2084
|
-
continue;
|
|
2085
2067
|
}
|
|
2068
|
+
}
|
|
2069
|
+
};
|
|
2086
2070
|
|
|
2087
|
-
|
|
2071
|
+
/**
|
|
2072
|
+
*
|
|
2073
|
+
* @param {HTMLElement} element
|
|
2074
|
+
* @param {Object} attributes
|
|
2075
|
+
*/
|
|
2076
|
+
const AttributesWrapper = (element, attributes) => {
|
|
2077
|
+
|
|
2078
|
+
for(const originalAttributeName in attributes) {
|
|
2079
|
+
const attributeName = originalAttributeName.toLowerCase();
|
|
2080
|
+
let value = attributes[originalAttributeName];
|
|
2081
|
+
const typeOf = typeof value;
|
|
2082
|
+
AttributeHandlers[typeOf](element, attributeName, value);
|
|
2088
2083
|
}
|
|
2089
2084
|
return element;
|
|
2090
2085
|
};
|
|
@@ -2224,10 +2219,6 @@ var NativeComponents = (function (exports) {
|
|
|
2224
2219
|
return this;
|
|
2225
2220
|
};
|
|
2226
2221
|
|
|
2227
|
-
String.prototype.handleNdAttribute = function(element, attributeName) {
|
|
2228
|
-
element.setAttribute(attributeName, this);
|
|
2229
|
-
};
|
|
2230
|
-
|
|
2231
2222
|
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
2232
2223
|
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
2233
2224
|
bindBooleanAttribute(element, attributeName, this);
|
|
@@ -2237,6 +2228,20 @@ var NativeComponents = (function (exports) {
|
|
|
2237
2228
|
bindAttributeWithObservable(element, attributeName, this);
|
|
2238
2229
|
};
|
|
2239
2230
|
|
|
2231
|
+
ObservableItem.prototype.bindClassProperty = function(element, className) {
|
|
2232
|
+
element.classes.toggle(className, this.val());
|
|
2233
|
+
this.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
2234
|
+
};
|
|
2235
|
+
|
|
2236
|
+
ObservableWhen.prototype.bindClassProperty = function(element, className) {
|
|
2237
|
+
element.classes.toggle(className, this.isActive());
|
|
2238
|
+
this.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2241
|
+
Boolean.prototype.bindClassProperty = function(element, className) {
|
|
2242
|
+
element.classes.toggle(className, this);
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2240
2245
|
let $textNodeCache = null;
|
|
2241
2246
|
|
|
2242
2247
|
const ElementCreator = {
|
|
@@ -2399,29 +2404,51 @@ var NativeComponents = (function (exports) {
|
|
|
2399
2404
|
anchor.remove = () => {
|
|
2400
2405
|
anchor.append.apply(anchor, parent.childNodes);
|
|
2401
2406
|
};
|
|
2407
|
+
anchor.getParent = () => parent;
|
|
2402
2408
|
|
|
2403
2409
|
anchor.appendChild = (child) => {
|
|
2404
2410
|
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2405
2411
|
parent.appendChild(child);
|
|
2406
2412
|
};
|
|
2407
2413
|
|
|
2414
|
+
anchor.appendChildRaw = parent.appendChild.bind(parent);
|
|
2415
|
+
anchor.append = anchor.appendChild;
|
|
2416
|
+
anchor.appendRaw = anchor.appendChildRaw;
|
|
2417
|
+
|
|
2418
|
+
anchor.insertAtStart = (child) => {
|
|
2419
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2420
|
+
parent.firstChild ? parent.insertBefore(child, parent.firstChild) : parent.appendChild(child);
|
|
2421
|
+
};
|
|
2422
|
+
anchor.insertAtStartRaw = (child) => {
|
|
2423
|
+
parent.firstChild ? parent.insertBefore(child, parent.firstChild) : parent.appendChild(child);
|
|
2424
|
+
};
|
|
2425
|
+
|
|
2408
2426
|
anchor.appendElement = anchor.appendChild;
|
|
2409
2427
|
|
|
2410
2428
|
anchor.removeChildren = () => {
|
|
2411
|
-
parent.
|
|
2429
|
+
parent.textContent = '';
|
|
2412
2430
|
};
|
|
2413
2431
|
|
|
2414
2432
|
anchor.replaceContent = function(content) {
|
|
2415
2433
|
const child = Validator.isElement(content) ? content : ElementCreator.getChild(content);
|
|
2416
2434
|
parent.replaceChildren(child);
|
|
2417
2435
|
};
|
|
2436
|
+
|
|
2437
|
+
anchor.replaceContentRaw = function(child) {
|
|
2438
|
+
parent.replaceChildren(child);
|
|
2439
|
+
};
|
|
2418
2440
|
anchor.setContent = anchor.replaceContent;
|
|
2419
2441
|
|
|
2420
2442
|
anchor.insertBefore = (child, anchor) => {
|
|
2421
2443
|
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2422
2444
|
parent.insertBefore(child, anchor);
|
|
2423
2445
|
};
|
|
2446
|
+
anchor.insertBeforeRaw = (child, anchor) => {
|
|
2447
|
+
parent.insertBefore(child, anchor);
|
|
2448
|
+
};
|
|
2449
|
+
|
|
2424
2450
|
anchor.appendChildBefore = anchor.insertBefore;
|
|
2451
|
+
anchor.appendChildBeforeRaw = anchor.insertBeforeRaw;
|
|
2425
2452
|
|
|
2426
2453
|
anchor.clear = anchor.remove;
|
|
2427
2454
|
anchor.detach = anchor.remove;
|
|
@@ -2447,7 +2474,6 @@ var NativeComponents = (function (exports) {
|
|
|
2447
2474
|
|
|
2448
2475
|
anchorFragment.onConnectedOnce((parent) => {
|
|
2449
2476
|
if(isUniqueChild) {
|
|
2450
|
-
console.log('Lets overwrite some functions with parent ', parent);
|
|
2451
2477
|
oneChildAnchorOverwriting(anchorFragment, parent);
|
|
2452
2478
|
}
|
|
2453
2479
|
});
|
|
@@ -2469,15 +2495,19 @@ var NativeComponents = (function (exports) {
|
|
|
2469
2495
|
|
|
2470
2496
|
const insertBefore = function(parent, child, target) {
|
|
2471
2497
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2498
|
+
insertBeforeRaw(parent, childElement, target);
|
|
2499
|
+
};
|
|
2500
|
+
|
|
2501
|
+
const insertBeforeRaw = function(parent, child, target) {
|
|
2472
2502
|
if(parent === anchorFragment) {
|
|
2473
|
-
parent.nativeInsertBefore(
|
|
2503
|
+
parent.nativeInsertBefore(child, target);
|
|
2474
2504
|
return;
|
|
2475
2505
|
}
|
|
2476
2506
|
if(isParentUniqueChild(parent) && target === anchorEnd) {
|
|
2477
|
-
parent.append(
|
|
2507
|
+
parent.append(child, target);
|
|
2478
2508
|
return;
|
|
2479
2509
|
}
|
|
2480
|
-
parent.insertBefore(
|
|
2510
|
+
parent.insertBefore(child, target);
|
|
2481
2511
|
};
|
|
2482
2512
|
|
|
2483
2513
|
anchorFragment.appendElement = function(child) {
|
|
@@ -2499,8 +2529,32 @@ var NativeComponents = (function (exports) {
|
|
|
2499
2529
|
insertBefore(parent, child, before);
|
|
2500
2530
|
};
|
|
2501
2531
|
|
|
2502
|
-
anchorFragment.
|
|
2503
|
-
|
|
2532
|
+
anchorFragment.appendChildRaw = function(child, before = null) {
|
|
2533
|
+
const parent = anchorEnd.parentNode;
|
|
2534
|
+
if(!parent) {
|
|
2535
|
+
DebugManager.error('Anchor', 'Anchor : parent not found', child);
|
|
2536
|
+
return;
|
|
2537
|
+
}
|
|
2538
|
+
before = before ?? anchorEnd;
|
|
2539
|
+
insertBeforeRaw(parent, child, before);
|
|
2540
|
+
};
|
|
2541
|
+
|
|
2542
|
+
anchorFragment.getParent = () => anchorEnd.parentNode;
|
|
2543
|
+
anchorFragment.append = anchorFragment.appendChild;
|
|
2544
|
+
anchorFragment.appendRaw = anchorFragment.appendChildRaw;
|
|
2545
|
+
|
|
2546
|
+
anchorFragment.insertAtStart = function(child) {
|
|
2547
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2548
|
+
anchorFragment.insertAtStartRaw(child);
|
|
2549
|
+
};
|
|
2550
|
+
|
|
2551
|
+
anchorFragment.insertAtStartRaw = function(child) {
|
|
2552
|
+
const parentNode = anchorStart.parentNode;
|
|
2553
|
+
if(parentNode === anchorFragment) {
|
|
2554
|
+
parentNode.nativeInsertBefore(child, anchorStart);
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2557
|
+
parentNode.insertBefore(child, anchorStart);
|
|
2504
2558
|
};
|
|
2505
2559
|
|
|
2506
2560
|
anchorFragment.removeChildren = function() {
|
|
@@ -2547,6 +2601,10 @@ var NativeComponents = (function (exports) {
|
|
|
2547
2601
|
|
|
2548
2602
|
anchorFragment.replaceContent = function(child) {
|
|
2549
2603
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2604
|
+
anchorFragment.replaceContentRaw(childElement);
|
|
2605
|
+
};
|
|
2606
|
+
|
|
2607
|
+
anchorFragment.replaceContentRaw = function(child) {
|
|
2550
2608
|
const parent = anchorEnd.parentNode;
|
|
2551
2609
|
if(!parent) {
|
|
2552
2610
|
return;
|
|
@@ -2560,10 +2618,10 @@ var NativeComponents = (function (exports) {
|
|
|
2560
2618
|
};
|
|
2561
2619
|
|
|
2562
2620
|
anchorFragment.setContent = anchorFragment.replaceContent;
|
|
2621
|
+
anchorFragment.setContentRaw = anchorFragment.replaceContentRaw;
|
|
2563
2622
|
|
|
2564
|
-
anchorFragment.insertBefore =
|
|
2565
|
-
|
|
2566
|
-
};
|
|
2623
|
+
anchorFragment.insertBefore = anchorFragment.appendChild;
|
|
2624
|
+
anchorFragment.insertBeforeRaw = anchorFragment.appendChildRaw;
|
|
2567
2625
|
|
|
2568
2626
|
anchorFragment.endElement = function() {
|
|
2569
2627
|
return anchorEnd;
|
|
@@ -3015,19 +3073,22 @@ var NativeComponents = (function (exports) {
|
|
|
3015
3073
|
}
|
|
3016
3074
|
}
|
|
3017
3075
|
if(this.$classes) {
|
|
3018
|
-
const cache = {};
|
|
3019
3076
|
const keys = Object.keys(this.$classes);
|
|
3020
3077
|
|
|
3021
3078
|
if(keys.length === 1) {
|
|
3022
3079
|
const key = keys[0];
|
|
3023
3080
|
const callback = this.$classes[key];
|
|
3024
3081
|
steps.push((clonedNode, data) => {
|
|
3025
|
-
|
|
3026
|
-
ElementCreator.processClassAttribute(clonedNode, cache);
|
|
3082
|
+
callback.apply(null, data).bindClassProperty(clonedNode, key);
|
|
3027
3083
|
});
|
|
3028
3084
|
} else {
|
|
3085
|
+
const properties = this.$classes;
|
|
3086
|
+
const keysLength = keys.length;
|
|
3029
3087
|
steps.push((clonedNode, data) => {
|
|
3030
|
-
|
|
3088
|
+
for(let i = 0; i < keysLength; i++) {
|
|
3089
|
+
const key = keys[i];
|
|
3090
|
+
properties[key].apply(null, data).bindClassProperty(clonedNode, key);
|
|
3091
|
+
}
|
|
3031
3092
|
});
|
|
3032
3093
|
}
|
|
3033
3094
|
}
|
|
@@ -3254,6 +3315,8 @@ var NativeComponents = (function (exports) {
|
|
|
3254
3315
|
};
|
|
3255
3316
|
});
|
|
3256
3317
|
|
|
3318
|
+
const $clearEvent = { action: 'clear' };
|
|
3319
|
+
|
|
3257
3320
|
/**
|
|
3258
3321
|
* Removes all items from the array and triggers an update.
|
|
3259
3322
|
*
|
|
@@ -3267,7 +3330,7 @@ var NativeComponents = (function (exports) {
|
|
|
3267
3330
|
return;
|
|
3268
3331
|
}
|
|
3269
3332
|
this.$currentValue.length = 0;
|
|
3270
|
-
this.trigger(
|
|
3333
|
+
this.trigger($clearEvent);
|
|
3271
3334
|
return true;
|
|
3272
3335
|
};
|
|
3273
3336
|
|