@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.
- package/dist/tmagic-editor.mjs +769 -768
- package/dist/tmagic-editor.mjs.map +1 -1
- package/dist/tmagic-editor.umd.js +773 -771
- package/dist/tmagic-editor.umd.js.map +1 -1
- package/package.json +9 -9
- package/src/Editor.vue +2 -2
- package/src/components/ContentMenu.vue +2 -2
- package/src/components/Icon.vue +6 -4
- package/src/components/ToolButton.vue +29 -14
- package/src/fields/Code.vue +4 -1
- package/src/fields/CodeLink.vue +19 -11
- package/src/fields/CodeSelect.vue +6 -6
- package/src/fields/UISelect.vue +8 -7
- package/src/index.ts +2 -1
- package/src/layouts/AddPageBox.vue +13 -20
- package/src/layouts/CodeEditor.vue +106 -120
- package/src/layouts/Framework.vue +3 -2
- package/src/layouts/PropsPanel.vue +3 -8
- package/src/layouts/sidebar/ComponentListPanel.vue +13 -11
- package/src/layouts/sidebar/LayerMenu.vue +86 -91
- package/src/layouts/sidebar/LayerPanel.vue +252 -162
- package/src/layouts/sidebar/Sidebar.vue +24 -28
- package/src/layouts/sidebar/TabPane.vue +43 -51
- package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +22 -18
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +21 -21
- package/src/layouts/workspace/PageBar.vue +11 -10
- package/src/services/codeBlock.ts +16 -10
- package/src/services/editor.ts +4 -4
- package/src/theme/index.scss +1 -15
- package/src/theme/theme.scss +15 -0
- package/src/type.ts +1 -1
- package/types/Editor.vue.d.ts +2 -2
- package/types/fields/Code.vue.d.ts +8 -0
- package/types/fields/CodeLink.vue.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/layouts/AddPageBox.vue.d.ts +45 -3
- package/types/layouts/CodeEditor.vue.d.ts +160 -45
- package/types/layouts/sidebar/LayerMenu.vue.d.ts +16 -64
- package/types/layouts/sidebar/LayerPanel.vue.d.ts +16 -1071
- package/types/layouts/sidebar/Sidebar.vue.d.ts +114 -17
- package/types/layouts/sidebar/TabPane.vue.d.ts +80 -12
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -0
- package/types/services/codeBlock.d.ts +1 -1
- package/types/services/editor.d.ts +2 -2
- package/types/type.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.0-beta.
|
|
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.
|
|
49
|
-
"@tmagic/
|
|
50
|
-
"@tmagic/
|
|
51
|
-
"@tmagic/
|
|
52
|
-
"@tmagic/
|
|
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/
|
|
66
|
-
"
|
|
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
|
-
<
|
|
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
|
-
></
|
|
11
|
+
></ToolButton>
|
|
12
12
|
</div>
|
|
13
13
|
<teleport to="body">
|
|
14
14
|
<content-menu
|
package/src/components/Icon.vue
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
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
|
-
/></
|
|
5
|
+
/></TMagicIcon>
|
|
6
6
|
<i v-else-if="typeof icon === 'string'" class="magic-editor-icon" :class="icon"></i>
|
|
7
|
-
<
|
|
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
|
-
<
|
|
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
|
-
<
|
|
15
|
-
<
|
|
16
|
-
><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></
|
|
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
|
-
</
|
|
19
|
-
<
|
|
20
|
-
><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></
|
|
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
|
-
<
|
|
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 }}<
|
|
31
|
+
{{ data.text }}<TMagicIcon class="el-icon--right"><ArrowDown></ArrowDown></TMagicIcon>
|
|
27
32
|
</span>
|
|
28
33
|
<template #dropdown>
|
|
29
|
-
<
|
|
30
|
-
<
|
|
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
|
-
}}</
|
|
33
|
-
</
|
|
37
|
+
}}</TMagicDropdownItem>
|
|
38
|
+
</TMagicDropdownMenu>
|
|
34
39
|
</template>
|
|
35
|
-
</
|
|
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
|
|
package/src/fields/Code.vue
CHANGED
|
@@ -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;
|
package/src/fields/CodeLink.vue
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
-
</
|
|
29
|
+
</TMagicTooltip>
|
|
30
30
|
</div>
|
|
31
|
-
</
|
|
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
|
-
|
|
131
|
+
tMagicMessage.error('请先绑定代码块');
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
// 记录当前已被绑定的代码块,为查看弹窗的展示内容
|
package/src/fields/UISelect.vue
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-fields-ui-select" v-if="uiSelectMode" @click="cancelHandler">
|
|
3
|
-
<
|
|
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
|
-
<
|
|
7
|
-
<
|
|
8
|
-
</
|
|
9
|
-
<
|
|
10
|
-
<
|
|
11
|
-
</
|
|
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(
|
|
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
|
-
<
|
|
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 {
|
|
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
|
-
|
|
24
|
-
components: { Plus },
|
|
24
|
+
const services = inject<Services>('services');
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const clickHandler = () => {
|
|
27
|
+
const { editorService } = services || {};
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
clickHandler() {
|
|
31
|
-
const { editorService } = services || {};
|
|
29
|
+
if (!editorService) return;
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 {
|
|
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
|
-
|
|
28
|
-
|
|
50
|
+
let vsEditor: monaco.editor.IStandaloneCodeEditor | null = null;
|
|
51
|
+
let vsDiffEditor: monaco.editor.IStandaloneDiffEditor | null = null;
|
|
29
52
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
53
|
+
const values = ref('');
|
|
54
|
+
const loading = ref(false);
|
|
55
|
+
const codeEditor = ref<HTMLDivElement>();
|
|
34
56
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
57
|
+
const resizeObserver = new globalThis.ResizeObserver(
|
|
58
|
+
throttle((): void => {
|
|
59
|
+
vsEditor?.layout();
|
|
60
|
+
vsDiffEditor?.layout();
|
|
61
|
+
}, 300),
|
|
62
|
+
);
|
|
38
63
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
default: () => '',
|
|
42
|
-
},
|
|
64
|
+
const setEditorValue = (v: string | any, m: string | any) => {
|
|
65
|
+
values.value = toString(v, props.language);
|
|
43
66
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
emits: ['initd', 'save'],
|
|
71
|
+
return vsDiffEditor?.setModel({
|
|
72
|
+
original: originalModel,
|
|
73
|
+
modified: modifiedModel,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
56
76
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let vsDiffEditor: monaco.editor.IStandaloneDiffEditor | null = null;
|
|
77
|
+
return vsEditor?.setValue(values.value);
|
|
78
|
+
};
|
|
60
79
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const codeEditor = ref<HTMLDivElement>();
|
|
80
|
+
const getEditorValue = () =>
|
|
81
|
+
props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
|
|
64
82
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
vsEditor?.layout();
|
|
68
|
-
vsDiffEditor?.layout();
|
|
69
|
-
}, 300),
|
|
70
|
-
);
|
|
83
|
+
const init = async () => {
|
|
84
|
+
if (!codeEditor.value) return;
|
|
71
85
|
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
const options = {
|
|
87
|
+
value: values.value,
|
|
88
|
+
language: props.language,
|
|
89
|
+
theme: 'vs-dark',
|
|
90
|
+
...props.options,
|
|
91
|
+
};
|
|
74
92
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
original: originalModel,
|
|
81
|
-
modified: modifiedModel,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
99
|
+
setEditorValue(props.initValues, props.modifiedValues);
|
|
84
100
|
|
|
85
|
-
|
|
86
|
-
};
|
|
101
|
+
loading.value = false;
|
|
87
102
|
|
|
88
|
-
|
|
89
|
-
props.type === 'diff' ? vsDiffEditor?.getModifiedEditor().getValue() : vsEditor?.getValue();
|
|
103
|
+
emit('initd', vsEditor);
|
|
90
104
|
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
113
|
+
if (props.type !== 'diff' && props.autoSave) {
|
|
114
|
+
vsEditor?.onDidBlurEditorWidget(() => {
|
|
115
|
+
emit('save', getEditorValue());
|
|
116
|
+
});
|
|
117
|
+
}
|
|
100
118
|
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
138
|
+
init();
|
|
139
|
+
});
|
|
152
140
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
codeEditor,
|
|
141
|
+
onUnmounted(() => {
|
|
142
|
+
resizeObserver.disconnect();
|
|
143
|
+
});
|
|
157
144
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
145
|
+
defineExpose({
|
|
146
|
+
getEditor() {
|
|
147
|
+
return vsEditor || vsDiffEditor;
|
|
148
|
+
},
|
|
161
149
|
|
|
162
|
-
|
|
150
|
+
setEditorValue,
|
|
163
151
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
};
|
|
152
|
+
focus() {
|
|
153
|
+
vsEditor?.focus();
|
|
154
|
+
vsDiffEditor?.focus();
|
|
169
155
|
},
|
|
170
156
|
});
|
|
171
157
|
</script>
|