@toolbox-web/grid 2.3.0 → 2.4.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 (106) hide show
  1. package/all.d.ts +1 -0
  2. package/all.js +2 -2
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +2 -1
  7. package/lib/core/internal/aria.d.ts +13 -0
  8. package/lib/core/internal/diagnostics.d.ts +5 -1
  9. package/lib/core/internal/dom-builder.d.ts +0 -25
  10. package/lib/core/internal/drag-drop-registry.d.ts +66 -0
  11. package/lib/core/internal/render-scheduler.d.ts +9 -8
  12. package/lib/core/plugin/base-plugin.d.ts +23 -0
  13. package/lib/core/plugin/plugin-manager.d.ts +9 -0
  14. package/lib/core/types.d.ts +67 -46
  15. package/lib/features/registry.js.map +1 -1
  16. package/lib/features/reorder-rows.d.ts +3 -3
  17. package/lib/features/reorder-rows.js +1 -1
  18. package/lib/features/reorder-rows.js.map +1 -1
  19. package/lib/features/row-drag-drop.d.ts +9 -0
  20. package/lib/features/row-drag-drop.js +2 -0
  21. package/lib/features/row-drag-drop.js.map +1 -0
  22. package/lib/features/server-side.js.map +1 -1
  23. package/lib/plugins/clipboard/index.js +1 -1
  24. package/lib/plugins/clipboard/index.js.map +1 -1
  25. package/lib/plugins/column-virtualization/index.js +1 -1
  26. package/lib/plugins/column-virtualization/index.js.map +1 -1
  27. package/lib/plugins/context-menu/index.js +1 -1
  28. package/lib/plugins/context-menu/index.js.map +1 -1
  29. package/lib/plugins/editing/index.js +1 -1
  30. package/lib/plugins/editing/index.js.map +1 -1
  31. package/lib/plugins/export/ExportPlugin.d.ts +89 -0
  32. package/lib/plugins/export/index.d.ts +3 -2
  33. package/lib/plugins/export/index.js +1 -1
  34. package/lib/plugins/export/index.js.map +1 -1
  35. package/lib/plugins/export/types.d.ts +30 -0
  36. package/lib/plugins/filtering/FilteringPlugin.d.ts +15 -0
  37. package/lib/plugins/filtering/index.js +1 -1
  38. package/lib/plugins/filtering/index.js.map +1 -1
  39. package/lib/plugins/grouping-columns/index.js +1 -1
  40. package/lib/plugins/grouping-columns/index.js.map +1 -1
  41. package/lib/plugins/grouping-rows/index.js +2 -2
  42. package/lib/plugins/grouping-rows/index.js.map +1 -1
  43. package/lib/plugins/master-detail/index.js +1 -1
  44. package/lib/plugins/master-detail/index.js.map +1 -1
  45. package/lib/plugins/multi-sort/index.js +1 -1
  46. package/lib/plugins/multi-sort/index.js.map +1 -1
  47. package/lib/plugins/pinned-columns/index.js +1 -1
  48. package/lib/plugins/pinned-columns/index.js.map +1 -1
  49. package/lib/plugins/pinned-rows/index.js +1 -1
  50. package/lib/plugins/pinned-rows/index.js.map +1 -1
  51. package/lib/plugins/pivot/index.js +1 -1
  52. package/lib/plugins/pivot/index.js.map +1 -1
  53. package/lib/plugins/print/index.js +1 -1
  54. package/lib/plugins/print/index.js.map +1 -1
  55. package/lib/plugins/reorder-columns/index.js +1 -1
  56. package/lib/plugins/reorder-columns/index.js.map +1 -1
  57. package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts +14 -156
  58. package/lib/plugins/reorder-rows/index.d.ts +10 -4
  59. package/lib/plugins/reorder-rows/index.js +1 -1
  60. package/lib/plugins/reorder-rows/index.js.map +1 -1
  61. package/lib/plugins/reorder-rows/types.d.ts +9 -86
  62. package/lib/plugins/responsive/index.js +1 -1
  63. package/lib/plugins/responsive/index.js.map +1 -1
  64. package/lib/plugins/row-drag-drop/RowDragDropPlugin.d.ts +146 -0
  65. package/lib/plugins/row-drag-drop/index.d.ts +9 -0
  66. package/lib/plugins/row-drag-drop/index.js +2 -0
  67. package/lib/plugins/row-drag-drop/index.js.map +1 -0
  68. package/lib/plugins/row-drag-drop/types.d.ts +276 -0
  69. package/lib/plugins/selection/index.js +1 -1
  70. package/lib/plugins/selection/index.js.map +1 -1
  71. package/lib/plugins/server-side/ServerSidePlugin.d.ts +13 -0
  72. package/lib/plugins/server-side/datasource-types.d.ts +54 -7
  73. package/lib/plugins/server-side/datasource.d.ts +10 -2
  74. package/lib/plugins/server-side/index.d.ts +1 -1
  75. package/lib/plugins/server-side/index.js +1 -1
  76. package/lib/plugins/server-side/index.js.map +1 -1
  77. package/lib/plugins/server-side/types.d.ts +1 -1
  78. package/lib/plugins/shared/drag-drop-protocol.d.ts +98 -0
  79. package/lib/plugins/tooltip/index.js +1 -1
  80. package/lib/plugins/tooltip/index.js.map +1 -1
  81. package/lib/plugins/tree/TreePlugin.d.ts +19 -6
  82. package/lib/plugins/tree/index.js +1 -1
  83. package/lib/plugins/tree/index.js.map +1 -1
  84. package/lib/plugins/undo-redo/index.js +1 -1
  85. package/lib/plugins/undo-redo/index.js.map +1 -1
  86. package/lib/plugins/visibility/index.js +1 -1
  87. package/lib/plugins/visibility/index.js.map +1 -1
  88. package/package.json +1 -1
  89. package/umd/grid.all.umd.js +1 -1
  90. package/umd/grid.all.umd.js.map +1 -1
  91. package/umd/grid.umd.js +1 -1
  92. package/umd/grid.umd.js.map +1 -1
  93. package/umd/plugins/export.umd.js +1 -1
  94. package/umd/plugins/export.umd.js.map +1 -1
  95. package/umd/plugins/filtering.umd.js +1 -1
  96. package/umd/plugins/filtering.umd.js.map +1 -1
  97. package/umd/plugins/reorder-rows.umd.js +1 -1
  98. package/umd/plugins/reorder-rows.umd.js.map +1 -1
  99. package/umd/plugins/row-drag-drop.umd.js +2 -0
  100. package/umd/plugins/row-drag-drop.umd.js.map +1 -0
  101. package/umd/plugins/selection.umd.js +1 -1
  102. package/umd/plugins/selection.umd.js.map +1 -1
  103. package/umd/plugins/server-side.umd.js +1 -1
  104. package/umd/plugins/server-side.umd.js.map +1 -1
  105. package/umd/plugins/tree.umd.js +1 -1
  106. package/umd/plugins/tree.umd.js.map +1 -1
@@ -1,5 +1,5 @@
1
1
  import { ServerSideDataSource } from './datasource-types';
2
- export type { DataRequestModel, DataSourceChildrenDetail, DataSourceDataDetail, DataSourceErrorDetail, DataSourceLoadingDetail, FetchChildrenQuery, GetChildRowsParams, GetChildRowsResult, GetRowsParams, GetRowsResult, ServerSideDataSource, ViewportMappingQuery, ViewportMappingResponse, } from './datasource-types';
2
+ export type { DataRequestModel, DataSourceChildrenDetail, DataSourceDataDetail, DataSourceErrorDetail, DataSourceLoadingDetail, FetchChildrenQuery, GetChildRowsParams, GetChildRowsResult, GetRowsParams, GetRowsResult, ServerSideDataSource, Subscribable, ViewportMappingQuery, ViewportMappingResponse } from './datasource-types';
3
3
  /**
4
4
  * Configuration for the server-side data plugin.
5
5
  *
@@ -0,0 +1,98 @@
1
+ import { ColumnConfig } from '../../core/types';
2
+ /** @internal */
3
+ export declare function setCurrentDragSession<T>(sessionId: string, payload: RowDragPayload<T>): void;
4
+ /** @internal */
5
+ export declare function getCurrentDragSession<T = unknown>(): {
6
+ sessionId: string;
7
+ payload: RowDragPayload<T>;
8
+ } | null;
9
+ /** @internal */
10
+ export declare function clearCurrentDragSession(): void;
11
+ /** Base MIME type carried on `dataTransfer` for tbw row drags. */
12
+ export declare const TBW_ROW_DRAG_MIME = "application/x-tbw-grid-rows+json";
13
+ /** Build a zone-tagged MIME type, visible in `dataTransfer.types` during dragover. */
14
+ export declare function mimeForZone(zone: string): string;
15
+ /** Extract the zone from a tagged MIME, or `null` if untagged. */
16
+ export declare function parseZoneFromMime(mime: string): string | null;
17
+ /**
18
+ * Find the first MIME entry in `types` whose zone matches `zone`.
19
+ * Used during `dragover` for the accept-check (browsers hide `getData()`
20
+ * during dragover, but `types` is always visible).
21
+ */
22
+ export declare function findMatchingZoneMime(types: readonly string[], zone: string): string | null;
23
+ /** Returns true if any tbw row-drag MIME is present in `types`. */
24
+ export declare function hasAnyRowDragMime(types: readonly string[]): boolean;
25
+ /**
26
+ * Cross-grid drag payload, carried on `dataTransfer` and (for same-window
27
+ * recovery) keyed in the WeakRef registry by `sessionId`.
28
+ */
29
+ export interface RowDragPayload<T = unknown> {
30
+ /** Drag session id (matches the WeakRef registry key). */
31
+ sessionId: string;
32
+ /** Source grid id (`grid.id` or auto-generated UUID). */
33
+ sourceGridId: string;
34
+ /** Drop zone the source grid is participating in. */
35
+ dropZone: string;
36
+ /** Serialized row payload (JSON-safe). For same-window drops, recovered live via the registry. */
37
+ rows: T[];
38
+ /** Original indices in the source grid's `_rows` array. */
39
+ rowIndices: number[];
40
+ /** Move (default) removes from source; copy leaves source intact. */
41
+ operation: 'move' | 'copy';
42
+ }
43
+ /** Encode a payload to the JSON string written to `dataTransfer`. */
44
+ export declare function encodePayload<T>(payload: RowDragPayload<T>): string;
45
+ /** Decode a payload from the JSON string read off `dataTransfer`. */
46
+ export declare function decodePayload<T = unknown>(raw: string): RowDragPayload<T> | null;
47
+ export interface DropPosition {
48
+ /** Target visual row index that the cursor is over, or `null` for empty area. */
49
+ overIndex: number | null;
50
+ /** Final insertion index in the target grid's `_rows`. */
51
+ insertIndex: number;
52
+ /** True when the cursor is above the row midpoint. */
53
+ isBefore: boolean;
54
+ }
55
+ /**
56
+ * Compute the insertion index for a drop, given the row element under the
57
+ * cursor (if any), the cursor's clientY, and the total row count when the
58
+ * cursor is in empty space below the last row.
59
+ *
60
+ * - Cursor above row midpoint → insert at `targetIndex`
61
+ * - Cursor below row midpoint → insert at `targetIndex + 1`
62
+ * - Cursor over empty area below the last row → append (`insertIndex = totalRows`)
63
+ */
64
+ export declare function computeDropPosition(rowEl: HTMLElement | null, clientY: number, rowIndexResolver: (el: HTMLElement) => number, totalRows: number): DropPosition;
65
+ export interface AutoScrollOptions {
66
+ /** Pixels from the top/bottom edge that activate auto-scroll. */
67
+ edgeSize?: number;
68
+ /** Base scroll speed in pixels-per-frame near the edge. */
69
+ speed?: number;
70
+ /** Max speed at the very edge (linear ramp from `speed` → `maxSpeed`). */
71
+ maxSpeed?: number;
72
+ }
73
+ export interface AutoScroller {
74
+ /** Update pointer position; starts the rAF loop if needed. */
75
+ onPointerMove(clientY: number): void;
76
+ /** Stop the rAF loop and reset state. */
77
+ stop(): void;
78
+ /** True when actively auto-scrolling. */
79
+ readonly isScrolling: boolean;
80
+ }
81
+ /**
82
+ * Create an auto-scroller for a viewport element.
83
+ *
84
+ * The scroller runs a `requestAnimationFrame` loop only while the pointer is
85
+ * within `edgeSize` of the viewport's top or bottom and there is room to
86
+ * scroll. Speed ramps linearly from `speed` (at the edge boundary) to
87
+ * `maxSpeed` (at the very edge).
88
+ */
89
+ export declare function createAutoScroller(viewport: HTMLElement, options?: AutoScrollOptions, onScrollChange?: (active: boolean) => void): AutoScroller;
90
+ /**
91
+ * Format rows as a TSV string for the `text/plain` drag fallback.
92
+ * Used when the drop target is an external app (Excel, Notepad, Slack).
93
+ *
94
+ * - One row per line, fields separated by `\t`.
95
+ * - Tabs and newlines in cell values are replaced with spaces.
96
+ * - Skips columns flagged as `utility` (drag handle, checkbox, etc.).
97
+ */
98
+ export declare function formatRowsAsTSV<T extends Record<string, unknown>>(rows: readonly T[], columns: readonly ColumnConfig[]): string;
@@ -1,2 +1,2 @@
1
- function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,o,r,i){return`${t(r,i)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}const 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(t=>t.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${o.slice(3).join("|")}|this\\b`);const r=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("|")),i=/^on\w+$/i,n=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),s=/^\s*(javascript|vbscript|data|blob):/i;function a(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const a of o){const t=a.tagName.toLowerCase();if(r.has(t)){e.push(a);continue}if("svg"===t||"http://www.w3.org/2000/svg"===a.namespaceURI){if(Array.from(a.attributes).some(t=>i.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(a);continue}}const o=[];for(const e of a.attributes){const t=e.name.toLowerCase();i.test(t)?o.push(e.name):(n.has(t)&&s.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name)}o.forEach(t=>a.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}const l='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',p={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:l,filterActive:l,print:"🖨️"};class c{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const o=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...p,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(e,10);if(!isNaN(o))return o}return 200}setIcon(t,e,o){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,o);void 0!==r?"string"==typeof r?t.innerHTML=a(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(r.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(o,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(o,r):t.appendChild(o),o}warn(o,r){void 0!==r?console.warn(e(o,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${o}`)}throwDiagnostic(t,o){throw new Error(e(t,o,this.gridElement.id,this.name))}}function d(t){return t.scrollWidth>t.clientWidth}function h(){return"function"==typeof HTMLElement.prototype?.showPopover}class u extends c{name="tooltip";styles='@layer tbw-plugins{.tbw-tooltip-popover{margin:0;padding:var(--tbw-tooltip-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-tooltip-bg, light-dark(#333338, #484850));color:var(--tbw-tooltip-fg, light-dark(#f5f5f5, #f0f0f0));border:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-radius:var(--tbw-tooltip-radius, var(--tbw-border-radius, .25rem));box-shadow:none;filter:var(--tbw-tooltip-shadow, drop-shadow(0 4px 4px rgba(0, 0, 0, .45)));font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-tooltip-font-size, var(--tbw-font-size-sm, .9285em));max-width:var(--tbw-tooltip-max-width, 300px);white-space:pre-line;word-wrap:break-word;overflow-wrap:break-word;pointer-events:none;z-index:10001}.tbw-tooltip-popover:after{content:"";position:absolute;width:var(--tbw-tooltip-arrow-size, 14px);height:var(--tbw-tooltip-arrow-size, 14px);left:var(--tbw-tooltip-arrow-offset, 16px);background:inherit;pointer-events:none}.tbw-tooltip-popover:not(.tbw-tooltip-above):after{top:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-top:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-left:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}.tbw-tooltip-popover.tbw-tooltip-above:after{bottom:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-bottom:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-right:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}@supports (anchor-name: --test){.tbw-tooltip-popover{position-anchor:--tbw-tooltip-anchor;top:calc(anchor(bottom) + 11px);left:anchor(left);position-try-fallbacks:--tbw-tooltip-flip-above}@position-try --tbw-tooltip-flip-above{top:auto;bottom:calc(anchor(top) + 11px)}}}';static manifest={ownedProperties:[{property:"cellTooltip",level:"column",description:'the "cellTooltip" column property'},{property:"headerTooltip",level:"column",description:'the "headerTooltip" column property'}],configRules:[]};#o=null;#r=null;#i=!1;get#n(){return!1!==this.config.header}get#s(){return!1!==this.config.cell}attach(t){super.attach(t)}detach(){this.#a(),this.#o?.remove(),this.#o=null,this.#i=!1,super.detach()}afterRender(){this.#l(),this.#p()}#l(){if(this.#o)return;const t=document.createElement("div");t.className="tbw-tooltip-popover",t.setAttribute("popover","hint"),t.style.overflow="visible",t.style.margin="0",document.body.appendChild(t),this.#o=t}#c(t,e){if(this.#o){if(this.#d(),t.style.setProperty("anchor-name","--tbw-tooltip-anchor"),this.#r=t,this.#o.textContent=e,h())try{this.#o.showPopover()}catch{}"undefined"!=typeof CSS&&!0===CSS.supports?.("anchor-name","--test")?requestAnimationFrame(()=>this.#h(t)):this.#u(t)}}#a(){if(this.#o){if(h())try{this.#o.hidePopover()}catch{}this.#o.classList.remove("tbw-tooltip-above")}this.#d()}#d(){this.#r&&("--tbw-tooltip-anchor"===this.#r.style.getPropertyValue("anchor-name")&&this.#r.style.removeProperty("anchor-name"),this.#r=null)}#u(t){if(!this.#o)return;const e=t.getBoundingClientRect();this.#o.style.position="fixed",this.#o.style.left=`${e.left}px`;window.innerHeight-e.bottom<80?(this.#o.style.top="",this.#o.style.bottom=window.innerHeight-e.top+11+"px",this.#o.classList.add("tbw-tooltip-above")):(this.#o.style.top=`${e.bottom+11}px`,this.#o.style.bottom="",this.#o.classList.remove("tbw-tooltip-above"))}#h(t){if(!this.#o)return;const e=t.getBoundingClientRect(),o=this.#o.getBoundingClientRect();this.#o.classList.toggle("tbw-tooltip-above",o.bottom<=e.top)}#p(){if(this.#i)return;const t=this.gridElement?.querySelector(".tbw-grid-root");t&&(this.#i=!0,t.addEventListener("mouseover",t=>this.#f(t),{signal:this.disconnectSignal}),t.addEventListener("mouseout",t=>this.#b(t),{signal:this.disconnectSignal}))}#f(t){const e=t.target;if(!e?.closest)return;const o=e.closest('[part~="header-cell"]');if(o&&this.#n)return void this.#g(o);const r=e.closest("[data-row][data-col]");r&&this.#s&&!r.style.getPropertyValue("anchor-name")&&this.#m(r)}#b(t){const e=t.target;if(!e?.closest)return;const o=e.closest('[part~="header-cell"], [data-row][data-col]');if(!o)return;const r=t.relatedTarget;r&&o.contains(r)||this.#a()}#g(t){const e=parseInt(t.getAttribute("data-col")??"-1",10);if(e<0)return;const o=this.visibleColumns[e];if(!o)return;const r=function(t,e){const o=t.headerTooltip;if(!1===o)return null;if("string"==typeof o)return o;if("function"==typeof o)return o({column:t,value:t.header??t.field});const r=e.querySelector("span:first-child")??e;return d(r)&&r.textContent?.trim()||null}(o,t);r&&this.#c(t,r)}#m(t){const e=parseInt(t.getAttribute("data-row")??"-1",10),o=parseInt(t.getAttribute("data-col")??"-1",10);if(e<0||o<0)return;const r=this.visibleColumns[o];if(!r)return;const i=this.rows[e],n=i?.[r.field],s=function(t,e,o,r,i){const n=t.cellTooltip;if(!1===n)return null;if("string"==typeof n)return n;if("function"==typeof n)return n({value:r,row:o,column:t,field:t.field,grid:i});return d(e)&&e.textContent?.trim()||null}(r,t,i,n,this.grid);s&&this.#c(t,s)}}export{u as TooltipPlugin};
1
+ function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function e(e,o,r,i){return`${t(r,i)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}const 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(t=>t.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${o.slice(3).join("|")}|this\\b`);const r=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("|")),i=/^on\w+$/i,n=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),s=/^\s*(javascript|vbscript|data|blob):/i;function a(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const a of o){const t=a.tagName.toLowerCase();if(r.has(t)){e.push(a);continue}if("svg"===t||"http://www.w3.org/2000/svg"===a.namespaceURI){if(Array.from(a.attributes).some(t=>i.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(a);continue}}const o=[];for(const e of a.attributes){const t=e.name.toLowerCase();i.test(t)?o.push(e.name):(n.has(t)&&s.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name)}o.forEach(t=>a.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}const l={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};class c{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}mergeConfigsFrom(t){if(0===t.length)return;const o={...this.userConfig},r={};for(const e of Object.keys(o))r[e]=this;for(const i of t){const t=i.userConfig;for(const[n,s]of Object.entries(t)){if(void 0===s)continue;if(!(n in o)){o[n]=s,r[n]=i;continue}if(o[n]===s)continue;const t=r[n]?.constructor.name??this.constructor.name,a=i.constructor.name,l=e("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} 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,o)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const o=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...l,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(e,10);if(!isNaN(o))return o}return 200}setIcon(t,e,o){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,o);void 0!==r?"string"==typeof r?t.innerHTML=a(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(r.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(o,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(o,r):t.appendChild(o),o}warn(o,r){void 0!==r?console.warn(e(o,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${o}`)}throwDiagnostic(t,o){throw new Error(e(t,o,this.gridElement.id,this.name))}}function p(t){return t.scrollWidth>t.clientWidth}function d(){return"function"==typeof HTMLElement.prototype?.showPopover}class h extends c{name="tooltip";styles='@layer tbw-plugins{.tbw-tooltip-popover{margin:0;padding:var(--tbw-tooltip-padding, var(--tbw-spacing-sm, .375rem) var(--tbw-spacing-md, .5rem));background:var(--tbw-tooltip-bg, light-dark(#333338, #484850));color:var(--tbw-tooltip-fg, light-dark(#f5f5f5, #f0f0f0));border:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-radius:var(--tbw-tooltip-radius, var(--tbw-border-radius, .25rem));box-shadow:none;filter:var(--tbw-tooltip-shadow, drop-shadow(0 4px 4px rgba(0, 0, 0, .45)));font-family:var(--tbw-font-family, system-ui, sans-serif);font-size:var(--tbw-tooltip-font-size, var(--tbw-font-size-sm, .9285em));max-width:var(--tbw-tooltip-max-width, 300px);white-space:pre-line;word-wrap:break-word;overflow-wrap:break-word;pointer-events:none;z-index:10001}.tbw-tooltip-popover:after{content:"";position:absolute;width:var(--tbw-tooltip-arrow-size, 14px);height:var(--tbw-tooltip-arrow-size, 14px);left:var(--tbw-tooltip-arrow-offset, 16px);background:inherit;pointer-events:none}.tbw-tooltip-popover:not(.tbw-tooltip-above):after{top:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-top:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-left:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}.tbw-tooltip-popover.tbw-tooltip-above:after{bottom:calc(var(--tbw-tooltip-arrow-size, 14px) / -2);transform:rotate(45deg);border-bottom:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72));border-right:1px solid var(--tbw-tooltip-border, light-dark(#222226, #6a6a72))}@supports (anchor-name: --test){.tbw-tooltip-popover{position-anchor:--tbw-tooltip-anchor;top:calc(anchor(bottom) + 11px);left:anchor(left);position-try-fallbacks:--tbw-tooltip-flip-above}@position-try --tbw-tooltip-flip-above{top:auto;bottom:calc(anchor(top) + 11px)}}}';static manifest={ownedProperties:[{property:"cellTooltip",level:"column",description:'the "cellTooltip" column property'},{property:"headerTooltip",level:"column",description:'the "headerTooltip" column property'}],configRules:[]};#o=null;#r=null;#i=!1;get#n(){return!1!==this.config.header}get#s(){return!1!==this.config.cell}attach(t){super.attach(t)}detach(){this.#a(),this.#o?.remove(),this.#o=null,this.#i=!1,super.detach()}afterRender(){this.#l(),this.#c()}#l(){if(this.#o)return;const t=document.createElement("div");t.className="tbw-tooltip-popover",t.setAttribute("popover","hint"),t.style.overflow="visible",t.style.margin="0",document.body.appendChild(t),this.#o=t}#p(t,e){if(this.#o){if(this.#d(),t.style.setProperty("anchor-name","--tbw-tooltip-anchor"),this.#r=t,this.#o.textContent=e,d())try{this.#o.showPopover()}catch{}"undefined"!=typeof CSS&&!0===CSS.supports?.("anchor-name","--test")?requestAnimationFrame(()=>this.#h(t)):this.#u(t)}}#a(){if(this.#o){if(d())try{this.#o.hidePopover()}catch{}this.#o.classList.remove("tbw-tooltip-above")}this.#d()}#d(){this.#r&&("--tbw-tooltip-anchor"===this.#r.style.getPropertyValue("anchor-name")&&this.#r.style.removeProperty("anchor-name"),this.#r=null)}#u(t){if(!this.#o)return;const e=t.getBoundingClientRect();this.#o.style.position="fixed",this.#o.style.left=`${e.left}px`;window.innerHeight-e.bottom<80?(this.#o.style.top="",this.#o.style.bottom=window.innerHeight-e.top+11+"px",this.#o.classList.add("tbw-tooltip-above")):(this.#o.style.top=`${e.bottom+11}px`,this.#o.style.bottom="",this.#o.classList.remove("tbw-tooltip-above"))}#h(t){if(!this.#o)return;const e=t.getBoundingClientRect(),o=this.#o.getBoundingClientRect();this.#o.classList.toggle("tbw-tooltip-above",o.bottom<=e.top)}#c(){if(this.#i)return;const t=this.gridElement?.querySelector(".tbw-grid-root");t&&(this.#i=!0,t.addEventListener("mouseover",t=>this.#f(t),{signal:this.disconnectSignal}),t.addEventListener("mouseout",t=>this.#g(t),{signal:this.disconnectSignal}))}#f(t){const e=t.target;if(!e?.closest)return;const o=e.closest('[part~="header-cell"]');if(o&&this.#n)return void this.#b(o);const r=e.closest("[data-row][data-col]");r&&this.#s&&!r.style.getPropertyValue("anchor-name")&&this.#m(r)}#g(t){const e=t.target;if(!e?.closest)return;const o=e.closest('[part~="header-cell"], [data-row][data-col]');if(!o)return;const r=t.relatedTarget;r&&o.contains(r)||this.#a()}#b(t){const e=parseInt(t.getAttribute("data-col")??"-1",10);if(e<0)return;const o=this.visibleColumns[e];if(!o)return;const r=function(t,e){const o=t.headerTooltip;if(!1===o)return null;if("string"==typeof o)return o;if("function"==typeof o)return o({column:t,value:t.header??t.field});const r=e.querySelector("span:first-child")??e;return p(r)&&r.textContent?.trim()||null}(o,t);r&&this.#p(t,r)}#m(t){const e=parseInt(t.getAttribute("data-row")??"-1",10),o=parseInt(t.getAttribute("data-col")??"-1",10);if(e<0||o<0)return;const r=this.visibleColumns[o];if(!r)return;const i=this.rows[e],n=i?.[r.field],s=function(t,e,o,r,i){const n=t.cellTooltip;if(!1===n)return null;if("string"==typeof n)return n;if("function"==typeof n)return n({value:r,row:o,column:t,field:t.field,grid:i});return p(e)&&e.textContent?.trim()||null}(r,t,i,n,this.grid);s&&this.#p(t,s)}}export{h as TooltipPlugin};
2
2
  //# sourceMappingURL=index.js.map