diff options
| author | bobzel <zzzman@gmail.com> | 2025-03-24 16:29:32 -0400 | 
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2025-03-24 16:29:32 -0400 | 
| commit | 858f5d2f1621695a703b0e3f8297521c3ebe692d (patch) | |
| tree | 3180f91ee18bf8accef98cbbb6db6688666e8340 /src/client/views/nodes/formattedText/DashFieldView.tsx | |
| parent | 9c5d14fdd562dc1bcc8aa0f73ce7ad189c9fbf23 (diff) | |
| parent | b6cf21b5a52184f89909898d292a79c57c043d7e (diff) | |
Merge branch 'fieldSyntaxUpdate' into aarav_edit
Diffstat (limited to 'src/client/views/nodes/formattedText/DashFieldView.tsx')
| -rw-r--r-- | src/client/views/nodes/formattedText/DashFieldView.tsx | 71 | 
1 files changed, 20 insertions, 51 deletions
| diff --git a/src/client/views/nodes/formattedText/DashFieldView.tsx b/src/client/views/nodes/formattedText/DashFieldView.tsx index e899b49bc..bb0efa917 100644 --- a/src/client/views/nodes/formattedText/DashFieldView.tsx +++ b/src/client/views/nodes/formattedText/DashFieldView.tsx @@ -1,8 +1,10 @@  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';  import { Tooltip } from '@mui/material'; -import { action, computed, IReactionDisposer, makeObservable, observable, reaction, runInAction } from 'mobx'; +import { action, computed, IReactionDisposer, makeObservable, observable, reaction } from 'mobx';  import { observer } from 'mobx-react'; +import { Node } from 'prosemirror-model';  import { NodeSelection } from 'prosemirror-state'; +import { EditorView } from 'prosemirror-view';  import * as React from 'react';  import * as ReactDOM from 'react-dom/client';  import { returnFalse, returnTrue, returnZero, setupMoveUpEvents } from '../../../../ClientUtils'; @@ -13,6 +15,7 @@ import { SchemaHeaderField } from '../../../../fields/SchemaHeaderField';  import { Cast, DocCast } from '../../../../fields/Types';  import { emptyFunction } from '../../../../Utils';  import { DocServer } from '../../../DocServer'; +import { DocumentOptions, FInfo } from '../../../documents/Documents';  import { CollectionViewType } from '../../../documents/DocumentTypes';  import { Transform } from '../../../util/Transform';  import { undoable, undoBatch } from '../../../util/UndoManager'; @@ -23,9 +26,6 @@ import { ObservableReactComponent } from '../../ObservableReactComponent';  import { OpenWhere } from '../OpenWhere';  import './DashFieldView.scss';  import { FormattedTextBox } from './FormattedTextBox'; -import { Node } from 'prosemirror-model'; -import { EditorView } from 'prosemirror-view'; -import { DocumentOptions, FInfo } from '../../../documents/Documents';  @observer  export class DashFieldViewMenu extends AntimodeMenu<AntimodeMenuProps> { @@ -99,7 +99,6 @@ interface IDashFieldViewInternal {      width: number;      height: number;      editable: boolean; -    nodeSelected: () => boolean;      node: Node;      getPos: () => number;      unclickable: () => boolean; @@ -112,7 +111,7 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi      _fieldKey: string;      _fieldRef = React.createRef<HTMLDivElement>();      @observable _dashDoc: Doc | undefined = undefined; -    @observable _expanded = this._props.nodeSelected(); +    @observable _expanded = false;      constructor(props: IDashFieldViewInternal) {          super(props); @@ -140,7 +139,7 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi      componentWillUnmount() {          this._reactionDisposer?.();      } -    isRowActive = () => (this._props.nodeSelected() || this._expanded) && this._props.editable; +    isRowActive = () => this._props.tbox._props.isContentActive() && this._props.editable;      finishEdit = action(() => {          if (this._expanded) {              this._expanded = false; @@ -149,7 +148,7 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi              setTimeout(() => !this._props.tbox.ProseRef?.contains(document.activeElement) && this._props.tbox._props.onBlur?.());          }      }); -    selectedCells = () => (this._dashDoc ? [this._dashDoc] : undefined); +    selectedCells = () => (this._dashDoc && this._expanded ? [this._dashDoc] : undefined);      columnWidth = () => Math.min(this._props.tbox._props.PanelWidth(), Math.max(50, this._props.tbox._props.PanelWidth() - 100)); // try to leave room for the fieldKey      finfo = (fieldKey: string) => (new DocumentOptions() as Record<string, FInfo>)[fieldKey]; @@ -158,17 +157,18 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi      @computed get fieldValueContent() {          return !this._dashDoc ? null : (              <div +                className="dashFieldView-fieldSpan"                  onPointerDown={action(() => {                      this._expanded = !this._props.editable ? false : !this._expanded; -                })} -                style={{ fontSize: 'smaller', width: !this._hideKey && this._expanded ? this.columnWidth() : undefined }}> +                })}>                  <SchemaTableCell -                    Document={this._dashDoc} +                    Doc={this._dashDoc}                      col={0}                      deselectCell={emptyFunction} -                    selectCell={emptyFunction} +                    selectCell={() => (this._expanded ? true : undefined)} +                    autoFocus={true}                      maxWidth={this._props.hideKey || this._hideKey ? undefined : this._props.tbox._props.PanelWidth} -                    columnWidth={this._expanded || this._props.nodeSelected() ? () => undefined : returnZero} +                    columnWidth={returnZero}                      selectedCells={this.selectedCells}                      selectedCol={returnZero}                      fieldKey={this._fieldKey} @@ -184,11 +184,10 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi                      getFinfo={this.finfo}                      setColumnValues={returnFalse}                      allowCRs -                    oneLine={!this._expanded && !this._props.nodeSelected()} +                    oneLine={!this._expanded}                      finishEdit={this.finishEdit}                      transform={Transform.Identity}                      menuTarget={null} -                    autoFocus                      rootSelected={this._props.tbox._props.rootSelected}                  />              </div> @@ -233,7 +232,7 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi      }      @computed get _hideValue() { -        return this._props.hideValue && !this._props.nodeSelected(); +        return this._props.hideValue;      }      // clicking on the label creates a pivot view collection of all documents @@ -255,7 +254,6 @@ export class DashFieldViewInternal extends ObservableReactComponent<IDashFieldVi      };      @computed get values() { -        if (this._props.nodeSelected()) return [];          const vals = FilterPanel.gatherFieldValues(DocListCast(Doc.ActiveDashboard?.data), this._fieldKey, []);          return vals.strings.map(facet => ({ value: facet, label: facet })); @@ -297,8 +295,6 @@ export class DashFieldView {      node: Node;      tbox: FormattedTextBox;      getpos: () => number | undefined; -    @observable _nodeSelected = false; -    NodeSelected = () => this._nodeSelected;      unclickable = () => !this.tbox._props.rootSelected?.() && this.node.marks.some(m => m.type === this.tbox.EditorView?.state.schema.marks.linkAnchor && m.attrs.noPreview);      constructor(node: Node, view: EditorView, getPos: () => number | undefined, tbox: FormattedTextBox) { @@ -311,26 +307,13 @@ export class DashFieldView {          this.dom.style.width = node.attrs.width;          this.dom.style.height = node.attrs.height;          this.dom.style.position = 'relative'; -        this.dom.style.display = 'inline-block'; +        this.dom.style.display = 'inline-flex';          this.dom.onkeypress = function (e: KeyboardEvent) {              e.stopPropagation();          }; -        this.dom.onkeydown = (e: KeyboardEvent) => { +        this.dom.onkeydown = action((e: KeyboardEvent) => {              e.stopPropagation(); -            if (e.key === 'Tab') { -                e.preventDefault(); -                const editor = tbox.EditorView; -                if (editor) { -                    const { state } = editor; -                    for (let i = getPosition() + 1; i < state.doc.content.size; i++) { -                        if (state.doc.nodeAt(i)?.type.name === state.schema.nodes.dashField.name) { -                            editor.dispatch(state.tr.setSelection(new NodeSelection(state.doc.resolve(i)))); -                            return; -                        } -                    } -                } -            } -        }; +        });          this.dom.onkeyup = function (e: KeyboardEvent) {              e.stopPropagation();          }; @@ -351,7 +334,6 @@ export class DashFieldView {                  hideKey={node.attrs.hideKey}                  hideValue={node.attrs.hideValue}                  editable={node.attrs.editable} -                nodeSelected={this.NodeSelected}                  tbox={tbox}              />          ); @@ -365,19 +347,6 @@ export class DashFieldView {              }          });      } -    deselectNode() { -        runInAction(() => { -            this._nodeSelected = false; -        }); -        this.dom.classList.remove('ProseMirror-selectednode'); -    } -    selectNode() { -        setTimeout( -            action(() => { -                this._nodeSelected = true; -            }), -            100 -        ); -        this.dom.classList.add('ProseMirror-selectednode'); -    } +    deselectNode() {} +    selectNode() {}  } | 
