@aerogel/core 0.0.0-next.9a02fcd3bcf698211dd7a71d4c48257c96dd7832 → 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 +2130 -1361
- 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 +4 -8
- package/src/bootstrap/index.ts +25 -16
- package/src/bootstrap/options.ts +1 -1
- package/src/components/AGAppLayout.vue +1 -1
- package/src/components/AGAppModals.vue +1 -1
- package/src/components/AGAppOverlays.vue +1 -1
- 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 +4 -3
- package/src/components/forms/AGForm.vue +11 -12
- package/src/components/forms/AGInput.vue +8 -4
- package/src/components/forms/AGSelect.vue +11 -17
- package/src/components/headless/forms/AGHeadlessButton.ts +3 -0
- package/src/components/headless/forms/AGHeadlessButton.vue +16 -5
- package/src/components/headless/forms/AGHeadlessInput.ts +18 -5
- 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 +43 -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 +3 -3
- package/src/components/headless/forms/AGHeadlessSelect.vue +15 -15
- package/src/components/headless/forms/AGHeadlessSelectError.vue +2 -2
- package/src/components/headless/forms/AGHeadlessSelectOption.vue +10 -18
- 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 +17 -18
- package/src/components/headless/modals/AGHeadlessModal.vue +12 -10
- 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 +3 -3
- package/src/components/index.ts +2 -0
- package/src/components/lib/AGErrorMessage.vue +3 -3
- package/src/components/lib/AGMarkdown.vue +24 -6
- package/src/components/lib/AGMeasured.vue +3 -2
- package/src/components/lib/AGProgressBar.vue +55 -0
- package/src/components/lib/AGStartupCrash.vue +1 -1
- package/src/components/lib/index.ts +1 -0
- package/src/components/modals/AGAlertModal.ts +6 -3
- package/src/components/modals/AGConfirmModal.ts +19 -4
- package/src/components/modals/AGConfirmModal.vue +6 -5
- package/src/components/modals/AGErrorReportModal.ts +8 -5
- package/src/components/modals/AGErrorReportModal.vue +2 -2
- package/src/components/modals/AGErrorReportModalButtons.vue +10 -10
- package/src/components/modals/AGErrorReportModalTitle.vue +2 -2
- package/src/components/modals/AGLoadingModal.ts +11 -5
- package/src/components/modals/AGModal.vue +20 -19
- 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 +15 -4
- package/src/components/modals/AGPromptModal.vue +5 -4
- package/src/components/modals/index.ts +0 -1
- package/src/components/snackbars/AGSnackbar.vue +2 -2
- package/src/components/utils.ts +62 -9
- package/src/directives/index.ts +11 -5
- package/src/directives/measure.ts +34 -6
- package/src/errors/Errors.state.ts +1 -1
- package/src/errors/Errors.ts +12 -12
- package/src/errors/JobCancelledError.ts +3 -0
- package/src/errors/index.ts +9 -6
- package/src/errors/utils.ts +17 -1
- package/src/forms/Form.test.ts +32 -3
- package/src/forms/Form.ts +80 -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} +1 -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 +46 -0
- package/src/lang/Lang.state.ts +11 -0
- package/src/lang/Lang.ts +48 -21
- 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 +26 -3
- package/src/services/App.ts +11 -3
- package/src/services/Cache.ts +43 -0
- package/src/services/Events.ts +15 -5
- package/src/services/Service.ts +125 -54
- package/src/services/Storage.ts +20 -0
- package/src/services/index.ts +13 -5
- package/src/services/utils.ts +18 -0
- package/src/testing/index.ts +4 -3
- package/src/testing/setup.ts +11 -0
- package/src/ui/UI.state.ts +9 -2
- package/src/ui/UI.ts +157 -52
- package/src/ui/index.ts +5 -4
- package/src/ui/utils.ts +16 -0
- package/src/utils/composition/events.ts +2 -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 +2 -0
- package/src/utils/markdown.test.ts +50 -0
- package/src/utils/markdown.ts +19 -6
- package/src/utils/vue.ts +22 -15
- 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
package/package.json
CHANGED
|
@@ -1,52 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aerogel/core",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"main": "dist/aerogel-core.cjs.js",
|
|
6
|
-
"module": "dist/aerogel-core.esm.js",
|
|
7
|
-
"types": "dist/aerogel-core.d.ts",
|
|
3
|
+
"version": "0.0.0-next.9a1c5ba39a454b316eba36ec7bdf579fed3d95d2",
|
|
4
|
+
"type": "module",
|
|
8
5
|
"sideEffects": false,
|
|
6
|
+
"exports": {
|
|
7
|
+
"types": "./dist/aerogel-core.d.ts",
|
|
8
|
+
"default": "./dist/aerogel-core.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Noel De Martin",
|
|
16
|
+
"repository": "github:NoelDeMartin/aerogel",
|
|
9
17
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"build:js": "noeldemartin-build-javascript",
|
|
12
|
-
"build:types": "noeldemartin-build-types",
|
|
13
|
-
"histoire": "histoire dev",
|
|
18
|
+
"build": "vite build && ./scripts/fix-types.sh",
|
|
14
19
|
"lint": "noeldemartin-lint src",
|
|
15
|
-
"publish-next": "noeldemartin-publish-next",
|
|
16
20
|
"test": "vitest --run",
|
|
17
|
-
"test:ci": "vitest --run --reporter verbose"
|
|
18
|
-
|
|
19
|
-
"engines": {
|
|
20
|
-
"node": ">=18.x"
|
|
21
|
+
"test:ci": "vitest --run --reporter verbose",
|
|
22
|
+
"verify": "noeldemartin-verify"
|
|
21
23
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"url": "https://github.com/NoelDeMartin/aerogeljs.git"
|
|
25
|
-
},
|
|
26
|
-
"keywords": [
|
|
27
|
-
"javascript",
|
|
28
|
-
"framework",
|
|
29
|
-
"solid"
|
|
30
|
-
],
|
|
31
|
-
"author": "Noel De Martin",
|
|
32
|
-
"license": "MIT",
|
|
33
|
-
"bugs": {
|
|
34
|
-
"url": "https://github.com/NoelDeMartin/aerogeljs/issues"
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vue": "^3.5.0"
|
|
35
26
|
},
|
|
36
27
|
"dependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"marked": "^5.0.4",
|
|
28
|
+
"@noeldemartin/utils": "0.7.0-next.31cf84b4b57092d146528f27579439783aca71bb",
|
|
29
|
+
"dompurify": "^3.2.4",
|
|
30
|
+
"marked": "^15.0.7",
|
|
41
31
|
"pinia": "^2.1.6",
|
|
42
|
-
"
|
|
32
|
+
"reka-ui": "^2.2.0"
|
|
43
33
|
},
|
|
44
34
|
"devDependencies": {
|
|
45
|
-
"@aerogel/vite": "*"
|
|
46
|
-
"@histoire/plugin-vue": "^0.17.6",
|
|
47
|
-
"@types/dompurify": "^3.0.2",
|
|
48
|
-
"@types/marked": "^5.0.0",
|
|
49
|
-
"tailwindcss": "^3.3.5"
|
|
35
|
+
"@aerogel/vite": "*"
|
|
50
36
|
},
|
|
51
37
|
"eslintConfig": {
|
|
52
38
|
"extends": [
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { createApp } from 'vue';
|
|
3
|
-
import { mock } from '@noeldemartin/
|
|
3
|
+
import { mock } from '@noeldemartin/testing';
|
|
4
4
|
import type { Component } from 'vue';
|
|
5
5
|
|
|
6
|
-
import Events from '
|
|
7
|
-
import
|
|
6
|
+
import Events from '@aerogel/core/services/Events';
|
|
7
|
+
import measure from '@aerogel/core/directives/measure';
|
|
8
8
|
|
|
9
9
|
import { bootstrap } from './index';
|
|
10
10
|
|
|
11
11
|
describe('Aerogel', () => {
|
|
12
12
|
|
|
13
13
|
beforeEach(() => {
|
|
14
|
-
vi.stubGlobal('document', { getElementById: () => null });
|
|
15
14
|
vi.mock('vue', async () => {
|
|
16
15
|
const vue = (await vi.importActual('vue')) as Object;
|
|
17
16
|
|
|
@@ -49,10 +48,7 @@ describe('Aerogel', () => {
|
|
|
49
48
|
await bootstrap(rootComponent);
|
|
50
49
|
|
|
51
50
|
// Assert
|
|
52
|
-
expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith(
|
|
53
|
-
'initial-focus',
|
|
54
|
-
initialFocus,
|
|
55
|
-
);
|
|
51
|
+
expect(vi.mocked(createApp).mock.results[0]?.value.directive).toHaveBeenCalledWith('measure', measure);
|
|
56
52
|
});
|
|
57
53
|
|
|
58
54
|
});
|
package/src/bootstrap/index.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { createApp } from 'vue';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export
|
|
2
|
+
import { isDevelopment } from '@noeldemartin/utils';
|
|
3
|
+
import type { App as AppInstance, Component } from 'vue';
|
|
4
|
+
|
|
5
|
+
import App from '@aerogel/core/services/App';
|
|
6
|
+
import directives from '@aerogel/core/directives';
|
|
7
|
+
import errors from '@aerogel/core/errors';
|
|
8
|
+
import Events from '@aerogel/core/services/Events';
|
|
9
|
+
import lang from '@aerogel/core/lang';
|
|
10
|
+
import services from '@aerogel/core/services';
|
|
11
|
+
import testing from '@aerogel/core/testing';
|
|
12
|
+
import ui from '@aerogel/core/ui';
|
|
13
|
+
import { installPlugins } from '@aerogel/core/plugins';
|
|
14
|
+
import type { AerogelOptions } from '@aerogel/core/bootstrap/options';
|
|
15
|
+
|
|
16
|
+
export type { AerogelOptions };
|
|
17
|
+
|
|
18
|
+
export async function bootstrapApplication(app: AppInstance, options: AerogelOptions = {}): Promise<void> {
|
|
17
19
|
const plugins = [testing, directives, errors, lang, services, ui, ...(options.plugins ?? [])];
|
|
18
20
|
|
|
21
|
+
App.instance = app;
|
|
22
|
+
|
|
19
23
|
await installPlugins(plugins, app, options);
|
|
20
24
|
await options.install?.(app);
|
|
21
25
|
await Events.emit('application-ready');
|
|
@@ -24,6 +28,11 @@ export async function bootstrapApplication(app: App, options: AerogelOptions = {
|
|
|
24
28
|
export async function bootstrap(rootComponent: Component, options: AerogelOptions = {}): Promise<void> {
|
|
25
29
|
const app = createApp(rootComponent);
|
|
26
30
|
|
|
31
|
+
if (isDevelopment()) {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
(window as any).$aerogel = app;
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
await bootstrapApplication(app, options);
|
|
28
37
|
|
|
29
38
|
app.mount('#app');
|
|
@@ -32,7 +41,7 @@ export async function bootstrap(rootComponent: Component, options: AerogelOption
|
|
|
32
41
|
await Events.emit('application-mounted');
|
|
33
42
|
}
|
|
34
43
|
|
|
35
|
-
declare module '
|
|
44
|
+
declare module '@aerogel/core/services/Events' {
|
|
36
45
|
export interface EventsPayload {
|
|
37
46
|
'application-ready': void;
|
|
38
47
|
'application-mounted': void;
|
package/src/bootstrap/options.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<script setup lang="ts">
|
|
12
12
|
import { ref } from 'vue';
|
|
13
13
|
|
|
14
|
-
import { useEvent } from '
|
|
14
|
+
import { useEvent } from '@aerogel/core/utils/composition/events';
|
|
15
15
|
|
|
16
16
|
import AGAppModals from './AGAppModals.vue';
|
|
17
17
|
import AGAppSnackbars from './AGAppSnackbars.vue';
|
|
@@ -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 '@aerogel/core/components/utils';
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
export interface IModal {
|
|
4
|
+
cancellable: Ref<boolean>;
|
|
5
|
+
close(result?: unknown): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface IModalProps {
|
|
9
|
+
cancellable: boolean;
|
|
10
|
+
title: string | null;
|
|
11
|
+
description: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IModalDefaultSlotProps {
|
|
15
|
+
close(result?: unknown): Promise<void>;
|
|
16
|
+
}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
8
|
import { computed } from 'vue';
|
|
9
9
|
|
|
10
|
-
import { enumProp } from '
|
|
11
|
-
import { Colors } from '
|
|
10
|
+
import { enumProp } from '@aerogel/core/utils/vue';
|
|
11
|
+
import { Colors } from '@aerogel/core/components/constants';
|
|
12
12
|
|
|
13
13
|
import AGHeadlessButton from '../headless/forms/AGHeadlessButton.vue';
|
|
14
14
|
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
</template>
|
|
25
25
|
|
|
26
26
|
<script setup lang="ts">
|
|
27
|
-
import { componentRef, stringProp } from '
|
|
27
|
+
import { componentRef, stringProp } from '@aerogel/core/utils/vue';
|
|
28
28
|
|
|
29
|
-
import
|
|
29
|
+
import { useInputEmits } from '@aerogel/core/components/headless/forms/AGHeadlessInput';
|
|
30
|
+
import type { IAGHeadlessInput } from '@aerogel/core/components/headless/forms/AGHeadlessInput';
|
|
30
31
|
|
|
31
32
|
import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
|
|
32
33
|
import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
|
|
@@ -35,7 +36,7 @@ import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
|
|
|
35
36
|
|
|
36
37
|
defineProps({ name: stringProp() });
|
|
37
38
|
defineOptions({ inheritAttrs: false });
|
|
38
|
-
defineEmits(
|
|
39
|
+
defineEmits(useInputEmits());
|
|
39
40
|
|
|
40
41
|
const $input = componentRef<IAGHeadlessInput>();
|
|
41
42
|
</script>
|
|
@@ -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
|
-
import { objectProp } from '
|
|
11
|
-
import type Form from '
|
|
10
|
+
import { objectProp } from '@aerogel/core/utils/vue';
|
|
11
|
+
import type Form from '@aerogel/core/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>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
class="relative flex flex-col items-center"
|
|
5
5
|
:class="className"
|
|
6
6
|
v-bind="props"
|
|
7
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
7
8
|
>
|
|
8
9
|
<AGHeadlessInputLabel class="sr-only" />
|
|
9
10
|
<AGHeadlessInputInput
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
'ring-1 ring-red-500': $input?.errors,
|
|
14
15
|
}"
|
|
15
16
|
/>
|
|
17
|
+
<AGHeadlessInputDescription />
|
|
16
18
|
<div class="absolute bottom-0 left-0 translate-y-full">
|
|
17
19
|
<AGHeadlessInputError class="mt-1 text-sm text-red-500" />
|
|
18
20
|
</div>
|
|
@@ -20,17 +22,19 @@
|
|
|
20
22
|
</template>
|
|
21
23
|
|
|
22
24
|
<script setup lang="ts">
|
|
23
|
-
import { componentRef } from '
|
|
24
|
-
import { useInputAttrs } from '
|
|
25
|
-
import { useInputProps } from '
|
|
26
|
-
import type { IAGHeadlessInput } from '
|
|
25
|
+
import { componentRef } from '@aerogel/core/utils/vue';
|
|
26
|
+
import { useInputAttrs } from '@aerogel/core/utils/composition/forms';
|
|
27
|
+
import { useInputEmits, useInputProps } from '@aerogel/core/components/headless/forms/AGHeadlessInput';
|
|
28
|
+
import type { IAGHeadlessInput } from '@aerogel/core/components/headless/forms/AGHeadlessInput';
|
|
27
29
|
|
|
28
30
|
import AGHeadlessInput from '../headless/forms/AGHeadlessInput.vue';
|
|
31
|
+
import AGHeadlessInputDescription from '../headless/forms/AGHeadlessInputDescription.vue';
|
|
29
32
|
import AGHeadlessInputError from '../headless/forms/AGHeadlessInputError.vue';
|
|
30
33
|
import AGHeadlessInputInput from '../headless/forms/AGHeadlessInputInput.vue';
|
|
31
34
|
import AGHeadlessInputLabel from '../headless/forms/AGHeadlessInputLabel.vue';
|
|
32
35
|
|
|
33
36
|
defineOptions({ inheritAttrs: false });
|
|
37
|
+
defineEmits(useInputEmits());
|
|
34
38
|
|
|
35
39
|
const props = defineProps(useInputProps());
|
|
36
40
|
const $input = componentRef<IAGHeadlessInput>();
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
as="div"
|
|
6
6
|
@update:model-value="$emit('update:modelValue', $event)"
|
|
7
7
|
>
|
|
8
|
-
<AGHeadlessSelectLabel class="block text-sm font-medium leading-6 text-gray-900" />
|
|
9
8
|
<div class="relative" :class="{ 'mt-2': $select?.label }">
|
|
10
|
-
<
|
|
11
|
-
class="relative w-full cursor-default bg-white py-1.5 pl-3
|
|
9
|
+
<AGHeadlessSelectTrigger
|
|
10
|
+
class="relative w-full cursor-default bg-white py-1.5 pr-10 pl-3 text-left text-gray-900 ring-1 ring-gray-300 ring-inset focus:ring-2 focus:ring-indigo-600 focus:outline-hidden"
|
|
12
11
|
text-class="block truncate"
|
|
13
12
|
:class="{
|
|
14
13
|
'ring-1 ring-red-500': $select?.errors,
|
|
@@ -16,22 +15,18 @@
|
|
|
16
15
|
>
|
|
17
16
|
<template #icon>
|
|
18
17
|
<span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
|
19
|
-
<IconCheveronDown class="
|
|
18
|
+
<IconCheveronDown class="size-5 text-gray-400" />
|
|
20
19
|
</span>
|
|
21
20
|
</template>
|
|
22
|
-
</
|
|
21
|
+
</AGHeadlessSelectTrigger>
|
|
23
22
|
<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
|
|
23
|
+
class="absolute z-10 mt-1 max-h-60 w-full overflow-auto border border-gray-300 bg-white py-1 text-base ring-1 ring-black/5 focus:outline-hidden"
|
|
25
24
|
>
|
|
26
25
|
<AGHeadlessSelectOption
|
|
27
26
|
v-for="(option, index) in $select?.options ?? []"
|
|
28
27
|
:key="index"
|
|
29
28
|
:value="option"
|
|
30
|
-
class="relative block cursor-default
|
|
31
|
-
selected-class="font-semibold"
|
|
32
|
-
unselected-class="font-normal"
|
|
33
|
-
active-class="bg-indigo-600 text-white"
|
|
34
|
-
inactive-class="text-gray-900"
|
|
29
|
+
class="relative block cursor-default truncate py-2 pr-9 pl-3 text-gray-900 select-none data-[highlighted]:bg-indigo-600 data-[highlighted]:text-white data-[state=checked]:font-semibold data-[state=unchecked]:font-normal"
|
|
35
30
|
/>
|
|
36
31
|
</AGHeadlessSelectOptions>
|
|
37
32
|
</div>
|
|
@@ -42,16 +37,15 @@
|
|
|
42
37
|
<script setup lang="ts">
|
|
43
38
|
import IconCheveronDown from '~icons/zondicons/cheveron-down';
|
|
44
39
|
|
|
45
|
-
import { componentRef } from '
|
|
46
|
-
import { useSelectEmits, useSelectProps } from '
|
|
47
|
-
import type { IAGHeadlessSelect } from '
|
|
40
|
+
import { componentRef } from '@aerogel/core/utils/vue';
|
|
41
|
+
import { useSelectEmits, useSelectProps } from '@aerogel/core/components/headless/forms/AGHeadlessSelect';
|
|
42
|
+
import type { IAGHeadlessSelect } from '@aerogel/core/components/headless/forms/AGHeadlessSelect';
|
|
48
43
|
|
|
49
44
|
import AGHeadlessSelect from '../headless/forms/AGHeadlessSelect.vue';
|
|
50
|
-
import
|
|
45
|
+
import AGHeadlessSelectTrigger from '../headless/forms/AGHeadlessSelectTrigger.vue';
|
|
51
46
|
import AGHeadlessSelectError from '../headless/forms/AGHeadlessSelectError.vue';
|
|
52
|
-
import AGHeadlessSelectLabel from '../headless/forms/AGHeadlessSelectLabel.vue';
|
|
53
47
|
import AGHeadlessSelectOption from '../headless/forms/AGHeadlessSelectOption.vue';
|
|
54
|
-
import AGHeadlessSelectOptions from '../headless/forms/AGHeadlessSelectOptions';
|
|
48
|
+
import AGHeadlessSelectOptions from '../headless/forms/AGHeadlessSelectOptions.vue';
|
|
55
49
|
|
|
56
50
|
defineEmits(useSelectEmits());
|
|
57
51
|
|
|
@@ -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>
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
import { computed } from 'vue';
|
|
9
9
|
import { objectWithoutEmpty } from '@noeldemartin/utils';
|
|
10
10
|
|
|
11
|
-
import { booleanProp, objectProp, stringProp } from '
|
|
11
|
+
import { booleanProp, objectProp, stringProp } from '@aerogel/core/utils/vue';
|
|
12
|
+
import { elementRef } from '@aerogel/core/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,22 +1,35 @@
|
|
|
1
1
|
import type { ComputedRef, DeepReadonly, ExtractPropTypes, Ref } from 'vue';
|
|
2
|
+
import type { Writable } from '@noeldemartin/utils';
|
|
2
3
|
|
|
3
|
-
import { stringProp } from '
|
|
4
|
-
import { extractComponentProps } 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';
|
|
5
8
|
|
|
6
|
-
export interface IAGHeadlessInput {
|
|
9
|
+
export interface IAGHeadlessInput extends HasElement {
|
|
7
10
|
id: string;
|
|
8
11
|
name: ComputedRef<string | null>;
|
|
9
12
|
label: ComputedRef<string | null>;
|
|
10
|
-
|
|
13
|
+
description: ComputedRef<string | boolean | null>;
|
|
14
|
+
value: ComputedRef<FormFieldValue | null>;
|
|
15
|
+
required: ComputedRef<boolean | null>;
|
|
11
16
|
errors: DeepReadonly<Ref<string[] | null>>;
|
|
12
|
-
update(value:
|
|
17
|
+
update(value: FormFieldValue | null): void;
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
export const inputProps = {
|
|
16
21
|
name: stringProp(),
|
|
17
22
|
label: stringProp(),
|
|
23
|
+
description: stringProp(),
|
|
24
|
+
modelValue: mixedProp<FormFieldValue>([String, Number, Boolean]),
|
|
18
25
|
};
|
|
19
26
|
|
|
27
|
+
export const inputEmits = ['update:modelValue'] as const;
|
|
28
|
+
|
|
29
|
+
export function useInputEmits(): Writable<typeof inputEmits> {
|
|
30
|
+
return [...inputEmits];
|
|
31
|
+
}
|
|
32
|
+
|
|
20
33
|
export function useInputProps(): typeof inputProps {
|
|
21
34
|
return inputProps;
|
|
22
35
|
}
|
|
@@ -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>
|