@aerogel/core 0.0.0-next.e4c0d5bd2801fbe93545477ea515af53df69b522 → 0.0.0-next.ec720bb060627e76b204dc15f6bf955d11a77cbc
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.d.ts +98 -31
- package/dist/aerogel-core.js +1261 -1089
- package/dist/aerogel-core.js.map +1 -1
- package/package.json +2 -1
- package/src/components/headless/HeadlessInputInput.vue +2 -2
- package/src/components/headless/HeadlessSwitch.vue +96 -0
- package/src/components/headless/index.ts +1 -0
- package/src/components/ui/Button.vue +15 -0
- package/src/components/ui/Modal.vue +12 -4
- 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/index.ts +2 -0
- 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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerogel/core",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.ec720bb060627e76b204dc15f6bf955d11a77cbc",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"class-variance-authority": "^0.7.1",
|
|
34
34
|
"clsx": "^2.1.1",
|
|
35
35
|
"dompurify": "^3.2.4",
|
|
36
|
+
"eruda": "^3.4.1",
|
|
36
37
|
"marked": "^15.0.7",
|
|
37
38
|
"pinia": "^2.1.6",
|
|
38
39
|
"reka-ui": "^2.2.0",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="rootClass">
|
|
3
|
+
<label v-if="label" :for="expose.id" :class="labelClass">
|
|
4
|
+
{{ label }}
|
|
5
|
+
</label>
|
|
6
|
+
<SwitchRoot
|
|
7
|
+
:id="expose.id"
|
|
8
|
+
:name
|
|
9
|
+
:model-value="expose.value.value"
|
|
10
|
+
v-bind="$attrs"
|
|
11
|
+
:class="inputClass"
|
|
12
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
13
|
+
>
|
|
14
|
+
<SwitchThumb :class="thumbClass" />
|
|
15
|
+
</SwitchRoot>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts" generic="T extends boolean = boolean">
|
|
20
|
+
import { SwitchRoot, SwitchThumb } from 'reka-ui';
|
|
21
|
+
import { computed, inject, readonly, watchEffect } from 'vue';
|
|
22
|
+
import { uuid } from '@noeldemartin/utils';
|
|
23
|
+
import type { HTMLAttributes } from 'vue';
|
|
24
|
+
|
|
25
|
+
import type FormController from '@aerogel/core/forms/FormController';
|
|
26
|
+
import type { FormFieldValue } from '@aerogel/core/forms/FormController';
|
|
27
|
+
import type { InputEmits, InputExpose, InputProps } from '@aerogel/core/components/contracts/Input';
|
|
28
|
+
|
|
29
|
+
defineOptions({ inheritAttrs: false });
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
name,
|
|
33
|
+
label,
|
|
34
|
+
description,
|
|
35
|
+
modelValue,
|
|
36
|
+
class: rootClass,
|
|
37
|
+
} = defineProps<
|
|
38
|
+
InputProps<T> & {
|
|
39
|
+
class?: HTMLAttributes['class'];
|
|
40
|
+
labelClass?: HTMLAttributes['class'];
|
|
41
|
+
inputClass?: HTMLAttributes['class'];
|
|
42
|
+
thumbClass?: HTMLAttributes['class'];
|
|
43
|
+
}
|
|
44
|
+
>();
|
|
45
|
+
const emit = defineEmits<InputEmits>();
|
|
46
|
+
const form = inject<FormController | null>('form', null);
|
|
47
|
+
const errors = computed(() => {
|
|
48
|
+
if (!form || !name) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return form.errors[name] ?? null;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const expose = {
|
|
56
|
+
id: `switch-${uuid()}`,
|
|
57
|
+
name: computed(() => name),
|
|
58
|
+
label: computed(() => label),
|
|
59
|
+
description: computed(() => description),
|
|
60
|
+
value: computed(() => {
|
|
61
|
+
if (form && name) {
|
|
62
|
+
return form.getFieldValue(name) as boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return modelValue;
|
|
66
|
+
}),
|
|
67
|
+
errors: readonly(errors),
|
|
68
|
+
required: computed(() => {
|
|
69
|
+
if (!name || !form) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return form.getFieldRules(name).includes('required');
|
|
74
|
+
}),
|
|
75
|
+
update(value) {
|
|
76
|
+
if (form && name) {
|
|
77
|
+
form.setFieldValue(name, value as FormFieldValue);
|
|
78
|
+
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
emit('update:modelValue', value);
|
|
83
|
+
},
|
|
84
|
+
} satisfies InputExpose;
|
|
85
|
+
|
|
86
|
+
defineExpose(expose);
|
|
87
|
+
|
|
88
|
+
watchEffect(() => {
|
|
89
|
+
if (!description && !errors.value) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// eslint-disable-next-line no-console
|
|
94
|
+
console.warn('Errors and description not implemented in <HeadlessSwitch>');
|
|
95
|
+
});
|
|
96
|
+
</script>
|
|
@@ -16,4 +16,5 @@ export { default as HeadlessSelectOption } from './HeadlessSelectOption.vue';
|
|
|
16
16
|
export { default as HeadlessSelectOptions } from './HeadlessSelectOptions.vue';
|
|
17
17
|
export { default as HeadlessSelectTrigger } from './HeadlessSelectTrigger.vue';
|
|
18
18
|
export { default as HeadlessSelectValue } from './HeadlessSelectValue.vue';
|
|
19
|
+
export { default as HeadlessSwitch } from './HeadlessSwitch.vue';
|
|
19
20
|
export { default as HeadlessToast } from './HeadlessToast.vue';
|
|
@@ -88,6 +88,21 @@ const renderedClasses = computed(() => variantClasses<Variants<Pick<ButtonProps,
|
|
|
88
88
|
disabled: false,
|
|
89
89
|
class: 'hover:underline',
|
|
90
90
|
},
|
|
91
|
+
{
|
|
92
|
+
variant: 'link',
|
|
93
|
+
size: 'small',
|
|
94
|
+
class: 'leading-6',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
variant: 'link',
|
|
98
|
+
size: 'default',
|
|
99
|
+
class: 'leading-8',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
variant: 'link',
|
|
103
|
+
size: 'large',
|
|
104
|
+
class: 'leading-10',
|
|
105
|
+
},
|
|
91
106
|
],
|
|
92
107
|
defaultVariants: {
|
|
93
108
|
variant: 'default',
|
|
@@ -27,14 +27,22 @@
|
|
|
27
27
|
|
|
28
28
|
<HeadlessModalTitle
|
|
29
29
|
v-if="title"
|
|
30
|
-
class="px-4 pt-5
|
|
31
|
-
:class="{
|
|
30
|
+
class="px-4 pt-5 text-base font-semibold text-gray-900"
|
|
31
|
+
:class="{
|
|
32
|
+
'sr-only': titleHidden,
|
|
33
|
+
'pb-0': description && !descriptionHidden,
|
|
34
|
+
'pb-2': !description || descriptionHidden,
|
|
35
|
+
}"
|
|
32
36
|
>
|
|
33
37
|
<Markdown :text="title" inline />
|
|
34
38
|
</HeadlessModalTitle>
|
|
35
39
|
|
|
36
|
-
<HeadlessModalDescription
|
|
37
|
-
|
|
40
|
+
<HeadlessModalDescription
|
|
41
|
+
v-if="description"
|
|
42
|
+
class="px-4 pt-1 pb-2"
|
|
43
|
+
:class="{ 'sr-only': descriptionHidden }"
|
|
44
|
+
>
|
|
45
|
+
<Markdown :text="description" class="text-sm leading-6 text-gray-500" />
|
|
38
46
|
</HeadlessModalDescription>
|
|
39
47
|
|
|
40
48
|
<div :class="renderedContentClass">
|
|
@@ -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>
|
|
@@ -27,6 +27,8 @@ export { default as SelectLabel } from './SelectLabel.vue';
|
|
|
27
27
|
export { default as SelectOption } from './SelectOption.vue';
|
|
28
28
|
export { default as SelectOptions } from './SelectOptions.vue';
|
|
29
29
|
export { default as SelectTrigger } from './SelectTrigger.vue';
|
|
30
|
+
export { default as Setting } from './Setting.vue';
|
|
30
31
|
export { default as SettingsModal } from './SettingsModal.vue';
|
|
31
32
|
export { default as StartupCrash } from './StartupCrash.vue';
|
|
33
|
+
export { default as Switch } from './Switch.vue';
|
|
32
34
|
export { default as Toast } from './Toast.vue';
|
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>
|
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 {
|