@aerogel/core 0.0.0-next.926bde19326fe7b6b24b277666936862b64d8295 → 0.0.0-next.980a397d575dcb5ff8c5a0bff769d09f938ea03c

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 (97) 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 +958 -128
  4. package/dist/aerogel-core.esm.js +1 -1
  5. package/dist/aerogel-core.esm.js.map +1 -1
  6. package/histoire.config.ts +7 -0
  7. package/noeldemartin.config.js +4 -1
  8. package/package.json +14 -4
  9. package/postcss.config.js +6 -0
  10. package/src/assets/histoire.css +3 -0
  11. package/src/bootstrap/bootstrap.test.ts +1 -0
  12. package/src/bootstrap/index.ts +14 -2
  13. package/src/components/AGAppLayout.vue +6 -2
  14. package/src/components/AGAppModals.vue +15 -0
  15. package/src/components/AGAppOverlays.vue +5 -7
  16. package/src/components/AGAppSnackbars.vue +13 -0
  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/AGSelect.story.vue +28 -0
  22. package/src/components/forms/AGSelect.vue +53 -0
  23. package/src/components/forms/index.ts +5 -5
  24. package/src/components/headless/forms/AGHeadlessButton.vue +7 -7
  25. package/src/components/headless/forms/AGHeadlessInput.ts +27 -2
  26. package/src/components/headless/forms/AGHeadlessInput.vue +11 -8
  27. package/src/components/headless/forms/AGHeadlessInputError.vue +1 -1
  28. package/src/components/headless/forms/AGHeadlessInputInput.vue +15 -3
  29. package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
  30. package/src/components/headless/forms/AGHeadlessSelect.ts +44 -0
  31. package/src/components/headless/forms/AGHeadlessSelect.vue +76 -0
  32. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  33. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  34. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  35. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  37. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  38. package/src/components/headless/forms/index.ts +9 -1
  39. package/src/components/headless/index.ts +1 -0
  40. package/src/components/headless/modals/AGHeadlessModal.ts +9 -0
  41. package/src/components/headless/modals/AGHeadlessModalPanel.vue +5 -1
  42. package/src/components/headless/modals/index.ts +4 -6
  43. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  44. package/src/components/headless/snackbars/index.ts +25 -0
  45. package/src/components/index.ts +3 -1
  46. package/src/components/lib/AGErrorMessage.vue +16 -0
  47. package/src/components/lib/AGLink.vue +9 -0
  48. package/src/components/lib/AGMarkdown.vue +36 -0
  49. package/src/components/lib/AGStartupCrash.vue +31 -0
  50. package/src/components/lib/index.ts +4 -0
  51. package/src/components/modals/AGAlertModal.vue +1 -2
  52. package/src/components/modals/AGConfirmModal.ts +10 -0
  53. package/src/components/modals/AGConfirmModal.vue +2 -2
  54. package/src/components/modals/AGErrorReportModal.ts +20 -0
  55. package/src/components/modals/AGErrorReportModal.vue +62 -0
  56. package/src/components/modals/AGErrorReportModalButtons.vue +109 -0
  57. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  58. package/src/components/modals/AGLoadingModal.ts +9 -0
  59. package/src/components/modals/AGLoadingModal.vue +19 -0
  60. package/src/components/modals/AGModal.ts +1 -1
  61. package/src/components/modals/AGModal.vue +23 -4
  62. package/src/components/modals/AGModalTitle.vue +9 -0
  63. package/src/components/modals/index.ts +20 -2
  64. package/src/components/snackbars/AGSnackbar.vue +42 -0
  65. package/src/components/snackbars/index.ts +3 -0
  66. package/src/directives/index.ts +16 -3
  67. package/src/errors/Errors.state.ts +31 -0
  68. package/src/errors/Errors.ts +183 -0
  69. package/src/errors/index.ts +55 -0
  70. package/src/forms/Form.ts +26 -15
  71. package/src/forms/utils.ts +17 -0
  72. package/src/lang/Lang.ts +12 -4
  73. package/src/lang/index.ts +3 -5
  74. package/src/lang/utils.ts +4 -0
  75. package/src/main.histoire.ts +1 -0
  76. package/src/main.ts +1 -2
  77. package/src/plugins/Plugin.ts +1 -0
  78. package/src/plugins/index.ts +19 -0
  79. package/src/services/App.state.ts +10 -2
  80. package/src/services/App.ts +24 -2
  81. package/src/services/Service.ts +136 -45
  82. package/src/services/index.ts +21 -4
  83. package/src/services/store.ts +27 -0
  84. package/src/ui/UI.state.ts +11 -1
  85. package/src/ui/UI.ts +75 -9
  86. package/src/ui/index.ts +7 -1
  87. package/src/utils/composition/forms.ts +11 -0
  88. package/src/utils/index.ts +1 -0
  89. package/src/utils/markdown.ts +11 -2
  90. package/src/utils/vue.ts +5 -3
  91. package/tailwind.config.js +4 -0
  92. package/tsconfig.json +1 -0
  93. package/vite.config.ts +2 -1
  94. package/.eslintrc.js +0 -3
  95. package/src/components/basic/AGMarkdown.vue +0 -35
  96. package/src/components/basic/index.ts +0 -3
  97. package/src/globals.ts +0 -6
package/src/ui/UI.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { facade, fail, uuid } from '@noeldemartin/utils';
1
+ import { after, facade, fail, uuid } from '@noeldemartin/utils';
2
2
  import { markRaw, nextTick } from 'vue';
3
3
  import type { Component } from 'vue';
4
4
  import type { ObjectValues } from '@noeldemartin/utils';
5
5
 
6
6
  import Events from '@/services/Events';
7
+ 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,42 @@ 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
+
76
+ try {
77
+ const [result] = await Promise.all([operation, after({ seconds: 1 })]);
78
+
79
+ return result;
80
+ } finally {
81
+ await this.closeModal(modal.id);
82
+ }
83
+ }
84
+
85
+ public showSnackbar(message: string, options: ShowSnackbarOptions = {}): void {
86
+ const snackbar: Snackbar = {
87
+ id: uuid(),
88
+ properties: { message, ...options },
89
+ component: options.component ?? markRaw(this.requireComponent(UIComponents.Snackbar)),
90
+ };
91
+
92
+ this.setState('snackbars', this.snackbars.concat(snackbar));
93
+
94
+ setTimeout(() => this.hideSnackbar(snackbar.id), 5000);
95
+ }
96
+
97
+ public hideSnackbar(id: string): void {
98
+ this.setState(
99
+ 'snackbars',
100
+ this.snackbars.filter((snackbar) => snackbar.id !== id),
101
+ );
102
+ }
103
+
54
104
  public registerComponent(name: UIComponent, component: Component): void {
55
105
  this.components[name] = component;
56
106
  }
@@ -90,13 +140,8 @@ export class UIService extends Service {
90
140
  }
91
141
 
92
142
  protected async boot(): Promise<void> {
93
- await super.boot();
94
-
95
143
  this.watchModalEvents();
96
- }
97
-
98
- private requireComponent(name: UIComponent): Component {
99
- return this.components[name] ?? fail(`UI Component '${name}' is not defined!`);
144
+ this.watchMountedEvent();
100
145
  }
101
146
 
102
147
  private watchModalEvents(): void {
@@ -109,7 +154,10 @@ export class UIService extends Service {
109
154
  });
110
155
 
111
156
  Events.on('modal-closed', async ({ modal, result }) => {
112
- this.setState({ modals: this.modals.filter((m) => m.id !== modal.id) });
157
+ this.setState(
158
+ 'modals',
159
+ this.modals.filter((m) => m.id !== modal.id),
160
+ );
113
161
 
114
162
  this.modalCallbacks[modal.id]?.closed?.(result);
115
163
 
@@ -121,6 +169,24 @@ export class UIService extends Service {
121
169
  });
122
170
  }
123
171
 
172
+ private watchMountedEvent(): void {
173
+ Events.once('application-mounted', async () => {
174
+ const splash = document.getElementById('splash');
175
+
176
+ if (!splash) {
177
+ return;
178
+ }
179
+
180
+ if (window.getComputedStyle(splash).opacity !== '0') {
181
+ splash.style.opacity = '0';
182
+
183
+ await after({ ms: 600 });
184
+ }
185
+
186
+ splash.remove();
187
+ });
188
+ }
189
+
124
190
  }
125
191
 
126
192
  export default facade(new UIService());
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
@@ -3,13 +3,15 @@ import { inject, reactive, ref } from 'vue';
3
3
  import type { Directive, InjectionKey, PropType, Ref, UnwrapNestedRefs } from 'vue';
4
4
 
5
5
  type BaseProp<T> = {
6
- type: PropType<T>;
6
+ type?: PropType<T>;
7
7
  validator?(value: unknown): boolean;
8
8
  };
9
9
 
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[]>,
@@ -62,7 +64,7 @@ export function injectOrFail<T>(key: InjectionKey<T> | string, errorMessage?: st
62
64
  return inject(key) ?? fail(errorMessage ?? `Could not resolve '${key}' injection key`);
63
65
  }
64
66
 
65
- export function mixedProp<T>(type: PropType<T>): OptionalProp<T | null> {
67
+ export function mixedProp<T>(type?: PropType<T>): OptionalProp<T | null> {
66
68
  return {
67
69
  type,
68
70
  default: null,
@@ -106,7 +108,7 @@ export function requiredEnumProp<Enum extends Record<string, unknown>>(
106
108
  };
107
109
  }
108
110
 
109
- export function requiredMixedProp<T>(type: PropType<T>): RequiredProp<T> {
111
+ export function requiredMixedProp<T>(type?: PropType<T>): RequiredProp<T> {
110
112
  return {
111
113
  type,
112
114
  required: true,
@@ -0,0 +1,4 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: ['./src/**/*.{vue,ts}'],
4
+ };
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "types": ["unplugin-icons/types/vue3", "@aerogel/vite/dist/virtual"],
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/.eslintrc.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- extends: ['@noeldemartin/eslint-config-vue'],
3
- };
@@ -1,35 +0,0 @@
1
- <template>
2
- <root />
3
- </template>
4
-
5
- <script setup lang="ts">
6
- import { computed, h } from 'vue';
7
-
8
- import { renderMarkdown } from '@/utils/markdown';
9
- import { booleanProp, stringProp } from '@/utils/vue';
10
- import { translate } from '@/lang';
11
-
12
- const props = defineProps({
13
- as: stringProp('div'),
14
- langKey: stringProp(),
15
- text: stringProp(),
16
- inline: booleanProp(),
17
- raw: booleanProp(),
18
- });
19
-
20
- const markdown = computed(() => props.text ?? (props.langKey && translate(props.langKey)));
21
- const html = computed(() => {
22
- if (!markdown.value) {
23
- return null;
24
- }
25
-
26
- let html = renderMarkdown(markdown.value);
27
-
28
- if (props.inline) {
29
- html = html.replace('<p>', '<span>').replace('</p>', '</span>');
30
- }
31
-
32
- return html;
33
- });
34
- const root = () => h(props.as, { class: props.raw ? '' : 'prose', innerHTML: html.value });
35
- </script>
@@ -1,3 +0,0 @@
1
- import AGMarkdown from './AGMarkdown.vue';
2
-
3
- export { AGMarkdown };
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
- }