@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.
- 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 +43 -2
- package/dist/plugins/addExpandedRows.js +48 -2
- 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 +60 -2
- package/dist/plugins/addSelectedRows.js +67 -2
- 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/plugins/cacheConfig.d.ts +7 -0
- package/dist/plugins/cacheConfig.js +11 -0
- 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 +31 -30
package/dist/tableComponent.d.ts
CHANGED
|
@@ -2,18 +2,59 @@ import type { TableState } from './createViewModel.js';
|
|
|
2
2
|
import type { AnyPlugins, ComponentKeys, ElementHook, PluginTablePropSet } from './types/TablePlugin.js';
|
|
3
3
|
import type { Clonable } from './utils/clone.js';
|
|
4
4
|
import { type Readable } from 'svelte/store';
|
|
5
|
+
/**
|
|
6
|
+
* Initialization options for a TableComponent.
|
|
7
|
+
*/
|
|
5
8
|
export interface TableComponentInit {
|
|
9
|
+
/** Unique identifier for the component. */
|
|
6
10
|
id: string;
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Abstract base class for all table components (rows, cells, etc.).
|
|
14
|
+
* Provides common functionality for state injection, hook application, and attribute merging.
|
|
15
|
+
*
|
|
16
|
+
* @template Item - The type of data items in the table.
|
|
17
|
+
* @template Plugins - The plugins used by the table.
|
|
18
|
+
* @template Key - The component key type (e.g., 'tbody.tr', 'tbody.tr.td').
|
|
19
|
+
*/
|
|
8
20
|
export declare abstract class TableComponent<Item, Plugins extends AnyPlugins, Key extends ComponentKeys> implements Clonable<TableComponent<Item, Plugins, Key>> {
|
|
21
|
+
/** Unique identifier for the component. */
|
|
9
22
|
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new TableComponent.
|
|
25
|
+
*
|
|
26
|
+
* @param init - Initialization options.
|
|
27
|
+
*/
|
|
10
28
|
constructor({ id }: TableComponentInit);
|
|
11
29
|
private attrsForName;
|
|
30
|
+
/**
|
|
31
|
+
* Gets the merged HTML attributes from all applied plugins.
|
|
32
|
+
*
|
|
33
|
+
* @returns A readable store of merged attributes.
|
|
34
|
+
*/
|
|
12
35
|
attrs(): Readable<Record<string, unknown>>;
|
|
13
36
|
private propsForName;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the merged props from all applied plugins.
|
|
39
|
+
*
|
|
40
|
+
* @returns A readable store of plugin props keyed by plugin name.
|
|
41
|
+
*/
|
|
14
42
|
props(): Readable<PluginTablePropSet<Plugins>[Key]>;
|
|
43
|
+
/** Reference to the table state, injected after creation. */
|
|
15
44
|
state?: TableState<Item, Plugins>;
|
|
45
|
+
/**
|
|
46
|
+
* Injects the table state reference into this component.
|
|
47
|
+
*
|
|
48
|
+
* @param state - The table state to inject.
|
|
49
|
+
*/
|
|
16
50
|
injectState(state: TableState<Item, Plugins>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Applies a plugin hook to this component.
|
|
53
|
+
* Hooks can provide both props and attributes.
|
|
54
|
+
*
|
|
55
|
+
* @param pluginName - The name of the plugin.
|
|
56
|
+
* @param hook - The element hook containing props and/or attrs.
|
|
57
|
+
*/
|
|
17
58
|
applyHook(pluginName: string, hook: ElementHook<Record<string, unknown>, Record<string, unknown>>): void;
|
|
18
59
|
abstract clone(): TableComponent<Item, Plugins, Key>;
|
|
19
60
|
}
|
package/dist/tableComponent.js
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { finalizeAttributes, mergeAttributes } from './utils/attributes.js';
|
|
2
2
|
import { derivedKeys } from '@humanspeak/svelte-subscribe';
|
|
3
3
|
import { derived } from 'svelte/store';
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for all table components (rows, cells, etc.).
|
|
6
|
+
* Provides common functionality for state injection, hook application, and attribute merging.
|
|
7
|
+
*
|
|
8
|
+
* @template Item - The type of data items in the table.
|
|
9
|
+
* @template Plugins - The plugins used by the table.
|
|
10
|
+
* @template Key - The component key type (e.g., 'tbody.tr', 'tbody.tr.td').
|
|
11
|
+
*/
|
|
4
12
|
export class TableComponent {
|
|
13
|
+
/** Unique identifier for the component. */
|
|
5
14
|
id;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new TableComponent.
|
|
17
|
+
*
|
|
18
|
+
* @param init - Initialization options.
|
|
19
|
+
*/
|
|
6
20
|
constructor({ id }) {
|
|
7
21
|
this.id = id;
|
|
8
22
|
}
|
|
9
23
|
attrsForName = {};
|
|
24
|
+
/**
|
|
25
|
+
* Gets the merged HTML attributes from all applied plugins.
|
|
26
|
+
*
|
|
27
|
+
* @returns A readable store of merged attributes.
|
|
28
|
+
*/
|
|
10
29
|
attrs() {
|
|
11
30
|
return derived(Object.values(this.attrsForName), ($attrsArray) => {
|
|
12
31
|
let $mergedAttrs = {};
|
|
@@ -17,13 +36,31 @@ export class TableComponent {
|
|
|
17
36
|
});
|
|
18
37
|
}
|
|
19
38
|
propsForName = {};
|
|
39
|
+
/**
|
|
40
|
+
* Gets the merged props from all applied plugins.
|
|
41
|
+
*
|
|
42
|
+
* @returns A readable store of plugin props keyed by plugin name.
|
|
43
|
+
*/
|
|
20
44
|
props() {
|
|
21
45
|
return derivedKeys(this.propsForName);
|
|
22
46
|
}
|
|
47
|
+
/** Reference to the table state, injected after creation. */
|
|
23
48
|
state;
|
|
49
|
+
/**
|
|
50
|
+
* Injects the table state reference into this component.
|
|
51
|
+
*
|
|
52
|
+
* @param state - The table state to inject.
|
|
53
|
+
*/
|
|
24
54
|
injectState(state) {
|
|
25
55
|
this.state = state;
|
|
26
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Applies a plugin hook to this component.
|
|
59
|
+
* Hooks can provide both props and attributes.
|
|
60
|
+
*
|
|
61
|
+
* @param pluginName - The name of the plugin.
|
|
62
|
+
* @param hook - The element hook containing props and/or attrs.
|
|
63
|
+
*/
|
|
27
64
|
applyHook(pluginName, hook) {
|
|
28
65
|
if (hook.props !== undefined) {
|
|
29
66
|
this.propsForName[pluginName] = hook.props;
|
package/dist/types/Action.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return type for Svelte actions.
|
|
3
|
+
* Contains optional lifecycle methods for updating and destroying the action.
|
|
4
|
+
*
|
|
5
|
+
* @template Props - The type of props passed to the action.
|
|
6
|
+
*/
|
|
1
7
|
export type ActionReturnType<Props = any> = {
|
|
2
|
-
|
|
8
|
+
/** Called when props change. */
|
|
9
|
+
update?: (_newProps: Props) => void;
|
|
10
|
+
/** Called when the element is removed from the DOM. */
|
|
3
11
|
destroy?: () => void;
|
|
4
12
|
};
|
|
5
|
-
|
|
13
|
+
/**
|
|
14
|
+
* A Svelte action function that can be applied to DOM elements.
|
|
15
|
+
* Actions receive an element and optional props, returning lifecycle methods.
|
|
16
|
+
*
|
|
17
|
+
* @template Props - The type of props passed to the action.
|
|
18
|
+
*/
|
|
19
|
+
export type Action<Props> = (_node: Element, _props?: Props) => ActionReturnType<Props> | void;
|
package/dist/types/Entries.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an object type to its entries type (array of [key, value] tuples).
|
|
3
|
+
* Similar to the return type of Object.entries() but with stronger typing.
|
|
4
|
+
*
|
|
5
|
+
* @template Obj - The object type to convert.
|
|
6
|
+
*/
|
|
1
7
|
export type Entries<Obj> = NonNullable<{
|
|
2
8
|
[K in keyof Obj]: [K, NonNullable<Obj[K]>];
|
|
3
9
|
}[keyof Obj]>[];
|
package/dist/types/KeyPath.d.ts
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a union of all valid dot-notation key paths for an object type.
|
|
3
|
+
* Useful for type-safe property access with nested objects.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The object type to extract paths from.
|
|
6
|
+
* @template D - Maximum depth to traverse (default 3 to avoid infinite recursion).
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* type Person = { name: string; address: { city: string } }
|
|
10
|
+
* type Paths = KeyPath<Person> // 'name' | 'address' | 'address.city'
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
1
13
|
export type KeyPath<T, D extends number = 3> = KeyPath_<T, D, []>;
|
|
14
|
+
/**
|
|
15
|
+
* Internal recursive helper for KeyPath.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
2
18
|
type KeyPath_<T, D extends number, S extends unknown[]> = D extends S['length'] ? never : T extends object ? {
|
|
3
19
|
[K in keyof T]-?: K extends string ? `${K}` | Join<K, KeyPath_<T[K], D, [never, ...S]>> : K extends number ? `[${K}]` | Join<`[${K}]`, KeyPath_<T[K], D, [never, ...S]>> : never;
|
|
4
20
|
}[keyof T] : '';
|
|
21
|
+
/**
|
|
22
|
+
* Internal helper for joining path segments with dots.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
5
25
|
type Join<K, P> = K extends string | number ? P extends string | number ? P extends `[${string}` ? `${K}${P}` : `${K}${'' extends P ? '' : '.'}${P}` : never : never;
|
|
6
26
|
export {};
|
package/dist/types/Label.d.ts
CHANGED
|
@@ -3,6 +3,29 @@ import type { DataBodyCell, DisplayBodyCell } from '../bodyCells.js';
|
|
|
3
3
|
import type { TableState } from '../createViewModel.js';
|
|
4
4
|
import type { HeaderCell } from '../headerCells.js';
|
|
5
5
|
import type { AnyPlugins } from './TablePlugin.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/**
|
|
7
|
+
* A render function for data body cells.
|
|
8
|
+
* Receives the cell and table state, returns content to render.
|
|
9
|
+
*
|
|
10
|
+
* @template Item - The type of data items in the table.
|
|
11
|
+
* @template Plugins - The plugins used by the table.
|
|
12
|
+
* @template Value - The type of the cell value.
|
|
13
|
+
*/
|
|
14
|
+
export type DataLabel<Item, Plugins extends AnyPlugins = AnyPlugins, Value = any> = (_cell: DataBodyCell<Item, AnyPlugins, Value>, _state: TableState<Item, Plugins>) => RenderConfig;
|
|
15
|
+
/**
|
|
16
|
+
* A render function for display body cells.
|
|
17
|
+
* Receives the cell and table state, returns content to render.
|
|
18
|
+
*
|
|
19
|
+
* @template Item - The type of data items in the table.
|
|
20
|
+
* @template Plugins - The plugins used by the table.
|
|
21
|
+
*/
|
|
22
|
+
export type DisplayLabel<Item, Plugins extends AnyPlugins = AnyPlugins> = (_cell: DisplayBodyCell<Item>, _state: TableState<Item, Plugins>) => RenderConfig;
|
|
23
|
+
/**
|
|
24
|
+
* A label for header cells. Can be static content or a render function.
|
|
25
|
+
* If the function type is removed from the union, generics will not be
|
|
26
|
+
* inferred for subtypes.
|
|
27
|
+
*
|
|
28
|
+
* @template Item - The type of data items in the table.
|
|
29
|
+
* @template Plugins - The plugins used by the table.
|
|
30
|
+
*/
|
|
31
|
+
export type HeaderLabel<Item, Plugins extends AnyPlugins = AnyPlugins> = RenderConfig | ((_cell: HeaderCell<Item, Plugins>, _state: TableState<Item, Plugins>) => RenderConfig);
|
package/dist/types/Matrix.d.ts
CHANGED
|
@@ -5,12 +5,41 @@ import type { DataColumn, FlatColumn } from '../columns.js';
|
|
|
5
5
|
import type { PluginInitTableState, TableAttributes, TableBodyAttributes, TableHeadAttributes } from '../createViewModel.js';
|
|
6
6
|
import type { HeaderCell, HeaderCellAttributes } from '../headerCells.js';
|
|
7
7
|
import type { HeaderRow, HeaderRowAttributes } from '../headerRows.js';
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A table plugin factory function.
|
|
10
|
+
* Receives initialization options and returns a plugin instance.
|
|
11
|
+
*
|
|
12
|
+
* @template Item - The type of data items in the table.
|
|
13
|
+
* @template PluginState - The state exposed by the plugin.
|
|
14
|
+
* @template ColumnOptions - Per-column configuration options.
|
|
15
|
+
* @template TablePropSet - Props added to table components.
|
|
16
|
+
* @template TableAttributeSet - Attributes added to table components.
|
|
17
|
+
*/
|
|
18
|
+
export type TablePlugin<Item, PluginState, ColumnOptions, TablePropSet extends AnyTablePropSet = AnyTablePropSet, TableAttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = (_init: TablePluginInit<Item, ColumnOptions>) => TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet, TableAttributeSet>;
|
|
19
|
+
/**
|
|
20
|
+
* Initialization options passed to a table plugin.
|
|
21
|
+
*
|
|
22
|
+
* @template Item - The type of data items in the table.
|
|
23
|
+
* @template ColumnOptions - Per-column configuration options.
|
|
24
|
+
*/
|
|
9
25
|
export type TablePluginInit<Item, ColumnOptions> = {
|
|
26
|
+
/** The name/key of this plugin in the plugins object. */
|
|
10
27
|
pluginName: string;
|
|
28
|
+
/** The table state during plugin initialization. */
|
|
11
29
|
tableState: PluginInitTableState<Item>;
|
|
30
|
+
/** Column options keyed by column ID. */
|
|
12
31
|
columnOptions: Record<string, ColumnOptions>;
|
|
13
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* A plugin instance returned by a TablePlugin factory.
|
|
35
|
+
* Contains state, transformation functions, and component hooks.
|
|
36
|
+
*
|
|
37
|
+
* @template Item - The type of data items in the table.
|
|
38
|
+
* @template PluginState - The state exposed by the plugin.
|
|
39
|
+
* @template ColumnOptions - Per-column configuration options.
|
|
40
|
+
* @template TablePropSet - Props added to table components.
|
|
41
|
+
* @template TableAttributeSet - Attributes added to table components.
|
|
42
|
+
*/
|
|
14
43
|
export type TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet extends AnyTablePropSet = AnyTablePropSet, TableAttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = {
|
|
15
44
|
pluginState: PluginState;
|
|
16
45
|
transformFlatColumnsFn?: Readable<TransformFlatColumnsFn<Item>>;
|
|
@@ -23,65 +52,166 @@ export type TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet e
|
|
|
23
52
|
columnOptions?: ColumnOptions;
|
|
24
53
|
hooks?: TableHooks<Item, TablePropSet, TableAttributeSet>;
|
|
25
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* A record of table plugins, keyed by plugin name.
|
|
57
|
+
* Used as a type constraint for the plugins parameter.
|
|
58
|
+
*/
|
|
26
59
|
export type AnyPlugins = Record<any, TablePlugin<any, any, any, any, any>>;
|
|
60
|
+
/**
|
|
61
|
+
* A record of plugin instances, keyed by plugin name.
|
|
62
|
+
* Used internally after plugins are initialized.
|
|
63
|
+
*/
|
|
27
64
|
export type AnyPluginInstances = Record<any, TablePluginInstance<any, any, any, any, any>>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
65
|
+
/**
|
|
66
|
+
* A synchronous function that transforms flat columns.
|
|
67
|
+
*
|
|
68
|
+
* @template Item - The type of data items in the table.
|
|
69
|
+
*/
|
|
70
|
+
export type TransformFlatColumnsFn<Item> = (_flatColumns: DataColumn<Item>[]) => DataColumn<Item>[];
|
|
71
|
+
/**
|
|
72
|
+
* A reactive function that derives flat columns from a store.
|
|
73
|
+
*
|
|
74
|
+
* @template Item - The type of data items in the table.
|
|
75
|
+
*/
|
|
76
|
+
export type DeriveFlatColumnsFn<Item> = <Col extends FlatColumn<Item>>(_flatColumns: Readable<Col[]>) => Readable<Col[]>;
|
|
77
|
+
/**
|
|
78
|
+
* A reactive function that derives rows from a store.
|
|
79
|
+
*
|
|
80
|
+
* @template Item - The type of data items in the table.
|
|
81
|
+
*/
|
|
82
|
+
export type DeriveRowsFn<Item> = <Row extends BodyRow<Item>>(_rows: Readable<Row[]>) => Readable<Row[]>;
|
|
83
|
+
/**
|
|
84
|
+
* A generic reactive derivation function.
|
|
85
|
+
*
|
|
86
|
+
* @template T - The type being derived.
|
|
87
|
+
*/
|
|
88
|
+
export type DeriveFn<T> = (_obj: Readable<T>) => Readable<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Maps component keys to their corresponding component types.
|
|
91
|
+
*
|
|
92
|
+
* @template Item - The type of data items in the table.
|
|
93
|
+
* @template Plugins - The plugins used by the table.
|
|
94
|
+
*/
|
|
32
95
|
export type Components<Item, Plugins extends AnyPlugins = AnyPlugins> = {
|
|
33
96
|
'thead.tr': HeaderRow<Item, Plugins>;
|
|
34
97
|
'thead.tr.th': HeaderCell<Item, Plugins>;
|
|
35
98
|
'tbody.tr': BodyRow<Item, Plugins>;
|
|
36
99
|
'tbody.tr.td': BodyCell<Item, Plugins>;
|
|
37
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Maps component keys to their corresponding attribute types.
|
|
103
|
+
*
|
|
104
|
+
* @template Item - The type of data items in the table.
|
|
105
|
+
* @template Plugins - The plugins used by the table.
|
|
106
|
+
*/
|
|
38
107
|
export type AttributesForKey<Item, Plugins extends AnyPlugins = AnyPlugins> = {
|
|
39
108
|
'thead.tr': HeaderRowAttributes<Item, Plugins>;
|
|
40
109
|
'thead.tr.th': HeaderCellAttributes<Item, Plugins>;
|
|
41
110
|
'tbody.tr': BodyRowAttributes<Item, Plugins>;
|
|
42
111
|
'tbody.tr.td': BodyCellAttributes<Item, Plugins>;
|
|
43
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Valid keys for table components: header rows, header cells, body rows, body cells.
|
|
115
|
+
*/
|
|
44
116
|
export type ComponentKeys = keyof Components<unknown>;
|
|
45
117
|
type TablePropSet<PropSet extends {
|
|
46
|
-
[
|
|
118
|
+
[_K in ComponentKeys]?: unknown;
|
|
47
119
|
}> = {
|
|
48
120
|
[K in ComponentKeys]: PropSet[K];
|
|
49
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* Creates a new table prop set type, filtering out undefined component props.
|
|
124
|
+
*
|
|
125
|
+
* @template PropSet - The prop set definition.
|
|
126
|
+
*/
|
|
50
127
|
export type NewTablePropSet<PropSet extends {
|
|
51
|
-
[
|
|
128
|
+
[_K in ComponentKeys]?: unknown;
|
|
52
129
|
}> = {
|
|
53
130
|
[K in ComponentKeys]: unknown extends PropSet[K] ? never : PropSet[K];
|
|
54
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* A table prop set with any types. Used as a type constraint.
|
|
134
|
+
*/
|
|
55
135
|
export type AnyTablePropSet = TablePropSet<any>;
|
|
136
|
+
/**
|
|
137
|
+
* Internal type for mapping component keys to attribute sets.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
56
140
|
type TableAttributeSet<AttributeSet extends {
|
|
57
|
-
[
|
|
141
|
+
[_K in ComponentKeys]?: unknown;
|
|
58
142
|
}> = {
|
|
59
143
|
[K in ComponentKeys]: AttributeSet[K];
|
|
60
144
|
};
|
|
145
|
+
/**
|
|
146
|
+
* Creates a new table attribute set type, filtering out undefined component attributes.
|
|
147
|
+
*
|
|
148
|
+
* @template AttributeSet - The attribute set definition.
|
|
149
|
+
*/
|
|
61
150
|
export type NewTableAttributeSet<AttributeSet extends {
|
|
62
|
-
[
|
|
151
|
+
[_K in ComponentKeys]?: unknown;
|
|
63
152
|
}> = {
|
|
64
153
|
[K in ComponentKeys]: unknown extends AttributeSet[K] ? never : AttributeSet[K];
|
|
65
154
|
};
|
|
155
|
+
/**
|
|
156
|
+
* A table attribute set with any types. Used as a type constraint.
|
|
157
|
+
*/
|
|
66
158
|
export type AnyTableAttributeSet = TableAttributeSet<any>;
|
|
159
|
+
/**
|
|
160
|
+
* Hooks for attaching props and attributes to table components.
|
|
161
|
+
* Each hook receives a component and returns props/attrs stores.
|
|
162
|
+
*
|
|
163
|
+
* @template Item - The type of data items in the table.
|
|
164
|
+
* @template PropSet - The prop set type.
|
|
165
|
+
* @template AttributeSet - The attribute set type.
|
|
166
|
+
*/
|
|
67
167
|
export type TableHooks<Item, PropSet extends AnyTablePropSet = AnyTablePropSet, AttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = {
|
|
68
|
-
[ComponentKey in keyof Components<Item>]?: (
|
|
168
|
+
[ComponentKey in keyof Components<Item>]?: (_component: Components<Item>[ComponentKey]) => ElementHook<PropSet[ComponentKey], AttributeSet[ComponentKey]>;
|
|
69
169
|
};
|
|
170
|
+
/**
|
|
171
|
+
* Return type for component hooks.
|
|
172
|
+
* Contains optional readable stores for props and attributes.
|
|
173
|
+
*
|
|
174
|
+
* @template Props - The props type.
|
|
175
|
+
* @template Attributes - The attributes type.
|
|
176
|
+
*/
|
|
70
177
|
export type ElementHook<Props, Attributes> = {
|
|
178
|
+
/** Reactive props store. */
|
|
71
179
|
props?: Readable<Props>;
|
|
180
|
+
/** Reactive attributes store. */
|
|
72
181
|
attrs?: Readable<Attributes>;
|
|
73
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* Extracts the plugin state types from a plugins record.
|
|
185
|
+
*
|
|
186
|
+
* @template Plugins - The plugins record type.
|
|
187
|
+
*/
|
|
74
188
|
export type PluginStates<Plugins extends AnyPlugins> = {
|
|
75
189
|
[K in keyof Plugins]: ReturnType<Plugins[K]>['pluginState'];
|
|
76
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* Internal type for extracting prop sets from plugins.
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
77
195
|
type TablePropSetForPluginKey<Plugins extends AnyPlugins> = {
|
|
78
196
|
[K in keyof Plugins]: Plugins[K] extends TablePlugin<any, any, any, infer TablePropSet> ? TablePropSet : never;
|
|
79
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Combines prop sets from all plugins into a single type.
|
|
200
|
+
* Props are grouped by component key, then by plugin key.
|
|
201
|
+
*
|
|
202
|
+
* @template Plugins - The plugins record type.
|
|
203
|
+
*/
|
|
80
204
|
export type PluginTablePropSet<Plugins extends AnyPlugins> = {
|
|
81
205
|
[ComponentKey in ComponentKeys]: {
|
|
82
206
|
[PluginKey in keyof Plugins]: TablePropSetForPluginKey<Plugins>[PluginKey][ComponentKey];
|
|
83
207
|
};
|
|
84
208
|
};
|
|
209
|
+
/**
|
|
210
|
+
* Extracts column configuration types from all plugins.
|
|
211
|
+
* Used to type the `plugins` option in column definitions.
|
|
212
|
+
*
|
|
213
|
+
* @template Plugins - The plugins record type.
|
|
214
|
+
*/
|
|
85
215
|
export type PluginColumnConfigs<Plugins extends AnyPlugins> = Partial<{
|
|
86
216
|
[K in keyof Plugins]: ReturnType<Plugins[K]>['columnOptions'];
|
|
87
217
|
}>;
|
package/dist/utils/array.d.ts
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an array containing only the distinct elements from the input array.
|
|
3
|
+
* Preserves the order of first occurrence.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @param items - The input array potentially containing duplicates.
|
|
7
|
+
* @returns A new array with duplicate elements removed.
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* getDistinct([1, 2, 2, 3, 1]) // Returns [1, 2, 3]
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
1
13
|
export declare const getDistinct: <T>(items: T[]) => T[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns an array containing only the elements that appear more than once
|
|
16
|
+
* in the input array.
|
|
17
|
+
*
|
|
18
|
+
* @template T - The type of elements in the array.
|
|
19
|
+
* @param items - The input array to check for duplicates.
|
|
20
|
+
* @returns A new array containing only duplicate elements.
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* getDuplicates([1, 2, 2, 3, 1]) // Returns [1, 2]
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
2
26
|
export declare const getDuplicates: <T>(items: T[]) => T[];
|
package/dist/utils/array.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
import { getCounter } from './counter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array containing only the distinct elements from the input array.
|
|
4
|
+
* Preserves the order of first occurrence.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of elements in the array.
|
|
7
|
+
* @param items - The input array potentially containing duplicates.
|
|
8
|
+
* @returns A new array with duplicate elements removed.
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* getDistinct([1, 2, 2, 3, 1]) // Returns [1, 2, 3]
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
2
14
|
export const getDistinct = (items) => {
|
|
3
15
|
return Array.from(getCounter(items).keys());
|
|
4
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns an array containing only the elements that appear more than once
|
|
19
|
+
* in the input array.
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of elements in the array.
|
|
22
|
+
* @param items - The input array to check for duplicates.
|
|
23
|
+
* @returns A new array containing only duplicate elements.
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* getDuplicates([1, 2, 2, 3, 1]) // Returns [1, 2]
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
5
29
|
export const getDuplicates = (items) => {
|
|
6
30
|
return Array.from(getCounter(items).entries())
|
|
7
31
|
.filter(([, count]) => count !== 1)
|
|
@@ -1,2 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges two attribute objects, with special handling for style properties.
|
|
3
|
+
* Style objects are deeply merged rather than overwritten.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the first attributes object.
|
|
6
|
+
* @template U - The type of the second attributes object.
|
|
7
|
+
* @param a - The first attributes object.
|
|
8
|
+
* @param b - The second attributes object (takes precedence for non-style properties).
|
|
9
|
+
* @returns A merged attributes object with combined styles.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* mergeAttributes(
|
|
13
|
+
* { class: 'foo', style: { color: 'red' } },
|
|
14
|
+
* { class: 'bar', style: { fontSize: '14px' } }
|
|
15
|
+
* )
|
|
16
|
+
* // Returns { class: 'bar', style: { color: 'red', fontSize: '14px' } }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
1
19
|
export declare const mergeAttributes: <T extends Record<string, unknown>, U extends Record<string, unknown>>(a: T, b: U) => T & U;
|
|
20
|
+
/**
|
|
21
|
+
* Converts an attributes object's style property from an object to a CSS string.
|
|
22
|
+
* This prepares attributes for use in DOM elements.
|
|
23
|
+
*
|
|
24
|
+
* @template T - The type of the attributes object.
|
|
25
|
+
* @param attrs - The attributes object with a potential style object.
|
|
26
|
+
* @returns A new attributes object with the style converted to a string.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* finalizeAttributes({ class: 'foo', style: { color: 'red' } })
|
|
30
|
+
* // Returns { class: 'foo', style: 'color:red' }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
2
33
|
export declare const finalizeAttributes: <T extends Record<string, unknown>>(attrs: T) => Record<string, unknown>;
|
package/dist/utils/attributes.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
import { stringifyCss } from './css.js';
|
|
2
|
+
/**
|
|
3
|
+
* Merges two attribute objects, with special handling for style properties.
|
|
4
|
+
* Style objects are deeply merged rather than overwritten.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the first attributes object.
|
|
7
|
+
* @template U - The type of the second attributes object.
|
|
8
|
+
* @param a - The first attributes object.
|
|
9
|
+
* @param b - The second attributes object (takes precedence for non-style properties).
|
|
10
|
+
* @returns A merged attributes object with combined styles.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* mergeAttributes(
|
|
14
|
+
* { class: 'foo', style: { color: 'red' } },
|
|
15
|
+
* { class: 'bar', style: { fontSize: '14px' } }
|
|
16
|
+
* )
|
|
17
|
+
* // Returns { class: 'bar', style: { color: 'red', fontSize: '14px' } }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
2
20
|
export const mergeAttributes = (a, b) => {
|
|
3
21
|
if (a.style === undefined && b.style === undefined) {
|
|
4
22
|
return { ...a, ...b };
|
|
@@ -12,6 +30,19 @@ export const mergeAttributes = (a, b) => {
|
|
|
12
30
|
}
|
|
13
31
|
};
|
|
14
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Converts an attributes object's style property from an object to a CSS string.
|
|
35
|
+
* This prepares attributes for use in DOM elements.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The type of the attributes object.
|
|
38
|
+
* @param attrs - The attributes object with a potential style object.
|
|
39
|
+
* @returns A new attributes object with the style converted to a string.
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* finalizeAttributes({ class: 'foo', style: { color: 'red' } })
|
|
43
|
+
* // Returns { class: 'foo', style: 'color:red' }
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
15
46
|
export const finalizeAttributes = (attrs) => {
|
|
16
47
|
if (attrs.style === undefined || typeof attrs.style !== 'object') {
|
|
17
48
|
return attrs;
|
package/dist/utils/clone.d.ts
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for objects that can create a copy of themselves.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the cloned object.
|
|
5
|
+
*/
|
|
1
6
|
export interface Clonable<T> {
|
|
7
|
+
/** Creates and returns a copy of the object. */
|
|
2
8
|
clone(): T;
|
|
3
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Type guard that checks if an object implements the Clonable interface.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The expected type of the cloned object.
|
|
14
|
+
* @param obj - The object to check.
|
|
15
|
+
* @returns True if the object has a clone method.
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* if (isClonable(obj)) {
|
|
19
|
+
* const copy = obj.clone()
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
4
23
|
export declare const isClonable: <T>(obj: unknown) => obj is Clonable<T>;
|
|
5
24
|
/**
|
|
6
25
|
* Create a new instance of a class instance with all properties shallow
|
package/dist/utils/clone.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard that checks if an object implements the Clonable interface.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The expected type of the cloned object.
|
|
5
|
+
* @param obj - The object to check.
|
|
6
|
+
* @returns True if the object has a clone method.
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* if (isClonable(obj)) {
|
|
10
|
+
* const copy = obj.clone()
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
1
14
|
export const isClonable = (obj) => {
|
|
2
15
|
return typeof obj.clone === 'function';
|
|
3
16
|
};
|
package/dist/utils/compare.d.ts
CHANGED
|
@@ -1,2 +1,31 @@
|
|
|
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 declare const compare: <T extends string | number>(a: T | T[], b: T | T[]) => number;
|
|
17
|
+
/**
|
|
18
|
+
* Compares two arrays element by element for sorting purposes.
|
|
19
|
+
* Comparison stops at the first non-equal element.
|
|
20
|
+
*
|
|
21
|
+
* @template T - The type of elements in the arrays (string or number).
|
|
22
|
+
* @param a - The first array to compare.
|
|
23
|
+
* @param b - The second array to compare.
|
|
24
|
+
* @returns A number indicating the sort order based on the first differing element.
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* compareArray([1, 2, 3], [1, 2, 4]) // Returns -1
|
|
28
|
+
* compareArray(['a', 'b'], ['a', 'a']) // Returns 1
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
2
31
|
export declare const compareArray: <T extends string | number>(a: T[], b: T[]) => number;
|