aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/PropertiesView.tsx
blob: 9fc19253e18f6af14b9bd282aa79b7039199081e (plain)
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
import React = require("react");
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Checkbox, Tooltip } from "@material-ui/core";
import { intersection } from "lodash";
import { action, autorun, computed, Lambda, observable, reaction, runInAction } from "mobx";
import { observer } from "mobx-react";
import { ColorState, SketchPicker } from "react-color";
import { AclAddonly, AclAdmin, AclEdit, AclPrivate, AclReadonly, AclSym, AclUnset, DataSym, Doc, Field, HeightSym, Opt, WidthSym } from "../../fields/Doc";
import { Id } from "../../fields/FieldSymbols";
import { InkField } from "../../fields/InkField";
import { ComputedField } from "../../fields/ScriptField";
import { Cast, NumCast, StrCast } from "../../fields/Types";
import { denormalizeEmail, GetEffectiveAcl, SharingPermissions } from "../../fields/util";
import { emptyFunction, returnEmptyDoclist, returnEmptyFilter, returnFalse, returnTrue } from "../../Utils";
import { DocumentType } from "../documents/DocumentTypes";
import { DocumentManager } from "../util/DocumentManager";
import { SelectionManager } from "../util/SelectionManager";
import { SharingManager } from "../util/SharingManager";
import { Transform } from "../util/Transform";
import { undoBatch, UndoManager } from "../util/UndoManager";
import { CollectionDockingView } from "./collections/CollectionDockingView";
import { CollectionViewType } from "./collections/CollectionView";
import { EditableView } from "./EditableView";
import { InkStrokeProperties } from "./InkStrokeProperties";
import { DocumentView, StyleProviderFunc } from "./nodes/DocumentView";
import { KeyValueBox } from "./nodes/KeyValueBox";
import { PresBox } from "./nodes/PresBox";
import { PropertiesButtons } from "./PropertiesButtons";
import { PropertiesDocContextSelector } from "./PropertiesDocContextSelector";
import "./PropertiesView.scss";
import { DefaultStyleProvider, FilteringStyleProvider } from "./StyleProvider";
import { CurrentUserUtils } from "../util/CurrentUserUtils";
import { FilterBox } from "./nodes/FilterBox";
import { List } from "../../fields/List";
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;
const _global = (window /* browser */ || global /* node */) as any;

interface PropertiesViewProps {
    width: number;
    height: number;
    styleProvider?: StyleProviderFunc;
}

@observer
export class PropertiesView extends React.Component<PropertiesViewProps> {
    private _widthUndo?: UndoManager.Batch;

    @computed get MAX_EMBED_HEIGHT() { return 200; }

    @computed get selectedDoc() { return SelectionManager.SelectedSchemaDoc() || this.selectedDocumentView?.rootDoc; }
    @computed get filterDoc() {
        return FilterBox._filterScope === "Current Collection" ? this.selectedDoc! : CurrentUserUtils.ActiveDashboard;
    }
    @computed get selectedDocumentView() {
        if (SelectionManager.Views().length) return SelectionManager.Views()[0];
        if (PresBox.Instance?._selectedArray.size) return DocumentManager.Instance.getDocumentView(PresBox.Instance.rootDoc);
        return undefined;
    }
    @computed get isPres(): boolean {
        return this.selectedDoc?.type === DocumentType.PRES;
    }
    @computed get dataDoc() { return this.selectedDoc?.[DataSym]; }

    @observable layoutFields: boolean = false;

    @observable openOptions: boolean = true;
    @observable openSharing: boolean = true;
    @observable openFields: boolean = true;
    @observable openLayout: boolean = false;
    @observable openContexts: boolean = true;
    @observable openAppearance: boolean = true;
    @observable openTransform: boolean = true;
    @observable openFilters: boolean = true; // should be false

    /**
     * autorun to set up the filter doc of a collection if that collection has been selected and the filters panel is open
     */
    private selectedDocListenerDisposer: Opt<Lambda>;

    // @observable selectedUser: string = "";
    // @observable addButtonPressed: boolean = false;
    @observable layoutDocAcls: boolean = false;

    //Pres Trails booleans:
    @observable openPresTransitions: boolean = false;
    @observable openPresProgressivize: boolean = false;
    @observable openAddSlide: boolean = false;
    @observable openSlideOptions: boolean = false;

    @observable inOptions: boolean = false;
    @observable _controlBtn: boolean = false;
    @observable _lock: boolean = false;

    componentDidMount() {
        this.selectedDocListenerDisposer?.();
        this.selectedDocListenerDisposer = autorun(() => this.openFilters && this.selectedDoc && this.checkFilterDoc());
    }

    componentWillUnmount() {
        this.selectedDocListenerDisposer?.();
    }

    @computed get isInk() { return this.selectedDoc?.type === DocumentType.INK; }

    rtfWidth = () => {
        return !this.selectedDoc ? 0 : Math.min(this.selectedDoc?.[WidthSym](), this.props.width - 20);
    }
    rtfHeight = () => {
        return !this.selectedDoc ? 0 : this.rtfWidth() <= this.selectedDoc?.[WidthSym]() ? Math.min(this.selectedDoc?.[HeightSym](), this.MAX_EMBED_HEIGHT) : this.MAX_EMBED_HEIGHT;
    }

    @action
    docWidth = () => {
        if (this.selectedDoc) {
            const layoutDoc = this.selectedDoc;
            const aspect = Doc.NativeAspect(layoutDoc, undefined, !layoutDoc._fitWidth);
            if (aspect) return Math.min(layoutDoc[WidthSym](), Math.min(this.MAX_EMBED_HEIGHT * aspect, this.props.width - 20));
            return Doc.NativeWidth(layoutDoc) ? Math.min(layoutDoc[WidthSym](), this.props.width - 20) : this.props.width - 20;
        } else {
            return 0;
        }
    }

    @action
    docHeight = () => {
        if (this.selectedDoc && this.dataDoc) {
            const layoutDoc = this.selectedDoc;
            return Math.max(70, Math.min(this.MAX_EMBED_HEIGHT,
                Doc.NativeAspect(layoutDoc, undefined, true) ? this.docWidth() / Doc.NativeAspect(layoutDoc, undefined, true) :
                    layoutDoc._fitWidth ? (!Doc.NativeHeight(this.dataDoc) ? NumCast(this.props.height) :
                        Math.min(this.docWidth() * NumCast(layoutDoc.scrollHeight, Doc.NativeHeight(layoutDoc)) / Doc.NativeWidth(layoutDoc) || NumCast(this.props.height))) :
                        NumCast(layoutDoc._height) || 50));
        }
        return 0;
    }

    @computed get expandedField() {
        if (this.dataDoc && this.selectedDoc) {
            const ids: { [key: string]: string } = {};
            const docs = SelectionManager.Views().length < 2 ? [this.layoutFields ? Doc.Layout(this.selectedDoc) : this.dataDoc] :
                SelectionManager.Views().map(dv => this.layoutFields ? dv.layoutDoc : dv.dataDoc);
            docs.forEach(doc => Object.keys(doc).forEach(key => !(key in ids) && doc[key] !== ComputedField.undefined && (ids[key] = key)));
            const rows: JSX.Element[] = [];
            for (const key of Object.keys(ids).slice().sort()) {
                const docvals = new Set<any>();
                docs.forEach(doc => docvals.add(doc[key]));
                const contents = Array.from(docvals.keys()).length > 1 ? "-multiple" : docs[0][key];
                if (key[0] === "#") {
                    rows.push(<div style={{ display: "flex", overflowY: "visible", marginBottom: "2px" }} key={key}>
                        <span style={{ fontWeight: "bold", whiteSpace: "nowrap" }}>{key}</span>
                    &nbsp;
                </div>);
                } else {
                    const contentElement = <EditableView key="editableView"
                        contents={contents !== undefined ? Field.toString(contents as Field) : "null"}
                        height={13}
                        fontSize={10}
                        GetValue={() => contents !== undefined ? Field.toString(contents as Field) : "null"}
                        SetValue={(value: string) => { docs.map(doc => KeyValueBox.SetField(doc, key, value, true)); return true; }}
                    />;
                    rows.push(<div style={{ display: "flex", overflowY: "visible", marginBottom: "-1px" }} key={key}>
                        <span style={{ fontWeight: "bold", whiteSpace: "nowrap" }}>{key + ":"}</span>
                        &nbsp;
                        {contentElement}
                    </div>);
                }
            }
            rows.push(<div className="propertiesView-field" key={"newKeyValue"} style={{ marginTop: "3px" }}>
                <EditableView
                    key="editableView"
                    oneLine
                    contents={"add key:value or #tags"}
                    height={13}
                    fontSize={10}
                    GetValue={() => ""}
                    SetValue={this.setKeyValue} />
            </div>);
            return rows;
        }
    }

    @computed get noviceFields() {
        if (this.dataDoc) {
            const ids: { [key: string]: string } = {};
            const docs = SelectionManager.Views().length < 2 ? [this.dataDoc] : SelectionManager.Views().map(dv => dv.dataDoc);
            docs.forEach(doc => Object.keys(doc).forEach(key => !(key in ids) && doc[key] !== ComputedField.undefined && (ids[key] = key)));
            const rows: JSX.Element[] = [];
            const noviceReqFields = ["author", "creationDate", "tags"];
            const noviceLayoutFields = ["_curPage"];
            const noviceKeys = [...Array.from(Object.keys(ids)).filter(key => key[0] === "#" || key.indexOf("lastModified") !== -1 || (key[0] === key[0].toUpperCase() && !key.startsWith("acl"))),
            ...noviceReqFields, ...noviceLayoutFields];
            for (const key of noviceKeys.sort()) {
                const docvals = new Set<any>();
                docs.forEach(doc => docvals.add(doc[key]));
                const contents = Array.from(docvals.keys()).length > 1 ? "-multiple" : docs[0][key];
                if (key[0] === "#") {
                    rows.push(<div className="propertiesView-uneditable-field" key={key}>
                        <span style={{ fontWeight: "bold", whiteSpace: "nowrap" }}>{key}</span>
                        &nbsp;
                    </div>);
                } else if (contents !== undefined) {
                    const value = Field.toString(contents as Field);
                    if (noviceReqFields.includes(key) || key.indexOf("lastModified") !== -1) {
                        rows.push(<div className="propertiesView-uneditable-field" key={key}>
                            <span style={{ fontWeight: "bold", whiteSpace: "nowrap" }}>{key + ": "}</span>
                            <div style={{ whiteSpace: "nowrap", overflowX: "hidden" }}>{value}</div>
                        </div>);
                    } else {
                        const contentElement = <EditableView key="editableView"
                            contents={value}
                            height={13}
                            fontSize={10}
                            GetValue={() => contents !== undefined ? Field.toString(contents as Field) : "null"}
                            SetValue={(value: string) => { docs.map(doc => KeyValueBox.SetField(doc, key, value, true)); return true; }}
                        />;

                        rows.push(<div style={{ display: "flex", overflowY: "visible", marginBottom: "-1px" }} key={key}>
                            <span style={{ fontWeight: "bold", whiteSpace: "nowrap" }}>{key + ":"}</span>
                        &nbsp;
                        {contentElement}
                        </div>);
                    }
                }
            }
            rows.push(<div className="propertiesView-field" key={"newKeyValue"} style={{ marginTop: "3px" }}>
                <EditableView
                    key="editableView"
                    oneLine
                    contents={"add key:value or #tags"}
                    height={13}
                    fontSize={10}
                    GetValue={() => ""}
                    SetValue={this.setKeyValue} />
            </div>);
            return rows;
        }
    }

    @undoBatch
    setKeyValue = (value: string) => {
        const docs = SelectionManager.Views().length < 2 && this.selectedDoc ? [this.layoutFields ? Doc.Layout(this.selectedDoc) : this.dataDoc] : SelectionManager.Views().map(dv => this.layoutFields ? dv.layoutDoc : dv.dataDoc);
        docs.forEach(doc => {
            if (value.indexOf(":") !== -1) {
                const newVal = value[0].toUpperCase() + value.substring(1, value.length);
                const splits = newVal.split(":");
                KeyValueBox.SetField(doc, splits[0], splits[1], true);
                const tags = StrCast(doc.tags, ":");
                if (tags.includes(`${splits[0]}:`) && splits[1] === "undefined") {
                    KeyValueBox.SetField(doc, "tags", `"${tags.replace(splits[0] + ":", "")}"`, true);
                }
                return true;
            } else if (value[0] === "#") {
                const newVal = value + `:'${value}'`;
                doc[DataSym][value] = value;
                const tags = StrCast(doc.tags, ":");
                if (!tags.includes(`${value}:`)) {
                    doc[DataSym].tags = `${tags + value + ':'}`;
                }
                return true;
            }
        });
        return false;
    }

    @observable transform: Transform = Transform.Identity();
    getTransform = () => this.transform;
    propertiesDocViewRef = (ref: HTMLDivElement) => {
        const observer = new _global.ResizeObserver(action((entries: any) => {
            const cliRect = ref.getBoundingClientRect();
            this.transform = new Transform(-cliRect.x, -cliRect.y, 1);
        }));
        ref && observer.observe(ref);
    }

    @computed get contexts() {
        return !this.selectedDoc ? (null) : <PropertiesDocContextSelector Document={this.selectedDoc} hideTitle={true} addDocTab={(doc, where) => CollectionDockingView.AddSplit(doc, "right")} />;
    }

    @computed get layoutPreview() {
        if (SelectionManager.Views().length > 1) {
            return "-- multiple selected --";
        }
        if (this.selectedDoc) {
            const layoutDoc = Doc.Layout(this.selectedDoc);
            const panelHeight = StrCast(Doc.LayoutField(layoutDoc)).includes("FormattedTextBox") ? this.rtfHeight : this.docHeight;
            const panelWidth = StrCast(Doc.LayoutField(layoutDoc)).includes("FormattedTextBox") ? this.rtfWidth : this.docWidth;
            return <div ref={this.propertiesDocViewRef} style={{ pointerEvents: "none", display: "inline-block", height: panelHeight() }} key={this.selectedDoc[Id]}>
                <DocumentView
                    Document={layoutDoc}
                    DataDoc={this.dataDoc}
                    renderDepth={1}
                    fitContentsToDoc={returnTrue}
                    rootSelected={returnFalse}
                    styleProvider={DefaultStyleProvider}
                    layerProvider={undefined}
                    docViewPath={returnEmptyDoclist}
                    freezeDimensions={true}
                    dontCenter={"y"}
                    isDocumentActive={returnFalse}
                    isContentActive={returnFalse}
                    NativeWidth={layoutDoc.type === DocumentType.RTF ? this.rtfWidth : undefined}
                    NativeHeight={layoutDoc.type === DocumentType.RTF ? this.rtfHeight : undefined}
                    PanelWidth={panelWidth}
                    PanelHeight={panelHeight}
                    focus={returnFalse}
                    ScreenToLocalTransform={this.getTransform}
                    docFilters={returnEmptyFilter}
                    docRangeFilters={returnEmptyFilter}
                    searchFilterDocs={returnEmptyDoclist}
                    ContainingCollectionDoc={undefined}
                    ContainingCollectionView={undefined}
                    addDocument={returnFalse}
                    moveDocument={undefined}
                    removeDocument={returnFalse}
                    whenChildContentsActiveChanged={emptyFunction}
                    addDocTab={returnFalse}
                    pinToPres={emptyFunction}
                    bringToFront={returnFalse}
                    dontRegisterView={true}
                    dropAction={undefined}
                />
            </div>;
        } else {
            return null;
        }
    }

    /**
     * Handles the changing of a user's permissions from the permissions panel.
     */
    @undoBatch
    changePermissions = (e: any, user: string) => {
        const docs = SelectionManager.Views().length < 2 ? [this.selectedDoc!] : SelectionManager.Views().map(docView => docView.props.Document);
        SharingManager.Instance.shareFromPropertiesSidebar(user, e.currentTarget.value as SharingPermissions, docs);
    }

    /**
     * @returns the options for the permissions dropdown.
     */
    getPermissionsSelect(user: string, permission: string) {
        const dropdownValues: string[] = Object.values(SharingPermissions);
        if (permission === "-multiple-") dropdownValues.unshift(permission);
        if (user === "Override") dropdownValues.unshift("None");
        return <select className="permissions-select"
            value={permission}
            onChange={e => this.changePermissions(e, user)}>
            {dropdownValues.filter(permission => permission !== SharingPermissions.View).map(permission => {
                return (
                    <option key={permission} value={permission}>
                        {permission === SharingPermissions.Add ? "Can Augment" : permission}
                    </option>);
            })}
        </select>;
    }

    /**
     * @returns the notification icon. On clicking, it should notify someone of a document been shared with them.
     */
    @computed get notifyIcon() {
        return <Tooltip title={<div className="dash-tooltip">Notify with message</div>}>
            <div className="notify-button">
                <FontAwesomeIcon className="notify-button-icon" icon="bell" color="white" size="sm" />
            </div>
        </Tooltip>;
    }

    /**
     * ... next to the owner that opens the main SharingManager interface on click.
     */
    @computed get expansionIcon() {
        return <Tooltip title={<div className="dash-tooltip">{"Show more permissions"}</div>}>
            <div className="expansion-button" onPointerDown={() => {
                if (this.selectedDocumentView || this.selectedDoc) {
                    SharingManager.Instance.open(this.selectedDocumentView?.props.Document === this.selectedDocumentView ? this.selectedDocumentView : undefined, this.selectedDoc);
                }
            }}>
                <FontAwesomeIcon className="expansion-button-icon" icon="ellipsis-h" color="black" size="sm" />
            </div>
        </Tooltip>;
    }

    /**
     * @returns a row of the permissions panel
     */
    sharingItem(name: string, admin: boolean, permission: string, showExpansionIcon?: boolean) {
        return <div className="propertiesView-sharingTable-item" key={name + permission}
        // style={{ backgroundColor: this.selectedUser === name ? "#bcecfc" : "" }}
        // onPointerDown={action(() => this.selectedUser = this.selectedUser === name ? "" : name)}
        >
            <div className="propertiesView-sharingTable-item-name" style={{ width: name !== "Me" ? "85px" : "80px" }}> {name} </div>
            {/* {name !== "Me" ? this.notifyIcon : null} */}
            <div className="propertiesView-sharingTable-item-permission">
                {admin && permission !== "Owner" ? this.getPermissionsSelect(name, permission) : permission}
                {permission === "Owner" || showExpansionIcon ? this.expansionIcon : null}
            </div>
        </div>;
    }

    /**
     * @returns the sharing and permissions panel.
     */
    @computed get sharingTable() {
        const AclMap = new Map<symbol, string>([
            [AclUnset, "None"],
            [AclPrivate, SharingPermissions.None],
            [AclReadonly, SharingPermissions.View],
            [AclAddonly, SharingPermissions.Add],
            [AclEdit, SharingPermissions.Edit],
            [AclAdmin, SharingPermissions.Admin]
        ]);

        // all selected docs
        const docs = SelectionManager.Views().length < 2 ?
            [this.layoutDocAcls ? this.selectedDoc! : this.selectedDoc![DataSym]]
            : SelectionManager.Views().map(docView => this.layoutDocAcls ? docView.props.Document : docView.props.Document[DataSym]);

        const target = docs[0];

        // tslint:disable-next-line: no-unnecessary-callback-wrapper
        const effectiveAcls = docs.map(doc => GetEffectiveAcl(doc));
        const showAdmin = effectiveAcls.every(acl => acl === AclAdmin);

        // users in common between all docs
        const commonKeys: string[] = intersection(...docs.map(doc => this.layoutDocAcls ? doc?.[AclSym] && Object.keys(doc[AclSym]) : doc?.[DataSym][AclSym] && Object.keys(doc[DataSym][AclSym])));

        const tableEntries = [];

        // DocCastAsync(Doc.UserDoc().sidebarUsersDisplayed).then(sidebarUsersDisplayed => {
        if (commonKeys.length) {
            for (const key of commonKeys) {
                const name = denormalizeEmail(key.substring(4));
                const uniform = docs.every(doc => this.layoutDocAcls ? doc?.[AclSym]?.[key] === docs[0]?.[AclSym]?.[key] : doc?.[DataSym]?.[AclSym]?.[key] === docs[0]?.[DataSym]?.[AclSym]?.[key]);
                if (name !== Doc.CurrentUserEmail && name !== target.author && name !== "Public" && name !== "Override"/* && sidebarUsersDisplayed![name] !== false*/) {
                    tableEntries.push(this.sharingItem(name, showAdmin, uniform ? AclMap.get(this.layoutDocAcls ? target[AclSym][key] : target[DataSym][AclSym][key])! : "-multiple-"));
                }
            }
        }

        const ownerSame = Doc.CurrentUserEmail !== target.author && docs.filter(doc => doc).every(doc => doc.author === docs[0].author);
        // shifts the current user, owner, public to the top of the doc.
        // tableEntries.unshift(this.sharingItem("Override", showAdmin, docs.filter(doc => doc).every(doc => doc["acl-Override"] === docs[0]["acl-Override"]) ? (AclMap.get(target[AclSym]?.["acl-Override"]) || "None") : "-multiple-"));
        tableEntries.unshift(this.sharingItem("Public", showAdmin, docs.filter(doc => doc).every(doc => doc["acl-Public"] === docs[0]["acl-Public"]) ? (AclMap.get(target[AclSym]?.["acl-Public"]) || SharingPermissions.None) : "-multiple-"));
        tableEntries.unshift(this.sharingItem("Me", showAdmin, docs.filter(doc => doc).every(doc => doc.author === Doc.CurrentUserEmail) ? "Owner" : effectiveAcls.every(acl => acl === effectiveAcls[0]) ? AclMap.get(effectiveAcls[0])! : "-multiple-", !ownerSame));
        if (ownerSame) tableEntries.unshift(this.sharingItem(StrCast(target.author), showAdmin, "Owner"));

        return <div className="propertiesView-sharingTable">
            {tableEntries}
        </div>;
    }

    @computed get fieldsCheckbox() {
        return <Checkbox
            color="primary"
            onChange={this.toggleCheckbox}
            checked={this.layoutFields}
        />;
    }

    @action
    toggleCheckbox = () => {
        this.layoutFields = !this.layoutFields;
    }

    @computed get editableTitle() {
        const titles = new Set<string>();
        SelectionManager.Views().forEach(dv => titles.add(StrCast(dv.rootDoc.title)));
        const title = Array.from(titles.keys()).length > 1 ? "--multiple selected--" : StrCast(this.selectedDoc?.title);
        return <div className="editable-title">
            <EditableView
                key="editableView"
                contents={title}
                height={25}
                fontSize={14}
                GetValue={() => title}
                SetValue={this.setTitle} />
        </div>;
    }

    @undoBatch
    @action
    setTitle = (value: string) => {
        if (SelectionManager.Views().length > 1) {
            SelectionManager.Views().map(dv => Doc.SetInPlace(dv.rootDoc, "title", value, true));
            return true;
        } else if (this.dataDoc) {
            if (this.selectedDoc) Doc.SetInPlace(this.selectedDoc, "title", value, true);
            else KeyValueBox.SetField(this.dataDoc, "title", value, true);
            return true;
        }
        return false;
    }


    @undoBatch
    @action
    rotate = (angle: number) => {
        const _centerPoints: { X: number, Y: number }[] = [];
        if (this.selectedDoc) {
            const doc = this.selectedDoc;
            if (doc.type === DocumentType.INK && doc.x && doc.y && doc._width && doc._height && doc.data) {
                const ink = Cast(doc.data, InkField)?.inkData;
                if (ink) {
                    const xs = ink.map(p => p.X);
                    const ys = ink.map(p => p.Y);
                    const left = Math.min(...xs);
                    const top = Math.min(...ys);
                    const right = Math.max(...xs);
                    const bottom = Math.max(...ys);
                    _centerPoints.push({ X: left, Y: top });
                }
            }

            var index = 0;
            if (doc.type === DocumentType.INK && doc.x && doc.y && doc._width && doc._height && doc.data) {
                doc.rotation = NumCast(doc.rotation) + angle;
                const inks = Cast(doc.data, InkField)?.inkData;
                if (inks) {
                    const newPoints: { X: number, Y: number }[] = [];
                    inks.forEach(ink => {
                        const newX = Math.cos(angle) * (ink.X - _centerPoints[index].X) - Math.sin(angle) * (ink.Y - _centerPoints[index].Y) + _centerPoints[index].X;
                        const newY = Math.sin(angle) * (ink.X - _centerPoints[index].X) + Math.cos(angle) * (ink.Y - _centerPoints[index].Y) + _centerPoints[index].Y;
                        newPoints.push({ X: newX, Y: newY });
                    });
                    doc.data = new InkField(newPoints);
                    const xs = newPoints.map(p => p.X);
                    const ys = newPoints.map(p => p.Y);
                    const left = Math.min(...xs);
                    const top = Math.min(...ys);
                    const right = Math.max(...xs);
                    const bottom = Math.max(...ys);

                    doc._height = (bottom - top);
                    doc._width = (right - left);
                }
                index++;
            }
        }
    }

    @computed
    get controlPointsButton() {
        const formatInstance = InkStrokeProperties.Instance;
        return !formatInstance ? (null) : <div className="inking-button">
            <Tooltip title={<div className="dash-tooltip">{"Edit points"}</div>}>
                <div className="inking-button-points" onPointerDown={action(() => formatInstance._controlBtn = !formatInstance._controlBtn)} style={{ backgroundColor: formatInstance._controlBtn ? "black" : "" }}>
                    <FontAwesomeIcon icon="bezier-curve" color="white" size="lg" />
                </div>
            </Tooltip>
            <Tooltip title={<div className="dash-tooltip">{formatInstance._lock ? "Unlock ratio" : "Lock ratio"}</div>}>
                <div className="inking-button-lock" onPointerDown={action(() => formatInstance._lock = !formatInstance._lock)} >
                    <FontAwesomeIcon icon={formatInstance._lock ? "lock" : "unlock"} color="white" size="lg" />
                </div>
            </Tooltip>
            <Tooltip title={<div className="dash-tooltip">{"Rotate 90˚"}</div>}>
                <div className="inking-button-rotate" onPointerDown={action(() => this.rotate(Math.PI / 2))}>
                    <FontAwesomeIcon icon="undo" color="white" size="lg" />
                </div>
            </Tooltip>
        </div>;
    }

    inputBox = (key: string, value: any, setter: (val: string) => {}, title: string) => {
        return <div className="inputBox"
            style={{
                marginRight: title === "X:" ? "19px" : "",
                marginLeft: title === "∠:" ? "39px" : ""
            }}>
            <div className="inputBox-title"> {title} </div>
            <input className="inputBox-input"
                type="text" value={value}
                onChange={e => {
                    setter(e.target.value);
                }}
                onKeyPress={e => {
                    e.stopPropagation();
                }} />
            <div className="inputBox-button">
                <div className="inputBox-button-up" key="up2"
                    onPointerDown={undoBatch(action(() => this.upDownButtons("up", key)))} >
                    <FontAwesomeIcon icon="caret-up" color="white" size="sm" />
                </div>
                <div className="inputbox-Button-down" key="down2"
                    onPointerDown={undoBatch(action(() => this.upDownButtons("down", key)))} >
                    <FontAwesomeIcon icon="caret-down" color="white" size="sm" />
                </div>
            </div>
        </div>;
    }

    inputBoxDuo = (key: string, value: any, setter: (val: string) => {}, title1: string, key2: string, value2: any, setter2: (val: string) => {}, title2: string) => {
        return <div className="inputBox-duo">
            {this.inputBox(key, value, setter, title1)}
            {title2 === "" ? (null) : this.inputBox(key2, value2, setter2, title2)}
        </div>;
    }

    @action
    upDownButtons = (dirs: string, field: string) => {
        switch (field) {
            case "rot": this.rotate((dirs === "up" ? .1 : -.1)); break;
            case "Xps": this.selectedDoc && (this.selectedDoc.x = NumCast(this.selectedDoc?.x) + (dirs === "up" ? 10 : -10)); break;
            case "Yps": this.selectedDoc && (this.selectedDoc.y = NumCast(this.selectedDoc?.y) + (dirs === "up" ? 10 : -10)); break;
            case "stk": this.selectedDoc && (this.selectedDoc.strokeWidth = NumCast(this.selectedDoc?.strokeWidth) + (dirs === "up" ? .1 : -.1)); break;
            case "wid":
                const oldWidth = NumCast(this.selectedDoc?._width);
                const oldHeight = NumCast(this.selectedDoc?._height);
                const oldX = NumCast(this.selectedDoc?.x);
                const oldY = NumCast(this.selectedDoc?.y);
                this.selectedDoc && (this.selectedDoc._width = oldWidth + (dirs === "up" ? 10 : - 10));
                InkStrokeProperties.Instance?._lock && this.selectedDoc && (this.selectedDoc._height = (NumCast(this.selectedDoc?._width) / oldWidth * NumCast(this.selectedDoc?._height)));
                const doc = this.selectedDoc;
                if (doc?.type === DocumentType.INK && doc.x && doc.y && doc._height && doc._width) {
                    const ink = Cast(doc.data, InkField)?.inkData;
                    if (ink) {
                        const newPoints: { X: number, Y: number }[] = [];
                        for (var j = 0; j < ink.length; j++) {
                            // (new x — oldx) + (oldxpoint * newWidt)/oldWidth 
                            const newX = (NumCast(doc.x) - oldX) + (ink[j].X * NumCast(doc._width)) / oldWidth;
                            const newY = (NumCast(doc.y) - oldY) + (ink[j].Y * NumCast(doc._height)) / oldHeight;
                            newPoints.push({ X: newX, Y: newY });
                        }
                        doc.data = new InkField(newPoints);
                    }
                }
                break;
            case "hgt":
                const oWidth = NumCast(this.selectedDoc?._width);
                const oHeight = NumCast(this.selectedDoc?._height);
                const oX = NumCast(this.selectedDoc?.x);
                const oY = NumCast(this.selectedDoc?.y);
                this.selectedDoc && (this.selectedDoc._height = oHeight + (dirs === "up" ? 10 : - 10));
                InkStrokeProperties.Instance?._lock && this.selectedDoc && (this.selectedDoc._width = (NumCast(this.selectedDoc?._height) / oHeight * NumCast(this.selectedDoc?._width)));
                const docu = this.selectedDoc;
                if (docu?.type === DocumentType.INK && docu.x && docu.y && docu._height && docu._width) {
                    const ink = Cast(docu.data, InkField)?.inkData;
                    if (ink) {
                        const newPoints: { X: number, Y: number }[] = [];
                        for (var j = 0; j < ink.length; j++) {
                            // (new x — oldx) + (oldxpoint * newWidt)/oldWidth 
                            const newX = (NumCast(docu.x) - oX) + (ink[j].X * NumCast(docu._width)) / oWidth;
                            const newY = (NumCast(docu.y) - oY) + (ink[j].Y * NumCast(docu._height)) / oHeight;
                            newPoints.push({ X: newX, Y: newY });
                        }
                        docu.data = new InkField(newPoints);
                    }
                }
                break;
        }
    }

    getField(key: string) {
        //if (this.selectedDoc) {
        return Field.toString(this.selectedDoc?.[key] as Field);
        // } else {
        //     return undefined as Opt<string>;
        // }
    }

    @computed get shapeXps() { return this.getField("x"); }
    @computed get shapeYps() { return this.getField("y"); }
    @computed get shapeRot() { return this.getField("rotation"); }
    @computed get shapeHgt() { return this.getField("_height"); }
    @computed get shapeWid() { return this.getField("_width"); }
    set shapeXps(value) { this.selectedDoc && (this.selectedDoc.x = Number(value)); }
    set shapeYps(value) { this.selectedDoc && (this.selectedDoc.y = Number(value)); }
    set shapeRot(value) { this.selectedDoc && (this.selectedDoc.rotation = Number(value)); }
    set shapeWid(value) {
        const oldWidth = NumCast(this.selectedDoc?._width);
        this.selectedDoc && (this.selectedDoc._width = Number(value));
        InkStrokeProperties.Instance?._lock && this.selectedDoc && (this.selectedDoc._height = (NumCast(this.selectedDoc?._width) * NumCast(this.selectedDoc?._height)) / oldWidth);
    }
    set shapeHgt(value) {
        const oldHeight = NumCast(this.selectedDoc?._height);
        this.selectedDoc && (this.selectedDoc._height = Number(value));
        InkStrokeProperties.Instance?._lock && this.selectedDoc && (this.selectedDoc._width = (NumCast(this.selectedDoc?._height) * NumCast(this.selectedDoc?._width)) / oldHeight);
    }

    @computed get hgtInput() { return this.inputBoxDuo("hgt", this.shapeHgt, (val: string) => { if (!isNaN(Number(val))) { this.shapeHgt = val; } return true; }, "H:", "wid", this.shapeWid, (val: string) => { if (!isNaN(Number(val))) { this.shapeWid = val; } return true; }, "W:"); }
    @computed get XpsInput() { return this.inputBoxDuo("Xps", this.shapeXps, (val: string) => { if (val !== "0" && !isNaN(Number(val))) { this.shapeXps = val; } return true; }, "X:", "Yps", this.shapeYps, (val: string) => { if (val !== "0" && !isNaN(Number(val))) { this.shapeYps = val; } return true; }, "Y:"); }
    @computed get rotInput() { return this.inputBoxDuo("rot", this.shapeRot, (val: string) => { if (!isNaN(Number(val))) { this.rotate(Number(val) - Number(this.shapeRot)); this.shapeRot = val; } return true; }, "∠:", "rot", this.shapeRot, (val: string) => { if (!isNaN(Number(val))) { this.rotate(Number(val) - Number(this.shapeRot)); this.shapeRot = val; } return true; }, ""); }


    @observable private _fillBtn = false;
    @observable private _lineBtn = false;

    private _lastFill = "#D0021B";
    private _lastLine = "#D0021B";
    private _lastDash: any = "2";

    @computed get colorFil() { const ccol = this.getField("fillColor") || ""; ccol && (this._lastFill = ccol); return ccol; }
    @computed get colorStk() { const ccol = this.getField("color") || ""; ccol && (this._lastLine = ccol); return ccol; }
    set colorFil(value) { value && (this._lastFill = value); this.selectedDoc && (this.selectedDoc.fillColor = value ? value : undefined); }
    set colorStk(value) { value && (this._lastLine = value); this.selectedDoc && (this.selectedDoc.color = value ? value : undefined); }

    colorButton(value: string, type: string, setter: () => {}) {
        // return <div className="properties-flyout" onPointerEnter={e => this.changeScrolling(false)}
        //     onPointerLeave={e => this.changeScrolling(true)}>
        //     <Flyout anchorPoint={anchorPoints.LEFT_TOP}
        //         content={type === "fill" ? this.fillPicker : this.linePicker}>
        return <div className="color-button" key="color" onPointerDown={undoBatch(action(e => setter()))}>
            <div className="color-button-preview" style={{
                backgroundColor: value ?? "121212", width: 15, height: 15,
                display: value === "" || value === "transparent" ? "none" : ""
            }} />
            {value === "" || value === "transparent" ? <p style={{ fontSize: 25, color: "red", marginTop: -14 }}>☒</p> : ""}
        </div>;
        //     </Flyout>
        // </div>;

    }

    @undoBatch
    @action
    switchStk = (color: ColorState) => {
        const val = String(color.hex);
        this.colorStk = val;
        return true;
    }
    @undoBatch
    @action
    switchFil = (color: ColorState) => {
        const val = String(color.hex);
        this.colorFil = val;
        return true;
    }

    colorPicker(setter: (color: string) => {}, type: string) {
        return <SketchPicker onChange={type === "stk" ? this.switchStk : this.switchFil}
            presetColors={['#D0021B', '#F5A623', '#F8E71C', '#8B572A', '#7ED321', '#417505',
                '#9013FE', '#4A90E2', '#50E3C2', '#B8E986', '#000000', '#4A4A4A', '#9B9B9B',
                '#FFFFFF', '#f1efeb', 'transparent']}
            color={type === "stk" ? this.colorStk : this.colorFil} />;
    }

    @computed get fillButton() { return this.colorButton(this.colorFil, "fill", () => { this._fillBtn = !this._fillBtn; this._lineBtn = false; return true; }); }
    @computed get lineButton() { return this.colorButton(this.colorStk, "line", () => { this._lineBtn = !this._lineBtn; this._fillBtn = false; return true; }); }

    @computed get fillPicker() { return this.colorPicker((color: string) => this.colorFil = color, "fil"); }
    @computed get linePicker() { return this.colorPicker((color: string) => this.colorStk = color, "stk"); }

    @computed get strokeAndFill() {
        return <div>
            <div key="fill" className="strokeAndFill">
                <div className="fill">
                    <div className="fill-title">Fill:</div>
                    <div className="fill-button">{this.fillButton}</div>
                </div>
                <div className="stroke">
                    <div className="stroke-title"> Stroke: </div>
                    <div className="stroke-button">{this.lineButton}</div>
                </div>
            </div>
            {this._fillBtn ? this.fillPicker : ""}
            {this._lineBtn ? this.linePicker : ""}
        </div>;
    }

    @computed get solidStk() { return this.selectedDoc?.color && (!this.selectedDoc?.strokeDash || this.selectedDoc?.strokeDash === "0") ? true : false; }
    @computed get dashdStk() { return this.selectedDoc?.strokeDash || ""; }
    @computed get unStrokd() { return this.selectedDoc?.color ? true : false; }
    @computed get widthStk() { return this.getField("strokeWidth") || "1"; }
    @computed get markHead() { return this.getField("strokeStartMarker") || ""; }
    @computed get markTail() { return this.getField("strokeEndMarker") || ""; }
    set solidStk(value) { this.dashdStk = ""; this.unStrokd = !value; }
    set dashdStk(value) {
        value && (this._lastDash = value) && (this.unStrokd = false);
        this.selectedDoc && (this.selectedDoc.strokeDash = value ? this._lastDash : undefined);
    }
    set widthStk(value) { this.selectedDoc && (this.selectedDoc.strokeWidth = Number(value)); }
    set unStrokd(value) { this.colorStk = value ? "" : this._lastLine; }
    set markHead(value) { this.selectedDoc && (this.selectedDoc.strokeStartMarker = value); }
    set markTail(value) { this.selectedDoc && (this.selectedDoc.strokeEndMarker = value); }


    @computed get stkInput() { return this.regInput("stk", this.widthStk, (val: string) => this.widthStk = val); }


    regInput = (key: string, value: any, setter: (val: string) => {}) => {
        return <div className="inputBox">
            <input className="inputBox-input"
                type="text" value={value}
                onChange={e => setter(e.target.value)} />
            <div className="inputBox-button">
                <div className="inputBox-button-up" key="up2"
                    onPointerDown={undoBatch(action(() => this.upDownButtons("up", key)))} >
                    <FontAwesomeIcon icon="caret-up" color="white" size="sm" />
                </div>
                <div className="inputbox-Button-down" key="down2"
                    onPointerDown={undoBatch(action(() => this.upDownButtons("down", key)))} >
                    <FontAwesomeIcon icon="caret-down" color="white" size="sm" />
                </div>
            </div>
        </div>;
    }

    @computed get widthAndDash() {
        return <div className="widthAndDash">
            <div className="width">
                <div className="width-top">
                    <div className="width-title">Width:</div>
                    <div className="width-input">{this.stkInput}</div>
                </div>
                <input className="width-range" type="range"
                    defaultValue={Number(this.widthStk)} min={1} max={100}
                    onChange={(action((e) => this.widthStk = e.target.value))}
                    onMouseDown={(e) => { this._widthUndo = UndoManager.StartBatch("width undo"); }}
                    onMouseUp={(e) => { this._widthUndo?.end(); this._widthUndo = undefined; }}
                />
            </div>

            <div className="arrows">
                <div className="arrows-head">
                    <div className="arrows-head-title" >Arrow Head: </div>
                    <input key="markHead" className="arrows-head-input" type="checkbox"
                        checked={this.markHead !== ""}
                        onChange={undoBatch(action(() => this.markHead = this.markHead ? "" : "arrow"))} />
                </div>
                <div className="arrows-tail">
                    <div className="arrows-tail-title" >Arrow End: </div>
                    <input key="markTail" className="arrows-tail-input" type="checkbox"
                        checked={this.markTail !== ""}
                        onChange={undoBatch(action(() => this.markTail = this.markTail ? "" : "arrow"))} />
                </div>
            </div>
            <div className="dashed">
                <div className="dashed-title">Dashed Line:</div>
                <input key="markHead" className="dashed-input"
                    type="checkbox" checked={this.dashdStk === "2"}
                    onChange={this.changeDash} />
            </div>
        </div>;
    }

    @undoBatch @action
    changeDash = () => {
        this.dashdStk = this.dashdStk === "2" ? "0" : "2";
    }

    @computed get appearanceEditor() {
        return <div className="appearance-editor">
            {this.widthAndDash}
            {this.strokeAndFill}
        </div>;
    }

    @computed get transformEditor() {
        return <div className="transform-editor">
            {this.controlPointsButton}
            {this.hgtInput}
            {this.XpsInput}
            {this.rotInput}
        </div>;
    }

    @computed get optionsSubMenu() {
        return <div className="propertiesView-settings" onPointerEnter={action(() => this.inOptions = true)}
            onPointerLeave={action(() => this.inOptions = false)}>
            <div className="propertiesView-settings-title"
                onPointerDown={action(() => this.openOptions = !this.openOptions)}
                style={{ backgroundColor: this.openOptions ? "black" : "" }}>
                Options
                        <div className="propertiesView-settings-title-icon">
                    <FontAwesomeIcon icon={this.openOptions ? "caret-down" : "caret-right"} size="lg" color="white" />
                </div>
            </div>
            {!this.openOptions ? (null) :
                <div className="propertiesView-settings-content">
                    <PropertiesButtons />
                </div>}
        </div>;
    }

    @computed get sharingSubMenu() {
        return <div className="propertiesView-sharing">
            <div className="propertiesView-sharing-title"
                onPointerDown={action(() => this.openSharing = !this.openSharing)}
                style={{ backgroundColor: this.openSharing ? "black" : "" }}>
                Sharing {"&"} Permissions
                        <div className="propertiesView-sharing-title-icon">
                    <FontAwesomeIcon icon={this.openSharing ? "caret-down" : "caret-right"} size="lg" color="white" />
                </div>
            </div>
            {!this.openSharing ? (null) :
                <div className="propertiesView-sharing-content">
                    <div className="propertiesView-buttonContainer">
                        {!Doc.UserDoc().noviceMode ? (<div className="propertiesView-acls-checkbox">
                            <Checkbox
                                color="primary"
                                onChange={action(() => this.layoutDocAcls = !this.layoutDocAcls)}
                                checked={this.layoutDocAcls}
                            />
                            <div className="propertiesView-acls-checkbox-text">Layout</div>
                        </div>) : (null)}
                        {/* <Tooltip title={<><div className="dash-tooltip">{"Re-distribute sharing settings"}</div></>}>
                                        <button onPointerDown={() => SharingManager.Instance.distributeOverCollection(this.selectedDoc!)}>
                                            <FontAwesomeIcon icon="redo-alt" color="white" size="1x" />
                                        </button>
                                    </Tooltip> */}
                    </div>
                    {this.sharingTable}
                </div>}
        </div>;
    }

    /**
     * Checks if a currentFilter (FilterDoc) exists on the current collection (if the Properties Panel + Filters submenu are open).
     * If it doesn't exist, it creates it.
     */
    checkFilterDoc() {
        if (this.filterDoc.type === DocumentType.COL && !this.filterDoc.currentFilter) CurrentUserUtils.setupFilterDocs(this.filterDoc);
    }

    /**
     * Creates a new currentFilter for this.filterDoc, 
     */
    createNewFilterDoc = () => {
        const temp = this.filterDoc._docFilters;
        this.filterDoc._docFilters = new List<string>();
        (this.filterDoc.currentFilter as Doc)._docFiltersList = temp;
        this.filterDoc.currentFilter = undefined;
        CurrentUserUtils.setupFilterDocs(this.filterDoc);
    }

    /**
     * Updates this.filterDoc's currentFilter and saves the docFilters on the currentFilter
     */
    updateFilterDoc = (doc: Doc) => {
        if (doc === this.filterDoc.currentFilter) return; // causes problems if you try to reapply the same doc
        const temp = doc._docFiltersList;
        const otherTemp = this.filterDoc._docFilters;
        this.filterDoc._docFilters = new List<string>();
        (this.filterDoc.currentFilter as Doc)._docFiltersList = otherTemp;
        this.filterDoc.currentFilter = doc;
        doc._docFiltersList = new List<string>();
        this.filterDoc._docFilters = temp;
    }

    @computed get filtersSubMenu() {
        return !this.filterDoc?.currentFilter ? (null) : <div className="propertiesView-filters">
            <div className="propertiesView-filters-title"
                onPointerDown={action(() => this.openFilters = !this.openFilters)}
                style={{ backgroundColor: this.openFilters ? "black" : "" }}>
                Filters
                        <div className="propertiesView-filters-title-icon">
                    <FontAwesomeIcon icon={this.openFilters ? "caret-down" : "caret-right"} size="lg" color="white" />
                </div>
            </div>
            {
                !this.openFilters ? (null) :
                    <div className="propertiesView-filters-content">
                        <DocumentView
                            Document={this.filterDoc.currentFilter as Doc}
                            DataDoc={undefined}
                            addDocument={undefined}
                            addDocTab={returnFalse}
                            pinToPres={emptyFunction}
                            rootSelected={returnTrue}
                            removeDocument={returnFalse}
                            ScreenToLocalTransform={this.getTransform}
                            PanelWidth={this.docWidth}
                            PanelHeight={this.docHeight}
                            renderDepth={0}
                            scriptContext={this.filterDoc.currentFilter as Doc}
                            focus={emptyFunction}
                            styleProvider={DefaultStyleProvider}
                            parentActive={returnTrue}
                            whenActiveChanged={emptyFunction}
                            bringToFront={emptyFunction}
                            docFilters={returnEmptyFilter}
                            docRangeFilters={returnEmptyFilter}
                            searchFilterDocs={returnEmptyDoclist}
                            ContainingCollectionView={undefined}
                            ContainingCollectionDoc={undefined}
                            createNewFilterDoc={this.createNewFilterDoc}
                            updateFilterDoc={this.updateFilterDoc}
                            docViewPath={returnEmptyDoclist}
                            layerProvider={undefined}
                            dontCenter="y"
                        />
                    </div>
            }
        </div >;
    }

    @computed get inkSubMenu() {
        return <>
            {!this.isInk ? (null) :
                <div className="propertiesView-appearance">
                    <div className="propertiesView-appearance-title"
                        onPointerDown={action(() => this.openAppearance = !this.openAppearance)}
                        style={{ backgroundColor: this.openAppearance ? "black" : "" }}>
                        Appearance
                            <div className="propertiesView-appearance-title-icon">
                            <FontAwesomeIcon icon={this.openAppearance ? "caret-down" : "caret-right"} size="lg" color="white" />
                        </div>
                    </div>
                    {!this.openAppearance ? (null) :
                        <div className="propertiesView-appearance-content">
                            {this.appearanceEditor}
                        </div>}
                </div>}

            {this.isInk ? <div className="propertiesView-transform">
                <div className="propertiesView-transform-title"
                    onPointerDown={action(() => this.openTransform = !this.openTransform)}
                    style={{ backgroundColor: this.openTransform ? "black" : "" }}>
                    Transform
                        <div className="propertiesView-transform-title-icon">
                        <FontAwesomeIcon icon={this.openTransform ? "caret-down" : "caret-right"} size="lg" color="white" />
                    </div>
                </div>
                {this.openTransform ? <div className="propertiesView-transform-content">
                    {this.transformEditor}
                </div> : null}
            </div> : null}
        </>;
    }

    @computed get fieldsSubMenu() {
        return <div className="propertiesView-fields">
            <div className="propertiesView-fields-title"
                onPointerDown={action(() => this.openFields = !this.openFields)}
                style={{ backgroundColor: this.openFields ? "black" : "" }}>
                Fields {"&"} Tags
                            <div className="propertiesView-fields-title-icon">
                    <FontAwesomeIcon icon={this.openFields ? "caret-down" : "caret-right"} size="lg" color="white" />
                </div>
            </div>
            {!Doc.UserDoc().noviceMode && this.openFields ? <div className="propertiesView-fields-checkbox">
                {this.fieldsCheckbox}
                <div className="propertiesView-fields-checkbox-text">Layout</div>
            </div> : null}
            {!this.openFields ? (null) :
                <div className="propertiesView-fields-content">
                    {Doc.UserDoc().noviceMode ? this.noviceFields : this.expandedField}
                </div>}
        </div>;
    }

    @computed get contextsSubMenu() {
        return <div className="propertiesView-contexts">
            <div className="propertiesView-contexts-title"
                onPointerDown={action(() => this.openContexts = !this.openContexts)}
                style={{ backgroundColor: this.openContexts ? "black" : "" }}>
                Contexts
                        <div className="propertiesView-contexts-title-icon">
                    <FontAwesomeIcon icon={this.openContexts ? "caret-down" : "caret-right"} size="lg" color="white" />
                </div>
            </div>
            {this.openContexts ? <div className="propertiesView-contexts-content"  >{this.contexts}</div> : null}
        </div>;
    }

    @computed get layoutSubMenu() {
        return <div className="propertiesView-layout">
            <div className="propertiesView-layout-title"
                onPointerDown={action(() => this.openLayout = !this.openLayout)}
                style={{ backgroundColor: this.openLayout ? "black" : "" }}>
                Layout
                        <div className="propertiesView-layout-title-icon">
                    <FontAwesomeIcon icon={this.openLayout ? "caret-down" : "caret-right"} size="lg" color="white" />
                </div>
            </div>
            {this.openLayout ? <div className="propertiesView-layout-content"  >{this.layoutPreview}</div> : null}
        </div>;
    }



    /**
     * Handles adding and removing members from the sharing panel
     */
    // handleUserChange = (selectedUser: string, add: boolean) => {
    //     if (!Doc.UserDoc().sidebarUsersDisplayed) Doc.UserDoc().sidebarUsersDisplayed = new Doc;
    //     DocCastAsync(Doc.UserDoc().sidebarUsersDisplayed).then(sidebarUsersDisplayed => {
    //         sidebarUsersDisplayed![`display-${selectedUser}`] = add;
    //         !add && runInAction(() => this.selectedUser = "");
    //     });
    // }

    render() {
        if (!this.selectedDoc && !this.isPres) {
            return <div className="propertiesView" style={{ width: this.props.width }}>
                <div className="propertiesView-title" style={{ width: this.props.width }}>
                    No Document Selected
                </div>
            </div>;

        } else {
            if (this.selectedDoc && !this.isPres) {
                return <div className="propertiesView" style={{
                    width: this.props.width,
                    minWidth: this.props.width,
                    //overflowY: this.scrolling ? "scroll" : "visible"
                }} >
                    <div className="propertiesView-title" style={{ width: this.props.width }}>
                        Properties
                    </div>
                    <div className="propertiesView-name">
                        {this.editableTitle}
                    </div>
                    {this.optionsSubMenu}

                    {this.sharingSubMenu}

                    {this.filtersSubMenu}

                    {this.inkSubMenu}

                    {this.fieldsSubMenu}

                    {this.contextsSubMenu}

                    {this.layoutSubMenu}
                </div>;
            }
            if (this.isPres) {
                const selectedItem: boolean = PresBox.Instance?._selectedArray.size > 0;
                const type = PresBox.Instance.activeItem?.type;
                const viewType = PresBox.Instance.activeItem?._viewType;
                const pannable: boolean = (type === DocumentType.COL && viewType === CollectionViewType.Freeform) || type === DocumentType.IMG;
                const scrollable: boolean = type === DocumentType.PDF || type === DocumentType.WEB || type === DocumentType.RTF || viewType === CollectionViewType.Stacking;
                return <div className="propertiesView" style={{ width: this.props.width }}>
                    <div className="propertiesView-title" style={{ width: this.props.width }}>
                        Presentation
                    </div>
                    <div className="propertiesView-name" style={{ borderBottom: 0 }}>
                        {this.editableTitle}
                        <div className="propertiesView-presSelected">
                            <div className="propertiesView-selectedCount">
                                {PresBox.Instance?._selectedArray.size} selected
                            </div>
                            <div className="propertiesView-selectedList">
                                {PresBox.Instance?.listOfSelected}
                            </div>
                        </div>
                    </div>
                    {!selectedItem ? (null) : <div className="propertiesView-presTrails">
                        <div className="propertiesView-presTrails-title"
                            onPointerDown={action(() => { this.openPresTransitions = !this.openPresTransitions; })}
                            style={{ backgroundColor: this.openPresTransitions ? "black" : "" }}>
                            &nbsp; <FontAwesomeIcon style={{ alignSelf: "center" }} icon={"rocket"} /> &nbsp; Transitions
                        <div className="propertiesView-presTrails-title-icon">
                                <FontAwesomeIcon icon={this.openPresTransitions ? "caret-down" : "caret-right"} size="lg" color="white" />
                            </div>
                        </div>
                        {this.openPresTransitions ? <div className="propertiesView-presTrails-content">
                            {PresBox.Instance.transitionDropdown}
                        </div> : null}
                    </div>}
                    {/* {!selectedItem || type === DocumentType.VID || type === DocumentType.AUDIO ? (null) : <div className="propertiesView-presTrails">
                        <div className="propertiesView-presTrails-title"
                            onPointerDown={action(() => this.openPresProgressivize = !this.openPresProgressivize)}
                            style={{ backgroundColor: this.openPresProgressivize ? "black" : "" }}>
                            &nbsp; <FontAwesomeIcon style={{ alignSelf: "center" }} icon={"tasks"} /> &nbsp; Progressivize
                        <div className="propertiesView-presTrails-title-icon">
                                <FontAwesomeIcon icon={this.openPresProgressivize ? "caret-down" : "caret-right"} size="lg" color="white" />
                            </div>
                        </div>
                        {this.openPresProgressivize ? <div className="propertiesView-presTrails-content">
                            {PresBox.Instance.progressivizeDropdown}
                        </div> : null}
                    </div>} */}
                    {!selectedItem || (type !== DocumentType.VID && type !== DocumentType.AUDIO) ? (null) : <div className="propertiesView-presTrails">
                        <div className="propertiesView-presTrails-title"
                            onPointerDown={action(() => { this.openSlideOptions = !this.openSlideOptions; })}
                            style={{ backgroundColor: this.openSlideOptions ? "black" : "" }}>
                            &nbsp; <FontAwesomeIcon style={{ alignSelf: "center" }} icon={type === DocumentType.AUDIO ? "file-audio" : "file-video"} /> &nbsp; {type === DocumentType.AUDIO ? "Audio Options" : "Video Options"}
                            <div className="propertiesView-presTrails-title-icon">
                                <FontAwesomeIcon icon={this.openSlideOptions ? "caret-down" : "caret-right"} size="lg" color="white" />
                            </div>
                        </div>
                        {this.openSlideOptions ? <div className="propertiesView-presTrails-content">
                            {PresBox.Instance.mediaOptionsDropdown}
                        </div> : null}
                    </div>}
                    {/* <div className="propertiesView-presTrails">
                        <div className="propertiesView-presTrails-title"
                            onPointerDown={action(() => { this.openAddSlide = !this.openAddSlide; })}
                            style={{ backgroundColor: this.openAddSlide ? "black" : "" }}>
                            &nbsp; <FontAwesomeIcon icon={"plus"} /> &nbsp; Add new slide
                        <div className="propertiesView-presTrails-title-icon">
                                <FontAwesomeIcon icon={this.openAddSlide ? "caret-down" : "caret-right"} size="lg" color="white" />
                            </div>
                        </div>
                        {this.openAddSlide ? <div className="propertiesView-presTrails-content">
                            {PresBox.Instance.newDocumentDropdown}
                        </div> : null}
                    </div> */}
                </div>;
            }
        }
    }
}