@tmagic/editor 1.4.9 → 1.4.11
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/style.css +26 -0
- package/dist/tmagic-editor.js +3231 -2800
- package/dist/tmagic-editor.umd.cjs +3257 -2821
- package/package.json +12 -10
- package/src/Editor.vue +2 -1
- package/src/components/CodeParams.vue +11 -1
- package/src/editorProps.ts +3 -0
- package/src/fields/CondOpSelect.vue +87 -0
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +183 -0
- package/src/fields/DataSourceFieldSelect/Index.vue +168 -0
- package/src/fields/DataSourceFields.vue +6 -0
- package/src/fields/DisplayConds.vue +145 -0
- package/src/hooks/use-data-source-method.ts +1 -1
- package/src/index.ts +8 -2
- package/src/layouts/Framework.vue +4 -2
- package/src/layouts/page-bar/PageBar.vue +8 -2
- package/src/layouts/page-bar/PageBarScrollContainer.vue +40 -4
- package/src/layouts/page-bar/PageList.vue +55 -0
- package/src/services/ui.ts +1 -0
- package/src/theme/data-source-field-select.scss +16 -0
- package/src/theme/page-bar.scss +13 -0
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +35 -4
- package/src/utils/data-source/index.ts +9 -3
- package/src/utils/props.ts +6 -103
- package/types/editorProps.d.ts +3 -1
- package/types/fields/CondOpSelect.vue.d.ts +17 -0
- package/types/fields/DataSourceFieldSelect/FieldSelect.vue.d.ts +36 -0
- package/types/fields/{DataSourceFieldSelect.vue.d.ts → DataSourceFieldSelect/Index.vue.d.ts} +1 -1
- package/types/fields/DisplayConds.vue.d.ts +32 -0
- package/types/index.d.ts +3 -1
- package/types/layouts/Framework.vue.d.ts +3 -1
- package/types/layouts/PropsPanel.vue.d.ts +21 -21
- package/types/layouts/page-bar/PageBar.vue.d.ts +6 -0
- package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +3 -0
- package/types/layouts/page-bar/PageList.vue.d.ts +25 -0
- package/types/services/ui.d.ts +1 -0
- package/types/type.d.ts +30 -4
- package/types/utils/data-source/index.d.ts +1 -0
- package/types/utils/props.d.ts +12 -0
- package/src/fields/DataSourceFieldSelect.vue +0 -149
|
@@ -41,7 +41,7 @@ export const useDataSourceMethod = () => {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
let codeContent = method.content
|
|
44
|
+
let codeContent = method.content || `({ params, dataSource, app }) => {\n // place your code here\n}`;
|
|
45
45
|
|
|
46
46
|
if (typeof codeContent !== 'string') {
|
|
47
47
|
codeContent = codeContent.toString();
|
package/src/index.ts
CHANGED
|
@@ -21,13 +21,15 @@ import Code from './fields/Code.vue';
|
|
|
21
21
|
import CodeLink from './fields/CodeLink.vue';
|
|
22
22
|
import CodeSelect from './fields/CodeSelect.vue';
|
|
23
23
|
import CodeSelectCol from './fields/CodeSelectCol.vue';
|
|
24
|
+
import CondOpSelect from './fields/CondOpSelect.vue';
|
|
24
25
|
import DataSourceFields from './fields/DataSourceFields.vue';
|
|
25
|
-
import DataSourceFieldSelect from './fields/DataSourceFieldSelect.vue';
|
|
26
|
+
import DataSourceFieldSelect from './fields/DataSourceFieldSelect/Index.vue';
|
|
26
27
|
import DataSourceInput from './fields/DataSourceInput.vue';
|
|
27
28
|
import DataSourceMethods from './fields/DataSourceMethods.vue';
|
|
28
29
|
import DataSourceMethodSelect from './fields/DataSourceMethodSelect.vue';
|
|
29
30
|
import DataSourceMocks from './fields/DataSourceMocks.vue';
|
|
30
31
|
import DataSourceSelect from './fields/DataSourceSelect.vue';
|
|
32
|
+
import DisplayConds from './fields/DisplayConds.vue';
|
|
31
33
|
import EventSelect from './fields/EventSelect.vue';
|
|
32
34
|
import KeyValue from './fields/KeyValue.vue';
|
|
33
35
|
import PageFragmentSelect from './fields/PageFragmentSelect.vue';
|
|
@@ -68,7 +70,7 @@ export { default as DataSourceMethods } from './fields/DataSourceMethods.vue';
|
|
|
68
70
|
export { default as DataSourceInput } from './fields/DataSourceInput.vue';
|
|
69
71
|
export { default as DataSourceSelect } from './fields/DataSourceSelect.vue';
|
|
70
72
|
export { default as DataSourceMethodSelect } from './fields/DataSourceMethodSelect.vue';
|
|
71
|
-
export { default as DataSourceFieldSelect } from './fields/DataSourceFieldSelect.vue';
|
|
73
|
+
export { default as DataSourceFieldSelect } from './fields/DataSourceFieldSelect/Index.vue';
|
|
72
74
|
export { default as EventSelect } from './fields/EventSelect.vue';
|
|
73
75
|
export { default as KeyValue } from './fields/KeyValue.vue';
|
|
74
76
|
export { default as CodeBlockList } from './layouts/sidebar/code-block/CodeBlockList.vue';
|
|
@@ -84,6 +86,8 @@ export { default as Resizer } from './components/Resizer.vue';
|
|
|
84
86
|
export { default as CodeBlockEditor } from './components/CodeBlockEditor.vue';
|
|
85
87
|
export { default as FloatingBox } from './components/FloatingBox.vue';
|
|
86
88
|
export { default as PageFragmentSelect } from './fields/PageFragmentSelect.vue';
|
|
89
|
+
export { default as DisplayConds } from './fields/DisplayConds.vue';
|
|
90
|
+
export { default as CondOpSelect } from './fields/CondOpSelect.vue';
|
|
87
91
|
|
|
88
92
|
const defaultInstallOpt: InstallOptions = {
|
|
89
93
|
// eslint-disable-next-line no-eval
|
|
@@ -114,5 +118,7 @@ export default {
|
|
|
114
118
|
app.component('m-fields-data-source-method-select', DataSourceMethodSelect);
|
|
115
119
|
app.component('m-fields-data-source-field-select', DataSourceFieldSelect);
|
|
116
120
|
app.component('m-fields-page-fragment-select', PageFragmentSelect);
|
|
121
|
+
app.component('m-fields-display-conds', DisplayConds);
|
|
122
|
+
app.component('m-fields-cond-op-select', CondOpSelect);
|
|
117
123
|
},
|
|
118
124
|
};
|
|
@@ -38,9 +38,10 @@
|
|
|
38
38
|
</slot>
|
|
39
39
|
|
|
40
40
|
<slot name="page-bar">
|
|
41
|
-
<PageBar :disabled-page-fragment="disabledPageFragment">
|
|
41
|
+
<PageBar :disabled-page-fragment="disabledPageFragment" :page-bar-sort-options="pageBarSortOptions">
|
|
42
42
|
<template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
|
|
43
43
|
<template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
|
|
44
|
+
<template #page-list-popover="{ list }"><slot name="page-list-popover" :list="list"></slot></template>
|
|
44
45
|
</PageBar>
|
|
45
46
|
</slot>
|
|
46
47
|
</template>
|
|
@@ -63,7 +64,7 @@ import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
|
63
64
|
import { TMagicScrollbar } from '@tmagic/design';
|
|
64
65
|
|
|
65
66
|
import SplitView from '@editor/components/SplitView.vue';
|
|
66
|
-
import type { FrameworkSlots, GetColumnWidth, Services } from '@editor/type';
|
|
67
|
+
import type { FrameworkSlots, GetColumnWidth, PageBarSortOptions, Services } from '@editor/type';
|
|
67
68
|
import { getConfig } from '@editor/utils/config';
|
|
68
69
|
|
|
69
70
|
import PageBar from './page-bar/PageBar.vue';
|
|
@@ -78,6 +79,7 @@ defineOptions({
|
|
|
78
79
|
|
|
79
80
|
defineProps<{
|
|
80
81
|
disabledPageFragment: boolean;
|
|
82
|
+
pageBarSortOptions?: PageBarSortOptions;
|
|
81
83
|
}>();
|
|
82
84
|
|
|
83
85
|
const DEFAULT_LEFT_COLUMN_WIDTH = 310;
|
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
<div class="m-editor-page-bar-tabs">
|
|
3
3
|
<SwitchTypeButton v-if="!disabledPageFragment" v-model="active" />
|
|
4
4
|
|
|
5
|
-
<PageBarScrollContainer :type="active">
|
|
5
|
+
<PageBarScrollContainer :type="active" :page-bar-sort-options="pageBarSortOptions">
|
|
6
6
|
<template #prepend>
|
|
7
7
|
<AddButton :type="active"></AddButton>
|
|
8
|
+
<PageList :list="list">
|
|
9
|
+
<template #page-list-popover="{ list }"><slot name="page-list-popover" :list="list"></slot></template>
|
|
10
|
+
</PageList>
|
|
8
11
|
</template>
|
|
9
12
|
|
|
10
13
|
<div
|
|
11
14
|
v-for="item in list"
|
|
12
15
|
class="m-editor-page-bar-item"
|
|
13
16
|
:key="item.id"
|
|
17
|
+
:page-id="item.id"
|
|
14
18
|
:class="{ active: page?.id === item.id }"
|
|
15
19
|
@click="switchPage(item.id)"
|
|
16
20
|
>
|
|
@@ -61,11 +65,12 @@ import { Id, type MPage, type MPageFragment, NodeType } from '@tmagic/schema';
|
|
|
61
65
|
import { isPage, isPageFragment } from '@tmagic/utils';
|
|
62
66
|
|
|
63
67
|
import ToolButton from '@editor/components/ToolButton.vue';
|
|
64
|
-
import type { Services } from '@editor/type';
|
|
68
|
+
import type { PageBarSortOptions, Services } from '@editor/type';
|
|
65
69
|
import { getPageFragmentList, getPageList } from '@editor/utils';
|
|
66
70
|
|
|
67
71
|
import AddButton from './AddButton.vue';
|
|
68
72
|
import PageBarScrollContainer from './PageBarScrollContainer.vue';
|
|
73
|
+
import PageList from './PageList.vue';
|
|
69
74
|
import SwitchTypeButton from './SwitchTypeButton.vue';
|
|
70
75
|
|
|
71
76
|
defineOptions({
|
|
@@ -74,6 +79,7 @@ defineOptions({
|
|
|
74
79
|
|
|
75
80
|
defineProps<{
|
|
76
81
|
disabledPageFragment: boolean;
|
|
82
|
+
pageBarSortOptions?: PageBarSortOptions;
|
|
77
83
|
}>();
|
|
78
84
|
|
|
79
85
|
const active = ref<NodeType.PAGE | NodeType.PAGE_FRAGMENT>(NodeType.PAGE);
|
|
@@ -34,11 +34,12 @@ import {
|
|
|
34
34
|
type WatchStopHandle,
|
|
35
35
|
} from 'vue';
|
|
36
36
|
import { ArrowLeftBold, ArrowRightBold } from '@element-plus/icons-vue';
|
|
37
|
+
import Sortable, { SortableEvent } from 'sortablejs';
|
|
37
38
|
|
|
38
|
-
import { NodeType } from '@tmagic/schema';
|
|
39
|
+
import { Id, NodeType } from '@tmagic/schema';
|
|
39
40
|
|
|
40
41
|
import Icon from '@editor/components/Icon.vue';
|
|
41
|
-
import type { Services } from '@editor/type';
|
|
42
|
+
import type { PageBarSortOptions, Services } from '@editor/type';
|
|
42
43
|
|
|
43
44
|
defineOptions({
|
|
44
45
|
name: 'MEditorPageBarScrollContainer',
|
|
@@ -46,23 +47,29 @@ defineOptions({
|
|
|
46
47
|
|
|
47
48
|
const props = defineProps<{
|
|
48
49
|
type: NodeType.PAGE | NodeType.PAGE_FRAGMENT;
|
|
50
|
+
pageBarSortOptions?: PageBarSortOptions;
|
|
49
51
|
}>();
|
|
50
52
|
|
|
51
53
|
const services = inject<Services>('services');
|
|
52
54
|
const editorService = services?.editorService;
|
|
53
55
|
const uiService = services?.uiService;
|
|
54
56
|
|
|
55
|
-
const itemsContainer = ref<
|
|
57
|
+
const itemsContainer = ref<HTMLElement>();
|
|
56
58
|
const canScroll = ref(false);
|
|
57
59
|
|
|
58
60
|
const showAddPageButton = computed(() => uiService?.get('showAddPageButton'));
|
|
61
|
+
const showPageListButton = computed(() => uiService?.get('showPageListButton'));
|
|
59
62
|
|
|
60
63
|
const itemsContainerWidth = ref(0);
|
|
61
64
|
|
|
62
65
|
const setCanScroll = () => {
|
|
63
66
|
// 减去新增、左移、右移三个按钮的宽度
|
|
64
67
|
// 37 = icon width 16 + padding 10 * 2 + border-right 1
|
|
65
|
-
itemsContainerWidth.value =
|
|
68
|
+
itemsContainerWidth.value =
|
|
69
|
+
(pageBar.value?.clientWidth || 0) -
|
|
70
|
+
37 * 2 -
|
|
71
|
+
(showAddPageButton.value ? 37 : 21) -
|
|
72
|
+
(showPageListButton.value ? 37 : 0);
|
|
66
73
|
|
|
67
74
|
nextTick(() => {
|
|
68
75
|
if (itemsContainer.value) {
|
|
@@ -126,6 +133,35 @@ const crateWatchLength = (length: ComputedRef<number>) =>
|
|
|
126
133
|
} else {
|
|
127
134
|
scroll('end');
|
|
128
135
|
}
|
|
136
|
+
if (length > 1) {
|
|
137
|
+
const el = document.querySelector('.m-editor-page-bar-items') as HTMLElement;
|
|
138
|
+
let beforeDragList: Id[] = [];
|
|
139
|
+
const options = {
|
|
140
|
+
...{
|
|
141
|
+
dataIdAttr: 'page-id', // 获取排序后的数据
|
|
142
|
+
onStart: async (event: SortableEvent) => {
|
|
143
|
+
if (typeof props.pageBarSortOptions?.beforeStart === 'function') {
|
|
144
|
+
await props.pageBarSortOptions.beforeStart(event, sortable);
|
|
145
|
+
}
|
|
146
|
+
beforeDragList = sortable.toArray();
|
|
147
|
+
},
|
|
148
|
+
onUpdate: async (event: SortableEvent) => {
|
|
149
|
+
await editorService?.sort(
|
|
150
|
+
beforeDragList[event.oldIndex as number],
|
|
151
|
+
beforeDragList[event.newIndex as number],
|
|
152
|
+
);
|
|
153
|
+
if (typeof props.pageBarSortOptions?.afterUpdate === 'function') {
|
|
154
|
+
await props.pageBarSortOptions.afterUpdate(event, sortable);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
...{
|
|
159
|
+
...(props.pageBarSortOptions ? props.pageBarSortOptions : {}),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
if (!el) return;
|
|
163
|
+
const sortable = new Sortable(el, options);
|
|
164
|
+
}
|
|
129
165
|
});
|
|
130
166
|
},
|
|
131
167
|
{
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
v-if="showPageListButton"
|
|
4
|
+
id="m-editor-page-bar-list-icon"
|
|
5
|
+
class="m-editor-page-bar-item m-editor-page-bar-item-icon"
|
|
6
|
+
>
|
|
7
|
+
<TMagicPopover popper-class="page-bar-popover" placement="top" :width="160" trigger="hover">
|
|
8
|
+
<div>
|
|
9
|
+
<slot name="page-list-popover" :list="list">
|
|
10
|
+
<ToolButton
|
|
11
|
+
v-for="(item, index) in list"
|
|
12
|
+
:data="{
|
|
13
|
+
type: 'button',
|
|
14
|
+
text: item.devconfig?.tabName || item.name || item.id,
|
|
15
|
+
handler: () => switchPage(item.id),
|
|
16
|
+
}"
|
|
17
|
+
:key="index"
|
|
18
|
+
></ToolButton>
|
|
19
|
+
</slot>
|
|
20
|
+
</div>
|
|
21
|
+
<template #reference>
|
|
22
|
+
<TMagicIcon class="m-editor-page-list-menu-icon">
|
|
23
|
+
<Files></Files>
|
|
24
|
+
</TMagicIcon>
|
|
25
|
+
</template>
|
|
26
|
+
</TMagicPopover>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script setup lang="ts">
|
|
31
|
+
import { computed, inject } from 'vue';
|
|
32
|
+
import { Files } from '@element-plus/icons-vue';
|
|
33
|
+
|
|
34
|
+
import { TMagicIcon, TMagicPopover } from '@tmagic/design';
|
|
35
|
+
import { Id, MPage, MPageFragment } from '@tmagic/schema';
|
|
36
|
+
|
|
37
|
+
import ToolButton from '@editor/components/ToolButton.vue';
|
|
38
|
+
import type { Services } from '@editor/type';
|
|
39
|
+
defineOptions({
|
|
40
|
+
name: 'MEditorPageList',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
defineProps<{
|
|
44
|
+
list: MPage[] | MPageFragment[];
|
|
45
|
+
}>();
|
|
46
|
+
|
|
47
|
+
const services = inject<Services>('services');
|
|
48
|
+
const uiService = services?.uiService;
|
|
49
|
+
const editorService = services?.editorService;
|
|
50
|
+
|
|
51
|
+
const showPageListButton = computed(() => uiService?.get('showPageListButton'));
|
|
52
|
+
const switchPage = (id: Id) => {
|
|
53
|
+
editorService?.select(id);
|
|
54
|
+
};
|
|
55
|
+
</script>
|
package/src/services/ui.ts
CHANGED
package/src/theme/page-bar.scss
CHANGED
|
@@ -18,6 +18,19 @@
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
.m-editor-page-list-item {
|
|
22
|
+
display: flex;
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: $--page-bar-height;
|
|
25
|
+
line-height: $--page-bar-height;
|
|
26
|
+
color: $--font-color;
|
|
27
|
+
z-index: 2;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
&:hover {
|
|
30
|
+
background-color: $--hover-color;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
.m-editor-page-bar {
|
|
22
35
|
display: flex;
|
|
23
36
|
width: 100%;
|
package/src/theme/theme.scss
CHANGED
package/src/type.ts
CHANGED
|
@@ -18,13 +18,15 @@
|
|
|
18
18
|
|
|
19
19
|
import type { Component } from 'vue';
|
|
20
20
|
import type EventEmitter from 'events';
|
|
21
|
+
import Sortable, { Options, SortableEvent } from 'sortablejs';
|
|
21
22
|
import type { PascalCasedProperties } from 'type-fest';
|
|
22
23
|
|
|
23
|
-
import type { ChildConfig, ColumnConfig, FilterFunction, FormConfig, FormItem, Input } from '@tmagic/form';
|
|
24
|
+
import type { ChildConfig, ColumnConfig, FilterFunction, FormConfig, FormItem, FormState, Input } from '@tmagic/form';
|
|
24
25
|
import type {
|
|
25
26
|
CodeBlockContent,
|
|
26
27
|
CodeBlockDSL,
|
|
27
28
|
DataSourceFieldType,
|
|
29
|
+
DataSourceSchema,
|
|
28
30
|
Id,
|
|
29
31
|
MApp,
|
|
30
32
|
MContainer,
|
|
@@ -55,7 +57,6 @@ import type { StageOverlayService } from './services/stageOverlay';
|
|
|
55
57
|
import type { StorageService } from './services/storage';
|
|
56
58
|
import type { UiService } from './services/ui';
|
|
57
59
|
import type { UndoRedo } from './utils/undo-redo';
|
|
58
|
-
|
|
59
60
|
export interface FrameworkSlots {
|
|
60
61
|
header(props: {}): any;
|
|
61
62
|
nav(props: {}): any;
|
|
@@ -70,6 +71,7 @@ export interface FrameworkSlots {
|
|
|
70
71
|
'page-bar'(props: {}): any;
|
|
71
72
|
'page-bar-title'(props: { page: MPage | MPageFragment }): any;
|
|
72
73
|
'page-bar-popover'(props: { page: MPage | MPageFragment }): any;
|
|
74
|
+
'page-list-popover'(props: { list: MPage[] | MPageFragment[] }): any;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
export interface WorkspaceSlots {
|
|
@@ -238,6 +240,8 @@ export interface UiState {
|
|
|
238
240
|
propsPanelSize: 'large' | 'default' | 'small';
|
|
239
241
|
/** 是否显示新增页面按钮 */
|
|
240
242
|
showAddPageButton: boolean;
|
|
243
|
+
/** 是否在页面工具栏显示呼起页面列表按钮 */
|
|
244
|
+
showPageListButton: boolean;
|
|
241
245
|
/** 是否隐藏侧边栏 */
|
|
242
246
|
hideSlideBar: boolean;
|
|
243
247
|
/** 侧边栏面板配置 */
|
|
@@ -646,19 +650,38 @@ export interface DataSourceMethodSelectConfig extends FormItem {
|
|
|
646
650
|
|
|
647
651
|
export interface DataSourceFieldSelectConfig extends FormItem {
|
|
648
652
|
type: 'data-source-field-select';
|
|
649
|
-
/**
|
|
653
|
+
/**
|
|
654
|
+
* 是否要编译成数据源的data。
|
|
650
655
|
* key: 不编译,就是要数据源id和field name;
|
|
651
656
|
* value: 要编译(数据源data[`${filed}`])
|
|
652
657
|
* */
|
|
653
658
|
value?: 'key' | 'value';
|
|
654
659
|
/** 是否严格的遵守父子节点不互相关联 */
|
|
655
|
-
checkStrictly?:
|
|
660
|
+
checkStrictly?:
|
|
661
|
+
| boolean
|
|
662
|
+
| ((
|
|
663
|
+
mForm: FormState | undefined,
|
|
664
|
+
data: {
|
|
665
|
+
model: Record<any, any>;
|
|
666
|
+
values: Record<any, any>;
|
|
667
|
+
parent?: Record<any, any>;
|
|
668
|
+
formValue: Record<any, any>;
|
|
669
|
+
prop: string;
|
|
670
|
+
config: DataSourceFieldSelectConfig;
|
|
671
|
+
dataSource?: DataSourceSchema;
|
|
672
|
+
},
|
|
673
|
+
) => boolean);
|
|
656
674
|
dataSourceFieldType?: DataSourceFieldType[];
|
|
657
675
|
fieldConfig?: ChildConfig;
|
|
658
676
|
/** 是否可以编辑数据源,disable表示的是是否可以选择数据源 */
|
|
659
677
|
notEditable?: boolean | FilterFunction;
|
|
660
678
|
}
|
|
661
679
|
|
|
680
|
+
export interface CondOpSelectConfig extends FormItem {
|
|
681
|
+
type: 'cond-op';
|
|
682
|
+
parentFields?: string[];
|
|
683
|
+
}
|
|
684
|
+
|
|
662
685
|
/** 可新增的数据源类型选项 */
|
|
663
686
|
export interface DatasourceTypeOption {
|
|
664
687
|
/** 数据源类型 */
|
|
@@ -747,3 +770,11 @@ export interface EventBus extends EventEmitter {
|
|
|
747
770
|
|
|
748
771
|
export type PropsFormConfigFunction = (data: { editorService: EditorService }) => FormConfig;
|
|
749
772
|
export type PropsFormValueFunction = (data: { editorService: EditorService }) => Partial<MNode>;
|
|
773
|
+
|
|
774
|
+
export type PartSortableOptions = Omit<Options, 'onStart' | 'onUpdate'>;
|
|
775
|
+
export interface PageBarSortOptions extends PartSortableOptions {
|
|
776
|
+
/** 在onUpdate之后调用 */
|
|
777
|
+
afterUpdate?: (event: SortableEvent, sortable: Sortable) => void;
|
|
778
|
+
/** 在onStart之前调用 */
|
|
779
|
+
beforeStart?: (event: SortableEvent, sortable: Sortable) => void;
|
|
780
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CascaderOption, FormConfig, FormState } from '@tmagic/form';
|
|
2
2
|
import { DataSchema, DataSourceFieldType, DataSourceSchema } from '@tmagic/schema';
|
|
3
|
-
import { isNumber } from '@tmagic/utils';
|
|
3
|
+
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, isNumber } from '@tmagic/utils';
|
|
4
4
|
|
|
5
5
|
import BaseFormConfig from './formConfigs/base';
|
|
6
6
|
import HttpFormConfig from './formConfigs/http';
|
|
@@ -215,10 +215,13 @@ export const getCascaderOptionsFromFields = (
|
|
|
215
215
|
dataSourceFieldType.push('any');
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
let children: CascaderOption[] = [];
|
|
219
|
+
if (field.type && ['any', 'array', 'object'].includes(field.type)) {
|
|
220
|
+
children = getCascaderOptionsFromFields(field.fields, dataSourceFieldType);
|
|
221
|
+
}
|
|
219
222
|
|
|
220
223
|
const item = {
|
|
221
|
-
label: field.title || field.name
|
|
224
|
+
label: `${field.title || field.name}(${field.type})`,
|
|
222
225
|
value: field.name,
|
|
223
226
|
children,
|
|
224
227
|
};
|
|
@@ -241,3 +244,6 @@ export const getCascaderOptionsFromFields = (
|
|
|
241
244
|
});
|
|
242
245
|
return child;
|
|
243
246
|
};
|
|
247
|
+
|
|
248
|
+
export const removeDataSourceFieldPrefix = (id?: string) =>
|
|
249
|
+
id?.replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, '') || '';
|
package/src/utils/props.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
2
|
/*
|
|
2
3
|
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
4
|
*
|
|
@@ -18,19 +19,17 @@
|
|
|
18
19
|
|
|
19
20
|
import type { FormConfig, FormState, TabPaneConfig } from '@tmagic/form';
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const arrayOptions = [
|
|
22
|
+
export const arrayOptions = [
|
|
24
23
|
{ text: '包含', value: 'include' },
|
|
25
24
|
{ text: '不包含', value: 'not_include' },
|
|
26
25
|
];
|
|
27
26
|
|
|
28
|
-
const eqOptions = [
|
|
27
|
+
export const eqOptions = [
|
|
29
28
|
{ text: '等于', value: '=' },
|
|
30
29
|
{ text: '不等于', value: '!=' },
|
|
31
30
|
];
|
|
32
31
|
|
|
33
|
-
const numberOptions = [
|
|
32
|
+
export const numberOptions = [
|
|
34
33
|
{ text: '大于', value: '>' },
|
|
35
34
|
{ text: '大于等于', value: '>=' },
|
|
36
35
|
{ text: '小于', value: '<' },
|
|
@@ -359,106 +358,10 @@ export const displayTabConfig: TabPaneConfig = {
|
|
|
359
358
|
display: (vm: FormState, { model }: any) => model.type !== 'page',
|
|
360
359
|
items: [
|
|
361
360
|
{
|
|
362
|
-
type: '
|
|
361
|
+
type: 'display-conds',
|
|
363
362
|
name: 'displayConds',
|
|
364
363
|
titlePrefix: '条件组',
|
|
365
|
-
|
|
366
|
-
items: [
|
|
367
|
-
{
|
|
368
|
-
type: 'table',
|
|
369
|
-
name: 'cond',
|
|
370
|
-
items: [
|
|
371
|
-
{
|
|
372
|
-
type: 'data-source-field-select',
|
|
373
|
-
name: 'field',
|
|
374
|
-
value: 'key',
|
|
375
|
-
label: '字段',
|
|
376
|
-
checkStrictly: false,
|
|
377
|
-
dataSourceFieldType: ['string', 'number', 'boolean', 'any'],
|
|
378
|
-
},
|
|
379
|
-
{
|
|
380
|
-
type: 'select',
|
|
381
|
-
options: (mForm, { model }) => {
|
|
382
|
-
const [id, ...fieldNames] = model.field;
|
|
383
|
-
|
|
384
|
-
const ds = dataSourceService.getDataSourceById(id);
|
|
385
|
-
|
|
386
|
-
let fields = ds?.fields || [];
|
|
387
|
-
let type = '';
|
|
388
|
-
(fieldNames || []).forEach((fieldName: string) => {
|
|
389
|
-
const field = fields.find((f) => f.name === fieldName);
|
|
390
|
-
fields = field?.fields || [];
|
|
391
|
-
type = field?.type || '';
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
if (type === 'array') {
|
|
395
|
-
return arrayOptions;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (type === 'boolean') {
|
|
399
|
-
return [
|
|
400
|
-
{ text: '是', value: 'is' },
|
|
401
|
-
{ text: '不是', value: 'not' },
|
|
402
|
-
];
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (type === 'number') {
|
|
406
|
-
return [...eqOptions, ...numberOptions];
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (type === 'string') {
|
|
410
|
-
return [...arrayOptions, ...eqOptions];
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return [...arrayOptions, ...eqOptions, ...numberOptions];
|
|
414
|
-
},
|
|
415
|
-
label: '条件',
|
|
416
|
-
name: 'op',
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
label: '值',
|
|
420
|
-
items: [
|
|
421
|
-
{
|
|
422
|
-
name: 'value',
|
|
423
|
-
type: (mForm, { model }) => {
|
|
424
|
-
const [id, ...fieldNames] = model.field;
|
|
425
|
-
|
|
426
|
-
const ds = dataSourceService.getDataSourceById(id);
|
|
427
|
-
|
|
428
|
-
let fields = ds?.fields || [];
|
|
429
|
-
let type = '';
|
|
430
|
-
(fieldNames || []).forEach((fieldName: string) => {
|
|
431
|
-
const field = fields.find((f) => f.name === fieldName);
|
|
432
|
-
fields = field?.fields || [];
|
|
433
|
-
type = field?.type || '';
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
if (type === 'number') {
|
|
437
|
-
return 'number';
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
if (type === 'boolean') {
|
|
441
|
-
return 'select';
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
return 'text';
|
|
445
|
-
},
|
|
446
|
-
options: [
|
|
447
|
-
{ text: 'true', value: true },
|
|
448
|
-
{ text: 'false', value: false },
|
|
449
|
-
],
|
|
450
|
-
display: (vm, { model }) => !['between', 'not_between'].includes(model.op),
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
name: 'range',
|
|
454
|
-
type: 'number-range',
|
|
455
|
-
display: (vm, { model }) => ['between', 'not_between'].includes(model.op),
|
|
456
|
-
},
|
|
457
|
-
],
|
|
458
|
-
},
|
|
459
|
-
],
|
|
460
|
-
},
|
|
461
|
-
],
|
|
364
|
+
defaultValue: [],
|
|
462
365
|
},
|
|
463
366
|
],
|
|
464
367
|
};
|
package/types/editorProps.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { EventOption } from '@tmagic/core';
|
|
|
2
2
|
import type { FormConfig, FormState } from '@tmagic/form';
|
|
3
3
|
import type { DataSourceSchema, Id, MApp, MNode } from '@tmagic/schema';
|
|
4
4
|
import StageCore, { ContainerHighlightType, type CustomizeMoveableOptionsCallbackConfig, type GuidesOptions, type MoveableOptions, RenderType, type UpdateDragEl } from '@tmagic/stage';
|
|
5
|
-
import type { ComponentGroup, DatasourceTypeOption, MenuBarData, MenuButton, MenuComponent, SideBarData, StageRect } from './type';
|
|
5
|
+
import type { ComponentGroup, DatasourceTypeOption, MenuBarData, MenuButton, MenuComponent, PageBarSortOptions, SideBarData, StageRect } from './type';
|
|
6
6
|
export interface EditorProps {
|
|
7
7
|
/** 页面初始值 */
|
|
8
8
|
modelValue?: MApp;
|
|
@@ -80,6 +80,8 @@ export interface EditorProps {
|
|
|
80
80
|
/** 用于自定义组件树与画布的右键菜单 */
|
|
81
81
|
customContentMenu?: (menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[];
|
|
82
82
|
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
|
83
|
+
/** 页面顺序拖拽配置参数 */
|
|
84
|
+
pageBarSortOptions?: PageBarSortOptions;
|
|
83
85
|
}
|
|
84
86
|
export declare const defaultEditorProps: {
|
|
85
87
|
renderType: RenderType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FieldProps } from '@tmagic/form';
|
|
2
|
+
import type { CondOpSelectConfig } from '../type';
|
|
3
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<FieldProps<CondOpSelectConfig>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
4
|
+
change: (...args: any[]) => void;
|
|
5
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<FieldProps<CondOpSelectConfig>>>> & {
|
|
6
|
+
onChange?: ((...args: any[]) => any) | undefined;
|
|
7
|
+
}, {}, {}>;
|
|
8
|
+
export default _default;
|
|
9
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
10
|
+
type __VLS_TypePropsToOption<T> = {
|
|
11
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
12
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
13
|
+
} : {
|
|
14
|
+
type: import('vue').PropType<T[K]>;
|
|
15
|
+
required: true;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type FilterFunction } from '@tmagic/form';
|
|
2
|
+
import { DataSourceFieldType } from '@tmagic/schema';
|
|
3
|
+
declare let __VLS_typeProps: {
|
|
4
|
+
/**
|
|
5
|
+
* 是否要编译成数据源的data。
|
|
6
|
+
* key: 不编译,就是要数据源id和field name;
|
|
7
|
+
* value: 要编译(数据源data[`${filed}`])
|
|
8
|
+
* */
|
|
9
|
+
value?: 'key' | 'value';
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
checkStrictly?: boolean;
|
|
12
|
+
size?: 'large' | 'default' | 'small';
|
|
13
|
+
dataSourceFieldType?: DataSourceFieldType[];
|
|
14
|
+
/** 是否可以编辑数据源,disable表示的是是否可以选择数据源 */
|
|
15
|
+
notEditable?: boolean | FilterFunction;
|
|
16
|
+
};
|
|
17
|
+
type __VLS_PublicProps = {
|
|
18
|
+
'modelValue'?: string[] | any;
|
|
19
|
+
} & typeof __VLS_typeProps;
|
|
20
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToOption<__VLS_PublicProps>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
21
|
+
"update:modelValue": (modelValue: any) => void;
|
|
22
|
+
change: (v: string[]) => void;
|
|
23
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToOption<__VLS_PublicProps>>> & {
|
|
24
|
+
onChange?: ((v: string[]) => any) | undefined;
|
|
25
|
+
"onUpdate:modelValue"?: ((modelValue: any) => any) | undefined;
|
|
26
|
+
}, {}, {}>;
|
|
27
|
+
export default _default;
|
|
28
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
29
|
+
type __VLS_TypePropsToOption<T> = {
|
|
30
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
31
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
32
|
+
} : {
|
|
33
|
+
type: import('vue').PropType<T[K]>;
|
|
34
|
+
required: true;
|
|
35
|
+
};
|
|
36
|
+
};
|
package/types/fields/{DataSourceFieldSelect.vue.d.ts → DataSourceFieldSelect/Index.vue.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FieldProps } from '@tmagic/form';
|
|
2
|
-
import type { DataSourceFieldSelectConfig } from '
|
|
2
|
+
import type { DataSourceFieldSelectConfig } from '../../type';
|
|
3
3
|
declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToOption<FieldProps<DataSourceFieldSelectConfig>>, {
|
|
4
4
|
disabled: boolean;
|
|
5
5
|
}>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|