@aerogel/core 0.0.0-next.8ae083000611b11799d37033e9a5250d0d07c324 → 0.0.0-next.8bd66d5f5e264650120ea3cc37519f2409c6cc39
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.
- package/dist/aerogel-core.css +1 -1
- package/dist/aerogel-core.d.ts +250 -57
- package/dist/aerogel-core.js +1530 -1134
- package/dist/aerogel-core.js.map +1 -1
- package/package.json +2 -1
- package/src/components/contracts/AlertModal.ts +11 -0
- package/src/components/contracts/ConfirmModal.ts +3 -1
- package/src/components/contracts/DropdownMenu.ts +6 -1
- package/src/components/contracts/ErrorReportModal.ts +5 -4
- package/src/components/headless/HeadlessInputInput.vue +16 -5
- package/src/components/headless/HeadlessSwitch.vue +96 -0
- package/src/components/headless/index.ts +1 -0
- package/src/components/ui/AdvancedOptions.vue +1 -1
- package/src/components/ui/AlertModal.vue +5 -2
- package/src/components/ui/Button.vue +23 -6
- package/src/components/ui/ConfirmModal.vue +7 -2
- package/src/components/ui/DropdownMenuOption.vue +12 -4
- package/src/components/ui/DropdownMenuOptions.vue +18 -1
- package/src/components/ui/ErrorLogs.vue +19 -0
- package/src/components/ui/ErrorLogsModal.vue +48 -0
- package/src/components/ui/ErrorReportModal.vue +12 -6
- package/src/components/ui/Input.vue +2 -2
- package/src/components/ui/Markdown.vue +13 -1
- package/src/components/ui/Modal.vue +18 -9
- package/src/components/ui/SelectLabel.vue +5 -1
- package/src/components/ui/Setting.vue +31 -0
- package/src/components/ui/Switch.vue +11 -0
- package/src/components/ui/TextArea.vue +56 -0
- package/src/components/ui/Toast.vue +16 -14
- package/src/components/ui/index.ts +5 -0
- package/src/directives/measure.ts +11 -5
- package/src/errors/Errors.ts +17 -6
- package/src/errors/index.ts +6 -2
- package/src/errors/settings/Debug.vue +32 -0
- package/src/errors/settings/index.ts +10 -0
- package/src/forms/FormController.ts +4 -0
- package/src/index.css +3 -0
- package/src/lang/index.ts +1 -1
- package/src/lang/settings/Language.vue +1 -1
- package/src/services/index.ts +2 -2
- package/src/testing/index.ts +4 -0
- package/src/ui/UI.ts +20 -4
- package/src/utils/classes.ts +9 -17
- package/src/utils/markdown.ts +35 -1
- package/src/utils/vue.ts +6 -1
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
9
|
import { computed } from 'vue';
|
|
10
|
+
import type { HTMLAttributes } from 'vue';
|
|
10
11
|
|
|
11
12
|
import HeadlessSelectLabel from '@aerogel/core/components/headless/HeadlessSelectLabel.vue';
|
|
12
13
|
import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
|
|
13
14
|
import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
|
|
14
15
|
|
|
16
|
+
const { class: rootClasses } = defineProps<{ class?: HTMLAttributes['class'] }>();
|
|
17
|
+
|
|
15
18
|
const select = injectReactiveOrFail<SelectExpose>('select', '<SelectLabel> must be a child of a <Select>');
|
|
16
|
-
const renderedClasses = computed(() =>
|
|
19
|
+
const renderedClasses = computed(() =>
|
|
20
|
+
classes('block text-sm leading-6 font-medium text-gray-900', select.labelClass, rootClasses));
|
|
17
21
|
</script>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="mt-4 flex" :class="{ 'flex-col': layout === 'vertical' }">
|
|
3
|
+
<div class="flex-grow">
|
|
4
|
+
<h3 :id="titleId" class="text-base font-semibold">
|
|
5
|
+
{{ title }}
|
|
6
|
+
</h3>
|
|
7
|
+
<Markdown v-if="description" :text="description" class="mt-1 text-sm text-gray-500" />
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div :class="renderedRootClass">
|
|
11
|
+
<slot />
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import { computed } from 'vue';
|
|
18
|
+
import type { HTMLAttributes } from 'vue';
|
|
19
|
+
|
|
20
|
+
import Markdown from '@aerogel/core/components/ui/Markdown.vue';
|
|
21
|
+
import { classes } from '@aerogel/core/utils';
|
|
22
|
+
|
|
23
|
+
const { layout = 'horizontal', class: rootClass } = defineProps<{
|
|
24
|
+
title: string;
|
|
25
|
+
titleId?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
class?: HTMLAttributes['class'];
|
|
28
|
+
layout?: 'vertical' | 'horizontal';
|
|
29
|
+
}>();
|
|
30
|
+
const renderedRootClass = computed(() => classes(rootClass, 'flex flex-col justify-center gap-1'));
|
|
31
|
+
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<HeadlessSwitch
|
|
3
|
+
class="flex flex-row items-center gap-1"
|
|
4
|
+
input-class="disabled:opacity-50 disabled:cursor-not-allowed data-[state=checked]:bg-primary-600 data-[state=unchecked]:bg-gray-200 relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focusdisabled:opacity-50 disabled:cursor-not-allowed :ring-2 focus:ring-primary-600 focus:ring-offset-2 focus:outline-hidden"
|
|
5
|
+
thumb-class="data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0 pointer-events-none inline-block size-5 transform rounded-full bg-white shadow-sm ring-0 transition duration-200 ease-in-out"
|
|
6
|
+
/>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
import HeadlessSwitch from '@aerogel/core/components/headless/HeadlessSwitch.vue';
|
|
11
|
+
</script>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<HeadlessInput
|
|
3
|
+
ref="$inputRef"
|
|
4
|
+
:label="label"
|
|
5
|
+
:class="rootClasses"
|
|
6
|
+
v-bind="props"
|
|
7
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
8
|
+
>
|
|
9
|
+
<HeadlessInputLabel class="block text-sm leading-6 font-medium text-gray-900" />
|
|
10
|
+
<div :class="renderedWrapperClasses">
|
|
11
|
+
<HeadlessInputTextArea v-bind="inputAttrs" :class="renderedInputClasses" />
|
|
12
|
+
<div v-if="$input?.errors" class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
|
|
13
|
+
<IconExclamationSolid class="size-5 text-red-500" />
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
<HeadlessInputDescription class="mt-2 text-sm text-gray-600" />
|
|
17
|
+
<HeadlessInputError class="mt-2 text-sm text-red-600" />
|
|
18
|
+
</HeadlessInput>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import IconExclamationSolid from '~icons/zondicons/exclamation-solid';
|
|
23
|
+
|
|
24
|
+
import { computed, useTemplateRef } from 'vue';
|
|
25
|
+
import type { HTMLAttributes } from 'vue';
|
|
26
|
+
|
|
27
|
+
import HeadlessInput from '@aerogel/core/components/headless/HeadlessInput.vue';
|
|
28
|
+
import HeadlessInputLabel from '@aerogel/core/components/headless/HeadlessInputLabel.vue';
|
|
29
|
+
import HeadlessInputTextArea from '@aerogel/core/components/headless/HeadlessInputTextArea.vue';
|
|
30
|
+
import HeadlessInputDescription from '@aerogel/core/components/headless/HeadlessInputDescription.vue';
|
|
31
|
+
import HeadlessInputError from '@aerogel/core/components/headless/HeadlessInputError.vue';
|
|
32
|
+
import { classes } from '@aerogel/core/utils/classes';
|
|
33
|
+
import { useInputAttrs } from '@aerogel/core/utils/composition/forms';
|
|
34
|
+
import type { InputEmits, InputProps } from '@aerogel/core/components/contracts/Input';
|
|
35
|
+
|
|
36
|
+
defineOptions({ inheritAttrs: false });
|
|
37
|
+
defineEmits<InputEmits>();
|
|
38
|
+
const { label, inputClass, wrapperClass, ...props } = defineProps<
|
|
39
|
+
InputProps & { inputClass?: HTMLAttributes['class']; wrapperClass?: HTMLAttributes['class'] }
|
|
40
|
+
>();
|
|
41
|
+
const $input = useTemplateRef('$inputRef');
|
|
42
|
+
const [inputAttrs, rootClasses] = useInputAttrs();
|
|
43
|
+
const renderedWrapperClasses = computed(() =>
|
|
44
|
+
classes('relative rounded-md shadow-2xs', { 'mt-1': label }, wrapperClass));
|
|
45
|
+
const renderedInputClasses = computed(() =>
|
|
46
|
+
classes(
|
|
47
|
+
// eslint-disable-next-line vue/max-len
|
|
48
|
+
'block w-full rounded-md border-0 py-1.5 ring-1 ring-inset focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6',
|
|
49
|
+
{
|
|
50
|
+
'focus:ring-primary-600': !$input.value?.errors,
|
|
51
|
+
'text-gray-900 shadow-2xs ring-gray-900/10 placeholder:text-gray-400': !$input.value?.errors,
|
|
52
|
+
'pr-10 text-red-900 ring-red-900/10 placeholder:text-red-300 focus:ring-red-500': $input.value?.errors,
|
|
53
|
+
},
|
|
54
|
+
inputClass,
|
|
55
|
+
));
|
|
56
|
+
</script>
|
|
@@ -13,32 +13,34 @@
|
|
|
13
13
|
</template>
|
|
14
14
|
|
|
15
15
|
<script setup lang="ts">
|
|
16
|
+
import { computed } from 'vue';
|
|
16
17
|
import type { HTMLAttributes } from 'vue';
|
|
17
18
|
|
|
18
19
|
import Button from '@aerogel/core/components/ui/Button.vue';
|
|
19
20
|
import Markdown from '@aerogel/core/components/ui/Markdown.vue';
|
|
20
21
|
import HeadlessToast from '@aerogel/core/components/headless/HeadlessToast.vue';
|
|
21
22
|
import HeadlessToastAction from '@aerogel/core/components/headless/HeadlessToastAction.vue';
|
|
22
|
-
import {
|
|
23
|
+
import { variantClasses } from '@aerogel/core/utils/classes';
|
|
23
24
|
import type { ToastExpose, ToastProps } from '@aerogel/core/components/contracts/Toast';
|
|
24
25
|
import type { Variants } from '@aerogel/core/utils/classes';
|
|
25
26
|
|
|
26
27
|
const { class: baseClasses, variant = 'secondary' } = defineProps<ToastProps & { class?: HTMLAttributes['class'] }>();
|
|
27
|
-
const renderedClasses =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
const renderedClasses = computed(() =>
|
|
29
|
+
variantClasses<Variants<Pick<ToastProps, 'variant'>>>(
|
|
30
|
+
{ baseClasses, variant },
|
|
31
|
+
{
|
|
32
|
+
baseClasses: 'flex items-center gap-2 rounded-md p-2 ring-1 shadow-lg border-gray-200',
|
|
33
|
+
variants: {
|
|
34
|
+
variant: {
|
|
35
|
+
secondary: 'bg-gray-900 text-white ring-black',
|
|
36
|
+
danger: 'bg-red-50 text-red-900 ring-red-100',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
defaultVariants: {
|
|
40
|
+
variant: 'secondary',
|
|
35
41
|
},
|
|
36
42
|
},
|
|
37
|
-
|
|
38
|
-
variant: 'secondary',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
);
|
|
43
|
+
));
|
|
42
44
|
|
|
43
45
|
defineExpose<ToastExpose>();
|
|
44
46
|
</script>
|
|
@@ -7,6 +7,8 @@ export { default as DropdownMenu } from './DropdownMenu.vue';
|
|
|
7
7
|
export { default as DropdownMenuOption } from './DropdownMenuOption.vue';
|
|
8
8
|
export { default as DropdownMenuOptions } from './DropdownMenuOptions.vue';
|
|
9
9
|
export { default as EditableContent } from './EditableContent.vue';
|
|
10
|
+
export { default as ErrorLogs } from './ErrorLogs.vue';
|
|
11
|
+
export { default as ErrorLogsModal } from './ErrorLogsModal.vue';
|
|
10
12
|
export { default as ErrorMessage } from './ErrorMessage.vue';
|
|
11
13
|
export { default as ErrorReportModal } from './ErrorReportModal.vue';
|
|
12
14
|
export { default as ErrorReportModalButtons } from './ErrorReportModalButtons.vue';
|
|
@@ -25,6 +27,9 @@ export { default as SelectLabel } from './SelectLabel.vue';
|
|
|
25
27
|
export { default as SelectOption } from './SelectOption.vue';
|
|
26
28
|
export { default as SelectOptions } from './SelectOptions.vue';
|
|
27
29
|
export { default as SelectTrigger } from './SelectTrigger.vue';
|
|
30
|
+
export { default as Setting } from './Setting.vue';
|
|
28
31
|
export { default as SettingsModal } from './SettingsModal.vue';
|
|
29
32
|
export { default as StartupCrash } from './StartupCrash.vue';
|
|
33
|
+
export { default as Switch } from './Switch.vue';
|
|
34
|
+
export { default as TextArea } from './TextArea.vue';
|
|
30
35
|
export { default as Toast } from './Toast.vue';
|
|
@@ -3,6 +3,15 @@ import { tap } from '@noeldemartin/utils';
|
|
|
3
3
|
|
|
4
4
|
const resizeObservers: WeakMap<HTMLElement, ResizeObserver> = new WeakMap();
|
|
5
5
|
|
|
6
|
+
export type MeasureDirectiveValue =
|
|
7
|
+
| MeasureDirectiveListener
|
|
8
|
+
| {
|
|
9
|
+
css?: boolean;
|
|
10
|
+
watch?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type MeasureDirectiveModifiers = 'css' | 'watch';
|
|
14
|
+
|
|
6
15
|
export interface ElementSize {
|
|
7
16
|
width: number;
|
|
8
17
|
height: number;
|
|
@@ -10,11 +19,8 @@ export interface ElementSize {
|
|
|
10
19
|
|
|
11
20
|
export type MeasureDirectiveListener = (size: ElementSize) => unknown;
|
|
12
21
|
|
|
13
|
-
export default defineDirective({
|
|
14
|
-
mounted(element: HTMLElement, { value }) {
|
|
15
|
-
// TODO replace with argument when typed properly
|
|
16
|
-
const modifiers = { css: true, watch: true };
|
|
17
|
-
|
|
22
|
+
export default defineDirective<MeasureDirectiveValue, MeasureDirectiveModifiers>({
|
|
23
|
+
mounted(element: HTMLElement, { value, modifiers }) {
|
|
18
24
|
const listener = typeof value === 'function' ? (value as MeasureDirectiveListener) : null;
|
|
19
25
|
const update = () => {
|
|
20
26
|
const sizes = element.getBoundingClientRect();
|
package/src/errors/Errors.ts
CHANGED
|
@@ -22,16 +22,23 @@ export class ErrorsService extends Service {
|
|
|
22
22
|
this.enabled = false;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public async inspect(error: ErrorSource | ErrorReport[]): Promise<void
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
25
|
+
public async inspect(error: ErrorSource | ErrorReport, reports?: ErrorReport[]): Promise<void>;
|
|
26
|
+
public async inspect(reports: ErrorReport[]): Promise<void>;
|
|
27
|
+
public async inspect(errorOrReports: ErrorSource | ErrorReport[], _reports?: ErrorReport[]): Promise<void> {
|
|
28
|
+
if (Array.isArray(errorOrReports) && errorOrReports.length === 0) {
|
|
29
29
|
UI.alert(translateWithDefault('errors.inspectEmpty', 'Nothing to inspect!'));
|
|
30
30
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
const report = Array.isArray(errorOrReports)
|
|
35
|
+
? (errorOrReports[0] as ErrorReport)
|
|
36
|
+
: this.isErrorReport(errorOrReports)
|
|
37
|
+
? errorOrReports
|
|
38
|
+
: await this.createErrorReport(errorOrReports);
|
|
39
|
+
const reports = Array.isArray(errorOrReports) ? (errorOrReports as ErrorReport[]) : (_reports ?? [report]);
|
|
40
|
+
|
|
41
|
+
UI.modal(UI.requireComponent('error-report-modal'), { report, reports });
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
public async report(error: ErrorSource, message?: string): Promise<void> {
|
|
@@ -75,7 +82,7 @@ export class ErrorsService extends Service {
|
|
|
75
82
|
{
|
|
76
83
|
label: translateWithDefault('errors.viewDetails', 'View details'),
|
|
77
84
|
dismiss: true,
|
|
78
|
-
click: () => UI.modal(UI.requireComponent('error-report-modal'), { reports: [report] }),
|
|
85
|
+
click: () => UI.modal(UI.requireComponent('error-report-modal'), { report, reports: [report] }),
|
|
79
86
|
},
|
|
80
87
|
],
|
|
81
88
|
},
|
|
@@ -117,6 +124,10 @@ export class ErrorsService extends Service {
|
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
126
|
|
|
127
|
+
private isErrorReport(error: unknown): error is ErrorReport {
|
|
128
|
+
return isObject(error) && 'title' in error;
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
private async createErrorReport(error: ErrorSource): Promise<ErrorReport> {
|
|
121
132
|
if (typeof error === 'string') {
|
|
122
133
|
return { title: error };
|
package/src/errors/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { App } from 'vue';
|
|
1
|
+
import type { App as AppInstance } from 'vue';
|
|
2
2
|
|
|
3
|
+
import App from '@aerogel/core/services/App';
|
|
3
4
|
import { bootServices } from '@aerogel/core/services';
|
|
4
5
|
import { definePlugin } from '@aerogel/core/plugins';
|
|
5
6
|
|
|
6
7
|
import Errors from './Errors';
|
|
8
|
+
import settings from './settings';
|
|
7
9
|
import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
|
|
8
10
|
|
|
9
11
|
export * from './utils';
|
|
@@ -19,7 +21,7 @@ const frameworkHandler: ErrorHandler = (error) => {
|
|
|
19
21
|
return true;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
function setUpErrorHandler(app:
|
|
24
|
+
function setUpErrorHandler(app: AppInstance, baseHandler: ErrorHandler = () => false): void {
|
|
23
25
|
const errorHandler: ErrorHandler = (error) => baseHandler(error) || frameworkHandler(error);
|
|
24
26
|
|
|
25
27
|
app.config.errorHandler = errorHandler;
|
|
@@ -34,6 +36,8 @@ export default definePlugin({
|
|
|
34
36
|
async install(app, options) {
|
|
35
37
|
setUpErrorHandler(app, options.handleError);
|
|
36
38
|
|
|
39
|
+
settings.forEach((setting) => App.addSetting(setting));
|
|
40
|
+
|
|
37
41
|
await bootServices(app, services);
|
|
38
42
|
},
|
|
39
43
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Setting
|
|
3
|
+
title-id="debug-setting"
|
|
4
|
+
:title="$td('settings.debug', 'Debugging')"
|
|
5
|
+
:description="$td('settings.debugDescription', 'Enable debugging with [Eruda](https://eruda.liriliri.io/).')"
|
|
6
|
+
>
|
|
7
|
+
<Switch v-model="enabled" aria-labelledby="debug-setting" />
|
|
8
|
+
</Setting>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { ref, watchEffect } from 'vue';
|
|
13
|
+
import type Eruda from 'eruda';
|
|
14
|
+
|
|
15
|
+
import Setting from '@aerogel/core/components/ui/Setting.vue';
|
|
16
|
+
import Switch from '@aerogel/core/components/ui/Switch.vue';
|
|
17
|
+
|
|
18
|
+
let eruda: typeof Eruda | null = null;
|
|
19
|
+
const enabled = ref(false);
|
|
20
|
+
|
|
21
|
+
watchEffect(async () => {
|
|
22
|
+
if (!enabled.value) {
|
|
23
|
+
eruda?.destroy();
|
|
24
|
+
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
eruda ??= (await import('eruda')).default;
|
|
29
|
+
|
|
30
|
+
eruda.init();
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
@@ -109,6 +109,10 @@ export default class FormController<Fields extends FormFieldDefinitions = FormFi
|
|
|
109
109
|
return this._fields[field]?.rules?.split('|') ?? [];
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
public getFieldType<T extends keyof Fields>(field: T): FormFieldType | null {
|
|
113
|
+
return this._fields[field]?.type ?? null;
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
public data(): FormData<Fields> {
|
|
113
117
|
return { ...this._data };
|
|
114
118
|
}
|
package/src/index.css
CHANGED
package/src/lang/index.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { definePlugin } from '@aerogel/core/plugins';
|
|
|
4
4
|
|
|
5
5
|
import Lang from './Lang';
|
|
6
6
|
import settings from './settings';
|
|
7
|
-
import type { LangProvider } from './Lang';
|
|
8
7
|
import { translate, translateWithDefault } from './utils';
|
|
8
|
+
import type { LangProvider } from './Lang';
|
|
9
9
|
|
|
10
10
|
export { Lang, translate, translateWithDefault };
|
|
11
11
|
export type { LangProvider };
|
package/src/services/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { App as
|
|
1
|
+
import type { App as AppInstance } from 'vue';
|
|
2
2
|
|
|
3
3
|
import { definePlugin } from '@aerogel/core/plugins';
|
|
4
4
|
import { isDevelopment, isTesting } from '@noeldemartin/utils';
|
|
@@ -30,7 +30,7 @@ export type DefaultServices = typeof defaultServices;
|
|
|
30
30
|
|
|
31
31
|
export interface Services extends DefaultServices {}
|
|
32
32
|
|
|
33
|
-
export async function bootServices(app:
|
|
33
|
+
export async function bootServices(app: AppInstance, services: Record<string, Service>): Promise<void> {
|
|
34
34
|
await Promise.all(
|
|
35
35
|
Object.entries(services).map(async ([name, service]) => {
|
|
36
36
|
await service
|
package/src/testing/index.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { isTesting } from '@noeldemartin/utils';
|
|
|
2
2
|
import type { GetClosureArgs } from '@noeldemartin/utils';
|
|
3
3
|
|
|
4
4
|
import Events from '@aerogel/core/services/Events';
|
|
5
|
+
import { App } from '@aerogel/core/services';
|
|
5
6
|
import { definePlugin } from '@aerogel/core/plugins';
|
|
7
|
+
import type { Services } from '@aerogel/core/services';
|
|
6
8
|
|
|
7
9
|
export interface AerogelTestingRuntime {
|
|
8
10
|
on: (typeof Events)['on'];
|
|
11
|
+
service<T extends keyof Services>(name: T): Services[T] | null;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export default definePlugin({
|
|
@@ -16,6 +19,7 @@ export default definePlugin({
|
|
|
16
19
|
|
|
17
20
|
globalThis.testingRuntime = {
|
|
18
21
|
on: ((...args: GetClosureArgs<(typeof Events)['on']>) => Events.on(...args)) as (typeof Events)['on'],
|
|
22
|
+
service: (name) => App.service(name),
|
|
19
23
|
};
|
|
20
24
|
},
|
|
21
25
|
});
|
package/src/ui/UI.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { after, facade, fail, isDevelopment, required, uuid } from '@noeldemartin/utils';
|
|
2
|
-
import { markRaw, nextTick } from 'vue';
|
|
2
|
+
import { markRaw, nextTick, unref } from 'vue';
|
|
3
3
|
import type { ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
|
|
4
4
|
import type { Component } from 'vue';
|
|
5
5
|
import type { ClosureArgs } from '@noeldemartin/utils';
|
|
@@ -64,6 +64,7 @@ export type LoadingOptions = AcceptRefs<{
|
|
|
64
64
|
title?: string;
|
|
65
65
|
message?: string;
|
|
66
66
|
progress?: number;
|
|
67
|
+
delay?: number;
|
|
67
68
|
}>;
|
|
68
69
|
|
|
69
70
|
export interface ConfirmOptionsWithCheckboxes<T extends ConfirmModalCheckboxes = ConfirmModalCheckboxes>
|
|
@@ -218,7 +219,11 @@ export class UIService extends Service {
|
|
|
218
219
|
operation?: Promise<T> | (() => T),
|
|
219
220
|
): Promise<T> {
|
|
220
221
|
const processOperation = (o: Promise<T> | (() => T)) => (typeof o === 'function' ? Promise.resolve(o()) : o);
|
|
221
|
-
const processArgs = (): {
|
|
222
|
+
const processArgs = (): {
|
|
223
|
+
operationPromise: Promise<T>;
|
|
224
|
+
props?: AcceptRefs<LoadingModalProps>;
|
|
225
|
+
delay?: number;
|
|
226
|
+
} => {
|
|
222
227
|
if (typeof operationOrMessageOrOptions === 'string') {
|
|
223
228
|
return {
|
|
224
229
|
props: { message: operationOrMessageOrOptions },
|
|
@@ -230,13 +235,24 @@ export class UIService extends Service {
|
|
|
230
235
|
return { operationPromise: processOperation(operationOrMessageOrOptions) };
|
|
231
236
|
}
|
|
232
237
|
|
|
238
|
+
const { delay, ...props } = operationOrMessageOrOptions;
|
|
239
|
+
|
|
233
240
|
return {
|
|
234
|
-
props
|
|
241
|
+
props,
|
|
242
|
+
delay: unref(delay),
|
|
235
243
|
operationPromise: processOperation(operation as Promise<T> | (() => T)),
|
|
236
244
|
};
|
|
237
245
|
};
|
|
238
246
|
|
|
239
|
-
|
|
247
|
+
let delayed = false;
|
|
248
|
+
const { operationPromise, props, delay } = processArgs();
|
|
249
|
+
|
|
250
|
+
delay && (await Promise.race([after({ ms: delay }).then(() => (delayed = true)), operationPromise]));
|
|
251
|
+
|
|
252
|
+
if (delay && !delayed) {
|
|
253
|
+
return operationPromise;
|
|
254
|
+
}
|
|
255
|
+
|
|
240
256
|
const modal = await this.modal(this.requireComponent('loading-modal'), props);
|
|
241
257
|
|
|
242
258
|
try {
|
package/src/utils/classes.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import {
|
|
2
|
+
import { unref } from 'vue';
|
|
3
3
|
import { cva } from 'class-variance-authority';
|
|
4
4
|
import { twMerge } from 'tailwind-merge';
|
|
5
5
|
import type { ClassValue } from 'clsx';
|
|
6
|
-
import type {
|
|
6
|
+
import type { PropType } from 'vue';
|
|
7
7
|
import type { GetClosureArgs, GetClosureResult } from '@noeldemartin/utils';
|
|
8
8
|
|
|
9
9
|
export type CVAConfig<T> = NonNullable<GetClosureArgs<typeof cva<T>>[1]>;
|
|
10
10
|
export type CVAProps<T> = NonNullable<GetClosureArgs<GetClosureResult<typeof cva<T>>>[0]>;
|
|
11
|
-
export type RefsObject<T> = { [K in keyof T]: Ref<T[K]> | T[K] };
|
|
12
11
|
export type Variants<T extends Record<string, string | boolean>> = Required<{
|
|
13
12
|
[K in keyof T]: Exclude<T[K], undefined> extends string
|
|
14
13
|
? { [key in Exclude<T[K], undefined>]: string | null }
|
|
@@ -26,22 +25,15 @@ export type PickComponentProps<TValues, TDefinitions> = {
|
|
|
26
25
|
[K in keyof TValues]: K extends keyof TDefinitions ? TValues[K] : never;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
|
-
export function
|
|
30
|
-
value:
|
|
28
|
+
export function variantClasses<T>(
|
|
29
|
+
value: { baseClasses?: string } & CVAProps<T>,
|
|
31
30
|
config: { baseClasses?: string } & CVAConfig<T>,
|
|
32
|
-
):
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const variants = cva(configBaseClasses, configs as CVAConfig<T>);
|
|
37
|
-
const values = Object.entries(valueRefs).reduce((extractedValues, [name, valueRef]) => {
|
|
38
|
-
extractedValues[name as keyof CVAProps<T>] = unref(valueRef);
|
|
31
|
+
): string {
|
|
32
|
+
const { baseClasses: valueBaseClasses, ...values } = value;
|
|
33
|
+
const { baseClasses: configBaseClasses, ...configs } = config;
|
|
34
|
+
const variants = cva(configBaseClasses, configs as CVAConfig<T>);
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
}, {} as CVAProps<T>);
|
|
42
|
-
|
|
43
|
-
return classes(variants(values), unref(valueBaseClasses));
|
|
44
|
-
});
|
|
36
|
+
return classes(variants(values as CVAProps<T>), unref(valueBaseClasses));
|
|
45
37
|
}
|
|
46
38
|
|
|
47
39
|
export function classes(...inputs: ClassValue[]): string {
|
package/src/utils/markdown.ts
CHANGED
|
@@ -2,10 +2,18 @@ import DOMPurify from 'dompurify';
|
|
|
2
2
|
import { stringMatchAll, tap } from '@noeldemartin/utils';
|
|
3
3
|
import { Renderer, marked } from 'marked';
|
|
4
4
|
|
|
5
|
+
let router: MarkdownRouter | null = null;
|
|
6
|
+
|
|
5
7
|
function makeRenderer(): Renderer {
|
|
6
8
|
return tap(new Renderer(), (renderer) => {
|
|
7
9
|
renderer.link = function(link) {
|
|
8
|
-
|
|
10
|
+
const defaultLink = Renderer.prototype.link.apply(this, [link]);
|
|
11
|
+
|
|
12
|
+
if (!link.href.startsWith('#')) {
|
|
13
|
+
return defaultLink.replace('<a', '<a target="_blank"');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return defaultLink;
|
|
9
17
|
};
|
|
10
18
|
});
|
|
11
19
|
}
|
|
@@ -20,11 +28,37 @@ function renderActionLinks(html: string): string {
|
|
|
20
28
|
return html;
|
|
21
29
|
}
|
|
22
30
|
|
|
31
|
+
function renderRouteLinks(html: string): string {
|
|
32
|
+
const matches = stringMatchAll<3>(html, /<a[^>]*href="#route:([^"]+)"[^>]*>([^<]+)<\/a>/g);
|
|
33
|
+
|
|
34
|
+
for (const [link, route, text] of matches) {
|
|
35
|
+
const url = router?.resolve(route) ?? route;
|
|
36
|
+
|
|
37
|
+
html = html.replace(link, `<a data-markdown-route="${route}" href="${url}">${text}</a>`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return html;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface MarkdownRouter {
|
|
44
|
+
resolve(route: string): string;
|
|
45
|
+
visit(route: string): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getMarkdownRouter(): MarkdownRouter | null {
|
|
49
|
+
return router;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function setMarkdownRouter(markdownRouter: MarkdownRouter): void {
|
|
53
|
+
router = markdownRouter;
|
|
54
|
+
}
|
|
55
|
+
|
|
23
56
|
export function renderMarkdown(markdown: string): string {
|
|
24
57
|
let html = marked(markdown, { renderer: makeRenderer(), async: false });
|
|
25
58
|
|
|
26
59
|
html = safeHtml(html);
|
|
27
60
|
html = renderActionLinks(html);
|
|
61
|
+
html = renderRouteLinks(html);
|
|
28
62
|
|
|
29
63
|
return html;
|
|
30
64
|
}
|
package/src/utils/vue.ts
CHANGED
|
@@ -12,7 +12,12 @@ function renderVNodeAttrs(node: VNode): string {
|
|
|
12
12
|
}, '');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
export function defineDirective<TValue = any, TModifiers extends string = string>(
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
directive: Directive<any, TValue, TModifiers>,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
): Directive<any, TValue, TModifiers> {
|
|
16
21
|
return directive;
|
|
17
22
|
}
|
|
18
23
|
|