@aerogel/core 0.0.0-next.d824b40e5d06757cd9f47c9f771d916185df4f05 → 0.0.0-next.eed7a057cf5b844cd9f7fc6bda2d8df49fcd6736

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 (137) hide show
  1. package/dist/aerogel-core.d.ts +3212 -485
  2. package/dist/aerogel-core.js +2789 -0
  3. package/dist/aerogel-core.js.map +1 -0
  4. package/package.json +25 -31
  5. package/src/bootstrap/bootstrap.test.ts +7 -10
  6. package/src/bootstrap/index.ts +43 -15
  7. package/src/bootstrap/options.ts +4 -1
  8. package/src/components/AGAppLayout.vue +7 -2
  9. package/src/components/AGAppModals.vue +1 -1
  10. package/src/components/AGAppOverlays.vue +6 -2
  11. package/src/components/AGAppSnackbars.vue +2 -2
  12. package/src/components/composition.ts +23 -0
  13. package/src/components/forms/AGButton.vue +2 -2
  14. package/src/components/forms/AGCheckbox.vue +10 -3
  15. package/src/components/forms/AGForm.vue +11 -12
  16. package/src/components/forms/AGInput.vue +13 -7
  17. package/src/components/forms/AGSelect.story.vue +46 -0
  18. package/src/components/forms/AGSelect.vue +60 -0
  19. package/src/components/forms/index.ts +5 -6
  20. package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
  21. package/src/components/headless/forms/AGHeadlessButton.vue +24 -13
  22. package/src/components/headless/forms/AGHeadlessInput.ts +37 -4
  23. package/src/components/headless/forms/AGHeadlessInput.vue +24 -8
  24. package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
  25. package/src/components/headless/forms/AGHeadlessInputError.vue +2 -2
  26. package/src/components/headless/forms/AGHeadlessInputInput.vue +45 -6
  27. package/src/components/headless/forms/AGHeadlessInputLabel.vue +9 -3
  28. package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
  29. package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
  30. package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
  31. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  32. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  33. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  34. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  35. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  37. package/src/components/headless/forms/composition.ts +10 -0
  38. package/src/components/headless/forms/index.ts +13 -1
  39. package/src/components/headless/modals/AGHeadlessModal.ts +30 -1
  40. package/src/components/headless/modals/AGHeadlessModal.vue +16 -12
  41. package/src/components/headless/modals/AGHeadlessModalPanel.vue +13 -9
  42. package/src/components/headless/modals/AGHeadlessModalTitle.vue +14 -4
  43. package/src/components/headless/modals/index.ts +4 -6
  44. package/src/components/headless/snackbars/index.ts +25 -10
  45. package/src/components/index.ts +3 -1
  46. package/src/components/interfaces.ts +24 -0
  47. package/src/components/lib/AGErrorMessage.vue +16 -0
  48. package/src/components/lib/AGMarkdown.vue +54 -0
  49. package/src/components/lib/AGMeasured.vue +16 -0
  50. package/src/components/lib/AGProgressBar.vue +55 -0
  51. package/src/components/lib/AGStartupCrash.vue +31 -0
  52. package/src/components/lib/index.ts +6 -0
  53. package/src/components/modals/AGAlertModal.ts +18 -0
  54. package/src/components/modals/AGAlertModal.vue +4 -15
  55. package/src/components/modals/AGConfirmModal.ts +42 -0
  56. package/src/components/modals/AGConfirmModal.vue +10 -14
  57. package/src/components/modals/AGErrorReportModal.ts +32 -3
  58. package/src/components/modals/AGErrorReportModal.vue +8 -16
  59. package/src/components/modals/AGErrorReportModalButtons.vue +13 -11
  60. package/src/components/modals/AGErrorReportModalTitle.vue +3 -3
  61. package/src/components/modals/AGLoadingModal.ts +29 -0
  62. package/src/components/modals/AGLoadingModal.vue +4 -8
  63. package/src/components/modals/AGModal.ts +2 -1
  64. package/src/components/modals/AGModal.vue +18 -13
  65. package/src/components/modals/AGModalContext.ts +1 -1
  66. package/src/components/modals/AGModalContext.vue +15 -5
  67. package/src/components/modals/AGPromptModal.ts +41 -0
  68. package/src/components/modals/AGPromptModal.vue +34 -0
  69. package/src/components/modals/index.ts +13 -19
  70. package/src/components/snackbars/AGSnackbar.vue +4 -10
  71. package/src/components/utils.ts +13 -0
  72. package/src/directives/index.ts +7 -5
  73. package/src/directives/measure.ts +40 -0
  74. package/src/errors/Errors.state.ts +1 -1
  75. package/src/errors/Errors.ts +32 -30
  76. package/src/errors/JobCancelledError.ts +3 -0
  77. package/src/errors/index.ts +19 -29
  78. package/src/errors/utils.ts +35 -0
  79. package/src/forms/Form.test.ts +32 -3
  80. package/src/forms/Form.ts +90 -21
  81. package/src/forms/composition.ts +2 -2
  82. package/src/forms/index.ts +3 -1
  83. package/src/forms/utils.ts +34 -3
  84. package/src/forms/validation.ts +19 -0
  85. package/src/{main.ts → index.ts} +3 -0
  86. package/src/jobs/Job.ts +147 -0
  87. package/src/jobs/index.ts +10 -0
  88. package/src/jobs/listeners.ts +3 -0
  89. package/src/jobs/status.ts +4 -0
  90. package/src/lang/DefaultLangProvider.ts +46 -0
  91. package/src/lang/Lang.state.ts +11 -0
  92. package/src/lang/Lang.ts +44 -29
  93. package/src/lang/index.ts +7 -5
  94. package/src/plugins/Plugin.ts +1 -1
  95. package/src/plugins/index.ts +10 -7
  96. package/src/services/App.state.ts +29 -7
  97. package/src/services/App.ts +41 -6
  98. package/src/services/Cache.ts +43 -0
  99. package/src/services/Events.test.ts +39 -0
  100. package/src/services/Events.ts +112 -32
  101. package/src/services/Service.ts +154 -49
  102. package/src/services/Storage.ts +20 -0
  103. package/src/services/index.ts +14 -5
  104. package/src/services/store.ts +8 -5
  105. package/src/services/utils.ts +18 -0
  106. package/src/testing/index.ts +26 -0
  107. package/src/testing/setup.ts +11 -0
  108. package/src/ui/UI.state.ts +9 -2
  109. package/src/ui/UI.ts +251 -41
  110. package/src/ui/index.ts +13 -7
  111. package/src/ui/utils.ts +16 -0
  112. package/src/utils/composition/events.ts +3 -2
  113. package/src/utils/composition/persistent.test.ts +33 -0
  114. package/src/utils/composition/persistent.ts +11 -0
  115. package/src/utils/composition/state.test.ts +47 -0
  116. package/src/utils/composition/state.ts +24 -0
  117. package/src/utils/index.ts +3 -0
  118. package/src/utils/markdown.test.ts +50 -0
  119. package/src/utils/markdown.ts +19 -6
  120. package/src/utils/tailwindcss.test.ts +26 -0
  121. package/src/utils/tailwindcss.ts +7 -0
  122. package/src/utils/vue.ts +30 -9
  123. package/.eslintrc.js +0 -3
  124. package/dist/aerogel-core.cjs.js +0 -2
  125. package/dist/aerogel-core.cjs.js.map +0 -1
  126. package/dist/aerogel-core.esm.js +0 -2
  127. package/dist/aerogel-core.esm.js.map +0 -1
  128. package/dist/virtual.d.ts +0 -11
  129. package/noeldemartin.config.js +0 -5
  130. package/src/components/basic/AGErrorMessage.vue +0 -16
  131. package/src/components/basic/AGMarkdown.vue +0 -36
  132. package/src/components/basic/index.ts +0 -5
  133. package/src/directives/initial-focus.ts +0 -11
  134. package/src/types/virtual.d.ts +0 -11
  135. package/tsconfig.json +0 -11
  136. package/vite.config.ts +0 -14
  137. /package/src/components/{basic → lib}/AGLink.vue +0 -0
package/src/ui/UI.ts CHANGED
@@ -1,12 +1,22 @@
1
- import { facade, fail, uuid } from '@noeldemartin/utils';
1
+ import { after, facade, fail, isDevelopment, required, 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
- import Events from '@/services/Events';
7
- import type { SnackbarAction, SnackbarColor } from '@/components/headless/snackbars';
6
+ import App from '@aerogel/core/services/App';
7
+ import Events from '@aerogel/core/services/Events';
8
+ import type { AcceptRefs } from '@aerogel/core/utils';
9
+ import type { Color } from '@aerogel/core/components/constants';
10
+ import type { SnackbarAction, SnackbarColor } from '@aerogel/core/components/headless/snackbars';
11
+ import type {
12
+ AGAlertModalProps,
13
+ AGConfirmModalProps,
14
+ AGLoadingModalProps,
15
+ AGPromptModalProps,
16
+ } from '@aerogel/core/components';
8
17
 
9
18
  import Service from './UI.state';
19
+ import { MOBILE_BREAKPOINT, getCurrentLayout } from './utils';
10
20
  import type { Modal, ModalComponent, Snackbar } from './UI.state';
11
21
 
12
22
  interface ModalCallbacks<T = unknown> {
@@ -15,20 +25,53 @@ interface ModalCallbacks<T = unknown> {
15
25
  }
16
26
 
17
27
  type ModalProperties<TComponent> = TComponent extends ModalComponent<infer TProperties, unknown> ? TProperties : never;
18
- type ModalResult<TComponent> = TComponent extends ModalComponent<Record<string, unknown>, infer TResult>
19
- ? TResult
20
- : never;
28
+ type ModalResult<TComponent> =
29
+ TComponent extends ModalComponent<Record<string, unknown>, infer TResult> ? TResult : never;
21
30
 
22
31
  export const UIComponents = {
23
32
  AlertModal: 'alert-modal',
24
33
  ConfirmModal: 'confirm-modal',
25
34
  ErrorReportModal: 'error-report-modal',
26
35
  LoadingModal: 'loading-modal',
36
+ PromptModal: 'prompt-modal',
27
37
  Snackbar: 'snackbar',
38
+ StartupCrash: 'startup-crash',
28
39
  } as const;
29
40
 
30
41
  export type UIComponent = ObjectValues<typeof UIComponents>;
31
42
 
43
+ export type ConfirmCheckboxes = Record<string, { label: string; default?: boolean; required?: boolean }>;
44
+
45
+ export type ConfirmOptions = AcceptRefs<{
46
+ acceptText?: string;
47
+ acceptColor?: Color;
48
+ cancelText?: string;
49
+ cancelColor?: Color;
50
+ actions?: Record<string, () => unknown>;
51
+ required?: boolean;
52
+ }>;
53
+
54
+ export type LoadingOptions = AcceptRefs<{
55
+ title?: string;
56
+ message?: string;
57
+ progress?: number;
58
+ }>;
59
+
60
+ export interface ConfirmOptionsWithCheckboxes<T extends ConfirmCheckboxes = ConfirmCheckboxes> extends ConfirmOptions {
61
+ checkboxes?: T;
62
+ }
63
+
64
+ export type PromptOptions = AcceptRefs<{
65
+ label?: string;
66
+ defaultValue?: string;
67
+ placeholder?: string;
68
+ acceptText?: string;
69
+ acceptColor?: Color;
70
+ cancelText?: string;
71
+ cancelColor?: Color;
72
+ trim?: boolean;
73
+ }>;
74
+
32
75
  export interface ShowSnackbarOptions {
33
76
  component?: Component;
34
77
  color?: SnackbarColor;
@@ -47,43 +90,158 @@ export class UIService extends Service {
47
90
  public alert(message: string): void;
48
91
  public alert(title: string, message: string): void;
49
92
  public alert(messageOrTitle: string, message?: string): void {
50
- const options = typeof message === 'string' ? { title: messageOrTitle, message } : { message: messageOrTitle };
93
+ const getProperties = (): AGAlertModalProps => {
94
+ if (typeof message !== 'string') {
95
+ return { message: messageOrTitle };
96
+ }
51
97
 
52
- this.openModal(this.requireComponent(UIComponents.AlertModal), options);
98
+ return {
99
+ title: messageOrTitle,
100
+ message,
101
+ };
102
+ };
103
+
104
+ this.openModal(this.requireComponent(UIComponents.AlertModal), getProperties());
53
105
  }
54
106
 
55
- public async confirm(message: string): Promise<boolean>;
56
- public async confirm(title: string, message: string): Promise<boolean>;
57
- public async confirm(messageOrTitle: string, message?: string): Promise<boolean> {
58
- const options = typeof message === 'string' ? { title: messageOrTitle, message } : { message: messageOrTitle };
59
- const modal = await this.openModal<ModalComponent<{ message: string }, boolean>>(
60
- this.requireComponent(UIComponents.ConfirmModal),
61
- options,
62
- );
107
+ /* eslint-disable max-len */
108
+ public async confirm(message: string, options?: ConfirmOptions): Promise<boolean>;
109
+ public async confirm(title: string, message: string, options?: ConfirmOptions): Promise<boolean>;
110
+ public async confirm<T extends ConfirmCheckboxes>(message: string, options?: ConfirmOptionsWithCheckboxes<T>): Promise<[boolean, Record<keyof T, boolean>]>; // prettier-ignore
111
+ public async confirm<T extends ConfirmCheckboxes>(title: string, message: string, options?: ConfirmOptionsWithCheckboxes<T>): Promise<[boolean, Record<keyof T, boolean>]>; // prettier-ignore
112
+ /* eslint-enable max-len */
113
+
114
+ public async confirm(
115
+ messageOrTitle: string,
116
+ messageOrOptions?: string | ConfirmOptions | ConfirmOptionsWithCheckboxes,
117
+ options?: ConfirmOptions | ConfirmOptionsWithCheckboxes,
118
+ ): Promise<boolean | [boolean, Record<string, boolean>]> {
119
+ const getProperties = (): AGConfirmModalProps => {
120
+ if (typeof messageOrOptions !== 'string') {
121
+ return {
122
+ ...(messageOrOptions ?? {}),
123
+ message: messageOrTitle,
124
+ required: !!messageOrOptions?.required,
125
+ };
126
+ }
127
+
128
+ return {
129
+ ...(options ?? {}),
130
+ title: messageOrTitle,
131
+ message: messageOrOptions,
132
+ required: !!options?.required,
133
+ };
134
+ };
135
+ const properties = getProperties();
136
+ const modal = await this.openModal<
137
+ ModalComponent<AGConfirmModalProps, boolean | [boolean, Record<string, boolean>]>
138
+ >(this.requireComponent(UIComponents.ConfirmModal), properties);
63
139
  const result = await modal.beforeClose;
64
140
 
65
- return result ?? false;
141
+ const confirmed = typeof result === 'object' ? result[0] : (result ?? false);
142
+ const checkboxes =
143
+ typeof result === 'object'
144
+ ? result[1]
145
+ : Object.entries(properties.checkboxes ?? {}).reduce(
146
+ (values, [checkbox, { default: defaultValue }]) => ({
147
+ [checkbox]: defaultValue ?? false,
148
+ ...values,
149
+ }),
150
+ {} as Record<string, boolean>,
151
+ );
152
+
153
+ for (const [name, checkbox] of Object.entries(properties.checkboxes ?? {})) {
154
+ if (!checkbox.required || checkboxes[name]) {
155
+ continue;
156
+ }
157
+
158
+ if (confirmed && isDevelopment()) {
159
+ // eslint-disable-next-line no-console
160
+ console.warn(`Confirmed confirm modal was suppressed because required '${name}' checkbox was missing`);
161
+ }
162
+
163
+ return [false, checkboxes];
164
+ }
165
+
166
+ return 'checkboxes' in properties ? [confirmed, checkboxes] : confirmed;
167
+ }
168
+
169
+ public async prompt(message: string, options?: PromptOptions): Promise<string | null>;
170
+ public async prompt(title: string, message: string, options?: PromptOptions): Promise<string | null>;
171
+ public async prompt(
172
+ messageOrTitle: string,
173
+ messageOrOptions?: string | PromptOptions,
174
+ options?: PromptOptions,
175
+ ): Promise<string | null> {
176
+ const trim = options?.trim ?? true;
177
+ const getProperties = (): AGPromptModalProps => {
178
+ if (typeof messageOrOptions !== 'string') {
179
+ return {
180
+ message: messageOrTitle,
181
+ ...(messageOrOptions ?? {}),
182
+ } as AGPromptModalProps;
183
+ }
184
+
185
+ return {
186
+ title: messageOrTitle,
187
+ message: messageOrOptions,
188
+ ...(options ?? {}),
189
+ } as AGPromptModalProps;
190
+ };
191
+
192
+ const modal = await this.openModal<ModalComponent<AGPromptModalProps, string | null>>(
193
+ this.requireComponent(UIComponents.PromptModal),
194
+ getProperties(),
195
+ );
196
+ const rawResult = await modal.beforeClose;
197
+ const result = trim && typeof rawResult === 'string' ? rawResult?.trim() : rawResult;
198
+
199
+ return result ?? null;
66
200
  }
67
201
 
68
- public async loading<T>(operation: Promise<T>): Promise<T>;
69
- public async loading<T>(message: string, operation: Promise<T>): Promise<T>;
70
- public async loading<T>(messageOrOperation: string | Promise<T>, operation?: Promise<T>): Promise<T> {
71
- operation = typeof messageOrOperation === 'string' ? (operation as Promise<T>) : messageOrOperation;
202
+ public async loading<T>(operation: Promise<T> | (() => T)): Promise<T>;
203
+ public async loading<T>(message: string, operation: Promise<T> | (() => T)): Promise<T>;
204
+ public async loading<T>(options: LoadingOptions, operation: Promise<T> | (() => T)): Promise<T>;
205
+ public async loading<T>(
206
+ operationOrMessageOrOptions: string | LoadingOptions | Promise<T> | (() => T),
207
+ operation?: Promise<T> | (() => T),
208
+ ): Promise<T> {
209
+ const processOperation = (o: Promise<T> | (() => T)) => (typeof o === 'function' ? Promise.resolve(o()) : o);
210
+ const processArgs = (): { operationPromise: Promise<T>; props?: AGLoadingModalProps } => {
211
+ if (typeof operationOrMessageOrOptions === 'string') {
212
+ return {
213
+ props: { message: operationOrMessageOrOptions },
214
+ operationPromise: processOperation(operation as Promise<T> | (() => T)),
215
+ };
216
+ }
217
+
218
+ if (typeof operationOrMessageOrOptions === 'function' || operationOrMessageOrOptions instanceof Promise) {
219
+ return { operationPromise: processOperation(operationOrMessageOrOptions) };
220
+ }
221
+
222
+ return {
223
+ props: operationOrMessageOrOptions,
224
+ operationPromise: processOperation(operation as Promise<T> | (() => T)),
225
+ };
226
+ };
72
227
 
73
- const message = typeof messageOrOperation === 'string' ? messageOrOperation : undefined;
74
- const modal = await this.openModal(this.requireComponent(UIComponents.LoadingModal), { message });
75
- const result = await operation;
228
+ const { operationPromise, props } = processArgs();
229
+ const modal = await this.openModal(this.requireComponent(UIComponents.LoadingModal), props);
76
230
 
77
- await this.closeModal(modal.id);
231
+ try {
232
+ const [result] = await Promise.all([operationPromise, after({ seconds: 1 })]);
78
233
 
79
- return result;
234
+ return result;
235
+ } finally {
236
+ await this.closeModal(modal.id);
237
+ }
80
238
  }
81
239
 
82
240
  public showSnackbar(message: string, options: ShowSnackbarOptions = {}): void {
83
241
  const snackbar: Snackbar = {
84
242
  id: uuid(),
85
243
  properties: { message, ...options },
86
- component: options.component ?? markRaw(this.requireComponent(UIComponents.Snackbar)),
244
+ component: markRaw(options.component ?? this.requireComponent(UIComponents.Snackbar)),
87
245
  };
88
246
 
89
247
  this.setState('snackbars', this.snackbars.concat(snackbar));
@@ -133,11 +291,40 @@ export class UIService extends Service {
133
291
  }
134
292
 
135
293
  public async closeModal(id: string, result?: unknown): Promise<void> {
294
+ if (!App.isMounted()) {
295
+ await this.removeModal(id, result);
296
+
297
+ return;
298
+ }
299
+
136
300
  await Events.emit('close-modal', { id, result });
137
301
  }
138
302
 
139
- protected async boot(): Promise<void> {
303
+ public async closeAllModals(): Promise<void> {
304
+ while (this.modals.length > 0) {
305
+ await this.closeModal(required(this.modals[this.modals.length - 1]).id);
306
+ }
307
+ }
308
+
309
+ protected override async boot(): Promise<void> {
140
310
  this.watchModalEvents();
311
+ this.watchMountedEvent();
312
+ this.watchViewportBreakpoints();
313
+ }
314
+
315
+ private async removeModal(id: string, result?: unknown): Promise<void> {
316
+ this.setState(
317
+ 'modals',
318
+ this.modals.filter((m) => m.id !== id),
319
+ );
320
+
321
+ this.modalCallbacks[id]?.closed?.(result);
322
+
323
+ delete this.modalCallbacks[id];
324
+
325
+ const activeModal = this.modals.at(-1);
326
+
327
+ await (activeModal && Events.emit('show-modal', { id: activeModal.id }));
141
328
  }
142
329
 
143
330
  private watchModalEvents(): void {
@@ -149,32 +336,55 @@ export class UIService extends Service {
149
336
  }
150
337
  });
151
338
 
152
- Events.on('modal-closed', async ({ modal, result }) => {
153
- this.setState(
154
- 'modals',
155
- this.modals.filter((m) => m.id !== modal.id),
156
- );
339
+ Events.on('modal-closed', async ({ modal: { id }, result }) => {
340
+ await this.removeModal(id, result);
341
+ });
342
+ }
343
+
344
+ private watchMountedEvent(): void {
345
+ Events.once('application-mounted', async () => {
346
+ if (!globalThis.document || !globalThis.getComputedStyle) {
347
+ return;
348
+ }
157
349
 
158
- this.modalCallbacks[modal.id]?.closed?.(result);
350
+ const splash = globalThis.document.getElementById('splash');
159
351
 
160
- delete this.modalCallbacks[modal.id];
352
+ if (!splash) {
353
+ return;
354
+ }
161
355
 
162
- const activeModal = this.modals.at(-1);
356
+ if (globalThis.getComputedStyle(splash).opacity !== '0') {
357
+ splash.style.opacity = '0';
163
358
 
164
- await (activeModal && Events.emit('show-modal', { id: activeModal.id }));
359
+ await after({ ms: 600 });
360
+ }
361
+
362
+ splash.remove();
165
363
  });
166
364
  }
167
365
 
366
+ private watchViewportBreakpoints(): void {
367
+ if (!globalThis.matchMedia) {
368
+ return;
369
+ }
370
+
371
+ const media = globalThis.matchMedia(`(min-width: ${MOBILE_BREAKPOINT}px)`);
372
+
373
+ media.addEventListener('change', () => this.setState({ layout: getCurrentLayout() }));
374
+ }
375
+
168
376
  }
169
377
 
170
- export default facade(new UIService());
378
+ export default facade(UIService);
171
379
 
172
- declare module '@/services/Events' {
380
+ declare module '@aerogel/core/services/Events' {
173
381
  export interface EventsPayload {
174
- 'modal-will-close': { modal: Modal; result?: unknown };
175
- 'modal-closed': { modal: Modal; result?: unknown };
176
382
  'close-modal': { id: string; result?: unknown };
177
383
  'hide-modal': { id: string };
384
+ 'hide-overlays-backdrop': void;
385
+ 'modal-closed': { modal: Modal; result?: unknown };
386
+ 'modal-will-close': { modal: Modal; result?: unknown };
178
387
  'show-modal': { id: string };
388
+ 'show-overlays-backdrop': void;
179
389
  }
180
390
  }
package/src/ui/index.ts CHANGED
@@ -1,20 +1,24 @@
1
1
  import type { Component } from 'vue';
2
2
 
3
- import { bootServices } from '@/services';
4
- import { definePlugin } from '@/plugins';
3
+ import { bootServices } from '@aerogel/core/services';
4
+ import { definePlugin } from '@aerogel/core/plugins';
5
5
 
6
6
  import UI, { UIComponents } from './UI';
7
7
  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 * from './utils';
20
+ export { default as UI } from './UI';
21
+
18
22
  export type UIServices = typeof services;
19
23
 
20
24
  export default definePlugin({
@@ -24,7 +28,9 @@ export default definePlugin({
24
28
  [UIComponents.ConfirmModal]: AGConfirmModal,
25
29
  [UIComponents.ErrorReportModal]: AGErrorReportModal,
26
30
  [UIComponents.LoadingModal]: AGLoadingModal,
31
+ [UIComponents.PromptModal]: AGPromptModal,
27
32
  [UIComponents.Snackbar]: AGSnackbar,
33
+ [UIComponents.StartupCrash]: AGStartupCrash,
28
34
  };
29
35
 
30
36
  Object.entries({
@@ -36,12 +42,12 @@ export default definePlugin({
36
42
  },
37
43
  });
38
44
 
39
- declare module '@/bootstrap/options' {
40
- interface AerogelOptions {
45
+ declare module '@aerogel/core/bootstrap/options' {
46
+ export interface AerogelOptions {
41
47
  components?: Partial<Record<UIComponent, Component>>;
42
48
  }
43
49
  }
44
50
 
45
- declare module '@/services' {
51
+ declare module '@aerogel/core/services' {
46
52
  export interface Services extends UIServices {}
47
53
  }
@@ -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
+ }
@@ -1,19 +1,20 @@
1
1
  import { onUnmounted } from 'vue';
2
2
 
3
- import Events from '@/services/Events';
3
+ import Events from '@aerogel/core/services/Events';
4
4
  import type {
5
5
  EventListener,
6
6
  EventWithPayload,
7
7
  EventWithoutPayload,
8
8
  EventsPayload,
9
9
  UnknownEvent,
10
- } from '@/services/Events';
10
+ } from '@aerogel/core/services/Events';
11
11
 
12
12
  export function useEvent<Event extends EventWithoutPayload>(event: Event, listener: () => unknown): void;
13
13
  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 {
@@ -0,0 +1,33 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { nextTick } from 'vue';
3
+ import { Storage } from '@noeldemartin/utils';
4
+
5
+ import { persistent } from './persistent';
6
+
7
+ describe('Vue persistent helper', () => {
8
+
9
+ it('serializes to localStorage', async () => {
10
+ // Arrange
11
+ const store = persistent<{ foo?: string }>('foobar', {});
12
+
13
+ // Act
14
+ store.foo = 'bar';
15
+
16
+ await nextTick();
17
+
18
+ // Assert
19
+ expect(Storage.get('foobar')).toEqual({ foo: 'bar' });
20
+ });
21
+
22
+ it('reads from localStorage', async () => {
23
+ // Arrange
24
+ Storage.set('foobar', { foo: 'bar' });
25
+
26
+ // Act
27
+ const store = persistent<{ foo?: string }>('foobar', {});
28
+
29
+ // Assert
30
+ expect(store.foo).toEqual('bar');
31
+ });
32
+
33
+ });
@@ -0,0 +1,11 @@
1
+ import { reactive, toRaw, watch } from 'vue';
2
+ import { Storage } from '@noeldemartin/utils';
3
+ import type { UnwrapNestedRefs } from 'vue';
4
+
5
+ export function persistent<T extends object>(name: string, defaults: T): UnwrapNestedRefs<T> {
6
+ const store = reactive<T>(Storage.get<T>(name) ?? defaults);
7
+
8
+ watch(store, () => Storage.set(name, toRaw(store)));
9
+
10
+ return store;
11
+ }
@@ -0,0 +1,47 @@
1
+ import { after } from '@noeldemartin/utils';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { ref } from 'vue';
4
+
5
+ import { computedDebounce } from './state';
6
+
7
+ describe('Vue state helpers', () => {
8
+
9
+ it('computes debounced state', async () => {
10
+ // Initial
11
+ const state = ref(0);
12
+ const value = computedDebounce({ delay: 90 }, () => state.value);
13
+
14
+ expect(value.value).toBe(null);
15
+
16
+ await after({ ms: 100 });
17
+
18
+ expect(value.value).toBe(0);
19
+
20
+ // Update
21
+ state.value = 42;
22
+
23
+ expect(value.value).toBe(0);
24
+
25
+ await after({ ms: 100 });
26
+
27
+ expect(value.value).toBe(42);
28
+
29
+ // Debounced Update
30
+ state.value = 23;
31
+
32
+ expect(value.value).toBe(42);
33
+
34
+ await after({ ms: 50 });
35
+
36
+ state.value = 32;
37
+
38
+ await after({ ms: 50 });
39
+
40
+ expect(value.value).toBe(42);
41
+
42
+ await after({ ms: 100 });
43
+
44
+ expect(value.value).toBe(32);
45
+ });
46
+
47
+ });
@@ -0,0 +1,24 @@
1
+ import { debounce } from '@noeldemartin/utils';
2
+ import { ref, watchEffect } from 'vue';
3
+ import type { ComputedGetter, ComputedRef } from '@vue/runtime-core';
4
+
5
+ export interface ComputedDebounceOptions<T> {
6
+ initial?: T;
7
+ delay?: number;
8
+ }
9
+
10
+ export function computedDebounce<T>(options: ComputedDebounceOptions<T>, getter: ComputedGetter<T>): ComputedRef<T>;
11
+ export function computedDebounce<T>(getter: ComputedGetter<T>): ComputedRef<T | null>;
12
+ export function computedDebounce<T>(
13
+ optionsOrGetter: ComputedGetter<T> | ComputedDebounceOptions<T>,
14
+ inputGetter?: ComputedGetter<T>,
15
+ ): ComputedRef<T> {
16
+ const inputOptions = inputGetter ? (optionsOrGetter as ComputedDebounceOptions<T>) : {};
17
+ const getter = inputGetter ?? (optionsOrGetter as ComputedGetter<T>);
18
+ const state = ref(inputOptions.initial ?? null);
19
+ const update = debounce((value) => (state.value = value), inputOptions.delay ?? 300);
20
+
21
+ watchEffect(() => update(getter()));
22
+
23
+ return state as unknown as ComputedRef<T>;
24
+ }
@@ -1,4 +1,7 @@
1
1
  export * from './composition/events';
2
2
  export * from './composition/forms';
3
3
  export * from './composition/hooks';
4
+ export * from './composition/persistent';
5
+ export * from './markdown';
6
+ export * from './tailwindcss';
4
7
  export * from './vue';
@@ -0,0 +1,50 @@
1
+ /* eslint-disable max-len */
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { renderMarkdown } from './markdown';
5
+
6
+ describe('Markdown utils', () => {
7
+
8
+ it('renders basic markdown', () => {
9
+ // Arrange
10
+ const expectedHTML = `
11
+ <h1>Title</h1>
12
+ <p>body with <a target="_blank" href="https://example.com">link</a></p>
13
+ <ul>
14
+ <li>One</li>
15
+ <li>Two</li>
16
+ <li>Three</li>
17
+ </ul>
18
+ `;
19
+
20
+ // Act
21
+ const html = renderMarkdown(
22
+ ['# Title', 'body with [link](https://example.com)', '- One', '- Two', '- Three'].join('\n'),
23
+ );
24
+
25
+ // Assert
26
+ expect(normalizeHTML(html)).toMatch(new RegExp(normalizeHTML(expectedHTML)));
27
+ });
28
+
29
+ it('renders button links', () => {
30
+ // Arrange
31
+ const expectedHTML = `
32
+ <p><button type="button" data-markdown-action="do-something">link</button></p>
33
+ `;
34
+
35
+ // Act
36
+ const html = renderMarkdown('[link](#action:do-something)');
37
+
38
+ // Assert
39
+ expect(normalizeHTML(html)).toMatch(new RegExp(normalizeHTML(expectedHTML)));
40
+ });
41
+
42
+ });
43
+
44
+ function normalizeHTML(html: string): string {
45
+ return html
46
+ .split('\n')
47
+ .map((line) => line.trim())
48
+ .join('\n')
49
+ .trim();
50
+ }