aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionMulticolumn
diff options
context:
space:
mode:
authorZachary Zhang <zacharyzhang7@gmail.com>2024-08-31 00:46:29 -0400
committerZachary Zhang <zacharyzhang7@gmail.com>2024-08-31 00:46:29 -0400
commit196294f331496262bef256da8b8e9dbc80288bea (patch)
tree85ff27b7a8070585f9a5ef71dff63566e03232ba /src/client/views/collections/collectionMulticolumn
parent0cf61501ec9be34294935f01973c1bd9cad6d267 (diff)
parentc36607691e0b7f5c04f3209a64958f5e51ddd785 (diff)
Merge branch 'master' into zach-starter
Diffstat (limited to 'src/client/views/collections/collectionMulticolumn')
-rw-r--r--src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.scss69
-rw-r--r--src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx109
-rw-r--r--src/client/views/collections/collectionMulticolumn/CollectionMultirowView.scss49
-rw-r--r--src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx39
-rw-r--r--src/client/views/collections/collectionMulticolumn/MulticolumnResizer.tsx2
-rw-r--r--src/client/views/collections/collectionMulticolumn/MultirowResizer.tsx2
6 files changed, 143 insertions, 127 deletions
diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.scss b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.scss
index f983fd815..06d78c39e 100644
--- a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.scss
+++ b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.scss
@@ -1,43 +1,50 @@
-.collectionMulticolumnView_contents {
- display: flex;
- //overflow: hidden; // bcz: turned of to allow highlighting to appear when there is no border (e.g, for a component of the slide template)
- width: 100%;
+.collectionMulticolumnView_drop {
height: 100%;
+ top: 0;
+ left: 0;
+ position: absolute;
- .document-wrapper {
+ .collectionMulticolumnView_contents {
display: flex;
- flex-direction: column;
+ //overflow: hidden; // bcz: turned of to allow highlighting to appear when there is no border (e.g, for a component of the slide template)
width: 100%;
- align-items: center;
- position: relative;
- > .iconButton-container {
- top: 0;
- left: 0;
- position: absolute;
- }
-
- .contentFittingDocumentView {
- margin: auto;
- }
+ height: 100%;
- .label-wrapper {
+ .document-wrapper {
display: flex;
- flex-direction: row;
- justify-content: center;
- height: 20px;
+ flex-direction: column;
+ width: 100%;
+ align-items: center;
+ position: relative;
+ > .iconButton-container {
+ top: 0;
+ left: 0;
+ position: absolute;
+ }
+
+ .contentFittingDocumentView {
+ margin: auto;
+ }
+
+ .label-wrapper {
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ height: 20px;
+ }
}
- }
- .multiColumnResizer {
- cursor: ew-resize;
- transition: 0.5s opacity ease;
- display: flex;
- flex-direction: column;
+ .multiColumnResizer {
+ cursor: ew-resize;
+ transition: 0.5s opacity ease;
+ display: flex;
+ flex-direction: column;
- .multiColumnResizer-hdl {
- width: 100%;
- height: 100%;
- transition: 0.5s background-color ease;
+ .multiColumnResizer-hdl {
+ width: 100%;
+ height: 100%;
+ transition: 0.5s background-color ease;
+ }
}
}
}
diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx
index b8509a005..d67e10c0b 100644
--- a/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx
+++ b/src/client/views/collections/collectionMulticolumn/CollectionMulticolumnView.tsx
@@ -1,5 +1,3 @@
-/* eslint-disable jsx-a11y/no-static-element-interactions */
-/* eslint-disable jsx-a11y/click-events-have-key-events */
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Tooltip } from '@mui/material';
import { Button, IconButton } from 'browndash-components';
@@ -12,13 +10,14 @@ import { BoolCast, NumCast, ScriptCast, StrCast } from '../../../../fields/Types
import { DragManager } from '../../../util/DragManager';
import { SettingsManager } from '../../../util/SettingsManager';
import { Transform } from '../../../util/Transform';
-import { undoBatch, undoable } from '../../../util/UndoManager';
+import { undoable } from '../../../util/UndoManager';
import { DocumentView } from '../../nodes/DocumentView';
-import { CollectionSubView } from '../CollectionSubView';
+import { CollectionSubView, SubCollectionViewProps } from '../CollectionSubView';
import './CollectionMulticolumnView.scss';
import ResizeBar from './MulticolumnResizer';
import WidthLabel from './MulticolumnWidthLabel';
import { dropActionType } from '../../../util/DropActionTypes';
+import { SnappingManager } from '../../../util/SnappingManager';
interface WidthSpecifier {
magnitude: number;
@@ -42,7 +41,7 @@ const resizerWidth = 8;
export class CollectionMulticolumnView extends CollectionSubView() {
@observable _startIndex = 0;
- constructor(props: any) {
+ constructor(props: SubCollectionViewProps) {
super(props);
makeObservable(this);
}
@@ -198,30 +197,28 @@ export class CollectionMulticolumnView extends CollectionSubView() {
* documents before the target.
*/
private lookupIndividualTransform = (layout: Doc) => {
- const { columnUnitLength } = this;
- if (columnUnitLength === undefined) {
+ if (this.columnUnitLength === undefined) {
return Transform.Identity(); // we're still waiting on promises to resolve
}
let offset = 0;
// eslint-disable-next-line no-restricted-syntax
for (const { layout: candidate } of this.childLayoutPairs) {
if (candidate === layout) {
- return this.ScreenToLocalBoxXf().translate(0, -offset / (this._props.NativeDimScaling?.() || 1));
+ return this.ScreenToLocalBoxXf().translate(-offset / (this._props.NativeDimScaling?.() || 1), 0);
}
offset += this.lookupPixels(candidate) + resizerWidth;
}
return Transform.Identity();
};
- @undoBatch
onInternalDrop = (e: Event, de: DragManager.DropEvent) => {
let dropInd = -1;
- if (de.complete.docDragData && this._mainCont) {
+ if (de.complete.docDragData && this._contRef.current) {
let curInd = -1;
de.complete.docDragData?.droppedDocuments.forEach(d => {
curInd = this.childDocs.indexOf(d);
});
- Array.from(this._mainCont.children).forEach((child, index) => {
+ Array.from(this._contRef.current.children).forEach((child, index) => {
const brect = child.getBoundingClientRect();
if (brect.x < de.x && brect.x + brect.width > de.x) {
if (curInd !== -1 && curInd === Math.floor(index / 2)) {
@@ -305,7 +302,7 @@ export class CollectionMulticolumnView extends CollectionSubView() {
whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
addDocTab={this._props.addDocTab}
pinToPres={this._props.pinToPres}
- dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as any} // 'y', 'x', 'xy'
+ dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as 'x' | 'y' | 'xy'}
/>
);
};
@@ -319,11 +316,11 @@ export class CollectionMulticolumnView extends CollectionSubView() {
this.childLayouts.forEach((layout, i) => {
collector.push(
// eslint-disable-next-line react/no-array-index-key
- <Tooltip title={'Tab: ' + StrCast(layout.title)} key={'wrapper' + i}>
+ <Tooltip title={'Doc: ' + StrCast(layout.title)} key={'wrapper' + i}>
<div className="document-wrapper" style={{ flexDirection: 'column', width: this.lookupPixels(layout) }}>
{this.getDisplayDoc(layout)}
{this.layoutDoc._chromeHidden ? null : (
- <Button tooltip="Remove document from header bar" icon={<FontAwesomeIcon icon="times" size="lg" />} onClick={undoable(() => this._props.removeDocument?.(layout), 'close doc')} color={SettingsManager.userColor} />
+ <Button tooltip="Remove document" icon={<FontAwesomeIcon icon="times" size="lg" />} onClick={undoable(() => this._props.removeDocument?.(layout), 'close doc')} color={SettingsManager.userColor} />
)}
<WidthLabel layout={layout} collectionDoc={this.Document} />
</div>
@@ -345,49 +342,53 @@ export class CollectionMulticolumnView extends CollectionSubView() {
return collector;
}
+ _contRef = React.createRef<HTMLDivElement>();
render() {
return (
- <div
- className="collectionMulticolumnView_contents"
- ref={this.createDashEventsTarget}
- style={{
- width: `calc(100% - ${2 * NumCast(this.Document._xMargin)}px)`,
- height: `calc(100% - ${2 * NumCast(this.Document._yMargin)}px)`,
- marginLeft: NumCast(this.Document._xMargin),
- marginRight: NumCast(this.Document._xMargin),
- marginTop: NumCast(this.Document._yMargin),
- marginBottom: NumCast(this.Document._yMargin),
- }}>
- {this.contents}
- {!this._startIndex ? null : (
- <Tooltip title="scroll back">
- <div
- style={{ position: 'absolute', bottom: 0, left: 0, background: SettingsManager.userVariantColor }}
- onClick={action(() => {
- this._startIndex = Math.min(this.childLayoutPairs.length - 1, this._startIndex + this.maxShown);
- })}>
- <Button
- tooltip="Scroll back"
- icon={<FontAwesomeIcon icon="chevron-left" size="lg" />}
+ <div className="collectionMulticolumnView_drop" ref={this.createDashEventsTarget}>
+ <div
+ className="collectionMulticolumnView_contents"
+ ref={this._contRef}
+ style={{
+ pointerEvents: this._props.isContentActive() && SnappingManager.IsDragging ? 'all' : this._props.pointerEvents?.(),
+ width: `calc(100% - ${2 * NumCast(this.Document._xMargin)}px)`,
+ height: `calc(100% - ${2 * NumCast(this.Document._yMargin)}px)`,
+ marginLeft: NumCast(this.Document._xMargin),
+ marginRight: NumCast(this.Document._xMargin),
+ marginTop: NumCast(this.Document._yMargin),
+ marginBottom: NumCast(this.Document._yMargin),
+ }}>
+ {this.contents}
+ {!this._startIndex ? null : (
+ <Tooltip title="scroll back">
+ <div
+ style={{ position: 'absolute', bottom: 0, left: 0, background: SettingsManager.userVariantColor }}
+ onClick={action(() => {
+ this._startIndex = Math.min(this.childLayoutPairs.length - 1, this._startIndex + this.maxShown);
+ })}>
+ <Button
+ tooltip="Scroll back"
+ icon={<FontAwesomeIcon icon="chevron-left" size="lg" />}
+ onClick={action(() => {
+ this._startIndex = Math.max(0, this._startIndex - this.maxShown);
+ })}
+ color={SettingsManager.userColor}
+ />
+ </div>
+ </Tooltip>
+ )}
+ {this._startIndex > this.childLayoutPairs.length - 1 || !this.maxShown ? null : (
+ <Tooltip title="scroll forward">
+ <div
+ style={{ position: 'absolute', bottom: 0, right: 0, background: SettingsManager.userVariantColor }}
onClick={action(() => {
- this._startIndex = Math.max(0, this._startIndex - this.maxShown);
- })}
- color={SettingsManager.userColor}
- />
- </div>
- </Tooltip>
- )}
- {this._startIndex > this.childLayoutPairs.length - 1 || !this.maxShown ? null : (
- <Tooltip title="scroll forward">
- <div
- style={{ position: 'absolute', bottom: 0, right: 0, background: SettingsManager.userVariantColor }}
- onClick={action(() => {
- this._startIndex = Math.min(this.childLayoutPairs.length - 1, this._startIndex + this.maxShown);
- })}>
- <IconButton icon={<FaChevronRight />} color={SettingsManager.userColor} />
- </div>
- </Tooltip>
- )}
+ this._startIndex = Math.min(this.childLayoutPairs.length - 1, this._startIndex + this.maxShown);
+ })}>
+ <IconButton icon={<FaChevronRight />} color={SettingsManager.userColor} />
+ </div>
+ </Tooltip>
+ )}
+ </div>
</div>
);
}
diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.scss b/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.scss
index f44eacb2a..0d49fabaa 100644
--- a/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.scss
+++ b/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.scss
@@ -1,34 +1,41 @@
-.collectionMultirowView_contents {
- display: flex;
- //overflow: hidden; // bcz: turned of to allow highlighting to appear when there is no border (e.g, for a component of the slide template)
- width: 100%;
+.collectionMultirowView_drop {
height: 100%;
- flex-direction: column;
+ top: 0;
+ left: 0;
+ position: absolute;
- .document-wrapper {
+ .collectionMultirowView_contents {
display: flex;
- flex-direction: row;
+ //overflow: hidden; // bcz: turned of to allow highlighting to appear when there is no border (e.g, for a component of the slide template)
+ width: 100%;
height: 100%;
- align-items: center;
+ flex-direction: column;
- .label-wrapper {
+ .document-wrapper {
display: flex;
flex-direction: row;
- justify-content: center;
- height: 20px;
+ height: 100%;
+ align-items: center;
+
+ .label-wrapper {
+ display: flex;
+ flex-direction: row;
+ justify-content: center;
+ height: 20px;
+ }
}
- }
- .multiRowResizer {
- cursor: ns-resize;
- transition: 0.5s opacity ease;
- display: flex;
- flex-direction: row;
+ .multiRowResizer {
+ cursor: ns-resize;
+ transition: 0.5s opacity ease;
+ display: flex;
+ flex-direction: row;
- .multiRowResizer-hdl {
- width: 100%;
- height: 100%;
- transition: 0.5s background-color ease;
+ .multiRowResizer-hdl {
+ width: 100%;
+ height: 100%;
+ transition: 0.5s background-color ease;
+ }
}
}
}
diff --git a/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx b/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx
index 3fe3d5343..bda8e91ac 100644
--- a/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx
+++ b/src/client/views/collections/collectionMulticolumn/CollectionMultirowView.tsx
@@ -6,9 +6,8 @@ import { BoolCast, NumCast, ScriptCast, StrCast } from '../../../../fields/Types
import { DragManager } from '../../../util/DragManager';
import { dropActionType } from '../../../util/DropActionTypes';
import { Transform } from '../../../util/Transform';
-import { undoBatch } from '../../../util/UndoManager';
import { DocumentView } from '../../nodes/DocumentView';
-import { CollectionSubView } from '../CollectionSubView';
+import { CollectionSubView, SubCollectionViewProps } from '../CollectionSubView';
import './CollectionMultirowView.scss';
import HeightLabel from './MultirowHeightLabel';
import ResizeBar from './MultirowResizer';
@@ -33,7 +32,7 @@ const resizerHeight = 8;
@observer
export class CollectionMultirowView extends CollectionSubView() {
- constructor(props: any) {
+ constructor(props: SubCollectionViewProps) {
super(props);
makeObservable(this);
}
@@ -193,15 +192,14 @@ export class CollectionMultirowView extends CollectionSubView() {
return Transform.Identity(); // type coersion, this case should never be hit
};
- @undoBatch
onInternalDrop = (e: Event, de: DragManager.DropEvent) => {
let dropInd = -1;
- if (de.complete.docDragData && this._mainCont) {
+ if (de.complete.docDragData && this._contRef.current) {
let curInd = -1;
de.complete.docDragData?.droppedDocuments.forEach(d => {
curInd = this.childDocs.indexOf(d);
});
- Array.from(this._mainCont.children).forEach((child, index) => {
+ Array.from(this._contRef.current.children).forEach((child, index) => {
const brect = child.getBoundingClientRect();
if (brect.y < de.y && brect.y + brect.height > de.y) {
if (curInd !== -1 && curInd === Math.floor(index / 2)) {
@@ -284,7 +282,7 @@ export class CollectionMultirowView extends CollectionSubView() {
whenChildContentsActiveChanged={this._props.whenChildContentsActiveChanged}
addDocTab={this._props.addDocTab}
pinToPres={this._props.pinToPres}
- dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as any} // 'y', 'x', 'xy'
+ dontCenter={StrCast(this.layoutDoc.layout_dontCenter) as 'y' | 'x' | 'xy'}
/>
);
};
@@ -318,20 +316,23 @@ export class CollectionMultirowView extends CollectionSubView() {
return collector;
}
+ _contRef = React.createRef<HTMLDivElement>();
render() {
return (
- <div
- className="collectionMultirowView_contents"
- style={{
- width: `calc(100% - ${2 * NumCast(this.Document._xMargin)}px)`,
- height: `calc(100% - ${2 * NumCast(this.Document._yMargin)}px)`,
- marginLeft: NumCast(this.Document._xMargin),
- marginRight: NumCast(this.Document._xMargin),
- marginTop: NumCast(this.Document._yMargin),
- marginBottom: NumCast(this.Document._yMargin),
- }}
- ref={this.createDashEventsTarget}>
- {this.contents}
+ <div className="collectionMultirowView_drop" ref={this.createDashEventsTarget}>
+ <div
+ ref={this._contRef}
+ className="collectionMultirowView_contents"
+ style={{
+ width: `calc(100% - ${2 * NumCast(this.Document._xMargin)}px)`,
+ height: `calc(100% - ${2 * NumCast(this.Document._yMargin)}px)`,
+ marginLeft: NumCast(this.Document._xMargin),
+ marginRight: NumCast(this.Document._xMargin),
+ marginTop: NumCast(this.Document._yMargin),
+ marginBottom: NumCast(this.Document._yMargin),
+ }}>
+ {this.contents}
+ </div>
</div>
);
}
diff --git a/src/client/views/collections/collectionMulticolumn/MulticolumnResizer.tsx b/src/client/views/collections/collectionMulticolumn/MulticolumnResizer.tsx
index 931e2c5e0..10a6fa2e9 100644
--- a/src/client/views/collections/collectionMulticolumn/MulticolumnResizer.tsx
+++ b/src/client/views/collections/collectionMulticolumn/MulticolumnResizer.tsx
@@ -68,7 +68,7 @@ export default class ResizeBar extends React.Component<ResizerProps> {
style={{
pointerEvents: this.props.isContentActive?.() ? 'all' : 'none',
width: this.props.width,
- backgroundColor: !this.props.isContentActive?.() ? '' : this.props.styleProvider?.(undefined, undefined, StyleProp.WidgetColor),
+ backgroundColor: !this.props.isContentActive?.() ? '' : (this.props.styleProvider?.(undefined, undefined, StyleProp.WidgetColor) as string),
}}>
<div className="multiColumnResizer-hdl" onPointerDown={e => this.registerResizing(e)} />
</div>
diff --git a/src/client/views/collections/collectionMulticolumn/MultirowResizer.tsx b/src/client/views/collections/collectionMulticolumn/MultirowResizer.tsx
index cff0a8b4c..918365700 100644
--- a/src/client/views/collections/collectionMulticolumn/MultirowResizer.tsx
+++ b/src/client/views/collections/collectionMulticolumn/MultirowResizer.tsx
@@ -66,7 +66,7 @@ export default class ResizeBar extends React.Component<ResizerProps> {
style={{
pointerEvents: this.props.isContentActive?.() ? 'all' : 'none',
height: this.props.height,
- backgroundColor: !this.props.isContentActive?.() ? '' : this.props.styleProvider?.(undefined, undefined, StyleProp.WidgetColor),
+ backgroundColor: !this.props.isContentActive?.() ? '' : this.props.styleProvider?.(undefined, undefined, StyleProp.WidgetColor) as string,
}}>
<div className="multiRowResizer-hdl" onPointerDown={e => this.registerResizing(e)} />
</div>