diff --git a/excalidraw-app/tests/collab.test.tsx b/excalidraw-app/tests/collab.test.tsx index f6cd68fab..3572303f4 100644 --- a/excalidraw-app/tests/collab.test.tsx +++ b/excalidraw-app/tests/collab.test.tsx @@ -3,7 +3,7 @@ import { createRedoAction, createUndoAction, } 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 { act, render, waitFor } from "@excalidraw/excalidraw/tests/test-utils"; import { vi } from "vitest"; diff --git a/packages/element/package.json b/packages/element/package.json index 02d1ccf25..db510d2cc 100644 --- a/packages/element/package.json +++ b/packages/element/package.json @@ -47,7 +47,9 @@ "last 1 safari version" ] }, - "dependencies": {}, + "dependencies": { + "fractional-indexing": "3.2.0" + }, "devDependencies": {}, "bugs": "https://github.com/excalidraw/excalidraw/issues", "repository": "https://github.com/excalidraw/excalidraw", diff --git a/packages/excalidraw/fractionalIndex.ts b/packages/element/src/fractionalIndex.ts similarity index 99% rename from packages/excalidraw/fractionalIndex.ts rename to packages/element/src/fractionalIndex.ts index d45b53bc8..081368266 100644 --- a/packages/excalidraw/fractionalIndex.ts +++ b/packages/element/src/fractionalIndex.ts @@ -1,18 +1,18 @@ import { generateNKeysBetween } from "fractional-indexing"; +import { arrayToMap } from "@excalidraw/common"; + import { mutateElement } from "@excalidraw/element/mutateElement"; import { getBoundTextElement } from "@excalidraw/element/textElement"; import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; -import { arrayToMap } from "@excalidraw/common"; - import type { ExcalidrawElement, FractionalIndex, OrderedExcalidrawElement, } from "@excalidraw/element/types"; -import { InvalidFractionalIndexError } from "./errors"; +import { InvalidFractionalIndexError } from "../../excalidraw/errors"; /** * Envisioned relation between array order and fractional indices: diff --git a/packages/excalidraw/tests/binding.test.tsx b/packages/element/tests/binding.test.tsx similarity index 96% rename from packages/excalidraw/tests/binding.test.tsx rename to packages/element/tests/binding.test.tsx index 1c50062c1..57b88cb17 100644 --- a/packages/excalidraw/tests/binding.test.tsx +++ b/packages/element/tests/binding.test.tsx @@ -1,15 +1,14 @@ +import { KEYS, arrayToMap } from "@excalidraw/common"; + import { pointFrom } from "@excalidraw/math"; -import React from "react"; -import { actionWrapTextInContainer } from "../actions/actionBoundText"; -import { getTransformHandles } from "../element/transformHandles"; -import { Excalidraw, isLinearElement } from "../index"; -import { KEYS } from "../keys"; -import { arrayToMap } from "../utils"; +import { actionWrapTextInContainer } from "@excalidraw/excalidraw/actions/actionBoundText"; +import { getTransformHandles } from "@excalidraw/element/transformHandles"; +import { Excalidraw, isLinearElement } from "@excalidraw/excalidraw"; -import { API } from "./helpers/api"; -import { UI, Pointer, Keyboard } from "./helpers/ui"; -import { fireEvent, render } from "./test-utils"; +import { API } from "@excalidraw/excalidraw/tests/helpers/api"; +import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui"; +import { fireEvent, render } from "@excalidraw/excalidraw/tests/test-utils"; const { h } = window; diff --git a/packages/excalidraw/tests/fractionalIndex.test.ts b/packages/element/tests/fractionalIndex.test.ts similarity index 98% rename from packages/excalidraw/tests/fractionalIndex.test.ts rename to packages/element/tests/fractionalIndex.test.ts index dbd55bd92..a82f49479 100644 --- a/packages/excalidraw/tests/fractionalIndex.test.ts +++ b/packages/element/tests/fractionalIndex.test.ts @@ -1,18 +1,24 @@ /* eslint-disable no-lone-blocks */ import { generateKeyBetween } from "fractional-indexing"; -import { deepCopyElement } from "../element/newElement"; -import { InvalidFractionalIndexError } from "../errors"; +import { arrayToMap } from "@excalidraw/common"; + import { syncInvalidIndices, syncMovedIndices, validateFractionalIndices, -} from "../fractionalIndex"; -import { arrayToMap } from "../utils"; +} from "@excalidraw/element/fractionalIndex"; -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("should NOT sync empty array", () => { diff --git a/packages/excalidraw/actions/actionBoundText.tsx b/packages/excalidraw/actions/actionBoundText.tsx index 6a1fac903..a9625b9bb 100644 --- a/packages/excalidraw/actions/actionBoundText.tsx +++ b/packages/excalidraw/actions/actionBoundText.tsx @@ -29,6 +29,8 @@ import { import { mutateElement } from "@excalidraw/element/mutateElement"; import { measureText } from "@excalidraw/element/textMeasurements"; +import { syncMovedIndices } from "@excalidraw/element/fractionalIndex"; + import type { ExcalidrawElement, ExcalidrawLinearElement, @@ -36,7 +38,6 @@ import type { ExcalidrawTextElement, } from "@excalidraw/element/types"; -import { syncMovedIndices } from "../fractionalIndex"; import { CaptureUpdateAction } from "../store"; import { register } from "./register"; diff --git a/packages/excalidraw/actions/actionGroup.tsx b/packages/excalidraw/actions/actionGroup.tsx index 291f871c6..6b47ef969 100644 --- a/packages/excalidraw/actions/actionGroup.tsx +++ b/packages/excalidraw/actions/actionGroup.tsx @@ -26,6 +26,8 @@ import { isElementInGroup, } from "@excalidraw/element/groups"; +import { syncMovedIndices } from "@excalidraw/element/fractionalIndex"; + import type { ExcalidrawElement, ExcalidrawTextElement, @@ -35,8 +37,6 @@ import type { import { ToolButton } from "../components/ToolButton"; import { UngroupIcon, GroupIcon } from "../components/icons"; -import { syncMovedIndices } from "../fractionalIndex"; - import { t } from "../i18n"; import { isSomeElementSelected } from "../scene"; diff --git a/packages/excalidraw/change.ts b/packages/excalidraw/change.ts index 0cd9e5264..9028d237b 100644 --- a/packages/excalidraw/change.ts +++ b/packages/excalidraw/change.ts @@ -31,6 +31,11 @@ import { import { getNonDeletedGroupIds } from "@excalidraw/element/groups"; +import { + orderByFractionalIndex, + syncMovedIndices, +} from "@excalidraw/element/fractionalIndex"; + import type { BindableProp, BindingProp } from "@excalidraw/element/binding"; import type { ElementUpdate } from "@excalidraw/element/mutateElement"; @@ -46,7 +51,6 @@ import type { SceneElementsMap, } from "@excalidraw/element/types"; -import { orderByFractionalIndex, syncMovedIndices } from "./fractionalIndex"; import { getObservedAppState } from "./store"; import type { diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index dfb214426..5f4372a66 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -284,6 +284,11 @@ import { selectGroupsForSelectedElements, } from "@excalidraw/element/groups"; +import { + syncInvalidIndices, + syncMovedIndices, +} from "@excalidraw/element/fractionalIndex"; + import type { LocalPoint, Radians } from "@excalidraw/math"; import type { @@ -447,7 +452,6 @@ import { LaserTrails } from "../laser-trails"; import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils"; import { textWysiwyg } from "../wysiwyg/textWysiwyg"; import { isOverScrollBars } from "../scene/scrollbars"; -import { syncInvalidIndices, syncMovedIndices } from "../fractionalIndex"; import { isMaybeMermaidDefinition } from "../mermaid"; diff --git a/packages/excalidraw/data/reconcile.ts b/packages/excalidraw/data/reconcile.ts index 0a9e7d99f..fb27b2845 100644 --- a/packages/excalidraw/data/reconcile.ts +++ b/packages/excalidraw/data/reconcile.ts @@ -2,13 +2,13 @@ import throttle from "lodash.throttle"; import { ENV, arrayToMap } from "@excalidraw/common"; -import type { OrderedExcalidrawElement } from "@excalidraw/element/types"; - import { orderByFractionalIndex, syncInvalidIndices, validateFractionalIndices, -} from "../fractionalIndex"; +} from "@excalidraw/element/fractionalIndex"; + +import type { OrderedExcalidrawElement } from "@excalidraw/element/types"; import type { AppState } from "../types"; import type { MakeBrand } from "../utility-types"; diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts index db6556e5f..0fa02001a 100644 --- a/packages/excalidraw/data/restore.ts +++ b/packages/excalidraw/data/restore.ts @@ -41,6 +41,8 @@ import { isUsingAdaptiveRadius, } from "@excalidraw/element/typeChecks"; +import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; + import type { LocalPoint, Radians } from "@excalidraw/math"; import type { @@ -62,7 +64,6 @@ import type { import { getDefaultAppState } from "../appState"; import { getLineHeight } from "../fonts/FontMetadata"; -import { syncInvalidIndices } from "../fractionalIndex"; import { getNormalizedGridSize, getNormalizedGridStep, diff --git a/packages/excalidraw/data/transform.ts b/packages/excalidraw/data/transform.ts index f1079e33b..ee54732a6 100644 --- a/packages/excalidraw/data/transform.ts +++ b/packages/excalidraw/data/transform.ts @@ -34,6 +34,8 @@ import { } from "@excalidraw/element/textMeasurements"; import { isArrowElement } from "@excalidraw/element/typeChecks"; +import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; + import type { ElementConstructorOpts } from "@excalidraw/element/newElement"; import type { @@ -58,7 +60,6 @@ import type { } from "@excalidraw/element/types"; import { getLineHeight } from "../fonts/FontMetadata"; -import { syncInvalidIndices } from "../fractionalIndex"; import type { MarkOptional } from "../utility-types"; diff --git a/packages/excalidraw/package.json b/packages/excalidraw/package.json index 5acec7f6b..9570233c0 100644 --- a/packages/excalidraw/package.json +++ b/packages/excalidraw/package.json @@ -69,7 +69,6 @@ "canvas-roundrect-polyfill": "0.0.1", "clsx": "1.1.1", "cross-env": "7.0.3", - "fractional-indexing": "3.2.0", "fuzzy": "0.1.3", "image-blob-reduce": "3.0.1", "jotai": "2.11.0", diff --git a/packages/excalidraw/scene/Scene.ts b/packages/excalidraw/scene/Scene.ts index 3602879ab..5a325be08 100644 --- a/packages/excalidraw/scene/Scene.ts +++ b/packages/excalidraw/scene/Scene.ts @@ -11,6 +11,12 @@ import { isFrameLikeElement } from "@excalidraw/element/typeChecks"; import { getElementsInGroup } from "@excalidraw/element/groups"; +import { + syncInvalidIndices, + syncMovedIndices, + validateFractionalIndices, +} from "@excalidraw/element/fractionalIndex"; + import type { LinearElementEditor } from "@excalidraw/element/linearElementEditor"; import type { ExcalidrawElement, @@ -24,12 +30,6 @@ import type { Ordered, } from "@excalidraw/element/types"; -import { - syncInvalidIndices, - syncMovedIndices, - validateFractionalIndices, -} from "../fractionalIndex"; - import { getSelectedElements } from "./selection"; import type { AppState } from "../types"; diff --git a/packages/excalidraw/scene/export.ts b/packages/excalidraw/scene/export.ts index 79463ea86..14da66a8e 100644 --- a/packages/excalidraw/scene/export.ts +++ b/packages/excalidraw/scene/export.ts @@ -38,6 +38,8 @@ import { getRootElements, } from "@excalidraw/element/frame"; +import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; + import type { Bounds } from "@excalidraw/element/bounds"; import type { @@ -53,7 +55,6 @@ import { base64ToString, decode, encode, stringToBase64 } from "../data/encode"; import { serializeAsJSON } from "../data/json"; import { Fonts } from "../fonts"; -import { syncInvalidIndices } from "../fractionalIndex"; import { renderStaticScene } from "../renderer/staticScene"; import { renderSceneToSvg } from "../renderer/staticSvgScene"; diff --git a/packages/excalidraw/tests/data/reconcile.test.ts b/packages/excalidraw/tests/data/reconcile.test.ts index 35a33956a..fa509c582 100644 --- a/packages/excalidraw/tests/data/reconcile.test.ts +++ b/packages/excalidraw/tests/data/reconcile.test.ts @@ -1,5 +1,6 @@ +import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex"; + import { reconcileElements } from "../../data/reconcile"; -import { syncInvalidIndices } from "../../fractionalIndex"; import { randomInteger } from "../../random"; import { cloneJSON } from "../../utils"; diff --git a/packages/excalidraw/zindex.ts b/packages/excalidraw/zindex.ts index 2d19ffe27..72c3daf09 100644 --- a/packages/excalidraw/zindex.ts +++ b/packages/excalidraw/zindex.ts @@ -4,12 +4,13 @@ import { arrayToMap, findIndex, findLastIndex } from "@excalidraw/common"; import { getElementsInGroup } from "@excalidraw/element/groups"; +import { syncMovedIndices } from "@excalidraw/element/fractionalIndex"; + import type { ExcalidrawElement, ExcalidrawFrameLikeElement, } from "@excalidraw/element/types"; -import { syncMovedIndices } from "./fractionalIndex"; import { getSelectedElements } from "./scene"; import Scene from "./scene/Scene"; diff --git a/yarn.lock b/yarn.lock index 6651a9109..ccd0827fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" 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: - name string-width-cjs +"string-width-cjs@npm:string-width@^4.2.0": + 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" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -8954,7 +8962,14 @@ stringify-object@^3.3.0: is-obj "^1.0.1" 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" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -10087,8 +10102,7 @@ workbox-window@7.3.0, workbox-window@^7.3.0: "@types/trusted-types" "^2.0.2" workbox-core "7.3.0" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: - name wrap-ansi-cjs +"wrap-ansi-cjs@npm: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== @@ -10106,6 +10120,15 @@ wrap-ansi@^6.2.0: string-width "^4.1.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: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"