@aerogel/core 0.0.0-next.8e6b2bcc764fa682decbb41aa6848c77a744dec3 → 0.0.0-next.906ec80f260b7e5cb54a0c97bd4905bdaf4bf916
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 +653 -91
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/bootstrap/bootstrap.test.ts +0 -1
- package/src/bootstrap/index.ts +12 -2
- package/src/components/AGAppSnackbars.vue +1 -1
- package/src/components/composition.ts +23 -0
- package/src/components/forms/AGForm.vue +9 -10
- package/src/components/forms/AGInput.vue +2 -0
- package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
- package/src/components/headless/forms/AGHeadlessButton.vue +15 -4
- package/src/components/headless/forms/AGHeadlessInput.ts +10 -4
- package/src/components/headless/forms/AGHeadlessInput.vue +18 -5
- package/src/components/headless/forms/AGHeadlessInputDescription.vue +28 -0
- package/src/components/headless/forms/AGHeadlessInputInput.vue +42 -5
- package/src/components/headless/forms/AGHeadlessInputTextArea.vue +43 -0
- package/src/components/headless/forms/composition.ts +10 -0
- package/src/components/headless/forms/index.ts +4 -0
- package/src/components/headless/modals/AGHeadlessModal.ts +3 -1
- package/src/components/headless/modals/AGHeadlessModal.vue +10 -4
- package/src/components/headless/modals/AGHeadlessModalPanel.vue +10 -6
- package/src/components/headless/modals/AGHeadlessModalTitle.vue +14 -4
- package/src/components/index.ts +2 -0
- package/src/components/interfaces.ts +24 -0
- package/src/components/lib/AGMarkdown.vue +22 -4
- package/src/components/lib/AGMeasured.vue +1 -0
- package/src/components/lib/AGProgressBar.vue +55 -0
- package/src/components/lib/index.ts +1 -0
- package/src/components/modals/AGAlertModal.ts +5 -2
- package/src/components/modals/AGConfirmModal.ts +18 -3
- package/src/components/modals/AGConfirmModal.vue +3 -3
- package/src/components/modals/AGErrorReportModal.ts +5 -2
- package/src/components/modals/AGLoadingModal.ts +10 -4
- package/src/components/modals/AGModal.ts +1 -0
- package/src/components/modals/AGModalContext.vue +14 -4
- package/src/components/modals/AGPromptModal.ts +14 -3
- package/src/components/modals/AGPromptModal.vue +2 -2
- package/src/directives/measure.ts +24 -5
- package/src/errors/JobCancelledError.ts +3 -0
- package/src/errors/index.ts +2 -0
- package/src/errors/utils.ts +16 -0
- package/src/forms/Form.test.ts +28 -0
- package/src/forms/Form.ts +65 -8
- package/src/forms/index.ts +3 -1
- package/src/forms/utils.ts +34 -3
- package/src/forms/validation.ts +19 -0
- package/src/jobs/Job.ts +144 -2
- package/src/jobs/index.ts +4 -1
- package/src/jobs/listeners.ts +3 -0
- package/src/jobs/status.ts +4 -0
- package/src/lang/DefaultLangProvider.ts +43 -0
- package/src/lang/Lang.state.ts +11 -0
- package/src/lang/Lang.ts +48 -21
- package/src/services/App.state.ts +22 -0
- package/src/services/App.ts +8 -0
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.ts +13 -3
- package/src/services/Service.ts +116 -45
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +9 -2
- package/src/services/utils.ts +18 -0
- package/src/testing/setup.ts +27 -0
- package/src/ui/UI.state.ts +7 -0
- package/src/ui/UI.ts +145 -44
- package/src/ui/index.ts +1 -0
- package/src/ui/utils.ts +16 -0
- 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 +2 -0
- package/src/utils/markdown.test.ts +50 -0
- package/src/utils/markdown.ts +17 -2
- package/src/utils/vue.ts +15 -3
- package/vite.config.ts +4 -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.906ec80f260b7e5cb54a0c97bd4905bdaf4bf916",
|
|
5
5
|
"main": "dist/aerogel-core.cjs.js",
|
|
6
6
|
"module": "dist/aerogel-core.esm.js",
|
|
7
7
|
"types": "dist/aerogel-core.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@headlessui/vue": "^1.7.14",
|
|
38
|
-
"@noeldemartin/utils": "0.
|
|
38
|
+
"@noeldemartin/utils": "0.6.0-next.036a147180df61c600c4599df30816ac860dbf06",
|
|
39
39
|
"dompurify": "^3.0.3",
|
|
40
40
|
"marked": "^5.0.4",
|
|
41
41
|
"pinia": "^2.1.6",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@aerogel/vite": "*",
|
|
46
|
-
"@histoire/plugin-vue": "
|
|
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"
|
package/src/bootstrap/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import Aerogel from 'virtual:aerogel';
|
|
2
|
+
|
|
1
3
|
import { createApp } from 'vue';
|
|
2
|
-
import type { App, Component } from 'vue';
|
|
4
|
+
import type { App as AppInstance, Component } from 'vue';
|
|
3
5
|
|
|
6
|
+
import App from '@/services/App';
|
|
4
7
|
import directives from '@/directives';
|
|
5
8
|
import errors from '@/errors';
|
|
6
9
|
import Events from '@/services/Events';
|
|
@@ -13,9 +16,11 @@ import type { AerogelOptions } from '@/bootstrap/options';
|
|
|
13
16
|
|
|
14
17
|
export { AerogelOptions };
|
|
15
18
|
|
|
16
|
-
export async function bootstrapApplication(app:
|
|
19
|
+
export async function bootstrapApplication(app: AppInstance, options: AerogelOptions = {}): Promise<void> {
|
|
17
20
|
const plugins = [testing, directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
18
21
|
|
|
22
|
+
App.instance = app;
|
|
23
|
+
|
|
19
24
|
await installPlugins(plugins, app, options);
|
|
20
25
|
await options.install?.(app);
|
|
21
26
|
await Events.emit('application-ready');
|
|
@@ -24,6 +29,11 @@ export async function bootstrapApplication(app: App, options: AerogelOptions = {
|
|
|
24
29
|
export async function bootstrap(rootComponent: Component, options: AerogelOptions = {}): Promise<void> {
|
|
25
30
|
const app = createApp(rootComponent);
|
|
26
31
|
|
|
32
|
+
if (Aerogel.environment === 'development') {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
(window as any).$aerogel = app;
|
|
35
|
+
}
|
|
36
|
+
|
|
27
37
|
await bootstrapApplication(app, options);
|
|
28
38
|
|
|
29
39
|
app.mount('#app');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div aria-live="assertive" class="
|
|
2
|
+
<div aria-live="assertive" class="pointer-events-none fixed inset-0 z-50 flex items-end px-4 py-6 sm:p-6">
|
|
3
3
|
<div class="flex w-full flex-col items-end space-y-4">
|
|
4
4
|
<component
|
|
5
5
|
:is="snackbar.component"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { customRef } from 'vue';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
|
|
4
|
+
import { getElement } from '@/components/interfaces';
|
|
5
|
+
|
|
6
|
+
export function elementRef(): Ref<HTMLElement | undefined> {
|
|
7
|
+
return customRef((track, trigger) => {
|
|
8
|
+
let value: HTMLElement | undefined = undefined;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
get() {
|
|
12
|
+
track();
|
|
13
|
+
|
|
14
|
+
return value;
|
|
15
|
+
},
|
|
16
|
+
set(newValue) {
|
|
17
|
+
value = getElement(newValue);
|
|
18
|
+
|
|
19
|
+
trigger();
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<form @submit.prevent="submit">
|
|
2
|
+
<form @submit.prevent="form?.submit()">
|
|
3
3
|
<slot />
|
|
4
4
|
</form>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import { provide } from 'vue';
|
|
8
|
+
import { provide, watchEffect } from 'vue';
|
|
9
9
|
|
|
10
10
|
import { objectProp } from '@/utils/vue';
|
|
11
11
|
import type Form from '@/forms/Form';
|
|
12
12
|
|
|
13
|
+
let offSubmit: (() => void) | undefined;
|
|
13
14
|
const props = defineProps({ form: objectProp<Form>() });
|
|
14
|
-
|
|
15
15
|
const emit = defineEmits<{ submit: [] }>();
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
watchEffect((onCleanup) => {
|
|
18
|
+
offSubmit?.();
|
|
19
|
+
offSubmit = props.form?.on('submit', () => emit('submit'));
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
21
|
+
onCleanup(() => offSubmit?.());
|
|
22
|
+
});
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
}
|
|
24
|
+
provide('form', props.form);
|
|
26
25
|
</script>
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
'ring-1 ring-red-500': $input?.errors,
|
|
14
14
|
}"
|
|
15
15
|
/>
|
|
16
|
+
<AGHeadlessInputDescription />
|
|
16
17
|
<div class="absolute bottom-0 left-0 translate-y-full">
|
|
17
18
|
<AGHeadlessInputError class="mt-1 text-sm text-red-500" />
|
|
18
19
|
</div>
|
|
@@ -26,6 +27,7 @@ import { useInputProps } from '@/components/headless/forms/AGHeadlessInput';
|
|
|
26
27
|
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
27
28
|
|
|
28
29
|
import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
|
|
30
|
+
import AGHeadlessInputDescription from '../headless/forms/AGHeadlessInputDescription.vue';
|
|
29
31
|
import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
|
|
30
32
|
import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
|
|
31
33
|
import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<component :is="component.
|
|
2
|
+
<component :is="component.as" ref="$root" v-bind="component.props">
|
|
3
3
|
<slot />
|
|
4
4
|
</component>
|
|
5
5
|
</template>
|
|
@@ -9,8 +9,12 @@ import { computed } from 'vue';
|
|
|
9
9
|
import { objectWithoutEmpty } from '@noeldemartin/utils';
|
|
10
10
|
|
|
11
11
|
import { booleanProp, objectProp, stringProp } from '@/utils/vue';
|
|
12
|
+
import { elementRef } from '@/components/composition';
|
|
13
|
+
|
|
14
|
+
import type { IAGHeadlessButton } from './AGHeadlessButton';
|
|
12
15
|
|
|
13
16
|
const props = defineProps({
|
|
17
|
+
as: objectProp(),
|
|
14
18
|
href: stringProp(),
|
|
15
19
|
url: stringProp(),
|
|
16
20
|
route: stringProp(),
|
|
@@ -19,10 +23,15 @@ const props = defineProps({
|
|
|
19
23
|
submit: booleanProp(),
|
|
20
24
|
});
|
|
21
25
|
|
|
26
|
+
const $root = elementRef();
|
|
22
27
|
const component = computed(() => {
|
|
28
|
+
if (props.as) {
|
|
29
|
+
return { as: props.as, props: {} };
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
if (props.route) {
|
|
24
33
|
return {
|
|
25
|
-
|
|
34
|
+
as: 'router-link',
|
|
26
35
|
props: {
|
|
27
36
|
to: objectWithoutEmpty({
|
|
28
37
|
name: props.route,
|
|
@@ -35,7 +44,7 @@ const component = computed(() => {
|
|
|
35
44
|
|
|
36
45
|
if (props.href || props.url) {
|
|
37
46
|
return {
|
|
38
|
-
|
|
47
|
+
as: 'a',
|
|
39
48
|
props: {
|
|
40
49
|
target: '_blank',
|
|
41
50
|
href: props.href || props.url,
|
|
@@ -44,8 +53,10 @@ const component = computed(() => {
|
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
return {
|
|
47
|
-
|
|
56
|
+
as: 'button',
|
|
48
57
|
props: { type: props.submit ? 'submit' : 'button' },
|
|
49
58
|
};
|
|
50
59
|
});
|
|
60
|
+
|
|
61
|
+
defineExpose<IAGHeadlessButton>({ $el: $root });
|
|
51
62
|
</script>
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
2
|
|
|
3
|
-
import { stringProp } from '@/utils';
|
|
3
|
+
import { mixedProp, stringProp } from '@/utils';
|
|
4
4
|
import { extractComponentProps } from '@/components/utils';
|
|
5
|
+
import type { FormFieldValue } from '@/forms/Form';
|
|
6
|
+
import type { HasElement } from '@/components/interfaces';
|
|
5
7
|
|
|
6
|
-
export interface IAGHeadlessInput {
|
|
8
|
+
export interface IAGHeadlessInput extends HasElement {
|
|
7
9
|
id: string;
|
|
8
10
|
name: ComputedRef<string | null>;
|
|
9
11
|
label: ComputedRef<string | null>;
|
|
10
|
-
|
|
12
|
+
description: ComputedRef<string | boolean | null>;
|
|
13
|
+
value: ComputedRef<FormFieldValue | null>;
|
|
14
|
+
required: ComputedRef<boolean | null>;
|
|
11
15
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
12
|
-
update(value:
|
|
16
|
+
update(value: FormFieldValue | null): void;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
export const inputProps = {
|
|
16
20
|
name: stringProp(),
|
|
17
21
|
label: stringProp(),
|
|
22
|
+
description: stringProp(),
|
|
23
|
+
modelValue: mixedProp<FormFieldValue>([String, Number, Boolean]),
|
|
18
24
|
};
|
|
19
25
|
|
|
20
26
|
export function useInputProps(): typeof inputProps {
|
|
@@ -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 {
|
|
12
|
+
import { stringProp } from '@/utils/vue';
|
|
13
13
|
import type Form from '@/forms/Form';
|
|
14
|
+
import type { __SetsElement } from '@/components/interfaces';
|
|
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 '@/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>
|
|
@@ -4,20 +4,26 @@
|
|
|
4
4
|
ref="$input"
|
|
5
5
|
:name="name"
|
|
6
6
|
:type="type"
|
|
7
|
-
:
|
|
7
|
+
:required="input.required ?? undefined"
|
|
8
8
|
:aria-invalid="input.errors ? 'true' : 'false'"
|
|
9
|
-
:aria-describedby="
|
|
9
|
+
:aria-describedby="
|
|
10
|
+
input.errors ? `${input.id}-error` : input.description ? `${input.id}-description` : undefined
|
|
11
|
+
"
|
|
10
12
|
:checked="checked"
|
|
11
13
|
@input="update"
|
|
12
14
|
>
|
|
13
15
|
</template>
|
|
14
16
|
|
|
15
17
|
<script setup lang="ts">
|
|
16
|
-
import { computed, ref } from 'vue';
|
|
18
|
+
import { computed, ref, watchEffect } from 'vue';
|
|
17
19
|
|
|
18
|
-
import { injectReactiveOrFail, stringProp } from '@/utils';
|
|
20
|
+
import { injectReactiveOrFail, stringProp } from '@/utils/vue';
|
|
21
|
+
import type { __SetsElement } from '@/components/interfaces';
|
|
22
|
+
import type { FormFieldValue } from '@/forms/Form';
|
|
19
23
|
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
20
24
|
|
|
25
|
+
import { onFormFocus } from './composition';
|
|
26
|
+
|
|
21
27
|
const props = defineProps({
|
|
22
28
|
type: stringProp('text'),
|
|
23
29
|
});
|
|
@@ -42,6 +48,37 @@ function update() {
|
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
input.update(
|
|
51
|
+
input.update(getValue());
|
|
46
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
|
+
});
|
|
47
84
|
</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 '@/utils/vue';
|
|
20
|
+
import type { IAGHeadlessInput } from '@/components/headless/forms/AGHeadlessInput';
|
|
21
|
+
import type { __SetsElement } from '@/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,10 @@
|
|
|
1
|
+
import { inject, onUnmounted } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type Form from '@/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,11 +1,15 @@
|
|
|
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
14
|
export { default as AGHeadlessSelectButton } from './AGHeadlessSelectButton.vue';
|
|
11
15
|
export { default as AGHeadlessSelectError } from './AGHeadlessSelectError.vue';
|
|
@@ -13,6 +13,7 @@ export interface IAGHeadlessModalDefaultSlotProps {
|
|
|
13
13
|
|
|
14
14
|
export const modalProps = {
|
|
15
15
|
cancellable: booleanProp(true),
|
|
16
|
+
inline: booleanProp(),
|
|
16
17
|
title: stringProp(),
|
|
17
18
|
};
|
|
18
19
|
|
|
@@ -28,7 +29,8 @@ export function extractModalProps<T extends ExtractPropTypes<typeof modalProps>>
|
|
|
28
29
|
|
|
29
30
|
export function useModalExpose($modal: Ref<IAGHeadlessModal | undefined>): IAGModal {
|
|
30
31
|
return {
|
|
31
|
-
|
|
32
|
+
inline: computed(() => !!$modal.value?.inline),
|
|
32
33
|
cancellable: computed(() => !!$modal.value?.cancellable),
|
|
34
|
+
close: async () => $modal.value?.close(),
|
|
33
35
|
};
|
|
34
36
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
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
|
|
|
@@ -26,6 +31,7 @@ const { modal } = injectReactiveOrFail<IAGModalContext>(
|
|
|
26
31
|
'could not obtain modal reference from <AGHeadlessModal>, ' +
|
|
27
32
|
'did you render this component manually? Show it using $ui.openModal() instead',
|
|
28
33
|
);
|
|
34
|
+
const rootComponent = computed(() => (modal.properties.inline ? 'div' : Dialog));
|
|
29
35
|
|
|
30
36
|
async function hide(): Promise<void> {
|
|
31
37
|
if (!$root.value?.$el) {
|
|
@@ -82,5 +88,5 @@ useEvent('show-modal', async ({ id }) => {
|
|
|
82
88
|
});
|
|
83
89
|
|
|
84
90
|
defineSlots<{ default(props: IAGHeadlessModalDefaultSlotProps): VNode[] }>();
|
|
85
|
-
defineExpose<IAGHeadlessModal>({ close, cancellable: toRef(props, 'cancellable') });
|
|
91
|
+
defineExpose<IAGHeadlessModal>({ close, cancellable: toRef(props, 'cancellable'), inline: toRef(props, 'inline') });
|
|
86
92
|
</script>
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<component :is="rootComponent">
|
|
3
3
|
<slot />
|
|
4
4
|
|
|
5
5
|
<template v-if="childModal">
|
|
6
|
-
<div
|
|
7
|
-
|
|
6
|
+
<div
|
|
7
|
+
class="pointer-events-none inset-0 z-50 bg-black/30"
|
|
8
|
+
:class="childModal.properties.inline ? 'absolute' : 'fixed'"
|
|
9
|
+
/>
|
|
10
|
+
<AGModalContext :child-index="childIndex + 1" :modal="childModal" />
|
|
8
11
|
</template>
|
|
9
|
-
</
|
|
12
|
+
</component>
|
|
10
13
|
</template>
|
|
11
14
|
|
|
12
15
|
<script setup lang="ts">
|
|
@@ -19,10 +22,11 @@ import type { IAGModalContext } from '@/components/modals/AGModalContext';
|
|
|
19
22
|
|
|
20
23
|
import AGModalContext from '../../modals/AGModalContext.vue';
|
|
21
24
|
|
|
22
|
-
const modal = injectReactiveOrFail<IAGModalContext>(
|
|
25
|
+
const { modal, childIndex } = injectReactiveOrFail<IAGModalContext>(
|
|
23
26
|
'modal',
|
|
24
27
|
'could not obtain modal reference from <AGHeadlessModalPanel>, ' +
|
|
25
28
|
'did you render this component manually? Show it using $ui.openModal() instead',
|
|
26
29
|
);
|
|
27
|
-
const
|
|
30
|
+
const rootComponent = computed(() => (modal.properties.inline ? 'div' : DialogPanel));
|
|
31
|
+
const childModal = computed(() => UI.modals[childIndex] ?? null);
|
|
28
32
|
</script>
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
2
|
+
<component :is="rootComponent" v-bind="rootProps">
|
|
3
3
|
<slot />
|
|
4
|
-
</
|
|
4
|
+
</component>
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
+
import { computed } from 'vue';
|
|
8
9
|
import { DialogTitle } from '@headlessui/vue';
|
|
9
10
|
|
|
10
|
-
import { stringProp } from '@/utils/vue';
|
|
11
|
+
import { injectReactiveOrFail, stringProp } from '@/utils/vue';
|
|
12
|
+
import type { IAGModalContext } from '@/components/modals/AGModalContext';
|
|
11
13
|
|
|
12
|
-
defineProps({ as: stringProp('h2') });
|
|
14
|
+
const props = defineProps({ as: stringProp('h2') });
|
|
15
|
+
|
|
16
|
+
const { modal } = injectReactiveOrFail<IAGModalContext>(
|
|
17
|
+
'modal',
|
|
18
|
+
'could not obtain modal reference from <AGHeadlessModalPanel>, ' +
|
|
19
|
+
'did you render this component manually? Show it using $ui.openModal() instead',
|
|
20
|
+
);
|
|
21
|
+
const rootComponent = computed(() => (modal.properties.inline ? 'div' : DialogTitle));
|
|
22
|
+
const rootProps = computed(() => (modal.properties.inline ? {} : { as: props.as }));
|
|
13
23
|
</script>
|
package/src/components/index.ts
CHANGED
|
@@ -3,9 +3,11 @@ import AGAppOverlays from './AGAppOverlays.vue';
|
|
|
3
3
|
|
|
4
4
|
export { AGAppLayout, AGAppOverlays };
|
|
5
5
|
|
|
6
|
+
export * from './composition';
|
|
6
7
|
export * from './constants';
|
|
7
8
|
export * from './forms';
|
|
8
9
|
export * from './headless';
|
|
10
|
+
export * from './interfaces';
|
|
9
11
|
export * from './lib';
|
|
10
12
|
export * from './modals';
|
|
11
13
|
export * from './snackbars';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isObject } from '@noeldemartin/utils';
|
|
2
|
+
import type { Ref, UnwrapNestedRefs } from 'vue';
|
|
3
|
+
|
|
4
|
+
export function getElement(value: unknown): HTMLElement | undefined {
|
|
5
|
+
if (value instanceof HTMLElement) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (hasElement(value)) {
|
|
10
|
+
return value.$el;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function hasElement(value: unknown): value is UnwrapNestedRefs<HasElement> {
|
|
15
|
+
return isObject(value) && '$el' in value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface __SetsElement {
|
|
19
|
+
__setElement(element?: HTMLElement): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface HasElement {
|
|
23
|
+
$el: Readonly<Ref<HTMLElement | undefined>>;
|
|
24
|
+
}
|