@aerogel/core 0.0.0-next.f8cdd39997c56dcd46e07c26af8a84d04d610fce → 0.0.0-next.fd1bd21aea7a9ab8c4eab69a5f5776db5de8bf35
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 +1175 -237
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/histoire.config.ts +7 -0
- package/package.json +14 -5
- 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 +25 -5
- package/src/bootstrap/options.ts +3 -0
- package/src/components/AGAppLayout.vue +7 -2
- package/src/components/AGAppOverlays.vue +5 -1
- package/src/components/AGAppSnackbars.vue +1 -1
- package/src/components/forms/AGCheckbox.vue +7 -1
- package/src/components/forms/AGForm.vue +9 -10
- package/src/components/forms/AGInput.vue +10 -6
- package/src/components/forms/AGSelect.story.vue +46 -0
- package/src/components/forms/AGSelect.vue +60 -0
- package/src/components/forms/index.ts +5 -6
- package/src/components/headless/forms/AGHeadlessButton.vue +17 -12
- package/src/components/headless/forms/AGHeadlessInput.ts +27 -3
- package/src/components/headless/forms/AGHeadlessInput.vue +9 -6
- package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
- package/src/components/headless/forms/AGHeadlessInputInput.vue +40 -4
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
- package/src/components/headless/forms/AGHeadlessInputTextArea.vue +40 -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/modals/AGHeadlessModal.ts +27 -0
- package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
- package/src/components/headless/modals/index.ts +4 -6
- package/src/components/headless/snackbars/index.ts +23 -8
- package/src/components/index.ts +1 -1
- package/src/components/{basic → lib}/AGErrorMessage.vue +2 -2
- package/src/components/{basic → lib}/AGMarkdown.vue +7 -2
- 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 -15
- package/src/components/modals/AGConfirmModal.ts +27 -0
- package/src/components/modals/AGConfirmModal.vue +7 -11
- package/src/components/modals/AGErrorReportModal.ts +27 -1
- package/src/components/modals/AGErrorReportModal.vue +8 -16
- package/src/components/modals/AGErrorReportModalButtons.vue +4 -2
- package/src/components/modals/AGErrorReportModalTitle.vue +1 -1
- package/src/components/modals/AGLoadingModal.ts +23 -0
- package/src/components/modals/AGLoadingModal.vue +4 -8
- package/src/components/modals/AGModal.ts +1 -1
- package/src/components/modals/AGModal.vue +15 -12
- package/src/components/modals/AGModalTitle.vue +9 -0
- package/src/components/modals/AGPromptModal.ts +30 -0
- package/src/components/modals/AGPromptModal.vue +34 -0
- package/src/components/modals/index.ts +13 -17
- package/src/components/snackbars/AGSnackbar.vue +3 -9
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +5 -1
- package/src/directives/measure.ts +21 -0
- package/src/errors/Errors.ts +26 -24
- package/src/errors/index.ts +10 -23
- package/src/errors/utils.ts +19 -0
- package/src/forms/Form.ts +57 -9
- package/src/forms/index.ts +1 -0
- package/src/forms/utils.ts +15 -0
- package/src/jobs/Job.ts +5 -0
- package/src/jobs/index.ts +7 -0
- package/src/lang/Lang.ts +11 -23
- package/src/main.histoire.ts +1 -0
- package/src/main.ts +3 -0
- package/src/plugins/Plugin.ts +1 -0
- package/src/plugins/index.ts +19 -0
- package/src/services/App.state.ts +6 -5
- package/src/services/App.ts +35 -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 +50 -16
- package/src/services/index.ts +5 -2
- package/src/services/store.ts +8 -5
- package/src/testing/index.ts +25 -0
- package/src/ui/UI.ts +127 -19
- package/src/ui/index.ts +8 -3
- package/src/utils/composition/events.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +13 -4
- package/tailwind.config.js +4 -0
- package/tsconfig.json +1 -1
- package/.eslintrc.js +0 -3
- package/dist/virtual.d.ts +0 -11
- package/src/components/basic/index.ts +0 -5
- package/src/types/virtual.d.ts +0 -11
- /package/src/components/{basic → lib}/AGLink.vue +0 -0
package/src/services/Events.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { FluentArray } from '@noeldemartin/utils';
|
|
1
|
+
import { arrayRemove, facade, fail, tap } from '@noeldemartin/utils';
|
|
3
2
|
|
|
4
3
|
import Service from '@/services/Service';
|
|
5
4
|
|
|
6
5
|
export interface EventsPayload {}
|
|
6
|
+
export interface EventListenerOptions {
|
|
7
|
+
priority: number;
|
|
8
|
+
}
|
|
9
|
+
export type AerogelGlobalEvents = Partial<{ [Event in EventWithoutPayload]: () => unknown }> &
|
|
10
|
+
Partial<{ [Event in EventWithPayload]: EventListener<EventsPayload[Event]> }>;
|
|
7
11
|
|
|
8
12
|
export type EventListener<T = unknown> = (payload: T) => unknown;
|
|
9
13
|
export type UnknownEvent<T> = T extends keyof EventsPayload ? never : T;
|
|
@@ -16,70 +20,136 @@ export type EventWithPayload = {
|
|
|
16
20
|
[K in keyof EventsPayload]: EventsPayload[K] extends void ? never : K;
|
|
17
21
|
}[keyof EventsPayload];
|
|
18
22
|
|
|
23
|
+
export const EventListenerPriorities = {
|
|
24
|
+
Low: -256,
|
|
25
|
+
Default: 0,
|
|
26
|
+
High: 256,
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
19
29
|
export class EventsService extends Service {
|
|
20
30
|
|
|
21
|
-
private listeners: Record<string,
|
|
31
|
+
private listeners: Record<string, { priorities: number[]; handlers: Record<number, EventListener[]> }> = {};
|
|
32
|
+
|
|
33
|
+
protected async boot(): Promise<void> {
|
|
34
|
+
Object.entries(globalThis.__aerogelEvents__ ?? {}).forEach(([event, listener]) =>
|
|
35
|
+
this.on(event as string, listener as EventListener));
|
|
36
|
+
}
|
|
22
37
|
|
|
23
38
|
public emit<Event extends EventWithoutPayload>(event: Event): Promise<void>;
|
|
24
39
|
public emit<Event extends EventWithPayload>(event: Event, payload: EventsPayload[Event]): Promise<void>;
|
|
25
40
|
public emit<Event extends string>(event: UnknownEvent<Event>, payload?: unknown): Promise<void>;
|
|
26
41
|
public async emit(event: string, payload?: unknown): Promise<void> {
|
|
27
|
-
const listeners =
|
|
42
|
+
const listeners = this.listeners[event] ?? { priorities: [], handlers: {} };
|
|
28
43
|
|
|
29
|
-
|
|
44
|
+
for (const priority of listeners.priorities) {
|
|
45
|
+
await Promise.all(listeners.handlers[priority]?.map((listener) => listener(payload)) ?? []);
|
|
46
|
+
}
|
|
30
47
|
}
|
|
31
48
|
|
|
49
|
+
/* eslint-disable max-len */
|
|
32
50
|
public on<Event extends EventWithoutPayload>(event: Event, listener: () => unknown): () => void;
|
|
33
|
-
public on<Event extends
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
): () => void | void;
|
|
37
|
-
|
|
51
|
+
public on<Event extends EventWithoutPayload>(event: Event, options: Partial<EventListenerOptions>, listener: () => unknown): () => void; // prettier-ignore
|
|
52
|
+
public on<Event extends EventWithPayload>(event: Event, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
|
|
53
|
+
public on<Event extends EventWithPayload>(event: Event, options: Partial<EventListenerOptions>, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
|
|
38
54
|
public on<Event extends string>(event: UnknownEvent<Event>, listener: EventListener): () => void;
|
|
39
|
-
public on(event:
|
|
40
|
-
|
|
55
|
+
public on<Event extends string>(event: UnknownEvent<Event>, options: Partial<EventListenerOptions>, listener: EventListener): () => void; // prettier-ignore
|
|
56
|
+
/* eslint-enable max-len */
|
|
41
57
|
|
|
42
|
-
|
|
58
|
+
public on(
|
|
59
|
+
event: string,
|
|
60
|
+
optionsOrListener: Partial<EventListenerOptions> | EventListener,
|
|
61
|
+
listener?: EventListener,
|
|
62
|
+
): () => void {
|
|
63
|
+
const options = typeof optionsOrListener === 'function' ? {} : optionsOrListener;
|
|
64
|
+
const handler = typeof optionsOrListener === 'function' ? optionsOrListener : (listener as EventListener);
|
|
65
|
+
|
|
66
|
+
this.registerListener(event, options, handler);
|
|
67
|
+
|
|
68
|
+
return () => this.off(event, handler);
|
|
43
69
|
}
|
|
44
70
|
|
|
71
|
+
/* eslint-disable max-len */
|
|
45
72
|
public once<Event extends EventWithoutPayload>(event: Event, listener: () => unknown): () => void;
|
|
46
|
-
public once<Event extends
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
): () => void | void;
|
|
50
|
-
|
|
73
|
+
public once<Event extends EventWithoutPayload>(event: Event, options: Partial<EventListenerOptions>, listener: () => unknown): () => void; // prettier-ignore
|
|
74
|
+
public once<Event extends EventWithPayload>(event: Event, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
|
|
75
|
+
public once<Event extends EventWithPayload>(event: Event, options: Partial<EventListenerOptions>, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
|
|
51
76
|
public once<Event extends string>(event: UnknownEvent<Event>, listener: EventListener): () => void;
|
|
52
|
-
public once(event:
|
|
77
|
+
public once<Event extends string>(event: UnknownEvent<Event>, options: Partial<EventListenerOptions>, listener: EventListener): () => void; // prettier-ignore
|
|
78
|
+
/* eslint-enable max-len */
|
|
79
|
+
|
|
80
|
+
public once(
|
|
81
|
+
event: string,
|
|
82
|
+
optionsOrListener: Partial<EventListenerOptions> | EventListener,
|
|
83
|
+
listener?: EventListener,
|
|
84
|
+
): () => void {
|
|
53
85
|
let onceListener: EventListener | null = null;
|
|
86
|
+
const options = typeof optionsOrListener === 'function' ? {} : optionsOrListener;
|
|
87
|
+
const handler = typeof optionsOrListener === 'function' ? optionsOrListener : (listener as EventListener);
|
|
54
88
|
|
|
55
89
|
return tap(
|
|
56
90
|
() => onceListener && this.off(event, onceListener),
|
|
57
91
|
(off) => {
|
|
58
|
-
|
|
59
|
-
(
|
|
60
|
-
off();
|
|
92
|
+
onceListener = (...args) => {
|
|
93
|
+
off();
|
|
61
94
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
95
|
+
return handler(...args);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
this.registerListener(event, options, handler);
|
|
65
99
|
},
|
|
66
100
|
);
|
|
67
101
|
}
|
|
68
102
|
|
|
69
103
|
public off(event: string, listener: EventListener): void {
|
|
70
|
-
const
|
|
104
|
+
const listeners = this.listeners[event];
|
|
71
105
|
|
|
72
|
-
if (!
|
|
106
|
+
if (!listeners) {
|
|
73
107
|
return;
|
|
74
108
|
}
|
|
75
109
|
|
|
76
|
-
|
|
110
|
+
const priorities = [...listeners.priorities];
|
|
111
|
+
|
|
112
|
+
for (const priority of priorities) {
|
|
113
|
+
arrayRemove(listeners.handlers[priority] ?? [], listener);
|
|
77
114
|
|
|
78
|
-
|
|
115
|
+
if (listeners.handlers[priority]?.length === 0) {
|
|
116
|
+
delete listeners.handlers[priority];
|
|
117
|
+
arrayRemove(listeners.priorities, priority);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (listeners.priorities.length === 0) {
|
|
79
122
|
delete this.listeners[event];
|
|
80
123
|
}
|
|
81
124
|
}
|
|
82
125
|
|
|
126
|
+
protected registerListener(event: string, options: Partial<EventListenerOptions>, handler: EventListener): void {
|
|
127
|
+
const priority = options.priority ?? 0;
|
|
128
|
+
|
|
129
|
+
if (!(event in this.listeners)) {
|
|
130
|
+
this.listeners[event] = { priorities: [], handlers: {} };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const priorities =
|
|
134
|
+
this.listeners[event]?.priorities ?? fail<number[]>(`priorities missing for event '${event}'`);
|
|
135
|
+
const handlers =
|
|
136
|
+
this.listeners[event]?.handlers ??
|
|
137
|
+
fail<Record<number, EventListener[]>>(`handlers missing for event '${event}'`);
|
|
138
|
+
|
|
139
|
+
if (!priorities.includes(priority)) {
|
|
140
|
+
priorities.push(priority);
|
|
141
|
+
priorities.sort((a, b) => b - a);
|
|
142
|
+
handlers[priority] = [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
handlers[priority]?.push(handler);
|
|
146
|
+
}
|
|
147
|
+
|
|
83
148
|
}
|
|
84
149
|
|
|
85
|
-
export default facade(
|
|
150
|
+
export default facade(EventsService);
|
|
151
|
+
|
|
152
|
+
declare global {
|
|
153
|
+
// eslint-disable-next-line no-var
|
|
154
|
+
var __aerogelEvents__: AerogelGlobalEvents | undefined;
|
|
155
|
+
}
|
package/src/services/Service.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MagicObject, PromisedValue, Storage, isEmpty, objectDeepClone, objectOnly } from '@noeldemartin/utils';
|
|
2
2
|
import type { Constructor } from '@noeldemartin/utils';
|
|
3
|
+
import type { MaybeRef } from 'vue';
|
|
3
4
|
import type { Store } from 'pinia';
|
|
4
5
|
|
|
5
6
|
import ServiceBootError from '@/errors/ServiceBootError';
|
|
@@ -8,9 +9,12 @@ import { defineServiceStore } from '@/services/store';
|
|
|
8
9
|
export type ServiceState = Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
9
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];
|
|
17
|
+
[K in keyof TComputedState]: (state: UnrefServiceState<TState>) => TComputedState[K];
|
|
14
18
|
} & ThisType<{
|
|
15
19
|
readonly [K in keyof TComputedState]: TComputedState[K];
|
|
16
20
|
}>;
|
|
@@ -20,12 +24,14 @@ export function defineServiceState<
|
|
|
20
24
|
ComputedState extends ServiceState = {}
|
|
21
25
|
>(options: {
|
|
22
26
|
name: string;
|
|
23
|
-
initialState: State;
|
|
27
|
+
initialState: State | (() => State);
|
|
24
28
|
persist?: (keyof State)[];
|
|
25
29
|
computed?: ComputedStateDefinition<State, ComputedState>;
|
|
26
30
|
serialize?: (state: Partial<State>) => Partial<State>;
|
|
27
|
-
}): Constructor<State
|
|
28
|
-
|
|
31
|
+
}): Constructor<UnrefServiceState<State>> &
|
|
32
|
+
Constructor<ComputedState> &
|
|
33
|
+
Constructor<Service<UnrefServiceState<State>, ComputedState, Partial<UnrefServiceState<State>>>> {
|
|
34
|
+
return class extends Service<UnrefServiceState<State>, ComputedState> {
|
|
29
35
|
|
|
30
36
|
public static persist = (options.persist as string[]) ?? [];
|
|
31
37
|
|
|
@@ -37,21 +43,41 @@ export function defineServiceState<
|
|
|
37
43
|
return options.name ?? null;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
protected getInitialState(): State {
|
|
41
|
-
|
|
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>);
|
|
42
68
|
}
|
|
43
69
|
|
|
44
|
-
protected getComputedStateDefinition(): ComputedStateDefinition<State
|
|
45
|
-
return options.computed ??
|
|
70
|
+
protected getComputedStateDefinition(): ComputedStateDefinition<UnrefServiceState<State>, ComputedState> {
|
|
71
|
+
return (options.computed ?? {}) as ComputedStateDefinition<UnrefServiceState<State>, ComputedState>;
|
|
46
72
|
}
|
|
47
73
|
|
|
48
74
|
protected serializePersistedState(state: Partial<State>): Partial<State> {
|
|
49
75
|
return options.serialize?.(state) ?? state;
|
|
50
76
|
}
|
|
51
|
-
|
|
52
|
-
} as unknown as Constructor<State
|
|
77
|
+
|
|
78
|
+
} as unknown as Constructor<UnrefServiceState<State>> &
|
|
53
79
|
Constructor<ComputedState> &
|
|
54
|
-
Constructor<Service<State
|
|
80
|
+
Constructor<Service<UnrefServiceState<State>, ComputedState, Partial<UnrefServiceState<State>>>>;
|
|
55
81
|
}
|
|
56
82
|
|
|
57
83
|
export default class Service<
|
|
@@ -65,7 +91,7 @@ export default class Service<
|
|
|
65
91
|
protected _name: string;
|
|
66
92
|
private _booted: PromisedValue<void>;
|
|
67
93
|
private _computedStateKeys: Set<keyof State>;
|
|
68
|
-
private _store
|
|
94
|
+
private _store: Store | false;
|
|
69
95
|
|
|
70
96
|
constructor() {
|
|
71
97
|
super();
|
|
@@ -104,6 +130,10 @@ export default class Service<
|
|
|
104
130
|
return this._booted;
|
|
105
131
|
}
|
|
106
132
|
|
|
133
|
+
public hasPersistedState(): boolean {
|
|
134
|
+
return Storage.has(this._name);
|
|
135
|
+
}
|
|
136
|
+
|
|
107
137
|
public hasState<P extends keyof State>(property: P): boolean {
|
|
108
138
|
if (!this._store) {
|
|
109
139
|
return false;
|
|
@@ -162,7 +192,11 @@ export default class Service<
|
|
|
162
192
|
return;
|
|
163
193
|
}
|
|
164
194
|
|
|
165
|
-
const storage = Storage.
|
|
195
|
+
const storage = Storage.get<ServiceStorage>(this._name);
|
|
196
|
+
|
|
197
|
+
if (!storage) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
166
200
|
|
|
167
201
|
Storage.set(this._name, {
|
|
168
202
|
...storage,
|
|
@@ -191,14 +225,14 @@ export default class Service<
|
|
|
191
225
|
}
|
|
192
226
|
|
|
193
227
|
protected async frameworkBoot(): Promise<void> {
|
|
194
|
-
this.
|
|
228
|
+
this.initializePersistedState();
|
|
195
229
|
}
|
|
196
230
|
|
|
197
231
|
protected async boot(): Promise<void> {
|
|
198
|
-
//
|
|
232
|
+
// Placeholder for overrides, don't place any functionality here.
|
|
199
233
|
}
|
|
200
234
|
|
|
201
|
-
protected
|
|
235
|
+
protected initializePersistedState(): void {
|
|
202
236
|
// TODO fix this.static()
|
|
203
237
|
const persist = (this.constructor as unknown as { persist: string[] }).persist;
|
|
204
238
|
|
package/src/services/index.ts
CHANGED
|
@@ -3,15 +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';
|
|
8
9
|
import { getPiniaStore } from './store';
|
|
9
10
|
|
|
10
11
|
export * from './App';
|
|
12
|
+
export * from './Cache';
|
|
11
13
|
export * from './Events';
|
|
12
14
|
export * from './Service';
|
|
15
|
+
export * from './store';
|
|
13
16
|
|
|
14
|
-
export { App, Events, Service };
|
|
17
|
+
export { App, Cache, Events, Service };
|
|
15
18
|
|
|
16
19
|
const defaultServices = {
|
|
17
20
|
$app: App,
|
|
@@ -50,7 +53,7 @@ export default definePlugin({
|
|
|
50
53
|
});
|
|
51
54
|
|
|
52
55
|
declare module '@/bootstrap/options' {
|
|
53
|
-
interface AerogelOptions {
|
|
56
|
+
export interface AerogelOptions {
|
|
54
57
|
services?: Record<string, Service>;
|
|
55
58
|
}
|
|
56
59
|
}
|
package/src/services/store.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import { tap } from '@noeldemartin/utils';
|
|
1
2
|
import { createPinia, defineStore, setActivePinia } from 'pinia';
|
|
2
3
|
import type { DefineStoreOptions, Pinia, StateTree, Store, _GettersTree } from 'pinia';
|
|
3
4
|
|
|
4
5
|
let _store: Pinia | null = null;
|
|
5
6
|
|
|
6
7
|
function initializePiniaStore(): Pinia {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
return _store ?? resetPiniaStore();
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
export function resetPiniaStore(): Pinia {
|
|
12
|
+
return tap(createPinia(), (store) => {
|
|
13
|
+
_store = store;
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
setActivePinia(store);
|
|
16
|
+
});
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
export function getPiniaStore(): Pinia {
|
|
@@ -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.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { facade, fail, uuid } from '@noeldemartin/utils';
|
|
1
|
+
import { after, facade, fail, uuid } from '@noeldemartin/utils';
|
|
2
2
|
import { markRaw, nextTick } from 'vue';
|
|
3
3
|
import type { Component } from 'vue';
|
|
4
4
|
import type { ObjectValues } from '@noeldemartin/utils';
|
|
5
5
|
|
|
6
6
|
import Events from '@/services/Events';
|
|
7
7
|
import type { SnackbarAction, SnackbarColor } from '@/components/headless/snackbars';
|
|
8
|
+
import type { AGAlertModalProps, AGConfirmModalProps, AGLoadingModalProps, AGPromptModalProps } from '@/components';
|
|
8
9
|
|
|
9
10
|
import Service from './UI.state';
|
|
10
11
|
import type { Modal, ModalComponent, Snackbar } from './UI.state';
|
|
@@ -24,11 +25,27 @@ export const UIComponents = {
|
|
|
24
25
|
ConfirmModal: 'confirm-modal',
|
|
25
26
|
ErrorReportModal: 'error-report-modal',
|
|
26
27
|
LoadingModal: 'loading-modal',
|
|
28
|
+
PromptModal: 'prompt-modal',
|
|
27
29
|
Snackbar: 'snackbar',
|
|
30
|
+
StartupCrash: 'startup-crash',
|
|
28
31
|
} as const;
|
|
29
32
|
|
|
30
33
|
export type UIComponent = ObjectValues<typeof UIComponents>;
|
|
31
34
|
|
|
35
|
+
export interface ConfirmOptions {
|
|
36
|
+
acceptText?: string;
|
|
37
|
+
cancelText?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PromptOptions {
|
|
41
|
+
label?: string;
|
|
42
|
+
defaultValue?: string;
|
|
43
|
+
placeholder?: string;
|
|
44
|
+
acceptText?: string;
|
|
45
|
+
cancelText?: string;
|
|
46
|
+
trim?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
32
49
|
export interface ShowSnackbarOptions {
|
|
33
50
|
component?: Component;
|
|
34
51
|
color?: SnackbarColor;
|
|
@@ -47,43 +64,113 @@ export class UIService extends Service {
|
|
|
47
64
|
public alert(message: string): void;
|
|
48
65
|
public alert(title: string, message: string): void;
|
|
49
66
|
public alert(messageOrTitle: string, message?: string): void {
|
|
50
|
-
const
|
|
67
|
+
const getProperties = (): AGAlertModalProps => {
|
|
68
|
+
if (typeof message !== 'string') {
|
|
69
|
+
return { message: messageOrTitle };
|
|
70
|
+
}
|
|
51
71
|
|
|
52
|
-
|
|
72
|
+
return {
|
|
73
|
+
title: messageOrTitle,
|
|
74
|
+
message,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
this.openModal(this.requireComponent(UIComponents.AlertModal), getProperties());
|
|
53
79
|
}
|
|
54
80
|
|
|
55
|
-
public async confirm(message: string): Promise<boolean>;
|
|
56
|
-
public async confirm(title: string, message: string): Promise<boolean>;
|
|
57
|
-
public async confirm(
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
public async confirm(message: string, options?: ConfirmOptions): Promise<boolean>;
|
|
82
|
+
public async confirm(title: string, message: string, options?: ConfirmOptions): Promise<boolean>;
|
|
83
|
+
public async confirm(
|
|
84
|
+
messageOrTitle: string,
|
|
85
|
+
messageOrOptions?: string | ConfirmOptions,
|
|
86
|
+
options?: ConfirmOptions,
|
|
87
|
+
): Promise<boolean> {
|
|
88
|
+
const getProperties = (): AGConfirmModalProps => {
|
|
89
|
+
if (typeof messageOrOptions !== 'string') {
|
|
90
|
+
return {
|
|
91
|
+
message: messageOrTitle,
|
|
92
|
+
...(messageOrOptions ?? {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
title: messageOrTitle,
|
|
98
|
+
message: messageOrOptions,
|
|
99
|
+
...(options ?? {}),
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const modal = await this.openModal<ModalComponent<AGConfirmModalProps, boolean>>(
|
|
60
104
|
this.requireComponent(UIComponents.ConfirmModal),
|
|
61
|
-
|
|
105
|
+
getProperties(),
|
|
62
106
|
);
|
|
63
107
|
const result = await modal.beforeClose;
|
|
64
108
|
|
|
65
109
|
return result ?? false;
|
|
66
110
|
}
|
|
67
111
|
|
|
112
|
+
public async prompt(message: string, options?: PromptOptions): Promise<string | null>;
|
|
113
|
+
public async prompt(title: string, message: string, options?: PromptOptions): Promise<string | null>;
|
|
114
|
+
public async prompt(
|
|
115
|
+
messageOrTitle: string,
|
|
116
|
+
messageOrOptions?: string | PromptOptions,
|
|
117
|
+
options?: PromptOptions,
|
|
118
|
+
): Promise<string | null> {
|
|
119
|
+
const trim = options?.trim ?? true;
|
|
120
|
+
const getProperties = (): AGPromptModalProps => {
|
|
121
|
+
if (typeof messageOrOptions !== 'string') {
|
|
122
|
+
return {
|
|
123
|
+
message: messageOrTitle,
|
|
124
|
+
...(messageOrOptions ?? {}),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
title: messageOrTitle,
|
|
130
|
+
message: messageOrOptions,
|
|
131
|
+
...(options ?? {}),
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const modal = await this.openModal<ModalComponent<AGPromptModalProps, string | null>>(
|
|
136
|
+
this.requireComponent(UIComponents.PromptModal),
|
|
137
|
+
getProperties(),
|
|
138
|
+
);
|
|
139
|
+
const rawResult = await modal.beforeClose;
|
|
140
|
+
const result = trim ? rawResult?.trim() : rawResult;
|
|
141
|
+
|
|
142
|
+
return result ?? null;
|
|
143
|
+
}
|
|
144
|
+
|
|
68
145
|
public async loading<T>(operation: Promise<T>): Promise<T>;
|
|
69
146
|
public async loading<T>(message: string, operation: Promise<T>): Promise<T>;
|
|
70
147
|
public async loading<T>(messageOrOperation: string | Promise<T>, operation?: Promise<T>): Promise<T> {
|
|
71
|
-
|
|
148
|
+
const getProperties = (): AGLoadingModalProps => {
|
|
149
|
+
if (typeof messageOrOperation !== 'string') {
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return { message: messageOrOperation };
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const modal = await this.openModal(this.requireComponent(UIComponents.LoadingModal), getProperties());
|
|
72
157
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const result = await operation;
|
|
158
|
+
try {
|
|
159
|
+
operation = typeof messageOrOperation === 'string' ? (operation as Promise<T>) : messageOrOperation;
|
|
76
160
|
|
|
77
|
-
|
|
161
|
+
const [result] = await Promise.all([operation, after({ seconds: 1 })]);
|
|
78
162
|
|
|
79
|
-
|
|
163
|
+
return result;
|
|
164
|
+
} finally {
|
|
165
|
+
await this.closeModal(modal.id);
|
|
166
|
+
}
|
|
80
167
|
}
|
|
81
168
|
|
|
82
169
|
public showSnackbar(message: string, options: ShowSnackbarOptions = {}): void {
|
|
83
170
|
const snackbar: Snackbar = {
|
|
84
171
|
id: uuid(),
|
|
85
172
|
properties: { message, ...options },
|
|
86
|
-
component: options.component ??
|
|
173
|
+
component: markRaw(options.component ?? this.requireComponent(UIComponents.Snackbar)),
|
|
87
174
|
};
|
|
88
175
|
|
|
89
176
|
this.setState('snackbars', this.snackbars.concat(snackbar));
|
|
@@ -138,6 +225,7 @@ export class UIService extends Service {
|
|
|
138
225
|
|
|
139
226
|
protected async boot(): Promise<void> {
|
|
140
227
|
this.watchModalEvents();
|
|
228
|
+
this.watchMountedEvent();
|
|
141
229
|
}
|
|
142
230
|
|
|
143
231
|
private watchModalEvents(): void {
|
|
@@ -165,16 +253,36 @@ export class UIService extends Service {
|
|
|
165
253
|
});
|
|
166
254
|
}
|
|
167
255
|
|
|
256
|
+
private watchMountedEvent(): void {
|
|
257
|
+
Events.once('application-mounted', async () => {
|
|
258
|
+
const splash = document.getElementById('splash');
|
|
259
|
+
|
|
260
|
+
if (!splash) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (window.getComputedStyle(splash).opacity !== '0') {
|
|
265
|
+
splash.style.opacity = '0';
|
|
266
|
+
|
|
267
|
+
await after({ ms: 600 });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
splash.remove();
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
168
274
|
}
|
|
169
275
|
|
|
170
|
-
export default facade(
|
|
276
|
+
export default facade(UIService);
|
|
171
277
|
|
|
172
278
|
declare module '@/services/Events' {
|
|
173
279
|
export interface EventsPayload {
|
|
174
|
-
'modal-will-close': { modal: Modal; result?: unknown };
|
|
175
|
-
'modal-closed': { modal: Modal; result?: unknown };
|
|
176
280
|
'close-modal': { id: string; result?: unknown };
|
|
177
281
|
'hide-modal': { id: string };
|
|
282
|
+
'hide-overlays-backdrop': void;
|
|
283
|
+
'modal-closed': { modal: Modal; result?: unknown };
|
|
284
|
+
'modal-will-close': { modal: Modal; result?: unknown };
|
|
178
285
|
'show-modal': { id: string };
|
|
286
|
+
'show-overlays-backdrop': void;
|
|
179
287
|
}
|
|
180
288
|
}
|
package/src/ui/index.ts
CHANGED
|
@@ -8,13 +8,16 @@ import AGAlertModal from '../components/modals/AGAlertModal.vue';
|
|
|
8
8
|
import AGConfirmModal from '../components/modals/AGConfirmModal.vue';
|
|
9
9
|
import AGErrorReportModal from '../components/modals/AGErrorReportModal.vue';
|
|
10
10
|
import AGLoadingModal from '../components/modals/AGLoadingModal.vue';
|
|
11
|
+
import AGPromptModal from '../components/modals/AGPromptModal.vue';
|
|
11
12
|
import AGSnackbar from '../components/snackbars/AGSnackbar.vue';
|
|
13
|
+
import AGStartupCrash from '../components/lib/AGStartupCrash.vue';
|
|
12
14
|
import type { UIComponent } from './UI';
|
|
13
15
|
|
|
14
|
-
export { UI, UIComponents, UIComponent };
|
|
15
|
-
|
|
16
16
|
const services = { $ui: UI };
|
|
17
17
|
|
|
18
|
+
export * from './UI';
|
|
19
|
+
export { default as UI } from './UI';
|
|
20
|
+
|
|
18
21
|
export type UIServices = typeof services;
|
|
19
22
|
|
|
20
23
|
export default definePlugin({
|
|
@@ -24,7 +27,9 @@ export default definePlugin({
|
|
|
24
27
|
[UIComponents.ConfirmModal]: AGConfirmModal,
|
|
25
28
|
[UIComponents.ErrorReportModal]: AGErrorReportModal,
|
|
26
29
|
[UIComponents.LoadingModal]: AGLoadingModal,
|
|
30
|
+
[UIComponents.PromptModal]: AGPromptModal,
|
|
27
31
|
[UIComponents.Snackbar]: AGSnackbar,
|
|
32
|
+
[UIComponents.StartupCrash]: AGStartupCrash,
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
Object.entries({
|
|
@@ -37,7 +42,7 @@ export default definePlugin({
|
|
|
37
42
|
});
|
|
38
43
|
|
|
39
44
|
declare module '@/bootstrap/options' {
|
|
40
|
-
interface AerogelOptions {
|
|
45
|
+
export interface AerogelOptions {
|
|
41
46
|
components?: Partial<Record<UIComponent, Component>>;
|
|
42
47
|
}
|
|
43
48
|
}
|
|
@@ -14,6 +14,7 @@ export function useEvent<Event extends EventWithPayload>(
|
|
|
14
14
|
event: Event,
|
|
15
15
|
listener: EventListener<EventsPayload[Event]>
|
|
16
16
|
): void;
|
|
17
|
+
export function useEvent<Payload>(event: string, listener: (payload: Payload) => unknown): void;
|
|
17
18
|
export function useEvent<Event extends string>(event: UnknownEvent<Event>, listener: EventListener): void;
|
|
18
19
|
|
|
19
20
|
export function useEvent(event: string, listener: EventListener): void {
|