Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

feat(editor): customizing color top picks (#11872)

David Luzarabeeaeba217a
diff --git a/packages/common/src/colors.ts b/packages/common/src/colors.ts
index fa674fc6f8..d067a5bcca 100644
--- a/packages/common/src/colors.ts
+++ b/packages/common/src/colors.ts
@@ -230,6 +230,11 @@ const COMMON_ELEMENT_SHADES = pick(COLOR_PALETTE, [
// quick picks defaults
// -----------------------------------------------------------------------------
+/** number of slots in the color-picker top-picks strip — the strip layout is
+ * sized for exactly this many swatches, and pick customization (replace /
+ * reorder) preserves it */
+export const COLOR_TOP_PICKS_SLOTS = 5;
+
// ORDER matters for positioning in quick picker
export const DEFAULT_ELEMENT_STROKE_PICKS = [
COLOR_PALETTE.black,
diff --git a/packages/excalidraw/actions/actionCanvas.tsx b/packages/excalidraw/actions/actionCanvas.tsx
index eded7e9ade..c87d3ddfac 100644
--- a/packages/excalidraw/actions/actionCanvas.tsx
+++ b/packages/excalidraw/actions/actionCanvas.tsx
@@ -111,6 +111,7 @@ export const actionClearCanvas = register({
gridStep: appState.gridStep,
gridModeEnabled: appState.gridModeEnabled,
stats: appState.stats,
+ colorTopPicks: appState.colorTopPicks,
activeTool:
appState.activeTool.type === "image"
? {
diff --git a/packages/excalidraw/actions/actionProperties.tsx b/packages/excalidraw/actions/actionProperties.tsx
index 13973804ea..6cfa77290a 100644
--- a/packages/excalidraw/actions/actionProperties.tsx
+++ b/packages/excalidraw/actions/actionProperties.tsx
@@ -381,6 +381,7 @@ export const actionChangeStrokeColor = register<
<ColorPicker
topPicks={DEFAULT_ELEMENT_STROKE_PICKS}
palette={DEFAULT_ELEMENT_STROKE_COLOR_PALETTE}
+ customizableTopPicks="elementStroke"
type="elementStroke"
label={t("labels.stroke")}
color={getFormValue(
@@ -466,6 +467,7 @@ export const actionChangeBackgroundColor = register<
<ColorPicker
topPicks={DEFAULT_ELEMENT_BACKGROUND_PICKS}
palette={DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE}
+ customizableTopPicks="elementBackground"
type="elementBackground"
label={t("labels.background")}
color={getFormValue(
@@ -520,6 +522,10 @@ export const actionChangeBucketFillBackgroundColor = register<
// hidden rather than removed from the palette so the remaining
// colors keep their usual hotkeys (w for white etc.)
excludedColors={[COLOR_PALETTE.transparent]}
+ // customized independently of the background picker's picks even
+ // though both drive `currentItemBackgroundColor` — the bucket
+ // strip's defaults and use case differ (no transparent)
+ customizableTopPicks="bucketFill"
type="elementBackground"
label={t("labels.background")}
color={app.bucketFill.getBucketFillBackgroundColor(
diff --git a/packages/excalidraw/actions/manager.tsx b/packages/excalidraw/actions/manager.tsx
index 75d31e4773..97be812231 100644
--- a/packages/excalidraw/actions/manager.tsx
+++ b/packages/excalidraw/actions/manager.tsx
@@ -192,14 +192,21 @@ export class ActionManager {
const action = this.actions[name];
const PanelComponent = action.PanelComponent!;
PanelComponent.displayName = "PanelComponent";
- const elements = this.getElementsIncludingDeleted();
- const appState = this.getAppState();
const updateData = (formState?: any) => {
if (this.isActionBlockedByViewportTransition(action)) {
return;
}
- trackAction(action, "ui", appState, elements, this.app, formState);
+ // read fresh state at call time — memoized panel children may invoke
+ // an `updateData` closure minted by an earlier render
+ trackAction(
+ action,
+ "ui",
+ this.getAppState(),
+ this.getElementsIncludingDeleted(),
+ this.app,
+ formState,
+ );
this.updater(
action.perform(
diff --git a/packages/excalidraw/appState.ts b/packages/excalidraw/appState.ts
index 91a452e321..2fe4a6801c 100644
--- a/packages/excalidraw/appState.ts
+++ b/packages/excalidraw/appState.ts
@@ -130,6 +130,11 @@ export const getDefaultAppState = (): Omit<
activeLockedId: null,
bindMode: "orbit",
boxSelectionMode: "contain",
+ colorTopPicks: {
+ elementStroke: null,
+ elementBackground: null,
+ bucketFill: null,
+ },
};
};
@@ -261,6 +266,7 @@ const APP_STATE_STORAGE_CONF = (<
lockedMultiSelections: { browser: true, export: true, server: true },
activeLockedId: { browser: false, export: false, server: false },
bindMode: { browser: true, export: false, server: false },
+ colorTopPicks: { browser: true, export: false, server: false },
});
const _clearAppStateForStorage = <
diff --git a/packages/excalidraw/components/ColorPicker/ColorPicker.scss b/packages/excalidraw/components/ColorPicker/ColorPicker.scss
index cd91681912..e33f355c5d 100644
--- a/packages/excalidraw/components/ColorPicker/ColorPicker.scss
+++ b/packages/excalidraw/components/ColorPicker/ColorPicker.scss
@@ -2,6 +2,11 @@
@use "../../css/variables.module" as *;
.excalidraw {
+ --color-outline: var(--color-gray-20);
+ &.theme--dark {
+ --color-outline: var(--color-gray-80);
+ }
+
.focus-visible-none {
&:focus-visible {
outline: none !important;
@@ -20,6 +25,44 @@
text-align: left;
}
+ .color-picker__context-menu {
+ background: var(--popup-bg-color);
+ border-radius: var(--border-radius-lg);
+ box-shadow: var(--shadow-island);
+ padding: 0.25rem;
+ }
+
+ .color-picker__context-menu-item {
+ font-size: 0.75rem;
+ padding: 0.375rem 0.625rem;
+ border-radius: var(--border-radius-md);
+ color: var(--text-primary-color);
+ cursor: pointer;
+ outline: none;
+ user-select: none;
+
+ // :hover as well — radix only sets data-highlighted once the item gets
+ // focus via pointermove, which leaves dead frames (e.g. menu opening
+ // under a stationary cursor)
+ &[data-highlighted],
+ &:not([data-disabled]):hover {
+ background: var(--button-hover-bg);
+ }
+
+ &[data-disabled] {
+ opacity: 0.5;
+ pointer-events: none;
+ }
+ }
+
+ .color-picker__tip {
+ padding: 0 0.5rem;
+ font-size: 0.6875rem;
+ line-height: 1.4;
+ text-align: left;
+ color: var(--color-gray-60);
+ }
+
.color-picker-container {
display: grid;
grid-template-columns: 1fr 20px 1.625rem;
@@ -48,7 +91,7 @@
--size: 1.375rem;
&.has-outline {
- box-shadow: inset 0 0 0 1px #d9d9d9;
+ box-shadow: 0 0 0 1px var(--color-outline);
}
padding: 0;
@@ -57,28 +100,22 @@
height: var(--size);
border: 0;
border-radius: var(--radius);
- filter: var(--theme-filter);
background-color: var(--swatch-color);
background-position: left center;
position: relative;
font-family: inherit;
box-sizing: border-box;
- &:hover:not(.active):not(.color-picker__button--large) {
- transform: scale(1.075);
- }
-
&:hover:not(.active).color-picker__button--large {
- &::after {
- content: "";
- position: absolute;
- top: -1px;
- left: -1px;
- right: -1px;
- bottom: -1px;
- box-shadow: 0 0 0 1px var(--color-gray-30);
- border-radius: var(--radius);
- filter: var(--theme-filter);
+ box-shadow: inset 0 0 0 1px var(--color-primary);
+ }
+ &:active {
+ box-shadow: 0 0 0 1px var(--color-primary) !important;
+ }
+ &:active.color-picker__button--large {
+ box-shadow: none !important;
+ &.has-outline {
+ box-shadow: 0 0 0 1px var(--color-outline) !important;
}
}
@@ -103,7 +140,7 @@
}
}
- &.active {
+ &.active:not(:active) {
.color-picker__button-outline {
position: absolute;
--offset: -1px;
@@ -114,7 +151,6 @@
box-shadow: 0 0 0 1px var(--color-primary-darkest);
z-index: 1; // due hover state so this has preference
border-radius: var(--radius);
- filter: var(--theme-filter);
}
}
@@ -140,7 +176,7 @@
}
&--large {
- --radius: 0.5rem;
+ --radius: 6px;
width: 1.875rem;
height: 1.875rem;
}
@@ -177,10 +213,10 @@
.color-picker__button__hotkey-label {
position: absolute;
- right: 5px;
- bottom: 3px;
- filter: none;
- font-size: 11px;
+ right: 4px;
+ bottom: 2px;
+ font-size: 10px;
+ font-family: monospace;
font-weight: 500;
}
@@ -288,10 +324,6 @@
&-colors {
padding: 0.5rem 0;
-
- .color-picker-swatch {
- margin: 0 0.25rem;
- }
}
}
@@ -299,41 +331,6 @@
grid-column: 1 / span 5;
}
- .color-picker-swatch {
- position: relative;
- height: 1.875rem;
- width: 1.875rem;
- cursor: pointer;
- border-radius: 4px;
- margin: 0;
- box-sizing: border-box;
- border: 1px solid #ddd;
- background-color: currentColor !important;
- filter: var(--theme-filter);
-
- &:focus {
- /* TODO: only show the border when the color is too light to see as a shadow */
- box-shadow: 0 0 4px 1px currentColor;
- border-color: var(--select-highlight-color);
- }
- }
-
- .color-picker-transparent {
- border-radius: 4px;
- box-shadow: color.adjust(#000, $alpha: -0.9) 0 0 0 1px inset;
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- }
-
- .color-picker-transparent,
- .color-picker-label-swatch {
- background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==")
- left center;
- }
-
.color-picker-hash {
height: var(--default-button-size);
flex-shrink: 0;
@@ -445,74 +442,157 @@
}
}
- .color-picker-label-swatch-container {
- border: 1px solid var(--default-border-color);
- border-radius: var(--border-radius-lg);
- width: var(--default-button-size);
- height: var(--default-button-size);
- box-sizing: border-box;
- overflow: hidden;
- }
+ // top-picks drag & drop (pinning + reordering)
+ // ---------------------------------------------------------------------------
- .color-picker-label-swatch {
- @include outlineButtonStyles;
- background-color: var(--swatch-color) !important;
- overflow: hidden;
+ .color-picker__top-picks {
+ // anchor for the animated drop-target outline
position: relative;
- filter: var(--theme-filter);
- border: 0 !important;
+ }
- &:after {
- content: "";
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background: var(--swatch-color);
+ .color-picker__top-picks .color-picker__button {
+ // the strip is tiny and never scrolls — allow touch-dragging picks
+ touch-action: none;
+ }
+
+ .color-picker__top-picks.is-dnd-active {
+ .color-picker__button {
+ // no hover/tooltips while a drag is in flight; hit-testing is
+ // coordinate-based so this doesn't affect dropping
+ pointer-events: none;
+ transition: transform 0.14s ease, opacity 0.14s ease,
+ box-shadow 0.14s ease;
}
}
- .color-picker-keybinding {
+ // "marching ants" outline hinting that the strip accepts the drop —
+ // SVG because CSS dashed outlines/borders can't animate their dash offset
+ .color-picker__top-picks__dnd-outline {
position: absolute;
- bottom: 2px;
- font-size: 0.7em;
+ top: -5px;
+ left: -5px;
+ width: calc(100% + 10px);
+ height: calc(100% + 10px);
+ pointer-events: none;
+ overflow: visible;
+
+ rect {
+ x: 0.5px;
+ y: 0.5px;
+ rx: 6px;
+ width: calc(100% - 1px);
+ height: calc(100% - 1px);
+ fill: none;
+ stroke: var(--color-primary);
+ stroke-width: 1;
+ stroke-dasharray: 4 4;
+ animation: excalidraw-color-dnd-march 0.8s linear infinite;
+
+ @media (prefers-reduced-motion: reduce) {
+ animation: none;
+ }
+ }
+ }
- :root[dir="ltr"] & {
- right: 2px;
+ @keyframes excalidraw-color-dnd-march {
+ to {
+ // one full dash+gap period per cycle → seamless loop
+ stroke-dashoffset: -8;
}
+ }
- :root[dir="rtl"] & {
- left: 2px;
+ // the pick being reordered — its ghost is following the pointer
+ .color-picker__button.is-dnd-source {
+ opacity: 0.3;
+ }
+
+ // slot a dragged swatch would replace
+ .color-picker__button.is-dnd-target {
+ transform: scale(1.2);
+ box-shadow: 0 0 0 1px var(--color-primary-darkest);
+ }
+
+ // this color is already pinned — drop not allowed
+ .color-picker__button.is-dnd-duplicate {
+ animation: excalidraw-color-dnd-duplicate 0.45s ease-in-out infinite
+ alternate;
+ }
+
+ @keyframes excalidraw-color-dnd-duplicate {
+ from {
+ box-shadow: 0 0 0 2px var(--color-danger, #e03131);
+ transform: scale(1);
+ }
+ to {
+ box-shadow: 0 0 0 3px var(--color-danger, #e03131);
+ transform: scale(1.12);
}
+ }
+}
- @include isMobile {
- display: none;
+// drag & drop ghost — appended to document.body (outside the .excalidraw
+// scope) so it can follow the pointer without overflow clipping
+.excalidraw-color-dnd-ghost {
+ position: fixed;
+ top: 0;
+ left: 0;
+ z-index: 10000;
+ pointer-events: none;
+ will-change: transform;
+ // NOTE transform is deliberately not transitioned here (tracks the pointer
+ // every frame); --dropping adds it for the fly-to-target animation
+ transition: width 0.15s ease, height 0.15s ease;
+
+ &__swatch {
+ width: 100%;
+ height: 100%;
+ border-radius: 4px;
+ box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
+ transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
+
+ &.is-transparent {
+ background-color: #fff;
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==");
+ background-position: left center;
}
}
- .color-picker-type-canvasBackground .color-picker-keybinding {
- color: #aaa;
+ &--lifted &__swatch {
+ transform: scale(1.2);
+ box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.08);
}
- .color-picker-type-elementBackground .color-picker-keybinding {
- color: #fff;
+ &--over &__swatch {
+ transform: scale(1.05);
+ box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.08);
}
- .color-picker-swatch[aria-label="transparent"] .color-picker-keybinding {
- color: #aaa;
+ &--blocked &__swatch {
+ opacity: 0.4;
+ transform: scale(0.85);
}
- .color-picker-type-elementStroke .color-picker-keybinding {
- color: #d4d4d4;
+ &--dropping {
+ transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.3, 1), width 0.18s ease,
+ height 0.18s ease;
}
- &.theme--dark {
- .color-picker-type-elementBackground .color-picker-keybinding {
- color: #000;
- }
- .color-picker-swatch[aria-label="transparent"] .color-picker-keybinding {
- color: #000;
- }
+ &--dropping &__swatch {
+ transform: scale(1);
+ box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
+ }
+
+ &--fade &__swatch {
+ opacity: 0;
+ }
+}
+
+body.excalidraw-color-dnd-active {
+ user-select: none !important;
+ -webkit-user-select: none !important;
+
+ &,
+ * {
+ cursor: grabbing !important;
}
}
diff --git a/packages/excalidraw/components/ColorPicker/ColorPicker.tsx b/packages/excalidraw/components/ColorPicker/ColorPicker.tsx
index 9c2697c846..aa65bb8868 100644
--- a/packages/excalidraw/components/ColorPicker/ColorPicker.tsx
+++ b/packages/excalidraw/components/ColorPicker/ColorPicker.tsx
@@ -1,17 +1,21 @@
import { Popover } from "radix-ui";
import clsx from "clsx";
-import { useRef, useEffect } from "react";
+import { memo, useRef, useEffect } from "react";
import {
+ applyDarkModeFilter,
COLOR_OUTLINE_CONTRAST_THRESHOLD,
COLOR_PALETTE,
+ DEFAULT_ELEMENT_BACKGROUND_PICKS,
+ DEFAULT_ELEMENT_STROKE_PICKS,
isColorDark,
isWritableElement,
+ THEME,
} from "@excalidraw/common";
import type { ColorTuple, ColorPaletteCustom } from "@excalidraw/common";
-import type { ExcalidrawElement } from "@excalidraw/element/types";
+import type { ExcalidrawElement, Theme } from "@excalidraw/element/types";
import { useAtom } from "../../editor-jotai";
import { t } from "../../i18n";
@@ -31,6 +35,11 @@ import { Picker } from "./Picker";
import PickerHeading from "./PickerHeading";
import { TopPicks } from "./TopPicks";
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
+import {
+ ColorPickerDnDContext,
+ useColorPickerDnD,
+ useTopPicksDnD,
+} from "./topPicksDnD";
import "./ColorPicker.scss";
@@ -54,6 +63,10 @@ interface ColorPickerProps {
updateData: (formData?: any) => void;
/** palette colors to hide from the popup, keeping hotkey positions */
excludedColors?: readonly string[];
+ /** allow users to customize the top picks strip by drag & dropping colors
+ * from the picker popup onto it. The value names the
+ * `appState.colorTopPicks` slot the customization is stored in */
+ customizableTopPicks?: keyof AppState["colorTopPicks"];
}
const ColorPickerPopupContent = ({
@@ -117,9 +130,32 @@ const ColorPickerPopupContent = ({
// Improve focus handling for text editing scenarios
preventAutoFocusOnTouch={!!appState.editingTextElement}
onFocusOutside={(event) => {
+ // focus moving into the top-picks context menu — let the menu keep
+ // it (stealing it back would clear the menu's focus-driven
+ // `data-highlighted` styling and break its keyboard navigation)
+ if (
+ event.target instanceof HTMLElement &&
+ event.target.closest(".color-picker__context-menu")
+ ) {
+ event.preventDefault();
+ return;
+ }
// refocus due to eye dropper
if (!isWritableElement(event.target)) {
- focusPickerContent();
+ if (
+ event.target instanceof HTMLElement &&
+ event.target.matches(":active")
+ ) {
+ // the focus escaped because a button outside is being pressed
+ // (e.g. a top pick) — stealing focus mid-press makes the browser
+ // drop the button's activation (`:active` styling), so wait for
+ // the release
+ window.addEventListener("pointerup", focusPickerContent, {
+ once: true,
+ });
+ } else {
+ focusPickerContent();
+ }
}
event.preventDefault();
}}
@@ -157,6 +193,7 @@ const ColorPickerPopupContent = ({
palette={palette}
excludedColors={excludedColors}
color={color}
+ theme={appState.theme}
onChange={(changedColor) => {
// Save caret position before color change if editing text
const savedSelection = appState.editingTextElement
@@ -214,10 +251,18 @@ const ColorPickerPopupContent = ({
);
};
+const isColorPickerPopup = (
+ popup: AppState["openPopup"],
+): popup is ColorPickerType =>
+ popup === "elementStroke" ||
+ popup === "elementBackground" ||
+ popup === "canvasBackground";
+
const ColorPickerTrigger = ({
label,
color,
type,
+ theme,
mode = "background",
onToggle,
editingTextElement,
@@ -225,6 +270,7 @@ const ColorPickerTrigger = ({
color: string | null;
label: string;
type: ColorPickerType;
+ theme: Theme;
mode?: "background" | "stroke";
onToggle: () => void;
editingTextElement?: boolean;
@@ -232,6 +278,10 @@ const ColorPickerTrigger = ({
const stylesPanelMode = useStylesPanelMode();
const isCompactMode = stylesPanelMode !== "full";
const isMobileMode = stylesPanelMode === "mobile";
+ const dnd = useColorPickerDnD();
+ const displayColor = color
+ ? applyDarkModeFilter(color, theme === THEME.DARK)
+ : null;
const handleClick = (e: React.MouseEvent) => {
// use pointerdown so we run before outside-close logic
e.preventDefault();
@@ -256,7 +306,7 @@ const ColorPickerTrigger = ({
"mobile-border": isMobileMode,
})}
aria-label={label}
- style={color ? { "--swatch-color": color } : undefined}
+ style={displayColor ? { "--swatch-color": displayColor } : undefined}
title={
type === "elementStroke"
? t("labels.showStroke")
@@ -264,6 +314,11 @@ const ColorPickerTrigger = ({
}
data-openpopup={type}
onClick={handleClick}
+ // the active-color swatch can be dragged onto the top-picks strip to
+ // pin the current (possibly custom) color
+ onPointerDown={
+ dnd ? (event) => dnd.startSwatchDrag(event, color) : undefined
+ }
>
<div className="color-picker__button-outline">{!color && slashIcon}</div>
{isCompactMode && color && mode === "stroke" && (
@@ -271,7 +326,8 @@ const ColorPickerTrigger = ({
<span
style={{
color:
- color && isColorDark(color, COLOR_OUTLINE_CONTRAST_THRESHOLD)
+ displayColor &&
+ isColorDark(displayColor, COLOR_OUTLINE_CONTRAST_THRESHOLD)
? "#fff"
: "#111",
}}
@@ -284,7 +340,7 @@ const ColorPickerTrigger = ({
);
};
-export const ColorPicker = ({
+const ColorPickerComponent = ({
type,
color,
onChange,
@@ -295,6 +351,7 @@ export const ColorPicker = ({
updateData,
appState,
excludedColors,
+ customizableTopPicks,
}: ColorPickerProps) => {
const openRef = useRef(appState.openPopup);
useEffect(() => {
@@ -303,8 +360,43 @@ export const ColorPicker = ({
const stylesPanelMode = useStylesPanelMode();
const isCompactMode = stylesPanelMode !== "full";
+ const isTopPicksCustomizable = !!customizableTopPicks && !isCompactMode;
+
+ // user-pinned picks trump the (host-provided or default) baseline
+ const customTopPicks =
+ isTopPicksCustomizable && customizableTopPicks
+ ? appState.colorTopPicks?.[customizableTopPicks]
+ : null;
+
+ // fully-resolved picks currently displayed in the strip — the baseline the
+ // drag & drop customization starts from
+ const effectiveTopPicks = customTopPicks?.length
+ ? customTopPicks
+ : topPicks ??
+ (type === "elementStroke"
+ ? DEFAULT_ELEMENT_STROKE_PICKS
+ : DEFAULT_ELEMENT_BACKGROUND_PICKS);
+
+ const dnd = useTopPicksDnD({
+ enabled: isTopPicksCustomizable,
+ picks: effectiveTopPicks,
+ onPicksChange: (picks) => {
+ if (!customizableTopPicks) {
+ return;
+ }
+ // NOTE the comparator comparing `appState.colorTopPicks` is what keeps
+ // this captured spread fresh — see `areColorPickerPropsEqual`
+ updateData({
+ colorTopPicks: {
+ ...appState.colorTopPicks,
+ [customizableTopPicks]: picks,
+ },
+ });
+ },
+ });
+
return (
- <div>
+ <ColorPickerDnDContext.Provider value={isTopPicksCustomizable ? dnd : null}>
<div
role="dialog"
aria-modal="true"
@@ -314,10 +406,37 @@ export const ColorPicker = ({
>
{!isCompactMode && (
<TopPicks
+ theme={appState.theme}
activeColor={color}
- onChange={onChange}
+ onChange={(pickedColor) => {
+ onChange(pickedColor);
+ // if another color-picker popup is open, follow the user's
+ // focus over to this picker (same as clicking its trigger)
+ if (
+ isColorPickerPopup(appState.openPopup) &&
+ appState.openPopup !== type
+ ) {
+ // deferred: each updateData spreads the full pre-commit
+ // appState, so issuing this in the same task would clobber
+ // the color change committed by `onChange` above
+ setTimeout(() => updateData({ openPopup: type }), 0);
+ }
+ }}
type={type}
- topPicks={topPicks}
+ topPicks={customTopPicks?.length ? customTopPicks : topPicks}
+ isCustomized={!!customTopPicks?.length}
+ onReset={
+ isTopPicksCustomizable && customizableTopPicks
+ ? () => {
+ updateData({
+ colorTopPicks: {
+ ...appState.colorTopPicks,
+ [customizableTopPicks]: null,
+ },
+ });
+ }
+ : undefined
+ }
/>
)}
{!isCompactMode && <ButtonSeparator />}
@@ -334,6 +453,7 @@ export const ColorPicker = ({
color={color}
label={label}
type={type}
+ theme={appState.theme}
mode={type === "elementStroke" ? "stroke" : "background"}
editingTextElement={!!appState.editingTextElement}
onToggle={() => {
@@ -366,6 +486,51 @@ export const ColorPicker = ({
)}
</Popover.Root>
</div>
- </div>
+ </ColorPickerDnDContext.Provider>
);
};
+
+/**
+ * ColorPicker renders on every styles-panel render (selection churn during
+ * box-select and the like), while its actual inputs are a handful of resolved
+ * primitives and reference-stable objects — cheap `===` checks, no deep
+ * comparisons:
+ * - `palette` / `topPicks` / `excludedColors` are module constants,
+ * - `appState.colorTopPicks` identity changes exactly when its content does.
+ *
+ * Function props (`onChange`, `updateData`) are deliberately ignored — they
+ * are recreated every render but semantically stable (they read fresh state
+ * at call time). Same for `elements`, which is only sampled once when the
+ * popup opens (most-used custom colors).
+ */
+const areColorPickerPropsEqual = (
+ prev: ColorPickerProps,
+ next: ColorPickerProps,
+) => {
+ // the open popup is interactive (hotkeys, eye dropper, most-used custom
+ // colors) — never memoize it, including the open/close transitions
+ if (
+ prev.appState.openPopup === prev.type ||
+ next.appState.openPopup === next.type
+ ) {
+ return false;
+ }
+ return (
+ prev.type === next.type &&
+ prev.color === next.color &&
+ prev.label === next.label &&
+ // popup open/close is rare, and the strip's click handler branches on
+ // which popup is open (popup-switching) — keep its closure fresh
+ prev.appState.openPopup === next.appState.openPopup &&
+ prev.palette === next.palette &&
+ prev.topPicks === next.topPicks &&
+ prev.excludedColors === next.excludedColors &&
+ prev.customizableTopPicks === next.customizableTopPicks &&
+ prev.appState.theme === next.appState.theme &&
+ prev.appState.colorTopPicks === next.appState.colorTopPicks &&
+ // the trigger tweaks its click behavior while a text element is edited
+ !!prev.appState.editingTextElement === !!next.appState.editingTextElement
+ );
+};
+
+export const ColorPicker = memo(ColorPickerComponent, areColorPickerPropsEqual);
diff --git a/packages/excalidraw/components/ColorPicker/CustomColorList.tsx b/packages/excalidraw/components/ColorPicker/CustomColorList.tsx
index acc7b3e0e6..a5ccd869d6 100644
--- a/packages/excalidraw/components/ColorPicker/CustomColorList.tsx
+++ b/packages/excalidraw/components/ColorPicker/CustomColorList.tsx
@@ -1,12 +1,18 @@
import clsx from "clsx";
import { useEffect, useRef } from "react";
+import { applyDarkModeFilter, THEME } from "@excalidraw/common";
+
+import type { Theme } from "@excalidraw/element/types";
+
import { useAtom } from "../../editor-jotai";
import HotkeyLabel from "./HotkeyLabel";
import { activeColorPickerSectionAtom } from "./colorPickerUtils";
+import { useColorPickerDnD } from "./topPicksDnD";
interface CustomColorListProps {
+ theme: Theme;
colors: string[];
color: string | null;
onChange: (color: string) => void;
@@ -14,6 +20,7 @@ interface CustomColorListProps {
}
export const CustomColorList = ({
+ theme,
colors,
color,
onChange,
@@ -22,6 +29,7 @@ export const CustomColorList = ({
const [activeColorPickerSection, setActiveColorPickerSection] = useAtom(
activeColorPickerSectionAtom,
);
+ const dnd = useColorPickerDnD();
const btnRef = useRef<HTMLButtonElement>(null);
@@ -34,6 +42,7 @@ export const CustomColorList = ({
return (
<div className="color-picker-content--default">
{colors.map((c, i) => {
+ const displayColor = applyDarkModeFilter(c, theme === THEME.DARK);
return (
<button
ref={color === c ? btnRef : undefined}
@@ -50,13 +59,16 @@ export const CustomColorList = ({
onChange(c);
setActiveColorPickerSection("custom");
}}
+ onPointerDown={
+ dnd ? (event) => dnd.startSwatchDrag(event, c) : undefined
+ }
title={c}
aria-label={label}
- style={{ "--swatch-color": c }}
+ style={{ "--swatch-color": displayColor }}
key={i}
>
<div className="color-picker__button-outline" />
- <HotkeyLabel color={c} keyLabel={i + 1} />
+ <HotkeyLabel color={displayColor} keyLabel={i + 1} />
</button>
);
})}
diff --git a/packages/excalidraw/components/ColorPicker/Picker.tsx b/packages/excalidraw/components/ColorPicker/Picker.tsx
index 34d306e74d..fa64b5aae8 100644
--- a/packages/excalidraw/components/ColorPicker/Picker.tsx
+++ b/packages/excalidraw/components/ColorPicker/Picker.tsx
@@ -8,7 +8,7 @@ import {
KEYS,
} from "@excalidraw/common";
-import type { ExcalidrawElement } from "@excalidraw/element/types";
+import type { ExcalidrawElement, Theme } from "@excalidraw/element/types";
import type { ColorPaletteCustom } from "@excalidraw/common";
@@ -26,10 +26,12 @@ import {
isCustomColor,
} from "./colorPickerUtils";
import { colorPickerKeyNavHandler } from "./keyboardNavHandlers";
+import { useColorPickerDnD } from "./topPicksDnD";
import type { ColorPickerType } from "./colorPickerUtils";
interface PickerProps {
+ theme: Theme;
color: string | null;
onChange: (color: string) => void;
type: ColorPickerType;
@@ -47,6 +49,7 @@ interface PickerProps {
export const Picker = React.forwardRef(
(
{
+ theme,
color,
onChange,
type,
@@ -80,6 +83,7 @@ export const Picker = React.forwardRef(
const [activeColorPickerSection, setActiveColorPickerSection] = useAtom(
activeColorPickerSectionAtom,
);
+ const dnd = useColorPickerDnD();
const colorObj = getColorNameAndShadeFromColor({
color,
@@ -177,6 +181,7 @@ export const Picker = React.forwardRef(
{t("colorPicker.mostUsedCustomColors")}
</PickerHeading>
<CustomColorList
+ theme={theme}
colors={customColors}
color={color}
label={t("colorPicker.mostUsedCustomColors")}
@@ -188,6 +193,7 @@ export const Picker = React.forwardRef(
<div>
<PickerHeading>{t("colorPicker.colors")}</PickerHeading>
<PickerColorList
+ theme={theme}
color={color}
palette={palette}
onChange={onChange}
@@ -200,6 +206,7 @@ export const Picker = React.forwardRef(
<div>
<PickerHeading>{t("colorPicker.shades")}</PickerHeading>
<ShadeList
+ theme={theme}
color={color}
onChange={onChange}
palette={palette}
@@ -207,6 +214,12 @@ export const Picker = React.forwardRef(
/>
</div>
{children}
+ {/* dnd context is only provided when top picks are customizable */}
+ {dnd && (
+ <div className="color-picker__tip">
+ {t("colorPicker.topPicksTip")}
+ </div>
+ )}
</div>
</div>
);
diff --git a/packages/excalidraw/components/ColorPicker/PickerColorList.tsx b/packages/excalidraw/components/ColorPicker/PickerColorList.tsx
index 3253ddef30..5b23c4d434 100644
--- a/packages/excalidraw/components/ColorPicker/PickerColorList.tsx
+++ b/packages/excalidraw/components/ColorPicker/PickerColorList.tsx
@@ -1,7 +1,14 @@
import clsx from "clsx";
import { useEffect, useRef } from "react";
-import type { ColorPaletteCustom } from "@excalidraw/common";
+import {
+ applyDarkModeFilter,
+ isColorDark,
+ THEME,
+ type ColorPaletteCustom,
+} from "@excalidraw/common";
+
+import type { Theme } from "@excalidraw/element/types";
import { useAtom } from "../../editor-jotai";
import { t } from "../../i18n";
@@ -12,10 +19,12 @@ import {
colorPickerHotkeyBindings,
getColorNameAndShadeFromColor,
} from "./colorPickerUtils";
+import { useColorPickerDnD } from "./topPicksDnD";
import type { TranslationKeys } from "../../i18n";
interface PickerColorListProps {
+ theme: Theme;
palette: ColorPaletteCustom;
color: string | null;
onChange: (color: string) => void;
@@ -29,6 +38,7 @@ interface PickerColorListProps {
}
const PickerColorList = ({
+ theme,
palette,
color,
onChange,
@@ -43,6 +53,7 @@ const PickerColorList = ({
const [activeColorPickerSection, setActiveColorPickerSection] = useAtom(
activeColorPickerSectionAtom,
);
+ const dnd = useColorPickerDnD();
const btnRef = useRef<HTMLButtonElement>(null);
@@ -72,6 +83,7 @@ const PickerColorList = ({
}
const keybinding = colorPickerHotkeyBindings[index];
+ const displayColor = applyDarkModeFilter(color, theme === THEME.DARK);
const label = t(
`colors.${key.replace(/\d+/, "")}` as unknown as TranslationKeys,
null,
@@ -84,8 +96,9 @@ const PickerColorList = ({
tabIndex={-1}
type="button"
className={clsx(
- "color-picker__button color-picker__button--large has-outline",
+ "color-picker__button color-picker__button--large",
{
+ "has-outline": !isColorDark(color, 255),
active: colorObj?.colorName === key,
"is-transparent": color === "transparent" || !color,
},
@@ -94,16 +107,21 @@ const PickerColorList = ({
onChange(color);
setActiveColorPickerSection("baseColors");
}}
+ onPointerDown={
+ dnd ? (event) => dnd.startSwatchDrag(event, color) : undefined
+ }
title={`${label}${
color.startsWith("#") ? ` ${color}` : ""
} — ${keybinding}`}
aria-label={`${label} — ${keybinding}`}
- style={color ? { "--swatch-color": color } : undefined}
+ style={color ? { "--swatch-color": displayColor } : undefined}
data-testid={`color-${key}`}
key={key}
>
<div className="color-picker__button-outline" />
- {showHotKey && <HotkeyLabel color={color} keyLabel={keybinding} />}
+ {showHotKey && (
+ <HotkeyLabel color={displayColor} keyLabel={keybinding} />
+ )}
</button>
);
})}
diff --git a/packages/excalidraw/components/ColorPicker/ShadeList.tsx b/packages/excalidraw/components/ColorPicker/ShadeList.tsx
index 2c17c57ede..9d4d05f506 100644
--- a/packages/excalidraw/components/ColorPicker/ShadeList.tsx
+++ b/packages/excalidraw/components/ColorPicker/ShadeList.tsx
@@ -1,7 +1,13 @@
import clsx from "clsx";
import { useEffect, useRef } from "react";
-import type { ColorPaletteCustom } from "@excalidraw/common";
+import {
+ applyDarkModeFilter,
+ THEME,
+ type ColorPaletteCustom,
+} from "@excalidraw/common";
+
+import type { Theme } from "@excalidraw/element/types";
import { useAtom } from "../../editor-jotai";
import { t } from "../../i18n";
@@ -11,8 +17,10 @@ import {
activeColorPickerSectionAtom,
getColorNameAndShadeFromColor,
} from "./colorPickerUtils";
+import { useColorPickerDnD } from "./topPicksDnD";
interface ShadeListProps {
+ theme: Theme;
color: string | null;
onChange: (color: string) => void;
palette: ColorPaletteCustom;
@@ -20,6 +28,7 @@ interface ShadeListProps {
}
export const ShadeList = ({
+ theme,
color,
onChange,
palette,
@@ -33,6 +42,7 @@ export const ShadeList = ({
const [activeColorPickerSection, setActiveColorPickerSection] = useAtom(
activeColorPickerSectionAtom,
);
+ const dnd = useColorPickerDnD();
const btnRef = useRef<HTMLButtonElement>(null);
@@ -50,34 +60,45 @@ export const ShadeList = ({
if (Array.isArray(shades)) {
return (
<div className="color-picker-content--default shades">
- {shades.map((color, i) => (
- <button
- ref={
- i === shade && activeColorPickerSection === "shades"
- ? btnRef
- : undefined
- }
- tabIndex={-1}
- key={i}
- type="button"
- className={clsx(
- "color-picker__button color-picker__button--large has-outline",
- { active: i === shade },
- )}
- aria-label="Shade"
- title={`${colorName} - ${i + 1}`}
- style={color ? { "--swatch-color": color } : undefined}
- onClick={() => {
- onChange(color);
- setActiveColorPickerSection("shades");
- }}
- >
- <div className="color-picker__button-outline" />
- {showHotKey && (
- <HotkeyLabel color={color} keyLabel={i + 1} isShade />
- )}
- </button>
- ))}
+ {shades.map((color, i) => {
+ const displayColor = applyDarkModeFilter(
+ color,
+ theme === THEME.DARK,
+ );
+ return (
+ <button
+ ref={
+ i === shade && activeColorPickerSection === "shades"
+ ? btnRef
+ : undefined
+ }
+ tabIndex={-1}
+ key={i}
+ type="button"
+ className={clsx(
+ "color-picker__button color-picker__button--large",
+ {
+ active: i === shade,
+ },
+ )}
+ aria-label="Shade"
+ title={`${colorName} - ${i + 1}`}
+ style={color ? { "--swatch-color": displayColor } : undefined}
+ onClick={() => {
+ onChange(color);
+ setActiveColorPickerSection("shades");
+ }}
+ onPointerDown={
+ dnd ? (event) => dnd.startSwatchDrag(event, color) : undefined
+ }
+ >
+ <div className="color-picker__button-outline" />
+ {showHotKey && (
+ <HotkeyLabel color={displayColor} keyLabel={i + 1} isShade />
+ )}
+ </button>
+ );
+ })}
</div>
);
}
diff --git a/packages/excalidraw/components/ColorPicker/TopPicks.tsx b/packages/excalidraw/components/ColorPicker/TopPicks.tsx
index 5b5070a5b6..e2b5d3ddb5 100644
--- a/packages/excalidraw/components/ColorPicker/TopPicks.tsx
+++ b/packages/excalidraw/components/ColorPicker/TopPicks.tsx
@@ -1,28 +1,51 @@
import clsx from "clsx";
+import { ContextMenu } from "radix-ui";
import {
+ applyDarkModeFilter,
COLOR_OUTLINE_CONTRAST_THRESHOLD,
DEFAULT_CANVAS_BACKGROUND_PICKS,
DEFAULT_ELEMENT_BACKGROUND_PICKS,
DEFAULT_ELEMENT_STROKE_PICKS,
isColorDark,
+ THEME,
} from "@excalidraw/common";
+import type { Theme } from "@excalidraw/element/types";
+
+import { t } from "../../i18n";
+import { useExcalidrawContainer } from "../App";
+
+import { useColorPickerDnD } from "./topPicksDnD";
+
import type { ColorPickerType } from "./colorPickerUtils";
interface TopPicksProps {
+ theme: Theme;
onChange: (color: string) => void;
type: ColorPickerType;
activeColor: string | null;
topPicks?: readonly string[];
+ /** present when the strip is user-customizable — enables the right-click
+ * context menu resetting the strip to its default picks */
+ onReset?: () => void;
+ /** whether custom picks are currently applied (enables the reset item) */
+ isCustomized?: boolean;
}
export const TopPicks = ({
+ theme,
onChange,
type,
activeColor,
topPicks,
+ onReset,
+ isCustomized,
}: TopPicksProps) => {
+ const dnd = useColorPickerDnD();
+ const dragState = dnd?.dragState ?? null;
+ const { container } = useExcalidrawContainer();
+
let colors;
if (type === "elementStroke") {
colors = DEFAULT_ELEMENT_STROKE_PICKS;
@@ -46,28 +69,116 @@ export const TopPicks = ({
return null;
}
- return (
- <div className="color-picker__top-picks">
- {colors.map((color: string) => (
- <button
- className={clsx("color-picker__button", {
- active: color === activeColor,
- "is-transparent": color === "transparent" || !color,
- "has-outline": !isColorDark(
- color,
- COLOR_OUTLINE_CONTRAST_THRESHOLD,
- ),
- })}
- style={{ "--swatch-color": color }}
- key={color}
- type="button"
- title={color}
- onClick={() => onChange(color)}
- data-testid={`color-top-pick-${color}`}
+ // live preview of the reorder result — every pick translates to the slot
+ // it would occupy if dropped right now
+ const getReorderOffset = (index: number) => {
+ if (
+ !dragState ||
+ dragState.origin.kind !== "pick" ||
+ dragState.overIndex === null
+ ) {
+ return 0;
+ }
+ const from = dragState.origin.index;
+ const to = dragState.overIndex;
+ if (from === to) {
+ return 0;
+ }
+ let newIndex = index;
+ if (index === from) {
+ newIndex = to;
+ } else {
+ if (index > from) {
+ newIndex -= 1;
+ }
+ if (newIndex >= to) {
+ newIndex += 1;
+ }
+ }
+ return (newIndex - index) * dragState.slotSpan;
+ };
+
+ const strip = (
+ <div
+ className={clsx("color-picker__top-picks", {
+ "is-dnd-active": !!dragState,
+ })}
+ ref={dnd?.setStripEl}
+ >
+ {dragState && (
+ <svg
+ className="color-picker__top-picks__dnd-outline"
+ aria-hidden="true"
>
- <div className="color-picker__button-outline" />
- </button>
- ))}
+ <rect />
+ </svg>
+ )}
+ {colors.map((color: string, index: number) => {
+ const reorderOffset = getReorderOffset(index);
+ const displayColor = applyDarkModeFilter(color, theme === THEME.DARK);
+ return (
+ <button
+ className={clsx("color-picker__button", {
+ active: color === activeColor,
+ "is-transparent": color === "transparent" || !color,
+ "has-outline": !isColorDark(
+ color,
+ COLOR_OUTLINE_CONTRAST_THRESHOLD,
+ ),
+ "is-dnd-source":
+ dragState?.origin.kind === "pick" &&
+ dragState.origin.index === index,
+ "is-dnd-target":
+ dragState?.origin.kind === "swatch" &&
+ dragState.overIndex === index,
+ "is-dnd-duplicate": dragState?.duplicateIndex === index,
+ })}
+ style={{
+ "--swatch-color": displayColor,
+ transform: reorderOffset
+ ? `translateX(${reorderOffset}px)`
+ : undefined,
+ }}
+ key={color}
+ type="button"
+ title={color}
+ onClick={() => onChange(color)}
+ onPointerDown={
+ dnd
+ ? (event) => dnd.startPickDrag(event, index, color)
+ : undefined
+ }
+ data-testid={`color-top-pick-${color}`}
+ data-top-pick-index={index}
+ >
+ <div className="color-picker__button-outline" />
+ </button>
+ );
+ })}
</div>
);
+
+ if (!onReset) {
+ return strip;
+ }
+
+ return (
+ <ContextMenu.Root>
+ <ContextMenu.Trigger asChild>{strip}</ContextMenu.Trigger>
+ <ContextMenu.Portal container={container}>
+ <ContextMenu.Content
+ className="color-picker__context-menu"
+ style={{ zIndex: "var(--zIndex-ui-styles-popup)" }}
+ >
+ <ContextMenu.Item
+ className="color-picker__context-menu-item"
+ disabled={!isCustomized}
+ onSelect={onReset}
+ >
+ {t("colorPicker.resetTopPicks")}
+ </ContextMenu.Item>
+ </ContextMenu.Content>
+ </ContextMenu.Portal>
+ </ContextMenu.Root>
+ );
};
diff --git a/packages/excalidraw/components/ColorPicker/topPicksDnD.tsx b/packages/excalidraw/components/ColorPicker/topPicksDnD.tsx
new file mode 100644
index 0000000000..f794fd07d6
--- /dev/null
+++ b/packages/excalidraw/components/ColorPicker/topPicksDnD.tsx
@@ -0,0 +1,572 @@
+import {
+ createContext,
+ useContext,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+
+import { colorToHex, isTransparent } from "@excalidraw/common";
+
+/**
+ * Custom (non-native) drag & drop for pinning colors to the color-picker
+ * top-picks strip and reordering the strip itself.
+ *
+ * Implemented with pointer events + a manually rendered "ghost" swatch so we
+ * control the visuals fully (native HTML5 dnd flickers and forces ugly
+ * ghosting/cursors).
+ */
+
+const GHOST_CLASS = "excalidraw-color-dnd-ghost";
+const BODY_CLASS = "excalidraw-color-dnd-active";
+const DRAG_THRESHOLD = 10;
+/** a fast sloppy click can travel many px — releases faster than this stay
+ * clicks; the drag only starts once the pointer is held this long */
+const DRAG_TIME_THRESHOLD_MS = 100;
+
+/** value-equality of colors — normalizes notation (`#fff` vs `#ffffff` vs
+ * `white`) so visually identical colors can't occupy multiple pick slots */
+const isSameColor = (a: string, b: string) => {
+ if (a.toLowerCase() === b.toLowerCase()) {
+ return true;
+ }
+ const aHex = colorToHex(a);
+ return aHex !== null && aHex === colorToHex(b);
+};
+
+type DragOrigin =
+ // a color dragged from the picker popup (palette/shades/custom) or the
+ // active-color trigger — dropping replaces the hovered pick
+ | { kind: "swatch" }
+ // a pick dragged from the top-picks strip itself — dropping reorders
+ | { kind: "pick"; index: number };
+
+export type TopPicksDragState = {
+ color: string;
+ origin: DragOrigin;
+ /** hovered strip slot — the slot to replace (swatch drags) or the final
+ * position (pick reorders). null while the pointer is outside the strip */
+ overIndex: number | null;
+ /** index of an already-pinned identical color that blocks the drop */
+ duplicateIndex: number | null;
+ /** signed distance between strip slot centers (for reorder preview) */
+ slotSpan: number;
+} | null;
+
+type DragSession = {
+ pointerId: number;
+ startX: number;
+ startY: number;
+ startTime: number;
+ lastX: number;
+ lastY: number;
+ /** pending delayed activation (spatial threshold crossed before the
+ * temporal one) */
+ activationTimer: number | null;
+ color: string;
+ origin: DragOrigin;
+ sourceEl: HTMLElement;
+ sourceRect: DOMRect;
+ activated: boolean;
+ ghost: HTMLDivElement | null;
+ ghostW: number;
+ ghostH: number;
+ slotRects: DOMRect[];
+ slotSpan: number;
+ hitRect: { left: number; right: number; top: number; bottom: number } | null;
+ overIndex: number | null;
+ duplicateIndex: number | null;
+};
+
+export type ColorPickerDnD = {
+ dragState: TopPicksDragState;
+ startSwatchDrag: (event: React.PointerEvent, color: string | null) => void;
+ startPickDrag: (
+ event: React.PointerEvent,
+ index: number,
+ color: string,
+ ) => void;
+ setStripEl: (el: HTMLDivElement | null) => void;
+};
+
+export const ColorPickerDnDContext = createContext<ColorPickerDnD | null>(null);
+
+export const useColorPickerDnD = () => useContext(ColorPickerDnDContext);
+
+export const useTopPicksDnD = ({
+ enabled,
+ picks,
+ onPicksChange,
+}: {
+ enabled: boolean;
+ picks: readonly string[];
+ onPicksChange: (picks: string[]) => void;
+}): ColorPickerDnD => {
+ const [dragState, setDragState] = useState<TopPicksDragState>(null);
+ const stripRef = useRef<HTMLDivElement | null>(null);
+
+ const latestRef = useRef({ enabled, picks, onPicksChange });
+ latestRef.current = { enabled, picks, onPicksChange };
+
+ const controller = useMemo(() => {
+ let session: DragSession | null = null;
+
+ const publish = () => {
+ if (session?.activated) {
+ setDragState({
+ color: session.color,
+ origin: session.origin,
+ overIndex: session.overIndex,
+ duplicateIndex: session.duplicateIndex,
+ slotSpan: session.slotSpan,
+ });
+ } else {
+ setDragState(null);
+ }
+ };
+
+ const measureStrip = () => {
+ const strip = stripRef.current;
+ if (!strip || !session) {
+ return false;
+ }
+ const buttons = Array.from(
+ strip.querySelectorAll<HTMLElement>("[data-top-pick-index]"),
+ ).sort(
+ (a, b) =>
+ Number(a.dataset.topPickIndex) - Number(b.dataset.topPickIndex),
+ );
+ if (!buttons.length) {
+ return false;
+ }
+ session.slotRects = buttons.map((button) =>
+ button.getBoundingClientRect(),
+ );
+ const [first, second] = session.slotRects;
+ // strip is evenly spaced (space-between); sign flips under RTL
+ session.slotSpan = second ? second.left - first.left : first.width + 4;
+ const stripRect = strip.getBoundingClientRect();
+ const padX = Math.max(Math.abs(session.slotSpan) / 2, 10);
+ session.hitRect = {
+ left: stripRect.left - padX,
+ right: stripRect.right + padX,
+ top: stripRect.top - 14,
+ bottom: stripRect.bottom + 14,
+ };
+ return true;
+ };
+
+ const positionGhost = (x: number, y: number) => {
+ if (session?.ghost) {
+ session.ghost.style.transform = `translate(${
+ x - session.ghostW / 2
+ }px, ${y - session.ghostH / 2}px)`;
+ }
+ };
+
+ const setGhostSize = (
+ width: number,
+ height: number,
+ x: number,
+ y: number,
+ ) => {
+ if (!session?.ghost) {
+ return;
+ }
+ if (session.ghostW !== width || session.ghostH !== height) {
+ session.ghostW = width;
+ session.ghostH = height;
+ session.ghost.style.width = `${width}px`;
+ session.ghost.style.height = `${height}px`;
+ positionGhost(x, y);
+ }
+ };
+
+ const activate = (x: number, y: number) => {
+ if (!session) {
+ return;
+ }
+ const { sourceRect, sourceEl, color } = session;
+
+ const ghost = document.createElement("div");
+ ghost.className = GHOST_CLASS;
+ const swatch = document.createElement("div");
+ swatch.className = `${GHOST_CLASS}__swatch`;
+ if (isTransparent(color)) {
+ swatch.classList.add("is-transparent");
+ } else {
+ // swatches render the theme-adjusted color (dark mode remaps colors
+ // rather than CSS-filtering them) — sample the rendered color so the
+ // ghost matches what the user picked up
+ const rendered = getComputedStyle(sourceEl).backgroundColor;
+ swatch.style.backgroundColor =
+ rendered && rendered !== "rgba(0, 0, 0, 0)" ? rendered : color;
+ }
+ ghost.appendChild(swatch);
+ document.body.appendChild(ghost);
+
+ session.ghost = ghost;
+ session.ghostW = sourceRect.width;
+ session.ghostH = sourceRect.height;
+ ghost.style.width = `${sourceRect.width}px`;
+ ghost.style.height = `${sourceRect.height}px`;
+ positionGhost(x, y);
+ // let the spawn frame paint at rest, then "lift" (scale-up transition)
+ requestAnimationFrame(() => {
+ // unless the drag already ended — don't restyle a ghost that's
+ // mid-flight in its release animation (or already removed)
+ if (session?.ghost === ghost) {
+ ghost.classList.add(`${GHOST_CLASS}--lifted`);
+ }
+ });
+
+ document.body.classList.add(BODY_CLASS);
+ session.activated = true;
+ publish();
+ };
+
+ const hitTest = (x: number, y: number) => {
+ if (!session?.hitRect) {
+ return;
+ }
+ const { hitRect, slotRects } = session;
+ let overIndex: number | null = null;
+ let duplicateIndex: number | null = null;
+
+ if (
+ x >= hitRect.left &&
+ x <= hitRect.right &&
+ y >= hitRect.top &&
+ y <= hitRect.bottom
+ ) {
+ let best = 0;
+ let bestDistance = Infinity;
+ slotRects.forEach((rect, index) => {
+ const distance = Math.abs(x - (rect.left + rect.width / 2));
+ if (distance < bestDistance) {
+ bestDistance = distance;
+ best = index;
+ }
+ });
+ if (session.origin.kind === "swatch") {
+ const duplicate = latestRef.current.picks.findIndex((pick) =>
+ isSameColor(pick, session!.color),
+ );
+ if (duplicate !== -1) {
+ duplicateIndex = duplicate;
+ } else {
+ overIndex = best;
+ }
+ } else {
+ overIndex = best;
+ }
+ }
+
+ if (
+ overIndex !== session.overIndex ||
+ duplicateIndex !== session.duplicateIndex
+ ) {
+ session.overIndex = overIndex;
+ session.duplicateIndex = duplicateIndex;
+
+ const { ghost } = session;
+ if (ghost) {
+ ghost.classList.toggle(`${GHOST_CLASS}--over`, overIndex !== null);
+ ghost.classList.toggle(
+ `${GHOST_CLASS}--blocked`,
+ duplicateIndex !== null,
+ );
+ }
+ publish();
+ }
+
+ // over the strip the ghost morphs to slot size to preview the landing
+ if (overIndex !== null) {
+ const rect = session.slotRects[overIndex];
+ setGhostSize(rect.width, rect.height, x, y);
+ } else {
+ setGhostSize(session.sourceRect.width, session.sourceRect.height, x, y);
+ }
+ };
+
+ const releaseGhost = (target: { rect: DOMRect | null }) => {
+ if (!session?.ghost) {
+ return;
+ }
+ const { ghost } = session;
+ session.ghost = null;
+ ghost.classList.add(`${GHOST_CLASS}--dropping`);
+ const rect = target.rect;
+ if (rect) {
+ ghost.style.width = `${rect.width}px`;
+ ghost.style.height = `${rect.height}px`;
+ ghost.style.transform = `translate(${rect.left}px, ${rect.top}px)`;
+ }
+ window.setTimeout(() => {
+ ghost.classList.add(`${GHOST_CLASS}--fade`);
+ }, 160);
+ window.setTimeout(() => {
+ ghost.remove();
+ }, 340);
+ };
+
+ // kill any in-flight (or retargetable) reorder-preview transitions before
+ // the drag state is torn down. Running CSS transitions survive both the
+ // removal of the `transition` property (spec: transition-* changes don't
+ // affect running transitions) and React's keyed DOM reorder on commit —
+ // the browser retargets them, which made the picks visibly re-shift on
+ // drop. Clearing the transforms with transitions disabled (+ forced
+ // reflow) cancels them for good, so the commit paints the final order
+ // directly.
+ const settleStripInstantly = () => {
+ const strip = stripRef.current;
+ if (!strip || !session?.activated) {
+ return;
+ }
+ const buttons = Array.from(
+ strip.querySelectorAll<HTMLElement>("[data-top-pick-index]"),
+ );
+ for (const button of buttons) {
+ button.style.transition = "none";
+ button.style.transform = "none";
+ }
+ // flush the non-animated state...
+ void strip.offsetWidth;
+ // ...then let the stylesheet govern transitions again (next drag)
+ for (const button of buttons) {
+ button.style.transition = "";
+ }
+ };
+
+ const suppressNextClick = () => {
+ const suppress = (event: MouseEvent) => {
+ event.preventDefault();
+ event.stopPropagation();
+ };
+ window.addEventListener("click", suppress, { capture: true, once: true });
+ window.setTimeout(() => {
+ window.removeEventListener("click", suppress, { capture: true });
+ }, 100);
+ };
+
+ const removeListeners = () => {
+ window.removeEventListener("pointermove", onPointerMove, true);
+ window.removeEventListener("pointerup", onPointerUp, true);
+ window.removeEventListener("pointercancel", onPointerCancel, true);
+ window.removeEventListener("keydown", onKeyDown, true);
+ };
+
+ const dispose = () => {
+ removeListeners();
+ document.body.classList.remove(BODY_CLASS);
+ if (session?.activationTimer != null) {
+ window.clearTimeout(session.activationTimer);
+ }
+ session = null;
+ setDragState(null);
+ };
+
+ const cancelDrag = (animate: boolean) => {
+ if (!session) {
+ return;
+ }
+ settleStripInstantly();
+ if (session.ghost) {
+ if (animate) {
+ releaseGhost({ rect: session.sourceRect });
+ } else {
+ session.ghost.remove();
+ session.ghost = null;
+ }
+ }
+ dispose();
+ };
+
+ const tryActivate = (x: number, y: number) => {
+ if (!session || session.activated) {
+ return;
+ }
+ if (!measureStrip()) {
+ dispose();
+ return;
+ }
+ activate(x, y);
+ hitTest(x, y);
+ };
+
+ const onPointerMove = (event: PointerEvent) => {
+ if (!session || event.pointerId !== session.pointerId) {
+ return;
+ }
+ session.lastX = event.clientX;
+ session.lastY = event.clientY;
+ if (!session.activated) {
+ if (
+ Math.hypot(
+ event.clientX - session.startX,
+ event.clientY - session.startY,
+ ) < DRAG_THRESHOLD
+ ) {
+ // back inside the click tolerance — a delayed activation scheduled
+ // while we were beyond it no longer applies (wiggle-and-return
+ // must stay a click)
+ if (session.activationTimer !== null) {
+ window.clearTimeout(session.activationTimer);
+ session.activationTimer = null;
+ }
+ return;
+ }
+ const elapsed = performance.now() - session.startTime;
+ if (elapsed < DRAG_TIME_THRESHOLD_MS) {
+ // spatial threshold crossed, temporal not yet — likely a fast
+ // sloppy click. Wait out the rest of the grace period; the timeout
+ // covers "flick then hold still", where no further moves fire
+ if (session.activationTimer === null) {
+ session.activationTimer = window.setTimeout(() => {
+ if (session) {
+ session.activationTimer = null;
+ // the pointer may have returned inside the tolerance after
+ // the last event we saw — never activate from within it
+ if (
+ Math.hypot(
+ session.lastX - session.startX,
+ session.lastY - session.startY,
+ ) >= DRAG_THRESHOLD
+ ) {
+ tryActivate(session.lastX, session.lastY);
+ }
+ }
+ }, DRAG_TIME_THRESHOLD_MS - elapsed);
+ }
+ return;
+ }
+ tryActivate(event.clientX, event.clientY);
+ if (!session?.activated) {
+ return;
+ }
+ }
+ event.preventDefault();
+ positionGhost(event.clientX, event.clientY);
+ hitTest(event.clientX, event.clientY);
+ };
+
+ const onPointerUp = (event: PointerEvent) => {
+ if (!session || event.pointerId !== session.pointerId) {
+ return;
+ }
+ if (!session.activated) {
+ // never became a drag — let the regular click happen
+ dispose();
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ suppressNextClick();
+
+ const { overIndex, origin, color, slotRects } = session;
+ const { picks, onPicksChange } = latestRef.current;
+
+ settleStripInstantly();
+
+ if (overIndex !== null) {
+ if (origin.kind === "swatch") {
+ if (!picks.some((pick) => isSameColor(pick, color))) {
+ const next = [...picks];
+ next[overIndex] = color;
+ onPicksChange(next);
+ }
+ } else if (origin.index !== overIndex) {
+ const next = [...picks];
+ const [moved] = next.splice(origin.index, 1);
+ next.splice(overIndex, 0, moved);
+ onPicksChange(next);
+ }
+ releaseGhost({ rect: slotRects[overIndex] });
+ } else {
+ releaseGhost({ rect: session.sourceRect });
+ }
+ dispose();
+ };
+
+ const onPointerCancel = (event: PointerEvent) => {
+ if (session && event.pointerId === session.pointerId) {
+ cancelDrag(true);
+ }
+ };
+
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (session?.activated && event.key === "Escape") {
+ event.preventDefault();
+ event.stopPropagation();
+ cancelDrag(true);
+ }
+ };
+
+ const begin = (
+ event: React.PointerEvent,
+ color: string | null,
+ origin: DragOrigin,
+ ) => {
+ if (
+ !latestRef.current.enabled ||
+ session ||
+ event.button !== 0 ||
+ !color
+ ) {
+ return;
+ }
+ session = {
+ pointerId: event.pointerId,
+ startX: event.clientX,
+ startY: event.clientY,
+ startTime: performance.now(),
+ lastX: event.clientX,
+ lastY: event.clientY,
+ activationTimer: null,
+ color,
+ origin,
+ sourceEl: event.currentTarget as HTMLElement,
+ sourceRect: (
+ event.currentTarget as HTMLElement
+ ).getBoundingClientRect(),
+ activated: false,
+ ghost: null,
+ ghostW: 0,
+ ghostH: 0,
+ slotRects: [],
+ slotSpan: 0,
+ hitRect: null,
+ overIndex: null,
+ duplicateIndex: null,
+ };
+ window.addEventListener("pointermove", onPointerMove, true);
+ window.addEventListener("pointerup", onPointerUp, true);
+ window.addEventListener("pointercancel", onPointerCancel, true);
+ window.addEventListener("keydown", onKeyDown, true);
+ };
+
+ return {
+ begin,
+ destroy: () => cancelDrag(false),
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ // cancel a drag in flight if the picker unmounts mid-drag
+ useEffect(() => () => controller.destroy(), [controller]);
+
+ return useMemo(
+ () => ({
+ dragState,
+ startSwatchDrag: (event, color) =>
+ controller.begin(event, color, { kind: "swatch" }),
+ startPickDrag: (event, index, color) =>
+ controller.begin(event, color, { kind: "pick", index }),
+ setStripEl: (el) => {
+ stripRef.current = el;
+ },
+ }),
+ [dragState, controller],
+ );
+};
diff --git a/packages/excalidraw/data/restore.ts b/packages/excalidraw/data/restore.ts
index 300ee8a3d0..b8567aa5cd 100644
--- a/packages/excalidraw/data/restore.ts
+++ b/packages/excalidraw/data/restore.ts
@@ -1,6 +1,8 @@
import { isFiniteNumber, isValidPoint, pointFrom } from "@excalidraw/math";
import {
+ colorToHex,
+ COLOR_TOP_PICKS_SLOTS,
type CombineBrandsIfNeeded,
DEFAULT_FONT_FAMILY,
DEFAULT_STROKE_STREAMLINE,
@@ -1099,6 +1101,32 @@ const LegacyAppStateMigrations: {
},
};
+const restoreColorTopPicksList = (value: unknown): readonly string[] | null => {
+ if (!Array.isArray(value)) {
+ return null;
+ }
+ // keyed by normalized color value so notation variants (`#fff` vs
+ // `#ffffff` vs `white`) dedupe, while the value keeps the original
+ // notation — normalizing the output would break e.g. `transparent`
+ // (→ `#00000000`), which the picker matches by literal value
+ const colors = new Map<string, string>();
+ for (const color of value) {
+ if (typeof color !== "string") {
+ continue;
+ }
+ const normalized = colorToHex(color) ?? color.toLowerCase();
+ if (!colors.has(normalized)) {
+ colors.set(normalized, color);
+ }
+ // the strip layout fits exactly this many slots — longer lists (hostile
+ // or hand-edited storage) would overflow the properties island
+ if (colors.size >= COLOR_TOP_PICKS_SLOTS) {
+ break;
+ }
+ }
+ return colors.size ? [...colors.values()] : null;
+};
+
export const restoreAppState = (
appState: ImportedDataState["appState"],
localAppState: Partial<AppState> | null | undefined,
@@ -1145,6 +1173,19 @@ export const restoreAppState = (
nextAppState.boxSelectionMode = boxSelectionMode;
}
+ // drop malformed persisted custom top picks (imported data is untrusted)
+ nextAppState.colorTopPicks = {
+ elementStroke: restoreColorTopPicksList(
+ nextAppState.colorTopPicks?.elementStroke,
+ ),
+ elementBackground: restoreColorTopPicksList(
+ nextAppState.colorTopPicks?.elementBackground,
+ ),
+ bucketFill: restoreColorTopPicksList(
+ nextAppState.colorTopPicks?.bucketFill,
+ ),
+ };
+
// legacy
if ((appState as any).currentItemStrokeWidth !== undefined) {
nextAppState.currentItemStrokeWidthKey =
diff --git a/packages/excalidraw/locales/en.json b/packages/excalidraw/locales/en.json
index 3c5f47fe76..3cc7a60d9b 100644
--- a/packages/excalidraw/locales/en.json
+++ b/packages/excalidraw/locales/en.json
@@ -612,7 +612,9 @@
"hexCode": "Hex code",
"noShades": "No shades available for this color",
"invalidColor": "Not a valid color",
- "invalidHexLength": "Hex code must be 3, 4, 6, or 8 characters"
+ "invalidHexLength": "Hex code must be 3, 4, 6, or 8 characters",
+ "topPicksTip": "Tip: drag any color onto your top picks to pin it",
+ "resetTopPicks": "Reset to default top picks"
},
"overwriteConfirm": {
"action": {
diff --git a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap
index a2f634d77e..f81b29f599 100644
--- a/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/contextmenu.test.tsx.snap
@@ -15,6 +15,11 @@ exports[`contextMenu element > right-clicking on a group should select whole gro
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": {
"items": [
"separator",
@@ -1089,6 +1094,11 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1304,6 +1314,11 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1636,6 +1651,11 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1968,6 +1988,11 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2183,6 +2208,11 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2425,6 +2455,11 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2724,6 +2759,11 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3097,6 +3137,11 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3618,6 +3663,11 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3942,6 +3992,11 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4266,6 +4321,11 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4678,6 +4738,11 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": {
"items": [
"separator",
@@ -5896,6 +5961,11 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": {
"items": [
"separator",
@@ -7165,6 +7235,11 @@ exports[`contextMenu element > shows context menu for canvas > [end of test] app
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": {
"items": [
{
@@ -7855,6 +7930,11 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": {
"items": [
"separator",
@@ -8847,6 +8927,11 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": {
"items": [
"separator",
diff --git a/packages/excalidraw/tests/__snapshots__/excalidraw.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/excalidraw.test.tsx.snap
index 2ed8bc1c53..68d2730b05 100644
--- a/packages/excalidraw/tests/__snapshots__/excalidraw.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/excalidraw.test.tsx.snap
@@ -690,84 +690,68 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
<div
style="padding: 0px 0.625rem;"
>
- <div>
+ <div
+ aria-modal="true"
+ class="color-picker-container"
+ role="dialog"
+ >
<div
- aria-modal="true"
- class="color-picker-container"
- role="dialog"
+ class="color-picker__top-picks"
>
- <div
- class="color-picker__top-picks"
- >
- <button
- class="color-picker__button active has-outline"
- data-testid="color-top-pick-#ffffff"
- style="--swatch-color: #ffffff;"
- title="#ffffff"
- type="button"
- >
- <div
- class="color-picker__button-outline"
- />
- </button>
- <button
- class="color-picker__button has-outline"
- data-testid="color-top-pick-#f8f9fa"
- style="--swatch-color: #f8f9fa;"
- title="#f8f9fa"
- type="button"
- >
- <div
- class="color-picker__button-outline"
- />
- </button>
- <button
- class="color-picker__button has-outline"
- data-testid="color-top-pick-#f5faff"
- style="--swatch-color: #f5faff;"
- title="#f5faff"
- type="button"
- >
- <div
- class="color-picker__button-outline"
- />
- </button>
- <button
- class="color-picker__button has-outline"
- data-testid="color-top-pick-#fffce8"
- style="--swatch-color: #fffce8;"
- title="#fffce8"
- type="button"
- >
- <div
- class="color-picker__button-outline"
- />
- </button>
- <button
- class="color-picker__button has-outline"
- data-testid="color-top-pick-#fdf8f6"
- style="--swatch-color: #fdf8f6;"
- title="#fdf8f6"
- type="button"
- >
- <div
- class="color-picker__button-outline"
- />
- </button>
- </div>
- <div
- style="width: 1px; height: 1rem; margin: 0px auto;"
- />
<button
- aria-controls="radix-:r16:"
- aria-expanded="false"
- aria-haspopup="dialog"
- aria-label="Canvas background"
- class="color-picker__button active-color properties-trigger has-outline"
- data-openpopup="canvasBackground"
- data-state="closed"
+ class="color-picker__button active has-outline"
+ data-testid="color-top-pick-#ffffff"
+ data-top-pick-index="0"
style="--swatch-color: #ffffff;"
- title="Show background color picker"
+ title="#ffffff"
+ type="button"
+ >
+ <div
+ class="color-picker__button-outline"
+ />
+ </button>
+ <button
+ class="color-picker__button has-outline"
+ data-testid="color-top-pick-#f8f9fa"
+ data-top-pick-index="1"
+ style="--swatch-color: #f8f9fa;"
+ title="#f8f9fa"
+ type="button"
+ >
+ <div
+ class="color-picker__button-outline"
+ />
+ </button>
+ <button
+ class="color-picker__button has-outline"
+ data-testid="color-top-pick-#f5faff"
+ data-top-pick-index="2"
+ style="--swatch-color: #f5faff;"
+ title="#f5faff"
+ type="button"
+ >
+ <div
+ class="color-picker__button-outline"
+ />
+ </button>
+ <button
+ class="color-picker__button has-outline"
+ data-testid="color-top-pick-#fffce8"
+ data-top-pick-index="3"
+ style="--swatch-color: #fffce8;"
+ title="#fffce8"
+ type="button"
+ >
+ <div
+ class="color-picker__button-outline"
+ />
+ </button>
+ <button
+ class="color-picker__button has-outline"
+ data-testid="color-top-pick-#fdf8f6"
+ data-top-pick-index="4"
+ style="--swatch-color: #fdf8f6;"
+ title="#fdf8f6"
type="button"
>
<div
@@ -775,6 +759,25 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
/>
</button>
</div>
+ <div
+ style="width: 1px; height: 1rem; margin: 0px auto;"
+ />
+ <button
+ aria-controls="radix-:r16:"
+ aria-expanded="false"
+ aria-haspopup="dialog"
+ aria-label="Canvas background"
+ class="color-picker__button active-color properties-trigger has-outline"
+ data-openpopup="canvasBackground"
+ data-state="closed"
+ style="--swatch-color: #ffffff;"
+ title="Show background color picker"
+ type="button"
+ >
+ <div
+ class="color-picker__button-outline"
+ />
+ </button>
</div>
</div>
</div>
diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
index 6ab2bc7696..df4ce4d2ab 100644
--- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
@@ -15,6 +15,11 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -649,6 +654,11 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1211,6 +1221,11 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1572,6 +1587,11 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1935,6 +1955,11 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2199,6 +2224,11 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2653,6 +2683,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2957,6 +2992,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3277,6 +3317,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3572,6 +3617,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3859,6 +3909,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4095,6 +4150,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4353,6 +4413,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4625,6 +4690,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4855,6 +4925,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5085,6 +5160,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5333,6 +5413,11 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5590,6 +5675,11 @@ exports[`history > multiplayer undo/redo > conflicts in frames and their childre
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5849,6 +5939,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -6179,6 +6274,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -6607,6 +6707,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -6982,6 +7087,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -7295,6 +7405,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -7588,6 +7703,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -7819,6 +7939,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8172,6 +8297,11 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8525,6 +8655,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8932,6 +9067,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9220,6 +9360,11 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9485,6 +9630,11 @@ exports[`history > multiplayer undo/redo > should not override remote changes on
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9751,6 +9901,11 @@ exports[`history > multiplayer undo/redo > should not override remote changes on
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9984,6 +10139,11 @@ exports[`history > multiplayer undo/redo > should override remotely added groups
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -10282,6 +10442,11 @@ exports[`history > multiplayer undo/redo > should override remotely added points
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -10600,6 +10765,11 @@ exports[`history > multiplayer undo/redo > should redistribute deltas when eleme
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -10837,6 +11007,11 @@ exports[`history > multiplayer undo/redo > should redraw arrows on undo > [end o
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -11763,6 +11938,11 @@ exports[`history > multiplayer undo/redo > should update history entries after r
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -12024,6 +12204,11 @@ exports[`history > singleplayer undo/redo > remounting undo/redo buttons should
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -12260,6 +12445,11 @@ exports[`history > singleplayer undo/redo > should clear the redo stack on eleme
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -12498,6 +12688,11 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -12902,6 +13097,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13113,6 +13313,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13321,6 +13526,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13623,6 +13833,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13922,6 +14137,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on s
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14168,6 +14388,11 @@ exports[`history > singleplayer undo/redo > should disable undo/redo buttons whe
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14406,6 +14631,11 @@ exports[`history > singleplayer undo/redo > should end up with no history entry
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14644,6 +14874,11 @@ exports[`history > singleplayer undo/redo > should iterate through the history w
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14892,6 +15127,11 @@ exports[`history > singleplayer undo/redo > should not clear the redo stack on s
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -15224,6 +15464,11 @@ exports[`history > singleplayer undo/redo > should not collapse when applying co
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -15395,6 +15640,11 @@ exports[`history > singleplayer undo/redo > should not end up with history entry
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -15680,6 +15930,11 @@ exports[`history > singleplayer undo/redo > should not end up with history entry
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -15944,6 +16199,11 @@ exports[`history > singleplayer undo/redo > should not modify anything on unrela
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -16098,6 +16358,11 @@ exports[`history > singleplayer undo/redo > should not override appstate changes
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -16381,6 +16646,11 @@ exports[`history > singleplayer undo/redo > should support appstate name or view
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -16544,6 +16814,11 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -17293,6 +17568,11 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -17940,6 +18220,11 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -18587,6 +18872,11 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -19337,6 +19627,11 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -20106,6 +20401,11 @@ exports[`history > singleplayer undo/redo > should support changes in elements'
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -20587,6 +20887,11 @@ exports[`history > singleplayer undo/redo > should support duplication of groups
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -21099,6 +21404,11 @@ exports[`history > singleplayer undo/redo > should support element creation, del
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -21559,6 +21869,11 @@ exports[`history > singleplayer undo/redo > should support linear element creati
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
index 3a81505d23..88fc275449 100644
--- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
@@ -15,6 +15,11 @@ exports[`given element A and group of elements B and given both are selected whe
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -442,6 +447,11 @@ exports[`given element A and group of elements B and given both are selected whe
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -859,6 +869,11 @@ exports[`regression tests > Cmd/Ctrl-click exclusively select element under poin
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1426,6 +1441,11 @@ exports[`regression tests > Drags selected element when hitting only bounding bo
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -1634,6 +1654,11 @@ exports[`regression tests > adjusts z order when grouping > [end of test] appSta
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2019,6 +2044,11 @@ exports[`regression tests > alt-drag duplicates an element > [end of test] appSt
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2265,6 +2295,11 @@ exports[`regression tests > arrow keys > [end of test] appState 1`] = `
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2446,6 +2481,11 @@ exports[`regression tests > can drag element that covers another element, while
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -2772,6 +2812,11 @@ exports[`regression tests > change the properties of a shape > [end of test] app
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3028,6 +3073,11 @@ exports[`regression tests > click on an element and drag it > [dragged] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3270,6 +3320,11 @@ exports[`regression tests > click on an element and drag it > [end of test] appS
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3507,6 +3562,11 @@ exports[`regression tests > click to select a shape > [end of test] appState 1`]
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -3766,6 +3826,11 @@ exports[`regression tests > click-drag to select a group > [end of test] appStat
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4081,6 +4146,11 @@ exports[`regression tests > deleting last but one element in editing group shoul
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4518,6 +4588,11 @@ exports[`regression tests > deselects group of selected elements on pointer down
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -4802,6 +4877,11 @@ exports[`regression tests > deselects group of selected elements on pointer up w
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5079,6 +5159,11 @@ exports[`regression tests > deselects selected element on pointer down when poin
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5288,6 +5373,11 @@ exports[`regression tests > deselects selected element, on pointer up, when clic
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5489,6 +5579,11 @@ exports[`regression tests > double click to edit a group > [end of test] appStat
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -5883,6 +5978,11 @@ exports[`regression tests > drags selected elements from point inside common bou
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -6181,6 +6281,11 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -6974,6 +7079,11 @@ exports[`regression tests > given a group of selected elements with an element t
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -7309,6 +7419,11 @@ exports[`regression tests > given a selected element A and a not selected elemen
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -7589,6 +7704,11 @@ exports[`regression tests > given selected element A with lower z-index than uns
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -7825,6 +7945,11 @@ exports[`regression tests > given selected element A with lower z-index than uns
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8066,6 +8191,11 @@ exports[`regression tests > key 2 selects rectangle tool > [end of test] appStat
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8247,6 +8377,11 @@ exports[`regression tests > key 3 selects diamond tool > [end of test] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8428,6 +8563,11 @@ exports[`regression tests > key 4 selects ellipse tool > [end of test] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8609,6 +8749,11 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -8843,6 +8988,11 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9075,6 +9225,11 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9272,6 +9427,11 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9506,6 +9666,11 @@ exports[`regression tests > key d selects diamond tool > [end of test] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9687,6 +9852,11 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -9919,6 +10089,11 @@ exports[`regression tests > key o selects ellipse tool > [end of test] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -10100,6 +10275,11 @@ exports[`regression tests > key p selects freedraw tool > [end of test] appState
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -10297,6 +10477,11 @@ exports[`regression tests > key r selects rectangle tool > [end of test] appStat
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -10478,6 +10663,11 @@ exports[`regression tests > make a group and duplicate it > [end of test] appSta
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -11010,6 +11200,11 @@ exports[`regression tests > noop interaction after undo shouldn't create history
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -11291,6 +11486,11 @@ exports[`regression tests > pinch-to-zoom works > [end of test] appState 1`] = `
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -11415,6 +11615,11 @@ exports[`regression tests > shift click on selected element should deselect it o
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -11616,6 +11821,11 @@ exports[`regression tests > shift-click to multiselect, then drag > [end of test
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -11936,6 +12146,11 @@ exports[`regression tests > should group elements and ungroup them > [end of tes
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -12366,6 +12581,11 @@ exports[`regression tests > single-clicking on a subgroup of a selected group sh
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13007,6 +13227,11 @@ exports[`regression tests > spacebar + drag scrolls the canvas > [end of test] a
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13134,6 +13359,11 @@ exports[`regression tests > supports nested groups > [end of test] appState 1`]
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -13766,6 +13996,11 @@ exports[`regression tests > switches from group of selected elements to another
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14106,6 +14341,11 @@ exports[`regression tests > switches selected element on pointer down > [end of
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14371,6 +14611,11 @@ exports[`regression tests > two-finger scroll works > [end of test] appState 1`]
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14495,6 +14740,11 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14860,6 +15110,11 @@ exports[`regression tests > updates fontSize & fontFamily appState > [end of tes
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
@@ -14984,6 +15239,11 @@ exports[`regression tests > zoom hotkeys > [end of test] appState 1`] = `
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,
diff --git a/packages/excalidraw/tests/colorTopPicks.test.ts b/packages/excalidraw/tests/colorTopPicks.test.ts
new file mode 100644
index 0000000000..de577840cd
--- /dev/null
+++ b/packages/excalidraw/tests/colorTopPicks.test.ts
@@ -0,0 +1,51 @@
+import { COLOR_TOP_PICKS_SLOTS } from "@excalidraw/common";
+
+import { restoreAppState } from "../data/restore";
+
+describe("restore appState.colorTopPicks", () => {
+ it("dedupes notation variants and drops non-strings", () => {
+ const restored = restoreAppState(
+ {
+ colorTopPicks: {
+ elementStroke: null,
+ elementBackground: [
+ "#FFF",
+ "#ffffff",
+ "white",
+ "#a5d8ff",
+ "rgb(165, 216, 255)",
+ "#eebefa",
+ 42,
+ "transparent",
+ "rgba(0, 0, 0, 0)",
+ ],
+ },
+ } as any,
+ null,
+ );
+ expect(restored.colorTopPicks.elementBackground).toEqual([
+ "#FFF",
+ "#a5d8ff",
+ "#eebefa",
+ "transparent",
+ ]);
+ expect(restored.colorTopPicks.elementStroke).toBe(null);
+ });
+
+ it("caps at the strip slot count and nulls malformed input", () => {
+ const many = Array.from(
+ { length: 20 },
+ (_, i) => `#0000${String(i).padStart(2, "0")}`,
+ );
+ const restored = restoreAppState(
+ {
+ colorTopPicks: { elementStroke: many, elementBackground: "junk" },
+ } as any,
+ null,
+ );
+ expect(restored.colorTopPicks.elementStroke).toEqual(
+ many.slice(0, COLOR_TOP_PICKS_SLOTS),
+ );
+ expect(restored.colorTopPicks.elementBackground).toBe(null);
+ });
+});
diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts
index dbf5097359..6685ee968d 100644
--- a/packages/excalidraw/types.ts
+++ b/packages/excalidraw/types.ts
@@ -536,6 +536,17 @@ export interface AppState {
// a drag operation (like pointer position vs bindable element) but needed
// globally for calculating the binding strategy
bindMode: BindMode;
+ /** user-customized color-picker top picks (pinned via drag & drop from the
+ * color picker popup). `null` means no customization (defaults, or
+ * host-supplied `topPicks`, are used). Kept per picker. */
+ colorTopPicks: {
+ elementStroke: readonly string[] | null;
+ elementBackground: readonly string[] | null;
+ /** the bucket-fill tool keeps a list separate from `elementBackground`
+ * even though both drive `currentItemBackgroundColor` (its defaults and
+ * use case differ — no transparent) */
+ bucketFill: readonly string[] | null;
+ };
}
export type SearchMatch = {
diff --git a/packages/utils/tests/__snapshots__/export.test.ts.snap b/packages/utils/tests/__snapshots__/export.test.ts.snap
index 1edab7385d..6954af24ef 100644
--- a/packages/utils/tests/__snapshots__/export.test.ts.snap
+++ b/packages/utils/tests/__snapshots__/export.test.ts.snap
@@ -15,6 +15,11 @@ exports[`exportToSvg > with default arguments 1`] = `
"bindingPreference": "enabled",
"boxSelectionMode": "contain",
"collaborators": Map {},
+ "colorTopPicks": {
+ "bucketFill": null,
+ "elementBackground": null,
+ "elementStroke": null,
+ },
"contextMenu": null,
"croppingElementId": null,
"currentHoveredFontFamily": null,