@aerogel/core 0.0.0-next.7f6ed5a1f91688a86bf5ede2adc465e4fd6cfdea → 0.0.0-next.824cf5311c4335d119158f507dad094ed4f4f0b6

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 (120) 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 +1630 -204
  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 +15 -8
  9. package/postcss.config.js +6 -0
  10. package/src/assets/histoire.css +3 -0
  11. package/src/bootstrap/bootstrap.test.ts +4 -59
  12. package/src/bootstrap/index.ts +31 -28
  13. package/src/bootstrap/options.ts +8 -1
  14. package/src/components/AGAppLayout.vue +7 -2
  15. package/src/components/AGAppModals.vue +15 -0
  16. package/src/components/AGAppOverlays.vue +10 -8
  17. package/src/components/AGAppSnackbars.vue +13 -0
  18. package/src/components/constants.ts +8 -0
  19. package/src/components/forms/AGButton.vue +36 -3
  20. package/src/components/forms/AGCheckbox.vue +41 -0
  21. package/src/components/forms/AGInput.vue +15 -9
  22. package/src/components/forms/AGSelect.story.vue +46 -0
  23. package/src/components/forms/AGSelect.vue +60 -0
  24. package/src/components/forms/index.ts +5 -5
  25. package/src/components/headless/forms/AGHeadlessButton.vue +7 -7
  26. package/src/components/headless/forms/AGHeadlessInput.ts +23 -3
  27. package/src/components/headless/forms/AGHeadlessInput.vue +13 -10
  28. package/src/components/headless/forms/AGHeadlessInputError.vue +9 -5
  29. package/src/components/headless/forms/AGHeadlessInputInput.vue +20 -4
  30. package/src/components/headless/forms/AGHeadlessInputLabel.vue +22 -0
  31. package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
  32. package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
  33. package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
  34. package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
  35. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
  36. package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
  37. package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
  38. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
  39. package/src/components/headless/forms/index.ts +14 -4
  40. package/src/components/headless/index.ts +1 -0
  41. package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
  42. package/src/components/headless/modals/AGHeadlessModal.vue +8 -6
  43. package/src/components/headless/modals/AGHeadlessModalPanel.vue +10 -2
  44. package/src/components/headless/modals/index.ts +4 -6
  45. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
  46. package/src/components/headless/snackbars/index.ts +40 -0
  47. package/src/components/index.ts +5 -2
  48. package/src/components/lib/AGErrorMessage.vue +16 -0
  49. package/src/components/lib/AGLink.vue +9 -0
  50. package/src/components/lib/AGMarkdown.vue +36 -0
  51. package/src/components/lib/AGMeasured.vue +15 -0
  52. package/src/components/lib/AGStartupCrash.vue +31 -0
  53. package/src/components/lib/index.ts +5 -0
  54. package/src/components/modals/AGAlertModal.ts +15 -0
  55. package/src/components/modals/AGAlertModal.vue +4 -5
  56. package/src/components/modals/AGConfirmModal.ts +27 -0
  57. package/src/components/modals/AGConfirmModal.vue +26 -0
  58. package/src/components/modals/AGErrorReportModal.ts +46 -0
  59. package/src/components/modals/AGErrorReportModal.vue +54 -0
  60. package/src/components/modals/AGErrorReportModalButtons.vue +111 -0
  61. package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
  62. package/src/components/modals/AGLoadingModal.ts +23 -0
  63. package/src/components/modals/AGLoadingModal.vue +15 -0
  64. package/src/components/modals/AGModal.ts +5 -1
  65. package/src/components/modals/AGModal.vue +26 -5
  66. package/src/components/modals/AGModalTitle.vue +9 -0
  67. package/src/components/modals/AGPromptModal.ts +30 -0
  68. package/src/components/modals/AGPromptModal.vue +34 -0
  69. package/src/components/modals/index.ts +16 -4
  70. package/src/components/snackbars/AGSnackbar.vue +36 -0
  71. package/src/components/snackbars/index.ts +3 -0
  72. package/src/components/utils.ts +10 -0
  73. package/src/directives/index.ts +21 -4
  74. package/src/directives/measure.ts +12 -0
  75. package/src/errors/Errors.state.ts +31 -0
  76. package/src/errors/Errors.ts +192 -0
  77. package/src/errors/index.ts +45 -0
  78. package/src/forms/Form.test.ts +21 -0
  79. package/src/forms/Form.ts +48 -17
  80. package/src/forms/utils.ts +17 -0
  81. package/src/jobs/Job.ts +5 -0
  82. package/src/jobs/index.ts +7 -0
  83. package/src/lang/Lang.ts +48 -9
  84. package/src/lang/index.ts +17 -76
  85. package/src/lang/utils.ts +4 -0
  86. package/src/main.histoire.ts +1 -0
  87. package/src/main.ts +3 -0
  88. package/src/plugins/Plugin.ts +8 -0
  89. package/src/plugins/index.ts +26 -0
  90. package/src/services/App.state.ts +17 -0
  91. package/src/services/App.ts +47 -0
  92. package/src/services/Events.test.ts +39 -0
  93. package/src/services/Events.ts +88 -30
  94. package/src/services/Service.ts +195 -33
  95. package/src/services/index.ts +33 -7
  96. package/src/services/store.ts +30 -0
  97. package/src/types/vite.d.ts +0 -2
  98. package/src/ui/UI.state.ts +12 -6
  99. package/src/ui/UI.ts +177 -12
  100. package/src/ui/index.ts +31 -16
  101. package/src/utils/composition/events.ts +1 -0
  102. package/src/utils/composition/forms.ts +11 -0
  103. package/src/utils/composition/hooks.ts +9 -0
  104. package/src/utils/index.ts +4 -0
  105. package/src/utils/markdown.ts +11 -2
  106. package/src/utils/tailwindcss.test.ts +26 -0
  107. package/src/utils/tailwindcss.ts +7 -0
  108. package/src/utils/vue.ts +15 -4
  109. package/tailwind.config.js +4 -0
  110. package/tsconfig.json +2 -10
  111. package/vite.config.ts +3 -6
  112. package/.eslintrc.js +0 -3
  113. package/src/bootstrap/hooks.ts +0 -19
  114. package/src/components/basic/AGMarkdown.vue +0 -20
  115. package/src/components/basic/index.ts +0 -3
  116. package/src/lang/helpers.ts +0 -5
  117. package/src/models/index.ts +0 -18
  118. package/src/routing/index.ts +0 -33
  119. package/src/testing/stubs/lang/en.yaml +0 -1
  120. package/src/testing/stubs/models/User.ts +0 -3
package/src/ui/index.ts CHANGED
@@ -1,37 +1,52 @@
1
1
  import type { Component } from 'vue';
2
2
 
3
3
  import { bootServices } from '@/services';
4
- import { defineBootstrapHook } from '@/bootstrap/hooks';
4
+ import { definePlugin } from '@/plugins';
5
5
 
6
6
  import UI, { UIComponents } from './UI';
7
7
  import AGAlertModal from '../components/modals/AGAlertModal.vue';
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 AGPromptModal from '../components/modals/AGPromptModal.vue';
12
+ import AGSnackbar from '../components/snackbars/AGSnackbar.vue';
13
+ import AGStartupCrash from '../components/lib/AGStartupCrash.vue';
8
14
  import type { UIComponent } from './UI';
9
15
 
10
- export { UI, UIComponents, UIComponent };
11
-
12
16
  const services = { $ui: UI };
13
17
 
14
- export type UIServices = typeof services;
15
-
16
- export default defineBootstrapHook(async (app, options) => {
17
- const defaultComponents = {
18
- [UIComponents.AlertModal]: AGAlertModal,
19
- };
18
+ export * from './UI';
19
+ export { default as UI } from './UI';
20
20
 
21
- Object.entries({
22
- ...defaultComponents,
23
- ...options.components,
24
- }).forEach(([name, component]) => UI.registerComponent(name as UIComponent, component));
21
+ export type UIServices = typeof services;
25
22
 
26
- await bootServices(app, services);
23
+ export default definePlugin({
24
+ async install(app, options) {
25
+ const defaultComponents = {
26
+ [UIComponents.AlertModal]: AGAlertModal,
27
+ [UIComponents.ConfirmModal]: AGConfirmModal,
28
+ [UIComponents.ErrorReportModal]: AGErrorReportModal,
29
+ [UIComponents.LoadingModal]: AGLoadingModal,
30
+ [UIComponents.PromptModal]: AGPromptModal,
31
+ [UIComponents.Snackbar]: AGSnackbar,
32
+ [UIComponents.StartupCrash]: AGStartupCrash,
33
+ };
34
+
35
+ Object.entries({
36
+ ...defaultComponents,
37
+ ...options.components,
38
+ }).forEach(([name, component]) => UI.registerComponent(name as UIComponent, component));
39
+
40
+ await bootServices(app, services);
41
+ },
27
42
  });
28
43
 
29
44
  declare module '@/bootstrap/options' {
30
- interface BootstrapOptions {
45
+ export interface AerogelOptions {
31
46
  components?: Partial<Record<UIComponent, Component>>;
32
47
  }
33
48
  }
34
49
 
35
50
  declare module '@/services' {
36
- interface Services extends UIServices {}
51
+ export interface Services extends UIServices {}
37
52
  }
@@ -14,6 +14,7 @@ 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,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
+ }
@@ -0,0 +1,9 @@
1
+ import { noop } from '@noeldemartin/utils';
2
+ import { onMounted, onUnmounted } from 'vue';
3
+
4
+ export function onCleanMounted(operation: () => Function): void {
5
+ let cleanUp: Function = noop;
6
+
7
+ onMounted(() => (cleanUp = operation()));
8
+ onUnmounted(() => cleanUp());
9
+ }
@@ -1 +1,5 @@
1
+ export * from './composition/events';
2
+ export * from './composition/forms';
3
+ export * from './composition/hooks';
4
+ export * from './tailwindcss';
1
5
  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 {
@@ -0,0 +1,26 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { removeInteractiveClasses } from './tailwindcss';
4
+
5
+ describe('TailwindCSS utils', () => {
6
+
7
+ it('Removes interactive classes', () => {
8
+ const cases: [string, string][] = [
9
+ ['text-red hover:text-green', 'text-red'],
10
+ ['text-red hover:text-green text-lg', 'text-red text-lg'],
11
+ [
12
+ `
13
+ text-red text-lg
14
+ focus:text-yellow
15
+ hover:focus:text-black
16
+ `,
17
+ 'text-red text-lg',
18
+ ],
19
+ ];
20
+
21
+ cases.forEach(([original, expected]) => {
22
+ expect(removeInteractiveClasses(original)).toEqual(expected);
23
+ });
24
+ });
25
+
26
+ });
@@ -0,0 +1,7 @@
1
+ export function removeInteractiveClasses(classes: string): string {
2
+ return classes
3
+ .split(/\s+/)
4
+ .filter((className) => !/^(hover|focus|focus-visible):/.test(className))
5
+ .join(' ')
6
+ .trim();
7
+ }
package/src/utils/vue.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import { fail } from '@noeldemartin/utils';
2
- import { inject, reactive, ref } from 'vue';
2
+ import { computed, inject, reactive, ref, watch } 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[]>,
@@ -28,6 +30,15 @@ export function componentRef<T>(): Ref<UnwrapNestedRefs<T> | undefined> {
28
30
  return ref<UnwrapNestedRefs<T>>();
29
31
  }
30
32
 
33
+ export function computedAsync<T>(getter: () => Promise<T>): Ref<T | undefined> {
34
+ const result = ref<T>();
35
+ const asyncValue = computed(getter);
36
+
37
+ watch(asyncValue, async () => (result.value = await asyncValue.value), { immediate: true });
38
+
39
+ return result;
40
+ }
41
+
31
42
  export function defineDirective(directive: Directive): Directive {
32
43
  return directive;
33
44
  }
@@ -62,7 +73,7 @@ export function injectOrFail<T>(key: InjectionKey<T> | string, errorMessage?: st
62
73
  return inject(key) ?? fail(errorMessage ?? `Could not resolve '${key}' injection key`);
63
74
  }
64
75
 
65
- export function mixedProp<T>(type: PropType<T>): OptionalProp<T | null> {
76
+ export function mixedProp<T>(type?: PropType<T>): OptionalProp<T | null> {
66
77
  return {
67
78
  type,
68
79
  default: null,
@@ -106,7 +117,7 @@ export function requiredEnumProp<Enum extends Record<string, unknown>>(
106
117
  };
107
118
  }
108
119
 
109
- export function requiredMixedProp<T>(type: PropType<T>): RequiredProp<T> {
120
+ export function requiredMixedProp<T>(type?: PropType<T>): RequiredProp<T> {
110
121
  return {
111
122
  type,
112
123
  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,15 +1,7 @@
1
1
  {
2
+ "extends": "../../tsconfig.json",
2
3
  "compilerOptions": {
3
- "target": "esnext",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
- "strict": true,
7
- "types": [],
8
- "jsx": "preserve",
9
- "noUncheckedIndexedAccess": true,
10
- "resolveJsonModule": true,
11
- "esModuleInterop": true,
12
- "lib": ["esnext", "dom"],
4
+ "types": ["unplugin-icons/types/vue3", "@aerogel/vite/dist/virtual"],
13
5
  "baseUrl": ".",
14
6
  "paths": {
15
7
  "@/*": ["./src/*"]
package/vite.config.ts CHANGED
@@ -1,17 +1,14 @@
1
- import I18n from '@intlify/unplugin-vue-i18n/vite';
2
- import Vue from '@vitejs/plugin-vue';
1
+ import Aerogel from '@aerogel/vite';
2
+ import Icons from 'unplugin-icons/vite';
3
3
  import { defineConfig } from 'vitest/config';
4
4
  import { resolve } from 'path';
5
5
 
6
- const isTesting = process.env.NODE_ENV === 'test';
7
-
8
6
  export default defineConfig({
9
7
  test: { clearMocks: true },
10
- plugins: [Vue(), I18n({ include: resolve(__dirname, './src/testing/stubs/lang/**/*.yaml') })],
8
+ plugins: [Aerogel(), Icons()],
11
9
  resolve: {
12
10
  alias: {
13
11
  '@': resolve(__dirname, './src'),
14
12
  },
15
13
  },
16
- define: isTesting ? { __AG_BASE_PATH: 'undefined' } : undefined,
17
14
  });
package/.eslintrc.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- extends: ['@noeldemartin/eslint-config-vue'],
3
- };
@@ -1,19 +0,0 @@
1
- import type { App } from 'vue';
2
-
3
- import type { BootstrapOptions } from '@/bootstrap/options';
4
-
5
- const mountedHooks: Function[] = [];
6
-
7
- export type BootstrapHook = (app: App, options: BootstrapOptions) => Promise<void>;
8
-
9
- export function onAppMounted(hook: Function): void {
10
- mountedHooks.push(hook);
11
- }
12
-
13
- export function runAppMountedHooks(): void {
14
- mountedHooks.forEach((hook) => hook());
15
- }
16
-
17
- export function defineBootstrapHook<T extends BootstrapHook>(hook: T): T {
18
- return hook;
19
- }
@@ -1,20 +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 { stringProp } from '@/utils/vue';
10
- import { lang } from '@/lang/helpers';
11
-
12
- const props = defineProps({
13
- langKey: stringProp(),
14
- text: stringProp(),
15
- });
16
-
17
- const markdown = computed(() => props.text ?? (props.langKey && lang(props.langKey)));
18
- const html = computed(() => markdown.value && renderMarkdown(markdown.value));
19
- const root = () => h('div', { class: 'prose', innerHTML: html.value });
20
- </script>
@@ -1,3 +0,0 @@
1
- import AGMarkdown from './AGMarkdown.vue';
2
-
3
- export { AGMarkdown };
@@ -1,5 +0,0 @@
1
- import Lang from '@/lang/Lang';
2
-
3
- export function lang(key: string, parameters: Record<string, unknown> = {}): string {
4
- return Lang.translate(key, parameters);
5
- }
@@ -1,18 +0,0 @@
1
- import { IndexedDBEngine, bootModelsFromViteGlob, setEngine } from 'soukai';
2
-
3
- import { defineBootstrapHook } from '@/bootstrap/hooks';
4
-
5
- export default defineBootstrapHook(async (_, options) => {
6
- if (!options.models) {
7
- return;
8
- }
9
-
10
- setEngine(new IndexedDBEngine());
11
- bootModelsFromViteGlob(options.models);
12
- });
13
-
14
- declare module '@/bootstrap/options' {
15
- interface BootstrapOptions {
16
- models?: Record<string, Record<string, unknown>>;
17
- }
18
- }
@@ -1,33 +0,0 @@
1
- import { createRouter, createWebHistory } from 'vue-router';
2
- import type { Plugin } from 'vue';
3
-
4
- import { defineBootstrapHook } from '@/bootstrap/hooks';
5
-
6
- function createAppRouter(options: { routes: RouteRecordRaw[]; basePath?: string }): Plugin {
7
- return createRouter({
8
- history: createWebHistory(options.basePath),
9
- routes: options.routes,
10
- });
11
- }
12
-
13
- export default defineBootstrapHook(async (app, options) => {
14
- if (!options.routes) {
15
- return;
16
- }
17
-
18
- const plugin = createAppRouter({
19
- routes: options.routes,
20
- basePath: options.basePath ?? __AG_BASE_PATH,
21
- });
22
-
23
- app.use(plugin);
24
- });
25
-
26
- declare module '@/bootstrap/options' {
27
- interface BootstrapOptions {
28
- routes?: RouteRecordRaw[];
29
- basePath?: string;
30
- }
31
- }
32
-
33
- import type { RouteRecordRaw } from 'vue-router';
@@ -1 +0,0 @@
1
- foo: Bar
@@ -1,3 +0,0 @@
1
- import { Model } from 'soukai';
2
-
3
- export default class User extends Model {}