feat: select in grid

This commit is contained in:
SaikaSakura
2022-07-27 18:13:52 +08:00
parent e150b7c32a
commit cfe9d5a82d
5 changed files with 22 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ export class GridItemBlock extends BaseView {
public override selectable = false; public override selectable = false;
public override activatable = false; public override activatable = false;
public override allowPendant = false; public override allowPendant = false;
public override layoutOnly = true;
type = Protocol.Block.Type.grid; type = Protocol.Block.Type.grid;
View = GridItemRender(GridItem); View = GridItemRender(GridItem);

View File

@@ -9,6 +9,7 @@ export class GridBlock extends BaseView {
public override selectable = false; public override selectable = false;
public override activatable = false; public override activatable = false;
public override allowPendant = false; public override allowPendant = false;
public override layoutOnly = true;
type = Protocol.Block.Type.grid; type = Protocol.Block.Type.grid;
View = GridRender(Grid); View = GridRender(Grid);

View File

@@ -252,6 +252,7 @@ export class DragDropManager {
} }
public handlerEditorDrop(event: React.DragEvent<Element>) { public handlerEditorDrop(event: React.DragEvent<Element>) {
event.preventDefault();
// IMP: can not use Decorators now may use decorators is right // IMP: can not use Decorators now may use decorators is right
if (this.isEnabled()) { if (this.isEnabled()) {
if (this.isDragBlock(event)) { if (this.isDragBlock(event)) {

View File

@@ -324,9 +324,21 @@ export class SelectionManager implements VirgoSelection {
} }
if (block && block.dom) { if (block && block.dom) {
if (selectionRect.isIntersect(domToRect(block.dom))) { if (selectionRect.isIntersect(domToRect(block.dom))) {
const selectableChildren = await ( const childrenBlocks = await block.children();
await block.children() // should check directly in structured block
).filter(childBlock => { const structuredChildrenBlocks: Array<AsyncBlock> =
childrenBlocks.filter(childBlock => {
return this._editor.getView(childBlock.type).layoutOnly;
});
for await (const childBlock of structuredChildrenBlocks) {
const childSelectedNodes =
await this.calcRenderBlockIntersect(
selectionRect,
childBlock
);
selectedNodes.push(...childSelectedNodes);
}
const selectableChildren = childrenBlocks.filter(childBlock => {
return this._editor.getView(childBlock.type).selectable; return this._editor.getView(childBlock.type).selectable;
}); });
for await (const childBlock of selectableChildren) { for await (const childBlock of selectableChildren) {
@@ -350,6 +362,7 @@ export class SelectionManager implements VirgoSelection {
} }
} }
} }
console.log({ selectedNodes });
return selectedNodes; return selectedNodes;
} }

View File

@@ -3,7 +3,7 @@
* *
* @example * @example
* ```ts * ```ts
* // except: type Values = 1 | '2' * except: type Values = 1 | '2'
* type Values = ValueOf<{a: 1, b: '2'}> * type Values = ValueOf<{a: 1, b: '2'}>
* ``` * ```
*/ */
@@ -14,7 +14,7 @@ export type ValueOf<X extends Record<string, unknown>> = X[keyof X];
* *
* @example * @example
* ```ts * ```ts
* // except: type FirstType = string; * except: type FirstType = string;
* type FirstType = First<[string], 0> * type FirstType = First<[string], 0>
* ``` * ```
*/ */
@@ -25,7 +25,7 @@ export type IndexOf<X extends unknown[], I extends number> = X[I];
* *
* @example * @example
* ```ts * ```ts
* // except: type FirstType = string; * except: type FirstType = string;
* type FirstType = First<[string]> * type FirstType = First<[string]>
* ``` * ```
*/ */