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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
import { ObservableMap, action, computed, makeObservable, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Utils, returnFalse, returnTrue, returnZero } from '../../../Utils';
import { Doc, DocListCast, Field } from '../../../fields/Doc';
import { Id } from '../../../fields/FieldSymbols';
import { NumCast, ScriptCast, StrCast, BoolCast } from '../../../fields/Types';
import { DragManager } from '../../util/DragManager';
import { SelectionManager } from '../../util/SelectionManager';
import { StyleProp } from '../StyleProvider';
import { DocumentView } from '../nodes/DocumentView';
import './CollectionCardDeckView.scss';
import { CollectionSubView } from './CollectionSubView';
import { Transform } from '../../util/Transform';
// import Card from 'react-bootstrap/Card';
@observer
export class CollectionCardView extends CollectionSubView() {
@observable selectedNodeIndex = -1;
@observable hoveredNodeIndex = -1;
@action
setHoveredNodeIndex = (index: number) => {
if (!this.isSelected(index)) {
this.hoveredNodeIndex = index;
}
};
translateHover = (index: number): number => {
if (this.hoveredNodeIndex == index && !this.isSelected(index)) {
return -50 * this.fitContentScale;
}
return 0;
};
@action
setSelectedNodeIndex = (index: number) => {
const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
console.log('goodnight');
if (SelectionManager.IsSelected(docs[index])) {
console.log('good mornings');
this.setSelectedNodeIndex(index);
}
};
isSelected = (index: number): boolean => {
const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
return SelectionManager.IsSelected(docs[index]);
};
inactiveDocs = () => {
const docs = DocListCast(this.Document[this.fieldKey ?? Doc.LayoutFieldKey(this.Document)]);
return docs.filter(d => !SelectionManager.IsSelected(d));
};
middleIndex = Math.floor(this.inactiveDocs().length / 2);
constructor(props: any) {
super(props);
makeObservable(this);
// this.rotationDegree(7);
}
private _dropDisposer?: DragManager.DragDropDisposer;
componentWillUnmount() {
this._dropDisposer?.();
}
protected createDashEventsTarget = (ele: HTMLDivElement | null) => {
this._dropDisposer?.();
if (ele) {
this._dropDisposer = DragManager.MakeDropTarget(ele, this.onInternalDrop.bind(this), this.layoutDoc);
}
};
childDocumentWidth = 600; // target width of a Doc...
/**
* how much to scale down the contents of the view so that everything will fit
*/
@computed get fitContentScale() {
return (this.childDocumentWidth * this.childLayoutPairs.length) / this._props.PanelWidth();
}
panelWidth = () => this.childDocumentWidth;
panelHeight = (layout: Doc) => () => (2 * (this.panelWidth() * NumCast(layout._height))) / NumCast(layout._width);
onChildDoubleClick = () => ScriptCast(this.layoutDoc.onChildDoubleClick);
isContentActive = () => this._props.isSelected() || this._props.isContentActive() || this._props.isAnyChildContentActive();
isChildContentActive = () => (this.isContentActive() ? true : false);
rotate = (amCards: number, index: number) => {
console.log(amCards + "wtf")
const possRotate = -30 + index * (30 / ((amCards - (amCards % 2)) / 2));
const stepMag = Math.abs(-30 + (amCards / 2 - 1) * (30 / ((amCards - (amCards % 2)) / 2)));
// console.log(possRotate + "poss")
if (amCards % 2 == 0 && possRotate == 0) {
// console.log('whaddup');
return possRotate + Math.abs(-30 + (index - 1) * (30 / (amCards / 2)));
} else if (amCards % 2 == 0 && index > (amCards + 1) / 2) {
// console.log("sup" + stepMag);
return possRotate + stepMag;
}
return possRotate;
};
translateY = (amCards: number, index: number) => {
const evenOdd = amCards % 2;
const apex = (amCards - evenOdd) / 2;
const stepMag = 200 / ((amCards - evenOdd) / 2) + Math.abs((apex - index) * 25);
console.log('steo' + stepMag);
if (evenOdd == 1 || index < apex - 1) {
console.log('hi' + index);
return Math.abs(stepMag * (apex - index));
} else {
if (index == apex || index == apex - 1) {
return 0;
}
return Math.abs(stepMag * (apex - index - 1));
}
};
translateOverFlowY = (amCards: number, index: number) => {
if (amCards > 8 && index > amCards / 2) {
return 100;
}
return 0;
};
translateSelected = (index: number): number => {
if (this.isSelected(index)) {
const middleOfPanel = this._props.PanelWidth() / 2;
const scaledNodeWidth = this.panelWidth() * 1.25;
// Calculate the position of the node's left edge before scaling
const nodeLeftEdge = index * this.panelWidth();
// Find the center of the node after scaling
const scaledNodeCenter = nodeLeftEdge + scaledNodeWidth / 2;
// Calculate the translation needed to align the scaled node's center with the panel's center
const translation = middleOfPanel - scaledNodeCenter;
return translation;
}
return 0;
};
@computed get sortedDocsType() {
const desc = BoolCast(this.layoutDoc.sortDesc);
let sorted = []
for (let i=0; i< this.childLayoutPairs.length; i++){ //copying everything in childlayout pairs to sorted so that i can use the sort function without altering the original list
sorted[i] = this.childLayoutPairs[i]
}
// Copy and sort documents by type
const docs = sorted.sort((docA, docB) => {
const typeA = docA.layout.type ?? ''; // If docA.type is undefined, use an empty string
const typeB = docB.layout.type ?? ''; // If docB.type is undefined, use an empty string
// Perform a basic string comparison if types are strings
let out = 0;
if (typeA < typeB) out = -1;
if (typeA > typeB) out = 1;
if (desc) out *= -1; // Reverse the sort order if descending is true
return out;
});
return { docs };
}
@observable docRefs = new ObservableMap<Doc, DocumentView>();
@computed get contentSorted() {
const sortedDocs = this.sortedDocsType.docs;
const amCards = this.inactiveDocs().length;
const displayDoc = (childPair: { layout: Doc; data: Doc }, screenToLocalTransform: () => Transform) => {
return (
<DocumentView
{...this._props}
ref={action((r: DocumentView) => r?.ContentDiv && this.docRefs.set(childPair.layout, r))}
Document={childPair.layout}
TemplateDataDocument={childPair.data}
NativeWidth={returnZero}
NativeHeight={returnZero}
layout_fitWidth={returnFalse}
onDoubleClickScript={this.onChildDoubleClick}
renderDepth={this._props.renderDepth + 1}
LayoutTemplate={this._props.childLayoutTemplate}
LayoutTemplateString={this._props.childLayoutString}
ScreenToLocalTransform={screenToLocalTransform}
isContentActive={this.isChildContentActive}
isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive}
PanelWidth={this.panelWidth}
PanelHeight={this.panelHeight(childPair.layout)}
/>
);
};
// Map sorted documents to their rendered components
return sortedDocs.map((childPair, index) => {
// const childPair = { layout: doc, data: doc };
const isHovered = this.hoveredNodeIndex === index;
const inactiveIndex = this.sortedDocsType.docs.filter(d => !SelectionManager.IsSelected(d.layout)).indexOf(childPair);
const isSelected = SelectionManager.IsSelected(childPair.layout);
const childScreenToLocal = () => {
const dref = this.docRefs.get(childPair.layout);
const { translateX, translateY, scale } = Utils.GetScreenTransform(dref?.ContentDiv);
return new Transform(-translateX + (dref?.centeringX || 0) * scale, -translateY + (dref?.centeringY || 0) * scale, 1).scale(1 / scale).rotate(!isSelected ? -this.rotate(amCards, inactiveIndex) : 0);
};
return (
<div
key={childPair.layout[Id]}
className={`card-item${isSelected ? '-active' : ''}`}
style={{
width: this.panelWidth(),
height: this.panelHeight(childPair.layout)(),
transform: `
rotate(${!isSelected ? this.rotate(amCards, inactiveIndex) : 0}deg)
translateY(${isHovered ? this.translateHover(inactiveIndex) : isSelected ? 50 * this.fitContentScale : this.translateY(amCards, inactiveIndex)}px)
translateX(${isSelected ? (this._props.PanelWidth() / 2) * this.fitContentScale - this.childDocumentWidth : 0}px)
scale(${isSelected ? 1.25 : 1})
`,
}}
onMouseEnter={() => this.setHoveredNodeIndex(index)}>
{displayDoc(childPair, childScreenToLocal)}
</div>
);
});
}
@computed get content() {
// const currentIndex = NumCast(this.layoutDoc._carousel_index);
const amCards = this.inactiveDocs().length;
console.log(amCards + "lol")
// const sortedDocs = this.sortedDocsType.docs; // Retrieve sorted documents
// const myInactives =
const displayDoc = (childPair: { layout: Doc; data: Doc }, screenToLocalTransform: () => Transform) => {
return (
<DocumentView
{...this._props}
ref={action((r: DocumentView) => r?.ContentDiv && this.docRefs.set(childPair.layout, r))}
Document={childPair.layout}
TemplateDataDocument={childPair.data}
// onClickScript={this.toggleIcon}
//suppressSetHeight={true}
NativeWidth={returnZero}
NativeHeight={returnZero}
layout_fitWidth={returnFalse}
onDoubleClickScript={this.onChildDoubleClick}
renderDepth={this._props.renderDepth + 1}
LayoutTemplate={this._props.childLayoutTemplate}
LayoutTemplateString={this._props.childLayoutString}
// focus={this.focus}
ScreenToLocalTransform={screenToLocalTransform} //makes sure the box wrapper thing is in the right spot
isContentActive={this.isChildContentActive}
isDocumentActive={this._props.childDocumentsActive?.() || this.Document._childDocumentsActive ? this._props.isDocumentActive : this.isContentActive}
PanelWidth={this.panelWidth}
PanelHeight={this.panelHeight(childPair.layout)}
/>
);
};
return this.childLayoutPairs.map((childPair, index) => {
const isSelected = this.isSelected(index);
const isHovered = this.hoveredNodeIndex === index;
const isOverflow = amCards > 8 && index > amCards / 2;
// const inactiveIndex = this.sortedDocsType.docs.indexOf(childPair);
const inactiveIndex = this.inactiveDocs().indexOf(childPair.layout);
// const yOffset = this.verticalOffset(index);
const childScreenToLocal = () => {
const dref = this.docRefs.get(childPair.layout);
const { translateX, translateY, scale } = Utils.GetScreenTransform(dref?.ContentDiv);
// the document view may center its contents and if so, will prepend that onto the screenToLocalTansform. so we have to subtract that off
return new Transform(-translateX + (dref?.centeringX || 0) * scale, -translateY + (dref?.centeringY || 0) * scale, 1).scale(1 / scale).rotate(!isSelected ? -this.rotate(amCards, inactiveIndex) : 0);
};
return (
<div
key={childPair.layout[Id]}
className={`card-item${isSelected ? '-active' : ''}`}
style={{
width: this.panelWidth(),
height: this.panelHeight(childPair.layout)(),
transform: `
rotate(${!isSelected ? this.rotate(amCards, inactiveIndex) : 0}deg)
translateY(${isHovered ? this.translateHover(index) : isSelected ? 50 * this.fitContentScale : this.translateY(amCards, inactiveIndex)}px)
translateX(${isSelected ? (this._props.PanelWidth() / 2) * this.fitContentScale - this.childDocumentWidth : 0}px)
scale(${isSelected ? 1.25 : 1})
`, //scale has to be applied last or selected offset gets messed up
}}
// onClick={() => this.setSelectedNodeIndex(index)}
onMouseEnter={() => this.setHoveredNodeIndex(index)}>
{/* {this.lol(childPair.data, index)} */}
{displayDoc(childPair, childScreenToLocal)}
</div>
);
});
}
@computed get translateWrapperX() {
if (this.inactiveDocs().length != this.childLayoutPairs.length) {
return this.panelWidth() / 2;
}
return 0;
}
@computed get renderCardsSort(){
if (BoolCast(this._props.Document.card_sort_type) == true){
return this.contentSorted
}
else{
return this.content
}
}
render() {
return (
<div
className="collectionCardView-outer"
ref={this.createDashEventsTarget}
style={{
background: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.BackgroundColor),
color: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.Color),
}}>
<div
className="card-wrapper"
style={{
transform: ` scale(${1 / this.fitContentScale}) translateX(${this.translateWrapperX}px)`,
transformOrigin: 'top left',
height: `${100 * this.fitContentScale}%`,
}}
onMouseLeave={() => this.setHoveredNodeIndex(-1)}>
{this.renderCardsSort}
</div>
{/* <Card className={`custom-modal-position step-${step}`}>
<Card.Header>
{header}
<Button variant="close" className= "tut-close"onClick={store.toggleTutorial} style={{ position: 'absolute', top: 0, right: 0 }} />
</Card.Header>
<Card.Body>{body}
<Button className= 'next-step' variant="primary" onClick={store.nextStep}>Next Step!</Button>
</Card.Body>
</Card> */}
{/* {this.focusContent} */}
</div>
);
}
}
|