@una-ui/nuxt 1.0.0-alpha.11 → 1.0.0-alpha.13

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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@una-ui/nuxt",
3
3
  "configKey": "una",
4
- "version": "1.0.0-alpha.11",
4
+ "version": "1.0.0-alpha.13",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -8,7 +8,7 @@ import 'unocss';
8
8
  import 'unocss-preset-animations';
9
9
 
10
10
  const name = "@una-ui/nuxt";
11
- const version = "1.0.0-alpha.11";
11
+ const version = "1.0.0-alpha.13";
12
12
 
13
13
  const module = defineNuxtModule({
14
14
  meta: {
@@ -19,9 +19,10 @@ import ComboboxTrigger from "./ComboboxTrigger.vue";
19
19
  import ComboboxViewport from "./ComboboxViewport.vue";
20
20
  const props = defineProps({
21
21
  modelValue: { type: null, required: false },
22
+ defaultValue: { type: null, required: false },
22
23
  items: { type: Array, required: false },
23
- labelKey: { type: null, required: false },
24
- valueKey: { type: null, required: false },
24
+ labelKey: { type: null, required: false, default: "label" },
25
+ valueKey: { type: null, required: false, default: "value" },
25
26
  groupSeparator: { type: Boolean, required: false },
26
27
  textEmpty: { type: String, required: false, default: "No items found." },
27
28
  label: { type: String, required: false },
@@ -49,7 +50,6 @@ const props = defineProps({
49
50
  openOnClick: { type: Boolean, required: false },
50
51
  ignoreFilter: { type: Boolean, required: false },
51
52
  resetModelValueOnClear: { type: Boolean, required: false },
52
- defaultValue: { type: null, required: false },
53
53
  dir: { type: String, required: false },
54
54
  disabled: { type: Boolean, required: false },
55
55
  highlightOnHover: { type: Boolean, required: false },
@@ -87,8 +87,6 @@ const rootProps = reactiveOmit(props, [
87
87
  "_comboboxCheckbox"
88
88
  ]);
89
89
  const forwarded = useForwardPropsEmits(rootProps, emits);
90
- const labelKey = computed(() => props.labelKey?.toString() ?? "label");
91
- const valueKey = computed(() => props.valueKey?.toString() ?? "value");
92
90
  const hasGroups = computed(() => {
93
91
  return Array.isArray(props.items) && props.items.length > 0 && typeof props.items[0] === "object" && "items" in props.items[0];
94
92
  });
@@ -97,46 +95,44 @@ function getItemProperty(item, key) {
97
95
  return "";
98
96
  return typeof item !== "object" ? item : item[key];
99
97
  }
100
- function findItemByValue(value) {
101
- if (!props.items)
102
- return void 0;
103
- if (hasGroups.value) {
104
- for (const group of props.items) {
105
- const found = group.items?.find((item) => getItemProperty(item, valueKey.value) === value);
106
- if (found)
107
- return found;
108
- }
109
- return void 0;
110
- } else {
111
- return props.items.find((item) => getItemProperty(item, valueKey.value) === value);
112
- }
113
- }
114
98
  function getDisplayValue(val) {
115
- if (!val || Array.isArray(val) && val.length === 0)
99
+ if (val == null || Array.isArray(val) && val.length === 0)
116
100
  return "";
117
- if (props.multiple && Array.isArray(val)) {
101
+ if (Array.isArray(val)) {
118
102
  return val.map((v) => {
119
103
  if (typeof v !== "object" || v === null) {
120
- const item = findItemByValue(v);
121
- return item ? getItemProperty(item, labelKey.value) : v;
104
+ return String(v);
122
105
  }
123
- return getItemProperty(v, labelKey.value) || getItemProperty(v, valueKey.value) || "";
124
- }).filter(Boolean).join(", ");
106
+ return getItemProperty(v, props.labelKey) || getItemProperty(v, props.valueKey) || "";
107
+ }).filter((v) => v !== null && v !== void 0).join(", ");
125
108
  }
126
109
  if (typeof val !== "object" || val === null) {
127
- const item = findItemByValue(val);
128
- return item ? getItemProperty(item, labelKey.value) : String(val || "");
110
+ return String(val);
129
111
  }
130
- return getItemProperty(val, labelKey.value) || getItemProperty(val, valueKey.value) || "";
112
+ return getItemProperty(val, props.labelKey) || getItemProperty(val, props.valueKey) || "";
131
113
  }
132
114
  function isItemSelected(item) {
133
- if (item == null)
115
+ if (item == null || !props.modelValue)
134
116
  return false;
135
- const itemValue = getItemProperty(item, valueKey.value);
136
- if (props.multiple && Array.isArray(props.modelValue)) {
137
- return props.modelValue.includes(itemValue);
117
+ if (typeof item !== "object") {
118
+ if (Array.isArray(props.modelValue)) {
119
+ return props.modelValue.includes(item);
120
+ }
121
+ return props.modelValue === item;
122
+ }
123
+ const itemValue = getItemProperty(item, props.valueKey);
124
+ if (Array.isArray(props.modelValue)) {
125
+ return props.modelValue.some((v) => {
126
+ if (typeof v !== "object" || v === null) {
127
+ return v === itemValue;
128
+ }
129
+ return getItemProperty(v, props.valueKey) === itemValue;
130
+ });
131
+ }
132
+ if (typeof props.modelValue !== "object" || props.modelValue === null) {
133
+ return props.modelValue === itemValue;
138
134
  }
139
- return typeof props.modelValue === "object" && props.modelValue !== null ? getItemProperty(props.modelValue, valueKey.value) === itemValue : props.modelValue === itemValue;
135
+ return getItemProperty(props.modelValue, props.valueKey) === itemValue;
140
136
  }
141
137
  </script>
142
138
 
@@ -254,8 +250,8 @@ function isItemSelected(item) {
254
250
  <slot name="group">
255
251
  <ComboboxItem
256
252
  v-for="item in items"
257
- :key="getItemProperty(item, valueKey)"
258
- :value="props.multiple ? getItemProperty(item, valueKey) : item"
253
+ :key="getItemProperty(item, props.valueKey)"
254
+ :value="item"
259
255
  :size
260
256
  v-bind="props._comboboxItem"
261
257
  :class="cn(
@@ -265,7 +261,7 @@ function isItemSelected(item) {
265
261
  >
266
262
  <slot name="item" :item="item" :selected="isItemSelected(item)">
267
263
  <slot name="label" :item="item">
268
- {{ getItemProperty(item, labelKey) }}
264
+ {{ getItemProperty(item, props.labelKey) }}
269
265
  </slot>
270
266
 
271
267
  <ComboboxItemIndicator
@@ -300,8 +296,8 @@ function isItemSelected(item) {
300
296
  <slot name="group" :group="group">
301
297
  <ComboboxItem
302
298
  v-for="item in group.items"
303
- :key="getItemProperty(item, valueKey)"
304
- :value="props.multiple ? getItemProperty(item, valueKey) : item"
299
+ :key="getItemProperty(item, props.valueKey)"
300
+ :value="item"
305
301
  :size
306
302
  v-bind="{ ...props._comboboxItem, ...group._comboboxItem }"
307
303
  :class="cn(
@@ -311,7 +307,7 @@ function isItemSelected(item) {
311
307
  >
312
308
  <slot name="item" :item="item" :group="group" :selected="isItemSelected(item)">
313
309
  <slot name="label" :item="item">
314
- {{ getItemProperty(item, labelKey) }}
310
+ {{ getItemProperty(item, props.labelKey) }}
315
311
  </slot>
316
312
 
317
313
  <ComboboxItemIndicator
@@ -7,7 +7,7 @@ defineOptions({
7
7
  inheritAttrs: false
8
8
  });
9
9
  const props = defineProps({
10
- displayValue: { type: Function, required: false },
10
+ displayValue: { type: Function, required: false, default: () => "" },
11
11
  modelValue: { type: String, required: false },
12
12
  autoFocus: { type: Boolean, required: false },
13
13
  disabled: { type: Boolean, required: false },
@@ -1,16 +1,38 @@
1
+ import type { NComboboxInputProps } from '../../types/index.js';
1
2
  declare var __VLS_12: any, __VLS_13: any;
2
3
  type __VLS_Slots = {} & {
3
4
  [K in NonNullable<typeof __VLS_12>]?: (props: typeof __VLS_13) => any;
4
5
  };
5
- declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ declare const __VLS_component: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<NComboboxInputProps>, {
7
+ displayValue: () => "";
8
+ }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
9
  "update:modelValue": (args_0: string) => any;
7
- }, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
10
+ }, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<NComboboxInputProps>, {
11
+ displayValue: () => "";
12
+ }>>> & Readonly<{
8
13
  "onUpdate:modelValue"?: ((args_0: string) => any) | undefined;
9
14
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
15
  declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
11
16
  export default _default;
17
+ type __VLS_WithDefaults<P, D> = {
18
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
19
+ default: D[K];
20
+ }> : P[K];
21
+ };
22
+ type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
23
+ type __VLS_TypePropsToOption<T> = {
24
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
25
+ type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
26
+ } : {
27
+ type: import('vue').PropType<T[K]>;
28
+ required: true;
29
+ };
30
+ };
12
31
  type __VLS_WithSlots<T, S> = T & {
13
32
  new (): {
14
33
  $slots: S;
15
34
  };
16
35
  };
36
+ type __VLS_PrettifyLocal<T> = {
37
+ [K in keyof T]: T[K];
38
+ } & {};
@@ -52,7 +52,7 @@ const id = computed(() => props.id ?? randomId("checkbox"));
52
52
  <CheckboxRoot
53
53
  v-bind="{ ...forwarded, ...$attrs }"
54
54
  :id="id"
55
- v-slot="{ ...slotProps }"
55
+ v-slot="slotProps"
56
56
  :class="
57
57
  cn(
58
58
  'peer checkbox',
@@ -68,9 +68,11 @@ const id = computed(() => props.id ?? randomId("checkbox"));
68
68
  :class="cn('checkbox-indicator', una?.checkboxIndicator)"
69
69
  v-bind="props._checkboxIndicator"
70
70
  >
71
- <slot name="icon">
71
+ <slot
72
+ name="icon" v-bind="slotProps"
73
+ >
72
74
  <Icon
73
- :name="slotProps.modelValue === 'indeterminate' ? props.una?.checkboxIndeterminateIcon ?? 'checkbox-indeterminate-icon' : slotProps.modelValue ? props.una?.checkboxCheckedIcon ?? 'checkbox-checked-icon' : props.una?.checkboxUncheckedIcon ?? 'checkbox-unchecked-icon'"
75
+ :name="slotProps.state === 'indeterminate' ? props.una?.checkboxIndeterminateIcon ?? 'checkbox-indeterminate-icon' : slotProps.state ? props.una?.checkboxCheckedIcon ?? 'checkbox-checked-icon' : props.una?.checkboxUncheckedIcon ?? 'checkbox-unchecked-icon'"
74
76
  :class="cn('checkbox-icon-base', una?.checkboxIconBase)"
75
77
  />
76
78
  </slot>
@@ -1,5 +1,5 @@
1
1
  import type { NCheckboxProps } from '../../types/index.js';
2
- declare var __VLS_9: {}, __VLS_17: {};
2
+ declare var __VLS_9: any, __VLS_17: {};
3
3
  type __VLS_Slots = {} & {
4
4
  icon?: (props: typeof __VLS_9) => any;
5
5
  } & {
@@ -14,8 +14,8 @@ import SelectTrigger from "./SelectTrigger.vue";
14
14
  import SelectValue from "./SelectValue.vue";
15
15
  const props = defineProps({
16
16
  items: { type: null, required: false },
17
- itemKey: { type: null, required: false },
18
- valueKey: { type: null, required: false },
17
+ labelKey: { type: null, required: false, default: "label" },
18
+ valueKey: { type: null, required: false, default: "value" },
19
19
  label: { type: String, required: false },
20
20
  groupSeparator: { type: Boolean, required: false },
21
21
  defaultValue: { type: null, required: false },
@@ -56,16 +56,25 @@ const forwarded = useForwardPropsEmits(props, emits);
56
56
  function formatSelectedValue(value) {
57
57
  if (!value || Array.isArray(value) && value.length === 0)
58
58
  return null;
59
- if (props.multiple && Array.isArray(value)) {
59
+ const findItemByValue = (val) => {
60
+ const allItems = hasGroups.value ? props.items.flatMap((group) => group.items) : props.items;
61
+ return allItems?.find((item2) => {
62
+ const itemValue = props.valueKey && typeof item2 === "object" ? item2[props.valueKey] : item2;
63
+ return itemValue === val;
64
+ });
65
+ };
66
+ if (Array.isArray(value)) {
60
67
  return value.map((val) => {
61
- if (props.valueKey && typeof val === "object") {
62
- return val[props.valueKey];
68
+ const item2 = findItemByValue(val);
69
+ if (item2 && props.labelKey && typeof item2 === "object") {
70
+ return item2[props.labelKey];
63
71
  }
64
72
  return val;
65
73
  }).join(", ");
66
74
  }
67
- if (props.valueKey && typeof value === "object") {
68
- return value[props.valueKey];
75
+ const item = findItemByValue(value);
76
+ if (item && props.labelKey && typeof item === "object") {
77
+ return item[props.labelKey];
69
78
  }
70
79
  return value;
71
80
  }
@@ -73,6 +82,7 @@ function formatSelectedValue(value) {
73
82
 
74
83
  <template>
75
84
  <SelectRoot
85
+ v-slot="{ modelValue, open }"
76
86
  :class="cn(
77
87
  props.una?.select,
78
88
  props.class
@@ -131,14 +141,14 @@ function formatSelectedValue(value) {
131
141
  :key="item"
132
142
  >
133
143
  <SelectItem
134
- :value="item"
144
+ :value="props.valueKey && typeof item === 'object' ? item[props.valueKey] : item"
135
145
  :size
136
146
  :select-item
137
147
  v-bind="props._selectItem"
138
148
  :una
139
149
  >
140
150
  <slot name="item" :item="item">
141
- {{ props.itemKey && item ? item[props.itemKey] : item }}
151
+ {{ props.labelKey && typeof item === "object" ? item[props.labelKey] : item }}
142
152
  </slot>
143
153
  <template #indicator>
144
154
  <slot name="indicator" :item="item" />
@@ -177,14 +187,14 @@ function formatSelectedValue(value) {
177
187
  :key="item"
178
188
  >
179
189
  <SelectItem
180
- :value="item"
190
+ :value="props.valueKey && typeof item === 'object' ? item[props.valueKey] : item"
181
191
  :size
182
192
  :select-item
183
193
  v-bind="{ ..._selectItem, ...group._selectItem }"
184
194
  :una
185
195
  >
186
196
  <slot name="item" :item="item">
187
- {{ props.itemKey ? item[props.itemKey] : item }}
197
+ {{ props.labelKey && typeof item === "object" ? item[props.labelKey] : item }}
188
198
  </slot>
189
199
  <template #indicator>
190
200
  <slot name="indicator" :item="item" />
@@ -10,12 +10,17 @@ interface BaseExtensions {
10
10
  export type ExtractItemType<T> = T extends {
11
11
  items: infer I extends AcceptableValue[];
12
12
  } ? I[number] : T;
13
- export interface NComboboxProps<T extends AcceptableValue, M extends boolean> extends Omit<ComboboxRootProps<ExtractItemType<T>>, 'modelValue'>, Pick<NComboboxInputProps, 'status' | 'id'>, BaseExtensions {
13
+ export interface NComboboxProps<T extends AcceptableValue, M extends boolean> extends Omit<ComboboxRootProps<ExtractItemType<T>>, 'modelValue' | 'defaultValue'>, Pick<NComboboxInputProps, 'status' | 'id'>, BaseExtensions {
14
14
  /**
15
15
  * The model value for the combobox.
16
- * When using grouped items, this will be the item type from within the groups.
16
+ * Stores the full item object(s), not extracted values.
17
17
  */
18
- modelValue?: (M extends true ? ExtractItemType<T>[] : ExtractItemType<T>) | null;
18
+ modelValue?: M extends true ? ExtractItemType<T>[] | null : ExtractItemType<T> | null;
19
+ /**
20
+ * The default value for the combobox.
21
+ * Should be the full item object(s), not extracted values.
22
+ */
23
+ defaultValue?: M extends true ? ExtractItemType<T>[] | null : ExtractItemType<T> | null;
19
24
  /**
20
25
  * The items to display in the combobox.
21
26
  *
@@ -23,17 +28,17 @@ export interface NComboboxProps<T extends AcceptableValue, M extends boolean> ex
23
28
  */
24
29
  items?: T[] | NComboboxGroupProps<ExtractItemType<T>>[];
25
30
  /**
26
- * The key name to use to display in the select items.
31
+ * The key name to use to display in the combobox items.
27
32
  *
28
33
  * @default 'label'
29
34
  */
30
- labelKey?: keyof ExtractItemType<T>;
35
+ labelKey?: keyof ExtractItemType<T> | string;
31
36
  /**
32
- * The key name to use to display in the selected value.
37
+ * The key name to use for comparing items (used for selection matching).
33
38
  *
34
39
  * @default 'value'
35
40
  */
36
- valueKey?: keyof ExtractItemType<T>;
41
+ valueKey?: keyof ExtractItemType<T> | string;
37
42
  /**
38
43
  * Whether to show a separator between groups.
39
44
  *
@@ -22,7 +22,7 @@ export interface SelectGroup<T extends AcceptableValue> {
22
22
  _selectLabel?: Partial<NSelectLabelProps>;
23
23
  _selectItem?: Partial<NSelectItemProps>;
24
24
  }
25
- export interface NSelectProps<T extends AcceptableValue, Items extends Array<T | SelectGroup<T>>, M extends boolean = false> extends SelectExtensions<T> {
25
+ export interface NSelectProps<T extends AcceptableValue, Items extends Array<T | SelectGroup<T>>, M extends boolean = false> extends Omit<SelectExtensions<T>, 'modelValue' | 'defaultValue'> {
26
26
  /**
27
27
  * The items to display in the select.
28
28
  */
@@ -30,11 +30,11 @@ export interface NSelectProps<T extends AcceptableValue, Items extends Array<T |
30
30
  /**
31
31
  * The key name to use to display in the select items.
32
32
  */
33
- itemKey?: keyof T;
33
+ labelKey?: keyof T | string;
34
34
  /**
35
35
  * The key name to use to display in the selected value.
36
36
  */
37
- valueKey?: keyof T;
37
+ valueKey?: keyof T | string;
38
38
  /**
39
39
  * The label to display above the select items.
40
40
  */
@@ -45,8 +45,8 @@ export interface NSelectProps<T extends AcceptableValue, Items extends Array<T |
45
45
  * @default false
46
46
  */
47
47
  groupSeparator?: boolean;
48
- defaultValue?: M extends true ? T[] : T;
49
- modelValue?: M extends true ? T[] : T;
48
+ defaultValue?: M extends true ? any[] : any;
49
+ modelValue?: M extends true ? any[] : any;
50
50
  multiple?: M;
51
51
  /**
52
52
  * Sub-component configurations
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@una-ui/nuxt",
3
3
  "type": "module",
4
- "version": "1.0.0-alpha.11",
4
+ "version": "1.0.0-alpha.13",
5
5
  "description": "Nuxt module for @una-ui",
6
6
  "author": "Phojie Rengel <phojrengel@gmail.com>",
7
7
  "license": "MIT",
@@ -40,11 +40,11 @@
40
40
  "@nuxt/kit": "^3.19.2",
41
41
  "@nuxtjs/color-mode": "^3.5.2",
42
42
  "@tanstack/vue-table": "^8.21.3",
43
- "@unocss/core": "^66.5.4",
44
- "@unocss/nuxt": "^66.5.4",
45
- "@unocss/preset-attributify": "^66.5.4",
46
- "@unocss/preset-icons": "^66.5.4",
47
- "@unocss/reset": "^66.5.4",
43
+ "@unocss/core": "^66.5.10",
44
+ "@unocss/nuxt": "^66.5.10",
45
+ "@unocss/preset-attributify": "^66.5.10",
46
+ "@unocss/preset-icons": "^66.5.10",
47
+ "@unocss/reset": "^66.5.10",
48
48
  "@vee-validate/nuxt": "^4.15.1",
49
49
  "@vee-validate/zod": "^4.15.1",
50
50
  "@vueuse/core": "^12.8.2",
@@ -55,16 +55,16 @@
55
55
  "ohash": "^1.1.6",
56
56
  "reka-ui": "^2.6.0",
57
57
  "tailwind-merge": "^3.4.0",
58
- "unocss": "^66.5.4",
58
+ "unocss": "^66.5.10",
59
59
  "unocss-preset-animations": "^1.3.0",
60
60
  "vaul-vue": "^0.4.1",
61
- "@una-ui/extractor-vue-script": "^1.0.0-alpha.11",
62
- "@una-ui/preset": "^1.0.0-alpha.11"
61
+ "@una-ui/extractor-vue-script": "^1.0.0-alpha.13",
62
+ "@una-ui/preset": "^1.0.0-alpha.13"
63
63
  },
64
64
  "devDependencies": {
65
- "@iconify-json/lucide": "^1.2.73",
66
- "@iconify-json/radix-icons": "^1.2.5",
67
- "@iconify-json/tabler": "^1.2.23",
65
+ "@iconify-json/lucide": "^1.2.86",
66
+ "@iconify-json/radix-icons": "^1.2.6",
67
+ "@iconify-json/tabler": "^1.2.26",
68
68
  "@nuxt/module-builder": "^1.0.2",
69
69
  "@nuxt/schema": "^3.19.2",
70
70
  "nuxt": "^3.19.2",