@tmagic/editor 1.3.1 → 1.3.2

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 (51) hide show
  1. package/dist/style.css +50 -0
  2. package/dist/tmagic-editor.js +577 -574
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +586 -585
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +15 -13
  7. package/src/components/CodeBlockEditor.vue +6 -4
  8. package/src/fields/DataSourceSelect.vue +15 -9
  9. package/src/hooks/index.ts +1 -0
  10. package/src/hooks/use-code-block-edit.ts +2 -0
  11. package/src/hooks/use-float-box.ts +153 -0
  12. package/src/index.ts +1 -0
  13. package/src/initService.ts +12 -11
  14. package/src/layouts/Framework.vue +10 -1
  15. package/src/layouts/sidebar/Sidebar.vue +90 -5
  16. package/src/layouts/sidebar/code-block/CodeBlockList.vue +2 -1
  17. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +11 -10
  18. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +6 -4
  19. package/src/layouts/sidebar/data-source/DataSourceList.vue +9 -8
  20. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +15 -15
  21. package/src/layouts/sidebar/layer/use-drag.ts +4 -0
  22. package/src/layouts/sidebar/layer/use-node-status.ts +20 -15
  23. package/src/services/dataSource.ts +4 -0
  24. package/src/services/dep.ts +22 -284
  25. package/src/services/ui.ts +15 -0
  26. package/src/theme/code-block.scss +5 -0
  27. package/src/theme/floatbox.scss +48 -0
  28. package/src/theme/sidebar.scss +1 -0
  29. package/src/theme/theme.scss +1 -0
  30. package/src/type.ts +30 -20
  31. package/types/components/CodeBlockEditor.vue.d.ts +3 -0
  32. package/types/fields/DataSourceSelect.vue.d.ts +6 -4
  33. package/types/hooks/index.d.ts +1 -0
  34. package/types/hooks/use-code-block-edit.d.ts +26 -46
  35. package/types/hooks/use-data-source-method.d.ts +26 -46
  36. package/types/hooks/use-float-box.d.ts +15 -0
  37. package/types/index.d.ts +1 -0
  38. package/types/layouts/PropsPanel.vue.d.ts +92 -59
  39. package/types/layouts/sidebar/Sidebar.vue.d.ts +1 -2
  40. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -1
  41. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +3 -1
  42. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -0
  43. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +1 -1
  44. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +15 -2
  45. package/types/layouts/sidebar/layer/use-click.d.ts +7 -46
  46. package/types/services/dataSource.d.ts +10 -2
  47. package/types/services/dep.d.ts +12 -112
  48. package/types/services/ui.d.ts +8 -0
  49. package/types/type.d.ts +23 -18
  50. package/src/utils/dep.ts +0 -81
  51. package/types/utils/dep.d.ts +0 -6
@@ -5,53 +5,14 @@ export declare const useClick: (services: Services | undefined, isCtrlKeyDown: R
5
5
  menu: Ref<({
6
6
  $: import("vue").ComponentInternalInstance;
7
7
  $data: {};
8
- $props: {
9
- key?: string | number | symbol | undefined;
10
- ref?: import("vue").VNodeRef | undefined;
11
- ref_for?: boolean | undefined;
12
- ref_key?: string | undefined;
13
- onVnodeBeforeMount?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
14
- [key: string]: any;
15
- }>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
16
- [key: string]: any;
17
- }>) => void)[] | undefined;
18
- onVnodeMounted?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
19
- [key: string]: any;
20
- }>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
21
- [key: string]: any;
22
- }>) => void)[] | undefined;
23
- onVnodeBeforeUpdate?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
24
- [key: string]: any;
25
- }>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
26
- [key: string]: any;
27
- }>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
28
- [key: string]: any;
29
- }>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
30
- [key: string]: any;
31
- }>) => void)[] | undefined;
32
- onVnodeUpdated?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
33
- [key: string]: any;
34
- }>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
35
- [key: string]: any;
36
- }>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
37
- [key: string]: any;
38
- }>, oldVNode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
39
- [key: string]: any;
40
- }>) => void)[] | undefined;
41
- onVnodeBeforeUnmount?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
42
- [key: string]: any;
43
- }>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
44
- [key: string]: any;
45
- }>) => void)[] | undefined;
46
- onVnodeUnmounted?: ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
47
- [key: string]: any;
48
- }>) => void) | ((vnode: import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
49
- [key: string]: any;
50
- }>) => void)[] | undefined;
51
- class?: unknown;
52
- style?: unknown;
8
+ $props: Partial<{}> & Omit<{
53
9
  readonly layerContentMenu: (import("../../../type").MenuButton | import("../../../type").MenuComponent)[];
54
- };
10
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
11
+ layerContentMenu: {
12
+ type: import("vue").PropType<(import("../../../type").MenuButton | import("../../../type").MenuComponent)[]>;
13
+ required: true;
14
+ };
15
+ }>>, never>;
55
16
  $attrs: {
56
17
  [x: string]: unknown;
57
18
  };
@@ -25,8 +25,16 @@ declare class DataSource extends BaseService {
25
25
  setFormEvent(type: string, value?: EventOption[]): void;
26
26
  getFormMethod(type?: string): EventOption[];
27
27
  setFormMethod(type: string, value?: EventOption[]): void;
28
- add(config: DataSourceSchema): void;
29
- update(config: DataSourceSchema): void;
28
+ add(config: DataSourceSchema): {
29
+ id: string;
30
+ type: string;
31
+ title?: string | undefined;
32
+ description?: string | undefined;
33
+ fields: import("@tmagic/schema").DataSchema[];
34
+ methods: import("@tmagic/schema").CodeBlockContent[];
35
+ mocks?: import("@tmagic/schema").MockSchema[] | undefined;
36
+ };
37
+ update(config: DataSourceSchema): DataSourceSchema;
30
38
  remove(id: string): void;
31
39
  getDataSourceById(id: string): DataSourceSchema | undefined;
32
40
  resetState(): void;
@@ -1,121 +1,21 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import type { Dep, MNode } from '@tmagic/schema';
4
- import { DepTargetType } from '../type';
5
- type IsTarget = (key: string | number, value: any) => boolean;
6
- interface TargetOptions {
7
- isTarget: IsTarget;
8
- id: string | number;
9
- /** 类型,数据源、代码块或其他 */
10
- type?: DepTargetType | string;
11
- name?: string;
12
- }
13
- /**
14
- * 需要收集依赖的目标
15
- * 例如:一个代码块可以为一个目标
16
- */
17
- export declare class Target extends EventEmitter {
18
- /**
19
- * 如何识别目标
20
- */
21
- isTarget: IsTarget;
22
- /**
23
- * 目标id,不可重复
24
- * 例如目标是代码块,则为代码块id
25
- */
26
- id: string | number;
27
- /**
28
- * 目标名称,用于显示在依赖列表中
29
- */
30
- name?: string;
31
- /**
32
- * 不同的目标可以进行分类,例如代码块,数据源可以为两个不同的type
33
- */
34
- type: DepTargetType | string;
35
- /**
36
- * 依赖详情
37
- * 实例:{ 'node_id': { name: 'node_name', keys: [ created, mounted ] } }
38
- */
39
- deps: Dep;
40
- constructor(options: TargetOptions);
41
- /**
42
- * 更新依赖
43
- * @param node 节点配置
44
- * @param key 哪个key配置了这个目标的id
45
- */
46
- updateDep(node: MNode, key: string | number): void;
47
- /**
48
- * 删除依赖
49
- * @param node 哪个节点的依赖需要移除,如果为空,则移除所有依赖
50
- * @param key 节点下哪个key需要移除,如果为空,则移除改节点下的所有依赖key
51
- * @returns void
52
- */
53
- removeDep(node?: MNode, key?: string | number): void;
54
- /**
55
- * 判断指定节点下的指定key是否存在在依赖列表中
56
- * @param node 哪个节点
57
- * @param key 哪个key
58
- * @returns boolean
59
- */
60
- hasDep(node: MNode, key: string | number): boolean;
61
- destroy(): void;
62
- }
63
- export declare class Watcher extends EventEmitter {
64
- private targets;
65
- /**
66
- * 获取指定类型中的所有target
67
- * @param type 分类
68
- * @returns Target[]
69
- */
70
- getTargets(type?: DepTargetType | string): {
1
+ import { type Target } from '@tmagic/dep';
2
+ import type { Id, MNode } from '@tmagic/schema';
3
+ import BaseService from './BaseService';
4
+ declare class Dep extends BaseService {
5
+ private watcher;
6
+ removeTargets(type?: string): void;
7
+ getTargets(type?: string): {
71
8
  [targetId: string]: Target;
72
9
  [targetId: number]: Target;
73
10
  };
74
- /**
75
- * 添加新的目标
76
- * @param target Target
77
- */
11
+ getTarget(id: Id): Target | undefined;
78
12
  addTarget(target: Target): void;
79
- /**
80
- * 获取指定id的target
81
- * @param id target id
82
- * @returns Target
83
- */
84
- getTarget(id: string | number): Target | undefined;
85
- /**
86
- * 判断是否存在指定id的target
87
- * @param id target id
88
- * @returns boolean
89
- */
90
- hasTarget(id: string | number): boolean;
91
- /**
92
- * 删除指定id的target
93
- * @param id target id
94
- */
95
- removeTarget(id: string | number): void;
96
- /**
97
- * 删除指定分类的所有target
98
- * @param type 分类
99
- * @returns void
100
- */
101
- removeTargets(type?: DepTargetType | string): void;
102
- /**
103
- * 删除所有target
104
- */
13
+ removeTarget(id: Id): void;
105
14
  clearTargets(): void;
106
- /**
107
- * 收集依赖
108
- * @param nodes 需要收集的节点
109
- * @param deep 是否需要收集子节点
110
- */
111
15
  collect(nodes: MNode[], deep?: boolean): void;
112
- /**
113
- * 清除依赖
114
- * @param nodes 需要清除依赖的节点
115
- */
116
16
  clear(nodes?: MNode[]): void;
117
- private collectItem;
17
+ hasTarget(id: Id): boolean;
118
18
  }
119
- export type DepService = Watcher;
120
- declare const _default: Watcher;
19
+ export type DepService = Dep;
20
+ declare const _default: Dep;
121
21
  export default _default;
@@ -24,9 +24,17 @@ declare class Ui extends BaseService {
24
24
  showRule: boolean;
25
25
  propsPanelSize: "default" | "small" | "large";
26
26
  showAddPageButton: boolean;
27
+ floatBox: Map<string, {
28
+ status: boolean;
29
+ zIndex: number;
30
+ top: number;
31
+ left: number;
32
+ }>;
33
+ hideSlideBar: boolean;
27
34
  }[K];
28
35
  zoom(zoom: number): Promise<void>;
29
36
  calcZoom(): Promise<number>;
37
+ setFloatBox(keys: string[]): Promise<void>;
30
38
  resetState(): void;
31
39
  destroy(): void;
32
40
  private setStageRect;
package/types/type.d.ts CHANGED
@@ -167,6 +167,15 @@ export interface UiState {
167
167
  propsPanelSize: 'large' | 'default' | 'small';
168
168
  /** 是否显示新增页面按钮 */
169
169
  showAddPageButton: boolean;
170
+ /** slide 拖拽悬浮窗 state */
171
+ floatBox: Map<string, {
172
+ status: boolean;
173
+ zIndex: number;
174
+ top: number;
175
+ left: number;
176
+ }>;
177
+ /** 是否隐藏侧边栏 */
178
+ hideSlideBar: boolean;
170
179
  }
171
180
  export interface EditorNodeInfo {
172
181
  node: MNode | null;
@@ -265,6 +274,15 @@ export interface SideComponent extends MenuComponent {
265
274
  text: string;
266
275
  /** vue组件或url */
267
276
  icon: Component<{}, {}, any>;
277
+ /** slide 唯一标识 key */
278
+ $key: string;
279
+ /** 组件扩展参数 */
280
+ boxComponentConfig?: {
281
+ /** Vue3组件 */
282
+ component?: any;
283
+ /** 传入组件的props对象 */
284
+ props?: Record<string, any>;
285
+ };
268
286
  }
269
287
  /**
270
288
  * component-list: 组件列表
@@ -281,6 +299,11 @@ export interface SideBarData {
281
299
  /** panel列表 */
282
300
  items: SideItem[];
283
301
  }
302
+ /**
303
+ * drawer 抽屉
304
+ * box 悬浮窗
305
+ */
306
+ export type SlideType = 'drawer' | 'box';
284
307
  export interface ComponentItem {
285
308
  /** 显示文案 */
286
309
  text: string;
@@ -338,12 +361,6 @@ export type CodeState = {
338
361
  undeletableList: Id[];
339
362
  paramsColConfig?: ColumnConfig;
340
363
  };
341
- export type HookData = {
342
- /** 代码块id */
343
- codeId: Id;
344
- /** 参数 */
345
- params?: object;
346
- };
347
364
  export type CodeRelation = {
348
365
  /** 组件id:[代码id1,代码id2] */
349
366
  [compId: Id]: Id[];
@@ -489,18 +506,6 @@ export interface DataSourceFieldSelectConfig {
489
506
  disabled?: boolean | FilterFunction;
490
507
  display?: boolean | FilterFunction;
491
508
  }
492
- /** 依赖收集的目标类型 */
493
- export declare enum DepTargetType {
494
- DEFAULT = "default",
495
- /** 代码块 */
496
- CODE_BLOCK = "code-block",
497
- /** 数据源 */
498
- DATA_SOURCE = "data-source",
499
- /** 数据源方法 */
500
- DATA_SOURCE_METHOD = "data-source-method",
501
- /** 数据源条件 */
502
- DATA_SOURCE_COND = "data-source-cond"
503
- }
504
509
  /** 可新增的数据源类型选项 */
505
510
  export interface DatasourceTypeOption {
506
511
  /** 数据源类型 */
package/src/utils/dep.ts DELETED
@@ -1,81 +0,0 @@
1
- import { isEmpty } from 'lodash-es';
2
-
3
- import { type CodeBlockContent, HookType, type Id } from '@tmagic/schema';
4
- import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
5
-
6
- import dataSourceService from '@editor/services/dataSource';
7
- import { Target } from '@editor/services/dep';
8
- import { DepTargetType, type HookData } from '@editor/type';
9
-
10
- export const createCodeBlockTarget = (id: Id, codeBlock: CodeBlockContent) =>
11
- new Target({
12
- type: DepTargetType.CODE_BLOCK,
13
- id,
14
- name: codeBlock.name,
15
- isTarget: (key: string | number, value: any) => {
16
- if (id === value) {
17
- return true;
18
- }
19
-
20
- if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
21
- const index = value.hookData.findIndex((item: HookData) => item.codeId === id);
22
- return Boolean(index > -1);
23
- }
24
-
25
- return false;
26
- },
27
- });
28
-
29
- export const createDataSourceTarget = (id: Id) =>
30
- new Target({
31
- type: DepTargetType.DATA_SOURCE,
32
- id,
33
- isTarget: (key: string | number, value: any) => {
34
- // 关联数据源对象或者在模板在使用数据源
35
- if ((value?.isBindDataSource && value.dataSourceId) || (typeof value === 'string' && value.includes(`${id}`))) {
36
- return true;
37
- }
38
-
39
- // 关联数据源字段,格式为 [前缀+数据源ID, 字段名]
40
- if (!Array.isArray(value) || typeof value[0] !== 'string') {
41
- return false;
42
- }
43
-
44
- const [prefixId] = value;
45
- const prefixIndex = prefixId.indexOf(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);
46
-
47
- if (prefixIndex === -1) {
48
- return false;
49
- }
50
-
51
- const dsId = prefixId.substring(prefixIndex + DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX.length);
52
-
53
- return dsId === id && Boolean(dataSourceService.getDataSourceById(id));
54
- },
55
- });
56
-
57
- export const createDataSourceCondTarget = (id: string) =>
58
- new Target({
59
- type: DepTargetType.DATA_SOURCE_COND,
60
- id,
61
- isTarget: (key: string | number, value: any) => {
62
- if (!Array.isArray(value) || value[0] !== id || !`${key}`.startsWith('displayConds')) return false;
63
-
64
- const ds = dataSourceService.getDataSourceById(id);
65
-
66
- return Boolean(ds?.fields?.find((field) => field.name === value[1]));
67
- },
68
- });
69
-
70
- export const createDataSourceMethodTarget = (id: string) =>
71
- new Target({
72
- type: DepTargetType.DATA_SOURCE_METHOD,
73
- id,
74
- isTarget: (key: string | number, value: any) => {
75
- if (!Array.isArray(value) || value[0] !== id) return false;
76
-
77
- const ds = dataSourceService.getDataSourceById(id);
78
-
79
- return Boolean(ds?.methods?.find((method) => method.name === value[1]));
80
- },
81
- });
@@ -1,6 +0,0 @@
1
- import { type CodeBlockContent, type Id } from '@tmagic/schema';
2
- import { Target } from '../services/dep';
3
- export declare const createCodeBlockTarget: (id: Id, codeBlock: CodeBlockContent) => Target;
4
- export declare const createDataSourceTarget: (id: Id) => Target;
5
- export declare const createDataSourceCondTarget: (id: string) => Target;
6
- export declare const createDataSourceMethodTarget: (id: string) => Target;