-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(editor): 多选菜单支持复制粘贴删除 #217
Conversation
const services = inject<Services>('services'); | ||
const stageOptions = inject<StageOptions>('stageOptions'); | ||
|
||
const stageWrap = ref<InstanceType<typeof ScrollViewer>>(); | ||
const stageContainer = ref<HTMLDivElement>(); | ||
const menu = ref<InstanceType<typeof ViewerMenu>>(); | ||
const isMultiSelect = ref<Boolean>(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isMultiSelect = ref<Boolean>(false); | |
const isMultiSelect = computed(() => editorService.get('node').length >1); |
@@ -131,6 +132,10 @@ export default defineComponent({ | |||
services?.editorService.highlight(el.id); | |||
}); | |||
|
|||
stage?.on('multiSelect', (els: HTMLElement[]) => { | |||
services?.editorService.multiSelect(els); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiSelect的参数改成string[]
services?.editorService.multiSelect(els); | |
services?.editorService.multiSelect(els.map(el => el.id)); |
const services = inject<Services>('services'); | ||
const editorService = services?.editorService; | ||
const menu = ref<InstanceType<typeof ContentMenu>>(); | ||
const canPaste = ref(false); | ||
const canCenter = ref(false); | ||
|
||
const node = computed(() => editorService?.get('node')); | ||
const selectedNodes = computed(() => editorService?.get('selectedNodes') || []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectedNodes改成nodes
@@ -83,7 +83,7 @@ class Editor extends BaseService { | |||
|
|||
/** | |||
* 设置当前指点节点配置 | |||
* @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | |||
* @param name 'root' | 'page' | 'parent' | 'node' | 'highlightNode' | 'selectedNodes' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectedNodes改成nodes,set nodes的时候将node设置成nodes的第一个元素
* @param config 指定节点配置或者ID | ||
* @returns 加入多选的节点配置 | ||
*/ | ||
public multiSelect(config: HTMLElement[]): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
入参给出ids: string[]
config.forEach((element) => { | ||
const { node } = this.selectedConfigExceptionHandler(element.id); | ||
if (!node) return; | ||
const isExist = selectedNodes.find((selectedNode) => selectedNode.id === node.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以使用lodash的uniq方法去重
public async copy(config: MNode): Promise<void> { | ||
globalThis.localStorage.setItem(COPY_STORAGE_KEY, serialize(config)); | ||
public async copy(config: MNode | MNode[]): Promise<void> { | ||
if (Array.isArray(config)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个if else 没有区别?
packages/editor/src/type.ts
Outdated
@@ -64,6 +64,7 @@ export interface StoreState { | |||
parent: MContainer | null; | |||
node: MNode | null; | |||
highlightNode: MNode | null; | |||
selectedNodes: MNode[] | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成nodes
if (!node) return; | ||
nodes.push(node); | ||
}); | ||
this.set('nodes', uniq(nodes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
先uniq(ids)
* @param config 指定节点配置或者ID | ||
* @returns 加入多选的节点配置 | ||
*/ | ||
public multiSelect(config: Id[]): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数名改成ids
@@ -273,7 +292,7 @@ class Editor extends BaseService { | |||
public async add(addNode: AddMNode, parent?: MContainer | null): Promise<MNode> { | |||
// 加入inputEvent是为给业务扩展时可以获取到更多的信息,只有在使用拖拽添加组件时才有改对象 | |||
const { type, inputEvent, ...config } = addNode; | |||
const curNode = this.get<MContainer>('node'); | |||
const curNode = this.get<MContainer>('nodes')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还是get('node')就好
return node; | ||
public async remove(nodes: MNode | MNode[]): Promise<(MNode | void)[]> { | ||
const removeNodes = Array.isArray(nodes) ? nodes : [nodes]; | ||
return Promise.all(removeNodes.map(async (node) => await this.doRemove(node))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不需要async,也不需要await
return Promise.all(removeNodes.map(async (node) => await this.doRemove(node))); | |
return Promise.all(removeNodes.map((node) => this.doRemove(node))); |
const configStr = globalThis.localStorage.getItem(COPY_STORAGE_KEY); | ||
const curNode = this.get<MContainer>('nodes')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用get('node')
1、多选右键菜单支持复制粘贴删除
2、编辑器选中节点统一为nodes数组,保留原node对象为nodes数组的第一个元素
3、将复制粘贴删除行为封装到editorservice中
4、支持键盘快捷键操作
5、将复制粘贴操作拆分后进一步封装