@iyio/protogen 0.7.50 → 0.8.0
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/package.json +9 -13
- package/src/index.d.ts +17 -17
- package/src/index.js +17 -20
- package/src/index.js.map +1 -1
- package/src/lib/ProtoExpressionEngine.d.ts +1 -1
- package/src/lib/ProtoExpressionEngine.js +26 -31
- package/src/lib/ProtoExpressionEngine.js.map +1 -1
- package/src/lib/executeProtoPipelineAsync.d.ts +1 -1
- package/src/lib/executeProtoPipelineAsync.js +3 -7
- package/src/lib/executeProtoPipelineAsync.js.map +1 -1
- package/src/lib/markdown.d.ts +2 -2
- package/src/lib/markdown.js +30 -34
- package/src/lib/markdown.js.map +1 -1
- package/src/lib/output-utils.d.ts +1 -1
- package/src/lib/output-utils.js +35 -38
- package/src/lib/output-utils.js.map +1 -1
- package/src/lib/protogen-cli.d.ts +1 -1
- package/src/lib/protogen-cli.js +7 -11
- package/src/lib/protogen-cli.js.map +1 -1
- package/src/lib/protogen-expression-ctrls.d.ts +1 -1
- package/src/lib/protogen-expression-ctrls.js +22 -26
- package/src/lib/protogen-expression-ctrls.js.map +1 -1
- package/src/lib/protogen-expression-lib.d.ts +1 -1
- package/src/lib/protogen-expression-lib.js +19 -32
- package/src/lib/protogen-expression-lib.js.map +1 -1
- package/src/lib/protogen-expression-types.d.ts +1 -1
- package/src/lib/protogen-expression-types.js +4 -8
- package/src/lib/protogen-expression-types.js.map +1 -1
- package/src/lib/protogen-lib.d.ts +1 -1
- package/src/lib/protogen-lib.js +15 -28
- package/src/lib/protogen-lib.js.map +1 -1
- package/src/lib/protogen-node.d.ts +1 -1
- package/src/lib/protogen-node.js +98 -119
- package/src/lib/protogen-node.js.map +1 -1
- package/src/lib/protogen-pipeline-types.d.ts +2 -2
- package/src/lib/protogen-pipeline-types.js +5 -8
- package/src/lib/protogen-pipeline-types.js.map +1 -1
- package/src/lib/protogen-pipeline.d.ts +1 -1
- package/src/lib/protogen-pipeline.js +5 -10
- package/src/lib/protogen-pipeline.js.map +1 -1
- package/src/lib/protogen-plugin-util.d.ts +2 -2
- package/src/lib/protogen-plugin-util.js +17 -24
- package/src/lib/protogen-plugin-util.js.map +1 -1
- package/src/lib/protogen-types.d.ts +1 -1
- package/src/lib/protogen-types.js +2 -7
- package/src/lib/protogen-types.js.map +1 -1
- package/src/lib/protogen-workflow-lib.d.ts +2 -2
- package/src/lib/protogen-workflow-lib.js +20 -26
- package/src/lib/protogen-workflow-lib.js.map +1 -1
- package/src/lib/protogen-workflow-types.d.ts +2 -2
- package/src/lib/protogen-workflow-types.js +1 -2
- package/src/lib/test-plugin.js +3 -5
- package/src/lib/test-plugin.js.map +1 -1
- package/src/lib/typescript-utils.d.ts +2 -2
- package/src/lib/typescript-utils.js +18 -30
- package/src/lib/typescript-utils.js.map +1 -1
- package/src/package.json +1 -4
- package/tsconfig.tsbuildinfo +1 -0
- package/esm/package.json +0 -3
- package/esm/src/index.d.ts +0 -17
- package/esm/src/index.js +0 -18
- package/esm/src/index.js.map +0 -1
- package/esm/src/lib/ProtoExpressionEngine.d.ts +0 -16
- package/esm/src/lib/ProtoExpressionEngine.js +0 -356
- package/esm/src/lib/ProtoExpressionEngine.js.map +0 -1
- package/esm/src/lib/executeProtoPipelineAsync.d.ts +0 -2
- package/esm/src/lib/executeProtoPipelineAsync.js +0 -75
- package/esm/src/lib/executeProtoPipelineAsync.js.map +0 -1
- package/esm/src/lib/markdown.d.ts +0 -6
- package/esm/src/lib/markdown.js +0 -291
- package/esm/src/lib/markdown.js.map +0 -1
- package/esm/src/lib/output-utils.d.ts +0 -33
- package/esm/src/lib/output-utils.js +0 -235
- package/esm/src/lib/output-utils.js.map +0 -1
- package/esm/src/lib/protogen-cli.d.ts +0 -17
- package/esm/src/lib/protogen-cli.js +0 -25
- package/esm/src/lib/protogen-cli.js.map +0 -1
- package/esm/src/lib/protogen-expression-ctrls.d.ts +0 -2
- package/esm/src/lib/protogen-expression-ctrls.js +0 -282
- package/esm/src/lib/protogen-expression-ctrls.js.map +0 -1
- package/esm/src/lib/protogen-expression-lib.d.ts +0 -16
- package/esm/src/lib/protogen-expression-lib.js +0 -103
- package/esm/src/lib/protogen-expression-lib.js.map +0 -1
- package/esm/src/lib/protogen-expression-types.d.ts +0 -160
- package/esm/src/lib/protogen-expression-types.js +0 -46
- package/esm/src/lib/protogen-expression-types.js.map +0 -1
- package/esm/src/lib/protogen-lib.d.ts +0 -23
- package/esm/src/lib/protogen-lib.js +0 -96
- package/esm/src/lib/protogen-lib.js.map +0 -1
- package/esm/src/lib/protogen-node.d.ts +0 -76
- package/esm/src/lib/protogen-node.js +0 -719
- package/esm/src/lib/protogen-node.js.map +0 -1
- package/esm/src/lib/protogen-pipeline-types.d.ts +0 -145
- package/esm/src/lib/protogen-pipeline-types.js +0 -27
- package/esm/src/lib/protogen-pipeline-types.js.map +0 -1
- package/esm/src/lib/protogen-pipeline.d.ts +0 -5
- package/esm/src/lib/protogen-pipeline.js +0 -88
- package/esm/src/lib/protogen-pipeline.js.map +0 -1
- package/esm/src/lib/protogen-plugin-util.d.ts +0 -29
- package/esm/src/lib/protogen-plugin-util.js +0 -119
- package/esm/src/lib/protogen-plugin-util.js.map +0 -1
- package/esm/src/lib/protogen-types.d.ts +0 -198
- package/esm/src/lib/protogen-types.js +0 -9
- package/esm/src/lib/protogen-types.js.map +0 -1
- package/esm/src/lib/protogen-workflow-lib.d.ts +0 -7
- package/esm/src/lib/protogen-workflow-lib.js +0 -53
- package/esm/src/lib/protogen-workflow-lib.js.map +0 -1
- package/esm/src/lib/protogen-workflow-types.d.ts +0 -95
- package/esm/src/lib/protogen-workflow-types.js +0 -2
- package/esm/src/lib/protogen-workflow-types.js.map +0 -1
- package/esm/src/lib/test-plugin.d.ts +0 -1
- package/esm/src/lib/test-plugin.js +0 -18
- package/esm/src/lib/test-plugin.js.map +0 -1
- package/esm/src/lib/typescript-utils.d.ts +0 -15
- package/esm/src/lib/typescript-utils.js +0 -161
- package/esm/src/lib/typescript-utils.js.map +0 -1
package/src/lib/protogen-node.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.protoRemoveDisplayChildren = exports.protoSetNodeCtrl = exports.protoGetNodeCtrl = exports.protoClearRevLinks = exports.protoUpdateLayouts = exports.protoParsingResultFromNode = exports.protoSetPosScale = exports.protoGetPosScale = exports.protoRenderLines = exports.protoAddFlattenedHierarchy = exports.protoFlattenHierarchy = exports.protoChildrenToArray = exports.protoAddLink = exports.protoGetNodeAtPath = exports.protoGetTypeRef = exports.protoAddAutoLinks = exports.protoUpdateLinks = exports.protoNormalizeNodes = exports.protoInheritNodesFrom = exports.protoCloneNode = exports.protoApplyInheritance = exports.protoMergeNodes = exports.protoEnsureUniqueAddress = exports.protoCreateNodeAddressMap = exports.protoCreateEmptyNode = exports.protoApplyParent = exports.protoGetNodeParent = exports.protoGetChildrenByNameOrUndefined = exports.protoGetChildrenByName = exports.protoGetChildren = exports.protoChildrenToStringArrayOrUndefined = exports.protoChildrenToStringRecordOrUndefined = exports.protoFindChildren = exports.protoFindChild = exports.protoAddChild = void 0;
|
|
4
|
-
const common_1 = require("@iyio/common");
|
|
5
|
-
const protogen_lib_1 = require("./protogen-lib");
|
|
1
|
+
import { conditionalDeepClone, deleteUndefined, getSubstringCount, safeParseNumber } from "@iyio/common";
|
|
2
|
+
import { protoSetLayout } from "./protogen-lib.js";
|
|
6
3
|
const parentKey = Symbol('ProtoNodeParent');
|
|
7
|
-
const protoAddChild = (parent, child) => {
|
|
4
|
+
export const protoAddChild = (parent, child) => {
|
|
8
5
|
if (!parent.children) {
|
|
9
6
|
parent.children = {};
|
|
10
7
|
}
|
|
@@ -23,18 +20,20 @@ const protoAddChild = (parent, child) => {
|
|
|
23
20
|
parent.children[name] = child;
|
|
24
21
|
child[parentKey] = parent;
|
|
25
22
|
};
|
|
26
|
-
|
|
27
|
-
const protoFindChild = (parent, recursive, filter) => {
|
|
23
|
+
export const protoFindChild = (parent, recursive, filter) => {
|
|
28
24
|
if (!parent?.children) {
|
|
29
25
|
return undefined;
|
|
30
26
|
}
|
|
31
27
|
for (const key in parent.children) {
|
|
32
28
|
const child = parent.children[key];
|
|
29
|
+
if (!child) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
33
32
|
if (filter(child, key, parent)) {
|
|
34
33
|
return child;
|
|
35
34
|
}
|
|
36
35
|
if (recursive) {
|
|
37
|
-
const found =
|
|
36
|
+
const found = protoFindChild(child, true, filter);
|
|
38
37
|
if (found) {
|
|
39
38
|
return found;
|
|
40
39
|
}
|
|
@@ -42,8 +41,7 @@ const protoFindChild = (parent, recursive, filter) => {
|
|
|
42
41
|
}
|
|
43
42
|
return undefined;
|
|
44
43
|
};
|
|
45
|
-
|
|
46
|
-
const protoFindChildren = (parent, recursive, filter, appendTo) => {
|
|
44
|
+
export const protoFindChildren = (parent, recursive, filter, appendTo) => {
|
|
47
45
|
const children = appendTo ?? [];
|
|
48
46
|
if (!parent) {
|
|
49
47
|
return children;
|
|
@@ -51,13 +49,15 @@ const protoFindChildren = (parent, recursive, filter, appendTo) => {
|
|
|
51
49
|
_protoFindChildren(parent, recursive, filter, children);
|
|
52
50
|
return children;
|
|
53
51
|
};
|
|
54
|
-
exports.protoFindChildren = protoFindChildren;
|
|
55
52
|
const _protoFindChildren = (parent, recursive, filter, children) => {
|
|
56
53
|
if (!parent.children) {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
56
|
for (const key in parent.children) {
|
|
60
57
|
const child = parent.children[key];
|
|
58
|
+
if (!child) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
61
|
if (filter(child, key, parent)) {
|
|
62
62
|
children.push(child);
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ const _protoFindChildren = (parent, recursive, filter, children) => {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
-
const protoChildrenToStringRecordOrUndefined = (children) => {
|
|
69
|
+
export const protoChildrenToStringRecordOrUndefined = (children) => {
|
|
70
70
|
if (!children) {
|
|
71
71
|
return undefined;
|
|
72
72
|
}
|
|
@@ -88,8 +88,7 @@ const protoChildrenToStringRecordOrUndefined = (children) => {
|
|
|
88
88
|
}
|
|
89
89
|
return obj;
|
|
90
90
|
};
|
|
91
|
-
|
|
92
|
-
const protoChildrenToStringArrayOrUndefined = (name, children) => {
|
|
91
|
+
export const protoChildrenToStringArrayOrUndefined = (name, children) => {
|
|
93
92
|
if (!children || !name) {
|
|
94
93
|
return undefined;
|
|
95
94
|
}
|
|
@@ -105,8 +104,7 @@ const protoChildrenToStringArrayOrUndefined = (name, children) => {
|
|
|
105
104
|
}
|
|
106
105
|
return values.length ? values : undefined;
|
|
107
106
|
};
|
|
108
|
-
|
|
109
|
-
const protoGetChildren = (parent, recursive, appendTo) => {
|
|
107
|
+
export const protoGetChildren = (parent, recursive, appendTo) => {
|
|
110
108
|
const children = appendTo ?? [];
|
|
111
109
|
if (!parent) {
|
|
112
110
|
return children;
|
|
@@ -114,31 +112,30 @@ const protoGetChildren = (parent, recursive, appendTo) => {
|
|
|
114
112
|
_protoGetChildren(parent, recursive, children);
|
|
115
113
|
return children;
|
|
116
114
|
};
|
|
117
|
-
exports.protoGetChildren = protoGetChildren;
|
|
118
115
|
const _protoGetChildren = (parent, recursive, children) => {
|
|
119
116
|
if (!parent.children) {
|
|
120
117
|
return;
|
|
121
118
|
}
|
|
122
119
|
for (const key in parent.children) {
|
|
123
120
|
const child = parent.children[key];
|
|
121
|
+
if (!child) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
124
|
children.push(child);
|
|
125
125
|
if (recursive) {
|
|
126
126
|
_protoGetChildren(child, true, children);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
|
-
const protoGetChildrenByName = (parent, name, recursive, appendTo) => {
|
|
131
|
-
return
|
|
130
|
+
export const protoGetChildrenByName = (parent, name, recursive, appendTo) => {
|
|
131
|
+
return protoFindChildren(parent, recursive, c => c.name === name, appendTo);
|
|
132
132
|
};
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
const children = (0, exports.protoFindChildren)(parent, recursive, c => c.name === name, appendTo);
|
|
133
|
+
export const protoGetChildrenByNameOrUndefined = (parent, name, recursive, appendTo) => {
|
|
134
|
+
const children = protoFindChildren(parent, recursive, c => c.name === name, appendTo);
|
|
136
135
|
return children.length ? children : undefined;
|
|
137
136
|
};
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
exports.protoGetNodeParent = protoGetNodeParent;
|
|
141
|
-
const protoApplyParent = (node) => {
|
|
137
|
+
export const protoGetNodeParent = (node) => node?.[parentKey];
|
|
138
|
+
export const protoApplyParent = (node) => {
|
|
142
139
|
if (!node.children) {
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
@@ -148,11 +145,10 @@ const protoApplyParent = (node) => {
|
|
|
148
145
|
continue;
|
|
149
146
|
}
|
|
150
147
|
child[parentKey] = node;
|
|
151
|
-
|
|
148
|
+
protoApplyParent(child);
|
|
152
149
|
}
|
|
153
150
|
};
|
|
154
|
-
|
|
155
|
-
const protoCreateEmptyNode = (name, type, value) => {
|
|
151
|
+
export const protoCreateEmptyNode = (name, type, value) => {
|
|
156
152
|
const node = {
|
|
157
153
|
name,
|
|
158
154
|
address: name,
|
|
@@ -164,16 +160,14 @@ const protoCreateEmptyNode = (name, type, value) => {
|
|
|
164
160
|
}
|
|
165
161
|
return node;
|
|
166
162
|
};
|
|
167
|
-
|
|
168
|
-
const protoCreateNodeAddressMap = (nodes) => {
|
|
163
|
+
export const protoCreateNodeAddressMap = (nodes) => {
|
|
169
164
|
const map = {};
|
|
170
165
|
for (const n of nodes) {
|
|
171
166
|
map[n.address] = n;
|
|
172
167
|
}
|
|
173
168
|
return map;
|
|
174
169
|
};
|
|
175
|
-
|
|
176
|
-
const protoEnsureUniqueAddress = (node, nodes) => {
|
|
170
|
+
export const protoEnsureUniqueAddress = (node, nodes) => {
|
|
177
171
|
const hasMatch = (address) => {
|
|
178
172
|
for (const n of nodes) {
|
|
179
173
|
if (n.address === address) {
|
|
@@ -195,14 +189,13 @@ const protoEnsureUniqueAddress = (node, nodes) => {
|
|
|
195
189
|
node.address = address + '#' + i;
|
|
196
190
|
return true;
|
|
197
191
|
};
|
|
198
|
-
exports.protoEnsureUniqueAddress = protoEnsureUniqueAddress;
|
|
199
192
|
/**
|
|
200
193
|
* Merges all nodes from srcNodes into destNodes
|
|
201
194
|
* @param destNodes A flat map of nodes
|
|
202
195
|
* @param srcNodes A flat map of nodes
|
|
203
196
|
*/
|
|
204
|
-
const protoMergeNodes = (destNodes, srcNodes) => {
|
|
205
|
-
const destMap =
|
|
197
|
+
export const protoMergeNodes = (destNodes, srcNodes) => {
|
|
198
|
+
const destMap = protoCreateNodeAddressMap(destNodes);
|
|
206
199
|
const added = [];
|
|
207
200
|
for (const srcNode of srcNodes) {
|
|
208
201
|
if (destMap[srcNode.address]) {
|
|
@@ -216,14 +209,16 @@ const protoMergeNodes = (destNodes, srcNodes) => {
|
|
|
216
209
|
let pa = i === -1 ? null : node.address.substring(0, i);
|
|
217
210
|
const parent = pa ? destMap[pa] : undefined;
|
|
218
211
|
if (parent && !added.includes(parent)) {
|
|
219
|
-
|
|
212
|
+
protoAddChild(parent, node);
|
|
220
213
|
}
|
|
221
214
|
if (node.renderData?.before) {
|
|
222
215
|
const before = destMap[node.renderData.before];
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
if (before) {
|
|
217
|
+
const bi = destNodes.indexOf(before);
|
|
218
|
+
if (before && bi !== -1) {
|
|
219
|
+
destNodes.splice(bi + 1, 0, node);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
227
222
|
}
|
|
228
223
|
}
|
|
229
224
|
if (parent && pa) {
|
|
@@ -248,10 +243,9 @@ const protoMergeNodes = (destNodes, srcNodes) => {
|
|
|
248
243
|
}
|
|
249
244
|
}
|
|
250
245
|
}
|
|
251
|
-
|
|
246
|
+
protoNormalizeNodes(destNodes, { addressMap: destMap });
|
|
252
247
|
};
|
|
253
|
-
|
|
254
|
-
const protoApplyInheritance = (nodes) => {
|
|
248
|
+
export const protoApplyInheritance = (nodes) => {
|
|
255
249
|
for (const node of nodes) {
|
|
256
250
|
if (node.address.includes('.')) {
|
|
257
251
|
continue;
|
|
@@ -265,12 +259,11 @@ const protoApplyInheritance = (nodes) => {
|
|
|
265
259
|
console.log(nodes);
|
|
266
260
|
throw new Error(`Unable to find node (${type.type}) for inheritance by (${node.name})`);
|
|
267
261
|
}
|
|
268
|
-
|
|
262
|
+
protoInheritNodesFrom(node, fromNode, nodes);
|
|
269
263
|
updateInheritedAddresses(node, [node.address], true);
|
|
270
264
|
}
|
|
271
265
|
}
|
|
272
266
|
};
|
|
273
|
-
exports.protoApplyInheritance = protoApplyInheritance;
|
|
274
267
|
const updateInheritedAddresses = (node, path, requireInherited) => {
|
|
275
268
|
if (!node.children) {
|
|
276
269
|
return;
|
|
@@ -293,8 +286,8 @@ const shouldBeNode = (node) => {
|
|
|
293
286
|
(typeof node.type === 'string') &&
|
|
294
287
|
Array.isArray(node.types)) ? true : false;
|
|
295
288
|
};
|
|
296
|
-
const protoCloneNode = (node) => {
|
|
297
|
-
return
|
|
289
|
+
export const protoCloneNode = (node) => {
|
|
290
|
+
return conditionalDeepClone(node, (key, value, path, values) => {
|
|
298
291
|
const child = values[values.length - 2];
|
|
299
292
|
const parent = values[values.length - 4];
|
|
300
293
|
const skip = (key === 'renderData' &&
|
|
@@ -303,20 +296,19 @@ const protoCloneNode = (node) => {
|
|
|
303
296
|
return !skip;
|
|
304
297
|
});
|
|
305
298
|
};
|
|
306
|
-
|
|
307
|
-
const protoInheritNodesFrom = (to, from, allNodes, inheritanceChain = []) => {
|
|
299
|
+
export const protoInheritNodesFrom = (to, from, allNodes, inheritanceChain = []) => {
|
|
308
300
|
if (inheritanceChain.includes(from.name)) {
|
|
309
301
|
throw new Error(`inheritance loop detected (${inheritanceChain.join(' -> ')} -> ${from.name})`);
|
|
310
302
|
}
|
|
311
303
|
inheritanceChain.push(from.name);
|
|
312
|
-
const omit =
|
|
304
|
+
const omit = protoGetChildrenByName(to, '$omit', false);
|
|
313
305
|
if (from.children) {
|
|
314
306
|
for (const c in from.children) {
|
|
315
307
|
const child = from.children[c];
|
|
316
308
|
if (!child || child.inheritedAddress || to.children?.[c] || omit.some(op => op.value === child.name || op.value === child.address)) {
|
|
317
309
|
continue;
|
|
318
310
|
}
|
|
319
|
-
const clone =
|
|
311
|
+
const clone = protoCloneNode(child);
|
|
320
312
|
clone.inheritedAddress = clone.address;
|
|
321
313
|
if (!to.children) {
|
|
322
314
|
to.children = {};
|
|
@@ -331,28 +323,27 @@ const protoInheritNodesFrom = (to, from, allNodes, inheritanceChain = []) => {
|
|
|
331
323
|
if (!fromNode) {
|
|
332
324
|
throw new Error(`Unable to find node (${type.type}) for inheritance by (${to.name}).`);
|
|
333
325
|
}
|
|
334
|
-
|
|
326
|
+
protoInheritNodesFrom(to, fromNode, allNodes, inheritanceChain);
|
|
335
327
|
}
|
|
336
328
|
}
|
|
337
329
|
};
|
|
338
|
-
|
|
339
|
-
const protoNormalizeNodes = (nodes, { autoLink = true, revLink = true, srcLink = true, updateBefore = true, addComments = true, addressMap = (0, exports.protoCreateNodeAddressMap)(nodes), applyInheritance, } = {}) => {
|
|
330
|
+
export const protoNormalizeNodes = (nodes, { autoLink = true, revLink = true, srcLink = true, updateBefore = true, addComments = true, addressMap = protoCreateNodeAddressMap(nodes), applyInheritance, } = {}) => {
|
|
340
331
|
if (applyInheritance) {
|
|
341
|
-
|
|
342
|
-
addressMap =
|
|
332
|
+
protoApplyInheritance(nodes);
|
|
333
|
+
addressMap = protoCreateNodeAddressMap(nodes);
|
|
343
334
|
}
|
|
344
335
|
let lastNode = null;
|
|
345
336
|
for (const node of nodes) {
|
|
346
337
|
if (addComments && node.children?.['#']) {
|
|
347
338
|
node.comment = (node.children['#'].value ?? '').trimEnd();
|
|
348
339
|
}
|
|
349
|
-
const parent =
|
|
340
|
+
const parent = protoGetNodeParent(node);
|
|
350
341
|
for (const type of node.types) {
|
|
351
342
|
if (type.source) {
|
|
352
343
|
const address = type.path.join('.');
|
|
353
344
|
node.sourceAddress = address;
|
|
354
345
|
node.sourceLinked = addressMap[address] ? true : false;
|
|
355
|
-
|
|
346
|
+
protoAddLink(node, {
|
|
356
347
|
name: address,
|
|
357
348
|
address,
|
|
358
349
|
priority: 'med',
|
|
@@ -370,7 +361,7 @@ const protoNormalizeNodes = (nodes, { autoLink = true, revLink = true, srcLink =
|
|
|
370
361
|
const address = node.value;
|
|
371
362
|
parent.sourceAddress = address;
|
|
372
363
|
parent.sourceLinked = addressMap[address] ? true : false;
|
|
373
|
-
|
|
364
|
+
protoAddLink(parent, {
|
|
374
365
|
name: address,
|
|
375
366
|
address,
|
|
376
367
|
priority: 'med',
|
|
@@ -379,29 +370,28 @@ const protoNormalizeNodes = (nodes, { autoLink = true, revLink = true, srcLink =
|
|
|
379
370
|
}
|
|
380
371
|
if (parent && node.name === '$link' && node.value) {
|
|
381
372
|
const address = node.value;
|
|
382
|
-
|
|
373
|
+
protoAddLink(parent, {
|
|
383
374
|
name: address,
|
|
384
375
|
address,
|
|
385
376
|
color: node.children?.['color']?.value
|
|
386
377
|
});
|
|
387
378
|
}
|
|
388
379
|
if (autoLink && !node.special) {
|
|
389
|
-
|
|
380
|
+
protoAddAutoLinks(node);
|
|
390
381
|
}
|
|
391
382
|
lastNode = node;
|
|
392
383
|
}
|
|
393
384
|
if (revLink) {
|
|
394
|
-
|
|
385
|
+
protoUpdateLinks(nodes, addressMap);
|
|
395
386
|
}
|
|
396
387
|
};
|
|
397
|
-
|
|
398
|
-
const protoUpdateLinks = (nodes, addressMap) => {
|
|
388
|
+
export const protoUpdateLinks = (nodes, addressMap) => {
|
|
399
389
|
for (const node of nodes) {
|
|
400
390
|
if (node.links) {
|
|
401
391
|
for (const link of node.links) {
|
|
402
392
|
const to = addressMap[link.address];
|
|
403
393
|
if (to) {
|
|
404
|
-
|
|
394
|
+
protoAddLink(to, {
|
|
405
395
|
name: node.name,
|
|
406
396
|
address: node.address,
|
|
407
397
|
rev: true,
|
|
@@ -413,8 +403,7 @@ const protoUpdateLinks = (nodes, addressMap) => {
|
|
|
413
403
|
}
|
|
414
404
|
}
|
|
415
405
|
};
|
|
416
|
-
|
|
417
|
-
const protoAddAutoLinks = (node) => {
|
|
406
|
+
export const protoAddAutoLinks = (node) => {
|
|
418
407
|
if (node.name !== node.type && node.types.length) {
|
|
419
408
|
for (const type of node.types) {
|
|
420
409
|
if (!type.type || type.less || !type.isRefType) {
|
|
@@ -425,7 +414,7 @@ const protoAddAutoLinks = (node) => {
|
|
|
425
414
|
}
|
|
426
415
|
const pri = type.important;
|
|
427
416
|
const address = type.path.join('.');
|
|
428
|
-
|
|
417
|
+
protoAddLink(node, {
|
|
429
418
|
name: address,
|
|
430
419
|
address: address,
|
|
431
420
|
priority: pri ? 'high' : 'low'
|
|
@@ -433,18 +422,16 @@ const protoAddAutoLinks = (node) => {
|
|
|
433
422
|
}
|
|
434
423
|
}
|
|
435
424
|
};
|
|
436
|
-
|
|
437
|
-
const protoGetTypeRef = (type, addressMap) => {
|
|
425
|
+
export const protoGetTypeRef = (type, addressMap) => {
|
|
438
426
|
if (!type?.isRefType) {
|
|
439
427
|
return undefined;
|
|
440
428
|
}
|
|
441
429
|
if (!type.path) {
|
|
442
430
|
return addressMap[type.type];
|
|
443
431
|
}
|
|
444
|
-
return
|
|
432
|
+
return protoGetNodeAtPath(type.path, addressMap);
|
|
445
433
|
};
|
|
446
|
-
|
|
447
|
-
const protoGetNodeAtPath = (path, addressMap, relative) => {
|
|
434
|
+
export const protoGetNodeAtPath = (path, addressMap, relative) => {
|
|
448
435
|
if (typeof path === 'string') {
|
|
449
436
|
if (!path) {
|
|
450
437
|
return undefined;
|
|
@@ -458,12 +445,12 @@ const protoGetNodeAtPath = (path, addressMap, relative) => {
|
|
|
458
445
|
return undefined;
|
|
459
446
|
}
|
|
460
447
|
if (!path[0] && relative) {
|
|
461
|
-
const p =
|
|
448
|
+
const p = protoGetNodeParent(relative);
|
|
462
449
|
if (p) {
|
|
463
450
|
path[0] = p.address;
|
|
464
451
|
}
|
|
465
452
|
}
|
|
466
|
-
let node = addressMap[path[0]];
|
|
453
|
+
let node = addressMap[path[0] ?? ''];
|
|
467
454
|
for (let i = 1; i < path.length; i++) {
|
|
468
455
|
if (!node) {
|
|
469
456
|
return undefined;
|
|
@@ -478,7 +465,6 @@ const protoGetNodeAtPath = (path, addressMap, relative) => {
|
|
|
478
465
|
}
|
|
479
466
|
return node;
|
|
480
467
|
};
|
|
481
|
-
exports.protoGetNodeAtPath = protoGetNodeAtPath;
|
|
482
468
|
const getLinkTarget = (node, key, addressMap, maxDepth = 30) => {
|
|
483
469
|
if (maxDepth < 1) {
|
|
484
470
|
return { node, jmp: false };
|
|
@@ -516,8 +502,8 @@ const getLinkTarget = (node, key, addressMap, maxDepth = 30) => {
|
|
|
516
502
|
}
|
|
517
503
|
return { node, jmp };
|
|
518
504
|
};
|
|
519
|
-
const protoAddLink = (node, link, allowDuplicates = false) => {
|
|
520
|
-
|
|
505
|
+
export const protoAddLink = (node, link, allowDuplicates = false) => {
|
|
506
|
+
deleteUndefined(link);
|
|
521
507
|
if (node.links && !allowDuplicates) {
|
|
522
508
|
for (const l of node.links) {
|
|
523
509
|
if (l.address === link.address) {
|
|
@@ -531,8 +517,7 @@ const protoAddLink = (node, link, allowDuplicates = false) => {
|
|
|
531
517
|
node.links.push(link);
|
|
532
518
|
return true;
|
|
533
519
|
};
|
|
534
|
-
|
|
535
|
-
const protoChildrenToArray = (children, filterOutNonStandard = false) => {
|
|
520
|
+
export const protoChildrenToArray = (children, filterOutNonStandard = false) => {
|
|
536
521
|
if (!children) {
|
|
537
522
|
return [];
|
|
538
523
|
}
|
|
@@ -543,29 +528,29 @@ const protoChildrenToArray = (children, filterOutNonStandard = false) => {
|
|
|
543
528
|
(filterOutNonStandard && (child.special || child.isContent))) {
|
|
544
529
|
continue;
|
|
545
530
|
}
|
|
546
|
-
ary.push(
|
|
531
|
+
ary.push(child);
|
|
547
532
|
}
|
|
548
533
|
return ary;
|
|
549
534
|
};
|
|
550
|
-
|
|
551
|
-
const protoFlattenHierarchy = (node) => {
|
|
535
|
+
export const protoFlattenHierarchy = (node) => {
|
|
552
536
|
const ary = [];
|
|
553
|
-
|
|
537
|
+
protoAddFlattenedHierarchy(node, ary);
|
|
554
538
|
return ary;
|
|
555
539
|
};
|
|
556
|
-
|
|
557
|
-
const protoAddFlattenedHierarchy = (node, ary) => {
|
|
540
|
+
export const protoAddFlattenedHierarchy = (node, ary) => {
|
|
558
541
|
ary.push(node);
|
|
559
542
|
if (node.children) {
|
|
560
543
|
for (const name in node.children) {
|
|
561
|
-
|
|
544
|
+
const child = node.children[name];
|
|
545
|
+
if (child) {
|
|
546
|
+
protoAddFlattenedHierarchy(child, ary);
|
|
547
|
+
}
|
|
562
548
|
}
|
|
563
549
|
}
|
|
564
550
|
};
|
|
565
|
-
|
|
566
|
-
const protoRenderLines = ({ rootNode, nodes, maxDepth, hideContent, hideSpecial, hideTypeInfo, filter, renderer, }) => {
|
|
551
|
+
export const protoRenderLines = ({ rootNode, nodes, maxDepth, hideContent, hideSpecial, hideTypeInfo, filter, renderer, }) => {
|
|
567
552
|
if (!nodes && rootNode) {
|
|
568
|
-
nodes =
|
|
553
|
+
nodes = protoFlattenHierarchy(rootNode);
|
|
569
554
|
}
|
|
570
555
|
if (!nodes) {
|
|
571
556
|
return [];
|
|
@@ -602,8 +587,7 @@ const protoRenderLines = ({ rootNode, nodes, maxDepth, hideContent, hideSpecial,
|
|
|
602
587
|
}
|
|
603
588
|
return lines;
|
|
604
589
|
};
|
|
605
|
-
|
|
606
|
-
const protoGetPosScale = (node) => {
|
|
590
|
+
export const protoGetPosScale = (node) => {
|
|
607
591
|
const layout = node.children?.['$layout'];
|
|
608
592
|
if (!layout?.value) {
|
|
609
593
|
return {
|
|
@@ -614,14 +598,13 @@ const protoGetPosScale = (node) => {
|
|
|
614
598
|
}
|
|
615
599
|
const [x, y, w] = layout.value.split(/\s+/);
|
|
616
600
|
return {
|
|
617
|
-
x:
|
|
618
|
-
y:
|
|
619
|
-
width:
|
|
601
|
+
x: safeParseNumber(x),
|
|
602
|
+
y: safeParseNumber(y),
|
|
603
|
+
width: safeParseNumber(w, 300),
|
|
620
604
|
scale: 1,
|
|
621
605
|
};
|
|
622
606
|
};
|
|
623
|
-
|
|
624
|
-
const protoSetPosScale = (node, posScale) => {
|
|
607
|
+
export const protoSetPosScale = (node, posScale) => {
|
|
625
608
|
let layout = node.children?.['$layout'];
|
|
626
609
|
const scale = posScale.scale ?? 1;
|
|
627
610
|
const value = `${Math.round(posScale.x * scale)} ${Math.round(posScale.y * scale)} ${Math.round((posScale.width ?? 300) * scale)}`;
|
|
@@ -636,15 +619,14 @@ const protoSetPosScale = (node, posScale) => {
|
|
|
636
619
|
types: [{ type: '', path: [] }],
|
|
637
620
|
value
|
|
638
621
|
};
|
|
639
|
-
|
|
622
|
+
protoAddChild(node, layout);
|
|
640
623
|
}
|
|
641
624
|
if (layout.renderData?.input !== undefined) {
|
|
642
625
|
delete layout.renderData.input;
|
|
643
626
|
}
|
|
644
627
|
};
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
const allNodes = (0, exports.protoFlattenHierarchy)(node);
|
|
628
|
+
export const protoParsingResultFromNode = (node) => {
|
|
629
|
+
const allNodes = protoFlattenHierarchy(node);
|
|
648
630
|
const addressMap = {};
|
|
649
631
|
for (const node of allNodes) {
|
|
650
632
|
if (!addressMap[node.address]) {
|
|
@@ -657,8 +639,7 @@ const protoParsingResultFromNode = (node) => {
|
|
|
657
639
|
addressMap,
|
|
658
640
|
};
|
|
659
641
|
};
|
|
660
|
-
|
|
661
|
-
const protoUpdateLayouts = (nodes, { x = 0, yStart = 0, width = 300, lineHeight, getOffset, transform, }) => {
|
|
642
|
+
export const protoUpdateLayouts = (nodes, { x = 0, yStart = 0, width = 300, lineHeight, getOffset, transform, }) => {
|
|
662
643
|
let y = yStart;
|
|
663
644
|
for (const node of nodes) {
|
|
664
645
|
if (!node.renderData) {
|
|
@@ -674,20 +655,19 @@ const protoUpdateLayouts = (nodes, { x = 0, yStart = 0, width = 300, lineHeight,
|
|
|
674
655
|
getOffset,
|
|
675
656
|
broken: node.links?.some(l => l.broken)
|
|
676
657
|
};
|
|
677
|
-
|
|
678
|
-
y += lineHeight + (
|
|
658
|
+
protoSetLayout(node, transform ? transform(node, layout) : layout);
|
|
659
|
+
y += lineHeight + (getSubstringCount(node.renderData.input ?? '', '\n') * lineHeight);
|
|
679
660
|
}
|
|
680
661
|
return y;
|
|
681
662
|
};
|
|
682
|
-
|
|
683
|
-
const protoClearRevLinks = (nodes) => {
|
|
663
|
+
export const protoClearRevLinks = (nodes) => {
|
|
684
664
|
for (const node of nodes) {
|
|
685
665
|
if (!node.links) {
|
|
686
666
|
continue;
|
|
687
667
|
}
|
|
688
668
|
for (let i = 0; i < node.links.length; i++) {
|
|
689
669
|
const link = node.links[i];
|
|
690
|
-
if (link
|
|
670
|
+
if (link?.rev) {
|
|
691
671
|
node.links.splice(i, 1);
|
|
692
672
|
i--;
|
|
693
673
|
}
|
|
@@ -697,20 +677,18 @@ const protoClearRevLinks = (nodes) => {
|
|
|
697
677
|
}
|
|
698
678
|
}
|
|
699
679
|
};
|
|
700
|
-
exports.protoClearRevLinks = protoClearRevLinks;
|
|
701
680
|
const nodeCtrlKey = Symbol('nodeCtrlKey');
|
|
702
|
-
const protoGetNodeCtrl = (node) => {
|
|
681
|
+
export const protoGetNodeCtrl = (node) => {
|
|
703
682
|
while (node) {
|
|
704
683
|
const ctrl = node[nodeCtrlKey];
|
|
705
684
|
if (ctrl) {
|
|
706
685
|
return ctrl;
|
|
707
686
|
}
|
|
708
|
-
node =
|
|
687
|
+
node = protoGetNodeParent(node);
|
|
709
688
|
}
|
|
710
689
|
return undefined;
|
|
711
690
|
};
|
|
712
|
-
|
|
713
|
-
const protoSetNodeCtrl = (node, ctrl) => {
|
|
691
|
+
export const protoSetNodeCtrl = (node, ctrl) => {
|
|
714
692
|
if (node) {
|
|
715
693
|
if (ctrl) {
|
|
716
694
|
node[nodeCtrlKey] = ctrl;
|
|
@@ -720,12 +698,11 @@ const protoSetNodeCtrl = (node, ctrl) => {
|
|
|
720
698
|
}
|
|
721
699
|
}
|
|
722
700
|
};
|
|
723
|
-
exports.protoSetNodeCtrl = protoSetNodeCtrl;
|
|
724
701
|
/**
|
|
725
702
|
* Removes children that are only used for display purposes such as $layout and renderData.
|
|
726
703
|
* Returns the same node that is passed in.
|
|
727
704
|
*/
|
|
728
|
-
const protoRemoveDisplayChildren = (node, options = {}) => {
|
|
705
|
+
export const protoRemoveDisplayChildren = (node, options = {}) => {
|
|
729
706
|
if (Array.isArray(node)) {
|
|
730
707
|
for (const n of node) {
|
|
731
708
|
_protoRemoveDisplayChildren(n, options);
|
|
@@ -736,7 +713,6 @@ const protoRemoveDisplayChildren = (node, options = {}) => {
|
|
|
736
713
|
}
|
|
737
714
|
return node;
|
|
738
715
|
};
|
|
739
|
-
exports.protoRemoveDisplayChildren = protoRemoveDisplayChildren;
|
|
740
716
|
const _protoRemoveDisplayChildren = (node, options = {}) => {
|
|
741
717
|
delete node.renderData;
|
|
742
718
|
if (options.removeComments) {
|
|
@@ -750,7 +726,10 @@ const _protoRemoveDisplayChildren = (node, options = {}) => {
|
|
|
750
726
|
delete node.children[e];
|
|
751
727
|
}
|
|
752
728
|
else {
|
|
753
|
-
|
|
729
|
+
const child = node.children[e];
|
|
730
|
+
if (child) {
|
|
731
|
+
protoRemoveDisplayChildren(child);
|
|
732
|
+
}
|
|
754
733
|
}
|
|
755
734
|
}
|
|
756
735
|
};
|