@aerogel/core 0.1.1-next.ad50ec0af53abadac36a5f25261330a0b5d77f4b → 0.1.1-next.b342b522bd4e8a154c68962bb545cd8ae66010c3

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.ad50ec0af53abadac36a5f25261330a0b5d77f4b",
3
+ "version": "0.1.1-next.b342b522bd4e8a154c68962bb545cd8ae66010c3",
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';
@@ -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>
@@ -1,37 +1,80 @@
1
1
  <template>
2
2
  <ComboboxRoot
3
- open-on-focus
4
3
  ignore-filter
4
+ :open
5
+ :reset-search-term-on-blur="false"
6
+ :reset-search-term-on-select="false"
5
7
  :model-value="acceptableValue"
6
8
  :by="compareOptions"
7
9
  @update:model-value="update($event)"
8
10
  >
9
- <ProvideRef v-model="input" name="combobox-input">
11
+ <Provide name="combobox" :value="combobox">
10
12
  <ComboboxLabel />
11
- <ComboboxTrigger />
12
- <ComboboxOptions />
13
- </ProvideRef>
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>
14
17
  </ComboboxRoot>
15
18
  </template>
16
19
 
17
20
  <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
18
21
  import { ComboboxRoot } from 'reka-ui';
19
- import { ref } from 'vue';
22
+ import { computed, ref, watch } from 'vue';
23
+ import type { AcceptableValue } from 'reka-ui';
20
24
  import type { Nullable } from '@noeldemartin/utils';
21
25
 
22
- import ProvideRef from '@aerogel/core/components/vue/ProvideRef.vue';
26
+ import Provide from '@aerogel/core/components/vue/Provide.vue';
23
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';
24
30
  import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
25
31
  import type { FormFieldValue } from '@aerogel/core/forms';
26
32
 
27
33
  import ComboboxOptions from './ComboboxOptions.vue';
28
34
  import ComboboxTrigger from './ComboboxTrigger.vue';
29
35
  import ComboboxLabel from './ComboboxLabel.vue';
36
+ import HeadlessSelectError from '../headless/HeadlessSelectError.vue';
30
37
 
31
38
  const emit = defineEmits<SelectEmits<T>>();
32
- const { as = 'div', compareOptions = (a, b) => a === b, ...props } = defineProps<SelectProps<T>>();
33
- const { expose, acceptableValue, update } = useSelect({ as, compareOptions, ...props }, emit);
34
- const input = ref(acceptableValue.value ?? '');
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 combobox = {
56
+ input: ref(acceptableValue.value ? renderOption(acceptableValue.value as T) : ''),
57
+ preventChange: ref(false),
58
+ $group: ref(null),
59
+ } satisfies AcceptRefs<ComboboxContext>;
60
+
61
+ function update(value: AcceptableValue) {
62
+ combobox.input.value = renderOption(value as T);
63
+
64
+ baseUpdate(value);
65
+ }
66
+
67
+ watch(combobox.input, (value) => {
68
+ const newInputOption = newInputValue ? (newInputValue(value) as AcceptableValue) : value;
69
+ const renderedValue = renderOption(expose.value.value);
70
+ const renderedNewInputOption = renderOption(expose.value.value as T);
71
+
72
+ if (renderedValue === renderedNewInputOption) {
73
+ return;
74
+ }
75
+
76
+ update(newInputOption);
77
+ });
35
78
 
36
79
  defineExpose(expose);
37
80
  </script>
@@ -1,5 +1,5 @@
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
  >
@@ -12,21 +12,35 @@
12
12
 
13
13
  <script setup lang="ts">
14
14
  import { computed } from 'vue';
15
- import { ComboboxItem, type ComboboxItemProps } from 'reka-ui';
15
+ import { ComboboxItem, injectComboboxRootContext } from 'reka-ui';
16
16
  import { toString } from '@noeldemartin/utils';
17
+ import type { ComboboxItemProps, SelectItemSelectEvent } from 'reka-ui';
17
18
 
18
19
  import { injectReactiveOrFail } from '@aerogel/core/utils';
20
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
19
21
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
20
22
 
23
+ const emit = defineEmits<{ select: [] }>();
24
+
21
25
  const { value } = defineProps<ComboboxItemProps>();
22
26
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOption> must be a child of a <Combobox>');
27
+ const rootContext = injectComboboxRootContext();
28
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
23
29
  const renderedLabel = computed(() => {
24
30
  const itemOption = select.options?.find((option) => option.value === value);
25
31
 
26
- if (itemOption) {
27
- 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;
28
38
  }
29
39
 
30
- return toString(value);
31
- });
40
+ event.preventDefault();
41
+ combobox.preventChange = true;
42
+ rootContext.modelValue.value = value;
43
+
44
+ emit('select');
45
+ }
32
46
  </script>
@@ -16,11 +16,20 @@
16
16
  </div>
17
17
  </ComboboxEmpty>
18
18
 
19
- <ComboboxGroup>
20
- <ComboboxOption v-if="input" :value="input">
21
- {{ input }}
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 }}
22
26
  </ComboboxOption>
23
- <ComboboxOption v-for="option in filteredOptions" :key="option.key" :value="option.value" />
27
+ <ComboboxOption
28
+ v-for="option in filteredOptions"
29
+ :key="option.key"
30
+ :value="option.value"
31
+ @select="$emit('select')"
32
+ />
24
33
  </ComboboxGroup>
25
34
  </ComboboxViewport>
26
35
  </ComboboxContent>
@@ -29,20 +38,34 @@
29
38
 
30
39
  <script setup lang="ts">
31
40
  import { ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxPortal, ComboboxViewport, useFilter } from 'reka-ui';
32
- import { computed } from 'vue';
33
- import type { Ref } from 'vue';
41
+ import { computed, useTemplateRef, watch } from 'vue';
42
+ import type { Nullable } from '@noeldemartin/utils';
43
+ import type { AcceptableValue } from 'reka-ui';
34
44
 
35
- import { classes, injectOrFail, injectReactiveOrFail } from '@aerogel/core/utils';
45
+ import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
46
+ import type { FormFieldValue } from '@aerogel/core/forms';
36
47
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
48
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
37
49
 
38
50
  import ComboboxOption from './ComboboxOption.vue';
39
51
 
52
+ defineEmits<{ select: [] }>();
53
+
54
+ const { newInputValue } = defineProps<{ newInputValue?: (value: string) => Nullable<FormFieldValue> }>();
40
55
  const { contains } = useFilter({ sensitivity: 'base' });
41
56
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxOptions> must be a child of a <Combobox>');
42
- const input = injectOrFail<Ref<string>>('combobox-input');
43
- const filteredOptions = computed(() => select.options?.filter((option) => contains(option.label, input.value)) ?? []);
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
+ );
44
65
  const renderedClasses = classes(
45
66
  'max-h-(--reka-combobox-content-available-height) min-w-(--reka-combobox-trigger-width)',
46
67
  'z-50 overflow-auto rounded-lg bg-white text-base shadow-lg ring-1 ring-black/5 focus:outline-hidden',
47
68
  );
69
+
70
+ watch($group, () => (combobox.$group = $group.value?.$el ?? null));
48
71
  </script>
@@ -1,24 +1,35 @@
1
1
  <template>
2
- <ComboboxAnchor>
2
+ <ComboboxAnchor class="relative">
3
3
  <ComboboxInput
4
4
  :id="select.id"
5
- v-model="input"
5
+ v-model="combobox.input"
6
6
  :placeholder="select.placeholder"
7
7
  :class="renderedRootClasses"
8
+ :display-value="select.renderOption"
9
+ :name="select.name"
10
+ @focus="$emit('focus')"
11
+ @blur="onBlur()"
12
+ @keydown.esc="$emit('blur')"
8
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>
9
17
  </ComboboxAnchor>
10
18
  </template>
11
19
 
12
20
  <script setup lang="ts">
21
+ import IconExclamationSolid from '~icons/zondicons/exclamation-solid';
22
+
13
23
  import { ComboboxAnchor, ComboboxInput } from 'reka-ui';
14
- import { computed } from 'vue';
15
- import type { Ref } from 'vue';
24
+ import { computed, watch } from 'vue';
16
25
 
17
- import { classes, injectOrFail, injectReactiveOrFail } from '@aerogel/core/utils';
26
+ import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
18
27
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
28
+ import type { ComboboxContext } from '@aerogel/core/components/contracts/Combobox';
19
29
 
30
+ const emit = defineEmits<{ focus: []; change: []; blur: [] }>();
20
31
  const select = injectReactiveOrFail<SelectExpose>('select', '<ComboboxTrigger> must be a child of a <Combobox>');
21
- const input = injectOrFail<Ref<string>>('combobox-input');
32
+ const combobox = injectReactiveOrFail<ComboboxContext>('combobox');
22
33
  const renderedRootClasses = computed(() =>
23
34
  classes(
24
35
  // eslint-disable-next-line vue/max-len
@@ -30,4 +41,27 @@ const renderedRootClasses = computed(() =>
30
41
  'pr-10 text-red-900 ring-red-900/10 placeholder:text-red-300 focus:ring-red-500': select.errors,
31
42
  },
32
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
+ );
33
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>
@@ -1 +1 @@
1
- export { default as ProvideRef } from './ProvideRef.vue';
1
+ export { default as Provide } from './Provide.vue';
@@ -30,7 +30,7 @@ describe('FormController', () => {
30
30
  const form = useForm({
31
31
  name: {
32
32
  type: 'string',
33
- rules: 'required',
33
+ rules: ['required'],
34
34
  },
35
35
  });
36
36
 
@@ -48,7 +48,7 @@ describe('FormController', () => {
48
48
  const form = useForm({
49
49
  name: {
50
50
  type: 'string',
51
- rules: 'required',
51
+ rules: ['required'],
52
52
  },
53
53
  });
54
54
 
@@ -69,11 +69,11 @@ describe('FormController', () => {
69
69
  const form = useForm({
70
70
  trimmed: {
71
71
  type: 'string',
72
- rules: 'required',
72
+ rules: ['required'],
73
73
  },
74
74
  untrimmed: {
75
75
  type: 'string',
76
- rules: 'required',
76
+ rules: ['required'],
77
77
  trim: false,
78
78
  },
79
79
  });
@@ -14,7 +14,7 @@ export interface FormFieldDefinition<
14
14
  type: TType;
15
15
  trim?: boolean;
16
16
  default?: GetFormFieldValue<TType>;
17
- rules?: TRules;
17
+ rules?: TRules[];
18
18
  values?: readonly TValueType[];
19
19
  [__valueType]?: TValueType;
20
20
  }
@@ -109,7 +109,7 @@ export default class FormController<Fields extends FormFieldDefinitions = FormFi
109
109
  }
110
110
 
111
111
  public getFieldRules<T extends keyof Fields>(field: T): string[] {
112
- return this._fields[field]?.rules?.split('|') ?? [];
112
+ return this._fields[field]?.rules ?? [];
113
113
  }
114
114
 
115
115
  public setFieldErrors<T extends keyof Fields>(field: T, errors: string[] | null): void {
@@ -201,7 +201,7 @@ export default class FormController<Fields extends FormFieldDefinitions = FormFi
201
201
  private getFieldErrors(name: keyof Fields, definition: FormFieldDefinition): string[] | null {
202
202
  const errors = [];
203
203
  const value = this._data[name];
204
- const rules = definition.rules?.split('|') ?? [];
204
+ const rules = definition.rules ?? [];
205
205
 
206
206
  errors.push(...validateType(value, definition));
207
207
 
@@ -1,4 +1,15 @@
1
+ import { registerFormValidationRule } from '@aerogel/core/forms/validation';
2
+ import { definePlugin } from '@aerogel/core/plugins';
3
+
1
4
  export * from './FormController';
2
5
  export * from './utils';
3
6
  export * from './validation';
4
7
  export { default as FormController } from './FormController';
8
+
9
+ export default definePlugin({
10
+ async install(_, { formValidationRules }) {
11
+ for (const [rule, validator] of Object.entries(formValidationRules ?? {})) {
12
+ registerFormValidationRule(rule, validator);
13
+ }
14
+ },
15
+ });