@tanstack/preact-table 9.0.0-alpha.22 → 9.0.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +117 -0
  2. package/dist/FlexRender.cjs +50 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +51 -0
  5. package/dist/{esm/FlexRender.d.ts → FlexRender.d.ts} +20 -15
  6. package/dist/FlexRender.js +49 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/Subscribe.cjs +36 -0
  9. package/dist/Subscribe.cjs.map +1 -0
  10. package/dist/Subscribe.d.cts +49 -0
  11. package/dist/Subscribe.d.ts +49 -0
  12. package/dist/Subscribe.js +36 -0
  13. package/dist/Subscribe.js.map +1 -0
  14. package/dist/createTableHook.cjs +334 -0
  15. package/dist/createTableHook.cjs.map +1 -0
  16. package/dist/createTableHook.d.cts +358 -0
  17. package/dist/createTableHook.d.ts +358 -0
  18. package/dist/createTableHook.js +334 -0
  19. package/dist/createTableHook.js.map +1 -0
  20. package/dist/index.cjs +18 -0
  21. package/dist/index.d.cts +6 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/{esm/index.js → index.js} +5 -10
  24. package/dist/useTable.cjs +38 -0
  25. package/dist/useTable.cjs.map +1 -0
  26. package/dist/useTable.d.cts +60 -0
  27. package/dist/useTable.d.ts +60 -0
  28. package/dist/useTable.js +38 -0
  29. package/dist/useTable.js.map +1 -0
  30. package/package.json +11 -13
  31. package/dist/esm/FlexRender.js +0 -41
  32. package/dist/esm/FlexRender.js.map +0 -1
  33. package/dist/esm/Subscribe.d.ts +0 -44
  34. package/dist/esm/Subscribe.js +0 -9
  35. package/dist/esm/Subscribe.js.map +0 -1
  36. package/dist/esm/createTableHook.d.ts +0 -349
  37. package/dist/esm/createTableHook.js +0 -133
  38. package/dist/esm/createTableHook.js.map +0 -1
  39. package/dist/esm/index.d.ts +0 -5
  40. package/dist/esm/index.js.map +0 -1
  41. package/dist/esm/useTable.d.ts +0 -55
  42. package/dist/esm/useTable.js +0 -38
  43. package/dist/esm/useTable.js.map +0 -1
@@ -1,38 +0,0 @@
1
- import { useState, useMemo } from "preact/hooks";
2
- import { constructTable } from "@tanstack/table-core";
3
- import { useStore, shallow } from "@tanstack/preact-store";
4
- import { FlexRender } from "./FlexRender.js";
5
- import { Subscribe } from "./Subscribe.js";
6
- function useTable(tableOptions, selector = () => ({})) {
7
- const [table] = useState(() => {
8
- const tableInstance = constructTable(tableOptions);
9
- tableInstance.Subscribe = function SubscribeBound(props) {
10
- return Subscribe({ ...props, table: tableInstance });
11
- };
12
- tableInstance.FlexRender = FlexRender;
13
- return tableInstance;
14
- });
15
- table.setOptions((prev) => ({
16
- ...prev,
17
- ...tableOptions
18
- }));
19
- const selectorWithDataAndColumns = (state2) => ({
20
- columns: tableOptions.columns,
21
- data: tableOptions.data,
22
- ...selector(state2)
23
- });
24
- const state = useStore(table.store, selectorWithDataAndColumns, {
25
- equal: shallow
26
- });
27
- return useMemo(
28
- () => ({
29
- ...table,
30
- state
31
- }),
32
- [state, table]
33
- );
34
- }
35
- export {
36
- useTable
37
- };
38
- //# sourceMappingURL=useTable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTable.js","sources":["../../src/useTable.ts"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { constructTable } from '@tanstack/table-core'\nimport { shallow, useStore } from '@tanstack/preact-store'\nimport { FlexRender } from './FlexRender'\nimport { Subscribe } from './Subscribe'\nimport type {\n CellData,\n NoInfer,\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 { SubscribeProps } from './Subscribe'\n\nexport type PreactTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.\n *\n * This is useful for opting into state re-renders for specific parts of the table state.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {({ rowSelection }) => ( // important to include `{() => {()}}` syntax\n * <tr key={row.id}>\n * // render the row\n * </tr>\n * )}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\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 * @example\n * ```tsx\n * <table.FlexRender cell={cell} />\n * <table.FlexRender header={header} />\n * <table.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 */\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 * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected> & {\n columns: TableOptions<TFeatures, TData>['columns']\n data: TableOptions<TFeatures, TData>['data']\n }\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptions<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): PreactTable<TFeatures, TData, TSelected> {\n const [table] = useState(() => {\n const tableInstance = constructTable(tableOptions) as PreactTable<\n TFeatures,\n TData,\n TSelected\n >\n\n tableInstance.Subscribe = function SubscribeBound<TSelected>(\n props: Omit<SubscribeProps<TFeatures, TData, TSelected>, 'table'>,\n ) {\n return Subscribe({ ...props, table: tableInstance })\n }\n\n tableInstance.FlexRender = FlexRender\n\n return tableInstance\n })\n\n // sync table options on every render\n table.setOptions((prev) => ({\n ...prev,\n ...tableOptions,\n }))\n\n const selectorWithDataAndColumns = (state: TableState<TFeatures>) => ({\n columns: tableOptions.columns,\n data: tableOptions.data,\n ...selector(state),\n })\n\n const state = useStore(table.store, selectorWithDataAndColumns, {\n equal: shallow,\n })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n ) as PreactTable<TFeatures, TData, TSelected>\n}\n"],"names":["state"],"mappings":";;;;;AA4EO,SAAS,SAKd,cACA,WAAwD,OACrD,CAAA,IACuC;AAC1C,QAAM,CAAC,KAAK,IAAI,SAAS,MAAM;AAC7B,UAAM,gBAAgB,eAAe,YAAY;AAMjD,kBAAc,YAAY,SAAS,eACjC,OACA;AACA,aAAO,UAAU,EAAE,GAAG,OAAO,OAAO,eAAe;AAAA,IACrD;AAEA,kBAAc,aAAa;AAE3B,WAAO;AAAA,EACT,CAAC;AAGD,QAAM,WAAW,CAAC,UAAU;AAAA,IAC1B,GAAG;AAAA,IACH,GAAG;AAAA,EAAA,EACH;AAEF,QAAM,6BAA6B,CAACA,YAAkC;AAAA,IACpE,SAAS,aAAa;AAAA,IACtB,MAAM,aAAa;AAAA,IACnB,GAAG,SAASA,MAAK;AAAA,EAAA;AAGnB,QAAM,QAAQ,SAAS,MAAM,OAAO,4BAA4B;AAAA,IAC9D,OAAO;AAAA,EAAA,CACR;AAED,SAAO;AAAA,IACL,OAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IAAA;AAAA,IAEF,CAAC,OAAO,KAAK;AAAA,EAAA;AAEjB;"}