Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: style panel and settings panel keyboard shortcuts (#3936)
Oleg Isonenae22bf929d5a
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsxindex e38ce0aac9..01437b2cc3 100644--- a/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx@@ -136,7 +136,7 @@ const BreakpointEditorItem = ({suffix={<Textvariant="unit"- color="subtle"+ color="moreSubtle"align="center"css={{ width: theme.spacing[10] }}>diff --git a/apps/builder/app/builder/features/inspector/inspector.tsx b/apps/builder/app/builder/features/inspector/inspector.tsxindex 169b7f7f1d..e2eaaea9cb 100644--- a/apps/builder/app/builder/features/inspector/inspector.tsx+++ b/apps/builder/app/builder/features/inspector/inspector.tsx@@ -1,4 +1,4 @@-import { useRef, useState } from "react";+import { useRef } from "react";import { computed } from "nanostores";import { useStore } from "@nanostores/react";import type { Instance } from "@webstudio-is/sdk";@@ -16,6 +16,7 @@ import {ScrollArea,Separator,Tooltip,+ Kbd,} from "@webstudio-is/design-system";import { StylePanel } from "~/builder/features/style-panel";import { SettingsPanelContainer } from "~/builder/features/settings-panel";@@ -31,6 +32,7 @@ import type { Settings } from "~/builder/shared/client-settings";import { MetaIcon } from "~/builder/shared/meta-icon";import { getInstanceLabel } from "~/shared/instance-utils";import { BindingPopoverProvider } from "~/builder/shared/binding-popover";+import { $activeInspectorPanel } from "~/builder/shared/nano-states";const InstanceInfo = ({ instance }: { instance: Instance }) => {const metas = useStore($registeredComponentMetas);@@ -74,10 +76,10 @@ const $isDragging = computed([$dragAndDropState], (state) => state.isDragging);export const Inspector = ({ navigatorLayout }: InspectorProps) => {const selectedInstance = useStore($selectedInstance);const tabsRef = useRef<HTMLDivElement>(null);- const [tab, setTab] = useState("style");const isDragging = useStore($isDragging);const metas = useStore($registeredComponentMetas);const selectedPage = useStore($selectedPage);+ const activeInspectorPanel = useStore($activeInspectorPanel);if (navigatorLayout === "docked" && isDragging) {return <NavigatorTree />;@@ -99,12 +101,10 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {const meta = metas.get(selectedInstance.component);const documentType = selectedPage?.meta.documentType ?? "html";- const isStyleTabVisible = documentType === "html" && (meta?.stylable ?? true);-- const availableTabs = [- isStyleTabVisible ? "style" : undefined,- "settings",- ].filter((tab) => tab);+ const availablePanels = {+ style: documentType === "html" && (meta?.stylable ?? true),+ settings: true,+ };return (<EnhancedTooltipProvider@@ -116,16 +116,27 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {<BindingPopoverProvider value={{ containerRef: tabsRef }}><PanelTabsref={tabsRef}- value={availableTabs.includes(tab) ? tab : availableTabs[0]}- onValueChange={setTab}+ value={+ availablePanels[activeInspectorPanel]+ ? activeInspectorPanel+ : "settings"+ }+ onValueChange={(panel) => {+ $activeInspectorPanel.set(panel as keyof typeof availablePanels);+ }}asChild><Flex direction="column"><PanelTabsList>- {isStyleTabVisible && (+ {availablePanels.style && (<Tooltipvariant="wrapped"- content="The Style panel allows manipulation of CSS visually."+ content={+ <Text>+ CSS for the selected instance + <Kbd value={["S"]} color="moreSubtle" />+ </Text>+ }><div><PanelTabsTrigger value="style">Style</PanelTabsTrigger>@@ -134,7 +145,13 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {)}<Tooltipvariant="wrapped"- content="The Settings panel allows for customizing component properties and HTML attributes."+ content={+ <Text>+ Settings, properties and attributes of the selected+ instance + <Kbd value={["D"]} color="moreSubtle" />+ </Text>+ }><div><PanelTabsTrigger value="settings">diff --git a/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx b/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsxindex cbc0c192e5..fae44d56ed 100644--- a/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx+++ b/apps/builder/app/builder/features/sidebar-left/panels/components/components.tsx@@ -305,8 +305,8 @@ export const TabContent = ({ publish, onSetActiveTab }: TabContentProps) => {export const Icon = PlusIcon;export const label = (- <Flex gap="1">- <Text>Components</Text>- <Kbd value={["(A)"]} />- </Flex>+ <Text>+ Components + <Kbd value={["A"]} color="moreSubtle" />+ </Text>);diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsxindex 19c47faa00..7840bcd52a 100644--- a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx@@ -188,6 +188,11 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {<SidebarTabsContentvalue={activeTab === "none" ? "" : activeTab}+ onKeyDown={(event) => {+ if (event.key === "Escape") {+ setActiveTab("none");+ }+ }}css={{width: theme.spacing[30],// We need the node to be rendered but hiddendiff --git a/apps/builder/app/builder/shared/commands.ts b/apps/builder/app/builder/shared/commands.tsindex 9e4b550229..9abbf45fd0 100644--- a/apps/builder/app/builder/shared/commands.ts+++ b/apps/builder/app/builder/shared/commands.ts@@ -21,7 +21,7 @@ import {import type { InstanceSelector } from "~/shared/tree-utils";import { serverSyncStore } from "~/shared/sync";import { $publisher } from "~/shared/pubsub";-import { $activeSidebarPanel } from "./nano-states";+import { $activeInspectorPanel, $activeSidebarPanel } from "./nano-states";import { toast } from "@webstudio-is/design-system";const makeBreakpointCommand = <CommandName extends string>(@@ -133,6 +133,25 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({$activeSidebarPanel.set("components");},disableHotkeyOnFormTags: true,+ disableHotkeyOnContentEditable: true,+ },+ {+ name: "openStylePanel",+ defaultHotkeys: ["s"],+ handler: () => {+ $activeInspectorPanel.set("style");+ },+ disableHotkeyOnFormTags: true,+ disableHotkeyOnContentEditable: true,+ },+ {+ name: "openSettingsPanel",+ defaultHotkeys: ["d"],+ handler: () => {+ $activeInspectorPanel.set("settings");+ },+ disableHotkeyOnFormTags: true,+ disableHotkeyOnContentEditable: true,},makeBreakpointCommand("selectBreakpoint1", 1),makeBreakpointCommand("selectBreakpoint2", 2),diff --git a/apps/builder/app/builder/shared/nano-states/index.ts b/apps/builder/app/builder/shared/nano-states/index.tsindex 283243b6e0..ecf600b636 100644--- a/apps/builder/app/builder/shared/nano-states/index.ts+++ b/apps/builder/app/builder/shared/nano-states/index.ts@@ -37,6 +37,8 @@ export const $scale = computed(export const $activeSidebarPanel = atom<TabName>("none");+export const $activeInspectorPanel = atom<"style" | "settings">("style");+// keep in sync with user-plan-features.serverexport const $userPlanFeatures = atom<UserPlanFeatures>({allowShareAdminLinks: false,diff --git a/apps/builder/app/shared/commands-emitter.ts b/apps/builder/app/shared/commands-emitter.tsindex ede29df957..5d1d86c116 100644--- a/apps/builder/app/shared/commands-emitter.ts+++ b/apps/builder/app/shared/commands-emitter.ts@@ -43,8 +43,20 @@ export type Command<CommandName extends string> = CommandMeta<CommandName> & {const $commandMetas = atom(new Map<string, CommandMeta<string>>());clientSyncStore.register("commandMetas", $commandMetas);+// Copied from https://github.com/ai/keyux/blob/main/hotkey.js#L1C1-L2C1+// eslint-disable-next-line no-control-regex+const nonEnglishLayout = /^[^\x00-\x7F]$/;++const getKey = (event: KeyboardEvent) => {+ if (nonEnglishLayout.test(event.key) && /^Key.$/.test(event.code)) {+ return event.code.replace(/^Key/, "").toLowerCase();+ }+ return event.key;+};+const findCommandsMatchingHotkeys = (event: KeyboardEvent) => {- const { key, ctrlKey, metaKey, shiftKey, altKey } = event;+ const { ctrlKey, metaKey, shiftKey, altKey } = event;+ const key = getKey(event);const pressedKeys = new Set<string>();pressedKeys.add(key.toLocaleLowerCase());if (ctrlKey) {diff --git a/packages/design-system/src/components/input-field.tsx b/packages/design-system/src/components/input-field.tsxindex 0b2efe5f40..40c5f82c2a 100644--- a/packages/design-system/src/components/input-field.tsx+++ b/packages/design-system/src/components/input-field.tsx@@ -9,6 +9,8 @@ import {type ComponentProps,type Ref,type FocusEventHandler,+ useRef,+ type KeyboardEventHandler,} from "react";import { textVariants } from "./text";import { css, theme, type CSS } from "../stitches.config";@@ -239,6 +241,7 @@ export const InputField = forwardRef(onBlur,variant,size,+ onKeyDown,...inputProps}: InputProps & InputFieldProps,ref: Ref<HTMLDivElement>@@ -249,6 +252,14 @@ export const InputField = forwardRef(onFocusWithin: onFocus,onBlurWithin: onBlur,});+ const unfocusContainerRef = useRef<HTMLDivElement>(null);+ const handleKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {+ onKeyDown?.(event);+ if (event.key === "Escape" && event.defaultPrevented === false) {+ event.preventDefault();+ unfocusContainerRef.current?.focus();+ }+ };return (<Container@@ -261,7 +272,13 @@ export const InputField = forwardRef({...focusWithinProps}ref={mergeRefs(ref, containerRef ?? null)}>- <Input {...inputProps} ref={inputRef} />+ <div+ // This element is used to move focus to it when user hits Escape.+ // This way user can unfocus the input and then use any single-key shortcut.+ tabIndex={-1}+ ref={unfocusContainerRef}+ />+ <Input {...inputProps} onKeyDown={handleKeyDown} ref={inputRef} /></Container>);}diff --git a/packages/design-system/src/components/kbd.tsx b/packages/design-system/src/components/kbd.tsxindex 1363eee960..830adffca3 100644--- a/packages/design-system/src/components/kbd.tsx+++ b/packages/design-system/src/components/kbd.tsx@@ -33,9 +33,15 @@ const format = (value: ShortcutDefinition) => {);};-export const Kbd = ({ value }: { value: ShortcutDefinition }) => {+export const Kbd = ({+ value,+ color = "subtle",+}: {+ value: ShortcutDefinition;+ color?: "subtle" | "moreSubtle";+}) => {return (- <Text color="subtle" as="kbd">+ <Text color={color} as="kbd">{format(value)}</Text>);diff --git a/packages/design-system/src/components/search-field.tsx b/packages/design-system/src/components/search-field.tsxindex 8b4d61fcec..35467c6990 100644--- a/packages/design-system/src/components/search-field.tsx+++ b/packages/design-system/src/components/search-field.tsx@@ -72,7 +72,9 @@ const SearchFieldBase: ForwardRefRenderFunction<aria-label="Reset search"title="Reset search"tabIndex={-1}- onClick={handleCancel}+ onClick={() => {+ handleCancel();+ }}icon={<CrossCircledFilledIcon />}/></Flex>@@ -83,6 +85,7 @@ const SearchFieldBase: ForwardRefRenderFunction<}}onKeyDown={(event) => {if (event.key === "Escape" && value.length !== 0) {+ event.preventDefault();handleCancel();}onKeyDown?.(event);diff --git a/packages/design-system/src/components/toolbar.tsx b/packages/design-system/src/components/toolbar.tsxindex 377fe6f9d9..39b6b49e84 100644--- a/packages/design-system/src/components/toolbar.tsx+++ b/packages/design-system/src/components/toolbar.tsx@@ -63,7 +63,7 @@ const toggleItemStyle = css(textVariants.labelsTitleCase, {},variant: {subtle: {- color: theme.colors.foregroundSubtle,+ color: theme.colors.foregroundTextMoreSubtle,"&:hover, &[data-state=on], &[aria-checked=true]": {color: "inherit",},