Skip to content

Type safe allow and disallow#1572

Open
DamianKocjan wants to merge 9 commits into
puckeditor:mainfrom
DamianKocjan:feat-typed-allow-disallow
Open

Type safe allow and disallow#1572
DamianKocjan wants to merge 9 commits into
puckeditor:mainfrom
DamianKocjan:feat-typed-allow-disallow

Conversation

@DamianKocjan
Copy link
Copy Markdown
Contributor

Closes #1099

Description

This PR introduces type safety for the allow and disallow props within Puck's Slot/DropZone.

Changes made

Updated DropZoneProps to use the generic component type for allow and disallow arrays.

How to test

Open a component configuration in a TypeScript environment (e.g., apps/demo/config/blocks/Flex/index.tsx).

Ensure the component is typed using the new generic: ComponentConfig<Props, keyof Components>.

Inside the render function, find a Slot.

Try to add an allow prop:

<Slot allow={["NonExistentComponent"]} /> 

Verify: TypeScript should throw an error because "NonExistentComponent" is not a key in your Components type.

Verify: Triggering autocomplete within the allow array should suggest valid component names from your config.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 17, 2026

@DamianKocjan is attempting to deploy a commit to the Puck Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

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

Thanks @DamianKocjan! Some thoughts in the comments.

@@ -1 +0,0 @@
export * from "./Editor";
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.

Accidental?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's no Editor file or folder

Comment on lines +30 to +33
export const TemplateInternal: ComponentConfig<
TemplateProps,
keyof Components
> = {
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.

I'm a little hesitant of this API because the config types are already on the edge as it is.

I think a cleaner API would be using our new format:

ComponentConfig<{
  props: TemplateProps,
  availableComponents: keyof Components
}>

Worth adding, this will be a feat so we'll hold off merge until closer to 0.22

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll refactor later this week to use new format ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chrisvxd Took me more time than I anticipated, but it's done now. Sorry for waiting

@DamianKocjan DamianKocjan requested a review from chrisvxd May 12, 2026 21:36
import { DragAxis } from "../../types";

export type DropZoneProps = {
export type DropZoneProps<T = string> = {
Copy link
Copy Markdown
Contributor Author

@DamianKocjan DamianKocjan May 12, 2026

Choose a reason for hiding this comment

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

I'm not sure if Tshould be as it is. Maybe something more descriptive like Components or ComponentKeys

} from "./Internal";

export type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
export type SlotComponent<T = string> = (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same goes here

) => ReactNode;

export type PuckComponent<Props> = (
export type PuckComponent<Props, T = string> = (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And here...

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.

Ability to make allow and disallow type safe

2 participants