@aerogel/core 0.0.0-next.b58141fee5d2fe7d25debdbca6b1d2bf1c13e48e → 0.0.0-next.bb9dcdbb118a15d146d3a1c4cf861ca2f4f1eebd

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 (130) 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 +1637 -295
  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 +23 -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 +29 -0
  42. package/src/components/headless/modals/AGHeadlessModal.vue +13 -9
  43. package/src/components/headless/modals/AGHeadlessModalPanel.vue +10 -6
  44. package/src/components/headless/modals/AGHeadlessModalTitle.vue +14 -4
  45. package/src/components/headless/modals/index.ts +4 -6
  46. package/src/components/headless/snackbars/index.ts +23 -8
  47. package/src/components/index.ts +3 -1
  48. package/src/components/interfaces.ts +24 -0
  49. package/src/components/{basic → lib}/AGErrorMessage.vue +2 -2
  50. package/src/components/lib/AGMarkdown.vue +54 -0
  51. package/src/components/lib/AGMeasured.vue +16 -0
  52. package/src/components/lib/AGProgressBar.vue +30 -0
  53. package/src/components/lib/AGStartupCrash.vue +31 -0
  54. package/src/components/lib/index.ts +6 -0
  55. package/src/components/modals/AGAlertModal.ts +18 -0
  56. package/src/components/modals/AGAlertModal.vue +4 -15
  57. package/src/components/modals/AGConfirmModal.ts +41 -0
  58. package/src/components/modals/AGConfirmModal.vue +10 -14
  59. package/src/components/modals/AGErrorReportModal.ts +30 -1
  60. package/src/components/modals/AGErrorReportModal.vue +8 -16
  61. package/src/components/modals/AGErrorReportModalButtons.vue +4 -2
  62. package/src/components/modals/AGErrorReportModalTitle.vue +1 -1
  63. package/src/components/modals/AGLoadingModal.ts +29 -0
  64. package/src/components/modals/AGLoadingModal.vue +4 -8
  65. package/src/components/modals/AGModal.ts +2 -1
  66. package/src/components/modals/AGModal.vue +14 -12
  67. package/src/components/modals/AGModalContext.vue +14 -4
  68. package/src/components/modals/AGPromptModal.ts +41 -0
  69. package/src/components/modals/AGPromptModal.vue +34 -0
  70. package/src/components/modals/index.ts +13 -19
  71. package/src/components/snackbars/AGSnackbar.vue +3 -9
  72. package/src/components/utils.ts +10 -0
  73. package/src/directives/index.ts +5 -1
  74. package/src/directives/measure.ts +40 -0
  75. package/src/errors/Errors.ts +26 -24
  76. package/src/errors/JobCancelledError.ts +3 -0
  77. package/src/errors/index.ts +10 -23
  78. package/src/errors/utils.ts +35 -0
  79. package/src/forms/Form.test.ts +28 -0
  80. package/src/forms/Form.ts +77 -11
  81. package/src/forms/index.ts +3 -1
  82. package/src/forms/utils.ts +34 -3
  83. package/src/forms/validation.ts +19 -0
  84. package/src/jobs/Job.ts +147 -0
  85. package/src/jobs/index.ts +10 -0
  86. package/src/jobs/listeners.ts +3 -0
  87. package/src/jobs/status.ts +4 -0
  88. package/src/lang/DefaultLangProvider.ts +43 -0
  89. package/src/lang/Lang.state.ts +11 -0
  90. package/src/lang/Lang.ts +44 -29
  91. package/src/main.histoire.ts +1 -0
  92. package/src/main.ts +3 -0
  93. package/src/plugins/Plugin.ts +1 -0
  94. package/src/plugins/index.ts +19 -0
  95. package/src/services/App.state.ts +23 -5
  96. package/src/services/App.ts +43 -3
  97. package/src/services/Cache.ts +43 -0
  98. package/src/services/Events.test.ts +39 -0
  99. package/src/services/Events.ts +111 -31
  100. package/src/services/Service.ts +145 -40
  101. package/src/services/Storage.ts +20 -0
  102. package/src/services/index.ts +11 -3
  103. package/src/services/store.ts +8 -5
  104. package/src/services/utils.ts +18 -0
  105. package/src/testing/index.ts +25 -0
  106. package/src/testing/setup.ts +27 -0
  107. package/src/ui/UI.state.ts +7 -0
  108. package/src/ui/UI.ts +237 -34
  109. package/src/ui/index.ts +9 -3
  110. package/src/ui/utils.ts +16 -0
  111. package/src/utils/composition/events.ts +1 -0
  112. package/src/utils/composition/persistent.test.ts +33 -0
  113. package/src/utils/composition/persistent.ts +11 -0
  114. package/src/utils/composition/state.test.ts +47 -0
  115. package/src/utils/composition/state.ts +24 -0
  116. package/src/utils/index.ts +2 -0
  117. package/src/utils/markdown.test.ts +50 -0
  118. package/src/utils/markdown.ts +17 -2
  119. package/src/utils/tailwindcss.test.ts +26 -0
  120. package/src/utils/tailwindcss.ts +7 -0
  121. package/src/utils/vue.ts +27 -6
  122. package/tailwind.config.js +4 -0
  123. package/tsconfig.json +1 -1
  124. package/vite.config.ts +4 -1
  125. package/.eslintrc.js +0 -3
  126. package/dist/virtual.d.ts +0 -11
  127. package/src/components/basic/AGMarkdown.vue +0 -36
  128. package/src/components/basic/index.ts +0 -5
  129. package/src/types/virtual.d.ts +0 -11
  130. /package/src/components/{basic → lib}/AGLink.vue +0 -0
@@ -3,9 +3,11 @@ import AGAppOverlays from './AGAppOverlays.vue';
3
3
 
4
4
  export { AGAppLayout, AGAppOverlays };
5
5
 
6
- export * from './basic';
6
+ export * from './composition';
7
7
  export * from './constants';
8
8
  export * from './forms';
9
9
  export * from './headless';
10
+ export * from './interfaces';
11
+ export * from './lib';
10
12
  export * from './modals';
11
13
  export * from './snackbars';
@@ -0,0 +1,24 @@
1
+ import { isObject } from '@noeldemartin/utils';
2
+ import type { Ref, UnwrapNestedRefs } from 'vue';
3
+
4
+ export function getElement(value: unknown): HTMLElement | undefined {
5
+ if (value instanceof HTMLElement) {
6
+ return value;
7
+ }
8
+
9
+ if (hasElement(value)) {
10
+ return value.$el;
11
+ }
12
+ }
13
+
14
+ export function hasElement(value: unknown): value is UnwrapNestedRefs<HasElement> {
15
+ return isObject(value) && '$el' in value;
16
+ }
17
+
18
+ export interface __SetsElement {
19
+ __setElement(element?: HTMLElement): void;
20
+ }
21
+
22
+ export interface HasElement {
23
+ $el: Readonly<Ref<HTMLElement | undefined>>;
24
+ }
@@ -5,12 +5,12 @@
5
5
  <script setup lang="ts">
6
6
  import { computed } from 'vue';
7
7
 
8
- import Errors from '@/errors/Errors';
9
8
  import { requiredObjectProp } from '@/utils/vue';
9
+ import { getErrorMessage } from '@/errors/utils';
10
10
  import type { ErrorSource } from '@/errors/Errors.state';
11
11
 
12
12
  import AGMarkdown from './AGMarkdown.vue';
13
13
 
14
14
  const props = defineProps({ error: requiredObjectProp<ErrorSource>() });
15
- const message = computed(() => Errors.getErrorMessage(props.error));
15
+ const message = computed(() => getErrorMessage(props.error));
16
16
  </script>
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <root />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { computed, h, useAttrs } from 'vue';
7
+ import { isInstanceOf } from '@noeldemartin/utils';
8
+
9
+ import { renderMarkdown } from '@/utils/markdown';
10
+ import { booleanProp, mixedProp, objectProp, stringProp } from '@/utils/vue';
11
+ import { translate } from '@/lang';
12
+
13
+ const props = defineProps({
14
+ as: stringProp(),
15
+ inline: booleanProp(),
16
+ langKey: stringProp(),
17
+ langParams: mixedProp<number | Record<string, unknown>>(),
18
+ text: stringProp(),
19
+ actions: objectProp<Record<string, () => unknown>>(),
20
+ });
21
+
22
+ const attrs = useAttrs();
23
+ const markdown = computed(() => props.text ?? (props.langKey && translate(props.langKey, props.langParams ?? {})));
24
+ const html = computed(() => {
25
+ if (!markdown.value) {
26
+ return null;
27
+ }
28
+
29
+ let renderedHtml = renderMarkdown(markdown.value);
30
+
31
+ if (props.inline) {
32
+ renderedHtml = renderedHtml.replace('<p>', '<span>').replace('</p>', '</span>');
33
+ }
34
+
35
+ return renderedHtml;
36
+ });
37
+ const root = () =>
38
+ h(props.as ?? (props.inline ? 'span' : 'div'), {
39
+ innerHTML: html.value,
40
+ onClick,
41
+ ...attrs,
42
+ class: `${attrs.class ?? ''} ${props.inline ? '' : 'prose'}`,
43
+ });
44
+
45
+ async function onClick(event: Event) {
46
+ const { target } = event;
47
+
48
+ if (isInstanceOf(target, HTMLElement) && target.dataset.markdownAction) {
49
+ props.actions?.[target.dataset.markdownAction]?.();
50
+
51
+ return;
52
+ }
53
+ }
54
+ </script>
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <component :is="as" v-measure="() => (measured = true)" :class="{ '!invisible !absolute !w-auto': !measured }">
3
+ <slot />
4
+ </component>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { ref } from 'vue';
9
+
10
+ import { stringProp } from '@/utils/vue';
11
+
12
+ defineProps({ as: stringProp('span') });
13
+
14
+ // TODO use v-measure.css
15
+ const measured = ref(false);
16
+ </script>
@@ -0,0 +1,30 @@
1
+ <template>
2
+ <div class="mt-1 h-2 w-full min-w-[min(400px,80vw)] overflow-hidden rounded-full bg-gray-200">
3
+ <div :class="barClasses" :style="`transform:translateX(-${(1 - progress) * 100}%)`" />
4
+ <span class="sr-only">
5
+ {{
6
+ $td('ui.progress', '{progress}% complete', {
7
+ progress: progress * 100,
8
+ })
9
+ }}
10
+ </span>
11
+ </div>
12
+ </template>
13
+
14
+ <script setup lang="ts">
15
+ import { computed } from 'vue';
16
+
17
+ import { requiredNumberProp, stringProp } from '@/utils/vue';
18
+
19
+ const props = defineProps({
20
+ progress: requiredNumberProp(),
21
+ class: stringProp(''),
22
+ });
23
+ const barClasses = computed(() => {
24
+ const classes = props.class ?? '';
25
+
26
+ return `h-full w-full transition-transform duration-500 ease-linear ${
27
+ classes.includes('bg-') ? classes : `${classes} bg-gray-700`
28
+ }`;
29
+ });
30
+ </script>
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <div class="grid flex-grow place-items-center">
3
+ <div class="flex flex-col items-center space-y-6 p-8">
4
+ <h1 class="mt-2 text-center text-4xl font-medium text-red-600">
5
+ {{ $td('startupCrash.title', 'Something went wrong!') }}
6
+ </h1>
7
+ <AGMarkdown
8
+ :text="
9
+ $td(
10
+ 'startupCrash.message',
11
+ 'Something failed trying to start the application.\n\nHere\'s some things you can do:'
12
+ )
13
+ "
14
+ class="mt-4 text-center"
15
+ />
16
+ <div class="mt-4 flex flex-col space-y-4">
17
+ <AGButton color="danger" @click="$app.reload()">
18
+ {{ $td('startupCrash.reload', 'Try again') }}
19
+ </AGButton>
20
+ <AGButton color="danger" @click="$errors.inspect($errors.startupErrors)">
21
+ {{ $td('startupCrash.inspect', 'View error details') }}
22
+ </AGButton>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ </template>
27
+
28
+ <script setup lang="ts">
29
+ import AGMarkdown from './AGMarkdown.vue';
30
+ import AGButton from '../forms/AGButton.vue';
31
+ </script>
@@ -0,0 +1,6 @@
1
+ export { default as AGErrorMessage } from './AGErrorMessage.vue';
2
+ export { default as AGLink } from './AGLink.vue';
3
+ export { default as AGMarkdown } from './AGMarkdown.vue';
4
+ export { default as AGMeasured } from './AGMeasured.vue';
5
+ export { default as AGProgressBar } from './AGProgressBar.vue';
6
+ export { default as AGStartupCrash } from './AGStartupCrash.vue';
@@ -0,0 +1,18 @@
1
+ import type { ExtractPropTypes } from 'vue';
2
+ import type { ObjectWithout, Pretty } from '@noeldemartin/utils';
3
+
4
+ import { requiredStringProp, stringProp } from '@/utils';
5
+ import type { AcceptRefs } from '@/utils';
6
+
7
+ export const alertModalProps = {
8
+ title: stringProp(),
9
+ message: requiredStringProp(),
10
+ };
11
+
12
+ export type AGAlertModalProps = Pretty<
13
+ AcceptRefs<ObjectWithout<ExtractPropTypes<typeof alertModalProps>, null | undefined>>
14
+ >;
15
+
16
+ export function useAlertModalProps(): typeof alertModalProps {
17
+ return alertModalProps;
18
+ }
@@ -1,25 +1,14 @@
1
1
  <template>
2
- <AGModal>
3
- <AGMarkdown
4
- v-if="title"
5
- :text="title"
6
- as="h2"
7
- class="font-semibold"
8
- inline
9
- />
2
+ <AGModal :title="title">
10
3
  <AGMarkdown :text="message" />
11
4
  </AGModal>
12
5
  </template>
13
6
 
14
7
  <script setup lang="ts">
15
- import { requiredStringProp, stringProp } from '@/utils/vue';
16
-
17
8
  import AGModal from './AGModal.vue';
9
+ import { useAlertModalProps } from './AGAlertModal';
18
10
 
19
- import AGMarkdown from '../basic/AGMarkdown.vue';
11
+ import AGMarkdown from '../lib/AGMarkdown.vue';
20
12
 
21
- defineProps({
22
- title: stringProp(),
23
- message: requiredStringProp(),
24
- });
13
+ defineProps(useAlertModalProps());
25
14
  </script>
@@ -0,0 +1,41 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithout, Pretty, 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 { AcceptRefs } from '@/utils';
9
+ import type { ConfirmCheckboxes } from '@/ui';
10
+
11
+ export const confirmModalProps = {
12
+ title: stringProp(),
13
+ message: requiredStringProp(),
14
+ acceptText: stringProp(),
15
+ acceptColor: enumProp(Colors, Colors.Primary),
16
+ cancelText: stringProp(),
17
+ cancelColor: enumProp(Colors, Colors.Clear),
18
+ checkboxes: objectProp<ConfirmCheckboxes>(),
19
+ actions: objectProp<Record<string, () => unknown>>(),
20
+ };
21
+
22
+ export type AGConfirmModalProps = Pretty<
23
+ AcceptRefs<
24
+ SubPartial<
25
+ ObjectWithout<ExtractPropTypes<typeof confirmModalProps>, null | undefined>,
26
+ 'acceptColor' | 'cancelColor'
27
+ >
28
+ >
29
+ >;
30
+
31
+ export function useConfirmModalProps(): typeof confirmModalProps {
32
+ return confirmModalProps;
33
+ }
34
+
35
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
36
+ export function useConfirmModal(props: ExtractPropTypes<typeof confirmModalProps>) {
37
+ const renderedAcceptText = computed(() => props.acceptText ?? translateWithDefault('ui.accept', 'Ok'));
38
+ const renderedCancelText = computed(() => props.cancelText ?? translateWithDefault('ui.cancel', 'Cancel'));
39
+
40
+ return { renderedAcceptText, renderedCancelText };
41
+ }
@@ -1,30 +1,26 @@
1
1
  <template>
2
- <AGModal v-slot="{ close }: IAGModalDefaultSlotProps" :cancellable="false">
3
- <AGMarkdown v-if="title" :text="title" as="h1" />
4
- <AGMarkdown :text="message" />
2
+ <AGModal v-slot="{ close }: IAGModalDefaultSlotProps" :cancellable="false" :title="title">
3
+ <AGMarkdown :text="message" :actions="actions" />
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,10 @@
1
- import type { Component } from 'vue';
1
+ import { computed, ref } from 'vue';
2
+ import type { Component, ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithout, Pretty } from '@noeldemartin/utils';
2
4
 
3
5
  import { requiredArrayProp } from '@/utils/vue';
6
+ import { translateWithDefault } from '@/lang';
7
+ import type { AcceptRefs } from '@/utils/vue';
4
8
  import type { ErrorReport } from '@/errors';
5
9
 
6
10
  export interface IAGErrorReportModalButtonsDefaultSlotProps {
@@ -15,6 +19,31 @@ export const errorReportModalProps = {
15
19
  reports: requiredArrayProp<ErrorReport>(),
16
20
  };
17
21
 
22
+ export type AGErrorReportModalProps = Pretty<
23
+ AcceptRefs<ObjectWithout<ExtractPropTypes<typeof errorReportModalProps>, null | undefined>>
24
+ >;
25
+
18
26
  export function useErrorReportModalProps(): typeof errorReportModalProps {
19
27
  return errorReportModalProps;
20
28
  }
29
+
30
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
31
+ export function useErrorReportModal(props: ExtractPropTypes<typeof errorReportModalProps>) {
32
+ const activeReportIndex = ref(0);
33
+ const report = computed(() => props.reports[activeReportIndex.value] as ErrorReport);
34
+ const details = computed(
35
+ () =>
36
+ report.value.details?.trim() ||
37
+ translateWithDefault('errors.detailsEmpty', 'This error is missing a stacktrace.'),
38
+ );
39
+ const previousReportText = translateWithDefault('errors.previousReport', 'Show previous report');
40
+ const nextReportText = translateWithDefault('errors.nextReport', 'Show next report');
41
+
42
+ return {
43
+ activeReportIndex,
44
+ details,
45
+ nextReportText,
46
+ previousReportText,
47
+ report,
48
+ };
49
+ }
@@ -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,10 +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;
83
85
 
84
86
  // eslint-disable-next-line no-console
85
- console.error(props.report.error);
87
+ console.error(error);
86
88
 
87
89
  UI.showSnackbar(
88
90
  translateWithDefault(
@@ -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,29 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithout } from '@noeldemartin/utils';
4
+
5
+ import { numberProp, stringProp } from '@/utils';
6
+ import { translateWithDefault } from '@/lang';
7
+ import type { AcceptRefs } from '@/utils';
8
+
9
+ export const loadingModalProps = {
10
+ title: stringProp(),
11
+ message: stringProp(),
12
+ progress: numberProp(),
13
+ };
14
+
15
+ export type AGLoadingModalProps = AcceptRefs<
16
+ ObjectWithout<ExtractPropTypes<typeof loadingModalProps>, null | undefined>
17
+ >;
18
+
19
+ export function useLoadingModalProps(): typeof loadingModalProps {
20
+ return loadingModalProps;
21
+ }
22
+
23
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24
+ export function useLoadingModal(props: ExtractPropTypes<typeof loadingModalProps>) {
25
+ const renderedMessage = computed(() => props.message ?? translateWithDefault('ui.loading', 'Loading...'));
26
+ const showProgress = computed(() => typeof props.progress === 'number');
27
+
28
+ return { renderedMessage, showProgress };
29
+ }
@@ -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>
@@ -1,8 +1,9 @@
1
1
  import type { Ref } from 'vue';
2
2
 
3
3
  export interface IAGModal {
4
+ inline: Ref<boolean>;
4
5
  cancellable: Ref<boolean>;
5
- close(): Promise<void>;
6
+ close(result?: unknown): Promise<void>;
6
7
  }
7
8
 
8
9
  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" v-bind="$attrs">
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,22 +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
37
  defineOptions({ inheritAttrs: false });
32
- defineProps({ cancellable: booleanProp(true) });
33
- defineExpose<IAGModal>({
34
- close: async () => $headlessModal.value?.close(),
35
- cancellable: computed(() => !!$headlessModal.value?.cancellable),
36
- });
38
+ defineExpose<IAGModal>(useModalExpose($modal));
37
39
  </script>
@@ -1,18 +1,28 @@
1
1
  <template>
2
- <component :is="modal.component" v-bind="modal.properties" />
2
+ <component :is="modal.component" v-bind="modalProperties" />
3
3
  </template>
4
4
 
5
5
  <script setup lang="ts">
6
- import { provide, toRef } from 'vue';
6
+ import { computed, provide, toRef, unref } from 'vue';
7
7
 
8
- import { requiredNumberProp, requiredObjectProp } from '@/utils/vue';
8
+ import { numberProp, requiredObjectProp } from '@/utils/vue';
9
9
  import type { Modal } from '@/ui/UI.state';
10
10
 
11
11
  import type { IAGModalContext } from './AGModalContext';
12
12
 
13
13
  const props = defineProps({
14
14
  modal: requiredObjectProp<Modal>(),
15
- childIndex: requiredNumberProp(),
15
+ childIndex: numberProp(0),
16
+ });
17
+
18
+ const modalProperties = computed(() => {
19
+ const properties = {} as typeof props.modal.properties;
20
+
21
+ for (const property in props.modal.properties) {
22
+ properties[property] = unref(props.modal.properties[property]);
23
+ }
24
+
25
+ return properties;
16
26
  });
17
27
 
18
28
  provide<IAGModalContext>('modal', {
@@ -0,0 +1,41 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithout, Pretty, SubPartial } from '@noeldemartin/utils';
4
+
5
+ import { Colors } from '@/components/constants';
6
+ import { enumProp, requiredStringProp, stringProp } from '@/utils';
7
+ import { translateWithDefault } from '@/lang';
8
+ import type { AcceptRefs } from '@/utils';
9
+
10
+ export const promptModalProps = {
11
+ title: stringProp(),
12
+ message: requiredStringProp(),
13
+ label: stringProp(),
14
+ defaultValue: stringProp(),
15
+ placeholder: stringProp(),
16
+ acceptText: stringProp(),
17
+ acceptColor: enumProp(Colors, Colors.Primary),
18
+ cancelText: stringProp(),
19
+ cancelColor: enumProp(Colors, Colors.Clear),
20
+ };
21
+
22
+ export type AGPromptModalProps = Pretty<
23
+ AcceptRefs<
24
+ SubPartial<
25
+ ObjectWithout<ExtractPropTypes<typeof promptModalProps>, null | undefined>,
26
+ 'acceptColor' | 'cancelColor'
27
+ >
28
+ >
29
+ >;
30
+
31
+ export function usePromptModalProps(): typeof promptModalProps {
32
+ return promptModalProps;
33
+ }
34
+
35
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
36
+ export function usePromptModal(props: ExtractPropTypes<typeof promptModalProps>) {
37
+ const renderedAcceptText = computed(() => props.acceptText ?? translateWithDefault('ui.accept', 'Ok'));
38
+ const renderedCancelText = computed(() => props.cancelText ?? translateWithDefault('ui.cancel', 'Cancel'));
39
+
40
+ return { renderedAcceptText, renderedCancelText };
41
+ }