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

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 (137) hide show
  1. package/dist/aerogel-core.d.ts +3212 -485
  2. package/dist/aerogel-core.js +2789 -0
  3. package/dist/aerogel-core.js.map +1 -0
  4. package/package.json +25 -31
  5. package/src/bootstrap/bootstrap.test.ts +7 -10
  6. package/src/bootstrap/index.ts +43 -15
  7. package/src/bootstrap/options.ts +4 -1
  8. package/src/components/AGAppLayout.vue +7 -2
  9. package/src/components/AGAppModals.vue +1 -1
  10. package/src/components/AGAppOverlays.vue +6 -2
  11. package/src/components/AGAppSnackbars.vue +2 -2
  12. package/src/components/composition.ts +23 -0
  13. package/src/components/forms/AGButton.vue +2 -2
  14. package/src/components/forms/AGCheckbox.vue +10 -3
  15. package/src/components/forms/AGForm.vue +11 -12
  16. package/src/components/forms/AGInput.vue +13 -7
  17. package/src/components/forms/AGSelect.story.vue +46 -0
  18. package/src/components/forms/AGSelect.vue +60 -0
  19. package/src/components/forms/index.ts +5 -6
  20. package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
  21. package/src/components/headless/forms/AGHeadlessButton.vue +24 -13
  22. package/src/components/headless/forms/AGHeadlessInput.ts +37 -4
  23. package/src/components/headless/forms/AGHeadlessInput.vue +24 -8
  24. package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
  25. package/src/components/headless/forms/AGHeadlessInputError.vue +2 -2
  26. package/src/components/headless/forms/AGHeadlessInputInput.vue +45 -6
  27. package/src/components/headless/forms/AGHeadlessInputLabel.vue +9 -3
  28. package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
  29. package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
  30. package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
  31. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  32. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  33. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  34. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  35. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  37. package/src/components/headless/forms/composition.ts +10 -0
  38. package/src/components/headless/forms/index.ts +13 -1
  39. package/src/components/headless/modals/AGHeadlessModal.ts +30 -1
  40. package/src/components/headless/modals/AGHeadlessModal.vue +16 -12
  41. package/src/components/headless/modals/AGHeadlessModalPanel.vue +13 -9
  42. package/src/components/headless/modals/AGHeadlessModalTitle.vue +14 -4
  43. package/src/components/headless/modals/index.ts +4 -6
  44. package/src/components/headless/snackbars/index.ts +25 -10
  45. package/src/components/index.ts +3 -1
  46. package/src/components/interfaces.ts +24 -0
  47. package/src/components/lib/AGErrorMessage.vue +16 -0
  48. package/src/components/lib/AGMarkdown.vue +54 -0
  49. package/src/components/lib/AGMeasured.vue +16 -0
  50. package/src/components/lib/AGProgressBar.vue +55 -0
  51. package/src/components/lib/AGStartupCrash.vue +31 -0
  52. package/src/components/lib/index.ts +6 -0
  53. package/src/components/modals/AGAlertModal.ts +18 -0
  54. package/src/components/modals/AGAlertModal.vue +4 -15
  55. package/src/components/modals/AGConfirmModal.ts +42 -0
  56. package/src/components/modals/AGConfirmModal.vue +10 -14
  57. package/src/components/modals/AGErrorReportModal.ts +32 -3
  58. package/src/components/modals/AGErrorReportModal.vue +8 -16
  59. package/src/components/modals/AGErrorReportModalButtons.vue +13 -11
  60. package/src/components/modals/AGErrorReportModalTitle.vue +3 -3
  61. package/src/components/modals/AGLoadingModal.ts +29 -0
  62. package/src/components/modals/AGLoadingModal.vue +4 -8
  63. package/src/components/modals/AGModal.ts +2 -1
  64. package/src/components/modals/AGModal.vue +18 -13
  65. package/src/components/modals/AGModalContext.ts +1 -1
  66. package/src/components/modals/AGModalContext.vue +15 -5
  67. package/src/components/modals/AGPromptModal.ts +41 -0
  68. package/src/components/modals/AGPromptModal.vue +34 -0
  69. package/src/components/modals/index.ts +13 -19
  70. package/src/components/snackbars/AGSnackbar.vue +4 -10
  71. package/src/components/utils.ts +13 -0
  72. package/src/directives/index.ts +7 -5
  73. package/src/directives/measure.ts +40 -0
  74. package/src/errors/Errors.state.ts +1 -1
  75. package/src/errors/Errors.ts +32 -30
  76. package/src/errors/JobCancelledError.ts +3 -0
  77. package/src/errors/index.ts +19 -29
  78. package/src/errors/utils.ts +35 -0
  79. package/src/forms/Form.test.ts +32 -3
  80. package/src/forms/Form.ts +90 -21
  81. package/src/forms/composition.ts +2 -2
  82. package/src/forms/index.ts +3 -1
  83. package/src/forms/utils.ts +34 -3
  84. package/src/forms/validation.ts +19 -0
  85. package/src/{main.ts → index.ts} +3 -0
  86. package/src/jobs/Job.ts +147 -0
  87. package/src/jobs/index.ts +10 -0
  88. package/src/jobs/listeners.ts +3 -0
  89. package/src/jobs/status.ts +4 -0
  90. package/src/lang/DefaultLangProvider.ts +46 -0
  91. package/src/lang/Lang.state.ts +11 -0
  92. package/src/lang/Lang.ts +44 -29
  93. package/src/lang/index.ts +7 -5
  94. package/src/plugins/Plugin.ts +1 -1
  95. package/src/plugins/index.ts +10 -7
  96. package/src/services/App.state.ts +29 -7
  97. package/src/services/App.ts +41 -6
  98. package/src/services/Cache.ts +43 -0
  99. package/src/services/Events.test.ts +39 -0
  100. package/src/services/Events.ts +112 -32
  101. package/src/services/Service.ts +154 -49
  102. package/src/services/Storage.ts +20 -0
  103. package/src/services/index.ts +14 -5
  104. package/src/services/store.ts +8 -5
  105. package/src/services/utils.ts +18 -0
  106. package/src/testing/index.ts +26 -0
  107. package/src/testing/setup.ts +11 -0
  108. package/src/ui/UI.state.ts +9 -2
  109. package/src/ui/UI.ts +251 -41
  110. package/src/ui/index.ts +13 -7
  111. package/src/ui/utils.ts +16 -0
  112. package/src/utils/composition/events.ts +3 -2
  113. package/src/utils/composition/persistent.test.ts +33 -0
  114. package/src/utils/composition/persistent.ts +11 -0
  115. package/src/utils/composition/state.test.ts +47 -0
  116. package/src/utils/composition/state.ts +24 -0
  117. package/src/utils/index.ts +3 -0
  118. package/src/utils/markdown.test.ts +50 -0
  119. package/src/utils/markdown.ts +19 -6
  120. package/src/utils/tailwindcss.test.ts +26 -0
  121. package/src/utils/tailwindcss.ts +7 -0
  122. package/src/utils/vue.ts +30 -9
  123. package/.eslintrc.js +0 -3
  124. package/dist/aerogel-core.cjs.js +0 -2
  125. package/dist/aerogel-core.cjs.js.map +0 -1
  126. package/dist/aerogel-core.esm.js +0 -2
  127. package/dist/aerogel-core.esm.js.map +0 -1
  128. package/dist/virtual.d.ts +0 -11
  129. package/noeldemartin.config.js +0 -5
  130. package/src/components/basic/AGErrorMessage.vue +0 -16
  131. package/src/components/basic/AGMarkdown.vue +0 -36
  132. package/src/components/basic/index.ts +0 -5
  133. package/src/directives/initial-focus.ts +0 -11
  134. package/src/types/virtual.d.ts +0 -11
  135. package/tsconfig.json +0 -11
  136. package/vite.config.ts +0 -14
  137. /package/src/components/{basic → lib}/AGLink.vue +0 -0
@@ -5,10 +5,10 @@
5
5
  <script setup lang="ts">
6
6
  import { computed } from 'vue';
7
7
 
8
- import { numberProp, requiredObjectProp } from '@/utils/vue';
9
- import type { ErrorReport } from '@/errors';
8
+ import { numberProp, requiredObjectProp } from '@aerogel/core/utils/vue';
9
+ import type { ErrorReport } from '@aerogel/core/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 '@aerogel/core/utils';
6
+ import { translateWithDefault } from '@aerogel/core/lang';
7
+ import type { AcceptRefs } from '@aerogel/core/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,24 @@
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';
22
- import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from '@/components/headless/modals/AGHeadlessModal';
24
+ import { useModalExpose, useModalProps } from '@aerogel/core/components/headless/modals/AGHeadlessModal';
25
+ import type {
26
+ IAGHeadlessModal,
27
+ IAGHeadlessModalDefaultSlotProps,
28
+ } from '@aerogel/core/components/headless/modals/AGHeadlessModal';
23
29
 
24
30
  import type { IAGModal } from './AGModal';
25
31
 
26
32
  import AGHeadlessModal from '../headless/modals/AGHeadlessModal.vue';
27
33
  import AGHeadlessModalPanel from '../headless/modals/AGHeadlessModalPanel.vue';
34
+ import AGHeadlessModalTitle from '../headless/modals/AGHeadlessModalTitle.vue';
35
+ import AGMarkdown from '../lib/AGMarkdown.vue';
28
36
 
29
- const $headlessModal = ref<IAGHeadlessModal>();
37
+ const props = defineProps(useModalProps());
38
+ const $modal = ref<IAGHeadlessModal>();
30
39
 
31
40
  defineOptions({ inheritAttrs: false });
32
- defineProps({ cancellable: booleanProp(true) });
33
- defineExpose<IAGModal>({
34
- close: async () => $headlessModal.value?.close(),
35
- cancellable: computed(() => !!$headlessModal.value?.cancellable),
36
- });
41
+ defineExpose<IAGModal>(useModalExpose($modal));
37
42
  </script>
@@ -1,6 +1,6 @@
1
1
  import type { Ref } from 'vue';
2
2
 
3
- import type { Modal } from '@/ui/UI.state';
3
+ import type { Modal } from '@aerogel/core/ui/UI.state';
4
4
 
5
5
  export interface IAGModalContext {
6
6
  modal: Ref<Modal>;
@@ -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';
9
- import type { Modal } from '@/ui/UI.state';
8
+ import { numberProp, requiredObjectProp } from '@aerogel/core/utils/vue';
9
+ import type { Modal } from '@aerogel/core/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 '@aerogel/core/components/constants';
6
+ import { enumProp, requiredStringProp, stringProp } from '@aerogel/core/utils';
7
+ import { translateWithDefault } from '@aerogel/core/lang';
8
+ import type { AcceptRefs } from '@aerogel/core/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
+ }
@@ -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,23 +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
-
1
+ export * from './AGAlertModal';
2
+ export * from './AGConfirmModal';
10
3
  export * from './AGErrorReportModal';
4
+ export * from './AGLoadingModal';
11
5
  export * from './AGModal';
12
6
  export * from './AGModalContext';
7
+ export * from './AGPromptModal';
13
8
 
14
- export {
15
- AGAlertModal,
16
- AGConfirmModal,
17
- AGErrorReportModalButtons,
18
- AGErrorReportModalTitle,
19
- AGLoadingModal,
20
- AGModal,
21
- AGModalTitle,
22
- AGModalContext,
23
- };
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';
@@ -15,16 +15,15 @@
15
15
  <script setup lang="ts">
16
16
  import { computed } from 'vue';
17
17
 
18
- import UI from '@/ui/UI';
19
- import { Colors } from '@/components/constants';
20
- import { useSnackbarProps } from '@/components/headless';
21
- import type { SnackbarAction } from '@/components/headless';
18
+ import { Colors } from '@aerogel/core/components/constants';
19
+ import { useSnackbar, useSnackbarProps } from '@aerogel/core/components/headless/snackbars';
22
20
 
23
21
  import AGButton from '../forms/AGButton.vue';
24
22
  import AGHeadlessSnackbar from '../headless/snackbars/AGHeadlessSnackbar.vue';
25
- import AGMarkdown from '../basic/AGMarkdown.vue';
23
+ import AGMarkdown from '../lib/AGMarkdown.vue';
26
24
 
27
25
  const props = defineProps(useSnackbarProps());
26
+ const { activate } = useSnackbar(props);
28
27
  const styleClasses = computed(() => {
29
28
  switch (props.color) {
30
29
  case Colors.Danger:
@@ -34,9 +33,4 @@ const styleClasses = computed(() => {
34
33
  return 'bg-gray-900 text-white';
35
34
  }
36
35
  });
37
-
38
- function activate(action: SnackbarAction): void {
39
- action.handler?.();
40
- action.dismiss && UI.hideSnackbar(props.id);
41
- }
42
36
  </script>
@@ -0,0 +1,13 @@
1
+ export function extractComponentProps<T extends Record<string, unknown>>(
2
+ values: Record<string, unknown>,
3
+ definitions: Record<string, unknown>,
4
+ ): T {
5
+ return Object.keys(definitions).reduce(
6
+ (extracted, prop) => {
7
+ extracted[prop] = values[prop];
8
+
9
+ return extracted;
10
+ },
11
+ {} as Record<string, unknown>,
12
+ ) as T;
13
+ }
@@ -1,13 +1,15 @@
1
1
  import type { Directive } from 'vue';
2
2
 
3
- import { definePlugin } from '@/plugins';
3
+ import { definePlugin } from '@aerogel/core/plugins';
4
4
 
5
- import initialFocus from './initial-focus';
5
+ import measure from './measure';
6
6
 
7
7
  const builtInDirectives: Record<string, Directive> = {
8
- 'initial-focus': initialFocus,
8
+ measure: measure,
9
9
  };
10
10
 
11
+ export * from './measure';
12
+
11
13
  export default definePlugin({
12
14
  install(app, options) {
13
15
  const directives = {
@@ -21,8 +23,8 @@ export default definePlugin({
21
23
  },
22
24
  });
23
25
 
24
- declare module '@/bootstrap/options' {
25
- interface AerogelOptions {
26
+ declare module '@aerogel/core/bootstrap/options' {
27
+ export interface AerogelOptions {
26
28
  directives?: Record<string, Directive>;
27
29
  }
28
30
  }
@@ -0,0 +1,40 @@
1
+ import { defineDirective } from '@aerogel/core/utils/vue';
2
+ import { tap } from '@noeldemartin/utils';
3
+
4
+ const resizeObservers: WeakMap<HTMLElement, ResizeObserver> = new WeakMap();
5
+
6
+ export interface ElementSize {
7
+ width: number;
8
+ height: number;
9
+ }
10
+
11
+ export type MeasureDirectiveListener = (size: ElementSize) => unknown;
12
+
13
+ export default defineDirective({
14
+ mounted(element: HTMLElement, { value }) {
15
+ // TODO replace with argument when typed properly
16
+ const modifiers = { css: true, watch: true };
17
+
18
+ const listener = typeof value === 'function' ? (value as MeasureDirectiveListener) : null;
19
+ const update = () => {
20
+ const sizes = element.getBoundingClientRect();
21
+
22
+ if (modifiers.css) {
23
+ element.style.setProperty('--width', `${sizes.width}px`);
24
+ element.style.setProperty('--height', `${sizes.height}px`);
25
+ }
26
+
27
+ listener?.({ width: sizes.width, height: sizes.height });
28
+ };
29
+
30
+ if (modifiers.watch) {
31
+ resizeObservers.set(element, tap(new ResizeObserver(update)).observe(element));
32
+ }
33
+
34
+ update();
35
+ },
36
+ unmounted(element) {
37
+ resizeObservers.get(element)?.unobserve(element);
38
+ resizeObservers.delete(element);
39
+ },
40
+ });
@@ -1,6 +1,6 @@
1
1
  import type { JSError } from '@noeldemartin/utils';
2
2
 
3
- import { defineServiceState } from '@/services';
3
+ import { defineServiceState } from '@aerogel/core/services';
4
4
 
5
5
  export type ErrorSource = string | Error | JSError | unknown;
6
6
 
@@ -1,13 +1,16 @@
1
- import { JSError, facade, isObject, objectWithoutEmpty, toString } from '@noeldemartin/utils';
1
+ import { JSError, facade, isDevelopment, isObject, isTesting, objectWithoutEmpty, toString } from '@noeldemartin/utils';
2
2
 
3
- import App from '@/services/App';
4
- import ServiceBootError from '@/errors/ServiceBootError';
5
- import UI, { UIComponents } from '@/ui/UI';
6
- import { translateWithDefault } from '@/lang/utils';
3
+ import App from '@aerogel/core/services/App';
4
+ import ServiceBootError from '@aerogel/core/errors/ServiceBootError';
5
+ import UI, { UIComponents } from '@aerogel/core/ui/UI';
6
+ import { translateWithDefault } from '@aerogel/core/lang/utils';
7
7
 
8
8
  import Service from './Errors.state';
9
- import { Colors } from '@/components/constants';
9
+ import { Colors } from '@aerogel/core/components/constants';
10
+ import { Events } from '@aerogel/core/services';
11
+ import type { AGErrorReportModalProps } from '@aerogel/core/components/modals/AGErrorReportModal';
10
12
  import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
13
+ import type { ModalComponent } from '@aerogel/core/ui/UI.state';
11
14
 
12
15
  export class ErrorsService extends Service {
13
16
 
@@ -23,7 +26,7 @@ export class ErrorsService extends Service {
23
26
  }
24
27
 
25
28
  public async inspect(error: ErrorSource | ErrorReport[]): Promise<void> {
26
- const reports = Array.isArray(error) ? error : [await this.createErrorReport(error)];
29
+ const reports = Array.isArray(error) ? (error as ErrorReport[]) : [await this.createErrorReport(error)];
27
30
 
28
31
  if (reports.length === 0) {
29
32
  UI.alert(translateWithDefault('errors.inspectEmpty', 'Nothing to inspect!'));
@@ -31,11 +34,19 @@ export class ErrorsService extends Service {
31
34
  return;
32
35
  }
33
36
 
34
- UI.openModal(UI.requireComponent(UIComponents.ErrorReportModal), { reports });
37
+ UI.openModal<ModalComponent<AGErrorReportModalProps>>(UI.requireComponent(UIComponents.ErrorReportModal), {
38
+ reports,
39
+ });
35
40
  }
36
41
 
37
42
  public async report(error: ErrorSource, message?: string): Promise<void> {
38
- if (App.development || App.testing) {
43
+ await Events.emit('error', { error, message });
44
+
45
+ if (isTesting('unit')) {
46
+ throw error;
47
+ }
48
+
49
+ if (isDevelopment()) {
39
50
  this.logError(error);
40
51
  }
41
52
 
@@ -43,7 +54,7 @@ export class ErrorsService extends Service {
43
54
  throw error;
44
55
  }
45
56
 
46
- if (!App.isMounted) {
57
+ if (!App.isMounted()) {
47
58
  const startupError = await this.createStartupErrorReport(error);
48
59
 
49
60
  if (startupError) {
@@ -70,9 +81,10 @@ export class ErrorsService extends Service {
70
81
  text: translateWithDefault('errors.viewDetails', 'View details'),
71
82
  dismiss: true,
72
83
  handler: () =>
73
- UI.openModal(UI.requireComponent(UIComponents.ErrorReportModal), {
74
- reports: [report],
75
- }),
84
+ UI.openModal<ModalComponent<AGErrorReportModalProps>>(
85
+ UI.requireComponent(UIComponents.ErrorReportModal),
86
+ { reports: [report] },
87
+ ),
76
88
  },
77
89
  ],
78
90
  },
@@ -105,22 +117,6 @@ export class ErrorsService extends Service {
105
117
  });
106
118
  }
107
119
 
108
- public getErrorMessage(error: ErrorSource): string {
109
- if (typeof error === 'string') {
110
- return error;
111
- }
112
-
113
- if (error instanceof Error || error instanceof JSError) {
114
- return error.message;
115
- }
116
-
117
- if (isObject(error)) {
118
- return toString(error['message'] ?? error['description'] ?? 'Unknown error object');
119
- }
120
-
121
- return translateWithDefault('errors.unknown', 'Unknown Error');
122
- }
123
-
124
120
  private logError(error: unknown): void {
125
121
  // eslint-disable-next-line no-console
126
122
  console.error(error);
@@ -180,4 +176,10 @@ export class ErrorsService extends Service {
180
176
 
181
177
  }
182
178
 
183
- export default facade(new ErrorsService());
179
+ export default facade(ErrorsService);
180
+
181
+ declare module '@aerogel/core/services/Events' {
182
+ export interface EventsPayload {
183
+ error: { error: ErrorSource; message?: string };
184
+ }
185
+ }
@@ -0,0 +1,3 @@
1
+ import { JSError } from '@noeldemartin/utils';
2
+
3
+ export default class JobCancelledError extends JSError {}
@@ -1,38 +1,30 @@
1
- import { tap } from '@noeldemartin/utils';
1
+ import type { App } from 'vue';
2
2
 
3
- import { bootServices } from '@/services';
4
- import { definePlugin } from '@/plugins';
3
+ import { bootServices } from '@aerogel/core/services';
4
+ import { definePlugin } from '@aerogel/core/plugins';
5
5
 
6
6
  import Errors from './Errors';
7
- import { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
7
+ import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
8
8
 
9
- export { Errors, ErrorSource, ErrorReport, ErrorReportLog };
9
+ export * from './utils';
10
+ export { Errors };
11
+ export { default as JobCancelledError } from './JobCancelledError';
12
+ export { default as ServiceBootError } from './ServiceBootError';
13
+ export type { ErrorSource, ErrorReport, ErrorReportLog };
10
14
 
11
15
  const services = { $errors: Errors };
12
16
  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
17
  Errors.report(error);
24
18
 
25
19
  return true;
26
20
  };
27
21
 
28
- function setUpErrorHandler(baseHandler: ErrorHandler = () => false): ErrorHandler {
29
- return tap(
30
- (error) => baseHandler(error) || frameworkHandler(error),
31
- (errorHandler) => {
32
- globalThis.onerror = (message, _, __, ___, error) => errorHandler(error ?? message);
33
- globalThis.onunhandledrejection = (event) => errorHandler(event.reason);
34
- },
35
- );
22
+ function setUpErrorHandler(app: App, baseHandler: ErrorHandler = () => false): void {
23
+ const errorHandler: ErrorHandler = (error) => baseHandler(error) || frameworkHandler(error);
24
+
25
+ app.config.errorHandler = errorHandler;
26
+ globalThis.onerror = (event, _, __, ___, error) => errorHandler(error ?? event);
27
+ globalThis.onunhandledrejection = (event) => errorHandler(event.reason);
36
28
  }
37
29
 
38
30
  export type ErrorHandler = (error: ErrorSource) => boolean;
@@ -40,20 +32,18 @@ export type ErrorsServices = typeof services;
40
32
 
41
33
  export default definePlugin({
42
34
  async install(app, options) {
43
- const errorHandler = setUpErrorHandler(options.handleError);
44
-
45
- app.config.errorHandler = errorHandler;
35
+ setUpErrorHandler(app, options.handleError);
46
36
 
47
37
  await bootServices(app, services);
48
38
  },
49
39
  });
50
40
 
51
- declare module '@/bootstrap/options' {
52
- interface AerogelOptions {
41
+ declare module '@aerogel/core/bootstrap/options' {
42
+ export interface AerogelOptions {
53
43
  handleError?(error: ErrorSource): boolean;
54
44
  }
55
45
  }
56
46
 
57
- declare module '@/services' {
47
+ declare module '@aerogel/core/services' {
58
48
  export interface Services extends ErrorsServices {}
59
49
  }
@@ -0,0 +1,35 @@
1
+ import { JSError, isObject, toString } from '@noeldemartin/utils';
2
+ import { translateWithDefault } from '@aerogel/core/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
+ }