@jimka/typescript-ui 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/{AbstractBooleanInput-DE5NNJT0.js → AbstractBooleanInput-CbW7ZrDT.js} +2 -2
- package/dist/lib/{AbstractBooleanInput-DE5NNJT0.js.map → AbstractBooleanInput-CbW7ZrDT.js.map} +1 -1
- package/dist/lib/{AbstractInput-BxfrmD2W.js → AbstractInput-B10DfLOf.js} +2 -2
- package/dist/lib/{AbstractInput-BxfrmD2W.js.map → AbstractInput-B10DfLOf.js.map} +1 -1
- package/dist/lib/Anchor-BsblS5it.js +2 -0
- package/dist/lib/Anchor-BsblS5it.js.map +1 -0
- package/dist/lib/AnchorConstraints-Bfkt8019.js +2 -0
- package/dist/lib/AnchorConstraints-Bfkt8019.js.map +1 -0
- package/dist/lib/{AnimatedDropdown-QLNasu_Y.js → AnimatedDropdown-kL47HPGP.js} +2 -2
- package/dist/lib/{AnimatedDropdown-QLNasu_Y.js.map → AnimatedDropdown-kL47HPGP.js.map} +1 -1
- package/dist/lib/Border-CNS6aEXB.js +2 -0
- package/dist/lib/{Border-CKKUk5G9.js.map → Border-CNS6aEXB.js.map} +1 -1
- package/dist/lib/Button-T16zSZip.js +2 -0
- package/dist/lib/Button-T16zSZip.js.map +1 -0
- package/dist/lib/{Card-a4dzYrbX.js → Card-CD3jxshU.js} +2 -2
- package/dist/lib/{Card-a4dzYrbX.js.map → Card-CD3jxshU.js.map} +1 -1
- package/dist/lib/CodeEditor-BGlB232h.js +2 -0
- package/dist/lib/CodeEditor-BGlB232h.js.map +1 -0
- package/dist/lib/ComboBox-C9FYMuLv.js +2 -0
- package/dist/lib/ComboBox-C9FYMuLv.js.map +1 -0
- package/dist/lib/Component-w65rPK75.js +2 -0
- package/dist/lib/Component-w65rPK75.js.map +1 -0
- package/dist/lib/Container-C7RPLQEc.js +2 -0
- package/dist/lib/{Container-0bsG2Q8Z.js.map → Container-C7RPLQEc.js.map} +1 -1
- package/dist/lib/DOM-Ba8YRVel.js +2 -0
- package/dist/lib/{DOM-67StIm5G.js.map → DOM-Ba8YRVel.js.map} +1 -1
- package/dist/lib/DragManager-UvPHSoRm.js +2 -0
- package/dist/lib/{DragManager-DRor_-1x.js.map → DragManager-UvPHSoRm.js.map} +1 -1
- package/dist/lib/{FieldDecorator-Bpx8J8n9.js → FieldDecorator-HG65hEtk.js} +2 -2
- package/dist/lib/{FieldDecorator-Bpx8J8n9.js.map → FieldDecorator-HG65hEtk.js.map} +1 -1
- package/dist/lib/{Fit-CL1m1nIZ.js → Fit-Cg3dPyZg.js} +2 -2
- package/dist/lib/{Fit-CL1m1nIZ.js.map → Fit-Cg3dPyZg.js.map} +1 -1
- package/dist/lib/FloatingPanel-D5buuVrQ.js +2 -0
- package/dist/lib/FloatingPanel-D5buuVrQ.js.map +1 -0
- package/dist/lib/{Glyph-wN7bk7mg.js → Glyph-DeJF_zsR.js} +2 -2
- package/dist/lib/{Glyph-wN7bk7mg.js.map → Glyph-DeJF_zsR.js.map} +1 -1
- package/dist/lib/{Grid-DHHmaB-Y.js → Grid-BYBohJIA.js} +2 -2
- package/dist/lib/{Grid-DHHmaB-Y.js.map → Grid-BYBohJIA.js.map} +1 -1
- package/dist/lib/{GridConstraints-DVc1BmlP.js → GridConstraints-Bts284FI.js} +2 -2
- package/dist/lib/{GridConstraints-DVc1BmlP.js.map → GridConstraints-Bts284FI.js.map} +1 -1
- package/dist/lib/{Header-2hKwQo_u.js → Header-BIFJK9nR.js} +2 -2
- package/dist/lib/{Header-2hKwQo_u.js.map → Header-BIFJK9nR.js.map} +1 -1
- package/dist/lib/{IconText-DC7Xe34b.js → IconText-Dsb1xS-E.js} +2 -2
- package/dist/lib/{IconText-DC7Xe34b.js.map → IconText-Dsb1xS-E.js.map} +1 -1
- package/dist/lib/LanguageRegistry-CcVnbKuh.js +2 -0
- package/dist/lib/LanguageRegistry-CcVnbKuh.js.map +1 -0
- package/dist/lib/LayoutSerialization-ySzY1h2l.js +2 -0
- package/dist/lib/{LayoutSerialization-D5bBas4W.js.map → LayoutSerialization-ySzY1h2l.js.map} +1 -1
- package/dist/lib/LayoutSizes-DKDK1Cle.js +2 -0
- package/dist/lib/LayoutSizes-DKDK1Cle.js.map +1 -0
- package/dist/lib/List-BPd-IXZR.js +2 -0
- package/dist/lib/{List-CG4NvwuV.js.map → List-BPd-IXZR.js.map} +1 -1
- package/dist/lib/MemoryStore-BgP7-Uzn.js +2 -0
- package/dist/lib/{MemoryStore-DT6iWWco.js.map → MemoryStore-BgP7-Uzn.js.map} +1 -1
- package/dist/lib/Menu-C0roOCY7.js +2 -0
- package/dist/lib/Menu-C0roOCY7.js.map +1 -0
- package/dist/lib/{MenuButton-wy_0RskC.js → MenuButton-BR4KOFld.js} +2 -2
- package/dist/lib/{MenuButton-wy_0RskC.js.map → MenuButton-BR4KOFld.js.map} +1 -1
- package/dist/lib/Panel-CpNQTLNF.js +2 -0
- package/dist/lib/{Panel-Rd9zkNXx.js.map → Panel-CpNQTLNF.js.map} +1 -1
- package/dist/lib/{Position-Ck_KD4cR.js → Position-PBVBW1JS.js} +2 -2
- package/dist/lib/{Position-Ck_KD4cR.js.map → Position-PBVBW1JS.js.map} +1 -1
- package/dist/lib/{ProgressSpinner-yt-VXyCb.js → ProgressSpinner-lAsK26C-.js} +2 -2
- package/dist/lib/{ProgressSpinner-yt-VXyCb.js.map → ProgressSpinner-lAsK26C-.js.map} +1 -1
- package/dist/lib/RadioButton-CCcIaL54.js +2 -0
- package/dist/lib/RadioButton-CCcIaL54.js.map +1 -0
- package/dist/lib/{RovingTabIndex-DFJyoveq.js → RovingTabIndex-C2Vzq0IX.js} +2 -2
- package/dist/lib/{RovingTabIndex-DFJyoveq.js.map → RovingTabIndex-C2Vzq0IX.js.map} +1 -1
- package/dist/lib/Scrollbar-C3ZZyZ1e.js +2 -0
- package/dist/lib/Scrollbar-C3ZZyZ1e.js.map +1 -0
- package/dist/lib/Slider-DZ9drUxn.js +2 -0
- package/dist/lib/Slider-DZ9drUxn.js.map +1 -0
- package/dist/lib/{Spacer-qalSEJ5i.js → Spacer-SDhOMp2g.js} +2 -2
- package/dist/lib/{Spacer-qalSEJ5i.js.map → Spacer-SDhOMp2g.js.map} +1 -1
- package/dist/lib/TabButton-DNo4ZgV8.js +2 -0
- package/dist/lib/TabButton-DNo4ZgV8.js.map +1 -0
- package/dist/lib/Text-CdHf3B-1.js +2 -0
- package/dist/lib/Text-CdHf3B-1.js.map +1 -0
- package/dist/lib/{Tooltip-Dro4DOZs.js → Tooltip-B_UF5bXD.js} +2 -2
- package/dist/lib/{Tooltip-Dro4DOZs.js.map → Tooltip-B_UF5bXD.js.map} +1 -1
- package/dist/lib/Tree-C7qLbIYH.js +2 -0
- package/dist/lib/Tree-C7qLbIYH.js.map +1 -0
- package/dist/lib/VBox-32fxpkDl.js +2 -0
- package/dist/lib/VBox-32fxpkDl.js.map +1 -0
- package/dist/lib/{Validator-Du8PqS5i.js → Validator-Cjs1EU5Q.js} +2 -2
- package/dist/lib/{Validator-Du8PqS5i.js.map → Validator-Cjs1EU5Q.js.map} +1 -1
- package/dist/lib/{VirtualScroller-Bv4KXGKW.js → VirtualScroller-cvFNMS7U.js} +2 -2
- package/dist/lib/{VirtualScroller-Bv4KXGKW.js.map → VirtualScroller-cvFNMS7U.js.map} +1 -1
- package/dist/lib/component/button.es.js +1 -1
- package/dist/lib/component/chart.es.js +1 -1
- package/dist/lib/component/chart.es.js.map +1 -1
- package/dist/lib/component/container.es.js +1 -1
- package/dist/lib/component/container.es.js.map +1 -1
- package/dist/lib/component/diagram.es.js +1 -1
- package/dist/lib/component/diagram.es.js.map +1 -1
- package/dist/lib/component/display.es.js +1 -1
- package/dist/lib/component/display.es.js.map +1 -1
- package/dist/lib/component/editor.es.js +3 -3
- package/dist/lib/component/editor.es.js.map +1 -1
- package/dist/lib/component/input.es.js +1 -1
- package/dist/lib/component/input.es.js.map +1 -1
- package/dist/lib/component/list.es.js +1 -1
- package/dist/lib/component/list.es.js.map +1 -1
- package/dist/lib/component/menubar.es.js +1 -1
- package/dist/lib/component/menubar.es.js.map +1 -1
- package/dist/lib/component/table.es.js +2 -2
- package/dist/lib/component/table.es.js.map +1 -1
- package/dist/lib/component/tree.es.js +1 -1
- package/dist/lib/component/tree.es.js.map +1 -1
- package/dist/lib/core.es.js +1 -1
- package/dist/lib/core.es.js.map +1 -1
- package/dist/lib/data.es.js +1 -1
- package/dist/lib/glyphs/solid/index.es.js +1 -1
- package/dist/lib/languages-Dl8qdL8a.js +2 -0
- package/dist/lib/languages-Dl8qdL8a.js.map +1 -0
- package/dist/lib/layout.es.js +1 -1
- package/dist/lib/layout.es.js.map +1 -1
- package/dist/lib/overlay.es.js +1 -1
- package/dist/lib/overlay.es.js.map +1 -1
- package/dist/lib/primitive.es.js +1 -1
- package/dist/lib/router.es.js +1 -1
- package/dist/lib/router.es.js.map +1 -1
- package/dist/lib/selectionsEqual-BrTxPMmK.js +2 -0
- package/dist/lib/{selectionsEqual-Ci3_uflt.js.map → selectionsEqual-BrTxPMmK.js.map} +1 -1
- package/dist/lib/types/component/button/TabButton.d.ts +1 -1
- package/dist/lib/types/component/button/ToggleButton.d.ts +1 -1
- package/dist/lib/types/component/chart/ChartLegend.d.ts +1 -1
- package/dist/lib/types/component/container/FloatingPanel.d.ts +23 -0
- package/dist/lib/types/component/container/ScrollStrip.d.ts +1 -1
- package/dist/lib/types/component/container/Scrollbar.d.ts +1 -3
- package/dist/lib/types/component/container/TabBar.d.ts +1 -1
- package/dist/lib/types/component/container/index.d.ts +2 -0
- package/dist/lib/types/component/diagram/DiagramGroupNode.d.ts +1 -1
- package/dist/lib/types/component/display/Markdown.d.ts +42 -1
- package/dist/lib/types/component/display/MarkdownMinimap.d.ts +38 -0
- package/dist/lib/types/component/display/MarkdownViewer.d.ts +60 -0
- package/dist/lib/types/component/display/index.d.ts +6 -0
- package/dist/lib/types/component/editor/CodeEditor.d.ts +13 -0
- package/dist/lib/types/component/editor/index.d.ts +1 -1
- package/dist/lib/types/component/input/Checkbox.d.ts +1 -1
- package/dist/lib/types/component/input/RadioButton.d.ts +1 -1
- package/dist/lib/types/component/input/Slider.d.ts +1 -1
- package/dist/lib/types/component/input/Text.d.ts +0 -2
- package/dist/lib/types/component/input/Toggle.d.ts +1 -1
- package/dist/lib/types/component/menubar/MenuBar.d.ts +1 -1
- package/dist/lib/types/component/menubar/ToolBar.d.ts +1 -0
- package/dist/lib/types/component/table/Body.d.ts +1 -0
- package/dist/lib/types/component/table/cell/SortPriorityBadge.d.ts +1 -1
- package/dist/lib/types/component/table/cell/editor/CellEditorPool.d.ts +1 -0
- package/dist/lib/types/component/table/cell/editor/Date.d.ts +1 -0
- package/dist/lib/types/component/table/cell/editor/DateTime.d.ts +1 -0
- package/dist/lib/types/component/table/cell/editor/Time.d.ts +1 -0
- package/dist/lib/types/component/tree/Tree.d.ts +9 -1
- package/dist/lib/types/component/tree/index.d.ts +1 -1
- package/dist/lib/types/component/tree/renderer/Label.d.ts +1 -1
- package/dist/lib/types/core/Component.d.ts +5 -0
- package/dist/lib/types/core/Theme.d.ts +4 -2
- package/dist/lib/types/layout/LayoutManager.d.ts +8 -0
- package/dist/lib/validation.es.js +1 -1
- package/llms.txt +3 -0
- package/package.json +15 -15
- package/dist/lib/AnchorConstraints-DdDYSDkf.js +0 -2
- package/dist/lib/AnchorConstraints-DdDYSDkf.js.map +0 -1
- package/dist/lib/Border-CKKUk5G9.js +0 -2
- package/dist/lib/Button-MZDYJOMC.js +0 -2
- package/dist/lib/Button-MZDYJOMC.js.map +0 -1
- package/dist/lib/ComboBox-C04SfXAR.js +0 -2
- package/dist/lib/ComboBox-C04SfXAR.js.map +0 -1
- package/dist/lib/Component-fRQvgaEY.js +0 -2
- package/dist/lib/Component-fRQvgaEY.js.map +0 -1
- package/dist/lib/Container-0bsG2Q8Z.js +0 -2
- package/dist/lib/DOM-67StIm5G.js +0 -2
- package/dist/lib/DragManager-DRor_-1x.js +0 -2
- package/dist/lib/LayoutSerialization-D5bBas4W.js +0 -2
- package/dist/lib/LayoutSizes-qNaURyiw.js +0 -2
- package/dist/lib/LayoutSizes-qNaURyiw.js.map +0 -1
- package/dist/lib/List-CG4NvwuV.js +0 -2
- package/dist/lib/MemoryStore-DT6iWWco.js +0 -2
- package/dist/lib/Menu-CrZy2u0g.js +0 -2
- package/dist/lib/Menu-CrZy2u0g.js.map +0 -1
- package/dist/lib/Panel-Rd9zkNXx.js +0 -2
- package/dist/lib/RadioButton-D23rId-V.js +0 -2
- package/dist/lib/RadioButton-D23rId-V.js.map +0 -1
- package/dist/lib/Scrollbar-SOj9psiP.js +0 -2
- package/dist/lib/Scrollbar-SOj9psiP.js.map +0 -1
- package/dist/lib/Slider-DBnAZ-F7.js +0 -2
- package/dist/lib/Slider-DBnAZ-F7.js.map +0 -1
- package/dist/lib/TabButton-DKECTTk1.js +0 -2
- package/dist/lib/TabButton-DKECTTk1.js.map +0 -1
- package/dist/lib/Text-KB5LksJl.js +0 -2
- package/dist/lib/Text-KB5LksJl.js.map +0 -1
- package/dist/lib/VBox-P3WFGkPc.js +0 -2
- package/dist/lib/VBox-P3WFGkPc.js.map +0 -1
- package/dist/lib/selectionsEqual-Ci3_uflt.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"../DOM-67StIm5G.js";import{a as t,l as n,n as r}from"../Position-Ck_KD4cR.js";import{S as i,b as a,d as o,f as s,h as c,m as l,p as u,r as d,t as f}from"../Component-fRQvgaEY.js";import{t as p}from"../ListenerBag-WPdKuuds.js";import{t as m}from"../Container-0bsG2Q8Z.js";import{t as h}from"../Glyph-wN7bk7mg.js";import{a as g,t as _}from"../Tooltip-Dro4DOZs.js";import{t as v}from"../Fit-CL1m1nIZ.js";import{t as y}from"../Text-KB5LksJl.js";import{r as ee}from"../VBox-P3WFGkPc.js";import{a as te,o as ne,t as re}from"../Border-CKKUk5G9.js";import{t as b}from"../ProgressSpinner-yt-VXyCb.js";import{t as x}from"../Placement-7kqdaK4Z.js";import{t as S}from"../Button-MZDYJOMC.js";import{t as C}from"../DragManager-DRor_-1x.js";import{t as ie}from"../Menu-CrZy2u0g.js";import{n as w,r as ae}from"../DragChain-CYGuT7OA.js";import{t as oe}from"../Card-a4dzYrbX.js";import{i as se,t as ce}from"../MemoryStore-DT6iWWco.js";import{a as le,g as ue,n as de,o as fe,r as pe,t as me,u as T}from"../ComboBox-C04SfXAR.js";import{caret_down as he}from"../glyphs/solid/caret_down.es.js";import{t as ge}from"../reduceModifierSelection-DTo8HyFl.js";import{caret_right as _e}from"../glyphs/solid/caret_right.es.js";import{n as ve,t as ye}from"../selectionsEqual-Ci3_uflt.js";import{plus as E}from"../glyphs/solid/plus.es.js";import{minus as be}from"../glyphs/solid/minus.es.js";import{arrows_rotate as xe}from"../glyphs/solid/arrows_rotate.es.js";import{ban as Se}from"../glyphs/solid/ban.es.js";var Table$1=class extends s{constructor(e){super(),e&&this.applyOptions(e)}attach(e){let t=e.getClassName();if(t!=`Table`&&t!=`TreeTable`)throw Error(`Container must be a Table or TreeTable.`);return super.attach(e),this}doLayout(){let t=this.getContainer();if(!t)return;let r=t.getInnerSize();if(!r||!Number.isFinite(r.width)||!Number.isFinite(r.height))return;let i=t.getContentInsets(),a=t.getColumns(),o=t.getColumns().length,s=t.getAvailableColumnWidth(),c=Math.max(s,t.getColumnWidthTarget()),l=t.getColumnWidths();l.length===o?(l=this.rescaleWidths(t,a,l,c),t.setColumnWidths(l)):(l=this.initializeWidths(t,a,s),t.setColumnWidths(l));let u=t.getHeader(),f=t.getBody(),p=t.getFooter();if(t.isHeaderVisible()&&u&&u.isDisplayed()){let t=d.getTheme(),a=n.lineHeightPx()+2*(t.table.cell.padding??2),o=u.hasParentRow()?a:0,c=u.getPerimeterSize(),f=o+a+c.top+c.bottom;u.setAutoCommitStyle(!1),u.setX(i.getLeft()),u.setY(i.getTop()),u.setWidth(r.width),u.setHeight(f),u.setAutoCommitStyle(!0);let p=u.getContentBounds()??{x:0,y:0,width:r.width,height:f},m=l.reduce((e,t)=>e+t,0),h=Math.max(p.width,m),g=u.getParentRow();g.setAutoCommitStyle(!1),g.setX(p.x),g.setY(p.y),g.setWidth(h),g.setHeight(o),g.setAutoCommitStyle(!0);let _=u.getComponents()[1];_.setAutoCommitStyle(!1),_.setX(p.x),_.setY(p.y+o),_.setWidth(h),_.setHeight(a),_.setAutoCommitStyle(!0),u.renderColumnWindow({columnWidths:l,viewportWidth:s,columnHeight:a,parentRowHeight:o});let v=e.source.getScrollBarWidth(),y=u.getScrollbarCover();e.sink.apply(y,{style:{left:p.x+p.width-v+`px`,top:p.y+`px`,width:v+`px`,height:p.height+`px`}})}if(t.isFooterVisible()&&p&&p.isDisplayed()){let e=d.getTheme(),t=n.lineHeightPx()+2*(e.table.cell.padding??2),a=p.getColumns(),o=p.getPerimeterSize(),s=t+o.top+o.bottom;p.setAutoCommitStyle(!1),p.setX(i.getLeft()),p.setY(i.getTop()+r.height-s),p.setWidth(r.width),p.setHeight(s),p.setAutoCommitStyle(!0);let c=p.getContentBounds()??{x:0,y:0,width:r.width,height:t},u=0;a.forEach((e,t)=>{e.setAutoCommitStyle(!1),e.setX(u),e.setY(0),e.setWidth(l[t]),e.setHeight(c.height),e.setAutoCommitStyle(!0),e.doLayout(),u+=l[t]})}if(t.isBodyVisible()&&f&&f.isDisplayed()){let e=t.isHeaderVisible()&&u&&u.isDisplayed()?u.getHeight():0,n=t.isFooterVisible()&&p&&p.isDisplayed()?p.getHeight():0;f.setAutoCommitStyle(!1),f.setX(i.getLeft()),f.setY(i.getTop()+e),f.setWidth(r.width),f.setHeight(r.height-e-n),f.setAutoCommitStyle(!0),f.renderWindow(s,l)}}initializeWidths(e,r,i){let a=e.getIntrinsicColumnWidths(),o=a.reduce((e,t)=>e+(t??0),0),s=a.filter(e=>e===null).length,c=s>0?(i-o)/s:0,l=a.map((i,a)=>{if(i!==null)return i;let o=r[a],s=e.getColumnMinWidth(o),l=o.getMaxWidth()??t;return n.clamp(c,s,l)});return this.absorbSlackIntoGreedy(r,l,i)}rescaleWidths(e,t,n,r){let i=t.map(e=>{let t=e.getField().getType();return t===`boolean`||t===`number`||t===`date`}),a=n.reduce((e,t,n)=>e+(i[n]?t:0),0),o=n.reduce((e,t,n)=>e+(i[n]?0:t),0),s=r-a;if(o<=0||s<=0||Math.abs(o-s)<=.5)return n;let c=s/o,l=n.map((n,r)=>i[r]?n:this.clamp(n*c,t[r],e));return this.absorbSlackIntoGreedy(t,l,r)}absorbSlackIntoGreedy(e,t,n){let r=n-t.reduce((e,t)=>e+t,0);if(r<=.5)return t;let i=[];if(e.forEach((e,t)=>{let n=e.getField().getType();n!==`boolean`&&n!==`number`&&n!==`date`&&e.getMaxWidth()===void 0&&i.push(t)}),i.length===0)return t;let a=r/i.length,o=[...t];for(let e of i)o[e]+=a;return o}clamp(e,r,i){let a=i.getColumnMinWidth(r),o=r.getMaxWidth()??t;return n.clamp(e,a,o)}},Ce=c(Table$1);function blurRelatedTargetHandle(t){return t.relatedTarget?e.source.intern(t.relatedTarget):null}var CellEditor=class extends f{_onCommitRequested=null;constructor(e=`div`){super({tag:e}),this.setLayoutManager(new v);let applyPadding=()=>{let e=d.getTheme().table.cell.padding;this.setInsets(new r(0,e,0,e))};applyPadding(),this.subscribeTheme(applyPadding)}retainsFocus(e){return!1}setCommitRequestHandler(e){this._onCommitRequested=e}requestCommit(){this._onCommitRequested?.()}getContentX(){return 0}},Cell=class extends f{_readOnly;_requiredEmpty=!1;_baseBackground=`var(--ts-ui-table-cell-bg, transparent)`;_renderer;_editor;_editorPool=null;_scrollIntoView=null;_activeEditor=null;_listeners=new p;constructor(e,t,n,a,o){super({tag:e||`td`}),this.setLayoutManager(new oe),this.getAria().setRole(`gridcell`),this._readOnly=!1,this._renderer=t,this._editor=n,this.setInsets(new r(0,0,0,0)),this.setBackgroundColor(`var(--ts-ui-table-cell-bg, transparent)`),this.setForegroundColor(`var(--ts-ui-table-cell-color, inherit)`),this.setBorder(`var(--ts-ui-table-cell-border, none)`),this.subscribeTheme(()=>this.setBorder(`var(--ts-ui-table-cell-border, none)`)),this.addComponent(t,a),n&&(this.addComponent(n,o),n.setCommitRequestHandler(()=>this.commitEdit()),i.addListener(n,`blur`,e=>{n.retainsFocus(blurRelatedTargetHandle(e))||this.commitEdit()}),i.addListener(n,`keydown`,e=>this.onKeyDown(e))),i.addListener(t,`dblclick`,()=>this.startEdit())}clampsToContentSize(){return!1}getEditorKey(){return null}setEditorPool(e){return this._editorPool=e,this}setScrollIntoViewHandler(e){return this._scrollIntoView=e,this}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}isReadOnly(){return!!this._readOnly}setReadOnly(e){if(this._readOnly===e)return this;if(this._readOnly=e,e&&this._activeEditor){let e=this._activeEditor.getValue();this._renderer.setValue(e),this.emit(`commit`,e),this.detachEditor()}return this._applyStateTint(),this}setRequiredEmpty(e){return this._requiredEmpty===e?this:(this._requiredEmpty=e,this._applyStateTint(),this)}setBaseBackground(e){return this._baseBackground=e??`var(--ts-ui-table-cell-bg, transparent)`,this._applyStateTint(),this}_applyStateTint(){this._readOnly?(this.setBackgroundColor(`var(--ts-ui-table-cell-readonly-bg, rgba(0, 0, 0, 0.04))`),this.setCursor(`default`)):(this.setBackgroundColor(this._baseBackground),this.clearCursor()),this._requiredEmpty&&!this._readOnly?this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-required-outline, rgba(220, 60, 60, 0.6))`):this.clearShadow()}onKeyDown(e){let t=e.detail?.keyCode;t==13?(this.commitEdit(),this.emit(`editend`)):t==27&&(this.cancelEdit(),this.emit(`editend`))}isEditing(){return this._activeEditor!==null}getLayoutManager(){return super.getLayoutManager()}startEdit(){if(this.isReadOnly()||this.isEditing())return;if(this._scrollIntoView?.(),this._editor)this._activeEditor=this._editor;else{let e=this.getEditorKey();if(!e||!this._editorPool)return;let t=this._editorPool.acquire(e,this);if(!t)return;this._activeEditor=t,this.addComponent(this._activeEditor)}let e=this._activeEditor,t=this._renderer;this.prepareEditor(e),e.setValue(t.getValue()),this.getLayoutManager().setVisibleComponentId(e.getId()),this.doLayout(),e.focus(!0)}commitEdit(){if(this.isReadOnly()||!this.isEditing())return this;let e=this._activeEditor.getValue();return this._renderer.setValue(e),this.emit(`commit`,e),this.detachEditor(),this}cancelEdit(){this.isReadOnly()||!this.isEditing()||this.detachEditor()}detachEditor(){let e=this._activeEditor;e&&(this._activeEditor=null,this.getLayoutManager().setVisibleComponentId(this._renderer.getId()),this.doLayout(),this._editor!==e&&(this.removeComponent(e),this._editorPool?.release()))}setValue(e){return this._renderer.setValue(e),this}getRenderer(){return this._renderer}doLayout(){return super.doLayout(),this.alignEditorWithContent(),this}alignEditorWithContent(){let e=this._activeEditor;if(!e)return;let t=this._renderer.getContentX();if(t<=0)return;let n=this.getContentBounds()??{x:0,y:0,width:this.getWidth()??0,height:0},r=Math.max(0,n.width-t);e.setAutoCommitStyle(!1),e.setX(n.x+t),e.setWidth(r),e.setAutoCommitStyle(!0)}wrapRenderer(e){let t=this._renderer;this.removeComponent(t);let n=e(t);return this._renderer=n,this.addComponent(n),this.getLayoutManager().setVisibleComponentId(n.getId()),this}getEditor(){return this._editor}setActiveRenderer(e,t){t&&(this.addComponent(e),i.addListener(e,`dblclick`,()=>this.startEdit()));let n=this._renderer!==e;this._renderer=e,this.getLayoutManager().setVisibleComponentId(e.getId()),n&&this.doLayout()}prepareEditor(e){}},BooleanEditor=class extends CellEditor{_checkBox=new de;_value=null;_listeners=new p;_suppressCommit=!1;constructor(){super(),this._checkBox.setIndeterminate(!0),this._checkBox.setAnimated(!1),this.addComponent(this._checkBox),this._checkBox.on(`action`,()=>{this._suppressCommit||(this._value=this._checkBox.isSelected(),this.emit(`change`,this._value))})}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}getValue(){return this._value}setValue(e){this._value=e??null,this._suppressCommit=!0;try{this._value===null?this._checkBox.setIndeterminate(!0):(this._checkBox.setIndeterminate(!1),this._checkBox.setSelected(this._value))}finally{this._suppressCommit=!1}return this}setReadOnly(e){return this._checkBox.setReadOnly(e),this}isReadOnly(){return this._checkBox.isReadOnly()}toggle(){let e=!this._checkBox.isSelected();return this._checkBox.setIndeterminate(!1),this._checkBox.setSelected(e),this._value=e,this.emit(`change`,this._value),this}},D=c(BooleanEditor),CellRenderer=class extends f{constructor(){super(),this.setLayoutManager(new v);let applyPadding=()=>{let e=d.getTheme().table.cell.padding;this.setInsets(new r(0,e,0,e))};applyPadding(),this.subscribeTheme(applyPadding)}getContentX(){return 0}doLayout(){super.doLayout();let e=this.getComponents();if(e.length!==1)return this;let t=e[0];if(!(t instanceof y))return this;let n=t.getHeight();return n>0&&t.setLineHeight(n),this}},StringRenderer=class extends CellRenderer{_text=new y;_value=null;constructor(){super(),this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getText(){return this._text}getValue(){return this._value}setValue(e){return this._value=e??null,this._text.setText(this._value===null?``:String(this._value)),this}},O=c(StringRenderer),NumberRenderer=class extends CellRenderer{_text=new y;_value=null;constructor(){super(),this._text.setPointerEvents(`none`),this._text.setTextAlign(`right`),this._text.setText(``),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){return this._value=e??null,this._text.setText(this._value===null?``:String(this._value)),this}},k=c(NumberRenderer),DateRenderer=class extends CellRenderer{_text=new y;_value=null;constructor(){super(),this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){return this._value=e??null,this._text.setText(e?e.toLocaleDateString():``),this}},A=c(DateRenderer),TimeRenderer=class extends CellRenderer{_text=new y;_value=null;_showSeconds;constructor(e=!1){super(),this._showSeconds=e,this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){this._value=e??null;let t=this._showSeconds?{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{hour:`2-digit`,minute:`2-digit`};return this._text.setText(e?e.toLocaleTimeString(void 0,t):``),this}},j=c(TimeRenderer),DateTimeRenderer=class extends CellRenderer{_text=new y;_value=null;_showSeconds;constructor(e=!1){super(),this._showSeconds=e,this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){this._value=e??null;let t=this._showSeconds?{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};return this._text.setText(e?e.toLocaleString(void 0,t):``),this}},M=c(DateTimeRenderer),GlyphRenderer=class extends CellRenderer{_value=null;_glyph=null;getValue(){return this._value}setValue(e){let t=e||null;return t===this._value&&(t===null||this._glyph)?this:(this._glyph&&=(this.removeComponent(this._glyph),null),this._value=t,t!==null&&(this._glyph=new h(t),this._glyph.setPointerEvents(`none`),this.addComponent(this._glyph)),this.doLayout(),this)}},N=c(GlyphRenderer);function normalizeComboOptions(e){return e.map(e=>typeof e==`string`?{value:e,label:e}:{value:e.value,label:e.label??e.value})}var ComboRenderer=class extends CellRenderer{_text=new y;_map=new Map;_value=null;constructor(e){super();for(let t of normalizeComboOptions(e))this._map.set(t.value,t.label);this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getText(){return this._text}getValue(){return this._value}setValue(e){if(this._value=e??null,this._value===null)this._text.setText(``);else{let e=String(this._value);this._text.setText(this._map.get(e)??e)}return this}setOptions(e){this._map.clear();for(let t of normalizeComboOptions(e))this._map.set(t.value,t.label);return this.setValue(this._value),this}},P=c(ComboRenderer),F=c(class DynamicCell extends Cell{_field;_columnType;_showSeconds;_cellType;_cellValues;_renderers=new Map;_activeType=`string`;_currentOptions=[];_checkbox=null;_justCreated=!1;constructor(e,t,n){let r=new O;super(`td`,r),this._field=e,this._columnType=t,this._showSeconds=n.showSeconds??!1,this._cellType=n.cellType,this._cellValues=n.cellValues,this._renderers.set(`string`,r)}bindRecord(e){let t=this._cellType?.(e)??this._columnType;if(this._activeType=t,t===`boolean`){let t=this.ensureCheckbox();this.setActiveRenderer(t,this._justCreated),t.setValue(e.get(this._field));return}if(t===`combo`){this._currentOptions=this._cellValues?.(e)??[];let t=this.ensureRenderer(`combo`);t.setOptions(this._currentOptions),this.setActiveRenderer(t,this._justCreated),t.setValue(e.get(this._field));return}let n=this.ensureRenderer(t);this.setActiveRenderer(n,this._justCreated),n.setValue(e.get(this._field))}getEditorKey(){switch(this._activeType){case`number`:return`number`;case`date`:return`date`;case`time`:return this._showSeconds?`time:seconds`:`time`;case`datetime`:return this._showSeconds?`datetime:seconds`:`datetime`;case`combo`:return`combo:${this._field}`;case`boolean`:case`glyph`:return null;default:return`string`}}startEdit(){if(this._activeType===`boolean`){if(this.isReadOnly())return;this._checkbox?.toggle();return}super.startEdit()}setReadOnly(e){return super.setReadOnly(e),this._activeType===`boolean`&&this._checkbox?.setReadOnly(e),this}prepareEditor(e){this._activeType===`combo`&&e.setOptions(this._currentOptions)}ensureRenderer(e){let t=this._renderers.get(e);if(t)return this._justCreated=!1,t;let n=DynamicCell.buildRenderer(e,this._showSeconds);return this._renderers.set(e,n),this._justCreated=!0,n}static buildRenderer(e,t){switch(e){case`number`:return new k;case`date`:return new A;case`time`:return new j(t);case`datetime`:return new M(t);case`combo`:return new P([]);case`glyph`:return new N;default:return new O}}ensureCheckbox(){if(this._checkbox)return this._justCreated=!1,this._checkbox;let e=new D;return e.on(`change`,e=>this.emitCommit(e)),this._checkbox=e,this._justCreated=!0,e}emitCommit(e){this.emit(`commit`,e)}}),DefaultCell=class extends Cell{constructor(e){let t=new O;super(e||`td`,t)}getRenderer(){return super.getRenderer()}setValue(e){return this.getRenderer().setValue(e),this}},I=c(DefaultCell),StringCell=class extends Cell{constructor(){let e=new O;super(`td`,e)}getEditorKey(){return`string`}setValue(e){return this.getRenderer().setValue(e),this}},we=c(StringCell),BooleanCell=class extends Cell{_checkbox;constructor(){let e=new D;super(`td`,e,void 0,{fill:l.NONE,anchor:u.CENTER},void 0),this._checkbox=e}on(e,t){return e===`commit`?(this._checkbox.on(`change`,t),this):super.on(e,t)}off(e,t){return e===`commit`?(this._checkbox.off(`change`,t),this):super.off(e,t)}setReadOnly(e){return super.setReadOnly(e),this._checkbox.setReadOnly(e),this}startEdit(){this.isReadOnly()||this._checkbox.toggle()}setValue(e){return this.getRenderer().setValue(e),this}},Te=c(BooleanCell),NumberCell=class extends Cell{constructor(){let e=new k;super(`td`,e)}getEditorKey(){return`number`}setValue(e){return this.getRenderer().setValue(e),this}},Ee=c(NumberCell),DateCell=class extends Cell{constructor(){let e=new A;super(`td`,e)}getEditorKey(){return`date`}setValue(e){return this.getRenderer().setValue(e),this}commitEdit(){let e=this._activeEditor;return e&&!e.isEmpty()&&e.getValue()===null?(this.cancelEdit(),this):(super.commitEdit(),this)}},De=c(DateCell),TimeCell=class extends Cell{_showSeconds;constructor(e=!1){let t=new j(e);super(`td`,t),this._showSeconds=e}getEditorKey(){return this._showSeconds?`time:seconds`:`time`}setValue(e){return this.getRenderer().setValue(e),this}commitEdit(){let e=this._activeEditor;return e&&!e.isEmpty()&&e.getValue()===null?(this.cancelEdit(),this):(super.commitEdit(),this)}},Oe=c(TimeCell),DateTimeCell=class extends Cell{_showSeconds;constructor(e=!1){let t=new M(e);super(`td`,t),this._showSeconds=e}getEditorKey(){return this._showSeconds?`datetime:seconds`:`datetime`}setValue(e){return this.getRenderer().setValue(e),this}commitEdit(){let e=this._activeEditor;return e&&!e.isEmpty()&&e.getValue()===null?(this.cancelEdit(),this):(super.commitEdit(),this)}},L=c(DateTimeCell),GlyphCell=class extends Cell{constructor(){let e=new N;super(`td`,e)}setValue(e){return this.getRenderer().setValue(e),this}},R=c(GlyphCell),ComboCell=class extends Cell{_field;constructor(e,t){super(`td`,new P(t)),this._field=e}getEditorKey(){return`combo:${this._field}`}setValue(e){return this.getRenderer().setValue(e),this}},z=c(ComboCell);h.register(he,_e);var TreeCellRenderer=class extends CellRenderer{_toggle=null;_depth=0;_hasChildren=!1;_expanded=!1;constructor(e,t=16){super(),this._delegate=e,this._indentPx=t,this.setLayoutManager(new o),super.setInsets(new r(0,0,0,0)),this.addComponent(e)}getDelegate(){return this._delegate}getToggle(){return this._toggle}getDepth(){return this._depth}getContentX(){return this._depth*this._indentPx+20}getValue(){return this._delegate.getValue()}setValue(e){return this._delegate.setValue(e),this}setTreeState(e,t,n){return this._depth===e&&this._hasChildren===t&&this._expanded===n?this:(this._depth=e,this._hasChildren=t,this._expanded=n,this.refreshToggle(),this.doLayout(),this)}setInsets(e){return this._delegate?.setInsets(e),this}refreshToggle(){if(this._toggle&&=(this.removeComponent(this._toggle),null),!this._hasChildren)return;let e=new h(this._expanded?`caret-down`:`caret-right`);e.setCursor(`pointer`),e.clearInsets(),e.getAria().setHidden(!0),this._toggle=e,this.addComponent(e)}doLayout(){let e=this.getContentBounds()??{x:0,y:0,width:0,height:0},t=e.width,n=e.height,r=this._depth*this._indentPx;if(this._toggle){let t=this._toggle.getPreferredSize()?.height??n;this._toggle.setAutoCommitStyle(!1),this._toggle.setX(e.x+r),this._toggle.setY(e.y+Math.max(0,(n-t)/2)),this._toggle.setWidth(20),this._toggle.setHeight(t),this._toggle.setAutoCommitStyle(!0)}let i=r+20,a=Math.max(0,t-i);return this._delegate.setAutoCommitStyle(!1),this._delegate.setX(e.x+i),this._delegate.setY(e.y),this._delegate.setWidth(a),this._delegate.setHeight(n),this._delegate.setAutoCommitStyle(!0),super.doLayout(),this}},B=c(TreeCellRenderer),V=c(class Row extends f{_model;_data;_onCellCommit;_treeCell=null;_stripe=!1;_visibleFields=[];_columnConfigs=new Map;_treeFieldName;_windowFirst=0;_cellKeys=[];_fieldNames=[];_columnsDirty=!1;constructor(e,t,n=new Set,r=new Map,i,a){super({tag:`tr`}),this.getAria().setRole(`row`),this._model=e,this._data=t,this._onCellCommit=i,this._model&&this.setColumnFields(this._model,n,r,a)}getTreeCell(){return this._treeCell}getColumnWindowStart(){return this._windowFirst}getFieldNames(){return this._fieldNames}getData(){return this._data}setData(e){this._data=e;let t=this.getComponents(),n=this._fieldNames;for(let r=0;r<n.length;r++)this.bindCell(t[r],e,n[r]);return this.updateVisualState(),this}setStripe(e){this._stripe=e}updateVisualState(){let t=this.getElement();t&&(this._data?.isNew()?e.sink.apply(t,{style:{"background-color":`var(--ts-ui-table-row-new, rgba(70, 200, 70, 0.15))`}}):this._data?.isDirty()?e.sink.apply(t,{style:{"background-color":`var(--ts-ui-table-row-dirty, rgba(255, 165, 0, 0.15))`}}):this._stripe?e.sink.apply(t,{style:{"background-color":`var(--ts-ui-table-row-stripe, rgba(0, 0, 0, 0.035))`}}):e.sink.apply(t,{style:{"background-color":null}}))}addColumn(e,t){return this.addComponent(e,t),this}addComponent(e,t){return super.addComponent(e,t),this}setColumnFields(e,t,n,r){return this._model=e,this._visibleFields=e.getFields().filter(e=>!t.has(e.getName())).sort((e,t)=>e.getOrder()-t.getOrder()),this._columnConfigs=n,this._treeFieldName=r,this._columnsDirty=!0,this}setColumnWindow(e,t){let n=this._visibleFields.length-1;t=Math.min(t,n),e>t&&(e=t+1);let r=this._windowFirst+this.getComponents().length-1;if(!this._columnsDirty&&e===this._windowFirst&&t===r)return!1;let i=this.getComponents(),a=new Map;for(let e=0;e<i.length;e++){let t=this._fieldNames[e];t!==void 0&&a.set(t,{cell:i[e],key:this._cellKeys[e]})}let o=t-e+1,s=Array(o).fill(void 0),c=new Set;for(let n=e;n<=t;n++){let t=this._visibleFields[n],r=this.cellKeyFor(t),i=a.get(t.getName());i&&i.key===r&&(s[n-e]=i.cell,a.delete(t.getName()))}let l=new Map;for(let e of a.values()){let t=l.get(e.key);t?t.push(e.cell):l.set(e.key,[e.cell])}for(let n=e;n<=t;n++){let t=n-e;if(s[t]!==void 0)continue;let r=this._visibleFields[n],i=this.cellKeyFor(r),a=l.get(i),o;if(a&&a.length>0)o=a.pop(),this.setLayoutConstraints(o,{data:r});else{o=Row.createCellForField(r,this._columnConfigs),this._treeFieldName!==void 0&&r.getName()===this._treeFieldName&&o.wrapRenderer(e=>new B(e));let e=o;o.on(`commit`,t=>this.commitCellValue(e,t)),this.addComponent(o,{data:r})}s[t]=o,c.add(n)}for(let n=e;n<=t;n++){let t=s[n-e],r=this._visibleFields[n];t.getAria().setColIndex(n+1),t.setBaseBackground(this._columnConfigs.get(r.getName())?.groupColor??null),c.has(n)&&this.bindCell(t,this._data,r.getName())}for(let e of l.values())for(let t of e)t.isEditing()&&t.commitEdit(),this.removeComponent(t),t.dispose();let u=new Map(s.map((e,t)=>[e,t]));this.sortComponents((e,t)=>(u.get(e)??0)-(u.get(t)??0)),this._windowFirst=e,this._fieldNames=[],this._cellKeys=[],this._treeCell=null;for(let n=e;n<=t;n++){let t=this._visibleFields[n],r=s[n-e];this._fieldNames.push(t.getName()),this._cellKeys.push(this.cellKeyFor(t)),this._treeFieldName!==void 0&&t.getName()===this._treeFieldName&&(this._treeCell=r)}return this._columnsDirty=!1,!0}commitCellValue(e,t){let n=this.getLayoutConstraints(e)?.data;n&&(this._data&&(this._data.set(n.getName(),t),this._onCellCommit?.(this._data)),this.updateVisualState())}static cellKey(e,t,n){if(n)return`tree:${e.getName()}`;if(t?.renderer)return`renderer:${e.getName()}`;if(t?.cellType)return`dynamic:${e.getName()}`;if(t?.values&&t.values.length>0)return`combo:${e.getName()}`;let r=e.getType();return r===`time`||r===`datetime`?`${r}:${t?.showSeconds??!1}`:r}cellKeyFor(e){let t=this._treeFieldName!==void 0&&e.getName()===this._treeFieldName;return Row.cellKey(e,this._columnConfigs.get(e.getName()),t)}bindCell(e,t,n){e instanceof F&&t?e.bindRecord(t):e.setValue(t?t.get(n):void 0)}static createCellForField(e,t){let n=t.get(e.getName());if(n?.renderer)return new Cell(`td`,n.renderer());if(n?.cellType)return new F(e.getName(),e.getType(),n);let r=n?.values;if(r&&r.length>0)return new z(e.getName(),r);switch(e.getType()){case`string`:return new we;case`number`:return new Ee;case`boolean`:return new Te;case`date`:return new De;case`time`:return new Oe(t.get(e.getName())?.showSeconds??!1);case`datetime`:return new L(t.get(e.getName())?.showSeconds??!1);case`glyph`:return new R;default:return new I}}doLayout(){return this}}),ke=`var(--ts-ui-table-resize-handle-cursor, ew-resize)`,Ae=null;function ensureResizeHandleClassRule(){Ae||=new a({scope:`class`,name:`ResizeHandle`,styles:{position:`absolute`,top:`0`,right:`0`,width:`var(--ts-ui-table-resize-handle-width,5px)`,height:`100%`,zIndex:`1`}})}var ResizeHandle=class extends f{_listeners=new p;constructor(e){ensureResizeHandleClassRule(),super({tag:`div`,...e??{}}),this.setCursor(ke),this.setBackgroundImage(`linear-gradient(to right,transparent 80%,var(--ts-ui-table-resize-handle-color,rgba(0,0,0,0.2)) 80%)`),this.setZIndex(1),this.applyListeners(e?.listeners)}init(e){return super.init(e),i.addListener(this,`mousedown`,this._onMouseDown),i.addListener(this,`click`,this._onClick),this}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}dragMove(e){this.emit(`dragmove`,e)}dragEnd(){this.emit(`dragend`)}_onMouseDown=e=>(this.emit(`dragstart`,e),!0);_onClick=()=>!0},je=c(ResizeHandle),Me=null;function ensureSortBadgeClassRule(){Me||=new a({scope:`class`,name:`SortPriorityBadge`,styles:{position:`absolute`,top:`2px`,right:`8px`,fontSize:`var(--ts-ui-sort-badge-font-size, var(--ts-ui-font-size))`,lineHeight:`1`,borderRadius:`3px`,padding:`1px 3px`,pointerEvents:`none`}})}var SortPriorityBadge=class extends f{constructor(e){ensureSortBadgeClassRule(),super({tag:`span`,...e??{}}),this._priority??=null,this.setBackgroundColor(`var(--ts-ui-sort-badge-bg, rgba(0,0,0,0.15))`),this.setForegroundColor(`var(--ts-ui-sort-badge-color, inherit)`),this.setVisible(this._shouldShow(this._priority))}applyOptions(e){return super.applyOptions(e),e.priority!==void 0&&(this._priority=e.priority),this}render(){let t=super.render();return e.sink.apply(t,{text:this._priorityText()}),t}getPriority(){return this._priority}setPriority(t){this._priority=t;let n=this.getElement();return n&&e.sink.apply(n,{text:this._priorityText()}),this.setVisible(this._shouldShow(t)),this}clearPriority(){return this.setPriority(null)}_priorityText(){return this._shouldShow(this._priority)?String(this._priority):``}_shouldShow(e){return e!=null&&e>=2}},Ne=c(SortPriorityBadge),Pe=16,Fe=16,Ie=null;function ensureHeaderCellGlyphClassRule(){Ie||=new a({scope:`class`,name:`HeaderCellGlyph`,styles:{position:`absolute`,left:`var(--ts-ui-table-header-glyph-gap, 4px)`,top:`50%`}})}var HeaderCell=class extends I{_text;_fieldName;_isDragging=!1;_tooltipText=``;_sortState=null;_headerGlyph=null;_headerGlyphInstance=null;_columnFocused=!1;_required=!1;constructor(e,t,n){super(`th`),this.getAria().setRole(`columnheader`),this.getAria().setSort(`none`),this._text=e,this._fieldName=t,this._headerGlyph=n??null;let r=this.getRenderer();r.getText().setFontSize(`--ts-ui-table-header-font-size`),r.getText().setFontWeight(`bold`),r.getText().setText(e),this.createStyleRule(`:active`).set(`boxShadow`,`var(--ts-ui-button-pressed-shadow, 1px 2px 5px 0 rgba(0,0,0,0.2) inset)`),this._resizeHandle=new je({listeners:{dragstart:e=>this.onResizeDragStart(e),dragmove:e=>this.emit(`resizedrag`,e)}}),this._priorityBadge=new Ne}init(t){super.init(t);let n=t||this.getElement();return n?(i.addSubtreeListener(this,`click`,e=>this.onSortClick(e.shiftKey)),i.addSubtreeListener(this,`contextmenu`,e=>{e.preventDefault(),this.emit(`contextmenu`,this._fieldName,e.clientX,e.clientY)}),e.sink.appendChild(n,this._resizeHandle.getElement(!0)),e.sink.appendChild(n,this._priorityBadge.getElement(!0)),this._tooltipText&&_.attachToElement(n,this._tooltipText),this._headerGlyph&&this.setHeaderGlyph(this._headerGlyph),this):this}setFieldName(e){return this._fieldName=e,this}getFieldName(){return this._fieldName}getHeaderGlyph(){return this._headerGlyph}setHeaderGlyph(e){return this._headerGlyph=e,this._mountHeaderGlyph(this.getElement()),this.doLayout(),this}_mountHeaderGlyph(t){this._headerGlyphInstance&&=(this._headerGlyphInstance.dispose(),null);let n=d.getTheme().table.cell.padding,i=this._headerGlyph;if(!i||!t){this.getRenderer().setInsets(new r(0,n,0,n));return}ensureHeaderCellGlyphClassRule();let a=new h(i);a.setTransform(`translateY(-50%)`),a.setSize({width:Pe,height:Fe}),a.setForegroundColor(`var(--ts-ui-table-header-glyph-color, currentColor)`),a.setPointerEvents(`none`);let o=a.getElement(!0);e.sink.apply(o,{addClass:[`HeaderCellGlyph`]}),e.sink.appendChild(t,o),this._headerGlyphInstance=a;let s=20+n;this.getRenderer().setInsets(new r(0,n,0,s))}setSortState(e,t){return this._sortState={state:e,priority:t??null},this._renderTitle(),this.getAria().setSort(e===`asc`?`ascending`:`descending`),this._priorityBadge.setPriority(t??null),this}getSortState(){return this._sortState}clearSortState(){return this._sortState=null,this._renderTitle(),this.getAria().setSort(`none`),this._priorityBadge.clearPriority(),this}setRequired(e){return this._required=e,this._renderTitle(),this}setHeaderText(e){return this._text===e?this:(this._text=e,this._renderTitle(),this)}_renderTitle(){let e=this._sortState?this._sortState.state===`asc`?` ▲`:` ▼`:``,t=this._required?` *`:``;this.getRenderer().getText().setText(this._text+t+e)}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}setTooltip(e){this._tooltipText=e;let t=this.getElement();return t&&_.attachToElement(t,e),this}getTooltip(){return this._tooltipText}onSortClick(e){if(this._isDragging){this._isDragging=!1;return}this.emit(`sortclick`,this._fieldName,e)}onResizeDragStart(e){e.stopPropagation(),this._isDragging=!0,this.emit(`resizestart`,e.clientX),i.addViewportListener(this,`mousemove`,this.onResizeDrag),i.addViewportListener(this,`mouseup`,this.onResizeDragStop),te(ke)}onResizeDrag(e){return this._resizeHandle.dragMove(e.clientX),!0}onResizeDragStop(){return i.removeViewportListener(this,`mousemove`,this.onResizeDrag),i.removeViewportListener(this,`mouseup`,this.onResizeDragStop),ne(),this._resizeHandle.dragEnd(),setTimeout(()=>{this._isDragging=!1},0),!0}setColumnFocused(e){return this._columnFocused=e,e?this.setShadow(`inset 0 -2px 0 0 var(--ts-ui-focus-ring, rgba(30, 100, 200, 0.6))`):this.clearShadow(),this}isColumnFocused(){return this._columnFocused}destructor(){this._resizeHandle?.dispose(),this._priorityBadge?.dispose(),this._headerGlyphInstance?.dispose(),super.destructor()}},Le=c(HeaderCell),ParentHeaderCell=class extends I{_text;_color;_tooltipText=``;constructor(e,t){super(`th`),this._text=e,this._color=t,this.getAria().setRole(`columnheader`);let n=this.getRenderer();n.getText().setFontSize(`--ts-ui-table-header-font-size`),n.getText().setFontWeight(`bold`),n.getText().setTextAlign(`center`),n.getText().setText(e),this.setBackgroundColor(t??`transparent`),this.setShadow([`inset -1px 0 0 0 var(--ts-ui-table-resize-handle-color, rgba(0, 0, 0, 0.2))`,`inset 0 -1px 0 0 var(--ts-ui-table-resize-handle-color, rgba(0, 0, 0, 0.2))`].join(`, `))}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}setTooltip(e){this._tooltipText=e;let t=this.getElement();return t&&_.attachToElement(t,e),this}getTooltip(){return this._tooltipText}getText(){return this._text}getColor(){return this._color}init(e){super.init(e);let t=e||this.getElement();return t?(i.addSubtreeListener(this,`contextmenu`,this.onContextMenu),this._tooltipText&&_.attachToElement(t,this._tooltipText),this):this}onContextMenu(e){e.preventDefault(),this.emit(`contextmenu`,e.clientX,e.clientY)}},Re=c(ParentHeaderCell),CellGeometryCache=class{_geometry=new WeakMap;clear(){this._geometry=new WeakMap}apply(e,t,n,r){let i=this._geometry.get(e);i&&i.x===t&&i.w===n&&i.h===r||(e.setAutoCommitStyle(!1),e.setX(t),e.setY(0),e.setWidth(n),e.setHeight(r),e.setAutoCommitStyle(!0),e.doLayout(),e.getElement()&&this._geometry.set(e,{x:t,w:n,h:r}))}},StringEditor=class extends CellEditor{_textField=new T;_value=null;constructor(){super(),i.addListener(this._textField,`blur`,e=>{i.fireEvent(this,`blur`,e)}),i.addListener(this._textField,`keydown`,e=>{i.fireEvent(this,`keydown`,{detail:{key:e.key,code:e.code,keyCode:e.keyCode,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}})}),i.addListener(this._textField,`input`,()=>this.onInput()),this._textField.setMaxSize({width:2**53-1,height:2**53-1}),this._textField.clearPadding(),this._textField.setBorderRadius(`0`),this._textField.setBorder({border:`0px solid transparent`}),this._textField.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this._textField.setOutline(`none`),this._textField.setText(``),this.addComponent(this._textField)}getValue(){return this._value}setValue(e){return this._value=e??null,this._textField.setText(this._value===null?``:String(this._value)),this}focus(e=!1){return this._textField.focus(e),this._textField.select(),this}onInput(){let e=this._textField.getText();this._value=e||null}},ze=c(StringEditor),NumberEditor=class extends CellEditor{_textField=new T;_value=null;constructor(){super(),i.addListener(this._textField,`blur`,e=>{i.fireEvent(this,`blur`,e)}),i.addListener(this._textField,`keydown`,e=>{i.fireEvent(this,`keydown`,{detail:{key:e.key,code:e.code,keyCode:e.keyCode,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}})}),i.addListener(this._textField,`input`,()=>this.onInput()),this.setMaxSize({width:2**53-1,height:2**53-1}),this._textField.setMaxSize({width:2**53-1,height:2**53-1}),this._textField.clearPadding(),this.setBorderRadius(`0`),this._textField.setBorder({border:`0px solid transparent`}),this._textField.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this._textField.setOutline(`none`),this._textField.setTextAlign(`right`),this._textField.setText(``),this.addComponent(this._textField,{anchor:u.NORTHEAST})}getValue(){return this._value}setValue(e){return this._value=e??null,this._textField.setText(this._value===null?``:String(this._value)),this}focus(e=!1){return this._textField.focus(e),this._textField.select(),this}onInput(){let e=this._textField.getText();if(!e){this._value=null;return}let t=Number(e);this._value=isNaN(t)?null:t}},Be=c(NumberEditor),TextInputCellEditor=class extends CellEditor{_type=null;_inputMode=null;_autoComplete=null;constructor(){super(`input`)}setType(e){return this._type=e,this.setElementAttribute(`type`,e),this}setInputMode(e){return this._inputMode=e,this.setElementAttribute(`inputmode`,e),this}setAutoComplete(e){return this._autoComplete=e,this.setElementAttribute(`autocomplete`,e),this}init(t){super.init(t);let n=t||this.getElement();return this._type!==null&&e.sink.apply(n,{setAttr:{type:this._type}}),this._inputMode!==null&&e.sink.apply(n,{setAttr:{inputmode:this._inputMode}}),this._autoComplete!==null&&e.sink.apply(n,{setAttr:{autocomplete:this._autoComplete}}),this}},DateEditor=class extends TextInputCellEditor{_value=null;_dropdown=null;_animated=!0;_text=``;constructor(){super(),this.setMaxSize({width:2**53-1,height:2**53-1}),this.setBorderRadius(`0`),this.setBorder({border:`0px solid transparent`}),this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this.setOutline(`none`),i.addListener(this,`focus`,()=>this.openDropdown()),i.addListener(this,`blur`,()=>this.closeDropdown()),i.addListener(this,`input`,()=>this.onInput()),this.setType(`text`),this.setInputMode(`none`),this.setAutoComplete(`off`)}isEmpty(){return!this.getText()&&this._value===null}getValue(){return this._value}setValue(e){return this._value=e,this.setText(e?this.toInputString(e):``),this}setText(t){this._text=t;let n=this.getElement();return n&&e.sink.setValue(n,t),this}getText(){return this._text}syncTextFromDom(){let t=this.getElement();this._text=t?e.source.getValue(t):``}setDropdownAnimated(e){return this._animated=e,this._dropdown&&this._dropdown.setAnimated(e),this}isDropdownAnimated(){return this._animated}ensureDropdown(){return this._dropdown||(this._dropdown=new fe(e=>this.onDateSelected(e)),this._dropdown.setAnimated(this._animated)),this._dropdown}openDropdown(){let e=this.ensureDropdown();if(e.isOpen())return;let t=this.getElement();t&&e.showAt(t,this._value)}closeDropdown(){this._dropdown?.isOpen()&&this._dropdown.hideAnimated()}onInput(){this.syncTextFromDom();let e=this.getText();if(!e){this._value=null;return}let t=new Date(e+`T00:00:00`);this._value=isNaN(t.getTime())?null:t}onDateSelected(t){this.setValue(t),this._dropdown?.hideAnimated();let n=this.getElement();n&&e.sink.blur(n)}toInputString(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}},Ve=c(DateEditor),TimeEditor=class extends TextInputCellEditor{_showSeconds;_value=null;_dropdown=null;_animated=!0;_text=``;constructor(e=!1){super(),this._showSeconds=e,this.setMaxSize({width:2**53-1,height:2**53-1}),this.setBorderRadius(`0`),this.setBorder({border:`0px solid transparent`}),this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this.setOutline(`none`),i.addListener(this,`focus`,()=>this.openDropdown()),i.addListener(this,`blur`,()=>this.closeDropdown()),i.addListener(this,`input`,()=>this.onInput()),this.setType(`text`),this.setInputMode(`none`),this.setAutoComplete(`off`)}isEmpty(){return!this.getText()&&this._value===null}getValue(){return this._value}setValue(e){return this._value=e,this.setText(e?this.toInputString(e):``),this}setText(t){this._text=t;let n=this.getElement();return n&&e.sink.setValue(n,t),this}getText(){return this._text}syncTextFromDom(){let t=this.getElement();this._text=t?e.source.getValue(t):``}setDropdownAnimated(e){return this._animated=e,this._dropdown&&this._dropdown.setAnimated(e),this}isDropdownAnimated(){return this._animated}ensureDropdown(){return this._dropdown||(this._dropdown=new le((e,t,n)=>this.onTimeSelected(e,t,n),{showSeconds:this._showSeconds}),this._dropdown.setAnimated(this._animated)),this._dropdown}openDropdown(){let e=this.ensureDropdown();if(e.isOpen())return;let t=this.getElement();t&&e.showAt(t,this._value)}closeDropdown(){this._dropdown?.isOpen()&&this._dropdown.hideAnimated()}onInput(){this.syncTextFromDom();let e=this.getText();if(!e){this._value=null;return}let t=e.split(`:`).map(Number);if(t.some(isNaN)){this._value=null;return}this._value=new Date(1970,0,1,t[0],t[1]??0,t[2]??0)}onTimeSelected(e,t,n){let r=new Date(1970,0,1,e,t,n,0);this.setValue(r)}toInputString(e){let t=String(e.getHours()).padStart(2,`0`),n=String(e.getMinutes()).padStart(2,`0`);return this._showSeconds?`${t}:${n}:${String(e.getSeconds()).padStart(2,`0`)}`:`${t}:${n}`}},H=c(TimeEditor),DateTimeEditor=class extends TextInputCellEditor{_showSeconds;_value=null;_dropdown=null;_animated=!0;_text=``;constructor(e=!1){super(),this._showSeconds=e,this.setMaxSize({width:2**53-1,height:2**53-1}),this.setBorderRadius(`0`),this.setBorder({border:`0px solid transparent`}),this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this.setOutline(`none`),i.addListener(this,`focus`,()=>this.openDropdown()),i.addListener(this,`blur`,e=>this.onEditorBlur(e)),i.addListener(this,`input`,()=>this.onInput()),this.setType(`text`),this.setInputMode(`none`),this.setAutoComplete(`off`)}retainsFocus(e){return this._dropdown!==null&&this._dropdown.isOpen()&&g.containsAcrossLayers(this._dropdown,e)}isEmpty(){return!this.getText()&&this._value===null}getValue(){return this._value}setValue(e){return this._value=e,this.setText(e?this.toInputString(e):``),this}setText(t){this._text=t;let n=this.getElement();return n&&e.sink.setValue(n,t),this}getText(){return this._text}syncTextFromDom(){let t=this.getElement();this._text=t?e.source.getValue(t):``}setDropdownAnimated(e){return this._animated=e,this._dropdown&&this._dropdown.setAnimated(e),this}isDropdownAnimated(){return this._animated}ensureDropdown(){return this._dropdown||(this._dropdown=new pe(e=>this.onDateTimeSelected(e),{showSeconds:this._showSeconds}),this._dropdown.setAnimated(this._animated)),this._dropdown}openDropdown(){let e=this.ensureDropdown();if(e.isOpen())return;let t=this.getElement();t&&(e.setCloseHandler(()=>this.onOutsideDismiss()),e.setAnchorElement(t),e.showAt(t,this._value))}closeDropdown(){this._dropdown?.isOpen()&&this._dropdown.hideAnimated()}onOutsideDismiss(){this.closeDropdown(),this.requestCommit()}onEditorBlur(e){this.retainsFocus(blurRelatedTargetHandle(e))||this.closeDropdown()}onInput(){this.syncTextFromDom();let e=this.getText();if(!e){this._value=null;return}let t=new Date(e.replace(` `,`T`));this._value=isNaN(t.getTime())?null:t}onDateTimeSelected(e){this.setValue(e)}toInputString(e){let t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,`0`),r=String(e.getDate()).padStart(2,`0`),i=String(e.getHours()).padStart(2,`0`),a=String(e.getMinutes()).padStart(2,`0`);return this._showSeconds?`${t}-${n}-${r} ${i}:${a}:${String(e.getSeconds()).padStart(2,`0`)}`:`${t}-${n}-${r} ${i}:${a}`}},U=c(DateTimeEditor),CellEditorPool=class{_editors=new Map;_factories=new Map;_activeCell=null;constructor(){this._factories.set(`string`,()=>new ze),this._factories.set(`number`,()=>new Be),this._factories.set(`date`,()=>new Ve),this._factories.set(`time`,()=>new H(!1)),this._factories.set(`time:seconds`,()=>new H(!0)),this._factories.set(`datetime`,()=>new U(!1)),this._factories.set(`datetime:seconds`,()=>new U(!0))}register(e,t){return this._factories.set(e,t),this._editors.delete(e),this}acquire(e,t){let n=this._factories.get(e);if(!n)return null;let r=this._editors.get(e);return r||(r=n(),this.wireListeners(r),this._editors.set(e,r)),this._activeCell=t,r}release(){this._activeCell=null}wireListeners(e){e.setCommitRequestHandler(()=>this._activeCell?.commitEdit()),i.addListener(e,`blur`,t=>{e.retainsFocus(blurRelatedTargetHandle(t))||this._activeCell?.commitEdit()}),i.addListener(e,`keydown`,e=>{this._activeCell?.onKeyDown(e)})}},ComboEditor=class extends CellEditor{_combo;_value=null;constructor(e){super(`div`);let t=normalizeComboOptions(e).map(e=>({key:e.value,label:e.label}));this._combo=new me,this._combo.setItems(t),this._combo.setBorder({border:`0px solid transparent`}),this._combo.setBorderRadius(`0`),this._combo.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this._combo.on(`action`,()=>this.commitFromCombo()),i.addListener(this._combo,`blur`,()=>this.commitFromCombo()),i.addListener(this._combo,`keydown`,e=>{i.fireEvent(this,`keydown`,{detail:{key:e.key,code:e.code,keyCode:e.keyCode,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}})}),this.addComponent(this._combo)}getValue(){return this._value}setValue(e){return this._value=e??null,this._combo.setValue(this._value===null?``:String(this._value)),this}focus(e=!1){return this._combo.focus(e),this._combo.openDropdown(),this}setOptions(e){let t=normalizeComboOptions(e).map(e=>({key:e.value,label:e.label}));return this._combo.setItems(t),this._combo.setValue(this._value===null?``:String(this._value)),this}commitFromCombo(){let e=this._combo.getValue();this._value=e||null,this.requestCommit()}},W=c(ComboEditor);function resolveClickedColumn(t,n){for(let r=0;r<t.length;r++){let i=t[r].getElement();if(i&&(i===n||e.source.contains(i,n)))return r}return-1}var He=2;function computeColumnWindow(e,t,n){let r=e.length,i=Array(r),a=0;for(let t=0;t<r;t++)i[t]=a,a+=e[t];if(r===0)return{firstCol:0,lastCol:-1,widths:e,lefts:i};let o=t+n,s=-1,c=-1;for(let n=0;n<r;n++){let r=i[n];r+e[n]>=t&&r<=o&&(s===-1&&(s=n),c=n)}return s===-1&&(s=0,c=0),{firstCol:Math.max(0,s-He),lastCol:Math.min(r-1,c+He),widths:e,lefts:i}}function columnWidthsEqual(e,t){if(!t)return e.length===0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var Ue=class Body extends ve{_store;_hiddenColumns=new Set;_columns=[];_columnConfigs=new Map;_rowReadOnly=null;_cellGeom=new CellGeometryCache;_lastBodyWidth=0;_lastColumnWidths=[];_lastAriaRowCount=-1;_rowHeight;_colWindow={firstCol:0,lastCol:-1,widths:[],lefts:[]};_reconciling=!1;_storeRefresh=null;_selectedRecords=new Set;_anchorRecord=null;_focusedColIndex=0;_editorPool=new CellEditorPool;_header=null;_listeners=new p;constructor(e){super({tag:`tbody`}),this.setOverflow(`hidden`),this.setBackgroundColor(`var(--ts-ui-input-bg, rgb(255, 255, 255))`),this.getAria().setTabIndex(0),this.getAria().setRole(`rowgroup`),this._store=e,this.bindStore(e),this._rowHeight=this.computeRowHeight(),this.subscribeTheme(()=>this.onThemeReflow())}onThemeReflow(){this._rowHeight=this.computeRowHeight(),super.onThemeReflow()}computeRowHeight(){let e=d.getTheme();return n.lineHeightPx()+2*(e.table.cell.padding??2)}getRowHeight(){return this._rowHeight}createPoolRow(){let e=this.createRow();return e.setColumnWindow(this._colWindow.firstCol,this._colWindow.lastCol),this.wireRowCells(e),e}wireRowCells(e){for(let t of e.getComponents())t.setEditorPool(this._editorPool),t.setScrollIntoViewHandler(()=>this.scrollColumnIntoView(this._focusedColIndex))}bindStore(e){let refresh=()=>this.onStoreChange();this._storeRefresh=refresh,e.on(`load`,refresh),e.on(`add`,refresh),e.on(`remove`,refresh),e.on(`datachange`,refresh),e.on(`beforesync`,refresh),e.on(`sync`,refresh)}onStoreChange(){this._boundIndices.fill(-1),this.renderWindow()}getVisibleRecords(){return this._store.getRecords()}createRow(){return new V(this._store.model,void 0,this._hiddenColumns,this._columnConfigs,e=>this._store.notifyRecordChanged(e))}getTreeFieldName(){}computeRowAria(e,t){e.getAria().setRowIndex(t+2)}afterRowBound(e,t,n){}invalidateRowBindings(){this._boundIndices.fill(-1)}getStore(){return this._store}getHiddenColumns(){return this._hiddenColumns}getColumnConfigs(){return this._columnConfigs}getRowPool(){return this._rowPool}invalidateGeom(){super.invalidateGeom(),this._cellGeom.clear()}setHiddenColumns(e){let t=new Set;for(let n of e){let e=this._columns.find(e=>e.getField().getName()===n);(!e||!e.isUnhideable())&&t.add(n)}return this._hiddenColumns=t,this.syncPoolCells(),this.renderWindow(),this}setColumns(e){return this._columns=e,this.syncPoolCells(),this.renderWindow(),this}setRowReadOnly(e){return this._rowReadOnly=e,this}setColumnConfigs(e){return this._columnConfigs=e,this.registerComboEditors(e),this.syncPoolCells(),this.renderWindow(),this}registerComboEditors(e){for(let[t,n]of e){let e=n.values;e&&e.length>0?this._editorPool.register(`combo:${t}`,()=>new W(e)):n.cellValues&&this._editorPool.register(`combo:${t}`,()=>new W([]))}}syncPoolCells(){if(!this._reconciling){this._reconciling=!0;try{this.commitEditsOutsideWindow(null);let e=this.getTreeFieldName();for(let t=0;t<this._rowPool.length;t++){let n=this._rowPool[t];n.setColumnFields(this._store.model,this._hiddenColumns,this._columnConfigs,e),this.wireRowCells(n),this._rowGeom[t]=null}}finally{this._reconciling=!1}}}setStore(e){if(this._storeRefresh){let e=this._store;[`load`,`add`,`remove`,`datachange`,`beforesync`,`sync`].forEach(t=>e.off(t,this._storeRefresh))}return this._store=e,this.bindStore(e),this.invalidateGeom(),this.getElement()&&this.onStoreChange(),this}init(e){super.init(e);let t=e||this.getElement();return t?(this.initScroller(t),i.addListener(this,`focus`,this.onFocus),i.addListener(this,`keydown`,this.onKeyDown),i.addSubtreeListener(this,`click`,this.onSubtreeClick),this.renderWindow(),this):this}onScrollerTick(){this.renderWindow(),!this.wasRenderDeferred()&&this._scroller&&(this.emit(`verticalscroll`,this._scroller.getScrollY()),this.emit(`horizontalscroll`,this._scroller.getScrollX()))}onFocus(){this._updateActiveDescendant(),this._updateFocusStyle()}getEditorPool(){return this._editorPool}doLayout(){return super.doLayout(),this.renderWindowIfDeferred(),this}renderWindow(e,t){if(this.updateColumnWidthCache(e,t),!this._reconciling&&!(!this.getElement()||!this._scroller)&&!this.deferRenderWhileFirstLayoutHeld()){this._reconciling=!0;try{this.renderWindowPass()}finally{this._reconciling=!1}this.finishResumedRender()}}renderWindowPass(){let e=this._scroller,t=this.getVisibleRecords(),n=t.length,r=e.getScrollX(),i=e.getScrollY(),a=n*this._rowHeight,o=this._lastColumnWidths.reduce((e,t)=>e+t,0),s=Math.max(this._lastBodyWidth,o);e.clampToContent(s,a);let c=Math.max(this._lastBodyWidth,o),l=this._store.model.getFields().filter(e=>!this._hiddenColumns.has(e.getName())).length,u=l>0?c/l:c,d=Array.from({length:l},(e,t)=>this._lastColumnWidths[t]??u);this._colWindow=computeColumnWindow(d,e.getScrollX(),this.getWidth()||0),this.commitEditsOutsideWindow(this._colWindow)&&(t=this.getVisibleRecords(),n=t.length,a=n*this._rowHeight);let f=this.getHeight()||0,p=this.computeVisibleWindow(e.getScrollY(),f,n),m=this.computePoolTarget(p.windowSize,f,n);this.growRowPool(m),this.bindAndPositionRows(p.firstRow,p.windowSize,c,t,this._colWindow),this.hideExcessPoolRows(p.windowSize),n!==this._lastAriaRowCount&&(this.getAria().setRowCount(n),this._lastAriaRowCount=n),e.layoutScrollbars(s,a);let h=e.getScrollX(),g=e.getScrollY();h!==r&&this.emit(`horizontalscroll`,h),g!==i&&this.emit(`verticalscroll`,g),this._updateFocusStyle()}updateColumnWidthCache(e,t){if(e===void 0)return;let n=this._lastBodyWidth!==e||!columnWidthsEqual(this._lastColumnWidths,t);this._lastBodyWidth=e,this._lastColumnWidths=t??[],n&&this.invalidateGeom()}commitEditsOutsideWindow(e){let t=!1;for(let n of this._rowPool){let r=n.getComponents(),i=n.getColumnWindowStart();for(let n=0;n<r.length;n++){let a=i+n;(e===null||a<e.firstCol||a>e.lastCol)&&r[n].isEditing()&&(r[n].commitEdit(),t=!0)}}return t}bindAndPositionRows(e,t,n,r,i){let a=this._rowHeight;for(let o=0;o<t;o++){let t=this._rowPool[o],s=t.setColumnWindow(i.firstCol,i.lastCol);s&&this.wireRowCells(t);let c=e+o,l=this._boundIndices[o]!==c;l&&(t.setData(r[c]),this._boundIndices[o]=c,t.setStripe(c%2==1),this.updateRowVisualState(o),this.computeRowAria(t,c)),(l||s)&&this.applyReadOnlyState(t,r[c]),this.afterRowBound(t,c,l),this.applyRequiredEmptyState(t,r[c]),this.positionRow(o,c*a,n);let u=t.getComponents(),d=i.lefts[i.firstCol]??0;for(let e=0;e<u.length;e++){let t=i.widths[i.firstCol+e]??0;this._cellGeom.apply(u[e],d,t,a),d+=t}}}onSubtreeClick(t){if(!(t instanceof MouseEvent))return;let n=t.target===null?null:e.source.intern(t.target);for(;n;){let r=this._rowPool.find(e=>e.getElement()===n);if(r){this.onRowClick(r,t);return}n=e.source.getParentElement(n)}}onRowClick(t,n){let r=t.getData()??null;if(!r)return;let i=this.getVisibleRecords(),a=new Set(this._selectedRecords);this._anchorRecord=ge(this._selectedRecords,this._anchorRecord,r,e=>i.indexOf(e),e=>i[e],{ctrl:n.ctrlKey||n.metaKey,shift:n.shiftKey}),this._boundIndices.forEach((e,t)=>{e!==-1&&this.updateRowVisualState(t)}),this.notifySelectionChange(a);let o=n.target===null?null:e.source.intern(n.target),s=resolveClickedColumn(t.getComponents(),o),c=s>=0?s+t.getColumnWindowStart():-1;c>=0&&(this._focusedColIndex=c);let l=o===null?``:e.source.getTagName(o);if(l!==`INPUT`&&l!==`TEXTAREA`&&l!==`SELECT`&&this.focus(),this._updateFocusStyle(),this._updateActiveDescendant(),c>=0){let e=t.getFieldNames()[s];this.emit(`cellclick`,{record:r,field:e,columnIndex:c,value:r.get(e),rowIndex:this.getVisibleRecords().indexOf(r),event:n})}}selectRecord(e){let t=new Set(this._selectedRecords);this._selectedRecords.clear(),this._anchorRecord=e,e&&this._selectedRecords.add(e),this._boundIndices.forEach((e,t)=>{e!==-1&&this.updateRowVisualState(t)}),this.notifySelectionChange(t)}getSelectedRecord(){return this._anchorRecord&&this._selectedRecords.has(this._anchorRecord)?this._anchorRecord:this._selectedRecords.size>0?[...this._selectedRecords][0]:null}getSelectedRecords(){return[...this._selectedRecords]}setSelectedRecords(e){let t=new Set(this._selectedRecords);this._selectedRecords.clear(),this._anchorRecord=e.length>0?e[0]:null;for(let t of e)this._selectedRecords.add(t);this._boundIndices.forEach((e,t)=>{e!==-1&&this.updateRowVisualState(t)}),this.notifySelectionChange(t)}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,t){this._listeners.fire(e,t)}notifySelectionChange(e){ye(e,this._selectedRecords)||this.emit(`selection`,this.getSelectedRecords())}scrollToRecord(e){let t=this.getVisibleRecords().indexOf(e);t!==-1&&this.setScrollY(t*this._rowHeight)}applyReadOnlyState(e,t){let n=this._rowReadOnly?.(t)===!0,r=e.getComponents(),i=e.getFieldNames();for(let e=0;e<r.length;e++){let a=r[e],o=i[e],s=this._columnConfigs.get(o),c=s?.readOnly===!0,l=s?.cellReadOnly?.(t)===!0,u=c||n||l;a.setReadOnly(u)}}static isEmptyValue(e){return e==null||e===``}applyRequiredEmptyState(e,t){let n=e.getComponents(),r=e.getFieldNames();for(let e=0;e<n.length;e++){let i=r[e],a=this._columnConfigs.get(i),o=a?.required===!0||a?.requiredPredicate?.(t)===!0,s=Body.isEmptyValue(t.get(i));n[e].setRequiredEmpty(o&&s)}}updateRowVisualState(t){let n=this._boundIndices[t];if(n===-1)return;let r=this.getVisibleRecords()[n];if(!r)return;let i=this._rowPool[t],a=i.getElement(),o=this._selectedRecords.has(r);o?e.sink.apply(a,{style:{"background-color":`var(--ts-ui-table-row-selected, rgba(30, 100, 200, 0.15))`,"box-shadow":`var(--ts-ui-table-row-selected-border, none)`}}):(e.sink.apply(a,{style:{"box-shadow":null}}),i.updateVisualState()),i.getAria().setSelected(o)}setHeader(e){return this._header=e,this}_updateFocusStyle(){for(let t of this._rowPool)for(let n of t.getComponents()){let t=n.getElement();t&&e.sink.apply(t,{style:{outline:null,"outline-offset":null}})}if(this._header?.setFocusedColumn(this._anchorRecord?this._focusedColIndex:null),!this._anchorRecord)return;let t=this.getVisibleRecords().indexOf(this._anchorRecord),n=this._boundIndices.indexOf(t);if(n<0)return;let r=this._rowPool[n],i=r.getComponents(),a=this._focusedColIndex-r.getColumnWindowStart(),o=a>=0&&a<i.length?i[a]:void 0;if(o){let t=o.getElement();t&&e.sink.apply(t,{style:{outline:`var(--ts-ui-indicator-selection, 1px dashed rgb(120, 170, 240))`,"outline-offset":`-1px`}})}}_updateActiveDescendant(){if(!this._anchorRecord){this.getAria().setActiveDescendant(``);return}let e=this.getVisibleRecords().indexOf(this._anchorRecord),t=this._boundIndices.indexOf(e);if(t<0){this.getAria().setActiveDescendant(``);return}let n=this._rowPool[t],r=n.getComponents(),i=this._focusedColIndex-n.getColumnWindowStart(),a=i>=0&&i<r.length?r[i]:void 0;a?this.getAria().setActiveDescendant(a.getId()):this.getAria().setActiveDescendant(this._rowPool[t].getId())}onKeyDown(e){let t=this.getVisibleRecords();if(t.length===0||!new Set([`ArrowDown`,`ArrowUp`,`Home`,`End`,`ArrowLeft`,`ArrowRight`,`PageUp`,`PageDown`,`Enter`,` `]).has(e.key))return;if(e.preventDefault(),e.key===`ArrowLeft`||e.key===`ArrowRight`){let t=this._store.model.getFields().filter(e=>!this._hiddenColumns.has(e.getName())).length;e.key===`ArrowLeft`?this._focusedColIndex=Math.max(0,this._focusedColIndex-1):this._focusedColIndex=Math.min(t-1,this._focusedColIndex+1),this.scrollColumnIntoView(this._focusedColIndex),this.renderWindow(),this._updateActiveDescendant(),this._updateFocusStyle();return}if(e.key===`Enter`||e.key===` `){if(!this._anchorRecord)return;this.scrollColumnIntoView(this._focusedColIndex),this.renderWindow();let e=t.indexOf(this._anchorRecord),n=this._boundIndices.indexOf(e);if(n<0)return;let r=this._rowPool[n],i=r.getComponents(),a=this._focusedColIndex-r.getColumnWindowStart(),o=a>=0&&a<i.length?i[a]:void 0;if(o instanceof Cell){let e=o;e.on(`editend`,()=>{this.focus(),this._updateFocusStyle(),this._updateActiveDescendant()}),e.startEdit()}return}let n=this._anchorRecord?t.indexOf(this._anchorRecord):-1,r=this.computePageSize(),i;i=e.key===`ArrowDown`?n<0?0:Math.min(n+1,t.length-1):e.key===`ArrowUp`?n<0?0:Math.max(n-1,0):e.key===`PageDown`?n<0?0:Math.min(n+r,t.length-1):e.key===`PageUp`?n<0?0:Math.max(n-r,0):e.key===`Home`?0:t.length-1;let a=t[i];this.selectRecord(a),this.scrollRecordIntoView(a),this.renderWindow(),this._updateActiveDescendant()}scrollRecordIntoView(e){this.scrollRowIntoView(this.getVisibleRecords().indexOf(e))}scrollColumnIntoView(e){let t=this._lastColumnWidths;if(!this._scroller||e<0||e>=t.length)return;let n=0;for(let r=0;r<e;r++)n+=t[r];let r=n+t[e],i=this._scroller.getScrollX(),a=this.getWidth()||0,o=i+a,s=i;n<i?s=n:r>o&&(s=r-a),s!==i&&this.setScrollX(s)}},G=c(Ue),K=`var(--ts-ui-table-header-bg, var(--ts-ui-button-bg, linear-gradient(rgb(241, 241, 241), rgb(200, 200, 200))))`,TableHeader=class extends f{_model;_store;_hiddenColumns=new Set;_columns=[];_listeners=new p;_scrollbarCover=null;_visibleFields=[];_windowFirst=0;_scrollX=0;_focusedCol=null;_columnsDirty=!0;_geometry={columnWidths:[],viewportWidth:0,columnHeight:0,parentRowHeight:0};_cellGeom=new CellGeometryCache;constructor(e,t){super({tag:`thead`}),this.getAria().setRole(`rowgroup`),this.setBorder({borderBottom:`1px solid var(--ts-ui-table-header-border, black)`}),this.setBackgroundColor(K),this.setBackgroundImage(K),this.setOverflow(`hidden`),this._model=e,this._store=t;let n=new V,r=new V;this.addRow(n),this.addRow(r),this.rebuildCells(),this.rebuildParentCells(),this.subscribeTheme(()=>this._cellGeom.clear())}getModel(){return this._model}setStore(e){return this._store=e,this}setModel(e){let toNames=e=>e.getFields().slice().filter(e=>!this._hiddenColumns.has(e.getName())).sort((e,t)=>e.getOrder()-t.getOrder()).map(e=>e.getName()),t=toNames(this._model),n=toNames(e);return t.length===n.length&&t.every((e,t)=>e===n[t])||(this._model=e,this.rebuildCells(),this.rebuildParentCells()),this.syncSortIndicators(),this}setHiddenColumns(e){let t=new Set;for(let n of e){let e=this._columns.find(e=>e.getField().getName()===n);(!e||!e.isUnhideable())&&t.add(n)}return this._hiddenColumns=t,this.rebuildCells(),this.rebuildParentCells(),this}setColumns(e){return this._columns=e,this.rebuildCells(),this.rebuildParentCells(),this}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}getColumns(){return this.getComponents()[1].getComponents()}getColumnWindowStart(){return this._windowFirst}getParentRow(){return this.getComponents()[0]}hasParentRow(){return this._columns.filter(e=>!this._hiddenColumns.has(e.getField().getName())).some(e=>e.getGroup()!==null)}getScrollbarCover(){if(this._scrollbarCover===null){let t=e.sink.createElement(`div`);e.sink.apply(t,{style:{position:`absolute`,top:`0`,boxSizing:`border-box`,zIndex:`1`,pointerEvents:`none`,backgroundColor:K,backgroundImage:K,borderLeft:`1px solid var(--ts-ui-table-resize-handle-color, rgba(0, 0, 0, 0.2))`}}),e.sink.appendChild(this.getElement(!0),t),this.trackHandle(t),this._scrollbarCover=t}return this._scrollbarCover}addRow(e){return this.addComponent(e),this}addComponent(e){return super.addComponent(e),this}setHeight(e){return super.setHeight(e),this}rebuildCells(){this._visibleFields=this.computeVisibleFields(this._model),this._columnsDirty=!0,this.syncSortIndicators()}computeVisibleFields(e){return e.getFields().slice().filter(e=>!this._hiddenColumns.has(e.getName())).sort((e,t)=>e.getOrder()-t.getOrder())}reconcileColumnCells(e,t){let n=this.getComponents()[1];if(!this._columnsDirty&&e===this._windowFirst&&t===this._windowFirst+n.getComponents().length-1)return!1;let r=new Map(this._columns.map(e=>[e.getField().getName(),e])),i=n.getComponents().slice(),a=new Map;for(let e of i){let t=n.getLayoutConstraints(e)?.data;t&&a.set(t.getName(),e)}let o=t-e+1,s=Array(o).fill(void 0);for(let n=e;n<=t;n++){let t=this._visibleFields[n].getName(),r=a.get(t);r&&(s[n-e]=r,a.delete(t))}let c=Array.from(a.values());for(let r=e;r<=t;r++){let t=r-e;if(s[t]!==void 0)continue;let i=this._visibleFields[r],a=c.pop();a?n.setLayoutConstraints(a,{data:i}):(a=new Le(i.getName(),i.getName(),null),n.addComponent(a,{data:i}),this.wireCell(a)),s[t]=a}for(let n=e;n<=t;n++){let t=s[n-e],i=this._visibleFields[n],a=r.get(i.getName());t.setFieldName(i.getName()),t.setHeaderText(a?.getHeaderText()??i.getName());let o=i.getDescription();t.getTooltip()!==o&&t.setTooltip(o);let c=a?.getHeaderGlyph()??null;t.getHeaderGlyph()!==c&&t.setHeaderGlyph(c),t.setBaseBackground(a?.getGroupColor()??null),t.setRequired(a?.isRequired()??!1),t.getAria().setColIndex(n+1)}for(let e of c)n.removeComponent(e),e.dispose();let l=new Map(s.map((e,t)=>[e,t]));return n.sortComponents((e,t)=>(l.get(e)??0)-(l.get(t)??0)),this._windowFirst=e,this._columnsDirty=!1,!0}rebuildParentCells(){let e=this.getParentRow();if(e.disposeAllComponents(),!this.hasParentRow())return;let t=this._columns.filter(e=>!this._hiddenColumns.has(e.getField().getName())).sort((e,t)=>e.getField().getOrder()-t.getField().getOrder());if(t.length===0)return;let n=0,r=t[0].getGroup(),i=t[0].getGroupColor(),flush=a=>{let o=new Re(r??``,i),s=t.slice(n,a).map(e=>e.getField().getName());r!==null&&s.length>0&&o.setTooltip(`${r}: ${s.join(`, `)}`),o.on(`contextmenu`,(e,t)=>{this.emit(`columncontextmenu`,``,e,t)}),e.addComponent(o,{data:{spanFrom:n,spanTo:a-1}})};for(let e=1;e<t.length;e++){let a=t[e].getGroup();r!==null&&a===r?i===null&&t[e].getGroupColor()!==null&&(i=t[e].getGroupColor()):(flush(e),n=e,r=a,i=t[e].getGroupColor())}flush(t.length)}wireCell(e){e.on(`sortclick`,(e,t)=>this.handleSortClick(e,t)),e.on(`resizestart`,t=>this.emit(`columnresizestart`,this.columnIndexOf(e),t)),e.on(`resizedrag`,t=>this.emit(`columnresize`,this.columnIndexOf(e),t)),e.on(`contextmenu`,(e,t,n)=>this.emit(`columncontextmenu`,e,t,n))}columnIndexOf(e){let t=this.getColumns().indexOf(e);return t===-1?-1:this._windowFirst+t}handleSortClick(e,t){if(t){let t=this._store.getActiveSorters(),n=t.findIndex(t=>t.field===e),r;r=n===-1?[...t,{field:e,dir:`asc`}]:t[n].dir===`asc`?t.map((e,t)=>t===n?{field:e.field,dir:`desc`}:e):t.filter((e,t)=>t!==n),r.length===0?this._store.clearSort():this._store.sort(r)}else{let t=this._store.getActiveSorters(),n=t.length===1&&t[0].field===e?t[0]:null;n?n.dir===`asc`?this._store.sort(e,`desc`):this._store.clearSort():this._store.sort(e,`asc`)}this.syncSortIndicators()}syncSortIndicators(){let e=this.getColumns(),t=this._store.getActiveSorters(),n=new Map(t.map((e,t)=>[e.field,{dir:e.dir,priority:t+1}])),r=t.length>1;e.forEach((e,t)=>{let i=this._visibleFields[this._windowFirst+t],a=i?n.get(i.getName()):void 0;a?e.setSortState(a.dir,r?a.priority:null):e.clearSortState()})}renderColumnWindow(e){e&&(this._geometry=e);let t=this._geometry,n=computeColumnWindow(this._visibleFields.map((e,n)=>t.columnWidths[n]??0),this._scrollX,t.viewportWidth);return this.reconcileColumnCells(n.firstCol,n.lastCol)&&(this.syncSortIndicators(),this.applyFocusedColumn()),this.positionColumnCells(n,t.columnHeight),this.positionParentCells(n,t.parentRowHeight),this}positionColumnCells(e,t){let n=this.getColumns();for(let r=0;r<n.length;r++){let i=e.firstCol+r;this._cellGeom.apply(n[r],e.lefts[i]??0,e.widths[i]??0,t)}}positionParentCells(e,t){let n=this.getParentRow();for(let r of n.getComponents()){let i=n.getLayoutConstraints(r)?.data,a=i?.spanFrom??0,o=i?.spanTo??0,s=e.lefts[a]??0,c=(e.lefts[o]??0)+(e.widths[o]??0)-s;this._cellGeom.apply(r,s,c,t)}}setScrollX(e){return e===this._scrollX?this:(this._scrollX=e,this.getParentRow().setTranslate(-e,0),this.getComponents()[1].setTranslate(-e,0),this.renderColumnWindow(),this)}getScrollX(){return this._scrollX}setFocusedColumn(e){return this._focusedCol=e,this.applyFocusedColumn(),this}applyFocusedColumn(){let e=this.getColumns();for(let t=0;t<e.length;t++)e[t].setColumnFocused(this._windowFirst+t===this._focusedCol)}},q=c(TableHeader),FooterRow=class extends f{constructor(){super({tag:`tfoot`}),this.setBorder({borderTop:`1px solid var(--ts-ui-border-color, black)`});let e=`var(--ts-ui-button-bg, linear-gradient(rgb(241, 241, 241), rgb(200, 200, 200)))`;this.setBackgroundColor(e),this.setBackgroundImage(e);let t=new V;this.addRow(t)}getColumns(){return this.getComponents()[0].getComponents()}addRow(e){return this.addComponent(e),this}addComponent(e){return super.addComponent(e),this}setWidth(e){return super.setWidth(e),this.getComponents()[0].setWidth(this.getContentBounds()?.width??e),this}setHeight(e){return super.setHeight(e),this.getComponents()[0].setHeight(this.getContentBounds()?.height??e),this}},J=c(FooterRow),Y=class Column{_field;_minWidth;_maxWidth;_width;_maxContentLength;_hidden;_unhideable;_readOnly;_headerGlyph;_headerText;_group;_groupColor;_required;constructor(e,t){this._field=e,this._minWidth=t?.minWidth,this._maxWidth=t?.maxWidth,this._width=t?.width,this._maxContentLength=t?.maxContentLength,this._hidden=t?.hidden??!1,this._unhideable=t?.unhideable??!1,this._readOnly=t?.readOnly??!1,this._headerGlyph=t?.headerGlyph??null,this._headerText=t?.headerText??null,this._group=t?.group??null,this._groupColor=t?.groupColor??null,this._required=t?.required??!1}getField(){return this._field}getMinWidth(){return this._minWidth}getMaxWidth(){return this._maxWidth}getWidth(){return this._width}getMaxContentLength(){return this._maxContentLength}isInitiallyHidden(){return this._hidden}isUnhideable(){return this._unhideable}isReadOnly(){return this._readOnly}getHeaderGlyph(){return this._headerGlyph}getHeaderText(){return this._headerText}setHeaderGlyph(e){return this._headerGlyph=e,this}clearHeaderGlyph(){return this.setHeaderGlyph(null)}getGroup(){return this._group}getGroupColor(){return this._groupColor}isRequired(){return this._required}static resolve(e,t){let n=e.slice().sort((e,t)=>e.getOrder()-t.getOrder());if(!t)return n.map(e=>new Column(e));let r=new Map(t.columns.map(e=>[e.field,e])),i=new Set(t.columns.map(e=>e.field));return t.appendUnlisted===!1?n.filter(e=>i.has(e.getName())).map(e=>new Column(e,r.get(e.getName()))):n.map(e=>new Column(e,r.get(e.getName())))}},X=class TableExporter{static exportCSV(e,t,n,r){let i=[e.map(e=>TableExporter.escapeCSVField(e.getField().getName())).join(`,`),...t.map(t=>e.map(e=>TableExporter.escapeCSVField(TableExporter.formatValue(e,t.get(e.getField().getName()),n))).join(`,`))].join(`\r
|
|
1
|
+
import{t as e}from"../DOM-Ba8YRVel.js";import{a as t,l as n,n as r}from"../Position-PBVBW1JS.js";import{S as i,b as a,d as o,f as s,h as c,m as l,p as u,r as d,t as f}from"../Component-w65rPK75.js";import{t as p}from"../ListenerBag-WPdKuuds.js";import{t as m}from"../Container-C7RPLQEc.js";import{t as h}from"../Glyph-DeJF_zsR.js";import{a as g,t as _}from"../Tooltip-B_UF5bXD.js";import{t as v}from"../Fit-Cg3dPyZg.js";import{t as y}from"../Text-CdHf3B-1.js";import{r as b}from"../VBox-32fxpkDl.js";import{a as ee,o as te,t as ne}from"../Border-CNS6aEXB.js";import{t as re}from"../ProgressSpinner-lAsK26C-.js";import{t as x}from"../Placement-7kqdaK4Z.js";import{t as S}from"../Button-T16zSZip.js";import{t as C}from"../DragManager-UvPHSoRm.js";import{t as ie}from"../Menu-C0roOCY7.js";import{n as w,r as ae}from"../DragChain-CYGuT7OA.js";import{t as oe}from"../Card-CD3jxshU.js";import{i as se,t as ce}from"../MemoryStore-BgP7-Uzn.js";import{a as le,g as ue,n as de,o as fe,r as pe,t as me,u as T}from"../ComboBox-C9FYMuLv.js";import{caret_down as he}from"../glyphs/solid/caret_down.es.js";import{n as ge,t as _e}from"../selectionsEqual-BrTxPMmK.js";import{caret_right as ve}from"../glyphs/solid/caret_right.es.js";import{arrows_rotate as ye}from"../glyphs/solid/arrows_rotate.es.js";import{t as be}from"../reduceModifierSelection-DTo8HyFl.js";import{plus as xe}from"../glyphs/solid/plus.es.js";import{minus as Se}from"../glyphs/solid/minus.es.js";import{ban as E}from"../glyphs/solid/ban.es.js";var Table$1=class extends s{constructor(e){super(),e&&this.applyOptions(e)}attach(e){let t=e.getClassName();if(t!=`Table`&&t!=`TreeTable`)throw Error(`Container must be a Table or TreeTable.`);return super.attach(e),this}doLayout(){let t=this.getContainer();if(!t)return;let r=t.getInnerSize();if(!r||!Number.isFinite(r.width)||!Number.isFinite(r.height))return;let i=t.getContentInsets(),a=t.getColumns(),o=t.getColumns().length,s=t.getAvailableColumnWidth(),c=Math.max(s,t.getColumnWidthTarget()),l=t.getColumnWidths();l.length===o?(l=this.rescaleWidths(t,a,l,c),t.setColumnWidths(l)):(l=this.initializeWidths(t,a,s),t.setColumnWidths(l));let u=t.getHeader(),f=t.getBody(),p=t.getFooter();if(t.isHeaderVisible()&&u&&u.isDisplayed()){let t=d.getTheme(),a=n.lineHeightPx()+2*(t.table.cell.padding??2),o=u.hasParentRow()?a:0,c=u.getPerimeterSize(),f=o+a+c.top+c.bottom;u.setAutoCommitStyle(!1),u.setX(i.getLeft()),u.setY(i.getTop()),u.setWidth(r.width),u.setHeight(f),u.setAutoCommitStyle(!0);let p=u.getContentBounds()??{x:0,y:0,width:r.width,height:f},m=l.reduce((e,t)=>e+t,0),h=Math.max(p.width,m),g=u.getParentRow();g.setAutoCommitStyle(!1),g.setX(p.x),g.setY(p.y),g.setWidth(h),g.setHeight(o),g.setAutoCommitStyle(!0);let _=u.getComponents()[1];_.setAutoCommitStyle(!1),_.setX(p.x),_.setY(p.y+o),_.setWidth(h),_.setHeight(a),_.setAutoCommitStyle(!0),u.renderColumnWindow({columnWidths:l,viewportWidth:s,columnHeight:a,parentRowHeight:o});let v=e.source.getScrollBarWidth(),y=u.getScrollbarCover();e.sink.apply(y,{style:{left:p.x+p.width-v+`px`,top:p.y+`px`,width:v+`px`,height:p.height+`px`}})}if(t.isFooterVisible()&&p&&p.isDisplayed()){let e=d.getTheme(),t=n.lineHeightPx()+2*(e.table.cell.padding??2),a=p.getColumns(),o=p.getPerimeterSize(),s=t+o.top+o.bottom;p.setAutoCommitStyle(!1),p.setX(i.getLeft()),p.setY(i.getTop()+r.height-s),p.setWidth(r.width),p.setHeight(s),p.setAutoCommitStyle(!0);let c=p.getContentBounds()??{x:0,y:0,width:r.width,height:t},u=0;a.forEach((e,t)=>{e.setAutoCommitStyle(!1),e.setX(u),e.setY(0),e.setWidth(l[t]),e.setHeight(c.height),e.setAutoCommitStyle(!0),e.doLayout(),u+=l[t]})}if(t.isBodyVisible()&&f&&f.isDisplayed()){let e=t.isHeaderVisible()&&u&&u.isDisplayed()?u.getHeight():0,n=t.isFooterVisible()&&p&&p.isDisplayed()?p.getHeight():0;f.setAutoCommitStyle(!1),f.setX(i.getLeft()),f.setY(i.getTop()+e),f.setWidth(r.width),f.setHeight(r.height-e-n),f.setAutoCommitStyle(!0),f.renderWindow(s,l)}}initializeWidths(e,r,i){let a=e.getIntrinsicColumnWidths(),o=a.reduce((e,t)=>e+(t??0),0),s=a.filter(e=>e===null).length,c=s>0?(i-o)/s:0,l=a.map((i,a)=>{if(i!==null)return i;let o=r[a],s=e.getColumnMinWidth(o),l=o.getMaxWidth()??t;return n.clamp(c,s,l)});return this.absorbSlackIntoGreedy(r,l,i)}rescaleWidths(e,t,n,r){let i=t.map(e=>{let t=e.getField().getType();return t===`boolean`||t===`number`||t===`date`}),a=n.reduce((e,t,n)=>e+(i[n]?t:0),0),o=n.reduce((e,t,n)=>e+(i[n]?0:t),0),s=r-a;if(o<=0||s<=0||Math.abs(o-s)<=.5)return n;let c=s/o,l=n.map((n,r)=>i[r]?n:this.clamp(n*c,t[r],e));return this.absorbSlackIntoGreedy(t,l,r)}absorbSlackIntoGreedy(e,t,n){let r=n-t.reduce((e,t)=>e+t,0);if(r<=.5)return t;let i=[];if(e.forEach((e,t)=>{let n=e.getField().getType();n!==`boolean`&&n!==`number`&&n!==`date`&&e.getMaxWidth()===void 0&&i.push(t)}),i.length===0)return t;let a=r/i.length,o=[...t];for(let e of i)o[e]+=a;return o}clamp(e,r,i){let a=i.getColumnMinWidth(r),o=r.getMaxWidth()??t;return n.clamp(e,a,o)}},Ce=c(Table$1);function blurRelatedTargetHandle(t){return t.relatedTarget?e.source.intern(t.relatedTarget):null}var CellEditor=class extends f{_onCommitRequested=null;constructor(e=`div`){super({tag:e}),this.setLayoutManager(new v);let applyPadding=()=>{let e=d.getTheme().table.cell.padding;this.setInsets(new r(0,e,0,e))};applyPadding(),this.subscribeTheme(applyPadding)}retainsFocus(e){return!1}setCommitRequestHandler(e){this._onCommitRequested=e}requestCommit(){this._onCommitRequested?.()}getContentX(){return 0}},Cell=class extends f{_readOnly;_requiredEmpty=!1;_baseBackground=`var(--ts-ui-table-cell-bg, transparent)`;_renderer;_editor;_editorPool=null;_scrollIntoView=null;_activeEditor=null;_listeners=new p;constructor(e,t,n,a,o){super({tag:e||`td`}),this.setLayoutManager(new oe),this.getAria().setRole(`gridcell`),this._readOnly=!1,this._renderer=t,this._editor=n,this.setInsets(new r(0,0,0,0)),this.setBackgroundColor(`var(--ts-ui-table-cell-bg, transparent)`),this.setForegroundColor(`var(--ts-ui-table-cell-color, inherit)`),this.setBorder(`var(--ts-ui-table-cell-border, none)`),this.subscribeTheme(()=>this.setBorder(`var(--ts-ui-table-cell-border, none)`)),this.addComponent(t,a),n&&(this.addComponent(n,o),n.setCommitRequestHandler(()=>this.commitEdit()),i.addListener(n,`blur`,e=>{n.retainsFocus(blurRelatedTargetHandle(e))||this.commitEdit()}),i.addListener(n,`keydown`,e=>this.onKeyDown(e))),i.addListener(t,`dblclick`,()=>this.startEdit())}clampsToContentSize(){return!1}getEditorKey(){return null}setEditorPool(e){return this._editorPool=e,this}setScrollIntoViewHandler(e){return this._scrollIntoView=e,this}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}isReadOnly(){return!!this._readOnly}setReadOnly(e){if(this._readOnly===e)return this;if(this._readOnly=e,e&&this._activeEditor){let e=this._activeEditor.getValue();this._renderer.setValue(e),this.emit(`commit`,e),this.detachEditor()}return this._applyStateTint(),this}setRequiredEmpty(e){return this._requiredEmpty===e?this:(this._requiredEmpty=e,this._applyStateTint(),this)}setBaseBackground(e){return this._baseBackground=e??`var(--ts-ui-table-cell-bg, transparent)`,this._applyStateTint(),this}_applyStateTint(){this._readOnly?(this.setBackgroundColor(`var(--ts-ui-table-cell-readonly-bg, rgba(0, 0, 0, 0.04))`),this.setCursor(`default`)):(this.setBackgroundColor(this._baseBackground),this.clearCursor()),this._requiredEmpty&&!this._readOnly?this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-required-outline, rgba(220, 60, 60, 0.6))`):this.clearShadow()}onKeyDown(e){let t=e.detail?.keyCode;t==13?(this.commitEdit(),this.emit(`editend`)):t==27&&(this.cancelEdit(),this.emit(`editend`))}isEditing(){return this._activeEditor!==null}getLayoutManager(){return super.getLayoutManager()}startEdit(){if(this.isReadOnly()||this.isEditing())return;if(this._scrollIntoView?.(),this._editor)this._activeEditor=this._editor;else{let e=this.getEditorKey();if(!e||!this._editorPool)return;let t=this._editorPool.acquire(e,this);if(!t)return;this._activeEditor=t,this.addComponent(this._activeEditor)}let e=this._activeEditor,t=this._renderer;this.prepareEditor(e),e.setValue(t.getValue()),this.getLayoutManager().setVisibleComponentId(e.getId()),this.doLayout(),e.focus(!0)}commitEdit(){if(this.isReadOnly()||!this.isEditing())return this;let e=this._activeEditor.getValue();return this._renderer.setValue(e),this.emit(`commit`,e),this.detachEditor(),this}cancelEdit(){this.isReadOnly()||!this.isEditing()||this.detachEditor()}detachEditor(){let e=this._activeEditor;e&&(this._activeEditor=null,this.getLayoutManager().setVisibleComponentId(this._renderer.getId()),this.doLayout(),this._editor!==e&&(this.removeComponent(e),this._editorPool?.release()))}setValue(e){return this._renderer.setValue(e),this}getRenderer(){return this._renderer}doLayout(){return super.doLayout(),this.alignEditorWithContent(),this}alignEditorWithContent(){let e=this._activeEditor;if(!e)return;let t=this._renderer.getContentX();if(t<=0)return;let n=this.getContentBounds()??{x:0,y:0,width:this.getWidth()??0,height:0},r=Math.max(0,n.width-t);e.setAutoCommitStyle(!1),e.setX(n.x+t),e.setWidth(r),e.setAutoCommitStyle(!0)}wrapRenderer(e){let t=this._renderer;this.removeComponent(t);let n=e(t);return this._renderer=n,this.addComponent(n),this.getLayoutManager().setVisibleComponentId(n.getId()),this}getEditor(){return this._editor}setActiveRenderer(e,t){t&&(this.addComponent(e),i.addListener(e,`dblclick`,()=>this.startEdit()));let n=this._renderer!==e;this._renderer=e,this.getLayoutManager().setVisibleComponentId(e.getId()),n&&this.doLayout()}prepareEditor(e){}},BooleanEditor=class extends CellEditor{_checkBox=new de;_value=null;_listeners=new p;_suppressCommit=!1;constructor(){super(),this._checkBox.setIndeterminate(!0),this._checkBox.setAnimated(!1),this.addComponent(this._checkBox),this._checkBox.on(`action`,()=>{this._suppressCommit||(this._value=this._checkBox.isSelected(),this.emit(`change`,this._value))})}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}getValue(){return this._value}setValue(e){this._value=e??null,this._suppressCommit=!0;try{this._value===null?this._checkBox.setIndeterminate(!0):(this._checkBox.setIndeterminate(!1),this._checkBox.setSelected(this._value))}finally{this._suppressCommit=!1}return this}setReadOnly(e){return this._checkBox.setReadOnly(e),this}isReadOnly(){return this._checkBox.isReadOnly()}toggle(){let e=!this._checkBox.isSelected();return this._checkBox.setIndeterminate(!1),this._checkBox.setSelected(e),this._value=e,this.emit(`change`,this._value),this}},D=c(BooleanEditor),CellRenderer=class extends f{constructor(){super(),this.setLayoutManager(new v);let applyPadding=()=>{let e=d.getTheme().table.cell.padding;this.setInsets(new r(0,e,0,e))};applyPadding(),this.subscribeTheme(applyPadding)}getContentX(){return 0}doLayout(){super.doLayout();let e=this.getComponents();if(e.length!==1)return this;let t=e[0];if(!(t instanceof y))return this;let n=t.getHeight();return n>0&&t.setLineHeight(n),this}},StringRenderer=class extends CellRenderer{_text=new y;_value=null;constructor(){super(),this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getText(){return this._text}getValue(){return this._value}setValue(e){return this._value=e??null,this._text.setText(this._value===null?``:String(this._value)),this}},O=c(StringRenderer),NumberRenderer=class extends CellRenderer{_text=new y;_value=null;constructor(){super(),this._text.setPointerEvents(`none`),this._text.setTextAlign(`right`),this._text.setText(``),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){return this._value=e??null,this._text.setText(this._value===null?``:String(this._value)),this}},k=c(NumberRenderer),DateRenderer=class extends CellRenderer{_text=new y;_value=null;constructor(){super(),this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){return this._value=e??null,this._text.setText(e?e.toLocaleDateString():``),this}},A=c(DateRenderer),TimeRenderer=class extends CellRenderer{_text=new y;_value=null;_showSeconds;constructor(e=!1){super(),this._showSeconds=e,this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){this._value=e??null;let t=this._showSeconds?{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{hour:`2-digit`,minute:`2-digit`};return this._text.setText(e?e.toLocaleTimeString(void 0,t):``),this}},j=c(TimeRenderer),DateTimeRenderer=class extends CellRenderer{_text=new y;_value=null;_showSeconds;constructor(e=!1){super(),this._showSeconds=e,this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getValue(){return this._value}setValue(e){this._value=e??null;let t=this._showSeconds?{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};return this._text.setText(e?e.toLocaleString(void 0,t):``),this}},M=c(DateTimeRenderer),GlyphRenderer=class extends CellRenderer{_value=null;_glyph=null;getValue(){return this._value}setValue(e){let t=e||null;return t===this._value&&(t===null||this._glyph)?this:(this._glyph&&=(this.removeComponent(this._glyph),null),this._value=t,t!==null&&(this._glyph=new h(t),this._glyph.setPointerEvents(`none`),this.addComponent(this._glyph)),this.doLayout(),this)}},N=c(GlyphRenderer);function normalizeComboOptions(e){return e.map(e=>typeof e==`string`?{value:e,label:e}:{value:e.value,label:e.label??e.value})}var ComboRenderer=class extends CellRenderer{_text=new y;_map=new Map;_value=null;constructor(e){super();for(let t of normalizeComboOptions(e))this._map.set(t.value,t.label);this._text.setText(``),this._text.setPointerEvents(`none`),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getText(){return this._text}getValue(){return this._value}setValue(e){if(this._value=e??null,this._value===null)this._text.setText(``);else{let e=String(this._value);this._text.setText(this._map.get(e)??e)}return this}setOptions(e){this._map.clear();for(let t of normalizeComboOptions(e))this._map.set(t.value,t.label);return this.setValue(this._value),this}},P=c(ComboRenderer),F=c(class DynamicCell extends Cell{_field;_columnType;_showSeconds;_cellType;_cellValues;_renderers=new Map;_activeType=`string`;_currentOptions=[];_checkbox=null;_justCreated=!1;constructor(e,t,n){let r=new O;super(`td`,r),this._field=e,this._columnType=t,this._showSeconds=n.showSeconds??!1,this._cellType=n.cellType,this._cellValues=n.cellValues,this._renderers.set(`string`,r)}bindRecord(e){let t=this._cellType?.(e)??this._columnType;if(this._activeType=t,t===`boolean`){let t=this.ensureCheckbox();this.setActiveRenderer(t,this._justCreated),t.setValue(e.get(this._field));return}if(t===`combo`){this._currentOptions=this._cellValues?.(e)??[];let t=this.ensureRenderer(`combo`);t.setOptions(this._currentOptions),this.setActiveRenderer(t,this._justCreated),t.setValue(e.get(this._field));return}let n=this.ensureRenderer(t);this.setActiveRenderer(n,this._justCreated),n.setValue(e.get(this._field))}getEditorKey(){switch(this._activeType){case`number`:return`number`;case`date`:return`date`;case`time`:return this._showSeconds?`time:seconds`:`time`;case`datetime`:return this._showSeconds?`datetime:seconds`:`datetime`;case`combo`:return`combo:${this._field}`;case`boolean`:case`glyph`:return null;default:return`string`}}startEdit(){if(this._activeType===`boolean`){if(this.isReadOnly())return;this._checkbox?.toggle();return}super.startEdit()}setReadOnly(e){return super.setReadOnly(e),this._activeType===`boolean`&&this._checkbox?.setReadOnly(e),this}prepareEditor(e){this._activeType===`combo`&&e.setOptions(this._currentOptions)}ensureRenderer(e){let t=this._renderers.get(e);if(t)return this._justCreated=!1,t;let n=DynamicCell.buildRenderer(e,this._showSeconds);return this._renderers.set(e,n),this._justCreated=!0,n}static buildRenderer(e,t){switch(e){case`number`:return new k;case`date`:return new A;case`time`:return new j(t);case`datetime`:return new M(t);case`combo`:return new P([]);case`glyph`:return new N;default:return new O}}ensureCheckbox(){if(this._checkbox)return this._justCreated=!1,this._checkbox;let e=new D;return e.on(`change`,e=>this.emitCommit(e)),this._checkbox=e,this._justCreated=!0,e}emitCommit(e){this.emit(`commit`,e)}}),DefaultCell=class extends Cell{constructor(e){let t=new O;super(e||`td`,t)}getRenderer(){return super.getRenderer()}setValue(e){return this.getRenderer().setValue(e),this}},I=c(DefaultCell),StringCell=class extends Cell{constructor(){let e=new O;super(`td`,e)}getEditorKey(){return`string`}setValue(e){return this.getRenderer().setValue(e),this}},we=c(StringCell),BooleanCell=class extends Cell{_checkbox;constructor(){let e=new D;super(`td`,e,void 0,{fill:l.NONE,anchor:u.CENTER},void 0),this._checkbox=e}on(e,t){return e===`commit`?(this._checkbox.on(`change`,t),this):super.on(e,t)}off(e,t){return e===`commit`?(this._checkbox.off(`change`,t),this):super.off(e,t)}setReadOnly(e){return super.setReadOnly(e),this._checkbox.setReadOnly(e),this}startEdit(){this.isReadOnly()||this._checkbox.toggle()}setValue(e){return this.getRenderer().setValue(e),this}},Te=c(BooleanCell),NumberCell=class extends Cell{constructor(){let e=new k;super(`td`,e)}getEditorKey(){return`number`}setValue(e){return this.getRenderer().setValue(e),this}},Ee=c(NumberCell),DateCell=class extends Cell{constructor(){let e=new A;super(`td`,e)}getEditorKey(){return`date`}setValue(e){return this.getRenderer().setValue(e),this}commitEdit(){let e=this._activeEditor;return e&&!e.isEmpty()&&e.getValue()===null?(this.cancelEdit(),this):(super.commitEdit(),this)}},De=c(DateCell),TimeCell=class extends Cell{_showSeconds;constructor(e=!1){let t=new j(e);super(`td`,t),this._showSeconds=e}getEditorKey(){return this._showSeconds?`time:seconds`:`time`}setValue(e){return this.getRenderer().setValue(e),this}commitEdit(){let e=this._activeEditor;return e&&!e.isEmpty()&&e.getValue()===null?(this.cancelEdit(),this):(super.commitEdit(),this)}},Oe=c(TimeCell),DateTimeCell=class extends Cell{_showSeconds;constructor(e=!1){let t=new M(e);super(`td`,t),this._showSeconds=e}getEditorKey(){return this._showSeconds?`datetime:seconds`:`datetime`}setValue(e){return this.getRenderer().setValue(e),this}commitEdit(){let e=this._activeEditor;return e&&!e.isEmpty()&&e.getValue()===null?(this.cancelEdit(),this):(super.commitEdit(),this)}},L=c(DateTimeCell),GlyphCell=class extends Cell{constructor(){let e=new N;super(`td`,e)}setValue(e){return this.getRenderer().setValue(e),this}},R=c(GlyphCell),ComboCell=class extends Cell{_field;constructor(e,t){super(`td`,new P(t)),this._field=e}getEditorKey(){return`combo:${this._field}`}setValue(e){return this.getRenderer().setValue(e),this}},z=c(ComboCell);h.register(he,ve);var TreeCellRenderer=class extends CellRenderer{_toggle=null;_depth=0;_hasChildren=!1;_expanded=!1;constructor(e,t=16){super(),this._delegate=e,this._indentPx=t,this.setLayoutManager(new o),super.setInsets(new r(0,0,0,0)),this.addComponent(e)}getDelegate(){return this._delegate}getToggle(){return this._toggle}getDepth(){return this._depth}getContentX(){return this._depth*this._indentPx+20}getValue(){return this._delegate.getValue()}setValue(e){return this._delegate.setValue(e),this}setTreeState(e,t,n){return this._depth===e&&this._hasChildren===t&&this._expanded===n?this:(this._depth=e,this._hasChildren=t,this._expanded=n,this.refreshToggle(),this.doLayout(),this)}setInsets(e){return this._delegate?.setInsets(e),this}refreshToggle(){if(this._toggle&&=(this.removeComponent(this._toggle),null),!this._hasChildren)return;let e=new h(this._expanded?`caret-down`:`caret-right`);e.setCursor(`pointer`),e.clearInsets(),e.getAria().setHidden(!0),this._toggle=e,this.addComponent(e)}doLayout(){let e=this.getContentBounds()??{x:0,y:0,width:0,height:0},t=e.width,n=e.height,r=this._depth*this._indentPx;if(this._toggle){let t=this._toggle.getPreferredSize()?.height??n;this._toggle.setAutoCommitStyle(!1),this._toggle.setX(e.x+r),this._toggle.setY(e.y+Math.max(0,(n-t)/2)),this._toggle.setWidth(20),this._toggle.setHeight(t),this._toggle.setAutoCommitStyle(!0)}let i=r+20,a=Math.max(0,t-i);return this._delegate.setAutoCommitStyle(!1),this._delegate.setX(e.x+i),this._delegate.setY(e.y),this._delegate.setWidth(a),this._delegate.setHeight(n),this._delegate.setAutoCommitStyle(!0),super.doLayout(),this}},B=c(TreeCellRenderer),V=c(class Row extends f{_model;_data;_onCellCommit;_treeCell=null;_stripe=!1;_visibleFields=[];_columnConfigs=new Map;_treeFieldName;_windowFirst=0;_cellKeys=[];_fieldNames=[];_columnsDirty=!1;constructor(e,t,n=new Set,r=new Map,i,a){super({tag:`tr`}),this.getAria().setRole(`row`),this._model=e,this._data=t,this._onCellCommit=i,this._model&&this.setColumnFields(this._model,n,r,a)}getTreeCell(){return this._treeCell}getColumnWindowStart(){return this._windowFirst}getFieldNames(){return this._fieldNames}getData(){return this._data}setData(e){this._data=e;let t=this.getComponents(),n=this._fieldNames;for(let r=0;r<n.length;r++)this.bindCell(t[r],e,n[r]);return this.updateVisualState(),this}setStripe(e){this._stripe=e}updateVisualState(){let t=this.getElement();t&&(this._data?.isNew()?e.sink.apply(t,{style:{"background-color":`var(--ts-ui-table-row-new, rgba(70, 200, 70, 0.15))`}}):this._data?.isDirty()?e.sink.apply(t,{style:{"background-color":`var(--ts-ui-table-row-dirty, rgba(255, 165, 0, 0.15))`}}):this._stripe?e.sink.apply(t,{style:{"background-color":`var(--ts-ui-table-row-stripe, rgba(0, 0, 0, 0.035))`}}):e.sink.apply(t,{style:{"background-color":null}}))}addColumn(e,t){return this.addComponent(e,t),this}addComponent(e,t){return super.addComponent(e,t),this}setColumnFields(e,t,n,r){return this._model=e,this._visibleFields=e.getFields().filter(e=>!t.has(e.getName())).sort((e,t)=>e.getOrder()-t.getOrder()),this._columnConfigs=n,this._treeFieldName=r,this._columnsDirty=!0,this}setColumnWindow(e,t){let n=this._visibleFields.length-1;t=Math.min(t,n),e>t&&(e=t+1);let r=this._windowFirst+this.getComponents().length-1;if(!this._columnsDirty&&e===this._windowFirst&&t===r)return!1;let i=this.getComponents(),a=new Map;for(let e=0;e<i.length;e++){let t=this._fieldNames[e];t!==void 0&&a.set(t,{cell:i[e],key:this._cellKeys[e]})}let o=t-e+1,s=Array(o).fill(void 0),c=new Set;for(let n=e;n<=t;n++){let t=this._visibleFields[n],r=this.cellKeyFor(t),i=a.get(t.getName());i&&i.key===r&&(s[n-e]=i.cell,a.delete(t.getName()))}let l=new Map;for(let e of a.values()){let t=l.get(e.key);t?t.push(e.cell):l.set(e.key,[e.cell])}for(let n=e;n<=t;n++){let t=n-e;if(s[t]!==void 0)continue;let r=this._visibleFields[n],i=this.cellKeyFor(r),a=l.get(i),o;if(a&&a.length>0)o=a.pop(),this.setLayoutConstraints(o,{data:r});else{o=Row.createCellForField(r,this._columnConfigs),this._treeFieldName!==void 0&&r.getName()===this._treeFieldName&&o.wrapRenderer(e=>new B(e));let e=o;o.on(`commit`,t=>this.commitCellValue(e,t)),this.addComponent(o,{data:r})}s[t]=o,c.add(n)}for(let n=e;n<=t;n++){let t=s[n-e],r=this._visibleFields[n];t.getAria().setColIndex(n+1),t.setBaseBackground(this._columnConfigs.get(r.getName())?.groupColor??null),c.has(n)&&this.bindCell(t,this._data,r.getName())}for(let e of l.values())for(let t of e)t.isEditing()&&t.commitEdit(),this.removeComponent(t),t.dispose();let u=new Map(s.map((e,t)=>[e,t]));this.sortComponents((e,t)=>(u.get(e)??0)-(u.get(t)??0)),this._windowFirst=e,this._fieldNames=[],this._cellKeys=[],this._treeCell=null;for(let n=e;n<=t;n++){let t=this._visibleFields[n],r=s[n-e];this._fieldNames.push(t.getName()),this._cellKeys.push(this.cellKeyFor(t)),this._treeFieldName!==void 0&&t.getName()===this._treeFieldName&&(this._treeCell=r)}return this._columnsDirty=!1,!0}commitCellValue(e,t){let n=this.getLayoutConstraints(e)?.data;n&&(this._data&&(this._data.set(n.getName(),t),this._onCellCommit?.(this._data)),this.updateVisualState())}static cellKey(e,t,n){if(n)return`tree:${e.getName()}`;if(t?.renderer)return`renderer:${e.getName()}`;if(t?.cellType)return`dynamic:${e.getName()}`;if(t?.values&&t.values.length>0)return`combo:${e.getName()}`;let r=e.getType();return r===`time`||r===`datetime`?`${r}:${t?.showSeconds??!1}`:r}cellKeyFor(e){let t=this._treeFieldName!==void 0&&e.getName()===this._treeFieldName;return Row.cellKey(e,this._columnConfigs.get(e.getName()),t)}bindCell(e,t,n){e instanceof F&&t?e.bindRecord(t):e.setValue(t?t.get(n):void 0)}static createCellForField(e,t){let n=t.get(e.getName());if(n?.renderer)return new Cell(`td`,n.renderer());if(n?.cellType)return new F(e.getName(),e.getType(),n);let r=n?.values;if(r&&r.length>0)return new z(e.getName(),r);switch(e.getType()){case`string`:return new we;case`number`:return new Ee;case`boolean`:return new Te;case`date`:return new De;case`time`:return new Oe(t.get(e.getName())?.showSeconds??!1);case`datetime`:return new L(t.get(e.getName())?.showSeconds??!1);case`glyph`:return new R;default:return new I}}doLayout(){return this}}),ke=`var(--ts-ui-table-resize-handle-cursor, ew-resize)`,Ae=null;function ensureResizeHandleClassRule(){Ae||=new a({scope:`class`,name:`ResizeHandle`,styles:{position:`absolute`,top:`0`,right:`0`,width:`var(--ts-ui-table-resize-handle-width,5px)`,height:`100%`,zIndex:`1`}})}var ResizeHandle=class extends f{_listeners=new p;constructor(e){ensureResizeHandleClassRule(),super({tag:`div`,...e??{}}),this.setCursor(ke),this.setBackgroundImage(`linear-gradient(to right,transparent 80%,var(--ts-ui-table-resize-handle-color,rgba(0,0,0,0.2)) 80%)`),this.setZIndex(1),this.applyListeners(e?.listeners)}init(e){return super.init(e),i.addListener(this,`mousedown`,this._onMouseDown),i.addListener(this,`click`,this._onClick),this}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}dragMove(e){this.emit(`dragmove`,e)}dragEnd(){this.emit(`dragend`)}_onMouseDown=e=>(this.emit(`dragstart`,e),!0);_onClick=()=>!0},je=c(ResizeHandle),Me=null;function ensureSortBadgeClassRule(){Me||=new a({scope:`class`,name:`SortPriorityBadge`,styles:{position:`absolute`,top:`2px`,right:`8px`,fontSize:`var(--ts-ui-sort-badge-font-size, var(--ts-ui-font-size))`,lineHeight:`1`,borderRadius:`3px`,padding:`1px 3px`,pointerEvents:`none`}})}var Ne={backgroundColor:`var(--ts-ui-sort-badge-bg, rgba(0,0,0,0.15))`,foregroundColor:`var(--ts-ui-sort-badge-color, inherit)`},SortPriorityBadge=class extends f{constructor(e,t){ensureSortBadgeClassRule(),super({tag:`span`,...e??{}},{...Ne,...t??{}}),this._priority??=null,this.setVisible(this._shouldShow(this._priority))}applyOptions(e){return super.applyOptions(e),e.priority!==void 0&&(this._priority=e.priority),this}render(){let t=super.render();return e.sink.apply(t,{text:this._priorityText()}),t}getPriority(){return this._priority}setPriority(t){this._priority=t;let n=this.getElement();return n&&e.sink.apply(n,{text:this._priorityText()}),this.setVisible(this._shouldShow(t)),this}clearPriority(){return this.setPriority(null)}_priorityText(){return this._shouldShow(this._priority)?String(this._priority):``}_shouldShow(e){return e!=null&&e>=2}},Pe=c(SortPriorityBadge),Fe=16,Ie=16,Le=null;function ensureHeaderCellGlyphClassRule(){Le||=new a({scope:`class`,name:`HeaderCellGlyph`,styles:{position:`absolute`,left:`var(--ts-ui-table-header-glyph-gap, 4px)`,top:`50%`}})}var HeaderCell=class extends I{_text;_fieldName;_isDragging=!1;_tooltipText=``;_sortState=null;_headerGlyph=null;_headerGlyphInstance=null;_columnFocused=!1;_required=!1;constructor(e,t,n){super(`th`),this.getAria().setRole(`columnheader`),this.getAria().setSort(`none`),this._text=e,this._fieldName=t,this._headerGlyph=n??null;let r=this.getRenderer();r.getText().setFontSize(`--ts-ui-table-header-font-size`),r.getText().setFontWeight(`bold`),r.getText().setText(e),this.createStyleRule(`:active`).set(`boxShadow`,`var(--ts-ui-button-pressed-shadow, 1px 2px 5px 0 rgba(0,0,0,0.2) inset)`),this._resizeHandle=new je({listeners:{dragstart:e=>this.onResizeDragStart(e),dragmove:e=>this.emit(`resizedrag`,e)}}),this._priorityBadge=new Pe}init(t){super.init(t);let n=t||this.getElement();return n?(i.addSubtreeListener(this,`click`,e=>this.onSortClick(e.shiftKey)),i.addSubtreeListener(this,`contextmenu`,e=>{e.preventDefault(),this.emit(`contextmenu`,this._fieldName,e.clientX,e.clientY)}),e.sink.appendChild(n,this._resizeHandle.getElement(!0)),e.sink.appendChild(n,this._priorityBadge.getElement(!0)),this._tooltipText&&_.attachToElement(n,this._tooltipText),this._headerGlyph&&this.setHeaderGlyph(this._headerGlyph),this):this}setFieldName(e){return this._fieldName=e,this}getFieldName(){return this._fieldName}getHeaderGlyph(){return this._headerGlyph}setHeaderGlyph(e){return this._headerGlyph=e,this._mountHeaderGlyph(this.getElement()),this.doLayout(),this}_mountHeaderGlyph(t){this._headerGlyphInstance&&=(this._headerGlyphInstance.dispose(),null);let n=d.getTheme().table.cell.padding,i=this._headerGlyph;if(!i||!t){this.getRenderer().setInsets(new r(0,n,0,n));return}ensureHeaderCellGlyphClassRule();let a=new h(i);a.setTransform(`translateY(-50%)`),a.setSize({width:Fe,height:Ie}),a.setForegroundColor(`var(--ts-ui-table-header-glyph-color, currentColor)`),a.setPointerEvents(`none`);let o=a.getElement(!0);e.sink.apply(o,{addClass:[`HeaderCellGlyph`]}),e.sink.appendChild(t,o),this._headerGlyphInstance=a;let s=20+n;this.getRenderer().setInsets(new r(0,n,0,s))}setSortState(e,t){return this._sortState={state:e,priority:t??null},this._renderTitle(),this.getAria().setSort(e===`asc`?`ascending`:`descending`),this._priorityBadge.setPriority(t??null),this}getSortState(){return this._sortState}clearSortState(){return this._sortState=null,this._renderTitle(),this.getAria().setSort(`none`),this._priorityBadge.clearPriority(),this}setRequired(e){return this._required=e,this._renderTitle(),this}setHeaderText(e){return this._text===e?this:(this._text=e,this._renderTitle(),this)}_renderTitle(){let e=this._sortState?this._sortState.state===`asc`?` ▲`:` ▼`:``,t=this._required?` *`:``;this.getRenderer().getText().setText(this._text+t+e)}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}setTooltip(e){this._tooltipText=e;let t=this.getElement();return t&&_.attachToElement(t,e),this}getTooltip(){return this._tooltipText}onSortClick(e){if(this._isDragging){this._isDragging=!1;return}this.emit(`sortclick`,this._fieldName,e)}onResizeDragStart(e){e.stopPropagation(),this._isDragging=!0,this.emit(`resizestart`,e.clientX),i.addViewportListener(this,`mousemove`,this.onResizeDrag),i.addViewportListener(this,`mouseup`,this.onResizeDragStop),ee(ke)}onResizeDrag(e){return this._resizeHandle.dragMove(e.clientX),!0}onResizeDragStop(){return i.removeViewportListener(this,`mousemove`,this.onResizeDrag),i.removeViewportListener(this,`mouseup`,this.onResizeDragStop),te(),this._resizeHandle.dragEnd(),setTimeout(()=>{this._isDragging=!1},0),!0}setColumnFocused(e){return this._columnFocused=e,e?this.setShadow(`inset 0 -2px 0 0 var(--ts-ui-focus-ring, rgba(30, 100, 200, 0.6))`):this.clearShadow(),this}isColumnFocused(){return this._columnFocused}destructor(){this._resizeHandle?.dispose(),this._priorityBadge?.dispose(),this._headerGlyphInstance?.dispose(),super.destructor()}},Re=c(HeaderCell),ParentHeaderCell=class extends I{_text;_color;_tooltipText=``;constructor(e,t){super(`th`),this._text=e,this._color=t,this.getAria().setRole(`columnheader`);let n=this.getRenderer();n.getText().setFontSize(`--ts-ui-table-header-font-size`),n.getText().setFontWeight(`bold`),n.getText().setTextAlign(`center`),n.getText().setText(e),this.setBackgroundColor(t??`transparent`),this.setShadow([`inset -1px 0 0 0 var(--ts-ui-table-resize-handle-color, rgba(0, 0, 0, 0.2))`,`inset 0 -1px 0 0 var(--ts-ui-table-resize-handle-color, rgba(0, 0, 0, 0.2))`].join(`, `))}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}setTooltip(e){this._tooltipText=e;let t=this.getElement();return t&&_.attachToElement(t,e),this}getTooltip(){return this._tooltipText}getText(){return this._text}getColor(){return this._color}init(e){super.init(e);let t=e||this.getElement();return t?(i.addSubtreeListener(this,`contextmenu`,this.onContextMenu),this._tooltipText&&_.attachToElement(t,this._tooltipText),this):this}onContextMenu(e){e.preventDefault(),this.emit(`contextmenu`,e.clientX,e.clientY)}},ze=c(ParentHeaderCell),CellGeometryCache=class{_geometry=new WeakMap;clear(){this._geometry=new WeakMap}apply(e,t,n,r){let i=this._geometry.get(e);i&&i.x===t&&i.w===n&&i.h===r||(e.setAutoCommitStyle(!1),e.setX(t),e.setY(0),e.setWidth(n),e.setHeight(r),e.setAutoCommitStyle(!0),e.doLayout(),e.getElement()&&this._geometry.set(e,{x:t,w:n,h:r}))}},StringEditor=class extends CellEditor{_textField=new T;_value=null;constructor(){super(),i.addListener(this._textField,`blur`,e=>{i.fireEvent(this,`blur`,e)}),i.addListener(this._textField,`keydown`,e=>{i.fireEvent(this,`keydown`,{detail:{key:e.key,code:e.code,keyCode:e.keyCode,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}})}),i.addListener(this._textField,`input`,()=>this.onInput()),this._textField.setMaxSize({width:2**53-1,height:2**53-1}),this._textField.clearPadding(),this._textField.setBorderRadius(`0`),this._textField.setBorder({border:`0px solid transparent`}),this._textField.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this._textField.setOutline(`none`),this._textField.setText(``),this.addComponent(this._textField)}getValue(){return this._value}setValue(e){return this._value=e??null,this._textField.setText(this._value===null?``:String(this._value)),this}focus(e=!1){return this._textField.focus(e),this._textField.select(),this}onInput(){let e=this._textField.getText();this._value=e||null}},Be=c(StringEditor),NumberEditor=class extends CellEditor{_textField=new T;_value=null;constructor(){super(),i.addListener(this._textField,`blur`,e=>{i.fireEvent(this,`blur`,e)}),i.addListener(this._textField,`keydown`,e=>{i.fireEvent(this,`keydown`,{detail:{key:e.key,code:e.code,keyCode:e.keyCode,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}})}),i.addListener(this._textField,`input`,()=>this.onInput()),this.setMaxSize({width:2**53-1,height:2**53-1}),this._textField.setMaxSize({width:2**53-1,height:2**53-1}),this._textField.clearPadding(),this.setBorderRadius(`0`),this._textField.setBorder({border:`0px solid transparent`}),this._textField.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this._textField.setOutline(`none`),this._textField.setTextAlign(`right`),this._textField.setText(``),this.addComponent(this._textField,{anchor:u.NORTHEAST})}getValue(){return this._value}setValue(e){return this._value=e??null,this._textField.setText(this._value===null?``:String(this._value)),this}focus(e=!1){return this._textField.focus(e),this._textField.select(),this}onInput(){let e=this._textField.getText();if(!e){this._value=null;return}let t=Number(e);this._value=isNaN(t)?null:t}},Ve=c(NumberEditor),TextInputCellEditor=class extends CellEditor{_type=null;_inputMode=null;_autoComplete=null;constructor(){super(`input`)}setType(e){return this._type=e,this.setElementAttribute(`type`,e),this}setInputMode(e){return this._inputMode=e,this.setElementAttribute(`inputmode`,e),this}setAutoComplete(e){return this._autoComplete=e,this.setElementAttribute(`autocomplete`,e),this}init(t){super.init(t);let n=t||this.getElement();return this._type!==null&&e.sink.apply(n,{setAttr:{type:this._type}}),this._inputMode!==null&&e.sink.apply(n,{setAttr:{inputmode:this._inputMode}}),this._autoComplete!==null&&e.sink.apply(n,{setAttr:{autocomplete:this._autoComplete}}),this}},DateEditor=class extends TextInputCellEditor{_value=null;_dropdown=null;_animated=!0;_text=``;constructor(){super(),this.setMaxSize({width:2**53-1,height:2**53-1}),this.setBorderRadius(`0`),this.setBorder({border:`0px solid transparent`}),this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this.setOutline(`none`),i.addListener(this,`focus`,()=>this.openDropdown()),i.addListener(this,`blur`,()=>this.closeDropdown()),i.addListener(this,`input`,()=>this.onInput()),this.setType(`text`),this.setInputMode(`none`),this.setAutoComplete(`off`)}destructor(){this._dropdown?.dispose(),super.destructor()}isEmpty(){return!this.getText()&&this._value===null}getValue(){return this._value}setValue(e){return this._value=e,this.setText(e?this.toInputString(e):``),this}setText(t){this._text=t;let n=this.getElement();return n&&e.sink.setValue(n,t),this}getText(){return this._text}syncTextFromDom(){let t=this.getElement();this._text=t?e.source.getValue(t):``}setDropdownAnimated(e){return this._animated=e,this._dropdown&&this._dropdown.setAnimated(e),this}isDropdownAnimated(){return this._animated}ensureDropdown(){return this._dropdown||(this._dropdown=new fe(e=>this.onDateSelected(e)),this._dropdown.setAnimated(this._animated)),this._dropdown}openDropdown(){let e=this.ensureDropdown();if(e.isOpen())return;let t=this.getElement();t&&e.showAt(t,this._value)}closeDropdown(){this._dropdown?.isOpen()&&this._dropdown.hideAnimated()}onInput(){this.syncTextFromDom();let e=this.getText();if(!e){this._value=null;return}let t=new Date(e+`T00:00:00`);this._value=isNaN(t.getTime())?null:t}onDateSelected(t){this.setValue(t),this._dropdown?.hideAnimated();let n=this.getElement();n&&e.sink.blur(n)}toInputString(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}},He=c(DateEditor),TimeEditor=class extends TextInputCellEditor{_showSeconds;_value=null;_dropdown=null;_animated=!0;_text=``;constructor(e=!1){super(),this._showSeconds=e,this.setMaxSize({width:2**53-1,height:2**53-1}),this.setBorderRadius(`0`),this.setBorder({border:`0px solid transparent`}),this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this.setOutline(`none`),i.addListener(this,`focus`,()=>this.openDropdown()),i.addListener(this,`blur`,()=>this.closeDropdown()),i.addListener(this,`input`,()=>this.onInput()),this.setType(`text`),this.setInputMode(`none`),this.setAutoComplete(`off`)}destructor(){this._dropdown?.dispose(),super.destructor()}isEmpty(){return!this.getText()&&this._value===null}getValue(){return this._value}setValue(e){return this._value=e,this.setText(e?this.toInputString(e):``),this}setText(t){this._text=t;let n=this.getElement();return n&&e.sink.setValue(n,t),this}getText(){return this._text}syncTextFromDom(){let t=this.getElement();this._text=t?e.source.getValue(t):``}setDropdownAnimated(e){return this._animated=e,this._dropdown&&this._dropdown.setAnimated(e),this}isDropdownAnimated(){return this._animated}ensureDropdown(){return this._dropdown||(this._dropdown=new le((e,t,n)=>this.onTimeSelected(e,t,n),{showSeconds:this._showSeconds}),this._dropdown.setAnimated(this._animated)),this._dropdown}openDropdown(){let e=this.ensureDropdown();if(e.isOpen())return;let t=this.getElement();t&&e.showAt(t,this._value)}closeDropdown(){this._dropdown?.isOpen()&&this._dropdown.hideAnimated()}onInput(){this.syncTextFromDom();let e=this.getText();if(!e){this._value=null;return}let t=e.split(`:`).map(Number);if(t.some(isNaN)){this._value=null;return}this._value=new Date(1970,0,1,t[0],t[1]??0,t[2]??0)}onTimeSelected(e,t,n){let r=new Date(1970,0,1,e,t,n,0);this.setValue(r)}toInputString(e){let t=String(e.getHours()).padStart(2,`0`),n=String(e.getMinutes()).padStart(2,`0`);return this._showSeconds?`${t}:${n}:${String(e.getSeconds()).padStart(2,`0`)}`:`${t}:${n}`}},H=c(TimeEditor),DateTimeEditor=class extends TextInputCellEditor{_showSeconds;_value=null;_dropdown=null;_animated=!0;_text=``;constructor(e=!1){super(),this._showSeconds=e,this.setMaxSize({width:2**53-1,height:2**53-1}),this.setBorderRadius(`0`),this.setBorder({border:`0px solid transparent`}),this.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this.setOutline(`none`),i.addListener(this,`focus`,()=>this.openDropdown()),i.addListener(this,`blur`,e=>this.onEditorBlur(e)),i.addListener(this,`input`,()=>this.onInput()),this.setType(`text`),this.setInputMode(`none`),this.setAutoComplete(`off`)}destructor(){this._dropdown?.dispose(),super.destructor()}retainsFocus(e){return this._dropdown!==null&&this._dropdown.isOpen()&&g.containsAcrossLayers(this._dropdown,e)}isEmpty(){return!this.getText()&&this._value===null}getValue(){return this._value}setValue(e){return this._value=e,this.setText(e?this.toInputString(e):``),this}setText(t){this._text=t;let n=this.getElement();return n&&e.sink.setValue(n,t),this}getText(){return this._text}syncTextFromDom(){let t=this.getElement();this._text=t?e.source.getValue(t):``}setDropdownAnimated(e){return this._animated=e,this._dropdown&&this._dropdown.setAnimated(e),this}isDropdownAnimated(){return this._animated}ensureDropdown(){return this._dropdown||(this._dropdown=new pe(e=>this.onDateTimeSelected(e),{showSeconds:this._showSeconds}),this._dropdown.setAnimated(this._animated)),this._dropdown}openDropdown(){let e=this.ensureDropdown();if(e.isOpen())return;let t=this.getElement();t&&(e.setCloseHandler(()=>this.onOutsideDismiss()),e.setAnchorElement(t),e.showAt(t,this._value))}closeDropdown(){this._dropdown?.isOpen()&&this._dropdown.hideAnimated()}onOutsideDismiss(){this.closeDropdown(),this.requestCommit()}onEditorBlur(e){this.retainsFocus(blurRelatedTargetHandle(e))||this.closeDropdown()}onInput(){this.syncTextFromDom();let e=this.getText();if(!e){this._value=null;return}let t=new Date(e.replace(` `,`T`));this._value=isNaN(t.getTime())?null:t}onDateTimeSelected(e){this.setValue(e)}toInputString(e){let t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,`0`),r=String(e.getDate()).padStart(2,`0`),i=String(e.getHours()).padStart(2,`0`),a=String(e.getMinutes()).padStart(2,`0`);return this._showSeconds?`${t}-${n}-${r} ${i}:${a}:${String(e.getSeconds()).padStart(2,`0`)}`:`${t}-${n}-${r} ${i}:${a}`}},U=c(DateTimeEditor),CellEditorPool=class{_editors=new Map;_factories=new Map;_activeCell=null;constructor(){this._factories.set(`string`,()=>new Be),this._factories.set(`number`,()=>new Ve),this._factories.set(`date`,()=>new He),this._factories.set(`time`,()=>new H(!1)),this._factories.set(`time:seconds`,()=>new H(!0)),this._factories.set(`datetime`,()=>new U(!1)),this._factories.set(`datetime:seconds`,()=>new U(!0))}register(e,t){return this._factories.set(e,t),this._editors.delete(e),this}acquire(e,t){let n=this._factories.get(e);if(!n)return null;let r=this._editors.get(e);return r||(r=n(),this.wireListeners(r),this._editors.set(e,r)),this._activeCell=t,r}release(){this._activeCell=null}dispose(){for(let e of this._editors.values())e.dispose();this._editors.clear()}wireListeners(e){e.setCommitRequestHandler(()=>this._activeCell?.commitEdit()),i.addListener(e,`blur`,t=>{e.retainsFocus(blurRelatedTargetHandle(t))||this._activeCell?.commitEdit()}),i.addListener(e,`keydown`,e=>{this._activeCell?.onKeyDown(e)})}},ComboEditor=class extends CellEditor{_combo;_value=null;constructor(e){super(`div`);let t=normalizeComboOptions(e).map(e=>({key:e.value,label:e.label}));this._combo=new me,this._combo.setItems(t),this._combo.setBorder({border:`0px solid transparent`}),this._combo.setBorderRadius(`0`),this._combo.setShadow(`inset 0 0 0 1px var(--ts-ui-table-cell-editor-border, rgba(30, 100, 200, 0.6))`),this._combo.on(`action`,()=>this.commitFromCombo()),i.addListener(this._combo,`blur`,()=>this.commitFromCombo()),i.addListener(this._combo,`keydown`,e=>{i.fireEvent(this,`keydown`,{detail:{key:e.key,code:e.code,keyCode:e.keyCode,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey}})}),this.addComponent(this._combo)}getValue(){return this._value}setValue(e){return this._value=e??null,this._combo.setValue(this._value===null?``:String(this._value)),this}focus(e=!1){return this._combo.focus(e),this._combo.openDropdown(),this}setOptions(e){let t=normalizeComboOptions(e).map(e=>({key:e.value,label:e.label}));return this._combo.setItems(t),this._combo.setValue(this._value===null?``:String(this._value)),this}commitFromCombo(){let e=this._combo.getValue();this._value=e||null,this.requestCommit()}},W=c(ComboEditor);function resolveClickedColumn(t,n){for(let r=0;r<t.length;r++){let i=t[r].getElement();if(i&&(i===n||e.source.contains(i,n)))return r}return-1}var Ue=2;function computeColumnWindow(e,t,n){let r=e.length,i=Array(r),a=0;for(let t=0;t<r;t++)i[t]=a,a+=e[t];if(r===0)return{firstCol:0,lastCol:-1,widths:e,lefts:i};let o=t+n,s=-1,c=-1;for(let n=0;n<r;n++){let r=i[n];r+e[n]>=t&&r<=o&&(s===-1&&(s=n),c=n)}return s===-1&&(s=0,c=0),{firstCol:Math.max(0,s-Ue),lastCol:Math.min(r-1,c+Ue),widths:e,lefts:i}}function columnWidthsEqual(e,t){if(!t)return e.length===0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var We=class Body extends ge{_store;_hiddenColumns=new Set;_columns=[];_columnConfigs=new Map;_rowReadOnly=null;_cellGeom=new CellGeometryCache;_lastBodyWidth=0;_lastColumnWidths=[];_lastAriaRowCount=-1;_rowHeight;_colWindow={firstCol:0,lastCol:-1,widths:[],lefts:[]};_reconciling=!1;_storeRefresh=null;_selectedRecords=new Set;_anchorRecord=null;_focusedColIndex=0;_editorPool=new CellEditorPool;_header=null;_listeners=new p;constructor(e){super({tag:`tbody`}),this.setOverflow(`hidden`),this.setBackgroundColor(`var(--ts-ui-input-bg, rgb(255, 255, 255))`),this.getAria().setTabIndex(0),this.getAria().setRole(`rowgroup`),this._store=e,this.bindStore(e),this._rowHeight=this.computeRowHeight(),this.subscribeTheme(()=>this.onThemeReflow())}onThemeReflow(){this._rowHeight=this.computeRowHeight(),super.onThemeReflow()}computeRowHeight(){let e=d.getTheme();return n.lineHeightPx()+2*(e.table.cell.padding??2)}getRowHeight(){return this._rowHeight}createPoolRow(){let e=this.createRow();return e.setColumnWindow(this._colWindow.firstCol,this._colWindow.lastCol),this.wireRowCells(e),e}wireRowCells(e){for(let t of e.getComponents())t.setEditorPool(this._editorPool),t.setScrollIntoViewHandler(()=>this.scrollColumnIntoView(this._focusedColIndex))}bindStore(e){let refresh=()=>this.onStoreChange();this._storeRefresh=refresh,e.on(`load`,refresh),e.on(`add`,refresh),e.on(`remove`,refresh),e.on(`datachange`,refresh),e.on(`beforesync`,refresh),e.on(`sync`,refresh)}onStoreChange(){this._boundIndices.fill(-1),this.renderWindow()}getVisibleRecords(){return this._store.getRecords()}createRow(){return new V(this._store.model,void 0,this._hiddenColumns,this._columnConfigs,e=>this._store.notifyRecordChanged(e))}getTreeFieldName(){}computeRowAria(e,t){e.getAria().setRowIndex(t+2)}afterRowBound(e,t,n){}invalidateRowBindings(){this._boundIndices.fill(-1)}getStore(){return this._store}getHiddenColumns(){return this._hiddenColumns}getColumnConfigs(){return this._columnConfigs}getRowPool(){return this._rowPool}invalidateGeom(){super.invalidateGeom(),this._cellGeom.clear()}setHiddenColumns(e){let t=new Set;for(let n of e){let e=this._columns.find(e=>e.getField().getName()===n);(!e||!e.isUnhideable())&&t.add(n)}return this._hiddenColumns=t,this.syncPoolCells(),this.renderWindow(),this}setColumns(e){return this._columns=e,this.syncPoolCells(),this.renderWindow(),this}setRowReadOnly(e){return this._rowReadOnly=e,this}setColumnConfigs(e){return this._columnConfigs=e,this.registerComboEditors(e),this.syncPoolCells(),this.renderWindow(),this}registerComboEditors(e){for(let[t,n]of e){let e=n.values;e&&e.length>0?this._editorPool.register(`combo:${t}`,()=>new W(e)):n.cellValues&&this._editorPool.register(`combo:${t}`,()=>new W([]))}}syncPoolCells(){if(!this._reconciling){this._reconciling=!0;try{this.commitEditsOutsideWindow(null);let e=this.getTreeFieldName();for(let t=0;t<this._rowPool.length;t++){let n=this._rowPool[t];n.setColumnFields(this._store.model,this._hiddenColumns,this._columnConfigs,e),this.wireRowCells(n),this._rowGeom[t]=null}}finally{this._reconciling=!1}}}setStore(e){if(this._storeRefresh){let e=this._store;[`load`,`add`,`remove`,`datachange`,`beforesync`,`sync`].forEach(t=>e.off(t,this._storeRefresh))}return this._store=e,this.bindStore(e),this.invalidateGeom(),this.getElement()&&this.onStoreChange(),this}init(e){super.init(e);let t=e||this.getElement();return t?(this.initScroller(t),i.addListener(this,`focus`,this.onFocus),i.addListener(this,`keydown`,this.onKeyDown),i.addSubtreeListener(this,`click`,this.onSubtreeClick),this.renderWindow(),this):this}onScrollerTick(){this.renderWindow(),!this.wasRenderDeferred()&&this._scroller&&(this.emit(`verticalscroll`,this._scroller.getScrollY()),this.emit(`horizontalscroll`,this._scroller.getScrollX()))}onFocus(){this._updateActiveDescendant(),this._updateFocusStyle()}getEditorPool(){return this._editorPool}destructor(){this._editorPool.dispose(),super.destructor()}doLayout(){return super.doLayout(),this.renderWindowIfDeferred(),this}renderWindow(e,t){if(this.updateColumnWidthCache(e,t),!this._reconciling&&!(!this.getElement()||!this._scroller)&&!this.deferRenderWhileFirstLayoutHeld()){this._reconciling=!0;try{this.renderWindowPass()}finally{this._reconciling=!1}this.finishResumedRender()}}renderWindowPass(){let e=this._scroller,t=this.getVisibleRecords(),n=t.length,r=e.getScrollX(),i=e.getScrollY(),a=n*this._rowHeight,o=this._lastColumnWidths.reduce((e,t)=>e+t,0),s=Math.max(this._lastBodyWidth,o);e.clampToContent(s,a);let c=Math.max(this._lastBodyWidth,o),l=this._store.model.getFields().filter(e=>!this._hiddenColumns.has(e.getName())).length,u=l>0?c/l:c,d=Array.from({length:l},(e,t)=>this._lastColumnWidths[t]??u);this._colWindow=computeColumnWindow(d,e.getScrollX(),this.getWidth()||0),this.commitEditsOutsideWindow(this._colWindow)&&(t=this.getVisibleRecords(),n=t.length,a=n*this._rowHeight);let f=this.getHeight()||0,p=this.computeVisibleWindow(e.getScrollY(),f,n),m=this.computePoolTarget(p.windowSize,f,n);this.growRowPool(m),this.bindAndPositionRows(p.firstRow,p.windowSize,c,t,this._colWindow),this.hideExcessPoolRows(p.windowSize),n!==this._lastAriaRowCount&&(this.getAria().setRowCount(n),this._lastAriaRowCount=n),e.layoutScrollbars(s,a);let h=e.getScrollX(),g=e.getScrollY();h!==r&&this.emit(`horizontalscroll`,h),g!==i&&this.emit(`verticalscroll`,g),this._updateFocusStyle()}updateColumnWidthCache(e,t){if(e===void 0)return;let n=this._lastBodyWidth!==e||!columnWidthsEqual(this._lastColumnWidths,t);this._lastBodyWidth=e,this._lastColumnWidths=t??[],n&&this.invalidateGeom()}commitEditsOutsideWindow(e){let t=!1;for(let n of this._rowPool){let r=n.getComponents(),i=n.getColumnWindowStart();for(let n=0;n<r.length;n++){let a=i+n;(e===null||a<e.firstCol||a>e.lastCol)&&r[n].isEditing()&&(r[n].commitEdit(),t=!0)}}return t}bindAndPositionRows(e,t,n,r,i){let a=this._rowHeight;for(let o=0;o<t;o++){let t=this._rowPool[o],s=t.setColumnWindow(i.firstCol,i.lastCol);s&&this.wireRowCells(t);let c=e+o,l=this._boundIndices[o]!==c;l&&(t.setData(r[c]),this._boundIndices[o]=c,t.setStripe(c%2==1),this.updateRowVisualState(o),this.computeRowAria(t,c)),(l||s)&&this.applyReadOnlyState(t,r[c]),this.afterRowBound(t,c,l),this.applyRequiredEmptyState(t,r[c]),this.positionRow(o,c*a,n);let u=t.getComponents(),d=i.lefts[i.firstCol]??0;for(let e=0;e<u.length;e++){let t=i.widths[i.firstCol+e]??0;this._cellGeom.apply(u[e],d,t,a),d+=t}}}onSubtreeClick(t){if(!(t instanceof MouseEvent))return;let n=t.target===null?null:e.source.intern(t.target);for(;n;){let r=this._rowPool.find(e=>e.getElement()===n);if(r){this.onRowClick(r,t);return}n=e.source.getParentElement(n)}}onRowClick(t,n){let r=t.getData()??null;if(!r)return;let i=this.getVisibleRecords(),a=new Set(this._selectedRecords);this._anchorRecord=be(this._selectedRecords,this._anchorRecord,r,e=>i.indexOf(e),e=>i[e],{ctrl:n.ctrlKey||n.metaKey,shift:n.shiftKey}),this._boundIndices.forEach((e,t)=>{e!==-1&&this.updateRowVisualState(t)}),this.notifySelectionChange(a);let o=n.target===null?null:e.source.intern(n.target),s=resolveClickedColumn(t.getComponents(),o),c=s>=0?s+t.getColumnWindowStart():-1;c>=0&&(this._focusedColIndex=c);let l=o===null?``:e.source.getTagName(o);if(l!==`INPUT`&&l!==`TEXTAREA`&&l!==`SELECT`&&this.focus(),this._updateFocusStyle(),this._updateActiveDescendant(),c>=0){let e=t.getFieldNames()[s];this.emit(`cellclick`,{record:r,field:e,columnIndex:c,value:r.get(e),rowIndex:this.getVisibleRecords().indexOf(r),event:n})}}selectRecord(e){let t=new Set(this._selectedRecords);this._selectedRecords.clear(),this._anchorRecord=e,e&&this._selectedRecords.add(e),this._boundIndices.forEach((e,t)=>{e!==-1&&this.updateRowVisualState(t)}),this.notifySelectionChange(t)}getSelectedRecord(){return this._anchorRecord&&this._selectedRecords.has(this._anchorRecord)?this._anchorRecord:this._selectedRecords.size>0?[...this._selectedRecords][0]:null}getSelectedRecords(){return[...this._selectedRecords]}setSelectedRecords(e){let t=new Set(this._selectedRecords);this._selectedRecords.clear(),this._anchorRecord=e.length>0?e[0]:null;for(let t of e)this._selectedRecords.add(t);this._boundIndices.forEach((e,t)=>{e!==-1&&this.updateRowVisualState(t)}),this.notifySelectionChange(t)}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,t){this._listeners.fire(e,t)}notifySelectionChange(e){_e(e,this._selectedRecords)||this.emit(`selection`,this.getSelectedRecords())}scrollToRecord(e){let t=this.getVisibleRecords().indexOf(e);t!==-1&&this.setScrollY(t*this._rowHeight)}applyReadOnlyState(e,t){let n=this._rowReadOnly?.(t)===!0,r=e.getComponents(),i=e.getFieldNames();for(let e=0;e<r.length;e++){let a=r[e],o=i[e],s=this._columnConfigs.get(o),c=s?.readOnly===!0,l=s?.cellReadOnly?.(t)===!0,u=c||n||l;a.setReadOnly(u)}}static isEmptyValue(e){return e==null||e===``}applyRequiredEmptyState(e,t){let n=e.getComponents(),r=e.getFieldNames();for(let e=0;e<n.length;e++){let i=r[e],a=this._columnConfigs.get(i),o=a?.required===!0||a?.requiredPredicate?.(t)===!0,s=Body.isEmptyValue(t.get(i));n[e].setRequiredEmpty(o&&s)}}updateRowVisualState(t){let n=this._boundIndices[t];if(n===-1)return;let r=this.getVisibleRecords()[n];if(!r)return;let i=this._rowPool[t],a=i.getElement(),o=this._selectedRecords.has(r);o?e.sink.apply(a,{style:{"background-color":`var(--ts-ui-table-row-selected, rgba(30, 100, 200, 0.15))`,"box-shadow":`var(--ts-ui-table-row-selected-border, none)`}}):(e.sink.apply(a,{style:{"box-shadow":null}}),i.updateVisualState()),i.getAria().setSelected(o)}setHeader(e){return this._header=e,this}_updateFocusStyle(){for(let t of this._rowPool)for(let n of t.getComponents()){let t=n.getElement();t&&e.sink.apply(t,{style:{outline:null,"outline-offset":null}})}if(this._header?.setFocusedColumn(this._anchorRecord?this._focusedColIndex:null),!this._anchorRecord)return;let t=this.getVisibleRecords().indexOf(this._anchorRecord),n=this._boundIndices.indexOf(t);if(n<0)return;let r=this._rowPool[n],i=r.getComponents(),a=this._focusedColIndex-r.getColumnWindowStart(),o=a>=0&&a<i.length?i[a]:void 0;if(o){let t=o.getElement();t&&e.sink.apply(t,{style:{outline:`var(--ts-ui-indicator-selection, 1px dashed rgb(120, 170, 240))`,"outline-offset":`-1px`}})}}_updateActiveDescendant(){if(!this._anchorRecord){this.getAria().setActiveDescendant(``);return}let e=this.getVisibleRecords().indexOf(this._anchorRecord),t=this._boundIndices.indexOf(e);if(t<0){this.getAria().setActiveDescendant(``);return}let n=this._rowPool[t],r=n.getComponents(),i=this._focusedColIndex-n.getColumnWindowStart(),a=i>=0&&i<r.length?r[i]:void 0;a?this.getAria().setActiveDescendant(a.getId()):this.getAria().setActiveDescendant(this._rowPool[t].getId())}onKeyDown(e){let t=this.getVisibleRecords();if(t.length===0||!new Set([`ArrowDown`,`ArrowUp`,`Home`,`End`,`ArrowLeft`,`ArrowRight`,`PageUp`,`PageDown`,`Enter`,` `]).has(e.key))return;if(e.preventDefault(),e.key===`ArrowLeft`||e.key===`ArrowRight`){let t=this._store.model.getFields().filter(e=>!this._hiddenColumns.has(e.getName())).length;this._focusedColIndex=e.key===`ArrowLeft`?Math.max(0,this._focusedColIndex-1):Math.min(t-1,this._focusedColIndex+1),this.scrollColumnIntoView(this._focusedColIndex),this.renderWindow(),this._updateActiveDescendant(),this._updateFocusStyle();return}if(e.key===`Enter`||e.key===` `){if(!this._anchorRecord)return;this.scrollColumnIntoView(this._focusedColIndex),this.renderWindow();let e=t.indexOf(this._anchorRecord),n=this._boundIndices.indexOf(e);if(n<0)return;let r=this._rowPool[n],i=r.getComponents(),a=this._focusedColIndex-r.getColumnWindowStart(),o=a>=0&&a<i.length?i[a]:void 0;if(o instanceof Cell){let e=o;e.on(`editend`,()=>{this.focus(),this._updateFocusStyle(),this._updateActiveDescendant()}),e.startEdit()}return}let n=this._anchorRecord?t.indexOf(this._anchorRecord):-1,r=this.computePageSize(),i;i=e.key===`ArrowDown`?n<0?0:Math.min(n+1,t.length-1):e.key===`ArrowUp`?n<0?0:Math.max(n-1,0):e.key===`PageDown`?n<0?0:Math.min(n+r,t.length-1):e.key===`PageUp`?n<0?0:Math.max(n-r,0):e.key===`Home`?0:t.length-1;let a=t[i];this.selectRecord(a),this.scrollRecordIntoView(a),this.renderWindow(),this._updateActiveDescendant()}scrollRecordIntoView(e){this.scrollRowIntoView(this.getVisibleRecords().indexOf(e))}scrollColumnIntoView(e){let t=this._lastColumnWidths;if(!this._scroller||e<0||e>=t.length)return;let n=0;for(let r=0;r<e;r++)n+=t[r];let r=n+t[e],i=this._scroller.getScrollX(),a=this.getWidth()||0,o=i+a,s=i;n<i?s=n:r>o&&(s=r-a),s!==i&&this.setScrollX(s)}},G=c(We),K=`var(--ts-ui-table-header-bg, var(--ts-ui-button-bg, linear-gradient(rgb(241, 241, 241), rgb(200, 200, 200))))`,TableHeader=class extends f{_model;_store;_hiddenColumns=new Set;_columns=[];_listeners=new p;_scrollbarCover=null;_visibleFields=[];_windowFirst=0;_scrollX=0;_focusedCol=null;_columnsDirty=!0;_geometry={columnWidths:[],viewportWidth:0,columnHeight:0,parentRowHeight:0};_cellGeom=new CellGeometryCache;constructor(e,t){super({tag:`thead`}),this.getAria().setRole(`rowgroup`),this.setBorder({borderBottom:`1px solid var(--ts-ui-table-header-border, black)`}),this.setBackgroundColor(K),this.setBackgroundImage(K),this.setOverflow(`hidden`),this._model=e,this._store=t;let n=new V,r=new V;this.addRow(n),this.addRow(r),this.rebuildCells(),this.rebuildParentCells(),this.subscribeTheme(()=>this._cellGeom.clear())}getModel(){return this._model}setStore(e){return this._store=e,this}setModel(e){let toNames=e=>e.getFields().slice().filter(e=>!this._hiddenColumns.has(e.getName())).sort((e,t)=>e.getOrder()-t.getOrder()).map(e=>e.getName()),t=toNames(this._model),n=toNames(e);return t.length===n.length&&t.every((e,t)=>e===n[t])||(this._model=e,this.rebuildCells(),this.rebuildParentCells()),this.syncSortIndicators(),this}setHiddenColumns(e){let t=new Set;for(let n of e){let e=this._columns.find(e=>e.getField().getName()===n);(!e||!e.isUnhideable())&&t.add(n)}return this._hiddenColumns=t,this.rebuildCells(),this.rebuildParentCells(),this}setColumns(e){return this._columns=e,this.rebuildCells(),this.rebuildParentCells(),this}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,...t){this._listeners.fire(e,...t)}getColumns(){return this.getComponents()[1].getComponents()}getColumnWindowStart(){return this._windowFirst}getParentRow(){return this.getComponents()[0]}hasParentRow(){return this._columns.filter(e=>!this._hiddenColumns.has(e.getField().getName())).some(e=>e.getGroup()!==null)}getScrollbarCover(){if(this._scrollbarCover===null){let t=e.sink.createElement(`div`);e.sink.apply(t,{style:{position:`absolute`,top:`0`,boxSizing:`border-box`,zIndex:`1`,pointerEvents:`none`,backgroundColor:K,backgroundImage:K,borderLeft:`1px solid var(--ts-ui-table-resize-handle-color, rgba(0, 0, 0, 0.2))`}}),e.sink.appendChild(this.getElement(!0),t),this.trackHandle(t),this._scrollbarCover=t}return this._scrollbarCover}addRow(e){return this.addComponent(e),this}addComponent(e){return super.addComponent(e),this}setHeight(e){return super.setHeight(e),this}rebuildCells(){this._visibleFields=this.computeVisibleFields(this._model),this._columnsDirty=!0,this.syncSortIndicators()}computeVisibleFields(e){return e.getFields().slice().filter(e=>!this._hiddenColumns.has(e.getName())).sort((e,t)=>e.getOrder()-t.getOrder())}reconcileColumnCells(e,t){let n=this.getComponents()[1];if(!this._columnsDirty&&e===this._windowFirst&&t===this._windowFirst+n.getComponents().length-1)return!1;let r=new Map(this._columns.map(e=>[e.getField().getName(),e])),i=n.getComponents().slice(),a=new Map;for(let e of i){let t=n.getLayoutConstraints(e)?.data;t&&a.set(t.getName(),e)}let o=t-e+1,s=Array(o).fill(void 0);for(let n=e;n<=t;n++){let t=this._visibleFields[n].getName(),r=a.get(t);r&&(s[n-e]=r,a.delete(t))}let c=Array.from(a.values());for(let r=e;r<=t;r++){let t=r-e;if(s[t]!==void 0)continue;let i=this._visibleFields[r],a=c.pop();a?n.setLayoutConstraints(a,{data:i}):(a=new Re(i.getName(),i.getName(),null),n.addComponent(a,{data:i}),this.wireCell(a)),s[t]=a}for(let n=e;n<=t;n++){let t=s[n-e],i=this._visibleFields[n],a=r.get(i.getName());t.setFieldName(i.getName()),t.setHeaderText(a?.getHeaderText()??i.getName());let o=i.getDescription();t.getTooltip()!==o&&t.setTooltip(o);let c=a?.getHeaderGlyph()??null;t.getHeaderGlyph()!==c&&t.setHeaderGlyph(c),t.setBaseBackground(a?.getGroupColor()??null),t.setRequired(a?.isRequired()??!1),t.getAria().setColIndex(n+1)}for(let e of c)n.removeComponent(e),e.dispose();let l=new Map(s.map((e,t)=>[e,t]));return n.sortComponents((e,t)=>(l.get(e)??0)-(l.get(t)??0)),this._windowFirst=e,this._columnsDirty=!1,!0}rebuildParentCells(){let e=this.getParentRow();if(e.disposeAllComponents(),!this.hasParentRow())return;let t=this._columns.filter(e=>!this._hiddenColumns.has(e.getField().getName())).sort((e,t)=>e.getField().getOrder()-t.getField().getOrder());if(t.length===0)return;let n=0,r=t[0].getGroup(),i=t[0].getGroupColor(),flush=a=>{let o=new ze(r??``,i),s=t.slice(n,a).map(e=>e.getField().getName());r!==null&&s.length>0&&o.setTooltip(`${r}: ${s.join(`, `)}`),o.on(`contextmenu`,(e,t)=>{this.emit(`columncontextmenu`,``,e,t)}),e.addComponent(o,{data:{spanFrom:n,spanTo:a-1}})};for(let e=1;e<t.length;e++){let a=t[e].getGroup();r===null||a!==r?(flush(e),n=e,r=a,i=t[e].getGroupColor()):i===null&&t[e].getGroupColor()!==null&&(i=t[e].getGroupColor())}flush(t.length)}wireCell(e){e.on(`sortclick`,(e,t)=>this.handleSortClick(e,t)),e.on(`resizestart`,t=>this.emit(`columnresizestart`,this.columnIndexOf(e),t)),e.on(`resizedrag`,t=>this.emit(`columnresize`,this.columnIndexOf(e),t)),e.on(`contextmenu`,(e,t,n)=>this.emit(`columncontextmenu`,e,t,n))}columnIndexOf(e){let t=this.getColumns().indexOf(e);return t===-1?-1:this._windowFirst+t}handleSortClick(e,t){if(t){let t=this._store.getActiveSorters(),n=t.findIndex(t=>t.field===e),r;r=n===-1?[...t,{field:e,dir:`asc`}]:t[n].dir===`asc`?t.map((e,t)=>t===n?{field:e.field,dir:`desc`}:e):t.filter((e,t)=>t!==n),r.length===0?this._store.clearSort():this._store.sort(r)}else{let t=this._store.getActiveSorters(),n=t.length===1&&t[0].field===e?t[0]:null;n?n.dir===`asc`?this._store.sort(e,`desc`):this._store.clearSort():this._store.sort(e,`asc`)}this.syncSortIndicators()}syncSortIndicators(){let e=this.getColumns(),t=this._store.getActiveSorters(),n=new Map(t.map((e,t)=>[e.field,{dir:e.dir,priority:t+1}])),r=t.length>1;e.forEach((e,t)=>{let i=this._visibleFields[this._windowFirst+t],a=i?n.get(i.getName()):void 0;a?e.setSortState(a.dir,r?a.priority:null):e.clearSortState()})}renderColumnWindow(e){e&&(this._geometry=e);let t=this._geometry,n=computeColumnWindow(this._visibleFields.map((e,n)=>t.columnWidths[n]??0),this._scrollX,t.viewportWidth);return this.reconcileColumnCells(n.firstCol,n.lastCol)&&(this.syncSortIndicators(),this.applyFocusedColumn()),this.positionColumnCells(n,t.columnHeight),this.positionParentCells(n,t.parentRowHeight),this}positionColumnCells(e,t){let n=this.getColumns();for(let r=0;r<n.length;r++){let i=e.firstCol+r;this._cellGeom.apply(n[r],e.lefts[i]??0,e.widths[i]??0,t)}}positionParentCells(e,t){let n=this.getParentRow();for(let r of n.getComponents()){let i=n.getLayoutConstraints(r)?.data,a=i?.spanFrom??0,o=i?.spanTo??0,s=e.lefts[a]??0,c=(e.lefts[o]??0)+(e.widths[o]??0)-s;this._cellGeom.apply(r,s,c,t)}}setScrollX(e){return e===this._scrollX?this:(this._scrollX=e,this.getParentRow().setTranslate(-e,0),this.getComponents()[1].setTranslate(-e,0),this.renderColumnWindow(),this)}getScrollX(){return this._scrollX}setFocusedColumn(e){return this._focusedCol=e,this.applyFocusedColumn(),this}applyFocusedColumn(){let e=this.getColumns();for(let t=0;t<e.length;t++)e[t].setColumnFocused(this._windowFirst+t===this._focusedCol)}},q=c(TableHeader),FooterRow=class extends f{constructor(){super({tag:`tfoot`}),this.setBorder({borderTop:`1px solid var(--ts-ui-border-color, black)`});let e=`var(--ts-ui-button-bg, linear-gradient(rgb(241, 241, 241), rgb(200, 200, 200)))`;this.setBackgroundColor(e),this.setBackgroundImage(e);let t=new V;this.addRow(t)}getColumns(){return this.getComponents()[0].getComponents()}addRow(e){return this.addComponent(e),this}addComponent(e){return super.addComponent(e),this}setWidth(e){return super.setWidth(e),this.getComponents()[0].setWidth(this.getContentBounds()?.width??e),this}setHeight(e){return super.setHeight(e),this.getComponents()[0].setHeight(this.getContentBounds()?.height??e),this}},J=c(FooterRow),Y=class Column{_field;_minWidth;_maxWidth;_width;_maxContentLength;_hidden;_unhideable;_readOnly;_headerGlyph;_headerText;_group;_groupColor;_required;constructor(e,t){this._field=e,this._minWidth=t?.minWidth,this._maxWidth=t?.maxWidth,this._width=t?.width,this._maxContentLength=t?.maxContentLength,this._hidden=t?.hidden??!1,this._unhideable=t?.unhideable??!1,this._readOnly=t?.readOnly??!1,this._headerGlyph=t?.headerGlyph??null,this._headerText=t?.headerText??null,this._group=t?.group??null,this._groupColor=t?.groupColor??null,this._required=t?.required??!1}getField(){return this._field}getMinWidth(){return this._minWidth}getMaxWidth(){return this._maxWidth}getWidth(){return this._width}getMaxContentLength(){return this._maxContentLength}isInitiallyHidden(){return this._hidden}isUnhideable(){return this._unhideable}isReadOnly(){return this._readOnly}getHeaderGlyph(){return this._headerGlyph}getHeaderText(){return this._headerText}setHeaderGlyph(e){return this._headerGlyph=e,this}clearHeaderGlyph(){return this.setHeaderGlyph(null)}getGroup(){return this._group}getGroupColor(){return this._groupColor}isRequired(){return this._required}static resolve(e,t){let n=e.slice().sort((e,t)=>e.getOrder()-t.getOrder());if(!t)return n.map(e=>new Column(e));let r=new Map(t.columns.map(e=>[e.field,e])),i=new Set(t.columns.map(e=>e.field));return t.appendUnlisted===!1?n.filter(e=>i.has(e.getName())).map(e=>new Column(e,r.get(e.getName()))):n.map(e=>new Column(e,r.get(e.getName())))}},X=class TableExporter{static exportCSV(e,t,n,r){let i=[e.map(e=>TableExporter.escapeCSVField(e.getField().getName())).join(`,`),...t.map(t=>e.map(e=>TableExporter.escapeCSVField(TableExporter.formatValue(e,t.get(e.getField().getName()),n))).join(`,`))].join(`\r
|
|
2
2
|
`);TableExporter.download(i,r?.filename??`table-export.csv`,`text/csv;charset=utf-8;`)}static exportJSON(e,t,n,r){let i=t.map(t=>Object.fromEntries(e.map(e=>[e.getField().getName(),TableExporter.formatValue(e,t.get(e.getField().getName()),n)]))),a=JSON.stringify(i,null,2);TableExporter.download(a,r?.filename??`table-export.json`,`application/json`)}static formatValue(e,t,n){if(t==null||!(t instanceof Date))return t;let r=e.getField().getType(),i=n.get(e.getField().getName())?.showSeconds??!1;switch(r){case`date`:return t.toLocaleDateString();case`time`:return t.toLocaleTimeString(void 0,i?{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{hour:`2-digit`,minute:`2-digit`});case`datetime`:return t.toLocaleString(void 0,i?{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}:{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`});default:return t}}static escapeCSVField(e){let t=String(e??``);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
3
|
-
`)?`"`+t.replace(/"/g,`""`)+`"`:t}static download(t,n,r){let i=new Blob([t],{type:r}),a=URL.createObjectURL(i),o=e.sink.createElement(`a`);e.sink.apply(o,{setAttr:{href:a,download:n}}),e.sink.appendChild(e.source.getBody(),o),e.sink.click(o),e.sink.removeChild(e.source.getBody(),o),e.sink.release(o),URL.revokeObjectURL(a)}},We=new se([{name:`field`,type:`string`,order:0},{name:`value`,type:`auto`,order:1},{name:`filler`,type:`string`,order:2}]),Ge=30,Ke=4,qe=8,Je=8,Ye=100,Xe=21,Z=6,Ze=400,Qe=50,Q=3,$e=60,et=new Date(2e3,11,31,23,59,59),tt=.5,Table=class extends f{_store;_spec;_resolvedColumns=[];_hiddenColumns=new Set;_columnContextMenu=new ie;_headerVisible;_header;_body;_bodyVisible;_footer;_footerVisible;_columnWidths=[];_dragEdgeIndex=null;_dragLastClientX=0;_columnWidthTarget=0;_savedColumnWidths=new Map;_columnConfigs=new Map;_exportMenuEnabled=!1;_listeners=new p;_displayMode=`normal`;_rotatedRecord=null;_rotatedStore=null;_rotatedColumns=[];_rotatedConfigs=new Map;_rotatedFieldByName=new Map;_sourceRefresh=null;_suppressSelectionForward=!1;_autoWidthsSampled=!1;_widthRefs=null;_sampledCandidates=new Map;constructor(e,t,n){super({tag:`table`}),this.setLayoutManager(new Ce),this.getAria().setRole(`grid`),this.setBorder({border:`1px solid var(--ts-ui-border-color, black)`}),this.setInsets(new r(0,0,0,0)),this.setOverflow(`hidden`),this.setMinSize({width:100,height:100}),this._store=e,this._spec=t,this._headerVisible=!0,this._bodyVisible=!0,this._footerVisible=!1,this.bindSourceStore(e),this._resolvedColumns=Y.resolve(e.model.getFields(),t),this.initHiddenFromSpec(),this._header=new q(e.model,e),this._header.on(`columnresizestart`,(e,t)=>this.onColumnResizeStart(e,t)),this._header.on(`columnresize`,(e,t)=>this.onColumnResize(e,t)),this._header.on(`columncontextmenu`,(e,t,n)=>this.showColumnMenu(t,n)),this._header.setWillChange(`transform`),this.addComponent(this._header),this._header.setColumns(this._resolvedColumns),this._body=n?n(e):new G(e),this._body.setHeader(this._header),this.addComponent(this._body),this._body.setColumns(this._resolvedColumns),this._footer=new J,this.addComponent(this._footer);let i=this.getEffectiveHiddenSet();i.size>0&&(this._header.setHiddenColumns(i),this._body.setHiddenColumns(i)),t&&(this._columnConfigs=this.buildColumnConfigs(t),this._body.setColumnConfigs(this._columnConfigs)),this._body.setRowReadOnly(t?.rowReadOnly??null),this.getAria().setColCount(this.getColumns().length),this._body.on(`horizontalscroll`,e=>{this._header.setScrollX(e)}),this._body.on(`selection`,e=>{this._suppressSelectionForward||this._displayMode===`rotated`||this.emit(`selection`,e)}),this._body.on(`cellclick`,e=>this.emit(`cellclick`,e))}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,t){this._listeners.fire(e,t)}getColumns(){return this._displayMode===`rotated`?this._rotatedColumns:this.getSourceColumns()}getSourceColumns(){let e=this.getEffectiveHiddenSet();return this._resolvedColumns.filter(t=>!e.has(t.getField().getName()))}getDisplayMode(){return this._displayMode}setDisplayMode(e){if(e===this._displayMode)return this;if(this._displayMode=e,e===`rotated`){this._rotatedRecord=this._body.getSelectedRecord()??this._store.getRecords()[0]??null;let e=this.ensureRotatedStore();this.rebuildRotatedStore(),this.bindView(e,this._rotatedColumns,this._rotatedConfigs,new Set,()=>!0),this.emit(`selection`,this._rotatedRecord?[this._rotatedRecord]:[])}else this.bindView(this._store,this.getSourceColumns(),this._columnConfigs,this.getEffectiveHiddenSet(),this._spec?.rowReadOnly??null),this._body.selectRecord(this._rotatedRecord);return this}getStore(){return this._store}getModel(){return this._store.model}setStore(e){return this.setDisplayMode(`normal`),this._header.setStore(e),this.unbindSourceStore(this._store),this._store=e,this._columnWidths=[],this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._autoWidthsSampled=!1,this._widthRefs=null,this._sampledCandidates=new Map,this._resolvedColumns=Y.resolve(e.model.getFields(),this._spec),this.bindSourceStore(e),this._body.setStore(e),this._header.setModel(e.model),this._header.setColumns(this._resolvedColumns),this._body.setColumns(this._resolvedColumns),this._header.setHiddenColumns(this.getEffectiveHiddenSet()),this.getAria().setColCount(this.getColumns().length),this.doLayout(),this}getColumnWidths(){return this._columnWidths}setColumnWidths(e){this._columnWidths=e;let t=this.getColumns();return e.forEach((e,n)=>{let r=t[n];r&&this._savedColumnWidths.set(r.getField().getName(),e)}),this}getAvailableColumnWidth(){let t=this.getInnerSize();return t?t.width-e.source.getScrollBarWidth():0}getColumnWidthTarget(){return this._columnWidthTarget}setColumnVisible(e,t){if(this._displayMode===`rotated`)return this;if(!t){let t=this._resolvedColumns.find(t=>t.getField().getName()===e);if(t&&t.isUnhideable())return this}t?this._hiddenColumns.delete(e):this._hiddenColumns.add(e),this._widthRefs=null;let n=this.getColumns(),r=null,i=n.map((e,t)=>{let n=this._savedColumnWidths.get(e.getField().getName());return n===void 0?(r??=this.getIntrinsicColumnWidths(),r[t]??this.flexColumnWidth(e)):n}),a=this._columnWidths.reduce((e,t)=>e+t,0),o=i.reduce((e,t)=>e+t,0);this._columnWidths=o>a+.5&&a>0?this.trimToTarget(n,i,a,e):i,this._columnWidthTarget>0&&(this._columnWidthTarget=this._columnWidths.reduce((e,t)=>e+t,0));let s=this.getEffectiveHiddenSet();return this._header.setHiddenColumns(s),this._body.setHiddenColumns(s),this.getAria().setColCount(this.getColumns().length),this.doLayout(),this}getHeader(){return this._header}isHeaderVisible(){return this._headerVisible}getBody(){return this._body}isBodyVisible(){return this._bodyVisible}getFooter(){return this._footer}isFooterVisible(){return this._footerVisible}addRow(e={}){let[t]=this._store.add(e);return this._displayMode===`rotated`?(this.selectRecord(t),t):(this._body.scrollToRecord(t),this._body.selectRecord(t),t)}removeSelectedRow(){if(this._displayMode===`rotated`)return this._rotatedRecord&&this._store.remove(this._rotatedRecord),this;let e=this._body.getSelectedRecord();return e?(this._body.selectRecord(null),this._store.remove(e),this):this}selectRecord(e){return this._displayMode===`rotated`?e===this._rotatedRecord?this:(this._rotatedRecord=e,this.rebuildRotatedStore(),this.emit(`selection`,e?[e]:[]),this):(e&&this._body.scrollToRecord(e),this._body.selectRecord(e),this)}async sync(){return this._store.sync()}reject(){this._store.reject()}getSelectedRecord(){return this._displayMode===`rotated`?this._rotatedRecord:this._body.getSelectedRecord()}getSelectedRecords(){return this._displayMode===`rotated`?this._rotatedRecord?[this._rotatedRecord]:[]:this._body.getSelectedRecords()}addComponent(e,t){return e instanceof q?this._header=e:e instanceof G?this._body=e:e instanceof J&&(this._footer=e),super.addComponent(e,t),this}trimToTarget(e,t,n,r){let i=[...t],isFixedType=e=>{let t=e.getField().getType();return t===`boolean`||t===`number`||t===`date`},trim=(t,n)=>{let r=t.reduce((e,t)=>e+t.room,0);if(r<=0)return n;let a=Math.min(n,r);for(let{i:n,room:o}of t)i[n]=Math.max(i[n]-o/r*a,this.getColumnMinWidth(e[n]));return n-a},pool=t=>e.map((e,n)=>({i:n,room:isFixedType(e)===t&&e.getField().getName()!==r&&this._savedColumnWidths.has(e.getField().getName())?i[n]-this.getColumnMinWidth(e):0})).filter(e=>e.room>.5),a=i.reduce((e,t)=>e+t,0)-n;return a=trim(pool(!1),a),a>.5&&trim(pool(!0),a),i}buildColumnConfigs(e){let t=new Map;for(let n of e.columns)t.set(n.field,n);return t}initHiddenFromSpec(){for(let e of this._resolvedColumns)e.isInitiallyHidden()&&!e.isUnhideable()&&this._hiddenColumns.add(e.getField().getName())}getEffectiveHiddenSet(){let e=new Set(this._resolvedColumns.map(e=>e.getField().getName())),t=new Set(this._hiddenColumns);for(let n of this._store.model.getFields())e.has(n.getName())||t.add(n.getName());return t}bindSourceStore(e){let refresh=()=>this.onSourceStoreChange();this._sourceRefresh=refresh,e.on(`load`,refresh),e.on(`add`,refresh),e.on(`remove`,refresh),e.on(`datachange`,refresh)}unbindSourceStore(e){this._sourceRefresh&&[`load`,`add`,`remove`,`datachange`].forEach(t=>e.off(t,this._sourceRefresh))}onSourceStoreChange(){if(this.maybeResampleColumnWidths(),this._displayMode!==`rotated`)return;let e=this._store.getRecords();if(!(this._rotatedRecord!==null&&e.includes(this._rotatedRecord))){let t=this._rotatedRecord;this._rotatedRecord=e[0]??null,this._rotatedRecord!==t&&this.emit(`selection`,this._rotatedRecord?[this._rotatedRecord]:[])}this.rebuildRotatedStore()}ensureRotatedStore(){if(this._rotatedStore)return this._rotatedStore;let e={columns:[{field:`field`,minWidth:80,maxWidth:200,unhideable:!0},{field:`value`,minWidth:120,maxWidth:360,unhideable:!0,cellType:e=>this.rotatedCellType(e),cellValues:e=>this.rotatedCellValues(e)},{field:`filler`,headerText:``,minWidth:0,unhideable:!0}],rowReadOnly:()=>!0};return this._rotatedStore=new ce(We,[]),this._rotatedColumns=Y.resolve(We.getFields(),e),this._rotatedConfigs=this.buildColumnConfigs(e),this._rotatedStore}rebuildRotatedStore(){let e=this.ensureRotatedStore(),t=this.getSourceColumns().map(e=>e.getField()),n=this._rotatedRecord;this._rotatedFieldByName=new Map(t.map(e=>[e.getName(),e])),e.loadData(n?t.map(e=>({field:e.getName(),value:n.get(e.getName())})):[])}rotatedCellType(e){let t=this._rotatedFieldByName.get(e.get(`field`));if(!t)return null;let n=this._columnConfigs.get(t.getName())?.values;return n&&n.length>0?`combo`:t.getType()}rotatedCellValues(e){let t=this._rotatedFieldByName.get(e.get(`field`));return t?this._columnConfigs.get(t.getName())?.values:void 0}bindView(e,t,n,r,i){this._suppressSelectionForward=!0,this._header.setStore(e),this._header.setModel(e.model),this._header.setColumns(t),this._header.setHiddenColumns(r),this._body.selectRecord(null),this._body.setStore(e),this._body.setColumnConfigs(n),this._body.setColumns(t),this._body.setHiddenColumns(r),this._body.setRowReadOnly(i),this._body.setStore(e),this._suppressSelectionForward=!1,this._columnWidths=[],this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._widthRefs=null,this.getAria().setColCount(this.getColumns().length),this.doLayout()}destructor(){this._columnContextMenu.dispose(),super.destructor()}showColumnMenu(e,t){if(this._displayMode===`rotated`){if(!this._exportMenuEnabled)return;this._columnContextMenu.show(e,t,[{text:`Export as CSV`,action:()=>this.exportCSV()},{text:`Export as JSON`,action:()=>this.exportJSON()}]);return}let n=this._resolvedColumns.slice().sort((e,t)=>e.getField().getOrder()-t.getField().getOrder()),r=[],i;n.forEach(e=>{let t=e.getField().getName(),n=!this._hiddenColumns.has(t),a=e.getGroup();a!==null&&a!==i&&r.push({text:a,enabled:!1});let o=a===null?``:`\xA0\xA0\xA0\xA0`,s=!e.isUnhideable();r.push({text:o+(n?`✓ `:` `)+t,action:()=>this.setColumnVisible(t,!n),enabled:s}),i=a}),r.push({separator:!0},{text:`Reset columns`,action:()=>this.resetColumns()}),this._exportMenuEnabled&&r.push({separator:!0},{text:`Export as CSV`,action:()=>this.exportCSV()},{text:`Export as JSON`,action:()=>this.exportJSON()}),this._columnContextMenu.show(e,t,r)}setExportMenuEnabled(e){return this._exportMenuEnabled=e,this}exportCSV(e){let t=this.getExportColumns(e?.includeHidden??!1),n=this._store.getRecords();X.exportCSV(t,n,this._columnConfigs,e)}exportJSON(e){let t=this.getExportColumns(e?.includeHidden??!1),n=this._store.getRecords();X.exportJSON(t,n,this._columnConfigs,e)}getExportColumns(e){return e?this._resolvedColumns.slice():this.getSourceColumns()}onColumnResizeStart(e,t){e<0||e>=this._columnWidths.length||(this._dragEdgeIndex=e,this._dragLastClientX=t)}onColumnResize(e,t){if(this._dragEdgeIndex===null||e!==this._dragEdgeIndex)return;let n=this._columnWidths,r=this.getColumns(),i=r.map(e=>e.getMinWidth()??Ge),a=r.map(e=>e.getMaxWidth()??1/0),o=[],s=[];for(let t=e;t>=0;t--)o.push(t);for(let t=e+1;t<n.length;t++)s.push(t);let c=t-this._dragLastClientX,l=c>=0?1:-1,u=this.getAvailableColumnWidth(),d=n.reduce((e,t)=>e+t,0),f=Math.max(0,d-u),p=l>0?Math.min(c,w(o,n,1,i,a)):Math.min(-c,w(o,n,-1,i,a),w(s,n,1,i,a)+f);if(p<=1e-6)return;let m=l>0?f>tt?0:p:p-Math.min(p,f),h=n.slice();ae(o,n,p,l,i,a,h),ae(s,n,m,-l,i,a,h),this._dragLastClientX+=l*p,this._columnWidths=h;let g=h.reduce((e,t)=>e+t,0);this._columnWidthTarget=g>u+tt?g:0,this.scheduleLayout()}resetColumns(){this._hiddenColumns=new Set,this.initHiddenFromSpec(),this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._widthRefs=null;let e=this.getColumns(),t=this.getIntrinsicColumnWidths();this._columnWidths=e.map((e,n)=>t[n]??this.flexColumnWidth(e));let n=this.getEffectiveHiddenSet();this._header.setHiddenColumns(n),this._body.setHiddenColumns(n),this.doLayout()}isAutoSizeColumns(){return(this._spec?.autoSizeColumns??!1)&&this._displayMode!==`rotated`}getColumnMinWidth(e){return e.getMinWidth()??this.columnWidthPolicy(e,0,null).min}getIntrinsicColumnWidths(){let e=this.getColumns(),t=this.measureHeaders(e),n=this.measureContent(e);return e.map((e,r)=>{let i=this.columnWidthPolicy(e,t[r],n[r]),a=e.getWidth()??i.preferred;return a===null?null:this.clampColumnWidth(a,e,i)})}clampColumnWidth(e,t,r){return n.clamp(e,t.getMinWidth()??r.min,t.getMaxWidth()??Ze)}flexColumnWidth(e){let t=this.measureHeaders([e])[0],n=this.columnWidthPolicy(e,t,null);return this.clampColumnWidth(Math.max(Ye,t),e,n)}measureHeaders(e){let t=e.map(e=>e.getHeaderText()??e.getField().getName());return n.measureTextWidths(t,{fontSize:`var(--ts-ui-table-header-font-size, var(--ts-ui-font-size))`,fontWeight:`bold`}).map(e=>e+Xe)}measureContent(e){this.collectCandidates(e);let t=e.map(e=>this.resolveContentCandidates(e)),r=[],i=[];t.forEach((e,t)=>{e?.forEach(e=>{i.push(t),r.push(e)})});let a=n.measureTextWidths(r),o=e.map(()=>null);return a.forEach((e,t)=>{let n=i[t];o[n]=Math.max(o[n]??0,e)}),o}resolveContentCandidates(e){let t=e.getField().getType();if(t!==`string`&&t!==`auto`||!this.isAutoSizeColumns())return null;let n=this._sampledCandidates.get(e.getField().getName());if(n&&n.length>0)return n;let r=this._columnConfigs.get(e.getField().getName());if(r?.values&&r.values.length>0)return normalizeComboOptions(r.values).map(e=>e.label).sort((e,t)=>t.length-e.length).slice(0,Q);let i=e.getMaxContentLength();return i===void 0?null:[`0`.repeat(Math.min(i,$e))]}collectCandidates(e){let t=e.map(e=>this.samplesRecordText(e)),n=Math.min(Qe,this._store.getCount()),r=new Map;for(let i=0;i<n;i++){let n=this._store.getAt(i);e.forEach((e,i)=>{if(!t[i])return;let a=e.getField().getName(),o=n.get(a),s=String(X.formatValue(e,o,this._columnConfigs)??``),c=r.get(a)??[];this.keepLongest(c,s),r.set(a,c)})}n>0&&(this._autoWidthsSampled=!0),this._sampledCandidates=r}keepLongest(e,t){e.includes(t)||(e.push(t),e.sort((e,t)=>t.length-e.length),e.length>Q&&(e.length=Q))}samplesRecordText(e){let t=this._columnConfigs.get(e.getField().getName());if(t?.renderer||t?.values&&t.values.length>0)return!1;let n=e.getField().getType();return n===`number`||(n===`string`||n===`auto`)&&this.isAutoSizeColumns()}sampledDigits(e){let t=this._sampledCandidates.get(e.getField().getName());return!t||t.length===0?null:Math.max(...t.map(e=>e.length))}showsSeconds(e){return this._columnConfigs.get(e.getField().getName())?.showSeconds??!1}columnWidthPolicy(e,t,n){let r=this.ensureWidthReferences(),i=e.getField().getType();switch(i){case`boolean`:return{min:22,preferred:Math.max(22,t)};case`glyph`:return{min:26,preferred:Math.max(26,t)};case`date`:case`time`:case`datetime`:{let n=`${i}:${this.showsSeconds(e)}`,a=(r.datePx.get(n)??0)+Z;return{min:a,preferred:Math.max(a,t)}}case`number`:{let n=r.digitPx*Ke+Z,i=e.getMaxContentLength()??this.sampledDigits(e)??qe;return{min:n,preferred:Math.max(n,r.digitPx*i+Z,t)}}default:{let e=Math.max(Ge,r.digitPx*Je+Z);return n===null?{min:e,preferred:null}:{min:e,preferred:Math.max(e,n,t)}}}}ensureWidthReferences(){if(this._widthRefs)return this._widthRefs;let e=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`],t=this.dateReferenceKeys(),r=n.measureTextWidths([...e,...t.map(e=>e.text)]);return this._widthRefs={digitPx:Math.max(...r.slice(0,e.length)),datePx:new Map(t.map((t,n)=>[t.key,r[e.length+n]]))},this._widthRefs}dateReferenceKeys(){let e=new Map;for(let t of this.getColumns()){let n=t.getField().getType();if(n!==`date`&&n!==`time`&&n!==`datetime`)continue;let r=`${n}:${this.showsSeconds(t)}`;e.has(r)||e.set(r,String(X.formatValue(t,et,this._columnConfigs)??``))}return Array.from(e,([e,t])=>({key:e,text:t}))}maybeResampleColumnWidths(){!this.isAutoSizeColumns()||this._autoWidthsSampled||this._store.getCount()===0||(this._columnWidths=[],this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._widthRefs=null,this.doLayout())}},$=c(Table);h.register(E,be,xe,Se);var TablePanel=class extends m{_table;_toolbar;_syncBtn;_rejectBtn;_spinner=null;_paginationBar=void 0;constructor(e,t){super(),this.setLayoutManager(new re),this._toolbar=new f,this._toolbar.setLayoutManager(new ee);let n=new S({glyph:`plus`});n.setPreferredSize({width:28,height:28}),n.on(`action`,()=>{this._table.addRow()}),_.attach(n,`Add row`),this._toolbar.addComponent(n);let r=new S({glyph:`minus`});r.setPreferredSize({width:28,height:28}),r.on(`action`,()=>{this._table.removeSelectedRow()}),_.attach(r,`Remove selected row`),this._toolbar.addComponent(r),this._syncBtn=new S({glyph:`arrows-rotate`}),this._syncBtn.setPreferredSize({width:28,height:28}),this._syncBtn.on(`action`,()=>{this._table.sync()}),_.attach(this._syncBtn,`Sync pending changes`),this._toolbar.addComponent(this._syncBtn),this._rejectBtn=new S({glyph:`ban`}),this._rejectBtn.setPreferredSize({width:28,height:28}),this._rejectBtn.on(`action`,()=>this._table.reject()),_.attach(this._rejectBtn,`Reject pending changes`),this._toolbar.addComponent(this._rejectBtn),this._table=new $(e,t),super.addComponent(this._toolbar,{placement:x.NORTH}),super.addComponent(this._table,{placement:x.CENTER}),e.on(`loadingchange`,e=>{this._spinner||=new b(24),e.loading?this._spinner.showOverlay(this._table):this._spinner.hideOverlay()});let refreshSyncButtons=()=>this.refreshSyncButtons();e.on(`add`,refreshSyncButtons),e.on(`remove`,refreshSyncButtons),e.on(`datachange`,refreshSyncButtons),e.on(`sync`,refreshSyncButtons),e.on(`load`,refreshSyncButtons),this.refreshSyncButtons()}refreshSyncButtons(){let e=this._table.getStore().hasPendingChanges();this._syncBtn.setEnabled(e),this._rejectBtn.setEnabled(e)}getTable(){return this._table}getToolbar(){return this._toolbar}setExportMenuEnabled(e){return this._table.setExportMenuEnabled(e),this}exportCSV(e){this._table.exportCSV(e)}exportJSON(e){this._table.exportJSON(e)}setPaginationBar(e){return this._paginationBar&&(this.removeComponent(this._paginationBar),this._paginationBar.dispose()),this._paginationBar=e,super.addComponent(e,{placement:x.SOUTH}),this}getPaginationBar(){return this._paginationBar}},nt=c(TablePanel),TreeBody=class extends Ue{_byId=new Map;_childIds=new Map;_expanded=new Set;_flatRows=[];_rowDnDTeardowns=new Map;_emptyAreaDropTeardown=null;_reparentHandler=null;_reparentValidator=null;constructor(e,t){super(e),this._idField=t.idField,this._parentField=t.parentField,this._treeColumn=t.treeColumn,this._indentPx=t.indentPx,this.rebuildIndex(),this.flatten()}getIdField(){return this._idField}getParentField(){return this._parentField}getTreeColumn(){return this._treeColumn}getFlatRecords(){return this._flatRows}getRecordById(e){return this._byId.get(e)}getChildrenOf(e){return this._childIds.get(e)??[]}isDirectoryRecord(e){return this.getChildrenOf(e.get(this._idField)).length>0}isAncestorOf(e,t){if(e===t)return!0;let n=e.get(this._idField),r=t,i=new Set;for(;r;){let e=r.get(this._parentField);if(e==null)return!1;if(e===n)return!0;if(i.has(e))return!1;i.add(e),r=this._byId.get(e)}return!1}isExpanded(e){let t=e.get(this._idField),n=this._childIds.get(t);return!!n&&n.length>0&&this._expanded.has(t)}setExpanded(e,t){let n=e.get(this._idField),r=this._childIds.get(n);if(!r||r.length===0)return this;if(t){if(this._expanded.has(n))return this;this._expanded.add(n)}else{if(!this._expanded.has(n))return this;this._expanded.delete(n)}return this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this}expandToDepth(e){this._expanded.clear();let recurse=(t,n)=>{if(!(n>e))for(let e of t){let t=e.get(this._idField),r=this._childIds.get(t);r&&r.length>0&&(this._expanded.add(t),recurse(r,n+1))}};return recurse(this._childIds.get(null)??[],0),this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this}collapseAll(){return this._expanded.size===0?this:(this._expanded.clear(),this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this)}expandAll(){let e=new Set;for(let[t,n]of this._childIds)t!==null&&n.length>0&&e.add(t);let t=this._childIds.get(null)??[];for(let n of t){let t=n.get(this._idField),r=this._childIds.get(t);r&&r.length>0&&e.add(t)}return this._expanded=e,this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this}getToggleElement(e){let t=e.getTreeCell();if(!t)return null;let n=t.getRenderer();if(!(n instanceof B))return null;let r=n.getToggle();return r?r.getElement()??null:null}init(e){return super.init(e),this.ensureEmptyAreaDropTarget(),this}onStoreChange(){this.rebuildIndex(),this.flatten(),super.onStoreChange()}getVisibleRecords(){return this._flatRows.map(e=>e.record)}createRow(){return new V(this.getStore().model,void 0,this.getHiddenColumns(),this.getColumnConfigs(),e=>this.getStore().notifyRecordChanged(e),this._treeColumn)}getTreeFieldName(){return this._treeColumn}computeRowAria(e,t){super.computeRowAria(e,t);let n=this._flatRows[t];n&&(e.getAria().setLevel(n.depth+1),e.getAria().setExpanded(n.hasChildren?n.expanded:null),e.getAria().setSetSize(n.siblingCount),e.getAria().setPosInSet(n.posInSet))}afterRowBound(e,t,n){let r=e.getTreeCell(),i=this._flatRows[t];if(r&&i&&r.getRenderer().setTreeState(i.depth,i.hasChildren,i.expanded),this._reparentHandler!==null){if(!i){this.teardownRowDnD(e);return}(n||!this._rowDnDTeardowns.has(e))&&this.installRowDnD(e,i.record)}}installRowDnD(e,t){this.teardownRowDnD(e);let n=C.makeDragSource(e,{dragData:{recordId:t.get(this._idField)}}),dropTargetForRow=e=>this.resolveDragged(e)?this.resolveDropParentForRow(t):null,r=C.makeDropTarget(e,{accepts:e=>{let t=this.resolveDragged(e);if(!t)return!1;let n=dropTargetForRow(e);return this._reparentValidator?.(t,n)??!1},onDrop:e=>{let t=this.resolveDragged(e);if(!t)return!1;let n=dropTargetForRow(e);return this._reparentHandler?.(t,n)??!1}});this._rowDnDTeardowns.set(e,()=>{n(),r()})}resolveDragged(e){let t=e.dragData.recordId;return this._byId.get(t)}resolveDropParentForRow(e){if(this.isDirectoryRecord(e))return e;let t=e.get(this._parentField);return t==null?null:this._byId.get(t)??null}teardownRowDnD(e){let t=this._rowDnDTeardowns.get(e);t&&(t(),this._rowDnDTeardowns.delete(e))}setReparentHandlers(e,t){return this._reparentValidator=e,this._reparentHandler=t,this.getElement()&&this.ensureEmptyAreaDropTarget(),this}ensureEmptyAreaDropTarget(){this._emptyAreaDropTeardown===null&&this._reparentHandler!==null&&(this._emptyAreaDropTeardown=C.makeDropTarget(this,{accepts:e=>{let t=this.resolveDragged(e);return t?this._reparentValidator?.(t,null)??!1:!1},onDrop:e=>{let t=this.resolveDragged(e);return t?this._reparentHandler?.(t,null)??!1:!1}}))}onSubtreeClick(t){let n=t.target===null?null:e.source.intern(t.target);for(let t of this.getRowPool()){let r=this.getToggleElement(t);if(r&&n!==null&&(n===r||e.source.contains(r,n))){let e=t.getData();e&&this.setExpanded(e,!this.isExpanded(e));return}}super.onSubtreeClick(t)}onKeyDown(e){if(e.key!==`ArrowRight`&&e.key!==`ArrowLeft`){super.onKeyDown(e);return}let t=this.getSelectedRecord();if(!t){super.onKeyDown(e);return}let n=this._flatRows.findIndex(e=>e.record===t);if(n<0){e.preventDefault();return}e.preventDefault();let r=this._flatRows[n];e.key===`ArrowRight`?this.handleArrowRight(r,n):this.handleArrowLeft(r,n)}handleArrowRight(e,t){if(!e.hasChildren)return;if(!e.expanded){this.setExpanded(e.record,!0);return}let n=this._flatRows[t+1];n&&n.depth===e.depth+1&&this.moveFocusTo(n.record)}handleArrowLeft(e,t){if(e.hasChildren&&e.expanded){this.setExpanded(e.record,!1);return}if(e.depth!==0){for(let n=t-1;n>=0;n--)if(this._flatRows[n].depth===e.depth-1){this.moveFocusTo(this._flatRows[n].record);return}}}moveFocusTo(e){this.selectRecord(e),this.scrollRecordIntoView(e),this.renderWindow(),this._updateActiveDescendant(),this._updateFocusStyle()}rebuildIndex(){this._byId.clear(),this._childIds.clear();let e=this.getStore().getRecords();for(let t of e){let e=t.get(this._idField);this._byId.set(e,t)}for(let t of e){let e=t.get(this._parentField),n=e!=null&&this._byId.has(e)?e:null,r=this._childIds.get(n);r?r.push(t):this._childIds.set(n,[t])}}flatten(){let e=[],recurse=(t,n)=>{let r=t.length;for(let i=0;i<t.length;i++){let a=t[i],o=a.get(this._idField),s=this._childIds.get(o),c=!!s&&s.length>0,l=c&&this._expanded.has(o);e.push({record:a,depth:n,hasChildren:c,expanded:l,siblingCount:r,posInSet:i+1}),l&&recurse(s,n+1)}};recurse(this._childIds.get(null)??[],0),this._flatRows=e}},rt=c(TreeBody),it=16,at=c(class TreeTable extends ${_treeSpec;_treeBody;_rowReparentWrappers=new Map;constructor(e,t){let n=t.indentPx??it,r=TreeTable.markTreeColumnUnhideable(t);super(e,r,e=>new rt(e,{idField:t.idField,parentField:t.parentField,treeColumn:t.treeColumn,indentPx:n})),this._treeSpec=t,this._treeBody=this.getBody(),this.getAria().setRole(`treegrid`),this._treeBody.setReparentHandlers((e,t)=>this.canReparent(e,t),(e,t)=>this.reparentRow(e,t))}static markTreeColumnUnhideable(e){let t=e.columns.find(t=>t.field===e.treeColumn)?e.columns.map(t=>t.field===e.treeColumn?{...t,unhideable:!0}:t):[...e.columns,{field:e.treeColumn,unhideable:!0}];return{...e,columns:t}}getBody(){return super.getBody()}getTreeSpec(){return this._treeSpec}setExpanded(e,t){return this._treeBody.setExpanded(e,t),this}isExpanded(e){return this._treeBody.isExpanded(e)}expandToDepth(e){return this._treeBody.expandToDepth(e),this}collapseAll(){return this._treeBody.collapseAll(),this}expandAll(){return this._treeBody.expandAll(),this}addRow(e={},t){let n=t?{...e,[this._treeSpec.parentField]:t.get(this._treeSpec.idField)}:e;return super.addRow(n)}getRecordById(e){return this._treeBody.getRecordById(e)}isDirectoryRecord(e){return this._treeBody.isDirectoryRecord(e)}reparentRow(e,t){if(!this.canReparent(e,t))return!1;let n=this._treeSpec.parentField,r=this._treeSpec.idField,a=e.get(n),o=a==null?null:this._treeBody.getRecordById(a)??null;e.set(n,t===null?null:t.get(r)),this.getStore().notifyRecordChanged(e);let s={record:e,newParent:t,oldParent:o};return i.fireEvent(this,`rowreparent`,{detail:s}),!0}canReparent(e,t){return!(!this._treeBody.getRecordById(e.get(this._treeSpec.idField))||e.get(this._treeSpec.parentField)===(t===null?null:t.get(this._treeSpec.idField))||t!==null&&this._treeBody.isAncestorOf(e,t))}addRowReparentListener(e){if(this._rowReparentWrappers.has(e))return this;let wrapper=t=>e(t.detail);return this._rowReparentWrappers.set(e,wrapper),i.addListener(this,`rowreparent`,wrapper),this}removeRowReparentListener(e){let t=this._rowReparentWrappers.get(e);return t?(i.removeListener(this,`rowreparent`,t),this._rowReparentWrappers.delete(e),this):this}});h.register(E,be,xe,Se);var TreeTablePanel=class extends m{_treeTable;_toolbar;_syncBtn;_rejectBtn;_spinner=null;_paginationBar=void 0;constructor(e,t){super(),this.setLayoutManager(new re),this._toolbar=new f,this._toolbar.setLayoutManager(new ee);let n=new S({glyph:`plus`});n.setPreferredSize({width:28,height:28}),n.on(`action`,()=>{this.addRowUnderSelection()}),_.attach(n,`Add row`),this._toolbar.addComponent(n);let r=new S({glyph:`minus`});r.setPreferredSize({width:28,height:28}),r.on(`action`,()=>{this._treeTable.removeSelectedRow()}),_.attach(r,`Remove selected row`),this._toolbar.addComponent(r),this._syncBtn=new S({glyph:`arrows-rotate`}),this._syncBtn.setPreferredSize({width:28,height:28}),this._syncBtn.on(`action`,()=>{this._treeTable.sync()}),_.attach(this._syncBtn,`Sync pending changes`),this._toolbar.addComponent(this._syncBtn),this._rejectBtn=new S({glyph:`ban`}),this._rejectBtn.setPreferredSize({width:28,height:28}),this._rejectBtn.on(`action`,()=>this._treeTable.reject()),_.attach(this._rejectBtn,`Reject pending changes`),this._toolbar.addComponent(this._rejectBtn),this._treeTable=new at(e,t),super.addComponent(this._toolbar,{placement:x.NORTH}),super.addComponent(this._treeTable,{placement:x.CENTER}),e.on(`loadingchange`,e=>{this._spinner||=new b(24),e.loading?this._spinner.showOverlay(this._treeTable):this._spinner.hideOverlay()});let refreshSyncButtons=()=>this.refreshSyncButtons();e.on(`add`,refreshSyncButtons),e.on(`remove`,refreshSyncButtons),e.on(`datachange`,refreshSyncButtons),e.on(`sync`,refreshSyncButtons),e.on(`load`,refreshSyncButtons),this.refreshSyncButtons()}addRowUnderSelection(){let e=this._treeTable.getSelectedRecord();if(e===null)return this._treeTable.addRow();if(this._treeTable.isDirectoryRecord(e))return this._treeTable.addRow({},e);let t=e.get(this._treeTable.getTreeSpec().parentField),n=t==null?void 0:this._treeTable.getRecordById(t);return this._treeTable.addRow({},n)}refreshSyncButtons(){let e=this._treeTable.getStore().hasPendingChanges();this._syncBtn.setEnabled(e),this._rejectBtn.setEnabled(e)}getTreeTable(){return this._treeTable}getToolbar(){return this._toolbar}setExportMenuEnabled(e){return this._treeTable.setExportMenuEnabled(e),this}exportCSV(e){this._treeTable.exportCSV(e)}exportJSON(e){this._treeTable.exportJSON(e)}setPaginationBar(e){return this._paginationBar&&(this.removeComponent(this._paginationBar),this._paginationBar.dispose()),this._paginationBar=e,super.addComponent(e,{placement:x.SOUTH}),this}getPaginationBar(){return this._paginationBar}},ot=c(TreeTablePanel),LinkCellRenderer=class extends CellRenderer{_text;_value=null;constructor(e){super(),this._text=new ue(``,{interactive:!1,foregroundColor:e?.color}),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getText(){return this._text}getValue(){return this._value}setValue(e){this._value=e??null,this._text.setText(this._value===null?``:String(this._value))}},st=c(LinkCellRenderer);export{G as Body,Te as BooleanCell,D as BooleanEditor,Cell,CellEditor,CellEditorPool,CellRenderer,Y as Column,z as ComboCell,W as ComboEditor,P as ComboRenderer,De as DateCell,Ve as DateEditor,A as DateRenderer,L as DateTimeCell,U as DateTimeEditor,M as DateTimeRenderer,I as DefaultCell,F as DynamicCell,J as FooterRow,R as GlyphCell,N as GlyphRenderer,Le as HeaderCell,st as LinkCellRenderer,Ee as NumberCell,Be as NumberEditor,k as NumberRenderer,Re as ParentHeaderCell,V as Row,we as StringCell,ze as StringEditor,O as StringRenderer,$ as Table,X as TableExporter,q as TableHeader,nt as TablePanel,Oe as TimeCell,H as TimeEditor,j as TimeRenderer,rt as TreeBody,B as TreeCellRenderer,at as TreeTable,ot as TreeTablePanel};
|
|
3
|
+
`)?`"`+t.replace(/"/g,`""`)+`"`:t}static download(t,n,r){let i=new Blob([t],{type:r}),a=URL.createObjectURL(i),o=e.sink.createElement(`a`);e.sink.apply(o,{setAttr:{href:a,download:n}}),e.sink.appendChild(e.source.getBody(),o),e.sink.click(o),e.sink.removeChild(e.source.getBody(),o),e.sink.release(o),URL.revokeObjectURL(a)}},Ge=new se([{name:`field`,type:`string`,order:0},{name:`value`,type:`auto`,order:1},{name:`filler`,type:`string`,order:2}]),Ke=30,qe=4,Je=8,Ye=8,Xe=100,Ze=21,Z=6,Qe=400,$e=50,Q=3,et=60,tt=new Date(2e3,11,31,23,59,59),nt=.5,Table=class extends f{_store;_spec;_resolvedColumns=[];_hiddenColumns=new Set;_columnContextMenu=new ie;_headerVisible;_header;_body;_bodyVisible;_footer;_footerVisible;_columnWidths=[];_dragEdgeIndex=null;_dragLastClientX=0;_columnWidthTarget=0;_savedColumnWidths=new Map;_columnConfigs=new Map;_exportMenuEnabled=!1;_listeners=new p;_displayMode=`normal`;_rotatedRecord=null;_rotatedStore=null;_rotatedColumns=[];_rotatedConfigs=new Map;_rotatedFieldByName=new Map;_sourceRefresh=null;_suppressSelectionForward=!1;_autoWidthsSampled=!1;_widthRefs=null;_sampledCandidates=new Map;constructor(e,t,n){super({tag:`table`}),this.setLayoutManager(new Ce),this.getAria().setRole(`grid`),this.setBorder({border:`1px solid var(--ts-ui-border-color, black)`}),this.setInsets(new r(0,0,0,0)),this.setOverflow(`hidden`),this.setMinSize({width:100,height:100}),this._store=e,this._spec=t,this._headerVisible=!0,this._bodyVisible=!0,this._footerVisible=!1,this.bindSourceStore(e),this._resolvedColumns=Y.resolve(e.model.getFields(),t),this.initHiddenFromSpec(),this._header=new q(e.model,e),this._header.on(`columnresizestart`,(e,t)=>this.onColumnResizeStart(e,t)),this._header.on(`columnresize`,(e,t)=>this.onColumnResize(e,t)),this._header.on(`columncontextmenu`,(e,t,n)=>this.showColumnMenu(t,n)),this._header.setWillChange(`transform`),this.addComponent(this._header),this._header.setColumns(this._resolvedColumns),this._body=n?n(e):new G(e),this._body.setHeader(this._header),this.addComponent(this._body),this._body.setColumns(this._resolvedColumns),this._footer=new J,this.addComponent(this._footer);let i=this.getEffectiveHiddenSet();i.size>0&&(this._header.setHiddenColumns(i),this._body.setHiddenColumns(i)),t&&(this._columnConfigs=this.buildColumnConfigs(t),this._body.setColumnConfigs(this._columnConfigs)),this._body.setRowReadOnly(t?.rowReadOnly??null),this.getAria().setColCount(this.getColumns().length),this._body.on(`horizontalscroll`,e=>{this._header.setScrollX(e)}),this._body.on(`selection`,e=>{this._suppressSelectionForward||this._displayMode===`rotated`||this.emit(`selection`,e)}),this._body.on(`cellclick`,e=>this.emit(`cellclick`,e))}on(e,t){return this._listeners.add(e,t),this}off(e,t){return this._listeners.remove(e,t),this}emit(e,t){this._listeners.fire(e,t)}getColumns(){return this._displayMode===`rotated`?this._rotatedColumns:this.getSourceColumns()}getSourceColumns(){let e=this.getEffectiveHiddenSet();return this._resolvedColumns.filter(t=>!e.has(t.getField().getName()))}getDisplayMode(){return this._displayMode}setDisplayMode(e){if(e===this._displayMode)return this;if(this._displayMode=e,e===`rotated`){this._rotatedRecord=this._body.getSelectedRecord()??this._store.getRecords()[0]??null;let e=this.ensureRotatedStore();this.rebuildRotatedStore(),this.bindView(e,this._rotatedColumns,this._rotatedConfigs,new Set,()=>!0),this.emit(`selection`,this._rotatedRecord?[this._rotatedRecord]:[])}else this.bindView(this._store,this.getSourceColumns(),this._columnConfigs,this.getEffectiveHiddenSet(),this._spec?.rowReadOnly??null),this._body.selectRecord(this._rotatedRecord);return this}getStore(){return this._store}getModel(){return this._store.model}setStore(e){return this.setDisplayMode(`normal`),this._header.setStore(e),this.unbindSourceStore(this._store),this._store=e,this._columnWidths=[],this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._autoWidthsSampled=!1,this._widthRefs=null,this._sampledCandidates=new Map,this._resolvedColumns=Y.resolve(e.model.getFields(),this._spec),this.bindSourceStore(e),this._body.setStore(e),this._header.setModel(e.model),this._header.setColumns(this._resolvedColumns),this._body.setColumns(this._resolvedColumns),this._header.setHiddenColumns(this.getEffectiveHiddenSet()),this.getAria().setColCount(this.getColumns().length),this.doLayout(),this}getColumnWidths(){return this._columnWidths}setColumnWidths(e){this._columnWidths=e;let t=this.getColumns();return e.forEach((e,n)=>{let r=t[n];r&&this._savedColumnWidths.set(r.getField().getName(),e)}),this}getAvailableColumnWidth(){let t=this.getInnerSize();return t?t.width-e.source.getScrollBarWidth():0}getColumnWidthTarget(){return this._columnWidthTarget}setColumnVisible(e,t){if(this._displayMode===`rotated`)return this;if(!t){let t=this._resolvedColumns.find(t=>t.getField().getName()===e);if(t&&t.isUnhideable())return this}t?this._hiddenColumns.delete(e):this._hiddenColumns.add(e),this._widthRefs=null;let n=this.getColumns(),r=null,i=n.map((e,t)=>{let n=this._savedColumnWidths.get(e.getField().getName());return n===void 0?(r??=this.getIntrinsicColumnWidths(),r[t]??this.flexColumnWidth(e)):n}),a=this._columnWidths.reduce((e,t)=>e+t,0),o=i.reduce((e,t)=>e+t,0);this._columnWidths=o>a+.5&&a>0?this.trimToTarget(n,i,a,e):i,this._columnWidthTarget>0&&(this._columnWidthTarget=this._columnWidths.reduce((e,t)=>e+t,0));let s=this.getEffectiveHiddenSet();return this._header.setHiddenColumns(s),this._body.setHiddenColumns(s),this.getAria().setColCount(this.getColumns().length),this.doLayout(),this}getHeader(){return this._header}isHeaderVisible(){return this._headerVisible}getBody(){return this._body}isBodyVisible(){return this._bodyVisible}getFooter(){return this._footer}isFooterVisible(){return this._footerVisible}addRow(e={}){let[t]=this._store.add(e);return this._displayMode===`rotated`?(this.selectRecord(t),t):(this._body.scrollToRecord(t),this._body.selectRecord(t),t)}removeSelectedRow(){if(this._displayMode===`rotated`)return this._rotatedRecord&&this._store.remove(this._rotatedRecord),this;let e=this._body.getSelectedRecord();return e?(this._body.selectRecord(null),this._store.remove(e),this):this}selectRecord(e){return this._displayMode===`rotated`?e===this._rotatedRecord?this:(this._rotatedRecord=e,this.rebuildRotatedStore(),this.emit(`selection`,e?[e]:[]),this):(e&&this._body.scrollToRecord(e),this._body.selectRecord(e),this)}async sync(){return this._store.sync()}reject(){this._store.reject()}getSelectedRecord(){return this._displayMode===`rotated`?this._rotatedRecord:this._body.getSelectedRecord()}getSelectedRecords(){return this._displayMode===`rotated`?this._rotatedRecord?[this._rotatedRecord]:[]:this._body.getSelectedRecords()}addComponent(e,t){return e instanceof q?this._header=e:e instanceof G?this._body=e:e instanceof J&&(this._footer=e),super.addComponent(e,t),this}trimToTarget(e,t,n,r){let i=[...t],isFixedType=e=>{let t=e.getField().getType();return t===`boolean`||t===`number`||t===`date`},trim=(t,n)=>{let r=t.reduce((e,t)=>e+t.room,0);if(r<=0)return n;let a=Math.min(n,r);for(let{i:n,room:o}of t)i[n]=Math.max(i[n]-o/r*a,this.getColumnMinWidth(e[n]));return n-a},pool=t=>e.map((e,n)=>({i:n,room:isFixedType(e)===t&&e.getField().getName()!==r&&this._savedColumnWidths.has(e.getField().getName())?i[n]-this.getColumnMinWidth(e):0})).filter(e=>e.room>.5),a=i.reduce((e,t)=>e+t,0)-n;return a=trim(pool(!1),a),a>.5&&trim(pool(!0),a),i}buildColumnConfigs(e){let t=new Map;for(let n of e.columns)t.set(n.field,n);return t}initHiddenFromSpec(){for(let e of this._resolvedColumns)e.isInitiallyHidden()&&!e.isUnhideable()&&this._hiddenColumns.add(e.getField().getName())}getEffectiveHiddenSet(){let e=new Set(this._resolvedColumns.map(e=>e.getField().getName())),t=new Set(this._hiddenColumns);for(let n of this._store.model.getFields())e.has(n.getName())||t.add(n.getName());return t}bindSourceStore(e){let refresh=()=>this.onSourceStoreChange();this._sourceRefresh=refresh,e.on(`load`,refresh),e.on(`add`,refresh),e.on(`remove`,refresh),e.on(`datachange`,refresh)}unbindSourceStore(e){this._sourceRefresh&&[`load`,`add`,`remove`,`datachange`].forEach(t=>e.off(t,this._sourceRefresh))}onSourceStoreChange(){if(this.maybeResampleColumnWidths(),this._displayMode!==`rotated`)return;let e=this._store.getRecords();if(!(this._rotatedRecord!==null&&e.includes(this._rotatedRecord))){let t=this._rotatedRecord;this._rotatedRecord=e[0]??null,this._rotatedRecord!==t&&this.emit(`selection`,this._rotatedRecord?[this._rotatedRecord]:[])}this.rebuildRotatedStore()}ensureRotatedStore(){if(this._rotatedStore)return this._rotatedStore;let e={columns:[{field:`field`,minWidth:80,maxWidth:200,unhideable:!0},{field:`value`,minWidth:120,maxWidth:360,unhideable:!0,cellType:e=>this.rotatedCellType(e),cellValues:e=>this.rotatedCellValues(e)},{field:`filler`,headerText:``,minWidth:0,unhideable:!0}],rowReadOnly:()=>!0};return this._rotatedStore=new ce(Ge,[]),this._rotatedColumns=Y.resolve(Ge.getFields(),e),this._rotatedConfigs=this.buildColumnConfigs(e),this._rotatedStore}rebuildRotatedStore(){let e=this.ensureRotatedStore(),t=this.getSourceColumns().map(e=>e.getField()),n=this._rotatedRecord;this._rotatedFieldByName=new Map(t.map(e=>[e.getName(),e])),e.loadData(n?t.map(e=>({field:e.getName(),value:n.get(e.getName())})):[])}rotatedCellType(e){let t=this._rotatedFieldByName.get(e.get(`field`));if(!t)return null;let n=this._columnConfigs.get(t.getName())?.values;return n&&n.length>0?`combo`:t.getType()}rotatedCellValues(e){let t=this._rotatedFieldByName.get(e.get(`field`));return t?this._columnConfigs.get(t.getName())?.values:void 0}bindView(e,t,n,r,i){this._suppressSelectionForward=!0,this._header.setStore(e),this._header.setModel(e.model),this._header.setColumns(t),this._header.setHiddenColumns(r),this._body.selectRecord(null),this._body.setStore(e),this._body.setColumnConfigs(n),this._body.setColumns(t),this._body.setHiddenColumns(r),this._body.setRowReadOnly(i),this._body.setStore(e),this._suppressSelectionForward=!1,this._columnWidths=[],this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._widthRefs=null,this.getAria().setColCount(this.getColumns().length),this.doLayout()}destructor(){this._columnContextMenu.dispose(),super.destructor()}showColumnMenu(e,t){if(this._displayMode===`rotated`){if(!this._exportMenuEnabled)return;this._columnContextMenu.show(e,t,[{text:`Export as CSV`,action:()=>this.exportCSV()},{text:`Export as JSON`,action:()=>this.exportJSON()}]);return}let n=this._resolvedColumns.slice().sort((e,t)=>e.getField().getOrder()-t.getField().getOrder()),r=[],i;n.forEach(e=>{let t=e.getField().getName(),n=!this._hiddenColumns.has(t),a=e.getGroup();a!==null&&a!==i&&r.push({text:a,enabled:!1});let o=a===null?``:`\xA0\xA0\xA0\xA0`,s=!e.isUnhideable();r.push({text:o+(n?`✓ `:` `)+t,action:()=>this.setColumnVisible(t,!n),enabled:s}),i=a}),r.push({separator:!0},{text:`Reset columns`,action:()=>this.resetColumns()}),this._exportMenuEnabled&&r.push({separator:!0},{text:`Export as CSV`,action:()=>this.exportCSV()},{text:`Export as JSON`,action:()=>this.exportJSON()}),this._columnContextMenu.show(e,t,r)}setExportMenuEnabled(e){return this._exportMenuEnabled=e,this}exportCSV(e){let t=this.getExportColumns(e?.includeHidden??!1),n=this._store.getRecords();X.exportCSV(t,n,this._columnConfigs,e)}exportJSON(e){let t=this.getExportColumns(e?.includeHidden??!1),n=this._store.getRecords();X.exportJSON(t,n,this._columnConfigs,e)}getExportColumns(e){return e?this._resolvedColumns.slice():this.getSourceColumns()}onColumnResizeStart(e,t){e<0||e>=this._columnWidths.length||(this._dragEdgeIndex=e,this._dragLastClientX=t)}onColumnResize(e,t){if(this._dragEdgeIndex===null||e!==this._dragEdgeIndex)return;let n=this._columnWidths,r=this.getColumns(),i=r.map(e=>e.getMinWidth()??Ke),a=r.map(e=>e.getMaxWidth()??1/0),o=[],s=[];for(let t=e;t>=0;t--)o.push(t);for(let t=e+1;t<n.length;t++)s.push(t);let c=t-this._dragLastClientX,l=c>=0?1:-1,u=this.getAvailableColumnWidth(),d=n.reduce((e,t)=>e+t,0),f=Math.max(0,d-u),p=l>0?Math.min(c,w(o,n,1,i,a)):Math.min(-c,w(o,n,-1,i,a),w(s,n,1,i,a)+f);if(p<=1e-6)return;let m=l>0?f>nt?0:p:p-Math.min(p,f),h=n.slice();ae(o,n,p,l,i,a,h),ae(s,n,m,-l,i,a,h),this._dragLastClientX+=l*p,this._columnWidths=h;let g=h.reduce((e,t)=>e+t,0);this._columnWidthTarget=g>u+nt?g:0,this.scheduleLayout()}resetColumns(){this._hiddenColumns=new Set,this.initHiddenFromSpec(),this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._widthRefs=null;let e=this.getColumns(),t=this.getIntrinsicColumnWidths();this._columnWidths=e.map((e,n)=>t[n]??this.flexColumnWidth(e));let n=this.getEffectiveHiddenSet();this._header.setHiddenColumns(n),this._body.setHiddenColumns(n),this.doLayout()}isAutoSizeColumns(){return(this._spec?.autoSizeColumns??!1)&&this._displayMode!==`rotated`}getColumnMinWidth(e){return e.getMinWidth()??this.columnWidthPolicy(e,0,null).min}getIntrinsicColumnWidths(){let e=this.getColumns(),t=this.measureHeaders(e),n=this.measureContent(e);return e.map((e,r)=>{let i=this.columnWidthPolicy(e,t[r],n[r]),a=e.getWidth()??i.preferred;return a===null?null:this.clampColumnWidth(a,e,i)})}clampColumnWidth(e,t,r){return n.clamp(e,t.getMinWidth()??r.min,t.getMaxWidth()??Qe)}flexColumnWidth(e){let t=this.measureHeaders([e])[0],n=this.columnWidthPolicy(e,t,null);return this.clampColumnWidth(Math.max(Xe,t),e,n)}measureHeaders(e){let t=e.map(e=>e.getHeaderText()??e.getField().getName());return n.measureTextWidths(t,{fontSize:`var(--ts-ui-table-header-font-size, var(--ts-ui-font-size))`,fontWeight:`bold`}).map(e=>e+Ze)}measureContent(e){this.collectCandidates(e);let t=e.map(e=>this.resolveContentCandidates(e)),r=[],i=[];t.forEach((e,t)=>{e?.forEach(e=>{i.push(t),r.push(e)})});let a=n.measureTextWidths(r),o=e.map(()=>null);return a.forEach((e,t)=>{let n=i[t];o[n]=Math.max(o[n]??0,e)}),o}resolveContentCandidates(e){let t=e.getField().getType();if(t!==`string`&&t!==`auto`||!this.isAutoSizeColumns())return null;let n=this._sampledCandidates.get(e.getField().getName());if(n&&n.length>0)return n;let r=this._columnConfigs.get(e.getField().getName());if(r?.values&&r.values.length>0)return normalizeComboOptions(r.values).map(e=>e.label).sort((e,t)=>t.length-e.length).slice(0,Q);let i=e.getMaxContentLength();return i===void 0?null:[`0`.repeat(Math.min(i,et))]}collectCandidates(e){let t=e.map(e=>this.samplesRecordText(e)),n=Math.min($e,this._store.getCount()),r=new Map;for(let i=0;i<n;i++){let n=this._store.getAt(i);e.forEach((e,i)=>{if(!t[i])return;let a=e.getField().getName(),o=n.get(a),s=String(X.formatValue(e,o,this._columnConfigs)??``),c=r.get(a)??[];this.keepLongest(c,s),r.set(a,c)})}n>0&&(this._autoWidthsSampled=!0),this._sampledCandidates=r}keepLongest(e,t){e.includes(t)||(e.push(t),e.sort((e,t)=>t.length-e.length),e.length>Q&&(e.length=Q))}samplesRecordText(e){let t=this._columnConfigs.get(e.getField().getName());if(t?.renderer||t?.values&&t.values.length>0)return!1;let n=e.getField().getType();return n===`number`||(n===`string`||n===`auto`)&&this.isAutoSizeColumns()}sampledDigits(e){let t=this._sampledCandidates.get(e.getField().getName());return!t||t.length===0?null:Math.max(...t.map(e=>e.length))}showsSeconds(e){return this._columnConfigs.get(e.getField().getName())?.showSeconds??!1}columnWidthPolicy(e,t,n){let r=this.ensureWidthReferences(),i=e.getField().getType();switch(i){case`boolean`:return{min:22,preferred:Math.max(22,t)};case`glyph`:return{min:26,preferred:Math.max(26,t)};case`date`:case`time`:case`datetime`:{let n=`${i}:${this.showsSeconds(e)}`,a=(r.datePx.get(n)??0)+Z;return{min:a,preferred:Math.max(a,t)}}case`number`:{let n=r.digitPx*qe+Z,i=e.getMaxContentLength()??this.sampledDigits(e)??Je;return{min:n,preferred:Math.max(n,r.digitPx*i+Z,t)}}default:{let e=Math.max(Ke,r.digitPx*Ye+Z);return n===null?{min:e,preferred:null}:{min:e,preferred:Math.max(e,n,t)}}}}ensureWidthReferences(){if(this._widthRefs)return this._widthRefs;let e=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`],t=this.dateReferenceKeys(),r=n.measureTextWidths([...e,...t.map(e=>e.text)]);return this._widthRefs={digitPx:Math.max(...r.slice(0,e.length)),datePx:new Map(t.map((t,n)=>[t.key,r[e.length+n]]))},this._widthRefs}dateReferenceKeys(){let e=new Map;for(let t of this.getColumns()){let n=t.getField().getType();if(n!==`date`&&n!==`time`&&n!==`datetime`)continue;let r=`${n}:${this.showsSeconds(t)}`;e.has(r)||e.set(r,String(X.formatValue(t,tt,this._columnConfigs)??``))}return Array.from(e,([e,t])=>({key:e,text:t}))}maybeResampleColumnWidths(){!this.isAutoSizeColumns()||this._autoWidthsSampled||this._store.getCount()===0||(this._columnWidths=[],this._savedColumnWidths=new Map,this._columnWidthTarget=0,this._widthRefs=null,this.doLayout())}},$=c(Table);h.register(xe,Se,ye,E);var TablePanel=class extends m{_table;_toolbar;_syncBtn;_rejectBtn;_spinner=null;_paginationBar=void 0;constructor(e,t){super(),this.setLayoutManager(new ne),this._toolbar=new f,this._toolbar.setLayoutManager(new b);let n=new S({glyph:`plus`});n.setPreferredSize({width:28,height:28}),n.on(`action`,()=>{this._table.addRow()}),_.attach(n,`Add row`),this._toolbar.addComponent(n);let r=new S({glyph:`minus`});r.setPreferredSize({width:28,height:28}),r.on(`action`,()=>{this._table.removeSelectedRow()}),_.attach(r,`Remove selected row`),this._toolbar.addComponent(r),this._syncBtn=new S({glyph:`arrows-rotate`}),this._syncBtn.setPreferredSize({width:28,height:28}),this._syncBtn.on(`action`,()=>{this._table.sync()}),_.attach(this._syncBtn,`Sync pending changes`),this._toolbar.addComponent(this._syncBtn),this._rejectBtn=new S({glyph:`ban`}),this._rejectBtn.setPreferredSize({width:28,height:28}),this._rejectBtn.on(`action`,()=>this._table.reject()),_.attach(this._rejectBtn,`Reject pending changes`),this._toolbar.addComponent(this._rejectBtn),this._table=new $(e,t),super.addComponent(this._toolbar,{placement:x.NORTH}),super.addComponent(this._table,{placement:x.CENTER}),e.on(`loadingchange`,e=>{this._spinner||=new re(24),e.loading?this._spinner.showOverlay(this._table):this._spinner.hideOverlay()});let refreshSyncButtons=()=>this.refreshSyncButtons();e.on(`add`,refreshSyncButtons),e.on(`remove`,refreshSyncButtons),e.on(`datachange`,refreshSyncButtons),e.on(`sync`,refreshSyncButtons),e.on(`load`,refreshSyncButtons),this.refreshSyncButtons()}refreshSyncButtons(){let e=this._table.getStore().hasPendingChanges();this._syncBtn.setEnabled(e),this._rejectBtn.setEnabled(e)}getTable(){return this._table}getToolbar(){return this._toolbar}setExportMenuEnabled(e){return this._table.setExportMenuEnabled(e),this}exportCSV(e){this._table.exportCSV(e)}exportJSON(e){this._table.exportJSON(e)}setPaginationBar(e){return this._paginationBar&&(this.removeComponent(this._paginationBar),this._paginationBar.dispose()),this._paginationBar=e,super.addComponent(e,{placement:x.SOUTH}),this}getPaginationBar(){return this._paginationBar}},rt=c(TablePanel),TreeBody=class extends We{_byId=new Map;_childIds=new Map;_expanded=new Set;_flatRows=[];_rowDnDTeardowns=new Map;_emptyAreaDropTeardown=null;_reparentHandler=null;_reparentValidator=null;constructor(e,t){super(e),this._idField=t.idField,this._parentField=t.parentField,this._treeColumn=t.treeColumn,this._indentPx=t.indentPx,this.rebuildIndex(),this.flatten()}getIdField(){return this._idField}getParentField(){return this._parentField}getTreeColumn(){return this._treeColumn}getFlatRecords(){return this._flatRows}getRecordById(e){return this._byId.get(e)}getChildrenOf(e){return this._childIds.get(e)??[]}isDirectoryRecord(e){return this.getChildrenOf(e.get(this._idField)).length>0}isAncestorOf(e,t){if(e===t)return!0;let n=e.get(this._idField),r=t,i=new Set;for(;r;){let e=r.get(this._parentField);if(e==null)return!1;if(e===n)return!0;if(i.has(e))return!1;i.add(e),r=this._byId.get(e)}return!1}isExpanded(e){let t=e.get(this._idField),n=this._childIds.get(t);return!!n&&n.length>0&&this._expanded.has(t)}setExpanded(e,t){let n=e.get(this._idField),r=this._childIds.get(n);if(!r||r.length===0)return this;if(t){if(this._expanded.has(n))return this;this._expanded.add(n)}else{if(!this._expanded.has(n))return this;this._expanded.delete(n)}return this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this}expandToDepth(e){this._expanded.clear();let recurse=(t,n)=>{if(!(n>e))for(let e of t){let t=e.get(this._idField),r=this._childIds.get(t);r&&r.length>0&&(this._expanded.add(t),recurse(r,n+1))}};return recurse(this._childIds.get(null)??[],0),this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this}collapseAll(){return this._expanded.size===0?this:(this._expanded.clear(),this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this)}expandAll(){let e=new Set;for(let[t,n]of this._childIds)t!==null&&n.length>0&&e.add(t);let t=this._childIds.get(null)??[];for(let n of t){let t=n.get(this._idField),r=this._childIds.get(t);r&&r.length>0&&e.add(t)}return this._expanded=e,this.flatten(),this.invalidateRowBindings(),this.renderWindow(),this}getToggleElement(e){let t=e.getTreeCell();if(!t)return null;let n=t.getRenderer();if(!(n instanceof B))return null;let r=n.getToggle();return r?r.getElement()??null:null}init(e){return super.init(e),this.ensureEmptyAreaDropTarget(),this}onStoreChange(){this.rebuildIndex(),this.flatten(),super.onStoreChange()}getVisibleRecords(){return this._flatRows.map(e=>e.record)}createRow(){return new V(this.getStore().model,void 0,this.getHiddenColumns(),this.getColumnConfigs(),e=>this.getStore().notifyRecordChanged(e),this._treeColumn)}getTreeFieldName(){return this._treeColumn}computeRowAria(e,t){super.computeRowAria(e,t);let n=this._flatRows[t];n&&(e.getAria().setLevel(n.depth+1),e.getAria().setExpanded(n.hasChildren?n.expanded:null),e.getAria().setSetSize(n.siblingCount),e.getAria().setPosInSet(n.posInSet))}afterRowBound(e,t,n){let r=e.getTreeCell(),i=this._flatRows[t];if(r&&i&&r.getRenderer().setTreeState(i.depth,i.hasChildren,i.expanded),this._reparentHandler!==null){if(!i){this.teardownRowDnD(e);return}(n||!this._rowDnDTeardowns.has(e))&&this.installRowDnD(e,i.record)}}installRowDnD(e,t){this.teardownRowDnD(e);let n=C.makeDragSource(e,{dragData:{recordId:t.get(this._idField)}}),dropTargetForRow=e=>this.resolveDragged(e)?this.resolveDropParentForRow(t):null,r=C.makeDropTarget(e,{accepts:e=>{let t=this.resolveDragged(e);if(!t)return!1;let n=dropTargetForRow(e);return this._reparentValidator?.(t,n)??!1},onDrop:e=>{let t=this.resolveDragged(e);if(!t)return!1;let n=dropTargetForRow(e);return this._reparentHandler?.(t,n)??!1}});this._rowDnDTeardowns.set(e,()=>{n(),r()})}resolveDragged(e){let t=e.dragData.recordId;return this._byId.get(t)}resolveDropParentForRow(e){if(this.isDirectoryRecord(e))return e;let t=e.get(this._parentField);return t==null?null:this._byId.get(t)??null}teardownRowDnD(e){let t=this._rowDnDTeardowns.get(e);t&&(t(),this._rowDnDTeardowns.delete(e))}setReparentHandlers(e,t){return this._reparentValidator=e,this._reparentHandler=t,this.getElement()&&this.ensureEmptyAreaDropTarget(),this}ensureEmptyAreaDropTarget(){this._emptyAreaDropTeardown===null&&this._reparentHandler!==null&&(this._emptyAreaDropTeardown=C.makeDropTarget(this,{accepts:e=>{let t=this.resolveDragged(e);return t?this._reparentValidator?.(t,null)??!1:!1},onDrop:e=>{let t=this.resolveDragged(e);return t?this._reparentHandler?.(t,null)??!1:!1}}))}onSubtreeClick(t){let n=t.target===null?null:e.source.intern(t.target);for(let t of this.getRowPool()){let r=this.getToggleElement(t);if(r&&n!==null&&(n===r||e.source.contains(r,n))){let e=t.getData();e&&this.setExpanded(e,!this.isExpanded(e));return}}super.onSubtreeClick(t)}onKeyDown(e){if(e.key!==`ArrowRight`&&e.key!==`ArrowLeft`){super.onKeyDown(e);return}let t=this.getSelectedRecord();if(!t){super.onKeyDown(e);return}let n=this._flatRows.findIndex(e=>e.record===t);if(n<0){e.preventDefault();return}e.preventDefault();let r=this._flatRows[n];e.key===`ArrowRight`?this.handleArrowRight(r,n):this.handleArrowLeft(r,n)}handleArrowRight(e,t){if(!e.hasChildren)return;if(!e.expanded){this.setExpanded(e.record,!0);return}let n=this._flatRows[t+1];n&&n.depth===e.depth+1&&this.moveFocusTo(n.record)}handleArrowLeft(e,t){if(e.hasChildren&&e.expanded){this.setExpanded(e.record,!1);return}if(e.depth!==0){for(let n=t-1;n>=0;n--)if(this._flatRows[n].depth===e.depth-1){this.moveFocusTo(this._flatRows[n].record);return}}}moveFocusTo(e){this.selectRecord(e),this.scrollRecordIntoView(e),this.renderWindow(),this._updateActiveDescendant(),this._updateFocusStyle()}rebuildIndex(){this._byId.clear(),this._childIds.clear();let e=this.getStore().getRecords();for(let t of e){let e=t.get(this._idField);this._byId.set(e,t)}for(let t of e){let e=t.get(this._parentField),n=e!=null&&this._byId.has(e)?e:null,r=this._childIds.get(n);r?r.push(t):this._childIds.set(n,[t])}}flatten(){let e=[],recurse=(t,n)=>{let r=t.length;for(let i=0;i<t.length;i++){let a=t[i],o=a.get(this._idField),s=this._childIds.get(o),c=!!s&&s.length>0,l=c&&this._expanded.has(o);e.push({record:a,depth:n,hasChildren:c,expanded:l,siblingCount:r,posInSet:i+1}),l&&recurse(s,n+1)}};recurse(this._childIds.get(null)??[],0),this._flatRows=e}},it=c(TreeBody),at=16,ot=c(class TreeTable extends ${_treeSpec;_treeBody;_rowReparentWrappers=new Map;constructor(e,t){let n=t.indentPx??at,r=TreeTable.markTreeColumnUnhideable(t);super(e,r,e=>new it(e,{idField:t.idField,parentField:t.parentField,treeColumn:t.treeColumn,indentPx:n})),this._treeSpec=t,this._treeBody=this.getBody(),this.getAria().setRole(`treegrid`),this._treeBody.setReparentHandlers((e,t)=>this.canReparent(e,t),(e,t)=>this.reparentRow(e,t))}static markTreeColumnUnhideable(e){let t=e.columns.find(t=>t.field===e.treeColumn)?e.columns.map(t=>t.field===e.treeColumn?{...t,unhideable:!0}:t):[...e.columns,{field:e.treeColumn,unhideable:!0}];return{...e,columns:t}}getBody(){return super.getBody()}getTreeSpec(){return this._treeSpec}setExpanded(e,t){return this._treeBody.setExpanded(e,t),this}isExpanded(e){return this._treeBody.isExpanded(e)}expandToDepth(e){return this._treeBody.expandToDepth(e),this}collapseAll(){return this._treeBody.collapseAll(),this}expandAll(){return this._treeBody.expandAll(),this}addRow(e={},t){let n=t?{...e,[this._treeSpec.parentField]:t.get(this._treeSpec.idField)}:e;return super.addRow(n)}getRecordById(e){return this._treeBody.getRecordById(e)}isDirectoryRecord(e){return this._treeBody.isDirectoryRecord(e)}reparentRow(e,t){if(!this.canReparent(e,t))return!1;let n=this._treeSpec.parentField,r=this._treeSpec.idField,a=e.get(n),o=a==null?null:this._treeBody.getRecordById(a)??null;e.set(n,t===null?null:t.get(r)),this.getStore().notifyRecordChanged(e);let s={record:e,newParent:t,oldParent:o};return i.fireEvent(this,`rowreparent`,{detail:s}),!0}canReparent(e,t){return!(!this._treeBody.getRecordById(e.get(this._treeSpec.idField))||e.get(this._treeSpec.parentField)===(t===null?null:t.get(this._treeSpec.idField))||t!==null&&this._treeBody.isAncestorOf(e,t))}addRowReparentListener(e){if(this._rowReparentWrappers.has(e))return this;let wrapper=t=>e(t.detail);return this._rowReparentWrappers.set(e,wrapper),i.addListener(this,`rowreparent`,wrapper),this}removeRowReparentListener(e){let t=this._rowReparentWrappers.get(e);return t?(i.removeListener(this,`rowreparent`,t),this._rowReparentWrappers.delete(e),this):this}});h.register(xe,Se,ye,E);var TreeTablePanel=class extends m{_treeTable;_toolbar;_syncBtn;_rejectBtn;_spinner=null;_paginationBar=void 0;constructor(e,t){super(),this.setLayoutManager(new ne),this._toolbar=new f,this._toolbar.setLayoutManager(new b);let n=new S({glyph:`plus`});n.setPreferredSize({width:28,height:28}),n.on(`action`,()=>{this.addRowUnderSelection()}),_.attach(n,`Add row`),this._toolbar.addComponent(n);let r=new S({glyph:`minus`});r.setPreferredSize({width:28,height:28}),r.on(`action`,()=>{this._treeTable.removeSelectedRow()}),_.attach(r,`Remove selected row`),this._toolbar.addComponent(r),this._syncBtn=new S({glyph:`arrows-rotate`}),this._syncBtn.setPreferredSize({width:28,height:28}),this._syncBtn.on(`action`,()=>{this._treeTable.sync()}),_.attach(this._syncBtn,`Sync pending changes`),this._toolbar.addComponent(this._syncBtn),this._rejectBtn=new S({glyph:`ban`}),this._rejectBtn.setPreferredSize({width:28,height:28}),this._rejectBtn.on(`action`,()=>this._treeTable.reject()),_.attach(this._rejectBtn,`Reject pending changes`),this._toolbar.addComponent(this._rejectBtn),this._treeTable=new ot(e,t),super.addComponent(this._toolbar,{placement:x.NORTH}),super.addComponent(this._treeTable,{placement:x.CENTER}),e.on(`loadingchange`,e=>{this._spinner||=new re(24),e.loading?this._spinner.showOverlay(this._treeTable):this._spinner.hideOverlay()});let refreshSyncButtons=()=>this.refreshSyncButtons();e.on(`add`,refreshSyncButtons),e.on(`remove`,refreshSyncButtons),e.on(`datachange`,refreshSyncButtons),e.on(`sync`,refreshSyncButtons),e.on(`load`,refreshSyncButtons),this.refreshSyncButtons()}addRowUnderSelection(){let e=this._treeTable.getSelectedRecord();if(e===null)return this._treeTable.addRow();if(this._treeTable.isDirectoryRecord(e))return this._treeTable.addRow({},e);let t=e.get(this._treeTable.getTreeSpec().parentField),n=t==null?void 0:this._treeTable.getRecordById(t);return this._treeTable.addRow({},n)}refreshSyncButtons(){let e=this._treeTable.getStore().hasPendingChanges();this._syncBtn.setEnabled(e),this._rejectBtn.setEnabled(e)}getTreeTable(){return this._treeTable}getToolbar(){return this._toolbar}setExportMenuEnabled(e){return this._treeTable.setExportMenuEnabled(e),this}exportCSV(e){this._treeTable.exportCSV(e)}exportJSON(e){this._treeTable.exportJSON(e)}setPaginationBar(e){return this._paginationBar&&(this.removeComponent(this._paginationBar),this._paginationBar.dispose()),this._paginationBar=e,super.addComponent(e,{placement:x.SOUTH}),this}getPaginationBar(){return this._paginationBar}},st=c(TreeTablePanel),LinkCellRenderer=class extends CellRenderer{_text;_value=null;constructor(e){super(),this._text=new ue(``,{interactive:!1,foregroundColor:e?.color}),this._text.setAutoMeasure(!1),this.addComponent(this._text)}getText(){return this._text}getValue(){return this._value}setValue(e){this._value=e??null,this._text.setText(this._value===null?``:String(this._value))}},ct=c(LinkCellRenderer);export{G as Body,Te as BooleanCell,D as BooleanEditor,Cell,CellEditor,CellEditorPool,CellRenderer,Y as Column,z as ComboCell,W as ComboEditor,P as ComboRenderer,De as DateCell,He as DateEditor,A as DateRenderer,L as DateTimeCell,U as DateTimeEditor,M as DateTimeRenderer,I as DefaultCell,F as DynamicCell,J as FooterRow,R as GlyphCell,N as GlyphRenderer,Re as HeaderCell,ct as LinkCellRenderer,Ee as NumberCell,Ve as NumberEditor,k as NumberRenderer,ze as ParentHeaderCell,V as Row,we as StringCell,Be as StringEditor,O as StringRenderer,$ as Table,X as TableExporter,q as TableHeader,rt as TablePanel,Oe as TimeCell,H as TimeEditor,j as TimeRenderer,it as TreeBody,B as TreeCellRenderer,ot as TreeTable,st as TreeTablePanel};
|
|
4
4
|
//# sourceMappingURL=table.es.js.map
|