@tmagic/editor 1.3.11 → 1.3.13

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.
@@ -32,7 +32,7 @@
32
32
  top: 0;
33
33
  width: 100%;
34
34
  height: 100%;
35
- background-color: rgba(0, 0, 0, 0.6);
35
+ background-color: #fff;
36
36
  display: flex;
37
37
  z-index: 20;
38
38
  overflow: auto;
@@ -42,11 +42,12 @@
42
42
  position: relative;
43
43
  flex-shrink: 0;
44
44
  margin: auto;
45
+ box-shadow: rgba(0, 0, 0, 0.04) 0px 3px 5px;
45
46
  }
46
47
 
47
48
  .m-editor-stage-overlay-close.tmagic-design-icon {
48
49
  position: fixed;
49
- right: 10px;
50
+ right: 20px;
50
51
  top: 10px;
51
52
  }
52
53
 
package/src/type.ts CHANGED
@@ -39,6 +39,7 @@ import type { EventsService } from './services/events';
39
39
  import type { HistoryService } from './services/history';
40
40
  import type { KeybindingService } from './services/keybinding';
41
41
  import type { PropsService } from './services/props';
42
+ import type { StageOverlayService } from './services/stageOverlay';
42
43
  import type { StorageService } from './services/storage';
43
44
  import type { UiService } from './services/ui';
44
45
  import type { UndoRedo } from './utils/undo-redo';
@@ -118,22 +119,23 @@ export interface Services {
118
119
  depService: DepService;
119
120
  dataSourceService: DataSourceService;
120
121
  keybindingService: KeybindingService;
122
+ stageOverlayService: StageOverlayService;
121
123
  }
122
124
 
123
125
  export interface StageOptions {
124
- runtimeUrl: string;
125
- autoScrollIntoView: boolean;
126
- containerHighlightClassName: string;
127
- containerHighlightDuration: number;
128
- containerHighlightType: ContainerHighlightType;
126
+ runtimeUrl?: string;
127
+ autoScrollIntoView?: boolean;
128
+ containerHighlightClassName?: string;
129
+ containerHighlightDuration?: number;
130
+ containerHighlightType?: ContainerHighlightType;
129
131
  disabledDragStart?: boolean;
130
- render: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
131
- moveableOptions: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
132
- canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
133
- isContainer: (el: HTMLElement) => boolean | Promise<boolean>;
134
- updateDragEl: UpdateDragEl;
135
- renderType: RenderType;
136
- guidesOptions: Partial<GuidesOptions>;
132
+ render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
133
+ moveableOptions?: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
134
+ canSelect?: (el: HTMLElement) => boolean | Promise<boolean>;
135
+ isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
136
+ updateDragEl?: UpdateDragEl;
137
+ renderType?: RenderType;
138
+ guidesOptions?: Partial<GuidesOptions>;
137
139
  disabledMultiSelect?: boolean;
138
140
  }
139
141
 
@@ -160,6 +162,17 @@ export interface PropsState {
160
162
  relateIdMap: Record<Id, Id>;
161
163
  }
162
164
 
165
+ export interface StageOverlayState {
166
+ wrapDiv: HTMLDivElement;
167
+ sourceEl: HTMLElement | null;
168
+ contentEl: HTMLElement | null;
169
+ stage: StageCore | null;
170
+ stageOptions: StageOptions | null;
171
+ wrapWidth: number;
172
+ wrapHeight: number;
173
+ stageOverlayVisible: boolean;
174
+ }
175
+
163
176
  export interface ComponentGroupState {
164
177
  list: ComponentGroup[];
165
178
  }
@@ -19,8 +19,6 @@ export interface EditorProps {
19
19
  layerContentMenu?: (MenuButton | MenuComponent)[];
20
20
  /** 画布右键菜单 */
21
21
  stageContentMenu?: (MenuButton | MenuComponent)[];
22
- /** 中间工作区域中画布渲染的内容 */
23
- render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
24
22
  /** 中间工作区域中画布通过iframe渲染时的页面url */
25
23
  runtimeUrl?: string;
26
24
  /** 是用iframe渲染还是直接渲染 */
@@ -48,18 +46,20 @@ export interface EditorProps {
48
46
  moveableOptions?: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
49
47
  /** 编辑器初始化时默认选中的组件ID */
50
48
  defaultSelected?: Id;
51
- canSelect?: (el: HTMLElement) => boolean | Promise<boolean>;
52
- isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
49
+ /** 拖入画布中容器时,识别到容器后给容器根dom加上的class */
53
50
  containerHighlightClassName?: string;
51
+ /** 拖入画布中容器时,悬停识别容器的时间 */
54
52
  containerHighlightDuration?: number;
53
+ /** 拖入画布中容器时,识别容器的操作类型 */
55
54
  containerHighlightType?: ContainerHighlightType;
55
+ /** 画布大小 */
56
56
  stageRect?: StageRect;
57
+ /** monaco editor 的配置 */
57
58
  codeOptions?: {
58
59
  [key: string]: any;
59
60
  };
60
- updateDragEl?: UpdateDragEl;
61
+ /** 禁用鼠标左键按下时就开始拖拽,需要先选中再可以拖拽 */
61
62
  disabledDragStart?: boolean;
62
- extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
63
63
  /** 自定义依赖收集器,复制组件时会将关联依赖一并复制 */
64
64
  collectorOptions?: CustomTargetOptions;
65
65
  /** 标尺配置 */
@@ -68,9 +68,28 @@ export interface EditorProps {
68
68
  disabledMultiSelect?: boolean;
69
69
  /** 禁用页面片 */
70
70
  disabledPageFragment?: boolean;
71
+ /** 禁用双击在浮层中单独编辑选中组件 */
72
+ disabledStageOverlay?: boolean;
73
+ /** 中间工作区域中画布渲染的内容 */
74
+ render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
75
+ /** 选中时会在画布上复制出一个大小相同的dom,实际拖拽的是这个dom,此方法用于干预这个dom的生成方式 */
76
+ updateDragEl?: UpdateDragEl;
77
+ /** 用于设置画布上的dom是否可以被选中 */
78
+ canSelect?: (el: HTMLElement) => boolean | Promise<boolean>;
79
+ /** 用于设置画布上的dom是否可以被拖入其中 */
80
+ isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
81
+ /** 用于自定义组件树与画布的右键菜单 */
71
82
  customContentMenu?: (menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[];
83
+ extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
72
84
  }
73
85
  export declare const defaultEditorProps: {
86
+ renderType: RenderType;
87
+ disabledMultiSelect: boolean;
88
+ disabledPageFragment: boolean;
89
+ disabledStageOverlay: boolean;
90
+ containerHighlightClassName: string;
91
+ containerHighlightDuration: number;
92
+ containerHighlightType: ContainerHighlightType;
74
93
  componentGroupList: () => never[];
75
94
  datasourceList: () => never[];
76
95
  menu: () => {
@@ -86,11 +105,5 @@ export declare const defaultEditorProps: {
86
105
  datasourceConfigs: () => {};
87
106
  canSelect: (el: HTMLElement) => boolean;
88
107
  isContainer: (el: HTMLElement) => boolean;
89
- containerHighlightClassName: string;
90
- containerHighlightDuration: number;
91
- containerHighlightType: ContainerHighlightType;
92
108
  codeOptions: () => {};
93
- renderType: RenderType;
94
- disabledMultiSelect: boolean;
95
- disabledPageFragment: boolean;
96
109
  };
package/types/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export { default as historyService } from './services/history';
15
15
  export { default as storageService } from './services/storage';
16
16
  export { default as eventsService } from './services/events';
17
17
  export { default as dataSourceService } from './services/dataSource';
18
+ export { default as stageOverlayService } from './services/stageOverlay';
18
19
  export { default as uiService } from './services/ui';
19
20
  export { default as codeBlockService } from './services/codeBlock';
20
21
  export { default as depService } from './services/dep';
@@ -1,11 +1,19 @@
1
1
  import type { MenuButton, MenuComponent, WorkspaceSlots } from '../../type';
2
- declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<{
2
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
3
3
  stageContentMenu: (MenuButton | MenuComponent)[];
4
+ disabledStageOverlay?: boolean | undefined;
4
5
  customContentMenu?: ((menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[]) | undefined;
5
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
6
+ }>, {
7
+ disabledStageOverlay: boolean;
8
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
6
9
  stageContentMenu: (MenuButton | MenuComponent)[];
10
+ disabledStageOverlay?: boolean | undefined;
7
11
  customContentMenu?: ((menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[]) | undefined;
8
- }>>>, {}, {}>, Readonly<WorkspaceSlots>>;
12
+ }>, {
13
+ disabledStageOverlay: boolean;
14
+ }>>>, {
15
+ disabledStageOverlay: boolean;
16
+ }, {}>, Readonly<WorkspaceSlots>>;
9
17
  export default _default;
10
18
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
11
19
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -16,6 +24,14 @@ type __VLS_TypePropsToRuntimeProps<T> = {
16
24
  required: true;
17
25
  };
18
26
  };
27
+ type __VLS_WithDefaults<P, D> = {
28
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
29
+ default: D[K];
30
+ }> : P[K];
31
+ };
32
+ type __VLS_Prettify<T> = {
33
+ [K in keyof T]: T[K];
34
+ } & {};
19
35
  type __VLS_WithTemplateSlots<T, S> = T & {
20
36
  new (): {
21
37
  $slots: S;
@@ -1,11 +1,19 @@
1
1
  import { type MenuButton, type MenuComponent } from '../../../type';
2
- declare const _default: import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<{
2
+ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
3
3
  stageContentMenu: (MenuButton | MenuComponent)[];
4
+ disabledStageOverlay?: boolean | undefined;
4
5
  customContentMenu?: ((menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[]) | undefined;
5
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
6
+ }>, {
7
+ disabledStageOverlay: boolean;
8
+ }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
6
9
  stageContentMenu: (MenuButton | MenuComponent)[];
10
+ disabledStageOverlay?: boolean | undefined;
7
11
  customContentMenu?: ((menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[]) | undefined;
8
- }>>>, {}, {}>;
12
+ }>, {
13
+ disabledStageOverlay: boolean;
14
+ }>>>, {
15
+ disabledStageOverlay: boolean;
16
+ }, {}>;
9
17
  export default _default;
10
18
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
11
19
  type __VLS_TypePropsToRuntimeProps<T> = {
@@ -16,3 +24,11 @@ type __VLS_TypePropsToRuntimeProps<T> = {
16
24
  required: true;
17
25
  };
18
26
  };
27
+ type __VLS_WithDefaults<P, D> = {
28
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
29
+ default: D[K];
30
+ }> : P[K];
31
+ };
32
+ type __VLS_Prettify<T> = {
33
+ [K in keyof T]: T[K];
34
+ } & {};
@@ -1,7 +1,7 @@
1
1
  import type { Id, MContainer, MNode } from '@tmagic/schema';
2
+ import BaseService from '../services/BaseService';
2
3
  import type { AddMNode, EditorNodeInfo, PastePosition, StepValue, StoreState, StoreStateKey } from '../type';
3
4
  import { LayerOffset, Layout } from '../type';
4
- import BaseService from './BaseService';
5
5
  declare class Editor extends BaseService {
6
6
  state: StoreState;
7
7
  private isHistoryStateChange;
@@ -0,0 +1,23 @@
1
+ import StageCore from '@tmagic/stage';
2
+ import BaseService from '../services/BaseService';
3
+ import type { StageOptions, StageOverlayState } from '../type';
4
+ declare class StageOverlay extends BaseService {
5
+ private state;
6
+ constructor();
7
+ get<K extends keyof StageOverlayState>(name: K): StageOverlayState[K];
8
+ set<K extends keyof StageOverlayState, T extends StageOverlayState[K]>(name: K, value: T): void;
9
+ openOverlay(el: HTMLElement | undefined | null): void;
10
+ closeOverlay(): void;
11
+ updateOverlay(): void;
12
+ createStage(stageOptions?: StageOptions): StageCore;
13
+ private createContentEl;
14
+ private copyDocumentElement;
15
+ private render;
16
+ private updateHandler;
17
+ private addHandler;
18
+ private removeHandler;
19
+ private updateSelectStatus;
20
+ }
21
+ export type StageOverlayService = StageOverlay;
22
+ declare const _default: StageOverlay;
23
+ export default _default;
package/types/type.d.ts CHANGED
@@ -12,6 +12,7 @@ import type { EventsService } from './services/events';
12
12
  import type { HistoryService } from './services/history';
13
13
  import type { KeybindingService } from './services/keybinding';
14
14
  import type { PropsService } from './services/props';
15
+ import type { StageOverlayService } from './services/stageOverlay';
15
16
  import type { StorageService } from './services/storage';
16
17
  import type { UiService } from './services/ui';
17
18
  import type { UndoRedo } from './utils/undo-redo';
@@ -95,21 +96,22 @@ export interface Services {
95
96
  depService: DepService;
96
97
  dataSourceService: DataSourceService;
97
98
  keybindingService: KeybindingService;
99
+ stageOverlayService: StageOverlayService;
98
100
  }
99
101
  export interface StageOptions {
100
- runtimeUrl: string;
101
- autoScrollIntoView: boolean;
102
- containerHighlightClassName: string;
103
- containerHighlightDuration: number;
104
- containerHighlightType: ContainerHighlightType;
102
+ runtimeUrl?: string;
103
+ autoScrollIntoView?: boolean;
104
+ containerHighlightClassName?: string;
105
+ containerHighlightDuration?: number;
106
+ containerHighlightType?: ContainerHighlightType;
105
107
  disabledDragStart?: boolean;
106
- render: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
107
- moveableOptions: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
108
- canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
109
- isContainer: (el: HTMLElement) => boolean | Promise<boolean>;
110
- updateDragEl: UpdateDragEl;
111
- renderType: RenderType;
112
- guidesOptions: Partial<GuidesOptions>;
108
+ render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
109
+ moveableOptions?: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
110
+ canSelect?: (el: HTMLElement) => boolean | Promise<boolean>;
111
+ isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
112
+ updateDragEl?: UpdateDragEl;
113
+ renderType?: RenderType;
114
+ guidesOptions?: Partial<GuidesOptions>;
113
115
  disabledMultiSelect?: boolean;
114
116
  }
115
117
  export interface StoreState {
@@ -132,6 +134,16 @@ export interface PropsState {
132
134
  propsValueMap: Record<string, Partial<MNode>>;
133
135
  relateIdMap: Record<Id, Id>;
134
136
  }
137
+ export interface StageOverlayState {
138
+ wrapDiv: HTMLDivElement;
139
+ sourceEl: HTMLElement | null;
140
+ contentEl: HTMLElement | null;
141
+ stage: StageCore | null;
142
+ stageOptions: StageOptions | null;
143
+ wrapWidth: number;
144
+ wrapHeight: number;
145
+ stageOverlayVisible: boolean;
146
+ }
135
147
  export interface ComponentGroupState {
136
148
  list: ComponentGroup[];
137
149
  }
@@ -1,158 +0,0 @@
1
- import { computed, inject, nextTick, ref, watch } from 'vue';
2
-
3
- import type StageCore from '@tmagic/stage';
4
-
5
- import type { Services, StageOptions } from '@editor/type';
6
-
7
- import { useStage } from './use-stage';
8
-
9
- export const useStageOverlay = () => {
10
- const services = inject<Services>('services');
11
- const stageOptions = inject<StageOptions>('stageOptions');
12
-
13
- const wrapWidth = ref(0);
14
- const wrapHeight = ref(0);
15
- const stageOverlayVisible = ref(false);
16
- const stageOverlay = ref<HTMLDivElement>();
17
-
18
- const stage = computed(() => services?.editorService.get('stage'));
19
-
20
- let subStage: StageCore | null = null;
21
-
22
- const div = document.createElement('div');
23
- let selectEl: HTMLElement | null = null;
24
-
25
- const render = () => {
26
- if (!selectEl) return;
27
-
28
- const content = selectEl.cloneNode(true) as HTMLElement;
29
- content.style.position = 'static';
30
- Array.from(div.children).forEach((element) => {
31
- element.remove();
32
- });
33
- div.appendChild(content);
34
-
35
- subStage?.renderer.contentWindow?.magic.onPageElUpdate(div);
36
-
37
- subStage?.select(content);
38
- };
39
-
40
- const copyDocumentElement = () => {
41
- const doc = subStage?.renderer.getDocument();
42
- const documentElement = stage.value?.renderer.getDocument()?.documentElement;
43
-
44
- if (doc && documentElement) {
45
- doc.replaceChild(documentElement.cloneNode(true), doc.documentElement);
46
- }
47
- };
48
-
49
- const updateOverlay = () => {
50
- if (!selectEl) return;
51
-
52
- const { scrollWidth, scrollHeight } = selectEl;
53
-
54
- stageOverlay.value!.style.width = `${scrollWidth}px`;
55
- stageOverlay.value!.style.height = `${scrollHeight}px`;
56
-
57
- wrapWidth.value = scrollWidth;
58
- wrapHeight.value = scrollHeight;
59
- };
60
-
61
- const updateHandler = () => {
62
- render();
63
- updateOverlay();
64
- };
65
-
66
- const addHandler = () => {
67
- render();
68
- updateOverlay();
69
- };
70
-
71
- const removeHandler = () => {
72
- render();
73
- updateOverlay();
74
- };
75
-
76
- const openOverlay = async (el: HTMLElement) => {
77
- selectEl = el;
78
-
79
- stageOverlayVisible.value = true;
80
-
81
- if (!stageOverlay.value) {
82
- await nextTick();
83
- }
84
-
85
- if (!stageOptions) {
86
- return;
87
- }
88
-
89
- subStage = useStage({
90
- ...stageOptions,
91
- runtimeUrl: '',
92
- autoScrollIntoView: false,
93
- render(stage: StageCore) {
94
- copyDocumentElement();
95
-
96
- const rootEl = stage.renderer.getDocument()?.getElementById('app');
97
- if (rootEl) {
98
- rootEl.remove();
99
- }
100
-
101
- div.style.cssText = `
102
- width: ${el.scrollWidth}px;
103
- height: ${el.scrollHeight}px;
104
- background-color: #fff;
105
- `;
106
-
107
- render();
108
-
109
- return div;
110
- },
111
- });
112
- subStage.mount(stageOverlay.value!);
113
-
114
- const { mask, renderer } = subStage;
115
-
116
- const { contentWindow } = renderer;
117
- mask.showRule(false);
118
-
119
- updateOverlay();
120
-
121
- contentWindow?.magic.onRuntimeReady({});
122
-
123
- services?.editorService.on('update', updateHandler);
124
- services?.editorService.on('add', addHandler);
125
- services?.editorService.on('remove', removeHandler);
126
- };
127
-
128
- const closeOverlay = () => {
129
- stageOverlayVisible.value = false;
130
- subStage?.destroy();
131
- subStage = null;
132
-
133
- services?.editorService.off('update', updateHandler);
134
- services?.editorService.off('add', addHandler);
135
- services?.editorService.off('remove', removeHandler);
136
- };
137
-
138
- watch(stage, (stage) => {
139
- if (stage) {
140
- stage.on('dblclick', async (event: MouseEvent) => {
141
- const el = await stage.actionManager.getElementFromPoint(event);
142
- if (el) {
143
- openOverlay(el);
144
- }
145
- });
146
- } else if (subStage) {
147
- closeOverlay();
148
- }
149
- });
150
-
151
- return {
152
- wrapWidth,
153
- wrapHeight,
154
- stageOverlayVisible,
155
- stageOverlay,
156
- closeOverlay,
157
- };
158
- };
@@ -1,7 +0,0 @@
1
- export declare const useStageOverlay: () => {
2
- wrapWidth: import("vue").Ref<number>;
3
- wrapHeight: import("vue").Ref<number>;
4
- stageOverlayVisible: import("vue").Ref<boolean>;
5
- stageOverlay: import("vue").Ref<HTMLDivElement | undefined>;
6
- closeOverlay: () => void;
7
- };