@tmagic/editor 1.2.0-beta.1 → 1.2.0-beta.3

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 (45) hide show
  1. package/dist/tmagic-editor.mjs +769 -768
  2. package/dist/tmagic-editor.mjs.map +1 -1
  3. package/dist/tmagic-editor.umd.js +773 -771
  4. package/dist/tmagic-editor.umd.js.map +1 -1
  5. package/package.json +9 -9
  6. package/src/Editor.vue +2 -2
  7. package/src/components/ContentMenu.vue +2 -2
  8. package/src/components/Icon.vue +6 -4
  9. package/src/components/ToolButton.vue +29 -14
  10. package/src/fields/Code.vue +4 -1
  11. package/src/fields/CodeLink.vue +19 -11
  12. package/src/fields/CodeSelect.vue +6 -6
  13. package/src/fields/UISelect.vue +8 -7
  14. package/src/index.ts +2 -1
  15. package/src/layouts/AddPageBox.vue +13 -20
  16. package/src/layouts/CodeEditor.vue +106 -120
  17. package/src/layouts/Framework.vue +3 -2
  18. package/src/layouts/PropsPanel.vue +3 -8
  19. package/src/layouts/sidebar/ComponentListPanel.vue +13 -11
  20. package/src/layouts/sidebar/LayerMenu.vue +86 -91
  21. package/src/layouts/sidebar/LayerPanel.vue +252 -162
  22. package/src/layouts/sidebar/Sidebar.vue +24 -28
  23. package/src/layouts/sidebar/TabPane.vue +43 -51
  24. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +22 -18
  25. package/src/layouts/sidebar/code-block/CodeBlockList.vue +21 -21
  26. package/src/layouts/workspace/PageBar.vue +11 -10
  27. package/src/services/codeBlock.ts +16 -10
  28. package/src/services/editor.ts +4 -4
  29. package/src/theme/index.scss +1 -15
  30. package/src/theme/theme.scss +15 -0
  31. package/src/type.ts +1 -1
  32. package/types/Editor.vue.d.ts +2 -2
  33. package/types/fields/Code.vue.d.ts +8 -0
  34. package/types/fields/CodeLink.vue.d.ts +4 -0
  35. package/types/index.d.ts +1 -0
  36. package/types/layouts/AddPageBox.vue.d.ts +45 -3
  37. package/types/layouts/CodeEditor.vue.d.ts +160 -45
  38. package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -64
  39. package/types/layouts/sidebar/LayerPanel.vue.d.ts +16 -1071
  40. package/types/layouts/sidebar/Sidebar.vue.d.ts +114 -17
  41. package/types/layouts/sidebar/TabPane.vue.d.ts +80 -12
  42. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -0
  43. package/types/services/codeBlock.d.ts +1 -1
  44. package/types/services/editor.d.ts +2 -2
  45. package/types/type.d.ts +1 -1
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.0-beta.1",
2
+ "version": "1.2.0-beta.3",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -45,14 +45,14 @@
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.1",
49
- "@tmagic/form": "1.2.0-beta.1",
50
- "@tmagic/schema": "1.2.0-beta.1",
51
- "@tmagic/stage": "1.2.0-beta.1",
52
- "@tmagic/utils": "1.2.0-beta.1",
48
+ "@tmagic/core": "1.2.0-beta.3",
49
+ "@tmagic/design": "1.2.0-beta.3",
50
+ "@tmagic/form": "1.2.0-beta.3",
51
+ "@tmagic/schema": "1.2.0-beta.3",
52
+ "@tmagic/stage": "1.2.0-beta.3",
53
+ "@tmagic/utils": "1.2.0-beta.3",
53
54
  "buffer": "^6.0.3",
54
55
  "color": "^3.1.3",
55
- "element-plus": "^2.2.17",
56
56
  "events": "^3.3.0",
57
57
  "gesto": "^1.7.0",
58
58
  "keycon": "^1.1.2",
@@ -62,8 +62,8 @@
62
62
  "vue": "^3.2.37"
63
63
  },
64
64
  "peerDependencies": {
65
- "@tmagic/form": "1.2.0-beta.1",
66
- "element-plus": "^2.2.17",
65
+ "@tmagic/design": "1.2.0-beta.3",
66
+ "@tmagic/form": "1.2.0-beta.3",
67
67
  "monaco-editor": "^0.34.0",
68
68
  "vue": "^3.2.37"
69
69
  },
package/src/Editor.vue CHANGED
@@ -27,8 +27,8 @@
27
27
  <slot name="code-block-panel-header"></slot>
28
28
  </template>
29
29
 
30
- <template #code-block-panel-tool="{ id }">
31
- <slot name="code-block-panel-tool" :id="id"></slot>
30
+ <template #code-block-panel-tool="{ id, data }">
31
+ <slot name="code-block-panel-tool" :id="id" :data="data"></slot>
32
32
  </template>
33
33
 
34
34
  <template #code-block-edit-panel-header="{ id }">
@@ -1,14 +1,14 @@
1
1
  <template>
2
2
  <div v-if="menuData.length && visible" class="magic-editor-content-menu" ref="menu" :style="menuStyle">
3
3
  <div>
4
- <tool-button
4
+ <ToolButton
5
5
  v-for="(item, index) in menuData"
6
6
  event-type="mouseup"
7
7
  :data="item"
8
8
  :key="index"
9
9
  @mouseup="hide"
10
10
  @mouseenter="showSubMenu(item)"
11
- ></tool-button>
11
+ ></ToolButton>
12
12
  </div>
13
13
  <teleport to="body">
14
14
  <content-menu
@@ -1,16 +1,18 @@
1
1
  <template>
2
- <el-icon v-if="!icon" class="magic-editor-icon"><Edit></Edit></el-icon>
3
- <el-icon v-else-if="typeof icon === 'string' && icon.startsWith('http')" class="magic-editor-icon"
2
+ <TMagicIcon v-if="!icon" class="magic-editor-icon"><Edit></Edit></TMagicIcon>
3
+ <TMagicIcon v-else-if="typeof icon === 'string' && icon.startsWith('http')" class="magic-editor-icon"
4
4
  ><img :src="icon"
5
- /></el-icon>
5
+ /></TMagicIcon>
6
6
  <i v-else-if="typeof icon === 'string'" class="magic-editor-icon" :class="icon"></i>
7
- <el-icon v-else class="magic-editor-icon"><component :is="toRaw(icon)"></component></el-icon>
7
+ <TMagicIcon v-else class="magic-editor-icon"><component :is="toRaw(icon)"></component></TMagicIcon>
8
8
  </template>
9
9
 
10
10
  <script lang="ts" setup>
11
11
  import { toRaw } from 'vue';
12
12
  import { Edit } from '@element-plus/icons-vue';
13
13
 
14
+ import { TMagicIcon } from '@tmagic/design';
15
+
14
16
  defineProps<{
15
17
  icon?: any;
16
18
  }>();
@@ -7,32 +7,37 @@
7
7
  @mousedown="mousedownHandler(data, $event)"
8
8
  @mouseup="mouseupHandler(data, $event)"
9
9
  >
10
- <el-divider v-if="data.type === 'divider'" :direction="data.direction || 'vertical'"></el-divider>
10
+ <TMagicDivider v-if="data.type === 'divider'" :direction="data.direction || 'vertical'"></TMagicDivider>
11
11
  <div v-else-if="data.type === 'text'" class="menu-item-text">{{ data.text }}</div>
12
12
 
13
13
  <template v-else-if="data.type === 'button'">
14
- <el-tooltip v-if="data.tooltip" effect="dark" placement="bottom-start" :content="data.tooltip">
15
- <el-button size="small" text :disabled="disabled"
16
- ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></el-button
14
+ <TMagicTooltip v-if="data.tooltip" effect="dark" placement="bottom-start" :content="data.tooltip">
15
+ <TMagicButton size="small" text :disabled="disabled"
16
+ ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></TMagicButton
17
17
  >
18
- </el-tooltip>
19
- <el-button v-else size="small" text :disabled="disabled"
20
- ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></el-button
18
+ </TMagicTooltip>
19
+ <TMagicButton v-else size="small" text :disabled="disabled"
20
+ ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></TMagicButton
21
21
  >
22
22
  </template>
23
23
 
24
- <el-dropdown v-else-if="data.type === 'dropdown'" trigger="click" :disabled="disabled" @command="dropdownHandler">
24
+ <TMagicDropdown
25
+ v-else-if="data.type === 'dropdown'"
26
+ trigger="click"
27
+ :disabled="disabled"
28
+ @command="dropdownHandler"
29
+ >
25
30
  <span class="el-dropdown-link menubar-menu-button">
26
- {{ data.text }}<el-icon class="el-icon--right"><ArrowDown></ArrowDown></el-icon>
31
+ {{ data.text }}<TMagicIcon class="el-icon--right"><ArrowDown></ArrowDown></TMagicIcon>
27
32
  </span>
28
33
  <template #dropdown>
29
- <el-dropdown-menu v-if="data.items && data.items.length">
30
- <el-dropdown-item v-for="(subItem, index) in data.items" :key="index" :command="{ data, subItem }">{{
34
+ <TMagicDropdownMenu v-if="data.items && data.items.length">
35
+ <TMagicDropdownItem v-for="(subItem, index) in data.items" :key="index" :command="{ data, subItem }">{{
31
36
  subItem.text
32
- }}</el-dropdown-item>
33
- </el-dropdown-menu>
37
+ }}</TMagicDropdownItem>
38
+ </TMagicDropdownMenu>
34
39
  </template>
35
- </el-dropdown>
40
+ </TMagicDropdown>
36
41
 
37
42
  <component v-else-if="data.type === 'component'" v-bind="data.props || {}" :is="data.component"></component>
38
43
  </div>
@@ -42,6 +47,16 @@
42
47
  import { computed, inject } from 'vue';
43
48
  import { ArrowDown } from '@element-plus/icons-vue';
44
49
 
50
+ import {
51
+ TMagicButton,
52
+ TMagicDivider,
53
+ TMagicDropdown,
54
+ TMagicDropdownItem,
55
+ TMagicDropdownMenu,
56
+ TMagicIcon,
57
+ TMagicTooltip,
58
+ } from '@tmagic/design';
59
+
45
60
  import MIcon from '../components/Icon.vue';
46
61
  import type { MenuButton, MenuComponent, Services } from '../type';
47
62
 
@@ -3,6 +3,7 @@
3
3
  :style="`height: ${height}`"
4
4
  :init-values="model[name]"
5
5
  :language="language"
6
+ :options="config.options"
6
7
  @save="save"
7
8
  ></magic-code-editor>
8
9
  </template>
@@ -17,12 +18,14 @@ const props = defineProps<{
17
18
  name: string;
18
19
  config: {
19
20
  language?: string;
21
+ options?: Object;
22
+ height?: string;
20
23
  };
21
24
  prop: string;
22
25
  }>();
23
26
 
24
27
  const language = computed(() => props.config.language || 'javascript');
25
- const height = computed(() => `${document.body.clientHeight - 168}px`);
28
+ const height = computed(() => props.config.height || `${document.body.clientHeight - 168}px`);
26
29
 
27
30
  const save = (v: string) => {
28
31
  props.model[props.name] = v;
@@ -12,6 +12,7 @@ const props = defineProps<{
12
12
  name: string;
13
13
  text?: string;
14
14
  formTitle?: string;
15
+ codeOptions?: Object;
15
16
  };
16
17
  model: any;
17
18
  name: string;
@@ -20,17 +21,24 @@ const props = defineProps<{
20
21
 
21
22
  const emit = defineEmits(['change']);
22
23
 
23
- const formConfig = computed(() => ({
24
- ...props.config,
25
- text: '',
26
- type: 'link',
27
- form: [
28
- {
29
- name: props.name,
30
- type: 'vs-code',
31
- },
32
- ],
33
- }));
24
+ const formConfig = computed(() => {
25
+ const { codeOptions, ...config } = props.config;
26
+ return {
27
+ ...config,
28
+ text: '',
29
+ type: 'link',
30
+ form: [
31
+ {
32
+ name: props.name,
33
+ type: 'vs-code',
34
+ options: {
35
+ tabSize: 2,
36
+ ...(codeOptions || {}),
37
+ },
38
+ },
39
+ ],
40
+ };
41
+ });
34
42
 
35
43
  const modelValue = reactive<{ form: Record<string, string> }>({
36
44
  form: {
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div class="m-fields-code-select" :key="fieldKey">
3
- <el-card shadow="never">
3
+ <TMagicCard shadow="never">
4
4
  <template #header>
5
5
  <m-fields-select
6
6
  :config="selectConfig"
@@ -12,7 +12,7 @@
12
12
  ></m-fields-select>
13
13
  </template>
14
14
  <div class="tool-bar">
15
- <el-tooltip class="tool-item" effect="dark" content="查看代码块" placement="top">
15
+ <TMagicTooltip class="tool-item" effect="dark" content="查看代码块" placement="top">
16
16
  <svg
17
17
  @click="viewHandler"
18
18
  preserveAspectRatio="xMidYMid meet"
@@ -26,17 +26,17 @@
26
26
  d="m23 12l-7.071 7.071l-1.414-1.414L20.172 12l-5.657-5.657l1.414-1.414L23 12zM3.828 12l5.657 5.657l-1.414 1.414L1 12l7.071-7.071l1.414 1.414L3.828 12z"
27
27
  ></path>
28
28
  </svg>
29
- </el-tooltip>
29
+ </TMagicTooltip>
30
30
  </div>
31
- </el-card>
31
+ </TMagicCard>
32
32
  </div>
33
33
  </template>
34
34
 
35
35
  <script lang="ts" setup>
36
36
  import { computed, defineEmits, defineProps, inject, ref, watchEffect } from 'vue';
37
- import { ElMessage } from 'element-plus';
38
37
  import { cloneDeep, map, xor } from 'lodash-es';
39
38
 
39
+ import { TMagicCard, tMagicMessage, TMagicTooltip } from '@tmagic/design';
40
40
  import { SelectConfig } from '@tmagic/form';
41
41
 
42
42
  import type { Services } from '../type';
@@ -128,7 +128,7 @@ const setCombineIds = async (codeIds: string[]) => {
128
128
 
129
129
  const viewHandler = async () => {
130
130
  if (props.model[props.name].length === 0) {
131
- ElMessage.error('请先绑定代码块');
131
+ tMagicMessage.error('请先绑定代码块');
132
132
  return;
133
133
  }
134
134
  // 记录当前已被绑定的代码块,为查看弹窗的展示内容
@@ -1,14 +1,14 @@
1
1
  <template>
2
2
  <div class="m-fields-ui-select" v-if="uiSelectMode" @click="cancelHandler">
3
- <el-button type="danger" :icon="Delete" text style="padding: 0">取消</el-button>
3
+ <TMagicButton type="danger" :icon="Delete" text style="padding: 0">取消</TMagicButton>
4
4
  </div>
5
5
  <div class="m-fields-ui-select" v-else @click="startSelect" style="display: flex">
6
- <el-tooltip v-if="val" content="清除">
7
- <el-button style="padding: 0" type="danger" :icon="Close" text @click.stop="deleteHandler"></el-button>
8
- </el-tooltip>
9
- <el-tooltip :content="val ? toName + '_' + val : '点击此处选择'">
10
- <el-button text style="padding: 0; margin: 0">{{ val ? toName + '_' + val : '点击此处选择' }}</el-button>
11
- </el-tooltip>
6
+ <TMagicTooltip v-if="val" content="清除">
7
+ <TMagicButton style="padding: 0" type="danger" :icon="Close" text @click.stop="deleteHandler"></TMagicButton>
8
+ </TMagicTooltip>
9
+ <TMagicTooltip :content="val ? toName + '_' + val : '点击此处选择'">
10
+ <TMagicButton text style="padding: 0; margin: 0">{{ val ? toName + '_' + val : '点击此处选择' }}</TMagicButton>
11
+ </TMagicTooltip>
12
12
  </div>
13
13
  </template>
14
14
 
@@ -16,6 +16,7 @@
16
16
  import { computed, inject, ref } from 'vue';
17
17
  import { Close, Delete } from '@element-plus/icons-vue';
18
18
 
19
+ import { TMagicButton, TMagicTooltip } from '@tmagic/design';
19
20
  import { FormState } from '@tmagic/form';
20
21
 
21
22
  import { Services } from '../type';
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export { default as uiService } from './services/ui';
42
42
  export { default as codeBlockService } from './services/codeBlock';
43
43
  export { default as ComponentListPanel } from './layouts/sidebar/ComponentListPanel.vue';
44
44
  export { default as LayerPanel } from './layouts/sidebar/LayerPanel.vue';
45
+ export { default as CodeSelect } from './fields/CodeSelect.vue';
45
46
  export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
46
47
  export { default as PropsPanel } from './layouts/PropsPanel.vue';
47
48
  export { default as ToolButton } from './components/ToolButton.vue';
@@ -63,7 +64,7 @@ export default {
63
64
  app.component('m-fields-ui-select', uiSelect);
64
65
  app.component('m-fields-code-link', CodeLink);
65
66
  app.component('m-fields-vs-code', Code);
66
- app.component(CodeEditor.name, CodeEditor);
67
+ app.component('magic-code-editor', CodeEditor);
67
68
  app.component('m-fields-code-select', CodeSelect);
68
69
  },
69
70
  };
@@ -3,7 +3,7 @@
3
3
  <div class="m-editor-empty-content">
4
4
  <div class="m-editor-empty-button" @click="clickHandler">
5
5
  <div>
6
- <el-icon><plus /></el-icon>
6
+ <MIcon :icon="Plus"></MIcon>
7
7
  </div>
8
8
  <p>新增页面</p>
9
9
  </div>
@@ -11,33 +11,26 @@
11
11
  </div>
12
12
  </template>
13
13
 
14
- <script lang="ts">
15
- import { defineComponent, inject, toRaw } from 'vue';
14
+ <script lang="ts" setup>
15
+ import { inject, toRaw } from 'vue';
16
16
  import { Plus } from '@element-plus/icons-vue';
17
17
 
18
18
  import { NodeType } from '@tmagic/schema';
19
19
 
20
+ import MIcon from '../components/Icon.vue';
20
21
  import type { Services } from '../type';
21
22
  import { generatePageNameByApp } from '../utils';
22
23
 
23
- export default defineComponent({
24
- components: { Plus },
24
+ const services = inject<Services>('services');
25
25
 
26
- setup() {
27
- const services = inject<Services>('services');
26
+ const clickHandler = () => {
27
+ const { editorService } = services || {};
28
28
 
29
- return {
30
- clickHandler() {
31
- const { editorService } = services || {};
29
+ if (!editorService) return;
32
30
 
33
- if (!editorService) return;
34
-
35
- editorService.add({
36
- type: NodeType.PAGE,
37
- name: generatePageNameByApp(toRaw(editorService.get('root'))),
38
- });
39
- },
40
- };
41
- },
42
- });
31
+ editorService.add({
32
+ type: NodeType.PAGE,
33
+ name: generatePageNameByApp(toRaw(editorService.get('root'))),
34
+ });
35
+ };
43
36
  </script>
@@ -2,12 +2,35 @@
2
2
  <div ref="codeEditor" class="magic-code-editor"></div>
3
3
  </template>
4
4
 
5
- <script lang="ts">
6
- import { defineComponent, onMounted, onUnmounted, ref, watch } from 'vue';
5
+ <script lang="ts" setup>
6
+ import { onMounted, onUnmounted, ref, watch } from 'vue';
7
7
  import { throttle } from 'lodash-es';
8
8
  import * as monaco from 'monaco-editor';
9
9
  import serialize from 'serialize-javascript';
10
10
 
11
+ const props = withDefaults(
12
+ defineProps<{
13
+ initValues?: string | Object;
14
+ modifiedValues?: string | Object;
15
+ type?: string;
16
+ language?: string;
17
+ options?: {
18
+ [key: string]: any;
19
+ };
20
+ autoSave?: boolean;
21
+ }>(),
22
+ {
23
+ type: '',
24
+ autoSave: true,
25
+ language: 'javascript',
26
+ options: () => ({
27
+ tabSize: 2,
28
+ }),
29
+ },
30
+ );
31
+
32
+ const emit = defineEmits(['initd', 'save']);
33
+
11
34
  const toString = (v: string | any, language: string): string => {
12
35
  let value = '';
13
36
  if (typeof v !== 'string') {
@@ -24,148 +47,111 @@ const toString = (v: string | any, language: string): string => {
24
47
  return value;
25
48
  };
26
49
 
27
- export default defineComponent({
28
- name: 'magic-code-editor',
50
+ let vsEditor: monaco.editor.IStandaloneCodeEditor | null = null;
51
+ let vsDiffEditor: monaco.editor.IStandaloneDiffEditor | null = null;
29
52
 
30
- props: {
31
- initValues: {
32
- type: [String, Object],
33
- },
53
+ const values = ref('');
54
+ const loading = ref(false);
55
+ const codeEditor = ref<HTMLDivElement>();
34
56
 
35
- modifiedValues: {
36
- type: [String, Object],
37
- },
57
+ const resizeObserver = new globalThis.ResizeObserver(
58
+ throttle((): void => {
59
+ vsEditor?.layout();
60
+ vsDiffEditor?.layout();
61
+ }, 300),
62
+ );
38
63
 
39
- type: {
40
- type: String,
41
- default: () => '',
42
- },
64
+ const setEditorValue = (v: string | any, m: string | any) => {
65
+ values.value = toString(v, props.language);
43
66
 
44
- language: {
45
- type: String,
46
- default: () => 'javascript',
47
- },
67
+ if (props.type === 'diff') {
68
+ const originalModel = monaco.editor.createModel(values.value, 'text/javascript');
69
+ const modifiedModel = monaco.editor.createModel(toString(m, props.language), 'text/javascript');
48
70
 
49
- options: {
50
- type: Object,
51
- default: () => ({}),
52
- },
53
- },
54
-
55
- emits: ['initd', 'save'],
71
+ return vsDiffEditor?.setModel({
72
+ original: originalModel,
73
+ modified: modifiedModel,
74
+ });
75
+ }
56
76
 
57
- setup(props, { emit }) {
58
- let vsEditor: monaco.editor.IStandaloneCodeEditor | null = null;
59
- let vsDiffEditor: monaco.editor.IStandaloneDiffEditor | null = null;
77
+ return vsEditor?.setValue(values.value);
78
+ };
60
79
 
61
- const values = ref('');
62
- const loading = ref(false);
63
- const codeEditor = ref<HTMLDivElement>();
80
+ const getEditorValue = () =>
81
+ props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
64
82
 
65
- const resizeObserver = new globalThis.ResizeObserver(
66
- throttle((): void => {
67
- vsEditor?.layout();
68
- vsDiffEditor?.layout();
69
- }, 300),
70
- );
83
+ const init = async () => {
84
+ if (!codeEditor.value) return;
71
85
 
72
- const setEditorValue = (v: string | any, m: string | any) => {
73
- values.value = toString(v, props.language);
86
+ const options = {
87
+ value: values.value,
88
+ language: props.language,
89
+ theme: 'vs-dark',
90
+ ...props.options,
91
+ };
74
92
 
75
- if (props.type === 'diff') {
76
- const originalModel = monaco.editor.createModel(values.value, 'text/javascript');
77
- const modifiedModel = monaco.editor.createModel(toString(m, props.language), 'text/javascript');
93
+ if (props.type === 'diff') {
94
+ vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
95
+ } else {
96
+ vsEditor = monaco.editor.create(codeEditor.value, options);
97
+ }
78
98
 
79
- return vsDiffEditor?.setModel({
80
- original: originalModel,
81
- modified: modifiedModel,
82
- });
83
- }
99
+ setEditorValue(props.initValues, props.modifiedValues);
84
100
 
85
- return vsEditor?.setValue(values.value);
86
- };
101
+ loading.value = false;
87
102
 
88
- const getEditorValue = () =>
89
- props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
103
+ emit('initd', vsEditor);
90
104
 
91
- const init = async () => {
92
- if (!codeEditor.value) return;
105
+ codeEditor.value.addEventListener('keydown', (e) => {
106
+ if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
107
+ e.preventDefault();
108
+ e.stopPropagation();
109
+ emit('save', getEditorValue());
110
+ }
111
+ });
93
112
 
94
- const options = {
95
- value: values.value,
96
- language: props.language,
97
- theme: 'vs-dark',
98
- ...props.options,
99
- };
113
+ if (props.type !== 'diff' && props.autoSave) {
114
+ vsEditor?.onDidBlurEditorWidget(() => {
115
+ emit('save', getEditorValue());
116
+ });
117
+ }
100
118
 
101
- if (props.type === 'diff') {
102
- vsDiffEditor = monaco.editor.createDiffEditor(codeEditor.value, options);
103
- } else {
104
- vsEditor = monaco.editor.create(codeEditor.value, options);
105
- }
119
+ resizeObserver.observe(codeEditor.value);
120
+ };
106
121
 
122
+ watch(
123
+ () => props.initValues,
124
+ (v, preV) => {
125
+ if (v !== preV) {
107
126
  setEditorValue(props.initValues, props.modifiedValues);
127
+ }
128
+ },
129
+ {
130
+ deep: true,
131
+ immediate: true,
132
+ },
133
+ );
108
134
 
109
- loading.value = false;
110
-
111
- emit('initd', vsEditor);
112
-
113
- codeEditor.value.addEventListener('keydown', (e) => {
114
- if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
115
- e.preventDefault();
116
- e.stopPropagation();
117
- emit('save', getEditorValue());
118
- }
119
- });
120
-
121
- if (props.type !== 'diff') {
122
- vsEditor?.onDidBlurEditorWidget(() => {
123
- emit('save', getEditorValue());
124
- });
125
- }
126
-
127
- resizeObserver.observe(codeEditor.value);
128
- };
129
-
130
- watch(
131
- () => props.initValues,
132
- (v, preV) => {
133
- if (v !== preV) {
134
- setEditorValue(props.initValues, props.modifiedValues);
135
- }
136
- },
137
- {
138
- deep: true,
139
- immediate: true,
140
- },
141
- );
142
-
143
- onMounted(async () => {
144
- loading.value = true;
145
-
146
- init();
147
- });
135
+ onMounted(async () => {
136
+ loading.value = true;
148
137
 
149
- onUnmounted(() => {
150
- resizeObserver.disconnect();
151
- });
138
+ init();
139
+ });
152
140
 
153
- return {
154
- values,
155
- loading,
156
- codeEditor,
141
+ onUnmounted(() => {
142
+ resizeObserver.disconnect();
143
+ });
157
144
 
158
- getEditor() {
159
- return vsEditor || vsDiffEditor;
160
- },
145
+ defineExpose({
146
+ getEditor() {
147
+ return vsEditor || vsDiffEditor;
148
+ },
161
149
 
162
- setEditorValue,
150
+ setEditorValue,
163
151
 
164
- focus() {
165
- vsEditor?.focus();
166
- vsDiffEditor?.focus();
167
- },
168
- };
152
+ focus() {
153
+ vsEditor?.focus();
154
+ vsDiffEditor?.focus();
169
155
  },
170
156
  });
171
157
  </script>