@aerogel/core 0.0.0-next.c2e6acc000e97a1020c2e232678563c53884dd0e → 0.0.0-next.c3236837f7f8fc319a4a56022accb32757b3db89
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.css +1 -0
- package/dist/aerogel-core.d.ts +1267 -599
- package/dist/aerogel-core.js +2560 -1859
- package/dist/aerogel-core.js.map +1 -1
- package/package.json +7 -2
- package/src/components/AppLayout.vue +1 -3
- package/src/components/AppModals.vue +1 -1
- package/src/components/AppOverlays.vue +2 -34
- package/src/components/AppToasts.vue +16 -0
- package/src/components/contracts/AlertModal.ts +15 -0
- package/src/components/contracts/Button.ts +1 -0
- package/src/components/contracts/ConfirmModal.ts +12 -5
- package/src/components/contracts/DropdownMenu.ts +25 -0
- package/src/components/contracts/ErrorReportModal.ts +8 -4
- package/src/components/contracts/Input.ts +9 -9
- package/src/components/contracts/LoadingModal.ts +12 -4
- package/src/components/contracts/Modal.ts +14 -2
- package/src/components/contracts/PromptModal.ts +8 -2
- package/src/components/contracts/Select.ts +45 -0
- package/src/components/contracts/Toast.ts +15 -0
- package/src/components/contracts/index.ts +5 -1
- package/src/components/headless/HeadlessButton.vue +9 -3
- package/src/components/headless/HeadlessInput.vue +3 -3
- package/src/components/headless/HeadlessInputDescription.vue +1 -1
- package/src/components/headless/HeadlessInputInput.vue +21 -10
- package/src/components/headless/HeadlessInputTextArea.vue +6 -6
- package/src/components/headless/HeadlessModal.vue +23 -50
- package/src/components/headless/HeadlessModalContent.vue +11 -5
- package/src/components/headless/HeadlessModalDescription.vue +12 -0
- package/src/components/headless/HeadlessModalOverlay.vue +2 -2
- package/src/components/headless/HeadlessModalTitle.vue +2 -2
- package/src/components/headless/HeadlessSelect.vue +120 -0
- package/src/components/headless/{forms/AGHeadlessSelectError.vue → HeadlessSelectError.vue} +3 -4
- package/src/components/headless/HeadlessSelectLabel.vue +25 -0
- package/src/components/headless/HeadlessSelectOption.vue +34 -0
- package/src/components/headless/HeadlessSelectOptions.vue +42 -0
- package/src/components/headless/HeadlessSelectTrigger.vue +22 -0
- package/src/components/headless/HeadlessSelectValue.vue +18 -0
- package/src/components/headless/HeadlessSwitch.vue +96 -0
- package/src/components/headless/HeadlessToast.vue +18 -0
- package/src/components/headless/HeadlessToastAction.vue +13 -0
- package/src/components/headless/index.ts +9 -3
- package/src/components/index.ts +4 -9
- package/src/components/ui/AdvancedOptions.vue +18 -0
- package/src/components/ui/AlertModal.vue +7 -3
- package/src/components/ui/Button.vue +74 -17
- package/src/components/ui/Checkbox.vue +21 -14
- package/src/components/ui/ConfirmModal.vue +14 -6
- package/src/components/ui/DropdownMenu.vue +32 -0
- package/src/components/ui/DropdownMenuOption.vue +22 -0
- package/src/components/ui/DropdownMenuOptions.vue +44 -0
- package/src/components/ui/EditableContent.vue +82 -0
- package/src/components/ui/ErrorLogs.vue +19 -0
- package/src/components/ui/ErrorLogsModal.vue +48 -0
- package/src/components/{lib/AGErrorMessage.vue → ui/ErrorMessage.vue} +2 -3
- package/src/components/ui/ErrorReportModal.vue +18 -7
- package/src/components/ui/ErrorReportModalButtons.vue +6 -8
- package/src/components/ui/ErrorReportModalTitle.vue +1 -1
- package/src/components/ui/Input.vue +11 -7
- package/src/components/ui/Link.vue +2 -2
- package/src/components/ui/LoadingModal.vue +8 -6
- package/src/components/ui/Markdown.vue +41 -6
- package/src/components/ui/Modal.vue +95 -19
- package/src/components/ui/ModalContext.vue +2 -1
- package/src/components/ui/ProgressBar.vue +9 -8
- package/src/components/ui/PromptModal.vue +11 -8
- package/src/components/ui/Select.vue +27 -0
- package/src/components/ui/SelectLabel.vue +21 -0
- package/src/components/ui/SelectOption.vue +29 -0
- package/src/components/ui/SelectOptions.vue +35 -0
- package/src/components/ui/SelectTrigger.vue +29 -0
- package/src/components/ui/Setting.vue +31 -0
- package/src/components/ui/SettingsModal.vue +15 -0
- package/src/components/ui/Switch.vue +11 -0
- package/src/components/ui/TextArea.vue +56 -0
- package/src/components/ui/Toast.vue +46 -0
- package/src/components/ui/index.ts +19 -0
- package/src/directives/measure.ts +11 -5
- package/src/errors/Errors.ts +21 -19
- package/src/errors/index.ts +6 -2
- package/src/errors/settings/Debug.vue +32 -0
- package/src/errors/settings/index.ts +10 -0
- package/src/forms/FormController.test.ts +32 -9
- package/src/forms/FormController.ts +27 -22
- package/src/forms/index.ts +0 -1
- package/src/forms/utils.ts +34 -34
- package/src/index.css +70 -3
- package/src/lang/index.ts +5 -1
- package/src/lang/settings/Language.vue +48 -0
- package/src/lang/settings/index.ts +10 -0
- package/src/services/App.state.ts +11 -1
- package/src/services/App.ts +9 -1
- package/src/services/Events.test.ts +8 -8
- package/src/services/Events.ts +2 -8
- package/src/services/index.ts +5 -2
- package/src/testing/index.ts +4 -0
- package/src/ui/UI.state.ts +5 -15
- package/src/ui/UI.ts +115 -99
- package/src/ui/index.ts +18 -19
- package/src/utils/classes.ts +41 -0
- package/src/utils/composition/events.ts +2 -4
- package/src/utils/composition/forms.ts +16 -1
- package/src/utils/composition/state.ts +11 -2
- package/src/utils/index.ts +3 -1
- package/src/utils/markdown.ts +35 -1
- package/src/utils/types.ts +3 -0
- package/src/utils/vue.ts +28 -129
- package/src/components/AppSnackbars.vue +0 -13
- package/src/components/composition.ts +0 -23
- package/src/components/constants.ts +0 -8
- package/src/components/contracts/shared.ts +0 -9
- package/src/components/forms/AGSelect.story.vue +0 -46
- package/src/components/forms/AGSelect.vue +0 -54
- package/src/components/forms/index.ts +0 -1
- package/src/components/headless/forms/AGHeadlessSelect.ts +0 -42
- package/src/components/headless/forms/AGHeadlessSelect.vue +0 -77
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +0 -4
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +0 -31
- package/src/components/headless/forms/AGHeadlessSelectOptions.vue +0 -19
- package/src/components/headless/forms/AGHeadlessSelectTrigger.vue +0 -25
- package/src/components/headless/forms/composition.ts +0 -10
- package/src/components/headless/forms/index.ts +0 -8
- package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +0 -10
- package/src/components/headless/snackbars/index.ts +0 -40
- package/src/components/lib/AGMeasured.vue +0 -16
- package/src/components/lib/index.ts +0 -3
- package/src/components/snackbars/AGSnackbar.vue +0 -38
- package/src/components/snackbars/index.ts +0 -3
- package/src/components/utils.ts +0 -107
- package/src/forms/composition.ts +0 -6
- package/src/utils/tailwindcss.test.ts +0 -26
- package/src/utils/tailwindcss.ts +0 -7
- package/src/utils/vdom.ts +0 -31
- /package/src/components/{lib/AGStartupCrash.vue → ui/StartupCrash.vue} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<HeadlessInput
|
|
3
|
+
ref="$inputRef"
|
|
4
|
+
:label="label"
|
|
5
|
+
:class="rootClasses"
|
|
6
|
+
v-bind="props"
|
|
7
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
8
|
+
>
|
|
9
|
+
<HeadlessInputLabel class="block text-sm leading-6 font-medium text-gray-900" />
|
|
10
|
+
<div :class="renderedWrapperClasses">
|
|
11
|
+
<HeadlessInputTextArea v-bind="inputAttrs" :class="renderedInputClasses" />
|
|
12
|
+
<div v-if="$input?.errors" class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
|
|
13
|
+
<IconExclamationSolid class="size-5 text-red-500" />
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
<HeadlessInputDescription class="mt-2 text-sm text-gray-600" />
|
|
17
|
+
<HeadlessInputError class="mt-2 text-sm text-red-600" />
|
|
18
|
+
</HeadlessInput>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import IconExclamationSolid from '~icons/zondicons/exclamation-solid';
|
|
23
|
+
|
|
24
|
+
import { computed, useTemplateRef } from 'vue';
|
|
25
|
+
import type { HTMLAttributes } from 'vue';
|
|
26
|
+
|
|
27
|
+
import HeadlessInput from '@aerogel/core/components/headless/HeadlessInput.vue';
|
|
28
|
+
import HeadlessInputLabel from '@aerogel/core/components/headless/HeadlessInputLabel.vue';
|
|
29
|
+
import HeadlessInputTextArea from '@aerogel/core/components/headless/HeadlessInputTextArea.vue';
|
|
30
|
+
import HeadlessInputDescription from '@aerogel/core/components/headless/HeadlessInputDescription.vue';
|
|
31
|
+
import HeadlessInputError from '@aerogel/core/components/headless/HeadlessInputError.vue';
|
|
32
|
+
import { classes } from '@aerogel/core/utils/classes';
|
|
33
|
+
import { useInputAttrs } from '@aerogel/core/utils/composition/forms';
|
|
34
|
+
import type { InputEmits, InputProps } from '@aerogel/core/components/contracts/Input';
|
|
35
|
+
|
|
36
|
+
defineOptions({ inheritAttrs: false });
|
|
37
|
+
defineEmits<InputEmits>();
|
|
38
|
+
const { label, inputClass, wrapperClass, ...props } = defineProps<
|
|
39
|
+
InputProps & { inputClass?: HTMLAttributes['class']; wrapperClass?: HTMLAttributes['class'] }
|
|
40
|
+
>();
|
|
41
|
+
const $input = useTemplateRef('$inputRef');
|
|
42
|
+
const [inputAttrs, rootClasses] = useInputAttrs();
|
|
43
|
+
const renderedWrapperClasses = computed(() =>
|
|
44
|
+
classes('relative rounded-md shadow-2xs', { 'mt-1': label }, wrapperClass));
|
|
45
|
+
const renderedInputClasses = computed(() =>
|
|
46
|
+
classes(
|
|
47
|
+
// eslint-disable-next-line vue/max-len
|
|
48
|
+
'block w-full rounded-md border-0 py-1.5 ring-1 ring-inset focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6',
|
|
49
|
+
{
|
|
50
|
+
'focus:ring-primary-600': !$input.value?.errors,
|
|
51
|
+
'text-gray-900 shadow-2xs ring-gray-300 placeholder:text-gray-400': !$input.value?.errors,
|
|
52
|
+
'pr-10 text-red-900 ring-red-300 placeholder:text-red-300 focus:ring-red-500': $input.value?.errors,
|
|
53
|
+
},
|
|
54
|
+
inputClass,
|
|
55
|
+
));
|
|
56
|
+
</script>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<HeadlessToast :class="renderedClasses">
|
|
3
|
+
<Markdown v-if="message" :text="message" inline />
|
|
4
|
+
|
|
5
|
+
<Button
|
|
6
|
+
v-for="(action, key) of actions"
|
|
7
|
+
:key
|
|
8
|
+
:action
|
|
9
|
+
:variant
|
|
10
|
+
:as="HeadlessToastAction"
|
|
11
|
+
/>
|
|
12
|
+
</HeadlessToast>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { computed } from 'vue';
|
|
17
|
+
import type { HTMLAttributes } from 'vue';
|
|
18
|
+
|
|
19
|
+
import Button from '@aerogel/core/components/ui/Button.vue';
|
|
20
|
+
import Markdown from '@aerogel/core/components/ui/Markdown.vue';
|
|
21
|
+
import HeadlessToast from '@aerogel/core/components/headless/HeadlessToast.vue';
|
|
22
|
+
import HeadlessToastAction from '@aerogel/core/components/headless/HeadlessToastAction.vue';
|
|
23
|
+
import { variantClasses } from '@aerogel/core/utils/classes';
|
|
24
|
+
import type { ToastExpose, ToastProps } from '@aerogel/core/components/contracts/Toast';
|
|
25
|
+
import type { Variants } from '@aerogel/core/utils/classes';
|
|
26
|
+
|
|
27
|
+
const { class: baseClasses, variant = 'secondary' } = defineProps<ToastProps & { class?: HTMLAttributes['class'] }>();
|
|
28
|
+
const renderedClasses = computed(() =>
|
|
29
|
+
variantClasses<Variants<Pick<ToastProps, 'variant'>>>(
|
|
30
|
+
{ baseClasses, variant },
|
|
31
|
+
{
|
|
32
|
+
baseClasses: 'flex items-center gap-2 rounded-md p-2 ring-1 shadow-lg border-gray-200',
|
|
33
|
+
variants: {
|
|
34
|
+
variant: {
|
|
35
|
+
secondary: 'bg-gray-900 text-white ring-black',
|
|
36
|
+
danger: 'bg-red-50 text-red-900 ring-red-100',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
defaultVariants: {
|
|
40
|
+
variant: 'secondary',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
));
|
|
44
|
+
|
|
45
|
+
defineExpose<ToastExpose>();
|
|
46
|
+
</script>
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
export { default as AdvancedOptions } from './AdvancedOptions.vue';
|
|
1
2
|
export { default as AlertModal } from './AlertModal.vue';
|
|
2
3
|
export { default as Button } from './Button.vue';
|
|
3
4
|
export { default as Checkbox } from './Checkbox.vue';
|
|
4
5
|
export { default as ConfirmModal } from './ConfirmModal.vue';
|
|
6
|
+
export { default as DropdownMenu } from './DropdownMenu.vue';
|
|
7
|
+
export { default as DropdownMenuOption } from './DropdownMenuOption.vue';
|
|
8
|
+
export { default as DropdownMenuOptions } from './DropdownMenuOptions.vue';
|
|
9
|
+
export { default as EditableContent } from './EditableContent.vue';
|
|
10
|
+
export { default as ErrorLogs } from './ErrorLogs.vue';
|
|
11
|
+
export { default as ErrorLogsModal } from './ErrorLogsModal.vue';
|
|
12
|
+
export { default as ErrorMessage } from './ErrorMessage.vue';
|
|
5
13
|
export { default as ErrorReportModal } from './ErrorReportModal.vue';
|
|
6
14
|
export { default as ErrorReportModalButtons } from './ErrorReportModalButtons.vue';
|
|
7
15
|
export { default as ErrorReportModalTitle } from './ErrorReportModalTitle.vue';
|
|
@@ -14,3 +22,14 @@ export { default as Modal } from './Modal.vue';
|
|
|
14
22
|
export { default as ModalContext } from './ModalContext.vue';
|
|
15
23
|
export { default as ProgressBar } from './ProgressBar.vue';
|
|
16
24
|
export { default as PromptModal } from './PromptModal.vue';
|
|
25
|
+
export { default as Select } from './Select.vue';
|
|
26
|
+
export { default as SelectLabel } from './SelectLabel.vue';
|
|
27
|
+
export { default as SelectOption } from './SelectOption.vue';
|
|
28
|
+
export { default as SelectOptions } from './SelectOptions.vue';
|
|
29
|
+
export { default as SelectTrigger } from './SelectTrigger.vue';
|
|
30
|
+
export { default as Setting } from './Setting.vue';
|
|
31
|
+
export { default as SettingsModal } from './SettingsModal.vue';
|
|
32
|
+
export { default as StartupCrash } from './StartupCrash.vue';
|
|
33
|
+
export { default as Switch } from './Switch.vue';
|
|
34
|
+
export { default as TextArea } from './TextArea.vue';
|
|
35
|
+
export { default as Toast } from './Toast.vue';
|
|
@@ -3,6 +3,15 @@ import { tap } from '@noeldemartin/utils';
|
|
|
3
3
|
|
|
4
4
|
const resizeObservers: WeakMap<HTMLElement, ResizeObserver> = new WeakMap();
|
|
5
5
|
|
|
6
|
+
export type MeasureDirectiveValue =
|
|
7
|
+
| MeasureDirectiveListener
|
|
8
|
+
| {
|
|
9
|
+
css?: boolean;
|
|
10
|
+
watch?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type MeasureDirectiveModifiers = 'css' | 'watch';
|
|
14
|
+
|
|
6
15
|
export interface ElementSize {
|
|
7
16
|
width: number;
|
|
8
17
|
height: number;
|
|
@@ -10,11 +19,8 @@ export interface ElementSize {
|
|
|
10
19
|
|
|
11
20
|
export type MeasureDirectiveListener = (size: ElementSize) => unknown;
|
|
12
21
|
|
|
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
|
-
|
|
22
|
+
export default defineDirective<MeasureDirectiveValue, MeasureDirectiveModifiers>({
|
|
23
|
+
mounted(element: HTMLElement, { value, modifiers }) {
|
|
18
24
|
const listener = typeof value === 'function' ? (value as MeasureDirectiveListener) : null;
|
|
19
25
|
const update = () => {
|
|
20
26
|
const sizes = element.getBoundingClientRect();
|
package/src/errors/Errors.ts
CHANGED
|
@@ -2,12 +2,9 @@ import { JSError, facade, isDevelopment, isObject, isTesting, objectWithoutEmpty
|
|
|
2
2
|
|
|
3
3
|
import App from '@aerogel/core/services/App';
|
|
4
4
|
import ServiceBootError from '@aerogel/core/errors/ServiceBootError';
|
|
5
|
-
import UI
|
|
5
|
+
import UI from '@aerogel/core/ui/UI';
|
|
6
6
|
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
7
|
-
import { Colors } from '@aerogel/core/components/constants';
|
|
8
7
|
import { Events } from '@aerogel/core/services';
|
|
9
|
-
import type { ErrorReportModalProps } from '@aerogel/core/components/contracts/ErrorReportModal';
|
|
10
|
-
import type { ModalComponent } from '@aerogel/core/ui/UI.state';
|
|
11
8
|
|
|
12
9
|
import Service from './Errors.state';
|
|
13
10
|
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
@@ -25,18 +22,23 @@ export class ErrorsService extends Service {
|
|
|
25
22
|
this.enabled = false;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
public async inspect(error: ErrorSource | ErrorReport[]): Promise<void
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
25
|
+
public async inspect(error: ErrorSource | ErrorReport, reports?: ErrorReport[]): Promise<void>;
|
|
26
|
+
public async inspect(reports: ErrorReport[]): Promise<void>;
|
|
27
|
+
public async inspect(errorOrReports: ErrorSource | ErrorReport[], _reports?: ErrorReport[]): Promise<void> {
|
|
28
|
+
if (Array.isArray(errorOrReports) && errorOrReports.length === 0) {
|
|
32
29
|
UI.alert(translateWithDefault('errors.inspectEmpty', 'Nothing to inspect!'));
|
|
33
30
|
|
|
34
31
|
return;
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const report = Array.isArray(errorOrReports)
|
|
35
|
+
? (errorOrReports[0] as ErrorReport)
|
|
36
|
+
: this.isErrorReport(errorOrReports)
|
|
37
|
+
? errorOrReports
|
|
38
|
+
: await this.createErrorReport(errorOrReports);
|
|
39
|
+
const reports = Array.isArray(errorOrReports) ? (errorOrReports as ErrorReport[]) : (_reports ?? [report]);
|
|
40
|
+
|
|
41
|
+
UI.modal(UI.requireComponent('error-report-modal'), { report, reports });
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
public async report(error: ErrorSource, message?: string): Promise<void> {
|
|
@@ -71,20 +73,16 @@ export class ErrorsService extends Service {
|
|
|
71
73
|
date: new Date(),
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
UI.
|
|
76
|
+
UI.toast(
|
|
75
77
|
message ??
|
|
76
78
|
translateWithDefault('errors.notice', 'Something went wrong, but it\'s not your fault. Try again!'),
|
|
77
79
|
{
|
|
78
|
-
|
|
80
|
+
variant: 'danger',
|
|
79
81
|
actions: [
|
|
80
82
|
{
|
|
81
|
-
|
|
83
|
+
label: translateWithDefault('errors.viewDetails', 'View details'),
|
|
82
84
|
dismiss: true,
|
|
83
|
-
|
|
84
|
-
UI.openModal<ModalComponent<ErrorReportModalProps>>(
|
|
85
|
-
UI.requireComponent(UIComponents.ErrorReportModal),
|
|
86
|
-
{ reports: [report] },
|
|
87
|
-
),
|
|
85
|
+
click: () => UI.modal(UI.requireComponent('error-report-modal'), { report, reports: [report] }),
|
|
88
86
|
},
|
|
89
87
|
],
|
|
90
88
|
},
|
|
@@ -126,6 +124,10 @@ export class ErrorsService extends Service {
|
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
126
|
|
|
127
|
+
private isErrorReport(error: unknown): error is ErrorReport {
|
|
128
|
+
return isObject(error) && 'title' in error;
|
|
129
|
+
}
|
|
130
|
+
|
|
129
131
|
private async createErrorReport(error: ErrorSource): Promise<ErrorReport> {
|
|
130
132
|
if (typeof error === 'string') {
|
|
131
133
|
return { title: error };
|
package/src/errors/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { App } from 'vue';
|
|
1
|
+
import type { App as AppInstance } from 'vue';
|
|
2
2
|
|
|
3
|
+
import App from '@aerogel/core/services/App';
|
|
3
4
|
import { bootServices } from '@aerogel/core/services';
|
|
4
5
|
import { definePlugin } from '@aerogel/core/plugins';
|
|
5
6
|
|
|
6
7
|
import Errors from './Errors';
|
|
8
|
+
import settings from './settings';
|
|
7
9
|
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
8
10
|
|
|
9
11
|
export * from './utils';
|
|
@@ -19,7 +21,7 @@ const frameworkHandler: ErrorHandler = (error) => {
|
|
|
19
21
|
return true;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
function setUpErrorHandler(app:
|
|
24
|
+
function setUpErrorHandler(app: AppInstance, baseHandler: ErrorHandler = () => false): void {
|
|
23
25
|
const errorHandler: ErrorHandler = (error) => baseHandler(error) || frameworkHandler(error);
|
|
24
26
|
|
|
25
27
|
app.config.errorHandler = errorHandler;
|
|
@@ -34,6 +36,8 @@ export default definePlugin({
|
|
|
34
36
|
async install(app, options) {
|
|
35
37
|
setUpErrorHandler(app, options.handleError);
|
|
36
38
|
|
|
39
|
+
settings.forEach((setting) => App.addSetting(setting));
|
|
40
|
+
|
|
37
41
|
await bootServices(app, services);
|
|
38
42
|
},
|
|
39
43
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Setting
|
|
3
|
+
title-id="debug-setting"
|
|
4
|
+
:title="$td('settings.debug', 'Debugging')"
|
|
5
|
+
:description="$td('settings.debugDescription', 'Enable debugging with [Eruda](https://eruda.liriliri.io/).')"
|
|
6
|
+
>
|
|
7
|
+
<Switch v-model="enabled" aria-labelledby="debug-setting" />
|
|
8
|
+
</Setting>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { ref, watchEffect } from 'vue';
|
|
13
|
+
import type Eruda from 'eruda';
|
|
14
|
+
|
|
15
|
+
import Setting from '@aerogel/core/components/ui/Setting.vue';
|
|
16
|
+
import Switch from '@aerogel/core/components/ui/Switch.vue';
|
|
17
|
+
|
|
18
|
+
let eruda: typeof Eruda | null = null;
|
|
19
|
+
const enabled = ref(false);
|
|
20
|
+
|
|
21
|
+
watchEffect(async () => {
|
|
22
|
+
if (!enabled.value) {
|
|
23
|
+
eruda?.destroy();
|
|
24
|
+
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
eruda ??= (await import('eruda')).default;
|
|
29
|
+
|
|
30
|
+
eruda.init();
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
2
|
+
import { tt } from '@noeldemartin/testing';
|
|
3
|
+
import type { Equals } from '@noeldemartin/utils';
|
|
4
|
+
import type { Expect } from '@noeldemartin/testing';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
numberInput,
|
|
8
|
+
objectInput,
|
|
9
|
+
requiredObjectInput,
|
|
10
|
+
requiredStringInput,
|
|
11
|
+
stringInput,
|
|
12
|
+
} from '@aerogel/core/forms/utils';
|
|
13
|
+
import { useForm } from '@aerogel/core/utils/composition/forms';
|
|
7
14
|
|
|
8
15
|
describe('FormController', () => {
|
|
9
16
|
|
|
@@ -21,7 +28,7 @@ describe('FormController', () => {
|
|
|
21
28
|
// Arrange
|
|
22
29
|
const form = useForm({
|
|
23
30
|
name: {
|
|
24
|
-
type:
|
|
31
|
+
type: 'string',
|
|
25
32
|
rules: 'required',
|
|
26
33
|
},
|
|
27
34
|
});
|
|
@@ -39,7 +46,7 @@ describe('FormController', () => {
|
|
|
39
46
|
// Arrange
|
|
40
47
|
const form = useForm({
|
|
41
48
|
name: {
|
|
42
|
-
type:
|
|
49
|
+
type: 'string',
|
|
43
50
|
rules: 'required',
|
|
44
51
|
},
|
|
45
52
|
});
|
|
@@ -60,11 +67,11 @@ describe('FormController', () => {
|
|
|
60
67
|
// Arrange
|
|
61
68
|
const form = useForm({
|
|
62
69
|
trimmed: {
|
|
63
|
-
type:
|
|
70
|
+
type: 'string',
|
|
64
71
|
rules: 'required',
|
|
65
72
|
},
|
|
66
73
|
untrimmed: {
|
|
67
|
-
type:
|
|
74
|
+
type: 'string',
|
|
68
75
|
rules: 'required',
|
|
69
76
|
trim: false,
|
|
70
77
|
},
|
|
@@ -84,4 +91,20 @@ describe('FormController', () => {
|
|
|
84
91
|
expect(form.errors).toEqual({ trimmed: ['required'], untrimmed: null });
|
|
85
92
|
});
|
|
86
93
|
|
|
94
|
+
it('infers field types', () => {
|
|
95
|
+
const form = useForm({
|
|
96
|
+
one: stringInput(),
|
|
97
|
+
two: requiredStringInput(),
|
|
98
|
+
three: objectInput(),
|
|
99
|
+
four: requiredObjectInput<{ foo: string; bar?: number }>(),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
tt<
|
|
103
|
+
| Expect<Equals<typeof form.one, string | null>>
|
|
104
|
+
| Expect<Equals<typeof form.two, string>>
|
|
105
|
+
| Expect<Equals<typeof form.three, object | null>>
|
|
106
|
+
| Expect<Equals<typeof form.four, { foo: string; bar?: number }>>
|
|
107
|
+
>();
|
|
108
|
+
});
|
|
109
|
+
|
|
87
110
|
});
|
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { computed, nextTick, reactive, readonly, ref } from 'vue';
|
|
2
2
|
import { MagicObject, arrayRemove, fail, toString } from '@noeldemartin/utils';
|
|
3
|
-
import { validate } from './validation';
|
|
4
|
-
import type { ObjectValues } from '@noeldemartin/utils';
|
|
5
3
|
import type { ComputedRef, DeepReadonly, Ref, UnwrapNestedRefs } from 'vue';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Boolean: 'boolean',
|
|
11
|
-
Object: 'object',
|
|
12
|
-
Date: 'date',
|
|
13
|
-
} as const;
|
|
5
|
+
import { validate } from './validation';
|
|
6
|
+
|
|
7
|
+
export const __objectType: unique symbol = Symbol();
|
|
14
8
|
|
|
15
|
-
export interface FormFieldDefinition<
|
|
9
|
+
export interface FormFieldDefinition<
|
|
10
|
+
TType extends FormFieldType = FormFieldType,
|
|
11
|
+
TRules extends string = string,
|
|
12
|
+
TObjectType = object,
|
|
13
|
+
> {
|
|
16
14
|
type: TType;
|
|
17
15
|
trim?: boolean;
|
|
18
16
|
default?: GetFormFieldValue<TType>;
|
|
19
17
|
rules?: TRules;
|
|
18
|
+
[__objectType]?: TObjectType;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
export type
|
|
23
|
-
export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
|
|
21
|
+
export type FormFieldType = 'string' | 'number' | 'boolean' | 'object' | 'date';
|
|
24
22
|
export type FormFieldValue = GetFormFieldValue<FormFieldType>;
|
|
23
|
+
export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
|
|
25
24
|
|
|
26
25
|
export type FormData<T> = {
|
|
27
|
-
-readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
|
|
26
|
+
-readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules, infer TObjectType>
|
|
28
27
|
? TRules extends 'required'
|
|
29
|
-
? GetFormFieldValue<TType>
|
|
30
|
-
: GetFormFieldValue<TType> | null
|
|
28
|
+
? GetFormFieldValue<TType, TObjectType>
|
|
29
|
+
: GetFormFieldValue<TType, TObjectType> | null
|
|
31
30
|
: never;
|
|
32
31
|
};
|
|
33
32
|
|
|
@@ -35,15 +34,17 @@ export type FormErrors<T> = {
|
|
|
35
34
|
[k in keyof T]: string[] | null;
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
export type GetFormFieldValue<TType> = TType extends
|
|
37
|
+
export type GetFormFieldValue<TType, TObjectType = object> = TType extends 'string'
|
|
39
38
|
? string
|
|
40
|
-
: TType extends
|
|
39
|
+
: TType extends 'number'
|
|
41
40
|
? number
|
|
42
|
-
: TType extends
|
|
41
|
+
: TType extends 'boolean'
|
|
43
42
|
? boolean
|
|
44
|
-
: TType extends
|
|
45
|
-
? object
|
|
46
|
-
|
|
43
|
+
: TType extends 'object'
|
|
44
|
+
? TObjectType extends object
|
|
45
|
+
? TObjectType
|
|
46
|
+
: object
|
|
47
|
+
: TType extends 'date'
|
|
47
48
|
? Date
|
|
48
49
|
: never;
|
|
49
50
|
|
|
@@ -91,7 +92,7 @@ export default class FormController<Fields extends FormFieldDefinitions = FormFi
|
|
|
91
92
|
this._fields[field] ?? fail<FormFieldDefinition>(`Trying to set undefined '${toString(field)}' field`);
|
|
92
93
|
|
|
93
94
|
this._data[field] =
|
|
94
|
-
definition.type ===
|
|
95
|
+
definition.type === 'string' && (definition.trim ?? true)
|
|
95
96
|
? (toString(value).trim() as FormData<Fields>[T])
|
|
96
97
|
: value;
|
|
97
98
|
|
|
@@ -108,6 +109,10 @@ export default class FormController<Fields extends FormFieldDefinitions = FormFi
|
|
|
108
109
|
return this._fields[field]?.rules?.split('|') ?? [];
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
public getFieldType<T extends keyof Fields>(field: T): FormFieldType | null {
|
|
113
|
+
return this._fields[field]?.type ?? null;
|
|
114
|
+
}
|
|
115
|
+
|
|
111
116
|
public data(): FormData<Fields> {
|
|
112
117
|
return { ...this._data };
|
|
113
118
|
}
|
package/src/forms/index.ts
CHANGED
package/src/forms/utils.ts
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { FormFieldTypes } from './FormController';
|
|
2
1
|
import type { FormFieldDefinition } from './FormController';
|
|
3
2
|
|
|
4
|
-
export function booleanInput(
|
|
5
|
-
defaultValue?: boolean,
|
|
6
|
-
options: { rules?: string } = {},
|
|
7
|
-
): FormFieldDefinition<typeof FormFieldTypes.Boolean> {
|
|
3
|
+
export function booleanInput(defaultValue?: boolean, options: { rules?: string } = {}): FormFieldDefinition<'boolean'> {
|
|
8
4
|
return {
|
|
9
5
|
default: defaultValue,
|
|
10
|
-
type:
|
|
6
|
+
type: 'boolean',
|
|
11
7
|
rules: options.rules,
|
|
12
8
|
};
|
|
13
9
|
}
|
|
14
10
|
|
|
15
|
-
export function dateInput(
|
|
16
|
-
defaultValue?: Date,
|
|
17
|
-
options: { rules?: string } = {},
|
|
18
|
-
): FormFieldDefinition<typeof FormFieldTypes.Date> {
|
|
11
|
+
export function dateInput(defaultValue?: Date, options: { rules?: string } = {}): FormFieldDefinition<'date'> {
|
|
19
12
|
return {
|
|
20
13
|
default: defaultValue,
|
|
21
|
-
type:
|
|
14
|
+
type: 'date',
|
|
22
15
|
rules: options.rules,
|
|
23
16
|
};
|
|
24
17
|
}
|
|
25
18
|
|
|
26
|
-
export function requiredBooleanInput(
|
|
27
|
-
defaultValue?: boolean,
|
|
28
|
-
): FormFieldDefinition<typeof FormFieldTypes.Boolean, 'required'> {
|
|
19
|
+
export function requiredBooleanInput(defaultValue?: boolean): FormFieldDefinition<'boolean', 'required'> {
|
|
29
20
|
return {
|
|
30
21
|
default: defaultValue,
|
|
31
|
-
type:
|
|
22
|
+
type: 'boolean',
|
|
32
23
|
rules: 'required',
|
|
33
24
|
};
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
export function requiredDateInput(defaultValue?: Date): FormFieldDefinition<
|
|
27
|
+
export function requiredDateInput(defaultValue?: Date): FormFieldDefinition<'date', 'required'> {
|
|
37
28
|
return {
|
|
38
29
|
default: defaultValue,
|
|
39
|
-
type:
|
|
30
|
+
type: 'date',
|
|
40
31
|
rules: 'required',
|
|
41
32
|
};
|
|
42
33
|
}
|
|
43
34
|
|
|
44
|
-
export function requiredNumberInput(
|
|
45
|
-
defaultValue?: number,
|
|
46
|
-
): FormFieldDefinition<typeof FormFieldTypes.Number, 'required'> {
|
|
35
|
+
export function requiredNumberInput(defaultValue?: number): FormFieldDefinition<'number', 'required'> {
|
|
47
36
|
return {
|
|
48
37
|
default: defaultValue,
|
|
49
|
-
type:
|
|
38
|
+
type: 'number',
|
|
50
39
|
rules: 'required',
|
|
51
40
|
};
|
|
52
41
|
}
|
|
53
42
|
|
|
54
|
-
export function
|
|
55
|
-
defaultValue?: string,
|
|
56
|
-
): FormFieldDefinition<typeof FormFieldTypes.String, 'required'> {
|
|
43
|
+
export function requiredObjectInput<T extends object>(defaultValue?: T): FormFieldDefinition<'object', 'required', T> {
|
|
57
44
|
return {
|
|
58
45
|
default: defaultValue,
|
|
59
|
-
type:
|
|
46
|
+
type: 'object',
|
|
60
47
|
rules: 'required',
|
|
61
48
|
};
|
|
62
49
|
}
|
|
63
50
|
|
|
64
|
-
export function
|
|
65
|
-
defaultValue?: number,
|
|
66
|
-
options: { rules?: string } = {},
|
|
67
|
-
): FormFieldDefinition<typeof FormFieldTypes.Number> {
|
|
51
|
+
export function requiredStringInput(defaultValue?: string): FormFieldDefinition<'string', 'required'> {
|
|
68
52
|
return {
|
|
69
53
|
default: defaultValue,
|
|
70
|
-
type:
|
|
54
|
+
type: 'string',
|
|
55
|
+
rules: 'required',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function numberInput(defaultValue?: number, options: { rules?: string } = {}): FormFieldDefinition<'number'> {
|
|
60
|
+
return {
|
|
61
|
+
default: defaultValue,
|
|
62
|
+
type: 'number',
|
|
71
63
|
rules: options.rules,
|
|
72
64
|
};
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
export function
|
|
76
|
-
defaultValue?:
|
|
67
|
+
export function objectInput<T extends object>(
|
|
68
|
+
defaultValue?: T,
|
|
77
69
|
options: { rules?: string } = {},
|
|
78
|
-
): FormFieldDefinition<
|
|
70
|
+
): FormFieldDefinition<'object', string, T> {
|
|
71
|
+
return {
|
|
72
|
+
default: defaultValue,
|
|
73
|
+
type: 'object',
|
|
74
|
+
rules: options.rules,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function stringInput(defaultValue?: string, options: { rules?: string } = {}): FormFieldDefinition<'string'> {
|
|
79
79
|
return {
|
|
80
80
|
default: defaultValue,
|
|
81
|
-
type:
|
|
81
|
+
type: 'string',
|
|
82
82
|
rules: options.rules,
|
|
83
83
|
};
|
|
84
84
|
}
|