Skip to content
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

Merged
merged 6 commits into from
Aug 3, 2022

Conversation

khuntoriia
Copy link
Collaborator

@khuntoriia khuntoriia commented Jul 29, 2022

1、多选右键菜单支持复制粘贴删除
2、编辑器选中节点统一为nodes数组,保留原node对象为nodes数组的第一个元素
3、将复制粘贴删除行为封装到editorservice中
4、支持键盘快捷键操作
5、将复制粘贴操作拆分后进一步封装

@khuntoriia khuntoriia requested a review from jia000 July 29, 2022 13:17
@khuntoriia khuntoriia mentioned this pull request Jul 29, 2022
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiSelect的参数改成string[]

Suggested change
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') || []);
Copy link
Collaborator

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'
Copy link
Collaborator

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 {
Copy link
Collaborator

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);
Copy link
Collaborator

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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个if else 没有区别?

@@ -64,6 +64,7 @@ export interface StoreState {
parent: MContainer | null;
node: MNode | null;
highlightNode: MNode | null;
selectedNodes: MNode[] | null;
Copy link
Collaborator

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));
Copy link
Collaborator

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 {
Copy link
Collaborator

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];
Copy link
Collaborator

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)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要async,也不需要await

Suggested change
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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用get('node')

@jia000 jia000 merged commit b702857 into Tencent:master Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants