@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 CHANGED
@@ -4,166 +4,115 @@
4
4
 
5
5
  # @agile-team/mach-table-react
6
6
 
7
- Official React 18+ adapter for MachTable 0.23. It provides a generic `<MachTable>`, full app/route configuration, advanced-filter aware remote query, conflict-aware editing workflows, persistent named views, a cohesive controller, optional and persistent column resizing, bounded random-access remote blocks, governed domain APIs, optional Worker processing, a standard toolbar, in-place React cell refresh, latest-closure event handling and StrictMode-safe cleanup. `RobotGrid` remains a deprecated 0.x alias.
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
- Optional large local-data Worker helpers use the same installed package but a separate chunk:
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
- ## Direct import
19
+ ## 基础接入
28
20
 
29
21
  ```tsx
30
22
  import { useMemo } from "react";
31
- import { MachTable, useMachGrid, type ColDef } from "@agile-team/mach-table-react";
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 App({ rows }: { rows: Row[] }) {
36
- const grid = useMachGrid<Row>();
27
+ export function Customers({ rows }: { rows: Row[] }) {
28
+ const table = useMachTable<Row>();
37
29
  const columns = useMemo<ColDef<Row>[]>(
38
- () => [{ field: "name", headerName: "Name", flex: 1 }],
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={grid.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
- ## Route-level lazy loading
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
- ## Application and route defaults
51
+ ## 应用配置
78
52
 
79
- Keep table conventions in one file. Providers can be nested; the nearest configuration is merged, named presets are reusable, and explicit table props win:
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, resizable: true, filter: true }
62
+ defaultColDef: { sortable: true, filter: true, resizable: true }
89
63
  },
90
64
  defaultPreset: "list",
91
65
  presets: {
92
- list: defineMachTablePreset({ pagination: false }),
66
+ list: defineMachTablePreset({ stripedRows: true }),
93
67
  crud: defineMachTablePreset({ rowSelection: "multiple", editType: "fullRow" })
94
68
  }
95
69
  });
70
+ ```
96
71
 
97
- // main.tsx
72
+ ```tsx
98
73
  <MachTableProvider config={machTableConfig}>
99
74
  <App />
100
75
  </MachTableProvider>
101
76
  ```
102
77
 
103
- The adapter installs the matching `@agile-team/mach-table` core automatically and re-exports its complete API and types. Only `react >= 18` and `react-dom >= 18` remain peer dependencies supplied by the host application.
78
+ Provider 可按路由/布局嵌套,最近一层覆盖外层,表格 props 优先级最高。
104
79
 
105
- ## Remote lists and standard workflows
80
+ ## 按需加载
106
81
 
107
- Import heavier page workflows from the tree-shakeable subpath:
82
+ React 不模拟全局组件注册。路由本身懒加载时普通 import 已自然拆包;需要独立边界时:
108
83
 
109
84
  ```tsx
110
- import { useMachTableQuery, useMachTableController } from "@agile-team/mach-table-react/workflows";
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
- The query hook cancels superseded requests, ignores stale responses, forwards nested advanced filters, exposes an error overlay and supports cross-page or select-all-matching selection. `useMachTableEditing()` adds dirty state, detailed partial-save/conflict results, guarded saves, conflict resolution, rollback and reveal helpers.
88
+ 可选能力使用子入口:
133
89
 
134
90
  ```tsx
135
- const editing = useMachTableEditing(grid, { guardBeforeUnload: true });
136
- const result = await editing.saveDetailed(orderApi.saveChanges);
137
- if (result.conflicts.length) editing.reveal(result.conflicts[0].rowId);
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
- See the [advanced filter](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/advanced-filter.md), [named views](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/saved-views.md), and [batch save](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/batch-save.md) guides.
150
-
151
- ## Cell and full-row editing
97
+ - `/workflows`:请求取消、防过期覆盖、服务端分页、跨页选择、脏数据和冲突保存。
98
+ - `/ui`:可选标准工具栏。
99
+ - `/adapters`:自定义 React cell/detail renderer 桥接。
100
+ - `/worker`:大型本地过滤/排序的独立 Worker 能力。
152
101
 
153
102
  ```tsx
154
- import { MachTable, rowActionsColumn } from "@agile-team/mach-table-react";
155
-
156
- const columns = [
157
- { field: "name", editable: true },
158
- { field: "age", editable: true, cellEditor: "number" },
159
- rowActionsColumn({ onView, onDelete, overflow: "drawer" })
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 editType="fullRow" columnDefs={columns} rowData={rows} />;
111
+ <MachTable<Row> apiRef={table.apiRef} columnDefs={columns} {...query.bindings} />;
163
112
  ```
164
113
 
165
- Cell mode is the default and provides a pencil plus inline confirm/cancel controls. Use `editableIndicator="always" | "hover" | "none"` to match the page density.
114
+ 该包自动依赖 `@agile-team/mach-table` 并重导出 Core 类型;宿主只需提供 `react` 和 `react-dom >= 18`。
166
115
 
167
- Documentation: [React guide](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/react.md) · [Enterprise integration](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/enterprise-integration.md) · [Next.js / SSR](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/ssr.md)
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). Any use requires prior written authorization. See the [license](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSE) and [authorization process](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSING.md).
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 };
@@ -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 _chunkMFRKW34Vcjs = require('./chunk-MFRKW34V.cjs');var _react = require('react');var _machtable = require('@agile-team/mach-table'); _createStarExport(_machtable);var I=_machtable.normalizeMachTableConfig.call(void 0, ),T=_react.createContext.call(void 0, I);function Q({config:e,defaults:a,children:r}){let t=_react.useContext.call(void 0, T),n=_react.useMemo.call(void 0, ()=>_machtable.mergeMachTableConfig.call(void 0, t,{..._nullishCoalesce(e, () => ({})),...a?{defaults:a}:{}}),[t,e,a]);return _react.createElement.call(void 0, T.Provider,{value:n},r)}function j(){return _react.useContext.call(void 0, T).defaults}function P(){return _react.useContext.call(void 0, T)}function W(e,a){let r={};for(let t of _machtable.GRID_OPTION_KEYS){if(t==="className")continue;let n=t==="ariaLabel"?e.gridAriaLabel:t==="ariaLabelledBy"?e.gridAriaLabelledBy:t==="ariaDescribedBy"?e.gridAriaDescribedBy:e[t];n!==void 0&&(r[t]=n)}return e.gridClassName!==void 0&&(r.className=e.gridClassName),_machtable.resolveMachTableGridOptions.call(void 0, a,e.preset,r).options}function N(e){let{className:a,style:r,apiRef:t}=e,n=_react.useRef.call(void 0, null),s=_react.useRef.call(void 0, null),O=_react.useRef.call(void 0, e);O.current=e;let E=P(),y=[E,e.preset,..._machtable.GRID_OPTION_KEYS.map(o=>o==="className"?e.gridClassName:o==="ariaLabel"?e.gridAriaLabel:o==="ariaLabelledBy"?e.gridAriaLabelledBy:o==="ariaDescribedBy"?e.gridAriaDescribedBy:e[o])],m=_react.useRef.call(void 0, null);(!m.current||m.current.inputs.length!==y.length||y.some((o,i)=>!Object.is(o,_optionalChain([m, 'access', _2 => _2.current, 'optionalAccess', _3 => _3.inputs, 'access', _4 => _4[i]]))))&&(m.current={inputs:y,options:W(e,E)});let R=m.current.options,g=_react.useRef.call(void 0, R);g.current=R,_react.useEffect.call(void 0, ()=>{let o=n.current;if(!o)return;let i={...g.current};for(let b of _machtable.EVENT_TYPES){let p=`on${b.charAt(0).toUpperCase()}${b.slice(1)}`;i[p]=S=>{let D=g.current[p];typeof D=="function"&&D(S);let C=O.current[p];typeof C=="function"&&C!==D&&C(S)}}let f=_machtable.createGrid.call(void 0, o,i);return s.current=f,()=>{f.destroy(),s.current=null}},[]),_react.useEffect.call(void 0, ()=>{if(!t)return;let o=s.current;return t.current=o,()=>{t.current===o&&(t.current=null)}},[t]);let M=_machtable.GRID_OPTION_KEYS.map(o=>R[o]),A=_react.useRef.call(void 0, null);return _react.useEffect.call(void 0, ()=>{let o=A.current;if(A.current=M,!o)return;let i={};M.forEach((f,b)=>{Object.is(f,o[b])||(i[_machtable.GRID_OPTION_KEYS[b]]=f)}),Object.keys(i).length>0&&_optionalChain([s, 'access', _5 => _5.current, 'optionalAccess', _6 => _6.updateOptions, 'call', _7 => _7(i)])},M),_react.createElement.call(void 0, "div",{ref:n,className:`mach-react-host ${_nullishCoalesce(a, () => (""))}`.trim()||void 0,style:r,"aria-label":e["aria-label"],"aria-labelledby":e["aria-labelledby"],"aria-describedby":e["aria-describedby"]})}var J=N;var X={search:!0,refresh:!0,columns:!0,density:!0,export:!0,undoRedo:!1,fullscreen:!1};function c(e,a){return _nullishCoalesce(_optionalChain([e, 'optionalAccess', _8 => _8[a]]), () => (X[a]))}function u(e,a,r,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:r},a)}function Z(e){let a=[e.start],r=_nullishCoalesce(e.searchPlaceholder, () => ("\u641C\u7D22\u5F53\u524D\u7ED3\u679C"));return c(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"},r),_react.createElement.call(void 0, "span",{"aria-hidden":!0},"\u2315"),_react.createElement.call(void 0, "input",{type:"search",value:_nullishCoalesce(e.search, () => ("")),placeholder:r,onChange:t=>{let n=t.currentTarget.value;_optionalChain([e, 'access', _9 => _9.onSearchChange, 'optionalCall', _10 => _10(n)]),e.onSearchChange||(e.commands?e.commands.search(n||null):_optionalChain([e, 'access', _11 => _11.api, 'optionalAccess', _12 => _12.setQuickFilter, 'call', _13 => _13(n||null)]))}}))),c(e.features,"refresh")&&a.push(u("\u5237\u65B0",e.loading?"\u2026":"\u21BB",()=>{_optionalChain([e, 'access', _14 => _14.onRefresh, 'optionalCall', _15 => _15()]),e.onRefresh||(e.commands?e.commands.refresh():_optionalChain([e, 'access', _16 => _16.api, 'optionalAccess', _17 => _17.isInfinite, 'call', _18 => _18()])?e.api.reload():_optionalChain([e, 'access', _19 => _19.api, 'optionalAccess', _20 => _20.refreshCells, 'call', _21 => _21()]))},e.loading)),c(e.features,"columns")&&a.push(u("\u5217\u8BBE\u7F6E","\u2637",t=>{e.commands?e.commands.openColumns(t.currentTarget):_optionalChain([e, 'access', _22 => _22.api, 'optionalAccess', _23 => _23.openColumnWorkbench, 'call', _24 => _24(t.currentTarget)])})),c(e.features,"density")&&a.push(_react.createElement.call(void 0, "select",{key:"density",className:"mach-toolbar__select",value:_nullishCoalesce(_optionalChain([e, 'access', _25 => _25.api, 'optionalAccess', _26 => _26.getGridOption, 'call', _27 => _27("size")]), () => ("normal")),"aria-label":"\u8868\u683C\u5BC6\u5EA6",onChange:t=>{let n=t.currentTarget.value;e.commands?e.commands.setDensity(n):_optionalChain([e, 'access', _28 => _28.api, 'optionalAccess', _29 => _29.setGridOption, 'call', _30 => _30("size",n)])}},_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 ee(e){e.commands?e.commands.undo():_optionalChain([e, 'access', _31 => _31.api, 'optionalAccess', _32 => _32.undo, 'call', _33 => _33()])}function ae(e){e.commands?e.commands.redo():_optionalChain([e, 'access', _34 => _34.api, 'optionalAccess', _35 => _35.redo, 'call', _36 => _36()])}function te(e){let a=[];return(_nullishCoalesce(e.selectedCount, () => (0)))>0&&a.push(_react.createElement.call(void 0, "button",{type:"button",className:"mach-toolbar__selection",onClick:()=>_optionalChain([e, 'access', _37 => _37.onClearSelection, 'optionalCall', _38 => _38()])},`\u5DF2\u9009 ${e.selectedCount} \u9879 \xD7`)),c(e.features,"undoRedo")&&(a.push(u("\u64A4\u9500","\u21B6",()=>ee(e),e.commands?!e.commands.canUndo():!_optionalChain([e, 'access', _39 => _39.api, 'optionalAccess', _40 => _40.canUndo, 'call', _41 => _41()]))),a.push(u("\u91CD\u505A","\u21B7",()=>ae(e),e.commands?!e.commands.canRedo():!_optionalChain([e, 'access', _42 => _42.api, 'optionalAccess', _43 => _43.canRedo, 'call', _44 => _44()])))),c(e.features,"export")&&a.push(u("\u5BFC\u51FA CSV","\u21E9",()=>{_optionalChain([e, 'access', _45 => _45.commands, 'optionalAccess', _46 => _46.exportCsv, 'call', _47 => _47(e.exportFilename)])},!e.commands)),c(e.features,"fullscreen")&&a.push(u("\u5168\u5C4F","\u26F6",()=>{_optionalChain([e, 'access', _48 => _48.commands, 'optionalAccess', _49 => _49.toggleFullscreen, 'call', _50 => _50()])},!e.commands)),a.push(e.end),a}function re(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"},...Z(e)),_react.createElement.call(void 0, "div",{className:"mach-toolbar__aside"},...te(e)))}var _client = require('react-dom/client');function ne(e){return a=>{let r=document.createElement("div");r.className="mach-cell-react",r.style.width="100%";let t=_client.createRoot.call(void 0, r);t.render(_react.createElement.call(void 0, e,a));let n=!1;return{el:r,refresh:s=>(t.render(_react.createElement.call(void 0, e,s)),!0),destroy:()=>{n||(n=!0,window.setTimeout(()=>{t.unmount()},0))}}}}function oe(e){return a=>{let r=document.createElement("div");r.style.height="100%";let t=_client.createRoot.call(void 0, r);t.render(_react.createElement.call(void 0, e,a));let n=!1;return{el:r,destroy:()=>{n||(n=!0,window.setTimeout(()=>{t.unmount()},0))}}}}var pe=N;exports.MachTable = N; exports.MachTableProvider = Q; exports.MachTableToolbar = re; exports.RobotGrid = J; exports.default = pe; exports.reactCellRenderer = ne; exports.reactDetailRenderer = oe; exports.useMachGrid = _chunkMFRKW34Vcjs.a; exports.useMachTableConfig = P; exports.useMachTableController = _chunkMFRKW34Vcjs.d; exports.useMachTableDefaults = j; exports.useMachTableEditing = _chunkMFRKW34Vcjs.b; exports.useMachTableQuery = _chunkMFRKW34Vcjs.c;
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, ComponentType } from 'react';
3
- import { GridOptions, MachTablePresetSelection, GridApi, MachTableCommands, MachTableRuntimeConfig, ResolvedMachTableConfig, CellRendererParams, RowNode, CellRendererFn, DetailRowRendererParams } from '@agile-team/mach-table';
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 { M as MachTablePageRequest, a as MachTablePageResult, b as MachTableQuerySource, c as MachTableRemoteSelectionState, U as UseMachGridReturn, d as UseMachTableControllerOptions, e as UseMachTableControllerReturn, f as UseMachTableEditingOptions, g as UseMachTableEditingReturn, h as UseMachTableQueryOptions, i as UseMachTableQueryReturn, u as useMachGrid, j as useMachTableController, k as useMachTableEditing, l as useMachTableQuery } from './workflows-CoKf5zIV.cjs';
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 MachTableToolbarFeatures {
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<TData = any>({ config, defaults, children }: MachTableProviderProps<TData>): react.FunctionComponentElement<react.ProviderProps<ResolvedMachTableConfig>>;
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
- interface ReactCellRendererProps<TData = any, TValue = any> extends CellRendererParams<TData, TValue> {
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, ComponentType } from 'react';
3
- import { GridOptions, MachTablePresetSelection, GridApi, MachTableCommands, MachTableRuntimeConfig, ResolvedMachTableConfig, CellRendererParams, RowNode, CellRendererFn, DetailRowRendererParams } from '@agile-team/mach-table';
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 { M as MachTablePageRequest, a as MachTablePageResult, b as MachTableQuerySource, c as MachTableRemoteSelectionState, U as UseMachGridReturn, d as UseMachTableControllerOptions, e as UseMachTableControllerReturn, f as UseMachTableEditingOptions, g as UseMachTableEditingReturn, h as UseMachTableQueryOptions, i as UseMachTableQueryReturn, u as useMachGrid, j as useMachTableController, k as useMachTableEditing, l as useMachTableQuery } from './workflows-CoKf5zIV.js';
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 MachTableToolbarFeatures {
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<TData = any>({ config, defaults, children }: MachTableProviderProps<TData>): react.FunctionComponentElement<react.ProviderProps<ResolvedMachTableConfig>>;
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
- interface ReactCellRendererProps<TData = any, TValue = any> extends CellRendererParams<TData, TValue> {
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 L,b as _,c as k,d as F}from"./chunk-WF435LXF.js";import{createElement as $,useEffect as x,useRef as d}from"react";import{createGrid as q,GRID_OPTION_KEYS as h,EVENT_TYPES as K,resolveMachTableGridOptions as Y}from"@agile-team/mach-table";import{createContext as B,createElement as U,useContext as v,useMemo as V}from"react";import{mergeMachTableConfig as z,normalizeMachTableConfig as H}from"@agile-team/mach-table";var I=H(),T=B(I);function Q({config:e,defaults:a,children:r}){let t=v(T),n=V(()=>z(t,{...e??{},...a?{defaults:a}:{}}),[t,e,a]);return U(T.Provider,{value:n},r)}function j(){return v(T).defaults}function P(){return v(T)}function W(e,a){let r={};for(let t of h){if(t==="className")continue;let n=t==="ariaLabel"?e.gridAriaLabel:t==="ariaLabelledBy"?e.gridAriaLabelledBy:t==="ariaDescribedBy"?e.gridAriaDescribedBy:e[t];n!==void 0&&(r[t]=n)}return e.gridClassName!==void 0&&(r.className=e.gridClassName),Y(a,e.preset,r).options}function N(e){let{className:a,style:r,apiRef:t}=e,n=d(null),s=d(null),O=d(e);O.current=e;let E=P(),y=[E,e.preset,...h.map(o=>o==="className"?e.gridClassName:o==="ariaLabel"?e.gridAriaLabel:o==="ariaLabelledBy"?e.gridAriaLabelledBy:o==="ariaDescribedBy"?e.gridAriaDescribedBy:e[o])],m=d(null);(!m.current||m.current.inputs.length!==y.length||y.some((o,i)=>!Object.is(o,m.current?.inputs[i])))&&(m.current={inputs:y,options:W(e,E)});let R=m.current.options,g=d(R);g.current=R,x(()=>{let o=n.current;if(!o)return;let i={...g.current};for(let b of K){let p=`on${b.charAt(0).toUpperCase()}${b.slice(1)}`;i[p]=S=>{let D=g.current[p];typeof D=="function"&&D(S);let C=O.current[p];typeof C=="function"&&C!==D&&C(S)}}let f=q(o,i);return s.current=f,()=>{f.destroy(),s.current=null}},[]),x(()=>{if(!t)return;let o=s.current;return t.current=o,()=>{t.current===o&&(t.current=null)}},[t]);let M=h.map(o=>R[o]),A=d(null);return x(()=>{let o=A.current;if(A.current=M,!o)return;let i={};M.forEach((f,b)=>{Object.is(f,o[b])||(i[h[b]]=f)}),Object.keys(i).length>0&&s.current?.updateOptions(i)},M),$("div",{ref:n,className:`mach-react-host ${a??""}`.trim()||void 0,style:r,"aria-label":e["aria-label"],"aria-labelledby":e["aria-labelledby"],"aria-describedby":e["aria-describedby"]})}var J=N;import{createElement as l}from"react";var X={search:!0,refresh:!0,columns:!0,density:!0,export:!0,undoRedo:!1,fullscreen:!1};function c(e,a){return e?.[a]??X[a]}function u(e,a,r,t=!1){return l("button",{key:e,type:"button",className:"mach-toolbar__button",title:e,"aria-label":e,disabled:t,onClick:r},a)}function Z(e){let a=[e.start],r=e.searchPlaceholder??"\u641C\u7D22\u5F53\u524D\u7ED3\u679C";return c(e.features,"search")&&a.push(l("label",{className:"mach-toolbar__search",key:"search"},l("span",{className:"mach-sr-only"},r),l("span",{"aria-hidden":!0},"\u2315"),l("input",{type:"search",value:e.search??"",placeholder:r,onChange:t=>{let n=t.currentTarget.value;e.onSearchChange?.(n),e.onSearchChange||(e.commands?e.commands.search(n||null):e.api?.setQuickFilter(n||null))}}))),c(e.features,"refresh")&&a.push(u("\u5237\u65B0",e.loading?"\u2026":"\u21BB",()=>{e.onRefresh?.(),e.onRefresh||(e.commands?e.commands.refresh():e.api?.isInfinite()?e.api.reload():e.api?.refreshCells())},e.loading)),c(e.features,"columns")&&a.push(u("\u5217\u8BBE\u7F6E","\u2637",t=>{e.commands?e.commands.openColumns(t.currentTarget):e.api?.openColumnWorkbench(t.currentTarget)})),c(e.features,"density")&&a.push(l("select",{key:"density",className:"mach-toolbar__select",value:e.api?.getGridOption("size")??"normal","aria-label":"\u8868\u683C\u5BC6\u5EA6",onChange:t=>{let n=t.currentTarget.value;e.commands?e.commands.setDensity(n):e.api?.setGridOption("size",n)}},l("option",{value:"compact"},"\u7D27\u51D1"),l("option",{value:"normal"},"\u6807\u51C6"),l("option",{value:"large"},"\u5BBD\u677E"))),a.push(e.children),a}function ee(e){e.commands?e.commands.undo():e.api?.undo()}function ae(e){e.commands?e.commands.redo():e.api?.redo()}function te(e){let a=[];return(e.selectedCount??0)>0&&a.push(l("button",{type:"button",className:"mach-toolbar__selection",onClick:()=>e.onClearSelection?.()},`\u5DF2\u9009 ${e.selectedCount} \u9879 \xD7`)),c(e.features,"undoRedo")&&(a.push(u("\u64A4\u9500","\u21B6",()=>ee(e),e.commands?!e.commands.canUndo():!e.api?.canUndo())),a.push(u("\u91CD\u505A","\u21B7",()=>ae(e),e.commands?!e.commands.canRedo():!e.api?.canRedo()))),c(e.features,"export")&&a.push(u("\u5BFC\u51FA CSV","\u21E9",()=>{e.commands?.exportCsv(e.exportFilename)},!e.commands)),c(e.features,"fullscreen")&&a.push(u("\u5168\u5C4F","\u26F6",()=>{e.commands?.toggleFullscreen()},!e.commands)),a.push(e.end),a}function re(e){return l("div",{className:"mach-toolbar",role:"toolbar","aria-label":"\u8868\u683C\u5DE5\u5177\u680F"},l("div",{className:"mach-toolbar__main"},...Z(e)),l("div",{className:"mach-toolbar__aside"},...te(e)))}import{createElement as G,isValidElement as ye}from"react";import{createRoot as w}from"react-dom/client";function ne(e){return a=>{let r=document.createElement("div");r.className="mach-cell-react",r.style.width="100%";let t=w(r);t.render(G(e,a));let n=!1;return{el:r,refresh:s=>(t.render(G(e,s)),!0),destroy:()=>{n||(n=!0,window.setTimeout(()=>{t.unmount()},0))}}}}function oe(e){return a=>{let r=document.createElement("div");r.style.height="100%";let t=w(r);t.render(G(e,a));let n=!1;return{el:r,destroy:()=>{n||(n=!0,window.setTimeout(()=>{t.unmount()},0))}}}}export*from"@agile-team/mach-table";var pe=N;export{N as MachTable,Q as MachTableProvider,re as MachTableToolbar,J as RobotGrid,pe as default,ne as reactCellRenderer,oe as reactDetailRenderer,L as useMachGrid,P as useMachTableConfig,F as useMachTableController,j as useMachTableDefaults,_ as useMachTableEditing,k as useMachTableQuery};
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 };