@aerogel/core 0.1.1-next.83b702b110078faef3926d147f4746121b64a2d5 → 0.1.1-next.84e8ec11357e1ac863394cd875447af4d599dba3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aerogel/core",
3
- "version": "0.1.1-next.83b702b110078faef3926d147f4746121b64a2d5",
3
+ "version": "0.1.1-next.84e8ec11357e1ac863394cd875447af4d599dba3",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -10,13 +10,14 @@ import lang from '@aerogel/core/lang';
10
10
  import services from '@aerogel/core/services';
11
11
  import testing from '@aerogel/core/testing';
12
12
  import ui from '@aerogel/core/ui';
13
+ import forms from '@aerogel/core/forms';
13
14
  import { installPlugins } from '@aerogel/core/plugins';
14
15
  import type { AerogelOptions } from '@aerogel/core/bootstrap/options';
15
16
 
16
17
  export type { AerogelOptions };
17
18
 
18
19
  export async function bootstrapApplication(app: AppInstance, options: AerogelOptions = {}): Promise<void> {
19
- const plugins = [testing, directives, errors, lang, services, ui, ...(options.plugins ?? [])];
20
+ const plugins = [testing, directives, errors, lang, services, ui, forms, ...(options.plugins ?? [])];
20
21
 
21
22
  App.instance = app;
22
23
 
@@ -0,0 +1,5 @@
1
+ export type ComboboxContext = {
2
+ input: string;
3
+ preventChange: boolean;
4
+ $group: HTMLDivElement | null;
5
+ };
@@ -1,7 +1,8 @@
1
1
  import { computed, inject, provide, readonly } from 'vue';
2
2
  import { evaluate, toString, uuid } from '@noeldemartin/utils';
3
+ import type { AcceptRefs } from '@aerogel/core/utils';
3
4
  import type { AcceptableValue, AsTag, SelectContentProps } from 'reka-ui';
4
- import type { Component, ComputedRef, EmitFn, HTMLAttributes } from 'vue';
5
+ import type { Component, ComputedRef, EmitFn, HTMLAttributes, Ref } from 'vue';
5
6
  import type { Nullable } from '@noeldemartin/utils';
6
7
 
7
8
  import { translateWithDefault } from '@aerogel/core/lang';
@@ -37,10 +38,11 @@ export interface SelectExpose<T extends Nullable<FormFieldValue> = Nullable<Form
37
38
  options: ComputedRef<Nullable<readonly SelectOptionData[]>>;
38
39
  selectedOption: ComputedRef<Nullable<SelectOptionData>>;
39
40
  placeholder: ComputedRef<string>;
40
- labelClass?: HTMLAttributes['class'];
41
- optionsClass?: HTMLAttributes['class'];
41
+ labelClass: ComputedRef<HTMLAttributes['class']>;
42
+ optionsClass: ComputedRef<HTMLAttributes['class']>;
42
43
  align?: SelectContentProps['align'];
43
44
  side?: SelectContentProps['side'];
45
+ renderOption: (option: T) => string;
44
46
  }
45
47
 
46
48
  export function hasSelectOptionLabel(option: unknown): option is HasSelectOptionLabel {
@@ -48,70 +50,84 @@ export function hasSelectOptionLabel(option: unknown): option is HasSelectOption
48
50
  }
49
51
 
50
52
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
51
- export function useSelect<T extends Nullable<FormFieldValue>>(props: SelectProps<T>, emit: EmitFn<SelectEmits<T>>) {
53
+ export function useSelect<T extends Nullable<FormFieldValue>>(
54
+ props: Ref<SelectProps<T>>,
55
+ emit: EmitFn<SelectEmits<T>>,
56
+ ) {
52
57
  const form = inject<FormController | null>('form', null);
58
+ const renderOption = (option: T): string => {
59
+ if (option === undefined) {
60
+ return '';
61
+ }
62
+
63
+ return props.value.renderOption
64
+ ? props.value.renderOption(option)
65
+ : hasSelectOptionLabel(option)
66
+ ? evaluate(option.label as string)
67
+ : toString(option);
68
+ };
53
69
  const computedValue = computed(() => {
54
- if (form && props.name) {
55
- return form.getFieldValue(props.name) as T;
70
+ const { name, modelValue } = props.value;
71
+
72
+ if (form && name) {
73
+ return form.getFieldValue(name) as T;
56
74
  }
57
75
 
58
- return props.modelValue as T;
76
+ return modelValue as T;
59
77
  });
60
78
  const acceptableValue = computed(() => computedValue.value as AcceptableValue);
61
79
  const errors = computed(() => {
62
- if (!form || !props.name) {
80
+ if (!form || !props.value.name) {
63
81
  return null;
64
82
  }
65
83
 
66
- return form.errors[props.name] ?? null;
84
+ return form.errors[props.value.name] ?? null;
67
85
  });
68
86
  const computedOptions = computed(() => {
69
- if (!props.options) {
87
+ if (!props.value.options) {
70
88
  return null;
71
89
  }
72
90
 
73
- return props.options.map((option) => ({
91
+ return props.value.options.map((option) => ({
74
92
  key: uuid(),
75
- label: props.renderOption
76
- ? props.renderOption(option)
77
- : hasSelectOptionLabel(option)
78
- ? evaluate(option.label as string)
79
- : toString(option),
93
+ label: renderOption(option),
80
94
  value: option as AcceptableValue,
81
95
  }));
82
96
  });
83
97
 
84
98
  const expose = {
85
- labelClass: props.labelClass,
86
- optionsClass: props.optionsClass,
87
- align: props.align,
88
- side: props.side,
99
+ renderOption,
100
+ labelClass: computed(() => props.value.labelClass),
101
+ optionsClass: computed(() => props.value.optionsClass),
102
+ align: computed(() => props.value.align),
103
+ side: computed(() => props.value.side),
89
104
  value: computedValue,
90
105
  id: `select-${uuid()}`,
91
- name: computed(() => props.name),
92
- label: computed(() => props.label),
93
- description: computed(() => props.description),
94
- placeholder: computed(() => props.placeholder ?? translateWithDefault('ui.select', 'Select an option')),
106
+ name: computed(() => props.value.name),
107
+ label: computed(() => props.value.label),
108
+ description: computed(() => props.value.description),
109
+ placeholder: computed(() => props.value.placeholder ?? translateWithDefault('ui.select', 'Select an option')),
95
110
  options: computedOptions,
96
- selectedOption: computed(() => computedOptions.value?.find((option) => option.value === props.modelValue)),
111
+ selectedOption: computed(() =>
112
+ computedOptions.value?.find((option) => option.value === props.value.modelValue)),
97
113
  errors: readonly(errors),
98
114
  required: computed(() => {
99
- if (!props.name || !form) {
115
+ if (!props.value.name || !form) {
100
116
  return;
101
117
  }
102
118
 
103
- return form.getFieldRules(props.name).includes('required');
119
+ return form.getFieldRules(props.value.name).includes('required');
104
120
  }),
105
121
  update(value) {
106
- if (form && props.name) {
107
- form.setFieldValue(props.name, value as FormFieldValue);
122
+ if (form && props.value.name) {
123
+ form.setFieldValue(props.value.name, value as FormFieldValue);
108
124
 
109
125
  return;
110
126
  }
111
127
 
112
128
  emit('update:modelValue', value);
113
129
  },
114
- } satisfies SelectExpose<T>;
130
+ } satisfies AcceptRefs<SelectExpose<T>>;
115
131
 
116
132
  function update(value: AcceptableValue) {
117
133
  expose.update(value as T);
@@ -119,5 +135,5 @@ export function useSelect<T extends Nullable<FormFieldValue>>(props: SelectProps
119
135
 
120
136
  provide('select', expose);
121
137
 
122
- return { expose, update, acceptableValue };
138
+ return { expose, acceptableValue, update, renderOption };
123
139
  }
@@ -1,5 +1,6 @@
1
1
  export * from './AlertModal';
2
2
  export * from './Button';
3
+ export * from './Combobox';
3
4
  export * from './ConfirmModal';
4
5
  export * from './DropdownMenu';
5
6
  export * from './ErrorReportModal';
@@ -19,7 +19,7 @@ import { computed, inject, useTemplateRef, watchEffect } from 'vue';
19
19
 
20
20
  import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
21
21
  import { onFormFocus } from '@aerogel/core/utils/composition/forms';
22
- import { LOCAL_TIMEZONE_OFFSET } from '@aerogel/core/utils';
22
+ import { getLocalTimezoneOffset } from '@aerogel/core/utils';
23
23
  import type FormController from '@aerogel/core/forms/FormController';
24
24
  import type { FormFieldValue } from '@aerogel/core/forms/FormController';
25
25
  import type { InputExpose } from '@aerogel/core/components/contracts/Input';
@@ -66,7 +66,10 @@ function getValue(): FormFieldValue | null {
66
66
  case 'date':
67
67
  case 'time':
68
68
  case 'datetime-local':
69
- return new Date(Math.round($input.value.valueAsNumber / 60000) * 60000 + LOCAL_TIMEZONE_OFFSET);
69
+ return new Date(
70
+ Math.round($input.value.valueAsNumber / 60000) * 60000 +
71
+ getLocalTimezoneOffset($input.value.valueAsDate ?? new Date($input.value.valueAsNumber)),
72
+ );
70
73
  case 'number':
71
74
  return $input.value.valueAsNumber;
72
75
  default:
@@ -83,8 +86,11 @@ watchEffect(() => {
83
86
  if (['date', 'time', 'datetime-local'].includes(renderedType.value) && value.value instanceof Date) {
84
87
  const roundedValue = Math.round(value.value.getTime() / 60000) * 60000;
85
88
 
86
- $input.value.valueAsNumber = roundedValue - LOCAL_TIMEZONE_OFFSET;
87
- input.update(new Date(roundedValue));
89
+ $input.value.valueAsNumber = roundedValue - getLocalTimezoneOffset(value.value);
90
+
91
+ if (value.value.getTime() !== roundedValue) {
92
+ input.update(new Date(roundedValue));
93
+ }
88
94
 
89
95
  return;
90
96
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
18
18
  import { SelectRoot } from 'reka-ui';
19
+ import { computed } from 'vue';
19
20
  import type { Nullable } from '@noeldemartin/utils';
20
21
 
21
22
  import { useSelect } from '@aerogel/core/components/contracts/Select';
@@ -29,7 +30,10 @@ defineOptions({ inheritAttrs: false });
29
30
 
30
31
  const emit = defineEmits<SelectEmits<T>>();
31
32
  const { as = 'div', compareOptions = (a, b) => a === b, ...props } = defineProps<SelectProps<T>>();
32
- const { expose, acceptableValue, update } = useSelect({ as, compareOptions, ...props }, emit);
33
+ const { expose, acceptableValue, update } = useSelect(
34
+ computed(() => ({ as, compareOptions, ...props })),
35
+ emit,
36
+ );
33
37
 
34
38
  defineExpose(expose);
35
39
  </script>
@@ -25,10 +25,6 @@ const select = injectReactiveOrFail<SelectExpose>(
25
25
  const renderedLabel = computed(() => {
26
26
  const itemOption = select.options?.find((option) => option.value === value);
27
27
 
28
- if (itemOption) {
29
- return itemOption.label;
30
- }
31
-
32
- return toString(value);
28
+ return itemOption ? select.renderOption(itemOption.value) : toString(value);
33
29
  });
34
30
  </script>
@@ -5,3 +5,4 @@ export { default as AppToasts } from './AppToasts.vue';
5
5
  export * from './contracts';
6
6
  export * from './headless';
7
7
  export * from './ui';
8
+ export * from './vue';
@@ -1,30 +1,94 @@
1
1
  <template>
2
2
  <ComboboxRoot
3
- open-on-focus
3
+ ignore-filter
4
+ :open
5
+ :reset-search-term-on-blur="false"
6
+ :reset-search-term-on-select="false"
4
7
  :model-value="acceptableValue"
5
8
  :by="compareOptions"
6
9
  @update:model-value="update($event)"
7
10
  >
8
- <ComboboxLabel />
9
- <ComboboxTrigger />
10
- <ComboboxOptions />
11
+ <Provide name="combobox" :value="combobox">
12
+ <ComboboxLabel />
13
+ <ComboboxTrigger @focus="open = true" @change="open = true" @blur="open = false" />
14
+ <HeadlessSelectError class="mt-2 text-sm text-red-600" />
15
+ <ComboboxOptions :new-input-value @select="open = false" />
16
+ </Provide>
11
17
  </ComboboxRoot>
12
18
  </template>
13
19
 
14
20
  <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
15
21
  import { ComboboxRoot } from 'reka-ui';
22
+ import { computed, ref, watch } from 'vue';
23
+ import type { AcceptableValue } from 'reka-ui';
24
+ import type { Nullable } from '@noeldemartin/utils';
25
+
26
+ import Provide from '@aerogel/core/components/vue/Provide.vue';
16
27
  import { useSelect } from '@aerogel/core/components/contracts/Select';
28
+ import type { AcceptRefs } from '@aerogel/core/utils';
29
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
17
30
  import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
18
31
  import type { FormFieldValue } from '@aerogel/core/forms';
19
- import type { Nullable } from '@noeldemartin/utils';
20
32
 
21
33
  import ComboboxOptions from './ComboboxOptions.vue';
22
34
  import ComboboxTrigger from './ComboboxTrigger.vue';
23
35
  import ComboboxLabel from './ComboboxLabel.vue';
36
+ import HeadlessSelectError from '../headless/HeadlessSelectError.vue';
24
37
 
25
38
  const emit = defineEmits<SelectEmits<T>>();
26
- const { as = 'div', compareOptions = (a, b) => a === b, ...props } = defineProps<SelectProps<T>>();
27
- const { expose, acceptableValue, update } = useSelect({ as, compareOptions, ...props }, emit);
39
+ const {
40
+ as = 'div',
41
+ compareOptions = (a, b) => a === b,
42
+ newInputValue,
43
+ ...props
44
+ } = defineProps<SelectProps<T> & { newInputValue?: (value: string) => T }>();
45
+ const {
46
+ expose,
47
+ acceptableValue,
48
+ update: baseUpdate,
49
+ renderOption,
50
+ } = useSelect(
51
+ computed(() => ({ as, compareOptions, ...props })),
52
+ emit,
53
+ );
54
+ const open = ref(false);
55
+ const optionsByLabel = computed(() =>
56
+ Object.fromEntries(expose.options.value?.map((option) => [option.label, option.value]) ?? []));
57
+ const combobox = {
58
+ input: ref(acceptableValue.value ? renderOption(acceptableValue.value as T) : ''),
59
+ preventChange: ref(false),
60
+ $group: ref(null),
61
+ } satisfies AcceptRefs<ComboboxContext>;
62
+
63
+ function update(value: AcceptableValue) {
64
+ combobox.input.value = renderOption(value as T);
65
+
66
+ baseUpdate(value);
67
+ }
68
+
69
+ watch(expose.value, (value) => {
70
+ const newOptionLabel = renderOption(value as T);
71
+
72
+ if (combobox.input.value === newOptionLabel) {
73
+ return;
74
+ }
75
+
76
+ combobox.preventChange.value = true;
77
+ combobox.input.value = newOptionLabel;
78
+ });
79
+
80
+ watch(combobox.input, (value) => {
81
+ const newInputOption = newInputValue ? (newInputValue(value) as AcceptableValue) : value;
82
+ const newInputOptionLabel = renderOption(newInputOption as T);
83
+
84
+ if (newInputOptionLabel in optionsByLabel.value) {
85
+ update(optionsByLabel.value[newInputOptionLabel] as AcceptableValue);
86
+
87
+ return;
88
+ }
89
+
90
+ update(newInputOption);
91
+ });
28
92
 
29
93
  defineExpose(expose);
30
94
  </script>
@@ -2,8 +2,8 @@
2
2
  <Label
3
3
  v-if="show"
4
4
  :for="select.id"
5
+ :class="renderedClasses"
5
6
  v-bind="$props"
6
- class="block text-sm leading-6 font-medium text-gray-900"
7
7
  >
8
8
  <slot>
9
9
  {{ select.label }}
@@ -16,6 +16,7 @@ import { computed, useSlots } from 'vue';
16
16
  import { Label } from 'reka-ui';
17
17
  import type { LabelProps } from 'reka-ui';
18
18
 
19
+ import { classes } from '@aerogel/core/utils';
19
20
  import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
20
21
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
21
22
 
@@ -24,4 +25,5 @@ defineProps<Omit<LabelProps, 'for'>>();
24
25
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxLabel> must be a child of a <Combobox>');
25
26
  const slots = useSlots();
26
27
  const show = computed(() => !!(select.label || slots.default));
28
+ const renderedClasses = computed(() => classes('block text-sm leading-6 font-medium text-gray-900', select.labelClass));
27
29
  </script>
@@ -1,30 +1,46 @@
1
1
  <template>
2
- <ComboboxItem v-bind="$props" class="group p-1 outline-none">
2
+ <ComboboxItem v-bind="$props" class="group p-1 outline-none" @select="onSelect($event)">
3
3
  <div
4
4
  class="relative flex max-w-[calc(100vw-2rem)] cursor-pointer items-center gap-2 truncate rounded-md px-2 py-1 text-sm select-none *:truncate group-data-[highlighted]:bg-gray-100 group-data-[state=checked]:font-semibold group-data-[state=unchecked]:opacity-50"
5
5
  >
6
- {{ renderedLabel }}
6
+ <slot>
7
+ {{ renderedLabel }}
8
+ </slot>
7
9
  </div>
8
10
  </ComboboxItem>
9
11
  </template>
10
12
 
11
13
  <script setup lang="ts">
12
14
  import { computed } from 'vue';
13
- import { ComboboxItem, type ComboboxItemProps } from 'reka-ui';
15
+ import { ComboboxItem, injectComboboxRootContext } from 'reka-ui';
14
16
  import { toString } from '@noeldemartin/utils';
17
+ import type { ComboboxItemProps, SelectItemSelectEvent } from 'reka-ui';
15
18
 
16
19
  import { injectReactiveOrFail } from '@aerogel/core/utils';
20
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
17
21
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
18
22
 
23
+ const emit = defineEmits<{ select: [] }>();
24
+
19
25
  const { value } = defineProps<ComboboxItemProps>();
20
26
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOption> must be a child of a <Combobox>');
27
+ const rootContext = injectComboboxRootContext();
28
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
21
29
  const renderedLabel = computed(() => {
22
30
  const itemOption = select.options?.find((option) => option.value === value);
23
31
 
24
- if (itemOption) {
25
- return itemOption.label;
32
+ return itemOption ? select.renderOption(itemOption.value) : toString(value);
33
+ });
34
+
35
+ function onSelect(event: SelectItemSelectEvent<unknown>) {
36
+ if (rootContext.multiple.value || rootContext.disabled.value) {
37
+ return;
26
38
  }
27
39
 
28
- return toString(value);
29
- });
40
+ event.preventDefault();
41
+ combobox.preventChange = true;
42
+ rootContext.modelValue.value = value;
43
+
44
+ emit('select');
45
+ }
30
46
  </script>
@@ -16,8 +16,20 @@
16
16
  </div>
17
17
  </ComboboxEmpty>
18
18
 
19
- <ComboboxGroup>
20
- <ComboboxOption v-for="option in select.options ?? []" :key="option.key" :value="option.value" />
19
+ <ComboboxGroup ref="$group">
20
+ <ComboboxOption
21
+ v-if="showInputOption"
22
+ :value="newInputValue?.(combobox.input) ?? (combobox.input as AcceptableValue)"
23
+ @select="$emit('select')"
24
+ >
25
+ {{ combobox.input }}
26
+ </ComboboxOption>
27
+ <ComboboxOption
28
+ v-for="option in filteredOptions"
29
+ :key="option.key"
30
+ :value="option.value"
31
+ @select="$emit('select')"
32
+ />
21
33
  </ComboboxGroup>
22
34
  </ComboboxViewport>
23
35
  </ComboboxContent>
@@ -25,16 +37,35 @@
25
37
  </template>
26
38
 
27
39
  <script setup lang="ts">
28
- import { ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxPortal, ComboboxViewport } from 'reka-ui';
40
+ import { ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxPortal, ComboboxViewport, useFilter } from 'reka-ui';
41
+ import { computed, useTemplateRef, watch } from 'vue';
42
+ import type { Nullable } from '@noeldemartin/utils';
43
+ import type { AcceptableValue } from 'reka-ui';
29
44
 
30
45
  import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
46
+ import type { FormFieldValue } from '@aerogel/core/forms';
31
47
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
48
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
32
49
 
33
50
  import ComboboxOption from './ComboboxOption.vue';
34
51
 
52
+ defineEmits<{ select: [] }>();
53
+
54
+ const { newInputValue } = defineProps<{ newInputValue?: (value: string) => Nullable<FormFieldValue> }>();
55
+ const { contains } = useFilter({ sensitivity: 'base' });
35
56
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOptions> must be a child of a <Combobox>');
57
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
58
+ const $group = useTemplateRef('$group');
59
+ const filteredOptions = computed(
60
+ () => select.options?.filter((option) => contains(option.label, combobox.input)) ?? [],
61
+ );
62
+ const showInputOption = computed(
63
+ () => combobox.input && !filteredOptions.value.some((option) => option.label === combobox.input),
64
+ );
36
65
  const renderedClasses = classes(
37
66
  'max-h-(--reka-combobox-content-available-height) min-w-(--reka-combobox-trigger-width)',
38
67
  'z-50 overflow-auto rounded-lg bg-white text-base shadow-lg ring-1 ring-black/5 focus:outline-hidden',
39
68
  );
69
+
70
+ watch($group, () => (combobox.$group = $group.value?.$el ?? null));
40
71
  </script>
@@ -1,17 +1,35 @@
1
1
  <template>
2
- <ComboboxAnchor>
3
- <ComboboxInput :id="select.id" :placeholder="select.placeholder" :class="renderedRootClasses" />
2
+ <ComboboxAnchor class="relative">
3
+ <ComboboxInput
4
+ :id="select.id"
5
+ v-model="combobox.input"
6
+ :placeholder="select.placeholder"
7
+ :class="renderedRootClasses"
8
+ :display-value="select.renderOption"
9
+ :name="select.name"
10
+ @focus="$emit('focus')"
11
+ @blur="onBlur()"
12
+ @keydown.esc="$emit('blur')"
13
+ />
14
+ <div v-if="select?.errors" class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
15
+ <IconExclamationSolid class="size-5 text-red-500" />
16
+ </div>
4
17
  </ComboboxAnchor>
5
18
  </template>
6
19
 
7
20
  <script setup lang="ts">
21
+ import IconExclamationSolid from '~icons/zondicons/exclamation-solid';
22
+
8
23
  import { ComboboxAnchor, ComboboxInput } from 'reka-ui';
24
+ import { computed, watch } from 'vue';
9
25
 
10
26
  import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
11
27
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
12
- import { computed } from 'vue';
28
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
13
29
 
30
+ const emit = defineEmits<{ focus: []; change: []; blur: [] }>();
14
31
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxTrigger> must be a child of a <Combobox>');
32
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
15
33
  const renderedRootClasses = computed(() =>
16
34
  classes(
17
35
  // eslint-disable-next-line vue/max-len
@@ -23,4 +41,27 @@ const renderedRootClasses = computed(() =>
23
41
  'pr-10 text-red-900 ring-red-900/10 placeholder:text-red-300 focus:ring-red-500': select.errors,
24
42
  },
25
43
  ));
44
+
45
+ function onBlur() {
46
+ const elements = Array.from(document.querySelectorAll(':hover'));
47
+
48
+ if (elements.some((element) => combobox.$group?.contains(element))) {
49
+ return;
50
+ }
51
+
52
+ emit('blur');
53
+ }
54
+
55
+ watch(
56
+ () => combobox.input,
57
+ () => {
58
+ if (combobox.preventChange) {
59
+ combobox.preventChange = false;
60
+
61
+ return;
62
+ }
63
+
64
+ emit('change');
65
+ },
66
+ );
26
67
  </script>
@@ -3,6 +3,7 @@
3
3
  <SelectLabel />
4
4
  <slot>
5
5
  <SelectTrigger />
6
+ <HeadlessSelectError class="mt-2 text-sm text-red-600" />
6
7
  <SelectOptions />
7
8
  </slot>
8
9
  </HeadlessSelect>
@@ -19,6 +20,7 @@ import type { FormFieldValue } from '@aerogel/core/forms';
19
20
  import SelectLabel from './SelectLabel.vue';
20
21
  import SelectOptions from './SelectOptions.vue';
21
22
  import SelectTrigger from './SelectTrigger.vue';
23
+ import HeadlessSelectError from '../headless/HeadlessSelectError.vue';
22
24
 
23
25
  defineProps<SelectProps<T>>();
24
26
  defineEmits<SelectEmits<T>>();
@@ -2,11 +2,15 @@
2
2
  <HeadlessSelectTrigger :class="renderedClasses">
3
3
  <HeadlessSelectValue class="col-start-1 row-start-1 truncate pr-6" />
4
4
  <IconCheveronDown class="col-start-1 row-start-1 size-5 self-center justify-self-end text-gray-500 sm:size-4" />
5
+ <div v-if="select?.errors" class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
6
+ <IconExclamationSolid class="size-5 text-red-500" />
7
+ </div>
5
8
  </HeadlessSelectTrigger>
6
9
  </template>
7
10
 
8
11
  <script setup lang="ts">
9
12
  import IconCheveronDown from '~icons/zondicons/cheveron-down';
13
+ import IconExclamationSolid from '~icons/zondicons/exclamation-solid';
10
14
 
11
15
  import { computed } from 'vue';
12
16
  import type { HTMLAttributes } from 'vue';
@@ -22,8 +26,15 @@ const select = injectReactiveOrFail<SelectExpose>('select', '<SelectTrigger> mus
22
26
  const renderedClasses = computed(() =>
23
27
  classes(
24
28
  // eslint-disable-next-line vue/max-len
25
- 'focus:outline-primary-600 data-[state=open]:outline-primary-600 grid w-full cursor-default grid-cols-1 rounded-md bg-white py-1.5 pr-2 pl-3 text-left text-gray-900 outline-1 -outline-offset-1 outline-gray-300 focus:outline-2 focus:-outline-offset-2 sm:text-sm/6',
26
- { 'mt-1': select.label },
29
+ 'relative grid w-full cursor-default grid-cols-1 rounded-md bg-white py-1.5 pr-2 pl-3 text-left text-gray-900 outline-1 -outline-offset-1',
30
+ 'focus:outline-2 focus:-outline-offset-2 sm:text-sm/6',
31
+ {
32
+ 'mt-1': select.label,
33
+ 'outline-gray-300 focus:outline-primary-600 data-[state=open]:outline-primary-600': !select.errors,
34
+ 'text-gray-900 shadow-2xs ring-gray-900/10 placeholder:text-gray-400': !select.errors,
35
+ 'outline-red-900/10 pr-10 text-red-900 placeholder:text-red-300': select.errors,
36
+ 'focus:outline-red-500 data-[state=open]:outline-red-500': select.errors,
37
+ },
27
38
  rootClasses,
28
39
  ));
29
40
  </script>
@@ -0,0 +1,11 @@
1
+ <template>
2
+ <slot />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { provide } from 'vue';
7
+
8
+ const { name, value } = defineProps<{ name: string; value: unknown }>();
9
+
10
+ provide(name, value);
11
+ </script>
@@ -0,0 +1 @@
1
+ export { default as Provide } from './Provide.vue';
@@ -3,6 +3,7 @@ import type { App as AppInstance } from 'vue';
3
3
  import App from '@aerogel/core/services/App';
4
4
  import { bootServices } from '@aerogel/core/services';
5
5
  import { definePlugin } from '@aerogel/core/plugins';
6
+ import { getErrorMessage } from '@aerogel/core/errors/utils';
6
7
 
7
8
  import Errors from './Errors';
8
9
  import settings from './settings';
@@ -16,6 +17,10 @@ export type { ErrorSource, ErrorReport, ErrorReportLog };
16
17
 
17
18
  const services = { $errors: Errors };
18
19
  const frameworkHandler: ErrorHandler = (error) => {
20
+ if (getErrorMessage(error).includes('ResizeObserver loop completed with undelivered notifications.')) {
21
+ return true;
22
+ }
23
+
19
24
  Errors.report(error);
20
25
 
21
26
  return true;