From 79021f4b6b0b14de6cd319ea2cd9b3ad82cef60a Mon Sep 17 00:00:00 2001 From: Marcel Mraz Date: Mon, 17 Mar 2025 20:04:21 +0100 Subject: [PATCH] Fix components --- packages/common/package.json | 123 +++++++++--------- packages/element/package.json | 111 ++++++++-------- packages/element/tests/textElement.test.ts | 2 +- packages/excalidraw/components/Actions.tsx | 41 +++--- packages/excalidraw/components/App.tsx | 2 +- .../components/ColorPicker/ColorInput.tsx | 4 +- .../components/ColorPicker/ColorPicker.tsx | 11 +- .../components/ColorPicker/Picker.tsx | 6 +- .../components/ColorPicker/TopPicks.tsx | 2 +- .../ColorPicker/colorPickerUtils.ts | 3 +- .../ColorPicker/keyboardNavHandlers.ts | 14 +- .../CommandPalette/CommandPalette.tsx | 19 +-- .../excalidraw/components/DarkModeToggle.tsx | 7 +- .../components/DefaultSidebar.test.tsx | 3 +- .../excalidraw/components/DefaultSidebar.tsx | 5 +- packages/excalidraw/components/Dialog.tsx | 4 +- .../components/ElementLinkDialog.tsx | 12 +- packages/excalidraw/components/EyeDropper.tsx | 9 +- .../excalidraw/components/FilledButton.tsx | 3 +- .../components/FontPicker/FontPicker.tsx | 7 +- .../components/FontPicker/FontPickerList.tsx | 6 +- .../FontPicker/FontPickerTrigger.tsx | 4 +- .../FontPicker/keyboardNavHandlers.ts | 6 +- packages/excalidraw/components/HelpDialog.tsx | 7 +- packages/excalidraw/components/HintViewer.tsx | 16 ++- packages/excalidraw/components/IconPicker.tsx | 3 +- .../components/ImageExportDialog.tsx | 17 ++- .../excalidraw/components/InitializeApp.tsx | 3 +- .../components/JSONExportDialog.tsx | 7 +- packages/excalidraw/components/LayerUI.tsx | 21 ++- .../excalidraw/components/LibraryMenu.tsx | 19 ++- .../components/LibraryMenuBrowseButton.tsx | 3 +- .../components/LibraryMenuHeaderContent.tsx | 3 +- .../components/LibraryMenuItems.tsx | 3 +- .../components/LibraryMenuSection.tsx | 3 +- .../excalidraw/components/LoadingMessage.tsx | 7 +- packages/excalidraw/components/MobileMenu.tsx | 6 +- packages/excalidraw/components/Modal.tsx | 3 +- .../components/PasteChartDialog.tsx | 3 +- packages/excalidraw/components/Popover.tsx | 3 +- .../excalidraw/components/ProjectName.tsx | 3 +- .../components/PropertiesPopover.tsx | 2 +- .../excalidraw/components/PublishLibrary.tsx | 5 +- packages/excalidraw/components/SearchMenu.tsx | 27 ++-- .../components/Sidebar/Sidebar.test.tsx | 3 +- .../excalidraw/components/Sidebar/Sidebar.tsx | 5 +- .../excalidraw/components/Stats/Angle.tsx | 11 +- .../excalidraw/components/Stats/Dimension.tsx | 13 +- .../excalidraw/components/Stats/DragInput.tsx | 10 +- .../excalidraw/components/Stats/FontSize.tsx | 18 +-- .../components/Stats/MultiAngle.tsx | 14 +- .../components/Stats/MultiDimension.tsx | 23 ++-- .../components/Stats/MultiFontSize.tsx | 20 +-- .../components/Stats/MultiPosition.tsx | 15 ++- .../excalidraw/components/Stats/Position.tsx | 9 +- .../excalidraw/components/Stats/index.tsx | 16 ++- .../components/Stats/stats.test.tsx | 20 +-- packages/excalidraw/components/Stats/utils.ts | 26 ++-- .../TTDDialog/MermaidToExcalidraw.tsx | 7 +- .../components/TTDDialog/TTDDialog.tsx | 7 +- .../components/TTDDialog/TTDDialogInput.tsx | 3 +- .../TTDDialog/TTDDialogSubmitShortcut.tsx | 2 +- .../components/TTDDialog/TTDDialogTabs.tsx | 3 +- .../excalidraw/components/TTDDialog/common.ts | 6 +- packages/excalidraw/components/ToolButton.tsx | 6 +- packages/excalidraw/components/UserList.tsx | 4 +- .../components/canvases/InteractiveCanvas.tsx | 17 ++- .../components/canvases/NewElementCanvas.tsx | 3 +- .../components/canvases/StaticCanvas.tsx | 10 +- .../dropdownMenu/DropdownMenu.test.tsx | 3 +- .../dropdownMenu/DropdownMenuContent.tsx | 3 +- .../dropdownMenu/DropdownMenuItem.tsx | 3 +- .../components/dropdownMenu/common.ts | 3 +- .../components/hyperlink/Hyperlink.tsx | 56 +++++--- .../components/hyperlink/helpers.ts | 16 ++- packages/excalidraw/components/icons.tsx | 4 +- .../components/main-menu/DefaultItems.tsx | 7 +- .../components/main-menu/MainMenu.tsx | 3 +- packages/tsconfig.base.json | 54 ++++---- tsconfig.json | 2 +- 80 files changed, 555 insertions(+), 438 deletions(-) diff --git a/packages/common/package.json b/packages/common/package.json index bab4e6949..5ef41450f 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,66 +1,65 @@ { - "name": "@excalidraw/common", - "version": "0.1.0", - "type": "module", - "types": "./dist/types/common/index.d.ts", - "main": "./dist/prod/index.js", - "module": "./dist/prod/index.js", - "exports": { - ".": { - "types": "./dist/types/common/index.d.ts", - "development": "./dist/dev/index.js", - "production": "./dist/prod/index.js", - "default": "./dist/prod/index.js" - }, - "./*": { - "types": "./../common/dist/types/common/*" - } + "name": "@excalidraw/common", + "version": "0.1.0", + "type": "module", + "types": "./dist/types/common/index.d.ts", + "main": "./dist/prod/index.js", + "module": "./dist/prod/index.js", + "exports": { + ".": { + "types": "./dist/types/common/index.d.ts", + "development": "./dist/dev/index.js", + "production": "./dist/prod/index.js", + "default": "./dist/prod/index.js" }, - "files": [ - "dist/*" - ], - "description": "Excalidraw common functions, constants, etc.", - "publishConfig": { - "access": "public" - }, - "license": "MIT", - "keywords": [ - "excalidraw", - "excalidraw-utils" - ], - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not ie <= 11", - "not op_mini all", - "not safari < 12", - "not kaios <= 2.5", - "not edge < 79", - "not chrome < 70", - "not and_uc < 13", - "not samsung < 10" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, - "dependencies": { - "es6-promise-pool": "2.5.0", - "nanoid": "3.3.3", - "open-color": "1.9.1", - "roughjs": "4.6.4" - }, - "devDependencies": { - "typescript": "4.9.4" - }, - "bugs": "https://github.com/excalidraw/excalidraw/issues", - "repository": "https://github.com/excalidraw/excalidraw", - "scripts": { - "gen:types": "rm -rf types && tsc", - "build:esm": "rm -rf dist && node ../../scripts/buildShared.js && yarn gen:types" + "./*": { + "types": "./../common/dist/types/common/*" } + }, + "files": [ + "dist/*" + ], + "description": "Excalidraw common functions, constants, etc.", + "publishConfig": { + "access": "public" + }, + "license": "MIT", + "keywords": [ + "excalidraw", + "excalidraw-utils" + ], + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all", + "not safari < 12", + "not kaios <= 2.5", + "not edge < 79", + "not chrome < 70", + "not and_uc < 13", + "not samsung < 10" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "dependencies": { + "es6-promise-pool": "2.5.0", + "nanoid": "3.3.3", + "open-color": "1.9.1", + "roughjs": "4.6.4" + }, + "devDependencies": { + "typescript": "4.9.4" + }, + "bugs": "https://github.com/excalidraw/excalidraw/issues", + "repository": "https://github.com/excalidraw/excalidraw", + "scripts": { + "gen:types": "rm -rf types && tsc", + "build:esm": "rm -rf dist && node ../../scripts/buildShared.js && yarn gen:types" } - \ No newline at end of file +} diff --git a/packages/element/package.json b/packages/element/package.json index 166ff3265..02d1ccf25 100644 --- a/packages/element/package.json +++ b/packages/element/package.json @@ -1,61 +1,58 @@ { - "name": "@excalidraw/element", - "version": "0.1.0", - "type": "module", - "types": "./dist/types/element/index.d.ts", - "main": "./dist/prod/index.js", - "module": "./dist/prod/index.js", - "exports": { - ".": { - "types": "./dist/types/element/index.d.ts", - "development": "./dist/dev/index.js", - "production": "./dist/prod/index.js", - "default": "./dist/prod/index.js" - }, - "./*": { - "types": "./../element/dist/types/element/*" - } + "name": "@excalidraw/element", + "version": "0.1.0", + "type": "module", + "types": "./dist/types/element/index.d.ts", + "main": "./dist/prod/index.js", + "module": "./dist/prod/index.js", + "exports": { + ".": { + "types": "./dist/types/element/index.d.ts", + "development": "./dist/dev/index.js", + "production": "./dist/prod/index.js", + "default": "./dist/prod/index.js" }, - "files": [ - "dist/*" - ], - "description": "Excalidraw elements-related logic", - "publishConfig": { - "access": "public" - }, - "license": "MIT", - "keywords": [ - "excalidraw", - "excalidraw-utils" - ], - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not ie <= 11", - "not op_mini all", - "not safari < 12", - "not kaios <= 2.5", - "not edge < 79", - "not chrome < 70", - "not and_uc < 13", - "not samsung < 10" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, - "dependencies": { - }, - "devDependencies": { - }, - "bugs": "https://github.com/excalidraw/excalidraw/issues", - "repository": "https://github.com/excalidraw/excalidraw", - "scripts": { - "gen:types": "rm -rf types && tsc", - "build:esm": "rm -rf dist && node ../../scripts/buildShared.js && yarn gen:types" + "./*": { + "types": "./../element/dist/types/element/*" } + }, + "files": [ + "dist/*" + ], + "description": "Excalidraw elements-related logic", + "publishConfig": { + "access": "public" + }, + "license": "MIT", + "keywords": [ + "excalidraw", + "excalidraw-utils" + ], + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all", + "not safari < 12", + "not kaios <= 2.5", + "not edge < 79", + "not chrome < 70", + "not and_uc < 13", + "not samsung < 10" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "dependencies": {}, + "devDependencies": {}, + "bugs": "https://github.com/excalidraw/excalidraw/issues", + "repository": "https://github.com/excalidraw/excalidraw", + "scripts": { + "gen:types": "rm -rf types && tsc", + "build:esm": "rm -rf dist && node ../../scripts/buildShared.js && yarn gen:types" } - \ No newline at end of file +} diff --git a/packages/element/tests/textElement.test.ts b/packages/element/tests/textElement.test.ts index 9ff485d24..65b9b0cf9 100644 --- a/packages/element/tests/textElement.test.ts +++ b/packages/element/tests/textElement.test.ts @@ -8,7 +8,7 @@ import { getContainerCoords, getBoundTextMaxWidth, getBoundTextMaxHeight, -a} from "../src/textElement"; +} from "../src/textElement"; import { detectLineHeight, getLineHeightInPx } from "../src/textMeasurements"; import type { ExcalidrawTextElementWithContainer } from "../src/types"; diff --git a/packages/excalidraw/components/Actions.tsx b/packages/excalidraw/components/Actions.tsx index c74c1ad85..53b1efb72 100644 --- a/packages/excalidraw/components/Actions.tsx +++ b/packages/excalidraw/components/Actions.tsx @@ -1,24 +1,39 @@ import clsx from "clsx"; import { useState } from "react"; -import { actionToggleZenMode } from "../actions"; +import { + CLASSES, + KEYS, + capitalizeString, + isTransparent, +} from "@excalidraw/common"; -import { KEYS } from "../keys"; -import { CLASSES } from "../constants"; -import { alignActionsPredicate } from "../actions/actionAlign"; -import { trackEvent } from "../analytics"; -import { useTunnels } from "../context/tunnels"; import { shouldAllowVerticalAlign, suppportsHorizontalAlign, -} from "../element/textElement"; +} from "@excalidraw/element/textElement"; + import { hasBoundTextElement, isElbowArrow, isImageElement, isLinearElement, isTextElement, -} from "../element/typeChecks"; +} from "@excalidraw/element/typeChecks"; + +import type { + ExcalidrawElement, + ExcalidrawElementType, + NonDeletedElementsMap, + NonDeletedSceneElementsMap, +} from "@excalidraw/element/types"; + +import { actionToggleZenMode } from "../actions"; + +import { alignActionsPredicate } from "../actions/actionAlign"; +import { trackEvent } from "../analytics"; +import { useTunnels } from "../context/tunnels"; + import { t } from "../i18n"; import { canChangeRoundness, @@ -29,8 +44,8 @@ import { hasStrokeWidth, } from "../scene"; import { hasStrokeColor, toolIsArrow } from "../scene/comparisons"; -import { SHAPES } from "../shapes"; -import { capitalizeString, isTransparent } from "../utils"; + +import { SHAPES } from "./shapes"; import "./Actions.scss"; @@ -48,12 +63,6 @@ import { MagicIcon, } from "./icons"; -import type { - ExcalidrawElement, - ExcalidrawElementType, - NonDeletedElementsMap, - NonDeletedSceneElementsMap, -} from "../element/types"; import type { AppClassProperties, AppProps, UIAppState, Zoom } from "../types"; import type { ActionManager } from "../actions/manager"; diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 4968542bc..5fd2ea030 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -193,7 +193,7 @@ import { getDateTime, isShallowEqual, arrayToMap, -} from "@excalidraw/common/utils"; +} from "@excalidraw/common"; import { createSrcDoc, diff --git a/packages/excalidraw/components/ColorPicker/ColorInput.tsx b/packages/excalidraw/components/ColorPicker/ColorInput.tsx index dc7d572a3..a3f6722eb 100644 --- a/packages/excalidraw/components/ColorPicker/ColorInput.tsx +++ b/packages/excalidraw/components/ColorPicker/ColorInput.tsx @@ -1,10 +1,10 @@ import clsx from "clsx"; import { useCallback, useEffect, useRef, useState } from "react"; +import { KEYS, getShortcutKey } from "@excalidraw/common"; + import { useAtom } from "../../editor-jotai"; import { t } from "../../i18n"; -import { KEYS } from "../../keys"; -import { getShortcutKey } from "../../utils"; import { useDevice } from "../App"; import { activeEyeDropperAtom } from "../EyeDropper"; import { eyeDropperIcon } from "../icons"; diff --git a/packages/excalidraw/components/ColorPicker/ColorPicker.tsx b/packages/excalidraw/components/ColorPicker/ColorPicker.tsx index 7f6ee8a85..34f6c6d12 100644 --- a/packages/excalidraw/components/ColorPicker/ColorPicker.tsx +++ b/packages/excalidraw/components/ColorPicker/ColorPicker.tsx @@ -2,10 +2,14 @@ import * as Popover from "@radix-ui/react-popover"; import clsx from "clsx"; import { useRef } from "react"; -import { COLOR_PALETTE } from "../../colors"; +import { COLOR_PALETTE, isTransparent } from "@excalidraw/common"; + +import type { ColorTuple, ColorPaletteCustom } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { useAtom } from "../../editor-jotai"; import { t } from "../../i18n"; -import { isTransparent } from "../../utils"; import { useExcalidrawContainer } from "../App"; import { ButtonSeparator } from "../ButtonSeparator"; import { activeEyeDropperAtom } from "../EyeDropper"; @@ -20,8 +24,7 @@ import { activeColorPickerSectionAtom } from "./colorPickerUtils"; import "./ColorPicker.scss"; import type { ColorPickerType } from "./colorPickerUtils"; -import type { ColorTuple, ColorPaletteCustom } from "../../colors"; -import type { ExcalidrawElement } from "../../element/types"; + import type { AppState } from "../../types"; const isValidColor = (color: string) => { diff --git a/packages/excalidraw/components/ColorPicker/Picker.tsx b/packages/excalidraw/components/ColorPicker/Picker.tsx index 9f311e9c1..122eb0069 100644 --- a/packages/excalidraw/components/ColorPicker/Picker.tsx +++ b/packages/excalidraw/components/ColorPicker/Picker.tsx @@ -1,10 +1,13 @@ import React, { useEffect, useState } from "react"; +import { EVENT } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX, DEFAULT_ELEMENT_STROKE_COLOR_INDEX, } from "../../colors"; -import { EVENT } from "../../constants"; import { useAtom } from "../../editor-jotai"; import { t } from "../../i18n"; import { KEYS } from "../../keys"; @@ -23,7 +26,6 @@ import { colorPickerKeyNavHandler } from "./keyboardNavHandlers"; import type { ColorPickerType } from "./colorPickerUtils"; import type { ColorPaletteCustom } from "../../colors"; -import type { ExcalidrawElement } from "../../element/types"; interface PickerProps { color: string; diff --git a/packages/excalidraw/components/ColorPicker/TopPicks.tsx b/packages/excalidraw/components/ColorPicker/TopPicks.tsx index 9bd8fdb9a..6d18a9587 100644 --- a/packages/excalidraw/components/ColorPicker/TopPicks.tsx +++ b/packages/excalidraw/components/ColorPicker/TopPicks.tsx @@ -4,7 +4,7 @@ import { DEFAULT_CANVAS_BACKGROUND_PICKS, DEFAULT_ELEMENT_BACKGROUND_PICKS, DEFAULT_ELEMENT_STROKE_PICKS, -} from "../../colors"; +} from "@excalidraw/common"; import type { ColorPickerType } from "./colorPickerUtils"; diff --git a/packages/excalidraw/components/ColorPicker/colorPickerUtils.ts b/packages/excalidraw/components/ColorPicker/colorPickerUtils.ts index bbb4e587d..42a16ac0b 100644 --- a/packages/excalidraw/components/ColorPicker/colorPickerUtils.ts +++ b/packages/excalidraw/components/ColorPicker/colorPickerUtils.ts @@ -1,8 +1,9 @@ +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { MAX_CUSTOM_COLORS_USED_IN_CANVAS } from "../../colors"; import { atom } from "../../editor-jotai"; import type { ColorPickerColor, ColorPaletteCustom } from "../../colors"; -import type { ExcalidrawElement } from "../../element/types"; export const getColorNameAndShadeFromColor = ({ palette, diff --git a/packages/excalidraw/components/ColorPicker/keyboardNavHandlers.ts b/packages/excalidraw/components/ColorPicker/keyboardNavHandlers.ts index c4e321700..287f850ca 100644 --- a/packages/excalidraw/components/ColorPicker/keyboardNavHandlers.ts +++ b/packages/excalidraw/components/ColorPicker/keyboardNavHandlers.ts @@ -1,5 +1,10 @@ -import { COLORS_PER_ROW, COLOR_PALETTE } from "../../colors"; -import { KEYS } from "../../keys"; +import { COLORS_PER_ROW, COLOR_PALETTE, KEYS } from "@excalidraw/common"; + +import type { + ColorPickerColor, + ColorPalette, + ColorPaletteCustom, +} from "@excalidraw/common"; import { colorPickerHotkeyBindings, @@ -7,11 +12,6 @@ import { } from "./colorPickerUtils"; import type { ActiveColorPickerSectionAtomType } from "./colorPickerUtils"; -import type { - ColorPickerColor, - ColorPalette, - ColorPaletteCustom, -} from "../../colors"; import type { ValueOf } from "../../utility-types"; const arrowHandler = ( diff --git a/packages/excalidraw/components/CommandPalette/CommandPalette.tsx b/packages/excalidraw/components/CommandPalette/CommandPalette.tsx index 7febb61c9..0d1442e29 100644 --- a/packages/excalidraw/components/CommandPalette/CommandPalette.tsx +++ b/packages/excalidraw/components/CommandPalette/CommandPalette.tsx @@ -2,6 +2,15 @@ import clsx from "clsx"; import fuzzy from "fuzzy"; import { useEffect, useRef, useState } from "react"; +import { + DEFAULT_SIDEBAR, + EVENT, + KEYS, + capitalizeString, + getShortcutKey, + isWritableElement, +} from "@excalidraw/common"; + import { actionClearCanvas, actionLink, @@ -13,12 +22,10 @@ import { } from "../../actions/actionElementLink"; import { getShortcutFromShortcutName } from "../../actions/shortcuts"; import { trackEvent } from "../../analytics"; -import { DEFAULT_SIDEBAR, EVENT } from "../../constants"; import { useUIAppState } from "../../context/ui-appState"; import { deburr } from "../../deburr"; import { atom, useAtom, editorJotaiStore } from "../../editor-jotai"; import { t } from "../../i18n"; -import { KEYS } from "../../keys"; import { useApp, useAppProps, @@ -42,13 +49,7 @@ import { LibraryIcon, } from "../icons"; -import { - capitalizeString, - getShortcutKey, - isWritableElement, -} from "../../utils"; - -import { SHAPES } from "../../shapes"; +import { SHAPES } from "../shapes"; import { canChangeBackgroundColor, canChangeStrokeColor } from "../Actions"; import { useStableCallback } from "../../hooks/useStableCallback"; import { activeConfirmDialogAtom } from "../ActiveConfirmDialog"; diff --git a/packages/excalidraw/components/DarkModeToggle.tsx b/packages/excalidraw/components/DarkModeToggle.tsx index f04712944..474181ba4 100644 --- a/packages/excalidraw/components/DarkModeToggle.tsx +++ b/packages/excalidraw/components/DarkModeToggle.tsx @@ -1,12 +1,13 @@ -import { THEME } from "../constants"; +import { THEME } from "@excalidraw/common"; + +import type { Theme } from "@excalidraw/element/types"; + import { t } from "../i18n"; import { ToolButton } from "./ToolButton"; import "./ToolIcon.scss"; -import type { Theme } from "../element/types"; - // We chose to use only explicit toggle and not a third option for system value, // but this could be added in the future. export const DarkModeToggle = (props: { diff --git a/packages/excalidraw/components/DefaultSidebar.test.tsx b/packages/excalidraw/components/DefaultSidebar.test.tsx index f8bc0dbbb..1b3f1cac9 100644 --- a/packages/excalidraw/components/DefaultSidebar.test.tsx +++ b/packages/excalidraw/components/DefaultSidebar.test.tsx @@ -1,6 +1,7 @@ import React from "react"; -import { DEFAULT_SIDEBAR } from "../constants"; +import { DEFAULT_SIDEBAR } from "@excalidraw/common"; + import { DefaultSidebar } from "../index"; import { fireEvent, diff --git a/packages/excalidraw/components/DefaultSidebar.tsx b/packages/excalidraw/components/DefaultSidebar.tsx index cd9683c60..c0eff5e3e 100644 --- a/packages/excalidraw/components/DefaultSidebar.tsx +++ b/packages/excalidraw/components/DefaultSidebar.tsx @@ -4,10 +4,11 @@ import { CANVAS_SEARCH_TAB, DEFAULT_SIDEBAR, LIBRARY_SIDEBAR_TAB, -} from "../constants"; + composeEventHandlers, +} from "@excalidraw/common"; + import { useTunnels } from "../context/tunnels"; import { useUIAppState } from "../context/ui-appState"; -import { composeEventHandlers } from "../utils"; import "../components/dropdownMenu/DropdownMenu.scss"; diff --git a/packages/excalidraw/components/Dialog.tsx b/packages/excalidraw/components/Dialog.tsx index cf6b1254a..00ae2be0c 100644 --- a/packages/excalidraw/components/Dialog.tsx +++ b/packages/excalidraw/components/Dialog.tsx @@ -1,11 +1,11 @@ import clsx from "clsx"; import React, { useEffect, useState } from "react"; +import { KEYS, queryFocusableElements } from "@excalidraw/common"; + import { useSetAtom } from "../editor-jotai"; import { useCallbackRefState } from "../hooks/useCallbackRefState"; import { t } from "../i18n"; -import { KEYS } from "../keys"; -import { queryFocusableElements } from "../utils"; import { useExcalidrawContainer, diff --git a/packages/excalidraw/components/ElementLinkDialog.tsx b/packages/excalidraw/components/ElementLinkDialog.tsx index 7cf329633..5a0b9107b 100644 --- a/packages/excalidraw/components/ElementLinkDialog.tsx +++ b/packages/excalidraw/components/ElementLinkDialog.tsx @@ -1,13 +1,16 @@ import { useCallback, useEffect, useState } from "react"; -import { normalizeLink } from "../data/url"; +import { normalizeLink, KEYS } from "@excalidraw/common"; + import { defaultGetElementLinkFromSelection, getLinkIdAndTypeFromSelection, -} from "../element/elementLink"; -import { mutateElement } from "../element/mutateElement"; +} from "@excalidraw/element/elementLink"; +import { mutateElement } from "@excalidraw/element/mutateElement"; + +import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; + import { t } from "../i18n"; -import { KEYS } from "../keys"; import { getSelectedElements } from "../scene"; import DialogActionButton from "./DialogActionButton"; @@ -17,7 +20,6 @@ import { TrashIcon } from "./icons"; import "./ElementLinkDialog.scss"; -import type { ElementsMap, ExcalidrawElement } from "../element/types"; import type { AppProps, AppState, UIAppState } from "../types"; const ElementLinkDialog = ({ diff --git a/packages/excalidraw/components/EyeDropper.tsx b/packages/excalidraw/components/EyeDropper.tsx index 8c4a73e32..f7f98123d 100644 --- a/packages/excalidraw/components/EyeDropper.tsx +++ b/packages/excalidraw/components/EyeDropper.tsx @@ -1,22 +1,21 @@ import { useEffect, useRef } from "react"; import { createPortal } from "react-dom"; -import { rgbToHex } from "../colors"; -import { EVENT } from "../constants"; +import { EVENT, KEYS, rgbToHex } from "@excalidraw/common"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { useUIAppState } from "../context/ui-appState"; import { atom } from "../editor-jotai"; import { useCreatePortalContainer } from "../hooks/useCreatePortalContainer"; import { useOutsideClick } from "../hooks/useOutsideClick"; import { useStable } from "../hooks/useStable"; -import { KEYS } from "../keys"; import { getSelectedElements } from "../scene"; import { useApp, useExcalidrawContainer, useExcalidrawElements } from "./App"; import "./EyeDropper.scss"; -import type { ExcalidrawElement } from "../element/types"; - import type { ColorPickerType } from "./ColorPicker/colorPickerUtils"; export type EyeDropperProperties = { diff --git a/packages/excalidraw/components/FilledButton.tsx b/packages/excalidraw/components/FilledButton.tsx index 4e5b3e3ba..53b30a046 100644 --- a/packages/excalidraw/components/FilledButton.tsx +++ b/packages/excalidraw/components/FilledButton.tsx @@ -1,8 +1,9 @@ import clsx from "clsx"; import React, { forwardRef, useState } from "react"; +import { isPromiseLike } from "@excalidraw/common"; + import { AbortError } from "../errors"; -import { isPromiseLike } from "../utils"; import Spinner from "./Spinner"; import { tablerCheckIcon } from "./icons"; diff --git a/packages/excalidraw/components/FontPicker/FontPicker.tsx b/packages/excalidraw/components/FontPicker/FontPicker.tsx index 4018ad243..546e1fa34 100644 --- a/packages/excalidraw/components/FontPicker/FontPicker.tsx +++ b/packages/excalidraw/components/FontPicker/FontPicker.tsx @@ -1,7 +1,10 @@ import * as Popover from "@radix-ui/react-popover"; import React, { useCallback, useMemo } from "react"; -import { FONT_FAMILY } from "../../constants"; +import { FONT_FAMILY } from "@excalidraw/common"; + +import type { FontFamilyValues } from "@excalidraw/element/types"; + import { t } from "../../i18n"; import { ButtonIconSelect } from "../ButtonIconSelect"; import { ButtonSeparator } from "../ButtonSeparator"; @@ -16,8 +19,6 @@ import { FontPickerTrigger } from "./FontPickerTrigger"; import "./FontPicker.scss"; -import type { FontFamilyValues } from "../../element/types"; - export const DEFAULT_FONTS = [ { value: FONT_FAMILY.Excalifont, diff --git a/packages/excalidraw/components/FontPicker/FontPickerList.tsx b/packages/excalidraw/components/FontPicker/FontPickerList.tsx index d93b08695..fe86da0e9 100644 --- a/packages/excalidraw/components/FontPicker/FontPickerList.tsx +++ b/packages/excalidraw/components/FontPicker/FontPickerList.tsx @@ -7,10 +7,12 @@ import React, { type KeyboardEventHandler, } from "react"; -import { type FontFamilyValues } from "../../element/types"; +import { type FontFamilyValues } from "@excalidraw/element/types"; + +import { arrayToList, debounce, getFontFamilyString } from "@excalidraw/common"; + import { Fonts } from "../../fonts"; import { t } from "../../i18n"; -import { arrayToList, debounce, getFontFamilyString } from "../../utils"; import { useApp, useAppProps, useExcalidrawContainer } from "../App"; import { PropertiesPopover } from "../PropertiesPopover"; import { QuickSearch } from "../QuickSearch"; diff --git a/packages/excalidraw/components/FontPicker/FontPickerTrigger.tsx b/packages/excalidraw/components/FontPicker/FontPickerTrigger.tsx index d83dda0fd..6f3cc638a 100644 --- a/packages/excalidraw/components/FontPicker/FontPickerTrigger.tsx +++ b/packages/excalidraw/components/FontPicker/FontPickerTrigger.tsx @@ -1,14 +1,14 @@ import * as Popover from "@radix-ui/react-popover"; import { useMemo } from "react"; +import type { FontFamilyValues } from "@excalidraw/element/types"; + import { t } from "../../i18n"; import { ButtonIcon } from "../ButtonIcon"; import { TextIcon } from "../icons"; import { isDefaultFont } from "./FontPicker"; -import type { FontFamilyValues } from "../../element/types"; - interface FontPickerTriggerProps { selectedFontFamily: FontFamilyValues | null; } diff --git a/packages/excalidraw/components/FontPicker/keyboardNavHandlers.ts b/packages/excalidraw/components/FontPicker/keyboardNavHandlers.ts index b0ecdf371..16ffa7c45 100644 --- a/packages/excalidraw/components/FontPicker/keyboardNavHandlers.ts +++ b/packages/excalidraw/components/FontPicker/keyboardNavHandlers.ts @@ -1,9 +1,9 @@ -import { KEYS } from "../../keys"; +import { KEYS } from "@excalidraw/common"; + +import type { Node } from "@excalidraw/common"; import { type FontDescriptor } from "./FontPickerList"; -import type { Node } from "../../utils"; - interface FontPickerKeyNavHandlerProps { event: React.KeyboardEvent; inputRef: React.RefObject; diff --git a/packages/excalidraw/components/HelpDialog.tsx b/packages/excalidraw/components/HelpDialog.tsx index 19ecaa57e..60fc40372 100644 --- a/packages/excalidraw/components/HelpDialog.tsx +++ b/packages/excalidraw/components/HelpDialog.tsx @@ -1,11 +1,12 @@ import React from "react"; +import { isDarwin, isFirefox, isWindows } from "@excalidraw/common"; + +import { KEYS, getShortcutKey } from "@excalidraw/common"; + import { getShortcutFromShortcutName } from "../actions/shortcuts"; import { probablySupportsClipboardBlob } from "../clipboard"; -import { isDarwin, isFirefox, isWindows } from "../constants"; import { t } from "../i18n"; -import { KEYS } from "../keys"; -import { getShortcutKey } from "../utils"; import { Dialog } from "./Dialog"; import { ExternalLinkIcon, GithubIcon, youtubeIcon } from "./icons"; diff --git a/packages/excalidraw/components/HintViewer.tsx b/packages/excalidraw/components/HintViewer.tsx index c285e361b..6eb1a2186 100644 --- a/packages/excalidraw/components/HintViewer.tsx +++ b/packages/excalidraw/components/HintViewer.tsx @@ -1,18 +1,20 @@ -import { isEraserActive } from "../appState"; +import { CANVAS_SEARCH_TAB, DEFAULT_SIDEBAR } from "@excalidraw/common"; + import { isFlowchartNodeElement, isImageElement, isLinearElement, isTextBindableContainer, isTextElement, -} from "../element/typeChecks"; +} from "@excalidraw/element/typeChecks"; + +import { getShortcutKey } from "@excalidraw/common"; + +import { isNodeInFlowchart } from "@excalidraw/element/flowchart"; + import { t } from "../i18n"; - -import { getShortcutKey } from "../utils"; - -import { isNodeInFlowchart } from "../element/flowchart"; +import { isEraserActive } from "../appState"; import { isGridModeEnabled } from "../snapping"; -import { CANVAS_SEARCH_TAB, DEFAULT_SIDEBAR } from "../constants"; import "./HintViewer.scss"; diff --git a/packages/excalidraw/components/IconPicker.tsx b/packages/excalidraw/components/IconPicker.tsx index b91d37c23..5630ae8d7 100644 --- a/packages/excalidraw/components/IconPicker.tsx +++ b/packages/excalidraw/components/IconPicker.tsx @@ -2,9 +2,10 @@ import * as Popover from "@radix-ui/react-popover"; import clsx from "clsx"; import React, { useEffect } from "react"; +import { isArrowKey, KEYS } from "@excalidraw/common"; + import { atom, useAtom } from "../editor-jotai"; import { getLanguage, t } from "../i18n"; -import { isArrowKey, KEYS } from "../keys"; import Collapsible from "./Stats/Collapsible"; import { useDevice } from "./App"; diff --git a/packages/excalidraw/components/ImageExportDialog.tsx b/packages/excalidraw/components/ImageExportDialog.tsx index 0d19f5b5d..984df67d5 100644 --- a/packages/excalidraw/components/ImageExportDialog.tsx +++ b/packages/excalidraw/components/ImageExportDialog.tsx @@ -1,6 +1,15 @@ import { exportToCanvas } from "@excalidraw/utils/export"; import React, { useEffect, useRef, useState } from "react"; +import { + DEFAULT_EXPORT_PADDING, + EXPORT_IMAGE_TYPES, + isFirefox, + EXPORT_SCALES, +} from "@excalidraw/common"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { actionExportWithDarkMode, actionChangeExportBackground, @@ -9,12 +18,6 @@ import { actionChangeProjectName, } from "../actions/actionExport"; import { probablySupportsClipboardBlob } from "../clipboard"; -import { - DEFAULT_EXPORT_PADDING, - EXPORT_IMAGE_TYPES, - isFirefox, - EXPORT_SCALES, -} from "../constants"; import { prepareElementsForExport } from "../data"; import { canvasToBlob } from "../data/blob"; import { nativeFileSystemSupported } from "../data/filesystem"; @@ -34,7 +37,7 @@ import { FilledButton } from "./FilledButton"; import "./ImageExportDialog.scss"; import type { ActionManager } from "../actions/manager"; -import type { NonDeletedExcalidrawElement } from "../element/types"; + import type { AppClassProperties, BinaryFiles, UIAppState } from "../types"; const supportsContextFilters = diff --git a/packages/excalidraw/components/InitializeApp.tsx b/packages/excalidraw/components/InitializeApp.tsx index efc83a55b..1e5dda6dc 100644 --- a/packages/excalidraw/components/InitializeApp.tsx +++ b/packages/excalidraw/components/InitializeApp.tsx @@ -1,10 +1,11 @@ import React, { useEffect, useState } from "react"; +import type { Theme } from "@excalidraw/element/types"; + import { defaultLang, languages, setLanguage } from "../i18n"; import { LoadingMessage } from "./LoadingMessage"; -import type { Theme } from "../element/types"; import type { Language } from "../i18n"; interface Props { diff --git a/packages/excalidraw/components/JSONExportDialog.tsx b/packages/excalidraw/components/JSONExportDialog.tsx index ae203d3e4..4dfedc692 100644 --- a/packages/excalidraw/components/JSONExportDialog.tsx +++ b/packages/excalidraw/components/JSONExportDialog.tsx @@ -1,11 +1,14 @@ import React from "react"; +import { getFrame } from "@excalidraw/common"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { actionSaveFileToDisk } from "../actions/actionExport"; import { trackEvent } from "../analytics"; import { nativeFileSystemSupported } from "../data/filesystem"; import { t } from "../i18n"; -import { getFrame } from "../utils"; import { Card } from "./Card"; import { Dialog } from "./Dialog"; @@ -15,7 +18,7 @@ import { exportToFileIcon, LinkIcon } from "./icons"; import "./ExportDialog.scss"; import type { ActionManager } from "../actions/manager"; -import type { NonDeletedExcalidrawElement } from "../element/types"; + import type { ExportOpts, BinaryFiles, UIAppState } from "../types"; export type ExportCB = ( diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsx index 83ac7ae9c..e08956c08 100644 --- a/packages/excalidraw/components/LayerUI.tsx +++ b/packages/excalidraw/components/LayerUI.tsx @@ -1,20 +1,31 @@ import clsx from "clsx"; import React from "react"; -import { mutateElement } from "../element/mutateElement"; +import { + CLASSES, + DEFAULT_SIDEBAR, + TOOL_TYPE, + capitalizeString, + isShallowEqual, +} from "@excalidraw/common"; + +import { mutateElement } from "@excalidraw/element/mutateElement"; + +import { showSelectedShapeActions } from "@excalidraw/element"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { ShapeCache } from "../scene/ShapeCache"; import Scene from "../scene/Scene"; import { actionToggleStats } from "../actions"; import { trackEvent } from "../analytics"; import { isHandToolActive } from "../appState"; -import { CLASSES, DEFAULT_SIDEBAR, TOOL_TYPE } from "../constants"; import { TunnelsContext, useInitializeTunnels } from "../context/tunnels"; import { UIAppStateContext } from "../context/ui-appState"; import { useAtom, useAtomValue } from "../editor-jotai"; -import { showSelectedShapeActions } from "../element"; + import { t } from "../i18n"; import { calculateScrollCenter } from "../scene"; -import { capitalizeString, isShallowEqual } from "../utils"; import { SelectedShapeActions, ShapesSwitcher } from "./Actions"; import { LoadingMessage } from "./LoadingMessage"; @@ -51,7 +62,7 @@ import "./LayerUI.scss"; import "./Toolbar.scss"; import type { ActionManager } from "../actions/manager"; -import type { NonDeletedExcalidrawElement } from "../element/types"; + import type { Language } from "../i18n"; import type { AppProps, diff --git a/packages/excalidraw/components/LibraryMenu.tsx b/packages/excalidraw/components/LibraryMenu.tsx index 03c476e47..62bd235c2 100644 --- a/packages/excalidraw/components/LibraryMenu.tsx +++ b/packages/excalidraw/components/LibraryMenu.tsx @@ -7,8 +7,18 @@ import React, { useRef, } from "react"; +import { + LIBRARY_DISABLED_TYPES, + randomId, + isShallowEqual, +} from "@excalidraw/common"; + +import type { + ExcalidrawElement, + NonDeletedExcalidrawElement, +} from "@excalidraw/element/types"; + import { trackEvent } from "../analytics"; -import { LIBRARY_DISABLED_TYPES } from "../constants"; import { useUIAppState } from "../context/ui-appState"; import { distributeLibraryItemsOnSquareGrid, @@ -16,9 +26,8 @@ import { } from "../data/library"; import { atom, useAtom } from "../editor-jotai"; import { t } from "../i18n"; -import { randomId } from "../random"; + import { getSelectedElements } from "../scene"; -import { isShallowEqual } from "../utils"; import { useApp, @@ -32,10 +41,6 @@ import Spinner from "./Spinner"; import "./LibraryMenu.scss"; -import type { - ExcalidrawElement, - NonDeletedExcalidrawElement, -} from "../element/types"; import type { LibraryItems, LibraryItem, diff --git a/packages/excalidraw/components/LibraryMenuBrowseButton.tsx b/packages/excalidraw/components/LibraryMenuBrowseButton.tsx index 2b2623ed1..86bd4e2ad 100644 --- a/packages/excalidraw/components/LibraryMenuBrowseButton.tsx +++ b/packages/excalidraw/components/LibraryMenuBrowseButton.tsx @@ -1,4 +1,5 @@ -import { VERSIONS } from "../constants"; +import { VERSIONS } from "@excalidraw/common"; + import { t } from "../i18n"; import type { ExcalidrawProps, UIAppState } from "../types"; diff --git a/packages/excalidraw/components/LibraryMenuHeaderContent.tsx b/packages/excalidraw/components/LibraryMenuHeaderContent.tsx index cc6c942ae..5b003effa 100644 --- a/packages/excalidraw/components/LibraryMenuHeaderContent.tsx +++ b/packages/excalidraw/components/LibraryMenuHeaderContent.tsx @@ -1,6 +1,8 @@ import clsx from "clsx"; import { useCallback, useState } from "react"; +import { muteFSAbortError } from "@excalidraw/common"; + import { useUIAppState } from "../context/ui-appState"; import { fileOpen } from "../data/filesystem"; import { saveLibraryAsJSON } from "../data/json"; @@ -8,7 +10,6 @@ import { libraryItemsAtom } from "../data/library"; import { useAtom } from "../editor-jotai"; import { useLibraryCache } from "../hooks/useLibraryItemSvg"; import { t } from "../i18n"; -import { muteFSAbortError } from "../utils"; import { useApp, useExcalidrawSetAppState } from "./App"; import ConfirmDialog from "./ConfirmDialog"; diff --git a/packages/excalidraw/components/LibraryMenuItems.tsx b/packages/excalidraw/components/LibraryMenuItems.tsx index af5b9d3e6..9b6c0d054 100644 --- a/packages/excalidraw/components/LibraryMenuItems.tsx +++ b/packages/excalidraw/components/LibraryMenuItems.tsx @@ -6,7 +6,8 @@ import React, { useState, } from "react"; -import { MIME_TYPES } from "../constants"; +import { MIME_TYPES } from "@excalidraw/common"; + import { serializeLibraryAsJSON } from "../data/json"; import { duplicateElements } from "../element/newElement"; import { useLibraryCache } from "../hooks/useLibraryItemSvg"; diff --git a/packages/excalidraw/components/LibraryMenuSection.tsx b/packages/excalidraw/components/LibraryMenuSection.tsx index 5f7de2b09..d98b413fb 100644 --- a/packages/excalidraw/components/LibraryMenuSection.tsx +++ b/packages/excalidraw/components/LibraryMenuSection.tsx @@ -1,10 +1,11 @@ import React, { memo, useEffect, useState } from "react"; +import type { ExcalidrawElement, NonDeleted } from "@excalidraw/element/types"; + import { useTransition } from "../hooks/useTransition"; import { EmptyLibraryUnit, LibraryUnit } from "./LibraryUnit"; -import type { ExcalidrawElement, NonDeleted } from "../element/types"; import type { SvgCache } from "../hooks/useLibraryItemSvg"; import type { LibraryItem } from "../types"; import type { ReactNode } from "react"; diff --git a/packages/excalidraw/components/LoadingMessage.tsx b/packages/excalidraw/components/LoadingMessage.tsx index bdcc5a341..c971b37ee 100644 --- a/packages/excalidraw/components/LoadingMessage.tsx +++ b/packages/excalidraw/components/LoadingMessage.tsx @@ -1,13 +1,14 @@ import clsx from "clsx"; import { useState, useEffect } from "react"; -import { THEME } from "../constants"; +import { THEME } from "@excalidraw/common"; + +import type { Theme } from "@excalidraw/element/types"; + import { t } from "../i18n"; import Spinner from "./Spinner"; -import type { Theme } from "../element/types"; - export const LoadingMessage: React.FC<{ delay?: number; theme?: Theme }> = ({ delay, theme, diff --git a/packages/excalidraw/components/MobileMenu.tsx b/packages/excalidraw/components/MobileMenu.tsx index 08a20174c..454c0f64e 100644 --- a/packages/excalidraw/components/MobileMenu.tsx +++ b/packages/excalidraw/components/MobileMenu.tsx @@ -1,8 +1,11 @@ import React from "react"; +import { showSelectedShapeActions } from "@excalidraw/element"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { isHandToolActive } from "../appState"; import { useTunnels } from "../context/tunnels"; -import { showSelectedShapeActions } from "../element"; import { t } from "../i18n"; import { calculateScrollCenter } from "../scene"; import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars"; @@ -18,7 +21,6 @@ import { Section } from "./Section"; import Stack from "./Stack"; import type { ActionManager } from "../actions/manager"; -import type { NonDeletedExcalidrawElement } from "../element/types"; import type { AppClassProperties, AppProps, diff --git a/packages/excalidraw/components/Modal.tsx b/packages/excalidraw/components/Modal.tsx index a5ade9efa..32f42986f 100644 --- a/packages/excalidraw/components/Modal.tsx +++ b/packages/excalidraw/components/Modal.tsx @@ -2,8 +2,9 @@ import clsx from "clsx"; import { useRef } from "react"; import { createPortal } from "react-dom"; +import { KEYS } from "@excalidraw/common"; + import { useCreatePortalContainer } from "../hooks/useCreatePortalContainer"; -import { KEYS } from "../keys"; import "./Modal.scss"; diff --git a/packages/excalidraw/components/PasteChartDialog.tsx b/packages/excalidraw/components/PasteChartDialog.tsx index 58bd5a385..2566017ac 100644 --- a/packages/excalidraw/components/PasteChartDialog.tsx +++ b/packages/excalidraw/components/PasteChartDialog.tsx @@ -1,6 +1,8 @@ import oc from "open-color"; import React, { useLayoutEffect, useRef, useState } from "react"; +import type { ChartType } from "@excalidraw/element/types"; + import { trackEvent } from "../analytics"; import { renderSpreadsheet } from "../charts"; import { t } from "../i18n"; @@ -12,7 +14,6 @@ import { Dialog } from "./Dialog"; import "./PasteChartDialog.scss"; import type { ChartElements, Spreadsheet } from "../charts"; -import type { ChartType } from "../element/types"; import type { UIAppState } from "../types"; type OnInsertChart = (chartType: ChartType, elements: ChartElements) => void; diff --git a/packages/excalidraw/components/Popover.tsx b/packages/excalidraw/components/Popover.tsx index 2bd72b20b..4864b37d1 100644 --- a/packages/excalidraw/components/Popover.tsx +++ b/packages/excalidraw/components/Popover.tsx @@ -1,8 +1,7 @@ import React, { useLayoutEffect, useRef, useEffect } from "react"; import { unstable_batchedUpdates } from "react-dom"; -import { KEYS } from "../keys"; -import { queryFocusableElements } from "../utils"; +import { KEYS, queryFocusableElements } from "@excalidraw/common"; import "./Popover.scss"; diff --git a/packages/excalidraw/components/ProjectName.tsx b/packages/excalidraw/components/ProjectName.tsx index 0d60ddd66..ad50c7fd5 100644 --- a/packages/excalidraw/components/ProjectName.tsx +++ b/packages/excalidraw/components/ProjectName.tsx @@ -1,7 +1,6 @@ import React, { useState } from "react"; -import { focusNearestParent } from "../utils"; -import { KEYS } from "../keys"; +import { focusNearestParent, KEYS } from "@excalidraw/common"; import { useExcalidrawContainer } from "./App"; diff --git a/packages/excalidraw/components/PropertiesPopover.tsx b/packages/excalidraw/components/PropertiesPopover.tsx index a30f1374d..d8372ea27 100644 --- a/packages/excalidraw/components/PropertiesPopover.tsx +++ b/packages/excalidraw/components/PropertiesPopover.tsx @@ -2,7 +2,7 @@ import * as Popover from "@radix-ui/react-popover"; import clsx from "clsx"; import React, { type ReactNode } from "react"; -import { isInteractive } from "../utils"; +import { isInteractive } from "@excalidraw/common"; import { useDevice } from "./App"; import { Island } from "./Island"; diff --git a/packages/excalidraw/components/PublishLibrary.tsx b/packages/excalidraw/components/PublishLibrary.tsx index 8a7188b63..c1db91296 100644 --- a/packages/excalidraw/components/PublishLibrary.tsx +++ b/packages/excalidraw/components/PublishLibrary.tsx @@ -8,11 +8,12 @@ import { EXPORT_SOURCE, MIME_TYPES, VERSIONS, -} from "../constants"; + chunk, +} from "@excalidraw/common"; + import { EditorLocalStorage } from "../data/EditorLocalStorage"; import { canvasToBlob, resizeImageFile } from "../data/blob"; import { t } from "../i18n"; -import { chunk } from "../utils"; import { Dialog } from "./Dialog"; import DialogActionButton from "./DialogActionButton"; diff --git a/packages/excalidraw/components/SearchMenu.tsx b/packages/excalidraw/components/SearchMenu.tsx index 70d3f4f27..b9fab72c5 100644 --- a/packages/excalidraw/components/SearchMenu.tsx +++ b/packages/excalidraw/components/SearchMenu.tsx @@ -3,17 +3,27 @@ import clsx from "clsx"; import debounce from "lodash.debounce"; import { Fragment, memo, useEffect, useRef, useState } from "react"; -import { CLASSES, EVENT } from "../constants"; -import { atom, useAtom } from "../editor-jotai"; -import { isTextElement, newTextElement } from "../element"; -import { isElementCompletelyInViewport } from "../element/sizeHelpers"; +import { CLASSES, EVENT } from "@excalidraw/common"; + +import { isTextElement, newTextElement } from "@excalidraw/element"; + +import { isElementCompletelyInViewport } from "@excalidraw/element/sizeHelpers"; + +import { measureText } from "@excalidraw/element/textMeasurements"; + +import { + KEYS, + randomInteger, + addEventListener, + getFontString, +} from "@excalidraw/common"; + +import type { ExcalidrawTextElement } from "@excalidraw/element/types"; + +import { atom, useAtom } from "../editor-jotai"; -import { measureText } from "../element/textMeasurements"; import { useStable } from "../hooks/useStable"; import { t } from "../i18n"; -import { KEYS } from "../keys"; -import { randomInteger } from "../random"; -import { addEventListener, getFontString } from "../utils"; import { useApp, useExcalidrawSetAppState } from "./App"; import { Button } from "./Button"; @@ -22,7 +32,6 @@ import { collapseDownIcon, upIcon, searchIcon } from "./icons"; import "./SearchMenu.scss"; -import type { ExcalidrawTextElement } from "../element/types"; import type { AppClassProperties } from "../types"; const searchQueryAtom = atom(""); diff --git a/packages/excalidraw/components/Sidebar/Sidebar.test.tsx b/packages/excalidraw/components/Sidebar/Sidebar.test.tsx index 39a1cbc63..dd52fdb11 100644 --- a/packages/excalidraw/components/Sidebar/Sidebar.test.tsx +++ b/packages/excalidraw/components/Sidebar/Sidebar.test.tsx @@ -1,7 +1,8 @@ import React from "react"; import { vi } from "vitest"; -import { DEFAULT_SIDEBAR } from "../../constants"; +import { DEFAULT_SIDEBAR } from "@excalidraw/common"; + import { Excalidraw, Sidebar } from "../../index"; import { act, diff --git a/packages/excalidraw/components/Sidebar/Sidebar.tsx b/packages/excalidraw/components/Sidebar/Sidebar.tsx index 8a008fd9f..af94d78c7 100644 --- a/packages/excalidraw/components/Sidebar/Sidebar.tsx +++ b/packages/excalidraw/components/Sidebar/Sidebar.tsx @@ -9,12 +9,11 @@ import React, { useCallback, } from "react"; -import { EVENT } from "../../constants"; +import { EVENT, KEYS, updateObject } from "@excalidraw/common"; + import { useUIAppState } from "../../context/ui-appState"; import { atom, useSetAtom } from "../../editor-jotai"; import { useOutsideClick } from "../../hooks/useOutsideClick"; -import { KEYS } from "../../keys"; -import { updateObject } from "../../utils"; import { useDevice, useExcalidrawSetAppState } from "../App"; import { Island } from "../Island"; diff --git a/packages/excalidraw/components/Stats/Angle.tsx b/packages/excalidraw/components/Stats/Angle.tsx index 10c76d519..67693551f 100644 --- a/packages/excalidraw/components/Stats/Angle.tsx +++ b/packages/excalidraw/components/Stats/Angle.tsx @@ -1,17 +1,20 @@ import { degreesToRadians, radiansToDegrees } from "@excalidraw/math"; +import { mutateElement } from "@excalidraw/element/mutateElement"; + +import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { isArrowElement, isElbowArrow } from "@excalidraw/element/typeChecks"; + import type { Degrees } from "@excalidraw/math"; -import { mutateElement } from "../../element/mutateElement"; -import { getBoundTextElement } from "../../element/textElement"; -import { isArrowElement, isElbowArrow } from "../../element/typeChecks"; +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { angleIcon } from "../icons"; import DragInput from "./DragInput"; import { getStepSizedValue, isPropertyEditable, updateBindings } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; -import type { ExcalidrawElement } from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/Dimension.tsx b/packages/excalidraw/components/Stats/Dimension.tsx index f58c06acc..142abc407 100644 --- a/packages/excalidraw/components/Stats/Dimension.tsx +++ b/packages/excalidraw/components/Stats/Dimension.tsx @@ -1,19 +1,20 @@ import { clamp, round } from "@excalidraw/math"; -import { MIN_WIDTH_OR_HEIGHT } from "../../constants"; +import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common"; import { MINIMAL_CROP_SIZE, getUncroppedWidthAndHeight, -} from "../../element/cropElement"; -import { mutateElement } from "../../element/mutateElement"; -import { resizeSingleElement } from "../../element/resizeElements"; -import { isImageElement } from "../../element/typeChecks"; +} from "@excalidraw/element/cropElement"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { resizeSingleElement } from "@excalidraw/element/resizeElements"; +import { isImageElement } from "@excalidraw/element/typeChecks"; + +import type { ExcalidrawElement } from "@excalidraw/element/types"; import DragInput from "./DragInput"; import { getStepSizedValue, isPropertyEditable } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; -import type { ExcalidrawElement } from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/DragInput.tsx b/packages/excalidraw/components/Stats/DragInput.tsx index fbea33e55..d533bb957 100644 --- a/packages/excalidraw/components/Stats/DragInput.tsx +++ b/packages/excalidraw/components/Stats/DragInput.tsx @@ -1,11 +1,12 @@ import clsx from "clsx"; import { useEffect, useRef, useState } from "react"; -import { EVENT } from "../../constants"; -import { deepCopyElement } from "../../element/newElement"; -import { KEYS } from "../../keys"; +import { EVENT, KEYS, cloneJSON } from "@excalidraw/common"; +import { deepCopyElement } from "@excalidraw/element/newElement"; + +import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; + import { CaptureUpdateAction } from "../../store"; -import { cloneJSON } from "../../utils"; import { useApp } from "../App"; import { InlineIcon } from "../InlineIcon"; @@ -14,7 +15,6 @@ import { SMALLEST_DELTA } from "./utils"; import "./DragInput.scss"; import type { StatsInputProperty } from "./utils"; -import type { ElementsMap, ExcalidrawElement } from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/FontSize.tsx b/packages/excalidraw/components/Stats/FontSize.tsx index 4fbdab833..18195fa37 100644 --- a/packages/excalidraw/components/Stats/FontSize.tsx +++ b/packages/excalidraw/components/Stats/FontSize.tsx @@ -1,17 +1,19 @@ -import { isTextElement, redrawTextBoundingBox } from "../../element"; -import { mutateElement } from "../../element/mutateElement"; -import { getBoundTextElement } from "../../element/textElement"; -import { hasBoundTextElement } from "../../element/typeChecks"; +import { isTextElement, redrawTextBoundingBox } from "@excalidraw/element"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; + +import type { + ExcalidrawElement, + ExcalidrawTextElement, +} from "@excalidraw/element/types"; + import { fontSizeIcon } from "../icons"; import StatsDragInput from "./DragInput"; import { getStepSizedValue } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; -import type { - ExcalidrawElement, - ExcalidrawTextElement, -} from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/MultiAngle.tsx b/packages/excalidraw/components/Stats/MultiAngle.tsx index ec314c183..e90167cd8 100644 --- a/packages/excalidraw/components/Stats/MultiAngle.tsx +++ b/packages/excalidraw/components/Stats/MultiAngle.tsx @@ -1,18 +1,22 @@ +import { isInGroup } from "@excalidraw/common"; + import { degreesToRadians, radiansToDegrees } from "@excalidraw/math"; +import { mutateElement } from "@excalidraw/element/mutateElement"; + +import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { isArrowElement } from "@excalidraw/element/typeChecks"; + import type { Degrees } from "@excalidraw/math"; -import { mutateElement } from "../../element/mutateElement"; -import { getBoundTextElement } from "../../element/textElement"; -import { isArrowElement } from "../../element/typeChecks"; -import { isInGroup } from "../../groups"; +import type { ExcalidrawElement } from "@excalidraw/element/types"; + import { angleIcon } from "../icons"; import DragInput from "./DragInput"; import { getStepSizedValue, isPropertyEditable } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; -import type { ExcalidrawElement } from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/MultiDimension.tsx b/packages/excalidraw/components/Stats/MultiDimension.tsx index fb9cea942..cb27c93ee 100644 --- a/packages/excalidraw/components/Stats/MultiDimension.tsx +++ b/packages/excalidraw/components/Stats/MultiDimension.tsx @@ -1,18 +1,24 @@ import { pointFrom, type GlobalPoint } from "@excalidraw/math"; import { useMemo } from "react"; -import { MIN_WIDTH_OR_HEIGHT } from "../../constants"; -import { getCommonBounds, isTextElement } from "../../element"; -import { updateBoundElements } from "../../element/binding"; -import { mutateElement } from "../../element/mutateElement"; +import { MIN_WIDTH_OR_HEIGHT } from "@excalidraw/common"; +import { getCommonBounds, isTextElement } from "@excalidraw/element"; +import { updateBoundElements } from "@excalidraw/element/binding"; +import { mutateElement } from "@excalidraw/element/mutateElement"; import { rescalePointsInElement, resizeSingleElement, -} from "../../element/resizeElements"; +} from "@excalidraw/element/resizeElements"; import { getBoundTextElement, handleBindTextResize, -} from "../../element/textElement"; +} from "@excalidraw/element/textElement"; + +import type { + ElementsMap, + ExcalidrawElement, + NonDeletedSceneElementsMap, +} from "@excalidraw/element/types"; import DragInput from "./DragInput"; import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils"; @@ -20,11 +26,6 @@ import { getElementsInAtomicUnit } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; import type { AtomicUnit } from "./utils"; -import type { - ElementsMap, - ExcalidrawElement, - NonDeletedSceneElementsMap, -} from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/MultiFontSize.tsx b/packages/excalidraw/components/Stats/MultiFontSize.tsx index 8335399ef..5391aadfd 100644 --- a/packages/excalidraw/components/Stats/MultiFontSize.tsx +++ b/packages/excalidraw/components/Stats/MultiFontSize.tsx @@ -1,7 +1,14 @@ -import { isTextElement, redrawTextBoundingBox } from "../../element"; -import { mutateElement } from "../../element/mutateElement"; -import { getBoundTextElement } from "../../element/textElement"; -import { hasBoundTextElement } from "../../element/typeChecks"; +import { isTextElement, redrawTextBoundingBox } from "@excalidraw/element"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { getBoundTextElement } from "@excalidraw/element/textElement"; +import { hasBoundTextElement } from "@excalidraw/element/typeChecks"; + +import type { + ExcalidrawElement, + ExcalidrawTextElement, + NonDeletedSceneElementsMap, +} from "@excalidraw/element/types"; + import { isInGroup } from "../../groups"; import { fontSizeIcon } from "../icons"; @@ -9,11 +16,6 @@ import StatsDragInput from "./DragInput"; import { getStepSizedValue } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; -import type { - ExcalidrawElement, - ExcalidrawTextElement, - NonDeletedSceneElementsMap, -} from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/MultiPosition.tsx b/packages/excalidraw/components/Stats/MultiPosition.tsx index a8fdacf29..c722eccbc 100644 --- a/packages/excalidraw/components/Stats/MultiPosition.tsx +++ b/packages/excalidraw/components/Stats/MultiPosition.tsx @@ -1,7 +1,14 @@ import { pointFrom, pointRotateRads } from "@excalidraw/math"; import { useMemo } from "react"; -import { getCommonBounds, isTextElement } from "../../element"; +import { getCommonBounds, isTextElement } from "@excalidraw/element"; + +import type { + ElementsMap, + ExcalidrawElement, + NonDeletedExcalidrawElement, + NonDeletedSceneElementsMap, +} from "@excalidraw/element/types"; import StatsDragInput from "./DragInput"; import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils"; @@ -9,12 +16,6 @@ import { getElementsInAtomicUnit, moveElement } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; import type { AtomicUnit } from "./utils"; -import type { - ElementsMap, - ExcalidrawElement, - NonDeletedExcalidrawElement, - NonDeletedSceneElementsMap, -} from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/Position.tsx b/packages/excalidraw/components/Stats/Position.tsx index 08d0a8830..bf6dfd161 100644 --- a/packages/excalidraw/components/Stats/Position.tsx +++ b/packages/excalidraw/components/Stats/Position.tsx @@ -3,15 +3,16 @@ import { clamp, pointFrom, pointRotateRads, round } from "@excalidraw/math"; import { getFlipAdjustedCropPosition, getUncroppedWidthAndHeight, -} from "../../element/cropElement"; -import { mutateElement } from "../../element/mutateElement"; -import { isImageElement } from "../../element/typeChecks"; +} from "@excalidraw/element/cropElement"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { isImageElement } from "@excalidraw/element/typeChecks"; + +import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types"; import StatsDragInput from "./DragInput"; import { getStepSizedValue, moveElement } from "./utils"; import type { DragInputCallbackType } from "./DragInput"; -import type { ElementsMap, ExcalidrawElement } from "../../element/types"; import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/Stats/index.tsx b/packages/excalidraw/components/Stats/index.tsx index 56764fefb..6a38f4713 100644 --- a/packages/excalidraw/components/Stats/index.tsx +++ b/packages/excalidraw/components/Stats/index.tsx @@ -3,12 +3,15 @@ import clsx from "clsx"; import throttle from "lodash.throttle"; import { useEffect, useMemo, useState, memo } from "react"; -import { STATS_PANELS } from "../../constants"; -import { getCommonBounds } from "../../element/bounds"; -import { getUncroppedWidthAndHeight } from "../../element/cropElement"; -import { isElbowArrow, isImageElement } from "../../element/typeChecks"; -import { frameAndChildrenSelectedTogether } from "../../frame"; -import { elementsAreInSameGroup } from "../../groups"; +import { STATS_PANELS, elementsAreInSameGroup } from "@excalidraw/common"; +import { getCommonBounds } from "@excalidraw/element/bounds"; +import { getUncroppedWidthAndHeight } from "@excalidraw/element/cropElement"; +import { isElbowArrow, isImageElement } from "@excalidraw/element/typeChecks"; + +import { frameAndChildrenSelectedTogether } from "@excalidraw/element/frame"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { t } from "../../i18n"; import { isGridModeEnabled } from "../../snapping"; import { useExcalidrawAppState, useExcalidrawSetAppState } from "../App"; @@ -29,7 +32,6 @@ import { getAtomicUnits } from "./utils"; import "./Stats.scss"; -import type { NonDeletedExcalidrawElement } from "../../element/types"; import type { AppClassProperties, AppState, diff --git a/packages/excalidraw/components/Stats/stats.test.tsx b/packages/excalidraw/components/Stats/stats.test.tsx index b1fe0d685..76446a5cf 100644 --- a/packages/excalidraw/components/Stats/stats.test.tsx +++ b/packages/excalidraw/components/Stats/stats.test.tsx @@ -3,14 +3,21 @@ import { act, fireEvent, queryByTestId } from "@testing-library/react"; import React from "react"; import { vi } from "vitest"; +import { getCommonBounds, isTextElement } from "@excalidraw/element"; + +import { setDateTimeForTests, isInGroup, reseed } from "@excalidraw/common"; + import type { Degrees } from "@excalidraw/math"; +import type { + ExcalidrawElement, + ExcalidrawLinearElement, + ExcalidrawTextElement, +} from "@excalidraw/element/types"; + import { Excalidraw, mutateElement } from "../.."; import { actionGroup } from "../../actions"; -import { getCommonBounds, isTextElement } from "../../element"; -import { isInGroup } from "../../groups"; import { t } from "../../i18n"; -import { reseed } from "../../random"; import * as StaticScene from "../../renderer/staticScene"; import { API } from "../../tests/helpers/api"; import { Keyboard, Pointer, UI } from "../../tests/helpers/ui"; @@ -21,16 +28,9 @@ import { render, restoreOriginalGetBoundingClientRect, } from "../../tests/test-utils"; -import { setDateTimeForTests } from "../../utils"; import { getStepSizedValue } from "./utils"; -import type { - ExcalidrawElement, - ExcalidrawLinearElement, - ExcalidrawTextElement, -} from "../../element/types"; - const { h } = window; const mouse = new Pointer("mouse"); const renderStaticScene = vi.spyOn(StaticScene, "renderStaticScene"); diff --git a/packages/excalidraw/components/Stats/utils.ts b/packages/excalidraw/components/Stats/utils.ts index 219e02fa5..6c5ecd097 100644 --- a/packages/excalidraw/components/Stats/utils.ts +++ b/packages/excalidraw/components/Stats/utils.ts @@ -1,30 +1,32 @@ import { pointFrom, pointRotateRads } from "@excalidraw/math"; -import type { Radians } from "@excalidraw/math"; - import { bindOrUnbindLinearElements, updateBoundElements, -} from "../../element/binding"; -import { mutateElement } from "../../element/mutateElement"; -import { getBoundTextElement } from "../../element/textElement"; +} from "@excalidraw/element/binding"; +import { mutateElement } from "@excalidraw/element/mutateElement"; +import { getBoundTextElement } from "@excalidraw/element/textElement"; import { isFrameLikeElement, isLinearElement, isTextElement, -} from "../../element/typeChecks"; -import { - getSelectedGroupIds, - getElementsInGroup, - isInGroup, -} from "../../groups"; +} from "@excalidraw/element/typeChecks"; + +import type { Radians } from "@excalidraw/math"; import type { ElementsMap, ExcalidrawElement, NonDeletedExcalidrawElement, NonDeletedSceneElementsMap, -} from "../../element/types"; +} from "@excalidraw/element/types"; + +import { + getSelectedGroupIds, + getElementsInGroup, + isInGroup, +} from "../../groups"; + import type Scene from "../../scene/Scene"; import type { AppState } from "../../types"; diff --git a/packages/excalidraw/components/TTDDialog/MermaidToExcalidraw.tsx b/packages/excalidraw/components/TTDDialog/MermaidToExcalidraw.tsx index b8cd48dfa..8a4f92840 100644 --- a/packages/excalidraw/components/TTDDialog/MermaidToExcalidraw.tsx +++ b/packages/excalidraw/components/TTDDialog/MermaidToExcalidraw.tsx @@ -1,11 +1,13 @@ import { useState, useRef, useEffect, useDeferredValue } from "react"; +import { EDITOR_LS_KEYS, debounce, isDevEnv } from "@excalidraw/common"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { useApp } from "../App"; import { ArrowRightIcon } from "../icons"; -import { EDITOR_LS_KEYS } from "../../constants"; import { EditorLocalStorage } from "../../data/EditorLocalStorage"; import { t } from "../../i18n"; -import { debounce, isDevEnv } from "../../utils"; import Trans from "../Trans"; import { TTDDialogInput } from "./TTDDialogInput"; @@ -23,7 +25,6 @@ import "./MermaidToExcalidraw.scss"; import type { BinaryFiles } from "../../types"; import type { MermaidToExcalidrawLibProps } from "./common"; -import type { NonDeletedExcalidrawElement } from "../../element/types"; const MERMAID_EXAMPLE = "flowchart TD\n A[Christmas] -->|Get money| B(Go shopping)\n B --> C{Let me think}\n C -->|One| D[Laptop]\n C -->|Two| E[iPhone]\n C -->|Three| F[Car]"; diff --git a/packages/excalidraw/components/TTDDialog/TTDDialog.tsx b/packages/excalidraw/components/TTDDialog/TTDDialog.tsx index 3b9b868f7..68d230d24 100644 --- a/packages/excalidraw/components/TTDDialog/TTDDialog.tsx +++ b/packages/excalidraw/components/TTDDialog/TTDDialog.tsx @@ -1,6 +1,9 @@ -import { isFiniteNumber } from "@excalidraw/math"; import { useEffect, useRef, useState } from "react"; +import { isFiniteNumber } from "@excalidraw/math"; + +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { trackEvent } from "../../analytics"; import { useUIAppState } from "../../context/ui-appState"; import { atom, useAtom } from "../../editor-jotai"; @@ -32,7 +35,7 @@ import "./TTDDialog.scss"; import type { ChangeEventHandler } from "react"; import type { MermaidToExcalidrawLibProps } from "./common"; -import type { NonDeletedExcalidrawElement } from "../../element/types"; + import type { BinaryFiles } from "../../types"; const MIN_PROMPT_LENGTH = 3; diff --git a/packages/excalidraw/components/TTDDialog/TTDDialogInput.tsx b/packages/excalidraw/components/TTDDialog/TTDDialogInput.tsx index 8e349643e..9bd80b681 100644 --- a/packages/excalidraw/components/TTDDialog/TTDDialogInput.tsx +++ b/packages/excalidraw/components/TTDDialog/TTDDialogInput.tsx @@ -1,7 +1,6 @@ import { useEffect, useRef } from "react"; -import { EVENT } from "../../constants"; -import { KEYS } from "../../keys"; +import { EVENT, KEYS } from "@excalidraw/common"; import type { ChangeEventHandler } from "react"; diff --git a/packages/excalidraw/components/TTDDialog/TTDDialogSubmitShortcut.tsx b/packages/excalidraw/components/TTDDialog/TTDDialogSubmitShortcut.tsx index a8831e3a0..05cad640b 100644 --- a/packages/excalidraw/components/TTDDialog/TTDDialogSubmitShortcut.tsx +++ b/packages/excalidraw/components/TTDDialog/TTDDialogSubmitShortcut.tsx @@ -1,4 +1,4 @@ -import { getShortcutKey } from "../../utils"; +import { getShortcutKey } from "@excalidraw/common"; export const TTDDialogSubmitShortcut = () => { return ( diff --git a/packages/excalidraw/components/TTDDialog/TTDDialogTabs.tsx b/packages/excalidraw/components/TTDDialog/TTDDialogTabs.tsx index 1c9075e7d..fe4128106 100644 --- a/packages/excalidraw/components/TTDDialog/TTDDialogTabs.tsx +++ b/packages/excalidraw/components/TTDDialog/TTDDialogTabs.tsx @@ -1,7 +1,8 @@ import * as RadixTabs from "@radix-ui/react-tabs"; import { useRef } from "react"; -import { isMemberOf } from "../../utils"; +import { isMemberOf } from "@excalidraw/common"; + import { useExcalidrawSetAppState } from "../App"; import type { ReactNode } from "react"; diff --git a/packages/excalidraw/components/TTDDialog/common.ts b/packages/excalidraw/components/TTDDialog/common.ts index 89c342c65..2e59565cf 100644 --- a/packages/excalidraw/components/TTDDialog/common.ts +++ b/packages/excalidraw/components/TTDDialog/common.ts @@ -1,13 +1,15 @@ +import { DEFAULT_EXPORT_PADDING, EDITOR_LS_KEYS } from "@excalidraw/common"; + import type { MermaidConfig } from "@excalidraw/mermaid-to-excalidraw"; import type { MermaidToExcalidrawResult } from "@excalidraw/mermaid-to-excalidraw/dist/interfaces"; -import { DEFAULT_EXPORT_PADDING, EDITOR_LS_KEYS } from "../../constants"; +import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; + import { EditorLocalStorage } from "../../data/EditorLocalStorage"; import { canvasToBlob } from "../../data/blob"; import { t } from "../../i18n"; import { convertToExcalidrawElements, exportToCanvas } from "../../index"; -import type { NonDeletedExcalidrawElement } from "../../element/types"; import type { AppClassProperties, BinaryFiles } from "../../types"; const resetPreview = ({ diff --git a/packages/excalidraw/components/ToolButton.tsx b/packages/excalidraw/components/ToolButton.tsx index fb76731b0..f833a6d1f 100644 --- a/packages/excalidraw/components/ToolButton.tsx +++ b/packages/excalidraw/components/ToolButton.tsx @@ -1,15 +1,17 @@ import clsx from "clsx"; import React, { useEffect, useRef, useState } from "react"; +import { isPromiseLike } from "@excalidraw/common"; + +import type { PointerType } from "@excalidraw/element/types"; + import { AbortError } from "../errors"; -import { isPromiseLike } from "../utils"; import "./ToolIcon.scss"; import Spinner from "./Spinner"; import { useExcalidrawContainer } from "./App"; -import type { PointerType } from "../element/types"; import type { CSSProperties } from "react"; export type ToolButtonSize = "small" | "medium"; diff --git a/packages/excalidraw/components/UserList.tsx b/packages/excalidraw/components/UserList.tsx index 6c74411a1..d609e474c 100644 --- a/packages/excalidraw/components/UserList.tsx +++ b/packages/excalidraw/components/UserList.tsx @@ -2,9 +2,9 @@ import * as Popover from "@radix-ui/react-popover"; import clsx from "clsx"; import React, { useLayoutEffect } from "react"; -import { supportsResizeObserver } from "../constants"; +import { supportsResizeObserver, isShallowEqual } from "@excalidraw/common"; + import { t } from "../i18n"; -import { isShallowEqual } from "../utils"; import { useExcalidrawActionManager } from "./App"; import { Island } from "./Island"; diff --git a/packages/excalidraw/components/canvases/InteractiveCanvas.tsx b/packages/excalidraw/components/canvases/InteractiveCanvas.tsx index 8388e5e6c..1f4f57433 100644 --- a/packages/excalidraw/components/canvases/InteractiveCanvas.tsx +++ b/packages/excalidraw/components/canvases/InteractiveCanvas.tsx @@ -1,15 +1,20 @@ import React, { useEffect, useRef } from "react"; -import { CURSOR_TYPE } from "../../constants"; -import { t } from "../../i18n"; -import { isRenderThrottlingEnabled } from "../../reactUtils"; -import { renderInteractiveScene } from "../../renderer/interactiveScene"; -import { isShallowEqual, sceneCoordsToViewportCoords } from "../../utils"; +import { + CURSOR_TYPE, + isShallowEqual, + sceneCoordsToViewportCoords, +} from "@excalidraw/common"; import type { NonDeletedExcalidrawElement, NonDeletedSceneElementsMap, -} from "../../element/types"; +} from "@excalidraw/element/types"; + +import { t } from "../../i18n"; +import { isRenderThrottlingEnabled } from "../../reactUtils"; +import { renderInteractiveScene } from "../../renderer/interactiveScene"; + import type { InteractiveCanvasRenderConfig, RenderableElementsMap, diff --git a/packages/excalidraw/components/canvases/NewElementCanvas.tsx b/packages/excalidraw/components/canvases/NewElementCanvas.tsx index 524d6af34..4310f1bd1 100644 --- a/packages/excalidraw/components/canvases/NewElementCanvas.tsx +++ b/packages/excalidraw/components/canvases/NewElementCanvas.tsx @@ -1,9 +1,10 @@ import { useEffect, useRef } from "react"; +import type { NonDeletedSceneElementsMap } from "@excalidraw/element/types"; + import { isRenderThrottlingEnabled } from "../../reactUtils"; import { renderNewElementScene } from "../../renderer/renderNewElementScene"; -import type { NonDeletedSceneElementsMap } from "../../element/types"; import type { RenderableElementsMap, StaticCanvasRenderConfig, diff --git a/packages/excalidraw/components/canvases/StaticCanvas.tsx b/packages/excalidraw/components/canvases/StaticCanvas.tsx index 6e2df9537..b70c8ace6 100644 --- a/packages/excalidraw/components/canvases/StaticCanvas.tsx +++ b/packages/excalidraw/components/canvases/StaticCanvas.tsx @@ -1,13 +1,15 @@ import React, { useEffect, useRef } from "react"; -import { isRenderThrottlingEnabled } from "../../reactUtils"; -import { renderStaticScene } from "../../renderer/staticScene"; -import { isShallowEqual } from "../../utils"; +import { isShallowEqual } from "@excalidraw/common"; import type { NonDeletedExcalidrawElement, NonDeletedSceneElementsMap, -} from "../../element/types"; +} from "@excalidraw/element/types"; + +import { isRenderThrottlingEnabled } from "../../reactUtils"; +import { renderStaticScene } from "../../renderer/staticScene"; + import type { RenderableElementsMap, StaticCanvasRenderConfig, diff --git a/packages/excalidraw/components/dropdownMenu/DropdownMenu.test.tsx b/packages/excalidraw/components/dropdownMenu/DropdownMenu.test.tsx index d4c0b7a8d..5be65b100 100644 --- a/packages/excalidraw/components/dropdownMenu/DropdownMenu.test.tsx +++ b/packages/excalidraw/components/dropdownMenu/DropdownMenu.test.tsx @@ -1,7 +1,8 @@ import React from "react"; +import { KEYS } from "@excalidraw/common"; + import { Excalidraw } from "../../index"; -import { KEYS } from "../../keys"; import { Keyboard } from "../../tests/helpers/ui"; import { render, diff --git a/packages/excalidraw/components/dropdownMenu/DropdownMenuContent.tsx b/packages/excalidraw/components/dropdownMenu/DropdownMenuContent.tsx index 24a0a4d27..33a9bc005 100644 --- a/packages/excalidraw/components/dropdownMenu/DropdownMenuContent.tsx +++ b/packages/excalidraw/components/dropdownMenu/DropdownMenuContent.tsx @@ -1,7 +1,8 @@ import clsx from "clsx"; import React, { useEffect, useRef } from "react"; -import { EVENT } from "../../constants"; +import { EVENT } from "@excalidraw/common"; + import { useOutsideClick } from "../../hooks/useOutsideClick"; import { useStable } from "../../hooks/useStable"; import { KEYS } from "../../keys"; diff --git a/packages/excalidraw/components/dropdownMenu/DropdownMenuItem.tsx b/packages/excalidraw/components/dropdownMenu/DropdownMenuItem.tsx index fc19bd1bf..7a3bde0bd 100644 --- a/packages/excalidraw/components/dropdownMenu/DropdownMenuItem.tsx +++ b/packages/excalidraw/components/dropdownMenu/DropdownMenuItem.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useRef } from "react"; -import { THEME } from "../../constants"; +import { THEME } from "@excalidraw/common"; + import { useExcalidrawAppState } from "../App"; import MenuItemContent from "./DropdownMenuItemContent"; diff --git a/packages/excalidraw/components/dropdownMenu/common.ts b/packages/excalidraw/components/dropdownMenu/common.ts index 312b78aae..feca5c406 100644 --- a/packages/excalidraw/components/dropdownMenu/common.ts +++ b/packages/excalidraw/components/dropdownMenu/common.ts @@ -1,7 +1,6 @@ import React, { useContext } from "react"; -import { EVENT } from "../../constants"; -import { composeEventHandlers } from "../../utils"; +import { EVENT, composeEventHandlers } from "@excalidraw/common"; export const DropdownMenuContentPropsContext = React.createContext<{ onSelect?: (event: Event) => void; diff --git a/packages/excalidraw/components/hyperlink/Hyperlink.tsx b/packages/excalidraw/components/hyperlink/Hyperlink.tsx index 88983aeab..6200a039c 100644 --- a/packages/excalidraw/components/hyperlink/Hyperlink.tsx +++ b/packages/excalidraw/components/hyperlink/Hyperlink.tsx @@ -8,37 +8,51 @@ import { useState, } from "react"; -import { trackEvent } from "../../analytics"; -import { getTooltipDiv, updateTooltipPosition } from "../../components/Tooltip"; -import { EVENT, HYPERLINK_TOOLTIP_DELAY } from "../../constants"; -import { isLocalLink, normalizeLink } from "../../data/url"; -import { getElementAbsoluteCoords } from "../../element/bounds"; -import { hitElementBoundingBox } from "../../element/collision"; -import { isElementLink } from "../../element/elementLink"; -import { getEmbedLink, embeddableURLValidator } from "../../element/embeddable"; -import { mutateElement } from "../../element/mutateElement"; -import { t } from "../../i18n"; +import { EVENT, HYPERLINK_TOOLTIP_DELAY } from "@excalidraw/common"; + +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; + +import { hitElementBoundingBox } from "@excalidraw/element/collision"; + +import { isElementLink } from "@excalidraw/element/elementLink"; + +import { + getEmbedLink, + embeddableURLValidator, +} from "@excalidraw/element/embeddable"; + +import { mutateElement } from "@excalidraw/element/mutateElement"; + import { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, wrapEvent, -} from "../../utils"; -import { useAppProps, useDevice, useExcalidrawAppState } from "../App"; -import { ToolButton } from "../ToolButton"; -import { FreedrawIcon, TrashIcon, elementLinkIcon } from "../icons"; -import { KEYS } from "../../keys"; -import { getSelectedElements } from "../../scene"; -import { isEmbeddableElement } from "../../element/typeChecks"; + isLocalLink, + normalizeLink, +} from "@excalidraw/common"; -import { getLinkHandleFromCoords } from "./helpers"; - -import "./Hyperlink.scss"; +import { isEmbeddableElement } from "@excalidraw/element/typeChecks"; import type { ElementsMap, ExcalidrawEmbeddableElement, NonDeletedExcalidrawElement, -} from "../../element/types"; +} from "@excalidraw/element/types"; + +import { trackEvent } from "../../analytics"; +import { getTooltipDiv, updateTooltipPosition } from "../../components/Tooltip"; + +import { t } from "../../i18n"; + +import { useAppProps, useDevice, useExcalidrawAppState } from "../App"; +import { ToolButton } from "../ToolButton"; +import { FreedrawIcon, TrashIcon, elementLinkIcon } from "../icons"; +import { getSelectedElements } from "../../scene"; + +import { getLinkHandleFromCoords } from "./helpers"; + +import "./Hyperlink.scss"; + import type { AppState, ExcalidrawProps, UIAppState } from "../../types"; const POPUP_WIDTH = 380; diff --git a/packages/excalidraw/components/hyperlink/helpers.ts b/packages/excalidraw/components/hyperlink/helpers.ts index 3d39e2ebe..b5140f485 100644 --- a/packages/excalidraw/components/hyperlink/helpers.ts +++ b/packages/excalidraw/components/hyperlink/helpers.ts @@ -1,17 +1,19 @@ import { pointFrom, pointRotateRads } from "@excalidraw/math"; +import { MIME_TYPES } from "@excalidraw/common"; +import { getElementAbsoluteCoords } from "@excalidraw/element/bounds"; +import { hitElementBoundingBox } from "@excalidraw/element/collision"; + import type { GlobalPoint, Radians } from "@excalidraw/math"; -import { MIME_TYPES } from "../../constants"; -import { getElementAbsoluteCoords } from "../../element/bounds"; -import { hitElementBoundingBox } from "../../element/collision"; -import { DEFAULT_LINK_SIZE } from "../../renderer/renderElement"; - -import type { Bounds } from "../../element/bounds"; +import type { Bounds } from "@excalidraw/element/bounds"; import type { ElementsMap, NonDeletedExcalidrawElement, -} from "../../element/types"; +} from "@excalidraw/element/types"; + +import { DEFAULT_LINK_SIZE } from "../../renderer/renderElement"; + import type { AppState, UIAppState } from "../../types"; export const EXTERNAL_LINK_IMG = document.createElement("img"); diff --git a/packages/excalidraw/components/icons.tsx b/packages/excalidraw/components/icons.tsx index 03e6ca2bb..c6d7f9473 100644 --- a/packages/excalidraw/components/icons.tsx +++ b/packages/excalidraw/components/icons.tsx @@ -10,9 +10,9 @@ import clsx from "clsx"; import oc from "open-color"; import React from "react"; -import { THEME } from "../constants"; +import { THEME } from "@excalidraw/common"; -import type { Theme } from "../element/types"; +import type { Theme } from "@excalidraw/element/types"; export const iconFillColor = (theme: Theme) => "var(--icon-fill-color)"; diff --git a/packages/excalidraw/components/main-menu/DefaultItems.tsx b/packages/excalidraw/components/main-menu/DefaultItems.tsx index c2307d521..29a2761a1 100644 --- a/packages/excalidraw/components/main-menu/DefaultItems.tsx +++ b/packages/excalidraw/components/main-menu/DefaultItems.tsx @@ -1,5 +1,9 @@ import clsx from "clsx"; +import { THEME } from "@excalidraw/common"; + +import type { Theme } from "@excalidraw/element/types"; + import { actionClearCanvas, actionLoadScene, @@ -10,7 +14,6 @@ import { } from "../../actions"; import { getShortcutFromShortcutName } from "../../actions/shortcuts"; import { trackEvent } from "../../analytics"; -import { THEME } from "../../constants"; import { useUIAppState } from "../../context/ui-appState"; import { useSetAtom } from "../../editor-jotai"; import { useI18n } from "../../i18n"; @@ -44,8 +47,6 @@ import { import "./DefaultItems.scss"; -import type { Theme } from "../../element/types"; - export const LoadScene = () => { const { t } = useI18n(); const actionManager = useExcalidrawActionManager(); diff --git a/packages/excalidraw/components/main-menu/MainMenu.tsx b/packages/excalidraw/components/main-menu/MainMenu.tsx index 54f60a364..7c2b5fb4a 100644 --- a/packages/excalidraw/components/main-menu/MainMenu.tsx +++ b/packages/excalidraw/components/main-menu/MainMenu.tsx @@ -1,9 +1,10 @@ import React from "react"; +import { composeEventHandlers } from "@excalidraw/common"; + import { useTunnels } from "../../context/tunnels"; import { useUIAppState } from "../../context/ui-appState"; import { t } from "../../i18n"; -import { composeEventHandlers } from "../../utils"; import { useDevice, useExcalidrawSetAppState } from "../App"; import { UserList } from "../UserList"; import DropdownMenu from "../dropdownMenu/DropdownMenu"; diff --git a/packages/tsconfig.base.json b/packages/tsconfig.base.json index fa8c1ed6e..b00d1d60a 100644 --- a/packages/tsconfig.base.json +++ b/packages/tsconfig.base.json @@ -1,29 +1,27 @@ - { - "compilerOptions": { - "target": "ESNext", - "strict": true, - "skipLibCheck": true, - "declaration": true, - "allowSyntheticDefaultImports": true, - "module": "ESNext", - "moduleResolution": "Node", - "resolveJsonModule": true, - "jsx": "react-jsx", - "emitDeclarationOnly": true, - "paths": { - "@excalidraw/common": ["./common/index.ts"], - "@excalidraw/common/*": ["./common/src/*"], - "@excalidraw/element": ["./element/index.ts"], - "@excalidraw/element/*": ["./element/src/*"], - "@excalidraw/excalidraw": ["./excalidraw/index.tsx"], - "@excalidraw/excalidraw/*": ["./excalidraw/*"], - "@excalidraw/math": ["./math/index.ts"], - "@excalidraw/math/*": ["./math/src/*"], - "@excalidraw/utils": ["./utils/index.ts"], - "@excalidraw/utils/*": ["./utils/*"], - } - }, - "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"] - } - \ No newline at end of file + "compilerOptions": { + "target": "ESNext", + "strict": true, + "skipLibCheck": true, + "declaration": true, + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "Node", + "resolveJsonModule": true, + "jsx": "react-jsx", + "emitDeclarationOnly": true, + "paths": { + "@excalidraw/common": ["./common/index.ts"], + "@excalidraw/common/*": ["./common/src/*"], + "@excalidraw/element": ["./element/index.ts"], + "@excalidraw/element/*": ["./element/src/*"], + "@excalidraw/excalidraw": ["./excalidraw/index.tsx"], + "@excalidraw/excalidraw/*": ["./excalidraw/*"], + "@excalidraw/math": ["./math/index.ts"], + "@excalidraw/math/*": ["./math/src/*"], + "@excalidraw/utils": ["./utils/index.ts"], + "@excalidraw/utils/*": ["./utils/*"] + } + }, + "exclude": ["**/*.test.*", "tests", "types", "examples", "dist"] +} diff --git a/tsconfig.json b/tsconfig.json index 8fe3e2bdd..a9112b87c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,7 +28,7 @@ "@excalidraw/math": ["./packages/math/index.ts"], "@excalidraw/math/*": ["./packages/math/src/*"], "@excalidraw/utils": ["./packages/utils/index.ts"], - "@excalidraw/utils/*": ["./packages/utils/*"], + "@excalidraw/utils/*": ["./packages/utils/*"] } }, "include": ["packages", "excalidraw-app"],