Skip to content

Commit

Permalink
Merge branch 'master' of github.com:toeverything/blocksuite into ayus…
Browse files Browse the repository at this point in the history
…h/5561
  • Loading branch information
AyushAgrawal-A2 committed Dec 13, 2023
2 parents 4d5acfa + f4fc7f9 commit 565b88e
Show file tree
Hide file tree
Showing 33 changed files with 178 additions and 201 deletions.
9 changes: 4 additions & 5 deletions packages/blocks/src/_common/components/file-drop-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type { BaseBlockModel } from '@blocksuite/store';
import {
calcDropTarget,
getClosestBlockElementByPoint,
getEditorContainer,
getModelByBlockElement,
getModelByBlockComponent,
isPageMode,
matchFlavours,
Point,
} from '../../_common/utils/index.js';
Expand Down Expand Up @@ -53,8 +53,7 @@ export class FileDropManager {
}

get isPageMode(): boolean {
const editor = getEditorContainer(this._blockService.page);
return editor.mode === 'page';
return isPageMode(this._blockService.page);
}

get type(): 'before' | 'after' {
Expand Down Expand Up @@ -95,7 +94,7 @@ export class FileDropManager {
let result = null;
let rect = null;
if (element) {
const model = getModelByBlockElement(element);
const model = getModelByBlockComponent(element);
result = calcDropTarget(point, model, element);
if (result) {
rect = result.rect;
Expand Down
4 changes: 2 additions & 2 deletions packages/blocks/src/_common/components/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BaseBlockModel } from '@blocksuite/store';
import { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';

import { BLOCK_ID_ATTR, BLOCK_SERVICE_LOADING_ATTR } from '../consts.js';
import { BLOCK_ID_ATTR } from '../consts.js';

@customElement('loader-element')
export class Loader extends LitElement {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class Loader extends LitElement {
super.connectedCallback();
if (this.hostModel) {
this.setAttribute(BLOCK_ID_ATTR, this.hostModel.id);
this.setAttribute(BLOCK_SERVICE_LOADING_ATTR, 'true');
this.setAttribute('data-service-loading', 'true');
}

const width = this.width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { customElement, property, state } from 'lit/decorators.js';
import type { DocPageBlockComponent } from '../../../../../page-block/doc/doc-page-block.js';
import { FontLinkedPageIcon, FontPageIcon } from '../../../../icons/index.js';
import {
getBlockElementByModel,
getBlockComponentByModel,
getClosestBlockElementByElement,
getModelByElement,
} from '../../../../utils/index.js';
Expand Down Expand Up @@ -127,7 +127,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
const targetPageId = refMeta.id;
const root = model.page.root;
assertExists(root);
const element = getBlockElementByModel(root) as DocPageBlockComponent;
const element = getBlockComponentByModel(root) as DocPageBlockComponent;
assertExists(element);
element.slots.pageLinkClicked.emit({ pageId: targetPageId });
}
Expand Down
4 changes: 0 additions & 4 deletions packages/blocks/src/_common/consts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
export const BLOCK_ID_ATTR = 'data-block-id';
export const BLOCK_SERVICE_LOADING_ATTR = 'data-service-loading';
export const SCROLL_THRESHOLD = 100;

export const NOTE_WIDTH = 800;
export const BLOCK_CHILDREN_CONTAINER_PADDING_LEFT = 26;
export const PAGE_BLOCK_CHILD_PADDING = 24;
export const EDGELESS_BLOCK_CHILD_PADDING = 24;
export const EDGELESS_BLOCK_CHILD_BORDER_WIDTH = 2;
export const ACTIVE_NOTE_EXTRA_PADDING = 20;

// The height of the header, which is used to calculate the scroll offset
// In AFFiNE, to avoid the option element to be covered by the header, we need to reserve the space for the header
Expand Down
16 changes: 8 additions & 8 deletions packages/blocks/src/_common/utils/drag-and-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import type { BaseBlockModel } from '@blocksuite/store';

import { matchFlavours } from './model.js';
import {
type BlockComponentElement,
type BlockComponent,
DropFlags,
getClosestBlockElementByElement,
getDropRectByPoint,
getModelByBlockElement,
getModelByBlockComponent,
getRectByBlockElement,
} from './query.js';
import { type Point, Rect } from './rect.js';
Expand All @@ -31,7 +31,7 @@ export function calcDropTarget(
point: Point,
model: BaseBlockModel,
element: Element,
draggingElements: BlockComponentElement[] = [],
draggingElements: BlockComponent[] = [],
scale: number = 1,
flavour: string | null = null // for block-hub
): DropResult | null {
Expand All @@ -44,7 +44,7 @@ export function calcDropTarget(
if (children.length) {
if (draggingElements.length) {
shouldAppendToDatabase = draggingElements
.map(getModelByBlockElement)
.map(getModelByBlockComponent)
.every(m => children.includes(m.flavour));
} else if (flavour) {
shouldAppendToDatabase = children.includes(flavour);
Expand All @@ -55,7 +55,7 @@ export function calcDropTarget(
const databaseBlockElement = element.closest('affine-database');
if (databaseBlockElement) {
element = databaseBlockElement;
model = getModelByBlockElement(element);
model = getModelByBlockComponent(element);
}
}

Expand All @@ -76,7 +76,7 @@ export function calcDropTarget(
modelState: {
model,
rect: domRect,
element: element as BlockComponentElement,
element: element as BlockComponent,
},
};
} else if (flag === DropFlags.Database) {
Expand All @@ -97,7 +97,7 @@ export function calcDropTarget(
modelState: {
model,
rect: domRect,
element: element as BlockComponentElement,
element: element as BlockComponent,
},
};
}
Expand Down Expand Up @@ -171,7 +171,7 @@ export function calcDropTarget(
modelState: {
model,
rect: domRect,
element: element as BlockComponentElement,
element: element as BlockComponent,
},
};
}
Loading

0 comments on commit 565b88e

Please sign in to comment.