refactor(editor): use lodash (#10657)

This commit is contained in:
Saul-Mirone
2025-03-06 09:00:00 +00:00
parent 8062893603
commit 7ae9daa6f6
46 changed files with 160 additions and 555 deletions

View File

@@ -4,9 +4,10 @@ import {
getCommonBoundWithRotation,
type IBound,
} from '@blocksuite/global/gfx';
import { assertType, DisposableGroup, last } from '@blocksuite/global/utils';
import { assertType, DisposableGroup } from '@blocksuite/global/utils';
import type { BlockModel } from '@blocksuite/store';
import { Signal } from '@preact/signals-core';
import last from 'lodash-es/last';
import { LifeCycleWatcher } from '../extension/lifecycle-watcher.js';
import type { BlockStdScope } from '../scope/block-std-scope.js';

View File

@@ -1,12 +1,8 @@
import { Bound } from '@blocksuite/global/gfx';
import {
assertType,
DisposableGroup,
last,
Slot,
} from '@blocksuite/global/utils';
import { assertType, DisposableGroup, Slot } from '@blocksuite/global/utils';
import type { Store } from '@blocksuite/store';
import { generateKeyBetween } from 'fractional-indexing';
import last from 'lodash-es/last';
import {
compare,
@@ -162,7 +158,9 @@ export class LayerManager {
if (curLayer) {
curLayer.indexes = [
getElementIndex(curLayer.elements[0]),
getElementIndex(last(curLayer.elements)!),
getElementIndex(
last(curLayer.elements as GfxPrimitiveElementModel[])!
),
];
curLayer.zIndex = currentCSSZindex;
layers.push(curLayer as LayerManager['layers'][number]);
@@ -342,7 +340,10 @@ export class LayerManager {
if (
!last(this.layers) ||
[SortOrder.AFTER, SortOrder.SAME].includes(
compare(target, last(last(this.layers)!.elements)!)
compare(
target,
last(last(this.layers)!.elements as GfxPrimitiveElementModel[])!
)
)
) {
const layer = last(this.layers);
@@ -364,7 +365,15 @@ export class LayerManager {
const layer = layers[cur];
const layerElements = layer.elements;
if (isInRange([layerElements[0], last(layerElements)!], target)) {
if (
isInRange(
[
layerElements[0],
last(layerElements as GfxPrimitiveElementModel[])!,
],
target
)
) {
const insertIdx = layerElements.findIndex((_, idx) => {
const pre = layerElements[idx - 1];
return (
@@ -392,7 +401,13 @@ export class LayerManager {
} else {
const nextLayer = layers[cur - 1];
if (!nextLayer || compare(target, last(nextLayer.elements)!) >= 0) {
if (
!nextLayer ||
compare(
target,
last(nextLayer.elements as GfxPrimitiveElementModel[])!
) >= 0
) {
if (layer.type === type) {
addToLayer(layer, target, 0);
updateLayersZIndex(layers, cur);

View File

@@ -13,8 +13,9 @@ import {
type SerializedXYWH,
type XYWH,
} from '@blocksuite/global/gfx';
import { DisposableGroup, isEqual, Slot } from '@blocksuite/global/utils';
import { DisposableGroup, Slot } from '@blocksuite/global/utils';
import { createMutex } from 'lib0/mutex';
import isEqual from 'lodash-es/isEqual';
import * as Y from 'yjs';
import {

View File

@@ -2,12 +2,8 @@ import {
getCommonBoundWithRotation,
type IPoint,
} from '@blocksuite/global/gfx';
import {
assertType,
DisposableGroup,
groupBy,
Slot,
} from '@blocksuite/global/utils';
import { assertType, DisposableGroup, Slot } from '@blocksuite/global/utils';
import groupBy from 'lodash-es/groupBy';
import {
BlockSelection,

View File

@@ -1,4 +1,3 @@
import { nToLast } from '@blocksuite/global/utils';
import type { Store } from '@blocksuite/store';
import type { GfxLocalElementModel } from '../gfx/index.js';
@@ -113,17 +112,17 @@ export function compare(
| GfxModel
| GfxGroupCompatibleInterface
| GfxLocalElementModel
| undefined = nToLast(aGroups, i);
| undefined = aGroups.at(-i);
let bGroup:
| GfxModel
| GfxGroupCompatibleInterface
| GfxLocalElementModel
| undefined = nToLast(bGroups, i);
| undefined = bGroups.at(-i);
while (aGroup === bGroup && aGroup) {
++i;
aGroup = nToLast(aGroups, i);
bGroup = nToLast(bGroups, i);
aGroup = aGroups.at(-i);
bGroup = bGroups.at(-i);
}
aGroup = aGroup ?? a;