@tmagic/editor 1.1.6 → 1.2.0-beta.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.
@@ -0,0 +1,155 @@
1
+ import { Id, MNode } from '@tmagic/schema';
2
+ import type { CodeBlockContent, CodeBlockDSL } from '../type';
3
+ import { CodeEditorMode, CodeSelectOp } from '../type';
4
+ import BaseService from './BaseService';
5
+ declare class CodeBlock extends BaseService {
6
+ private state;
7
+ constructor();
8
+ /**
9
+ * 设置活动的代码块dsl数据源
10
+ * @param {CodeBlockDSL} codeDsl 代码DSL
11
+ * @returns {void}
12
+ */
13
+ setCodeDsl(codeDsl: CodeBlockDSL): Promise<void>;
14
+ /**
15
+ * 获取活动的代码块dsl数据源(默认从dsl中的codeBlock字段读取)
16
+ * @param {boolean} forceRefresh 是否强制从活动dsl拉取刷新
17
+ * @returns {CodeBlockDSL | null}
18
+ */
19
+ getCodeDsl(forceRefresh?: boolean): Promise<CodeBlockDSL | null>;
20
+ /**
21
+ * 根据代码块id获取代码块内容
22
+ * @param {string} id 代码块id
23
+ * @returns {CodeBlockContent | null}
24
+ */
25
+ getCodeContentById(id: string): Promise<CodeBlockContent | null>;
26
+ /**
27
+ * 设置代码块ID和代码内容到源dsl
28
+ * @param {string} id 代码块id
29
+ * @param {CodeBlockContent} codeConfig 代码块内容配置信息
30
+ * @returns {void}
31
+ */
32
+ setCodeDslById(id: string, codeConfig: CodeBlockContent): Promise<void>;
33
+ /**
34
+ * 根据代码块id数组获取代码dsl
35
+ * @param {string[]} ids 代码块id数组
36
+ * @returns {CodeBlockDSL}
37
+ */
38
+ getCodeDslByIds(ids: string[]): Promise<CodeBlockDSL>;
39
+ /**
40
+ * 设置代码编辑面板展示状态
41
+ * @param {boolean} status 是否展示代码编辑面板
42
+ * @returns {void}
43
+ */
44
+ setCodeEditorShowStatus(status: boolean): Promise<void>;
45
+ /**
46
+ * 获取代码编辑面板展示状态
47
+ * @returns {boolean} 是否展示代码编辑面板
48
+ */
49
+ getCodeEditorShowStatus(): boolean;
50
+ /**
51
+ * 设置代码编辑面板展示状态及展示内容
52
+ * @param {boolean} status 是否展示代码编辑面板
53
+ * @param {string} id 代码块id
54
+ * @returns {void}
55
+ */
56
+ setCodeEditorContent(status: boolean, id: string): void;
57
+ /**
58
+ * 获取当前选中的代码块内容
59
+ * @returns {CodeBlockContent | null}
60
+ */
61
+ getCurrentDsl(): Promise<CodeBlockContent | null>;
62
+ /**
63
+ * 获取编辑状态
64
+ * @returns {boolean} 是否可编辑
65
+ */
66
+ getEditStatus(): boolean;
67
+ /**
68
+ * 设置编辑状态
69
+ * @param {boolean} 是否可编辑
70
+ * @returns {void}
71
+ */
72
+ setEditStatus(status: boolean): Promise<void>;
73
+ /**
74
+ * 设置当前选中的代码块ID
75
+ * @param {string} id 代码块id
76
+ * @returns {void}
77
+ */
78
+ setId(id: string): void;
79
+ /**
80
+ * 获取当前选中的代码块ID
81
+ * @returns {string} id 代码块id
82
+ */
83
+ getId(): string;
84
+ /**
85
+ * 获取当前模式
86
+ * @returns {CodeEditorMode}
87
+ */
88
+ getMode(): CodeEditorMode;
89
+ /**
90
+ * 设置当前模式
91
+ * @param {CodeEditorMode} mode 模式
92
+ * @returns {void}
93
+ */
94
+ setMode(mode: CodeEditorMode): Promise<void>;
95
+ /**
96
+ * 设置当前选中组件已关联绑定的代码块id数组
97
+ * @param {string[]} ids 代码块id数组
98
+ * @returns {void}
99
+ */
100
+ setCombineIds(ids: string[]): Promise<void>;
101
+ /**
102
+ * 获取当前选中组件已关联绑定的代码块id数组
103
+ * @returns {string[]}
104
+ */
105
+ getCombineIds(): string[];
106
+ /**
107
+ * 设置绑定关系
108
+ * @param {Id} 组件id
109
+ * @param {string[]} diffCodeIds 代码块id数组
110
+ * @param {CodeSelectOp} opFlag 操作类型
111
+ * @param {string} hook 代码块挂载hook名称
112
+ * @returns {void}
113
+ */
114
+ setCombineRelation(compId: Id, diffCodeIds: string[], opFlag: CodeSelectOp, hook: string): Promise<void>;
115
+ /**
116
+ * 获取不可删除列表
117
+ * @returns {string[]}
118
+ */
119
+ getUndeletableList(): string[];
120
+ /**
121
+ * 设置不可删除列表:为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除)
122
+ * @param {string[]} codeIds 代码块id数组
123
+ * @returns {void}
124
+ */
125
+ setUndeleteableList(codeIds: string[]): Promise<void>;
126
+ /**
127
+ * 在dsl数据源中删除指定id的代码块
128
+ * @param {string[]} codeIds 需要删除的代码块id数组
129
+ * @returns {CodeBlockDSL} 删除后的code dsl
130
+ */
131
+ deleteCodeDslByIds(codeIds: string[]): Promise<CodeBlockDSL>;
132
+ /**
133
+ * 生成代码块唯一id
134
+ * @returns {string} 代码块唯一id
135
+ */
136
+ getUniqueId(): Promise<string>;
137
+ /**
138
+ * 一对一解除绑定关系 功能隐藏,暂时注释
139
+ * @param {string} compId 组件id
140
+ * @param {string} codeId 代码块id
141
+ * @param {string[]} codeHooks 代码块挂载hook名称
142
+ * @returns {boolean} 结果
143
+ */
144
+ /**
145
+ * 通过组件id解除绑定关系(删除组件)
146
+ * @param {MNode} compId 组件节点
147
+ * @returns void
148
+ */
149
+ deleteCompsInRelation(node: MNode): Promise<void>;
150
+ destroy(): void;
151
+ private recurseNodes;
152
+ }
153
+ export declare type CodeBlockService = CodeBlock;
154
+ declare const _default: CodeBlock;
155
+ export default _default;
@@ -1,4 +1,4 @@
1
- import type { Id, MContainer, MNode } from '@tmagic/schema';
1
+ import type { CodeBlockDSL, Id, MContainer, MNode } from '@tmagic/schema';
2
2
  import { StepValue } from '../services/history';
3
3
  import type { AddMNode, EditorNodeInfo, PastePosition, StoreState } from '../type';
4
4
  import { LayerOffset, Layout } from '../type';
@@ -138,6 +138,17 @@ declare class Editor extends BaseService {
138
138
  move(left: number, top: number): Promise<void>;
139
139
  destroy(): void;
140
140
  resetModifiedNodeId(): void;
141
+ /**
142
+ * 从dsl中的codeBlock字段读取活动的代码块
143
+ * @returns {CodeBlockDSL | null}
144
+ */
145
+ getCodeDsl(): Promise<CodeBlockDSL | null>;
146
+ /**
147
+ * 设置代码块到dsl的codeBlock字段
148
+ * @param {CodeBlockDSL} codeDsl 代码DSL
149
+ * @returns {void}
150
+ */
151
+ setCodeDsl(codeDsl: CodeBlockDSL): Promise<void>;
141
152
  private addModifiedNodeId;
142
153
  private pushHistoryState;
143
154
  private changeHistoryState;
@@ -13,6 +13,7 @@ declare class Props extends BaseService {
13
13
  items: (import("@tmagic/form").ChildConfig & {
14
14
  [key: string]: any;
15
15
  })[];
16
+ lazy?: undefined;
16
17
  } | {
17
18
  title: string;
18
19
  items: {
@@ -34,6 +35,17 @@ declare class Props extends BaseService {
34
35
  })[];
35
36
  }[];
36
37
  labelWidth?: undefined;
38
+ lazy?: undefined;
39
+ } | {
40
+ title: string;
41
+ lazy: boolean;
42
+ items: {
43
+ name: string;
44
+ text: string;
45
+ type: string;
46
+ labelWidth: string;
47
+ }[];
48
+ labelWidth?: undefined;
37
49
  })[];
38
50
  }[]>;
39
51
  /**
package/types/type.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { FormConfig } from '@tmagic/form';
3
3
  import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
4
  import type StageCore from '@tmagic/stage';
5
5
  import type { ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
6
+ import type { CodeBlockService } from './services/codeBlock';
6
7
  import type { ComponentListService } from './services/componentList';
7
8
  import type { EditorService } from './services/editor';
8
9
  import type { EventsService } from './services/events';
@@ -23,6 +24,7 @@ export interface Services {
23
24
  propsService: PropsService;
24
25
  componentListService: ComponentListService;
25
26
  uiService: UiService;
27
+ codeBlockService: CodeBlockService;
26
28
  }
27
29
  export interface StageOptions {
28
30
  runtimeUrl: string;
@@ -190,7 +192,7 @@ export interface SideComponent extends MenuComponent {
190
192
  * component-list: 组件列表
191
193
  * layer: 已选组件树
192
194
  */
193
- export declare type SideItem = 'component-list' | 'layer' | SideComponent;
195
+ export declare type SideItem = 'component-list' | 'layer' | 'code-block' | SideComponent;
194
196
  /** 工具栏 */
195
197
  export interface SideBarData {
196
198
  /** 容器类型 */
@@ -243,3 +245,77 @@ export interface ScrollViewerEvent {
243
245
  scrollHeight: number;
244
246
  scrollWidth: number;
245
247
  }
248
+ export interface CodeBlockDSL {
249
+ [id: string]: CodeBlockContent;
250
+ }
251
+ export interface CodeBlockContent {
252
+ /** 代码块名称 */
253
+ name: string;
254
+ /** 代码块内容 */
255
+ content: string;
256
+ /** 代码块与组件的绑定关系 */
257
+ comps?: CodeRelation;
258
+ /** 扩展字段 */
259
+ [propName: string]: any;
260
+ }
261
+ export declare type CodeState = {
262
+ /** 是否展示代码块编辑区 */
263
+ isShowCodeEditor: boolean;
264
+ /** 代码块DSL数据源 */
265
+ codeDsl: CodeBlockDSL | null;
266
+ /** 当前选中的代码块id */
267
+ id: string;
268
+ /** 代码块是否可编辑 */
269
+ editable: boolean;
270
+ /** 代码编辑面板的展示模式 */
271
+ mode: CodeEditorMode;
272
+ /** list模式下左侧展示的代码列表 */
273
+ combineIds: string[];
274
+ /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
275
+ undeletableList: string[];
276
+ };
277
+ export declare type CodeRelation = {
278
+ /** 组件id:['created'] */
279
+ [compId: string | number]: string[];
280
+ };
281
+ export declare enum CodeEditorMode {
282
+ /** 左侧菜单,右侧代码 */
283
+ LIST = "list",
284
+ /** 全屏代码 */
285
+ EDITOR = "editor"
286
+ }
287
+ export interface CodeDslList {
288
+ /** 代码块id */
289
+ id: string;
290
+ /** 代码块名称 */
291
+ name: string;
292
+ /** 代码块函数内容 */
293
+ content: any;
294
+ /** 是否展示代码绑定关系 */
295
+ showRelation?: boolean;
296
+ }
297
+ export interface ListState {
298
+ /** 代码块列表 */
299
+ codeList: CodeDslList[];
300
+ }
301
+ export interface ListRelationState extends ListState {
302
+ /** 与代码块绑定的组件id信息 */
303
+ bindComps: {
304
+ /** 代码块id : 组件信息 */
305
+ [id: string]: MNode[];
306
+ };
307
+ }
308
+ export declare enum CodeDeleteErrorType {
309
+ /** 代码块存在于不可删除列表中 */
310
+ UNDELETEABLE = "undeleteable",
311
+ /** 代码块存在绑定关系 */
312
+ BIND = "bind"
313
+ }
314
+ export declare enum CodeSelectOp {
315
+ /** 增加 */
316
+ ADD = "add",
317
+ /** 删除 */
318
+ DELETE = "delete",
319
+ /** 单选修改 */
320
+ CHANGE = "change"
321
+ }
@@ -12,6 +12,7 @@ export declare const fillConfig: (config?: FormConfig) => {
12
12
  items: (import("@tmagic/form").ChildConfig & {
13
13
  [key: string]: any;
14
14
  })[];
15
+ lazy?: undefined;
15
16
  } | {
16
17
  title: string;
17
18
  items: {
@@ -33,5 +34,16 @@ export declare const fillConfig: (config?: FormConfig) => {
33
34
  })[];
34
35
  }[];
35
36
  labelWidth?: undefined;
37
+ lazy?: undefined;
38
+ } | {
39
+ title: string;
40
+ lazy: boolean;
41
+ items: {
42
+ name: string;
43
+ text: string;
44
+ type: string;
45
+ labelWidth: string;
46
+ }[];
47
+ labelWidth?: undefined;
36
48
  })[];
37
49
  }[];