@omnigrid/resize-plugin 0.1.2 → 0.1.4

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
@@ -1,26 +1,6 @@
1
1
  import type { GridApi, GridPlugin } from "@omnigrid/core";
2
- /**
3
- * Live drag-guide state for the currently resizing column.
4
- */
5
- export interface ColumnResizeGuide {
6
- /** ID of the column being resized. */
7
- columnId: string;
8
- /** Current pointer x-coordinate, in viewport pixels. */
9
- x: number;
10
- /** Whether the guide is currently visible. */
11
- visible: boolean;
12
- }
13
- /**
14
- * Configuration for the column resize plugin.
15
- */
16
- export interface ColumnResizePluginOptions<T> {
17
- /** Called with the column id and clamped width each time the width changes during a drag. */
18
- onResize?: (columnId: string, width: number) => void;
19
- /** Called when a drag begins, with the column id and its starting width. */
20
- onResizeStart?: (columnId: string, width: number) => void;
21
- /** Called when a drag completes, with the column id and its final width. */
22
- onResizeEnd?: (columnId: string, width: number) => void;
23
- }
2
+ import type { ColumnResizeGuide, ColumnResizePluginOptions } from "./types";
3
+ export type { ColumnResizeGuide, ColumnResizePluginOptions } from "./types";
24
4
  /**
25
5
  * Headless column-resize controller.
26
6
  *
@@ -38,6 +18,10 @@ export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
38
18
  private readonly onResize?;
39
19
  private readonly onResizeStart?;
40
20
  private readonly onResizeEnd?;
21
+ /** Set while an actual drag occurred during the current resize session. */
22
+ private resizeDragged;
23
+ /** Suppress the click synthesized right after a completed drag-resize. */
24
+ private suppressNextClick;
41
25
  constructor(options?: ColumnResizePluginOptions<T>);
42
26
  register(api: GridApi<T>): () => void;
43
27
  /**
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) {
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Live drag-guide state for the currently resizing column.
3
+ */
4
+ export interface ColumnResizeGuide {
5
+ /** ID of the column being resized. */
6
+ columnId: string;
7
+ /** Current pointer x-coordinate, in viewport pixels. */
8
+ x: number;
9
+ /** Whether the guide is currently visible. */
10
+ visible: boolean;
11
+ }
12
+ /**
13
+ * Configuration for the column resize plugin.
14
+ */
15
+ export interface ColumnResizePluginOptions<T> {
16
+ /** Called with the column id and clamped width each time the width changes during a drag. */
17
+ onResize?: (columnId: string, width: number) => void;
18
+ /** Called when a drag begins, with the column id and its starting width. */
19
+ onResizeStart?: (columnId: string, width: number) => void;
20
+ /** Called when a drag completes, with the column id and its final width. */
21
+ onResizeEnd?: (columnId: string, width: number) => void;
22
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
1
  {
2
- "name": "@omnigrid/resize-plugin",
3
- "version": "0.1.2",
4
- "description": "Headless column resize plugin for OmniGrid",
5
- "keywords": [
6
- "omnigrid",
7
- "grid",
8
- "resize",
9
- "plugin"
10
- ],
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/KRZK-Apps/omnigrid.git",
14
- "directory": "plugins/base/resize"
15
- },
16
- "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/resize#readme",
17
- "bugs": {
18
- "url": "https://github.com/KRZK-Apps/omnigrid/issues"
19
- },
20
- "license": "MIT",
21
- "type": "module",
22
- "main": "dist/index.js",
23
- "types": "dist/index.d.ts",
24
- "exports": {
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js"
2
+ "name": "@omnigrid/resize-plugin",
3
+ "version": "0.1.4",
4
+ "description": "Headless column resize plugin for OmniGrid",
5
+ "keywords": [
6
+ "omnigrid",
7
+ "grid",
8
+ "resize",
9
+ "plugin"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/KRZK-Apps/omnigrid.git",
14
+ "directory": "plugins/base/resize"
15
+ },
16
+ "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/resize#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/KRZK-Apps/omnigrid/issues"
19
+ },
20
+ "license": "MIT",
21
+ "type": "module",
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "npx tsc -p tsconfig.json",
35
+ "lint": "npx tsc --noEmit -p tsconfig.json",
36
+ "test": "vitest run",
37
+ "prepublishOnly": "npm run build"
38
+ },
39
+ "dependencies": {
40
+ "@omnigrid/core": "^0.1.0"
28
41
  }
29
- },
30
- "files": [
31
- "dist"
32
- ],
33
- "scripts": {
34
- "build": "npx tsc -p tsconfig.json",
35
- "lint": "npx tsc --noEmit -p tsconfig.json",
36
- "test": "vitest run",
37
- "prepublishOnly": "npm run build"
38
- },
39
- "dependencies": {
40
- "@omnigrid/core": "^0.1.0"
41
- }
42
42
  }