@aerogel/core 0.0.0-next.980a397d575dcb5ff8c5a0bff769d09f938ea03c → 0.0.0-next.9f9564ab9f8da05f60d7868db361edbc5601ee39
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 +689 -140
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/bootstrap/bootstrap.test.ts +3 -3
- package/src/bootstrap/index.ts +16 -5
- package/src/bootstrap/options.ts +3 -0
- package/src/components/AGAppLayout.vue +3 -2
- package/src/components/AGAppOverlays.vue +5 -1
- package/src/components/AGAppSnackbars.vue +1 -1
- package/src/components/forms/AGCheckbox.vue +7 -1
- package/src/components/forms/AGForm.vue +9 -10
- package/src/components/forms/AGInput.vue +10 -6
- package/src/components/forms/AGSelect.story.vue +21 -3
- package/src/components/forms/AGSelect.vue +10 -3
- package/src/components/headless/forms/AGHeadlessButton.vue +17 -12
- package/src/components/headless/forms/AGHeadlessInput.ts +12 -13
- package/src/components/headless/forms/AGHeadlessInput.vue +3 -3
- package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
- package/src/components/headless/forms/AGHeadlessInputInput.vue +40 -4
- package/src/components/headless/forms/AGHeadlessInputTextArea.vue +40 -0
- package/src/components/headless/forms/AGHeadlessSelect.ts +20 -22
- package/src/components/headless/forms/AGHeadlessSelect.vue +23 -22
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +6 -6
- package/src/components/headless/forms/composition.ts +10 -0
- package/src/components/headless/forms/index.ts +3 -0
- package/src/components/headless/modals/AGHeadlessModal.ts +19 -1
- package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
- package/src/components/headless/snackbars/index.ts +23 -8
- package/src/components/lib/AGErrorMessage.vue +2 -2
- package/src/components/lib/AGMarkdown.vue +9 -4
- package/src/components/lib/AGMeasured.vue +15 -0
- package/src/components/lib/index.ts +1 -0
- package/src/components/modals/AGAlertModal.ts +15 -0
- package/src/components/modals/AGAlertModal.vue +3 -14
- package/src/components/modals/AGConfirmModal.ts +17 -0
- package/src/components/modals/AGConfirmModal.vue +6 -10
- package/src/components/modals/AGErrorReportModal.ts +27 -1
- package/src/components/modals/AGErrorReportModal.vue +7 -15
- package/src/components/modals/AGErrorReportModalButtons.vue +4 -2
- package/src/components/modals/AGLoadingModal.ts +14 -0
- package/src/components/modals/AGLoadingModal.vue +3 -7
- package/src/components/modals/AGModal.vue +14 -12
- package/src/components/modals/AGPromptModal.ts +30 -0
- package/src/components/modals/AGPromptModal.vue +34 -0
- package/src/components/modals/index.ts +11 -19
- package/src/components/snackbars/AGSnackbar.vue +2 -8
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +5 -1
- package/src/directives/measure.ts +21 -0
- package/src/errors/Errors.ts +26 -24
- package/src/errors/index.ts +2 -11
- package/src/errors/utils.ts +19 -0
- package/src/forms/Form.ts +43 -3
- package/src/forms/index.ts +1 -0
- package/src/forms/utils.ts +15 -0
- package/src/jobs/Job.ts +5 -0
- package/src/jobs/index.ts +7 -0
- package/src/lang/Lang.ts +14 -22
- package/src/main.ts +3 -0
- package/src/services/App.state.ts +1 -2
- package/src/services/App.ts +21 -3
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.test.ts +39 -0
- package/src/services/Events.ts +100 -30
- package/src/services/Service.ts +42 -12
- package/src/services/index.ts +5 -2
- package/src/services/store.ts +8 -5
- package/src/testing/index.ts +25 -0
- package/src/ui/UI.ts +101 -15
- package/src/ui/index.ts +8 -3
- package/src/utils/composition/events.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +10 -1
|
@@ -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
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
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
|
-
<
|
|
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,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
37
|
defineOptions({ inheritAttrs: false });
|
|
32
|
-
|
|
33
|
-
defineExpose<IAGModal>({
|
|
34
|
-
close: async () => $headlessModal.value?.close(),
|
|
35
|
-
cancellable: computed(() => !!$headlessModal.value?.cancellable),
|
|
36
|
-
});
|
|
38
|
+
defineExpose<IAGModal>(useModalExpose($modal));
|
|
37
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,25 +1,17 @@
|
|
|
1
|
-
|
|
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';
|
|
10
2
|
export * from './AGConfirmModal';
|
|
11
3
|
export * from './AGErrorReportModal';
|
|
12
4
|
export * from './AGLoadingModal';
|
|
13
5
|
export * from './AGModal';
|
|
14
6
|
export * from './AGModalContext';
|
|
7
|
+
export * from './AGPromptModal';
|
|
15
8
|
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
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
18
|
import { Colors } from '@/components/constants';
|
|
20
|
-
import { useSnackbarProps } from '@/components/headless';
|
|
21
|
-
import type { SnackbarAction } from '@/components/headless';
|
|
19
|
+
import { useSnackbar, useSnackbarProps } from '@/components/headless/snackbars';
|
|
22
20
|
|
|
23
21
|
import AGButton from '../forms/AGButton.vue';
|
|
24
22
|
import AGHeadlessSnackbar from '../headless/snackbars/AGHeadlessSnackbar.vue';
|
|
25
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,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,11 +3,15 @@ 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
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
16
|
install(app, options) {
|
|
13
17
|
const directives = {
|
|
@@ -22,7 +26,7 @@ export default definePlugin({
|
|
|
22
26
|
});
|
|
23
27
|
|
|
24
28
|
declare module '@/bootstrap/options' {
|
|
25
|
-
interface AerogelOptions {
|
|
29
|
+
export interface AerogelOptions {
|
|
26
30
|
directives?: Record<string, Directive>;
|
|
27
31
|
}
|
|
28
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
|
@@ -7,7 +7,10 @@ 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';
|
|
11
|
+
import type { AGErrorReportModalProps } from '@/components/modals/AGErrorReportModal';
|
|
10
12
|
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
13
|
+
import type { ModalComponent } from '@/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), {
|
|
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
|
-
|
|
43
|
+
await Events.emit('error', { error, message });
|
|
44
|
+
|
|
45
|
+
if (App.testing) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (App.development) {
|
|
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(
|
|
74
|
-
|
|
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(
|
|
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
|
@@ -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;
|
|
@@ -45,7 +36,7 @@ export default definePlugin({
|
|
|
45
36
|
});
|
|
46
37
|
|
|
47
38
|
declare module '@/bootstrap/options' {
|
|
48
|
-
interface AerogelOptions {
|
|
39
|
+
export interface AerogelOptions {
|
|
49
40
|
handleError?(error: ErrorSource): boolean;
|
|
50
41
|
}
|
|
51
42
|
}
|
|
@@ -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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MagicObject } from '@noeldemartin/utils';
|
|
2
|
-
import { computed, reactive, readonly, ref } from 'vue';
|
|
1
|
+
import { MagicObject, arrayRemove } from '@noeldemartin/utils';
|
|
2
|
+
import { computed, nextTick, reactive, readonly, ref } from 'vue';
|
|
3
3
|
import type { ObjectValues } from '@noeldemartin/utils';
|
|
4
4
|
import type { ComputedRef, DeepReadonly, Ref, UnwrapNestedRefs } from 'vue';
|
|
5
5
|
|
|
@@ -8,6 +8,7 @@ export const FormFieldTypes = {
|
|
|
8
8
|
Number: 'number',
|
|
9
9
|
Boolean: 'boolean',
|
|
10
10
|
Object: 'object',
|
|
11
|
+
Date: 'date',
|
|
11
12
|
} as const;
|
|
12
13
|
|
|
13
14
|
export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType, TRules extends string = string> {
|
|
@@ -18,6 +19,7 @@ export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType
|
|
|
18
19
|
|
|
19
20
|
export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
|
|
20
21
|
export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
|
|
22
|
+
export type FormFieldValue = GetFormFieldValue<FormFieldType>;
|
|
21
23
|
|
|
22
24
|
export type FormData<T> = {
|
|
23
25
|
-readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
|
|
@@ -39,10 +41,15 @@ export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.Strin
|
|
|
39
41
|
? boolean
|
|
40
42
|
: TType extends typeof FormFieldTypes.Object
|
|
41
43
|
? object
|
|
44
|
+
: TType extends typeof FormFieldTypes.Date
|
|
45
|
+
? Date
|
|
42
46
|
: never;
|
|
43
47
|
|
|
44
48
|
const validForms: WeakMap<Form, ComputedRef<boolean>> = new WeakMap();
|
|
45
49
|
|
|
50
|
+
export type SubmitFormListener = () => unknown;
|
|
51
|
+
export type FocusFormListener = (input: string) => unknown;
|
|
52
|
+
|
|
46
53
|
export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
|
|
47
54
|
|
|
48
55
|
public errors: DeepReadonly<UnwrapNestedRefs<FormErrors<Fields>>>;
|
|
@@ -51,6 +58,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
51
58
|
private _data: FormData<Fields>;
|
|
52
59
|
private _submitted: Ref<boolean>;
|
|
53
60
|
private _errors: FormErrors<Fields>;
|
|
61
|
+
private _listeners: { focus?: FocusFormListener[]; submit?: SubmitFormListener[] } = {};
|
|
54
62
|
|
|
55
63
|
constructor(fields: Fields) {
|
|
56
64
|
super();
|
|
@@ -88,6 +96,10 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
88
96
|
return this._data[field] as unknown as GetFormFieldValue<Fields[T]['type']>;
|
|
89
97
|
}
|
|
90
98
|
|
|
99
|
+
public data(): FormData<Fields> {
|
|
100
|
+
return { ...this._data };
|
|
101
|
+
}
|
|
102
|
+
|
|
91
103
|
public validate(): boolean {
|
|
92
104
|
const errors = Object.entries(this._fields).reduce((formErrors, [name, definition]) => {
|
|
93
105
|
formErrors[name] = this.getFieldErrors(name, definition);
|
|
@@ -110,7 +122,35 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
110
122
|
public submit(): boolean {
|
|
111
123
|
this._submitted.value = true;
|
|
112
124
|
|
|
113
|
-
|
|
125
|
+
const valid = this.validate();
|
|
126
|
+
|
|
127
|
+
valid && this._listeners['submit']?.forEach((listener) => listener());
|
|
128
|
+
|
|
129
|
+
return valid;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public on(event: 'focus', listener: FocusFormListener): () => void;
|
|
133
|
+
public on(event: 'submit', listener: SubmitFormListener): () => void;
|
|
134
|
+
public on(event: 'focus' | 'submit', listener: FocusFormListener | SubmitFormListener): () => void {
|
|
135
|
+
this._listeners[event] ??= [];
|
|
136
|
+
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
|
+
this._listeners[event]?.push(listener as any);
|
|
139
|
+
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
return () => this.off(event as any, listener);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public off(event: 'focus', listener: FocusFormListener): void;
|
|
145
|
+
public off(event: 'submit', listener: SubmitFormListener): void;
|
|
146
|
+
public off(event: 'focus' | 'submit', listener: FocusFormListener | SubmitFormListener): void {
|
|
147
|
+
arrayRemove(this._listeners[event] ?? [], listener);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public async focus(input: string): Promise<void> {
|
|
151
|
+
await nextTick();
|
|
152
|
+
|
|
153
|
+
this._listeners['focus']?.forEach((listener) => listener(input));
|
|
114
154
|
}
|
|
115
155
|
|
|
116
156
|
protected __get(property: string): unknown {
|
package/src/forms/index.ts
CHANGED
package/src/forms/utils.ts
CHANGED
|
@@ -8,6 +8,13 @@ export function booleanInput(defaultValue?: boolean): FormFieldDefinition<typeof
|
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export function dateInput(defaultValue?: Date): FormFieldDefinition<typeof FormFieldTypes.Date> {
|
|
12
|
+
return {
|
|
13
|
+
default: defaultValue,
|
|
14
|
+
type: FormFieldTypes.Date,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
export function requiredBooleanInput(
|
|
12
19
|
defaultValue?: boolean,
|
|
13
20
|
): FormFieldDefinition<typeof FormFieldTypes.Boolean, 'required'> {
|
|
@@ -18,6 +25,14 @@ export function requiredBooleanInput(
|
|
|
18
25
|
};
|
|
19
26
|
}
|
|
20
27
|
|
|
28
|
+
export function requiredDateInput(defaultValue?: Date): FormFieldDefinition<typeof FormFieldTypes.Date> {
|
|
29
|
+
return {
|
|
30
|
+
default: defaultValue,
|
|
31
|
+
type: FormFieldTypes.Date,
|
|
32
|
+
rules: 'required',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
export function requiredNumberInput(
|
|
22
37
|
defaultValue?: number,
|
|
23
38
|
): FormFieldDefinition<typeof FormFieldTypes.Number, 'required'> {
|
package/src/jobs/Job.ts
ADDED
package/src/lang/Lang.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { facade
|
|
1
|
+
import { facade } from '@noeldemartin/utils';
|
|
2
2
|
|
|
3
3
|
import App from '@/services/App';
|
|
4
4
|
import Service from '@/services/Service';
|
|
5
5
|
|
|
6
6
|
export interface LangProvider {
|
|
7
|
-
translate(key: string, parameters?: Record<string, unknown>): string;
|
|
7
|
+
translate(key: string, parameters?: Record<string, unknown> | number): string;
|
|
8
|
+
translateWithDefault(key: string, defaultMessage: string, parameters?: Record<string, unknown> | number): string;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export class LangService extends Service {
|
|
@@ -21,6 +22,12 @@ export class LangService extends Service {
|
|
|
21
22
|
|
|
22
23
|
return key;
|
|
23
24
|
},
|
|
25
|
+
translateWithDefault: (_, defaultMessage) => {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
App.development && console.warn('Lang provider is missing');
|
|
28
|
+
|
|
29
|
+
return defaultMessage;
|
|
30
|
+
},
|
|
24
31
|
};
|
|
25
32
|
}
|
|
26
33
|
|
|
@@ -28,33 +35,18 @@ export class LangService extends Service {
|
|
|
28
35
|
this.provider = provider;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
|
-
public translate(key: string, parameters?: Record<string, unknown>): string {
|
|
38
|
+
public translate(key: string, parameters?: Record<string, unknown> | number): string {
|
|
32
39
|
return this.provider.translate(key, parameters) ?? key;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
public translateWithDefault(key: string, defaultMessage: string): string;
|
|
36
|
-
public translateWithDefault(key: string, parameters: Record<string, unknown>, defaultMessage: string): string;
|
|
37
42
|
public translateWithDefault(
|
|
38
43
|
key: string,
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
defaultMessage: string,
|
|
45
|
+
parameters: Record<string, unknown> | number = {},
|
|
41
46
|
): string {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const parameters = typeof defaultMessageOrParameters === 'string' ? {} : defaultMessageOrParameters ?? {};
|
|
45
|
-
const message = this.provider.translate(key, parameters) ?? key;
|
|
46
|
-
|
|
47
|
-
if (message === key) {
|
|
48
|
-
return Object.entries(parameters).reduce(
|
|
49
|
-
(renderedMessage, [name, value]) =>
|
|
50
|
-
renderedMessage.replace(new RegExp(`\\{\\s*${name}\\s*\\}`, 'g'), toString(value)),
|
|
51
|
-
defaultMessage,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return message;
|
|
47
|
+
return this.provider.translateWithDefault(key, defaultMessage, parameters);
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
}
|
|
59
51
|
|
|
60
|
-
export default facade(
|
|
52
|
+
export default facade(LangService);
|
package/src/main.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from './bootstrap';
|
|
2
2
|
export * from './components';
|
|
3
|
+
export * from './directives';
|
|
3
4
|
export * from './errors';
|
|
4
5
|
export * from './forms';
|
|
6
|
+
export * from './jobs';
|
|
5
7
|
export * from './lang';
|
|
6
8
|
export * from './plugins';
|
|
7
9
|
export * from './services';
|
|
10
|
+
export * from './testing';
|
|
8
11
|
export * from './ui';
|
|
9
12
|
export * from './utils';
|
|
@@ -9,10 +9,9 @@ export default defineServiceState({
|
|
|
9
9
|
plugins: {} as Record<string, Plugin>,
|
|
10
10
|
environment: Aerogel.environment,
|
|
11
11
|
sourceUrl: Aerogel.sourceUrl,
|
|
12
|
-
isMounted: false,
|
|
13
12
|
},
|
|
14
13
|
computed: {
|
|
15
14
|
development: (state) => state.environment === 'development',
|
|
16
|
-
testing: (state) => state.environment === 'testing',
|
|
15
|
+
testing: (state) => state.environment === 'test' || state.environment === 'testing',
|
|
17
16
|
},
|
|
18
17
|
});
|