@aerogel/core 0.0.0-next.f8cdd39997c56dcd46e07c26af8a84d04d610fce → 0.0.0-next.fcfbfdc3428c34c4d1c0e781b61d244f13232fc9

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 (182) hide show
  1. package/dist/aerogel-core.d.ts +2645 -884
  2. package/dist/aerogel-core.js +3266 -0
  3. package/dist/aerogel-core.js.map +1 -0
  4. package/package.json +36 -34
  5. package/src/bootstrap/bootstrap.test.ts +7 -10
  6. package/src/bootstrap/index.ts +43 -14
  7. package/src/bootstrap/options.ts +4 -1
  8. package/src/components/AppLayout.vue +16 -0
  9. package/src/components/{AGAppModals.vue → AppModals.vue} +3 -4
  10. package/src/components/{AGAppOverlays.vue → AppOverlays.vue} +5 -6
  11. package/src/components/AppToasts.vue +16 -0
  12. package/src/components/contracts/AlertModal.ts +4 -0
  13. package/src/components/contracts/Button.ts +16 -0
  14. package/src/components/contracts/ConfirmModal.ts +41 -0
  15. package/src/components/contracts/DropdownMenu.ts +20 -0
  16. package/src/components/contracts/ErrorReportModal.ts +29 -0
  17. package/src/components/contracts/Input.ts +26 -0
  18. package/src/components/contracts/LoadingModal.ts +22 -0
  19. package/src/components/contracts/Modal.ts +21 -0
  20. package/src/components/contracts/PromptModal.ts +30 -0
  21. package/src/components/contracts/Select.ts +44 -0
  22. package/src/components/contracts/Toast.ts +13 -0
  23. package/src/components/contracts/index.ts +11 -0
  24. package/src/components/headless/HeadlessButton.vue +51 -0
  25. package/src/components/headless/HeadlessInput.vue +59 -0
  26. package/src/components/headless/HeadlessInputDescription.vue +27 -0
  27. package/src/components/headless/{forms/AGHeadlessInputError.vue → HeadlessInputError.vue} +4 -8
  28. package/src/components/headless/HeadlessInputInput.vue +75 -0
  29. package/src/components/headless/HeadlessInputLabel.vue +18 -0
  30. package/src/components/headless/HeadlessInputTextArea.vue +40 -0
  31. package/src/components/headless/HeadlessModal.vue +92 -0
  32. package/src/components/headless/HeadlessModalContent.vue +30 -0
  33. package/src/components/headless/HeadlessModalDescription.vue +12 -0
  34. package/src/components/headless/HeadlessModalOverlay.vue +12 -0
  35. package/src/components/headless/HeadlessModalTitle.vue +12 -0
  36. package/src/components/headless/HeadlessSelect.vue +118 -0
  37. package/src/components/headless/HeadlessSelectError.vue +25 -0
  38. package/src/components/headless/HeadlessSelectLabel.vue +25 -0
  39. package/src/components/headless/HeadlessSelectOption.vue +34 -0
  40. package/src/components/headless/HeadlessSelectOptions.vue +37 -0
  41. package/src/components/headless/HeadlessSelectTrigger.vue +22 -0
  42. package/src/components/headless/HeadlessSelectValue.vue +18 -0
  43. package/src/components/headless/HeadlessToast.vue +18 -0
  44. package/src/components/headless/HeadlessToastAction.vue +13 -0
  45. package/src/components/headless/index.ts +19 -3
  46. package/src/components/index.ts +6 -9
  47. package/src/components/ui/AdvancedOptions.vue +18 -0
  48. package/src/components/ui/AlertModal.vue +13 -0
  49. package/src/components/ui/Button.vue +98 -0
  50. package/src/components/ui/Checkbox.vue +56 -0
  51. package/src/components/ui/ConfirmModal.vue +42 -0
  52. package/src/components/ui/DropdownMenu.vue +32 -0
  53. package/src/components/ui/DropdownMenuOption.vue +14 -0
  54. package/src/components/ui/DropdownMenuOptions.vue +27 -0
  55. package/src/components/ui/EditableContent.vue +82 -0
  56. package/src/components/ui/ErrorMessage.vue +15 -0
  57. package/src/components/ui/ErrorReportModal.vue +62 -0
  58. package/src/components/{modals/AGErrorReportModalButtons.vue → ui/ErrorReportModalButtons.vue} +38 -29
  59. package/src/components/ui/ErrorReportModalTitle.vue +24 -0
  60. package/src/components/ui/Form.vue +24 -0
  61. package/src/components/ui/Input.vue +56 -0
  62. package/src/components/ui/Link.vue +12 -0
  63. package/src/components/ui/LoadingModal.vue +32 -0
  64. package/src/components/ui/Markdown.vue +69 -0
  65. package/src/components/ui/Modal.vue +91 -0
  66. package/src/components/ui/ModalContext.vue +30 -0
  67. package/src/components/ui/ProgressBar.vue +51 -0
  68. package/src/components/ui/PromptModal.vue +35 -0
  69. package/src/components/ui/Select.vue +25 -0
  70. package/src/components/ui/SelectLabel.vue +17 -0
  71. package/src/components/ui/SelectOption.vue +29 -0
  72. package/src/components/ui/SelectOptions.vue +30 -0
  73. package/src/components/ui/SelectTrigger.vue +29 -0
  74. package/src/components/ui/SettingsModal.vue +15 -0
  75. package/src/components/ui/StartupCrash.vue +31 -0
  76. package/src/components/ui/Toast.vue +42 -0
  77. package/src/components/ui/index.ts +30 -0
  78. package/src/directives/index.ts +13 -5
  79. package/src/directives/measure.ts +40 -0
  80. package/src/errors/Errors.state.ts +1 -1
  81. package/src/errors/Errors.ts +35 -34
  82. package/src/errors/JobCancelledError.ts +3 -0
  83. package/src/errors/index.ts +19 -29
  84. package/src/errors/utils.ts +35 -0
  85. package/src/forms/{Form.test.ts → FormController.test.ts} +33 -4
  86. package/src/forms/FormController.ts +245 -0
  87. package/src/forms/composition.ts +4 -4
  88. package/src/forms/index.ts +3 -1
  89. package/src/forms/utils.ts +36 -5
  90. package/src/forms/validation.ts +19 -0
  91. package/src/index.css +54 -0
  92. package/src/{main.ts → index.ts} +3 -0
  93. package/src/jobs/Job.ts +147 -0
  94. package/src/jobs/index.ts +10 -0
  95. package/src/jobs/listeners.ts +3 -0
  96. package/src/jobs/status.ts +4 -0
  97. package/src/lang/DefaultLangProvider.ts +46 -0
  98. package/src/lang/Lang.state.ts +11 -0
  99. package/src/lang/Lang.ts +44 -29
  100. package/src/lang/index.ts +12 -6
  101. package/src/lang/settings/Language.vue +48 -0
  102. package/src/lang/settings/index.ts +10 -0
  103. package/src/plugins/Plugin.ts +2 -1
  104. package/src/plugins/index.ts +22 -0
  105. package/src/services/App.state.ts +40 -6
  106. package/src/services/App.ts +53 -5
  107. package/src/services/Cache.ts +43 -0
  108. package/src/services/Events.test.ts +39 -0
  109. package/src/services/Events.ts +112 -32
  110. package/src/services/Service.ts +154 -49
  111. package/src/services/Storage.ts +20 -0
  112. package/src/services/index.ts +18 -6
  113. package/src/services/store.ts +8 -5
  114. package/src/services/utils.ts +18 -0
  115. package/src/testing/index.ts +26 -0
  116. package/src/testing/setup.ts +11 -0
  117. package/src/ui/UI.state.ts +19 -7
  118. package/src/ui/UI.ts +274 -58
  119. package/src/ui/index.ts +23 -17
  120. package/src/ui/utils.ts +16 -0
  121. package/src/utils/classes.ts +49 -0
  122. package/src/utils/composition/events.ts +3 -2
  123. package/src/utils/composition/forms.ts +14 -4
  124. package/src/utils/composition/persistent.test.ts +33 -0
  125. package/src/utils/composition/persistent.ts +11 -0
  126. package/src/utils/composition/state.test.ts +47 -0
  127. package/src/utils/composition/state.ts +33 -0
  128. package/src/utils/index.ts +5 -0
  129. package/src/utils/markdown.test.ts +50 -0
  130. package/src/utils/markdown.ts +19 -6
  131. package/src/utils/types.ts +3 -0
  132. package/src/utils/vue.ts +28 -118
  133. package/.eslintrc.js +0 -3
  134. package/dist/aerogel-core.cjs.js +0 -2
  135. package/dist/aerogel-core.cjs.js.map +0 -1
  136. package/dist/aerogel-core.esm.js +0 -2
  137. package/dist/aerogel-core.esm.js.map +0 -1
  138. package/dist/virtual.d.ts +0 -11
  139. package/noeldemartin.config.js +0 -5
  140. package/src/components/AGAppLayout.vue +0 -11
  141. package/src/components/AGAppSnackbars.vue +0 -13
  142. package/src/components/basic/AGErrorMessage.vue +0 -16
  143. package/src/components/basic/AGLink.vue +0 -9
  144. package/src/components/basic/AGMarkdown.vue +0 -36
  145. package/src/components/basic/index.ts +0 -5
  146. package/src/components/constants.ts +0 -8
  147. package/src/components/forms/AGButton.vue +0 -44
  148. package/src/components/forms/AGCheckbox.vue +0 -35
  149. package/src/components/forms/AGForm.vue +0 -26
  150. package/src/components/forms/AGInput.vue +0 -36
  151. package/src/components/forms/index.ts +0 -6
  152. package/src/components/headless/forms/AGHeadlessButton.vue +0 -51
  153. package/src/components/headless/forms/AGHeadlessInput.ts +0 -8
  154. package/src/components/headless/forms/AGHeadlessInput.vue +0 -54
  155. package/src/components/headless/forms/AGHeadlessInputInput.vue +0 -45
  156. package/src/components/headless/forms/AGHeadlessInputLabel.vue +0 -16
  157. package/src/components/headless/forms/index.ts +0 -6
  158. package/src/components/headless/modals/AGHeadlessModal.ts +0 -7
  159. package/src/components/headless/modals/AGHeadlessModal.vue +0 -88
  160. package/src/components/headless/modals/AGHeadlessModalPanel.vue +0 -28
  161. package/src/components/headless/modals/AGHeadlessModalTitle.vue +0 -13
  162. package/src/components/headless/modals/index.ts +0 -6
  163. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +0 -10
  164. package/src/components/headless/snackbars/index.ts +0 -25
  165. package/src/components/modals/AGAlertModal.vue +0 -25
  166. package/src/components/modals/AGConfirmModal.vue +0 -30
  167. package/src/components/modals/AGErrorReportModal.ts +0 -20
  168. package/src/components/modals/AGErrorReportModal.vue +0 -62
  169. package/src/components/modals/AGErrorReportModalTitle.vue +0 -25
  170. package/src/components/modals/AGLoadingModal.vue +0 -19
  171. package/src/components/modals/AGModal.ts +0 -10
  172. package/src/components/modals/AGModal.vue +0 -36
  173. package/src/components/modals/AGModalContext.ts +0 -8
  174. package/src/components/modals/AGModalContext.vue +0 -22
  175. package/src/components/modals/index.ts +0 -21
  176. package/src/components/snackbars/AGSnackbar.vue +0 -42
  177. package/src/components/snackbars/index.ts +0 -3
  178. package/src/directives/initial-focus.ts +0 -11
  179. package/src/forms/Form.ts +0 -176
  180. package/src/types/virtual.d.ts +0 -11
  181. package/tsconfig.json +0 -11
  182. package/vite.config.ts +0 -14
@@ -0,0 +1,59 @@
1
+ <template>
2
+ <component :is="as">
3
+ <slot />
4
+ </component>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed, inject, provide, readonly } from 'vue';
9
+ import { uuid } from '@noeldemartin/utils';
10
+
11
+ import type FormController from '@aerogel/core/forms/FormController';
12
+ import type { FormFieldValue } from '@aerogel/core/forms/FormController';
13
+ import type { InputEmits, InputExpose, InputProps } from '@aerogel/core/components/contracts/Input';
14
+
15
+ const { as = 'div', name, label, description, modelValue } = defineProps<InputProps & { as?: string }>();
16
+ const emit = defineEmits<InputEmits>();
17
+ const form = inject<FormController | null>('form', null);
18
+ const errors = computed(() => {
19
+ if (!form || !name) {
20
+ return null;
21
+ }
22
+
23
+ return form.errors[name] ?? null;
24
+ });
25
+
26
+ const expose = {
27
+ id: `input-${uuid()}`,
28
+ name: computed(() => name),
29
+ label: computed(() => label),
30
+ description: computed(() => description),
31
+ value: computed(() => {
32
+ if (form && name) {
33
+ return form.getFieldValue(name);
34
+ }
35
+
36
+ return modelValue;
37
+ }),
38
+ errors: readonly(errors),
39
+ required: computed(() => {
40
+ if (!name || !form) {
41
+ return;
42
+ }
43
+
44
+ return form.getFieldRules(name).includes('required');
45
+ }),
46
+ update(value) {
47
+ if (form && name) {
48
+ form.setFieldValue(name, value as FormFieldValue);
49
+
50
+ return;
51
+ }
52
+
53
+ emit('update:modelValue', value);
54
+ },
55
+ } satisfies InputExpose;
56
+
57
+ provide('input', expose);
58
+ defineExpose(expose);
59
+ </script>
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <slot :id="`${input.id}-description`">
3
+ <Markdown
4
+ v-if="show"
5
+ v-bind="$attrs"
6
+ :id="`${input.id}-description`"
7
+ :text
8
+ />
9
+ </slot>
10
+ </template>
11
+
12
+ <script setup lang="ts">
13
+ import { computed } from 'vue';
14
+
15
+ import Markdown from '@aerogel/core/components/ui/Markdown.vue';
16
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
17
+ import type { InputExpose } from '@aerogel/core/components/contracts/Input';
18
+
19
+ defineOptions({ inheritAttrs: false });
20
+
21
+ const input = injectReactiveOrFail<InputExpose>(
22
+ 'input',
23
+ '<HeadlessInputDescription> must be a child of a <HeadlessInput>',
24
+ );
25
+ const text = computed(() => (typeof input.description === 'string' ? input.description : ''));
26
+ const show = computed(() => !!input.description);
27
+ </script>
@@ -7,15 +7,11 @@
7
7
  <script setup lang="ts">
8
8
  import { computed } from 'vue';
9
9
 
10
- import { injectReactiveOrFail } from '@/utils/vue';
11
- import { translateWithDefault } from '@/lang/utils';
10
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
11
+ import { translateWithDefault } from '@aerogel/core/lang/utils';
12
+ import type { InputExpose } from '@aerogel/core/components/contracts/Input';
12
13
 
13
- import type { IAGHeadlessInput } from './AGHeadlessInput';
14
-
15
- const input = injectReactiveOrFail<IAGHeadlessInput>(
16
- 'input',
17
- '<AGHeadlessInputError> must be a child of a <AGHeadlessInput>',
18
- );
14
+ const input = injectReactiveOrFail<InputExpose>('input', '<HeadlessInputError> must be a child of a <HeadlessInput>');
19
15
  const errorMessage = computed(() => {
20
16
  if (!input.errors) {
21
17
  return null;
@@ -0,0 +1,75 @@
1
+ <template>
2
+ <input
3
+ :id="input.id"
4
+ ref="$inputRef"
5
+ :name
6
+ :type
7
+ :checked
8
+ :required="input.required ?? undefined"
9
+ :aria-invalid="input.errors ? 'true' : 'false'"
10
+ :aria-describedby="
11
+ input.errors ? `${input.id}-error` : input.description ? `${input.id}-description` : undefined
12
+ "
13
+ @input="update"
14
+ >
15
+ </template>
16
+
17
+ <script setup lang="ts">
18
+ import { computed, useTemplateRef, watchEffect } from 'vue';
19
+
20
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
21
+ import { onFormFocus } from '@aerogel/core/utils/composition/forms';
22
+ import type { FormFieldValue } from '@aerogel/core/forms/FormController';
23
+ import type { InputExpose } from '@aerogel/core/components/contracts/Input';
24
+
25
+ const { type = 'text' } = defineProps<{ type?: string }>();
26
+ const $input = useTemplateRef('$inputRef');
27
+ const input = injectReactiveOrFail<InputExpose>('input', '<HeadlessInputInput> must be a child of a <HeadlessInput>');
28
+ const name = computed(() => input.name ?? undefined);
29
+ const value = computed(() => input.value);
30
+ const checked = computed(() => {
31
+ if (type !== 'checkbox') {
32
+ return;
33
+ }
34
+
35
+ return !!value.value;
36
+ });
37
+
38
+ function update() {
39
+ if (!$input.value) {
40
+ return;
41
+ }
42
+
43
+ input.update(getValue());
44
+ }
45
+
46
+ function getValue(): FormFieldValue | null {
47
+ if (!$input.value) {
48
+ return null;
49
+ }
50
+
51
+ switch (type) {
52
+ case 'checkbox':
53
+ return $input.value.checked;
54
+ case 'date':
55
+ return $input.value.valueAsDate;
56
+ default:
57
+ return $input.value.value;
58
+ }
59
+ }
60
+
61
+ onFormFocus(input, () => $input.value?.focus());
62
+ watchEffect(() => {
63
+ if (!$input.value) {
64
+ return;
65
+ }
66
+
67
+ if (type === 'date') {
68
+ $input.value.valueAsDate = value.value as Date;
69
+
70
+ return;
71
+ }
72
+
73
+ $input.value.value = (value.value as string) ?? null;
74
+ });
75
+ </script>
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <label v-if="show" :for="input.id">
3
+ <slot>
4
+ {{ input.label }}
5
+ </slot>
6
+ </label>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { computed, useSlots } from 'vue';
11
+
12
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
13
+ import type { InputExpose } from '@aerogel/core/components/contracts/Input';
14
+
15
+ const input = injectReactiveOrFail<InputExpose>('input', '<HeadlessInputLabel> must be a child of a <HeadlessInput>');
16
+ const slots = useSlots();
17
+ const show = computed(() => !!(input.label || slots.default));
18
+ </script>
@@ -0,0 +1,40 @@
1
+ <template>
2
+ <textarea
3
+ :id="input.id"
4
+ ref="$textAreaRef"
5
+ :name
6
+ :value
7
+ :required="input.required ?? undefined"
8
+ :aria-invalid="input.errors ? 'true' : 'false'"
9
+ :aria-describedby="
10
+ input.errors ? `${input.id}-error` : input.description ? `${input.id}-description` : undefined
11
+ "
12
+ @input="update"
13
+ />
14
+ </template>
15
+
16
+ <script setup lang="ts">
17
+ import { computed, useTemplateRef } from 'vue';
18
+
19
+ import { onFormFocus } from '@aerogel/core/utils/composition/forms';
20
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
21
+ import type { InputExpose } from '@aerogel/core/components/contracts/Input';
22
+
23
+ const $textArea = useTemplateRef('$textAreaRef');
24
+ const input = injectReactiveOrFail<InputExpose>(
25
+ 'input',
26
+ '<HeadlessInputTextArea> must be a child of a <HeadlessInput>',
27
+ );
28
+ const name = computed(() => input.name ?? undefined);
29
+ const value = computed(() => input.value as string);
30
+
31
+ function update() {
32
+ if (!$textArea.value) {
33
+ return;
34
+ }
35
+
36
+ input.update($textArea.value.value);
37
+ }
38
+
39
+ onFormFocus(input, () => $textArea.value?.focus());
40
+ </script>
@@ -0,0 +1,92 @@
1
+ <template>
2
+ <DialogRoot :ref="forwardRef" open @update:open="persistent || close()">
3
+ <DialogPortal>
4
+ <slot :close="close" />
5
+ </DialogPortal>
6
+ </DialogRoot>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { provide, ref } from 'vue';
11
+ import { DialogPortal, DialogRoot, useForwardExpose } from 'reka-ui';
12
+ import type { DialogContent } from 'reka-ui';
13
+ import type { Nullable } from '@noeldemartin/utils';
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';
18
+ import type { AcceptRefs } from '@aerogel/core/utils/vue';
19
+ import type { UIModalContext } from '@aerogel/core/ui/UI.state';
20
+ import type { ModalExpose, ModalProps, ModalSlots } from '@aerogel/core/components/contracts/Modal';
21
+
22
+ 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.openModal() instead',
27
+ );
28
+
29
+ defineProps<ModalProps>();
30
+ defineSlots<ModalSlots>();
31
+ defineExpose<AcceptRefs<ModalExpose>>({ close, $content });
32
+
33
+ const { forwardRef, currentElement } = useForwardExpose();
34
+ const hidden = ref(true);
35
+ const closed = ref(false);
36
+
37
+ provide('$modalContentRef', $content);
38
+
39
+ useEvent('close-modal', async ({ id, result }) => {
40
+ if (id !== modal.id) {
41
+ return;
42
+ }
43
+
44
+ await close(result);
45
+ });
46
+
47
+ useEvent('hide-modal', async ({ id }) => {
48
+ if (id !== modal.id) {
49
+ return;
50
+ }
51
+
52
+ await hide();
53
+ });
54
+
55
+ useEvent('show-modal', async ({ id }) => {
56
+ if (id !== modal.id) {
57
+ return;
58
+ }
59
+
60
+ await show();
61
+ });
62
+
63
+ async function hide(): Promise<void> {
64
+ if (!currentElement.value) {
65
+ return;
66
+ }
67
+
68
+ hidden.value = true;
69
+ }
70
+
71
+ async function show(): Promise<void> {
72
+ if (!currentElement.value) {
73
+ return;
74
+ }
75
+
76
+ hidden.value = false;
77
+ }
78
+
79
+ async function close(result?: unknown) {
80
+ if (closed.value) {
81
+ return;
82
+ }
83
+
84
+ Events.emit('modal-will-close', { modal, result });
85
+
86
+ await hide();
87
+
88
+ closed.value = true;
89
+
90
+ Events.emit('modal-closed', { modal, result });
91
+ }
92
+ </script>
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <DialogContent ref="$contentRef">
3
+ <slot />
4
+
5
+ <ModalContext v-if="childModal" :child-index="childIndex + 1" :modal="childModal" />
6
+ </DialogContent>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { computed, useTemplateRef, watchEffect } from 'vue';
11
+ import { DialogContent } from 'reka-ui';
12
+ import type { Ref } from 'vue';
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.state';
18
+ import type { ModalContentInstance } from '@aerogel/core/components/contracts/Modal';
19
+
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.openModal() instead',
24
+ );
25
+ const $modalContentRef = injectOrFail<Ref<ModalContentInstance>>('$modalContentRef');
26
+ const $content = useTemplateRef('$contentRef');
27
+ const childModal = computed(() => UI.modals[childIndex] ?? null);
28
+
29
+ watchEffect(() => ($modalContentRef.value = $content.value));
30
+ </script>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <DialogDescription v-bind="$props">
3
+ <slot />
4
+ </DialogDescription>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { DialogDescription } from 'reka-ui';
9
+ import type { DialogDescriptionProps } from 'reka-ui';
10
+
11
+ defineProps<DialogDescriptionProps>();
12
+ </script>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <DialogOverlay v-bind="$props">
3
+ <slot />
4
+ </DialogOverlay>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { DialogOverlay } from 'reka-ui';
9
+ import type { DialogOverlayProps } from 'reka-ui';
10
+
11
+ defineProps<DialogOverlayProps>();
12
+ </script>
@@ -0,0 +1,12 @@
1
+ <template>
2
+ <DialogTitle v-bind="$props">
3
+ <slot />
4
+ </DialogTitle>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { DialogTitle } from 'reka-ui';
9
+ import type { DialogTitleProps } from 'reka-ui';
10
+
11
+ defineProps<DialogTitleProps>();
12
+ </script>
@@ -0,0 +1,118 @@
1
+ <template>
2
+ <SelectRoot
3
+ v-slot="{ open }"
4
+ :model-value="acceptableValue"
5
+ :by="(a, b) => a === b"
6
+ @update:model-value="update($event)"
7
+ >
8
+ <component :is="as" v-bind="$attrs">
9
+ <slot :model-value :open>
10
+ <HeadlessSelectTrigger />
11
+ <HeadlessSelectOptions />
12
+ </slot>
13
+ </component>
14
+ </SelectRoot>
15
+ </template>
16
+
17
+ <script setup lang="ts">
18
+ import { computed, inject, provide, readonly } from 'vue';
19
+ import { value as evaluate, toString, uuid } from '@noeldemartin/utils';
20
+ import { SelectRoot } from 'reka-ui';
21
+ import type { AcceptableValue } from 'reka-ui';
22
+
23
+ import { translateWithDefault } from '@aerogel/core/lang';
24
+ import { hasSelectOptionLabel } from '@aerogel/core/components/contracts/Select';
25
+ import type FormController from '@aerogel/core/forms/FormController';
26
+ import type { SelectEmits, SelectExpose, SelectProps } from '@aerogel/core/components/contracts/Select';
27
+ import type { FormFieldValue } from '@aerogel/core/forms/FormController';
28
+
29
+ import HeadlessSelectTrigger from './HeadlessSelectTrigger.vue';
30
+ import HeadlessSelectOptions from './HeadlessSelectOptions.vue';
31
+
32
+ defineOptions({ inheritAttrs: false });
33
+
34
+ const {
35
+ name,
36
+ as = 'div',
37
+ label,
38
+ options,
39
+ labelClass,
40
+ optionsClass,
41
+ renderOption,
42
+ description,
43
+ placeholder,
44
+ modelValue,
45
+ align,
46
+ side,
47
+ } = defineProps<SelectProps>();
48
+ const emit = defineEmits<SelectEmits>();
49
+ const form = inject<FormController | null>('form', null);
50
+ const computedValue = computed(() => {
51
+ if (form && name) {
52
+ return form.getFieldValue(name);
53
+ }
54
+
55
+ return modelValue;
56
+ });
57
+ const acceptableValue = computed(() => computedValue.value as AcceptableValue);
58
+ const errors = computed(() => {
59
+ if (!form || !name) {
60
+ return null;
61
+ }
62
+
63
+ return form.errors[name] ?? null;
64
+ });
65
+ const computedOptions = computed(() => {
66
+ if (!options) {
67
+ return null;
68
+ }
69
+
70
+ return options.map((option) => ({
71
+ key: uuid(),
72
+ label: renderOption
73
+ ? renderOption(option)
74
+ : hasSelectOptionLabel(option)
75
+ ? evaluate(option.label as string)
76
+ : toString(option),
77
+ value: option as AcceptableValue,
78
+ }));
79
+ });
80
+ const expose = {
81
+ labelClass,
82
+ optionsClass,
83
+ align,
84
+ side,
85
+ value: computedValue,
86
+ id: `select-${uuid()}`,
87
+ name: computed(() => name),
88
+ label: computed(() => label),
89
+ description: computed(() => description),
90
+ placeholder: computed(() => placeholder ?? translateWithDefault('ui.select', 'Select an option')),
91
+ options: computedOptions,
92
+ selectedOption: computed(() => computedOptions.value?.find((option) => option.value === modelValue)),
93
+ errors: readonly(errors),
94
+ required: computed(() => {
95
+ if (!name || !form) {
96
+ return;
97
+ }
98
+
99
+ return form.getFieldRules(name).includes('required');
100
+ }),
101
+ update(value) {
102
+ if (form && name) {
103
+ form.setFieldValue(name, value as FormFieldValue);
104
+
105
+ return;
106
+ }
107
+
108
+ emit('update:modelValue', value);
109
+ },
110
+ } satisfies SelectExpose;
111
+
112
+ function update(value: AcceptableValue) {
113
+ expose.update(value as FormFieldValue);
114
+ }
115
+
116
+ provide('select', expose);
117
+ defineExpose(expose);
118
+ </script>
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <p v-if="errorMessage" :id="`${select.id}-error`">
3
+ {{ errorMessage }}
4
+ </p>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { computed } from 'vue';
9
+
10
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
11
+ import { translateWithDefault } from '@aerogel/core/lang/utils';
12
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
13
+
14
+ const select = injectReactiveOrFail<SelectExpose>(
15
+ 'select',
16
+ '<HeadlessSelectError> must be a child of a <HeadlessSelect>',
17
+ );
18
+ const errorMessage = computed(() => {
19
+ if (!select.errors) {
20
+ return null;
21
+ }
22
+
23
+ return translateWithDefault(`errors.${select.errors[0]}`, `Error: ${select.errors[0]}`);
24
+ });
25
+ </script>
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <Label v-if="show" :for="select.id" v-bind="$props">
3
+ <slot>
4
+ {{ select.label }}
5
+ </slot>
6
+ </Label>
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import { computed, useSlots } from 'vue';
11
+ import { Label } from 'reka-ui';
12
+ import type { LabelProps } from 'reka-ui';
13
+
14
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
15
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
16
+
17
+ defineProps<Omit<LabelProps, 'for'>>();
18
+
19
+ const select = injectReactiveOrFail<SelectExpose>(
20
+ 'select',
21
+ '<HeadlessSelectLabel> must be a child of a <HeadlessSelect>',
22
+ );
23
+ const slots = useSlots();
24
+ const show = computed(() => !!(select.label || slots.default));
25
+ </script>
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <SelectItem v-bind="$props">
3
+ <SelectItemText>
4
+ <slot>
5
+ {{ renderedLabel }}
6
+ </slot>
7
+ </SelectItemText>
8
+ </SelectItem>
9
+ </template>
10
+
11
+ <script setup lang="ts">
12
+ import { computed } from 'vue';
13
+ import { SelectItem, SelectItemText } from 'reka-ui';
14
+ import { toString } from '@noeldemartin/utils';
15
+ import type { SelectItemProps } from 'reka-ui';
16
+
17
+ import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
18
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
19
+
20
+ const { value } = defineProps<SelectItemProps>();
21
+ const select = injectReactiveOrFail<SelectExpose>(
22
+ 'select',
23
+ '<HeadlessSelectOption> must be a child of a <HeadlessSelect>',
24
+ );
25
+ const renderedLabel = computed(() => {
26
+ const itemOption = select.options?.find((option) => option.value === value);
27
+
28
+ if (itemOption) {
29
+ return itemOption.label;
30
+ }
31
+
32
+ return toString(value);
33
+ });
34
+ </script>
@@ -0,0 +1,37 @@
1
+ <template>
2
+ <SelectPortal>
3
+ <SelectContent
4
+ position="popper"
5
+ :class="$props.class"
6
+ :align="select.align"
7
+ :side="select.side"
8
+ >
9
+ <SelectViewport :class="innerClass">
10
+ <slot>
11
+ <HeadlessSelectOption
12
+ v-for="option in select.options ?? []"
13
+ :key="option.key"
14
+ :value="option.value"
15
+ />
16
+ </slot>
17
+ </SelectViewport>
18
+ </SelectContent>
19
+ </SelectPortal>
20
+ </template>
21
+
22
+ <script setup lang="ts">
23
+ import { SelectContent, SelectPortal, SelectViewport } from 'reka-ui';
24
+ import type { HTMLAttributes } from 'vue';
25
+
26
+ import { injectReactiveOrFail } from '@aerogel/core/utils';
27
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
28
+
29
+ import HeadlessSelectOption from './HeadlessSelectOption.vue';
30
+
31
+ defineProps<{ class?: HTMLAttributes['class']; innerClass?: HTMLAttributes['class'] }>();
32
+
33
+ const select = injectReactiveOrFail<SelectExpose>(
34
+ 'select',
35
+ '<HeadlessSelectOptions> must be a child of a <HeadlessSelect>',
36
+ );
37
+ </script>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <SelectTrigger :id="select.id">
3
+ <slot>
4
+ <HeadlessSelectValue :placeholder="select.placeholder" />
5
+ <SelectIcon />
6
+ </slot>
7
+ </SelectTrigger>
8
+ </template>
9
+
10
+ <script setup lang="ts">
11
+ import { SelectIcon, SelectTrigger } from 'reka-ui';
12
+
13
+ import { injectReactiveOrFail } from '@aerogel/core/utils';
14
+ import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
15
+
16
+ import HeadlessSelectValue from './HeadlessSelectValue.vue';
17
+
18
+ const select = injectReactiveOrFail<SelectExpose>(
19
+ 'select',
20
+ '<HeadlessSelectTrigger> must be a child of a <HeadlessSelect>',
21
+ );
22
+ </script>