bits-ui 0.11.1 → 0.11.3

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.
@@ -6,18 +6,23 @@
6
6
  import type { CreateSelectProps, SelectOptionProps } from "@melt-ui/svelte";
7
7
  import type { AsChild, Expand, OmitFloating, OnChangeFn } from "../../internal/index.js";
8
8
  import type { ContentProps, ArrowProps } from "../floating/_types.js";
9
- type Props<T = unknown, Multiple extends boolean = false> = Expand<OmitFloating<Omit<CreateSelectProps, "selected" | "defaultSelected" | "onSelectedChange">> & {
9
+ import type { Selected } from "../..";
10
+ export type WhenTrue<TrueOrFalse, IfTrue, IfFalse, IfNeither = IfTrue | IfFalse> = [
11
+ TrueOrFalse
12
+ ] extends [true] ? IfTrue : [TrueOrFalse] extends [false] ? IfFalse : IfNeither;
13
+ type SelectValue<T, Multiple extends boolean> = WhenTrue<Multiple, T[] | undefined, T | undefined>;
14
+ type Props<T = unknown, Multiple extends boolean = false> = Expand<OmitFloating<Omit<CreateSelectProps, "selected" | "defaultSelected" | "onSelectedChange" | "multiple">> & {
10
15
  /**
11
16
  * The selected value of the select.
12
17
  * You can bind this to a value to programmatically control the selected value.
13
18
  *
14
19
  * @defaultValue undefined
15
20
  */
16
- selected?: CreateSelectProps<T, Multiple>["defaultSelected"] & {};
21
+ selected?: SelectValue<Selected<T>, Multiple> | undefined;
17
22
  /**
18
23
  * A callback function called when the selected value changes.
19
24
  */
20
- onSelectedChange?: OnChangeFn<CreateSelectProps<T, Multiple>["defaultSelected"]>;
25
+ onSelectedChange?: OnChangeFn<SelectValue<Selected<T>, Multiple>>;
21
26
  /**
22
27
  * The open state of the select menu.
23
28
  * You can bind this to a boolean value to programmatically control the open state.
@@ -30,9 +35,14 @@ type Props<T = unknown, Multiple extends boolean = false> = Expand<OmitFloating<
30
35
  */
31
36
  onOpenChange?: OnChangeFn<boolean>;
32
37
  /**
33
- *
38
+ * Whether or not multiple values can be selected.
34
39
  */
35
40
  multiple?: Multiple;
41
+ /**
42
+ * Optionally provide an array of `Selected<T>` objects to
43
+ * type the `selected` and `onSelectedChange` props.
44
+ */
45
+ items?: Selected<T>[];
36
46
  }>;
37
47
  type GroupProps = AsChild;
38
48
  type InputProps = AsChild;
@@ -1,4 +1,6 @@
1
- <script>import { derived } from "svelte/store";
1
+ <script context="module"></script>
2
+
3
+ <script generics="T, Multiple extends boolean = false">import { derived } from "svelte/store";
2
4
  import { setCtx } from "../ctx.js";
3
5
  export let required = void 0;
4
6
  export let disabled = void 0;
@@ -29,7 +31,10 @@ const {
29
31
  name,
30
32
  multiple,
31
33
  forceVisible: true,
32
- defaultSelected: Array.isArray(selected) ? [...selected] : selected,
34
+ defaultSelected: Array.isArray(selected) ? [...selected] : (
35
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
+ selected
37
+ ),
33
38
  defaultOpen: open,
34
39
  onSelectedChange: ({ next }) => {
35
40
  if (Array.isArray(next)) {
@@ -66,7 +71,10 @@ $:
66
71
  open !== void 0 && localOpen.set(open);
67
72
  $:
68
73
  selected !== void 0 && localSelected.set(
69
- Array.isArray(selected) ? [...selected] : selected
74
+ Array.isArray(selected) ? [...selected] : (
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ selected
77
+ )
70
78
  );
71
79
  $:
72
80
  updateOption("required", required);
@@ -1,7 +1,6 @@
1
1
  import { SvelteComponent } from "svelte";
2
- declare class __sveltets_Render<T extends unknown, Multiple extends boolean> {
3
- props(): Omit<{
4
- multiple?: (false & Multiple) | undefined;
2
+ declare class __sveltets_Render<T, Multiple extends boolean = false> {
3
+ props(): {
5
4
  disabled?: boolean | undefined;
6
5
  preventScroll?: boolean | undefined;
7
6
  closeOnEscape?: boolean | undefined;
@@ -13,16 +12,12 @@ declare class __sveltets_Render<T extends unknown, Multiple extends boolean> {
13
12
  typeahead?: boolean | undefined;
14
13
  scrollAlignment?: "center" | "nearest" | undefined;
15
14
  highlightOnHover?: boolean | undefined;
16
- selected?: (import("@melt-ui/svelte/internal/types").WhenTrue<Multiple, import("@melt-ui/svelte/index.js").ComboboxOption<T>[], import("@melt-ui/svelte/index.js").ComboboxOption<T>, import("@melt-ui/svelte/index.js").ComboboxOption<T>[] | import("@melt-ui/svelte/index.js").ComboboxOption<T>> & {}) | undefined;
17
- onSelectedChange?: import("../../../internal/types.js").OnChangeFn<import("@melt-ui/svelte/internal/types").WhenTrue<Multiple, import("@melt-ui/svelte/index.js").ComboboxOption<T>[], import("@melt-ui/svelte/index.js").ComboboxOption<T>, import("@melt-ui/svelte/index.js").ComboboxOption<T>[] | import("@melt-ui/svelte/index.js").ComboboxOption<T>> | undefined> | undefined;
15
+ selected?: import("../_types.js").WhenTrue<Multiple, import("../../../index.js").Selected<T>[] | undefined, import("../../../index.js").Selected<T> | undefined, import("../../../index.js").Selected<T> | import("../../../index.js").Selected<T>[] | undefined> | undefined;
16
+ onSelectedChange?: import("../../../internal/types.js").OnChangeFn<import("../_types.js").WhenTrue<Multiple, import("../../../index.js").Selected<T>[] | undefined, import("../../../index.js").Selected<T> | undefined, import("../../../index.js").Selected<T> | import("../../../index.js").Selected<T>[] | undefined>> | undefined;
18
17
  open?: boolean | undefined;
19
18
  onOpenChange?: import("../../../internal/types.js").OnChangeFn<boolean> | undefined;
20
- }, "multiple"> & {
21
- items?: {
22
- value: T;
23
- label?: string | undefined;
24
- }[] | undefined;
25
19
  multiple?: Multiple | undefined;
20
+ items?: import("../../../index.js").Selected<T>[] | undefined;
26
21
  };
27
22
  events(): {} & {
28
23
  [evt: string]: CustomEvent<any>;
@@ -37,9 +32,9 @@ declare class __sveltets_Render<T extends unknown, Multiple extends boolean> {
37
32
  };
38
33
  };
39
34
  }
40
- export type SelectProps<T extends unknown, Multiple extends boolean> = ReturnType<__sveltets_Render<T, Multiple>['props']>;
41
- export type SelectEvents<T extends unknown, Multiple extends boolean> = ReturnType<__sveltets_Render<T, Multiple>['events']>;
42
- export type SelectSlots<T extends unknown, Multiple extends boolean> = ReturnType<__sveltets_Render<T, Multiple>['slots']>;
43
- export default class Select<T extends unknown, Multiple extends boolean> extends SvelteComponent<SelectProps<T, Multiple>, SelectEvents<T, Multiple>, SelectSlots<T, Multiple>> {
35
+ export type SelectProps<T, Multiple extends boolean = false> = ReturnType<__sveltets_Render<T, Multiple>['props']>;
36
+ export type SelectEvents<T, Multiple extends boolean = false> = ReturnType<__sveltets_Render<T, Multiple>['events']>;
37
+ export type SelectSlots<T, Multiple extends boolean = false> = ReturnType<__sveltets_Render<T, Multiple>['slots']>;
38
+ export default class Select<T, Multiple extends boolean = false> extends SvelteComponent<SelectProps<T, Multiple>, SelectEvents<T, Multiple>, SelectSlots<T, Multiple>> {
44
39
  }
45
40
  export {};
@@ -2,7 +2,7 @@ import type { HTMLDivAttributes, Transition } from "../../internal/index.js";
2
2
  import type { EventHandler, HTMLAttributes, HTMLButtonAttributes, HTMLInputAttributes } from "svelte/elements";
3
3
  import type { CustomEventHandler } from "../../index.js";
4
4
  import type * as I from "./_types.js";
5
- type Props<T = unknown, Multiple extends boolean = false> = I.Props<T, Multiple>;
5
+ type Props<T, Multiple extends boolean = false> = I.Props<T, Multiple>;
6
6
  type ContentProps<T extends Transition = Transition, In extends Transition = Transition, Out extends Transition = Transition> = I.ContentProps<T, In, Out> & HTMLDivAttributes;
7
7
  type GroupProps = I.GroupProps & HTMLDivAttributes;
8
8
  type InputProps = I.InputProps & HTMLInputAttributes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "exports": {