@aerogel/core 0.0.0-next.980a397d575dcb5ff8c5a0bff769d09f938ea03c → 0.0.0-next.9a1c5ba39a454b316eba36ec7bdf579fed3d95d2
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 +2255 -1046
- package/dist/aerogel-core.js +2763 -0
- package/dist/aerogel-core.js.map +1 -0
- package/package.json +23 -37
- package/src/bootstrap/bootstrap.test.ts +7 -11
- package/src/bootstrap/index.ts +36 -16
- package/src/bootstrap/options.ts +4 -1
- package/src/components/AGAppLayout.vue +3 -2
- package/src/components/AGAppModals.vue +1 -1
- package/src/components/AGAppOverlays.vue +6 -2
- package/src/components/AGAppSnackbars.vue +1 -1
- package/src/components/composition.ts +23 -0
- package/src/components/contracts/Modal.ts +16 -0
- package/src/components/contracts/index.ts +2 -0
- package/src/components/contracts/shared.ts +9 -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 +21 -3
- package/src/components/forms/AGSelect.vue +20 -19
- 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 +22 -14
- package/src/components/headless/forms/AGHeadlessInput.vue +19 -6
- 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 +1 -1
- package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
- package/src/components/headless/forms/AGHeadlessSelect.ts +20 -22
- package/src/components/headless/forms/AGHeadlessSelect.vue +34 -33
- package/src/components/headless/forms/AGHeadlessSelectError.vue +2 -2
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +14 -22
- package/src/components/headless/forms/AGHeadlessSelectOptions.vue +19 -0
- package/src/components/headless/forms/AGHeadlessSelectTrigger.vue +25 -0
- package/src/components/headless/forms/composition.ts +10 -0
- package/src/components/headless/forms/index.ts +6 -3
- package/src/components/headless/modals/AGHeadlessModal.ts +25 -8
- package/src/components/headless/modals/AGHeadlessModal.vue +12 -12
- package/src/components/headless/modals/AGHeadlessModalContent.vue +25 -0
- package/src/components/headless/modals/index.ts +3 -2
- package/src/components/headless/snackbars/index.ts +25 -10
- package/src/components/index.ts +2 -0
- package/src/components/lib/AGErrorMessage.vue +4 -4
- package/src/components/lib/AGMarkdown.vue +24 -6
- package/src/components/lib/AGMeasured.vue +16 -0
- package/src/components/lib/AGProgressBar.vue +55 -0
- package/src/components/lib/AGStartupCrash.vue +1 -1
- package/src/components/lib/index.ts +2 -0
- package/src/components/modals/AGAlertModal.ts +18 -0
- package/src/components/modals/AGAlertModal.vue +3 -14
- package/src/components/modals/AGConfirmModal.ts +33 -1
- package/src/components/modals/AGConfirmModal.vue +10 -13
- package/src/components/modals/AGErrorReportModal.ts +32 -3
- package/src/components/modals/AGErrorReportModal.vue +9 -17
- package/src/components/modals/AGErrorReportModalButtons.vue +14 -12
- package/src/components/modals/AGErrorReportModalTitle.vue +2 -2
- package/src/components/modals/AGLoadingModal.ts +21 -1
- package/src/components/modals/AGLoadingModal.vue +3 -7
- package/src/components/modals/AGModal.vue +25 -22
- package/src/components/modals/AGModalContext.ts +1 -1
- package/src/components/modals/AGModalContext.vue +15 -5
- package/src/components/modals/AGModalTitle.vue +1 -1
- package/src/components/modals/AGPromptModal.ts +41 -0
- package/src/components/modals/AGPromptModal.vue +35 -0
- package/src/components/modals/index.ts +11 -20
- package/src/components/snackbars/AGSnackbar.vue +3 -9
- package/src/components/utils.ts +63 -0
- package/src/directives/index.ts +13 -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 +11 -17
- package/src/errors/utils.ts +35 -0
- package/src/forms/Form.test.ts +32 -3
- package/src/forms/Form.ts +81 -20
- 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 +8 -6
- package/src/plugins/Plugin.ts +1 -1
- package/src/plugins/index.ts +10 -7
- package/src/services/App.state.ts +27 -5
- package/src/services/App.ts +32 -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 +150 -49
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +15 -6
- 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 +233 -45
- 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 +33 -17
- 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/histoire.config.ts +0 -7
- package/noeldemartin.config.js +0 -5
- package/postcss.config.js +0 -6
- package/src/assets/histoire.css +0 -3
- package/src/components/headless/forms/AGHeadlessSelectButton.vue +0 -24
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +0 -24
- package/src/components/headless/forms/AGHeadlessSelectOptions.ts +0 -3
- package/src/components/headless/modals/AGHeadlessModalPanel.vue +0 -28
- package/src/components/headless/modals/AGHeadlessModalTitle.vue +0 -13
- package/src/components/modals/AGModal.ts +0 -10
- package/src/directives/initial-focus.ts +0 -11
- package/src/main.histoire.ts +0 -1
- package/tailwind.config.js +0 -4
- package/tsconfig.json +0 -11
- package/vite.config.ts +0 -14
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
import type { ComputedRef, DeepReadonly, Ref } from 'vue';
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
import type { Writable } from '@noeldemartin/utils';
|
|
2
3
|
|
|
3
|
-
import { stringProp } from '
|
|
4
|
+
import { mixedProp, stringProp } from '@aerogel/core/utils';
|
|
5
|
+
import { extractComponentProps } from '@aerogel/core/components/utils';
|
|
6
|
+
import type { FormFieldValue } from '@aerogel/core/forms/Form';
|
|
7
|
+
import type { HasElement } from '@aerogel/core/components/contracts/shared';
|
|
4
8
|
|
|
5
|
-
export interface IAGHeadlessInput {
|
|
9
|
+
export interface IAGHeadlessInput extends HasElement {
|
|
6
10
|
id: string;
|
|
7
11
|
name: ComputedRef<string | null>;
|
|
8
12
|
label: ComputedRef<string | null>;
|
|
9
|
-
|
|
13
|
+
description: ComputedRef<string | boolean | null>;
|
|
14
|
+
value: ComputedRef<FormFieldValue | null>;
|
|
15
|
+
required: ComputedRef<boolean | null>;
|
|
10
16
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
11
|
-
update(value:
|
|
17
|
+
update(value: FormFieldValue | null): void;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export const inputProps = {
|
|
15
21
|
name: stringProp(),
|
|
16
22
|
label: stringProp(),
|
|
23
|
+
description: stringProp(),
|
|
24
|
+
modelValue: mixedProp<FormFieldValue>([String, Number, Boolean]),
|
|
17
25
|
};
|
|
18
26
|
|
|
27
|
+
export const inputEmits = ['update:modelValue'] as const;
|
|
28
|
+
|
|
29
|
+
export function useInputEmits(): Writable<typeof inputEmits> {
|
|
30
|
+
return [...inputEmits];
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
export function useInputProps(): typeof inputProps {
|
|
20
34
|
return inputProps;
|
|
21
35
|
}
|
|
22
36
|
|
|
23
|
-
export function extractInputProps<T extends
|
|
24
|
-
|
|
37
|
+
export function extractInputProps<T extends ExtractPropTypes<typeof inputProps>>(
|
|
38
|
+
props: T,
|
|
25
39
|
): Pick<T, keyof typeof inputProps> {
|
|
26
|
-
return
|
|
27
|
-
const prop = selectProp as keyof typeof inputProps;
|
|
28
|
-
|
|
29
|
-
extractedProps[prop] = componentProps[prop];
|
|
30
|
-
|
|
31
|
-
return extractedProps;
|
|
32
|
-
}, {} as Pick<T, keyof typeof inputProps>);
|
|
40
|
+
return extractComponentProps(props, inputProps);
|
|
33
41
|
}
|
|
@@ -6,11 +6,12 @@
|
|
|
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/contracts/shared';
|
|
14
15
|
|
|
15
16
|
import { useInputProps } from './AGHeadlessInput';
|
|
16
17
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
@@ -18,9 +19,9 @@ import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
|
18
19
|
const emit = defineEmits(['update:modelValue']);
|
|
19
20
|
const props = defineProps({
|
|
20
21
|
as: stringProp('div'),
|
|
21
|
-
modelValue: mixedProp<string | number | boolean>([String, Number, Boolean]),
|
|
22
22
|
...useInputProps(),
|
|
23
23
|
});
|
|
24
|
+
const $el = ref<HTMLElement>();
|
|
24
25
|
const errors = computed(() => {
|
|
25
26
|
if (!form || !props.name) {
|
|
26
27
|
return null;
|
|
@@ -29,18 +30,27 @@ const errors = computed(() => {
|
|
|
29
30
|
return form.errors[props.name] ?? null;
|
|
30
31
|
});
|
|
31
32
|
const form = inject<Form | null>('form', null);
|
|
32
|
-
const api: IAGHeadlessInput = {
|
|
33
|
+
const api: IAGHeadlessInput & __SetsElement = {
|
|
34
|
+
$el,
|
|
33
35
|
id: `input-${uuid()}`,
|
|
34
36
|
name: computed(() => props.name),
|
|
35
37
|
label: computed(() => props.label),
|
|
38
|
+
description: computed(() => props.description),
|
|
36
39
|
value: computed(() => {
|
|
37
40
|
if (form && props.name) {
|
|
38
|
-
return form.getFieldValue(props.name)
|
|
41
|
+
return form.getFieldValue(props.name);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
return props.modelValue;
|
|
42
45
|
}),
|
|
43
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
|
+
}),
|
|
44
54
|
update(value) {
|
|
45
55
|
if (form && props.name) {
|
|
46
56
|
form.setFieldValue(props.name, value);
|
|
@@ -50,6 +60,9 @@ const api: IAGHeadlessInput = {
|
|
|
50
60
|
|
|
51
61
|
emit('update:modelValue', value);
|
|
52
62
|
},
|
|
63
|
+
__setElement(element) {
|
|
64
|
+
$el.value = element;
|
|
65
|
+
},
|
|
53
66
|
};
|
|
54
67
|
|
|
55
68
|
provide<IAGHeadlessInput>('input', api);
|
|
@@ -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/contracts/shared';
|
|
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>
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<script setup lang="ts">
|
|
10
10
|
import { computed, useSlots } from 'vue';
|
|
11
11
|
|
|
12
|
-
import { injectReactiveOrFail } from '
|
|
12
|
+
import { injectReactiveOrFail } from '@aerogel/core/utils/vue';
|
|
13
13
|
|
|
14
14
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
15
15
|
|
|
@@ -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/contracts/shared';
|
|
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>
|
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import type { ComputedRef, DeepReadonly, Ref } from 'vue';
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
import type { Writable } from '@noeldemartin/utils';
|
|
2
3
|
|
|
3
|
-
import { requiredArrayProp, stringProp } from '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value: string | number | boolean | object | null;
|
|
7
|
-
text: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type IAGSelectOptionValue = string | number | boolean | object | null;
|
|
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';
|
|
11
7
|
|
|
12
8
|
export interface IAGHeadlessSelect {
|
|
13
9
|
id: string;
|
|
14
10
|
label: ComputedRef<string | null>;
|
|
15
11
|
noSelectionText: ComputedRef<string>;
|
|
16
12
|
buttonText: ComputedRef<string>;
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
renderText: ComputedRef<(value: FormFieldValue) => string>;
|
|
14
|
+
selectedOption: ComputedRef<FormFieldValue | null>;
|
|
15
|
+
options: ComputedRef<FormFieldValue[]>;
|
|
19
16
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
20
|
-
update(value:
|
|
17
|
+
update(value: FormFieldValue): void;
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
export const selectProps = {
|
|
24
21
|
name: stringProp(),
|
|
25
22
|
label: stringProp(),
|
|
26
|
-
options: requiredArrayProp<
|
|
23
|
+
options: requiredArrayProp<FormFieldValue>(),
|
|
27
24
|
noSelectionText: stringProp(),
|
|
25
|
+
optionsText: mixedProp<string | ((option: FormFieldValue) => string)>(),
|
|
28
26
|
};
|
|
29
27
|
|
|
28
|
+
export const selectEmits = ['update:modelValue'] as const;
|
|
29
|
+
|
|
30
30
|
export function useSelectProps(): typeof selectProps {
|
|
31
31
|
return selectProps;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return Object.keys(selectProps).reduce((extractedProps, selectProp) => {
|
|
38
|
-
const prop = selectProp as keyof typeof selectProps;
|
|
39
|
-
|
|
40
|
-
extractedProps[prop] = componentProps[prop];
|
|
34
|
+
export function useSelectEmits(): Writable<typeof selectEmits> {
|
|
35
|
+
return [...selectEmits];
|
|
36
|
+
}
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
export function extractSelectProps<T extends ExtractPropTypes<typeof selectProps>>(
|
|
39
|
+
props: T,
|
|
40
|
+
): Pick<T, keyof typeof selectProps> {
|
|
41
|
+
return extractComponentProps(props, selectProps);
|
|
44
42
|
}
|
|
@@ -1,47 +1,45 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@update:model-value="update($event)"
|
|
6
|
-
>
|
|
7
|
-
<slot :value="value" :open="open" :disabled="disabled" />
|
|
8
|
-
</Listbox>
|
|
2
|
+
<SelectRoot v-slot="{ open }: ComponentProps" :model-value="selectedOption" @update:model-value="update($event)">
|
|
3
|
+
<slot :model-value="modelValue" :open="open" />
|
|
4
|
+
</SelectRoot>
|
|
9
5
|
</template>
|
|
10
6
|
|
|
11
7
|
<script setup lang="ts">
|
|
12
8
|
import { computed, inject, provide } from 'vue';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
9
|
+
import { toString, uuid } from '@noeldemartin/utils';
|
|
10
|
+
import { SelectRoot } from 'reka-ui';
|
|
11
|
+
import type { AcceptableValue } from 'reka-ui';
|
|
15
12
|
|
|
16
|
-
import { mixedProp } from '
|
|
17
|
-
import { translateWithDefault } from '
|
|
18
|
-
import type Form from '
|
|
19
|
-
import type {
|
|
13
|
+
import { mixedProp } from '@aerogel/core/utils/vue';
|
|
14
|
+
import { translateWithDefault } from '@aerogel/core/lang/utils';
|
|
15
|
+
import type Form from '@aerogel/core/forms/Form';
|
|
16
|
+
import type { FormFieldValue } from '@aerogel/core/forms/Form';
|
|
17
|
+
import type { ComponentProps } from '@aerogel/core/utils/vue';
|
|
20
18
|
|
|
21
|
-
import { useSelectProps } from './AGHeadlessSelect';
|
|
22
|
-
import type { IAGHeadlessSelect
|
|
19
|
+
import { useSelectEmits, useSelectProps } from './AGHeadlessSelect';
|
|
20
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
23
21
|
|
|
24
|
-
const emit = defineEmits(
|
|
22
|
+
const emit = defineEmits(useSelectEmits());
|
|
25
23
|
const props = defineProps({
|
|
26
|
-
modelValue: mixedProp<
|
|
24
|
+
modelValue: mixedProp<FormFieldValue>(),
|
|
27
25
|
...useSelectProps(),
|
|
28
26
|
});
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const option: IAGSelectOption = {
|
|
34
|
-
value,
|
|
35
|
-
text: toString(isObject(value) && 'text' in value ? value.text : value),
|
|
36
|
-
};
|
|
27
|
+
const renderText = computed(() => {
|
|
28
|
+
if (typeof props.optionsText === 'function') {
|
|
29
|
+
return props.optionsText;
|
|
30
|
+
}
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const selectedOptionValue = form && props.name ? form.getFieldValue(props.name) : props.modelValue;
|
|
32
|
+
if (typeof props.optionsText === 'string') {
|
|
33
|
+
return (option: FormFieldValue): string => toString(option[props.optionsText as keyof FormFieldValue]);
|
|
34
|
+
}
|
|
42
35
|
|
|
43
|
-
return
|
|
36
|
+
return (option: FormFieldValue) => toString(option);
|
|
44
37
|
});
|
|
38
|
+
const form = inject<Form | null>('form', null);
|
|
39
|
+
const noSelectionText = computed(() => props.noSelectionText ?? translateWithDefault('select.noSelection', '-'));
|
|
40
|
+
const selectedOption = computed(
|
|
41
|
+
() => (form && props.name ? form.getFieldValue(props.name) : props.modelValue) as AcceptableValue,
|
|
42
|
+
);
|
|
45
43
|
const errors = computed(() => {
|
|
46
44
|
if (!form || !props.name) {
|
|
47
45
|
return null;
|
|
@@ -50,7 +48,8 @@ const errors = computed(() => {
|
|
|
50
48
|
return form.errors[props.name] ?? null;
|
|
51
49
|
});
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
function update(value: any) {
|
|
54
53
|
if (form && props.name) {
|
|
55
54
|
form.setFieldValue(props.name, value);
|
|
56
55
|
|
|
@@ -62,12 +61,14 @@ function update(value: IAGSelectOptionValue) {
|
|
|
62
61
|
|
|
63
62
|
const api: IAGHeadlessSelect = {
|
|
64
63
|
id: `select-${uuid()}`,
|
|
65
|
-
options,
|
|
66
64
|
noSelectionText,
|
|
67
65
|
selectedOption,
|
|
68
66
|
errors,
|
|
67
|
+
options: computed(() => props.options),
|
|
69
68
|
label: computed(() => props.label),
|
|
70
|
-
buttonText: computed(() =>
|
|
69
|
+
buttonText: computed(() =>
|
|
70
|
+
selectedOption.value === null ? noSelectionText.value : renderText.value(selectedOption.value)),
|
|
71
|
+
renderText,
|
|
71
72
|
update,
|
|
72
73
|
};
|
|
73
74
|
|
|
@@ -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 { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
14
14
|
|
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[unselectedClass ?? 'unselected']: !selected,
|
|
10
|
-
}"
|
|
11
|
-
>
|
|
12
|
-
{{ option?.text }}
|
|
13
|
-
</li>
|
|
14
|
-
</slot>
|
|
15
|
-
</ListboxOption>
|
|
2
|
+
<SelectItem :value="value" as="template">
|
|
3
|
+
<SelectItemText>
|
|
4
|
+
<slot>
|
|
5
|
+
{{ select.renderText(value) }}
|
|
6
|
+
</slot>
|
|
7
|
+
</SelectItemText>
|
|
8
|
+
</SelectItem>
|
|
16
9
|
</template>
|
|
17
10
|
|
|
18
11
|
<script setup lang="ts">
|
|
19
|
-
import {
|
|
20
|
-
import { ListboxOption } from '@headlessui/vue';
|
|
12
|
+
import { SelectItem, SelectItemText } from 'reka-ui';
|
|
21
13
|
|
|
22
|
-
import { injectReactiveOrFail, requiredMixedProp, stringProp } from '
|
|
23
|
-
import type { ComponentProps } from '@/utils/vue';
|
|
14
|
+
import { injectReactiveOrFail, requiredMixedProp, stringProp } from '@aerogel/core/utils/vue';
|
|
24
15
|
|
|
25
|
-
import type { IAGHeadlessSelect
|
|
16
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
defineProps({
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
value: requiredMixedProp<any>(),
|
|
29
21
|
selectedClass: stringProp(),
|
|
30
22
|
unselectedClass: stringProp(),
|
|
31
23
|
activeClass: stringProp(),
|
|
32
24
|
inactiveClass: stringProp(),
|
|
33
25
|
});
|
|
26
|
+
|
|
34
27
|
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
35
28
|
'select',
|
|
36
29
|
'<AGHeadlessSelectOption> must be a child of a <AGHeadlessSelect>',
|
|
37
30
|
);
|
|
38
|
-
const option = computed(() => select.options.find((selectOption) => selectOption.value === props.value));
|
|
39
31
|
</script>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<SelectPortal>
|
|
3
|
+
<SelectContent :class="classes">
|
|
4
|
+
<SelectViewport>
|
|
5
|
+
<slot />
|
|
6
|
+
</SelectViewport>
|
|
7
|
+
</SelectContent>
|
|
8
|
+
</SelectPortal>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { computed } from 'vue';
|
|
13
|
+
import { SelectContent, SelectPortal, SelectViewport } from 'reka-ui';
|
|
14
|
+
|
|
15
|
+
import { stringProp } from '@aerogel/core/utils/vue';
|
|
16
|
+
|
|
17
|
+
const props = defineProps({ class: stringProp('') });
|
|
18
|
+
const classes = computed(() => props.class);
|
|
19
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<SelectTrigger>
|
|
3
|
+
<SelectValue>
|
|
4
|
+
<slot>
|
|
5
|
+
<span :class="textClass">{{ select?.buttonText }}</span>
|
|
6
|
+
</slot>
|
|
7
|
+
<slot name="icon" />
|
|
8
|
+
</SelectValue>
|
|
9
|
+
</SelectTrigger>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { SelectTrigger, SelectValue } from 'reka-ui';
|
|
14
|
+
|
|
15
|
+
import { injectReactiveOrFail, stringProp } from '@aerogel/core/utils/vue';
|
|
16
|
+
|
|
17
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
18
|
+
|
|
19
|
+
defineProps({ textClass: stringProp() });
|
|
20
|
+
|
|
21
|
+
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
22
|
+
'select',
|
|
23
|
+
'<AGHeadlessSelectTrigger> must be a child of a <AGHeadlessSelect>',
|
|
24
|
+
);
|
|
25
|
+
</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,14 +1,17 @@
|
|
|
1
|
+
export * from './composition';
|
|
2
|
+
export * from './AGHeadlessButton';
|
|
1
3
|
export * from './AGHeadlessInput';
|
|
2
4
|
export * from './AGHeadlessSelect';
|
|
3
5
|
export * from './AGHeadlessSelectOption';
|
|
4
6
|
export { default as AGHeadlessButton } from './AGHeadlessButton.vue';
|
|
5
7
|
export { default as AGHeadlessInput } from './AGHeadlessInput.vue';
|
|
8
|
+
export { default as AGHeadlessInputDescription } from './AGHeadlessInputDescription.vue';
|
|
6
9
|
export { default as AGHeadlessInputError } from './AGHeadlessInputError.vue';
|
|
7
10
|
export { default as AGHeadlessInputInput } from './AGHeadlessInputInput.vue';
|
|
8
11
|
export { default as AGHeadlessInputLabel } from './AGHeadlessInputLabel.vue';
|
|
12
|
+
export { default as AGHeadlessInputTextArea } from './AGHeadlessInputTextArea.vue';
|
|
9
13
|
export { default as AGHeadlessSelect } from './AGHeadlessSelect.vue';
|
|
10
|
-
export { default as
|
|
14
|
+
export { default as AGHeadlessSelectTrigger } from './AGHeadlessSelectTrigger.vue';
|
|
11
15
|
export { default as AGHeadlessSelectError } from './AGHeadlessSelectError.vue';
|
|
12
|
-
export { default as AGHeadlessSelectLabel } from './AGHeadlessSelectLabel.vue';
|
|
13
16
|
export { default as AGHeadlessSelectOption } from './AGHeadlessSelectOption.vue';
|
|
14
|
-
export { default as AGHeadlessSelectOptions } from './AGHeadlessSelectOptions';
|
|
17
|
+
export { default as AGHeadlessSelectOptions } from './AGHeadlessSelectOptions.vue';
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { booleanProp, stringProp } from '@aerogel/core/utils/vue';
|
|
5
|
+
import { extractComponentProps } from '@aerogel/core/components/utils';
|
|
6
|
+
import type { ComponentPropDefinitions } from '@aerogel/core/components/utils';
|
|
7
|
+
import type { ComponentProps } from '@aerogel/core/utils/vue';
|
|
8
|
+
import type { IModal, IModalProps } from '@aerogel/core/components/contracts/Modal';
|
|
9
|
+
|
|
10
|
+
export interface IAGHeadlessModal extends IModal {}
|
|
5
11
|
|
|
6
12
|
export interface IAGHeadlessModalDefaultSlotProps {
|
|
7
13
|
close(result?: unknown): Promise<void>;
|
|
8
14
|
}
|
|
9
15
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
}
|
|
16
|
+
export function extractModalProps<T extends IModalProps>(props: T): ComponentProps<IModalProps> {
|
|
17
|
+
return extractComponentProps(props, modalProps());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function modalProps(): ComponentPropDefinitions<IModalProps> {
|
|
21
|
+
return {
|
|
22
|
+
cancellable: booleanProp(true),
|
|
23
|
+
description: stringProp(),
|
|
24
|
+
title: stringProp(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
13
27
|
|
|
14
|
-
export function
|
|
15
|
-
return
|
|
28
|
+
export function modalExpose($modal: Ref<IAGHeadlessModal | undefined>): IModal {
|
|
29
|
+
return {
|
|
30
|
+
cancellable: computed(() => !!$modal.value?.cancellable),
|
|
31
|
+
close: async () => $modal.value?.close(),
|
|
32
|
+
};
|
|
16
33
|
}
|