@aerogel/core 0.0.0-next.c8f032a868370824898e171969aec1bb6827688e → 0.0.0-next.d824b40e5d06757cd9f47c9f771d916185df4f05

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 (72) 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 +545 -88
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/dist/virtual.d.ts +11 -0
  7. package/noeldemartin.config.js +4 -1
  8. package/package.json +4 -3
  9. package/src/bootstrap/index.ts +6 -2
  10. package/src/components/AGAppModals.vue +15 -0
  11. package/src/components/AGAppOverlays.vue +5 -7
  12. package/src/components/AGAppSnackbars.vue +13 -0
  13. package/src/components/basic/AGErrorMessage.vue +16 -0
  14. package/src/components/basic/AGLink.vue +9 -0
  15. package/src/components/basic/AGMarkdown.vue +10 -9
  16. package/src/components/basic/index.ts +3 -1
  17. package/src/components/constants.ts +8 -0
  18. package/src/components/forms/AGButton.vue +33 -10
  19. package/src/components/forms/AGCheckbox.vue +35 -0
  20. package/src/components/forms/AGInput.vue +8 -4
  21. package/src/components/forms/index.ts +2 -1
  22. package/src/components/headless/forms/AGHeadlessButton.vue +7 -7
  23. package/src/components/headless/forms/AGHeadlessInput.ts +2 -2
  24. package/src/components/headless/forms/AGHeadlessInput.vue +3 -3
  25. package/src/components/headless/forms/AGHeadlessInputError.vue +1 -1
  26. package/src/components/headless/forms/AGHeadlessInputInput.vue +15 -3
  27. package/src/components/headless/index.ts +1 -0
  28. package/src/components/headless/modals/AGHeadlessModalPanel.vue +5 -1
  29. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  30. package/src/components/headless/snackbars/index.ts +25 -0
  31. package/src/components/index.ts +2 -0
  32. package/src/components/modals/AGAlertModal.vue +0 -1
  33. package/src/components/modals/AGConfirmModal.vue +1 -1
  34. package/src/components/modals/AGErrorReportModal.ts +20 -0
  35. package/src/components/modals/AGErrorReportModal.vue +62 -0
  36. package/src/components/modals/AGErrorReportModalButtons.vue +109 -0
  37. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  38. package/src/components/modals/AGLoadingModal.vue +19 -0
  39. package/src/components/modals/AGModal.vue +23 -4
  40. package/src/components/modals/AGModalTitle.vue +9 -0
  41. package/src/components/modals/index.ts +18 -2
  42. package/src/components/snackbars/AGSnackbar.vue +42 -0
  43. package/src/components/snackbars/index.ts +3 -0
  44. package/src/directives/index.ts +16 -3
  45. package/src/errors/Errors.state.ts +31 -0
  46. package/src/errors/Errors.ts +183 -0
  47. package/src/errors/index.ts +59 -0
  48. package/src/forms/Form.test.ts +21 -0
  49. package/src/forms/Form.ts +22 -12
  50. package/src/forms/utils.ts +17 -0
  51. package/src/lang/Lang.ts +12 -4
  52. package/src/lang/index.ts +3 -5
  53. package/src/lang/utils.ts +4 -0
  54. package/src/main.ts +1 -2
  55. package/src/plugins/Plugin.ts +1 -0
  56. package/src/plugins/index.ts +19 -0
  57. package/src/services/App.state.ts +10 -2
  58. package/src/services/App.ts +14 -1
  59. package/src/services/Service.ts +132 -45
  60. package/src/services/index.ts +21 -4
  61. package/src/services/store.ts +27 -0
  62. package/src/types/virtual.d.ts +11 -0
  63. package/src/ui/UI.state.ts +11 -1
  64. package/src/ui/UI.ts +52 -8
  65. package/src/ui/index.ts +7 -1
  66. package/src/utils/composition/forms.ts +11 -0
  67. package/src/utils/index.ts +1 -0
  68. package/src/utils/markdown.ts +11 -2
  69. package/src/utils/vue.ts +2 -0
  70. package/tsconfig.json +1 -0
  71. package/vite.config.ts +2 -1
  72. package/src/globals.ts +0 -6
@@ -6,30 +6,31 @@
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;
24
24
  }
25
25
 
26
- let html = renderMarkdown(markdown.value);
26
+ let renderedHtml = renderMarkdown(markdown.value);
27
27
 
28
28
  if (props.inline) {
29
- html = html.replace('<p>', '<span>').replace('</p>', '</span>');
29
+ renderedHtml = renderedHtml.replace('<p>', '<span>').replace('</p>', '</span>');
30
30
  }
31
31
 
32
- return html;
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>
@@ -1,3 +1,5 @@
1
+ import AGErrorMessage from './AGErrorMessage.vue';
2
+ import AGLink from './AGLink.vue';
1
3
  import AGMarkdown from './AGMarkdown.vue';
2
4
 
3
- export { AGMarkdown };
5
+ export { AGErrorMessage, AGLink, AGMarkdown };
@@ -0,0 +1,8 @@
1
+ export const Colors = {
2
+ Primary: 'primary',
3
+ Secondary: 'secondary',
4
+ Danger: 'danger',
5
+ Clear: 'clear',
6
+ } as const;
7
+
8
+ export type Color = (typeof Colors)[keyof typeof Colors];
@@ -1,21 +1,44 @@
1
1
  <template>
2
- <AGHeadlessButton
3
- class="px-2.5 py-1.5 text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2"
4
- :class="{
5
- 'bg-indigo-600 hover:bg-indigo-500 focus-visible:outline-indigo-600': !secondary,
6
- 'bg-gray-600 hover:bg-gray-500 focus-visible:outline-gray-600': secondary,
7
- }"
8
- >
2
+ <AGHeadlessButton class="px-2.5 py-1.5 focus-visible:outline focus-visible:outline-2" :class="colorClasses">
9
3
  <slot />
10
4
  </AGHeadlessButton>
11
5
  </template>
12
6
 
13
7
  <script setup lang="ts">
14
- import { booleanProp } from '@/utils';
8
+ import { computed } from 'vue';
9
+
10
+ import { enumProp } from '@/utils/vue';
11
+ import { Colors } from '@/components/constants';
15
12
 
16
13
  import AGHeadlessButton from '../headless/forms/AGHeadlessButton.vue';
17
14
 
18
- defineProps({
19
- secondary: booleanProp(),
15
+ const props = defineProps({
16
+ color: enumProp(Colors, Colors.Primary),
17
+ });
18
+
19
+ const colorClasses = computed(() => {
20
+ switch (props.color) {
21
+ case Colors.Secondary:
22
+ return [
23
+ 'text-white bg-gray-600',
24
+ 'hover:bg-gray-500',
25
+ 'focus-visible:outline-offset-2 focus-visible:outline-gray-600',
26
+ ].join(' ');
27
+ case Colors.Clear:
28
+ return 'hover:bg-gray-500/20 focus-visible:outline-gray-500/60';
29
+ case Colors.Danger:
30
+ return [
31
+ 'text-white bg-red-600',
32
+ 'hover:bg-red-500',
33
+ 'focus-visible:outline-offset-2 focus-visible:outline-red-600',
34
+ ].join(' ');
35
+ case Colors.Primary:
36
+ default:
37
+ return [
38
+ 'text-white bg-indigo-600',
39
+ 'hover:bg-indigo-500',
40
+ 'focus-visible:outline-offset-2 focus-visible:outline-indigo-600',
41
+ ].join(' ');
42
+ }
20
43
  });
21
44
  </script>
@@ -0,0 +1,35 @@
1
+ <template>
2
+ <AGHeadlessInput ref="$input" :name="name" class="flex">
3
+ <AGHeadlessInputInput
4
+ v-bind="$attrs"
5
+ type="checkbox"
6
+ :class="{
7
+ 'text-indigo-600 focus:ring-indigo-600': !$input?.errors,
8
+ 'border-red-200 text-red-600 focus:ring-red-600': $input?.errors,
9
+ }"
10
+ />
11
+
12
+ <div class="ml-2">
13
+ <AGHeadlessInputLabel v-if="$slots.default">
14
+ <slot />
15
+ </AGHeadlessInputLabel>
16
+ <AGHeadlessInputError class="text-sm text-red-600" />
17
+ </div>
18
+ </AGHeadlessInput>
19
+ </template>
20
+
21
+ <script setup lang="ts">
22
+ import { componentRef, stringProp } from '@/utils/vue';
23
+
24
+ import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
25
+
26
+ import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
27
+ import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
28
+ import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
29
+ import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
30
+
31
+ defineProps({ name: stringProp() });
32
+ defineOptions({ inheritAttrs: false });
33
+
34
+ const $input = componentRef<IAGHeadlessInput>();
35
+ </script>
@@ -1,24 +1,27 @@
1
1
  <template>
2
2
  <AGHeadlessInput
3
3
  ref="$input"
4
- as="div"
5
- class="flex flex-col items-center"
4
+ class="relative flex flex-col items-center"
5
+ :class="className"
6
6
  :name="name"
7
7
  >
8
8
  <AGHeadlessInputInput
9
- v-bind="$attrs"
9
+ v-bind="attrs"
10
10
  class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600"
11
11
  :class="{
12
12
  'ring-1 ring-red-500': $input?.errors,
13
13
  }"
14
14
  />
15
- <AGHeadlessInputError class="mt-1 text-sm text-red-500" />
15
+ <div class="absolute bottom-0 left-0 translate-y-full">
16
+ <AGHeadlessInputError class="mt-1 text-sm text-red-500" />
17
+ </div>
16
18
  </AGHeadlessInput>
17
19
  </template>
18
20
 
19
21
  <script setup lang="ts">
20
22
  import { componentRef, stringProp } from '@/utils/vue';
21
23
 
24
+ import { useInputAttrs } from '@/utils';
22
25
  import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
23
26
 
24
27
  import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
@@ -29,4 +32,5 @@ defineProps({ name: stringProp() });
29
32
  defineOptions({ inheritAttrs: false });
30
33
 
31
34
  const $input = componentRef<IAGHeadlessInput>();
35
+ const [attrs, className] = useInputAttrs();
32
36
  </script>
@@ -1,5 +1,6 @@
1
1
  import AGButton from './AGButton.vue';
2
+ import AGCheckbox from './AGCheckbox.vue';
2
3
  import AGForm from './AGForm.vue';
3
4
  import AGInput from './AGInput.vue';
4
5
 
5
- export { AGButton, AGForm, AGInput };
6
+ export { AGButton, AGCheckbox, AGForm, AGInput };
@@ -7,15 +7,15 @@
7
7
  <script setup lang="ts">
8
8
  import { computed } from 'vue';
9
9
  import { objectWithoutEmpty } from '@noeldemartin/utils';
10
- import type { LocationQuery, RouteLocation, RouteParams } from 'vue-router';
11
10
 
12
11
  import { booleanProp, objectProp, stringProp } from '@/utils/vue';
13
12
 
14
- const { url, route, routeParams, routeQuery, submit } = defineProps({
13
+ const { href, url, route, routeParams, routeQuery, submit } = defineProps({
14
+ href: stringProp(),
15
15
  url: stringProp(),
16
16
  route: stringProp(),
17
- routeParams: objectProp<RouteParams>(() => ({})),
18
- routeQuery: objectProp<LocationQuery>(() => ({})),
17
+ routeParams: objectProp(() => ({})),
18
+ routeQuery: objectProp(() => ({})),
19
19
  submit: booleanProp(),
20
20
  });
21
21
 
@@ -24,7 +24,7 @@ const component = computed(() => {
24
24
  return {
25
25
  tag: 'router-link',
26
26
  props: {
27
- to: objectWithoutEmpty<Partial<RouteLocation>>({
27
+ to: objectWithoutEmpty({
28
28
  name: route,
29
29
  params: routeParams,
30
30
  query: routeQuery,
@@ -33,12 +33,12 @@ const component = computed(() => {
33
33
  };
34
34
  }
35
35
 
36
- if (url) {
36
+ if (href || url) {
37
37
  return {
38
38
  tag: 'a',
39
39
  props: {
40
40
  target: '_blank',
41
- href: url,
41
+ href: href || url,
42
42
  },
43
43
  };
44
44
  }
@@ -2,7 +2,7 @@ import type { ComputedRef, DeepReadonly, Ref } from 'vue';
2
2
 
3
3
  export interface IAGHeadlessInput {
4
4
  id: string;
5
- value: ComputedRef<string | number | null>;
5
+ value: ComputedRef<string | number | boolean | null>;
6
6
  errors: DeepReadonly<Ref<string[] | null>>;
7
- update(value: string | number | null): void;
7
+ update(value: string | number | boolean | null): void;
8
8
  }
@@ -9,16 +9,16 @@
9
9
  import { computed, inject, provide, readonly } from 'vue';
10
10
  import { uuid } from '@noeldemartin/utils';
11
11
 
12
- import { stringProp } from '@/utils/vue';
12
+ import { mixedProp, stringProp } from '@/utils/vue';
13
13
  import type Form from '@/forms/Form';
14
14
 
15
15
  import type { IAGHeadlessInput } from './AGHeadlessInput';
16
16
 
17
17
  const emit = defineEmits(['update:modelValue']);
18
18
  const props = defineProps({
19
- as: stringProp(),
19
+ as: stringProp('div'),
20
20
  name: stringProp(),
21
- modelValue: stringProp(),
21
+ modelValue: mixedProp<string | number | boolean>([String, Number, Boolean]),
22
22
  });
23
23
  const errors = computed(() => {
24
24
  if (!form || !props.name) {
@@ -8,7 +8,7 @@
8
8
  import { computed } from 'vue';
9
9
 
10
10
  import { injectReactiveOrFail } from '@/utils/vue';
11
- import { translateWithDefault } from '@/lang';
11
+ import { translateWithDefault } from '@/lang/utils';
12
12
 
13
13
  import type { IAGHeadlessInput } from './AGHeadlessInput';
14
14
 
@@ -2,10 +2,11 @@
2
2
  <input
3
3
  :id="input.id"
4
4
  ref="$input"
5
- type="text"
5
+ :type="type"
6
6
  :value="value"
7
7
  :aria-invalid="input.errors ? 'true' : 'false'"
8
8
  :aria-describedby="input.errors ? `${input.id}-error` : undefined"
9
+ :checked="checked"
9
10
  @input="update"
10
11
  >
11
12
  </template>
@@ -13,21 +14,32 @@
13
14
  <script setup lang="ts">
14
15
  import { computed, ref } from 'vue';
15
16
 
16
- import { injectReactiveOrFail } from '@/utils';
17
+ import { injectReactiveOrFail, stringProp } from '@/utils';
17
18
  import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
18
19
 
20
+ const props = defineProps({
21
+ type: stringProp('text'),
22
+ });
23
+
19
24
  const $input = ref<HTMLInputElement>();
20
25
  const input = injectReactiveOrFail<IAGHeadlessInput>(
21
26
  'input',
22
27
  '<AGHeadlessInputInput> must be a child of a <AGHeadlessInput>',
23
28
  );
24
29
  const value = computed(() => input.value);
30
+ const checked = computed(() => {
31
+ if (props.type !== 'checkbox') {
32
+ return;
33
+ }
34
+
35
+ return !!value.value;
36
+ });
25
37
 
26
38
  function update() {
27
39
  if (!$input.value) {
28
40
  return;
29
41
  }
30
42
 
31
- input.update($input.value.value);
43
+ input.update(props.type === 'checkbox' ? $input.value.checked : $input.value.value);
32
44
  }
33
45
  </script>
@@ -1,2 +1,3 @@
1
1
  export * from './forms';
2
2
  export * from './modals';
3
+ export * from './snackbars';
@@ -1,7 +1,11 @@
1
1
  <template>
2
2
  <DialogPanel>
3
3
  <slot />
4
- <AGModalContext v-if="childModal" :child-index="modal.childIndex + 1" :modal="childModal" />
4
+
5
+ <template v-if="childModal">
6
+ <div class="pointer-events-none fixed inset-0 z-50 bg-black/30" />
7
+ <AGModalContext :child-index="modal.childIndex + 1" :modal="childModal" />
8
+ </template>
5
9
  </DialogPanel>
6
10
  </template>
7
11
 
@@ -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,25 @@
1
+ import { arrayProp, enumProp, requiredStringProp } from '@/utils/vue';
2
+ import { Colors } from '@/components/constants';
3
+ import { objectWithout } from '@noeldemartin/utils';
4
+
5
+ export { default as AGHeadlessSnackbar } from './AGHeadlessSnackbar.vue';
6
+
7
+ export interface SnackbarAction {
8
+ text: string;
9
+ dismiss?: boolean;
10
+ handler?(): unknown;
11
+ }
12
+
13
+ export type SnackbarColor = (typeof SnackbarColors)[keyof typeof SnackbarColors];
14
+
15
+ export const SnackbarColors = objectWithout(Colors, ['Primary', 'Clear']);
16
+ export const snackbarProps = {
17
+ id: requiredStringProp(),
18
+ message: requiredStringProp(),
19
+ actions: arrayProp<SnackbarAction>(() => []),
20
+ color: enumProp(SnackbarColors, Colors.Secondary),
21
+ };
22
+
23
+ export function useSnackbarProps(): typeof snackbarProps {
24
+ return snackbarProps;
25
+ }
@@ -4,6 +4,8 @@ import AGAppOverlays from './AGAppOverlays.vue';
4
4
  export { AGAppLayout, AGAppOverlays };
5
5
 
6
6
  export * from './basic';
7
+ export * from './constants';
7
8
  export * from './forms';
8
9
  export * from './headless';
9
10
  export * from './modals';
11
+ export * from './snackbars';
@@ -5,7 +5,6 @@
5
5
  :text="title"
6
6
  as="h2"
7
7
  class="font-semibold"
8
- raw
9
8
  inline
10
9
  />
11
10
  <AGMarkdown :text="message" />
@@ -7,7 +7,7 @@
7
7
  <AGButton @click="close(true)">
8
8
  {{ $td('ui.ok', 'OK') }}
9
9
  </AGButton>
10
- <AGButton secondary @click="close()">
10
+ <AGButton color="secondary" @click="close()">
11
11
  {{ $td('ui.cancel', 'Cancel') }}
12
12
  </AGButton>
13
13
  </div>
@@ -0,0 +1,20 @@
1
+ import type { Component } from 'vue';
2
+
3
+ import { requiredArrayProp } from '@/utils/vue';
4
+ import type { ErrorReport } from '@/errors';
5
+
6
+ export interface IAGErrorReportModalButtonsDefaultSlotProps {
7
+ id: string;
8
+ description: string;
9
+ iconComponent: Component;
10
+ url?: string;
11
+ handler?(): void;
12
+ }
13
+
14
+ export const errorReportModalProps = {
15
+ reports: requiredArrayProp<ErrorReport>(),
16
+ };
17
+
18
+ export function useErrorReportModalProps(): typeof errorReportModalProps {
19
+ return errorReportModalProps;
20
+ }
@@ -0,0 +1,62 @@
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="$td('errors.previousReport', 'Show previous report')"
16
+ :aria-label="$td('errors.previousReport', 'Show previous report')"
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="$td('errors.nextReport', 'Show next report')"
25
+ :aria-label="$td('errors.nextReport', 'Show next report')"
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
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
+ />
40
+ </AGModal>
41
+ </template>
42
+
43
+ <script setup lang="ts">
44
+ import IconCheveronRight from '~icons/zondicons/cheveron-right';
45
+ import IconCheveronLeft from '~icons/zondicons/cheveron-left';
46
+
47
+ import { computed, ref } from 'vue';
48
+
49
+ import type { ErrorReport } from '@/errors';
50
+
51
+ import { useErrorReportModalProps } from './AGErrorReportModal';
52
+
53
+ import AGButton from '../forms/AGButton.vue';
54
+ import AGErrorReportModalButtons from './AGErrorReportModalButtons.vue';
55
+ import AGErrorReportModalTitle from './AGErrorReportModalTitle.vue';
56
+ import AGMarkdown from '../basic/AGMarkdown.vue';
57
+ import AGModal from './AGModal.vue';
58
+
59
+ const props = defineProps(useErrorReportModalProps());
60
+ const activeReportIndex = ref(0);
61
+ const report = computed(() => props.reports[activeReportIndex.value] as ErrorReport);
62
+ </script>
@@ -0,0 +1,109 @@
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
+ (window as { error?: unknown }).error = props.report.error;
83
+
84
+ // eslint-disable-next-line no-console
85
+ console.error(props.report.error);
86
+
87
+ UI.showSnackbar(
88
+ translateWithDefault(
89
+ 'errors.addedToConsole',
90
+ 'You can now use the **error** variable in the console',
91
+ ),
92
+ );
93
+ },
94
+ },
95
+ ],
96
+ (reportButtons: IAGErrorReportModalButtonsDefaultSlotProps[]) => {
97
+ if (!githubReportUrl.value) {
98
+ return;
99
+ }
100
+
101
+ reportButtons.push({
102
+ id: 'github',
103
+ description: 'Report in GitHub',
104
+ iconComponent: IconGitHub,
105
+ url: githubReportUrl.value,
106
+ });
107
+ },
108
+ ));
109
+ </script>
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <AGMarkdown :text="text" inline />
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { computed } from 'vue';
7
+
8
+ import { numberProp, requiredObjectProp } from '@/utils/vue';
9
+ import type { ErrorReport } from '@/errors';
10
+
11
+ import AGMarkdown from '../basic/AGMarkdown.vue';
12
+
13
+ const props = defineProps({
14
+ report: requiredObjectProp<ErrorReport>(),
15
+ currentReport: numberProp(),
16
+ totalReports: numberProp(),
17
+ });
18
+ const text = computed(() => {
19
+ if (!props.totalReports || props.totalReports <= 1) {
20
+ return props.report.title;
21
+ }
22
+
23
+ return `${props.report.title} (${props.currentReport}/${props.totalReports})`;
24
+ });
25
+ </script>
@@ -0,0 +1,19 @@
1
+ <template>
2
+ <AGModal :cancellable="false">
3
+ <AGMarkdown :text="renderedMessage" />
4
+ </AGModal>
5
+ </template>
6
+
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
+ import AGModal from './AGModal.vue';
14
+
15
+ import AGMarkdown from '../basic/AGMarkdown.vue';
16
+
17
+ const props = defineProps({ message: stringProp() });
18
+ const renderedMessage = computed(() => props.message ?? translateWithDefault('ui.loading', 'Loading...'));
19
+ </script>