j-templates 6.1.9 → 6.1.11

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.
@@ -13,16 +13,16 @@ function CreateNodeValueAssignment(target) {
13
13
  };
14
14
  }
15
15
  function WalkValue(next, callback, index = 0, parent = "") {
16
- const keys = Object.keys(next);
17
- for (let x = 0; x < keys.length; x++) {
18
- const value = next[keys[x]];
16
+ const entries = Object.entries(next);
17
+ for (let x = 0; x < entries.length; x++) {
18
+ const [key, value] = entries[x];
19
19
  const type = (0, json_1.JsonType)(value);
20
20
  switch (type) {
21
21
  case "object":
22
- index = WalkValue(value, callback, index, `${parent}${keys[x]}.`);
22
+ index = WalkValue(value, callback, index, `${parent}${key}.`);
23
23
  break;
24
24
  default:
25
- callback(`${parent}${keys[x]}`, value, index);
25
+ callback(`${parent}${key}`, value, index);
26
26
  index++;
27
27
  break;
28
28
  }
@@ -51,7 +51,9 @@ function GetAssignmentFunction(path) {
51
51
  }
52
52
  }
53
53
  function CreatePropertyAssignment(target) {
54
- const last = [["", null, null]];
54
+ const last = [
55
+ ["", null, null],
56
+ ];
55
57
  function WalkCallback(path, value, index) {
56
58
  if (index >= last.length || last[index][0] !== path) {
57
59
  last[index] = [path, value, GetAssignmentFunction(path)];
@@ -57,6 +57,9 @@ exports.DOMNodeConfig = {
57
57
  createTextNode(value = '') {
58
58
  return window_1.wndw.document.createTextNode(value);
59
59
  },
60
+ isTextNode(target) {
61
+ return target.nodeType === Node.TEXT_NODE;
62
+ },
60
63
  scheduleUpdate,
61
64
  wrapPriorityUpdates,
62
65
  addListener(target, type, callback) {
package/Node/boundNode.js CHANGED
@@ -66,36 +66,9 @@ var BoundNode;
66
66
  boundNode.assignEvents = null;
67
67
  }
68
68
  }
69
- if (nodeDef.text) {
70
- boundNode.assignText = nodeConfig_1.NodeConfig.createTextAssignment(boundNode.node);
71
- if (typeof nodeDef.text === 'function') {
72
- const scope = observableScope_1.ObservableScope.Create(nodeDef.text);
73
- boundNode.scopes ??= [];
74
- boundNode.scopes.push(scope);
75
- observableScope_1.ObservableScope.Watch(scope, function (scope) { ScheduleSetText(boundNode, scope); });
76
- const next = observableScope_1.ObservableScope.Value(scope);
77
- boundNode.assignText(next);
78
- }
79
- else {
80
- boundNode.assignText(nodeDef.text);
81
- boundNode.assignText = null;
82
- }
83
- }
84
69
  }
85
70
  BoundNode.Init = Init;
86
71
  })(BoundNode || (exports.BoundNode = BoundNode = {}));
87
- function ScheduleSetText(node, scope) {
88
- if (node.setText)
89
- return;
90
- node.setText = true;
91
- nodeConfig_1.NodeConfig.scheduleUpdate(function () {
92
- node.setText = false;
93
- if (node.destroyed)
94
- return;
95
- const next = observableScope_1.ObservableScope.Value(scope);
96
- node.assignText(next);
97
- });
98
- }
99
72
  function ScheduleSetProperties(node, scope) {
100
73
  if (node.setProperties)
101
74
  return;
@@ -1,7 +1,7 @@
1
1
  import { IObservableScope } from "../Store/Tree/observableScope";
2
2
  import { RecursivePartial } from "../Utils/utils.types";
3
3
  import { NodeRefType } from "./nodeRef";
4
- import { INodeRefBase } from "./nodeRef.types";
4
+ import { AllNodeRefTypes, INodeRefBase } from "./nodeRef.types";
5
5
  export type FunctionOr<T> = {
6
6
  (...args: Array<any>): T | Promise<T>;
7
7
  } | T;
@@ -53,4 +53,5 @@ export interface IBoundNodeBase extends INodeRefBase {
53
53
  }
54
54
  export interface IBoundNode extends IBoundNodeBase {
55
55
  type: NodeRefType.BoundNode;
56
+ childNodes: AllNodeRefTypes[];
56
57
  }
@@ -1,6 +1,6 @@
1
1
  import { ComponentNodeEvents, ComponentNodeFunction } from "./componentNode.types";
2
2
  import { ObservableScope } from "../Store/Tree/observableScope";
3
- import { INodeRefBase, NodeRefTypes } from "./nodeRef.types";
3
+ import { INodeRefBase, ElementNodeRefTypes } from "./nodeRef.types";
4
4
  export declare class Component<D = void, T = void, E = void> {
5
5
  private nodeRef;
6
6
  private componentEvents;
@@ -13,7 +13,7 @@ export declare class Component<D = void, T = void, E = void> {
13
13
  protected get NodeRef(): INodeRefBase;
14
14
  protected get Templates(): T;
15
15
  constructor(data: D | (() => (D | Promise<D>)), templates: T, nodeRef: INodeRefBase, componentEvents: ComponentNodeEvents<E>);
16
- Template(): NodeRefTypes | NodeRefTypes[];
16
+ Template(): ElementNodeRefTypes | ElementNodeRefTypes[];
17
17
  Bound(): void;
18
18
  Fire<P extends keyof E>(event: P, data?: E[P]): void;
19
19
  Destroy(): void;
@@ -22,7 +22,7 @@ export declare namespace Component {
22
22
  function ToFunction<D = void, T = void, E = void>(type: string, constructor: ComponentConstructor<D, T, E>): ComponentNodeFunction<D, T, E>;
23
23
  function ToFunction<D = void, T = void, E = void>(type: string, namespace: string, constructor: ComponentConstructor<D, T, E>): ComponentNodeFunction<D, T, E>;
24
24
  function Register<D = void, T = void, E = void>(name: string, constructor: ComponentConstructor<D, T, E>): void;
25
- function Attach(node: Node, nodeRef: NodeRefTypes): void;
25
+ function Attach(node: Node, nodeRef: ElementNodeRefTypes): void;
26
26
  }
27
27
  export type ComponentConstructor<D, T, E> = {
28
28
  new (data: {
@@ -100,6 +100,7 @@ function AddTemplate(node, init) {
100
100
  list_1.List.Add(list, {
101
101
  value: undefined,
102
102
  init: true,
103
+ scope: null,
103
104
  nodes
104
105
  });
105
106
  if (init) {
@@ -1,6 +1,7 @@
1
1
  import { BoundNodeFunctionParam, IBoundNodeBase, NodeDefinition } from "./boundNode.types";
2
2
  import { Component, ComponentConstructor } from "./component";
3
3
  import { NodeRefType } from "./nodeRef";
4
+ import { AllNodeRefTypes } from "./nodeRef.types";
4
5
  export type ComponentNodeEvents<E = void> = {
5
6
  [P in keyof E]?: {
6
7
  (data: E[P]): void;
@@ -32,4 +33,5 @@ export interface IComponentNodeBase<D, T, E> extends IBoundNodeBase {
32
33
  }
33
34
  export interface IComponentNode<D, T, E> extends IComponentNodeBase<D, T, E> {
34
35
  type: NodeRefType.ComponentNode;
36
+ childNodes: AllNodeRefTypes[];
35
37
  }
@@ -21,28 +21,82 @@ var ElementNode;
21
21
  return elemNode;
22
22
  }
23
23
  ElementNode.Create = Create;
24
+ function CreateValueScopeCallback(dataScope) {
25
+ return function () {
26
+ const value = observableScope_1.ObservableScope.Value(dataScope);
27
+ if (!value)
28
+ return valueDefault;
29
+ if (!Array.isArray(value))
30
+ return [value];
31
+ return value;
32
+ };
33
+ }
34
+ function CreateNodeScopeCallback(elementNode, valueScope) {
35
+ let lastNodeList;
36
+ return function () {
37
+ const values = observableScope_1.ObservableScope.Value(valueScope);
38
+ const lastNodeMap = lastNodeList && list_1.List.ToNodeMap(lastNodeList, GetDataValue);
39
+ const nextNodeList = list_1.List.Create();
40
+ for (let x = 0; x < values.length; x++) {
41
+ let curNode = null;
42
+ if (lastNodeMap !== undefined) {
43
+ const nodeArr = lastNodeMap.get(values[x]);
44
+ if (nodeArr !== undefined) {
45
+ let y = nodeArr.length - 1;
46
+ for (; y >= 0 && nodeArr[y] === null; y--) { }
47
+ curNode = nodeArr[y];
48
+ nodeArr[y] = null;
49
+ }
50
+ }
51
+ const value = values[x];
52
+ if (curNode !== null) {
53
+ list_1.List.RemoveNode(lastNodeList, curNode);
54
+ list_1.List.AddNode(nextNodeList, curNode);
55
+ const nextNodes = observableScope_1.ObservableScope.Value(curNode.data.scope);
56
+ if (curNode.data.nodes !== nextNodes) {
57
+ list_1.List.Add(elementNode.destroyNodeList, {
58
+ ...curNode.data,
59
+ scope: null
60
+ });
61
+ curNode.data.init = false;
62
+ curNode.data.nodes = nextNodes;
63
+ }
64
+ }
65
+ else {
66
+ const scope = observableScope_1.ObservableScope.Create(function () {
67
+ return injector_1.Injector.Scope(elementNode.injector, CreateNodeArray, elementNode.children, value);
68
+ });
69
+ curNode = list_1.List.Add(nextNodeList, {
70
+ value,
71
+ init: false,
72
+ scope,
73
+ nodes: observableScope_1.ObservableScope.Value(scope),
74
+ });
75
+ }
76
+ }
77
+ lastNodeList && list_1.List.Append(elementNode.destroyNodeList, lastNodeList);
78
+ lastNodeList = nextNodeList;
79
+ return nextNodeList;
80
+ };
81
+ }
24
82
  function Init(elementNode) {
25
- const nodeDef = elementNode.nodeDef;
26
- if (elementNode.childrenArray !== null || (elementNode.children !== null && !nodeDef.data)) {
27
- SetDefaultData(elementNode);
28
- }
29
- else if (elementNode.children !== null) {
30
- const dataScope = observableScope_1.ObservableScope.Create(nodeDef.data);
31
- const valueScope = observableScope_1.ObservableScope.Create(function () {
32
- const value = observableScope_1.ObservableScope.Value(dataScope);
33
- if (!value)
34
- return valueDefault;
35
- if (!Array.isArray(value))
36
- return [value];
37
- return value;
83
+ elementNode.childNodes = new Set();
84
+ if (elementNode.children !== null) {
85
+ const dataScope = elementNode.nodeDef.data ? observableScope_1.ObservableScope.Create(elementNode.nodeDef.data) : observableScope_1.ObservableScope.Create(function () {
86
+ return [true];
38
87
  });
88
+ const valueScope = observableScope_1.ObservableScope.Create(CreateValueScopeCallback(dataScope));
89
+ const nodeScope = observableScope_1.ObservableScope.Create(CreateNodeScopeCallback(elementNode, valueScope));
39
90
  elementNode.childNodes = new Set();
40
91
  elementNode.scopes ??= [];
41
- elementNode.scopes.push(dataScope, valueScope);
42
- observableScope_1.ObservableScope.Watch(valueScope, function () {
43
- ScheduleSetData(elementNode, valueScope);
92
+ elementNode.scopes.push(dataScope, valueScope, nodeScope);
93
+ observableScope_1.ObservableScope.Watch(nodeScope, function (scope) {
94
+ ScheduleSetData(elementNode, scope);
44
95
  });
45
- SetData(elementNode, observableScope_1.ObservableScope.Value(valueScope), true);
96
+ UpdateNodes(elementNode, observableScope_1.ObservableScope.Value(nodeScope), true);
97
+ }
98
+ else if (elementNode.childrenArray !== null) {
99
+ SetDefaultData(elementNode);
46
100
  }
47
101
  boundNode_1.BoundNode.Init(elementNode);
48
102
  }
@@ -56,104 +110,56 @@ function ScheduleSetData(node, scope) {
56
110
  node.setData = false;
57
111
  if (node.destroyed)
58
112
  return;
59
- SetData(node, observableScope_1.ObservableScope.Value(scope));
113
+ UpdateNodes(node, observableScope_1.ObservableScope.Value(scope));
60
114
  });
61
115
  }
62
116
  function SetDefaultData(node) {
63
- (0, thread_1.Synch)(function () {
64
- const nodes = node.childrenArray || injector_1.Injector.Scope(node.injector, CreateNodeArray, node.children, true);
65
- node.childrenArray = null;
66
- if (nodes.length > 0) {
67
- (0, thread_1.Schedule)(function () {
68
- if (node.destroyed)
69
- return;
70
- nodeRef_1.NodeRef.InitAll(node, nodes);
71
- });
72
- (0, thread_1.Thread)(function () {
73
- if (node.destroyed)
74
- return;
75
- const defaultNodeList = list_1.List.Create();
76
- list_1.List.Add(defaultNodeList, {
77
- value: null,
78
- init: true,
79
- nodes
80
- });
81
- nodeRef_1.NodeRef.ReconcileChildren(node, defaultNodeList);
82
- list_1.List.Clear(defaultNodeList);
83
- });
84
- }
117
+ const nodes = node.childrenArray ||
118
+ injector_1.Injector.Scope(node.injector, CreateNodeArray, node.children, true);
119
+ node.childrenArray = null;
120
+ const defaultNodeList = list_1.List.Create();
121
+ list_1.List.Add(defaultNodeList, {
122
+ value: null,
123
+ init: false,
124
+ scope: null,
125
+ nodes
85
126
  });
127
+ UpdateNodes(node, defaultNodeList, true);
86
128
  }
87
129
  function GetDataValue(data) {
88
130
  return data.value;
89
131
  }
90
- function ReconcileNodeData(node, values) {
91
- const nextNodeList = list_1.List.Create();
92
- const currentNodeList = node.nodeList;
93
- const nodeMap = currentNodeList && list_1.List.ToNodeMap(currentNodeList, GetDataValue);
94
- for (let x = 0; x < values.length; x++) {
95
- let curNode = null;
96
- if (nodeMap) {
97
- const nodeArr = nodeMap.get(values[x]);
98
- if (nodeArr) {
99
- let y = nodeArr.length - 1;
100
- for (; y >= 0 && !curNode; y--) {
101
- curNode = nodeArr[y];
102
- nodeArr[y] = null;
103
- }
104
- }
105
- }
106
- if (curNode) {
107
- list_1.List.RemoveNode(currentNodeList, curNode);
108
- list_1.List.AddNode(nextNodeList, curNode);
109
- }
110
- else {
111
- curNode = list_1.List.Add(nextNodeList, {
112
- value: values[x],
113
- init: false,
114
- nodes: injector_1.Injector.Scope(node.injector, CreateNodeArray, node.children, values[x])
115
- });
116
- }
117
- }
118
- let curNode = nextNodeList.head;
119
- while (curNode) {
120
- const data = curNode.data;
121
- !data.init && (0, thread_1.Schedule)(function () {
122
- if (node.destroyed || nextNodeList.size === 0)
123
- return;
124
- nodeRef_1.NodeRef.InitAll(node, data.nodes);
125
- data.init = true;
126
- });
127
- curNode = curNode.next;
128
- }
129
- if (currentNodeList) {
130
- let curDetach = currentNodeList.head;
131
- while (curDetach) {
132
- const data = curDetach.data;
133
- curDetach = curDetach.next;
132
+ function UpdateNodes(elementNode, nodeList, init = false) {
133
+ (0, thread_1.Synch)(function () {
134
+ let data;
135
+ while (data = list_1.List.Pop(elementNode.destroyNodeList)) {
136
+ observableScope_1.ObservableScope.Destroy(data.scope);
134
137
  for (let x = 0; x < data.nodes.length; x++)
135
- node.childNodes.delete(data.nodes[x]);
138
+ elementNode.childNodes.delete(data.nodes[x]);
136
139
  nodeRef_1.NodeRef.DestroyAll(data.nodes);
137
140
  }
138
- list_1.List.Clear(currentNodeList);
139
- }
140
- node.nodeList = nextNodeList;
141
- }
142
- function SetData(node, values, init = false) {
143
- (0, thread_1.Synch)(function () {
144
- ReconcileNodeData(node, values);
145
- const attachNodes = node.nodeList;
146
- const startSize = attachNodes.size;
141
+ for (let node = nodeList.head; node !== null; node = node.next) {
142
+ if (!node.data.init) {
143
+ const nodeData = node.data;
144
+ (0, thread_1.Schedule)(function () {
145
+ if (elementNode.destroyed || nodeData.init)
146
+ return;
147
+ nodeRef_1.NodeRef.InitAll(elementNode, nodeData.nodes);
148
+ nodeData.init = true;
149
+ });
150
+ }
151
+ }
152
+ const startSize = nodeList.size;
147
153
  (0, thread_1.Thread)(function (async) {
148
- if (node.destroyed)
154
+ if (elementNode.destroyed)
149
155
  return;
150
156
  if (init || !async)
151
- nodeRef_1.NodeRef.ReconcileChildren(node, attachNodes);
157
+ nodeRef_1.NodeRef.ReconcileChildren(elementNode, nodeList);
152
158
  else
153
159
  nodeConfig_1.NodeConfig.scheduleUpdate(function () {
154
- if (node.destroyed || attachNodes.size !== startSize)
160
+ if (elementNode.destroyed || nodeList.size !== startSize)
155
161
  return;
156
- nodeRef_1.NodeRef.ReconcileChildren(node, attachNodes);
162
+ nodeRef_1.NodeRef.ReconcileChildren(elementNode, nodeList);
157
163
  });
158
164
  });
159
165
  });
@@ -161,12 +167,7 @@ function SetData(node, values, init = false) {
161
167
  function CreateNodeArray(childrenFunc, value) {
162
168
  const newNodes = childrenFunc(value);
163
169
  if (typeof newNodes === "string" || !newNodes) {
164
- const textNode = nodeRef_1.NodeRef.Create("text", null, nodeRef_1.NodeRefType.BoundNode);
165
- textNode.nodeDef = {
166
- text: function () {
167
- return childrenFunc(value);
168
- }
169
- };
170
+ const textNode = nodeRef_1.NodeRef.Create(newNodes, null, nodeRef_1.NodeRefType.TextNode);
170
171
  return [textNode];
171
172
  }
172
173
  if (Array.isArray(newNodes))
@@ -1,11 +1,12 @@
1
+ import { IObservableScope } from "../Store/Tree/observableScope";
1
2
  import { IList } from "../Utils/list";
2
3
  import { NodeDefinition, BoundNodeFunctionParam, IBoundNodeBase } from "./boundNode.types";
3
4
  import { NodeRefType } from "./nodeRef";
4
- import { INodeRefBase, NodeRefTypes } from "./nodeRef.types";
5
+ import { INodeRefBase, ElementNodeRefTypes, AllNodeRefTypes } from "./nodeRef.types";
5
6
  export type ElementChildrenFunction<T> = {
6
- (data: T): string | NodeRefTypes | NodeRefTypes[];
7
+ (data: T): string | ElementNodeRefTypes | ElementNodeRefTypes[];
7
8
  };
8
- export type ElementChildrenFunctionParam<T> = ElementChildrenFunction<T> | NodeRefTypes[];
9
+ export type ElementChildrenFunctionParam<T> = ElementChildrenFunction<T> | ElementNodeRefTypes[];
9
10
  export type ElementNodeFunction<T> = {
10
11
  (nodeDef: ElementNodeFunctionParam<T>, children?: ElementChildrenFunctionParam<T>): INodeRefBase;
11
12
  };
@@ -23,15 +24,17 @@ export interface ElementNodeFunctionParam<T, P = HTMLElement, E = HTMLElementEve
23
24
  export interface IElementDataNode<T> {
24
25
  value: T;
25
26
  init: boolean;
26
- nodes: NodeRefTypes[] | null;
27
+ scope: IObservableScope<AllNodeRefTypes[] | null>;
28
+ nodes: AllNodeRefTypes[] | null;
27
29
  }
28
30
  export interface IElementNodeBase<T> extends IBoundNodeBase {
29
31
  nodeDef: ElementNodeFunctionParam<T>;
30
32
  children: ElementChildrenFunction<T>;
31
- childrenArray: NodeRefTypes[];
32
- nodeList: IList<IElementDataNode<T>> | null;
33
+ childrenArray: ElementNodeRefTypes[];
34
+ destroyNodeList: IList<IElementDataNode<T>>;
33
35
  setData: boolean;
34
36
  }
35
37
  export interface IElementNode<T> extends IElementNodeBase<T> {
36
38
  type: NodeRefType.ElementNode;
39
+ childNodes: Set<AllNodeRefTypes>;
37
40
  }
@@ -4,6 +4,7 @@ export interface INodeConfig {
4
4
  scheduleUpdate(callback: () => void): void;
5
5
  wrapPriorityUpdates<P extends any[]>(callback: (...args: P) => void): (...args: P) => void;
6
6
  setText(target: any, text: string): void;
7
+ isTextNode(target: any): boolean;
7
8
  getAttribute(target: any, attribute: string): string;
8
9
  setAttribute(target: any, attribute: string, value: string): void;
9
10
  addListener(target: any, type: string, callback: {
package/Node/nodeRef.d.ts CHANGED
@@ -1,23 +1,26 @@
1
- import { INodeRef, INodeRefBase, NodeRefTypes } from "./nodeRef.types";
1
+ import { INodeRef, ElementNodeRefTypes, AllNodeRefTypes } from "./nodeRef.types";
2
2
  import { IBoundNode } from "./boundNode.types";
3
3
  import { IElementDataNode, IElementNode } from "./elementNode.types";
4
4
  import { IComponentNode } from "./componentNode.types";
5
5
  import { IList } from "../Utils/list";
6
+ import { ITextNode } from "./textNode.types";
6
7
  export declare enum NodeRefType {
7
8
  NodeRef = 0,
8
9
  BoundNode = 1,
9
10
  ElementNode = 2,
10
- ComponentNode = 3
11
+ ComponentNode = 3,
12
+ TextNode = 4
11
13
  }
12
14
  export declare namespace NodeRef {
13
15
  function Wrap(node: any): INodeRef;
14
- function Create(nodeType: any, namespace: string, type: NodeRefType): INodeRef | IBoundNode | IElementNode<any> | IComponentNode<any, any, any>;
15
- function Init(nodeRef: NodeRefTypes): void;
16
- function InitAll(parentNode: NodeRefTypes, nodeRefs: Array<NodeRefTypes>): void;
17
- function AddChild(node: INodeRefBase, child: INodeRefBase): void;
18
- function AddChildAfter(node: INodeRefBase, currentChild: INodeRefBase, newChild: INodeRefBase): void;
19
- function ReconcileChildren(node: INodeRefBase, nextChildren: IList<IElementDataNode<unknown>>): void;
20
- function DetachChild(node: INodeRefBase, child: INodeRefBase): void;
21
- function Destroy(node: NodeRefTypes): void;
22
- function DestroyAll(nodes: Array<INodeRefBase>): void;
16
+ function Create(nodeType: any, namespace: string, type: NodeRefType): INodeRef | IBoundNode | IElementNode<any> | IComponentNode<any, any, any> | ITextNode;
17
+ function Init(nodeRef: AllNodeRefTypes): void;
18
+ function InitAll(parentNode: ElementNodeRefTypes, nodeRefs: Array<AllNodeRefTypes>): void;
19
+ function AddChild(node: ElementNodeRefTypes, child: AllNodeRefTypes): void;
20
+ function AddChildAfter(node: ElementNodeRefTypes, currentChild: AllNodeRefTypes, newChild: AllNodeRefTypes): void;
21
+ function AddChildBefore(node: ElementNodeRefTypes, currentChild: AllNodeRefTypes, newChild: AllNodeRefTypes): void;
22
+ function ReconcileChildren(node: ElementNodeRefTypes, nextChildren: IList<IElementDataNode<unknown>>): void;
23
+ function DetachChild(node: ElementNodeRefTypes, child: AllNodeRefTypes): void;
24
+ function Destroy(node: AllNodeRefTypes): void;
25
+ function DestroyAll(nodes: Array<AllNodeRefTypes>): void;
23
26
  }
package/Node/nodeRef.js CHANGED
@@ -6,6 +6,7 @@ const injector_1 = require("../Utils/injector");
6
6
  const boundNode_1 = require("./boundNode");
7
7
  const elementNode_1 = require("./elementNode");
8
8
  const componentNode_1 = require("./componentNode");
9
+ const list_1 = require("../Utils/list");
9
10
  const Store_1 = require("../Store");
10
11
  var NodeRefType;
11
12
  (function (NodeRefType) {
@@ -13,18 +14,26 @@ var NodeRefType;
13
14
  NodeRefType[NodeRefType["BoundNode"] = 1] = "BoundNode";
14
15
  NodeRefType[NodeRefType["ElementNode"] = 2] = "ElementNode";
15
16
  NodeRefType[NodeRefType["ComponentNode"] = 3] = "ComponentNode";
17
+ NodeRefType[NodeRefType["TextNode"] = 4] = "TextNode";
16
18
  })(NodeRefType || (exports.NodeRefType = NodeRefType = {}));
17
19
  var NodeRef;
18
20
  (function (NodeRef) {
19
21
  function Wrap(node) {
20
- var nodeRef = Create(null, null, NodeRefType.NodeRef);
22
+ const nodeRef = Create(null, null, NodeRefType.BoundNode);
21
23
  nodeRef.node = node;
22
- nodeRef.childNodes = new Set();
24
+ nodeRef.childNodes = [];
23
25
  return nodeRef;
24
26
  }
25
27
  NodeRef.Wrap = Wrap;
26
28
  function Create(nodeType, namespace, type) {
27
29
  switch (type) {
30
+ case NodeRefType.TextNode:
31
+ return {
32
+ type: NodeRefType.TextNode,
33
+ parent: null,
34
+ node: null,
35
+ value: nodeType
36
+ };
28
37
  case NodeRefType.NodeRef:
29
38
  return {
30
39
  node: null,
@@ -80,7 +89,8 @@ var NodeRef;
80
89
  nodeList: null,
81
90
  setData: false,
82
91
  setText: false,
83
- scopes: null
92
+ scopes: null,
93
+ destroyNodeList: list_1.List.Create()
84
94
  };
85
95
  case NodeRefType.ComponentNode:
86
96
  return {
@@ -106,7 +116,7 @@ var NodeRef;
106
116
  }
107
117
  NodeRef.Create = Create;
108
118
  function Init(nodeRef) {
109
- if (nodeRef.node)
119
+ if (nodeRef.node || nodeRef.type === NodeRefType.TextNode)
110
120
  return;
111
121
  nodeRef.node = nodeRef.nodeType === 'text' ? nodeConfig_1.NodeConfig.createTextNode() : nodeConfig_1.NodeConfig.createNode(nodeRef.nodeType, nodeRef.nodeNamespace);
112
122
  nodeRef.childNodes = nodeRef.nodeType !== 'text' ? [] : null;
@@ -124,10 +134,17 @@ var NodeRef;
124
134
  }
125
135
  NodeRef.Init = Init;
126
136
  function AddChildToNode(parentNode, child) {
127
- if (Array.isArray(parentNode.childNodes))
128
- parentNode.childNodes.push(child);
129
- else
130
- parentNode.childNodes.add(child);
137
+ switch (parentNode.type) {
138
+ case NodeRefType.ElementNode:
139
+ parentNode.childNodes.add(child);
140
+ break;
141
+ case NodeRefType.ComponentNode:
142
+ case NodeRefType.BoundNode:
143
+ parentNode.childNodes.push(child);
144
+ break;
145
+ default:
146
+ throw "Unable to add child node to node";
147
+ }
131
148
  }
132
149
  function InitAll(parentNode, nodeRefs) {
133
150
  for (var x = 0; x < nodeRefs.length; x++) {
@@ -151,6 +168,14 @@ var NodeRef;
151
168
  nodeConfig_1.NodeConfig.addChildAfter(node.node, currentChild && currentChild.node, newChild.node);
152
169
  }
153
170
  NodeRef.AddChildAfter = AddChildAfter;
171
+ function AddChildBefore(node, currentChild, newChild) {
172
+ if (currentChild && currentChild.parent !== node)
173
+ throw "currentChild is not valid";
174
+ newChild.parent = node;
175
+ AddChildToNode(node, newChild);
176
+ nodeConfig_1.NodeConfig.addChildBefore(node.node, currentChild && currentChild.node, newChild.node);
177
+ }
178
+ NodeRef.AddChildBefore = AddChildBefore;
154
179
  function ReconcileChildren(node, nextChildren) {
155
180
  const rootNode = node.node;
156
181
  if (nextChildren.size === 0) {
@@ -162,9 +187,17 @@ var NodeRef;
162
187
  let remove = false;
163
188
  for (let curDataNode = nextChildren.head; curDataNode !== null; curDataNode = curDataNode.next) {
164
189
  for (let x = 0; x < curDataNode.data.nodes.length; x++) {
165
- const actualNode = priorNode ? nodeConfig_1.NodeConfig.getNextSibling(priorNode) : nodeConfig_1.NodeConfig.getFirstChild(rootNode);
166
190
  const virtualNode = curDataNode.data.nodes[x];
167
- const expectedNode = virtualNode.node;
191
+ const actualNode = priorNode ? nodeConfig_1.NodeConfig.getNextSibling(priorNode) : nodeConfig_1.NodeConfig.getFirstChild(rootNode);
192
+ let expectedNode;
193
+ if (virtualNode.type === NodeRefType.TextNode && actualNode !== null && nodeConfig_1.NodeConfig.isTextNode(actualNode)) {
194
+ nodeConfig_1.NodeConfig.setText(actualNode, virtualNode.value);
195
+ virtualNode.node = expectedNode = actualNode;
196
+ }
197
+ else if (virtualNode.type === NodeRefType.TextNode)
198
+ expectedNode = nodeConfig_1.NodeConfig.createTextNode(virtualNode.value);
199
+ else
200
+ expectedNode = virtualNode.node;
168
201
  if (actualNode !== expectedNode) {
169
202
  nodeConfig_1.NodeConfig.addChildBefore(rootNode, actualNode, expectedNode);
170
203
  !remove && insert && actualNode && nodeConfig_1.NodeConfig.removeChild(rootNode, actualNode);
@@ -186,14 +219,12 @@ var NodeRef;
186
219
  }
187
220
  NodeRef.ReconcileChildren = ReconcileChildren;
188
221
  function DetachChild(node, child) {
189
- if (!Array.isArray(node.childNodes) && node.childNodes.delete(child)) {
190
- nodeConfig_1.NodeConfig.removeChild(node.node, child.node);
222
+ if (node.type === NodeRefType.ElementNode && node.childNodes.delete(child))
191
223
  child.parent = null;
192
- }
193
224
  }
194
225
  NodeRef.DetachChild = DetachChild;
195
226
  function Destroy(node) {
196
- if (node.destroyed)
227
+ if (node.type === NodeRefType.TextNode || node.destroyed)
197
228
  return;
198
229
  node.destroyed = true;
199
230
  if (Array.isArray(node.childNodes))
@@ -3,6 +3,7 @@ import { IBoundNode } from "./boundNode.types";
3
3
  import { IComponentNode } from "./componentNode.types";
4
4
  import { IElementNode } from "./elementNode.types";
5
5
  import { NodeRefType } from "./nodeRef";
6
+ import { ITextNode } from "./textNode.types";
6
7
  export interface INodeRefBase {
7
8
  type: NodeRefType;
8
9
  node: any;
@@ -10,10 +11,11 @@ export interface INodeRefBase {
10
11
  nodeNamespace: string;
11
12
  injector: Injector;
12
13
  parent: INodeRefBase;
13
- childNodes: INodeRefBase[] | Set<INodeRefBase>;
14
+ childNodes: AllNodeRefTypes[] | Set<AllNodeRefTypes>;
14
15
  destroyed: boolean;
15
16
  }
16
17
  export interface INodeRef extends INodeRefBase {
17
18
  type: NodeRefType.NodeRef;
18
19
  }
19
- export type NodeRefTypes = INodeRef | IBoundNode | IElementNode<any> | IComponentNode<any, any, any>;
20
+ export type ElementNodeRefTypes = INodeRef | IBoundNode | IElementNode<any> | IComponentNode<any, any, any>;
21
+ export type AllNodeRefTypes = ElementNodeRefTypes | ITextNode;
@@ -0,0 +1,7 @@
1
+ import { NodeRefType } from "./nodeRef";
2
+ export interface ITextNode {
3
+ type: NodeRefType.TextNode;
4
+ parent: any;
5
+ node: any;
6
+ value: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
1
  import { Component } from "../Node/component";
2
2
  import { IDestroyable } from "./utils.types";
3
- import { NodeRefTypes } from "../Node/nodeRef.types";
3
+ import { ElementNodeRefTypes } from "../Node/nodeRef.types";
4
4
  export declare function Computed<T extends Component<any, any, any>, K extends keyof T, V extends T[K]>(defaultValue: V): (target: T, propertyKey: K, descriptor: PropertyDescriptor) => PropertyDescriptor;
5
5
  export declare function ComputedAsync<T extends Component<any, any, any>, K extends keyof T, V extends T[K]>(defaultValue: V): (target: T, propertyKey: K, descriptor: PropertyDescriptor) => PropertyDescriptor;
6
6
  export declare function State(): any;
@@ -16,12 +16,12 @@ export declare namespace Destroy {
16
16
  }
17
17
  declare function DestroyDecorator<T extends Component<any, any, any> & Record<K, IDestroyable>, K extends string>(target: T, propertyKey: K): any;
18
18
  export declare function PreReqTemplate(template: {
19
- (): NodeRefTypes | NodeRefTypes[];
19
+ (): ElementNodeRefTypes | ElementNodeRefTypes[];
20
20
  }): <T extends Component<any, any, any>>(target: {
21
21
  new (...args: Array<any>): T;
22
22
  }) => any;
23
23
  export declare namespace PreReqTemplate {
24
- function Get(value: any): NodeRefTypes[];
24
+ function Get(value: any): ElementNodeRefTypes[];
25
25
  }
26
26
  export declare function PreReq(): typeof PreReqDecorator;
27
27
  export declare namespace PreReq {
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { NodeRefTypes } from "./Node/nodeRef.types";
1
+ export { AllNodeRefTypes as NodeRefTypes } from "./Node/nodeRef.types";
2
2
  export { Component } from "./Node/component";
3
3
  export { CalcScope as calc } from './Store/Tree/observableScope';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "j-templates",
3
- "version": "6.1.9",
3
+ "version": "6.1.11",
4
4
  "description": "j-templates",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/TypesInCode/jTemplates",