chore(editor): remove common utils in surface block (#9527)

This commit is contained in:
Saul-Mirone
2025-01-06 02:41:39 +00:00
parent 3d168ba2d2
commit c22804766d
22 changed files with 38 additions and 285 deletions

View File

@@ -1,30 +0,0 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
esbuild: {
target: 'es2018',
},
test: {
globalSetup: '../../../scripts/vitest-global.js',
include: ['src/__tests__/**/*.unit.spec.ts'],
testTimeout: 1000,
coverage: {
provider: 'istanbul', // or 'c8'
reporter: ['lcov'],
reportsDirectory: '../../../.coverage/affine',
},
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog(log, type) {
if (log.includes('https://lit.dev/msg/dev-mode')) {
return false;
}
console.warn(`Unexpected ${type} log`, log);
throw new Error(log);
},
environment: 'happy-dom',
},
});

View File

@@ -1,30 +0,0 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
esbuild: {
target: 'es2018',
},
test: {
globalSetup: '../../../scripts/vitest-global.js',
include: ['src/__tests__/**/*.unit.spec.ts'],
testTimeout: 1000,
coverage: {
provider: 'istanbul', // or 'c8'
reporter: ['lcov'],
reportsDirectory: '../../../.coverage/affine-block-paragraph',
},
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog(log, type) {
if (log.includes('https://lit.dev/msg/dev-mode')) {
return false;
}
console.warn(`Unexpected ${type} log`, log);
throw new Error(log);
},
environment: 'happy-dom',
},
});

View File

@@ -65,34 +65,6 @@ export {
} from './utils/mindmap/layout.js'; } from './utils/mindmap/layout.js';
export { RoughCanvas } from './utils/rough/canvas.js'; export { RoughCanvas } from './utils/rough/canvas.js';
import {
almostEqual,
clamp,
getPointFromBoundsWithRotation,
getStroke,
getSvgPathFromStroke,
intersects,
isOverlap,
isPointIn,
lineIntersects,
linePolygonIntersects,
normalizeDegAngle,
polygonGetPointTangent,
polygonNearestPoint,
polygonPointDistance,
polyLineNearestPoint,
rotatePoints,
sign,
toDegree,
toRadian,
} from '@blocksuite/global/utils';
import { generateKeyBetween } from 'fractional-indexing';
import {
generateElementId,
getLastPropsKey,
normalizeWheelDeltaY,
} from './utils';
import { import {
addTree, addTree,
containsNode, containsNode,
@@ -107,8 +79,10 @@ export * from './extensions';
export { export {
addNote, addNote,
addNoteAtPoint, addNoteAtPoint,
generateElementId,
getLastPropsKey, getLastPropsKey,
getSurfaceBlock, getSurfaceBlock,
normalizeWheelDeltaY,
} from './utils'; } from './utils';
export type { Options } from './utils/rough/core'; export type { Options } from './utils/rough/core';
export { sortIndex } from './utils/sort'; export { sortIndex } from './utils/sort';
@@ -132,32 +106,6 @@ export const TextUtils = {
isSameFontFamily, isSameFontFamily,
}; };
export const CommonUtils = {
almostEqual,
clamp,
generateElementId,
generateKeyBetween,
getPointFromBoundsWithRotation,
getStroke,
getSvgPathFromStroke,
getLastPropsKey,
intersects,
isOverlap,
isPointIn,
lineIntersects,
linePolygonIntersects,
normalizeDegAngle,
normalizeWheelDeltaY,
polygonGetPointTangent,
polygonNearestPoint,
polygonPointDistance,
polyLineNearestPoint,
rotatePoints,
sign,
toDegree,
toRadian,
};
export const MindmapUtils = { export const MindmapUtils = {
addTree, addTree,
createFromTree, createFromTree,

View File

@@ -1,30 +0,0 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
esbuild: {
target: 'es2018',
},
test: {
globalSetup: '../../../scripts/vitest-global.js',
include: ['src/__tests__/**/*.unit.spec.ts'],
testTimeout: 1000,
coverage: {
provider: 'istanbul', // or 'c8'
reporter: ['lcov'],
reportsDirectory: '../../../.coverage/affine-components',
},
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog(log, type) {
if (log.includes('https://lit.dev/msg/dev-mode')) {
return false;
}
console.warn(`Unexpected ${type} log`, log);
throw new Error(log);
},
environment: 'happy-dom',
},
});

View File

@@ -1,30 +0,0 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
esbuild: {
target: 'es2018',
},
test: {
globalSetup: '../../scripts/vitest-global.js',
include: ['src/__tests__/**/*.unit.spec.ts'],
testTimeout: 1000,
coverage: {
provider: 'istanbul', // or 'c8'
reporter: ['lcov'],
reportsDirectory: '../../.coverage/blocks',
},
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog(log, type) {
if (log.includes('https://lit.dev/msg/dev-mode')) {
return false;
}
console.warn(`Unexpected ${type} log`, log);
throw new Error(log);
},
environment: 'happy-dom',
},
});

View File

@@ -1,30 +0,0 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
esbuild: {
target: 'es2018',
},
test: {
globalSetup: '../../scripts/vitest-global.js',
include: ['src/__tests__/**/*.unit.spec.ts'],
testTimeout: 1000,
coverage: {
provider: 'istanbul', // or 'c8'
reporter: ['lcov'],
reportsDirectory: '../../../.coverage/affine-model',
},
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog(log, type) {
if (log.includes('https://lit.dev/msg/dev-mode')) {
return false;
}
console.warn(`Unexpected ${type} log`, log);
throw new Error(log);
},
environment: 'happy-dom',
},
});

View File

@@ -1,30 +0,0 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
esbuild: {
target: 'es2018',
},
test: {
globalSetup: '../../../scripts/vitest-global.js',
include: ['src/__tests__/**/*.unit.spec.ts'],
testTimeout: 1000,
coverage: {
provider: 'istanbul', // or 'c8'
reporter: ['lcov'],
reportsDirectory: '../../../.coverage/affine-widget-scroll-anchoring',
},
/**
* Custom handler for console.log in tests.
*
* Return `false` to ignore the log.
*/
onConsoleLog(log, type) {
if (log.includes('https://lit.dev/msg/dev-mode')) {
return false;
}
console.warn(`Unexpected ${type} log`, log);
throw new Error(log);
},
environment: 'happy-dom',
},
});

View File

@@ -1,6 +1,5 @@
import { import {
CanvasElementType, CanvasElementType,
CommonUtils,
EdgelessCRUDIdentifier, EdgelessCRUDIdentifier,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
import { import {
@@ -36,7 +35,10 @@ import type { XYWH } from '@blocksuite/global/utils';
import { import {
assertInstanceOf, assertInstanceOf,
Bound, Bound,
clamp,
normalizeDegAngle,
serializeXYWH, serializeXYWH,
toDegree,
Vec, Vec,
WithDisposable, WithDisposable,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
@@ -342,10 +344,8 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
if (!point) return; if (!point) return;
const len = connector.path.length; const len = connector.path.length;
const angle = CommonUtils.normalizeDegAngle( const angle = normalizeDegAngle(
CommonUtils.toDegree( toDegree(Vec.angle(connector.path[len - 2], connector.path[len - 1]))
Vec.angle(connector.path[len - 2], connector.path[len - 1])
)
); );
let nextBound: Bound; let nextBound: Bound;
let position: Connection['position']; let position: Connection['position'];
@@ -399,8 +399,8 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
const coord = viewport.toViewCoord(pos[0], pos[1]); const coord = viewport.toViewCoord(pos[0], pos[1]);
const { width, height } = viewportRect; const { width, height } = viewportRect;
coord[0] = CommonUtils.clamp(coord[0], 20, width - 20 - PANEL_WIDTH); coord[0] = clamp(coord[0], 20, width - 20 - PANEL_WIDTH);
coord[1] = CommonUtils.clamp(coord[1], 20, height - 20 - PANEL_HEIGHT); coord[1] = clamp(coord[1], 20, height - 20 - PANEL_HEIGHT);
return coord; return coord;
} }

View File

@@ -1,5 +1,4 @@
import { import {
CommonUtils,
type Options, type Options,
Overlay, Overlay,
type RoughCanvas, type RoughCanvas,
@@ -17,7 +16,7 @@ import {
import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx'; import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { XYWH } from '@blocksuite/global/utils'; import type { XYWH } from '@blocksuite/global/utils';
import { assertType, Bound } from '@blocksuite/global/utils'; import { assertType, Bound, normalizeDegAngle } from '@blocksuite/global/utils';
import * as Y from 'yjs'; import * as Y from 'yjs';
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js'; import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
@@ -193,7 +192,7 @@ export function nextBound(
angle = 270; angle = 270;
break; break;
} }
angle = CommonUtils.normalizeDegAngle(angle + curShape.rotate); angle = normalizeDegAngle(angle + curShape.rotate);
if (angle >= 45 && angle <= 135) { if (angle >= 45 && angle <= 135) {
nextBound = new Bound(x, y + h + MAIN_GAP, w, h); nextBound = new Bound(x, y + h + MAIN_GAP, w, h);

View File

@@ -8,7 +8,6 @@ import {
} from '@blocksuite/affine-block-embed'; } from '@blocksuite/affine-block-embed';
import { import {
CanvasElementType, CanvasElementType,
CommonUtils,
normalizeShapeBound, normalizeShapeBound,
OverlayIdentifier, OverlayIdentifier,
TextUtils, TextUtils,
@@ -54,6 +53,7 @@ import {
assertType, assertType,
Bound, Bound,
deserializeXYWH, deserializeXYWH,
normalizeDegAngle,
pickValues, pickValues,
Slot, Slot,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
@@ -597,7 +597,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
} else { } else {
this.gfx.updateElement(id, { this.gfx.updateElement(id, {
xywh: bounds.serialize(), xywh: bounds.serialize(),
rotate: CommonUtils.normalizeDegAngle(rotate + delta), rotate: normalizeDegAngle(rotate + delta),
}); });
} }
}); });

View File

@@ -1,4 +1,3 @@
import { CommonUtils } from '@blocksuite/affine-block-surface';
import { NOTE_MIN_WIDTH } from '@blocksuite/affine-model'; import { NOTE_MIN_WIDTH } from '@blocksuite/affine-model';
import { import {
assertExists, assertExists,
@@ -7,13 +6,12 @@ import {
type IPoint, type IPoint,
type IVec, type IVec,
type PointLocation, type PointLocation,
rotatePoints,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
import type { SelectableProps } from '../../utils/query.js'; import type { SelectableProps } from '../../utils/query.js';
import { HandleDirection, type ResizeMode } from './resize-handles.js'; import { HandleDirection, type ResizeMode } from './resize-handles.js';
const { rotatePoints } = CommonUtils;
// 15deg // 15deg
const SHIFT_LOCKING_ANGLE = Math.PI / 12; const SHIFT_LOCKING_ANGLE = Math.PI / 12;

View File

@@ -1,5 +1,4 @@
import { import {
CommonUtils,
EdgelessCRUDIdentifier, EdgelessCRUDIdentifier,
TextUtils, TextUtils,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
@@ -15,6 +14,7 @@ import {
import { import {
assertExists, assertExists,
Bound, Bound,
toRadian,
Vec, Vec,
WithDisposable, WithDisposable,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
@@ -25,8 +25,6 @@ import * as Y from 'yjs';
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js'; import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
const { toRadian } = CommonUtils;
export class EdgelessShapeTextEditor extends WithDisposable(ShadowlessElement) { export class EdgelessShapeTextEditor extends WithDisposable(ShadowlessElement) {
get crud() { get crud() {
return this.edgeless.std.get(EdgelessCRUDIdentifier); return this.edgeless.std.get(EdgelessCRUDIdentifier);

View File

@@ -1,5 +1,4 @@
import { import {
CommonUtils,
EdgelessCRUDIdentifier, EdgelessCRUDIdentifier,
TextUtils, TextUtils,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
@@ -14,6 +13,7 @@ import {
import { import {
assertExists, assertExists,
Bound, Bound,
toRadian,
Vec, Vec,
WithDisposable, WithDisposable,
} from '@blocksuite/global/utils'; } from '@blocksuite/global/utils';
@@ -24,8 +24,6 @@ import { styleMap } from 'lit/directives/style-map.js';
import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js'; import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js';
import { deleteElements } from '../../utils/crud.js'; import { deleteElements } from '../../utils/crud.js';
const { toRadian } = CommonUtils;
export class EdgelessTextEditor extends WithDisposable(ShadowlessElement) { export class EdgelessTextEditor extends WithDisposable(ShadowlessElement) {
get crud() { get crud() {
return this.edgeless.std.get(EdgelessCRUDIdentifier); return this.edgeless.std.get(EdgelessCRUDIdentifier);

View File

@@ -1,4 +1,3 @@
import { CommonUtils } from '@blocksuite/affine-block-surface';
import { import {
FrameNavigatorNextIcon, FrameNavigatorNextIcon,
FrameNavigatorPrevIcon, FrameNavigatorPrevIcon,
@@ -10,7 +9,7 @@ import { toast } from '@blocksuite/affine-components/toast';
import type { FrameBlockModel } from '@blocksuite/affine-model'; import type { FrameBlockModel } from '@blocksuite/affine-model';
import { EditPropsStore } from '@blocksuite/affine-shared/services'; import { EditPropsStore } from '@blocksuite/affine-shared/services';
import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx'; import type { GfxToolsFullOptionValue } from '@blocksuite/block-std/gfx';
import { Bound, SignalWatcher } from '@blocksuite/global/utils'; import { Bound, clamp, SignalWatcher } from '@blocksuite/global/utils';
import { effect } from '@preact/signals-core'; import { effect } from '@preact/signals-core';
import { cssVar } from '@toeverything/theme'; import { cssVar } from '@toeverything/theme';
import { css, html, LitElement, nothing, type PropertyValues } from 'lit'; import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
@@ -22,8 +21,6 @@ import { isFrameBlock } from '../../utils/query.js';
import { launchIntoFullscreen } from '../utils.js'; import { launchIntoFullscreen } from '../utils.js';
import { EdgelessToolbarToolMixin } from './mixins/tool.mixin.js'; import { EdgelessToolbarToolMixin } from './mixins/tool.mixin.js';
const { clamp } = CommonUtils;
export class PresentationToolbar extends EdgelessToolbarToolMixin( export class PresentationToolbar extends EdgelessToolbarToolMixin(
SignalWatcher(LitElement) SignalWatcher(LitElement)
) { ) {

View File

@@ -1,7 +1,6 @@
import { CommonUtils } from '@blocksuite/affine-block-surface';
import type { CursorType, StandardCursor } from '@blocksuite/block-std/gfx'; import type { CursorType, StandardCursor } from '@blocksuite/block-std/gfx';
import type { IVec } from '@blocksuite/global/utils'; import type { IVec } from '@blocksuite/global/utils';
import { assertExists, Vec } from '@blocksuite/global/utils'; import { assertExists, normalizeDegAngle, Vec } from '@blocksuite/global/utils';
import { css, html } from 'lit'; import { css, html } from 'lit';
// "<svg width='32' height='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'><g><path fill='white' d='M13.7,18.5h3.9l0-1.5c0-1.4-1.2-2.6-2.6-2.6h-1.5v3.9l-5.8-5.8l5.8-5.8v3.9h2.3c3.1,0,5.6,2.5,5.6,5.6v2.3h3.9l-5.8,5.8L13.7,18.5z'/><path d='M20.4,19.4v-3.2c0-2.6-2.1-4.7-4.7-4.7h-3.2l0,0V9L9,12.6l3.6,3.6v-2.6l0,0H15c1.9,0,3.5,1.6,3.5,3.5v2.4l0,0h-2.6l3.6,3.6l3.6-3.6L20.4,19.4L20.4,19.4z'/></g></svg>"; // "<svg width='32' height='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'><g><path fill='white' d='M13.7,18.5h3.9l0-1.5c0-1.4-1.2-2.6-2.6-2.6h-1.5v3.9l-5.8-5.8l5.8-5.8v3.9h2.3c3.1,0,5.6,2.5,5.6,5.6v2.3h3.9l-5.8,5.8L13.7,18.5z'/><path d='M20.4,19.4v-3.2c0-2.6-2.1-4.7-4.7-4.7h-3.2l0,0V9L9,12.6l3.6,3.6v-2.6l0,0H15c1.9,0,3.5,1.6,3.5,3.5v2.4l0,0h-2.6l3.6,3.6l3.6-3.6L20.4,19.4L20.4,19.4z'/></g></svg>";
@@ -93,7 +92,7 @@ export function calcAngle(target: HTMLElement, point: IVec, offset = 0) {
assertExists(rect); assertExists(rect);
const { left, top, right, bottom } = rect; const { left, top, right, bottom } = rect;
const center = Vec.med([left, top], [right, bottom]); const center = Vec.med([left, top], [right, bottom]);
return CommonUtils.normalizeDegAngle( return normalizeDegAngle(
((Vec.angle(center, point) + offset) * 180) / Math.PI ((Vec.angle(center, point) + offset) * 180) / Math.PI
); );
} }
@@ -155,9 +154,7 @@ export function calcAngleWithRotation(
const c = new DOMPoint(...center).matrixTransform(m); const c = new DOMPoint(...center).matrixTransform(m);
return CommonUtils.normalizeDegAngle( return normalizeDegAngle((Vec.angle([c.x, c.y], point) * 180) / Math.PI);
(Vec.angle([c.x, c.y], point) * 180) / Math.PI
);
} }
export function calcAngleEdgeWithRotation(target: HTMLElement, rotate: number) { export function calcAngleEdgeWithRotation(target: HTMLElement, rotate: number) {

View File

@@ -3,8 +3,8 @@ import type {
SurfaceBlockModel, SurfaceBlockModel,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
import { import {
CommonUtils,
EdgelessLegacySlotIdentifier, EdgelessLegacySlotIdentifier,
normalizeWheelDeltaY,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
import type { import type {
RootBlockModel, RootBlockModel,
@@ -49,8 +49,6 @@ import { getBackgroundGrid, isCanvasElement } from './utils/query.js';
import { mountShapeTextEditor } from './utils/text.js'; import { mountShapeTextEditor } from './utils/text.js';
import { fitToScreen } from './utils/viewport.js'; import { fitToScreen } from './utils/viewport.js';
const { normalizeWheelDeltaY } = CommonUtils;
export class EdgelessRootBlockComponent extends BlockComponent< export class EdgelessRootBlockComponent extends BlockComponent<
RootBlockModel, RootBlockModel,
EdgelessRootService, EdgelessRootService,

View File

@@ -1,5 +1,4 @@
import { import {
CommonUtils,
EdgelessCRUDIdentifier, EdgelessCRUDIdentifier,
Overlay, Overlay,
type SurfaceBlockComponent, type SurfaceBlockComponent,
@@ -7,9 +6,13 @@ import {
import { isTopLevelBlock } from '@blocksuite/affine-shared/utils'; import { isTopLevelBlock } from '@blocksuite/affine-shared/utils';
import type { PointerEventState } from '@blocksuite/block-std'; import type { PointerEventState } from '@blocksuite/block-std';
import { BaseTool } from '@blocksuite/block-std/gfx'; import { BaseTool } from '@blocksuite/block-std/gfx';
import { Bound, type IVec } from '@blocksuite/global/utils'; import {
Bound,
const { getSvgPathFromStroke, getStroke, linePolygonIntersects } = CommonUtils; getStroke,
getSvgPathFromStroke,
type IVec,
linePolygonIntersects,
} from '@blocksuite/global/utils';
class EraserOverlay extends Overlay { class EraserOverlay extends Overlay {
d = ''; d = '';

View File

@@ -1,5 +1,4 @@
import { import {
CommonUtils,
Overlay, Overlay,
type SurfaceBlockComponent, type SurfaceBlockComponent,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
@@ -12,6 +11,7 @@ import {
Bound, Bound,
getBoundFromPoints, getBoundFromPoints,
getPolygonPathFromPoints, getPolygonPathFromPoints,
getSvgPathFromStroke,
linePolygonIntersects, linePolygonIntersects,
pointInPolygon, pointInPolygon,
rotatePoints, rotatePoints,
@@ -70,7 +70,7 @@ export class LassoTool extends BaseTool<LassoToolOption> {
private readonly _loop = () => { private readonly _loop = () => {
const path = const path =
this.activatedOption.mode === LassoMode.FreeHand this.activatedOption.mode === LassoMode.FreeHand
? CommonUtils.getSvgPathFromStroke(this._lassoPoints) ? getSvgPathFromStroke(this._lassoPoints)
: getPolygonPathFromPoints(this._lassoPoints); : getPolygonPathFromPoints(this._lassoPoints);
this._overlay.d = path; this._overlay.d = path;

View File

@@ -1,4 +1,4 @@
import { CommonUtils, sortIndex } from '@blocksuite/affine-block-surface'; import { generateElementId, sortIndex } from '@blocksuite/affine-block-surface';
import type { ConnectorElementModel } from '@blocksuite/affine-model'; import type { ConnectorElementModel } from '@blocksuite/affine-model';
import { assertExists, assertType, Bound } from '@blocksuite/global/utils'; import { assertExists, assertType, Bound } from '@blocksuite/global/utils';
import type { BlockSnapshot, SnapshotNode } from '@blocksuite/store'; import type { BlockSnapshot, SnapshotNode } from '@blocksuite/store';
@@ -50,7 +50,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
Object.entries( Object.entries(
blockJson.props.elements as Record<string, Record<string, unknown>> blockJson.props.elements as Record<string, Record<string, unknown>>
).forEach(([id, val]) => { ).forEach(([id, val]) => {
const newId = CommonUtils.generateElementId(); const newId = generateElementId();
regeneratedIdMap.set(id, newId); regeneratedIdMap.set(id, newId);
val.id = newId; val.id = newId;

View File

@@ -1,6 +1,5 @@
import { import {
type CanvasElementWithText, type CanvasElementWithText,
CommonUtils,
GRID_GAP_MAX, GRID_GAP_MAX,
GRID_GAP_MIN, GRID_GAP_MIN,
} from '@blocksuite/affine-block-surface'; } from '@blocksuite/affine-block-surface';
@@ -36,13 +35,11 @@ import type {
Viewport, Viewport,
} from '@blocksuite/block-std/gfx'; } from '@blocksuite/block-std/gfx';
import type { PointLocation } from '@blocksuite/global/utils'; import type { PointLocation } from '@blocksuite/global/utils';
import { Bound } from '@blocksuite/global/utils'; import { Bound, clamp } from '@blocksuite/global/utils';
import type { BlockModel } from '@blocksuite/store'; import type { BlockModel } from '@blocksuite/store';
import type { Connectable } from '../../../_common/utils/index.js'; import type { Connectable } from '../../../_common/utils/index.js';
const { clamp } = CommonUtils;
export function isMindmapNode( export function isMindmapNode(
element: GfxBlockElementModel | BlockSuite.EdgelessModel | null element: GfxBlockElementModel | BlockSuite.EdgelessModel | null
) { ) {

View File

@@ -1,5 +1,4 @@
import type { BuiltInEmbedModel } from '@blocksuite/affine-block-bookmark'; import type { BuiltInEmbedModel } from '@blocksuite/affine-block-bookmark';
import { CommonUtils } from '@blocksuite/affine-block-surface';
import { ConnectorCWithArrowIcon } from '@blocksuite/affine-components/icons'; import { ConnectorCWithArrowIcon } from '@blocksuite/affine-components/icons';
import { import {
cloneGroups, cloneGroups,
@@ -31,6 +30,7 @@ import { requestConnectedFrame } from '@blocksuite/affine-shared/utils';
import { WidgetComponent } from '@blocksuite/block-std'; import { WidgetComponent } from '@blocksuite/block-std';
import { import {
atLeastNMatches, atLeastNMatches,
clamp,
getCommonBoundWithRotation, getCommonBoundWithRotation,
groupBy, groupBy,
pickValues, pickValues,
@@ -238,8 +238,8 @@ export class EdgelessElementToolbarWidget extends WidgetComponent<
left += 0.5 * (w - rect.width); left += 0.5 * (w - rect.width);
} }
left = CommonUtils.clamp(left, 10, width - rect.width - 10); left = clamp(left, 10, width - rect.width - 10);
top = CommonUtils.clamp(top, 10, height - rect.height - 150); top = clamp(top, 10, height - rect.height - 150);
this.style.transform = `translate3d(${left}px, ${top}px, 0)`; this.style.transform = `translate3d(${left}px, ${top}px, 0)`;
}, this); }, this);

View File

@@ -1,5 +1,5 @@
import { CommonUtils } from '@blocksuite/affine-block-surface';
import type { BlockComponent } from '@blocksuite/block-std'; import type { BlockComponent } from '@blocksuite/block-std';
import { generateKeyBetween } from '@blocksuite/block-std/gfx';
import type { import type {
EdgelessRootBlockComponent, EdgelessRootBlockComponent,
GroupElementModel, GroupElementModel,
@@ -238,7 +238,7 @@ test('blocks should rerender when their z-index changed', async () => {
service.crud.addElement('shape', { service.crud.addElement('shape', {
shapeType: 'rect', shapeType: 'rect',
index: CommonUtils.generateKeyBetween( index: generateKeyBetween(
service.crud.getElementById(blocks[1])!.index, service.crud.getElementById(blocks[1])!.index,
service.crud.getElementById(blocks[2])!.index service.crud.getElementById(blocks[2])!.index
), ),