@tanstack/preact-table 9.0.0-alpha.43 → 9.0.0-alpha.45

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.
@@ -2,7 +2,7 @@ let _tanstack_preact_store = require("@tanstack/preact-store");
2
2
 
3
3
  //#region src/Subscribe.ts
4
4
  function Subscribe(props) {
5
- const selected = (0, _tanstack_preact_store.useSelector)("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: _tanstack_preact_store.shallow });
5
+ const selected = (0, _tanstack_preact_store.useSelector)(props.source, props.selector, { compare: _tanstack_preact_store.shallow });
6
6
  return typeof props.children === "function" ? props.children(selected) : props.children;
7
7
  }
8
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"Subscribe.cjs","names":["shallow"],"sources":["../src/Subscribe.ts"],"sourcesContent":["import { shallow, useSelector } from '@tanstack/preact-store'\nimport type { Atom, ReadonlyAtom } from '@tanstack/preact-store'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren } from 'preact'\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store).\n */\nexport type SubscribePropsWithSourceWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected).\n */\nexport type SubscribePropsWithSource<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected = TSourceValue,\n> =\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\n/**\n * A Preact component that allows you to subscribe to the table state.\n *\n * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so\n * JSX contextual typing works. This standalone component uses a union `props` type.\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n>(\n props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n>(\n props: SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n>(\n props: SubscribePropsWithStore<TFeatures, TData, TSelected>,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,\n): ComponentChildren {\n const source = 'source' in props ? props.source : props.table.store\n const selectFn =\n 'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector\n\n const selected = useSelector(\n source as never,\n selectFn as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ComponentChildren)(selected)\n : props.children\n}\n"],"mappings":";;;AA+HA,SAAgB,UAMd,OACmB;CAKnB,MAAM,mDAJS,YAAY,QAAQ,MAAM,SAAS,MAAM,MAAM,OAE5D,YAAY,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAKpE,EACE,SAASA,gCACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAAqD,SAAS,GACrE,MAAM"}
1
+ {"version":3,"file":"Subscribe.cjs","names":["shallow"],"sources":["../src/Subscribe.ts"],"sourcesContent":["import { shallow, useSelector } from '@tanstack/preact-store'\nimport type {\n Atom,\n ReadonlyAtom,\n ReadonlyStore,\n Store,\n} from '@tanstack/preact-store'\nimport type { TableFeatures, TableState } from '@tanstack/table-core'\nimport type { ComponentChildren } from 'preact'\n\nexport type SubscribeSource<TValue> =\n | Atom<TValue>\n | ReadonlyAtom<TValue>\n | Store<TValue>\n | ReadonlyStore<TValue>\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TSelected,\n> = {\n source: SubscribeSource<TableState<TFeatures>>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<TSourceValue> = {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store).\n */\nexport type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected).\n */\nexport type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> =\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TSelected>\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>\n\n/**\n * A Preact component that allows you to subscribe to the table state.\n *\n * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so\n * JSX contextual typing works. This standalone component uses a union `props` type.\n */\nexport function Subscribe<TSourceValue>(\n props: SubscribePropsWithSourceIdentity<TSourceValue>,\n): ComponentChildren\nexport function Subscribe<TSourceValue, TSelected>(\n props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,\n): ComponentChildren\nexport function Subscribe<TFeatures extends TableFeatures, TSelected>(\n props: SubscribePropsWithStore<TFeatures, TSelected>,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TSelected, TSourceValue>,\n): ComponentChildren {\n const selected = useSelector(\n props.source as never,\n props.selector as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ComponentChildren)(selected)\n : props.children\n}\n"],"mappings":";;;AAuFA,SAAgB,UAKd,OACmB;CACnB,MAAM,mDACJ,MAAM,QACN,MAAM,UACN,EACE,SAASA,gCACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAAqD,SAAS,GACrE,MAAM"}
@@ -1,14 +1,15 @@
1
- import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
1
+ import { TableFeatures, TableState } from "@tanstack/table-core";
2
2
  import { ComponentChildren } from "preact";
3
- import { Atom, ReadonlyAtom } from "@tanstack/preact-store";
3
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/preact-store";
4
4
 
5
5
  //#region src/Subscribe.d.ts
6
+ type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
6
7
  /**
7
8
  * Subscribe to `table.store` (full table state). The selector receives the full
8
9
  * {@link TableState}.
9
10
  */
10
- type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
11
- table: Table<TFeatures, TData>;
11
+ type SubscribePropsWithStore<TFeatures extends TableFeatures, TSelected> = {
12
+ source: SubscribeSource<TableState<TFeatures>>;
12
13
  /**
13
14
  * Select from full table state. Re-renders when the selected value changes
14
15
  * (shallow compare).
@@ -24,35 +25,33 @@ type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowD
24
25
  * `table.optionsStore`). Omitting `selector` is equivalent to the identity
25
26
  * selector — children receive `TSourceValue`.
26
27
  */
27
- type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
28
- table: Table<TFeatures, TData>;
29
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
28
+ type SubscribePropsWithSourceIdentity<TSourceValue> = {
29
+ source: SubscribeSource<TSourceValue>;
30
30
  selector?: undefined;
31
31
  children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren;
32
32
  };
33
33
  /**
34
34
  * Subscribe to a projected value from a source (atom or store).
35
35
  */
36
- type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
37
- table: Table<TFeatures, TData>;
38
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
36
+ type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
37
+ source: SubscribeSource<TSourceValue>;
39
38
  selector: (state: TSourceValue) => TSelected;
40
39
  children: ((state: TSelected) => ComponentChildren) | ComponentChildren;
41
40
  };
42
41
  /**
43
42
  * Subscribe to a single source — atom or store (identity or projected).
44
43
  */
45
- type SubscribePropsWithSource<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
46
- type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
44
+ type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
45
+ type SubscribeProps<TFeatures extends TableFeatures, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TSelected> | SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
47
46
  /**
48
47
  * A Preact component that allows you to subscribe to the table state.
49
48
  *
50
49
  * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so
51
50
  * JSX contextual typing works. This standalone component uses a union `props` type.
52
51
  */
53
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue>(props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>): ComponentChildren;
54
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>): ComponentChildren;
55
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ComponentChildren;
52
+ declare function Subscribe<TSourceValue>(props: SubscribePropsWithSourceIdentity<TSourceValue>): ComponentChildren;
53
+ declare function Subscribe<TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>): ComponentChildren;
54
+ declare function Subscribe<TFeatures extends TableFeatures, TSelected>(props: SubscribePropsWithStore<TFeatures, TSelected>): ComponentChildren;
56
55
  //#endregion
57
- export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
56
+ export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource };
58
57
  //# sourceMappingURL=Subscribe.d.cts.map
@@ -1,14 +1,15 @@
1
- import { RowData, Table, TableFeatures, TableState } from "@tanstack/table-core";
2
- import { Atom, ReadonlyAtom } from "@tanstack/preact-store";
1
+ import { TableFeatures, TableState } from "@tanstack/table-core";
2
+ import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/preact-store";
3
3
  import { ComponentChildren } from "preact";
4
4
 
5
5
  //#region src/Subscribe.d.ts
6
+ type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
6
7
  /**
7
8
  * Subscribe to `table.store` (full table state). The selector receives the full
8
9
  * {@link TableState}.
9
10
  */
10
- type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
11
- table: Table<TFeatures, TData>;
11
+ type SubscribePropsWithStore<TFeatures extends TableFeatures, TSelected> = {
12
+ source: SubscribeSource<TableState<TFeatures>>;
12
13
  /**
13
14
  * Select from full table state. Re-renders when the selected value changes
14
15
  * (shallow compare).
@@ -24,35 +25,33 @@ type SubscribePropsWithStore<TFeatures extends TableFeatures, TData extends RowD
24
25
  * `table.optionsStore`). Omitting `selector` is equivalent to the identity
25
26
  * selector — children receive `TSourceValue`.
26
27
  */
27
- type SubscribePropsWithSourceIdentity<TFeatures extends TableFeatures, TData extends RowData, TSourceValue> = {
28
- table: Table<TFeatures, TData>;
29
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
28
+ type SubscribePropsWithSourceIdentity<TSourceValue> = {
29
+ source: SubscribeSource<TSourceValue>;
30
30
  selector?: undefined;
31
31
  children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren;
32
32
  };
33
33
  /**
34
34
  * Subscribe to a projected value from a source (atom or store).
35
35
  */
36
- type SubscribePropsWithSourceWithSelector<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected> = {
37
- table: Table<TFeatures, TData>;
38
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
36
+ type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
37
+ source: SubscribeSource<TSourceValue>;
39
38
  selector: (state: TSourceValue) => TSelected;
40
39
  children: ((state: TSelected) => ComponentChildren) | ComponentChildren;
41
40
  };
42
41
  /**
43
42
  * Subscribe to a single source — atom or store (identity or projected).
44
43
  */
45
- type SubscribePropsWithSource<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
46
- type SubscribeProps<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TData, TSelected> | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue> | SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>;
44
+ type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> = SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
45
+ type SubscribeProps<TFeatures extends TableFeatures, TSelected = unknown, TSourceValue = unknown> = SubscribePropsWithStore<TFeatures, TSelected> | SubscribePropsWithSourceIdentity<TSourceValue> | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>;
47
46
  /**
48
47
  * A Preact component that allows you to subscribe to the table state.
49
48
  *
50
49
  * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so
51
50
  * JSX contextual typing works. This standalone component uses a union `props` type.
52
51
  */
53
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue>(props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>): ComponentChildren;
54
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TFeatures, TData, TSourceValue, TSelected>): ComponentChildren;
55
- declare function Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected>(props: SubscribePropsWithStore<TFeatures, TData, TSelected>): ComponentChildren;
52
+ declare function Subscribe<TSourceValue>(props: SubscribePropsWithSourceIdentity<TSourceValue>): ComponentChildren;
53
+ declare function Subscribe<TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>): ComponentChildren;
54
+ declare function Subscribe<TFeatures extends TableFeatures, TSelected>(props: SubscribePropsWithStore<TFeatures, TSelected>): ComponentChildren;
56
55
  //#endregion
57
- export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore };
56
+ export { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource };
58
57
  //# sourceMappingURL=Subscribe.d.ts.map
package/dist/Subscribe.js CHANGED
@@ -2,7 +2,7 @@ import { shallow, useSelector } from "@tanstack/preact-store";
2
2
 
3
3
  //#region src/Subscribe.ts
4
4
  function Subscribe(props) {
5
- const selected = useSelector("source" in props ? props.source : props.table.store, "source" in props ? props.selector ?? ((x) => x) : props.selector, { compare: shallow });
5
+ const selected = useSelector(props.source, props.selector, { compare: shallow });
6
6
  return typeof props.children === "function" ? props.children(selected) : props.children;
7
7
  }
8
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"Subscribe.js","names":[],"sources":["../src/Subscribe.ts"],"sourcesContent":["import { shallow, useSelector } from '@tanstack/preact-store'\nimport type { Atom, ReadonlyAtom } from '@tanstack/preact-store'\nimport type {\n RowData,\n Table,\n TableFeatures,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren } from 'preact'\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store).\n */\nexport type SubscribePropsWithSourceWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n> = {\n table: Table<TFeatures, TData>\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected).\n */\nexport type SubscribePropsWithSource<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected = TSourceValue,\n> =\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TData, TSelected>\n | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>\n | SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >\n\n/**\n * A Preact component that allows you to subscribe to the table state.\n *\n * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so\n * JSX contextual typing works. This standalone component uses a union `props` type.\n */\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n>(\n props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSourceValue,\n TSelected,\n>(\n props: SubscribePropsWithSourceWithSelector<\n TFeatures,\n TData,\n TSourceValue,\n TSelected\n >,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n>(\n props: SubscribePropsWithStore<TFeatures, TData, TSelected>,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,\n): ComponentChildren {\n const source = 'source' in props ? props.source : props.table.store\n const selectFn =\n 'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector\n\n const selected = useSelector(\n source as never,\n selectFn as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ComponentChildren)(selected)\n : props.children\n}\n"],"mappings":";;;AA+HA,SAAgB,UAMd,OACmB;CAKnB,MAAM,WAAW,YAJF,YAAY,QAAQ,MAAM,SAAS,MAAM,MAAM,OAE5D,YAAY,QAAS,MAAM,cAAc,MAAe,KAAM,MAAM,UAKpE,EACE,SAAS,SACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAAqD,SAAS,GACrE,MAAM"}
1
+ {"version":3,"file":"Subscribe.js","names":[],"sources":["../src/Subscribe.ts"],"sourcesContent":["import { shallow, useSelector } from '@tanstack/preact-store'\nimport type {\n Atom,\n ReadonlyAtom,\n ReadonlyStore,\n Store,\n} from '@tanstack/preact-store'\nimport type { TableFeatures, TableState } from '@tanstack/table-core'\nimport type { ComponentChildren } from 'preact'\n\nexport type SubscribeSource<TValue> =\n | Atom<TValue>\n | ReadonlyAtom<TValue>\n | Store<TValue>\n | ReadonlyStore<TValue>\n\n/**\n * Subscribe to `table.store` (full table state). The selector receives the full\n * {@link TableState}.\n */\nexport type SubscribePropsWithStore<\n TFeatures extends TableFeatures,\n TSelected,\n> = {\n source: SubscribeSource<TableState<TFeatures>>\n /**\n * Select from full table state. Re-renders when the selected value changes\n * (shallow compare).\n *\n * Required in store mode so you never accidentally subscribe to the whole\n * store without an explicit projection.\n */\n selector: (state: TableState<TFeatures>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to the full value of a source (e.g. `table.atoms.rowSelection` or\n * `table.optionsStore`). Omitting `selector` is equivalent to the identity\n * selector — children receive `TSourceValue`.\n */\nexport type SubscribePropsWithSourceIdentity<TSourceValue> = {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a projected value from a source (atom or store).\n */\nexport type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n}\n\n/**\n * Subscribe to a single source — atom or store (identity or projected).\n */\nexport type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> =\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>\n\nexport type SubscribeProps<\n TFeatures extends TableFeatures,\n TSelected = unknown,\n TSourceValue = unknown,\n> =\n | SubscribePropsWithStore<TFeatures, TSelected>\n | SubscribePropsWithSourceIdentity<TSourceValue>\n | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>\n\n/**\n * A Preact component that allows you to subscribe to the table state.\n *\n * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so\n * JSX contextual typing works. This standalone component uses a union `props` type.\n */\nexport function Subscribe<TSourceValue>(\n props: SubscribePropsWithSourceIdentity<TSourceValue>,\n): ComponentChildren\nexport function Subscribe<TSourceValue, TSelected>(\n props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,\n): ComponentChildren\nexport function Subscribe<TFeatures extends TableFeatures, TSelected>(\n props: SubscribePropsWithStore<TFeatures, TSelected>,\n): ComponentChildren\nexport function Subscribe<\n TFeatures extends TableFeatures,\n TSelected,\n TSourceValue,\n>(\n props: SubscribeProps<TFeatures, TSelected, TSourceValue>,\n): ComponentChildren {\n const selected = useSelector(\n props.source as never,\n props.selector as Parameters<typeof useSelector>[1],\n {\n compare: shallow,\n },\n ) as TSelected\n\n return typeof props.children === 'function'\n ? (props.children as (state: TSelected) => ComponentChildren)(selected)\n : props.children\n}\n"],"mappings":";;;AAuFA,SAAgB,UAKd,OACmB;CACnB,MAAM,WAAW,YACf,MAAM,QACN,MAAM,UACN,EACE,SAAS,SACV,CACF;AAED,QAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAAqD,SAAS,GACrE,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"createTableHook.cjs","names":["FlexRender","useTable"],"sources":["../src/createTableHook.tsx"],"sourcesContent":["'use client'\nimport { createContext } from 'preact'\nimport { useContext, useMemo } from 'preact/hooks'\nimport { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'\nimport { useTable } from './useTable'\nimport { FlexRender } from './FlexRender'\nimport type {\n AccessorFn,\n AccessorFnColumnDef,\n AccessorKeyColumnDef,\n Cell,\n CellContext,\n CellData,\n Column,\n ColumnDef,\n DeepKeys,\n DeepValue,\n DisplayColumnDef,\n GroupColumnDef,\n Header,\n IdentifiedColumnDef,\n NoInfer,\n Row,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren, ComponentType } from 'preact'\nimport type { PreactTable } from './useTable'\n\n// =============================================================================\n// Enhanced Context Types with Pre-bound Components\n// =============================================================================\n\n/**\n * Enhanced CellContext with pre-bound cell components.\n * The `cell` property includes the registered cellComponents.\n */\nexport type AppCellContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> = {\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren }\n column: Column<TFeatures, TData, TValue>\n getValue: CellContext<TFeatures, TData, TValue>['getValue']\n renderValue: CellContext<TFeatures, TData, TValue>['renderValue']\n row: Row<TFeatures, TData>\n table: Table<TFeatures, TData>\n}\n\n/**\n * Enhanced HeaderContext with pre-bound header components.\n * The `header` property includes the registered headerComponents.\n */\nexport type AppHeaderContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n column: Column<TFeatures, TData, TValue>\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren }\n table: Table<TFeatures, TData>\n}\n\n// =============================================================================\n// Enhanced Column Definition Types\n// =============================================================================\n\n/**\n * Template type for column definitions that can be a string or a function.\n */\nexport type AppColumnDefTemplate<TProps extends object> =\n | string\n | ((props: TProps) => any)\n\n/**\n * Enhanced column definition base with pre-bound components in cell/header/footer contexts.\n */\nexport type AppColumnDefBase<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n IdentifiedColumnDef<TFeatures, TData, TValue>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, TValue, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n}\n\n/**\n * Enhanced display column definition with pre-bound components.\n */\nexport type AppDisplayColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n DisplayColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n}\n\n/**\n * Enhanced group column definition with pre-bound components.\n */\nexport type AppGroupColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n GroupColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer' | 'columns'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n columns?: Array<ColumnDef<TFeatures, TData, unknown>>\n}\n\n// =============================================================================\n// Enhanced Column Helper Type\n// =============================================================================\n\n/**\n * Enhanced column helper with pre-bound components in cell/header/footer contexts.\n * This enables TypeScript to know about the registered components when defining columns.\n */\nexport type AppColumnHelper<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n /**\n * Creates a data column definition with an accessor key or function.\n * The cell, header, and footer contexts include pre-bound components.\n */\n accessor: <\n TAccessor extends AccessorFn<TData> | DeepKeys<TData>,\n TValue extends TAccessor extends AccessorFn<TData, infer TReturn>\n ? TReturn\n : TAccessor extends DeepKeys<TData>\n ? DeepValue<TData, TAccessor>\n : never,\n >(\n accessor: TAccessor,\n column: TAccessor extends AccessorFn<TData>\n ? AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n > & { id: string }\n : AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n >,\n ) => TAccessor extends AccessorFn<TData>\n ? AccessorFnColumnDef<TFeatures, TData, TValue>\n : AccessorKeyColumnDef<TFeatures, TData, TValue>\n\n /**\n * Wraps an array of column definitions to preserve each column's individual TValue type.\n */\n columns: <TColumns extends ReadonlyArray<ColumnDef<TFeatures, TData, any>>>(\n columns: [...TColumns],\n ) => Array<ColumnDef<TFeatures, TData, any>> & [...TColumns]\n\n /**\n * Creates a display column definition for non-data columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n display: (\n column: AppDisplayColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => DisplayColumnDef<TFeatures, TData, unknown>\n\n /**\n * Creates a group column definition with nested child columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n group: (\n column: AppGroupColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => GroupColumnDef<TFeatures, TData, unknown>\n}\n\n// =============================================================================\n// CreateTableHook Options and Props\n// =============================================================================\n\n/**\n * Options for creating a table hook with pre-bound components and default table options.\n * Extends all TableOptions except 'columns' | 'data' | 'store' | 'state' | 'initialState'.\n */\nexport type CreateTableHookOptions<\n TFeatures extends TableFeatures,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n> & {\n /**\n * Table-level components that need access to the table instance.\n * These are available directly on the table object returned by useAppTable.\n * Use `useTableContext()` inside these components.\n * @example { PaginationControls, GlobalFilter, RowCount }\n */\n tableComponents?: TTableComponents\n /**\n * Cell-level components that need access to the cell instance.\n * These are available on the cell object passed to AppCell's children.\n * Use `useCellContext()` inside these components.\n * @example { TextCell, NumberCell, DateCell, CurrencyCell }\n */\n cellComponents?: TCellComponents\n /**\n * Header-level components that need access to the header instance.\n * These are available on the header object passed to AppHeader/AppFooter's children.\n * Use `useHeaderContext()` inside these components.\n * @example { SortIndicator, ColumnFilter, ResizeHandle }\n */\n headerComponents?: THeaderComponents\n}\n\n/**\n * Props for AppTable component - without selector\n */\nexport interface AppTablePropsWithoutSelector {\n children: ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppTable component - with selector\n */\nexport interface AppTablePropsWithSelector<\n TFeatures extends TableFeatures,\n TSelected,\n> {\n children: (state: TSelected) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppCell component - without selector\n */\nexport interface AppCellPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppCell component - with selector\n */\nexport interface AppCellPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppHeader/AppFooter component - without selector\n */\nexport interface AppHeaderPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppHeader/AppFooter component - with selector\n */\nexport interface AppHeaderPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Component type for AppCell - wraps a cell and provides cell context with optional Subscribe\n */\nexport interface AppCellComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppHeader/AppFooter - wraps a header and provides header context with optional Subscribe\n */\nexport interface AppHeaderComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppTable - root wrapper with optional Subscribe\n */\nexport interface AppTableComponent<TFeatures extends TableFeatures> {\n (props: AppTablePropsWithoutSelector): ComponentChildren\n <TSelected>(\n props: AppTablePropsWithSelector<TFeatures, TSelected>,\n ): ComponentChildren\n}\n\n/**\n * Extended table API returned by useAppTable with all App wrapper components\n */\nexport type AppPreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = PreactTable<TFeatures, TData, TSelected> &\n NoInfer<TTableComponents> & {\n /**\n * Root wrapper component that provides table context with optional Subscribe.\n * @example\n * ```tsx\n * // Without selector - children is ComponentChildren\n * <table.AppTable>\n * <table>...</table>\n * </table.AppTable>\n *\n * // With selector - children receives selected state\n * <table.AppTable selector={(s) => s.pagination}>\n * {(pagination) => <div>Page {pagination.pageIndex}</div>}\n * </table.AppTable>\n * ```\n */\n AppTable: AppTableComponent<TFeatures>\n /**\n * Wraps a cell and provides cell context with pre-bound cellComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppCell cell={cell}>\n * {(c) => <td><c.TextCell /></td>}\n * </table.AppCell>\n *\n * // With selector - children receives cell and selected state\n * <table.AppCell cell={cell} selector={(s) => s.columnFilters}>\n * {(c, filters) => <td>{filters.length}</td>}\n * </table.AppCell>\n * ```\n */\n AppCell: AppCellComponent<TFeatures, TData, NoInfer<TCellComponents>>\n /**\n * Wraps a header and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppHeader header={header}>\n * {(h) => <th><h.SortIndicator /></th>}\n * </table.AppHeader>\n *\n * // With selector\n * <table.AppHeader header={header} selector={(s) => s.sorting}>\n * {(h, sorting) => <th>{sorting.length} sorted</th>}\n * </table.AppHeader>\n * ```\n */\n AppHeader: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n /**\n * Wraps a footer and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * <table.AppFooter header={footer}>\n * {(f) => <td><table.FlexRender footer={footer} /></td>}\n * </table.AppFooter>\n * ```\n */\n AppFooter: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n }\n\n/**\n * Creates a custom table hook with pre-bound components for composition.\n *\n * This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:\n * - Define features, row models, and default options once, shared across all tables\n * - Register reusable table, cell, and header components\n * - Access table/cell/header instances via context in those components\n * - Get a `useAppTable` hook that returns an extended table with App wrapper components\n * - Get a `createAppColumnHelper` function pre-bound to your features\n *\n * @example\n * ```tsx\n * // hooks/table.ts\n * export const {\n * useAppTable,\n * createAppColumnHelper,\n * useTableContext,\n * useCellContext,\n * useHeaderContext,\n * } = createTableHook({\n * _features: tableFeatures({\n * rowPaginationFeature,\n * rowSortingFeature,\n * columnFilteringFeature,\n * }),\n * _rowModels: {\n * paginatedRowModel: createPaginatedRowModel(),\n * sortedRowModel: createSortedRowModel(sortFns),\n * filteredRowModel: createFilteredRowModel(filterFns),\n * },\n * tableComponents: { PaginationControls, RowCount },\n * cellComponents: { TextCell, NumberCell },\n * headerComponents: { SortIndicator, ColumnFilter },\n * })\n *\n * // Create column helper with TFeatures already bound\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * // components/table-components.tsx\n * function PaginationControls() {\n * const table = useTableContext() // TFeatures already known!\n * return <table.Subscribe selector={(s) => s.pagination}>...</table.Subscribe>\n * }\n *\n * // features/users.tsx\n * function UsersTable({ data }: { data: Person[] }) {\n * const table = useAppTable({\n * columns,\n * data, // TData inferred from Person[]\n * })\n *\n * return (\n * <table.AppTable>\n * <table>\n * <thead>\n * {table.getHeaderGroups().map(headerGroup => (\n * <tr key={headerGroup.id}>\n * {headerGroup.headers.map(h => (\n * <table.AppHeader header={h} key={h.id}>\n * {(header) => (\n * <th>\n * <table.FlexRender header={h} />\n * <header.SortIndicator />\n * </th>\n * )}\n * </table.AppHeader>\n * ))}\n * </tr>\n * ))}\n * </thead>\n * <tbody>\n * {table.getRowModel().rows.map(row => (\n * <tr key={row.id}>\n * {row.getAllCells().map(c => (\n * <table.AppCell cell={c} key={c.id}>\n * {(cell) => <td><cell.TextCell /></td>}\n * </table.AppCell>\n * ))}\n * </tr>\n * ))}\n * </tbody>\n * </table>\n * <table.PaginationControls />\n * </table.AppTable>\n * )\n * }\n * ```\n */\nexport function createTableHook<\n TFeatures extends TableFeatures,\n const TTableComponents extends Record<string, ComponentType<any>>,\n const TCellComponents extends Record<string, ComponentType<any>>,\n const THeaderComponents extends Record<string, ComponentType<any>>,\n>({\n tableComponents,\n cellComponents,\n headerComponents,\n ...defaultTableOptions\n}: CreateTableHookOptions<\n TFeatures,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n>) {\n // Create contexts internally with TFeatures baked in\n const TableContext = createContext<PreactTable<TFeatures, any, any>>(\n null as never,\n )\n const CellContext = createContext<Cell<TFeatures, any, any>>(null as never)\n const HeaderContext = createContext<Header<TFeatures, any, any>>(\n null as never,\n )\n\n /**\n * Create a column helper pre-bound to the features and components configured in this table hook.\n * The cell, header, and footer contexts include pre-bound components (e.g., `cell.TextCell`).\n * @example\n * ```tsx\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * const columns = [\n * columnHelper.accessor('firstName', {\n * header: 'First Name',\n * cell: ({ cell }) => <cell.TextCell />, // cell has pre-bound components!\n * }),\n * columnHelper.accessor('age', {\n * header: 'Age',\n * cell: ({ cell }) => <cell.NumberCell />,\n * }),\n * ]\n * ```\n */\n function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n > {\n // The runtime implementation is the same - components are attached at render time\n // This cast provides the enhanced types for column definitions\n return coreCreateColumnHelper<TFeatures, TData>() as AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >\n }\n\n /**\n * Access the table instance from within an `AppTable` wrapper.\n * Use this in custom `tableComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function PaginationControls() {\n * const table = useTableContext()\n * return (\n * <table.Subscribe selector={(s) => s.pagination}>\n * {(pagination) => (\n * <div>\n * <button onClick={() => table.previousPage()}>Prev</button>\n * <span>Page {pagination.pageIndex + 1}</span>\n * <button onClick={() => table.nextPage()}>Next</button>\n * </div>\n * )}\n * </table.Subscribe>\n * )\n * }\n * ```\n */\n function useTableContext<TData extends RowData = RowData>(): PreactTable<\n TFeatures,\n TData\n > {\n const table = useContext(TableContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!table) {\n throw new Error(\n '`useTableContext` must be used within an `AppTable` component. ' +\n 'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.',\n )\n }\n\n return table as PreactTable<TFeatures, TData>\n }\n\n /**\n * Access the cell instance from within an `AppCell` wrapper.\n * Use this in custom `cellComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function TextCell() {\n * const cell = useCellContext<string>()\n * return <span>{cell.getValue()}</span>\n * }\n *\n * function NumberCell({ format }: { format?: Intl.NumberFormatOptions }) {\n * const cell = useCellContext<number>()\n * return <span>{cell.getValue().toLocaleString(undefined, format)}</span>\n * }\n * ```\n */\n function useCellContext<TValue extends CellData = CellData>() {\n const cell = useContext(CellContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!cell) {\n throw new Error(\n '`useCellContext` must be used within an `AppCell` component. ' +\n 'Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.',\n )\n }\n\n return cell as Cell<TFeatures, any, TValue>\n }\n\n /**\n * Access the header instance from within an `AppHeader` or `AppFooter` wrapper.\n * Use this in custom `headerComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function SortIndicator() {\n * const header = useHeaderContext()\n * const sorted = header.column.getIsSorted()\n * return sorted === 'asc' ? '🔼' : sorted === 'desc' ? '🔽' : null\n * }\n *\n * function ColumnFilter() {\n * const header = useHeaderContext()\n * if (!header.column.getCanFilter()) return null\n * return (\n * <input\n * value={(header.column.getFilterValue() ?? '') as string}\n * onChange={(e) => header.column.setFilterValue(e.target.value)}\n * placeholder=\"Filter...\"\n * />\n * )\n * }\n * ```\n */\n function useHeaderContext<TValue extends CellData = CellData>() {\n const header = useContext(HeaderContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!header) {\n throw new Error(\n '`useHeaderContext` must be used within an `AppHeader` or `AppFooter` component.',\n )\n }\n\n return header as Header<TFeatures, any, TValue>\n }\n\n /**\n * Context-aware FlexRender component for cells.\n * Uses the cell from context, so no need to pass cell prop.\n */\n function CellFlexRender() {\n const cell = useCellContext()\n return <FlexRender cell={cell} />\n }\n\n /**\n * Context-aware FlexRender component for headers.\n * Uses the header from context, so no need to pass header prop.\n */\n function HeaderFlexRender() {\n const header = useHeaderContext()\n return <FlexRender header={header} />\n }\n\n /**\n * Context-aware FlexRender component for footers.\n * Uses the header from context, so no need to pass footer prop.\n */\n function FooterFlexRender() {\n const header = useHeaderContext()\n return <FlexRender footer={header} />\n }\n\n /**\n * Enhanced useTable hook that returns a table with App wrapper components\n * and pre-bound tableComponents attached directly to the table object.\n *\n * Default options from createTableHook are automatically merged with\n * the options passed here. Options passed here take precedence.\n *\n * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.\n */\n function useAppTable<TData extends RowData, TSelected = {}>(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: (state: TableState<TFeatures>) => TSelected,\n ): AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n > {\n // Merge default options with provided options (provided takes precedence)\n const table = useTable<TFeatures, TData, TSelected>(\n { ...defaultTableOptions, ...tableOptions } as TableOptions<\n TFeatures,\n TData\n >,\n selector,\n )\n\n // AppTable - Root wrapper that provides table context with optional Subscribe\n const AppTable = useMemo(() => {\n function AppTableImpl(\n props: AppTablePropsWithoutSelector,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props: AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props:\n | AppTablePropsWithoutSelector\n | AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren {\n const { children, selector: appTableSelector } = props as any\n\n return (\n <TableContext.Provider value={table}>\n {appTableSelector ? (\n <table.Subscribe selector={appTableSelector}>\n {(state: TAppTableSelected) =>\n (children as (state: TAppTableSelected) => ComponentChildren)(\n state,\n )\n }\n </table.Subscribe>\n ) : (\n children\n )}\n </TableContext.Provider>\n )\n }\n return AppTableImpl as AppTableComponent<TFeatures>\n }, [table])\n\n // AppCell - Wraps cell with context, pre-bound cellComponents, and optional Subscribe\n const AppCell = useMemo(() => {\n function AppCellImpl<TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props:\n | AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >\n | AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren {\n const { cell, children, selector: appCellSelector } = props as any\n const extendedCell = Object.assign(cell, {\n FlexRender: CellFlexRender,\n ...cellComponents,\n })\n\n return (\n <CellContext.Provider value={cell}>\n {appCellSelector ? (\n <table.Subscribe selector={appCellSelector}>\n {(state: TAppCellSelected) =>\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & {\n FlexRender: () => ComponentChildren\n },\n state: TAppCellSelected,\n ) => ComponentChildren\n )(extendedCell, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedCell)\n )}\n </CellContext.Provider>\n )\n }\n return AppCellImpl as AppCellComponent<TFeatures, TData, TCellComponents>\n }, [table])\n\n // AppHeader - Wraps header with context, pre-bound headerComponents, and optional Subscribe\n const AppHeader = useMemo(() => {\n function AppHeaderImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appHeaderSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: HeaderFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appHeaderSelector ? (\n <table.Subscribe selector={appHeaderSelector}>\n {(state: TAppHeaderSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppHeaderSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppHeaderImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // AppFooter - Same as AppHeader (footers use Header type)\n const AppFooter = useMemo(() => {\n function AppFooterImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appFooterSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: FooterFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appFooterSelector ? (\n <table.Subscribe selector={appFooterSelector}>\n {(state: TAppFooterSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppFooterSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppFooterImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // Combine everything into the extended table API\n const extendedTable = useMemo(() => {\n return Object.assign(table, {\n AppTable,\n AppCell,\n AppHeader,\n AppFooter,\n ...tableComponents,\n }) as AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n >\n }, [table, AppTable, AppCell, AppHeader, AppFooter])\n\n return extendedTable\n }\n\n return {\n appFeatures: defaultTableOptions._features as TFeatures,\n createAppColumnHelper,\n useAppTable,\n useTableContext,\n useCellContext,\n useHeaderContext,\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"createTableHook.cjs","names":["FlexRender","useTable"],"sources":["../src/createTableHook.tsx"],"sourcesContent":["'use client'\nimport { createContext } from 'preact'\nimport { useContext, useMemo } from 'preact/hooks'\nimport { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'\nimport { useTable } from './useTable'\nimport { FlexRender } from './FlexRender'\nimport type {\n AccessorFn,\n AccessorFnColumnDef,\n AccessorKeyColumnDef,\n Cell,\n CellContext,\n CellData,\n Column,\n ColumnDef,\n DeepKeys,\n DeepValue,\n DisplayColumnDef,\n GroupColumnDef,\n Header,\n IdentifiedColumnDef,\n NoInfer,\n Row,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren, ComponentType } from 'preact'\nimport type { PreactTable } from './useTable'\n\n// =============================================================================\n// Enhanced Context Types with Pre-bound Components\n// =============================================================================\n\n/**\n * Enhanced CellContext with pre-bound cell components.\n * The `cell` property includes the registered cellComponents.\n */\nexport type AppCellContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> = {\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren }\n column: Column<TFeatures, TData, TValue>\n getValue: CellContext<TFeatures, TData, TValue>['getValue']\n renderValue: CellContext<TFeatures, TData, TValue>['renderValue']\n row: Row<TFeatures, TData>\n table: Table<TFeatures, TData>\n}\n\n/**\n * Enhanced HeaderContext with pre-bound header components.\n * The `header` property includes the registered headerComponents.\n */\nexport type AppHeaderContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n column: Column<TFeatures, TData, TValue>\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren }\n table: Table<TFeatures, TData>\n}\n\n// =============================================================================\n// Enhanced Column Definition Types\n// =============================================================================\n\n/**\n * Template type for column definitions that can be a string or a function.\n */\nexport type AppColumnDefTemplate<TProps extends object> =\n | string\n | ((props: TProps) => any)\n\n/**\n * Enhanced column definition base with pre-bound components in cell/header/footer contexts.\n */\nexport type AppColumnDefBase<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n IdentifiedColumnDef<TFeatures, TData, TValue>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, TValue, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n}\n\n/**\n * Enhanced display column definition with pre-bound components.\n */\nexport type AppDisplayColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n DisplayColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n}\n\n/**\n * Enhanced group column definition with pre-bound components.\n */\nexport type AppGroupColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n GroupColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer' | 'columns'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n columns?: Array<ColumnDef<TFeatures, TData, unknown>>\n}\n\n// =============================================================================\n// Enhanced Column Helper Type\n// =============================================================================\n\n/**\n * Enhanced column helper with pre-bound components in cell/header/footer contexts.\n * This enables TypeScript to know about the registered components when defining columns.\n */\nexport type AppColumnHelper<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n /**\n * Creates a data column definition with an accessor key or function.\n * The cell, header, and footer contexts include pre-bound components.\n */\n accessor: <\n TAccessor extends AccessorFn<TData> | DeepKeys<TData>,\n TValue extends TAccessor extends AccessorFn<TData, infer TReturn>\n ? TReturn\n : TAccessor extends DeepKeys<TData>\n ? DeepValue<TData, TAccessor>\n : never,\n >(\n accessor: TAccessor,\n column: TAccessor extends AccessorFn<TData>\n ? AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n > & { id: string }\n : AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n >,\n ) => TAccessor extends AccessorFn<TData>\n ? AccessorFnColumnDef<TFeatures, TData, TValue>\n : AccessorKeyColumnDef<TFeatures, TData, TValue>\n\n /**\n * Wraps an array of column definitions to preserve each column's individual TValue type.\n */\n columns: <TColumns extends ReadonlyArray<ColumnDef<TFeatures, TData, any>>>(\n columns: [...TColumns],\n ) => Array<ColumnDef<TFeatures, TData, any>> & [...TColumns]\n\n /**\n * Creates a display column definition for non-data columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n display: (\n column: AppDisplayColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => DisplayColumnDef<TFeatures, TData, unknown>\n\n /**\n * Creates a group column definition with nested child columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n group: (\n column: AppGroupColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => GroupColumnDef<TFeatures, TData, unknown>\n}\n\n// =============================================================================\n// CreateTableHook Options and Props\n// =============================================================================\n\n/**\n * Options for creating a table hook with pre-bound components and default table options.\n * Extends all TableOptions except 'columns' | 'data' | 'store' | 'state' | 'initialState'.\n */\nexport type CreateTableHookOptions<\n TFeatures extends TableFeatures,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n> & {\n /**\n * Table-level components that need access to the table instance.\n * These are available directly on the table object returned by useAppTable.\n * Use `useTableContext()` inside these components.\n * @example { PaginationControls, GlobalFilter, RowCount }\n */\n tableComponents?: TTableComponents\n /**\n * Cell-level components that need access to the cell instance.\n * These are available on the cell object passed to AppCell's children.\n * Use `useCellContext()` inside these components.\n * @example { TextCell, NumberCell, DateCell, CurrencyCell }\n */\n cellComponents?: TCellComponents\n /**\n * Header-level components that need access to the header instance.\n * These are available on the header object passed to AppHeader/AppFooter's children.\n * Use `useHeaderContext()` inside these components.\n * @example { SortIndicator, ColumnFilter, ResizeHandle }\n */\n headerComponents?: THeaderComponents\n}\n\n/**\n * Props for AppTable component - without selector\n */\nexport interface AppTablePropsWithoutSelector {\n children: ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppTable component - with selector\n */\nexport interface AppTablePropsWithSelector<\n TFeatures extends TableFeatures,\n TSelected,\n> {\n children: (state: TSelected) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppCell component - without selector\n */\nexport interface AppCellPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppCell component - with selector\n */\nexport interface AppCellPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppHeader/AppFooter component - without selector\n */\nexport interface AppHeaderPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppHeader/AppFooter component - with selector\n */\nexport interface AppHeaderPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Component type for AppCell - wraps a cell and provides cell context with optional Subscribe\n */\nexport interface AppCellComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppHeader/AppFooter - wraps a header and provides header context with optional Subscribe\n */\nexport interface AppHeaderComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppTable - root wrapper with optional Subscribe\n */\nexport interface AppTableComponent<TFeatures extends TableFeatures> {\n (props: AppTablePropsWithoutSelector): ComponentChildren\n <TSelected>(\n props: AppTablePropsWithSelector<TFeatures, TSelected>,\n ): ComponentChildren\n}\n\n/**\n * Extended table API returned by useAppTable with all App wrapper components\n */\nexport type AppPreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = PreactTable<TFeatures, TData, TSelected> &\n NoInfer<TTableComponents> & {\n /**\n * Root wrapper component that provides table context with optional Subscribe.\n * @example\n * ```tsx\n * // Without selector - children is ComponentChildren\n * <table.AppTable>\n * <table>...</table>\n * </table.AppTable>\n *\n * // With selector - children receives selected state\n * <table.AppTable selector={(s) => s.pagination}>\n * {(pagination) => <div>Page {pagination.pageIndex}</div>}\n * </table.AppTable>\n * ```\n */\n AppTable: AppTableComponent<TFeatures>\n /**\n * Wraps a cell and provides cell context with pre-bound cellComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppCell cell={cell}>\n * {(c) => <td><c.TextCell /></td>}\n * </table.AppCell>\n *\n * // With selector - children receives cell and selected state\n * <table.AppCell cell={cell} selector={(s) => s.columnFilters}>\n * {(c, filters) => <td>{filters.length}</td>}\n * </table.AppCell>\n * ```\n */\n AppCell: AppCellComponent<TFeatures, TData, NoInfer<TCellComponents>>\n /**\n * Wraps a header and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppHeader header={header}>\n * {(h) => <th><h.SortIndicator /></th>}\n * </table.AppHeader>\n *\n * // With selector\n * <table.AppHeader header={header} selector={(s) => s.sorting}>\n * {(h, sorting) => <th>{sorting.length} sorted</th>}\n * </table.AppHeader>\n * ```\n */\n AppHeader: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n /**\n * Wraps a footer and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * <table.AppFooter header={footer}>\n * {(f) => <td><table.FlexRender footer={footer} /></td>}\n * </table.AppFooter>\n * ```\n */\n AppFooter: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n }\n\n/**\n * Creates a custom table hook with pre-bound components for composition.\n *\n * This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:\n * - Define features, row models, and default options once, shared across all tables\n * - Register reusable table, cell, and header components\n * - Access table/cell/header instances via context in those components\n * - Get a `useAppTable` hook that returns an extended table with App wrapper components\n * - Get a `createAppColumnHelper` function pre-bound to your features\n *\n * @example\n * ```tsx\n * // hooks/table.ts\n * export const {\n * useAppTable,\n * createAppColumnHelper,\n * useTableContext,\n * useCellContext,\n * useHeaderContext,\n * } = createTableHook({\n * _features: tableFeatures({\n * rowPaginationFeature,\n * rowSortingFeature,\n * columnFilteringFeature,\n * }),\n * _rowModels: {\n * paginatedRowModel: createPaginatedRowModel(),\n * sortedRowModel: createSortedRowModel(sortFns),\n * filteredRowModel: createFilteredRowModel(filterFns),\n * },\n * tableComponents: { PaginationControls, RowCount },\n * cellComponents: { TextCell, NumberCell },\n * headerComponents: { SortIndicator, ColumnFilter },\n * })\n *\n * // Create column helper with TFeatures already bound\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * // components/table-components.tsx\n * function PaginationControls() {\n * const table = useTableContext() // TFeatures already known!\n * return <table.Subscribe selector={(s) => s.pagination}>...</table.Subscribe>\n * }\n *\n * // features/users.tsx\n * function UsersTable({ data }: { data: Person[] }) {\n * const table = useAppTable({\n * columns,\n * data, // TData inferred from Person[]\n * })\n *\n * return (\n * <table.AppTable>\n * <table>\n * <thead>\n * {table.getHeaderGroups().map(headerGroup => (\n * <tr key={headerGroup.id}>\n * {headerGroup.headers.map(h => (\n * <table.AppHeader header={h} key={h.id}>\n * {(header) => (\n * <th>\n * <table.FlexRender header={h} />\n * <header.SortIndicator />\n * </th>\n * )}\n * </table.AppHeader>\n * ))}\n * </tr>\n * ))}\n * </thead>\n * <tbody>\n * {table.getRowModel().rows.map(row => (\n * <tr key={row.id}>\n * {row.getAllCells().map(c => (\n * <table.AppCell cell={c} key={c.id}>\n * {(cell) => <td><cell.TextCell /></td>}\n * </table.AppCell>\n * ))}\n * </tr>\n * ))}\n * </tbody>\n * </table>\n * <table.PaginationControls />\n * </table.AppTable>\n * )\n * }\n * ```\n */\nexport function createTableHook<\n TFeatures extends TableFeatures,\n const TTableComponents extends Record<string, ComponentType<any>>,\n const TCellComponents extends Record<string, ComponentType<any>>,\n const THeaderComponents extends Record<string, ComponentType<any>>,\n>({\n tableComponents,\n cellComponents,\n headerComponents,\n ...defaultTableOptions\n}: CreateTableHookOptions<\n TFeatures,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n>) {\n // Create contexts internally with TFeatures baked in\n const TableContext = createContext<PreactTable<TFeatures, any, any>>(\n null as never,\n )\n const CellContext = createContext<Cell<TFeatures, any, any>>(null as never)\n const HeaderContext = createContext<Header<TFeatures, any, any>>(\n null as never,\n )\n\n /**\n * Create a column helper pre-bound to the features and components configured in this table hook.\n * The cell, header, and footer contexts include pre-bound components (e.g., `cell.TextCell`).\n * @example\n * ```tsx\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * const columns = [\n * columnHelper.accessor('firstName', {\n * header: 'First Name',\n * cell: ({ cell }) => <cell.TextCell />, // cell has pre-bound components!\n * }),\n * columnHelper.accessor('age', {\n * header: 'Age',\n * cell: ({ cell }) => <cell.NumberCell />,\n * }),\n * ]\n * ```\n */\n function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n > {\n // The runtime implementation is the same - components are attached at render time\n // This cast provides the enhanced types for column definitions\n return coreCreateColumnHelper<TFeatures, TData>() as AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >\n }\n\n /**\n * Access the table instance from within an `AppTable` wrapper.\n * Use this in custom `tableComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function PaginationControls() {\n * const table = useTableContext()\n * return (\n * <table.Subscribe selector={(s) => s.pagination}>\n * {(pagination) => (\n * <div>\n * <button onClick={() => table.previousPage()}>Prev</button>\n * <span>Page {pagination.pageIndex + 1}</span>\n * <button onClick={() => table.nextPage()}>Next</button>\n * </div>\n * )}\n * </table.Subscribe>\n * )\n * }\n * ```\n */\n function useTableContext<TData extends RowData = RowData>(): PreactTable<\n TFeatures,\n TData\n > {\n const table = useContext(TableContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!table) {\n throw new Error(\n '`useTableContext` must be used within an `AppTable` component. ' +\n 'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.',\n )\n }\n\n return table as PreactTable<TFeatures, TData>\n }\n\n /**\n * Access the cell instance from within an `AppCell` wrapper.\n * Use this in custom `cellComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function TextCell() {\n * const cell = useCellContext<string>()\n * return <span>{cell.getValue()}</span>\n * }\n *\n * function NumberCell({ format }: { format?: Intl.NumberFormatOptions }) {\n * const cell = useCellContext<number>()\n * return <span>{cell.getValue().toLocaleString(undefined, format)}</span>\n * }\n * ```\n */\n function useCellContext<TValue extends CellData = CellData>() {\n const cell = useContext(CellContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!cell) {\n throw new Error(\n '`useCellContext` must be used within an `AppCell` component. ' +\n 'Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.',\n )\n }\n\n return cell as Cell<TFeatures, any, TValue>\n }\n\n /**\n * Access the header instance from within an `AppHeader` or `AppFooter` wrapper.\n * Use this in custom `headerComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function SortIndicator() {\n * const header = useHeaderContext()\n * const sorted = header.column.getIsSorted()\n * return sorted === 'asc' ? '🔼' : sorted === 'desc' ? '🔽' : null\n * }\n *\n * function ColumnFilter() {\n * const header = useHeaderContext()\n * if (!header.column.getCanFilter()) return null\n * return (\n * <input\n * value={(header.column.getFilterValue() ?? '') as string}\n * onChange={(e) => header.column.setFilterValue(e.target.value)}\n * placeholder=\"Filter...\"\n * />\n * )\n * }\n * ```\n */\n function useHeaderContext<TValue extends CellData = CellData>() {\n const header = useContext(HeaderContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!header) {\n throw new Error(\n '`useHeaderContext` must be used within an `AppHeader` or `AppFooter` component.',\n )\n }\n\n return header as Header<TFeatures, any, TValue>\n }\n\n /**\n * Context-aware FlexRender component for cells.\n * Uses the cell from context, so no need to pass cell prop.\n */\n function CellFlexRender() {\n const cell = useCellContext()\n return <FlexRender cell={cell} />\n }\n\n /**\n * Context-aware FlexRender component for headers.\n * Uses the header from context, so no need to pass header prop.\n */\n function HeaderFlexRender() {\n const header = useHeaderContext()\n return <FlexRender header={header} />\n }\n\n /**\n * Context-aware FlexRender component for footers.\n * Uses the header from context, so no need to pass footer prop.\n */\n function FooterFlexRender() {\n const header = useHeaderContext()\n return <FlexRender footer={header} />\n }\n\n /**\n * Enhanced useTable hook that returns a table with App wrapper components\n * and pre-bound tableComponents attached directly to the table object.\n *\n * Default options from createTableHook are automatically merged with\n * the options passed here. Options passed here take precedence.\n *\n * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.\n */\n function useAppTable<\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n >(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: (state: TableState<TFeatures>) => TSelected,\n ): AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n > {\n // Merge default options with provided options (provided takes precedence)\n const table = useTable<TFeatures, TData, TSelected>(\n { ...defaultTableOptions, ...tableOptions } as TableOptions<\n TFeatures,\n TData\n >,\n selector,\n )\n\n // AppTable - Root wrapper that provides table context with optional Subscribe\n const AppTable = useMemo(() => {\n function AppTableImpl(\n props: AppTablePropsWithoutSelector,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props: AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props:\n | AppTablePropsWithoutSelector\n | AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren {\n const { children, selector: appTableSelector } = props as any\n\n return (\n <TableContext.Provider value={table}>\n {appTableSelector ? (\n <table.Subscribe selector={appTableSelector}>\n {(state: TAppTableSelected) =>\n (children as (state: TAppTableSelected) => ComponentChildren)(\n state,\n )\n }\n </table.Subscribe>\n ) : (\n children\n )}\n </TableContext.Provider>\n )\n }\n return AppTableImpl as AppTableComponent<TFeatures>\n }, [table])\n\n // AppCell - Wraps cell with context, pre-bound cellComponents, and optional Subscribe\n const AppCell = useMemo(() => {\n function AppCellImpl<TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props:\n | AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >\n | AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren {\n const { cell, children, selector: appCellSelector } = props as any\n const extendedCell = Object.assign(cell, {\n FlexRender: CellFlexRender,\n ...cellComponents,\n })\n\n return (\n <CellContext.Provider value={cell}>\n {appCellSelector ? (\n <table.Subscribe selector={appCellSelector}>\n {(state: TAppCellSelected) =>\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & {\n FlexRender: () => ComponentChildren\n },\n state: TAppCellSelected,\n ) => ComponentChildren\n )(extendedCell, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedCell)\n )}\n </CellContext.Provider>\n )\n }\n return AppCellImpl as AppCellComponent<TFeatures, TData, TCellComponents>\n }, [table])\n\n // AppHeader - Wraps header with context, pre-bound headerComponents, and optional Subscribe\n const AppHeader = useMemo(() => {\n function AppHeaderImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appHeaderSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: HeaderFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appHeaderSelector ? (\n <table.Subscribe selector={appHeaderSelector}>\n {(state: TAppHeaderSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppHeaderSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppHeaderImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // AppFooter - Same as AppHeader (footers use Header type)\n const AppFooter = useMemo(() => {\n function AppFooterImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appFooterSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: FooterFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appFooterSelector ? (\n <table.Subscribe selector={appFooterSelector}>\n {(state: TAppFooterSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppFooterSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppFooterImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // Combine everything into the extended table API\n const extendedTable = useMemo(() => {\n return Object.assign(table, {\n AppTable,\n AppCell,\n AppHeader,\n AppFooter,\n ...tableComponents,\n }) as AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n >\n }, [table, AppTable, AppCell, AppHeader, AppFooter])\n\n return extendedTable\n }\n\n return {\n appFeatures: defaultTableOptions._features as TFeatures,\n createAppColumnHelper,\n useAppTable,\n useTableContext,\n useCellContext,\n useHeaderContext,\n }\n}\n"],"mappings":"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"}
@@ -348,7 +348,7 @@ declare function createTableHook<TFeatures extends TableFeatures, const TTableCo
348
348
  }: CreateTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents>): {
349
349
  appFeatures: TFeatures;
350
350
  createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<TFeatures, TData, TCellComponents, THeaderComponents>;
351
- useAppTable: <TData extends RowData, TSelected = {}>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppPreactTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
351
+ useAppTable: <TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppPreactTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
352
352
  useTableContext: <TData extends RowData = RowData>() => PreactTable<TFeatures, TData>;
353
353
  useCellContext: <TValue extends CellData = unknown>() => Cell<TFeatures, any, TValue>;
354
354
  useHeaderContext: <TValue extends CellData = unknown>() => Header<TFeatures, any, TValue>;
@@ -348,7 +348,7 @@ declare function createTableHook<TFeatures extends TableFeatures, const TTableCo
348
348
  }: CreateTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents>): {
349
349
  appFeatures: TFeatures;
350
350
  createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<TFeatures, TData, TCellComponents, THeaderComponents>;
351
- useAppTable: <TData extends RowData, TSelected = {}>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppPreactTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
351
+ useAppTable: <TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppPreactTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
352
352
  useTableContext: <TData extends RowData = RowData>() => PreactTable<TFeatures, TData>;
353
353
  useCellContext: <TValue extends CellData = unknown>() => Cell<TFeatures, any, TValue>;
354
354
  useHeaderContext: <TValue extends CellData = unknown>() => Header<TFeatures, any, TValue>;
@@ -1 +1 @@
1
- {"version":3,"file":"createTableHook.js","names":["coreCreateColumnHelper"],"sources":["../src/createTableHook.tsx"],"sourcesContent":["'use client'\nimport { createContext } from 'preact'\nimport { useContext, useMemo } from 'preact/hooks'\nimport { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'\nimport { useTable } from './useTable'\nimport { FlexRender } from './FlexRender'\nimport type {\n AccessorFn,\n AccessorFnColumnDef,\n AccessorKeyColumnDef,\n Cell,\n CellContext,\n CellData,\n Column,\n ColumnDef,\n DeepKeys,\n DeepValue,\n DisplayColumnDef,\n GroupColumnDef,\n Header,\n IdentifiedColumnDef,\n NoInfer,\n Row,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren, ComponentType } from 'preact'\nimport type { PreactTable } from './useTable'\n\n// =============================================================================\n// Enhanced Context Types with Pre-bound Components\n// =============================================================================\n\n/**\n * Enhanced CellContext with pre-bound cell components.\n * The `cell` property includes the registered cellComponents.\n */\nexport type AppCellContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> = {\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren }\n column: Column<TFeatures, TData, TValue>\n getValue: CellContext<TFeatures, TData, TValue>['getValue']\n renderValue: CellContext<TFeatures, TData, TValue>['renderValue']\n row: Row<TFeatures, TData>\n table: Table<TFeatures, TData>\n}\n\n/**\n * Enhanced HeaderContext with pre-bound header components.\n * The `header` property includes the registered headerComponents.\n */\nexport type AppHeaderContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n column: Column<TFeatures, TData, TValue>\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren }\n table: Table<TFeatures, TData>\n}\n\n// =============================================================================\n// Enhanced Column Definition Types\n// =============================================================================\n\n/**\n * Template type for column definitions that can be a string or a function.\n */\nexport type AppColumnDefTemplate<TProps extends object> =\n | string\n | ((props: TProps) => any)\n\n/**\n * Enhanced column definition base with pre-bound components in cell/header/footer contexts.\n */\nexport type AppColumnDefBase<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n IdentifiedColumnDef<TFeatures, TData, TValue>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, TValue, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n}\n\n/**\n * Enhanced display column definition with pre-bound components.\n */\nexport type AppDisplayColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n DisplayColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n}\n\n/**\n * Enhanced group column definition with pre-bound components.\n */\nexport type AppGroupColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n GroupColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer' | 'columns'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n columns?: Array<ColumnDef<TFeatures, TData, unknown>>\n}\n\n// =============================================================================\n// Enhanced Column Helper Type\n// =============================================================================\n\n/**\n * Enhanced column helper with pre-bound components in cell/header/footer contexts.\n * This enables TypeScript to know about the registered components when defining columns.\n */\nexport type AppColumnHelper<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n /**\n * Creates a data column definition with an accessor key or function.\n * The cell, header, and footer contexts include pre-bound components.\n */\n accessor: <\n TAccessor extends AccessorFn<TData> | DeepKeys<TData>,\n TValue extends TAccessor extends AccessorFn<TData, infer TReturn>\n ? TReturn\n : TAccessor extends DeepKeys<TData>\n ? DeepValue<TData, TAccessor>\n : never,\n >(\n accessor: TAccessor,\n column: TAccessor extends AccessorFn<TData>\n ? AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n > & { id: string }\n : AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n >,\n ) => TAccessor extends AccessorFn<TData>\n ? AccessorFnColumnDef<TFeatures, TData, TValue>\n : AccessorKeyColumnDef<TFeatures, TData, TValue>\n\n /**\n * Wraps an array of column definitions to preserve each column's individual TValue type.\n */\n columns: <TColumns extends ReadonlyArray<ColumnDef<TFeatures, TData, any>>>(\n columns: [...TColumns],\n ) => Array<ColumnDef<TFeatures, TData, any>> & [...TColumns]\n\n /**\n * Creates a display column definition for non-data columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n display: (\n column: AppDisplayColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => DisplayColumnDef<TFeatures, TData, unknown>\n\n /**\n * Creates a group column definition with nested child columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n group: (\n column: AppGroupColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => GroupColumnDef<TFeatures, TData, unknown>\n}\n\n// =============================================================================\n// CreateTableHook Options and Props\n// =============================================================================\n\n/**\n * Options for creating a table hook with pre-bound components and default table options.\n * Extends all TableOptions except 'columns' | 'data' | 'store' | 'state' | 'initialState'.\n */\nexport type CreateTableHookOptions<\n TFeatures extends TableFeatures,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n> & {\n /**\n * Table-level components that need access to the table instance.\n * These are available directly on the table object returned by useAppTable.\n * Use `useTableContext()` inside these components.\n * @example { PaginationControls, GlobalFilter, RowCount }\n */\n tableComponents?: TTableComponents\n /**\n * Cell-level components that need access to the cell instance.\n * These are available on the cell object passed to AppCell's children.\n * Use `useCellContext()` inside these components.\n * @example { TextCell, NumberCell, DateCell, CurrencyCell }\n */\n cellComponents?: TCellComponents\n /**\n * Header-level components that need access to the header instance.\n * These are available on the header object passed to AppHeader/AppFooter's children.\n * Use `useHeaderContext()` inside these components.\n * @example { SortIndicator, ColumnFilter, ResizeHandle }\n */\n headerComponents?: THeaderComponents\n}\n\n/**\n * Props for AppTable component - without selector\n */\nexport interface AppTablePropsWithoutSelector {\n children: ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppTable component - with selector\n */\nexport interface AppTablePropsWithSelector<\n TFeatures extends TableFeatures,\n TSelected,\n> {\n children: (state: TSelected) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppCell component - without selector\n */\nexport interface AppCellPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppCell component - with selector\n */\nexport interface AppCellPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppHeader/AppFooter component - without selector\n */\nexport interface AppHeaderPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppHeader/AppFooter component - with selector\n */\nexport interface AppHeaderPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Component type for AppCell - wraps a cell and provides cell context with optional Subscribe\n */\nexport interface AppCellComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppHeader/AppFooter - wraps a header and provides header context with optional Subscribe\n */\nexport interface AppHeaderComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppTable - root wrapper with optional Subscribe\n */\nexport interface AppTableComponent<TFeatures extends TableFeatures> {\n (props: AppTablePropsWithoutSelector): ComponentChildren\n <TSelected>(\n props: AppTablePropsWithSelector<TFeatures, TSelected>,\n ): ComponentChildren\n}\n\n/**\n * Extended table API returned by useAppTable with all App wrapper components\n */\nexport type AppPreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = PreactTable<TFeatures, TData, TSelected> &\n NoInfer<TTableComponents> & {\n /**\n * Root wrapper component that provides table context with optional Subscribe.\n * @example\n * ```tsx\n * // Without selector - children is ComponentChildren\n * <table.AppTable>\n * <table>...</table>\n * </table.AppTable>\n *\n * // With selector - children receives selected state\n * <table.AppTable selector={(s) => s.pagination}>\n * {(pagination) => <div>Page {pagination.pageIndex}</div>}\n * </table.AppTable>\n * ```\n */\n AppTable: AppTableComponent<TFeatures>\n /**\n * Wraps a cell and provides cell context with pre-bound cellComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppCell cell={cell}>\n * {(c) => <td><c.TextCell /></td>}\n * </table.AppCell>\n *\n * // With selector - children receives cell and selected state\n * <table.AppCell cell={cell} selector={(s) => s.columnFilters}>\n * {(c, filters) => <td>{filters.length}</td>}\n * </table.AppCell>\n * ```\n */\n AppCell: AppCellComponent<TFeatures, TData, NoInfer<TCellComponents>>\n /**\n * Wraps a header and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppHeader header={header}>\n * {(h) => <th><h.SortIndicator /></th>}\n * </table.AppHeader>\n *\n * // With selector\n * <table.AppHeader header={header} selector={(s) => s.sorting}>\n * {(h, sorting) => <th>{sorting.length} sorted</th>}\n * </table.AppHeader>\n * ```\n */\n AppHeader: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n /**\n * Wraps a footer and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * <table.AppFooter header={footer}>\n * {(f) => <td><table.FlexRender footer={footer} /></td>}\n * </table.AppFooter>\n * ```\n */\n AppFooter: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n }\n\n/**\n * Creates a custom table hook with pre-bound components for composition.\n *\n * This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:\n * - Define features, row models, and default options once, shared across all tables\n * - Register reusable table, cell, and header components\n * - Access table/cell/header instances via context in those components\n * - Get a `useAppTable` hook that returns an extended table with App wrapper components\n * - Get a `createAppColumnHelper` function pre-bound to your features\n *\n * @example\n * ```tsx\n * // hooks/table.ts\n * export const {\n * useAppTable,\n * createAppColumnHelper,\n * useTableContext,\n * useCellContext,\n * useHeaderContext,\n * } = createTableHook({\n * _features: tableFeatures({\n * rowPaginationFeature,\n * rowSortingFeature,\n * columnFilteringFeature,\n * }),\n * _rowModels: {\n * paginatedRowModel: createPaginatedRowModel(),\n * sortedRowModel: createSortedRowModel(sortFns),\n * filteredRowModel: createFilteredRowModel(filterFns),\n * },\n * tableComponents: { PaginationControls, RowCount },\n * cellComponents: { TextCell, NumberCell },\n * headerComponents: { SortIndicator, ColumnFilter },\n * })\n *\n * // Create column helper with TFeatures already bound\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * // components/table-components.tsx\n * function PaginationControls() {\n * const table = useTableContext() // TFeatures already known!\n * return <table.Subscribe selector={(s) => s.pagination}>...</table.Subscribe>\n * }\n *\n * // features/users.tsx\n * function UsersTable({ data }: { data: Person[] }) {\n * const table = useAppTable({\n * columns,\n * data, // TData inferred from Person[]\n * })\n *\n * return (\n * <table.AppTable>\n * <table>\n * <thead>\n * {table.getHeaderGroups().map(headerGroup => (\n * <tr key={headerGroup.id}>\n * {headerGroup.headers.map(h => (\n * <table.AppHeader header={h} key={h.id}>\n * {(header) => (\n * <th>\n * <table.FlexRender header={h} />\n * <header.SortIndicator />\n * </th>\n * )}\n * </table.AppHeader>\n * ))}\n * </tr>\n * ))}\n * </thead>\n * <tbody>\n * {table.getRowModel().rows.map(row => (\n * <tr key={row.id}>\n * {row.getAllCells().map(c => (\n * <table.AppCell cell={c} key={c.id}>\n * {(cell) => <td><cell.TextCell /></td>}\n * </table.AppCell>\n * ))}\n * </tr>\n * ))}\n * </tbody>\n * </table>\n * <table.PaginationControls />\n * </table.AppTable>\n * )\n * }\n * ```\n */\nexport function createTableHook<\n TFeatures extends TableFeatures,\n const TTableComponents extends Record<string, ComponentType<any>>,\n const TCellComponents extends Record<string, ComponentType<any>>,\n const THeaderComponents extends Record<string, ComponentType<any>>,\n>({\n tableComponents,\n cellComponents,\n headerComponents,\n ...defaultTableOptions\n}: CreateTableHookOptions<\n TFeatures,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n>) {\n // Create contexts internally with TFeatures baked in\n const TableContext = createContext<PreactTable<TFeatures, any, any>>(\n null as never,\n )\n const CellContext = createContext<Cell<TFeatures, any, any>>(null as never)\n const HeaderContext = createContext<Header<TFeatures, any, any>>(\n null as never,\n )\n\n /**\n * Create a column helper pre-bound to the features and components configured in this table hook.\n * The cell, header, and footer contexts include pre-bound components (e.g., `cell.TextCell`).\n * @example\n * ```tsx\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * const columns = [\n * columnHelper.accessor('firstName', {\n * header: 'First Name',\n * cell: ({ cell }) => <cell.TextCell />, // cell has pre-bound components!\n * }),\n * columnHelper.accessor('age', {\n * header: 'Age',\n * cell: ({ cell }) => <cell.NumberCell />,\n * }),\n * ]\n * ```\n */\n function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n > {\n // The runtime implementation is the same - components are attached at render time\n // This cast provides the enhanced types for column definitions\n return coreCreateColumnHelper<TFeatures, TData>() as AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >\n }\n\n /**\n * Access the table instance from within an `AppTable` wrapper.\n * Use this in custom `tableComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function PaginationControls() {\n * const table = useTableContext()\n * return (\n * <table.Subscribe selector={(s) => s.pagination}>\n * {(pagination) => (\n * <div>\n * <button onClick={() => table.previousPage()}>Prev</button>\n * <span>Page {pagination.pageIndex + 1}</span>\n * <button onClick={() => table.nextPage()}>Next</button>\n * </div>\n * )}\n * </table.Subscribe>\n * )\n * }\n * ```\n */\n function useTableContext<TData extends RowData = RowData>(): PreactTable<\n TFeatures,\n TData\n > {\n const table = useContext(TableContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!table) {\n throw new Error(\n '`useTableContext` must be used within an `AppTable` component. ' +\n 'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.',\n )\n }\n\n return table as PreactTable<TFeatures, TData>\n }\n\n /**\n * Access the cell instance from within an `AppCell` wrapper.\n * Use this in custom `cellComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function TextCell() {\n * const cell = useCellContext<string>()\n * return <span>{cell.getValue()}</span>\n * }\n *\n * function NumberCell({ format }: { format?: Intl.NumberFormatOptions }) {\n * const cell = useCellContext<number>()\n * return <span>{cell.getValue().toLocaleString(undefined, format)}</span>\n * }\n * ```\n */\n function useCellContext<TValue extends CellData = CellData>() {\n const cell = useContext(CellContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!cell) {\n throw new Error(\n '`useCellContext` must be used within an `AppCell` component. ' +\n 'Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.',\n )\n }\n\n return cell as Cell<TFeatures, any, TValue>\n }\n\n /**\n * Access the header instance from within an `AppHeader` or `AppFooter` wrapper.\n * Use this in custom `headerComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function SortIndicator() {\n * const header = useHeaderContext()\n * const sorted = header.column.getIsSorted()\n * return sorted === 'asc' ? '🔼' : sorted === 'desc' ? '🔽' : null\n * }\n *\n * function ColumnFilter() {\n * const header = useHeaderContext()\n * if (!header.column.getCanFilter()) return null\n * return (\n * <input\n * value={(header.column.getFilterValue() ?? '') as string}\n * onChange={(e) => header.column.setFilterValue(e.target.value)}\n * placeholder=\"Filter...\"\n * />\n * )\n * }\n * ```\n */\n function useHeaderContext<TValue extends CellData = CellData>() {\n const header = useContext(HeaderContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!header) {\n throw new Error(\n '`useHeaderContext` must be used within an `AppHeader` or `AppFooter` component.',\n )\n }\n\n return header as Header<TFeatures, any, TValue>\n }\n\n /**\n * Context-aware FlexRender component for cells.\n * Uses the cell from context, so no need to pass cell prop.\n */\n function CellFlexRender() {\n const cell = useCellContext()\n return <FlexRender cell={cell} />\n }\n\n /**\n * Context-aware FlexRender component for headers.\n * Uses the header from context, so no need to pass header prop.\n */\n function HeaderFlexRender() {\n const header = useHeaderContext()\n return <FlexRender header={header} />\n }\n\n /**\n * Context-aware FlexRender component for footers.\n * Uses the header from context, so no need to pass footer prop.\n */\n function FooterFlexRender() {\n const header = useHeaderContext()\n return <FlexRender footer={header} />\n }\n\n /**\n * Enhanced useTable hook that returns a table with App wrapper components\n * and pre-bound tableComponents attached directly to the table object.\n *\n * Default options from createTableHook are automatically merged with\n * the options passed here. Options passed here take precedence.\n *\n * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.\n */\n function useAppTable<TData extends RowData, TSelected = {}>(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: (state: TableState<TFeatures>) => TSelected,\n ): AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n > {\n // Merge default options with provided options (provided takes precedence)\n const table = useTable<TFeatures, TData, TSelected>(\n { ...defaultTableOptions, ...tableOptions } as TableOptions<\n TFeatures,\n TData\n >,\n selector,\n )\n\n // AppTable - Root wrapper that provides table context with optional Subscribe\n const AppTable = useMemo(() => {\n function AppTableImpl(\n props: AppTablePropsWithoutSelector,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props: AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props:\n | AppTablePropsWithoutSelector\n | AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren {\n const { children, selector: appTableSelector } = props as any\n\n return (\n <TableContext.Provider value={table}>\n {appTableSelector ? (\n <table.Subscribe selector={appTableSelector}>\n {(state: TAppTableSelected) =>\n (children as (state: TAppTableSelected) => ComponentChildren)(\n state,\n )\n }\n </table.Subscribe>\n ) : (\n children\n )}\n </TableContext.Provider>\n )\n }\n return AppTableImpl as AppTableComponent<TFeatures>\n }, [table])\n\n // AppCell - Wraps cell with context, pre-bound cellComponents, and optional Subscribe\n const AppCell = useMemo(() => {\n function AppCellImpl<TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props:\n | AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >\n | AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren {\n const { cell, children, selector: appCellSelector } = props as any\n const extendedCell = Object.assign(cell, {\n FlexRender: CellFlexRender,\n ...cellComponents,\n })\n\n return (\n <CellContext.Provider value={cell}>\n {appCellSelector ? (\n <table.Subscribe selector={appCellSelector}>\n {(state: TAppCellSelected) =>\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & {\n FlexRender: () => ComponentChildren\n },\n state: TAppCellSelected,\n ) => ComponentChildren\n )(extendedCell, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedCell)\n )}\n </CellContext.Provider>\n )\n }\n return AppCellImpl as AppCellComponent<TFeatures, TData, TCellComponents>\n }, [table])\n\n // AppHeader - Wraps header with context, pre-bound headerComponents, and optional Subscribe\n const AppHeader = useMemo(() => {\n function AppHeaderImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appHeaderSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: HeaderFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appHeaderSelector ? (\n <table.Subscribe selector={appHeaderSelector}>\n {(state: TAppHeaderSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppHeaderSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppHeaderImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // AppFooter - Same as AppHeader (footers use Header type)\n const AppFooter = useMemo(() => {\n function AppFooterImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appFooterSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: FooterFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appFooterSelector ? (\n <table.Subscribe selector={appFooterSelector}>\n {(state: TAppFooterSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppFooterSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppFooterImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // Combine everything into the extended table API\n const extendedTable = useMemo(() => {\n return Object.assign(table, {\n AppTable,\n AppCell,\n AppHeader,\n AppFooter,\n ...tableComponents,\n }) as AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n >\n }, [table, AppTable, AppCell, AppHeader, AppFooter])\n\n return extendedTable\n }\n\n return {\n appFeatures: defaultTableOptions._features as TFeatures,\n createAppColumnHelper,\n useAppTable,\n useTableContext,\n useCellContext,\n useHeaderContext,\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"createTableHook.js","names":["coreCreateColumnHelper"],"sources":["../src/createTableHook.tsx"],"sourcesContent":["'use client'\nimport { createContext } from 'preact'\nimport { useContext, useMemo } from 'preact/hooks'\nimport { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core'\nimport { useTable } from './useTable'\nimport { FlexRender } from './FlexRender'\nimport type {\n AccessorFn,\n AccessorFnColumnDef,\n AccessorKeyColumnDef,\n Cell,\n CellContext,\n CellData,\n Column,\n ColumnDef,\n DeepKeys,\n DeepValue,\n DisplayColumnDef,\n GroupColumnDef,\n Header,\n IdentifiedColumnDef,\n NoInfer,\n Row,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren, ComponentType } from 'preact'\nimport type { PreactTable } from './useTable'\n\n// =============================================================================\n// Enhanced Context Types with Pre-bound Components\n// =============================================================================\n\n/**\n * Enhanced CellContext with pre-bound cell components.\n * The `cell` property includes the registered cellComponents.\n */\nexport type AppCellContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> = {\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren }\n column: Column<TFeatures, TData, TValue>\n getValue: CellContext<TFeatures, TData, TValue>['getValue']\n renderValue: CellContext<TFeatures, TData, TValue>['renderValue']\n row: Row<TFeatures, TData>\n table: Table<TFeatures, TData>\n}\n\n/**\n * Enhanced HeaderContext with pre-bound header components.\n * The `header` property includes the registered headerComponents.\n */\nexport type AppHeaderContext<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n column: Column<TFeatures, TData, TValue>\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren }\n table: Table<TFeatures, TData>\n}\n\n// =============================================================================\n// Enhanced Column Definition Types\n// =============================================================================\n\n/**\n * Template type for column definitions that can be a string or a function.\n */\nexport type AppColumnDefTemplate<TProps extends object> =\n | string\n | ((props: TProps) => any)\n\n/**\n * Enhanced column definition base with pre-bound components in cell/header/footer contexts.\n */\nexport type AppColumnDefBase<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n IdentifiedColumnDef<TFeatures, TData, TValue>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, TValue, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>\n >\n}\n\n/**\n * Enhanced display column definition with pre-bound components.\n */\nexport type AppDisplayColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n DisplayColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n}\n\n/**\n * Enhanced group column definition with pre-bound components.\n */\nexport type AppGroupColumnDef<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n GroupColumnDef<TFeatures, TData, unknown>,\n 'cell' | 'header' | 'footer' | 'columns'\n> & {\n cell?: AppColumnDefTemplate<\n AppCellContext<TFeatures, TData, unknown, TCellComponents>\n >\n header?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n footer?: AppColumnDefTemplate<\n AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>\n >\n columns?: Array<ColumnDef<TFeatures, TData, unknown>>\n}\n\n// =============================================================================\n// Enhanced Column Helper Type\n// =============================================================================\n\n/**\n * Enhanced column helper with pre-bound components in cell/header/footer contexts.\n * This enables TypeScript to know about the registered components when defining columns.\n */\nexport type AppColumnHelper<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = {\n /**\n * Creates a data column definition with an accessor key or function.\n * The cell, header, and footer contexts include pre-bound components.\n */\n accessor: <\n TAccessor extends AccessorFn<TData> | DeepKeys<TData>,\n TValue extends TAccessor extends AccessorFn<TData, infer TReturn>\n ? TReturn\n : TAccessor extends DeepKeys<TData>\n ? DeepValue<TData, TAccessor>\n : never,\n >(\n accessor: TAccessor,\n column: TAccessor extends AccessorFn<TData>\n ? AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n > & { id: string }\n : AppColumnDefBase<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n THeaderComponents\n >,\n ) => TAccessor extends AccessorFn<TData>\n ? AccessorFnColumnDef<TFeatures, TData, TValue>\n : AccessorKeyColumnDef<TFeatures, TData, TValue>\n\n /**\n * Wraps an array of column definitions to preserve each column's individual TValue type.\n */\n columns: <TColumns extends ReadonlyArray<ColumnDef<TFeatures, TData, any>>>(\n columns: [...TColumns],\n ) => Array<ColumnDef<TFeatures, TData, any>> & [...TColumns]\n\n /**\n * Creates a display column definition for non-data columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n display: (\n column: AppDisplayColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => DisplayColumnDef<TFeatures, TData, unknown>\n\n /**\n * Creates a group column definition with nested child columns.\n * The cell, header, and footer contexts include pre-bound components.\n */\n group: (\n column: AppGroupColumnDef<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >,\n ) => GroupColumnDef<TFeatures, TData, unknown>\n}\n\n// =============================================================================\n// CreateTableHook Options and Props\n// =============================================================================\n\n/**\n * Options for creating a table hook with pre-bound components and default table options.\n * Extends all TableOptions except 'columns' | 'data' | 'store' | 'state' | 'initialState'.\n */\nexport type CreateTableHookOptions<\n TFeatures extends TableFeatures,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = Omit<\n TableOptions<TFeatures, any>,\n 'columns' | 'data' | 'store' | 'state' | 'initialState'\n> & {\n /**\n * Table-level components that need access to the table instance.\n * These are available directly on the table object returned by useAppTable.\n * Use `useTableContext()` inside these components.\n * @example { PaginationControls, GlobalFilter, RowCount }\n */\n tableComponents?: TTableComponents\n /**\n * Cell-level components that need access to the cell instance.\n * These are available on the cell object passed to AppCell's children.\n * Use `useCellContext()` inside these components.\n * @example { TextCell, NumberCell, DateCell, CurrencyCell }\n */\n cellComponents?: TCellComponents\n /**\n * Header-level components that need access to the header instance.\n * These are available on the header object passed to AppHeader/AppFooter's children.\n * Use `useHeaderContext()` inside these components.\n * @example { SortIndicator, ColumnFilter, ResizeHandle }\n */\n headerComponents?: THeaderComponents\n}\n\n/**\n * Props for AppTable component - without selector\n */\nexport interface AppTablePropsWithoutSelector {\n children: ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppTable component - with selector\n */\nexport interface AppTablePropsWithSelector<\n TFeatures extends TableFeatures,\n TSelected,\n> {\n children: (state: TSelected) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppCell component - without selector\n */\nexport interface AppCellPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppCell component - with selector\n */\nexport interface AppCellPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n TCellComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n cell: Cell<TFeatures, TData, TValue>\n children: (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Props for AppHeader/AppFooter component - without selector\n */\nexport interface AppHeaderPropsWithoutSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n selector?: never\n}\n\n/**\n * Props for AppHeader/AppFooter component - with selector\n */\nexport interface AppHeaderPropsWithSelector<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n TSelected,\n> {\n header: Header<TFeatures, TData, TValue>\n children: (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n state: TSelected,\n ) => ComponentChildren\n selector: (state: TableState<TFeatures>) => TSelected\n}\n\n/**\n * Component type for AppCell - wraps a cell and provides cell context with optional Subscribe\n */\nexport interface AppCellComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TCellComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppHeader/AppFooter - wraps a header and provides header context with optional Subscribe\n */\nexport interface AppHeaderComponent<\n TFeatures extends TableFeatures,\n TData extends RowData,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> {\n <TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n <TValue extends CellData = CellData, TSelected = unknown>(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TSelected\n >,\n ): ComponentChildren\n}\n\n/**\n * Component type for AppTable - root wrapper with optional Subscribe\n */\nexport interface AppTableComponent<TFeatures extends TableFeatures> {\n (props: AppTablePropsWithoutSelector): ComponentChildren\n <TSelected>(\n props: AppTablePropsWithSelector<TFeatures, TSelected>,\n ): ComponentChildren\n}\n\n/**\n * Extended table API returned by useAppTable with all App wrapper components\n */\nexport type AppPreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected,\n TTableComponents extends Record<string, ComponentType<any>>,\n TCellComponents extends Record<string, ComponentType<any>>,\n THeaderComponents extends Record<string, ComponentType<any>>,\n> = PreactTable<TFeatures, TData, TSelected> &\n NoInfer<TTableComponents> & {\n /**\n * Root wrapper component that provides table context with optional Subscribe.\n * @example\n * ```tsx\n * // Without selector - children is ComponentChildren\n * <table.AppTable>\n * <table>...</table>\n * </table.AppTable>\n *\n * // With selector - children receives selected state\n * <table.AppTable selector={(s) => s.pagination}>\n * {(pagination) => <div>Page {pagination.pageIndex}</div>}\n * </table.AppTable>\n * ```\n */\n AppTable: AppTableComponent<TFeatures>\n /**\n * Wraps a cell and provides cell context with pre-bound cellComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppCell cell={cell}>\n * {(c) => <td><c.TextCell /></td>}\n * </table.AppCell>\n *\n * // With selector - children receives cell and selected state\n * <table.AppCell cell={cell} selector={(s) => s.columnFilters}>\n * {(c, filters) => <td>{filters.length}</td>}\n * </table.AppCell>\n * ```\n */\n AppCell: AppCellComponent<TFeatures, TData, NoInfer<TCellComponents>>\n /**\n * Wraps a header and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * // Without selector\n * <table.AppHeader header={header}>\n * {(h) => <th><h.SortIndicator /></th>}\n * </table.AppHeader>\n *\n * // With selector\n * <table.AppHeader header={header} selector={(s) => s.sorting}>\n * {(h, sorting) => <th>{sorting.length} sorted</th>}\n * </table.AppHeader>\n * ```\n */\n AppHeader: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n /**\n * Wraps a footer and provides header context with pre-bound headerComponents.\n * Optionally accepts a selector for Subscribe functionality.\n * @example\n * ```tsx\n * <table.AppFooter header={footer}>\n * {(f) => <td><table.FlexRender footer={footer} /></td>}\n * </table.AppFooter>\n * ```\n */\n AppFooter: AppHeaderComponent<TFeatures, TData, NoInfer<THeaderComponents>>\n }\n\n/**\n * Creates a custom table hook with pre-bound components for composition.\n *\n * This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:\n * - Define features, row models, and default options once, shared across all tables\n * - Register reusable table, cell, and header components\n * - Access table/cell/header instances via context in those components\n * - Get a `useAppTable` hook that returns an extended table with App wrapper components\n * - Get a `createAppColumnHelper` function pre-bound to your features\n *\n * @example\n * ```tsx\n * // hooks/table.ts\n * export const {\n * useAppTable,\n * createAppColumnHelper,\n * useTableContext,\n * useCellContext,\n * useHeaderContext,\n * } = createTableHook({\n * _features: tableFeatures({\n * rowPaginationFeature,\n * rowSortingFeature,\n * columnFilteringFeature,\n * }),\n * _rowModels: {\n * paginatedRowModel: createPaginatedRowModel(),\n * sortedRowModel: createSortedRowModel(sortFns),\n * filteredRowModel: createFilteredRowModel(filterFns),\n * },\n * tableComponents: { PaginationControls, RowCount },\n * cellComponents: { TextCell, NumberCell },\n * headerComponents: { SortIndicator, ColumnFilter },\n * })\n *\n * // Create column helper with TFeatures already bound\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * // components/table-components.tsx\n * function PaginationControls() {\n * const table = useTableContext() // TFeatures already known!\n * return <table.Subscribe selector={(s) => s.pagination}>...</table.Subscribe>\n * }\n *\n * // features/users.tsx\n * function UsersTable({ data }: { data: Person[] }) {\n * const table = useAppTable({\n * columns,\n * data, // TData inferred from Person[]\n * })\n *\n * return (\n * <table.AppTable>\n * <table>\n * <thead>\n * {table.getHeaderGroups().map(headerGroup => (\n * <tr key={headerGroup.id}>\n * {headerGroup.headers.map(h => (\n * <table.AppHeader header={h} key={h.id}>\n * {(header) => (\n * <th>\n * <table.FlexRender header={h} />\n * <header.SortIndicator />\n * </th>\n * )}\n * </table.AppHeader>\n * ))}\n * </tr>\n * ))}\n * </thead>\n * <tbody>\n * {table.getRowModel().rows.map(row => (\n * <tr key={row.id}>\n * {row.getAllCells().map(c => (\n * <table.AppCell cell={c} key={c.id}>\n * {(cell) => <td><cell.TextCell /></td>}\n * </table.AppCell>\n * ))}\n * </tr>\n * ))}\n * </tbody>\n * </table>\n * <table.PaginationControls />\n * </table.AppTable>\n * )\n * }\n * ```\n */\nexport function createTableHook<\n TFeatures extends TableFeatures,\n const TTableComponents extends Record<string, ComponentType<any>>,\n const TCellComponents extends Record<string, ComponentType<any>>,\n const THeaderComponents extends Record<string, ComponentType<any>>,\n>({\n tableComponents,\n cellComponents,\n headerComponents,\n ...defaultTableOptions\n}: CreateTableHookOptions<\n TFeatures,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n>) {\n // Create contexts internally with TFeatures baked in\n const TableContext = createContext<PreactTable<TFeatures, any, any>>(\n null as never,\n )\n const CellContext = createContext<Cell<TFeatures, any, any>>(null as never)\n const HeaderContext = createContext<Header<TFeatures, any, any>>(\n null as never,\n )\n\n /**\n * Create a column helper pre-bound to the features and components configured in this table hook.\n * The cell, header, and footer contexts include pre-bound components (e.g., `cell.TextCell`).\n * @example\n * ```tsx\n * const columnHelper = createAppColumnHelper<Person>()\n *\n * const columns = [\n * columnHelper.accessor('firstName', {\n * header: 'First Name',\n * cell: ({ cell }) => <cell.TextCell />, // cell has pre-bound components!\n * }),\n * columnHelper.accessor('age', {\n * header: 'Age',\n * cell: ({ cell }) => <cell.NumberCell />,\n * }),\n * ]\n * ```\n */\n function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n > {\n // The runtime implementation is the same - components are attached at render time\n // This cast provides the enhanced types for column definitions\n return coreCreateColumnHelper<TFeatures, TData>() as AppColumnHelper<\n TFeatures,\n TData,\n TCellComponents,\n THeaderComponents\n >\n }\n\n /**\n * Access the table instance from within an `AppTable` wrapper.\n * Use this in custom `tableComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function PaginationControls() {\n * const table = useTableContext()\n * return (\n * <table.Subscribe selector={(s) => s.pagination}>\n * {(pagination) => (\n * <div>\n * <button onClick={() => table.previousPage()}>Prev</button>\n * <span>Page {pagination.pageIndex + 1}</span>\n * <button onClick={() => table.nextPage()}>Next</button>\n * </div>\n * )}\n * </table.Subscribe>\n * )\n * }\n * ```\n */\n function useTableContext<TData extends RowData = RowData>(): PreactTable<\n TFeatures,\n TData\n > {\n const table = useContext(TableContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!table) {\n throw new Error(\n '`useTableContext` must be used within an `AppTable` component. ' +\n 'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.',\n )\n }\n\n return table as PreactTable<TFeatures, TData>\n }\n\n /**\n * Access the cell instance from within an `AppCell` wrapper.\n * Use this in custom `cellComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function TextCell() {\n * const cell = useCellContext<string>()\n * return <span>{cell.getValue()}</span>\n * }\n *\n * function NumberCell({ format }: { format?: Intl.NumberFormatOptions }) {\n * const cell = useCellContext<number>()\n * return <span>{cell.getValue().toLocaleString(undefined, format)}</span>\n * }\n * ```\n */\n function useCellContext<TValue extends CellData = CellData>() {\n const cell = useContext(CellContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!cell) {\n throw new Error(\n '`useCellContext` must be used within an `AppCell` component. ' +\n 'Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.',\n )\n }\n\n return cell as Cell<TFeatures, any, TValue>\n }\n\n /**\n * Access the header instance from within an `AppHeader` or `AppFooter` wrapper.\n * Use this in custom `headerComponents` passed to `createTableHook`.\n * TFeatures is already known from the createTableHook call.\n *\n * @example\n * ```tsx\n * function SortIndicator() {\n * const header = useHeaderContext()\n * const sorted = header.column.getIsSorted()\n * return sorted === 'asc' ? '🔼' : sorted === 'desc' ? '🔽' : null\n * }\n *\n * function ColumnFilter() {\n * const header = useHeaderContext()\n * if (!header.column.getCanFilter()) return null\n * return (\n * <input\n * value={(header.column.getFilterValue() ?? '') as string}\n * onChange={(e) => header.column.setFilterValue(e.target.value)}\n * placeholder=\"Filter...\"\n * />\n * )\n * }\n * ```\n */\n function useHeaderContext<TValue extends CellData = CellData>() {\n const header = useContext(HeaderContext)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!header) {\n throw new Error(\n '`useHeaderContext` must be used within an `AppHeader` or `AppFooter` component.',\n )\n }\n\n return header as Header<TFeatures, any, TValue>\n }\n\n /**\n * Context-aware FlexRender component for cells.\n * Uses the cell from context, so no need to pass cell prop.\n */\n function CellFlexRender() {\n const cell = useCellContext()\n return <FlexRender cell={cell} />\n }\n\n /**\n * Context-aware FlexRender component for headers.\n * Uses the header from context, so no need to pass header prop.\n */\n function HeaderFlexRender() {\n const header = useHeaderContext()\n return <FlexRender header={header} />\n }\n\n /**\n * Context-aware FlexRender component for footers.\n * Uses the header from context, so no need to pass footer prop.\n */\n function FooterFlexRender() {\n const header = useHeaderContext()\n return <FlexRender footer={header} />\n }\n\n /**\n * Enhanced useTable hook that returns a table with App wrapper components\n * and pre-bound tableComponents attached directly to the table object.\n *\n * Default options from createTableHook are automatically merged with\n * the options passed here. Options passed here take precedence.\n *\n * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.\n */\n function useAppTable<\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n >(\n tableOptions: Omit<\n TableOptions<TFeatures, TData>,\n '_features' | '_rowModels'\n >,\n selector?: (state: TableState<TFeatures>) => TSelected,\n ): AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n > {\n // Merge default options with provided options (provided takes precedence)\n const table = useTable<TFeatures, TData, TSelected>(\n { ...defaultTableOptions, ...tableOptions } as TableOptions<\n TFeatures,\n TData\n >,\n selector,\n )\n\n // AppTable - Root wrapper that provides table context with optional Subscribe\n const AppTable = useMemo(() => {\n function AppTableImpl(\n props: AppTablePropsWithoutSelector,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props: AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren\n function AppTableImpl<TAppTableSelected>(\n props:\n | AppTablePropsWithoutSelector\n | AppTablePropsWithSelector<TFeatures, TAppTableSelected>,\n ): ComponentChildren {\n const { children, selector: appTableSelector } = props as any\n\n return (\n <TableContext.Provider value={table}>\n {appTableSelector ? (\n <table.Subscribe selector={appTableSelector}>\n {(state: TAppTableSelected) =>\n (children as (state: TAppTableSelected) => ComponentChildren)(\n state,\n )\n }\n </table.Subscribe>\n ) : (\n children\n )}\n </TableContext.Provider>\n )\n }\n return AppTableImpl as AppTableComponent<TFeatures>\n }, [table])\n\n // AppCell - Wraps cell with context, pre-bound cellComponents, and optional Subscribe\n const AppCell = useMemo(() => {\n function AppCellImpl<TValue extends CellData = CellData>(\n props: AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props: AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren\n function AppCellImpl<\n TValue extends CellData = CellData,\n TAppCellSelected = unknown,\n >(\n props:\n | AppCellPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents\n >\n | AppCellPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n TCellComponents,\n TAppCellSelected\n >,\n ): ComponentChildren {\n const { cell, children, selector: appCellSelector } = props as any\n const extendedCell = Object.assign(cell, {\n FlexRender: CellFlexRender,\n ...cellComponents,\n })\n\n return (\n <CellContext.Provider value={cell}>\n {appCellSelector ? (\n <table.Subscribe selector={appCellSelector}>\n {(state: TAppCellSelected) =>\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & {\n FlexRender: () => ComponentChildren\n },\n state: TAppCellSelected,\n ) => ComponentChildren\n )(extendedCell, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n cell: Cell<TFeatures, TData, TValue> &\n TCellComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedCell)\n )}\n </CellContext.Provider>\n )\n }\n return AppCellImpl as AppCellComponent<TFeatures, TData, TCellComponents>\n }, [table])\n\n // AppHeader - Wraps header with context, pre-bound headerComponents, and optional Subscribe\n const AppHeader = useMemo(() => {\n function AppHeaderImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren\n function AppHeaderImpl<\n TValue extends CellData = CellData,\n TAppHeaderSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppHeaderSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appHeaderSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: HeaderFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appHeaderSelector ? (\n <table.Subscribe selector={appHeaderSelector}>\n {(state: TAppHeaderSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppHeaderSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppHeaderImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // AppFooter - Same as AppHeader (footers use Header type)\n const AppFooter = useMemo(() => {\n function AppFooterImpl<TValue extends CellData = CellData>(\n props: AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props: AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren\n function AppFooterImpl<\n TValue extends CellData = CellData,\n TAppFooterSelected = unknown,\n >(\n props:\n | AppHeaderPropsWithoutSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents\n >\n | AppHeaderPropsWithSelector<\n TFeatures,\n TData,\n TValue,\n THeaderComponents,\n TAppFooterSelected\n >,\n ): ComponentChildren {\n const { header, children, selector: appFooterSelector } = props as any\n const extendedHeader = Object.assign(header, {\n FlexRender: FooterFlexRender,\n ...headerComponents,\n })\n\n return (\n <HeaderContext.Provider value={header}>\n {appFooterSelector ? (\n <table.Subscribe selector={appFooterSelector}>\n {(state: TAppFooterSelected) =>\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents,\n state: TAppFooterSelected,\n ) => ComponentChildren\n )(extendedHeader, state)\n }\n </table.Subscribe>\n ) : (\n (\n children as (\n header: Header<TFeatures, TData, TValue> &\n THeaderComponents & { FlexRender: () => ComponentChildren },\n ) => ComponentChildren\n )(extendedHeader)\n )}\n </HeaderContext.Provider>\n )\n }\n return AppFooterImpl as AppHeaderComponent<\n TFeatures,\n TData,\n THeaderComponents\n >\n }, [table])\n\n // Combine everything into the extended table API\n const extendedTable = useMemo(() => {\n return Object.assign(table, {\n AppTable,\n AppCell,\n AppHeader,\n AppFooter,\n ...tableComponents,\n }) as AppPreactTable<\n TFeatures,\n TData,\n TSelected,\n TTableComponents,\n TCellComponents,\n THeaderComponents\n >\n }, [table, AppTable, AppCell, AppHeader, AppFooter])\n\n return extendedTable\n }\n\n return {\n appFeatures: defaultTableOptions._features as TFeatures,\n createAppColumnHelper,\n useAppTable,\n useTableContext,\n useCellContext,\n useHeaderContext,\n }\n}\n"],"mappings":"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"}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FlexRender, FlexRenderProps, Renderable, flexRender } from "./FlexRender.cjs";
2
- import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore } from "./Subscribe.cjs";
2
+ import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource } from "./Subscribe.cjs";
3
3
  import { PreactTable, useTable } from "./useTable.cjs";
4
4
  import { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, createTableHook } from "./createTableHook.cjs";
5
5
  export * from "@tanstack/table-core";
6
- export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, PreactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
6
+ export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, PreactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource, createTableHook, flexRender, useTable };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FlexRender, FlexRenderProps, Renderable, flexRender } from "./FlexRender.js";
2
- import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore } from "./Subscribe.js";
2
+ import { Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource } from "./Subscribe.js";
3
3
  import { PreactTable, useTable } from "./useTable.js";
4
4
  import { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, createTableHook } from "./createTableHook.js";
5
5
  export * from "@tanstack/table-core";
6
- export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, PreactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, createTableHook, flexRender, useTable };
6
+ export { AppCellComponent, AppCellContext, AppCellPropsWithSelector, AppCellPropsWithoutSelector, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderComponent, AppHeaderContext, AppHeaderPropsWithSelector, AppHeaderPropsWithoutSelector, AppPreactTable, AppTableComponent, AppTablePropsWithSelector, AppTablePropsWithoutSelector, CreateTableHookOptions, FlexRender, FlexRenderProps, PreactTable, Renderable, Subscribe, SubscribeProps, SubscribePropsWithSource, SubscribePropsWithSourceIdentity, SubscribePropsWithSourceWithSelector, SubscribePropsWithStore, SubscribeSource, createTableHook, flexRender, useTable };
package/dist/useTable.cjs CHANGED
@@ -6,7 +6,7 @@ let _tanstack_preact_store = require("@tanstack/preact-store");
6
6
  let preact_hooks = require("preact/hooks");
7
7
 
8
8
  //#region src/useTable.ts
9
- function useTable(tableOptions, selector = () => ({})) {
9
+ function useTable(tableOptions, selector) {
10
10
  const [table] = (0, preact_hooks.useState)(() => {
11
11
  const tableInstance = (0, _tanstack_table_core.constructTable)({
12
12
  ...tableOptions,
@@ -16,9 +16,10 @@ function useTable(tableOptions, selector = () => ({})) {
16
16
  }
17
17
  });
18
18
  tableInstance.Subscribe = ((props) => {
19
+ const source = props.source ?? tableInstance.store;
19
20
  return require_Subscribe.Subscribe({
20
21
  ...props,
21
- table: tableInstance
22
+ source
22
23
  });
23
24
  });
24
25
  tableInstance.FlexRender = require_FlexRender.FlexRender;
@@ -1 +1 @@
1
- {"version":3,"file":"useTable.cjs","names":["preactReactivity","Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { preactReactivity } from './reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/preact-store'\nimport type { ComponentChildren } from 'preact'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type PreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (source first, then store) so JSX contextual typing works for both modes.\n * Source without `selector` is separate so children infer `TSourceValue` (identity projection).\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ComponentChildren\n }\n /**\n * A Preact component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ComponentChildren\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n */\n readonly state: Readonly<TSelected>\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): PreactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: preactReactivity(),\n ...tableOptions._features,\n },\n }) as PreactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as PreactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n )\n}\n"],"mappings":";;;;;;;;AAkFA,SAAgB,SAKd,cACA,kBACG,EAAE,GACqC;CAC1C,MAAM,CAAC,0CAAwB;EAC7B,MAAM,yDAA+B;GACnC,GAAG;GACH,WAAW;IACT,sBAAsBA,qCAAkB;IACxC,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;AACzC,UAAOC,4BAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,gDAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,gCAAS,CAAC;AAEtE,yCACS;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
1
+ {"version":3,"file":"useTable.cjs","names":["preactReactivity","Subscribe","FlexRender","shallow"],"sources":["../src/useTable.ts"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { preactReactivity } from './reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren } from 'preact'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'\n\nexport type PreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n> = Table<TFeatures, TData> & {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (source first, then store) so JSX contextual typing works for both modes.\n * Source without `selector` is separate so children infer `TSourceValue` (identity projection).\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSourceValue, TSubSelected>(props: {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSubSelected>(\n props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,\n ): ComponentChildren\n }\n /**\n * A Preact component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ComponentChildren\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n */\n readonly state: Readonly<TSelected>\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector?: (state: TableState<TFeatures>) => TSelected,\n): PreactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: preactReactivity(),\n ...tableOptions._features,\n },\n }) as PreactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n const source = props.source ?? tableInstance.store\n\n return Subscribe({\n ...props,\n source,\n })\n }) as PreactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n )\n}\n"],"mappings":";;;;;;;;AA8EA,SAAgB,SAKd,cACA,UAC0C;CAC1C,MAAM,CAAC,0CAAwB;EAC7B,MAAM,yDAA+B;GACnC,GAAG;GACH,WAAW;IACT,sBAAsBA,qCAAkB;IACxC,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;GACzC,MAAM,SAAS,MAAM,UAAU,cAAc;AAE7C,UAAOC,4BAAU;IACf,GAAG;IACH;IACD,CAAC;;AAGJ,gBAAc,aAAaC;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,gDAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,gCAAS,CAAC;AAEtE,yCACS;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
@@ -1,11 +1,10 @@
1
1
  import { FlexRenderProps } from "./FlexRender.cjs";
2
- import { SubscribePropsWithStore } from "./Subscribe.cjs";
2
+ import { SubscribePropsWithStore, SubscribeSource } from "./Subscribe.cjs";
3
3
  import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
4
4
  import { ComponentChildren } from "preact";
5
- import { Atom, ReadonlyAtom } from "@tanstack/preact-store";
6
5
 
7
6
  //#region src/useTable.d.ts
8
- type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
7
+ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>> = Table<TFeatures, TData> & {
9
8
  /**
10
9
  * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.
11
10
  *
@@ -35,16 +34,16 @@ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelect
35
34
  */
36
35
  Subscribe: {
37
36
  <TSourceValue>(props: {
38
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
37
+ source: SubscribeSource<TSourceValue>;
39
38
  selector?: undefined;
40
39
  children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren;
41
40
  }): ComponentChildren;
42
41
  <TSourceValue, TSubSelected>(props: {
43
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
42
+ source: SubscribeSource<TSourceValue>;
44
43
  selector: (state: TSourceValue) => TSubSelected;
45
44
  children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren;
46
45
  }): ComponentChildren;
47
- <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ComponentChildren;
46
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>): ComponentChildren;
48
47
  };
49
48
  /**
50
49
  * A Preact component that renders headers, cells, or footers with custom markup.
@@ -56,7 +55,7 @@ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelect
56
55
  */
57
56
  readonly state: Readonly<TSelected>;
58
57
  };
59
- declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): PreactTable<TFeatures, TData, TSelected>;
58
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): PreactTable<TFeatures, TData, TSelected>;
60
59
  //#endregion
61
60
  export { PreactTable, useTable };
62
61
  //# sourceMappingURL=useTable.d.cts.map
@@ -1,11 +1,10 @@
1
1
  import { FlexRenderProps } from "./FlexRender.js";
2
- import { SubscribePropsWithStore } from "./Subscribe.js";
2
+ import { SubscribePropsWithStore, SubscribeSource } from "./Subscribe.js";
3
3
  import { CellData, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
4
- import { Atom, ReadonlyAtom } from "@tanstack/preact-store";
5
4
  import { ComponentChildren } from "preact";
6
5
 
7
6
  //#region src/useTable.d.ts
8
- type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
7
+ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>> = Table<TFeatures, TData> & {
9
8
  /**
10
9
  * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.
11
10
  *
@@ -35,16 +34,16 @@ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelect
35
34
  */
36
35
  Subscribe: {
37
36
  <TSourceValue>(props: {
38
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
37
+ source: SubscribeSource<TSourceValue>;
39
38
  selector?: undefined;
40
39
  children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren;
41
40
  }): ComponentChildren;
42
41
  <TSourceValue, TSubSelected>(props: {
43
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>;
42
+ source: SubscribeSource<TSourceValue>;
44
43
  selector: (state: TSourceValue) => TSubSelected;
45
44
  children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren;
46
45
  }): ComponentChildren;
47
- <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TData, TSubSelected>, 'table'>): ComponentChildren;
46
+ <TSubSelected>(props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>): ComponentChildren;
48
47
  };
49
48
  /**
50
49
  * A Preact component that renders headers, cells, or footers with custom markup.
@@ -56,7 +55,7 @@ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelect
56
55
  */
57
56
  readonly state: Readonly<TSelected>;
58
57
  };
59
- declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): PreactTable<TFeatures, TData, TSelected>;
58
+ declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): PreactTable<TFeatures, TData, TSelected>;
60
59
  //#endregion
61
60
  export { PreactTable, useTable };
62
61
  //# sourceMappingURL=useTable.d.ts.map
package/dist/useTable.js CHANGED
@@ -6,7 +6,7 @@ import { shallow, useSelector } from "@tanstack/preact-store";
6
6
  import { useMemo, useState } from "preact/hooks";
7
7
 
8
8
  //#region src/useTable.ts
9
- function useTable(tableOptions, selector = () => ({})) {
9
+ function useTable(tableOptions, selector) {
10
10
  const [table] = useState(() => {
11
11
  const tableInstance = constructTable({
12
12
  ...tableOptions,
@@ -16,9 +16,10 @@ function useTable(tableOptions, selector = () => ({})) {
16
16
  }
17
17
  });
18
18
  tableInstance.Subscribe = ((props) => {
19
+ const source = props.source ?? tableInstance.store;
19
20
  return Subscribe({
20
21
  ...props,
21
- table: tableInstance
22
+ source
22
23
  });
23
24
  });
24
25
  tableInstance.FlexRender = FlexRender;
@@ -1 +1 @@
1
- {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { preactReactivity } from './reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { Atom, ReadonlyAtom } from '@tanstack/preact-store'\nimport type { ComponentChildren } from 'preact'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore } from './Subscribe'\n\nexport type PreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (source first, then store) so JSX contextual typing works for both modes.\n * Source without `selector` is separate so children infer `TSourceValue` (identity projection).\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSourceValue, TSubSelected>(props: {\n source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSubSelected>(\n props: Omit<\n SubscribePropsWithStore<TFeatures, TData, TSubSelected>,\n 'table'\n >,\n ): ComponentChildren\n }\n /**\n * A Preact component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ComponentChildren\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n */\n readonly state: Readonly<TSelected>\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): PreactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: preactReactivity(),\n ...tableOptions._features,\n },\n }) as PreactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n return Subscribe({\n ...props,\n table: tableInstance,\n })\n }) as PreactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n )\n}\n"],"mappings":";;;;;;;;AAkFA,SAAgB,SAKd,cACA,kBACG,EAAE,GACqC;CAC1C,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe;GACnC,GAAG;GACH,WAAW;IACT,sBAAsB,kBAAkB;IACxC,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;AACzC,UAAO,UAAU;IACf,GAAG;IACH,OAAO;IACR,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAEtE,QAAO,eACE;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
1
+ {"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { preactReactivity } from './reactivity'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { ComponentChildren } from 'preact'\nimport type { FlexRenderProps } from './FlexRender'\nimport type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'\n\nexport type PreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n> = Table<TFeatures, TData> & {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * Pass `source` to subscribe to a single atom or store (e.g. `table.atoms.rowSelection`\n * or `table.optionsStore`) instead of the full `table.store`.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => (\n * <tr key={row.id}>...</tr>\n * )}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection}>\n * {(rowSelection) => <div>...</div>}\n * </table.Subscribe>\n *\n * @example\n * <table.Subscribe source={table.atoms.rowSelection} selector={(s) => s?.[row.id]}>\n * {() => <tr key={row.id}>...</tr>}\n * </table.Subscribe>\n */\n /**\n * Overloads (source first, then store) so JSX contextual typing works for both modes.\n * Source without `selector` is separate so children infer `TSourceValue` (identity projection).\n */\n Subscribe: {\n <TSourceValue>(props: {\n source: SubscribeSource<TSourceValue>\n selector?: undefined\n children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSourceValue, TSubSelected>(props: {\n source: SubscribeSource<TSourceValue>\n selector: (state: TSourceValue) => TSubSelected\n children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren\n }): ComponentChildren\n <TSubSelected>(\n props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,\n ): ComponentChildren\n }\n /**\n * A Preact component that renders headers, cells, or footers with custom markup.\n * Use this utility component instead of manually calling flexRender.\n */\n FlexRender: <TValue extends CellData = CellData>(\n props: FlexRenderProps<TFeatures, TData, TValue>,\n ) => ComponentChildren\n /**\n * The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.\n */\n readonly state: Readonly<TSelected>\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = TableState<TFeatures>,\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector?: (state: TableState<TFeatures>) => TSelected,\n): PreactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable({\n ...tableOptions,\n _features: {\n coreReativityFeature: preactReactivity(),\n ...tableOptions._features,\n },\n }) as PreactTable<TFeatures, TData, TSelected>\n\n tableInstance.Subscribe = ((props: any) => {\n const source = props.source ?? tableInstance.store\n\n return Subscribe({\n ...props,\n source,\n })\n }) as PreactTable<TFeatures, TData, TSelected>['Subscribe']\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const state = useSelector(table.store, selector, { compare: shallow })\n\n return useMemo(\n () => ({\n ...table,\n options: tableOptions,\n state,\n }),\n [table, tableOptions, state],\n )\n}\n"],"mappings":";;;;;;;;AA8EA,SAAgB,SAKd,cACA,UAC0C;CAC1C,MAAM,CAAC,SAAS,eAAe;EAC7B,MAAM,gBAAgB,eAAe;GACnC,GAAG;GACH,WAAW;IACT,sBAAsB,kBAAkB;IACxC,GAAG,aAAa;IACjB;GACF,CAAC;AAEF,gBAAc,cAAc,UAAe;GACzC,MAAM,SAAS,MAAM,UAAU,cAAc;AAE7C,UAAO,UAAU;IACf,GAAG;IACH;IACD,CAAC;;AAGJ,gBAAc,aAAa;AAE3B,SAAO;GACP;AAGF,OAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAEtE,QAAO,eACE;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/preact-table",
3
- "version": "9.0.0-alpha.43",
3
+ "version": "9.0.0-alpha.45",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Preact.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/Subscribe.ts CHANGED
@@ -1,23 +1,28 @@
1
1
  import { shallow, useSelector } from '@tanstack/preact-store'
2
- import type { Atom, ReadonlyAtom } from '@tanstack/preact-store'
3
2
  import type {
4
- RowData,
5
- Table,
6
- TableFeatures,
7
- TableState,
8
- } from '@tanstack/table-core'
3
+ Atom,
4
+ ReadonlyAtom,
5
+ ReadonlyStore,
6
+ Store,
7
+ } from '@tanstack/preact-store'
8
+ import type { TableFeatures, TableState } from '@tanstack/table-core'
9
9
  import type { ComponentChildren } from 'preact'
10
10
 
11
+ export type SubscribeSource<TValue> =
12
+ | Atom<TValue>
13
+ | ReadonlyAtom<TValue>
14
+ | Store<TValue>
15
+ | ReadonlyStore<TValue>
16
+
11
17
  /**
12
18
  * Subscribe to `table.store` (full table state). The selector receives the full
13
19
  * {@link TableState}.
14
20
  */
15
21
  export type SubscribePropsWithStore<
16
22
  TFeatures extends TableFeatures,
17
- TData extends RowData,
18
23
  TSelected,
19
24
  > = {
20
- table: Table<TFeatures, TData>
25
+ source: SubscribeSource<TableState<TFeatures>>
21
26
  /**
22
27
  * Select from full table state. Re-renders when the selected value changes
23
28
  * (shallow compare).
@@ -34,13 +39,8 @@ export type SubscribePropsWithStore<
34
39
  * `table.optionsStore`). Omitting `selector` is equivalent to the identity
35
40
  * selector — children receive `TSourceValue`.
36
41
  */
37
- export type SubscribePropsWithSourceIdentity<
38
- TFeatures extends TableFeatures,
39
- TData extends RowData,
40
- TSourceValue,
41
- > = {
42
- table: Table<TFeatures, TData>
43
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
42
+ export type SubscribePropsWithSourceIdentity<TSourceValue> = {
43
+ source: SubscribeSource<TSourceValue>
44
44
  selector?: undefined
45
45
  children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren
46
46
  }
@@ -48,14 +48,8 @@ export type SubscribePropsWithSourceIdentity<
48
48
  /**
49
49
  * Subscribe to a projected value from a source (atom or store).
50
50
  */
51
- export type SubscribePropsWithSourceWithSelector<
52
- TFeatures extends TableFeatures,
53
- TData extends RowData,
54
- TSourceValue,
55
- TSelected,
56
- > = {
57
- table: Table<TFeatures, TData>
58
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
51
+ export type SubscribePropsWithSourceWithSelector<TSourceValue, TSelected> = {
52
+ source: SubscribeSource<TSourceValue>
59
53
  selector: (state: TSourceValue) => TSelected
60
54
  children: ((state: TSelected) => ComponentChildren) | ComponentChildren
61
55
  }
@@ -63,34 +57,18 @@ export type SubscribePropsWithSourceWithSelector<
63
57
  /**
64
58
  * Subscribe to a single source — atom or store (identity or projected).
65
59
  */
66
- export type SubscribePropsWithSource<
67
- TFeatures extends TableFeatures,
68
- TData extends RowData,
69
- TSourceValue,
70
- TSelected = TSourceValue,
71
- > =
72
- | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>
73
- | SubscribePropsWithSourceWithSelector<
74
- TFeatures,
75
- TData,
76
- TSourceValue,
77
- TSelected
78
- >
60
+ export type SubscribePropsWithSource<TSourceValue, TSelected = TSourceValue> =
61
+ | SubscribePropsWithSourceIdentity<TSourceValue>
62
+ | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>
79
63
 
80
64
  export type SubscribeProps<
81
65
  TFeatures extends TableFeatures,
82
- TData extends RowData,
83
66
  TSelected = unknown,
84
67
  TSourceValue = unknown,
85
68
  > =
86
- | SubscribePropsWithStore<TFeatures, TData, TSelected>
87
- | SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>
88
- | SubscribePropsWithSourceWithSelector<
89
- TFeatures,
90
- TData,
91
- TSourceValue,
92
- TSelected
93
- >
69
+ | SubscribePropsWithStore<TFeatures, TSelected>
70
+ | SubscribePropsWithSourceIdentity<TSourceValue>
71
+ | SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>
94
72
 
95
73
  /**
96
74
  * A Preact component that allows you to subscribe to the table state.
@@ -98,48 +76,25 @@ export type SubscribeProps<
98
76
  * For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so
99
77
  * JSX contextual typing works. This standalone component uses a union `props` type.
100
78
  */
101
- export function Subscribe<
102
- TFeatures extends TableFeatures,
103
- TData extends RowData,
104
- TSourceValue,
105
- >(
106
- props: SubscribePropsWithSourceIdentity<TFeatures, TData, TSourceValue>,
79
+ export function Subscribe<TSourceValue>(
80
+ props: SubscribePropsWithSourceIdentity<TSourceValue>,
107
81
  ): ComponentChildren
108
- export function Subscribe<
109
- TFeatures extends TableFeatures,
110
- TData extends RowData,
111
- TSourceValue,
112
- TSelected,
113
- >(
114
- props: SubscribePropsWithSourceWithSelector<
115
- TFeatures,
116
- TData,
117
- TSourceValue,
118
- TSelected
119
- >,
82
+ export function Subscribe<TSourceValue, TSelected>(
83
+ props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>,
120
84
  ): ComponentChildren
121
- export function Subscribe<
122
- TFeatures extends TableFeatures,
123
- TData extends RowData,
124
- TSelected,
125
- >(
126
- props: SubscribePropsWithStore<TFeatures, TData, TSelected>,
85
+ export function Subscribe<TFeatures extends TableFeatures, TSelected>(
86
+ props: SubscribePropsWithStore<TFeatures, TSelected>,
127
87
  ): ComponentChildren
128
88
  export function Subscribe<
129
89
  TFeatures extends TableFeatures,
130
- TData extends RowData,
131
90
  TSelected,
132
91
  TSourceValue,
133
92
  >(
134
- props: SubscribeProps<TFeatures, TData, TSelected, TSourceValue>,
93
+ props: SubscribeProps<TFeatures, TSelected, TSourceValue>,
135
94
  ): ComponentChildren {
136
- const source = 'source' in props ? props.source : props.table.store
137
- const selectFn =
138
- 'source' in props ? (props.selector ?? ((x: unknown) => x)) : props.selector
139
-
140
95
  const selected = useSelector(
141
- source as never,
142
- selectFn as Parameters<typeof useSelector>[1],
96
+ props.source as never,
97
+ props.selector as Parameters<typeof useSelector>[1],
143
98
  {
144
99
  compare: shallow,
145
100
  },
@@ -796,7 +796,10 @@ export function createTableHook<
796
796
  *
797
797
  * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.
798
798
  */
799
- function useAppTable<TData extends RowData, TSelected = {}>(
799
+ function useAppTable<
800
+ TData extends RowData,
801
+ TSelected = TableState<TFeatures>,
802
+ >(
800
803
  tableOptions: Omit<
801
804
  TableOptions<TFeatures, TData>,
802
805
  '_features' | '_rowModels'
package/src/useTable.ts CHANGED
@@ -12,15 +12,14 @@ import type {
12
12
  TableOptions,
13
13
  TableState,
14
14
  } from '@tanstack/table-core'
15
- import type { Atom, ReadonlyAtom } from '@tanstack/preact-store'
16
15
  import type { ComponentChildren } from 'preact'
17
16
  import type { FlexRenderProps } from './FlexRender'
18
- import type { SubscribePropsWithStore } from './Subscribe'
17
+ import type { SubscribePropsWithStore, SubscribeSource } from './Subscribe'
19
18
 
20
19
  export type PreactTable<
21
20
  TFeatures extends TableFeatures,
22
21
  TData extends RowData,
23
- TSelected = {},
22
+ TSelected = TableState<TFeatures>,
24
23
  > = Table<TFeatures, TData> & {
25
24
  /**
26
25
  * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.
@@ -51,20 +50,17 @@ export type PreactTable<
51
50
  */
52
51
  Subscribe: {
53
52
  <TSourceValue>(props: {
54
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
53
+ source: SubscribeSource<TSourceValue>
55
54
  selector?: undefined
56
55
  children: ((state: TSourceValue) => ComponentChildren) | ComponentChildren
57
56
  }): ComponentChildren
58
57
  <TSourceValue, TSubSelected>(props: {
59
- source: Atom<TSourceValue> | ReadonlyAtom<TSourceValue>
58
+ source: SubscribeSource<TSourceValue>
60
59
  selector: (state: TSourceValue) => TSubSelected
61
60
  children: ((state: TSubSelected) => ComponentChildren) | ComponentChildren
62
61
  }): ComponentChildren
63
62
  <TSubSelected>(
64
- props: Omit<
65
- SubscribePropsWithStore<TFeatures, TData, TSubSelected>,
66
- 'table'
67
- >,
63
+ props: Omit<SubscribePropsWithStore<TFeatures, TSubSelected>, 'source'>,
68
64
  ): ComponentChildren
69
65
  }
70
66
  /**
@@ -83,11 +79,10 @@ export type PreactTable<
83
79
  export function useTable<
84
80
  TFeatures extends TableFeatures,
85
81
  TData extends RowData,
86
- TSelected = {},
82
+ TSelected = TableState<TFeatures>,
87
83
  >(
88
84
  tableOptions: TableOptions<TFeatures, TData>,
89
- selector: (state: TableState<TFeatures>) => TSelected = () =>
90
- ({}) as TSelected,
85
+ selector?: (state: TableState<TFeatures>) => TSelected,
91
86
  ): PreactTable<TFeatures, TData, TSelected> {
92
87
  const [table] = useState(() => {
93
88
  const tableInstance = constructTable({
@@ -99,9 +94,11 @@ export function useTable<
99
94
  }) as PreactTable<TFeatures, TData, TSelected>
100
95
 
101
96
  tableInstance.Subscribe = ((props: any) => {
97
+ const source = props.source ?? tableInstance.store
98
+
102
99
  return Subscribe({
103
100
  ...props,
104
- table: tableInstance,
101
+ source,
105
102
  })
106
103
  }) as PreactTable<TFeatures, TData, TSelected>['Subscribe']
107
104