j-templates 7.0.1 → 7.0.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/DOM/createEventAssignment.d.ts +3 -0
- package/DOM/createEventAssignment.js +6 -0
- package/DOM/domNodeConfig.js +3 -2
- package/Node/nodeConfig.d.ts +1 -0
- package/Node/vNode.js +39 -32
- package/Node/vNode.types.d.ts +0 -7
- package/Store/Tree/observableScope.js +14 -9
- package/Utils/animation.js +4 -4
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateEventAssignment = CreateEventAssignment;
|
|
4
|
+
exports.AssignEvents = AssignEvents;
|
|
4
5
|
function CreateEventAssignment(target, event) {
|
|
5
6
|
let lastEvent;
|
|
6
7
|
return function (next) {
|
|
@@ -12,3 +13,8 @@ function CreateEventAssignment(target, event) {
|
|
|
12
13
|
lastEvent = nextEvent;
|
|
13
14
|
};
|
|
14
15
|
}
|
|
16
|
+
function AssignEvents(target, eventMap) {
|
|
17
|
+
const entries = Object.entries(eventMap);
|
|
18
|
+
for (let x = 0; x < entries.length; x++)
|
|
19
|
+
target.addEventListener(entries[x][0], entries[x][1]);
|
|
20
|
+
}
|
package/DOM/domNodeConfig.js
CHANGED
|
@@ -119,6 +119,9 @@ exports.DOMNodeConfig = {
|
|
|
119
119
|
createEventAssignment(target) {
|
|
120
120
|
return (0, createAssignment_1.CreateAssignment)(target, createEventAssignment_1.CreateEventAssignment);
|
|
121
121
|
},
|
|
122
|
+
assignEvents(target, next) {
|
|
123
|
+
(0, createEventAssignment_1.AssignEvents)(target, next);
|
|
124
|
+
},
|
|
122
125
|
createAttributeAssignment(target) {
|
|
123
126
|
return (0, createAssignment_1.CreateAssignment)(target, createAttributeAssignment_1.CreateAttributeAssignment);
|
|
124
127
|
},
|
|
@@ -139,8 +142,6 @@ exports.DOMNodeConfig = {
|
|
|
139
142
|
target.replaceChildren(...children);
|
|
140
143
|
},
|
|
141
144
|
reconcileChildren(target, children) {
|
|
142
|
-
if (children.length === 0 && !target.firstChild)
|
|
143
|
-
return;
|
|
144
145
|
if (children.length === 0 || !target.firstChild) {
|
|
145
146
|
target.replaceChildren(...children);
|
|
146
147
|
return;
|
package/Node/nodeConfig.d.ts
CHANGED
package/Node/vNode.js
CHANGED
|
@@ -15,9 +15,6 @@ var vNode;
|
|
|
15
15
|
node: null,
|
|
16
16
|
children: null,
|
|
17
17
|
destroyed: false,
|
|
18
|
-
assignProperties: null,
|
|
19
|
-
assignEvents: null,
|
|
20
|
-
assignAttributes: null,
|
|
21
18
|
component: null,
|
|
22
19
|
scopes: []
|
|
23
20
|
};
|
|
@@ -38,7 +35,6 @@ var vNode;
|
|
|
38
35
|
if (vnode.destroyed)
|
|
39
36
|
return;
|
|
40
37
|
vnode.destroyed = true;
|
|
41
|
-
vnode.assignEvents?.(null);
|
|
42
38
|
vnode.component?.Destroy();
|
|
43
39
|
Store_1.ObservableScope.DestroyAll(vnode.scopes);
|
|
44
40
|
vnode.children && DestroyAll(vnode.children);
|
|
@@ -72,53 +68,40 @@ function InitNode(vnode) {
|
|
|
72
68
|
const node = vnode.node = nodeConfig_1.NodeConfig.createNode(type, namespace);
|
|
73
69
|
vnode.definition = null;
|
|
74
70
|
if (props) {
|
|
75
|
-
|
|
71
|
+
const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
|
|
76
72
|
if (typeof props === 'function') {
|
|
77
73
|
const scope = Store_1.ObservableScope.Create(props);
|
|
78
74
|
vnode.scopes.push(scope);
|
|
79
|
-
Store_1.ObservableScope.Watch(scope,
|
|
80
|
-
const value = Store_1.ObservableScope.Peek(scope);
|
|
81
|
-
vnode.assignProperties(value);
|
|
82
|
-
}));
|
|
75
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignProperties));
|
|
83
76
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
vnode.assignProperties(props);
|
|
88
|
-
vnode.assignProperties = null;
|
|
77
|
+
assignProperties(value);
|
|
89
78
|
}
|
|
79
|
+
else
|
|
80
|
+
assignProperties(props);
|
|
90
81
|
}
|
|
91
82
|
if (on) {
|
|
92
|
-
|
|
83
|
+
const assignEvents = nodeConfig_1.NodeConfig.createEventAssignment(node);
|
|
93
84
|
if (typeof on === 'function') {
|
|
94
85
|
const scope = Store_1.ObservableScope.Create(on);
|
|
95
86
|
vnode.scopes.push(scope);
|
|
96
|
-
Store_1.ObservableScope.Watch(scope,
|
|
97
|
-
const value = Store_1.ObservableScope.Peek(scope);
|
|
98
|
-
vnode.assignEvents(value);
|
|
99
|
-
}));
|
|
87
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignEvents));
|
|
100
88
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
101
|
-
|
|
89
|
+
assignEvents(value);
|
|
102
90
|
}
|
|
103
91
|
else
|
|
104
|
-
|
|
92
|
+
assignEvents(on);
|
|
105
93
|
}
|
|
106
94
|
if (attrs) {
|
|
107
|
-
|
|
95
|
+
const assignAttributes = nodeConfig_1.NodeConfig.createAttributeAssignment(node);
|
|
108
96
|
if (typeof attrs === 'function') {
|
|
109
97
|
const scope = Store_1.ObservableScope.Create(attrs);
|
|
110
98
|
vnode.scopes.push(scope);
|
|
111
|
-
Store_1.ObservableScope.Watch(scope,
|
|
112
|
-
const value = Store_1.ObservableScope.Peek(scope);
|
|
113
|
-
vnode.assignAttributes(value);
|
|
114
|
-
}));
|
|
99
|
+
Store_1.ObservableScope.Watch(scope, ScheduledAssignment(assignAttributes));
|
|
115
100
|
const value = Store_1.ObservableScope.Peek(scope);
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
vnode.assignAttributes(attrs);
|
|
120
|
-
vnode.assignAttributes = null;
|
|
101
|
+
assignAttributes(value);
|
|
121
102
|
}
|
|
103
|
+
else
|
|
104
|
+
assignAttributes(attrs);
|
|
122
105
|
}
|
|
123
106
|
if (componentConstructor) {
|
|
124
107
|
vnode.component = new componentConstructor(vnode);
|
|
@@ -230,7 +213,18 @@ function WrapDynamicChildren(dataScope, nodeList, injector, children) {
|
|
|
230
213
|
else {
|
|
231
214
|
const childrenScope = Store_1.ObservableScope.Create(function () {
|
|
232
215
|
const childNodes = injector_1.Injector.Scope(injector, children, data);
|
|
233
|
-
|
|
216
|
+
const nodes = Array.isArray(childNodes) ? childNodes : [childNodes];
|
|
217
|
+
for (let x = 0; x < nodes.length; x++) {
|
|
218
|
+
if (typeof nodes[x] === 'string')
|
|
219
|
+
nodes[x] = vNode.Create({
|
|
220
|
+
type: 'text',
|
|
221
|
+
namespace: null,
|
|
222
|
+
props: {
|
|
223
|
+
nodeValue: nodes[x]
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return nodes;
|
|
234
228
|
});
|
|
235
229
|
list_1.List.Add(nextNodeList, {
|
|
236
230
|
data,
|
|
@@ -286,6 +280,19 @@ function ToArray(callback) {
|
|
|
286
280
|
return [result];
|
|
287
281
|
};
|
|
288
282
|
}
|
|
283
|
+
function ScheduledAssignment(assign) {
|
|
284
|
+
let scheduled = false;
|
|
285
|
+
return function (scope) {
|
|
286
|
+
if (scheduled)
|
|
287
|
+
return;
|
|
288
|
+
scheduled = true;
|
|
289
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(function () {
|
|
290
|
+
scheduled = false;
|
|
291
|
+
const value = Store_1.ObservableScope.Peek(scope);
|
|
292
|
+
assign(value);
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
}
|
|
289
296
|
function CreateScheduledCallback(callback) {
|
|
290
297
|
let scheduled = false;
|
|
291
298
|
return function () {
|
package/Node/vNode.types.d.ts
CHANGED
|
@@ -18,13 +18,6 @@ export type vNode = {
|
|
|
18
18
|
node: Node | null;
|
|
19
19
|
children: vNode[] | null;
|
|
20
20
|
destroyed: boolean;
|
|
21
|
-
assignProperties: (next: any) => void;
|
|
22
|
-
assignEvents: (next: {
|
|
23
|
-
[event: string]: (event: Event) => void;
|
|
24
|
-
}) => void;
|
|
25
|
-
assignAttributes: (next: {
|
|
26
|
-
[attr: string]: string;
|
|
27
|
-
}) => void;
|
|
28
21
|
scopes: IObservableScope<unknown>[];
|
|
29
22
|
component: Component;
|
|
30
23
|
};
|
|
@@ -77,8 +77,8 @@ function CalcScope(callback) {
|
|
|
77
77
|
async: valueFunction[Symbol.toStringTag] === "AsyncFunction",
|
|
78
78
|
dirty: true,
|
|
79
79
|
emitter: emitter_1.Emitter.Create(),
|
|
80
|
-
emitters:
|
|
81
|
-
calcFunctions:
|
|
80
|
+
emitters: null,
|
|
81
|
+
calcFunctions: null,
|
|
82
82
|
onDestroyed: null,
|
|
83
83
|
destroyed: false,
|
|
84
84
|
setCallback: function () {
|
|
@@ -153,16 +153,15 @@ function CalcScope(callback) {
|
|
|
153
153
|
}
|
|
154
154
|
ObservableScope.DestroyAll = DestroyAll;
|
|
155
155
|
})(ObservableScope || (exports.ObservableScope = ObservableScope = {}));
|
|
156
|
-
function CalcChanged(calc) {
|
|
157
|
-
const value = calc.getFunction();
|
|
158
|
-
const changed = calc.value !== value;
|
|
159
|
-
calc.value = value;
|
|
160
|
-
return changed;
|
|
161
|
-
}
|
|
162
156
|
function DirtyScope(scope) {
|
|
163
157
|
if (scope.dirty || !scope.getFunction)
|
|
164
158
|
return;
|
|
165
|
-
|
|
159
|
+
let dirty = scope.calcFunctions.length === 0;
|
|
160
|
+
for (let x = 0; !dirty && x < scope.calcFunctions.length; x++) {
|
|
161
|
+
const calc = scope.calcFunctions[x];
|
|
162
|
+
dirty = dirty || calc.value !== calc.getFunction();
|
|
163
|
+
}
|
|
164
|
+
scope.dirty = dirty;
|
|
166
165
|
if (!scope.dirty)
|
|
167
166
|
return;
|
|
168
167
|
if (scope.async) {
|
|
@@ -209,6 +208,12 @@ function UpdateValue(scope) {
|
|
|
209
208
|
UpdateEmitters(scope, emitters);
|
|
210
209
|
}
|
|
211
210
|
function UpdateEmitters(scope, right) {
|
|
211
|
+
if (scope.emitters === null) {
|
|
212
|
+
for (let x = 0; x < right.length; x++)
|
|
213
|
+
emitter_1.Emitter.On(right[x], scope.setCallback);
|
|
214
|
+
scope.emitters = right;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
212
217
|
if (right.length === 0) {
|
|
213
218
|
if (scope.emitters.length > 0) {
|
|
214
219
|
for (let x = 0; x < scope.emitters.length; x++)
|
package/Utils/animation.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Animation = exports.AnimationType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const nodeConfig_1 = require("../Node/nodeConfig");
|
|
5
5
|
var StepFunctions;
|
|
6
6
|
(function (StepFunctions) {
|
|
7
7
|
function EaseIn(start, duration) {
|
|
@@ -47,7 +47,7 @@ class Animation {
|
|
|
47
47
|
this.enabled = true;
|
|
48
48
|
this.type = type;
|
|
49
49
|
this.animationDuration = duration;
|
|
50
|
-
this.animationUpdate =
|
|
50
|
+
this.animationUpdate = nodeConfig_1.NodeConfig.wrapPriorityUpdates(update);
|
|
51
51
|
}
|
|
52
52
|
Animate(start, end) {
|
|
53
53
|
if (!this.enabled)
|
|
@@ -70,13 +70,13 @@ class Animation {
|
|
|
70
70
|
const next = this.start + step;
|
|
71
71
|
this.animationUpdate(next);
|
|
72
72
|
if (percent < 1)
|
|
73
|
-
|
|
73
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(this.animationRun);
|
|
74
74
|
else {
|
|
75
75
|
resolve();
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
this.animationRun = animationRun;
|
|
79
|
-
|
|
79
|
+
nodeConfig_1.NodeConfig.scheduleUpdate(this.animationRun);
|
|
80
80
|
}).then(() => {
|
|
81
81
|
this.Cancel();
|
|
82
82
|
});
|