This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEditorSubpanel.tsx
320 lines (299 loc) · 15.1 KB
/
EditorSubpanel.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
import { Button, Row, Column, Pre, CheckBox, TextInput, TextArea, Select, Spinner } from 'react-vcomponents';
import { BaseComponentWithConnector, BaseComponent, GetDOM, SimpleShouldUpdate, ShallowChanged } from 'react-vextensions';
import { ScrollView } from 'react-vscrollview';
import { AddTimelineStep } from 'Server/Commands/AddTimelineStep';
import { TimelineStep, NodeReveal } from 'Store/firebase/timelineSteps/@TimelineStep';
import { ShowSignInPopup } from 'UI/@Shared/NavBar/UserPanel';
import { ES } from 'Utils/UI/GlobalStyles';
import { Connect, State, ACTSet, InfoButton, MakeDraggable, DragInfo } from 'Utils/FrameworkOverrides';
import { Map } from 'Store/firebase/maps/@Map';
import { MeID } from 'Store/firebase/users';
import { IsUserCreatorOrMod } from 'Store/firebase/userExtras';
import { ShowEditTimelineStepDialog } from 'UI/@Shared/Timelines/Steps/TimelineStepDetailsUI';
import { DeleteTimelineStep } from 'Server/Commands/DeleteTimelineStep';
import { GetTimelineSteps } from 'Store/firebase/timelines';
import { GetSelectedTimeline, GetTimelineOpenSubpanel, TimelineSubpanel, GetTimelinePanelOpen } from 'Store/main/maps/$map';
import { UpdateTimelineStep } from 'Server/Commands/UpdateTimelineStep';
import { UpdateTimeline } from 'Server/Commands/UpdateTimeline';
import { Global, ToInt, ToNumber, ToJSON, WaitXThenRun, VRect, Vector2i } from 'js-vextensions';
import { GetOpenMapID } from 'Store/main';
import { ShowMessageBox } from 'react-vmessagebox';
import { Timeline } from 'Store/firebase/timelines/@Timeline';
import { MinuteSecondInput } from 'Utils/ReactComponents/MinuteSecondInput';
import { Droppable, DroppableProvided, DroppableStateSnapshot } from 'react-beautiful-dnd';
import { DroppableInfo, DraggableInfo } from 'Utils/UI/DNDStructures';
import { GetNodeColor, MapNodeType } from 'Store/firebase/nodes/@MapNodeType';
import { GetNodeL3, GetNodeDisplayText, GetNodeL2 } from 'Store/firebase/nodes/$node';
import { GetNode, GetNodeID } from 'Store/firebase/nodes';
import ReactDOM from 'react-dom';
// for use by react-beautiful-dnd (using text replacement)
G({ LockMapEdgeScrolling });
function LockMapEdgeScrolling() {
const mapID = GetOpenMapID();
return State(a => a.main.lockMapScrolling) && GetTimelinePanelOpen(mapID) && GetTimelineOpenSubpanel(mapID) == TimelineSubpanel.Editor;
}
const EditorSubpanel_connector = (state, { map }: {map: Map}) => {
const timeline = GetSelectedTimeline(map._key);
return {
timeline,
timelineSteps: timeline && GetTimelineSteps(timeline, true),
lockMapScrolling: State(a => a.main.lockMapScrolling),
};
};
@Connect(EditorSubpanel_connector)
export class EditorSubpanel extends BaseComponentWithConnector(EditorSubpanel_connector, {}) {
render() {
const { map, timeline, timelineSteps, lockMapScrolling } = this.props;
if (timeline == null) return null;
const droppableInfo = new DroppableInfo({ type: 'TimelineStepList', timelineID: timeline._key });
return (
<>
<Row mlr={5}>
<Pre>Add: </Pre>
<Button ml={5} text="Video" enabled={timeline != null && timeline.videoID == null} onClick={() => {
if (MeID() == null) return ShowSignInPopup();
new UpdateTimeline({ id: timeline._key, updates: { videoID: '' } }).Run();
}}/>
<Button ml={5} text="Statement" enabled={timeline != null} onClick={() => {
if (MeID() == null) return ShowSignInPopup();
const newStep = new TimelineStep({});
new AddTimelineStep({ timelineID: timeline._key, step: newStep }).Run();
}}/>
<CheckBox ml="auto" text="Lock map scrolling" title="Lock map edge-scrolling. (for dragging onto timeline steps)" checked={lockMapScrolling} onChange={(val) => {
store.dispatch(new ACTSet(a => a.main.lockMapScrolling, val));
}}/>
</Row>
<ScrollView style={ES({ flex: 1 })} contentStyle={ES({
flex: 1, position: 'relative', padding: 7,
// filter: 'drop-shadow(rgb(0, 0, 0) 0px 0px 10px)', // disabled for now, since otherwise causes issue with dnd system (and portal fix causes errors here, fsr)
})}>
{timeline.videoID != null &&
<Row mb={7} p="7px 10px" style={{ background: 'rgba(0,0,0,.7)', borderRadius: 10, border: '1px solid rgba(255,255,255,.15)' }}>
<Pre>Video ID: </Pre>
<TextInput value={timeline.videoID} delayChangeTillDefocus={true} onChange={(val) => {
new UpdateTimeline({ id: timeline._key, updates: { videoID: val } }).Run();
}}/>
<CheckBox ml={5} text="Start: " checked={timeline.videoStartTime != null} onChange={(val) => {
if (val) {
new UpdateTimeline({ id: timeline._key, updates: { videoStartTime: 0 } }).Run();
} else {
new UpdateTimeline({ id: timeline._key, updates: { videoStartTime: null } }).Run();
}
}}/>
<MinuteSecondInput mr={5} style={{ width: 60 }} enabled={timeline.videoStartTime != null} value={timeline.videoStartTime}
onChange={val => new UpdateTimeline({ id: timeline._key, updates: { videoStartTime: val } }).Run()}/>
<Pre>Height<InfoButton text={`
The height, as a percentage of the width.
4:3 = 75%
16:9 = 56.25%
`.AsMultiline(0)}/>: </Pre>
<Spinner min={0} max={100} step={0.01} delayChangeTillDefocus={true} style={{ width: 62 }} value={(timeline.videoHeightVSWidthPercent * 100).RoundTo(0.01)} onChange={(val) => {
new UpdateTimeline({ id: timeline._key, updates: { videoHeightVSWidthPercent: (val / 100).RoundTo(0.0001) } }).Run();
}}/>
<Pre>%</Pre>
<Button ml="auto" text="X" onClick={() => {
ShowMessageBox({
title: 'Delete video attachment', cancelButton: true,
message: 'Remove the video attachment for this timeline?',
onOK: () => {
new UpdateTimeline({ id: timeline._key, updates: { videoID: null } }).Run();
},
});
}}/>
</Row>}
<Droppable type="TimelineStep" droppableId={ToJSON(droppableInfo.VSet({ timelineID: timeline._key }))}>{(provided: DroppableProvided, snapshot: DroppableStateSnapshot) => (
<Column ref={c => provided.innerRef(GetDOM(c) as any)}>
{timelineSteps && timelineSteps.map((step, index) => {
if (step == null) return null;
return <StepUI key={index} index={index} last={index == timeline.steps.length - 1} map={map} timeline={timeline} step={step}/>;
})}
</Column>
)}</Droppable>
</ScrollView>
</>
);
}
}
const positionOptions = [
{ name: 'Full', value: null },
{ name: 'Left', value: 1 },
{ name: 'Right', value: 2 },
{ name: 'Center', value: 3 },
];
/* let portal: HTMLElement;
WaitXThenRun(0, () => {
portal = document.createElement('div');
document.body.appendChild(portal);
}); */
type StepUIProps = {index: number, last: boolean, map: Map, timeline: Timeline, step: TimelineStep} & {dragInfo?: DragInfo};
@MakeDraggable(({ index, step }: StepUIProps) => {
return {
type: 'TimelineStep',
draggableInfo: new DraggableInfo({ stepID: step._key }),
index,
};
})
@SimpleShouldUpdate({ propsToIgnore: ['dragInfo'] })
class StepUI extends BaseComponent<StepUIProps, {placeholderRect: VRect}> {
render() {
const { index, last, map, timeline, step, dragInfo } = this.props;
const { placeholderRect } = this.state;
const creatorOrMod = IsUserCreatorOrMod(MeID(), map);
const asDragPreview = dragInfo && dragInfo.snapshot.isDragging;
const result = (
<Column mt={index == 0 ? 0 : 7} {...(dragInfo && dragInfo.provided.draggableProps)}
style={E(
{ background: 'rgba(0,0,0,.7)', borderRadius: 10, border: '1px solid rgba(255,255,255,.15)' },
dragInfo && dragInfo.provided.draggableProps.style,
asDragPreview && { zIndex: 10 },
)}>
<Row p="7px 10px" {...(dragInfo && dragInfo.provided.dragHandleProps)}>
<Pre>Step {index + 1}</Pre>
{/* <Button ml={5} text="Edit" title="Edit this step" style={{ flexShrink: 0 }} onClick={() => {
ShowEditTimelineStepDialog(MeID(), step);
}}/> */}
<Row ml="auto">
{timeline.videoID != null &&
<>
<CheckBox text="Video time: " checked={step.videoTime != null} onChange={(val) => {
if (val) {
new UpdateTimelineStep({ stepID: step._key, stepUpdates: { videoTime: 0 } }).Run();
} else {
new UpdateTimelineStep({ stepID: step._key, stepUpdates: { videoTime: null } }).Run();
}
}}/>
<MinuteSecondInput mr={5} style={{ width: 60 }} enabled={step.videoTime != null} value={step.videoTime}
onChange={val => new UpdateTimelineStep({ stepID: step._key, stepUpdates: { videoTime: val } }).Run()}/>
</>}
{/* <Pre>Speaker: </Pre>
<Select value={} onChange={val=> {}}/> */}
<Pre>Position: </Pre>
<Select options={positionOptions} value={step.groupID} onChange={(val) => {
new UpdateTimelineStep({ stepID: step._key, stepUpdates: { groupID: val } }).Run();
}}/>
<Button ml={5} text="X" onClick={() => {
ShowMessageBox({
title: `Delete step ${index + 1}`, cancelButton: true,
message: `
Delete timeline step with text:
${step.message}
`.AsMultiline(0),
onOK: () => {
new DeleteTimelineStep({ stepID: step._key }).Run();
},
});
}}/>
</Row>
</Row>
{/* <Row ml={5} style={{ minHeight: 20 }}>{step.message}</Row> */}
<TextArea autoSize={true} delayChangeTillDefocus={true} style={{ background: 'rgba(255,255,255,.2)', color: 'rgba(255,255,255,.7)', padding: 5, outline: 'none' }}
value={step.message}
onChange={(val) => {
new UpdateTimelineStep({ stepID: step._key, stepUpdates: { message: val } }).Run();
}}/>
<Droppable type="MapNode" droppableId={ToJSON(new DroppableInfo({ type: 'TimelineStepNodeRevealList', stepID: step._key }))}>{(provided: DroppableProvided, snapshot: DroppableStateSnapshot) => (
<Column ref={(c) => { this.nodeHolder = c; provided.innerRef(GetDOM(c) as any); }}
style={E(
{ position: 'relative', padding: 7, background: 'rgba(255,255,255,.3)', borderRadius: '0 0 10px 10px' },
(step.nodeReveals == null || step.nodeReveals.length == 0) && { padding: '3px 5px' },
)}>
{(step.nodeReveals == null || step.nodeReveals.length == 0) && provided.placeholder == null &&
<div style={{ fontSize: 11, opacity: 0.7, textAlign: 'center' }}>Drag nodes here to have them display when the playback reaches this step.</div>}
{step.nodeReveals && step.nodeReveals.map((nodeReveal, index) => {
return <NodeRevealUI key={index} step={step} nodeReveal={nodeReveal} index={index}/>;
})}
{provided.placeholder}
{provided.placeholder && void WaitXThenRun(0, () => this.StartGeneratingPositionedPlaceholder())}
{provided.placeholder && placeholderRect &&
<div style={{
// position: 'absolute', left: 0 /* placeholderRect.x */, top: placeholderRect.y, width: placeholderRect.width, height: placeholderRect.height,
position: 'absolute', left: 7 /* placeholderRect.x */, top: placeholderRect.y, right: 7, height: placeholderRect.height,
border: '1px dashed rgba(255,255,255,1)', borderRadius: 5,
}}/>}
</Column>
)}</Droppable>
</Column>
);
// if drag preview, we have to put in portal, since otherwise the "filter" effect of ancestors causes the {position:fixed} style to not be relative-to-page
/* if (asDragPreview) {
return ReactDOM.createPortal(result, portal);
} */
return result;
}
nodeHolder: Row;
StartGeneratingPositionedPlaceholder() {
if (this.nodeHolder == null || !this.nodeHolder.mounted) {
// call again in a second, once node-holder is initialized
WaitXThenRun(0, () => this.StartGeneratingPositionedPlaceholder());
return;
}
const nodeHolderRect = VRect.FromLTWH(this.nodeHolder.DOM.getBoundingClientRect());
const dragBox = document.querySelector('.NodeUI_Inner.DragPreview');
if (dragBox == null) return; // this can happen at end of drag
const dragBoxRect = VRect.FromLTWH(dragBox.getBoundingClientRect());
const siblingNodeUIs = (this.nodeHolder.DOM.childNodes.ToArray() as HTMLElement[]).filter(a => a.classList.contains('NodeUI'));
const siblingNodeUIInnerDOMs = siblingNodeUIs.map(nodeUI => nodeUI.QuerySelector_BreadthFirst('.NodeUI_Inner'));
const firstOffsetInner = siblingNodeUIInnerDOMs.find(a => a && a.style.transform && a.style.transform.includes('translate('));
let placeholderRect: VRect;
if (firstOffsetInner) {
const firstOffsetInnerRect = VRect.FromLTWH(firstOffsetInner.getBoundingClientRect()).NewTop(top => top - dragBoxRect.height);
const firstOffsetInnerRect_relative = new VRect(firstOffsetInnerRect.Position.Minus(nodeHolderRect.Position), firstOffsetInnerRect.Size);
placeholderRect = firstOffsetInnerRect_relative.NewWidth(dragBoxRect.width).NewHeight(dragBoxRect.height);
} else {
if (siblingNodeUIInnerDOMs.length) {
const lastInner = siblingNodeUIInnerDOMs.Last();
const lastInnerRect = VRect.FromLTWH(lastInner.getBoundingClientRect()).NewTop(top => top - dragBoxRect.height);
const lastInnerRect_relative = new VRect(lastInnerRect.Position.Minus(nodeHolderRect.Position), lastInnerRect.Size);
placeholderRect = lastInnerRect_relative.NewWidth(dragBoxRect.width).NewHeight(dragBoxRect.height);
// if (dragBoxRect.Center.y > firstOffsetInnerRect.Center.y) {
placeholderRect.y += lastInnerRect.height;
} else {
// placeholderRect = new VRect(Vector2i.zero, dragBoxRect.Size);
placeholderRect = new VRect(new Vector2i(7, 7), dragBoxRect.Size); // adjust for padding
}
}
this.SetState({ placeholderRect });
}
}
const connector = (state, { nodeReveal }: {step: TimelineStep, nodeReveal: NodeReveal, index: number}) => {
let node = GetNodeL2(GetNodeID(nodeReveal.path));
let nodeL3 = GetNodeL3(nodeReveal.path);
// if one is null, make them both null to be consistent
if (node == null || nodeL3 == null) {
node = null;
nodeL3 = null;
}
return {
node,
nodeL3,
displayText: node && nodeL3 ? GetNodeDisplayText(node, nodeReveal.path) : `(Node no longer exists: ${GetNodeID(nodeReveal.path)})`,
};
};
@Connect(connector)
export class NodeRevealUI extends BaseComponentWithConnector(connector, {}) {
render() {
const { step, nodeReveal, index, node, nodeL3, displayText } = this.props;
// if (node == null || nodeL3 == null) return null;
const path = nodeReveal.path;
const backgroundColor = GetNodeColor(nodeL3 || { type: MapNodeType.Category } as any).desaturate(0.5).alpha(0.8);
return (
<Row key={index} mt={index === 0 ? 0 : 5}
style={E(
{ width: '100%', padding: 5, background: backgroundColor.css(), borderRadius: 5, /* cursor: 'pointer', */ border: '1px solid rgba(0,0,0,.5)' },
// selected && { background: backgroundColor.brighten(0.3).alpha(1).css() },
)}
onMouseDown={(e) => {
if (e.button !== 2) return false;
// this.SetState({ menuOpened: true });
}}>
<span>{displayText}</span>
{/* <NodeUI_Menu_Helper {...{map, node}}/> */}
{/* <NodeUI_Menu_Stub {...{ node: nodeL3, path: `${node._key}`, inList: true }}/> */}
<Button ml="auto" text="X" style={{ margin: -3, padding: '3px 10px' }} onClick={() => {
const newNodeReveals = step.nodeReveals.Except(nodeReveal);
new UpdateTimelineStep({ stepID: step._key, stepUpdates: { nodeReveals: newNodeReveals } }).Run();
}}/>
</Row>
);
}
}