diff --git a/blocksuite/affine/all/vitest.config.ts b/blocksuite/affine/all/vitest.config.ts deleted file mode 100644 index 700f600c64..0000000000 --- a/blocksuite/affine/all/vitest.config.ts +++ /dev/null @@ -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', - }, -}); diff --git a/blocksuite/affine/block-paragraph/vitest.config.ts b/blocksuite/affine/block-paragraph/vitest.config.ts deleted file mode 100644 index b39a4f9ea8..0000000000 --- a/blocksuite/affine/block-paragraph/vitest.config.ts +++ /dev/null @@ -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', - }, -}); diff --git a/blocksuite/affine/block-surface/src/index.ts b/blocksuite/affine/block-surface/src/index.ts index 4611c4607b..488dd11f16 100644 --- a/blocksuite/affine/block-surface/src/index.ts +++ b/blocksuite/affine/block-surface/src/index.ts @@ -65,34 +65,6 @@ export { } from './utils/mindmap/layout.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 { addTree, containsNode, @@ -107,8 +79,10 @@ export * from './extensions'; export { addNote, addNoteAtPoint, + generateElementId, getLastPropsKey, getSurfaceBlock, + normalizeWheelDeltaY, } from './utils'; export type { Options } from './utils/rough/core'; export { sortIndex } from './utils/sort'; @@ -132,32 +106,6 @@ export const TextUtils = { 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 = { addTree, createFromTree, diff --git a/blocksuite/affine/components/vitest.config.ts b/blocksuite/affine/components/vitest.config.ts deleted file mode 100644 index 3243b60ffb..0000000000 --- a/blocksuite/affine/components/vitest.config.ts +++ /dev/null @@ -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', - }, -}); diff --git a/blocksuite/affine/data-view/vitest.config.ts b/blocksuite/affine/data-view/vitest.config.ts deleted file mode 100644 index 9ae9d1cc50..0000000000 --- a/blocksuite/affine/data-view/vitest.config.ts +++ /dev/null @@ -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', - }, -}); diff --git a/blocksuite/affine/model/vitest.config.ts b/blocksuite/affine/model/vitest.config.ts deleted file mode 100644 index 9faa866c54..0000000000 --- a/blocksuite/affine/model/vitest.config.ts +++ /dev/null @@ -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', - }, -}); diff --git a/blocksuite/affine/widget-scroll-anchoring/vitest.config.ts b/blocksuite/affine/widget-scroll-anchoring/vitest.config.ts deleted file mode 100644 index 04dcaa6f15..0000000000 --- a/blocksuite/affine/widget-scroll-anchoring/vitest.config.ts +++ /dev/null @@ -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', - }, -}); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/auto-complete-panel.ts b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/auto-complete-panel.ts index a1d69b4df2..305670eb88 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/auto-complete-panel.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/auto-complete-panel.ts @@ -1,6 +1,5 @@ import { CanvasElementType, - CommonUtils, EdgelessCRUDIdentifier, } from '@blocksuite/affine-block-surface'; import { @@ -36,7 +35,10 @@ import type { XYWH } from '@blocksuite/global/utils'; import { assertInstanceOf, Bound, + clamp, + normalizeDegAngle, serializeXYWH, + toDegree, Vec, WithDisposable, } from '@blocksuite/global/utils'; @@ -342,10 +344,8 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) { if (!point) return; const len = connector.path.length; - const angle = CommonUtils.normalizeDegAngle( - CommonUtils.toDegree( - Vec.angle(connector.path[len - 2], connector.path[len - 1]) - ) + const angle = normalizeDegAngle( + toDegree(Vec.angle(connector.path[len - 2], connector.path[len - 1])) ); let nextBound: Bound; let position: Connection['position']; @@ -399,8 +399,8 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) { const coord = viewport.toViewCoord(pos[0], pos[1]); const { width, height } = viewportRect; - coord[0] = CommonUtils.clamp(coord[0], 20, width - 20 - PANEL_WIDTH); - coord[1] = CommonUtils.clamp(coord[1], 20, height - 20 - PANEL_HEIGHT); + coord[0] = clamp(coord[0], 20, width - 20 - PANEL_WIDTH); + coord[1] = clamp(coord[1], 20, height - 20 - PANEL_HEIGHT); return coord; } diff --git a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts index e9b0ae18a9..8e62fb666d 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/auto-complete/utils.ts @@ -1,5 +1,4 @@ import { - CommonUtils, type Options, Overlay, type RoughCanvas, @@ -17,7 +16,7 @@ import { import type { GfxController, GfxModel } from '@blocksuite/block-std/gfx'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; 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 type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js'; @@ -193,7 +192,7 @@ export function nextBound( angle = 270; break; } - angle = CommonUtils.normalizeDegAngle(angle + curShape.rotate); + angle = normalizeDegAngle(angle + curShape.rotate); if (angle >= 45 && angle <= 135) { nextBound = new Bound(x, y + h + MAIN_GAP, w, h); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts b/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts index 8f447453b5..8732f813ad 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/rects/edgeless-selected-rect.ts @@ -8,7 +8,6 @@ import { } from '@blocksuite/affine-block-embed'; import { CanvasElementType, - CommonUtils, normalizeShapeBound, OverlayIdentifier, TextUtils, @@ -54,6 +53,7 @@ import { assertType, Bound, deserializeXYWH, + normalizeDegAngle, pickValues, Slot, } from '@blocksuite/global/utils'; @@ -597,7 +597,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent< } else { this.gfx.updateElement(id, { xywh: bounds.serialize(), - rotate: CommonUtils.normalizeDegAngle(rotate + delta), + rotate: normalizeDegAngle(rotate + delta), }); } }); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts b/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts index 2f2ab2b8e6..312f760a79 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/resize/resize-manager.ts @@ -1,4 +1,3 @@ -import { CommonUtils } from '@blocksuite/affine-block-surface'; import { NOTE_MIN_WIDTH } from '@blocksuite/affine-model'; import { assertExists, @@ -7,13 +6,12 @@ import { type IPoint, type IVec, type PointLocation, + rotatePoints, } from '@blocksuite/global/utils'; import type { SelectableProps } from '../../utils/query.js'; import { HandleDirection, type ResizeMode } from './resize-handles.js'; -const { rotatePoints } = CommonUtils; - // 15deg const SHIFT_LOCKING_ANGLE = Math.PI / 12; diff --git a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-shape-text-editor.ts b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-shape-text-editor.ts index 2a15c9afe9..760da7d905 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-shape-text-editor.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-shape-text-editor.ts @@ -1,5 +1,4 @@ import { - CommonUtils, EdgelessCRUDIdentifier, TextUtils, } from '@blocksuite/affine-block-surface'; @@ -15,6 +14,7 @@ import { import { assertExists, Bound, + toRadian, Vec, WithDisposable, } from '@blocksuite/global/utils'; @@ -25,8 +25,6 @@ import * as Y from 'yjs'; import type { EdgelessRootBlockComponent } from '../../edgeless-root-block.js'; -const { toRadian } = CommonUtils; - export class EdgelessShapeTextEditor extends WithDisposable(ShadowlessElement) { get crud() { return this.edgeless.std.get(EdgelessCRUDIdentifier); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts index 1d2cf89fb8..ab0b592efe 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/text/edgeless-text-editor.ts @@ -1,5 +1,4 @@ import { - CommonUtils, EdgelessCRUDIdentifier, TextUtils, } from '@blocksuite/affine-block-surface'; @@ -14,6 +13,7 @@ import { import { assertExists, Bound, + toRadian, Vec, WithDisposable, } 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 { deleteElements } from '../../utils/crud.js'; -const { toRadian } = CommonUtils; - export class EdgelessTextEditor extends WithDisposable(ShadowlessElement) { get crud() { return this.edgeless.std.get(EdgelessCRUDIdentifier); diff --git a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/presentation-toolbar.ts b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/presentation-toolbar.ts index 3260ca6c0f..17fb3d3d30 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/toolbar/presentation-toolbar.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/toolbar/presentation-toolbar.ts @@ -1,4 +1,3 @@ -import { CommonUtils } from '@blocksuite/affine-block-surface'; import { FrameNavigatorNextIcon, FrameNavigatorPrevIcon, @@ -10,7 +9,7 @@ import { toast } from '@blocksuite/affine-components/toast'; import type { FrameBlockModel } from '@blocksuite/affine-model'; import { EditPropsStore } from '@blocksuite/affine-shared/services'; 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 { cssVar } from '@toeverything/theme'; 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 { EdgelessToolbarToolMixin } from './mixins/tool.mixin.js'; -const { clamp } = CommonUtils; - export class PresentationToolbar extends EdgelessToolbarToolMixin( SignalWatcher(LitElement) ) { diff --git a/blocksuite/blocks/src/root-block/edgeless/components/utils.ts b/blocksuite/blocks/src/root-block/edgeless/components/utils.ts index 70b29af38c..3ec17f23ed 100644 --- a/blocksuite/blocks/src/root-block/edgeless/components/utils.ts +++ b/blocksuite/blocks/src/root-block/edgeless/components/utils.ts @@ -1,7 +1,6 @@ -import { CommonUtils } from '@blocksuite/affine-block-surface'; import type { CursorType, StandardCursor } from '@blocksuite/block-std/gfx'; 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'; // ""; @@ -93,7 +92,7 @@ export function calcAngle(target: HTMLElement, point: IVec, offset = 0) { assertExists(rect); const { left, top, right, bottom } = rect; const center = Vec.med([left, top], [right, bottom]); - return CommonUtils.normalizeDegAngle( + return normalizeDegAngle( ((Vec.angle(center, point) + offset) * 180) / Math.PI ); } @@ -155,9 +154,7 @@ export function calcAngleWithRotation( const c = new DOMPoint(...center).matrixTransform(m); - return CommonUtils.normalizeDegAngle( - (Vec.angle([c.x, c.y], point) * 180) / Math.PI - ); + return normalizeDegAngle((Vec.angle([c.x, c.y], point) * 180) / Math.PI); } export function calcAngleEdgeWithRotation(target: HTMLElement, rotate: number) { diff --git a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts index a6528f6137..b651763bff 100644 --- a/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts +++ b/blocksuite/blocks/src/root-block/edgeless/edgeless-root-block.ts @@ -3,8 +3,8 @@ import type { SurfaceBlockModel, } from '@blocksuite/affine-block-surface'; import { - CommonUtils, EdgelessLegacySlotIdentifier, + normalizeWheelDeltaY, } from '@blocksuite/affine-block-surface'; import type { RootBlockModel, @@ -49,8 +49,6 @@ import { getBackgroundGrid, isCanvasElement } from './utils/query.js'; import { mountShapeTextEditor } from './utils/text.js'; import { fitToScreen } from './utils/viewport.js'; -const { normalizeWheelDeltaY } = CommonUtils; - export class EdgelessRootBlockComponent extends BlockComponent< RootBlockModel, EdgelessRootService, diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts index a8498c8941..07ca2951f4 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/eraser-tool.ts @@ -1,5 +1,4 @@ import { - CommonUtils, EdgelessCRUDIdentifier, Overlay, type SurfaceBlockComponent, @@ -7,9 +6,13 @@ import { import { isTopLevelBlock } from '@blocksuite/affine-shared/utils'; import type { PointerEventState } from '@blocksuite/block-std'; import { BaseTool } from '@blocksuite/block-std/gfx'; -import { Bound, type IVec } from '@blocksuite/global/utils'; - -const { getSvgPathFromStroke, getStroke, linePolygonIntersects } = CommonUtils; +import { + Bound, + getStroke, + getSvgPathFromStroke, + type IVec, + linePolygonIntersects, +} from '@blocksuite/global/utils'; class EraserOverlay extends Overlay { d = ''; diff --git a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts index e81e924764..f579bfb48e 100644 --- a/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts +++ b/blocksuite/blocks/src/root-block/edgeless/gfx-tool/lasso-tool.ts @@ -1,5 +1,4 @@ import { - CommonUtils, Overlay, type SurfaceBlockComponent, } from '@blocksuite/affine-block-surface'; @@ -12,6 +11,7 @@ import { Bound, getBoundFromPoints, getPolygonPathFromPoints, + getSvgPathFromStroke, linePolygonIntersects, pointInPolygon, rotatePoints, @@ -70,7 +70,7 @@ export class LassoTool extends BaseTool { private readonly _loop = () => { const path = this.activatedOption.mode === LassoMode.FreeHand - ? CommonUtils.getSvgPathFromStroke(this._lassoPoints) + ? getSvgPathFromStroke(this._lassoPoints) : getPolygonPathFromPoints(this._lassoPoints); this._overlay.d = path; diff --git a/blocksuite/blocks/src/root-block/edgeless/services/template-middlewares.ts b/blocksuite/blocks/src/root-block/edgeless/services/template-middlewares.ts index f01add8f99..6c23d09f4a 100644 --- a/blocksuite/blocks/src/root-block/edgeless/services/template-middlewares.ts +++ b/blocksuite/blocks/src/root-block/edgeless/services/template-middlewares.ts @@ -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 { assertExists, assertType, Bound } from '@blocksuite/global/utils'; import type { BlockSnapshot, SnapshotNode } from '@blocksuite/store'; @@ -50,7 +50,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => { Object.entries( blockJson.props.elements as Record> ).forEach(([id, val]) => { - const newId = CommonUtils.generateElementId(); + const newId = generateElementId(); regeneratedIdMap.set(id, newId); val.id = newId; diff --git a/blocksuite/blocks/src/root-block/edgeless/utils/query.ts b/blocksuite/blocks/src/root-block/edgeless/utils/query.ts index 5326ed9f4c..7ee4133fbc 100644 --- a/blocksuite/blocks/src/root-block/edgeless/utils/query.ts +++ b/blocksuite/blocks/src/root-block/edgeless/utils/query.ts @@ -1,6 +1,5 @@ import { type CanvasElementWithText, - CommonUtils, GRID_GAP_MAX, GRID_GAP_MIN, } from '@blocksuite/affine-block-surface'; @@ -36,13 +35,11 @@ import type { Viewport, } from '@blocksuite/block-std/gfx'; 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 { Connectable } from '../../../_common/utils/index.js'; -const { clamp } = CommonUtils; - export function isMindmapNode( element: GfxBlockElementModel | BlockSuite.EdgelessModel | null ) { diff --git a/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts b/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts index b27ec9f897..dc200938ea 100644 --- a/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts +++ b/blocksuite/blocks/src/root-block/widgets/element-toolbar/index.ts @@ -1,5 +1,4 @@ import type { BuiltInEmbedModel } from '@blocksuite/affine-block-bookmark'; -import { CommonUtils } from '@blocksuite/affine-block-surface'; import { ConnectorCWithArrowIcon } from '@blocksuite/affine-components/icons'; import { cloneGroups, @@ -31,6 +30,7 @@ import { requestConnectedFrame } from '@blocksuite/affine-shared/utils'; import { WidgetComponent } from '@blocksuite/block-std'; import { atLeastNMatches, + clamp, getCommonBoundWithRotation, groupBy, pickValues, @@ -238,8 +238,8 @@ export class EdgelessElementToolbarWidget extends WidgetComponent< left += 0.5 * (w - rect.width); } - left = CommonUtils.clamp(left, 10, width - rect.width - 10); - top = CommonUtils.clamp(top, 10, height - rect.height - 150); + left = clamp(left, 10, width - rect.width - 10); + top = clamp(top, 10, height - rect.height - 150); this.style.transform = `translate3d(${left}px, ${top}px, 0)`; }, this); diff --git a/blocksuite/presets/src/__tests__/edgeless/layer.spec.ts b/blocksuite/presets/src/__tests__/edgeless/layer.spec.ts index 6ac120fec5..15c61178c3 100644 --- a/blocksuite/presets/src/__tests__/edgeless/layer.spec.ts +++ b/blocksuite/presets/src/__tests__/edgeless/layer.spec.ts @@ -1,5 +1,5 @@ -import { CommonUtils } from '@blocksuite/affine-block-surface'; import type { BlockComponent } from '@blocksuite/block-std'; +import { generateKeyBetween } from '@blocksuite/block-std/gfx'; import type { EdgelessRootBlockComponent, GroupElementModel, @@ -238,7 +238,7 @@ test('blocks should rerender when their z-index changed', async () => { service.crud.addElement('shape', { shapeType: 'rect', - index: CommonUtils.generateKeyBetween( + index: generateKeyBetween( service.crud.getElementById(blocks[1])!.index, service.crud.getElementById(blocks[2])!.index ),