@aerogel/core 0.0.0-next.a56c0f4966eb71571173f8502f3f36d357ceebc7 → 0.0.0-next.a68f133e2c9a1ae9ba84b4e2e42df909289e5fba
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 +615 -133
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/bootstrap/bootstrap.test.ts +3 -3
- package/src/bootstrap/index.ts +13 -3
- package/src/bootstrap/options.ts +3 -0
- package/src/components/AGAppLayout.vue +3 -2
- package/src/components/AGAppOverlays.vue +5 -1
- package/src/components/forms/AGCheckbox.vue +7 -1
- package/src/components/forms/AGInput.vue +8 -6
- package/src/components/forms/AGSelect.story.vue +21 -3
- package/src/components/forms/AGSelect.vue +10 -3
- package/src/components/headless/forms/AGHeadlessInput.ts +21 -1
- package/src/components/headless/forms/AGHeadlessInput.vue +4 -1
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
- package/src/components/headless/forms/AGHeadlessSelect.ts +21 -22
- package/src/components/headless/forms/AGHeadlessSelect.vue +24 -24
- package/src/components/headless/forms/AGHeadlessSelectLabel.vue +4 -1
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +6 -6
- package/src/components/headless/modals/AGHeadlessModal.ts +27 -0
- package/src/components/headless/modals/AGHeadlessModal.vue +3 -5
- package/src/components/headless/modals/index.ts +4 -6
- package/src/components/headless/snackbars/index.ts +23 -8
- package/src/components/lib/AGMeasured.vue +15 -0
- package/src/components/lib/index.ts +1 -0
- package/src/components/modals/AGAlertModal.ts +15 -0
- package/src/components/modals/AGAlertModal.vue +3 -14
- package/src/components/modals/AGConfirmModal.ts +27 -0
- package/src/components/modals/AGConfirmModal.vue +7 -11
- package/src/components/modals/AGErrorReportModal.ts +27 -1
- package/src/components/modals/AGErrorReportModal.vue +7 -15
- package/src/components/modals/AGErrorReportModalButtons.vue +4 -2
- package/src/components/modals/AGLoadingModal.ts +23 -0
- package/src/components/modals/AGLoadingModal.vue +3 -7
- package/src/components/modals/AGModal.ts +2 -2
- package/src/components/modals/AGModal.vue +14 -12
- package/src/components/modals/AGPromptModal.ts +30 -0
- package/src/components/modals/AGPromptModal.vue +34 -0
- package/src/components/modals/index.ts +13 -19
- package/src/components/snackbars/AGSnackbar.vue +2 -8
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +3 -1
- package/src/directives/measure.ts +12 -0
- package/src/errors/Errors.ts +17 -8
- package/src/errors/index.ts +1 -11
- package/src/forms/Form.ts +1 -0
- package/src/lang/Lang.ts +1 -1
- package/src/services/App.state.ts +1 -2
- package/src/services/App.ts +21 -3
- package/src/services/Events.ts +1 -1
- package/src/services/Service.ts +44 -14
- package/src/services/index.ts +2 -1
- package/src/services/store.ts +8 -5
- package/src/ui/UI.ts +93 -12
- package/src/ui/index.ts +8 -3
- package/src/utils/composition/events.ts +1 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tailwindcss.test.ts +26 -0
- package/src/utils/tailwindcss.ts +7 -0
- package/src/utils/vue.ts +10 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerogel/core",
|
|
3
3
|
"description": "The Lightest Solid",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.a68f133e2c9a1ae9ba84b4e2e42df909289e5fba",
|
|
5
5
|
"main": "dist/aerogel-core.cjs.js",
|
|
6
6
|
"module": "dist/aerogel-core.esm.js",
|
|
7
7
|
"types": "dist/aerogel-core.d.ts",
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"build": "rm dist -rf && npm run build:js && npm run build:types",
|
|
11
11
|
"build:js": "noeldemartin-build-javascript",
|
|
12
12
|
"build:types": "noeldemartin-build-types",
|
|
13
|
-
"histoire
|
|
14
|
-
"histoire:prod": "histoire build",
|
|
13
|
+
"histoire": "histoire dev",
|
|
15
14
|
"lint": "noeldemartin-lint src",
|
|
16
15
|
"publish-next": "noeldemartin-publish-next",
|
|
17
16
|
"test": "vitest --run",
|
|
@@ -36,7 +35,7 @@
|
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"@headlessui/vue": "^1.7.14",
|
|
39
|
-
"@noeldemartin/utils": "0.5.
|
|
38
|
+
"@noeldemartin/utils": "0.5.1-next.49cc6c9b4a20930cbf922a949135981791acc5c3",
|
|
40
39
|
"dompurify": "^3.0.3",
|
|
41
40
|
"marked": "^5.0.4",
|
|
42
41
|
"pinia": "^2.1.6",
|
|
@@ -44,6 +43,7 @@
|
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@aerogel/vite": "*",
|
|
46
|
+
"@histoire/plugin-vue": "^0.17.6",
|
|
47
47
|
"@types/dompurify": "^3.0.2",
|
|
48
48
|
"@types/marked": "^5.0.0",
|
|
49
49
|
"tailwindcss": "^3.3.5"
|
|
@@ -6,7 +6,7 @@ import type { Component } from 'vue';
|
|
|
6
6
|
import Events from '@/services/Events';
|
|
7
7
|
import initialFocus from '@/directives/initial-focus';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { bootstrap } from './index';
|
|
10
10
|
|
|
11
11
|
describe('Aerogel', () => {
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ describe('Aerogel', () => {
|
|
|
32
32
|
const rootComponent = mock<Component>();
|
|
33
33
|
|
|
34
34
|
// Act
|
|
35
|
-
await
|
|
35
|
+
await bootstrap(rootComponent);
|
|
36
36
|
|
|
37
37
|
// Assert
|
|
38
38
|
const globals = vi.mocked(createApp).mock.results[0]?.value.config.globalProperties;
|
|
@@ -46,7 +46,7 @@ describe('Aerogel', () => {
|
|
|
46
46
|
const rootComponent = mock<Component>();
|
|
47
47
|
|
|
48
48
|
// Act
|
|
49
|
-
await
|
|
49
|
+
await bootstrap(rootComponent);
|
|
50
50
|
|
|
51
51
|
// Assert
|
|
52
52
|
expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith(
|
package/src/bootstrap/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createApp } from 'vue';
|
|
2
|
-
import type { Component } from 'vue';
|
|
2
|
+
import type { App, Component } from 'vue';
|
|
3
3
|
|
|
4
4
|
import directives from '@/directives';
|
|
5
5
|
import errors from '@/errors';
|
|
@@ -10,11 +10,21 @@ import ui from '@/ui';
|
|
|
10
10
|
import { installPlugins } from '@/plugins';
|
|
11
11
|
import type { AerogelOptions } from '@/bootstrap/options';
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export { AerogelOptions };
|
|
14
|
+
|
|
15
|
+
export async function bootstrapApplication(app: App, options: AerogelOptions = {}): Promise<void> {
|
|
14
16
|
const plugins = [directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
15
|
-
const app = createApp(rootComponent);
|
|
16
17
|
|
|
17
18
|
await installPlugins(plugins, app, options);
|
|
19
|
+
await options.install?.(app);
|
|
20
|
+
|
|
21
|
+
Events.emit('application-ready');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function bootstrap(rootComponent: Component, options: AerogelOptions = {}): Promise<void> {
|
|
25
|
+
const app = createApp(rootComponent);
|
|
26
|
+
|
|
27
|
+
await bootstrapApplication(app, options);
|
|
18
28
|
|
|
19
29
|
app.mount('#app');
|
|
20
30
|
app._container?.classList.remove('loading');
|
package/src/bootstrap/options.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="flex min-h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased">
|
|
3
3
|
<slot v-if="$errors.hasStartupErrors" name="startup-crash">
|
|
4
|
-
<
|
|
4
|
+
<component :is="$ui.requireComponent(UIComponents.StartupCrash)" />
|
|
5
5
|
</slot>
|
|
6
6
|
<slot v-else />
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
</template>
|
|
11
11
|
|
|
12
12
|
<script setup lang="ts">
|
|
13
|
+
import { UIComponents } from '@/ui/UI';
|
|
14
|
+
|
|
13
15
|
import AGAppOverlays from './AGAppOverlays.vue';
|
|
14
|
-
import AGStartupCrash from './lib/AGStartupCrash.vue';
|
|
15
16
|
</script>
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div
|
|
2
|
+
<div
|
|
3
|
+
id="aerogel-overlays-backdrop"
|
|
4
|
+
ref="$backdrop"
|
|
5
|
+
class="pointer-events-none fixed inset-0 z-50 bg-black/30 opacity-0"
|
|
6
|
+
/>
|
|
3
7
|
<AGAppModals />
|
|
4
8
|
<AGAppSnackbars />
|
|
5
9
|
</template>
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<AGHeadlessInput
|
|
2
|
+
<AGHeadlessInput
|
|
3
|
+
ref="$input"
|
|
4
|
+
:name="name"
|
|
5
|
+
class="flex"
|
|
6
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
7
|
+
>
|
|
3
8
|
<AGHeadlessInputInput
|
|
4
9
|
v-bind="$attrs"
|
|
5
10
|
type="checkbox"
|
|
@@ -30,6 +35,7 @@ import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
|
|
|
30
35
|
|
|
31
36
|
defineProps({ name: stringProp() });
|
|
32
37
|
defineOptions({ inheritAttrs: false });
|
|
38
|
+
defineEmits(['update:modelValue']);
|
|
33
39
|
|
|
34
40
|
const $input = componentRef<IAGHeadlessInput>();
|
|
35
41
|
</script>
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
ref="$input"
|
|
4
4
|
class="relative flex flex-col items-center"
|
|
5
5
|
:class="className"
|
|
6
|
-
|
|
6
|
+
v-bind="props"
|
|
7
7
|
>
|
|
8
|
+
<AGHeadlessInputLabel class="sr-only" />
|
|
8
9
|
<AGHeadlessInputInput
|
|
9
10
|
v-bind="attrs"
|
|
10
11
|
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"
|
|
@@ -19,18 +20,19 @@
|
|
|
19
20
|
</template>
|
|
20
21
|
|
|
21
22
|
<script setup lang="ts">
|
|
22
|
-
import { componentRef
|
|
23
|
-
|
|
24
|
-
import {
|
|
23
|
+
import { componentRef } from '@/utils/vue';
|
|
24
|
+
import { useInputAttrs } from '@/utils/composition/forms';
|
|
25
|
+
import { useInputProps } from '@/components/headless/forms/AGHeadlessInput';
|
|
25
26
|
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
26
27
|
|
|
27
28
|
import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
|
|
28
|
-
import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
|
|
29
29
|
import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
|
|
30
|
+
import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
|
|
31
|
+
import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
|
|
30
32
|
|
|
31
|
-
defineProps({ name: stringProp() });
|
|
32
33
|
defineOptions({ inheritAttrs: false });
|
|
33
34
|
|
|
35
|
+
const props = defineProps(useInputProps());
|
|
34
36
|
const $input = componentRef<IAGHeadlessInput>();
|
|
35
37
|
const [attrs, className] = useInputAttrs();
|
|
36
38
|
</script>
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<Story>
|
|
3
3
|
<div class="h-96">
|
|
4
|
-
<AGSelect v-model="bestMugiwara" :label="
|
|
4
|
+
<AGSelect v-model="bestMugiwara" :label="bestMugiwaraLabel" :options="bestMugiwaraOptions" />
|
|
5
|
+
<AGSelect
|
|
6
|
+
v-model="bestFood"
|
|
7
|
+
:label="bestFoodLabel"
|
|
8
|
+
:options="bestFoodOptions"
|
|
9
|
+
options-text="name"
|
|
10
|
+
/>
|
|
5
11
|
</div>
|
|
6
12
|
</Story>
|
|
7
13
|
</template>
|
|
@@ -12,8 +18,10 @@ import { ref } from 'vue';
|
|
|
12
18
|
import AGSelect from './AGSelect.vue';
|
|
13
19
|
|
|
14
20
|
const bestMugiwara = ref(null);
|
|
15
|
-
const
|
|
16
|
-
const
|
|
21
|
+
const bestFood = ref(null);
|
|
22
|
+
const bestMugiwaraLabel = 'Who\'s the best Mugiwara?';
|
|
23
|
+
const bestFoodLabel = 'What\'s the best food?';
|
|
24
|
+
const bestMugiwaraOptions = [
|
|
17
25
|
'Monkey D. Luffy',
|
|
18
26
|
'Roronoa Zoro',
|
|
19
27
|
'Nami',
|
|
@@ -25,4 +33,14 @@ const options = [
|
|
|
25
33
|
'Brook',
|
|
26
34
|
'Jinbe',
|
|
27
35
|
];
|
|
36
|
+
const bestFoodOptions = [
|
|
37
|
+
{
|
|
38
|
+
id: 'ramen',
|
|
39
|
+
name: 'Ramen',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'pizza',
|
|
43
|
+
name: 'Pizza',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
28
46
|
</script>
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<AGHeadlessSelect
|
|
2
|
+
<AGHeadlessSelect
|
|
3
|
+
v-bind="props"
|
|
4
|
+
ref="$select"
|
|
5
|
+
as="div"
|
|
6
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
7
|
+
>
|
|
3
8
|
<AGHeadlessSelectLabel class="block text-sm font-medium leading-6 text-gray-900" />
|
|
4
9
|
<div class="relative" :class="{ 'mt-2': $select?.label }">
|
|
5
10
|
<AGHeadlessSelectButton
|
|
@@ -21,7 +26,7 @@
|
|
|
21
26
|
<AGHeadlessSelectOption
|
|
22
27
|
v-for="(option, index) in $select?.options ?? []"
|
|
23
28
|
:key="index"
|
|
24
|
-
:value="option
|
|
29
|
+
:value="option"
|
|
25
30
|
class="relative block cursor-default select-none truncate py-2 pl-3 pr-9"
|
|
26
31
|
selected-class="font-semibold"
|
|
27
32
|
unselected-class="font-normal"
|
|
@@ -38,7 +43,7 @@
|
|
|
38
43
|
import IconCheveronDown from '~icons/zondicons/cheveron-down';
|
|
39
44
|
|
|
40
45
|
import { componentRef } from '@/utils/vue';
|
|
41
|
-
import { useSelectProps } from '@/components/headless/forms/AGHeadlessSelect';
|
|
46
|
+
import { useSelectEmits, useSelectProps } from '@/components/headless/forms/AGHeadlessSelect';
|
|
42
47
|
import type { IAGHeadlessSelect } from '@/components/headless/forms/AGHeadlessSelect';
|
|
43
48
|
|
|
44
49
|
import AGHeadlessSelect from '../headless/forms/AGHeadlessSelect.vue';
|
|
@@ -48,6 +53,8 @@ import AGHeadlessSelectLabel from '../headless/forms/AGHeadlessSelectLabel.vue';
|
|
|
48
53
|
import AGHeadlessSelectOption from '../headless/forms/AGHeadlessSelectOption.vue';
|
|
49
54
|
import AGHeadlessSelectOptions from '../headless/forms/AGHeadlessSelectOptions';
|
|
50
55
|
|
|
56
|
+
defineEmits(useSelectEmits());
|
|
57
|
+
|
|
51
58
|
const props = defineProps(useSelectProps());
|
|
52
59
|
const $select = componentRef<IAGHeadlessSelect>();
|
|
53
60
|
</script>
|
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
import type { ComputedRef, DeepReadonly, Ref } from 'vue';
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { stringProp } from '@/utils';
|
|
4
|
+
import { extractComponentProps } from '@/components/utils';
|
|
2
5
|
|
|
3
6
|
export interface IAGHeadlessInput {
|
|
4
7
|
id: string;
|
|
8
|
+
name: ComputedRef<string | null>;
|
|
9
|
+
label: ComputedRef<string | null>;
|
|
5
10
|
value: ComputedRef<string | number | boolean | null>;
|
|
6
11
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
7
12
|
update(value: string | number | boolean | null): void;
|
|
8
13
|
}
|
|
14
|
+
|
|
15
|
+
export const inputProps = {
|
|
16
|
+
name: stringProp(),
|
|
17
|
+
label: stringProp(),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function useInputProps(): typeof inputProps {
|
|
21
|
+
return inputProps;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function extractInputProps<T extends ExtractPropTypes<typeof inputProps>>(
|
|
25
|
+
props: T,
|
|
26
|
+
): Pick<T, keyof typeof inputProps> {
|
|
27
|
+
return extractComponentProps(props, inputProps);
|
|
28
|
+
}
|
|
@@ -12,13 +12,14 @@ import { uuid } from '@noeldemartin/utils';
|
|
|
12
12
|
import { mixedProp, stringProp } from '@/utils/vue';
|
|
13
13
|
import type Form from '@/forms/Form';
|
|
14
14
|
|
|
15
|
+
import { useInputProps } from './AGHeadlessInput';
|
|
15
16
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
16
17
|
|
|
17
18
|
const emit = defineEmits(['update:modelValue']);
|
|
18
19
|
const props = defineProps({
|
|
19
20
|
as: stringProp('div'),
|
|
20
|
-
name: stringProp(),
|
|
21
21
|
modelValue: mixedProp<string | number | boolean>([String, Number, Boolean]),
|
|
22
|
+
...useInputProps(),
|
|
22
23
|
});
|
|
23
24
|
const errors = computed(() => {
|
|
24
25
|
if (!form || !props.name) {
|
|
@@ -30,6 +31,8 @@ const errors = computed(() => {
|
|
|
30
31
|
const form = inject<Form | null>('form', null);
|
|
31
32
|
const api: IAGHeadlessInput = {
|
|
32
33
|
id: `input-${uuid()}`,
|
|
34
|
+
name: computed(() => props.name),
|
|
35
|
+
label: computed(() => props.label),
|
|
33
36
|
value: computed(() => {
|
|
34
37
|
if (form && props.name) {
|
|
35
38
|
return form.getFieldValue(props.name) as string | number | boolean | null;
|
|
@@ -1,10 +1,14 @@
|
|
|
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">
|
|
10
|
+
import { computed, useSlots } from 'vue';
|
|
11
|
+
|
|
8
12
|
import { injectReactiveOrFail } from '@/utils/vue';
|
|
9
13
|
|
|
10
14
|
import type { IAGHeadlessInput } from './AGHeadlessInput';
|
|
@@ -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>
|
|
@@ -1,43 +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 '@/utils/vue';
|
|
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 '@/utils/vue';
|
|
5
|
+
import { extractComponentProps } from '@/components/utils';
|
|
6
|
+
import type { FormFieldValue } from '@/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(),
|
|
23
|
+
options: requiredArrayProp<FormFieldValue>(),
|
|
26
24
|
noSelectionText: stringProp(),
|
|
25
|
+
optionsText: mixedProp<string | ((option: FormFieldValue) => string)>(),
|
|
27
26
|
};
|
|
28
27
|
|
|
28
|
+
export const selectEmits = ['update:modelValue'] as const;
|
|
29
|
+
|
|
29
30
|
export function useSelectProps(): typeof selectProps {
|
|
30
31
|
return selectProps;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return Object.keys(selectProps).reduce((extractedProps, selectProp) => {
|
|
37
|
-
const prop = selectProp as keyof typeof selectProps;
|
|
38
|
-
|
|
39
|
-
extractedProps[prop] = componentProps[prop];
|
|
34
|
+
export function useSelectEmits(): Writable<typeof selectEmits> {
|
|
35
|
+
return [...selectEmits];
|
|
36
|
+
}
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
export function extractSelectProps<T extends ExtractPropTypes<typeof selectProps>>(
|
|
39
|
+
props: T,
|
|
40
|
+
): Pick<T, keyof typeof selectProps> {
|
|
41
|
+
return extractComponentProps(props, selectProps);
|
|
43
42
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<Listbox
|
|
3
3
|
v-slot="{ value, open, disabled }: ComponentProps"
|
|
4
|
-
:model-value="selectedOption
|
|
4
|
+
:model-value="selectedOption"
|
|
5
5
|
@update:model-value="update($event)"
|
|
6
6
|
>
|
|
7
7
|
<slot :value="value" :open="open" :disabled="disabled" />
|
|
@@ -10,39 +10,37 @@
|
|
|
10
10
|
|
|
11
11
|
<script setup lang="ts">
|
|
12
12
|
import { computed, inject, provide } from 'vue';
|
|
13
|
-
import {
|
|
13
|
+
import { toString, uuid } from '@noeldemartin/utils';
|
|
14
14
|
import { Listbox } from '@headlessui/vue';
|
|
15
15
|
|
|
16
|
-
import { mixedProp
|
|
16
|
+
import { mixedProp } from '@/utils/vue';
|
|
17
17
|
import { translateWithDefault } from '@/lang/utils';
|
|
18
18
|
import type Form from '@/forms/Form';
|
|
19
|
+
import type { FormFieldValue } from '@/forms/Form';
|
|
19
20
|
import type { ComponentProps } from '@/utils/vue';
|
|
20
21
|
|
|
21
|
-
import { useSelectProps } from './AGHeadlessSelect';
|
|
22
|
-
import type { IAGHeadlessSelect
|
|
22
|
+
import { useSelectEmits, useSelectProps } from './AGHeadlessSelect';
|
|
23
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
23
24
|
|
|
24
|
-
const emit = defineEmits(
|
|
25
|
+
const emit = defineEmits(useSelectEmits());
|
|
25
26
|
const props = defineProps({
|
|
26
|
-
|
|
27
|
-
modelValue: mixedProp<IAGSelectOptionValue>(),
|
|
27
|
+
modelValue: mixedProp<FormFieldValue>(),
|
|
28
28
|
...useSelectProps(),
|
|
29
29
|
});
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const option: IAGSelectOption = {
|
|
35
|
-
value,
|
|
36
|
-
text: toString(isObject(value) && 'text' in value ? value.text : value),
|
|
37
|
-
};
|
|
30
|
+
const renderText = computed(() => {
|
|
31
|
+
if (typeof props.optionsText === 'function') {
|
|
32
|
+
return props.optionsText;
|
|
33
|
+
}
|
|
38
34
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const selectedOptionValue = form && props.name ? form.getFieldValue(props.name) : props.modelValue;
|
|
35
|
+
if (typeof props.optionsText === 'string') {
|
|
36
|
+
return (option: FormFieldValue): string => toString(option[props.optionsText as keyof FormFieldValue]);
|
|
37
|
+
}
|
|
43
38
|
|
|
44
|
-
return
|
|
39
|
+
return (option: FormFieldValue) => toString(option);
|
|
45
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));
|
|
46
44
|
const errors = computed(() => {
|
|
47
45
|
if (!form || !props.name) {
|
|
48
46
|
return null;
|
|
@@ -51,7 +49,7 @@ const errors = computed(() => {
|
|
|
51
49
|
return form.errors[props.name] ?? null;
|
|
52
50
|
});
|
|
53
51
|
|
|
54
|
-
function update(value:
|
|
52
|
+
function update(value: FormFieldValue) {
|
|
55
53
|
if (form && props.name) {
|
|
56
54
|
form.setFieldValue(props.name, value);
|
|
57
55
|
|
|
@@ -63,12 +61,14 @@ function update(value: IAGSelectOptionValue) {
|
|
|
63
61
|
|
|
64
62
|
const api: IAGHeadlessSelect = {
|
|
65
63
|
id: `select-${uuid()}`,
|
|
66
|
-
options,
|
|
67
64
|
noSelectionText,
|
|
68
65
|
selectedOption,
|
|
69
66
|
errors,
|
|
67
|
+
options: computed(() => props.options),
|
|
70
68
|
label: computed(() => props.label),
|
|
71
|
-
buttonText: computed(() =>
|
|
69
|
+
buttonText: computed(() =>
|
|
70
|
+
selectedOption.value === null ? noSelectionText.value : renderText.value(selectedOption.value)),
|
|
71
|
+
renderText,
|
|
72
72
|
update,
|
|
73
73
|
};
|
|
74
74
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<ListboxLabel v-if="
|
|
2
|
+
<ListboxLabel v-if="show" v-slot="{ open, disabled }: ComponentProps">
|
|
3
3
|
<slot :open="open" :disabled="disabled">
|
|
4
4
|
{{ select.label }}
|
|
5
5
|
</slot>
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script setup lang="ts">
|
|
10
|
+
import { computed, useSlots } from 'vue';
|
|
10
11
|
import { ListboxLabel } from '@headlessui/vue';
|
|
11
12
|
|
|
12
13
|
import { injectReactiveOrFail } from '@/utils/vue';
|
|
@@ -18,4 +19,6 @@ const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
|
18
19
|
'select',
|
|
19
20
|
'<AGHeadlessSelectLabel> must be a child of a <AGHeadlessSelect>',
|
|
20
21
|
);
|
|
22
|
+
const slots = useSlots();
|
|
23
|
+
const show = computed(() => !!(select.label || slots.default));
|
|
21
24
|
</script>
|
|
@@ -9,31 +9,31 @@
|
|
|
9
9
|
[unselectedClass ?? 'unselected']: !selected,
|
|
10
10
|
}"
|
|
11
11
|
>
|
|
12
|
-
{{
|
|
12
|
+
{{ select.renderText(value) }}
|
|
13
13
|
</li>
|
|
14
14
|
</slot>
|
|
15
15
|
</ListboxOption>
|
|
16
16
|
</template>
|
|
17
17
|
|
|
18
18
|
<script setup lang="ts">
|
|
19
|
-
import { computed } from 'vue';
|
|
20
19
|
import { ListboxOption } from '@headlessui/vue';
|
|
21
20
|
|
|
22
21
|
import { injectReactiveOrFail, requiredMixedProp, stringProp } from '@/utils/vue';
|
|
23
22
|
import type { ComponentProps } from '@/utils/vue';
|
|
23
|
+
import type { FormFieldValue } from '@/forms/Form';
|
|
24
24
|
|
|
25
|
-
import type { IAGHeadlessSelect
|
|
25
|
+
import type { IAGHeadlessSelect } from './AGHeadlessSelect';
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
value: requiredMixedProp<
|
|
27
|
+
defineProps({
|
|
28
|
+
value: requiredMixedProp<FormFieldValue>(),
|
|
29
29
|
selectedClass: stringProp(),
|
|
30
30
|
unselectedClass: stringProp(),
|
|
31
31
|
activeClass: stringProp(),
|
|
32
32
|
inactiveClass: stringProp(),
|
|
33
33
|
});
|
|
34
|
+
|
|
34
35
|
const select = injectReactiveOrFail<IAGHeadlessSelect>(
|
|
35
36
|
'select',
|
|
36
37
|
'<AGHeadlessSelectOption> must be a child of a <AGHeadlessSelect>',
|
|
37
38
|
);
|
|
38
|
-
const option = computed(() => select.options.find((selectOption) => selectOption.value === props.value));
|
|
39
39
|
</script>
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import type { ExtractPropTypes, Ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
import { booleanProp, stringProp } from '@/utils';
|
|
5
|
+
import { extractComponentProps } from '@/components/utils';
|
|
1
6
|
import type { IAGModal } from '@/components/modals/AGModal';
|
|
2
7
|
|
|
3
8
|
export interface IAGHeadlessModal extends IAGModal {}
|
|
@@ -5,3 +10,25 @@ export interface IAGHeadlessModal extends IAGModal {}
|
|
|
5
10
|
export interface IAGHeadlessModalDefaultSlotProps {
|
|
6
11
|
close(result?: unknown): Promise<void>;
|
|
7
12
|
}
|
|
13
|
+
|
|
14
|
+
export const modalProps = {
|
|
15
|
+
cancellable: booleanProp(true),
|
|
16
|
+
title: stringProp(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function useModalProps(): typeof modalProps {
|
|
20
|
+
return modalProps;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function extractModalProps<T extends ExtractPropTypes<typeof modalProps>>(
|
|
24
|
+
props: T,
|
|
25
|
+
): Pick<T, keyof typeof modalProps> {
|
|
26
|
+
return extractComponentProps(props, modalProps);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function useModalExpose($modal: Ref<IAGHeadlessModal | undefined>): IAGModal {
|
|
30
|
+
return {
|
|
31
|
+
close: async () => $modal.value?.close(),
|
|
32
|
+
cancellable: computed(() => !!$modal.value?.cancellable),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -11,15 +11,13 @@ import type { VNode } from 'vue';
|
|
|
11
11
|
|
|
12
12
|
import Events from '@/services/Events';
|
|
13
13
|
import { useEvent } from '@/utils/composition/events';
|
|
14
|
-
import {
|
|
14
|
+
import { injectReactiveOrFail } from '@/utils/vue';
|
|
15
15
|
import type { IAGModalContext } from '@/components/modals/AGModalContext';
|
|
16
16
|
|
|
17
|
+
import { useModalProps } from './AGHeadlessModal';
|
|
17
18
|
import type { IAGHeadlessModal, IAGHeadlessModalDefaultSlotProps } from './AGHeadlessModal';
|
|
18
19
|
|
|
19
|
-
const props = defineProps(
|
|
20
|
-
cancellable: booleanProp(true),
|
|
21
|
-
});
|
|
22
|
-
|
|
20
|
+
const props = defineProps(useModalProps());
|
|
23
21
|
const $root = ref<{ $el?: HTMLElement } | null>(null);
|
|
24
22
|
const hidden = ref(true);
|
|
25
23
|
const closed = ref(false);
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { AGHeadlessModal, AGHeadlessModalPanel, AGHeadlessModalTitle, IAGHeadlessModal };
|
|
1
|
+
export * from './AGHeadlessModal';
|
|
2
|
+
export { default as AGHeadlessModal } from './AGHeadlessModal.vue';
|
|
3
|
+
export { default as AGHeadlessModalPanel } from './AGHeadlessModalPanel.vue';
|
|
4
|
+
export { default as AGHeadlessModalTitle } from './AGHeadlessModalTitle.vue';
|