maquette 4.1.2 → 4.1.4
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/cache.d.ts +3 -3
- package/dist/cache.js +3 -3
- package/dist/cache.js.map +1 -1
- package/dist/dom.d.ts +28 -28
- package/dist/dom.js +28 -28
- package/dist/dom.js.map +1 -1
- package/dist/h.d.ts +2 -2
- package/dist/h.js.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +75 -75
- package/dist/interfaces.js.map +1 -1
- package/dist/mapping.d.ts +1 -1
- package/dist/mapping.js +1 -1
- package/dist/mapping.js.map +1 -1
- package/dist/maquette.cjs.js +142 -144
- package/dist/maquette.umd.js +142 -144
- package/dist/maquette.umd.min.js +1 -1
- package/dist/projection.js +28 -23
- package/dist/projection.js.map +1 -1
- package/dist/projector.d.ts +8 -8
- package/dist/projector.js +3 -10
- package/dist/projector.js.map +1 -1
- package/package.json +30 -63
- package/polyfills/maquette-polyfills.js +0 -531
package/dist/maquette.umd.js
CHANGED
|
@@ -4,6 +4,38 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.maquette = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Creates a {@link CalculationCache} object, useful for caching {@link VNode} trees.
|
|
9
|
+
* In practice, caching of {@link VNode} trees is not needed, because achieving 60 frames per second is almost never a problem.
|
|
10
|
+
* For more information, see {@link CalculationCache}.
|
|
11
|
+
*
|
|
12
|
+
* @param <Result> The type of the value that is cached.
|
|
13
|
+
*/
|
|
14
|
+
var createCache = function () {
|
|
15
|
+
var cachedInputs;
|
|
16
|
+
var cachedOutcome;
|
|
17
|
+
return {
|
|
18
|
+
invalidate: function () {
|
|
19
|
+
cachedOutcome = undefined;
|
|
20
|
+
cachedInputs = undefined;
|
|
21
|
+
},
|
|
22
|
+
result: function (inputs, calculation) {
|
|
23
|
+
if (cachedInputs) {
|
|
24
|
+
for (var i = 0; i < inputs.length; i++) {
|
|
25
|
+
if (cachedInputs[i] !== inputs[i]) {
|
|
26
|
+
cachedOutcome = undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!cachedOutcome) {
|
|
31
|
+
cachedOutcome = calculation();
|
|
32
|
+
cachedInputs = inputs;
|
|
33
|
+
}
|
|
34
|
+
return cachedOutcome;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
7
39
|
var NAMESPACE_W3 = "http://www.w3.org/";
|
|
8
40
|
var NAMESPACE_SVG = "".concat(NAMESPACE_W3, "2000/svg");
|
|
9
41
|
var NAMESPACE_XLINK = "".concat(NAMESPACE_W3, "1999/xlink");
|
|
@@ -65,11 +97,7 @@
|
|
|
65
97
|
if (i !== indexToCheck) {
|
|
66
98
|
var node = childNodes[i];
|
|
67
99
|
if (same(node, childNode)) {
|
|
68
|
-
throw {
|
|
69
|
-
error: new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")),
|
|
70
|
-
parentNode: parentVNode,
|
|
71
|
-
childNode: childNode,
|
|
72
|
-
};
|
|
100
|
+
throw Object.assign(new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")), { parentNode: parentVNode, childNode: childNode });
|
|
73
101
|
}
|
|
74
102
|
}
|
|
75
103
|
}
|
|
@@ -132,6 +160,7 @@
|
|
|
132
160
|
}
|
|
133
161
|
};
|
|
134
162
|
var vnodeOnlyProps = [
|
|
163
|
+
"on",
|
|
135
164
|
"afterCreate",
|
|
136
165
|
"afterUpdate",
|
|
137
166
|
"afterRemoved",
|
|
@@ -182,19 +211,6 @@
|
|
|
182
211
|
}
|
|
183
212
|
}
|
|
184
213
|
}
|
|
185
|
-
else if (propName === "on" && propValue) {
|
|
186
|
-
// object with string keys and function values
|
|
187
|
-
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
188
|
-
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
189
|
-
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
190
|
-
if (eventHandlerInterceptor) {
|
|
191
|
-
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
192
|
-
}
|
|
193
|
-
if (listener) {
|
|
194
|
-
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
214
|
else if (propName !== "key" && propValue !== null && propValue !== undefined) {
|
|
199
215
|
var type = typeof propValue;
|
|
200
216
|
if (type === "function") {
|
|
@@ -223,6 +239,19 @@
|
|
|
223
239
|
}
|
|
224
240
|
}
|
|
225
241
|
}
|
|
242
|
+
if (properties.on) {
|
|
243
|
+
// object with string keys and function values
|
|
244
|
+
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
245
|
+
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
246
|
+
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
247
|
+
if (eventHandlerInterceptor) {
|
|
248
|
+
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
249
|
+
}
|
|
250
|
+
if (listener) {
|
|
251
|
+
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
226
255
|
};
|
|
227
256
|
var addChildren = function (domNode, children, projectionOptions) {
|
|
228
257
|
if (!children) {
|
|
@@ -454,7 +483,8 @@
|
|
|
454
483
|
var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
|
|
455
484
|
var newChild = newChildren[newIndex];
|
|
456
485
|
if (oldChild !== undefined && same(oldChild, newChild)) {
|
|
457
|
-
textUpdated =
|
|
486
|
+
textUpdated =
|
|
487
|
+
updateDom(oldChild, newChild, projectionOptions, domNode, oldChildren) || textUpdated;
|
|
458
488
|
oldIndex++;
|
|
459
489
|
}
|
|
460
490
|
else {
|
|
@@ -466,7 +496,8 @@
|
|
|
466
496
|
checkDistinguishable(oldChildren, i, vnode, "removed");
|
|
467
497
|
}
|
|
468
498
|
textUpdated =
|
|
469
|
-
updateDom(oldChildren[findOldIndex], newChild, projectionOptions) ||
|
|
499
|
+
updateDom(oldChildren[findOldIndex], newChild, projectionOptions, domNode, oldChildren) ||
|
|
500
|
+
textUpdated;
|
|
470
501
|
oldIndex = findOldIndex + 1;
|
|
471
502
|
}
|
|
472
503
|
else {
|
|
@@ -487,7 +518,7 @@
|
|
|
487
518
|
}
|
|
488
519
|
return textUpdated;
|
|
489
520
|
};
|
|
490
|
-
updateDom = function (previous, vnode, projectionOptions) {
|
|
521
|
+
updateDom = function (previous, vnode, projectionOptions, parentNode, oldChildren) {
|
|
491
522
|
var domNode = previous.domNode;
|
|
492
523
|
var textUpdated = false;
|
|
493
524
|
if (previous === vnode) {
|
|
@@ -497,7 +528,13 @@
|
|
|
497
528
|
if (vnode.vnodeSelector === "") {
|
|
498
529
|
if (vnode.text !== previous.text) {
|
|
499
530
|
var newTextNode = domNode.ownerDocument.createTextNode(vnode.text);
|
|
500
|
-
|
|
531
|
+
try {
|
|
532
|
+
parentNode.replaceChild(newTextNode, domNode);
|
|
533
|
+
}
|
|
534
|
+
catch (_a) {
|
|
535
|
+
// Text nodes can be substituted by google translate
|
|
536
|
+
parentNode.replaceChild(newTextNode, parentNode.childNodes[oldChildren.indexOf(previous)]);
|
|
537
|
+
}
|
|
501
538
|
vnode.domNode = newTextNode;
|
|
502
539
|
textUpdated = true;
|
|
503
540
|
return textUpdated;
|
|
@@ -551,7 +588,7 @@
|
|
|
551
588
|
}
|
|
552
589
|
var previousVNode = vnode;
|
|
553
590
|
vnode = updatedVnode;
|
|
554
|
-
updateDom(previousVNode, updatedVnode, projectionOptions);
|
|
591
|
+
updateDom(previousVNode, updatedVnode, projectionOptions, previousVNode.domNode.parentNode, [previousVNode]);
|
|
555
592
|
},
|
|
556
593
|
domNode: vnode.domNode,
|
|
557
594
|
};
|
|
@@ -577,13 +614,13 @@
|
|
|
577
614
|
};
|
|
578
615
|
var dom = {
|
|
579
616
|
/**
|
|
580
|
-
* Creates a real DOM tree from `vnode`. The
|
|
581
|
-
* its
|
|
582
|
-
* This is a low-level method. Users will typically use a
|
|
583
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
617
|
+
* Creates a real DOM tree from `vnode`. The {@link Projection} object returned will contain the resulting DOM Node in
|
|
618
|
+
* its {@link Projection.domNode | domNode} property.
|
|
619
|
+
* This is a low-level method. Users will typically use a {@link Projector} instead.
|
|
620
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
|
|
584
621
|
* objects may only be rendered once.
|
|
585
622
|
* @param projectionOptions - Options to be used to create and update the projection.
|
|
586
|
-
* @returns The
|
|
623
|
+
* @returns The {@link Projection} which also contains the DOM Node that was created.
|
|
587
624
|
*/
|
|
588
625
|
create: function (vnode, projectionOptions) {
|
|
589
626
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -591,13 +628,13 @@
|
|
|
591
628
|
return createProjection(vnode, projectionOptions);
|
|
592
629
|
},
|
|
593
630
|
/**
|
|
594
|
-
* Appends a new child node to the DOM which is generated from a
|
|
595
|
-
* This is a low-level method. Users will typically use a
|
|
631
|
+
* Appends a new child node to the DOM which is generated from a {@link VNode}.
|
|
632
|
+
* This is a low-level method. Users will typically use a {@link Projector} instead.
|
|
596
633
|
* @param parentNode - The parent node for the new child node.
|
|
597
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
634
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
|
|
598
635
|
* objects may only be rendered once.
|
|
599
|
-
* @param projectionOptions - Options to be used to create and update the
|
|
600
|
-
* @returns The
|
|
636
|
+
* @param projectionOptions - Options to be used to create and update the {@link Projection}.
|
|
637
|
+
* @returns The {@link Projection} that was created.
|
|
601
638
|
*/
|
|
602
639
|
append: function (parentNode, vnode, projectionOptions) {
|
|
603
640
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -605,13 +642,13 @@
|
|
|
605
642
|
return createProjection(vnode, projectionOptions);
|
|
606
643
|
},
|
|
607
644
|
/**
|
|
608
|
-
* Inserts a new DOM node which is generated from a
|
|
609
|
-
* This is a low-level method. Users wil typically use a
|
|
645
|
+
* Inserts a new DOM node which is generated from a {@link VNode}.
|
|
646
|
+
* This is a low-level method. Users wil typically use a {@link Projector} instead.
|
|
610
647
|
* @param beforeNode - The node that the DOM Node is inserted before.
|
|
611
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
612
|
-
* NOTE:
|
|
613
|
-
* @param projectionOptions - Options to be used to create and update the projection, see
|
|
614
|
-
* @returns The
|
|
648
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function.
|
|
649
|
+
* NOTE: {@link VNode} objects may only be rendered once.
|
|
650
|
+
* @param projectionOptions - Options to be used to create and update the projection, see {@link createProjector}.
|
|
651
|
+
* @returns The {@link Projection} that was created.
|
|
615
652
|
*/
|
|
616
653
|
insertBefore: function (beforeNode, vnode, projectionOptions) {
|
|
617
654
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -619,15 +656,15 @@
|
|
|
619
656
|
return createProjection(vnode, projectionOptions);
|
|
620
657
|
},
|
|
621
658
|
/**
|
|
622
|
-
* Merges a new DOM node which is generated from a
|
|
659
|
+
* Merges a new DOM node which is generated from a {@link VNode} with an existing DOM Node.
|
|
623
660
|
* This means that the virtual DOM and the real DOM will have one overlapping element.
|
|
624
|
-
* Therefore the selector for the root
|
|
625
|
-
* This is a low-level method. Users wil typically use a
|
|
661
|
+
* Therefore the selector for the root {@link VNode} will be ignored, but its properties and children will be applied to the Element provided.
|
|
662
|
+
* This is a low-level method. Users wil typically use a {@link Projector} instead.
|
|
626
663
|
* @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
|
|
627
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
664
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode} objects
|
|
628
665
|
* may only be rendered once.
|
|
629
|
-
* @param projectionOptions - Options to be used to create and update the projection, see
|
|
630
|
-
* @returns The
|
|
666
|
+
* @param projectionOptions - Options to be used to create and update the projection, see {@link createProjector}.
|
|
667
|
+
* @returns The {@link Projection} that was created.
|
|
631
668
|
*/
|
|
632
669
|
merge: function (element, vnode, projectionOptions) {
|
|
633
670
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -636,13 +673,13 @@
|
|
|
636
673
|
return createProjection(vnode, projectionOptions);
|
|
637
674
|
},
|
|
638
675
|
/**
|
|
639
|
-
* Replaces an existing DOM node with a node generated from a
|
|
640
|
-
* This is a low-level method. Users will typically use a
|
|
641
|
-
* @param element - The node for the
|
|
642
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
676
|
+
* Replaces an existing DOM node with a node generated from a {@link VNode}.
|
|
677
|
+
* This is a low-level method. Users will typically use a {@link Projector} instead.
|
|
678
|
+
* @param element - The node for the {@link VNode} to replace.
|
|
679
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
|
|
643
680
|
* objects may only be rendered once.
|
|
644
|
-
* @param projectionOptions - Options to be used to create and update the
|
|
645
|
-
* @returns The
|
|
681
|
+
* @param projectionOptions - Options to be used to create and update the {@link Projection}.
|
|
682
|
+
* @returns The {@link Projection} that was created.
|
|
646
683
|
*/
|
|
647
684
|
replace: function (element, vnode, projectionOptions) {
|
|
648
685
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -708,6 +745,57 @@
|
|
|
708
745
|
};
|
|
709
746
|
}
|
|
710
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
|
|
750
|
+
* See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
|
|
751
|
+
*
|
|
752
|
+
* @param <Source> The type of source items. A database-record for instance.
|
|
753
|
+
* @param <Target> The type of target items. A {@link MaquetteComponent} for instance.
|
|
754
|
+
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
|
|
755
|
+
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
|
|
756
|
+
* to the `callback` argument in `Array.map(callback)`.
|
|
757
|
+
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
|
|
758
|
+
*/
|
|
759
|
+
var createMapping = function (getSourceKey, createResult, updateResult) {
|
|
760
|
+
var keys = [];
|
|
761
|
+
var results = [];
|
|
762
|
+
return {
|
|
763
|
+
results: results,
|
|
764
|
+
map: function (newSources) {
|
|
765
|
+
var newKeys = newSources.map(getSourceKey);
|
|
766
|
+
var oldTargets = results.slice();
|
|
767
|
+
var oldIndex = 0;
|
|
768
|
+
for (var i = 0; i < newSources.length; i++) {
|
|
769
|
+
var source = newSources[i];
|
|
770
|
+
var sourceKey = newKeys[i];
|
|
771
|
+
if (sourceKey === keys[oldIndex]) {
|
|
772
|
+
results[i] = oldTargets[oldIndex];
|
|
773
|
+
updateResult(source, oldTargets[oldIndex], i);
|
|
774
|
+
oldIndex++;
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
var found = false;
|
|
778
|
+
for (var j = 1; j < keys.length + 1; j++) {
|
|
779
|
+
var searchIndex = (oldIndex + j) % keys.length;
|
|
780
|
+
if (keys[searchIndex] === sourceKey) {
|
|
781
|
+
results[i] = oldTargets[searchIndex];
|
|
782
|
+
updateResult(newSources[i], oldTargets[searchIndex], i);
|
|
783
|
+
oldIndex = searchIndex + 1;
|
|
784
|
+
found = true;
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
if (!found) {
|
|
789
|
+
results[i] = createResult(source, i);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
results.length = newSources.length;
|
|
794
|
+
keys = newKeys;
|
|
795
|
+
},
|
|
796
|
+
};
|
|
797
|
+
};
|
|
798
|
+
|
|
711
799
|
var createParentNodePath = function (node, rootNode) {
|
|
712
800
|
var parentNodePath = [];
|
|
713
801
|
while (node && node !== rootNode) {
|
|
@@ -716,19 +804,12 @@
|
|
|
716
804
|
}
|
|
717
805
|
return parentNodePath;
|
|
718
806
|
};
|
|
719
|
-
var find;
|
|
720
|
-
if (Array.prototype.find) {
|
|
721
|
-
find = function (items, predicate) { return items.find(predicate); };
|
|
722
|
-
}
|
|
723
|
-
else {
|
|
724
|
-
find = function (items, predicate) { return items.filter(predicate)[0]; };
|
|
725
|
-
}
|
|
726
807
|
var findVNodeByParentNodePath = function (vnode, parentNodePath) {
|
|
727
808
|
var result = vnode;
|
|
728
809
|
parentNodePath.forEach(function (node) {
|
|
729
810
|
result =
|
|
730
811
|
result && result.children
|
|
731
|
-
?
|
|
812
|
+
? result.children.find(function (child) { return child.domNode === node; })
|
|
732
813
|
: undefined;
|
|
733
814
|
});
|
|
734
815
|
return result;
|
|
@@ -755,9 +836,9 @@
|
|
|
755
836
|
}
|
|
756
837
|
};
|
|
757
838
|
/**
|
|
758
|
-
* Creates a
|
|
839
|
+
* Creates a {@link Projector} instance using the provided projectionOptions.
|
|
759
840
|
*
|
|
760
|
-
* For more information, see
|
|
841
|
+
* For more information, see {@link Projector}.
|
|
761
842
|
*
|
|
762
843
|
* @param projectorOptions Options that influence how the DOM is rendered and updated.
|
|
763
844
|
*/
|
|
@@ -842,89 +923,6 @@
|
|
|
842
923
|
return projector;
|
|
843
924
|
};
|
|
844
925
|
|
|
845
|
-
/**
|
|
846
|
-
* Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
|
|
847
|
-
* In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
|
|
848
|
-
* For more information, see [[CalculationCache]].
|
|
849
|
-
*
|
|
850
|
-
* @param <Result> The type of the value that is cached.
|
|
851
|
-
*/
|
|
852
|
-
var createCache = function () {
|
|
853
|
-
var cachedInputs;
|
|
854
|
-
var cachedOutcome;
|
|
855
|
-
return {
|
|
856
|
-
invalidate: function () {
|
|
857
|
-
cachedOutcome = undefined;
|
|
858
|
-
cachedInputs = undefined;
|
|
859
|
-
},
|
|
860
|
-
result: function (inputs, calculation) {
|
|
861
|
-
if (cachedInputs) {
|
|
862
|
-
for (var i = 0; i < inputs.length; i++) {
|
|
863
|
-
if (cachedInputs[i] !== inputs[i]) {
|
|
864
|
-
cachedOutcome = undefined;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
if (!cachedOutcome) {
|
|
869
|
-
cachedOutcome = calculation();
|
|
870
|
-
cachedInputs = inputs;
|
|
871
|
-
}
|
|
872
|
-
return cachedOutcome;
|
|
873
|
-
},
|
|
874
|
-
};
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
/**
|
|
878
|
-
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
|
|
879
|
-
* See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
|
|
880
|
-
*
|
|
881
|
-
* @param <Source> The type of source items. A database-record for instance.
|
|
882
|
-
* @param <Target> The type of target items. A [[MaquetteComponent]] for instance.
|
|
883
|
-
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
|
|
884
|
-
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
|
|
885
|
-
* to the `callback` argument in `Array.map(callback)`.
|
|
886
|
-
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
|
|
887
|
-
*/
|
|
888
|
-
var createMapping = function (getSourceKey, createResult, updateResult) {
|
|
889
|
-
var keys = [];
|
|
890
|
-
var results = [];
|
|
891
|
-
return {
|
|
892
|
-
results: results,
|
|
893
|
-
map: function (newSources) {
|
|
894
|
-
var newKeys = newSources.map(getSourceKey);
|
|
895
|
-
var oldTargets = results.slice();
|
|
896
|
-
var oldIndex = 0;
|
|
897
|
-
for (var i = 0; i < newSources.length; i++) {
|
|
898
|
-
var source = newSources[i];
|
|
899
|
-
var sourceKey = newKeys[i];
|
|
900
|
-
if (sourceKey === keys[oldIndex]) {
|
|
901
|
-
results[i] = oldTargets[oldIndex];
|
|
902
|
-
updateResult(source, oldTargets[oldIndex], i);
|
|
903
|
-
oldIndex++;
|
|
904
|
-
}
|
|
905
|
-
else {
|
|
906
|
-
var found = false;
|
|
907
|
-
for (var j = 1; j < keys.length + 1; j++) {
|
|
908
|
-
var searchIndex = (oldIndex + j) % keys.length;
|
|
909
|
-
if (keys[searchIndex] === sourceKey) {
|
|
910
|
-
results[i] = oldTargets[searchIndex];
|
|
911
|
-
updateResult(newSources[i], oldTargets[searchIndex], i);
|
|
912
|
-
oldIndex = searchIndex + 1;
|
|
913
|
-
found = true;
|
|
914
|
-
break;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
if (!found) {
|
|
918
|
-
results[i] = createResult(source, i);
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
results.length = newSources.length;
|
|
923
|
-
keys = newKeys;
|
|
924
|
-
},
|
|
925
|
-
};
|
|
926
|
-
};
|
|
927
|
-
|
|
928
926
|
exports.createCache = createCache;
|
|
929
927
|
exports.createMapping = createMapping;
|
|
930
928
|
exports.createProjector = createProjector;
|
package/dist/maquette.umd.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).maquette={})})(this,function(e){function l(t,r){var o={};return Object.keys(t).forEach(function(e){o[e]=t[e]}),r&&Object.keys(r).forEach(function(e){o[e]=r[e]}),o}var t="http://www.w3.org/",S="".concat(t,"2000/svg"),w="".concat(t,"1999/xlink"),v=[],h=function(e,t){return e.vnodeSelector===t.vnodeSelector&&(e.properties&&t.properties?e.properties.key===t.properties.key&&e.properties.bind===t.properties.bind:!e.properties&&!t.properties)},E=function(e){if("string"!=typeof e)throw Error("Style values must be strings")},m=function(e,t,r){if(""!==t.vnodeSelector)for(var o=r;o<e.length;o++)if(h(e[o],t))return o;return-1},g=function(e,t,r,o){var n=e[t];if(""!==n.vnodeSelector){var i=n.properties;if(!(i&&(void 0===i.key?i.bind:i.key)))for(var d=0;d<e.length;d++)if(d!==t){var a=e[d];if(h(a,n))throw Object.assign(Error("".concat(r.vnodeSelector," had a ").concat(n.vnodeSelector," child ").concat("added"===o?o:"removed",", but there is now more than one. You must add unique key properties to make them distinguishable.")),{parentNode:r,childNode:n})}}},y=function(e){var t;e.properties&&(t=e.properties.enterAnimation)&&t(e.domNode,e.properties)},r=[],o=!1,n=function(e){(e.children||[]).forEach(n),e.properties&&e.properties.afterRemoved&&e.properties.afterRemoved.call(e.properties.bind||e.properties,e.domNode)},i=function(){o=!1,r.forEach(n),r.length=0},d=function(e){r.push(e),o||(o=!0,"undefined"!=typeof window&&"requestIdleCallback"in window?window.requestIdleCallback(i,{timeout:16}):setTimeout(i,16))},N=function(e){var t=e.domNode;if(e.properties){var r=e.properties.exitAnimation;if(r)return t.style.pointerEvents="none",void r(t,function(){t.parentNode&&(t.parentNode.removeChild(t),d(e))},e.properties)}t.parentNode&&(t.parentNode.removeChild(t),d(e))},a=["on","afterCreate","afterUpdate","afterRemoved","enterAnimation","exitAnimation","updateAnimation"];function k(e){return!a.includes(e)}function f(e,t,r){c(e,t.children,r),t.text&&(e.textContent=t.text),p(e,t.properties,r),t.properties&&t.properties.afterCreate&&t.properties.afterCreate.call(t.properties.bind||t.properties,e,r,t.vnodeSelector,t.properties,t.children)}function s(r,o){return{getLastRender:function(){return r},update:function(e){if(r.vnodeSelector!==e.vnodeSelector)throw Error("The selector for the root VNode may not be changed. (consider using dom.merge and add one extra level to the virtual DOM)");var t=r;x(t,r=e,o,t.domNode.parentNode,[t])},domNode:r.domNode}}function u(e){return l(A,e)}var p=function(e,t,r){if(t){for(var o=r.eventHandlerInterceptor,n=Object.keys(t).filter(k),i=n.length,d=0;d<i;d++){var a,s=n[d],p=t[s];if("className"===s)throw Error('Property "className" is not supported, use "class".');if("class"===s)C(e,p,!0);else if("classes"===s)for(var c=Object.keys(p),l=c.length,f=0;f<l;f++){var u=c[f];p[u]&&e.classList.add(u)}else if("styles"===s)for(var v=Object.keys(p),h=v.length,f=0;f<h;f++){var m=v[f],g=p[m];g&&(E(g),r.styleApplyer(e,m,g))}else"key"!==s&&null!=p&&("function"==(a=typeof p)?(s.lastIndexOf("on",0)||o&&(p=o(s,p,e,t)),e[s]=p):r.namespace===S?"href"===s?e.setAttributeNS(w,s,p):e.setAttribute(s,p):"string"==a&&"value"!==s&&"innerHTML"!==s?e.setAttribute(s,p):e[s]=p)}if(t.on)for(var y=0,N=Object.entries(t.on);y<N.length;y++){var b=N[y],x=b[0],b=b[1],A="function"==typeof b?b:b.listener;(A=o?o(x,A,e,t):A)&&e.addEventListener(x,A,"function"==typeof b?void 0:b.options)}}},c=function(e,t,r){if(t)for(var o=0,n=t;o<n.length;o++){var i=n[o];b(i,e,void 0,r)}},b=function(e,t,r,o){var n,i=0,d=e.vnodeSelector,a=t.ownerDocument;if(""===d)e.domNode?e.domNode.nodeValue=e.text:(n=e.domNode=a.createTextNode(e.text),void 0!==r?t.insertBefore(n,r):t.appendChild(n));else{for(var s=0;s<=d.length;++s){var p,c=d[0|s]||"";s!==d.length&&"."!=c&&"#"!=c||(c=d[0|i-1]||"",p=d.slice(i,s),"."==c?n.classList.add(p):"#"==c?n.id=p:(void 0!==(o="svg"===p?l(o,{namespace:S}):o).namespace?n=e.domNode=a.createElementNS(o.namespace,p):(n=e.domNode=e.domNode||(null!=(c=e.properties)&&c.is?a.createElement(p,{is:e.properties.is}):a.createElement(p)),"input"===p&&e.properties&&void 0!==e.properties.type&&n.setAttribute("type",e.properties.type)),void 0!==r?t.insertBefore(n,r):n.parentNode!==t&&t.appendChild(n)),i=s+1)}f(n,e,o)}},C=function(t,e,r){e&&e.split(" ").forEach(function(e){e&&t.classList.toggle(e,r)})},x=function(t,e,r,o,n){var i=t.domNode;if(t!==e){var d=!1;if(""===e.vnodeSelector){if(e.text!==t.text){var a=i.ownerDocument.createTextNode(e.text);try{o.replaceChild(a,i)}catch(e){o.replaceChild(a,o.childNodes[n.indexOf(t)])}return e.domNode=a,!0}e.domNode=i}else e.vnodeSelector.lastIndexOf("svg",0)||(r=l(r,{namespace:S})),t.text!==e.text&&(d=!0,void 0===e.text?i.removeChild(i.firstChild):i.textContent=e.text),e.domNode=i,d=((e,t,r,o,n)=>{if(r===o)return!1;for(var i,d=(r=r||v).length,a=(o=o||v).length,s=0,p=0,c=!1;p<a;){var l=s<d?r[s]:void 0,f=o[p];if(void 0!==l&&h(l,f))c=x(l,f,n,t,r)||c,s++;else{var u=m(r,f,s+1);if(u<0)b(f,t,s<d?r[s].domNode:void 0,n),y(f),g(o,p,e,"added");else{for(i=s;i<u;i++)N(r[i]),g(r,i,e,"removed");c=x(r[u],f,n,t,r)||c,s=u+1}}p++}if(s<d)for(i=s;i<d;i++)N(r[i]),g(r,i,e,"removed");return c})(e,i,t.children,e.children,r)||d,d=((e,t,r,o)=>{if(r){for(var n=!1,i=Object.keys(r).filter(k),d=i.length,a=0;a<d;a++){var s,p=i[a],c=r[p],l=t[p];if("class"===p)l!==c&&(C(e,l,!1),C(e,c,!0));else if("classes"===p)for(var f=e.classList,u=Object.keys(c),v=u.length,h=0;h<v;h++){var m=u[h],g=!!c[m];g!=!!l[m]&&(n=!0,g?f.add(m):f.remove(m))}else if("styles"===p)for(var y=Object.keys(c),N=y.length,h=0;h<N;h++){var b=y[h],x=c[b];x!==l[b]&&(n=!0,x?(E(x),o.styleApplyer(e,b,x)):o.styleApplyer(e,b,""))}else c||"string"!=typeof l||(c=""),"value"===p?(e[p]!==c&&c!==l&&(e[p]=c),c!==l&&(n=!0)):c===l||"function"==(s=typeof c)&&o.eventHandlerInterceptor||(o.namespace===S?"href"===p?e.setAttributeNS(w,p,c):e.setAttribute(p,c):"string"==s&&"innerHTML"!==p?"role"===p&&""===c?e.removeAttribute(p):e.setAttribute(p,c):e[p]!==c&&(e[p]=c),n=!0)}return n}})(i,t.properties,e.properties,r)||d,e.properties&&e.properties.afterUpdate&&e.properties.afterUpdate.call(e.properties.bind||e.properties,i,r,e.vnodeSelector,e.properties,e.children);d&&e.properties&&e.properties.updateAnimation&&e.properties.updateAnimation(i,e.properties,t.properties)}return!1},A={namespace:void 0,performanceLogger:function(){},eventHandlerInterceptor:void 0,styleApplyer:function(e,t,r){"-"==(t[0]||"")?e.style.setProperty(t,r):e.style[t]=r}},O={create:function(e,t){return t=u(t),b(e,document.createElement("div"),void 0,t),s(e,t)},append:function(e,t,r){return r=u(r),b(t,e,void 0,r),s(t,r)},insertBefore:function(e,t,r){return r=u(r),b(t,e.parentNode,e,r),s(t,r)},merge:function(e,t,r){return r=u(r),f(t.domNode=e,t,r),s(t,r)},replace:function(e,t,r){return r=u(r),b(t,e.parentNode,e,r),e.parentNode.removeChild(e),s(t,r)}};e.createCache=function(){var o,n;return{invalidate:function(){o=n=void 0},result:function(e,t){if(o)for(var r=0;r<e.length;r++)o[r]!==e[r]&&(n=void 0);return n||(n=t(),o=e),n}}},e.createMapping=function(c,l,f){var u=[],v=[];return{results:v,map:function(e){for(var t=e.map(c),r=v.slice(),o=0,n=0;n<e.length;n++){var i=e[n],d=t[n];if(d===u[o])v[n]=r[o],f(i,r[o],n),o++;else{for(var a=!1,s=1;s<u.length+1;s++){var p=(o+s)%u.length;if(u[p]===d){v[n]=r[p],f(e[n],r[p],n),o=1+p,a=!0;break}}a||(v[n]=l(i,n))}}v.length=e.length,u=t}}},e.createProjector=function(e){function r(e,t,r){var i,d,a;function n(e){a("domEvent",e);var t,r,o=i,n=((e,t)=>{for(var r=[];e&&e!==t;)r.push(e),e=e.parentNode;return r})(e.currentTarget,o.domNode),o=(n.reverse(),o=o.getLastRender(),r=o,n.forEach(function(t){r=r&&r.children?r.children.find(function(e){return e.domNode===t}):void 0}),r);return d.scheduleRender(),o&&(t=(null!=(n=null!=(n=o.properties["on".concat(e.type)])?n:o.properties.on[e.type].listener)?n:o.properties.on[e.type]).apply(o.properties.bind||this,arguments)),a("domEventProcessed",e),t}s.eventHandlerInterceptor=(d=f,a=p,function(e,t,r,o){return n}),i=e(t,r(),s),c.push(i),l.push(r)}function t(){if(o=void 0,n){n=!1,p("renderStart",void 0);for(var e=0;e<c.length;e++){var t=l[e]();p("rendered",void 0),c[e].update(t),p("patched",void 0)}p("renderDone",void 0),n=!0}}var o,s=u(e),p=s.performanceLogger,n=!0,i=!1,c=[],l=[],f={renderNow:t,scheduleRender:function(){o||i||(o=requestAnimationFrame(t))},stop:function(){o&&(cancelAnimationFrame(o),o=void 0),i=!0},resume:function(){n=!(i=!1),f.scheduleRender()},append:function(e,t){r(O.append,e,t)},insertBefore:function(e,t){r(O.insertBefore,e,t)},merge:function(e,t){r(O.merge,e,t)},replace:function(e,t){r(O.replace,e,t)},detach:function(e){for(var t=0;t<l.length;t++)if(l[t]===e)return l.splice(t,1),c.splice(t,1)[0];throw Error("renderFunction was not found")}};return f},e.dom=O,e.h=function(e,t,r){if(Array.isArray(t))r=t,t=void 0;else if(t&&("string"==typeof t||t.vnodeSelector)||r&&("string"==typeof r||r.vnodeSelector))throw Error("h called with invalid arguments");var o,n;return r&&1===r.length&&"string"==typeof r[0]?o=r[0]:r&&(function e(t,r,o){for(var n=0,i=r.length;n<i;n++){var d=r[n];Array.isArray(d)?e(t,d,o):null!=d&&!1!==d&&("string"==typeof d&&(d={vnodeSelector:"",properties:void 0,children:void 0,text:d.toString(),domNode:null}),o.push(d))}}(e,r,n=[]),0===n.length)&&(n=void 0),{vnodeSelector:e,properties:t,children:n,text:""===o?void 0:o,domNode:null}}});
|
package/dist/projection.js
CHANGED
|
@@ -59,11 +59,7 @@ var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, oper
|
|
|
59
59
|
if (i !== indexToCheck) {
|
|
60
60
|
var node = childNodes[i];
|
|
61
61
|
if (same(node, childNode)) {
|
|
62
|
-
throw {
|
|
63
|
-
error: new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")),
|
|
64
|
-
parentNode: parentVNode,
|
|
65
|
-
childNode: childNode,
|
|
66
|
-
};
|
|
62
|
+
throw Object.assign(new Error("".concat(parentVNode.vnodeSelector, " had a ").concat(childNode.vnodeSelector, " child ").concat(operation === "added" ? operation : "removed", ", but there is now more than one. You must add unique key properties to make them distinguishable.")), { parentNode: parentVNode, childNode: childNode });
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
}
|
|
@@ -126,6 +122,7 @@ var nodeToRemove = function (vNode) {
|
|
|
126
122
|
}
|
|
127
123
|
};
|
|
128
124
|
var vnodeOnlyProps = [
|
|
125
|
+
"on",
|
|
129
126
|
"afterCreate",
|
|
130
127
|
"afterUpdate",
|
|
131
128
|
"afterRemoved",
|
|
@@ -176,19 +173,6 @@ var setProperties = function (domNode, properties, projectionOptions) {
|
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
175
|
}
|
|
179
|
-
else if (propName === "on" && propValue) {
|
|
180
|
-
// object with string keys and function values
|
|
181
|
-
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
182
|
-
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
183
|
-
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
184
|
-
if (eventHandlerInterceptor) {
|
|
185
|
-
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
186
|
-
}
|
|
187
|
-
if (listener) {
|
|
188
|
-
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
176
|
else if (propName !== "key" && propValue !== null && propValue !== undefined) {
|
|
193
177
|
var type = typeof propValue;
|
|
194
178
|
if (type === "function") {
|
|
@@ -217,6 +201,19 @@ var setProperties = function (domNode, properties, projectionOptions) {
|
|
|
217
201
|
}
|
|
218
202
|
}
|
|
219
203
|
}
|
|
204
|
+
if (properties.on) {
|
|
205
|
+
// object with string keys and function values
|
|
206
|
+
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
207
|
+
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
208
|
+
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
209
|
+
if (eventHandlerInterceptor) {
|
|
210
|
+
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
211
|
+
}
|
|
212
|
+
if (listener) {
|
|
213
|
+
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
220
217
|
};
|
|
221
218
|
var addChildren = function (domNode, children, projectionOptions) {
|
|
222
219
|
if (!children) {
|
|
@@ -448,7 +445,8 @@ var updateChildren = function (vnode, domNode, oldChildren, newChildren, project
|
|
|
448
445
|
var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
|
|
449
446
|
var newChild = newChildren[newIndex];
|
|
450
447
|
if (oldChild !== undefined && same(oldChild, newChild)) {
|
|
451
|
-
textUpdated =
|
|
448
|
+
textUpdated =
|
|
449
|
+
updateDom(oldChild, newChild, projectionOptions, domNode, oldChildren) || textUpdated;
|
|
452
450
|
oldIndex++;
|
|
453
451
|
}
|
|
454
452
|
else {
|
|
@@ -460,7 +458,8 @@ var updateChildren = function (vnode, domNode, oldChildren, newChildren, project
|
|
|
460
458
|
checkDistinguishable(oldChildren, i, vnode, "removed");
|
|
461
459
|
}
|
|
462
460
|
textUpdated =
|
|
463
|
-
updateDom(oldChildren[findOldIndex], newChild, projectionOptions) ||
|
|
461
|
+
updateDom(oldChildren[findOldIndex], newChild, projectionOptions, domNode, oldChildren) ||
|
|
462
|
+
textUpdated;
|
|
464
463
|
oldIndex = findOldIndex + 1;
|
|
465
464
|
}
|
|
466
465
|
else {
|
|
@@ -481,7 +480,7 @@ var updateChildren = function (vnode, domNode, oldChildren, newChildren, project
|
|
|
481
480
|
}
|
|
482
481
|
return textUpdated;
|
|
483
482
|
};
|
|
484
|
-
updateDom = function (previous, vnode, projectionOptions) {
|
|
483
|
+
updateDom = function (previous, vnode, projectionOptions, parentNode, oldChildren) {
|
|
485
484
|
var domNode = previous.domNode;
|
|
486
485
|
var textUpdated = false;
|
|
487
486
|
if (previous === vnode) {
|
|
@@ -491,7 +490,13 @@ updateDom = function (previous, vnode, projectionOptions) {
|
|
|
491
490
|
if (vnode.vnodeSelector === "") {
|
|
492
491
|
if (vnode.text !== previous.text) {
|
|
493
492
|
var newTextNode = domNode.ownerDocument.createTextNode(vnode.text);
|
|
494
|
-
|
|
493
|
+
try {
|
|
494
|
+
parentNode.replaceChild(newTextNode, domNode);
|
|
495
|
+
}
|
|
496
|
+
catch (_a) {
|
|
497
|
+
// Text nodes can be substituted by google translate
|
|
498
|
+
parentNode.replaceChild(newTextNode, parentNode.childNodes[oldChildren.indexOf(previous)]);
|
|
499
|
+
}
|
|
495
500
|
vnode.domNode = newTextNode;
|
|
496
501
|
textUpdated = true;
|
|
497
502
|
return textUpdated;
|
|
@@ -545,7 +550,7 @@ export var createProjection = function (vnode, projectionOptions) {
|
|
|
545
550
|
}
|
|
546
551
|
var previousVNode = vnode;
|
|
547
552
|
vnode = updatedVnode;
|
|
548
|
-
updateDom(previousVNode, updatedVnode, projectionOptions);
|
|
553
|
+
updateDom(previousVNode, updatedVnode, projectionOptions, previousVNode.domNode.parentNode, [previousVNode]);
|
|
549
554
|
},
|
|
550
555
|
domNode: vnode.domNode,
|
|
551
556
|
};
|