@aerogel/core 0.0.0-next.88c59e62f64db70aedfbc4c31b5bbc287be44483 → 0.0.0-next.8e6b2bcc764fa682decbb41aa6848c77a744dec3
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 +856 -124
- package/dist/aerogel-core.esm.js +1 -1
- package/dist/aerogel-core.esm.js.map +1 -1
- package/histoire.config.ts +7 -0
- package/package.json +14 -5
- package/postcss.config.js +6 -0
- package/src/assets/histoire.css +3 -0
- package/src/bootstrap/bootstrap.test.ts +4 -3
- package/src/bootstrap/index.ts +22 -5
- package/src/bootstrap/options.ts +3 -0
- package/src/components/AGAppLayout.vue +7 -2
- package/src/components/AGAppOverlays.vue +5 -1
- package/src/components/AGAppSnackbars.vue +1 -1
- package/src/components/forms/AGCheckbox.vue +7 -1
- package/src/components/forms/AGInput.vue +8 -6
- package/src/components/forms/AGSelect.story.vue +46 -0
- package/src/components/forms/AGSelect.vue +60 -0
- package/src/components/forms/index.ts +1 -0
- package/src/components/headless/forms/AGHeadlessButton.vue +8 -8
- package/src/components/headless/forms/AGHeadlessInput.ts +21 -1
- package/src/components/headless/forms/AGHeadlessInput.vue +7 -4
- package/src/components/headless/forms/AGHeadlessInputInput.vue +2 -0
- package/src/components/headless/forms/AGHeadlessInputLabel.vue +8 -2
- package/src/components/headless/forms/AGHeadlessSelect.ts +28 -17
- package/src/components/headless/forms/AGHeadlessSelect.vue +60 -28
- 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 +0 -4
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +39 -0
- package/src/components/headless/forms/index.ts +5 -3
- 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/index.ts +1 -1
- package/src/components/{basic → lib}/AGErrorMessage.vue +2 -2
- package/src/components/lib/AGMeasured.vue +15 -0
- package/src/components/lib/AGStartupCrash.vue +31 -0
- package/src/components/lib/index.ts +5 -0
- package/src/components/modals/AGAlertModal.ts +15 -0
- package/src/components/modals/AGAlertModal.vue +4 -15
- package/src/components/modals/AGConfirmModal.ts +27 -0
- package/src/components/modals/AGConfirmModal.vue +8 -12
- package/src/components/modals/AGErrorReportModal.ts +27 -1
- package/src/components/modals/AGErrorReportModal.vue +8 -16
- package/src/components/modals/AGErrorReportModalButtons.vue +4 -2
- package/src/components/modals/AGErrorReportModalTitle.vue +1 -1
- package/src/components/modals/AGLoadingModal.ts +23 -0
- package/src/components/modals/AGLoadingModal.vue +4 -8
- 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 +3 -9
- package/src/components/utils.ts +10 -0
- package/src/directives/index.ts +5 -1
- package/src/directives/measure.ts +21 -0
- package/src/errors/Errors.ts +26 -24
- package/src/errors/index.ts +10 -23
- package/src/errors/utils.ts +19 -0
- package/src/forms/Form.ts +9 -3
- package/src/jobs/Job.ts +5 -0
- package/src/jobs/index.ts +7 -0
- package/src/lang/Lang.ts +11 -23
- package/src/main.histoire.ts +1 -0
- package/src/main.ts +3 -0
- package/src/services/App.state.ts +4 -5
- package/src/services/App.ts +30 -3
- package/src/services/Events.test.ts +39 -0
- package/src/services/Events.ts +100 -30
- package/src/services/Service.ts +50 -16
- package/src/services/index.ts +2 -1
- package/src/services/store.ts +8 -5
- package/src/testing/index.ts +25 -0
- package/src/ui/UI.ts +124 -19
- 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 +11 -2
- package/tailwind.config.js +4 -0
- package/tsconfig.json +1 -1
- package/.eslintrc.js +0 -3
- package/dist/virtual.d.ts +0 -11
- package/src/components/basic/index.ts +0 -5
- package/src/components/headless/forms/AGHeadlessSelectButton.ts +0 -3
- package/src/components/headless/forms/AGHeadlessSelectLabel.ts +0 -3
- package/src/types/virtual.d.ts +0 -11
- /package/src/components/{basic → lib}/AGLink.vue +0 -0
- /package/src/components/{basic → lib}/AGMarkdown.vue +0 -0
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.8e6b2bcc764fa682decbb41aa6848c77a744dec3",
|
|
5
5
|
"main": "dist/aerogel-core.cjs.js",
|
|
6
6
|
"module": "dist/aerogel-core.esm.js",
|
|
7
7
|
"types": "dist/aerogel-core.d.ts",
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm dist -rf && npm run build:js && npm run build:types",
|
|
11
11
|
"build:js": "noeldemartin-build-javascript",
|
|
12
|
-
"build:types": "noeldemartin-build-types
|
|
12
|
+
"build:types": "noeldemartin-build-types",
|
|
13
|
+
"histoire": "histoire dev",
|
|
13
14
|
"lint": "noeldemartin-lint src",
|
|
14
15
|
"publish-next": "noeldemartin-publish-next",
|
|
15
|
-
"test": "vitest --run"
|
|
16
|
+
"test": "vitest --run",
|
|
17
|
+
"test:ci": "vitest --run --reporter verbose"
|
|
16
18
|
},
|
|
17
19
|
"engines": {
|
|
18
20
|
"node": ">=18.x"
|
|
@@ -33,7 +35,7 @@
|
|
|
33
35
|
},
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"@headlessui/vue": "^1.7.14",
|
|
36
|
-
"@noeldemartin/utils": "0.
|
|
38
|
+
"@noeldemartin/utils": "0.5.1-next.49cc6c9b4a20930cbf922a949135981791acc5c3",
|
|
37
39
|
"dompurify": "^3.0.3",
|
|
38
40
|
"marked": "^5.0.4",
|
|
39
41
|
"pinia": "^2.1.6",
|
|
@@ -41,7 +43,14 @@
|
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@aerogel/vite": "*",
|
|
46
|
+
"@histoire/plugin-vue": "^0.17.6",
|
|
44
47
|
"@types/dompurify": "^3.0.2",
|
|
45
|
-
"@types/marked": "^5.0.0"
|
|
48
|
+
"@types/marked": "^5.0.0",
|
|
49
|
+
"tailwindcss": "^3.3.5"
|
|
50
|
+
},
|
|
51
|
+
"eslintConfig": {
|
|
52
|
+
"extends": [
|
|
53
|
+
"@noeldemartin/eslint-config-vue"
|
|
54
|
+
]
|
|
46
55
|
}
|
|
47
56
|
}
|
|
@@ -6,11 +6,12 @@ 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
|
|
|
13
13
|
beforeEach(() => {
|
|
14
|
+
vi.stubGlobal('document', { getElementById: () => null });
|
|
14
15
|
vi.mock('vue', async () => {
|
|
15
16
|
const vue = (await vi.importActual('vue')) as Object;
|
|
16
17
|
|
|
@@ -31,7 +32,7 @@ describe('Aerogel', () => {
|
|
|
31
32
|
const rootComponent = mock<Component>();
|
|
32
33
|
|
|
33
34
|
// Act
|
|
34
|
-
await
|
|
35
|
+
await bootstrap(rootComponent);
|
|
35
36
|
|
|
36
37
|
// Assert
|
|
37
38
|
const globals = vi.mocked(createApp).mock.results[0]?.value.config.globalProperties;
|
|
@@ -45,7 +46,7 @@ describe('Aerogel', () => {
|
|
|
45
46
|
const rootComponent = mock<Component>();
|
|
46
47
|
|
|
47
48
|
// Act
|
|
48
|
-
await
|
|
49
|
+
await bootstrap(rootComponent);
|
|
49
50
|
|
|
50
51
|
// Assert
|
|
51
52
|
expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith(
|
package/src/bootstrap/index.ts
CHANGED
|
@@ -1,23 +1,40 @@
|
|
|
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';
|
|
6
6
|
import Events from '@/services/Events';
|
|
7
7
|
import lang from '@/lang';
|
|
8
8
|
import services from '@/services';
|
|
9
|
+
import testing from '@/testing';
|
|
9
10
|
import ui from '@/ui';
|
|
10
11
|
import { installPlugins } from '@/plugins';
|
|
11
12
|
import type { AerogelOptions } from '@/bootstrap/options';
|
|
12
13
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export { AerogelOptions };
|
|
15
|
+
|
|
16
|
+
export async function bootstrapApplication(app: App, options: AerogelOptions = {}): Promise<void> {
|
|
17
|
+
const plugins = [testing, directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
16
18
|
|
|
17
19
|
await installPlugins(plugins, app, options);
|
|
20
|
+
await options.install?.(app);
|
|
21
|
+
await 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');
|
|
21
31
|
|
|
22
|
-
Events.emit('application-mounted');
|
|
32
|
+
await Events.emit('application-mounted');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare module '@/services/Events' {
|
|
36
|
+
export interface EventsPayload {
|
|
37
|
+
'application-ready': void;
|
|
38
|
+
'application-mounted': void;
|
|
39
|
+
}
|
|
23
40
|
}
|
package/src/bootstrap/options.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="flex h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased">
|
|
3
|
-
<slot
|
|
2
|
+
<div class="flex min-h-full flex-col text-base font-normal leading-tight text-gray-900 antialiased">
|
|
3
|
+
<slot v-if="$errors.hasStartupErrors" name="startup-crash">
|
|
4
|
+
<component :is="$ui.requireComponent(UIComponents.StartupCrash)" />
|
|
5
|
+
</slot>
|
|
6
|
+
<slot v-else />
|
|
4
7
|
|
|
5
8
|
<AGAppOverlays />
|
|
6
9
|
</div>
|
|
7
10
|
</template>
|
|
8
11
|
|
|
9
12
|
<script setup lang="ts">
|
|
13
|
+
import { UIComponents } from '@/ui/UI';
|
|
14
|
+
|
|
10
15
|
import AGAppOverlays from './AGAppOverlays.vue';
|
|
11
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,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div aria-live="assertive" class="z-60 pointer-events-none fixed inset-0 flex items-end px-4 py-6 sm:p-6">
|
|
3
|
-
<div class="flex w-full flex-col items-
|
|
3
|
+
<div class="flex w-full flex-col items-end space-y-4">
|
|
4
4
|
<component
|
|
5
5
|
:is="snackbar.component"
|
|
6
6
|
v-for="snackbar of $ui.snackbars"
|
|
@@ -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>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Story>
|
|
3
|
+
<div class="h-96">
|
|
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
|
+
/>
|
|
11
|
+
</div>
|
|
12
|
+
</Story>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { ref } from 'vue';
|
|
17
|
+
|
|
18
|
+
import AGSelect from './AGSelect.vue';
|
|
19
|
+
|
|
20
|
+
const bestMugiwara = ref(null);
|
|
21
|
+
const bestFood = ref(null);
|
|
22
|
+
const bestMugiwaraLabel = 'Who\'s the best Mugiwara?';
|
|
23
|
+
const bestFoodLabel = 'What\'s the best food?';
|
|
24
|
+
const bestMugiwaraOptions = [
|
|
25
|
+
'Monkey D. Luffy',
|
|
26
|
+
'Roronoa Zoro',
|
|
27
|
+
'Nami',
|
|
28
|
+
'Usopp',
|
|
29
|
+
'Sanji',
|
|
30
|
+
'Tony Tony Chopper',
|
|
31
|
+
'Nico Robin',
|
|
32
|
+
'Franky',
|
|
33
|
+
'Brook',
|
|
34
|
+
'Jinbe',
|
|
35
|
+
];
|
|
36
|
+
const bestFoodOptions = [
|
|
37
|
+
{
|
|
38
|
+
id: 'ramen',
|
|
39
|
+
name: 'Ramen',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'pizza',
|
|
43
|
+
name: 'Pizza',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
</script>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AGHeadlessSelect
|
|
3
|
+
v-bind="props"
|
|
4
|
+
ref="$select"
|
|
5
|
+
as="div"
|
|
6
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
7
|
+
>
|
|
8
|
+
<AGHeadlessSelectLabel class="block text-sm font-medium leading-6 text-gray-900" />
|
|
9
|
+
<div class="relative" :class="{ 'mt-2': $select?.label }">
|
|
10
|
+
<AGHeadlessSelectButton
|
|
11
|
+
class="relative w-full cursor-default bg-white py-1.5 pl-3 pr-10 text-left text-gray-900 ring-1 ring-inset ring-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-600"
|
|
12
|
+
text-class="block truncate"
|
|
13
|
+
:class="{
|
|
14
|
+
'ring-1 ring-red-500': $select?.errors,
|
|
15
|
+
}"
|
|
16
|
+
>
|
|
17
|
+
<template #icon>
|
|
18
|
+
<span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
|
19
|
+
<IconCheveronDown class="h-5 w-5 text-gray-400" />
|
|
20
|
+
</span>
|
|
21
|
+
</template>
|
|
22
|
+
</AGHeadlessSelectButton>
|
|
23
|
+
<AGHeadlessSelectOptions
|
|
24
|
+
class="absolute z-10 mt-1 max-h-60 w-full overflow-auto border bg-white py-1 text-base ring-1 ring-black ring-opacity-5 focus:outline-none"
|
|
25
|
+
>
|
|
26
|
+
<AGHeadlessSelectOption
|
|
27
|
+
v-for="(option, index) in $select?.options ?? []"
|
|
28
|
+
:key="index"
|
|
29
|
+
:value="option"
|
|
30
|
+
class="relative block cursor-default select-none truncate py-2 pl-3 pr-9"
|
|
31
|
+
selected-class="font-semibold"
|
|
32
|
+
unselected-class="font-normal"
|
|
33
|
+
active-class="bg-indigo-600 text-white"
|
|
34
|
+
inactive-class="text-gray-900"
|
|
35
|
+
/>
|
|
36
|
+
</AGHeadlessSelectOptions>
|
|
37
|
+
</div>
|
|
38
|
+
<AGHeadlessSelectError class="mt-2 text-sm text-red-600" />
|
|
39
|
+
</AGHeadlessSelect>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
<script setup lang="ts">
|
|
43
|
+
import IconCheveronDown from '~icons/zondicons/cheveron-down';
|
|
44
|
+
|
|
45
|
+
import { componentRef } from '@/utils/vue';
|
|
46
|
+
import { useSelectEmits, useSelectProps } from '@/components/headless/forms/AGHeadlessSelect';
|
|
47
|
+
import type { IAGHeadlessSelect } from '@/components/headless/forms/AGHeadlessSelect';
|
|
48
|
+
|
|
49
|
+
import AGHeadlessSelect from '../headless/forms/AGHeadlessSelect.vue';
|
|
50
|
+
import AGHeadlessSelectButton from '../headless/forms/AGHeadlessSelectButton.vue';
|
|
51
|
+
import AGHeadlessSelectError from '../headless/forms/AGHeadlessSelectError.vue';
|
|
52
|
+
import AGHeadlessSelectLabel from '../headless/forms/AGHeadlessSelectLabel.vue';
|
|
53
|
+
import AGHeadlessSelectOption from '../headless/forms/AGHeadlessSelectOption.vue';
|
|
54
|
+
import AGHeadlessSelectOptions from '../headless/forms/AGHeadlessSelectOptions';
|
|
55
|
+
|
|
56
|
+
defineEmits(useSelectEmits());
|
|
57
|
+
|
|
58
|
+
const props = defineProps(useSelectProps());
|
|
59
|
+
const $select = componentRef<IAGHeadlessSelect>();
|
|
60
|
+
</script>
|
|
@@ -10,7 +10,7 @@ import { objectWithoutEmpty } from '@noeldemartin/utils';
|
|
|
10
10
|
|
|
11
11
|
import { booleanProp, objectProp, stringProp } from '@/utils/vue';
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const props = defineProps({
|
|
14
14
|
href: stringProp(),
|
|
15
15
|
url: stringProp(),
|
|
16
16
|
route: stringProp(),
|
|
@@ -20,32 +20,32 @@ const { href, url, route, routeParams, routeQuery, submit } = defineProps({
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
const component = computed(() => {
|
|
23
|
-
if (route) {
|
|
23
|
+
if (props.route) {
|
|
24
24
|
return {
|
|
25
25
|
tag: 'router-link',
|
|
26
26
|
props: {
|
|
27
27
|
to: objectWithoutEmpty({
|
|
28
|
-
name: route,
|
|
29
|
-
params: routeParams,
|
|
30
|
-
query: routeQuery,
|
|
28
|
+
name: props.route,
|
|
29
|
+
params: props.routeParams,
|
|
30
|
+
query: props.routeQuery,
|
|
31
31
|
}),
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (href || url) {
|
|
36
|
+
if (props.href || props.url) {
|
|
37
37
|
return {
|
|
38
38
|
tag: 'a',
|
|
39
39
|
props: {
|
|
40
40
|
target: '_blank',
|
|
41
|
-
href: href || url,
|
|
41
|
+
href: props.href || props.url,
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return {
|
|
47
47
|
tag: 'button',
|
|
48
|
-
props: { type: submit ? 'submit' : 'button' },
|
|
48
|
+
props: { type: props.submit ? 'submit' : 'button' },
|
|
49
49
|
};
|
|
50
50
|
});
|
|
51
51
|
</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) {
|
|
@@ -28,8 +29,10 @@ const errors = computed(() => {
|
|
|
28
29
|
return form.errors[props.name] ?? null;
|
|
29
30
|
});
|
|
30
31
|
const form = inject<Form | null>('form', null);
|
|
31
|
-
const
|
|
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;
|
|
@@ -49,6 +52,6 @@ const publicApi: IAGHeadlessInput = {
|
|
|
49
52
|
},
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
provide<IAGHeadlessInput>('input',
|
|
53
|
-
defineExpose<IAGHeadlessInput>(
|
|
55
|
+
provide<IAGHeadlessInput>('input', api);
|
|
56
|
+
defineExpose<IAGHeadlessInput>(api);
|
|
54
57
|
</script>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
<input
|
|
3
3
|
:id="input.id"
|
|
4
4
|
ref="$input"
|
|
5
|
+
:name="name"
|
|
5
6
|
:type="type"
|
|
6
7
|
:value="value"
|
|
7
8
|
:aria-invalid="input.errors ? 'true' : 'false'"
|
|
@@ -26,6 +27,7 @@ const input = injectReactiveOrFail<IAGHeadlessInput>(
|
|
|
26
27
|
'input',
|
|
27
28
|
'<AGHeadlessInputInput> must be a child of a <AGHeadlessInput>',
|
|
28
29
|
);
|
|
30
|
+
const name = computed(() => input.name ?? undefined);
|
|
29
31
|
const value = computed(() => input.value);
|
|
30
32
|
const checked = computed(() => {
|
|
31
33
|
if (props.type !== 'checkbox') {
|
|
@@ -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,31 +1,42 @@
|
|
|
1
|
-
import type { ComputedRef } from 'vue';
|
|
1
|
+
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
import type { Writable } from '@noeldemartin/utils';
|
|
2
3
|
|
|
3
|
-
import { requiredArrayProp } from '@/utils/vue';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { mixedProp, requiredArrayProp, stringProp } from '@/utils/vue';
|
|
5
|
+
import { extractComponentProps } from '@/components/utils';
|
|
6
|
+
import type { FormFieldValue } from '@/forms/Form';
|
|
6
7
|
|
|
7
8
|
export interface IAGHeadlessSelect {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
18
|
}
|
|
12
19
|
|
|
13
20
|
export const selectProps = {
|
|
14
|
-
|
|
21
|
+
name: stringProp(),
|
|
22
|
+
label: stringProp(),
|
|
23
|
+
options: requiredArrayProp<FormFieldValue>(),
|
|
24
|
+
noSelectionText: stringProp(),
|
|
25
|
+
optionsText: mixedProp<string | ((option: FormFieldValue) => string)>(),
|
|
15
26
|
};
|
|
16
27
|
|
|
28
|
+
export const selectEmits = ['update:modelValue'] as const;
|
|
29
|
+
|
|
17
30
|
export function useSelectProps(): typeof selectProps {
|
|
18
31
|
return selectProps;
|
|
19
32
|
}
|
|
20
33
|
|
|
21
|
-
export function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return Object.keys(selectProps).reduce((extractedProps, selectProp) => {
|
|
25
|
-
const prop = selectProp as keyof typeof selectProps;
|
|
26
|
-
|
|
27
|
-
extractedProps[prop] = componentProps[prop];
|
|
34
|
+
export function useSelectEmits(): Writable<typeof selectEmits> {
|
|
35
|
+
return [...selectEmits];
|
|
36
|
+
}
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
export function extractSelectProps<T extends ExtractPropTypes<typeof selectProps>>(
|
|
39
|
+
props: T,
|
|
40
|
+
): Pick<T, keyof typeof selectProps> {
|
|
41
|
+
return extractComponentProps(props, selectProps);
|
|
31
42
|
}
|