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

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 (72) 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 +545 -88
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/dist/virtual.d.ts +11 -0
  7. package/noeldemartin.config.js +4 -1
  8. package/package.json +4 -3
  9. package/src/bootstrap/index.ts +6 -2
  10. package/src/components/AGAppModals.vue +15 -0
  11. package/src/components/AGAppOverlays.vue +5 -7
  12. package/src/components/AGAppSnackbars.vue +13 -0
  13. package/src/components/basic/AGErrorMessage.vue +16 -0
  14. package/src/components/basic/AGLink.vue +9 -0
  15. package/src/components/basic/AGMarkdown.vue +10 -9
  16. package/src/components/basic/index.ts +3 -1
  17. package/src/components/constants.ts +8 -0
  18. package/src/components/forms/AGButton.vue +33 -10
  19. package/src/components/forms/AGCheckbox.vue +35 -0
  20. package/src/components/forms/AGInput.vue +8 -4
  21. package/src/components/forms/index.ts +2 -1
  22. package/src/components/headless/forms/AGHeadlessButton.vue +7 -7
  23. package/src/components/headless/forms/AGHeadlessInput.ts +2 -2
  24. package/src/components/headless/forms/AGHeadlessInput.vue +3 -3
  25. package/src/components/headless/forms/AGHeadlessInputError.vue +1 -1
  26. package/src/components/headless/forms/AGHeadlessInputInput.vue +15 -3
  27. package/src/components/headless/index.ts +1 -0
  28. package/src/components/headless/modals/AGHeadlessModalPanel.vue +5 -1
  29. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  30. package/src/components/headless/snackbars/index.ts +25 -0
  31. package/src/components/index.ts +2 -0
  32. package/src/components/modals/AGAlertModal.vue +0 -1
  33. package/src/components/modals/AGConfirmModal.vue +1 -1
  34. package/src/components/modals/AGErrorReportModal.ts +20 -0
  35. package/src/components/modals/AGErrorReportModal.vue +62 -0
  36. package/src/components/modals/AGErrorReportModalButtons.vue +109 -0
  37. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  38. package/src/components/modals/AGLoadingModal.vue +19 -0
  39. package/src/components/modals/AGModal.vue +23 -4
  40. package/src/components/modals/AGModalTitle.vue +9 -0
  41. package/src/components/modals/index.ts +18 -2
  42. package/src/components/snackbars/AGSnackbar.vue +42 -0
  43. package/src/components/snackbars/index.ts +3 -0
  44. package/src/directives/index.ts +16 -3
  45. package/src/errors/Errors.state.ts +31 -0
  46. package/src/errors/Errors.ts +183 -0
  47. package/src/errors/index.ts +59 -0
  48. package/src/forms/Form.test.ts +21 -0
  49. package/src/forms/Form.ts +22 -12
  50. package/src/forms/utils.ts +17 -0
  51. package/src/lang/Lang.ts +12 -4
  52. package/src/lang/index.ts +3 -5
  53. package/src/lang/utils.ts +4 -0
  54. package/src/main.ts +1 -2
  55. package/src/plugins/Plugin.ts +1 -0
  56. package/src/plugins/index.ts +19 -0
  57. package/src/services/App.state.ts +10 -2
  58. package/src/services/App.ts +14 -1
  59. package/src/services/Service.ts +132 -45
  60. package/src/services/index.ts +21 -4
  61. package/src/services/store.ts +27 -0
  62. package/src/types/virtual.d.ts +11 -0
  63. package/src/ui/UI.state.ts +11 -1
  64. package/src/ui/UI.ts +52 -8
  65. package/src/ui/index.ts +7 -1
  66. package/src/utils/composition/forms.ts +11 -0
  67. package/src/utils/index.ts +1 -0
  68. package/src/utils/markdown.ts +11 -2
  69. package/src/utils/vue.ts +2 -0
  70. package/tsconfig.json +1 -0
  71. package/vite.config.ts +2 -1
  72. package/src/globals.ts +0 -6
@@ -1,3 +1,7 @@
1
+ import type { GetClosureArgs } from '@noeldemartin/utils';
2
+
3
+ import App from '@/services/App';
4
+
1
5
  import type { Plugin } from './Plugin';
2
6
 
3
7
  export * from './Plugin';
@@ -5,3 +9,18 @@ export * from './Plugin';
5
9
  export function definePlugin<T extends Plugin>(plugin: T): T {
6
10
  return plugin;
7
11
  }
12
+
13
+ export async function installPlugins(plugins: Plugin[], ...args: GetClosureArgs<Plugin['install']>): Promise<void> {
14
+ App.setState(
15
+ 'plugins',
16
+ plugins.reduce((pluginsMap, plugin) => {
17
+ if (plugin.name) {
18
+ pluginsMap[plugin.name] = plugin;
19
+ }
20
+
21
+ return pluginsMap;
22
+ }, {} as Record<string, Plugin>),
23
+ );
24
+
25
+ await Promise.all(plugins.map((plugin) => plugin.install(...args)) ?? []);
26
+ }
@@ -1,10 +1,18 @@
1
+ import Build from 'virtual:aerogel';
2
+
1
3
  import { defineServiceState } from '@/services/Service';
4
+ import type { Plugin } from '@/plugins/Plugin';
2
5
 
3
6
  export default defineServiceState({
7
+ name: 'app',
4
8
  initialState: {
5
- environment: __AG_ENV,
9
+ plugins: {} as Record<string, Plugin>,
10
+ environment: Build.environment,
11
+ sourceUrl: Build.sourceUrl,
12
+ isMounted: false,
6
13
  },
7
14
  computed: {
8
- isDevelopment: (state) => state.environment === 'development',
15
+ development: (state) => state.environment === 'development',
16
+ testing: (state) => state.environment === 'testing',
9
17
  },
10
18
  });
@@ -1,7 +1,20 @@
1
1
  import { facade } from '@noeldemartin/utils';
2
2
 
3
+ import Events from '@/services/Events';
4
+ import type { Plugin } from '@/plugins';
5
+
3
6
  import Service from './App.state';
4
7
 
5
- export class AppService extends Service {}
8
+ export class AppService extends Service {
9
+
10
+ public plugin<T extends Plugin = Plugin>(name: string): T | null {
11
+ return (this.plugins[name] as T) ?? null;
12
+ }
13
+
14
+ protected async boot(): Promise<void> {
15
+ Events.once('application-mounted', () => this.setState({ isMounted: true }));
16
+ }
17
+
18
+ }
6
19
 
7
20
  export default facade(new AppService());
@@ -1,27 +1,42 @@
1
- import { computed, reactive } from 'vue';
2
- import { MagicObject, PromisedValue } from '@noeldemartin/utils';
3
- import type { ComputedRef } from 'vue';
1
+ import { MagicObject, PromisedValue, Storage, isEmpty, objectDeepClone, objectOnly } from '@noeldemartin/utils';
4
2
  import type { Constructor } from '@noeldemartin/utils';
3
+ import type { Store } from 'pinia';
5
4
 
6
5
  import ServiceBootError from '@/errors/ServiceBootError';
6
+ import { defineServiceStore } from '@/services/store';
7
7
 
8
8
  export type ServiceState = Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
9
- export type DefaultServiceState = {};
9
+ export type DefaultServiceState = any; // eslint-disable-line @typescript-eslint/no-explicit-any
10
10
  export type ServiceConstructor<T extends Service = Service> = Constructor<T> & typeof Service;
11
11
 
12
12
  export type ComputedStateDefinition<TState extends ServiceState, TComputedState extends ServiceState> = {
13
13
  [K in keyof TComputedState]: (state: TState) => TComputedState[K];
14
- };
14
+ } & ThisType<{
15
+ readonly [K in keyof TComputedState]: TComputedState[K];
16
+ }>;
15
17
 
16
18
  export function defineServiceState<
17
19
  State extends ServiceState = ServiceState,
18
20
  ComputedState extends ServiceState = {}
19
21
  >(options: {
22
+ name: string;
20
23
  initialState: State;
24
+ persist?: (keyof State)[];
21
25
  computed?: ComputedStateDefinition<State, ComputedState>;
22
- }): Constructor<State> & Constructor<ComputedState> & ServiceConstructor {
26
+ serialize?: (state: Partial<State>) => Partial<State>;
27
+ }): Constructor<State> & Constructor<ComputedState> & Constructor<Service<State, ComputedState, Partial<State>>> {
23
28
  return class extends Service<State, ComputedState> {
24
29
 
30
+ public static persist = (options.persist as string[]) ?? [];
31
+
32
+ protected usesStore(): boolean {
33
+ return true;
34
+ }
35
+
36
+ protected getName(): string | null {
37
+ return options.name ?? null;
38
+ }
39
+
25
40
  protected getInitialState(): State {
26
41
  return options.initialState;
27
42
  }
@@ -29,47 +44,57 @@ export function defineServiceState<
29
44
  protected getComputedStateDefinition(): ComputedStateDefinition<State, ComputedState> {
30
45
  return options.computed ?? ({} as ComputedStateDefinition<State, ComputedState>);
31
46
  }
47
+
48
+ protected serializePersistedState(state: Partial<State>): Partial<State> {
49
+ return options.serialize?.(state) ?? state;
50
+ }
32
51
 
33
- } as unknown as Constructor<State> & Constructor<ComputedState> & ServiceConstructor;
52
+ } as unknown as Constructor<State> &
53
+ Constructor<ComputedState> &
54
+ Constructor<Service<State, ComputedState, Partial<State>>>;
34
55
  }
35
56
 
36
57
  export default class Service<
37
58
  State extends ServiceState = DefaultServiceState,
38
- ComputedState extends ServiceState = {}
59
+ ComputedState extends ServiceState = {},
60
+ ServiceStorage extends Partial<State> = Partial<State>
39
61
  > extends MagicObject {
40
62
 
41
- protected _namespace: string;
63
+ public static persist: string[] = [];
64
+
65
+ protected _name: string;
42
66
  private _booted: PromisedValue<void>;
43
- private _state: State;
44
- private _computedState: Record<keyof ComputedState, ComputedRef>;
67
+ private _computedStateKeys: Set<keyof State>;
68
+ private _store?: Store | false;
45
69
 
46
70
  constructor() {
47
71
  super();
48
72
 
49
- this._namespace = new.target.name;
50
- this._booted = new PromisedValue();
51
- this._state = reactive(this.getInitialState());
52
- this._computedState = Object.entries(this.getComputedStateDefinition()).reduce(
53
- (computedState, [name, method]) => {
54
- computedState[name as keyof ComputedState] = computed(() => method(this._state));
73
+ const getters = this.getComputedStateDefinition();
55
74
 
56
- return computedState;
57
- },
58
- {} as Record<keyof ComputedState, ComputedRef>,
59
- );
75
+ this._name = this.getName() ?? new.target.name;
76
+ this._booted = new PromisedValue();
77
+ this._computedStateKeys = new Set(Object.keys(getters));
78
+ this._store =
79
+ this.usesStore() &&
80
+ defineServiceStore(this._name, {
81
+ state: () => this.getInitialState(),
82
+
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ getters: getters as any,
85
+ });
60
86
  }
61
87
 
62
88
  public get booted(): PromisedValue<void> {
63
89
  return this._booted;
64
90
  }
65
91
 
66
- public launch(namespace?: string): Promise<void> {
67
- const handleError = (error: unknown) => this._booted.reject(new ServiceBootError(this._namespace, error));
68
-
69
- this._namespace = namespace ?? this._namespace;
92
+ public launch(): Promise<void> {
93
+ const handleError = (error: unknown) => this._booted.reject(new ServiceBootError(this._name, error));
70
94
 
71
95
  try {
72
- this.boot()
96
+ this.frameworkBoot()
97
+ .then(() => this.boot())
73
98
  .then(() => this._booted.resolve())
74
99
  .catch(handleError);
75
100
  } catch (error) {
@@ -79,15 +104,48 @@ export default class Service<
79
104
  return this._booted;
80
105
  }
81
106
 
107
+ public hasState<P extends keyof State>(property: P): boolean {
108
+ if (!this._store) {
109
+ return false;
110
+ }
111
+
112
+ return property in this._store.$state || this._computedStateKeys.has(property);
113
+ }
114
+
115
+ public getState(): State;
116
+ public getState<P extends keyof State>(property: P): State[P];
117
+ public getState<P extends keyof State>(property?: P): State | State[P] {
118
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
119
+ const store = this._store as any;
120
+
121
+ if (property) {
122
+ return store ? store[property] : undefined;
123
+ }
124
+
125
+ return store ? store : {};
126
+ }
127
+
128
+ public setState<P extends keyof State>(property: P, value: State[P]): void;
129
+ public setState(state: Partial<State>): void;
130
+ public setState<P extends keyof State>(stateOrProperty: P | Partial<State>, value?: State[P]): void {
131
+ if (!this._store) {
132
+ return;
133
+ }
134
+
135
+ const state = (
136
+ typeof stateOrProperty === 'string' ? { [stateOrProperty]: value } : stateOrProperty
137
+ ) as Partial<State>;
138
+
139
+ Object.assign(this._store.$state, state);
140
+
141
+ this.onStateUpdated(state);
142
+ }
143
+
82
144
  protected __get(property: string): unknown {
83
145
  if (this.hasState(property)) {
84
146
  return this.getState(property);
85
147
  }
86
148
 
87
- if (this.hasComputedState(property)) {
88
- return this.getComputedState(property);
89
- }
90
-
91
149
  return super.__get(property);
92
150
  }
93
151
 
@@ -95,26 +153,29 @@ export default class Service<
95
153
  this.setState({ [property]: value } as Partial<State>);
96
154
  }
97
155
 
98
- protected hasState<P extends keyof State>(property: P): boolean {
99
- return property in this._state;
100
- }
156
+ protected onStateUpdated(state: Partial<State>): void {
157
+ // TODO fix this.static()
158
+ const persist = (this.constructor as unknown as { persist: string[] }).persist;
159
+ const persisted = objectOnly(state, persist);
101
160
 
102
- protected hasComputedState<P extends keyof State>(property: P): boolean {
103
- return property in this._computedState;
104
- }
161
+ if (isEmpty(persisted)) {
162
+ return;
163
+ }
105
164
 
106
- protected getState(): State;
107
- protected getState<P extends keyof State>(property: P): State[P];
108
- protected getState<P extends keyof State>(property?: P): State | State[P] {
109
- return property ? this._state[property] : this._state;
165
+ const storage = Storage.require<ServiceStorage>(this._name);
166
+
167
+ Storage.set(this._name, {
168
+ ...storage,
169
+ ...this.serializePersistedState(objectDeepClone(persisted) as Partial<State>),
170
+ });
110
171
  }
111
172
 
112
- protected getComputedState<P extends keyof ComputedState>(property: P): ComputedState[P] {
113
- return this._computedState[property]?.value;
173
+ protected usesStore(): boolean {
174
+ return false;
114
175
  }
115
176
 
116
- protected setState(state: Partial<State>): void {
117
- Object.assign(this._state, state);
177
+ protected getName(): string | null {
178
+ return null;
118
179
  }
119
180
 
120
181
  protected getInitialState(): State {
@@ -125,8 +186,34 @@ export default class Service<
125
186
  return {} as ComputedStateDefinition<State, ComputedState>;
126
187
  }
127
188
 
189
+ protected serializePersistedState(state: Partial<State>): Partial<State> {
190
+ return state;
191
+ }
192
+
193
+ protected async frameworkBoot(): Promise<void> {
194
+ this.restorePersistedState();
195
+ }
196
+
128
197
  protected async boot(): Promise<void> {
129
- //
198
+ // Override.
199
+ }
200
+
201
+ protected restorePersistedState(): void {
202
+ // TODO fix this.static()
203
+ const persist = (this.constructor as unknown as { persist: string[] }).persist;
204
+
205
+ if (!this.usesStore() || isEmpty(persist)) {
206
+ return;
207
+ }
208
+
209
+ if (Storage.has(this._name)) {
210
+ const persisted = Storage.require<ServiceStorage>(this._name);
211
+ this.setState(persisted);
212
+
213
+ return;
214
+ }
215
+
216
+ Storage.set(this._name, objectOnly(this.getState(), persist));
130
217
  }
131
218
 
132
219
  }
@@ -5,6 +5,7 @@ import { definePlugin } from '@/plugins';
5
5
  import App from './App';
6
6
  import Events from './Events';
7
7
  import Service from './Service';
8
+ import { getPiniaStore } from './store';
8
9
 
9
10
  export * from './App';
10
11
  export * from './Events';
@@ -24,20 +25,36 @@ export interface Services extends DefaultServices {}
24
25
  export async function bootServices(app: VueApp, services: Record<string, Service>): Promise<void> {
25
26
  await Promise.all(
26
27
  Object.entries(services).map(async ([name, service]) => {
27
- // eslint-disable-next-line no-console
28
- await service.launch(name.slice(1)).catch((error) => console.error(error));
28
+ await service
29
+ .launch()
30
+ .catch((error) => app.config.errorHandler?.(error, null, `Failed launching ${name}.`));
29
31
  }),
30
32
  );
31
33
 
32
34
  Object.assign(app.config.globalProperties, services);
35
+
36
+ App.development && Object.assign(window, services);
33
37
  }
34
38
 
35
39
  export default definePlugin({
36
- async install(app) {
37
- await bootServices(app, defaultServices);
40
+ async install(app, options) {
41
+ const services = {
42
+ ...defaultServices,
43
+ ...options.services,
44
+ };
45
+
46
+ app.use(getPiniaStore());
47
+
48
+ await bootServices(app, services);
38
49
  },
39
50
  });
40
51
 
52
+ declare module '@/bootstrap/options' {
53
+ interface AerogelOptions {
54
+ services?: Record<string, Service>;
55
+ }
56
+ }
57
+
41
58
  declare module '@vue/runtime-core' {
42
59
  interface ComponentCustomProperties extends Services {}
43
60
  }
@@ -0,0 +1,27 @@
1
+ import { createPinia, defineStore, setActivePinia } from 'pinia';
2
+ import type { DefineStoreOptions, Pinia, StateTree, Store, _GettersTree } from 'pinia';
3
+
4
+ let _store: Pinia | null = null;
5
+
6
+ function initializePiniaStore(): Pinia {
7
+ if (!_store) {
8
+ _store = createPinia();
9
+
10
+ setActivePinia(_store);
11
+ }
12
+
13
+ return _store;
14
+ }
15
+
16
+ export function getPiniaStore(): Pinia {
17
+ return _store ?? initializePiniaStore();
18
+ }
19
+
20
+ export function defineServiceStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(
21
+ name: Id,
22
+ options: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,
23
+ ): Store<Id, S, G, A> {
24
+ initializePiniaStore();
25
+
26
+ return defineStore(name, options)();
27
+ }
@@ -0,0 +1,11 @@
1
+ declare module 'virtual:aerogel' {
2
+ interface AerogelBuild {
3
+ environment: 'production' | 'development' | 'testing';
4
+ basePath?: string;
5
+ sourceUrl?: string;
6
+ }
7
+
8
+ const build: AerogelBuild;
9
+
10
+ export default build;
11
+ }
@@ -17,6 +17,16 @@ export interface ModalComponent<
17
17
  Result = unknown
18
18
  > {}
19
19
 
20
+ export interface Snackbar {
21
+ id: string;
22
+ component: Component;
23
+ properties: Record<string, unknown>;
24
+ }
25
+
20
26
  export default defineServiceState({
21
- initialState: { modals: [] as Modal[] },
27
+ name: 'ui',
28
+ initialState: {
29
+ modals: [] as Modal[],
30
+ snackbars: [] as Snackbar[],
31
+ },
22
32
  });
package/src/ui/UI.ts CHANGED
@@ -4,9 +4,10 @@ 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 { SnackbarAction, SnackbarColor } from '@/components/headless/snackbars';
7
8
 
8
9
  import Service from './UI.state';
9
- import type { Modal, ModalComponent } from './UI.state';
10
+ import type { Modal, ModalComponent, Snackbar } from './UI.state';
10
11
 
11
12
  interface ModalCallbacks<T = unknown> {
12
13
  willClose(result: T | undefined): void;
@@ -21,15 +22,28 @@ type ModalResult<TComponent> = TComponent extends ModalComponent<Record<string,
21
22
  export const UIComponents = {
22
23
  AlertModal: 'alert-modal',
23
24
  ConfirmModal: 'confirm-modal',
25
+ ErrorReportModal: 'error-report-modal',
26
+ LoadingModal: 'loading-modal',
27
+ Snackbar: 'snackbar',
24
28
  } as const;
25
29
 
26
30
  export type UIComponent = ObjectValues<typeof UIComponents>;
27
31
 
32
+ export interface ShowSnackbarOptions {
33
+ component?: Component;
34
+ color?: SnackbarColor;
35
+ actions?: SnackbarAction[];
36
+ }
37
+
28
38
  export class UIService extends Service {
29
39
 
30
40
  private modalCallbacks: Record<string, Partial<ModalCallbacks>> = {};
31
41
  private components: Partial<Record<UIComponent, Component>> = {};
32
42
 
43
+ public requireComponent(name: UIComponent): Component {
44
+ return this.components[name] ?? fail(`UI Component '${name}' is not defined!`);
45
+ }
46
+
33
47
  public alert(message: string): void;
34
48
  public alert(title: string, message: string): void;
35
49
  public alert(messageOrTitle: string, message?: string): void {
@@ -51,6 +65,39 @@ export class UIService extends Service {
51
65
  return result ?? false;
52
66
  }
53
67
 
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;
72
+
73
+ const message = typeof messageOrOperation === 'string' ? messageOrOperation : undefined;
74
+ const modal = await this.openModal(this.requireComponent(UIComponents.LoadingModal), { message });
75
+ const result = await operation;
76
+
77
+ await this.closeModal(modal.id);
78
+
79
+ return result;
80
+ }
81
+
82
+ public showSnackbar(message: string, options: ShowSnackbarOptions = {}): void {
83
+ const snackbar: Snackbar = {
84
+ id: uuid(),
85
+ properties: { message, ...options },
86
+ component: options.component ?? markRaw(this.requireComponent(UIComponents.Snackbar)),
87
+ };
88
+
89
+ this.setState('snackbars', this.snackbars.concat(snackbar));
90
+
91
+ setTimeout(() => this.hideSnackbar(snackbar.id), 5000);
92
+ }
93
+
94
+ public hideSnackbar(id: string): void {
95
+ this.setState(
96
+ 'snackbars',
97
+ this.snackbars.filter((snackbar) => snackbar.id !== id),
98
+ );
99
+ }
100
+
54
101
  public registerComponent(name: UIComponent, component: Component): void {
55
102
  this.components[name] = component;
56
103
  }
@@ -90,15 +137,9 @@ export class UIService extends Service {
90
137
  }
91
138
 
92
139
  protected async boot(): Promise<void> {
93
- await super.boot();
94
-
95
140
  this.watchModalEvents();
96
141
  }
97
142
 
98
- private requireComponent(name: UIComponent): Component {
99
- return this.components[name] ?? fail(`UI Component '${name}' is not defined!`);
100
- }
101
-
102
143
  private watchModalEvents(): void {
103
144
  Events.on('modal-will-close', ({ modal, result }) => {
104
145
  this.modalCallbacks[modal.id]?.willClose?.(result);
@@ -109,7 +150,10 @@ export class UIService extends Service {
109
150
  });
110
151
 
111
152
  Events.on('modal-closed', async ({ modal, result }) => {
112
- this.setState({ modals: this.modals.filter((m) => m.id !== modal.id) });
153
+ this.setState(
154
+ 'modals',
155
+ this.modals.filter((m) => m.id !== modal.id),
156
+ );
113
157
 
114
158
  this.modalCallbacks[modal.id]?.closed?.(result);
115
159
 
package/src/ui/index.ts CHANGED
@@ -6,6 +6,9 @@ import { definePlugin } from '@/plugins';
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
+ import AGErrorReportModal from '../components/modals/AGErrorReportModal.vue';
10
+ import AGLoadingModal from '../components/modals/AGLoadingModal.vue';
11
+ import AGSnackbar from '../components/snackbars/AGSnackbar.vue';
9
12
  import type { UIComponent } from './UI';
10
13
 
11
14
  export { UI, UIComponents, UIComponent };
@@ -19,6 +22,9 @@ export default definePlugin({
19
22
  const defaultComponents = {
20
23
  [UIComponents.AlertModal]: AGAlertModal,
21
24
  [UIComponents.ConfirmModal]: AGConfirmModal,
25
+ [UIComponents.ErrorReportModal]: AGErrorReportModal,
26
+ [UIComponents.LoadingModal]: AGLoadingModal,
27
+ [UIComponents.Snackbar]: AGSnackbar,
22
28
  };
23
29
 
24
30
  Object.entries({
@@ -37,5 +43,5 @@ declare module '@/bootstrap/options' {
37
43
  }
38
44
 
39
45
  declare module '@/services' {
40
- interface Services extends UIServices {}
46
+ export interface Services extends UIServices {}
41
47
  }
@@ -0,0 +1,11 @@
1
+ import { objectWithout } from '@noeldemartin/utils';
2
+ import { computed, useAttrs } from 'vue';
3
+ import type { ComputedRef } from 'vue';
4
+
5
+ export function useInputAttrs(): [ComputedRef<{}>, ComputedRef<unknown>] {
6
+ const attrs = useAttrs();
7
+ const className = computed(() => attrs.class);
8
+ const inputAttrs = computed(() => objectWithout(attrs, 'class'));
9
+
10
+ return [inputAttrs, className];
11
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './composition/events';
2
+ export * from './composition/forms';
2
3
  export * from './composition/hooks';
3
4
  export * from './vue';
@@ -1,8 +1,17 @@
1
+ import { tap } from '@noeldemartin/utils';
1
2
  import DOMPurify from 'dompurify';
2
- import { marked } from 'marked';
3
+ import { Renderer, marked } from 'marked';
4
+
5
+ function makeRenderer(): Renderer {
6
+ return tap(new Renderer(), (renderer) => {
7
+ renderer.link = function(href, title, text) {
8
+ return Renderer.prototype.link.apply(this, [href, title, text]).replace('<a', '<a target="_blank"');
9
+ };
10
+ });
11
+ }
3
12
 
4
13
  export function renderMarkdown(markdown: string): string {
5
- return safeHtml(marked(markdown, { mangle: false, headerIds: false }));
14
+ return safeHtml(marked(markdown, { mangle: false, headerIds: false, renderer: makeRenderer() }));
6
15
  }
7
16
 
8
17
  export function safeHtml(html: string): string {
package/src/utils/vue.ts CHANGED
@@ -10,6 +10,8 @@ type BaseProp<T> = {
10
10
  type RequiredProp<T> = BaseProp<T> & { required: true };
11
11
  type OptionalProp<T> = BaseProp<T> & { default: T | (() => T) | null };
12
12
 
13
+ export type ComponentProps = Record<string, unknown>;
14
+
13
15
  export function arrayProp<T>(defaultValue?: () => T[]): OptionalProp<T[]> {
14
16
  return {
15
17
  type: Array as PropType<T[]>,
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "types": ["unplugin-icons/types/vue3"],
4
5
  "baseUrl": ".",
5
6
  "paths": {
6
7
  "@/*": ["./src/*"]
package/vite.config.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import Aerogel from '@aerogel/vite';
2
+ import Icons from 'unplugin-icons/vite';
2
3
  import { defineConfig } from 'vitest/config';
3
4
  import { resolve } from 'path';
4
5
 
5
6
  export default defineConfig({
6
7
  test: { clearMocks: true },
7
- plugins: [Aerogel()],
8
+ plugins: [Aerogel(), Icons()],
8
9
  resolve: {
9
10
  alias: {
10
11
  '@': resolve(__dirname, './src'),
package/src/globals.ts DELETED
@@ -1,6 +0,0 @@
1
- export {};
2
-
3
- declare global {
4
- export const __AG_BASE_PATH: string | undefined;
5
- export const __AG_ENV: 'production' | 'development' | 'testing';
6
- }