@tmagic/editor 1.4.7 → 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 (152) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +314 -452
  3. package/dist/tmagic-editor.umd.cjs +313 -450
  4. package/package.json +15 -11
  5. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  6. package/types/services/editor.d.ts +19 -2
  7. package/types/services/props.d.ts +5 -5
  8. package/types/type.d.ts +6 -0
  9. package/types/utils/editor.d.ts +1 -0
  10. package/src/Editor.vue +0 -211
  11. package/src/components/CodeBlockEditor.vue +0 -268
  12. package/src/components/CodeParams.vue +0 -60
  13. package/src/components/ContentMenu.vue +0 -193
  14. package/src/components/FloatingBox.vue +0 -178
  15. package/src/components/Icon.vue +0 -27
  16. package/src/components/Resizer.vue +0 -23
  17. package/src/components/ScrollBar.vue +0 -151
  18. package/src/components/ScrollViewer.vue +0 -128
  19. package/src/components/SearchInput.vue +0 -37
  20. package/src/components/SplitView.vue +0 -186
  21. package/src/components/ToolButton.vue +0 -138
  22. package/src/components/Tree.vue +0 -71
  23. package/src/components/TreeNode.vue +0 -150
  24. package/src/editorProps.ts +0 -117
  25. package/src/fields/Code.vue +0 -50
  26. package/src/fields/CodeLink.vue +0 -80
  27. package/src/fields/CodeSelect.vue +0 -132
  28. package/src/fields/CodeSelectCol.vue +0 -139
  29. package/src/fields/DataSourceFieldSelect.vue +0 -149
  30. package/src/fields/DataSourceFields.vue +0 -323
  31. package/src/fields/DataSourceInput.vue +0 -331
  32. package/src/fields/DataSourceMethodSelect.vue +0 -153
  33. package/src/fields/DataSourceMethods.vue +0 -104
  34. package/src/fields/DataSourceMocks.vue +0 -255
  35. package/src/fields/DataSourceSelect.vue +0 -98
  36. package/src/fields/EventSelect.vue +0 -375
  37. package/src/fields/KeyValue.vue +0 -137
  38. package/src/fields/PageFragmentSelect.vue +0 -63
  39. package/src/fields/UISelect.vue +0 -135
  40. package/src/hooks/index.ts +0 -24
  41. package/src/hooks/use-code-block-edit.ts +0 -83
  42. package/src/hooks/use-data-source-edit.ts +0 -46
  43. package/src/hooks/use-data-source-method.ts +0 -100
  44. package/src/hooks/use-editor-content-height.ts +0 -26
  45. package/src/hooks/use-filter.ts +0 -55
  46. package/src/hooks/use-float-box.ts +0 -76
  47. package/src/hooks/use-getso.ts +0 -35
  48. package/src/hooks/use-next-float-box-position.ts +0 -29
  49. package/src/hooks/use-node-status.ts +0 -48
  50. package/src/hooks/use-stage.ts +0 -129
  51. package/src/hooks/use-window-rect.ts +0 -20
  52. package/src/icons/AppManageIcon.vue +0 -15
  53. package/src/icons/CenterIcon.vue +0 -13
  54. package/src/icons/CodeIcon.vue +0 -28
  55. package/src/icons/FolderMinusIcon.vue +0 -22
  56. package/src/icons/PinIcon.vue +0 -25
  57. package/src/icons/PinnedIcon.vue +0 -25
  58. package/src/index.ts +0 -118
  59. package/src/initService.ts +0 -443
  60. package/src/layouts/AddPageBox.vue +0 -55
  61. package/src/layouts/CodeEditor.vue +0 -226
  62. package/src/layouts/Framework.vue +0 -163
  63. package/src/layouts/NavMenu.vue +0 -200
  64. package/src/layouts/PropsPanel.vue +0 -130
  65. package/src/layouts/page-bar/AddButton.vue +0 -48
  66. package/src/layouts/page-bar/PageBar.vue +0 -159
  67. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  68. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  69. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  70. package/src/layouts/sidebar/Sidebar.vue +0 -278
  71. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -160
  72. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  73. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  74. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -172
  75. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  76. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  77. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  78. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  79. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  80. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  81. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  82. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  83. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  84. package/src/layouts/workspace/Workspace.vue +0 -46
  85. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  86. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  87. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  88. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  89. package/src/services/BaseService.ts +0 -230
  90. package/src/services/codeBlock.ts +0 -327
  91. package/src/services/componentList.ts +0 -58
  92. package/src/services/dataSource.ts +0 -216
  93. package/src/services/dep.ts +0 -152
  94. package/src/services/editor.ts +0 -1096
  95. package/src/services/events.ts +0 -93
  96. package/src/services/history.ts +0 -126
  97. package/src/services/keybinding.ts +0 -220
  98. package/src/services/props.ts +0 -271
  99. package/src/services/stageOverlay.ts +0 -212
  100. package/src/services/storage.ts +0 -155
  101. package/src/services/ui.ts +0 -156
  102. package/src/shims-vue.d.ts +0 -6
  103. package/src/theme/breadcrumb.scss +0 -6
  104. package/src/theme/code-block.scss +0 -6
  105. package/src/theme/code-editor.scss +0 -38
  106. package/src/theme/common/var.scss +0 -14
  107. package/src/theme/component-list-panel.scss +0 -95
  108. package/src/theme/content-menu.scss +0 -76
  109. package/src/theme/data-source-field.scss +0 -12
  110. package/src/theme/data-source-fields.scss +0 -13
  111. package/src/theme/data-source-input.scss +0 -18
  112. package/src/theme/data-source-methods.scss +0 -13
  113. package/src/theme/data-source.scss +0 -28
  114. package/src/theme/event.scss +0 -37
  115. package/src/theme/floating-box.scss +0 -32
  116. package/src/theme/framework.scss +0 -69
  117. package/src/theme/icon.scss +0 -12
  118. package/src/theme/index.scss +0 -10
  119. package/src/theme/key-value.scss +0 -20
  120. package/src/theme/layer-panel.scss +0 -26
  121. package/src/theme/layout.scss +0 -9
  122. package/src/theme/nav-menu.scss +0 -78
  123. package/src/theme/page-bar.scss +0 -89
  124. package/src/theme/page-fragment-select.scss +0 -14
  125. package/src/theme/props-panel.scss +0 -55
  126. package/src/theme/resizer.scss +0 -66
  127. package/src/theme/ruler.scss +0 -38
  128. package/src/theme/search-input.scss +0 -14
  129. package/src/theme/sidebar.scss +0 -79
  130. package/src/theme/stage.scss +0 -76
  131. package/src/theme/theme.scss +0 -27
  132. package/src/theme/tree.scss +0 -89
  133. package/src/theme/workspace.scss +0 -9
  134. package/src/type.ts +0 -746
  135. package/src/utils/compose.ts +0 -52
  136. package/src/utils/config.ts +0 -29
  137. package/src/utils/content-menu.ts +0 -95
  138. package/src/utils/data-source/formConfigs/base.ts +0 -30
  139. package/src/utils/data-source/formConfigs/http.ts +0 -60
  140. package/src/utils/data-source/index.ts +0 -243
  141. package/src/utils/editor.ts +0 -294
  142. package/src/utils/idle-task.ts +0 -72
  143. package/src/utils/index.ts +0 -24
  144. package/src/utils/keybinding-config.ts +0 -125
  145. package/src/utils/logger.ts +0 -47
  146. package/src/utils/monaco-editor.ts +0 -8
  147. package/src/utils/operator.ts +0 -106
  148. package/src/utils/props.ts +0 -504
  149. package/src/utils/scroll-viewer.ts +0 -165
  150. package/src/utils/tree.ts +0 -15
  151. package/src/utils/undo-redo.ts +0 -76
  152. package/tsconfig.build.json +0 -16
@@ -1,117 +0,0 @@
1
- import type { EventOption } from '@tmagic/core';
2
- import type { FormConfig, FormState } from '@tmagic/form';
3
- import type { DataSourceSchema, Id, MApp, MNode } from '@tmagic/schema';
4
- import StageCore, {
5
- CONTAINER_HIGHLIGHT_CLASS_NAME,
6
- ContainerHighlightType,
7
- type CustomizeMoveableOptionsCallbackConfig,
8
- type GuidesOptions,
9
- type MoveableOptions,
10
- RenderType,
11
- type UpdateDragEl,
12
- } from '@tmagic/stage';
13
-
14
- import type {
15
- ComponentGroup,
16
- DatasourceTypeOption,
17
- MenuBarData,
18
- MenuButton,
19
- MenuComponent,
20
- SideBarData,
21
- StageRect,
22
- } from './type';
23
-
24
- export interface EditorProps {
25
- /** 页面初始值 */
26
- modelValue?: MApp;
27
- /** 左侧面板中的组件类型列表 */
28
- componentGroupList?: ComponentGroup[];
29
- /** 左侧面板中的数据源类型列表 */
30
- datasourceList?: DatasourceTypeOption[];
31
- /** 左侧面板配置 */
32
- sidebar?: SideBarData;
33
- /** 顶部工具栏配置 */
34
- menu?: MenuBarData;
35
- /** 组件树右键菜单 */
36
- layerContentMenu?: (MenuButton | MenuComponent)[];
37
- /** 画布右键菜单 */
38
- stageContentMenu?: (MenuButton | MenuComponent)[];
39
- /** 中间工作区域中画布通过iframe渲染时的页面url */
40
- runtimeUrl?: string;
41
- /** 是用iframe渲染还是直接渲染 */
42
- renderType?: RenderType;
43
- /** 选中时是否自动滚动到可视区域 */
44
- autoScrollIntoView?: boolean;
45
- /** 组件的属性配置表单的dsl */
46
- propsConfigs?: Record<string, FormConfig>;
47
- /** 添加组件时的默认值 */
48
- propsValues?: Record<string, Partial<MNode>>;
49
- /** 组件联动事件选项列表 */
50
- eventMethodList?: Record<string, { events: EventOption[]; methods: EventOption[] }>;
51
- /** 添加数据源时的默认值 */
52
- datasourceValues?: Record<string, Partial<DataSourceSchema>>;
53
- /** 数据源的属性配置表单的dsl */
54
- datasourceConfigs?: Record<string, FormConfig>;
55
- datasourceEventMethodList?: Record<string, { events: EventOption[]; methods: EventOption[] }>;
56
- /** 画布中组件选中框的移动范围 */
57
- moveableOptions?: MoveableOptions | ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions);
58
- /** 编辑器初始化时默认选中的组件ID */
59
- defaultSelected?: Id;
60
- /** 拖入画布中容器时,识别到容器后给容器根dom加上的class */
61
- containerHighlightClassName?: string;
62
- /** 拖入画布中容器时,悬停识别容器的时间 */
63
- containerHighlightDuration?: number;
64
- /** 拖入画布中容器时,识别容器的操作类型 */
65
- containerHighlightType?: ContainerHighlightType;
66
- /** 画布大小 */
67
- stageRect?: StageRect;
68
- /** monaco editor 的配置 */
69
- codeOptions?: { [key: string]: any };
70
- /** 禁用鼠标左键按下时就开始拖拽,需要先选中再可以拖拽 */
71
- disabledDragStart?: boolean;
72
- /** 标尺配置 */
73
- guidesOptions?: Partial<GuidesOptions>;
74
- /** 禁止多选 */
75
- disabledMultiSelect?: boolean;
76
- /** 禁用页面片 */
77
- disabledPageFragment?: boolean;
78
- /** 禁用双击在浮层中单独编辑选中组件 */
79
- disabledStageOverlay?: boolean;
80
- /** 禁用属性配置面板右下角显示源码的按钮 */
81
- disabledShowSrc?: boolean;
82
- /** 中间工作区域中画布渲染的内容 */
83
- render?: (stage: StageCore) => HTMLDivElement | Promise<HTMLDivElement>;
84
- /** 选中时会在画布上复制出一个大小相同的dom,实际拖拽的是这个dom,此方法用于干预这个dom的生成方式 */
85
- updateDragEl?: UpdateDragEl;
86
- /** 用于设置画布上的dom是否可以被选中 */
87
- canSelect?: (el: HTMLElement) => boolean | Promise<boolean>;
88
- /** 用于设置画布上的dom是否可以被拖入其中 */
89
- isContainer?: (el: HTMLElement) => boolean | Promise<boolean>;
90
- /** 用于自定义组件树与画布的右键菜单 */
91
- customContentMenu?: (menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[];
92
- extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
93
- }
94
-
95
- export const defaultEditorProps = {
96
- renderType: RenderType.IFRAME,
97
- disabledMultiSelect: false,
98
- disabledPageFragment: false,
99
- disabledStageOverlay: false,
100
- containerHighlightClassName: CONTAINER_HIGHLIGHT_CLASS_NAME,
101
- containerHighlightDuration: 800,
102
- containerHighlightType: ContainerHighlightType.DEFAULT,
103
- disabledShowSrc: false,
104
- componentGroupList: () => [],
105
- datasourceList: () => [],
106
- menu: () => ({ left: [], right: [] }),
107
- layerContentMenu: () => [],
108
- stageContentMenu: () => [],
109
- propsConfigs: () => ({}),
110
- propsValues: () => ({}),
111
- eventMethodList: () => ({}),
112
- datasourceValues: () => ({}),
113
- datasourceConfigs: () => ({}),
114
- canSelect: (el: HTMLElement) => Boolean(el.id),
115
- isContainer: (el: HTMLElement) => el.classList.contains('magic-ui-container'),
116
- codeOptions: () => ({}),
117
- };
@@ -1,50 +0,0 @@
1
- <template>
2
- <MagicCodeEditor
3
- :height="config.height"
4
- :init-values="model[name]"
5
- :language="config.language"
6
- :options="{
7
- ...config.options,
8
- readOnly: disabled,
9
- }"
10
- :parse="config.parse"
11
- @save="save"
12
- ></MagicCodeEditor>
13
- </template>
14
-
15
- <script lang="ts" setup>
16
- import type { FieldProps, FormItem } from '@tmagic/form';
17
-
18
- import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
19
-
20
- defineOptions({
21
- name: 'MFieldsVsCode',
22
- });
23
-
24
- const emit = defineEmits<{
25
- change: [value: string | any];
26
- }>();
27
-
28
- const props = withDefaults(
29
- defineProps<
30
- FieldProps<
31
- {
32
- language?: string;
33
- options?: {
34
- [key: string]: any;
35
- };
36
- height?: string;
37
- parse?: boolean;
38
- } & FormItem
39
- >
40
- >(),
41
- {
42
- disabled: false,
43
- },
44
- );
45
-
46
- const save = (v: string | any) => {
47
- props.model[props.name] = v;
48
- emit('change', v);
49
- };
50
- </script>
@@ -1,80 +0,0 @@
1
- <template>
2
- <m-fields-link :config="formConfig" :model="modelValue" name="form" @change="changeHandler"></m-fields-link>
3
- </template>
4
-
5
- <script lang="ts" setup>
6
- import { computed, reactive, watch } from 'vue';
7
- import serialize from 'serialize-javascript';
8
-
9
- import type { FieldProps, FormItem } from '@tmagic/form';
10
-
11
- import { getConfig } from '@editor/utils/config';
12
-
13
- defineOptions({
14
- name: 'MFieldsCodeLink',
15
- });
16
-
17
- const props = defineProps<
18
- FieldProps<
19
- {
20
- type: 'code-link';
21
- formTitle?: string;
22
- codeOptions?: Object;
23
- } & FormItem
24
- >
25
- >();
26
-
27
- const emit = defineEmits(['change']);
28
-
29
- const formConfig = computed(() => {
30
- const { codeOptions, ...config } = props.config;
31
- return {
32
- ...config,
33
- text: '',
34
- type: 'link',
35
- form: [
36
- {
37
- name: props.name,
38
- type: 'vs-code',
39
- options: {
40
- tabSize: 2,
41
- ...(codeOptions || {}),
42
- },
43
- },
44
- ],
45
- };
46
- });
47
-
48
- const modelValue = reactive<{ form: Record<string, string> }>({
49
- form: {
50
- [props.name]: '',
51
- },
52
- });
53
-
54
- watch(
55
- () => props.model[props.name],
56
- (value) => {
57
- modelValue.form = {
58
- [props.name]: serialize(value, {
59
- space: 2,
60
- unsafe: true,
61
- }).replace(/"(\w+)":\s/g, '$1: '),
62
- };
63
- },
64
- {
65
- immediate: true,
66
- },
67
- );
68
-
69
- const changeHandler = (v: Record<string, any>) => {
70
- if (!props.name || !props.model) return;
71
-
72
- try {
73
- const parseDSL = getConfig('parseDSL');
74
- props.model[props.name] = parseDSL(`(${v[props.name]})`);
75
- emit('change', props.model[props.name]);
76
- } catch (e) {
77
- console.error(e);
78
- }
79
- };
80
- </script>
@@ -1,132 +0,0 @@
1
- <template>
2
- <div class="m-fields-code-select" :class="config.className">
3
- <TMagicCard>
4
- <MContainer
5
- :config="codeConfig"
6
- :size="size"
7
- :prop="prop"
8
- :disabled="disabled"
9
- :lastValues="lastValues"
10
- :model="model[name]"
11
- @change="changeHandler"
12
- >
13
- </MContainer>
14
- </TMagicCard>
15
- </div>
16
- </template>
17
-
18
- <script lang="ts" setup>
19
- import { computed, inject, watch } from 'vue';
20
- import { isEmpty } from 'lodash-es';
21
-
22
- import { TMagicCard } from '@tmagic/design';
23
- import type { FieldProps, FormItem } from '@tmagic/form';
24
- import { FormState, MContainer } from '@tmagic/form';
25
- import { HookCodeType, HookType } from '@tmagic/schema';
26
-
27
- import type { Services } from '@editor/type';
28
-
29
- defineOptions({
30
- name: 'MFieldsCodeSelect',
31
- });
32
-
33
- const emit = defineEmits(['change']);
34
-
35
- const services = inject<Services>('services');
36
-
37
- const props = withDefaults(
38
- defineProps<
39
- FieldProps<
40
- {
41
- className?: string;
42
- } & FormItem
43
- >
44
- >(),
45
- {},
46
- );
47
-
48
- const codeConfig = computed(() => ({
49
- type: 'group-list',
50
- name: 'hookData',
51
- enableToggleMode: false,
52
- expandAll: true,
53
- title: (mForm: FormState, { model, index }: any) => {
54
- if (model.codeType === HookCodeType.DATA_SOURCE_METHOD) {
55
- if (Array.isArray(model.codeId)) {
56
- if (model.codeId.length < 2) {
57
- return index;
58
- }
59
-
60
- const ds = services?.dataSourceService.getDataSourceById(model.codeId[0]);
61
- return `${ds?.title} / ${model.codeId[1]}`;
62
- }
63
-
64
- return Array.isArray(model.codeId) ? model.codeId.join('/') : index;
65
- }
66
- return model.codeId || index;
67
- },
68
- items: [
69
- {
70
- type: 'row',
71
- items: [
72
- {
73
- type: 'select',
74
- name: 'codeType',
75
- span: 8,
76
- options: [
77
- { value: HookCodeType.CODE, text: '代码块' },
78
- { value: HookCodeType.DATA_SOURCE_METHOD, text: '数据源方法' },
79
- ],
80
- defaultValue: 'code',
81
- onChange: (mForm: FormState, v: HookCodeType, { model }: any) => {
82
- if (v === HookCodeType.DATA_SOURCE_METHOD) {
83
- model.codeId = [];
84
- } else {
85
- model.codeId = '';
86
- }
87
-
88
- return v;
89
- },
90
- },
91
- {
92
- type: 'code-select-col',
93
- name: 'codeId',
94
- span: 16,
95
- labelWidth: 0,
96
- display: (mForm: FormState, { model }: any) => model.codeType !== HookCodeType.DATA_SOURCE_METHOD,
97
- notEditable: () => !services?.codeBlockService.getEditStatus(),
98
- },
99
- {
100
- type: 'data-source-method-select',
101
- name: 'codeId',
102
- span: 16,
103
- labelWidth: 0,
104
- display: (mForm: FormState, { model }: any) => model.codeType === HookCodeType.DATA_SOURCE_METHOD,
105
- notEditable: () => !services?.dataSourceService.get('editable'),
106
- },
107
- ],
108
- },
109
- ],
110
- }));
111
-
112
- watch(
113
- () => props.model[props.name],
114
- (value) => {
115
- // 兼容旧的数据结构
116
- if (isEmpty(value)) {
117
- // 空值或者空数组
118
- props.model[props.name] = {
119
- hookType: HookType.CODE,
120
- hookData: [],
121
- };
122
- }
123
- },
124
- {
125
- immediate: true,
126
- },
127
- );
128
-
129
- const changeHandler = async () => {
130
- emit('change', props.model[props.name]);
131
- };
132
- </script>
@@ -1,139 +0,0 @@
1
- <template>
2
- <div class="m-fields-code-select-col">
3
- <div class="code-select-container">
4
- <!-- 代码块下拉框 -->
5
- <MContainer
6
- class="select"
7
- :config="selectConfig"
8
- :model="model"
9
- :size="size"
10
- @change="onParamsChangeHandler"
11
- ></MContainer>
12
-
13
- <!-- 查看/编辑按钮 -->
14
- <TMagicButton
15
- v-if="model[name] && hasCodeBlockSidePanel"
16
- class="m-fields-select-action-button"
17
- :size="size"
18
- @click="editCode(model[name])"
19
- >
20
- <MIcon :icon="!notEditable ? Edit : View"></MIcon>
21
- </TMagicButton>
22
- </div>
23
-
24
- <!-- 参数填写框 -->
25
- <CodeParams
26
- v-if="paramsConfig.length"
27
- name="params"
28
- :key="model[name]"
29
- :model="model"
30
- :size="size"
31
- :params-config="paramsConfig"
32
- @change="onParamsChangeHandler"
33
- ></CodeParams>
34
- </div>
35
- </template>
36
-
37
- <script lang="ts" setup>
38
- import { computed, inject, ref, watch } from 'vue';
39
- import { Edit, View } from '@element-plus/icons-vue';
40
- import { isEmpty, map } from 'lodash-es';
41
-
42
- import { TMagicButton } from '@tmagic/design';
43
- import { createValues, type FieldProps, filterFunction, type FormState, MContainer } from '@tmagic/form';
44
- import type { Id } from '@tmagic/schema';
45
-
46
- import CodeParams from '@editor/components/CodeParams.vue';
47
- import MIcon from '@editor/components/Icon.vue';
48
- import type { CodeParamStatement, CodeSelectColConfig, EventBus, Services } from '@editor/type';
49
- import { SideItemKey } from '@editor/type';
50
-
51
- defineOptions({
52
- name: 'MFieldsCodeSelectCol',
53
- });
54
-
55
- const mForm = inject<FormState | undefined>('mForm');
56
- const services = inject<Services>('services');
57
- const eventBus = inject<EventBus>('eventBus');
58
- const emit = defineEmits(['change']);
59
-
60
- const props = withDefaults(defineProps<FieldProps<CodeSelectColConfig>>(), {
61
- disabled: false,
62
- });
63
-
64
- const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
65
-
66
- const hasCodeBlockSidePanel = computed(() =>
67
- (services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.CODE_BLOCK),
68
- );
69
-
70
- /**
71
- * 根据代码块id获取代码块参数配置
72
- * @param codeId 代码块ID
73
- */
74
- const getParamItemsConfig = (codeId?: Id): CodeParamStatement[] => {
75
- if (!codeDsl.value || !codeId) return [];
76
-
77
- const paramStatements = codeDsl.value[codeId]?.params;
78
-
79
- if (isEmpty(paramStatements)) return [];
80
-
81
- return paramStatements.map((paramState: CodeParamStatement) => ({
82
- labelWidth: '100px',
83
- text: paramState.name,
84
- ...paramState,
85
- }));
86
- };
87
-
88
- const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
89
- const paramsConfig = ref<CodeParamStatement[]>(getParamItemsConfig(props.model[props.name]));
90
-
91
- watch(
92
- () => props.model[props.name],
93
- (v, preV) => {
94
- if (v !== preV) {
95
- paramsConfig.value = getParamItemsConfig(v);
96
- }
97
- },
98
- );
99
-
100
- const selectConfig = {
101
- type: 'select',
102
- name: props.name,
103
- disable: props.disabled,
104
- options: () => {
105
- if (codeDsl.value) {
106
- return map(codeDsl.value, (value, key) => ({
107
- text: `${value.name}(${key})`,
108
- label: `${value.name}(${key})`,
109
- value: key,
110
- }));
111
- }
112
- return [];
113
- },
114
- onChange: (formState: any, codeId: Id, { model }: any) => {
115
- // 通过下拉框选择的codeId变化后修正model的值,避免写入其他codeId的params
116
- paramsConfig.value = getParamItemsConfig(codeId);
117
-
118
- if (paramsConfig.value.length) {
119
- model.params = createValues(formState, paramsConfig.value, {}, model.params);
120
- } else {
121
- model.params = {};
122
- }
123
-
124
- return codeId;
125
- },
126
- };
127
-
128
- /**
129
- * 参数值修改更新
130
- */
131
- const onParamsChangeHandler = (value: any) => {
132
- props.model.params = value.params;
133
- emit('change', props.model);
134
- };
135
-
136
- const editCode = (id: string) => {
137
- eventBus?.emit('edit-code', id);
138
- };
139
- </script>
@@ -1,149 +0,0 @@
1
- <template>
2
- <div class="m-fields-data-source-field-select">
3
- <component
4
- :is="tagName"
5
- :config="showDataSourceFieldSelect || !config.fieldConfig ? cascaderConfig : config.fieldConfig"
6
- :model="model"
7
- :name="name"
8
- :disabled="disabled"
9
- :size="size"
10
- :last-values="lastValues"
11
- :init-values="initValues"
12
- :values="values"
13
- :prop="`${prop}${prop ? '.' : ''}${name}`"
14
- @change="onChangeHandler"
15
- ></component>
16
-
17
- <TMagicButton
18
- v-if="(showDataSourceFieldSelect || !config.fieldConfig) && selectedDataSourceId && hasDataSourceSidePanel"
19
- class="m-fields-select-action-button"
20
- :size="size"
21
- @click="editHandler(selectedDataSourceId)"
22
- ><MIcon :icon="!notEditable ? Edit : View"></MIcon
23
- ></TMagicButton>
24
-
25
- <TMagicButton
26
- v-if="config.fieldConfig"
27
- style="margin-left: 5px"
28
- :type="showDataSourceFieldSelect ? 'primary' : 'default'"
29
- :size="size"
30
- @click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
31
- ><MIcon :icon="Coin"></MIcon
32
- ></TMagicButton>
33
- </div>
34
- </template>
35
-
36
- <script setup lang="ts">
37
- import { computed, inject, ref, resolveComponent, watch } from 'vue';
38
- import { Coin, Edit, View } from '@element-plus/icons-vue';
39
-
40
- import { TMagicButton } from '@tmagic/design';
41
- import type { CascaderConfig, FieldProps, FormState } from '@tmagic/form';
42
- import { filterFunction, MCascader } from '@tmagic/form';
43
- import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
44
-
45
- import MIcon from '@editor/components/Icon.vue';
46
- import type { DataSourceFieldSelectConfig, EventBus, Services } from '@editor/type';
47
- import { SideItemKey } from '@editor/type';
48
- import { getCascaderOptionsFromFields } from '@editor/utils';
49
-
50
- defineOptions({
51
- name: 'MFieldsDataSourceFieldSelect',
52
- });
53
-
54
- const services = inject<Services>('services');
55
- const eventBus = inject<EventBus>('eventBus');
56
- const emit = defineEmits(['change']);
57
-
58
- const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(), {
59
- disabled: false,
60
- });
61
-
62
- const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
63
-
64
- const hasDataSourceSidePanel = computed(() =>
65
- (services?.uiService.get('sideBarItems') || []).find((item) => item.$key === SideItemKey.DATA_SOURCE),
66
- );
67
-
68
- const selectedDataSourceId = computed(() => {
69
- const value = props.model[props.name];
70
- if (!Array.isArray(value) || !value.length) {
71
- return '';
72
- }
73
-
74
- return value[0].replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, '');
75
- });
76
-
77
- const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
78
-
79
- const cascaderConfig = computed<CascaderConfig>(() => {
80
- const valueIsKey = props.config.value === 'key';
81
-
82
- return {
83
- type: 'cascader',
84
- checkStrictly: props.config.checkStrictly ?? !valueIsKey,
85
- popperClass: 'm-editor-data-source-field-select-popper',
86
- options: () => {
87
- const options =
88
- dataSources.value?.map((ds) => ({
89
- label: ds.title || ds.id,
90
- value: valueIsKey ? ds.id : `${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX}${ds.id}`,
91
- children: getCascaderOptionsFromFields(ds.fields, props.config.dataSourceFieldType),
92
- })) || [];
93
- return options.filter((option) => option.children.length);
94
- },
95
- };
96
- });
97
-
98
- const showDataSourceFieldSelect = ref(false);
99
-
100
- watch(
101
- () => props.model[props.name],
102
- (value) => {
103
- if (
104
- Array.isArray(value) &&
105
- typeof value[0] === 'string' &&
106
- value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
107
- ) {
108
- showDataSourceFieldSelect.value = true;
109
- } else {
110
- showDataSourceFieldSelect.value = false;
111
- }
112
- },
113
- {
114
- immediate: true,
115
- },
116
- );
117
-
118
- const mForm = inject<FormState | undefined>('mForm');
119
-
120
- const type = computed((): string => {
121
- let type = props.config.fieldConfig?.type;
122
- if (typeof type === 'function') {
123
- type = type(mForm, {
124
- model: props.model,
125
- });
126
- }
127
- if (type === 'form') return '';
128
- if (type === 'container') return '';
129
- return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (props.config.items ? '' : 'text');
130
- });
131
-
132
- const tagName = computed(() => {
133
- if (showDataSourceFieldSelect.value || !props.config.fieldConfig) {
134
- return MCascader;
135
- }
136
-
137
- const component = resolveComponent(`m-${props.config.items ? 'form' : 'fields'}-${type.value}`);
138
- if (typeof component !== 'string') return component;
139
- return 'm-fields-text';
140
- });
141
-
142
- const onChangeHandler = (value: any) => {
143
- emit('change', value);
144
- };
145
-
146
- const editHandler = (id: string) => {
147
- eventBus?.emit('edit-data-source', id);
148
- };
149
- </script>