@omnigrid/resize-plugin 0.1.4 → 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 +0 -4
- package/dist/index.js +22 -102
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ export type { ColumnResizeGuide, ColumnResizePluginOptions } from "./types";
|
|
|
12
12
|
export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
|
|
13
13
|
readonly name = "@omnigrid/column-resize-plugin";
|
|
14
14
|
private api?;
|
|
15
|
-
private readonly wrappedRenderers;
|
|
16
15
|
private activeResize?;
|
|
17
16
|
private guide;
|
|
18
17
|
private readonly onResize?;
|
|
@@ -121,9 +120,6 @@ export declare class ColumnResizePlugin<T> implements GridPlugin<T> {
|
|
|
121
120
|
*/
|
|
122
121
|
clearGuide(): void;
|
|
123
122
|
private canResizeColumn;
|
|
124
|
-
private attachResizeHandles;
|
|
125
|
-
/** Restores the original header renderers that were wrapped with resize handles. */
|
|
126
|
-
private detachResizeHandles;
|
|
127
123
|
private createResizeHandleNode;
|
|
128
124
|
private bindPointerHandlers;
|
|
129
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() {
|