@lcap/nasl 0.3.10-beta → 0.3.10-beta.5

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.
Files changed (61) hide show
  1. package/out/service/logic/logic.d.ts +26 -17
  2. package/out/service/logic/logic.js +6 -0
  3. package/out/service/logic/logic.js.map +1 -1
  4. package/out/types/app/App.d.ts +5 -4
  5. package/out/types/app/App.js +30 -24
  6. package/out/types/app/App.js.map +1 -1
  7. package/out/types/cacheData.js.map +1 -1
  8. package/out/types/data/dataTypes.js +1 -1
  9. package/out/types/data/dataTypes.js.map +1 -1
  10. package/out/types/index.d.ts +2 -4
  11. package/out/types/index.js +3 -6
  12. package/out/types/index.js.map +1 -1
  13. package/out/types/logic/Logic.d.ts +4 -12
  14. package/out/types/logic/Logic.js +26 -14
  15. package/out/types/logic/Logic.js.map +1 -1
  16. package/out/types/logic/LogicItem.d.ts +1 -20
  17. package/out/types/logic/LogicItem.js +0 -184
  18. package/out/types/logic/LogicItem.js.map +1 -1
  19. package/out/types/logic/Param.js +2 -0
  20. package/out/types/logic/Param.js.map +1 -1
  21. package/out/types/logic/translator.js +39 -8
  22. package/out/types/logic/translator.js.map +1 -1
  23. package/out/types/page/Element.d.ts +10 -2
  24. package/out/types/page/Element.js +51 -4
  25. package/out/types/page/Element.js.map +1 -1
  26. package/out/types/page/View.d.ts +10 -16
  27. package/out/types/page/View.js +40 -15
  28. package/out/types/page/View.js.map +1 -1
  29. package/out/types/process/ProcessParam.js +3 -1
  30. package/out/types/process/ProcessParam.js.map +1 -1
  31. package/package.json +1 -2
  32. package/src/service/logic/logic.js +6 -0
  33. package/src/types/app/App.ts +36 -27
  34. package/src/types/cacheData.ts +7 -7
  35. package/src/types/data/dataTypes.ts +1 -1
  36. package/src/types/index.ts +2 -4
  37. package/src/types/logic/Logic.ts +35 -30
  38. package/src/types/logic/LogicItem.ts +5 -207
  39. package/src/types/logic/Param.ts +20 -17
  40. package/src/types/logic/translator.js +125 -153
  41. package/src/types/page/Element.ts +121 -71
  42. package/src/types/page/View.ts +79 -61
  43. package/src/types/page/dist/View.js +727 -0
  44. package/src/types/process/ProcessParam.ts +4 -1
  45. package/tsconfig.json +1 -1
  46. package/out/service/debugger/debugger.d.ts +0 -3
  47. package/out/service/debugger/debugger.js +0 -95
  48. package/out/service/debugger/debugger.js.map +0 -1
  49. package/out/test/units/config.spec.d.ts +0 -1
  50. package/out/test/units/config.spec.js +0 -12
  51. package/out/test/units/config.spec.js.map +0 -1
  52. package/out/types/logic/BreakPoint.d.ts +0 -42
  53. package/out/types/logic/BreakPoint.js +0 -155
  54. package/out/types/logic/BreakPoint.js.map +0 -1
  55. package/out/types/logic/Debugger.d.ts +0 -156
  56. package/out/types/logic/Debugger.js +0 -912
  57. package/out/types/logic/Debugger.js.map +0 -1
  58. package/src/service/debugger/debugger.js +0 -90
  59. package/src/types/logic/BreakPoint.ts +0 -200
  60. package/src/types/logic/Debugger.ts +0 -1140
  61. package/src/types/logic/translator.d.ts +0 -16
@@ -7,7 +7,6 @@ import { vertexsMap } from '../cacheData';
7
7
  import Variable from '../logic/Variable';
8
8
  import * as babelParser from '@babel/parser';
9
9
  import { isPlainObject, cloneDeep, mapValues } from 'lodash';
10
- import * as utilsAll from '../../../src/types/utils/string';
11
10
  import { refreshHtml } from '../cache';
12
11
  import { BusinessCode } from '../enum';
13
12
 
@@ -31,14 +30,14 @@ export interface ParseContext {
31
30
 
32
31
  export function catchFn(view: View) {
33
32
  return async (err: any) => {
34
- if(err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
33
+ if (err.code !== BusinessCode.HasReferenced) // 节点被引用,不用刷新数据
35
34
  await refreshHtml(view);
36
35
  else
37
36
  config.defaultApp?.emit('saved', err);
38
37
 
39
38
  config.defaultApp?.history.load();
40
39
  throw err;
41
- }
40
+ };
42
41
  }
43
42
 
44
43
  /**
@@ -155,6 +154,11 @@ export class Element extends Vertex {
155
154
  */
156
155
  @immutable()
157
156
  public readonly children?: Array<Element> = [];
157
+ /**
158
+ * 标签名前缀
159
+ */
160
+ @immutable()
161
+ public static readonly TAG_NAME_REG?: RegExp = /^([lieu]|van)[-_]/;
158
162
 
159
163
  /**
160
164
  * @param source 需要合并的部分参数
@@ -181,45 +185,45 @@ export class Element extends Vertex {
181
185
  }
182
186
 
183
187
  config.defaultApp?.emit('saving');
184
- if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
185
- const body = this.toJSON();
186
- body.parentId = this.parent && this.parent.id;
187
- body._posIndex = this.parent && this.parent.children.indexOf(this);
188
- utils.logger.debug('添加元素', body);
189
- const result = await elementService.create({
190
- headers: {
191
- appId: config.defaultApp?.id,
192
- operationAction: 'Element.create',
193
- operationDesc: `添加组件"${this.getElementTitle()}"`,
194
- },
195
- body,
196
- }).catch(catchFn(this.view));
197
-
198
- this.deepPick(result, ['id', 'parentId', 'elementId']);
199
- // attr,directive,event的id,exprssion需要合并
200
- this.attrList.forEach((attr, index) => {
201
- attr.deepPick(result.attrList[index], ['id', 'expression']);
202
- });
203
- this.directiveList.forEach((directive, index) => {
204
- directive.deepPick(result.directiveList[index], ['id', 'expression']);
205
- });
206
- this.eventList.forEach((event, index) => {
207
- event.deepPick(result.eventList[index], ['id']);
208
- });
209
- }
210
-
211
- this.view && this.view.emit('change');
212
-
213
- if (actionOptions?.loadHistory !== false) {
214
- await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
188
+ if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
189
+ const body = this.toJSON();
190
+ body.parentId = this.parent && this.parent.id;
191
+ body._posIndex = this.parent && this.parent.children.indexOf(this);
192
+ utils.logger.debug('添加元素', body);
193
+ const result = await elementService.create({
194
+ headers: {
195
+ appId: config.defaultApp?.id,
215
196
  operationAction: 'Element.create',
216
- operationBeforeImage: null,
217
- operationAfterImage: JSON.parse(JSON.stringify(this)),
218
197
  operationDesc: `添加组件"${this.getElementTitle()}"`,
219
- });
198
+ },
199
+ body,
200
+ }).catch(catchFn(this.view));
201
+
202
+ this.deepPick(result, ['id', 'parentId', 'elementId']);
203
+ // attr,directive,event的id,exprssion需要合并
204
+ this.attrList.forEach((attr, index) => {
205
+ attr.deepPick(result.attrList[index], ['id', 'expression']);
206
+ });
207
+ this.directiveList.forEach((directive, index) => {
208
+ directive.deepPick(result.directiveList[index], ['id', 'expression']);
209
+ });
210
+ this.eventList.forEach((event, index) => {
211
+ event.deepPick(result.eventList[index], ['id']);
212
+ });
213
+ }
214
+
215
+ this.view && this.view.emit('change');
216
+
217
+ if (actionOptions?.loadHistory !== false) {
218
+ await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
219
+ operationAction: 'Element.create',
220
+ operationBeforeImage: null,
221
+ operationAfterImage: JSON.parse(JSON.stringify(this)),
222
+ operationDesc: `添加组件"${this.getElementTitle()}"`,
223
+ });
220
224
  config.defaultApp?.emit('saved');
221
- }
222
- return this;
225
+ }
226
+ return this;
223
227
  }
224
228
  /**
225
229
  * 删除元素
@@ -230,6 +234,7 @@ export class Element extends Vertex {
230
234
  const index = this.parent.children.indexOf(this);
231
235
  ~index && this.parent.children.splice(index, 1);
232
236
  this.view && this.view.emit('local-change');
237
+ this.view.removeComponentName(this.name);
233
238
  return this;
234
239
  }
235
240
 
@@ -240,16 +245,16 @@ export class Element extends Vertex {
240
245
 
241
246
  if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
242
247
  if (this.id) {
243
- await elementService.delete({
244
- headers: {
245
- appId: config.defaultApp?.id,
246
- operationAction: 'Element.delete',
247
- operationDesc: `删除组件"${this.getElementTitle()}"`,
248
- },
249
- query: {
250
- id: this.id,
251
- },
252
- }).catch(catchFn(this.view));
248
+ await elementService.delete({
249
+ headers: {
250
+ appId: config.defaultApp?.id,
251
+ operationAction: 'Element.delete',
252
+ operationDesc: `删除组件"${this.getElementTitle()}"`,
253
+ },
254
+ query: {
255
+ id: this.id,
256
+ },
257
+ }).catch(catchFn(this.view));
253
258
  }
254
259
  }
255
260
 
@@ -266,6 +271,8 @@ export class Element extends Vertex {
266
271
  });
267
272
  config.defaultApp?.emit('saved');
268
273
  }
274
+ // 递归删除组件名的缓存
275
+ this.deepRemoveComponentName();
269
276
  }
270
277
  /**
271
278
  * 修改元素
@@ -274,32 +281,32 @@ export class Element extends Vertex {
274
281
  config.defaultApp?.emit('saving');
275
282
 
276
283
  source && this.assign(source);
277
- if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
278
- const body = this.toPlainJSON();
279
- utils.logger.debug('修改组件', body);
280
- await elementService.update({
281
- headers: {
282
- appId: config.defaultApp?.id,
283
- operationAction: actionOptions?.actionName || 'Element.update',
284
- operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
285
- },
286
- body,
287
- }).catch(catchFn(this.view));
288
- }
284
+ if (actionOptions?.actionMode !== ACTION_MODE.undoRedo) {
285
+ const body = this.toPlainJSON();
286
+ utils.logger.debug('修改组件', body);
287
+ await elementService.update({
288
+ headers: {
289
+ appId: config.defaultApp?.id,
290
+ operationAction: actionOptions?.actionName || 'Element.update',
291
+ operationDesc: actionOptions?.actionDesc || `修改组件"${this.getElementTitle()}"`,
292
+ },
293
+ body,
294
+ }).catch(catchFn(this.view));
295
+ }
289
296
 
290
- this.view && this.view.emit('change');
291
- await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
292
- operationAction: 'Element.update',
293
- operationBeforeImage: null,
294
- operationAfterImage: null,
295
- operationDesc: `修改组件"${this.getElementTitle()}"`,
296
- });
297
+ this.view && this.view.emit('change');
298
+ await config.defaultApp?.history.load(actionOptions?.actionMode !== ACTION_MODE.undoRedo && {
299
+ operationAction: 'Element.update',
300
+ operationBeforeImage: null,
301
+ operationAfterImage: null,
302
+ operationDesc: `修改组件"${this.getElementTitle()}"`,
303
+ });
297
304
 
298
305
  config.defaultApp?.emit('saved');
299
306
  return this;
300
307
  }
301
308
 
302
- /**
309
+ /**
303
310
  * 按当前 id 加载逻辑数据
304
311
  */
305
312
  async load() {
@@ -379,6 +386,8 @@ export class Element extends Vertex {
379
386
 
380
387
  const index = this.parent.children.indexOf(this);
381
388
  const newNode = Element.fromHTML(code, this.parent, this.view);
389
+ // 复制的元素需重新命名
390
+ newNode.initComponentName();
382
391
 
383
392
  const mergeExpression = (originList: Array<Attr|Directive>, newList: Array<Attr|Directive>) => {
384
393
  newList.forEach((item) => {
@@ -436,7 +445,7 @@ export class Element extends Vertex {
436
445
  // 处理弹窗组件的命名问题
437
446
  if (newNode.tag === 'u-modal') {
438
447
  Object.assign(newNode, {
439
- name: utilsAll.unique('saveModal1', existingNames as any),
448
+ name: utils.unique('saveModal1', existingNames as any),
440
449
  });
441
450
  }
442
451
 
@@ -496,7 +505,7 @@ export class Element extends Vertex {
496
505
  await this.update(undefined, {
497
506
  actionDesc: `设置组件"${this.getElementTitle()}"的名称为"${name}"`,
498
507
  });
499
-
508
+
500
509
  if (!(window as any).globalData.hasUserCenter) {
501
510
  // 同步权限
502
511
  new Nuims({
@@ -844,6 +853,39 @@ export class Element extends Vertex {
844
853
  }
845
854
  }
846
855
  }
856
+
857
+ // 初始化组件名
858
+ public initComponentName() {
859
+ const name = this.genComponentName();
860
+ this.assign({ name });
861
+ this.view.addComponentName(name);
862
+ }
863
+
864
+ // 生成新的组件名
865
+ public genComponentName(): string {
866
+ const compNameSet = this.view.componentNameSet;
867
+ const tagName = this.tag.replace(Element.TAG_NAME_REG, '').replace(/-/g, '_');
868
+ const componentName = utils.unique(tagName + '1', compNameSet);
869
+ return componentName;
870
+ }
871
+
872
+ // 递归删除组件名的缓存
873
+ public deepRemoveComponentName(): void {
874
+ return this.traverseChildren((ele: Element) => {
875
+ this.view.removeComponentName(ele.name);
876
+ });
877
+ }
878
+
879
+ // 递归遍历组件
880
+ public traverseChildren(cb: (ele: Element) => void): void {
881
+ return (function loop(item: Element) {
882
+ cb(item);
883
+ if (item.children?.length) {
884
+ item.children.forEach(loop);
885
+ }
886
+ })(this);
887
+ }
888
+
847
889
  /**
848
890
  * 从 Vue 的 ASTNode 转换成 ASL 元素
849
891
  * @param astNode Vue 的 ASTNode
@@ -1322,6 +1364,10 @@ export class Element extends Vertex {
1322
1364
  const element = this.parse(html, context);
1323
1365
  utils.traverse((current) => {
1324
1366
  current.node.assign({ view, parent: current.parent });
1367
+ // 生成唯一组件名 依赖element.view
1368
+ if (!current.node.name) {
1369
+ current.node.initComponentName();
1370
+ }
1325
1371
  }, { node: element, parent });
1326
1372
  return element;
1327
1373
  }
@@ -1340,6 +1386,10 @@ export class Element extends Vertex {
1340
1386
  view,
1341
1387
  parent,
1342
1388
  });
1389
+ // // 生成唯一组件名 依赖element.view
1390
+ // if (!element.name) {
1391
+ // element.initComponentName();
1392
+ // }
1343
1393
 
1344
1394
  return element;
1345
1395
  }
@@ -1,6 +1,5 @@
1
-
2
1
  import { immutable, circular, action, excludedInJSON } from '../decorators';
3
- import { config, history, LEVEL_ENUM, Vertex, PackageJSON, App, Enum, Service, WebService, Structure, Page, Element, utils, ViewParam, ViewVariable, Lifecycle, genFinalCode, generator, Nuims, ActionOptions, ACTION_MODE, vertexsMap, updateDataTypeList, Interface, LogicItem } from '..';
2
+ import { config, history, LEVEL_ENUM, Vertex, PackageJSON, App, Enum, Service, WebService, Structure, Page, Element, utils, ViewParam, ViewVariable, Lifecycle, genFinalCode, generator, Nuims, ActionOptions, ACTION_MODE, vertexsMap, updateDataTypeList, Interface } from '..';
4
3
  import Block from './Block';
5
4
  import { viewService } from '../../service/page';
6
5
  import { Param } from '../logic/Param';
@@ -17,14 +16,6 @@ import * as babel from '@babel/core';
17
16
  import view from '@/service/page/view';
18
17
  import Entity from '../data/Entity';
19
18
  import { postServiceType } from '../../service/common/preprocess';
20
- export interface FrontEndsourceMap {
21
- [id: string]: {
22
- isLogic: boolean,
23
- node: LogicItem,
24
- from: number,
25
- to: number,
26
- }
27
- }
28
19
  import { catchFn } from './Page';
29
20
 
30
21
  /**
@@ -121,9 +112,6 @@ export class View extends Block {
121
112
  */
122
113
  @excludedInJSON()
123
114
  public contentPromise: Promise<any> = undefined;
124
-
125
- @excludedInJSON()
126
- public sourceMap: FrontEndsourceMap = {};
127
115
  /**
128
116
  * 输入参数
129
117
  */
@@ -140,6 +128,12 @@ export class View extends Block {
140
128
  */
141
129
  @immutable()
142
130
  public readonly moreChildrenFields: Array<string> = ['$def.params', '$def.variables', '$def.logics'];
131
+ /**
132
+ * 当前View中所有组件名的缓存
133
+ */
134
+ @immutable()
135
+ public readonly componentNameSet: Set<string> = new Set();
136
+
143
137
  /**
144
138
  * @param source 需要合并的部分参数
145
139
  */
@@ -208,7 +202,6 @@ export class View extends Block {
208
202
  // def 情况比较特殊,需要单独处理,防止逻辑重新加载
209
203
  this._syncDef($def);
210
204
  this.attachNodePath(true);
211
- this.toVueOptions();
212
205
  return this;
213
206
  } catch (err) { }
214
207
  })().finally(() => this.contentPromise = undefined);
@@ -219,30 +212,30 @@ export class View extends Block {
219
212
  return this.contentPromise;
220
213
 
221
214
  return this.contentPromise = (async () => {
222
- const result: View = await viewService.load({
223
- path: {
224
- id: this.id,
225
- },
226
- query: {
227
- enableCache,
228
- },
229
- config: { noErrorTip: true },
230
- });
231
- const oldLogics = this.$def.logics;
232
- Object.assign(result, {
233
- children: this.children,
234
- })
235
- const temp = View.from(result, this.parent, this.page, this);
236
- const newLogics = temp.$def.logics;
237
- oldLogics.forEach((logic) => {
238
- if(!newLogics.find((item) => item.id === logic.id))
239
- logic.destroy();
240
- });
241
- this.assign(temp);
242
- utils.traverse((current) => {
243
- current.node.attachNodePath(true);
244
- }, { node: this });
245
- return this;
215
+ const result: View = await viewService.load({
216
+ path: {
217
+ id: this.id,
218
+ },
219
+ query: {
220
+ enableCache,
221
+ },
222
+ config: { noErrorTip: true },
223
+ });
224
+ const oldLogics = this.$def.logics;
225
+ Object.assign(result, {
226
+ children: this.children,
227
+ });
228
+ const temp = View.from(result, this.parent, this.page, this);
229
+ const newLogics = temp.$def.logics;
230
+ oldLogics.forEach((logic) => {
231
+ if (!newLogics.find((item) => item.id === logic.id))
232
+ logic.destroy();
233
+ });
234
+ this.assign(temp);
235
+ utils.traverse((current) => {
236
+ current.node.attachNodePath(true);
237
+ }, { node: this });
238
+ return this;
246
239
  })().finally(() => this.contentPromise = undefined);
247
240
  }
248
241
  isContentLoaded() {
@@ -430,16 +423,16 @@ export class View extends Block {
430
423
  if (!this.parent)
431
424
  throw Error('该子页面为根节点!');
432
425
 
433
- await viewService.delete({
434
- headers: {
435
- appId: config.defaultApp?.id,
436
- operationAction: actionOptions?.actionName || 'View.delete',
437
- operationDesc: actionOptions?.actionDesc || `删除子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
438
- },
439
- path: {
440
- id: this.id,
441
- },
442
- }).catch(catchFn());
426
+ await viewService.delete({
427
+ headers: {
428
+ appId: config.defaultApp?.id,
429
+ operationAction: actionOptions?.actionName || 'View.delete',
430
+ operationDesc: actionOptions?.actionDesc || `删除子页面"${this.name}${this.title ? `(${this.title})` : ''}"`,
431
+ },
432
+ path: {
433
+ id: this.id,
434
+ },
435
+ }).catch(catchFn());
443
436
 
444
437
  const index = this.parent.children.indexOf(this);
445
438
  ~index && this.parent.children.splice(index, 1);
@@ -681,6 +674,7 @@ export class View extends Block {
681
674
  let componentOptions = 'const componentOptions = {};';
682
675
  if (this.script)
683
676
  componentOptions = this.script.trim().replace(/export default |module\.exports +=/, 'const componentOptions = ');
677
+
684
678
  const $def = JSON.parse(JSON.stringify(this.$def));
685
679
  $def.title = this.title;
686
680
  $def.crumb = this.crumb;
@@ -706,16 +700,10 @@ export class View extends Block {
706
700
  // );
707
701
  // }
708
702
  // }, { node: $def }, { mode: 'anyObject' });
709
- const {
710
- output,
711
- sourceMap,
712
- } = translator($def, this.script);
713
- return {
714
- script: `${componentOptions}${genFinalCode(output, options && options.finalCode)}
703
+ return `${componentOptions}
704
+ ${genFinalCode(translator($def), options && options.finalCode)}
715
705
  export default componentOptions;
716
- `,
717
- sourceMap,
718
- };
706
+ `;
719
707
  }
720
708
  /**
721
709
  * 转换成 Vue 文件
@@ -749,12 +737,9 @@ export class View extends Block {
749
737
  * @TODO 后面 template 可以优化成 render 函数
750
738
  */
751
739
  toVueOptions(options?: ElementToVueOptions) {
752
- const { script, sourceMap } = this.toScript(options);
753
- this.sourceMap = sourceMap;
754
740
  return {
755
741
  template: this.$html.toVue(options),
756
- script,
757
- sourceMap,
742
+ script: this.toScript(options),
758
743
  // definition: JSON.stringify(this.$def),
759
744
  };
760
745
  }
@@ -928,6 +913,39 @@ export class View extends Block {
928
913
  // config.defaultApp?.emit('saved');
929
914
  }
930
915
 
916
+ // 遍历页面缓存所有组件名
917
+ traverseAllComponentName(): void {
918
+ utils.traverse(({ node }) => {
919
+ node && this.componentNameSet.add(node.name);
920
+ }, { node: this.$html });
921
+ }
922
+
923
+ // 组件名是否有效
924
+ isValidComponentName(name: string): boolean {
925
+ if (name) {
926
+ return !this.componentNameSet.has(name);
927
+ }
928
+ return false;
929
+ }
930
+
931
+ // 保存组件名至缓存
932
+ addComponentName(nameOrElement: string | Element) {
933
+ let name: string = nameOrElement as string;
934
+ if (nameOrElement instanceof Element) {
935
+ name = nameOrElement.name;
936
+ }
937
+ return this.componentNameSet.add(name);
938
+ }
939
+
940
+ // 在缓存中移除组件名
941
+ removeComponentName(nameOrElement: string | Element): void {
942
+ let name: string = nameOrElement as string;
943
+ if (nameOrElement instanceof Element) {
944
+ name = nameOrElement.name;
945
+ }
946
+ this.componentNameSet.delete(name);
947
+ }
948
+
931
949
  _removeDef($def: View['$def']) {
932
950
  const removedParams = this.$def.params.filter((param) => $def.params?.find((item) => param.id === item.id));
933
951
  this.$def.params = this.$def.params.filter((param) => !$def.params?.find((item) => param.id === item.id));