@ghostvue/vue 0.1.0 → 0.2.0

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.
Files changed (53) hide show
  1. package/dist/GhostCheckboxGroup.vue.d.ts +24 -0
  2. package/dist/GhostComboboxContent.vue.d.ts +2 -2
  3. package/dist/GhostContextMenuContent.vue.d.ts +2 -2
  4. package/dist/GhostDatePickerContent.vue.d.ts +2 -2
  5. package/dist/GhostDropdownMenuContent.vue.d.ts +2 -2
  6. package/dist/GhostField.vue.d.ts +8 -5
  7. package/dist/GhostFieldError.vue.d.ts +3 -6
  8. package/dist/GhostFileUpload.vue.d.ts +1 -1
  9. package/dist/GhostForm.vue.d.ts +25 -0
  10. package/dist/GhostHoverCardContent.vue.d.ts +2 -2
  11. package/dist/GhostMenubarContent.vue.d.ts +2 -2
  12. package/dist/GhostPopoverContent.vue.d.ts +2 -2
  13. package/dist/GhostPresence.vue.d.ts +27 -0
  14. package/dist/GhostScrollSpy.vue.d.ts +1 -1
  15. package/dist/GhostScrollSpyItem.vue.d.ts +1 -1
  16. package/dist/GhostSelect.vue.d.ts +19 -46
  17. package/dist/GhostSelectContent.vue.d.ts +2 -2
  18. package/dist/GhostSelectValue.vue.d.ts +4 -7
  19. package/dist/GhostSubmenu.vue.d.ts +23 -0
  20. package/dist/GhostSubmenuContent.vue.d.ts +20 -0
  21. package/dist/GhostSubmenuTrigger.vue.d.ts +17 -0
  22. package/dist/GhostTagsInput.vue.d.ts +26 -0
  23. package/dist/GhostTooltipContent.vue.d.ts +2 -2
  24. package/dist/GhostTree.vue.d.ts +1 -1
  25. package/dist/dev-codes.d.ts +36 -0
  26. package/dist/dialog-shared.d.ts +15 -6
  27. package/dist/dismissable-layer-stack.d.ts +1 -0
  28. package/dist/form-reset.d.ts +9 -1
  29. package/dist/ghost-checkbox-group.d.ts +88 -0
  30. package/dist/ghost-dialog.d.ts +2 -0
  31. package/dist/ghost-field.d.ts +22 -1
  32. package/dist/ghost-form.d.ts +273 -0
  33. package/dist/ghost-presence.d.ts +78 -0
  34. package/dist/ghost-select.d.ts +63 -6
  35. package/dist/ghost-submenu.d.ts +20 -0
  36. package/dist/ghost-tags-input.d.ts +41 -0
  37. package/dist/ghost-tooltip-provider.d.ts +15 -4
  38. package/dist/ghostvue.js +7988 -5869
  39. package/dist/index.d.ts +17 -2
  40. package/dist/manifest.json +1378 -70
  41. package/dist/resolver.js +1 -1
  42. package/dist/track-reactive-reads.d.ts +13 -0
  43. package/dist/use-dismissable-layer.d.ts +8 -0
  44. package/dist/use-focus-scope.d.ts +7 -0
  45. package/dist/use-ghost-checkbox-group.d.ts +13 -0
  46. package/dist/use-ghost-form.d.ts +7 -0
  47. package/dist/use-ghost-menu-branch.d.ts +54 -0
  48. package/dist/use-ghost-menu-collection.d.ts +11 -0
  49. package/dist/use-ghost-menu-root.d.ts +13 -0
  50. package/dist/use-ghost-presence.d.ts +48 -0
  51. package/dist/use-ghost-select.d.ts +18 -8
  52. package/dist/use-roving-focus.d.ts +2 -0
  53. package/package.json +2 -1
@@ -0,0 +1,88 @@
1
+ import type { Component, ComputedRef, InjectionKey, MaybeRefOrGetter, Ref } from 'vue';
2
+ /** Valid `as` targets for {@link GhostCheckboxGroup}. */
3
+ export type GhostCheckboxGroupElement = string | Component;
4
+ /** Props for {@link GhostCheckboxGroup}. */
5
+ export interface GhostCheckboxGroupProps<TValue extends string> {
6
+ /**
7
+ * Controlled selection. `undefined` is uncontrolled. `[]` is a defined
8
+ * empty selection. Accepts readonly and frozen arrays; never mutated.
9
+ */
10
+ modelValue?: readonly TValue[] | undefined;
11
+ /**
12
+ * Uncontrolled seed and form-reset baseline. Shallow-copied once at setup;
13
+ * later prop changes and later mutation of the passed array are ignored.
14
+ * @default []
15
+ */
16
+ defaultValue?: readonly TValue[];
17
+ /**
18
+ * Native `name` applied to every member input. Without a group `name`,
19
+ * members without their own `name` submit nothing.
20
+ */
21
+ name?: string | undefined;
22
+ /**
23
+ * Disables every member input natively. On a `fieldset` root it also sets
24
+ * the native `disabled` attribute.
25
+ * @default false
26
+ */
27
+ disabled?: boolean;
28
+ /**
29
+ * Group-level error hook for Field or form integration. Sets
30
+ * `data-state="invalid"` and `aria-invalid="true"` on the root.
31
+ * @default false
32
+ */
33
+ invalid?: boolean;
34
+ /**
35
+ * Root host. A `fieldset` needs no role. Any other host gets `role="group"`.
36
+ * @default 'fieldset'
37
+ */
38
+ as?: GhostCheckboxGroupElement;
39
+ }
40
+ /** Emits for {@link GhostCheckboxGroup}. */
41
+ export interface GhostCheckboxGroupEmits<TValue extends string> {
42
+ 'update:modelValue': [value: TValue[]];
43
+ }
44
+ /** Methods and state exposed from a template ref to {@link GhostCheckboxGroup}. */
45
+ export interface GhostCheckboxGroupExposed {
46
+ /** The root element after mount, or `null` before mount. */
47
+ readonly element: HTMLElement | null;
48
+ /** Focuses the first enabled checked member in DOM order, else the first enabled member. */
49
+ focus(options?: FocusOptions): void;
50
+ /** Blurs the active member if it is inside the group. */
51
+ blur(): void;
52
+ }
53
+ /** Options for {@link useGhostCheckboxGroup}. */
54
+ export interface UseGhostCheckboxGroupOptions<TValue extends string = string> {
55
+ modelValue?: MaybeRefOrGetter<readonly TValue[] | undefined>;
56
+ defaultValue?: MaybeRefOrGetter<readonly TValue[] | undefined>;
57
+ name?: MaybeRefOrGetter<string | undefined>;
58
+ disabled?: MaybeRefOrGetter<boolean | undefined>;
59
+ invalid?: MaybeRefOrGetter<boolean | undefined>;
60
+ onValueChange?: (value: TValue[]) => void;
61
+ }
62
+ /** Reactive state and handlers returned by {@link useGhostCheckboxGroup}. */
63
+ export interface GhostCheckboxGroupContext<TValue extends string = string> {
64
+ readonly selectedValues: Ref<readonly TValue[]>;
65
+ readonly name: ComputedRef<string | undefined>;
66
+ readonly disabled: ComputedRef<boolean>;
67
+ readonly invalid: ComputedRef<boolean>;
68
+ isSelected: (value: string) => boolean;
69
+ setSelected: (value: TValue, checked: boolean) => void;
70
+ toggle: (value: TValue) => void;
71
+ registerMember: (id: symbol, value: string, disabled: boolean, getElement: () => HTMLInputElement | null, restoreDom: () => void) => void;
72
+ updateMember: (id: symbol, value: string, disabled: boolean) => void;
73
+ unregisterMember: (id: symbol) => void;
74
+ restoreAllMemberDom: () => void;
75
+ applyFormReset: () => void;
76
+ readonly registryVersion: Ref<number>;
77
+ }
78
+ export interface GhostCheckboxGroupRegisteredMember {
79
+ value: string;
80
+ disabled: boolean;
81
+ getElement: () => HTMLInputElement | null;
82
+ restoreDom: () => void;
83
+ }
84
+ export interface GhostCheckboxGroupInternalContext extends GhostCheckboxGroupContext {
85
+ readonly members: Map<symbol, GhostCheckboxGroupRegisteredMember>;
86
+ notifyMemberBeforeUnmount: (id: symbol, input: HTMLInputElement) => void;
87
+ }
88
+ export declare const ghostCheckboxGroupContextKey: InjectionKey<GhostCheckboxGroupInternalContext>;
@@ -250,5 +250,7 @@ export interface GhostDialogContext {
250
250
  }
251
251
  export interface GhostDialogInternalContext extends GhostDialogContext {
252
252
  openedAtMount: Ref<boolean>;
253
+ /** Internal: skips content exit retention (see `DialogPartsContext`). */
254
+ skipExitPresence?: () => boolean;
253
255
  }
254
256
  export declare const ghostDialogContextKey: InjectionKey<GhostDialogInternalContext>;
@@ -13,6 +13,11 @@ export interface GhostFieldProps {
13
13
  * Optional control id override. When omitted, {@link useGhostId} generates one.
14
14
  */
15
15
  id?: string;
16
+ /**
17
+ * Canonical dot-path key associating this field with an ancestor `GhostForm`
18
+ * or `useGhostForm` context.
19
+ */
20
+ name?: string;
16
21
  /**
17
22
  * Propagates disabled semantics to the control through {@link GhostFieldControl}.
18
23
  * @default false
@@ -20,7 +25,8 @@ export interface GhostFieldProps {
20
25
  disabled?: boolean;
21
26
  /**
22
27
  * Propagates invalid semantics to the control and sets root `data-state`.
23
- * @default false
28
+ * Explicit boolean values override ancestor form state; defaults to form
29
+ * field invalidity when named inside `GhostForm`, else `false`.
24
30
  */
25
31
  invalid?: boolean;
26
32
  /**
@@ -29,6 +35,19 @@ export interface GhostFieldProps {
29
35
  */
30
36
  required?: boolean;
31
37
  }
38
+ /** Scoped slot props from {@link GhostField}. */
39
+ export interface GhostFieldSlotProps {
40
+ invalid: boolean;
41
+ error: string | undefined;
42
+ errors: readonly string[];
43
+ touched: boolean;
44
+ dirty: boolean;
45
+ }
46
+ /** Scoped slot props from {@link GhostFieldError}. */
47
+ export interface GhostFieldErrorSlotProps {
48
+ message: string | undefined;
49
+ errors: readonly string[];
50
+ }
32
51
  /** Props for {@link GhostFieldLabel}. */
33
52
  export interface GhostFieldLabelProps {
34
53
  /**
@@ -137,6 +156,8 @@ export interface GhostFieldContext {
137
156
  errorRegistered: Ref<boolean>;
138
157
  errorVisible: Ref<boolean>;
139
158
  ariaDescribedBy: ComputedRef<string | undefined>;
159
+ errorMessage?: ComputedRef<string | undefined>;
160
+ fieldErrors?: ComputedRef<readonly string[]>;
140
161
  setDescriptionId(id: string | null): void;
141
162
  setErrorId(id: string | null): void;
142
163
  setDescriptionRegistered(registered: boolean): void;
@@ -0,0 +1,273 @@
1
+ import type { ComponentPublicInstance, ComputedRef, InjectionKey, MaybeRefOrGetter, Ref } from 'vue';
2
+ /**
3
+ * Standard Schema v1 structural interface (`~standard`), compatible with Zod,
4
+ * Valibot, ArkType, Yup, and plain inline validators without a runtime
5
+ * dependency.
6
+ */
7
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
8
+ readonly '~standard': StandardSchemaV1.Props<Input, Output>;
9
+ }
10
+ export declare namespace StandardSchemaV1 {
11
+ interface Props<Input = unknown, Output = Input> {
12
+ readonly version: 1;
13
+ readonly vendor: string;
14
+ readonly validate: (value: unknown, options?: Options) => Result<Output> | Promise<Result<Output>>;
15
+ readonly types?: Types<Input, Output> | undefined;
16
+ }
17
+ interface Options {
18
+ readonly libraryOptions?: Record<string, unknown> | undefined;
19
+ }
20
+ type Result<Output> = SuccessResult<Output> | FailureResult;
21
+ interface SuccessResult<Output> {
22
+ readonly value: Output;
23
+ readonly issues?: undefined;
24
+ }
25
+ interface FailureResult {
26
+ readonly issues: readonly Issue[];
27
+ }
28
+ interface Issue {
29
+ readonly message: string;
30
+ readonly path?: readonly (PropertyKey | PathSegment)[] | undefined;
31
+ }
32
+ interface PathSegment {
33
+ readonly key: PropertyKey;
34
+ }
35
+ interface Types<Input = unknown, Output = Input> {
36
+ readonly input: Input;
37
+ readonly output: Output;
38
+ }
39
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
40
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
41
+ }
42
+ /** Validation timing trigger for {@link GhostForm} and {@link useGhostForm}. */
43
+ export type GhostFormValidateTrigger = 'submit' | 'blur' | 'change';
44
+ /** Root `data-state` values exposed by {@link GhostForm}. */
45
+ export type GhostFormDataState = 'submitting' | 'validating' | 'invalid';
46
+ type IsAny<T> = 0 extends 1 & T ? true : false;
47
+ type IsUnknown<T> = IsAny<T> extends true ? false : unknown extends T ? [keyof T] extends [never] ? true : false : false;
48
+ type GhostFormTerminalValue = string | number | boolean | bigint | symbol | null | undefined | Date | URL | RegExp | File | Blob | Map<unknown, unknown> | Set<unknown> | ((...args: never[]) => unknown);
49
+ type GhostFormFieldPathDepth<T, Depth extends readonly unknown[]> = Depth['length'] extends 4 ? never : T extends GhostFormTerminalValue ? never : T extends readonly (infer E)[] ? `${number}` | (E extends GhostFormTerminalValue ? never : `${number}.${GhostFormFieldPathDepth<E, [...Depth, unknown]>}`) : string extends keyof T ? string : {
50
+ [K in keyof T & string]: NonNullable<T[K]> extends GhostFormTerminalValue ? K : NonNullable<T[K]> extends readonly (infer E)[] ? K | `${K}.${number}` | (E extends GhostFormTerminalValue ? never : `${K}.${number}.${GhostFormFieldPathDepth<E, [...Depth, unknown]>}`) : string extends keyof NonNullable<T[K]> ? K | `${K}.${string}` : K | `${K}.${GhostFormFieldPathDepth<NonNullable<T[K]>, [...Depth, unknown]>}`;
51
+ }[keyof T & string];
52
+ /**
53
+ * Bounded-depth (4 levels) canonical dot-path helper for nested objects and
54
+ * arrays in `TValues`. Widens to `string` for `unknown` or index-signature
55
+ * records.
56
+ */
57
+ export type GhostFormFieldPath<TValues> = IsAny<TValues> extends true ? string : IsUnknown<TValues> extends true ? string : string extends keyof TValues ? string : [GhostFormFieldPathDepth<NonNullable<TValues>, []>] extends [never] ? string : GhostFormFieldPathDepth<NonNullable<TValues>, []>;
58
+ /** Payload delivered to `@submit` and `onSubmit` when validation succeeds. */
59
+ export interface GhostFormSubmitPayload<TOutput, TValues> {
60
+ /** Validated and transformed schema output (`StandardSchemaV1.InferOutput<TSchema>`). */
61
+ readonly output: TOutput;
62
+ /** Snapshot reference to the consumer `values` passed into validation. */
63
+ readonly values: TValues;
64
+ /** Originating native `SubmitEvent` when triggered from `<form>`, or `null` for `submit()`. */
65
+ readonly event: SubmitEvent | null;
66
+ /**
67
+ * Registers an asynchronous post-validation mutation on `<GhostForm>`
68
+ * `@submit` listeners so `isSubmitting`, `isPending`, `aria-busy`, and
69
+ * duplicate-submit protection remain active until `promise` settles.
70
+ */
71
+ readonly waitUntil: (promise: PromiseLike<unknown>) => void;
72
+ /** Imperative server-error helper scoped to the active form submission. */
73
+ readonly setFieldErrors: (path: GhostFormFieldPath<TValues> | (string & {}), messages: readonly string[]) => void;
74
+ /** Imperative form-level error helper scoped to the active form submission. */
75
+ readonly setFormErrors: (messages: readonly string[]) => void;
76
+ /** Resets errors, tracking state, and pending epochs. */
77
+ readonly reset: () => void;
78
+ }
79
+ /** Payload delivered to `@invalid` and `onInvalid` when submit validation fails. */
80
+ export interface GhostFormInvalidPayload<TValues> {
81
+ /** All issues returned by the schema for this validation pass, in vendor order. */
82
+ readonly issues: readonly StandardSchemaV1.Issue[];
83
+ /** Visible field-scoped error messages keyed by canonical dot-path. */
84
+ readonly fieldErrors: Readonly<Record<string, readonly string[]>>;
85
+ /** Visible form-level error messages (empty/missing or symbol path). */
86
+ readonly formErrors: readonly string[];
87
+ readonly values: TValues;
88
+ readonly event: SubmitEvent | null;
89
+ }
90
+ /** Result returned by `submit()`. */
91
+ export type GhostFormSubmitResult<TOutput> = {
92
+ readonly status: 'submitted';
93
+ readonly output: TOutput;
94
+ } | {
95
+ readonly status: 'invalid';
96
+ readonly issues: readonly StandardSchemaV1.Issue[];
97
+ } | {
98
+ readonly status: 'aborted';
99
+ } | {
100
+ readonly status: 'ignored';
101
+ };
102
+ /** Result returned by `validate()`. */
103
+ export interface GhostFormValidateResult<TOutput> {
104
+ readonly valid: boolean;
105
+ readonly output?: TOutput;
106
+ readonly issues: readonly StandardSchemaV1.Issue[];
107
+ }
108
+ /** Escape-hatch bindings returned by `fieldProps(path)`. */
109
+ export interface GhostFormFieldBindings {
110
+ readonly name: string;
111
+ readonly invalid: boolean;
112
+ }
113
+ /** Root `<form>` attributes returned by `useGhostForm().formProps`. */
114
+ export interface GhostFormRootAttributes {
115
+ ref: (el: Element | ComponentPublicInstance | null) => void;
116
+ class: 'ghost-form';
117
+ novalidate: true | undefined;
118
+ 'aria-busy'?: 'true' | undefined;
119
+ 'data-part': 'root';
120
+ 'data-ghost-form': '';
121
+ 'data-state'?: GhostFormDataState | undefined;
122
+ onSubmit: (event: SubmitEvent) => void;
123
+ onReset: (event: Event) => void;
124
+ }
125
+ /** Props for {@link GhostForm}. */
126
+ export interface GhostFormProps<TSchema extends StandardSchemaV1 = StandardSchemaV1, TValues = StandardSchemaV1.InferInput<TSchema>> {
127
+ /** Standard Schema v1 validator (`schema['~standard'].version === 1`). */
128
+ schema: TSchema;
129
+ /** Consumer-owned input state passed to `schema['~standard'].validate`. */
130
+ values: NoInfer<TValues>;
131
+ /**
132
+ * Trigger that first reveals issues on an untouched field before the first submit.
133
+ * @default 'submit'
134
+ */
135
+ validateOn?: GhostFormValidateTrigger;
136
+ /**
137
+ * Trigger that re-validates a field once it has visible issues or after submit.
138
+ * @default 'change'
139
+ */
140
+ revalidateOn?: GhostFormValidateTrigger;
141
+ /**
142
+ * Sets HTML `novalidate` on `<form>` so Standard Schema v1 owns submit validation.
143
+ * @default true
144
+ */
145
+ novalidate?: boolean;
146
+ /**
147
+ * Moves focus after DOM flush to the first focusable invalid control when submit fails.
148
+ * @default true
149
+ */
150
+ focusInvalidOnSubmit?: boolean;
151
+ /** Optional seed issues partitioned synchronously at setup without calling `validate()`. */
152
+ initialIssues?: readonly StandardSchemaV1.Issue[] | undefined;
153
+ /** Optional vendor options forwarded as the second argument to `validate()`. */
154
+ schemaOptions?: StandardSchemaV1.Options | undefined;
155
+ }
156
+ /** Events emitted by {@link GhostForm}. */
157
+ export interface GhostFormEmits<TSchema extends StandardSchemaV1 = StandardSchemaV1, TValues = StandardSchemaV1.InferInput<TSchema>> {
158
+ /** Emitted when schema validation succeeds for an accepted submit attempt. */
159
+ submit: [
160
+ payload: GhostFormSubmitPayload<StandardSchemaV1.InferOutput<TSchema>, TValues>
161
+ ];
162
+ /** Emitted when schema validation returns issues for an accepted submit attempt. */
163
+ invalid: [payload: GhostFormInvalidPayload<TValues>];
164
+ /** Emitted when a non-cancelled DOM reset or imperative `reset()` completes. */
165
+ reset: [event: Event | null];
166
+ }
167
+ /** Scoped slot props exposed by {@link GhostForm}'s default slot. */
168
+ export interface GhostFormSlotProps<TSchema extends StandardSchemaV1 = StandardSchemaV1, TValues = StandardSchemaV1.InferInput<TSchema>> {
169
+ readonly fieldErrors: Readonly<Record<string, readonly string[]>>;
170
+ readonly formErrors: readonly string[];
171
+ readonly issues: readonly StandardSchemaV1.Issue[];
172
+ readonly isValid: boolean;
173
+ readonly isInvalid: boolean;
174
+ readonly isValidating: boolean;
175
+ readonly isSubmitting: boolean;
176
+ readonly isPending: boolean;
177
+ readonly isDirty: boolean;
178
+ readonly hasSubmitted: boolean;
179
+ readonly submitCount: number;
180
+ readonly getFieldError: (path: GhostFormFieldPath<TValues>) => string | undefined;
181
+ readonly getFieldErrors: (path: GhostFormFieldPath<TValues>) => readonly string[];
182
+ readonly getFieldIssues: (path: GhostFormFieldPath<TValues>) => readonly StandardSchemaV1.Issue[];
183
+ readonly isFieldInvalid: (path: GhostFormFieldPath<TValues>) => boolean;
184
+ readonly isFieldTouched: (path: GhostFormFieldPath<TValues>) => boolean;
185
+ readonly isFieldDirty: (path: GhostFormFieldPath<TValues>) => boolean;
186
+ readonly fieldProps: (path: GhostFormFieldPath<TValues>) => GhostFormFieldBindings;
187
+ readonly validate: () => Promise<GhostFormValidateResult<StandardSchemaV1.InferOutput<TSchema>>>;
188
+ readonly validateField: (path: GhostFormFieldPath<TValues>) => Promise<readonly StandardSchemaV1.Issue[]>;
189
+ readonly submit: (event?: SubmitEvent | null) => Promise<GhostFormSubmitResult<StandardSchemaV1.InferOutput<TSchema>>>;
190
+ readonly reset: () => void;
191
+ readonly clearErrors: (path?: GhostFormFieldPath<TValues>) => void;
192
+ readonly setFieldErrors: (path: GhostFormFieldPath<TValues> | (string & {}), messages: readonly string[]) => void;
193
+ readonly setFormErrors: (messages: readonly string[]) => void;
194
+ readonly touchField: (path: GhostFormFieldPath<TValues>) => void;
195
+ readonly blurField: (path: GhostFormFieldPath<TValues>) => void;
196
+ }
197
+ /** Methods and DOM ref exposed by {@link GhostForm}. */
198
+ export interface GhostFormExposed<TSchema extends StandardSchemaV1 = StandardSchemaV1, TValues = StandardSchemaV1.InferInput<TSchema>> {
199
+ readonly element: HTMLFormElement | null;
200
+ readonly submit: (event?: SubmitEvent | null) => Promise<GhostFormSubmitResult<StandardSchemaV1.InferOutput<TSchema>>>;
201
+ readonly validate: () => Promise<GhostFormValidateResult<StandardSchemaV1.InferOutput<TSchema>>>;
202
+ readonly validateField: (path: GhostFormFieldPath<TValues>) => Promise<readonly StandardSchemaV1.Issue[]>;
203
+ readonly reset: () => void;
204
+ readonly clearErrors: (path?: GhostFormFieldPath<TValues>) => void;
205
+ readonly setFieldErrors: (path: GhostFormFieldPath<TValues> | (string & {}), messages: readonly string[]) => void;
206
+ readonly setFormErrors: (messages: readonly string[]) => void;
207
+ }
208
+ /** Options for {@link useGhostForm}. */
209
+ export interface UseGhostFormOptions<TSchema extends StandardSchemaV1 = StandardSchemaV1, TValues = StandardSchemaV1.InferInput<TSchema>> {
210
+ schema: MaybeRefOrGetter<TSchema>;
211
+ values: MaybeRefOrGetter<NoInfer<TValues>>;
212
+ validateOn?: MaybeRefOrGetter<GhostFormValidateTrigger | undefined>;
213
+ revalidateOn?: MaybeRefOrGetter<GhostFormValidateTrigger | undefined>;
214
+ novalidate?: MaybeRefOrGetter<boolean | undefined>;
215
+ focusInvalidOnSubmit?: MaybeRefOrGetter<boolean | undefined>;
216
+ initialIssues?: readonly StandardSchemaV1.Issue[] | undefined;
217
+ schemaOptions?: MaybeRefOrGetter<StandardSchemaV1.Options | undefined>;
218
+ /**
219
+ * Provides `ghostFormContextKey` to descendant `GhostField` components when
220
+ * called inside `setup()`. Disable when hosting multiple `useGhostForm`
221
+ * instances in a single component setup scope without `<GhostForm>` wrappers.
222
+ * @default true
223
+ */
224
+ provideContext?: boolean;
225
+ onSubmit?: (payload: GhostFormSubmitPayload<StandardSchemaV1.InferOutput<TSchema>, TValues>) => unknown;
226
+ onInvalid?: (payload: GhostFormInvalidPayload<TValues>) => void;
227
+ onReset?: (event: Event | null) => void;
228
+ }
229
+ /** Reactive state, actions, and root attributes returned by {@link useGhostForm}. */
230
+ export interface UseGhostFormReturn<TSchema extends StandardSchemaV1 = StandardSchemaV1, TValues = StandardSchemaV1.InferInput<TSchema>> {
231
+ readonly element: Ref<HTMLFormElement | null>;
232
+ readonly formRef: (el: Element | ComponentPublicInstance | null) => void;
233
+ readonly formProps: ComputedRef<GhostFormRootAttributes>;
234
+ readonly fieldErrors: ComputedRef<Readonly<Record<string, readonly string[]>>>;
235
+ readonly formErrors: ComputedRef<readonly string[]>;
236
+ readonly issues: ComputedRef<readonly StandardSchemaV1.Issue[]>;
237
+ readonly isValid: ComputedRef<boolean>;
238
+ readonly isInvalid: ComputedRef<boolean>;
239
+ readonly isValidating: ComputedRef<boolean>;
240
+ readonly isSubmitting: ComputedRef<boolean>;
241
+ readonly isPending: ComputedRef<boolean>;
242
+ readonly isDirty: ComputedRef<boolean>;
243
+ readonly hasSubmitted: ComputedRef<boolean>;
244
+ readonly submitCount: ComputedRef<number>;
245
+ readonly getFieldError: (path: GhostFormFieldPath<TValues>) => string | undefined;
246
+ readonly getFieldErrors: (path: GhostFormFieldPath<TValues>) => readonly string[];
247
+ readonly getFieldIssues: (path: GhostFormFieldPath<TValues>) => readonly StandardSchemaV1.Issue[];
248
+ readonly isFieldInvalid: (path: GhostFormFieldPath<TValues>) => boolean;
249
+ readonly isFieldTouched: (path: GhostFormFieldPath<TValues>) => boolean;
250
+ readonly isFieldDirty: (path: GhostFormFieldPath<TValues>) => boolean;
251
+ readonly fieldProps: (path: GhostFormFieldPath<TValues>) => GhostFormFieldBindings;
252
+ readonly validate: () => Promise<GhostFormValidateResult<StandardSchemaV1.InferOutput<TSchema>>>;
253
+ readonly validateField: (path: GhostFormFieldPath<TValues>) => Promise<readonly StandardSchemaV1.Issue[]>;
254
+ readonly submit: (event?: SubmitEvent | null) => Promise<GhostFormSubmitResult<StandardSchemaV1.InferOutput<TSchema>>>;
255
+ readonly reset: () => void;
256
+ readonly clearErrors: (path?: GhostFormFieldPath<TValues>) => void;
257
+ readonly setFieldErrors: (path: GhostFormFieldPath<TValues> | (string & {}), messages: readonly string[]) => void;
258
+ readonly setFormErrors: (messages: readonly string[]) => void;
259
+ readonly touchField: (path: GhostFormFieldPath<TValues>) => void;
260
+ readonly blurField: (path: GhostFormFieldPath<TValues>) => void;
261
+ }
262
+ /** Form context provided to descendant {@link GhostField} instances. */
263
+ export interface GhostFormContext {
264
+ readonly isFieldInvalid: (path: string) => boolean;
265
+ readonly getFieldError: (path: string) => string | undefined;
266
+ readonly getFieldErrors: (path: string) => readonly string[];
267
+ readonly isFieldTouched: (path: string) => boolean;
268
+ readonly isFieldDirty: (path: string) => boolean;
269
+ readonly registerField: (path: string) => () => void;
270
+ readonly blurField: (path: string) => void;
271
+ }
272
+ export declare const ghostFormContextKey: InjectionKey<GhostFormContext>;
273
+ export {};
@@ -0,0 +1,78 @@
1
+ import type { ComputedRef, MaybeRefOrGetter, Ref } from 'vue';
2
+ /**
3
+ * Presence lifecycle phase. `'exiting'` means the surface is logically closed
4
+ * but its DOM stays mounted while its own CSS exit motion runs.
5
+ */
6
+ export type GhostPresencePhase = 'closed' | 'open' | 'exiting';
7
+ /**
8
+ * Value written to the surface's `data-state` hook. `'closed'` covers both the
9
+ * `'exiting'` and `'closed'` phases, so exit CSS targets `[data-state='closed']`.
10
+ */
11
+ export type GhostPresenceDataState = 'open' | 'closed';
12
+ /** Options for {@link useGhostPresence}. */
13
+ export interface UseGhostPresenceOptions {
14
+ /** Logical open state (`true` while open, `false` when logically closed). */
15
+ present: MaybeRefOrGetter<boolean>;
16
+ /**
17
+ * Host element (HTML or SVG) whose own CSS transitions/animations gate DOM
18
+ * removal during the `exiting` phase. Optional when binding `setElement` as a
19
+ * template ref.
20
+ */
21
+ element?: MaybeRefOrGetter<Element | null | undefined>;
22
+ /**
23
+ * Skips exit retention when `true` (for example `disableAnimation` or an
24
+ * anchored overlay closed before initial positioning completed).
25
+ * @default false
26
+ */
27
+ disabled?: MaybeRefOrGetter<boolean | undefined>;
28
+ /**
29
+ * Invoked once after an `exiting` surface finishes its exit motion and flips
30
+ * `isPresent` to `false`. Never called when an exit is interrupted by reopen
31
+ * or aborted by owner component unmount.
32
+ */
33
+ onExitComplete?: () => void;
34
+ }
35
+ /** Reactive state returned by {@link useGhostPresence}. */
36
+ export interface UseGhostPresenceReturn {
37
+ /** `true` while `present` is `true` or while `phase` is `'exiting'`. */
38
+ isPresent: ComputedRef<boolean>;
39
+ /** Current lifecycle phase: `'closed'`, `'open'`, or `'exiting'`. */
40
+ phase: Readonly<Ref<GhostPresencePhase>>;
41
+ /** `'open'` when logically open; `'closed'` during `'exiting'` and `'closed'`. */
42
+ dataState: ComputedRef<GhostPresenceDataState>;
43
+ /** `true` only while `phase` is `'exiting'`. */
44
+ isExiting: ComputedRef<boolean>;
45
+ /**
46
+ * Template-ref setter accepting a raw `Element`, a component instance exposing
47
+ * `{ element: Element | null }` or an `Element` `$el`, or `null`. Used when `options.element`
48
+ * is not passed directly.
49
+ */
50
+ setElement: (target: unknown) => void;
51
+ }
52
+ /** Props for the renderless {@link GhostPresence} component. */
53
+ export interface GhostPresenceProps {
54
+ /**
55
+ * Logical open/mounted state. When `true`, mounts the default slot; when
56
+ * `false`, transitions through `exiting` before unmount.
57
+ */
58
+ present: boolean;
59
+ /**
60
+ * When `true`, bypasses exit waiting and unmounts immediately when `present`
61
+ * turns `false`.
62
+ * @default false
63
+ */
64
+ disabled?: boolean;
65
+ }
66
+ /** Props passed to the {@link GhostPresence} default slot. */
67
+ export interface GhostPresenceSlotProps {
68
+ /** Logical `present` value passed to the component. */
69
+ present: boolean;
70
+ /** Current lifecycle phase. */
71
+ phase: GhostPresencePhase;
72
+ /** Value to bind as `data-state` on a surface that binds `setElement` manually. */
73
+ state: GhostPresenceDataState;
74
+ /** `true` while the exit motion runs; bind `:inert="exiting || undefined"` when binding manually. */
75
+ exiting: boolean;
76
+ /** Template-ref setter for the animated surface when the slot is not a single element. */
77
+ setElement: (target: unknown) => void;
78
+ }
@@ -14,6 +14,42 @@ export type GhostSelectContentElement = string | Component;
14
14
  export type GhostSelectOptionElement = string | Component;
15
15
  export type GhostSelectGroupElement = string | Component;
16
16
  export type GhostSelectLabelElement = string | Component;
17
+ /** Value accepted by `modelValue` / `defaultValue` for a {@link GhostSelect} root. */
18
+ export type GhostSelectValueInput<Multiple extends boolean = false> = Multiple extends true ? readonly string[] : string;
19
+ /** Value emitted by `update:modelValue` for a {@link GhostSelect} root. */
20
+ export type GhostSelectModelValue<Multiple extends boolean = false> = Multiple extends true ? string[] : string | undefined;
21
+ /** Props accepted by {@link GhostSelect}. */
22
+ export interface GhostSelectProps<Multiple extends boolean = false> {
23
+ /** Enables multiple-value selection in `string[]`. Read once at setup. @default false */
24
+ multiple?: Multiple & boolean;
25
+ /** Controlled selected value. `undefined` is uncontrolled. */
26
+ modelValue?: GhostSelectValueInput<Multiple> | undefined;
27
+ /** Initial value when uncontrolled; restored on native form reset. */
28
+ defaultValue?: GhostSelectValueInput<Multiple> | undefined;
29
+ /** Visually hidden submit input `name`. */
30
+ name?: string | undefined;
31
+ /** External `<form>` id to associate with. */
32
+ form?: string | undefined;
33
+ /** Disables trigger and options; omits value from submit. @default false */
34
+ disabled?: boolean;
35
+ /** Native constraint validation when `name` is set. @default false */
36
+ required?: boolean;
37
+ /** Sets `aria-invalid` on the trigger. @default false */
38
+ invalid?: boolean;
39
+ /** Controlled listbox open state. */
40
+ open?: boolean | undefined;
41
+ /** Initial open state when `open` is omitted. @default false */
42
+ defaultOpen?: boolean;
43
+ /** Placeholder text when nothing is selected. */
44
+ placeholder?: string | undefined;
45
+ /** Overridable internal strings (`required` message, `listSeparator`). */
46
+ messages?: GhostSelectMessages | undefined;
47
+ }
48
+ /** Scoped slot props passed to {@link GhostSelectValue}'s default slot. */
49
+ export interface GhostSelectValueSlotProps {
50
+ values: readonly string[];
51
+ labels: readonly string[];
52
+ }
17
53
  export type GhostSelectPlacement = Placement;
18
54
  export type GhostSelectStrategy = Strategy;
19
55
  export type GhostSelectPadding = number | {
@@ -46,8 +82,7 @@ export interface GhostSelectOptionRecord {
46
82
  disabled: boolean;
47
83
  getElement: () => HTMLElement | null;
48
84
  }
49
- export interface GhostSelectContext {
50
- selectedValue: Ref<string | undefined>;
85
+ export interface GhostSelectContextBase {
51
86
  isOpen: Ref<boolean>;
52
87
  open: () => void;
53
88
  close: () => void;
@@ -55,6 +90,8 @@ export interface GhostSelectContext {
55
90
  required: ComputedRef<boolean>;
56
91
  invalid: ComputedRef<boolean>;
57
92
  placeholder: ComputedRef<string | undefined>;
93
+ messages: ComputedRef<GhostSelectMessages | undefined>;
94
+ selectedValues: ComputedRef<readonly string[]>;
58
95
  defaultTriggerId: ComputedRef<string>;
59
96
  defaultContentId: ComputedRef<string>;
60
97
  triggerId: ComputedRef<string>;
@@ -87,6 +124,16 @@ export interface GhostSelectContext {
87
124
  openFocusFromEnd: Ref<boolean>;
88
125
  labelVersion: Ref<number>;
89
126
  }
127
+ export interface GhostSelectSingleContext extends GhostSelectContextBase {
128
+ readonly multiple: false;
129
+ selectedValue: Ref<string | undefined>;
130
+ }
131
+ export interface GhostSelectMultipleContext extends GhostSelectContextBase {
132
+ readonly multiple: true;
133
+ selectedValue: Readonly<Ref<readonly string[]>>;
134
+ replaceSelection: (values: readonly string[]) => void;
135
+ }
136
+ export type GhostSelectContext = GhostSelectSingleContext | GhostSelectMultipleContext;
90
137
  export declare const ghostSelectContextKey: InjectionKey<GhostSelectContext>;
91
138
  export interface GhostSelectTriggerExposed {
92
139
  readonly element: HTMLElement | null;
@@ -112,10 +159,12 @@ export interface GhostSelectExposed {
112
159
  export interface GhostSelectMessages {
113
160
  /** Native constraint validation message when `required` and empty. @default 'Select a value.' */
114
161
  required?: string;
162
+ /** Separator joining selected option labels in multiple mode. @default ', ' */
163
+ listSeparator?: string;
115
164
  }
116
- export interface UseGhostSelectOptions {
117
- modelValue?: MaybeRefOrGetter<string | undefined>;
118
- defaultValue?: MaybeRefOrGetter<string | undefined>;
165
+ interface GhostSelectStateOptions<Multiple extends boolean> {
166
+ modelValue?: MaybeRefOrGetter<GhostSelectValueInput<Multiple> | undefined>;
167
+ defaultValue?: MaybeRefOrGetter<GhostSelectValueInput<Multiple> | undefined>;
119
168
  open?: MaybeRefOrGetter<boolean | undefined>;
120
169
  defaultOpen?: MaybeRefOrGetter<boolean | undefined>;
121
170
  disabled?: MaybeRefOrGetter<boolean | undefined>;
@@ -125,7 +174,15 @@ export interface UseGhostSelectOptions {
125
174
  form?: MaybeRefOrGetter<string | undefined>;
126
175
  placeholder?: MaybeRefOrGetter<string | undefined>;
127
176
  messages?: MaybeRefOrGetter<GhostSelectMessages | undefined>;
128
- onValueChange?: (value: string | undefined) => void;
177
+ onValueChange?: (value: GhostSelectModelValue<Multiple>) => void;
129
178
  onOpenChange?: (open: boolean) => void;
130
179
  getFormInput?: () => HTMLInputElement | null;
180
+ getFormInputs?: () => readonly (HTMLInputElement | null)[];
131
181
  }
182
+ /** The runtime flag must be present when the return type promises an array. */
183
+ export type UseGhostSelectOptions<Multiple extends boolean = false> = GhostSelectStateOptions<Multiple> & ({
184
+ multiple: MaybeRefOrGetter<Multiple>;
185
+ } | (false extends Multiple ? {
186
+ multiple?: MaybeRefOrGetter<Multiple | undefined>;
187
+ } : never));
188
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { GhostPortalTarget } from './ghost-portal.js';
2
+ /** Open state for a submenu within an active menu. */
3
+ export interface GhostSubmenuProps {
4
+ /** Controlled open state. Omit to use the local model. */
5
+ open?: boolean | undefined;
6
+ /** Initial state for an uncontrolled submenu. */
7
+ defaultOpen?: boolean;
8
+ }
9
+ /** Properties for a submenu's menu item trigger. */
10
+ export interface GhostSubmenuTriggerProps {
11
+ /** Skips the trigger during keyboard navigation and prevents entry. */
12
+ disabled?: boolean;
13
+ }
14
+ /** Placement of a submenu's menu surface in the document. */
15
+ export interface GhostSubmenuContentProps {
16
+ /** Teleport the child menu out of the ancestor's DOM subtree. */
17
+ portal?: boolean;
18
+ /** Destination when portaling. Defaults to the document body. */
19
+ portalTo?: GhostPortalTarget;
20
+ }