@agile-team/mach-table 0.36.0 → 0.38.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 +23 -18
- package/dist/adapter.cjs +1 -1
- package/dist/adapter.d.cts +6 -2
- package/dist/adapter.d.ts +6 -2
- package/dist/adapter.js +1 -1
- package/dist/analysis.cjs +1 -1
- package/dist/analysis.d.cts +2 -2
- package/dist/analysis.d.ts +2 -2
- package/dist/analysis.js +1 -1
- package/dist/{api-Di5SQHAP.d.cts → api-Bgcy7aRd.d.cts} +7 -2
- package/dist/{api-Di5SQHAP.d.ts → api-Bgcy7aRd.d.ts} +7 -2
- package/dist/business.cjs +1 -1
- package/dist/business.d.cts +1 -26
- package/dist/business.d.ts +1 -26
- package/dist/business.js +1 -1
- package/dist/{configuration-nh5lvWDe.d.ts → configuration-B5dSDN9d.d.ts} +1 -1
- package/dist/{configuration-DlRW86iR.d.cts → configuration-BVWcsdGm.d.cts} +1 -1
- package/dist/import.cjs +1 -1
- package/dist/import.d.cts +1 -1
- package/dist/import.d.ts +1 -1
- package/dist/import.js +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +4 -13
- package/dist/index.d.ts +4 -13
- package/dist/index.js +5 -5
- package/dist/mach-table.css +1 -1
- package/dist/multi-range.d.cts +1 -1
- package/dist/multi-range.d.ts +1 -1
- package/dist/ordering.cjs +1 -1
- package/dist/ordering.d.cts +1 -1
- package/dist/ordering.d.ts +1 -1
- package/dist/ordering.js +1 -1
- package/dist/preferences.d.cts +1 -1
- package/dist/preferences.d.ts +1 -1
- package/dist/server-side.cjs +1 -1
- package/dist/server-side.d.cts +1 -1
- package/dist/server-side.d.ts +1 -1
- package/dist/server-side.js +1 -1
- package/dist/{shared-BusgJSf4.d.ts → shared-CLEc9O2p.d.ts} +1 -1
- package/dist/{shared-O6pPO8H8.d.cts → shared-DfLrRGYY.d.cts} +1 -1
- package/dist/workbench.cjs +1 -1
- package/dist/workbench.css +1 -1
- package/dist/workbench.d.cts +3 -3
- package/dist/workbench.d.ts +3 -3
- package/dist/workbench.js +1 -1
- package/dist/worker.d.cts +2 -2
- package/dist/worker.d.ts +2 -2
- package/package.json +2 -2
- package/dist/cachedDictionary-C26hMT22.d.cts +0 -30
- package/dist/cachedDictionary-C26hMT22.d.ts +0 -30
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# @agile-team/mach-table
|
|
6
6
|
|
|
7
|
-
MachTable 0.
|
|
7
|
+
MachTable 0.38.0 的框架无关 TypeScript Core,零运行时依赖。提供行列双虚拟化、编辑、树与分组、随机访问远程数据和区段隔离状态持久化。本版补齐异步表头的布局恢复和动态换列时的状态更新。通过 `rowNumber: true` 启用自动序号,内置分页默认开启。
|
|
8
8
|
|
|
9
9
|
小型本地明细可使用 `domLayout: "autoHeight"` 随当前页内容收起;本版为该模式的空态、加载态和错误态预留必要展示空间,恢复数据后释放最小高度。可通过 `--mach-overlay-min-height` 局部调整。大数据表继续使用有明确高度的默认虚拟布局。
|
|
10
10
|
|
|
@@ -98,7 +98,7 @@ const options: GridOptions<Plan> = {
|
|
|
98
98
|
| `/server-side` | 服务端分组/聚合、route 分页、缓存/刷新/事务及层级选择 |
|
|
99
99
|
| `/multi-range` | Ctrl/Cmd 追加范围、格式化复制、校验清空及撤销 |
|
|
100
100
|
| `/import` | 有界数据预览、共享同步/异步校验、结构化错误与过期保护 |
|
|
101
|
-
| `/business` |
|
|
101
|
+
| `/business` | 范围与币种/单位分组的本地语义合计 |
|
|
102
102
|
| `/analysis` | Pivot、安全公式、柱/折线图和数据表回退 |
|
|
103
103
|
|
|
104
104
|
```ts
|
|
@@ -116,28 +116,33 @@ filters.destroy();
|
|
|
116
116
|
|
|
117
117
|
Source-available © ChenyCHENYU (Agile Team). 任何使用均须事先取得书面授权。详见 [LICENSE](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSE) 与[授权流程](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSING.md)。
|
|
118
118
|
|
|
119
|
-
##
|
|
119
|
+
## 显示策略与本地合计
|
|
120
|
+
|
|
121
|
+
页面把已准备好的标签与普通格式化函数组合到列上。MachTable 只接收同步函数与普通选项,不持有字典实例、加载服务或订阅协议。异步数据准备与刷新由项目管理。
|
|
120
122
|
|
|
121
123
|
```ts
|
|
122
|
-
import {
|
|
124
|
+
import { summarizeRows } from "@agile-team/mach-table/business";
|
|
123
125
|
|
|
124
|
-
const
|
|
125
|
-
const labels = new Map(options.map(entry => [entry.value, entry.label]));
|
|
126
|
+
const labels = new Map([["ready", "已就绪"]]);
|
|
126
127
|
const statusColumn = {
|
|
127
128
|
field: "status",
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
output: { clipboard: "label", csv: "code-label" }
|
|
132
|
-
})
|
|
129
|
+
valueFormatter: ({ value }) => labels.get(String(value)) ?? String(value ?? ""),
|
|
130
|
+
valueSerializer: ({ value, target }) =>
|
|
131
|
+
target === "clipboard" ? labels.get(String(value)) ?? value : value
|
|
133
132
|
};
|
|
133
|
+
const rows = [{ currency: "CNY", unit: "t", amount: 120, completed: 2, planned: 4 }];
|
|
134
|
+
const summary = summarizeRows(rows, {
|
|
135
|
+
scope: "page",
|
|
136
|
+
groupBy: row => JSON.stringify([row.currency, row.unit]),
|
|
137
|
+
metrics: [
|
|
138
|
+
{ id: "amount", kind: "sum", value: row => row.amount },
|
|
139
|
+
{ id: "count", kind: "count" },
|
|
140
|
+
{ id: "completion", kind: "ratio", numerator: row => row.completed, denominator: row => row.planned }
|
|
141
|
+
]
|
|
142
|
+
});
|
|
134
143
|
```
|
|
135
144
|
|
|
136
|
-
`/business`
|
|
137
|
-
|
|
138
|
-
`summarizeRows(rows, { scope, metrics, groupBy?, numeric? })` 只计算传入记录,支持 sum/count/ratio/none;ratio 先分别汇总分子分母。业务按币种、单位分组,scope 仅声明 page/selected/query,不自动获取全量。默认有限 number 仍遵循浮点语义,精确金额使用已有同步 numeric 策略;结果接入原 summaryMethod 或固定行。详见[业务列与字典](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/business-columns.md)。
|
|
139
|
-
|
|
140
|
-
根入口的 `createCachedDictionary()` 现在复用同 key 在途请求,失效隔离旧响应并结束旧等待,缺失项受同一 TTL/LRU 约束。失败可重试,销毁拒绝未完成请求,错误观察回调不会阻塞清理。具体升级边界见[升级指南](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/upgrading.md)。
|
|
145
|
+
`/business` 只提供本地语义合计;scope 声明 page/selected/query,实际只处理传入记录。ratio 先汇总分子分母,精确金额可注入 numeric 策略;服务端全量由后端计算。详情见[业务列与合计](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/business-columns.md)。
|
|
141
146
|
|
|
142
147
|
## 列值与运行边界(自 0.33)
|
|
143
148
|
|
|
@@ -150,7 +155,7 @@ const statusColumn = {
|
|
|
150
155
|
|
|
151
156
|
## 内容列宽与状态颜色(0.35)
|
|
152
157
|
|
|
153
|
-
未声明 `width` 的列默认按表头和已加载数据的显示文本测宽:每列均匀抽样最多 100 行,默认 80–360px,`minWidth/maxWidth`
|
|
158
|
+
未声明 `width` 的列默认按表头和已加载数据的显示文本测宽:每列均匀抽样最多 100 行,默认 80–360px,`minWidth/maxWidth` 可覆盖。长内容在单元格内省略,表格保留内部横向滚动;不为测宽请求远程数据或执行自定义渲染器。格式化文本及状态标签文字都参与测量。图形/操作等特殊列请指定宽度。
|
|
154
159
|
|
|
155
160
|
```ts
|
|
156
161
|
const columns = [
|
|
@@ -164,7 +169,7 @@ const columns = [
|
|
|
164
169
|
];
|
|
165
170
|
```
|
|
166
171
|
|
|
167
|
-
`status` 复用主题标签,支持 `success/warning/danger/info/neutral` 及 CSS 颜色;未知代码保持中性,`0/false`
|
|
172
|
+
`status` 复用主题标签,支持 `success/warning/danger/info/neutral` 及 CSS 颜色;未知代码保持中性,`0/false` 保留。formatter 的文字可参与默认语义匹配;显式 renderer 优先。状态配置只控制展示,导出继续遵循原有列值政策。
|
|
168
173
|
|
|
169
174
|
普通布局尊重显式 `width` 和拖动后的宽度;`autoWidth: false` 保留原默认 150px。显式选择 `columnLayout: "fit"` 时仍按首选宽度比例铺满,360px 限制的是内容首选宽度,实际铺满仍遵循显式 minWidth/maxWidth;配置 `flex` 则主动允许本列吸收余量。手动调宽、列状态恢复及主动 `columns.fit()` 不受自动默认上限限制。更新数据或刷新单元格会重新测量,普通布局刷新复用结果。
|
|
170
175
|
|
package/dist/adapter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},me=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ue(t))!pe.call(e,r)&&r!==n&&P(e,r,{get:()=>t[r],enumerable:!(o=de(t,r))||o.enumerable});return e};var ge=e=>me(P({},"__esModule",{value:!0}),e);var Ee={};fe(Ee,{GRID_OPTION_KEYS:()=>re,GRID_OPTION_META:()=>oe,beginGridInput:()=>te,canReplaceGridData:()=>ee,createSelectControl:()=>Y,equivalentConfigValue:()=>O,equivalentGridOption:()=>F,mergeMachTableConfig:()=>ie,normalizeMachTableConfig:()=>S,readGridCell:()=>Q,resolveMachTableGridOptions:()=>se,resumeGrid:()=>Z,suspendGrid:()=>J,writeGridInput:()=>X});module.exports=ge(Ee);function O(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((r,d)=>O(r,t[d],n-1));if(!K(e)||!K(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&O(e[r],t[r],n-1))}function K(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var be=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function F(e,t,n){return Object.is(t,n)||be.has(e)&&O(t,n,3)}function h(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let r of Object.keys(n))o.setAttribute(r,n[r]);return o}function W(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let r=n.item(o);if(!r.startsWith("--mach-"))continue;let d=n.getPropertyValue(r).trim();d&&e.style.setProperty(r,d)}e.style.colorScheme=n.colorScheme}function V(e,t,n){return e<t?t:e>n?n:e}var _=0;function B(e="rg"){return _++,`${e}-${_}`}var p=null;function z(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function U(e){let t=e.target;p?.contains(t)||p?.close()}function E(){p?.reposition()}function q(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function ye(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",U,!0),document.addEventListener("keydown",q,!0),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0))}function he(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",U,!0),document.removeEventListener("keydown",q,!0),window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0))}function w(e,t){return t?`${e} ${t}`:e}function R(e){let t=[];return e.forEach((n,o)=>{n.disabled||t.push(o)}),t}function $(e,t,n){let o=R(e);if(o.length===0)return-1;let r=o.indexOf(t);return r<0?n>0?o[0]:o[o.length-1]:o[Math.max(0,Math.min(o.length-1,r+n))]}function G(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function Y(e){let t=h("div",w("mach-select-control",e.classNames?.root)),n=h("select",w("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=h("button",w("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let r=h("span",w("mach-select-value",e.classNames?.value)),d=h("span",w("mach-select-caret",e.classNames?.caret));d.setAttribute("aria-hidden","true"),o.append(r,d);let i=h("div",w("mach-select-listbox",e.classNames?.listbox));i.id=B("mach-select-listbox"),i.setAttribute("role","listbox"),i.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",i.id),t.append(n,o);let s=[...e.options],m=[],c=-1,g=!1,I=()=>e.themeSource??t.closest(".mach-root")??t,v=()=>{let a=s.find(l=>l.value===n.value);r.textContent=a?.label??n.value,m.forEach((l,b)=>{let u=s[b]?.value===n.value;l.setAttribute("aria-selected",u?"true":"false"),l.classList.toggle("mach-select-option--selected",u),l.classList.toggle("mach-select-option--active",b===c)}),o.setAttribute("aria-activedescendant",c>=0?m[c]?.id??"":"")},k=()=>{let a=o.getBoundingClientRect(),l=i.getBoundingClientRect(),b=Math.max(a.width,l.width),u=V(a.left,8,Math.max(8,window.innerWidth-b-8)),C=window.innerHeight-a.bottom-8,T=C<Math.min(l.height,240)&&a.top>C,f=T?Math.max(8,a.top-l.height-5):Math.min(window.innerHeight-l.height-8,a.bottom+5);i.style.minWidth=`${a.width}px`,i.style.left=`${u}px`,i.style.top=`${Math.max(8,f)}px`,i.classList.toggle("mach-select-listbox--above",T)},y=(a=!1)=>i.classList.contains("mach-select-listbox--open")?(i.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),i.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),i.remove(),he(y),a&&!g&&o.focus({preventScroll:!0}),!0):!1,le=(a,l=!0)=>{!s[a]||s[a].disabled||(c=a,v(),l&&m[a]?.scrollIntoView?.({block:"nearest"}))},M=()=>{g||o.disabled||i.classList.contains("mach-select-listbox--open")||(ye({owner:I(),close:y,contains:a=>t.contains(a)||i.contains(a),reposition:k}),c=G(s,n.value),c<0&&(c=R(s)[0]??-1),W(i,I()),document.body.appendChild(i),i.classList.add("mach-select-listbox--open"),i.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),k(),v(),m[c]?.scrollIntoView?.({block:"nearest"}))},L=a=>{let l=s[a];!l||l.disabled||(n.value=l.value,c=a,v(),y(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},N=(a,l)=>{s=[...a],n.replaceChildren(),i.replaceChildren(),m=s.map((u,C)=>{let T=document.createElement("option");T.value=u.value,T.textContent=u.label,T.disabled=u.disabled===!0,n.appendChild(T);let f=h("button",w("mach-select-option",e.classNames?.option));return f.id=`${i.id}-option-${C}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",ce=>ce.preventDefault()),f.addEventListener("click",()=>L(C)),i.appendChild(f),f});let b=s.find(u=>!u.disabled)?.value??"";n.value=l!=null&&s.some(u=>u.value===l)?l:b,c=G(s,n.value),v()},j=a=>{if(a.key==="Tab"){y();return}if(a.key==="Escape"){if(!y(!0))return;a.preventDefault(),a.stopPropagation();return}if(a.key==="Enter"||a.key===" "){a.preventDefault(),a.stopPropagation(),i.classList.contains("mach-select-listbox--open")?L(c):M();return}let l=c;if(a.key==="ArrowDown")l=$(s,c,1);else if(a.key==="ArrowUp")l=$(s,c,-1);else if(a.key==="Home")l=R(s)[0]??-1;else if(a.key==="End"){let b=R(s);l=b[b.length-1]??-1}else return;a.preventDefault(),a.stopPropagation(),i.classList.contains("mach-select-listbox--open")||M(),le(l)},H=()=>{c=G(s,n.value),v(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{y()||M()}),o.addEventListener("keydown",j),n.addEventListener("change",H),N(s,e.value),{el:t,native:n,trigger:o,listbox:i,contains:a=>t.contains(a)||i.contains(a),isOpen:()=>i.classList.contains("mach-select-listbox--open"),open:M,close:y,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:a=>{n.value=a,c=G(s,a),v()},setOptions:N,destroy:()=>{g||(g=!0,y(),o.removeEventListener("keydown",j),n.removeEventListener("change",H),t.remove())}}}var x=Symbol.for("mach-table.adapter.lifecycle.v1");function J(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&z(t),e[x]?.suspend()}function Z(e){e.isDestroyed()||e[x]?.resume()}function Q(e,t,n){return e.isDestroyed()?"":e[x]?.readCell(t,n)??""}function X(e,t){e.isDestroyed()||e[x]?.writeInput(t)}function ee(e){return!e.isDestroyed()&&(e[x]?.canReplaceData()??!1)}var Te=Symbol.for("mach-table.import.v1");function we(e){let t=e[Te];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function te(e){return e.isDestroyed()?()=>!1:we(e).begin()}var ne={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function ve(){return Object.fromEntries(Object.entries(ne).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var oe=ve(),re=Object.freeze(Object.keys(ne));function A(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function De(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(r){o=r}try{t(...n)}catch(r){o??(o=r)}if(o!==void 0)throw o}}function Ce(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function Oe(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let r of o)n[r]={...e.columnTypes?.[r],...t.columnTypes?.[r]};return n}function xe(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let r=t[o],d=n[o];typeof r!="function"||typeof d!="function"||(e[o]=De(r,d))}}function Me(e,t){let n={...e,...t,features:t.features??e.features};(e.defaultColDef||t.defaultColDef)&&(n.defaultColDef={...e.defaultColDef,...t.defaultColDef}),(e.locale||t.locale)&&(n.locale={...e.locale,...t.locale});let o=Ce(e,t);o&&(n.components=o);let r=Oe(e,t);return r&&(n.columnTypes=r),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=A(e.pagination,t.pagination),n.statusBar=A(e.statusBar,t.statusBar),n.watermark=A(e.watermark,t.watermark),xe(n,e,t),n}function D(...e){return e.reduce(Me,{})}function Ge(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var Re=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function ae(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[r,d]of Object.entries(t)){if(!Re.includes(r)&&(r!=="dataProcessor"||d==null||typeof d=="function")){o[r]=d;continue}let i={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:r,layer:n,message:r==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${r}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(i),e.strict!==!1)throw new TypeError(i.message)}return o}function S(e={}){let t=ae(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(ae(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function ie(e,t){let n=S({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[r,d]of Object.entries(n.presets))o[r]=D(e.presets[r]??{},d);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function se(e,t,n,o){let r=t===void 0?e.defaultPreset:t,d=[{name:"application defaults",options:e.defaults}];for(let s of Ge(r)){let m=e.presets[s];if(!m){let c={code:"UNKNOWN_PRESET",preset:s,message:`[MachTable] Unknown preset "${s}". Register it in mach-table.config.ts or remove the preset.`};o?o(c):e.onConfigWarning?e.onConfigWarning(c):console.warn(c.message);continue}d.push({name:`preset:${s}`,options:m})}d.push({name:"table props",options:n});let i=D(...d.map(s=>s.options));return{options:i,explain(s){let m=d.filter(g=>Object.prototype.hasOwnProperty.call(g.options,s)).map(g=>({name:g.name,value:g.options[s]})),c=m[m.length-1];return{key:s,value:i[s],source:c?.name??"MachTable built-in",layers:m}}}}0&&(module.exports={GRID_OPTION_KEYS,GRID_OPTION_META,beginGridInput,canReplaceGridData,createSelectControl,equivalentConfigValue,equivalentGridOption,mergeMachTableConfig,normalizeMachTableConfig,readGridCell,resolveMachTableGridOptions,resumeGrid,suspendGrid,writeGridInput});
|
|
1
|
+
"use strict";var A=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var me=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},ge=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of pe(t))!fe.call(e,r)&&r!==n&&A(e,r,{get:()=>t[r],enumerable:!(o=ue(t,r))||o.enumerable});return e};var be=e=>ge(A({},"__esModule",{value:!0}),e);var Pe={};me(Pe,{GRID_OPTION_KEYS:()=>re,GRID_OPTION_META:()=>oe,beginGridInput:()=>te,canReplaceGridData:()=>ee,createSelectControl:()=>Y,equivalentConfigValue:()=>x,equivalentGridOption:()=>_,mergeMachTableConfig:()=>ie,normalizeMachTableConfig:()=>S,readGridCell:()=>Q,resolveMachTableGridOptions:()=>se,resumeGrid:()=>Z,suspendGrid:()=>J,writeGridInput:()=>X});module.exports=be(Pe);function x(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((r,l)=>x(r,t[l],n-1));if(!F(e)||!F(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&x(e[r],t[r],n-1))}function F(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var ye=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function _(e,t,n){return Object.is(t,n)||ye.has(e)&&x(t,n,3)}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let r of Object.keys(n))o.setAttribute(r,n[r]);return o}function B(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let r=n.item(o);if(!r.startsWith("--mach-"))continue;let l=n.getPropertyValue(r).trim();l&&e.style.setProperty(r,l)}e.style.colorScheme=n.colorScheme}function V(e,t,n){return e<t?t:e>n?n:e}var W=0;function $(e="rg"){return W++,`${e}-${W}`}var p=null;function z(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function U(e){let t=e.target;p?.contains(t)||p?.close()}function P(){p?.reposition()}function q(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function he(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",U,!0),document.addEventListener("keydown",q,!0),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0))}function Te(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",U,!0),document.removeEventListener("keydown",q,!0),window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0))}function T(e,t){return t?`${e} ${t}`:e}function M(e,t,n){let o=e[t]&&!e[t].disabled,r=o?t+n:n>0?0:e.length-1;for(let l=r;l>=0&&l<e.length;l+=n)if(!e[l].disabled)return l;return o?t:-1}function E(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function Y(e){let t=y("div",T("mach-select-control",e.classNames?.root)),n=y("select",T("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",T("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let r=y("span",T("mach-select-value",e.classNames?.value)),l=y("span",T("mach-select-caret",e.classNames?.caret));l.setAttribute("aria-hidden","true"),o.append(r,l);let s=y("div",T("mach-select-listbox",e.classNames?.listbox));s.id=$("mach-select-listbox"),s.setAttribute("role","listbox"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",s.id),t.append(n,o);let i=[...e.options],m=[],d=-1,g=!1,le=()=>e.themeSource??t.closest(".mach-root")??t,I=a=>t.contains(a)||s.contains(a),C=()=>s.classList.contains("mach-select-listbox--open"),w=()=>{let a=i.find(c=>c.value===n.value);r.textContent=a?.label??n.value,m.forEach((c,v)=>{let u=i[v]?.value===n.value;c.setAttribute("aria-selected",u?"true":"false"),c.classList.toggle("mach-select-option--selected",u),c.classList.toggle("mach-select-option--active",v===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},L=()=>{let a=o.getBoundingClientRect(),c=s.getBoundingClientRect(),v=Math.max(a.width,c.width),u=V(a.left,8,Math.max(8,window.innerWidth-v-8)),O=window.innerHeight-a.bottom-8,h=O<Math.min(c.height,240)&&a.top>O,f=h?Math.max(8,a.top-c.height-5):Math.min(window.innerHeight-c.height-8,a.bottom+5);s.style.minWidth=`${a.width}px`,s.style.left=`${u}px`,s.style.top=`${Math.max(8,f)}px`,s.classList.toggle("mach-select-listbox--above",h)},b=(a=!1)=>C()?(s.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),s.remove(),Te(b),a&&!g&&o.focus({preventScroll:!0}),!0):!1,ce=(a,c=!0)=>{!i[a]||i[a].disabled||(d=a,w(),c&&m[a]?.scrollIntoView?.({block:"nearest"}))},R=()=>{if(g||o.disabled||C())return;let a=le();he({owner:a,close:b,contains:I,reposition:L}),d=E(i,n.value),d<0&&(d=M(i,-1,1)),B(s,a),document.body.appendChild(s),s.classList.add("mach-select-listbox--open"),s.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),L(),w(),m[d]?.scrollIntoView?.({block:"nearest"})},N=a=>{let c=i[a];!c||c.disabled||(n.value=c.value,d=a,w(),b(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},j=(a,c)=>{i=[...a],n.replaceChildren(),s.replaceChildren(),m=i.map((u,O)=>{let h=document.createElement("option");h.value=u.value,h.textContent=u.label,h.disabled=u.disabled===!0,n.appendChild(h);let f=y("button",T("mach-select-option",e.classNames?.option));return f.id=`${s.id}-option-${O}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",de=>de.preventDefault()),f.addEventListener("click",()=>N(O)),s.appendChild(f),f});let v=i.find(u=>!u.disabled)?.value??"";n.value=c!=null&&i.some(u=>u.value===c)?c:v,d=E(i,n.value),w()},H=a=>{if(a.key==="Tab"){b();return}if(a.key==="Escape"){if(!b(!0))return;a.preventDefault(),a.stopPropagation();return}if(a.key==="Enter"||a.key===" "){a.preventDefault(),a.stopPropagation(),C()?N(d):R();return}let c=d;if(a.key==="ArrowDown")c=M(i,d,1);else if(a.key==="ArrowUp")c=M(i,d,-1);else if(a.key==="Home")c=M(i,-1,1);else if(a.key==="End")c=M(i,-1,-1);else return;a.preventDefault(),a.stopPropagation(),C()||R(),ce(c)},K=()=>{d=E(i,n.value),w(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{b()||R()}),o.addEventListener("keydown",H),n.addEventListener("change",K),j(i,e.value),{el:t,native:n,trigger:o,listbox:s,contains:I,isOpen:C,open:R,close:b,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:a=>{n.value=a,d=E(i,a),w()},setOptions:j,destroy:()=>{g||(g=!0,b(),o.removeEventListener("keydown",H),n.removeEventListener("change",K),t.remove())}}}var G=Symbol.for("mach-table.adapter.lifecycle.v1");function J(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&z(t),e[G]?.suspend()}function Z(e){e.isDestroyed()||e[G]?.resume()}function Q(e,t,n){return e.isDestroyed()?"":e[G]?.readCell(t,n)??""}function X(e,t){e.isDestroyed()||e[G]?.writeInput(t)}function ee(e){return!e.isDestroyed()&&(e[G]?.canReplaceData()??!1)}var we=Symbol.for("mach-table.import.v1");function ve(e){let t=e[we];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function te(e){return e.isDestroyed()?()=>!1:ve(e).begin()}var ne={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",rowNumber:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function De(){return Object.fromEntries(Object.entries(ne).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var oe=De(),re=Object.freeze(Object.keys(ne));function k(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function Ce(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(r){o=r}try{t(...n)}catch(r){o??(o=r)}if(o!==void 0)throw o}}function Oe(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function xe(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let r of o)n[r]={...e.columnTypes?.[r],...t.columnTypes?.[r]};return n}function Me(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let r=t[o],l=n[o];typeof r!="function"||typeof l!="function"||(e[o]=Ce(r,l))}}function Ge(e,t){let n={...e,...t,features:t.features??e.features};(e.defaultColDef||t.defaultColDef)&&(n.defaultColDef={...e.defaultColDef,...t.defaultColDef}),(e.locale||t.locale)&&(n.locale={...e.locale,...t.locale});let o=Oe(e,t);o&&(n.components=o);let r=xe(e,t);return r&&(n.columnTypes=r),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=k(e.pagination,t.pagination),n.statusBar=k(e.statusBar,t.statusBar),n.watermark=k(e.watermark,t.watermark),Me(n,e,t),n}function D(...e){return e.reduce(Ge,{})}function Re(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var Ee=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function ae(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[r,l]of Object.entries(t)){if(!Ee.includes(r)&&(r!=="dataProcessor"||l==null||typeof l=="function")){o[r]=l;continue}let s={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:r,layer:n,message:r==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${r}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(s),e.strict!==!1)throw new TypeError(s.message)}return o}function S(e={}){let t=ae(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(ae(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function ie(e,t){let n=S({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[r,l]of Object.entries(n.presets))o[r]=D(e.presets[r]??{},l);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function se(e,t,n,o){let r=t===void 0?e.defaultPreset:t,l=[{name:"application defaults",options:e.defaults}];for(let i of Re(r)){let m=e.presets[i];if(!m){let d={code:"UNKNOWN_PRESET",preset:i,message:`[MachTable] Unknown preset "${i}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}l.push({name:`preset:${i}`,options:m})}l.push({name:"table props",options:n});let s={rowNumber:!0,...D(...l.map(i=>i.options))};return{options:s,explain(i){let m=l.filter(g=>Object.prototype.hasOwnProperty.call(g.options,i)).map(g=>({name:g.name,value:g.options[i]})),d=m[m.length-1];return{key:i,value:s[i],source:d?.name??"MachTable built-in",layers:m}}}}0&&(module.exports={GRID_OPTION_KEYS,GRID_OPTION_META,beginGridInput,canReplaceGridData,createSelectControl,equivalentConfigValue,equivalentGridOption,mergeMachTableConfig,normalizeMachTableConfig,readGridCell,resolveMachTableGridOptions,resumeGrid,suspendGrid,writeGridInput});
|
package/dist/adapter.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-
|
|
2
|
-
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-
|
|
1
|
+
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-Bgcy7aRd.cjs';
|
|
2
|
+
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-BVWcsdGm.cjs';
|
|
3
3
|
|
|
4
4
|
/** Bounded structural comparison for small immutable config values, never row data. */
|
|
5
5
|
declare function equivalentConfigValue(left: unknown, right: unknown, depth?: number): boolean;
|
|
@@ -225,6 +225,10 @@ declare const GRID_OPTION_META: {
|
|
|
225
225
|
readonly kind: "boolean";
|
|
226
226
|
readonly update: "options";
|
|
227
227
|
};
|
|
228
|
+
readonly rowNumber: {
|
|
229
|
+
readonly kind: "boolean";
|
|
230
|
+
readonly update: "options";
|
|
231
|
+
};
|
|
228
232
|
readonly indexOffset: {
|
|
229
233
|
readonly kind: "number";
|
|
230
234
|
readonly update: "options";
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-
|
|
2
|
-
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-
|
|
1
|
+
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-Bgcy7aRd.js';
|
|
2
|
+
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-B5dSDN9d.js';
|
|
3
3
|
|
|
4
4
|
/** Bounded structural comparison for small immutable config values, never row data. */
|
|
5
5
|
declare function equivalentConfigValue(left: unknown, right: unknown, depth?: number): boolean;
|
|
@@ -225,6 +225,10 @@ declare const GRID_OPTION_META: {
|
|
|
225
225
|
readonly kind: "boolean";
|
|
226
226
|
readonly update: "options";
|
|
227
227
|
};
|
|
228
|
+
readonly rowNumber: {
|
|
229
|
+
readonly kind: "boolean";
|
|
230
|
+
readonly update: "options";
|
|
231
|
+
};
|
|
228
232
|
readonly indexOffset: {
|
|
229
233
|
readonly kind: "number";
|
|
230
234
|
readonly update: "options";
|
package/dist/adapter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function M(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((a,d)=>M(a,t[d],n-1));if(!j(e)||!j(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(a=>Object.prototype.hasOwnProperty.call(t,a)&&M(e[a],t[a],n-1))}function j(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var Z=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function Q(e,t,n){return Object.is(t,n)||Z.has(e)&&M(t,n,3)}function h(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let a of Object.keys(n))o.setAttribute(a,n[a]);return o}function K(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let a=n.item(o);if(!a.startsWith("--mach-"))continue;let d=n.getPropertyValue(a).trim();d&&e.style.setProperty(a,d)}e.style.colorScheme=n.colorScheme}function F(e,t,n){return e<t?t:e>n?n:e}var H=0;function _(e="rg"){return H++,`${e}-${H}`}var p=null;function V(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function B(e){let t=e.target;p?.contains(t)||p?.close()}function E(){p?.reposition()}function $(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function X(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",B,!0),document.addEventListener("keydown",$,!0),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0))}function ee(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",B,!0),document.removeEventListener("keydown",$,!0),window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0))}function w(e,t){return t?`${e} ${t}`:e}function R(e){let t=[];return e.forEach((n,o)=>{n.disabled||t.push(o)}),t}function W(e,t,n){let o=R(e);if(o.length===0)return-1;let a=o.indexOf(t);return a<0?n>0?o[0]:o[o.length-1]:o[Math.max(0,Math.min(o.length-1,a+n))]}function G(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function te(e){let t=h("div",w("mach-select-control",e.classNames?.root)),n=h("select",w("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=h("button",w("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let a=h("span",w("mach-select-value",e.classNames?.value)),d=h("span",w("mach-select-caret",e.classNames?.caret));d.setAttribute("aria-hidden","true"),o.append(a,d);let i=h("div",w("mach-select-listbox",e.classNames?.listbox));i.id=_("mach-select-listbox"),i.setAttribute("role","listbox"),i.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",i.id),t.append(n,o);let s=[...e.options],m=[],c=-1,g=!1,A=()=>e.themeSource??t.closest(".mach-root")??t,v=()=>{let r=s.find(l=>l.value===n.value);a.textContent=r?.label??n.value,m.forEach((l,b)=>{let u=s[b]?.value===n.value;l.setAttribute("aria-selected",u?"true":"false"),l.classList.toggle("mach-select-option--selected",u),l.classList.toggle("mach-select-option--active",b===c)}),o.setAttribute("aria-activedescendant",c>=0?m[c]?.id??"":"")},S=()=>{let r=o.getBoundingClientRect(),l=i.getBoundingClientRect(),b=Math.max(r.width,l.width),u=F(r.left,8,Math.max(8,window.innerWidth-b-8)),C=window.innerHeight-r.bottom-8,T=C<Math.min(l.height,240)&&r.top>C,f=T?Math.max(8,r.top-l.height-5):Math.min(window.innerHeight-l.height-8,r.bottom+5);i.style.minWidth=`${r.width}px`,i.style.left=`${u}px`,i.style.top=`${Math.max(8,f)}px`,i.classList.toggle("mach-select-listbox--above",T)},y=(r=!1)=>i.classList.contains("mach-select-listbox--open")?(i.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),i.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),i.remove(),ee(y),r&&!g&&o.focus({preventScroll:!0}),!0):!1,Y=(r,l=!0)=>{!s[r]||s[r].disabled||(c=r,v(),l&&m[r]?.scrollIntoView?.({block:"nearest"}))},x=()=>{g||o.disabled||i.classList.contains("mach-select-listbox--open")||(X({owner:A(),close:y,contains:r=>t.contains(r)||i.contains(r),reposition:S}),c=G(s,n.value),c<0&&(c=R(s)[0]??-1),K(i,A()),document.body.appendChild(i),i.classList.add("mach-select-listbox--open"),i.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),S(),v(),m[c]?.scrollIntoView?.({block:"nearest"}))},I=r=>{let l=s[r];!l||l.disabled||(n.value=l.value,c=r,v(),y(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},k=(r,l)=>{s=[...r],n.replaceChildren(),i.replaceChildren(),m=s.map((u,C)=>{let T=document.createElement("option");T.value=u.value,T.textContent=u.label,T.disabled=u.disabled===!0,n.appendChild(T);let f=h("button",w("mach-select-option",e.classNames?.option));return f.id=`${i.id}-option-${C}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",J=>J.preventDefault()),f.addEventListener("click",()=>I(C)),i.appendChild(f),f});let b=s.find(u=>!u.disabled)?.value??"";n.value=l!=null&&s.some(u=>u.value===l)?l:b,c=G(s,n.value),v()},L=r=>{if(r.key==="Tab"){y();return}if(r.key==="Escape"){if(!y(!0))return;r.preventDefault(),r.stopPropagation();return}if(r.key==="Enter"||r.key===" "){r.preventDefault(),r.stopPropagation(),i.classList.contains("mach-select-listbox--open")?I(c):x();return}let l=c;if(r.key==="ArrowDown")l=W(s,c,1);else if(r.key==="ArrowUp")l=W(s,c,-1);else if(r.key==="Home")l=R(s)[0]??-1;else if(r.key==="End"){let b=R(s);l=b[b.length-1]??-1}else return;r.preventDefault(),r.stopPropagation(),i.classList.contains("mach-select-listbox--open")||x(),Y(l)},N=()=>{c=G(s,n.value),v(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{y()||x()}),o.addEventListener("keydown",L),n.addEventListener("change",N),k(s,e.value),{el:t,native:n,trigger:o,listbox:i,contains:r=>t.contains(r)||i.contains(r),isOpen:()=>i.classList.contains("mach-select-listbox--open"),open:x,close:y,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:r=>{n.value=r,c=G(s,r),v()},setOptions:k,destroy:()=>{g||(g=!0,y(),o.removeEventListener("keydown",L),n.removeEventListener("change",N),t.remove())}}}var O=Symbol.for("mach-table.adapter.lifecycle.v1");function ne(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&V(t),e[O]?.suspend()}function oe(e){e.isDestroyed()||e[O]?.resume()}function re(e,t,n){return e.isDestroyed()?"":e[O]?.readCell(t,n)??""}function ae(e,t){e.isDestroyed()||e[O]?.writeInput(t)}function ie(e){return!e.isDestroyed()&&(e[O]?.canReplaceData()??!1)}var se=Symbol.for("mach-table.import.v1");function le(e){let t=e[se];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function ce(e){return e.isDestroyed()?()=>!1:le(e).begin()}var z={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function de(){return Object.fromEntries(Object.entries(z).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var ue=de(),pe=Object.freeze(Object.keys(z));function P(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function fe(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(a){o=a}try{t(...n)}catch(a){o??(o=a)}if(o!==void 0)throw o}}function me(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function ge(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let a of o)n[a]={...e.columnTypes?.[a],...t.columnTypes?.[a]};return n}function be(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let a=t[o],d=n[o];typeof a!="function"||typeof d!="function"||(e[o]=fe(a,d))}}function ye(e,t){let n={...e,...t,features:t.features??e.features};(e.defaultColDef||t.defaultColDef)&&(n.defaultColDef={...e.defaultColDef,...t.defaultColDef}),(e.locale||t.locale)&&(n.locale={...e.locale,...t.locale});let o=me(e,t);o&&(n.components=o);let a=ge(e,t);return a&&(n.columnTypes=a),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=P(e.pagination,t.pagination),n.statusBar=P(e.statusBar,t.statusBar),n.watermark=P(e.watermark,t.watermark),be(n,e,t),n}function D(...e){return e.reduce(ye,{})}function he(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var Te=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function U(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[a,d]of Object.entries(t)){if(!Te.includes(a)&&(a!=="dataProcessor"||d==null||typeof d=="function")){o[a]=d;continue}let i={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:a,layer:n,message:a==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${a}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(i),e.strict!==!1)throw new TypeError(i.message)}return o}function q(e={}){let t=U(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(U(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function we(e,t){let n=q({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[a,d]of Object.entries(n.presets))o[a]=D(e.presets[a]??{},d);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function ve(e,t,n,o){let a=t===void 0?e.defaultPreset:t,d=[{name:"application defaults",options:e.defaults}];for(let s of he(a)){let m=e.presets[s];if(!m){let c={code:"UNKNOWN_PRESET",preset:s,message:`[MachTable] Unknown preset "${s}". Register it in mach-table.config.ts or remove the preset.`};o?o(c):e.onConfigWarning?e.onConfigWarning(c):console.warn(c.message);continue}d.push({name:`preset:${s}`,options:m})}d.push({name:"table props",options:n});let i=D(...d.map(s=>s.options));return{options:i,explain(s){let m=d.filter(g=>Object.prototype.hasOwnProperty.call(g.options,s)).map(g=>({name:g.name,value:g.options[s]})),c=m[m.length-1];return{key:s,value:i[s],source:c?.name??"MachTable built-in",layers:m}}}}export{pe as GRID_OPTION_KEYS,ue as GRID_OPTION_META,ce as beginGridInput,ie as canReplaceGridData,te as createSelectControl,M as equivalentConfigValue,Q as equivalentGridOption,we as mergeMachTableConfig,q as normalizeMachTableConfig,re as readGridCell,ve as resolveMachTableGridOptions,oe as resumeGrid,ne as suspendGrid,ae as writeGridInput};
|
|
1
|
+
function R(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((a,l)=>R(a,t[l],n-1));if(!H(e)||!H(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(a=>Object.prototype.hasOwnProperty.call(t,a)&&R(e[a],t[a],n-1))}function H(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var Q=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function X(e,t,n){return Object.is(t,n)||Q.has(e)&&R(t,n,3)}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let a of Object.keys(n))o.setAttribute(a,n[a]);return o}function F(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let a=n.item(o);if(!a.startsWith("--mach-"))continue;let l=n.getPropertyValue(a).trim();l&&e.style.setProperty(a,l)}e.style.colorScheme=n.colorScheme}function _(e,t,n){return e<t?t:e>n?n:e}var K=0;function W(e="rg"){return K++,`${e}-${K}`}var p=null;function B(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function V(e){let t=e.target;p?.contains(t)||p?.close()}function P(){p?.reposition()}function $(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function ee(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",V,!0),document.addEventListener("keydown",$,!0),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0))}function te(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",V,!0),document.removeEventListener("keydown",$,!0),window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0))}function T(e,t){return t?`${e} ${t}`:e}function x(e,t,n){let o=e[t]&&!e[t].disabled,a=o?t+n:n>0?0:e.length-1;for(let l=a;l>=0&&l<e.length;l+=n)if(!e[l].disabled)return l;return o?t:-1}function E(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function ne(e){let t=y("div",T("mach-select-control",e.classNames?.root)),n=y("select",T("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",T("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let a=y("span",T("mach-select-value",e.classNames?.value)),l=y("span",T("mach-select-caret",e.classNames?.caret));l.setAttribute("aria-hidden","true"),o.append(a,l);let s=y("div",T("mach-select-listbox",e.classNames?.listbox));s.id=W("mach-select-listbox"),s.setAttribute("role","listbox"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",s.id),t.append(n,o);let i=[...e.options],m=[],d=-1,g=!1,Y=()=>e.themeSource??t.closest(".mach-root")??t,k=r=>t.contains(r)||s.contains(r),C=()=>s.classList.contains("mach-select-listbox--open"),w=()=>{let r=i.find(c=>c.value===n.value);a.textContent=r?.label??n.value,m.forEach((c,v)=>{let u=i[v]?.value===n.value;c.setAttribute("aria-selected",u?"true":"false"),c.classList.toggle("mach-select-option--selected",u),c.classList.toggle("mach-select-option--active",v===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},S=()=>{let r=o.getBoundingClientRect(),c=s.getBoundingClientRect(),v=Math.max(r.width,c.width),u=_(r.left,8,Math.max(8,window.innerWidth-v-8)),O=window.innerHeight-r.bottom-8,h=O<Math.min(c.height,240)&&r.top>O,f=h?Math.max(8,r.top-c.height-5):Math.min(window.innerHeight-c.height-8,r.bottom+5);s.style.minWidth=`${r.width}px`,s.style.left=`${u}px`,s.style.top=`${Math.max(8,f)}px`,s.classList.toggle("mach-select-listbox--above",h)},b=(r=!1)=>C()?(s.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),s.remove(),te(b),r&&!g&&o.focus({preventScroll:!0}),!0):!1,J=(r,c=!0)=>{!i[r]||i[r].disabled||(d=r,w(),c&&m[r]?.scrollIntoView?.({block:"nearest"}))},G=()=>{if(g||o.disabled||C())return;let r=Y();ee({owner:r,close:b,contains:k,reposition:S}),d=E(i,n.value),d<0&&(d=x(i,-1,1)),F(s,r),document.body.appendChild(s),s.classList.add("mach-select-listbox--open"),s.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),S(),w(),m[d]?.scrollIntoView?.({block:"nearest"})},I=r=>{let c=i[r];!c||c.disabled||(n.value=c.value,d=r,w(),b(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},L=(r,c)=>{i=[...r],n.replaceChildren(),s.replaceChildren(),m=i.map((u,O)=>{let h=document.createElement("option");h.value=u.value,h.textContent=u.label,h.disabled=u.disabled===!0,n.appendChild(h);let f=y("button",T("mach-select-option",e.classNames?.option));return f.id=`${s.id}-option-${O}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",Z=>Z.preventDefault()),f.addEventListener("click",()=>I(O)),s.appendChild(f),f});let v=i.find(u=>!u.disabled)?.value??"";n.value=c!=null&&i.some(u=>u.value===c)?c:v,d=E(i,n.value),w()},N=r=>{if(r.key==="Tab"){b();return}if(r.key==="Escape"){if(!b(!0))return;r.preventDefault(),r.stopPropagation();return}if(r.key==="Enter"||r.key===" "){r.preventDefault(),r.stopPropagation(),C()?I(d):G();return}let c=d;if(r.key==="ArrowDown")c=x(i,d,1);else if(r.key==="ArrowUp")c=x(i,d,-1);else if(r.key==="Home")c=x(i,-1,1);else if(r.key==="End")c=x(i,-1,-1);else return;r.preventDefault(),r.stopPropagation(),C()||G(),J(c)},j=()=>{d=E(i,n.value),w(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{b()||G()}),o.addEventListener("keydown",N),n.addEventListener("change",j),L(i,e.value),{el:t,native:n,trigger:o,listbox:s,contains:k,isOpen:C,open:G,close:b,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:r=>{n.value=r,d=E(i,r),w()},setOptions:L,destroy:()=>{g||(g=!0,b(),o.removeEventListener("keydown",N),n.removeEventListener("change",j),t.remove())}}}var M=Symbol.for("mach-table.adapter.lifecycle.v1");function oe(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&B(t),e[M]?.suspend()}function re(e){e.isDestroyed()||e[M]?.resume()}function ae(e,t,n){return e.isDestroyed()?"":e[M]?.readCell(t,n)??""}function ie(e,t){e.isDestroyed()||e[M]?.writeInput(t)}function se(e){return!e.isDestroyed()&&(e[M]?.canReplaceData()??!1)}var le=Symbol.for("mach-table.import.v1");function ce(e){let t=e[le];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function de(e){return e.isDestroyed()?()=>!1:ce(e).begin()}var z={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",rowNumber:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function ue(){return Object.fromEntries(Object.entries(z).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var pe=ue(),fe=Object.freeze(Object.keys(z));function A(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function me(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(a){o=a}try{t(...n)}catch(a){o??(o=a)}if(o!==void 0)throw o}}function ge(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function be(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let a of o)n[a]={...e.columnTypes?.[a],...t.columnTypes?.[a]};return n}function ye(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let a=t[o],l=n[o];typeof a!="function"||typeof l!="function"||(e[o]=me(a,l))}}function he(e,t){let n={...e,...t,features:t.features??e.features};(e.defaultColDef||t.defaultColDef)&&(n.defaultColDef={...e.defaultColDef,...t.defaultColDef}),(e.locale||t.locale)&&(n.locale={...e.locale,...t.locale});let o=ge(e,t);o&&(n.components=o);let a=be(e,t);return a&&(n.columnTypes=a),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=A(e.pagination,t.pagination),n.statusBar=A(e.statusBar,t.statusBar),n.watermark=A(e.watermark,t.watermark),ye(n,e,t),n}function D(...e){return e.reduce(he,{})}function Te(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var we=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function U(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[a,l]of Object.entries(t)){if(!we.includes(a)&&(a!=="dataProcessor"||l==null||typeof l=="function")){o[a]=l;continue}let s={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:a,layer:n,message:a==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${a}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(s),e.strict!==!1)throw new TypeError(s.message)}return o}function q(e={}){let t=U(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(U(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function ve(e,t){let n=q({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[a,l]of Object.entries(n.presets))o[a]=D(e.presets[a]??{},l);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function De(e,t,n,o){let a=t===void 0?e.defaultPreset:t,l=[{name:"application defaults",options:e.defaults}];for(let i of Te(a)){let m=e.presets[i];if(!m){let d={code:"UNKNOWN_PRESET",preset:i,message:`[MachTable] Unknown preset "${i}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}l.push({name:`preset:${i}`,options:m})}l.push({name:"table props",options:n});let s={rowNumber:!0,...D(...l.map(i=>i.options))};return{options:s,explain(i){let m=l.filter(g=>Object.prototype.hasOwnProperty.call(g.options,i)).map(g=>({name:g.name,value:g.options[i]})),d=m[m.length-1];return{key:i,value:s[i],source:d?.name??"MachTable built-in",layers:m}}}}export{fe as GRID_OPTION_KEYS,pe as GRID_OPTION_META,de as beginGridInput,se as canReplaceGridData,ne as createSelectControl,R as equivalentConfigValue,X as equivalentGridOption,ve as mergeMachTableConfig,q as normalizeMachTableConfig,ae as readGridCell,De as resolveMachTableGridOptions,re as resumeGrid,oe as suspendGrid,ie as writeGridInput};
|
package/dist/analysis.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var D=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(t,e)=>{for(var n in e)D(t,n,{get:e[n],enumerable:!0})},le=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!se.call(t,o)&&o!==n&&D(t,o,{get:()=>e[o],enumerable:!(r=oe(e,o))||r.enumerable});return t};var ue=t=>le(D({},"__esModule",{value:!0}),t);var ke={};ae(ke,{createPivot:()=>C,evaluateFormulas:()=>S,mountAnalysis:()=>re});module.exports=ue(ke);var ce=new Set(["__proto__","prototype","constructor"]),M=new Map;function G(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ce.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function E(t){return G(t)!==null}function x(t,e){if(t==null)return;let n=G(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function U(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function V(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function B(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var de=new Set(["sum","count","avg","min","max"]);function Y(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function W(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function me(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!E(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){fe(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function fe(t){if(!de.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!E(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function z(t,e,n){let r=t.get(e);r||(r=U(),t.set(e,r)),V(r,n)}function pe(t,e){return JSON.stringify([t===null?"total":Y(t),e.field??null,e.aggregate])}function C(t,e){me(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>W(x(s,p))),f=Y(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>W(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;K(d,r,o,h,p,g),i.length&&K(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)q(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:X(a,u.cells)}));return{columns:a,rows:l,totals:X(a,o),inputCount:t.length}}function q(t,e,n){let r=pe(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function K(t,e,n,r,o,i){let a=q(e,r,o);z(t.cells,a,i),z(n,a,i)}function X(t,e){let n=Object.create(null);for(let r of t)n[r.id]=B(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},J={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},he=new Set(["SUM","MIN","MAX","AVG"]);function ge(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ve(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ve(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function Z(t){let e=ge(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(J,d)?J[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!he.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function k(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function be(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return k(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return k((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return k(be(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return k(t.name==="AVG"?r/n.length:r)}function S(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!E(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,Z(l))}catch(s){r.set(a,Q(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=we(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Q(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function ye(t,e){if(!E(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return k(n)}function we(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return ye(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=k(T(l,o));return n.set(i,s),s}catch(l){let s=Q(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function ee(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function te(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",ee(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function ne(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],O=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,I)=>{let R=b.values[e];if(R==null){O();return}let N=55+v*(I+.5),F=p(R),$=b.dimensions.map(j=>j==null?"\u7A7A\u503C":String(j)).join(" / ")||"\u5168\u90E8",H=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});H.append(y("title",{},`${$}: ${R}`)),l.append(H),n==="line"&&P.push(`${N},${F}`),(i.length<=10||I%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},$.slice(0,12)))}),O(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var xe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function re(t,e){return new L(t,e)}var L=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=te(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(xe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=S(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
1
|
+
"use strict";var D=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(t,e)=>{for(var n in e)D(t,n,{get:e[n],enumerable:!0})},le=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!se.call(t,o)&&o!==n&&D(t,o,{get:()=>e[o],enumerable:!(r=oe(e,o))||r.enumerable});return t};var ue=t=>le(D({},"__esModule",{value:!0}),t);var Ee={};ae(Ee,{createPivot:()=>C,evaluateFormulas:()=>S,mountAnalysis:()=>re});module.exports=ue(Ee);var ce=new Set(["__proto__","prototype","constructor"]),M=new Map;function G(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ce.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function k(t){return G(t)!==null}function x(t,e){if(t==null)return;let n=G(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function U(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function V(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function B(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var de=new Set(["sum","count","avg","min","max"]);function Y(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function W(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function me(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!k(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){fe(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function fe(t){if(!de.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!k(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function z(t,e,n){let r=t.get(e);r||(r=U(),t.set(e,r)),V(r,n)}function pe(t,e){return JSON.stringify([t===null?"total":Y(t),e.field??null,e.aggregate])}function C(t,e){me(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>W(x(s,p))),f=Y(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>W(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;K(d,r,o,h,p,g),i.length&&K(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)q(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:X(a,u.cells)}));return{columns:a,rows:l,totals:X(a,o),inputCount:t.length}}function q(t,e,n){let r=pe(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function K(t,e,n,r,o,i){let a=q(e,r,o);z(t.cells,a,i),z(n,a,i)}function X(t,e){let n=Object.create(null);for(let r of t)n[r.id]=B(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},J={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},he=new Set(["SUM","MIN","MAX","AVG"]);function ge(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ve(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ve(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function Z(t){let e=ge(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(J,d)?J[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!he.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function E(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function be(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return E(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return E((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return E(be(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return E(t.name==="AVG"?r/n.length:r)}function S(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!k(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,Z(l))}catch(s){r.set(a,Q(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=we(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Q(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function ye(t,e){if(!k(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return E(n)}function we(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return ye(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=E(T(l,o));return n.set(i,s),s}catch(l){let s=Q(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function ee(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function te(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",ee(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function ne(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],O=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,I)=>{let R=b.values[e];if(R==null){O();return}let N=55+v*(I+.5),F=p(R),$=b.dimensions.map(j=>j==null?"\u7A7A\u503C":String(j)).join(" / ")||"\u5168\u90E8",H=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});H.append(y("title",{},`${$}: ${R}`)),l.append(H),n==="line"&&P.push(`${N},${F}`),(i.length<=10||I%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},$.slice(0,12)))}),O(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var xe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function re(t,e){return new L(t,e)}var L=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=te(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(xe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=S(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
2
2
|
${l.join(`
|
|
3
3
|
`)}`)}this.f(r),this.result=C(o.rows,this.config),this.page=0,this.refresh();let i=this.options.api.rows.isRemote()?"\u8FDC\u7A0B\u6A21\u5F0F\u4EC5\u5305\u542B\u5DF2\u52A0\u8F7D\u884C\uFF0C\u4E0D\u4EE3\u8868\u670D\u52A1\u7AEF\u5168\u91CF\u3002":"",a=n>e.length?`\u5DF2\u52A0\u8F7D ${n} \u884C\uFF0C\u672C\u6B21\u4EC5\u5206\u6790\u524D ${e.length} \u884C\u3002`:`\u5206\u6790\u5DF2\u52A0\u8F7D\u7684 ${e.length} \u884C\u3002`;this.e.status.textContent=`${a}${i} \u751F\u6210 ${this.result.rows.length} \u4E2A\u884C\u7EC4\u3001${this.result.columns.length} \u4E2A\u7ED3\u679C\u5217\u3002`,this.e.status.classList.remove("mach-workbench__status--error"),this.e.status.setAttribute("role","status")}catch(r){this.result=null,this.results.replaceChildren(),this.e.status.textContent=r instanceof Error?r.message:String(r),this.e.status.classList.add("mach-workbench__status--error"),this.e.status.setAttribute("role","alert")}}m(){let e=Object.create(null);for(let n of this.formulas){if(!n.field||Object.prototype.hasOwnProperty.call(e,n.field))throw new Error("\u516C\u5F0F\u7ED3\u679C\u5217\u4E0D\u80FD\u4E3A\u7A7A\u6216\u91CD\u590D");e[n.field]=n.expression}return e}f(e){let n=new Set([...this.l().map(o=>o.field),...Object.keys(e)]),r=[...this.config.rowFields,...this.config.columnFields??[],...this.config.values.flatMap(o=>o.field?[o.field]:[])];for(let o of r)if(!n.has(o))throw new Error(`\u5B57\u6BB5\u5DF2\u79FB\u9664\u6216\u4E0D\u53EF\u5206\u6790\uFF1A${o}`)}n(){if(this.results.replaceChildren(),!this.result)return;let e=this.result;e.columns.some(l=>l.id===this.t)||(this.t=e.columns[0]?.id??"");let n=c("div","mach-workbench__tools");n.append(A("\u56FE\u8868\u7C7B\u578B",[{value:"bar",label:"\u67F1\u72B6\u56FE"},{value:"line",label:"\u6298\u7EBF\u56FE"}],this.o,l=>{this.o=l,this.n(),_(this.results,"\u56FE\u8868\u7C7B\u578B")}),A("\u56FE\u8868\u6307\u6807",e.columns.map(l=>({value:l.id,label:l.label})),this.t,l=>{this.t=l,this.n(),_(this.results,"\u56FE\u8868\u6307\u6807")})),this.results.append(n,ne(e,this.t,this.o),this.table(e));let r=Math.max(1,Math.ceil(e.rows.length/50)),o=c("nav","mach-workbench__tools");o.setAttribute("aria-label","\u5206\u6790\u7ED3\u679C\u5206\u9875");let i=w("\u4E0A\u4E00\u9875",()=>{this.page--,this.n(),_(this.results.querySelector("nav"),"\u4E0A\u4E00\u9875")}),a=w("\u4E0B\u4E00\u9875",()=>{this.page++,this.n(),_(this.results.querySelector("nav"),"\u4E0B\u4E00\u9875")});i.disabled=this.page<=0,a.disabled=this.page>=r-1,o.append(i,c("span",void 0,`\u7B2C ${this.page+1} / ${r} \u9875 \xB7 \u6BCF\u9875 50 \u7EC4`),a),this.results.append(o)}table(e){let n=c("div","mach-analysis__table-wrap"),r=c("table","mach-analysis__table");r.append(c("caption",void 0,"\u900F\u89C6\u7ED3\u679C\u6570\u636E\u8868\uFF08\u5B8C\u6574\u7ED3\u679C\u53EF\u5206\u9875\u67E5\u770B\uFF09"));let o=c("thead"),i=c("tr");for(let s of["\u884C\u7EF4\u5EA6",...e.columns.map(u=>u.label)]){let u=c("th",void 0,s);u.scope="col",i.append(u)}o.append(i);let a=c("tbody");for(let s of e.rows.slice(this.page*50,(this.page+1)*50))a.append(this.u(s.dimensions.map(u=>u==null?"\u7A7A\u503C":String(u)).join(" / ")||"\u5168\u90E8",e,s.values));let l=c("tfoot");return l.append(this.u("\u5408\u8BA1",e,e.totals)),r.append(o,a,l),n.append(r),n}u(e,n,r){let o=c("tr"),i=c("th",void 0,e);i.scope="row",o.append(i);for(let a of n.columns){let l=r[a.id],s=c("td",void 0,l==null?"\u2014":l.toLocaleString("zh-CN",{maximumFractionDigits:6}));s.title=l==null?"\u65E0\u6570\u503C":String(l),o.append(s)}return o}};0&&(module.exports={createPivot,evaluateFormulas,mountAnalysis});
|
package/dist/analysis.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-
|
|
2
|
-
import './api-
|
|
1
|
+
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-DfLrRGYY.cjs';
|
|
2
|
+
import './api-Bgcy7aRd.cjs';
|
|
3
3
|
|
|
4
4
|
type PivotAggregate = "sum" | "count" | "avg" | "min" | "max";
|
|
5
5
|
type PivotDimension = string | number | boolean | null;
|
package/dist/analysis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-
|
|
2
|
-
import './api-
|
|
1
|
+
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-CLEc9O2p.js';
|
|
2
|
+
import './api-Bgcy7aRd.js';
|
|
3
3
|
|
|
4
4
|
type PivotAggregate = "sum" | "count" | "avg" | "min" | "max";
|
|
5
5
|
type PivotDimension = string | number | boolean | null;
|
package/dist/analysis.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var ne=new Set(["__proto__","prototype","constructor"]),M=new Map;function j(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ne.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function E(t){return j(t)!==null}function x(t,e){if(t==null)return;let n=j(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function G(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function U(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function V(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var re=new Set(["sum","count","avg","min","max"]);function X(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function B(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function oe(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!E(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){ie(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function ie(t){if(!re.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!E(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function W(t,e,n){let r=t.get(e);r||(r=G(),t.set(e,r)),U(r,n)}function se(t,e){return JSON.stringify([t===null?"total":X(t),e.field??null,e.aggregate])}function S(t,e){oe(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>B(x(s,p))),f=X(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>B(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;z(d,r,o,h,p,g),i.length&&z(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)Y(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:K(a,u.cells)}));return{columns:a,rows:l,totals:K(a,o),inputCount:t.length}}function Y(t,e,n){let r=se(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function z(t,e,n,r,o,i){let a=Y(e,r,o);W(t.cells,a,i),W(n,a,i)}function K(t,e){let n=Object.create(null);for(let r of t)n[r.id]=V(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},q={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},ae=new Set(["SUM","MIN","MAX","AVG"]);function le(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ue(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ue(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function J(t){let e=le(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(q,d)?q[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!ae.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function k(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function ce(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return k(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return k((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return k(ce(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return k(t.name==="AVG"?r/n.length:r)}function R(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!E(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,J(l))}catch(s){r.set(a,Z(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=me(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Z(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function de(t,e){if(!E(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return k(n)}function me(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return de(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=k(T(l,o));return n.set(i,s),s}catch(l){let s=Z(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function Q(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function ee(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",Q(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function te(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],L=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,O)=>{let C=b.values[e];if(C==null){L();return}let N=55+v*(O+.5),F=p(C),I=b.dimensions.map(H=>H==null?"\u7A7A\u503C":String(H)).join(" / ")||"\u5168\u90E8",$=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});$.append(y("title",{},`${I}: ${C}`)),l.append($),n==="line"&&P.push(`${N},${F}`),(i.length<=10||O%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},I.slice(0,12)))}),L(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var fe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function pe(t,e){return new D(t,e)}var D=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=ee(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(fe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=R(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
1
|
+
var ne=new Set(["__proto__","prototype","constructor"]),M=new Map;function j(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ne.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function k(t){return j(t)!==null}function x(t,e){if(t==null)return;let n=j(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function G(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function U(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function V(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var re=new Set(["sum","count","avg","min","max"]);function X(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function B(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function oe(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!k(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){ie(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function ie(t){if(!re.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!k(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function W(t,e,n){let r=t.get(e);r||(r=G(),t.set(e,r)),U(r,n)}function se(t,e){return JSON.stringify([t===null?"total":X(t),e.field??null,e.aggregate])}function S(t,e){oe(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>B(x(s,p))),f=X(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>B(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;z(d,r,o,h,p,g),i.length&&z(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)Y(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:K(a,u.cells)}));return{columns:a,rows:l,totals:K(a,o),inputCount:t.length}}function Y(t,e,n){let r=se(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function z(t,e,n,r,o,i){let a=Y(e,r,o);W(t.cells,a,i),W(n,a,i)}function K(t,e){let n=Object.create(null);for(let r of t)n[r.id]=V(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},q={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},ae=new Set(["SUM","MIN","MAX","AVG"]);function le(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ue(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ue(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function J(t){let e=le(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(q,d)?q[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!ae.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function E(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function ce(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return E(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return E((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return E(ce(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return E(t.name==="AVG"?r/n.length:r)}function R(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!k(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,J(l))}catch(s){r.set(a,Z(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=me(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Z(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function de(t,e){if(!k(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return E(n)}function me(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return de(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=E(T(l,o));return n.set(i,s),s}catch(l){let s=Z(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function Q(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function ee(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",Q(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function te(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],L=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,O)=>{let C=b.values[e];if(C==null){L();return}let N=55+v*(O+.5),F=p(C),I=b.dimensions.map(H=>H==null?"\u7A7A\u503C":String(H)).join(" / ")||"\u5168\u90E8",$=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});$.append(y("title",{},`${I}: ${C}`)),l.append($),n==="line"&&P.push(`${N},${F}`),(i.length<=10||O%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},I.slice(0,12)))}),L(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var fe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function pe(t,e){return new D(t,e)}var D=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=ee(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(fe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=R(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
2
2
|
${l.join(`
|
|
3
3
|
`)}`)}this.f(r),this.result=S(o.rows,this.config),this.page=0,this.refresh();let i=this.options.api.rows.isRemote()?"\u8FDC\u7A0B\u6A21\u5F0F\u4EC5\u5305\u542B\u5DF2\u52A0\u8F7D\u884C\uFF0C\u4E0D\u4EE3\u8868\u670D\u52A1\u7AEF\u5168\u91CF\u3002":"",a=n>e.length?`\u5DF2\u52A0\u8F7D ${n} \u884C\uFF0C\u672C\u6B21\u4EC5\u5206\u6790\u524D ${e.length} \u884C\u3002`:`\u5206\u6790\u5DF2\u52A0\u8F7D\u7684 ${e.length} \u884C\u3002`;this.e.status.textContent=`${a}${i} \u751F\u6210 ${this.result.rows.length} \u4E2A\u884C\u7EC4\u3001${this.result.columns.length} \u4E2A\u7ED3\u679C\u5217\u3002`,this.e.status.classList.remove("mach-workbench__status--error"),this.e.status.setAttribute("role","status")}catch(r){this.result=null,this.results.replaceChildren(),this.e.status.textContent=r instanceof Error?r.message:String(r),this.e.status.classList.add("mach-workbench__status--error"),this.e.status.setAttribute("role","alert")}}m(){let e=Object.create(null);for(let n of this.formulas){if(!n.field||Object.prototype.hasOwnProperty.call(e,n.field))throw new Error("\u516C\u5F0F\u7ED3\u679C\u5217\u4E0D\u80FD\u4E3A\u7A7A\u6216\u91CD\u590D");e[n.field]=n.expression}return e}f(e){let n=new Set([...this.l().map(o=>o.field),...Object.keys(e)]),r=[...this.config.rowFields,...this.config.columnFields??[],...this.config.values.flatMap(o=>o.field?[o.field]:[])];for(let o of r)if(!n.has(o))throw new Error(`\u5B57\u6BB5\u5DF2\u79FB\u9664\u6216\u4E0D\u53EF\u5206\u6790\uFF1A${o}`)}n(){if(this.results.replaceChildren(),!this.result)return;let e=this.result;e.columns.some(l=>l.id===this.t)||(this.t=e.columns[0]?.id??"");let n=c("div","mach-workbench__tools");n.append(A("\u56FE\u8868\u7C7B\u578B",[{value:"bar",label:"\u67F1\u72B6\u56FE"},{value:"line",label:"\u6298\u7EBF\u56FE"}],this.o,l=>{this.o=l,this.n(),_(this.results,"\u56FE\u8868\u7C7B\u578B")}),A("\u56FE\u8868\u6307\u6807",e.columns.map(l=>({value:l.id,label:l.label})),this.t,l=>{this.t=l,this.n(),_(this.results,"\u56FE\u8868\u6307\u6807")})),this.results.append(n,te(e,this.t,this.o),this.table(e));let r=Math.max(1,Math.ceil(e.rows.length/50)),o=c("nav","mach-workbench__tools");o.setAttribute("aria-label","\u5206\u6790\u7ED3\u679C\u5206\u9875");let i=w("\u4E0A\u4E00\u9875",()=>{this.page--,this.n(),_(this.results.querySelector("nav"),"\u4E0A\u4E00\u9875")}),a=w("\u4E0B\u4E00\u9875",()=>{this.page++,this.n(),_(this.results.querySelector("nav"),"\u4E0B\u4E00\u9875")});i.disabled=this.page<=0,a.disabled=this.page>=r-1,o.append(i,c("span",void 0,`\u7B2C ${this.page+1} / ${r} \u9875 \xB7 \u6BCF\u9875 50 \u7EC4`),a),this.results.append(o)}table(e){let n=c("div","mach-analysis__table-wrap"),r=c("table","mach-analysis__table");r.append(c("caption",void 0,"\u900F\u89C6\u7ED3\u679C\u6570\u636E\u8868\uFF08\u5B8C\u6574\u7ED3\u679C\u53EF\u5206\u9875\u67E5\u770B\uFF09"));let o=c("thead"),i=c("tr");for(let s of["\u884C\u7EF4\u5EA6",...e.columns.map(u=>u.label)]){let u=c("th",void 0,s);u.scope="col",i.append(u)}o.append(i);let a=c("tbody");for(let s of e.rows.slice(this.page*50,(this.page+1)*50))a.append(this.u(s.dimensions.map(u=>u==null?"\u7A7A\u503C":String(u)).join(" / ")||"\u5168\u90E8",e,s.values));let l=c("tfoot");return l.append(this.u("\u5408\u8BA1",e,e.totals)),r.append(o,a,l),n.append(r),n}u(e,n,r){let o=c("tr"),i=c("th",void 0,e);i.scope="row",o.append(i);for(let a of n.columns){let l=r[a.id],s=c("td",void 0,l==null?"\u2014":l.toLocaleString("zh-CN",{maximumFractionDigits:6}));s.title=l==null?"\u65E0\u6570\u503C":String(l),o.append(s)}return o}};export{S as createPivot,R as evaluateFormulas,pe as mountAnalysis};
|
|
@@ -28,6 +28,8 @@ declare class Column<TData = any> {
|
|
|
28
28
|
parentGroup: ColumnGroup<TData> | null;
|
|
29
29
|
level: number;
|
|
30
30
|
isDetailToggle: boolean;
|
|
31
|
+
/** Generated UI column excluded from the business export schema. */
|
|
32
|
+
isAutoRowNumber?: true;
|
|
31
33
|
constructor(id: string, colDef: ColDef<TData>);
|
|
32
34
|
get sortable(): boolean;
|
|
33
35
|
get resizable(): boolean;
|
|
@@ -219,7 +221,7 @@ interface SelectEditorOption {
|
|
|
219
221
|
interface SelectEditorParams {
|
|
220
222
|
/** Primitive options kept for concise same-label/same-value selects. */
|
|
221
223
|
values?: readonly (string | number)[];
|
|
222
|
-
/** Label/value options
|
|
224
|
+
/** Label/value options when the stored value differs from its display text. */
|
|
223
225
|
options?: readonly SelectEditorOption[];
|
|
224
226
|
}
|
|
225
227
|
interface SetFilterParams {
|
|
@@ -932,6 +934,8 @@ interface GridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
932
934
|
loadTreeChildren?: (params: TreeDataLoadParams<TData>) => Promise<readonly TData[]>;
|
|
933
935
|
autoCheckedChildren?: boolean;
|
|
934
936
|
defaultExpandAll?: boolean;
|
|
937
|
+
/** Add a row-number column when no index column is declared. Enabled by default by the Vue and React components. */
|
|
938
|
+
rowNumber?: boolean;
|
|
935
939
|
indexOffset?: number;
|
|
936
940
|
/** Apply flat local row moves automatically (default true). False emits intent for server-controlled ordering. */
|
|
937
941
|
applyRowDrag?: boolean;
|
|
@@ -1051,6 +1055,7 @@ interface ResolvedGridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
1051
1055
|
loadTreeChildren?: (params: TreeDataLoadParams<TData>) => Promise<readonly TData[]>;
|
|
1052
1056
|
autoCheckedChildren: boolean;
|
|
1053
1057
|
defaultExpandAll: boolean;
|
|
1058
|
+
rowNumber: boolean;
|
|
1054
1059
|
indexOffset: number;
|
|
1055
1060
|
applyRowDrag: boolean;
|
|
1056
1061
|
rowDragPolicy?: RowDragPolicy<TData>;
|
|
@@ -1435,4 +1440,4 @@ interface GridApi<TData = any> {
|
|
|
1435
1440
|
isDestroyed(): boolean;
|
|
1436
1441
|
}
|
|
1437
1442
|
|
|
1438
|
-
export { type
|
|
1443
|
+
export { type ContextMenuItem as $, type AdvancedFilterModel as A, type ApplyGridStateOptions as B, type ColDef as C, type CellAlign as D, type CellClassParams as E, type FilterType as F, type GridFeature as G, type CellClassRule as H, type ImportMatrixOptions as I, type CellClickEvent as J, type CellContextMenuEvent as K, type CellDoubleClickEvent as L, type CellEditingStartedEvent as M, type CellEditingStoppedEvent as N, type CellEditorFactory as O, type CellEditorParams as P, type CellRendererOutput as Q, type CellStyleRule as R, type SortModel as S, type CellValueChangedEvent as T, type ColDefOrGroup as U, type ColumnLayoutMode as V, type ColumnMovedEvent as W, type ColumnResizedEvent as X, type ColumnStatus as Y, type ColumnVisibilityChangedEvent as Z, type ColumnWorkbenchItem as _, type GridCellRange as a, type PaginationChangedEvent as a$, type ContextMenuParams as a0, type CsvExportParams as a1, DEFAULT_LOCALE as a2, type DatasourceMode as a3, type DateFilterCondition as a4, type DateFilterMatch as a5, type DetailRowRendererParams as a6, type DetailToggledEvent as a7, type DirtyStateChangedEvent as a8, type DomLayoutMode as a9, type GridHierarchyApi as aA, type GridIoApi as aB, type GridPaginationApi as aC, type GridPerformanceSnapshot as aD, type GridPersistenceOptions as aE, type GridReadyEvent as aF, type GridRowsApi as aG, type GridSelectionApi as aH, type GridSortingApi as aI, type GridStateApi as aJ, type GridStateSection as aK, type GridUpdateSchedulerSnapshot as aL, type GridViewApi as aM, type HeaderComponentParams as aN, type ICellEditor as aO, type ICellRendererResult as aP, type ImportCsvOptions as aQ, type InfiniteGetRowsParams as aR, LOCALE_EN as aS, type MachTableLocale as aT, type MachTableLocaleKey as aU, type MatrixExportParams as aV, type ModelUpdatedEvent as aW, type NumberFilterCondition as aX, type NumberFilterMatch as aY, type OverlayContent as aZ, type OverlayTemplate as a_, EVENT_TYPES as aa, type EditableIndicator as ab, type EditableParams as ac, type EventHandlers as ad, type FilterChangedEvent as ae, type GetRowHeightParams as af, type GridAsyncOptions as ag, type GridBatchSaveResult as ah, type GridCellChange as ai, type GridColumnsApi as aj, type GridDataProcessorColumn as ak, type GridDataProcessorRequest as al, type GridDataProcessorResult as am, type GridDataProcessorRow as an, type GridDatasource as ao, type GridDiagnosticError as ap, type GridDiagnostics as aq, type GridDiagnosticsApi as ar, type GridEditType as as, type GridEditingApi as at, type GridErrorCode as au, type GridErrorEvent as av, type GridEventBase as aw, type GridEventMap as ax, type GridFeatureContext as ay, type GridFilteringApi as az, type GridApi as b, type PaginationConfig as b0, type PinnedDirection as b1, type PrintOptions as b2, type RangeSelectionChangedEvent as b3, type RefreshCellsParams as b4, type RemoteBlockCacheSnapshot as b5, type ResolvedGridOptions as b6, type RowClickEvent as b7, type RowDragEndEvent as b8, type RowDragIntent as b9, type ThemeMode as bA, type TooltipParams as bB, type TreeChildrenLoadFailedEvent as bC, type TreeChildrenLoadedEvent as bD, type TreeDataLoadParams as bE, type ValueFormatterParams as bF, type ValueGetterParams as bG, type ValueInputSource as bH, type ValueOutputTarget as bI, type ValueParserParams as bJ, type ValueSerializerParams as bK, type ValueSetterParams as bL, type WatermarkConfig as bM, formatText as bN, formatTwo as bO, isColDefGroup as bP, matchLocaleKey as bQ, type RowDragPolicy as ba, type RowEditChange as bb, type RowEditValidationParams as bc, type RowEditValidationResult as bd, type RowEditingStartedEvent as be, type RowEditingStoppedEvent as bf, type RowNode as bg, type RowSelectionMode as bh, type RowStyleParams as bi, type RowStyleRule as bj, type RowTone as bk, type RowTransaction as bl, type SaveChangeIssue as bm, type SaveChangesResult as bn, type SelectEditorOption as bo, type SelectEditorParams as bp, type SelectionChangedEvent as bq, type SetFilterCondition as br, type SetFilterParams as bs, type SortChangedEvent as bt, type SortDirection as bu, type SortModelItem as bv, type StatusBarConfig as bw, type StatusBarPanel as bx, type TextFilterCondition as by, type TextFilterMatch as bz, type GridOptions as c, type GridDataProcessor as d, type GridComponents as e, type GridState as f, type GridStateStore as g, type FilterModel as h, type FieldPath as i, type GridEventType as j, type SaveChangesHandler as k, type ColumnFilter as l, type AdvancedFilterCondition as m, type AdvancedFilterNode as n, type AdvancedFilterGroup as o, type ColDefGroup as p, type GridStateInput as q, type GridSize as r, type CellRendererParams as s, type GridChange as t, type CellRendererFn as u, type FieldPathValue as v, type SaveChangeConflict as w, type ColumnState as x, type ActionPolicy as y, type ActionPolicyContext as z };
|