@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.
- package/dist/aerogel-core.cjs.js +1 -1
- package/dist/aerogel-core.cjs.js.map +1 -1
- package/dist/aerogel-core.d.ts +1371 -257
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/histoire.config.ts +7 -0
- package/noeldemartin.config.js +4 -1
- package/package.json +13 -4
- package/postcss.config.js +6 -0
- package/src/assets/histoire.css +3 -0
- package/src/bootstrap/bootstrap.test.ts +4 -3
- package/src/bootstrap/index.ts +25 -5
- package/src/bootstrap/options.ts +3 -0
- package/src/components/AGAppLayout.vue +7 -2
- package/src/components/AGAppModals.vue +15 -0
- package/src/components/AGAppOverlays.vue +10 -8
- package/src/components/AGAppSnackbars.vue +13 -0
- package/src/components/constants.ts +8 -0
- package/src/components/forms/AGButton.vue +25 -15
- package/src/components/forms/AGCheckbox.vue +7 -1
- package/src/components/forms/AGInput.vue +8 -6
- package/src/components/forms/AGSelect.story.vue +46 -0
- package/src/components/forms/AGSelect.vue +60 -0
- package/src/components/forms/index.ts +5 -6
- package/src/components/headless/forms/AGHeadlessButton.vue +9 -8
- package/src/components/headless/forms/AGHeadlessInput.ts +21 -1
- package/src/components/headless/forms/AGHeadlessInput.vue +8 -5
- package/src/components/headless/forms/AGHeadlessInputInput.vue +2 -0
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
- package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
- package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
- package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
- package/src/components/headless/forms/index.ts +9 -1
- package/src/components/headless/index.ts +1 -0
- package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
- package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
- package/src/components/headless/modals/index.ts +4 -6
- package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
- package/src/components/headless/snackbars/index.ts +40 -0
- package/src/components/index.ts +3 -1
- package/src/components/lib/AGErrorMessage.vue +16 -0
- package/src/components/lib/AGLink.vue +9 -0
- package/src/components/{basic → lib}/AGMarkdown.vue +7 -6
- package/src/components/lib/AGMeasured.vue +15 -0
- package/src/components/lib/AGStartupCrash.vue +31 -0
- package/src/components/lib/index.ts +5 -0
- package/src/components/modals/AGAlertModal.ts +15 -0
- package/src/components/modals/AGAlertModal.vue +4 -16
- package/src/components/modals/AGConfirmModal.ts +27 -0
- package/src/components/modals/AGConfirmModal.vue +8 -12
- package/src/components/modals/AGErrorReportModal.ts +46 -0
- package/src/components/modals/AGErrorReportModal.vue +54 -0
- package/src/components/modals/AGErrorReportModalButtons.vue +111 -0
- package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
- package/src/components/modals/AGLoadingModal.ts +23 -0
- package/src/components/modals/AGLoadingModal.vue +4 -8
- package/src/components/modals/AGModal.ts +1 -1
- package/src/components/modals/AGModal.vue +16 -13
- package/src/components/modals/AGModalTitle.vue +9 -0
- package/src/components/modals/AGPromptModal.ts +30 -0
- package/src/components/modals/AGPromptModal.vue +34 -0
- package/src/components/modals/index.ts +16 -7
- package/src/components/snackbars/AGSnackbar.vue +36 -0
- package/src/components/snackbars/index.ts +3 -0
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +20 -3
- package/src/directives/measure.ts +21 -0
- package/src/errors/Errors.ts +65 -12
- package/src/errors/index.ts +26 -1
- package/src/errors/utils.ts +19 -0
- package/src/forms/Form.ts +15 -6
- package/src/jobs/Job.ts +5 -0
- package/src/jobs/index.ts +7 -0
- package/src/lang/Lang.ts +12 -24
- package/src/main.histoire.ts +1 -0
- package/src/main.ts +3 -2
- package/src/plugins/Plugin.ts +1 -0
- package/src/plugins/index.ts +19 -0
- package/src/services/App.state.ts +8 -4
- package/src/services/App.ts +35 -5
- package/src/services/Events.test.ts +39 -0
- package/src/services/Events.ts +100 -30
- package/src/services/Service.ts +55 -16
- package/src/services/index.ts +8 -4
- package/src/services/store.ts +8 -5
- package/src/testing/index.ts +25 -0
- package/src/ui/UI.state.ts +10 -1
- package/src/ui/UI.ts +160 -26
- package/src/ui/index.ts +12 -3
- package/src/utils/composition/events.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/markdown.ts +11 -2
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +15 -4
- package/tailwind.config.js +4 -0
- package/tsconfig.json +1 -0
- package/vite.config.ts +2 -1
- package/.eslintrc.js +0 -3
- package/src/components/basic/index.ts +0 -3
- package/src/globals.ts +0 -6
|
@@ -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 '../lib/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,23 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import type { ExtractPropTypes } from 'vue';
|
|
3
|
+
import type { ObjectWithoutEmpty } from '@noeldemartin/utils';
|
|
4
|
+
|
|
5
|
+
import { stringProp } from '@/utils';
|
|
6
|
+
import { translateWithDefault } from '@/lang';
|
|
7
|
+
|
|
8
|
+
export const loadingModalProps = {
|
|
9
|
+
message: stringProp(),
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type AGLoadingModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof loadingModalProps>>;
|
|
13
|
+
|
|
14
|
+
export function useLoadingModalProps(): typeof loadingModalProps {
|
|
15
|
+
return loadingModalProps;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
19
|
+
export function useLoadingModal(props: ExtractPropTypes<typeof loadingModalProps>) {
|
|
20
|
+
const renderedMessage = computed(() => props.message ?? translateWithDefault('ui.loading', 'Loading...'));
|
|
21
|
+
|
|
22
|
+
return { renderedMessage };
|
|
23
|
+
}
|
|
@@ -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 '../
|
|
11
|
+
import AGMarkdown from '../lib/AGMarkdown.vue';
|
|
16
12
|
|
|
17
|
-
const props = defineProps(
|
|
18
|
-
const renderedMessage =
|
|
13
|
+
const props = defineProps(useLoadingModalProps());
|
|
14
|
+
const { renderedMessage } = useLoadingModal(props);
|
|
19
15
|
</script>
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<AGHeadlessModal
|
|
3
|
-
ref="$
|
|
3
|
+
ref="$modal"
|
|
4
4
|
v-slot="{ close }: IAGHeadlessModalDefaultSlotProps"
|
|
5
|
-
|
|
5
|
+
v-bind="props"
|
|
6
6
|
class="relative z-50"
|
|
7
7
|
>
|
|
8
|
-
<div class="fixed inset-0 flex items-center justify-center">
|
|
9
|
-
<AGHeadlessModalPanel class="flex max-h-full max-w-full flex-col overflow-hidden bg-white">
|
|
10
|
-
<
|
|
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 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,21 +19,21 @@
|
|
|
16
19
|
</template>
|
|
17
20
|
|
|
18
21
|
<script setup lang="ts">
|
|
19
|
-
import {
|
|
22
|
+
import { ref } from 'vue';
|
|
20
23
|
|
|
21
|
-
import {
|
|
24
|
+
import { useModalExpose, useModalProps } from '@/components/headless/modals/AGHeadlessModal';
|
|
22
25
|
import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from '@/components/headless/modals/AGHeadlessModal';
|
|
23
26
|
|
|
24
27
|
import type { IAGModal } from './AGModal';
|
|
25
28
|
|
|
26
29
|
import AGHeadlessModal from '../headless/modals/AGHeadlessModal.vue';
|
|
27
30
|
import AGHeadlessModalPanel from '../headless/modals/AGHeadlessModalPanel.vue';
|
|
31
|
+
import AGHeadlessModalTitle from '../headless/modals/AGHeadlessModalTitle.vue';
|
|
32
|
+
import AGMarkdown from '../lib/AGMarkdown.vue';
|
|
28
33
|
|
|
29
|
-
const
|
|
34
|
+
const props = defineProps(useModalProps());
|
|
35
|
+
const $modal = ref<IAGHeadlessModal>();
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
defineExpose<IAGModal>(
|
|
33
|
-
close: async () => $headlessModal.value?.close(),
|
|
34
|
-
cancellable: computed(() => !!$headlessModal.value?.cancellable),
|
|
35
|
-
});
|
|
37
|
+
defineOptions({ inheritAttrs: false });
|
|
38
|
+
defineExpose<IAGModal>(useModalExpose($modal));
|
|
36
39
|
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
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 promptModalProps = {
|
|
9
|
+
title: stringProp(),
|
|
10
|
+
message: requiredStringProp(),
|
|
11
|
+
label: stringProp(),
|
|
12
|
+
defaultValue: stringProp(),
|
|
13
|
+
placeholder: stringProp(),
|
|
14
|
+
acceptText: stringProp(),
|
|
15
|
+
cancelText: stringProp(),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type AGPromptModalProps = ObjectWithoutEmpty<ExtractPropTypes<typeof promptModalProps>>;
|
|
19
|
+
|
|
20
|
+
export function usePromptModalProps(): typeof promptModalProps {
|
|
21
|
+
return promptModalProps;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
25
|
+
export function usePromptModal(props: ExtractPropTypes<typeof promptModalProps>) {
|
|
26
|
+
const renderedAcceptText = computed(() => props.acceptText ?? translateWithDefault('ui.accept', 'Ok'));
|
|
27
|
+
const renderedCancelText = computed(() => props.cancelText ?? translateWithDefault('ui.cancel', 'Cancel'));
|
|
28
|
+
|
|
29
|
+
return { renderedAcceptText, renderedCancelText };
|
|
30
|
+
}
|
|
@@ -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 submit>
|
|
10
|
+
{{ renderedAcceptText }}
|
|
11
|
+
</AGButton>
|
|
12
|
+
<AGButton color="secondary" @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,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export * from './AGAlertModal';
|
|
2
|
+
export * from './AGConfirmModal';
|
|
3
|
+
export * from './AGErrorReportModal';
|
|
4
|
+
export * from './AGLoadingModal';
|
|
5
|
+
export * from './AGModal';
|
|
6
|
+
export * from './AGModalContext';
|
|
7
|
+
export * from './AGPromptModal';
|
|
7
8
|
|
|
8
|
-
export {
|
|
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';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AGHeadlessSnackbar class="flex flex-row items-center justify-center gap-3 p-4" :class="styleClasses">
|
|
3
|
+
<AGMarkdown :text="message" inline />
|
|
4
|
+
<AGButton
|
|
5
|
+
v-for="(action, i) of actions"
|
|
6
|
+
:key="i"
|
|
7
|
+
:color="color"
|
|
8
|
+
@click="activate(action)"
|
|
9
|
+
>
|
|
10
|
+
{{ action.text }}
|
|
11
|
+
</AGButton>
|
|
12
|
+
</AGHeadlessSnackbar>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { computed } from 'vue';
|
|
17
|
+
|
|
18
|
+
import { Colors } from '@/components/constants';
|
|
19
|
+
import { useSnackbar, useSnackbarProps } from '@/components/headless/snackbars';
|
|
20
|
+
|
|
21
|
+
import AGButton from '../forms/AGButton.vue';
|
|
22
|
+
import AGHeadlessSnackbar from '../headless/snackbars/AGHeadlessSnackbar.vue';
|
|
23
|
+
import AGMarkdown from '../lib/AGMarkdown.vue';
|
|
24
|
+
|
|
25
|
+
const props = defineProps(useSnackbarProps());
|
|
26
|
+
const { activate } = useSnackbar(props);
|
|
27
|
+
const styleClasses = computed(() => {
|
|
28
|
+
switch (props.color) {
|
|
29
|
+
case Colors.Danger:
|
|
30
|
+
return 'bg-red-200 text-red-900';
|
|
31
|
+
default:
|
|
32
|
+
case Colors.Secondary:
|
|
33
|
+
return 'bg-gray-900 text-white';
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
</script>
|
|
@@ -0,0 +1,10 @@
|
|
|
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((extracted, prop) => {
|
|
6
|
+
extracted[prop] = values[prop];
|
|
7
|
+
|
|
8
|
+
return extracted;
|
|
9
|
+
}, {} as Record<string, unknown>) as T;
|
|
10
|
+
}
|
package/src/directives/index.ts
CHANGED
|
@@ -3,13 +3,30 @@ import type { Directive } from 'vue';
|
|
|
3
3
|
import { definePlugin } from '@/plugins';
|
|
4
4
|
|
|
5
5
|
import initialFocus from './initial-focus';
|
|
6
|
+
import measure from './measure';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const builtInDirectives: Record<string, Directive> = {
|
|
8
9
|
'initial-focus': initialFocus,
|
|
10
|
+
'measure': measure,
|
|
9
11
|
};
|
|
10
12
|
|
|
13
|
+
export * from './measure';
|
|
14
|
+
|
|
11
15
|
export default definePlugin({
|
|
12
|
-
install(app) {
|
|
13
|
-
|
|
16
|
+
install(app, options) {
|
|
17
|
+
const directives = {
|
|
18
|
+
...builtInDirectives,
|
|
19
|
+
...options.directives,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
for (const [name, directive] of Object.entries(directives)) {
|
|
23
|
+
app.directive(name, directive);
|
|
24
|
+
}
|
|
14
25
|
},
|
|
15
26
|
});
|
|
27
|
+
|
|
28
|
+
declare module '@/bootstrap/options' {
|
|
29
|
+
export interface AerogelOptions {
|
|
30
|
+
directives?: Record<string, Directive>;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineDirective } from '@/utils/vue';
|
|
2
|
+
|
|
3
|
+
export interface ElementSize {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type MeasureDirectiveListener = (size: ElementSize) => unknown;
|
|
9
|
+
|
|
10
|
+
export default defineDirective({
|
|
11
|
+
mounted(element: HTMLElement, { value }) {
|
|
12
|
+
const listener = typeof value === 'function' ? (value as MeasureDirectiveListener) : null;
|
|
13
|
+
const sizes = element.getBoundingClientRect();
|
|
14
|
+
|
|
15
|
+
// TODO guard with modifiers.css once typed properly
|
|
16
|
+
element.style.setProperty('--width', `${sizes.width}px`);
|
|
17
|
+
element.style.setProperty('--height', `${sizes.height}px`);
|
|
18
|
+
|
|
19
|
+
listener?.({ width: sizes.width, height: sizes.height });
|
|
20
|
+
},
|
|
21
|
+
});
|
package/src/errors/Errors.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { JSError, facade, isObject } from '@noeldemartin/utils';
|
|
1
|
+
import { JSError, facade, isObject, objectWithoutEmpty, toString } from '@noeldemartin/utils';
|
|
2
2
|
|
|
3
3
|
import App from '@/services/App';
|
|
4
4
|
import ServiceBootError from '@/errors/ServiceBootError';
|
|
5
|
-
import UI from '@/ui/UI';
|
|
6
|
-
import {
|
|
5
|
+
import UI, { UIComponents } from '@/ui/UI';
|
|
6
|
+
import { translateWithDefault } from '@/lang/utils';
|
|
7
7
|
|
|
8
8
|
import Service from './Errors.state';
|
|
9
|
+
import { Colors } from '@/components/constants';
|
|
10
|
+
import { Events } from '@/services';
|
|
11
|
+
import type { AGErrorReportModalProps } from '@/components/modals/AGErrorReportModal';
|
|
9
12
|
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
13
|
+
import type { ModalComponent } from '@/ui/UI.state';
|
|
10
14
|
|
|
11
15
|
export class ErrorsService extends Service {
|
|
12
16
|
|
|
@@ -22,14 +26,27 @@ export class ErrorsService extends Service {
|
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
public async inspect(error: ErrorSource | ErrorReport[]): Promise<void> {
|
|
25
|
-
const reports = Array.isArray(error) ? error : [await this.createErrorReport(error)];
|
|
29
|
+
const reports = Array.isArray(error) ? (error as ErrorReport[]) : [await this.createErrorReport(error)];
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
if (reports.length === 0) {
|
|
32
|
+
UI.alert(translateWithDefault('errors.inspectEmpty', 'Nothing to inspect!'));
|
|
33
|
+
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
UI.openModal<ModalComponent<AGErrorReportModalProps>>(UI.requireComponent(UIComponents.ErrorReportModal), {
|
|
38
|
+
reports,
|
|
39
|
+
});
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
public async report(error: ErrorSource, message?: string): Promise<void> {
|
|
32
|
-
|
|
43
|
+
await Events.emit('error', { error, message });
|
|
44
|
+
|
|
45
|
+
if (App.testing) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (App.development) {
|
|
33
50
|
this.logError(error);
|
|
34
51
|
}
|
|
35
52
|
|
|
@@ -37,7 +54,7 @@ export class ErrorsService extends Service {
|
|
|
37
54
|
throw error;
|
|
38
55
|
}
|
|
39
56
|
|
|
40
|
-
if (!App.isMounted) {
|
|
57
|
+
if (!App.isMounted()) {
|
|
41
58
|
const startupError = await this.createStartupErrorReport(error);
|
|
42
59
|
|
|
43
60
|
if (startupError) {
|
|
@@ -54,8 +71,24 @@ export class ErrorsService extends Service {
|
|
|
54
71
|
date: new Date(),
|
|
55
72
|
};
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
UI.showSnackbar(
|
|
75
|
+
message ??
|
|
76
|
+
translateWithDefault('errors.notice', 'Something went wrong, but it\'s not your fault. Try again!'),
|
|
77
|
+
{
|
|
78
|
+
color: Colors.Danger,
|
|
79
|
+
actions: [
|
|
80
|
+
{
|
|
81
|
+
text: translateWithDefault('errors.viewDetails', 'View details'),
|
|
82
|
+
dismiss: true,
|
|
83
|
+
handler: () =>
|
|
84
|
+
UI.openModal<ModalComponent<AGErrorReportModalProps>>(
|
|
85
|
+
UI.requireComponent(UIComponents.ErrorReportModal),
|
|
86
|
+
{ reports: [report] },
|
|
87
|
+
),
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
);
|
|
59
92
|
|
|
60
93
|
this.setState({ logs: [log].concat(this.logs) });
|
|
61
94
|
}
|
|
@@ -102,8 +135,22 @@ export class ErrorsService extends Service {
|
|
|
102
135
|
return this.createErrorReportFromError(error);
|
|
103
136
|
}
|
|
104
137
|
|
|
138
|
+
if (isObject(error)) {
|
|
139
|
+
return objectWithoutEmpty({
|
|
140
|
+
title: toString(
|
|
141
|
+
error['name'] ?? error['title'] ?? translateWithDefault('errors.unknown', 'Unknown Error'),
|
|
142
|
+
),
|
|
143
|
+
description: toString(
|
|
144
|
+
error['message'] ??
|
|
145
|
+
error['description'] ??
|
|
146
|
+
translateWithDefault('errors.unknownDescription', 'Unknown error object'),
|
|
147
|
+
),
|
|
148
|
+
error,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
105
152
|
return {
|
|
106
|
-
title:
|
|
153
|
+
title: translateWithDefault('errors.unknown', 'Unknown Error'),
|
|
107
154
|
error,
|
|
108
155
|
};
|
|
109
156
|
}
|
|
@@ -129,4 +176,10 @@ export class ErrorsService extends Service {
|
|
|
129
176
|
|
|
130
177
|
}
|
|
131
178
|
|
|
132
|
-
export default facade(
|
|
179
|
+
export default facade(ErrorsService);
|
|
180
|
+
|
|
181
|
+
declare module '@/services/Events' {
|
|
182
|
+
export interface EventsPayload {
|
|
183
|
+
error: { error: ErrorSource; message?: string };
|
|
184
|
+
}
|
|
185
|
+
}
|
package/src/errors/index.ts
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
|
+
import type { App } from 'vue';
|
|
2
|
+
|
|
1
3
|
import { bootServices } from '@/services';
|
|
2
4
|
import { definePlugin } from '@/plugins';
|
|
3
5
|
|
|
4
6
|
import Errors from './Errors';
|
|
5
7
|
import { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
6
8
|
|
|
9
|
+
export * from './utils';
|
|
7
10
|
export { Errors, ErrorSource, ErrorReport, ErrorReportLog };
|
|
8
11
|
|
|
9
12
|
const services = { $errors: Errors };
|
|
13
|
+
const frameworkHandler: ErrorHandler = (error) => {
|
|
14
|
+
Errors.report(error);
|
|
15
|
+
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function setUpErrorHandler(app: App, baseHandler: ErrorHandler = () => false): void {
|
|
20
|
+
const errorHandler: ErrorHandler = (error) => baseHandler(error) || frameworkHandler(error);
|
|
21
|
+
|
|
22
|
+
app.config.errorHandler = errorHandler;
|
|
23
|
+
globalThis.onerror = (event, _, __, ___, error) => errorHandler(error ?? event);
|
|
24
|
+
globalThis.onunhandledrejection = (event) => errorHandler(event.reason);
|
|
25
|
+
}
|
|
10
26
|
|
|
27
|
+
export type ErrorHandler = (error: ErrorSource) => boolean;
|
|
11
28
|
export type ErrorsServices = typeof services;
|
|
12
29
|
|
|
13
30
|
export default definePlugin({
|
|
14
|
-
async install(app) {
|
|
31
|
+
async install(app, options) {
|
|
32
|
+
setUpErrorHandler(app, options.handleError);
|
|
33
|
+
|
|
15
34
|
await bootServices(app, services);
|
|
16
35
|
},
|
|
17
36
|
});
|
|
18
37
|
|
|
38
|
+
declare module '@/bootstrap/options' {
|
|
39
|
+
export interface AerogelOptions {
|
|
40
|
+
handleError?(error: ErrorSource): boolean;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
19
44
|
declare module '@/services' {
|
|
20
45
|
export interface Services extends ErrorsServices {}
|
|
21
46
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JSError, isObject, toString } from '@noeldemartin/utils';
|
|
2
|
+
import { translateWithDefault } from '@/lang/utils';
|
|
3
|
+
import type { ErrorSource } from './Errors.state';
|
|
4
|
+
|
|
5
|
+
export function getErrorMessage(error: ErrorSource): string {
|
|
6
|
+
if (typeof error === 'string') {
|
|
7
|
+
return error;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (error instanceof Error || error instanceof JSError) {
|
|
11
|
+
return error.message;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (isObject(error)) {
|
|
15
|
+
return toString(error['message'] ?? error['description'] ?? 'Unknown error object');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return translateWithDefault('errors.unknown', 'Unknown Error');
|
|
19
|
+
}
|
package/src/forms/Form.ts
CHANGED
|
@@ -7,6 +7,7 @@ export const FormFieldTypes = {
|
|
|
7
7
|
String: 'string',
|
|
8
8
|
Number: 'number',
|
|
9
9
|
Boolean: 'boolean',
|
|
10
|
+
Object: 'object',
|
|
10
11
|
} as const;
|
|
11
12
|
|
|
12
13
|
export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType, TRules extends string = string> {
|
|
@@ -17,6 +18,7 @@ export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType
|
|
|
17
18
|
|
|
18
19
|
export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
|
|
19
20
|
export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
|
|
21
|
+
export type FormFieldValue = GetFormFieldValue<FormFieldType>;
|
|
20
22
|
|
|
21
23
|
export type FormData<T> = {
|
|
22
24
|
-readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
|
|
@@ -36,15 +38,18 @@ export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.Strin
|
|
|
36
38
|
? number
|
|
37
39
|
: TType extends typeof FormFieldTypes.Boolean
|
|
38
40
|
? boolean
|
|
41
|
+
: TType extends typeof FormFieldTypes.Object
|
|
42
|
+
? object
|
|
39
43
|
: never;
|
|
40
44
|
|
|
45
|
+
const validForms: WeakMap<Form, ComputedRef<boolean>> = new WeakMap();
|
|
46
|
+
|
|
41
47
|
export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
|
|
42
48
|
|
|
43
49
|
public errors: DeepReadonly<UnwrapNestedRefs<FormErrors<Fields>>>;
|
|
44
50
|
|
|
45
51
|
private _fields: Fields;
|
|
46
52
|
private _data: FormData<Fields>;
|
|
47
|
-
private _valid: ComputedRef<boolean>;
|
|
48
53
|
private _submitted: Ref<boolean>;
|
|
49
54
|
private _errors: FormErrors<Fields>;
|
|
50
55
|
|
|
@@ -55,13 +60,17 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
55
60
|
this._submitted = ref(false);
|
|
56
61
|
this._data = this.getInitialData(fields);
|
|
57
62
|
this._errors = this.getInitialErrors(fields);
|
|
58
|
-
|
|
63
|
+
|
|
64
|
+
validForms.set(
|
|
65
|
+
this,
|
|
66
|
+
computed(() => !Object.values(this._errors).some((error) => error !== null)),
|
|
67
|
+
);
|
|
59
68
|
|
|
60
69
|
this.errors = readonly(this._errors);
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
public get valid(): boolean {
|
|
64
|
-
return this
|
|
73
|
+
return !!validForms.get(this)?.value;
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
public get submitted(): boolean {
|
|
@@ -92,11 +101,11 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
92
101
|
return this.valid;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
public reset(): void {
|
|
104
|
+
public reset(options: { keepData?: boolean; keepErrors?: boolean } = {}): void {
|
|
96
105
|
this._submitted.value = false;
|
|
97
106
|
|
|
98
|
-
this.resetData();
|
|
99
|
-
this.resetErrors();
|
|
107
|
+
options.keepData || this.resetData();
|
|
108
|
+
options.keepErrors || this.resetErrors();
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
public submit(): boolean {
|
package/src/jobs/Job.ts
ADDED