diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.md index fb4068d92d..2fad134f98 100644 --- a/packages/excalidraw/CHANGELOG.md +++ b/packages/excalidraw/CHANGELOG.md @@ -13,6 +13,13 @@ Please add the latest change on the top under the correct section. ## Unreleased +### Minimap, zoom menu and `ui.disabled` (2026-11-12) [#12605](https://github.com/excalidraw/excalidraw/pull/12605), [#12606](https://github.com/excalidraw/excalidraw/pull/12606) + +- A toggleable minimap above the bottom-left canvas actions: drag its viewport (or press outside of it) to pan, wheel over it to zoom. Toggled from the footer button next to the zoom level, the Preferences menu, the command palette and the context menu; stored as `appState.minimapEnabled` (in the browser, not in exported files). Not shown on phones or in editors shorter than 500px. +- The zoom out / zoom in buttons are replaced by a zoom menu on the zoom level (zoom in and out, zoom to fit, zoom to selection, reset zoom), sharing the footer island with the minimap toggle. The zoom in, zoom out and reset zoom actions are unchanged. +- New `ui={{ disabled: { minimap: true } }}`, the opt-out form of the `ui` prop: the full default UI minus the listed controls. It removes the minimap and every way to toggle it. +- Without the minimap toggle (`ui.disabled.minimap`, or the reduced UI of `ui={{ enabled: { zoom: true } }}`), the zoom controls stay the zoom out / zoom level / zoom in buttons. + ### Arrows aren't clipped to frames (2026-10-31) [#12516](https://github.com/excalidraw/excalidraw/pull/12516) - Arrows and their labels are no longer clipped to the frame they belong to, so they can connect elements across and out of frames, and their part outside the frame can be selected. They still belong to their frame, so they're moved, copied and deleted with it, but only while one of their ends is in it (bound to an element in the frame, or inside it). An arrow whose ends both leave its frame (moved, bound to elements outside it, or with the elements it's bound to) leaves the frame. diff --git a/packages/excalidraw/actions/actionCanvas.tsx b/packages/excalidraw/actions/actionCanvas.tsx index 7732e9c971..d8babe8184 100644 --- a/packages/excalidraw/actions/actionCanvas.tsx +++ b/packages/excalidraw/actions/actionCanvas.tsx @@ -1,5 +1,7 @@ import { DEFAULT_CANVAS_BACKGROUND_PICKS, + MAX_ZOOM, + MIN_ZOOM, THEME, ZOOM_STEP, CODES, @@ -16,6 +18,8 @@ import type { Bounds } from "@excalidraw/common"; import { getDefaultAppState } from "../appState"; import { ColorPicker } from "../components/ColorPicker/ColorPicker"; +import { IconButton } from "../components/IconButton"; +import { Tooltip } from "../components/Tooltip"; import { MoonIcon, SunIcon, @@ -25,6 +29,7 @@ import { ZoomOutIcon, ZoomResetIcon, } from "../components/icons"; +import { useAppStateValue } from "../hooks/useAppStateValue"; import { t } from "../i18n"; import { getNormalizedZoom } from "../scene"; @@ -33,6 +38,7 @@ import { getViewportForZoomWithScrollConstraints, zoomToFitBounds, } from "../viewport"; +import { getShortcutKey } from "../shortcut"; import { register } from "./register"; @@ -146,6 +152,29 @@ export const actionZoomIn = register({ captureUpdate: CaptureUpdateAction.EVENTUALLY, }; }, + PanelComponent: ({ updateData }) => { + const zoomValue = useAppStateValue((appState) => appState.zoom.value); + return ( + + = MAX_ZOOM} + onClick={() => { + updateData(null); + }} + /> + + ); + }, keyTest: (event) => (event.code === CODES.EQUAL || event.code === CODES.NUM_ADD) && (event[KEYS.CTRL_OR_CMD] || event.shiftKey), @@ -177,6 +206,29 @@ export const actionZoomOut = register({ captureUpdate: CaptureUpdateAction.EVENTUALLY, }; }, + PanelComponent: ({ updateData }) => { + const zoomValue = useAppStateValue((appState) => appState.zoom.value); + return ( + + { + updateData(null); + }} + /> + + ); + }, keyTest: (event) => (event.code === CODES.MINUS || event.code === CODES.NUM_SUBTRACT) && (event[KEYS.CTRL_OR_CMD] || event.shiftKey), @@ -213,6 +265,28 @@ export const actionResetZoom = register({ captureUpdate: CaptureUpdateAction.EVENTUALLY, }; }, + PanelComponent: ({ updateData }) => { + const zoomValue = useAppStateValue((appState) => appState.zoom.value); + return ( + + { + updateData(null); + }} + > + {(zoomValue * 100).toFixed(0)}% + + + ); + }, keyTest: (event) => (event.code === CODES.ZERO || event.code === CODES.NUM_ZERO) && (event[KEYS.CTRL_OR_CMD] || event.shiftKey), diff --git a/packages/excalidraw/actions/actionToggleMinimap.tsx b/packages/excalidraw/actions/actionToggleMinimap.tsx index 6068052f6b..4af1086c84 100644 --- a/packages/excalidraw/actions/actionToggleMinimap.tsx +++ b/packages/excalidraw/actions/actionToggleMinimap.tsx @@ -31,6 +31,9 @@ export const actionToggleMinimap = register({ }, checked: (appState) => appState.minimapEnabled, predicate: (elements, appState, appProps, app) => + // not part of the host's UI (`ui={false}`, `ui.enabled`, or + // `ui.disabled.minimap`) + app.isUIControlEnabled("minimap") && // the minimap lives in the footer, which isn't rendered on phones app.editorInterface.formFactor !== "phone" && appState.height >= MINIMAP_MIN_EDITOR_HEIGHT && diff --git a/packages/excalidraw/components/Actions.scss b/packages/excalidraw/components/Actions.scss index c017684313..47f716844c 100644 --- a/packages/excalidraw/components/Actions.scss +++ b/packages/excalidraw/components/Actions.scss @@ -12,6 +12,7 @@ align-items: center; } +.zoom-button, .undo-redo-buttons button, .minimap-toggle-button { border-radius: 0 !important; @@ -30,6 +31,69 @@ } } +// the zoom out / zoom level / zoom in buttons, shown instead of the zoom menu +// when there's no minimap toggle +.reset-zoom-button { + border-left: 0 !important; + border-right: 0 !important; + padding: 0 0.625rem !important; + width: 3.75rem !important; + justify-content: center; + color: var(--text-primary-color); + + // unlike the other zoom buttons, has no .ToolIcon__icon to show the hover + .zoom-actions &:hover:not(:active) { + background-color: var(--button-hover-bg); + } +} + +// shifted left in zen mode (the wrapper rather than the button, so that the +// tooltip, positioned off the wrapper, moves along) +.reset-zoom-button-wrapper { + transition: transform var(--zen-mode-transition-duration) ease-in-out; +} + +// faded out in zen mode +.zoom-out-button-wrapper, +.zoom-in-button-wrapper { + transition: opacity var(--zen-mode-transition-duration) ease-in-out, + visibility var(--zen-mode-transition-duration); + + // hidden along with the wrappers, at the end of their fade (see + // styles.scss) + .zoom-button { + transition: visibility var(--zen-mode-transition-duration); + } +} + +.zoom-out-button { + border-top-left-radius: var(--border-radius-lg) !important; + border-bottom-left-radius: var(--border-radius-lg) !important; + + :root[dir="rtl"] & { + transform: scaleX(-1); + } + + .ToolIcon__icon { + border-top-right-radius: 0 !important; + border-bottom-right-radius: 0 !important; + } +} + +.zoom-in-button { + border-top-right-radius: var(--border-radius-lg) !important; + border-bottom-right-radius: var(--border-radius-lg) !important; + + :root[dir="rtl"] & { + transform: scaleX(-1); + } + + .ToolIcon__icon { + border-top-left-radius: 0 !important; + border-bottom-left-radius: 0 !important; + } +} + // the zoom level, opening the zoom menu (overrides the dropdown trigger's // own, outlined look: it's a part of the zoom island) .excalidraw .zoom-actions .zoom-menu-trigger { diff --git a/packages/excalidraw/components/Actions.tsx b/packages/excalidraw/components/Actions.tsx index fbaac85d02..fd595fc832 100644 --- a/packages/excalidraw/components/Actions.tsx +++ b/packages/excalidraw/components/Actions.tsx @@ -886,7 +886,8 @@ export const MobileShapeActions = ({ /** * The zoom level, opening a menu of the zoom actions, along with the minimap - * toggle. + * toggle. Without the minimap toggle (removed by the host's `ui` config), the + * zoom out / zoom level (resetting it) / zoom in buttons instead. */ export const ZoomActions = ({ actionManager, @@ -900,7 +901,16 @@ export const ZoomActions = ({ zenModeEnabled: boolean; }) => (
- {zoomUIEnabled && } + {zoomUIEnabled && + (minimapUIEnabled ? ( + + ) : ( + <> + {actionManager.renderAction("zoomOut")} + {actionManager.renderAction("resetZoom")} + {actionManager.renderAction("zoomIn")} + + ))} {minimapUIEnabled && (
+ typeof ui === "object" && ui !== null; + const AppContext = React.createContext(null!); const AppPropsContext = React.createContext(null!); @@ -1074,23 +1078,32 @@ class App extends React.Component { ); } - /** Whether Excalidraw's full default UI is rendered. */ + /** + * Whether Excalidraw's default UI is rendered (with `ui.disabled`, minus the + * controls it removes). + */ public isDefaultUIEnabled(props: Pick = this.props): boolean { return ( - props.ui !== false && (typeof props.ui !== "object" || props.ui === null) + props.ui !== false && !(isUIConfig(props.ui) && "enabled" in props.ui) ); } /** Whether an individual default UI control is rendered. */ - public isUIControlEnabled( - control: keyof UIConfig["enabled"], + public isUIControlEnabled = ( + control: UIControl, props: Pick = this.props, - ): boolean { - if (typeof props.ui === "object" && props.ui !== null) { - return props.ui.enabled?.[control] === true; + ): boolean => { + if (isUIConfig(props.ui)) { + return "enabled" in props.ui + ? (props.ui.enabled as Partial>)?.[ + control + ] === true + : (props.ui.disabled as Partial>)?.[ + control + ] !== true; } return props.ui !== false; - } + }; updateEditorAtom = ( atom: WritableAtom, diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsx index d07e68ec6b..f6efe133aa 100644 --- a/packages/excalidraw/components/LayerUI.tsx +++ b/packages/excalidraw/components/LayerUI.tsx @@ -243,8 +243,7 @@ const LayerUI = ({ ); }; - const minimapUIEnabled = - defaultUIEnabled && actionManager.isActionEnabled(actionToggleMinimap); + const minimapUIEnabled = actionManager.isActionEnabled(actionToggleMinimap); const renderCanvasActions = () => (
diff --git a/packages/excalidraw/css/styles.scss b/packages/excalidraw/css/styles.scss index 798a2b5ef8..7a7c4b8d1d 100644 --- a/packages/excalidraw/css/styles.scss +++ b/packages/excalidraw/css/styles.scss @@ -643,6 +643,10 @@ body.excalidraw-cursor-resize * { } } + .reset-zoom-button { + font-family: var(--ui-font); + } + .finalize-button { display: grid; grid-auto-flow: column; @@ -720,6 +724,35 @@ body.excalidraw-cursor-resize * { background-color: transparent !important; } } + + // zoom buttons (no zoom menu): only show the zoom level (fade out in + // place, same as other zen-hidden UI). Hides the tooltip wrappers so they + // don't show tooltips either. + .zoom-out-button-wrapper, + .zoom-in-button-wrapper { + opacity: 0; + visibility: hidden; + pointer-events: none; + + // the buttons set their own `visibility: visible` + // (.ToolIcon_type_button--show), which would keep them focusable + .zoom-button { + visibility: hidden; + } + } + + .reset-zoom-button { + border-radius: var(--border-radius-lg) !important; + } + + // shift into the hidden zoom-out button's place + .reset-zoom-button-wrapper { + transform: translateX(calc(-1 * var(--lg-button-size))); + + :root[dir="rtl"] & { + transform: translateX(var(--lg-button-size)); + } + } } // fade the chrome in/out only while toggling zen mode (see diff --git a/packages/excalidraw/index.tsx b/packages/excalidraw/index.tsx index 01636ba107..44df155558 100644 --- a/packages/excalidraw/index.tsx +++ b/packages/excalidraw/index.tsx @@ -40,6 +40,7 @@ import type { AppState, ExcalidrawImperativeAPI, ExcalidrawProps, + UIConfig, } from "./types"; polyfill(); @@ -268,6 +269,22 @@ const ExcalidrawBase = (props: ExcalidrawProps) => { ); }; +/** Same form (`enabled` or `disabled`), with the same controls in it. */ +const isUIConfigSame = (prev: UIConfig, next: UIConfig) => { + const getControls = (config: UIConfig) => + ("enabled" in config ? config.enabled : config.disabled) as + | Record + | undefined; + if ("enabled" in prev !== "enabled" in next) { + return false; + } + const prevControls = getControls(prev) ?? {}; + const nextControls = getControls(next) ?? {}; + return [ + ...new Set([...Object.keys(prevControls), ...Object.keys(nextControls)]), + ].every((control) => !!prevControls[control] === !!nextControls[control]); +}; + const areEqual = (prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => { // short-circuit early if (prevProps.children !== nextProps.children) { @@ -339,9 +356,7 @@ const areEqual = (prevProps: ExcalidrawProps, nextProps: ExcalidrawProps) => { prevUI !== null && typeof nextUI === "object" && nextUI !== null && - !!prevUI.enabled?.zoom === !!nextUI.enabled?.zoom && - !!prevUI.enabled?.scrollBackToContent === - !!nextUI.enabled?.scrollBackToContent); + isUIConfigSame(prevUI, nextUI)); if (!isUISame) { return false; diff --git a/packages/excalidraw/tests/minimap.test.tsx b/packages/excalidraw/tests/minimap.test.tsx index e7350951c7..131f933c92 100644 --- a/packages/excalidraw/tests/minimap.test.tsx +++ b/packages/excalidraw/tests/minimap.test.tsx @@ -3,6 +3,7 @@ import { vi } from "vitest"; import { THEME, viewportCoordsToSceneCoords } from "@excalidraw/common"; +import { actionToggleMinimap } from "../actions"; import { Excalidraw } from "../index"; import { AnimationController } from "../renderer/animation"; @@ -98,6 +99,24 @@ describe("minimap", () => { }); }); + it("is removed with every way to toggle it by ui.disabled.minimap", async () => { + await render( + , + ); + + expect(getMinimap()).toBe(null); + expect(document.querySelector("[data-testid='button-minimap']")).toBe(null); + // the Preferences item, command palette and context menu go by it + expect(h.app.actionManager.isActionEnabled(actionToggleMinimap)).toBe( + false, + ); + // the rest of the default UI stays + expect(document.querySelector(".main-menu-trigger")).not.toBe(null); + }); + it("is toggled by the footer button", async () => { await render(); diff --git a/packages/excalidraw/tests/zoomMenu.test.tsx b/packages/excalidraw/tests/zoomMenu.test.tsx index 5621214737..b8d8b9fe06 100644 --- a/packages/excalidraw/tests/zoomMenu.test.tsx +++ b/packages/excalidraw/tests/zoomMenu.test.tsx @@ -67,4 +67,29 @@ describe("zoom menu", () => { expect(getTrigger().textContent).toBe("110%"); expect(getMenu()).toBe(null); }); + + it.each([ + ["the reduced UI", { enabled: { zoom: true } }], + ["ui.disabled.minimap", { disabled: { minimap: true } }], + ] as const)( + "is replaced by the zoom buttons without the minimap toggle (%s)", + async (_, ui) => { + await render(); + + expect(getTrigger()).toBe(null); + const getResetButton = () => + document.querySelector(".reset-zoom-button")!; + expect(getResetButton().textContent).toBe("100%"); + + fireEvent.click(document.querySelector(".zoom-in-button")!); + expect(getResetButton().textContent).toBe("110%"); + + fireEvent.click(document.querySelector(".zoom-out-button")!); + fireEvent.click(document.querySelector(".zoom-out-button")!); + expect(getResetButton().textContent).toBe("90%"); + + fireEvent.click(getResetButton()); + expect(h.state.zoom.value).toBe(1); + }, + ); }); diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts index e0f0357621..2824933366 100644 --- a/packages/excalidraw/types.ts +++ b/packages/excalidraw/types.ts @@ -800,26 +800,52 @@ export type InteractionConfig = { }; }; -export type UIConfig = { - /** - * Default UI controls that stay enabled while the rest of Excalidraw's - * default UI is hidden. Opt-in: anything omitted or `false` is disabled. - */ - enabled: { - /** - * The zoom-out, reset-zoom, and zoom-in controls. - * - * @default false - */ - zoom?: boolean; - /** - * The button shown when the viewport is scrolled away from all content. - * - * @default false - */ - scrollBackToContent?: boolean; - }; -}; +export type UIConfig = + | { + /** + * Default UI controls that stay enabled while the rest of Excalidraw's + * default UI is hidden. Opt-in: anything omitted or `false` is + * disabled. + */ + enabled: { + /** + * The zoom controls (zoom out, the zoom level resetting it, zoom in). + * + * @default false + */ + zoom?: boolean; + /** + * The button shown when the viewport is scrolled away from all + * content. + * + * @default false + */ + scrollBackToContent?: boolean; + }; + } + | { + /** + * Default UI controls that are removed while the rest of Excalidraw's + * default UI is rendered. Opt-out: anything omitted or `false` stays. + */ + disabled: { + /** + * The minimap, and every way to toggle it (its footer button, the + * Preferences menu item, and the command palette and context menu + * entries). Without the minimap toggle next to them, the zoom + * controls are the zoom out / zoom level / zoom in buttons instead of + * the zoom menu. + * + * @default false + */ + minimap?: boolean; + }; + }; + +/** A default UI control that `UIConfig` can keep or remove. */ +export type UIControl = + | keyof Extract["enabled"] + | keyof Extract["disabled"]; /** Supported visual changes. Geometry, content, bindings and styles are not overridable. */ export type ElementRenderOverride = Readonly<{ @@ -988,10 +1014,12 @@ export interface ExcalidrawProps { * `false`. * * Pass a config object to keep specific default controls rendered while the - * rest of the default UI is hidden (see `UIConfig`): + * rest of the default UI is hidden, or to remove specific controls from the + * otherwise full default UI (see `UIConfig`): * * ```tsx * + * * ``` * * NOTE: this is WIP and what default UI is/is not rendered when ui=false @@ -1280,6 +1308,7 @@ export type AppClassProperties = { isInteractionEnabled: App["isInteractionEnabled"]; isNavigationEnabled: App["isNavigationEnabled"]; + isUIControlEnabled: App["isUIControlEnabled"]; }; export type PointerDownState = Readonly<{