@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,137 +0,0 @@
1
- <template>
2
- <div class="m-fields-key-value">
3
- <div v-if="!showCode">
4
- <div class="m-fields-key-value-item" v-for="(item, index) in records" :key="index">
5
- <TMagicInput
6
- placeholder="key"
7
- v-model="records[index][0]"
8
- :disabled="disabled"
9
- :size="size"
10
- @change="keyChangeHandler"
11
- ></TMagicInput>
12
- <span class="m-fileds-key-value-delimiter">:</span>
13
- <TMagicInput
14
- placeholder="value"
15
- v-model="records[index][1]"
16
- :disabled="disabled"
17
- :size="size"
18
- @change="valueChangeHandler"
19
- ></TMagicInput>
20
-
21
- <TMagicButton
22
- class="m-fileds-key-value-delete"
23
- type="danger"
24
- :size="size"
25
- :disabled="disabled"
26
- circle
27
- plain
28
- :icon="Delete"
29
- @click="deleteHandler(index)"
30
- ></TMagicButton>
31
- </div>
32
-
33
- <TMagicButton type="primary" :size="size" :disabled="disabled" plain :icon="Plus" @click="addHandler"
34
- >添加</TMagicButton
35
- >
36
- </div>
37
-
38
- <MagicCodeEditor
39
- v-if="config.advanced && showCode"
40
- height="200px"
41
- :init-values="model[name]"
42
- language="json"
43
- :options="{
44
- readOnly: disabled,
45
- }"
46
- :parse="true"
47
- @save="save"
48
- ></MagicCodeEditor>
49
-
50
- <TMagicButton
51
- v-if="config.advanced"
52
- size="default"
53
- :disabled="disabled"
54
- link
55
- :icon="CodeIcon"
56
- @click="showCode = !showCode"
57
- ></TMagicButton>
58
- </div>
59
- </template>
60
-
61
- <script setup lang="ts">
62
- import { ref, watchEffect } from 'vue';
63
- import { Delete, Plus } from '@element-plus/icons-vue';
64
-
65
- import { TMagicButton, TMagicInput } from '@tmagic/design';
66
- import type { FieldProps, FormItem } from '@tmagic/form';
67
-
68
- import CodeIcon from '@editor/icons/CodeIcon.vue';
69
- import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
70
-
71
- defineOptions({
72
- name: 'MFieldsKeyValue',
73
- });
74
-
75
- const props = withDefaults(
76
- defineProps<
77
- FieldProps<
78
- {
79
- type: 'key-value';
80
- advanced?: boolean;
81
- } & FormItem
82
- >
83
- >(),
84
- {
85
- disabled: false,
86
- },
87
- );
88
-
89
- const emit = defineEmits<(e: 'change', value: Record<string, any>) => void>();
90
-
91
- const records = ref<[string, string][]>([]);
92
- const showCode = ref(false);
93
-
94
- watchEffect(() => {
95
- const initValues: [string, any][] = Object.entries(props.model[props.name] || {});
96
-
97
- for (const [, value] of initValues) {
98
- if (typeof value !== 'string') {
99
- showCode.value = true;
100
- break;
101
- }
102
- }
103
-
104
- records.value = initValues;
105
- });
106
-
107
- const getValue = () => {
108
- const record: Record<string, string> = {};
109
- records.value.forEach(([key, value]) => {
110
- if (key) {
111
- record[key] = value;
112
- }
113
- });
114
- return record;
115
- };
116
-
117
- const keyChangeHandler = () => {
118
- emit('change', getValue());
119
- };
120
-
121
- const valueChangeHandler = () => {
122
- emit('change', getValue());
123
- };
124
-
125
- const addHandler = () => {
126
- records.value.push(['', '']);
127
- };
128
-
129
- const deleteHandler = (index: number) => {
130
- records.value.splice(index, 1);
131
- emit('change', getValue());
132
- };
133
-
134
- const save = (v: string | any) => {
135
- emit('change', v);
136
- };
137
- </script>
@@ -1,63 +0,0 @@
1
- <template>
2
- <div class="m-fields-page-fragment-select">
3
- <div class="page-fragment-select-container">
4
- <!-- 页面片下拉框 -->
5
- <m-form-container
6
- class="select"
7
- :config="selectConfig"
8
- :model="model"
9
- :size="size"
10
- @change="changeHandler"
11
- ></m-form-container>
12
- <!-- 编辑按钮 -->
13
- <Icon v-if="model[name]" class="icon" :icon="Edit" @click="editPageFragment(model[name])"></Icon>
14
- </div>
15
- </div>
16
- </template>
17
-
18
- <script lang="ts" setup>
19
- import { computed, inject } from 'vue';
20
- import { Edit } from '@element-plus/icons-vue';
21
-
22
- import { FieldProps } from '@tmagic/form';
23
- import { Id, NodeType } from '@tmagic/schema';
24
-
25
- import Icon from '@editor/components/Icon.vue';
26
- import type { PageFragmentSelectConfig, Services } from '@editor/type';
27
-
28
- defineOptions({
29
- name: 'MFieldsPageFragmentSelect',
30
- });
31
-
32
- const services = inject<Services>('services');
33
- const emit = defineEmits(['change']);
34
-
35
- const props = withDefaults(defineProps<FieldProps<PageFragmentSelectConfig>>(), {
36
- disabled: false,
37
- });
38
- const pageList = computed(() =>
39
- services?.editorService.get('root')?.items.filter((item) => item.type === NodeType.PAGE_FRAGMENT),
40
- );
41
-
42
- const selectConfig = {
43
- type: 'select',
44
- name: props.name,
45
- options: () => {
46
- if (pageList.value) {
47
- return pageList.value.map((item) => ({
48
- text: `${item.devconfig?.tabName || item.title || item.name}(${item.id})`,
49
- label: `${item.devconfig?.tabName || item.title || item.name}(${item.id})`,
50
- value: item.id,
51
- }));
52
- }
53
- return [];
54
- },
55
- };
56
- const changeHandler = async () => {
57
- emit('change', props.model[props.name]);
58
- };
59
-
60
- const editPageFragment = (id: Id) => {
61
- services?.editorService.select(id);
62
- };
63
- </script>
@@ -1,135 +0,0 @@
1
- <template>
2
- <div class="m-fields-ui-select" v-if="uiSelectMode" @click="cancelHandler">
3
- <TMagicButton type="danger" :icon="Delete" :disabled="disabled" :size="size" link style="padding: 0"
4
- >取消</TMagicButton
5
- >
6
- </div>
7
- <div class="m-fields-ui-select" v-else style="display: flex">
8
- <template v-if="val">
9
- <TMagicTooltip content="清除" placement="top">
10
- <TMagicButton
11
- style="padding: 0"
12
- type="danger"
13
- :icon="Close"
14
- :disabled="disabled"
15
- :size="size"
16
- link
17
- @click.stop="deleteHandler"
18
- ></TMagicButton>
19
- </TMagicTooltip>
20
-
21
- <TMagicTooltip content="点击选中组件" placement="top">
22
- <TMagicButton
23
- link
24
- style="padding: 0; margin: 0"
25
- :disabled="disabled"
26
- :size="size"
27
- @click="selectNode(val)"
28
- @mouseenter="highlight(val)"
29
- @mouseleave="unhighlight"
30
- >{{ `${toName}_${val}` }}</TMagicButton
31
- >
32
- </TMagicTooltip>
33
- </template>
34
-
35
- <TMagicTooltip v-else content="点击此处选择" placement="top">
36
- <TMagicButton link style="padding: 0; margin: 0" :disabled="disabled" :size="size" @click="startSelect"
37
- >点击此处选择</TMagicButton
38
- >
39
- </TMagicTooltip>
40
- </div>
41
- </template>
42
-
43
- <script lang="ts" setup>
44
- import { computed, inject, ref } from 'vue';
45
- import { Close, Delete } from '@element-plus/icons-vue';
46
- import { throttle } from 'lodash-es';
47
-
48
- import { TMagicButton, TMagicTooltip } from '@tmagic/design';
49
- import type { FieldProps, FormItem, FormState } from '@tmagic/form';
50
- import type { Id } from '@tmagic/schema';
51
-
52
- import { Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
53
-
54
- defineOptions({
55
- name: 'MFieldsUISelect',
56
- });
57
-
58
- const props = defineProps<FieldProps<{ type: 'ui-select' } & FormItem>>();
59
-
60
- const emit = defineEmits(['change']);
61
-
62
- const services = inject<Services>('services');
63
- const mForm = inject<FormState>('mForm');
64
- const val = computed(() => props.model[props.name]);
65
- const uiSelectMode = ref(false);
66
-
67
- const cancelHandler = () => {
68
- if (!services?.uiService) return;
69
- services.uiService.set('uiSelectMode', false);
70
- uiSelectMode.value = false;
71
- globalThis.document.removeEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler as EventListener);
72
- };
73
-
74
- const clickHandler = ({ detail }: Event & { detail: any }) => {
75
- if (detail.id) {
76
- props.model[props.name] = detail.id;
77
- emit('change', detail.id);
78
- mForm?.$emit('field-change', props.prop, detail.id);
79
- }
80
-
81
- if (cancelHandler) {
82
- cancelHandler();
83
- }
84
- };
85
-
86
- const toName = computed(() => {
87
- const config = services?.editorService.getNodeById(val.value);
88
- return config?.name || '';
89
- });
90
-
91
- const startSelect = () => {
92
- if (!services?.uiService) return;
93
- services.uiService.set('uiSelectMode', true);
94
- uiSelectMode.value = true;
95
- globalThis.document.addEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler as EventListener);
96
- };
97
-
98
- const deleteHandler = () => {
99
- if (props.model) {
100
- props.model[props.name] = '';
101
- emit('change', '');
102
- mForm?.$emit('field-change', props.prop, '');
103
- }
104
- };
105
-
106
- const selectNode = async (id: Id) => {
107
- await services?.editorService.select(id);
108
- services?.editorService.get('stage')?.select(id);
109
- services?.stageOverlayService.get('stage')?.select(id);
110
- };
111
-
112
- const highlight = throttle((id: Id) => {
113
- services?.editorService.highlight(id);
114
- services?.editorService.get('stage')?.highlight(id);
115
- services?.stageOverlayService.get('stage')?.highlight(id);
116
- }, 150);
117
-
118
- const unhighlight = () => {
119
- services?.editorService.set('highlightNode', null);
120
- services?.editorService.get('stage')?.clearHighlight();
121
- services?.stageOverlayService.get('stage')?.clearHighlight();
122
- };
123
- </script>
124
-
125
- <style lang="scss">
126
- .m-fields-ui-select {
127
- cursor: pointer;
128
- i {
129
- margin-right: 3px;
130
- }
131
- span {
132
- color: #2882e0;
133
- }
134
- }
135
- </style>
@@ -1,24 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- export * from './use-code-block-edit';
20
- export * from './use-data-source-method';
21
- export * from './use-stage';
22
- export * from './use-float-box';
23
- export * from './use-window-rect';
24
- export * from './use-editor-content-height';
@@ -1,83 +0,0 @@
1
- import { nextTick, ref } from 'vue';
2
- import { cloneDeep } from 'lodash-es';
3
-
4
- import { tMagicMessage } from '@tmagic/design';
5
- import type { CodeBlockContent } from '@tmagic/schema';
6
-
7
- import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
8
- import type { CodeBlockService } from '@editor/services/codeBlock';
9
-
10
- export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
11
- const codeConfig = ref<CodeBlockContent>();
12
- const codeId = ref<string>();
13
- const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
14
-
15
- // 新增代码块
16
- const createCodeBlock = async () => {
17
- if (!codeBlockService) {
18
- tMagicMessage.error('新增代码块失败');
19
- return;
20
- }
21
-
22
- codeConfig.value = {
23
- name: '',
24
- content: `({app, params}) => {\n // place your code here\n}`,
25
- params: [],
26
- };
27
-
28
- codeId.value = await codeBlockService.getUniqueId();
29
-
30
- await nextTick();
31
-
32
- codeBlockEditor.value?.show();
33
- };
34
-
35
- // 编辑代码块
36
- const editCode = async (id: string) => {
37
- const codeBlock = await codeBlockService?.getCodeContentById(id);
38
-
39
- if (!codeBlock) {
40
- tMagicMessage.error('获取代码块内容失败');
41
- return;
42
- }
43
-
44
- let codeContent = codeBlock.content;
45
-
46
- if (typeof codeContent !== 'string') {
47
- codeContent = codeContent.toString();
48
- }
49
-
50
- codeConfig.value = {
51
- ...cloneDeep(codeBlock),
52
- content: codeContent,
53
- };
54
- codeId.value = id;
55
-
56
- await nextTick();
57
- codeBlockEditor.value?.show();
58
- };
59
-
60
- // 删除代码块
61
- const deleteCode = async (key: string) => {
62
- codeBlockService?.deleteCodeDslByIds([key]);
63
- };
64
-
65
- const submitCodeBlockHandler = async (values: CodeBlockContent) => {
66
- if (!codeId.value) return;
67
-
68
- await codeBlockService?.setCodeDslById(codeId.value, values);
69
-
70
- codeBlockEditor.value?.hide();
71
- };
72
-
73
- return {
74
- codeId,
75
- codeConfig,
76
- codeBlockEditor,
77
-
78
- createCodeBlock,
79
- editCode,
80
- deleteCode,
81
- submitCodeBlockHandler,
82
- };
83
- };
@@ -1,46 +0,0 @@
1
- import { computed, ref } from 'vue';
2
-
3
- import type { DataSourceSchema } from '@tmagic/schema';
4
-
5
- import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
6
- import type { DataSourceService } from '@editor/services/dataSource';
7
-
8
- export const useDataSourceEdit = (dataSourceService?: DataSourceService) => {
9
- const dialogTitle = ref('');
10
- const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
11
- const dataSourceValues = ref<Record<string, any>>({});
12
-
13
- const editable = computed(() => dataSourceService?.get('editable') ?? true);
14
-
15
- const editHandler = (id: string) => {
16
- if (!editDialog.value) return;
17
-
18
- dataSourceValues.value = {
19
- ...dataSourceService?.getDataSourceById(id),
20
- };
21
-
22
- dialogTitle.value = `编辑${dataSourceValues.value.title || ''}`;
23
-
24
- editDialog.value.show();
25
- };
26
-
27
- const submitDataSourceHandler = (value: DataSourceSchema) => {
28
- if (value.id) {
29
- dataSourceService?.update(value);
30
- } else {
31
- dataSourceService?.add(value);
32
- }
33
-
34
- editDialog.value?.hide();
35
- };
36
-
37
- return {
38
- dialogTitle,
39
- editDialog,
40
- dataSourceValues,
41
- editable,
42
-
43
- editHandler,
44
- submitDataSourceHandler,
45
- };
46
- };
@@ -1,100 +0,0 @@
1
- import { nextTick, ref } from 'vue';
2
- import { cloneDeep } from 'lodash-es';
3
-
4
- import { tMagicMessage } from '@tmagic/design';
5
- import type { CodeBlockContent, DataSourceSchema } from '@tmagic/schema';
6
-
7
- import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
8
- import { getConfig } from '@editor/utils/config';
9
-
10
- export const useDataSourceMethod = () => {
11
- const codeConfig = ref<CodeBlockContent>();
12
- const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
13
-
14
- const dataSource = ref<DataSourceSchema>();
15
- const dataSourceMethod = ref('');
16
-
17
- return {
18
- codeConfig,
19
- codeBlockEditor,
20
-
21
- createCode: async (model: DataSourceSchema) => {
22
- codeConfig.value = {
23
- name: '',
24
- content: `({ params, dataSource, app }) => {\n // place your code here\n}`,
25
- params: [],
26
- };
27
-
28
- await nextTick();
29
-
30
- dataSource.value = model;
31
- dataSourceMethod.value = '';
32
-
33
- codeBlockEditor.value?.show();
34
- },
35
-
36
- editCode: async (model: DataSourceSchema, methodName: string) => {
37
- const method = model.methods?.find((method) => method.name === methodName);
38
-
39
- if (!method) {
40
- tMagicMessage.error('获取数据源方法失败');
41
- return;
42
- }
43
-
44
- let codeContent = method.content;
45
-
46
- if (typeof codeContent !== 'string') {
47
- codeContent = codeContent.toString();
48
- }
49
-
50
- codeConfig.value = {
51
- ...cloneDeep(method),
52
- content: codeContent,
53
- };
54
-
55
- await nextTick();
56
-
57
- dataSource.value = model;
58
- dataSourceMethod.value = methodName;
59
-
60
- codeBlockEditor.value?.show();
61
- },
62
-
63
- deleteCode: async (model: DataSourceSchema, methodName: string) => {
64
- if (!model.methods) return;
65
-
66
- const index = model.methods.findIndex((method) => method.name === methodName);
67
-
68
- if (index === -1) {
69
- return;
70
- }
71
-
72
- model.methods.splice(index, 1);
73
- },
74
-
75
- submitCode: (values: CodeBlockContent) => {
76
- if (!dataSource.value) return;
77
-
78
- if (!dataSource.value.methods) {
79
- dataSource.value.methods = [];
80
- }
81
-
82
- if (values.content) {
83
- // 在保存的时候转换代码内容
84
- const parseDSL = getConfig('parseDSL');
85
- if (typeof values.content === 'string') {
86
- values.content = parseDSL<(...args: any[]) => any>(values.content);
87
- }
88
- }
89
-
90
- if (dataSourceMethod.value) {
91
- const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
92
- dataSource.value.methods.splice(index, 1, values);
93
- } else {
94
- dataSource.value.methods.push(values);
95
- }
96
-
97
- codeBlockEditor.value?.hide();
98
- },
99
- };
100
- };
@@ -1,26 +0,0 @@
1
- import { computed, inject, ref, watch } from 'vue';
2
-
3
- import type { Services } from '@editor/type';
4
-
5
- export const useEditorContentHeight = () => {
6
- const services = inject<Services>('services');
7
- const frameworkHeight = computed(() => services?.uiService.get('frameworkRect').height || 0);
8
- const navMenuHeight = computed(() => services?.uiService.get('navMenuRect').height || 0);
9
- const editorContentHeight = computed(() => frameworkHeight.value - navMenuHeight.value);
10
-
11
- const height = ref(0);
12
- watch(
13
- editorContentHeight,
14
- () => {
15
- if (height.value > 0 && height.value === editorContentHeight.value) return;
16
- height.value = editorContentHeight.value;
17
- },
18
- {
19
- immediate: true,
20
- },
21
- );
22
-
23
- return {
24
- height,
25
- };
26
- };
@@ -1,55 +0,0 @@
1
- import { type Ref, ref } from 'vue';
2
-
3
- import type { Id, MNode } from '@tmagic/schema';
4
-
5
- import type { LayerNodeStatus, TreeNodeData } from '@editor/type';
6
- import { traverseNode } from '@editor/utils';
7
- import { updateStatus } from '@editor/utils/tree';
8
-
9
- export const useFilter = (
10
- nodeData: Ref<TreeNodeData[]>,
11
- nodeStatusMap: Ref<Map<Id, LayerNodeStatus> | undefined>,
12
- filterNodeMethod: (value: string, data: MNode) => boolean,
13
- ) => {
14
- // tree方法:对树节点进行筛选时执行的方法
15
- const filterIsMatch = (value: string | string[], data: MNode): boolean => {
16
- const string = !Array.isArray(value) ? [value] : value;
17
-
18
- if (!string.length) {
19
- return true;
20
- }
21
-
22
- return string.some((v) => filterNodeMethod(v, data));
23
- };
24
-
25
- const filter = (text: string | string[]) => {
26
- if (!nodeData.value.length) return;
27
-
28
- nodeData.value.forEach((node) => {
29
- traverseNode(node, (node: MNode, parents: MNode[]) => {
30
- if (!nodeStatusMap.value) return;
31
-
32
- const visible = filterIsMatch(text, node);
33
- if (visible && parents.length) {
34
- parents.forEach((parent) => {
35
- updateStatus(nodeStatusMap.value!, parent.id, {
36
- visible,
37
- expand: true,
38
- });
39
- });
40
- }
41
-
42
- updateStatus(nodeStatusMap.value, node.id, {
43
- visible,
44
- });
45
- });
46
- });
47
- };
48
-
49
- return {
50
- filterText: ref(''),
51
- filterTextChangeHandler(text: string | string[]) {
52
- filter(text);
53
- },
54
- };
55
- };