@aerogel/core 0.0.0-next.a68f133e2c9a1ae9ba84b4e2e42df909289e5fba → 0.0.0-next.b243de4e2590f02709edeebd8c13b74087592c04

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 (61) 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 +383 -48
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/package.json +3 -3
  7. package/src/bootstrap/bootstrap.test.ts +0 -1
  8. package/src/bootstrap/index.ts +5 -4
  9. package/src/components/AGAppSnackbars.vue +1 -1
  10. package/src/components/composition.ts +23 -0
  11. package/src/components/forms/AGForm.vue +9 -10
  12. package/src/components/forms/AGInput.vue +2 -0
  13. package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
  14. package/src/components/headless/forms/AGHeadlessButton.vue +23 -12
  15. package/src/components/headless/forms/AGHeadlessInput.ts +10 -4
  16. package/src/components/headless/forms/AGHeadlessInput.vue +18 -5
  17. package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
  18. package/src/components/headless/forms/AGHeadlessInputInput.vue +44 -5
  19. package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
  20. package/src/components/headless/forms/composition.ts +10 -0
  21. package/src/components/headless/forms/index.ts +4 -0
  22. package/src/components/index.ts +2 -0
  23. package/src/components/interfaces.ts +24 -0
  24. package/src/components/lib/AGErrorMessage.vue +2 -2
  25. package/src/components/lib/AGMarkdown.vue +9 -4
  26. package/src/components/lib/AGMeasured.vue +1 -0
  27. package/src/components/modals/AGConfirmModal.ts +9 -3
  28. package/src/components/modals/AGConfirmModal.vue +2 -2
  29. package/src/components/modals/AGPromptModal.ts +9 -3
  30. package/src/components/modals/AGPromptModal.vue +2 -2
  31. package/src/directives/index.ts +2 -0
  32. package/src/directives/measure.ts +33 -5
  33. package/src/errors/Errors.ts +9 -16
  34. package/src/errors/index.ts +1 -0
  35. package/src/errors/utils.ts +19 -0
  36. package/src/forms/Form.test.ts +28 -0
  37. package/src/forms/Form.ts +65 -8
  38. package/src/forms/index.ts +3 -1
  39. package/src/forms/utils.ts +34 -3
  40. package/src/forms/validation.ts +19 -0
  41. package/src/jobs/Job.ts +5 -0
  42. package/src/jobs/index.ts +7 -0
  43. package/src/lang/DefaultLangProvider.ts +43 -0
  44. package/src/lang/Lang.state.ts +11 -0
  45. package/src/lang/Lang.ts +43 -28
  46. package/src/main.ts +3 -0
  47. package/src/services/App.state.ts +14 -0
  48. package/src/services/App.ts +3 -0
  49. package/src/services/Cache.ts +43 -0
  50. package/src/services/Events.test.ts +39 -0
  51. package/src/services/Events.ts +99 -29
  52. package/src/services/Service.ts +15 -3
  53. package/src/services/index.ts +3 -1
  54. package/src/testing/index.ts +25 -0
  55. package/src/testing/setup.ts +19 -0
  56. package/src/ui/UI.state.ts +7 -0
  57. package/src/ui/UI.ts +40 -10
  58. package/src/ui/index.ts +1 -0
  59. package/src/ui/utils.ts +16 -0
  60. package/src/utils/vue.ts +11 -2
  61. package/vite.config.ts +4 -1
@@ -1,3 +1,5 @@
1
+ import Aerogel from 'virtual:aerogel';
2
+
1
3
  import { PromisedValue, facade, forever, updateLocationQueryParameters } from '@noeldemartin/utils';
2
4
 
3
5
  import Events from '@/services/Events';
@@ -7,6 +9,7 @@ import Service from './App.state';
7
9
 
8
10
  export class AppService extends Service {
9
11
 
12
+ public readonly name = Aerogel.name;
10
13
  public readonly ready = new PromisedValue<void>();
11
14
  public readonly mounted = new PromisedValue<void>();
12
15
 
@@ -0,0 +1,43 @@
1
+ import { PromisedValue, facade, tap } from '@noeldemartin/utils';
2
+
3
+ import Service from '@/services/Service';
4
+
5
+ export class CacheService extends Service {
6
+
7
+ private cache?: PromisedValue<Cache> = undefined;
8
+
9
+ public async get(url: string): Promise<Response | null> {
10
+ const cache = await this.open();
11
+ const response = await cache.match(url);
12
+
13
+ return response ?? null;
14
+ }
15
+
16
+ public async store(url: string, response: Response): Promise<void> {
17
+ const cache = await this.open();
18
+
19
+ await cache.put(url, response);
20
+ }
21
+
22
+ public async replace(url: string, response: Response): Promise<void> {
23
+ const cache = await this.open();
24
+ const keys = await cache.keys(url);
25
+
26
+ if (keys.length === 0) {
27
+ return;
28
+ }
29
+
30
+ await cache.put(url, response);
31
+ }
32
+
33
+ protected async open(): Promise<Cache> {
34
+ return (this.cache =
35
+ this.cache ??
36
+ tap(new PromisedValue<Cache>(), (cache) => {
37
+ caches.open('app').then((instance) => cache.resolve(instance));
38
+ }));
39
+ }
40
+
41
+ }
42
+
43
+ export default facade(CacheService);
@@ -0,0 +1,39 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest';
2
+
3
+ import Events, { EventListenerPriorities } from './Events';
4
+
5
+ describe('Events', () => {
6
+
7
+ beforeEach(() => void Events.reset());
8
+
9
+ it('registers listeners', async () => {
10
+ // Arrange
11
+ let counter = 0;
12
+
13
+ Events.on('trigger', () => counter++);
14
+
15
+ // Act
16
+ await Events.emit('trigger');
17
+ await Events.emit('trigger');
18
+ await Events.emit('trigger');
19
+
20
+ // Assert
21
+ expect(counter).toEqual(3);
22
+ });
23
+
24
+ it('triggers listeners by priority', async () => {
25
+ // Arrange
26
+ const storage: string[] = [];
27
+
28
+ Events.on('trigger', () => storage.push('second'));
29
+ Events.on('trigger', { priority: EventListenerPriorities.Low }, () => storage.push('third'));
30
+ Events.on('trigger', { priority: EventListenerPriorities.High }, () => storage.push('first'));
31
+
32
+ // Act
33
+ await Events.emit('trigger');
34
+
35
+ // Assert
36
+ expect(storage).toEqual(['first', 'second', 'third']);
37
+ });
38
+
39
+ });
@@ -1,9 +1,13 @@
1
- import { arr, facade, tap } from '@noeldemartin/utils';
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, FluentArray<EventListener>> = {};
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 = [...(this.listeners[event] ?? [])];
42
+ const listeners = this.listeners[event] ?? { priorities: [], handlers: {} };
28
43
 
29
- await Promise.all(listeners.map((listener) => listener(payload)) ?? []);
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 EventWithPayload>(
34
- event: Event,
35
- listener: EventListener<EventsPayload[Event]>
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: string, listener: EventListener): () => void {
40
- (this.listeners[event] ??= arr<EventListener>([])).push(listener);
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
- return () => this.off(event, listener);
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 EventWithPayload>(
47
- event: Event,
48
- listener: EventListener<EventsPayload[Event]>
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: string, listener: EventListener): () => void {
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
- (this.listeners[event] ??= arr<EventListener>([])).push(
59
- (onceListener = (...args) => {
60
- off();
92
+ onceListener = (...args) => {
93
+ off();
61
94
 
62
- return listener(...args);
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 eventListeners = this.listeners[event];
104
+ const listeners = this.listeners[event];
71
105
 
72
- if (!eventListeners) {
106
+ if (!listeners) {
73
107
  return;
74
108
  }
75
109
 
76
- eventListeners.remove(listener);
110
+ const priorities = [...listeners.priorities];
111
+
112
+ for (const priority of priorities) {
113
+ arrayRemove(listeners.handlers[priority] ?? [], listener);
77
114
 
78
- if (eventListeners.isEmpty()) {
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
150
  export default facade(EventsService);
151
+
152
+ declare global {
153
+ // eslint-disable-next-line no-var
154
+ var __aerogelEvents__: AerogelGlobalEvents | undefined;
155
+ }
@@ -1,4 +1,4 @@
1
- import { MagicObject, PromisedValue, Storage, isEmpty, objectDeepClone, objectOnly } from '@noeldemartin/utils';
1
+ import { MagicObject, PromisedValue, Storage, fail, isEmpty, objectDeepClone, objectOnly } from '@noeldemartin/utils';
2
2
  import type { Constructor } from '@noeldemartin/utils';
3
3
  import type { MaybeRef } from 'vue';
4
4
  import type { Store } from 'pinia';
@@ -74,7 +74,7 @@ export function defineServiceState<
74
74
  protected serializePersistedState(state: Partial<State>): Partial<State> {
75
75
  return options.serialize?.(state) ?? state;
76
76
  }
77
-
77
+
78
78
  } as unknown as Constructor<UnrefServiceState<State>> &
79
79
  Constructor<ComputedState> &
80
80
  Constructor<Service<UnrefServiceState<State>, ComputedState, Partial<UnrefServiceState<State>>>>;
@@ -91,7 +91,7 @@ export default class Service<
91
91
  protected _name: string;
92
92
  private _booted: PromisedValue<void>;
93
93
  private _computedStateKeys: Set<keyof State>;
94
- private _store?: Store | false;
94
+ private _store: Store<string, State, ComputedState, {}> | false;
95
95
 
96
96
  constructor() {
97
97
  super();
@@ -130,6 +130,10 @@ export default class Service<
130
130
  return this._booted;
131
131
  }
132
132
 
133
+ public hasPersistedState(): boolean {
134
+ return Storage.has(this._name);
135
+ }
136
+
133
137
  public hasState<P extends keyof State>(property: P): boolean {
134
138
  if (!this._store) {
135
139
  return false;
@@ -246,4 +250,12 @@ export default class Service<
246
250
  Storage.set(this._name, objectOnly(this.getState(), persist));
247
251
  }
248
252
 
253
+ protected requireStore(): Store<string, State, ComputedState, {}> {
254
+ if (!this._store) {
255
+ return fail(`Failed getting '${this._name}' store`);
256
+ }
257
+
258
+ return this._store;
259
+ }
260
+
249
261
  }
@@ -3,16 +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';
13
15
  export * from './store';
14
16
 
15
- export { App, Events, Service };
17
+ export { App, Cache, Events, Service };
16
18
 
17
19
  const defaultServices = {
18
20
  $app: App,
@@ -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
+ }
@@ -0,0 +1,19 @@
1
+ import { mock, tap } from '@noeldemartin/utils';
2
+ import { beforeEach, vi } from 'vitest';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ tap(globalThis, (global: any) => {
6
+ global.jest = vi;
7
+ global.navigator = { languages: ['en'] };
8
+ global.localStorage = mock<Storage>({
9
+ getItem: () => null,
10
+ setItem: () => null,
11
+ });
12
+ });
13
+
14
+ beforeEach(() => {
15
+ vi.stubGlobal('document', {
16
+ querySelector: () => null,
17
+ getElementById: () => null,
18
+ });
19
+ });
@@ -2,6 +2,8 @@ import type { Component } from 'vue';
2
2
 
3
3
  import { defineServiceState } from '@/services/Service';
4
4
 
5
+ import { Layouts, getCurrentLayout } from './utils';
6
+
5
7
  export interface Modal<T = unknown> {
6
8
  id: string;
7
9
  properties: Record<string, unknown>;
@@ -28,5 +30,10 @@ export default defineServiceState({
28
30
  initialState: {
29
31
  modals: [] as Modal[],
30
32
  snackbars: [] as Snackbar[],
33
+ layout: getCurrentLayout(),
34
+ },
35
+ computed: {
36
+ mobile: ({ layout }) => layout === Layouts.Mobile,
37
+ desktop: ({ layout }) => layout === Layouts.Desktop,
31
38
  },
32
39
  });
package/src/ui/UI.ts CHANGED
@@ -4,10 +4,12 @@ import type { Component } from 'vue';
4
4
  import type { ObjectValues } from '@noeldemartin/utils';
5
5
 
6
6
  import Events from '@/services/Events';
7
+ import type { Color } from '@/components/constants';
7
8
  import type { SnackbarAction, SnackbarColor } from '@/components/headless/snackbars';
8
9
  import type { AGAlertModalProps, AGConfirmModalProps, AGLoadingModalProps, AGPromptModalProps } from '@/components';
9
10
 
10
11
  import Service from './UI.state';
12
+ import { MOBILE_BREAKPOINT, getCurrentLayout } from './utils';
11
13
  import type { Modal, ModalComponent, Snackbar } from './UI.state';
12
14
 
13
15
  interface ModalCallbacks<T = unknown> {
@@ -34,7 +36,9 @@ export type UIComponent = ObjectValues<typeof UIComponents>;
34
36
 
35
37
  export interface ConfirmOptions {
36
38
  acceptText?: string;
39
+ acceptColor?: Color;
37
40
  cancelText?: string;
41
+ cancelColor?: Color;
38
42
  }
39
43
 
40
44
  export interface PromptOptions {
@@ -42,7 +46,10 @@ export interface PromptOptions {
42
46
  defaultValue?: string;
43
47
  placeholder?: string;
44
48
  acceptText?: string;
49
+ acceptColor?: Color;
45
50
  cancelText?: string;
51
+ cancelColor?: Color;
52
+ trim?: boolean;
46
53
  }
47
54
 
48
55
  export interface ShowSnackbarOptions {
@@ -115,6 +122,7 @@ export class UIService extends Service {
115
122
  messageOrOptions?: string | PromptOptions,
116
123
  options?: PromptOptions,
117
124
  ): Promise<string | null> {
125
+ const trim = options?.trim ?? true;
118
126
  const getProperties = (): AGPromptModalProps => {
119
127
  if (typeof messageOrOptions !== 'string') {
120
128
  return {
@@ -134,14 +142,18 @@ export class UIService extends Service {
134
142
  this.requireComponent(UIComponents.PromptModal),
135
143
  getProperties(),
136
144
  );
137
- const result = await modal.beforeClose;
145
+ const rawResult = await modal.beforeClose;
146
+ const result = trim && typeof rawResult === 'string' ? rawResult?.trim() : rawResult;
138
147
 
139
148
  return result ?? null;
140
149
  }
141
150
 
142
- public async loading<T>(operation: Promise<T>): Promise<T>;
143
- public async loading<T>(message: string, operation: Promise<T>): Promise<T>;
144
- public async loading<T>(messageOrOperation: string | Promise<T>, operation?: Promise<T>): Promise<T> {
151
+ public async loading<T>(operation: Promise<T> | (() => T)): Promise<T>;
152
+ public async loading<T>(message: string, operation: Promise<T> | (() => T)): Promise<T>;
153
+ public async loading<T>(
154
+ messageOrOperation: string | Promise<T> | (() => T),
155
+ operation?: Promise<T> | (() => T),
156
+ ): Promise<T> {
145
157
  const getProperties = (): AGLoadingModalProps => {
146
158
  if (typeof messageOrOperation !== 'string') {
147
159
  return {};
@@ -153,7 +165,8 @@ export class UIService extends Service {
153
165
  const modal = await this.openModal(this.requireComponent(UIComponents.LoadingModal), getProperties());
154
166
 
155
167
  try {
156
- operation = typeof messageOrOperation === 'string' ? (operation as Promise<T>) : messageOrOperation;
168
+ operation = typeof messageOrOperation === 'string' ? (operation as () => T) : messageOrOperation;
169
+ operation = typeof operation === 'function' ? Promise.resolve(operation()) : operation;
157
170
 
158
171
  const [result] = await Promise.all([operation, after({ seconds: 1 })]);
159
172
 
@@ -167,7 +180,7 @@ export class UIService extends Service {
167
180
  const snackbar: Snackbar = {
168
181
  id: uuid(),
169
182
  properties: { message, ...options },
170
- component: options.component ?? markRaw(this.requireComponent(UIComponents.Snackbar)),
183
+ component: markRaw(options.component ?? this.requireComponent(UIComponents.Snackbar)),
171
184
  };
172
185
 
173
186
  this.setState('snackbars', this.snackbars.concat(snackbar));
@@ -223,6 +236,7 @@ export class UIService extends Service {
223
236
  protected async boot(): Promise<void> {
224
237
  this.watchModalEvents();
225
238
  this.watchMountedEvent();
239
+ this.watchViewportBreakpoints();
226
240
  }
227
241
 
228
242
  private watchModalEvents(): void {
@@ -252,13 +266,17 @@ export class UIService extends Service {
252
266
 
253
267
  private watchMountedEvent(): void {
254
268
  Events.once('application-mounted', async () => {
255
- const splash = document.getElementById('splash');
269
+ if (!globalThis.document || !globalThis.getComputedStyle) {
270
+ return;
271
+ }
272
+
273
+ const splash = globalThis.document.getElementById('splash');
256
274
 
257
275
  if (!splash) {
258
276
  return;
259
277
  }
260
278
 
261
- if (window.getComputedStyle(splash).opacity !== '0') {
279
+ if (globalThis.getComputedStyle(splash).opacity !== '0') {
262
280
  splash.style.opacity = '0';
263
281
 
264
282
  await after({ ms: 600 });
@@ -268,16 +286,28 @@ export class UIService extends Service {
268
286
  });
269
287
  }
270
288
 
289
+ private watchViewportBreakpoints(): void {
290
+ if (!globalThis.matchMedia) {
291
+ return;
292
+ }
293
+
294
+ const media = globalThis.matchMedia(`(min-width: ${MOBILE_BREAKPOINT}px)`);
295
+
296
+ media.addEventListener('change', () => this.setState({ layout: getCurrentLayout() }));
297
+ }
298
+
271
299
  }
272
300
 
273
301
  export default facade(UIService);
274
302
 
275
303
  declare module '@/services/Events' {
276
304
  export interface EventsPayload {
277
- 'modal-will-close': { modal: Modal; result?: unknown };
278
- 'modal-closed': { modal: Modal; result?: unknown };
279
305
  'close-modal': { id: string; result?: unknown };
280
306
  'hide-modal': { id: string };
307
+ 'hide-overlays-backdrop': void;
308
+ 'modal-closed': { modal: Modal; result?: unknown };
309
+ 'modal-will-close': { modal: Modal; result?: unknown };
281
310
  'show-modal': { id: string };
311
+ 'show-overlays-backdrop': void;
282
312
  }
283
313
  }
package/src/ui/index.ts CHANGED
@@ -16,6 +16,7 @@ import type { UIComponent } from './UI';
16
16
  const services = { $ui: UI };
17
17
 
18
18
  export * from './UI';
19
+ export * from './utils';
19
20
  export { default as UI } from './UI';
20
21
 
21
22
  export type UIServices = typeof services;
@@ -0,0 +1,16 @@
1
+ export const MOBILE_BREAKPOINT = 768;
2
+
3
+ export const Layouts = {
4
+ Mobile: 'mobile',
5
+ Desktop: 'desktop',
6
+ } as const;
7
+
8
+ export type Layout = (typeof Layouts)[keyof typeof Layouts];
9
+
10
+ export function getCurrentLayout(): Layout {
11
+ if (globalThis.innerWidth > MOBILE_BREAKPOINT) {
12
+ return Layouts.Desktop;
13
+ }
14
+
15
+ return Layouts.Mobile;
16
+ }
package/src/utils/vue.ts CHANGED
@@ -73,13 +73,22 @@ export function injectOrFail<T>(key: InjectionKey<T> | string, errorMessage?: st
73
73
  return inject(key) ?? fail(errorMessage ?? `Could not resolve '${key}' injection key`);
74
74
  }
75
75
 
76
- export function mixedProp<T>(type?: PropType<T>): OptionalProp<T | null> {
76
+ export function listenerProp<T extends Function = Function>(): OptionalProp<T | null> {
77
77
  return {
78
- type,
78
+ type: Function as PropType<T>,
79
79
  default: null,
80
80
  };
81
81
  }
82
82
 
83
+ export function mixedProp<T>(type?: PropType<T>): OptionalProp<T | null>;
84
+ export function mixedProp<T>(type: PropType<T>, defaultValue: T): OptionalProp<T>;
85
+ export function mixedProp<T>(type?: PropType<T>, defaultValue?: T): OptionalProp<T | null> {
86
+ return {
87
+ type,
88
+ default: defaultValue ?? null,
89
+ };
90
+ }
91
+
83
92
  export function numberProp(): OptionalProp<number | null>;
84
93
  export function numberProp(defaultValue: number): OptionalProp<number>;
85
94
  export function numberProp(defaultValue: number | null = null): OptionalProp<number | null> {
package/vite.config.ts CHANGED
@@ -4,7 +4,10 @@ import { defineConfig } from 'vitest/config';
4
4
  import { resolve } from 'path';
5
5
 
6
6
  export default defineConfig({
7
- test: { clearMocks: true },
7
+ test: {
8
+ clearMocks: true,
9
+ setupFiles: ['./src/testing/setup.ts'],
10
+ },
8
11
  plugins: [Aerogel(), Icons()],
9
12
  resolve: {
10
13
  alias: {