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

Support dot notation for fields #142

Closed
chrisvxd opened this issue Oct 10, 2023 · 1 comment
Closed

Support dot notation for fields #142

chrisvxd opened this issue Oct 10, 2023 · 1 comment

Comments

@chrisvxd
Copy link
Member

#60 made the request for a new `object data type for more complex, nested data shapes to be managed by Puck fields.

This was proposed in PR #62, but it was decided that the array interface might not be appropriate for this, and that we are conflating 1) UI concerns and 2) data model concerns.

Consequently, we closed #60/#62 and opened #64 to handle 1) the UI rendering by introducing a React-ish renderFields API.

Proposal

Option 1 - Nested paths

#64 handles the UI-layer for rendering complex objects. Additionally, we could allow for reaching into nested objects via the field API

export const Block: ComponentConfig<BlockProps> = {
  fields: {
    "data.label": {  type: "text", },
  },
 // Optionally render the fields  
  renderFields: () => {
    return <>
      <Fieldset title="Data">
        <Field name="data.label" />
      </Fieldset>
    </>
  },
}

Option 2 - object field type

The original proposal from #62, we could implement an object field type that reuses the array API and UI.

export const Block: ComponentConfig<BlockProps> = {
  fields: {
    data: {
      type: "object",
      // Collapse `arrayFields` into `fields`?
      fields: {
        label: { type: "text" }
      },
    },
  },
}

Option 3 - combo

We could also offer both APIs and allow the user to determine what is best for their use-case.

Considerations

  • How to type nested paths
@chrisvxd
Copy link
Member Author

chrisvxd commented Jan 6, 2025

Object fields where implemented in #256

@chrisvxd chrisvxd closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant