@tmagic/editor 1.5.0-beta.9 → 1.5.1

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 (99) hide show
  1. package/dist/{style.css → tmagic-editor.css} +228 -22
  2. package/dist/tmagic-editor.js +1670 -1012
  3. package/dist/tmagic-editor.umd.cjs +1705 -1048
  4. package/package.json +14 -12
  5. package/src/Editor.vue +24 -6
  6. package/src/components/CodeBlockEditor.vue +14 -8
  7. package/src/components/CodeParams.vue +5 -5
  8. package/src/components/ContentMenu.vue +18 -18
  9. package/src/components/FloatingBox.vue +3 -3
  10. package/src/components/Resizer.vue +4 -4
  11. package/src/components/ScrollBar.vue +3 -3
  12. package/src/components/ScrollViewer.vue +3 -3
  13. package/src/components/SplitView.vue +2 -2
  14. package/src/components/ToolButton.vue +2 -1
  15. package/src/editorProps.ts +6 -2
  16. package/src/fields/Code.vue +1 -2
  17. package/src/fields/CodeSelect.vue +13 -11
  18. package/src/fields/CodeSelectCol.vue +32 -5
  19. package/src/fields/CondOpSelect.vue +5 -2
  20. package/src/fields/DataSourceFields.vue +31 -12
  21. package/src/fields/DataSourceInput.vue +2 -2
  22. package/src/fields/DataSourceMethods.vue +72 -14
  23. package/src/fields/DataSourceMocks.vue +0 -1
  24. package/src/fields/DisplayConds.vue +8 -3
  25. package/src/fields/EventSelect.vue +28 -12
  26. package/src/fields/KeyValue.vue +17 -12
  27. package/src/fields/UISelect.vue +6 -3
  28. package/src/hooks/index.ts +0 -1
  29. package/src/hooks/use-code-block-edit.ts +3 -3
  30. package/src/hooks/use-data-source-edit.ts +3 -2
  31. package/src/hooks/use-filter.ts +1 -1
  32. package/src/hooks/use-getso.ts +7 -7
  33. package/src/hooks/use-node-status.ts +2 -2
  34. package/src/index.ts +2 -1
  35. package/src/initService.ts +177 -74
  36. package/src/layouts/CodeEditor.vue +2 -2
  37. package/src/layouts/Framework.vue +13 -12
  38. package/src/layouts/NavMenu.vue +2 -2
  39. package/src/layouts/page-bar/AddButton.vue +29 -9
  40. package/src/layouts/page-bar/PageBar.vue +79 -66
  41. package/src/layouts/page-bar/PageBarScrollContainer.vue +84 -98
  42. package/src/layouts/page-bar/PageList.vue +5 -3
  43. package/src/layouts/page-bar/Search.vue +67 -0
  44. package/src/layouts/props-panel/FormPanel.vue +123 -0
  45. package/src/layouts/props-panel/PropsPanel.vue +146 -0
  46. package/src/layouts/props-panel/use-style-panel.ts +29 -0
  47. package/src/layouts/sidebar/Sidebar.vue +7 -1
  48. package/src/layouts/sidebar/code-block/CodeBlockList.vue +18 -2
  49. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +35 -4
  50. package/src/layouts/sidebar/code-block/useContentMenu.ts +83 -0
  51. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
  52. package/src/layouts/sidebar/data-source/DataSourceList.vue +13 -8
  53. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +40 -4
  54. package/src/layouts/sidebar/data-source/useContentMenu.ts +81 -0
  55. package/src/layouts/sidebar/layer/LayerMenu.vue +7 -13
  56. package/src/layouts/sidebar/layer/LayerPanel.vue +11 -4
  57. package/src/layouts/sidebar/layer/use-click.ts +2 -2
  58. package/src/layouts/sidebar/layer/use-keybinding.ts +2 -2
  59. package/src/layouts/sidebar/layer/use-node-status.ts +2 -3
  60. package/src/layouts/workspace/Workspace.vue +13 -3
  61. package/src/layouts/workspace/viewer/NodeListMenu.vue +3 -3
  62. package/src/layouts/workspace/viewer/Stage.vue +41 -11
  63. package/src/layouts/workspace/viewer/StageOverlay.vue +2 -2
  64. package/src/layouts/workspace/viewer/ViewerMenu.vue +4 -6
  65. package/src/services/dataSource.ts +12 -5
  66. package/src/services/dep.ts +61 -13
  67. package/src/services/editor.ts +46 -51
  68. package/src/services/storage.ts +2 -1
  69. package/src/services/ui.ts +1 -0
  70. package/src/theme/common/var.scss +12 -10
  71. package/src/theme/component-list-panel.scss +9 -7
  72. package/src/theme/content-menu.scss +7 -5
  73. package/src/theme/data-source.scss +3 -1
  74. package/src/theme/floating-box.scss +4 -2
  75. package/src/theme/framework.scss +7 -5
  76. package/src/theme/index.scss +4 -5
  77. package/src/theme/key-value.scss +2 -2
  78. package/src/theme/layer-panel.scss +3 -1
  79. package/src/theme/layout.scss +1 -1
  80. package/src/theme/nav-menu.scss +7 -5
  81. package/src/theme/page-bar.scss +51 -27
  82. package/src/theme/props-panel.scss +81 -1
  83. package/src/theme/resizer.scss +1 -1
  84. package/src/theme/search-input.scss +1 -0
  85. package/src/theme/sidebar.scss +4 -2
  86. package/src/theme/stage.scss +3 -1
  87. package/src/theme/theme.scss +28 -28
  88. package/src/theme/tree.scss +14 -12
  89. package/src/type.ts +10 -1
  90. package/src/utils/content-menu.ts +2 -2
  91. package/src/utils/data-source/formConfigs/http.ts +2 -0
  92. package/src/utils/data-source/index.ts +2 -2
  93. package/src/utils/editor.ts +78 -22
  94. package/src/utils/idle-task.ts +36 -4
  95. package/src/utils/props.ts +48 -6
  96. package/types/index.d.ts +2312 -2080
  97. package/src/hooks/use-data-source-method.ts +0 -100
  98. package/src/layouts/PropsPanel.vue +0 -131
  99. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
@@ -1,100 +0,0 @@
1
- import { nextTick, ref } from 'vue';
2
- import { cloneDeep } from 'lodash-es';
3
-
4
- import type { CodeBlockContent, DataSourceSchema } from '@tmagic/core';
5
- import { tMagicMessage } from '@tmagic/design';
6
-
7
- import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
8
- import { getEditorConfig } 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 || `({ params, dataSource, app }) => {\n // place your code here\n}`;
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 = getEditorConfig('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,131 +0,0 @@
1
- <template>
2
- <div class="m-editor-props-panel" v-show="nodes.length === 1">
3
- <slot name="props-panel-header"></slot>
4
- <MForm
5
- ref="configForm"
6
- :class="propsPanelSize"
7
- :popper-class="`m-editor-props-panel-popper ${propsPanelSize}`"
8
- :size="propsPanelSize"
9
- :init-values="values"
10
- :config="curFormConfig"
11
- :extend-state="extendState"
12
- @change="submit"
13
- @error="errorHandler"
14
- ></MForm>
15
-
16
- <TMagicButton
17
- v-if="!disabledShowSrc"
18
- class="m-editor-props-panel-src-icon"
19
- circle
20
- size="large"
21
- title="源码"
22
- :type="showSrc ? 'primary' : ''"
23
- @click="showSrc = !showSrc"
24
- >
25
- <MIcon :icon="DocumentIcon"></MIcon>
26
- </TMagicButton>
27
-
28
- <CodeEditor
29
- v-if="showSrc"
30
- class="m-editor-props-panel-src-code"
31
- :height="`${editorContentHeight}px`"
32
- :init-values="values"
33
- :options="codeOptions"
34
- :parse="true"
35
- @save="saveCode"
36
- ></CodeEditor>
37
- </div>
38
- </template>
39
-
40
- <script lang="ts" setup>
41
- import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
42
- import { Document as DocumentIcon } from '@element-plus/icons-vue';
43
-
44
- import type { MNode } from '@tmagic/core';
45
- import { TMagicButton } from '@tmagic/design';
46
- import type { FormState, FormValue } from '@tmagic/form';
47
- import { MForm } from '@tmagic/form';
48
-
49
- import MIcon from '@editor/components/Icon.vue';
50
- import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
51
- import type { PropsPanelSlots, Services } from '@editor/type';
52
-
53
- import CodeEditor from './CodeEditor.vue';
54
-
55
- defineSlots<PropsPanelSlots>();
56
-
57
- defineOptions({
58
- name: 'MEditorPropsPanel',
59
- });
60
-
61
- defineProps<{
62
- disabledShowSrc?: boolean;
63
- extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
64
- }>();
65
-
66
- const codeOptions = inject('codeOptions', {});
67
-
68
- const emit = defineEmits(['mounted', 'submit-error', 'form-error']);
69
-
70
- const showSrc = ref(false);
71
-
72
- const internalInstance = getCurrentInstance();
73
- const values = ref<FormValue>({});
74
- const configForm = ref<InstanceType<typeof MForm>>();
75
- // ts类型应该是FormConfig, 但是打包时会出错,所以暂时用any
76
- const curFormConfig = ref<any>([]);
77
- const services = inject<Services>('services');
78
- const node = computed(() => services?.editorService.get('node'));
79
- const nodes = computed(() => services?.editorService.get('nodes') || []);
80
- const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
81
- const stage = computed(() => services?.editorService.get('stage'));
82
-
83
- const { height: editorContentHeight } = useEditorContentHeight();
84
-
85
- const init = async () => {
86
- if (!node.value) {
87
- curFormConfig.value = [];
88
- return;
89
- }
90
-
91
- const type = node.value.type || (node.value.items ? 'container' : 'text');
92
- curFormConfig.value = (await services?.propsService.getPropsConfig(type)) || [];
93
- values.value = node.value;
94
- };
95
-
96
- watchEffect(init);
97
- services?.propsService.on('props-configs-change', init);
98
-
99
- onMounted(() => {
100
- emit('mounted', internalInstance);
101
- });
102
-
103
- onBeforeUnmount(() => {
104
- services?.propsService.off('props-configs-change', init);
105
- });
106
-
107
- watchEffect(() => {
108
- if (configForm.value && stage.value) {
109
- configForm.value.formState.stage = stage.value;
110
- }
111
- });
112
-
113
- const submit = async () => {
114
- try {
115
- const values = await configForm.value?.submitForm();
116
- services?.editorService.update(values);
117
- } catch (e: any) {
118
- emit('submit-error', e);
119
- }
120
- };
121
-
122
- const errorHandler = (e: any) => {
123
- emit('form-error', e);
124
- };
125
-
126
- const saveCode = (values: MNode) => {
127
- services?.editorService.update(values);
128
- };
129
-
130
- defineExpose({ configForm, submit });
131
- </script>
@@ -1,45 +0,0 @@
1
- <template>
2
- <TMagicButton
3
- v-for="item in data"
4
- class="m-editor-page-bar-switch-type-button"
5
- size="small"
6
- :key="item.type"
7
- link
8
- :class="{ active: modelValue === item.type }"
9
- :type="modelValue === item.type ? 'primary' : ''"
10
- @click="clickHandler(item.type)"
11
- >{{ item.text }}</TMagicButton
12
- >
13
- </template>
14
-
15
- <script setup lang="ts">
16
- import { NodeType } from '@tmagic/core';
17
- import { TMagicButton } from '@tmagic/design';
18
-
19
- defineOptions({
20
- name: 'MEditorPageBarSwitchTypeButton',
21
- });
22
-
23
- defineProps<{
24
- modelValue: NodeType.PAGE | NodeType.PAGE_FRAGMENT;
25
- }>();
26
-
27
- const data: { type: NodeType.PAGE | NodeType.PAGE_FRAGMENT; text: string }[] = [
28
- {
29
- type: NodeType.PAGE,
30
- text: '页面',
31
- },
32
- {
33
- type: NodeType.PAGE_FRAGMENT,
34
- text: '页面片',
35
- },
36
- ];
37
-
38
- const emit = defineEmits<{
39
- 'update:modelValue': [value: NodeType.PAGE | NodeType.PAGE_FRAGMENT];
40
- }>();
41
-
42
- const clickHandler = (value: NodeType.PAGE | NodeType.PAGE_FRAGMENT) => {
43
- emit('update:modelValue', value);
44
- };
45
- </script>