Skip to content

Commit

Permalink
Merge branch 'arnost/jotai-upgrade' of https://github.com/excalidraw/…
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Jan 16, 2025
2 parents e309037 + afaf86e commit 56f9d18
Show file tree
Hide file tree
Showing 32 changed files with 93 additions and 101 deletions.
2 changes: 1 addition & 1 deletion excalidraw-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ const ExcalidrawApp = () => {

return (
<TopErrorBoundary>
<Provider unstable_createStore={() => appJotaiStore}>
<Provider store={appJotaiStore}>
<ExcalidrawWrapper />
</Provider>
</TopErrorBoundary>
Expand Down
4 changes: 2 additions & 2 deletions excalidraw-app/app-jotai.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { unstable_createStore } from "jotai";
import { createStore } from "jotai";

export const appJotaiStore = unstable_createStore();
export const appJotaiStore = createStore();
2 changes: 1 addition & 1 deletion excalidraw-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"firebase": "8.3.3",
"i18next-browser-languagedetector": "6.1.4",
"idb-keyval": "6.0.3",
"jotai": "1.13.1",
"jotai": "2.11.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"socket.io-client": "4.7.2",
Expand Down
5 changes: 2 additions & 3 deletions packages/excalidraw/components/ActiveConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { atom, useAtom } from "jotai";
import { atom } from "jotai";
import { actionClearCanvas } from "../actions";
import { t } from "../i18n";
import { jotaiScope } from "../jotai";
import { useAtom } from "../jotai";
import { useExcalidrawActionManager } from "./App";
import ConfirmDialog from "./ConfirmDialog";

Expand All @@ -10,7 +10,6 @@ export const activeConfirmDialogAtom = atom<"clearCanvas" | null>(null);
export const ActiveConfirmDialog = () => {
const [activeConfirmDialog, setActiveConfirmDialog] = useAtom(
activeConfirmDialogAtom,
jotaiScope,
);
const actionManager = useExcalidrawActionManager();

Expand Down
8 changes: 2 additions & 6 deletions packages/excalidraw/components/ColorPicker/ColorInput.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { getColor } from "./ColorPicker";
import { useAtom } from "jotai";
import type { ColorPickerType } from "./colorPickerUtils";
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
import { eyeDropperIcon } from "../icons";
import { jotaiScope } from "../../jotai";
import { useAtom } from "../../jotai";
import { KEYS } from "../../keys";
import { activeEyeDropperAtom } from "../EyeDropper";
import clsx from "clsx";
Expand Down Expand Up @@ -57,10 +56,7 @@ export const ColorInput = ({
}
}, [activeSection]);

const [eyeDropperState, setEyeDropperState] = useAtom(
activeEyeDropperAtom,
jotaiScope,
);
const [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom);

useEffect(() => {
return () => {
Expand Down
8 changes: 2 additions & 6 deletions packages/excalidraw/components/ColorPicker/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { TopPicks } from "./TopPicks";
import { ButtonSeparator } from "../ButtonSeparator";
import { Picker } from "./Picker";
import * as Popover from "@radix-ui/react-popover";
import { useAtom } from "jotai";
import type { ColorPickerType } from "./colorPickerUtils";
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
import { useExcalidrawContainer } from "../App";
Expand All @@ -15,7 +14,7 @@ import PickerHeading from "./PickerHeading";
import { t } from "../../i18n";
import clsx from "clsx";
import { useRef } from "react";
import { jotaiScope } from "../../jotai";
import { useAtom } from "../../jotai";
import { ColorInput } from "./ColorInput";
import { activeEyeDropperAtom } from "../EyeDropper";
import { PropertiesPopover } from "../PropertiesPopover";
Expand Down Expand Up @@ -76,10 +75,7 @@ const ColorPickerPopupContent = ({
const { container } = useExcalidrawContainer();
const [, setActiveColorPickerSection] = useAtom(activeColorPickerSectionAtom);

const [eyeDropperState, setEyeDropperState] = useAtom(
activeEyeDropperAtom,
jotaiScope,
);
const [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom);

const colorInputJSX = (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from "clsx";
import { useAtom } from "jotai";
import { useAtom } from "../../jotai";
import { useEffect, useRef } from "react";
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
import HotkeyLabel from "./HotkeyLabel";
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/components/ColorPicker/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ExcalidrawElement } from "../../element/types";
import { ShadeList } from "./ShadeList";

import PickerColorList from "./PickerColorList";
import { useAtom } from "jotai";
import { useAtom } from "../../jotai";
import { CustomColorList } from "./CustomColorList";
import { colorPickerKeyNavHandler } from "./keyboardNavHandlers";
import PickerHeading from "./PickerHeading";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from "clsx";
import { useAtom } from "jotai";
import { useAtom } from "../../jotai";
import { useEffect, useRef } from "react";
import {
activeColorPickerSectionAtom,
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/components/ColorPicker/ShadeList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from "clsx";
import { useAtom } from "jotai";
import { useAtom } from "../../jotai";
import { useEffect, useRef } from "react";
import {
activeColorPickerSectionAtom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import {
getShortcutKey,
isWritableElement,
} from "../../utils";
import { atom, useAtom } from "jotai";
import { atom } from "jotai";
import { useAtom } from "../../jotai";
import { deburr } from "../../deburr";
import type { MarkRequired } from "../../utility-types";
import { InlineIcon } from "../InlineIcon";
Expand Down
5 changes: 2 additions & 3 deletions packages/excalidraw/components/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Dialog } from "./Dialog";

import "./ConfirmDialog.scss";
import DialogActionButton from "./DialogActionButton";
import { useSetAtom } from "jotai";
import { isLibraryMenuOpenAtom } from "./LibraryMenu";
import { useExcalidrawContainer, useExcalidrawSetAppState } from "./App";
import { jotaiScope } from "../jotai";
import { useSetAtom } from "../jotai";

interface Props extends Omit<DialogProps, "onCloseRequest"> {
onConfirm: () => void;
Expand All @@ -27,7 +26,7 @@ const ConfirmDialog = (props: Props) => {
...rest
} = props;
const setAppState = useExcalidrawSetAppState();
const setIsLibraryMenuOpen = useSetAtom(isLibraryMenuOpenAtom, jotaiScope);
const setIsLibraryMenuOpen = useSetAtom(isLibraryMenuOpenAtom);
const { container } = useExcalidrawContainer();

return (
Expand Down
5 changes: 2 additions & 3 deletions packages/excalidraw/components/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import "./Dialog.scss";
import { Island } from "./Island";
import { Modal } from "./Modal";
import { queryFocusableElements } from "../utils";
import { useSetAtom } from "jotai";
import { isLibraryMenuOpenAtom } from "./LibraryMenu";
import { jotaiScope } from "../jotai";
import { useSetAtom } from "../jotai";
import { t } from "../i18n";
import { CloseIcon } from "./icons";

Expand Down Expand Up @@ -92,7 +91,7 @@ export const Dialog = (props: DialogProps) => {
}, [islandNode, props.autofocus]);

const setAppState = useExcalidrawSetAppState();
const setIsLibraryMenuOpen = useSetAtom(isLibraryMenuOpenAtom, jotaiScope);
const setIsLibraryMenuOpen = useSetAtom(isLibraryMenuOpenAtom);

const onClose = () => {
setAppState({ openMenu: null });
Expand Down
9 changes: 3 additions & 6 deletions packages/excalidraw/components/IconPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { isArrowKey, KEYS } from "../keys";
import { getLanguage, t } from "../i18n";
import clsx from "clsx";
import Collapsible from "./Stats/Collapsible";
import { atom, useAtom } from "jotai";
import { jotaiScope } from "../jotai";
import { atom } from "jotai";
import { useAtom } from "../jotai";
import { useDevice } from "..";

const moreOptionsAtom = atom(false);
Expand Down Expand Up @@ -94,10 +94,7 @@ function Picker<T>({
event.stopPropagation();
};

const [showMoreOptions, setShowMoreOptions] = useAtom(
moreOptionsAtom,
jotaiScope,
);
const [showMoreOptions, setShowMoreOptions] = useAtom(moreOptionsAtom);

const alwaysVisibleOptions = React.useMemo(
() => options.slice(0, numberOfOptionsToAlwaysShow),
Expand Down
16 changes: 7 additions & 9 deletions packages/excalidraw/components/LayerUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import { trackEvent } from "../analytics";
import { useDevice } from "./App";
import Footer from "./footer/Footer";
import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
import { jotaiScope } from "../jotai";
import { Provider, useAtom, useAtomValue } from "jotai";
import { useAtom, useAtomValue } from "../jotai";
import MainMenu from "./main-menu/MainMenu";
import { ActiveConfirmDialog } from "./ActiveConfirmDialog";
import { OverwriteConfirmDialog } from "./OverwriteConfirm/OverwriteConfirm";
Expand Down Expand Up @@ -152,10 +151,9 @@ const LayerUI = ({
const device = useDevice();
const tunnels = useInitializeTunnels();

const [eyeDropperState, setEyeDropperState] = useAtom(
activeEyeDropperAtom,
jotaiScope,
);
const TunnelsProvider = tunnels.jotai.Provider;

const [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom);

const renderJSONExportDialog = () => {
if (!UIOptions.canvasActions.export) {
Expand Down Expand Up @@ -386,7 +384,7 @@ const LayerUI = ({
);
};

const isSidebarDocked = useAtomValue(isSidebarDockedAtom, jotaiScope);
const isSidebarDocked = useAtomValue(isSidebarDockedAtom);

if (uiDisabled) {
return null;
Expand Down Expand Up @@ -575,11 +573,11 @@ const LayerUI = ({

return (
<UIAppStateContext.Provider value={appState}>
<Provider scope={tunnels.jotaiScope}>
<TunnelsProvider>
<TunnelsContext.Provider value={tunnels}>
{layerUIJSX}
</TunnelsContext.Provider>
</Provider>
</TunnelsProvider>
</UIAppStateContext.Provider>
);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/excalidraw/components/LibraryMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import type {
} from "../types";
import LibraryMenuItems from "./LibraryMenuItems";
import { trackEvent } from "../analytics";
import { atom, useAtom } from "jotai";
import { jotaiScope } from "../jotai";
import { atom } from "jotai";
import { useAtom } from "../jotai";
import Spinner from "./Spinner";
import {
useApp,
Expand Down Expand Up @@ -61,7 +61,7 @@ export const LibraryMenuContent = ({
selectedItems: LibraryItem["id"][];
onSelectItems: (id: LibraryItem["id"][]) => void;
}) => {
const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
const [libraryItemsData] = useAtom(libraryItemsAtom);

const _onAddToLibrary = useCallback(
(elements: LibraryItem["elements"]) => {
Expand Down
8 changes: 3 additions & 5 deletions packages/excalidraw/components/LibraryMenuHeaderContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from "react";
import { t } from "../i18n";
import Trans from "./Trans";
import { jotaiScope } from "../jotai";
import { useAtom } from "../jotai";
import type { LibraryItem, LibraryItems, UIAppState } from "../types";
import { useApp, useExcalidrawSetAppState } from "./App";
import { saveLibraryAsJSON } from "../data/json";
Expand All @@ -17,7 +17,6 @@ import {
import { ToolButton } from "./ToolButton";
import { fileOpen } from "../data/filesystem";
import { muteFSAbortError } from "../utils";
import { useAtom } from "jotai";
import ConfirmDialog from "./ConfirmDialog";
import PublishLibrary from "./PublishLibrary";
import { Dialog } from "./Dialog";
Expand Down Expand Up @@ -51,10 +50,9 @@ export const LibraryDropdownMenuButton: React.FC<{
appState,
className,
}) => {
const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
const [libraryItemsData] = useAtom(libraryItemsAtom);
const [isLibraryMenuOpen, setIsLibraryMenuOpen] = useAtom(
isLibraryMenuOpenAtom,
jotaiScope,
);

const renderRemoveLibAlert = () => {
Expand Down Expand Up @@ -286,7 +284,7 @@ export const LibraryDropdownMenu = ({
const appState = useUIAppState();
const setAppState = useExcalidrawSetAppState();

const [libraryItemsData] = useAtom(libraryItemsAtom, jotaiScope);
const [libraryItemsData] = useAtom(libraryItemsAtom);

const removeFromLibrary = async (libraryItems: LibraryItems) => {
const nextItems = libraryItems.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react";
import { useAtom } from "jotai";

import { useTunnels } from "../../context/tunnels";
import { jotaiScope } from "../../jotai";
import { useAtom } from "../../jotai";
import { Dialog } from "../Dialog";
import { withInternalFallback } from "../hoc/withInternalFallback";
import { overwriteConfirmStateAtom } from "./OverwriteConfirmState";
Expand All @@ -23,7 +22,6 @@ const OverwriteConfirmDialog = Object.assign(
const { OverwriteConfirmDialogTunnel } = useTunnels();
const [overwriteConfirmState, setState] = useAtom(
overwriteConfirmStateAtom,
jotaiScope,
);

if (!overwriteConfirmState.active) {
Expand Down
11 changes: 4 additions & 7 deletions packages/excalidraw/components/SearchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { measureText } from "../element/textElement";
import { addEventListener, getFontString } from "../utils";
import { KEYS } from "../keys";
import clsx from "clsx";
import { atom, useAtom } from "jotai";
import { jotaiScope } from "../jotai";
import { atom } from "jotai";
import { useAtom } from "../jotai";
import { t } from "../i18n";
import { isElementCompletelyInViewport } from "../element/sizeHelpers";
import { randomInteger } from "../random";
Expand Down Expand Up @@ -58,7 +58,7 @@ export const SearchMenu = () => {

const searchInputRef = useRef<HTMLInputElement>(null);

const [inputValue, setInputValue] = useAtom(searchQueryAtom, jotaiScope);
const [inputValue, setInputValue] = useAtom(searchQueryAtom);
const searchQuery = inputValue.trim() as SearchQuery;

const [isSearching, setIsSearching] = useState(false);
Expand All @@ -70,10 +70,7 @@ export const SearchMenu = () => {
const searchedQueryRef = useRef<SearchQuery | null>(null);
const lastSceneNonceRef = useRef<number | undefined>(undefined);

const [focusIndex, setFocusIndex] = useAtom(
searchItemInFocusAtom,
jotaiScope,
);
const [focusIndex, setFocusIndex] = useAtom(searchItemInFocusAtom);
const elementsMap = app.scene.getNonDeletedElementsMap();

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions packages/excalidraw/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React, {
useCallback,
} from "react";
import { Island } from "../Island";
import { atom, useSetAtom } from "jotai";
import { jotaiScope } from "../../jotai";
import { atom } from "jotai";
import { useSetAtom } from "../../jotai";
import type { SidebarProps, SidebarPropsContextValue } from "./common";
import { SidebarPropsContext } from "./common";
import { SidebarHeader } from "./SidebarHeader";
Expand Down Expand Up @@ -58,7 +58,7 @@ export const SidebarInner = forwardRef(

const setAppState = useExcalidrawSetAppState();

const setIsSidebarDockedAtom = useSetAtom(isSidebarDockedAtom, jotaiScope);
const setIsSidebarDockedAtom = useSetAtom(isSidebarDockedAtom);

useLayoutEffect(() => {
setIsSidebarDockedAtom(!!docked);
Expand Down
3 changes: 2 additions & 1 deletion packages/excalidraw/components/TTDDialog/TTDDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import type { BinaryFiles } from "../../types";
import { ArrowRightIcon } from "../icons";

import "./TTDDialog.scss";
import { atom, useAtom } from "jotai";
import { atom } from "jotai";
import { useAtom } from "../../jotai";
import { trackEvent } from "../../analytics";
import { InlineIcon } from "../InlineIcon";
import { TTDDialogSubmitShortcut } from "./TTDDialogSubmitShortcut";
Expand Down
Loading

0 comments on commit 56f9d18

Please sign in to comment.