@aerogel/core 0.0.0-next.b85327579d32f21c6a9fa21142f0165cdd320d7e → 0.0.0-next.b9379d15fd4f40346d655134b49c9015ead9c536
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 +2310 -664
- package/dist/aerogel-core.js +3542 -0
- package/dist/aerogel-core.js.map +1 -0
- package/package.json +38 -34
- package/src/bootstrap/bootstrap.test.ts +7 -10
- package/src/bootstrap/index.ts +43 -14
- package/src/bootstrap/options.ts +4 -1
- package/src/components/AppLayout.vue +14 -0
- package/src/components/AppModals.vue +14 -0
- package/src/components/AppOverlays.vue +9 -0
- package/src/components/AppToasts.vue +16 -0
- package/src/components/contracts/AlertModal.ts +19 -0
- package/src/components/contracts/Button.ts +16 -0
- package/src/components/contracts/ConfirmModal.ts +48 -0
- package/src/components/contracts/DropdownMenu.ts +25 -0
- package/src/components/contracts/ErrorReportModal.ts +33 -0
- package/src/components/contracts/Input.ts +26 -0
- package/src/components/contracts/LoadingModal.ts +26 -0
- package/src/components/contracts/Modal.ts +21 -0
- package/src/components/contracts/PromptModal.ts +34 -0
- package/src/components/contracts/Select.ts +45 -0
- package/src/components/contracts/Toast.ts +15 -0
- package/src/components/contracts/index.ts +11 -0
- package/src/components/headless/HeadlessButton.vue +51 -0
- package/src/components/headless/HeadlessInput.vue +59 -0
- package/src/components/headless/HeadlessInputDescription.vue +27 -0
- package/src/components/headless/{forms/AGHeadlessInputError.vue → HeadlessInputError.vue} +4 -8
- package/src/components/headless/HeadlessInputInput.vue +75 -0
- package/src/components/headless/HeadlessInputLabel.vue +18 -0
- package/src/components/headless/HeadlessInputTextArea.vue +40 -0
- package/src/components/headless/HeadlessModal.vue +57 -0
- package/src/components/headless/HeadlessModalContent.vue +30 -0
- package/src/components/headless/HeadlessModalDescription.vue +12 -0
- package/src/components/headless/HeadlessModalOverlay.vue +12 -0
- package/src/components/headless/HeadlessModalTitle.vue +12 -0
- package/src/components/headless/HeadlessSelect.vue +120 -0
- package/src/components/headless/HeadlessSelectError.vue +25 -0
- 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 +20 -2
- package/src/components/index.ts +6 -7
- package/src/components/ui/AdvancedOptions.vue +18 -0
- package/src/components/ui/AlertModal.vue +17 -0
- package/src/components/ui/Button.vue +100 -0
- package/src/components/ui/Checkbox.vue +56 -0
- package/src/components/ui/ConfirmModal.vue +50 -0
- 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/ui/ErrorMessage.vue +15 -0
- package/src/components/ui/ErrorReportModal.vue +73 -0
- package/src/components/ui/ErrorReportModalButtons.vue +118 -0
- package/src/components/ui/ErrorReportModalTitle.vue +24 -0
- package/src/components/ui/Form.vue +24 -0
- package/src/components/ui/Input.vue +56 -0
- package/src/components/ui/Link.vue +12 -0
- package/src/components/ui/LoadingModal.vue +34 -0
- package/src/components/ui/Markdown.vue +97 -0
- package/src/components/ui/Modal.vue +123 -0
- package/src/components/ui/ModalContext.vue +31 -0
- package/src/components/ui/ProgressBar.vue +51 -0
- package/src/components/ui/PromptModal.vue +38 -0
- 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/SettingsModal.vue +15 -0
- package/src/components/ui/StartupCrash.vue +31 -0
- package/src/components/ui/Switch.vue +11 -0
- package/src/components/ui/Toast.vue +46 -0
- package/src/components/ui/index.ts +33 -0
- package/src/directives/index.ts +27 -6
- package/src/directives/measure.ts +46 -0
- package/src/errors/Errors.state.ts +1 -1
- package/src/errors/Errors.ts +70 -15
- package/src/errors/JobCancelledError.ts +3 -0
- package/src/errors/index.ts +38 -6
- package/src/errors/settings/Debug.vue +39 -0
- package/src/errors/settings/index.ts +10 -0
- package/src/errors/utils.ts +35 -0
- package/src/forms/FormController.test.ts +110 -0
- package/src/forms/FormController.ts +246 -0
- package/src/forms/index.ts +3 -2
- package/src/forms/utils.ts +51 -20
- package/src/forms/validation.ts +19 -0
- package/src/index.css +73 -0
- package/src/{main.ts → index.ts} +3 -2
- package/src/jobs/Job.ts +147 -0
- package/src/jobs/index.ts +10 -0
- package/src/jobs/listeners.ts +3 -0
- package/src/jobs/status.ts +4 -0
- package/src/lang/DefaultLangProvider.ts +46 -0
- package/src/lang/Lang.state.ts +11 -0
- package/src/lang/Lang.ts +44 -29
- package/src/lang/index.ts +12 -6
- package/src/lang/settings/Language.vue +48 -0
- package/src/lang/settings/index.ts +10 -0
- package/src/plugins/Plugin.ts +2 -1
- package/src/plugins/index.ts +22 -0
- package/src/services/App.state.ts +42 -5
- package/src/services/App.ts +52 -6
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.test.ts +39 -0
- package/src/services/Events.ts +110 -36
- package/src/services/Service.ts +160 -50
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +25 -10
- package/src/services/store.ts +8 -5
- package/src/services/utils.ts +18 -0
- package/src/testing/index.ts +26 -0
- package/src/testing/setup.ts +11 -0
- package/src/ui/UI.state.ts +20 -9
- package/src/ui/UI.ts +322 -74
- package/src/ui/index.ts +32 -23
- package/src/ui/utils.ts +16 -0
- package/src/utils/classes.ts +41 -0
- package/src/utils/composition/events.ts +4 -5
- package/src/utils/composition/forms.ts +20 -4
- package/src/utils/composition/persistent.test.ts +33 -0
- package/src/utils/composition/persistent.ts +11 -0
- package/src/utils/composition/state.test.ts +47 -0
- package/src/utils/composition/state.ts +33 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/markdown.test.ts +50 -0
- package/src/utils/markdown.ts +60 -4
- package/src/utils/types.ts +3 -0
- package/src/utils/vue.ts +38 -121
- package/.eslintrc.js +0 -3
- package/dist/aerogel-core.cjs.js +0 -2
- package/dist/aerogel-core.cjs.js.map +0 -1
- package/dist/aerogel-core.esm.js +0 -2
- package/dist/aerogel-core.esm.js.map +0 -1
- package/noeldemartin.config.js +0 -2
- package/src/components/AGAppLayout.vue +0 -11
- package/src/components/AGAppOverlays.vue +0 -39
- package/src/components/basic/AGMarkdown.vue +0 -35
- package/src/components/basic/index.ts +0 -3
- package/src/components/forms/AGButton.vue +0 -34
- package/src/components/forms/AGCheckbox.vue +0 -35
- package/src/components/forms/AGForm.vue +0 -26
- package/src/components/forms/AGInput.vue +0 -36
- package/src/components/forms/index.ts +0 -6
- package/src/components/headless/forms/AGHeadlessButton.vue +0 -50
- package/src/components/headless/forms/AGHeadlessInput.ts +0 -8
- package/src/components/headless/forms/AGHeadlessInput.vue +0 -54
- package/src/components/headless/forms/AGHeadlessInputInput.vue +0 -45
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +0 -16
- package/src/components/headless/forms/index.ts +0 -6
- package/src/components/headless/modals/AGHeadlessModal.ts +0 -7
- package/src/components/headless/modals/AGHeadlessModal.vue +0 -88
- package/src/components/headless/modals/AGHeadlessModalPanel.vue +0 -28
- package/src/components/headless/modals/AGHeadlessModalTitle.vue +0 -13
- package/src/components/headless/modals/index.ts +0 -6
- package/src/components/modals/AGAlertModal.vue +0 -26
- package/src/components/modals/AGConfirmModal.vue +0 -30
- package/src/components/modals/AGLoadingModal.vue +0 -19
- package/src/components/modals/AGModal.ts +0 -10
- package/src/components/modals/AGModal.vue +0 -36
- package/src/components/modals/AGModalContext.ts +0 -8
- package/src/components/modals/AGModalContext.vue +0 -22
- package/src/components/modals/index.ts +0 -8
- package/src/directives/initial-focus.ts +0 -11
- package/src/forms/Form.test.ts +0 -58
- package/src/forms/Form.ts +0 -176
- package/src/forms/composition.ts +0 -6
- package/src/globals.ts +0 -6
- package/tsconfig.json +0 -10
- package/vite.config.ts +0 -13
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<AGModal>
|
|
3
|
-
<AGMarkdown
|
|
4
|
-
v-if="title"
|
|
5
|
-
:text="title"
|
|
6
|
-
as="h2"
|
|
7
|
-
class="font-semibold"
|
|
8
|
-
raw
|
|
9
|
-
inline
|
|
10
|
-
/>
|
|
11
|
-
<AGMarkdown :text="message" />
|
|
12
|
-
</AGModal>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<script setup lang="ts">
|
|
16
|
-
import { requiredStringProp, stringProp } from '@/utils/vue';
|
|
17
|
-
|
|
18
|
-
import AGModal from './AGModal.vue';
|
|
19
|
-
|
|
20
|
-
import AGMarkdown from '../basic/AGMarkdown.vue';
|
|
21
|
-
|
|
22
|
-
defineProps({
|
|
23
|
-
title: stringProp(),
|
|
24
|
-
message: requiredStringProp(),
|
|
25
|
-
});
|
|
26
|
-
</script>
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<AGModal v-slot="{ close }: IAGModalDefaultSlotProps" :cancellable="false">
|
|
3
|
-
<AGMarkdown v-if="title" :text="title" as="h1" />
|
|
4
|
-
<AGMarkdown :text="message" />
|
|
5
|
-
|
|
6
|
-
<div class="mt-2 flex flex-row-reverse gap-2">
|
|
7
|
-
<AGButton @click="close(true)">
|
|
8
|
-
{{ $td('ui.ok', 'OK') }}
|
|
9
|
-
</AGButton>
|
|
10
|
-
<AGButton secondary @click="close()">
|
|
11
|
-
{{ $td('ui.cancel', 'Cancel') }}
|
|
12
|
-
</AGButton>
|
|
13
|
-
</div>
|
|
14
|
-
</AGModal>
|
|
15
|
-
</template>
|
|
16
|
-
|
|
17
|
-
<script setup lang="ts">
|
|
18
|
-
import { requiredStringProp, stringProp } from '@/utils/vue';
|
|
19
|
-
|
|
20
|
-
import AGModal from './AGModal.vue';
|
|
21
|
-
import type { IAGModalDefaultSlotProps } from './AGModal';
|
|
22
|
-
|
|
23
|
-
import AGButton from '../forms/AGButton.vue';
|
|
24
|
-
import AGMarkdown from '../basic/AGMarkdown.vue';
|
|
25
|
-
|
|
26
|
-
defineProps({
|
|
27
|
-
title: stringProp(),
|
|
28
|
-
message: requiredStringProp(),
|
|
29
|
-
});
|
|
30
|
-
</script>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<AGModal :cancellable="false">
|
|
3
|
-
<AGMarkdown :text="renderedMessage" />
|
|
4
|
-
</AGModal>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
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
|
-
import AGModal from './AGModal.vue';
|
|
14
|
-
|
|
15
|
-
import AGMarkdown from '../basic/AGMarkdown.vue';
|
|
16
|
-
|
|
17
|
-
const props = defineProps({ message: stringProp() });
|
|
18
|
-
const renderedMessage = computed(() => props.message ?? translateWithDefault('ui.loading', 'Loading...'));
|
|
19
|
-
</script>
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<AGHeadlessModal
|
|
3
|
-
ref="$headlessModal"
|
|
4
|
-
v-slot="{ close }: IAGHeadlessModalDefaultSlotProps"
|
|
5
|
-
:cancellable="cancellable"
|
|
6
|
-
class="relative z-50"
|
|
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
|
-
<div class="flex max-h-full flex-col overflow-auto p-4">
|
|
11
|
-
<slot :close="close" />
|
|
12
|
-
</div>
|
|
13
|
-
</AGHeadlessModalPanel>
|
|
14
|
-
</div>
|
|
15
|
-
</AGHeadlessModal>
|
|
16
|
-
</template>
|
|
17
|
-
|
|
18
|
-
<script setup lang="ts">
|
|
19
|
-
import { computed, ref } from 'vue';
|
|
20
|
-
|
|
21
|
-
import { booleanProp } from '@/utils';
|
|
22
|
-
import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from '@/components/headless/modals/AGHeadlessModal';
|
|
23
|
-
|
|
24
|
-
import type { IAGModal } from './AGModal';
|
|
25
|
-
|
|
26
|
-
import AGHeadlessModal from '../headless/modals/AGHeadlessModal.vue';
|
|
27
|
-
import AGHeadlessModalPanel from '../headless/modals/AGHeadlessModalPanel.vue';
|
|
28
|
-
|
|
29
|
-
const $headlessModal = ref<IAGHeadlessModal>();
|
|
30
|
-
|
|
31
|
-
defineProps({ cancellable: booleanProp(true) });
|
|
32
|
-
defineExpose<IAGModal>({
|
|
33
|
-
close: async () => $headlessModal.value?.close(),
|
|
34
|
-
cancellable: computed(() => !!$headlessModal.value?.cancellable),
|
|
35
|
-
});
|
|
36
|
-
</script>
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<component :is="modal.component" v-bind="modal.properties" />
|
|
3
|
-
</template>
|
|
4
|
-
|
|
5
|
-
<script setup lang="ts">
|
|
6
|
-
import { provide, toRef } from 'vue';
|
|
7
|
-
|
|
8
|
-
import { requiredNumberProp, requiredObjectProp } from '@/utils/vue';
|
|
9
|
-
import type { Modal } from '@/ui/UI.state';
|
|
10
|
-
|
|
11
|
-
import type { IAGModalContext } from './AGModalContext';
|
|
12
|
-
|
|
13
|
-
const props = defineProps({
|
|
14
|
-
modal: requiredObjectProp<Modal>(),
|
|
15
|
-
childIndex: requiredNumberProp(),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
provide<IAGModalContext>('modal', {
|
|
19
|
-
modal: toRef(props, 'modal'),
|
|
20
|
-
childIndex: toRef(props, 'childIndex'),
|
|
21
|
-
});
|
|
22
|
-
</script>
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import AGAlertModal from './AGAlertModal.vue';
|
|
2
|
-
import AGConfirmModal from './AGConfirmModal.vue';
|
|
3
|
-
import AGLoadingModal from './AGLoadingModal.vue';
|
|
4
|
-
import AGModal from './AGModal.vue';
|
|
5
|
-
import AGModalContext from './AGModalContext.vue';
|
|
6
|
-
import { IAGModal } from './AGModal';
|
|
7
|
-
|
|
8
|
-
export { AGAlertModal, AGConfirmModal, AGModal, AGModalContext, AGLoadingModal, IAGModal };
|
package/src/forms/Form.test.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { useForm } from './composition';
|
|
4
|
-
import { FormFieldTypes } from '@/main';
|
|
5
|
-
import { numberInput, requiredStringInput } from '@/forms/utils';
|
|
6
|
-
|
|
7
|
-
describe('Form', () => {
|
|
8
|
-
|
|
9
|
-
it('defines magic fields', () => {
|
|
10
|
-
const form = useForm({
|
|
11
|
-
name: requiredStringInput(),
|
|
12
|
-
age: numberInput(),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
expectTypeOf(form.name).toEqualTypeOf<string>();
|
|
16
|
-
expectTypeOf(form.age).toEqualTypeOf<number | null>();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('validates required fields', () => {
|
|
20
|
-
// Arrange
|
|
21
|
-
const form = useForm({
|
|
22
|
-
name: {
|
|
23
|
-
type: FormFieldTypes.String,
|
|
24
|
-
rules: 'required',
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// Act
|
|
29
|
-
form.submit();
|
|
30
|
-
|
|
31
|
-
// Assert
|
|
32
|
-
expect(form.valid).toBe(false);
|
|
33
|
-
expect(form.submitted).toBe(true);
|
|
34
|
-
expect(form.errors.name).toEqual(['required']);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('resets form', () => {
|
|
38
|
-
// Arrange
|
|
39
|
-
const form = useForm({
|
|
40
|
-
name: {
|
|
41
|
-
type: FormFieldTypes.String,
|
|
42
|
-
rules: 'required',
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
form.name = 'Foo bar';
|
|
47
|
-
form.submit();
|
|
48
|
-
|
|
49
|
-
// Act
|
|
50
|
-
form.reset();
|
|
51
|
-
|
|
52
|
-
// Assert
|
|
53
|
-
expect(form.valid).toBe(true);
|
|
54
|
-
expect(form.submitted).toBe(false);
|
|
55
|
-
expect(form.name).toBeNull();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
});
|
package/src/forms/Form.ts
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { MagicObject } from '@noeldemartin/utils';
|
|
2
|
-
import { computed, reactive, readonly, ref } from 'vue';
|
|
3
|
-
import type { ObjectValues } from '@noeldemartin/utils';
|
|
4
|
-
import type { ComputedRef, DeepReadonly, Ref, UnwrapNestedRefs } from 'vue';
|
|
5
|
-
|
|
6
|
-
export const FormFieldTypes = {
|
|
7
|
-
String: 'string',
|
|
8
|
-
Number: 'number',
|
|
9
|
-
Boolean: 'boolean',
|
|
10
|
-
} as const;
|
|
11
|
-
|
|
12
|
-
export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType, TRules extends string = string> {
|
|
13
|
-
type: TType;
|
|
14
|
-
default?: GetFormFieldValue<TType>;
|
|
15
|
-
rules?: TRules;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
|
|
19
|
-
export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
|
|
20
|
-
|
|
21
|
-
export type FormData<T> = {
|
|
22
|
-
-readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
|
|
23
|
-
? TRules extends 'required'
|
|
24
|
-
? GetFormFieldValue<TType>
|
|
25
|
-
: GetFormFieldValue<TType> | null
|
|
26
|
-
: never;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type FormErrors<T> = {
|
|
30
|
-
[k in keyof T]: string[] | null;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.String
|
|
34
|
-
? string
|
|
35
|
-
: TType extends typeof FormFieldTypes.Number
|
|
36
|
-
? number
|
|
37
|
-
: TType extends typeof FormFieldTypes.Boolean
|
|
38
|
-
? boolean
|
|
39
|
-
: never;
|
|
40
|
-
|
|
41
|
-
export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
|
|
42
|
-
|
|
43
|
-
public errors: DeepReadonly<UnwrapNestedRefs<FormErrors<Fields>>>;
|
|
44
|
-
|
|
45
|
-
private _fields: Fields;
|
|
46
|
-
private _data: FormData<Fields>;
|
|
47
|
-
private _valid: ComputedRef<boolean>;
|
|
48
|
-
private _submitted: Ref<boolean>;
|
|
49
|
-
private _errors: FormErrors<Fields>;
|
|
50
|
-
|
|
51
|
-
constructor(fields: Fields) {
|
|
52
|
-
super();
|
|
53
|
-
|
|
54
|
-
this._fields = fields;
|
|
55
|
-
this._submitted = ref(false);
|
|
56
|
-
this._data = this.getInitialData(fields);
|
|
57
|
-
this._errors = this.getInitialErrors(fields);
|
|
58
|
-
this._valid = computed(() => !Object.values(this._errors).some((error) => error !== null));
|
|
59
|
-
|
|
60
|
-
this.errors = readonly(this._errors);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public get valid(): boolean {
|
|
64
|
-
return this._valid.value;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public get submitted(): boolean {
|
|
68
|
-
return this._submitted.value;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public setFieldValue<T extends keyof Fields>(field: T, value: FormData<Fields>[T]): void {
|
|
72
|
-
this._data[field] = value;
|
|
73
|
-
|
|
74
|
-
if (this._submitted.value) {
|
|
75
|
-
this.validate();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public getFieldValue<T extends keyof Fields>(field: T): GetFormFieldValue<Fields[T]['type']> {
|
|
80
|
-
return this._data[field] as unknown as GetFormFieldValue<Fields[T]['type']>;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public validate(): boolean {
|
|
84
|
-
const errors = Object.entries(this._fields).reduce((formErrors, [name, definition]) => {
|
|
85
|
-
formErrors[name] = this.getFieldErrors(name, definition);
|
|
86
|
-
|
|
87
|
-
return formErrors;
|
|
88
|
-
}, {} as Record<string, string[] | null>);
|
|
89
|
-
|
|
90
|
-
this.resetErrors(errors);
|
|
91
|
-
|
|
92
|
-
return this.valid;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public reset(): void {
|
|
96
|
-
this._submitted.value = false;
|
|
97
|
-
|
|
98
|
-
this.resetData();
|
|
99
|
-
this.resetErrors();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public submit(): boolean {
|
|
103
|
-
this._submitted.value = true;
|
|
104
|
-
|
|
105
|
-
return this.validate();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
protected __get(property: string): unknown {
|
|
109
|
-
if (!(property in this._fields)) {
|
|
110
|
-
return super.__get(property);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return this._data[property];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
protected __set(property: string, value: unknown): void {
|
|
117
|
-
if (!(property in this._fields)) {
|
|
118
|
-
super.__set(property, value);
|
|
119
|
-
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
Object.assign(this._data, { [property]: value });
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private getFieldErrors(name: keyof Fields, definition: FormFieldDefinition): string[] | null {
|
|
127
|
-
const errors = [];
|
|
128
|
-
|
|
129
|
-
if (definition.rules?.includes('required') && !this._data[name]) {
|
|
130
|
-
errors.push('required');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return errors.length > 0 ? errors : null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private getInitialData(fields: Fields): FormData<Fields> {
|
|
137
|
-
if (this.static().isConjuring()) {
|
|
138
|
-
return {} as FormData<Fields>;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const data = Object.entries(fields).reduce((formData, [name, definition]) => {
|
|
142
|
-
formData[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
|
|
143
|
-
|
|
144
|
-
return formData;
|
|
145
|
-
}, {} as FormData<Fields>);
|
|
146
|
-
|
|
147
|
-
return reactive(data) as FormData<Fields>;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private getInitialErrors(fields: Fields): FormErrors<Fields> {
|
|
151
|
-
if (this.static().isConjuring()) {
|
|
152
|
-
return {} as FormErrors<Fields>;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const errors = Object.keys(fields).reduce((formErrors, name) => {
|
|
156
|
-
formErrors[name as keyof Fields] = null;
|
|
157
|
-
|
|
158
|
-
return formErrors;
|
|
159
|
-
}, {} as FormErrors<Fields>);
|
|
160
|
-
|
|
161
|
-
return reactive(errors) as FormErrors<Fields>;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private resetData(): void {
|
|
165
|
-
for (const [name, field] of Object.entries(this._fields)) {
|
|
166
|
-
this._data[name as keyof Fields] = (field.default ?? null) as FormData<Fields>[keyof Fields];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private resetErrors(errors?: Record<string, string[] | null>): void {
|
|
171
|
-
Object.keys(this._errors).forEach((key) => delete this._errors[key as keyof Fields]);
|
|
172
|
-
|
|
173
|
-
errors && Object.assign(this._errors, errors);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
}
|
package/src/forms/composition.ts
DELETED
package/src/globals.ts
DELETED
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import Aerogel from '@aerogel/vite';
|
|
2
|
-
import { defineConfig } from 'vitest/config';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
test: { clearMocks: true },
|
|
7
|
-
plugins: [Aerogel()],
|
|
8
|
-
resolve: {
|
|
9
|
-
alias: {
|
|
10
|
-
'@': resolve(__dirname, './src'),
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
});
|