@tanstack/preact-table 9.0.0-alpha.21 → 9.0.0-alpha.23

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/dist/FlexRender.cjs +50 -0
  2. package/dist/FlexRender.cjs.map +1 -0
  3. package/dist/FlexRender.d.cts +51 -0
  4. package/dist/{esm/FlexRender.d.ts → FlexRender.d.ts} +20 -15
  5. package/dist/FlexRender.js +49 -0
  6. package/dist/FlexRender.js.map +1 -0
  7. package/dist/Subscribe.cjs +36 -0
  8. package/dist/Subscribe.cjs.map +1 -0
  9. package/dist/Subscribe.d.cts +49 -0
  10. package/dist/Subscribe.d.ts +49 -0
  11. package/dist/Subscribe.js +36 -0
  12. package/dist/Subscribe.js.map +1 -0
  13. package/dist/createTableHook.cjs +334 -0
  14. package/dist/createTableHook.cjs.map +1 -0
  15. package/dist/createTableHook.d.cts +358 -0
  16. package/dist/createTableHook.d.ts +358 -0
  17. package/dist/createTableHook.js +334 -0
  18. package/dist/createTableHook.js.map +1 -0
  19. package/dist/index.cjs +18 -0
  20. package/dist/index.d.cts +6 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/{esm/index.js → index.js} +5 -10
  23. package/dist/useTable.cjs +38 -0
  24. package/dist/useTable.cjs.map +1 -0
  25. package/dist/useTable.d.cts +60 -0
  26. package/dist/useTable.d.ts +60 -0
  27. package/dist/useTable.js +38 -0
  28. package/dist/useTable.js.map +1 -0
  29. package/package.json +11 -13
  30. package/src/useTable.ts +14 -19
  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 -52
  42. package/dist/esm/useTable.js +0 -46
  43. package/dist/esm/useTable.js.map +0 -1
@@ -1,46 +0,0 @@
1
- import { useState, useLayoutEffect, useEffect, 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
- const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
7
- function useTable(tableOptions, selector = () => ({})) {
8
- const [table] = useState(() => {
9
- const tableInstance = constructTable(tableOptions);
10
- tableInstance.Subscribe = function SubscribeBound(props) {
11
- return Subscribe({ ...props, table: tableInstance });
12
- };
13
- tableInstance.FlexRender = FlexRender;
14
- return tableInstance;
15
- });
16
- table.setOptions((prev) => ({
17
- ...prev,
18
- ...tableOptions
19
- }));
20
- useIsomorphicLayoutEffect(() => {
21
- queueMicrotask(() => {
22
- table.baseStore.setState((prev) => ({
23
- ...prev
24
- }));
25
- });
26
- }, [
27
- table.options.columns,
28
- // re-render when columns change
29
- table.options.data,
30
- // re-render when data changes
31
- table.options.state
32
- // sync preact state to the table store
33
- ]);
34
- const state = useStore(table.store, selector, { equal: shallow });
35
- return useMemo(
36
- () => ({
37
- ...table,
38
- state
39
- }),
40
- [state, table]
41
- );
42
- }
43
- export {
44
- useTable
45
- };
46
- //# sourceMappingURL=useTable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTable.js","sources":["../../src/useTable.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, 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\nconst useIsomorphicLayoutEffect =\n typeof window !== 'undefined' ? useLayoutEffect : useEffect\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}\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 useIsomorphicLayoutEffect(() => {\n // prevent race condition between table.setOptions and table.baseStore.setState\n queueMicrotask(() => {\n table.baseStore.setState((prev) => ({\n ...prev,\n }))\n })\n }, [\n table.options.columns, // re-render when columns change\n table.options.data, // re-render when data changes\n table.options.state, // sync preact state to the table store\n ])\n\n const state = useStore(table.store, selector, { equal: shallow })\n\n return useMemo(\n () => ({\n ...table,\n state,\n }),\n [state, table],\n )\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,4BACJ,OAAO,WAAW,cAAc,kBAAkB;AAyD7C,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,4BAA0B,MAAM;AAE9B,mBAAe,MAAM;AACnB,YAAM,UAAU,SAAS,CAAC,UAAU;AAAA,QAClC,GAAG;AAAA,MAAA,EACH;AAAA,IACJ,CAAC;AAAA,EACH,GAAG;AAAA,IACD,MAAM,QAAQ;AAAA;AAAA,IACd,MAAM,QAAQ;AAAA;AAAA,IACd,MAAM,QAAQ;AAAA;AAAA,EAAA,CACf;AAED,QAAM,QAAQ,SAAS,MAAM,OAAO,UAAU,EAAE,OAAO,SAAS;AAEhE,SAAO;AAAA,IACL,OAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,IAAA;AAAA,IAEF,CAAC,OAAO,KAAK;AAAA,EAAA;AAEjB;"}