@humanspeak/svelte-headless-table 6.0.2 → 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.
- package/README.md +2 -2
- package/dist/bodyCells.d.ts +116 -0
- package/dist/bodyCells.js +80 -0
- package/dist/bodyRows.d.ts +92 -0
- package/dist/bodyRows.js +55 -0
- package/dist/columns.d.ts +204 -0
- package/dist/columns.js +120 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/dist/createTable.d.ts +107 -0
- package/dist/createTable.js +92 -0
- package/dist/createViewModel.d.ts +105 -2
- package/dist/createViewModel.js +55 -1
- package/dist/headerCells.d.ts +210 -0
- package/dist/headerCells.js +151 -0
- package/dist/headerRows.d.ts +72 -0
- package/dist/headerRows.js +60 -0
- package/dist/plugins/addColumnFilters.d.ts +101 -0
- package/dist/plugins/addColumnFilters.js +55 -0
- package/dist/plugins/addColumnOrder.d.ts +30 -0
- package/dist/plugins/addColumnOrder.js +21 -0
- package/dist/plugins/addDataExport.d.ts +51 -0
- package/dist/plugins/addDataExport.js +30 -0
- package/dist/plugins/addExpandedRows.d.ts +41 -2
- package/dist/plugins/addExpandedRows.js +24 -0
- package/dist/plugins/addFlatten.d.ts +48 -3
- package/dist/plugins/addFlatten.js +28 -0
- package/dist/plugins/addGridLayout.d.ts +13 -0
- package/dist/plugins/addGridLayout.js +13 -0
- package/dist/plugins/addGroupBy.d.ts +80 -4
- package/dist/plugins/addGroupBy.js +48 -4
- package/dist/plugins/addHiddenColumns.d.ts +27 -0
- package/dist/plugins/addHiddenColumns.js +19 -0
- package/dist/plugins/addPagination.d.ts +54 -0
- package/dist/plugins/addPagination.js +29 -0
- package/dist/plugins/addResizedColumns.d.ts +58 -4
- package/dist/plugins/addResizedColumns.js +33 -0
- package/dist/plugins/addSelectedRows.d.ts +58 -2
- package/dist/plugins/addSelectedRows.js +42 -0
- package/dist/plugins/addSortBy.d.ts +83 -6
- package/dist/plugins/addSortBy.js +65 -24
- package/dist/plugins/addSubRows.d.ts +39 -1
- package/dist/plugins/addSubRows.js +25 -0
- package/dist/plugins/addTableFilter.d.ts +87 -3
- package/dist/plugins/addTableFilter.js +90 -40
- package/dist/tableComponent.d.ts +41 -0
- package/dist/tableComponent.js +37 -0
- package/dist/types/Action.d.ts +16 -2
- package/dist/types/Entries.d.ts +6 -0
- package/dist/types/KeyPath.d.ts +20 -0
- package/dist/types/Label.d.ts +26 -3
- package/dist/types/Matrix.d.ts +6 -0
- package/dist/types/TablePlugin.d.ts +140 -10
- package/dist/utils/array.d.ts +24 -0
- package/dist/utils/array.js +24 -0
- package/dist/utils/attributes.d.ts +31 -0
- package/dist/utils/attributes.js +31 -0
- package/dist/utils/clone.d.ts +19 -0
- package/dist/utils/clone.js +13 -0
- package/dist/utils/compare.d.ts +29 -0
- package/dist/utils/compare.js +29 -0
- package/dist/utils/counter.d.ts +12 -0
- package/dist/utils/counter.js +12 -0
- package/dist/utils/css.d.ts +11 -0
- package/dist/utils/css.js +11 -0
- package/dist/utils/event.d.ts +14 -0
- package/dist/utils/event.js +14 -0
- package/dist/utils/filter.d.ts +47 -0
- package/dist/utils/filter.js +47 -0
- package/dist/utils/math.d.ts +22 -0
- package/dist/utils/math.js +22 -0
- package/dist/utils/matrix.d.ts +24 -0
- package/dist/utils/matrix.js +24 -0
- package/dist/utils/store.d.ts +116 -9
- package/dist/utils/store.js +63 -0
- package/package.json +22 -22
package/dist/utils/css.d.ts
CHANGED
|
@@ -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}`)
|
package/dist/utils/event.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/event.js
CHANGED
|
@@ -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;
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/filter.js
CHANGED
|
@@ -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';
|
package/dist/utils/math.d.ts
CHANGED
|
@@ -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;
|
package/dist/utils/math.js
CHANGED
|
@@ -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);
|
package/dist/utils/matrix.d.ts
CHANGED
|
@@ -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>;
|
package/dist/utils/matrix.js
CHANGED
|
@@ -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) {
|
package/dist/utils/store.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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>;
|
package/dist/utils/store.js
CHANGED
|
@@ -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));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanspeak/svelte-headless-table",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.3",
|
|
4
4
|
"description": "A powerful, headless table library for Svelte that provides complete control over table UI while handling complex data operations like sorting, filtering, pagination, grouping, and row expansion. Build custom, accessible data tables with zero styling opinions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -58,55 +58,55 @@
|
|
|
58
58
|
"!dist/**/*.spec.*"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@humanspeak/memory-cache": "^1.0.
|
|
61
|
+
"@humanspeak/memory-cache": "^1.0.4",
|
|
62
62
|
"@humanspeak/svelte-keyed": "^5.0.1",
|
|
63
63
|
"@humanspeak/svelte-render": "^5.1.1",
|
|
64
64
|
"@humanspeak/svelte-subscribe": "^5.0.0"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@eslint/compat": "^2.0.
|
|
67
|
+
"@eslint/compat": "^2.0.2",
|
|
68
68
|
"@eslint/js": "^9.39.2",
|
|
69
|
-
"@faker-js/faker": "^10.
|
|
70
|
-
"@playwright/test": "^1.
|
|
69
|
+
"@faker-js/faker": "^10.2.0",
|
|
70
|
+
"@playwright/test": "^1.58.1",
|
|
71
71
|
"@sveltejs/adapter-auto": "^7.0.0",
|
|
72
|
-
"@sveltejs/kit": "^2.
|
|
72
|
+
"@sveltejs/kit": "^2.50.1",
|
|
73
73
|
"@sveltejs/package": "^2.5.7",
|
|
74
|
-
"@sveltejs/vite-plugin-svelte": "^6.2.
|
|
74
|
+
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
75
75
|
"@testing-library/jest-dom": "^6.9.1",
|
|
76
76
|
"@testing-library/svelte": "^5.3.1",
|
|
77
77
|
"@types/eslint": "9.6.1",
|
|
78
|
-
"@types/node": "^25.0
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
80
|
-
"@typescript-eslint/parser": "^8.
|
|
81
|
-
"@vitest/coverage-v8": "^4.0.
|
|
78
|
+
"@types/node": "^25.1.0",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
80
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
81
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
82
82
|
"concurrently": "^9.2.1",
|
|
83
83
|
"eslint": "^9.39.2",
|
|
84
84
|
"eslint-config-prettier": "10.1.8",
|
|
85
85
|
"eslint-plugin-import": "2.32.0",
|
|
86
|
-
"eslint-plugin-svelte": "3.
|
|
86
|
+
"eslint-plugin-svelte": "3.14.0",
|
|
87
87
|
"eslint-plugin-unused-imports": "4.3.0",
|
|
88
|
-
"globals": "^
|
|
88
|
+
"globals": "^17.2.0",
|
|
89
89
|
"husky": "^9.1.7",
|
|
90
|
-
"prettier": "^3.
|
|
90
|
+
"prettier": "^3.8.1",
|
|
91
91
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
92
|
-
"prettier-plugin-sort-json": "^4.
|
|
92
|
+
"prettier-plugin-sort-json": "^4.2.0",
|
|
93
93
|
"prettier-plugin-svelte": "^3.4.1",
|
|
94
94
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
95
|
-
"publint": "^0.3.
|
|
96
|
-
"svelte": "^5.
|
|
95
|
+
"publint": "^0.3.17",
|
|
96
|
+
"svelte": "^5.49.1",
|
|
97
97
|
"svelte-check": "^4.3.5",
|
|
98
98
|
"tslib": "^2.8.1",
|
|
99
|
-
"type-fest": "^5.
|
|
99
|
+
"type-fest": "^5.4.2",
|
|
100
100
|
"typescript": "^5.9.3",
|
|
101
|
-
"typescript-eslint": "^8.
|
|
102
|
-
"vite": "^7.3.
|
|
103
|
-
"vitest": "^4.0.
|
|
101
|
+
"typescript-eslint": "^8.54.0",
|
|
102
|
+
"vite": "^7.3.1",
|
|
103
|
+
"vitest": "^4.0.18"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"svelte": "^5.30.0"
|
|
107
107
|
},
|
|
108
108
|
"volta": {
|
|
109
|
-
"node": "
|
|
109
|
+
"node": "24.12.0"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
112
112
|
"build": "vite build && npm run package",
|