aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/Main.tsx
blob: 43b9a6b39eefcc8bded81af5507d6557b617ae2a (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
/* eslint-disable no-new */
// if ((module as any).hot) {
//     (module as any).hot.accept();
// }

import * as dotenv from 'dotenv'; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import { AssignAllExtensions } from '../../extensions/Extensions';
import { FieldLoader } from '../../fields/FieldLoader';
import { BranchingTrailManager } from '../util/BranchingTrailManager';
import { CurrentUserUtils } from '../util/CurrentUserUtils';
import { LinkFollower } from '../util/LinkFollower';
import { PingManager } from '../util/PingManager';
import { ReplayMovements } from '../util/ReplayMovements';
import { TrackMovements } from '../util/TrackMovements';
import { KeyManager } from './GlobalKeyHandler';
import { InkingStroke } from './InkingStroke';
import { MainView } from './MainView';
import { CollectionCalendarView } from './collections/CollectionCalendarView';
import { CollectionDockingView } from './collections/CollectionDockingView';
import { CollectionView } from './collections/CollectionView';
import { TabDocView } from './collections/TabDocView';
import { CollectionFreeFormView } from './collections/collectionFreeForm';
import { CollectionFreeFormInfoUI } from './collections/collectionFreeForm/CollectionFreeFormInfoUI';
import { CollectionSchemaView } from './collections/collectionSchema/CollectionSchemaView';
import { SchemaRowBox } from './collections/collectionSchema/SchemaRowBox';
import './global/globalScripts';
import { AudioBox } from './nodes/AudioBox';
import { ChatBox } from './nodes/ChatBox/ChatBox';
import { ComparisonBox } from './nodes/ComparisonBox';
import { DataVizBox } from './nodes/DataVizBox/DataVizBox';
import { DiagramBox } from './nodes/DiagramBox';
import { DocumentContentsView, HTMLtag } from './nodes/DocumentContentsView';
import { EquationBox } from './nodes/EquationBox';
import { FieldView } from './nodes/FieldView';
import { FontIconBox } from './nodes/FontIconBox/FontIconBox';
import { FunctionPlotBox } from './nodes/FunctionPlotBox';
import { ImageBox } from './nodes/ImageBox';
import { KeyValueBox } from './nodes/KeyValueBox';
import { LabelBox } from './nodes/LabelBox';
import { LinkBox } from './nodes/LinkBox';
import { LoadingBox } from './nodes/LoadingBox';
import { MapBox } from './nodes/MapBox/MapBox';
import { MapPushpinBox } from './nodes/MapBox/MapPushpinBox';
import { PDFBox } from './nodes/PDFBox';
import { PhysicsSimulationBox } from './nodes/PhysicsBox/PhysicsSimulationBox';
import { RecordingBox } from './nodes/RecordingBox';
import { ScreenshotBox } from './nodes/ScreenshotBox';
import { ScriptingBox } from './nodes/ScriptingBox';
import { VideoBox } from './nodes/VideoBox';
import { WebBox } from './nodes/WebBox';
import { DashDocCommentView } from './nodes/formattedText/DashDocCommentView';
import { DashDocView } from './nodes/formattedText/DashDocView';
import { DashFieldView } from './nodes/formattedText/DashFieldView';
import { EquationView } from './nodes/formattedText/EquationView';
import { FootnoteView } from './nodes/formattedText/FootnoteView';
import { FormattedTextBox } from './nodes/formattedText/FormattedTextBox';
import { SummaryView } from './nodes/formattedText/SummaryView';
import { ImportElementBox } from './nodes/importBox/ImportElementBox';
import { PresBox, PresElementBox } from './nodes/trails';
import { SearchBox } from './search/SearchBox';

dotenv.config();

AssignAllExtensions();
FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0, message: 'cache' }; // bcz: not sure why this is needed to get the code loaded properly...

(async () => {
    MainView.Live = window.location.search.includes('live');
    const rootEle = document.getElementById('root');
    if (!rootEle) return;
    rootEle.style.zIndex = '0';
    const root = ReactDOM.createRoot(rootEle);
    root.render(<FieldLoader />);
    window.location.search.includes('safe') && CollectionView.SetSafeMode(true);
    const info = await CurrentUserUtils.loadCurrentUser();
    if (!info.userDocumentId) {
        alert('Fatal Error: user not found in database');
        return;
    }
    await CurrentUserUtils.loadUserDocument(info);
    setTimeout(() => {
        // prevent zooming browser
        document.getElementById('root')!.addEventListener('wheel', event => event.ctrlKey && event.preventDefault(), true);
        const startload = (document as any).startLoad;
        const loading = Date.now() - (startload ? Number(startload) : Date.now() - 3000);
        console.log('Loading Time = ' + loading);
        const d = new Date();
        d.setTime(d.getTime() + 100 * 24 * 60 * 60 * 1000);
        const expires = 'expires=' + d.toUTCString();
        document.cookie = `loadtime=${loading};${expires};path=/`;
        new TrackMovements();
        new ReplayMovements();
        new BranchingTrailManager({});
        new PingManager();
        new KeyManager();

        // initialize plugins and classes that require plugins
        CollectionDockingView.Init(TabDocView);
        FormattedTextBox.Init((tbox: FormattedTextBox) => ({
            dashComment(node: any, view: any, getPos: any) { return new DashDocCommentView(node, view, getPos); }, // prettier-ignore
            dashDoc(node: any, view: any, getPos: any)     { return new DashDocView(node, view, getPos, tbox); }, // prettier-ignore
            dashField(node: any, view: any, getPos: any)   { return new DashFieldView(node, view, getPos, tbox); }, // prettier-ignore
            equation(node: any, view: any, getPos: any)    { return new EquationView(node, view, getPos, tbox); }, // prettier-ignore
            summary(node: any, view: any, getPos: any)     { return new SummaryView(node, view, getPos); }, // prettier-ignore
            footnote(node: any, view: any, getPos: any)    { return new FootnoteView(node, view, getPos); }, // prettier-ignore
        }));
        CollectionFreeFormInfoUI.Init();
        LinkFollower.Init();
        KeyValueBox.Init();
        PresBox.Init(TabDocView.AllTabDocs);
        DocumentContentsView.Init(KeyValueBox.LayoutString(), {
            FormattedTextBox,
            ImageBox,
            FontIconBox,
            LabelBox,
            EquationBox,
            FieldView,
            CollectionFreeFormView,
            CollectionDockingView,
            CollectionSchemaView,
            CollectionCalendarView,
            CollectionView,
            WebBox,
            KeyValueBox,
            PDFBox,
            VideoBox,
            AudioBox,
            RecordingBox,
            PresBox,
            PresElementBox,
            SearchBox,
            FunctionPlotBox,
            InkingStroke,
            LinkBox,
            ScriptingBox,
            MapBox,
            ScreenshotBox,
            DataVizBox,
            ChatBox,
            DiagramBox,
            HTMLtag,
            ComparisonBox,
            LoadingBox,
            PhysicsSimulationBox,
            SchemaRowBox,
            ImportElementBox,
            MapPushpinBox,
        });
        root.render(<MainView />);
    }, 0);
})();