@omnigrid/resize-plugin 0.1.6 → 0.1.7

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/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @omnigrid/resize-plugin
2
+
3
+ Headless column resize plugin for OmniGrid. Adds draggable resize handles and double-click auto-fit to leaf column headers, respecting `minWidth` / `maxWidth` and pinned / grouped layouts.
4
+
5
+ ## What it provides
6
+
7
+ - Drag a header handle to resize a leaf column; the group header above it tracks its children
8
+ - Double-click a header to auto-fit the column to the widest visible value
9
+ - Respects per-column `minWidth` / `maxWidth` and `resizable: false`
10
+ - Works with pinned left/right panes and column groups
11
+ - Emits `onResizeStart`, `onResize`, and `onResizeEnd` callbacks
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { Grid } from "@omnigrid/core";
17
+ import { ColumnResizePlugin } from "@omnigrid/resize-plugin";
18
+
19
+ const grid = new Grid({
20
+ columns: [
21
+ { id: "name", field: "name", header: "Name", resizable: true },
22
+ { id: "qty", field: "qty", header: "Qty", resizable: true },
23
+ ],
24
+ plugins: [
25
+ new ColumnResizePlugin({
26
+ onResize: (columnId, width) => console.log(columnId, width),
27
+ }),
28
+ ],
29
+ });
30
+ ```
31
+
32
+ ## Links
33
+
34
+ - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/resize
35
+ - **Demo:** https://omnigrid.cc/demo/react/plugins/base/resize
36
+ - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
37
+
38
+ ## License
39
+
40
+ MIT © KRZK Apps
package/dist/index.d.ts CHANGED
@@ -21,6 +21,8 @@ export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
21
21
  private resizeDragged;
22
22
  /** Suppress the click synthesized right after a completed drag-resize. */
23
23
  private suppressNextClick;
24
+ private pointerMoveFrame;
25
+ private pendingPointerX;
24
26
  constructor(options?: ColumnResizePluginOptions<T>);
25
27
  register(api: GridApi<T>): () => void;
26
28
  /**
@@ -123,6 +125,8 @@ export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
123
125
  private createResizeHandleNode;
124
126
  private bindPointerHandlers;
125
127
  private findLeafColumn;
128
+ private flushPendingPointerMove;
129
+ private cancelPendingPointerMove;
126
130
  private clampWidth;
127
131
  private withFixedWidth;
128
132
  private resolveCellValue;
package/dist/index.js CHANGED
@@ -15,6 +15,8 @@ export class ColumnResizePlugin {
15
15
  this.resizeDragged = false;
16
16
  /** Suppress the click synthesized right after a completed drag-resize. */
17
17
  this.suppressNextClick = false;
18
+ this.pointerMoveFrame = null;
19
+ this.pendingPointerX = null;
18
20
  this.onResize = options.onResize;
19
21
  this.onResizeStart = options.onResizeStart;
20
22
  this.onResizeEnd = options.onResizeEnd;
@@ -29,6 +31,7 @@ export class ColumnResizePlugin {
29
31
  const unregisterPointerHandlers = this.bindPointerHandlers();
30
32
  return () => {
31
33
  unregisterPointerHandlers();
34
+ this.cancelPendingPointerMove();
32
35
  unregisterHeaderExtension();
33
36
  this.clearGuide();
34
37
  this.activeResize = undefined;
@@ -127,6 +130,7 @@ export class ColumnResizePlugin {
127
130
  const currentWidth = this.getColumnWidth(columnId);
128
131
  if (currentWidth === undefined)
129
132
  return 0;
133
+ this.cancelPendingPointerMove();
130
134
  this.activeResize = {
131
135
  columnId,
132
136
  startX: clientX,
@@ -188,6 +192,7 @@ export class ColumnResizePlugin {
188
192
  * @api
189
193
  */
190
194
  endResize() {
195
+ this.flushPendingPointerMove();
191
196
  const active = this.activeResize;
192
197
  if (!active)
193
198
  return 0;
@@ -290,7 +295,16 @@ export class ColumnResizePlugin {
290
295
  const handlePointerMove = (event) => {
291
296
  if (!this.activeResize)
292
297
  return;
293
- this.resizeTo(event.clientX);
298
+ this.pendingPointerX = event.clientX;
299
+ if (this.pointerMoveFrame !== null)
300
+ return;
301
+ this.pointerMoveFrame = window.requestAnimationFrame(() => {
302
+ this.pointerMoveFrame = null;
303
+ const clientX = this.pendingPointerX;
304
+ this.pendingPointerX = null;
305
+ if (clientX !== null && this.activeResize)
306
+ this.resizeTo(clientX);
307
+ });
294
308
  };
295
309
  const handlePointerUp = () => {
296
310
  if (!this.activeResize)
@@ -322,6 +336,23 @@ export class ColumnResizePlugin {
322
336
  return undefined;
323
337
  return flattenColumns(this.api.getState().columns).find((column) => column.id === columnId);
324
338
  }
339
+ flushPendingPointerMove() {
340
+ if (this.pointerMoveFrame !== null && typeof window !== "undefined") {
341
+ window.cancelAnimationFrame(this.pointerMoveFrame);
342
+ }
343
+ this.pointerMoveFrame = null;
344
+ const clientX = this.pendingPointerX;
345
+ this.pendingPointerX = null;
346
+ if (clientX !== null && this.activeResize)
347
+ this.resizeTo(clientX);
348
+ }
349
+ cancelPendingPointerMove() {
350
+ if (this.pointerMoveFrame !== null && typeof window !== "undefined") {
351
+ window.cancelAnimationFrame(this.pointerMoveFrame);
352
+ }
353
+ this.pointerMoveFrame = null;
354
+ this.pendingPointerX = null;
355
+ }
325
356
  clampWidth(column, width) {
326
357
  const minimum = column.minWidth ?? 0;
327
358
  const maximum = column.maxWidth ?? Number.POSITIVE_INFINITY;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/resize-plugin",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Headless column resize plugin for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",
@@ -13,7 +13,7 @@
13
13
  "url": "https://github.com/KRZK-Apps/omnigrid.git",
14
14
  "directory": "plugins/base/resize"
15
15
  },
16
- "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/resize#readme",
16
+ "homepage": "https://omnigrid.cc/demo/react/plugins/base/resize",
17
17
  "bugs": {
18
18
  "url": "https://github.com/KRZK-Apps/omnigrid/issues"
19
19
  },