mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
feat: add componentMeta?.advanced?.callbacks?.onSelectHook api
This commit is contained in:
parent
5feeab5aec
commit
03495ba9ef
@ -19,6 +19,7 @@ const jestConfig = {
|
||||
// testMatch: ['**/setting-field.test.ts'],
|
||||
// testMatch: ['**/node.test.ts'],
|
||||
// testMatch: ['**/builtin-hotkey.test.ts'],
|
||||
// testMatch: ['**/selection.test.ts'],
|
||||
transformIgnorePatterns: [
|
||||
`/node_modules/(?!${esModules})/`,
|
||||
],
|
||||
|
||||
@ -159,6 +159,9 @@ export interface IBaseNode<Schema extends IPublicTypeNodeSchema = IPublicTypeNod
|
||||
setProps(props?: IPublicTypePropsMap | IPublicTypePropsList | Props | null): void;
|
||||
|
||||
mergeProps(props: IPublicTypePropsMap): void;
|
||||
|
||||
/** 是否可以选中 */
|
||||
canSelect(): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -644,6 +647,12 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
|
||||
return !!this.getExtraProp('isLocked')?.getValue();
|
||||
}
|
||||
|
||||
canSelect(): boolean {
|
||||
const onSelectHook = this.componentMeta?.advanced?.callbacks?.onSelectHook;
|
||||
const canSelect = typeof onSelectHook === 'function' ? onSelectHook(this.internalToShellNode()!) : true;
|
||||
return canSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择当前节点
|
||||
*/
|
||||
|
||||
@ -32,6 +32,12 @@ export class Selection implements ISelection {
|
||||
return;
|
||||
}
|
||||
|
||||
const node = this.doc.getNode(id);
|
||||
|
||||
if (!node?.canSelect()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._selected = [id];
|
||||
this.emitter.emit('selectionchange', this._selected);
|
||||
}
|
||||
@ -40,7 +46,18 @@ export class Selection implements ISelection {
|
||||
* 批量选中
|
||||
*/
|
||||
selectAll(ids: string[]) {
|
||||
this._selected = ids;
|
||||
const selectIds: string[] = [];
|
||||
|
||||
ids.forEach(d => {
|
||||
const node = this.doc.getNode(d);
|
||||
|
||||
if (node?.canSelect()) {
|
||||
selectIds.push(d);
|
||||
}
|
||||
});
|
||||
|
||||
this._selected = selectIds;
|
||||
|
||||
this.emitter.emit('selectionchange', this._selected);
|
||||
}
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ describe('选择区测试', () => {
|
||||
selectionChangeHandler.mockClear();
|
||||
});
|
||||
|
||||
it('dispose 方法', () => {
|
||||
it('selectAll 包含不存在的 id', () => {
|
||||
const project = new Project(designer, {
|
||||
componentsTree: [
|
||||
formSchema,
|
||||
@ -135,14 +135,7 @@ describe('选择区测试', () => {
|
||||
|
||||
selection.selectAll(['form', 'node_k1ow3cbj', 'form2']);
|
||||
|
||||
const selectionChangeHandler = jest.fn();
|
||||
selection.onSelectionChange(selectionChangeHandler);
|
||||
selection.dispose();
|
||||
|
||||
expect(selectionChangeHandler).toHaveBeenCalledTimes(1);
|
||||
expect(selectionChangeHandler.mock.calls[0][0]).toEqual(['form', 'node_k1ow3cbj']);
|
||||
expect(selection.selected).toEqual(['form', 'node_k1ow3cbj']);
|
||||
selectionChangeHandler.mockClear();
|
||||
});
|
||||
|
||||
it('dispose 方法 - 选中的节点没有被删除的', () => {
|
||||
|
||||
@ -195,6 +195,9 @@ export interface IPublicTypeCallbacks {
|
||||
onMoveHook?: (currentNode: IPublicModelNode) => boolean;
|
||||
// thinkof 限制性拖拽
|
||||
onHoverHook?: (currentNode: IPublicModelNode) => boolean;
|
||||
|
||||
/** 选中 hook,如果返回值是 false,可以控制组件不可被选中 */
|
||||
onSelectHook?: (currentNode: IPublicModelNode) => boolean;
|
||||
onChildMoveHook?: (childNode: IPublicModelNode, currentNode: IPublicModelNode) => boolean;
|
||||
|
||||
// events
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user