@nuxt/ui 2.18.7 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/module.d.mts +1 -1
  2. package/dist/module.d.ts +1 -1
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +3 -3
  5. package/dist/runtime/components/data/Table.vue +82 -27
  6. package/dist/runtime/components/data/Table.vue.d.ts +45 -37
  7. package/dist/runtime/components/elements/AvatarGroup.js +2 -2
  8. package/dist/runtime/components/elements/Carousel.vue +1 -1
  9. package/dist/runtime/components/elements/Dropdown.vue +6 -2
  10. package/dist/runtime/components/elements/MeterGroup.d.ts +1 -1
  11. package/dist/runtime/components/elements/Progress.vue +1 -1
  12. package/dist/runtime/components/forms/Checkbox.vue.d.ts +1 -1
  13. package/dist/runtime/components/forms/Form.vue +104 -43
  14. package/dist/runtime/components/forms/Form.vue.d.ts +5 -3
  15. package/dist/runtime/components/forms/Input.vue +5 -2
  16. package/dist/runtime/components/forms/Input.vue.d.ts +3 -0
  17. package/dist/runtime/components/forms/InputMenu.vue +419 -8
  18. package/dist/runtime/components/forms/InputMenu.vue.d.ts +19 -0
  19. package/dist/runtime/components/forms/Radio.vue.d.ts +1 -1
  20. package/dist/runtime/components/forms/RadioGroup.vue +3 -4
  21. package/dist/runtime/components/forms/RadioGroup.vue.d.ts +1 -1
  22. package/dist/runtime/components/forms/SelectMenu.vue +501 -11
  23. package/dist/runtime/components/forms/SelectMenu.vue.d.ts +30 -2
  24. package/dist/runtime/components/forms/Textarea.vue +7 -4
  25. package/dist/runtime/components/forms/Textarea.vue.d.ts +3 -0
  26. package/dist/runtime/components/layout/Divider.vue +1 -1
  27. package/dist/runtime/components/layout/Divider.vue.d.ts +5 -2
  28. package/dist/runtime/components/navigation/CommandPalette.vue +1 -1
  29. package/dist/runtime/components/navigation/CommandPalette.vue.d.ts +1 -1
  30. package/dist/runtime/components/navigation/CommandPaletteGroup.vue.d.ts +1 -1
  31. package/dist/runtime/components/navigation/Pagination.vue +4 -4
  32. package/dist/runtime/components/navigation/Pagination.vue.d.ts +1 -1
  33. package/dist/runtime/components/navigation/Tabs.vue +1 -1
  34. package/dist/runtime/components/navigation/VerticalNavigation.vue.d.ts +6 -2
  35. package/dist/runtime/components/overlays/Modal.vue +1 -1
  36. package/dist/runtime/components/overlays/Notifications.vue +1 -1
  37. package/dist/runtime/components/overlays/Popover.vue +6 -2
  38. package/dist/runtime/composables/defineShortcuts.js +1 -1
  39. package/dist/runtime/composables/useButtonGroup.d.ts +1 -1
  40. package/dist/runtime/composables/useUI.js +1 -1
  41. package/dist/runtime/plugins/modals.js +1 -1
  42. package/dist/runtime/plugins/slideovers.js +1 -1
  43. package/dist/runtime/types/accordion.d.ts +1 -1
  44. package/dist/runtime/types/alert.d.ts +4 -4
  45. package/dist/runtime/types/avatar.d.ts +3 -3
  46. package/dist/runtime/types/badge.d.ts +3 -3
  47. package/dist/runtime/types/button.d.ts +3 -5
  48. package/dist/runtime/types/chip.d.ts +2 -2
  49. package/dist/runtime/types/command-palette.d.ts +2 -2
  50. package/dist/runtime/types/component.d.ts +3 -3
  51. package/dist/runtime/types/divider.d.ts +3 -3
  52. package/dist/runtime/types/dropdown.d.ts +1 -1
  53. package/dist/runtime/types/form-group.d.ts +2 -2
  54. package/dist/runtime/types/form.d.ts +7 -2
  55. package/dist/runtime/types/index.d.ts +1 -0
  56. package/dist/runtime/types/index.js +1 -0
  57. package/dist/runtime/types/input.d.ts +3 -3
  58. package/dist/runtime/types/kbd.d.ts +2 -2
  59. package/dist/runtime/types/meter.d.ts +2 -2
  60. package/dist/runtime/types/modal.d.ts +2 -2
  61. package/dist/runtime/types/notification.d.ts +1 -1
  62. package/dist/runtime/types/progress.d.ts +2 -2
  63. package/dist/runtime/types/range.d.ts +3 -3
  64. package/dist/runtime/types/select.d.ts +3 -3
  65. package/dist/runtime/types/table.d.ts +18 -0
  66. package/dist/runtime/types/textarea.d.ts +3 -3
  67. package/dist/runtime/types/toggle.d.ts +3 -3
  68. package/dist/runtime/types/utils.d.ts +2 -2
  69. package/dist/runtime/ui.config/data/table.d.ts +1 -0
  70. package/dist/runtime/ui.config/data/table.js +1 -0
  71. package/dist/runtime/ui.config/elements/avatar.js +15 -15
  72. package/dist/runtime/ui.config/elements/button.js +25 -25
  73. package/dist/runtime/ui.config/elements/buttonGroup.js +1 -1
  74. package/dist/runtime/ui.config/elements/chip.js +5 -5
  75. package/dist/runtime/ui.config/elements/meter.js +20 -20
  76. package/dist/runtime/ui.config/elements/meterGroup.js +1 -1
  77. package/dist/runtime/ui.config/elements/progress.js +18 -18
  78. package/dist/runtime/ui.config/forms/formGroup.js +5 -6
  79. package/dist/runtime/ui.config/forms/input.js +40 -40
  80. package/dist/runtime/ui.config/forms/inputMenu.d.ts +6 -0
  81. package/dist/runtime/ui.config/forms/inputMenu.js +7 -1
  82. package/dist/runtime/ui.config/forms/range.js +20 -20
  83. package/dist/runtime/ui.config/forms/selectMenu.d.ts +9 -0
  84. package/dist/runtime/ui.config/forms/selectMenu.js +10 -1
  85. package/dist/runtime/ui.config/forms/toggle.js +20 -20
  86. package/dist/runtime/ui.config/layout/divider.d.ts +1 -0
  87. package/dist/runtime/ui.config/layout/divider.js +12 -11
  88. package/dist/runtime/ui.config/navigation/horizontalNavigation.js +1 -1
  89. package/dist/runtime/ui.config/navigation/verticalNavigation.js +1 -1
  90. package/dist/runtime/ui.config/popper.js +0 -1
  91. package/dist/runtime/utils/colors.js +7 -7
  92. package/dist/runtime/utils/index.js +4 -4
  93. package/dist/runtime/utils/lodash.js +1 -1
  94. package/package.json +21 -19
@@ -56,16 +56,11 @@ export default defineComponent({
56
56
  async function getErrors() {
57
57
  let errs = await props.validate(props.state);
58
58
  if (props.schema) {
59
- if (isZodSchema(props.schema)) {
60
- errs = errs.concat(await getZodErrors(props.state, props.schema));
61
- } else if (isYupSchema(props.schema)) {
62
- errs = errs.concat(await getYupErrors(props.state, props.schema));
63
- } else if (isJoiSchema(props.schema)) {
64
- errs = errs.concat(await getJoiErrors(props.state, props.schema));
65
- } else if (isValibotSchema(props.schema)) {
66
- errs = errs.concat(await getValibotError(props.state, props.schema));
59
+ const { errors: errors2, result } = await parseSchema(props.state, props.schema);
60
+ if (errors2) {
61
+ errs = errs.concat(errors2);
67
62
  } else {
68
- throw new Error("Form validation failed: Unsupported form schema");
63
+ Object.assign(props.state, result);
69
64
  }
70
65
  }
71
66
  return errs;
@@ -157,64 +152,130 @@ function isYupSchema(schema) {
157
152
  function isYupError(error) {
158
153
  return error.inner !== void 0;
159
154
  }
160
- async function getYupErrors(state, schema) {
155
+ function isSuperStructSchema(schema) {
156
+ return "schema" in schema && typeof schema.coercer === "function" && typeof schema.validator === "function" && typeof schema.refiner === "function";
157
+ }
158
+ function isJoiSchema(schema) {
159
+ return schema.validateAsync !== void 0 && schema.id !== void 0;
160
+ }
161
+ function isJoiError(error) {
162
+ return error.isJoi === true;
163
+ }
164
+ function isValibotSchema(schema) {
165
+ return "_parse" in schema || "_run" in schema || typeof schema === "function" && "schema" in schema;
166
+ }
167
+ function isZodSchema(schema) {
168
+ return schema.parse !== void 0;
169
+ }
170
+ async function validateValibotSchema(state, schema) {
171
+ const result = await ("_parse" in schema ? schema._parse(state) : "_run" in schema ? schema._run({ typed: false, value: state }, {}) : schema(state));
172
+ if (!result.issues || result.issues.length === 0) {
173
+ const output = "output" in result ? result.output : "value" in result ? result.value : null;
174
+ return {
175
+ errors: null,
176
+ result: output
177
+ };
178
+ }
179
+ const errors = result.issues.map((issue) => ({
180
+ path: issue.path?.map((item) => item.key).join(".") || "",
181
+ message: issue.message
182
+ }));
183
+ return {
184
+ errors,
185
+ result: null
186
+ };
187
+ }
188
+ async function validateJoiSchema(state, schema) {
161
189
  try {
162
- await schema.validate(state, { abortEarly: false });
163
- return [];
190
+ await schema.validateAsync(state, { abortEarly: false });
191
+ return {
192
+ errors: null,
193
+ result: state
194
+ };
164
195
  } catch (error) {
165
- if (isYupError(error)) {
166
- return error.inner.map((issue) => ({
167
- path: issue.path ?? "",
196
+ if (isJoiError(error)) {
197
+ const errors = error.details.map((issue) => ({
198
+ path: issue.path.join("."),
168
199
  message: issue.message
169
200
  }));
201
+ return {
202
+ errors,
203
+ result: null
204
+ };
170
205
  } else {
171
206
  throw error;
172
207
  }
173
208
  }
174
209
  }
175
- function isZodSchema(schema) {
176
- return schema.parse !== void 0;
177
- }
178
- async function getZodErrors(state, schema) {
210
+ async function validateZodSchema(state, schema) {
179
211
  const result = await schema.safeParseAsync(state);
180
212
  if (result.success === false) {
181
- return result.error.issues.map((issue) => ({
213
+ const errors = result.error.issues.map((issue) => ({
182
214
  path: issue.path.join("."),
183
215
  message: issue.message
184
216
  }));
217
+ return {
218
+ errors,
219
+ result: null
220
+ };
185
221
  }
186
- return [];
187
- }
188
- function isJoiSchema(schema) {
189
- return schema.validateAsync !== void 0 && schema.id !== void 0;
222
+ return {
223
+ result: result.data,
224
+ errors: null
225
+ };
190
226
  }
191
- function isJoiError(error) {
192
- return error.isJoi === true;
227
+ async function validateSuperstructSchema(state, schema) {
228
+ const [err, result] = schema.validate(state);
229
+ if (err) {
230
+ const errors = err.failures().map((error) => ({
231
+ message: error.message,
232
+ path: error.path.join(".")
233
+ }));
234
+ return {
235
+ errors,
236
+ result: null
237
+ };
238
+ }
239
+ return {
240
+ errors: null,
241
+ result
242
+ };
193
243
  }
194
- async function getJoiErrors(state, schema) {
244
+ async function validateYupSchema(state, schema) {
195
245
  try {
196
- await schema.validateAsync(state, { abortEarly: false });
197
- return [];
246
+ const result = schema.validateSync(state, { abortEarly: false });
247
+ return {
248
+ errors: null,
249
+ result
250
+ };
198
251
  } catch (error) {
199
- if (isJoiError(error)) {
200
- return error.details.map((detail) => ({
201
- path: detail.path.join("."),
202
- message: detail.message
252
+ if (isYupError(error)) {
253
+ const errors = error.inner.map((issue) => ({
254
+ path: issue.path ?? "",
255
+ message: issue.message
203
256
  }));
257
+ return {
258
+ errors,
259
+ result: null
260
+ };
204
261
  } else {
205
262
  throw error;
206
263
  }
207
264
  }
208
265
  }
209
- function isValibotSchema(schema) {
210
- return "_parse" in schema || "_run" in schema || typeof schema === "function" && "schema" in schema;
211
- }
212
- async function getValibotError(state, schema) {
213
- const result = await ("_parse" in schema ? schema._parse(state) : "_run" in schema ? schema._run({ typed: false, value: state }, {}) : schema(state));
214
- return result.issues?.map((issue) => ({
215
- // We know that the key for a form schema is always a string or a number
216
- path: issue.path?.map((item) => item.key).join(".") || "",
217
- message: issue.message
218
- })) || [];
266
+ function parseSchema(state, schema) {
267
+ if (isZodSchema(schema)) {
268
+ return validateZodSchema(state, schema);
269
+ } else if (isJoiSchema(schema)) {
270
+ return validateJoiSchema(state, schema);
271
+ } else if (isValibotSchema(schema)) {
272
+ return validateValibotSchema(state, schema);
273
+ } else if (isYupSchema(schema)) {
274
+ return validateYupSchema(state, schema);
275
+ } else if (isSuperStructSchema(schema)) {
276
+ return validateSuperstructSchema(state, schema);
277
+ } else {
278
+ throw new Error("Form validation failed: Unsupported form schema");
279
+ }
219
280
  }
220
281
  </script>
@@ -5,10 +5,12 @@ import type { ObjectSchema as YupObjectSchema } from 'yup';
5
5
  import type { BaseSchema as ValibotSchema30, BaseSchemaAsync as ValibotSchemaAsync30 } from 'valibot30';
6
6
  import type { GenericSchema as ValibotSchema31, GenericSchemaAsync as ValibotSchemaAsync31, SafeParser as ValibotSafeParser31, SafeParserAsync as ValibotSafeParserAsync31 } from 'valibot31';
7
7
  import type { GenericSchema as ValibotSchema, GenericSchemaAsync as ValibotSchemaAsync, SafeParser as ValibotSafeParser, SafeParserAsync as ValibotSafeParserAsync } from 'valibot';
8
+ import type { Struct } from 'superstruct';
8
9
  import type { FormError, FormEventType } from '../../types/form.js';
10
+ type Schema = PropType<ZodSchema> | PropType<YupObjectSchema<any>> | PropType<JoiSchema> | PropType<ValibotSchema30 | ValibotSchemaAsync30> | PropType<ValibotSchema31 | ValibotSchemaAsync31> | PropType<ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any>> | PropType<ValibotSchema | ValibotSchemaAsync> | PropType<ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>> | PropType<Struct<any, any>>;
9
11
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
10
12
  schema: {
11
- type: PropType<ZodSchema> | PropType<YupObjectSchema<any>> | PropType<JoiSchema> | PropType<ValibotSchema30 | ValibotSchemaAsync30> | PropType<ValibotSchema31 | ValibotSchemaAsync31> | PropType<ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any>> | PropType<ValibotSchema | ValibotSchemaAsync> | PropType<ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>>;
13
+ type: Schema;
12
14
  default: any;
13
15
  };
14
16
  state: {
@@ -34,7 +36,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
34
36
  }[]>>;
35
37
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("error" | "submit")[], "error" | "submit", import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
36
38
  schema: {
37
- type: PropType<ZodSchema> | PropType<YupObjectSchema<any>> | PropType<JoiSchema> | PropType<ValibotSchema30 | ValibotSchemaAsync30> | PropType<ValibotSchema31 | ValibotSchemaAsync31> | PropType<ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any>> | PropType<ValibotSchema | ValibotSchemaAsync> | PropType<ValibotSafeParser<any, any> | ValibotSafeParserAsync<any, any>>;
39
+ type: Schema;
38
40
  default: any;
39
41
  };
40
42
  state: {
@@ -53,7 +55,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
53
55
  onSubmit?: (...args: any[]) => any;
54
56
  onError?: (...args: any[]) => any;
55
57
  }>, {
56
- schema: ZodSchema<any, import("zod").ZodTypeDef, any> | YupObjectSchema<any, import("yup").AnyObject, any, ""> | import("joi").AnySchema<any> | ValibotSchema30<any, any> | ValibotSchemaAsync30<any, any> | ValibotSchema31<unknown, unknown, import("valibot31").BaseIssue<unknown>> | ValibotSchemaAsync31<unknown, unknown, import("valibot31").BaseIssue<unknown>> | ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any> | ValibotSchema<unknown, unknown, import("valibot").BaseIssue<unknown>> | ValibotSchemaAsync<unknown, unknown, import("valibot").BaseIssue<unknown>>;
58
+ schema: ZodSchema<any, import("zod").ZodTypeDef, any> | YupObjectSchema<any, import("yup").AnyObject, any, ""> | import("joi").AnySchema<any> | ValibotSchema30<any, any> | ValibotSchemaAsync30<any, any> | ValibotSchema31<unknown, unknown, import("valibot31").BaseIssue<unknown>> | ValibotSchemaAsync31<unknown, unknown, import("valibot31").BaseIssue<unknown>> | ValibotSafeParser31<any, any> | ValibotSafeParserAsync31<any, any> | ValibotSchema<unknown, unknown, import("valibot").BaseIssue<unknown>> | ValibotSchemaAsync<unknown, unknown, import("valibot").BaseIssue<unknown>> | Struct<any, any>;
57
59
  validate: ((state: any) => Promise<FormError[]>) | ((state: any) => FormError[]);
58
60
  validateOn: FormEventType[];
59
61
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -33,8 +33,8 @@
33
33
  <script>
34
34
  import { ref, computed, toRef, onMounted, defineComponent } from "vue";
35
35
  import { twMerge, twJoin } from "tailwind-merge";
36
- import UIcon from "../elements/Icon.vue";
37
36
  import { defu } from "defu";
37
+ import UIcon from "../elements/Icon.vue";
38
38
  import { useUI } from "../../composables/useUI";
39
39
  import { useFormGroup } from "../../composables/useFormGroup";
40
40
  import { mergeConfig, looseToNumber } from "../../utils";
@@ -163,7 +163,7 @@ export default defineComponent({
163
163
  const { size: sizeButtonGroup, rounded } = useInjectButtonGroup({ ui, props });
164
164
  const { emitFormBlur, emitFormInput, size: sizeFormGroup, color, inputId, name } = useFormGroup(props, config);
165
165
  const size = computed(() => sizeButtonGroup.value ?? sizeFormGroup.value);
166
- const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false }));
166
+ const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false, nullify: false }));
167
167
  const input2 = ref(null);
168
168
  const autoFocus = () => {
169
169
  if (props.autofocus) {
@@ -177,6 +177,9 @@ export default defineComponent({
177
177
  if (modelModifiers.value.number || props.type === "number") {
178
178
  value = looseToNumber(value);
179
179
  }
180
+ if (modelModifiers.value.nullify) {
181
+ value ||= null;
182
+ }
180
183
  emit("update:modelValue", value);
181
184
  emitFormInput();
182
185
  };
@@ -212,6 +212,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
212
212
  trim?: boolean;
213
213
  lazy?: boolean;
214
214
  number?: boolean;
215
+ nullify?: boolean;
215
216
  }>;
216
217
  default: () => {};
217
218
  };
@@ -446,6 +447,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
446
447
  trim?: boolean;
447
448
  lazy?: boolean;
448
449
  number?: boolean;
450
+ nullify?: boolean;
449
451
  }>;
450
452
  default: () => {};
451
453
  };
@@ -593,6 +595,7 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
593
595
  trim?: boolean;
594
596
  lazy?: boolean;
595
597
  number?: boolean;
598
+ nullify?: boolean;
596
599
  };
597
600
  }, {}, {
598
601
  UIcon: import("vue").DefineComponent<import("vue").ExtractPropTypes<{