@tmagic/editor 1.3.0-beta.6 → 1.3.0-beta.7

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 (34) hide show
  1. package/dist/style.css +57 -56
  2. package/dist/tmagic-editor.js +487 -390
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +505 -408
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +10 -10
  7. package/src/Editor.vue +8 -0
  8. package/src/components/Tree.vue +66 -0
  9. package/src/components/TreeNode.vue +142 -0
  10. package/src/layouts/sidebar/Sidebar.vue +13 -0
  11. package/src/layouts/sidebar/data-source/DataSourceList.vue +4 -2
  12. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +8 -2
  13. package/src/layouts/sidebar/layer/LayerPanel.vue +40 -31
  14. package/src/layouts/sidebar/layer/use-click.ts +105 -0
  15. package/src/layouts/sidebar/layer/use-drag.ts +1 -1
  16. package/src/layouts/sidebar/layer/use-filter.ts +1 -12
  17. package/src/layouts/sidebar/layer/use-keybinding.ts +6 -2
  18. package/src/layouts/sidebar/layer/use-node-status.ts +4 -2
  19. package/src/theme/layer-panel.scss +2 -74
  20. package/src/theme/theme.scss +1 -0
  21. package/src/theme/tree.scss +72 -0
  22. package/src/type.ts +16 -1
  23. package/src/utils/tree.ts +15 -0
  24. package/types/{layouts/sidebar/layer/LayerNode.vue.d.ts → components/Tree.vue.d.ts} +19 -17
  25. package/types/components/TreeNode.vue.d.ts +47 -0
  26. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +2 -6
  27. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +7 -1
  28. package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +1 -1
  29. package/types/layouts/sidebar/layer/use-click.d.ts +106 -0
  30. package/types/layouts/sidebar/layer/use-filter.d.ts +0 -1
  31. package/types/layouts/sidebar/layer/use-keybinding.d.ts +2 -1
  32. package/types/type.d.ts +20 -1
  33. package/types/utils/tree.d.ts +3 -0
  34. package/src/layouts/sidebar/layer/LayerNode.vue +0 -208
@@ -1,208 +0,0 @@
1
- <template>
2
- <div
3
- v-show="visible"
4
- class="magic-editor-layer-node"
5
- ref="nodeEl"
6
- :draggable="!isPage(data)"
7
- :data-node-id="data.id"
8
- :data-is-container="Array.isArray(data.items)"
9
- @dragstart="handleDragStart"
10
- @dragleave="handleDragLeave"
11
- @dragend="handleDragEnd($event, data)"
12
- >
13
- <div
14
- class="layer-node"
15
- :class="{ selected, expanded }"
16
- :style="`padding-left: ${indent}px`"
17
- @contextmenu="contextmenuHandler"
18
- @mouseenter="highlightHandler()"
19
- >
20
- <MIcon
21
- class="expand-icon"
22
- :style="hasChilren ? '' : 'color: transparent; cursor: default'"
23
- :icon="expanded ? ArrowDown : ArrowRight"
24
- @click="expandHandler"
25
- ></MIcon>
26
-
27
- <div class="layer-node-content" @click="nodeClickHandler">
28
- <slot name="layer-node-content" :data="data">
29
- <div class="layer-node-label">{{ `${data.name} (${data.id})` }}</div>
30
- <div class="layer-node-tool">
31
- <LayerNodeTool :data="data"></LayerNodeTool>
32
- </div>
33
- </slot>
34
- </div>
35
- </div>
36
-
37
- <div v-if="hasChilren && expanded" class="magic-editor-layer-node-children">
38
- <LayerNode
39
- v-for="item in data.items"
40
- :data="item"
41
- :parent="(data as MContainer)"
42
- :key="item.id"
43
- :indent="indent + 11"
44
- :filter-text="filterText"
45
- :is-ctrl-key-down="isCtrlKeyDown"
46
- @node-contextmenu="nodeContentmenuHandler"
47
- >
48
- <template #layer-node-content="{ data: nodeData }">
49
- <slot name="layer-node-content" :data="nodeData"> </slot>
50
- </template>
51
- </LayerNode>
52
- </div>
53
- </div>
54
- </template>
55
-
56
- <script lang="ts" setup>
57
- import { computed, type ComputedRef, inject, nextTick, ref } from 'vue';
58
- import { ArrowDown, ArrowRight } from '@element-plus/icons-vue';
59
- import { throttle } from 'lodash-es';
60
-
61
- import type { Id, MContainer, MNode } from '@tmagic/schema';
62
- import { isPage } from '@tmagic/utils';
63
-
64
- import MIcon from '@editor/components/Icon.vue';
65
- import { LayerNodeSlots, LayerNodeStatus, Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
66
-
67
- import LayerNodeTool from './LayerNodeTool.vue';
68
- import { useDrag } from './use-drag';
69
- import { updateStatus } from './use-filter';
70
-
71
- defineSlots<LayerNodeSlots>();
72
-
73
- defineOptions({
74
- name: 'MEditorLayerNode',
75
- });
76
-
77
- const props = withDefaults(
78
- defineProps<{
79
- data: MNode;
80
- parent?: MContainer;
81
- indent?: number;
82
- filterText?: string;
83
- isCtrlKeyDown?: boolean;
84
- }>(),
85
- {
86
- indent: 0,
87
- filterText: '',
88
- isCtrlKeyDown: false,
89
- },
90
- );
91
-
92
- const emit = defineEmits<{
93
- 'node-contextmenu': [event: MouseEvent, node: MNode];
94
- }>();
95
-
96
- const services = inject<Services>('services');
97
- const nodeStatusMap = inject<ComputedRef<Map<Id, LayerNodeStatus>>>('nodeStatusMap');
98
- const editorService = services?.editorService;
99
- const uiService = services?.uiService;
100
-
101
- const nodeStatus = computed(
102
- () =>
103
- nodeStatusMap?.value?.get(props.data.id) || {
104
- selected: false,
105
- expand: false,
106
- visible: false,
107
- },
108
- );
109
-
110
- const expanded = computed(() => nodeStatus.value.expand);
111
- const selected = computed(() => nodeStatus.value.selected);
112
- const visible = computed(() => nodeStatus.value.visible);
113
-
114
- const hasChilren = computed(() => props.data.items?.length > 0);
115
-
116
- const nodeEl = ref<HTMLDivElement>();
117
- const { handleDragStart, handleDragEnd, handleDragLeave } = useDrag(services);
118
-
119
- const expandHandler = () => {
120
- if (!nodeStatusMap?.value) return;
121
-
122
- updateStatus(nodeStatusMap.value, props.data.id, {
123
- expand: !expanded.value,
124
- });
125
- };
126
-
127
- const nodeClickHandler = () => {
128
- if (!nodeStatusMap?.value) return;
129
-
130
- if (uiService?.get('uiSelectMode')) {
131
- document.dispatchEvent(new CustomEvent(UI_SELECT_MODE_EVENT_NAME, { detail: props.data }));
132
- return;
133
- }
134
-
135
- if (hasChilren.value && !props.isCtrlKeyDown) {
136
- updateStatus(nodeStatusMap.value, props.data.id, {
137
- expand: true,
138
- });
139
- }
140
-
141
- nextTick(() => {
142
- select(props.data);
143
- });
144
- };
145
-
146
- const contextmenuHandler = (event: MouseEvent) => {
147
- event.preventDefault();
148
- const nodes = editorService?.get('nodes') || [];
149
- if (nodes.length < 2 || !nodes.includes(props.data)) {
150
- nodeClickHandler();
151
- }
152
-
153
- emit('node-contextmenu', event, props.data);
154
- };
155
-
156
- const nodeContentmenuHandler = (event: MouseEvent, node: MNode) => {
157
- emit('node-contextmenu', event, node);
158
- };
159
-
160
- // 触发画布选中
161
- const select = async (data: MNode) => {
162
- if (!data.id) {
163
- throw new Error('没有id');
164
- }
165
-
166
- if (props.isCtrlKeyDown) {
167
- multiSelect(data);
168
- } else {
169
- await editorService?.select(data);
170
- editorService?.get('stage')?.select(data.id);
171
- }
172
- };
173
-
174
- const multiSelect = async (data: MNode) => {
175
- const nodes = editorService?.get('nodes') || [];
176
-
177
- const newNodes: Id[] = [];
178
- let isCancel = false;
179
- nodes.forEach((node) => {
180
- if (node.id === data.id) {
181
- isCancel = true;
182
- return;
183
- }
184
-
185
- newNodes.push(node.id);
186
- });
187
-
188
- // 只剩一个不能取消选中
189
- if (!isCancel || newNodes.length === 0) {
190
- newNodes.push(data.id);
191
- }
192
-
193
- await editorService?.multiSelect(newNodes);
194
- editorService?.get('stage')?.multiSelect(newNodes);
195
- };
196
-
197
- const throttleTime = 300;
198
- // 鼠标在组件树移动触发高亮
199
- const highlightHandler = throttle(() => {
200
- highlight();
201
- }, throttleTime);
202
-
203
- // 触发画布高亮
204
- const highlight = () => {
205
- editorService?.highlight(props.data);
206
- editorService?.get('stage')?.highlight(props.data.id);
207
- };
208
- </script>