-
Notifications
You must be signed in to change notification settings - Fork 493
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
feat: devtools #2196
base: v3
Are you sure you want to change the base?
feat: devtools #2196
Conversation
d20dc62
to
70f324b
Compare
c467bee
to
94736a6
Compare
94736a6
to
fe54379
Compare
c1d65b8
to
4887935
Compare
Deploying ui3 with Cloudflare Pages
|
commit: |
The PR is ready! I've put some efforts in generalizing the implementation because I think this can be made into a standalone module. I'll look into it soon 😄. I have some ideas for improvements we can implement later on:
|
{ id: 'array', schema: arrayInputSchema, component: ArrayInput } | ||
] | ||
|
||
export function usePropSchema() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This composable is used to infer which component to use for a property. It uses zod
to match and transform schema since the matching logic can be a bit tricky and is most likely going to evolve.
@@ -0,0 +1,36 @@ | |||
/* eslint-disable no-undef */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a duplicate from the prettier worker in the documentation with some improvements to await the imports instead of returning an error if they have not resolved yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be worth updating the docs one with those improvements?
src/devtools/meta.ts
Outdated
} | ||
|
||
// A Plugin to parse additional metadata for the Nuxt UI Devtools. | ||
export function devtoolsMetaPlugin() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This vite plugin is used to parse the content of the extendDevtoolsMeta
macro and inject it into the component meta.
src/devtools/meta.ts
Outdated
}, | ||
|
||
configureServer(server: ViteDevServer) { | ||
server.middlewares.use('/__nuxt_ui__/devtools/api/component-meta', async (_req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used by the devtools to fetch component metas.
src/devtools/meta.ts
Outdated
res.end(JSON.stringify(meta)) | ||
}) | ||
|
||
server.middlewares.use('/__nuxt_ui__/devtools/api/component-example', async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used by the devtools to fetch example code.
// https://github.com/nuxt/nuxt/pull/29366 | ||
// meta: { | ||
// isolate: true | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, the renderer will inherit from the user's app.vue
code which could lead to unexpected behaviour on the devtools interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll figure out a workaround if needed! It'll be a bit more restrictive tho
if (value === false) return | ||
if (!value) return | ||
if (props.component?.defaultVariants?.[key] === value) return | ||
if (props.component?.meta?.props.find(prop => prop.name === key && prop.default === value)) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue here leading to some default (multi-words) props behind displayed in the preview most likely caused by diffs in casing.
This PR introduces devtools for Nuxt UI. It allows users to browse Nuxt UI components and interact with their props.
How it works
There's two big parts to this implementation:
DevtoolsRenderer
Devtools App