@omnigrid/resize-plugin 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -38,6 +38,10 @@ export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
38
38
  private readonly onResize?;
39
39
  private readonly onResizeStart?;
40
40
  private readonly onResizeEnd?;
41
+ /** Set while an actual drag occurred during the current resize session. */
42
+ private resizeDragged;
43
+ /** Suppress the click synthesized right after a completed drag-resize. */
44
+ private suppressNextClick;
41
45
  constructor(options?: ColumnResizePluginOptions<T>);
42
46
  register(api: GridApi<T>): () => void;
43
47
  /**
package/dist/index.js CHANGED
@@ -12,6 +12,10 @@ export class ColumnResizePlugin {
12
12
  this.name = "@omnigrid/column-resize-plugin";
13
13
  this.wrappedRenderers = new Map();
14
14
  this.guide = { columnId: "", x: 0, visible: false };
15
+ /** Set while an actual drag occurred during the current resize session. */
16
+ this.resizeDragged = false;
17
+ /** Suppress the click synthesized right after a completed drag-resize. */
18
+ this.suppressNextClick = false;
15
19
  this.onResize = options.onResize;
16
20
  this.onResizeStart = options.onResizeStart;
17
21
  this.onResizeEnd = options.onResizeEnd;
@@ -127,6 +131,8 @@ export class ColumnResizePlugin {
127
131
  startWidth: currentWidth,
128
132
  direction: column?.pinned === "right" ? -1 : 1,
129
133
  };
134
+ this.resizeDragged = false;
135
+ this.suppressNextClick = false;
130
136
  this.guide = { columnId, x: clientX, visible: true };
131
137
  this.onResizeStart?.(columnId, currentWidth);
132
138
  return currentWidth;
@@ -168,6 +174,7 @@ export class ColumnResizePlugin {
168
174
  resizeBy(delta) {
169
175
  if (!this.activeResize)
170
176
  return 0;
177
+ this.resizeDragged = true;
171
178
  const { columnId, startWidth } = this.activeResize;
172
179
  const nextWidth = this.setColumnWidth(columnId, startWidth + delta);
173
180
  this.guide = { columnId, x: this.guide.x, visible: true };
@@ -185,6 +192,8 @@ export class ColumnResizePlugin {
185
192
  const width = this.getColumnWidth(active.columnId) ?? active.startWidth;
186
193
  this.onResizeEnd?.(active.columnId, width);
187
194
  this.clearGuide();
195
+ this.suppressNextClick = this.resizeDragged;
196
+ this.resizeDragged = false;
188
197
  this.activeResize = undefined;
189
198
  return width;
190
199
  }
@@ -277,8 +286,8 @@ export class ColumnResizePlugin {
277
286
  ? "omnigrid-column-resize-handle omnigrid-column-resize-handle-left"
278
287
  : "omnigrid-column-resize-handle";
279
288
  const contentStyle = column.pinned === "right"
280
- ? "position:relative; display:flex; align-items:center; width:calc(100% + 12px); margin-left:-12px; padding-left:12px; min-width:0;"
281
- : "position:relative; display:flex; align-items:center; width:calc(100% + 12px); margin-right:-12px; min-width:0;";
289
+ ? "display:flex; align-items:center; width:calc(100% + 12px); margin-left:-12px; padding-left:12px; min-width:0;"
290
+ : "display:flex; align-items:center; width:calc(100% + 12px); margin-right:-12px; min-width:0;";
282
291
  const sortIndicator = column.sortState && this.api
283
292
  ? {
284
293
  type: "node",
@@ -310,7 +319,12 @@ export class ColumnResizePlugin {
310
319
  {
311
320
  type: "node",
312
321
  tag: "span",
313
- attrs: { class: "omnigrid-header-label", style: "overflow:hidden; text-overflow:ellipsis; white-space:nowrap;" },
322
+ attrs: {
323
+ class: "omnigrid-header-label",
324
+ style: column.wrapText
325
+ ? "overflow:hidden; text-overflow:clip; white-space:normal; word-break:break-word;"
326
+ : "overflow:hidden; text-overflow:ellipsis; white-space:nowrap;",
327
+ },
314
328
  children: [content],
315
329
  },
316
330
  ...(sortIndicator
@@ -330,6 +344,9 @@ export class ColumnResizePlugin {
330
344
  class: handleClass,
331
345
  "aria-hidden": true,
332
346
  title: "Resize column",
347
+ style: column.pinned === "right"
348
+ ? "position:absolute; top:0; bottom:0; left:-8px;"
349
+ : "position:absolute; top:0; bottom:0; right:-8px;",
333
350
  },
334
351
  on: {
335
352
  pointerdown: (_context, event) => {
@@ -360,13 +377,24 @@ export class ColumnResizePlugin {
360
377
  return;
361
378
  this.endResize();
362
379
  };
380
+ // Swallow the click synthesized right after a completed drag-resize so it does
381
+ // not bubble up to the column header and trigger sorting. Capture phase stops it
382
+ // before it reaches React's root listener.
383
+ const handleClick = (event) => {
384
+ if (!this.suppressNextClick)
385
+ return;
386
+ this.suppressNextClick = false;
387
+ event.stopPropagation();
388
+ };
363
389
  document.addEventListener("pointermove", handlePointerMove);
364
390
  document.addEventListener("pointerup", handlePointerUp);
365
391
  document.addEventListener("pointercancel", handlePointerUp);
392
+ document.addEventListener("click", handleClick, true);
366
393
  return () => {
367
394
  document.removeEventListener("pointermove", handlePointerMove);
368
395
  document.removeEventListener("pointerup", handlePointerUp);
369
396
  document.removeEventListener("pointercancel", handlePointerUp);
397
+ document.removeEventListener("click", handleClick, true);
370
398
  };
371
399
  }
372
400
  findLeafColumn(columnId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/resize-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Headless column resize plugin for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",