chore: make zod imports tree-shakeable (#2846)

This commit is contained in:
Mick Lawitzke
2024-12-23 12:13:37 +01:00
committed by GitHub
parent 78be40a286
commit d6179912de
13 changed files with 22 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { z } from 'zod' import * as z from 'zod'
export const arrayInputSchema = z.object({ export const arrayInputSchema = z.object({
kind: z.literal('array'), kind: z.literal('array'),

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { z } from 'zod' import * as z from 'zod'
export const booleanInputSchema = z.literal('boolean').or(z.object({ export const booleanInputSchema = z.literal('boolean').or(z.object({
kind: z.literal('enum'), kind: z.literal('enum'),

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { z } from 'zod' import * as z from 'zod'
export const numberInputSchema = z.literal('number') export const numberInputSchema = z.literal('number')
export type NumberInputSchema = z.infer<typeof numberInputSchema> export type NumberInputSchema = z.infer<typeof numberInputSchema>

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { z } from 'zod' import * as z from 'zod'
export const objectInputSchema = z.object({ export const objectInputSchema = z.object({
kind: z.literal('object'), kind: z.literal('object'),

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { z } from 'zod' import * as z from 'zod'
export const stringEnumInputSchema = z.object({ export const stringEnumInputSchema = z.object({
kind: z.literal('enum'), kind: z.literal('enum'),

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { z } from 'zod' import * as z from 'zod'
export const stringInputSchema = z.literal('string').or(z.string().transform(t => t.split('|').find(s => s.trim() === 'string')).pipe(z.string())) export const stringInputSchema = z.literal('string').or(z.string().transform(t => t.split('|').find(s => s.trim() === 'string')).pipe(z.string()))

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { z } from 'zod' import * as z from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui' import type { FormSubmitEvent } from '@nuxt/ui'
const schema = z.object({ const schema = z.object({

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { z } from 'zod' import * as z from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui' import type { FormSubmitEvent } from '@nuxt/ui'
const schema = z.object({ const schema = z.object({

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { z } from 'zod' import * as z from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui' import type { FormSubmitEvent } from '@nuxt/ui'
const schema = z.object({ const schema = z.object({

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { z } from 'zod' import * as z from 'zod'
import type { FormSubmitEvent } from '#ui/types' import type { FormSubmitEvent } from '#ui/types'
const schema = z.object({ const schema = z.object({

View File

@@ -8,7 +8,7 @@ links:
## Usage ## Usage
Use the Form component to validate form data using schema libraries such as [Zod](https://github.com/colinhacks/zod), [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi), [Valibot](https://github.com/fabian-hiller/valibot), [Superstruct](https://github.com/ianstormtaylor/superstruct) or your own validation logic. Use the Form component to validate form data using schema libraries such as [Valibot](https://github.com/fabian-hiller/valibot), [Zod](https://github.com/colinhacks/zod), [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi), [Superstruct](https://github.com/ianstormtaylor/superstruct) or your own validation logic.
It works with the [FormField](/components/form-field) component to display error messages around form elements automatically. It works with the [FormField](/components/form-field) component to display error messages around form elements automatically.
@@ -17,13 +17,21 @@ It works with the [FormField](/components/form-field) component to display error
It requires two props: It requires two props:
- `state` - a reactive object holding the form's state. - `state` - a reactive object holding the form's state.
- `schema` - a schema object from a validation library like [Zod](https://github.com/colinhacks/zod), [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi), [Valibot](https://github.com/fabian-hiller/valibot) or [Superstruct](https://github.com/ianstormtaylor/superstruct). - `schema` - a schema object from a validation library like [Valibot](https://github.com/fabian-hiller/valibot), [Zod](https://github.com/colinhacks/zod), [Yup](https://github.com/jquense/yup), [Joi](https://github.com/hapijs/joi) or [Superstruct](https://github.com/ianstormtaylor/superstruct).
::warning ::warning
**No validation library is included** by default, ensure you **install the one you need**. **No validation library is included** by default, ensure you **install the one you need**.
:: ::
::tabs ::tabs
::component-example{label="Valibot"}
---
name: 'form-example-valibot'
props:
class: 'w-60'
---
::
::component-example{label="Zod"} ::component-example{label="Zod"}
--- ---
name: 'form-example-zod' name: 'form-example-zod'
@@ -48,14 +56,6 @@ It requires two props:
--- ---
:: ::
::component-example{label="Valibot"}
---
name: 'form-example-valibot'
props:
class: 'w-60'
---
::
::component-example{label="Superstruct"} ::component-example{label="Superstruct"}
--- ---
name: 'form-example-superstruct' name: 'form-example-superstruct'

View File

@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { z } from 'zod' import * as z from 'zod'
import type { FormSubmitEvent } from '@nuxt/ui' import type { FormSubmitEvent } from '@nuxt/ui'
import FormExampleElements from '../../../../docs/app/components/content/examples/form/FormExampleElements.vue' import FormExampleElements from '../../../../docs/app/components/content/examples/form/FormExampleElements.vue'
import FormExampleNestedList from '../../../../docs/app/components/content/examples/form/FormExampleNestedList.vue' import FormExampleNestedList from '../../../../docs/app/components/content/examples/form/FormExampleNestedList.vue'

View File

@@ -1,7 +1,7 @@
import { reactive, ref, nextTick } from 'vue' import { reactive, ref, nextTick } from 'vue'
import { describe, it, expect, test, beforeEach, vi } from 'vitest' import { describe, it, expect, test, beforeEach, vi } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime' import { mountSuspended } from '@nuxt/test-utils/runtime'
import { z } from 'zod' import * as z from 'zod'
import * as yup from 'yup' import * as yup from 'yup'
import Joi from 'joi' import Joi from 'joi'
import * as valibot from 'valibot' import * as valibot from 'valibot'