@toolbox-web/grid 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/internal/empty.d.ts +14 -6
- package/lib/core/types.d.ts +4 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/responsive/index.d.ts +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/responsive/types.d.ts +36 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/row-drag-drop/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +3 -2
- package/themes/dg-theme-bootstrap.css +13 -4
- package/themes/dg-theme-contrast.css +3 -0
- package/themes/dg-theme-large.css +4 -0
- package/themes/dg-theme-material.css +3 -0
- package/themes/dg-theme-standard.css +12 -3
- package/themes/dg-theme-vibrant.css +10 -3
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function r(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const r=e.querySelector?.(".tbw-sr-only");r&&(r.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{r.textContent=t}):r.textContent=t)}function o(t,r,...o){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):e[r](...o)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function i(e,t,r,o){return`${n(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__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)|${s.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("|"))),a=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),c=/^\s*(javascript|vbscript|data|blob):/i;function u(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(l.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>a.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();a.test(e)?r.push(t.name):"is"!==e?(d.has(e)&&c.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 f=class{static dependencies;static manifest;aliases;version="3.6.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 o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=o;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,l=o.constructor.name,a=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. 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{...t,...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(u(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(i(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(i(e,t,this.gridElement.id,this.name))}},h=/* @__PURE__ */new WeakMap;function g(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var m=/* @__PURE__ */new Map;function p(e,t){if(null==e)return;const r=function(e){if(-1===e.indexOf("."))return null;let t=m.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),m.set(e,t)),t}(t),o=e;return null===r?g(t)?void 0:o[t]:Object.prototype.hasOwnProperty.call(o,t)?o[t]:function(e,t){let r=e;for(let o=0;o<t.length;o++){if(null==r||"object"!=typeof r)return;const e=t[o];if(g(e))return;r=r[e]}return r}(o,r)}var b=new Intl.Collator(void 0,{sensitivity:"variant"});function C(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??v,n=e.field,i=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return p(e,t.field);if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,n=t.field;let i=h.get(o);if(i){const e=i.get(n);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,h.set(o,i);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return i.set(n,{v:s}),s}(e,t):e=>e[n];return{field:n,asc:"asc"===e.direction,comparator:o,getValue:i,pinPlaceholders:!t?.sortComparator}}),n=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),i=e.length,s=o.length,l=new Array(i*s);for(let u=0;u<i;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=i<=4294967295?new Uint32Array(i):new Array(i);for(let u=0;u<i;u++)a[u]=u;const d=(t,r)=>{if(n){const o=function(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const i=t*s,a=r*s;for(let n=0;n<s;n++){const s=o[n],d=s.comparator(l[i+n],l[a+n],e[t],e[r]);if(0!==d)return s.asc?d:-d}return 0};Uint32Array,a.sort(d);const c=e.slice();for(let u=0;u<i;u++)e[u]=c[a[u]]}function v(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:b.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function S(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function w(e,t){return e.find(e=>e.field===t)?.direction}var y=class extends f{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs,.7em);background:var(--tbw-multi-sort-badge-bg,var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color,var(--tbw-color-fg));width:var(--tbw-multi-sort-badge-size,1em);height:var(--tbw-multi-sort-badge-size,1em);margin-left:var(--tbw-spacing-xs,.125em);border-radius:50%;justify-content:center;align-items:center;font-weight:600;display:inline-flex}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#n(){return this.grid}clearCoreSortState(){this.#n._sortState=null}#i(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),n=e.filter(e=>!o.has(e.field));return n.length===e.length?e:n}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#n;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#i(this.sortModel),o=e;return r.length>0&&C(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){if(!this.columns.find(t=>t.field===e.field)?.sortable)return!1;const t=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const n=e.find(e=>e.field===t);return r?n?"asc"===n.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===n?.direction?[{field:t,direction:"desc"}]:"desc"===n?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,t,n),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=S(this.sortModel,r),n=w(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),n){const r=this.updateSortIndicator(e,n);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return S(this.sortModel,e)}getSortDirection(e){return w(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1!==t)return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}};export{y as MultiSortPlugin};
|
|
1
|
+
var e={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,selectAllRows:()=>"Select all rows",selectRow:e=>`Select row ${e+1}`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function r(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const r=e.querySelector?.(".tbw-sr-only");r&&(r.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{r.textContent=t}):r.textContent=t)}function o(t,r,...o){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[r];return n?n(...o):e[r](...o)}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function i(e,t,r,o){return`${n(r,o)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var s="__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)|${s.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("|"))),a=/^on\w+$/i,c=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),d=/^\s*(javascript|vbscript|data|blob):/i;function u(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(l.has(e)){t.push(o);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===o.namespaceURI)&&Array.from(o.attributes).some(e=>a.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();a.test(e)?r.push(t.name):"is"!==e?(c.has(e)&&d.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 f=class{static dependencies;static manifest;aliases;version="3.7.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 o of Object.keys(t))r[o]=this;for(const o of e){const e=o.userConfig;for(const[n,s]of Object.entries(e)){if(void 0===s)continue;if(!(n in t)){t[n]=s,r[n]=o;continue}if(t[n]===s)continue;const e=r[n]?.constructor.name??this.constructor.name,l=o.constructor.name,a=i("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${e} and ${l}. 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{...t,...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(u(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(i(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(i(e,t,this.gridElement.id,this.name))}},h=/* @__PURE__ */new WeakMap;function g(e){return"__proto__"===e||"constructor"===e||"prototype"===e}var m=/* @__PURE__ */new Map;function p(e,t){if(null==e)return;const r=function(e){if(-1===e.indexOf("."))return null;let t=m.get(e);return void 0===t&&(t=Object.freeze(e.split(".")),m.set(e,t)),t}(t),o=e;return null===r?g(t)?void 0:o[t]:Object.prototype.hasOwnProperty.call(o,t)?o[t]:function(e,t){let r=e;for(let o=0;o<t.length;o++){if(null==r||"object"!=typeof r)return;const e=t[o];if(g(e))return;r=r[e]}return r}(o,r)}var b=new Intl.Collator(void 0,{sensitivity:"variant"});function C(e,t,r){if(!t.length)return;const o=t.map(e=>{const t=r.find(t=>t.field===e.field),o=t?.sortComparator??v,n=e.field,i=t?.valueAccessor?e=>function(e,t,r=-1){if(!t.valueAccessor)return p(e,t.field);if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:r});const o=e,n=t.field;let i=h.get(o);if(i){const e=i.get(n);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,h.set(o,i);const s=t.valueAccessor({row:e,column:t,rowIndex:r});return i.set(n,{v:s}),s}(e,t):e=>e[n];return{field:n,asc:"asc"===e.direction,comparator:o,getValue:i,pinPlaceholders:!t?.sortComparator}}),n=o.some(e=>e.pinPlaceholders)&&function(e){for(let t=0;t<e.length;t++)if(!0===e[t]?.__loading)return!0;return!1}(e),i=e.length,s=o.length,l=new Array(i*s);for(let u=0;u<i;u++){const t=e[u],r=u*s;for(let e=0;e<s;e++)l[r+e]=o[e].getValue(t)}const a=i<=4294967295?new Uint32Array(i):new Array(i);for(let u=0;u<i;u++)a[u]=u;const c=(t,r)=>{if(n){const o=function(e,t){const r=!0===e?.__loading;return r===(!0===t?.__loading)?0:r?1:-1}(e[t],e[r]);if(0!==o)return o}const i=t*s,a=r*s;for(let n=0;n<s;n++){const s=o[n],c=s.comparator(l[i+n],l[a+n],e[t],e[r]);if(0!==c)return s.asc?c:-c}return 0};Uint32Array,a.sort(c);const d=e.slice();for(let u=0;u<i;u++)e[u]=d[a[u]]}function v(e,t){return null==e&&null==t?0:null==e?1:null==t?-1:"number"==typeof e&&"number"==typeof t?e-t:e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():"boolean"==typeof e&&"boolean"==typeof t?e===t?0:e?-1:1:b.compare("string"==typeof e?e:String(e),"string"==typeof t?t:String(t))}function S(e,t){const r=e.findIndex(e=>e.field===t);return r>=0?r+1:void 0}function w(e,t){return e.find(e=>e.field===t)?.direction}var y=class extends f{static manifest={queries:[{type:"sort:get-model",description:"Returns the current multi-sort model as SortModel[]"},{type:"sort:set-model",description:"Sets the multi-sort model from context (SortModel[])"}]};name="multiSort";styles='@layer tbw-plugins{.header-cell[data-sort=asc]:after{content:"↑";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.header-cell[data-sort=desc]:after{content:"↓";margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-indicator{margin-left:var(--tbw-spacing-xs,.25em);opacity:.8}.sort-index{font-size:var(--tbw-font-size-2xs,.7em);background:var(--tbw-multi-sort-badge-bg,var(--tbw-color-panel-bg));color:var(--tbw-multi-sort-badge-color,var(--tbw-color-fg));width:var(--tbw-multi-sort-badge-size,1em);height:var(--tbw-multi-sort-badge-size,1em);margin-left:var(--tbw-spacing-xs,.125em);border-radius:50%;justify-content:center;align-items:center;font-weight:600;display:inline-flex}}';get defaultConfig(){return{maxSortColumns:3,showSortIndex:!0}}sortModel=[];cachedSortResult=null;#r=!1;#o=[];get#n(){return this.grid}clearCoreSortState(){this.#n._sortState=null}#i(e){const t=this.grid?.query?.("grouping:get-grouped-fields",null);if(!Array.isArray(t)||0===t.length)return e;const r=t[0];if(!Array.isArray(r)||0===r.length)return e;const o=new Set(r),n=e.filter(e=>!o.has(e.field));return n.length===e.length?e:n}detach(){this.sortModel=[],this.cachedSortResult=null}handleQuery(e){switch(e.type){case"sort:get-model":return[...this.sortModel];case"sort:set-model":{const t=e.context;return!!Array.isArray(t)&&(this.sortModel=[...t],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),!0)}default:return}}processRows(e){if(0===this.sortModel.length)return this.cachedSortResult=null,[...e];const t=this.#n;if(!t._isGridEditMode&&"number"==typeof t._activeEditRows&&-1!==t._activeEditRows&&this.cachedSortResult&&this.cachedSortResult.length===e.length)return[...this.cachedSortResult];const r=this.#i(this.sortModel),o=e;return r.length>0&&C(o,r,this.columns),this.cachedSortResult=o,o}onHeaderClick(e){if(!this.columns.find(t=>t.field===e.field)?.sortable)return!1;const t=e.originalEvent.shiftKey,n=this.config.maxSortColumns??3;if(this.sortModel=function(e,t,r,o){const n=e.find(e=>e.field===t);return r?n?"asc"===n.direction?e.map(e=>e.field===t?{...e,direction:"desc"}:e):e.filter(e=>e.field!==t):e.length<o?[...e,{field:t,direction:"asc"}]:e:"asc"===n?.direction?[{field:t,direction:"desc"}]:"desc"===n?.direction?[]:[{field:t,direction:"asc"}]}(this.sortModel,e.field,t,n),this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender(),this.grid?.requestStateChange?.(),this.sortModel.length>0){const e=this.sortModel.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",e.join(", then "),""))}else r(this.gridElement,o(this.gridElement,"sortCleared"));return!0}afterRender(){const e=this.gridElement;if(!e)return;const t=!1!==this.config.showSortIndex;e.querySelectorAll(".header-row .cell[data-field]").forEach(e=>{const r=e.getAttribute("data-field");if(!r)return;const o=S(this.sortModel,r),n=w(this.sortModel,r);if(e.querySelector(".sort-index")?.remove(),n){const r=this.updateSortIndicator(e,n);if(t&&this.sortModel.length>1&&void 0!==o){const t=document.createElement("span");t.className="sort-index",t.textContent=String(o),r.nextSibling?e.insertBefore(t,r.nextSibling):e.appendChild(t)}}else e.classList.contains("sortable")&&this.updateSortIndicator(e,null)})}getSortModel(){return[...this.sortModel]}setSortModel(e){if(this.sortModel=[...e],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[...e]}),this.requestRender(),this.grid?.requestStateChange?.(),e.length>0){const t=e.map(e=>`${this.columns.find(t=>t.field===e.field)?.header??e.field} ${"asc"===e.direction?"ascending":"descending"}`);r(this.gridElement,o(this.gridElement,"sortApplied",t.join(", then "),""))}}clearSort(){this.sortModel=[],this.clearCoreSortState(),this.broadcast("sort-change",{sortModel:[]}),this.requestRender(),this.grid?.requestStateChange?.(),r(this.gridElement,o(this.gridElement,"sortCleared"))}getSortIndex(e){return S(this.sortModel,e)}getSortDirection(e){return w(this.sortModel,e)}getColumnState(e){const t=this.sortModel.findIndex(t=>t.field===e);if(-1!==t)return{sort:{direction:this.sortModel[t].direction,priority:t}}}applyColumnState(e,t){if(this.#r||(this.#o=[...this.sortModel]),t.sort){const r=this.sortModel.findIndex(t=>t.field===e),o={field:e,direction:t.sort.direction};-1!==r?this.sortModel[r]=o:this.sortModel.splice(t.sort.priority,0,o)}else this.sortModel=this.sortModel.filter(t=>t.field!==e);this.clearCoreSortState(),this.#r||(this.#r=!0,queueMicrotask(()=>{this.#r=!1;const e=this.#o;this.#o=[],function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r].field!==t[r].field||e[r].direction!==t[r].direction)return!1;return!0}(e,this.sortModel)||(this.broadcast("sort-change",{sortModel:[...this.sortModel]}),this.requestRender())}))}};export{y as MultiSortPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|