@aerogel/core 0.0.0-next.b85327579d32f21c6a9fa21142f0165cdd320d7e → 0.0.0-next.d547095ca85c86c1e41f5c7fa170d0ba856c3f4d

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 (106) 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 +1371 -257
  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/noeldemartin.config.js +4 -1
  8. package/package.json +13 -4
  9. package/postcss.config.js +6 -0
  10. package/src/assets/histoire.css +3 -0
  11. package/src/bootstrap/bootstrap.test.ts +4 -3
  12. package/src/bootstrap/index.ts +25 -5
  13. package/src/bootstrap/options.ts +3 -0
  14. package/src/components/AGAppLayout.vue +7 -2
  15. package/src/components/AGAppModals.vue +15 -0
  16. package/src/components/AGAppOverlays.vue +10 -8
  17. package/src/components/AGAppSnackbars.vue +13 -0
  18. package/src/components/constants.ts +8 -0
  19. package/src/components/forms/AGButton.vue +25 -15
  20. package/src/components/forms/AGCheckbox.vue +7 -1
  21. package/src/components/forms/AGInput.vue +8 -6
  22. package/src/components/forms/AGSelect.story.vue +46 -0
  23. package/src/components/forms/AGSelect.vue +60 -0
  24. package/src/components/forms/index.ts +5 -6
  25. package/src/components/headless/forms/AGHeadlessButton.vue +9 -8
  26. package/src/components/headless/forms/AGHeadlessInput.ts +21 -1
  27. package/src/components/headless/forms/AGHeadlessInput.vue +8 -5
  28. package/src/components/headless/forms/AGHeadlessInputInput.vue +2 -0
  29. package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
  30. package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
  31. package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
  32. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  33. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  34. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  35. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  37. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  38. package/src/components/headless/forms/index.ts +9 -1
  39. package/src/components/headless/index.ts +1 -0
  40. package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
  41. package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
  42. package/src/components/headless/modals/index.ts +4 -6
  43. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  44. package/src/components/headless/snackbars/index.ts +40 -0
  45. package/src/components/index.ts +3 -1
  46. package/src/components/lib/AGErrorMessage.vue +16 -0
  47. package/src/components/lib/AGLink.vue +9 -0
  48. package/src/components/{basic → lib}/AGMarkdown.vue +7 -6
  49. package/src/components/lib/AGMeasured.vue +15 -0
  50. package/src/components/lib/AGStartupCrash.vue +31 -0
  51. package/src/components/lib/index.ts +5 -0
  52. package/src/components/modals/AGAlertModal.ts +15 -0
  53. package/src/components/modals/AGAlertModal.vue +4 -16
  54. package/src/components/modals/AGConfirmModal.ts +27 -0
  55. package/src/components/modals/AGConfirmModal.vue +8 -12
  56. package/src/components/modals/AGErrorReportModal.ts +46 -0
  57. package/src/components/modals/AGErrorReportModal.vue +54 -0
  58. package/src/components/modals/AGErrorReportModalButtons.vue +111 -0
  59. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  60. package/src/components/modals/AGLoadingModal.ts +23 -0
  61. package/src/components/modals/AGLoadingModal.vue +4 -8
  62. package/src/components/modals/AGModal.ts +1 -1
  63. package/src/components/modals/AGModal.vue +16 -13
  64. package/src/components/modals/AGModalTitle.vue +9 -0
  65. package/src/components/modals/AGPromptModal.ts +30 -0
  66. package/src/components/modals/AGPromptModal.vue +34 -0
  67. package/src/components/modals/index.ts +16 -7
  68. package/src/components/snackbars/AGSnackbar.vue +36 -0
  69. package/src/components/snackbars/index.ts +3 -0
  70. package/src/components/utils.ts +10 -0
  71. package/src/directives/index.ts +20 -3
  72. package/src/directives/measure.ts +21 -0
  73. package/src/errors/Errors.ts +65 -12
  74. package/src/errors/index.ts +26 -1
  75. package/src/errors/utils.ts +19 -0
  76. package/src/forms/Form.ts +15 -6
  77. package/src/jobs/Job.ts +5 -0
  78. package/src/jobs/index.ts +7 -0
  79. package/src/lang/Lang.ts +12 -24
  80. package/src/main.histoire.ts +1 -0
  81. package/src/main.ts +3 -2
  82. package/src/plugins/Plugin.ts +1 -0
  83. package/src/plugins/index.ts +19 -0
  84. package/src/services/App.state.ts +8 -4
  85. package/src/services/App.ts +35 -5
  86. package/src/services/Events.test.ts +39 -0
  87. package/src/services/Events.ts +100 -30
  88. package/src/services/Service.ts +55 -16
  89. package/src/services/index.ts +8 -4
  90. package/src/services/store.ts +8 -5
  91. package/src/testing/index.ts +25 -0
  92. package/src/ui/UI.state.ts +10 -1
  93. package/src/ui/UI.ts +160 -26
  94. package/src/ui/index.ts +12 -3
  95. package/src/utils/composition/events.ts +1 -0
  96. package/src/utils/index.ts +1 -0
  97. package/src/utils/markdown.ts +11 -2
  98. package/src/utils/tailwindcss.test.ts +26 -0
  99. package/src/utils/tailwindcss.ts +7 -0
  100. package/src/utils/vue.ts +15 -4
  101. package/tailwind.config.js +4 -0
  102. package/tsconfig.json +1 -0
  103. package/vite.config.ts +2 -1
  104. package/.eslintrc.js +0 -3
  105. package/src/components/basic/index.ts +0 -3
  106. package/src/globals.ts +0 -6
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <ListboxOption v-slot="{ active, selected, disabled }: ComponentProps" :value="value" as="template">
3
+ <slot :active="active" :selected="selected" :disabled="disabled">
4
+ <li
5
+ :class="{
6
+ [activeClass ?? 'active']: active,
7
+ [inactiveClass ?? 'inactive']: !active,
8
+ [selectedClass ?? 'selected']: selected,
9
+ [unselectedClass ?? 'unselected']: !selected,
10
+ }"
11
+ >
12
+ {{ select.renderText(value) }}
13
+ </li>
14
+ </slot>
15
+ </ListboxOption>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ import { ListboxOption } from '@headlessui/vue';
20
+
21
+ import { injectReactiveOrFail, requiredMixedProp, stringProp } from '@/utils/vue';
22
+ import type { ComponentProps } from '@/utils/vue';
23
+ import type { FormFieldValue } from '@/forms/Form';
24
+
25
+ import type { IAGHeadlessSelect } from './AGHeadlessSelect';
26
+
27
+ defineProps({
28
+ value: requiredMixedProp<FormFieldValue>(),
29
+ selectedClass: stringProp(),
30
+ unselectedClass: stringProp(),
31
+ activeClass: stringProp(),
32
+ inactiveClass: stringProp(),
33
+ });
34
+
35
+ const select = injectReactiveOrFail<IAGHeadlessSelect>(
36
+ 'select',
37
+ '<AGHeadlessSelectOption> must be a child of a <AGHeadlessSelect>',
38
+ );
39
+ </script>
@@ -0,0 +1,3 @@
1
+ import { ListboxOptions } from '@headlessui/vue';
2
+
3
+ export default ListboxOptions;
@@ -1,6 +1,14 @@
1
- export { IAGHeadlessInput } from './AGHeadlessInput';
1
+ export * from './AGHeadlessInput';
2
+ export * from './AGHeadlessSelect';
3
+ export * from './AGHeadlessSelectOption';
2
4
  export { default as AGHeadlessButton } from './AGHeadlessButton.vue';
3
5
  export { default as AGHeadlessInput } from './AGHeadlessInput.vue';
4
6
  export { default as AGHeadlessInputError } from './AGHeadlessInputError.vue';
5
7
  export { default as AGHeadlessInputInput } from './AGHeadlessInputInput.vue';
6
8
  export { default as AGHeadlessInputLabel } from './AGHeadlessInputLabel.vue';
9
+ export { default as AGHeadlessSelect } from './AGHeadlessSelect.vue';
10
+ export { default as AGHeadlessSelectButton } from './AGHeadlessSelectButton.vue';
11
+ export { default as AGHeadlessSelectError } from './AGHeadlessSelectError.vue';
12
+ export { default as AGHeadlessSelectLabel } from './AGHeadlessSelectLabel.vue';
13
+ export { default as AGHeadlessSelectOption } from './AGHeadlessSelectOption.vue';
14
+ export { default as AGHeadlessSelectOptions } from './AGHeadlessSelectOptions';
@@ -1,2 +1,3 @@
1
1
  export * from './forms';
2
2
  export * from './modals';
3
+ export * from './snackbars';
@@ -1,3 +1,8 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes, Ref } from 'vue';
3
+
4
+ import { booleanProp, stringProp } from '@/utils';
5
+ import { extractComponentProps } from '@/components/utils';
1
6
  import type { IAGModal } from '@/components/modals/AGModal';
2
7
 
3
8
  export interface IAGHeadlessModal extends IAGModal {}
@@ -5,3 +10,25 @@ export interface IAGHeadlessModal extends IAGModal {}
5
10
  export interface IAGHeadlessModalDefaultSlotProps {
6
11
  close(result?: unknown): Promise<void>;
7
12
  }
13
+
14
+ export const modalProps = {
15
+ cancellable: booleanProp(true),
16
+ title: stringProp(),
17
+ };
18
+
19
+ export function useModalProps(): typeof modalProps {
20
+ return modalProps;
21
+ }
22
+
23
+ export function extractModalProps<T extends ExtractPropTypes<typeof modalProps>>(
24
+ props: T,
25
+ ): Pick<T, keyof typeof modalProps> {
26
+ return extractComponentProps(props, modalProps);
27
+ }
28
+
29
+ export function useModalExpose($modal: Ref<IAGHeadlessModal | undefined>): IAGModal {
30
+ return {
31
+ close: async () => $modal.value?.close(),
32
+ cancellable: computed(() => !!$modal.value?.cancellable),
33
+ };
34
+ }
@@ -11,15 +11,13 @@ import type { VNode } from 'vue';
11
11
 
12
12
  import Events from '@/services/Events';
13
13
  import { useEvent } from '@/utils/composition/events';
14
- import { booleanProp, injectReactiveOrFail } from '@/utils/vue';
14
+ import { injectReactiveOrFail } from '@/utils/vue';
15
15
  import type { IAGModalContext } from '@/components/modals/AGModalContext';
16
16
 
17
+ import { useModalProps } from './AGHeadlessModal';
17
18
  import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from './AGHeadlessModal';
18
19
 
19
- const props = defineProps({
20
- cancellable: booleanProp(true),
21
- });
22
-
20
+ const props = defineProps(useModalProps());
23
21
  const $root = ref<{ $el?: HTMLElement } | null>(null);
24
22
  const hidden = ref(true);
25
23
  const closed = ref(false);
@@ -1,6 +1,4 @@
1
- import AGHeadlessModal from './AGHeadlessModal.vue';
2
- import AGHeadlessModalPanel from './AGHeadlessModalPanel.vue';
3
- import AGHeadlessModalTitle from './AGHeadlessModalTitle.vue';
4
- import type { IAGHeadlessModal } from './AGHeadlessModal';
5
-
6
- export { AGHeadlessModal, AGHeadlessModalPanel, AGHeadlessModalTitle, IAGHeadlessModal };
1
+ export * from './AGHeadlessModal';
2
+ export { default as AGHeadlessModal } from './AGHeadlessModal.vue';
3
+ export { default as AGHeadlessModalPanel } from './AGHeadlessModalPanel.vue';
4
+ export { default as AGHeadlessModalTitle } from './AGHeadlessModalTitle.vue';
@@ -0,0 +1,10 @@
1
+ <template>
2
+ <div class="pointer-events-auto">
3
+ <slot />
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ // Stub import to fix build (otherwise, this file doesn't seem to be treated as a module).
9
+ import 'virtual:aerogel';
10
+ </script>
@@ -0,0 +1,40 @@
1
+ import type { ExtractPropTypes } from 'vue';
2
+ import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
3
+
4
+ import UI from '@/ui/UI';
5
+ import { arrayProp, enumProp, requiredStringProp } from '@/utils/vue';
6
+ import { Colors } from '@/components/constants';
7
+ import { objectWithout } from '@noeldemartin/utils';
8
+
9
+ export { default as AGHeadlessSnackbar } from './AGHeadlessSnackbar.vue';
10
+
11
+ export const SnackbarColors = objectWithout(Colors, ['Primary', 'Clear']);
12
+ export const snackbarProps = {
13
+ id: requiredStringProp(),
14
+ message: requiredStringProp(),
15
+ actions: arrayProp<SnackbarAction>(() => []),
16
+ color: enumProp(SnackbarColors, Colors.Secondary),
17
+ };
18
+
19
+ export interface SnackbarAction {
20
+ text: string;
21
+ dismiss?: boolean;
22
+ handler?(): unknown;
23
+ }
24
+
25
+ export type SnackbarColor = (typeof SnackbarColors)[keyof typeof SnackbarColors];
26
+ export type AGSnackbarProps = ObjectWithoutEmpty<ExtractPropTypes<typeof snackbarProps>>;
27
+
28
+ export function useSnackbarProps(): typeof snackbarProps {
29
+ return snackbarProps;
30
+ }
31
+
32
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
33
+ export function useSnackbar(props: ExtractPropTypes<typeof snackbarProps>) {
34
+ function activate(action: SnackbarAction): void {
35
+ action.handler?.();
36
+ action.dismiss && UI.hideSnackbar(props.id);
37
+ }
38
+
39
+ return { activate };
40
+ }
@@ -3,7 +3,9 @@ import AGAppOverlays from './AGAppOverlays.vue';
3
3
 
4
4
  export { AGAppLayout, AGAppOverlays };
5
5
 
6
- export * from './basic';
6
+ export * from './constants';
7
7
  export * from './forms';
8
8
  export * from './headless';
9
+ export * from './lib';
9
10
  export * from './modals';
11
+ export * from './snackbars';
@@ -0,0 +1,16 @@
1
+ <template>
2
+ <AGMarkdown :text="message" inline />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { computed } from 'vue';
7
+
8
+ import { requiredObjectProp } from '@/utils/vue';
9
+ import { getErrorMessage } from '@/errors/utils';
10
+ import type { ErrorSource } from '@/errors/Errors.state';
11
+
12
+ import AGMarkdown from './AGMarkdown.vue';
13
+
14
+ const props = defineProps({ error: requiredObjectProp<ErrorSource>() });
15
+ const message = computed(() => getErrorMessage(props.error));
16
+ </script>
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <AGHeadlessButton class="font-medium hover:underline">
3
+ <slot />
4
+ </AGHeadlessButton>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import AGHeadlessButton from '../headless/forms/AGHeadlessButton.vue';
9
+ </script>
@@ -6,18 +6,18 @@
6
6
  import { computed, h } from 'vue';
7
7
 
8
8
  import { renderMarkdown } from '@/utils/markdown';
9
- import { booleanProp, stringProp } from '@/utils/vue';
9
+ import { booleanProp, objectProp, stringProp } from '@/utils/vue';
10
10
  import { translate } from '@/lang';
11
11
 
12
12
  const props = defineProps({
13
- as: stringProp('div'),
13
+ as: stringProp(),
14
+ inline: booleanProp(),
14
15
  langKey: stringProp(),
16
+ langParams: objectProp<Record<string, unknown>>(),
15
17
  text: stringProp(),
16
- inline: booleanProp(),
17
- raw: booleanProp(),
18
18
  });
19
19
 
20
- const markdown = computed(() => props.text ?? (props.langKey && translate(props.langKey)));
20
+ const markdown = computed(() => props.text ?? (props.langKey && translate(props.langKey, props.langParams ?? {})));
21
21
  const html = computed(() => {
22
22
  if (!markdown.value) {
23
23
  return null;
@@ -31,5 +31,6 @@ const html = computed(() => {
31
31
 
32
32
  return renderedHtml;
33
33
  });
34
- const root = () => h(props.as, { class: props.raw ? '' : 'prose', innerHTML: html.value });
34
+ const root = () =>
35
+ h(props.as ?? (props.inline ? 'span' : 'div'), { class: props.inline ? '' : 'prose', innerHTML: html.value });
35
36
  </script>
@@ -0,0 +1,15 @@
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
+ const measured = ref(false);
15
+ </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,5 @@
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 AGStartupCrash } from './AGStartupCrash.vue';
@@ -0,0 +1,15 @@
1
+ import type { ExtractPropTypes } from 'vue';
2
+ import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
3
+
4
+ import { requiredStringProp, stringProp } from '@/utils';
5
+
6
+ export const alertModalProps = {
7
+ title: stringProp(),
8
+ message: requiredStringProp(),
9
+ };
10
+
11
+ export type AGAlertModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof alertModalProps>>;
12
+
13
+ export function useAlertModalProps(): typeof alertModalProps {
14
+ return alertModalProps;
15
+ }
@@ -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,27 @@
1
+ import { computed } from 'vue';
2
+ import type { ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
4
+
5
+ import { requiredStringProp, stringProp } from '@/utils';
6
+ import { translateWithDefault } from '@/lang';
7
+
8
+ export const confirmModalProps = {
9
+ title: stringProp(),
10
+ message: requiredStringProp(),
11
+ acceptText: stringProp(),
12
+ cancelText: stringProp(),
13
+ };
14
+
15
+ export type AGConfirmModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof confirmModalProps>>;
16
+
17
+ export function useConfirmModalProps(): typeof confirmModalProps {
18
+ return confirmModalProps;
19
+ }
20
+
21
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
22
+ export function useConfirmModal(props: ExtractPropTypes<typeof confirmModalProps>) {
23
+ const renderedAcceptText = computed(() => props.acceptText ?? translateWithDefault('ui.accept', 'Ok'));
24
+ const renderedCancelText = computed(() => props.cancelText ?? translateWithDefault('ui.cancel', 'Cancel'));
25
+
26
+ return { renderedAcceptText, renderedCancelText };
27
+ }
@@ -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
6
  <AGButton @click="close(true)">
8
- {{ $td('ui.ok', 'OK') }}
7
+ {{ renderedAcceptText }}
9
8
  </AGButton>
10
- <AGButton secondary @click="close()">
11
- {{ $td('ui.cancel', 'Cancel') }}
9
+ <AGButton color="secondary" @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>
@@ -0,0 +1,46 @@
1
+ import { computed, ref } from 'vue';
2
+ import type { Component, ExtractPropTypes } from 'vue';
3
+ import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
4
+
5
+ import { requiredArrayProp } from '@/utils/vue';
6
+ import { translateWithDefault } from '@/lang';
7
+ import type { ErrorReport } from '@/errors';
8
+
9
+ export interface IAGErrorReportModalButtonsDefaultSlotProps {
10
+ id: string;
11
+ description: string;
12
+ iconComponent: Component;
13
+ url?: string;
14
+ handler?(): void;
15
+ }
16
+
17
+ export const errorReportModalProps = {
18
+ reports: requiredArrayProp<ErrorReport>(),
19
+ };
20
+
21
+ export type AGErrorReportModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof errorReportModalProps>>;
22
+
23
+ export function useErrorReportModalProps(): typeof errorReportModalProps {
24
+ return errorReportModalProps;
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
+ }
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <AGModal>
3
+ <div>
4
+ <h2 class="flex items-center justify-between text-lg font-medium">
5
+ <div class="flex items-center">
6
+ <AGErrorReportModalTitle
7
+ :report="report"
8
+ :current-report="activeReportIndex + 1"
9
+ :total-reports="reports.length"
10
+ />
11
+ <template v-if="reports.length > 1">
12
+ <AGButton
13
+ color="clear"
14
+ :disabled="activeReportIndex === 0"
15
+ :title="previousReportText"
16
+ :aria-label="previousReportText"
17
+ @click="activeReportIndex--"
18
+ >
19
+ <IconCheveronLeft aria-hidden="true" class="h-4 w-4" />
20
+ </AGButton>
21
+ <AGButton
22
+ color="clear"
23
+ :disabled="activeReportIndex === reports.length - 1"
24
+ :title="nextReportText"
25
+ :aria-label="nextReportText"
26
+ @click="activeReportIndex++"
27
+ >
28
+ <IconCheveronRight aria-hidden="true" class="h-4 w-4" />
29
+ </AGButton>
30
+ </template>
31
+ </div>
32
+ <AGErrorReportModalButtons :report="report" />
33
+ </h2>
34
+ <AGMarkdown v-if="report.description" :text="report.description" class="mt-2" />
35
+ </div>
36
+ <pre class="h-full overflow-auto bg-gray-200 p-4 text-xs text-red-900" v-text="details" />
37
+ </AGModal>
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import IconCheveronRight from '~icons/zondicons/cheveron-right';
42
+ import IconCheveronLeft from '~icons/zondicons/cheveron-left';
43
+
44
+ import { useErrorReportModal, useErrorReportModalProps } from './AGErrorReportModal';
45
+
46
+ import AGButton from '../forms/AGButton.vue';
47
+ import AGErrorReportModalButtons from './AGErrorReportModalButtons.vue';
48
+ import AGErrorReportModalTitle from './AGErrorReportModalTitle.vue';
49
+ import AGMarkdown from '../lib/AGMarkdown.vue';
50
+ import AGModal from './AGModal.vue';
51
+
52
+ const props = defineProps(useErrorReportModalProps());
53
+ const { activeReportIndex, details, nextReportText, previousReportText, report } = useErrorReportModal(props);
54
+ </script>
@@ -0,0 +1,111 @@
1
+ <template>
2
+ <div class="flex">
3
+ <slot v-for="(button, i) of buttons" v-bind="(button as unknown as ComponentProps)" :key="i">
4
+ <AGButton
5
+ color="clear"
6
+ :url="button.url"
7
+ :title="$td(`errors.report_${button.id}`, button.description)"
8
+ :aria-label="$td(`errors.report_${button.id}`, button.description)"
9
+ @click="button.handler"
10
+ >
11
+ <component :is="button.iconComponent" class="h-4 w-4" aria-hidden="true" />
12
+ </AGButton>
13
+ </slot>
14
+ </div>
15
+ </template>
16
+
17
+ <script setup lang="ts">
18
+ import IconConsole from '~icons/mdi/console';
19
+ import IconCopy from '~icons/zondicons/copy';
20
+ import IconGitHub from '~icons/mdi/github';
21
+
22
+ import { computed } from 'vue';
23
+ import { stringExcerpt, tap } from '@noeldemartin/utils';
24
+
25
+ import App from '@/services/App';
26
+ import UI from '@/ui/UI';
27
+ import { requiredObjectProp } from '@/utils/vue';
28
+ import { translateWithDefault } from '@/lang/utils';
29
+ import type { ComponentProps } from '@/utils/vue';
30
+ import type { ErrorReport } from '@/errors';
31
+
32
+ import AGButton from '../forms/AGButton.vue';
33
+ import type { IAGErrorReportModalButtonsDefaultSlotProps } from './AGErrorReportModal';
34
+
35
+ const props = defineProps({
36
+ report: requiredObjectProp<ErrorReport>(),
37
+ });
38
+ const summary = computed(() =>
39
+ props.report.description ? `${props.report.title}: ${props.report.description}` : props.report.title);
40
+ const githubReportUrl = computed(() => {
41
+ if (!App.sourceUrl) {
42
+ return false;
43
+ }
44
+
45
+ const issueTitle = encodeURIComponent(summary.value);
46
+ const issueBody = encodeURIComponent(
47
+ [
48
+ '[Please, explain here what you were trying to do when this error appeared]',
49
+ '',
50
+ 'Error details:',
51
+ '```',
52
+ stringExcerpt(
53
+ props.report.details ?? 'Details missing from report',
54
+ 1800 - issueTitle.length - App.sourceUrl.length,
55
+ ).trim(),
56
+ '```',
57
+ ].join('\n'),
58
+ );
59
+
60
+ return `${App.sourceUrl}/issues/new?title=${issueTitle}&body=${issueBody}`;
61
+ });
62
+ const buttons = computed(() =>
63
+ tap(
64
+ [
65
+ {
66
+ id: 'clipboard',
67
+ description: 'Copy to clipboard',
68
+ iconComponent: IconCopy,
69
+ async handler() {
70
+ await navigator.clipboard.writeText(`${summary.value}\n\n${props.report.details}`);
71
+
72
+ UI.showSnackbar(
73
+ translateWithDefault('errors.copiedToClipboard', 'Debug information copied to clipboard'),
74
+ );
75
+ },
76
+ },
77
+ {
78
+ id: 'console',
79
+ description: 'Log to console',
80
+ iconComponent: IconConsole,
81
+ handler() {
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);
88
+
89
+ UI.showSnackbar(
90
+ translateWithDefault(
91
+ 'errors.addedToConsole',
92
+ 'You can now use the **error** variable in the console',
93
+ ),
94
+ );
95
+ },
96
+ },
97
+ ],
98
+ (reportButtons: IAGErrorReportModalButtonsDefaultSlotProps[]) => {
99
+ if (!githubReportUrl.value) {
100
+ return;
101
+ }
102
+
103
+ reportButtons.push({
104
+ id: 'github',
105
+ description: 'Report in GitHub',
106
+ iconComponent: IconGitHub,
107
+ url: githubReportUrl.value,
108
+ });
109
+ },
110
+ ));
111
+ </script>