@humanspeak/svelte-headless-table 6.0.1 → 6.0.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.
Files changed (78) hide show
  1. package/README.md +2 -2
  2. package/dist/bodyCells.d.ts +116 -0
  3. package/dist/bodyCells.js +80 -0
  4. package/dist/bodyRows.d.ts +92 -0
  5. package/dist/bodyRows.js +55 -0
  6. package/dist/columns.d.ts +204 -0
  7. package/dist/columns.js +120 -0
  8. package/dist/constants.d.ts +4 -0
  9. package/dist/constants.js +4 -0
  10. package/dist/createTable.d.ts +107 -0
  11. package/dist/createTable.js +92 -0
  12. package/dist/createViewModel.d.ts +105 -2
  13. package/dist/createViewModel.js +55 -1
  14. package/dist/headerCells.d.ts +210 -0
  15. package/dist/headerCells.js +151 -0
  16. package/dist/headerRows.d.ts +72 -0
  17. package/dist/headerRows.js +60 -0
  18. package/dist/plugins/addColumnFilters.d.ts +101 -0
  19. package/dist/plugins/addColumnFilters.js +55 -0
  20. package/dist/plugins/addColumnOrder.d.ts +30 -0
  21. package/dist/plugins/addColumnOrder.js +21 -0
  22. package/dist/plugins/addDataExport.d.ts +51 -0
  23. package/dist/plugins/addDataExport.js +30 -0
  24. package/dist/plugins/addExpandedRows.d.ts +43 -2
  25. package/dist/plugins/addExpandedRows.js +48 -2
  26. package/dist/plugins/addFlatten.d.ts +48 -3
  27. package/dist/plugins/addFlatten.js +28 -0
  28. package/dist/plugins/addGridLayout.d.ts +13 -0
  29. package/dist/plugins/addGridLayout.js +13 -0
  30. package/dist/plugins/addGroupBy.d.ts +80 -4
  31. package/dist/plugins/addGroupBy.js +48 -4
  32. package/dist/plugins/addHiddenColumns.d.ts +27 -0
  33. package/dist/plugins/addHiddenColumns.js +19 -0
  34. package/dist/plugins/addPagination.d.ts +54 -0
  35. package/dist/plugins/addPagination.js +29 -0
  36. package/dist/plugins/addResizedColumns.d.ts +58 -4
  37. package/dist/plugins/addResizedColumns.js +33 -0
  38. package/dist/plugins/addSelectedRows.d.ts +60 -2
  39. package/dist/plugins/addSelectedRows.js +67 -2
  40. package/dist/plugins/addSortBy.d.ts +83 -6
  41. package/dist/plugins/addSortBy.js +65 -24
  42. package/dist/plugins/addSubRows.d.ts +39 -1
  43. package/dist/plugins/addSubRows.js +25 -0
  44. package/dist/plugins/addTableFilter.d.ts +87 -3
  45. package/dist/plugins/addTableFilter.js +90 -40
  46. package/dist/plugins/cacheConfig.d.ts +7 -0
  47. package/dist/plugins/cacheConfig.js +11 -0
  48. package/dist/tableComponent.d.ts +41 -0
  49. package/dist/tableComponent.js +37 -0
  50. package/dist/types/Action.d.ts +16 -2
  51. package/dist/types/Entries.d.ts +6 -0
  52. package/dist/types/KeyPath.d.ts +20 -0
  53. package/dist/types/Label.d.ts +26 -3
  54. package/dist/types/Matrix.d.ts +6 -0
  55. package/dist/types/TablePlugin.d.ts +140 -10
  56. package/dist/utils/array.d.ts +24 -0
  57. package/dist/utils/array.js +24 -0
  58. package/dist/utils/attributes.d.ts +31 -0
  59. package/dist/utils/attributes.js +31 -0
  60. package/dist/utils/clone.d.ts +19 -0
  61. package/dist/utils/clone.js +13 -0
  62. package/dist/utils/compare.d.ts +29 -0
  63. package/dist/utils/compare.js +29 -0
  64. package/dist/utils/counter.d.ts +12 -0
  65. package/dist/utils/counter.js +12 -0
  66. package/dist/utils/css.d.ts +11 -0
  67. package/dist/utils/css.js +11 -0
  68. package/dist/utils/event.d.ts +14 -0
  69. package/dist/utils/event.js +14 -0
  70. package/dist/utils/filter.d.ts +47 -0
  71. package/dist/utils/filter.js +47 -0
  72. package/dist/utils/math.d.ts +22 -0
  73. package/dist/utils/math.js +22 -0
  74. package/dist/utils/matrix.d.ts +24 -0
  75. package/dist/utils/matrix.js +24 -0
  76. package/dist/utils/store.d.ts +116 -9
  77. package/dist/utils/store.js +63 -0
  78. package/package.json +31 -30
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Compares two values or arrays for sorting purposes.
3
+ * Returns a negative number if a < b, positive if a > b, and 0 if equal.
4
+ *
5
+ * @template T - The type of elements being compared (string or number).
6
+ * @param a - The first value or array to compare.
7
+ * @param b - The second value or array to compare.
8
+ * @returns A number indicating the sort order.
9
+ * @example
10
+ * ```typescript
11
+ * compare(1, 2) // Returns -1
12
+ * compare('b', 'a') // Returns 1
13
+ * compare([1, 2], [1, 3]) // Returns -1
14
+ * ```
15
+ */
1
16
  export const compare = (a, b) => {
2
17
  if (Array.isArray(a) && Array.isArray(b)) {
3
18
  return compareArray(a, b);
@@ -6,6 +21,20 @@ export const compare = (a, b) => {
6
21
  return a - b;
7
22
  return a < b ? -1 : a > b ? 1 : 0;
8
23
  };
24
+ /**
25
+ * Compares two arrays element by element for sorting purposes.
26
+ * Comparison stops at the first non-equal element.
27
+ *
28
+ * @template T - The type of elements in the arrays (string or number).
29
+ * @param a - The first array to compare.
30
+ * @param b - The second array to compare.
31
+ * @returns A number indicating the sort order based on the first differing element.
32
+ * @example
33
+ * ```typescript
34
+ * compareArray([1, 2, 3], [1, 2, 4]) // Returns -1
35
+ * compareArray(['a', 'b'], ['a', 'a']) // Returns 1
36
+ * ```
37
+ */
9
38
  export const compareArray = (a, b) => {
10
39
  const minLength = Math.min(a.length, b.length);
11
40
  for (let i = 0; i < minLength; i++) {
@@ -1 +1,13 @@
1
+ /**
2
+ * Creates a Map that counts the occurrences of each element in an array.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param items - The array of items to count.
6
+ * @returns A Map where keys are unique items and values are their occurrence counts.
7
+ * @example
8
+ * ```typescript
9
+ * getCounter(['a', 'b', 'a', 'c', 'a'])
10
+ * // Returns Map { 'a' => 3, 'b' => 1, 'c' => 1 }
11
+ * ```
12
+ */
1
13
  export declare const getCounter: <T>(items: T[]) => Map<T, number>;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Creates a Map that counts the occurrences of each element in an array.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param items - The array of items to count.
6
+ * @returns A Map where keys are unique items and values are their occurrence counts.
7
+ * @example
8
+ * ```typescript
9
+ * getCounter(['a', 'b', 'a', 'c', 'a'])
10
+ * // Returns Map { 'a' => 3, 'b' => 1, 'c' => 1 }
11
+ * ```
12
+ */
1
13
  export const getCounter = (items) => {
2
14
  const result = new Map();
3
15
  items.forEach((item) => {
@@ -1 +1,12 @@
1
+ /**
2
+ * Converts a CSS style object into an inline style string.
3
+ *
4
+ * @param style - An object containing CSS property-value pairs.
5
+ * @returns A semicolon-separated string of CSS declarations.
6
+ * @example
7
+ * ```typescript
8
+ * stringifyCss({ color: 'red', fontSize: '14px' })
9
+ * // Returns 'color:red;fontSize:14px'
10
+ * ```
11
+ */
1
12
  export declare const stringifyCss: (style: Record<string, unknown>) => string;
package/dist/utils/css.js CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Converts a CSS style object into an inline style string.
3
+ *
4
+ * @param style - An object containing CSS property-value pairs.
5
+ * @returns A semicolon-separated string of CSS declarations.
6
+ * @example
7
+ * ```typescript
8
+ * stringifyCss({ color: 'red', fontSize: '14px' })
9
+ * // Returns 'color:red;fontSize:14px'
10
+ * ```
11
+ */
1
12
  export const stringifyCss = (style) => {
2
13
  return Object.entries(style)
3
14
  .map(([name, value]) => `${name}:${value}`)
@@ -1 +1,15 @@
1
+ /**
2
+ * Determines if an event is a mouse click with the Shift key held down.
3
+ *
4
+ * @param event - The DOM event to check.
5
+ * @returns True if the event is a MouseEvent with shiftKey pressed, false otherwise.
6
+ * @example
7
+ * ```typescript
8
+ * element.addEventListener('click', (e) => {
9
+ * if (isShiftClick(e)) {
10
+ * // Handle shift+click
11
+ * }
12
+ * })
13
+ * ```
14
+ */
1
15
  export declare const isShiftClick: (event: Event) => boolean;
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Determines if an event is a mouse click with the Shift key held down.
3
+ *
4
+ * @param event - The DOM event to check.
5
+ * @returns True if the event is a MouseEvent with shiftKey pressed, false otherwise.
6
+ * @example
7
+ * ```typescript
8
+ * element.addEventListener('click', (e) => {
9
+ * if (isShiftClick(e)) {
10
+ * // Handle shift+click
11
+ * }
12
+ * })
13
+ * ```
14
+ */
1
15
  export const isShiftClick = (event) => {
2
16
  if (!(event instanceof MouseEvent))
3
17
  return false;
@@ -1,4 +1,51 @@
1
+ /**
2
+ * Type guard that checks if a value is not null.
3
+ *
4
+ * @template T - The non-null type.
5
+ * @param value - The value to check.
6
+ * @returns True if the value is not null.
7
+ * @example
8
+ * ```typescript
9
+ * const items = [1, null, 2, null, 3]
10
+ * const filtered = items.filter(nonNull) // Type: number[]
11
+ * ```
12
+ */
1
13
  export declare const nonNull: <T>(value: T | null) => value is T;
14
+ /**
15
+ * Type guard that checks if a value is not undefined.
16
+ *
17
+ * @template T - The defined type.
18
+ * @param value - The value to check.
19
+ * @returns True if the value is not undefined.
20
+ * @example
21
+ * ```typescript
22
+ * const items = [1, undefined, 2, undefined, 3]
23
+ * const filtered = items.filter(nonUndefined) // Type: number[]
24
+ * ```
25
+ */
2
26
  export declare const nonUndefined: <T>(value: T | undefined) => value is T;
27
+ /**
28
+ * Type guard that checks if a value is neither null nor undefined.
29
+ *
30
+ * @template T - The non-nullish type.
31
+ * @param value - The value to check.
32
+ * @returns True if the value is not null and not undefined.
33
+ * @example
34
+ * ```typescript
35
+ * const items = [1, null, 2, undefined, 3]
36
+ * const filtered = items.filter(nonNullish) // Type: number[]
37
+ * ```
38
+ */
3
39
  export declare const nonNullish: <T>(value: T | null | undefined) => value is T;
40
+ /**
41
+ * Type guard that checks if a value is a number.
42
+ *
43
+ * @param value - The value to check.
44
+ * @returns True if the value is of type number.
45
+ * @example
46
+ * ```typescript
47
+ * isNumber(42) // Returns true
48
+ * isNumber('42') // Returns false
49
+ * ```
50
+ */
4
51
  export declare const isNumber: (value: unknown) => value is number;
@@ -1,4 +1,51 @@
1
+ /**
2
+ * Type guard that checks if a value is not null.
3
+ *
4
+ * @template T - The non-null type.
5
+ * @param value - The value to check.
6
+ * @returns True if the value is not null.
7
+ * @example
8
+ * ```typescript
9
+ * const items = [1, null, 2, null, 3]
10
+ * const filtered = items.filter(nonNull) // Type: number[]
11
+ * ```
12
+ */
1
13
  export const nonNull = (value) => value !== null;
14
+ /**
15
+ * Type guard that checks if a value is not undefined.
16
+ *
17
+ * @template T - The defined type.
18
+ * @param value - The value to check.
19
+ * @returns True if the value is not undefined.
20
+ * @example
21
+ * ```typescript
22
+ * const items = [1, undefined, 2, undefined, 3]
23
+ * const filtered = items.filter(nonUndefined) // Type: number[]
24
+ * ```
25
+ */
2
26
  export const nonUndefined = (value) => value !== undefined;
27
+ /**
28
+ * Type guard that checks if a value is neither null nor undefined.
29
+ *
30
+ * @template T - The non-nullish type.
31
+ * @param value - The value to check.
32
+ * @returns True if the value is not null and not undefined.
33
+ * @example
34
+ * ```typescript
35
+ * const items = [1, null, 2, undefined, 3]
36
+ * const filtered = items.filter(nonNullish) // Type: number[]
37
+ * ```
38
+ */
3
39
  export const nonNullish = (value) => value != null;
40
+ /**
41
+ * Type guard that checks if a value is a number.
42
+ *
43
+ * @param value - The value to check.
44
+ * @returns True if the value is of type number.
45
+ * @example
46
+ * ```typescript
47
+ * isNumber(42) // Returns true
48
+ * isNumber('42') // Returns false
49
+ * ```
50
+ */
4
51
  export const isNumber = (value) => typeof value === 'number';
@@ -1,2 +1,24 @@
1
+ /**
2
+ * Calculates the sum of an array of numbers.
3
+ *
4
+ * @param nums - The array of numbers to sum.
5
+ * @returns The sum of all numbers in the array, or 0 for an empty array.
6
+ * @example
7
+ * ```typescript
8
+ * sum([1, 2, 3, 4, 5]) // Returns 15
9
+ * sum([]) // Returns 0
10
+ * ```
11
+ */
1
12
  export declare const sum: (nums: number[]) => number;
13
+ /**
14
+ * Calculates the arithmetic mean (average) of an array of numbers.
15
+ *
16
+ * @param nums - The array of numbers to average.
17
+ * @returns The mean of all numbers, or 0 for an empty array.
18
+ * @example
19
+ * ```typescript
20
+ * mean([1, 2, 3, 4, 5]) // Returns 3
21
+ * mean([]) // Returns 0
22
+ * ```
23
+ */
2
24
  export declare const mean: (nums: number[]) => number;
@@ -1,2 +1,24 @@
1
+ /**
2
+ * Calculates the sum of an array of numbers.
3
+ *
4
+ * @param nums - The array of numbers to sum.
5
+ * @returns The sum of all numbers in the array, or 0 for an empty array.
6
+ * @example
7
+ * ```typescript
8
+ * sum([1, 2, 3, 4, 5]) // Returns 15
9
+ * sum([]) // Returns 0
10
+ * ```
11
+ */
1
12
  export const sum = (nums) => nums.reduce((a, b) => a + b, 0);
13
+ /**
14
+ * Calculates the arithmetic mean (average) of an array of numbers.
15
+ *
16
+ * @param nums - The array of numbers to average.
17
+ * @returns The mean of all numbers, or 0 for an empty array.
18
+ * @example
19
+ * ```typescript
20
+ * mean([1, 2, 3, 4, 5]) // Returns 3
21
+ * mean([]) // Returns 0
22
+ * ```
23
+ */
2
24
  export const mean = (nums) => (nums.length === 0 ? 0 : sum(nums) / nums.length);
@@ -1,3 +1,27 @@
1
1
  import type { Matrix } from '../types/Matrix.js';
2
+ /**
3
+ * Creates a matrix of the specified dimensions filled with null values.
4
+ *
5
+ * @param width - The number of columns in the matrix.
6
+ * @param height - The number of rows in the matrix.
7
+ * @returns A new matrix with all elements set to null.
8
+ * @example
9
+ * ```typescript
10
+ * getNullMatrix(3, 2)
11
+ * // Returns [[null, null, null], [null, null, null]]
12
+ * ```
13
+ */
2
14
  export declare const getNullMatrix: (width: number, height: number) => Matrix<null>;
15
+ /**
16
+ * Transposes a matrix, swapping rows and columns.
17
+ *
18
+ * @template T - The type of elements in the matrix.
19
+ * @param matrix - The matrix to transpose.
20
+ * @returns A new matrix with rows and columns swapped.
21
+ * @example
22
+ * ```typescript
23
+ * getTransposed([[1, 2, 3], [4, 5, 6]])
24
+ * // Returns [[1, 4], [2, 5], [3, 6]]
25
+ * ```
26
+ */
3
27
  export declare const getTransposed: <T>(matrix: Matrix<T>) => Matrix<T>;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Creates a matrix of the specified dimensions filled with null values.
3
+ *
4
+ * @param width - The number of columns in the matrix.
5
+ * @param height - The number of rows in the matrix.
6
+ * @returns A new matrix with all elements set to null.
7
+ * @example
8
+ * ```typescript
9
+ * getNullMatrix(3, 2)
10
+ * // Returns [[null, null, null], [null, null, null]]
11
+ * ```
12
+ */
1
13
  export const getNullMatrix = (width, height) => {
2
14
  const result = [];
3
15
  // Use a loop to create a new array instance per row.
@@ -6,6 +18,18 @@ export const getNullMatrix = (width, height) => {
6
18
  }
7
19
  return result;
8
20
  };
21
+ /**
22
+ * Transposes a matrix, swapping rows and columns.
23
+ *
24
+ * @template T - The type of elements in the matrix.
25
+ * @param matrix - The matrix to transpose.
26
+ * @returns A new matrix with rows and columns swapped.
27
+ * @example
28
+ * ```typescript
29
+ * getTransposed([[1, 2, 3], [4, 5, 6]])
30
+ * // Returns [[1, 4], [2, 5], [3, 6]]
31
+ * ```
32
+ */
9
33
  export const getTransposed = (matrix) => {
10
34
  const height = matrix.length;
11
35
  if (height === 0) {
@@ -1,37 +1,144 @@
1
1
  import { type Readable, type Writable } from 'svelte/store';
2
+ /** Union type representing either a Readable or Writable Svelte store. */
2
3
  export type ReadOrWritable<T> = Readable<T> | Writable<T>;
4
+ /**
5
+ * Type guard that checks if a value is a Svelte Readable store.
6
+ *
7
+ * @template T - The type of the store's value.
8
+ * @param value - The value to check.
9
+ * @returns True if the value has a subscribe method.
10
+ * @example
11
+ * ```typescript
12
+ * if (isReadable(maybeStore)) {
13
+ * maybeStore.subscribe(value => console.log(value))
14
+ * }
15
+ * ```
16
+ */
3
17
  export declare const isReadable: <T>(value: any) => value is Readable<T>;
18
+ /**
19
+ * Type guard that checks if a value is a Svelte Writable store.
20
+ *
21
+ * @template T - The type of the store's value.
22
+ * @param store - The value to check.
23
+ * @returns True if the value has both update and set methods.
24
+ * @example
25
+ * ```typescript
26
+ * if (isWritable(maybeStore)) {
27
+ * maybeStore.set(newValue)
28
+ * }
29
+ * ```
30
+ */
4
31
  export declare const isWritable: <T>(store: any) => store is Writable<T>;
32
+ /**
33
+ * Maps each key of T to a Writable store containing that key's value type.
34
+ * @template T - The object type to map.
35
+ */
5
36
  export type WritableKeys<T> = {
6
37
  [K in keyof T]: T[K] extends undefined ? Writable<T[K] | undefined> : Writable<T[K]>;
7
38
  };
39
+ /**
40
+ * Maps each key of T to a Readable store containing that key's value type.
41
+ * @template T - The object type to map.
42
+ */
8
43
  export type ReadableKeys<T> = {
9
44
  [K in keyof T]: T[K] extends undefined ? Readable<T[K] | undefined> : Readable<T[K]>;
10
45
  };
46
+ /**
47
+ * Maps each key of T to either a Readable or Writable store.
48
+ * @template T - The object type to map.
49
+ */
11
50
  export type ReadOrWritableKeys<T> = {
12
51
  [K in keyof T]: T[K] extends undefined ? ReadOrWritable<T[K] | undefined> : ReadOrWritable<T[K]>;
13
52
  };
53
+ /** A readable store that always contains undefined. */
14
54
  export declare const Undefined: Readable<undefined>;
55
+ /**
56
+ * Returns the Undefined store typed as a Readable of type T.
57
+ * Useful for providing a default store value.
58
+ *
59
+ * @template T - The type to cast the undefined store to.
60
+ * @returns A Readable store typed as Readable<T>.
61
+ */
15
62
  export declare const UndefinedAs: <T>() => Readable<T>;
63
+ /**
64
+ * Options for toggle operations in set stores.
65
+ */
16
66
  export interface ToggleOptions {
67
+ /** If true, removes all other items when toggling an item on. */
17
68
  clearOthers?: boolean;
18
69
  }
70
+ /**
71
+ * Configuration options for creating an ArraySetStore.
72
+ * @template T - The type of elements in the array.
73
+ */
19
74
  export interface ArraySetStoreOptions<T> {
20
- isEqual?: (a: T, b: T) => boolean;
75
+ /** Custom equality function for comparing items. Defaults to strict equality. */
76
+ isEqual?: (_a: T, _b: T) => boolean;
21
77
  }
78
+ /**
79
+ * A Svelte store that maintains a unique set of items as an array.
80
+ * Extends Writable with set-like operations.
81
+ *
82
+ * @template T - The type of elements in the set.
83
+ */
22
84
  export interface ArraySetStore<T> extends Writable<T[]> {
23
- toggle: (item: T, options?: ToggleOptions) => void;
24
- add: (item: T) => void;
25
- remove: (item: T) => void;
85
+ /** Toggles an item in the set (adds if absent, removes if present). */
86
+ toggle: (_item: T, _options?: ToggleOptions) => void;
87
+ /** Adds an item to the set if not already present. */
88
+ add: (_item: T) => void;
89
+ /** Removes an item from the set if present. */
90
+ remove: (_item: T) => void;
91
+ /** Removes all items from the set. */
26
92
  clear: () => void;
27
93
  }
94
+ /**
95
+ * Creates a Svelte store that maintains a unique set of items as an array.
96
+ * Supports toggle, add, remove, and clear operations.
97
+ *
98
+ * @template T - The type of elements in the set.
99
+ * @param initial - The initial array of items.
100
+ * @param options - Configuration options including custom equality function.
101
+ * @returns An ArraySetStore with set-like operations.
102
+ * @example
103
+ * ```typescript
104
+ * const selectedIds = arraySetStore<string>(['id1'])
105
+ * selectedIds.toggle('id2') // Adds 'id2'
106
+ * selectedIds.toggle('id1') // Removes 'id1'
107
+ * ```
108
+ */
28
109
  export declare const arraySetStore: <T>(initial?: T[], { isEqual }?: ArraySetStoreOptions<T>) => ArraySetStore<T>;
110
+ /**
111
+ * A Svelte store that maintains a set using a Record with boolean values.
112
+ * More efficient for string/number keys than ArraySetStore.
113
+ *
114
+ * @template T - The type of keys (must be string or number).
115
+ */
29
116
  export interface RecordSetStore<T extends string | number> extends Writable<Record<T, boolean>> {
30
- toggle: (item: T) => void;
31
- add: (item: T) => void;
32
- addAll: (items: T[]) => void;
33
- remove: (item: T) => void;
34
- removeAll: (items: T[]) => void;
117
+ /** Toggles a key in the set (adds if absent, removes if present). */
118
+ toggle: (_item: T) => void;
119
+ /** Adds a key to the set. */
120
+ add: (_item: T) => void;
121
+ /** Adds multiple keys to the set. */
122
+ addAll: (_items: T[]) => void;
123
+ /** Removes a key from the set. */
124
+ remove: (_item: T) => void;
125
+ /** Removes multiple keys from the set. */
126
+ removeAll: (_items: T[]) => void;
127
+ /** Removes all keys from the set. */
35
128
  clear: () => void;
36
129
  }
130
+ /**
131
+ * Creates a Svelte store that maintains a set using a Record with boolean values.
132
+ * False values are automatically removed to keep the record clean.
133
+ *
134
+ * @template T - The type of keys (must be string or number).
135
+ * @param initial - The initial record of key-boolean pairs.
136
+ * @returns A RecordSetStore with set-like operations.
137
+ * @example
138
+ * ```typescript
139
+ * const expandedIds = recordSetStore<string>({ row1: true })
140
+ * expandedIds.toggle('row2') // Adds 'row2'
141
+ * expandedIds.toggle('row1') // Removes 'row1'
142
+ * ```
143
+ */
37
144
  export declare const recordSetStore: <T extends string | number>(initial?: Record<T, boolean>) => RecordSetStore<T>;
@@ -1,14 +1,63 @@
1
1
  import { readable, writable } from 'svelte/store';
2
+ /**
3
+ * Type guard that checks if a value is a Svelte Readable store.
4
+ *
5
+ * @template T - The type of the store's value.
6
+ * @param value - The value to check.
7
+ * @returns True if the value has a subscribe method.
8
+ * @example
9
+ * ```typescript
10
+ * if (isReadable(maybeStore)) {
11
+ * maybeStore.subscribe(value => console.log(value))
12
+ * }
13
+ * ```
14
+ */
2
15
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
16
  export const isReadable = (value) => {
4
17
  return value?.subscribe instanceof Function;
5
18
  };
19
+ /**
20
+ * Type guard that checks if a value is a Svelte Writable store.
21
+ *
22
+ * @template T - The type of the store's value.
23
+ * @param store - The value to check.
24
+ * @returns True if the value has both update and set methods.
25
+ * @example
26
+ * ```typescript
27
+ * if (isWritable(maybeStore)) {
28
+ * maybeStore.set(newValue)
29
+ * }
30
+ * ```
31
+ */
6
32
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
33
  export const isWritable = (store) => {
8
34
  return store?.update instanceof Function && store.set instanceof Function;
9
35
  };
36
+ /** A readable store that always contains undefined. */
10
37
  export const Undefined = readable(undefined);
38
+ /**
39
+ * Returns the Undefined store typed as a Readable of type T.
40
+ * Useful for providing a default store value.
41
+ *
42
+ * @template T - The type to cast the undefined store to.
43
+ * @returns A Readable store typed as Readable<T>.
44
+ */
11
45
  export const UndefinedAs = () => Undefined;
46
+ /**
47
+ * Creates a Svelte store that maintains a unique set of items as an array.
48
+ * Supports toggle, add, remove, and clear operations.
49
+ *
50
+ * @template T - The type of elements in the set.
51
+ * @param initial - The initial array of items.
52
+ * @param options - Configuration options including custom equality function.
53
+ * @returns An ArraySetStore with set-like operations.
54
+ * @example
55
+ * ```typescript
56
+ * const selectedIds = arraySetStore<string>(['id1'])
57
+ * selectedIds.toggle('id2') // Adds 'id2'
58
+ * selectedIds.toggle('id1') // Removes 'id1'
59
+ * ```
60
+ */
12
61
  export const arraySetStore = (initial = [], { isEqual = (a, b) => a === b } = {}) => {
13
62
  const { subscribe, update, set } = writable(initial);
14
63
  const toggle = (item, { clearOthers = false } = {}) => {
@@ -57,6 +106,20 @@ export const arraySetStore = (initial = [], { isEqual = (a, b) => a === b } = {}
57
106
  clear
58
107
  };
59
108
  };
109
+ /**
110
+ * Creates a Svelte store that maintains a set using a Record with boolean values.
111
+ * False values are automatically removed to keep the record clean.
112
+ *
113
+ * @template T - The type of keys (must be string or number).
114
+ * @param initial - The initial record of key-boolean pairs.
115
+ * @returns A RecordSetStore with set-like operations.
116
+ * @example
117
+ * ```typescript
118
+ * const expandedIds = recordSetStore<string>({ row1: true })
119
+ * expandedIds.toggle('row2') // Adds 'row2'
120
+ * expandedIds.toggle('row1') // Removes 'row1'
121
+ * ```
122
+ */
60
123
  export const recordSetStore = (initial = {}) => {
61
124
  const withFalseRemoved = (record) => {
62
125
  return Object.fromEntries(Object.entries(record).filter(([, v]) => v));