@aerogel/core 0.0.0-next.9a02fcd3bcf698211dd7a71d4c48257c96dd7832 → 0.0.0-next.9aa7c279868edbedbcee075aef52212597d803fb
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.d.ts +2080 -1616
- package/dist/aerogel-core.js +3265 -0
- package/dist/aerogel-core.js.map +1 -0
- package/package.json +31 -37
- package/src/bootstrap/bootstrap.test.ts +4 -8
- package/src/bootstrap/index.ts +25 -16
- package/src/bootstrap/options.ts +1 -1
- package/src/components/AppLayout.vue +14 -0
- package/src/components/{AGAppModals.vue → AppModals.vue} +3 -4
- package/src/components/AppOverlays.vue +9 -0
- package/src/components/AppToasts.vue +16 -0
- package/src/components/contracts/AlertModal.ts +8 -0
- package/src/components/contracts/Button.ts +16 -0
- package/src/components/contracts/ConfirmModal.ts +46 -0
- package/src/components/contracts/DropdownMenu.ts +20 -0
- package/src/components/contracts/ErrorReportModal.ts +32 -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/{forms/AGHeadlessInputLabel.vue → HeadlessInputLabel.vue} +3 -7
- 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/{forms/AGHeadlessSelectError.vue → HeadlessSelectError.vue} +5 -6
- 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/HeadlessToast.vue +18 -0
- package/src/components/headless/HeadlessToastAction.vue +13 -0
- package/src/components/headless/index.ts +19 -3
- package/src/components/index.ts +6 -9
- package/src/components/ui/AdvancedOptions.vue +18 -0
- package/src/components/ui/AlertModal.vue +14 -0
- package/src/components/ui/Button.vue +98 -0
- package/src/components/ui/Checkbox.vue +56 -0
- package/src/components/ui/ConfirmModal.vue +45 -0
- package/src/components/ui/DropdownMenu.vue +32 -0
- package/src/components/ui/DropdownMenuOption.vue +14 -0
- package/src/components/ui/DropdownMenuOptions.vue +27 -0
- package/src/components/ui/EditableContent.vue +82 -0
- package/src/components/ui/ErrorMessage.vue +15 -0
- package/src/components/ui/ErrorReportModal.vue +67 -0
- package/src/components/{modals/AGErrorReportModalButtons.vue → ui/ErrorReportModalButtons.vue} +34 -27
- 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 +69 -0
- package/src/components/ui/Modal.vue +122 -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 +17 -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/{lib/AGStartupCrash.vue → ui/StartupCrash.vue} +8 -8
- package/src/components/ui/Toast.vue +44 -0
- package/src/components/ui/index.ts +30 -0
- package/src/directives/index.ts +11 -5
- package/src/directives/measure.ts +34 -6
- package/src/errors/Errors.state.ts +1 -1
- package/src/errors/Errors.ts +14 -23
- package/src/errors/JobCancelledError.ts +3 -0
- package/src/errors/index.ts +9 -6
- package/src/errors/utils.ts +17 -1
- 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 +72 -0
- package/src/{main.ts → index.ts} +1 -0
- package/src/jobs/Job.ts +144 -2
- package/src/jobs/index.ts +4 -1
- 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 +48 -21
- 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 +1 -1
- package/src/plugins/index.ts +10 -7
- package/src/services/App.state.ts +36 -3
- package/src/services/App.ts +19 -3
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.test.ts +8 -8
- package/src/services/Events.ts +16 -12
- package/src/services/Service.ts +125 -54
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +16 -5
- package/src/services/utils.ts +18 -0
- package/src/testing/index.ts +4 -3
- package/src/testing/setup.ts +11 -0
- package/src/ui/UI.state.ts +14 -12
- package/src/ui/UI.ts +224 -120
- package/src/ui/index.ts +28 -28
- package/src/ui/utils.ts +16 -0
- package/src/utils/classes.ts +49 -0
- package/src/utils/composition/events.ts +4 -6
- 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 -1
- package/src/utils/markdown.test.ts +50 -0
- package/src/utils/markdown.ts +19 -6
- package/src/utils/types.ts +3 -0
- package/src/utils/vue.ts +28 -127
- 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/histoire.config.ts +0 -7
- package/noeldemartin.config.js +0 -5
- package/postcss.config.js +0 -6
- package/src/assets/histoire.css +0 -3
- package/src/components/AGAppLayout.vue +0 -16
- package/src/components/AGAppOverlays.vue +0 -41
- package/src/components/AGAppSnackbars.vue +0 -13
- package/src/components/constants.ts +0 -8
- package/src/components/forms/AGButton.vue +0 -44
- package/src/components/forms/AGCheckbox.vue +0 -41
- package/src/components/forms/AGForm.vue +0 -26
- package/src/components/forms/AGInput.vue +0 -38
- package/src/components/forms/AGSelect.story.vue +0 -46
- package/src/components/forms/AGSelect.vue +0 -60
- package/src/components/forms/index.ts +0 -5
- package/src/components/headless/forms/AGHeadlessButton.vue +0 -51
- package/src/components/headless/forms/AGHeadlessInput.ts +0 -28
- package/src/components/headless/forms/AGHeadlessInput.vue +0 -57
- package/src/components/headless/forms/AGHeadlessInputInput.vue +0 -47
- package/src/components/headless/forms/AGHeadlessSelect.ts +0 -42
- package/src/components/headless/forms/AGHeadlessSelect.vue +0 -77
- package/src/components/headless/forms/AGHeadlessSelectButton.vue +0 -24
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +0 -24
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +0 -4
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +0 -39
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +0 -3
- package/src/components/headless/forms/index.ts +0 -14
- package/src/components/headless/modals/AGHeadlessModal.ts +0 -34
- package/src/components/headless/modals/AGHeadlessModal.vue +0 -86
- 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 -4
- package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +0 -10
- package/src/components/headless/snackbars/index.ts +0 -40
- package/src/components/lib/AGErrorMessage.vue +0 -16
- package/src/components/lib/AGLink.vue +0 -9
- package/src/components/lib/AGMarkdown.vue +0 -36
- package/src/components/lib/AGMeasured.vue +0 -15
- package/src/components/lib/index.ts +0 -5
- package/src/components/modals/AGAlertModal.ts +0 -15
- package/src/components/modals/AGAlertModal.vue +0 -14
- package/src/components/modals/AGConfirmModal.ts +0 -27
- package/src/components/modals/AGConfirmModal.vue +0 -26
- package/src/components/modals/AGErrorReportModal.ts +0 -46
- package/src/components/modals/AGErrorReportModal.vue +0 -54
- package/src/components/modals/AGErrorReportModalTitle.vue +0 -25
- package/src/components/modals/AGLoadingModal.ts +0 -23
- package/src/components/modals/AGLoadingModal.vue +0 -15
- package/src/components/modals/AGModal.ts +0 -10
- package/src/components/modals/AGModal.vue +0 -39
- package/src/components/modals/AGModalContext.ts +0 -8
- package/src/components/modals/AGModalContext.vue +0 -22
- package/src/components/modals/AGModalTitle.vue +0 -9
- package/src/components/modals/AGPromptModal.ts +0 -30
- package/src/components/modals/AGPromptModal.vue +0 -34
- package/src/components/modals/index.ts +0 -17
- package/src/components/snackbars/AGSnackbar.vue +0 -36
- package/src/components/snackbars/index.ts +0 -3
- package/src/components/utils.ts +0 -10
- package/src/directives/initial-focus.ts +0 -11
- package/src/forms/Form.test.ts +0 -58
- package/src/forms/Form.ts +0 -185
- package/src/forms/composition.ts +0 -6
- package/src/main.histoire.ts +0 -1
- package/src/utils/tailwindcss.test.ts +0 -26
- package/src/utils/tailwindcss.ts +0 -7
- package/tailwind.config.js +0 -4
- package/tsconfig.json +0 -11
- package/vite.config.ts +0 -14
|
@@ -1,34 +0,0 @@
|
|
|
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,17 +0,0 @@
|
|
|
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';
|
|
8
|
-
|
|
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';
|
|
@@ -1,36 +0,0 @@
|
|
|
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>
|
package/src/components/utils.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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/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,185 +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
|
-
Object: 'object',
|
|
11
|
-
} as const;
|
|
12
|
-
|
|
13
|
-
export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType, TRules extends string = string> {
|
|
14
|
-
type: TType;
|
|
15
|
-
default?: GetFormFieldValue<TType>;
|
|
16
|
-
rules?: TRules;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
|
|
20
|
-
export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
|
|
21
|
-
export type FormFieldValue = GetFormFieldValue<FormFieldType>;
|
|
22
|
-
|
|
23
|
-
export type FormData<T> = {
|
|
24
|
-
-readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
|
|
25
|
-
? TRules extends 'required'
|
|
26
|
-
? GetFormFieldValue<TType>
|
|
27
|
-
: GetFormFieldValue<TType> | null
|
|
28
|
-
: never;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type FormErrors<T> = {
|
|
32
|
-
[k in keyof T]: string[] | null;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.String
|
|
36
|
-
? string
|
|
37
|
-
: TType extends typeof FormFieldTypes.Number
|
|
38
|
-
? number
|
|
39
|
-
: TType extends typeof FormFieldTypes.Boolean
|
|
40
|
-
? boolean
|
|
41
|
-
: TType extends typeof FormFieldTypes.Object
|
|
42
|
-
? object
|
|
43
|
-
: never;
|
|
44
|
-
|
|
45
|
-
const validForms: WeakMap<Form, ComputedRef<boolean>> = new WeakMap();
|
|
46
|
-
|
|
47
|
-
export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
|
|
48
|
-
|
|
49
|
-
public errors: DeepReadonly<UnwrapNestedRefs<FormErrors<Fields>>>;
|
|
50
|
-
|
|
51
|
-
private _fields: Fields;
|
|
52
|
-
private _data: FormData<Fields>;
|
|
53
|
-
private _submitted: Ref<boolean>;
|
|
54
|
-
private _errors: FormErrors<Fields>;
|
|
55
|
-
|
|
56
|
-
constructor(fields: Fields) {
|
|
57
|
-
super();
|
|
58
|
-
|
|
59
|
-
this._fields = fields;
|
|
60
|
-
this._submitted = ref(false);
|
|
61
|
-
this._data = this.getInitialData(fields);
|
|
62
|
-
this._errors = this.getInitialErrors(fields);
|
|
63
|
-
|
|
64
|
-
validForms.set(
|
|
65
|
-
this,
|
|
66
|
-
computed(() => !Object.values(this._errors).some((error) => error !== null)),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
this.errors = readonly(this._errors);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public get valid(): boolean {
|
|
73
|
-
return !!validForms.get(this)?.value;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public get submitted(): boolean {
|
|
77
|
-
return this._submitted.value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public setFieldValue<T extends keyof Fields>(field: T, value: FormData<Fields>[T]): void {
|
|
81
|
-
this._data[field] = value;
|
|
82
|
-
|
|
83
|
-
if (this._submitted.value) {
|
|
84
|
-
this.validate();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public getFieldValue<T extends keyof Fields>(field: T): GetFormFieldValue<Fields[T]['type']> {
|
|
89
|
-
return this._data[field] as unknown as GetFormFieldValue<Fields[T]['type']>;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public validate(): boolean {
|
|
93
|
-
const errors = Object.entries(this._fields).reduce((formErrors, [name, definition]) => {
|
|
94
|
-
formErrors[name] = this.getFieldErrors(name, definition);
|
|
95
|
-
|
|
96
|
-
return formErrors;
|
|
97
|
-
}, {} as Record<string, string[] | null>);
|
|
98
|
-
|
|
99
|
-
this.resetErrors(errors);
|
|
100
|
-
|
|
101
|
-
return this.valid;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public reset(options: { keepData?: boolean; keepErrors?: boolean } = {}): void {
|
|
105
|
-
this._submitted.value = false;
|
|
106
|
-
|
|
107
|
-
options.keepData || this.resetData();
|
|
108
|
-
options.keepErrors || this.resetErrors();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public submit(): boolean {
|
|
112
|
-
this._submitted.value = true;
|
|
113
|
-
|
|
114
|
-
return this.validate();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
protected __get(property: string): unknown {
|
|
118
|
-
if (!(property in this._fields)) {
|
|
119
|
-
return super.__get(property);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return this._data[property];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
protected __set(property: string, value: unknown): void {
|
|
126
|
-
if (!(property in this._fields)) {
|
|
127
|
-
super.__set(property, value);
|
|
128
|
-
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
Object.assign(this._data, { [property]: value });
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private getFieldErrors(name: keyof Fields, definition: FormFieldDefinition): string[] | null {
|
|
136
|
-
const errors = [];
|
|
137
|
-
|
|
138
|
-
if (definition.rules?.includes('required') && !this._data[name]) {
|
|
139
|
-
errors.push('required');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return errors.length > 0 ? errors : null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private getInitialData(fields: Fields): FormData<Fields> {
|
|
146
|
-
if (this.static().isConjuring()) {
|
|
147
|
-
return {} as FormData<Fields>;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const data = Object.entries(fields).reduce((formData, [name, definition]) => {
|
|
151
|
-
formData[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
|
|
152
|
-
|
|
153
|
-
return formData;
|
|
154
|
-
}, {} as FormData<Fields>);
|
|
155
|
-
|
|
156
|
-
return reactive(data) as FormData<Fields>;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private getInitialErrors(fields: Fields): FormErrors<Fields> {
|
|
160
|
-
if (this.static().isConjuring()) {
|
|
161
|
-
return {} as FormErrors<Fields>;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const errors = Object.keys(fields).reduce((formErrors, name) => {
|
|
165
|
-
formErrors[name as keyof Fields] = null;
|
|
166
|
-
|
|
167
|
-
return formErrors;
|
|
168
|
-
}, {} as FormErrors<Fields>);
|
|
169
|
-
|
|
170
|
-
return reactive(errors) as FormErrors<Fields>;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private resetData(): void {
|
|
174
|
-
for (const [name, field] of Object.entries(this._fields)) {
|
|
175
|
-
this._data[name as keyof Fields] = (field.default ?? null) as FormData<Fields>[keyof Fields];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
private resetErrors(errors?: Record<string, string[] | null>): void {
|
|
180
|
-
Object.keys(this._errors).forEach((key) => delete this._errors[key as keyof Fields]);
|
|
181
|
-
|
|
182
|
-
errors && Object.assign(this._errors, errors);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
}
|
package/src/forms/composition.ts
DELETED
package/src/main.histoire.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './assets/histoire.css';
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { removeInteractiveClasses } from './tailwindcss';
|
|
4
|
-
|
|
5
|
-
describe('TailwindCSS utils', () => {
|
|
6
|
-
|
|
7
|
-
it('Removes interactive classes', () => {
|
|
8
|
-
const cases: [string, string][] = [
|
|
9
|
-
['text-red hover:text-green', 'text-red'],
|
|
10
|
-
['text-red hover:text-green text-lg', 'text-red text-lg'],
|
|
11
|
-
[
|
|
12
|
-
`
|
|
13
|
-
text-red text-lg
|
|
14
|
-
focus:text-yellow
|
|
15
|
-
hover:focus:text-black
|
|
16
|
-
`,
|
|
17
|
-
'text-red text-lg',
|
|
18
|
-
],
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
cases.forEach(([original, expected]) => {
|
|
22
|
-
expect(removeInteractiveClasses(original)).toEqual(expected);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
});
|
package/src/utils/tailwindcss.ts
DELETED
package/tailwind.config.js
DELETED
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Aerogel from '@aerogel/vite';
|
|
2
|
-
import Icons from 'unplugin-icons/vite';
|
|
3
|
-
import { defineConfig } from 'vitest/config';
|
|
4
|
-
import { resolve } from 'path';
|
|
5
|
-
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
test: { clearMocks: true },
|
|
8
|
-
plugins: [Aerogel(), Icons()],
|
|
9
|
-
resolve: {
|
|
10
|
-
alias: {
|
|
11
|
-
'@': resolve(__dirname, './src'),
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
});
|