@tmagic/editor 1.2.0-beta.4 → 1.2.0-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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.0-beta.4",
2
+ "version": "1.2.0-beta.5",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -45,12 +45,12 @@
45
45
  "dependencies": {
46
46
  "@babel/core": "^7.18.0",
47
47
  "@element-plus/icons-vue": "^2.0.9",
48
- "@tmagic/core": "1.2.0-beta.4",
49
- "@tmagic/design": "1.2.0-beta.4",
50
- "@tmagic/form": "1.2.0-beta.4",
51
- "@tmagic/schema": "1.2.0-beta.4",
52
- "@tmagic/stage": "1.2.0-beta.4",
53
- "@tmagic/utils": "1.2.0-beta.4",
48
+ "@tmagic/core": "1.2.0-beta.5",
49
+ "@tmagic/design": "1.2.0-beta.5",
50
+ "@tmagic/form": "1.2.0-beta.5",
51
+ "@tmagic/schema": "1.2.0-beta.5",
52
+ "@tmagic/stage": "1.2.0-beta.5",
53
+ "@tmagic/utils": "1.2.0-beta.5",
54
54
  "buffer": "^6.0.3",
55
55
  "color": "^3.1.3",
56
56
  "events": "^3.3.0",
@@ -62,8 +62,8 @@
62
62
  "vue": "^3.2.37"
63
63
  },
64
64
  "peerDependencies": {
65
- "@tmagic/design": "1.2.0-beta.4",
66
- "@tmagic/form": "1.2.0-beta.4",
65
+ "@tmagic/design": "1.2.0-beta.5",
66
+ "@tmagic/form": "1.2.0-beta.5",
67
67
  "monaco-editor": "^0.34.0",
68
68
  "vue": "^3.2.37"
69
69
  },
@@ -10,7 +10,7 @@
10
10
  @save="saveCode"
11
11
  ></magic-code-editor>
12
12
 
13
- <layout
13
+ <Layout
14
14
  v-else
15
15
  class="m-editor-content"
16
16
  left-class="m-editor-framework-left"
@@ -29,7 +29,7 @@
29
29
  <template #center>
30
30
  <slot v-if="pageLength > 0" name="workspace"></slot>
31
31
  <slot v-else name="empty">
32
- <add-page-box></add-page-box>
32
+ <AddPageBox></AddPageBox>
33
33
  </slot>
34
34
  </template>
35
35
 
@@ -38,12 +38,12 @@
38
38
  <slot name="props-panel"></slot>
39
39
  </TMagicScrollbar>
40
40
  </template>
41
- </layout>
41
+ </Layout>
42
42
  </div>
43
43
  </template>
44
44
 
45
45
  <script lang="ts" setup>
46
- import { computed, inject, ref, watchEffect } from 'vue';
46
+ import { computed, inject, ref, watch } from 'vue';
47
47
 
48
48
  import { TMagicScrollbar } from '@tmagic/design';
49
49
  import type { MApp } from '@tmagic/schema';
@@ -71,24 +71,61 @@ const root = computed(() => editorService?.get<MApp>('root'));
71
71
 
72
72
  const pageLength = computed(() => editorService?.get<number>('pageLength') || 0);
73
73
  const showSrc = computed(() => uiService?.get<boolean>('showSrc'));
74
+
75
+ const LEFT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorLeftColumnWidthData';
76
+ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorRightColumnWidthData';
77
+
78
+ const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY));
79
+ const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY));
80
+
74
81
  const columnWidth = ref<Partial<GetColumnWidth>>({
75
- left: DEFAULT_LEFT_COLUMN_WIDTH,
82
+ left: leftColumnWidthCacheData,
76
83
  center: 0,
77
- right: 0,
78
- });
79
- uiService?.set('columnWidth', columnWidth.value);
80
-
81
- watchEffect(() => {
82
- if (pageLength.value <= 0) {
83
- columnWidth.value.right = undefined;
84
- columnWidth.value.center = globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH;
85
- } else {
86
- columnWidth.value.right = columnWidth.value.right || DEFAULT_RIGHT_COLUMN_WIDTH;
87
- columnWidth.value.center =
88
- globalThis.document.body.clientWidth - DEFAULT_LEFT_COLUMN_WIDTH - DEFAULT_RIGHT_COLUMN_WIDTH;
89
- }
84
+ right: RightColumnWidthCacheData,
90
85
  });
91
86
 
87
+ watch(
88
+ pageLength,
89
+ (length) => {
90
+ const left = columnWidth.value.left || DEFAULT_LEFT_COLUMN_WIDTH;
91
+
92
+ columnWidth.value.left = left;
93
+
94
+ if (length <= 0) {
95
+ columnWidth.value.right = undefined;
96
+ columnWidth.value.center = globalThis.document.body.clientWidth - left;
97
+ } else {
98
+ const right = columnWidth.value.right || RightColumnWidthCacheData || DEFAULT_RIGHT_COLUMN_WIDTH;
99
+ columnWidth.value.right = right;
100
+ columnWidth.value.center = globalThis.document.body.clientWidth - left - right;
101
+ }
102
+
103
+ uiService?.set('columnWidth', columnWidth);
104
+ },
105
+ {
106
+ immediate: true,
107
+ },
108
+ );
109
+
110
+ watch(
111
+ () => columnWidth.value.right,
112
+ (right) => {
113
+ if (typeof right === 'undefined') return;
114
+ globalThis.localStorage.setItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY, `${right}`);
115
+ },
116
+ );
117
+
118
+ watch(
119
+ () => columnWidth.value.left,
120
+ (left) => {
121
+ globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
122
+ },
123
+ );
124
+
125
+ const columnWidthChange = (columnWidth: GetColumnWidth) => {
126
+ uiService?.set('columnWidth', columnWidth);
127
+ };
128
+
92
129
  const saveCode = (value: string) => {
93
130
  try {
94
131
  // eslint-disable-next-line no-eval
@@ -97,21 +134,4 @@ const saveCode = (value: string) => {
97
134
  console.error(e);
98
135
  }
99
136
  };
100
-
101
- const COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorColumnWidthData';
102
-
103
- const columnWidthCacheData = globalThis.localStorage.getItem(COLUMN_WIDTH_STORAGE_KEY);
104
- if (columnWidthCacheData) {
105
- try {
106
- const columnWidthCache = JSON.parse(columnWidthCacheData);
107
- columnWidth.value = columnWidthCache;
108
- } catch (e) {
109
- console.error(e);
110
- }
111
- }
112
-
113
- const columnWidthChange = (columnWidth: GetColumnWidth) => {
114
- uiService?.set('columnWidth', columnWidth);
115
- globalThis.localStorage.setItem(COLUMN_WIDTH_STORAGE_KEY, JSON.stringify(columnWidth));
116
- };
117
137
  </script>
@@ -74,8 +74,13 @@ const center = ref(0);
74
74
 
75
75
  const changeLeft = (deltaX: number) => {
76
76
  if (typeof props.left === 'undefined') return;
77
- const left = Math.max(props.left + deltaX, props.minLeft) || 0;
77
+ let left = Math.max(props.left + deltaX, props.minLeft) || 0;
78
78
  emit('update:left', left);
79
+
80
+ if (clientWidth - left - (props.right || 0) <= 0) {
81
+ left = props.left;
82
+ }
83
+
79
84
  center.value = clientWidth - left - (props.right || 0);
80
85
 
81
86
  emit('change', {
@@ -87,8 +92,13 @@ const changeLeft = (deltaX: number) => {
87
92
 
88
93
  const changeRight = (deltaX: number) => {
89
94
  if (typeof props.right === 'undefined') return;
90
- const right = Math.max(props.right - deltaX, props.minRight) || 0;
95
+ let right = Math.max(props.right - deltaX, props.minRight) || 0;
91
96
  emit('update:right', right);
97
+
98
+ if (clientWidth - (props.left || 0) - right <= 0) {
99
+ right = props.right;
100
+ }
101
+
92
102
  center.value = clientWidth - (props.left || 0) - right;
93
103
 
94
104
  emit('change', {