@aerogel/core 0.0.0-next.bde642c4a8096c5fc3d5e676c2115da23f4bf1d8 → 0.0.0-next.c2e6acc000e97a1020c2e232678563c53884dd0e

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 (166) hide show
  1. package/dist/aerogel-core.d.ts +1396 -1645
  2. package/dist/aerogel-core.js +2968 -0
  3. package/dist/aerogel-core.js.map +1 -0
  4. package/package.json +27 -37
  5. package/src/bootstrap/bootstrap.test.ts +4 -7
  6. package/src/bootstrap/index.ts +25 -16
  7. package/src/bootstrap/options.ts +1 -1
  8. package/src/components/{AGAppLayout.vue → AppLayout.vue} +4 -4
  9. package/src/components/{AGAppModals.vue → AppModals.vue} +3 -4
  10. package/src/components/{AGAppOverlays.vue → AppOverlays.vue} +5 -5
  11. package/src/components/composition.ts +1 -1
  12. package/src/components/contracts/AlertModal.ts +4 -0
  13. package/src/components/contracts/Button.ts +15 -0
  14. package/src/components/contracts/ConfirmModal.ts +41 -0
  15. package/src/components/contracts/ErrorReportModal.ts +29 -0
  16. package/src/components/contracts/Input.ts +26 -0
  17. package/src/components/contracts/LoadingModal.ts +18 -0
  18. package/src/components/contracts/Modal.ts +9 -0
  19. package/src/components/contracts/PromptModal.ts +28 -0
  20. package/src/components/contracts/index.ts +7 -0
  21. package/src/components/contracts/shared.ts +9 -0
  22. package/src/components/forms/AGSelect.vue +11 -17
  23. package/src/components/forms/index.ts +0 -4
  24. package/src/components/headless/HeadlessButton.vue +45 -0
  25. package/src/components/headless/HeadlessInput.vue +59 -0
  26. package/src/components/headless/{forms/AGHeadlessInputDescription.vue → HeadlessInputDescription.vue} +6 -7
  27. package/src/components/headless/{forms/AGHeadlessInputError.vue → HeadlessInputError.vue} +4 -8
  28. package/src/components/headless/{forms/AGHeadlessInputInput.vue → HeadlessInputInput.vue} +11 -19
  29. package/src/components/headless/{forms/AGHeadlessInputLabel.vue → HeadlessInputLabel.vue} +3 -7
  30. package/src/components/headless/{forms/AGHeadlessInputTextArea.vue → HeadlessInputTextArea.vue} +7 -9
  31. package/src/components/headless/{modals/AGHeadlessModal.vue → HeadlessModal.vue} +16 -18
  32. package/src/components/headless/HeadlessModalContent.vue +24 -0
  33. package/src/components/headless/HeadlessModalOverlay.vue +12 -0
  34. package/src/components/headless/HeadlessModalTitle.vue +12 -0
  35. package/src/components/headless/forms/AGHeadlessSelect.ts +3 -3
  36. package/src/components/headless/forms/AGHeadlessSelect.vue +16 -16
  37. package/src/components/headless/forms/AGHeadlessSelectError.vue +2 -2
  38. package/src/components/headless/forms/AGHeadlessSelectOption.vue +10 -18
  39. package/src/components/headless/forms/AGHeadlessSelectOptions.vue +19 -0
  40. package/src/components/headless/forms/AGHeadlessSelectTrigger.vue +25 -0
  41. package/src/components/headless/forms/composition.ts +2 -2
  42. package/src/components/headless/forms/index.ts +2 -12
  43. package/src/components/headless/index.ts +12 -1
  44. package/src/components/headless/snackbars/index.ts +3 -3
  45. package/src/components/index.ts +5 -5
  46. package/src/components/lib/AGErrorMessage.vue +5 -5
  47. package/src/components/lib/AGMeasured.vue +3 -2
  48. package/src/components/lib/AGStartupCrash.vue +8 -8
  49. package/src/components/lib/index.ts +0 -2
  50. package/src/components/snackbars/AGSnackbar.vue +10 -8
  51. package/src/components/ui/AlertModal.vue +13 -0
  52. package/src/components/ui/Button.vue +58 -0
  53. package/src/components/ui/Checkbox.vue +49 -0
  54. package/src/components/ui/ConfirmModal.vue +42 -0
  55. package/src/components/ui/ErrorReportModal.vue +62 -0
  56. package/src/components/{modals/AGErrorReportModalButtons.vue → ui/ErrorReportModalButtons.vue} +29 -20
  57. package/src/components/ui/ErrorReportModalTitle.vue +24 -0
  58. package/src/components/{forms/AGForm.vue → ui/Form.vue} +4 -5
  59. package/src/components/ui/Input.vue +52 -0
  60. package/src/components/ui/Link.vue +12 -0
  61. package/src/components/ui/LoadingModal.vue +32 -0
  62. package/src/components/ui/Markdown.vue +62 -0
  63. package/src/components/ui/Modal.vue +55 -0
  64. package/src/components/ui/ModalContext.vue +30 -0
  65. package/src/components/ui/ProgressBar.vue +50 -0
  66. package/src/components/ui/PromptModal.vue +35 -0
  67. package/src/components/ui/index.ts +16 -0
  68. package/src/components/utils.ts +106 -9
  69. package/src/directives/index.ts +9 -5
  70. package/src/directives/measure.ts +25 -6
  71. package/src/errors/Errors.state.ts +1 -1
  72. package/src/errors/Errors.ts +14 -14
  73. package/src/errors/JobCancelledError.ts +3 -0
  74. package/src/errors/index.ts +9 -6
  75. package/src/errors/utils.ts +17 -1
  76. package/src/forms/{Form.test.ts → FormController.test.ts} +33 -4
  77. package/src/forms/{Form.ts → FormController.ts} +46 -25
  78. package/src/forms/composition.ts +4 -4
  79. package/src/forms/index.ts +3 -2
  80. package/src/forms/utils.ts +22 -6
  81. package/src/forms/validation.ts +19 -0
  82. package/src/index.css +8 -0
  83. package/src/jobs/Job.ts +144 -2
  84. package/src/jobs/index.ts +4 -1
  85. package/src/jobs/listeners.ts +3 -0
  86. package/src/jobs/status.ts +4 -0
  87. package/src/lang/DefaultLangProvider.ts +7 -4
  88. package/src/lang/Lang.state.ts +1 -1
  89. package/src/lang/Lang.ts +5 -1
  90. package/src/lang/index.ts +8 -6
  91. package/src/plugins/Plugin.ts +1 -1
  92. package/src/plugins/index.ts +10 -7
  93. package/src/services/App.state.ts +13 -4
  94. package/src/services/App.ts +8 -3
  95. package/src/services/Cache.ts +1 -1
  96. package/src/services/Events.ts +15 -5
  97. package/src/services/Service.ts +116 -53
  98. package/src/services/Storage.ts +20 -0
  99. package/src/services/index.ts +11 -5
  100. package/src/services/utils.ts +18 -0
  101. package/src/testing/index.ts +4 -3
  102. package/src/testing/setup.ts +5 -13
  103. package/src/ui/UI.state.ts +17 -5
  104. package/src/ui/UI.ts +168 -62
  105. package/src/ui/index.ts +17 -16
  106. package/src/ui/utils.ts +16 -0
  107. package/src/utils/composition/events.ts +2 -2
  108. package/src/utils/composition/forms.ts +4 -3
  109. package/src/utils/composition/persistent.test.ts +33 -0
  110. package/src/utils/composition/persistent.ts +11 -0
  111. package/src/utils/composition/state.test.ts +47 -0
  112. package/src/utils/composition/state.ts +24 -0
  113. package/src/utils/index.ts +2 -0
  114. package/src/utils/markdown.test.ts +50 -0
  115. package/src/utils/markdown.ts +19 -6
  116. package/src/utils/vdom.ts +31 -0
  117. package/src/utils/vue.ts +18 -13
  118. package/dist/aerogel-core.cjs.js +0 -2
  119. package/dist/aerogel-core.cjs.js.map +0 -1
  120. package/dist/aerogel-core.esm.js +0 -2
  121. package/dist/aerogel-core.esm.js.map +0 -1
  122. package/histoire.config.ts +0 -7
  123. package/noeldemartin.config.js +0 -5
  124. package/postcss.config.js +0 -6
  125. package/src/assets/histoire.css +0 -3
  126. package/src/components/forms/AGButton.vue +0 -44
  127. package/src/components/forms/AGCheckbox.vue +0 -41
  128. package/src/components/forms/AGInput.vue +0 -40
  129. package/src/components/headless/forms/AGHeadlessButton.ts +0 -3
  130. package/src/components/headless/forms/AGHeadlessButton.vue +0 -62
  131. package/src/components/headless/forms/AGHeadlessInput.ts +0 -33
  132. package/src/components/headless/forms/AGHeadlessInput.vue +0 -63
  133. package/src/components/headless/forms/AGHeadlessSelectButton.vue +0 -24
  134. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +0 -24
  135. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +0 -3
  136. package/src/components/headless/modals/AGHeadlessModal.ts +0 -34
  137. package/src/components/headless/modals/AGHeadlessModalPanel.vue +0 -28
  138. package/src/components/headless/modals/AGHeadlessModalTitle.vue +0 -13
  139. package/src/components/headless/modals/index.ts +0 -4
  140. package/src/components/interfaces.ts +0 -24
  141. package/src/components/lib/AGLink.vue +0 -9
  142. package/src/components/lib/AGMarkdown.vue +0 -41
  143. package/src/components/modals/AGAlertModal.ts +0 -15
  144. package/src/components/modals/AGAlertModal.vue +0 -14
  145. package/src/components/modals/AGConfirmModal.ts +0 -33
  146. package/src/components/modals/AGConfirmModal.vue +0 -26
  147. package/src/components/modals/AGErrorReportModal.ts +0 -46
  148. package/src/components/modals/AGErrorReportModal.vue +0 -54
  149. package/src/components/modals/AGErrorReportModalTitle.vue +0 -25
  150. package/src/components/modals/AGLoadingModal.ts +0 -23
  151. package/src/components/modals/AGLoadingModal.vue +0 -15
  152. package/src/components/modals/AGModal.ts +0 -10
  153. package/src/components/modals/AGModal.vue +0 -39
  154. package/src/components/modals/AGModalContext.ts +0 -8
  155. package/src/components/modals/AGModalContext.vue +0 -22
  156. package/src/components/modals/AGModalTitle.vue +0 -9
  157. package/src/components/modals/AGPromptModal.ts +0 -36
  158. package/src/components/modals/AGPromptModal.vue +0 -34
  159. package/src/components/modals/index.ts +0 -17
  160. package/src/directives/initial-focus.ts +0 -11
  161. package/src/main.histoire.ts +0 -1
  162. package/tailwind.config.js +0 -4
  163. package/tsconfig.json +0 -11
  164. package/vite.config.ts +0 -17
  165. /package/src/components/{AGAppSnackbars.vue → AppSnackbars.vue} +0 -0
  166. /package/src/{main.ts → index.ts} +0 -0
@@ -1,17 +1,25 @@
1
- import { FormFieldTypes } from './Form';
2
- import type { FormFieldDefinition } from './Form';
1
+ import { FormFieldTypes } from './FormController';
2
+ import type { FormFieldDefinition } from './FormController';
3
3
 
4
- export function booleanInput(defaultValue?: boolean): FormFieldDefinition<typeof FormFieldTypes.Boolean> {
4
+ export function booleanInput(
5
+ defaultValue?: boolean,
6
+ options: { rules?: string } = {},
7
+ ): FormFieldDefinition<typeof FormFieldTypes.Boolean> {
5
8
  return {
6
9
  default: defaultValue,
7
10
  type: FormFieldTypes.Boolean,
11
+ rules: options.rules,
8
12
  };
9
13
  }
10
14
 
11
- export function dateInput(defaultValue?: Date): FormFieldDefinition<typeof FormFieldTypes.Date> {
15
+ export function dateInput(
16
+ defaultValue?: Date,
17
+ options: { rules?: string } = {},
18
+ ): FormFieldDefinition<typeof FormFieldTypes.Date> {
12
19
  return {
13
20
  default: defaultValue,
14
21
  type: FormFieldTypes.Date,
22
+ rules: options.rules,
15
23
  };
16
24
  }
17
25
 
@@ -53,16 +61,24 @@ export function requiredStringInput(
53
61
  };
54
62
  }
55
63
 
56
- export function numberInput(defaultValue?: number): FormFieldDefinition<typeof FormFieldTypes.Number> {
64
+ export function numberInput(
65
+ defaultValue?: number,
66
+ options: { rules?: string } = {},
67
+ ): FormFieldDefinition<typeof FormFieldTypes.Number> {
57
68
  return {
58
69
  default: defaultValue,
59
70
  type: FormFieldTypes.Number,
71
+ rules: options.rules,
60
72
  };
61
73
  }
62
74
 
63
- export function stringInput(defaultValue?: string): FormFieldDefinition<typeof FormFieldTypes.String> {
75
+ export function stringInput(
76
+ defaultValue?: string,
77
+ options: { rules?: string } = {},
78
+ ): FormFieldDefinition<typeof FormFieldTypes.String> {
64
79
  return {
65
80
  default: defaultValue,
66
81
  type: FormFieldTypes.String,
82
+ rules: options.rules,
67
83
  };
68
84
  }
@@ -0,0 +1,19 @@
1
+ import { arrayFrom } from '@noeldemartin/utils';
2
+
3
+ const builtInRules: Record<string, FormFieldValidator> = {
4
+ required: (value) => (value ? undefined : 'required'),
5
+ };
6
+
7
+ export type FormFieldValidator<T = unknown> = (value: T) => string | string[] | undefined;
8
+
9
+ export const validators: Record<string, FormFieldValidator> = { ...builtInRules };
10
+
11
+ export function defineFormValidationRule<T>(rule: string, validator: FormFieldValidator<T>): void {
12
+ validators[rule] = validator as FormFieldValidator;
13
+ }
14
+
15
+ export function validate(value: unknown, rule: string): string[] {
16
+ const errors = validators[rule]?.(value);
17
+
18
+ return errors ? arrayFrom(errors) : [];
19
+ }
package/src/index.css ADDED
@@ -0,0 +1,8 @@
1
+ @source './';
2
+
3
+ @theme {
4
+ --color-background: oklch(1 0 0);
5
+ --color-primary: oklch(0.205 0 0);
6
+ --color-danger: oklch(0.577 0.245 27.325);
7
+ --color-accent: oklch(0.97 0 0);
8
+ }
package/src/jobs/Job.ts CHANGED
@@ -1,5 +1,147 @@
1
- export default abstract class Job {
1
+ import { ListenersManager, PromisedValue, round, tap, toError } from '@noeldemartin/utils';
2
+ import type { Listeners } from '@noeldemartin/utils';
2
3
 
3
- public abstract run(): Promise<void>;
4
+ import JobCancelledError from '@aerogel/core/errors/JobCancelledError';
5
+
6
+ import type { JobListener } from './listeners';
7
+ import type { JobStatus } from './status';
8
+
9
+ export default abstract class Job<
10
+ Listener extends JobListener = JobListener,
11
+ Status extends JobStatus = JobStatus,
12
+ SerializedStatus extends JobStatus = JobStatus,
13
+ > {
14
+
15
+ protected status: Status;
16
+ protected _listeners: ListenersManager<JobListener>;
17
+ protected _progress?: number;
18
+ protected _cancelled?: PromisedValue<void>;
19
+ protected _started: PromisedValue<void>;
20
+ protected _completed: PromisedValue<void>;
21
+
22
+ constructor() {
23
+ this.status = this.getInitialStatus();
24
+ this._listeners = new ListenersManager();
25
+ this._started = new PromisedValue();
26
+ this._completed = new PromisedValue();
27
+ }
28
+
29
+ public async start(): Promise<void> {
30
+ this.beforeStart();
31
+ this._started.resolve();
32
+
33
+ try {
34
+ await this.updateProgress();
35
+ await this.run();
36
+ await this.updateProgress();
37
+
38
+ this._completed.resolve();
39
+ } catch (error) {
40
+ if (error instanceof JobCancelledError) {
41
+ return;
42
+ }
43
+
44
+ throw tap(toError(error), (realError) => {
45
+ this._completed.reject(realError);
46
+ });
47
+ }
48
+ }
49
+
50
+ public async cancel(): Promise<void> {
51
+ this._cancelled = new PromisedValue();
52
+
53
+ await this._cancelled;
54
+ }
55
+
56
+ public serialize(): SerializedStatus {
57
+ return this.serializeStatus(this.status);
58
+ }
59
+
60
+ public get listeners(): Listeners<Listener> {
61
+ return this._listeners;
62
+ }
63
+
64
+ public get progress(): number {
65
+ return this._progress ?? 0;
66
+ }
67
+
68
+ public get cancelled(): boolean {
69
+ return !!this._cancelled?.isResolved();
70
+ }
71
+
72
+ public get started(): Promise<void> {
73
+ return this._started;
74
+ }
75
+
76
+ public get completed(): Promise<void> {
77
+ return this._completed;
78
+ }
79
+
80
+ protected abstract run(): Promise<void>;
81
+
82
+ protected getInitialStatus(): Status {
83
+ return { completed: false } as Status;
84
+ }
85
+
86
+ protected beforeStart(): void {
87
+ if (!this._started.isResolved()) {
88
+ return;
89
+ }
90
+
91
+ if (this._cancelled) {
92
+ delete this._progress;
93
+ delete this._cancelled;
94
+
95
+ return;
96
+ }
97
+
98
+ throw new Error('Job already started!');
99
+ }
100
+
101
+ protected assertNotCancelled(): void {
102
+ if (!this._cancelled) {
103
+ return;
104
+ }
105
+
106
+ this._cancelled.resolve();
107
+
108
+ throw new JobCancelledError();
109
+ }
110
+
111
+ protected calculateCurrentProgress(status?: JobStatus): number {
112
+ status ??= this.status;
113
+
114
+ if (status.completed) {
115
+ return 1;
116
+ }
117
+
118
+ if (!status.children) {
119
+ return 0;
120
+ }
121
+
122
+ return round(
123
+ status.children.reduce((total, child) => total + this.calculateCurrentProgress(child), 0) /
124
+ status.children.length,
125
+ 2,
126
+ );
127
+ }
128
+
129
+ protected async updateProgress(update?: (status: Status) => unknown): Promise<void> {
130
+ await update?.(this.status);
131
+
132
+ const progress = this.calculateCurrentProgress();
133
+
134
+ if (progress === this._progress) {
135
+ return;
136
+ }
137
+
138
+ this._progress = progress;
139
+
140
+ await this._listeners.emit('onUpdated', progress);
141
+ }
142
+
143
+ protected serializeStatus(status: Status): SerializedStatus {
144
+ return { ...status } as unknown as SerializedStatus;
145
+ }
4
146
 
5
147
  }
package/src/jobs/index.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import Job from './Job';
2
2
 
3
3
  export { Job };
4
+ export * from './Job';
5
+ export * from './listeners';
6
+ export * from './status';
4
7
 
5
8
  export async function dispatch(job: Job): Promise<void> {
6
- await job.run();
9
+ await job.start();
7
10
  }
@@ -0,0 +1,3 @@
1
+ export interface JobListener {
2
+ onUpdated?(progress: number): unknown;
3
+ }
@@ -0,0 +1,4 @@
1
+ export interface JobStatus {
2
+ completed: boolean;
3
+ children?: JobStatus[];
4
+ }
@@ -1,10 +1,13 @@
1
- import App from '@/services/App';
1
+ import { isDevelopment } from '@noeldemartin/utils';
2
2
 
3
3
  import type { LangProvider } from './Lang';
4
4
 
5
5
  export default class DefaultLangProvider implements LangProvider {
6
6
 
7
- constructor(private locale: string, private fallbackLocale: string) {}
7
+ constructor(
8
+ private locale: string,
9
+ private fallbackLocale: string,
10
+ ) {}
8
11
 
9
12
  public getLocale(): string {
10
13
  return this.locale;
@@ -28,14 +31,14 @@ export default class DefaultLangProvider implements LangProvider {
28
31
 
29
32
  public translate(key: string): string {
30
33
  // eslint-disable-next-line no-console
31
- App.development && console.warn('Lang provider is missing');
34
+ isDevelopment() && console.warn('Lang provider is missing');
32
35
 
33
36
  return key;
34
37
  }
35
38
 
36
39
  public translateWithDefault(_: string, defaultMessage: string): string {
37
40
  // eslint-disable-next-line no-console
38
- App.development && console.warn('Lang provider is missing');
41
+ isDevelopment() && console.warn('Lang provider is missing');
39
42
 
40
43
  return defaultMessage;
41
44
  }
@@ -1,4 +1,4 @@
1
- import { defineServiceState } from '@/services/Service';
1
+ import { defineServiceState } from '@aerogel/core/services/Service';
2
2
 
3
3
  export default defineServiceState({
4
4
  name: 'lang',
package/src/lang/Lang.ts CHANGED
@@ -52,7 +52,11 @@ export class LangService extends Service {
52
52
  return navigator.languages.find((locale) => locales.includes(locale)) ?? 'en';
53
53
  }
54
54
 
55
- protected async boot(): Promise<void> {
55
+ protected override async boot(): Promise<void> {
56
+ if (!globalThis.document) {
57
+ return;
58
+ }
59
+
56
60
  this.requireStore().$subscribe(
57
61
  async () => {
58
62
  await this.provider.setLocale(this.locale ?? this.getBrowserLocale());
package/src/lang/index.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { bootServices } from '@/services';
2
- import { definePlugin } from '@/plugins';
1
+ import { bootServices } from '@aerogel/core/services';
2
+ import { definePlugin } from '@aerogel/core/plugins';
3
3
 
4
- import Lang, { LangProvider } from './Lang';
4
+ import Lang from './Lang';
5
+ import type { LangProvider } from './Lang';
5
6
  import { translate, translateWithDefault } from './utils';
6
7
 
7
- export { Lang, LangProvider, translate, translateWithDefault };
8
+ export { Lang, translate, translateWithDefault };
9
+ export type { LangProvider };
8
10
 
9
11
  const services = { $lang: Lang };
10
12
 
@@ -19,11 +21,11 @@ export default definePlugin({
19
21
  },
20
22
  });
21
23
 
22
- declare module '@/services' {
24
+ declare module '@aerogel/core/services' {
23
25
  export interface Services extends LangServices {}
24
26
  }
25
27
 
26
- declare module '@vue/runtime-core' {
28
+ declare module 'vue' {
27
29
  interface ComponentCustomProperties {
28
30
  $td: typeof translateWithDefault;
29
31
  }
@@ -1,6 +1,6 @@
1
1
  import type { App } from 'vue';
2
2
 
3
- import type { AerogelOptions } from '@/bootstrap/options';
3
+ import type { AerogelOptions } from '@aerogel/core/bootstrap/options';
4
4
 
5
5
  export interface Plugin {
6
6
  name?: string;
@@ -1,6 +1,6 @@
1
1
  import type { GetClosureArgs } from '@noeldemartin/utils';
2
2
 
3
- import App from '@/services/App';
3
+ import App from '@aerogel/core/services/App';
4
4
 
5
5
  import type { Plugin } from './Plugin';
6
6
 
@@ -13,13 +13,16 @@ export function definePlugin<T extends Plugin>(plugin: T): T {
13
13
  export async function installPlugins(plugins: Plugin[], ...args: GetClosureArgs<Plugin['install']>): Promise<void> {
14
14
  App.setState(
15
15
  'plugins',
16
- plugins.reduce((pluginsMap, plugin) => {
17
- if (plugin.name) {
18
- pluginsMap[plugin.name] = plugin;
19
- }
16
+ plugins.reduce(
17
+ (pluginsMap, plugin) => {
18
+ if (plugin.name) {
19
+ pluginsMap[plugin.name] = plugin;
20
+ }
20
21
 
21
- return pluginsMap;
22
- }, {} as Record<string, Plugin>),
22
+ return pluginsMap;
23
+ },
24
+ {} as Record<string, Plugin>,
25
+ ),
23
26
  );
24
27
 
25
28
  await Promise.all(plugins.map((plugin) => plugin.install(...args)) ?? []);
@@ -1,30 +1,39 @@
1
1
  import Aerogel from 'virtual:aerogel';
2
2
 
3
- import { defineServiceState } from '@/services/Service';
4
- import type { Plugin } from '@/plugins/Plugin';
3
+ import { getEnv } from '@noeldemartin/utils';
4
+ import type { App } from 'vue';
5
+
6
+ import { defineServiceState } from '@aerogel/core/services/Service';
7
+ import type { Plugin } from '@aerogel/core/plugins/Plugin';
5
8
 
6
9
  export default defineServiceState({
7
10
  name: 'app',
8
11
  initialState: {
9
12
  plugins: {} as Record<string, Plugin>,
10
- environment: Aerogel.environment,
13
+ instance: null as App | null,
14
+ environment: getEnv() ?? 'development',
11
15
  version: Aerogel.version,
12
16
  sourceUrl: Aerogel.sourceUrl,
13
17
  },
14
18
  computed: {
15
19
  development: (state) => state.environment === 'development',
20
+ staging: (state) => state.environment === 'staging',
16
21
  testing: (state) => state.environment === 'test' || state.environment === 'testing',
17
22
  versionName(state): string {
18
23
  if (this.development) {
19
24
  return 'dev.' + Aerogel.sourceHash.toString().substring(0, 7);
20
25
  }
21
26
 
27
+ if (this.staging) {
28
+ return 'staging.' + Aerogel.sourceHash.toString().substring(0, 7);
29
+ }
30
+
22
31
  return `v${state.version}`;
23
32
  },
24
33
  versionUrl(state): string {
25
34
  return (
26
35
  state.sourceUrl +
27
- (this.development ? `/tree/${Aerogel.sourceHash}` : `/releases/tag/${this.versionName}`)
36
+ (this.development || this.staging ? `/tree/${Aerogel.sourceHash}` : `/releases/tag/${this.versionName}`)
28
37
  );
29
38
  },
30
39
  },
@@ -2,8 +2,9 @@ import Aerogel from 'virtual:aerogel';
2
2
 
3
3
  import { PromisedValue, facade, forever, updateLocationQueryParameters } from '@noeldemartin/utils';
4
4
 
5
- import Events from '@/services/Events';
6
- import type { Plugin } from '@/plugins';
5
+ import Events from '@aerogel/core/services/Events';
6
+ import type { Plugin } from '@aerogel/core/plugins';
7
+ import type { Services } from '@aerogel/core/services';
7
8
 
8
9
  import Service from './App.state';
9
10
 
@@ -40,7 +41,11 @@ export class AppService extends Service {
40
41
  return (this.plugins[name] as T) ?? null;
41
42
  }
42
43
 
43
- protected async boot(): Promise<void> {
44
+ public service<T extends keyof Services>(name: T): Services[T] | null {
45
+ return this.instance?.config.globalProperties[name] ?? null;
46
+ }
47
+
48
+ protected override async boot(): Promise<void> {
44
49
  Events.once('application-ready', () => this.ready.resolve());
45
50
  Events.once('application-mounted', () => this.mounted.resolve());
46
51
  }
@@ -1,6 +1,6 @@
1
1
  import { PromisedValue, facade, tap } from '@noeldemartin/utils';
2
2
 
3
- import Service from '@/services/Service';
3
+ import Service from '@aerogel/core/services/Service';
4
4
 
5
5
  export class CacheService extends Service {
6
6
 
@@ -1,10 +1,10 @@
1
1
  import { arrayRemove, facade, fail, tap } from '@noeldemartin/utils';
2
2
 
3
- import Service from '@/services/Service';
3
+ import Service from '@aerogel/core/services/Service';
4
4
 
5
5
  export interface EventsPayload {}
6
6
  export interface EventListenerOptions {
7
- priority: number;
7
+ priority: EventListenerPriority;
8
8
  }
9
9
  export type AerogelGlobalEvents = Partial<{ [Event in EventWithoutPayload]: () => unknown }> &
10
10
  Partial<{ [Event in EventWithPayload]: EventListener<EventsPayload[Event]> }>;
@@ -26,11 +26,13 @@ export const EventListenerPriorities = {
26
26
  High: 256,
27
27
  } as const;
28
28
 
29
+ export type EventListenerPriority = (typeof EventListenerPriorities)[keyof typeof EventListenerPriorities];
30
+
29
31
  export class EventsService extends Service {
30
32
 
31
33
  private listeners: Record<string, { priorities: number[]; handlers: Record<number, EventListener[]> }> = {};
32
34
 
33
- protected async boot(): Promise<void> {
35
+ protected override async boot(): Promise<void> {
34
36
  Object.entries(globalThis.__aerogelEvents__ ?? {}).forEach(([event, listener]) =>
35
37
  this.on(event as string, listener as EventListener));
36
38
  }
@@ -48,19 +50,27 @@ export class EventsService extends Service {
48
50
 
49
51
  /* eslint-disable max-len */
50
52
  public on<Event extends EventWithoutPayload>(event: Event, listener: () => unknown): () => void;
53
+ public on<Event extends EventWithoutPayload>(event: Event, priority: EventListenerPriority, listener: () => unknown): () => void; // prettier-ignore
51
54
  public on<Event extends EventWithoutPayload>(event: Event, options: Partial<EventListenerOptions>, listener: () => unknown): () => void; // prettier-ignore
52
55
  public on<Event extends EventWithPayload>(event: Event, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
56
+ public on<Event extends EventWithPayload>(event: Event, priority: EventListenerPriority, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
53
57
  public on<Event extends EventWithPayload>(event: Event, options: Partial<EventListenerOptions>, listener: EventListener<EventsPayload[Event]>): () => void | void; // prettier-ignore
54
58
  public on<Event extends string>(event: UnknownEvent<Event>, listener: EventListener): () => void;
59
+ public on<Event extends string>(event: UnknownEvent<Event>, priority: EventListenerPriority, listener: EventListener): () => void; // prettier-ignore
55
60
  public on<Event extends string>(event: UnknownEvent<Event>, options: Partial<EventListenerOptions>, listener: EventListener): () => void; // prettier-ignore
56
61
  /* eslint-enable max-len */
57
62
 
58
63
  public on(
59
64
  event: string,
60
- optionsOrListener: Partial<EventListenerOptions> | EventListener,
65
+ optionsOrListener: Partial<EventListenerOptions> | EventListenerPriority | EventListener,
61
66
  listener?: EventListener,
62
67
  ): () => void {
63
- const options = typeof optionsOrListener === 'function' ? {} : optionsOrListener;
68
+ const options =
69
+ typeof optionsOrListener === 'function'
70
+ ? {}
71
+ : typeof optionsOrListener === 'number'
72
+ ? { priority: optionsOrListener }
73
+ : optionsOrListener;
64
74
  const handler = typeof optionsOrListener === 'function' ? optionsOrListener : (listener as EventListener);
65
75
 
66
76
  this.registerListener(event, options, handler);