@xh/hoist 79.0.0-SNAPSHOT.1764952313480 → 79.0.0-SNAPSHOT.1764952554297
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/build/types/desktop/cmp/dash/canvas/DashCanvas.d.ts +1 -1
- package/build/types/desktop/cmp/dash/canvas/DashCanvasModel.d.ts +2 -39
- package/desktop/cmp/dash/canvas/DashCanvas.ts +4 -12
- package/desktop/cmp/dash/canvas/DashCanvasModel.ts +17 -113
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type ReactGridLayoutProps } from 'react-grid-layout';
|
|
2
1
|
import { HoistProps, TestSupportProps } from '@xh/hoist/core';
|
|
3
2
|
import '@xh/hoist/desktop/register';
|
|
3
|
+
import type { ReactGridLayoutProps } from 'react-grid-layout';
|
|
4
4
|
import { DashCanvasModel } from './DashCanvasModel';
|
|
5
5
|
import 'react-grid-layout/css/styles.css';
|
|
6
6
|
import './DashCanvas.scss';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { DragOverEvent, Layout } from 'react-grid-layout';
|
|
2
1
|
import { Persistable, PersistableState } from '@xh/hoist/core';
|
|
3
2
|
import { DashCanvasViewModel, DashCanvasViewSpec, DashConfig, DashViewState, DashModel } from '../';
|
|
4
3
|
import '@xh/hoist/desktop/register';
|
|
@@ -21,30 +20,6 @@ export interface DashCanvasConfig extends DashConfig<DashCanvasViewSpec, DashCan
|
|
|
21
20
|
maxRows?: number;
|
|
22
21
|
/** Padding inside the container [x, y] in pixels. Defaults to same as `margin`. */
|
|
23
22
|
containerPadding?: [number, number];
|
|
24
|
-
/**
|
|
25
|
-
* Whether the canvas should accept drag-and-drop of views from outside
|
|
26
|
-
* the canvas. Default false.
|
|
27
|
-
*/
|
|
28
|
-
droppable?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Optional Callback to invoke after a view is successfully dropped onto the canvas.
|
|
31
|
-
*/
|
|
32
|
-
onDropDone?: (viewModel: DashCanvasViewModel) => void;
|
|
33
|
-
/**
|
|
34
|
-
* Optional callback to invoke when an item is dragged over the canvas. This may be used to
|
|
35
|
-
* customize how the size of the dropping placeholder is calculated. The callback should
|
|
36
|
-
* return an object with optional 'w' and 'h' properties indicating the desired width and height
|
|
37
|
-
* (in grid units) of the dropping placeholder. If not provided, Hoist's own default logic will be used.
|
|
38
|
-
*/
|
|
39
|
-
onDropDragOver?: (e: DragOverEvent) => {
|
|
40
|
-
w?: number;
|
|
41
|
-
h?: number;
|
|
42
|
-
} | false | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Whether an overlay with an Add View button should be rendered
|
|
45
|
-
* when the canvas is empty. Default true.
|
|
46
|
-
*/
|
|
47
|
-
showAddViewButtonWhenEmpty?: boolean;
|
|
48
23
|
}
|
|
49
24
|
export interface DashCanvasItemState {
|
|
50
25
|
layout: DashCanvasItemLayout;
|
|
@@ -70,12 +45,7 @@ export declare class DashCanvasModel extends DashModel<DashCanvasViewSpec, DashC
|
|
|
70
45
|
compact: boolean;
|
|
71
46
|
margin: [number, number];
|
|
72
47
|
containerPadding: [number, number];
|
|
73
|
-
DROPPING_ELEM_ID: string;
|
|
74
48
|
maxRows: number;
|
|
75
|
-
showAddViewButtonWhenEmpty: boolean;
|
|
76
|
-
droppable: boolean;
|
|
77
|
-
onDropDone: (viewModel: DashCanvasViewModel) => void;
|
|
78
|
-
draggedInView: DashCanvasItemState;
|
|
79
49
|
/** Current number of rows in canvas */
|
|
80
50
|
get rows(): number;
|
|
81
51
|
get isEmpty(): boolean;
|
|
@@ -84,7 +54,7 @@ export declare class DashCanvasModel extends DashModel<DashCanvasViewSpec, DashC
|
|
|
84
54
|
isResizing: boolean;
|
|
85
55
|
private isLoadingState;
|
|
86
56
|
get rglLayout(): any[];
|
|
87
|
-
constructor({ viewSpecs, viewSpecDefaults, initialState, layoutLocked, contentLocked, renameLocked, persistWith, emptyText, addViewButtonText, columns, rowHeight, compact, margin, maxRows, containerPadding, extraMenuItems
|
|
57
|
+
constructor({ viewSpecs, viewSpecDefaults, initialState, layoutLocked, contentLocked, renameLocked, persistWith, emptyText, addViewButtonText, columns, rowHeight, compact, margin, maxRows, containerPadding, extraMenuItems }: DashCanvasConfig);
|
|
88
58
|
/** Removes all views from the canvas */
|
|
89
59
|
clear(): void;
|
|
90
60
|
/**
|
|
@@ -122,22 +92,15 @@ export declare class DashCanvasModel extends DashModel<DashCanvasViewSpec, DashC
|
|
|
122
92
|
renameView(id: string): void;
|
|
123
93
|
/** Scrolls a DashCanvasView into view. */
|
|
124
94
|
ensureViewVisible(id: string): void;
|
|
125
|
-
onDrop(rglLayout: Layout[], layoutItem: Layout, evt: Event): void;
|
|
126
|
-
setDraggedInView(view?: DashCanvasItemState): void;
|
|
127
|
-
onDropDragOver(e: DragOverEvent): {
|
|
128
|
-
w?: number;
|
|
129
|
-
h?: number;
|
|
130
|
-
} | false | undefined;
|
|
131
95
|
getPersistableState(): PersistableState<{
|
|
132
96
|
state: DashCanvasItemState[];
|
|
133
97
|
}>;
|
|
134
98
|
setPersistableState(persistableState: PersistableState<{
|
|
135
99
|
state: DashCanvasItemState[];
|
|
136
100
|
}>): void;
|
|
137
|
-
private doDrop;
|
|
138
101
|
private getLayoutFromPosition;
|
|
139
102
|
private addViewInternal;
|
|
140
|
-
onRglLayoutChange(rglLayout:
|
|
103
|
+
onRglLayoutChange(rglLayout: any): void;
|
|
141
104
|
private setLayout;
|
|
142
105
|
private loadState;
|
|
143
106
|
private buildState;
|
|
@@ -4,12 +4,6 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Copyright © 2025 Extremely Heavy Industries Inc.
|
|
6
6
|
*/
|
|
7
|
-
import ReactGridLayout, {
|
|
8
|
-
type ReactGridLayoutProps,
|
|
9
|
-
type DragOverEvent,
|
|
10
|
-
type Layout,
|
|
11
|
-
WidthProvider
|
|
12
|
-
} from 'react-grid-layout';
|
|
13
7
|
import {showContextMenu} from '@xh/hoist/kit/blueprint';
|
|
14
8
|
import composeRefs from '@seznam/compose-react-refs';
|
|
15
9
|
import {div, vbox, vspacer} from '@xh/hoist/cmp/layout';
|
|
@@ -26,6 +20,8 @@ import '@xh/hoist/desktop/register';
|
|
|
26
20
|
import {Classes, overlay} from '@xh/hoist/kit/blueprint';
|
|
27
21
|
import {consumeEvent, TEST_ID} from '@xh/hoist/utils/js';
|
|
28
22
|
import classNames from 'classnames';
|
|
23
|
+
import ReactGridLayout, {WidthProvider} from 'react-grid-layout';
|
|
24
|
+
import type {ReactGridLayoutProps} from 'react-grid-layout';
|
|
29
25
|
import {DashCanvasModel} from './DashCanvasModel';
|
|
30
26
|
import {dashCanvasContextMenu} from './impl/DashCanvasContextMenu';
|
|
31
27
|
import {dashCanvasView} from './impl/DashCanvasView';
|
|
@@ -91,7 +87,7 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
|
|
|
91
87
|
draggableHandle:
|
|
92
88
|
'.xh-dash-tab.xh-panel > .xh-panel__content > .xh-panel-header',
|
|
93
89
|
draggableCancel: '.xh-button',
|
|
94
|
-
onLayoutChange:
|
|
90
|
+
onLayoutChange: layout => model.onRglLayoutChange(layout),
|
|
95
91
|
onResizeStart: () => (model.isResizing = true),
|
|
96
92
|
onResizeStop: () => (model.isResizing = false),
|
|
97
93
|
items: model.viewModels.map(vm =>
|
|
@@ -100,13 +96,9 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
|
|
|
100
96
|
item: dashCanvasView({model: vm})
|
|
101
97
|
})
|
|
102
98
|
),
|
|
103
|
-
isDroppable: model.droppable,
|
|
104
|
-
onDrop: (layout: Layout[], layoutItem: Layout, evt: Event) =>
|
|
105
|
-
model.onDrop(layout, layoutItem, evt),
|
|
106
|
-
onDropDragOver: (evt: DragOverEvent) => model.onDropDragOver(evt),
|
|
107
99
|
...rglOptions
|
|
108
100
|
}),
|
|
109
|
-
emptyContainerOverlay(
|
|
101
|
+
emptyContainerOverlay()
|
|
110
102
|
],
|
|
111
103
|
[TEST_ID]: testId
|
|
112
104
|
})
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Copyright © 2025 Extremely Heavy Industries Inc.
|
|
6
6
|
*/
|
|
7
|
-
import type {DragOverEvent, Layout} from 'react-grid-layout';
|
|
8
7
|
import {Persistable, PersistableState, PersistenceProvider, XH} from '@xh/hoist/core';
|
|
9
8
|
import {required} from '@xh/hoist/data';
|
|
10
9
|
import {DashCanvasViewModel, DashCanvasViewSpec, DashConfig, DashViewState, DashModel} from '../';
|
|
@@ -17,7 +16,6 @@ import {createObservableRef} from '@xh/hoist/utils/react';
|
|
|
17
16
|
import {
|
|
18
17
|
defaultsDeep,
|
|
19
18
|
find,
|
|
20
|
-
omit,
|
|
21
19
|
uniqBy,
|
|
22
20
|
times,
|
|
23
21
|
without,
|
|
@@ -52,31 +50,6 @@ export interface DashCanvasConfig extends DashConfig<DashCanvasViewSpec, DashCan
|
|
|
52
50
|
|
|
53
51
|
/** Padding inside the container [x, y] in pixels. Defaults to same as `margin`. */
|
|
54
52
|
containerPadding?: [number, number];
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Whether the canvas should accept drag-and-drop of views from outside
|
|
58
|
-
* the canvas. Default false.
|
|
59
|
-
*/
|
|
60
|
-
droppable?: boolean;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Optional Callback to invoke after a view is successfully dropped onto the canvas.
|
|
64
|
-
*/
|
|
65
|
-
onDropDone?: (viewModel: DashCanvasViewModel) => void;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Optional callback to invoke when an item is dragged over the canvas. This may be used to
|
|
69
|
-
* customize how the size of the dropping placeholder is calculated. The callback should
|
|
70
|
-
* return an object with optional 'w' and 'h' properties indicating the desired width and height
|
|
71
|
-
* (in grid units) of the dropping placeholder. If not provided, Hoist's own default logic will be used.
|
|
72
|
-
*/
|
|
73
|
-
onDropDragOver?: (e: DragOverEvent) => {w?: number; h?: number} | false | undefined;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Whether an overlay with an Add View button should be rendered
|
|
77
|
-
* when the canvas is empty. Default true.
|
|
78
|
-
*/
|
|
79
|
-
showAddViewButtonWhenEmpty?: boolean;
|
|
80
53
|
}
|
|
81
54
|
|
|
82
55
|
export interface DashCanvasItemState {
|
|
@@ -113,12 +86,7 @@ export class DashCanvasModel
|
|
|
113
86
|
//-----------------------------
|
|
114
87
|
// Public properties
|
|
115
88
|
//-----------------------------
|
|
116
|
-
DROPPING_ELEM_ID = '__dropping-elem__';
|
|
117
89
|
maxRows: number;
|
|
118
|
-
showAddViewButtonWhenEmpty: boolean;
|
|
119
|
-
droppable: boolean;
|
|
120
|
-
onDropDone: (viewModel: DashCanvasViewModel) => void;
|
|
121
|
-
draggedInView: DashCanvasItemState;
|
|
122
90
|
|
|
123
91
|
/** Current number of rows in canvas */
|
|
124
92
|
get rows(): number {
|
|
@@ -138,27 +106,21 @@ export class DashCanvasModel
|
|
|
138
106
|
private isLoadingState: boolean;
|
|
139
107
|
|
|
140
108
|
get rglLayout() {
|
|
141
|
-
return this.layout
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
minH: viewSpec.minHeight,
|
|
157
|
-
maxW: viewSpec.maxWidth,
|
|
158
|
-
minW: viewSpec.minWidth
|
|
159
|
-
};
|
|
160
|
-
})
|
|
161
|
-
.filter(Boolean);
|
|
109
|
+
return this.layout.map(it => {
|
|
110
|
+
const dashCanvasView = this.getView(it.i),
|
|
111
|
+
{autoHeight, viewSpec} = dashCanvasView;
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
...it,
|
|
115
|
+
resizeHandles: autoHeight
|
|
116
|
+
? ['w', 'e']
|
|
117
|
+
: ['s', 'w', 'e', 'n', 'sw', 'nw', 'se', 'ne'],
|
|
118
|
+
maxH: viewSpec.maxHeight,
|
|
119
|
+
minH: viewSpec.minHeight,
|
|
120
|
+
maxW: viewSpec.maxWidth,
|
|
121
|
+
minW: viewSpec.minWidth
|
|
122
|
+
};
|
|
123
|
+
});
|
|
162
124
|
}
|
|
163
125
|
|
|
164
126
|
constructor({
|
|
@@ -177,11 +139,7 @@ export class DashCanvasModel
|
|
|
177
139
|
margin = [10, 10],
|
|
178
140
|
maxRows = Infinity,
|
|
179
141
|
containerPadding = margin,
|
|
180
|
-
extraMenuItems
|
|
181
|
-
showAddViewButtonWhenEmpty = true,
|
|
182
|
-
droppable = false,
|
|
183
|
-
onDropDone,
|
|
184
|
-
onDropDragOver
|
|
142
|
+
extraMenuItems
|
|
185
143
|
}: DashCanvasConfig) {
|
|
186
144
|
super();
|
|
187
145
|
makeObservable(this);
|
|
@@ -229,11 +187,6 @@ export class DashCanvasModel
|
|
|
229
187
|
this.emptyText = emptyText;
|
|
230
188
|
this.addViewButtonText = addViewButtonText;
|
|
231
189
|
this.extraMenuItems = extraMenuItems;
|
|
232
|
-
this.showAddViewButtonWhenEmpty = showAddViewButtonWhenEmpty;
|
|
233
|
-
this.droppable = droppable;
|
|
234
|
-
this.onDropDone = onDropDone;
|
|
235
|
-
// Override default onDropDragOver if provided
|
|
236
|
-
if (onDropDragOver) this.onDropDragOver = onDropDragOver;
|
|
237
190
|
|
|
238
191
|
this.loadState(initialState);
|
|
239
192
|
this.state = this.buildState();
|
|
@@ -359,31 +312,6 @@ export class DashCanvasModel
|
|
|
359
312
|
this.getView(id)?.ensureVisible();
|
|
360
313
|
}
|
|
361
314
|
|
|
362
|
-
onDrop(rglLayout: Layout[], layoutItem: Layout, evt: Event) {
|
|
363
|
-
throwIf(
|
|
364
|
-
!this.draggedInView,
|
|
365
|
-
`No draggedInView set on DashCanvasModel prior to onDrop operation.
|
|
366
|
-
Typically a developer would set this in response to dragstart events from
|
|
367
|
-
a DashViewTray or similar component.`
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
const {viewSpecId, title, state} = this.draggedInView,
|
|
371
|
-
layout = omit(layoutItem, 'i'),
|
|
372
|
-
newViewModel = this.doDrop(viewSpecId, {title, state, layout}, rglLayout);
|
|
373
|
-
|
|
374
|
-
this.draggedInView = null;
|
|
375
|
-
this.onDropDone?.(newViewModel);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
setDraggedInView(view?: DashCanvasItemState) {
|
|
379
|
-
this.draggedInView = view;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
onDropDragOver(e: DragOverEvent): {w?: number; h?: number} | false | undefined {
|
|
383
|
-
if (!this.draggedInView) return false;
|
|
384
|
-
return {w: 6, h: 6};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
315
|
//------------------------
|
|
388
316
|
// Persistable Interface
|
|
389
317
|
//------------------------
|
|
@@ -399,24 +327,6 @@ export class DashCanvasModel
|
|
|
399
327
|
//------------------------
|
|
400
328
|
// Implementation
|
|
401
329
|
//------------------------
|
|
402
|
-
@action
|
|
403
|
-
private doDrop(
|
|
404
|
-
specId: string,
|
|
405
|
-
opts: {
|
|
406
|
-
title: string;
|
|
407
|
-
state: any;
|
|
408
|
-
layout: DashCanvasItemLayout;
|
|
409
|
-
},
|
|
410
|
-
rglLayout: Layout[]
|
|
411
|
-
): DashCanvasViewModel {
|
|
412
|
-
const newViewModel: DashCanvasViewModel = this.addViewInternal(specId, opts),
|
|
413
|
-
droppingItem: any = rglLayout.find(it => it.i === this.DROPPING_ELEM_ID);
|
|
414
|
-
|
|
415
|
-
droppingItem.i = newViewModel.id;
|
|
416
|
-
this.onRglLayoutChange(rglLayout);
|
|
417
|
-
return newViewModel;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
330
|
private getLayoutFromPosition(position: string, specId: string) {
|
|
421
331
|
switch (position) {
|
|
422
332
|
case 'first':
|
|
@@ -474,14 +384,8 @@ export class DashCanvasModel
|
|
|
474
384
|
return model;
|
|
475
385
|
}
|
|
476
386
|
|
|
477
|
-
onRglLayoutChange(rglLayout
|
|
387
|
+
onRglLayoutChange(rglLayout) {
|
|
478
388
|
rglLayout = rglLayout.map(it => pick(it, ['i', 'x', 'y', 'w', 'h']));
|
|
479
|
-
|
|
480
|
-
// Early out if RGL is changing layout as user is dragging droppable
|
|
481
|
-
// item around the canvas. This will be called again once dragging
|
|
482
|
-
// has stopped and user has dropped the item onto the canvas.
|
|
483
|
-
if (rglLayout.some(it => it.i === this.DROPPING_ELEM_ID)) return;
|
|
484
|
-
|
|
485
389
|
this.setLayout(rglLayout);
|
|
486
390
|
}
|
|
487
391
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist",
|
|
3
|
-
"version": "79.0.0-SNAPSHOT.
|
|
3
|
+
"version": "79.0.0-SNAPSHOT.1764952554297",
|
|
4
4
|
"description": "Hoist add-on for building and deploying React Applications.",
|
|
5
5
|
"repository": "github:xh/hoist-react",
|
|
6
6
|
"homepage": "https://xh.io",
|