diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/SidebarAnnos.tsx | 72 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 1 | ||||
-rw-r--r-- | src/client/views/nodes/formattedText/FormattedTextBox.tsx | 5 |
3 files changed, 52 insertions, 26 deletions
diff --git a/src/client/views/SidebarAnnos.tsx b/src/client/views/SidebarAnnos.tsx index 869caabd1..78480da03 100644 --- a/src/client/views/SidebarAnnos.tsx +++ b/src/client/views/SidebarAnnos.tsx @@ -1,6 +1,6 @@ import { computed } from 'mobx'; import { observer } from 'mobx-react'; -import { Doc, DocListCast, StrListCast } from '../../fields/Doc'; +import { Doc, DocListCast, Field, FieldResult, StrListCast } from '../../fields/Doc'; import { Id } from '../../fields/FieldSymbols'; import { List } from '../../fields/List'; import { DocCast, NumCast, StrCast } from '../../fields/Types'; @@ -39,12 +39,13 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> { } _stackRef = React.createRef<CollectionStackingView>(); @computed get allMetadata() { - const keys = new Set<string>(); - DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc => SearchBox.documentKeys(doc).forEach(key => keys.add(key))); - return Array.from(keys.keys()) - .filter(key => key[0]) - .filter(key => key[0] !== '_' && key[0] === key[0].toUpperCase()) - .sort(); + const keys = new Map<string, FieldResult<Field>>(); + DocListCast(this.props.rootDoc[this.sidebarKey]).forEach(doc => + SearchBox.documentKeys(doc) + .filter(key => key[0] && key[0] !== '_' && key[0] === key[0].toUpperCase()) + .map(key => keys.set(key, doc[key])) + ); + return keys; } @computed get allUsers() { const keys = new Set<string>(); @@ -72,26 +73,47 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> { }); FormattedTextBox.SelectOnLoad = target[Id]; FormattedTextBox.DontSelectInitialText = true; - this.allMetadata.map(tag => (target[tag] = tag)); DocUtils.MakeLink({ doc: anchor }, { doc: target }, 'inline comment:comment on'); + const taggedContent = this.docFilters() + .filter(data => data.split(':')[0]) + .map(data => { + const key = data.split(':')[0]; + const val = Field.Copy(this.allMetadata.get(key)); + Doc.GetProto(target)[key] = val; + return { + type: 'dashField', + attrs: { fieldKey: key, docid: '', hideKey: false, editable: true }, + marks: [ + { type: 'pFontSize', attrs: { fontSize: '12px' } }, + { type: 'pFontFamily', attrs: { family: 'Arial' } }, + { type: 'pFontColor', attrs: { color: 'black' } }, + { type: 'strong' }, + { type: 'user_mark', attrs: { userid: Doc.CurrentUserEmail, modified: 0 } }, + ], + }; + }); + const textLines = [ + { + type: 'paragraph', + attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, + content: [{ type: 'dashField', attrs: { fieldKey: 'text', docid: anchor[Id], hideKey: true, editable: false } }], + }, + { type: 'paragraph', attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null } }, + ]; + const metadatatext = { + type: 'paragraph', + attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, + content: taggedContent, + }; + if (taggedContent.length) textLines.push(metadatatext); Doc.GetProto(target).text = new RichTextField( JSON.stringify({ doc: { type: 'doc', - content: [ - { - type: 'paragraph', - attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, - content: [{ type: 'dashField', attrs: { fieldKey: 'text', docid: anchor[Id], hideKey: true, editable: false } }], - }, - { - type: 'paragraph', - attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, - }, - ], + content: textLines, }, - selection: { type: 'text', anchor: 4, head: 4 }, + selection: { type: 'text', anchor: 4, head: 4 }, // set selection to middle paragraph }), '' ); @@ -148,10 +170,10 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> { </div> ); }; - const renderMeta = (tag: string) => { - const active = StrListCast(this.props.rootDoc[this.filtersKey]).includes(`${tag}:${tag}:exists`); + const renderMeta = (tag: string, dflt: FieldResult<Field>) => { + const active = StrListCast(this.props.rootDoc[this.filtersKey]).includes(`${tag}:${dflt}:exists`); return ( - <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, tag, tag, 'exists', true, this.sidebarKey, e.shiftKey)}> + <div key={tag} className={`sidebarAnnos-filterTag${active ? '-active' : ''}`} onClick={e => Doc.setDocFilter(this.props.rootDoc, tag, dflt, 'exists', true, this.sidebarKey, e.shiftKey)}> {tag} </div> ); @@ -178,7 +200,9 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> { }}> <div className="sidebarAnnos-tagList" style={{ height: this.filtersHeight() }} onWheel={e => e.stopPropagation()}> {this.allUsers.map(renderUsers)} - {this.allMetadata.map(renderMeta)} + {Array.from(this.allMetadata.keys()) + .sort() + .map(key => renderMeta(key, this.allMetadata.get(key)))} </div> <div style={{ width: '100%', height: `calc(100% - 38px)`, position: 'relative' }}> <CollectionStackingView diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 595fc3bca..a35400e72 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -619,6 +619,7 @@ export class DocumentViewInternal extends DocComponent<DocumentViewInternalProps }, 350); } else clickFunc(); } else if (this.allLinks && this.Document.type !== DocumentType.LINK && !isScriptBox() && this.Document.isLinkButton && !e.shiftKey && !e.ctrlKey) { + SelectionManager.DeselectAll(); this.allLinks.length && LinkFollower.FollowLink(undefined, this.props.Document, this.props, e.altKey); } else { if ((this.layoutDoc.onDragStart || this.props.Document.rootDocument) && !(e.ctrlKey || e.button > 0)) { diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx index 0e48dd93a..ee97e5e62 100644 --- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx +++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx @@ -1398,9 +1398,10 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FieldViewProps } else if (this._editorView) { this._editorView.dispatch(this._editorView.state.tr.addStoredMark(schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: Math.floor(Date.now() / 1000) }))); } - FormattedTextBox.DontSelectInitialText = false; } - selectOnLoad && this._editorView!.focus(); + if (FormattedTextBox.DontSelectInitialText) setTimeout(() => selectOnLoad && this._editorView!.focus(), 0); + else selectOnLoad && this._editorView!.focus(); + FormattedTextBox.DontSelectInitialText = false; // add user mark for any first character that was typed since the user mark that gets set in KeyPress won't have been called yet. if (this._editorView) { this._editorView.state.storedMarks = [ |