@tmagic/editor 1.0.0-rc.9 → 1.0.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.
@@ -62,9 +62,6 @@ declare const _default: DefineComponent<{
62
62
  /** 画布中组件选中框的移动范围 */
63
63
  moveableOptions: {
64
64
  type: PropType<MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions)>;
65
- default: () => (core?: StageCore | undefined) => {
66
- container: HTMLElement | null | undefined;
67
- };
68
65
  };
69
66
  /** 编辑器初始化时默认选中的组件ID */
70
67
  defaultSelected: {
@@ -142,9 +139,6 @@ declare const _default: DefineComponent<{
142
139
  /** 画布中组件选中框的移动范围 */
143
140
  moveableOptions: {
144
141
  type: PropType<MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions)>;
145
- default: () => (core?: StageCore | undefined) => {
146
- container: HTMLElement | null | undefined;
147
- };
148
142
  };
149
143
  /** 编辑器初始化时默认选中的组件ID */
150
144
  defaultSelected: {
@@ -178,7 +172,6 @@ declare const _default: DefineComponent<{
178
172
  propsConfigs: Record<string, FormConfig>;
179
173
  propsValues: Record<string, MNode>;
180
174
  eventMethodList: Record<string, any>;
181
- moveableOptions: MoveableOptions | ((core?: StageCore | undefined) => MoveableOptions);
182
175
  canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
183
176
  }>;
184
177
  export default _default;
@@ -23,21 +23,24 @@ declare class Editor extends BaseService {
23
23
  /**
24
24
  * 根据id获取组件、组件的父组件以及组件所属的页面节点
25
25
  * @param {number | string} id 组件id
26
+ * @param {boolean} raw 是否使用toRaw
26
27
  * @returns {EditorNodeInfo}
27
28
  */
28
- getNodeInfo(id: Id): EditorNodeInfo;
29
+ getNodeInfo(id: Id, raw?: boolean): EditorNodeInfo;
29
30
  /**
30
31
  * 根据ID获取指点节点配置
31
32
  * @param id 组件ID
33
+ * @param {boolean} raw 是否使用toRaw
32
34
  * @returns 组件节点配置
33
35
  */
34
- getNodeById(id: Id): MNode | undefined;
36
+ getNodeById(id: Id, raw?: boolean): MNode | undefined;
35
37
  /**
36
38
  * 根据ID获取指点节点的父节点配置
37
39
  * @param id 组件ID
40
+ * @param {boolean} raw 是否使用toRaw
38
41
  * @returns 指点组件的父节点配置
39
42
  */
40
- getParentById(id: Id): MContainer | undefined;
43
+ getParentById(id: Id, raw?: boolean): MContainer | undefined;
41
44
  /**
42
45
  * 只有容器拥有布局
43
46
  */
@@ -206,3 +206,5 @@ export declare enum Layout {
206
206
  export declare enum Keys {
207
207
  ESCAPE = "Space"
208
208
  }
209
+ export declare const H_GUIDE_LINE_STORAGE_KEY = "$MagicStageHorizontalGuidelinesData";
210
+ export declare const V_GUIDE_LINE_STORAGE_KEY = "$MagicStageVerticalGuidelinesData";
@@ -37,3 +37,4 @@ export declare const initPosition: (node: MNode, layout: Layout, parentNode: MNo
37
37
  export declare const setLayout: (node: MNode, layout: Layout) => MNode;
38
38
  export declare const change2Fixed: (node: MNode, root: MApp) => MNode;
39
39
  export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (parent: MNode, node?: MNode | undefined) => Promise<Layout>) => Promise<MNode>;
40
+ export declare const getGuideLineFromCache: (key: string) => number[];
@@ -44,6 +44,7 @@ export declare const DEFAULT_CONFIG: FormConfig;
44
44
  export declare const getDefaultPropsValue: (type: string, id: string) => {
45
45
  type: string;
46
46
  id: string;
47
+ layout: string;
47
48
  style: {};
48
49
  name: string;
49
50
  items: never[];
@@ -52,5 +53,6 @@ export declare const getDefaultPropsValue: (type: string, id: string) => {
52
53
  id: string;
53
54
  style: {};
54
55
  name: string;
56
+ layout?: undefined;
55
57
  items?: undefined;
56
58
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-rc.9",
2
+ "version": "1.0.2",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -43,11 +43,11 @@
43
43
  "dependencies": {
44
44
  "@babel/core": "^7.18.0",
45
45
  "@element-plus/icons": "0.0.11",
46
- "@tmagic/core": "1.0.0-rc.9",
47
- "@tmagic/form": "1.0.0-rc.9",
48
- "@tmagic/schema": "1.0.0-rc.9",
49
- "@tmagic/stage": "1.0.0-rc.9",
50
- "@tmagic/utils": "1.0.0-rc.9",
46
+ "@tmagic/core": "1.0.2",
47
+ "@tmagic/form": "1.0.2",
48
+ "@tmagic/schema": "1.0.2",
49
+ "@tmagic/stage": "1.0.2",
50
+ "@tmagic/utils": "1.0.2",
51
51
  "buffer": "^6.0.3",
52
52
  "color": "^3.1.3",
53
53
  "element-plus": "^2.2.0",
@@ -60,7 +60,7 @@
60
60
  "vue": "^3.2.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "@tmagic/form": "1.0.0-rc.9",
63
+ "@tmagic/form": "1.0.2",
64
64
  "element-plus": "^2.2.0",
65
65
  "monaco-editor": "^0.32.1",
66
66
  "vue": "^3.2.0"
package/src/Editor.vue CHANGED
@@ -10,8 +10,8 @@
10
10
  </slot>
11
11
  </template>
12
12
 
13
- <template #workspace :editorService="editorService">
14
- <slot name="workspace">
13
+ <template #workspace>
14
+ <slot name="workspace" :editorService="editorService">
15
15
  <workspace>
16
16
  <template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
17
17
  <template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
@@ -130,9 +130,6 @@ export default defineComponent({
130
130
  /** 画布中组件选中框的移动范围 */
131
131
  moveableOptions: {
132
132
  type: [Object, Function] as PropType<MoveableOptions | ((core?: StageCore) => MoveableOptions)>,
133
- default: () => (core?: StageCore) => ({
134
- container: core?.renderer?.contentWindow?.document.getElementById('app'),
135
- }),
136
133
  },
137
134
 
138
135
  /** 编辑器初始化时默认选中的组件ID */
@@ -36,11 +36,18 @@ import {
36
36
  import { cloneDeep } from 'lodash-es';
37
37
 
38
38
  import type { MApp, MNode, MPage } from '@tmagic/schema';
39
- import type { Runtime, SortEventData, UpdateEventData } from '@tmagic/stage';
40
- import StageCore from '@tmagic/stage';
39
+ import StageCore, { GuidesType, Runtime, SortEventData, UpdateEventData } from '@tmagic/stage';
41
40
 
42
41
  import ScrollViewer from '@editor/components/ScrollViewer.vue';
43
- import { Layout, Services, StageOptions, StageRect } from '@editor/type';
42
+ import {
43
+ H_GUIDE_LINE_STORAGE_KEY,
44
+ Layout,
45
+ Services,
46
+ StageOptions,
47
+ StageRect,
48
+ V_GUIDE_LINE_STORAGE_KEY,
49
+ } from '@editor/type';
50
+ import { getGuideLineFromCache } from '@editor/utils';
44
51
 
45
52
  import ViewerMenu from './ViewerMenu.vue';
46
53
 
@@ -70,6 +77,8 @@ export default defineComponent({
70
77
  let stage: StageCore | null = null;
71
78
  let runtime: Runtime | null = null;
72
79
 
80
+ const getGuideLineKey = (key: string) => `${key}_${root.value?.id}_${page.value?.id}`;
81
+
73
82
  watchEffect(() => {
74
83
  if (stage) return;
75
84
 
@@ -99,6 +108,11 @@ export default defineComponent({
99
108
 
100
109
  stage?.mount(stageContainer.value);
101
110
 
111
+ stage.mask.setGuides([
112
+ getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
113
+ getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY)),
114
+ ]);
115
+
102
116
  stage?.on('select', (el: HTMLElement) => {
103
117
  services?.editorService.select(el.id);
104
118
  });
@@ -115,15 +129,26 @@ export default defineComponent({
115
129
  services?.editorService.sort(ev.src, ev.dist);
116
130
  });
117
131
 
118
- stage?.on('changeGuides', () => {
132
+ stage?.on('changeGuides', (e) => {
119
133
  services?.uiService.set('showGuides', true);
134
+
135
+ if (!root.value || !page.value) return;
136
+
137
+ const storageKey = getGuideLineKey(
138
+ e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY,
139
+ );
140
+ if (e.guides.length) {
141
+ globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
142
+ } else {
143
+ globalThis.localStorage.removeItem(storageKey);
144
+ }
120
145
  });
121
146
 
122
147
  if (!node.value?.id) return;
123
148
  stage?.on('runtime-ready', (rt) => {
124
149
  runtime = rt;
125
150
  // toRaw返回的值是一个引用而非快照,需要cloneDeep
126
- root.value && runtime?.updateRootConfig(cloneDeep(toRaw(root.value)));
151
+ root.value && runtime?.updateRootConfig?.(cloneDeep(toRaw(root.value)));
127
152
  page.value?.id && runtime?.updatePageId?.(page.value.id);
128
153
  setTimeout(() => {
129
154
  node.value && stage?.select(toRaw(node.value.id));
@@ -138,7 +163,7 @@ export default defineComponent({
138
163
 
139
164
  watch(root, (root) => {
140
165
  if (runtime && root) {
141
- runtime.updateRootConfig(cloneDeep(toRaw(root)));
166
+ runtime.updateRootConfig?.(cloneDeep(toRaw(root)));
142
167
  }
143
168
  });
144
169
 
@@ -108,10 +108,14 @@ class Editor extends BaseService {
108
108
  /**
109
109
  * 根据id获取组件、组件的父组件以及组件所属的页面节点
110
110
  * @param {number | string} id 组件id
111
+ * @param {boolean} raw 是否使用toRaw
111
112
  * @returns {EditorNodeInfo}
112
113
  */
113
- public getNodeInfo(id: Id): EditorNodeInfo {
114
- const root = toRaw(this.get<MApp | null>('root'));
114
+ public getNodeInfo(id: Id, raw = true): EditorNodeInfo {
115
+ let root = this.get<MApp | null>('root');
116
+ if (raw) {
117
+ root = toRaw(root);
118
+ }
115
119
  if (!root) return {};
116
120
 
117
121
  if (id === root.id) {
@@ -141,21 +145,23 @@ class Editor extends BaseService {
141
145
  /**
142
146
  * 根据ID获取指点节点配置
143
147
  * @param id 组件ID
148
+ * @param {boolean} raw 是否使用toRaw
144
149
  * @returns 组件节点配置
145
150
  */
146
- public getNodeById(id: Id): MNode | undefined {
147
- const { node } = this.getNodeInfo(id);
151
+ public getNodeById(id: Id, raw = true): MNode | undefined {
152
+ const { node } = this.getNodeInfo(id, raw);
148
153
  return node;
149
154
  }
150
155
 
151
156
  /**
152
157
  * 根据ID获取指点节点的父节点配置
153
158
  * @param id 组件ID
159
+ * @param {boolean} raw 是否使用toRaw
154
160
  * @returns 指点组件的父节点配置
155
161
  */
156
- public getParentById(id: Id): MContainer | undefined {
162
+ public getParentById(id: Id, raw = true): MContainer | undefined {
157
163
  if (!this.get<MApp | null>('root')) return;
158
- const { parent } = this.getNodeInfo(id);
164
+ const { parent } = this.getNodeInfo(id, raw);
159
165
  return parent;
160
166
  }
161
167
 
@@ -279,7 +285,7 @@ class Editor extends BaseService {
279
285
  } else if (curNode.items) {
280
286
  parentNode = curNode;
281
287
  } else {
282
- parentNode = this.getParentById(curNode.id);
288
+ parentNode = this.getParentById(curNode.id, false);
283
289
  }
284
290
 
285
291
  if (!parentNode) throw new Error('未找到父元素');
@@ -332,7 +338,7 @@ class Editor extends BaseService {
332
338
 
333
339
  if (!root) throw new Error('没有root');
334
340
 
335
- const { parent, node: curNode } = this.getNodeInfo(node.id);
341
+ const { parent, node: curNode } = this.getNodeInfo(node.id, false);
336
342
 
337
343
  if (!parent || !curNode) throw new Error('找不要删除的节点');
338
344
 
@@ -384,7 +390,7 @@ class Editor extends BaseService {
384
390
  public async update(config: MNode): Promise<MNode> {
385
391
  if (!config?.id) throw new Error('没有配置或者配置缺少id值');
386
392
 
387
- const info = this.getNodeInfo(config.id);
393
+ const info = this.getNodeInfo(config.id, false);
388
394
 
389
395
  if (!info.node) throw new Error(`获取不到id为${config.id}的节点`);
390
396
 
@@ -26,7 +26,9 @@ import type { GetColumnWidth, SetColumnWidth, StageRect, UiState } from '@editor
26
26
  import BaseService from './BaseService';
27
27
 
28
28
  const DEFAULT_LEFT_COLUMN_WIDTH = 310;
29
+ const MIN_LEFT_COLUMN_WIDTH = 45;
29
30
  const DEFAULT_RIGHT_COLUMN_WIDTH = 480;
31
+ const MIN_RIGHT_COLUMN_WIDTH = 1;
30
32
 
31
33
  const COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorColumnWidthData';
32
34
 
@@ -117,11 +119,11 @@ class Ui extends BaseService {
117
119
  };
118
120
 
119
121
  if (left) {
120
- columnWidth.left = left;
122
+ columnWidth.left = Math.max(left, MIN_LEFT_COLUMN_WIDTH);
121
123
  }
122
124
 
123
125
  if (right) {
124
- columnWidth.right = right;
126
+ columnWidth.right = Math.max(right, MIN_RIGHT_COLUMN_WIDTH);
125
127
  }
126
128
 
127
129
  if (!center || center === 'auto') {
@@ -25,6 +25,7 @@
25
25
  justify-items: center;
26
26
  align-items: center;
27
27
  background-color: #f3f3f3;
28
+ white-space: nowrap;
28
29
 
29
30
  &.active {
30
31
  background-color: #fff;
package/src/type.ts CHANGED
@@ -263,3 +263,6 @@ export enum Layout {
263
263
  export enum Keys {
264
264
  ESCAPE = 'Space',
265
265
  }
266
+
267
+ export const H_GUIDE_LINE_STORAGE_KEY = '$MagicStageHorizontalGuidelinesData';
268
+ export const V_GUIDE_LINE_STORAGE_KEY = '$MagicStageVerticalGuidelinesData';
@@ -204,3 +204,18 @@ export const Fixed2Other = async (
204
204
 
205
205
  return toRelative(node);
206
206
  };
207
+
208
+ export const getGuideLineFromCache = (key: string): number[] => {
209
+ if (!key) return [];
210
+
211
+ const guideLineCacheData = globalThis.localStorage.getItem(key);
212
+ if (guideLineCacheData) {
213
+ try {
214
+ return JSON.parse(guideLineCacheData) || [];
215
+ } catch (e) {
216
+ console.error(e);
217
+ }
218
+ }
219
+
220
+ return [];
221
+ };
@@ -248,6 +248,7 @@ export const getDefaultPropsValue = (type: string, id: string) =>
248
248
  ? {
249
249
  type,
250
250
  id,
251
+ layout: 'absolute',
251
252
  style: {},
252
253
  name: type,
253
254
  items: [],