maquette 4.1.3 → 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 +130 -140
- package/dist/maquette.umd.js +130 -140
- package/dist/maquette.umd.min.js +1 -1
- package/dist/projection.js +16 -19
- 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 -64
- package/polyfills/maquette-polyfills.js +0 -531
package/dist/maquette.cjs.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Creates a {@link CalculationCache} object, useful for caching {@link VNode} trees.
|
|
5
|
+
* In practice, caching of {@link VNode} trees is not needed, because achieving 60 frames per second is almost never a problem.
|
|
6
|
+
* For more information, see {@link CalculationCache}.
|
|
7
|
+
*
|
|
8
|
+
* @param <Result> The type of the value that is cached.
|
|
9
|
+
*/
|
|
10
|
+
var createCache = function () {
|
|
11
|
+
var cachedInputs;
|
|
12
|
+
var cachedOutcome;
|
|
13
|
+
return {
|
|
14
|
+
invalidate: function () {
|
|
15
|
+
cachedOutcome = undefined;
|
|
16
|
+
cachedInputs = undefined;
|
|
17
|
+
},
|
|
18
|
+
result: function (inputs, calculation) {
|
|
19
|
+
if (cachedInputs) {
|
|
20
|
+
for (var i = 0; i < inputs.length; i++) {
|
|
21
|
+
if (cachedInputs[i] !== inputs[i]) {
|
|
22
|
+
cachedOutcome = undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!cachedOutcome) {
|
|
27
|
+
cachedOutcome = calculation();
|
|
28
|
+
cachedInputs = inputs;
|
|
29
|
+
}
|
|
30
|
+
return cachedOutcome;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
3
35
|
var NAMESPACE_W3 = "http://www.w3.org/";
|
|
4
36
|
var NAMESPACE_SVG = "".concat(NAMESPACE_W3, "2000/svg");
|
|
5
37
|
var NAMESPACE_XLINK = "".concat(NAMESPACE_W3, "1999/xlink");
|
|
@@ -61,11 +93,7 @@ var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, oper
|
|
|
61
93
|
if (i !== indexToCheck) {
|
|
62
94
|
var node = childNodes[i];
|
|
63
95
|
if (same(node, childNode)) {
|
|
64
|
-
throw {
|
|
65
|
-
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.")),
|
|
66
|
-
parentNode: parentVNode,
|
|
67
|
-
childNode: childNode,
|
|
68
|
-
};
|
|
96
|
+
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 });
|
|
69
97
|
}
|
|
70
98
|
}
|
|
71
99
|
}
|
|
@@ -128,6 +156,7 @@ var nodeToRemove = function (vNode) {
|
|
|
128
156
|
}
|
|
129
157
|
};
|
|
130
158
|
var vnodeOnlyProps = [
|
|
159
|
+
"on",
|
|
131
160
|
"afterCreate",
|
|
132
161
|
"afterUpdate",
|
|
133
162
|
"afterRemoved",
|
|
@@ -178,19 +207,6 @@ var setProperties = function (domNode, properties, projectionOptions) {
|
|
|
178
207
|
}
|
|
179
208
|
}
|
|
180
209
|
}
|
|
181
|
-
else if (propName === "on" && propValue) {
|
|
182
|
-
// object with string keys and function values
|
|
183
|
-
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
184
|
-
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
185
|
-
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
186
|
-
if (eventHandlerInterceptor) {
|
|
187
|
-
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
188
|
-
}
|
|
189
|
-
if (listener) {
|
|
190
|
-
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
210
|
else if (propName !== "key" && propValue !== null && propValue !== undefined) {
|
|
195
211
|
var type = typeof propValue;
|
|
196
212
|
if (type === "function") {
|
|
@@ -219,6 +235,19 @@ var setProperties = function (domNode, properties, projectionOptions) {
|
|
|
219
235
|
}
|
|
220
236
|
}
|
|
221
237
|
}
|
|
238
|
+
if (properties.on) {
|
|
239
|
+
// object with string keys and function values
|
|
240
|
+
for (var _i = 0, _a = Object.entries(properties.on); _i < _a.length; _i++) {
|
|
241
|
+
var _b = _a[_i], key = _b[0], handler = _b[1];
|
|
242
|
+
var listener = typeof handler === "function" ? handler : handler.listener;
|
|
243
|
+
if (eventHandlerInterceptor) {
|
|
244
|
+
listener = eventHandlerInterceptor(key, listener, domNode, properties);
|
|
245
|
+
}
|
|
246
|
+
if (listener) {
|
|
247
|
+
domNode.addEventListener(key, listener, typeof handler === "function" ? undefined : handler.options);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
222
251
|
};
|
|
223
252
|
var addChildren = function (domNode, children, projectionOptions) {
|
|
224
253
|
if (!children) {
|
|
@@ -498,7 +527,7 @@ updateDom = function (previous, vnode, projectionOptions, parentNode, oldChildre
|
|
|
498
527
|
try {
|
|
499
528
|
parentNode.replaceChild(newTextNode, domNode);
|
|
500
529
|
}
|
|
501
|
-
catch (
|
|
530
|
+
catch (_a) {
|
|
502
531
|
// Text nodes can be substituted by google translate
|
|
503
532
|
parentNode.replaceChild(newTextNode, parentNode.childNodes[oldChildren.indexOf(previous)]);
|
|
504
533
|
}
|
|
@@ -581,13 +610,13 @@ var applyDefaultProjectionOptions = function (projectorOptions) {
|
|
|
581
610
|
};
|
|
582
611
|
var dom = {
|
|
583
612
|
/**
|
|
584
|
-
* Creates a real DOM tree from `vnode`. The
|
|
585
|
-
* its
|
|
586
|
-
* This is a low-level method. Users will typically use a
|
|
587
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
613
|
+
* Creates a real DOM tree from `vnode`. The {@link Projection} object returned will contain the resulting DOM Node in
|
|
614
|
+
* its {@link Projection.domNode | domNode} property.
|
|
615
|
+
* This is a low-level method. Users will typically use a {@link Projector} instead.
|
|
616
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
|
|
588
617
|
* objects may only be rendered once.
|
|
589
618
|
* @param projectionOptions - Options to be used to create and update the projection.
|
|
590
|
-
* @returns The
|
|
619
|
+
* @returns The {@link Projection} which also contains the DOM Node that was created.
|
|
591
620
|
*/
|
|
592
621
|
create: function (vnode, projectionOptions) {
|
|
593
622
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -595,13 +624,13 @@ var dom = {
|
|
|
595
624
|
return createProjection(vnode, projectionOptions);
|
|
596
625
|
},
|
|
597
626
|
/**
|
|
598
|
-
* Appends a new child node to the DOM which is generated from a
|
|
599
|
-
* This is a low-level method. Users will typically use a
|
|
627
|
+
* Appends a new child node to the DOM which is generated from a {@link VNode}.
|
|
628
|
+
* This is a low-level method. Users will typically use a {@link Projector} instead.
|
|
600
629
|
* @param parentNode - The parent node for the new child node.
|
|
601
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
630
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
|
|
602
631
|
* objects may only be rendered once.
|
|
603
|
-
* @param projectionOptions - Options to be used to create and update the
|
|
604
|
-
* @returns The
|
|
632
|
+
* @param projectionOptions - Options to be used to create and update the {@link Projection}.
|
|
633
|
+
* @returns The {@link Projection} that was created.
|
|
605
634
|
*/
|
|
606
635
|
append: function (parentNode, vnode, projectionOptions) {
|
|
607
636
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -609,13 +638,13 @@ var dom = {
|
|
|
609
638
|
return createProjection(vnode, projectionOptions);
|
|
610
639
|
},
|
|
611
640
|
/**
|
|
612
|
-
* Inserts a new DOM node which is generated from a
|
|
613
|
-
* This is a low-level method. Users wil typically use a
|
|
641
|
+
* Inserts a new DOM node which is generated from a {@link VNode}.
|
|
642
|
+
* This is a low-level method. Users wil typically use a {@link Projector} instead.
|
|
614
643
|
* @param beforeNode - The node that the DOM Node is inserted before.
|
|
615
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
616
|
-
* NOTE:
|
|
617
|
-
* @param projectionOptions - Options to be used to create and update the projection, see
|
|
618
|
-
* @returns The
|
|
644
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function.
|
|
645
|
+
* NOTE: {@link VNode} objects may only be rendered once.
|
|
646
|
+
* @param projectionOptions - Options to be used to create and update the projection, see {@link createProjector}.
|
|
647
|
+
* @returns The {@link Projection} that was created.
|
|
619
648
|
*/
|
|
620
649
|
insertBefore: function (beforeNode, vnode, projectionOptions) {
|
|
621
650
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -623,15 +652,15 @@ var dom = {
|
|
|
623
652
|
return createProjection(vnode, projectionOptions);
|
|
624
653
|
},
|
|
625
654
|
/**
|
|
626
|
-
* Merges a new DOM node which is generated from a
|
|
655
|
+
* Merges a new DOM node which is generated from a {@link VNode} with an existing DOM Node.
|
|
627
656
|
* This means that the virtual DOM and the real DOM will have one overlapping element.
|
|
628
|
-
* Therefore the selector for the root
|
|
629
|
-
* This is a low-level method. Users wil typically use a
|
|
657
|
+
* Therefore the selector for the root {@link VNode} will be ignored, but its properties and children will be applied to the Element provided.
|
|
658
|
+
* This is a low-level method. Users wil typically use a {@link Projector} instead.
|
|
630
659
|
* @param element - The existing element to adopt as the root of the new virtual DOM. Existing attributes and child nodes are preserved.
|
|
631
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
660
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode} objects
|
|
632
661
|
* may only be rendered once.
|
|
633
|
-
* @param projectionOptions - Options to be used to create and update the projection, see
|
|
634
|
-
* @returns The
|
|
662
|
+
* @param projectionOptions - Options to be used to create and update the projection, see {@link createProjector}.
|
|
663
|
+
* @returns The {@link Projection} that was created.
|
|
635
664
|
*/
|
|
636
665
|
merge: function (element, vnode, projectionOptions) {
|
|
637
666
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -640,13 +669,13 @@ var dom = {
|
|
|
640
669
|
return createProjection(vnode, projectionOptions);
|
|
641
670
|
},
|
|
642
671
|
/**
|
|
643
|
-
* Replaces an existing DOM node with a node generated from a
|
|
644
|
-
* This is a low-level method. Users will typically use a
|
|
645
|
-
* @param element - The node for the
|
|
646
|
-
* @param vnode - The root of the virtual DOM tree that was created using the
|
|
672
|
+
* Replaces an existing DOM node with a node generated from a {@link VNode}.
|
|
673
|
+
* This is a low-level method. Users will typically use a {@link Projector} instead.
|
|
674
|
+
* @param element - The node for the {@link VNode} to replace.
|
|
675
|
+
* @param vnode - The root of the virtual DOM tree that was created using the {@link h} function. NOTE: {@link VNode}
|
|
647
676
|
* objects may only be rendered once.
|
|
648
|
-
* @param projectionOptions - Options to be used to create and update the
|
|
649
|
-
* @returns The
|
|
677
|
+
* @param projectionOptions - Options to be used to create and update the {@link Projection}.
|
|
678
|
+
* @returns The {@link Projection} that was created.
|
|
650
679
|
*/
|
|
651
680
|
replace: function (element, vnode, projectionOptions) {
|
|
652
681
|
projectionOptions = applyDefaultProjectionOptions(projectionOptions);
|
|
@@ -712,6 +741,57 @@ function h(selector, properties, children) {
|
|
|
712
741
|
};
|
|
713
742
|
}
|
|
714
743
|
|
|
744
|
+
/**
|
|
745
|
+
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
|
|
746
|
+
* See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
|
|
747
|
+
*
|
|
748
|
+
* @param <Source> The type of source items. A database-record for instance.
|
|
749
|
+
* @param <Target> The type of target items. A {@link MaquetteComponent} for instance.
|
|
750
|
+
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
|
|
751
|
+
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
|
|
752
|
+
* to the `callback` argument in `Array.map(callback)`.
|
|
753
|
+
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
|
|
754
|
+
*/
|
|
755
|
+
var createMapping = function (getSourceKey, createResult, updateResult) {
|
|
756
|
+
var keys = [];
|
|
757
|
+
var results = [];
|
|
758
|
+
return {
|
|
759
|
+
results: results,
|
|
760
|
+
map: function (newSources) {
|
|
761
|
+
var newKeys = newSources.map(getSourceKey);
|
|
762
|
+
var oldTargets = results.slice();
|
|
763
|
+
var oldIndex = 0;
|
|
764
|
+
for (var i = 0; i < newSources.length; i++) {
|
|
765
|
+
var source = newSources[i];
|
|
766
|
+
var sourceKey = newKeys[i];
|
|
767
|
+
if (sourceKey === keys[oldIndex]) {
|
|
768
|
+
results[i] = oldTargets[oldIndex];
|
|
769
|
+
updateResult(source, oldTargets[oldIndex], i);
|
|
770
|
+
oldIndex++;
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
var found = false;
|
|
774
|
+
for (var j = 1; j < keys.length + 1; j++) {
|
|
775
|
+
var searchIndex = (oldIndex + j) % keys.length;
|
|
776
|
+
if (keys[searchIndex] === sourceKey) {
|
|
777
|
+
results[i] = oldTargets[searchIndex];
|
|
778
|
+
updateResult(newSources[i], oldTargets[searchIndex], i);
|
|
779
|
+
oldIndex = searchIndex + 1;
|
|
780
|
+
found = true;
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (!found) {
|
|
785
|
+
results[i] = createResult(source, i);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
results.length = newSources.length;
|
|
790
|
+
keys = newKeys;
|
|
791
|
+
},
|
|
792
|
+
};
|
|
793
|
+
};
|
|
794
|
+
|
|
715
795
|
var createParentNodePath = function (node, rootNode) {
|
|
716
796
|
var parentNodePath = [];
|
|
717
797
|
while (node && node !== rootNode) {
|
|
@@ -720,19 +800,12 @@ var createParentNodePath = function (node, rootNode) {
|
|
|
720
800
|
}
|
|
721
801
|
return parentNodePath;
|
|
722
802
|
};
|
|
723
|
-
var find;
|
|
724
|
-
if (Array.prototype.find) {
|
|
725
|
-
find = function (items, predicate) { return items.find(predicate); };
|
|
726
|
-
}
|
|
727
|
-
else {
|
|
728
|
-
find = function (items, predicate) { return items.filter(predicate)[0]; };
|
|
729
|
-
}
|
|
730
803
|
var findVNodeByParentNodePath = function (vnode, parentNodePath) {
|
|
731
804
|
var result = vnode;
|
|
732
805
|
parentNodePath.forEach(function (node) {
|
|
733
806
|
result =
|
|
734
807
|
result && result.children
|
|
735
|
-
?
|
|
808
|
+
? result.children.find(function (child) { return child.domNode === node; })
|
|
736
809
|
: undefined;
|
|
737
810
|
});
|
|
738
811
|
return result;
|
|
@@ -759,9 +832,9 @@ var createEventHandlerInterceptor = function (projector, getProjection, performa
|
|
|
759
832
|
}
|
|
760
833
|
};
|
|
761
834
|
/**
|
|
762
|
-
* Creates a
|
|
835
|
+
* Creates a {@link Projector} instance using the provided projectionOptions.
|
|
763
836
|
*
|
|
764
|
-
* For more information, see
|
|
837
|
+
* For more information, see {@link Projector}.
|
|
765
838
|
*
|
|
766
839
|
* @param projectorOptions Options that influence how the DOM is rendered and updated.
|
|
767
840
|
*/
|
|
@@ -846,89 +919,6 @@ var createProjector = function (projectorOptions) {
|
|
|
846
919
|
return projector;
|
|
847
920
|
};
|
|
848
921
|
|
|
849
|
-
/**
|
|
850
|
-
* Creates a [[CalculationCache]] object, useful for caching [[VNode]] trees.
|
|
851
|
-
* In practice, caching of [[VNode]] trees is not needed, because achieving 60 frames per second is almost never a problem.
|
|
852
|
-
* For more information, see [[CalculationCache]].
|
|
853
|
-
*
|
|
854
|
-
* @param <Result> The type of the value that is cached.
|
|
855
|
-
*/
|
|
856
|
-
var createCache = function () {
|
|
857
|
-
var cachedInputs;
|
|
858
|
-
var cachedOutcome;
|
|
859
|
-
return {
|
|
860
|
-
invalidate: function () {
|
|
861
|
-
cachedOutcome = undefined;
|
|
862
|
-
cachedInputs = undefined;
|
|
863
|
-
},
|
|
864
|
-
result: function (inputs, calculation) {
|
|
865
|
-
if (cachedInputs) {
|
|
866
|
-
for (var i = 0; i < inputs.length; i++) {
|
|
867
|
-
if (cachedInputs[i] !== inputs[i]) {
|
|
868
|
-
cachedOutcome = undefined;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
if (!cachedOutcome) {
|
|
873
|
-
cachedOutcome = calculation();
|
|
874
|
-
cachedInputs = inputs;
|
|
875
|
-
}
|
|
876
|
-
return cachedOutcome;
|
|
877
|
-
},
|
|
878
|
-
};
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
/**
|
|
882
|
-
* Creates a {@link Mapping} instance that keeps an array of result objects synchronized with an array of source objects.
|
|
883
|
-
* See {@link http://maquettejs.org/docs/arrays.html Working with arrays}.
|
|
884
|
-
*
|
|
885
|
-
* @param <Source> The type of source items. A database-record for instance.
|
|
886
|
-
* @param <Target> The type of target items. A [[MaquetteComponent]] for instance.
|
|
887
|
-
* @param getSourceKey `function(source)` that must return a key to identify each source object. The result must either be a string or a number.
|
|
888
|
-
* @param createResult `function(source, index)` that must create a new result object from a given source. This function is identical
|
|
889
|
-
* to the `callback` argument in `Array.map(callback)`.
|
|
890
|
-
* @param updateResult `function(source, target, index)` that updates a result to an updated source.
|
|
891
|
-
*/
|
|
892
|
-
var createMapping = function (getSourceKey, createResult, updateResult) {
|
|
893
|
-
var keys = [];
|
|
894
|
-
var results = [];
|
|
895
|
-
return {
|
|
896
|
-
results: results,
|
|
897
|
-
map: function (newSources) {
|
|
898
|
-
var newKeys = newSources.map(getSourceKey);
|
|
899
|
-
var oldTargets = results.slice();
|
|
900
|
-
var oldIndex = 0;
|
|
901
|
-
for (var i = 0; i < newSources.length; i++) {
|
|
902
|
-
var source = newSources[i];
|
|
903
|
-
var sourceKey = newKeys[i];
|
|
904
|
-
if (sourceKey === keys[oldIndex]) {
|
|
905
|
-
results[i] = oldTargets[oldIndex];
|
|
906
|
-
updateResult(source, oldTargets[oldIndex], i);
|
|
907
|
-
oldIndex++;
|
|
908
|
-
}
|
|
909
|
-
else {
|
|
910
|
-
var found = false;
|
|
911
|
-
for (var j = 1; j < keys.length + 1; j++) {
|
|
912
|
-
var searchIndex = (oldIndex + j) % keys.length;
|
|
913
|
-
if (keys[searchIndex] === sourceKey) {
|
|
914
|
-
results[i] = oldTargets[searchIndex];
|
|
915
|
-
updateResult(newSources[i], oldTargets[searchIndex], i);
|
|
916
|
-
oldIndex = searchIndex + 1;
|
|
917
|
-
found = true;
|
|
918
|
-
break;
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
if (!found) {
|
|
922
|
-
results[i] = createResult(source, i);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
results.length = newSources.length;
|
|
927
|
-
keys = newKeys;
|
|
928
|
-
},
|
|
929
|
-
};
|
|
930
|
-
};
|
|
931
|
-
|
|
932
922
|
exports.createCache = createCache;
|
|
933
923
|
exports.createMapping = createMapping;
|
|
934
924
|
exports.createProjector = createProjector;
|