@aerogel/core 0.0.0-next.d824b40e5d06757cd9f47c9f771d916185df4f05 → 0.0.0-next.eed7a057cf5b844cd9f7fc6bda2d8df49fcd6736
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 +3212 -485
- package/dist/aerogel-core.js +2789 -0
- package/dist/aerogel-core.js.map +1 -0
- package/package.json +25 -31
- package/src/bootstrap/bootstrap.test.ts +7 -10
- package/src/bootstrap/index.ts +43 -15
- package/src/bootstrap/options.ts +4 -1
- package/src/components/AGAppLayout.vue +7 -2
- package/src/components/AGAppModals.vue +1 -1
- package/src/components/AGAppOverlays.vue +6 -2
- package/src/components/AGAppSnackbars.vue +2 -2
- package/src/components/composition.ts +23 -0
- package/src/components/forms/AGButton.vue +2 -2
- package/src/components/forms/AGCheckbox.vue +10 -3
- package/src/components/forms/AGForm.vue +11 -12
- package/src/components/forms/AGInput.vue +13 -7
- package/src/components/forms/AGSelect.story.vue +46 -0
- package/src/components/forms/AGSelect.vue +60 -0
- package/src/components/forms/index.ts +5 -6
- package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
- package/src/components/headless/forms/AGHeadlessButton.vue +24 -13
- package/src/components/headless/forms/AGHeadlessInput.ts +37 -4
- package/src/components/headless/forms/AGHeadlessInput.vue +24 -8
- package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
- package/src/components/headless/forms/AGHeadlessInputError.vue +2 -2
- package/src/components/headless/forms/AGHeadlessInputInput.vue +45 -6
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +9 -3
- package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
- package/src/components/headless/forms/AGHeadlessSelect.ts +42 -0
- package/src/components/headless/forms/AGHeadlessSelect.vue +77 -0
- package/src/components/headless/forms/AGHeadlessSelectButton.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectError.vue +26 -0
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +24 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.ts +4 -0
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +3 -0
- package/src/components/headless/forms/composition.ts +10 -0
- package/src/components/headless/forms/index.ts +13 -1
- package/src/components/headless/modals/AGHeadlessModal.ts +30 -1
- package/src/components/headless/modals/AGHeadlessModal.vue +16 -12
- package/src/components/headless/modals/AGHeadlessModalPanel.vue +13 -9
- package/src/components/headless/modals/AGHeadlessModalTitle.vue +14 -4
- package/src/components/headless/modals/index.ts +4 -6
- package/src/components/headless/snackbars/index.ts +25 -10
- package/src/components/index.ts +3 -1
- package/src/components/interfaces.ts +24 -0
- package/src/components/lib/AGErrorMessage.vue +16 -0
- package/src/components/lib/AGMarkdown.vue +54 -0
- package/src/components/lib/AGMeasured.vue +16 -0
- package/src/components/lib/AGProgressBar.vue +55 -0
- package/src/components/lib/AGStartupCrash.vue +31 -0
- package/src/components/lib/index.ts +6 -0
- package/src/components/modals/AGAlertModal.ts +18 -0
- package/src/components/modals/AGAlertModal.vue +4 -15
- package/src/components/modals/AGConfirmModal.ts +42 -0
- package/src/components/modals/AGConfirmModal.vue +10 -14
- package/src/components/modals/AGErrorReportModal.ts +32 -3
- package/src/components/modals/AGErrorReportModal.vue +8 -16
- package/src/components/modals/AGErrorReportModalButtons.vue +13 -11
- package/src/components/modals/AGErrorReportModalTitle.vue +3 -3
- package/src/components/modals/AGLoadingModal.ts +29 -0
- package/src/components/modals/AGLoadingModal.vue +4 -8
- package/src/components/modals/AGModal.ts +2 -1
- package/src/components/modals/AGModal.vue +18 -13
- package/src/components/modals/AGModalContext.ts +1 -1
- package/src/components/modals/AGModalContext.vue +15 -5
- package/src/components/modals/AGPromptModal.ts +41 -0
- package/src/components/modals/AGPromptModal.vue +34 -0
- package/src/components/modals/index.ts +13 -19
- package/src/components/snackbars/AGSnackbar.vue +4 -10
- package/src/components/utils.ts +13 -0
- package/src/directives/index.ts +7 -5
- package/src/directives/measure.ts +40 -0
- package/src/errors/Errors.state.ts +1 -1
- package/src/errors/Errors.ts +32 -30
- package/src/errors/JobCancelledError.ts +3 -0
- package/src/errors/index.ts +19 -29
- package/src/errors/utils.ts +35 -0
- package/src/forms/Form.test.ts +32 -3
- package/src/forms/Form.ts +90 -21
- package/src/forms/composition.ts +2 -2
- package/src/forms/index.ts +3 -1
- package/src/forms/utils.ts +34 -3
- package/src/forms/validation.ts +19 -0
- package/src/{main.ts → index.ts} +3 -0
- package/src/jobs/Job.ts +147 -0
- package/src/jobs/index.ts +10 -0
- package/src/jobs/listeners.ts +3 -0
- package/src/jobs/status.ts +4 -0
- package/src/lang/DefaultLangProvider.ts +46 -0
- package/src/lang/Lang.state.ts +11 -0
- package/src/lang/Lang.ts +44 -29
- package/src/lang/index.ts +7 -5
- package/src/plugins/Plugin.ts +1 -1
- package/src/plugins/index.ts +10 -7
- package/src/services/App.state.ts +29 -7
- package/src/services/App.ts +41 -6
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.test.ts +39 -0
- package/src/services/Events.ts +112 -32
- package/src/services/Service.ts +154 -49
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +14 -5
- package/src/services/store.ts +8 -5
- package/src/services/utils.ts +18 -0
- package/src/testing/index.ts +26 -0
- package/src/testing/setup.ts +11 -0
- package/src/ui/UI.state.ts +9 -2
- package/src/ui/UI.ts +251 -41
- package/src/ui/index.ts +13 -7
- package/src/ui/utils.ts +16 -0
- package/src/utils/composition/events.ts +3 -2
- package/src/utils/composition/persistent.test.ts +33 -0
- package/src/utils/composition/persistent.ts +11 -0
- package/src/utils/composition/state.test.ts +47 -0
- package/src/utils/composition/state.ts +24 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/markdown.test.ts +50 -0
- package/src/utils/markdown.ts +19 -6
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +30 -9
- package/.eslintrc.js +0 -3
- package/dist/aerogel-core.cjs.js +0 -2
- package/dist/aerogel-core.cjs.js.map +0 -1
- package/dist/aerogel-core.esm.js +0 -2
- package/dist/aerogel-core.esm.js.map +0 -1
- package/dist/virtual.d.ts +0 -11
- package/noeldemartin.config.js +0 -5
- package/src/components/basic/AGErrorMessage.vue +0 -16
- package/src/components/basic/AGMarkdown.vue +0 -36
- package/src/components/basic/index.ts +0 -5
- package/src/directives/initial-focus.ts +0 -11
- package/src/types/virtual.d.ts +0 -11
- package/tsconfig.json +0 -11
- package/vite.config.ts +0 -14
- /package/src/components/{basic → lib}/AGLink.vue +0 -0
|
@@ -6,20 +6,22 @@
|
|
|
6
6
|
</template>
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
|
-
import { computed, inject, provide, readonly } from 'vue';
|
|
9
|
+
import { computed, inject, provide, readonly, ref } from 'vue';
|
|
10
10
|
import { uuid } from '@noeldemartin/utils';
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import type Form from '
|
|
12
|
+
import { stringProp } from '@aerogel/core/utils/vue';
|
|
13
|
+
import type Form from '@aerogel/core/forms/Form';
|
|
14
|
+
import type { __SetsElement } from '@aerogel/core/components/interfaces';
|
|
14
15
|
|
|
16
|
+
import { useInputProps } from './AGHeadlessInput';
|
|
15
17
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
16
18
|
|
|
17
19
|
const emit = defineEmits(['update:modelValue']);
|
|
18
20
|
const props = defineProps({
|
|
19
21
|
as: stringProp('div'),
|
|
20
|
-
|
|
21
|
-
modelValue: mixedProp<string | number | boolean>([String, Number, Boolean]),
|
|
22
|
+
...useInputProps(),
|
|
22
23
|
});
|
|
24
|
+
const $el = ref<HTMLElement>();
|
|
23
25
|
const errors = computed(() => {
|
|
24
26
|
if (!form || !props.name) {
|
|
25
27
|
return null;
|
|
@@ -28,8 +30,12 @@ const errors = computed(() => {
|
|
|
28
30
|
return form.errors[props.name] ?? null;
|
|
29
31
|
});
|
|
30
32
|
const form = inject<Form | null>('form', null);
|
|
31
|
-
const
|
|
33
|
+
const api: IAGHeadlessInput & __SetsElement = {
|
|
34
|
+
$el,
|
|
32
35
|
id: `input-${uuid()}`,
|
|
36
|
+
name: computed(() => props.name),
|
|
37
|
+
label: computed(() => props.label),
|
|
38
|
+
description: computed(() => props.description),
|
|
33
39
|
value: computed(() => {
|
|
34
40
|
if (form && props.name) {
|
|
35
41
|
return form.getFieldValue(props.name);
|
|
@@ -38,6 +44,13 @@ const publicApi: IAGHeadlessInput = {
|
|
|
38
44
|
return props.modelValue;
|
|
39
45
|
}),
|
|
40
46
|
errors: readonly(errors),
|
|
47
|
+
required: computed(() => {
|
|
48
|
+
if (!props.name || !form) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return form.getFieldRules(props.name).includes('required');
|
|
53
|
+
}),
|
|
41
54
|
update(value) {
|
|
42
55
|
if (form && props.name) {
|
|
43
56
|
form.setFieldValue(props.name, value);
|
|
@@ -47,8 +60,11 @@ const publicApi: IAGHeadlessInput = {
|
|
|
47
60
|
|
|
48
61
|
emit('update:modelValue', value);
|
|
49
62
|
},
|
|
63
|
+
__setElement(element) {
|
|
64
|
+
$el.value = element;
|
|
65
|
+
},
|
|
50
66
|
};
|
|
51
67
|
|
|
52
|
-
provide<IAGHeadlessInput>('input',
|
|
53
|
-
defineExpose<IAGHeadlessInput>(
|
|
68
|
+
provide<IAGHeadlessInput>('input', api);
|
|
69
|
+
defineExpose<IAGHeadlessInput>(api);
|
|
54
70
|
</script>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<slot :id="`${input.id}-description`">
|
|
3
|
+
<AGMarkdown
|
|
4
|
+
v-if="show"
|
|
5
|
+
v-bind="$attrs"
|
|
6
|
+
:id="`${input.id}-description`"
|
|
7
|
+
:text="text"
|
|
8
|
+
/>
|
|
9
|
+
</slot>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { computed } from 'vue';
|
|
14
|
+
|
|
15
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
16
|
+
|
|
17
|
+
import AGMarkdown from '../../lib/AGMarkdown.vue';
|
|
18
|
+
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
19
|
+
|
|
20
|
+
defineOptions({ inheritAttrs: false });
|
|
21
|
+
|
|
22
|
+
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
23
|
+
'input',
|
|
24
|
+
'<AGHeadlessInputDescription> must be a child of a <AGHeadlessInput>',
|
|
25
|
+
);
|
|
26
|
+
const text = computed(() => (typeof input.description === 'string' ? input.description : ''));
|
|
27
|
+
const show = computed(() => !!input.description);
|
|
28
|
+
</script>
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
8
|
import { computed } from 'vue';
|
|
9
9
|
|
|
10
|
-
import { injectReactiveOrFail } from '
|
|
11
|
-
import { translateWithDefault } from '
|
|
10
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
11
|
+
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
12
12
|
|
|
13
13
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
14
14
|
|
|
@@ -2,20 +2,27 @@
|
|
|
2
2
|
<input
|
|
3
3
|
:id="input.id"
|
|
4
4
|
ref="$input"
|
|
5
|
+
:name="name"
|
|
5
6
|
:type="type"
|
|
6
|
-
:
|
|
7
|
+
:required="input.required ?? undefined"
|
|
7
8
|
:aria-invalid="input.errors ? 'true' : 'false'"
|
|
8
|
-
:aria-describedby="
|
|
9
|
+
:aria-describedby="
|
|
10
|
+
input.errors ? `${input.id}-error` : input.description ? `${input.id}-description` : undefined
|
|
11
|
+
"
|
|
9
12
|
:checked="checked"
|
|
10
13
|
@input="update"
|
|
11
14
|
>
|
|
12
15
|
</template>
|
|
13
16
|
|
|
14
17
|
<script setup lang="ts">
|
|
15
|
-
import { computed, ref } from 'vue';
|
|
18
|
+
import { computed, ref, watchEffect } from 'vue';
|
|
16
19
|
|
|
17
|
-
import { injectReactiveOrFail, stringProp } from '
|
|
18
|
-
import type {
|
|
20
|
+
import { injectReactiveOrFail, stringProp } from '@aerogel/core/utils/vue';
|
|
21
|
+
import type { __SetsElement } from '@aerogel/core/components/interfaces';
|
|
22
|
+
import type { FormFieldValue } from '@aerogel/core/forms/Form';
|
|
23
|
+
import type { IAGHeadlessInput } from '@aerogel/core/components/headless/forms/AGHeadlessInput';
|
|
24
|
+
|
|
25
|
+
import { onFormFocus } from './composition';
|
|
19
26
|
|
|
20
27
|
const props = defineProps({
|
|
21
28
|
type: stringProp('text'),
|
|
@@ -26,6 +33,7 @@ const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
|
26
33
|
'input',
|
|
27
34
|
'<AGHeadlessInputInput> must be a child of a <AGHeadlessInput>',
|
|
28
35
|
);
|
|
36
|
+
const name = computed(() => input.name ?? undefined);
|
|
29
37
|
const value = computed(() => input.value);
|
|
30
38
|
const checked = computed(() => {
|
|
31
39
|
if (props.type !== 'checkbox') {
|
|
@@ -40,6 +48,37 @@ function update() {
|
|
|
40
48
|
return;
|
|
41
49
|
}
|
|
42
50
|
|
|
43
|
-
input.update(
|
|
51
|
+
input.update(getValue());
|
|
44
52
|
}
|
|
53
|
+
|
|
54
|
+
function getValue(): FormFieldValue | null {
|
|
55
|
+
if (!$input.value) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
switch (props.type) {
|
|
60
|
+
case 'checkbox':
|
|
61
|
+
return $input.value.checked;
|
|
62
|
+
case 'date':
|
|
63
|
+
return $input.value.valueAsDate;
|
|
64
|
+
default:
|
|
65
|
+
return $input.value.value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onFormFocus(input, () => $input.value?.focus());
|
|
70
|
+
watchEffect(() => (input as unknown as __SetsElement).__setElement($input.value));
|
|
71
|
+
watchEffect(() => {
|
|
72
|
+
if (!$input.value) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (props.type === 'date') {
|
|
77
|
+
$input.value.valueAsDate = value.value as Date;
|
|
78
|
+
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
$input.value.value = value.value as string;
|
|
83
|
+
});
|
|
45
84
|
</script>
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<label :for="input.id">
|
|
3
|
-
<slot
|
|
2
|
+
<label v-if="show" :for="input.id">
|
|
3
|
+
<slot>
|
|
4
|
+
{{ input.label }}
|
|
5
|
+
</slot>
|
|
4
6
|
</label>
|
|
5
7
|
</template>
|
|
6
8
|
|
|
7
9
|
<script setup lang="ts">
|
|
8
|
-
import {
|
|
10
|
+
import { computed, useSlots } from 'vue';
|
|
11
|
+
|
|
12
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
9
13
|
|
|
10
14
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
11
15
|
|
|
@@ -13,4 +17,6 @@ const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
|
13
17
|
'input',
|
|
14
18
|
'<AGHeadlessInputLabel> must be a child of a <AGHeadlessInput>',
|
|
15
19
|
);
|
|
20
|
+
const slots = useSlots();
|
|
21
|
+
const show = computed(() => !!(input.label || slots.default));
|
|
16
22
|
</script>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<textarea
|
|
3
|
+
:id="input.id"
|
|
4
|
+
ref="$textArea"
|
|
5
|
+
:name="name"
|
|
6
|
+
:required="input.required ?? undefined"
|
|
7
|
+
:value="value"
|
|
8
|
+
:aria-invalid="input.errors ? 'true' : 'false'"
|
|
9
|
+
:aria-describedby="
|
|
10
|
+
input.errors ? `${input.id}-error` : input.description ? `${input.id}-description` : undefined
|
|
11
|
+
"
|
|
12
|
+
@input="update"
|
|
13
|
+
/>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import { computed, ref, watchEffect } from 'vue';
|
|
18
|
+
|
|
19
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
20
|
+
import type { IAGHeadlessInput } from '@aerogel/core/components/headless/forms/AGHeadlessInput';
|
|
21
|
+
import type { __SetsElement } from '@aerogel/core/components/interfaces';
|
|
22
|
+
|
|
23
|
+
import { onFormFocus } from './composition';
|
|
24
|
+
|
|
25
|
+
const $textArea = ref<HTMLTextAreaElement>();
|
|
26
|
+
const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
27
|
+
'input',
|
|
28
|
+
'<AGHeadlessInputTextArea> must be a child of a <AGHeadlessInput>',
|
|
29
|
+
);
|
|
30
|
+
const name = computed(() => input.name ?? undefined);
|
|
31
|
+
const value = computed(() => input.value as string);
|
|
32
|
+
|
|
33
|
+
function update() {
|
|
34
|
+
if (!$textArea.value) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
input.update($textArea.value.value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
watchEffect(() => (input as unknown as __SetsElement).__setElement($textArea.value));
|
|
42
|
+
onFormFocus(input, () => $textArea.value?.focus());
|
|
43
|
+
</script>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
import type { Writable } from '@noeldemartin/utils';
|
|
3
|
+
|
|
4
|
+
import { mixedProp, requiredArrayProp, stringProp } from '@aerogel/core/utils/vue';
|
|
5
|
+
import { extractComponentProps } from '@aerogel/core/components/utils';
|
|
6
|
+
import type { FormFieldValue } from '@aerogel/core/forms/Form';
|
|
7
|
+
|
|
8
|
+
export interface IAGHeadlessSelect {
|
|
9
|
+
id: string;
|
|
10
|
+
label: ComputedRef<string | null>;
|
|
11
|
+
noSelectionText: ComputedRef<string>;
|
|
12
|
+
buttonText: ComputedRef<string>;
|
|
13
|
+
renderText: ComputedRef<(value: FormFieldValue) => string>;
|
|
14
|
+
selectedOption: ComputedRef<FormFieldValue | null>;
|
|
15
|
+
options: ComputedRef<FormFieldValue[]>;
|
|
16
|
+
errors: DeepReadonly<Ref<string[] | null>>;
|
|
17
|
+
update(value: FormFieldValue): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const selectProps = {
|
|
21
|
+
name: stringProp(),
|
|
22
|
+
label: stringProp(),
|
|
23
|
+
options: requiredArrayProp<FormFieldValue>(),
|
|
24
|
+
noSelectionText: stringProp(),
|
|
25
|
+
optionsText: mixedProp<string | ((option: FormFieldValue) => string)>(),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const selectEmits = ['update:modelValue'] as const;
|
|
29
|
+
|
|
30
|
+
export function useSelectProps(): typeof selectProps {
|
|
31
|
+
return selectProps;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function useSelectEmits(): Writable<typeof selectEmits> {
|
|
35
|
+
return [...selectEmits];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function extractSelectProps<T extends ExtractPropTypes<typeof selectProps>>(
|
|
39
|
+
props: T,
|
|
40
|
+
): Pick<T, keyof typeof selectProps> {
|
|
41
|
+
return extractComponentProps(props, selectProps);
|
|
42
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Listbox
|
|
3
|
+
v-slot="{ value, open, disabled }: ComponentProps"
|
|
4
|
+
:model-value="selectedOption"
|
|
5
|
+
@update:model-value="update($event)"
|
|
6
|
+
>
|
|
7
|
+
<slot :value="value" :open="open" :disabled="disabled" />
|
|
8
|
+
</Listbox>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { computed, inject, provide } from 'vue';
|
|
13
|
+
import { toString, uuid } from '@noeldemartin/utils';
|
|
14
|
+
import { Listbox } from '@headlessui/vue';
|
|
15
|
+
|
|
16
|
+
import { mixedProp } from '@aerogel/core/utils/vue';
|
|
17
|
+
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
18
|
+
import type Form from '@aerogel/core/forms/Form';
|
|
19
|
+
import type { FormFieldValue } from '@aerogel/core/forms/Form';
|
|
20
|
+
import type { ComponentProps } from '@aerogel/core/utils/vue';
|
|
21
|
+
|
|
22
|
+
import { useSelectEmits, useSelectProps } from './AGHeadlessSelect';
|
|
23
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits(useSelectEmits());
|
|
26
|
+
const props = defineProps({
|
|
27
|
+
modelValue: mixedProp<FormFieldValue>(),
|
|
28
|
+
...useSelectProps(),
|
|
29
|
+
});
|
|
30
|
+
const renderText = computed(() => {
|
|
31
|
+
if (typeof props.optionsText === 'function') {
|
|
32
|
+
return props.optionsText;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof props.optionsText === 'string') {
|
|
36
|
+
return (option: FormFieldValue): string => toString(option[props.optionsText as keyof FormFieldValue]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (option: FormFieldValue) => toString(option);
|
|
40
|
+
});
|
|
41
|
+
const form = inject<Form | null>('form', null);
|
|
42
|
+
const noSelectionText = computed(() => props.noSelectionText ?? translateWithDefault('select.noSelection', '-'));
|
|
43
|
+
const selectedOption = computed(() => (form && props.name ? form.getFieldValue(props.name) : props.modelValue));
|
|
44
|
+
const errors = computed(() => {
|
|
45
|
+
if (!form || !props.name) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return form.errors[props.name] ?? null;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function update(value: FormFieldValue) {
|
|
53
|
+
if (form && props.name) {
|
|
54
|
+
form.setFieldValue(props.name, value);
|
|
55
|
+
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
emit('update:modelValue', value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const api: IAGHeadlessSelect = {
|
|
63
|
+
id: `select-${uuid()}`,
|
|
64
|
+
noSelectionText,
|
|
65
|
+
selectedOption,
|
|
66
|
+
errors,
|
|
67
|
+
options: computed(() => props.options),
|
|
68
|
+
label: computed(() => props.label),
|
|
69
|
+
buttonText: computed(() =>
|
|
70
|
+
selectedOption.value === null ? noSelectionText.value : renderText.value(selectedOption.value)),
|
|
71
|
+
renderText,
|
|
72
|
+
update,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
provide<IAGHeadlessSelect>('select', api);
|
|
76
|
+
defineExpose<IAGHeadlessSelect>(api);
|
|
77
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ListboxButton v-slot="{ value, open, disabled }: ComponentProps">
|
|
3
|
+
<slot :value="value" :open="open" :disabled="disabled">
|
|
4
|
+
<span :class="textClass">{{ select?.buttonText }}</span>
|
|
5
|
+
</slot>
|
|
6
|
+
<slot name="icon" />
|
|
7
|
+
</ListboxButton>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script setup lang="ts">
|
|
11
|
+
import { ListboxButton } from '@headlessui/vue';
|
|
12
|
+
|
|
13
|
+
import { injectReactiveOrFail, stringProp } from '@aerogel/core/utils/vue';
|
|
14
|
+
import type { ComponentProps } from '@aerogel/core/utils/vue';
|
|
15
|
+
|
|
16
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
17
|
+
|
|
18
|
+
defineProps({ textClass: stringProp() });
|
|
19
|
+
|
|
20
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
21
|
+
'select',
|
|
22
|
+
'<AGHeadlessSelectButton> must be a child of a <AGHeadlessSelect>',
|
|
23
|
+
);
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<p v-if="errorMessage" :id="`${select.id}-error`">
|
|
3
|
+
{{ errorMessage }}
|
|
4
|
+
</p>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
9
|
+
|
|
10
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
11
|
+
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
12
|
+
|
|
13
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
14
|
+
|
|
15
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
16
|
+
'select',
|
|
17
|
+
'<AGHeadlessSelectError> must be a child of a <AGHeadlessSelect>',
|
|
18
|
+
);
|
|
19
|
+
const errorMessage = computed(() => {
|
|
20
|
+
if (!select.errors) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return translateWithDefault(`errors.${select.errors[0]}`, `Error: ${select.errors[0]}`);
|
|
25
|
+
});
|
|
26
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ListboxLabel v-if="show" v-slot="{ open, disabled }: ComponentProps">
|
|
3
|
+
<slot :open="open" :disabled="disabled">
|
|
4
|
+
{{ select.label }}
|
|
5
|
+
</slot>
|
|
6
|
+
</ListboxLabel>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
import { computed, useSlots } from 'vue';
|
|
11
|
+
import { ListboxLabel } from '@headlessui/vue';
|
|
12
|
+
|
|
13
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
14
|
+
import type { ComponentProps } from '@aerogel/core/utils/vue';
|
|
15
|
+
|
|
16
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
17
|
+
|
|
18
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
19
|
+
'select',
|
|
20
|
+
'<AGHeadlessSelectLabel> must be a child of a <AGHeadlessSelect>',
|
|
21
|
+
);
|
|
22
|
+
const slots = useSlots();
|
|
23
|
+
const show = computed(() => !!(select.label || slots.default));
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ListboxOption v-slot="{ active, selected, disabled }: ComponentProps" :value="value" as="template">
|
|
3
|
+
<slot :active="active" :selected="selected" :disabled="disabled">
|
|
4
|
+
<li
|
|
5
|
+
:class="{
|
|
6
|
+
[activeClass ?? 'active']: active,
|
|
7
|
+
[inactiveClass ?? 'inactive']: !active,
|
|
8
|
+
[selectedClass ?? 'selected']: selected,
|
|
9
|
+
[unselectedClass ?? 'unselected']: !selected,
|
|
10
|
+
}"
|
|
11
|
+
>
|
|
12
|
+
{{ select.renderText(value) }}
|
|
13
|
+
</li>
|
|
14
|
+
</slot>
|
|
15
|
+
</ListboxOption>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { ListboxOption } from '@headlessui/vue';
|
|
20
|
+
|
|
21
|
+
import { injectReactiveOrFail, requiredMixedProp, stringProp } from '@aerogel/core/utils/vue';
|
|
22
|
+
import type { ComponentProps } from '@aerogel/core/utils/vue';
|
|
23
|
+
import type { FormFieldValue } from '@aerogel/core/forms/Form';
|
|
24
|
+
|
|
25
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
26
|
+
|
|
27
|
+
defineProps({
|
|
28
|
+
value: requiredMixedProp<FormFieldValue>(),
|
|
29
|
+
selectedClass: stringProp(),
|
|
30
|
+
unselectedClass: stringProp(),
|
|
31
|
+
activeClass: stringProp(),
|
|
32
|
+
inactiveClass: stringProp(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
36
|
+
'select',
|
|
37
|
+
'<AGHeadlessSelectOption> must be a child of a <AGHeadlessSelect>',
|
|
38
|
+
);
|
|
39
|
+
</script>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { inject, onUnmounted } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type Form from '@aerogel/core/forms/Form';
|
|
4
|
+
|
|
5
|
+
export function onFormFocus(input: { name: string | null }, listener: () => unknown): void {
|
|
6
|
+
const form = inject<Form | null>('form', null);
|
|
7
|
+
const stop = form?.on('focus', (name) => input.name === name && listener());
|
|
8
|
+
|
|
9
|
+
onUnmounted(() => stop?.());
|
|
10
|
+
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './composition';
|
|
2
|
+
export * from './AGHeadlessButton';
|
|
3
|
+
export * from './AGHeadlessInput';
|
|
4
|
+
export * from './AGHeadlessSelect';
|
|
5
|
+
export * from './AGHeadlessSelectOption';
|
|
2
6
|
export { default as AGHeadlessButton } from './AGHeadlessButton.vue';
|
|
3
7
|
export { default as AGHeadlessInput } from './AGHeadlessInput.vue';
|
|
8
|
+
export { default as AGHeadlessInputDescription } from './AGHeadlessInputDescription.vue';
|
|
4
9
|
export { default as AGHeadlessInputError } from './AGHeadlessInputError.vue';
|
|
5
10
|
export { default as AGHeadlessInputInput } from './AGHeadlessInputInput.vue';
|
|
6
11
|
export { default as AGHeadlessInputLabel } from './AGHeadlessInputLabel.vue';
|
|
12
|
+
export { default as AGHeadlessInputTextArea } from './AGHeadlessInputTextArea.vue';
|
|
13
|
+
export { default as AGHeadlessSelect } from './AGHeadlessSelect.vue';
|
|
14
|
+
export { default as AGHeadlessSelectButton } from './AGHeadlessSelectButton.vue';
|
|
15
|
+
export { default as AGHeadlessSelectError } from './AGHeadlessSelectError.vue';
|
|
16
|
+
export { default as AGHeadlessSelectLabel } from './AGHeadlessSelectLabel.vue';
|
|
17
|
+
export { default as AGHeadlessSelectOption } from './AGHeadlessSelectOption.vue';
|
|
18
|
+
export { default as AGHeadlessSelectOptions } from './AGHeadlessSelectOptions';
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import type { ExtractPropTypes, Ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
import { booleanProp, stringProp } from '@aerogel/core/utils';
|
|
5
|
+
import { extractComponentProps } from '@aerogel/core/components/utils';
|
|
6
|
+
import type { IAGModal } from '@aerogel/core/components/modals/AGModal';
|
|
2
7
|
|
|
3
8
|
export interface IAGHeadlessModal extends IAGModal {}
|
|
4
9
|
|
|
5
10
|
export interface IAGHeadlessModalDefaultSlotProps {
|
|
6
11
|
close(result?: unknown): Promise<void>;
|
|
7
12
|
}
|
|
13
|
+
|
|
14
|
+
export const modalProps = {
|
|
15
|
+
cancellable: booleanProp(true),
|
|
16
|
+
inline: booleanProp(),
|
|
17
|
+
title: stringProp(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function useModalProps(): typeof modalProps {
|
|
21
|
+
return modalProps;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function extractModalProps<T extends ExtractPropTypes<typeof modalProps>>(
|
|
25
|
+
props: T,
|
|
26
|
+
): Pick<T, keyof typeof modalProps> {
|
|
27
|
+
return extractComponentProps(props, modalProps);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useModalExpose($modal: Ref<IAGHeadlessModal | undefined>): IAGModal {
|
|
31
|
+
return {
|
|
32
|
+
inline: computed(() => !!$modal.value?.inline),
|
|
33
|
+
cancellable: computed(() => !!$modal.value?.cancellable),
|
|
34
|
+
close: async () => $modal.value?.close(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<component
|
|
3
|
+
:is="rootComponent"
|
|
4
|
+
ref="$root"
|
|
5
|
+
:open="true"
|
|
6
|
+
@close="cancellable && close()"
|
|
7
|
+
>
|
|
3
8
|
<slot :close="close" />
|
|
4
|
-
</
|
|
9
|
+
</component>
|
|
5
10
|
</template>
|
|
6
11
|
|
|
7
12
|
<script setup lang="ts">
|
|
8
|
-
import { ref, toRef } from 'vue';
|
|
13
|
+
import { computed, ref, toRef } from 'vue';
|
|
9
14
|
import { Dialog } from '@headlessui/vue';
|
|
10
15
|
import type { VNode } from 'vue';
|
|
11
16
|
|
|
12
|
-
import Events from '
|
|
13
|
-
import { useEvent } from '
|
|
14
|
-
import {
|
|
15
|
-
import type { IAGModalContext } from '
|
|
17
|
+
import Events from '@aerogel/core/services/Events';
|
|
18
|
+
import { useEvent } from '@aerogel/core/utils/composition/events';
|
|
19
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
20
|
+
import type { IAGModalContext } from '@aerogel/core/components/modals/AGModalContext';
|
|
16
21
|
|
|
22
|
+
import { useModalProps } from './AGHeadlessModal';
|
|
17
23
|
import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from './AGHeadlessModal';
|
|
18
24
|
|
|
19
|
-
const props = defineProps(
|
|
20
|
-
cancellable: booleanProp(true),
|
|
21
|
-
});
|
|
22
|
-
|
|
25
|
+
const props = defineProps(useModalProps());
|
|
23
26
|
const $root = ref<{ $el?: HTMLElement } | null>(null);
|
|
24
27
|
const hidden = ref(true);
|
|
25
28
|
const closed = ref(false);
|
|
@@ -28,6 +31,7 @@ const { modal } = injectReactiveOrFail<IAGModalContext>(
|
|
|
28
31
|
'could not obtain modal reference from <AGHeadlessModal>, ' +
|
|
29
32
|
'did you render this component manually? Show it using $ui.openModal() instead',
|
|
30
33
|
);
|
|
34
|
+
const rootComponent = computed(() => (modal.properties.inline ? 'div' : Dialog));
|
|
31
35
|
|
|
32
36
|
async function hide(): Promise<void> {
|
|
33
37
|
if (!$root.value?.$el) {
|
|
@@ -84,5 +88,5 @@ useEvent('show-modal', async ({ id }) => {
|
|
|
84
88
|
});
|
|
85
89
|
|
|
86
90
|
defineSlots<{ default(props: IAGHeadlessModalDefaultSlotProps): VNode[] }>();
|
|
87
|
-
defineExpose<IAGHeadlessModal>({ close, cancellable: toRef(props, 'cancellable') });
|
|
91
|
+
defineExpose<IAGHeadlessModal>({ close, cancellable: toRef(props, 'cancellable'), inline: toRef(props, 'inline') });
|
|
88
92
|
</script>
|