@aerogel/core 0.0.0-next.c8f032a868370824898e171969aec1bb6827688e → 0.0.0-next.d34923f3b144e8f6720e6a9cdadb2cd4fb4ab289
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.cjs.js +1 -1
- package/dist/aerogel-core.cjs.js.map +1 -1
- package/dist/aerogel-core.d.ts +1720 -243
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/histoire.config.ts +7 -0
- package/noeldemartin.config.js +4 -1
- package/package.json +14 -4
- package/postcss.config.js +6 -0
- package/src/assets/histoire.css +3 -0
- package/src/bootstrap/bootstrap.test.ts +4 -3
- package/src/bootstrap/index.ts +27 -4
- package/src/bootstrap/options.ts +3 -0
- package/src/components/AGAppLayout.vue +7 -2
- package/src/components/AGAppModals.vue +15 -0
- package/src/components/AGAppOverlays.vue +10 -8
- package/src/components/AGAppSnackbars.vue +13 -0
- package/src/components/constants.ts +8 -0
- package/src/components/forms/AGButton.vue +33 -10
- package/src/components/forms/AGCheckbox.vue +41 -0
- package/src/components/forms/AGForm.vue +9 -10
- package/src/components/forms/AGInput.vue +17 -9
- package/src/components/forms/AGSelect.story.vue +46 -0
- package/src/components/forms/AGSelect.vue +60 -0
- package/src/components/forms/index.ts +5 -5
- package/src/components/headless/forms/AGHeadlessButton.vue +21 -16
- package/src/components/headless/forms/AGHeadlessInput.ts +29 -4
- package/src/components/headless/forms/AGHeadlessInput.vue +17 -7
- package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
- package/src/components/headless/forms/AGHeadlessInputError.vue +1 -1
- package/src/components/headless/forms/AGHeadlessInputInput.vue +56 -6
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
- package/src/components/headless/forms/AGHeadlessInputTextArea.vue +42 -0
- package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
- package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
- package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
- package/src/components/headless/forms/composition.ts +10 -0
- package/src/components/headless/forms/index.ts +12 -1
- package/src/components/headless/index.ts +1 -0
- package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
- package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
- package/src/components/headless/modals/AGHeadlessModalPanel.vue +5 -1
- package/src/components/headless/modals/index.ts +4 -6
- package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
- package/src/components/headless/snackbars/index.ts +40 -0
- package/src/components/index.ts +4 -1
- package/src/components/interfaces.ts +9 -0
- package/src/components/lib/AGErrorMessage.vue +16 -0
- package/src/components/lib/AGLink.vue +9 -0
- package/src/components/lib/AGMarkdown.vue +41 -0
- package/src/components/lib/AGMeasured.vue +15 -0
- package/src/components/lib/AGStartupCrash.vue +31 -0
- package/src/components/lib/index.ts +5 -0
- package/src/components/modals/AGAlertModal.ts +15 -0
- package/src/components/modals/AGAlertModal.vue +4 -16
- package/src/components/modals/AGConfirmModal.ts +33 -0
- package/src/components/modals/AGConfirmModal.vue +9 -13
- package/src/components/modals/AGErrorReportModal.ts +46 -0
- package/src/components/modals/AGErrorReportModal.vue +54 -0
- package/src/components/modals/AGErrorReportModalButtons.vue +111 -0
- package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
- package/src/components/modals/AGLoadingModal.ts +23 -0
- package/src/components/modals/AGLoadingModal.vue +15 -0
- package/src/components/modals/AGModal.ts +1 -1
- package/src/components/modals/AGModal.vue +26 -5
- package/src/components/modals/AGModalTitle.vue +9 -0
- package/src/components/modals/AGPromptModal.ts +36 -0
- package/src/components/modals/AGPromptModal.vue +34 -0
- package/src/components/modals/index.ts +16 -6
- package/src/components/snackbars/AGSnackbar.vue +36 -0
- package/src/components/snackbars/index.ts +3 -0
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +20 -3
- package/src/directives/measure.ts +21 -0
- package/src/errors/Errors.state.ts +31 -0
- package/src/errors/Errors.ts +185 -0
- package/src/errors/index.ts +46 -0
- package/src/errors/utils.ts +19 -0
- package/src/forms/Form.test.ts +21 -0
- package/src/forms/Form.ts +76 -18
- package/src/forms/index.ts +1 -0
- package/src/forms/utils.ts +32 -0
- package/src/jobs/Job.ts +5 -0
- package/src/jobs/index.ts +7 -0
- package/src/lang/Lang.ts +14 -14
- package/src/lang/index.ts +3 -5
- package/src/lang/utils.ts +4 -0
- package/src/main.histoire.ts +1 -0
- package/src/main.ts +4 -2
- package/src/plugins/Plugin.ts +1 -0
- package/src/plugins/index.ts +19 -0
- package/src/services/App.state.ts +23 -2
- package/src/services/App.ts +46 -3
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.test.ts +39 -0
- package/src/services/Events.ts +100 -30
- package/src/services/Service.ts +174 -53
- package/src/services/index.ts +25 -5
- package/src/services/store.ts +30 -0
- package/src/testing/index.ts +25 -0
- package/src/ui/UI.state.ts +11 -1
- package/src/ui/UI.ts +177 -20
- package/src/ui/index.ts +15 -4
- package/src/utils/composition/events.ts +1 -0
- package/src/utils/composition/forms.ts +11 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/markdown.ts +11 -2
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +15 -4
- package/tailwind.config.js +4 -0
- package/tsconfig.json +1 -0
- package/vite.config.ts +2 -1
- package/.eslintrc.js +0 -3
- package/src/components/basic/AGMarkdown.vue +0 -35
- package/src/components/basic/index.ts +0 -3
- package/src/globals.ts +0 -6
package/src/services/Service.ts
CHANGED
|
@@ -1,75 +1,126 @@
|
|
|
1
|
-
import {
|
|
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 { MaybeRef } from 'vue';
|
|
4
|
+
import type { Store } from 'pinia';
|
|
5
5
|
|
|
6
6
|
import ServiceBootError from '@/errors/ServiceBootError';
|
|
7
|
+
import { defineServiceStore } from '@/services/store';
|
|
7
8
|
|
|
8
9
|
export type ServiceState = Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
9
|
-
export type DefaultServiceState =
|
|
10
|
+
export type DefaultServiceState = any; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
10
11
|
export type ServiceConstructor<T extends Service = Service> = Constructor<T> & typeof Service;
|
|
12
|
+
export type UnrefServiceState<State extends ServiceState> = {
|
|
13
|
+
[K in keyof State]: State[K] extends MaybeRef<infer T> ? T : State[K];
|
|
14
|
+
};
|
|
11
15
|
|
|
12
16
|
export type ComputedStateDefinition<TState extends ServiceState, TComputedState extends ServiceState> = {
|
|
13
|
-
[K in keyof TComputedState]: (state: TState) => TComputedState[K];
|
|
14
|
-
}
|
|
17
|
+
[K in keyof TComputedState]: (state: UnrefServiceState<TState>) => TComputedState[K];
|
|
18
|
+
} & ThisType<{
|
|
19
|
+
readonly [K in keyof TComputedState]: TComputedState[K];
|
|
20
|
+
}>;
|
|
15
21
|
|
|
16
22
|
export function defineServiceState<
|
|
17
23
|
State extends ServiceState = ServiceState,
|
|
18
24
|
ComputedState extends ServiceState = {}
|
|
19
25
|
>(options: {
|
|
20
|
-
|
|
26
|
+
name: string;
|
|
27
|
+
initialState: State | (() => State);
|
|
28
|
+
persist?: (keyof State)[];
|
|
21
29
|
computed?: ComputedStateDefinition<State, ComputedState>;
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
serialize?: (state: Partial<State>) => Partial<State>;
|
|
31
|
+
}): Constructor<UnrefServiceState<State>> &
|
|
32
|
+
Constructor<ComputedState> &
|
|
33
|
+
Constructor<Service<UnrefServiceState<State>, ComputedState, Partial<UnrefServiceState<State>>>> {
|
|
34
|
+
return class extends Service<UnrefServiceState<State>, ComputedState> {
|
|
35
|
+
|
|
36
|
+
public static persist = (options.persist as string[]) ?? [];
|
|
37
|
+
|
|
38
|
+
protected usesStore(): boolean {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected getName(): string | null {
|
|
43
|
+
return options.name ?? null;
|
|
44
|
+
}
|
|
24
45
|
|
|
25
|
-
protected getInitialState(): State {
|
|
26
|
-
|
|
46
|
+
protected getInitialState(): UnrefServiceState<State> {
|
|
47
|
+
if (typeof options.initialState === 'function') {
|
|
48
|
+
return options.initialState();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Object.entries(options.initialState).reduce((state, [key, value]) => {
|
|
52
|
+
try {
|
|
53
|
+
value = structuredClone(value);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
console.warn(
|
|
57
|
+
`Could not clone '${key}' state from ${this.getName()} service, ` +
|
|
58
|
+
'this may cause problems if you\'re using multiple instances of the service ' +
|
|
59
|
+
'(for example, in unit tests).\n' +
|
|
60
|
+
'To fix this problem, declare your initialState as a function instead.',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
state[key as keyof State] = value;
|
|
65
|
+
|
|
66
|
+
return state;
|
|
67
|
+
}, {} as UnrefServiceState<State>);
|
|
27
68
|
}
|
|
28
69
|
|
|
29
|
-
protected getComputedStateDefinition(): ComputedStateDefinition<State
|
|
30
|
-
return options.computed ??
|
|
70
|
+
protected getComputedStateDefinition(): ComputedStateDefinition<UnrefServiceState<State>, ComputedState> {
|
|
71
|
+
return (options.computed ?? {}) as ComputedStateDefinition<UnrefServiceState<State>, ComputedState>;
|
|
31
72
|
}
|
|
32
|
-
|
|
33
|
-
|
|
73
|
+
|
|
74
|
+
protected serializePersistedState(state: Partial<State>): Partial<State> {
|
|
75
|
+
return options.serialize?.(state) ?? state;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
} as unknown as Constructor<UnrefServiceState<State>> &
|
|
79
|
+
Constructor<ComputedState> &
|
|
80
|
+
Constructor<Service<UnrefServiceState<State>, ComputedState, Partial<UnrefServiceState<State>>>>;
|
|
34
81
|
}
|
|
35
82
|
|
|
36
83
|
export default class Service<
|
|
37
84
|
State extends ServiceState = DefaultServiceState,
|
|
38
|
-
ComputedState extends ServiceState = {}
|
|
85
|
+
ComputedState extends ServiceState = {},
|
|
86
|
+
ServiceStorage extends Partial<State> = Partial<State>
|
|
39
87
|
> extends MagicObject {
|
|
40
88
|
|
|
41
|
-
|
|
89
|
+
public static persist: string[] = [];
|
|
90
|
+
|
|
91
|
+
protected _name: string;
|
|
42
92
|
private _booted: PromisedValue<void>;
|
|
43
|
-
private
|
|
44
|
-
private
|
|
93
|
+
private _computedStateKeys: Set<keyof State>;
|
|
94
|
+
private _store: Store | false;
|
|
45
95
|
|
|
46
96
|
constructor() {
|
|
47
97
|
super();
|
|
48
98
|
|
|
49
|
-
|
|
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));
|
|
99
|
+
const getters = this.getComputedStateDefinition();
|
|
55
100
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
101
|
+
this._name = this.getName() ?? new.target.name;
|
|
102
|
+
this._booted = new PromisedValue();
|
|
103
|
+
this._computedStateKeys = new Set(Object.keys(getters));
|
|
104
|
+
this._store =
|
|
105
|
+
this.usesStore() &&
|
|
106
|
+
defineServiceStore(this._name, {
|
|
107
|
+
state: () => this.getInitialState(),
|
|
108
|
+
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
+
getters: getters as any,
|
|
111
|
+
});
|
|
60
112
|
}
|
|
61
113
|
|
|
62
114
|
public get booted(): PromisedValue<void> {
|
|
63
115
|
return this._booted;
|
|
64
116
|
}
|
|
65
117
|
|
|
66
|
-
public launch(
|
|
67
|
-
const handleError = (error: unknown) => this._booted.reject(new ServiceBootError(this.
|
|
68
|
-
|
|
69
|
-
this._namespace = namespace ?? this._namespace;
|
|
118
|
+
public launch(): Promise<void> {
|
|
119
|
+
const handleError = (error: unknown) => this._booted.reject(new ServiceBootError(this._name, error));
|
|
70
120
|
|
|
71
121
|
try {
|
|
72
|
-
this.
|
|
122
|
+
this.frameworkBoot()
|
|
123
|
+
.then(() => this.boot())
|
|
73
124
|
.then(() => this._booted.resolve())
|
|
74
125
|
.catch(handleError);
|
|
75
126
|
} catch (error) {
|
|
@@ -79,15 +130,52 @@ export default class Service<
|
|
|
79
130
|
return this._booted;
|
|
80
131
|
}
|
|
81
132
|
|
|
133
|
+
public hasPersistedState(): boolean {
|
|
134
|
+
return Storage.has(this._name);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public hasState<P extends keyof State>(property: P): boolean {
|
|
138
|
+
if (!this._store) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return property in this._store.$state || this._computedStateKeys.has(property);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public getState(): State;
|
|
146
|
+
public getState<P extends keyof State>(property: P): State[P];
|
|
147
|
+
public getState<P extends keyof State>(property?: P): State | State[P] {
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
|
+
const store = this._store as any;
|
|
150
|
+
|
|
151
|
+
if (property) {
|
|
152
|
+
return store ? store[property] : undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return store ? store : {};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public setState<P extends keyof State>(property: P, value: State[P]): void;
|
|
159
|
+
public setState(state: Partial<State>): void;
|
|
160
|
+
public setState<P extends keyof State>(stateOrProperty: P | Partial<State>, value?: State[P]): void {
|
|
161
|
+
if (!this._store) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const state = (
|
|
166
|
+
typeof stateOrProperty === 'string' ? { [stateOrProperty]: value } : stateOrProperty
|
|
167
|
+
) as Partial<State>;
|
|
168
|
+
|
|
169
|
+
Object.assign(this._store.$state, state);
|
|
170
|
+
|
|
171
|
+
this.onStateUpdated(state);
|
|
172
|
+
}
|
|
173
|
+
|
|
82
174
|
protected __get(property: string): unknown {
|
|
83
175
|
if (this.hasState(property)) {
|
|
84
176
|
return this.getState(property);
|
|
85
177
|
}
|
|
86
178
|
|
|
87
|
-
if (this.hasComputedState(property)) {
|
|
88
|
-
return this.getComputedState(property);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
179
|
return super.__get(property);
|
|
92
180
|
}
|
|
93
181
|
|
|
@@ -95,26 +183,33 @@ export default class Service<
|
|
|
95
183
|
this.setState({ [property]: value } as Partial<State>);
|
|
96
184
|
}
|
|
97
185
|
|
|
98
|
-
protected
|
|
99
|
-
|
|
100
|
-
|
|
186
|
+
protected onStateUpdated(state: Partial<State>): void {
|
|
187
|
+
// TODO fix this.static()
|
|
188
|
+
const persist = (this.constructor as unknown as { persist: string[] }).persist;
|
|
189
|
+
const persisted = objectOnly(state, persist);
|
|
101
190
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
191
|
+
if (isEmpty(persisted)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const storage = Storage.get<ServiceStorage>(this._name);
|
|
196
|
+
|
|
197
|
+
if (!storage) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
105
200
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
201
|
+
Storage.set(this._name, {
|
|
202
|
+
...storage,
|
|
203
|
+
...this.serializePersistedState(objectDeepClone(persisted) as Partial<State>),
|
|
204
|
+
});
|
|
110
205
|
}
|
|
111
206
|
|
|
112
|
-
protected
|
|
113
|
-
return
|
|
207
|
+
protected usesStore(): boolean {
|
|
208
|
+
return false;
|
|
114
209
|
}
|
|
115
210
|
|
|
116
|
-
protected
|
|
117
|
-
|
|
211
|
+
protected getName(): string | null {
|
|
212
|
+
return null;
|
|
118
213
|
}
|
|
119
214
|
|
|
120
215
|
protected getInitialState(): State {
|
|
@@ -125,8 +220,34 @@ export default class Service<
|
|
|
125
220
|
return {} as ComputedStateDefinition<State, ComputedState>;
|
|
126
221
|
}
|
|
127
222
|
|
|
223
|
+
protected serializePersistedState(state: Partial<State>): Partial<State> {
|
|
224
|
+
return state;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
protected async frameworkBoot(): Promise<void> {
|
|
228
|
+
this.initializePersistedState();
|
|
229
|
+
}
|
|
230
|
+
|
|
128
231
|
protected async boot(): Promise<void> {
|
|
129
|
-
//
|
|
232
|
+
// Placeholder for overrides, don't place any functionality here.
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
protected initializePersistedState(): void {
|
|
236
|
+
// TODO fix this.static()
|
|
237
|
+
const persist = (this.constructor as unknown as { persist: string[] }).persist;
|
|
238
|
+
|
|
239
|
+
if (!this.usesStore() || isEmpty(persist)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (Storage.has(this._name)) {
|
|
244
|
+
const persisted = Storage.require<ServiceStorage>(this._name);
|
|
245
|
+
this.setState(persisted);
|
|
246
|
+
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
Storage.set(this._name, objectOnly(this.getState(), persist));
|
|
130
251
|
}
|
|
131
252
|
|
|
132
253
|
}
|
package/src/services/index.ts
CHANGED
|
@@ -3,14 +3,18 @@ import type { App as VueApp } from 'vue';
|
|
|
3
3
|
import { definePlugin } from '@/plugins';
|
|
4
4
|
|
|
5
5
|
import App from './App';
|
|
6
|
+
import Cache from './Cache';
|
|
6
7
|
import Events from './Events';
|
|
7
8
|
import Service from './Service';
|
|
9
|
+
import { getPiniaStore } from './store';
|
|
8
10
|
|
|
9
11
|
export * from './App';
|
|
12
|
+
export * from './Cache';
|
|
10
13
|
export * from './Events';
|
|
11
14
|
export * from './Service';
|
|
15
|
+
export * from './store';
|
|
12
16
|
|
|
13
|
-
export { App, Events, Service };
|
|
17
|
+
export { App, Cache, Events, Service };
|
|
14
18
|
|
|
15
19
|
const defaultServices = {
|
|
16
20
|
$app: App,
|
|
@@ -24,20 +28,36 @@ export interface Services extends DefaultServices {}
|
|
|
24
28
|
export async function bootServices(app: VueApp, services: Record<string, Service>): Promise<void> {
|
|
25
29
|
await Promise.all(
|
|
26
30
|
Object.entries(services).map(async ([name, service]) => {
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
await service
|
|
32
|
+
.launch()
|
|
33
|
+
.catch((error) => app.config.errorHandler?.(error, null, `Failed launching ${name}.`));
|
|
29
34
|
}),
|
|
30
35
|
);
|
|
31
36
|
|
|
32
37
|
Object.assign(app.config.globalProperties, services);
|
|
38
|
+
|
|
39
|
+
App.development && Object.assign(window, services);
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
export default definePlugin({
|
|
36
|
-
async install(app) {
|
|
37
|
-
|
|
43
|
+
async install(app, options) {
|
|
44
|
+
const services = {
|
|
45
|
+
...defaultServices,
|
|
46
|
+
...options.services,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
app.use(getPiniaStore());
|
|
50
|
+
|
|
51
|
+
await bootServices(app, services);
|
|
38
52
|
},
|
|
39
53
|
});
|
|
40
54
|
|
|
55
|
+
declare module '@/bootstrap/options' {
|
|
56
|
+
export interface AerogelOptions {
|
|
57
|
+
services?: Record<string, Service>;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
41
61
|
declare module '@vue/runtime-core' {
|
|
42
62
|
interface ComponentCustomProperties extends Services {}
|
|
43
63
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { tap } from '@noeldemartin/utils';
|
|
2
|
+
import { createPinia, defineStore, setActivePinia } from 'pinia';
|
|
3
|
+
import type { DefineStoreOptions, Pinia, StateTree, Store, _GettersTree } from 'pinia';
|
|
4
|
+
|
|
5
|
+
let _store: Pinia | null = null;
|
|
6
|
+
|
|
7
|
+
function initializePiniaStore(): Pinia {
|
|
8
|
+
return _store ?? resetPiniaStore();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function resetPiniaStore(): Pinia {
|
|
12
|
+
return tap(createPinia(), (store) => {
|
|
13
|
+
_store = store;
|
|
14
|
+
|
|
15
|
+
setActivePinia(store);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getPiniaStore(): Pinia {
|
|
20
|
+
return _store ?? initializePiniaStore();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function defineServiceStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(
|
|
24
|
+
name: Id,
|
|
25
|
+
options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,
|
|
26
|
+
): Store<Id, S, G, A> {
|
|
27
|
+
initializePiniaStore();
|
|
28
|
+
|
|
29
|
+
return defineStore(name, options)();
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GetClosureArgs } from '@noeldemartin/utils';
|
|
2
|
+
|
|
3
|
+
import Events from '@/services/Events';
|
|
4
|
+
import { definePlugin } from '@/plugins';
|
|
5
|
+
|
|
6
|
+
export interface AerogelTestingRuntime {
|
|
7
|
+
on: (typeof Events)['on'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default definePlugin({
|
|
11
|
+
async install() {
|
|
12
|
+
if (import.meta.env.MODE !== 'testing') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
globalThis.testingRuntime = {
|
|
17
|
+
on: ((...args: GetClosureArgs<(typeof Events)['on']>) => Events.on(...args)) as (typeof Events)['on'],
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
declare global {
|
|
23
|
+
// eslint-disable-next-line no-var
|
|
24
|
+
var testingRuntime: AerogelTestingRuntime | undefined;
|
|
25
|
+
}
|
package/src/ui/UI.state.ts
CHANGED
|
@@ -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
|
-
|
|
27
|
+
name: 'ui',
|
|
28
|
+
initialState: {
|
|
29
|
+
modals: [] as Modal[],
|
|
30
|
+
snackbars: [] as Snackbar[],
|
|
31
|
+
},
|
|
22
32
|
});
|