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