@ibiz-template/model-helper 0.7.41-alpha.1 → 0.7.41-alpha.100

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.
@@ -17,10 +17,10 @@ export function mergeTreeView(dst, source) {
17
17
  }
18
18
  source.detreeNodes.forEach(sourceNode => {
19
19
  var _a;
20
- const isExist = dst.detreeNodes.find(dstNode => {
20
+ const item = dst.detreeNodes.find(dstNode => {
21
21
  return dstNode.id === sourceNode.id;
22
22
  });
23
- if (!isExist) {
23
+ if (!item) {
24
24
  (_a = dst.detreeNodes) === null || _a === void 0 ? void 0 : _a.push(sourceNode);
25
25
  }
26
26
  });
@@ -32,13 +32,149 @@ export function mergeTreeView(dst, source) {
32
32
  }
33
33
  source.detreeNodeRSs.forEach(sourceNodeRs => {
34
34
  var _a;
35
- const isExist = dst.detreeNodeRSs.find(dstNodeRs => {
35
+ // 若配置了用户标记(dynamic_overlay:before|after|replace|delete|start|end:noderesid),则需根据用户标记进行合并,否则原始数据没有则直接附加末尾
36
+ if (sourceNodeRs.userTag &&
37
+ sourceNodeRs.userTag.startsWith('dynamic_overlay') &&
38
+ sourceNodeRs.userTag.split(':').length === 3) {
39
+ mergeSubAppTreeNodeResToDst(dst, sourceNodeRs);
40
+ }
41
+ else {
42
+ const itemIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
43
+ return (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId &&
44
+ dstNodeRs.childDETreeNodeId === sourceNodeRs.childDETreeNodeId);
45
+ });
46
+ // 若存在end标记,则需要添加到第一个end标记节点关系前面,保证end标记节点关系始终添加到最后
47
+ const endIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
48
+ var _a;
49
+ if (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId) {
50
+ const tags = (_a = sourceNodeRs.userTag) === null || _a === void 0 ? void 0 : _a.split(':');
51
+ if (!tags || tags.length !== 3 || tags[1] !== 'end')
52
+ return false;
53
+ return true;
54
+ }
55
+ return false;
56
+ });
57
+ if (itemIndex === -1) {
58
+ if (endIndex === -1) {
59
+ (_a = dst.detreeNodeRSs) === null || _a === void 0 ? void 0 : _a.push(sourceNodeRs);
60
+ }
61
+ else {
62
+ dst.detreeNodeRSs.splice(endIndex, 0, sourceNodeRs);
63
+ }
64
+ }
65
+ }
66
+ });
67
+ }
68
+ }
69
+ /**
70
+ * 合并指定子应用树节点关系到主应用树指定位置
71
+ * @param dst 原始树
72
+ * @param sourceNode 子应用树节点关系
73
+ */
74
+ function mergeSubAppTreeNodeResToDst(dst, sourceNodeRs) {
75
+ var _a;
76
+ // dynamic_overlay:before|after|replace|delete|start|end:nodeid 定义附加位置
77
+ const [dynamicOverlay, targetPosition, targetTag] = sourceNodeRs.userTag.split(':');
78
+ if (!dynamicOverlay || !targetPosition || !targetTag)
79
+ return;
80
+ switch (targetPosition) {
81
+ case 'before':
82
+ // 在目标节点之前,dynamic_overlay:before:childnodeid,这儿最后一节拼接的是子节点标识
83
+ const beforeIndex = dst.detreeNodeRSs.findIndex(dstNode => {
84
+ return (dstNode.childDETreeNodeId === targetTag &&
85
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
86
+ });
87
+ if (beforeIndex !== -1) {
88
+ dst.detreeNodeRSs.splice(beforeIndex, 0, sourceNodeRs);
89
+ }
90
+ break;
91
+ case 'after':
92
+ // 在目标节点之后,格式如:dynamic_overlay:after:childnodeid,最后一节拼接的是子节点标识
93
+ const afterIndex = dst.detreeNodeRSs.findIndex(dstNode => {
94
+ return (dstNode.childDETreeNodeId === targetTag &&
95
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
96
+ });
97
+ if (afterIndex !== -1) {
98
+ dst.detreeNodeRSs.splice(afterIndex + 1, 0, sourceNodeRs);
99
+ }
100
+ break;
101
+ case 'replace':
102
+ // 替换目标节点,格式如:dynamic_overlay:replace:childnodeid,最后一节拼接的是子节点标识
103
+ const replaceIndex = dst.detreeNodeRSs.findIndex(dstNode => {
104
+ return (dstNode.childDETreeNodeId === targetTag &&
105
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
106
+ });
107
+ if (replaceIndex !== -1) {
108
+ dst.detreeNodeRSs.splice(replaceIndex, 1, sourceNodeRs);
109
+ }
110
+ break;
111
+ case 'delete':
112
+ // 删除目标节点,格式如:dynamic_overlay:delete:childnodeid,最后一节拼接的是子节点标识
113
+ const deleteIndex = dst.detreeNodeRSs.findIndex(dstNode => {
114
+ return (dstNode.childDETreeNodeId === targetTag &&
115
+ dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId);
116
+ });
117
+ if (deleteIndex !== -1) {
118
+ dst.detreeNodeRSs.splice(deleteIndex, 1);
119
+ }
120
+ break;
121
+ case 'start':
122
+ // 在目标节点内部开始,格式如:dynamic_overlay:start:随机字符,最后一节拼接的是随机字符,读的是当前节点关系的父节点标识
123
+ const startIndex = dst.detreeNodeRSs.findIndex(dstNode => {
124
+ return dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId;
125
+ });
126
+ if (startIndex !== -1) {
127
+ dst.detreeNodeRSs.splice(startIndex, 0, sourceNodeRs);
128
+ }
129
+ break;
130
+ case 'end':
131
+ // 在目标节点内部结束,格式如:dynamic_overlay:end:随机字符,最后一节拼接的是随机字符,读的是当前节点关系的父节点标识
132
+ const endIndex = getLastIndex(dst.detreeNodeRSs, dstNode => {
133
+ return dstNode.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId;
134
+ });
135
+ if (endIndex !== -1) {
136
+ dst.detreeNodeRSs.splice(endIndex + 1, 0, sourceNodeRs);
137
+ }
138
+ break;
139
+ default:
140
+ // 未识别位置,若源树不存在该关系,则直接附加到最后
141
+ const defaultIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
36
142
  return (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId &&
37
143
  dstNodeRs.childDETreeNodeId === sourceNodeRs.childDETreeNodeId);
38
144
  });
39
- if (!isExist) {
40
- (_a = dst.detreeNodeRSs) === null || _a === void 0 ? void 0 : _a.push(sourceNodeRs);
145
+ // 若存在end标记,则需要添加到第一个end标记节点关系前面,保证end标记节点关系始终添加到最后
146
+ const defaultEndIndex = dst.detreeNodeRSs.findIndex(dstNodeRs => {
147
+ var _a;
148
+ if (dstNodeRs.parentDETreeNodeId === sourceNodeRs.parentDETreeNodeId) {
149
+ const tags = (_a = sourceNodeRs.userTag) === null || _a === void 0 ? void 0 : _a.split(':');
150
+ if (!tags || tags.length !== 3 || tags[1] !== 'end')
151
+ return false;
152
+ return true;
153
+ }
154
+ return false;
155
+ });
156
+ if (defaultIndex === -1) {
157
+ if (defaultEndIndex === -1) {
158
+ (_a = dst.detreeNodeRSs) === null || _a === void 0 ? void 0 : _a.push(sourceNodeRs);
159
+ }
160
+ else {
161
+ dst.detreeNodeRSs.splice(defaultEndIndex, 0, sourceNodeRs);
162
+ }
41
163
  }
42
- });
164
+ break;
165
+ }
166
+ }
167
+ /**
168
+ * 获取指定数组中满足条件的最后一个元素
169
+ * @param arr 指定数组
170
+ * @param predicate 过滤条件
171
+ * @returns 找到则返回指定元素下标,反之返回-1
172
+ */
173
+ function getLastIndex(arr, predicate) {
174
+ for (let i = arr.length - 1; i >= 0; i--) {
175
+ if (predicate(arr[i])) {
176
+ return i;
177
+ }
43
178
  }
179
+ return -1;
44
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibiz-template/model-helper",
3
- "version": "0.7.41-alpha.1",
3
+ "version": "0.7.41-alpha.100",
4
4
  "description": "模型辅助库",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",
@@ -30,14 +30,14 @@
30
30
  "author": "iBiz",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@ibiz-template/core": "^0.7.41-alpha.1",
34
- "@ibiz/model-core": "^0.1.75",
35
- "@ibiz/rt-model-api": "0.2.72",
33
+ "@ibiz-template/core": "^0.7.41-alpha.88",
34
+ "@ibiz/model-core": "^0.1.86",
35
+ "@ibiz/rt-model-api": "0.2.84",
36
36
  "pluralize": "^8.0.0",
37
37
  "ramda": "^0.29.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@ibiz-template/runtime": "^0.7.41-alpha.1",
40
+ "@ibiz-template/runtime": "^0.7.41-alpha.100",
41
41
  "@types/pluralize": "^0.0.33",
42
42
  "@types/ramda": "^0.29.10"
43
43
  },
@@ -45,5 +45,5 @@
45
45
  "@ibiz-template/runtime": "^0.6.0",
46
46
  "ramda": "^0.29.0"
47
47
  },
48
- "gitHead": "49b4a4328c21f6b4725855f6f1a1c00a72ed8065"
48
+ "gitHead": "fddfbaa15b8d916e4da1cbb9308eb5f766bddb90"
49
49
  }