@aerogel/core 0.1.1 → 0.1.2-next.0532ffc3845be5e86d770e8e823f5216ef34dfbf

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 (70) hide show
  1. package/dist/aerogel-core.d.ts +539 -317
  2. package/dist/aerogel-core.js +1938 -1546
  3. package/dist/aerogel-core.js.map +1 -1
  4. package/package.json +4 -2
  5. package/src/bootstrap/index.ts +2 -1
  6. package/src/components/AppLayout.vue +1 -1
  7. package/src/components/AppOverlays.vue +3 -2
  8. package/src/components/contracts/AlertModal.ts +1 -1
  9. package/src/components/contracts/Button.ts +1 -1
  10. package/src/components/contracts/Combobox.ts +5 -0
  11. package/src/components/contracts/ConfirmModal.ts +5 -2
  12. package/src/components/contracts/Modal.ts +8 -3
  13. package/src/components/contracts/PromptModal.ts +6 -2
  14. package/src/components/contracts/Select.ts +98 -4
  15. package/src/components/contracts/Toast.ts +1 -1
  16. package/src/components/contracts/index.ts +1 -0
  17. package/src/components/headless/HeadlessInputInput.vue +27 -5
  18. package/src/components/headless/HeadlessModal.vue +6 -34
  19. package/src/components/headless/HeadlessModalContent.vue +5 -12
  20. package/src/components/headless/HeadlessSelect.vue +10 -91
  21. package/src/components/headless/HeadlessSelectOption.vue +1 -5
  22. package/src/components/index.ts +1 -1
  23. package/src/components/ui/AdvancedOptions.vue +4 -13
  24. package/src/components/ui/Button.vue +1 -0
  25. package/src/components/ui/Combobox.vue +94 -0
  26. package/src/components/ui/ComboboxLabel.vue +29 -0
  27. package/src/components/ui/ComboboxOption.vue +46 -0
  28. package/src/components/ui/ComboboxOptions.vue +71 -0
  29. package/src/components/ui/ComboboxTrigger.vue +67 -0
  30. package/src/components/ui/ConfirmModal.vue +7 -2
  31. package/src/components/ui/Details.vue +33 -0
  32. package/src/components/ui/Form.vue +1 -1
  33. package/src/components/ui/Input.vue +12 -4
  34. package/src/components/ui/LoadingModal.vue +1 -2
  35. package/src/components/ui/Modal.vue +53 -33
  36. package/src/components/ui/ProgressBar.vue +16 -2
  37. package/src/components/ui/PromptModal.vue +7 -2
  38. package/src/components/ui/Select.vue +2 -0
  39. package/src/components/ui/SelectTrigger.vue +13 -2
  40. package/src/components/ui/SettingsModal.vue +1 -1
  41. package/src/components/ui/Toast.vue +1 -0
  42. package/src/components/ui/index.ts +6 -1
  43. package/src/components/vue/Provide.vue +11 -0
  44. package/src/components/vue/index.ts +1 -0
  45. package/src/directives/index.ts +7 -7
  46. package/src/errors/Errors.ts +4 -0
  47. package/src/errors/index.ts +5 -0
  48. package/src/forms/FormController.test.ts +4 -4
  49. package/src/forms/FormController.ts +23 -13
  50. package/src/forms/index.ts +11 -0
  51. package/src/forms/utils.ts +36 -17
  52. package/src/forms/validation.ts +5 -1
  53. package/src/index.css +10 -0
  54. package/src/jobs/Job.ts +1 -1
  55. package/src/plugins/index.ts +1 -3
  56. package/src/services/App.state.ts +1 -0
  57. package/src/services/App.ts +4 -0
  58. package/src/services/index.ts +7 -0
  59. package/src/testing/index.ts +1 -2
  60. package/src/ui/UI.state.ts +0 -11
  61. package/src/ui/UI.ts +43 -125
  62. package/src/ui/index.ts +1 -0
  63. package/src/ui/modals.ts +36 -0
  64. package/src/utils/classes.ts +2 -3
  65. package/src/utils/composition/reactiveSet.test.ts +32 -0
  66. package/src/utils/composition/reactiveSet.ts +61 -0
  67. package/src/utils/index.ts +2 -0
  68. package/src/utils/time.ts +7 -0
  69. package/src/components/AppModals.vue +0 -14
  70. package/src/components/ui/ModalContext.vue +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aerogel/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-next.0532ffc3845be5e86d770e8e823f5216ef34dfbf",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -29,11 +29,13 @@
29
29
  "vue": "^3.5.0"
30
30
  },
31
31
  "dependencies": {
32
- "@noeldemartin/utils": "^0.7.1",
32
+ "@noeldemartin/utils": "0.7.3",
33
+ "@noeldemartin/vue-modals": "0.1.1",
33
34
  "class-variance-authority": "^0.7.1",
34
35
  "clsx": "^2.1.1",
35
36
  "dompurify": "^3.2.4",
36
37
  "eruda": "^3.4.1",
38
+ "eruda-indexeddb": "^0.1.1",
37
39
  "marked": "^15.0.7",
38
40
  "pinia": "^2.1.6",
39
41
  "reka-ui": "^2.2.0",
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="flex min-h-full flex-col text-base leading-tight font-normal text-gray-900 antialiased">
2
+ <div class="text-primary-text flex min-h-full flex-col text-base leading-tight font-normal antialiased">
3
3
  <slot v-if="$errors.hasStartupErrors" name="startup-crash">
4
4
  <component :is="$ui.requireComponent('startup-crash')" />
5
5
  </slot>
@@ -1,9 +1,10 @@
1
1
  <template>
2
- <AppModals />
2
+ <ModalsPortal nested />
3
3
  <AppToasts />
4
4
  </template>
5
5
 
6
6
  <script setup lang="ts">
7
- import AppModals from './AppModals.vue';
7
+ import { ModalsPortal } from '@aerogel/core/ui/modals';
8
+
8
9
  import AppToasts from './AppToasts.vue';
9
10
  </script>
@@ -8,7 +8,7 @@ export interface AlertModalProps {
8
8
  message: string;
9
9
  }
10
10
 
11
- export interface AlertModalExpose extends ModalExpose<void> {}
11
+ export interface AlertModalExpose extends ModalExpose {}
12
12
 
13
13
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
14
14
  export function useAlertModal(props: AlertModalProps) {
@@ -1,7 +1,7 @@
1
1
  import type { PrimitiveProps } from 'reka-ui';
2
2
  import type { HTMLAttributes } from 'vue';
3
3
 
4
- export type ButtonVariant = 'default' | 'secondary' | 'danger' | 'ghost' | 'outline' | 'link';
4
+ export type ButtonVariant = 'default' | 'secondary' | 'danger' | 'warning' | 'ghost' | 'outline' | 'link';
5
5
  export type ButtonSize = 'default' | 'small' | 'large' | 'icon';
6
6
  export interface ButtonProps extends PrimitiveProps {
7
7
  class?: HTMLAttributes['class'];
@@ -0,0 +1,5 @@
1
+ export type ComboboxContext = {
2
+ input: string;
3
+ preventChange: boolean;
4
+ $group: HTMLDivElement | null;
5
+ };
@@ -4,10 +4,11 @@ import { translateWithDefault } from '@aerogel/core/lang';
4
4
  import { useForm } from '@aerogel/core/utils/composition/forms';
5
5
  import type { ButtonVariant } from '@aerogel/core/components/contracts/Button';
6
6
  import type { FormFieldDefinition } from '@aerogel/core/forms/FormController';
7
- import type { ModalExpose } from '@aerogel/core/components/contracts/Modal';
8
7
  import type { Nullable } from '@noeldemartin/utils';
8
+ import type { ModalEmits, ModalExpose } from '@aerogel/core/components/contracts/Modal';
9
9
 
10
10
  export type ConfirmModalCheckboxes = Record<string, { label: string; default?: boolean; required?: boolean }>;
11
+ export type ConfirmModalResult = boolean | [boolean, Record<string, Nullable<boolean>>];
11
12
 
12
13
  export interface ConfirmModalProps {
13
14
  title?: string;
@@ -21,7 +22,9 @@ export interface ConfirmModalProps {
21
22
  required?: boolean;
22
23
  }
23
24
 
24
- export interface ConfirmModalExpose extends ModalExpose<boolean | [boolean, Record<string, Nullable<boolean>>]> {}
25
+ export interface ConfirmModalExpose extends ModalExpose {}
26
+
27
+ export interface ConfirmModalEmits extends ModalEmits<ConfirmModalResult> {}
25
28
 
26
29
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
27
30
  export function useConfirmModal(props: ConfirmModalProps) {
@@ -5,17 +5,22 @@ export type ModalContentInstance = Nullable<InstanceType<typeof DialogContent>>;
5
5
 
6
6
  export interface ModalProps {
7
7
  persistent?: boolean;
8
+ fullscreen?: boolean;
9
+ fullscreenOnMobile?: boolean;
8
10
  title?: string;
9
11
  titleHidden?: boolean;
10
12
  description?: string;
11
13
  descriptionHidden?: boolean;
12
14
  }
13
15
 
14
- export interface ModalSlots<Result = void> {
16
+ export interface ModalSlots<Result = never> {
15
17
  default(props: { close(result?: Result): Promise<void> }): unknown;
16
18
  }
17
19
 
18
- export interface ModalExpose<Result = void> {
19
- close(result?: Result): Promise<void>;
20
+ export interface ModalExpose {
20
21
  $content: ModalContentInstance;
21
22
  }
23
+
24
+ export interface ModalEmits<Result = never> {
25
+ (event: 'close', payload: Result): void;
26
+ }
@@ -4,7 +4,9 @@ import { useForm } from '@aerogel/core/utils/composition/forms';
4
4
  import { requiredStringInput } from '@aerogel/core/forms/utils';
5
5
  import { translateWithDefault } from '@aerogel/core/lang';
6
6
  import type { ButtonVariant } from '@aerogel/core/components/contracts/Button';
7
- import type { ModalExpose } from '@aerogel/core/components/contracts/Modal';
7
+ import type { ModalEmits, ModalExpose } from '@aerogel/core/components/contracts/Modal';
8
+
9
+ export type PromptModalResult = string;
8
10
 
9
11
  export interface PromptModalProps {
10
12
  title?: string;
@@ -18,7 +20,9 @@ export interface PromptModalProps {
18
20
  cancelVariant?: ButtonVariant;
19
21
  }
20
22
 
21
- export interface PromptModalExpose extends ModalExpose<string> {}
23
+ export interface PromptModalExpose extends ModalExpose {}
24
+
25
+ export interface PromptModalEmits extends ModalEmits<PromptModalResult> {}
22
26
 
23
27
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24
28
  export function usePromptModal(props: PromptModalProps) {
@@ -1,8 +1,12 @@
1
+ import { computed, inject, provide, readonly } from 'vue';
2
+ import { evaluate, toString, uuid } from '@noeldemartin/utils';
3
+ import type { AcceptRefs } from '@aerogel/core/utils';
1
4
  import type { AcceptableValue, AsTag, SelectContentProps } from 'reka-ui';
2
- import type { Component, ComputedRef, HTMLAttributes } from 'vue';
5
+ import type { Component, ComputedRef, EmitFn, HTMLAttributes, Ref } from 'vue';
3
6
  import type { Nullable } from '@noeldemartin/utils';
4
7
 
5
- import type { FormFieldValue } from '@aerogel/core/forms';
8
+ import { translateWithDefault } from '@aerogel/core/lang';
9
+ import type { FormController, FormFieldValue } from '@aerogel/core/forms';
6
10
 
7
11
  import type { InputEmits, InputExpose, InputProps } from './Input';
8
12
 
@@ -34,12 +38,102 @@ export interface SelectExpose<T extends Nullable<FormFieldValue> = Nullable<Form
34
38
  options: ComputedRef<Nullable<readonly SelectOptionData[]>>;
35
39
  selectedOption: ComputedRef<Nullable<SelectOptionData>>;
36
40
  placeholder: ComputedRef<string>;
37
- labelClass?: HTMLAttributes['class'];
38
- optionsClass?: HTMLAttributes['class'];
41
+ labelClass: ComputedRef<HTMLAttributes['class']>;
42
+ optionsClass: ComputedRef<HTMLAttributes['class']>;
39
43
  align?: SelectContentProps['align'];
40
44
  side?: SelectContentProps['side'];
45
+ renderOption: (option: T) => string;
41
46
  }
42
47
 
43
48
  export function hasSelectOptionLabel(option: unknown): option is HasSelectOptionLabel {
44
49
  return typeof option === 'object' && option !== null && 'label' in option;
45
50
  }
51
+
52
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
53
+ export function useSelect<T extends Nullable<FormFieldValue>>(
54
+ props: Ref<SelectProps<T>>,
55
+ emit: EmitFn<SelectEmits<T>>,
56
+ ) {
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
+ };
69
+ const computedValue = computed(() => {
70
+ const { name, modelValue } = props.value;
71
+
72
+ if (form && name) {
73
+ return form.getFieldValue(name) as T;
74
+ }
75
+
76
+ return modelValue as T;
77
+ });
78
+ const acceptableValue = computed(() => computedValue.value as AcceptableValue);
79
+ const errors = computed(() => {
80
+ if (!form || !props.value.name) {
81
+ return null;
82
+ }
83
+
84
+ return form.errors[props.value.name] ?? null;
85
+ });
86
+ const computedOptions = computed(() => {
87
+ if (!props.value.options) {
88
+ return null;
89
+ }
90
+
91
+ return props.value.options.map((option) => ({
92
+ key: uuid(),
93
+ label: renderOption(option),
94
+ value: option as AcceptableValue,
95
+ }));
96
+ });
97
+
98
+ const expose = {
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),
104
+ value: computedValue,
105
+ id: `select-${uuid()}`,
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')),
110
+ options: computedOptions,
111
+ selectedOption: computed(() =>
112
+ computedOptions.value?.find((option) => option.value === props.value.modelValue)),
113
+ errors: readonly(errors),
114
+ required: computed(() => {
115
+ if (!props.value.name || !form) {
116
+ return;
117
+ }
118
+
119
+ return form.getFieldRules(props.value.name).includes('required');
120
+ }),
121
+ update(value) {
122
+ if (form && props.value.name) {
123
+ form.setFieldValue(props.value.name, value as FormFieldValue);
124
+
125
+ return;
126
+ }
127
+
128
+ emit('update:modelValue', value);
129
+ },
130
+ } satisfies AcceptRefs<SelectExpose<T>>;
131
+
132
+ function update(value: AcceptableValue) {
133
+ expose.update(value as T);
134
+ }
135
+
136
+ provide('select', expose);
137
+
138
+ return { expose, acceptableValue, update, renderOption };
139
+ }
@@ -1,4 +1,4 @@
1
- export type ToastVariant = 'secondary' | 'danger';
1
+ export type ToastVariant = 'secondary' | 'warning' | 'danger';
2
2
 
3
3
  export interface ToastAction {
4
4
  label: string;
@@ -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,6 +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 { getLocalTimezoneOffset } from '@aerogel/core/utils';
22
23
  import type FormController from '@aerogel/core/forms/FormController';
23
24
  import type { FormFieldValue } from '@aerogel/core/forms/FormController';
24
25
  import type { InputExpose } from '@aerogel/core/components/contracts/Input';
@@ -39,7 +40,7 @@ const renderedType = computed(() => {
39
40
  return ['text', 'email', 'number', 'tel', 'url'].includes(fieldType) ? fieldType : 'text';
40
41
  });
41
42
  const checked = computed(() => {
42
- if (type !== 'checkbox') {
43
+ if (renderedType.value !== 'checkbox') {
43
44
  return;
44
45
  }
45
46
 
@@ -59,11 +60,26 @@ function getValue(): FormFieldValue | null {
59
60
  return null;
60
61
  }
61
62
 
62
- switch (type) {
63
+ switch (renderedType.value) {
63
64
  case 'checkbox':
64
65
  return $input.value.checked;
65
66
  case 'date':
66
- return $input.value.valueAsDate;
67
+ case 'time':
68
+ case 'datetime-local': {
69
+ const date = new Date(
70
+ Math.round($input.value.valueAsNumber / 60000) * 60000 +
71
+ getLocalTimezoneOffset($input.value.valueAsDate ?? new Date($input.value.valueAsNumber)),
72
+ );
73
+
74
+ if (isNaN(date.getTime())) {
75
+ return null;
76
+ }
77
+
78
+ return date;
79
+ }
80
+
81
+ case 'number':
82
+ return $input.value.valueAsNumber;
67
83
  default:
68
84
  return $input.value.value;
69
85
  }
@@ -75,8 +91,14 @@ watchEffect(() => {
75
91
  return;
76
92
  }
77
93
 
78
- if (type === 'date' && value.value instanceof Date) {
79
- $input.value.valueAsDate = value.value;
94
+ if (['date', 'time', 'datetime-local'].includes(renderedType.value) && value.value instanceof Date) {
95
+ const roundedValue = Math.round(value.value.getTime() / 60000) * 60000;
96
+
97
+ $input.value.valueAsNumber = roundedValue - getLocalTimezoneOffset(value.value);
98
+
99
+ if (value.value.getTime() !== roundedValue) {
100
+ input.update(new Date(roundedValue));
101
+ }
80
102
 
81
103
  return;
82
104
  }
@@ -1,57 +1,29 @@
1
1
  <template>
2
- <DialogRoot :ref="forwardRef" open @update:open="persistent || close()">
2
+ <DialogRoot :ref="forwardRef" open @update:open="persistent || $event || close()">
3
3
  <DialogPortal>
4
- <slot :close="close" />
4
+ <slot :close />
5
5
  </DialogPortal>
6
6
  </DialogRoot>
7
7
  </template>
8
8
 
9
9
  <script setup lang="ts" generic="T = void">
10
- import { provide, ref } from 'vue';
11
10
  import { DialogPortal, DialogRoot, useForwardExpose } from 'reka-ui';
11
+ import { provide, ref } from 'vue';
12
12
  import type { DialogContent } from 'reka-ui';
13
13
  import type { Nullable } from '@noeldemartin/utils';
14
14
 
15
- import Events from '@aerogel/core/services/Events';
16
- import { useEvent } from '@aerogel/core/utils/composition/events';
17
- import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
15
+ import { useModal } from '@aerogel/core/ui/modals';
18
16
  import type { AcceptRefs } from '@aerogel/core/utils/vue';
19
- import type { UIModalContext } from '@aerogel/core/ui/UI';
20
17
  import type { ModalExpose, ModalProps, ModalSlots } from '@aerogel/core/components/contracts/Modal';
21
18
 
22
19
  const $content = ref<Nullable<InstanceType<typeof DialogContent>>>(null);
23
- const { modal } = injectReactiveOrFail<UIModalContext>(
24
- 'modal',
25
- 'could not obtain modal reference from <HeadlessModal>, ' +
26
- 'did you render this component manually? Show it using $ui.modal() instead',
27
- );
20
+ const { close } = useModal<T>();
28
21
 
29
22
  defineProps<ModalProps>();
30
23
  defineSlots<ModalSlots<T>>();
31
- defineExpose<AcceptRefs<ModalExpose<T>>>({ close, $content });
24
+ defineExpose<AcceptRefs<ModalExpose>>({ $content });
32
25
 
33
26
  const { forwardRef } = useForwardExpose();
34
- const closed = ref(false);
35
27
 
36
28
  provide('$modalContentRef', $content);
37
-
38
- useEvent('close-modal', async ({ id, result }) => {
39
- if (id !== modal.id) {
40
- return;
41
- }
42
-
43
- await close(result);
44
- });
45
-
46
- async function close(result?: unknown) {
47
- if (closed.value) {
48
- return;
49
- }
50
-
51
- await Events.emit('modal-will-close', { modal, result });
52
-
53
- closed.value = true;
54
-
55
- await Events.emit('modal-has-closed', { modal, result });
56
- }
57
29
  </script>
@@ -2,29 +2,22 @@
2
2
  <DialogContent ref="$contentRef">
3
3
  <slot />
4
4
 
5
- <ModalContext v-if="childModal" :child-index="childIndex + 1" :modal="childModal" />
5
+ <ModalComponent :is="child" v-if="child" />
6
6
  </DialogContent>
7
7
  </template>
8
8
 
9
9
  <script setup lang="ts">
10
- import { computed, useTemplateRef, watchEffect } from 'vue';
10
+ import { useTemplateRef, watchEffect } from 'vue';
11
11
  import { DialogContent } from 'reka-ui';
12
12
  import type { Ref } from 'vue';
13
13
 
14
- import ModalContext from '@aerogel/core/components/ui/ModalContext.vue';
15
- import UI from '@aerogel/core/ui/UI';
16
- import { injectOrFail, injectReactiveOrFail } from '@aerogel/core/utils/vue';
17
- import type { UIModalContext } from '@aerogel/core/ui/UI';
14
+ import { ModalComponent, useModal } from '@aerogel/core/ui/modals';
15
+ import { injectOrFail } from '@aerogel/core/utils/vue';
18
16
  import type { ModalContentInstance } from '@aerogel/core/components/contracts/Modal';
19
17
 
20
- const { childIndex = 0 } = injectReactiveOrFail<UIModalContext>(
21
- 'modal',
22
- 'could not obtain modal reference from <HeadlessModalContent>, ' +
23
- 'did you render this component manually? Show it using $ui.modal() instead',
24
- );
18
+ const { child } = useModal();
25
19
  const $modalContentRef = injectOrFail<Ref<ModalContentInstance>>('$modalContentRef');
26
20
  const $content = useTemplateRef('$contentRef');
27
- const childModal = computed(() => UI.modals[childIndex] ?? null);
28
21
 
29
22
  watchEffect(() => ($modalContentRef.value = $content.value));
30
23
  </script>
@@ -2,7 +2,7 @@
2
2
  <SelectRoot
3
3
  v-slot="{ open }"
4
4
  :model-value="acceptableValue"
5
- :by="compareOptions as Closure<[AcceptableValue, AcceptableValue], boolean>"
5
+ :by="compareOptions"
6
6
  @update:model-value="update($event)"
7
7
  >
8
8
  <component :is="as" v-bind="$attrs">
@@ -15,16 +15,12 @@
15
15
  </template>
16
16
 
17
17
  <script setup lang="ts" generic="T extends Nullable<FormFieldValue>">
18
- import { computed, inject, provide, readonly } from 'vue';
19
- import { value as evaluate, toString, uuid } from '@noeldemartin/utils';
20
18
  import { SelectRoot } from 'reka-ui';
21
- import type { AcceptableValue } from 'reka-ui';
22
- import type { Closure, Nullable } from '@noeldemartin/utils';
19
+ import { computed } from 'vue';
20
+ import type { Nullable } from '@noeldemartin/utils';
23
21
 
24
- import { translateWithDefault } from '@aerogel/core/lang';
25
- import { hasSelectOptionLabel } from '@aerogel/core/components/contracts/Select';
26
- import type FormController from '@aerogel/core/forms/FormController';
27
- import type { SelectEmits, SelectExpose, SelectProps } from '@aerogel/core/components/contracts/Select';
22
+ import { useSelect } from '@aerogel/core/components/contracts/Select';
23
+ import type { SelectEmits, SelectProps } from '@aerogel/core/components/contracts/Select';
28
24
  import type { FormFieldValue } from '@aerogel/core/forms/FormController';
29
25
 
30
26
  import HeadlessSelectTrigger from './HeadlessSelectTrigger.vue';
@@ -32,89 +28,12 @@ import HeadlessSelectOptions from './HeadlessSelectOptions.vue';
32
28
 
33
29
  defineOptions({ inheritAttrs: false });
34
30
 
35
- const {
36
- name,
37
- as = 'div',
38
- label,
39
- options,
40
- labelClass,
41
- optionsClass,
42
- renderOption,
43
- compareOptions = (a, b) => a === b,
44
- description,
45
- placeholder,
46
- modelValue,
47
- align,
48
- side,
49
- } = defineProps<SelectProps<T>>();
50
31
  const emit = defineEmits<SelectEmits<T>>();
51
- const form = inject<FormController | null>('form', null);
52
- const computedValue = computed(() => {
53
- if (form && name) {
54
- return form.getFieldValue(name) as T;
55
- }
32
+ const { as = 'div', compareOptions = (a, b) => a === b, ...props } = defineProps<SelectProps<T>>();
33
+ const { expose, acceptableValue, update } = useSelect(
34
+ computed(() => ({ as, compareOptions, ...props })),
35
+ emit,
36
+ );
56
37
 
57
- return modelValue as T;
58
- });
59
- const acceptableValue = computed(() => computedValue.value as AcceptableValue);
60
- const errors = computed(() => {
61
- if (!form || !name) {
62
- return null;
63
- }
64
-
65
- return form.errors[name] ?? null;
66
- });
67
- const computedOptions = computed(() => {
68
- if (!options) {
69
- return null;
70
- }
71
-
72
- return options.map((option) => ({
73
- key: uuid(),
74
- label: renderOption
75
- ? renderOption(option)
76
- : hasSelectOptionLabel(option)
77
- ? evaluate(option.label as string)
78
- : toString(option),
79
- value: option as AcceptableValue,
80
- }));
81
- });
82
- const expose = {
83
- labelClass,
84
- optionsClass,
85
- align,
86
- side,
87
- value: computedValue,
88
- id: `select-${uuid()}`,
89
- name: computed(() => name),
90
- label: computed(() => label),
91
- description: computed(() => description),
92
- placeholder: computed(() => placeholder ?? translateWithDefault('ui.select', 'Select an option')),
93
- options: computedOptions,
94
- selectedOption: computed(() => computedOptions.value?.find((option) => option.value === modelValue)),
95
- errors: readonly(errors),
96
- required: computed(() => {
97
- if (!name || !form) {
98
- return;
99
- }
100
-
101
- return form.getFieldRules(name).includes('required');
102
- }),
103
- update(value) {
104
- if (form && name) {
105
- form.setFieldValue(name, value as FormFieldValue);
106
-
107
- return;
108
- }
109
-
110
- emit('update:modelValue', value);
111
- },
112
- } satisfies SelectExpose<T>;
113
-
114
- function update(value: AcceptableValue) {
115
- expose.update(value as T);
116
- }
117
-
118
- provide('select', expose);
119
38
  defineExpose(expose);
120
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,8 +1,8 @@
1
1
  export { default as AppLayout } from './AppLayout.vue';
2
- export { default as AppModals } from './AppModals.vue';
3
2
  export { default as AppOverlays } from './AppOverlays.vue';
4
3
  export { default as AppToasts } from './AppToasts.vue';
5
4
 
6
5
  export * from './contracts';
7
6
  export * from './headless';
8
7
  export * from './ui';
8
+ export * from './vue';
@@ -1,18 +1,9 @@
1
1
  <template>
2
- <details class="group">
3
- <summary
4
- class="-ml-2 flex w-[max-content] items-center rounded-lg py-2 pr-3 pl-1 hover:bg-gray-100 focus-visible:outline focus-visible:outline-gray-700"
5
- >
6
- <IconCheveronRight class="size-6 transition-transform group-open:rotate-90" />
7
- <span>{{ $td('ui.advancedOptions', 'Advanced options') }}</span>
8
- </summary>
9
-
10
- <div class="pt-2 pl-4">
11
- <slot />
12
- </div>
13
- </details>
2
+ <Details :label="$td('ui.advancedOptions', 'Advanced options')">
3
+ <slot />
4
+ </Details>
14
5
  </template>
15
6
 
16
7
  <script setup lang="ts">
17
- import IconCheveronRight from '~icons/zondicons/cheveron-right';
8
+ import Details from './Details.vue';
18
9
  </script>
@@ -25,6 +25,7 @@ const renderedClasses = computed(() => variantClasses<Variants<Pick<ButtonProps,
25
25
  default: 'bg-primary-600 text-white focus-visible:outline-primary-600',
26
26
  secondary: 'bg-background text-gray-900 ring-gray-300',
27
27
  danger: 'bg-red-600 text-white focus-visible:outline-red-600',
28
+ warning: 'bg-yellow-600 text-white focus-visible:outline-yellow-600',
28
29
  ghost: 'bg-transparent',
29
30
  outline: 'bg-transparent text-primary-600 ring-primary-600',
30
31
  link: 'text-links',