-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDropZoneLayer.tsx
More file actions
80 lines (71 loc) · 2.26 KB
/
DropZoneLayer.tsx
File metadata and controls
80 lines (71 loc) · 2.26 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as React from 'react';
import { Layer, WorkspaceEngine, WorkspaceModel } from '@projectstorm/react-workspaces-core';
import { DropZoneLayerPanelTheme, DropZoneLayerPanelWidget, DropZonePanelDirective } from './DropZoneLayerPanelWidget';
export interface DropZoneLayerOptions {
getDropZoneForModel: (model: WorkspaceModel) => DropZonePanelDirective | null;
theme?: DropZoneLayerPanelTheme;
modelID: string;
debugModels: boolean;
}
export class DropZoneLayer extends Layer {
constructor(private options2: DropZoneLayerOptions) {
super({
mouseEvents: false
});
}
renderLayer(event): React.JSX.Element {
return (
<DropZoneLayerWidget
debugModels={this.options2.debugModels}
engine={event.engine}
draggingModel={this.options2.modelID}
getDropZoneForModel={this.options2.getDropZoneForModel}
theme={this.options2.theme}
/>
);
}
}
//!--------------- widget ----------------
export interface DropZoneLayerWidgetProps {
engine: WorkspaceEngine;
getDropZoneForModel: (model: WorkspaceModel) => DropZonePanelDirective | null;
draggingModel: string;
debugModels: boolean;
theme?: DropZoneLayerPanelTheme;
}
export const DropZoneLayerWidget: React.FC<DropZoneLayerWidgetProps> = (props) => {
const draggingModelFlattened =
props.engine.rootModel
.flatten()
.find((m) => m.id === props.draggingModel)
?.flatten() || [];
return (
<>
{props.engine.rootModel
.flatten()
.filter((m) => m.r_visible)
.filter((m) => {
// filter out the dragging model and its children (cant add parent to children)
return !draggingModelFlattened.find((child) => child.id === m.id);
})
// dont show a drop zone for the same model
// .filter((m) => m.id !== props.draggingModel.id)
.map((m) => {
const directive = props.getDropZoneForModel(m);
if (!directive) {
return null;
}
return (
<DropZoneLayerPanelWidget
debug={props.debugModels}
directive={directive}
engine={props.engine}
model={m}
theme={props.theme}
key={m.id}
/>
);
})}
</>
);
};