@tmagic/editor 1.3.16 → 1.4.0-beta.2

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 (129) hide show
  1. package/dist/style.css +25 -9
  2. package/dist/tmagic-editor.js +1048 -632
  3. package/dist/tmagic-editor.umd.cjs +1065 -647
  4. package/package.json +23 -21
  5. package/src/components/CodeBlockEditor.vue +82 -59
  6. package/src/components/FloatingBox.vue +71 -25
  7. package/src/components/SplitView.vue +46 -35
  8. package/src/fields/Code.vue +12 -10
  9. package/src/fields/CodeLink.vue +9 -9
  10. package/src/fields/CodeSelect.vue +7 -5
  11. package/src/fields/CodeSelectCol.vue +1 -1
  12. package/src/fields/DataSourceFieldSelect.vue +118 -27
  13. package/src/fields/DataSourceFields.vue +10 -3
  14. package/src/fields/DataSourceInput.vue +7 -7
  15. package/src/fields/DataSourceMethodSelect.vue +1 -1
  16. package/src/fields/DataSourceMethods.vue +3 -3
  17. package/src/fields/DataSourceMocks.vue +3 -3
  18. package/src/fields/DataSourceSelect.vue +6 -18
  19. package/src/fields/EventSelect.vue +1 -1
  20. package/src/fields/KeyValue.vue +8 -8
  21. package/src/fields/PageFragmentSelect.vue +1 -1
  22. package/src/fields/UISelect.vue +5 -5
  23. package/src/hooks/index.ts +2 -0
  24. package/src/hooks/use-code-block-edit.ts +1 -2
  25. package/src/hooks/use-editor-content-height.ts +20 -0
  26. package/src/hooks/use-float-box.ts +8 -8
  27. package/src/hooks/use-window-rect.ts +20 -0
  28. package/src/index.ts +2 -2
  29. package/src/layouts/Framework.vue +33 -34
  30. package/src/layouts/NavMenu.vue +21 -2
  31. package/src/layouts/PropsPanel.vue +35 -0
  32. package/src/layouts/sidebar/Sidebar.vue +18 -8
  33. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -1
  34. package/src/layouts/workspace/viewer/NodeListMenu.vue +1 -0
  35. package/src/services/BaseService.ts +5 -2
  36. package/src/services/codeBlock.ts +14 -8
  37. package/src/services/dataSource.ts +39 -26
  38. package/src/services/editor.ts +46 -25
  39. package/src/services/events.ts +4 -4
  40. package/src/services/props.ts +44 -35
  41. package/src/services/stageOverlay.ts +16 -9
  42. package/src/services/storage.ts +14 -8
  43. package/src/services/ui.ts +26 -19
  44. package/src/theme/code-block.scss +0 -5
  45. package/src/theme/code-editor.scss +6 -0
  46. package/src/theme/floating-box.scss +4 -2
  47. package/src/theme/props-panel.scss +14 -0
  48. package/src/theme/sidebar.scss +6 -3
  49. package/src/type.ts +87 -37
  50. package/src/utils/operator.ts +37 -39
  51. package/src/utils/props.ts +174 -37
  52. package/types/components/CodeBlockEditor.vue.d.ts +46 -25
  53. package/types/components/CodeParams.vue.d.ts +5 -5
  54. package/types/components/ContentMenu.vue.d.ts +12 -12
  55. package/types/components/FloatingBox.vue.d.ts +42 -55
  56. package/types/components/Icon.vue.d.ts +3 -3
  57. package/types/components/Resizer.vue.d.ts +3 -3
  58. package/types/components/ScrollBar.vue.d.ts +3 -3
  59. package/types/components/ScrollViewer.vue.d.ts +12 -12
  60. package/types/components/SearchInput.vue.d.ts +1 -1
  61. package/types/components/SplitView.vue.d.ts +13 -11
  62. package/types/components/ToolButton.vue.d.ts +13 -13
  63. package/types/components/Tree.vue.d.ts +24 -14
  64. package/types/components/TreeNode.vue.d.ts +22 -12
  65. package/types/fields/Code.vue.d.ts +14 -14
  66. package/types/fields/CodeLink.vue.d.ts +6 -10
  67. package/types/fields/CodeSelect.vue.d.ts +14 -14
  68. package/types/fields/CodeSelectCol.vue.d.ts +11 -11
  69. package/types/fields/DataSourceFieldSelect.vue.d.ts +11 -11
  70. package/types/fields/DataSourceFields.vue.d.ts +11 -11
  71. package/types/fields/DataSourceInput.vue.d.ts +14 -18
  72. package/types/fields/DataSourceMethodSelect.vue.d.ts +11 -11
  73. package/types/fields/DataSourceMethods.vue.d.ts +11 -11
  74. package/types/fields/DataSourceMocks.vue.d.ts +11 -11
  75. package/types/fields/DataSourceSelect.vue.d.ts +13 -26
  76. package/types/fields/EventSelect.vue.d.ts +3 -3
  77. package/types/fields/KeyValue.vue.d.ts +14 -18
  78. package/types/fields/PageFragmentSelect.vue.d.ts +11 -11
  79. package/types/fields/UISelect.vue.d.ts +8 -4
  80. package/types/hooks/index.d.ts +2 -0
  81. package/types/hooks/use-code-block-edit.d.ts +66 -90
  82. package/types/hooks/use-data-source-method.d.ts +66 -90
  83. package/types/hooks/use-editor-content-height.d.ts +3 -0
  84. package/types/hooks/use-node-status.d.ts +6 -1
  85. package/types/hooks/use-window-rect.d.ts +6 -0
  86. package/types/icons/AppManageIcon.vue.d.ts +1 -1
  87. package/types/icons/CenterIcon.vue.d.ts +1 -1
  88. package/types/icons/CodeIcon.vue.d.ts +1 -1
  89. package/types/icons/FolderMinusIcon.vue.d.ts +1 -1
  90. package/types/icons/PinIcon.vue.d.ts +1 -1
  91. package/types/icons/PinnedIcon.vue.d.ts +1 -1
  92. package/types/layouts/AddPageBox.vue.d.ts +3 -3
  93. package/types/layouts/CodeEditor.vue.d.ts +12 -12
  94. package/types/layouts/Framework.vue.d.ts +9 -9
  95. package/types/layouts/NavMenu.vue.d.ts +11 -11
  96. package/types/layouts/PropsPanel.vue.d.ts +193 -243
  97. package/types/layouts/page-bar/AddButton.vue.d.ts +3 -3
  98. package/types/layouts/page-bar/PageBar.vue.d.ts +8 -8
  99. package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +8 -8
  100. package/types/layouts/page-bar/SwitchTypeButton.vue.d.ts +3 -3
  101. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +1 -1
  102. package/types/layouts/sidebar/Sidebar.vue.d.ts +13 -13
  103. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +10 -10
  104. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +9 -9
  105. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -3
  106. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +3 -3
  107. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +9 -9
  108. package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +11 -11
  109. package/types/layouts/sidebar/layer/LayerNodeTool.vue.d.ts +3 -3
  110. package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +9 -9
  111. package/types/layouts/sidebar/layer/use-click.d.ts +42 -76
  112. package/types/layouts/sidebar/layer/use-node-status.d.ts +6 -1
  113. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
  114. package/types/layouts/workspace/Workspace.vue.d.ts +12 -12
  115. package/types/layouts/workspace/viewer/NodeListMenu.vue.d.ts +1 -1
  116. package/types/layouts/workspace/viewer/Stage.vue.d.ts +11 -11
  117. package/types/layouts/workspace/viewer/StageOverlay.vue.d.ts +1 -1
  118. package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +12 -12
  119. package/types/services/BaseService.d.ts +5 -2
  120. package/types/services/codeBlock.d.ts +8 -0
  121. package/types/services/dataSource.d.ts +9 -2
  122. package/types/services/editor.d.ts +8 -1
  123. package/types/services/props.d.ts +15 -22
  124. package/types/services/stageOverlay.d.ts +9 -2
  125. package/types/services/storage.d.ts +8 -0
  126. package/types/services/ui.d.ts +20 -8
  127. package/types/type.d.ts +56 -32
  128. package/types/utils/operator.d.ts +1 -1
  129. package/types/utils/props.d.ts +2 -13
@@ -6,22 +6,22 @@
6
6
  import { computed, reactive, watch } from 'vue';
7
7
  import serialize from 'serialize-javascript';
8
8
 
9
- import type { FieldProps } from '@tmagic/form';
9
+ import type { FieldProps, FormItem } from '@tmagic/form';
10
10
 
11
11
  import { getConfig } from '@editor/utils/config';
12
12
 
13
13
  defineOptions({
14
- name: 'MEditorCodeLink',
14
+ name: 'MFieldsCodeLink',
15
15
  });
16
16
 
17
17
  const props = defineProps<
18
- FieldProps<{
19
- type: 'code-link';
20
- name: string;
21
- text?: string;
22
- formTitle?: string;
23
- codeOptions?: Object;
24
- }>
18
+ FieldProps<
19
+ {
20
+ type: 'code-link';
21
+ formTitle?: string;
22
+ codeOptions?: Object;
23
+ } & FormItem
24
+ >
25
25
  >();
26
26
 
27
27
  const emit = defineEmits(['change']);
@@ -11,14 +11,14 @@ import { computed, inject, watch } from 'vue';
11
11
  import { isEmpty } from 'lodash-es';
12
12
 
13
13
  import { TMagicCard } from '@tmagic/design';
14
- import type { FieldProps } from '@tmagic/form';
14
+ import type { FieldProps, FormItem } from '@tmagic/form';
15
15
  import { FormState } from '@tmagic/form';
16
16
  import { HookCodeType, HookType } from '@tmagic/schema';
17
17
 
18
18
  import type { Services } from '@editor/type';
19
19
 
20
20
  defineOptions({
21
- name: 'MEditorCodeSelect',
21
+ name: 'MFieldsCodeSelect',
22
22
  });
23
23
 
24
24
  const emit = defineEmits(['change']);
@@ -27,9 +27,11 @@ const services = inject<Services>('services');
27
27
 
28
28
  const props = withDefaults(
29
29
  defineProps<
30
- FieldProps<{
31
- className?: string;
32
- }>
30
+ FieldProps<
31
+ {
32
+ className?: string;
33
+ } & FormItem
34
+ >
33
35
  >(),
34
36
  {},
35
37
  );
@@ -49,7 +49,7 @@ import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
49
49
  import type { CodeParamStatement, CodeSelectColConfig, Services } from '@editor/type';
50
50
 
51
51
  defineOptions({
52
- name: 'MEditorCodeSelectCol',
52
+ name: 'MFieldsCodeSelectCol',
53
53
  });
54
54
 
55
55
  const mForm = inject<FormState | undefined>('mForm');
@@ -1,23 +1,47 @@
1
1
  <template>
2
- <m-form-container
3
- :config="{
4
- ...config,
5
- ...cascaderConfig,
6
- }"
7
- :model="model"
8
- @change="onChangeHandler"
9
- ></m-form-container>
2
+ <div style="width: 100%; display: flex; align-items: center">
3
+ <component
4
+ style="width: 100%"
5
+ :is="tagName"
6
+ :config="showDataSourceFieldSelect || !config.fieldConfig ? cascaderConfig : config.fieldConfig"
7
+ :model="model"
8
+ :name="name"
9
+ :disabled="disabled"
10
+ :size="size"
11
+ :last-values="lastValues"
12
+ :init-values="initValues"
13
+ :values="values"
14
+ :prop="`${prop}${prop ? '.' : ''}${name}`"
15
+ @change="onChangeHandler"
16
+ ></component>
17
+ <TMagicButton
18
+ v-if="config.fieldConfig"
19
+ style="margin-left: 5px"
20
+ link
21
+ :type="showDataSourceFieldSelect ? 'primary' : 'default'"
22
+ :icon="Coin"
23
+ :size="size"
24
+ @click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
25
+ ></TMagicButton>
26
+ </div>
10
27
  </template>
11
28
 
12
29
  <script setup lang="ts">
13
- import { computed, inject } from 'vue';
30
+ import { computed, inject, onMounted, ref, resolveComponent } from 'vue';
31
+ import { Coin } from '@element-plus/icons-vue';
14
32
 
15
- import type { CascaderOption, FieldProps } from '@tmagic/form';
16
- import type { DataSchema } from '@tmagic/schema';
33
+ import { TMagicButton } from '@tmagic/design';
34
+ import type { CascaderConfig, CascaderOption, FieldProps, FormState } from '@tmagic/form';
35
+ import { MCascader } from '@tmagic/form';
36
+ import type { DataSchema, DataSourceFieldType } from '@tmagic/schema';
17
37
  import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
18
38
 
19
39
  import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
20
40
 
41
+ defineOptions({
42
+ name: 'MFieldsDataSourceFieldSelect',
43
+ });
44
+
21
45
  const services = inject<Services>('services');
22
46
  const emit = defineEmits(['change']);
23
47
 
@@ -27,32 +51,99 @@ const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(
27
51
 
28
52
  const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
29
53
 
30
- const getOptionChildren = (fields: DataSchema[] = []): CascaderOption[] =>
31
- fields.map((field) => ({
32
- label: field.title || field.name,
33
- value: field.name,
34
- children: field.type === 'array' ? [] : getOptionChildren(field.fields),
35
- }));
54
+ const getOptionChildren = (
55
+ fields: DataSchema[] = [],
56
+ dataSourceFieldType: DataSourceFieldType[] = ['any'],
57
+ ): CascaderOption[] => {
58
+ const child: CascaderOption[] = [];
59
+ fields.forEach((field) => {
60
+ if (!dataSourceFieldType.length) {
61
+ dataSourceFieldType.push('any');
62
+ }
63
+
64
+ const children = getOptionChildren(field.fields, dataSourceFieldType);
65
+
66
+ const item = {
67
+ label: field.title || field.name,
68
+ value: field.name,
69
+ children,
70
+ };
71
+
72
+ const fieldType = field.type || 'any';
73
+ if (dataSourceFieldType.includes('any') || dataSourceFieldType.includes(fieldType)) {
74
+ child.push(item);
75
+ return;
76
+ }
77
+
78
+ if (!dataSourceFieldType.includes(fieldType) && fieldType !== 'object') {
79
+ return;
80
+ }
81
+
82
+ if (!children.length && ['object', 'array', 'any'].includes(field.type || '')) {
83
+ return;
84
+ }
85
+
86
+ child.push(item);
87
+ });
88
+ return child;
89
+ };
36
90
 
37
- const cascaderConfig = computed(() => {
91
+ const cascaderConfig = computed<CascaderConfig>(() => {
38
92
  const valueIsKey = props.config.value === 'key';
39
93
 
40
94
  return {
41
95
  type: 'cascader',
42
- name: props.name,
43
- checkStrictly: !valueIsKey,
44
- text: '',
45
- options: () =>
46
- dataSources.value
47
- ?.filter((ds) => ds.fields?.length)
48
- ?.map((ds) => ({
96
+ checkStrictly: props.config.checkStrictly ?? !valueIsKey,
97
+ popperClass: 'm-editor-data-source-field-select-popper',
98
+ options: () => {
99
+ const options =
100
+ dataSources.value?.map((ds) => ({
49
101
  label: ds.title || ds.id,
50
102
  value: valueIsKey ? ds.id : `${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX}${ds.id}`,
51
- children: getOptionChildren(ds.fields),
52
- })) || [],
103
+ children: getOptionChildren(ds.fields, props.config.dataSourceFieldType),
104
+ })) || [];
105
+ return options.filter((option) => option.children.length);
106
+ },
53
107
  };
54
108
  });
55
109
 
110
+ const showDataSourceFieldSelect = ref(false);
111
+
112
+ onMounted(() => {
113
+ const value = props.model[props.name];
114
+ if (
115
+ Array.isArray(value) &&
116
+ typeof value[0] === 'string' &&
117
+ value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
118
+ ) {
119
+ return (showDataSourceFieldSelect.value = true);
120
+ }
121
+ });
122
+
123
+ const mForm = inject<FormState | undefined>('mForm');
124
+
125
+ const type = computed((): string => {
126
+ let type = props.config.fieldConfig?.type;
127
+ if (typeof type === 'function') {
128
+ type = type(mForm, {
129
+ model: props.model,
130
+ });
131
+ }
132
+ if (type === 'form') return '';
133
+ if (type === 'container') return '';
134
+ return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (props.config.items ? '' : 'text');
135
+ });
136
+
137
+ const tagName = computed(() => {
138
+ if (showDataSourceFieldSelect.value || !props.config.fieldConfig) {
139
+ return MCascader;
140
+ }
141
+
142
+ const component = resolveComponent(`m-${props.config.items ? 'form' : 'fields'}-${type.value}`);
143
+ if (typeof component !== 'string') return component;
144
+ return 'm-fields-text';
145
+ });
146
+
56
147
  const onChangeHandler = (value: any) => {
57
148
  emit('change', value);
58
149
  };
@@ -37,13 +37,13 @@ import { computed, inject, ref } from 'vue';
37
37
  import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
38
38
  import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
39
39
  import type { DataSchema } from '@tmagic/schema';
40
- import { MagicTable } from '@tmagic/table';
40
+ import { type ColumnConfig, MagicTable } from '@tmagic/table';
41
41
  import { getDefaultValueFromFields } from '@tmagic/utils';
42
42
 
43
43
  import type { Services } from '@editor/type';
44
44
 
45
45
  defineOptions({
46
- name: 'MEditorDataSourceFields',
46
+ name: 'MFieldsDataSourceFields',
47
47
  });
48
48
 
49
49
  const props = withDefaults(
@@ -86,7 +86,7 @@ const fieldChange = ({ index, ...value }: Record<string, any>) => {
86
86
  emit('change', props.model[props.name]);
87
87
  };
88
88
 
89
- const fieldColumns = [
89
+ const fieldColumns: ColumnConfig[] = [
90
90
  {
91
91
  label: '属性名称',
92
92
  prop: 'title',
@@ -102,6 +102,13 @@ const fieldColumns = [
102
102
  {
103
103
  label: '默认值',
104
104
  prop: 'defaultValue',
105
+ formatter(item, row) {
106
+ try {
107
+ return JSON.stringify(row.defaultValue);
108
+ } catch (e) {
109
+ return row.defaultValue;
110
+ }
111
+ },
105
112
  },
106
113
  {
107
114
  label: '操作',
@@ -48,7 +48,7 @@ import { computed, inject, nextTick, ref, watch } from 'vue';
48
48
  import { Coin } from '@element-plus/icons-vue';
49
49
 
50
50
  import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
51
- import type { FieldProps } from '@tmagic/form';
51
+ import type { FieldProps, FormItem } from '@tmagic/form';
52
52
  import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
53
53
 
54
54
  import Icon from '@editor/components/Icon.vue';
@@ -56,16 +56,16 @@ import type { Services } from '@editor/type';
56
56
  import { getDisplayField } from '@editor/utils/data-source';
57
57
 
58
58
  defineOptions({
59
- name: 'MEditorDataSourceInput',
59
+ name: 'MFieldsDataSourceInput',
60
60
  });
61
61
 
62
62
  const props = withDefaults(
63
63
  defineProps<
64
- FieldProps<{
65
- type: 'data-source-input';
66
- name: string;
67
- text: string;
68
- }>
64
+ FieldProps<
65
+ {
66
+ type: 'data-source-input';
67
+ } & FormItem
68
+ >
69
69
  >(),
70
70
  {
71
71
  disabled: false,
@@ -49,7 +49,7 @@ import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
49
49
  import type { CodeParamStatement, DataSourceMethodSelectConfig, Services } from '@editor/type';
50
50
 
51
51
  defineOptions({
52
- name: 'MEditorDataSourceMethodSelect',
52
+ name: 'MFieldsDataSourceMethodSelect',
53
53
  });
54
54
 
55
55
  const mForm = inject<FormState | undefined>('mForm');
@@ -24,14 +24,14 @@
24
24
  import { TMagicButton } from '@tmagic/design';
25
25
  import type { FieldProps } from '@tmagic/form';
26
26
  import type { CodeBlockContent } from '@tmagic/schema';
27
- import { MagicTable } from '@tmagic/table';
27
+ import { type ColumnConfig, MagicTable } from '@tmagic/table';
28
28
 
29
29
  import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
30
30
  import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
31
31
  import type { CodeParamStatement } from '@editor/type';
32
32
 
33
33
  defineOptions({
34
- name: 'MEditorDataSourceMethods',
34
+ name: 'MFieldsDataSourceMethods',
35
35
  });
36
36
 
37
37
  const props = withDefaults(
@@ -49,7 +49,7 @@ const emit = defineEmits(['change']);
49
49
 
50
50
  const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
51
51
 
52
- const methodColumns = [
52
+ const methodColumns: ColumnConfig[] = [
53
53
  {
54
54
  label: '名称',
55
55
  prop: 'name',
@@ -26,14 +26,14 @@ import { computed, inject, ref } from 'vue';
26
26
  import { TMagicButton, tMagicMessageBox, TMagicSwitch } from '@tmagic/design';
27
27
  import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
28
28
  import type { MockSchema } from '@tmagic/schema';
29
- import { MagicTable } from '@tmagic/table';
29
+ import { type ColumnConfig, MagicTable } from '@tmagic/table';
30
30
  import { getDefaultValueFromFields } from '@tmagic/utils';
31
31
 
32
32
  import CodeEditor from '@editor/layouts/CodeEditor.vue';
33
33
  import { Services } from '@editor/type';
34
34
 
35
35
  defineOptions({
36
- name: 'MEditorDataSourceMocks',
36
+ name: 'MFieldsDataSourceMocks',
37
37
  });
38
38
 
39
39
  const props = withDefaults(
@@ -117,7 +117,7 @@ const formConfig: FormConfig = [
117
117
  },
118
118
  ];
119
119
 
120
- const columns = [
120
+ const columns: ColumnConfig[] = [
121
121
  {
122
122
  type: 'expand',
123
123
  component: CodeEditor,
@@ -14,31 +14,19 @@
14
14
  <script setup lang="ts">
15
15
  import { computed, inject } from 'vue';
16
16
 
17
- import { FieldProps, MSelect, SelectConfig } from '@tmagic/form';
17
+ import { type FieldProps, MSelect, type SelectConfig } from '@tmagic/form';
18
18
 
19
- import { Services } from '../type';
19
+ import type { DataSourceSelect, Services } from '../type';
20
20
 
21
21
  defineOptions({
22
- name: 'MEditorDataSourceSelect',
22
+ name: 'MFieldsDataSourceSelect',
23
23
  });
24
24
 
25
25
  const emit = defineEmits(['change']);
26
26
 
27
- const props = withDefaults(
28
- defineProps<
29
- FieldProps<{
30
- type: 'data-source-select';
31
- name: string;
32
- text?: string;
33
- placeholder?: string;
34
- dataSourceType?: string;
35
- value?: 'id' | 'value';
36
- }>
37
- >(),
38
- {
39
- disabled: false,
40
- },
41
- );
27
+ const props = withDefaults(defineProps<FieldProps<DataSourceSelect>>(), {
28
+ disabled: false,
29
+ });
42
30
 
43
31
  const { dataSourceService } = inject<Services>('services') || {};
44
32
 
@@ -61,7 +61,7 @@ import { ActionType } from '@tmagic/schema';
61
61
  import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
62
62
 
63
63
  defineOptions({
64
- name: 'MEditorEventSelect',
64
+ name: 'MFieldsEventSelect',
65
65
  });
66
66
 
67
67
  const props = defineProps<FieldProps<EventSelectConfig>>();
@@ -63,23 +63,23 @@ import { ref, watchEffect } from 'vue';
63
63
  import { Delete, Plus } from '@element-plus/icons-vue';
64
64
 
65
65
  import { TMagicButton, TMagicInput } from '@tmagic/design';
66
- import type { FieldProps } from '@tmagic/form';
66
+ import type { FieldProps, FormItem } from '@tmagic/form';
67
67
 
68
68
  import CodeIcon from '@editor/icons/CodeIcon.vue';
69
69
  import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
70
70
 
71
71
  defineOptions({
72
- name: 'MEditorKeyValue',
72
+ name: 'MFieldsKeyValue',
73
73
  });
74
74
 
75
75
  const props = withDefaults(
76
76
  defineProps<
77
- FieldProps<{
78
- type: 'key-value';
79
- name: string;
80
- text: string;
81
- advanced?: boolean;
82
- }>
77
+ FieldProps<
78
+ {
79
+ type: 'key-value';
80
+ advanced?: boolean;
81
+ } & FormItem
82
+ >
83
83
  >(),
84
84
  {
85
85
  disabled: false,
@@ -26,7 +26,7 @@ import Icon from '@editor/components/Icon.vue';
26
26
  import type { PageFragmentSelectConfig, Services } from '@editor/type';
27
27
 
28
28
  defineOptions({
29
- name: 'MEditorPageFragmentSelect',
29
+ name: 'MFieldsPageFragmentSelect',
30
30
  });
31
31
 
32
32
  const services = inject<Services>('services');
@@ -26,7 +26,7 @@
26
26
  :size="size"
27
27
  @click="selectNode(val)"
28
28
  @mouseenter="highlight(val)"
29
- @mouseleave="unhightlight"
29
+ @mouseleave="unhighlight"
30
30
  >{{ `${toName}_${val}` }}</TMagicButton
31
31
  >
32
32
  </TMagicTooltip>
@@ -46,16 +46,16 @@ import { Close, Delete } from '@element-plus/icons-vue';
46
46
  import { throttle } from 'lodash-es';
47
47
 
48
48
  import { TMagicButton, TMagicTooltip } from '@tmagic/design';
49
- import type { FieldProps, FormState } from '@tmagic/form';
49
+ import type { FieldProps, FormItem, FormState } from '@tmagic/form';
50
50
  import type { Id } from '@tmagic/schema';
51
51
 
52
52
  import { Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
53
53
 
54
54
  defineOptions({
55
- name: 'MEditorUISelect',
55
+ name: 'MFieldsUISelect',
56
56
  });
57
57
 
58
- const props = defineProps<FieldProps<any>>();
58
+ const props = defineProps<FieldProps<{ type: 'ui-select' } & FormItem>>();
59
59
 
60
60
  const emit = defineEmits(['change']);
61
61
 
@@ -115,7 +115,7 @@ const highlight = throttle((id: Id) => {
115
115
  services?.stageOverlayService.get('stage')?.highlight(id);
116
116
  }, 150);
117
117
 
118
- const unhightlight = () => {
118
+ const unhighlight = () => {
119
119
  services?.editorService.set('highlightNode', null);
120
120
  services?.editorService.get('stage')?.clearHighlight();
121
121
  services?.stageOverlayService.get('stage')?.clearHighlight();
@@ -20,3 +20,5 @@ export * from './use-code-block-edit';
20
20
  export * from './use-data-source-method';
21
21
  export * from './use-stage';
22
22
  export * from './use-float-box';
23
+ export * from './use-window-rect';
24
+ export * from './use-editor-content-height';
@@ -20,7 +20,7 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
20
20
  }
21
21
 
22
22
  codeConfig.value = {
23
- name: '代码块',
23
+ name: '',
24
24
  content: `({app, params}) => {\n // place your code here\n}`,
25
25
  params: [],
26
26
  };
@@ -54,7 +54,6 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
54
54
  codeId.value = id;
55
55
 
56
56
  await nextTick();
57
-
58
57
  codeBlockEditor.value?.show();
59
58
  };
60
59
 
@@ -0,0 +1,20 @@
1
+ import { computed, inject, ref, watchEffect } 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
+ watchEffect(() => {
13
+ if (height.value > 0) return;
14
+ height.value = editorContentHeight.value;
15
+ });
16
+
17
+ return {
18
+ height,
19
+ };
20
+ };
@@ -26,34 +26,34 @@ export const useFloatBox = (slideKeys: ComputedRef<string[]>) => {
26
26
  const showingBoxKeys = computed(() =>
27
27
  Object.keys(floatBoxStates.value).filter((key) => floatBoxStates.value[key].status),
28
28
  );
29
- const isDraging = ref(false);
29
+ const isDragging = ref(false);
30
30
 
31
- const dragstartHandler = () => (isDraging.value = true);
31
+ const dragstartHandler = () => (isDragging.value = true);
32
32
  const dragendHandler = (key: string, e: DragEvent) => {
33
33
  floatBoxStates.value[key] = {
34
34
  left: e.clientX,
35
35
  top: e.clientY,
36
36
  status: true,
37
37
  };
38
- isDraging.value = false;
38
+ isDragging.value = false;
39
39
  };
40
40
 
41
41
  document.body.addEventListener('dragover', (e: DragEvent) => {
42
- if (!isDraging.value) return;
42
+ if (!isDragging.value) return;
43
43
  e.preventDefault();
44
44
  });
45
45
 
46
46
  watch(
47
47
  () => slideKeys.value,
48
- () => {
49
- for (const key in slideKeys.value) {
50
- if (floatBoxStates.value[key]) continue;
48
+ (slideKeys) => {
49
+ slideKeys.forEach((key) => {
50
+ if (floatBoxStates.value[key]) return;
51
51
  floatBoxStates.value[key] = {
52
52
  status: false,
53
53
  top: 0,
54
54
  left: 0,
55
55
  };
56
- }
56
+ });
57
57
  },
58
58
  {
59
59
  deep: true,
@@ -0,0 +1,20 @@
1
+ import { onBeforeUnmount, reactive } from 'vue';
2
+
3
+ export const useWindowRect = () => {
4
+ const rect = reactive({ width: globalThis.innerWidth, height: globalThis.innerHeight });
5
+
6
+ const windowResizeHandler = () => {
7
+ rect.width = globalThis.innerWidth;
8
+ rect.height = globalThis.innerHeight;
9
+ };
10
+
11
+ globalThis.addEventListener('resize', windowResizeHandler);
12
+
13
+ onBeforeUnmount(() => {
14
+ globalThis.removeEventListener('resize', windowResizeHandler);
15
+ });
16
+
17
+ return {
18
+ rect,
19
+ };
20
+ };
package/src/index.ts CHANGED
@@ -96,11 +96,11 @@ export default {
96
96
  // eslint-disable-next-line no-param-reassign
97
97
  app.config.globalProperties.$TMAGIC_EDITOR = option;
98
98
  setConfig(option);
99
- app.component(Editor.name, Editor);
99
+ app.component(`${Editor.name || 'MEditor'}`, Editor);
100
+ app.component('magic-code-editor', CodeEditor);
100
101
  app.component('m-fields-ui-select', uiSelect);
101
102
  app.component('m-fields-code-link', CodeLink);
102
103
  app.component('m-fields-vs-code', Code);
103
- app.component('magic-code-editor', CodeEditor);
104
104
  app.component('m-fields-code-select', CodeSelect);
105
105
  app.component('m-fields-code-select-col', CodeSelectCol);
106
106
  app.component('m-fields-event-select', EventSelect);