j-templates 7.0.32 → 7.0.33

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.
@@ -1,5 +1,7 @@
1
1
  export declare function CreateNodeValueAssignment(target: HTMLElement): (value: string) => void;
2
- export declare function CreatePropertyAssignment(target: any): (next: {
2
+ export declare function CreatePropertyAssignment(target: any): ((next: {
3
+ nodeValue: string;
4
+ }) => void) | ((next: {
3
5
  [prop: string]: any;
4
- }) => void;
6
+ }) => void);
5
7
  export declare function AssignProperties(target: any, next: any): void;
@@ -52,6 +52,11 @@ function GetAssignmentFunction(path) {
52
52
  }
53
53
  }
54
54
  function CreatePropertyAssignment(target) {
55
+ if (target.nodeType === Node.TEXT_NODE) {
56
+ return function (next) {
57
+ AssignNodeValue(target, next.nodeValue);
58
+ };
59
+ }
55
60
  const last = [
56
61
  ["", null, null],
57
62
  ];
package/Node/vNode.js CHANGED
@@ -6,10 +6,6 @@ const injector_1 = require("../Utils/injector");
6
6
  const list_1 = require("../Utils/list");
7
7
  const thread_1 = require("../Utils/thread");
8
8
  const nodeConfig_1 = require("./nodeConfig");
9
- const DEFAULT_VNODE_ARRAY = [undefined];
10
- function DEFAULT_VNODE_DATA() {
11
- return DEFAULT_VNODE_ARRAY;
12
- }
13
9
  var vNode;
14
10
  (function (vNode) {
15
11
  function Create(definition) {
@@ -17,7 +13,7 @@ var vNode;
17
13
  definition,
18
14
  type: definition.type,
19
15
  injector: injector_1.Injector.Current() ?? new injector_1.Injector(),
20
- node: null,
16
+ node: definition.node ?? null,
21
17
  children: null,
22
18
  destroyed: false,
23
19
  component: null,
@@ -74,7 +70,7 @@ var vNode;
74
70
  })(vNode || (exports.vNode = vNode = {}));
75
71
  function InitNode(vnode) {
76
72
  const { type, namespace, props, attrs, on, data, componentConstructor, children, childrenArray, } = vnode.definition;
77
- const node = (vnode.node = nodeConfig_1.NodeConfig.createNode(type, namespace));
73
+ const node = (vnode.node = vnode.definition.node ?? nodeConfig_1.NodeConfig.createNode(type, namespace));
78
74
  vnode.definition = null;
79
75
  if (props) {
80
76
  const assignProperties = nodeConfig_1.NodeConfig.createPropertyAssignment(node);
@@ -138,16 +134,12 @@ function InitNode(vnode) {
138
134
  vNode.InitAll(vnode.children);
139
135
  }
140
136
  else if (children) {
141
- Children(vnode, children, data ? ToArray(data) : DEFAULT_VNODE_DATA);
137
+ Children(vnode, children, data);
142
138
  }
143
139
  UpdateChildren(vnode, true, !!childrenArray);
144
140
  }
145
141
  function Children(vnode, children, data) {
146
- const nodeList = list_1.List.Create();
147
- const childrenScope = Store_1.ObservableScope.Create(WrapChildren(vnode.injector, children, data, nodeList));
148
- Store_1.ObservableScope.OnDestroyed(childrenScope, function () {
149
- DestroyNodeList(nodeList);
150
- });
142
+ const childrenScope = CreateChildrenScope(vnode, children, data);
151
143
  vnode.scopes.push(childrenScope);
152
144
  Store_1.ObservableScope.Watch(childrenScope, CreateScheduledCallback(function (scope) {
153
145
  if (vnode.destroyed)
@@ -157,28 +149,21 @@ function Children(vnode, children, data) {
157
149
  }));
158
150
  AssignChildren(vnode, childrenScope);
159
151
  }
160
- function AssignChildren(vnode, childrenScope) {
161
- const children = Store_1.ObservableScope.Value(childrenScope);
162
- switch (typeof children) {
163
- case 'string': {
164
- if (vnode.children?.[0]?.type !== 'text') {
165
- vnode.children && vNode.DestroyAll(vnode.children);
166
- const node = injector_1.Injector.Scope(vnode.injector, vNode.Create, {
167
- type: "text",
168
- namespace: null,
169
- props() {
170
- return { nodeValue: Store_1.ObservableScope.Value(childrenScope) };
171
- },
172
- });
173
- vnode.children = [node];
174
- }
175
- break;
176
- }
177
- default: {
178
- vnode.children = Array.isArray(children) ? children : [children];
179
- break;
180
- }
181
- }
152
+ function CreateChildrenScope(vnode, children, data) {
153
+ if (data === undefined)
154
+ return Store_1.ObservableScope.Create(WrapStaticChildren(vnode, children));
155
+ const nodeList = list_1.List.Create();
156
+ const scope = Store_1.ObservableScope.Create(WrapChildren(vnode.injector, children, ToArray(data), nodeList));
157
+ Store_1.ObservableScope.OnDestroyed(scope, function () {
158
+ DestroyNodeList(nodeList);
159
+ });
160
+ return scope;
161
+ }
162
+ function WrapStaticChildren(vnode, children) {
163
+ return function () {
164
+ vnode.children && vNode.DestroyAll(vnode.children);
165
+ return injector_1.Injector.Scope(vnode.injector, children, undefined);
166
+ };
182
167
  }
183
168
  function WrapChildren(injector, children, data, nodeList) {
184
169
  return function () {
@@ -187,9 +172,6 @@ function WrapChildren(injector, children, data, nodeList) {
187
172
  case 0:
188
173
  DestroyNodeList(nodeList);
189
174
  return [];
190
- case 1:
191
- DestroyNodeList(nodeList);
192
- return injector_1.Injector.Scope(injector, children, nextData[0]);
193
175
  default: {
194
176
  const nodeListMap = list_1.List.ToListMap(nodeList, GetData);
195
177
  const nextNodeList = list_1.List.Create();
@@ -244,6 +226,26 @@ function DestroyNodeList(nodeList) {
244
226
  function GetData(data) {
245
227
  return data.data;
246
228
  }
229
+ function AssignChildren(vnode, childrenScope) {
230
+ const children = Store_1.ObservableScope.Peek(childrenScope);
231
+ switch (typeof children) {
232
+ case 'string': {
233
+ vnode.children = [vNode.Create({
234
+ type: 'text',
235
+ namespace: null,
236
+ node: vnode.children?.[0]?.type === 'text' && vnode.children[0].node || undefined,
237
+ props: {
238
+ nodeValue: children
239
+ }
240
+ })];
241
+ break;
242
+ }
243
+ default: {
244
+ vnode.children = Array.isArray(children) ? children : [children];
245
+ break;
246
+ }
247
+ }
248
+ }
247
249
  function UpdateChildren(vnode, init = false, skipInit = false) {
248
250
  if (!vnode.children)
249
251
  return;
@@ -252,7 +254,7 @@ function UpdateChildren(vnode, init = false, skipInit = false) {
252
254
  if (vnode.destroyed || children !== vnode.children)
253
255
  return;
254
256
  for (let x = 0; !skipInit && x < children.length; x++)
255
- if (children[x].node === null) {
257
+ if (children[x].definition) {
256
258
  const childNode = children[x];
257
259
  (0, thread_1.Schedule)(function () {
258
260
  if (vnode.destroyed || children !== vnode.children)
@@ -25,6 +25,7 @@ export type vNode = {
25
25
  };
26
26
  export type vNodeDefinition<P = HTMLElement, E = HTMLElementEventMap, T = never> = {
27
27
  type: string;
28
+ node?: Node;
28
29
  namespace: string | null;
29
30
  props?: FunctionOr<RecursivePartial<P>>;
30
31
  attrs?: FunctionOr<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "7.0.32",
3
+ "version": "7.0.33",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",