@tmagic/editor 1.2.0-beta.8 → 1.2.0-beta.9

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.8",
2
+ "version": "1.2.0-beta.9",
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.8",
49
- "@tmagic/design": "1.2.0-beta.8",
50
- "@tmagic/form": "1.2.0-beta.8",
51
- "@tmagic/schema": "1.2.0-beta.8",
52
- "@tmagic/stage": "1.2.0-beta.8",
53
- "@tmagic/utils": "1.2.0-beta.8",
48
+ "@tmagic/core": "1.2.0-beta.9",
49
+ "@tmagic/design": "1.2.0-beta.9",
50
+ "@tmagic/form": "1.2.0-beta.9",
51
+ "@tmagic/schema": "1.2.0-beta.9",
52
+ "@tmagic/stage": "1.2.0-beta.9",
53
+ "@tmagic/utils": "1.2.0-beta.9",
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.8",
66
- "@tmagic/form": "1.2.0-beta.8",
65
+ "@tmagic/design": "1.2.0-beta.9",
66
+ "@tmagic/form": "1.2.0-beta.9",
67
67
  "monaco-editor": "^0.34.0",
68
68
  "vue": "^3.2.37"
69
69
  },
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div v-if="menuData.length && visible" class="magic-editor-content-menu" ref="menu" :style="menuStyle">
2
+ <div v-if="menuData.length" v-show="visible" class="magic-editor-content-menu" ref="menu" :style="menuStyle">
3
3
  <div>
4
4
  <ToolButton
5
5
  v-for="(item, index) in menuData"
@@ -33,16 +33,16 @@
33
33
  </template>
34
34
 
35
35
  <script lang="ts" setup>
36
- import { computed, defineEmits, defineProps, inject, ref, watch, watchEffect } from 'vue';
37
- import { cloneDeep, map, xor } from 'lodash-es';
36
+ import { computed, defineEmits, defineProps, inject, ref, watchEffect } from 'vue';
37
+ import { map, xor } from 'lodash-es';
38
38
 
39
39
  import { TMagicCard, tMagicMessage, TMagicTooltip } from '@tmagic/design';
40
- import { SelectConfig } from '@tmagic/form';
40
+ import { FormState, SelectConfig } from '@tmagic/form';
41
41
 
42
42
  import type { Services } from '../type';
43
43
  import { CodeEditorMode, CodeSelectOp } from '../type';
44
44
  const services = inject<Services>('services');
45
-
45
+ const form = inject<FormState>('mForm');
46
46
  const emit = defineEmits(['change']);
47
47
 
48
48
  const props = defineProps<{
@@ -77,20 +77,10 @@ const selectConfig = computed(() => {
77
77
  });
78
78
  const fieldKey = ref('');
79
79
  const multiple = ref(true);
80
- let lastTagSnapshot = cloneDeep(props.model[props.name]) || [];
81
- let shouldWatch = true;
82
-
83
- // 管理端和editor有表现不一致的地方,管理端切换组件表单不会重新渲染,因此增加shouldWatch控制lastTagSnapshot的记录
84
- watch(
85
- () => props.model[props.name],
86
- (selectValue) => {
87
- if (shouldWatch) {
88
- lastTagSnapshot = cloneDeep(selectValue) || [];
89
- }
90
- },
91
- );
80
+ const lastTagSnapshot = ref<string[]>([]);
92
81
 
93
82
  watchEffect(async () => {
83
+ if (!props.model[props.name]) return;
94
84
  const combineNames = await Promise.all(
95
85
  props.model[props.name].map(async (id: string) => {
96
86
  const { name = '' } = (await services?.codeBlockService.getCodeContentById(id)) || {};
@@ -101,11 +91,9 @@ watchEffect(async () => {
101
91
  });
102
92
 
103
93
  const changeHandler = async (value: any) => {
104
- shouldWatch = false;
105
94
  let codeIds = value;
106
95
  if (typeof value === 'string') {
107
96
  multiple.value = false;
108
- lastTagSnapshot = [lastTagSnapshot];
109
97
  codeIds = value ? [value] : [];
110
98
  }
111
99
  await setCombineRelation(codeIds);
@@ -121,14 +109,13 @@ const setCombineRelation = async (codeIds: string[]) => {
121
109
  let opFlag = CodeSelectOp.CHANGE;
122
110
  let diffValues = codeIds;
123
111
  if (multiple.value) {
124
- opFlag = codeIds.length < lastTagSnapshot.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
125
- diffValues = xor(codeIds, lastTagSnapshot) as string[];
112
+ // initValues为表单初始值,当表单内容发生变化时,initValues也会更新,可以理解为上一次表单内容的快照
113
+ lastTagSnapshot.value = form?.initValues[props.name] || [];
114
+ opFlag = codeIds.length < lastTagSnapshot.value.length ? CodeSelectOp.DELETE : CodeSelectOp.ADD;
115
+ diffValues = xor(codeIds, lastTagSnapshot.value) as string[];
126
116
  }
127
-
128
117
  // 记录绑定关系
129
118
  await services?.codeBlockService.setCombineRelation(id, diffValues, opFlag, props.prop);
130
- lastTagSnapshot = codeIds;
131
- shouldWatch = true;
132
119
  };
133
120
 
134
121
  const viewHandler = async () => {