@aerogel/core 0.0.0-next.f86b4b09f066c4aef21796a37dbc8417b7dce3cd → 0.0.0-next.f8c757d83e1e0d001a2836fa45aba318ec17b9b9
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 +1973 -1688
- package/dist/aerogel-core.js +3234 -0
- package/dist/aerogel-core.js.map +1 -0
- package/package.json +30 -37
- package/src/bootstrap/bootstrap.test.ts +4 -7
- package/src/bootstrap/index.ts +14 -15
- package/src/bootstrap/options.ts +1 -1
- package/src/components/{AGAppLayout.vue → AppLayout.vue} +4 -4
- package/src/components/{AGAppModals.vue → AppModals.vue} +3 -4
- package/src/components/{AGAppOverlays.vue → AppOverlays.vue} +5 -10
- package/src/components/AppToasts.vue +16 -0
- package/src/components/contracts/AlertModal.ts +4 -0
- package/src/components/contracts/Button.ts +16 -0
- package/src/components/contracts/ConfirmModal.ts +41 -0
- package/src/components/contracts/DropdownMenu.ts +18 -0
- package/src/components/contracts/ErrorReportModal.ts +29 -0
- package/src/components/contracts/Input.ts +26 -0
- package/src/components/contracts/LoadingModal.ts +18 -0
- package/src/components/contracts/Modal.ts +13 -0
- package/src/components/contracts/PromptModal.ts +30 -0
- package/src/components/contracts/Select.ts +44 -0
- package/src/components/contracts/Toast.ts +13 -0
- package/src/components/contracts/index.ts +9 -0
- package/src/components/contracts/shared.ts +9 -0
- package/src/components/headless/HeadlessButton.vue +51 -0
- package/src/components/headless/HeadlessInput.vue +59 -0
- package/src/components/headless/{forms/AGHeadlessInputDescription.vue → HeadlessInputDescription.vue} +7 -8
- package/src/components/headless/{forms/AGHeadlessInputError.vue → HeadlessInputError.vue} +4 -8
- package/src/components/headless/{forms/AGHeadlessInputInput.vue → HeadlessInputInput.vue} +16 -25
- package/src/components/headless/{forms/AGHeadlessInputLabel.vue → HeadlessInputLabel.vue} +3 -7
- package/src/components/headless/{forms/AGHeadlessInputTextArea.vue → HeadlessInputTextArea.vue} +10 -13
- package/src/components/headless/{modals/AGHeadlessModal.vue → HeadlessModal.vue} +18 -18
- package/src/components/headless/HeadlessModalContent.vue +24 -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 +113 -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 +37 -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 -11
- package/src/components/ui/AdvancedOptions.vue +18 -0
- package/src/components/ui/AlertModal.vue +13 -0
- package/src/components/ui/Button.vue +98 -0
- package/src/components/ui/Checkbox.vue +56 -0
- package/src/components/ui/ConfirmModal.vue +42 -0
- package/src/components/ui/DropdownMenu.vue +27 -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 +62 -0
- package/src/components/{modals/AGErrorReportModalButtons.vue → ui/ErrorReportModalButtons.vue} +34 -27
- package/src/components/ui/ErrorReportModalTitle.vue +24 -0
- package/src/components/{forms/AGForm.vue → ui/Form.vue} +4 -5
- package/src/components/ui/Input.vue +56 -0
- package/src/components/ui/Link.vue +12 -0
- package/src/components/ui/LoadingModal.vue +32 -0
- package/src/components/ui/Markdown.vue +69 -0
- package/src/components/ui/Modal.vue +75 -0
- package/src/components/ui/ModalContext.vue +30 -0
- package/src/components/ui/ProgressBar.vue +50 -0
- package/src/components/ui/PromptModal.vue +35 -0
- package/src/components/ui/Select.vue +25 -0
- package/src/components/ui/SelectLabel.vue +17 -0
- package/src/components/ui/SelectOption.vue +29 -0
- package/src/components/ui/SelectOptions.vue +30 -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 +42 -0
- package/src/components/ui/index.ts +30 -0
- package/src/directives/index.ts +9 -5
- package/src/directives/measure.ts +1 -1
- package/src/errors/Errors.state.ts +1 -1
- package/src/errors/Errors.ts +17 -18
- package/src/errors/JobCancelledError.ts +3 -0
- package/src/errors/index.ts +9 -6
- package/src/errors/utils.ts +1 -1
- package/src/forms/{Form.test.ts → FormController.test.ts} +5 -4
- package/src/forms/{Form.ts → FormController.ts} +22 -19
- package/src/forms/composition.ts +4 -4
- package/src/forms/index.ts +2 -2
- package/src/forms/utils.ts +2 -2
- package/src/index.css +46 -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 +7 -4
- package/src/lang/Lang.state.ts +1 -1
- package/src/lang/Lang.ts +1 -1
- package/src/lang/index.ts +11 -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 +21 -5
- package/src/services/App.ts +7 -4
- package/src/services/Cache.ts +1 -1
- package/src/services/Events.ts +15 -5
- package/src/services/Service.ts +116 -53
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +14 -5
- package/src/services/utils.ts +18 -0
- package/src/testing/index.ts +4 -3
- package/src/testing/setup.ts +5 -13
- package/src/ui/UI.state.ts +12 -7
- package/src/ui/UI.ts +126 -84
- package/src/ui/index.ts +18 -18
- package/src/utils/classes.ts +49 -0
- package/src/utils/composition/events.ts +2 -2
- package/src/utils/composition/forms.ts +14 -4
- package/src/utils/composition/persistent.test.ts +33 -0
- package/src/utils/composition/persistent.ts +11 -0
- package/src/utils/composition/state.ts +11 -2
- package/src/utils/index.ts +4 -1
- package/src/utils/markdown.test.ts +50 -0
- package/src/utils/markdown.ts +19 -6
- package/src/utils/vue.ts +28 -136
- 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/AGAppSnackbars.vue +0 -13
- package/src/components/composition.ts +0 -23
- 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/AGInput.vue +0 -40
- 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.ts +0 -3
- package/src/components/headless/forms/AGHeadlessButton.vue +0 -62
- package/src/components/headless/forms/AGHeadlessInput.ts +0 -34
- package/src/components/headless/forms/AGHeadlessInput.vue +0 -70
- 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/composition.ts +0 -10
- package/src/components/headless/forms/index.ts +0 -18
- package/src/components/headless/modals/AGHeadlessModal.ts +0 -34
- 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/interfaces.ts +0 -24
- package/src/components/lib/AGErrorMessage.vue +0 -16
- package/src/components/lib/AGLink.vue +0 -9
- package/src/components/lib/AGMarkdown.vue +0 -41
- package/src/components/lib/AGMeasured.vue +0 -16
- 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 -35
- 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 -36
- 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/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 -17
- /package/src/{main.ts → index.ts} +0 -0
package/src/directives/index.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { Directive } from 'vue';
|
|
2
2
|
|
|
3
|
-
import { definePlugin } from '
|
|
3
|
+
import { definePlugin } from '@aerogel/core/plugins';
|
|
4
4
|
|
|
5
|
-
import initialFocus from './initial-focus';
|
|
6
5
|
import measure from './measure';
|
|
7
6
|
|
|
8
7
|
const builtInDirectives: Record<string, Directive> = {
|
|
9
|
-
|
|
10
|
-
'measure': measure,
|
|
8
|
+
measure: measure,
|
|
11
9
|
};
|
|
12
10
|
|
|
13
11
|
export * from './measure';
|
|
@@ -25,8 +23,14 @@ export default definePlugin({
|
|
|
25
23
|
},
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
declare module '
|
|
26
|
+
declare module '@aerogel/core/bootstrap/options' {
|
|
29
27
|
export interface AerogelOptions {
|
|
30
28
|
directives?: Record<string, Directive>;
|
|
31
29
|
}
|
|
32
30
|
}
|
|
31
|
+
|
|
32
|
+
declare module 'vue' {
|
|
33
|
+
interface ComponentCustomDirectives {
|
|
34
|
+
measure: Directive<string, string>;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/errors/Errors.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { JSError, facade, isObject, objectWithoutEmpty, toString } from '@noeldemartin/utils';
|
|
1
|
+
import { JSError, facade, isDevelopment, isObject, isTesting, objectWithoutEmpty, toString } from '@noeldemartin/utils';
|
|
2
2
|
|
|
3
|
-
import App from '
|
|
4
|
-
import ServiceBootError from '
|
|
5
|
-
import UI, { UIComponents } from '
|
|
6
|
-
import { translateWithDefault } from '
|
|
3
|
+
import App from '@aerogel/core/services/App';
|
|
4
|
+
import ServiceBootError from '@aerogel/core/errors/ServiceBootError';
|
|
5
|
+
import UI, { UIComponents } from '@aerogel/core/ui/UI';
|
|
6
|
+
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
7
|
+
import { Events } from '@aerogel/core/services';
|
|
8
|
+
import type { ErrorReportModalProps } from '@aerogel/core/components/contracts/ErrorReportModal';
|
|
9
|
+
import type { ModalComponent } from '@aerogel/core/ui/UI.state';
|
|
7
10
|
|
|
8
11
|
import Service from './Errors.state';
|
|
9
|
-
import { Colors } from '@/components/constants';
|
|
10
|
-
import { Events } from '@/services';
|
|
11
|
-
import type { AGErrorReportModalProps } from '@/components/modals/AGErrorReportModal';
|
|
12
12
|
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
13
|
-
import type { ModalComponent } from '@/ui/UI.state';
|
|
14
13
|
|
|
15
14
|
export class ErrorsService extends Service {
|
|
16
15
|
|
|
@@ -34,7 +33,7 @@ export class ErrorsService extends Service {
|
|
|
34
33
|
return;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
UI.openModal<ModalComponent<
|
|
36
|
+
UI.openModal<ModalComponent<ErrorReportModalProps>>(UI.requireComponent(UIComponents.ErrorReportModal), {
|
|
38
37
|
reports,
|
|
39
38
|
});
|
|
40
39
|
}
|
|
@@ -42,11 +41,11 @@ export class ErrorsService extends Service {
|
|
|
42
41
|
public async report(error: ErrorSource, message?: string): Promise<void> {
|
|
43
42
|
await Events.emit('error', { error, message });
|
|
44
43
|
|
|
45
|
-
if (
|
|
44
|
+
if (isTesting('unit')) {
|
|
46
45
|
throw error;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
if (
|
|
48
|
+
if (isDevelopment()) {
|
|
50
49
|
this.logError(error);
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -71,17 +70,17 @@ export class ErrorsService extends Service {
|
|
|
71
70
|
date: new Date(),
|
|
72
71
|
};
|
|
73
72
|
|
|
74
|
-
UI.
|
|
73
|
+
UI.toast(
|
|
75
74
|
message ??
|
|
76
75
|
translateWithDefault('errors.notice', 'Something went wrong, but it\'s not your fault. Try again!'),
|
|
77
76
|
{
|
|
78
|
-
|
|
77
|
+
variant: 'danger',
|
|
79
78
|
actions: [
|
|
80
79
|
{
|
|
81
|
-
|
|
80
|
+
label: translateWithDefault('errors.viewDetails', 'View details'),
|
|
82
81
|
dismiss: true,
|
|
83
|
-
|
|
84
|
-
UI.openModal<ModalComponent<
|
|
82
|
+
click: () =>
|
|
83
|
+
UI.openModal<ModalComponent<ErrorReportModalProps>>(
|
|
85
84
|
UI.requireComponent(UIComponents.ErrorReportModal),
|
|
86
85
|
{ reports: [report] },
|
|
87
86
|
),
|
|
@@ -178,7 +177,7 @@ export class ErrorsService extends Service {
|
|
|
178
177
|
|
|
179
178
|
export default facade(ErrorsService);
|
|
180
179
|
|
|
181
|
-
declare module '
|
|
180
|
+
declare module '@aerogel/core/services/Events' {
|
|
182
181
|
export interface EventsPayload {
|
|
183
182
|
error: { error: ErrorSource; message?: string };
|
|
184
183
|
}
|
package/src/errors/index.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { App } from 'vue';
|
|
2
2
|
|
|
3
|
-
import { bootServices } from '
|
|
4
|
-
import { definePlugin } from '
|
|
3
|
+
import { bootServices } from '@aerogel/core/services';
|
|
4
|
+
import { definePlugin } from '@aerogel/core/plugins';
|
|
5
5
|
|
|
6
6
|
import Errors from './Errors';
|
|
7
|
-
import { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
7
|
+
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
8
8
|
|
|
9
9
|
export * from './utils';
|
|
10
|
-
export { Errors
|
|
10
|
+
export { Errors };
|
|
11
|
+
export { default as JobCancelledError } from './JobCancelledError';
|
|
12
|
+
export { default as ServiceBootError } from './ServiceBootError';
|
|
13
|
+
export type { ErrorSource, ErrorReport, ErrorReportLog };
|
|
11
14
|
|
|
12
15
|
const services = { $errors: Errors };
|
|
13
16
|
const frameworkHandler: ErrorHandler = (error) => {
|
|
@@ -35,12 +38,12 @@ export default definePlugin({
|
|
|
35
38
|
},
|
|
36
39
|
});
|
|
37
40
|
|
|
38
|
-
declare module '
|
|
41
|
+
declare module '@aerogel/core/bootstrap/options' {
|
|
39
42
|
export interface AerogelOptions {
|
|
40
43
|
handleError?(error: ErrorSource): boolean;
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
declare module '
|
|
47
|
+
declare module '@aerogel/core/services' {
|
|
45
48
|
export interface Services extends ErrorsServices {}
|
|
46
49
|
}
|
package/src/errors/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSError, isObject, toString } from '@noeldemartin/utils';
|
|
2
|
-
import { translateWithDefault } from '
|
|
2
|
+
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
3
3
|
import type { ErrorSource } from './Errors.state';
|
|
4
4
|
|
|
5
5
|
const handlers: ErrorHandler[] = [];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { useForm } from '
|
|
4
|
-
import {
|
|
5
|
-
import { numberInput, requiredStringInput } from '@/forms/utils';
|
|
3
|
+
import { useForm } from '@aerogel/core/forms/composition';
|
|
4
|
+
import { numberInput, requiredStringInput } from '@aerogel/core/forms/utils';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
import { FormFieldTypes } from './FormController';
|
|
7
|
+
|
|
8
|
+
describe('FormController', () => {
|
|
8
9
|
|
|
9
10
|
it('defines magic fields', () => {
|
|
10
11
|
const form = useForm({
|
|
@@ -38,21 +38,21 @@ export type FormErrors<T> = {
|
|
|
38
38
|
export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.String
|
|
39
39
|
? string
|
|
40
40
|
: TType extends typeof FormFieldTypes.Number
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
? number
|
|
42
|
+
: TType extends typeof FormFieldTypes.Boolean
|
|
43
|
+
? boolean
|
|
44
|
+
: TType extends typeof FormFieldTypes.Object
|
|
45
|
+
? object
|
|
46
|
+
: TType extends typeof FormFieldTypes.Date
|
|
47
|
+
? Date
|
|
48
|
+
: never;
|
|
49
49
|
|
|
50
|
-
const validForms: WeakMap<
|
|
50
|
+
const validForms: WeakMap<FormController, ComputedRef<boolean>> = new WeakMap();
|
|
51
51
|
|
|
52
52
|
export type SubmitFormListener = () => unknown;
|
|
53
53
|
export type FocusFormListener = (input: string) => unknown;
|
|
54
54
|
|
|
55
|
-
export default class
|
|
55
|
+
export default class FormController<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
|
|
56
56
|
|
|
57
57
|
public errors: DeepReadonly<UnwrapNestedRefs<FormErrors<Fields>>>;
|
|
58
58
|
|
|
@@ -113,11 +113,14 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
public validate(): boolean {
|
|
116
|
-
const errors = Object.entries(this._fields).reduce(
|
|
117
|
-
formErrors[name
|
|
116
|
+
const errors = Object.entries(this._fields).reduce(
|
|
117
|
+
(formErrors, [name, definition]) => {
|
|
118
|
+
formErrors[name] = this.getFieldErrors(name, definition);
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
return formErrors;
|
|
121
|
+
},
|
|
122
|
+
{} as Record<string, string[] | null>,
|
|
123
|
+
);
|
|
121
124
|
|
|
122
125
|
this.resetErrors(errors);
|
|
123
126
|
|
|
@@ -165,7 +168,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
165
168
|
this._listeners['focus']?.forEach((listener) => listener(input));
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
protected __get(property: string): unknown {
|
|
171
|
+
protected override __get(property: string): unknown {
|
|
169
172
|
if (!(property in this._fields)) {
|
|
170
173
|
return super.__get(property);
|
|
171
174
|
}
|
|
@@ -173,7 +176,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
173
176
|
return this.getFieldValue(property);
|
|
174
177
|
}
|
|
175
178
|
|
|
176
|
-
protected __set(property: string, value: unknown): void {
|
|
179
|
+
protected override __set(property: string, value: unknown): void {
|
|
177
180
|
if (!(property in this._fields)) {
|
|
178
181
|
super.__set(property, value);
|
|
179
182
|
|
|
@@ -204,10 +207,10 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
|
|
|
204
207
|
return {} as FormData<Fields>;
|
|
205
208
|
}
|
|
206
209
|
|
|
207
|
-
const data = Object.entries(fields).reduce((
|
|
208
|
-
|
|
210
|
+
const data = Object.entries(fields).reduce((initialData, [name, definition]) => {
|
|
211
|
+
initialData[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
|
|
209
212
|
|
|
210
|
-
return
|
|
213
|
+
return initialData;
|
|
211
214
|
}, {} as FormData<Fields>);
|
|
212
215
|
|
|
213
216
|
return reactive(data) as FormData<Fields>;
|
package/src/forms/composition.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { FormData, FormFieldDefinitions } from '
|
|
1
|
+
import FormController from '@aerogel/core/forms/FormController';
|
|
2
|
+
import type { FormData, FormFieldDefinitions } from '@aerogel/core/forms/FormController';
|
|
3
3
|
|
|
4
|
-
export function useForm<const T extends FormFieldDefinitions>(fields: T):
|
|
5
|
-
return new
|
|
4
|
+
export function useForm<const T extends FormFieldDefinitions>(fields: T): FormController<T> & FormData<T> {
|
|
5
|
+
return new FormController(fields) as FormController<T> & FormData<T>;
|
|
6
6
|
}
|
package/src/forms/index.ts
CHANGED
package/src/forms/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FormFieldTypes } from './
|
|
2
|
-
import type { FormFieldDefinition } from './
|
|
1
|
+
import { FormFieldTypes } from './FormController';
|
|
2
|
+
import type { FormFieldDefinition } from './FormController';
|
|
3
3
|
|
|
4
4
|
export function booleanInput(
|
|
5
5
|
defaultValue?: boolean,
|
package/src/index.css
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@import 'tailwindcss';
|
|
2
|
+
|
|
3
|
+
@source './';
|
|
4
|
+
@source '../../plugin-local-first/src';
|
|
5
|
+
@source '../../plugin-solid/src';
|
|
6
|
+
|
|
7
|
+
@plugin '@tailwindcss/forms';
|
|
8
|
+
@plugin '@tailwindcss/typography';
|
|
9
|
+
|
|
10
|
+
@theme {
|
|
11
|
+
--color-background: oklch(1 0 0);
|
|
12
|
+
--color-primary: oklch(0.205 0 0);
|
|
13
|
+
--color-danger: oklch(0.577 0.245 27.325);
|
|
14
|
+
--color-accent: oklch(0.97 0 0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.clickable {
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.clickable::after {
|
|
22
|
+
--clickable-size: 44px;
|
|
23
|
+
--clickable-inset-by: min(0px, calc((100% - var(--clickable-size)) / 2));
|
|
24
|
+
|
|
25
|
+
content: '';
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: var(--clickable-inset-by);
|
|
28
|
+
left: var(--clickable-inset-by);
|
|
29
|
+
right: var(--clickable-inset-by);
|
|
30
|
+
bottom: var(--clickable-inset-by);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
input[type='number'].appearance-textfield {
|
|
34
|
+
appearance: textfield;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
input[type='number'].appearance-textfield::-webkit-outer-spin-button,
|
|
38
|
+
input[type='number'].appearance-textfield::-webkit-inner-spin-button {
|
|
39
|
+
appearance: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
button[data-markdown-action] {
|
|
43
|
+
color: var(--tw-prose-links);
|
|
44
|
+
text-decoration: underline;
|
|
45
|
+
font-weight: 500;
|
|
46
|
+
}
|
package/src/jobs/Job.ts
CHANGED
|
@@ -1,5 +1,147 @@
|
|
|
1
|
-
|
|
1
|
+
import { ListenersManager, PromisedValue, round, tap, toError } from '@noeldemartin/utils';
|
|
2
|
+
import type { Listeners } from '@noeldemartin/utils';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import JobCancelledError from '@aerogel/core/errors/JobCancelledError';
|
|
5
|
+
|
|
6
|
+
import type { JobListener } from './listeners';
|
|
7
|
+
import type { JobStatus } from './status';
|
|
8
|
+
|
|
9
|
+
export default abstract class Job<
|
|
10
|
+
Listener extends JobListener = JobListener,
|
|
11
|
+
Status extends JobStatus = JobStatus,
|
|
12
|
+
SerializedStatus extends JobStatus = JobStatus,
|
|
13
|
+
> {
|
|
14
|
+
|
|
15
|
+
protected status: Status;
|
|
16
|
+
protected _listeners: ListenersManager<JobListener>;
|
|
17
|
+
protected _progress?: number;
|
|
18
|
+
protected _cancelled?: PromisedValue<void>;
|
|
19
|
+
protected _started: PromisedValue<void>;
|
|
20
|
+
protected _completed: PromisedValue<void>;
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.status = this.getInitialStatus();
|
|
24
|
+
this._listeners = new ListenersManager();
|
|
25
|
+
this._started = new PromisedValue();
|
|
26
|
+
this._completed = new PromisedValue();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async start(): Promise<void> {
|
|
30
|
+
this.beforeStart();
|
|
31
|
+
this._started.resolve();
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
await this.updateProgress();
|
|
35
|
+
await this.run();
|
|
36
|
+
await this.updateProgress();
|
|
37
|
+
|
|
38
|
+
this._completed.resolve();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof JobCancelledError) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw tap(toError(error), (realError) => {
|
|
45
|
+
this._completed.reject(realError);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async cancel(): Promise<void> {
|
|
51
|
+
this._cancelled = new PromisedValue();
|
|
52
|
+
|
|
53
|
+
await this._cancelled;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public serialize(): SerializedStatus {
|
|
57
|
+
return this.serializeStatus(this.status);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public get listeners(): Listeners<Listener> {
|
|
61
|
+
return this._listeners;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get progress(): number {
|
|
65
|
+
return this._progress ?? 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public get cancelled(): boolean {
|
|
69
|
+
return !!this._cancelled?.isResolved();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public get started(): Promise<void> {
|
|
73
|
+
return this._started;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public get completed(): Promise<void> {
|
|
77
|
+
return this._completed;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected abstract run(): Promise<void>;
|
|
81
|
+
|
|
82
|
+
protected getInitialStatus(): Status {
|
|
83
|
+
return { completed: false } as Status;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
protected beforeStart(): void {
|
|
87
|
+
if (!this._started.isResolved()) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (this._cancelled) {
|
|
92
|
+
delete this._progress;
|
|
93
|
+
delete this._cancelled;
|
|
94
|
+
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
throw new Error('Job already started!');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected assertNotCancelled(): void {
|
|
102
|
+
if (!this._cancelled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this._cancelled.resolve();
|
|
107
|
+
|
|
108
|
+
throw new JobCancelledError();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
protected calculateCurrentProgress(status?: JobStatus): number {
|
|
112
|
+
status ??= this.status;
|
|
113
|
+
|
|
114
|
+
if (status.completed) {
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (!status.children) {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return round(
|
|
123
|
+
status.children.reduce((total, child) => total + this.calculateCurrentProgress(child), 0) /
|
|
124
|
+
status.children.length,
|
|
125
|
+
2,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected async updateProgress(update?: (status: Status) => unknown): Promise<void> {
|
|
130
|
+
await update?.(this.status);
|
|
131
|
+
|
|
132
|
+
const progress = this.calculateCurrentProgress();
|
|
133
|
+
|
|
134
|
+
if (progress === this._progress) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this._progress = progress;
|
|
139
|
+
|
|
140
|
+
await this._listeners.emit('onUpdated', progress);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
protected serializeStatus(status: Status): SerializedStatus {
|
|
144
|
+
return { ...status } as unknown as SerializedStatus;
|
|
145
|
+
}
|
|
4
146
|
|
|
5
147
|
}
|
package/src/jobs/index.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isDevelopment } from '@noeldemartin/utils';
|
|
2
2
|
|
|
3
3
|
import type { LangProvider } from './Lang';
|
|
4
4
|
|
|
5
5
|
export default class DefaultLangProvider implements LangProvider {
|
|
6
6
|
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(
|
|
8
|
+
private locale: string,
|
|
9
|
+
private fallbackLocale: string,
|
|
10
|
+
) {}
|
|
8
11
|
|
|
9
12
|
public getLocale(): string {
|
|
10
13
|
return this.locale;
|
|
@@ -28,14 +31,14 @@ export default class DefaultLangProvider implements LangProvider {
|
|
|
28
31
|
|
|
29
32
|
public translate(key: string): string {
|
|
30
33
|
// eslint-disable-next-line no-console
|
|
31
|
-
|
|
34
|
+
isDevelopment() && console.warn('Lang provider is missing');
|
|
32
35
|
|
|
33
36
|
return key;
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
public translateWithDefault(_: string, defaultMessage: string): string {
|
|
37
40
|
// eslint-disable-next-line no-console
|
|
38
|
-
|
|
41
|
+
isDevelopment() && console.warn('Lang provider is missing');
|
|
39
42
|
|
|
40
43
|
return defaultMessage;
|
|
41
44
|
}
|
package/src/lang/Lang.state.ts
CHANGED
package/src/lang/Lang.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class LangService extends Service {
|
|
|
52
52
|
return navigator.languages.find((locale) => locales.includes(locale)) ?? 'en';
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
protected async boot(): Promise<void> {
|
|
55
|
+
protected override async boot(): Promise<void> {
|
|
56
56
|
if (!globalThis.document) {
|
|
57
57
|
return;
|
|
58
58
|
}
|
package/src/lang/index.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import App from '@aerogel/core/services/App';
|
|
2
|
+
import { bootServices } from '@aerogel/core/services';
|
|
3
|
+
import { definePlugin } from '@aerogel/core/plugins';
|
|
3
4
|
|
|
4
|
-
import Lang
|
|
5
|
+
import Lang from './Lang';
|
|
6
|
+
import settings from './settings';
|
|
7
|
+
import type { LangProvider } from './Lang';
|
|
5
8
|
import { translate, translateWithDefault } from './utils';
|
|
6
9
|
|
|
7
|
-
export { Lang,
|
|
10
|
+
export { Lang, translate, translateWithDefault };
|
|
11
|
+
export type { LangProvider };
|
|
8
12
|
|
|
9
13
|
const services = { $lang: Lang };
|
|
10
14
|
|
|
@@ -14,16 +18,17 @@ export default definePlugin({
|
|
|
14
18
|
async install(app) {
|
|
15
19
|
app.config.globalProperties.$t ??= translate;
|
|
16
20
|
app.config.globalProperties.$td = translateWithDefault;
|
|
21
|
+
App.settings.push(...settings);
|
|
17
22
|
|
|
18
23
|
await bootServices(app, services);
|
|
19
24
|
},
|
|
20
25
|
});
|
|
21
26
|
|
|
22
|
-
declare module '
|
|
27
|
+
declare module '@aerogel/core/services' {
|
|
23
28
|
export interface Services extends LangServices {}
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
declare module '
|
|
31
|
+
declare module 'vue' {
|
|
27
32
|
interface ComponentCustomProperties {
|
|
28
33
|
$td: typeof translateWithDefault;
|
|
29
34
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Select
|
|
3
|
+
v-model="$lang.locale"
|
|
4
|
+
class="flex flex-col items-start md:flex-row"
|
|
5
|
+
as="div"
|
|
6
|
+
:options
|
|
7
|
+
:render-option="renderLocale"
|
|
8
|
+
>
|
|
9
|
+
<div class="grow">
|
|
10
|
+
<SelectLabel>
|
|
11
|
+
{{ $td('settings.locale', 'Language') }}
|
|
12
|
+
</SelectLabel>
|
|
13
|
+
<Markdown
|
|
14
|
+
lang-key="settings.localeDescription"
|
|
15
|
+
lang-default="Choose the application's language."
|
|
16
|
+
class="mt-1 text-sm text-gray-500"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
<Button variant="ghost" :as="SelectTrigger" class="w-auto outline-none" />
|
|
20
|
+
<SelectOptions />
|
|
21
|
+
</Select>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script setup lang="ts">
|
|
25
|
+
import Aerogel from 'virtual:aerogel';
|
|
26
|
+
|
|
27
|
+
import { computed } from 'vue';
|
|
28
|
+
|
|
29
|
+
import Markdown from '@aerogel/core/components/ui/Markdown.vue';
|
|
30
|
+
import Button from '@aerogel/core/components/ui/Button.vue';
|
|
31
|
+
import Select from '@aerogel/core/components/ui/Select.vue';
|
|
32
|
+
import SelectLabel from '@aerogel/core/components/ui/SelectLabel.vue';
|
|
33
|
+
import SelectTrigger from '@aerogel/core/components/ui/SelectTrigger.vue';
|
|
34
|
+
import SelectOptions from '@aerogel/core/components/ui/SelectOptions.vue';
|
|
35
|
+
import { Lang, translateWithDefault } from '@aerogel/core/lang';
|
|
36
|
+
|
|
37
|
+
const browserLocale = Lang.getBrowserLocale();
|
|
38
|
+
const options = computed(() => [null, ...Lang.locales]);
|
|
39
|
+
|
|
40
|
+
function renderLocale(locale: string | null): string {
|
|
41
|
+
return (
|
|
42
|
+
(locale && Aerogel.locales[locale]) ??
|
|
43
|
+
translateWithDefault('settings.localeDefault', '{locale} (default)', {
|
|
44
|
+
locale: Aerogel.locales[browserLocale] ?? browserLocale,
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
</script>
|