@tanstack/preact-table 9.0.0-alpha.45 → 9.0.0-alpha.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FlexRender.cjs.map +1 -1
- package/dist/FlexRender.js.map +1 -1
- package/dist/Subscribe.cjs.map +1 -1
- package/dist/Subscribe.d.cts +22 -0
- package/dist/Subscribe.d.ts +22 -0
- package/dist/Subscribe.js.map +1 -1
- package/dist/createTableHook.cjs.map +1 -1
- package/dist/createTableHook.js.map +1 -1
- package/dist/reactivity.cjs +7 -0
- package/dist/reactivity.cjs.map +1 -1
- package/dist/reactivity.js +7 -0
- package/dist/reactivity.js.map +1 -1
- package/dist/useTable.cjs +24 -0
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.d.cts +24 -0
- package/dist/useTable.d.ts +24 -0
- package/dist/useTable.js +24 -0
- package/dist/useTable.js.map +1 -1
- package/package.json +3 -3
- package/src/Subscribe.ts +22 -0
- package/src/reactivity.ts +7 -0
- package/src/useTable.ts +24 -0
package/dist/FlexRender.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlexRender.cjs","names":[],"sources":["../src/FlexRender.tsx"],"sourcesContent":["import type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentChild, ComponentType } from 'preact'\n\nexport type Renderable<TProps> = ComponentChild | ComponentType<TProps>\n\nfunction isPreactComponent<TProps>(\n component: unknown,\n): component is ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isPreactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['preact.memo', 'preact.forward_ref'].includes(\n component.$$typeof.description,\n )\n )\n}\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps> | null,\n props: TProps,\n): ComponentChild | Element | null {\n return !Comp ? null : isPreactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n const cell = props.cell\n const def = cell.column.columnDef\n // When the column-grouping feature is registered, a cell can be in one of\n // three special modes that should not render `columnDef.cell` directly:\n // - aggregated: render `columnDef.aggregatedCell` (falling back to\n // `columnDef.cell` if the column did not define one)\n // - placeholder: a duplicate value within a group — render nothing\n // - grouped: the group header cell — let the consumer render this; we\n // fall through to `columnDef.cell` so the existing behavior is\n // preserved (consumers that want a custom group header typically\n // branch on `cell.getIsGrouped()` themselves before calling FlexRender)\n // The optional-chaining + cast keeps this safe when the grouping feature\n // is not registered (the methods are absent at the type level then).\n const groupingCell = cell as typeof cell & {\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n }\n const groupingDef = def as typeof def & {\n aggregatedCell?: typeof def.cell\n }\n if (groupingCell.getIsAggregated?.()) {\n return flexRender(\n groupingDef.aggregatedCell ?? def.cell,\n cell.getContext(),\n )\n }\n if (groupingCell.getIsPlaceholder?.()) {\n return null\n }\n return flexRender(def.cell, cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"mappings":";;;AAWA,SAAS,kBACP,WACoC;
|
|
1
|
+
{"version":3,"file":"FlexRender.cjs","names":[],"sources":["../src/FlexRender.tsx"],"sourcesContent":["import type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentChild, ComponentType } from 'preact'\n\nexport type Renderable<TProps> = ComponentChild | ComponentType<TProps>\n\nfunction isPreactComponent<TProps>(\n component: unknown,\n): component is ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isPreactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['preact.memo', 'preact.forward_ref'].includes(\n component.$$typeof.description,\n )\n )\n}\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps> | null,\n props: TProps,\n): ComponentChild | Element | null {\n return !Comp ? null : isPreactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n const cell = props.cell\n const def = cell.column.columnDef\n // When the column-grouping feature is registered, a cell can be in one of\n // three special modes that should not render `columnDef.cell` directly:\n // - aggregated: render `columnDef.aggregatedCell` (falling back to\n // `columnDef.cell` if the column did not define one)\n // - placeholder: a duplicate value within a group — render nothing\n // - grouped: the group header cell — let the consumer render this; we\n // fall through to `columnDef.cell` so the existing behavior is\n // preserved (consumers that want a custom group header typically\n // branch on `cell.getIsGrouped()` themselves before calling FlexRender)\n // The optional-chaining + cast keeps this safe when the grouping feature\n // is not registered (the methods are absent at the type level then).\n const groupingCell = cell as typeof cell & {\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n }\n const groupingDef = def as typeof def & {\n aggregatedCell?: typeof def.cell\n }\n if (groupingCell.getIsAggregated?.()) {\n return flexRender(\n groupingDef.aggregatedCell ?? def.cell,\n cell.getContext(),\n )\n }\n if (groupingCell.getIsPlaceholder?.()) {\n return null\n }\n return flexRender(def.cell, cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"mappings":";;;AAWA,SAAS,kBACP,WACoC;CACpC,OACE,iBAAiB,UAAU,IAC3B,OAAO,cAAc,cACrB,kBAAkB,UAAU;;AAIhC,SAAS,iBAAiB,WAAgB;CACxC,OACE,OAAO,cAAc,qBACd;EACL,MAAM,QAAQ,OAAO,eAAe,UAAU;EAC9C,OAAO,MAAM,aAAa,MAAM,UAAU;KACxC;;AAIR,SAAS,kBAAkB,WAAgB;CACzC,OACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,eAAe,qBAAqB,CAAC,SACpC,UAAU,SAAS,YACpB;;;;;;AAQL,SAAgB,WACd,MACA,OACiC;CACjC,OAAO,CAAC,OAAO,OAAO,kBAA0B,KAAK,GACnD,4CAAC,MAAD,EAAM,GAAI,OAAS,IAEnB;;;;;;;;;;;;;;;;;;;AA6CJ,SAAgB,WAId,OAAkD;CAClD,IAAI,UAAU,SAAS,MAAM,MAAM;;EACjC,MAAM,OAAO,MAAM;EACnB,MAAM,MAAM,KAAK,OAAO;EAYxB,MAAM,eAAe;EAIrB,MAAM,cAAc;EAGpB,6BAAI,aAAa,iHAAmB,EAClC,OAAO,WACL,YAAY,kBAAkB,IAAI,MAClC,KAAK,YAAY,CAClB;EAEH,6BAAI,aAAa,kHAAoB,EACnC,OAAO;EAET,OAAO,WAAW,IAAI,MAAM,KAAK,YAAY,CAAC;;CAEhD,IAAI,YAAY,SAAS,MAAM,QAC7B,OAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;CAEH,IAAI,YAAY,SAAS,MAAM,QAC7B,OAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;CAEH,OAAO"}
|
package/dist/FlexRender.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlexRender.js","names":[],"sources":["../src/FlexRender.tsx"],"sourcesContent":["import type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentChild, ComponentType } from 'preact'\n\nexport type Renderable<TProps> = ComponentChild | ComponentType<TProps>\n\nfunction isPreactComponent<TProps>(\n component: unknown,\n): component is ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isPreactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['preact.memo', 'preact.forward_ref'].includes(\n component.$$typeof.description,\n )\n )\n}\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps> | null,\n props: TProps,\n): ComponentChild | Element | null {\n return !Comp ? null : isPreactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n const cell = props.cell\n const def = cell.column.columnDef\n // When the column-grouping feature is registered, a cell can be in one of\n // three special modes that should not render `columnDef.cell` directly:\n // - aggregated: render `columnDef.aggregatedCell` (falling back to\n // `columnDef.cell` if the column did not define one)\n // - placeholder: a duplicate value within a group — render nothing\n // - grouped: the group header cell — let the consumer render this; we\n // fall through to `columnDef.cell` so the existing behavior is\n // preserved (consumers that want a custom group header typically\n // branch on `cell.getIsGrouped()` themselves before calling FlexRender)\n // The optional-chaining + cast keeps this safe when the grouping feature\n // is not registered (the methods are absent at the type level then).\n const groupingCell = cell as typeof cell & {\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n }\n const groupingDef = def as typeof def & {\n aggregatedCell?: typeof def.cell\n }\n if (groupingCell.getIsAggregated?.()) {\n return flexRender(\n groupingDef.aggregatedCell ?? def.cell,\n cell.getContext(),\n )\n }\n if (groupingCell.getIsPlaceholder?.()) {\n return null\n }\n return flexRender(def.cell, cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"mappings":";;;AAWA,SAAS,kBACP,WACoC;
|
|
1
|
+
{"version":3,"file":"FlexRender.js","names":[],"sources":["../src/FlexRender.tsx"],"sourcesContent":["import type {\n Cell,\n CellData,\n Header,\n RowData,\n TableFeatures,\n} from '@tanstack/table-core'\nimport type { ComponentChild, ComponentType } from 'preact'\n\nexport type Renderable<TProps> = ComponentChild | ComponentType<TProps>\n\nfunction isPreactComponent<TProps>(\n component: unknown,\n): component is ComponentType<TProps> {\n return (\n isClassComponent(component) ||\n typeof component === 'function' ||\n isExoticComponent(component)\n )\n}\n\nfunction isClassComponent(component: any) {\n return (\n typeof component === 'function' &&\n (() => {\n const proto = Object.getPrototypeOf(component)\n return proto.prototype && proto.prototype.isPreactComponent\n })()\n )\n}\n\nfunction isExoticComponent(component: any) {\n return (\n typeof component === 'object' &&\n typeof component.$$typeof === 'symbol' &&\n ['preact.memo', 'preact.forward_ref'].includes(\n component.$$typeof.description,\n )\n )\n}\n\n/**\n * If rendering headers, cells, or footers with custom markup, use flexRender instead of `cell.getValue()` or `cell.renderValue()`.\n * @example flexRender(cell.column.columnDef.cell, cell.getContext())\n */\nexport function flexRender<TProps extends object>(\n Comp: Renderable<TProps> | null,\n props: TProps,\n): ComponentChild | Element | null {\n return !Comp ? null : isPreactComponent<TProps>(Comp) ? (\n <Comp {...props} />\n ) : (\n Comp\n )\n}\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example <FlexRender cell={cell} />\n * @example <FlexRender header={header} />\n * @example <FlexRender footer={footer} />\n */\nexport type FlexRenderProps<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n> =\n | { cell: Cell<TFeatures, TData, TValue>; header?: never; footer?: never }\n | {\n header: Header<TFeatures, TData, TValue>\n cell?: never\n footer?: never\n }\n | {\n footer: Header<TFeatures, TData, TValue>\n cell?: never\n header?: never\n }\n\n/**\n * Simplified component wrapper of `flexRender`. Use this utility component to render headers, cells, or footers with custom markup.\n * Only one prop (`cell`, `header`, or `footer`) may be passed.\n * @example\n * ```tsx\n * <FlexRender cell={cell} />\n * <FlexRender header={header} />\n * <FlexRender footer={footer} />\n * ```\n *\n * This replaces calling `flexRender` directly like this:\n * ```tsx\n * flexRender(cell.column.columnDef.cell, cell.getContext())\n * flexRender(header.column.columnDef.header, header.getContext())\n * flexRender(footer.column.columnDef.footer, footer.getContext())\n * ```\n */\nexport function FlexRender<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(props: FlexRenderProps<TFeatures, TData, TValue>) {\n if ('cell' in props && props.cell) {\n const cell = props.cell\n const def = cell.column.columnDef\n // When the column-grouping feature is registered, a cell can be in one of\n // three special modes that should not render `columnDef.cell` directly:\n // - aggregated: render `columnDef.aggregatedCell` (falling back to\n // `columnDef.cell` if the column did not define one)\n // - placeholder: a duplicate value within a group — render nothing\n // - grouped: the group header cell — let the consumer render this; we\n // fall through to `columnDef.cell` so the existing behavior is\n // preserved (consumers that want a custom group header typically\n // branch on `cell.getIsGrouped()` themselves before calling FlexRender)\n // The optional-chaining + cast keeps this safe when the grouping feature\n // is not registered (the methods are absent at the type level then).\n const groupingCell = cell as typeof cell & {\n getIsAggregated?: () => boolean\n getIsPlaceholder?: () => boolean\n }\n const groupingDef = def as typeof def & {\n aggregatedCell?: typeof def.cell\n }\n if (groupingCell.getIsAggregated?.()) {\n return flexRender(\n groupingDef.aggregatedCell ?? def.cell,\n cell.getContext(),\n )\n }\n if (groupingCell.getIsPlaceholder?.()) {\n return null\n }\n return flexRender(def.cell, cell.getContext())\n }\n if ('header' in props && props.header) {\n return flexRender(\n props.header.column.columnDef.header,\n props.header.getContext(),\n )\n }\n if ('footer' in props && props.footer) {\n return flexRender(\n props.footer.column.columnDef.footer,\n props.footer.getContext(),\n )\n }\n return null\n}\n"],"mappings":";;;AAWA,SAAS,kBACP,WACoC;CACpC,OACE,iBAAiB,UAAU,IAC3B,OAAO,cAAc,cACrB,kBAAkB,UAAU;;AAIhC,SAAS,iBAAiB,WAAgB;CACxC,OACE,OAAO,cAAc,qBACd;EACL,MAAM,QAAQ,OAAO,eAAe,UAAU;EAC9C,OAAO,MAAM,aAAa,MAAM,UAAU;KACxC;;AAIR,SAAS,kBAAkB,WAAgB;CACzC,OACE,OAAO,cAAc,YACrB,OAAO,UAAU,aAAa,YAC9B,CAAC,eAAe,qBAAqB,CAAC,SACpC,UAAU,SAAS,YACpB;;;;;;AAQL,SAAgB,WACd,MACA,OACiC;CACjC,OAAO,CAAC,OAAO,OAAO,kBAA0B,KAAK,GACnD,oBAAC,MAAD,EAAM,GAAI,OAAS,IAEnB;;;;;;;;;;;;;;;;;;;AA6CJ,SAAgB,WAId,OAAkD;CAClD,IAAI,UAAU,SAAS,MAAM,MAAM;;EACjC,MAAM,OAAO,MAAM;EACnB,MAAM,MAAM,KAAK,OAAO;EAYxB,MAAM,eAAe;EAIrB,MAAM,cAAc;EAGpB,6BAAI,aAAa,iHAAmB,EAClC,OAAO,WACL,YAAY,kBAAkB,IAAI,MAClC,KAAK,YAAY,CAClB;EAEH,6BAAI,aAAa,kHAAoB,EACnC,OAAO;EAET,OAAO,WAAW,IAAI,MAAM,KAAK,YAAY,CAAC;;CAEhD,IAAI,YAAY,SAAS,MAAM,QAC7B,OAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;CAEH,IAAI,YAAY,SAAS,MAAM,QAC7B,OAAO,WACL,MAAM,OAAO,OAAO,UAAU,QAC9B,MAAM,OAAO,YAAY,CAC1B;CAEH,OAAO"}
|
package/dist/Subscribe.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":";;;
|
|
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 *\n * @example\n * ```tsx\n * <Subscribe\n * source={table.store}\n * selector={(state) => ({ rowSelection: state.rowSelection })}\n * >\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * <Subscribe\n * source={table.atoms.rowSelection}\n * selector={(rowSelection) => rowSelection[row.id]}\n * >\n * {(selected) => <input checked={!!selected} type=\"checkbox\" />}\n * </Subscribe>\n * ```\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":";;;AA6GA,SAAgB,UAKd,OACmB;CACnB,MAAM,mDACJ,MAAM,QACN,MAAM,UACN,EACE,SAASA,gCACV,CACF;CAED,OAAO,OAAO,MAAM,aAAa,aAC5B,MAAM,SAAqD,SAAS,GACrE,MAAM"}
|
package/dist/Subscribe.d.cts
CHANGED
|
@@ -48,6 +48,28 @@ type SubscribeProps<TFeatures extends TableFeatures, TSelected = unknown, TSourc
|
|
|
48
48
|
*
|
|
49
49
|
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so
|
|
50
50
|
* JSX contextual typing works. This standalone component uses a union `props` type.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <Subscribe
|
|
55
|
+
* source={table.store}
|
|
56
|
+
* selector={(state) => ({ rowSelection: state.rowSelection })}
|
|
57
|
+
* >
|
|
58
|
+
* {({ rowSelection }) => (
|
|
59
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
60
|
+
* )}
|
|
61
|
+
* </Subscribe>
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* <Subscribe
|
|
67
|
+
* source={table.atoms.rowSelection}
|
|
68
|
+
* selector={(rowSelection) => rowSelection[row.id]}
|
|
69
|
+
* >
|
|
70
|
+
* {(selected) => <input checked={!!selected} type="checkbox" />}
|
|
71
|
+
* </Subscribe>
|
|
72
|
+
* ```
|
|
51
73
|
*/
|
|
52
74
|
declare function Subscribe<TSourceValue>(props: SubscribePropsWithSourceIdentity<TSourceValue>): ComponentChildren;
|
|
53
75
|
declare function Subscribe<TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>): ComponentChildren;
|
package/dist/Subscribe.d.ts
CHANGED
|
@@ -48,6 +48,28 @@ type SubscribeProps<TFeatures extends TableFeatures, TSelected = unknown, TSourc
|
|
|
48
48
|
*
|
|
49
49
|
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so
|
|
50
50
|
* JSX contextual typing works. This standalone component uses a union `props` type.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```tsx
|
|
54
|
+
* <Subscribe
|
|
55
|
+
* source={table.store}
|
|
56
|
+
* selector={(state) => ({ rowSelection: state.rowSelection })}
|
|
57
|
+
* >
|
|
58
|
+
* {({ rowSelection }) => (
|
|
59
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
60
|
+
* )}
|
|
61
|
+
* </Subscribe>
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* <Subscribe
|
|
67
|
+
* source={table.atoms.rowSelection}
|
|
68
|
+
* selector={(rowSelection) => rowSelection[row.id]}
|
|
69
|
+
* >
|
|
70
|
+
* {(selected) => <input checked={!!selected} type="checkbox" />}
|
|
71
|
+
* </Subscribe>
|
|
72
|
+
* ```
|
|
51
73
|
*/
|
|
52
74
|
declare function Subscribe<TSourceValue>(props: SubscribePropsWithSourceIdentity<TSourceValue>): ComponentChildren;
|
|
53
75
|
declare function Subscribe<TSourceValue, TSelected>(props: SubscribePropsWithSourceWithSelector<TSourceValue, TSelected>): ComponentChildren;
|
package/dist/Subscribe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":";;;
|
|
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 *\n * @example\n * ```tsx\n * <Subscribe\n * source={table.store}\n * selector={(state) => ({ rowSelection: state.rowSelection })}\n * >\n * {({ rowSelection }) => (\n * <div>Selected rows: {Object.keys(rowSelection).length}</div>\n * )}\n * </Subscribe>\n * ```\n *\n * @example\n * ```tsx\n * <Subscribe\n * source={table.atoms.rowSelection}\n * selector={(rowSelection) => rowSelection[row.id]}\n * >\n * {(selected) => <input checked={!!selected} type=\"checkbox\" />}\n * </Subscribe>\n * ```\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":";;;AA6GA,SAAgB,UAKd,OACmB;CACnB,MAAM,WAAW,YACf,MAAM,QACN,MAAM,UACN,EACE,SAAS,SACV,CACF;CAED,OAAO,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<\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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"}
|
|
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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"}
|
|
@@ -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<\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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"}
|
|
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/reactivity.cjs
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
let _tanstack_preact_store = require("@tanstack/preact-store");
|
|
2
2
|
|
|
3
3
|
//#region src/reactivity.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates the table-core reactivity bindings used by the Preact adapter.
|
|
6
|
+
*
|
|
7
|
+
* Preact stores table state in TanStack Store atoms and leaves options as plain
|
|
8
|
+
* resolved data because `useTable` synchronizes options during render.
|
|
9
|
+
*/
|
|
4
10
|
function preactReactivity() {
|
|
5
11
|
return {
|
|
6
12
|
createOptionsStore: false,
|
|
13
|
+
schedule: (fn) => queueMicrotask(() => fn()),
|
|
7
14
|
batch: _tanstack_preact_store.batch,
|
|
8
15
|
untrack: (fn) => fn(),
|
|
9
16
|
createReadonlyAtom: (fn, options) => {
|
package/dist/reactivity.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactivity.cjs","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/preact-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\n\nexport function preactReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: false,\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n\n// // TOTO - re-explore preact signals for reactivity\n// import { batch, computed, signal, untracked } from '@preact/signals'\n// import type {\n// TableAtomOptions,\n// TableReactivityBindings,\n// } from '@tanstack/table-core/reactivity'\n// import type { Atom, Observer, ReadonlyAtom } from '@tanstack/preact-store'\n\n// function observerToCallback<T>(\n// observerOrNext: Observer<T> | ((value: T) => void),\n// ): (value: T) => void {\n// return typeof observerOrNext === 'function'\n// ? observerOrNext\n// : (value) => observerOrNext.next?.(value)\n// }\n\n// function signalToReadonlyAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): ReadonlyAtom<T> {\n// return Object.assign(source, {\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as ReadonlyAtom<T>['subscribe'],\n// })\n// }\n\n// function signalToWritableAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): Atom<T> {\n// return Object.assign(source, {\n// set: (updater: T | ((prevVal: T) => T)) => {\n// source.value =\n// typeof updater === 'function'\n// ? (updater as (prevVal: T) => T)(source.value)\n// : updater\n// },\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as Atom<T>['subscribe'],\n// })\n// }\n\n// export function preactReactivity(): TableReactivityBindings {\n// return {\n// createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n// return signalToReadonlyAtom(computed(fn))\n// },\n// createWritableAtom: <T>(\n// value: T,\n// _options?: TableAtomOptions<T>,\n// ): Atom<T> => {\n// return signalToWritableAtom(signal(value))\n// },\n// untrack: untracked,\n// batch: batch,\n// }\n// }\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactivity.cjs","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/preact-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\n\n/**\n * Creates the table-core reactivity bindings used by the Preact adapter.\n *\n * Preact stores table state in TanStack Store atoms and leaves options as plain\n * resolved data because `useTable` synchronizes options during render.\n */\nexport function preactReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: false,\n schedule: (fn) => queueMicrotask(() => fn()),\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n\n// // TOTO - re-explore preact signals for reactivity\n// import { batch, computed, signal, untracked } from '@preact/signals'\n// import type {\n// TableAtomOptions,\n// TableReactivityBindings,\n// } from '@tanstack/table-core/reactivity'\n// import type { Atom, Observer, ReadonlyAtom } from '@tanstack/preact-store'\n\n// function observerToCallback<T>(\n// observerOrNext: Observer<T> | ((value: T) => void),\n// ): (value: T) => void {\n// return typeof observerOrNext === 'function'\n// ? observerOrNext\n// : (value) => observerOrNext.next?.(value)\n// }\n\n// function signalToReadonlyAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): ReadonlyAtom<T> {\n// return Object.assign(source, {\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as ReadonlyAtom<T>['subscribe'],\n// })\n// }\n\n// function signalToWritableAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): Atom<T> {\n// return Object.assign(source, {\n// set: (updater: T | ((prevVal: T) => T)) => {\n// source.value =\n// typeof updater === 'function'\n// ? (updater as (prevVal: T) => T)(source.value)\n// : updater\n// },\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as Atom<T>['subscribe'],\n// })\n// }\n\n// export function preactReactivity(): TableReactivityBindings {\n// return {\n// createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n// return signalToReadonlyAtom(computed(fn))\n// },\n// createWritableAtom: <T>(\n// value: T,\n// _options?: TableAtomOptions<T>,\n// ): Atom<T> => {\n// return signalToWritableAtom(signal(value))\n// },\n// untrack: untracked,\n// batch: batch,\n// }\n// }\n"],"mappings":";;;;;;;;;AAYA,SAAgB,mBAA4C;CAC1D,OAAO;EACL,oBAAoB;EACpB,WAAW,OAAO,qBAAqB,IAAI,CAAC;EAC5C;EACA,UAAU,OAAO,IAAI;EACrB,qBAAwB,IAAa,YAAkC;GACrE,oDAAwB,IAAI,EAAE,EAC5B,2DAAS,QAAS,SACnB,CAAC;;EAEJ,qBAAwB,OAAU,YAAkC;GAClE,8CAAkB,OAAO,EACvB,2DAAS,QAAS,SACnB,CAAC;;EAEL"}
|
package/dist/reactivity.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { batch, createAtom } from "@tanstack/preact-store";
|
|
2
2
|
|
|
3
3
|
//#region src/reactivity.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates the table-core reactivity bindings used by the Preact adapter.
|
|
6
|
+
*
|
|
7
|
+
* Preact stores table state in TanStack Store atoms and leaves options as plain
|
|
8
|
+
* resolved data because `useTable` synchronizes options during render.
|
|
9
|
+
*/
|
|
4
10
|
function preactReactivity() {
|
|
5
11
|
return {
|
|
6
12
|
createOptionsStore: false,
|
|
13
|
+
schedule: (fn) => queueMicrotask(() => fn()),
|
|
7
14
|
batch,
|
|
8
15
|
untrack: (fn) => fn(),
|
|
9
16
|
createReadonlyAtom: (fn, options) => {
|
package/dist/reactivity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactivity.js","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/preact-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\n\nexport function preactReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: false,\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n\n// // TOTO - re-explore preact signals for reactivity\n// import { batch, computed, signal, untracked } from '@preact/signals'\n// import type {\n// TableAtomOptions,\n// TableReactivityBindings,\n// } from '@tanstack/table-core/reactivity'\n// import type { Atom, Observer, ReadonlyAtom } from '@tanstack/preact-store'\n\n// function observerToCallback<T>(\n// observerOrNext: Observer<T> | ((value: T) => void),\n// ): (value: T) => void {\n// return typeof observerOrNext === 'function'\n// ? observerOrNext\n// : (value) => observerOrNext.next?.(value)\n// }\n\n// function signalToReadonlyAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): ReadonlyAtom<T> {\n// return Object.assign(source, {\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as ReadonlyAtom<T>['subscribe'],\n// })\n// }\n\n// function signalToWritableAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): Atom<T> {\n// return Object.assign(source, {\n// set: (updater: T | ((prevVal: T) => T)) => {\n// source.value =\n// typeof updater === 'function'\n// ? (updater as (prevVal: T) => T)(source.value)\n// : updater\n// },\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as Atom<T>['subscribe'],\n// })\n// }\n\n// export function preactReactivity(): TableReactivityBindings {\n// return {\n// createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n// return signalToReadonlyAtom(computed(fn))\n// },\n// createWritableAtom: <T>(\n// value: T,\n// _options?: TableAtomOptions<T>,\n// ): Atom<T> => {\n// return signalToWritableAtom(signal(value))\n// },\n// untrack: untracked,\n// batch: batch,\n// }\n// }\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"reactivity.js","names":[],"sources":["../src/reactivity.ts"],"sourcesContent":["import { batch, createAtom } from '@tanstack/preact-store'\nimport type {\n TableAtomOptions,\n TableReactivityBindings,\n} from '@tanstack/table-core/reactivity'\n\n/**\n * Creates the table-core reactivity bindings used by the Preact adapter.\n *\n * Preact stores table state in TanStack Store atoms and leaves options as plain\n * resolved data because `useTable` synchronizes options during render.\n */\nexport function preactReactivity(): TableReactivityBindings {\n return {\n createOptionsStore: false,\n schedule: (fn) => queueMicrotask(() => fn()),\n batch,\n untrack: (fn) => fn(),\n createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {\n return createAtom(() => fn(), {\n compare: options?.compare,\n })\n },\n createWritableAtom: <T>(value: T, options?: TableAtomOptions<T>) => {\n return createAtom(value, {\n compare: options?.compare,\n })\n },\n }\n}\n\n// // TOTO - re-explore preact signals for reactivity\n// import { batch, computed, signal, untracked } from '@preact/signals'\n// import type {\n// TableAtomOptions,\n// TableReactivityBindings,\n// } from '@tanstack/table-core/reactivity'\n// import type { Atom, Observer, ReadonlyAtom } from '@tanstack/preact-store'\n\n// function observerToCallback<T>(\n// observerOrNext: Observer<T> | ((value: T) => void),\n// ): (value: T) => void {\n// return typeof observerOrNext === 'function'\n// ? observerOrNext\n// : (value) => observerOrNext.next?.(value)\n// }\n\n// function signalToReadonlyAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): ReadonlyAtom<T> {\n// return Object.assign(source, {\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as ReadonlyAtom<T>['subscribe'],\n// })\n// }\n\n// function signalToWritableAtom<T>(source: {\n// value: T\n// subscribe: (observer: (value: T) => void) => () => void\n// }): Atom<T> {\n// return Object.assign(source, {\n// set: (updater: T | ((prevVal: T) => T)) => {\n// source.value =\n// typeof updater === 'function'\n// ? (updater as (prevVal: T) => T)(source.value)\n// : updater\n// },\n// get: () => source.value,\n// subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {\n// const unsubscribe = source.subscribe(observerToCallback(observerOrNext))\n// return { unsubscribe }\n// }) as Atom<T>['subscribe'],\n// })\n// }\n\n// export function preactReactivity(): TableReactivityBindings {\n// return {\n// createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {\n// return signalToReadonlyAtom(computed(fn))\n// },\n// createWritableAtom: <T>(\n// value: T,\n// _options?: TableAtomOptions<T>,\n// ): Atom<T> => {\n// return signalToWritableAtom(signal(value))\n// },\n// untrack: untracked,\n// batch: batch,\n// }\n// }\n"],"mappings":";;;;;;;;;AAYA,SAAgB,mBAA4C;CAC1D,OAAO;EACL,oBAAoB;EACpB,WAAW,OAAO,qBAAqB,IAAI,CAAC;EAC5C;EACA,UAAU,OAAO,IAAI;EACrB,qBAAwB,IAAa,YAAkC;GACrE,OAAO,iBAAiB,IAAI,EAAE,EAC5B,2DAAS,QAAS,SACnB,CAAC;;EAEJ,qBAAwB,OAAU,YAAkC;GAClE,OAAO,WAAW,OAAO,EACvB,2DAAS,QAAS,SACnB,CAAC;;EAEL"}
|
package/dist/useTable.cjs
CHANGED
|
@@ -6,6 +6,30 @@ 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
|
+
/**
|
|
10
|
+
* Creates a Preact table instance backed by TanStack Store atoms.
|
|
11
|
+
*
|
|
12
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
13
|
+
* exposed on `table.state` and compared shallowly for Preact re-renders. Omit
|
|
14
|
+
* the selector to subscribe to every registered table state slice, or pass a
|
|
15
|
+
* narrower selector and use `table.Subscribe` lower in the tree for targeted
|
|
16
|
+
* subscriptions.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const table = useTable(
|
|
21
|
+
* {
|
|
22
|
+
* _features,
|
|
23
|
+
* _rowModels: {},
|
|
24
|
+
* columns,
|
|
25
|
+
* data,
|
|
26
|
+
* },
|
|
27
|
+
* (state) => ({ pagination: state.pagination }),
|
|
28
|
+
* )
|
|
29
|
+
*
|
|
30
|
+
* table.state.pagination
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
9
33
|
function useTable(tableOptions, selector) {
|
|
10
34
|
const [table] = (0, preact_hooks.useState)(() => {
|
|
11
35
|
const tableInstance = (0, _tanstack_table_core.constructTable)({
|
package/dist/useTable.cjs.map
CHANGED
|
@@ -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 { 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":"
|
|
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\n/**\n * Creates a Preact table instance backed by TanStack Store atoms.\n *\n * The optional selector projects from `table.store`; the selected value is\n * exposed on `table.state` and compared shallowly for Preact re-renders. Omit\n * the selector to subscribe to every registered table state slice, or pass a\n * narrower selector and use `table.Subscribe` lower in the tree for targeted\n * subscriptions.\n *\n * @example\n * ```tsx\n * const table = useTable(\n * {\n * _features,\n * _rowModels: {},\n * columns,\n * data,\n * },\n * (state) => ({ pagination: state.pagination }),\n * )\n *\n * table.state.pagination\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,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;EAEF,cAAc,cAAc,UAAe;GACzC,MAAM,SAAS,MAAM,UAAU,cAAc;GAE7C,OAAOC,4BAAU;IACf,GAAG;IACH;IACD,CAAC;;EAGJ,cAAc,aAAaC;EAE3B,OAAO;GACP;CAGF,MAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,gDAAoB,MAAM,OAAO,UAAU,EAAE,SAASC,gCAAS,CAAC;CAEtE,wCACS;EACL,GAAG;EACH,SAAS;EACT;EACD,GACD;EAAC;EAAO;EAAc;EAAM,CAC7B"}
|
package/dist/useTable.d.cts
CHANGED
|
@@ -55,6 +55,30 @@ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelect
|
|
|
55
55
|
*/
|
|
56
56
|
readonly state: Readonly<TSelected>;
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Creates a Preact table instance backed by TanStack Store atoms.
|
|
60
|
+
*
|
|
61
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
62
|
+
* exposed on `table.state` and compared shallowly for Preact re-renders. Omit
|
|
63
|
+
* the selector to subscribe to every registered table state slice, or pass a
|
|
64
|
+
* narrower selector and use `table.Subscribe` lower in the tree for targeted
|
|
65
|
+
* subscriptions.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const table = useTable(
|
|
70
|
+
* {
|
|
71
|
+
* _features,
|
|
72
|
+
* _rowModels: {},
|
|
73
|
+
* columns,
|
|
74
|
+
* data,
|
|
75
|
+
* },
|
|
76
|
+
* (state) => ({ pagination: state.pagination }),
|
|
77
|
+
* )
|
|
78
|
+
*
|
|
79
|
+
* table.state.pagination
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
58
82
|
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>;
|
|
59
83
|
//#endregion
|
|
60
84
|
export { PreactTable, useTable };
|
package/dist/useTable.d.ts
CHANGED
|
@@ -55,6 +55,30 @@ type PreactTable<TFeatures extends TableFeatures, TData extends RowData, TSelect
|
|
|
55
55
|
*/
|
|
56
56
|
readonly state: Readonly<TSelected>;
|
|
57
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* Creates a Preact table instance backed by TanStack Store atoms.
|
|
60
|
+
*
|
|
61
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
62
|
+
* exposed on `table.state` and compared shallowly for Preact re-renders. Omit
|
|
63
|
+
* the selector to subscribe to every registered table state slice, or pass a
|
|
64
|
+
* narrower selector and use `table.Subscribe` lower in the tree for targeted
|
|
65
|
+
* subscriptions.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* const table = useTable(
|
|
70
|
+
* {
|
|
71
|
+
* _features,
|
|
72
|
+
* _rowModels: {},
|
|
73
|
+
* columns,
|
|
74
|
+
* data,
|
|
75
|
+
* },
|
|
76
|
+
* (state) => ({ pagination: state.pagination }),
|
|
77
|
+
* )
|
|
78
|
+
*
|
|
79
|
+
* table.state.pagination
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
58
82
|
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>;
|
|
59
83
|
//#endregion
|
|
60
84
|
export { PreactTable, useTable };
|
package/dist/useTable.js
CHANGED
|
@@ -6,6 +6,30 @@ import { shallow, useSelector } from "@tanstack/preact-store";
|
|
|
6
6
|
import { useMemo, useState } from "preact/hooks";
|
|
7
7
|
|
|
8
8
|
//#region src/useTable.ts
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Preact table instance backed by TanStack Store atoms.
|
|
11
|
+
*
|
|
12
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
13
|
+
* exposed on `table.state` and compared shallowly for Preact re-renders. Omit
|
|
14
|
+
* the selector to subscribe to every registered table state slice, or pass a
|
|
15
|
+
* narrower selector and use `table.Subscribe` lower in the tree for targeted
|
|
16
|
+
* subscriptions.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const table = useTable(
|
|
21
|
+
* {
|
|
22
|
+
* _features,
|
|
23
|
+
* _rowModels: {},
|
|
24
|
+
* columns,
|
|
25
|
+
* data,
|
|
26
|
+
* },
|
|
27
|
+
* (state) => ({ pagination: state.pagination }),
|
|
28
|
+
* )
|
|
29
|
+
*
|
|
30
|
+
* table.state.pagination
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
9
33
|
function useTable(tableOptions, selector) {
|
|
10
34
|
const [table] = useState(() => {
|
|
11
35
|
const tableInstance = constructTable({
|
package/dist/useTable.js.map
CHANGED
|
@@ -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 { 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":"
|
|
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\n/**\n * Creates a Preact table instance backed by TanStack Store atoms.\n *\n * The optional selector projects from `table.store`; the selected value is\n * exposed on `table.state` and compared shallowly for Preact re-renders. Omit\n * the selector to subscribe to every registered table state slice, or pass a\n * narrower selector and use `table.Subscribe` lower in the tree for targeted\n * subscriptions.\n *\n * @example\n * ```tsx\n * const table = useTable(\n * {\n * _features,\n * _rowModels: {},\n * columns,\n * data,\n * },\n * (state) => ({ pagination: state.pagination }),\n * )\n *\n * table.state.pagination\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,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;EAEF,cAAc,cAAc,UAAe;GACzC,MAAM,SAAS,MAAM,UAAU,cAAc;GAE7C,OAAO,UAAU;IACf,GAAG;IACH;IACD,CAAC;;EAGJ,cAAc,aAAa;EAE3B,OAAO;GACP;CAGF,MAAM,YAAY,UAAU;EAC1B,GAAG;EACH,GAAG;EACJ,EAAE;CAEH,MAAM,QAAQ,YAAY,MAAM,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;CAEtE,OAAO,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.
|
|
3
|
+
"version": "9.0.0-alpha.47",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Preact.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"src"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@tanstack/preact-store": "^0.13.
|
|
52
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
51
|
+
"@tanstack/preact-store": "^0.13.1",
|
|
52
|
+
"@tanstack/table-core": "9.0.0-alpha.47"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@preact/preset-vite": "^2.10.5",
|
package/src/Subscribe.ts
CHANGED
|
@@ -75,6 +75,28 @@ export type SubscribeProps<
|
|
|
75
75
|
*
|
|
76
76
|
* For `table.Subscribe` from `useTable`, prefer that API — it uses overloads so
|
|
77
77
|
* JSX contextual typing works. This standalone component uses a union `props` type.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* <Subscribe
|
|
82
|
+
* source={table.store}
|
|
83
|
+
* selector={(state) => ({ rowSelection: state.rowSelection })}
|
|
84
|
+
* >
|
|
85
|
+
* {({ rowSelection }) => (
|
|
86
|
+
* <div>Selected rows: {Object.keys(rowSelection).length}</div>
|
|
87
|
+
* )}
|
|
88
|
+
* </Subscribe>
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* <Subscribe
|
|
94
|
+
* source={table.atoms.rowSelection}
|
|
95
|
+
* selector={(rowSelection) => rowSelection[row.id]}
|
|
96
|
+
* >
|
|
97
|
+
* {(selected) => <input checked={!!selected} type="checkbox" />}
|
|
98
|
+
* </Subscribe>
|
|
99
|
+
* ```
|
|
78
100
|
*/
|
|
79
101
|
export function Subscribe<TSourceValue>(
|
|
80
102
|
props: SubscribePropsWithSourceIdentity<TSourceValue>,
|
package/src/reactivity.ts
CHANGED
|
@@ -4,9 +4,16 @@ import type {
|
|
|
4
4
|
TableReactivityBindings,
|
|
5
5
|
} from '@tanstack/table-core/reactivity'
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Creates the table-core reactivity bindings used by the Preact adapter.
|
|
9
|
+
*
|
|
10
|
+
* Preact stores table state in TanStack Store atoms and leaves options as plain
|
|
11
|
+
* resolved data because `useTable` synchronizes options during render.
|
|
12
|
+
*/
|
|
7
13
|
export function preactReactivity(): TableReactivityBindings {
|
|
8
14
|
return {
|
|
9
15
|
createOptionsStore: false,
|
|
16
|
+
schedule: (fn) => queueMicrotask(() => fn()),
|
|
10
17
|
batch,
|
|
11
18
|
untrack: (fn) => fn(),
|
|
12
19
|
createReadonlyAtom: <T>(fn: () => T, options?: TableAtomOptions<T>) => {
|
package/src/useTable.ts
CHANGED
|
@@ -76,6 +76,30 @@ export type PreactTable<
|
|
|
76
76
|
readonly state: Readonly<TSelected>
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Creates a Preact table instance backed by TanStack Store atoms.
|
|
81
|
+
*
|
|
82
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
83
|
+
* exposed on `table.state` and compared shallowly for Preact re-renders. Omit
|
|
84
|
+
* the selector to subscribe to every registered table state slice, or pass a
|
|
85
|
+
* narrower selector and use `table.Subscribe` lower in the tree for targeted
|
|
86
|
+
* subscriptions.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* const table = useTable(
|
|
91
|
+
* {
|
|
92
|
+
* _features,
|
|
93
|
+
* _rowModels: {},
|
|
94
|
+
* columns,
|
|
95
|
+
* data,
|
|
96
|
+
* },
|
|
97
|
+
* (state) => ({ pagination: state.pagination }),
|
|
98
|
+
* )
|
|
99
|
+
*
|
|
100
|
+
* table.state.pagination
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
79
103
|
export function useTable<
|
|
80
104
|
TFeatures extends TableFeatures,
|
|
81
105
|
TData extends RowData,
|