@agile-team/mach-table-react 0.23.0 → 0.24.0
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/README.md +43 -94
- package/dist/adapters.cjs +1 -0
- package/dist/adapters.d.cts +18 -0
- package/dist/adapters.d.ts +18 -0
- package/dist/adapters.js +1 -0
- package/dist/chunk-FN4LWAOL.js +1 -0
- package/dist/chunk-II7TCYIU.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +6 -58
- package/dist/index.d.ts +6 -58
- package/dist/index.js +1 -1
- package/dist/ui.cjs +1 -0
- package/dist/ui.d.cts +36 -0
- package/dist/ui.d.ts +36 -0
- package/dist/ui.js +1 -0
- package/dist/useMachTable-lL575Wzq.d.cts +12 -0
- package/dist/useMachTable-lL575Wzq.d.ts +12 -0
- package/dist/workflows.cjs +1 -1
- package/dist/workflows.d.cts +130 -2
- package/dist/workflows.d.ts +130 -2
- package/dist/workflows.js +1 -1
- package/package.json +23 -3
- package/dist/chunk-MFRKW34V.cjs +0 -1
- package/dist/chunk-WF435LXF.js +0 -1
- package/dist/workflows-CoKf5zIV.d.cts +0 -138
- package/dist/workflows-CoKf5zIV.d.ts +0 -138
package/README.md
CHANGED
|
@@ -4,166 +4,115 @@
|
|
|
4
4
|
|
|
5
5
|
# @agile-team/mach-table-react
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Install
|
|
7
|
+
MachTable 0.24 的官方 React 18+ 适配包。一个依赖即可获得 Core、泛型 `<MachTable>`、应用/路由配置、按需工作流、StrictMode 安全清理和最新闭包事件处理。
|
|
10
8
|
|
|
11
9
|
```bash
|
|
12
10
|
pnpm add @agile-team/mach-table-react
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { createWorkerDataProcessor } from "@agile-team/mach-table-react/worker";
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Import the stylesheet once from your application entry:
|
|
13
|
+
应用入口只引入一次样式:
|
|
22
14
|
|
|
23
15
|
```ts
|
|
24
16
|
import "@agile-team/mach-table-react/styles.css";
|
|
25
17
|
```
|
|
26
18
|
|
|
27
|
-
##
|
|
19
|
+
## 基础接入
|
|
28
20
|
|
|
29
21
|
```tsx
|
|
30
22
|
import { useMemo } from "react";
|
|
31
|
-
import { MachTable,
|
|
23
|
+
import { MachTable, useMachTable, type ColDef } from "@agile-team/mach-table-react";
|
|
32
24
|
|
|
33
25
|
interface Row { id: string; name: string }
|
|
34
26
|
|
|
35
|
-
export function
|
|
36
|
-
const
|
|
27
|
+
export function Customers({ rows }: { rows: Row[] }) {
|
|
28
|
+
const table = useMachTable<Row>();
|
|
37
29
|
const columns = useMemo<ColDef<Row>[]>(
|
|
38
|
-
() => [{ field: "name",
|
|
30
|
+
() => [{ field: "name", flex: 1, editable: true }],
|
|
39
31
|
[]
|
|
40
32
|
);
|
|
41
33
|
|
|
42
34
|
return (
|
|
43
35
|
<div style={{ height: 520 }}>
|
|
44
36
|
<MachTable<Row>
|
|
45
|
-
apiRef={
|
|
37
|
+
apiRef={table.apiRef}
|
|
46
38
|
rowData={rows}
|
|
47
39
|
columnDefs={columns}
|
|
48
40
|
rowKey="id"
|
|
49
|
-
stateKey="customer-list"
|
|
50
41
|
enableColumnResize
|
|
42
|
+
persistence={{ key: "customers:list", sections: ["columns"] }}
|
|
51
43
|
/>
|
|
52
44
|
</div>
|
|
53
45
|
);
|
|
54
46
|
}
|
|
55
47
|
```
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
React intentionally has no global component registry. MachTable provides a default component export so the standard `React.lazy` API works without a mapping wrapper:
|
|
60
|
-
|
|
61
|
-
```tsx
|
|
62
|
-
import { lazy, Suspense } from "react";
|
|
63
|
-
|
|
64
|
-
const MachTable = lazy(() => import("@agile-team/mach-table-react"));
|
|
65
|
-
|
|
66
|
-
export function OrdersPage() {
|
|
67
|
-
return (
|
|
68
|
-
<Suspense fallback={<div>Loading table...</div>}>
|
|
69
|
-
<MachTable columnDefs={columns} rowData={rows} />
|
|
70
|
-
</Suspense>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
When the page itself is route-lazy, a normal named import inside that page already produces the same route-level split. Use `React.lazy` when the grid should be split independently from the page.
|
|
49
|
+
对象型列和配置建议用 `useMemo` 保持引用稳定。`useMachTable()` 同时提供 `apiRef`、响应式 `api` 与 `ready`。
|
|
76
50
|
|
|
77
|
-
##
|
|
51
|
+
## 应用配置
|
|
78
52
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```tsx
|
|
82
|
-
// mach-table.config.ts
|
|
53
|
+
```ts
|
|
54
|
+
// src/config/mach-table.config.ts
|
|
83
55
|
import { defineMachTableConfig, defineMachTablePreset } from "@agile-team/mach-table-react";
|
|
56
|
+
|
|
84
57
|
export default defineMachTableConfig({
|
|
85
58
|
defaults: {
|
|
86
59
|
size: "compact",
|
|
60
|
+
columnLayout: "fit",
|
|
87
61
|
enableColumnResize: true,
|
|
88
|
-
defaultColDef: { sortable: true,
|
|
62
|
+
defaultColDef: { sortable: true, filter: true, resizable: true }
|
|
89
63
|
},
|
|
90
64
|
defaultPreset: "list",
|
|
91
65
|
presets: {
|
|
92
|
-
list: defineMachTablePreset({
|
|
66
|
+
list: defineMachTablePreset({ stripedRows: true }),
|
|
93
67
|
crud: defineMachTablePreset({ rowSelection: "multiple", editType: "fullRow" })
|
|
94
68
|
}
|
|
95
69
|
});
|
|
70
|
+
```
|
|
96
71
|
|
|
97
|
-
|
|
72
|
+
```tsx
|
|
98
73
|
<MachTableProvider config={machTableConfig}>
|
|
99
74
|
<App />
|
|
100
75
|
</MachTableProvider>
|
|
101
76
|
```
|
|
102
77
|
|
|
103
|
-
|
|
78
|
+
Provider 可按路由/布局嵌套,最近一层覆盖外层,表格 props 优先级最高。
|
|
104
79
|
|
|
105
|
-
##
|
|
80
|
+
## 按需加载
|
|
106
81
|
|
|
107
|
-
|
|
82
|
+
React 不模拟全局组件注册。路由本身懒加载时普通 import 已自然拆包;需要独立边界时:
|
|
108
83
|
|
|
109
84
|
```tsx
|
|
110
|
-
|
|
111
|
-
import { MachTable, MachTableToolbar } from "@agile-team/mach-table-react";
|
|
112
|
-
|
|
113
|
-
const query = useMachTableQuery({
|
|
114
|
-
query: filters,
|
|
115
|
-
queryKey: filters,
|
|
116
|
-
rowKey: "id",
|
|
117
|
-
request: orderApi.page,
|
|
118
|
-
mode: "manual"
|
|
119
|
-
});
|
|
120
|
-
const controller = useMachTableController({ query });
|
|
121
|
-
|
|
122
|
-
<MachTableToolbar
|
|
123
|
-
api={controller.table.api}
|
|
124
|
-
commands={controller.commands}
|
|
125
|
-
search={controller.search}
|
|
126
|
-
onSearchChange={controller.setSearch}
|
|
127
|
-
loading={controller.busy}
|
|
128
|
-
/>;
|
|
129
|
-
<MachTable apiRef={controller.table.apiRef} {...controller.bindings} />;
|
|
85
|
+
const MachTable = lazy(() => import("@agile-team/mach-table-react"));
|
|
130
86
|
```
|
|
131
87
|
|
|
132
|
-
|
|
88
|
+
可选能力使用子入口:
|
|
133
89
|
|
|
134
90
|
```tsx
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
async function saveCurrentView() {
|
|
140
|
-
const api = grid.apiRef.current;
|
|
141
|
-
if (!api) return;
|
|
142
|
-
const views = createGridViewManager(api, {
|
|
143
|
-
scope: `${tenantId}:${userId}:orders`
|
|
144
|
-
});
|
|
145
|
-
await views.save("My pending orders");
|
|
146
|
-
}
|
|
91
|
+
import { useMachTableQuery, useMachTableEditing } from "@agile-team/mach-table-react/workflows";
|
|
92
|
+
import { MachTableToolbar } from "@agile-team/mach-table-react/ui";
|
|
93
|
+
import { reactCellRenderer } from "@agile-team/mach-table-react/adapters";
|
|
94
|
+
import { createWorkerDataProcessor } from "@agile-team/mach-table-react/worker";
|
|
147
95
|
```
|
|
148
96
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
97
|
+
- `/workflows`:请求取消、防过期覆盖、服务端分页、跨页选择、脏数据和冲突保存。
|
|
98
|
+
- `/ui`:可选标准工具栏。
|
|
99
|
+
- `/adapters`:自定义 React cell/detail renderer 桥接。
|
|
100
|
+
- `/worker`:大型本地过滤/排序的独立 Worker 能力。
|
|
152
101
|
|
|
153
102
|
```tsx
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
103
|
+
const query = useMachTableQuery({
|
|
104
|
+
query: filters,
|
|
105
|
+
queryKey: filters,
|
|
106
|
+
rowKey: "id",
|
|
107
|
+
request: orderApi.page,
|
|
108
|
+
mode: "manual"
|
|
109
|
+
});
|
|
161
110
|
|
|
162
|
-
<MachTable
|
|
111
|
+
<MachTable<Row> apiRef={table.apiRef} columnDefs={columns} {...query.bindings} />;
|
|
163
112
|
```
|
|
164
113
|
|
|
165
|
-
|
|
114
|
+
该包自动依赖 `@agile-team/mach-table` 并重导出 Core 类型;宿主只需提供 `react` 和 `react-dom >= 18`。
|
|
166
115
|
|
|
167
|
-
|
|
116
|
+
文档:[React 指南](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/react.md) · [企业接入](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/enterprise-integration.md) · [SSR](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/ssr.md)
|
|
168
117
|
|
|
169
|
-
Source-available © ChenyCHENYU (Agile Team).
|
|
118
|
+
Source-available © ChenyCHENYU (Agile Team). 任何使用均须事先取得书面授权。详见 [LICENSE](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSE) 与[授权流程](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSING.md)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');var _client = require('react-dom/client');function s(a){return n=>{let e=document.createElement("div");e.className="mach-cell-react",e.style.width="100%";let t=_client.createRoot.call(void 0, e);t.render(_react.createElement.call(void 0, a,n));let r=!1;return{el:e,refresh:d=>(t.render(_react.createElement.call(void 0, a,d)),!0),destroy:()=>{r||(r=!0,window.setTimeout(()=>{t.unmount()},0))}}}}function c(a){return n=>{let e=document.createElement("div");e.style.height="100%";let t=_client.createRoot.call(void 0, e);t.render(_react.createElement.call(void 0, a,n));let r=!1;return{el:e,destroy:()=>{r||(r=!0,window.setTimeout(()=>{t.unmount()},0))}}}}exports.reactCellRenderer = s; exports.reactDetailRenderer = c;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode, ComponentType } from 'react';
|
|
2
|
+
import { CellRendererParams, RowNode, GridApi, CellRendererFn, DetailRowRendererParams } from '@agile-team/mach-table';
|
|
3
|
+
|
|
4
|
+
interface ReactCellRendererProps<TData = any, TValue = any> extends CellRendererParams<TData, TValue> {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
interface ReactDetailProps<TData = any> {
|
|
8
|
+
data: TData | null;
|
|
9
|
+
node: RowNode<TData>;
|
|
10
|
+
api: GridApi<TData>;
|
|
11
|
+
}
|
|
12
|
+
declare function reactCellRenderer<TData = any, TValue = any>(Component: ComponentType<ReactCellRendererProps<TData, TValue>>): CellRendererFn;
|
|
13
|
+
declare function reactDetailRenderer<TData = any>(Component: ComponentType<ReactDetailProps<TData>>): (params: DetailRowRendererParams<TData>) => {
|
|
14
|
+
el: HTMLElement;
|
|
15
|
+
destroy?: () => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { type ReactCellRendererProps, type ReactDetailProps, reactCellRenderer, reactDetailRenderer };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode, ComponentType } from 'react';
|
|
2
|
+
import { CellRendererParams, RowNode, GridApi, CellRendererFn, DetailRowRendererParams } from '@agile-team/mach-table';
|
|
3
|
+
|
|
4
|
+
interface ReactCellRendererProps<TData = any, TValue = any> extends CellRendererParams<TData, TValue> {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
interface ReactDetailProps<TData = any> {
|
|
8
|
+
data: TData | null;
|
|
9
|
+
node: RowNode<TData>;
|
|
10
|
+
api: GridApi<TData>;
|
|
11
|
+
}
|
|
12
|
+
declare function reactCellRenderer<TData = any, TValue = any>(Component: ComponentType<ReactCellRendererProps<TData, TValue>>): CellRendererFn;
|
|
13
|
+
declare function reactDetailRenderer<TData = any>(Component: ComponentType<ReactDetailProps<TData>>): (params: DetailRowRendererParams<TData>) => {
|
|
14
|
+
el: HTMLElement;
|
|
15
|
+
destroy?: () => void;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { type ReactCellRendererProps, type ReactDetailProps, reactCellRenderer, reactDetailRenderer };
|
package/dist/adapters.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createElement as o,isValidElement as p}from"react";import{createRoot as l}from"react-dom/client";function s(a){return n=>{let e=document.createElement("div");e.className="mach-cell-react",e.style.width="100%";let t=l(e);t.render(o(a,n));let r=!1;return{el:e,refresh:d=>(t.render(o(a,d)),!0),destroy:()=>{r||(r=!0,window.setTimeout(()=>{t.unmount()},0))}}}}function c(a){return n=>{let e=document.createElement("div");e.style.height="100%";let t=l(e);t.render(o(a,n));let r=!1;return{el:e,destroy:()=>{r||(r=!0,window.setTimeout(()=>{t.unmount()},0))}}}}export{s as reactCellRenderer,c as reactDetailRenderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useMemo as n,useState as r}from"react";function o(){let[i,l]=r(null),[u,t]=r(!1);return{apiRef:n(()=>{let a=null;return Object.defineProperty({},"current",{enumerable:!0,get:()=>a,set:e=>{e!==a&&(a=e,l(e),t(!1),e&&e.whenReady().then(()=>{a===e&&!e.isDestroyed()&&t(!0)}))}})},[]),api:i,ready:u}}export{o as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _react = require('react');function o(){let[i,l]=_react.useState.call(void 0, null),[u,t]=_react.useState.call(void 0, !1);return{apiRef:_react.useMemo.call(void 0, ()=>{let a=null;return Object.defineProperty({},"current",{enumerable:!0,get:()=>a,set:e=>{e!==a&&(a=e,l(e),t(!1),e&&e.whenReady().then(()=>{a===e&&!e.isDestroyed()&&t(!0)}))}})},[]),api:i,ready:u}}exports.a = o;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkII7TCYIUcjs = require('./chunk-II7TCYIU.cjs');var _react = require('react');var _machtable = require('@agile-team/mach-table'); _createStarExport(_machtable);var _adapter = require('@agile-team/mach-table/adapter');var w=_adapter.normalizeMachTableConfig.call(void 0, ),T=_react.createContext.call(void 0, w);function S({config:e,children:o}){let t=_react.useContext.call(void 0, T),r=_react.useMemo.call(void 0, ()=>_adapter.mergeMachTableConfig.call(void 0, t,_nullishCoalesce(e, () => ({}))),[t,e]);return _react.createElement.call(void 0, T.Provider,{value:r},o)}function h(){return _react.useContext.call(void 0, T)}function V(e){return`on${e.charAt(0).toUpperCase()}${e.slice(1)}`}function $(e,o){let t={};for(let r of _adapter.GRID_OPTION_KEYS){if(r==="className")continue;let c=r==="ariaLabel"?e.gridAriaLabel:r==="ariaLabelledBy"?e.gridAriaLabelledBy:r==="ariaDescribedBy"?e.gridAriaDescribedBy:e[r];c!==void 0&&(t[r]=c)}return e.gridClassName!==void 0&&(t.className=e.gridClassName),_adapter.resolveMachTableGridOptions.call(void 0, o,e.preset,t).options}function P(e){let{className:o,style:t,apiRef:r}=e,c=_react.useRef.call(void 0, null),u=_react.useRef.call(void 0, null),M=_react.useRef.call(void 0, e);M.current=e;let R=h(),p=[R,e.preset,..._adapter.GRID_OPTION_KEYS.map(a=>a==="className"?e.gridClassName:a==="ariaLabel"?e.gridAriaLabel:a==="ariaLabelledBy"?e.gridAriaLabelledBy:a==="ariaDescribedBy"?e.gridAriaDescribedBy:e[a])],l=_react.useRef.call(void 0, null);(!l.current||l.current.inputs.length!==p.length||p.some((a,n)=>!Object.is(a,_optionalChain([l, 'access', _2 => _2.current, 'optionalAccess', _3 => _3.inputs, 'access', _4 => _4[n]]))))&&(l.current={inputs:p,options:$(e,R)});let m=l.current.options,O=_react.useRef.call(void 0, m);O.current=m,_react.useEffect.call(void 0, ()=>{let a=c.current;if(!a)return;let n={...O.current};for(let d of _machtable.EVENT_TYPES){let f=V(d);n[f]=N=>{let v=M.current[f];typeof v=="function"&&v(N)}}let s=_machtable.createGrid.call(void 0, a,n);return u.current=s,()=>{s.destroy(),u.current=null}},[]),_react.useEffect.call(void 0, ()=>{if(!r)return;let a=u.current;return r.current=a,()=>{r.current===a&&(r.current=null)}},[r]);let g=_adapter.GRID_OPTION_KEYS.map(a=>m[a]),C=_react.useRef.call(void 0, null);return _react.useEffect.call(void 0, ()=>{let a=C.current;if(C.current=g,!a)return;let n={};g.forEach((s,d)=>{if(Object.is(s,a[d]))return;let f=_adapter.GRID_OPTION_KEYS[d];n[f]=s}),Object.keys(n).length>0&&_optionalChain([u, 'access', _5 => _5.current, 'optionalAccess', _6 => _6.updateOptions, 'call', _7 => _7(n)])},g),_react.createElement.call(void 0, "div",{ref:c,className:`mach-react-host ${_nullishCoalesce(o, () => (""))}`.trim()||void 0,style:t,"aria-label":e["aria-label"],"aria-labelledby":e["aria-labelledby"],"aria-describedby":e["aria-describedby"]})}var W=P;exports.MachTable = P; exports.MachTableProvider = S; exports.default = W; exports.useMachTable = _chunkII7TCYIUcjs.a; exports.useMachTableConfig = h;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { CSSProperties, MutableRefObject, ReactNode
|
|
3
|
-
import { GridOptions, MachTablePresetSelection, GridApi,
|
|
2
|
+
import { CSSProperties, MutableRefObject, ReactNode } from 'react';
|
|
3
|
+
import { GridOptions, MachTablePresetSelection, GridApi, MachTableRuntimeConfig, ResolvedMachTableConfig } from '@agile-team/mach-table';
|
|
4
4
|
export * from '@agile-team/mach-table';
|
|
5
|
-
export {
|
|
5
|
+
export { U as UseMachTableReturn, u as useMachTable } from './useMachTable-lL575Wzq.cjs';
|
|
6
6
|
|
|
7
7
|
type AdapterOnlyGridOption = "className" | "ariaLabel" | "ariaLabelledBy" | "ariaDescribedBy";
|
|
8
8
|
type MachTableReactProps<TData = any> = Omit<GridOptions<TData>, AdapterOnlyGridOption> & {
|
|
@@ -29,66 +29,14 @@ declare function MachTable<TData = any>(props: MachTableReactProps<TData>): reac
|
|
|
29
29
|
"aria-labelledby": string | undefined;
|
|
30
30
|
"aria-describedby": string | undefined;
|
|
31
31
|
}, HTMLDivElement>;
|
|
32
|
-
/** @deprecated Use MachTable. Kept as a source-compatible alias through 0.x. */
|
|
33
|
-
declare const RobotGrid: typeof MachTable;
|
|
34
|
-
/** @deprecated Use MachTableReactProps. */
|
|
35
|
-
type RobotGridReactProps<TData = any> = MachTableReactProps<TData>;
|
|
36
32
|
|
|
37
|
-
interface
|
|
38
|
-
search?: boolean;
|
|
39
|
-
refresh?: boolean;
|
|
40
|
-
columns?: boolean;
|
|
41
|
-
density?: boolean;
|
|
42
|
-
export?: boolean;
|
|
43
|
-
undoRedo?: boolean;
|
|
44
|
-
fullscreen?: boolean;
|
|
45
|
-
}
|
|
46
|
-
interface MachTableToolbarProps<TData = any> {
|
|
47
|
-
api?: GridApi<TData> | null;
|
|
48
|
-
commands?: MachTableCommands | null;
|
|
49
|
-
search?: string;
|
|
50
|
-
onSearchChange?(value: string): void;
|
|
51
|
-
onRefresh?(): void;
|
|
52
|
-
onClearSelection?(): void;
|
|
53
|
-
loading?: boolean;
|
|
54
|
-
selectedCount?: number;
|
|
55
|
-
searchPlaceholder?: string;
|
|
56
|
-
exportFilename?: string;
|
|
57
|
-
features?: MachTableToolbarFeatures;
|
|
58
|
-
start?: ReactNode;
|
|
59
|
-
children?: ReactNode;
|
|
60
|
-
end?: ReactNode;
|
|
61
|
-
}
|
|
62
|
-
declare function MachTableToolbar<TData = any>(props: MachTableToolbarProps<TData>): react.DetailedReactHTMLElement<{
|
|
63
|
-
className: string;
|
|
64
|
-
role: "toolbar";
|
|
65
|
-
"aria-label": string;
|
|
66
|
-
}, HTMLElement>;
|
|
67
|
-
|
|
68
|
-
interface MachTableProviderProps<TData = any> {
|
|
33
|
+
interface MachTableProviderProps {
|
|
69
34
|
/** Full app/route configuration. Prefer importing this from mach-table.config.ts. */
|
|
70
35
|
config?: MachTableRuntimeConfig;
|
|
71
|
-
/** Backwards-compatible shorthand for config.defaults. */
|
|
72
|
-
defaults?: Partial<GridOptions<TData>>;
|
|
73
36
|
children?: ReactNode;
|
|
74
37
|
}
|
|
75
38
|
/** Supplies app-, route- or layout-scoped defaults without making tables eager. */
|
|
76
|
-
declare function MachTableProvider
|
|
77
|
-
declare function useMachTableDefaults<TData = any>(): Partial<GridOptions<TData>>;
|
|
39
|
+
declare function MachTableProvider({ config, children }: MachTableProviderProps): react.FunctionComponentElement<react.ProviderProps<ResolvedMachTableConfig>>;
|
|
78
40
|
declare function useMachTableConfig(): ResolvedMachTableConfig;
|
|
79
41
|
|
|
80
|
-
|
|
81
|
-
children?: ReactNode;
|
|
82
|
-
}
|
|
83
|
-
interface ReactDetailProps<TData = any> {
|
|
84
|
-
data: TData | null;
|
|
85
|
-
node: RowNode<TData>;
|
|
86
|
-
api: GridApi<TData>;
|
|
87
|
-
}
|
|
88
|
-
declare function reactCellRenderer<TData = any, TValue = any>(Component: ComponentType<ReactCellRendererProps<TData, TValue>>): CellRendererFn;
|
|
89
|
-
declare function reactDetailRenderer<TData = any>(Component: ComponentType<ReactDetailProps<TData>>): (params: DetailRowRendererParams<TData>) => {
|
|
90
|
-
el: HTMLElement;
|
|
91
|
-
destroy?: () => void;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export { MachTable, MachTableProvider, type MachTableProviderProps, type MachTableReactProps, MachTableToolbar, type MachTableToolbarFeatures, type MachTableToolbarProps, type ReactCellRendererProps, type ReactDetailProps, RobotGrid, type RobotGridReactProps, MachTable as default, reactCellRenderer, reactDetailRenderer, useMachTableConfig, useMachTableDefaults };
|
|
42
|
+
export { MachTable, MachTableProvider, type MachTableProviderProps, type MachTableReactProps, MachTable as default, useMachTableConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { CSSProperties, MutableRefObject, ReactNode
|
|
3
|
-
import { GridOptions, MachTablePresetSelection, GridApi,
|
|
2
|
+
import { CSSProperties, MutableRefObject, ReactNode } from 'react';
|
|
3
|
+
import { GridOptions, MachTablePresetSelection, GridApi, MachTableRuntimeConfig, ResolvedMachTableConfig } from '@agile-team/mach-table';
|
|
4
4
|
export * from '@agile-team/mach-table';
|
|
5
|
-
export {
|
|
5
|
+
export { U as UseMachTableReturn, u as useMachTable } from './useMachTable-lL575Wzq.js';
|
|
6
6
|
|
|
7
7
|
type AdapterOnlyGridOption = "className" | "ariaLabel" | "ariaLabelledBy" | "ariaDescribedBy";
|
|
8
8
|
type MachTableReactProps<TData = any> = Omit<GridOptions<TData>, AdapterOnlyGridOption> & {
|
|
@@ -29,66 +29,14 @@ declare function MachTable<TData = any>(props: MachTableReactProps<TData>): reac
|
|
|
29
29
|
"aria-labelledby": string | undefined;
|
|
30
30
|
"aria-describedby": string | undefined;
|
|
31
31
|
}, HTMLDivElement>;
|
|
32
|
-
/** @deprecated Use MachTable. Kept as a source-compatible alias through 0.x. */
|
|
33
|
-
declare const RobotGrid: typeof MachTable;
|
|
34
|
-
/** @deprecated Use MachTableReactProps. */
|
|
35
|
-
type RobotGridReactProps<TData = any> = MachTableReactProps<TData>;
|
|
36
32
|
|
|
37
|
-
interface
|
|
38
|
-
search?: boolean;
|
|
39
|
-
refresh?: boolean;
|
|
40
|
-
columns?: boolean;
|
|
41
|
-
density?: boolean;
|
|
42
|
-
export?: boolean;
|
|
43
|
-
undoRedo?: boolean;
|
|
44
|
-
fullscreen?: boolean;
|
|
45
|
-
}
|
|
46
|
-
interface MachTableToolbarProps<TData = any> {
|
|
47
|
-
api?: GridApi<TData> | null;
|
|
48
|
-
commands?: MachTableCommands | null;
|
|
49
|
-
search?: string;
|
|
50
|
-
onSearchChange?(value: string): void;
|
|
51
|
-
onRefresh?(): void;
|
|
52
|
-
onClearSelection?(): void;
|
|
53
|
-
loading?: boolean;
|
|
54
|
-
selectedCount?: number;
|
|
55
|
-
searchPlaceholder?: string;
|
|
56
|
-
exportFilename?: string;
|
|
57
|
-
features?: MachTableToolbarFeatures;
|
|
58
|
-
start?: ReactNode;
|
|
59
|
-
children?: ReactNode;
|
|
60
|
-
end?: ReactNode;
|
|
61
|
-
}
|
|
62
|
-
declare function MachTableToolbar<TData = any>(props: MachTableToolbarProps<TData>): react.DetailedReactHTMLElement<{
|
|
63
|
-
className: string;
|
|
64
|
-
role: "toolbar";
|
|
65
|
-
"aria-label": string;
|
|
66
|
-
}, HTMLElement>;
|
|
67
|
-
|
|
68
|
-
interface MachTableProviderProps<TData = any> {
|
|
33
|
+
interface MachTableProviderProps {
|
|
69
34
|
/** Full app/route configuration. Prefer importing this from mach-table.config.ts. */
|
|
70
35
|
config?: MachTableRuntimeConfig;
|
|
71
|
-
/** Backwards-compatible shorthand for config.defaults. */
|
|
72
|
-
defaults?: Partial<GridOptions<TData>>;
|
|
73
36
|
children?: ReactNode;
|
|
74
37
|
}
|
|
75
38
|
/** Supplies app-, route- or layout-scoped defaults without making tables eager. */
|
|
76
|
-
declare function MachTableProvider
|
|
77
|
-
declare function useMachTableDefaults<TData = any>(): Partial<GridOptions<TData>>;
|
|
39
|
+
declare function MachTableProvider({ config, children }: MachTableProviderProps): react.FunctionComponentElement<react.ProviderProps<ResolvedMachTableConfig>>;
|
|
78
40
|
declare function useMachTableConfig(): ResolvedMachTableConfig;
|
|
79
41
|
|
|
80
|
-
|
|
81
|
-
children?: ReactNode;
|
|
82
|
-
}
|
|
83
|
-
interface ReactDetailProps<TData = any> {
|
|
84
|
-
data: TData | null;
|
|
85
|
-
node: RowNode<TData>;
|
|
86
|
-
api: GridApi<TData>;
|
|
87
|
-
}
|
|
88
|
-
declare function reactCellRenderer<TData = any, TValue = any>(Component: ComponentType<ReactCellRendererProps<TData, TValue>>): CellRendererFn;
|
|
89
|
-
declare function reactDetailRenderer<TData = any>(Component: ComponentType<ReactDetailProps<TData>>): (params: DetailRowRendererParams<TData>) => {
|
|
90
|
-
el: HTMLElement;
|
|
91
|
-
destroy?: () => void;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export { MachTable, MachTableProvider, type MachTableProviderProps, type MachTableReactProps, MachTableToolbar, type MachTableToolbarFeatures, type MachTableToolbarProps, type ReactCellRendererProps, type ReactDetailProps, RobotGrid, type RobotGridReactProps, MachTable as default, reactCellRenderer, reactDetailRenderer, useMachTableConfig, useMachTableDefaults };
|
|
42
|
+
export { MachTable, MachTableProvider, type MachTableProviderProps, type MachTableReactProps, MachTable as default, useMachTableConfig };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as x}from"./chunk-FN4LWAOL.js";import{createElement as k,useEffect as y,useRef as i}from"react";import{createGrid as j,EVENT_TYPES as I}from"@agile-team/mach-table";import{GRID_OPTION_KEYS as b,resolveMachTableGridOptions as _}from"@agile-team/mach-table/adapter";import{createContext as A,createElement as G,useContext as D,useMemo as L}from"react";import{mergeMachTableConfig as B,normalizeMachTableConfig as E}from"@agile-team/mach-table/adapter";var w=E(),T=A(w);function S({config:e,children:o}){let t=D(T),r=L(()=>B(t,e??{}),[t,e]);return G(T.Provider,{value:r},o)}function h(){return D(T)}function V(e){return`on${e.charAt(0).toUpperCase()}${e.slice(1)}`}function $(e,o){let t={};for(let r of b){if(r==="className")continue;let c=r==="ariaLabel"?e.gridAriaLabel:r==="ariaLabelledBy"?e.gridAriaLabelledBy:r==="ariaDescribedBy"?e.gridAriaDescribedBy:e[r];c!==void 0&&(t[r]=c)}return e.gridClassName!==void 0&&(t.className=e.gridClassName),_(o,e.preset,t).options}function P(e){let{className:o,style:t,apiRef:r}=e,c=i(null),u=i(null),M=i(e);M.current=e;let R=h(),p=[R,e.preset,...b.map(a=>a==="className"?e.gridClassName:a==="ariaLabel"?e.gridAriaLabel:a==="ariaLabelledBy"?e.gridAriaLabelledBy:a==="ariaDescribedBy"?e.gridAriaDescribedBy:e[a])],l=i(null);(!l.current||l.current.inputs.length!==p.length||p.some((a,n)=>!Object.is(a,l.current?.inputs[n])))&&(l.current={inputs:p,options:$(e,R)});let m=l.current.options,O=i(m);O.current=m,y(()=>{let a=c.current;if(!a)return;let n={...O.current};for(let d of I){let f=V(d);n[f]=N=>{let v=M.current[f];typeof v=="function"&&v(N)}}let s=j(a,n);return u.current=s,()=>{s.destroy(),u.current=null}},[]),y(()=>{if(!r)return;let a=u.current;return r.current=a,()=>{r.current===a&&(r.current=null)}},[r]);let g=b.map(a=>m[a]),C=i(null);return y(()=>{let a=C.current;if(C.current=g,!a)return;let n={};g.forEach((s,d)=>{if(Object.is(s,a[d]))return;let f=b[d];n[f]=s}),Object.keys(n).length>0&&u.current?.updateOptions(n)},g),k("div",{ref:c,className:`mach-react-host ${o??""}`.trim()||void 0,style:t,"aria-label":e["aria-label"],"aria-labelledby":e["aria-labelledby"],"aria-describedby":e["aria-describedby"]})}export*from"@agile-team/mach-table";var W=P;export{P as MachTable,S as MachTableProvider,W as default,x as useMachTable,h as useMachTableConfig};
|
package/dist/ui.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _react = require('react');var r={search:!0,refresh:!0,columns:!0,density:!0,export:!0,undoRedo:!1,fullscreen:!1};function o(e,a){return _nullishCoalesce(_optionalChain([e, 'optionalAccess', _ => _[a]]), () => (r[a]))}function c(e,a,i,t=!1){return _react.createElement.call(void 0, "button",{key:e,type:"button",className:"mach-toolbar__button",title:e,"aria-label":e,disabled:t,onClick:i},a)}function s(e){let a=[e.start],i=_nullishCoalesce(e.searchPlaceholder, () => ("\u641C\u7D22\u5F53\u524D\u7ED3\u679C"));return o(e.features,"search")&&a.push(_react.createElement.call(void 0, "label",{className:"mach-toolbar__search",key:"search"},_react.createElement.call(void 0, "span",{className:"mach-sr-only"},i),_react.createElement.call(void 0, "span",{"aria-hidden":!0},"\u2315"),_react.createElement.call(void 0, "input",{type:"search",value:_nullishCoalesce(e.search, () => ("")),placeholder:i,onChange:t=>{let l=t.currentTarget.value;_optionalChain([e, 'access', _2 => _2.onSearchChange, 'optionalCall', _3 => _3(l)]),e.onSearchChange||(e.commands?e.commands.search(l||null):_optionalChain([e, 'access', _4 => _4.api, 'optionalAccess', _5 => _5.filtering, 'access', _6 => _6.setQuickText, 'call', _7 => _7(l||null)]))}}))),o(e.features,"refresh")&&a.push(c("\u5237\u65B0",e.loading?"\u2026":"\u21BB",()=>{_optionalChain([e, 'access', _8 => _8.onRefresh, 'optionalCall', _9 => _9()]),e.onRefresh||(e.commands?e.commands.refresh():_optionalChain([e, 'access', _10 => _10.api, 'optionalAccess', _11 => _11.rows, 'access', _12 => _12.isRemote, 'call', _13 => _13()])?e.api.rows.reload():_optionalChain([e, 'access', _14 => _14.api, 'optionalAccess', _15 => _15.view, 'access', _16 => _16.refreshCells, 'call', _17 => _17()]))},e.loading)),o(e.features,"columns")&&a.push(c("\u5217\u8BBE\u7F6E","\u2637",t=>{e.commands?e.commands.openColumns(t.currentTarget):_optionalChain([e, 'access', _18 => _18.api, 'optionalAccess', _19 => _19.columns, 'access', _20 => _20.openWorkbench, 'call', _21 => _21(t.currentTarget)])})),o(e.features,"density")&&a.push(_react.createElement.call(void 0, "select",{key:"density",className:"mach-toolbar__select",value:_nullishCoalesce(_optionalChain([e, 'access', _22 => _22.api, 'optionalAccess', _23 => _23.getOption, 'call', _24 => _24("size")]), () => ("normal")),"aria-label":"\u8868\u683C\u5BC6\u5EA6",onChange:t=>{let l=t.currentTarget.value;e.commands?e.commands.setDensity(l):_optionalChain([e, 'access', _25 => _25.api, 'optionalAccess', _26 => _26.updateOptions, 'call', _27 => _27({size:l})])}},_react.createElement.call(void 0, "option",{value:"compact"},"\u7D27\u51D1"),_react.createElement.call(void 0, "option",{value:"normal"},"\u6807\u51C6"),_react.createElement.call(void 0, "option",{value:"large"},"\u5BBD\u677E"))),a.push(e.children),a}function d(e){let a=[];return(_nullishCoalesce(e.selectedCount, () => (0)))>0&&a.push(_react.createElement.call(void 0, "button",{key:"selection",type:"button",className:"mach-toolbar__selection",onClick:()=>_optionalChain([e, 'access', _28 => _28.onClearSelection, 'optionalCall', _29 => _29()])},`\u5DF2\u9009 ${e.selectedCount} \u9879 \xD7`)),o(e.features,"undoRedo")&&(a.push(c("\u64A4\u9500","\u21B6",()=>{e.commands?e.commands.undo():_optionalChain([e, 'access', _30 => _30.api, 'optionalAccess', _31 => _31.editing, 'access', _32 => _32.undo, 'call', _33 => _33()])},e.commands?!e.commands.canUndo():!_optionalChain([e, 'access', _34 => _34.api, 'optionalAccess', _35 => _35.editing, 'access', _36 => _36.canUndo, 'call', _37 => _37()]))),a.push(c("\u91CD\u505A","\u21B7",()=>{e.commands?e.commands.redo():_optionalChain([e, 'access', _38 => _38.api, 'optionalAccess', _39 => _39.editing, 'access', _40 => _40.redo, 'call', _41 => _41()])},e.commands?!e.commands.canRedo():!_optionalChain([e, 'access', _42 => _42.api, 'optionalAccess', _43 => _43.editing, 'access', _44 => _44.canRedo, 'call', _45 => _45()])))),o(e.features,"export")&&a.push(c("\u5BFC\u51FA CSV","\u21E9",()=>{_optionalChain([e, 'access', _46 => _46.commands, 'optionalAccess', _47 => _47.exportCsv, 'call', _48 => _48(e.exportFilename)])},!e.commands)),o(e.features,"fullscreen")&&a.push(c("\u5168\u5C4F","\u26F6",()=>{_optionalChain([e, 'access', _49 => _49.commands, 'optionalAccess', _50 => _50.toggleFullscreen, 'call', _51 => _51()])},!e.commands)),a.push(e.end),a}function u(e){return _react.createElement.call(void 0, "div",{className:"mach-toolbar",role:"toolbar","aria-label":"\u8868\u683C\u5DE5\u5177\u680F"},_react.createElement.call(void 0, "div",{className:"mach-toolbar__main"},...s(e)),_react.createElement.call(void 0, "div",{className:"mach-toolbar__aside"},...d(e)))}exports.MachTableToolbar = u;
|
package/dist/ui.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { GridApi, MachTableCommands } from '@agile-team/mach-table';
|
|
4
|
+
|
|
5
|
+
interface MachTableToolbarFeatures {
|
|
6
|
+
search?: boolean;
|
|
7
|
+
refresh?: boolean;
|
|
8
|
+
columns?: boolean;
|
|
9
|
+
density?: boolean;
|
|
10
|
+
export?: boolean;
|
|
11
|
+
undoRedo?: boolean;
|
|
12
|
+
fullscreen?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface MachTableToolbarProps<TData = any> {
|
|
15
|
+
api?: GridApi<TData> | null;
|
|
16
|
+
commands?: MachTableCommands | null;
|
|
17
|
+
search?: string;
|
|
18
|
+
onSearchChange?(value: string): void;
|
|
19
|
+
onRefresh?(): void;
|
|
20
|
+
onClearSelection?(): void;
|
|
21
|
+
loading?: boolean;
|
|
22
|
+
selectedCount?: number;
|
|
23
|
+
searchPlaceholder?: string;
|
|
24
|
+
exportFilename?: string;
|
|
25
|
+
features?: MachTableToolbarFeatures;
|
|
26
|
+
start?: ReactNode;
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
end?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
declare function MachTableToolbar<TData = any>(props: MachTableToolbarProps<TData>): react.DetailedReactHTMLElement<{
|
|
31
|
+
className: string;
|
|
32
|
+
role: "toolbar";
|
|
33
|
+
"aria-label": string;
|
|
34
|
+
}, HTMLElement>;
|
|
35
|
+
|
|
36
|
+
export { MachTableToolbar, type MachTableToolbarFeatures, type MachTableToolbarProps };
|
package/dist/ui.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { GridApi, MachTableCommands } from '@agile-team/mach-table';
|
|
4
|
+
|
|
5
|
+
interface MachTableToolbarFeatures {
|
|
6
|
+
search?: boolean;
|
|
7
|
+
refresh?: boolean;
|
|
8
|
+
columns?: boolean;
|
|
9
|
+
density?: boolean;
|
|
10
|
+
export?: boolean;
|
|
11
|
+
undoRedo?: boolean;
|
|
12
|
+
fullscreen?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface MachTableToolbarProps<TData = any> {
|
|
15
|
+
api?: GridApi<TData> | null;
|
|
16
|
+
commands?: MachTableCommands | null;
|
|
17
|
+
search?: string;
|
|
18
|
+
onSearchChange?(value: string): void;
|
|
19
|
+
onRefresh?(): void;
|
|
20
|
+
onClearSelection?(): void;
|
|
21
|
+
loading?: boolean;
|
|
22
|
+
selectedCount?: number;
|
|
23
|
+
searchPlaceholder?: string;
|
|
24
|
+
exportFilename?: string;
|
|
25
|
+
features?: MachTableToolbarFeatures;
|
|
26
|
+
start?: ReactNode;
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
end?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
declare function MachTableToolbar<TData = any>(props: MachTableToolbarProps<TData>): react.DetailedReactHTMLElement<{
|
|
31
|
+
className: string;
|
|
32
|
+
role: "toolbar";
|
|
33
|
+
"aria-label": string;
|
|
34
|
+
}, HTMLElement>;
|
|
35
|
+
|
|
36
|
+
export { MachTableToolbar, type MachTableToolbarFeatures, type MachTableToolbarProps };
|
package/dist/ui.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createElement as n}from"react";var r={search:!0,refresh:!0,columns:!0,density:!0,export:!0,undoRedo:!1,fullscreen:!1};function o(e,a){return e?.[a]??r[a]}function c(e,a,i,t=!1){return n("button",{key:e,type:"button",className:"mach-toolbar__button",title:e,"aria-label":e,disabled:t,onClick:i},a)}function s(e){let a=[e.start],i=e.searchPlaceholder??"\u641C\u7D22\u5F53\u524D\u7ED3\u679C";return o(e.features,"search")&&a.push(n("label",{className:"mach-toolbar__search",key:"search"},n("span",{className:"mach-sr-only"},i),n("span",{"aria-hidden":!0},"\u2315"),n("input",{type:"search",value:e.search??"",placeholder:i,onChange:t=>{let l=t.currentTarget.value;e.onSearchChange?.(l),e.onSearchChange||(e.commands?e.commands.search(l||null):e.api?.filtering.setQuickText(l||null))}}))),o(e.features,"refresh")&&a.push(c("\u5237\u65B0",e.loading?"\u2026":"\u21BB",()=>{e.onRefresh?.(),e.onRefresh||(e.commands?e.commands.refresh():e.api?.rows.isRemote()?e.api.rows.reload():e.api?.view.refreshCells())},e.loading)),o(e.features,"columns")&&a.push(c("\u5217\u8BBE\u7F6E","\u2637",t=>{e.commands?e.commands.openColumns(t.currentTarget):e.api?.columns.openWorkbench(t.currentTarget)})),o(e.features,"density")&&a.push(n("select",{key:"density",className:"mach-toolbar__select",value:e.api?.getOption("size")??"normal","aria-label":"\u8868\u683C\u5BC6\u5EA6",onChange:t=>{let l=t.currentTarget.value;e.commands?e.commands.setDensity(l):e.api?.updateOptions({size:l})}},n("option",{value:"compact"},"\u7D27\u51D1"),n("option",{value:"normal"},"\u6807\u51C6"),n("option",{value:"large"},"\u5BBD\u677E"))),a.push(e.children),a}function d(e){let a=[];return(e.selectedCount??0)>0&&a.push(n("button",{key:"selection",type:"button",className:"mach-toolbar__selection",onClick:()=>e.onClearSelection?.()},`\u5DF2\u9009 ${e.selectedCount} \u9879 \xD7`)),o(e.features,"undoRedo")&&(a.push(c("\u64A4\u9500","\u21B6",()=>{e.commands?e.commands.undo():e.api?.editing.undo()},e.commands?!e.commands.canUndo():!e.api?.editing.canUndo())),a.push(c("\u91CD\u505A","\u21B7",()=>{e.commands?e.commands.redo():e.api?.editing.redo()},e.commands?!e.commands.canRedo():!e.api?.editing.canRedo()))),o(e.features,"export")&&a.push(c("\u5BFC\u51FA CSV","\u21E9",()=>{e.commands?.exportCsv(e.exportFilename)},!e.commands)),o(e.features,"fullscreen")&&a.push(c("\u5168\u5C4F","\u26F6",()=>{e.commands?.toggleFullscreen()},!e.commands)),a.push(e.end),a}function u(e){return n("div",{className:"mach-toolbar",role:"toolbar","aria-label":"\u8868\u683C\u5DE5\u5177\u680F"},n("div",{className:"mach-toolbar__main"},...s(e)),n("div",{className:"mach-toolbar__aside"},...d(e)))}export{u as MachTableToolbar};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
import { GridApi } from '@agile-team/mach-table';
|
|
3
|
+
|
|
4
|
+
interface UseMachTableReturn<TData = any> {
|
|
5
|
+
apiRef: MutableRefObject<GridApi<TData> | null>;
|
|
6
|
+
api: GridApi<TData> | null;
|
|
7
|
+
ready: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Reactive access to the table lifecycle and command API. */
|
|
10
|
+
declare function useMachTable<TData = any>(): UseMachTableReturn<TData>;
|
|
11
|
+
|
|
12
|
+
export { type UseMachTableReturn as U, useMachTable as u };
|