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
|
import { action, IReactionDisposer, observable, reaction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Doc, HeightSym, WidthSym, DocListCast } from '../../new_fields/Doc';
import { ObjectField } from '../../new_fields/ObjectField';
import { makeInterface } from '../../new_fields/Schema';
import { ScriptField } from '../../new_fields/ScriptField';
import { BoolCast, NumCast, StrCast } from '../../new_fields/Types';
import { emptyFunction, returnEmptyString, returnOne, returnTrue, Utils } from '../../Utils';
import { Docs } from '../documents/Documents';
import { DragManager } from '../util/DragManager';
import { Transform } from '../util/Transform';
import "./CollectionLinearView.scss";
import { CollectionViewType } from './collections/CollectionBaseView';
import { CollectionSubView } from './collections/CollectionSubView';
import { documentSchema, DocumentView } from './nodes/DocumentView';
import { translate } from 'googleapis/build/src/apis/translate';
import { DocumentType } from '../documents/DocumentTypes';
type LinearDocument = makeInterface<[typeof documentSchema,]>;
const LinearDocument = makeInterface(documentSchema);
@observer
export class CollectionLinearView extends CollectionSubView(LinearDocument) {
@observable public addMenuToggle = React.createRef<HTMLInputElement>();
private _dropDisposer?: DragManager.DragDropDisposer;
private _heightDisposer?: IReactionDisposer;
private _spacing = 20;
componentWillUnmount() {
this._dropDisposer && this._dropDisposer();
this._heightDisposer && this._heightDisposer();
}
componentDidMount() {
// is there any reason this needs to exist? -syip. yes, it handles autoHeight for stacking views (masonry isn't yet supported).
this._heightDisposer = reaction(() => NumCast(this.props.Document.height, 0) + this.childDocs.length + (this.props.Document.isExpanded ? 1 : 0),
() => this.props.Document.width = 18 + (this.props.Document.isExpanded ? this.childDocs.length * (this.props.Document[HeightSym]()) : 10),
{ fireImmediately: true }
);
}
protected createDropTarget = (ele: HTMLDivElement) => { //used for stacking and masonry view
this._dropDisposer && this._dropDisposer();
if (ele) {
this._dropDisposer = DragManager.MakeDropTarget(ele, { handlers: { drop: this.drop.bind(this) } });
}
}
makeTemplate = (doc: Doc): boolean => {
let layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateField ? doc.layout : doc;
let layout = StrCast(layoutDoc.layout).match(/fieldKey={"[^"]*"}/)![0];
let fieldKey = layout.replace('fieldKey={"', "").replace(/"}$/, "");
let docs = DocListCast(layoutDoc[fieldKey]);
let any = false;
docs.map(d => {
if (!StrCast(d.title).startsWith("-")) {
any = true;
return Doc.MakeMetadataFieldTemplate(d, Doc.GetProto(layoutDoc));
}
if (d.type === DocumentType.COL) return this.makeTemplate(d);
return false;
});
return any;
}
drop = action((e: Event, de: DragManager.DropEvent) => {
(de.data as DragManager.DocumentDragData).draggedDocuments.map((doc, i) => {
let dbox = doc;
if (!doc.onDragStart && !doc.onClick && this.props.Document.convertToButtons && doc.viewType !== CollectionViewType.Linear) {
let layoutDoc = doc.layout instanceof Doc && doc.layout.isTemplateField ? doc.layout : doc;
if (layoutDoc.type === DocumentType.COL) {
layoutDoc.isTemplateDoc = this.makeTemplate(layoutDoc);
} else {
layoutDoc.isTemplateDoc = (layoutDoc.type === DocumentType.TEXT || layoutDoc.layout instanceof Doc) && de.data instanceof DragManager.DocumentDragData && !de.data.userDropAction;
}
dbox = Docs.Create.FontIconDocument({ nativeWidth: 100, nativeHeight: 100, width: 100, height: 100, backgroundColor: StrCast(doc.backgroundColor), title: "Custom", icon: layoutDoc.isTemplateDoc ? "font" : "bolt" });
dbox.dragFactory = layoutDoc;
dbox.removeDropProperties = doc.removeDropProperties instanceof ObjectField ? ObjectField.MakeCopy(doc.removeDropProperties) : undefined;
dbox.onDragStart = ScriptField.MakeFunction('getCopy(this.dragFactory, true)');
} else if (doc.viewType === CollectionViewType.Linear) {
dbox.ignoreClick = true;
}
(de.data as DragManager.DocumentDragData).droppedDocuments[i] = dbox;
});
e.stopPropagation();
return super.drop(e, de);
});
public isCurrent(doc: Doc) { return !doc.isMinimized && (Math.abs(NumCast(doc.displayTimecode, -1) - NumCast(this.Document.currentTimecode, -1)) < 1.5 || NumCast(doc.displayTimecode, -1) === -1); }
dimension = () => NumCast(this.props.Document.height); // 2 * the padding
getTransform = (ele: React.RefObject<HTMLDivElement>) => () => {
if (!ele.current) return Transform.Identity();
let { scale, translateX, translateY } = Utils.GetScreenTransform(ele.current);
return new Transform(-translateX, -translateY, 1 / scale);
}
render() {
let guid = Utils.GenerateGuid();
return <div className="collectionLinearView-outer">
<div className="collectionLinearView" ref={this.createDropTarget} >
<input id={`${guid}`} type="checkbox" checked={BoolCast(this.props.Document.isExpanded)} ref={this.addMenuToggle}
onChange={action((e: any) => this.props.Document.isExpanded = this.addMenuToggle.current!.checked)} />
<label htmlFor={`${guid}`} style={{ marginTop: "auto", marginBottom: "auto", background: StrCast(this.props.Document.backgroundColor, "black") === StrCast(this.props.Document.color, "white") ? "black" : StrCast(this.props.Document.backgroundColor, "black") }} title="Close Menu"><p>+</p></label>
<div className="collectionLinearView-content">
{this.childLayoutPairs.filter(pair => this.isCurrent(pair.layout)).map(pair => {
let nested = pair.layout.viewType === CollectionViewType.Linear;
let dref = React.createRef<HTMLDivElement>();
let nativeWidth = NumCast(pair.layout.nativeWidth, this.dimension());
let scalingContent = nested ? 1 : this.dimension() / (this._spacing + nativeWidth);
let scalingBox = nested ? 1 : this.dimension() / nativeWidth;
let deltaSize = nativeWidth * scalingBox - nativeWidth * scalingContent;
return <div className={`collectionLinearView-docBtn` + (pair.layout.onClick || pair.layout.onDragStart ? "-scalable" : "")} key={StrCast(pair.layout.title)} ref={dref}
style={{
width: nested ? pair.layout[WidthSym]() : this.dimension(),
height: nested && pair.layout.isExpanded ? pair.layout[HeightSym]() : this.dimension(),
transform: nested ? undefined : `translate(${deltaSize / 2}px, ${deltaSize / 2}px)`
}} >
<DocumentView
Document={pair.layout}
DataDoc={pair.data}
addDocument={this.props.addDocument}
moveDocument={this.props.moveDocument}
addDocTab={this.props.addDocTab}
pinToPres={emptyFunction}
removeDocument={this.props.removeDocument}
ruleProvider={undefined}
onClick={undefined}
ScreenToLocalTransform={this.getTransform(dref)}
ContentScaling={() => scalingContent} // ugh - need to get rid of this inline function to avoid recomputing
PanelWidth={() => nested ? pair.layout[WidthSym]() : this.dimension()}
PanelHeight={() => nested ? pair.layout[HeightSym]() : this.dimension()}
renderDepth={this.props.renderDepth + 1}
focus={emptyFunction}
backgroundColor={returnEmptyString}
parentActive={returnTrue}
whenActiveChanged={emptyFunction}
bringToFront={emptyFunction}
ContainingCollectionView={undefined}
ContainingCollectionDoc={undefined}
zoomToScale={emptyFunction}
getScale={returnOne}>
</DocumentView>
</div>;
})}
{/* <li key="undoTest"><button className="add-button round-button" title="Click if undo isn't working" onClick={() => UndoManager.TraceOpenBatches()}><FontAwesomeIcon icon="exclamation" size="sm" /></button></li> */}
</div>
</div>
</div>;
}
}
|