@omnigrid/resize-plugin 0.1.3 → 0.1.5
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 +2 -26
- package/dist/index.js +22 -102
- package/dist/types.d.ts +22 -0
- package/dist/types.js +1 -0
- package/package.json +39 -39
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import type { GridApi, GridPlugin } from "@omnigrid/core";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
*
|
|
@@ -32,7 +12,6 @@ export interface ColumnResizePluginOptions<T> {
|
|
|
32
12
|
export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
|
|
33
13
|
readonly name = "@omnigrid/column-resize-plugin";
|
|
34
14
|
private api?;
|
|
35
|
-
private readonly wrappedRenderers;
|
|
36
15
|
private activeResize?;
|
|
37
16
|
private guide;
|
|
38
17
|
private readonly onResize?;
|
|
@@ -141,9 +120,6 @@ export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
|
|
|
141
120
|
*/
|
|
142
121
|
clearGuide(): void;
|
|
143
122
|
private canResizeColumn;
|
|
144
|
-
private attachResizeHandles;
|
|
145
|
-
/** Restores the original header renderers that were wrapped with resize handles. */
|
|
146
|
-
private detachResizeHandles;
|
|
147
123
|
private createResizeHandleNode;
|
|
148
124
|
private bindPointerHandlers;
|
|
149
125
|
private findLeafColumn;
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import { flattenColumns, isColumnGroup } from "@omnigrid/core";
|
|
|
10
10
|
export class ColumnResizePlugin {
|
|
11
11
|
constructor(options = {}) {
|
|
12
12
|
this.name = "@omnigrid/column-resize-plugin";
|
|
13
|
-
this.wrappedRenderers = new Map();
|
|
14
13
|
this.guide = { columnId: "", x: 0, visible: false };
|
|
15
14
|
/** Set while an actual drag occurred during the current resize session. */
|
|
16
15
|
this.resizeDragged = false;
|
|
@@ -22,14 +21,17 @@ export class ColumnResizePlugin {
|
|
|
22
21
|
}
|
|
23
22
|
register(api) {
|
|
24
23
|
this.api = api;
|
|
25
|
-
|
|
24
|
+
const unregisterHeaderExtension = api.registerHeaderExtension({
|
|
25
|
+
id: `${this.name}:resize-handle`,
|
|
26
|
+
position: "overlay",
|
|
27
|
+
render: ({ column }) => (column.resizable === false ? null : this.createResizeHandleNode(column)),
|
|
28
|
+
});
|
|
26
29
|
const unregisterPointerHandlers = this.bindPointerHandlers();
|
|
27
30
|
return () => {
|
|
28
31
|
unregisterPointerHandlers();
|
|
32
|
+
unregisterHeaderExtension();
|
|
29
33
|
this.clearGuide();
|
|
30
34
|
this.activeResize = undefined;
|
|
31
|
-
if (!api.isDestroyed())
|
|
32
|
-
api.setColumns(this.detachResizeHandles(api.getState().columns));
|
|
33
35
|
this.api = undefined;
|
|
34
36
|
};
|
|
35
37
|
}
|
|
@@ -253,114 +255,32 @@ export class ColumnResizePlugin {
|
|
|
253
255
|
canResizeColumn(column) {
|
|
254
256
|
return !!column && column.resizable !== false;
|
|
255
257
|
}
|
|
256
|
-
|
|
257
|
-
return columns.map((column) => {
|
|
258
|
-
if (isColumnGroup(column)) {
|
|
259
|
-
return { ...column, children: this.attachResizeHandles(column.children) };
|
|
260
|
-
}
|
|
261
|
-
if (column.resizable === false) {
|
|
262
|
-
return column;
|
|
263
|
-
}
|
|
264
|
-
const originalHeaderRenderer = column.headerRenderer;
|
|
265
|
-
const wrapped = (headerColumn) => {
|
|
266
|
-
const resolvedHeader = originalHeaderRenderer ? originalHeaderRenderer(headerColumn) : headerColumn.header ?? headerColumn.id;
|
|
267
|
-
return this.createResizeHandleNode(headerColumn, resolvedHeader);
|
|
268
|
-
};
|
|
269
|
-
this.wrappedRenderers.set(wrapped, originalHeaderRenderer);
|
|
270
|
-
return { ...column, headerRenderer: wrapped };
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/** Restores the original header renderers that were wrapped with resize handles. */
|
|
274
|
-
detachResizeHandles(columns) {
|
|
275
|
-
return columns.map((column) => {
|
|
276
|
-
if (isColumnGroup(column)) {
|
|
277
|
-
return { ...column, children: this.detachResizeHandles(column.children) };
|
|
278
|
-
}
|
|
279
|
-
if (!column.headerRenderer || !this.wrappedRenderers.has(column.headerRenderer))
|
|
280
|
-
return column;
|
|
281
|
-
return { ...column, headerRenderer: this.wrappedRenderers.get(column.headerRenderer) };
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
createResizeHandleNode(column, content) {
|
|
258
|
+
createResizeHandleNode(column) {
|
|
285
259
|
const handleClass = column.pinned === "right"
|
|
286
260
|
? "omnigrid-column-resize-handle omnigrid-column-resize-handle-left"
|
|
287
261
|
: "omnigrid-column-resize-handle";
|
|
288
|
-
const contentStyle = column.pinned === "right"
|
|
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;";
|
|
291
|
-
const sortIndicator = column.sortState && this.api
|
|
292
|
-
? {
|
|
293
|
-
type: "node",
|
|
294
|
-
tag: "span",
|
|
295
|
-
attrs: { class: "omnigrid-sort-indicator", "aria-hidden": true },
|
|
296
|
-
children: [
|
|
297
|
-
this.api.icons.get(column.sortState === "asc" ? "arrow-up" : "arrow-down"),
|
|
298
|
-
...(column.sortIndex !== undefined
|
|
299
|
-
? [
|
|
300
|
-
{
|
|
301
|
-
type: "node",
|
|
302
|
-
tag: "span",
|
|
303
|
-
attrs: { class: "omnigrid-sort-priority" },
|
|
304
|
-
children: [String(column.sortIndex)],
|
|
305
|
-
},
|
|
306
|
-
]
|
|
307
|
-
: []),
|
|
308
|
-
],
|
|
309
|
-
}
|
|
310
|
-
: undefined;
|
|
311
262
|
return {
|
|
312
263
|
type: "node",
|
|
313
264
|
tag: "span",
|
|
314
265
|
attrs: {
|
|
315
|
-
class:
|
|
316
|
-
|
|
266
|
+
class: handleClass,
|
|
267
|
+
"aria-hidden": true,
|
|
268
|
+
title: "Resize column",
|
|
269
|
+
style: column.pinned === "right"
|
|
270
|
+
? "position:absolute; top:0; bottom:0; left:-8px;"
|
|
271
|
+
: "position:absolute; top:0; bottom:0; right:-8px;",
|
|
317
272
|
},
|
|
318
|
-
|
|
319
|
-
{
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
},
|
|
328
|
-
children: [content],
|
|
273
|
+
on: {
|
|
274
|
+
pointerdown: (_context, event) => {
|
|
275
|
+
if (typeof event.clientX === "number") {
|
|
276
|
+
this.beginResize(column.id, event.clientX);
|
|
277
|
+
}
|
|
329
278
|
},
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
{
|
|
333
|
-
type: "node",
|
|
334
|
-
tag: "span",
|
|
335
|
-
attrs: { class: "omnigrid-header-tools" },
|
|
336
|
-
children: [sortIndicator],
|
|
337
|
-
},
|
|
338
|
-
]
|
|
339
|
-
: []),
|
|
340
|
-
{
|
|
341
|
-
type: "node",
|
|
342
|
-
tag: "span",
|
|
343
|
-
attrs: {
|
|
344
|
-
class: handleClass,
|
|
345
|
-
"aria-hidden": true,
|
|
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;",
|
|
350
|
-
},
|
|
351
|
-
on: {
|
|
352
|
-
pointerdown: (_context, event) => {
|
|
353
|
-
if (typeof event.clientX === "number") {
|
|
354
|
-
this.beginResize(column.id, event.clientX);
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
dblclick: (_context) => {
|
|
358
|
-
this.autoSizeColumn(column.id);
|
|
359
|
-
},
|
|
360
|
-
click: () => undefined,
|
|
361
|
-
},
|
|
279
|
+
dblclick: (_context) => {
|
|
280
|
+
this.autoSizeColumn(column.id);
|
|
362
281
|
},
|
|
363
|
-
|
|
282
|
+
click: () => undefined,
|
|
283
|
+
},
|
|
364
284
|
};
|
|
365
285
|
}
|
|
366
286
|
bindPointerHandlers() {
|
package/dist/types.d.ts
ADDED
|
@@ -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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
"name": "@omnigrid/resize-plugin",
|
|
3
|
+
"version": "0.1.5",
|
|
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
|
}
|