@agile-team/mach-table 0.38.0 → 0.39.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/adapter.cjs +1 -1
- package/dist/adapter.d.cts +6 -2
- package/dist/adapter.d.ts +6 -2
- package/dist/adapter.js +1 -1
- package/dist/analysis.cjs +1 -1
- package/dist/analysis.d.cts +2 -2
- package/dist/analysis.d.ts +2 -2
- package/dist/analysis.js +2 -2
- package/dist/{api-Bgcy7aRd.d.cts → api-ChEKWrvH.d.cts} +6 -1
- package/dist/{api-Bgcy7aRd.d.ts → api-ChEKWrvH.d.ts} +6 -1
- package/dist/{configuration-B5dSDN9d.d.ts → configuration-BPj5MIUw.d.ts} +1 -1
- package/dist/{configuration-BVWcsdGm.d.cts → configuration-CZm-aiTf.d.cts} +1 -1
- package/dist/import.d.cts +1 -1
- package/dist/import.d.ts +1 -1
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +6 -6
- package/dist/multi-range.cjs +3 -3
- package/dist/multi-range.d.cts +1 -1
- package/dist/multi-range.d.ts +1 -1
- package/dist/multi-range.js +2 -2
- package/dist/ordering.cjs +1 -1
- package/dist/ordering.d.cts +1 -1
- package/dist/ordering.d.ts +1 -1
- package/dist/ordering.js +1 -1
- package/dist/preferences.d.cts +1 -1
- package/dist/preferences.d.ts +1 -1
- package/dist/server-side.d.cts +1 -1
- package/dist/server-side.d.ts +1 -1
- package/dist/{shared-DfLrRGYY.d.cts → shared-BIBSfPcs.d.cts} +1 -1
- package/dist/{shared-CLEc9O2p.d.ts → shared-Qnznvth3.d.ts} +1 -1
- package/dist/workbench.cjs +1 -1
- package/dist/workbench.d.cts +3 -3
- package/dist/workbench.d.ts +3 -3
- package/dist/workbench.js +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +2 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
# @agile-team/mach-table
|
|
6
6
|
|
|
7
|
-
MachTable 0.
|
|
7
|
+
MachTable 0.39.1 的框架无关 TypeScript Core,零运行时依赖。提供行列双虚拟化、编辑、树与分组、随机访问远程数据和区段隔离状态持久化。通过 `rowNumber: true` 启用自动序号,内置分页默认开启。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
本地明细使用 `domLayout: "autoHeight"` 随当前页内容收起。加上 `maxBodyHeight: 330`,超过 330px 的表体会使用虚拟滚动。表内筛选无匹配时,默认空态提供清除筛选;业务自定义空态优先。
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
pnpm add @agile-team/mach-table
|
package/dist/adapter.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var A=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var me=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},ge=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of pe(t))!fe.call(e,r)&&r!==n&&A(e,r,{get:()=>t[r],enumerable:!(o=ue(t,r))||o.enumerable});return e};var be=e=>ge(A({},"__esModule",{value:!0}),e);var Pe={};me(Pe,{GRID_OPTION_KEYS:()=>re,GRID_OPTION_META:()=>oe,beginGridInput:()=>te,canReplaceGridData:()=>ee,createSelectControl:()=>Y,equivalentConfigValue:()=>x,equivalentGridOption:()=>_,mergeMachTableConfig:()=>ie,normalizeMachTableConfig:()=>S,readGridCell:()=>Q,resolveMachTableGridOptions:()=>se,resumeGrid:()=>Z,suspendGrid:()=>J,writeGridInput:()=>X});module.exports=be(Pe);function x(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((r,l)=>x(r,t[l],n-1));if(!F(e)||!F(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&x(e[r],t[r],n-1))}function F(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var ye=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function _(e,t,n){return Object.is(t,n)||ye.has(e)&&x(t,n,3)}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let r of Object.keys(n))o.setAttribute(r,n[r]);return o}function B(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let r=n.item(o);if(!r.startsWith("--mach-"))continue;let l=n.getPropertyValue(r).trim();l&&e.style.setProperty(r,l)}e.style.colorScheme=n.colorScheme}function V(e,t,n){return e<t?t:e>n?n:e}var W=0;function $(e="rg"){return W++,`${e}-${W}`}var p=null;function z(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function U(e){let t=e.target;p?.contains(t)||p?.close()}function P(){p?.reposition()}function q(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function he(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",U,!0),document.addEventListener("keydown",q,!0),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0))}function Te(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",U,!0),document.removeEventListener("keydown",q,!0),window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0))}function T(e,t){return t?`${e} ${t}`:e}function M(e,t,n){let o=e[t]&&!e[t].disabled,r=o?t+n:n>0?0:e.length-1;for(let l=r;l>=0&&l<e.length;l+=n)if(!e[l].disabled)return l;return o?t:-1}function E(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function Y(e){let t=y("div",T("mach-select-control",e.classNames?.root)),n=y("select",T("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",T("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let r=y("span",T("mach-select-value",e.classNames?.value)),l=y("span",T("mach-select-caret",e.classNames?.caret));l.setAttribute("aria-hidden","true"),o.append(r,l);let s=y("div",T("mach-select-listbox",e.classNames?.listbox));s.id=$("mach-select-listbox"),s.setAttribute("role","listbox"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",s.id),t.append(n,o);let i=[...e.options],m=[],d=-1,g=!1,le=()=>e.themeSource??t.closest(".mach-root")??t,I=a=>t.contains(a)||s.contains(a),C=()=>s.classList.contains("mach-select-listbox--open"),w=()=>{let a=i.find(c=>c.value===n.value);r.textContent=a?.label??n.value,m.forEach((c,v)=>{let u=i[v]?.value===n.value;c.setAttribute("aria-selected",u?"true":"false"),c.classList.toggle("mach-select-option--selected",u),c.classList.toggle("mach-select-option--active",v===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},L=()=>{let a=o.getBoundingClientRect(),c=s.getBoundingClientRect(),v=Math.max(a.width,c.width),u=V(a.left,8,Math.max(8,window.innerWidth-v-8)),O=window.innerHeight-a.bottom-8,h=O<Math.min(c.height,240)&&a.top>O,f=h?Math.max(8,a.top-c.height-5):Math.min(window.innerHeight-c.height-8,a.bottom+5);s.style.minWidth=`${a.width}px`,s.style.left=`${u}px`,s.style.top=`${Math.max(8,f)}px`,s.classList.toggle("mach-select-listbox--above",h)},b=(a=!1)=>C()?(s.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),s.remove(),Te(b),a&&!g&&o.focus({preventScroll:!0}),!0):!1,ce=(a,c=!0)=>{!i[a]||i[a].disabled||(d=a,w(),c&&m[a]?.scrollIntoView?.({block:"nearest"}))},R=()=>{if(g||o.disabled||C())return;let a=le();he({owner:a,close:b,contains:I,reposition:L}),d=E(i,n.value),d<0&&(d=M(i,-1,1)),B(s,a),document.body.appendChild(s),s.classList.add("mach-select-listbox--open"),s.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),L(),w(),m[d]?.scrollIntoView?.({block:"nearest"})},N=a=>{let c=i[a];!c||c.disabled||(n.value=c.value,d=a,w(),b(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},j=(a,c)=>{i=[...a],n.replaceChildren(),s.replaceChildren(),m=i.map((u,O)=>{let h=document.createElement("option");h.value=u.value,h.textContent=u.label,h.disabled=u.disabled===!0,n.appendChild(h);let f=y("button",T("mach-select-option",e.classNames?.option));return f.id=`${s.id}-option-${O}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",de=>de.preventDefault()),f.addEventListener("click",()=>N(O)),s.appendChild(f),f});let v=i.find(u=>!u.disabled)?.value??"";n.value=c!=null&&i.some(u=>u.value===c)?c:v,d=E(i,n.value),w()},H=a=>{if(a.key==="Tab"){b();return}if(a.key==="Escape"){if(!b(!0))return;a.preventDefault(),a.stopPropagation();return}if(a.key==="Enter"||a.key===" "){a.preventDefault(),a.stopPropagation(),C()?N(d):R();return}let c=d;if(a.key==="ArrowDown")c=M(i,d,1);else if(a.key==="ArrowUp")c=M(i,d,-1);else if(a.key==="Home")c=M(i,-1,1);else if(a.key==="End")c=M(i,-1,-1);else return;a.preventDefault(),a.stopPropagation(),C()||R(),ce(c)},K=()=>{d=E(i,n.value),w(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{b()||R()}),o.addEventListener("keydown",H),n.addEventListener("change",K),j(i,e.value),{el:t,native:n,trigger:o,listbox:s,contains:I,isOpen:C,open:R,close:b,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:a=>{n.value=a,d=E(i,a),w()},setOptions:j,destroy:()=>{g||(g=!0,b(),o.removeEventListener("keydown",H),n.removeEventListener("change",K),t.remove())}}}var G=Symbol.for("mach-table.adapter.lifecycle.v1");function J(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&z(t),e[G]?.suspend()}function Z(e){e.isDestroyed()||e[G]?.resume()}function Q(e,t,n){return e.isDestroyed()?"":e[G]?.readCell(t,n)??""}function X(e,t){e.isDestroyed()||e[G]?.writeInput(t)}function ee(e){return!e.isDestroyed()&&(e[G]?.canReplaceData()??!1)}var we=Symbol.for("mach-table.import.v1");function ve(e){let t=e[we];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function te(e){return e.isDestroyed()?()=>!1:ve(e).begin()}var ne={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",rowNumber:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function De(){return Object.fromEntries(Object.entries(ne).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var oe=De(),re=Object.freeze(Object.keys(ne));function k(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function Ce(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(r){o=r}try{t(...n)}catch(r){o??(o=r)}if(o!==void 0)throw o}}function Oe(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function xe(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let r of o)n[r]={...e.columnTypes?.[r],...t.columnTypes?.[r]};return n}function Me(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let r=t[o],l=n[o];typeof r!="function"||typeof l!="function"||(e[o]=Ce(r,l))}}function Ge(e,t){let n={...e,...t,features:t.features??e.features};(e.defaultColDef||t.defaultColDef)&&(n.defaultColDef={...e.defaultColDef,...t.defaultColDef}),(e.locale||t.locale)&&(n.locale={...e.locale,...t.locale});let o=Oe(e,t);o&&(n.components=o);let r=xe(e,t);return r&&(n.columnTypes=r),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=k(e.pagination,t.pagination),n.statusBar=k(e.statusBar,t.statusBar),n.watermark=k(e.watermark,t.watermark),Me(n,e,t),n}function D(...e){return e.reduce(Ge,{})}function Re(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var Ee=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function ae(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[r,l]of Object.entries(t)){if(!Ee.includes(r)&&(r!=="dataProcessor"||l==null||typeof l=="function")){o[r]=l;continue}let s={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:r,layer:n,message:r==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${r}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(s),e.strict!==!1)throw new TypeError(s.message)}return o}function S(e={}){let t=ae(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(ae(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function ie(e,t){let n=S({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[r,l]of Object.entries(n.presets))o[r]=D(e.presets[r]??{},l);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function se(e,t,n,o){let r=t===void 0?e.defaultPreset:t,l=[{name:"application defaults",options:e.defaults}];for(let i of Re(r)){let m=e.presets[i];if(!m){let d={code:"UNKNOWN_PRESET",preset:i,message:`[MachTable] Unknown preset "${i}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}l.push({name:`preset:${i}`,options:m})}l.push({name:"table props",options:n});let s={rowNumber:!0,...D(...l.map(i=>i.options))};return{options:s,explain(i){let m=l.filter(g=>Object.prototype.hasOwnProperty.call(g.options,i)).map(g=>({name:g.name,value:g.options[i]})),d=m[m.length-1];return{key:i,value:s[i],source:d?.name??"MachTable built-in",layers:m}}}}0&&(module.exports={GRID_OPTION_KEYS,GRID_OPTION_META,beginGridInput,canReplaceGridData,createSelectControl,equivalentConfigValue,equivalentGridOption,mergeMachTableConfig,normalizeMachTableConfig,readGridCell,resolveMachTableGridOptions,resumeGrid,suspendGrid,writeGridInput});
|
|
1
|
+
"use strict";var P=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var be=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},ge=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of fe(t))!me.call(e,r)&&r!==n&&P(e,r,{get:()=>t[r],enumerable:!(o=pe(t,r))||o.enumerable});return e};var ye=e=>ge(P({},"__esModule",{value:!0}),e);var Ie={};be(Ie,{GRID_OPTION_KEYS:()=>ie,GRID_OPTION_META:()=>re,beginGridInput:()=>ne,canReplaceGridData:()=>te,createSelectControl:()=>J,equivalentConfigValue:()=>x,equivalentGridOption:()=>_,mergeMachTableConfig:()=>se,normalizeMachTableConfig:()=>A,readGridCell:()=>X,resolveMachTableGridOptions:()=>le,resumeGrid:()=>Q,suspendGrid:()=>Z,writeGridInput:()=>ee});module.exports=ye(Ie);function k(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function x(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((r,l)=>x(r,t[l],n-1));if(!F(e)||!F(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(r=>k(t,r)&&x(e[r],t[r],n-1))}function F(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var he=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function _(e,t,n){return Object.is(t,n)||he.has(e)&&x(t,n,3)}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let r of Object.keys(n))o.setAttribute(r,n[r]);return o}function Te(e,t,n,o=!1){let r=t?"addEventListener":"removeEventListener";for(let[l,s]of Object.entries(n))e[r](l,s,o)}function B(e,t,n){Te(document,e,{mousedown:t,keydown:n},!0)}function V(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let r=n.item(o);if(!r.startsWith("--mach-"))continue;let l=n.getPropertyValue(r).trim();l&&e.style.setProperty(r,l)}e.style.colorScheme=n.colorScheme}function z(e,t,n){return e<t?t:e>n?n:e}var W=0;function $(e="rg"){return W++,`${e}-${W}`}var p=null;function q(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function we(e){let t=e.target;p?.contains(t)||p?.close()}function U(){p?.reposition()}function ve(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function Y(e){B(e,we,ve);let t=e?"addEventListener":"removeEventListener";window[t]("resize",U),window[t]("scroll",U,!0)}function De(e){p?.close!==e.close&&p?.close(),!p&&(p=e,Y(!0))}function Oe(e){p?.close===e&&(p=null,Y(!1))}function T(e,t){return t?`${e} ${t}`:e}function M(e,t,n){let o=e[t]&&!e[t].disabled,r=o?t+n:n>0?0:e.length-1;for(let l=r;l>=0&&l<e.length;l+=n)if(!e[l].disabled)return l;return o?t:-1}function E(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function J(e){let t=y("div",T("mach-select-control",e.classNames?.root)),n=y("select",T("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",T("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let r=y("span",T("mach-select-value",e.classNames?.value)),l=y("span",T("mach-select-caret",e.classNames?.caret));l.setAttribute("aria-hidden","true"),o.append(r,l);let s=y("div",T("mach-select-listbox",e.classNames?.listbox));s.id=$("mach-select-listbox"),s.setAttribute("role","listbox"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",s.id),t.append(n,o);let a=[...e.options],m=[],d=-1,b=!1,ce=()=>e.themeSource??t.closest(".mach-root")??t,I=i=>t.contains(i)||s.contains(i),O=()=>s.classList.contains("mach-select-listbox--open"),w=()=>{let i=a.find(c=>c.value===n.value);r.textContent=i?.label??n.value,m.forEach((c,v)=>{let u=a[v]?.value===n.value;c.setAttribute("aria-selected",u?"true":"false"),c.classList.toggle("mach-select-option--selected",u),c.classList.toggle("mach-select-option--active",v===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},L=()=>{let i=o.getBoundingClientRect(),c=s.getBoundingClientRect(),v=Math.max(i.width,c.width),u=z(i.left,8,Math.max(8,window.innerWidth-v-8)),C=window.innerHeight-i.bottom-8,h=C<Math.min(c.height,240)&&i.top>C,f=h?Math.max(8,i.top-c.height-5):Math.min(window.innerHeight-c.height-8,i.bottom+5);s.style.minWidth=`${i.width}px`,s.style.left=`${u}px`,s.style.top=`${Math.max(8,f)}px`,s.classList.toggle("mach-select-listbox--above",h)},g=(i=!1)=>O()?(s.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),s.remove(),Oe(g),i&&!b&&o.focus({preventScroll:!0}),!0):!1,de=(i,c=!0)=>{!a[i]||a[i].disabled||(d=i,w(),c&&m[i]?.scrollIntoView?.({block:"nearest"}))},R=()=>{if(b||o.disabled||O())return;let i=ce();De({owner:i,close:g,contains:I,reposition:L}),d=E(a,n.value),d<0&&(d=M(a,-1,1)),V(s,i),document.body.appendChild(s),s.classList.add("mach-select-listbox--open"),s.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),L(),w(),m[d]?.scrollIntoView?.({block:"nearest"})},N=i=>{let c=a[i];!c||c.disabled||(n.value=c.value,d=i,w(),g(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},j=(i,c)=>{a=[...i],n.replaceChildren(),s.replaceChildren(),m=a.map((u,C)=>{let h=document.createElement("option");h.value=u.value,h.textContent=u.label,h.disabled=u.disabled===!0,n.appendChild(h);let f=y("button",T("mach-select-option",e.classNames?.option));return f.id=`${s.id}-option-${C}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",ue=>ue.preventDefault()),f.addEventListener("click",()=>N(C)),s.appendChild(f),f});let v=a.find(u=>!u.disabled)?.value??"";n.value=c!=null&&a.some(u=>u.value===c)?c:v,d=E(a,n.value),w()},K=i=>{if(i.key==="Tab"){g();return}if(i.key==="Escape"){if(!g(!0))return;i.preventDefault(),i.stopPropagation();return}if(i.key==="Enter"||i.key===" "){i.preventDefault(),i.stopPropagation(),O()?N(d):R();return}let c=d;if(i.key==="ArrowDown")c=M(a,d,1);else if(i.key==="ArrowUp")c=M(a,d,-1);else if(i.key==="Home")c=M(a,-1,1);else if(i.key==="End")c=M(a,-1,-1);else return;i.preventDefault(),i.stopPropagation(),O()||R(),de(c)},H=()=>{d=E(a,n.value),w(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{g()||R()}),o.addEventListener("keydown",K),n.addEventListener("change",H),j(a,e.value),{el:t,native:n,trigger:o,listbox:s,contains:I,isOpen:O,open:R,close:g,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:i=>{n.value=i,d=E(a,i),w()},setOptions:j,destroy:()=>{b||(b=!0,g(),o.removeEventListener("keydown",K),n.removeEventListener("change",H),t.remove())}}}var G=Symbol.for("mach-table.adapter.lifecycle.v1");function Z(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&q(t),e[G]?.suspend()}function Q(e){e.isDestroyed()||e[G]?.resume()}function X(e,t,n){return e.isDestroyed()?"":e[G]?.readCell(t,n)??""}function ee(e,t){e.isDestroyed()||e[G]?.writeInput(t)}function te(e){return!e.isDestroyed()&&(e[G]?.canReplaceData()??!1)}var Ce=Symbol.for("mach-table.import.v1");function xe(e){let t=e[Ce];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function ne(e){return e.isDestroyed()?()=>!1:xe(e).begin()}var oe={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",maxBodyHeight:"number",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",rowNumber:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function Me(){return Object.fromEntries(Object.entries(oe).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var re=Me(),ie=Object.freeze(Object.keys(oe));function S(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function Ge(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(r){o=r}try{t(...n)}catch(r){o??(o=r)}if(o!==void 0)throw o}}function Re(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function ke(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let r of o)n[r]={...e.columnTypes?.[r],...t.columnTypes?.[r]};return n}function Ee(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let r=t[o],l=n[o];typeof r!="function"||typeof l!="function"||(e[o]=Ge(r,l))}}function Pe(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 r=ke(e,t);return r&&(n.columnTypes=r),(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),Ee(n,e,t),n}function D(...e){return e.reduce(Pe,{})}function Se(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var Ae=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function ae(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[r,l]of Object.entries(t)){if(!Ae.includes(r)&&(r!=="dataProcessor"||l==null||typeof l=="function")){o[r]=l;continue}let s={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:r,layer:n,message:r==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${r}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(s),e.strict!==!1)throw new TypeError(s.message)}return o}function A(e={}){let t=ae(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(ae(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function se(e,t){let n=A({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[r,l]of Object.entries(n.presets))o[r]=D(e.presets[r]??{},l);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function le(e,t,n,o){let r=t===void 0?e.defaultPreset:t,l=[{name:"application defaults",options:e.defaults}];for(let a of Se(r)){let m=e.presets[a];if(!m){let d={code:"UNKNOWN_PRESET",preset:a,message:`[MachTable] Unknown preset "${a}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}l.push({name:`preset:${a}`,options:m})}l.push({name:"table props",options:n});let s={rowNumber:!0,...D(...l.map(a=>a.options))};return{options:s,explain(a){let m=l.filter(b=>k(b.options,a)).map(b=>({name:b.name,value:b.options[a]})),d=m[m.length-1];return{key:a,value:s[a],source:d?.name??"MachTable built-in",layers:m}}}}0&&(module.exports={GRID_OPTION_KEYS,GRID_OPTION_META,beginGridInput,canReplaceGridData,createSelectControl,equivalentConfigValue,equivalentGridOption,mergeMachTableConfig,normalizeMachTableConfig,readGridCell,resolveMachTableGridOptions,resumeGrid,suspendGrid,writeGridInput});
|
package/dist/adapter.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-
|
|
2
|
-
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-
|
|
1
|
+
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-ChEKWrvH.cjs';
|
|
2
|
+
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-CZm-aiTf.cjs';
|
|
3
3
|
|
|
4
4
|
/** Bounded structural comparison for small immutable config values, never row data. */
|
|
5
5
|
declare function equivalentConfigValue(left: unknown, right: unknown, depth?: number): boolean;
|
|
@@ -81,6 +81,10 @@ declare const GRID_OPTION_META: {
|
|
|
81
81
|
readonly kind: "string";
|
|
82
82
|
readonly update: "options";
|
|
83
83
|
};
|
|
84
|
+
readonly maxBodyHeight: {
|
|
85
|
+
readonly kind: "number";
|
|
86
|
+
readonly update: "options";
|
|
87
|
+
};
|
|
84
88
|
readonly rowSelection: {
|
|
85
89
|
readonly kind: "string";
|
|
86
90
|
readonly update: "options";
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-
|
|
2
|
-
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-
|
|
1
|
+
import { b as GridApi, c as GridOptions, j as GridEventType } from './api-ChEKWrvH.js';
|
|
2
|
+
export { M as MachTableOptionExplanation, R as ResolvedMachTableConfig, a as ResolvedMachTableGridOptions, m as mergeMachTableConfig, n as normalizeMachTableConfig, r as resolveMachTableGridOptions } from './configuration-BPj5MIUw.js';
|
|
3
3
|
|
|
4
4
|
/** Bounded structural comparison for small immutable config values, never row data. */
|
|
5
5
|
declare function equivalentConfigValue(left: unknown, right: unknown, depth?: number): boolean;
|
|
@@ -81,6 +81,10 @@ declare const GRID_OPTION_META: {
|
|
|
81
81
|
readonly kind: "string";
|
|
82
82
|
readonly update: "options";
|
|
83
83
|
};
|
|
84
|
+
readonly maxBodyHeight: {
|
|
85
|
+
readonly kind: "number";
|
|
86
|
+
readonly update: "options";
|
|
87
|
+
};
|
|
84
88
|
readonly rowSelection: {
|
|
85
89
|
readonly kind: "string";
|
|
86
90
|
readonly update: "options";
|
package/dist/adapter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function R(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((a,l)=>R(a,t[l],n-1));if(!H(e)||!H(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(a=>Object.prototype.hasOwnProperty.call(t,a)&&R(e[a],t[a],n-1))}function H(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var Q=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function X(e,t,n){return Object.is(t,n)||Q.has(e)&&R(t,n,3)}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let a of Object.keys(n))o.setAttribute(a,n[a]);return o}function F(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let a=n.item(o);if(!a.startsWith("--mach-"))continue;let l=n.getPropertyValue(a).trim();l&&e.style.setProperty(a,l)}e.style.colorScheme=n.colorScheme}function _(e,t,n){return e<t?t:e>n?n:e}var K=0;function W(e="rg"){return K++,`${e}-${K}`}var p=null;function B(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function V(e){let t=e.target;p?.contains(t)||p?.close()}function P(){p?.reposition()}function $(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function ee(e){p?.close!==e.close&&p?.close(),!p&&(p=e,document.addEventListener("mousedown",V,!0),document.addEventListener("keydown",$,!0),window.addEventListener("resize",P),window.addEventListener("scroll",P,!0))}function te(e){p?.close===e&&(p=null,document.removeEventListener("mousedown",V,!0),document.removeEventListener("keydown",$,!0),window.removeEventListener("resize",P),window.removeEventListener("scroll",P,!0))}function T(e,t){return t?`${e} ${t}`:e}function x(e,t,n){let o=e[t]&&!e[t].disabled,a=o?t+n:n>0?0:e.length-1;for(let l=a;l>=0&&l<e.length;l+=n)if(!e[l].disabled)return l;return o?t:-1}function E(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function ne(e){let t=y("div",T("mach-select-control",e.classNames?.root)),n=y("select",T("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",T("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let a=y("span",T("mach-select-value",e.classNames?.value)),l=y("span",T("mach-select-caret",e.classNames?.caret));l.setAttribute("aria-hidden","true"),o.append(a,l);let s=y("div",T("mach-select-listbox",e.classNames?.listbox));s.id=W("mach-select-listbox"),s.setAttribute("role","listbox"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",s.id),t.append(n,o);let i=[...e.options],m=[],d=-1,g=!1,Y=()=>e.themeSource??t.closest(".mach-root")??t,k=r=>t.contains(r)||s.contains(r),C=()=>s.classList.contains("mach-select-listbox--open"),w=()=>{let r=i.find(c=>c.value===n.value);a.textContent=r?.label??n.value,m.forEach((c,v)=>{let u=i[v]?.value===n.value;c.setAttribute("aria-selected",u?"true":"false"),c.classList.toggle("mach-select-option--selected",u),c.classList.toggle("mach-select-option--active",v===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},S=()=>{let r=o.getBoundingClientRect(),c=s.getBoundingClientRect(),v=Math.max(r.width,c.width),u=_(r.left,8,Math.max(8,window.innerWidth-v-8)),O=window.innerHeight-r.bottom-8,h=O<Math.min(c.height,240)&&r.top>O,f=h?Math.max(8,r.top-c.height-5):Math.min(window.innerHeight-c.height-8,r.bottom+5);s.style.minWidth=`${r.width}px`,s.style.left=`${u}px`,s.style.top=`${Math.max(8,f)}px`,s.classList.toggle("mach-select-listbox--above",h)},b=(r=!1)=>C()?(s.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),s.remove(),te(b),r&&!g&&o.focus({preventScroll:!0}),!0):!1,J=(r,c=!0)=>{!i[r]||i[r].disabled||(d=r,w(),c&&m[r]?.scrollIntoView?.({block:"nearest"}))},G=()=>{if(g||o.disabled||C())return;let r=Y();ee({owner:r,close:b,contains:k,reposition:S}),d=E(i,n.value),d<0&&(d=x(i,-1,1)),F(s,r),document.body.appendChild(s),s.classList.add("mach-select-listbox--open"),s.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),S(),w(),m[d]?.scrollIntoView?.({block:"nearest"})},I=r=>{let c=i[r];!c||c.disabled||(n.value=c.value,d=r,w(),b(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},L=(r,c)=>{i=[...r],n.replaceChildren(),s.replaceChildren(),m=i.map((u,O)=>{let h=document.createElement("option");h.value=u.value,h.textContent=u.label,h.disabled=u.disabled===!0,n.appendChild(h);let f=y("button",T("mach-select-option",e.classNames?.option));return f.id=`${s.id}-option-${O}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",Z=>Z.preventDefault()),f.addEventListener("click",()=>I(O)),s.appendChild(f),f});let v=i.find(u=>!u.disabled)?.value??"";n.value=c!=null&&i.some(u=>u.value===c)?c:v,d=E(i,n.value),w()},N=r=>{if(r.key==="Tab"){b();return}if(r.key==="Escape"){if(!b(!0))return;r.preventDefault(),r.stopPropagation();return}if(r.key==="Enter"||r.key===" "){r.preventDefault(),r.stopPropagation(),C()?I(d):G();return}let c=d;if(r.key==="ArrowDown")c=x(i,d,1);else if(r.key==="ArrowUp")c=x(i,d,-1);else if(r.key==="Home")c=x(i,-1,1);else if(r.key==="End")c=x(i,-1,-1);else return;r.preventDefault(),r.stopPropagation(),C()||G(),J(c)},j=()=>{d=E(i,n.value),w(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{b()||G()}),o.addEventListener("keydown",N),n.addEventListener("change",j),L(i,e.value),{el:t,native:n,trigger:o,listbox:s,contains:k,isOpen:C,open:G,close:b,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:r=>{n.value=r,d=E(i,r),w()},setOptions:L,destroy:()=>{g||(g=!0,b(),o.removeEventListener("keydown",N),n.removeEventListener("change",j),t.remove())}}}var M=Symbol.for("mach-table.adapter.lifecycle.v1");function oe(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&B(t),e[M]?.suspend()}function re(e){e.isDestroyed()||e[M]?.resume()}function ae(e,t,n){return e.isDestroyed()?"":e[M]?.readCell(t,n)??""}function ie(e,t){e.isDestroyed()||e[M]?.writeInput(t)}function se(e){return!e.isDestroyed()&&(e[M]?.canReplaceData()??!1)}var le=Symbol.for("mach-table.import.v1");function ce(e){let t=e[le];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function de(e){return e.isDestroyed()?()=>!1:ce(e).begin()}var z={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",rowNumber:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function ue(){return Object.fromEntries(Object.entries(z).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var pe=ue(),fe=Object.freeze(Object.keys(z));function A(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function me(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(a){o=a}try{t(...n)}catch(a){o??(o=a)}if(o!==void 0)throw o}}function ge(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function be(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let a of o)n[a]={...e.columnTypes?.[a],...t.columnTypes?.[a]};return n}function ye(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let a=t[o],l=n[o];typeof a!="function"||typeof l!="function"||(e[o]=me(a,l))}}function he(e,t){let n={...e,...t,features:t.features??e.features};(e.defaultColDef||t.defaultColDef)&&(n.defaultColDef={...e.defaultColDef,...t.defaultColDef}),(e.locale||t.locale)&&(n.locale={...e.locale,...t.locale});let o=ge(e,t);o&&(n.components=o);let a=be(e,t);return a&&(n.columnTypes=a),(e.aggFuncs||t.aggFuncs)&&(n.aggFuncs={...e.aggFuncs,...t.aggFuncs}),n.pagination=A(e.pagination,t.pagination),n.statusBar=A(e.statusBar,t.statusBar),n.watermark=A(e.watermark,t.watermark),ye(n,e,t),n}function D(...e){return e.reduce(he,{})}function Te(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var we=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function U(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[a,l]of Object.entries(t)){if(!we.includes(a)&&(a!=="dataProcessor"||l==null||typeof l=="function")){o[a]=l;continue}let s={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:a,layer:n,message:a==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${a}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(s),e.strict!==!1)throw new TypeError(s.message)}return o}function q(e={}){let t=U(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(U(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function ve(e,t){let n=q({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[a,l]of Object.entries(n.presets))o[a]=D(e.presets[a]??{},l);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function De(e,t,n,o){let a=t===void 0?e.defaultPreset:t,l=[{name:"application defaults",options:e.defaults}];for(let i of Te(a)){let m=e.presets[i];if(!m){let d={code:"UNKNOWN_PRESET",preset:i,message:`[MachTable] Unknown preset "${i}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}l.push({name:`preset:${i}`,options:m})}l.push({name:"table props",options:n});let s={rowNumber:!0,...D(...l.map(i=>i.options))};return{options:s,explain(i){let m=l.filter(g=>Object.prototype.hasOwnProperty.call(g.options,i)).map(g=>({name:g.name,value:g.options[i]})),d=m[m.length-1];return{key:i,value:s[i],source:d?.name??"MachTable built-in",layers:m}}}}export{fe as GRID_OPTION_KEYS,pe as GRID_OPTION_META,de as beginGridInput,se as canReplaceGridData,ne as createSelectControl,R as equivalentConfigValue,X as equivalentGridOption,ve as mergeMachTableConfig,q as normalizeMachTableConfig,ae as readGridCell,De as resolveMachTableGridOptions,re as resumeGrid,oe as suspendGrid,ie as writeGridInput};
|
|
1
|
+
function R(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function k(e,t,n=2){if(Object.is(e,t))return!0;if(n<=0)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length||e.length>100?!1:e.every((r,l)=>k(r,t[l],n-1));if(!K(e)||!K(t))return!1;let o=Object.keys(e);return o.length!==Object.keys(t).length||o.length>100?!1:o.every(r=>R(t,r)&&k(e[r],t[r],n-1))}function K(e){if(!e||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}var X=new Set(["defaultColDef","locale","components","columnTypes","aggFuncs","pagination","statusBar","watermark"]);function ee(e,t,n){return Object.is(t,n)||X.has(e)&&k(t,n,3)}function y(e,t,n){let o=document.createElement(e);if(t&&(o.className=t),n)for(let r of Object.keys(n))o.setAttribute(r,n[r]);return o}function te(e,t,n,o=!1){let r=t?"addEventListener":"removeEventListener";for(let[l,s]of Object.entries(n))e[r](l,s,o)}function F(e,t,n){te(document,e,{mousedown:t,keydown:n},!0)}function _(e,t){if(e.classList.add("mach-portal"),!t)return;let n=window.getComputedStyle(t);for(let o=0;o<n.length;o++){let r=n.item(o);if(!r.startsWith("--mach-"))continue;let l=n.getPropertyValue(r).trim();l&&e.style.setProperty(r,l)}e.style.colorScheme=n.colorScheme}function W(e,t,n){return e<t?t:e>n?n:e}var H=0;function B(e="rg"){return H++,`${e}-${H}`}var p=null;function z(e){p?.owner&&(e===p.owner||e.contains(p.owner))&&p.close()}function ne(e){let t=e.target;p?.contains(t)||p?.close()}function V(){p?.reposition()}function oe(e){e.key!=="Escape"||!p||(e.preventDefault(),e.stopImmediatePropagation(),p.close(!0))}function $(e){F(e,ne,oe);let t=e?"addEventListener":"removeEventListener";window[t]("resize",V),window[t]("scroll",V,!0)}function re(e){p?.close!==e.close&&p?.close(),!p&&(p=e,$(!0))}function ie(e){p?.close===e&&(p=null,$(!1))}function T(e,t){return t?`${e} ${t}`:e}function x(e,t,n){let o=e[t]&&!e[t].disabled,r=o?t+n:n>0?0:e.length-1;for(let l=r;l>=0&&l<e.length;l+=n)if(!e[l].disabled)return l;return o?t:-1}function E(e,t){return e.findIndex(n=>n.value===t&&!n.disabled)}function ae(e){let t=y("div",T("mach-select-control",e.classNames?.root)),n=y("select",T("mach-select-native",e.classNames?.native));n.hidden=!0,n.tabIndex=-1,n.setAttribute("aria-hidden","true");let o=y("button",T("mach-select-trigger",e.classNames?.trigger));o.type="button",o.setAttribute("role","combobox"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",e.ariaLabel);let r=y("span",T("mach-select-value",e.classNames?.value)),l=y("span",T("mach-select-caret",e.classNames?.caret));l.setAttribute("aria-hidden","true"),o.append(r,l);let s=y("div",T("mach-select-listbox",e.classNames?.listbox));s.id=B("mach-select-listbox"),s.setAttribute("role","listbox"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-controls",s.id),t.append(n,o);let a=[...e.options],m=[],d=-1,b=!1,J=()=>e.themeSource??t.closest(".mach-root")??t,S=i=>t.contains(i)||s.contains(i),O=()=>s.classList.contains("mach-select-listbox--open"),w=()=>{let i=a.find(c=>c.value===n.value);r.textContent=i?.label??n.value,m.forEach((c,v)=>{let u=a[v]?.value===n.value;c.setAttribute("aria-selected",u?"true":"false"),c.classList.toggle("mach-select-option--selected",u),c.classList.toggle("mach-select-option--active",v===d)}),o.setAttribute("aria-activedescendant",d>=0?m[d]?.id??"":"")},A=()=>{let i=o.getBoundingClientRect(),c=s.getBoundingClientRect(),v=Math.max(i.width,c.width),u=W(i.left,8,Math.max(8,window.innerWidth-v-8)),C=window.innerHeight-i.bottom-8,h=C<Math.min(c.height,240)&&i.top>C,f=h?Math.max(8,i.top-c.height-5):Math.min(window.innerHeight-c.height-8,i.bottom+5);s.style.minWidth=`${i.width}px`,s.style.left=`${u}px`,s.style.top=`${Math.max(8,f)}px`,s.classList.toggle("mach-select-listbox--above",h)},g=(i=!1)=>O()?(s.classList.remove("mach-select-listbox--open","mach-select-listbox--above"),s.setAttribute("aria-hidden","true"),o.setAttribute("aria-expanded","false"),o.removeAttribute("aria-activedescendant"),s.remove(),ie(g),i&&!b&&o.focus({preventScroll:!0}),!0):!1,Z=(i,c=!0)=>{!a[i]||a[i].disabled||(d=i,w(),c&&m[i]?.scrollIntoView?.({block:"nearest"}))},G=()=>{if(b||o.disabled||O())return;let i=J();re({owner:i,close:g,contains:S,reposition:A}),d=E(a,n.value),d<0&&(d=x(a,-1,1)),_(s,i),document.body.appendChild(s),s.classList.add("mach-select-listbox--open"),s.setAttribute("aria-hidden","false"),o.setAttribute("aria-expanded","true"),A(),w(),m[d]?.scrollIntoView?.({block:"nearest"})},I=i=>{let c=a[i];!c||c.disabled||(n.value=c.value,d=i,w(),g(!0),n.dispatchEvent(new Event("input",{bubbles:!0})),n.dispatchEvent(new Event("change",{bubbles:!0})))},L=(i,c)=>{a=[...i],n.replaceChildren(),s.replaceChildren(),m=a.map((u,C)=>{let h=document.createElement("option");h.value=u.value,h.textContent=u.label,h.disabled=u.disabled===!0,n.appendChild(h);let f=y("button",T("mach-select-option",e.classNames?.option));return f.id=`${s.id}-option-${C}`,f.type="button",f.tabIndex=-1,f.dataset.value=u.value,f.disabled=u.disabled===!0,f.setAttribute("role","option"),f.textContent=u.label,f.addEventListener("mousedown",Q=>Q.preventDefault()),f.addEventListener("click",()=>I(C)),s.appendChild(f),f});let v=a.find(u=>!u.disabled)?.value??"";n.value=c!=null&&a.some(u=>u.value===c)?c:v,d=E(a,n.value),w()},N=i=>{if(i.key==="Tab"){g();return}if(i.key==="Escape"){if(!g(!0))return;i.preventDefault(),i.stopPropagation();return}if(i.key==="Enter"||i.key===" "){i.preventDefault(),i.stopPropagation(),O()?I(d):G();return}let c=d;if(i.key==="ArrowDown")c=x(a,d,1);else if(i.key==="ArrowUp")c=x(a,d,-1);else if(i.key==="Home")c=x(a,-1,1);else if(i.key==="End")c=x(a,-1,-1);else return;i.preventDefault(),i.stopPropagation(),O()||G(),Z(c)},j=()=>{d=E(a,n.value),w(),e.onChange?.(n.value)};return o.addEventListener("click",()=>{g()||G()}),o.addEventListener("keydown",N),n.addEventListener("change",j),L(a,e.value),{el:t,native:n,trigger:o,listbox:s,contains:S,isOpen:O,open:G,close:g,focus:()=>o.focus({preventScroll:!0}),getValue:()=>n.value,setValue:i=>{n.value=i,d=E(a,i),w()},setOptions:L,destroy:()=>{b||(b=!0,g(),o.removeEventListener("keydown",N),n.removeEventListener("change",j),t.remove())}}}var M=Symbol.for("mach-table.adapter.lifecycle.v1");function se(e){if(e.isDestroyed())return;let t=e.view.getRoot();t&&z(t),e[M]?.suspend()}function le(e){e.isDestroyed()||e[M]?.resume()}function ce(e,t,n){return e.isDestroyed()?"":e[M]?.readCell(t,n)??""}function de(e,t){e.isDestroyed()||e[M]?.writeInput(t)}function ue(e){return!e.isDestroyed()&&(e[M]?.canReplaceData()??!1)}var pe=Symbol.for("mach-table.import.v1");function fe(e){let t=e[pe];if(!t)throw new TypeError("Import plans require a MachTable GridApi");return t}function me(e){return e.isDestroyed()?()=>!1:fe(e).begin()}var U={columnDefs:"array",rowData:"array",defaultColDef:"object",columnTypes:"object",rowKey:"unknown",rowHeight:"number",headerHeight:"number",rowBuffer:"number",columnLayout:"string",enableColumnResize:"boolean",domLayout:"string",maxBodyHeight:"number",rowSelection:"string",multiSort:"boolean",size:"string",stripedRows:"boolean",rowStyleRules:"array",showCellBorders:"boolean",theme:"string",quickFilterText:"string",advancedFilterModel:"object",masterDetail:"boolean",detailRowHeight:"number",detailRowRenderer:"function",isRowExpandable:"function",detailToggleColumn:"boolean",columnMenu:"boolean",aggFuncs:"object",components:"object",actionPolicy:"object",features:"array",initialState:"object",persistence:"boolean-object",locale:"object",editType:"string",editableIndicator:"string",rowEditValidator:"function",singleClickEdit:"boolean",manualSorting:"boolean",manualFiltering:"boolean",showSummary:"boolean",summaryMethod:"function",treeData:"boolean",childrenKey:"string",isTreeRowExpandable:"function",loadTreeChildren:"function",autoCheckedChildren:"boolean",defaultExpandAll:"boolean",rowNumber:"boolean",indexOffset:"number",applyRowDrag:"boolean",rowDragPolicy:"object",undoStackSize:"number",asyncTransactionWaitMillis:"number",getRowHeight:"function",pinnedTopRowData:"array",pinnedBottomRowData:"array",pagination:"boolean-object",watermark:"boolean-object",suppressWarnings:"boolean",enableRangeSelection:"boolean",suppressClipboard:"boolean",contextMenu:"boolean",getContextMenuItems:"function",tooltipComponent:"function",tooltipShowDelay:"number",flashCells:"boolean",fillHandle:"boolean",statusBar:"boolean-object",datasource:"object",datasourceMode:"string",blockSize:"number",infiniteBufferRows:"number",maxBlocksInCache:"number",datasourceMaxConcurrentRequests:"number",blockPrefetch:"number",datasourceRowCount:"number",dataProcessor:"object-function",dataProcessorMinRows:"number",datasourceRetryCount:"number",datasourceRetryDelay:"number",datasourceRetryJitter:"number",suppressCellFocus:"boolean",suppressRowHoverHighlight:"boolean",suppressNoRowsOverlay:"boolean",suppressHeaderFocus:"boolean",ariaLabel:"string",ariaLabelledBy:"string",ariaDescribedBy:"string",loading:"boolean",error:"unknown",overlayNoRowsTemplate:"unknown",overlayLoadingTemplate:"unknown",overlayErrorTemplate:"unknown",allowUnsafeOverlayHtml:"boolean",className:"string"};function be(){return Object.fromEntries(Object.entries(U).map(([e,t])=>[e,{kind:t,update:e==="columnDefs"||e==="rowData"?e:e==="quickFilterText"?"quickFilter":"options"}]))}var ge=be(),ye=Object.freeze(Object.keys(U));function P(e,t){return t===void 0?e:typeof t!="object"||t===null||typeof e!="object"||e===null?t:{...e,...t}}function he(e,t){return typeof e!="function"?t:typeof t!="function"?e:(...n)=>{let o;try{e(...n)}catch(r){o=r}try{t(...n)}catch(r){o??(o=r)}if(o!==void 0)throw o}}function Te(e,t){if(!(!e.components&&!t.components))return{cellRenderers:{...e.components?.cellRenderers,...t.components?.cellRenderers},cellEditors:{...e.components?.cellEditors,...t.components?.cellEditors}}}function we(e,t){if(!e.columnTypes&&!t.columnTypes)return;let n={},o=new Set([...Object.keys(e.columnTypes??{}),...Object.keys(t.columnTypes??{})]);for(let r of o)n[r]={...e.columnTypes?.[r],...t.columnTypes?.[r]};return n}function ve(e,t,n){for(let o of new Set([...Object.keys(t),...Object.keys(n)])){if(!/^on[A-Z]/.test(o))continue;let r=t[o],l=n[o];typeof r!="function"||typeof l!="function"||(e[o]=he(r,l))}}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=Te(e,t);o&&(n.components=o);let r=we(e,t);return r&&(n.columnTypes=r),(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),ve(n,e,t),n}function D(...e){return e.reduce(De,{})}function Oe(e){return e?(Array.isArray(e)?e:[e]).filter(t=>typeof t=="string"&&t.trim().length>0):[]}var Ce=["rowData","columnDefs","datasource","loading","error","initialState","persistence","components","columnTypes","stateKey","stateStore","stateSaveDebounceMs","columnStateKey","columnStateStore"];function q(e,t,n){if(!t||typeof t!="object"||Array.isArray(t))return{};let o={};for(let[r,l]of Object.entries(t)){if(!Ce.includes(r)&&(r!=="dataProcessor"||l==null||typeof l=="function")){o[r]=l;continue}let s={code:n==="defaults"?"INVALID_DEFAULT_OPTION":"INVALID_PRESET_OPTION",option:r,layer:n,message:r==="dataProcessor"?`[MachTable] "dataProcessor" in config ${n} must be a factory returning a fresh per-grid instance.`:`[MachTable] "${r}" is instance-only and cannot be declared in config ${n}.`};if(e.onConfigWarning?.(s),e.strict!==!1)throw new TypeError(s.message)}return o}function Y(e={}){let t=q(e,e.defaults,"defaults");return{defaults:D({columnTypes:e.columnTypes,components:e.components},t),presets:Object.fromEntries(Object.entries(e.presets??{}).map(([n,o])=>[n,D(q(e,o,`preset:${n}`))])),defaultPreset:e.defaultPreset??!1,strict:e.strict!==!1,...e.onConfigWarning?{onConfigWarning:e.onConfigWarning}:{}}}function xe(e,t){let n=Y({...t,strict:t.strict??e.strict,onConfigWarning:t.onConfigWarning??e.onConfigWarning}),o={...e.presets};for(let[r,l]of Object.entries(n.presets))o[r]=D(e.presets[r]??{},l);return{defaults:D(e.defaults,n.defaults),presets:o,defaultPreset:t.defaultPreset===void 0?e.defaultPreset:t.defaultPreset,strict:t.strict??e.strict,...t.onConfigWarning??e.onConfigWarning?{onConfigWarning:t.onConfigWarning??e.onConfigWarning}:{}}}function Me(e,t,n,o){let r=t===void 0?e.defaultPreset:t,l=[{name:"application defaults",options:e.defaults}];for(let a of Oe(r)){let m=e.presets[a];if(!m){let d={code:"UNKNOWN_PRESET",preset:a,message:`[MachTable] Unknown preset "${a}". Register it in mach-table.config.ts or remove the preset.`};o?o(d):e.onConfigWarning?e.onConfigWarning(d):console.warn(d.message);continue}l.push({name:`preset:${a}`,options:m})}l.push({name:"table props",options:n});let s={rowNumber:!0,...D(...l.map(a=>a.options))};return{options:s,explain(a){let m=l.filter(b=>R(b.options,a)).map(b=>({name:b.name,value:b.options[a]})),d=m[m.length-1];return{key:a,value:s[a],source:d?.name??"MachTable built-in",layers:m}}}}export{ye as GRID_OPTION_KEYS,ge as GRID_OPTION_META,me as beginGridInput,ue as canReplaceGridData,ae as createSelectControl,k as equivalentConfigValue,ee as equivalentGridOption,xe as mergeMachTableConfig,Y as normalizeMachTableConfig,ce as readGridCell,Me as resolveMachTableGridOptions,le as resumeGrid,se as suspendGrid,de as writeGridInput};
|
package/dist/analysis.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var D=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(t,e)=>{for(var n in e)D(t,n,{get:e[n],enumerable:!0})},le=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!se.call(t,o)&&o!==n&&D(t,o,{get:()=>e[o],enumerable:!(r=oe(e,o))||r.enumerable});return t};var ue=t=>le(D({},"__esModule",{value:!0}),t);var Ee={};ae(Ee,{createPivot:()=>C,evaluateFormulas:()=>S,mountAnalysis:()=>re});module.exports=ue(Ee);var ce=new Set(["__proto__","prototype","constructor"]),M=new Map;function G(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ce.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function k(t){return G(t)!==null}function x(t,e){if(t==null)return;let n=G(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function U(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function V(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function B(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var de=new Set(["sum","count","avg","min","max"]);function Y(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function W(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function me(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!k(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){fe(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function fe(t){if(!de.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!k(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function z(t,e,n){let r=t.get(e);r||(r=U(),t.set(e,r)),V(r,n)}function pe(t,e){return JSON.stringify([t===null?"total":Y(t),e.field??null,e.aggregate])}function C(t,e){me(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>W(x(s,p))),f=Y(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>W(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;K(d,r,o,h,p,g),i.length&&K(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)q(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:X(a,u.cells)}));return{columns:a,rows:l,totals:X(a,o),inputCount:t.length}}function q(t,e,n){let r=pe(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function K(t,e,n,r,o,i){let a=q(e,r,o);z(t.cells,a,i),z(n,a,i)}function X(t,e){let n=Object.create(null);for(let r of t)n[r.id]=B(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},J={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},he=new Set(["SUM","MIN","MAX","AVG"]);function ge(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ve(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ve(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function Z(t){let e=ge(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(J,d)?J[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!he.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function E(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function be(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return E(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return E((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return E(be(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return E(t.name==="AVG"?r/n.length:r)}function S(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!k(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,Z(l))}catch(s){r.set(a,Q(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=we(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Q(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function ye(t,e){if(!k(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return E(n)}function we(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return ye(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=E(T(l,o));return n.set(i,s),s}catch(l){let s=Q(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function ee(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function te(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",ee(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function ne(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],O=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,I)=>{let R=b.values[e];if(R==null){O();return}let N=55+v*(I+.5),F=p(R),$=b.dimensions.map(j=>j==null?"\u7A7A\u503C":String(j)).join(" / ")||"\u5168\u90E8",H=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});H.append(y("title",{},`${$}: ${R}`)),l.append(H),n==="line"&&P.push(`${N},${F}`),(i.length<=10||I%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},$.slice(0,12)))}),O(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var xe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function re(t,e){return new L(t,e)}var L=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=te(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(xe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=S(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
1
|
+
"use strict";var L=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(t,e)=>{for(var n in e)L(t,n,{get:e[n],enumerable:!0})},le=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!se.call(t,o)&&o!==n&&L(t,o,{get:()=>e[o],enumerable:!(r=oe(e,o))||r.enumerable});return t};var ue=t=>le(L({},"__esModule",{value:!0}),t);var Ee={};ae(Ee,{createPivot:()=>C,evaluateFormulas:()=>R,mountAnalysis:()=>re});module.exports=ue(Ee);var ce=new Set(["__proto__","prototype","constructor"]),M=new Map;function G(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ce.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function k(t){return G(t)!==null}function x(t,e){if(t==null)return;let n=G(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function U(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function V(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function B(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var de=new Set(["sum","count","avg","min","max"]);function Y(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function W(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function me(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!k(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){fe(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function fe(t){if(!de.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!k(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function K(t,e,n){let r=t.get(e);r||(r=U(),t.set(e,r)),V(r,n)}function pe(t,e){return JSON.stringify([t===null?"total":Y(t),e.field??null,e.aggregate])}function C(t,e){me(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>W(x(s,p))),f=Y(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>W(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;z(d,r,o,h,p,g),i.length&&z(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)q(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:X(a,u.cells)}));return{columns:a,rows:l,totals:X(a,o),inputCount:t.length}}function q(t,e,n){let r=pe(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function z(t,e,n,r,o,i){let a=q(e,r,o);K(t.cells,a,i),K(n,a,i)}function X(t,e){let n=Object.create(null);for(let r of t)n[r.id]=B(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},J={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},he=new Set(["SUM","MIN","MAX","AVG"]);function ge(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ve(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ve(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function Z(t){let e=ge(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(J,d)?J[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!he.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function E(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function be(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return E(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return E((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return E(be(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return E(t.name==="AVG"?r/n.length:r)}function R(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!k(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,Z(l))}catch(s){r.set(a,Q(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=we(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Q(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function ye(t,e){if(!k(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return E(n)}function we(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return ye(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=E(T(l,o));return n.set(i,s),s}catch(l){let s=Q(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function ee(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function te(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",ee(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function ne(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],O=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,I)=>{let S=b.values[e];if(S==null){O();return}let N=55+v*(I+.5),F=p(S),$=b.dimensions.map(j=>j==null?"\u7A7A\u503C":String(j)).join(" / ")||"\u5168\u90E8",H=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});H.append(y("title",{},`${$}: ${S}`)),l.append(H),n==="line"&&P.push(`${N},${F}`),(i.length<=10||I%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},$.slice(0,12)))}),O(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var xe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function re(t,e){return new D(t,e)}var D=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=te(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(xe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=R(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
2
2
|
${l.join(`
|
|
3
3
|
`)}`)}this.f(r),this.result=C(o.rows,this.config),this.page=0,this.refresh();let i=this.options.api.rows.isRemote()?"\u8FDC\u7A0B\u6A21\u5F0F\u4EC5\u5305\u542B\u5DF2\u52A0\u8F7D\u884C\uFF0C\u4E0D\u4EE3\u8868\u670D\u52A1\u7AEF\u5168\u91CF\u3002":"",a=n>e.length?`\u5DF2\u52A0\u8F7D ${n} \u884C\uFF0C\u672C\u6B21\u4EC5\u5206\u6790\u524D ${e.length} \u884C\u3002`:`\u5206\u6790\u5DF2\u52A0\u8F7D\u7684 ${e.length} \u884C\u3002`;this.e.status.textContent=`${a}${i} \u751F\u6210 ${this.result.rows.length} \u4E2A\u884C\u7EC4\u3001${this.result.columns.length} \u4E2A\u7ED3\u679C\u5217\u3002`,this.e.status.classList.remove("mach-workbench__status--error"),this.e.status.setAttribute("role","status")}catch(r){this.result=null,this.results.replaceChildren(),this.e.status.textContent=r instanceof Error?r.message:String(r),this.e.status.classList.add("mach-workbench__status--error"),this.e.status.setAttribute("role","alert")}}m(){let e=Object.create(null);for(let n of this.formulas){if(!n.field||Object.prototype.hasOwnProperty.call(e,n.field))throw new Error("\u516C\u5F0F\u7ED3\u679C\u5217\u4E0D\u80FD\u4E3A\u7A7A\u6216\u91CD\u590D");e[n.field]=n.expression}return e}f(e){let n=new Set([...this.l().map(o=>o.field),...Object.keys(e)]),r=[...this.config.rowFields,...this.config.columnFields??[],...this.config.values.flatMap(o=>o.field?[o.field]:[])];for(let o of r)if(!n.has(o))throw new Error(`\u5B57\u6BB5\u5DF2\u79FB\u9664\u6216\u4E0D\u53EF\u5206\u6790\uFF1A${o}`)}n(){if(this.results.replaceChildren(),!this.result)return;let e=this.result;e.columns.some(l=>l.id===this.t)||(this.t=e.columns[0]?.id??"");let n=c("div","mach-workbench__tools");n.append(A("\u56FE\u8868\u7C7B\u578B",[{value:"bar",label:"\u67F1\u72B6\u56FE"},{value:"line",label:"\u6298\u7EBF\u56FE"}],this.o,l=>{this.o=l,this.n(),_(this.results,"\u56FE\u8868\u7C7B\u578B")}),A("\u56FE\u8868\u6307\u6807",e.columns.map(l=>({value:l.id,label:l.label})),this.t,l=>{this.t=l,this.n(),_(this.results,"\u56FE\u8868\u6307\u6807")})),this.results.append(n,ne(e,this.t,this.o),this.table(e));let r=Math.max(1,Math.ceil(e.rows.length/50)),o=c("nav","mach-workbench__tools");o.setAttribute("aria-label","\u5206\u6790\u7ED3\u679C\u5206\u9875");let i=w("\u4E0A\u4E00\u9875",()=>{this.page--,this.n(),_(this.results.querySelector("nav"),"\u4E0A\u4E00\u9875")}),a=w("\u4E0B\u4E00\u9875",()=>{this.page++,this.n(),_(this.results.querySelector("nav"),"\u4E0B\u4E00\u9875")});i.disabled=this.page<=0,a.disabled=this.page>=r-1,o.append(i,c("span",void 0,`\u7B2C ${this.page+1} / ${r} \u9875 \xB7 \u6BCF\u9875 50 \u7EC4`),a),this.results.append(o)}table(e){let n=c("div","mach-analysis__table-wrap"),r=c("table","mach-analysis__table");r.append(c("caption",void 0,"\u900F\u89C6\u7ED3\u679C\u6570\u636E\u8868\uFF08\u5B8C\u6574\u7ED3\u679C\u53EF\u5206\u9875\u67E5\u770B\uFF09"));let o=c("thead"),i=c("tr");for(let s of["\u884C\u7EF4\u5EA6",...e.columns.map(u=>u.label)]){let u=c("th",void 0,s);u.scope="col",i.append(u)}o.append(i);let a=c("tbody");for(let s of e.rows.slice(this.page*50,(this.page+1)*50))a.append(this.u(s.dimensions.map(u=>u==null?"\u7A7A\u503C":String(u)).join(" / ")||"\u5168\u90E8",e,s.values));let l=c("tfoot");return l.append(this.u("\u5408\u8BA1",e,e.totals)),r.append(o,a,l),n.append(r),n}u(e,n,r){let o=c("tr"),i=c("th",void 0,e);i.scope="row",o.append(i);for(let a of n.columns){let l=r[a.id],s=c("td",void 0,l==null?"\u2014":l.toLocaleString("zh-CN",{maximumFractionDigits:6}));s.title=l==null?"\u65E0\u6570\u503C":String(l),o.append(s)}return o}};0&&(module.exports={createPivot,evaluateFormulas,mountAnalysis});
|
package/dist/analysis.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-
|
|
2
|
-
import './api-
|
|
1
|
+
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-BIBSfPcs.cjs';
|
|
2
|
+
import './api-ChEKWrvH.cjs';
|
|
3
3
|
|
|
4
4
|
type PivotAggregate = "sum" | "count" | "avg" | "min" | "max";
|
|
5
5
|
type PivotDimension = string | number | boolean | null;
|
package/dist/analysis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-
|
|
2
|
-
import './api-
|
|
1
|
+
import { W as WorkbenchOptions, a as WorkbenchHandle } from './shared-Qnznvth3.js';
|
|
2
|
+
import './api-ChEKWrvH.js';
|
|
3
3
|
|
|
4
4
|
type PivotAggregate = "sum" | "count" | "avg" | "min" | "max";
|
|
5
5
|
type PivotDimension = string | number | boolean | null;
|
package/dist/analysis.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var ne=new Set(["__proto__","prototype","constructor"]),M=new Map;function j(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ne.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function k(t){return j(t)!==null}function x(t,e){if(t==null)return;let n=j(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function G(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function U(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function V(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var re=new Set(["sum","count","avg","min","max"]);function X(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function B(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function oe(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!k(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){ie(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function ie(t){if(!re.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!k(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function W(t,e,n){let r=t.get(e);r||(r=G(),t.set(e,r)),U(r,n)}function se(t,e){return JSON.stringify([t===null?"total":X(t),e.field??null,e.aggregate])}function S(t,e){oe(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>B(x(s,p))),f=X(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>B(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;z(d,r,o,h,p,g),i.length&&z(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)Y(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:K(a,u.cells)}));return{columns:a,rows:l,totals:K(a,o),inputCount:t.length}}function Y(t,e,n){let r=se(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function z(t,e,n,r,o,i){let a=Y(e,r,o);W(t.cells,a,i),W(n,a,i)}function K(t,e){let n=Object.create(null);for(let r of t)n[r.id]=V(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},q={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},ae=new Set(["SUM","MIN","MAX","AVG"]);function le(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ue(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ue(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function J(t){let e=le(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(q,d)?q[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!ae.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function E(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function ce(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return E(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return E((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return E(ce(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return E(t.name==="AVG"?r/n.length:r)}function R(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!k(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,J(l))}catch(s){r.set(a,Z(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=me(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Z(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function de(t,e){if(!k(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return E(n)}function me(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return de(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=E(T(l,o));return n.set(i,s),s}catch(l){let s=Z(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function Q(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function ee(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",Q(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function te(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],L=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,O)=>{let C=b.values[e];if(C==null){L();return}let N=55+v*(O+.5),F=p(C),I=b.dimensions.map(H=>H==null?"\u7A7A\u503C":String(H)).join(" / ")||"\u5168\u90E8",$=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});$.append(y("title",{},`${I}: ${C}`)),l.append($),n==="line"&&P.push(`${N},${F}`),(i.length<=10||O%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},I.slice(0,12)))}),L(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var fe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function pe(t,e){return new D(t,e)}var D=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=ee(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(fe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=R(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
1
|
+
var ne=new Set(["__proto__","prototype","constructor"]),M=new Map;function j(t){if(typeof t!="string"||t.length===0)return null;let e=M.get(t);if(e!==void 0)return e;let n=t.split("."),r=n.every(o=>o.length>0&&!ne.has(o))?n:null;return t.length<=1024&&(M.size>=256&&M.delete(M.keys().next().value),M.set(t,r)),r}function k(t){return j(t)!==null}function x(t,e){if(t==null)return;let n=j(e);if(!n)return;let r=t;for(let o of n){if(r==null)return;r=r[o]}return r}function G(){return{count:0,numeric:0,sum:0,min:1/0,max:-1/0}}function U(t,e){t.count++,!(typeof e!="number"||!Number.isFinite(e))&&(t.numeric++,t.sum+=e,t.min=Math.min(t.min,e),t.max=Math.max(t.max,e))}function V(t,e){return e==="count"?t?.count??0:t?.numeric?e==="min"?t.min:e==="max"?t.max:Number.isFinite(t.sum)?e==="avg"?t.sum/t.numeric:t.sum:null:null}var re=new Set(["sum","count","avg","min","max"]);function X(t){return JSON.stringify(t.map(e=>[e===null?"null":typeof e,e]))}function B(t){if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;if(typeof t=="string"||typeof t=="boolean")return t;if(t instanceof Date&&!Number.isNaN(t.getTime()))return t.toISOString();throw new TypeError("Pivot dimensions must be primitive values or valid Dates")}function oe(t,e){if(t.length>1e4)throw new RangeError("Pivot supports at most 10000 input rows; aggregate remotely for larger datasets");let n=[...e.rowFields,...e.columnFields??[]];if(n.length>12||e.values.length>16||!e.values.length)throw new RangeError("Pivot supports 12 dimensions and 1\u201316 measures");for(let o of n)if(!k(o))throw new TypeError(`Invalid pivot field: ${o}`);let r=new Set;for(let o of e.values){ie(o);let i=JSON.stringify([o.field??null,o.aggregate]);if(r.has(i))throw new TypeError("Duplicate pivot measure");r.add(i)}}function ie(t){if(!re.has(t.aggregate))throw new TypeError(`Unknown pivot aggregate: ${String(t.aggregate)}`);if(t.field!=null&&!k(t.field))throw new TypeError(`Invalid pivot field: ${t.field}`);if(!t.field&&t.aggregate!=="count")throw new TypeError("Numeric pivot measures require a field")}function W(t,e,n){let r=t.get(e);r||(r=G(),t.set(e,r)),U(r,n)}function se(t,e){return JSON.stringify([t===null?"total":X(t),e.field??null,e.aggregate])}function R(t,e){oe(t,e);let n=new Map,r=new Map,o=new Map,i=e.columnFields??[];for(let s of t){let u=e.rowFields.map(p=>B(x(s,p))),f=X(u),d=n.get(f);if(d||(d={dimensions:u,cells:new Map},n.set(f,d)),n.size>2e3)throw new RangeError("Pivot supports at most 2000 result row groups");let h=i.map(p=>B(x(s,p)));for(let p of e.values){let g=p.field?x(s,p.field):void 0;K(d,r,o,h,p,g),i.length&&K(d,r,o,null,p,g)}if(r.size>128)throw new RangeError("Pivot supports at most 128 result columns")}if(!t.length&&!i.length)for(let s of e.values)Y(r,[],s);let a=[...r.values()].sort((s,u)=>Number(s.total)-Number(u.total)||s.id.localeCompare(u.id)),l=[...n.entries()].sort(([s],[u])=>s.localeCompare(u)).map(([s,u])=>({id:s,dimensions:u.dimensions,values:z(a,u.cells)}));return{columns:a,rows:l,totals:z(a,o),inputCount:t.length}}function Y(t,e,n){let r=se(e,n);if(!t.has(r)){let o=n.label??`${n.field??"\u8BB0\u5F55"} \xB7 ${n.aggregate}`,i=e===null?"\u5408\u8BA1":e.map(a=>a==null?"\u7A7A\u503C":String(a)).join(" / ");t.set(r,{id:r,label:i?`${i} / ${o}`:o,dimensions:e??[],total:e===null,measure:{...n}})}return r}function K(t,e,n,r,o,i){let a=Y(e,r,o);W(t.cells,a,i),W(n,a,i)}function z(t,e){let n=Object.create(null);for(let r of t)n[r.id]=V(e.get(r.id),r.measure.aggregate);return n}var m=class extends Error{constructor(n,r){super(r);this.code=n}},q={"+":1,"-":1,"*":2,"/":2,"%":2,"^":3},ae=new Set(["SUM","MIN","MAX","AVG"]);function le(t){if(t.length>4096)throw new m("LIMIT","Formula exceeds 4096 characters");let e=[],n=t.startsWith("=")?1:0;for(;n<t.length;){if(/\s/.test(t[n])){n++;continue}let r=ue(t.slice(n));if(e.push(r),n+=r.kind==="field"?r.value.length+2:r.value.length,e.length>256)throw new m("LIMIT","Formula exceeds 256 tokens")}return e}function ue(t){let e=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?/i.exec(t);if(e)return{kind:"number",value:e[0]};let n=/^\[([^\]\r\n]+)\]/.exec(t);if(n)return{kind:"field",value:n[1]};let r=/^[A-Za-z_\u4e00-\u9fff][\w.\u4e00-\u9fff]*/.exec(t);if(r)return{kind:"name",value:r[0]};if("+-*/%^(),".includes(t[0]))return{kind:"symbol",value:t[0]};throw new m("SYNTAX",`Unexpected token: ${t.slice(0,12)}`)}function J(t){let e=le(t),n=0,r=s=>{if(e[n++]?.value!==s)throw new m("SYNTAX",`Expected ${s}`)},o=(s,u)=>{if(u>32)throw new m("LIMIT","Formula exceeds 32 nesting levels");let f=a(u);for(;n<e.length;){let d=e[n].value,h=Object.prototype.hasOwnProperty.call(q,d)?q[d]:void 0;if(h==null||h<s)break;n++;let p=o(h+(d==="^"?0:1),u+1);f={kind:"binary",operator:d,left:f,right:p}}return f},i=(s,u)=>{let f=s.toUpperCase();if(!ae.has(f))throw new m("SYNTAX",`Unsupported function: ${s}`);r("(");let d=[];if(e[n]?.value!==")")do d.push(o(0,u+1));while(e[n]?.value===","&&++n);if(r(")"),!d.length&&f!=="SUM")throw new m("SYNTAX",`${f} requires arguments`);return{kind:"call",name:f,args:d}},a=s=>{let u=e[n++];if(!u)throw new m("SYNTAX","Expected a value");if(u.kind==="number")return{kind:"number",value:Number(u.value)};if(u.kind==="field")return{kind:"field",name:u.value};if(u.kind==="name")return e[n]?.value==="("?i(u.value,s):{kind:"field",name:u.value};if(u.value==="+"||u.value==="-")return{kind:"unary",operator:u.value,operand:o(3,s+1)};if(u.value==="("){let f=o(0,s+1);return r(")"),f}throw new m("SYNTAX",`Unexpected token: ${u.value}`)},l=o(0,0);if(n!==e.length)throw new m("SYNTAX","Unexpected trailing tokens");return l}function E(t){if(!Number.isFinite(t))throw new m("NON_FINITE","Formula result is not a finite number");return t}function ce(t,e,n){if((t==="/"||t==="%")&&n===0)throw new m("DIV_ZERO","Division by zero");return t==="+"?e+n:t==="-"?e-n:t==="*"?e*n:t==="/"?e/n:t==="%"?e%n:e**n}function T(t,e){if(t.kind==="number")return E(t.value);if(t.kind==="field")return e(t.name);if(t.kind==="unary")return E((t.operator==="-"?-1:1)*T(t.operand,e));if(t.kind==="binary")return E(ce(t.operator,T(t.left,e),T(t.right,e)));let n=t.args.map(o=>T(o,e));if(t.name==="MIN")return Math.min(...n);if(t.name==="MAX")return Math.max(...n);let r=n.reduce((o,i)=>o+i,0);return E(t.name==="AVG"?r/n.length:r)}function S(t,e){let n=Object.entries(e);if(n.length>32||t.length>1e4||n.length*t.length>1e5)throw new m("LIMIT","Formulas support 32 columns, 10000 rows and 100000 result cells");let r=new Map;for(let[a,l]of n){if(!k(a)||/[.\[\]]/.test(a))throw new m("SYNTAX",`Invalid formula column: ${a}; use a single-level ID without dots or brackets`);try{r.set(a,J(l))}catch(s){r.set(a,Z(s))}}let o=[];return{rows:t.map((a,l)=>{let s={...a},u=me(a,r);for(let[f,d]of u)d instanceof m&&o.push({rowIndex:l,colId:f,code:d.code,message:d.message}),Object.defineProperty(s,f,{value:d instanceof m?null:d,enumerable:!0,configurable:!0,writable:!0});return s}),errors:o}}function Z(t){return t instanceof m?t:new m("SYNTAX",t instanceof Error?t.message:String(t))}function de(t,e){if(!k(e))throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);let n=x(t,e);if(n===void 0)throw new m("UNKNOWN_FIELD",`Unknown field: ${e}`);if(typeof n!="number")throw new m("NON_NUMERIC",`Field is not numeric: ${e}`);return E(n)}function me(t,e){let n=new Map,r=new Set,o=i=>{if(!e.has(i))return de(t,i);let a=n.get(i);if(a instanceof m)throw a;if(a!=null)return a;if(r.has(i))throw new m("CYCLE",`Cyclic formula: ${[...r,i].join(" \u2192 ")}`);r.add(i);try{let l=e.get(i);if(l instanceof m)throw l;let s=E(T(l,o));return n.set(i,s),s}catch(l){let s=Z(l);throw n.set(i,s),s}finally{r.delete(i)}};for(let i of e.keys())try{o(i)}catch{}return n}function Q(t,e){if(t.classList.add("mach-portal"),!e)return;let n=window.getComputedStyle(e);for(let r=0;r<n.length;r++){let o=n.item(r);if(!o.startsWith("--mach-"))continue;let i=n.getPropertyValue(o).trim();i&&t.style.setProperty(o,i)}t.style.colorScheme=n.colorScheme}function c(t,e,n){let r=document.createElement(t);return e&&(r.className=e),n!=null&&(r.textContent=n),r}function w(t,e,n=""){let r=c("button",`mach-workbench__button ${n}`.trim(),t);return r.type="button",r.addEventListener("click",e),r}function A(t,e,n,r){let o=c("select","mach-workbench__input");o.setAttribute("aria-label",t);for(let i of e){let a=c("option",void 0,i.label);a.value=i.value,o.append(a)}return o.value=n,o.addEventListener("change",()=>r(o.value)),o}function _(t,e){let n=[...t.querySelectorAll("button,select,input")].filter(o=>!o.disabled);(n.find(o=>o.getAttribute("aria-label")===e||o.textContent===e)??n[0])?.focus()}function ee(t,e,n,r){let o=document.activeElement,i=c("section","mach-workbench");i.setAttribute("aria-label",e),i.tabIndex=-1;let a=c("header","mach-workbench__header");a.append(c("h2","mach-workbench__title",e),w("\u5173\u95ED",n));let l=c("div","mach-workbench__body"),s=c("p","mach-workbench__status");s.setAttribute("role","status"),s.setAttribute("aria-live","polite");let u=c("footer","mach-workbench__footer");i.append(a,l,s,u);let f=v=>{v.key!=="Escape"||v.isComposing||(v.preventDefault(),v.stopPropagation(),n())};i.addEventListener("keydown",f);let d=!1,h=r.view.getRoot(),p=()=>{d||(i.dataset.theme=h?.classList.contains("mach-theme-dark")?"dark":"light",Q(i,h))},g=null;try{p(),h&&(g=new MutationObserver(p),g.observe(h,{attributes:!0,attributeFilter:["class","style"]})),t.append(i)}catch(v){throw g?.disconnect(),i.remove(),v}return{root:i,body:l,status:s,footer:u,syncTheme:p,destroy(){if(d)return;d=!0,g?.disconnect();let v=i.contains(document.activeElement);i.removeEventListener("keydown",f),i.remove(),v&&o?.isConnected&&o.focus()}}}function y(t,e,n){let r=document.createElementNS("http://www.w3.org/2000/svg",t);for(let[o,i]of Object.entries(e))r.setAttribute(o,String(i));return n!=null&&(r.textContent=n),r}function te(t,e,n){let r=c("figure","mach-analysis__chart"),o=t.columns.find(b=>b.id===e);if(!o)return r.append(c("p",void 0,"\u5C1A\u65E0\u53EF\u7ED8\u5236\u7684\u6307\u6807")),r;let i=t.rows.slice(0,40),a=`${o.label} \xB7 ${n==="bar"?"\u67F1\u72B6\u56FE":"\u6298\u7EBF\u56FE"}\uFF0C${i.length} \u7EC4`,l=y("svg",{viewBox:"0 0 680 260",role:"img","aria-label":a});l.append(y("title",{},a));let s=i.map(b=>b.values[e]).filter(b=>b!=null&&Number.isFinite(b)),u=Math.min(0,...s),f=Math.max(0,...s),d=Math.max(Math.abs(f),Math.abs(u))||1,h=f/d-u/d||1,p=b=>210-(b/d-u/d)/h*180,g=p(0);l.append(y("line",{x1:50,x2:660,y1:g,y2:g,stroke:"currentColor",opacity:".4"})),l.append(y("text",{x:2,y:25,"font-size":11},String(f)),y("text",{x:2,y:212,"font-size":11},String(u)));let v=600/Math.max(i.length,1),P=[],D=()=>{P.length&&l.append(y("polyline",{points:P.join(" "),fill:"none",stroke:"currentColor","stroke-width":2})),P=[]};return i.forEach((b,O)=>{let C=b.values[e];if(C==null){D();return}let N=55+v*(O+.5),F=p(C),I=b.dimensions.map(H=>H==null?"\u7A7A\u503C":String(H)).join(" / ")||"\u5168\u90E8",$=n==="bar"?y("rect",{x:N-v*.35,y:Math.min(g,F),width:Math.max(1,v*.7),height:Math.max(1,Math.abs(F-g)),fill:"currentColor",rx:2}):y("circle",{cx:N,cy:F,r:3,fill:"currentColor"});$.append(y("title",{},`${I}: ${C}`)),l.append($),n==="line"&&P.push(`${N},${F}`),(i.length<=10||O%Math.ceil(i.length/10)===0)&&l.append(y("text",{x:N,y:238,"text-anchor":"middle","font-size":10},I.slice(0,12)))}),D(),r.append(l,c("figcaption","mach-workbench__hint",`${a}\u3002${t.rows.length>40?"\u56FE\u8868\u4EC5\u5C55\u793A\u524D 40 \u7EC4\uFF0C":""}\u5B8C\u6574\u6570\u503C\u89C1\u4E0B\u65B9\u6570\u636E\u8868\u3002`)),r}var fe={sum:"\u6C42\u548C",count:"\u8BB0\u5F55\u6570",avg:"\u5E73\u5747\u503C",min:"\u6700\u5C0F\u503C",max:"\u6700\u5927\u503C"};function pe(t,e){return new L(t,e)}var L=class{constructor(e,n){this.options=n;this.fields=[];this.result=null;this.results=c("div","mach-analysis__results");this.page=0;this.o="bar";this.t="";this.destroyed=!1;if(n.api.isDestroyed())throw new Error("Cannot mount analysis on a destroyed grid");this.config={rowFields:[...n.pivot?.rowFields??[]],columnFields:[...n.pivot?.columnFields??[]],values:n.pivot?.values.map(r=>({...r}))??[{aggregate:"count"}]},this.formulas=Object.entries(n.formulas??{}).map(([r,o])=>({field:r,expression:o})),this.e=ee(e,"\u6570\u636E\u5206\u6790",()=>{this.destroy(),n.onClose?.()},n.api),this.e.footer.append(w("\u8FD0\u884C\u5206\u6790",()=>this.s(),"mach-workbench__button--primary")),this.i=[n.api.on("gridDestroyed",()=>this.destroy()),n.api.on("modelUpdated",()=>{!this.destroyed&&this.result&&(this.e.status.textContent="\u8868\u683C\u6570\u636E\u5DF2\u66F4\u65B0\uFF1B\u91CD\u65B0\u8FD0\u884C\u5206\u6790\u4EE5\u5237\u65B0\u7ED3\u679C\u3002")})],this.refresh(),this.s(),this.e.root.focus()}refresh(){this.a()&&(this.fields=this.l(),this.e.syncTheme(),this.e.body.replaceChildren(),this.c(),this.e.body.append(this.results),this.n())}destroy(){this.destroyed||(this.destroyed=!0,this.i.splice(0).forEach(e=>e()),this.e.destroy())}a(){return!this.destroyed&&!this.options.api.isDestroyed()}l(){let e=[],n=r=>{for(let o of r){if("children"in o){n(o.children);continue}if(!o.field)continue;let i=x(this.options.api.rows.getAt(0)?.data,o.field);e.push({field:o.field,label:o.headerName??o.field,numeric:typeof i=="number"||o.cellEditor==="number"||o.filter==="number"})}};n(this.options.api.columns.getDefinitions()??[]);for(let r of this.formulas)r.field&&!e.some(o=>o.field===r.field)&&e.push({field:r.field,label:`${r.field}\uFF08\u516C\u5F0F\uFF09`,numeric:!0});return e}c(){let e=c("div","mach-analysis__settings");e.append(this.dimensions("\u884C\u7EF4\u5EA6",this.config.rowFields,o=>{this.config.rowFields=o}),this.dimensions("\u5217\u7EF4\u5EA6",this.config.columnFields??[],o=>{this.config.columnFields=o}));let n=c("fieldset","mach-workbench__group");n.append(c("legend",void 0,"\u805A\u5408\u6307\u6807")),this.config.values.forEach((o,i)=>n.append(this.measure(o,i)));let r=w("\u6DFB\u52A0\u6307\u6807",()=>{this.config.values=[...this.config.values,{aggregate:"count"}],this.refresh()});r.disabled=this.config.values.length>=16,n.append(r),e.append(n,this.d()),this.e.body.append(e)}dimensions(e,n,r){let o=c("label","mach-analysis__dimension",e),i=c("select","mach-workbench__input");i.multiple=!0,i.setAttribute("aria-label",e);let a=[...this.fields];for(let l of n)a.some(s=>s.field===l)||a.push({field:l,label:`${l}\uFF08\u5DF2\u79FB\u9664\uFF09`,numeric:!1});for(let l of a){let s=c("option",void 0,l.label);s.value=l.field,s.selected=n.includes(l.field),i.append(s)}return i.addEventListener("change",()=>r([...i.selectedOptions].map(l=>l.value))),o.append(i,c("small","mach-workbench__hint","\u652F\u6301\u591A\u9009\uFF1B\u4E0D\u9009\u62E9\u8868\u793A\u5168\u90E8\u8BB0\u5F55\u3002")),o}measure(e,n){let r=c("div","mach-workbench__values"),o=[{value:"",label:"\u5168\u90E8\u8BB0\u5F55"},...this.fields.map(i=>({value:i.field,label:i.label}))];return e.field&&!o.some(i=>i.value===e.field)&&o.push({value:e.field,label:`${e.field}\uFF08\u5DF2\u79FB\u9664\uFF09`}),r.append(A("\u6307\u6807\u5B57\u6BB5",o,e.field??"",i=>{e.field=i||void 0}),A("\u805A\u5408\u65B9\u5F0F",Object.entries(fe).map(([i,a])=>({value:i,label:a})),e.aggregate,i=>{e.aggregate=i}),w("\u5220\u9664\u6307\u6807",()=>{this.config.values=this.config.values.filter((i,a)=>a!==n),this.refresh()})),r}d(){let e=c("fieldset","mach-workbench__group");e.append(c("legend",void 0,"\u516C\u5F0F\u5217"),c("p","mach-workbench__hint","\u4F7F\u7528 [\u5B57\u6BB5]\u3001+ - * / % ^\u3001\u62EC\u53F7\u548C SUM / MIN / MAX / AVG\u3002\u7ED3\u679C\u5217\u4F7F\u7528\u5355\u5C42 ID\uFF0C\u4E0D\u542B . \u6216 []\uFF1B\u5D4C\u5957\u8F93\u5165\u53EF\u5F15\u7528 [tax.total]\u3002\u53EA\u8BA1\u7B97\u5F53\u524D\u8BB0\u5F55\uFF0C\u4E0D\u652F\u6301\u811A\u672C\u6216\u8DE8\u884C\u5F15\u7528\u3002")),this.formulas.forEach((r,o)=>{let i=c("div","mach-workbench__values"),a=c("input","mach-workbench__input");a.setAttribute("aria-label","\u516C\u5F0F\u7ED3\u679C\u5217"),a.placeholder="\u5982 total",a.value=r.field,a.addEventListener("input",()=>{r.field=a.value.trim()});let l=c("input","mach-workbench__input");l.setAttribute("aria-label","\u516C\u5F0F\u8868\u8FBE\u5F0F"),l.placeholder="\u5982 [quantity] * [price]",l.value=r.expression,l.addEventListener("input",()=>{r.expression=l.value}),i.append(a,l,w("\u5220\u9664\u516C\u5F0F",()=>{this.formulas.splice(o,1),this.refresh()})),e.append(i)});let n=w("\u6DFB\u52A0\u516C\u5F0F",()=>{this.formulas.push({field:"",expression:""}),this.refresh()});return n.disabled=this.formulas.length>=32,e.append(n),e}s(){if(!this.a())return;let e=[],n=0;this.options.api.rows.forEach(r=>{r.data==null||r.isGroup||r.isDetail||(n++,e.length<1e4&&e.push(r.data))});try{let r=this.m(),o=S(e,r);if(o.errors.length){let l=o.errors.slice(0,20).map(s=>`\u7B2C ${s.rowIndex+1} \u884C / ${s.colId}\uFF1A${s.code} ${s.message}`);throw new Error(`\u516C\u5F0F\u9519\u8BEF ${o.errors.length} \u9879${o.errors.length>20?"\uFF08\u663E\u793A\u524D 20 \u9879\uFF09":""}\uFF1A
|
|
2
2
|
${l.join(`
|
|
3
|
-
`)}`)}this.f(r),this.result=
|
|
3
|
+
`)}`)}this.f(r),this.result=R(o.rows,this.config),this.page=0,this.refresh();let i=this.options.api.rows.isRemote()?"\u8FDC\u7A0B\u6A21\u5F0F\u4EC5\u5305\u542B\u5DF2\u52A0\u8F7D\u884C\uFF0C\u4E0D\u4EE3\u8868\u670D\u52A1\u7AEF\u5168\u91CF\u3002":"",a=n>e.length?`\u5DF2\u52A0\u8F7D ${n} \u884C\uFF0C\u672C\u6B21\u4EC5\u5206\u6790\u524D ${e.length} \u884C\u3002`:`\u5206\u6790\u5DF2\u52A0\u8F7D\u7684 ${e.length} \u884C\u3002`;this.e.status.textContent=`${a}${i} \u751F\u6210 ${this.result.rows.length} \u4E2A\u884C\u7EC4\u3001${this.result.columns.length} \u4E2A\u7ED3\u679C\u5217\u3002`,this.e.status.classList.remove("mach-workbench__status--error"),this.e.status.setAttribute("role","status")}catch(r){this.result=null,this.results.replaceChildren(),this.e.status.textContent=r instanceof Error?r.message:String(r),this.e.status.classList.add("mach-workbench__status--error"),this.e.status.setAttribute("role","alert")}}m(){let e=Object.create(null);for(let n of this.formulas){if(!n.field||Object.prototype.hasOwnProperty.call(e,n.field))throw new Error("\u516C\u5F0F\u7ED3\u679C\u5217\u4E0D\u80FD\u4E3A\u7A7A\u6216\u91CD\u590D");e[n.field]=n.expression}return e}f(e){let n=new Set([...this.l().map(o=>o.field),...Object.keys(e)]),r=[...this.config.rowFields,...this.config.columnFields??[],...this.config.values.flatMap(o=>o.field?[o.field]:[])];for(let o of r)if(!n.has(o))throw new Error(`\u5B57\u6BB5\u5DF2\u79FB\u9664\u6216\u4E0D\u53EF\u5206\u6790\uFF1A${o}`)}n(){if(this.results.replaceChildren(),!this.result)return;let e=this.result;e.columns.some(l=>l.id===this.t)||(this.t=e.columns[0]?.id??"");let n=c("div","mach-workbench__tools");n.append(A("\u56FE\u8868\u7C7B\u578B",[{value:"bar",label:"\u67F1\u72B6\u56FE"},{value:"line",label:"\u6298\u7EBF\u56FE"}],this.o,l=>{this.o=l,this.n(),_(this.results,"\u56FE\u8868\u7C7B\u578B")}),A("\u56FE\u8868\u6307\u6807",e.columns.map(l=>({value:l.id,label:l.label})),this.t,l=>{this.t=l,this.n(),_(this.results,"\u56FE\u8868\u6307\u6807")})),this.results.append(n,te(e,this.t,this.o),this.table(e));let r=Math.max(1,Math.ceil(e.rows.length/50)),o=c("nav","mach-workbench__tools");o.setAttribute("aria-label","\u5206\u6790\u7ED3\u679C\u5206\u9875");let i=w("\u4E0A\u4E00\u9875",()=>{this.page--,this.n(),_(this.results.querySelector("nav"),"\u4E0A\u4E00\u9875")}),a=w("\u4E0B\u4E00\u9875",()=>{this.page++,this.n(),_(this.results.querySelector("nav"),"\u4E0B\u4E00\u9875")});i.disabled=this.page<=0,a.disabled=this.page>=r-1,o.append(i,c("span",void 0,`\u7B2C ${this.page+1} / ${r} \u9875 \xB7 \u6BCF\u9875 50 \u7EC4`),a),this.results.append(o)}table(e){let n=c("div","mach-analysis__table-wrap"),r=c("table","mach-analysis__table");r.append(c("caption",void 0,"\u900F\u89C6\u7ED3\u679C\u6570\u636E\u8868\uFF08\u5B8C\u6574\u7ED3\u679C\u53EF\u5206\u9875\u67E5\u770B\uFF09"));let o=c("thead"),i=c("tr");for(let s of["\u884C\u7EF4\u5EA6",...e.columns.map(u=>u.label)]){let u=c("th",void 0,s);u.scope="col",i.append(u)}o.append(i);let a=c("tbody");for(let s of e.rows.slice(this.page*50,(this.page+1)*50))a.append(this.u(s.dimensions.map(u=>u==null?"\u7A7A\u503C":String(u)).join(" / ")||"\u5168\u90E8",e,s.values));let l=c("tfoot");return l.append(this.u("\u5408\u8BA1",e,e.totals)),r.append(o,a,l),n.append(r),n}u(e,n,r){let o=c("tr"),i=c("th",void 0,e);i.scope="row",o.append(i);for(let a of n.columns){let l=r[a.id],s=c("td",void 0,l==null?"\u2014":l.toLocaleString("zh-CN",{maximumFractionDigits:6}));s.title=l==null?"\u65E0\u6570\u503C":String(l),o.append(s)}return o}};export{R as createPivot,S as evaluateFormulas,pe as mountAnalysis};
|
|
@@ -600,7 +600,9 @@ declare const DEFAULT_LOCALE: {
|
|
|
600
600
|
readonly statusAvg: "均 {n}";
|
|
601
601
|
readonly statusCount: "计 {n}";
|
|
602
602
|
readonly emptyRows: "没有可显示的行";
|
|
603
|
-
readonly emptyRowsHint: "
|
|
603
|
+
readonly emptyRowsHint: "暂无数据";
|
|
604
|
+
readonly noMatchingRows: "没有符合筛选条件的行";
|
|
605
|
+
readonly clearFilters: "清除筛选";
|
|
604
606
|
readonly paginationTotal: "共 {n} 条";
|
|
605
607
|
readonly paginationPage: "第 {a} / {b} 页";
|
|
606
608
|
readonly perPage: "{n} 条/页";
|
|
@@ -885,6 +887,8 @@ interface GridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
885
887
|
enableColumnResize?: boolean;
|
|
886
888
|
/** Lets small grids grow with their rows. Avoid for large or infinite datasets. */
|
|
887
889
|
domLayout?: DomLayoutMode;
|
|
890
|
+
/** Maximum body height in CSS pixels for autoHeight. Larger results scroll virtually. */
|
|
891
|
+
maxBodyHeight?: number;
|
|
888
892
|
rowSelection?: RowSelectionMode;
|
|
889
893
|
multiSort?: boolean;
|
|
890
894
|
size?: GridSize;
|
|
@@ -1015,6 +1019,7 @@ interface ResolvedGridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
1015
1019
|
columnLayout: ColumnLayoutMode;
|
|
1016
1020
|
enableColumnResize: boolean;
|
|
1017
1021
|
domLayout: DomLayoutMode;
|
|
1022
|
+
maxBodyHeight?: number;
|
|
1018
1023
|
rowSelection: RowSelectionMode;
|
|
1019
1024
|
multiSort: boolean;
|
|
1020
1025
|
size: GridSize;
|
|
@@ -600,7 +600,9 @@ declare const DEFAULT_LOCALE: {
|
|
|
600
600
|
readonly statusAvg: "均 {n}";
|
|
601
601
|
readonly statusCount: "计 {n}";
|
|
602
602
|
readonly emptyRows: "没有可显示的行";
|
|
603
|
-
readonly emptyRowsHint: "
|
|
603
|
+
readonly emptyRowsHint: "暂无数据";
|
|
604
|
+
readonly noMatchingRows: "没有符合筛选条件的行";
|
|
605
|
+
readonly clearFilters: "清除筛选";
|
|
604
606
|
readonly paginationTotal: "共 {n} 条";
|
|
605
607
|
readonly paginationPage: "第 {a} / {b} 页";
|
|
606
608
|
readonly perPage: "{n} 条/页";
|
|
@@ -885,6 +887,8 @@ interface GridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
885
887
|
enableColumnResize?: boolean;
|
|
886
888
|
/** Lets small grids grow with their rows. Avoid for large or infinite datasets. */
|
|
887
889
|
domLayout?: DomLayoutMode;
|
|
890
|
+
/** Maximum body height in CSS pixels for autoHeight. Larger results scroll virtually. */
|
|
891
|
+
maxBodyHeight?: number;
|
|
888
892
|
rowSelection?: RowSelectionMode;
|
|
889
893
|
multiSort?: boolean;
|
|
890
894
|
size?: GridSize;
|
|
@@ -1015,6 +1019,7 @@ interface ResolvedGridOptions<TData = any> extends EventHandlers<TData> {
|
|
|
1015
1019
|
columnLayout: ColumnLayoutMode;
|
|
1016
1020
|
enableColumnResize: boolean;
|
|
1017
1021
|
domLayout: DomLayoutMode;
|
|
1022
|
+
maxBodyHeight?: number;
|
|
1018
1023
|
rowSelection: RowSelectionMode;
|
|
1019
1024
|
multiSort: boolean;
|
|
1020
1025
|
size: GridSize;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-
|
|
1
|
+
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-ChEKWrvH.js';
|
|
2
2
|
|
|
3
3
|
type MachTablePresetSelection = string | readonly string[] | false;
|
|
4
4
|
type MachTableInstanceOptionKey = "rowData" | "columnDefs" | "datasource" | "loading" | "error" | "initialState" | "persistence" | "components" | "columnTypes";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-
|
|
1
|
+
import { c as GridOptions, d as GridDataProcessor, C as ColDef, e as GridComponents } from './api-ChEKWrvH.cjs';
|
|
2
2
|
|
|
3
3
|
type MachTablePresetSelection = string | readonly string[] | false;
|
|
4
4
|
type MachTableInstanceOptionKey = "rowData" | "columnDefs" | "datasource" | "loading" | "error" | "initialState" | "persistence" | "components" | "columnTypes";
|
package/dist/import.d.cts
CHANGED
package/dist/import.d.ts
CHANGED