@aerogel/core 0.0.0-next.f16bd1d894543c5303039c49f6f33488a1ffe931 → 0.0.0-next.f86b4b09f066c4aef21796a37dbc8417b7dce3cd

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 (118) hide show
  1. package/dist/aerogel-core.cjs.js +1 -1
  2. package/dist/aerogel-core.cjs.js.map +1 -1
  3. package/dist/aerogel-core.d.ts +1396 -235
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/histoire.config.ts +7 -0
  7. package/package.json +14 -5
  8. package/postcss.config.js +6 -0
  9. package/src/assets/histoire.css +3 -0
  10. package/src/bootstrap/bootstrap.test.ts +3 -3
  11. package/src/bootstrap/index.ts +35 -5
  12. package/src/bootstrap/options.ts +3 -0
  13. package/src/components/AGAppLayout.vue +7 -2
  14. package/src/components/AGAppOverlays.vue +5 -1
  15. package/src/components/AGAppSnackbars.vue +2 -2
  16. package/src/components/composition.ts +23 -0
  17. package/src/components/forms/AGCheckbox.vue +7 -1
  18. package/src/components/forms/AGForm.vue +9 -10
  19. package/src/components/forms/AGInput.vue +10 -6
  20. package/src/components/forms/AGSelect.story.vue +46 -0
  21. package/src/components/forms/AGSelect.vue +60 -0
  22. package/src/components/forms/index.ts +5 -6
  23. package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
  24. package/src/components/headless/forms/AGHeadlessButton.vue +24 -12
  25. package/src/components/headless/forms/AGHeadlessInput.ts +30 -4
  26. package/src/components/headless/forms/AGHeadlessInput.vue +23 -7
  27. package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
  28. package/src/components/headless/forms/AGHeadlessInputInput.vue +44 -5
  29. package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
  30. package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
  31. package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
  32. package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
  33. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  34. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  35. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  37. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  38. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  39. package/src/components/headless/forms/composition.ts +10 -0
  40. package/src/components/headless/forms/index.ts +13 -1
  41. package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
  42. package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
  43. package/src/components/headless/modals/index.ts +4 -6
  44. package/src/components/headless/snackbars/index.ts +23 -8
  45. package/src/components/index.ts +3 -1
  46. package/src/components/interfaces.ts +24 -0
  47. package/src/components/lib/AGErrorMessage.vue +16 -0
  48. package/src/components/lib/AGLink.vue +9 -0
  49. package/src/components/{basic → lib}/AGMarkdown.vue +12 -11
  50. package/src/components/lib/AGMeasured.vue +16 -0
  51. package/src/components/lib/AGStartupCrash.vue +31 -0
  52. package/src/components/lib/index.ts +5 -0
  53. package/src/components/modals/AGAlertModal.ts +15 -0
  54. package/src/components/modals/AGAlertModal.vue +4 -16
  55. package/src/components/modals/AGConfirmModal.ts +35 -0
  56. package/src/components/modals/AGConfirmModal.vue +9 -13
  57. package/src/components/modals/AGErrorReportModal.ts +27 -1
  58. package/src/components/modals/AGErrorReportModal.vue +8 -16
  59. package/src/components/modals/AGErrorReportModalButtons.vue +6 -1
  60. package/src/components/modals/AGErrorReportModalTitle.vue +2 -2
  61. package/src/components/modals/AGLoadingModal.ts +23 -0
  62. package/src/components/modals/AGLoadingModal.vue +4 -8
  63. package/src/components/modals/AGModal.ts +1 -1
  64. package/src/components/modals/AGModal.vue +15 -12
  65. package/src/components/modals/AGModalTitle.vue +9 -0
  66. package/src/components/modals/AGPromptModal.ts +36 -0
  67. package/src/components/modals/AGPromptModal.vue +34 -0
  68. package/src/components/modals/index.ts +13 -17
  69. package/src/components/snackbars/AGSnackbar.vue +4 -10
  70. package/src/components/utils.ts +10 -0
  71. package/src/directives/index.ts +5 -1
  72. package/src/directives/measure.ts +40 -0
  73. package/src/errors/Errors.ts +36 -12
  74. package/src/errors/index.ts +10 -23
  75. package/src/errors/utils.ts +35 -0
  76. package/src/forms/Form.test.ts +28 -0
  77. package/src/forms/Form.ts +80 -14
  78. package/src/forms/index.ts +3 -1
  79. package/src/forms/utils.ts +34 -3
  80. package/src/forms/validation.ts +19 -0
  81. package/src/jobs/Job.ts +5 -0
  82. package/src/jobs/index.ts +7 -0
  83. package/src/lang/DefaultLangProvider.ts +43 -0
  84. package/src/lang/Lang.state.ts +11 -0
  85. package/src/lang/Lang.ts +44 -29
  86. package/src/main.histoire.ts +1 -0
  87. package/src/main.ts +3 -0
  88. package/src/plugins/Plugin.ts +1 -0
  89. package/src/plugins/index.ts +19 -0
  90. package/src/services/App.state.ts +24 -6
  91. package/src/services/App.ts +43 -5
  92. package/src/services/Cache.ts +43 -0
  93. package/src/services/Events.test.ts +39 -0
  94. package/src/services/Events.ts +100 -30
  95. package/src/services/Service.ts +64 -17
  96. package/src/services/index.ts +11 -5
  97. package/src/services/store.ts +8 -5
  98. package/src/testing/index.ts +25 -0
  99. package/src/testing/setup.ts +19 -0
  100. package/src/ui/UI.state.ts +7 -0
  101. package/src/ui/UI.ts +194 -27
  102. package/src/ui/index.ts +9 -3
  103. package/src/ui/utils.ts +16 -0
  104. package/src/utils/composition/events.ts +1 -0
  105. package/src/utils/composition/state.test.ts +47 -0
  106. package/src/utils/composition/state.ts +24 -0
  107. package/src/utils/index.ts +1 -0
  108. package/src/utils/markdown.ts +11 -2
  109. package/src/utils/tailwindcss.test.ts +26 -0
  110. package/src/utils/tailwindcss.ts +7 -0
  111. package/src/utils/vue.ts +23 -5
  112. package/tailwind.config.js +4 -0
  113. package/tsconfig.json +1 -1
  114. package/vite.config.ts +4 -1
  115. package/.eslintrc.js +0 -3
  116. package/dist/virtual.d.ts +0 -11
  117. package/src/components/basic/index.ts +0 -3
  118. package/src/types/virtual.d.ts +0 -11
@@ -1,26 +1,14 @@
1
1
  <template>
2
- <AGModal>
3
- <AGMarkdown
4
- v-if="title"
5
- :text="title"
6
- as="h2"
7
- class="font-semibold"
8
- raw
9
- inline
10
- />
2
+ <AGModal :title="title">
11
3
  <AGMarkdown :text="message" />
12
4
  </AGModal>
13
5
  </template>
14
6
 
15
7
  <script setup lang="ts">
16
- import { requiredStringProp, stringProp } from '@/utils/vue';
17
-
18
8
  import AGModal from './AGModal.vue';
9
+ import { useAlertModalProps } from './AGAlertModal';
19
10
 
20
- import AGMarkdown from '../basic/AGMarkdown.vue';
11
+ import AGMarkdown from '../lib/AGMarkdown.vue';
21
12
 
22
- defineProps({
23
- title: stringProp(),
24
- message: requiredStringProp(),
25
- });
13
+ defineProps(useAlertModalProps());
26
14
  </script>
@@ -0,0 +1,35 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithout, SubPartial } from '@noeldemartin/utils';
4
+
5
+ import { Colors } from '@/components/constants';
6
+ import { enumProp, objectProp, requiredStringProp, stringProp } from '@/utils';
7
+ import { translateWithDefault } from '@/lang';
8
+ import type { ConfirmCheckboxes } from '@/ui';
9
+
10
+ export const confirmModalProps = {
11
+ title: stringProp(),
12
+ message: requiredStringProp(),
13
+ acceptText: stringProp(),
14
+ acceptColor: enumProp(Colors, Colors.Primary),
15
+ cancelText: stringProp(),
16
+ cancelColor: enumProp(Colors, Colors.Clear),
17
+ checkboxes: objectProp<ConfirmCheckboxes>(),
18
+ };
19
+
20
+ export type AGConfirmModalProps = SubPartial<
21
+ ObjectWithout<ExtractPropTypes<typeof confirmModalProps>, null | undefined>,
22
+ 'acceptColor' | 'cancelColor'
23
+ >;
24
+
25
+ export function useConfirmModalProps(): typeof confirmModalProps {
26
+ return confirmModalProps;
27
+ }
28
+
29
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
30
+ export function useConfirmModal(props: ExtractPropTypes<typeof confirmModalProps>) {
31
+ const renderedAcceptText = computed(() => props.acceptText ?? translateWithDefault('ui.accept', 'Ok'));
32
+ const renderedCancelText = computed(() => props.cancelText ?? translateWithDefault('ui.cancel', 'Cancel'));
33
+
34
+ return { renderedAcceptText, renderedCancelText };
35
+ }
@@ -1,30 +1,26 @@
1
1
  <template>
2
- <AGModal v-slot="{ close }: IAGModalDefaultSlotProps" :cancellable="false">
3
- <AGMarkdown v-if="title" :text="title" as="h1" />
2
+ <AGModal v-slot="{ close }: IAGModalDefaultSlotProps" :cancellable="false" :title="title">
4
3
  <AGMarkdown :text="message" />
5
4
 
6
5
  <div class="mt-2 flex flex-row-reverse gap-2">
7
- <AGButton @click="close(true)">
8
- {{ $td('ui.ok', 'OK') }}
6
+ <AGButton :color="acceptColor" @click="close(true)">
7
+ {{ renderedAcceptText }}
9
8
  </AGButton>
10
- <AGButton color="secondary" @click="close()">
11
- {{ $td('ui.cancel', 'Cancel') }}
9
+ <AGButton :color="cancelColor" @click="close()">
10
+ {{ renderedCancelText }}
12
11
  </AGButton>
13
12
  </div>
14
13
  </AGModal>
15
14
  </template>
16
15
 
17
16
  <script setup lang="ts">
18
- import { requiredStringProp, stringProp } from '@/utils/vue';
19
-
20
17
  import AGModal from './AGModal.vue';
18
+ import { useConfirmModal, useConfirmModalProps } from './AGConfirmModal';
21
19
  import type { IAGModalDefaultSlotProps } from './AGModal';
22
20
 
23
21
  import AGButton from '../forms/AGButton.vue';
24
- import AGMarkdown from '../basic/AGMarkdown.vue';
22
+ import AGMarkdown from '../lib/AGMarkdown.vue';
25
23
 
26
- defineProps({
27
- title: stringProp(),
28
- message: requiredStringProp(),
29
- });
24
+ const props = defineProps(useConfirmModalProps());
25
+ const { renderedAcceptText, renderedCancelText } = useConfirmModal(props);
30
26
  </script>
@@ -1,6 +1,9 @@
1
- import type { Component } from 'vue';
1
+ import { computed, ref } from 'vue';
2
+ import type { Component, ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
2
4
 
3
5
  import { requiredArrayProp } from '@/utils/vue';
6
+ import { translateWithDefault } from '@/lang';
4
7
  import type { ErrorReport } from '@/errors';
5
8
 
6
9
  export interface IAGErrorReportModalButtonsDefaultSlotProps {
@@ -15,6 +18,29 @@ export const errorReportModalProps = {
15
18
  reports: requiredArrayProp<ErrorReport>(),
16
19
  };
17
20
 
21
+ export type AGErrorReportModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof errorReportModalProps>>;
22
+
18
23
  export function useErrorReportModalProps(): typeof errorReportModalProps {
19
24
  return errorReportModalProps;
20
25
  }
26
+
27
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
28
+ export function useErrorReportModal(props: ExtractPropTypes<typeof errorReportModalProps>) {
29
+ const activeReportIndex = ref(0);
30
+ const report = computed(() => props.reports[activeReportIndex.value] as ErrorReport);
31
+ const details = computed(
32
+ () =>
33
+ report.value.details?.trim() ||
34
+ translateWithDefault('errors.detailsEmpty', 'This error is missing a stacktrace.'),
35
+ );
36
+ const previousReportText = translateWithDefault('errors.previousReport', 'Show previous report');
37
+ const nextReportText = translateWithDefault('errors.nextReport', 'Show next report');
38
+
39
+ return {
40
+ activeReportIndex,
41
+ details,
42
+ nextReportText,
43
+ previousReportText,
44
+ report,
45
+ };
46
+ }
@@ -12,8 +12,8 @@
12
12
  <AGButton
13
13
  color="clear"
14
14
  :disabled="activeReportIndex === 0"
15
- :title="$td('errors.previousReport', 'Show previous report')"
16
- :aria-label="$td('errors.previousReport', 'Show previous report')"
15
+ :title="previousReportText"
16
+ :aria-label="previousReportText"
17
17
  @click="activeReportIndex--"
18
18
  >
19
19
  <IconCheveronLeft aria-hidden="true" class="h-4 w-4" />
@@ -21,8 +21,8 @@
21
21
  <AGButton
22
22
  color="clear"
23
23
  :disabled="activeReportIndex === reports.length - 1"
24
- :title="$td('errors.nextReport', 'Show next report')"
25
- :aria-label="$td('errors.nextReport', 'Show next report')"
24
+ :title="nextReportText"
25
+ :aria-label="nextReportText"
26
26
  @click="activeReportIndex++"
27
27
  >
28
28
  <IconCheveronRight aria-hidden="true" class="h-4 w-4" />
@@ -33,10 +33,7 @@
33
33
  </h2>
34
34
  <AGMarkdown v-if="report.description" :text="report.description" class="mt-2" />
35
35
  </div>
36
- <pre
37
- class="h-full overflow-auto bg-gray-200 p-4 text-xs text-red-900"
38
- v-text="report.details ?? $td('errors.detailsEmpty', 'This error is missing a stacktrace.')"
39
- />
36
+ <pre class="h-full overflow-auto bg-gray-200 p-4 text-xs text-red-900" v-text="details" />
40
37
  </AGModal>
41
38
  </template>
42
39
 
@@ -44,19 +41,14 @@
44
41
  import IconCheveronRight from '~icons/zondicons/cheveron-right';
45
42
  import IconCheveronLeft from '~icons/zondicons/cheveron-left';
46
43
 
47
- import { computed, ref } from 'vue';
48
-
49
- import type { ErrorReport } from '@/errors';
50
-
51
- import { useErrorReportModalProps } from './AGErrorReportModal';
44
+ import { useErrorReportModal, useErrorReportModalProps } from './AGErrorReportModal';
52
45
 
53
46
  import AGButton from '../forms/AGButton.vue';
54
47
  import AGErrorReportModalButtons from './AGErrorReportModalButtons.vue';
55
48
  import AGErrorReportModalTitle from './AGErrorReportModalTitle.vue';
56
- import AGMarkdown from '../basic/AGMarkdown.vue';
49
+ import AGMarkdown from '../lib/AGMarkdown.vue';
57
50
  import AGModal from './AGModal.vue';
58
51
 
59
52
  const props = defineProps(useErrorReportModalProps());
60
- const activeReportIndex = ref(0);
61
- const report = computed(() => props.reports[activeReportIndex.value] as ErrorReport);
53
+ const { activeReportIndex, details, nextReportText, previousReportText, report } = useErrorReportModal(props);
62
54
  </script>
@@ -79,7 +79,12 @@ const buttons = computed(() =>
79
79
  description: 'Log to console',
80
80
  iconComponent: IconConsole,
81
81
  handler() {
82
- (window as { error?: unknown }).error = props.report.error;
82
+ const error = props.report.error ?? props.report;
83
+
84
+ (window as { error?: unknown }).error = error;
85
+
86
+ // eslint-disable-next-line no-console
87
+ console.error(error);
83
88
 
84
89
  UI.showSnackbar(
85
90
  translateWithDefault(
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <AGMarkdown :text="text" heading />
2
+ <AGMarkdown :text="text" inline />
3
3
  </template>
4
4
 
5
5
  <script setup lang="ts">
@@ -8,7 +8,7 @@ import { computed } from 'vue';
8
8
  import { numberProp, requiredObjectProp } from '@/utils/vue';
9
9
  import type { ErrorReport } from '@/errors';
10
10
 
11
- import AGMarkdown from '../basic/AGMarkdown.vue';
11
+ import AGMarkdown from '../lib/AGMarkdown.vue';
12
12
 
13
13
  const props = defineProps({
14
14
  report: requiredObjectProp<ErrorReport>(),
@@ -0,0 +1,23 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
4
+
5
+ import { stringProp } from '@/utils';
6
+ import { translateWithDefault } from '@/lang';
7
+
8
+ export const loadingModalProps = {
9
+ message: stringProp(),
10
+ };
11
+
12
+ export type AGLoadingModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof loadingModalProps>>;
13
+
14
+ export function useLoadingModalProps(): typeof loadingModalProps {
15
+ return loadingModalProps;
16
+ }
17
+
18
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
19
+ export function useLoadingModal(props: ExtractPropTypes<typeof loadingModalProps>) {
20
+ const renderedMessage = computed(() => props.message ?? translateWithDefault('ui.loading', 'Loading...'));
21
+
22
+ return { renderedMessage };
23
+ }
@@ -5,15 +5,11 @@
5
5
  </template>
6
6
 
7
7
  <script setup lang="ts">
8
- import { computed } from 'vue';
9
-
10
- import { stringProp } from '@/utils/vue';
11
- import { translateWithDefault } from '@/lang/utils';
12
-
13
8
  import AGModal from './AGModal.vue';
9
+ import { useLoadingModal, useLoadingModalProps } from './AGLoadingModal';
14
10
 
15
- import AGMarkdown from '../basic/AGMarkdown.vue';
11
+ import AGMarkdown from '../lib/AGMarkdown.vue';
16
12
 
17
- const props = defineProps({ message: stringProp() });
18
- const renderedMessage = computed(() => props.message ?? translateWithDefault('ui.loading', 'Loading...'));
13
+ const props = defineProps(useLoadingModalProps());
14
+ const { renderedMessage } = useLoadingModal(props);
19
15
  </script>
@@ -2,7 +2,7 @@ import type { Ref } from 'vue';
2
2
 
3
3
  export interface IAGModal {
4
4
  cancellable: Ref<boolean>;
5
- close(): Promise<void>;
5
+ close(result?: unknown): Promise<void>;
6
6
  }
7
7
 
8
8
  export interface IAGModalDefaultSlotProps {
@@ -1,13 +1,16 @@
1
1
  <template>
2
2
  <AGHeadlessModal
3
- ref="$headlessModal"
3
+ ref="$modal"
4
4
  v-slot="{ close }: IAGHeadlessModalDefaultSlotProps"
5
- :cancellable="cancellable"
5
+ v-bind="props"
6
6
  class="relative z-50"
7
7
  >
8
8
  <div class="fixed inset-0 flex items-center justify-center p-8">
9
- <AGHeadlessModalPanel class="flex max-h-full max-w-full flex-col overflow-hidden bg-white">
10
- <div class="flex max-h-full flex-col overflow-auto p-4">
9
+ <AGHeadlessModalPanel class="flex max-h-full max-w-full flex-col overflow-hidden bg-white p-4">
10
+ <AGHeadlessModalTitle v-if="title" class="mb-2 text-lg font-semibold">
11
+ <AGMarkdown :text="title" inline />
12
+ </AGHeadlessModalTitle>
13
+ <div class="flex max-h-full flex-col overflow-auto" v-bind="$attrs">
11
14
  <slot :close="close" />
12
15
  </div>
13
16
  </AGHeadlessModalPanel>
@@ -16,21 +19,21 @@
16
19
  </template>
17
20
 
18
21
  <script setup lang="ts">
19
- import { computed, ref } from 'vue';
22
+ import { ref } from 'vue';
20
23
 
21
- import { booleanProp } from '@/utils';
24
+ import { useModalExpose, useModalProps } from '@/components/headless/modals/AGHeadlessModal';
22
25
  import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from '@/components/headless/modals/AGHeadlessModal';
23
26
 
24
27
  import type { IAGModal } from './AGModal';
25
28
 
26
29
  import AGHeadlessModal from '../headless/modals/AGHeadlessModal.vue';
27
30
  import AGHeadlessModalPanel from '../headless/modals/AGHeadlessModalPanel.vue';
31
+ import AGHeadlessModalTitle from '../headless/modals/AGHeadlessModalTitle.vue';
32
+ import AGMarkdown from '../lib/AGMarkdown.vue';
28
33
 
29
- const $headlessModal = ref<IAGHeadlessModal>();
34
+ const props = defineProps(useModalProps());
35
+ const $modal = ref<IAGHeadlessModal>();
30
36
 
31
- defineProps({ cancellable: booleanProp(true) });
32
- defineExpose<IAGModal>({
33
- close: async () => $headlessModal.value?.close(),
34
- cancellable: computed(() => !!$headlessModal.value?.cancellable),
35
- });
37
+ defineOptions({ inheritAttrs: false });
38
+ defineExpose<IAGModal>(useModalExpose($modal));
36
39
  </script>
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <AGHeadlessModalTitle class="mb-2 font-semibold">
3
+ <slot />
4
+ </AGHeadlessModalTitle>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import AGHeadlessModalTitle from '../headless/modals/AGHeadlessModalTitle.vue';
9
+ </script>
@@ -0,0 +1,36 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithoutEmpty, SubPartial } from '@noeldemartin/utils';
4
+
5
+ import { Colors } from '@/components/constants';
6
+ import { enumProp, requiredStringProp, stringProp } from '@/utils';
7
+ import { translateWithDefault } from '@/lang';
8
+
9
+ export const promptModalProps = {
10
+ title: stringProp(),
11
+ message: requiredStringProp(),
12
+ label: stringProp(),
13
+ defaultValue: stringProp(),
14
+ placeholder: stringProp(),
15
+ acceptText: stringProp(),
16
+ acceptColor: enumProp(Colors, Colors.Primary),
17
+ cancelText: stringProp(),
18
+ cancelColor: enumProp(Colors, Colors.Clear),
19
+ };
20
+
21
+ export type AGPromptModalProps = SubPartial<
22
+ ObjectWithoutEmpty<ExtractPropTypes<typeof promptModalProps>>,
23
+ 'acceptColor' | 'cancelColor'
24
+ >;
25
+
26
+ export function usePromptModalProps(): typeof promptModalProps {
27
+ return promptModalProps;
28
+ }
29
+
30
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
31
+ export function usePromptModal(props: ExtractPropTypes<typeof promptModalProps>) {
32
+ const renderedAcceptText = computed(() => props.acceptText ?? translateWithDefault('ui.accept', 'Ok'));
33
+ const renderedCancelText = computed(() => props.cancelText ?? translateWithDefault('ui.cancel', 'Cancel'));
34
+
35
+ return { renderedAcceptText, renderedCancelText };
36
+ }
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <AGModal v-slot="{ close }: IAGModalDefaultSlotProps" :cancellable="false" :title="title">
3
+ <AGMarkdown :text="message" />
4
+
5
+ <AGForm :form="form" @submit="close(form.draft)">
6
+ <AGInput name="draft" :placeholder="placeholder" :label="label" />
7
+
8
+ <div class="mt-2 flex flex-row-reverse gap-2">
9
+ <AGButton :color="acceptColor" submit>
10
+ {{ renderedAcceptText }}
11
+ </AGButton>
12
+ <AGButton :color="cancelColor" @click="close()">
13
+ {{ renderedCancelText }}
14
+ </AGButton>
15
+ </div>
16
+ </AGForm>
17
+ </AGModal>
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import AGModal from './AGModal.vue';
22
+ import { usePromptModal, usePromptModalProps } from './AGPromptModal';
23
+ import type { IAGModalDefaultSlotProps } from './AGModal';
24
+
25
+ import AGButton from '../forms/AGButton.vue';
26
+ import AGForm from '../forms/AGForm.vue';
27
+ import AGInput from '../forms/AGInput.vue';
28
+ import AGMarkdown from '../lib/AGMarkdown.vue';
29
+ import { requiredStringInput, useForm } from '../../forms';
30
+
31
+ const props = defineProps(usePromptModalProps());
32
+ const form = useForm({ draft: requiredStringInput(props.defaultValue ?? '') });
33
+ const { renderedAcceptText, renderedCancelText } = usePromptModal(props);
34
+ </script>
@@ -1,21 +1,17 @@
1
- import AGAlertModal from './AGAlertModal.vue';
2
- import AGConfirmModal from './AGConfirmModal.vue';
3
- import AGErrorReportModalButtons from './AGErrorReportModalButtons.vue';
4
- import AGErrorReportModalTitle from './AGErrorReportModalTitle.vue';
5
- import AGLoadingModal from './AGLoadingModal.vue';
6
- import AGModal from './AGModal.vue';
7
- import AGModalContext from './AGModalContext.vue';
8
-
1
+ export * from './AGAlertModal';
2
+ export * from './AGConfirmModal';
9
3
  export * from './AGErrorReportModal';
4
+ export * from './AGLoadingModal';
10
5
  export * from './AGModal';
11
6
  export * from './AGModalContext';
7
+ export * from './AGPromptModal';
12
8
 
13
- export {
14
- AGAlertModal,
15
- AGConfirmModal,
16
- AGErrorReportModalButtons,
17
- AGErrorReportModalTitle,
18
- AGLoadingModal,
19
- AGModal,
20
- AGModalContext,
21
- };
9
+ export { default as AGAlertModal } from './AGAlertModal.vue';
10
+ export { default as AGConfirmModal } from './AGConfirmModal.vue';
11
+ export { default as AGErrorReportModalButtons } from './AGErrorReportModalButtons.vue';
12
+ export { default as AGErrorReportModalTitle } from './AGErrorReportModalTitle.vue';
13
+ export { default as AGLoadingModal } from './AGLoadingModal.vue';
14
+ export { default as AGModal } from './AGModal.vue';
15
+ export { default as AGModalContext } from './AGModalContext.vue';
16
+ export { default as AGModalTitle } from './AGModalTitle.vue';
17
+ export { default as AGPromptModal } from './AGPromptModal.vue';
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <AGHeadlessSnackbar class="flex flex-row items-center justify-center gap-3 p-4" :class="styleClasses">
3
- <AGMarkdown :text="message" raw />
3
+ <AGMarkdown :text="message" inline />
4
4
  <AGButton
5
5
  v-for="(action, i) of actions"
6
6
  :key="i"
@@ -15,16 +15,15 @@
15
15
  <script setup lang="ts">
16
16
  import { computed } from 'vue';
17
17
 
18
- import UI from '@/ui/UI';
19
18
  import { Colors } from '@/components/constants';
20
- import { useSnackbarProps } from '@/components/headless';
21
- import type { SnackbarAction } from '@/components/headless';
19
+ import { useSnackbar, useSnackbarProps } from '@/components/headless/snackbars';
22
20
 
23
21
  import AGButton from '../forms/AGButton.vue';
24
22
  import AGHeadlessSnackbar from '../headless/snackbars/AGHeadlessSnackbar.vue';
25
- import AGMarkdown from '../basic/AGMarkdown.vue';
23
+ import AGMarkdown from '../lib/AGMarkdown.vue';
26
24
 
27
25
  const props = defineProps(useSnackbarProps());
26
+ const { activate } = useSnackbar(props);
28
27
  const styleClasses = computed(() => {
29
28
  switch (props.color) {
30
29
  case Colors.Danger:
@@ -34,9 +33,4 @@ const styleClasses = computed(() => {
34
33
  return 'bg-gray-900 text-white';
35
34
  }
36
35
  });
37
-
38
- function activate(action: SnackbarAction): void {
39
- action.handler?.();
40
- action.dismiss && UI.hideSnackbar(props.id);
41
- }
42
36
  </script>
@@ -0,0 +1,10 @@
1
+ export function extractComponentProps<T extends Record<string, unknown>>(
2
+ values: Record<string, unknown>,
3
+ definitions: Record<string, unknown>,
4
+ ): T {
5
+ return Object.keys(definitions).reduce((extracted, prop) => {
6
+ extracted[prop] = values[prop];
7
+
8
+ return extracted;
9
+ }, {} as Record<string, unknown>) as T;
10
+ }
@@ -3,11 +3,15 @@ import type { Directive } from 'vue';
3
3
  import { definePlugin } from '@/plugins';
4
4
 
5
5
  import initialFocus from './initial-focus';
6
+ import measure from './measure';
6
7
 
7
8
  const builtInDirectives: Record<string, Directive> = {
8
9
  'initial-focus': initialFocus,
10
+ 'measure': measure,
9
11
  };
10
12
 
13
+ export * from './measure';
14
+
11
15
  export default definePlugin({
12
16
  install(app, options) {
13
17
  const directives = {
@@ -22,7 +26,7 @@ export default definePlugin({
22
26
  });
23
27
 
24
28
  declare module '@/bootstrap/options' {
25
- interface AerogelOptions {
29
+ export interface AerogelOptions {
26
30
  directives?: Record<string, Directive>;
27
31
  }
28
32
  }
@@ -0,0 +1,40 @@
1
+ import { defineDirective } from '@/utils/vue';
2
+ import { tap } from '@noeldemartin/utils';
3
+
4
+ const resizeObservers: WeakMap<HTMLElement, ResizeObserver> = new WeakMap();
5
+
6
+ export interface ElementSize {
7
+ width: number;
8
+ height: number;
9
+ }
10
+
11
+ export type MeasureDirectiveListener = (size: ElementSize) => unknown;
12
+
13
+ export default defineDirective({
14
+ mounted(element: HTMLElement, { value }) {
15
+ // TODO replace with argument when typed properly
16
+ const modifiers = { css: true, watch: true };
17
+
18
+ const listener = typeof value === 'function' ? (value as MeasureDirectiveListener) : null;
19
+ const update = () => {
20
+ const sizes = element.getBoundingClientRect();
21
+
22
+ if (modifiers.css) {
23
+ element.style.setProperty('--width', `${sizes.width}px`);
24
+ element.style.setProperty('--height', `${sizes.height}px`);
25
+ }
26
+
27
+ listener?.({ width: sizes.width, height: sizes.height });
28
+ };
29
+
30
+ if (modifiers.watch) {
31
+ resizeObservers.set(element, tap(new ResizeObserver(update)).observe(element));
32
+ }
33
+
34
+ update();
35
+ },
36
+ unmounted(element) {
37
+ resizeObservers.get(element)?.unobserve(element);
38
+ resizeObservers.delete(element);
39
+ },
40
+ });