aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/SidebarAnnos.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-12-21 14:55:48 -0500
committerbobzel <zzzman@gmail.com>2023-12-21 14:55:48 -0500
commit1caba64ee0f32ee8af79263cd4ef2a8bc5d5146e (patch)
tree0fa0e957d1f342fdc6ed4a4b43f5dddfddb1298a /src/client/views/SidebarAnnos.tsx
parent02eb7da95df283606d4275a22d9451cef371c3b5 (diff)
parent2691b951d96f2ce7652acbea9e340b61737b3b57 (diff)
Merge branch 'moreUpgrading' into dataViz-annotations
Diffstat (limited to 'src/client/views/SidebarAnnos.tsx')
-rw-r--r--src/client/views/SidebarAnnos.tsx88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/client/views/SidebarAnnos.tsx b/src/client/views/SidebarAnnos.tsx
index 1e1b8e0e6..0f4a4260c 100644
--- a/src/client/views/SidebarAnnos.tsx
+++ b/src/client/views/SidebarAnnos.tsx
@@ -1,27 +1,28 @@
-import { computed } from 'mobx';
+import { computed, makeObservable } from 'mobx';
import { observer } from 'mobx-react';
+import * as React from 'react';
+import { emptyFunction, returnAll, returnFalse, returnOne, returnZero } from '../../Utils';
import { Doc, DocListCast, Field, FieldResult, StrListCast } from '../../fields/Doc';
import { Id } from '../../fields/FieldSymbols';
import { List } from '../../fields/List';
import { RichTextField } from '../../fields/RichTextField';
import { DocCast, NumCast, StrCast } from '../../fields/Types';
-import { emptyFunction, returnAll, returnFalse, returnOne, returnTrue, returnZero } from '../../Utils';
-import { Docs, DocUtils } from '../documents/Documents';
import { CollectionViewType, DocumentType } from '../documents/DocumentTypes';
+import { DocUtils, Docs } from '../documents/Documents';
import { LinkManager } from '../util/LinkManager';
import { SearchUtil } from '../util/SearchUtil';
import { Transform } from '../util/Transform';
+import { ObservableReactComponent } from './ObservableReactComponent';
+import './SidebarAnnos.scss';
+import { StyleProp } from './StyleProvider';
import { CollectionStackingView } from './collections/CollectionStackingView';
import { FieldViewProps } from './nodes/FieldView';
import { FormattedTextBox } from './nodes/formattedText/FormattedTextBox';
-import './SidebarAnnos.scss';
-import { StyleProp } from './StyleProvider';
-import React = require('react');
interface ExtraProps {
fieldKey: string;
+ Document: Doc;
layoutDoc: Doc;
- rootDoc: Doc;
dataDoc: Doc;
// usePanelWidth: boolean;
showSidebar: boolean;
@@ -34,15 +35,16 @@ interface ExtraProps {
moveDocument: (doc: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (doc: Doc | Doc[]) => boolean, annotationKey?: string) => boolean;
}
@observer
-export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
- constructor(props: Readonly<FieldViewProps & ExtraProps>) {
+export class SidebarAnnos extends ObservableReactComponent<FieldViewProps & ExtraProps> {
+ constructor(props: any) {
super(props);
- // this.props.dataDoc[this.sidebarKey] = new List<Doc>(); // bcz: can't do this here. it blows away existing things and isn't a robust solution for making sure the field exists -- instead this should happen when the document is created and/or shared
+ makeObservable(this);
}
+
_stackRef = React.createRef<CollectionStackingView>();
@computed get allMetadata() {
const keys = new Map<string, FieldResult<Field>>();
- DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc =>
+ DocListCast(this._props.Document[this.sidebarKey]).forEach(doc =>
SearchUtil.documentKeys(doc)
.filter(key => key[0] && key[0] !== '_' && key[0] === key[0].toUpperCase())
.map(key => keys.set(key, doc[key]))
@@ -51,7 +53,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
}
@computed get allHashtags() {
const keys = new Set<string>();
- DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc => StrListCast(doc.tags).forEach(tag => keys.add(tag)));
+ DocListCast(this._props.Document[this.sidebarKey]).forEach(doc => StrListCast(doc.tags).forEach(tag => keys.add(tag)));
return Array.from(keys.keys())
.filter(key => key[0])
.filter(key => !key.startsWith('_') && (key[0] === '#' || key[0] === key[0].toUpperCase()))
@@ -59,7 +61,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
}
@computed get allUsers() {
const keys = new Set<string>();
- DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc => keys.add(StrCast(doc.author)));
+ DocListCast(this._props.Document[this.sidebarKey]).forEach(doc => keys.add(StrCast(doc.author)));
return Array.from(keys.keys()).sort();
}
@@ -69,7 +71,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
.join(' ');
const target = Docs.Create.TextDocument(startup, {
title: '-note-',
- annotationOn: this.props.rootDoc,
+ annotationOn: this._props.Document,
_width: 200,
_height: 50,
_layout_fitWidth: true,
@@ -77,7 +79,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
_text_fontSize: StrCast(Doc.UserDoc().fontSize),
_text_fontFamily: StrCast(Doc.UserDoc().fontFamily),
});
- FormattedTextBox.SelectOnLoad = target[Id];
+ FormattedTextBox.SetSelectOnLoad(target);
FormattedTextBox.DontSelectInitialText = true;
const link = DocUtils.MakeLink(anchor, target, { link_relationship: 'inline comment:comment on' });
link && (link.link_displayLine = false);
@@ -147,10 +149,10 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
return target;
};
makeDocUnfiltered = (doc: Doc) => {
- if (DocListCast(this.props.rootDoc[this.sidebarKey]).find(anno => Doc.AreProtosEqual(doc.layout_unrendered ? DocCast(doc.annotationOn) : doc, anno))) {
+ if (DocListCast(this._props.Document[this.sidebarKey]).find(anno => Doc.AreProtosEqual(doc.layout_unrendered ? DocCast(doc.annotationOn) : doc, anno))) {
if (this.childFilters()) {
// if any child filters exist, get rid of them
- this.props.layoutDoc._childFilters = new List<string>();
+ this._props.layoutDoc._childFilters = new List<string>();
}
return true;
}
@@ -158,27 +160,27 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
};
get sidebarKey() {
- return this.props.fieldKey + '_sidebar';
+ return this._props.fieldKey + '_sidebar';
}
filtersHeight = () => 38;
screenToLocalTransform = () =>
- this.props
+ this._props
.ScreenToLocalTransform()
- .translate(Doc.NativeWidth(this.props.dataDoc), 0)
- .scale(this.props.NativeDimScaling?.() || 1);
+ .translate(Doc.NativeWidth(this._props.dataDoc), 0)
+ .scale(this._props.NativeDimScaling?.() || 1);
panelWidth = () =>
- !this.props.showSidebar
+ !this._props.showSidebar
? 0
- : this.props.usePanelWidth // [DocumentType.RTF, DocumentType.MAP].includes(this.props.layoutDoc.type as any)
- ? this.props.PanelWidth() / (this.props.NativeDimScaling?.() || 1)
- : ((NumCast(this.props.nativeWidth) - Doc.NativeWidth(this.props.dataDoc)) * this.props.PanelWidth()) / NumCast(this.props.nativeWidth);
- panelHeight = () => this.props.PanelHeight() - this.filtersHeight();
- addDocument = (doc: Doc | Doc[]) => this.props.sidebarAddDocument(doc, this.sidebarKey);
- moveDocument = (doc: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (doc: Doc | Doc[]) => boolean) => this.props.moveDocument(doc, targetCollection, addDocument, this.sidebarKey);
- removeDocument = (doc: Doc | Doc[]) => this.props.removeDocument(doc, this.sidebarKey);
- childFilters = () => StrListCast(this.props.layoutDoc._childFilters);
+ : this._props.usePanelWidth // [DocumentType.RTF, DocumentType.MAP].includes(this._props.layoutDoc.type as any)
+ ? this._props.PanelWidth() / (this._props.NativeDimScaling?.() || 1)
+ : ((NumCast(this._props.nativeWidth) - Doc.NativeWidth(this._props.dataDoc)) * this._props.PanelWidth()) / NumCast(this._props.nativeWidth);
+ panelHeight = () => this._props.PanelHeight() - this.filtersHeight();
+ addDocument = (doc: Doc | Doc[]) => this._props.sidebarAddDocument(doc, this.sidebarKey);
+ moveDocument = (doc: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (doc: Doc | Doc[]) => boolean) => this._props.moveDocument(doc, targetCollection, addDocument, this.sidebarKey);
+ removeDocument = (doc: Doc | Doc[]) => this._props.removeDocument(doc, this.sidebarKey);
+ childFilters = () => StrListCast(this._props.layoutDoc._childFilters);
layout_showTitle = () => 'title';
- setHeightCallback = (height: number) => this.props.setHeight?.(height + this.filtersHeight());
+ setHeightCallback = (height: number) => this._props.setHeight?.(height + this.filtersHeight());
sortByLinkAnchorY = (a: Doc, b: Doc) => {
const ay = LinkManager.Links(a).length && DocCast(LinkManager.Links(a)[0].link_anchor_1).y;
const by = LinkManager.Links(b).length && DocCast(LinkManager.Links(b)[0].link_anchor_1).y;
@@ -188,7 +190,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
const renderTag = (tag: string) => {
const active = this.childFilters().includes(`tags${Doc.FilterSep}${tag}${Doc.FilterSep}check`);
return (
- <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, 'tags', tag, 'check', true, undefined, e.shiftKey)}>
+ <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this._props.Document, 'tags', tag, 'check', true, undefined, e.shiftKey)}>
{tag}
</div>
);
@@ -196,7 +198,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
const renderMeta = (tag: string, dflt: FieldResult<Field>) => {
const active = this.childFilters().includes(`${tag}${Doc.FilterSep}${Doc.FilterAny}${Doc.FilterSep}exists`);
return (
- <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, tag, Doc.FilterAny, 'exists', true, undefined, e.shiftKey)}>
+ <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this._props.Document, tag, Doc.FilterAny, 'exists', true, undefined, e.shiftKey)}>
{tag}
</div>
);
@@ -204,20 +206,20 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
const renderUsers = (user: string) => {
const active = this.childFilters().includes(`author:${user}:check`);
return (
- <div key={user} className={`sidebarAnnos-filterUser${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, 'author', user, 'check', true, undefined, e.shiftKey)}>
+ <div key={user} className={`sidebarAnnos-filterUser${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this._props.Document, 'author', user, 'check', true, undefined, e.shiftKey)}>
{user}
</div>
);
};
// TODO: Calculation of the topbar is hardcoded and different for text nodes - it should all be the same and all be part of SidebarAnnos
- return !this.props.showSidebar ? null : (
+ return !this._props.showSidebar ? null : (
<div
style={{
position: 'absolute',
- pointerEvents: this.props.isContentActive() ? 'all' : undefined,
- top: this.props.rootDoc.type !== DocumentType.RTF && StrCast(this.props.rootDoc._layout_showTitle) === 'title' ? 15 : 0,
+ pointerEvents: this._props.isContentActive() ? 'all' : undefined,
+ top: this._props.Document.type !== DocumentType.RTF && StrCast(this._props.Document._layout_showTitle) === 'title' ? 15 : 0,
right: 0,
- background: this.props.styleProvider?.(this.props.rootDoc, this.props, StyleProp.WidgetColor),
+ background: this._props.styleProvider?.(this._props.Document, this._props, StyleProp.WidgetColor),
width: `100%`,
height: '100%',
}}>
@@ -231,7 +233,7 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
<div style={{ width: '100%', height: `calc(100% - 38px)`, position: 'relative' }}>
<CollectionStackingView
- {...this.props}
+ {...this._props}
setContentView={emptyFunction}
NativeWidth={returnZero}
NativeHeight={returnZero}
@@ -246,14 +248,14 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
NativeDimScaling={returnOne}
//childlayout_showTitle={this.layout_showTitle}
isAnyChildContentActive={returnFalse}
- childDocumentsActive={this.props.isContentActive}
- whenChildContentsActiveChanged={this.props.whenChildContentsActiveChanged}
- childHideDecorationTitle={returnTrue}
+ childDocumentsActive={this._props.isContentActive}
+ whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
+ childHideDecorationTitle={true}
removeDocument={this.removeDocument}
moveDocument={this.moveDocument}
addDocument={this.addDocument}
ScreenToLocalTransform={this.screenToLocalTransform}
- renderDepth={this.props.renderDepth + 1}
+ renderDepth={this._props.renderDepth + 1}
type_collection={CollectionViewType.Stacking}
fieldKey={this.sidebarKey}
pointerEvents={returnAll}