@aerogel/core 0.0.0-next.f1f5a990033d966dc0bb12d251110fbc9350dcc7 → 0.0.0-next.f9394854509d71d644498ac087706a2f8f8eea1c

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 (70) 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 +707 -139
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/package.json +3 -3
  7. package/src/bootstrap/bootstrap.test.ts +0 -1
  8. package/src/bootstrap/index.ts +13 -2
  9. package/src/bootstrap/options.ts +3 -0
  10. package/src/components/AGAppSnackbars.vue +1 -1
  11. package/src/components/composition.ts +23 -0
  12. package/src/components/forms/AGCheckbox.vue +7 -1
  13. package/src/components/forms/AGForm.vue +9 -10
  14. package/src/components/forms/AGInput.vue +10 -6
  15. package/src/components/forms/AGSelect.story.vue +21 -3
  16. package/src/components/forms/AGSelect.vue +10 -3
  17. package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
  18. package/src/components/headless/forms/AGHeadlessButton.vue +23 -12
  19. package/src/components/headless/forms/AGHeadlessInput.ts +10 -4
  20. package/src/components/headless/forms/AGHeadlessInput.vue +18 -5
  21. package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
  22. package/src/components/headless/forms/AGHeadlessInputInput.vue +44 -5
  23. package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
  24. package/src/components/headless/forms/AGHeadlessSelect.ts +15 -12
  25. package/src/components/headless/forms/AGHeadlessSelect.vue +23 -22
  26. package/src/components/headless/forms/AGHeadlessSelectOption.vue +6 -6
  27. package/src/components/headless/forms/composition.ts +10 -0
  28. package/src/components/headless/forms/index.ts +4 -0
  29. package/src/components/index.ts +2 -0
  30. package/src/components/interfaces.ts +24 -0
  31. package/src/components/lib/AGErrorMessage.vue +2 -2
  32. package/src/components/lib/AGMarkdown.vue +9 -4
  33. package/src/components/lib/AGMeasured.vue +1 -0
  34. package/src/components/modals/AGConfirmModal.ts +9 -3
  35. package/src/components/modals/AGConfirmModal.vue +2 -2
  36. package/src/components/modals/AGPromptModal.ts +36 -0
  37. package/src/components/modals/AGPromptModal.vue +34 -0
  38. package/src/components/modals/index.ts +10 -19
  39. package/src/directives/index.ts +2 -0
  40. package/src/directives/measure.ts +33 -5
  41. package/src/errors/Errors.ts +16 -19
  42. package/src/errors/index.ts +1 -10
  43. package/src/errors/utils.ts +35 -0
  44. package/src/forms/Form.test.ts +28 -0
  45. package/src/forms/Form.ts +66 -8
  46. package/src/forms/index.ts +3 -1
  47. package/src/forms/utils.ts +34 -3
  48. package/src/forms/validation.ts +19 -0
  49. package/src/jobs/Job.ts +5 -0
  50. package/src/jobs/index.ts +7 -0
  51. package/src/lang/DefaultLangProvider.ts +43 -0
  52. package/src/lang/Lang.state.ts +11 -0
  53. package/src/lang/Lang.ts +44 -29
  54. package/src/main.ts +3 -0
  55. package/src/services/App.state.ts +15 -2
  56. package/src/services/App.ts +24 -3
  57. package/src/services/Cache.ts +43 -0
  58. package/src/services/Events.test.ts +39 -0
  59. package/src/services/Events.ts +100 -30
  60. package/src/services/Service.ts +51 -13
  61. package/src/services/index.ts +4 -1
  62. package/src/services/store.ts +8 -5
  63. package/src/testing/index.ts +25 -0
  64. package/src/testing/setup.ts +19 -0
  65. package/src/ui/UI.state.ts +7 -0
  66. package/src/ui/UI.ts +82 -12
  67. package/src/ui/index.ts +3 -0
  68. package/src/ui/utils.ts +16 -0
  69. package/src/utils/vue.ts +11 -2
  70. package/vite.config.ts +4 -1
@@ -1,37 +1,40 @@
1
1
  import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
2
+ import type { Writable } from '@noeldemartin/utils';
2
3
 
3
- import { requiredArrayProp, stringProp } from '@/utils/vue';
4
+ import { mixedProp, requiredArrayProp, stringProp } from '@/utils/vue';
4
5
  import { extractComponentProps } from '@/components/utils';
5
-
6
- export interface IAGSelectOption {
7
- value: string | number | boolean | object | null;
8
- text: string;
9
- }
10
-
11
- export type IAGSelectOptionValue = string | number | boolean | object | null;
6
+ import type { FormFieldValue } from '@/forms/Form';
12
7
 
13
8
  export interface IAGHeadlessSelect {
14
9
  id: string;
15
10
  label: ComputedRef<string | null>;
16
11
  noSelectionText: ComputedRef<string>;
17
12
  buttonText: ComputedRef<string>;
18
- selectedOption: ComputedRef<IAGSelectOption | undefined>;
19
- options: ComputedRef<IAGSelectOption[]>;
13
+ renderText: ComputedRef<(value: FormFieldValue) => string>;
14
+ selectedOption: ComputedRef<FormFieldValue | null>;
15
+ options: ComputedRef<FormFieldValue[]>;
20
16
  errors: DeepReadonly<Ref<string[] | null>>;
21
- update(value: IAGSelectOptionValue): void;
17
+ update(value: FormFieldValue): void;
22
18
  }
23
19
 
24
20
  export const selectProps = {
25
21
  name: stringProp(),
26
22
  label: stringProp(),
27
- options: requiredArrayProp<IAGSelectOptionValue>(),
23
+ options: requiredArrayProp<FormFieldValue>(),
28
24
  noSelectionText: stringProp(),
25
+ optionsText: mixedProp<string | ((option: FormFieldValue) => string)>(),
29
26
  };
30
27
 
28
+ export const selectEmits = ['update:modelValue'] as const;
29
+
31
30
  export function useSelectProps(): typeof selectProps {
32
31
  return selectProps;
33
32
  }
34
33
 
34
+ export function useSelectEmits(): Writable<typeof selectEmits> {
35
+ return [...selectEmits];
36
+ }
37
+
35
38
  export function extractSelectProps<T extends ExtractPropTypes<typeof selectProps>>(
36
39
  props: T,
37
40
  ): Pick<T, keyof typeof selectProps> {
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <Listbox
3
3
  v-slot="{ value, open, disabled }: ComponentProps"
4
- :model-value="selectedOption?.value"
4
+ :model-value="selectedOption"
5
5
  @update:model-value="update($event)"
6
6
  >
7
7
  <slot :value="value" :open="open" :disabled="disabled" />
@@ -10,38 +10,37 @@
10
10
 
11
11
  <script setup lang="ts">
12
12
  import { computed, inject, provide } from 'vue';
13
- import { isObject, toString, uuid } from '@noeldemartin/utils';
13
+ import { toString, uuid } from '@noeldemartin/utils';
14
14
  import { Listbox } from '@headlessui/vue';
15
15
 
16
16
  import { mixedProp } from '@/utils/vue';
17
17
  import { translateWithDefault } from '@/lang/utils';
18
18
  import type Form from '@/forms/Form';
19
+ import type { FormFieldValue } from '@/forms/Form';
19
20
  import type { ComponentProps } from '@/utils/vue';
20
21
 
21
- import { useSelectProps } from './AGHeadlessSelect';
22
- import type { IAGHeadlessSelect, IAGSelectOption, IAGSelectOptionValue } from './AGHeadlessSelect';
22
+ import { useSelectEmits, useSelectProps } from './AGHeadlessSelect';
23
+ import type { IAGHeadlessSelect } from './AGHeadlessSelect';
23
24
 
24
- const emit = defineEmits(['update:modelValue']);
25
+ const emit = defineEmits(useSelectEmits());
25
26
  const props = defineProps({
26
- modelValue: mixedProp<IAGSelectOptionValue>(),
27
+ modelValue: mixedProp<FormFieldValue>(),
27
28
  ...useSelectProps(),
28
29
  });
29
- const form = inject<Form | null>('form', null);
30
- const noSelectionText = computed(() => props.noSelectionText ?? translateWithDefault('select.noSelection', '-'));
31
- const options = computed(() =>
32
- props.options.map((value) => {
33
- const option: IAGSelectOption = {
34
- value,
35
- text: toString(isObject(value) && 'text' in value ? value.text : value),
36
- };
30
+ const renderText = computed(() => {
31
+ if (typeof props.optionsText === 'function') {
32
+ return props.optionsText;
33
+ }
37
34
 
38
- return option;
39
- }));
40
- const selectedOption = computed(() => {
41
- const selectedOptionValue = form && props.name ? form.getFieldValue(props.name) : props.modelValue;
35
+ if (typeof props.optionsText === 'string') {
36
+ return (option: FormFieldValue): string => toString(option[props.optionsText as keyof FormFieldValue]);
37
+ }
42
38
 
43
- return options.value.find((option) => option.value === selectedOptionValue);
39
+ return (option: FormFieldValue) => toString(option);
44
40
  });
41
+ const form = inject<Form | null>('form', null);
42
+ const noSelectionText = computed(() => props.noSelectionText ?? translateWithDefault('select.noSelection', '-'));
43
+ const selectedOption = computed(() => (form && props.name ? form.getFieldValue(props.name) : props.modelValue));
45
44
  const errors = computed(() => {
46
45
  if (!form || !props.name) {
47
46
  return null;
@@ -50,7 +49,7 @@ const errors = computed(() => {
50
49
  return form.errors[props.name] ?? null;
51
50
  });
52
51
 
53
- function update(value: IAGSelectOptionValue) {
52
+ function update(value: FormFieldValue) {
54
53
  if (form && props.name) {
55
54
  form.setFieldValue(props.name, value);
56
55
 
@@ -62,12 +61,14 @@ function update(value: IAGSelectOptionValue) {
62
61
 
63
62
  const api: IAGHeadlessSelect = {
64
63
  id: `select-${uuid()}`,
65
- options,
66
64
  noSelectionText,
67
65
  selectedOption,
68
66
  errors,
67
+ options: computed(() => props.options),
69
68
  label: computed(() => props.label),
70
- buttonText: computed(() => selectedOption.value?.text ?? noSelectionText.value),
69
+ buttonText: computed(() =>
70
+ selectedOption.value === null ? noSelectionText.value : renderText.value(selectedOption.value)),
71
+ renderText,
71
72
  update,
72
73
  };
73
74
 
@@ -9,31 +9,31 @@
9
9
  [unselectedClass ?? 'unselected']: !selected,
10
10
  }"
11
11
  >
12
- {{ option?.text }}
12
+ {{ select.renderText(value) }}
13
13
  </li>
14
14
  </slot>
15
15
  </ListboxOption>
16
16
  </template>
17
17
 
18
18
  <script setup lang="ts">
19
- import { computed } from 'vue';
20
19
  import { ListboxOption } from '@headlessui/vue';
21
20
 
22
21
  import { injectReactiveOrFail, requiredMixedProp, stringProp } from '@/utils/vue';
23
22
  import type { ComponentProps } from '@/utils/vue';
23
+ import type { FormFieldValue } from '@/forms/Form';
24
24
 
25
- import type { IAGHeadlessSelect, IAGSelectOptionValue } from './AGHeadlessSelect';
25
+ import type { IAGHeadlessSelect } from './AGHeadlessSelect';
26
26
 
27
- const props = defineProps({
28
- value: requiredMixedProp<IAGSelectOptionValue>(),
27
+ defineProps({
28
+ value: requiredMixedProp<FormFieldValue>(),
29
29
  selectedClass: stringProp(),
30
30
  unselectedClass: stringProp(),
31
31
  activeClass: stringProp(),
32
32
  inactiveClass: stringProp(),
33
33
  });
34
+
34
35
  const select = injectReactiveOrFail<IAGHeadlessSelect>(
35
36
  'select',
36
37
  '<AGHeadlessSelectOption> must be a child of a <AGHeadlessSelect>',
37
38
  );
38
- const option = computed(() => select.options.find((selectOption) => selectOption.value === props.value));
39
39
  </script>
@@ -0,0 +1,10 @@
1
+ import { inject, onUnmounted } from 'vue';
2
+
3
+ import type Form from '@/forms/Form';
4
+
5
+ export function onFormFocus(input: { name: string | null }, listener: () => unknown): void {
6
+ const form = inject<Form | null>('form', null);
7
+ const stop = form?.on('focus', (name) => input.name === name && listener());
8
+
9
+ onUnmounted(() => stop?.());
10
+ }
@@ -1,11 +1,15 @@
1
+ export * from './composition';
2
+ export * from './AGHeadlessButton';
1
3
  export * from './AGHeadlessInput';
2
4
  export * from './AGHeadlessSelect';
3
5
  export * from './AGHeadlessSelectOption';
4
6
  export { default as AGHeadlessButton } from './AGHeadlessButton.vue';
5
7
  export { default as AGHeadlessInput } from './AGHeadlessInput.vue';
8
+ export { default as AGHeadlessInputDescription } from './AGHeadlessInputDescription.vue';
6
9
  export { default as AGHeadlessInputError } from './AGHeadlessInputError.vue';
7
10
  export { default as AGHeadlessInputInput } from './AGHeadlessInputInput.vue';
8
11
  export { default as AGHeadlessInputLabel } from './AGHeadlessInputLabel.vue';
12
+ export { default as AGHeadlessInputTextArea } from './AGHeadlessInputTextArea.vue';
9
13
  export { default as AGHeadlessSelect } from './AGHeadlessSelect.vue';
10
14
  export { default as AGHeadlessSelectButton } from './AGHeadlessSelectButton.vue';
11
15
  export { default as AGHeadlessSelectError } from './AGHeadlessSelectError.vue';
@@ -3,9 +3,11 @@ import AGAppOverlays from './AGAppOverlays.vue';
3
3
 
4
4
  export { AGAppLayout, AGAppOverlays };
5
5
 
6
+ export * from './composition';
6
7
  export * from './constants';
7
8
  export * from './forms';
8
9
  export * from './headless';
10
+ export * from './interfaces';
9
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>
@@ -3,20 +3,21 @@
3
3
  </template>
4
4
 
5
5
  <script setup lang="ts">
6
- import { computed, h } from 'vue';
6
+ import { computed, h, useAttrs } from 'vue';
7
7
 
8
8
  import { renderMarkdown } from '@/utils/markdown';
9
- import { booleanProp, objectProp, stringProp } from '@/utils/vue';
9
+ import { booleanProp, mixedProp, stringProp } from '@/utils/vue';
10
10
  import { translate } from '@/lang';
11
11
 
12
12
  const props = defineProps({
13
13
  as: stringProp(),
14
14
  inline: booleanProp(),
15
15
  langKey: stringProp(),
16
- langParams: objectProp<Record<string, unknown>>(),
16
+ langParams: mixedProp<number | Record<string, unknown>>(),
17
17
  text: stringProp(),
18
18
  });
19
19
 
20
+ const attrs = useAttrs();
20
21
  const markdown = computed(() => props.text ?? (props.langKey && translate(props.langKey, props.langParams ?? {})));
21
22
  const html = computed(() => {
22
23
  if (!markdown.value) {
@@ -32,5 +33,9 @@ const html = computed(() => {
32
33
  return renderedHtml;
33
34
  });
34
35
  const root = () =>
35
- h(props.as ?? (props.inline ? 'span' : 'div'), { class: props.inline ? '' : 'prose', innerHTML: html.value });
36
+ h(props.as ?? (props.inline ? 'span' : 'div'), {
37
+ innerHTML: html.value,
38
+ ...attrs,
39
+ class: `${attrs.class ?? ''} ${props.inline ? '' : 'prose'}`,
40
+ });
36
41
  </script>
@@ -11,5 +11,6 @@ import { stringProp } from '@/utils/vue';
11
11
 
12
12
  defineProps({ as: stringProp('span') });
13
13
 
14
+ // TODO use v-measure.css
14
15
  const measured = ref(false);
15
16
  </script>
@@ -1,18 +1,24 @@
1
1
  import { computed } from 'vue';
2
2
  import type { ExtractPropTypes } from 'vue';
3
- import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
3
+ import type { ObjectWithoutEmpty, SubPartial } from '@noeldemartin/utils';
4
4
 
5
- import { requiredStringProp, stringProp } from '@/utils';
5
+ import { Colors } from '@/components/constants';
6
+ import { enumProp, requiredStringProp, stringProp } from '@/utils';
6
7
  import { translateWithDefault } from '@/lang';
7
8
 
8
9
  export const confirmModalProps = {
9
10
  title: stringProp(),
10
11
  message: requiredStringProp(),
11
12
  acceptText: stringProp(),
13
+ acceptColor: enumProp(Colors, Colors.Primary),
12
14
  cancelText: stringProp(),
15
+ cancelColor: enumProp(Colors, Colors.Clear),
13
16
  };
14
17
 
15
- export type AGConfirmModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof confirmModalProps>>;
18
+ export type AGConfirmModalProps = SubPartial<
19
+ ObjectWithoutEmpty<ExtractPropTypes<typeof confirmModalProps>>,
20
+ 'acceptColor' | 'cancelColor'
21
+ >;
16
22
 
17
23
  export function useConfirmModalProps(): typeof confirmModalProps {
18
24
  return confirmModalProps;
@@ -3,10 +3,10 @@
3
3
  <AGMarkdown :text="message" />
4
4
 
5
5
  <div class="mt-2 flex flex-row-reverse gap-2">
6
- <AGButton @click="close(true)">
6
+ <AGButton :color="acceptColor" @click="close(true)">
7
7
  {{ renderedAcceptText }}
8
8
  </AGButton>
9
- <AGButton color="secondary" @click="close()">
9
+ <AGButton :color="cancelColor" @click="close()">
10
10
  {{ renderedCancelText }}
11
11
  </AGButton>
12
12
  </div>
@@ -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,26 +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 AGModalTitle from './AGModalTitle.vue';
8
- import AGModalContext from './AGModalContext.vue';
9
-
10
1
  export * from './AGAlertModal';
11
2
  export * from './AGConfirmModal';
12
3
  export * from './AGErrorReportModal';
13
4
  export * from './AGLoadingModal';
14
5
  export * from './AGModal';
15
6
  export * from './AGModalContext';
7
+ export * from './AGPromptModal';
16
8
 
17
- export {
18
- AGAlertModal,
19
- AGConfirmModal,
20
- AGErrorReportModalButtons,
21
- AGErrorReportModalTitle,
22
- AGLoadingModal,
23
- AGModal,
24
- AGModalTitle,
25
- AGModalContext,
26
- };
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';
@@ -10,6 +10,8 @@ const builtInDirectives: Record<string, Directive> = {
10
10
  'measure': measure,
11
11
  };
12
12
 
13
+ export * from './measure';
14
+
13
15
  export default definePlugin({
14
16
  install(app, options) {
15
17
  const directives = {
@@ -1,12 +1,40 @@
1
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;
2
12
 
3
13
  export default defineDirective({
4
- mounted(element: HTMLElement, { value }: { value?: () => unknown }) {
5
- const sizes = element.getBoundingClientRect();
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();
6
21
 
7
- element.style.setProperty('--width', `${sizes.width}px`);
8
- element.style.setProperty('--height', `${sizes.height}px`);
22
+ if (modifiers.css) {
23
+ element.style.setProperty('--width', `${sizes.width}px`);
24
+ element.style.setProperty('--height', `${sizes.height}px`);
25
+ }
9
26
 
10
- value?.();
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);
11
39
  },
12
40
  });
@@ -7,6 +7,7 @@ import { translateWithDefault } from '@/lang/utils';
7
7
 
8
8
  import Service from './Errors.state';
9
9
  import { Colors } from '@/components/constants';
10
+ import { Events } from '@/services';
10
11
  import type { AGErrorReportModalProps } from '@/components/modals/AGErrorReportModal';
11
12
  import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
12
13
  import type { ModalComponent } from '@/ui/UI.state';
@@ -39,7 +40,13 @@ export class ErrorsService extends Service {
39
40
  }
40
41
 
41
42
  public async report(error: ErrorSource, message?: string): Promise<void> {
42
- if (App.development || App.testing) {
43
+ await Events.emit('error', { error, message });
44
+
45
+ if (App.testing) {
46
+ throw error;
47
+ }
48
+
49
+ if (App.development) {
43
50
  this.logError(error);
44
51
  }
45
52
 
@@ -47,7 +54,7 @@ export class ErrorsService extends Service {
47
54
  throw error;
48
55
  }
49
56
 
50
- if (!App.isMounted) {
57
+ if (!App.isMounted()) {
51
58
  const startupError = await this.createStartupErrorReport(error);
52
59
 
53
60
  if (startupError) {
@@ -110,22 +117,6 @@ export class ErrorsService extends Service {
110
117
  });
111
118
  }
112
119
 
113
- public getErrorMessage(error: ErrorSource): string {
114
- if (typeof error === 'string') {
115
- return error;
116
- }
117
-
118
- if (error instanceof Error || error instanceof JSError) {
119
- return error.message;
120
- }
121
-
122
- if (isObject(error)) {
123
- return toString(error['message'] ?? error['description'] ?? 'Unknown error object');
124
- }
125
-
126
- return translateWithDefault('errors.unknown', 'Unknown Error');
127
- }
128
-
129
120
  private logError(error: unknown): void {
130
121
  // eslint-disable-next-line no-console
131
122
  console.error(error);
@@ -185,4 +176,10 @@ export class ErrorsService extends Service {
185
176
 
186
177
  }
187
178
 
188
- export default facade(new ErrorsService());
179
+ export default facade(ErrorsService);
180
+
181
+ declare module '@/services/Events' {
182
+ export interface EventsPayload {
183
+ error: { error: ErrorSource; message?: string };
184
+ }
185
+ }
@@ -6,20 +6,11 @@ import { definePlugin } from '@/plugins';
6
6
  import Errors from './Errors';
7
7
  import { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
8
8
 
9
+ export * from './utils';
9
10
  export { Errors, ErrorSource, ErrorReport, ErrorReportLog };
10
11
 
11
12
  const services = { $errors: Errors };
12
13
  const frameworkHandler: ErrorHandler = (error) => {
13
- if (!Errors.instance) {
14
- // eslint-disable-next-line no-console
15
- console.warn('Errors service hasn\'t been initialized properly!');
16
-
17
- // eslint-disable-next-line no-console
18
- console.error(error);
19
-
20
- return true;
21
- }
22
-
23
14
  Errors.report(error);
24
15
 
25
16
  return true;
@@ -0,0 +1,35 @@
1
+ import { JSError, isObject, toString } from '@noeldemartin/utils';
2
+ import { translateWithDefault } from '@/lang/utils';
3
+ import type { ErrorSource } from './Errors.state';
4
+
5
+ const handlers: ErrorHandler[] = [];
6
+
7
+ export type ErrorHandler = (error: ErrorSource) => string | undefined;
8
+
9
+ export function registerErrorHandler(handler: ErrorHandler): void {
10
+ handlers.push(handler);
11
+ }
12
+
13
+ export function getErrorMessage(error: ErrorSource): string {
14
+ for (const handler of handlers) {
15
+ const result = handler(error);
16
+
17
+ if (result) {
18
+ return result;
19
+ }
20
+ }
21
+
22
+ if (typeof error === 'string') {
23
+ return error;
24
+ }
25
+
26
+ if (error instanceof Error || error instanceof JSError) {
27
+ return error.message;
28
+ }
29
+
30
+ if (isObject(error)) {
31
+ return toString(error['message'] ?? error['description'] ?? 'Unknown error object');
32
+ }
33
+
34
+ return translateWithDefault('errors.unknown', 'Unknown Error');
35
+ }