aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DocumentContentsView.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/DocumentContentsView.tsx')
-rw-r--r--src/client/views/nodes/DocumentContentsView.tsx96
1 files changed, 14 insertions, 82 deletions
diff --git a/src/client/views/nodes/DocumentContentsView.tsx b/src/client/views/nodes/DocumentContentsView.tsx
index ec9db8480..18529a429 100644
--- a/src/client/views/nodes/DocumentContentsView.tsx
+++ b/src/client/views/nodes/DocumentContentsView.tsx
@@ -2,7 +2,6 @@
import { computed, makeObservable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
-import JsxParser from 'react-jsx-parser';
import * as XRegExp from 'xregexp';
import { OmitKeys } from '../../../ClientUtils';
import { Without, emptyPath } from '../../../Utils';
@@ -11,56 +10,15 @@ import { AclPrivate, DocData } from '../../../fields/DocSymbols';
import { ScriptField } from '../../../fields/ScriptField';
import { Cast, DocCast, StrCast } from '../../../fields/Types';
import { GetEffectiveAcl, TraceMobx } from '../../../fields/util';
-import { InkingStroke } from '../InkingStroke';
-import { ObservableReactComponent } from '../ObservableReactComponent';
-import { CollectionCalendarView } from '../collections/CollectionCalendarView';
-import { CollectionDockingView } from '../collections/CollectionDockingView';
-import { CollectionView } from '../collections/CollectionView';
-import { CollectionFreeFormView } from '../collections/collectionFreeForm/CollectionFreeFormView';
-import { CollectionSchemaView } from '../collections/collectionSchema/CollectionSchemaView';
-import { SchemaRowBox } from '../collections/collectionSchema/SchemaRowBox';
-import { SearchBox } from '../search/SearchBox';
-import { AudioBox } from './AudioBox';
-import { ComparisonBox } from './ComparisonBox';
-import { DataVizBox } from './DataVizBox/DataVizBox';
+import { ObservableReactComponent, ObserverJsxParser } from '../ObservableReactComponent';
import './DocumentView.scss';
-import { EquationBox } from './EquationBox';
-import { FieldView, FieldViewProps } from './FieldView';
-import { FontIconBox } from './FontIconBox/FontIconBox';
-import { FunctionPlotBox } from './FunctionPlotBox';
-import { ImageBox } from './ImageBox';
-import { KeyValueBox } from './KeyValueBox';
-import { LabelBox } from './LabelBox';
-import { LinkBox } from './LinkBox';
-import { LoadingBox } from './LoadingBox';
-import { MapBox } from './MapBox/MapBox';
-import { MapPushpinBox } from './MapBox/MapPushpinBox';
-import { PDFBox } from './PDFBox';
-import { PhysicsSimulationBox } from './PhysicsBox/PhysicsSimulationBox';
-import { RecordingBox } from './RecordingBox';
-import { ScreenshotBox } from './ScreenshotBox';
-import { ScriptingBox } from './ScriptingBox';
-import { VideoBox } from './VideoBox';
-import { WebBox } from './WebBox';
-import { FormattedTextBox } from './formattedText/FormattedTextBox';
-import { ImportElementBox } from './importBox/ImportElementBox';
-import { PresBox } from './trails/PresBox';
-import { PresElementBox } from './trails/PresElementBox';
+import { FieldViewProps } from './FieldView';
type BindingProps = Without<FieldViewProps, 'fieldKey'>;
export interface JsxBindings {
props: BindingProps;
}
-class ObserverJsxParser1 extends JsxParser {
- constructor(props: any) {
- super(props);
- observer(this as any);
- }
-}
-
-export const ObserverJsxParser: typeof JsxParser = ObserverJsxParser1 as any;
-
interface HTMLtagProps {
Document: Doc;
htmltag: string;
@@ -116,6 +74,15 @@ export interface DocumentContentsViewProps extends FieldViewProps {
}
@observer
export class DocumentContentsView extends ObservableReactComponent<DocumentContentsViewProps> {
+ private static DefaultLayoutString: string;
+ /**
+ * Set of all available rendering componets for Docs (e.g., ImageBox, CollectionFreeFormView, etc)
+ */
+ private static Components: { [key: string]: any };
+ public static Init(defaultLayoutString: string, components:{ [key: string]: any}) {
+ DocumentContentsView.DefaultLayoutString = defaultLayoutString;
+ DocumentContentsView.Components = components;
+ }
constructor(props: any) {
super(props);
makeObservable(this);
@@ -124,11 +91,11 @@ export class DocumentContentsView extends ObservableReactComponent<DocumentConte
TraceMobx();
if (this._props.LayoutTemplateString) return this._props.LayoutTemplateString;
if (!this.layoutDoc) return '<p>awaiting layout</p>';
- if (this._props.layoutFieldKey === 'layout_keyValue') return StrCast(this._props.Document.layout_keyValue, KeyValueBox.LayoutString());
+ if (this._props.layoutFieldKey === 'layout_keyValue') return StrCast(this._props.Document.layout_keyValue, DocumentContentsView.DefaultLayoutString);
const tempLayout = DocCast(this.layoutDoc[this.layoutDoc === this._props.Document && this._props.layoutFieldKey ? this._props.layoutFieldKey : StrCast(this.layoutDoc.layout_fieldKey, 'layout')]);
const layoutDoc = tempLayout ?? this.layoutDoc;
const layout = Cast(layoutDoc[layoutDoc === this._props.Document && this._props.layoutFieldKey ? this._props.layoutFieldKey : StrCast(layoutDoc.layout_fieldKey, 'layout')], 'string');
- if (layout === undefined) return this._props.Document.data ? "<FieldView {...props} fieldKey='data' />" : KeyValueBox.LayoutString();
+ if (layout === undefined) return this._props.Document.data ? "<FieldView {...props} fieldKey='data' />" : DocumentContentsView.DefaultLayoutString;
if (typeof layout === 'string') return layout;
return '<p>Loading layout</p>';
}
@@ -223,42 +190,7 @@ export class DocumentContentsView extends ObservableReactComponent<DocumentConte
key={42}
blacklistedAttrs={emptyPath}
renderInWrapper={false}
- components={{
- 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,
- HTMLtag,
- ComparisonBox,
- LoadingBox,
- PhysicsSimulationBox,
- SchemaRowBox,
- ImportElementBox,
- MapPushpinBox,
- }}
+ components={DocumentContentsView.Components}
bindings={bindings}
jsx={layoutFrame}
showWarnings