@tanstack/preact-table 0.0.1 → 9.0.0-alpha.14
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/LICENSE +21 -0
- package/dist/esm/FlexRender.d.ts +46 -0
- package/dist/esm/FlexRender.js +41 -0
- package/dist/esm/FlexRender.js.map +1 -0
- package/dist/esm/Subscribe.d.ts +44 -0
- package/dist/esm/Subscribe.js +9 -0
- package/dist/esm/Subscribe.js.map +1 -0
- package/dist/esm/createTableHook.d.ts +349 -0
- package/dist/esm/createTableHook.js +133 -0
- package/dist/esm/createTableHook.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/useTable.d.ts +52 -0
- package/dist/esm/useTable.js +46 -0
- package/dist/esm/useTable.js.map +1 -0
- package/package.json +61 -7
- package/src/FlexRender.tsx +119 -0
- package/src/Subscribe.ts +67 -0
- package/src/createTableHook.tsx +1120 -0
- package/src/index.ts +6 -0
- package/src/useTable.ts +132 -0
- package/README.md +0 -45
package/src/index.ts
ADDED
package/src/useTable.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useMemo, useState } from 'preact/hooks'
|
|
2
|
+
import { constructTable } from '@tanstack/table-core'
|
|
3
|
+
import { useStore } from '@tanstack/preact-store'
|
|
4
|
+
import { FlexRender } from './FlexRender'
|
|
5
|
+
import { Subscribe } from './Subscribe'
|
|
6
|
+
import type {
|
|
7
|
+
CellData,
|
|
8
|
+
NoInfer,
|
|
9
|
+
RowData,
|
|
10
|
+
Table,
|
|
11
|
+
TableFeatures,
|
|
12
|
+
TableOptions,
|
|
13
|
+
TableState,
|
|
14
|
+
} from '@tanstack/table-core'
|
|
15
|
+
import type { ComponentChildren } from 'preact'
|
|
16
|
+
import type { FlexRenderProps } from './FlexRender'
|
|
17
|
+
import type { SubscribeProps } from './Subscribe'
|
|
18
|
+
|
|
19
|
+
const useIsomorphicLayoutEffect =
|
|
20
|
+
typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
21
|
+
|
|
22
|
+
export type PreactTable<
|
|
23
|
+
TFeatures extends TableFeatures,
|
|
24
|
+
TData extends RowData,
|
|
25
|
+
TSelected = {},
|
|
26
|
+
> = Table<TFeatures, TData> & {
|
|
27
|
+
/**
|
|
28
|
+
* A Preact HOC (Higher Order Component) that allows you to subscribe to the table state.
|
|
29
|
+
*
|
|
30
|
+
* This is useful for opting into state re-renders for specific parts of the table state.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
34
|
+
* {({ rowSelection }) => ( // important to include `{() => {()}}` syntax
|
|
35
|
+
* <tr key={row.id}>
|
|
36
|
+
* // render the row
|
|
37
|
+
* </tr>
|
|
38
|
+
* )}
|
|
39
|
+
* </table.Subscribe>
|
|
40
|
+
*/
|
|
41
|
+
Subscribe: <TSelected>(props: {
|
|
42
|
+
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected
|
|
43
|
+
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
44
|
+
}) => ComponentChildren
|
|
45
|
+
/**
|
|
46
|
+
* A Preact component that renders headers, cells, or footers with custom markup.
|
|
47
|
+
* Use this utility component instead of manually calling flexRender.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* <table.FlexRender cell={cell} />
|
|
52
|
+
* <table.FlexRender header={header} />
|
|
53
|
+
* <table.FlexRender footer={footer} />
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* This replaces calling `flexRender` directly like this:
|
|
57
|
+
* ```tsx
|
|
58
|
+
* flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
59
|
+
* flexRender(header.column.columnDef.header, header.getContext())
|
|
60
|
+
* flexRender(footer.column.columnDef.footer, footer.getContext())
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
FlexRender: <TValue extends CellData = CellData>(
|
|
64
|
+
props: FlexRenderProps<TFeatures, TData, TValue>,
|
|
65
|
+
) => ComponentChildren
|
|
66
|
+
/**
|
|
67
|
+
* 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`.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
71
|
+
*
|
|
72
|
+
* console.log(table.state.globalFilter)
|
|
73
|
+
*/
|
|
74
|
+
readonly state: Readonly<TSelected>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function useTable<
|
|
78
|
+
TFeatures extends TableFeatures,
|
|
79
|
+
TData extends RowData,
|
|
80
|
+
TSelected = {},
|
|
81
|
+
>(
|
|
82
|
+
tableOptions: TableOptions<TFeatures, TData>,
|
|
83
|
+
selector: (state: TableState<TFeatures>) => TSelected = () =>
|
|
84
|
+
({}) as TSelected,
|
|
85
|
+
): PreactTable<TFeatures, TData, TSelected> {
|
|
86
|
+
const [table] = useState(() => {
|
|
87
|
+
const tableInstance = constructTable(tableOptions) as PreactTable<
|
|
88
|
+
TFeatures,
|
|
89
|
+
TData,
|
|
90
|
+
TSelected
|
|
91
|
+
>
|
|
92
|
+
|
|
93
|
+
tableInstance.Subscribe = function SubscribeBound<TSelected>(
|
|
94
|
+
props: Omit<SubscribeProps<TFeatures, TData, TSelected>, 'table'>,
|
|
95
|
+
) {
|
|
96
|
+
return Subscribe({ ...props, table: tableInstance })
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
tableInstance.FlexRender = FlexRender
|
|
100
|
+
|
|
101
|
+
return tableInstance
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// sync table options on every render
|
|
105
|
+
table.setOptions((prev) => ({
|
|
106
|
+
...prev,
|
|
107
|
+
...tableOptions,
|
|
108
|
+
}))
|
|
109
|
+
|
|
110
|
+
useIsomorphicLayoutEffect(() => {
|
|
111
|
+
// prevent race condition between table.setOptions and table.baseStore.setState
|
|
112
|
+
queueMicrotask(() => {
|
|
113
|
+
table.baseStore.setState((prev) => ({
|
|
114
|
+
...prev,
|
|
115
|
+
}))
|
|
116
|
+
})
|
|
117
|
+
}, [
|
|
118
|
+
table.options.columns, // re-render when columns change
|
|
119
|
+
table.options.data, // re-render when data changes
|
|
120
|
+
table.options.state, // sync preact state to the table store
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
const state = useStore(table.store, selector)
|
|
124
|
+
|
|
125
|
+
return useMemo(
|
|
126
|
+
() => ({
|
|
127
|
+
...table,
|
|
128
|
+
state,
|
|
129
|
+
}),
|
|
130
|
+
[state, table],
|
|
131
|
+
)
|
|
132
|
+
}
|
package/README.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# @tanstack/preact-table
|
|
2
|
-
|
|
3
|
-
## ⚠️ IMPORTANT NOTICE ⚠️
|
|
4
|
-
|
|
5
|
-
**This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
|
|
6
|
-
|
|
7
|
-
This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
|
|
8
|
-
|
|
9
|
-
## Purpose
|
|
10
|
-
|
|
11
|
-
This package exists to:
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@tanstack/preact-table`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
15
|
-
|
|
16
|
-
## What is OIDC Trusted Publishing?
|
|
17
|
-
|
|
18
|
-
OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
|
|
19
|
-
|
|
20
|
-
## Setup Instructions
|
|
21
|
-
|
|
22
|
-
To properly configure OIDC trusted publishing for this package:
|
|
23
|
-
|
|
24
|
-
1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
|
|
25
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
28
|
-
|
|
29
|
-
## DO NOT USE THIS PACKAGE
|
|
30
|
-
|
|
31
|
-
This package is a placeholder for OIDC configuration only. It:
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
36
|
-
|
|
37
|
-
## More Information
|
|
38
|
-
|
|
39
|
-
For more details about npm's trusted publishing feature, see:
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
**Maintained for OIDC setup purposes only**
|