From 1f3c2a97592afe36ffe167bafbb4cae515238134 Mon Sep 17 00:00:00 2001 From: ljungster Date: Thu, 17 Mar 2022 10:35:23 -0400 Subject: gutted NoteTaking --- .../views/collections/CollectionNoteTakingView.tsx | 178 ++++++--------------- .../CollectionNoteTakingViewFieldColumn.tsx | 71 +++----- 2 files changed, 69 insertions(+), 180 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionNoteTakingView.tsx b/src/client/views/collections/CollectionNoteTakingView.tsx index 8bccb0c0a..ee1ea67d4 100644 --- a/src/client/views/collections/CollectionNoteTakingView.tsx +++ b/src/client/views/collections/CollectionNoteTakingView.tsx @@ -24,41 +24,46 @@ import { LightboxView } from "../LightboxView"; import { CollectionFreeFormDocumentView } from "../nodes/CollectionFreeFormDocumentView"; import { DocFocusOptions, DocumentView, DocumentViewProps, ViewAdjustment } from "../nodes/DocumentView"; import { StyleProp } from "../StyleProvider"; -import { CollectionMasonryViewFieldRow } from "./CollectionMasonryViewFieldRow"; import "./CollectionStackingView.scss"; import { CollectionStackingViewFieldColumn } from "./CollectionStackingViewFieldColumn"; import { CollectionSubView } from "./CollectionSubView"; import { CollectionViewType } from "./CollectionView"; import internal = require("events"); +import { CollectionNoteTakingViewFieldColumn } from "./CollectionNoteTakingViewFieldColumn"; const _global = (window /* browser */ || global /* node */) as any; type StackingDocument = makeInterface<[typeof collectionSchema, typeof documentSchema]>; const StackingDocument = makeInterface(collectionSchema, documentSchema); -export type collectionStackingViewProps = { +export type collectionNoteTakingViewProps = { chromeHidden?: boolean; - // view type is stacking viewType?: CollectionViewType; NativeWidth?: () => number; NativeHeight?: () => number; + numColumns?: number; }; @observer -export class CollectionNoteTakingView extends CollectionSubView>(StackingDocument) { - // do we need a masonry grid here? We think that they are sharing data - _masonryGridRef: HTMLDivElement | null = null; +export class CollectionNoteTakingView extends CollectionSubView>(StackingDocument) { // used in a column dragger, likely due for the masonry grid view. We want to use this _draggerRef = React.createRef(); - // Not sure what a pivot field is. Seems like we cause reaction in MobX get rid of it once we exit this view - _pivotFieldDisposer?: IReactionDisposer; // Seems like we cause reaction in MobX get rid of our height once we exit this view _autoHeightDisposer?: IReactionDisposer; // keeping track of documents. Updated on internal and external drops. What's the difference? _docXfs: { height: () => number, width: () => number, stackedDocTransform: () => Transform }[] = []; // Doesn't look like this field is being used anywhere. Obsolete? _columnStart: number = 0; - // map of node headers to their heights. Used in Masonry - @observable _heightMap = new Map(); + + //--------------------------------------------------------------------------------------------------------------// + // TODO: these are things that I added but not sure that they actually belong here + // We may not need to actually keep track of the numColumns + _noteTakingRef: HTMLDivElement | null = null; + _numColumns: number = this.props.numColumns ? this.props.numColumns : 1; + @computed get numColumns() { return this._numColumns} + @computed get columnIndex() { return StrCast(this.layoutDoc._columnIndex); } + @computed get columnWidth() { return Number.MAX_VALUE } + //--------------------------------------------------------------------------------------------------------------// + // Assuming that this is the current css cursor style @observable _cursor: CursorProperty = "grab"; // gets reset whenever we scroll. Not sure what it is @@ -67,8 +72,6 @@ export class CollectionNoteTakingView extends CollectionSubView (pair.layout instanceof Doc) && !pair.layout.hidden).map(pair => pair.layout); } // how much margin we give the header @@ -76,18 +79,6 @@ export class CollectionNoteTakingView extends CollectionSubView(); } + } - // TODO: plj - these are the children children = (docs: Doc[]) => { - //TODO: can somebody explain me to what exactly TraceMobX is? TraceMobx(); - // appears that we are going to reset the _docXfs. TODO: what is Xfs? this._docXfs.length = 0; // Go through each of the documents that are contained return docs.map((d, i) => { const height = () => this.getDocHeight(d); const width = () => this.getDocWidth(d); - // assuming we need to get rowSpan because we might be dealing with many columns. Grid gap makes sense if multiple columns - const rowSpan = Math.ceil((height() + this.gridGap) / this.gridGap); // just getting the style - const style = this.isStackingView ? { width: width(), marginTop: i ? this.gridGap : 0, height: height() } : { gridRowEnd: `span ${rowSpan}` }; + const style = { width: width(), marginTop: i ? this.gridGap : 0, height: height() }; // So we're choosing whether we're going to render a column or a masonry doc - return
- {/*
*/} - {/* We'll want to add an onPointerDown that uses DragManager.DocumentDragData - -- we also want to remember to preventDefault (so other drag events are not recognized over this one) - -- Design discussion as to whether we want dragging to be on the document itself or with a drag button - -- Do we want clicking on this button to do anything as well? - -- Design Question: Schema view also has the notion of a drag manager (different from this one), do we want - the same functionality? - -- Problem: This only shows when the outer container is selected... - */} - {/*
- e.stopPropagation()} /> -
-
*/} - {/* some sort of filtering is being done here to actually get layout and make the doc look pretty*/} + return
{this.getDisplayDoc(d, width)}
}); } - @action - setDocHeight = (key: string, sectionHeight: number) => { - this._heightMap.set(key, sectionHeight); - } + + // @action + // setDocHeight = (key: string, sectionHeight: number) => { + // this._heightMap.set(key, sectionHeight); + // } // is sections that all collections inherit? I think this is how we show the masonry/columns //TODO: this seems important get Sections() { - // appears that pivot field IS actually for sorting - if (!this.pivotField || this.columnHeaders instanceof Promise) return new Map(); + // if (!this.pivotField || this.columnHeaders instanceof Promise) return new Map(); if (this.columnHeaders === undefined) { setTimeout(() => this.layoutDoc._columnHeaders = new List(), 0); return new Map(); } + const columnHeaders = Array.from(this.columnHeaders); const fields = new Map(columnHeaders.map(sh => [sh, []] as [SchemaHeaderField, []])); let changed = false; this.filteredChildren.map(d => { - const sectionValue = (d[this.pivotField] ? d[this.pivotField] : `NO ${this.pivotField.toUpperCase()} VALUE`) as object; + // need to set the section value + const sectionValue = d[this.columnIndex] as object; // the next five lines ensures that floating point rounding errors don't create more than one section -syip const parsed = parseInt(sectionValue.toString()); const castedSectionValue = !isNaN(parsed) ? parsed : sectionValue; // look for if header exists already - const existingHeader = columnHeaders.find(sh => sh.heading === (castedSectionValue ? castedSectionValue.toString() : `NO ${this.pivotField.toUpperCase()} VALUE`)); + const existingHeader = columnHeaders.find(sh => sh.heading === castedSectionValue.toString()); if (existingHeader) { fields.get(existingHeader)!.push(d); } else { - const newSchemaHeader = new SchemaHeaderField(castedSectionValue ? castedSectionValue.toString() : `NO ${this.pivotField.toUpperCase()} VALUE`); + const newSchemaHeader = new SchemaHeaderField(castedSectionValue.toString()); fields.set(newSchemaHeader, [d]); columnHeaders.push(newSchemaHeader); changed = true; @@ -186,23 +160,14 @@ export class CollectionNoteTakingView extends CollectionSubView this.pivotField, - () => this.layoutDoc._columnHeaders = new List() - ); - //TODO: where the heck are we getting filters from? this._autoHeightDisposer = reaction(() => this.layoutDoc._autoHeight, autoHeight => autoHeight && this.props.setHeight(Math.min(NumCast(this.layoutDoc._maxHeight, Number.MAX_SAFE_INTEGER), - this.headerMargin + (this.isStackingView ? - Math.max(...this.refList.map(r => Number(getComputedStyle(r).height.replace("px", "")))) : - this.refList.reduce((p, r) => p + Number(getComputedStyle(r).height.replace("px", "")), 0))))); + this.headerMargin + + Math.max(...this.refList.map(r => Number(getComputedStyle(r).height.replace("px", ""))))))); } componentWillUnmount() { super.componentWillUnmount(); - this._pivotFieldDisposer?.(); this._autoHeightDisposer?.(); } @@ -211,7 +176,7 @@ export class CollectionNoteTakingView extends CollectionSubView { - this._masonryGridRef = ele; + this._noteTakingRef = ele; this.createDashEventsTarget(ele!); //so the whole grid is the drop target? } @@ -334,7 +299,7 @@ export class CollectionNoteTakingView extends CollectionSubView pos[0] && where[0] < pos1[0] && where[1] > pos[1] && (i === this._docXfs.length - 1 || where[1] < pos1[1])) { dropInd = i; - const axis = this.isStackingView ? 1 : 0; + //TODO: not sure what the axis should actually be. Had a ternary previously with 0/1 + const axis = 1; dropAfter = where[axis] > (pos[axis] + pos1[axis]) / 2 ? 1 : 0; } }); @@ -495,16 +461,16 @@ export class CollectionNoteTakingView extends CollectionSubView { - const key = this.pivotField; + const key = this.columnIndex; let type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | undefined = undefined; - if (this.pivotField) { + if (this.columnIndex) { const types = docList.length ? docList.map(d => typeof d[key]) : this.filteredChildren.map(d => typeof d[key]); if (types.map((i, idx) => types.indexOf(i) === idx).length === 1) { type = types[0]; } } //TODO: I think that we only have one of these atm - return this.refList.splice(this.refList.indexOf(ref), 1)} observeHeight={ref => { if (ref) { @@ -529,9 +495,9 @@ export class CollectionNoteTakingView extends CollectionSubView; } - // what a section looks like if we're in masonry. Shouldn't actually need to use this. - // sectionMasonry = (heading: SchemaHeaderField | undefined, docList: Doc[], first: boolean) => { - // const key = this.pivotField; - // let type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | undefined = undefined; - // const types = docList.length ? docList.map(d => typeof d[key]) : this.filteredChildren.map(d => typeof d[key]); - // if (types.map((i, idx) => types.indexOf(i) === idx).length === 1) { - // type = types[0]; - // } - // const rows = () => !this.isStackingView ? 1 : Math.max(1, Math.min(docList.length, - // Math.floor((this.props.PanelWidth() - 2 * this.xMargin) / (this.columnWidth + this.gridGap)))); - // return this.refList.splice(this.refList.indexOf(ref), 1)} - // observeHeight={(ref) => { - // if (ref) { - // this.refList.push(ref); - // this.observer = new _global.ResizeObserver(action((entries: any) => { - // if (this.layoutDoc._autoHeight && ref && this.refList.length && !SnappingManager.GetIsDragging()) { - // const height = this.refList.reduce((p, r) => p + Number(getComputedStyle(r).height.replace("px", "")), 0); - // this.props.setHeight(this.headerMargin + height); - // } - // })); - // this.observer.observe(ref); - // } - // }} - // key={heading ? heading.heading : ""} - // rows={rows} - // headings={this.headings} - // heading={heading ? heading.heading : ""} - // headingObject={heading} - // docList={docList} - // parent={this} - // type={type} - // createDropTarget={this.createDashEventsTarget} - // screenToLocalTransform={this.props.ScreenToLocalTransform} - // setDocHeight={this.setDocHeight} - // />; - // } - @action // What are we adding a group to? addGroup = (value: string) => { if (value && this.columnHeaders) { const schemaHdrField = new SchemaHeaderField(value); this.columnHeaders.push(schemaHdrField); - DocUtils.addFieldEnumerations(undefined, this.pivotField, [{ title: value, _backgroundColor: "schemaHdrField.color" }]); + DocUtils.addFieldEnumerations(undefined, this.columnIndex, [{ title: value, _backgroundColor: "schemaHdrField.color" }]); return true; } return false; @@ -620,7 +544,7 @@ export class CollectionNoteTakingView extends CollectionSubView : null}
-
this.props.isContentActive(true) && e.stopPropagation()} > - {/* so it appears that we are actually rendering the sections. Maybe this is what we're looking for? */} {this.renderedSections} - {/* I think that showAddGroup must be passed in as false, which is why we can't find what Mehek showed - Or it's because we aren't passing a pivot field */} - {!this.showAddAGroup ? (null) : -
- -
} +
+ +
{/* {this.chromeHidden || !this.props.isSelected() ? (null) : ; docList: Doc[]; heading: string; - pivotField: string; + columnIndex: string; chromeHidden?: boolean; columnHeaders: SchemaHeaderField[] | undefined; headingObject: SchemaHeaderField | undefined; yMargin: number; columnWidth: number; - numGroupColumns: number; + numColumns: number; gridGap: number; type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | undefined; headings: () => object[]; - // I think that stacking view actually has a single column and then supposedly you can add more columns? Unsure renderChildren: (docs: Doc[]) => JSX.Element[]; addDocument: (doc: Doc | Doc[]) => boolean; createDropTarget: (ele: HTMLDivElement) => void; @@ -52,15 +50,15 @@ interface CSVFieldColumnProps { } @observer -export class CollectionStackingViewFieldColumn extends React.Component { +export class CollectionNoteTakingViewFieldColumn extends React.Component { @observable private _background = "inherit"; private dropDisposer?: DragManager.DragDropDisposer; private _headerRef: React.RefObject = React.createRef(); - @observable _paletteOn = false; + // @observable _paletteOn = false; @observable _heading = this.props.headingObject ? this.props.headingObject.heading : this.props.heading; - @observable _color = this.props.headingObject ? this.props.headingObject.color : "#f1efeb"; + // @observable _color = this.props.headingObject ? this.props.headingObject.color : "#f1efeb"; _ele: HTMLElement | null = null; // This is likely similar to what we will be doing. Why do we need to make these refs? @@ -81,8 +79,9 @@ export class CollectionStackingViewFieldColumn extends React.Component { const drop = { docs: de.complete.docDragData?.droppedDocuments, val: this.getValue(this._heading) }; - drop.docs?.forEach(d => Doc.SetInPlace(d, this.props.pivotField, drop.val, false)); + drop.docs?.forEach(d => Doc.SetInPlace(d, this.props.columnIndex, drop.val, false)); }); + getValue = (value: string): any => { const parsed = parseInt(value); if (!isNaN(parsed)) return parsed; @@ -92,13 +91,13 @@ export class CollectionStackingViewFieldColumn extends React.Component { + headingChanged = (value: string) => { const castedValue = this.getValue(value); if (castedValue) { if (this.props.columnHeaders?.map(i => i.heading).indexOf(castedValue.toString()) !== -1) { return false; } - this.props.docList.forEach(d => d[this.props.pivotField] = castedValue); + this.props.docList.forEach(d => d[this.props.columnIndex] = castedValue); if (this.props.headingObject) { this.props.headingObject.setHeading(castedValue.toString()); this._heading = this.props.headingObject.heading; @@ -108,12 +107,6 @@ export class CollectionStackingViewFieldColumn extends React.Component { - this.props.headingObject?.setColor(color); - this._color = color; - } - @action pointerEntered = () => SnappingManager.GetIsDragging() && (this._background = "#b4b4b4"); @action pointerLeave = () => this._background = "inherit"; textCallback = (char: string) => this.addNewTextDoc("-typed text-", false, true); @@ -121,7 +114,7 @@ export class CollectionStackingViewFieldColumn extends React.Component { if (!value && !forceEmptyNote) return false; - const key = this.props.pivotField; + const key = this.props.columnIndex; const newDoc = Docs.Create.TextDocument(value, { _height: 18, _width: 200, _fitWidth: true, title: value, _autoHeight: true }); newDoc[key] = this.getValue(this.props.heading); const maxHeading = this.props.docList.reduce((maxHeading, doc) => NumCast(doc.heading) > maxHeading ? NumCast(doc.heading) : maxHeading, 0); @@ -134,7 +127,7 @@ export class CollectionStackingViewFieldColumn extends React.Component { - this.props.docList.forEach(d => d[this.props.pivotField] = undefined); + this.props.docList.forEach(d => d[this.props.columnIndex] = undefined); if (this.props.columnHeaders && this.props.headingObject) { const index = this.props.columnHeaders.indexOf(this.props.headingObject); this.props.columnHeaders.splice(index, 1); @@ -157,7 +150,7 @@ export class CollectionStackingViewFieldColumn extends React.Component { - const gray = "#f1efeb"; - const selected = this.props.headingObject ? this.props.headingObject.color : gray; - const colors = ["pink2", "purple4", "bluegreen1", "yellow4", "gray", "red2", "bluegreen7", "bluegreen5", "orange1"]; - return
-
- {colors.map(col => { - const palette = PastelSchemaPalette.get(col); - return
this.changeColumnColor(palette!)} />; - })} -
-
; - } - renderMenu = () => { return
@@ -246,7 +224,7 @@ export class CollectionStackingViewFieldColumn extends React.Component + `Documents that don't have a ${key} value will go here. This column cannot be removed.` : ""}> evContents} SetValue={this.headingChanged} contents={evContents} oneLine={true} toggle={this.toggleVisibility} /> - {evContents === `NO ${key.toUpperCase()} VALUE` ? (null) : -
- - {this._paletteOn ? this.renderColorPicker() : (null)} -
- } {} @@ -294,7 +263,7 @@ export class CollectionStackingViewFieldColumn extends React.Component
: (null); - const templatecols = `${this.props.columnWidth / this.props.numGroupColumns}px `; + const templatecols = `${this.props.columnWidth / this.props.numColumns}px `; const type = this.props.Document.type; return <> {this.props.Document._columnsHideIfEmpty ? (null) : headingView} @@ -322,7 +291,7 @@ export class CollectionStackingViewFieldColumn extends React.Component + style={{ width: this.props.columnWidth / this.props.numColumns, marginBottom: 10, marginLeft: 25 }}>