@toolbox-web/grid 3.8.1 → 3.8.2

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.
@@ -1,2 +1,2 @@
1
- function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,i,r,n){return`${t(r,n)} ${e}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}var i="editing";function r(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,r=e.rawContentHeight-e.viewportHeight;return i<=0||r<=0?t:t*i/r}function n(t,e){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:e,container:i,viewportEl:n,scrollMapping:o}=t._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(!s||a<=0)return;const d=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const l=Math.max(0,d.top),c=a-l-Math.max(0,d.bottom);if(c<=0)return;const u=t._focusRow*e,h=o?function(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,r=e.rawContentHeight-e.viewportHeight;if(i<=0||r<=0)return t;const n=t*r/i;return n<0?0:n>r?r:n}(s.scrollTop,o):s.scrollTop;if(u<h+l){const t=Math.max(0,u-l);s.scrollTop=o?r(t,o):t}else if(u+e>h+l+c){const t=Math.max(0,u-c+e-l);s.scrollTop=o?r(t,o):t}}(t);const n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=function(t){const e=t._focusRow,i=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(e<i||e>=r)return;const n=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=n?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${t._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:a,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),n&&!e?.forceHorizontalScroll||function(t,e,i,r){const n=t.querySelector(".tbw-scroll-area");if(!n)return;if(r?.forceScrollLeft)return void(n.scrollLeft=0);if(r?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),a=n.getBoundingClientRect(),d=s.left-a.left+n.scrollLeft,l=d+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;d<c?n.scrollLeft=d-o.left:l>u&&(n.scrollLeft=l-n.clientWidth+o.right)}(t,a,d,e),function(t,e,r){if(r&&e.classList.contains(i)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(r){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,d,n)}var o=/{{\s*([^}]+)\s*}}/g,s="__DG_EMPTY__",a=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,d="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),l=new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`);var c=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),u=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),p=/^\s*(javascript|vbscript|data|blob):/i;function g(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const r of i){const t=r.tagName.toLowerCase();if(c.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>u.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}const i=[];for(const e of r.attributes){const t=e.name.toLowerCase();u.test(t)?i.push(e.name):"is"!==t?(h.has(t)&&p.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name):i.push(e.name)}i.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}function f(t,e){e&&"string"==typeof e?-1!==e.indexOf("<")||-1!==e.indexOf("&")?t.replaceChildren(g(e)):t.textContent=e:t.replaceChildren()}function m(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const r=t[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const r=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<t.length&&"'"!==t[i];)r+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(r,i)});continue}if(i+2<t.length){const r=t.slice(i,i+3);if("==="===r||"!=="===r){e.push({type:"op",v:r}),i+=3;continue}}if(i+1<t.length){const r=t.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){e.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;e.push({type:"op",v:r}),i++}else i++}return e}(t);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}function a(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function d(){const t=function(){let t=l();for(;a("op","||");)s(),t=t||l();return t}();if(a("op","?")){s();const e=d();if(!a("op",":"))return;s();const i=d();return t?e:i}return t}function l(){let t=c();for(;a("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=p();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=p();else{if("-"!==e.v)break;s(),t-=p()}}return t}function p(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return a("op","!")?(s(),!g()):f()}function f(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=d();return a("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-f()):void 0}}const m=d();return n<r.length?void 0:m}function v(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],r=(n=t.replace(o,(t,r)=>{const n=function(t,e){if(!(t=(t||"").trim()))return s;if(w.test(t))return s;if("value"===t)return null==e.value?s:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),r=e.row?e.row[i]:void 0;return null==r?s:String(r)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),r=e.typeDefault?e.typeDefault[i]:void 0;return null==r?s:String(r)}if(t.length>80)return s;if(!a.test(t)||l.test(t))return s;const i=t.match(/\./g);if(i&&i.length>1)return s;try{const i=m(t,e),r=null==i?"":String(i);return w.test(r)?s:r||s}catch{return s}}(r,e);return i.push({expr:r.trim(),result:n}),n===s?n:(o=n)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),n?n.replace(new RegExp(s,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const d=i.length&&i.every(t=>""===t.result||t.result===s);return w.test(t)||d?"":r}var w=/Reflect|Proxy|ownKeys/;var b={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var y=class{static dependencies;static manifest;aliases;version="3.8.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const i={...this.userConfig},r={};for(const e of Object.keys(i))r[e]=this;for(const n of t){const t=n.userConfig;for(const[o,s]of Object.entries(t)){if(void 0===s)continue;if(!(o in i)){i[o]=s,r[o]=n;continue}if(i[o]===s)continue;const t=r[o]?.constructor.name??this.constructor.name,a=n.constructor.name,d=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const r of Object.keys(e))delete e[r];Object.assign(e,i)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const i=this.grid?.query?.(t,e);return Array.isArray(i)?i.some(Boolean):!!i}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...b,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,i);void 0!==r?"string"==typeof r?f(t,r):r instanceof HTMLElement&&t.replaceChildren(r.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(i,r):t.appendChild(i),i}warn(i,r){void 0!==r?console.warn(e(i,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(t,i){throw new Error(e(t,i,this.gridElement.id,this.name))}},R=0,C=/* @__PURE__ */new Set,A="tbw-responsive-column-fade",k="data-responsive-column-fade";function S(t){for(const e of t.getAnimations?.()??[])e.id===A&&(e.finished?.catch(()=>{}),e.cancel())}function E(t){return t.startsWith("minmax(")?t.includes("fr")?"minmax(0px, 0fr)":"minmax(0px, 0px)":t.endsWith("fr")?"0fr":t.endsWith("%")?"0%":"0px"}var _=class extends y{name="responsive";version="1.0.0";styles='tbw-grid[data-responsive-transition]::view-transition-group(*){animation-duration:var(--tbw-responsive-duration,.2s)}tbw-grid[data-responsive-transition] .data-grid-row>.cell{view-transition-class:tbw-responsive-cell}tbw-grid[data-responsive-transition]::view-transition-group(.tbw-responsive-cell){animation-timing-function:ease-in-out}tbw-grid[data-responsive-transition]::view-transition-old(.tbw-responsive-cell){object-fit:none;object-position:right center;width:100%;height:100%}tbw-grid[data-responsive-transition]::view-transition-new(.tbw-responsive-cell){object-fit:none;object-position:right center;width:100%;height:100%}tbw-grid[data-responsive-transition]::view-transition-old(.tbw-responsive-cell){animation-duration:calc(var(--tbw-responsive-duration,.2s) * .35)}tbw-grid[data-responsive-transition]::view-transition-new(.tbw-responsive-cell){animation-duration:calc(var(--tbw-responsive-duration,.2s) * .35)}tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration,.2s) ease-out, transform var(--tbw-responsive-duration,.2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration,.2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);background:var(--tbw-color-bg);padding-inline-start:var(--tbw-spacing-xl);position:relative;contain:none!important;content-visibility:visible!important;grid-template-columns:none!important;display:block!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";background:var(--tbw-color-accent);inset-inline-start:0;width:4px;position:absolute;top:0;bottom:0}tbw-grid[data-responsive] .data-grid-row:not(.group-row,.responsive-card){height:auto!important;min-height:auto!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);justify-content:space-between;align-items:center;white-space:normal!important;border:none!important;background:0 0!important;border-inline-end:none!important;width:100%!important;min-width:0!important;height:auto!important;min-height:auto!important;line-height:1.5!important;display:flex!important;position:static!important;left:auto!important;right:auto!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";color:var(--tbw-color-header-fg);min-width:100px;flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);font-weight:600}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-hidden],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]:before{display:none!important}tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]{font-weight:500;justify-content:flex-start!important}tbw-grid[data-responsive][data-responsive-hide-header] .data-grid-row:not(.group-row)>.cell:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{pointer-events:none;opacity:0;border-inline-width:0!important;padding-inline:0!important;overflow:hidden!important}tbw-grid[data-responsive-column-fade] :is(.header-row,.data-grid-row){transition:grid-template-columns var(--tbw-responsive-duration,.2s) ease-out}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-header-pinned,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);display:block!important}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';static manifest={queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#i;#r=!1;#n;#o=!1;#s=0;#a;#d=Number.NEGATIVE_INFINITY;#l=++R;#c=`tbw-responsive-row-${this.#l}-`;#u=`tbw-responsive-cell-${this.#l}-`;#h=0;#p=/* @__PURE__ */new Set;#g=C;#f=/* @__PURE__ */new Set;#m=C;#v=/* @__PURE__ */new Set;#w=/* @__PURE__ */new Set;#b=0;#y;#R=!1;#C=null;#A=[];get#k(){return this.grid}isResponsive(){return this.#r}setResponsive(t){t!==this.#r&&(this.#r=t,this.#S(),this.emit("responsive-change",{isResponsive:t,width:this.#s,breakpoint:this.config.breakpoint??0}))}setBreakpoint(t){this.config.breakpoint=t,this.#a=void 0,this.#E(this.#s)}setCardRenderer(t){this.config.cardRenderer=t,this.#r&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#C}attach(t){super.attach(t),this.#_(),this.#H(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#A=[...this.config.breakpoints].sort((t,e)=>e.maxWidth-t.maxWidth)),this.#x(),this.#M(),this.#F=void 0,this.#T=void 0,this.#r&&this.requestRender(),this.#i=new ResizeObserver(t=>{this.#W(t[0]?.contentRect.width??0)}),this.#i.observe(this.gridElement)}#W(t){if(this.#s=t,t===this.#a)return;const e=this.config.debounceMs??100,i=performance.now()-this.#d;if(clearTimeout(this.#n),i>=e)return this.#a=t,void this.#E(t);this.#n=setTimeout(()=>{this.#a=this.#s,this.#E(this.#s)},e-i)}#_(){const t=this.gridElement;if(!t)return;const e=t.querySelector("tbw-grid-responsive-card");if(!e)return;const i=this.#k.__frameworkAdapter;if(i?.parseResponsiveCardElement){const t=i.parseResponsiveCardElement(e);t&&(this.config={...this.config,cardRenderer:t})}const r=e.getAttribute("breakpoint"),n=e.getAttribute("card-row-height"),o=e.getAttribute("hidden-columns"),s=e.getAttribute("hide-header"),a=e.getAttribute("debounce-ms"),d={};if(null!==r){const t=parseInt(r,10);isNaN(t)||(d.breakpoint=t)}if(null!==n&&(d.cardRowHeight="auto"===n?"auto":parseInt(n,10)),null!==o&&(d.hiddenColumns=o.split(",").map(t=>t.trim()).filter(t=>t.length>0)),null!==s&&(d.hideHeader="false"!==s),null!==a){const t=parseInt(a,10);isNaN(t)||(d.debounceMs=t)}const l=e.innerHTML.trim();!l||this.config.cardRenderer||i?.parseResponsiveCardElement||(d.cardRenderer=t=>{const e=v(l,{value:t,row:t}),i=document.createElement("div");return i.className="tbw-responsive-card-content",f(i,e),i}),Object.keys(d).length>0&&(this.config={...this.config,...d})}#H(t){this.#p=/* @__PURE__ */new Set,this.#f.clear();for(const e of t??[])"string"==typeof e?this.#p.add(e):e.showValue?this.#f.add(e.field):this.#p.add(e.field);this.#q()}get#L(){return this.#A.length>0?null!==this.#C:this.#r}#q(){const t=this.#L?this.#p:C;for(const e of this.#g)t.has(e)||this.#G(e,!1);for(const e of t)this.#g.has(e)||this.#G(e,!0);this.#O()}#G(t,e){(e?this.#w:this.#v).delete(t),(e?this.#v:this.#w).add(t)}#O(){const t=this.#D;t<=0||0===this.#v.size&&0===this.#w.size?this.#B():(this.#b=performance.now()+t,this.gridElement?.setAttribute(k,""),clearTimeout(this.#y),this.#y=setTimeout(()=>this.#B(),t))}#B(){clearTimeout(this.#y),this.#y=void 0,this.#b=0,this.#v.clear(),this.#w.clear(),this.gridElement?.removeAttribute(k);for(const t of this.gridElement?.querySelectorAll(".cell[data-field]")??[])S(t)}#$(t,e,i,r){S(t);const n=e?[{opacity:1},{opacity:0}]:[{opacity:0},{opacity:1}],o=t.animate?.(n,{duration:i,easing:"ease-out",fill:e?"forwards":"none"});o&&(o.id=A,o.currentTime=r)}#z(t){const e=this.#k?._gridTemplate??"";if(!e)return;const i=this.visibleColumns,r=function(t){const e=[];let i=0,r=0;for(let n=0;n<t.length;n++){const o=t[n];"("===o?i++:")"===o?i--:" "===o&&0===i&&(n>r&&e.push(t.slice(r,n)),r=n+1)}return r<t.length&&e.push(t.slice(r)),e}(e);let n=!1;if(t.size>0&&r.length===i.length)for(let o=0;o<i.length;o++){const e=i[o]?.field;e&&t.has(e)&&(r[o]=E(r[o]),n=!0)}(n||this.#R)&&(this.gridElement.style.setProperty("--tbw-column-template",n?r.join(" "):e),this.#R=n)}detach(){if(this.#i?.disconnect(),this.#i=void 0,this.#B(),clearTimeout(this.#n),this.#n=void 0,this.#a=void 0,this.#d=Number.NEGATIVE_INFINITY,this.gridElement){this.gridElement.removeAttribute("data-responsive"),this.gridElement.removeAttribute("data-responsive-animate"),this.gridElement.removeAttribute("data-responsive-hide-header"),this.gridElement.removeAttribute("data-responsive-transition");for(const t of this.gridElement.querySelectorAll(".cell[data-responsive-hidden], .cell[data-responsive-value-only]"))t.removeAttribute("data-responsive-hidden"),t.removeAttribute("data-responsive-value-only"),t.removeAttribute("aria-hidden");this.#I()}this.#g=C,this.#m=C,super.detach()}handleQuery(t){if("isCardMode"===t.type)return this.#r}afterRender(){this.#N();const t=this.#A.length>0?null!==this.#C:this.#r,e=t?this.#p:C,i=t?this.#f:C,r=this.#v.size>0||this.#w.size>0,n=this.#g.size>0||this.#m.size>0;if(this.#g=e,this.#m=i,this.#z(this.#r?C:e),0===e.size&&0===i.size&&!r&&!n)return;const o=this.#D,s=r?Math.min(o,Math.max(0,o-(this.#b-performance.now()))):0,a=this.gridElement.querySelectorAll(".cell[data-field]");for(const d of a){const t=d.getAttribute("data-field");if(!t)continue;const r=this.#v.has(t);(r||this.#w.has(t))&&this.#$(d,r,o,s),e.has(t)?(d.setAttribute("data-responsive-hidden",""),d.setAttribute("aria-hidden","true"),d.removeAttribute("data-responsive-value-only")):i.has(t)?(d.setAttribute("data-responsive-value-only",""),d.removeAttribute("data-responsive-hidden"),d.removeAttribute("aria-hidden")):(d.removeAttribute("data-responsive-hidden"),d.removeAttribute("data-responsive-value-only"),d.removeAttribute("aria-hidden"))}}#E(t){if(this.#A.length>0)return void this.#P(t);const e=this.config.breakpoint??0;0!==e||this.#o||(this.#o=!0,this.warn("TBW110","No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=e>0&&t<e;i!==this.#r&&(this.#r=i,this.#d=performance.now(),this.#S(),this.emit("responsive-change",{isResponsive:i,width:t,breakpoint:e}))}#P(t){let e=null;for(const i of this.#A)t<=i.maxWidth&&(e=i);if(e!==this.#C){this.#C=e,this.#d=performance.now(),e?.hiddenColumns?this.#H(e.hiddenColumns):this.#H(this.config.hiddenColumns);const i=!0===e?.cardLayout,r=i!==this.#r;r&&(this.#r=i),this.#S(r),this.emit("responsive-change",{isResponsive:this.#r,width:t,breakpoint:e?.maxWidth??0})}}#S(t=!0){this.#x(),t&&this.#B();const e=t?this.#j():null;if(!e)return t&&this.#V(),void this.requestRender();const i=this.gridElement,r=this.#Y(),n=++this.#h;"none"!==r&&this.#U(r),i.setAttribute("data-responsive-transition","");const o=e(async()=>{this.#V(),await(this.#k.forceLayout?.()),"none"!==r&&this.#U(r)}),s=()=>{n===this.#h&&(i.removeAttribute("data-responsive-transition"),"none"!==r&&this.#I())};o.finished.then(s,s),o.ready?.catch(()=>{})}get#K(){const{animation:t,animate:e}=this.config;return void 0!==t?t:!1!==e&&"fade"}get#D(){return!1!==this.#K&&this.isAnimationEnabled?this.config.animationDuration??200:0}#x(){this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.#D}ms`)}#j(){if(!1===this.#K||!this.isAnimationEnabled)return null;const t=this.gridElement,e=t.startViewTransition;return"function"==typeof e?e.bind(t):null}get#J(){return"function"==typeof this.gridElement?.startViewTransition}#U(t){const e=this.gridElement.querySelectorAll(".data-grid-row[aria-rowindex]");for(const i of e){const e=i.getAttribute("aria-rowindex");if("rows"!==t)for(const t of i.querySelectorAll(":scope > .cell[aria-colindex]")){const i=`${this.#u}${e}-${t.getAttribute("aria-colindex")}`;t.style.setProperty("view-transition-name",i)}else i.style.setProperty("view-transition-name",`${this.#c}${e}`)}}#Y(){const t=this.#K;if("morph-cells"===t){const t=this.gridElement.querySelectorAll(".data-grid-row > .cell[aria-colindex]").length;return t>0&&t<=150?"cells":"rows"}return"morph-rows"===t?"rows":"none"}#I(){const t=this.gridElement.querySelectorAll(".data-grid-row, .data-grid-row > .cell");for(const e of t)e.style.removeProperty("view-transition-name")}#Z;#M(){this.gridElement.toggleAttribute("data-responsive",this.#r),this.gridElement.toggleAttribute("data-responsive-animate",!1!==this.#K&&!this.#J),this.gridElement.toggleAttribute("data-responsive-hide-header",this.#r&&!0===this.config.hideHeader)}#V(){this.#M();const t=this.#k;if(this.#r){t._virtualization&&(this.#Z=t._virtualization.rowHeight);const e=this.gridElement.querySelector(".tbw-scroll-area");e&&(e.scrollLeft=0)}else{const e=this.gridElement.querySelectorAll(".data-grid-row");for(const t of e)t.style.height="",t.classList.remove("responsive-card");this.#Z&&this.#Z>0&&t._virtualization&&(t._virtualization.rowHeight=this.#Z,this.#Z=void 0),this.#F=void 0,this.#T=void 0,this.#Q=void 0}}renderRow(t,e,i){if(!this.#r||!this.config.cardRenderer)return;if(t.__isGroupRow)return;e.replaceChildren();const r=this.config.cardRenderer(t,i);e.className="data-grid-row responsive-card";const n=this.config.cardRowHeight;return e.style.height="auto"===n||void 0===n?"auto":`${this.#X()}px`,r.hasAttribute("role")||(r.setAttribute("role","gridcell"),r.setAttribute("aria-colindex","1")),e.appendChild(r),!0}onKeyDown(t){if(!this.#r)return!1;if(this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(t.key))return!1;const e=this.rows.length-1,i=this.visibleColumns.length-1;switch(t.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,t.preventDefault(),n(this.#k),!0;if(this.grid._focusRow<e)return this.grid._focusRow+=1,this.grid._focusCol=0,t.preventDefault(),n(this.#k),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,t.preventDefault(),n(this.#k),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,t.preventDefault(),n(this.#k),!0;break;case"ArrowRight":if(this.grid._focusRow<e)return this.grid._focusRow+=1,t.preventDefault(),n(this.#k),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,t.preventDefault(),n(this.#k),!0}return!1}#F;#T;#Q;#X(){const t=this.config.cardRowHeight,e=this.#F;return"number"==typeof t&&t>0?e&&e>t?e:t:e&&e>0?e:80}#tt(){return this.#T&&this.#T>0?this.#T:this.#Z??28}#et(){for(const t of this.rows)if(t.__isGroupRow)return!0;return!1}getRowHeight(t,e){if(this.#r&&this.config.cardRenderer)return t.__isGroupRow?this.#tt():this.#X()}#it(){let t=0;for(const e of this.rows)e.__isGroupRow||t++;return t}#rt=!1;#N(){if(!this.#r)return;let t=!1;const e=this.#k,i=this.#et(),r=this.#it();if(r!==this.#Q&&(this.#Q=r,t=!0),i){const e=this.gridElement.querySelector(".data-grid-row.group-row");if(e){const i=e.getBoundingClientRect().height;i>0&&i!==this.#T&&(this.#T=i,t=!0)}}const n=this.config.cardRenderer?".data-grid-row.responsive-card":".data-grid-row:not(.group-row)",o=this.gridElement.querySelector(n);if(o){const r=o.getBoundingClientRect().height;r>0&&r!==this.#F&&(this.#F=r,t=!0,!i&&e._virtualization&&(e._virtualization.rowHeight=r))}t&&!this.#rt&&(this.#rt=!0,queueMicrotask(()=>{this.#rt=!1,this.grid&&this.#r&&this.#k.refreshVirtualWindow?.(!0,!0)}))}};export{_ as ResponsivePlugin};
1
+ function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,i,r,n){return`${t(r,n)} ${e}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}var i="editing";function r(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,r=e.rawContentHeight-e.viewportHeight;return i<=0||r<=0?t:t*i/r}function n(t,e){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:e,container:i,viewportEl:n,scrollMapping:o}=t._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(!s||a<=0)return;const d=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const l=Math.max(0,d.top),c=a-l-Math.max(0,d.bottom);if(c<=0)return;const u=t._focusRow*e,h=o?function(t,e){if(!e.capped)return t;const i=e.spacerHeight-e.viewportHeight,r=e.rawContentHeight-e.viewportHeight;if(i<=0||r<=0)return t;const n=t*r/i;return n<0?0:n>r?r:n}(s.scrollTop,o):s.scrollTop;if(u<h+l){const t=Math.max(0,u-l);s.scrollTop=o?r(t,o):t}else if(u+e>h+l+c){const t=Math.max(0,u-c+e-l);s.scrollTop=o?r(t,o):t}}(t);const n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=function(t){const e=t._focusRow,i=t._virtualization.start??0,r=t._virtualization.end??t._rows.length;if(e<i||e>=r)return;const n=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=n?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${t._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:a,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),n&&!e?.forceHorizontalScroll||function(t,e,i,r){const n=t.querySelector(".tbw-scroll-area");if(!n)return;if(r?.forceScrollLeft)return void(n.scrollLeft=0);if(r?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),a=n.getBoundingClientRect(),d=s.left-a.left+n.scrollLeft,l=d+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;d<c?n.scrollLeft=d-o.left:l>u&&(n.scrollLeft=l-n.clientWidth+o.right)}(t,a,d,e),function(t,e,r){if(r&&e.classList.contains(i)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(r){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,d,n)}var o=/{{\s*([^}]+)\s*}}/g,s="__DG_EMPTY__",a=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,d="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),l=new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`);var c=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),u=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),p=/^\s*(javascript|vbscript|data|blob):/i;function g(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const r of i){const t=r.tagName.toLowerCase();if(c.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>u.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}const i=[];for(const e of r.attributes){const t=e.name.toLowerCase();u.test(t)?i.push(e.name):"is"!==t?(h.has(t)&&p.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name):i.push(e.name)}i.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}function f(t,e){e&&"string"==typeof e?-1!==e.indexOf("<")||-1!==e.indexOf("&")?t.replaceChildren(g(e)):t.textContent=e:t.replaceChildren()}function m(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const r=t[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const r=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<t.length&&"'"!==t[i];)r+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(r,i)});continue}if(i+2<t.length){const r=t.slice(i,i+3);if("==="===r||"!=="===r){e.push({type:"op",v:r}),i+=3;continue}}if(i+1<t.length){const r=t.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){e.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;e.push({type:"op",v:r}),i++}else i++}return e}(t);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}function a(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function d(){const t=function(){let t=l();for(;a("op","||");)s(),t=t||l();return t}();if(a("op","?")){s();const e=d();if(!a("op",":"))return;s();const i=d();return t?e:i}return t}function l(){let t=c();for(;a("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=p();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=p();else{if("-"!==e.v)break;s(),t-=p()}}return t}function p(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return a("op","!")?(s(),!g()):f()}function f(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=d();return a("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-f()):void 0}}const m=d();return n<r.length?void 0:m}function v(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],r=(n=t.replace(o,(t,r)=>{const n=function(t,e){if(!(t=(t||"").trim()))return s;if(w.test(t))return s;if("value"===t)return null==e.value?s:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),r=e.row?e.row[i]:void 0;return null==r?s:String(r)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),r=e.typeDefault?e.typeDefault[i]:void 0;return null==r?s:String(r)}if(t.length>80)return s;if(!a.test(t)||l.test(t))return s;const i=t.match(/\./g);if(i&&i.length>1)return s;try{const i=m(t,e),r=null==i?"":String(i);return w.test(r)?s:r||s}catch{return s}}(r,e);return i.push({expr:r.trim(),result:n}),n===s?n:(o=n)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),n?n.replace(new RegExp(s,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const d=i.length&&i.every(t=>""===t.result||t.result===s);return w.test(t)||d?"":r}var w=/Reflect|Proxy|ownKeys/;var b={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var y=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const i={...this.userConfig},r={};for(const e of Object.keys(i))r[e]=this;for(const n of t){const t=n.userConfig;for(const[o,s]of Object.entries(t)){if(void 0===s)continue;if(!(o in i)){i[o]=s,r[o]=n;continue}if(i[o]===s)continue;const t=r[o]?.constructor.name??this.constructor.name,a=n.constructor.name,d=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(d)}}Object.assign(this.userConfig,i)}refreshUserConfigFrom(t){const e=this.userConfig,i={...t.userConfig};for(const r of Object.keys(e))delete e[r];Object.assign(e,i)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const i=this.grid?.query?.(t,e);return Array.isArray(i)?i.some(Boolean):!!i}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...b,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,i);void 0!==r?"string"==typeof r?f(t,r):r instanceof HTMLElement&&t.replaceChildren(r.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(i,r):t.appendChild(i),i}warn(i,r){void 0!==r?console.warn(e(i,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(t,i){throw new Error(e(t,i,this.gridElement.id,this.name))}},R=0,C=/* @__PURE__ */new Set,A="tbw-responsive-column-fade",k="data-responsive-column-fade";function S(t){for(const e of t.getAnimations?.()??[])e.id===A&&(e.finished?.catch(()=>{}),e.cancel())}function E(t){return t.startsWith("minmax(")?t.includes("fr")?"minmax(0px, 0fr)":"minmax(0px, 0px)":t.endsWith("fr")?"0fr":t.endsWith("%")?"0%":"0px"}var _=class extends y{name="responsive";version="1.0.0";styles='tbw-grid[data-responsive-transition]::view-transition-group(*){animation-duration:var(--tbw-responsive-duration,.2s)}tbw-grid[data-responsive-transition] .data-grid-row>.cell{view-transition-class:tbw-responsive-cell}tbw-grid[data-responsive-transition]::view-transition-group(.tbw-responsive-cell){animation-timing-function:ease-in-out}tbw-grid[data-responsive-transition]::view-transition-old(.tbw-responsive-cell){object-fit:none;object-position:right center;width:100%;height:100%}tbw-grid[data-responsive-transition]::view-transition-new(.tbw-responsive-cell){object-fit:none;object-position:right center;width:100%;height:100%}tbw-grid[data-responsive-transition]::view-transition-old(.tbw-responsive-cell){animation-duration:calc(var(--tbw-responsive-duration,.2s) * .35)}tbw-grid[data-responsive-transition]::view-transition-new(.tbw-responsive-cell){animation-duration:calc(var(--tbw-responsive-duration,.2s) * .35)}tbw-grid[data-responsive-animate] .data-grid-row,tbw-grid[data-responsive-animate] .data-grid-row>.cell{transition:opacity var(--tbw-responsive-duration,.2s) ease-out, transform var(--tbw-responsive-duration,.2s) ease-out}tbw-grid[data-responsive][data-responsive-animate] .data-grid-row{animation:responsive-card-enter var(--tbw-responsive-duration,.2s) ease-out}@keyframes responsive-card-enter{0%{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}tbw-grid[data-responsive] .header{display:none!important}tbw-grid[data-responsive] .footer-row{display:none}tbw-grid[data-responsive] .tbw-scroll-area{overflow-x:hidden;min-width:0!important}tbw-grid[data-responsive] .rows-body-wrapper{min-width:0!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row){padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);background:var(--tbw-color-bg);padding-inline-start:var(--tbw-spacing-xl);position:relative;contain:none!important;content-visibility:visible!important;grid-template-columns:none!important;display:block!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row):nth-child(2n){background:var(--tbw-color-row-alt)}tbw-grid[data-responsive] .data-grid-row:not(.group-row):hover{background:var(--tbw-color-row-hover)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]{background:var(--tbw-color-selection)}tbw-grid[data-responsive] .data-grid-row:not(.group-row)[aria-selected=true]:before{content:"";background:var(--tbw-color-accent);inset-inline-start:0;width:4px;position:absolute;top:0;bottom:0}tbw-grid[data-responsive] .data-grid-row:not(.group-row,.responsive-card){height:auto!important;min-height:auto!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell{padding:var(--tbw-spacing-xs) var(--tbw-spacing-md);justify-content:space-between;align-items:center;white-space:normal!important;border:none!important;background:0 0!important;border-inline-end:none!important;width:100%!important;min-width:0!important;height:auto!important;min-height:auto!important;line-height:1.5!important;display:flex!important;position:static!important;left:auto!important;right:auto!important;overflow:visible!important}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:before{content:attr(data-header) ": ";color:var(--tbw-color-header-fg);min-width:100px;flex-shrink:0;margin-inline-end:var(--tbw-spacing-md);font-weight:600}tbw-grid[data-responsive] .data-grid-row:not(.group-row)>.cell:after{content:none}tbw-grid[data-responsive] .cell[data-utility],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-hidden],tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]:before{display:none!important}tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-value-only]{font-weight:500;justify-content:flex-start!important}tbw-grid[data-responsive][data-responsive-hide-header] .data-grid-row:not(.group-row)>.cell:before{display:none!important}tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{pointer-events:none;opacity:0;border-inline-width:0!important;padding-inline:0!important;overflow:hidden!important}tbw-grid[data-responsive-column-fade] :is(.header-row,.data-grid-row){transition:grid-template-columns var(--tbw-responsive-duration,.2s) ease-out}tbw-grid[data-responsive] .tbw-footer,tbw-grid[data-responsive] .tbw-header-pinned,tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows{display:none!important}tbw-grid[data-responsive] .tbw-pinned-rows,tbw-grid[data-responsive] .tbw-aggregation-rows,tbw-grid[data-responsive] .tbw-aggregation-row{min-width:0!important}tbw-grid[data-responsive] .data-grid-row.responsive-card{padding:var(--tbw-cell-padding);border-bottom:1px solid var(--tbw-color-border);display:block!important}tbw-grid[data-responsive] .data-grid-row.responsive-card>*{width:100%}tbw-grid[data-responsive] .data-grid-row.responsive-card .cell:before{display:none}';static manifest={queries:[{type:"isCardMode",description:"Returns whether the grid is currently in responsive card mode"}]};#i;#r=!1;#n;#o=!1;#s=0;#a;#d=Number.NEGATIVE_INFINITY;#l=++R;#c=`tbw-responsive-row-${this.#l}-`;#u=`tbw-responsive-cell-${this.#l}-`;#h=0;#p=/* @__PURE__ */new Set;#g=C;#f=/* @__PURE__ */new Set;#m=C;#v=/* @__PURE__ */new Set;#w=/* @__PURE__ */new Set;#b=0;#y;#R=!1;#C=null;#A=[];get#k(){return this.grid}isResponsive(){return this.#r}setResponsive(t){t!==this.#r&&(this.#r=t,this.#S(),this.emit("responsive-change",{isResponsive:t,width:this.#s,breakpoint:this.config.breakpoint??0}))}setBreakpoint(t){this.config.breakpoint=t,this.#a=void 0,this.#E(this.#s)}setCardRenderer(t){this.config.cardRenderer=t,this.#r&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#C}attach(t){super.attach(t),this.#_(),this.#H(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#A=[...this.config.breakpoints].sort((t,e)=>e.maxWidth-t.maxWidth)),this.#x(),this.#M(),this.#F=void 0,this.#T=void 0,this.#r&&this.requestRender(),this.#i=new ResizeObserver(t=>{this.#W(t[0]?.contentRect.width??0)}),this.#i.observe(this.gridElement)}#W(t){if(this.#s=t,t===this.#a)return;const e=this.config.debounceMs??100,i=performance.now()-this.#d;if(clearTimeout(this.#n),i>=e)return this.#a=t,void this.#E(t);this.#n=setTimeout(()=>{this.#a=this.#s,this.#E(this.#s)},e-i)}#_(){const t=this.gridElement;if(!t)return;const e=t.querySelector("tbw-grid-responsive-card");if(!e)return;const i=this.#k.__frameworkAdapter;if(i?.parseResponsiveCardElement){const t=i.parseResponsiveCardElement(e);t&&(this.config={...this.config,cardRenderer:t})}const r=e.getAttribute("breakpoint"),n=e.getAttribute("card-row-height"),o=e.getAttribute("hidden-columns"),s=e.getAttribute("hide-header"),a=e.getAttribute("debounce-ms"),d={};if(null!==r){const t=parseInt(r,10);isNaN(t)||(d.breakpoint=t)}if(null!==n&&(d.cardRowHeight="auto"===n?"auto":parseInt(n,10)),null!==o&&(d.hiddenColumns=o.split(",").map(t=>t.trim()).filter(t=>t.length>0)),null!==s&&(d.hideHeader="false"!==s),null!==a){const t=parseInt(a,10);isNaN(t)||(d.debounceMs=t)}const l=e.innerHTML.trim();!l||this.config.cardRenderer||i?.parseResponsiveCardElement||(d.cardRenderer=t=>{const e=v(l,{value:t,row:t}),i=document.createElement("div");return i.className="tbw-responsive-card-content",f(i,e),i}),Object.keys(d).length>0&&(this.config={...this.config,...d})}#H(t){this.#p=/* @__PURE__ */new Set,this.#f.clear();for(const e of t??[])"string"==typeof e?this.#p.add(e):e.showValue?this.#f.add(e.field):this.#p.add(e.field);this.#q()}get#L(){return this.#A.length>0?null!==this.#C:this.#r}#q(){const t=this.#L?this.#p:C;for(const e of this.#g)t.has(e)||this.#G(e,!1);for(const e of t)this.#g.has(e)||this.#G(e,!0);this.#O()}#G(t,e){(e?this.#w:this.#v).delete(t),(e?this.#v:this.#w).add(t)}#O(){const t=this.#D;t<=0||0===this.#v.size&&0===this.#w.size?this.#B():(this.#b=performance.now()+t,this.gridElement?.setAttribute(k,""),clearTimeout(this.#y),this.#y=setTimeout(()=>this.#B(),t))}#B(){clearTimeout(this.#y),this.#y=void 0,this.#b=0,this.#v.clear(),this.#w.clear(),this.gridElement?.removeAttribute(k);for(const t of this.gridElement?.querySelectorAll(".cell[data-field]")??[])S(t)}#$(t,e,i,r){S(t);const n=e?[{opacity:1},{opacity:0}]:[{opacity:0},{opacity:1}],o=t.animate?.(n,{duration:i,easing:"ease-out",fill:e?"forwards":"none"});o&&(o.id=A,o.currentTime=r)}#z(t){const e=this.#k?._gridTemplate??"";if(!e)return;const i=this.visibleColumns,r=function(t){const e=[];let i=0,r=0;for(let n=0;n<t.length;n++){const o=t[n];"("===o?i++:")"===o?i--:" "===o&&0===i&&(n>r&&e.push(t.slice(r,n)),r=n+1)}return r<t.length&&e.push(t.slice(r)),e}(e);let n=!1;if(t.size>0&&r.length===i.length)for(let o=0;o<i.length;o++){const e=i[o]?.field;e&&t.has(e)&&(r[o]=E(r[o]),n=!0)}(n||this.#R)&&(this.gridElement.style.setProperty("--tbw-column-template",n?r.join(" "):e),this.#R=n)}detach(){if(this.#i?.disconnect(),this.#i=void 0,this.#B(),clearTimeout(this.#n),this.#n=void 0,this.#a=void 0,this.#d=Number.NEGATIVE_INFINITY,this.gridElement){this.gridElement.removeAttribute("data-responsive"),this.gridElement.removeAttribute("data-responsive-animate"),this.gridElement.removeAttribute("data-responsive-hide-header"),this.gridElement.removeAttribute("data-responsive-transition");for(const t of this.gridElement.querySelectorAll(".cell[data-responsive-hidden], .cell[data-responsive-value-only]"))t.removeAttribute("data-responsive-hidden"),t.removeAttribute("data-responsive-value-only"),t.removeAttribute("aria-hidden");this.#I()}this.#g=C,this.#m=C,super.detach()}handleQuery(t){if("isCardMode"===t.type)return this.#r}afterRender(){this.#N();const t=this.#A.length>0?null!==this.#C:this.#r,e=t?this.#p:C,i=t?this.#f:C,r=this.#v.size>0||this.#w.size>0,n=this.#g.size>0||this.#m.size>0;if(this.#g=e,this.#m=i,this.#z(this.#r?C:e),0===e.size&&0===i.size&&!r&&!n)return;const o=this.#D,s=r?Math.min(o,Math.max(0,o-(this.#b-performance.now()))):0,a=this.gridElement.querySelectorAll(".cell[data-field]");for(const d of a){const t=d.getAttribute("data-field");if(!t)continue;const r=this.#v.has(t);(r||this.#w.has(t))&&this.#$(d,r,o,s),e.has(t)?(d.setAttribute("data-responsive-hidden",""),d.setAttribute("aria-hidden","true"),d.removeAttribute("data-responsive-value-only")):i.has(t)?(d.setAttribute("data-responsive-value-only",""),d.removeAttribute("data-responsive-hidden"),d.removeAttribute("aria-hidden")):(d.removeAttribute("data-responsive-hidden"),d.removeAttribute("data-responsive-value-only"),d.removeAttribute("aria-hidden"))}}#E(t){if(this.#A.length>0)return void this.#P(t);const e=this.config.breakpoint??0;0!==e||this.#o||(this.#o=!0,this.warn("TBW110","No breakpoint configured. Responsive mode is disabled. Set a breakpoint based on your grid's column count."));const i=e>0&&t<e;i!==this.#r&&(this.#r=i,this.#d=performance.now(),this.#S(),this.emit("responsive-change",{isResponsive:i,width:t,breakpoint:e}))}#P(t){let e=null;for(const i of this.#A)t<=i.maxWidth&&(e=i);if(e!==this.#C){this.#C=e,this.#d=performance.now(),e?.hiddenColumns?this.#H(e.hiddenColumns):this.#H(this.config.hiddenColumns);const i=!0===e?.cardLayout,r=i!==this.#r;r&&(this.#r=i),this.#S(r),this.emit("responsive-change",{isResponsive:this.#r,width:t,breakpoint:e?.maxWidth??0})}}#S(t=!0){this.#x(),t&&this.#B();const e=t?this.#j():null;if(!e)return t&&this.#V(),void this.requestRender();const i=this.gridElement,r=this.#Y(),n=++this.#h;"none"!==r&&this.#U(r),i.setAttribute("data-responsive-transition","");const o=e(async()=>{this.#V(),await(this.#k.forceLayout?.()),"none"!==r&&this.#U(r)}),s=()=>{n===this.#h&&(i.removeAttribute("data-responsive-transition"),"none"!==r&&this.#I())};o.finished.then(s,s),o.ready?.catch(()=>{})}get#K(){const{animation:t,animate:e}=this.config;return void 0!==t?t:!1!==e&&"fade"}get#D(){return!1!==this.#K&&this.isAnimationEnabled?this.config.animationDuration??200:0}#x(){this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.#D}ms`)}#j(){if(!1===this.#K||!this.isAnimationEnabled)return null;const t=this.gridElement,e=t.startViewTransition;return"function"==typeof e?e.bind(t):null}get#J(){return"function"==typeof this.gridElement?.startViewTransition}#U(t){const e=this.gridElement.querySelectorAll(".data-grid-row[aria-rowindex]");for(const i of e){const e=i.getAttribute("aria-rowindex");if("rows"!==t)for(const t of i.querySelectorAll(":scope > .cell[aria-colindex]")){const i=`${this.#u}${e}-${t.getAttribute("aria-colindex")}`;t.style.setProperty("view-transition-name",i)}else i.style.setProperty("view-transition-name",`${this.#c}${e}`)}}#Y(){const t=this.#K;if("morph-cells"===t){const t=this.gridElement.querySelectorAll(".data-grid-row > .cell[aria-colindex]").length;return t>0&&t<=150?"cells":"rows"}return"morph-rows"===t?"rows":"none"}#I(){const t=this.gridElement.querySelectorAll(".data-grid-row, .data-grid-row > .cell");for(const e of t)e.style.removeProperty("view-transition-name")}#Z;#M(){this.gridElement.toggleAttribute("data-responsive",this.#r),this.gridElement.toggleAttribute("data-responsive-animate",!1!==this.#K&&!this.#J),this.gridElement.toggleAttribute("data-responsive-hide-header",this.#r&&!0===this.config.hideHeader)}#V(){this.#M();const t=this.#k;if(this.#r){t._virtualization&&(this.#Z=t._virtualization.rowHeight);const e=this.gridElement.querySelector(".tbw-scroll-area");e&&(e.scrollLeft=0)}else{const e=this.gridElement.querySelectorAll(".data-grid-row");for(const t of e)t.style.height="",t.classList.remove("responsive-card");this.#Z&&this.#Z>0&&t._virtualization&&(t._virtualization.rowHeight=this.#Z,this.#Z=void 0),this.#F=void 0,this.#T=void 0,this.#Q=void 0}}renderRow(t,e,i){if(!this.#r||!this.config.cardRenderer)return;if(t.__isGroupRow)return;e.replaceChildren();const r=this.config.cardRenderer(t,i);e.className="data-grid-row responsive-card";const n=this.config.cardRowHeight;return e.style.height="auto"===n||void 0===n?"auto":`${this.#X()}px`,r.hasAttribute("role")||(r.setAttribute("role","gridcell"),r.setAttribute("aria-colindex","1")),e.appendChild(r),!0}onKeyDown(t){if(!this.#r)return!1;if(this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(t.key))return!1;const e=this.rows.length-1,i=this.visibleColumns.length-1;switch(t.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,t.preventDefault(),n(this.#k),!0;if(this.grid._focusRow<e)return this.grid._focusRow+=1,this.grid._focusCol=0,t.preventDefault(),n(this.#k),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,t.preventDefault(),n(this.#k),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,t.preventDefault(),n(this.#k),!0;break;case"ArrowRight":if(this.grid._focusRow<e)return this.grid._focusRow+=1,t.preventDefault(),n(this.#k),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,t.preventDefault(),n(this.#k),!0}return!1}#F;#T;#Q;#X(){const t=this.config.cardRowHeight,e=this.#F;return"number"==typeof t&&t>0?e&&e>t?e:t:e&&e>0?e:80}#tt(){return this.#T&&this.#T>0?this.#T:this.#Z??28}#et(){for(const t of this.rows)if(t.__isGroupRow)return!0;return!1}getRowHeight(t,e){if(this.#r&&this.config.cardRenderer)return t.__isGroupRow?this.#tt():this.#X()}#it(){let t=0;for(const e of this.rows)e.__isGroupRow||t++;return t}#rt=!1;#N(){if(!this.#r)return;let t=!1;const e=this.#k,i=this.#et(),r=this.#it();if(r!==this.#Q&&(this.#Q=r,t=!0),i){const e=this.gridElement.querySelector(".data-grid-row.group-row");if(e){const i=e.getBoundingClientRect().height;i>0&&i!==this.#T&&(this.#T=i,t=!0)}}const n=this.config.cardRenderer?".data-grid-row.responsive-card":".data-grid-row:not(.group-row)",o=this.gridElement.querySelector(n);if(o){const r=o.getBoundingClientRect().height;r>0&&r!==this.#F&&(this.#F=r,t=!0,!i&&e._virtualization&&(e._virtualization.rowHeight=r))}t&&!this.#rt&&(this.#rt=!0,queueMicrotask(()=>{this.#rt=!1,this.grid&&this.#r&&this.#k.refreshVirtualWindow?.(!0,!0)}))}};export{_ as ResponsivePlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- var e="editing",t="dragging",r=/* @__PURE__ */new Map;function o(e){const t=r.get(e);if(!t)return;if(t.hasPrimitives)return;const o=[];for(const r of t.refs){const e=r.deref();if(void 0===e)return;o.push(e)}return o}function n(e){r.delete(e)}function i(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){const e=/* @__PURE__ */new Uint32Array(2);return crypto.getRandomValues(e),`drag-${Date.now().toString(36)}-${e[0].toString(36)}${e[1].toString(36)}`}return`drag-${Date.now().toString(36)}-${(++s).toString(36)}`}var s=0;function a(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,o=t.rawContentHeight-t.viewportHeight;return r<=0||o<=0?e:e*r/o}function d(t,r){!function(e){if(!e._virtualization?.enabled)return;const{rowHeight:t,container:r,viewportEl:o,scrollMapping:n}=e._virtualization,i=r,s=o?.clientHeight??i?.clientHeight??0;if(!i||s<=0)return;const d=e._getVerticalScrollOffsets?.(e._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const c=Math.max(0,d.top),l=s-c-Math.max(0,d.bottom);if(l<=0)return;const g=e._focusRow*t,u=n?function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,o=t.rawContentHeight-t.viewportHeight;if(r<=0||o<=0)return e;const n=e*o/r;return n<0?0:n>o?o:n}(i.scrollTop,n):i.scrollTop;if(g<u+c){const e=Math.max(0,g-c);i.scrollTop=n?a(e,n):e}else if(g+t>u+c+l){const e=Math.max(0,g-l+t-c);i.scrollTop=n?a(e,n):e}}(t);const o=function(e){return void 0!==e._activeEditRows&&-1!==e._activeEditRows}(t)||!!t._isGridEditMode;var n;o||t.refreshVirtualWindow(!1),(n=t._bodyEl)&&n.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const i=function(e){const t=e._focusRow,r=e._virtualization.start??0,o=e._virtualization.end??e._rows.length;if(t<r||t>=o)return;const n=e._bodyEl.querySelectorAll(".data-grid-row")[t-r];let i=n?.children[e._focusCol];return i&&i.classList?.contains("cell")||(i=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),i?{rowEl:n??null,cell:i}:void 0}(t);if(!i)return;const{rowEl:s,cell:d}=i;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),o&&!r?.forceHorizontalScroll||function(e,t,r,o){const n=e.querySelector(".tbw-scroll-area");if(!n)return;if(o?.forceScrollLeft)return void(n.scrollLeft=0);if(o?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const i=e._getHorizontalScrollOffsets?.(t??void 0,r)??{left:0,right:0};if(i.skipScroll)return;const s=r.getBoundingClientRect(),a=n.getBoundingClientRect(),d=s.left-a.left+n.scrollLeft,c=d+s.width,l=n.scrollLeft+i.left,g=n.scrollLeft+n.clientWidth-i.right;d<l?n.scrollLeft=d-i.left:c>g&&(n.scrollLeft=c-n.clientWidth+i.right)}(t,s,d,r),function(t,r,o){if(o&&r.classList.contains(e)){const e=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}return}if(o){if(r.contains(document.activeElement))return;r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,d,o)}var c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function l(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function g(e,t,r,o){return`${l(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var u="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),f=(new RegExp(`__(proto|defineGetter|defineSetter)|${u.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),h=/^on\w+$/i,p=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),w=/^\s*(javascript|vbscript|data|blob):/i;function m(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(f.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>h.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();h.test(e)?r.push(t.name):"is"!==e?(p.has(e)&&w.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name):r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var b=class{static dependencies;static manifest;aliases;version="3.8.1";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,i]of Object.entries(e)){if(void 0===i)continue;if(!(n in t)){t[n]=i,r[n]=o;continue}if(t[n]===i)continue;const e=r[n]?.constructor.name??this.constructor.name,s=o.constructor.name,a=g("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const r=this.grid?.query?.(e,t);return Array.isArray(r)?r.some(Boolean):!!r}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...c,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);var n,i;void 0!==o?"string"==typeof o?(n=e,(i=o)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?n.replaceChildren(m(i)):n.textContent=i:n.replaceChildren()):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(g(e,t,this.gridElement.id,this.name)):console.warn(`${l(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(g(e,t,this.gridElement.id,this.name))}},v=null;function I(){return v}function y(){v=null}var x="application/x-tbw-grid-rows+json";function R(e){const t=e.match(/^application\/x-tbw-grid-rows\+json;zone=(.*)$/);if(!t)return null;try{return decodeURIComponent(t[1])}catch{return t[1]}}function C(e){return JSON.stringify(e)}function E(e,t,r,o){if(!e)return{overIndex:null,insertIndex:o,isBefore:!1};const n=r(e);if(n<0)return{overIndex:null,insertIndex:o,isBefore:!1};const i=e.getBoundingClientRect(),s=t<i.top+i.height/2;return{overIndex:n,insertIndex:s?n:n+1,isBefore:s}}function D(){return"function"==typeof HTMLElement.prototype?.showPopover}function S(e,t){let r=null,o=!1,n=!1;const i=new AbortController;function s(){o&&r&&(o=!1,D()&&r.hidePopover(),r.hidden=!0)}return document.addEventListener("pointerdown",e=>{o&&r&&!e.composedPath().includes(r)&&s()},{capture:!0,signal:i.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&s()},{capture:!0,signal:i.signal}),{get element(){return r},open(a,d,c){if(n||0===c.length)return;r||(r=function(){const r=document.createElement("div");return r.id=e,r.className=t,r.setAttribute("popover","manual"),r.setAttribute("role","group"),r.hidden=!0,r.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!r.contains(t)&&s()},{signal:i.signal}),r}());const l=a.closest("tbw-grid, [data-tbw-grid]")??document.body;r.parentNode!==l&&l.appendChild(r),r.setAttribute("aria-label",d),r.replaceChildren();for(const e of c){const o=document.createElement("button");o.type="button",o.className=`${t}-item`,o.textContent=e.label,o.disabled=!0===e.disabled,o.addEventListener("click",()=>{s(),e.run()}),r.appendChild(o)}r.hidden=!1,!o&&D()&&r.showPopover(),o=!0,function(e){if(!r)return;const t=e.getBoundingClientRect(),o=r.getBoundingClientRect(),n=Math.max(4,Math.min(t.left,window.innerWidth-o.width-4)),i=t.bottom+6,s=i+o.height<=window.innerHeight?i:Math.max(4,t.top-6-o.height);r.style.left=`${Math.round(n)}px`,r.style.top=`${Math.round(s)}px`}(a),r.querySelector("button:not([disabled])")?.focus()},close:s,dispose(){n=!0,s(),i.abort(),r?.remove(),r=null}}}var M="__tbw_row_drag",A=null,_=/* @__PURE__ */new Set;function L(){if("undefined"==typeof BroadcastChannel)return null;if(A)return A;try{(A=new BroadcastChannel("tbw-row-drag-drop")).addEventListener("message",e=>{const t=e.data;if(t&&"tbw-row-drag-drop:transfer"===t.type)for(const r of Array.from(_))try{r(t)}catch{}})}catch{A=null}return A}var T=/* @__PURE__ */new Set;var G=class e extends b{name="rowDragDrop";styles='@layer tbw-plugins{[data-field=__tbw_row_drag]{justify-content:center;align-items:center;display:flex}.dg-row-drag-handle{cursor:grab;-webkit-user-select:none;user-select:none;min-width:1em;min-height:1em;color:var(--tbw-row-reorder-handle-color,var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration,.12s) var(--tbw-transition-ease,ease);font-size:var(--tbw-font-size,1em);letter-spacing:-2px;justify-content:center;align-items:center;display:flex;position:relative}.dg-row-drag-handle:after{content:"";inline-size:var(--tbw-touch-target-min,24px);block-size:var(--tbw-touch-target-min,24px);position:absolute;inset-block-start:50%;inset-inline-start:50%;translate:-50% -50%}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover,var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}@media (hover:none){.dg-row-drag-handle{color:var(--tbw-row-reorder-handle-hover,var(--tbw-color-fg))}}@media (pointer:coarse){.dg-row-drag-handle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.data-grid-row.dragging{opacity:.6}.data-grid-row[draggable=true]{cursor:grab}.data-grid-row[draggable=true].dragging{cursor:grabbing}.tbw-row-drag-clone{pointer-events:none;position:fixed;top:-10000px;left:-10000px}.tbw-row-drag-count{pointer-events:none;background:var(--tbw-row-reorder-indicator,var(--tbw-color-accent));color:var(--tbw-color-accent-fg);box-shadow:0 2px 6px var(--tbw-color-shadow);z-index:9999;border-radius:999px;padding:2px 8px;font:600 12px/1.4 system-ui,sans-serif;position:fixed;top:-1000px;left:-1000px}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before,.data-grid-row.drop-target.drop-after:after{content:"";height:var(--tbw-drop-indicator-width,2px);background-color:var(--tbw-drop-indicator-color,var(--tbw-row-reorder-indicator,var(--tbw-color-accent)));z-index:10;pointer-events:none;position:absolute;left:0;right:0}.data-grid-row.drop-target.drop-before:before{top:0}.data-grid-row.drop-target.drop-after:after{bottom:0}.tbw-grid--drop-target-active{outline:2px dashed var(--tbw-drop-indicator-color,var(--tbw-color-accent));outline-offset:-2px}.tbw-grid--drop-target-rejected{outline:2px dashed var(--tbw-color-danger);outline-offset:-2px}.tbw-grid--auto-scrolling{cursor:ns-resize}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration,.2s) ease-out;will-change:transform;z-index:1}.tbw-row-move-menu{min-width:10rem;padding:var(--tbw-spacing-xs,.25rem);background:var(--tbw-color-panel-bg,light-dark(#fff,#1f1f1f));color:var(--tbw-color-fg,light-dark(#1a1a1a,#f0f0f0));border:1px solid var(--tbw-color-border,light-dark(#d0d0d0,#3a3a3a));border-radius:var(--tbw-border-radius,.25rem);box-shadow:var(--tbw-shadow-md,0 4px 12px #00000040);font:inherit;z-index:10001;flex-direction:column;margin:0;display:flex;position:fixed}.tbw-row-move-menu[hidden]{display:none}.tbw-row-move-menu-item{min-height:var(--tbw-touch-target-min,24px);padding:var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-sm,.5rem);text-align:start;border-radius:min(var(--tbw-border-radius,.25rem), 6px);color:inherit;font:inherit;cursor:pointer;background:0 0;border:none}.tbw-row-move-menu-item:hover:not(:disabled){background:var(--tbw-color-row-hover,light-dark(#f0f0f0,#2a2a2a))}.tbw-row-move-menu-item:disabled{opacity:.5;cursor:default}}';static manifest={events:[{type:"row-move",description:"Intra-grid row reorder.",cancelable:!0},{type:"row-drag-start",description:"Cross-grid drag started on this grid.",cancelable:!0},{type:"row-drag-end",description:"Drag finished on this grid (regardless of outcome)."},{type:"row-drop",description:"Cross-grid drop landing on this grid.",cancelable:!0},{type:"row-transfer",description:"Cross-grid transfer completed (fires on both grids)."}]};get defaultConfig(){return{enableKeyboard:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip",operation:"move",autoScroll:!0,dragFrom:"handle"}}shouldRenderDragHandle(){const e=this.config.showDragHandle;return!1!==e&&(!0===e||"row"!==this.config.dragFrom)}get rowIsDraggable(){return"row"===this.config.dragFrom||"both"===this.config.dragFrom}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}isDragging=!1;draggedRowIndex=null;draggedRows=[];draggedIndices=[];dragSessionId=null;dragAccepted=!1;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;autoScroller=null;gridId="";remoteTransferListener=e=>this.onRemoteTransfer(e);moveMenu=null;get internalGrid(){return this.grid}attach(e){super.attach(e);const t=this.gridElement;var r;t&&(this.gridId=t.id||`tbw-grid-${i().slice(0,8)}`,t.id||(t.id=this.gridId),this.setupDelegatedDragListeners(),r=this.remoteTransferListener,_.add(r),L(),T.add(this))}detach(){this.clearDebounceTimer(),this.autoScroller?.stop(),this.autoScroller=null,function(e){if(_.delete(e),0===_.size&&A){try{A.close()}catch{}A=null}}(this.remoteTransferListener),T.delete(this),this.moveMenu?.dispose(),this.moveMenu=null,this.dragSessionId&&n(this.dragSessionId),y(),this.resetDragState(),super.detach()}processColumns(e){if(!this.shouldRenderDragHandle())return[...e];const t={field:M,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,viewRenderer:()=>{const e=document.createElement("div");return e.className="dg-row-drag-handle",e.setAttribute("aria-label","Drag to reorder, or activate for move options"),e.setAttribute("role","button"),e.setAttribute("tabindex","-1"),e.draggable=!0,e.addEventListener("click",t=>{t.stopPropagation(),this.openMoveMenu(e)}),this.setIcon(e,"dragHandle"),e}};return"right"===this.config.dragHandlePosition?[...e,t]:[t,...e]}afterRender(){this.applyRowDraggable()}onScrollRender(){this.applyRowDraggable()}applyRowDraggable(){const e=this.internalGrid._bodyEl;if(!e)return;const t=this.rowIsDraggable,r=e.querySelectorAll(".data-grid-row");for(const o of r)t?"true"!==o.getAttribute("draggable")&&o.setAttribute("draggable","true"):o.hasAttribute("draggable")&&o.removeAttribute("draggable")}onKeyDown(e){if(!this.config.enableKeyboard)return;if(!e.ctrlKey||"ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;const t=this.internalGrid,r=t._focusRow,o=t._rows??this.sourceRows;if(r<0||r>=o.length)return;const n="up"==("ArrowUp"===e.key?"up":"down")?r-1:r+1;if(n<0||n>=o.length)return;const i=o[r];return this.canMoveRow(r,n)?(this.handleKeyboardMove(i,r,n,t._focusCol),e.preventDefault(),e.stopPropagation(),!0):void 0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const r=[...this.sourceRows];e<0||e>=r.length||t<0||t>=r.length||e!==t&&this.canMoveRow(e,t)&&this.executeIntraGridMove(r[e],e,t,"keyboard")}canMoveRow(e,t){const r=this.internalGrid._rows??this.sourceRows;if(e<0||e>=r.length)return!1;if(t<0||t>=r.length)return!1;if(e===t)return!1;const o=r[e],n=this.grid?.query?.("canMoveRow",o);if(Array.isArray(n)&&n.includes(!1))return!1;if(this.config.canDrag&&!this.config.canDrag(o,e))return!1;if(this.config.canDrop){const r={sessionId:"intra",sourceGridId:this.gridId,dropZone:this.config.dropZone??"",rows:[o],rowIndices:[e],operation:"move"};if(!this.config.canDrop(r,t))return!1}return!0}setupDelegatedDragListeners(){const e=this.gridElement;if(!e)return;const t=this.disconnectSignal;e.addEventListener("dragstart",e=>this.onDragStart(e),{signal:t}),e.addEventListener("dragend",()=>this.onDragEnd(),{signal:t}),e.addEventListener("dragover",e=>this.onDragOver(e),{signal:t}),e.addEventListener("dragleave",e=>this.onDragLeave(e),{signal:t}),e.addEventListener("drop",e=>this.onDrop(e),{signal:t})}onDragStart(e){const o=e.target;if(!o)return;const n=o.closest(".dg-row-drag-handle");let s=null,a=!1;if(n)s=n.closest(".data-grid-row"),a=!0;else if(this.rowIsDraggable){if(this.isInteractiveDragOrigin(o))return;s=o.closest(".data-grid-row")}if(!s)return;const d=this.getRowIndex(s);if(d<0)return;const{rows:c,indices:l}=this.resolveDraggedRows(d);if(0===c.length)return;if(this.config.canDrag&&!this.config.canDrag(c[0],d))return void e.preventDefault();const g=this.config.operation??"move",u=this.config.dropZone??"",f=i(),h={rows:c,indices:l,operation:g,dropZone:u};if(this.emitCancelable("row-drag-start",h))return void e.preventDefault();this.isDragging=!0,this.draggedRowIndex=d,this.draggedRows=c,this.draggedIndices=l,this.dragSessionId=f,this.dragAccepted=!1;const p=this.config.serializeRow??(e=>e),w={sessionId:f,sourceGridId:this.gridId,dropZone:u,rows:c.map(p),rowIndices:l,operation:g};if(e.dataTransfer){e.dataTransfer.effectAllowed="copy"===g?"copyMove":"move";try{e.dataTransfer.setData(x,C(w)),u&&e.dataTransfer.setData(`${x};zone=${encodeURIComponent(u)}`,C(w)),e.dataTransfer.setData("text/plain",function(e,t){const r=t.filter(e=>!e.utility&&"string"==typeof e.field&&""!==e.field),o=[];for(const n of e){const e=r.map(e=>{const t=n[e.field];return null==t?"":String(t).replace(/[\t\r\n]+/g," ")});o.push(e.join("\t"))}return o.join("\n")}(c,this.columns))}catch{}if(c.length>1){const t=document.createElement("div");t.className="tbw-row-drag-count",t.textContent=`${c.length} rows`,document.body.appendChild(t);try{e.dataTransfer.setDragImage(t,10,10)}catch{}setTimeout(()=>t.remove(),0)}else this.attachRowCloneDragImage(e,s,a?n:null)}!function(e,t){const o=[];let n=!1;for(const r of t)null!==r&&"object"==typeof r?o.push(new WeakRef(r)):n=!0;r.set(e,{refs:o,hasPrimitives:n})}(f,c),function(e,t){v={sessionId:e,payload:t}}(f,w),s.classList.add(t),this.gridElement.classList.add("tbw-grid--drag-source")}static INTERACTIVE_DRAG_SELECTORS='input,textarea,select,button,a,[contenteditable=""],[contenteditable="true"],.dg-cell-editor,.tbw-checkbox-cell';isInteractiveDragOrigin(t){return null!==t.closest(e.INTERACTIVE_DRAG_SELECTORS)}attachRowCloneDragImage(e,t,r){if(!e.dataTransfer)return;const o=t.getBoundingClientRect(),n=t.cloneNode(!0);n.classList.add("tbw-row-drag-clone"),n.classList.remove("dragging","drop-target","drop-before","drop-after","flip-animating","row-focus"),n.removeAttribute("aria-selected"),n.style.width=`${o.width}px`,n.style.height=`${o.height}px`,this.gridElement.appendChild(n);let i=e.clientX-o.left,s=e.clientY-o.top;if(r){const e=r.getBoundingClientRect();i=e.left-o.left+e.width/2,s=e.top-o.top+e.height/2}i=Math.max(0,Math.min(o.width,i)),s=Math.max(0,Math.min(o.height,s));try{e.dataTransfer.setDragImage(n,i,s)}catch{}setTimeout(()=>n.remove(),0)}onDragOver(e){const t=e.dataTransfer;if(!t)return;const r=t.types?Array.from(t.types):[];if(!function(e){for(const t of e)if("application/x-tbw-grid-rows+json"===t||t.startsWith("application/x-tbw-grid-rows+json;"))return!0;return!1}(r)&&!this.isDragging)return;const o=this.config.dropZone??"",n=I(),i=this.isDragging&&n?.payload.sourceGridId===this.gridId;if(!i){if(!o)return;if(!(function(e,t){for(const r of e)if(R(r)===t)return r;return null}(r,o)||n&&n.payload.dropZone===o))return}e.preventDefault(),t&&(t.dropEffect=n?.payload.operation??this.config.operation??"move");const s=e.target.closest(".data-grid-row"),a=this.internalGrid._rows??[],d=E(s,e.clientY,e=>this.getRowIndex(e),a.length);if(i&&null!==d.overIndex&&d.overIndex===this.draggedRowIndex)this.clearDropTargetClasses();else{if(n&&this.config.canDrop){const e=this.config.canDrop(n.payload,d.insertIndex);if(this.gridElement.classList.toggle("tbw-grid--drop-target-active",e),this.gridElement.classList.toggle("tbw-grid--drop-target-rejected",!e),!e)return void this.clearDropTargetClasses()}else this.gridElement.classList.add("tbw-grid--drop-target-active");this.dropRowIndex=d.insertIndex,this.applyDropPositionClasses(s,d.isBefore),!1!==this.config.autoScroll&&(this.ensureAutoScroller(),this.autoScroller?.onPointerMove(e.clientY))}}onDragLeave(e){const t=e.target.closest(".data-grid-row");t&&t.classList.remove("drop-target","drop-before","drop-after"),e.currentTarget&&!this.gridElement.contains(e.relatedTarget)&&(this.gridElement.classList.remove("tbw-grid--drop-target-active","tbw-grid--drop-target-rejected"),this.autoScroller?.stop())}onDrop(e){e.preventDefault(),this.autoScroller?.stop(),this.gridElement.classList.remove("tbw-grid--drop-target-active","tbw-grid--drop-target-rejected"),this.clearDropTargetClasses();const t=e.dataTransfer;if(!t)return;let r=I()?.payload??null,n=null;if(r){const e=o(r.sessionId);e&&(n=e)}else{if(r=function(e){if(!e)return null;try{const t=JSON.parse(e);if("string"!=typeof t?.sessionId||"string"!=typeof t?.sourceGridId||"string"!=typeof t?.dropZone||!Array.isArray(t?.rows)||!Array.isArray(t?.rowIndices)||"move"!==t.operation&&"copy"!==t.operation)return null;for(const e of t.rowIndices)if("number"!=typeof e||!Number.isInteger(e)||e<0)return null;return t}catch{return null}}(t.getData(x)),r){const e=o(r.sessionId);e&&(n=e)}}if(!r)return;const i=e.target.closest(".data-grid-row"),s=this.internalGrid._rows??[],a=E(i,e.clientY,e=>this.getRowIndex(e),s.length);let d=this.dropRowIndex??a.insertIndex;const c=r.sourceGridId===this.gridId,l=this.config.dropZone??"";if(c){const e=r.rowIndices[0];if(1===r.rowIndices.length&&d>e&&d--,e===d)return;const t=(n??r.rows)[0];if(!this.canMoveRow(e,d))return;return void this.executeIntraGridMove(t,e,d,"drag")}if(!l||l!==r.dropZone)return;if(this.config.canDrop&&!this.config.canDrop(r,d))return this.gridElement.classList.add("tbw-grid--drop-target-rejected"),void setTimeout(()=>this.gridElement.classList.remove("tbw-grid--drop-target-rejected"),200);const g=this.config.deserializeRow??(e=>e),u=n??r.rows.map(e=>g(e)),f={payload:r,sourceGridId:r.sourceGridId,targetIndex:d,operation:r.operation};if(this.emitCancelable("row-drop",f))return;const h=[...s];h.splice(d,0,...u),this.grid.rows=h;const p=this.findPeerOnGrid(r.sourceGridId);if("move"===r.operation&&p){const e=document.getElementById(r.sourceGridId);if(e){const t=(e._rows??e.rows??[]).slice(),o=[...r.rowIndices].sort((e,t)=>t-e);for(const e of o)e>=0&&e<t.length&&t.splice(e,1);e.rows=t}}p&&(p.dragAccepted=!0);const w={rows:u,fromGridId:r.sourceGridId,toGridId:this.gridId,fromIndices:r.rowIndices,toIndex:d,operation:r.operation};this.emit("row-transfer",w),p?p.emitTransfer(w):function(e){const t=L();if(t)try{t.postMessage(e)}catch{}}({type:"tbw-row-drag-drop:transfer",sessionId:r.sessionId,sourceGridId:r.sourceGridId,toGridId:this.gridId,dropZone:l,rowIndices:r.rowIndices,toIndex:d,operation:r.operation,serializedRows:r.rows})}onRemoteTransfer(e){if(e.sourceGridId!==this.gridId)return;const t=this.config.dropZone??"";if(!t||e.dropZone!==t)return;const r=this.config.deserializeRow??(e=>e),o=e.serializedRows.map(e=>r(e));if("move"===e.operation){const t=(this.internalGrid._rows??this.sourceRows).slice(),r=[...e.rowIndices].sort((e,t)=>t-e);for(const e of r)e>=0&&e<t.length&&t.splice(e,1);this.grid.rows=t}this.dragAccepted=!0,this.emit("row-transfer",{rows:o,fromGridId:e.sourceGridId,toGridId:e.toGridId,fromIndices:e.rowIndices,toIndex:e.toIndex,operation:e.operation})}onDragEnd(){if(this.dragSessionId&&n(this.dragSessionId),y(),this.autoScroller?.stop(),this.gridElement.classList.remove("tbw-grid--drag-source"),this.isDragging){const e={rows:this.draggedRows,indices:this.draggedIndices,accepted:this.dragAccepted};this.emit("row-drag-end",e)}this.clearDragClasses(),this.resetDragState()}emitTransfer(e){this.emit("row-transfer",e)}findPeerOnGrid(e){const t=document.getElementById(e);return t?.getPluginByName?t.getPluginByName("rowDragDrop")??null:null}peersInDropZone(){const e=this.config.dropZone??"";if(!e)return[];const t=[];for(const r of T){const o=r;o!==this&&((o.config.dropZone??"")===e&&t.push(o))}return t}get gridLabel(){const e=this.gridElement;return e?.getAttribute("aria-label")||e?.id||"grid"}openMoveMenu(e){const t=e.closest(".data-grid-row");if(!t)return;const r=this.getRowIndex(t);if(r<0)return;const o=this.internalGrid._rows??this.sourceRows,n=[{label:"Move up",disabled:0===r||!this.canMoveRow(r,r-1),run:()=>this.moveRow(r,r-1)},{label:"Move down",disabled:r>=o.length-1||!this.canMoveRow(r,r+1),run:()=>this.moveRow(r,r+1)},{label:"Move to top",disabled:0===r||!this.canMoveRow(r,0),run:()=>this.moveRow(r,0)},{label:"Move to bottom",disabled:r>=o.length-1||!this.canMoveRow(r,o.length-1),run:()=>this.moveRow(r,o.length-1)}],i="copy"===(this.config.operation??"move")?"Copy to":"Send to";for(const s of this.peersInDropZone())n.push({label:`${i} ${s.gridLabel}`,run:()=>this.transferToPeer(s,r)});this.moveMenu??=S("tbw-row-move-menu","tbw-row-move-menu"),this.moveMenu.open(e,`Move row ${r+1}`,n)}transferToPeer(e,t){const r=this.config.dropZone??"";if(!r)return;const{rows:o,indices:n}=this.resolveDraggedRows(t);if(0===o.length)return;if(this.config.canDrag&&!this.config.canDrag(o[0],t))return;const s=this.config.operation??"move";if(this.emitCancelable("row-drag-start",{rows:o,indices:n,operation:s,dropZone:r}))return;const a=this.config.serializeRow??(e=>e),d={sessionId:i(),sourceGridId:this.gridId,dropZone:r,rows:o.map(a),rowIndices:n,operation:s},c=e.acceptTransfer(d,o);if(c<0)return;if("move"===s){const e=[...this.internalGrid._rows??this.sourceRows];for(const t of[...n].sort((e,t)=>t-e))t>=0&&t<e.length&&e.splice(t,1);this.grid.rows=e}const l={rows:o,fromGridId:this.gridId,toGridId:e.gridId,fromIndices:n,toIndex:c,operation:s};e.emitTransfer(l),this.emit("row-transfer",l)}acceptTransfer(e,t){const r=this.config.dropZone??"";if(!r||r!==e.dropZone)return-1;const o=this.internalGrid._rows??this.sourceRows,n=o.length;if(this.config.canDrop&&!this.config.canDrop(e,n))return-1;const i={payload:e,sourceGridId:e.sourceGridId,targetIndex:n,operation:e.operation};return this.emitCancelable("row-drop",i)?-1:(this.grid.rows=[...o,...t],n)}resolveDraggedRows(e){const t=this.internalGrid._rows??this.sourceRows,r=t[e],o=this.grid?.getPluginByName?.("selection");if(o?.getSelectedRowIndices){const r=o.getSelectedRowIndices();if(r.includes(e)&&r.length>1){const e=[...r].sort((e,t)=>e-t);return{rows:e.map(e=>t[e]),indices:e}}}return{rows:[r],indices:[e]}}ensureAutoScroller(){if(this.autoScroller)return;const e=this.gridElement.querySelector(".rows-viewport");if(!e)return;const t="object"==typeof this.config.autoScroll?this.config.autoScroll:void 0;this.autoScroller=function(e,t={},r){const o=t.edgeSize??60,n=t.speed??8,i=t.maxSpeed??24;let s=null,a=null,d=!1;const c=e=>{e!==d&&(d=e,r?.(e))},l=()=>{if(s=null,null===a)return void c(!1);const t=e.getBoundingClientRect();let r=0;if(a<t.top+o){const e=1-Math.max(0,a-t.top)/o;r=-Math.round(n+(i-n)*e)}else if(a>t.bottom-o){const e=1-Math.max(0,t.bottom-a)/o;r=Math.round(n+(i-n)*e)}if(0===r)return void c(!1);const d=e.scrollTop;e.scrollTop=d+r,e.scrollTop!==d?(c(!0),s=requestAnimationFrame(l)):c(!1)};return{onPointerMove(e){a=e,null===s&&(s=requestAnimationFrame(l))},stop(){null!==s&&(cancelAnimationFrame(s),s=null),a=null,c(!1)},get isScrolling(){return d}}}(e,t,e=>{this.gridElement.classList.toggle("tbw-grid--auto-scrolling",e)})}applyDropPositionClasses(e,t){this.clearDropTargetClasses(),e&&(e.classList.add("drop-target"),e.classList.toggle("drop-before",t),e.classList.toggle("drop-after",!t))}clearDropTargetClasses(){this.gridElement?.querySelectorAll(".data-grid-row.drop-target").forEach(e=>{e.classList.remove("drop-target","drop-before","drop-after")})}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove(t,"drop-target","drop-before","drop-after")})}resetDragState(){this.isDragging=!1,this.draggedRowIndex=null,this.draggedRows=[],this.draggedIndices=[],this.dragSessionId=null,this.dragAccepted=!1,this.dropRowIndex=null,this.pendingMove=null}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}handleKeyboardMove(e,t,r,o){this.pendingMove?this.pendingMove.currentIndex=r:this.pendingMove={originalIndex:t,currentIndex:r,row:e},this.lastFocusCol=o;const n=this.internalGrid,i=[...n._rows??this.sourceRows],[s]=i.splice(t,1);i.splice(r,0,s),n._rows=i,n._focusRow=r,n._focusCol=o,n.refreshVirtualWindow(!0),d(n),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>this.flushPendingMove(),this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:r}=this.pendingMove;if(this.pendingMove=null,e===t)return;const o=this.internalGrid,n={row:r,fromIndex:e,toIndex:t,rows:[...o._rows??this.sourceRows],source:"keyboard"};this.emitCancelable("row-move",n)&&(o._rows=[...this.sourceRows],o._focusRow=e,o._focusCol=this.lastFocusCol,o.refreshVirtualWindow(!0),d(o))}executeIntraGridMove(e,t,r,o){const n=[...this.sourceRows],[i]=n.splice(t,1);n.splice(r,0,i);const s={row:e,fromIndex:t,toIndex:r,rows:n,source:o};if(!this.emitCancelable("row-move",s))if("flip"===this.animationType&&this.gridElement){const e=this.captureRowPositions();this.grid.rows=n,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(e,t,r)})}else this.grid.rows=n}captureRowPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const r=this.getRowIndex(t);r>=0&&e.set(r,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,r){const o=this.gridElement;if(!o||0===e.size)return;const n=Math.min(t,r),i=Math.max(t,r),s=[];if(o.querySelectorAll(".data-grid-row").forEach(o=>{const a=o,d=this.getRowIndex(a);if(d<0||d<n||d>i)return;let c;c=d===r?t:t<r?d+1:d-1;const l=e.get(c);if(void 0===l)return;const g=l-a.getBoundingClientRect().top;Math.abs(g)>1&&s.push({el:a,deltaY:g})}),0===s.length)return;s.forEach(({el:e,deltaY:t})=>{e.style.transform=`translateY(${t}px)`}),o.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{s.forEach(({el:e})=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{s.forEach(({el:e})=>{e.style.transform="",e.classList.remove("flip-animating")})},a+50)})}};export{M as ROW_DRAG_HANDLE_FIELD,G as RowDragDropPlugin};
1
+ var e="editing",t="dragging",r=/* @__PURE__ */new Map;function o(e){const t=r.get(e);if(!t)return;if(t.hasPrimitives)return;const o=[];for(const r of t.refs){const e=r.deref();if(void 0===e)return;o.push(e)}return o}function n(e){r.delete(e)}function i(){if("undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID)return crypto.randomUUID();if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){const e=/* @__PURE__ */new Uint32Array(2);return crypto.getRandomValues(e),`drag-${Date.now().toString(36)}-${e[0].toString(36)}${e[1].toString(36)}`}return`drag-${Date.now().toString(36)}-${(++s).toString(36)}`}var s=0;function a(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,o=t.rawContentHeight-t.viewportHeight;return r<=0||o<=0?e:e*r/o}function d(t,r){!function(e){if(!e._virtualization?.enabled)return;const{rowHeight:t,container:r,viewportEl:o,scrollMapping:n}=e._virtualization,i=r,s=o?.clientHeight??i?.clientHeight??0;if(!i||s<=0)return;const d=e._getVerticalScrollOffsets?.(e._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const c=Math.max(0,d.top),l=s-c-Math.max(0,d.bottom);if(l<=0)return;const g=e._focusRow*t,u=n?function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,o=t.rawContentHeight-t.viewportHeight;if(r<=0||o<=0)return e;const n=e*o/r;return n<0?0:n>o?o:n}(i.scrollTop,n):i.scrollTop;if(g<u+c){const e=Math.max(0,g-c);i.scrollTop=n?a(e,n):e}else if(g+t>u+c+l){const e=Math.max(0,g-l+t-c);i.scrollTop=n?a(e,n):e}}(t);const o=function(e){return void 0!==e._activeEditRows&&-1!==e._activeEditRows}(t)||!!t._isGridEditMode;var n;o||t.refreshVirtualWindow(!1),(n=t._bodyEl)&&n.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const i=function(e){const t=e._focusRow,r=e._virtualization.start??0,o=e._virtualization.end??e._rows.length;if(t<r||t>=o)return;const n=e._bodyEl.querySelectorAll(".data-grid-row")[t-r];let i=n?.children[e._focusCol];return i&&i.classList?.contains("cell")||(i=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),i?{rowEl:n??null,cell:i}:void 0}(t);if(!i)return;const{rowEl:s,cell:d}=i;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),o&&!r?.forceHorizontalScroll||function(e,t,r,o){const n=e.querySelector(".tbw-scroll-area");if(!n)return;if(o?.forceScrollLeft)return void(n.scrollLeft=0);if(o?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const i=e._getHorizontalScrollOffsets?.(t??void 0,r)??{left:0,right:0};if(i.skipScroll)return;const s=r.getBoundingClientRect(),a=n.getBoundingClientRect(),d=s.left-a.left+n.scrollLeft,c=d+s.width,l=n.scrollLeft+i.left,g=n.scrollLeft+n.clientWidth-i.right;d<l?n.scrollLeft=d-i.left:c>g&&(n.scrollLeft=c-n.clientWidth+i.right)}(t,s,d,r),function(t,r,o){if(o&&r.classList.contains(e)){const e=r.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}return}if(o){if(r.contains(document.activeElement))return;r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1");try{r.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,d,o)}var c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function l(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function g(e,t,r,o){return`${l(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var u="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),f=(new RegExp(`__(proto|defineGetter|defineSetter)|${u.slice(3).join("|")}|this\\b`),new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|"))),h=/^on\w+$/i,p=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),w=/^\s*(javascript|vbscript|data|blob):/i;function m(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const o of r){const e=o.tagName.toLowerCase();if(f.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>h.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(o);continue}const r=[];for(const t of o.attributes){const e=t.name.toLowerCase();h.test(e)?r.push(t.name):"is"!==e?(p.has(e)&&w.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name):r.push(t.name)}r.forEach(e=>o.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var b=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,i]of Object.entries(e)){if(void 0===i)continue;if(!(n in t)){t[n]=i,r[n]=o;continue}if(t[n]===i)continue;const e=r[n]?.constructor.name??this.constructor.name,s=o.constructor.name,a=g("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(a)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const o of Object.keys(t))delete t[o];Object.assign(t,r)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const r=this.grid?.query?.(e,t);return Array.isArray(r)?r.some(Boolean):!!r}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...c,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const o=this.#t(t,r);var n,i;void 0!==o?"string"==typeof o?(n=e,(i=o)&&"string"==typeof i?-1!==i.indexOf("<")||-1!==i.indexOf("&")?n.replaceChildren(m(i)):n.textContent=i:n.replaceChildren()):o instanceof HTMLElement&&e.replaceChildren(o.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const o=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return o?e.insertBefore(r,o):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(g(e,t,this.gridElement.id,this.name)):console.warn(`${l(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(g(e,t,this.gridElement.id,this.name))}},v=null;function I(){return v}function y(){v=null}var x="application/x-tbw-grid-rows+json";function R(e){const t=e.match(/^application\/x-tbw-grid-rows\+json;zone=(.*)$/);if(!t)return null;try{return decodeURIComponent(t[1])}catch{return t[1]}}function C(e){return JSON.stringify(e)}function E(e,t,r,o){if(!e)return{overIndex:null,insertIndex:o,isBefore:!1};const n=r(e);if(n<0)return{overIndex:null,insertIndex:o,isBefore:!1};const i=e.getBoundingClientRect(),s=t<i.top+i.height/2;return{overIndex:n,insertIndex:s?n:n+1,isBefore:s}}function D(){return"function"==typeof HTMLElement.prototype?.showPopover}function S(e,t){let r=null,o=!1,n=!1;const i=new AbortController;function s(){o&&r&&(o=!1,D()&&r.hidePopover(),r.hidden=!0)}return document.addEventListener("pointerdown",e=>{o&&r&&!e.composedPath().includes(r)&&s()},{capture:!0,signal:i.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&s()},{capture:!0,signal:i.signal}),{get element(){return r},open(a,d,c){if(n||0===c.length)return;r||(r=function(){const r=document.createElement("div");return r.id=e,r.className=t,r.setAttribute("popover","manual"),r.setAttribute("role","group"),r.hidden=!0,r.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!r.contains(t)&&s()},{signal:i.signal}),r}());const l=a.closest("tbw-grid, [data-tbw-grid]")??document.body;r.parentNode!==l&&l.appendChild(r),r.setAttribute("aria-label",d),r.replaceChildren();for(const e of c){const o=document.createElement("button");o.type="button",o.className=`${t}-item`,o.textContent=e.label,o.disabled=!0===e.disabled,o.addEventListener("click",()=>{s(),e.run()}),r.appendChild(o)}r.hidden=!1,!o&&D()&&r.showPopover(),o=!0,function(e){if(!r)return;const t=e.getBoundingClientRect(),o=r.getBoundingClientRect(),n=Math.max(4,Math.min(t.left,window.innerWidth-o.width-4)),i=t.bottom+6,s=i+o.height<=window.innerHeight?i:Math.max(4,t.top-6-o.height);r.style.left=`${Math.round(n)}px`,r.style.top=`${Math.round(s)}px`}(a),r.querySelector("button:not([disabled])")?.focus()},close:s,dispose(){n=!0,s(),i.abort(),r?.remove(),r=null}}}var M="__tbw_row_drag",A=null,_=/* @__PURE__ */new Set;function L(){if("undefined"==typeof BroadcastChannel)return null;if(A)return A;try{(A=new BroadcastChannel("tbw-row-drag-drop")).addEventListener("message",e=>{const t=e.data;if(t&&"tbw-row-drag-drop:transfer"===t.type)for(const r of Array.from(_))try{r(t)}catch{}})}catch{A=null}return A}var T=/* @__PURE__ */new Set;var G=class e extends b{name="rowDragDrop";styles='@layer tbw-plugins{[data-field=__tbw_row_drag]{justify-content:center;align-items:center;display:flex}.dg-row-drag-handle{cursor:grab;-webkit-user-select:none;user-select:none;min-width:1em;min-height:1em;color:var(--tbw-row-reorder-handle-color,var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration,.12s) var(--tbw-transition-ease,ease);font-size:var(--tbw-font-size,1em);letter-spacing:-2px;justify-content:center;align-items:center;display:flex;position:relative}.dg-row-drag-handle:after{content:"";inline-size:var(--tbw-touch-target-min,24px);block-size:var(--tbw-touch-target-min,24px);position:absolute;inset-block-start:50%;inset-inline-start:50%;translate:-50% -50%}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover,var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}@media (hover:none){.dg-row-drag-handle{color:var(--tbw-row-reorder-handle-hover,var(--tbw-color-fg))}}@media (pointer:coarse){.dg-row-drag-handle{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}.data-grid-row.dragging{opacity:.6}.data-grid-row[draggable=true]{cursor:grab}.data-grid-row[draggable=true].dragging{cursor:grabbing}.tbw-row-drag-clone{pointer-events:none;position:fixed;top:-10000px;left:-10000px}.tbw-row-drag-count{pointer-events:none;background:var(--tbw-row-reorder-indicator,var(--tbw-color-accent));color:var(--tbw-color-accent-fg);box-shadow:0 2px 6px var(--tbw-color-shadow);z-index:9999;border-radius:999px;padding:2px 8px;font:600 12px/1.4 system-ui,sans-serif;position:fixed;top:-1000px;left:-1000px}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before,.data-grid-row.drop-target.drop-after:after{content:"";height:var(--tbw-drop-indicator-width,2px);background-color:var(--tbw-drop-indicator-color,var(--tbw-row-reorder-indicator,var(--tbw-color-accent)));z-index:10;pointer-events:none;position:absolute;left:0;right:0}.data-grid-row.drop-target.drop-before:before{top:0}.data-grid-row.drop-target.drop-after:after{bottom:0}.tbw-grid--drop-target-active{outline:2px dashed var(--tbw-drop-indicator-color,var(--tbw-color-accent));outline-offset:-2px}.tbw-grid--drop-target-rejected{outline:2px dashed var(--tbw-color-danger);outline-offset:-2px}.tbw-grid--auto-scrolling{cursor:ns-resize}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration,.2s) ease-out;will-change:transform;z-index:1}.tbw-row-move-menu{min-width:10rem;padding:var(--tbw-spacing-xs,.25rem);background:var(--tbw-color-panel-bg,light-dark(#fff,#1f1f1f));color:var(--tbw-color-fg,light-dark(#1a1a1a,#f0f0f0));border:1px solid var(--tbw-color-border,light-dark(#d0d0d0,#3a3a3a));border-radius:var(--tbw-border-radius,.25rem);box-shadow:var(--tbw-shadow-md,0 4px 12px #00000040);font:inherit;z-index:10001;flex-direction:column;margin:0;display:flex;position:fixed}.tbw-row-move-menu[hidden]{display:none}.tbw-row-move-menu-item{min-height:var(--tbw-touch-target-min,24px);padding:var(--tbw-spacing-xs,.25rem) var(--tbw-spacing-sm,.5rem);text-align:start;border-radius:min(var(--tbw-border-radius,.25rem), 6px);color:inherit;font:inherit;cursor:pointer;background:0 0;border:none}.tbw-row-move-menu-item:hover:not(:disabled){background:var(--tbw-color-row-hover,light-dark(#f0f0f0,#2a2a2a))}.tbw-row-move-menu-item:disabled{opacity:.5;cursor:default}}';static manifest={events:[{type:"row-move",description:"Intra-grid row reorder.",cancelable:!0},{type:"row-drag-start",description:"Cross-grid drag started on this grid.",cancelable:!0},{type:"row-drag-end",description:"Drag finished on this grid (regardless of outcome)."},{type:"row-drop",description:"Cross-grid drop landing on this grid.",cancelable:!0},{type:"row-transfer",description:"Cross-grid transfer completed (fires on both grids)."}]};get defaultConfig(){return{enableKeyboard:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip",operation:"move",autoScroll:!0,dragFrom:"handle"}}shouldRenderDragHandle(){const e=this.config.showDragHandle;return!1!==e&&(!0===e||"row"!==this.config.dragFrom)}get rowIsDraggable(){return"row"===this.config.dragFrom||"both"===this.config.dragFrom}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}isDragging=!1;draggedRowIndex=null;draggedRows=[];draggedIndices=[];dragSessionId=null;dragAccepted=!1;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;autoScroller=null;gridId="";remoteTransferListener=e=>this.onRemoteTransfer(e);moveMenu=null;get internalGrid(){return this.grid}attach(e){super.attach(e);const t=this.gridElement;var r;t&&(this.gridId=t.id||`tbw-grid-${i().slice(0,8)}`,t.id||(t.id=this.gridId),this.setupDelegatedDragListeners(),r=this.remoteTransferListener,_.add(r),L(),T.add(this))}detach(){this.clearDebounceTimer(),this.autoScroller?.stop(),this.autoScroller=null,function(e){if(_.delete(e),0===_.size&&A){try{A.close()}catch{}A=null}}(this.remoteTransferListener),T.delete(this),this.moveMenu?.dispose(),this.moveMenu=null,this.dragSessionId&&n(this.dragSessionId),y(),this.resetDragState(),super.detach()}processColumns(e){if(!this.shouldRenderDragHandle())return[...e];const t={field:M,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,lockPosition:!0,utility:!0,viewRenderer:()=>{const e=document.createElement("div");return e.className="dg-row-drag-handle",e.setAttribute("aria-label","Drag to reorder, or activate for move options"),e.setAttribute("role","button"),e.setAttribute("tabindex","-1"),e.draggable=!0,e.addEventListener("click",t=>{t.stopPropagation(),this.openMoveMenu(e)}),this.setIcon(e,"dragHandle"),e}};return"right"===this.config.dragHandlePosition?[...e,t]:[t,...e]}afterRender(){this.applyRowDraggable()}onScrollRender(){this.applyRowDraggable()}applyRowDraggable(){const e=this.internalGrid._bodyEl;if(!e)return;const t=this.rowIsDraggable,r=e.querySelectorAll(".data-grid-row");for(const o of r)t?"true"!==o.getAttribute("draggable")&&o.setAttribute("draggable","true"):o.hasAttribute("draggable")&&o.removeAttribute("draggable")}onKeyDown(e){if(!this.config.enableKeyboard)return;if(!e.ctrlKey||"ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;const t=this.internalGrid,r=t._focusRow,o=t._rows??this.sourceRows;if(r<0||r>=o.length)return;const n="up"==("ArrowUp"===e.key?"up":"down")?r-1:r+1;if(n<0||n>=o.length)return;const i=o[r];return this.canMoveRow(r,n)?(this.handleKeyboardMove(i,r,n,t._focusCol),e.preventDefault(),e.stopPropagation(),!0):void 0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const r=[...this.sourceRows];e<0||e>=r.length||t<0||t>=r.length||e!==t&&this.canMoveRow(e,t)&&this.executeIntraGridMove(r[e],e,t,"keyboard")}canMoveRow(e,t){const r=this.internalGrid._rows??this.sourceRows;if(e<0||e>=r.length)return!1;if(t<0||t>=r.length)return!1;if(e===t)return!1;const o=r[e],n=this.grid?.query?.("canMoveRow",o);if(Array.isArray(n)&&n.includes(!1))return!1;if(this.config.canDrag&&!this.config.canDrag(o,e))return!1;if(this.config.canDrop){const r={sessionId:"intra",sourceGridId:this.gridId,dropZone:this.config.dropZone??"",rows:[o],rowIndices:[e],operation:"move"};if(!this.config.canDrop(r,t))return!1}return!0}setupDelegatedDragListeners(){const e=this.gridElement;if(!e)return;const t=this.disconnectSignal;e.addEventListener("dragstart",e=>this.onDragStart(e),{signal:t}),e.addEventListener("dragend",()=>this.onDragEnd(),{signal:t}),e.addEventListener("dragover",e=>this.onDragOver(e),{signal:t}),e.addEventListener("dragleave",e=>this.onDragLeave(e),{signal:t}),e.addEventListener("drop",e=>this.onDrop(e),{signal:t})}onDragStart(e){const o=e.target;if(!o)return;const n=o.closest(".dg-row-drag-handle");let s=null,a=!1;if(n)s=n.closest(".data-grid-row"),a=!0;else if(this.rowIsDraggable){if(this.isInteractiveDragOrigin(o))return;s=o.closest(".data-grid-row")}if(!s)return;const d=this.getRowIndex(s);if(d<0)return;const{rows:c,indices:l}=this.resolveDraggedRows(d);if(0===c.length)return;if(this.config.canDrag&&!this.config.canDrag(c[0],d))return void e.preventDefault();const g=this.config.operation??"move",u=this.config.dropZone??"",f=i(),h={rows:c,indices:l,operation:g,dropZone:u};if(this.emitCancelable("row-drag-start",h))return void e.preventDefault();this.isDragging=!0,this.draggedRowIndex=d,this.draggedRows=c,this.draggedIndices=l,this.dragSessionId=f,this.dragAccepted=!1;const p=this.config.serializeRow??(e=>e),w={sessionId:f,sourceGridId:this.gridId,dropZone:u,rows:c.map(p),rowIndices:l,operation:g};if(e.dataTransfer){e.dataTransfer.effectAllowed="copy"===g?"copyMove":"move";try{e.dataTransfer.setData(x,C(w)),u&&e.dataTransfer.setData(`${x};zone=${encodeURIComponent(u)}`,C(w)),e.dataTransfer.setData("text/plain",function(e,t){const r=t.filter(e=>!e.utility&&"string"==typeof e.field&&""!==e.field),o=[];for(const n of e){const e=r.map(e=>{const t=n[e.field];return null==t?"":String(t).replace(/[\t\r\n]+/g," ")});o.push(e.join("\t"))}return o.join("\n")}(c,this.columns))}catch{}if(c.length>1){const t=document.createElement("div");t.className="tbw-row-drag-count",t.textContent=`${c.length} rows`,document.body.appendChild(t);try{e.dataTransfer.setDragImage(t,10,10)}catch{}setTimeout(()=>t.remove(),0)}else this.attachRowCloneDragImage(e,s,a?n:null)}!function(e,t){const o=[];let n=!1;for(const r of t)null!==r&&"object"==typeof r?o.push(new WeakRef(r)):n=!0;r.set(e,{refs:o,hasPrimitives:n})}(f,c),function(e,t){v={sessionId:e,payload:t}}(f,w),s.classList.add(t),this.gridElement.classList.add("tbw-grid--drag-source")}static INTERACTIVE_DRAG_SELECTORS='input,textarea,select,button,a,[contenteditable=""],[contenteditable="true"],.dg-cell-editor,.tbw-checkbox-cell';isInteractiveDragOrigin(t){return null!==t.closest(e.INTERACTIVE_DRAG_SELECTORS)}attachRowCloneDragImage(e,t,r){if(!e.dataTransfer)return;const o=t.getBoundingClientRect(),n=t.cloneNode(!0);n.classList.add("tbw-row-drag-clone"),n.classList.remove("dragging","drop-target","drop-before","drop-after","flip-animating","row-focus"),n.removeAttribute("aria-selected"),n.style.width=`${o.width}px`,n.style.height=`${o.height}px`,this.gridElement.appendChild(n);let i=e.clientX-o.left,s=e.clientY-o.top;if(r){const e=r.getBoundingClientRect();i=e.left-o.left+e.width/2,s=e.top-o.top+e.height/2}i=Math.max(0,Math.min(o.width,i)),s=Math.max(0,Math.min(o.height,s));try{e.dataTransfer.setDragImage(n,i,s)}catch{}setTimeout(()=>n.remove(),0)}onDragOver(e){const t=e.dataTransfer;if(!t)return;const r=t.types?Array.from(t.types):[];if(!function(e){for(const t of e)if("application/x-tbw-grid-rows+json"===t||t.startsWith("application/x-tbw-grid-rows+json;"))return!0;return!1}(r)&&!this.isDragging)return;const o=this.config.dropZone??"",n=I(),i=this.isDragging&&n?.payload.sourceGridId===this.gridId;if(!i){if(!o)return;if(!(function(e,t){for(const r of e)if(R(r)===t)return r;return null}(r,o)||n&&n.payload.dropZone===o))return}e.preventDefault(),t&&(t.dropEffect=n?.payload.operation??this.config.operation??"move");const s=e.target.closest(".data-grid-row"),a=this.internalGrid._rows??[],d=E(s,e.clientY,e=>this.getRowIndex(e),a.length);if(i&&null!==d.overIndex&&d.overIndex===this.draggedRowIndex)this.clearDropTargetClasses();else{if(n&&this.config.canDrop){const e=this.config.canDrop(n.payload,d.insertIndex);if(this.gridElement.classList.toggle("tbw-grid--drop-target-active",e),this.gridElement.classList.toggle("tbw-grid--drop-target-rejected",!e),!e)return void this.clearDropTargetClasses()}else this.gridElement.classList.add("tbw-grid--drop-target-active");this.dropRowIndex=d.insertIndex,this.applyDropPositionClasses(s,d.isBefore),!1!==this.config.autoScroll&&(this.ensureAutoScroller(),this.autoScroller?.onPointerMove(e.clientY))}}onDragLeave(e){const t=e.target.closest(".data-grid-row");t&&t.classList.remove("drop-target","drop-before","drop-after"),e.currentTarget&&!this.gridElement.contains(e.relatedTarget)&&(this.gridElement.classList.remove("tbw-grid--drop-target-active","tbw-grid--drop-target-rejected"),this.autoScroller?.stop())}onDrop(e){e.preventDefault(),this.autoScroller?.stop(),this.gridElement.classList.remove("tbw-grid--drop-target-active","tbw-grid--drop-target-rejected"),this.clearDropTargetClasses();const t=e.dataTransfer;if(!t)return;let r=I()?.payload??null,n=null;if(r){const e=o(r.sessionId);e&&(n=e)}else{if(r=function(e){if(!e)return null;try{const t=JSON.parse(e);if("string"!=typeof t?.sessionId||"string"!=typeof t?.sourceGridId||"string"!=typeof t?.dropZone||!Array.isArray(t?.rows)||!Array.isArray(t?.rowIndices)||"move"!==t.operation&&"copy"!==t.operation)return null;for(const e of t.rowIndices)if("number"!=typeof e||!Number.isInteger(e)||e<0)return null;return t}catch{return null}}(t.getData(x)),r){const e=o(r.sessionId);e&&(n=e)}}if(!r)return;const i=e.target.closest(".data-grid-row"),s=this.internalGrid._rows??[],a=E(i,e.clientY,e=>this.getRowIndex(e),s.length);let d=this.dropRowIndex??a.insertIndex;const c=r.sourceGridId===this.gridId,l=this.config.dropZone??"";if(c){const e=r.rowIndices[0];if(1===r.rowIndices.length&&d>e&&d--,e===d)return;const t=(n??r.rows)[0];if(!this.canMoveRow(e,d))return;return void this.executeIntraGridMove(t,e,d,"drag")}if(!l||l!==r.dropZone)return;if(this.config.canDrop&&!this.config.canDrop(r,d))return this.gridElement.classList.add("tbw-grid--drop-target-rejected"),void setTimeout(()=>this.gridElement.classList.remove("tbw-grid--drop-target-rejected"),200);const g=this.config.deserializeRow??(e=>e),u=n??r.rows.map(e=>g(e)),f={payload:r,sourceGridId:r.sourceGridId,targetIndex:d,operation:r.operation};if(this.emitCancelable("row-drop",f))return;const h=[...s];h.splice(d,0,...u),this.grid.rows=h;const p=this.findPeerOnGrid(r.sourceGridId);if("move"===r.operation&&p){const e=document.getElementById(r.sourceGridId);if(e){const t=(e._rows??e.rows??[]).slice(),o=[...r.rowIndices].sort((e,t)=>t-e);for(const e of o)e>=0&&e<t.length&&t.splice(e,1);e.rows=t}}p&&(p.dragAccepted=!0);const w={rows:u,fromGridId:r.sourceGridId,toGridId:this.gridId,fromIndices:r.rowIndices,toIndex:d,operation:r.operation};this.emit("row-transfer",w),p?p.emitTransfer(w):function(e){const t=L();if(t)try{t.postMessage(e)}catch{}}({type:"tbw-row-drag-drop:transfer",sessionId:r.sessionId,sourceGridId:r.sourceGridId,toGridId:this.gridId,dropZone:l,rowIndices:r.rowIndices,toIndex:d,operation:r.operation,serializedRows:r.rows})}onRemoteTransfer(e){if(e.sourceGridId!==this.gridId)return;const t=this.config.dropZone??"";if(!t||e.dropZone!==t)return;const r=this.config.deserializeRow??(e=>e),o=e.serializedRows.map(e=>r(e));if("move"===e.operation){const t=(this.internalGrid._rows??this.sourceRows).slice(),r=[...e.rowIndices].sort((e,t)=>t-e);for(const e of r)e>=0&&e<t.length&&t.splice(e,1);this.grid.rows=t}this.dragAccepted=!0,this.emit("row-transfer",{rows:o,fromGridId:e.sourceGridId,toGridId:e.toGridId,fromIndices:e.rowIndices,toIndex:e.toIndex,operation:e.operation})}onDragEnd(){if(this.dragSessionId&&n(this.dragSessionId),y(),this.autoScroller?.stop(),this.gridElement.classList.remove("tbw-grid--drag-source"),this.isDragging){const e={rows:this.draggedRows,indices:this.draggedIndices,accepted:this.dragAccepted};this.emit("row-drag-end",e)}this.clearDragClasses(),this.resetDragState()}emitTransfer(e){this.emit("row-transfer",e)}findPeerOnGrid(e){const t=document.getElementById(e);return t?.getPluginByName?t.getPluginByName("rowDragDrop")??null:null}peersInDropZone(){const e=this.config.dropZone??"";if(!e)return[];const t=[];for(const r of T){const o=r;o!==this&&((o.config.dropZone??"")===e&&t.push(o))}return t}get gridLabel(){const e=this.gridElement;return e?.getAttribute("aria-label")||e?.id||"grid"}openMoveMenu(e){const t=e.closest(".data-grid-row");if(!t)return;const r=this.getRowIndex(t);if(r<0)return;const o=this.internalGrid._rows??this.sourceRows,n=[{label:"Move up",disabled:0===r||!this.canMoveRow(r,r-1),run:()=>this.moveRow(r,r-1)},{label:"Move down",disabled:r>=o.length-1||!this.canMoveRow(r,r+1),run:()=>this.moveRow(r,r+1)},{label:"Move to top",disabled:0===r||!this.canMoveRow(r,0),run:()=>this.moveRow(r,0)},{label:"Move to bottom",disabled:r>=o.length-1||!this.canMoveRow(r,o.length-1),run:()=>this.moveRow(r,o.length-1)}],i="copy"===(this.config.operation??"move")?"Copy to":"Send to";for(const s of this.peersInDropZone())n.push({label:`${i} ${s.gridLabel}`,run:()=>this.transferToPeer(s,r)});this.moveMenu??=S("tbw-row-move-menu","tbw-row-move-menu"),this.moveMenu.open(e,`Move row ${r+1}`,n)}transferToPeer(e,t){const r=this.config.dropZone??"";if(!r)return;const{rows:o,indices:n}=this.resolveDraggedRows(t);if(0===o.length)return;if(this.config.canDrag&&!this.config.canDrag(o[0],t))return;const s=this.config.operation??"move";if(this.emitCancelable("row-drag-start",{rows:o,indices:n,operation:s,dropZone:r}))return;const a=this.config.serializeRow??(e=>e),d={sessionId:i(),sourceGridId:this.gridId,dropZone:r,rows:o.map(a),rowIndices:n,operation:s},c=e.acceptTransfer(d,o);if(c<0)return;if("move"===s){const e=[...this.internalGrid._rows??this.sourceRows];for(const t of[...n].sort((e,t)=>t-e))t>=0&&t<e.length&&e.splice(t,1);this.grid.rows=e}const l={rows:o,fromGridId:this.gridId,toGridId:e.gridId,fromIndices:n,toIndex:c,operation:s};e.emitTransfer(l),this.emit("row-transfer",l)}acceptTransfer(e,t){const r=this.config.dropZone??"";if(!r||r!==e.dropZone)return-1;const o=this.internalGrid._rows??this.sourceRows,n=o.length;if(this.config.canDrop&&!this.config.canDrop(e,n))return-1;const i={payload:e,sourceGridId:e.sourceGridId,targetIndex:n,operation:e.operation};return this.emitCancelable("row-drop",i)?-1:(this.grid.rows=[...o,...t],n)}resolveDraggedRows(e){const t=this.internalGrid._rows??this.sourceRows,r=t[e],o=this.grid?.getPluginByName?.("selection");if(o?.getSelectedRowIndices){const r=o.getSelectedRowIndices();if(r.includes(e)&&r.length>1){const e=[...r].sort((e,t)=>e-t);return{rows:e.map(e=>t[e]),indices:e}}}return{rows:[r],indices:[e]}}ensureAutoScroller(){if(this.autoScroller)return;const e=this.gridElement.querySelector(".rows-viewport");if(!e)return;const t="object"==typeof this.config.autoScroll?this.config.autoScroll:void 0;this.autoScroller=function(e,t={},r){const o=t.edgeSize??60,n=t.speed??8,i=t.maxSpeed??24;let s=null,a=null,d=!1;const c=e=>{e!==d&&(d=e,r?.(e))},l=()=>{if(s=null,null===a)return void c(!1);const t=e.getBoundingClientRect();let r=0;if(a<t.top+o){const e=1-Math.max(0,a-t.top)/o;r=-Math.round(n+(i-n)*e)}else if(a>t.bottom-o){const e=1-Math.max(0,t.bottom-a)/o;r=Math.round(n+(i-n)*e)}if(0===r)return void c(!1);const d=e.scrollTop;e.scrollTop=d+r,e.scrollTop!==d?(c(!0),s=requestAnimationFrame(l)):c(!1)};return{onPointerMove(e){a=e,null===s&&(s=requestAnimationFrame(l))},stop(){null!==s&&(cancelAnimationFrame(s),s=null),a=null,c(!1)},get isScrolling(){return d}}}(e,t,e=>{this.gridElement.classList.toggle("tbw-grid--auto-scrolling",e)})}applyDropPositionClasses(e,t){this.clearDropTargetClasses(),e&&(e.classList.add("drop-target"),e.classList.toggle("drop-before",t),e.classList.toggle("drop-after",!t))}clearDropTargetClasses(){this.gridElement?.querySelectorAll(".data-grid-row.drop-target").forEach(e=>{e.classList.remove("drop-target","drop-before","drop-after")})}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove(t,"drop-target","drop-before","drop-after")})}resetDragState(){this.isDragging=!1,this.draggedRowIndex=null,this.draggedRows=[],this.draggedIndices=[],this.dragSessionId=null,this.dragAccepted=!1,this.dropRowIndex=null,this.pendingMove=null}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}handleKeyboardMove(e,t,r,o){this.pendingMove?this.pendingMove.currentIndex=r:this.pendingMove={originalIndex:t,currentIndex:r,row:e},this.lastFocusCol=o;const n=this.internalGrid,i=[...n._rows??this.sourceRows],[s]=i.splice(t,1);i.splice(r,0,s),n._rows=i,n._focusRow=r,n._focusCol=o,n.refreshVirtualWindow(!0),d(n),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>this.flushPendingMove(),this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:e,currentIndex:t,row:r}=this.pendingMove;if(this.pendingMove=null,e===t)return;const o=this.internalGrid,n={row:r,fromIndex:e,toIndex:t,rows:[...o._rows??this.sourceRows],source:"keyboard"};this.emitCancelable("row-move",n)&&(o._rows=[...this.sourceRows],o._focusRow=e,o._focusCol=this.lastFocusCol,o.refreshVirtualWindow(!0),d(o))}executeIntraGridMove(e,t,r,o){const n=[...this.sourceRows],[i]=n.splice(t,1);n.splice(r,0,i);const s={row:e,fromIndex:t,toIndex:r,rows:n,source:o};if(!this.emitCancelable("row-move",s))if("flip"===this.animationType&&this.gridElement){const e=this.captureRowPositions();this.grid.rows=n,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(e,t,r)})}else this.grid.rows=n}captureRowPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const r=this.getRowIndex(t);r>=0&&e.set(r,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,r){const o=this.gridElement;if(!o||0===e.size)return;const n=Math.min(t,r),i=Math.max(t,r),s=[];if(o.querySelectorAll(".data-grid-row").forEach(o=>{const a=o,d=this.getRowIndex(a);if(d<0||d<n||d>i)return;let c;c=d===r?t:t<r?d+1:d-1;const l=e.get(c);if(void 0===l)return;const g=l-a.getBoundingClientRect().top;Math.abs(g)>1&&s.push({el:a,deltaY:g})}),0===s.length)return;s.forEach(({el:e,deltaY:t})=>{e.style.transform=`translateY(${t}px)`}),o.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{s.forEach(({el:e})=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{s.forEach(({el:e})=>{e.style.transform="",e.classList.remove("flip-animating")})},a+50)})}};export{M as ROW_DRAG_HANDLE_FIELD,G as RowDragDropPlugin};
2
2
  //# sourceMappingURL=index.js.map