@tmagic/editor 1.1.0-beta.6 → 1.1.0-beta.7

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.1.0-beta.6",
2
+ "version": "1.1.0-beta.7",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -45,11 +45,11 @@
45
45
  "dependencies": {
46
46
  "@babel/core": "^7.18.0",
47
47
  "@element-plus/icons-vue": "^2.0.6",
48
- "@tmagic/core": "1.1.0-beta.6",
49
- "@tmagic/form": "1.1.0-beta.6",
50
- "@tmagic/schema": "1.1.0-beta.6",
51
- "@tmagic/stage": "1.1.0-beta.6",
52
- "@tmagic/utils": "1.1.0-beta.6",
48
+ "@tmagic/core": "1.1.0-beta.7",
49
+ "@tmagic/form": "1.1.0-beta.7",
50
+ "@tmagic/schema": "1.1.0-beta.7",
51
+ "@tmagic/stage": "1.1.0-beta.7",
52
+ "@tmagic/utils": "1.1.0-beta.7",
53
53
  "buffer": "^6.0.3",
54
54
  "color": "^3.1.3",
55
55
  "element-plus": "^2.2.6",
@@ -62,7 +62,7 @@
62
62
  "vue": "^3.2.37"
63
63
  },
64
64
  "peerDependencies": {
65
- "@tmagic/form": "1.1.0-beta.6",
65
+ "@tmagic/form": "1.1.0-beta.7",
66
66
  "element-plus": "^2.2.6",
67
67
  "monaco-editor": "^0.32.1",
68
68
  "vue": "^3.2.37"
@@ -21,7 +21,6 @@ import { FormState } from '@tmagic/form';
21
21
  import { Services } from '../type';
22
22
 
23
23
  const props = defineProps<{
24
- labelWidth: string;
25
24
  config: any;
26
25
  model: any;
27
26
  prop: string;
package/src/index.ts CHANGED
@@ -58,7 +58,7 @@ export default {
58
58
  setConfig(option);
59
59
 
60
60
  app.component(Editor.name, Editor);
61
- app.component(uiSelect.name, uiSelect);
61
+ app.component('m-fields-ui-select', uiSelect);
62
62
  app.component(CodeLink.name, CodeLink);
63
63
  app.component(Code.name, Code);
64
64
  app.component(CodeEditor.name, CodeEditor);
@@ -1,191 +1,73 @@
1
1
  <template>
2
- <div class="m-editor-page-bar" ref="pageBar">
3
- <div id="m-editor-page-bar-add-icon" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="addPage">
4
- <el-icon><plus></plus></el-icon>
5
- </div>
2
+ <PageBarScrollContainer>
6
3
  <div
7
- v-if="scrollState.canScroll"
8
- class="m-editor-page-bar-item m-editor-page-bar-item-icon"
9
- @click="scrollState.scroll('left')"
4
+ v-for="item in (root && root.items) || []"
5
+ class="m-editor-page-bar-item"
6
+ :key="item.key"
7
+ :class="{ active: page?.id === item.id }"
8
+ @click="switchPage(item)"
10
9
  >
11
- <el-icon><arrow-left-bold></arrow-left-bold></el-icon>
12
- </div>
13
- <div
14
- v-if="root"
15
- class="m-editor-page-bar-items"
16
- ref="itemsContainer"
17
- :style="`width: ${scrollState.itemsContainerWidth}px`"
18
- >
19
- <div
20
- v-for="item in root.items"
21
- :key="item.key"
22
- class="m-editor-page-bar-item"
23
- :class="{ active: page?.id === item.id }"
24
- @click="switchPage(item)"
25
- >
26
- <div class="m-editor-page-bar-title">
27
- <slot name="page-bar-title" :page="item">
28
- <el-tooltip effect="dark" placement="top-start" :content="item.name">
29
- <span>{{ item.name }}</span>
30
- </el-tooltip>
10
+ <div class="m-editor-page-bar-title">
11
+ <slot name="page-bar-title" :page="item">
12
+ <el-tooltip effect="dark" placement="top-start" :content="item.name">
13
+ <span>{{ item.name }}</span>
14
+ </el-tooltip>
15
+ </slot>
16
+ </div>
17
+
18
+ <el-popover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
19
+ <div>
20
+ <slot name="page-bar-popover" :page="item">
21
+ <tool-button
22
+ :data="{
23
+ type: 'button',
24
+ text: '复制',
25
+ icon: DocumentCopy,
26
+ handler: () => copy(item),
27
+ }"
28
+ ></tool-button>
29
+ <tool-button
30
+ :data="{
31
+ type: 'button',
32
+ text: '删除',
33
+ icon: Delete,
34
+ handler: () => remove(item),
35
+ }"
36
+ ></tool-button>
31
37
  </slot>
32
38
  </div>
33
-
34
- <el-popover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
35
- <div>
36
- <slot name="page-bar-popover" :page="item">
37
- <tool-button
38
- :data="{
39
- type: 'button',
40
- text: '复制',
41
- icon: DocumentCopy,
42
- handler: () => copy(item),
43
- }"
44
- ></tool-button>
45
- <tool-button
46
- :data="{
47
- type: 'button',
48
- text: '删除',
49
- icon: Delete,
50
- handler: () => remove(item),
51
- }"
52
- ></tool-button>
53
- </slot>
54
- </div>
55
- <template #reference>
56
- <el-icon class="m-editor-page-bar-menu-icon">
57
- <caret-bottom></caret-bottom>
58
- </el-icon>
59
- </template>
60
- </el-popover>
61
- </div>
39
+ <template #reference>
40
+ <el-icon class="m-editor-page-bar-menu-icon">
41
+ <caret-bottom></caret-bottom>
42
+ </el-icon>
43
+ </template>
44
+ </el-popover>
62
45
  </div>
63
- <div
64
- v-if="scrollState.canScroll"
65
- class="m-editor-page-bar-item m-editor-page-bar-item-icon"
66
- @click="scrollState.scroll('right')"
67
- >
68
- <el-icon><arrow-right-bold></arrow-right-bold></el-icon>
69
- </div>
70
- </div>
46
+ </PageBarScrollContainer>
71
47
  </template>
72
48
 
73
49
  <script lang="ts" setup>
74
- import { computed, ComputedRef, inject, onMounted, onUnmounted, ref, toRaw, watch } from 'vue';
75
- import { ArrowLeftBold, ArrowRightBold, CaretBottom, Delete, DocumentCopy, Plus } from '@element-plus/icons-vue';
50
+ import { computed, inject } from 'vue';
51
+ import { CaretBottom, Delete, DocumentCopy } from '@element-plus/icons-vue';
76
52
 
77
53
  import type { MApp, MPage } from '@tmagic/schema';
78
- import { NodeType } from '@tmagic/schema';
79
54
 
80
55
  import ToolButton from '../../components/ToolButton.vue';
81
56
  import type { Services } from '../../type';
82
- import { generatePageNameByApp } from '../../utils/editor';
83
-
84
- const useScroll = (root: ComputedRef<MApp | undefined>) => {
85
- const pageBar = ref<HTMLDivElement>();
86
- const itemsContainer = ref<HTMLDivElement>();
87
-
88
- const pageBarWidth = ref(0);
89
- const canScroll = ref(false);
90
-
91
- const itemsContainerWidth = computed(() => pageBarWidth.value - 105);
92
-
93
- let translateLeft = 0;
94
- const resizeObserver = new ResizeObserver((entries) => {
95
- for (const { contentRect } of entries) {
96
- const { width } = contentRect;
97
- pageBarWidth.value = width || 0;
98
-
99
- setCanScroll();
100
- }
101
- });
102
57
 
103
- const setCanScroll = () => {
104
- if (itemsContainer.value) {
105
- canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
106
- }
107
- };
108
-
109
- const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
110
- if (!itemsContainer.value) return;
111
-
112
- const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
113
-
114
- if (type === 'left') {
115
- translateLeft += 100;
116
-
117
- if (translateLeft > 0) {
118
- translateLeft = 0;
119
- }
120
- } else if (type === 'right') {
121
- translateLeft -= 100;
122
-
123
- if (-translateLeft > maxScrollLeft) {
124
- translateLeft = -maxScrollLeft;
125
- }
126
- } else if (type === 'start') {
127
- translateLeft = 0;
128
- } else if (type === 'end') {
129
- translateLeft = -maxScrollLeft;
130
- }
131
-
132
- itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
133
- };
134
-
135
- onMounted(() => {
136
- pageBar.value && resizeObserver.observe(pageBar.value);
137
- });
138
-
139
- onUnmounted(() => {
140
- resizeObserver.disconnect();
141
- });
142
-
143
- watch(
144
- () => root.value?.items.length,
145
- (length = 0, preLength = 0) => {
146
- setTimeout(() => {
147
- setCanScroll();
148
- if (length < preLength) {
149
- scroll('start');
150
- } else {
151
- scroll('end');
152
- }
153
- });
154
- },
155
- );
156
-
157
- return {
158
- pageBar,
159
- itemsContainer,
160
- canScroll,
161
-
162
- itemsContainerWidth,
163
-
164
- scroll,
165
- };
166
- };
58
+ import PageBarScrollContainer from './PageBarScrollContainer.vue';
167
59
 
168
60
  const services = inject<Services>('services');
169
61
  const editorService = services?.editorService;
170
62
 
171
63
  const root = computed(() => editorService?.get<MApp>('root'));
172
64
 
173
- const scrollState = useScroll(root);
174
65
  const page = computed(() => editorService?.get('page'));
175
66
 
176
67
  const switchPage = (page: MPage) => {
177
68
  editorService?.select(page);
178
69
  };
179
70
 
180
- const addPage = () => {
181
- if (!editorService) return;
182
- const pageConfig = {
183
- type: NodeType.PAGE,
184
- name: generatePageNameByApp(toRaw(editorService.get('root'))),
185
- };
186
- editorService.add(pageConfig);
187
- };
188
-
189
71
  const copy = (node: MPage) => {
190
72
  node && editorService?.copy(node);
191
73
  editorService?.paste({
@@ -0,0 +1,111 @@
1
+ <template>
2
+ <div class="m-editor-page-bar" ref="pageBar">
3
+ <div id="m-editor-page-bar-add-icon" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="addPage">
4
+ <el-icon><plus></plus></el-icon>
5
+ </div>
6
+ <div v-if="canScroll" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="scroll('left')">
7
+ <el-icon><arrow-left-bold></arrow-left-bold></el-icon>
8
+ </div>
9
+ <div v-if="root" class="m-editor-page-bar-items" ref="itemsContainer" :style="`width: ${itemsContainerWidth}px`">
10
+ <slot></slot>
11
+ </div>
12
+ <div v-if="canScroll" class="m-editor-page-bar-item m-editor-page-bar-item-icon" @click="scroll('right')">
13
+ <el-icon><arrow-right-bold></arrow-right-bold></el-icon>
14
+ </div>
15
+ </div>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ import { computed, inject, onMounted, onUnmounted, ref, toRaw, watch } from 'vue';
20
+ import { ArrowLeftBold, ArrowRightBold, Plus } from '@element-plus/icons-vue';
21
+
22
+ import { MApp, NodeType } from '@tmagic/schema';
23
+
24
+ import type { Services } from '../../type';
25
+ import { generatePageNameByApp } from '../../utils/editor';
26
+
27
+ const services = inject<Services>('services');
28
+ const editorService = services?.editorService;
29
+
30
+ const pageBar = ref<HTMLDivElement>();
31
+ const itemsContainer = ref<HTMLDivElement>();
32
+ const pageBarWidth = ref(0);
33
+ const canScroll = ref(false);
34
+
35
+ const itemsContainerWidth = computed(() => pageBarWidth.value - 105);
36
+
37
+ let translateLeft = 0;
38
+ const resizeObserver = new ResizeObserver((entries) => {
39
+ for (const { contentRect } of entries) {
40
+ const { width } = contentRect;
41
+ pageBarWidth.value = width || 0;
42
+
43
+ setCanScroll();
44
+ }
45
+ });
46
+
47
+ const setCanScroll = () => {
48
+ if (itemsContainer.value) {
49
+ canScroll.value = itemsContainer.value.scrollWidth > pageBarWidth.value - 105;
50
+ }
51
+ };
52
+
53
+ const scroll = (type: 'left' | 'right' | 'start' | 'end') => {
54
+ if (!itemsContainer.value) return;
55
+
56
+ const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
57
+
58
+ if (type === 'left') {
59
+ translateLeft += 100;
60
+
61
+ if (translateLeft > 0) {
62
+ translateLeft = 0;
63
+ }
64
+ } else if (type === 'right') {
65
+ translateLeft -= 100;
66
+
67
+ if (-translateLeft > maxScrollLeft) {
68
+ translateLeft = -maxScrollLeft;
69
+ }
70
+ } else if (type === 'start') {
71
+ translateLeft = 0;
72
+ } else if (type === 'end') {
73
+ translateLeft = -maxScrollLeft;
74
+ }
75
+
76
+ itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
77
+ };
78
+
79
+ onMounted(() => {
80
+ pageBar.value && resizeObserver.observe(pageBar.value);
81
+ });
82
+
83
+ onUnmounted(() => {
84
+ resizeObserver.disconnect();
85
+ });
86
+
87
+ const root = computed(() => editorService?.get<MApp>('root'));
88
+
89
+ watch(
90
+ () => root.value?.items.length,
91
+ (length = 0, preLength = 0) => {
92
+ setTimeout(() => {
93
+ setCanScroll();
94
+ if (length < preLength) {
95
+ scroll('start');
96
+ } else {
97
+ scroll('end');
98
+ }
99
+ });
100
+ },
101
+ );
102
+
103
+ const addPage = () => {
104
+ if (!editorService) return;
105
+ const pageConfig = {
106
+ type: NodeType.PAGE,
107
+ name: generatePageNameByApp(toRaw(editorService.get('root'))),
108
+ };
109
+ editorService.add(pageConfig);
110
+ };
111
+ </script>
@@ -3,7 +3,6 @@ declare const _default: {
3
3
  $: import("vue").ComponentInternalInstance;
4
4
  $data: {};
5
5
  $props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
6
- labelWidth: string;
7
6
  config: any;
8
7
  model: any;
9
8
  prop: string;
@@ -25,7 +24,6 @@ declare const _default: {
25
24
  $emit: (event: "change", ...args: any[]) => void;
26
25
  $el: any;
27
26
  $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
28
- labelWidth: string;
29
27
  config: any;
30
28
  model: any;
31
29
  prop: string;
@@ -53,7 +51,6 @@ declare const _default: {
53
51
  $nextTick: typeof import("vue").nextTick;
54
52
  $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
55
53
  } & Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
56
- labelWidth: string;
57
54
  config: any;
58
55
  model: any;
59
56
  prop: string;
@@ -65,7 +62,6 @@ declare const _default: {
65
62
  __isTeleport?: undefined;
66
63
  __isSuspense?: undefined;
67
64
  } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
68
- labelWidth: string;
69
65
  config: any;
70
66
  model: any;
71
67
  prop: string;
@@ -0,0 +1,48 @@
1
+ declare const _default: {
2
+ new (...args: any[]): {
3
+ $: import("vue").ComponentInternalInstance;
4
+ $data: {};
5
+ $props: Partial<{}> & Omit<Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>;
6
+ $attrs: {
7
+ [x: string]: unknown;
8
+ };
9
+ $refs: {
10
+ [x: string]: unknown;
11
+ };
12
+ $slots: Readonly<{
13
+ [name: string]: import("vue").Slot | undefined;
14
+ }>;
15
+ $root: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
16
+ $parent: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null;
17
+ $emit: ((event: string, ...args: any[]) => void) | ((event: string, ...args: any[]) => void);
18
+ $el: any;
19
+ $options: import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {}> & {
20
+ beforeCreate?: ((() => void) | (() => void)[]) | undefined;
21
+ created?: ((() => void) | (() => void)[]) | undefined;
22
+ beforeMount?: ((() => void) | (() => void)[]) | undefined;
23
+ mounted?: ((() => void) | (() => void)[]) | undefined;
24
+ beforeUpdate?: ((() => void) | (() => void)[]) | undefined;
25
+ updated?: ((() => void) | (() => void)[]) | undefined;
26
+ activated?: ((() => void) | (() => void)[]) | undefined;
27
+ deactivated?: ((() => void) | (() => void)[]) | undefined;
28
+ beforeDestroy?: ((() => void) | (() => void)[]) | undefined;
29
+ beforeUnmount?: ((() => void) | (() => void)[]) | undefined;
30
+ destroyed?: ((() => void) | (() => void)[]) | undefined;
31
+ unmounted?: ((() => void) | (() => void)[]) | undefined;
32
+ renderTracked?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
33
+ renderTriggered?: (((e: import("vue").DebuggerEvent) => void) | ((e: import("vue").DebuggerEvent) => void)[]) | undefined;
34
+ errorCaptured?: (((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void) | ((err: unknown, instance: import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>> | null, info: string) => boolean | void)[]) | undefined;
35
+ };
36
+ $forceUpdate: () => void;
37
+ $nextTick: typeof import("vue").nextTick;
38
+ $watch(source: string | Function, cb: Function, options?: import("vue").WatchOptions<boolean> | undefined): import("vue").WatchStopHandle;
39
+ } & Readonly<import("vue").ExtractPropTypes<{}>> & import("vue").ShallowUnwrapRef<{}> & {} & import("vue").ComponentCustomProperties;
40
+ __isFragment?: undefined;
41
+ __isTeleport?: undefined;
42
+ __isSuspense?: undefined;
43
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, import("vue").EmitsOptions, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
44
+ $slots: {
45
+ default: (_: {}) => any;
46
+ };
47
+ });
48
+ export default _default;