-
Notifications
You must be signed in to change notification settings - Fork 63
/
index.tsx
80 lines (73 loc) · 2.58 KB
/
index.tsx
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 { useMemo, useRef } from 'react';
import {
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
SlotFillProvider,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { AutomationCompositeContext, AutomationContext } from './context';
import { EmptyAutomation } from './empty-automation';
import { InserterPopover } from '../inserter-popover';
import { storeName } from '../../store';
import { Statistics } from './statistics';
import { Flow } from './flow';
import { useAutomationDragToScroll } from './use-automation-drag-to-scroll';
import { useAutomationScroll } from './use-automation-scroll';
import { useAutomationScrollCenter } from './use-automation-scroll-center';
type AutomationProps = {
context: 'edit' | 'view';
scroll?: boolean;
drag?: boolean;
showStatistics?: boolean;
};
export function Automation({
context,
scroll = true,
drag = true,
showStatistics = true,
}: AutomationProps): JSX.Element {
const automationData = useSelect(
(select) => select(storeName).getAutomationData(),
[],
);
const automationContext = useMemo(() => ({ context }), [context]);
const compositeState = useCompositeState({
orientation: 'vertical',
wrap: 'horizontal',
shift: true,
});
// handle automation scrolling, dragging, and horizontal scroll centering
const automationRef = useRef<HTMLDivElement>();
useAutomationScroll(scroll ? automationRef : undefined);
useAutomationScrollCenter(automationRef);
useAutomationDragToScroll(drag ? automationRef : undefined);
if (!automationData) {
return <EmptyAutomation />;
}
return (
<AutomationContext.Provider value={automationContext}>
<AutomationCompositeContext.Provider value={compositeState}>
<SlotFillProvider>
<Composite
ref={automationRef}
state={compositeState}
role="tree"
aria-label={__('Automation', 'mailpoet')}
aria-orientation="vertical"
className="mailpoet-automation-editor-automation"
>
{showStatistics && <Statistics />}
<div className="mailpoet-automation-editor-automation-wrapper">
<div className="mailpoet-automation-editor-automation-flow">
<Flow stepData={automationData.steps.root} row={0} />
</div>
<div />
</div>
<InserterPopover />
</Composite>
</SlotFillProvider>
</AutomationCompositeContext.Provider>
</AutomationContext.Provider>
);
}