Move fractional index in element

This commit is contained in:
Marcel Mraz 2025-03-18 19:28:58 +01:00
parent 1c5b8372b9
commit 3782407c76
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
18 changed files with 88 additions and 45 deletions

View file

@ -3,7 +3,7 @@ import {
createRedoAction, createRedoAction,
createUndoAction, createUndoAction,
} from "@excalidraw/excalidraw/actions/actionHistory"; } from "@excalidraw/excalidraw/actions/actionHistory";
import { syncInvalidIndices } from "@excalidraw/excalidraw/fractionalIndex"; import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { API } from "@excalidraw/excalidraw/tests/helpers/api"; import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { act, render, waitFor } from "@excalidraw/excalidraw/tests/test-utils"; import { act, render, waitFor } from "@excalidraw/excalidraw/tests/test-utils";
import { vi } from "vitest"; import { vi } from "vitest";

View file

@ -47,7 +47,9 @@
"last 1 safari version" "last 1 safari version"
] ]
}, },
"dependencies": {}, "dependencies": {
"fractional-indexing": "3.2.0"
},
"devDependencies": {}, "devDependencies": {},
"bugs": "https://github.com/excalidraw/excalidraw/issues", "bugs": "https://github.com/excalidraw/excalidraw/issues",
"repository": "https://github.com/excalidraw/excalidraw", "repository": "https://github.com/excalidraw/excalidraw",

View file

@ -1,18 +1,18 @@
import { generateNKeysBetween } from "fractional-indexing"; import { generateNKeysBetween } from "fractional-indexing";
import { arrayToMap } from "@excalidraw/common";
import { mutateElement } from "@excalidraw/element/mutateElement"; import { mutateElement } from "@excalidraw/element/mutateElement";
import { getBoundTextElement } from "@excalidraw/element/textElement"; import { getBoundTextElement } from "@excalidraw/element/textElement";
import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; import { hasBoundTextElement } from "@excalidraw/element/typeChecks";
import { arrayToMap } from "@excalidraw/common";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
FractionalIndex, FractionalIndex,
OrderedExcalidrawElement, OrderedExcalidrawElement,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { InvalidFractionalIndexError } from "./errors"; import { InvalidFractionalIndexError } from "../../excalidraw/errors";
/** /**
* Envisioned relation between array order and fractional indices: * Envisioned relation between array order and fractional indices:

View file

@ -1,15 +1,14 @@
import { KEYS, arrayToMap } from "@excalidraw/common";
import { pointFrom } from "@excalidraw/math"; import { pointFrom } from "@excalidraw/math";
import React from "react";
import { actionWrapTextInContainer } from "../actions/actionBoundText"; import { actionWrapTextInContainer } from "@excalidraw/excalidraw/actions/actionBoundText";
import { getTransformHandles } from "../element/transformHandles"; import { getTransformHandles } from "@excalidraw/element/transformHandles";
import { Excalidraw, isLinearElement } from "../index"; import { Excalidraw, isLinearElement } from "@excalidraw/excalidraw";
import { KEYS } from "../keys";
import { arrayToMap } from "../utils";
import { API } from "./helpers/api"; import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import { UI, Pointer, Keyboard } from "./helpers/ui"; import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui";
import { fireEvent, render } from "./test-utils"; import { fireEvent, render } from "@excalidraw/excalidraw/tests/test-utils";
const { h } = window; const { h } = window;

View file

@ -1,18 +1,24 @@
/* eslint-disable no-lone-blocks */ /* eslint-disable no-lone-blocks */
import { generateKeyBetween } from "fractional-indexing"; import { generateKeyBetween } from "fractional-indexing";
import { deepCopyElement } from "../element/newElement"; import { arrayToMap } from "@excalidraw/common";
import { InvalidFractionalIndexError } from "../errors";
import { import {
syncInvalidIndices, syncInvalidIndices,
syncMovedIndices, syncMovedIndices,
validateFractionalIndices, validateFractionalIndices,
} from "../fractionalIndex"; } from "@excalidraw/element/fractionalIndex";
import { arrayToMap } from "../utils";
import { API } from "./helpers/api"; import { deepCopyElement } from "@excalidraw/element/newElement";
import type { ExcalidrawElement, FractionalIndex } from "../element/types"; import { InvalidFractionalIndexError } from "@excalidraw/excalidraw/errors";
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
import type {
ExcalidrawElement,
FractionalIndex,
} from "@excalidraw/element/types";
describe("sync invalid indices with array order", () => { describe("sync invalid indices with array order", () => {
describe("should NOT sync empty array", () => { describe("should NOT sync empty array", () => {

View file

@ -29,6 +29,8 @@ import {
import { mutateElement } from "@excalidraw/element/mutateElement"; import { mutateElement } from "@excalidraw/element/mutateElement";
import { measureText } from "@excalidraw/element/textMeasurements"; import { measureText } from "@excalidraw/element/textMeasurements";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawLinearElement, ExcalidrawLinearElement,
@ -36,7 +38,6 @@ import type {
ExcalidrawTextElement, ExcalidrawTextElement,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { syncMovedIndices } from "../fractionalIndex";
import { CaptureUpdateAction } from "../store"; import { CaptureUpdateAction } from "../store";
import { register } from "./register"; import { register } from "./register";

View file

@ -26,6 +26,8 @@ import {
isElementInGroup, isElementInGroup,
} from "@excalidraw/element/groups"; } from "@excalidraw/element/groups";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawTextElement, ExcalidrawTextElement,
@ -35,8 +37,6 @@ import type {
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { UngroupIcon, GroupIcon } from "../components/icons"; import { UngroupIcon, GroupIcon } from "../components/icons";
import { syncMovedIndices } from "../fractionalIndex";
import { t } from "../i18n"; import { t } from "../i18n";
import { isSomeElementSelected } from "../scene"; import { isSomeElementSelected } from "../scene";

View file

@ -31,6 +31,11 @@ import {
import { getNonDeletedGroupIds } from "@excalidraw/element/groups"; import { getNonDeletedGroupIds } from "@excalidraw/element/groups";
import {
orderByFractionalIndex,
syncMovedIndices,
} from "@excalidraw/element/fractionalIndex";
import type { BindableProp, BindingProp } from "@excalidraw/element/binding"; import type { BindableProp, BindingProp } from "@excalidraw/element/binding";
import type { ElementUpdate } from "@excalidraw/element/mutateElement"; import type { ElementUpdate } from "@excalidraw/element/mutateElement";
@ -46,7 +51,6 @@ import type {
SceneElementsMap, SceneElementsMap,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex";
import { getObservedAppState } from "./store"; import { getObservedAppState } from "./store";
import type { import type {

View file

@ -284,6 +284,11 @@ import {
selectGroupsForSelectedElements, selectGroupsForSelectedElements,
} from "@excalidraw/element/groups"; } from "@excalidraw/element/groups";
import {
syncInvalidIndices,
syncMovedIndices,
} from "@excalidraw/element/fractionalIndex";
import type { LocalPoint, Radians } from "@excalidraw/math"; import type { LocalPoint, Radians } from "@excalidraw/math";
import type { import type {
@ -447,7 +452,6 @@ import { LaserTrails } from "../laser-trails";
import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils"; import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils";
import { textWysiwyg } from "../wysiwyg/textWysiwyg"; import { textWysiwyg } from "../wysiwyg/textWysiwyg";
import { isOverScrollBars } from "../scene/scrollbars"; import { isOverScrollBars } from "../scene/scrollbars";
import { syncInvalidIndices, syncMovedIndices } from "../fractionalIndex";
import { isMaybeMermaidDefinition } from "../mermaid"; import { isMaybeMermaidDefinition } from "../mermaid";

View file

@ -2,13 +2,13 @@ import throttle from "lodash.throttle";
import { ENV, arrayToMap } from "@excalidraw/common"; import { ENV, arrayToMap } from "@excalidraw/common";
import type { OrderedExcalidrawElement } from "@excalidraw/element/types";
import { import {
orderByFractionalIndex, orderByFractionalIndex,
syncInvalidIndices, syncInvalidIndices,
validateFractionalIndices, validateFractionalIndices,
} from "../fractionalIndex"; } from "@excalidraw/element/fractionalIndex";
import type { OrderedExcalidrawElement } from "@excalidraw/element/types";
import type { AppState } from "../types"; import type { AppState } from "../types";
import type { MakeBrand } from "../utility-types"; import type { MakeBrand } from "../utility-types";

View file

@ -41,6 +41,8 @@ import {
isUsingAdaptiveRadius, isUsingAdaptiveRadius,
} from "@excalidraw/element/typeChecks"; } from "@excalidraw/element/typeChecks";
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import type { LocalPoint, Radians } from "@excalidraw/math"; import type { LocalPoint, Radians } from "@excalidraw/math";
import type { import type {
@ -62,7 +64,6 @@ import type {
import { getDefaultAppState } from "../appState"; import { getDefaultAppState } from "../appState";
import { getLineHeight } from "../fonts/FontMetadata"; import { getLineHeight } from "../fonts/FontMetadata";
import { syncInvalidIndices } from "../fractionalIndex";
import { import {
getNormalizedGridSize, getNormalizedGridSize,
getNormalizedGridStep, getNormalizedGridStep,

View file

@ -34,6 +34,8 @@ import {
} from "@excalidraw/element/textMeasurements"; } from "@excalidraw/element/textMeasurements";
import { isArrowElement } from "@excalidraw/element/typeChecks"; import { isArrowElement } from "@excalidraw/element/typeChecks";
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import type { ElementConstructorOpts } from "@excalidraw/element/newElement"; import type { ElementConstructorOpts } from "@excalidraw/element/newElement";
import type { import type {
@ -58,7 +60,6 @@ import type {
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { getLineHeight } from "../fonts/FontMetadata"; import { getLineHeight } from "../fonts/FontMetadata";
import { syncInvalidIndices } from "../fractionalIndex";
import type { MarkOptional } from "../utility-types"; import type { MarkOptional } from "../utility-types";

View file

@ -69,7 +69,6 @@
"canvas-roundrect-polyfill": "0.0.1", "canvas-roundrect-polyfill": "0.0.1",
"clsx": "1.1.1", "clsx": "1.1.1",
"cross-env": "7.0.3", "cross-env": "7.0.3",
"fractional-indexing": "3.2.0",
"fuzzy": "0.1.3", "fuzzy": "0.1.3",
"image-blob-reduce": "3.0.1", "image-blob-reduce": "3.0.1",
"jotai": "2.11.0", "jotai": "2.11.0",

View file

@ -11,6 +11,12 @@ import { isFrameLikeElement } from "@excalidraw/element/typeChecks";
import { getElementsInGroup } from "@excalidraw/element/groups"; import { getElementsInGroup } from "@excalidraw/element/groups";
import {
syncInvalidIndices,
syncMovedIndices,
validateFractionalIndices,
} from "@excalidraw/element/fractionalIndex";
import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
@ -24,12 +30,6 @@ import type {
Ordered, Ordered,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import {
syncInvalidIndices,
syncMovedIndices,
validateFractionalIndices,
} from "../fractionalIndex";
import { getSelectedElements } from "./selection"; import { getSelectedElements } from "./selection";
import type { AppState } from "../types"; import type { AppState } from "../types";

View file

@ -38,6 +38,8 @@ import {
getRootElements, getRootElements,
} from "@excalidraw/element/frame"; } from "@excalidraw/element/frame";
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import type { Bounds } from "@excalidraw/element/bounds"; import type { Bounds } from "@excalidraw/element/bounds";
import type { import type {
@ -53,7 +55,6 @@ import { base64ToString, decode, encode, stringToBase64 } from "../data/encode";
import { serializeAsJSON } from "../data/json"; import { serializeAsJSON } from "../data/json";
import { Fonts } from "../fonts"; import { Fonts } from "../fonts";
import { syncInvalidIndices } from "../fractionalIndex";
import { renderStaticScene } from "../renderer/staticScene"; import { renderStaticScene } from "../renderer/staticScene";
import { renderSceneToSvg } from "../renderer/staticSvgScene"; import { renderSceneToSvg } from "../renderer/staticSvgScene";

View file

@ -1,5 +1,6 @@
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { reconcileElements } from "../../data/reconcile"; import { reconcileElements } from "../../data/reconcile";
import { syncInvalidIndices } from "../../fractionalIndex";
import { randomInteger } from "../../random"; import { randomInteger } from "../../random";
import { cloneJSON } from "../../utils"; import { cloneJSON } from "../../utils";

View file

@ -4,12 +4,13 @@ import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common";
import { getElementsInGroup } from "@excalidraw/element/groups"; import { getElementsInGroup } from "@excalidraw/element/groups";
import { syncMovedIndices } from "@excalidraw/element/fractionalIndex";
import type { import type {
ExcalidrawElement, ExcalidrawElement,
ExcalidrawFrameLikeElement, ExcalidrawFrameLikeElement,
} from "@excalidraw/element/types"; } from "@excalidraw/element/types";
import { syncMovedIndices } from "./fractionalIndex";
import { getSelectedElements } from "./scene"; import { getSelectedElements } from "./scene";
import Scene from "./scene/Scene"; import Scene from "./scene/Scene";

View file

@ -8851,8 +8851,16 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: "string-width-cjs@npm:string-width@^4.2.0":
name string-width-cjs version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3" version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@ -8954,7 +8962,14 @@ stringify-object@^3.3.0:
is-obj "^1.0.1" is-obj "^1.0.1"
is-regexp "^1.0.0" is-regexp "^1.0.0"
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1, strip-ansi@^7.0.1: "strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"
strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1, strip-ansi@^7.0.1:
version "6.0.1" version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@ -10087,8 +10102,7 @@ workbox-window@7.3.0, workbox-window@^7.3.0:
"@types/trusted-types" "^2.0.2" "@types/trusted-types" "^2.0.2"
workbox-core "7.3.0" workbox-core "7.3.0"
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: "wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
name wrap-ansi-cjs
version "7.0.0" version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@ -10106,6 +10120,15 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0" string-width "^4.1.0"
strip-ansi "^6.0.0" strip-ansi "^6.0.0"
wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"
wrap-ansi@^8.1.0: wrap-ansi@^8.1.0:
version "8.1.0" version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"