Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality for switching between editing and interactive mode #674

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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: 5 additions & 5 deletions packages/core/components/DraggableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { useAppContext } from "../Puck/context";
import { DefaultDraggable } from "../Draggable";
import { Loader } from "../Loader";
import { ActionBar } from "../ActionBar";
import { DefaultOverride } from "../DefaultOverride";

const getClassName = getClassNameFactory("DraggableComponent", styles);

Expand Down Expand Up @@ -81,8 +80,9 @@ export const DraggableComponent = ({
indicativeHover?: boolean;
style?: CSSProperties;
}) => {
const { zoomConfig, status, overrides, selectedItem, getPermissions } =
const { zoomConfig, status, overrides, selectedItem, getPermissions, isInteractive } =
useAppContext();

const isModifierHeld = useModifierHeld("Alt");

const El = status !== "LOADING" ? Draggable : DefaultDraggable;
Expand Down Expand Up @@ -132,7 +132,7 @@ export const DraggableComponent = ({
style={{
...style,
...provided.draggableProps.style,
cursor: isModifierHeld || isDragDisabled ? "pointer" : "grab",
cursor: isInteractive || isModifierHeld || isDragDisabled ? "pointer" : "grab",
}}
onMouseOver={onMouseOver}
onMouseOut={onMouseOut}
Expand Down Expand Up @@ -177,8 +177,8 @@ export const DraggableComponent = ({
</div>
)}

<div className={getClassName("overlay")} />
<div className={getClassName("contents")}>{children}</div>
<div className={getClassName("overlay")} style={{ ...(isInteractive && { cursor: 'default', background: 'transparent' }) }} />
<div className={getClassName("contents")} style={{ ...(isInteractive && { pointerEvents: 'auto' }) }}>{children}</div>
Copy link
Member

Choose a reason for hiding this comment

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

These would probably be better as a CSS class, passed to the getClassName function here.

Copy link
Author

Choose a reason for hiding this comment

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

done

</div>
)}
</El>
Expand Down
13 changes: 11 additions & 2 deletions packages/core/components/Puck/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export type AppContext<
plugins: Plugin[];
overrides: Partial<Overrides>;
history: Partial<PuckHistory>;
isInteractive: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Any ideas for how you could add this to the custom-ui demo? I like to use features in demos for easier reviewing, and so we can be sure things build properly.

Copy link
Author

Choose a reason for hiding this comment

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

Is there any information about future release? How soon can I start using this changes?

Copy link
Author

Choose a reason for hiding this comment

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

done

setIsInteractive: React.Dispatch<SetStateAction<boolean>>
viewports: Viewports;
zoomConfig: ZoomConfig;
setZoomConfig: (zoomConfig: ZoomConfig) => void;
Expand All @@ -90,10 +92,12 @@ const defaultContext: AppContext = {
dispatch: () => null,
config: { components: {} },
componentState: {},
setComponentState: () => {},
resolveData: () => {},
setComponentState: () => { },
resolveData: () => { },
plugins: [],
overrides: {},
isInteractive: false,
setIsInteractive: () => { },
history: {},
viewports: defaultViewports,
zoomConfig: {
Expand Down Expand Up @@ -127,12 +131,15 @@ export const AppProvider = ({
| "componentState"
| "setComponentState"
| "resolveData"
| "setIsInteractive"
>;
}) => {
const [zoomConfig, setZoomConfig] = useState(defaultContext.zoomConfig);

const [status, setStatus] = useState<Status>("LOADING");

const [isInteractive, setIsInteractive] = useState(false);

// App is ready when client has loaded, after initial render
// This triggers DropZones to activate
useEffect(() => {
Expand Down Expand Up @@ -222,6 +229,8 @@ export const AppProvider = ({
componentState,
setComponentState,
resolveData,
isInteractive,
setIsInteractive,
}}
>
{children}
Expand Down
27 changes: 14 additions & 13 deletions packages/core/components/Puck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
},
{}
)
Copy link
Member

Choose a reason for hiding this comment

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

I think your local prettier is conflicting with the shared prettier. Can you run npm run format and commit the results?

Copy link
Author

Choose a reason for hiding this comment

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

done

: {},
},
} as G["UserAppState"];
Expand Down Expand Up @@ -412,6 +412,7 @@ export function Puck<
config,
plugins: plugins || [],
overrides: loadedOverrides,
isInteractive: false,
history,
viewports,
iframe,
Expand Down
4 changes: 4 additions & 0 deletions packages/core/lib/use-puck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const usePuck = <UserConfig extends Config = Config>() => {
state: appState,
config,
history,
isInteractive,
setIsInteractive,
dispatch,
selectedItem: currentItem,
getPermissions,
Expand All @@ -15,9 +17,11 @@ export const usePuck = <UserConfig extends Config = Config>() => {
return {
appState,
config,
isInteractive,
dispatch,
getPermissions,
refreshPermissions,
setIsInteractive,
history: {
back: history.back!,
forward: history.forward!,
Expand Down
Loading