diff --git a/apps/demo/app/custom-ui/[...puckPath]/client.tsx b/apps/demo/app/custom-ui/[...puckPath]/client.tsx index 32f6340c6..9ba3d43ca 100644 --- a/apps/demo/app/custom-ui/[...puckPath]/client.tsx +++ b/apps/demo/app/custom-ui/[...puckPath]/client.tsx @@ -11,6 +11,18 @@ import { ChevronUp, ChevronDown, Globe, Lock, Unlock } from "lucide-react"; const CustomHeader = ({ onPublish }: { onPublish: (data: Data) => void }) => { const { appState, dispatch } = usePuck(); + const { + ui: { mode }, + } = appState; + + const toggleMode = () => { + dispatch({ + type: "setUi", + ui: { + mode: mode === "edit" ? "interactive" : "edit", + }, + }); + }; return (
void }) => { > Custom UI example
-
+
+
)} diff --git a/packages/core/components/DraggableComponent/styles.module.css b/packages/core/components/DraggableComponent/styles.module.css index 14502d0ba..77279082c 100644 --- a/packages/core/components/DraggableComponent/styles.module.css +++ b/packages/core/components/DraggableComponent/styles.module.css @@ -13,6 +13,20 @@ overflow: hidden; } +.DraggableComponent--isInteractive > .DraggableComponent-contents { + pointer-events: auto !important; +} + +.DraggableComponent--isInteractive > .DraggableComponent-overlay { + cursor: default !important; + background: transparent !important; + outline: none !important; +} + +.DraggableComponent--isInteractive:hover > .DraggableComopnent-overlay { + outline: none !important; +} + .DraggableComponent-contents { position: relative; /* Reset stacking context */ pointer-events: none; @@ -43,7 +57,7 @@ } .DraggableComponent--isDragging > .DraggableComponent-overlay { - outline: 2px var(--puck-color-azure-09) solid !important; + outline: 2px var(--puck-color-azure-09) solid; } .DraggableComponent-loadingOverlay { @@ -75,7 +89,7 @@ .DraggableComponent:not(.DraggableComponent--isSelected):hover > .DraggableComponent-overlay { - outline: 2px var(--puck-color-azure-09) solid !important; + outline: 2px var(--puck-color-azure-09) solid; } .DraggableComponent--indicativeHover > .DraggableComponent-overlay { @@ -91,7 +105,7 @@ } .DraggableComponent--isSelected > .DraggableComponent-overlay { - outline: 2px var(--puck-color-azure-07) solid !important; + outline: 2px var(--puck-color-azure-07) solid; } .DraggableComponent--isSelected > .DraggableComponent-actionsOverlay { diff --git a/packages/core/components/Puck/context.tsx b/packages/core/components/Puck/context.tsx index 2e8561e69..d658416ea 100644 --- a/packages/core/components/Puck/context.tsx +++ b/packages/core/components/Puck/context.tsx @@ -38,6 +38,7 @@ export const defaultAppState: AppState = { itemSelector: null, componentList: {}, isDragging: false, + mode: "edit", viewports: { current: { width: defaultViewports[0].width, @@ -71,6 +72,7 @@ export type AppContext< resolveData: (newAppState: AppState) => void; plugins: Plugin[]; overrides: Partial; + mode: "interactive" | "edit"; history: Partial; viewports: Viewports; zoomConfig: ZoomConfig; @@ -90,8 +92,8 @@ const defaultContext: AppContext = { dispatch: () => null, config: { components: {} }, componentState: {}, - setComponentState: () => {}, - resolveData: () => {}, + setComponentState: () => { }, + resolveData: () => { }, plugins: [], overrides: {}, history: {}, @@ -109,6 +111,7 @@ const defaultContext: AppContext = { globalPermissions: {}, getPermissions: () => ({}), refreshPermissions: () => null, + mode: "edit" }; export const appContext = createContext(defaultContext); diff --git a/packages/core/components/Puck/index.tsx b/packages/core/components/Puck/index.tsx index b02ccb8cb..73e4f2c4f 100644 --- a/packages/core/components/Puck/index.tsx +++ b/packages/core/components/Puck/index.tsx @@ -195,19 +195,19 @@ export function Puck< // Store categories under componentList on state to allow render functions and plugins to modify componentList: config.categories ? Object.entries(config.categories).reduce( - (acc, [categoryName, category]) => { - return { - ...acc, - [categoryName]: { - title: category.title, - components: category.components, - expanded: category.defaultExpanded, - visible: category.visible, - }, - }; - }, - {} - ) + (acc, [categoryName, category]) => { + return { + ...acc, + [categoryName]: { + title: category.title, + components: category.components, + expanded: category.defaultExpanded, + visible: category.visible, + }, + }; + }, + {} + ) : {}, }, } as G["UserAppState"]; @@ -415,6 +415,7 @@ export function Puck< history, viewports, iframe, + mode: ui.mode, globalPermissions: { delete: true, drag: true, diff --git a/packages/core/lib/use-puck.ts b/packages/core/lib/use-puck.ts index d2e7a36fe..26689b12d 100644 --- a/packages/core/lib/use-puck.ts +++ b/packages/core/lib/use-puck.ts @@ -11,7 +11,6 @@ export const usePuck = () => { getPermissions, refreshPermissions, } = useAppContext(); - return { appState, config, diff --git a/packages/core/types/AppState.tsx b/packages/core/types/AppState.tsx index 9a7893543..c639fa133 100644 --- a/packages/core/types/AppState.tsx +++ b/packages/core/types/AppState.tsx @@ -14,6 +14,7 @@ export type UiState = { rightSideBarVisible: boolean; itemSelector: ItemSelector | null; arrayState: Record; + mode: "interactive" | "edit"; componentList: Record< string, {