compote-ui 0.8.0 → 0.10.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.
@@ -1,9 +1,10 @@
1
- <script lang="ts" generics="T extends ComboboxItem">
2
- import { Combobox, createListCollection } from '@ark-ui/svelte/combobox';
1
+ <script lang="ts" generics="T extends ListItem">
2
+ import { Combobox } from '@ark-ui/svelte/combobox';
3
3
  import { Field } from '@ark-ui/svelte/field';
4
4
  import { useFilter } from '@ark-ui/svelte/locale';
5
5
  import { Portal } from '@ark-ui/svelte/portal';
6
- import type { ComboboxItem, ComboboxProps } from './types';
6
+ import type { ComboboxProps } from './types';
7
+ import { createListCollection, type ListItem } from '../../utils/collections';
7
8
  import { cn } from 'tailwind-variants';
8
9
  import PhCaretDown from '../../icons/PhCaretDown.svelte';
9
10
  import PhCheck from '../../icons/PhCheck.svelte';
@@ -27,13 +28,7 @@
27
28
  const filters = useFilter({ sensitivity: 'base' });
28
29
 
29
30
  // Base collection — only rebuilds when items prop changes
30
- const baseCollection = $derived(
31
- createListCollection({
32
- items,
33
- itemToString: (item) => item?.label ?? '',
34
- itemToValue: (item) => item?.value?.toString() ?? ''
35
- })
36
- );
31
+ const baseCollection = $derived(createListCollection(items));
37
32
 
38
33
  // Filtered view — lightweight .filter() on keystroke, full collection when empty
39
34
  const collection = $derived(
@@ -1,13 +1,14 @@
1
1
  import { Combobox } from '@ark-ui/svelte/combobox';
2
- import type { ComboboxItem, ComboboxProps } from './types';
3
- declare function $$render<T extends ComboboxItem>(): {
2
+ import type { ComboboxProps } from './types';
3
+ import { type ListItem } from '../../utils/collections';
4
+ declare function $$render<T extends ListItem>(): {
4
5
  props: ComboboxProps<T>;
5
6
  exports: {};
6
7
  bindings: "value";
7
8
  slots: {};
8
9
  events: {};
9
10
  };
10
- declare class __sveltets_Render<T extends ComboboxItem> {
11
+ declare class __sveltets_Render<T extends ListItem> {
11
12
  props(): ReturnType<typeof $$render<T>>['props'];
12
13
  events(): ReturnType<typeof $$render<T>>['events'];
13
14
  slots(): ReturnType<typeof $$render<T>>['slots'];
@@ -15,12 +16,12 @@ declare class __sveltets_Render<T extends ComboboxItem> {
15
16
  exports(): {};
16
17
  }
17
18
  interface $$IsomorphicComponent {
18
- new <T extends ComboboxItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
+ new <T extends ListItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
20
  $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
20
21
  } & ReturnType<__sveltets_Render<T>['exports']>;
21
- <T extends ComboboxItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
+ <T extends ListItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
23
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
23
24
  }
24
25
  declare const Combobox: $$IsomorphicComponent;
25
- type Combobox<T extends ComboboxItem> = InstanceType<typeof Combobox<T>>;
26
+ type Combobox<T extends ListItem> = InstanceType<typeof Combobox<T>>;
26
27
  export default Combobox;
@@ -1,10 +1,6 @@
1
1
  import type { ComboboxRootBaseProps } from '@ark-ui/svelte/combobox';
2
- export interface ComboboxItem<T = number | string> {
3
- value: T;
4
- label: string;
5
- disabled?: boolean;
6
- }
7
- export interface ComboboxProps<T extends ComboboxItem> extends Omit<ComboboxRootBaseProps<T>, 'value' | 'collection'> {
2
+ import type { ListItem } from '../../utils/collections';
3
+ export interface ComboboxProps<T extends ListItem> extends Omit<ComboboxRootBaseProps<T>, 'value' | 'collection'> {
8
4
  value?: number | string | null | (number | string)[];
9
5
  items: T[];
10
6
  label?: string;
@@ -1,12 +1,13 @@
1
1
  <script module>
2
2
  // eslint-disable-next-line no-import-assign
3
- export type { ListboxItem, ListboxProps } from './types';
3
+ export type { ListboxProps } from './types';
4
4
  </script>
5
5
 
6
6
  <script lang="ts" generics="T extends number | string = number | string">
7
7
  import { Listbox, createListCollection } from '@ark-ui/svelte/listbox';
8
8
  import { useFilter } from '@ark-ui/svelte/locale';
9
- import type { ListboxItem, ListboxProps } from './types';
9
+ import type { ListboxProps } from './types';
10
+ import type { ListItem } from '../../utils/collections';
10
11
  import { cn } from 'tailwind-variants';
11
12
  import PhCheck from '../../icons/PhCheck.svelte';
12
13
 
@@ -33,7 +34,7 @@
33
34
  items,
34
35
  itemToValue: (item) => item.value.toString(),
35
36
  isItemDisabled: (item) => item.disabled === true,
36
- ...(hasGroups ? { groupBy: (item: ListboxItem<T>) => item.group ?? '' } : {})
37
+ ...(hasGroups ? { groupBy: (item: ListItem<T>) => item.group ?? '' } : {})
37
38
  })
38
39
  );
39
40
 
@@ -1,4 +1,4 @@
1
- export type { ListboxItem, ListboxProps } from './types';
1
+ export type { ListboxProps } from './types';
2
2
  import { Listbox } from '@ark-ui/svelte/listbox';
3
3
  import type { ListboxProps } from './types';
4
4
  declare function $$render<T extends number | string = number | string>(): {
@@ -1,12 +1,7 @@
1
1
  import type { ListboxRootBaseProps } from '@ark-ui/svelte/listbox';
2
- export interface ListboxItem<T = number | string> {
3
- value: T;
4
- label: string;
5
- disabled?: boolean;
6
- group?: string;
7
- }
8
- export interface ListboxProps<T extends number | string = number | string> extends Omit<ListboxRootBaseProps<ListboxItem<T>>, 'collection' | 'value'> {
9
- items: ListboxItem<T>[];
2
+ import type { ListItem } from '../../utils/collections';
3
+ export interface ListboxProps<T extends number | string = number | string> extends Omit<ListboxRootBaseProps<ListItem<T>>, 'collection' | 'value'> {
4
+ items: ListItem<T>[];
10
5
  value?: T[];
11
6
  label?: string;
12
7
  name?: string;
@@ -1,8 +1,9 @@
1
- <script lang="ts" generics="T extends SelectItem">
1
+ <script lang="ts" generics="T extends ListItem">
2
2
  import { Field } from '@ark-ui/svelte/field';
3
3
  import { Portal } from '@ark-ui/svelte/portal';
4
- import { Select, createListCollection } from '@ark-ui/svelte/select';
5
- import type { SelectItem, SelectProps } from './types';
4
+ import { Select } from '@ark-ui/svelte/select';
5
+ import type { SelectProps } from './types';
6
+ import { createListCollection, type ListItem } from '../../utils/collections';
6
7
  import { cn } from 'tailwind-variants';
7
8
  import PhCaretDown from '../../icons/PhCaretDown.svelte';
8
9
  import PhCheck from '../../icons/PhCheck.svelte';
@@ -20,13 +21,7 @@
20
21
  layout === 'horizontal' ? 'flex items-center gap-1.5' : 'grid gap-1.5'
21
22
  );
22
23
 
23
- const collection = $derived(
24
- createListCollection<T>({
25
- items: items,
26
- itemToValue: (item) => item.value.toString(),
27
- isItemDisabled: (item) => item.disabled === true
28
- })
29
- );
24
+ const collection = $derived(createListCollection(items));
30
25
  </script>
31
26
 
32
27
  <Select.Root
@@ -1,13 +1,14 @@
1
1
  import { Select } from '@ark-ui/svelte/select';
2
- import type { SelectItem, SelectProps } from './types';
3
- declare function $$render<T extends SelectItem>(): {
2
+ import type { SelectProps } from './types';
3
+ import { type ListItem } from '../../utils/collections';
4
+ declare function $$render<T extends ListItem>(): {
4
5
  props: SelectProps<T>;
5
6
  exports: {};
6
7
  bindings: "value";
7
8
  slots: {};
8
9
  events: {};
9
10
  };
10
- declare class __sveltets_Render<T extends SelectItem> {
11
+ declare class __sveltets_Render<T extends ListItem> {
11
12
  props(): ReturnType<typeof $$render<T>>['props'];
12
13
  events(): ReturnType<typeof $$render<T>>['events'];
13
14
  slots(): ReturnType<typeof $$render<T>>['slots'];
@@ -15,12 +16,12 @@ declare class __sveltets_Render<T extends SelectItem> {
15
16
  exports(): {};
16
17
  }
17
18
  interface $$IsomorphicComponent {
18
- new <T extends SelectItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
+ new <T extends ListItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
20
  $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
20
21
  } & ReturnType<__sveltets_Render<T>['exports']>;
21
- <T extends SelectItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
+ <T extends ListItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
23
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
23
24
  }
24
25
  declare const Select: $$IsomorphicComponent;
25
- type Select<T extends SelectItem> = InstanceType<typeof Select<T>>;
26
+ type Select<T extends ListItem> = InstanceType<typeof Select<T>>;
26
27
  export default Select;
@@ -1,10 +1,6 @@
1
1
  import type { SelectRootBaseProps } from '@ark-ui/svelte/select';
2
- export interface SelectItem<T = number | string> {
3
- value: T;
4
- label: string;
5
- disabled?: boolean;
6
- }
7
- export interface SelectProps<T extends SelectItem> extends Omit<SelectRootBaseProps<T>, 'value' | 'collection'> {
2
+ import type { ListItem } from '../../utils/collections';
3
+ export interface SelectProps<T extends ListItem> extends Omit<SelectRootBaseProps<T>, 'value' | 'collection'> {
8
4
  value?: number | string | null;
9
5
  items: T[];
10
6
  label?: string;
@@ -1,7 +1,8 @@
1
- <script lang="ts" generics="T extends TreeNode">
2
- import { TreeView, createTreeCollection } from '@ark-ui/svelte/tree-view';
1
+ <script lang="ts" generics="T extends TreeItem">
2
+ import { TreeView } from '@ark-ui/svelte/tree-view';
3
3
  import { useFilter } from '@ark-ui/svelte/locale';
4
- import type { TreeNode, TreeViewProps } from './types';
4
+ import type { TreeViewProps } from './types';
5
+ import { createTreeCollection, type TreeItem } from '../../utils/collections';
5
6
  import { Debounced } from 'runed';
6
7
  import PhX from '../../icons/PhX.svelte';
7
8
  import PhCaretRight from '../../icons/PhCaretRight.svelte';
@@ -30,13 +31,7 @@
30
31
  const filterFns = useFilter({ sensitivity: 'base' });
31
32
  let searchTerm: string | undefined = $state();
32
33
  const debouncedSearchTerm = new Debounced(() => searchTerm, 250);
33
- const baseCollection = $derived(
34
- createTreeCollection<T>({
35
- nodeToValue: (node) => node.value.toString(),
36
- nodeToString: (node) => node.label,
37
- rootNode: { value: 'ROOT', label: '', children: items } as unknown as T
38
- })
39
- );
34
+ const baseCollection = $derived(createTreeCollection(items));
40
35
  const collection = $derived.by(() => {
41
36
  const term = debouncedSearchTerm.current ?? '';
42
37
  return term.length > 0
@@ -1,13 +1,14 @@
1
1
  import { TreeView } from '@ark-ui/svelte/tree-view';
2
- import type { TreeNode, TreeViewProps } from './types';
3
- declare function $$render<T extends TreeNode>(): {
2
+ import type { TreeViewProps } from './types';
3
+ import { type TreeItem } from '../../utils/collections';
4
+ declare function $$render<T extends TreeItem>(): {
4
5
  props: TreeViewProps<T>;
5
6
  exports: {};
6
7
  bindings: "selectedValue" | "checkedValue" | "contextNode";
7
8
  slots: {};
8
9
  events: {};
9
10
  };
10
- declare class __sveltets_Render<T extends TreeNode> {
11
+ declare class __sveltets_Render<T extends TreeItem> {
11
12
  props(): ReturnType<typeof $$render<T>>['props'];
12
13
  events(): ReturnType<typeof $$render<T>>['events'];
13
14
  slots(): ReturnType<typeof $$render<T>>['slots'];
@@ -15,12 +16,12 @@ declare class __sveltets_Render<T extends TreeNode> {
15
16
  exports(): {};
16
17
  }
17
18
  interface $$IsomorphicComponent {
18
- new <T extends TreeNode>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
+ new <T extends TreeItem>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
20
  $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
20
21
  } & ReturnType<__sveltets_Render<T>['exports']>;
21
- <T extends TreeNode>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
+ <T extends TreeItem>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
23
  z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
23
24
  }
24
25
  declare const TreeView: $$IsomorphicComponent;
25
- type TreeView<T extends TreeNode> = InstanceType<typeof TreeView<T>>;
26
+ type TreeView<T extends TreeItem> = InstanceType<typeof TreeView<T>>;
26
27
  export default TreeView;
@@ -1,11 +1,6 @@
1
1
  import type { UseTreeViewProps } from '@ark-ui/svelte/tree-view';
2
- export interface TreeNode {
3
- value: number | string;
4
- label: string;
5
- disabled?: boolean;
6
- children?: TreeNode[];
7
- }
8
- export interface TreeViewProps<T extends TreeNode> extends Omit<UseTreeViewProps<T>, 'collection'> {
2
+ import type { TreeItem } from '../../utils/collections';
3
+ export interface TreeViewProps<T extends TreeItem> extends Omit<UseTreeViewProps<T>, 'collection'> {
9
4
  items?: T[];
10
5
  label?: string;
11
6
  contextNode?: string | null;
package/dist/index.d.ts CHANGED
@@ -26,4 +26,6 @@ export * as Tabs from './components/tabs';
26
26
  export * as Menu from './components/menu';
27
27
  export * as Field from './components/field';
28
28
  export { default as TreeView } from './components/tree-view/tree-view.svelte';
29
- export type { TreeNode } from './components/tree-view/types';
29
+ export { createListCollection, createTreeCollection } from './utils/collections';
30
+ export type { ListItem, TreeItem } from './utils/collections';
31
+ export type { ListCollection, TreeCollection } from '@ark-ui/svelte/collection';
package/dist/index.js CHANGED
@@ -20,3 +20,4 @@ export * as Tabs from './components/tabs';
20
20
  export * as Menu from './components/menu';
21
21
  export * as Field from './components/field';
22
22
  export { default as TreeView } from './components/tree-view/tree-view.svelte';
23
+ export { createListCollection, createTreeCollection } from './utils/collections';
@@ -0,0 +1,15 @@
1
+ import type { ListCollection, TreeCollection } from '@ark-ui/svelte/collection';
2
+ export interface ListItem<T = number | string> {
3
+ value: T;
4
+ label: string;
5
+ disabled?: boolean;
6
+ group?: string;
7
+ }
8
+ export interface TreeItem {
9
+ value: number | string;
10
+ label: string;
11
+ disabled?: boolean;
12
+ children?: TreeItem[];
13
+ }
14
+ export declare function createListCollection<T extends ListItem>(items: T[]): ListCollection<T>;
15
+ export declare function createTreeCollection<T extends TreeItem>(items: T[]): TreeCollection<T>;
@@ -0,0 +1,17 @@
1
+ import { createListCollection as arkCreateListCollection, createTreeCollection as arkCreateTreeCollection } from '@ark-ui/svelte/collection';
2
+ export function createListCollection(items) {
3
+ return arkCreateListCollection({
4
+ items,
5
+ itemToValue: (item) => item.value.toString(),
6
+ itemToString: (item) => item.label,
7
+ isItemDisabled: (item) => item.disabled === true
8
+ });
9
+ }
10
+ export function createTreeCollection(items) {
11
+ return arkCreateTreeCollection({
12
+ nodeToValue: (node) => node.value.toString(),
13
+ nodeToString: (node) => node.label,
14
+ nodeToChildren: (node) => (node.children ?? []),
15
+ rootNode: { value: 'ROOT', label: '', children: items }
16
+ });
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",
@@ -1,2 +0,0 @@
1
- export { default as Switch } from './switch.svelte';
2
- export type { SwitchProps } from './types';
@@ -1 +0,0 @@
1
- export { default as Switch } from './switch.svelte';