j-templates 5.0.47 → 5.0.48
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/DOM/domNodeConfig.js +10 -1
- package/Node/elementNode.d.ts +1 -1
- package/Node/elementNode.js +78 -58
- package/Node/elementNode.types.d.ts +6 -1
- package/Node/nodeConfig.d.ts +3 -0
- package/Node/nodeRef.d.ts +3 -1
- package/Node/nodeRef.js +30 -5
- package/Store/Tree/observableTree.js +6 -5
- package/Utils/list.d.ts +3 -0
- package/Utils/list.js +40 -2
- package/index.debug.d.ts +0 -1
- package/index.debug.js +0 -12
- package/jTemplates.js +164 -71
- package/jTemplates.js.map +1 -1
- package/package.json +1 -1
package/jTemplates.js
CHANGED
|
@@ -88,7 +88,16 @@ exports.DOMNodeConfig = {
|
|
|
88
88
|
var cEvent = new CustomEvent(event, data);
|
|
89
89
|
target.dispatchEvent(cEvent);
|
|
90
90
|
},
|
|
91
|
-
setProperties: utils_1.SetProperties
|
|
91
|
+
setProperties: utils_1.SetProperties,
|
|
92
|
+
getFirstChild(target) {
|
|
93
|
+
return target.firstChild;
|
|
94
|
+
},
|
|
95
|
+
getNextSibling(target) {
|
|
96
|
+
return target.nextSibling;
|
|
97
|
+
},
|
|
98
|
+
replaceChildren(target, children) {
|
|
99
|
+
target.replaceChildren(...children);
|
|
100
|
+
},
|
|
92
101
|
};
|
|
93
102
|
|
|
94
103
|
|
|
@@ -660,13 +669,13 @@ function AddTemplate(node, init) {
|
|
|
660
669
|
|
|
661
670
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
662
671
|
exports.ElementNode = void 0;
|
|
663
|
-
const
|
|
664
|
-
const nodeConfig_1 = __webpack_require__(/*! ./nodeConfig */ "./src/Node/nodeConfig.ts");
|
|
672
|
+
const observableScope_1 = __webpack_require__(/*! ../Store/Tree/observableScope */ "./src/Store/Tree/observableScope.ts");
|
|
665
673
|
const injector_1 = __webpack_require__(/*! ../Utils/injector */ "./src/Utils/injector.ts");
|
|
666
674
|
const list_1 = __webpack_require__(/*! ../Utils/list */ "./src/Utils/list.ts");
|
|
667
675
|
const thread_1 = __webpack_require__(/*! ../Utils/thread */ "./src/Utils/thread.ts");
|
|
676
|
+
const boundNode_1 = __webpack_require__(/*! ./boundNode */ "./src/Node/boundNode.ts");
|
|
677
|
+
const nodeConfig_1 = __webpack_require__(/*! ./nodeConfig */ "./src/Node/nodeConfig.ts");
|
|
668
678
|
const nodeRef_1 = __webpack_require__(/*! ./nodeRef */ "./src/Node/nodeRef.ts");
|
|
669
|
-
const observableScope_1 = __webpack_require__(/*! ../Store/Tree/observableScope */ "./src/Store/Tree/observableScope.ts");
|
|
670
679
|
var ElementNode;
|
|
671
680
|
(function (ElementNode) {
|
|
672
681
|
function Create(type, namespace, nodeDef, children) {
|
|
@@ -726,75 +735,99 @@ function SetDefaultData(node) {
|
|
|
726
735
|
(0, thread_1.Thread)(function () {
|
|
727
736
|
if (node.destroyed)
|
|
728
737
|
return;
|
|
729
|
-
|
|
738
|
+
const defaultNodeList = list_1.List.Create();
|
|
739
|
+
list_1.List.Add(defaultNodeList, {
|
|
740
|
+
value: null,
|
|
741
|
+
init: true,
|
|
742
|
+
nodes
|
|
743
|
+
});
|
|
744
|
+
nodeRef_1.NodeRef.ReconcileChildren(node, defaultNodeList);
|
|
730
745
|
});
|
|
731
746
|
}
|
|
732
747
|
});
|
|
733
748
|
}
|
|
734
|
-
function
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
if (
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
(0, thread_1.Schedule)(function () {
|
|
753
|
-
if (node.destroyed || newNodesMap.size === 0)
|
|
754
|
-
return;
|
|
755
|
-
nodeRef_1.NodeRef.InitAll(nodes);
|
|
756
|
-
list_1.List.Push(newNodeArrayList, nodes);
|
|
757
|
-
});
|
|
749
|
+
function GetDataValue(data) {
|
|
750
|
+
return data.value;
|
|
751
|
+
}
|
|
752
|
+
function ReconcileNodeData(node, values) {
|
|
753
|
+
const nextNodeList = list_1.List.Create();
|
|
754
|
+
const initNodeList = list_1.List.Create();
|
|
755
|
+
const currentNodeList = node.nodeList;
|
|
756
|
+
const nodeMap = currentNodeList && list_1.List.ToNodeMap(currentNodeList, GetDataValue);
|
|
757
|
+
for (let x = 0; x < values.length; x++) {
|
|
758
|
+
let curNode;
|
|
759
|
+
if (nodeMap) {
|
|
760
|
+
const nodeArr = nodeMap.get(values[x]);
|
|
761
|
+
if (nodeArr) {
|
|
762
|
+
let y = nodeArr.length - 1;
|
|
763
|
+
for (; y >= 0 && !curNode; y--) {
|
|
764
|
+
curNode = nodeArr[y];
|
|
765
|
+
nodeArr[y] = null;
|
|
766
|
+
}
|
|
758
767
|
}
|
|
759
|
-
else
|
|
760
|
-
list_1.List.Push(newNodeArrayList, nodes);
|
|
761
|
-
newNodesArrays[x] = nodes;
|
|
762
768
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
769
|
+
if (curNode) {
|
|
770
|
+
list_1.List.RemoveNode(currentNodeList, curNode);
|
|
771
|
+
list_1.List.AddNode(nextNodeList, curNode);
|
|
772
|
+
if (!curNode.data.init)
|
|
773
|
+
list_1.List.Add(initNodeList, curNode.data);
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
curNode = list_1.List.Add(nextNodeList, {
|
|
777
|
+
value: values[x],
|
|
778
|
+
init: false,
|
|
779
|
+
nodes: injector_1.Injector.Scope(node.injector, CreateNodeArray, node.childrenFunc, values[x])
|
|
780
|
+
});
|
|
781
|
+
list_1.List.Add(initNodeList, curNode.data);
|
|
768
782
|
}
|
|
769
|
-
|
|
783
|
+
}
|
|
784
|
+
let curNode = initNodeList.head;
|
|
785
|
+
while (curNode) {
|
|
786
|
+
const data = curNode.data;
|
|
787
|
+
(0, thread_1.Schedule)(function () {
|
|
788
|
+
if (node.destroyed || nextNodeList.size === 0)
|
|
789
|
+
return;
|
|
790
|
+
nodeRef_1.NodeRef.InitAll(data.nodes);
|
|
791
|
+
data.init = true;
|
|
792
|
+
});
|
|
793
|
+
curNode = curNode.next;
|
|
794
|
+
}
|
|
795
|
+
if (currentNodeList) {
|
|
796
|
+
let curDetach = currentNodeList.head;
|
|
797
|
+
while (curDetach) {
|
|
798
|
+
nodeRef_1.NodeRef.DestroyAll(curDetach.data.nodes);
|
|
799
|
+
for (let x = 0; x < curDetach.data.nodes.length; x++)
|
|
800
|
+
node.childNodes.delete(curDetach.data.nodes[x]);
|
|
801
|
+
curDetach = curDetach.next;
|
|
802
|
+
}
|
|
803
|
+
list_1.List.Clear(currentNodeList);
|
|
804
|
+
}
|
|
805
|
+
let curAttach = nextNodeList.head;
|
|
806
|
+
while (curAttach) {
|
|
807
|
+
for (let x = 0; x < curAttach.data.nodes.length; x++)
|
|
808
|
+
node.childNodes.add(curAttach.data.nodes[x]);
|
|
809
|
+
curAttach = curAttach.next;
|
|
810
|
+
}
|
|
811
|
+
node.nodeList = nextNodeList;
|
|
812
|
+
}
|
|
813
|
+
function SetData(node, values, init = false) {
|
|
814
|
+
(0, thread_1.Synch)(function () {
|
|
815
|
+
ReconcileNodeData(node, values);
|
|
816
|
+
const attachNodes = node.nodeList;
|
|
770
817
|
(0, thread_1.Thread)(function () {
|
|
771
818
|
if (node.destroyed)
|
|
772
819
|
return;
|
|
773
820
|
if (init)
|
|
774
|
-
|
|
821
|
+
nodeRef_1.NodeRef.ReconcileChildren(node, attachNodes);
|
|
775
822
|
else
|
|
776
823
|
nodeConfig_1.NodeConfig.scheduleUpdate(function () {
|
|
777
|
-
if (node.destroyed)
|
|
824
|
+
if (node.destroyed || attachNodes.size < node.childNodes.size)
|
|
778
825
|
return;
|
|
779
|
-
|
|
826
|
+
nodeRef_1.NodeRef.ReconcileChildren(node, attachNodes);
|
|
780
827
|
});
|
|
781
828
|
});
|
|
782
829
|
});
|
|
783
830
|
}
|
|
784
|
-
function DetachAndAddNodes(node, detachNodes, newNodes) {
|
|
785
|
-
for (var x = 0; x < detachNodes.length; x++)
|
|
786
|
-
list_1.List.ForEach(detachNodes[x], function (nodes) {
|
|
787
|
-
for (var x = 0; x < nodes.length; x++)
|
|
788
|
-
nodeRef_1.NodeRef.DetachChild(node, nodes[x]);
|
|
789
|
-
});
|
|
790
|
-
var previousNode = null;
|
|
791
|
-
for (var x = 0; newNodes && x < newNodes.length; x++) {
|
|
792
|
-
for (var y = 0; y < newNodes[x].length; y++) {
|
|
793
|
-
nodeRef_1.NodeRef.AddChildAfter(node, previousNode, newNodes[x][y]);
|
|
794
|
-
previousNode = newNodes[x][y];
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
831
|
function CreateNodeArray(childrenFunc, value) {
|
|
799
832
|
var newNodes = childrenFunc(value);
|
|
800
833
|
if (typeof newNodes === "string") {
|
|
@@ -810,10 +843,6 @@ function CreateNodeArray(childrenFunc, value) {
|
|
|
810
843
|
return newNodes;
|
|
811
844
|
return [newNodes];
|
|
812
845
|
}
|
|
813
|
-
function DestroyNodeArrayList(nodeArrayList) {
|
|
814
|
-
list_1.List.ForEach(nodeArrayList, nodeRef_1.NodeRef.DestroyAll);
|
|
815
|
-
return nodeArrayList;
|
|
816
|
-
}
|
|
817
846
|
|
|
818
847
|
|
|
819
848
|
/***/ }),
|
|
@@ -911,7 +940,7 @@ var NodeRef;
|
|
|
911
940
|
setAttributes: false,
|
|
912
941
|
setEvents: false,
|
|
913
942
|
childrenFunc: null,
|
|
914
|
-
|
|
943
|
+
nodeList: null,
|
|
915
944
|
setData: false
|
|
916
945
|
};
|
|
917
946
|
case NodeRefType.ComponentNode:
|
|
@@ -966,16 +995,41 @@ var NodeRef;
|
|
|
966
995
|
}
|
|
967
996
|
NodeRef.AddChild = AddChild;
|
|
968
997
|
function AddChildAfter(node, currentChild, newChild) {
|
|
969
|
-
if (currentChild &&
|
|
998
|
+
if (currentChild && currentChild.parent !== node)
|
|
970
999
|
throw "currentChild is not valid";
|
|
971
1000
|
newChild.parent = node;
|
|
972
1001
|
node.childNodes.add(newChild);
|
|
973
1002
|
nodeConfig_1.NodeConfig.addChildAfter(node.node, currentChild && currentChild.node, newChild.node);
|
|
974
1003
|
}
|
|
975
1004
|
NodeRef.AddChildAfter = AddChildAfter;
|
|
1005
|
+
function ReconcileChildren(node, nextChildren) {
|
|
1006
|
+
const rootNode = node.node;
|
|
1007
|
+
if (nextChildren.size === 0) {
|
|
1008
|
+
nodeConfig_1.NodeConfig.replaceChildren(rootNode, []);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
let priorNode;
|
|
1012
|
+
let curDataNode = nextChildren?.head;
|
|
1013
|
+
while (curDataNode) {
|
|
1014
|
+
for (let x = 0; x < curDataNode.data.nodes.length; x++) {
|
|
1015
|
+
const actualNode = priorNode ? nodeConfig_1.NodeConfig.getNextSibling(priorNode) : nodeConfig_1.NodeConfig.getFirstChild(rootNode);
|
|
1016
|
+
const expectedNode = curDataNode.data.nodes[x].node;
|
|
1017
|
+
if (actualNode !== expectedNode) {
|
|
1018
|
+
nodeConfig_1.NodeConfig.addChildBefore(rootNode, actualNode, expectedNode);
|
|
1019
|
+
}
|
|
1020
|
+
priorNode = expectedNode;
|
|
1021
|
+
}
|
|
1022
|
+
curDataNode = curDataNode.next;
|
|
1023
|
+
}
|
|
1024
|
+
let remainingSibling = priorNode && nodeConfig_1.NodeConfig.getNextSibling(priorNode);
|
|
1025
|
+
while (remainingSibling) {
|
|
1026
|
+
nodeConfig_1.NodeConfig.removeChild(rootNode, remainingSibling);
|
|
1027
|
+
remainingSibling = nodeConfig_1.NodeConfig.getNextSibling(priorNode);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
NodeRef.ReconcileChildren = ReconcileChildren;
|
|
976
1031
|
function DetachChild(node, child) {
|
|
977
|
-
if (node.childNodes.
|
|
978
|
-
node.childNodes.delete(child);
|
|
1032
|
+
if (node.childNodes.delete(child)) {
|
|
979
1033
|
nodeConfig_1.NodeConfig.removeChild(node.node, child.node);
|
|
980
1034
|
child.parent = null;
|
|
981
1035
|
}
|
|
@@ -985,7 +1039,7 @@ var NodeRef;
|
|
|
985
1039
|
if (node.destroyed)
|
|
986
1040
|
return;
|
|
987
1041
|
node.destroyed = true;
|
|
988
|
-
node.childNodes
|
|
1042
|
+
node.childNodes?.forEach(Destroy);
|
|
989
1043
|
for (let x = 0; x < node.destroyables.length; x++)
|
|
990
1044
|
node.destroyables[x]?.Destroy();
|
|
991
1045
|
}
|
|
@@ -2089,14 +2143,12 @@ class ObservableTree {
|
|
|
2089
2143
|
if (!parentValue)
|
|
2090
2144
|
throw new Error("Unable to write path: " + path + ". Falsey value found at: " + pathParts.slice(0, x).join("."));
|
|
2091
2145
|
const prop = pathParts[x];
|
|
2092
|
-
const exists = Object.hasOwn(parentValue, prop);
|
|
2093
2146
|
const oldValue = parentValue[prop];
|
|
2094
2147
|
const oldType = TypeOf(oldValue);
|
|
2095
2148
|
parentValue[prop] = value;
|
|
2096
|
-
if (oldType !== Type.Value)
|
|
2097
|
-
return this.scopeCache.get(
|
|
2098
|
-
|
|
2099
|
-
const leafScopes = exists && this.leafScopeCache.get(parentValue);
|
|
2149
|
+
if (oldType !== Type.Value || Array.isArray(parentValue))
|
|
2150
|
+
return this.scopeCache.get(parentValue) || this.scopeCache.get(oldValue);
|
|
2151
|
+
const leafScopes = this.leafScopeCache.get(parentValue);
|
|
2100
2152
|
return leafScopes && leafScopes[prop] || this.scopeCache.get(parentValue);
|
|
2101
2153
|
}
|
|
2102
2154
|
UpdatePathCache(path, value) {
|
|
@@ -2104,6 +2156,9 @@ class ObservableTree {
|
|
|
2104
2156
|
if (type === Type.Value)
|
|
2105
2157
|
return;
|
|
2106
2158
|
this.pathCache.set(value, path);
|
|
2159
|
+
this.proxyCache.delete(value);
|
|
2160
|
+
this.scopeCache.delete(value);
|
|
2161
|
+
this.leafScopeCache.delete(value);
|
|
2107
2162
|
const keys = Object.keys(value);
|
|
2108
2163
|
for (let x = 0; x < keys.length; x++)
|
|
2109
2164
|
this.UpdatePathCache(`${path}.${keys[x]}`, value[keys[x]]);
|
|
@@ -2791,7 +2846,11 @@ var List;
|
|
|
2791
2846
|
}
|
|
2792
2847
|
List.Pop = Pop;
|
|
2793
2848
|
function Add(list, data) {
|
|
2794
|
-
|
|
2849
|
+
const node = { previous: null, next: null, data: data };
|
|
2850
|
+
return AddNode(list, node);
|
|
2851
|
+
}
|
|
2852
|
+
List.Add = Add;
|
|
2853
|
+
function AddNode(list, node) {
|
|
2795
2854
|
if (list.size === 0) {
|
|
2796
2855
|
list.head = node;
|
|
2797
2856
|
list.tail = node;
|
|
@@ -2805,7 +2864,7 @@ var List;
|
|
|
2805
2864
|
}
|
|
2806
2865
|
return node;
|
|
2807
2866
|
}
|
|
2808
|
-
List.
|
|
2867
|
+
List.AddNode = AddNode;
|
|
2809
2868
|
function AddBefore(list, node, data) {
|
|
2810
2869
|
if (!node)
|
|
2811
2870
|
return List.Add(list, data);
|
|
@@ -2853,6 +2912,25 @@ var List;
|
|
|
2853
2912
|
return node.data;
|
|
2854
2913
|
}
|
|
2855
2914
|
List.Remove = Remove;
|
|
2915
|
+
function RemoveNode(list, node) {
|
|
2916
|
+
if (list.head === node) {
|
|
2917
|
+
list.head = node.next;
|
|
2918
|
+
}
|
|
2919
|
+
else if (list.tail === node) {
|
|
2920
|
+
list.tail = node.previous;
|
|
2921
|
+
}
|
|
2922
|
+
else {
|
|
2923
|
+
const prev = node.previous;
|
|
2924
|
+
const next = node.next;
|
|
2925
|
+
prev.next = next;
|
|
2926
|
+
next.previous = prev;
|
|
2927
|
+
}
|
|
2928
|
+
node.next = node.previous = null;
|
|
2929
|
+
list.size--;
|
|
2930
|
+
if (list.size > 0)
|
|
2931
|
+
list.head.previous = list.tail.next = null;
|
|
2932
|
+
}
|
|
2933
|
+
List.RemoveNode = RemoveNode;
|
|
2856
2934
|
function ForEach(list, callback) {
|
|
2857
2935
|
var node = list.head;
|
|
2858
2936
|
while (node) {
|
|
@@ -2861,6 +2939,21 @@ var List;
|
|
|
2861
2939
|
}
|
|
2862
2940
|
}
|
|
2863
2941
|
List.ForEach = ForEach;
|
|
2942
|
+
function ToNodeMap(list, keyCallback) {
|
|
2943
|
+
const map = new Map();
|
|
2944
|
+
let node = list.head;
|
|
2945
|
+
while (node) {
|
|
2946
|
+
const key = keyCallback(node.data);
|
|
2947
|
+
const nodes = map.get(key) || [node];
|
|
2948
|
+
if (nodes[0] !== node)
|
|
2949
|
+
nodes.push(node);
|
|
2950
|
+
else
|
|
2951
|
+
map.set(key, nodes);
|
|
2952
|
+
node = node.next;
|
|
2953
|
+
}
|
|
2954
|
+
return map;
|
|
2955
|
+
}
|
|
2956
|
+
List.ToNodeMap = ToNodeMap;
|
|
2864
2957
|
})(List || (exports.List = List = {}));
|
|
2865
2958
|
|
|
2866
2959
|
|