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 11 commits into
base: main
Choose a base branch
from

Conversation

SicParv1sMagna
Copy link

@SicParv1sMagna SicParv1sMagna commented Nov 1, 2024

Recently I was trying to add PR for switching between editing and interactive mode PR. So, after a small conversation with Chris Villa in discord thread, he said that you want to add toggle in header for switching modes, I have added new functionality in context, which allows user to interact with components inside preview in "out of box" editor and in custom editor.

Closes issue #565

Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
puck-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 27, 2024 4:29pm
puck-docs ✅ Ready (Inspect) Visit Preview Dec 27, 2024 4:29pm

Copy link

vercel bot commented Nov 1, 2024

@SicParv1sMagna is attempting to deploy a commit to the Measured Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Nice one, I really like the idea of keeping this in state! I've left some comments.

My only concern I have is that this is going to clash with #556, which rebuilds DraggableComponent.

If you address my comments, we can figure out the conflicts before the next feature release, which will probably include #556.

};
},
{}
)
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

Comment on lines 180 to 181
<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

@@ -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

Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

I've been doing some thinking and this will actually be better on the AppState rather than a separate status. This saves us polluting the usePuck hook with every piece of appState, and introducing a custom dispatcher (setIsInteractive)

I also think that isInteractive is probably not quite the right name. I would prefer to introduce a new parameter to AppState, either mode or previewMode: "interactive" | "edit". Does that make sense?

Having said that, I know you're keen to get this done, so I'm happy to do a canary containing this existing implementation if it would help you out.

@SicParv1sMagna
Copy link
Author

SicParv1sMagna commented Nov 14, 2024

I've been doing some thinking and this will actually be better on the AppState rather than a separate status. This saves us polluting the usePuck hook with every piece of appState, and introducing a custom dispatcher (setIsInteractive)

I also think that isInteractive is probably not quite the right name. I would prefer to introduce a new parameter to AppState, either mode or previewMode: "interactive" | "edit". Does that make sense?

Having said that, I know you're keen to get this done, so I'm happy to do a canary containing this existing implementation if it would help you out.

I think that you're right, but as I understand, usePuck is allowed either on "out of box" solution (default ), either on custom layout side, so I would like to use it from usePuck hook, cus I'am using custom layout.
About naming, got you, I will try to fix this as soon as possible, probably, on the beginning of next week or weekend

@chrisvxd what do you think about this?

@chrisvxd
Copy link
Member

@SicParv1sMagna the app state is exposed via usePuck, and can be controlled via the dispatcher: https://puckeditor.com/docs/api-reference/functions/use-puck#appstate

I'm not convinced on the naming yet. For now, let's just move isInteractive to the app state and worry about the rename later (I can do a follow-up).

@SicParv1sMagna
Copy link
Author

@chrisvxd Hello, sorry for fixing this pr so long. Removed isInteractive from usePuck hook and renamed it to mode

@SicParv1sMagna
Copy link
Author

@chrisvxd is my merge request still actual?

Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Hey @SicParv1sMagna! Sorry for the delay.

Just reviewing now and this doesn't quite behave as expected. When I switch to interactive mode, the items are still draggable and action bar overlay shows. I think it might be better to modify DropZone to avoid rendering altogether when in interactive mode.

@SicParv1sMagna
Copy link
Author

@chrisvxd Missed that moment, fixed it, check it please)

@SicParv1sMagna
Copy link
Author

@chrisvxd Can you please check new version

Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Hi @SicParv1sMagna - I've addressed merge conflicts, but you still need to update your tests for this to pass CI. Please run cd packages/core && npm run test -u and commit the updated snapshot change.

@SicParv1sMagna
Copy link
Author

Hi @SicParv1sMagna - I've addressed merge conflicts, but you still need to update your tests for this to pass CI. Please run cd packages/core && npm run test -u and commit the updated snapshot change.

Give me few minutes

@SicParv1sMagna
Copy link
Author

cd packages/core && npm run test -u

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants