{ "name": "@ui-arch/table-core", "type": "headless-core", "description": "Headless table state machine: immutable state, dispatch/reducer, composable derive pipeline (filter -> sort -> paginate) with per-stage memoization. No DOM, no framework dependency.", "tags": [ "table", "headless", "state-machine", "datagrid" ], "api": { "entry": "src/index.ts", "exports": [ "createTable(options) -> TableInstance: create headless table instance", "sortPlugin(options?) -> multi-column sorting plugin (asc -> desc -> off cycle)", "filterPlugin(options?) -> column filter plugin (default substring match, custom predicate supported)", "paginationPlugin() -> client-side pagination with page clamping, exposes setPage/nextPage/prevPage/getPageInfo", "selectionPlugin() -> rowKey-based selection, exposes selectAllVisible" ], "keyTypes": [ "ColumnDef", "TableState", "TablePlugin", "RowModel", "Action" ] }, "usage": "const table = createTable({ data, columns, rowKey: 'id', plugins: [filterPlugin(), sortPlugin(), paginationPlugin()], initialState: { pagination: { page: 1, pageSize: 20 } } }); table.dispatch({ type: 'toggleSort', key: 'name' }); table.getVisibleRows()", "conventions": [ "selection/expanded must store rowKey, never row index", "derive pipeline order is fixed: filter -> sort -> paginate", "actions are the only way to mutate state; state is immutable" ], "docs": { "intro": "Headless 表格内核:不渲染任何 DOM,只管理状态与派生。任何渲染层通过 getVisibleRows() 拿行模型,配 subscribe() 刷新。", "steps": [ "创建实例:const table = createTable({ data, columns, rowKey: 'id', plugins: [filterPlugin(), sortPlugin(), paginationPlugin()] })", "取派生数据:table.getVisibleRows() 返回 { rows, total };total 语义固定 = 筛选后、分页前的行数", "变更状态:只能 dispatch action,如 table.dispatch({ type: 'toggleSort', key: 'name' });状态不可变", "订阅刷新:table.subscribe(fn),fn 里重新 getVisibleRows() 并交给渲染层", "分页信息:api.getPageInfo() 返回 { page, pageSize, totalPages };越界页码自动钳制", "扩展能力:实现 TablePlugin(derive / patchState / api 三钩子)传入 plugins 即插入管线" ] } }