@toolbox-web/grid 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/features/registry.js +1 -1
  6. package/lib/plugins/clipboard/index.js +1 -1
  7. package/lib/plugins/column-virtualization/index.js +1 -1
  8. package/lib/plugins/context-menu/index.js +1 -1
  9. package/lib/plugins/editing/index.js +1 -1
  10. package/lib/plugins/editing/index.js.map +1 -1
  11. package/lib/plugins/export/index.js +1 -1
  12. package/lib/plugins/filtering/index.js +1 -1
  13. package/lib/plugins/filtering/index.js.map +1 -1
  14. package/lib/plugins/grouping-columns/index.js +1 -1
  15. package/lib/plugins/grouping-rows/index.js +1 -1
  16. package/lib/plugins/master-detail/index.js +1 -1
  17. package/lib/plugins/multi-sort/index.js +1 -1
  18. package/lib/plugins/pinned-columns/index.js +1 -1
  19. package/lib/plugins/pinned-rows/index.js +1 -1
  20. package/lib/plugins/pivot/index.js +1 -1
  21. package/lib/plugins/print/index.js +1 -1
  22. package/lib/plugins/print/index.js.map +1 -1
  23. package/lib/plugins/reorder-columns/index.js +1 -1
  24. package/lib/plugins/responsive/index.js +1 -1
  25. package/lib/plugins/responsive/index.js.map +1 -1
  26. package/lib/plugins/row-drag-drop/index.js +1 -1
  27. package/lib/plugins/selection/index.js +1 -1
  28. package/lib/plugins/selection/index.js.map +1 -1
  29. package/lib/plugins/server-side/index.js +1 -1
  30. package/lib/plugins/shell/index.js +1 -1
  31. package/lib/plugins/sticky-rows/index.js +1 -1
  32. package/lib/plugins/tooltip/index.js +1 -1
  33. package/lib/plugins/tooltip/index.js.map +1 -1
  34. package/lib/plugins/tree/index.js +1 -1
  35. package/lib/plugins/undo-redo/index.js +1 -1
  36. package/lib/plugins/visibility/index.js +1 -1
  37. package/package.json +1 -1
  38. package/umd/grid.all.umd.js +1 -1
  39. package/umd/grid.all.umd.js.map +1 -1
  40. package/umd/grid.umd.js +1 -1
  41. package/umd/grid.umd.js.map +1 -1
  42. package/umd/plugins/editing.umd.js +1 -1
  43. package/umd/plugins/editing.umd.js.map +1 -1
  44. package/umd/plugins/filtering.umd.js +1 -1
  45. package/umd/plugins/filtering.umd.js.map +1 -1
  46. package/umd/plugins/print.umd.js +1 -1
  47. package/umd/plugins/print.umd.js.map +1 -1
  48. package/umd/plugins/responsive.umd.js +1 -1
  49. package/umd/plugins/responsive.umd.js.map +1 -1
  50. package/umd/plugins/selection.umd.js +1 -1
  51. package/umd/plugins/selection.umd.js.map +1 -1
  52. package/umd/plugins/tooltip.umd.js +1 -1
  53. package/umd/plugins/tooltip.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- var e="editing",t="dragging";function r(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;return r<=0||i<=0?e:e*r/i}function i(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,r,n){return`${i(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var o="__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("")),s=(new RegExp(`__(proto|defineGetter|defineSetter)|${o.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".split("|"))),a=/^on\w+$/i,l=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function c(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const i of r){const e=i.tagName.toLowerCase();if(s.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const r=[];for(const t of i.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):(l.has(e)&&d.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var u={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var g=class{static dependencies;static manifest;aliases;version="3.0.0";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 i of Object.keys(t))r[i]=this;for(const i of e){const e=i.userConfig;for(const[o,s]of Object.entries(e)){if(void 0===s)continue;if(!(o in t)){t[o]=s,r[o]=i;continue}if(t[o]===s)continue;const e=r[o]?.constructor.name??this.constructor.name,a=i.constructor.name,l=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const i of Object.keys(t))delete t[i];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)}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{...u,...e}}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 i=this.#t(t,r);void 0!==i?"string"==typeof i?e.innerHTML=c(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.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 i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(r,i):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${i(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}};function f(e){if(!0===e.lockPosition)return!1;if(!0===e.utility)return!1;const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}function h(e,t,r){if(t===r)return e;if(t<0||t>=e.length)return e;if(r<0||r>e.length)return e;const i=[...e],[n]=i.splice(t,1);return i.splice(r,0,n),i}var m="canMoveColumn",p=class extends g{name="reorderColumns";aliases=["reorder"];styles='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;left:0}.header-row>.cell.drop-after:after{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;right:0}.cell.flip-animating{transition:transform var(--tbw-animation-duration,.2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration,.2s) ease-out backwards}}';static manifest={queries:[{type:m,description:"Authoritative check for whether a column may be reordered (honors lockPosition)."}]};handleQuery(e){if(e.type===m){const t=e.context;return t?f(t):void 0}}get defaultConfig(){return{animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}get animationDuration(){return void 0!==this.config.animationDuration?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupFields=[];originalColumnOrder=null;get#r(){return this.grid}canMoveColumnWithPlugins(e){return!(!e||!f(e))&&!this.grid.query(m,e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell, .header-group-row > .cell").forEach(e=>{e.classList.remove(t,"drop-target","drop-before","drop-after")})}attach(e){super.attach(e),this.gridElement.addEventListener("column-reorder-request",e=>{const t=e.detail;t?.field&&"number"==typeof t.toIndex&&this.moveColumn(t.field,t.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[]}afterRender(){const e=this.gridElement;e&&(this.originalColumnOrder||(this.originalColumnOrder=this.columns.map(e=>e.field)),e.querySelectorAll(".header-row > .cell").forEach(e=>{const r=e,i=r.getAttribute("data-field");if(!i)return;const n=this.columns.find(e=>e.field===i);this.canMoveColumnWithPlugins(n)?(r.draggable=!0,r.getAttribute("data-dragstart-bound")||(r.setAttribute("data-dragstart-bound","true"),r.addEventListener("dragstart",e=>{const n=this.getColumnOrder().indexOf(i);this.isDragging=!0,this.draggedField=i,this.draggedIndex=n,this.draggedGroupFields=[],e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",i)),r.classList.add(t)}),r.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),r.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedField===i&&0===this.draggedGroupFields.length)return;if(this.draggedGroupFields.includes(i))return;const n=r.getBoundingClientRect(),o=n.left+n.width/2,s=this.getColumnOrder().indexOf(i);if(this.dropIndex=e.clientX<o?s:s+1,this.clearDragClasses(),this.draggedGroupFields.length>0)for(const r of this.draggedGroupFields)this.gridElement?.querySelector(`.header-row > .cell[data-field="${r}"]`)?.classList.add(t);else this.draggedField&&this.gridElement?.querySelector(`.header-row > .cell[data-field="${this.draggedField}"]`)?.classList.add(t);r.classList.add("drop-target"),r.classList.toggle("drop-before",e.clientX<o),r.classList.toggle("drop-after",e.clientX>=o)}),r.addEventListener("dragleave",()=>{r.classList.remove("drop-target","drop-before","drop-after")}),r.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.includes(i))return;const t=r.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;return void this.executeGroupBlockMove(this.draggedGroupFields,[i],n)}const t=this.draggedField,n=this.draggedIndex,o=this.dropIndex;if(!this.isDragging||null===t||null===n||null===o)return;const s=o>n?o-1:o,a=h(this.getColumnOrder(),n,s),l={field:t,fromIndex:n,toIndex:s,columnOrder:a};this.emitCancelable("column-move",l)||this.updateColumnOrder(a)}))):r.draggable=!1}),queueMicrotask(()=>this.setupGroupHeaderDrag(e)))}setupGroupHeaderDrag(e){e.querySelectorAll(".header-group-row > .cell[data-group]").forEach(r=>{const i=r,n=i.getAttribute("data-group");if(!n||n.startsWith("__implicit__"))return;if(i.getAttribute("data-group-drag-bound"))return;i.setAttribute("data-group-drag-bound","true");const o=this.getGroupFragmentFields(i,n);0!==o.length&&o.every(e=>{const t=this.columns.find(t=>t.field===e);return this.canMoveColumnWithPlugins(t)})&&(i.draggable=!0,i.style.cursor="grab",i.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=null,this.draggedIndex=null,this.draggedGroupFields=[...o],r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",`group:${n}`)),i.classList.add(t);for(const i of o)e.querySelector(`.header-row > .cell[data-field="${i}"]`)?.classList.add(t)}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),i.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0&&this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;const t=i.getBoundingClientRect(),r=t.left+t.width/2,n=e.clientX<r;this.clearDragClasses(),i.classList.add("drop-target"),i.classList.toggle("drop-before",n),i.classList.toggle("drop-after",!n)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;const t=i.getBoundingClientRect(),r=e.clientX<t.left+t.width/2;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;this.executeGroupBlockMove(this.draggedGroupFields,o,r)}else if(this.draggedField){const e=this.getColumnOrder(),t=r?o[0]:o[o.length-1],i=e.indexOf(this.draggedField),n=r?e.indexOf(t):e.indexOf(t)+1;if(-1===i||-1===n)return;const s=n>i?n-1:n,a=h(e,i,s);this.emitCancelable("column-move",{field:this.draggedField,fromIndex:i,toIndex:s,columnOrder:a})||this.updateColumnOrder(a)}}))})}getGroupFragmentFields(e,t){const r=e.style.gridColumn,i=/(\d+)\s*\/\s*span\s+(\d+)/.exec(r);if(!i)return[];const n=parseInt(i[1],10),o=parseInt(i[2],10),s=this.visibleColumns,a=[];for(let l=n-1;l<n-1+o&&l<s.length;l++){const e=s[l];e&&a.push(e.field)}return a}executeGroupBlockMove(e,t,r){const i=this.getColumnOrder(),n=i.filter(t=>!e.includes(t)),o=r?t[0]:t[t.length-1],s=n.indexOf(o);if(-1===s)return;const a=r?s:s+1,l=i.filter(t=>e.includes(t));n.splice(a,0,...l),this.emitCancelable("column-move",{field:e[0],fromIndex:i.indexOf(e[0]),toIndex:a,columnOrder:n})||this.updateColumnOrder(n)}onKeyDown(t){if(!t.altKey||"ArrowLeft"!==t.key&&"ArrowRight"!==t.key)return;const i=this.#r,n=i._focusCol,o=i._visibleColumns;if(n<0||n>=o.length)return;const s=o[n];if(!this.canMoveColumnWithPlugins(s))return;const a=this.getColumnOrder(),l=a.indexOf(s.field);if(-1===l)return;const d="ArrowLeft"===t.key?l-1:l+1;if(d<0||d>=a.length)return;const c=o.find(e=>e.field===a[d]);return this.canMoveColumnWithPlugins(c)?(this.moveColumn(s.field,d),i._focusCol=d,function(t,i){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:n,scrollMapping:o}=t._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(s&&a>0){const i=t._focusRow*e,n=o?function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;if(r<=0||i<=0)return e;const n=e*i/r;return n<0?0:n>i?i:n}(s.scrollTop,o):s.scrollTop;if(i<n)s.scrollTop=o?r(i,o):i;else if(i+e>n+a){const t=i-a+e;s.scrollTop=o?r(t,o):t}}}const n=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.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 s=t._focusRow,a=t._virtualization.start??0,l=t._virtualization.end??t._rows.length;if(s>=a&&s<l){const r=t._bodyEl.querySelectorAll(".data-grid-row")[s-a];let o=r?.children[t._focusCol];if(o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const s=t.querySelector(".tbw-scroll-area");if(s&&o&&(!n||i?.forceHorizontalScroll))if(i?.forceScrollLeft)s.scrollLeft=0;else if(i?.forceScrollRight)s.scrollLeft=s.scrollWidth-s.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(r??void 0,o)??{left:0,right:0};if(!e.skipScroll){const t=o.getBoundingClientRect(),r=s.getBoundingClientRect(),i=t.left-r.left+s.scrollLeft,n=i+t.width,a=s.scrollLeft+e.left,l=s.scrollLeft+s.clientWidth-e.right;i<a?s.scrollLeft=i-e.left:n>l&&(s.scrollLeft=n-s.clientWidth+e.right)}}if(n&&o.classList.contains(e)){const e=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(n&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!n){const e=document.activeElement;e instanceof HTMLElement&&e!==t&&"function"==typeof t.contains&&t.contains(e)&&!e.classList.contains("cell")&&!e.closest(".cell")||e===t||t.focus({preventScroll:!0})}}}}(this.#r),t.preventDefault(),t.stopPropagation(),!0):void 0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const r=this.getColumnOrder(),i=r.indexOf(e);if(-1===i)return;const n=h(r,i,t);this.emitCancelable("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder:n})||this.updateColumnOrder(n)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.originalColumnOrder??this.columns.map(e=>e.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const r=t.getAttribute("data-field");r&&e.set(r,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||0===e.size)return;const r=/* @__PURE__ */new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");if(!i)return;const n=e.get(i);if(void 0===n)return;const o=n-t.getBoundingClientRect().left;Math.abs(o)>1&&r.set(i,o)}),0===r.size)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=r.get(e.getAttribute("data-field")??"");if(void 0!==t){const r=e;r.style.transform=`translateX(${t}px)`,i.push(r)}}),0===i.length)return;t.offsetHeight;const n=this.animationDuration;requestAnimationFrame(()=>{i.forEach(e=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{i.forEach(e=>{e.style.transform="",e.classList.remove("flip-animating")})},n+50)})}animateFade(e){const t=this.gridElement;if(!t)return void e();const r=this.captureHeaderPositions();e();const i=/* @__PURE__ */new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(!t)return;const n=r.get(t);if(void 0===n)return;const o=e.getBoundingClientRect().left;Math.abs(n-o)>1&&i.add(t)}),0===i.size)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(t&&i.has(t)){const t=e;t.classList.add("fade-animating"),n.push(t)}}),0===n.length)return;const o=this.animationDuration;setTimeout(()=>{n.forEach(e=>e.classList.remove("fade-animating"))},o+50)}updateColumnOrder(e){const t=this.animationType;if("flip"===t&&this.gridElement){const t=this.captureHeaderPositions();this.grid.setColumnOrder(e),"function"==typeof this.grid.forceLayout?this.grid.forceLayout().then(()=>{this.animateFLIP(t)}):requestAnimationFrame(()=>{this.animateFLIP(t)})}else"fade"===t?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}};export{p as ReorderPlugin};
1
+ var e="editing",t="dragging";function r(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;return r<=0||i<=0?e:e*r/i}function i(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,r,n){return`${i(r,n)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var o="__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("")),s=(new RegExp(`__(proto|defineGetter|defineSetter)|${o.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".split("|"))),a=/^on\w+$/i,l=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function c(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const i of r){const e=i.tagName.toLowerCase();if(s.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const r=[];for(const t of i.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):(l.has(e)&&d.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}var u={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var g=class{static dependencies;static manifest;aliases;version="3.0.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 i of Object.keys(t))r[i]=this;for(const i of e){const e=i.userConfig;for(const[o,s]of Object.entries(e)){if(void 0===s)continue;if(!(o in t)){t[o]=s,r[o]=i;continue}if(t[o]===s)continue;const e=r[o]?.constructor.name??this.constructor.name,a=i.constructor.name,l=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,r={...e.userConfig};for(const i of Object.keys(t))delete t[i];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)}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{...u,...e}}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 i=this.#t(t,r);void 0!==i?"string"==typeof i?e.innerHTML=c(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.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 i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(r,i):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${i(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}};function f(e){if(!0===e.lockPosition)return!1;if(!0===e.utility)return!1;const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}function h(e,t,r){if(t===r)return e;if(t<0||t>=e.length)return e;if(r<0||r>e.length)return e;const i=[...e],[n]=i.splice(t,1);return i.splice(r,0,n),i}var m="canMoveColumn",p=class extends g{name="reorderColumns";aliases=["reorder"];styles='@layer tbw-plugins{.header-row>.cell[draggable=true]{cursor:grab;position:relative}.header-row>.cell.dragging{opacity:.5;cursor:grabbing}.header-row>.cell.drop-before:before{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;left:0}.header-row>.cell.drop-after:after{content:"";background:var(--tbw-reorder-indicator,var(--tbw-color-accent));z-index:1;width:2px;position:absolute;top:0;bottom:0;right:0}.cell.flip-animating{transition:transform var(--tbw-animation-duration,.2s) ease-out;will-change:transform;z-index:1}@keyframes reorder-fade-in{0%{opacity:0}to{opacity:1}}.cell.fade-animating{animation:reorder-fade-in var(--tbw-animation-duration,.2s) ease-out backwards}}';static manifest={queries:[{type:m,description:"Authoritative check for whether a column may be reordered (honors lockPosition)."}]};handleQuery(e){if(e.type===m){const t=e.context;return t?f(t):void 0}}get defaultConfig(){return{animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}get animationDuration(){return void 0!==this.config.animationDuration?this.config.animationDuration:super.animationDuration}isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupFields=[];originalColumnOrder=null;get#r(){return this.grid}canMoveColumnWithPlugins(e){return!(!e||!f(e))&&!this.grid.query(m,e).includes(!1)}clearDragClasses(){this.gridElement?.querySelectorAll(".header-row > .cell, .header-group-row > .cell").forEach(e=>{e.classList.remove(t,"drop-target","drop-before","drop-after")})}attach(e){super.attach(e),this.gridElement.addEventListener("column-reorder-request",e=>{const t=e.detail;t?.field&&"number"==typeof t.toIndex&&this.moveColumn(t.field,t.toIndex)},{signal:this.disconnectSignal})}detach(){this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[]}afterRender(){const e=this.gridElement;e&&(this.originalColumnOrder||(this.originalColumnOrder=this.columns.map(e=>e.field)),e.querySelectorAll(".header-row > .cell").forEach(e=>{const r=e,i=r.getAttribute("data-field");if(!i)return;const n=this.columns.find(e=>e.field===i);this.canMoveColumnWithPlugins(n)?(r.draggable=!0,r.getAttribute("data-dragstart-bound")||(r.setAttribute("data-dragstart-bound","true"),r.addEventListener("dragstart",e=>{const n=this.getColumnOrder().indexOf(i);this.isDragging=!0,this.draggedField=i,this.draggedIndex=n,this.draggedGroupFields=[],e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",i)),r.classList.add(t)}),r.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),r.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedField===i&&0===this.draggedGroupFields.length)return;if(this.draggedGroupFields.includes(i))return;const n=r.getBoundingClientRect(),o=n.left+n.width/2,s=this.getColumnOrder().indexOf(i);if(this.dropIndex=e.clientX<o?s:s+1,this.clearDragClasses(),this.draggedGroupFields.length>0)for(const r of this.draggedGroupFields)this.gridElement?.querySelector(`.header-row > .cell[data-field="${r}"]`)?.classList.add(t);else this.draggedField&&this.gridElement?.querySelector(`.header-row > .cell[data-field="${this.draggedField}"]`)?.classList.add(t);r.classList.add("drop-target"),r.classList.toggle("drop-before",e.clientX<o),r.classList.toggle("drop-after",e.clientX>=o)}),r.addEventListener("dragleave",()=>{r.classList.remove("drop-target","drop-before","drop-after")}),r.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.includes(i))return;const t=r.getBoundingClientRect(),n=e.clientX<t.left+t.width/2;return void this.executeGroupBlockMove(this.draggedGroupFields,[i],n)}const t=this.draggedField,n=this.draggedIndex,o=this.dropIndex;if(!this.isDragging||null===t||null===n||null===o)return;const s=o>n?o-1:o,a=h(this.getColumnOrder(),n,s),l={field:t,fromIndex:n,toIndex:s,columnOrder:a};this.emitCancelable("column-move",l)||this.updateColumnOrder(a)}))):r.draggable=!1}),queueMicrotask(()=>this.setupGroupHeaderDrag(e)))}setupGroupHeaderDrag(e){e.querySelectorAll(".header-group-row > .cell[data-group]").forEach(r=>{const i=r,n=i.getAttribute("data-group");if(!n||n.startsWith("__implicit__"))return;if(i.getAttribute("data-group-drag-bound"))return;i.setAttribute("data-group-drag-bound","true");const o=this.getGroupFragmentFields(i,n);0!==o.length&&o.every(e=>{const t=this.columns.find(t=>t.field===e);return this.canMoveColumnWithPlugins(t)})&&(i.draggable=!0,i.style.cursor="grab",i.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=null,this.draggedIndex=null,this.draggedGroupFields=[...o],r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",`group:${n}`)),i.classList.add(t);for(const i of o)e.querySelector(`.header-row > .cell[data-field="${i}"]`)?.classList.add(t)}),i.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.draggedGroupFields=[],this.clearDragClasses()}),i.addEventListener("dragover",e=>{if(e.preventDefault(),!this.isDragging)return;if(this.draggedGroupFields.length>0&&this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;const t=i.getBoundingClientRect(),r=t.left+t.width/2,n=e.clientX<r;this.clearDragClasses(),i.classList.add("drop-target"),i.classList.toggle("drop-before",n),i.classList.toggle("drop-after",!n)}),i.addEventListener("dragleave",()=>{i.classList.remove("drop-target","drop-before","drop-after")}),i.addEventListener("drop",e=>{if(e.preventDefault(),!this.isDragging)return;const t=i.getBoundingClientRect(),r=e.clientX<t.left+t.width/2;if(this.draggedGroupFields.length>0){if(this.draggedGroupFields.length===o.length&&this.draggedGroupFields.every(e=>o.includes(e)))return;this.executeGroupBlockMove(this.draggedGroupFields,o,r)}else if(this.draggedField){const e=this.getColumnOrder(),t=r?o[0]:o[o.length-1],i=e.indexOf(this.draggedField),n=r?e.indexOf(t):e.indexOf(t)+1;if(-1===i||-1===n)return;const s=n>i?n-1:n,a=h(e,i,s);this.emitCancelable("column-move",{field:this.draggedField,fromIndex:i,toIndex:s,columnOrder:a})||this.updateColumnOrder(a)}}))})}getGroupFragmentFields(e,t){const r=e.style.gridColumn,i=/(\d+)\s*\/\s*span\s+(\d+)/.exec(r);if(!i)return[];const n=parseInt(i[1],10),o=parseInt(i[2],10),s=this.visibleColumns,a=[];for(let l=n-1;l<n-1+o&&l<s.length;l++){const e=s[l];e&&a.push(e.field)}return a}executeGroupBlockMove(e,t,r){const i=this.getColumnOrder(),n=i.filter(t=>!e.includes(t)),o=r?t[0]:t[t.length-1],s=n.indexOf(o);if(-1===s)return;const a=r?s:s+1,l=i.filter(t=>e.includes(t));n.splice(a,0,...l),this.emitCancelable("column-move",{field:e[0],fromIndex:i.indexOf(e[0]),toIndex:a,columnOrder:n})||this.updateColumnOrder(n)}onKeyDown(t){if(!t.altKey||"ArrowLeft"!==t.key&&"ArrowRight"!==t.key)return;const i=this.#r,n=i._focusCol,o=i._visibleColumns;if(n<0||n>=o.length)return;const s=o[n];if(!this.canMoveColumnWithPlugins(s))return;const a=this.getColumnOrder(),l=a.indexOf(s.field);if(-1===l)return;const d="ArrowLeft"===t.key?l-1:l+1;if(d<0||d>=a.length)return;const c=o.find(e=>e.field===a[d]);return this.canMoveColumnWithPlugins(c)?(this.moveColumn(s.field,d),i._focusCol=d,function(t,i){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:n,scrollMapping:o}=t._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(s&&a>0){const i=t._focusRow*e,n=o?function(e,t){if(!t.capped)return e;const r=t.spacerHeight-t.viewportHeight,i=t.rawContentHeight-t.viewportHeight;if(r<=0||i<=0)return e;const n=e*i/r;return n<0?0:n>i?i:n}(s.scrollTop,o):s.scrollTop;if(i<n)s.scrollTop=o?r(i,o):i;else if(i+e>n+a){const t=i-a+e;s.scrollTop=o?r(t,o):t}}}const n=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.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 s=t._focusRow,a=t._virtualization.start??0,l=t._virtualization.end??t._rows.length;if(s>=a&&s<l){const r=t._bodyEl.querySelectorAll(".data-grid-row")[s-a];let o=r?.children[t._focusCol];if(o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const s=t.querySelector(".tbw-scroll-area");if(s&&o&&(!n||i?.forceHorizontalScroll))if(i?.forceScrollLeft)s.scrollLeft=0;else if(i?.forceScrollRight)s.scrollLeft=s.scrollWidth-s.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(r??void 0,o)??{left:0,right:0};if(!e.skipScroll){const t=o.getBoundingClientRect(),r=s.getBoundingClientRect(),i=t.left-r.left+s.scrollLeft,n=i+t.width,a=s.scrollLeft+e.left,l=s.scrollLeft+s.clientWidth-e.right;i<a?s.scrollLeft=i-e.left:n>l&&(s.scrollLeft=n-s.clientWidth+e.right)}}if(n&&o.classList.contains(e)){const e=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(n&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!n){const e=document.activeElement;e instanceof HTMLElement&&e!==t&&"function"==typeof t.contains&&t.contains(e)&&!e.classList.contains("cell")&&!e.closest(".cell")||e===t||t.focus({preventScroll:!0})}}}}(this.#r),t.preventDefault(),t.stopPropagation(),!0):void 0}getColumnOrder(){return this.grid.getColumnOrder()}moveColumn(e,t){const r=this.getColumnOrder(),i=r.indexOf(e);if(-1===i)return;const n=h(r,i,t);this.emitCancelable("column-move",{field:e,fromIndex:i,toIndex:t,columnOrder:n})||this.updateColumnOrder(n)}setColumnOrder(e){this.updateColumnOrder(e)}resetColumnOrder(){const e=this.originalColumnOrder??this.columns.map(e=>e.field);this.updateColumnOrder(e)}captureHeaderPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const r=t.getAttribute("data-field");r&&e.set(r,t.getBoundingClientRect().left)}),e}animateFLIP(e){const t=this.gridElement;if(!t||0===e.size)return;const r=/* @__PURE__ */new Map;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(t=>{const i=t.getAttribute("data-field");if(!i)return;const n=e.get(i);if(void 0===n)return;const o=n-t.getBoundingClientRect().left;Math.abs(o)>1&&r.set(i,o)}),0===r.size)return;const i=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=r.get(e.getAttribute("data-field")??"");if(void 0!==t){const r=e;r.style.transform=`translateX(${t}px)`,i.push(r)}}),0===i.length)return;t.offsetHeight;const n=this.animationDuration;requestAnimationFrame(()=>{i.forEach(e=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{i.forEach(e=>{e.style.transform="",e.classList.remove("flip-animating")})},n+50)})}animateFade(e){const t=this.gridElement;if(!t)return void e();const r=this.captureHeaderPositions();e();const i=/* @__PURE__ */new Set;if(t.querySelectorAll(".header-row > .cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(!t)return;const n=r.get(t);if(void 0===n)return;const o=e.getBoundingClientRect().left;Math.abs(n-o)>1&&i.add(t)}),0===i.size)return;const n=[];if(t.querySelectorAll(".cell[data-field]").forEach(e=>{const t=e.getAttribute("data-field");if(t&&i.has(t)){const t=e;t.classList.add("fade-animating"),n.push(t)}}),0===n.length)return;const o=this.animationDuration;setTimeout(()=>{n.forEach(e=>e.classList.remove("fade-animating"))},o+50)}updateColumnOrder(e){const t=this.animationType;if("flip"===t&&this.gridElement){const t=this.captureHeaderPositions();this.grid.setColumnOrder(e),"function"==typeof this.grid.forceLayout?this.grid.forceLayout().then(()=>{this.animateFLIP(t)}):requestAnimationFrame(()=>{this.animateFLIP(t)})}else"fade"===t?this.animateFade(()=>this.grid.setColumnOrder(e)):this.grid.setColumnOrder(e);this.grid.requestStateChange?.()}};export{p as ReorderPlugin};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,i,r,n){return`${e(r,n)} ${t}: ${i}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}var i="editing";function r(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;return i<=0||r<=0?e:e*i/r}function n(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:i,viewportEl:n,scrollMapping:o}=e._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(s&&a>0){const i=e._focusRow*t,n=o?function(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;if(i<=0||r<=0)return e;const n=e*r/i;return n<0?0:n>r?r:n}(s.scrollTop,o):s.scrollTop;if(i<n)s.scrollTop=o?r(i,o):i;else if(i+t>n+a){const e=i-a+t;s.scrollTop=o?r(e,o):e}}}const n=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;var o;n||e.refreshVirtualWindow(!1),(o=e._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const s=e._focusRow,a=e._virtualization.start??0,d=e._virtualization.end??e._rows.length;if(s>=a&&s<d){const r=e._bodyEl.querySelectorAll(".data-grid-row")[s-a];let o=r?.children[e._focusCol];if(o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${e._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const s=e.querySelector(".tbw-scroll-area");if(s&&o&&(!n||t?.forceHorizontalScroll))if(t?.forceScrollLeft)s.scrollLeft=0;else if(t?.forceScrollRight)s.scrollLeft=s.scrollWidth-s.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(r??void 0,o)??{left:0,right:0};if(!t.skipScroll){const e=o.getBoundingClientRect(),i=s.getBoundingClientRect(),r=e.left-i.left+s.scrollLeft,n=r+e.width,a=s.scrollLeft+t.left,d=s.scrollLeft+s.clientWidth-t.right;r<a?s.scrollLeft=r-t.left:n>d&&(s.scrollLeft=n-s.clientWidth+t.right)}}if(n&&o.classList.contains(i)){const e=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(n&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!n){const t=document.activeElement;t instanceof HTMLElement&&t!==e&&"function"==typeof e.contains&&e.contains(t)&&!t.classList.contains("cell")&&!t.closest(".cell")||t===e||e.focus({preventScroll:!0})}}}}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(e=>e.split("").reverse().join("")),l=new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`),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".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(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const r of i){const e=r.tagName.toLowerCase();if(c.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>u.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const i=[];for(const t of r.attributes){const e=t.name.toLowerCase();u.test(e)?i.push(t.name):(h.has(e)&&p.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name)}i.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function f(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const r=e[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const r=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<e.length&&"'"!==e[i];)r+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(r,i)});continue}if(i+2<e.length){const r=e.slice(i,i+3);if("==="===r||"!=="===r){t.push({type:"op",v:r}),i+=3;continue}}if(i+1<e.length){const r=e.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){t.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;t.push({type:"op",v:r}),i++}else i++}return t}(e);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}function a(e,t){const i=o();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function d(){const e=function(){let e=l();for(;a("op","||");)s(),e=e||l();return e}();if(a("op","?")){s();const t=d();if(!a("op",":"))return;s();const i=d();return e?t:i}return e}function l(){let e=c();for(;a("op","&&");)s(),e=e&&c();return e}function c(){let e=u();for(;;){const t=o();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===u();else if("!=="===t.v)s(),e=e!==u();else if("=="===t.v)s(),e=e==u();else{if("!="!==t.v)break;s(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=o();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<h();else if(">"===t.v)s(),e=e>h();else if("<="===t.v)s(),e=e<=h();else{if(">="!==t.v)break;s(),e=e>=h()}}return e}function h(){let e=p();for(;;){const t=o();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=p();else{if("-"!==t.v)break;s(),e-=p()}}return e}function p(){let e=g();for(;;){const t=o();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=g();else if("/"===t.v)s(),e/=g();else{if("%"!==t.v)break;s(),e%=g()}}return e}function g(){return a("op","!")?(s(),!g()):f()}function f(){const e=o();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const i=e.slice(4);return t.row?t.row[i]:void 0}if(e.startsWith("typeDefault.")){const i=e.slice(12);return t.typeDefault?t.typeDefault[i]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=d();return a("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-f()):void 0}}const v=d();return n<r.length?void 0:v}function v(e,t){if(!e||-1===e.indexOf("{{"))return e;const i=[],r=(n=e.replace(o,(e,r)=>{const n=function(e,t){if(!(e=(e||"").trim()))return s;if(w.test(e))return s;if("value"===e)return null==t.value?s:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=t.row?t.row[i]:void 0;return null==r?s:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=t.typeDefault?t.typeDefault[i]:void 0;return null==r?s:String(r)}if(e.length>80)return s;if(!a.test(e)||l.test(e))return s;const i=e.match(/\./g);if(i&&i.length>1)return s;try{const i=f(e,t),r=null==i?"":String(i);return w.test(r)?s:r||s}catch{return s}}(r,t);return i.push({expr:r.trim(),result:n}),n}),n?n.replace(new RegExp(s,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const d=i.length&&i.every(e=>""===e.result||e.result===s);return w.test(e)||d?"":r}var w=/Reflect|Proxy|ownKeys/;var m={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var b=class{static dependencies;static manifest;aliases;version="3.0.0";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 i={...this.userConfig},r={};for(const t of Object.keys(i))r[t]=this;for(const n of e){const e=n.userConfig;for(const[o,s]of Object.entries(e)){if(void 0===s)continue;if(!(o in i)){i[o]=s,r[o]=n;continue}if(i[o]===s)continue;const e=r[o]?.constructor.name??this.constructor.name,a=n.constructor.name,d=t("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} 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(e){const t=this.userConfig,i={...e.userConfig};for(const r of Object.keys(t))delete t[r];Object.assign(t,i)}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 i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.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)}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{...m,...e}}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(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}setIcon(e,t,i){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const r=this.#t(t,i);void 0!==r?"string"==typeof r?e.innerHTML=g(r):r instanceof HTMLElement&&(e.innerHTML="",e.appendChild(r.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 i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(i,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return r?e.insertBefore(i,r):e.appendChild(i),i}warn(i,r){void 0!==r?console.warn(t(i,r,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(e,i){throw new Error(t(e,i,this.gridElement.id,this.name))}},R=class extends b{name="responsive";version="1.0.0";styles='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;height:auto!important;min-height:auto!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:"";inset-inline-start:0;background:var(--tbw-color-accent);width:4px;position:absolute;top:0;bottom:0}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;border:none!important;white-space:normal!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);flex-shrink:0;min-width:100px;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]{display:none!important}tbw-grid[data-responsive] .data-grid-row>.cell[data-responsive-hidden]{display:none!important}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,tbw-grid:not([data-responsive]) .cell[data-responsive-hidden]{display:none!important}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=/* @__PURE__ */new Set;#d=/* @__PURE__ */new Set;#l=null;#c=[];get#u(){return this.grid}isResponsive(){return this.#r}setResponsive(e){e!==this.#r&&(this.#r=e,this.#h(),this.emit("responsive-change",{isResponsive:e,width:this.#s,breakpoint:this.config.breakpoint??0}),this.requestRender())}setBreakpoint(e){this.config.breakpoint=e,this.#p(this.#s)}setCardRenderer(e){this.config.cardRenderer=e,this.#r&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#l}attach(e){super.attach(e),this.#g(),this.#f(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#c=[...this.config.breakpoints].sort((e,t)=>t.maxWidth-e.maxWidth)),this.#i=new ResizeObserver(e=>{const t=e[0]?.contentRect.width??0;this.#s=t,clearTimeout(this.#n),this.#n=setTimeout(()=>{this.#p(t)},this.config.debounceMs??100)}),this.#i.observe(this.gridElement)}#g(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=this.#u.__frameworkAdapter;if(i?.parseResponsiveCardElement){const e=i.parseResponsiveCardElement(t);e&&(this.config={...this.config,cardRenderer:e})}const r=t.getAttribute("breakpoint"),n=t.getAttribute("card-row-height"),o=t.getAttribute("hidden-columns"),s=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),d={};if(null!==r){const e=parseInt(r,10);isNaN(e)||(d.breakpoint=e)}if(null!==n&&(d.cardRowHeight="auto"===n?"auto":parseInt(n,10)),null!==o&&(d.hiddenColumns=o.split(",").map(e=>e.trim()).filter(e=>e.length>0)),null!==s&&(d.hideHeader="false"!==s),null!==a){const e=parseInt(a,10);isNaN(e)||(d.debounceMs=e)}const l=t.innerHTML.trim();!l||this.config.cardRenderer||i?.parseResponsiveCardElement||(d.cardRenderer=e=>{const t=g(v(l,{value:e,row:e})),i=document.createElement("div");return i.className="tbw-responsive-card-content",i.innerHTML=t,i}),Object.keys(d).length>0&&(this.config={...this.config,...d})}#f(e){if(this.#a.clear(),this.#d.clear(),e)for(const t of e)"string"==typeof t?this.#a.add(t):t.showValue?this.#d.add(t.field):this.#a.add(t.field)}detach(){this.#i?.disconnect(),this.#i=void 0,clearTimeout(this.#n),this.#n=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if("isCardMode"===e.type)return this.#r}afterRender(){if(this.#v(),!(this.#c.length>0?null!==this.#l:this.#r))return;const e=this.#a.size>0,t=this.#d.size>0;if(!e&&!t)return;const i=this.gridElement.querySelectorAll(".cell[data-field]");for(const r of i){const e=r.getAttribute("data-field");e&&(this.#a.has(e)?(r.setAttribute("data-responsive-hidden",""),r.removeAttribute("data-responsive-value-only")):this.#d.has(e)?(r.setAttribute("data-responsive-value-only",""),r.removeAttribute("data-responsive-hidden")):(r.removeAttribute("data-responsive-hidden"),r.removeAttribute("data-responsive-value-only")))}}#p(e){if(this.#c.length>0)return void this.#w(e);const t=this.config.breakpoint??0;0!==t||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=t>0&&e<t;i!==this.#r&&(this.#r=i,this.#h(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#w(e){let t=null;for(const i of this.#c)e<=i.maxWidth&&(t=i);if(t!==this.#l){this.#l=t,t?.hiddenColumns?this.#f(t.hiddenColumns):this.#f(this.config.hiddenColumns);const i=!0===t?.cardLayout;i!==this.#r&&(this.#r=i,this.#h()),this.emit("responsive-change",{isResponsive:this.#r,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#m;#h(){this.gridElement.toggleAttribute("data-responsive",this.#r);const e=!1!==this.config.animate;this.gridElement.toggleAttribute("data-responsive-animate",e),this.gridElement.toggleAttribute("data-responsive-hide-header",this.#r&&!0===this.config.hideHeader),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.#u;if(this.#r){t._virtualization&&(this.#m=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.#m&&this.#m>0&&t._virtualization&&(t._virtualization.rowHeight=this.#m,this.#m=void 0),this.#b=void 0,this.#R=void 0,this.#y=void 0}}renderRow(e,t,i){if(!this.#r||!this.config.cardRenderer)return;if(e.__isGroupRow)return;t.replaceChildren();const r=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const n=this.config.cardRowHeight;return t.style.height="auto"===n||void 0===n?"auto":`${this.#C()}px`,t.appendChild(r),!0}onKeyDown(e){if(!this.#r)return!1;if(this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),n(this.#u),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),n(this.#u),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),n(this.#u),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),n(this.#u),!0}return!1}#b;#R;#y;#C(){if(this.#b&&this.#b>0)return this.#b;const e=this.config.cardRowHeight;return"number"==typeof e&&e>0?e:80}#k(){return this.#R&&this.#R>0?this.#R:this.#m??28}#_(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}getRowHeight(e,t){if(this.#r&&this.config.cardRenderer)return e.__isGroupRow?this.#k():this.#C()}#H(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#S=!1;#v(){if(!this.#r)return;let e=!1;const t=this.#u,i=this.#_(),r=this.#H();if(r!==this.#y&&(this.#y=r,e=!0),i){const t=this.gridElement.querySelector(".data-grid-row.group-row");if(t){const i=t.getBoundingClientRect().height;i>0&&i!==this.#R&&(this.#R=i,e=!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.#b&&(this.#b=r,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=r))}e&&!this.#S&&(this.#S=!0,queueMicrotask(()=>{this.#S=!1,this.grid&&this.#r&&this.#u.refreshVirtualWindow?.(!0,!0)}))}};export{R as ResponsivePlugin};
1
+ function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function t(t,i,r,n){return`${e(r,n)} ${t}: ${i}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}var i="editing";function r(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;return i<=0||r<=0?e:e*i/r}function n(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:i,viewportEl:n,scrollMapping:o}=e._virtualization,s=i,a=n?.clientHeight??s?.clientHeight??0;if(s&&a>0){const i=e._focusRow*t,n=o?function(e,t){if(!t.capped)return e;const i=t.spacerHeight-t.viewportHeight,r=t.rawContentHeight-t.viewportHeight;if(i<=0||r<=0)return e;const n=e*r/i;return n<0?0:n>r?r:n}(s.scrollTop,o):s.scrollTop;if(i<n)s.scrollTop=o?r(i,o):i;else if(i+t>n+a){const e=i-a+t;s.scrollTop=o?r(e,o):e}}}const n=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;var o;n||e.refreshVirtualWindow(!1),(o=e._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const s=e._focusRow,a=e._virtualization.start??0,d=e._virtualization.end??e._rows.length;if(s>=a&&s<d){const r=e._bodyEl.querySelectorAll(".data-grid-row")[s-a];let o=r?.children[e._focusCol];if(o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${e._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const s=e.querySelector(".tbw-scroll-area");if(s&&o&&(!n||t?.forceHorizontalScroll))if(t?.forceScrollLeft)s.scrollLeft=0;else if(t?.forceScrollRight)s.scrollLeft=s.scrollWidth-s.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(r??void 0,o)??{left:0,right:0};if(!t.skipScroll){const e=o.getBoundingClientRect(),i=s.getBoundingClientRect(),r=e.left-i.left+s.scrollLeft,n=r+e.width,a=s.scrollLeft+t.left,d=s.scrollLeft+s.clientWidth-t.right;r<a?s.scrollLeft=r-t.left:n>d&&(s.scrollLeft=n-s.clientWidth+t.right)}}if(n&&o.classList.contains(i)){const e=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(n&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!n){const t=document.activeElement;t instanceof HTMLElement&&t!==e&&"function"==typeof e.contains&&e.contains(t)&&!t.classList.contains("cell")&&!t.closest(".cell")||t===e||e.focus({preventScroll:!0})}}}}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(e=>e.split("").reverse().join("")),l=new RegExp(`__(proto|defineGetter|defineSetter)|${d.slice(3).join("|")}|this\\b`),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".split("|")),u=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),g=/^\s*(javascript|vbscript|data|blob):/i;function p(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],i=e.querySelectorAll("*");for(const r of i){const e=r.tagName.toLowerCase();if(c.has(e)){t.push(r);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(e=>u.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(r);continue}const i=[];for(const t of r.attributes){const e=t.name.toLowerCase();u.test(e)?i.push(t.name):(h.has(e)&&g.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&i.push(t.name)}i.forEach(e=>r.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function f(e,t){const i=function(e){const t=[];let i=0;for(;i<e.length;){const r=e[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<e.length&&e[i+1]>="0"&&e[i+1]<="9"){const r=i;for(;i<e.length&&(e[i]>="0"&&e[i]<="9"||"."===e[i]);)i++;t.push({type:"num",v:Number(e.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<e.length&&"'"!==e[i];)r+=e[i++];if(i>=e.length)return null;i++,t.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<e.length&&/[\w$.]/.test(e[i]);)i++;t.push({type:"id",v:e.slice(r,i)});continue}if(i+2<e.length){const r=e.slice(i,i+3);if("==="===r||"!=="===r){t.push({type:"op",v:r}),i+=3;continue}}if(i+1<e.length){const r=e.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){t.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;t.push({type:"op",v:r}),i++}else i++}return t}(e);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}function a(e,t){const i=o();return!!i&&(i.type===e&&(void 0===t||i.v===t))}function d(){const e=function(){let e=l();for(;a("op","||");)s(),e=e||l();return e}();if(a("op","?")){s();const t=d();if(!a("op",":"))return;s();const i=d();return e?t:i}return e}function l(){let e=c();for(;a("op","&&");)s(),e=e&&c();return e}function c(){let e=u();for(;;){const t=o();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===u();else if("!=="===t.v)s(),e=e!==u();else if("=="===t.v)s(),e=e==u();else{if("!="!==t.v)break;s(),e=e!=u()}}return e}function u(){let e=h();for(;;){const t=o();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<h();else if(">"===t.v)s(),e=e>h();else if("<="===t.v)s(),e=e<=h();else{if(">="!==t.v)break;s(),e=e>=h()}}return e}function h(){let e=g();for(;;){const t=o();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=p();for(;;){const t=o();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=p();else if("/"===t.v)s(),e/=p();else{if("%"!==t.v)break;s(),e%=p()}}return e}function p(){return a("op","!")?(s(),!p()):f()}function f(){const e=o();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const i=e.slice(4);return t.row?t.row[i]:void 0}if(e.startsWith("typeDefault.")){const i=e.slice(12);return t.typeDefault?t.typeDefault[i]:void 0}return"row"===e?t.row:"typeDefault"===e?t.typeDefault:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=d();return a("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-f()):void 0}}const v=d();return n<r.length?void 0:v}function v(e,t){if(!e||-1===e.indexOf("{{"))return e;const i=[],r=(n=e.replace(o,(e,r)=>{const n=function(e,t){if(!(e=(e||"").trim()))return s;if(w.test(e))return s;if("value"===e)return null==t.value?s:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(4),r=t.row?t.row[i]:void 0;return null==r?s:String(r)}if(e.startsWith("typeDefault.")&&!/[()?]/.test(e)&&!e.includes(":")){const i=e.slice(12),r=t.typeDefault?t.typeDefault[i]:void 0;return null==r?s:String(r)}if(e.length>80)return s;if(!a.test(e)||l.test(e))return s;const i=e.match(/\./g);if(i&&i.length>1)return s;try{const i=f(e,t),r=null==i?"":String(i);return w.test(r)?s:r||s}catch{return s}}(r,t);return i.push({expr:r.trim(),result:n}),n}),n?n.replace(new RegExp(s,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const d=i.length&&i.every(e=>""===e.result||e.result===s);return w.test(e)||d?"":r}var w=/Reflect|Proxy|ownKeys/;var m={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};var b=class{static dependencies;static manifest;aliases;version="3.0.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 i={...this.userConfig},r={};for(const t of Object.keys(i))r[t]=this;for(const n of e){const e=n.userConfig;for(const[o,s]of Object.entries(e)){if(void 0===s)continue;if(!(o in i)){i[o]=s,r[o]=n;continue}if(i[o]===s)continue;const e=r[o]?.constructor.name??this.constructor.name,a=n.constructor.name,d=t("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${o}" supplied by both ${e} 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(e){const t=this.userConfig,i={...e.userConfig};for(const r of Object.keys(t))delete t[r];Object.assign(t,i)}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 i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.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)}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{...m,...e}}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(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}setIcon(e,t,i){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const r=this.#t(t,i);void 0!==r?"string"==typeof r?e.innerHTML=p(r):r instanceof HTMLElement&&(e.innerHTML="",e.appendChild(r.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 i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(i,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return r?e.insertBefore(i,r):e.appendChild(i),i}warn(i,r){void 0!==r?console.warn(t(i,r,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${i}`)}throwDiagnostic(e,i){throw new Error(t(e,i,this.gridElement.id,this.name))}},R=class extends b{name="responsive";version="1.0.0";styles='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;height:auto!important;min-height:auto!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)>.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,tbw-grid:not([data-responsive]) .cell[data-responsive-hidden],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=/* @__PURE__ */new Set;#d=/* @__PURE__ */new Set;#l=null;#c=[];get#u(){return this.grid}isResponsive(){return this.#r}setResponsive(e){e!==this.#r&&(this.#r=e,this.#h(),this.emit("responsive-change",{isResponsive:e,width:this.#s,breakpoint:this.config.breakpoint??0}),this.requestRender())}setBreakpoint(e){this.config.breakpoint=e,this.#g(this.#s)}setCardRenderer(e){this.config.cardRenderer=e,this.#r&&this.requestRender()}getWidth(){return this.#s}getActiveBreakpoint(){return this.#l}attach(e){super.attach(e),this.#p(),this.#f(this.config.hiddenColumns),this.config.breakpoints?.length&&(this.#c=[...this.config.breakpoints].sort((e,t)=>t.maxWidth-e.maxWidth)),this.#i=new ResizeObserver(e=>{const t=e[0]?.contentRect.width??0;this.#s=t,clearTimeout(this.#n),this.#n=setTimeout(()=>{this.#g(t)},this.config.debounceMs??100)}),this.#i.observe(this.gridElement)}#p(){const e=this.gridElement;if(!e)return;const t=e.querySelector("tbw-grid-responsive-card");if(!t)return;const i=this.#u.__frameworkAdapter;if(i?.parseResponsiveCardElement){const e=i.parseResponsiveCardElement(t);e&&(this.config={...this.config,cardRenderer:e})}const r=t.getAttribute("breakpoint"),n=t.getAttribute("card-row-height"),o=t.getAttribute("hidden-columns"),s=t.getAttribute("hide-header"),a=t.getAttribute("debounce-ms"),d={};if(null!==r){const e=parseInt(r,10);isNaN(e)||(d.breakpoint=e)}if(null!==n&&(d.cardRowHeight="auto"===n?"auto":parseInt(n,10)),null!==o&&(d.hiddenColumns=o.split(",").map(e=>e.trim()).filter(e=>e.length>0)),null!==s&&(d.hideHeader="false"!==s),null!==a){const e=parseInt(a,10);isNaN(e)||(d.debounceMs=e)}const l=t.innerHTML.trim();!l||this.config.cardRenderer||i?.parseResponsiveCardElement||(d.cardRenderer=e=>{const t=p(v(l,{value:e,row:e})),i=document.createElement("div");return i.className="tbw-responsive-card-content",i.innerHTML=t,i}),Object.keys(d).length>0&&(this.config={...this.config,...d})}#f(e){if(this.#a.clear(),this.#d.clear(),e)for(const t of e)"string"==typeof t?this.#a.add(t):t.showValue?this.#d.add(t.field):this.#a.add(t.field)}detach(){this.#i?.disconnect(),this.#i=void 0,clearTimeout(this.#n),this.#n=void 0,this.gridElement&&this.gridElement.removeAttribute("data-responsive"),super.detach()}handleQuery(e){if("isCardMode"===e.type)return this.#r}afterRender(){if(this.#v(),!(this.#c.length>0?null!==this.#l:this.#r))return;const e=this.#a.size>0,t=this.#d.size>0;if(!e&&!t)return;const i=this.gridElement.querySelectorAll(".cell[data-field]");for(const r of i){const e=r.getAttribute("data-field");e&&(this.#a.has(e)?(r.setAttribute("data-responsive-hidden",""),r.removeAttribute("data-responsive-value-only")):this.#d.has(e)?(r.setAttribute("data-responsive-value-only",""),r.removeAttribute("data-responsive-hidden")):(r.removeAttribute("data-responsive-hidden"),r.removeAttribute("data-responsive-value-only")))}}#g(e){if(this.#c.length>0)return void this.#w(e);const t=this.config.breakpoint??0;0!==t||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=t>0&&e<t;i!==this.#r&&(this.#r=i,this.#h(),this.emit("responsive-change",{isResponsive:i,width:e,breakpoint:t}),this.requestRender())}#w(e){let t=null;for(const i of this.#c)e<=i.maxWidth&&(t=i);if(t!==this.#l){this.#l=t,t?.hiddenColumns?this.#f(t.hiddenColumns):this.#f(this.config.hiddenColumns);const i=!0===t?.cardLayout;i!==this.#r&&(this.#r=i,this.#h()),this.emit("responsive-change",{isResponsive:this.#r,width:e,breakpoint:t?.maxWidth??0}),this.requestRender()}}#m;#h(){this.gridElement.toggleAttribute("data-responsive",this.#r);const e=!1!==this.config.animate;this.gridElement.toggleAttribute("data-responsive-animate",e),this.gridElement.toggleAttribute("data-responsive-hide-header",this.#r&&!0===this.config.hideHeader),this.config.animationDuration&&this.gridElement.style.setProperty("--tbw-responsive-duration",`${this.config.animationDuration}ms`);const t=this.#u;if(this.#r){t._virtualization&&(this.#m=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.#m&&this.#m>0&&t._virtualization&&(t._virtualization.rowHeight=this.#m,this.#m=void 0),this.#b=void 0,this.#R=void 0,this.#y=void 0}}renderRow(e,t,i){if(!this.#r||!this.config.cardRenderer)return;if(e.__isGroupRow)return;t.replaceChildren();const r=this.config.cardRenderer(e,i);t.className="data-grid-row responsive-card";const n=this.config.cardRowHeight;return t.style.height="auto"===n||void 0===n?"auto":`${this.#C()}px`,t.appendChild(r),!0}onKeyDown(e){if(!this.#r)return!1;if(this.config.cardRenderer&&["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key))return!1;const t=this.rows.length-1,i=this.visibleColumns.length-1;switch(e.key){case"ArrowDown":if(this.grid._focusCol<i)return this.grid._focusCol+=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow<t)return this.grid._focusRow+=1,this.grid._focusCol=0,e.preventDefault(),n(this.#u),!0;break;case"ArrowUp":if(this.grid._focusCol>0)return this.grid._focusCol-=1,e.preventDefault(),n(this.#u),!0;if(this.grid._focusRow>0)return this.grid._focusRow-=1,this.grid._focusCol=i,e.preventDefault(),n(this.#u),!0;break;case"ArrowRight":if(this.grid._focusRow<t)return this.grid._focusRow+=1,e.preventDefault(),n(this.#u),!0;break;case"ArrowLeft":if(this.grid._focusRow>0)return this.grid._focusRow-=1,e.preventDefault(),n(this.#u),!0}return!1}#b;#R;#y;#C(){if(this.#b&&this.#b>0)return this.#b;const e=this.config.cardRowHeight;return"number"==typeof e&&e>0?e:80}#k(){return this.#R&&this.#R>0?this.#R:this.#m??28}#_(){for(const e of this.rows)if(e.__isGroupRow)return!0;return!1}getRowHeight(e,t){if(this.#r&&this.config.cardRenderer)return e.__isGroupRow?this.#k():this.#C()}#H(){let e=0;for(const t of this.rows)t.__isGroupRow||e++;return e}#S=!1;#v(){if(!this.#r)return;let e=!1;const t=this.#u,i=this.#_(),r=this.#H();if(r!==this.#y&&(this.#y=r,e=!0),i){const t=this.gridElement.querySelector(".data-grid-row.group-row");if(t){const i=t.getBoundingClientRect().height;i>0&&i!==this.#R&&(this.#R=i,e=!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.#b&&(this.#b=r,e=!0,!i&&t._virtualization&&(t._virtualization.rowHeight=r))}e&&!this.#S&&(this.#S=!0,queueMicrotask(()=>{this.#S=!1,this.grid&&this.#r&&this.#u.refreshVirtualWindow?.(!0,!0)}))}};export{R as ResponsivePlugin};
2
2
  //# sourceMappingURL=index.js.map