@tmagic/editor 1.4.6 → 1.4.8

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 (158) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +636 -589
  3. package/dist/tmagic-editor.umd.cjs +634 -586
  4. package/package.json +15 -11
  5. package/types/editorProps.d.ts +0 -7
  6. package/types/layouts/PropsPanel.vue.d.ts +9 -9
  7. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  8. package/types/services/codeBlock.d.ts +2 -1
  9. package/types/services/dataSource.d.ts +2 -1
  10. package/types/services/dep.d.ts +12 -2
  11. package/types/services/editor.d.ts +22 -4
  12. package/types/services/props.d.ts +7 -6
  13. package/types/type.d.ts +6 -0
  14. package/types/utils/editor.d.ts +1 -0
  15. package/types/utils/idle-task.d.ts +14 -0
  16. package/types/utils/operator.d.ts +2 -2
  17. package/src/Editor.vue +0 -211
  18. package/src/components/CodeBlockEditor.vue +0 -268
  19. package/src/components/CodeParams.vue +0 -60
  20. package/src/components/ContentMenu.vue +0 -193
  21. package/src/components/FloatingBox.vue +0 -178
  22. package/src/components/Icon.vue +0 -27
  23. package/src/components/Resizer.vue +0 -23
  24. package/src/components/ScrollBar.vue +0 -151
  25. package/src/components/ScrollViewer.vue +0 -128
  26. package/src/components/SearchInput.vue +0 -37
  27. package/src/components/SplitView.vue +0 -186
  28. package/src/components/ToolButton.vue +0 -138
  29. package/src/components/Tree.vue +0 -71
  30. package/src/components/TreeNode.vue +0 -148
  31. package/src/editorProps.ts +0 -124
  32. package/src/fields/Code.vue +0 -50
  33. package/src/fields/CodeLink.vue +0 -80
  34. package/src/fields/CodeSelect.vue +0 -132
  35. package/src/fields/CodeSelectCol.vue +0 -139
  36. package/src/fields/DataSourceFieldSelect.vue +0 -149
  37. package/src/fields/DataSourceFields.vue +0 -323
  38. package/src/fields/DataSourceInput.vue +0 -325
  39. package/src/fields/DataSourceMethodSelect.vue +0 -153
  40. package/src/fields/DataSourceMethods.vue +0 -104
  41. package/src/fields/DataSourceMocks.vue +0 -255
  42. package/src/fields/DataSourceSelect.vue +0 -98
  43. package/src/fields/EventSelect.vue +0 -301
  44. package/src/fields/KeyValue.vue +0 -137
  45. package/src/fields/PageFragmentSelect.vue +0 -63
  46. package/src/fields/UISelect.vue +0 -135
  47. package/src/hooks/index.ts +0 -24
  48. package/src/hooks/use-code-block-edit.ts +0 -83
  49. package/src/hooks/use-data-source-edit.ts +0 -46
  50. package/src/hooks/use-data-source-method.ts +0 -100
  51. package/src/hooks/use-editor-content-height.ts +0 -26
  52. package/src/hooks/use-filter.ts +0 -55
  53. package/src/hooks/use-float-box.ts +0 -76
  54. package/src/hooks/use-getso.ts +0 -35
  55. package/src/hooks/use-next-float-box-position.ts +0 -29
  56. package/src/hooks/use-node-status.ts +0 -48
  57. package/src/hooks/use-stage.ts +0 -129
  58. package/src/hooks/use-window-rect.ts +0 -20
  59. package/src/icons/AppManageIcon.vue +0 -15
  60. package/src/icons/CenterIcon.vue +0 -13
  61. package/src/icons/CodeIcon.vue +0 -28
  62. package/src/icons/FolderMinusIcon.vue +0 -22
  63. package/src/icons/PinIcon.vue +0 -25
  64. package/src/icons/PinnedIcon.vue +0 -25
  65. package/src/index.ts +0 -118
  66. package/src/initService.ts +0 -447
  67. package/src/layouts/AddPageBox.vue +0 -55
  68. package/src/layouts/CodeEditor.vue +0 -226
  69. package/src/layouts/Framework.vue +0 -163
  70. package/src/layouts/NavMenu.vue +0 -200
  71. package/src/layouts/PropsPanel.vue +0 -130
  72. package/src/layouts/page-bar/AddButton.vue +0 -48
  73. package/src/layouts/page-bar/PageBar.vue +0 -159
  74. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  75. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  76. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  77. package/src/layouts/sidebar/Sidebar.vue +0 -278
  78. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
  79. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  80. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  81. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
  82. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  83. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  84. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  85. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  86. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  87. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  88. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  89. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  90. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  91. package/src/layouts/workspace/Workspace.vue +0 -46
  92. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  93. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  94. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  95. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  96. package/src/services/BaseService.ts +0 -230
  97. package/src/services/codeBlock.ts +0 -324
  98. package/src/services/componentList.ts +0 -58
  99. package/src/services/dataSource.ts +0 -209
  100. package/src/services/dep.ts +0 -80
  101. package/src/services/editor.ts +0 -1087
  102. package/src/services/events.ts +0 -93
  103. package/src/services/history.ts +0 -126
  104. package/src/services/keybinding.ts +0 -220
  105. package/src/services/props.ts +0 -265
  106. package/src/services/stageOverlay.ts +0 -212
  107. package/src/services/storage.ts +0 -155
  108. package/src/services/ui.ts +0 -156
  109. package/src/shims-vue.d.ts +0 -6
  110. package/src/theme/breadcrumb.scss +0 -6
  111. package/src/theme/code-block.scss +0 -6
  112. package/src/theme/code-editor.scss +0 -38
  113. package/src/theme/common/var.scss +0 -14
  114. package/src/theme/component-list-panel.scss +0 -95
  115. package/src/theme/content-menu.scss +0 -76
  116. package/src/theme/data-source-field.scss +0 -12
  117. package/src/theme/data-source-fields.scss +0 -13
  118. package/src/theme/data-source-input.scss +0 -18
  119. package/src/theme/data-source-methods.scss +0 -13
  120. package/src/theme/data-source.scss +0 -28
  121. package/src/theme/event.scss +0 -37
  122. package/src/theme/floating-box.scss +0 -32
  123. package/src/theme/framework.scss +0 -69
  124. package/src/theme/icon.scss +0 -12
  125. package/src/theme/index.scss +0 -10
  126. package/src/theme/key-value.scss +0 -20
  127. package/src/theme/layer-panel.scss +0 -26
  128. package/src/theme/layout.scss +0 -9
  129. package/src/theme/nav-menu.scss +0 -78
  130. package/src/theme/page-bar.scss +0 -89
  131. package/src/theme/page-fragment-select.scss +0 -14
  132. package/src/theme/props-panel.scss +0 -55
  133. package/src/theme/resizer.scss +0 -66
  134. package/src/theme/ruler.scss +0 -38
  135. package/src/theme/search-input.scss +0 -14
  136. package/src/theme/sidebar.scss +0 -79
  137. package/src/theme/stage.scss +0 -76
  138. package/src/theme/theme.scss +0 -27
  139. package/src/theme/tree.scss +0 -89
  140. package/src/theme/workspace.scss +0 -9
  141. package/src/type.ts +0 -746
  142. package/src/utils/compose.ts +0 -52
  143. package/src/utils/config.ts +0 -29
  144. package/src/utils/content-menu.ts +0 -95
  145. package/src/utils/data-source/formConfigs/base.ts +0 -30
  146. package/src/utils/data-source/formConfigs/http.ts +0 -60
  147. package/src/utils/data-source/index.ts +0 -236
  148. package/src/utils/editor.ts +0 -294
  149. package/src/utils/index.ts +0 -24
  150. package/src/utils/keybinding-config.ts +0 -125
  151. package/src/utils/logger.ts +0 -47
  152. package/src/utils/monaco-editor.ts +0 -8
  153. package/src/utils/operator.ts +0 -106
  154. package/src/utils/props.ts +0 -504
  155. package/src/utils/scroll-viewer.ts +0 -165
  156. package/src/utils/tree.ts +0 -15
  157. package/src/utils/undo-redo.ts +0 -76
  158. package/tsconfig.build.json +0 -16
@@ -1,27 +0,0 @@
1
- <template>
2
- <TMagicIcon v-if="!icon" class="magic-editor-icon"><Edit></Edit></TMagicIcon>
3
- <TMagicIcon
4
- v-else-if="typeof icon === 'string' && (icon.startsWith('http') || isRelativePath(icon))"
5
- class="magic-editor-icon"
6
- ><img :src="icon"
7
- /></TMagicIcon>
8
- <i v-else-if="typeof icon === 'string'" class="magic-editor-icon" :class="icon"></i>
9
- <TMagicIcon v-else class="magic-editor-icon"><component :is="toRaw(icon)"></component></TMagicIcon>
10
- </template>
11
-
12
- <script lang="ts" setup>
13
- import { toRaw } from 'vue';
14
- import { Edit } from '@element-plus/icons-vue';
15
-
16
- import { TMagicIcon } from '@tmagic/design';
17
-
18
- defineOptions({
19
- name: 'MEditorIcon',
20
- });
21
-
22
- defineProps<{
23
- icon?: any;
24
- }>();
25
-
26
- const isRelativePath = (str: string) => /^(\.|(\.\.)?\/)/.test(str);
27
- </script>
@@ -1,23 +0,0 @@
1
- <template>
2
- <span ref="target" class="m-editor-resizer" :class="{ 'm-editor-resizer-draging': isDraging }">
3
- <slot></slot>
4
- </span>
5
- </template>
6
-
7
- <script lang="ts" setup>
8
- import { ref } from 'vue';
9
- import type { OnDrag } from 'gesto';
10
-
11
- import { useGetSo } from '@editor/hooks/use-getso';
12
-
13
- defineOptions({
14
- name: 'MEditorResizer',
15
- });
16
-
17
- const emit = defineEmits<{
18
- change: [e: OnDrag];
19
- }>();
20
-
21
- const target = ref<HTMLSpanElement>();
22
- const { isDraging } = useGetSo(target, emit);
23
- </script>
@@ -1,151 +0,0 @@
1
- <template>
2
- <div ref="bar" class="m-editor-scroll-bar" :class="isHorizontal ? 'horizontal' : 'vertical'">
3
- <div ref="thumb" class="m-editor-scroll-bar-thumb" :style="thumbStyle"></div>
4
- </div>
5
- </template>
6
-
7
- <script lang="ts" setup>
8
- import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
9
- import Gesto from 'gesto';
10
-
11
- defineOptions({
12
- name: 'MEditorScrollBar',
13
- });
14
-
15
- const props = defineProps<{
16
- size: number;
17
- scrollSize: number;
18
- isHorizontal?: boolean;
19
- pos: number;
20
- }>();
21
-
22
- const emit = defineEmits(['scroll']);
23
-
24
- const bar = ref<HTMLDivElement>();
25
- const thumb = ref<HTMLDivElement>();
26
-
27
- const thumbSize = computed(() => props.size * (props.size / props.scrollSize));
28
- const thumbPos = computed(() => (props.pos / props.scrollSize) * props.size);
29
-
30
- const thumbStyle = computed(() => ({
31
- [props.isHorizontal ? 'width' : 'height']: `${thumbSize.value}px`,
32
- transform: `translate${props.isHorizontal ? 'X' : 'Y'}(${thumbPos.value}px)`,
33
- }));
34
-
35
- let gesto: Gesto;
36
-
37
- onMounted(() => {
38
- if (!thumb.value) return;
39
- const thumbEl = thumb.value;
40
- gesto = new Gesto(thumbEl, {
41
- container: window,
42
- });
43
-
44
- gesto
45
- .on('dragStart', (e) => {
46
- e.inputEvent.stopPropagation();
47
- e.inputEvent.preventDefault();
48
- })
49
- .on('drag', (e) => {
50
- scrollBy(getDelta(e));
51
- });
52
-
53
- bar.value?.addEventListener('wheel', wheelHandler, false);
54
- });
55
-
56
- onBeforeUnmount(() => {
57
- if (gesto) gesto.off();
58
- bar.value?.removeEventListener('wheel', wheelHandler, false);
59
- });
60
-
61
- const wheelHandler = (e: WheelEvent) => {
62
- const delta = props.isHorizontal ? e.deltaX : e.deltaY;
63
- if (delta) {
64
- e.preventDefault();
65
- }
66
- scrollBy(delta);
67
- };
68
-
69
- const getDelta = (e: any) => {
70
- const ratio = (props.isHorizontal ? e.deltaX : e.deltaY) / props.size;
71
- return props.scrollSize * ratio;
72
- };
73
-
74
- const scrollBy = (delta: number) => {
75
- if (delta < 0) {
76
- if (props.pos <= 0) {
77
- emit('scroll', 0);
78
- } else {
79
- emit('scroll', -Math.min(-delta, props.pos));
80
- }
81
- } else {
82
- const leftPos = props.size - (thumbSize.value + thumbPos.value);
83
- if (leftPos <= 0) {
84
- emit('scroll', 0);
85
- } else {
86
- emit('scroll', Math.min(delta, leftPos));
87
- }
88
- }
89
- };
90
- </script>
91
-
92
- <style lang="scss">
93
- .m-editor-scroll-bar {
94
- position: absolute;
95
- background-color: transparent;
96
- opacity: 0.3;
97
- transition: background-color 0.2s linear, opacity 0.2s linear;
98
-
99
- .m-editor-scroll-bar-thumb {
100
- background-color: #aaa;
101
- border-radius: 6px;
102
- position: absolute;
103
- }
104
-
105
- &.horizontal {
106
- width: 100%;
107
- height: 15px;
108
- bottom: 0;
109
-
110
- .m-editor-scroll-bar-thumb {
111
- height: 6px;
112
- transition: background-color 0.2s linear, height 0.2s ease-in-out;
113
- bottom: 2px;
114
- }
115
- }
116
-
117
- &.vertical {
118
- height: 100%;
119
- width: 15px;
120
- right: 5px;
121
-
122
- .m-editor-scroll-bar-thumb {
123
- width: 6px;
124
- transition: background-color 0.2s linear, width 0.2s ease-in-out;
125
- right: 2px;
126
- }
127
- }
128
-
129
- &:hover,
130
- &:focus {
131
- background-color: #eee;
132
- opacity: 0.9;
133
-
134
- .m-editor-scroll-bar-thumb {
135
- background-color: #999;
136
- }
137
-
138
- &.horizontal {
139
- .m-editor-scroll-bar-thumb {
140
- height: 11px;
141
- }
142
- }
143
-
144
- &.vertical {
145
- .m-editor-scroll-bar-thumb {
146
- width: 11px;
147
- }
148
- }
149
- }
150
- }
151
- </style>
@@ -1,128 +0,0 @@
1
- <template>
2
- <div class="m-editor-scroll-viewer-container" ref="container">
3
- <div ref="el" :style="style">
4
- <slot></slot>
5
- </div>
6
-
7
- <slot name="content"></slot>
8
-
9
- <ScrollBar
10
- v-if="scrollHeight > wrapHeight"
11
- :scroll-size="scrollHeight"
12
- :pos="vOffset"
13
- :size="wrapHeight"
14
- @scroll="vScrollHandler"
15
- ></ScrollBar>
16
- <ScrollBar
17
- v-if="scrollWidth > wrapWidth"
18
- :is-horizontal="true"
19
- :scroll-size="scrollWidth"
20
- :pos="hOffset"
21
- :size="wrapWidth"
22
- @scroll="hScrollHandler"
23
- ></ScrollBar>
24
- </div>
25
- </template>
26
-
27
- <script lang="ts" setup>
28
- import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
29
-
30
- import { isNumber } from '@tmagic/utils';
31
-
32
- import type { ScrollViewerEvent } from '@editor/type';
33
- import { ScrollViewer } from '@editor/utils/scroll-viewer';
34
-
35
- import ScrollBar from './ScrollBar.vue';
36
-
37
- defineOptions({
38
- name: 'MEditorScrollViewer',
39
- });
40
-
41
- const props = withDefaults(
42
- defineProps<{
43
- width?: number | string;
44
- height?: number | string;
45
- wrapWidth?: number;
46
- wrapHeight?: number;
47
- zoom?: number;
48
- correctionScrollSize?: {
49
- width: number;
50
- height: number;
51
- };
52
- }>(),
53
- {
54
- width: 0,
55
- height: 0,
56
- wrapWidth: 0,
57
- wrapHeight: 0,
58
- zoom: 1,
59
- correctionScrollSize: () => ({
60
- width: 0,
61
- height: 0,
62
- }),
63
- },
64
- );
65
-
66
- const container = ref<HTMLDivElement>();
67
- const el = ref<HTMLDivElement>();
68
- const style = computed(
69
- () => `
70
- width: ${isNumber(`${props.width}`) ? `${props.width}px` : props.width};
71
- height: ${isNumber(`${props.height}`) ? `${props.height}px` : props.height};
72
- position: absolute;
73
- margin-top: 30px;
74
- `,
75
- );
76
-
77
- const scrollWidth = ref(0);
78
- const scrollHeight = ref(0);
79
-
80
- let scrollViewer: ScrollViewer;
81
-
82
- onMounted(() => {
83
- if (!container.value || !el.value) return;
84
- scrollViewer = new ScrollViewer({
85
- container: container.value,
86
- target: el.value,
87
- zoom: props.zoom,
88
- correctionScrollSize: props.correctionScrollSize,
89
- });
90
-
91
- scrollViewer.on('scroll', (data: ScrollViewerEvent) => {
92
- hOffset.value = data.scrollLeft;
93
- vOffset.value = data.scrollTop;
94
- scrollWidth.value = data.scrollWidth;
95
- scrollHeight.value = data.scrollHeight;
96
- });
97
- });
98
-
99
- onBeforeUnmount(() => {
100
- scrollViewer.destroy();
101
- });
102
-
103
- watch(
104
- () => props.zoom,
105
- () => {
106
- scrollViewer.setZoom(props.zoom);
107
- },
108
- );
109
-
110
- const vOffset = ref(0);
111
- const vScrollHandler = (delta: number) => {
112
- vOffset.value += delta;
113
- scrollViewer.scrollTo({
114
- top: vOffset.value,
115
- });
116
- };
117
- const hOffset = ref(0);
118
- const hScrollHandler = (delta: number) => {
119
- hOffset.value += delta;
120
- scrollViewer.scrollTo({
121
- left: hOffset.value,
122
- });
123
- };
124
-
125
- defineExpose({
126
- container,
127
- });
128
- </script>
@@ -1,37 +0,0 @@
1
- <template>
2
- <TMagicInput
3
- v-model="filterText"
4
- class="search-input"
5
- size="small"
6
- placeholder="输入关键字进行过滤"
7
- clearable
8
- @input="filterTextChangeHandler"
9
- >
10
- <template #prefix>
11
- <TMagicIcon><Search /></TMagicIcon>
12
- </template>
13
- </TMagicInput>
14
- </template>
15
-
16
- <script setup lang="ts">
17
- import { ref } from 'vue';
18
- import { Search } from '@element-plus/icons-vue';
19
-
20
- import { TMagicIcon, TMagicInput } from '@tmagic/design';
21
-
22
- defineOptions({
23
- name: 'MEditorSearchInput',
24
- });
25
-
26
- const emit = defineEmits(['search']);
27
-
28
- const filterText = ref('');
29
-
30
- let timer: NodeJS.Timeout | null = null;
31
- const filterTextChangeHandler = () => {
32
- timer && clearTimeout(timer);
33
- timer = setTimeout(() => {
34
- emit('search', filterText.value);
35
- }, 300);
36
- };
37
- </script>
@@ -1,186 +0,0 @@
1
- <template>
2
- <div ref="el" class="m-editor-layout" :style="`min-width: ${props.minCenter + props.minLeft + props.minRight}px`">
3
- <template v-if="hasLeft && $slots.left">
4
- <div class="m-editor-layout-left" :class="leftClass" :style="`width: ${left}px`">
5
- <slot name="left"></slot>
6
- </div>
7
- <Resizer @change="changeLeft"></Resizer>
8
- </template>
9
-
10
- <div class="m-editor-layout-center" :class="centerClass" :style="`width: ${center}px`">
11
- <slot name="center"></slot>
12
- </div>
13
-
14
- <template v-if="hasRight && $slots.right">
15
- <Resizer @change="changeRight"></Resizer>
16
- <div class="m-editor-layout-right" :class="rightClass" :style="`width: ${right}px`">
17
- <slot name="right"></slot>
18
- </div>
19
- </template>
20
- </div>
21
- </template>
22
-
23
- <script lang="ts" setup>
24
- import { computed, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
25
- import { OnDrag } from 'gesto';
26
-
27
- import Resizer from './Resizer.vue';
28
-
29
- defineOptions({
30
- name: 'MEditorSplitView',
31
- });
32
-
33
- const emit = defineEmits(['update:left', 'change', 'update:right']);
34
-
35
- const props = withDefaults(
36
- defineProps<{
37
- width?: number;
38
- left?: number;
39
- right?: number;
40
- minLeft?: number;
41
- minRight?: number;
42
- minCenter?: number;
43
- leftClass?: string;
44
- rightClass?: string;
45
- centerClass?: string;
46
- }>(),
47
- {
48
- minLeft: 46,
49
- minRight: 1,
50
- minCenter: 5,
51
- },
52
- );
53
-
54
- const el = ref<HTMLElement>();
55
-
56
- const hasLeft = computed(() => typeof props.left !== 'undefined');
57
- const hasRight = computed(() => typeof props.right !== 'undefined');
58
- const center = ref(0);
59
-
60
- let clientWidth = 0;
61
-
62
- const getCenterWidth = (l = 0, r = 0) => {
63
- let right = r > 0 ? r : 0;
64
- let left = l > 0 ? l : 0;
65
- let center = clientWidth - left - right;
66
-
67
- if (center < props.minCenter) {
68
- center = props.minCenter;
69
- if (right > center + props.minRight) {
70
- right = clientWidth - left - center;
71
- } else {
72
- right = props.minRight;
73
- left = clientWidth - right - center;
74
- }
75
- }
76
- return {
77
- center,
78
- left,
79
- right,
80
- };
81
- };
82
-
83
- const widthChange = (width: number) => {
84
- if (width <= 0) {
85
- return;
86
- }
87
-
88
- clientWidth = width;
89
- let left = props.left || 0;
90
- let right = props.right || 0;
91
-
92
- if (left > clientWidth) {
93
- left = clientWidth / 3;
94
- }
95
-
96
- if (right > clientWidth) {
97
- right = clientWidth / 3;
98
- }
99
-
100
- const columnWidth = getCenterWidth(left, right);
101
-
102
- center.value = columnWidth.center;
103
-
104
- emit('change', columnWidth);
105
- };
106
-
107
- if (typeof props.width !== 'number') {
108
- const resizerObserver = new ResizeObserver((entries) => {
109
- for (const { contentRect } of entries) {
110
- widthChange(contentRect.width);
111
- }
112
- });
113
-
114
- onMounted(() => {
115
- if (el.value) {
116
- resizerObserver.observe(el.value);
117
- }
118
- });
119
-
120
- onBeforeUnmount(() => {
121
- resizerObserver.disconnect();
122
- });
123
- } else {
124
- watchEffect(() => {
125
- if (typeof props.width === 'number') widthChange(props.width);
126
- });
127
- }
128
-
129
- const changeLeft = ({ deltaX }: OnDrag) => {
130
- if (typeof props.left === 'undefined') return;
131
- let left = Math.max(props.left + deltaX, props.minLeft) || 0;
132
- emit('update:left', left);
133
-
134
- if (clientWidth - left - (props.right || 0) <= 0) {
135
- left = props.left;
136
- }
137
-
138
- const columnWidth = getCenterWidth(left, props.right || 0);
139
-
140
- center.value = columnWidth.center;
141
-
142
- emit('change', {
143
- left: columnWidth.left,
144
- center: center.value,
145
- right: columnWidth.right,
146
- });
147
- };
148
-
149
- const changeRight = ({ deltaX }: OnDrag) => {
150
- if (typeof props.right === 'undefined') return;
151
- let right = Math.max(props.right - deltaX, props.minRight) || 0;
152
- emit('update:right', right);
153
-
154
- if (clientWidth - (props.left || 0) - right <= 0) {
155
- right = props.right;
156
- }
157
-
158
- const columnWidth = getCenterWidth(props.left, right);
159
-
160
- center.value = columnWidth.center;
161
-
162
- emit('change', {
163
- left: columnWidth.left,
164
- center: center.value,
165
- right: columnWidth.right,
166
- });
167
- };
168
-
169
- defineExpose({
170
- updateWidth() {
171
- clientWidth = props.width ?? el.value?.clientWidth ?? clientWidth;
172
-
173
- if (clientWidth <= 0) {
174
- return;
175
- }
176
-
177
- const columnWidth = getCenterWidth(props.left, props.right);
178
-
179
- emit('change', {
180
- left: columnWidth.left,
181
- center: center.value,
182
- right: columnWidth.right,
183
- });
184
- },
185
- });
186
- </script>
@@ -1,138 +0,0 @@
1
- <template>
2
- <div
3
- v-if="display"
4
- class="menu-item"
5
- :class="`${data.type} ${data.className || ''}`"
6
- @click="clickHandler(data, $event)"
7
- @mousedown="mousedownHandler(data, $event)"
8
- @mouseup="mouseupHandler(data, $event)"
9
- >
10
- <TMagicDivider v-if="data.type === 'divider'" :direction="data.direction || 'vertical'"></TMagicDivider>
11
- <div v-else-if="data.type === 'text'" class="menu-item-text">{{ data.text }}</div>
12
-
13
- <template v-else-if="data.type === 'button'">
14
- <TMagicTooltip v-if="data.tooltip" effect="dark" placement="bottom-start" :content="data.tooltip">
15
- <TMagicButton size="small" link :disabled="disabled"
16
- ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></TMagicButton
17
- >
18
- </TMagicTooltip>
19
- <TMagicButton v-else size="small" link :disabled="disabled" :title="data.text"
20
- ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></TMagicButton
21
- >
22
- </template>
23
-
24
- <TMagicDropdown
25
- v-else-if="data.type === 'dropdown'"
26
- trigger="click"
27
- :disabled="disabled"
28
- @command="dropdownHandler"
29
- >
30
- <span class="el-dropdown-link menubar-menu-button">
31
- {{ data.text }}<TMagicIcon class="el-icon--right"><ArrowDown></ArrowDown></TMagicIcon>
32
- </span>
33
- <template #dropdown>
34
- <TMagicDropdownMenu v-if="data.items && data.items.length">
35
- <TMagicDropdownItem v-for="(subItem, index) in data.items" :key="index" :command="{ data, subItem }">{{
36
- subItem.text
37
- }}</TMagicDropdownItem>
38
- </TMagicDropdownMenu>
39
- </template>
40
- </TMagicDropdown>
41
-
42
- <component
43
- v-else-if="data.type === 'component'"
44
- v-bind="data.props || {}"
45
- v-on="(data as MenuComponent).listeners || {}"
46
- :is="data.component"
47
- ></component>
48
- </div>
49
- </template>
50
-
51
- <script lang="ts" setup>
52
- import { computed, inject } from 'vue';
53
- import { ArrowDown } from '@element-plus/icons-vue';
54
-
55
- import {
56
- TMagicButton,
57
- TMagicDivider,
58
- TMagicDropdown,
59
- TMagicDropdownItem,
60
- TMagicDropdownMenu,
61
- TMagicIcon,
62
- TMagicTooltip,
63
- } from '@tmagic/design';
64
-
65
- import MIcon from '../components/Icon.vue';
66
- import type { MenuButton, MenuComponent, Services } from '../type';
67
-
68
- defineOptions({
69
- name: 'MEditorToolButton',
70
- });
71
-
72
- const props = withDefaults(
73
- defineProps<{
74
- data?: MenuButton | MenuComponent;
75
- eventType?: 'mousedown' | 'mouseup' | 'click';
76
- }>(),
77
- {
78
- data: () => ({
79
- type: 'text',
80
- display: false,
81
- }),
82
- eventType: 'click',
83
- },
84
- );
85
- const services = inject<Services>('services');
86
-
87
- const disabled = computed(() => {
88
- if (typeof props.data === 'string') return false;
89
- if (props.data.type === 'component') return false;
90
- if (typeof props.data.disabled === 'function') {
91
- return props.data.disabled(services);
92
- }
93
- return props.data.disabled;
94
- });
95
-
96
- const display = computed(() => {
97
- if (!props.data) return false;
98
- if (typeof props.data === 'string') return true;
99
- if (typeof props.data.display === 'function') {
100
- return props.data.display(services);
101
- }
102
- return props.data.display ?? true;
103
- });
104
-
105
- const buttonHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
106
- if (disabled.value) return;
107
- if (typeof (item as MenuButton).handler === 'function' && services) {
108
- (item as MenuButton).handler?.(services, event);
109
- }
110
- };
111
-
112
- const dropdownHandler = (command: any) => {
113
- if (command.item.handler) {
114
- command.item.handler(services);
115
- }
116
- };
117
-
118
- const clickHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
119
- if (props.eventType !== 'click') return;
120
- if (item.type === 'button') {
121
- buttonHandler(item, event);
122
- }
123
- };
124
-
125
- const mousedownHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
126
- if (props.eventType !== 'mousedown') return;
127
- if (item.type === 'button') {
128
- buttonHandler(item, event);
129
- }
130
- };
131
-
132
- const mouseupHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
133
- if (props.eventType !== 'mouseup') return;
134
- if (item.type === 'button') {
135
- buttonHandler(item, event);
136
- }
137
- };
138
- </script>