@agile-team/mach-table 0.31.2 → 0.32.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.
Files changed (48) hide show
  1. package/README.md +27 -1
  2. package/dist/adapter.cjs +1 -1
  3. package/dist/adapter.d.cts +20 -3
  4. package/dist/adapter.d.ts +20 -3
  5. package/dist/adapter.js +1 -1
  6. package/dist/analysis.cjs +3 -0
  7. package/dist/analysis.d.cts +60 -0
  8. package/dist/analysis.d.ts +60 -0
  9. package/dist/analysis.js +3 -0
  10. package/dist/{options-Bi_m5kXL.d.cts → api-pOhyuSQk.d.cts} +780 -754
  11. package/dist/{options-Bi_m5kXL.d.ts → api-pOhyuSQk.d.ts} +780 -754
  12. package/dist/{configuration-C9KYeIy1.d.ts → configuration-SYWVjGft.d.ts} +1 -1
  13. package/dist/{configuration-Bj_JwdTd.d.cts → configuration-gAE1eZuB.d.cts} +1 -1
  14. package/dist/index.cjs +6 -6
  15. package/dist/index.d.cts +3 -3
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +6 -6
  18. package/dist/mach-table.css +1 -1
  19. package/dist/multi-range.cjs +4 -0
  20. package/dist/multi-range.d.cts +13 -0
  21. package/dist/multi-range.d.ts +13 -0
  22. package/dist/multi-range.js +4 -0
  23. package/dist/ordering.cjs +1 -0
  24. package/dist/ordering.d.cts +93 -0
  25. package/dist/ordering.d.ts +93 -0
  26. package/dist/ordering.js +1 -0
  27. package/dist/preferences.cjs +1 -0
  28. package/dist/preferences.d.cts +71 -0
  29. package/dist/preferences.d.ts +71 -0
  30. package/dist/preferences.js +1 -0
  31. package/dist/server-side.cjs +1 -0
  32. package/dist/server-side.css +1 -0
  33. package/dist/server-side.css.d.ts +2 -0
  34. package/dist/server-side.d.cts +132 -0
  35. package/dist/server-side.d.ts +132 -0
  36. package/dist/server-side.js +1 -0
  37. package/dist/shared-Bi8hAuzn.d.cts +12 -0
  38. package/dist/shared-Bn77TiBm.d.ts +12 -0
  39. package/dist/workbench.cjs +1 -0
  40. package/dist/workbench.css +1 -0
  41. package/dist/workbench.css.d.ts +2 -0
  42. package/dist/workbench.d.cts +72 -0
  43. package/dist/workbench.d.ts +72 -0
  44. package/dist/workbench.js +1 -0
  45. package/dist/worker.d.cts +2 -2
  46. package/dist/worker.d.ts +2 -2
  47. package/package.json +72 -5
  48. /package/{styles → dist}/mach-table.css.d.ts +0 -0
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # @agile-team/mach-table
6
6
 
7
- MachTable 0.31.2 的框架无关 TypeScript Core:零运行时依赖,提供行列双虚拟化、领域化 API、单元格/整行编辑、树与分组、随机访问远程数据、区段隔离状态持久化和可诊断扩展系统。本版统一用户输入校验,完善缓存与异步保存边界,并优化筛选计划和失效列排序。
7
+ MachTable 0.32.0 的框架无关 TypeScript Core:零运行时依赖,提供行列双虚拟化、领域化 API、单元格/整行编辑、树与分组、随机访问远程数据、区段隔离状态持久化和可诊断扩展系统。本版增加六个按需高级子入口,完善内部资源所有权、框架生命周期与缓存操作边界。
8
8
 
9
9
  ```bash
10
10
  pnpm add @agile-team/mach-table
@@ -82,4 +82,30 @@ const options: GridOptions<Plan> = {
82
82
 
83
83
  文档:[快速开始](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/getting-started.md) · [企业接入](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/guide/enterprise-integration.md) · [API](https://github.com/ChenyCHENYU/MachTable/tree/main/docs/api)
84
84
 
85
+ ## 按需高级入口(0.32)
86
+
87
+ 仍从本包导入,无需另装高级功能包。普通根入口不加载这些实现或附加 CSS。
88
+
89
+ | 子路径 | 功能 |
90
+ | --- | --- |
91
+ | `/workbench` | 高级过滤草稿与应用、修改差异/部分保存/冲突审阅、手动诊断 |
92
+ | `/preferences` | 复合身份隔离、CAS、有序写入、历史版本及列 ID/类型迁移报告 |
93
+ | `/ordering` | 多行/树移动、防环与业务约束、失败回滚、持久化撤销/重做 |
94
+ | `/server-side` | 服务端分组/聚合、route 分页、缓存/刷新/事务及层级选择 |
95
+ | `/multi-range` | Ctrl/Cmd 追加范围、格式化复制、校验清空及撤销 |
96
+ | `/analysis` | Pivot、安全公式、柱/折线图和数据表回退 |
97
+
98
+ ```ts
99
+ import { mountAdvancedFilterBuilder } from "@agile-team/mach-table/workbench";
100
+ import "@agile-team/mach-table/styles/workbench.css";
101
+
102
+ const filters = mountAdvancedFilterBuilder(host, { api });
103
+ // 宿主卸载时调用;表格销毁也会释放工作台。
104
+ filters.destroy();
105
+ ```
106
+
107
+ 服务端分组控件使用 `/styles/server-side.css`,分析与多范围使用 `/styles/workbench.css`。排序、偏好和纯分析计算无需附加 CSS。服务端 Store 按 route 分页,不提供全树任意显示 offset;分析只处理当前已加载数据并显示范围。排序 undo/redo 的 transport 必须一次 CAS 保存 `context.operations` 的完整批次或 `context.plan.after`,只保存首参数无法完整恢复非连续/跨父级位置。
108
+
109
+ 完整示例与限制:[工作台](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/workbench.md) · [排序](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/row-presentation.md) · [企业偏好](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/enterprise-preferences.md) · [服务端 Store](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/server-side-store.md) · [多范围](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/multi-range.md) · [分析](https://github.com/ChenyCHENYU/MachTable/blob/main/docs/recipes/analysis.md)。
110
+
85
111
  Source-available © ChenyCHENYU (Agile Team). 任何使用均须事先取得书面授权。详见 [LICENSE](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSE) 与[授权流程](https://github.com/ChenyCHENYU/MachTable/blob/main/LICENSING.md)。
package/dist/adapter.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var x=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(e,t)=>{for(var n in t)x(e,n,{get:t[n],enumerable:!0})},ne=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of X(t))!ee.call(e,i)&&i!==n&&x(e,i,{get:()=>t[i],enumerable:!(o=Q(t,i))||o.enumerable});return e};var oe=e=>ne(x({},"__esModule",{value:!0}),e);var me={};te(me,{GRID_OPTION_KEYS:()=>R,GRID_OPTION_META:()=>M,createSelectControl:()=>Y,mergeMachTableConfig:()=>_,normalizeMachTableConfig:()=>L,resolveMachTableGridOptions:()=>W});module.exports=oe(me);var M={columnDefs:{kind:"array",update:"columnDefs"},rowData:{kind:"array",update:"rowData"},defaultColDef:{kind:"object",update:"options"},columnTypes:{kind:"object",update:"options"},rowKey:{kind:"unknown",update:"options"},rowHeight:{kind:"number",update:"options"},headerHeight:{kind:"number",update:"options"},rowBuffer:{kind:"number",update:"options"},columnLayout:{kind:"string",update:"options"},enableColumnResize:{kind:"boolean",update:"options"},domLayout:{kind:"string",update:"options"},rowSelection:{kind:"string",update:"options"},multiSort:{kind:"boolean",update:"options"},size:{kind:"string",update:"options"},stripedRows:{kind:"boolean",update:"options"},rowStyleRules:{kind:"array",update:"options"},showCellBorders:{kind:"boolean",update:"options"},theme:{kind:"string",update:"options"},quickFilterText:{kind:"string",update:"quickFilter"},advancedFilterModel:{kind:"object",update:"options"},masterDetail:{kind:"boolean",update:"options"},detailRowHeight:{kind:"number",update:"options"},detailRowRenderer:{kind:"function",update:"options"},isRowExpandable:{kind:"function",update:"options"},detailToggleColumn:{kind:"boolean",update:"options"},columnMenu:{kind:"boolean",update:"options"},aggFuncs:{kind:"object",update:"options"},components:{kind:"object",update:"options"},actionPolicy:{kind:"object",update:"options"},features:{kind:"array",update:"options"},initialState:{kind:"object",update:"options"},persistence:{kind:"boolean-object",update:"options"},locale:{kind:"object",update:"options"},editType:{kind:"string",update:"options"},editableIndicator:{kind:"string",update:"options"},rowEditValidator:{kind:"function",update:"options"},singleClickEdit:{kind:"boolean",update:"options"},manualSorting:{kind:"boolean",update:"options"},manualFiltering:{kind:"boolean",update:"options"},showSummary:{kind:"boolean",update:"options"},summaryMethod:{kind:"function",update:"options"},treeData:{kind:"boolean",update:"options"},childrenKey:{kind:"string",update:"options"},isTreeRowExpandable:{kind:"function",update:"options"},loadTreeChildren:{kind:"function",update:"options"},autoCheckedChildren:{kind:"boolean",update:"options"},defaultExpandAll:{kind:"boolean",update:"options"},indexOffset:{kind:"number",update:"options"},applyRowDrag:{kind:"boolean",update:"options"},undoStackSize:{kind:"number",update:"options"},asyncTransactionWaitMillis:{kind:"number",update:"options"},getRowHeight:{kind:"function",update:"options"},pinnedTopRowData:{kind:"array",update:"options"},pinnedBottomRowData:{kind:"array",update:"options"},pagination:{kind:"boolean-object",update:"options"},watermark:{kind:"boolean-object",update:"options"},suppressWarnings:{kind:"boolean",update:"options"},enableRangeSelection:{kind:"boolean",update:"options"},suppressClipboard:{kind:"boolean",update:"options"},contextMenu:{kind:"boolean",update:"options"},getContextMenuItems:{kind:"function",update:"options"},tooltipComponent:{kind:"function",update:"options"},tooltipShowDelay:{kind:"number",update:"options"},flashCells:{kind:"boolean",update:"options"},fillHandle:{kind:"boolean",update:"options"},statusBar:{kind:"boolean-object",update:"options"},datasource:{kind:"object",update:"options"},datasourceMode:{kind:"string",update:"options"},blockSize:{kind:"number",update:"options"},infiniteBufferRows:{kind:"number",update:"options"},maxBlocksInCache:{kind:"number",update:"options"},datasourceMaxConcurrentRequests:{kind:"number",update:"options"},blockPrefetch:{kind:"number",update:"options"},datasourceRowCount:{kind:"number",update:"options"},dataProcessor:{kind:"object",update:"options"},dataProcessorMinRows:{kind:"number",update:"options"},datasourceRetryCount:{kind:"number",update:"options"},datasourceRetryDelay:{kind:"number",update:"options"},datasourceRetryJitter:{kind:"number",update:"options"},suppressCellFocus:{kind:"boolean",update:"options"},suppressRowHoverHighlight:{kind:"boolean",update:"options"},suppressNoRowsOverlay:{kind:"boolean",update:"options"},suppressHeaderFocus:{kind:"boolean",update:"options"},ariaLabel:{kind:"string",update:"options"},ariaLabelledBy:{kind:"string",update:"options"},ariaDescribedBy:{kind:"string",update:"options"},loading:{kind:"boolean",update:"options"},error:{kind:"unknown",update:"options"},overlayNoRowsTemplate:{kind:"unknown",update:"options"},overlayLoadingTemplate:{kind:"unknown",update:"options"},overlayErrorTemplate:{kind:"unknown",update:"options"},allowUnsafeOverlayHtml:{kind:"boolean",update:"options"},className:{kind:"string",update:"options"}},R=Object.freeze(Object.keys(M)),ge=Object.freeze(R.filter(e=>M[e].update==="options"));function P(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function ae(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(i){o=i}try{t(...n)}catch(i){o??(o=i)}if(o!==void 0)throw o}}function ie(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function re(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let i of o)n[i]={...e.columnTypes?.[i],...t.columnTypes?.[i]};return n}function se(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let i=t[o],p=n[o];typeof i!="function"||typeof p!="function"||(e[o]=ae(i,p))}}function le(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=ie(e,t);o&&(n.components=o);let i=re(e,t);return i&&(n.columnTypes=i),(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),se(n,e,t),n}function C(...e){return e.reduce(le,{})}function de(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var ce=new Set(["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"]);function H(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[i,p]of Object.entries(t)){if(!ce.has(i)){o[i]=p;continue}let r={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:i,layer:n,message:`[MachTable] "${i}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(r),e.strict!==!1)throw new TypeError(r.message)}return o}function L(e={}){let t=H(e,e.defaults,"defaults");return{defaults:C({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,C(H(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function _(e,t){let n=L({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[i,p]of Object.entries(n.presets))o[i]=C(e.presets[i]??{},p);return{defaults:C(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 W(e,t,n,o){let i=t===void 0?e.defaultPreset:t,p=[{name:"application defaults",options:e.defaults}];for(let s of de(i)){let f=e.presets[s];if(!f){let d={code:"UNKNOWN_PRESET",preset:s,message:`[MachTable] Unknown preset "${s}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}p.push({name:`preset:${s}`,options:f})}p.push({name:"table props",options:n});let r=C(...p.map(s=>s.options));return{options:r,explain(s){let f=p.filter(b=>Object.prototype.hasOwnProperty.call(b.options,s)).map(b=>({name:b.name,value:b.options[s]})),d=f[f.length-1];return{key:s,value:r[s],source:d?.name??"MachTable built-in",layers:f}}}}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let i of Object.keys(n))o.setAttribute(i,n[i]);return o}var pe=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function K(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o of pe){let i=n.getPropertyValue(o).trim();i&&e.style.setProperty(o,i)}e.style.colorScheme=n.colorScheme}function z(e,t,n){return e<t?t:e>n?n:e}var B=0;function F(e="rg"){return B++,`${e}-${B}`}var m=null;function $(e){let t=e.target;m?.contains(t)||m?.close()}function S(){m?.reposition()}function U(e){e.key!=="Escape"||!m||(e.preventDefault(),e.stopImmediatePropagation(),m.close(!0))}function ue(e){m?.close!==e.close&&m?.close(),!m&&(m=e,document.addEventListener("mousedown",$,!0),document.addEventListener("keydown",U,!0),window.addEventListener("resize",S),window.addEventListener("scroll",S,!0))}function fe(e){m?.close===e&&(m=null,document.removeEventListener("mousedown",$,!0),document.removeEventListener("keydown",U,!0),window.removeEventListener("resize",S),window.removeEventListener("scroll",S,!0))}function k(e,t){return t?`${e} ${t}`:e}function E(e){let t=[];return e.forEach((n,o)=>{n.disabled||t.push(o)}),t}function V(e,t,n){let o=E(e);if(o.length===0)return-1;let i=o.indexOf(t);return i<0?n>0?o[0]:o[o.length-1]:o[Math.max(0,Math.min(o.length-1,i+n))]}function D(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function Y(e){let t=y("div",k("mach-select-control",e.classNames?.root)),n=y("select",k("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",k("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 i=y("span",k("mach-select-value",e.classNames?.value)),p=y("span",k("mach-select-caret",e.classNames?.caret));p.setAttribute("aria-hidden","true"),o.append(i,p);let r=y("div",k("mach-select-listbox",e.classNames?.listbox));r.id=F("mach-select-listbox"),r.setAttribute("role","listbox"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",r.id),t.append(n,o);let s=[...e.options],f=[],d=-1,b=!1,q=()=>e.themeSource??t.closest(".mach-root")??t,v=()=>{let a=s.find(l=>l.value===n.value);i.textContent=a?.label??n.value,f.forEach((l,g)=>{let c=s[g]?.value===n.value;l.setAttribute("aria-selected",c?"true":"false"),l.classList.toggle("mach-select-option--selected",c),l.classList.toggle("mach-select-option--active",g===d)}),o.setAttribute("aria-activedescendant",d>=0?f[d]?.id??"":"")},G=()=>{let a=o.getBoundingClientRect(),l=r.getBoundingClientRect(),g=Math.max(a.width,l.width),c=z(a.left,8,Math.max(8,window.innerWidth-g-8)),w=window.innerHeight-a.bottom-8,T=w<Math.min(l.height,240)&&a.top>w,u=T?Math.max(8,a.top-l.height-5):Math.min(window.innerHeight-l.height-8,a.bottom+5);r.style.minWidth=`${a.width}px`,r.style.left=`${c}px`,r.style.top=`${Math.max(8,u)}px`,r.classList.toggle("mach-select-listbox--above",T)},h=(a=!1)=>r.classList.contains("mach-select-listbox--open")?(r.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),r.remove(),fe(h),a&&!b&&o.focus({preventScroll:!0}),!0):!1,J=(a,l=!0)=>{!s[a]||s[a].disabled||(d=a,v(),l&&f[a]?.scrollIntoView?.({block:"nearest"}))},O=()=>{b||o.disabled||r.classList.contains("mach-select-listbox--open")||(ue({close:h,contains:a=>t.contains(a)||r.contains(a),reposition:G}),d=D(s,n.value),d<0&&(d=E(s)[0]??-1),K(r,q()),document.body.appendChild(r),r.classList.add("mach-select-listbox--open"),r.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),G(),v(),f[d]?.scrollIntoView?.({block:"nearest"}))},N=a=>{let l=s[a];!l||l.disabled||(n.value=l.value,d=a,v(),h(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},A=(a,l)=>{s=[...a],n.replaceChildren(),r.replaceChildren(),f=s.map((c,w)=>{let T=document.createElement("option");T.value=c.value,T.textContent=c.label,T.disabled=c.disabled===!0,n.appendChild(T);let u=y("button",k("mach-select-option",e.classNames?.option));return u.id=`${r.id}-option-${w}`,u.type="button",u.tabIndex=-1,u.dataset.value=c.value,u.disabled=c.disabled===!0,u.setAttribute("role","option"),u.textContent=c.label,u.addEventListener("mousedown",Z=>Z.preventDefault()),u.addEventListener("click",()=>N(w)),r.appendChild(u),u});let g=s.find(c=>!c.disabled)?.value??"";n.value=l!=null&&s.some(c=>c.value===l)?l:g,d=D(s,n.value),v()},I=a=>{if(a.key==="Tab"){h();return}if(a.key==="Escape"){if(!h(!0))return;a.preventDefault(),a.stopPropagation();return}if(a.key==="Enter"||a.key===" "){a.preventDefault(),a.stopPropagation(),r.classList.contains("mach-select-listbox--open")?N(d):O();return}let l=d;if(a.key==="ArrowDown")l=V(s,d,1);else if(a.key==="ArrowUp")l=V(s,d,-1);else if(a.key==="Home")l=E(s)[0]??-1;else if(a.key==="End"){let g=E(s);l=g[g.length-1]??-1}else return;a.preventDefault(),a.stopPropagation(),r.classList.contains("mach-select-listbox--open")||O(),J(l)},j=()=>{d=D(s,n.value),v(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{h()||O()}),o.addEventListener("keydown",I),n.addEventListener("change",j),A(s,e.value),{el:t,native:n,trigger:o,listbox:r,contains:a=>t.contains(a)||r.contains(a),isOpen:()=>r.classList.contains("mach-select-listbox--open"),open:O,close:h,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:a=>{n.value=a,d=D(s,a),v()},setOptions:A,destroy:()=>{b||(b=!0,h(),o.removeEventListener("keydown",I),n.removeEventListener("change",j),t.remove())}}}0&&(module.exports={GRID_OPTION_KEYS,GRID_OPTION_META,createSelectControl,mergeMachTableConfig,normalizeMachTableConfig,resolveMachTableGridOptions});
1
+ "use strict";var S=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var le=(e,t)=>{for(var n in t)S(e,n,{get:t[n],enumerable:!0})},de=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of re(t))!se.call(e,a)&&a!==n&&S(e,a,{get:()=>t[a],enumerable:!(o=ae(t,a))||o.enumerable});return e};var ce=e=>de(S({},"__esModule",{value:!0}),e);var ve={};le(ve,{GRID_OPTION_KEYS:()=>G,GRID_OPTION_META:()=>E,canReplaceGridData:()=>X,createSelectControl:()=>Y,mergeMachTableConfig:()=>te,normalizeMachTableConfig:()=>L,readGridCell:()=>Z,resolveMachTableGridOptions:()=>ne,resumeGrid:()=>J,suspendGrid:()=>q,writeGridInput:()=>Q});module.exports=ce(ve);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}var pe=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function W(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o of pe){let a=n.getPropertyValue(o).trim();a&&e.style.setProperty(o,a)}e.style.colorScheme=n.colorScheme}function B(e,t,n){return e<t?t:e>n?n:e}var F=0;function K(e="rg"){return F++,`${e}-${F}`}var p=null;function V(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function $(e){let t=e.target;p?.contains(t)||p?.close()}function R(){p?.reposition()}function U(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function ue(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",$,!0),document.addEventListener("keydown",U,!0),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0))}function fe(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",$,!0),document.removeEventListener("keydown",U,!0),window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0))}function k(e,t){return t?`${e} ${t}`:e}function x(e){let t=[];return e.forEach((n,o)=>{n.disabled||t.push(o)}),t}function z(e,t,n){let o=x(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 M(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function Y(e){let t=h("div",k("mach-select-control",e.classNames?.root)),n=h("select",k("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=h("button",k("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",k("mach-select-value",e.classNames?.value)),u=h("span",k("mach-select-caret",e.classNames?.caret));u.setAttribute("aria-hidden","true"),o.append(a,u);let r=h("div",k("mach-select-listbox",e.classNames?.listbox));r.id=K("mach-select-listbox"),r.setAttribute("role","listbox"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",r.id),t.append(n,o);let s=[...e.options],m=[],d=-1,g=!1,P=()=>e.themeSource??t.closest(".mach-root")??t,v=()=>{let i=s.find(l=>l.value===n.value);a.textContent=i?.label??n.value,m.forEach((l,b)=>{let c=s[b]?.value===n.value;l.setAttribute("aria-selected",c?"true":"false"),l.classList.toggle("mach-select-option--selected",c),l.classList.toggle("mach-select-option--active",b===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},I=()=>{let i=o.getBoundingClientRect(),l=r.getBoundingClientRect(),b=Math.max(i.width,l.width),c=B(i.left,8,Math.max(8,window.innerWidth-b-8)),D=window.innerHeight-i.bottom-8,T=D<Math.min(l.height,240)&&i.top>D,f=T?Math.max(8,i.top-l.height-5):Math.min(window.innerHeight-l.height-8,i.bottom+5);r.style.minWidth=`${i.width}px`,r.style.left=`${c}px`,r.style.top=`${Math.max(8,f)}px`,r.classList.toggle("mach-select-listbox--above",T)},y=(i=!1)=>r.classList.contains("mach-select-listbox--open")?(r.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),r.remove(),fe(y),i&&!g&&o.focus({preventScroll:!0}),!0):!1,oe=(i,l=!0)=>{!s[i]||s[i].disabled||(d=i,v(),l&&m[i]?.scrollIntoView?.({block:"nearest"}))},O=()=>{g||o.disabled||r.classList.contains("mach-select-listbox--open")||(ue({owner:P(),close:y,contains:i=>t.contains(i)||r.contains(i),reposition:I}),d=M(s,n.value),d<0&&(d=x(s)[0]??-1),W(r,P()),document.body.appendChild(r),r.classList.add("mach-select-listbox--open"),r.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),I(),v(),m[d]?.scrollIntoView?.({block:"nearest"}))},N=i=>{let l=s[i];!l||l.disabled||(n.value=l.value,d=i,v(),y(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},j=(i,l)=>{s=[...i],n.replaceChildren(),r.replaceChildren(),m=s.map((c,D)=>{let T=document.createElement("option");T.value=c.value,T.textContent=c.label,T.disabled=c.disabled===!0,n.appendChild(T);let f=h("button",k("mach-select-option",e.classNames?.option));return f.id=`${r.id}-option-${D}`,f.type="button",f.tabIndex=-1,f.dataset.value=c.value,f.disabled=c.disabled===!0,f.setAttribute("role","option"),f.textContent=c.label,f.addEventListener("mousedown",ie=>ie.preventDefault()),f.addEventListener("click",()=>N(D)),r.appendChild(f),f});let b=s.find(c=>!c.disabled)?.value??"";n.value=l!=null&&s.some(c=>c.value===l)?l:b,d=M(s,n.value),v()},H=i=>{if(i.key==="Tab"){y();return}if(i.key==="Escape"){if(!y(!0))return;i.preventDefault(),i.stopPropagation();return}if(i.key==="Enter"||i.key===" "){i.preventDefault(),i.stopPropagation(),r.classList.contains("mach-select-listbox--open")?N(d):O();return}let l=d;if(i.key==="ArrowDown")l=z(s,d,1);else if(i.key==="ArrowUp")l=z(s,d,-1);else if(i.key==="Home")l=x(s)[0]??-1;else if(i.key==="End"){let b=x(s);l=b[b.length-1]??-1}else return;i.preventDefault(),i.stopPropagation(),r.classList.contains("mach-select-listbox--open")||O(),oe(l)},_=()=>{d=M(s,n.value),v(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{y()||O()}),o.addEventListener("keydown",H),n.addEventListener("change",_),j(s,e.value),{el:t,native:n,trigger:o,listbox:r,contains:i=>t.contains(i)||r.contains(i),isOpen:()=>r.classList.contains("mach-select-listbox--open"),open:O,close:y,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:i=>{n.value=i,d=M(s,i),v()},setOptions:j,destroy:()=>{g||(g=!0,y(),o.removeEventListener("keydown",H),n.removeEventListener("change",_),t.remove())}}}var C=Symbol.for("mach-table.adapter.lifecycle.v1");function q(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&V(t),e[C]?.suspend()}function J(e){e.isDestroyed()||e[C]?.resume()}function Z(e,t,n){return e.isDestroyed()?"":e[C]?.readCell(t,n)??""}function Q(e,t){e.isDestroyed()||e[C]?.writeInput(t)}function X(e){return!e.isDestroyed()&&(e[C]?.canReplaceData()??!1)}var E={columnDefs:{kind:"array",update:"columnDefs"},rowData:{kind:"array",update:"rowData"},defaultColDef:{kind:"object",update:"options"},columnTypes:{kind:"object",update:"options"},rowKey:{kind:"unknown",update:"options"},rowHeight:{kind:"number",update:"options"},headerHeight:{kind:"number",update:"options"},rowBuffer:{kind:"number",update:"options"},columnLayout:{kind:"string",update:"options"},enableColumnResize:{kind:"boolean",update:"options"},domLayout:{kind:"string",update:"options"},rowSelection:{kind:"string",update:"options"},multiSort:{kind:"boolean",update:"options"},size:{kind:"string",update:"options"},stripedRows:{kind:"boolean",update:"options"},rowStyleRules:{kind:"array",update:"options"},showCellBorders:{kind:"boolean",update:"options"},theme:{kind:"string",update:"options"},quickFilterText:{kind:"string",update:"quickFilter"},advancedFilterModel:{kind:"object",update:"options"},masterDetail:{kind:"boolean",update:"options"},detailRowHeight:{kind:"number",update:"options"},detailRowRenderer:{kind:"function",update:"options"},isRowExpandable:{kind:"function",update:"options"},detailToggleColumn:{kind:"boolean",update:"options"},columnMenu:{kind:"boolean",update:"options"},aggFuncs:{kind:"object",update:"options"},components:{kind:"object",update:"options"},actionPolicy:{kind:"object",update:"options"},features:{kind:"array",update:"options"},initialState:{kind:"object",update:"options"},persistence:{kind:"boolean-object",update:"options"},locale:{kind:"object",update:"options"},editType:{kind:"string",update:"options"},editableIndicator:{kind:"string",update:"options"},rowEditValidator:{kind:"function",update:"options"},singleClickEdit:{kind:"boolean",update:"options"},manualSorting:{kind:"boolean",update:"options"},manualFiltering:{kind:"boolean",update:"options"},showSummary:{kind:"boolean",update:"options"},summaryMethod:{kind:"function",update:"options"},treeData:{kind:"boolean",update:"options"},childrenKey:{kind:"string",update:"options"},isTreeRowExpandable:{kind:"function",update:"options"},loadTreeChildren:{kind:"function",update:"options"},autoCheckedChildren:{kind:"boolean",update:"options"},defaultExpandAll:{kind:"boolean",update:"options"},indexOffset:{kind:"number",update:"options"},applyRowDrag:{kind:"boolean",update:"options"},rowDragPolicy:{kind:"object",update:"options"},undoStackSize:{kind:"number",update:"options"},asyncTransactionWaitMillis:{kind:"number",update:"options"},getRowHeight:{kind:"function",update:"options"},pinnedTopRowData:{kind:"array",update:"options"},pinnedBottomRowData:{kind:"array",update:"options"},pagination:{kind:"boolean-object",update:"options"},watermark:{kind:"boolean-object",update:"options"},suppressWarnings:{kind:"boolean",update:"options"},enableRangeSelection:{kind:"boolean",update:"options"},suppressClipboard:{kind:"boolean",update:"options"},contextMenu:{kind:"boolean",update:"options"},getContextMenuItems:{kind:"function",update:"options"},tooltipComponent:{kind:"function",update:"options"},tooltipShowDelay:{kind:"number",update:"options"},flashCells:{kind:"boolean",update:"options"},fillHandle:{kind:"boolean",update:"options"},statusBar:{kind:"boolean-object",update:"options"},datasource:{kind:"object",update:"options"},datasourceMode:{kind:"string",update:"options"},blockSize:{kind:"number",update:"options"},infiniteBufferRows:{kind:"number",update:"options"},maxBlocksInCache:{kind:"number",update:"options"},datasourceMaxConcurrentRequests:{kind:"number",update:"options"},blockPrefetch:{kind:"number",update:"options"},datasourceRowCount:{kind:"number",update:"options"},dataProcessor:{kind:"object",update:"options"},dataProcessorMinRows:{kind:"number",update:"options"},datasourceRetryCount:{kind:"number",update:"options"},datasourceRetryDelay:{kind:"number",update:"options"},datasourceRetryJitter:{kind:"number",update:"options"},suppressCellFocus:{kind:"boolean",update:"options"},suppressRowHoverHighlight:{kind:"boolean",update:"options"},suppressNoRowsOverlay:{kind:"boolean",update:"options"},suppressHeaderFocus:{kind:"boolean",update:"options"},ariaLabel:{kind:"string",update:"options"},ariaLabelledBy:{kind:"string",update:"options"},ariaDescribedBy:{kind:"string",update:"options"},loading:{kind:"boolean",update:"options"},error:{kind:"unknown",update:"options"},overlayNoRowsTemplate:{kind:"unknown",update:"options"},overlayLoadingTemplate:{kind:"unknown",update:"options"},overlayErrorTemplate:{kind:"unknown",update:"options"},allowUnsafeOverlayHtml:{kind:"boolean",update:"options"},className:{kind:"string",update:"options"}},G=Object.freeze(Object.keys(E)),Re=Object.freeze(G.filter(e=>E[e].update==="options"));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],u=n[o];typeof a!="function"||typeof u!="function"||(e[o]=me(a,u))}}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 w(...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 ke=new Set(["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"]);function ee(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[a,u]of Object.entries(t)){if(!ke.has(a)){o[a]=u;continue}let r={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:a,layer:n,message:`[MachTable] "${a}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(r),e.strict!==!1)throw new TypeError(r.message)}return o}function L(e={}){let t=ee(e,e.defaults,"defaults");return{defaults:w({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,w(ee(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function te(e,t){let n=L({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[a,u]of Object.entries(n.presets))o[a]=w(e.presets[a]??{},u);return{defaults:w(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 ne(e,t,n,o){let a=t===void 0?e.defaultPreset:t,u=[{name:"application defaults",options:e.defaults}];for(let s of Te(a)){let m=e.presets[s];if(!m){let d={code:"UNKNOWN_PRESET",preset:s,message:`[MachTable] Unknown preset "${s}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}u.push({name:`preset:${s}`,options:m})}u.push({name:"table props",options:n});let r=w(...u.map(s=>s.options));return{options:r,explain(s){let m=u.filter(g=>Object.prototype.hasOwnProperty.call(g.options,s)).map(g=>({name:g.name,value:g.options[s]})),d=m[m.length-1];return{key:s,value:r[s],source:d?.name??"MachTable built-in",layers:m}}}}0&&(module.exports={GRID_OPTION_KEYS,GRID_OPTION_META,canReplaceGridData,createSelectControl,mergeMachTableConfig,normalizeMachTableConfig,readGridCell,resolveMachTableGridOptions,resumeGrid,suspendGrid,writeGridInput});
@@ -1,5 +1,18 @@
1
- import { G as GridOptions, b as GridEventType } from './options-Bi_m5kXL.cjs';
2
- export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-Bj_JwdTd.cjs';
1
+ import { b as GridApi, c as GridOptions, e as GridEventType } from './api-pOhyuSQk.cjs';
2
+ export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-gAE1eZuB.cjs';
3
+
4
+ interface GridInputCell {
5
+ rowId: string;
6
+ colId: string;
7
+ value: unknown;
8
+ }
9
+ /** Internal adapter contract; deactivation preserves row data and saved state. */
10
+ declare function suspendGrid(api: GridApi<any>): void;
11
+ declare function resumeGrid(api: GridApi<any>): void;
12
+ /** Optional features share Core's formatter and user-input validation boundary. */
13
+ declare function readGridCell(api: GridApi<any>, rowId: string, colId: string): string;
14
+ declare function writeGridInput(api: GridApi<any>, cells: readonly GridInputCell[]): void;
15
+ declare function canReplaceGridData(api: GridApi<any>): boolean;
3
16
 
4
17
  type EventOptionKey = `on${Capitalize<GridEventType>}`;
5
18
  type GridOptionKey = Exclude<keyof GridOptions<any>, EventOptionKey>;
@@ -206,6 +219,10 @@ declare const GRID_OPTION_META: {
206
219
  readonly kind: "boolean";
207
220
  readonly update: "options";
208
221
  };
222
+ readonly rowDragPolicy: {
223
+ readonly kind: "object";
224
+ readonly update: "options";
225
+ };
209
226
  readonly undoStackSize: {
210
227
  readonly kind: "number";
211
228
  readonly update: "options";
@@ -424,4 +441,4 @@ interface SelectControl {
424
441
  }
425
442
  declare function createSelectControl(config: SelectControlOptions): SelectControl;
426
443
 
427
- export { GRID_OPTION_KEYS, GRID_OPTION_META, type SelectControl, type SelectControlClassNames, type SelectControlOption, type SelectControlOptions, createSelectControl };
444
+ export { GRID_OPTION_KEYS, GRID_OPTION_META, type GridInputCell, type SelectControl, type SelectControlClassNames, type SelectControlOption, type SelectControlOptions, canReplaceGridData, createSelectControl, readGridCell, resumeGrid, suspendGrid, writeGridInput };
package/dist/adapter.d.ts CHANGED
@@ -1,5 +1,18 @@
1
- import { G as GridOptions, b as GridEventType } from './options-Bi_m5kXL.js';
2
- export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-C9KYeIy1.js';
1
+ import { b as GridApi, c as GridOptions, e as GridEventType } from './api-pOhyuSQk.js';
2
+ export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-SYWVjGft.js';
3
+
4
+ interface GridInputCell {
5
+ rowId: string;
6
+ colId: string;
7
+ value: unknown;
8
+ }
9
+ /** Internal adapter contract; deactivation preserves row data and saved state. */
10
+ declare function suspendGrid(api: GridApi<any>): void;
11
+ declare function resumeGrid(api: GridApi<any>): void;
12
+ /** Optional features share Core's formatter and user-input validation boundary. */
13
+ declare function readGridCell(api: GridApi<any>, rowId: string, colId: string): string;
14
+ declare function writeGridInput(api: GridApi<any>, cells: readonly GridInputCell[]): void;
15
+ declare function canReplaceGridData(api: GridApi<any>): boolean;
3
16
 
4
17
  type EventOptionKey = `on${Capitalize<GridEventType>}`;
5
18
  type GridOptionKey = Exclude<keyof GridOptions<any>, EventOptionKey>;
@@ -206,6 +219,10 @@ declare const GRID_OPTION_META: {
206
219
  readonly kind: "boolean";
207
220
  readonly update: "options";
208
221
  };
222
+ readonly rowDragPolicy: {
223
+ readonly kind: "object";
224
+ readonly update: "options";
225
+ };
209
226
  readonly undoStackSize: {
210
227
  readonly kind: "number";
211
228
  readonly update: "options";
@@ -424,4 +441,4 @@ interface SelectControl {
424
441
  }
425
442
  declare function createSelectControl(config: SelectControlOptions): SelectControl;
426
443
 
427
- export { GRID_OPTION_KEYS, GRID_OPTION_META, type SelectControl, type SelectControlClassNames, type SelectControlOption, type SelectControlOptions, createSelectControl };
444
+ export { GRID_OPTION_KEYS, GRID_OPTION_META, type GridInputCell, type SelectControl, type SelectControlClassNames, type SelectControlOption, type SelectControlOptions, canReplaceGridData, createSelectControl, readGridCell, resumeGrid, suspendGrid, writeGridInput };
package/dist/adapter.js CHANGED
@@ -1 +1 @@
1
- var S={columnDefs:{kind:"array",update:"columnDefs"},rowData:{kind:"array",update:"rowData"},defaultColDef:{kind:"object",update:"options"},columnTypes:{kind:"object",update:"options"},rowKey:{kind:"unknown",update:"options"},rowHeight:{kind:"number",update:"options"},headerHeight:{kind:"number",update:"options"},rowBuffer:{kind:"number",update:"options"},columnLayout:{kind:"string",update:"options"},enableColumnResize:{kind:"boolean",update:"options"},domLayout:{kind:"string",update:"options"},rowSelection:{kind:"string",update:"options"},multiSort:{kind:"boolean",update:"options"},size:{kind:"string",update:"options"},stripedRows:{kind:"boolean",update:"options"},rowStyleRules:{kind:"array",update:"options"},showCellBorders:{kind:"boolean",update:"options"},theme:{kind:"string",update:"options"},quickFilterText:{kind:"string",update:"quickFilter"},advancedFilterModel:{kind:"object",update:"options"},masterDetail:{kind:"boolean",update:"options"},detailRowHeight:{kind:"number",update:"options"},detailRowRenderer:{kind:"function",update:"options"},isRowExpandable:{kind:"function",update:"options"},detailToggleColumn:{kind:"boolean",update:"options"},columnMenu:{kind:"boolean",update:"options"},aggFuncs:{kind:"object",update:"options"},components:{kind:"object",update:"options"},actionPolicy:{kind:"object",update:"options"},features:{kind:"array",update:"options"},initialState:{kind:"object",update:"options"},persistence:{kind:"boolean-object",update:"options"},locale:{kind:"object",update:"options"},editType:{kind:"string",update:"options"},editableIndicator:{kind:"string",update:"options"},rowEditValidator:{kind:"function",update:"options"},singleClickEdit:{kind:"boolean",update:"options"},manualSorting:{kind:"boolean",update:"options"},manualFiltering:{kind:"boolean",update:"options"},showSummary:{kind:"boolean",update:"options"},summaryMethod:{kind:"function",update:"options"},treeData:{kind:"boolean",update:"options"},childrenKey:{kind:"string",update:"options"},isTreeRowExpandable:{kind:"function",update:"options"},loadTreeChildren:{kind:"function",update:"options"},autoCheckedChildren:{kind:"boolean",update:"options"},defaultExpandAll:{kind:"boolean",update:"options"},indexOffset:{kind:"number",update:"options"},applyRowDrag:{kind:"boolean",update:"options"},undoStackSize:{kind:"number",update:"options"},asyncTransactionWaitMillis:{kind:"number",update:"options"},getRowHeight:{kind:"function",update:"options"},pinnedTopRowData:{kind:"array",update:"options"},pinnedBottomRowData:{kind:"array",update:"options"},pagination:{kind:"boolean-object",update:"options"},watermark:{kind:"boolean-object",update:"options"},suppressWarnings:{kind:"boolean",update:"options"},enableRangeSelection:{kind:"boolean",update:"options"},suppressClipboard:{kind:"boolean",update:"options"},contextMenu:{kind:"boolean",update:"options"},getContextMenuItems:{kind:"function",update:"options"},tooltipComponent:{kind:"function",update:"options"},tooltipShowDelay:{kind:"number",update:"options"},flashCells:{kind:"boolean",update:"options"},fillHandle:{kind:"boolean",update:"options"},statusBar:{kind:"boolean-object",update:"options"},datasource:{kind:"object",update:"options"},datasourceMode:{kind:"string",update:"options"},blockSize:{kind:"number",update:"options"},infiniteBufferRows:{kind:"number",update:"options"},maxBlocksInCache:{kind:"number",update:"options"},datasourceMaxConcurrentRequests:{kind:"number",update:"options"},blockPrefetch:{kind:"number",update:"options"},datasourceRowCount:{kind:"number",update:"options"},dataProcessor:{kind:"object",update:"options"},dataProcessorMinRows:{kind:"number",update:"options"},datasourceRetryCount:{kind:"number",update:"options"},datasourceRetryDelay:{kind:"number",update:"options"},datasourceRetryJitter:{kind:"number",update:"options"},suppressCellFocus:{kind:"boolean",update:"options"},suppressRowHoverHighlight:{kind:"boolean",update:"options"},suppressNoRowsOverlay:{kind:"boolean",update:"options"},suppressHeaderFocus:{kind:"boolean",update:"options"},ariaLabel:{kind:"string",update:"options"},ariaLabelledBy:{kind:"string",update:"options"},ariaDescribedBy:{kind:"string",update:"options"},loading:{kind:"boolean",update:"options"},error:{kind:"unknown",update:"options"},overlayNoRowsTemplate:{kind:"unknown",update:"options"},overlayLoadingTemplate:{kind:"unknown",update:"options"},overlayErrorTemplate:{kind:"unknown",update:"options"},allowUnsafeOverlayHtml:{kind:"boolean",update:"options"},className:{kind:"string",update:"options"}},A=Object.freeze(Object.keys(S)),se=Object.freeze(A.filter(e=>S[e].update==="options"));function x(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function Y(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(i){o=i}try{t(...n)}catch(i){o??(o=i)}if(o!==void 0)throw o}}function q(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function J(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let i of o)n[i]={...e.columnTypes?.[i],...t.columnTypes?.[i]};return n}function Z(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let i=t[o],p=n[o];typeof i!="function"||typeof p!="function"||(e[o]=Y(i,p))}}function Q(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=q(e,t);o&&(n.components=o);let i=J(e,t);return i&&(n.columnTypes=i),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=x(e.pagination,t.pagination),n.statusBar=x(e.statusBar,t.statusBar),n.watermark=x(e.watermark,t.watermark),Z(n,e,t),n}function C(...e){return e.reduce(Q,{})}function X(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var ee=new Set(["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"]);function I(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[i,p]of Object.entries(t)){if(!ee.has(i)){o[i]=p;continue}let r={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:i,layer:n,message:`[MachTable] "${i}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(r),e.strict!==!1)throw new TypeError(r.message)}return o}function j(e={}){let t=I(e,e.defaults,"defaults");return{defaults:C({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,C(I(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function te(e,t){let n=j({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[i,p]of Object.entries(n.presets))o[i]=C(e.presets[i]??{},p);return{defaults:C(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 ne(e,t,n,o){let i=t===void 0?e.defaultPreset:t,p=[{name:"application defaults",options:e.defaults}];for(let s of X(i)){let f=e.presets[s];if(!f){let d={code:"UNKNOWN_PRESET",preset:s,message:`[MachTable] Unknown preset "${s}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}p.push({name:`preset:${s}`,options:f})}p.push({name:"table props",options:n});let r=C(...p.map(s=>s.options));return{options:r,explain(s){let f=p.filter(b=>Object.prototype.hasOwnProperty.call(b.options,s)).map(b=>({name:b.name,value:b.options[s]})),d=f[f.length-1];return{key:s,value:r[s],source:d?.name??"MachTable built-in",layers:f}}}}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let i of Object.keys(n))o.setAttribute(i,n[i]);return o}var oe=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function _(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o of oe){let i=n.getPropertyValue(o).trim();i&&e.style.setProperty(o,i)}e.style.colorScheme=n.colorScheme}function W(e,t,n){return e<t?t:e>n?n:e}var H=0;function B(e="rg"){return H++,`${e}-${H}`}var m=null;function z(e){let t=e.target;m?.contains(t)||m?.close()}function E(){m?.reposition()}function F(e){e.key!=="Escape"||!m||(e.preventDefault(),e.stopImmediatePropagation(),m.close(!0))}function ae(e){m?.close!==e.close&&m?.close(),!m&&(m=e,document.addEventListener("mousedown",z,!0),document.addEventListener("keydown",F,!0),window.addEventListener("resize",E),window.addEventListener("scroll",E,!0))}function ie(e){m?.close===e&&(m=null,document.removeEventListener("mousedown",z,!0),document.removeEventListener("keydown",F,!0),window.removeEventListener("resize",E),window.removeEventListener("scroll",E,!0))}function k(e,t){return t?`${e} ${t}`:e}function D(e){let t=[];return e.forEach((n,o)=>{n.disabled||t.push(o)}),t}function K(e,t,n){let o=D(e);if(o.length===0)return-1;let i=o.indexOf(t);return i<0?n>0?o[0]:o[o.length-1]:o[Math.max(0,Math.min(o.length-1,i+n))]}function M(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function re(e){let t=y("div",k("mach-select-control",e.classNames?.root)),n=y("select",k("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",k("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 i=y("span",k("mach-select-value",e.classNames?.value)),p=y("span",k("mach-select-caret",e.classNames?.caret));p.setAttribute("aria-hidden","true"),o.append(i,p);let r=y("div",k("mach-select-listbox",e.classNames?.listbox));r.id=B("mach-select-listbox"),r.setAttribute("role","listbox"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",r.id),t.append(n,o);let s=[...e.options],f=[],d=-1,b=!1,V=()=>e.themeSource??t.closest(".mach-root")??t,v=()=>{let a=s.find(l=>l.value===n.value);i.textContent=a?.label??n.value,f.forEach((l,g)=>{let c=s[g]?.value===n.value;l.setAttribute("aria-selected",c?"true":"false"),l.classList.toggle("mach-select-option--selected",c),l.classList.toggle("mach-select-option--active",g===d)}),o.setAttribute("aria-activedescendant",d>=0?f[d]?.id??"":"")},R=()=>{let a=o.getBoundingClientRect(),l=r.getBoundingClientRect(),g=Math.max(a.width,l.width),c=W(a.left,8,Math.max(8,window.innerWidth-g-8)),w=window.innerHeight-a.bottom-8,T=w<Math.min(l.height,240)&&a.top>w,u=T?Math.max(8,a.top-l.height-5):Math.min(window.innerHeight-l.height-8,a.bottom+5);r.style.minWidth=`${a.width}px`,r.style.left=`${c}px`,r.style.top=`${Math.max(8,u)}px`,r.classList.toggle("mach-select-listbox--above",T)},h=(a=!1)=>r.classList.contains("mach-select-listbox--open")?(r.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),r.remove(),ie(h),a&&!b&&o.focus({preventScroll:!0}),!0):!1,$=(a,l=!0)=>{!s[a]||s[a].disabled||(d=a,v(),l&&f[a]?.scrollIntoView?.({block:"nearest"}))},O=()=>{b||o.disabled||r.classList.contains("mach-select-listbox--open")||(ae({close:h,contains:a=>t.contains(a)||r.contains(a),reposition:R}),d=M(s,n.value),d<0&&(d=D(s)[0]??-1),_(r,V()),document.body.appendChild(r),r.classList.add("mach-select-listbox--open"),r.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),R(),v(),f[d]?.scrollIntoView?.({block:"nearest"}))},P=a=>{let l=s[a];!l||l.disabled||(n.value=l.value,d=a,v(),h(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},L=(a,l)=>{s=[...a],n.replaceChildren(),r.replaceChildren(),f=s.map((c,w)=>{let T=document.createElement("option");T.value=c.value,T.textContent=c.label,T.disabled=c.disabled===!0,n.appendChild(T);let u=y("button",k("mach-select-option",e.classNames?.option));return u.id=`${r.id}-option-${w}`,u.type="button",u.tabIndex=-1,u.dataset.value=c.value,u.disabled=c.disabled===!0,u.setAttribute("role","option"),u.textContent=c.label,u.addEventListener("mousedown",U=>U.preventDefault()),u.addEventListener("click",()=>P(w)),r.appendChild(u),u});let g=s.find(c=>!c.disabled)?.value??"";n.value=l!=null&&s.some(c=>c.value===l)?l:g,d=M(s,n.value),v()},G=a=>{if(a.key==="Tab"){h();return}if(a.key==="Escape"){if(!h(!0))return;a.preventDefault(),a.stopPropagation();return}if(a.key==="Enter"||a.key===" "){a.preventDefault(),a.stopPropagation(),r.classList.contains("mach-select-listbox--open")?P(d):O();return}let l=d;if(a.key==="ArrowDown")l=K(s,d,1);else if(a.key==="ArrowUp")l=K(s,d,-1);else if(a.key==="Home")l=D(s)[0]??-1;else if(a.key==="End"){let g=D(s);l=g[g.length-1]??-1}else return;a.preventDefault(),a.stopPropagation(),r.classList.contains("mach-select-listbox--open")||O(),$(l)},N=()=>{d=M(s,n.value),v(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{h()||O()}),o.addEventListener("keydown",G),n.addEventListener("change",N),L(s,e.value),{el:t,native:n,trigger:o,listbox:r,contains:a=>t.contains(a)||r.contains(a),isOpen:()=>r.classList.contains("mach-select-listbox--open"),open:O,close:h,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:a=>{n.value=a,d=M(s,a),v()},setOptions:L,destroy:()=>{b||(b=!0,h(),o.removeEventListener("keydown",G),n.removeEventListener("change",N),t.remove())}}}export{A as GRID_OPTION_KEYS,S as GRID_OPTION_META,re as createSelectControl,te as mergeMachTableConfig,j as normalizeMachTableConfig,ne as resolveMachTableGridOptions};
1
+ 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}var J=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function H(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o of J){let a=n.getPropertyValue(o).trim();a&&e.style.setProperty(o,a)}e.style.colorScheme=n.colorScheme}function _(e,t,n){return e<t?t:e>n?n:e}var j=0;function F(e="rg"){return j++,`${e}-${j}`}var p=null;function B(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function K(e){let t=e.target;p?.contains(t)||p?.close()}function R(){p?.reposition()}function z(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function Z(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",K,!0),document.addEventListener("keydown",z,!0),window.addEventListener("resize",R),window.addEventListener("scroll",R,!0))}function Q(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",K,!0),document.removeEventListener("keydown",z,!0),window.removeEventListener("resize",R),window.removeEventListener("scroll",R,!0))}function k(e,t){return t?`${e} ${t}`:e}function x(e){let t=[];return e.forEach((n,o)=>{n.disabled||t.push(o)}),t}function W(e,t,n){let o=x(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 M(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function X(e){let t=h("div",k("mach-select-control",e.classNames?.root)),n=h("select",k("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=h("button",k("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",k("mach-select-value",e.classNames?.value)),u=h("span",k("mach-select-caret",e.classNames?.caret));u.setAttribute("aria-hidden","true"),o.append(a,u);let r=h("div",k("mach-select-listbox",e.classNames?.listbox));r.id=F("mach-select-listbox"),r.setAttribute("role","listbox"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",r.id),t.append(n,o);let s=[...e.options],m=[],d=-1,g=!1,G=()=>e.themeSource??t.closest(".mach-root")??t,v=()=>{let i=s.find(l=>l.value===n.value);a.textContent=i?.label??n.value,m.forEach((l,b)=>{let c=s[b]?.value===n.value;l.setAttribute("aria-selected",c?"true":"false"),l.classList.toggle("mach-select-option--selected",c),l.classList.toggle("mach-select-option--active",b===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},A=()=>{let i=o.getBoundingClientRect(),l=r.getBoundingClientRect(),b=Math.max(i.width,l.width),c=_(i.left,8,Math.max(8,window.innerWidth-b-8)),D=window.innerHeight-i.bottom-8,T=D<Math.min(l.height,240)&&i.top>D,f=T?Math.max(8,i.top-l.height-5):Math.min(window.innerHeight-l.height-8,i.bottom+5);r.style.minWidth=`${i.width}px`,r.style.left=`${c}px`,r.style.top=`${Math.max(8,f)}px`,r.classList.toggle("mach-select-listbox--above",T)},y=(i=!1)=>r.classList.contains("mach-select-listbox--open")?(r.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),r.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),r.remove(),Q(y),i&&!g&&o.focus({preventScroll:!0}),!0):!1,Y=(i,l=!0)=>{!s[i]||s[i].disabled||(d=i,v(),l&&m[i]?.scrollIntoView?.({block:"nearest"}))},O=()=>{g||o.disabled||r.classList.contains("mach-select-listbox--open")||(Z({owner:G(),close:y,contains:i=>t.contains(i)||r.contains(i),reposition:A}),d=M(s,n.value),d<0&&(d=x(s)[0]??-1),H(r,G()),document.body.appendChild(r),r.classList.add("mach-select-listbox--open"),r.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),A(),v(),m[d]?.scrollIntoView?.({block:"nearest"}))},L=i=>{let l=s[i];!l||l.disabled||(n.value=l.value,d=i,v(),y(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},P=(i,l)=>{s=[...i],n.replaceChildren(),r.replaceChildren(),m=s.map((c,D)=>{let T=document.createElement("option");T.value=c.value,T.textContent=c.label,T.disabled=c.disabled===!0,n.appendChild(T);let f=h("button",k("mach-select-option",e.classNames?.option));return f.id=`${r.id}-option-${D}`,f.type="button",f.tabIndex=-1,f.dataset.value=c.value,f.disabled=c.disabled===!0,f.setAttribute("role","option"),f.textContent=c.label,f.addEventListener("mousedown",q=>q.preventDefault()),f.addEventListener("click",()=>L(D)),r.appendChild(f),f});let b=s.find(c=>!c.disabled)?.value??"";n.value=l!=null&&s.some(c=>c.value===l)?l:b,d=M(s,n.value),v()},I=i=>{if(i.key==="Tab"){y();return}if(i.key==="Escape"){if(!y(!0))return;i.preventDefault(),i.stopPropagation();return}if(i.key==="Enter"||i.key===" "){i.preventDefault(),i.stopPropagation(),r.classList.contains("mach-select-listbox--open")?L(d):O();return}let l=d;if(i.key==="ArrowDown")l=W(s,d,1);else if(i.key==="ArrowUp")l=W(s,d,-1);else if(i.key==="Home")l=x(s)[0]??-1;else if(i.key==="End"){let b=x(s);l=b[b.length-1]??-1}else return;i.preventDefault(),i.stopPropagation(),r.classList.contains("mach-select-listbox--open")||O(),Y(l)},N=()=>{d=M(s,n.value),v(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{y()||O()}),o.addEventListener("keydown",I),n.addEventListener("change",N),P(s,e.value),{el:t,native:n,trigger:o,listbox:r,contains:i=>t.contains(i)||r.contains(i),isOpen:()=>r.classList.contains("mach-select-listbox--open"),open:O,close:y,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:i=>{n.value=i,d=M(s,i),v()},setOptions:P,destroy:()=>{g||(g=!0,y(),o.removeEventListener("keydown",I),n.removeEventListener("change",N),t.remove())}}}var C=Symbol.for("mach-table.adapter.lifecycle.v1");function ee(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&B(t),e[C]?.suspend()}function te(e){e.isDestroyed()||e[C]?.resume()}function ne(e,t,n){return e.isDestroyed()?"":e[C]?.readCell(t,n)??""}function oe(e,t){e.isDestroyed()||e[C]?.writeInput(t)}function ie(e){return!e.isDestroyed()&&(e[C]?.canReplaceData()??!1)}var E={columnDefs:{kind:"array",update:"columnDefs"},rowData:{kind:"array",update:"rowData"},defaultColDef:{kind:"object",update:"options"},columnTypes:{kind:"object",update:"options"},rowKey:{kind:"unknown",update:"options"},rowHeight:{kind:"number",update:"options"},headerHeight:{kind:"number",update:"options"},rowBuffer:{kind:"number",update:"options"},columnLayout:{kind:"string",update:"options"},enableColumnResize:{kind:"boolean",update:"options"},domLayout:{kind:"string",update:"options"},rowSelection:{kind:"string",update:"options"},multiSort:{kind:"boolean",update:"options"},size:{kind:"string",update:"options"},stripedRows:{kind:"boolean",update:"options"},rowStyleRules:{kind:"array",update:"options"},showCellBorders:{kind:"boolean",update:"options"},theme:{kind:"string",update:"options"},quickFilterText:{kind:"string",update:"quickFilter"},advancedFilterModel:{kind:"object",update:"options"},masterDetail:{kind:"boolean",update:"options"},detailRowHeight:{kind:"number",update:"options"},detailRowRenderer:{kind:"function",update:"options"},isRowExpandable:{kind:"function",update:"options"},detailToggleColumn:{kind:"boolean",update:"options"},columnMenu:{kind:"boolean",update:"options"},aggFuncs:{kind:"object",update:"options"},components:{kind:"object",update:"options"},actionPolicy:{kind:"object",update:"options"},features:{kind:"array",update:"options"},initialState:{kind:"object",update:"options"},persistence:{kind:"boolean-object",update:"options"},locale:{kind:"object",update:"options"},editType:{kind:"string",update:"options"},editableIndicator:{kind:"string",update:"options"},rowEditValidator:{kind:"function",update:"options"},singleClickEdit:{kind:"boolean",update:"options"},manualSorting:{kind:"boolean",update:"options"},manualFiltering:{kind:"boolean",update:"options"},showSummary:{kind:"boolean",update:"options"},summaryMethod:{kind:"function",update:"options"},treeData:{kind:"boolean",update:"options"},childrenKey:{kind:"string",update:"options"},isTreeRowExpandable:{kind:"function",update:"options"},loadTreeChildren:{kind:"function",update:"options"},autoCheckedChildren:{kind:"boolean",update:"options"},defaultExpandAll:{kind:"boolean",update:"options"},indexOffset:{kind:"number",update:"options"},applyRowDrag:{kind:"boolean",update:"options"},rowDragPolicy:{kind:"object",update:"options"},undoStackSize:{kind:"number",update:"options"},asyncTransactionWaitMillis:{kind:"number",update:"options"},getRowHeight:{kind:"function",update:"options"},pinnedTopRowData:{kind:"array",update:"options"},pinnedBottomRowData:{kind:"array",update:"options"},pagination:{kind:"boolean-object",update:"options"},watermark:{kind:"boolean-object",update:"options"},suppressWarnings:{kind:"boolean",update:"options"},enableRangeSelection:{kind:"boolean",update:"options"},suppressClipboard:{kind:"boolean",update:"options"},contextMenu:{kind:"boolean",update:"options"},getContextMenuItems:{kind:"function",update:"options"},tooltipComponent:{kind:"function",update:"options"},tooltipShowDelay:{kind:"number",update:"options"},flashCells:{kind:"boolean",update:"options"},fillHandle:{kind:"boolean",update:"options"},statusBar:{kind:"boolean-object",update:"options"},datasource:{kind:"object",update:"options"},datasourceMode:{kind:"string",update:"options"},blockSize:{kind:"number",update:"options"},infiniteBufferRows:{kind:"number",update:"options"},maxBlocksInCache:{kind:"number",update:"options"},datasourceMaxConcurrentRequests:{kind:"number",update:"options"},blockPrefetch:{kind:"number",update:"options"},datasourceRowCount:{kind:"number",update:"options"},dataProcessor:{kind:"object",update:"options"},dataProcessorMinRows:{kind:"number",update:"options"},datasourceRetryCount:{kind:"number",update:"options"},datasourceRetryDelay:{kind:"number",update:"options"},datasourceRetryJitter:{kind:"number",update:"options"},suppressCellFocus:{kind:"boolean",update:"options"},suppressRowHoverHighlight:{kind:"boolean",update:"options"},suppressNoRowsOverlay:{kind:"boolean",update:"options"},suppressHeaderFocus:{kind:"boolean",update:"options"},ariaLabel:{kind:"string",update:"options"},ariaLabelledBy:{kind:"string",update:"options"},ariaDescribedBy:{kind:"string",update:"options"},loading:{kind:"boolean",update:"options"},error:{kind:"unknown",update:"options"},overlayNoRowsTemplate:{kind:"unknown",update:"options"},overlayLoadingTemplate:{kind:"unknown",update:"options"},overlayErrorTemplate:{kind:"unknown",update:"options"},allowUnsafeOverlayHtml:{kind:"boolean",update:"options"},className:{kind:"string",update:"options"}},V=Object.freeze(Object.keys(E)),Te=Object.freeze(V.filter(e=>E[e].update==="options"));function S(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function ae(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 re(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function se(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 le(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],u=n[o];typeof a!="function"||typeof u!="function"||(e[o]=ae(a,u))}}function de(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=re(e,t);o&&(n.components=o);let a=se(e,t);return a&&(n.columnTypes=a),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=S(e.pagination,t.pagination),n.statusBar=S(e.statusBar,t.statusBar),n.watermark=S(e.watermark,t.watermark),le(n,e,t),n}function w(...e){return e.reduce(de,{})}function ce(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var pe=new Set(["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"]);function $(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[a,u]of Object.entries(t)){if(!pe.has(a)){o[a]=u;continue}let r={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:a,layer:n,message:`[MachTable] "${a}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(r),e.strict!==!1)throw new TypeError(r.message)}return o}function U(e={}){let t=$(e,e.defaults,"defaults");return{defaults:w({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,w($(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function ue(e,t){let n=U({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[a,u]of Object.entries(n.presets))o[a]=w(e.presets[a]??{},u);return{defaults:w(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 fe(e,t,n,o){let a=t===void 0?e.defaultPreset:t,u=[{name:"application defaults",options:e.defaults}];for(let s of ce(a)){let m=e.presets[s];if(!m){let d={code:"UNKNOWN_PRESET",preset:s,message:`[MachTable] Unknown preset "${s}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}u.push({name:`preset:${s}`,options:m})}u.push({name:"table props",options:n});let r=w(...u.map(s=>s.options));return{options:r,explain(s){let m=u.filter(g=>Object.prototype.hasOwnProperty.call(g.options,s)).map(g=>({name:g.name,value:g.options[s]})),d=m[m.length-1];return{key:s,value:r[s],source:d?.name??"MachTable built-in",layers:m}}}}export{V as GRID_OPTION_KEYS,E as GRID_OPTION_META,ie as canReplaceGridData,X as createSelectControl,ue as mergeMachTableConfig,U as normalizeMachTableConfig,ne as readGridCell,fe as resolveMachTableGridOptions,te as resumeGrid,ee as suspendGrid,oe as writeGridInput};
@@ -0,0 +1,3 @@
1
+ "use strict";var R=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(n,e)=>{for(var t in e)R(n,t,{get:e[t],enumerable:!0})},re=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ee(e))!te.call(n,i)&&i!==t&&R(n,i,{get:()=>e[i],enumerable:!(r=Q(e,i))||r.enumerable});return n};var ie=n=>re(R({},"__esModule",{value:!0}),n);var we={};ne(we,{createPivot:()=>C,evaluateFormulas:()=>N,mountAnalysis:()=>Z});module.exports=ie(we);var oe=new Set(["__proto__","prototype","constructor"]);function E(n){return typeof n!="string"||n.length===0?!1:n.split(".").every(t=>t.length>0&&!oe.has(t))}function x(n,e){if(n==null||!E(e))return;if(e.indexOf(".")<0)return n[e];let r=n,i=0;for(;i<e.length;){if(r==null)return;let o=e.indexOf(".",i);if(o<0){r=r[e.slice(i)];break}r=r[e.slice(i,o)],i=o+1}return r}var se=new Set(["sum","count","avg","min","max"]);function z(n){return JSON.stringify(n.map(e=>[e===null?"null":typeof e,e]))}function j(n){if(n==null)return null;if(typeof n=="number")return Number.isFinite(n)?n:null;if(typeof n=="string"||typeof n=="boolean")return n;if(n instanceof Date&&!Number.isNaN(n.getTime()))return n.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function ae(n,e){if(n.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let t=[...e.rowFields,...e.columnFields??[]];if(t.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let i of t)if(!E(i))throw new TypeError(`Invalid pivot field: ${i}`);let r=new Set;for(let i of e.values){le(i);let o=JSON.stringify([i.field??null,i.aggregate]);if(r.has(o))throw new TypeError("Duplicate pivot measure");r.add(o)}}function le(n){if(!se.has(n.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(n.aggregate)}`);if(n.field!=null&&!E(n.field))throw new TypeError(`Invalid pivot field: ${n.field}`);if(!n.field&&n.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function G(n,e,t){let r=n.get(e);r||(r={count:0,numeric:0,sum:0,min:1/0,max:-1/0},n.set(e,r)),r.count++,!(typeof t!="number"||!Number.isFinite(t))&&(r.numeric++,r.sum+=t,r.min=Math.min(r.min,t),r.max=Math.max(r.max,t))}function ue(n,e){return e==="count"?n?.count??0:n?.numeric?e==="avg"?Number.isFinite(n.sum)?n.sum/n.numeric:null:e==="sum"?Number.isFinite(n.sum)?n.sum:null:e==="min"?n.min:n.max:null}function ce(n,e){return JSON.stringify([n===null?"total":z(n),e.field??null,e.aggregate])}function C(n,e){ae(n,e);let t=new Map,r=new Map,i=new Map,o=e.columnFields??[];for(let s of n){let u=e.rowFields.map(p=>j(x(s,p))),m=z(u),d=t.get(m);if(d||(d={dimensions:u,cells:new Map},t.set(m,d)),t.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=o.map(p=>j(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;U(d,r,i,h,p,g),o.length&&U(d,r,i,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!n.length&&!o.length)for(let s of e.values)W(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...t.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:V(a,u.cells)}));return{columns:a,rows:l,totals:V(a,i),inputCount:n.length}}function W(n,e,t){let r=ce(e,t);if(!n.has(r)){let i=t.label??`${t.field??"\u8BB0\u5F55"} \xB7 ${t.aggregate}`,o=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");n.set(r,{id:r,label:o?`${o} / ${i}`:i,dimensions:e??[],total:e===null,measure:{...t}})}return r}function U(n,e,t,r,i,o){let a=W(e,r,i);G(n.cells,a,o),G(t,a,o)}function V(n,e){let t=Object.create(null);for(let r of n)t[r.id]=ue(e.get(r.id),r.measure.aggregate);return t}var f=class extends Error{constructor(t,r){super(r);this.code=t}},B={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},de=new Set(["SUM","MIN","MAX","AVG"]);function fe(n){if(n.length>4096)throw new f("LIMIT","Formula exceeds 4096 characters");let e=[],t=n.startsWith("=")?1:0;for(;t<n.length;){if(/\s/.test(n[t])){t++;continue}let r=me(n.slice(t));if(e.push(r),t+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new f("LIMIT","Formula exceeds 256 tokens")}return e}function me(n){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(n);if(e)return{kind:"number",value:e[0]};let t=/^\[([^\]\r\n]+)\]/.exec(n);if(t)return{kind:"field",value:t[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(n);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(n[0]))return{kind:"symbol",value:n[0]};throw new f("SYNTAX",`Unexpected token: ${n.slice(0,12)}`)}function X(n){let e=fe(n),t=0,r=s=>{if(e[t++]?.value!==s)throw new f("SYNTAX",`Expected ${s}`)},i=(s,u)=>{if(u>32)throw new f("LIMIT","Formula exceeds 32 nesting levels");let m=a(u);for(;t<e.length;){let d=e[t].value,h=Object.prototype.hasOwnProperty.call(B,d)?B[d]:void 0;if(h==null||h<s)break;t++;let p=i(h+(d==="^"?0:1),u+1);m={kind:"binary",operator:d,left:m,right:p}}return m},o=(s,u)=>{let m=s.toUpperCase();if(!de.has(m))throw new f("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[t]?.value!==")")do d.push(i(0,u+1));while(e[t]?.value===","&&++t);if(r(")"),!d.length&&m!=="SUM")throw new f("SYNTAX",`${m} requires arguments`);return{kind:"call",name:m,args:d}},a=s=>{let u=e[t++];if(!u)throw new f("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[t]?.value==="("?o(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:i(3,s+1)};if(u.value==="("){let m=i(0,s+1);return r(")"),m}throw new f("SYNTAX",`Unexpected token: ${u.value}`)},l=i(0,0);if(t!==e.length)throw new f("SYNTAX","Unexpected trailing tokens");return l}function k(n){if(!Number.isFinite(n))throw new f("NON_FINITE","Formula result is not a finite number");return n}function pe(n,e,t){if((n==="/"||n==="%")&&t===0)throw new f("DIV_ZERO","Division by zero");return n==="+"?e+t:n==="-"?e-t:n==="*"?e*t:n==="/"?e/t:n==="%"?e%t:e**t}function T(n,e){if(n.kind==="number")return k(n.value);if(n.kind==="field")return e(n.name);if(n.kind==="unary")return k((n.operator==="-"?-1:1)*T(n.operand,e));if(n.kind==="binary")return k(pe(n.operator,T(n.left,e),T(n.right,e)));let t=n.args.map(i=>T(i,e));if(n.name==="MIN")return Math.min(...t);if(n.name==="MAX")return Math.max(...t);let r=t.reduce((i,o)=>i+o,0);return k(n.name==="AVG"?r/t.length:r)}function N(n,e){let t=Object.entries(e);if(t.length>32||n.length>1e4||t.length*n.length>1e5)throw new f("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of t){if(!E(a)||/[.\[\]]/.test(a))throw new f("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,X(l))}catch(s){r.set(a,Y(s))}}let i=[];return{rows:n.map((a,l)=>{let s={...a},u=ge(a,r);for(let[m,d]of u)d instanceof f&&i.push({rowIndex:l,colId:m,code:d.code,message:d.message}),Object.defineProperty(s,m,{value:d instanceof f?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:i}}function Y(n){return n instanceof f?n:new f("SYNTAX",n instanceof Error?n.message:String(n))}function he(n,e){if(!E(e))throw new f("UNKNOWN_FIELD",`Unknown field: ${e}`);let t=x(n,e);if(t===void 0)throw new f("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof t!="number")throw new f("NON_NUMERIC",`Field is not numeric: ${e}`);return k(t)}function ge(n,e){let t=new Map,r=new Set,i=o=>{if(!e.has(o))return he(n,o);let a=t.get(o);if(a instanceof f)throw a;if(a!=null)return a;if(r.has(o))throw new f("CYCLE",`Cyclic formula: ${[...r,o].join(" \u2192 ")}`);r.add(o);try{let l=e.get(o);if(l instanceof f)throw l;let s=k(T(l,i));return t.set(o,s),s}catch(l){let s=Y(l);throw t.set(o,s),s}finally{r.delete(o)}};for(let o of e.keys())try{i(o)}catch{}return t}var ve=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function K(n,e){if(n.classList.add("mach-portal"),!e)return;let t=window.getComputedStyle(e);for(let r of ve){let i=t.getPropertyValue(r).trim();i&&n.style.setProperty(r,i)}n.style.colorScheme=t.colorScheme}function c(n,e,t){let r=document.createElement(n);return e&&(r.className=e),t!=null&&(r.textContent=t),r}function y(n,e,t=""){let r=c("button",`mach-workbench__button ${t}`.trim(),n);return r.type="button",r.addEventListener("click",e),r}function P(n,e,t,r){let i=c("select","mach-workbench__input");i.setAttribute("aria-label",n);for(let o of e){let a=c("option",void 0,o.label);a.value=o.value,i.append(a)}return i.value=t,i.addEventListener("change",()=>r(i.value)),i}function _(n,e){let t=[...n.querySelectorAll("button,select,input")].filter(i=>!i.disabled);(t.find(i=>i.getAttribute("aria-label")===e||i.textContent===e)??t[0])?.focus()}function q(n,e,t,r){let i=document.activeElement,o=c("section","mach-workbench");o.setAttribute("aria-label",e),o.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),y("\u5173\u95ED",t));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");o.append(a,l,s,u);let m=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),t())};o.addEventListener("keydown",m);let d=!1,h=r.view.getRoot(),p=()=>{d||(o.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",K(o,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),n.append(o)}catch(v){throw g?.disconnect(),o.remove(),v}return{root:o,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=o.contains(document.activeElement);o.removeEventListener("keydown",m),o.remove(),v&&i?.isConnected&&i.focus()}}}function w(n,e,t){let r=document.createElementNS("http://www.w3.org/2000/svg",n);for(let[i,o]of Object.entries(e))r.setAttribute(i,String(o));return t!=null&&(r.textContent=t),r}function J(n,e,t){let r=c("figure","mach-analysis__chart"),i=n.columns.find(b=>b.id===e);if(!i)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let o=n.rows.slice(0,40),a=`${i.label} \xB7 ${t==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${o.length} \u7EC4`,l=w("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(w("title",{},a));let s=o.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),m=Math.max(0,...s),d=Math.max(Math.abs(m),Math.abs(u))||1,h=m/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(w("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(w("text",{x:2,y:25,"font-size":11},String(m)),w("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(o.length,1),M=[],O=()=>{M.length&&l.append(w("polyline",{points:M.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),M=[]};return o.forEach((b,L)=>{let S=b.values[e];if(S==null){O();return}let F=55+v*(L+.5),A=p(S),I=b.dimensions.map(H=>H==null?"\u7A7A\u503C":String(H)).join(" / ")||"\u5168\u90E8",$=t==="bar"?w("rect",{x:F-v*.35,y:Math.min(g,A),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(A-g)),fill:"currentColor",rx:2}):w("circle",{cx:F,cy:A,r:3,fill:"currentColor"});$.append(w("title",{},`${I}: ${S}`)),l.append($),t==="line"&&M.push(`${F},${A}`),(o.length<=10||L%Math.ceil(o.length/10)===0)&&l.append(w("text",{x:F,y:238,"text-anchor":"middle","font-size":10},I.slice(0,12)))}),O(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${n.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 be={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function Z(n,e){return new D(n,e)}var D=class{constructor(e,t){this.options=t;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.i="bar";this.t="";this.destroyed=!1;if(t.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...t.pivot?.rowFields??[]],columnFields:[...t.pivot?.columnFields??[]],values:t.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(t.formulas??{}).map(([r,i])=>({field:r,expression:i})),this.e=q(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),t.onClose?.()},t.api),this.e.footer.append(y("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.o=[t.api.on("gridDestroyed",()=>this.destroy()),t.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.o.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],t=r=>{for(let i of r){if("children"in i){t(i.children);continue}if(!i.field)continue;let o=x(this.options.api.rows.getAt(0)?.data,i.field);e.push({field:i.field,label:i.headerName??i.field,numeric:typeof o=="number"||i.cellEditor==="number"||i.filter==="number"})}};t(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(i=>i.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,i=>{this.config.rowFields=i}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],i=>{this.config.columnFields=i}));let t=c("fieldset","mach-workbench__group");t.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((i,o)=>t.append(this.measure(i,o)));let r=y("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,t.append(r),e.append(t,this.d()),this.e.body.append(e)}dimensions(e,t,r){let i=c("label","mach-analysis__dimension",e),o=c("select","mach-workbench__input");o.multiple=!0,o.setAttribute("aria-label",e);let a=[...this.fields];for(let l of t)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=t.includes(l.field),o.append(s)}return o.addEventListener("change",()=>r([...o.selectedOptions].map(l=>l.value))),i.append(o,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),i}measure(e,t){let r=c("div","mach-workbench__values"),i=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(o=>({value:o.field,label:o.label}))];return e.field&&!i.some(o=>o.value===e.field)&&i.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(P("\u6307\u6807\u5B57\u6BB5",i,e.field??"",o=>{e.field=o||void 0}),P("\u805A\u5408\u65B9\u5F0F",Object.entries(be).map(([o,a])=>({value:o,label:a})),e.aggregate,o=>{e.aggregate=o}),y("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((o,a)=>a!==t),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,i)=>{let o=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}),o.append(a,l,y("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(i,1),this.refresh()})),e.append(o)});let t=y("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return t.disabled=this.formulas.length>=32,e.append(t),e}s(){if(!this.a())return;let e=[],t=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(t++,e.length<1e4&&e.push(r.data))});try{let r=this.f(),i=N(e,r);if(i.errors.length){let l=i.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 ${i.errors.length} \u9879${i.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
2
+ ${l.join(`
3
+ `)}`)}this.m(r),this.result=C(i.rows,this.config),this.page=0,this.refresh();let o=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=t>e.length?`\u5DF2\u52A0\u8F7D ${t} \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}${o} \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")}}f(){let e=Object.create(null);for(let t of this.formulas){if(!t.field||Object.prototype.hasOwnProperty.call(e,t.field))throw new Error("\u516C\u5F0F\u7ED3\u679C\u5217\u4E0D\u80FD\u4E3A\u7A7A\u6216\u91CD\u590D");e[t.field]=t.expression}return e}m(e){let t=new Set([...this.l().map(i=>i.field),...Object.keys(e)]),r=[...this.config.rowFields,...this.config.columnFields??[],...this.config.values.flatMap(i=>i.field?[i.field]:[])];for(let i of r)if(!t.has(i))throw new Error(`\u5B57\u6BB5\u5DF2\u79FB\u9664\u6216\u4E0D\u53EF\u5206\u6790\uFF1A${i}`)}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 t=c("div","mach-workbench__tools");t.append(P("\u56FE\u8868\u7C7B\u578B",[{value:"bar",label:"\u67F1\u72B6\u56FE"},{value:"line",label:"\u6298\u7EBF\u56FE"}],this.i,l=>{this.i=l,this.n(),_(this.results,"\u56FE\u8868\u7C7B\u578B")}),P("\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(t,J(e,this.t,this.i),this.table(e));let r=Math.max(1,Math.ceil(e.rows.length/50)),i=c("nav","mach-workbench__tools");i.setAttribute("aria-label","\u5206\u6790\u7ED3\u679C\u5206\u9875");let o=y("\u4E0A\u4E00\u9875",()=>{this.page--,this.n(),_(this.results.querySelector("nav"),"\u4E0A\u4E00\u9875")}),a=y("\u4E0B\u4E00\u9875",()=>{this.page++,this.n(),_(this.results.querySelector("nav"),"\u4E0B\u4E00\u9875")});o.disabled=this.page<=0,a.disabled=this.page>=r-1,i.append(o,c("span",void 0,`\u7B2C ${this.page+1} / ${r} \u9875 \xB7 \u6BCF\u9875 50 \u7EC4`),a),this.results.append(i)}table(e){let t=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 i=c("thead"),o=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",o.append(u)}i.append(o);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(i,a,l),t.append(r),t}u(e,t,r){let i=c("tr"),o=c("th",void 0,e);o.scope="row",i.append(o);for(let a of t.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),i.append(s)}return i}};0&&(module.exports={createPivot,evaluateFormulas,mountAnalysis});
@@ -0,0 +1,60 @@
1
+ import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-Bi8hAuzn.cjs';
2
+ import './api-pOhyuSQk.cjs';
3
+
4
+ type PivotAggregate = "sum" | "count" | "avg" | "min" | "max";
5
+ type PivotDimension = string | number | boolean | null;
6
+ interface PivotValue {
7
+ field?: string;
8
+ aggregate: PivotAggregate;
9
+ label?: string;
10
+ }
11
+ interface PivotOptions {
12
+ rowFields: readonly string[];
13
+ columnFields?: readonly string[];
14
+ values: readonly PivotValue[];
15
+ }
16
+ interface PivotColumn {
17
+ id: string;
18
+ label: string;
19
+ dimensions: PivotDimension[];
20
+ total: boolean;
21
+ measure: PivotValue;
22
+ }
23
+ interface PivotResultRow {
24
+ id: string;
25
+ dimensions: PivotDimension[];
26
+ values: Record<string, number | null>;
27
+ }
28
+ interface PivotResult {
29
+ columns: PivotColumn[];
30
+ rows: PivotResultRow[];
31
+ /** Grand-total row, aggregated from raw records (averages are weighted correctly). */
32
+ totals: Record<string, number | null>;
33
+ inputCount: number;
34
+ }
35
+ /** Independent, bounded pivot kernel. It never mutates input records or GridApi state. */
36
+ declare function createPivot<TData>(data: readonly TData[], options: PivotOptions): PivotResult;
37
+
38
+ type FormulaErrorCode = "SYNTAX" | "LIMIT" | "UNKNOWN_FIELD" | "NON_NUMERIC" | "DIV_ZERO" | "CYCLE" | "NON_FINITE";
39
+
40
+ interface FormulaIssue {
41
+ rowIndex: number;
42
+ colId: string;
43
+ code: FormulaErrorCode;
44
+ message: string;
45
+ }
46
+ interface FormulaResult<TData> {
47
+ rows: Array<TData & Record<string, unknown>>;
48
+ errors: FormulaIssue[];
49
+ }
50
+ /** Per-record calculated columns use flat output IDs; input references may use safe nested paths. */
51
+ declare function evaluateFormulas<TData extends object>(data: readonly TData[], formulas: Readonly<Record<string, string>>): FormulaResult<TData>;
52
+
53
+ interface AnalysisOptions<TData extends object = Record<string, unknown>> extends WorkbenchOptions<TData> {
54
+ pivot?: PivotOptions;
55
+ formulas?: Readonly<Record<string, string>>;
56
+ }
57
+ /** Optional analysis UI. Loaded-row scope and truncation are always visible, never server-wide claims. */
58
+ declare function mountAnalysis<TData extends object>(host: HTMLElement, options: AnalysisOptions<TData>): WorkbenchHandle;
59
+
60
+ export { type AnalysisOptions, type FormulaErrorCode, type FormulaIssue, type FormulaResult, type PivotAggregate, type PivotColumn, type PivotDimension, type PivotOptions, type PivotResult, type PivotResultRow, type PivotValue, createPivot, evaluateFormulas, mountAnalysis };
@@ -0,0 +1,60 @@
1
+ import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-Bn77TiBm.js';
2
+ import './api-pOhyuSQk.js';
3
+
4
+ type PivotAggregate = "sum" | "count" | "avg" | "min" | "max";
5
+ type PivotDimension = string | number | boolean | null;
6
+ interface PivotValue {
7
+ field?: string;
8
+ aggregate: PivotAggregate;
9
+ label?: string;
10
+ }
11
+ interface PivotOptions {
12
+ rowFields: readonly string[];
13
+ columnFields?: readonly string[];
14
+ values: readonly PivotValue[];
15
+ }
16
+ interface PivotColumn {
17
+ id: string;
18
+ label: string;
19
+ dimensions: PivotDimension[];
20
+ total: boolean;
21
+ measure: PivotValue;
22
+ }
23
+ interface PivotResultRow {
24
+ id: string;
25
+ dimensions: PivotDimension[];
26
+ values: Record<string, number | null>;
27
+ }
28
+ interface PivotResult {
29
+ columns: PivotColumn[];
30
+ rows: PivotResultRow[];
31
+ /** Grand-total row, aggregated from raw records (averages are weighted correctly). */
32
+ totals: Record<string, number | null>;
33
+ inputCount: number;
34
+ }
35
+ /** Independent, bounded pivot kernel. It never mutates input records or GridApi state. */
36
+ declare function createPivot<TData>(data: readonly TData[], options: PivotOptions): PivotResult;
37
+
38
+ type FormulaErrorCode = "SYNTAX" | "LIMIT" | "UNKNOWN_FIELD" | "NON_NUMERIC" | "DIV_ZERO" | "CYCLE" | "NON_FINITE";
39
+
40
+ interface FormulaIssue {
41
+ rowIndex: number;
42
+ colId: string;
43
+ code: FormulaErrorCode;
44
+ message: string;
45
+ }
46
+ interface FormulaResult<TData> {
47
+ rows: Array<TData & Record<string, unknown>>;
48
+ errors: FormulaIssue[];
49
+ }
50
+ /** Per-record calculated columns use flat output IDs; input references may use safe nested paths. */
51
+ declare function evaluateFormulas<TData extends object>(data: readonly TData[], formulas: Readonly<Record<string, string>>): FormulaResult<TData>;
52
+
53
+ interface AnalysisOptions<TData extends object = Record<string, unknown>> extends WorkbenchOptions<TData> {
54
+ pivot?: PivotOptions;
55
+ formulas?: Readonly<Record<string, string>>;
56
+ }
57
+ /** Optional analysis UI. Loaded-row scope and truncation are always visible, never server-wide claims. */
58
+ declare function mountAnalysis<TData extends object>(host: HTMLElement, options: AnalysisOptions<TData>): WorkbenchHandle;
59
+
60
+ export { type AnalysisOptions, type FormulaErrorCode, type FormulaIssue, type FormulaResult, type PivotAggregate, type PivotColumn, type PivotDimension, type PivotOptions, type PivotResult, type PivotResultRow, type PivotValue, createPivot, evaluateFormulas, mountAnalysis };
@@ -0,0 +1,3 @@
1
+ var J=new Set(["__proto__","prototype","constructor"]);function E(n){return typeof n!="string"||n.length===0?!1:n.split(".").every(t=>t.length>0&&!J.has(t))}function x(n,e){if(n==null||!E(e))return;if(e.indexOf(".")<0)return n[e];let r=n,i=0;for(;i<e.length;){if(r==null)return;let o=e.indexOf(".",i);if(o<0){r=r[e.slice(i)];break}r=r[e.slice(i,o)],i=o+1}return r}var Z=new Set(["sum","count","avg","min","max"]);function V(n){return JSON.stringify(n.map(e=>[e===null?"null":typeof e,e]))}function H(n){if(n==null)return null;if(typeof n=="number")return Number.isFinite(n)?n:null;if(typeof n=="string"||typeof n=="boolean")return n;if(n instanceof Date&&!Number.isNaN(n.getTime()))return n.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function Q(n,e){if(n.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let t=[...e.rowFields,...e.columnFields??[]];if(t.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let i of t)if(!E(i))throw new TypeError(`Invalid pivot field: ${i}`);let r=new Set;for(let i of e.values){ee(i);let o=JSON.stringify([i.field??null,i.aggregate]);if(r.has(o))throw new TypeError("Duplicate pivot measure");r.add(o)}}function ee(n){if(!Z.has(n.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(n.aggregate)}`);if(n.field!=null&&!E(n.field))throw new TypeError(`Invalid pivot field: ${n.field}`);if(!n.field&&n.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function j(n,e,t){let r=n.get(e);r||(r={count:0,numeric:0,sum:0,min:1/0,max:-1/0},n.set(e,r)),r.count++,!(typeof t!="number"||!Number.isFinite(t))&&(r.numeric++,r.sum+=t,r.min=Math.min(r.min,t),r.max=Math.max(r.max,t))}function te(n,e){return e==="count"?n?.count??0:n?.numeric?e==="avg"?Number.isFinite(n.sum)?n.sum/n.numeric:null:e==="sum"?Number.isFinite(n.sum)?n.sum:null:e==="min"?n.min:n.max:null}function ne(n,e){return JSON.stringify([n===null?"total":V(n),e.field??null,e.aggregate])}function N(n,e){Q(n,e);let t=new Map,r=new Map,i=new Map,o=e.columnFields??[];for(let s of n){let u=e.rowFields.map(p=>H(x(s,p))),m=V(u),d=t.get(m);if(d||(d={dimensions:u,cells:new Map},t.set(m,d)),t.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=o.map(p=>H(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;G(d,r,i,h,p,g),o.length&&G(d,r,i,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!n.length&&!o.length)for(let s of e.values)z(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...t.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:U(a,u.cells)}));return{columns:a,rows:l,totals:U(a,i),inputCount:n.length}}function z(n,e,t){let r=ne(e,t);if(!n.has(r)){let i=t.label??`${t.field??"\u8BB0\u5F55"} \xB7 ${t.aggregate}`,o=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");n.set(r,{id:r,label:o?`${o} / ${i}`:i,dimensions:e??[],total:e===null,measure:{...t}})}return r}function G(n,e,t,r,i,o){let a=z(e,r,i);j(n.cells,a,o),j(t,a,o)}function U(n,e){let t=Object.create(null);for(let r of n)t[r.id]=te(e.get(r.id),r.measure.aggregate);return t}var f=class extends Error{constructor(t,r){super(r);this.code=t}},W={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},re=new Set(["SUM","MIN","MAX","AVG"]);function ie(n){if(n.length>4096)throw new f("LIMIT","Formula exceeds 4096 characters");let e=[],t=n.startsWith("=")?1:0;for(;t<n.length;){if(/\s/.test(n[t])){t++;continue}let r=oe(n.slice(t));if(e.push(r),t+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new f("LIMIT","Formula exceeds 256 tokens")}return e}function oe(n){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(n);if(e)return{kind:"number",value:e[0]};let t=/^\[([^\]\r\n]+)\]/.exec(n);if(t)return{kind:"field",value:t[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(n);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(n[0]))return{kind:"symbol",value:n[0]};throw new f("SYNTAX",`Unexpected token: ${n.slice(0,12)}`)}function B(n){let e=ie(n),t=0,r=s=>{if(e[t++]?.value!==s)throw new f("SYNTAX",`Expected ${s}`)},i=(s,u)=>{if(u>32)throw new f("LIMIT","Formula exceeds 32 nesting levels");let m=a(u);for(;t<e.length;){let d=e[t].value,h=Object.prototype.hasOwnProperty.call(W,d)?W[d]:void 0;if(h==null||h<s)break;t++;let p=i(h+(d==="^"?0:1),u+1);m={kind:"binary",operator:d,left:m,right:p}}return m},o=(s,u)=>{let m=s.toUpperCase();if(!re.has(m))throw new f("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[t]?.value!==")")do d.push(i(0,u+1));while(e[t]?.value===","&&++t);if(r(")"),!d.length&&m!=="SUM")throw new f("SYNTAX",`${m} requires arguments`);return{kind:"call",name:m,args:d}},a=s=>{let u=e[t++];if(!u)throw new f("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[t]?.value==="("?o(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:i(3,s+1)};if(u.value==="("){let m=i(0,s+1);return r(")"),m}throw new f("SYNTAX",`Unexpected token: ${u.value}`)},l=i(0,0);if(t!==e.length)throw new f("SYNTAX","Unexpected trailing tokens");return l}function k(n){if(!Number.isFinite(n))throw new f("NON_FINITE","Formula result is not a finite number");return n}function se(n,e,t){if((n==="/"||n==="%")&&t===0)throw new f("DIV_ZERO","Division by zero");return n==="+"?e+t:n==="-"?e-t:n==="*"?e*t:n==="/"?e/t:n==="%"?e%t:e**t}function T(n,e){if(n.kind==="number")return k(n.value);if(n.kind==="field")return e(n.name);if(n.kind==="unary")return k((n.operator==="-"?-1:1)*T(n.operand,e));if(n.kind==="binary")return k(se(n.operator,T(n.left,e),T(n.right,e)));let t=n.args.map(i=>T(i,e));if(n.name==="MIN")return Math.min(...t);if(n.name==="MAX")return Math.max(...t);let r=t.reduce((i,o)=>i+o,0);return k(n.name==="AVG"?r/t.length:r)}function S(n,e){let t=Object.entries(e);if(t.length>32||n.length>1e4||t.length*n.length>1e5)throw new f("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of t){if(!E(a)||/[.\[\]]/.test(a))throw new f("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,B(l))}catch(s){r.set(a,X(s))}}let i=[];return{rows:n.map((a,l)=>{let s={...a},u=le(a,r);for(let[m,d]of u)d instanceof f&&i.push({rowIndex:l,colId:m,code:d.code,message:d.message}),Object.defineProperty(s,m,{value:d instanceof f?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:i}}function X(n){return n instanceof f?n:new f("SYNTAX",n instanceof Error?n.message:String(n))}function ae(n,e){if(!E(e))throw new f("UNKNOWN_FIELD",`Unknown field: ${e}`);let t=x(n,e);if(t===void 0)throw new f("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof t!="number")throw new f("NON_NUMERIC",`Field is not numeric: ${e}`);return k(t)}function le(n,e){let t=new Map,r=new Set,i=o=>{if(!e.has(o))return ae(n,o);let a=t.get(o);if(a instanceof f)throw a;if(a!=null)return a;if(r.has(o))throw new f("CYCLE",`Cyclic formula: ${[...r,o].join(" \u2192 ")}`);r.add(o);try{let l=e.get(o);if(l instanceof f)throw l;let s=k(T(l,i));return t.set(o,s),s}catch(l){let s=X(l);throw t.set(o,s),s}finally{r.delete(o)}};for(let o of e.keys())try{i(o)}catch{}return t}var ue=["--mach-font-family","--mach-font-size","--mach-font-size-sm","--mach-header-font-weight","--mach-cell-padding","--mach-header-h","--mach-primary","--mach-primary-weak","--mach-success","--mach-warning","--mach-danger","--mach-info","--mach-border-color","--mach-border-width","--mach-header-bg","--mach-header-fg","--mach-body-bg","--mach-body-fg","--mach-row-hover-bg","--mach-radius-sm","--mach-radius","--mach-radius-lg","--mach-shadow-sm","--mach-shadow","--mach-transition","--mach-z-popup","--mach-z-menu"];function Y(n,e){if(n.classList.add("mach-portal"),!e)return;let t=window.getComputedStyle(e);for(let r of ue){let i=t.getPropertyValue(r).trim();i&&n.style.setProperty(r,i)}n.style.colorScheme=t.colorScheme}function c(n,e,t){let r=document.createElement(n);return e&&(r.className=e),t!=null&&(r.textContent=t),r}function y(n,e,t=""){let r=c("button",`mach-workbench__button ${t}`.trim(),n);return r.type="button",r.addEventListener("click",e),r}function P(n,e,t,r){let i=c("select","mach-workbench__input");i.setAttribute("aria-label",n);for(let o of e){let a=c("option",void 0,o.label);a.value=o.value,i.append(a)}return i.value=t,i.addEventListener("change",()=>r(i.value)),i}function _(n,e){let t=[...n.querySelectorAll("button,select,input")].filter(i=>!i.disabled);(t.find(i=>i.getAttribute("aria-label")===e||i.textContent===e)??t[0])?.focus()}function K(n,e,t,r){let i=document.activeElement,o=c("section","mach-workbench");o.setAttribute("aria-label",e),o.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),y("\u5173\u95ED",t));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");o.append(a,l,s,u);let m=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),t())};o.addEventListener("keydown",m);let d=!1,h=r.view.getRoot(),p=()=>{d||(o.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",Y(o,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),n.append(o)}catch(v){throw g?.disconnect(),o.remove(),v}return{root:o,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=o.contains(document.activeElement);o.removeEventListener("keydown",m),o.remove(),v&&i?.isConnected&&i.focus()}}}function w(n,e,t){let r=document.createElementNS("http://www.w3.org/2000/svg",n);for(let[i,o]of Object.entries(e))r.setAttribute(i,String(o));return t!=null&&(r.textContent=t),r}function q(n,e,t){let r=c("figure","mach-analysis__chart"),i=n.columns.find(b=>b.id===e);if(!i)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let o=n.rows.slice(0,40),a=`${i.label} \xB7 ${t==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${o.length} \u7EC4`,l=w("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(w("title",{},a));let s=o.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),m=Math.max(0,...s),d=Math.max(Math.abs(m),Math.abs(u))||1,h=m/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(w("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(w("text",{x:2,y:25,"font-size":11},String(m)),w("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(o.length,1),M=[],D=()=>{M.length&&l.append(w("polyline",{points:M.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),M=[]};return o.forEach((b,O)=>{let C=b.values[e];if(C==null){D();return}let F=55+v*(O+.5),A=p(C),L=b.dimensions.map($=>$==null?"\u7A7A\u503C":String($)).join(" / ")||"\u5168\u90E8",I=t==="bar"?w("rect",{x:F-v*.35,y:Math.min(g,A),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(A-g)),fill:"currentColor",rx:2}):w("circle",{cx:F,cy:A,r:3,fill:"currentColor"});I.append(w("title",{},`${L}: ${C}`)),l.append(I),t==="line"&&M.push(`${F},${A}`),(o.length<=10||O%Math.ceil(o.length/10)===0)&&l.append(w("text",{x:F,y:238,"text-anchor":"middle","font-size":10},L.slice(0,12)))}),D(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${n.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 ce={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function de(n,e){return new R(n,e)}var R=class{constructor(e,t){this.options=t;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.i="bar";this.t="";this.destroyed=!1;if(t.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...t.pivot?.rowFields??[]],columnFields:[...t.pivot?.columnFields??[]],values:t.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(t.formulas??{}).map(([r,i])=>({field:r,expression:i})),this.e=K(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),t.onClose?.()},t.api),this.e.footer.append(y("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.o=[t.api.on("gridDestroyed",()=>this.destroy()),t.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.o.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],t=r=>{for(let i of r){if("children"in i){t(i.children);continue}if(!i.field)continue;let o=x(this.options.api.rows.getAt(0)?.data,i.field);e.push({field:i.field,label:i.headerName??i.field,numeric:typeof o=="number"||i.cellEditor==="number"||i.filter==="number"})}};t(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(i=>i.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,i=>{this.config.rowFields=i}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],i=>{this.config.columnFields=i}));let t=c("fieldset","mach-workbench__group");t.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((i,o)=>t.append(this.measure(i,o)));let r=y("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,t.append(r),e.append(t,this.d()),this.e.body.append(e)}dimensions(e,t,r){let i=c("label","mach-analysis__dimension",e),o=c("select","mach-workbench__input");o.multiple=!0,o.setAttribute("aria-label",e);let a=[...this.fields];for(let l of t)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=t.includes(l.field),o.append(s)}return o.addEventListener("change",()=>r([...o.selectedOptions].map(l=>l.value))),i.append(o,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),i}measure(e,t){let r=c("div","mach-workbench__values"),i=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(o=>({value:o.field,label:o.label}))];return e.field&&!i.some(o=>o.value===e.field)&&i.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(P("\u6307\u6807\u5B57\u6BB5",i,e.field??"",o=>{e.field=o||void 0}),P("\u805A\u5408\u65B9\u5F0F",Object.entries(ce).map(([o,a])=>({value:o,label:a})),e.aggregate,o=>{e.aggregate=o}),y("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((o,a)=>a!==t),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,i)=>{let o=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}),o.append(a,l,y("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(i,1),this.refresh()})),e.append(o)});let t=y("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return t.disabled=this.formulas.length>=32,e.append(t),e}s(){if(!this.a())return;let e=[],t=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(t++,e.length<1e4&&e.push(r.data))});try{let r=this.f(),i=S(e,r);if(i.errors.length){let l=i.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 ${i.errors.length} \u9879${i.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
2
+ ${l.join(`
3
+ `)}`)}this.m(r),this.result=N(i.rows,this.config),this.page=0,this.refresh();let o=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=t>e.length?`\u5DF2\u52A0\u8F7D ${t} \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}${o} \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")}}f(){let e=Object.create(null);for(let t of this.formulas){if(!t.field||Object.prototype.hasOwnProperty.call(e,t.field))throw new Error("\u516C\u5F0F\u7ED3\u679C\u5217\u4E0D\u80FD\u4E3A\u7A7A\u6216\u91CD\u590D");e[t.field]=t.expression}return e}m(e){let t=new Set([...this.l().map(i=>i.field),...Object.keys(e)]),r=[...this.config.rowFields,...this.config.columnFields??[],...this.config.values.flatMap(i=>i.field?[i.field]:[])];for(let i of r)if(!t.has(i))throw new Error(`\u5B57\u6BB5\u5DF2\u79FB\u9664\u6216\u4E0D\u53EF\u5206\u6790\uFF1A${i}`)}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 t=c("div","mach-workbench__tools");t.append(P("\u56FE\u8868\u7C7B\u578B",[{value:"bar",label:"\u67F1\u72B6\u56FE"},{value:"line",label:"\u6298\u7EBF\u56FE"}],this.i,l=>{this.i=l,this.n(),_(this.results,"\u56FE\u8868\u7C7B\u578B")}),P("\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(t,q(e,this.t,this.i),this.table(e));let r=Math.max(1,Math.ceil(e.rows.length/50)),i=c("nav","mach-workbench__tools");i.setAttribute("aria-label","\u5206\u6790\u7ED3\u679C\u5206\u9875");let o=y("\u4E0A\u4E00\u9875",()=>{this.page--,this.n(),_(this.results.querySelector("nav"),"\u4E0A\u4E00\u9875")}),a=y("\u4E0B\u4E00\u9875",()=>{this.page++,this.n(),_(this.results.querySelector("nav"),"\u4E0B\u4E00\u9875")});o.disabled=this.page<=0,a.disabled=this.page>=r-1,i.append(o,c("span",void 0,`\u7B2C ${this.page+1} / ${r} \u9875 \xB7 \u6BCF\u9875 50 \u7EC4`),a),this.results.append(i)}table(e){let t=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 i=c("thead"),o=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",o.append(u)}i.append(o);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(i,a,l),t.append(r),t}u(e,t,r){let i=c("tr"),o=c("th",void 0,e);o.scope="row",i.append(o);for(let a of t.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),i.append(s)}return i}};export{N as createPivot,S as evaluateFormulas,de as mountAnalysis};