@aerogel/core 0.0.0-next.7f6ed5a1f91688a86bf5ede2adc465e4fd6cfdea → 0.0.0-next.88c59e62f64db70aedfbc4c31b5bbc287be44483
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.cjs.js +1 -1
- package/dist/aerogel-core.cjs.js.map +1 -1
- package/dist/aerogel-core.d.ts +830 -104
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/dist/virtual.d.ts +11 -0
- package/noeldemartin.config.js +4 -1
- package/package.json +7 -9
- package/src/bootstrap/bootstrap.test.ts +0 -56
- package/src/bootstrap/index.ts +12 -25
- package/src/bootstrap/options.ts +5 -1
- package/src/components/AGAppModals.vue +15 -0
- package/src/components/AGAppOverlays.vue +5 -7
- package/src/components/AGAppSnackbars.vue +13 -0
- package/src/components/basic/AGErrorMessage.vue +16 -0
- package/src/components/basic/AGLink.vue +9 -0
- package/src/components/basic/AGMarkdown.vue +21 -5
- package/src/components/basic/index.ts +3 -1
- package/src/components/constants.ts +8 -0
- package/src/components/forms/AGButton.vue +36 -3
- package/src/components/forms/AGCheckbox.vue +35 -0
- package/src/components/forms/AGInput.vue +8 -4
- package/src/components/forms/index.ts +4 -5
- package/src/components/headless/forms/AGHeadlessButton.vue +7 -7
- package/src/components/headless/forms/AGHeadlessInput.ts +2 -2
- package/src/components/headless/forms/AGHeadlessInput.vue +6 -6
- package/src/components/headless/forms/AGHeadlessInputError.vue +9 -5
- package/src/components/headless/forms/AGHeadlessInputInput.vue +20 -4
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +16 -0
- package/src/components/headless/forms/AGHeadlessSelect.ts +31 -0
- package/src/components/headless/forms/AGHeadlessSelect.vue +45 -0
- package/src/components/headless/forms/AGHeadlessSelectButton.ts +3 -0
- package/src/components/headless/forms/AGHeadlessSelectLabel.ts +3 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +8 -0
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
- package/src/components/headless/forms/index.ts +12 -4
- package/src/components/headless/index.ts +1 -0
- package/src/components/headless/modals/AGHeadlessModal.vue +5 -1
- package/src/components/headless/modals/AGHeadlessModalPanel.vue +10 -2
- package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +10 -0
- package/src/components/headless/snackbars/index.ts +25 -0
- package/src/components/index.ts +4 -1
- package/src/components/modals/AGAlertModal.vue +12 -2
- package/src/components/modals/AGConfirmModal.vue +30 -0
- package/src/components/modals/AGErrorReportModal.ts +20 -0
- package/src/components/modals/AGErrorReportModal.vue +62 -0
- package/src/components/modals/AGErrorReportModalButtons.vue +109 -0
- package/src/components/modals/AGErrorReportModalTitle.vue +25 -0
- package/src/components/modals/AGLoadingModal.vue +19 -0
- package/src/components/modals/AGModal.ts +4 -0
- package/src/components/modals/AGModal.vue +23 -4
- package/src/components/modals/AGModalTitle.vue +9 -0
- package/src/components/modals/index.ts +20 -2
- package/src/components/snackbars/AGSnackbar.vue +42 -0
- package/src/components/snackbars/index.ts +3 -0
- package/src/directives/index.ts +19 -4
- package/src/errors/Errors.state.ts +31 -0
- package/src/errors/Errors.ts +183 -0
- package/src/errors/index.ts +59 -0
- package/src/forms/Form.test.ts +21 -0
- package/src/forms/Form.ts +41 -16
- package/src/forms/utils.ts +17 -0
- package/src/lang/Lang.ts +47 -8
- package/src/lang/index.ts +17 -76
- package/src/lang/utils.ts +4 -0
- package/src/main.ts +2 -0
- package/src/plugins/Plugin.ts +8 -0
- package/src/plugins/index.ts +26 -0
- package/src/services/App.state.ts +18 -0
- package/src/services/App.ts +20 -0
- package/src/services/Service.ts +157 -29
- package/src/services/index.ts +32 -7
- package/src/services/store.ts +27 -0
- package/src/types/virtual.d.ts +11 -0
- package/src/types/vite.d.ts +0 -2
- package/src/ui/UI.state.ts +12 -6
- package/src/ui/UI.ts +72 -10
- package/src/ui/index.ts +24 -14
- package/src/utils/composition/forms.ts +11 -0
- package/src/utils/composition/hooks.ts +9 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/markdown.ts +11 -2
- package/src/utils/vue.ts +4 -2
- package/tsconfig.json +2 -10
- package/vite.config.ts +3 -6
- package/src/bootstrap/hooks.ts +0 -19
- package/src/lang/helpers.ts +0 -5
- package/src/models/index.ts +0 -18
- package/src/routing/index.ts +0 -33
- package/src/testing/stubs/lang/en.yaml +0 -1
- package/src/testing/stubs/models/User.ts +0 -3
package/src/bootstrap/index.ts
CHANGED
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
import { createApp
|
|
1
|
+
import { createApp } from 'vue';
|
|
2
2
|
import type { Component } from 'vue';
|
|
3
3
|
|
|
4
4
|
import directives from '@/directives';
|
|
5
|
+
import errors from '@/errors';
|
|
6
|
+
import Events from '@/services/Events';
|
|
5
7
|
import lang from '@/lang';
|
|
6
|
-
import models from '@/models';
|
|
7
|
-
import routing from '@/routing';
|
|
8
8
|
import services from '@/services';
|
|
9
9
|
import ui from '@/ui';
|
|
10
|
-
import {
|
|
11
|
-
import type {
|
|
10
|
+
import { installPlugins } from '@/plugins';
|
|
11
|
+
import type { AerogelOptions } from '@/bootstrap/options';
|
|
12
12
|
|
|
13
|
-
export async function bootstrapApplication(rootComponent: Component, options:
|
|
14
|
-
const
|
|
15
|
-
const app = createApp(
|
|
16
|
-
data: () => ({
|
|
17
|
-
ready: false,
|
|
18
|
-
}),
|
|
19
|
-
mounted() {
|
|
20
|
-
runAppMountedHooks();
|
|
13
|
+
export async function bootstrapApplication(rootComponent: Component, options: AerogelOptions = {}): Promise<void> {
|
|
14
|
+
const plugins = [directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
15
|
+
const app = createApp(rootComponent);
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
render() {
|
|
25
|
-
if (!this.ready) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return h(rootComponent);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await Promise.all(hooks.map((hook) => hook(app, options)));
|
|
17
|
+
await installPlugins(plugins, app, options);
|
|
34
18
|
|
|
35
19
|
app.mount('#app');
|
|
20
|
+
app._container?.classList.remove('loading');
|
|
21
|
+
|
|
22
|
+
Events.emit('application-mounted');
|
|
36
23
|
}
|
package/src/bootstrap/options.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<aside v-if="modal">
|
|
3
|
+
<AGModalContext :child-index="1" :modal="modal" />
|
|
4
|
+
</aside>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
9
|
+
|
|
10
|
+
import UI from '@/ui/UI';
|
|
11
|
+
|
|
12
|
+
import AGModalContext from './modals/AGModalContext.vue';
|
|
13
|
+
|
|
14
|
+
const modal = computed(() => UI.modals[0] ?? null);
|
|
15
|
+
</script>
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div ref="$backdrop" class="pointer-events-none fixed inset-0 z-50 bg-black/30 opacity-0" />
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
</aside>
|
|
3
|
+
<AGAppModals />
|
|
4
|
+
<AGAppSnackbars />
|
|
6
5
|
</template>
|
|
7
6
|
|
|
8
7
|
<script setup lang="ts">
|
|
9
|
-
import {
|
|
8
|
+
import { ref } from 'vue';
|
|
10
9
|
|
|
11
|
-
import UI from '@/ui/UI';
|
|
12
10
|
import { useEvent } from '@/utils/composition/events';
|
|
13
11
|
|
|
14
|
-
import
|
|
12
|
+
import AGAppModals from './AGAppModals.vue';
|
|
13
|
+
import AGAppSnackbars from './AGAppSnackbars.vue';
|
|
15
14
|
|
|
16
15
|
const $backdrop = ref<HTMLElement | null>(null);
|
|
17
16
|
const backdropHidden = ref(true);
|
|
18
|
-
const modal = computed(() => UI.modals[0] ?? null);
|
|
19
17
|
|
|
20
18
|
useEvent('show-overlays-backdrop', async () => {
|
|
21
19
|
if (!$backdrop.value || !backdropHidden.value) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div aria-live="assertive" class="z-60 pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:p-6">
|
|
3
|
+
<div class="flex w-full flex-col items-center space-y-4 sm:items-end">
|
|
4
|
+
<component
|
|
5
|
+
:is="snackbar.component"
|
|
6
|
+
v-for="snackbar of $ui.snackbars"
|
|
7
|
+
:id="snackbar.id"
|
|
8
|
+
:key="snackbar.id"
|
|
9
|
+
v-bind="snackbar.properties"
|
|
10
|
+
/>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AGMarkdown :text="message" inline />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { computed } from 'vue';
|
|
7
|
+
|
|
8
|
+
import Errors from '@/errors/Errors';
|
|
9
|
+
import { requiredObjectProp } from '@/utils/vue';
|
|
10
|
+
import type { ErrorSource } from '@/errors/Errors.state';
|
|
11
|
+
|
|
12
|
+
import AGMarkdown from './AGMarkdown.vue';
|
|
13
|
+
|
|
14
|
+
const props = defineProps({ error: requiredObjectProp<ErrorSource>() });
|
|
15
|
+
const message = computed(() => Errors.getErrorMessage(props.error));
|
|
16
|
+
</script>
|
|
@@ -6,15 +6,31 @@
|
|
|
6
6
|
import { computed, h } from 'vue';
|
|
7
7
|
|
|
8
8
|
import { renderMarkdown } from '@/utils/markdown';
|
|
9
|
-
import { stringProp } from '@/utils/vue';
|
|
10
|
-
import {
|
|
9
|
+
import { booleanProp, objectProp, stringProp } from '@/utils/vue';
|
|
10
|
+
import { translate } from '@/lang';
|
|
11
11
|
|
|
12
12
|
const props = defineProps({
|
|
13
|
+
as: stringProp(),
|
|
14
|
+
inline: booleanProp(),
|
|
13
15
|
langKey: stringProp(),
|
|
16
|
+
langParams: objectProp<Record<string, unknown>>(),
|
|
14
17
|
text: stringProp(),
|
|
15
18
|
});
|
|
16
19
|
|
|
17
|
-
const markdown = computed(() => props.text ?? (props.langKey &&
|
|
18
|
-
const html = computed(() =>
|
|
19
|
-
|
|
20
|
+
const markdown = computed(() => props.text ?? (props.langKey && translate(props.langKey, props.langParams ?? {})));
|
|
21
|
+
const html = computed(() => {
|
|
22
|
+
if (!markdown.value) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let renderedHtml = renderMarkdown(markdown.value);
|
|
27
|
+
|
|
28
|
+
if (props.inline) {
|
|
29
|
+
renderedHtml = renderedHtml.replace('<p>', '<span>').replace('</p>', '</span>');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return renderedHtml;
|
|
33
|
+
});
|
|
34
|
+
const root = () =>
|
|
35
|
+
h(props.as ?? (props.inline ? 'span' : 'div'), { class: props.inline ? '' : 'prose', innerHTML: html.value });
|
|
20
36
|
</script>
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<AGHeadlessButton
|
|
3
|
-
class="bg-indigo-600 px-2.5 py-1.5 text-white hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
|
4
|
-
>
|
|
2
|
+
<AGHeadlessButton class="px-2.5 py-1.5 focus-visible:outline focus-visible:outline-2" :class="colorClasses">
|
|
5
3
|
<slot />
|
|
6
4
|
</AGHeadlessButton>
|
|
7
5
|
</template>
|
|
8
6
|
|
|
9
7
|
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
9
|
+
|
|
10
|
+
import { enumProp } from '@/utils/vue';
|
|
11
|
+
import { Colors } from '@/components/constants';
|
|
12
|
+
|
|
10
13
|
import AGHeadlessButton from '../headless/forms/AGHeadlessButton.vue';
|
|
14
|
+
|
|
15
|
+
const props = defineProps({
|
|
16
|
+
color: enumProp(Colors, Colors.Primary),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const colorClasses = computed(() => {
|
|
20
|
+
switch (props.color) {
|
|
21
|
+
case Colors.Secondary:
|
|
22
|
+
return [
|
|
23
|
+
'text-white bg-gray-600',
|
|
24
|
+
'hover:bg-gray-500',
|
|
25
|
+
'focus-visible:outline-offset-2 focus-visible:outline-gray-600',
|
|
26
|
+
].join(' ');
|
|
27
|
+
case Colors.Clear:
|
|
28
|
+
return 'hover:bg-gray-500/20 focus-visible:outline-gray-500/60';
|
|
29
|
+
case Colors.Danger:
|
|
30
|
+
return [
|
|
31
|
+
'text-white bg-red-600',
|
|
32
|
+
'hover:bg-red-500',
|
|
33
|
+
'focus-visible:outline-offset-2 focus-visible:outline-red-600',
|
|
34
|
+
].join(' ');
|
|
35
|
+
case Colors.Primary:
|
|
36
|
+
default:
|
|
37
|
+
return [
|
|
38
|
+
'text-white bg-indigo-600',
|
|
39
|
+
'hover:bg-indigo-500',
|
|
40
|
+
'focus-visible:outline-offset-2 focus-visible:outline-indigo-600',
|
|
41
|
+
].join(' ');
|
|
42
|
+
}
|
|
43
|
+
});
|
|
11
44
|
</script>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AGHeadlessInput ref="$input" :name="name" class="flex">
|
|
3
|
+
<AGHeadlessInputInput
|
|
4
|
+
v-bind="$attrs"
|
|
5
|
+
type="checkbox"
|
|
6
|
+
:class="{
|
|
7
|
+
'text-indigo-600 focus:ring-indigo-600': !$input?.errors,
|
|
8
|
+
'border-red-200 text-red-600 focus:ring-red-600': $input?.errors,
|
|
9
|
+
}"
|
|
10
|
+
/>
|
|
11
|
+
|
|
12
|
+
<div class="ml-2">
|
|
13
|
+
<AGHeadlessInputLabel v-if="$slots.default">
|
|
14
|
+
<slot />
|
|
15
|
+
</AGHeadlessInputLabel>
|
|
16
|
+
<AGHeadlessInputError class="text-sm text-red-600" />
|
|
17
|
+
</div>
|
|
18
|
+
</AGHeadlessInput>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
import { componentRef, stringProp } from '@/utils/vue';
|
|
23
|
+
|
|
24
|
+
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
25
|
+
|
|
26
|
+
import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
|
|
27
|
+
import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
|
|
28
|
+
import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
|
|
29
|
+
import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
|
|
30
|
+
|
|
31
|
+
defineProps({ name: stringProp() });
|
|
32
|
+
defineOptions({ inheritAttrs: false });
|
|
33
|
+
|
|
34
|
+
const $input = componentRef<IAGHeadlessInput>();
|
|
35
|
+
</script>
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<AGHeadlessInput
|
|
3
3
|
ref="$input"
|
|
4
|
-
|
|
5
|
-
class="
|
|
4
|
+
class="relative flex flex-col items-center"
|
|
5
|
+
:class="className"
|
|
6
6
|
:name="name"
|
|
7
7
|
>
|
|
8
8
|
<AGHeadlessInputInput
|
|
9
|
-
v-bind="
|
|
9
|
+
v-bind="attrs"
|
|
10
10
|
class="block w-full border-0 py-1.5 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600"
|
|
11
11
|
:class="{
|
|
12
12
|
'ring-1 ring-red-500': $input?.errors,
|
|
13
13
|
}"
|
|
14
14
|
/>
|
|
15
|
-
<
|
|
15
|
+
<div class="absolute bottom-0 left-0 translate-y-full">
|
|
16
|
+
<AGHeadlessInputError class="mt-1 text-sm text-red-500" />
|
|
17
|
+
</div>
|
|
16
18
|
</AGHeadlessInput>
|
|
17
19
|
</template>
|
|
18
20
|
|
|
19
21
|
<script setup lang="ts">
|
|
20
22
|
import { componentRef, stringProp } from '@/utils/vue';
|
|
21
23
|
|
|
24
|
+
import { useInputAttrs } from '@/utils';
|
|
22
25
|
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
23
26
|
|
|
24
27
|
import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
|
|
@@ -29,4 +32,5 @@ defineProps({ name: stringProp() });
|
|
|
29
32
|
defineOptions({ inheritAttrs: false });
|
|
30
33
|
|
|
31
34
|
const $input = componentRef<IAGHeadlessInput>();
|
|
35
|
+
const [attrs, className] = useInputAttrs();
|
|
32
36
|
</script>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { AGButton, AGForm, AGInput };
|
|
1
|
+
export { default as AGButton } from './AGButton.vue';
|
|
2
|
+
export { default as AGCheckbox } from './AGCheckbox.vue';
|
|
3
|
+
export { default as AGForm } from './AGForm.vue';
|
|
4
|
+
export { default as AGInput } from './AGInput.vue';
|
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
8
|
import { computed } from 'vue';
|
|
9
9
|
import { objectWithoutEmpty } from '@noeldemartin/utils';
|
|
10
|
-
import type { LocationQuery, RouteLocation, RouteParams } from 'vue-router';
|
|
11
10
|
|
|
12
11
|
import { booleanProp, objectProp, stringProp } from '@/utils/vue';
|
|
13
12
|
|
|
14
|
-
const { url, route, routeParams, routeQuery, submit } = defineProps({
|
|
13
|
+
const { href, url, route, routeParams, routeQuery, submit } = defineProps({
|
|
14
|
+
href: stringProp(),
|
|
15
15
|
url: stringProp(),
|
|
16
16
|
route: stringProp(),
|
|
17
|
-
routeParams: objectProp
|
|
18
|
-
routeQuery: objectProp
|
|
17
|
+
routeParams: objectProp(() => ({})),
|
|
18
|
+
routeQuery: objectProp(() => ({})),
|
|
19
19
|
submit: booleanProp(),
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ const component = computed(() => {
|
|
|
24
24
|
return {
|
|
25
25
|
tag: 'router-link',
|
|
26
26
|
props: {
|
|
27
|
-
to: objectWithoutEmpty
|
|
27
|
+
to: objectWithoutEmpty({
|
|
28
28
|
name: route,
|
|
29
29
|
params: routeParams,
|
|
30
30
|
query: routeQuery,
|
|
@@ -33,12 +33,12 @@ const component = computed(() => {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (url) {
|
|
36
|
+
if (href || url) {
|
|
37
37
|
return {
|
|
38
38
|
tag: 'a',
|
|
39
39
|
props: {
|
|
40
40
|
target: '_blank',
|
|
41
|
-
href: url,
|
|
41
|
+
href: href || url,
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
}
|
|
@@ -2,7 +2,7 @@ import type { ComputedRef, DeepReadonly, Ref } from 'vue';
|
|
|
2
2
|
|
|
3
3
|
export interface IAGHeadlessInput {
|
|
4
4
|
id: string;
|
|
5
|
-
value: ComputedRef<string | number | null>;
|
|
5
|
+
value: ComputedRef<string | number | boolean | null>;
|
|
6
6
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
7
|
-
update(value: string | number | null): void;
|
|
7
|
+
update(value: string | number | boolean | null): void;
|
|
8
8
|
}
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
import { computed, inject, provide, readonly } from 'vue';
|
|
10
10
|
import { uuid } from '@noeldemartin/utils';
|
|
11
11
|
|
|
12
|
-
import { stringProp } from '@/utils/vue';
|
|
12
|
+
import { mixedProp, stringProp } from '@/utils/vue';
|
|
13
13
|
import type Form from '@/forms/Form';
|
|
14
14
|
|
|
15
15
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
16
16
|
|
|
17
17
|
const emit = defineEmits(['update:modelValue']);
|
|
18
18
|
const props = defineProps({
|
|
19
|
-
as: stringProp(),
|
|
19
|
+
as: stringProp('div'),
|
|
20
20
|
name: stringProp(),
|
|
21
|
-
modelValue:
|
|
21
|
+
modelValue: mixedProp<string | number | boolean>([String, Number, Boolean]),
|
|
22
22
|
});
|
|
23
23
|
const errors = computed(() => {
|
|
24
24
|
if (!form || !props.name) {
|
|
@@ -27,12 +27,12 @@ const errors = computed(() => {
|
|
|
27
27
|
|
|
28
28
|
return form.errors[props.name] ?? null;
|
|
29
29
|
});
|
|
30
|
-
const form = inject<Form>('form');
|
|
30
|
+
const form = inject<Form | null>('form', null);
|
|
31
31
|
const publicApi: IAGHeadlessInput = {
|
|
32
|
-
id: uuid()
|
|
32
|
+
id: `input-${uuid()}`,
|
|
33
33
|
value: computed(() => {
|
|
34
34
|
if (form && props.name) {
|
|
35
|
-
return form.getFieldValue(props.name);
|
|
35
|
+
return form.getFieldValue(props.name) as string | number | boolean | null;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return props.modelValue;
|
|
@@ -5,18 +5,22 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import {
|
|
8
|
+
import { computed } from 'vue';
|
|
9
|
+
|
|
10
|
+
import { injectReactiveOrFail } from '@/utils/vue';
|
|
11
|
+
import { translateWithDefault } from '@/lang/utils';
|
|
9
12
|
|
|
10
13
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
11
|
-
import { computed } from 'vue';
|
|
12
|
-
import { lang } from '@/lang';
|
|
13
14
|
|
|
14
|
-
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
15
|
+
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
16
|
+
'input',
|
|
17
|
+
'<AGHeadlessInputError> must be a child of a <AGHeadlessInput>',
|
|
18
|
+
);
|
|
15
19
|
const errorMessage = computed(() => {
|
|
16
20
|
if (!input.errors) {
|
|
17
21
|
return null;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
return
|
|
24
|
+
return translateWithDefault(`errors.${input.errors[0]}`, `Error: ${input.errors[0]}`);
|
|
21
25
|
});
|
|
22
26
|
</script>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<input
|
|
3
|
+
:id="input.id"
|
|
3
4
|
ref="$input"
|
|
4
|
-
type="
|
|
5
|
+
:type="type"
|
|
5
6
|
:value="value"
|
|
6
7
|
:aria-invalid="input.errors ? 'true' : 'false'"
|
|
7
8
|
:aria-describedby="input.errors ? `${input.id}-error` : undefined"
|
|
9
|
+
:checked="checked"
|
|
8
10
|
@input="update"
|
|
9
11
|
>
|
|
10
12
|
</template>
|
|
@@ -12,18 +14,32 @@
|
|
|
12
14
|
<script setup lang="ts">
|
|
13
15
|
import { computed, ref } from 'vue';
|
|
14
16
|
|
|
15
|
-
import { injectReactiveOrFail } from '@/utils';
|
|
17
|
+
import { injectReactiveOrFail, stringProp } from '@/utils';
|
|
16
18
|
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
17
19
|
|
|
20
|
+
const props = defineProps({
|
|
21
|
+
type: stringProp('text'),
|
|
22
|
+
});
|
|
23
|
+
|
|
18
24
|
const $input = ref<HTMLInputElement>();
|
|
19
|
-
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
25
|
+
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
26
|
+
'input',
|
|
27
|
+
'<AGHeadlessInputInput> must be a child of a <AGHeadlessInput>',
|
|
28
|
+
);
|
|
20
29
|
const value = computed(() => input.value);
|
|
30
|
+
const checked = computed(() => {
|
|
31
|
+
if (props.type !== 'checkbox') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return !!value.value;
|
|
36
|
+
});
|
|
21
37
|
|
|
22
38
|
function update() {
|
|
23
39
|
if (!$input.value) {
|
|
24
40
|
return;
|
|
25
41
|
}
|
|
26
42
|
|
|
27
|
-
input.update($input.value.value);
|
|
43
|
+
input.update(props.type === 'checkbox' ? $input.value.checked : $input.value.value);
|
|
28
44
|
}
|
|
29
45
|
</script>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<label :for="input.id">
|
|
3
|
+
<slot />
|
|
4
|
+
</label>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { injectReactiveOrFail } from '@/utils/vue';
|
|
9
|
+
|
|
10
|
+
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
11
|
+
|
|
12
|
+
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
13
|
+
'input',
|
|
14
|
+
'<AGHeadlessInputLabel> must be a child of a <AGHeadlessInput>',
|
|
15
|
+
);
|
|
16
|
+
</script>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { requiredArrayProp } from '@/utils/vue';
|
|
4
|
+
|
|
5
|
+
export type SelectOptionValue = string | number | boolean | object | null;
|
|
6
|
+
|
|
7
|
+
export interface IAGHeadlessSelect {
|
|
8
|
+
value: ComputedRef<SelectOptionValue | undefined>;
|
|
9
|
+
options: SelectOptionValue[];
|
|
10
|
+
update(value: string | number | boolean | null): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const selectProps = {
|
|
14
|
+
options: requiredArrayProp<SelectOptionValue>(),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function useSelectProps(): typeof selectProps {
|
|
18
|
+
return selectProps;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function extractSelectProps<T extends Record<keyof typeof selectProps, unknown>>(
|
|
22
|
+
componentProps: T,
|
|
23
|
+
): Pick<T, keyof typeof selectProps> {
|
|
24
|
+
return Object.keys(selectProps).reduce((extractedProps, selectProp) => {
|
|
25
|
+
const prop = selectProp as keyof typeof selectProps;
|
|
26
|
+
|
|
27
|
+
extractedProps[prop] = componentProps[prop];
|
|
28
|
+
|
|
29
|
+
return extractedProps;
|
|
30
|
+
}, {} as Pick<T, keyof typeof selectProps>);
|
|
31
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Listbox :model-value="publicApi.value.value" @update:model-value="publicApi.update($event)">
|
|
3
|
+
<slot />
|
|
4
|
+
</Listbox>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { computed, inject } from 'vue';
|
|
9
|
+
import { Listbox } from '@headlessui/vue';
|
|
10
|
+
|
|
11
|
+
import { mixedProp, stringProp } from '@/utils/vue';
|
|
12
|
+
import type Form from '@/forms/Form';
|
|
13
|
+
|
|
14
|
+
import { useSelectProps } from './AGHeadlessSelect';
|
|
15
|
+
import type { IAGHeadlessSelect, SelectOptionValue } from './AGHeadlessSelect';
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits(['update:modelValue']);
|
|
18
|
+
const props = defineProps({
|
|
19
|
+
name: stringProp(),
|
|
20
|
+
modelValue: mixedProp<SelectOptionValue>(),
|
|
21
|
+
...useSelectProps(),
|
|
22
|
+
});
|
|
23
|
+
const form = inject<Form | null>('form', null);
|
|
24
|
+
const publicApi: IAGHeadlessSelect = {
|
|
25
|
+
value: computed(() => {
|
|
26
|
+
if (form && props.name) {
|
|
27
|
+
return form.getFieldValue(props.name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return props.modelValue;
|
|
31
|
+
}),
|
|
32
|
+
options: props.options,
|
|
33
|
+
update(value) {
|
|
34
|
+
if (form && props.name) {
|
|
35
|
+
form.setFieldValue(props.name, value);
|
|
36
|
+
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
emit('update:modelValue', value);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
defineExpose<IAGHeadlessSelect>(publicApi);
|
|
45
|
+
</script>
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export {
|
|
1
|
+
export * from './AGHeadlessInput';
|
|
2
|
+
export * from './AGHeadlessSelect';
|
|
3
|
+
export { default as AGHeadlessButton } from './AGHeadlessButton.vue';
|
|
4
|
+
export { default as AGHeadlessInput } from './AGHeadlessInput.vue';
|
|
5
|
+
export { default as AGHeadlessInputError } from './AGHeadlessInputError.vue';
|
|
6
|
+
export { default as AGHeadlessInputInput } from './AGHeadlessInputInput.vue';
|
|
7
|
+
export { default as AGHeadlessInputLabel } from './AGHeadlessInputLabel.vue';
|
|
8
|
+
export { default as AGHeadlessSelect } from './AGHeadlessSelect.vue';
|
|
9
|
+
export { default as AGHeadlessSelectButton } from './AGHeadlessSelectButton';
|
|
10
|
+
export { default as AGHeadlessSelectLabel } from './AGHeadlessSelectLabel';
|
|
11
|
+
export { default as AGHeadlessSelectOption, IAGHeadlessSelectOptionSlotProps } from './AGHeadlessSelectOption';
|
|
12
|
+
export { default as AGHeadlessSelectOptions } from './AGHeadlessSelectOptions';
|