@aerogel/core 0.0.0-next.c8f032a868370824898e171969aec1bb6827688e → 0.0.0-next.f16bd1d894543c5303039c49f6f33488a1ffe931

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.
Files changed (64) hide show
  1. package/dist/aerogel-core.cjs.js +1 -1
  2. package/dist/aerogel-core.cjs.js.map +1 -1
  3. package/dist/aerogel-core.d.ts +501 -83
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/dist/virtual.d.ts +11 -0
  7. package/noeldemartin.config.js +4 -1
  8. package/package.json +3 -2
  9. package/src/bootstrap/index.ts +4 -1
  10. package/src/components/AGAppModals.vue +15 -0
  11. package/src/components/AGAppOverlays.vue +5 -7
  12. package/src/components/AGAppSnackbars.vue +13 -0
  13. package/src/components/basic/AGMarkdown.vue +10 -5
  14. package/src/components/constants.ts +8 -0
  15. package/src/components/forms/AGButton.vue +33 -10
  16. package/src/components/forms/AGCheckbox.vue +35 -0
  17. package/src/components/forms/AGInput.vue +8 -4
  18. package/src/components/forms/index.ts +2 -1
  19. package/src/components/headless/forms/AGHeadlessButton.vue +3 -4
  20. package/src/components/headless/forms/AGHeadlessInput.ts +2 -2
  21. package/src/components/headless/forms/AGHeadlessInput.vue +3 -3
  22. package/src/components/headless/forms/AGHeadlessInputError.vue +1 -1
  23. package/src/components/headless/forms/AGHeadlessInputInput.vue +15 -3
  24. package/src/components/headless/index.ts +1 -0
  25. package/src/components/headless/modals/AGHeadlessModalPanel.vue +5 -1
  26. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  27. package/src/components/headless/snackbars/index.ts +25 -0
  28. package/src/components/index.ts +2 -0
  29. package/src/components/modals/AGConfirmModal.vue +1 -1
  30. package/src/components/modals/AGErrorReportModal.ts +20 -0
  31. package/src/components/modals/AGErrorReportModal.vue +62 -0
  32. package/src/components/modals/AGErrorReportModalButtons.vue +106 -0
  33. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  34. package/src/components/modals/AGLoadingModal.vue +19 -0
  35. package/src/components/modals/AGModal.vue +21 -3
  36. package/src/components/modals/index.ts +16 -2
  37. package/src/components/snackbars/AGSnackbar.vue +42 -0
  38. package/src/components/snackbars/index.ts +3 -0
  39. package/src/directives/index.ts +16 -3
  40. package/src/errors/Errors.state.ts +31 -0
  41. package/src/errors/Errors.ts +161 -0
  42. package/src/errors/index.ts +59 -0
  43. package/src/forms/Form.test.ts +21 -0
  44. package/src/forms/Form.ts +20 -10
  45. package/src/forms/utils.ts +17 -0
  46. package/src/lang/Lang.ts +11 -3
  47. package/src/lang/index.ts +3 -5
  48. package/src/lang/utils.ts +4 -0
  49. package/src/main.ts +1 -2
  50. package/src/services/App.state.ts +7 -1
  51. package/src/services/App.ts +11 -1
  52. package/src/services/Service.ts +126 -44
  53. package/src/services/index.ts +18 -4
  54. package/src/services/store.ts +27 -0
  55. package/src/types/virtual.d.ts +11 -0
  56. package/src/ui/UI.state.ts +11 -1
  57. package/src/ui/UI.ts +52 -6
  58. package/src/ui/index.ts +7 -1
  59. package/src/utils/composition/forms.ts +11 -0
  60. package/src/utils/index.ts +1 -0
  61. package/src/utils/vue.ts +2 -0
  62. package/tsconfig.json +1 -0
  63. package/vite.config.ts +2 -1
  64. package/src/globals.ts +0 -6
@@ -34,4 +34,25 @@ describe('Form', () => {
34
34
  expect(form.errors.name).toEqual(['required']);
35
35
  });
36
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
+
37
58
  });
package/src/forms/Form.ts CHANGED
@@ -6,6 +6,7 @@ import type { ComputedRef, DeepReadonly, Ref, UnwrapNestedRefs } from 'vue';
6
6
  export const FormFieldTypes = {
7
7
  String: 'string',
8
8
  Number: 'number',
9
+ Boolean: 'boolean',
9
10
  } as const;
10
11
 
11
12
  export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType, TRules extends string = string> {
@@ -18,7 +19,7 @@ export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
18
19
  export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
19
20
 
20
21
  export type FormData<T> = {
21
- [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
22
+ -readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
22
23
  ? TRules extends 'required'
23
24
  ? GetFormFieldValue<TType>
24
25
  : GetFormFieldValue<TType> | null
@@ -33,6 +34,8 @@ export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.Strin
33
34
  ? string
34
35
  : TType extends typeof FormFieldTypes.Number
35
36
  ? number
37
+ : TType extends typeof FormFieldTypes.Boolean
38
+ ? boolean
36
39
  : never;
37
40
 
38
41
  export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
@@ -78,10 +81,10 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
78
81
  }
79
82
 
80
83
  public validate(): boolean {
81
- const errors = Object.entries(this._fields).reduce((errors, [name, definition]) => {
82
- errors[name] = this.getFieldErrors(name, definition);
84
+ const errors = Object.entries(this._fields).reduce((formErrors, [name, definition]) => {
85
+ formErrors[name] = this.getFieldErrors(name, definition);
83
86
 
84
- return errors;
87
+ return formErrors;
85
88
  }, {} as Record<string, string[] | null>);
86
89
 
87
90
  this.resetErrors(errors);
@@ -92,6 +95,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
92
95
  public reset(): void {
93
96
  this._submitted.value = false;
94
97
 
98
+ this.resetData();
95
99
  this.resetErrors();
96
100
  }
97
101
 
@@ -134,10 +138,10 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
134
138
  return {} as FormData<Fields>;
135
139
  }
136
140
 
137
- const data = Object.entries(fields).reduce((data, [name, definition]) => {
138
- data[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
141
+ const data = Object.entries(fields).reduce((formData, [name, definition]) => {
142
+ formData[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
139
143
 
140
- return data;
144
+ return formData;
141
145
  }, {} as FormData<Fields>);
142
146
 
143
147
  return reactive(data) as FormData<Fields>;
@@ -148,15 +152,21 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
148
152
  return {} as FormErrors<Fields>;
149
153
  }
150
154
 
151
- const errors = Object.keys(fields).reduce((errors, name) => {
152
- errors[name as keyof Fields] = null;
155
+ const errors = Object.keys(fields).reduce((formErrors, name) => {
156
+ formErrors[name as keyof Fields] = null;
153
157
 
154
- return errors;
158
+ return formErrors;
155
159
  }, {} as FormErrors<Fields>);
156
160
 
157
161
  return reactive(errors) as FormErrors<Fields>;
158
162
  }
159
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
+
160
170
  private resetErrors(errors?: Record<string, string[] | null>): void {
161
171
  Object.keys(this._errors).forEach((key) => delete this._errors[key as keyof Fields]);
162
172
 
@@ -1,6 +1,23 @@
1
1
  import { FormFieldTypes } from './Form';
2
2
  import type { FormFieldDefinition } from './Form';
3
3
 
4
+ export function booleanInput(defaultValue?: boolean): FormFieldDefinition<typeof FormFieldTypes.Boolean> {
5
+ return {
6
+ default: defaultValue,
7
+ type: FormFieldTypes.Boolean,
8
+ };
9
+ }
10
+
11
+ export function requiredBooleanInput(
12
+ defaultValue?: boolean,
13
+ ): FormFieldDefinition<typeof FormFieldTypes.Boolean, 'required'> {
14
+ return {
15
+ default: defaultValue,
16
+ type: FormFieldTypes.Boolean,
17
+ rules: 'required',
18
+ };
19
+ }
20
+
4
21
  export function requiredNumberInput(
5
22
  defaultValue?: number,
6
23
  ): FormFieldDefinition<typeof FormFieldTypes.Number, 'required'> {
package/src/lang/Lang.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { facade } from '@noeldemartin/utils';
1
+ import { facade, toString } from '@noeldemartin/utils';
2
2
 
3
3
  import App from '@/services/App';
4
4
  import Service from '@/services/Service';
@@ -41,10 +41,18 @@ export class LangService extends Service {
41
41
  ): string {
42
42
  defaultMessage ??= defaultMessageOrParameters as string;
43
43
 
44
- const parameters = typeof defaultMessageOrParameters === 'string' ? {} : defaultMessageOrParameters;
44
+ const parameters = typeof defaultMessageOrParameters === 'string' ? {} : defaultMessageOrParameters ?? {};
45
45
  const message = this.provider.translate(key, parameters) ?? key;
46
46
 
47
- return message === key ? defaultMessage : message;
47
+ if (message === key) {
48
+ return Object.entries(parameters).reduce(
49
+ (renderedMessage, [name, value]) =>
50
+ renderedMessage.replace(new RegExp(`\\{\\s*${name}\\s*\\}`, 'g'), toString(value)),
51
+ defaultMessage,
52
+ );
53
+ }
54
+
55
+ return message;
48
56
  }
49
57
 
50
58
  }
package/src/lang/index.ts CHANGED
@@ -2,16 +2,14 @@ import { bootServices } from '@/services';
2
2
  import { definePlugin } from '@/plugins';
3
3
 
4
4
  import Lang, { LangProvider } from './Lang';
5
+ import { translate, translateWithDefault } from './utils';
5
6
 
6
- export { Lang, LangProvider };
7
+ export { Lang, LangProvider, translate, translateWithDefault };
7
8
 
8
9
  const services = { $lang: Lang };
9
10
 
10
11
  export type LangServices = typeof services;
11
12
 
12
- export const translate = Lang.translate.bind(Lang);
13
- export const translateWithDefault = Lang.translateWithDefault.bind(Lang);
14
-
15
13
  export default definePlugin({
16
14
  async install(app) {
17
15
  app.config.globalProperties.$t ??= translate;
@@ -22,7 +20,7 @@ export default definePlugin({
22
20
  });
23
21
 
24
22
  declare module '@/services' {
25
- interface Services extends LangServices {}
23
+ export interface Services extends LangServices {}
26
24
  }
27
25
 
28
26
  declare module '@vue/runtime-core' {
@@ -0,0 +1,4 @@
1
+ import Lang from './Lang';
2
+
3
+ export const translate = Lang.translate.bind(Lang);
4
+ export const translateWithDefault = Lang.translateWithDefault.bind(Lang);
package/src/main.ts CHANGED
@@ -1,7 +1,6 @@
1
- import './globals';
2
-
3
1
  export * from './bootstrap';
4
2
  export * from './components';
3
+ export * from './errors';
5
4
  export * from './forms';
6
5
  export * from './lang';
7
6
  export * from './plugins';
@@ -1,10 +1,16 @@
1
+ import Build from 'virtual:aerogel';
2
+
1
3
  import { defineServiceState } from '@/services/Service';
2
4
 
3
5
  export default defineServiceState({
6
+ name: 'app',
4
7
  initialState: {
5
- environment: __AG_ENV,
8
+ environment: Build.environment,
9
+ sourceUrl: Build.sourceUrl,
10
+ isMounted: false,
6
11
  },
7
12
  computed: {
8
13
  isDevelopment: (state) => state.environment === 'development',
14
+ isTesting: (state) => state.environment === 'testing',
9
15
  },
10
16
  });
@@ -1,7 +1,17 @@
1
1
  import { facade } from '@noeldemartin/utils';
2
2
 
3
+ import Events from '@/services/Events';
4
+
3
5
  import Service from './App.state';
4
6
 
5
- export class AppService extends Service {}
7
+ export class AppService extends Service {
8
+
9
+ protected async boot(): Promise<void> {
10
+ await super.boot();
11
+
12
+ Events.once('application-mounted', () => this.setState({ isMounted: true }));
13
+ }
14
+
15
+ }
6
16
 
7
17
  export default facade(new AppService());
@@ -1,27 +1,42 @@
1
- import { computed, reactive } from 'vue';
2
- import { MagicObject, PromisedValue } from '@noeldemartin/utils';
3
- import type { ComputedRef } from 'vue';
1
+ import { MagicObject, PromisedValue, Storage, isEmpty, objectDeepClone, objectOnly } from '@noeldemartin/utils';
4
2
  import type { Constructor } from '@noeldemartin/utils';
3
+ import type { Store } from 'pinia';
5
4
 
6
5
  import ServiceBootError from '@/errors/ServiceBootError';
6
+ import { defineServiceStore } from '@/services/store';
7
7
 
8
8
  export type ServiceState = Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
9
- export type DefaultServiceState = {};
9
+ export type DefaultServiceState = any; // eslint-disable-line @typescript-eslint/no-explicit-any
10
10
  export type ServiceConstructor<T extends Service = Service> = Constructor<T> & typeof Service;
11
11
 
12
12
  export type ComputedStateDefinition<TState extends ServiceState, TComputedState extends ServiceState> = {
13
13
  [K in keyof TComputedState]: (state: TState) => TComputedState[K];
14
- };
14
+ } & ThisType<{
15
+ readonly [K in keyof TComputedState]: TComputedState[K];
16
+ }>;
15
17
 
16
18
  export function defineServiceState<
17
19
  State extends ServiceState = ServiceState,
18
20
  ComputedState extends ServiceState = {}
19
21
  >(options: {
22
+ name: string;
20
23
  initialState: State;
24
+ persist?: (keyof State)[];
21
25
  computed?: ComputedStateDefinition<State, ComputedState>;
22
- }): Constructor<State> & Constructor<ComputedState> & ServiceConstructor {
26
+ serialize?: (state: Partial<State>) => Partial<State>;
27
+ }): Constructor<State> & Constructor<ComputedState> & Constructor<Service<State, ComputedState, Partial<State>>> {
23
28
  return class extends Service<State, ComputedState> {
24
29
 
30
+ public static persist = (options.persist as string[]) ?? [];
31
+
32
+ protected usesStore(): boolean {
33
+ return true;
34
+ }
35
+
36
+ protected getName(): string | null {
37
+ return options.name ?? null;
38
+ }
39
+
25
40
  protected getInitialState(): State {
26
41
  return options.initialState;
27
42
  }
@@ -29,44 +44,53 @@ export function defineServiceState<
29
44
  protected getComputedStateDefinition(): ComputedStateDefinition<State, ComputedState> {
30
45
  return options.computed ?? ({} as ComputedStateDefinition<State, ComputedState>);
31
46
  }
47
+
48
+ protected serializePersistedState(state: Partial<State>): Partial<State> {
49
+ return options.serialize?.(state) ?? state;
50
+ }
32
51
 
33
- } as unknown as Constructor<State> & Constructor<ComputedState> & ServiceConstructor;
52
+ } as unknown as Constructor<State> &
53
+ Constructor<ComputedState> &
54
+ Constructor<Service<State, ComputedState, Partial<State>>>;
34
55
  }
35
56
 
36
57
  export default class Service<
37
58
  State extends ServiceState = DefaultServiceState,
38
- ComputedState extends ServiceState = {}
59
+ ComputedState extends ServiceState = {},
60
+ ServiceStorage extends Partial<State> = Partial<State>
39
61
  > extends MagicObject {
40
62
 
41
- protected _namespace: string;
63
+ public static persist: string[] = [];
64
+
65
+ protected _name: string;
42
66
  private _booted: PromisedValue<void>;
43
- private _state: State;
44
- private _computedState: Record<keyof ComputedState, ComputedRef>;
67
+ private _computedStateKeys: Set<keyof State>;
68
+ private _store?: Store | false;
45
69
 
46
70
  constructor() {
47
71
  super();
48
72
 
49
- this._namespace = new.target.name;
50
- this._booted = new PromisedValue();
51
- this._state = reactive(this.getInitialState());
52
- this._computedState = Object.entries(this.getComputedStateDefinition()).reduce(
53
- (computedState, [name, method]) => {
54
- computedState[name as keyof ComputedState] = computed(() => method(this._state));
73
+ const getters = this.getComputedStateDefinition();
55
74
 
56
- return computedState;
57
- },
58
- {} as Record<keyof ComputedState, ComputedRef>,
59
- );
75
+ this._name = this.getName() ?? new.target.name;
76
+ this._booted = new PromisedValue();
77
+ this._computedStateKeys = new Set(Object.keys(getters));
78
+ this._store =
79
+ this.usesStore() &&
80
+ defineServiceStore(this._name, {
81
+ state: () => this.getInitialState(),
82
+
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ getters: getters as any,
85
+ });
60
86
  }
61
87
 
62
88
  public get booted(): PromisedValue<void> {
63
89
  return this._booted;
64
90
  }
65
91
 
66
- public launch(namespace?: string): Promise<void> {
67
- const handleError = (error: unknown) => this._booted.reject(new ServiceBootError(this._namespace, error));
68
-
69
- this._namespace = namespace ?? this._namespace;
92
+ public launch(): Promise<void> {
93
+ const handleError = (error: unknown) => this._booted.reject(new ServiceBootError(this._name, error));
70
94
 
71
95
  try {
72
96
  this.boot()
@@ -79,15 +103,48 @@ export default class Service<
79
103
  return this._booted;
80
104
  }
81
105
 
106
+ public hasState<P extends keyof State>(property: P): boolean {
107
+ if (!this._store) {
108
+ return false;
109
+ }
110
+
111
+ return property in this._store.$state || this._computedStateKeys.has(property);
112
+ }
113
+
114
+ public getState(): State;
115
+ public getState<P extends keyof State>(property: P): State[P];
116
+ public getState<P extends keyof State>(property?: P): State | State[P] {
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ const store = this._store as any;
119
+
120
+ if (property) {
121
+ return store ? store[property] : undefined;
122
+ }
123
+
124
+ return store ? store : {};
125
+ }
126
+
127
+ public setState<P extends keyof State>(property: P, value: State[P]): void;
128
+ public setState(state: Partial<State>): void;
129
+ public setState<P extends keyof State>(stateOrProperty: P | Partial<State>, value?: State[P]): void {
130
+ if (!this._store) {
131
+ return;
132
+ }
133
+
134
+ const state = (
135
+ typeof stateOrProperty === 'string' ? { [stateOrProperty]: value } : stateOrProperty
136
+ ) as Partial<State>;
137
+
138
+ Object.assign(this._store.$state, state);
139
+
140
+ this.onStateUpdated(state);
141
+ }
142
+
82
143
  protected __get(property: string): unknown {
83
144
  if (this.hasState(property)) {
84
145
  return this.getState(property);
85
146
  }
86
147
 
87
- if (this.hasComputedState(property)) {
88
- return this.getComputedState(property);
89
- }
90
-
91
148
  return super.__get(property);
92
149
  }
93
150
 
@@ -95,26 +152,29 @@ export default class Service<
95
152
  this.setState({ [property]: value } as Partial<State>);
96
153
  }
97
154
 
98
- protected hasState<P extends keyof State>(property: P): boolean {
99
- return property in this._state;
100
- }
155
+ protected onStateUpdated(state: Partial<State>): void {
156
+ // TODO fix this.static()
157
+ const persist = (this.constructor as unknown as { persist: string[] }).persist;
158
+ const persisted = objectOnly(state, persist);
101
159
 
102
- protected hasComputedState<P extends keyof State>(property: P): boolean {
103
- return property in this._computedState;
104
- }
160
+ if (isEmpty(persisted)) {
161
+ return;
162
+ }
163
+
164
+ const storage = Storage.require<ServiceStorage>(this._name);
105
165
 
106
- protected getState(): State;
107
- protected getState<P extends keyof State>(property: P): State[P];
108
- protected getState<P extends keyof State>(property?: P): State | State[P] {
109
- return property ? this._state[property] : this._state;
166
+ Storage.set(this._name, {
167
+ ...storage,
168
+ ...this.serializePersistedState(objectDeepClone(persisted) as Partial<State>),
169
+ });
110
170
  }
111
171
 
112
- protected getComputedState<P extends keyof ComputedState>(property: P): ComputedState[P] {
113
- return this._computedState[property]?.value;
172
+ protected usesStore(): boolean {
173
+ return false;
114
174
  }
115
175
 
116
- protected setState(state: Partial<State>): void {
117
- Object.assign(this._state, state);
176
+ protected getName(): string | null {
177
+ return null;
118
178
  }
119
179
 
120
180
  protected getInitialState(): State {
@@ -125,8 +185,30 @@ export default class Service<
125
185
  return {} as ComputedStateDefinition<State, ComputedState>;
126
186
  }
127
187
 
188
+ protected serializePersistedState(state: Partial<State>): Partial<State> {
189
+ return state;
190
+ }
191
+
128
192
  protected async boot(): Promise<void> {
129
- //
193
+ this.restorePersistedState();
194
+ }
195
+
196
+ protected restorePersistedState(): void {
197
+ // TODO fix this.static()
198
+ const persist = (this.constructor as unknown as { persist: string[] }).persist;
199
+
200
+ if (!this.usesStore() || isEmpty(persist)) {
201
+ return;
202
+ }
203
+
204
+ if (Storage.has(this._name)) {
205
+ const persisted = Storage.require<ServiceStorage>(this._name);
206
+ this.setState(persisted);
207
+
208
+ return;
209
+ }
210
+
211
+ Storage.set(this._name, objectOnly(this.getState(), persist));
130
212
  }
131
213
 
132
214
  }
@@ -5,6 +5,7 @@ import { definePlugin } from '@/plugins';
5
5
  import App from './App';
6
6
  import Events from './Events';
7
7
  import Service from './Service';
8
+ import { getPiniaStore } from './store';
8
9
 
9
10
  export * from './App';
10
11
  export * from './Events';
@@ -23,9 +24,9 @@ export interface Services extends DefaultServices {}
23
24
 
24
25
  export async function bootServices(app: VueApp, services: Record<string, Service>): Promise<void> {
25
26
  await Promise.all(
26
- Object.entries(services).map(async ([name, service]) => {
27
+ Object.entries(services).map(async ([_, service]) => {
27
28
  // eslint-disable-next-line no-console
28
- await service.launch(name.slice(1)).catch((error) => console.error(error));
29
+ await service.launch().catch((error) => console.error(error));
29
30
  }),
30
31
  );
31
32
 
@@ -33,11 +34,24 @@ export async function bootServices(app: VueApp, services: Record<string, Service
33
34
  }
34
35
 
35
36
  export default definePlugin({
36
- async install(app) {
37
- await bootServices(app, defaultServices);
37
+ async install(app, options) {
38
+ const services = {
39
+ ...defaultServices,
40
+ ...options.services,
41
+ };
42
+
43
+ app.use(getPiniaStore());
44
+
45
+ await bootServices(app, services);
38
46
  },
39
47
  });
40
48
 
49
+ declare module '@/bootstrap/options' {
50
+ interface AerogelOptions {
51
+ services?: Record<string, Service>;
52
+ }
53
+ }
54
+
41
55
  declare module '@vue/runtime-core' {
42
56
  interface ComponentCustomProperties extends Services {}
43
57
  }
@@ -0,0 +1,27 @@
1
+ import { createPinia, defineStore, setActivePinia } from 'pinia';
2
+ import type { DefineStoreOptions, Pinia, StateTree, Store, _GettersTree } from 'pinia';
3
+
4
+ let _store: Pinia | null = null;
5
+
6
+ function initializePiniaStore(): Pinia {
7
+ if (!_store) {
8
+ _store = createPinia();
9
+
10
+ setActivePinia(_store);
11
+ }
12
+
13
+ return _store;
14
+ }
15
+
16
+ export function getPiniaStore(): Pinia {
17
+ return _store ?? initializePiniaStore();
18
+ }
19
+
20
+ export function defineServiceStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(
21
+ name: Id,
22
+ options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,
23
+ ): Store<Id, S, G, A> {
24
+ initializePiniaStore();
25
+
26
+ return defineStore(name, options)();
27
+ }
@@ -0,0 +1,11 @@
1
+ declare module 'virtual:aerogel' {
2
+ interface AerogelBuild {
3
+ environment: 'production' | 'development' | 'testing';
4
+ basePath?: string;
5
+ sourceUrl?: string;
6
+ }
7
+
8
+ const build: AerogelBuild;
9
+
10
+ export default build;
11
+ }
@@ -17,6 +17,16 @@ export interface ModalComponent<
17
17
  Result = unknown
18
18
  > {}
19
19
 
20
+ export interface Snackbar {
21
+ id: string;
22
+ component: Component;
23
+ properties: Record<string, unknown>;
24
+ }
25
+
20
26
  export default defineServiceState({
21
- initialState: { modals: [] as Modal[] },
27
+ name: 'ui',
28
+ initialState: {
29
+ modals: [] as Modal[],
30
+ snackbars: [] as Snackbar[],
31
+ },
22
32
  });