Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type {
Metadata,
AsFieldProps,
DefaultComponentProps,
ComponentData,
HotkeyState,
} from "../../types";

import { SidebarSection } from "../SidebarSection";
Expand Down Expand Up @@ -124,6 +124,7 @@ type PuckProps<
};
initialHistory?: InitialHistory;
metadata?: Metadata;
hotkeys?: HotkeyState
Copy link
Copy Markdown
Collaborator

@FedericoBonel FedericoBonel Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to use a Partial here and handle that optionality (applying defaults) before passing it down to the appStore.

We might introduce more options in the future, and requiring enabled could become inconvenient, some users might only want to enable a single option.

};

const propsContext = createContext<Partial<PuckProps>>({});
Expand Down Expand Up @@ -159,6 +160,7 @@ function PuckProvider<
metadata,
onAction,
fieldTransforms,
hotkeys,
} = usePropsContext();

const iframe: IframeConfig = useMemo(
Expand Down Expand Up @@ -242,6 +244,7 @@ function PuckProvider<

const newAppState = {
...defaultAppState,
hotkeys,
data: {
...initialData,
root: { ...initialData?.root, props: root.props },
Expand Down Expand Up @@ -431,6 +434,7 @@ function PuckLayout<
const rightSideBarVisible = useAppStore(
(s) => s.state.ui.rightSideBarVisible
);
const enabledHotkeys = useAppStore((s) => s.state.hotkeys.enabled);

const {
width: leftWidth,
Expand Down Expand Up @@ -498,11 +502,11 @@ function PuckLayout<
if (ready && iframe.enabled) {
const frameDoc = getFrame();

if (frameDoc) {
if (frameDoc && enabledHotkeys) {
return monitorHotkeys(frameDoc);
}
}
}, [ready, iframe.enabled]);
}, [ready, iframe.enabled, enabledHotkeys]);

usePreviewModeHotkeys();

Expand Down
8 changes: 7 additions & 1 deletion packages/core/lib/use-hotkey.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from "react";
import { create } from "zustand";
import { subscribeWithSelector } from "zustand/middleware";
import { useAppStore } from '../store';

const keys = [
"ctrl",
Expand Down Expand Up @@ -168,7 +169,12 @@ export const monitorHotkeys = (doc: Document) => {
};

export const useMonitorHotkeys = () => {
useEffect(() => monitorHotkeys(document), []);
const enabledHotkeys = useAppStore((s) => s.state.hotkeys.enabled)

useEffect(() => {
if (!enabledHotkeys) return;
return monitorHotkeys(document);
}, [enabledHotkeys]);
};

export const useHotkey = (combo: KeyMapStrict, cb: Function) => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/store/default-app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defaultViewports } from "../components/ViewportControls/default-viewpor
import { PrivateAppState } from "../types/Internal";

export const defaultAppState: PrivateAppState = {
hotkeys: { enabled: true },
data: { content: [], root: {}, zones: {} },
ui: {
leftSideBarVisible: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/types/AppState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export type ItemWithId = {

export type ArrayState = { items: ItemWithId[]; openId: string };

export type HotkeyState = {
enabled: boolean;
}

export type UiState = {
leftSideBarVisible: boolean;
rightSideBarVisible: boolean;
Expand Down Expand Up @@ -39,6 +43,7 @@ export type UiState = {
};

export type AppState<UserData extends Data = Data> = {
hotkeys: HotkeyState;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the AppStore rather than AppState?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay! i have done a refactor update to the appstore

data: UserData;
ui: UiState;
};
Loading