-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathDropzoneDividersLayer.tsx
More file actions
61 lines (54 loc) · 1.69 KB
/
DropzoneDividersLayer.tsx
File metadata and controls
61 lines (54 loc) · 1.69 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
import * as React from 'react';
import { useEffect } from 'react';
import { Layer, useForceUpdate, WorkspaceEngine, WorkspaceNodeModel } from '@projectstorm/react-workspaces-core';
import { DropzoneDividerTheme, DropzoneDividerWidget } from './DropzoneDividerWidget';
export interface DropzoneDividersLayerOptions {
theme?: () => DropzoneDividerTheme;
}
export class DropzoneDividersLayer extends Layer {
constructor(protected options2: DropzoneDividersLayerOptions) {
super({
mouseEvents: false
});
}
renderLayer(event): React.JSX.Element {
return <DropzoneDividersLayerWidget engine={event.engine} theme={this.options2.theme} />;
}
}
export interface DropzoneDividersLayerWidgetProps {
engine: WorkspaceEngine;
theme?: () => DropzoneDividerTheme;
}
export const DropzoneDividersLayerWidget: React.FC<DropzoneDividersLayerWidgetProps> = (props) => {
const forceUpdate = useForceUpdate(true);
useEffect(() => {
return props.engine.registerListener({
layoutInvalidated: () => {
forceUpdate();
}
});
}, []);
return (
<>
{props.engine.rootModel
.flatten()
.filter((p) => p instanceof WorkspaceNodeModel)
.flatMap((m: WorkspaceNodeModel) => {
return m.r_divisions.map((division, index) => {
return (
<DropzoneDividerWidget
theme={props.theme?.()}
engine={props.engine}
dimension={division}
key={division.id}
handleDrop={(model) => {
m.addModel(model, index);
props.engine.normalize();
}}
/>
);
});
})}
</>
);
};