Move utility types in common

This commit is contained in:
Marcel Mraz 2025-03-18 19:43:21 +01:00
parent 0a7e9c51d6
commit e1ea33836e
No known key found for this signature in database
GPG key ID: 4EBD6E62DC830CD2
46 changed files with 76 additions and 50 deletions

View file

@ -71,7 +71,7 @@ import type {
ExcalidrawInitialDataState,
UIAppState,
} from "@excalidraw/excalidraw/types";
import type { ResolutionType } from "@excalidraw/excalidraw/utility-types";
import type { ResolutionType } from "@excalidraw/common/utility-types";
import type { ResolvablePromise } from "@excalidraw/common";
import CustomStats from "./CustomStats";

View file

@ -49,7 +49,7 @@ import type {
Collaborator,
Gesture,
} from "@excalidraw/excalidraw/types";
import type { Mutable, ValueOf } from "@excalidraw/excalidraw/utility-types";
import type { Mutable, ValueOf } from "@excalidraw/common/utility-types";
import { appJotaiStore, atom } from "../app-jotai";
import {

View file

@ -32,7 +32,7 @@ import type {
BinaryFileData,
BinaryFiles,
} from "@excalidraw/excalidraw/types";
import type { MaybePromise } from "@excalidraw/excalidraw/utility-types";
import type { MaybePromise } from "@excalidraw/common/utility-types";
import { SAVE_TO_LOCAL_STORAGE_TIMEOUT, STORAGE_KEYS } from "../app_constants";

View file

@ -28,7 +28,7 @@ import type {
BinaryFiles,
SocketId,
} from "@excalidraw/excalidraw/types";
import type { MakeBrand } from "@excalidraw/excalidraw/utility-types";
import type { MakeBrand } from "@excalidraw/common/utility-types";
import {
DELETED_ELEMENT_TIMEOUT,

View file

@ -1,6 +1,6 @@
import oc from "open-color";
import type { Merge } from "@excalidraw/excalidraw/utility-types";
import type { Merge } from "@excalidraw/common/utility-types";
// FIXME can't put to utils.ts rn because of circular dependency
const pick = <R extends Record<string, any>, K extends readonly (keyof R)[]>(

View file

@ -1,4 +1,4 @@
import type { ValueOf } from "@excalidraw/excalidraw/utility-types";
import type { ValueOf } from "@excalidraw/common/utility-types";
import { isDarwin } from "./constants";

View file

@ -21,7 +21,7 @@ import type {
import type {
MaybePromise,
ResolutionType,
} from "@excalidraw/excalidraw/utility-types";
} from "@excalidraw/common/utility-types";
import { COLOR_PALETTE } from "./colors";
import {

View file

@ -13,7 +13,7 @@ import {
isLinearElement,
} from "@excalidraw/element/typeChecks";
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
import type { Mutable } from "@excalidraw/common/utility-types";
import type {
ExcalidrawElement,

View file

@ -25,7 +25,7 @@ import type {
import type { AppState } from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { LinearElementEditor } from "./linearElementEditor";
import { getBoundTextElement, getContainerElement } from "./textElement";

View file

@ -6,7 +6,7 @@ import {
} from "@excalidraw/common";
import type { ExcalidrawProps } from "@excalidraw/excalidraw/types";
import type { MarkRequired } from "@excalidraw/excalidraw/utility-types";
import type { MarkRequired } from "@excalidraw/common/utility-types";
import { newTextElement } from "./newElement";
import { wrapText } from "./textWrapping";

View file

@ -29,7 +29,7 @@ import type {
StaticCanvasAppState,
} from "@excalidraw/excalidraw/types";
import type { ReadonlySetLike } from "@excalidraw/excalidraw/utility-types";
import type { ReadonlySetLike } from "@excalidraw/common/utility-types";
import { getElementsInGroup, selectGroupsFromGivenElements } from "./groups";

View file

@ -17,7 +17,7 @@ import type {
AppState,
InteractiveCanvasAppState,
} from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
import type { Mutable } from "@excalidraw/common/utility-types";
export const selectGroup = (
groupId: GroupId,

View file

@ -43,7 +43,7 @@ import type {
Zoom,
} from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
import type { Mutable } from "@excalidraw/common/utility-types";
import {
bindOrUnbindLinearElement,

View file

@ -10,7 +10,7 @@ import Scene from "@excalidraw/excalidraw/scene/Scene";
import type { Radians } from "@excalidraw/math";
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { ShapeCache } from "./ShapeCache";

View file

@ -25,7 +25,7 @@ import type {
MarkOptional,
Merge,
Mutable,
} from "@excalidraw/excalidraw/utility-types";
} from "@excalidraw/common/utility-types";
import { getResizedElementAbsoluteCoords } from "./bounds";
import { bumpVersion, newElementWith } from "./mutateElement";

View file

@ -22,7 +22,7 @@ import type Scene from "@excalidraw/excalidraw/scene/Scene";
import type { PointerDownState } from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/excalidraw/utility-types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { getArrowLocalFixedPoints, updateBoundElements } from "./binding";
import {

View file

@ -11,7 +11,7 @@ import {
import type { AppState } from "@excalidraw/excalidraw/types";
import type { ExtractSetType } from "@excalidraw/excalidraw/utility-types";
import type { ExtractSetType } from "@excalidraw/common/utility-types";
import {
resetOriginalContainerCache,

View file

@ -2,7 +2,7 @@ import { ROUNDNESS, assertNever } from "@excalidraw/common";
import type { ElementOrToolType } from "@excalidraw/excalidraw/types";
import type { MarkNonNullable } from "@excalidraw/excalidraw/utility-types";
import type { MarkNonNullable } from "@excalidraw/common/utility-types";
import type { Bounds } from "./bounds";
import type {

View file

@ -13,7 +13,7 @@ import type {
MarkNonNullable,
Merge,
ValueOf,
} from "@excalidraw/excalidraw/utility-types";
} from "@excalidraw/common/utility-types";
export type ChartType = "bar" | "line";
export type FillStyle = "hachure" | "cross-hatch" | "solid" | "zigzag";

View file

@ -38,12 +38,13 @@ import type {
ExcalidrawTextElement,
} from "@excalidraw/element/types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { CaptureUpdateAction } from "../store";
import { register } from "./register";
import type { AppState } from "../types";
import type { Mutable } from "../utility-types";
export const actionUnbindText = register({
name: "unbindText",

View file

@ -1,8 +1,9 @@
import { isDarwin, getShortcutKey } from "@excalidraw/common";
import type { SubtypeOf } from "@excalidraw/common/utility-types";
import { t } from "../i18n";
import type { SubtypeOf } from "../utility-types";
import type { ActionName } from "./types";
export type ShortcutName =

View file

@ -51,6 +51,8 @@ import type {
SceneElementsMap,
} from "@excalidraw/element/types";
import type { SubtypeOf, ValueOf } from "@excalidraw/common/utility-types";
import { getObservedAppState } from "./store";
import type {
@ -59,7 +61,6 @@ import type {
ObservedElementsAppState,
ObservedStandaloneAppState,
} from "./types";
import type { SubtypeOf, ValueOf } from "./utility-types";
/**
* Represents the difference between two objects of the same type.

View file

@ -316,6 +316,8 @@ import type {
ExcalidrawArrowElement,
} from "@excalidraw/element/types";
import type { ValueOf } from "@excalidraw/common/utility-types";
import {
actionAddToLibrary,
actionBringForward,
@ -515,7 +517,6 @@ import type {
NullableGridSize,
Offsets,
} from "../types";
import type { ValueOf } from "../utility-types";
import type { RoughCanvas } from "roughjs/bin/canvas";
import type { Action, ActionResult } from "../actions/types";

View file

@ -6,13 +6,14 @@ import type {
ColorPaletteCustom,
} from "@excalidraw/common";
import type { ValueOf } from "@excalidraw/common/utility-types";
import {
colorPickerHotkeyBindings,
getColorNameAndShadeFromColor,
} from "./colorPickerUtils";
import type { ActiveColorPickerSectionAtomType } from "./colorPickerUtils";
import type { ValueOf } from "../../utility-types";
const arrowHandler = (
eventKey: string,

View file

@ -11,6 +11,8 @@ import {
isWritableElement,
} from "@excalidraw/common";
import type { MarkRequired } from "@excalidraw/common/utility-types";
import {
actionClearCanvas,
actionLink,
@ -61,7 +63,6 @@ import "./CommandPalette.scss";
import type { CommandPaletteItem } from "./types";
import type { AppProps, AppState, UIAppState } from "../../types";
import type { MarkRequired } from "../../utility-types";
import type { ShortcutName } from "../../actions/shortcuts";
import type { TranslationKeys } from "../../i18n";
import type { Action } from "../../actions/types";

View file

@ -7,6 +7,8 @@ import {
composeEventHandlers,
} from "@excalidraw/common";
import type { MarkOptional, Merge } from "@excalidraw/common/utility-types";
import { useTunnels } from "../context/tunnels";
import { useUIAppState } from "../context/ui-appState";
@ -19,7 +21,6 @@ import { Sidebar } from "./Sidebar/Sidebar";
import { withInternalFallback } from "./hoc/withInternalFallback";
import { LibraryIcon, searchIcon } from "./icons";
import type { MarkOptional, Merge } from "../utility-types";
import type { SidebarProps, SidebarTriggerProps } from "./Sidebar/common";
const DefaultSidebarTrigger = withInternalFallback(

View file

@ -11,6 +11,8 @@ import { type FontFamilyValues } from "@excalidraw/element/types";
import { arrayToList, debounce, getFontFamilyString } from "@excalidraw/common";
import type { ValueOf } from "@excalidraw/common/utility-types";
import { Fonts } from "../../fonts";
import { t } from "../../i18n";
import { useApp, useAppProps, useExcalidrawContainer } from "../App";
@ -26,7 +28,6 @@ import { FontFamilyNormalIcon } from "../icons";
import { fontPickerKeyHandler } from "./keyboardNavHandlers";
import type { ValueOf } from "../../utility-types";
import type { JSX } from "react";
export interface FontDescriptor {

View file

@ -4,6 +4,8 @@ import React, { useLayoutEffect } from "react";
import { supportsResizeObserver, isShallowEqual } from "@excalidraw/common";
import type { MarkRequired } from "@excalidraw/common/utility-types";
import { t } from "../i18n";
import { useExcalidrawActionManager } from "./App";
@ -16,7 +18,6 @@ import "./UserList.scss";
import type { ActionManager } from "../actions/manager";
import type { Collaborator, SocketId } from "../types";
import type { MarkRequired } from "../utility-types";
export type GoToCollaboratorComponentProps = {
socketId: SocketId;

View file

@ -2,6 +2,8 @@ import React, { useEffect, useRef } from "react";
import { THEME } from "@excalidraw/common";
import type { ValueOf } from "@excalidraw/common/utility-types";
import { useExcalidrawAppState } from "../App";
import MenuItemContent from "./DropdownMenuItemContent";
@ -10,7 +12,6 @@ import {
useHandleDropdownMenuItemClick,
} from "./common";
import type { ValueOf } from "../../utility-types";
import type { JSX } from "react";
const DropdownMenuItem = ({

View file

@ -11,6 +11,8 @@ import { clearElementsForExport } from "@excalidraw/element";
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
import type { ValueOf } from "@excalidraw/common/utility-types";
import { cleanAppStateForExport } from "../appState";
import { CanvasError, ImageSceneDataError } from "../errors";
@ -25,7 +27,6 @@ import { restore, restoreLibraryItems } from "./restore";
import type { FileSystemHandle } from "./filesystem";
import type { AppState, DataURL, LibraryItem } from "../types";
import type { ValueOf } from "../utility-types";
import type { ImportedLibraryData } from "./types";
const parseFileContents = async (blob: Blob | File): Promise<string> => {

View file

@ -21,6 +21,8 @@ import { getCommonBoundingBox } from "@excalidraw/element/bounds";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type { MaybePromise } from "@excalidraw/common/utility-types";
import { atom, editorJotaiStore } from "../editor-jotai";
import { Emitter } from "../emitter";
@ -41,7 +43,6 @@ import type {
LibraryItemsSource,
LibraryItems_anyVersion,
} from "../types";
import type { MaybePromise } from "../utility-types";
/**
* format: hostname or hostname/pathname

View file

@ -10,8 +10,9 @@ import {
import type { OrderedExcalidrawElement } from "@excalidraw/element/types";
import type { MakeBrand } from "@excalidraw/common/utility-types";
import type { AppState } from "../types";
import type { MakeBrand } from "../utility-types";
export type ReconciledExcalidrawElement = OrderedExcalidrawElement &
MakeBrand<"ReconciledElement">;

View file

@ -61,6 +61,8 @@ import type {
StrokeRoundness,
} from "@excalidraw/element/types";
import type { MarkOptional, Mutable } from "@excalidraw/common/utility-types";
import { getDefaultAppState } from "../appState";
import { getLineHeight } from "../fonts/FontMetadata";
@ -71,7 +73,6 @@ import {
} from "../scene";
import type { AppState, BinaryFiles, LibraryItem } from "../types";
import type { MarkOptional, Mutable } from "../utility-types";
import type { ImportedDataState, LegacyAppState } from "./types";
type RestoredAppState = Omit<

View file

@ -59,9 +59,9 @@ import type {
VerticalAlign,
} from "@excalidraw/element/types";
import { getLineHeight } from "../fonts/FontMetadata";
import type { MarkOptional } from "@excalidraw/common/utility-types";
import type { MarkOptional } from "../utility-types";
import { getLineHeight } from "../fonts/FontMetadata";
export type ValidLinearElement = {
type: "arrow" | "line";

View file

@ -19,6 +19,8 @@ import type {
ExcalidrawTextElement,
} from "@excalidraw/element/types";
import type { ValueOf } from "@excalidraw/common/utility-types";
import { CascadiaFontFaces } from "./Cascadia";
import { ComicShannsFontFaces } from "./ComicShanns";
import { EmojiFontFaces } from "./Emoji";
@ -33,7 +35,6 @@ import { VirgilFontFaces } from "./Virgil";
import { XiaolaiFontFaces } from "./Xiaolai";
import type Scene from "../scene/Scene";
import type { ValueOf } from "../utility-types";
export class Fonts {
// it's ok to track fonts across multiple instances only once, so let's use

View file

@ -1,9 +1,9 @@
import type { NestedKeyOf } from "@excalidraw/common/utility-types";
import { useAtomValue, editorJotaiStore, atom } from "./editor-jotai";
import fallbackLangData from "./locales/en.json";
import percentages from "./locales/percentages.json";
import type { NestedKeyOf } from "./utility-types";
const COMPLETION_THRESHOLD = 85;
export interface Language {

View file

@ -77,12 +77,10 @@
"lodash.debounce": "4.0.8",
"nanoid": "3.3.3",
"pako": "2.0.3",
"perfect-freehand": "1.2.0",
"pica": "7.1.1",
"png-chunk-text": "1.0.0",
"png-chunks-encode": "1.0.0",
"png-chunks-extract": "1.0.0",
"points-on-curve": "1.0.1",
"pwacompat": "2.0.17",
"roughjs": "4.6.4",
"sass": "1.51.0",

View file

@ -2,7 +2,7 @@ import { promiseTry, resolvablePromise } from "@excalidraw/common";
import type { ResolvablePromise } from "@excalidraw/common";
import type { MaybePromise } from "./utility-types";
import type { MaybePromise } from "@excalidraw/common/utility-types";
type Job<T, TArgs extends unknown[]> = (...args: TArgs) => MaybePromise<T>;

View file

@ -30,10 +30,11 @@ import type {
Ordered,
} from "@excalidraw/element/types";
import type { Assert, SameType } from "@excalidraw/common/utility-types";
import { getSelectedElements } from "./selection";
import type { AppState } from "../types";
import type { Assert, SameType } from "../utility-types";
type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
type ElementKey = ExcalidrawElement | ElementIdKey;

View file

@ -40,6 +40,8 @@ import {
import { syncInvalidIndices } from "@excalidraw/element/fractionalIndex";
import { type Mutable } from "@excalidraw/common/utility-types";
import type { Bounds } from "@excalidraw/element/bounds";
import type {
@ -58,7 +60,6 @@ import { Fonts } from "../fonts";
import { renderStaticScene } from "../renderer/staticScene";
import { renderSceneToSvg } from "../renderer/staticSvgScene";
import { type Mutable } from "../utility-types";
import type { RenderableElementsMap } from "./types";

View file

@ -6,6 +6,8 @@ import type {
NonDeletedSceneElementsMap,
} from "@excalidraw/element/types";
import type { MakeBrand } from "@excalidraw/common/utility-types";
import type {
AppClassProperties,
AppState,
@ -17,7 +19,6 @@ import type {
Device,
PendingExcalidrawElements,
} from "../types";
import type { MakeBrand } from "../utility-types";
import type { RoughCanvas } from "roughjs/bin/canvas";
import type { Drawable } from "roughjs/bin/core";

View file

@ -4,13 +4,14 @@ import { deepCopyElement, newElementWith } from "@excalidraw/element";
import type { OrderedExcalidrawElement } from "@excalidraw/element/types";
import type { ValueOf } from "@excalidraw/common/utility-types";
import { getDefaultAppState } from "./appState";
import { AppStateChange, ElementsChange } from "./change";
import { Emitter } from "./emitter";
import type { AppState, ObservedAppState } from "./types";
import type { ValueOf } from "./utility-types";
// hidden non-enumerable property for runtime checks
const hiddenObservedAppStateProp = "__observedAppState";

View file

@ -22,6 +22,8 @@ import { isLinearElementType } from "@excalidraw/element/typeChecks";
import { getSelectedElements } from "@excalidraw/excalidraw/scene/selection";
import { assertNever } from "@excalidraw/common";
import { selectGroupsForSelectedElements } from "@excalidraw/element/groups";
import type {
ExcalidrawElement,
ExcalidrawGenericElement,
@ -38,7 +40,8 @@ import type {
FixedSegment,
} from "@excalidraw/element/types";
import { selectGroupsForSelectedElements } from "../../groups";
import type { Mutable } from "@excalidraw/common/utility-types";
import { getMimeType } from "../../data/blob";
import { createTestHook } from "../../components/App";
import { getDefaultAppState } from "../../appState";
@ -47,7 +50,7 @@ import { GlobalTestState, createEvent, fireEvent, act } from "../test-utils";
import type { Action } from "../../actions/types";
import type App from "../../components/App";
import type { AppState } from "../../types";
import type { Mutable } from "../../utility-types";
const readFile = util.promisify(fs.readFile);
// so that window.h is available when App.tsx is not imported as well.

View file

@ -13,6 +13,8 @@ import { ORIG_ID, arrayToMap } from "@excalidraw/common";
import type { ExcalidrawElement } from "@excalidraw/element/types";
import type { AllPossibleKeys } from "@excalidraw/common/utility-types";
import { STORAGE_KEYS } from "../../../excalidraw-app/app_constants";
import { getSelectedElements } from "../scene/selection";
@ -23,8 +25,6 @@ import type { RenderResult, RenderOptions } from "@testing-library/react";
import type { ImportedDataState } from "../data/types";
import type { AllPossibleKeys } from "../utility-types";
export { cleanup as unmountComponent };
const customQueries = {

View file

@ -36,6 +36,13 @@ import type {
ExcalidrawNonSelectionElement,
} from "@excalidraw/element/types";
import type {
Merge,
MaybePromise,
ValueOf,
MakeBrand,
} from "@excalidraw/common/utility-types";
import type { Action } from "./actions/types";
import type { Spreadsheet } from "./charts";
import type { ClipboardData } from "./clipboard";
@ -44,7 +51,6 @@ import type Library from "./data/library";
import type { FileSystemHandle } from "./data/filesystem";
import type { ContextMenuItems } from "./components/ContextMenu";
import type { SnapLine } from "./snapping";
import type { Merge, MaybePromise, ValueOf, MakeBrand } from "./utility-types";
import type { CaptureUpdateActionType } from "./store";
import type { ImportedDataState } from "./data/types";