aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionView.tsx
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-12-17 16:22:06 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-12-17 16:22:06 +0530
commit48fd017c46b930ae94e341ae73bfc35006008b44 (patch)
tree488aae6f3864622548c01433867309cc0bd03a24 /src/client/views/collections/CollectionView.tsx
parent563d86f03f63f60ec47aef23d2022c660ee18697 (diff)
parentf4f4cb6b3a639c3e1c0d291f1d290e80097cfa06 (diff)
merged
Diffstat (limited to 'src/client/views/collections/CollectionView.tsx')
-rw-r--r--src/client/views/collections/CollectionView.tsx114
1 files changed, 49 insertions, 65 deletions
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index 8f402c427..83c639871 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -10,7 +10,7 @@ import { List } from '../../../fields/List';
import { ObjectField } from '../../../fields/ObjectField';
import { BoolCast, Cast, ScriptCast, StrCast } from '../../../fields/Types';
import { ImageField } from '../../../fields/URLField';
-import { distributeAcls, GetEffectiveAcl, SharingPermissions, TraceMobx, normalizeEmail, denormalizeEmail } from '../../../fields/util';
+import { denormalizeEmail, distributeAcls, GetEffectiveAcl, SharingPermissions, TraceMobx } from '../../../fields/util';
import { returnFalse, Utils } from '../../../Utils';
import { Docs, DocUtils } from '../../documents/Documents';
import { DocumentType } from '../../documents/DocumentTypes';
@@ -38,10 +38,7 @@ import { SubCollectionViewProps } from './CollectionSubView';
import { CollectionTimeView } from './CollectionTimeView';
import { CollectionTreeView } from "./CollectionTreeView";
import './CollectionView.scss';
-import { listSpec } from '../../../fields/Schema';
-const higflyout = require("@hig/flyout");
-export const { anchorPoints } = higflyout;
-export const Flyout = higflyout.default;
+import { ScriptField } from '../../../fields/ScriptField';
export const COLLECTION_BORDER_WIDTH = 2;
const path = require('path');
@@ -64,28 +61,26 @@ export enum CollectionViewType {
Grid = "grid",
Pile = "pileup"
}
-export interface CollectionViewCustomProps {
+export interface CollectionViewProps extends FieldViewProps {
+ isAnnotationOverlay?: boolean; // is the collection an annotation overlay (eg an overlay on an image/video/etc)
+ layoutEngine?: () => string;
+ parentActive: (outsideReaction: boolean) => boolean;
filterAddDocument?: (doc: Doc | Doc[]) => boolean; // allows a document that renders a Collection view to filter or modify any documents added to the collection (see PresBox for an example)
+ setPreviewCursor?: (func: (x: number, y: number, drag: boolean) => void) => void;
+
+ // property overrides for child documents
+ children?: never | (() => JSX.Element[]) | React.ReactNode;
+ childDocuments?: Doc[]; // used to override the documents shown by the sub collection to an explicit list (see LinkBox)
childOpacity?: () => number;
- hideFilter?: true;
+ childLayoutTemplate?: () => (Doc | undefined);// specify a layout Doc template to use for children of the collection
+ childLayoutString?: string;
+ childFreezeDimensions?: boolean; // used by TimeView to coerce documents to treat their width height as their native width/height
childIgnoreNativeSize?: boolean;
+ childClickScript?: ScriptField;
+ childDoubleClickScript?: ScriptField;
}
-
-export interface CollectionRenderProps {
- addDocument: (document: Doc | Doc[]) => boolean;
- removeDocument: (document: Doc | Doc[]) => boolean;
- moveDocument: (document: Doc | Doc[], targetCollection: Doc | undefined, addDocument: (document: Doc | Doc[]) => boolean) => boolean;
- active: () => boolean;
- parentActive: (outsideReaction: boolean) => boolean;
- whenActiveChanged: (isActive: boolean) => void;
- PanelWidth: () => number;
- PanelHeight: () => number;
- ChildLayoutTemplate?: () => Doc;// specify a layout Doc template to use for children of the collection
- ChildLayoutString?: string;// specify a layout string to use for children of the collection
-}
-
@observer
-export class CollectionView extends Touchable<FieldViewProps & CollectionViewCustomProps> {
+export class CollectionView extends Touchable<CollectionViewProps> {
public static LayoutString(fieldStr: string) { return FieldView.LayoutString(CollectionView, fieldStr); }
_isChildActive = false; //TODO should this be observable?
@@ -97,22 +92,13 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
protected _multiTouchDisposer?: InteractionUtils.MultiTouchEventDisposer;
- private AclMap = new Map<symbol, string>([
- [AclPrivate, SharingPermissions.None],
- [AclReadonly, SharingPermissions.View],
- [AclAddonly, SharingPermissions.Add],
- [AclEdit, SharingPermissions.Edit],
- [AclAdmin, SharingPermissions.Admin]
- ]);
-
get collectionViewType(): CollectionViewType | undefined {
const viewField = StrCast(this.props.Document._viewType);
if (CollectionView._safeMode) {
- if (viewField === CollectionViewType.Freeform || viewField === CollectionViewType.Schema) {
- return CollectionViewType.Tree;
- }
- if (viewField === CollectionViewType.Invalid) {
- return CollectionViewType.Freeform;
+ switch (viewField) {
+ case CollectionViewType.Freeform:
+ case CollectionViewType.Schema: return CollectionViewType.Tree;
+ case CollectionViewType.Invalid: return CollectionViewType.Freeform;
}
}
return viewField as any as CollectionViewType;
@@ -120,7 +106,7 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
active = (outsideReaction?: boolean) => (this.props.isSelected(outsideReaction) ||
this.props.rootSelected(outsideReaction) ||
- this.props.Document.forceActive ||
+ (this.props.layerProvider?.(this.props.Document) !== false && (this.props.Document.forceActive || this.props.Document._isGroup)) ||
this._isChildActive ||
this.props.renderDepth === 0) ?
true :
@@ -136,7 +122,6 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
const docs = doc instanceof Doc ? [doc] : doc;
-
if (docs.find(doc => Doc.AreProtosEqual(doc, this.props.Document))) return false;
const targetDataDoc = this.props.Document[DataSym];
const docList = DocListCast(targetDataDoc[this.props.fieldKey]);
@@ -160,7 +145,7 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
if (effectiveAcl === AclAddonly) {
added.map(doc => {
- this.props.layerProvider?.(doc, true);
+ this.props.layerProvider?.(doc, true);// assigns layer values to the newly added document... testing the utility of this
Doc.AddDocToList(targetDataDoc, this.props.fieldKey, doc);
doc.context = this.props.Document;
});
@@ -185,7 +170,7 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
doc._stayInCollection = undefined;
doc.context = this.props.Document;
});
- added.map(doc => this.props.layerProvider?.(doc, true));
+ added.map(doc => this.props.layerProvider?.(doc, true));// assigns layer values to the newly added document... testing the utility of this
(targetDataDoc[this.props.fieldKey] as List<Doc>).push(...added);
targetDataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now()));
}
@@ -253,32 +238,30 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
}
screenToLocalTransform = () => this.props.renderDepth ? this.props.ScreenToLocalTransform() : this.props.ScreenToLocalTransform().scale(this.props.PanelWidth() / this.bodyPanelWidth());
- private SubView = (type: CollectionViewType, renderProps: CollectionRenderProps) => {
+ private SubView = (type: CollectionViewType, props: SubCollectionViewProps) => {
TraceMobx();
- const props: SubCollectionViewProps = { ...this.props, ...renderProps, ScreenToLocalTransform: this.screenToLocalTransform, CollectionView: this, annotationsKey: "" };
switch (type) {
- case CollectionViewType.Schema: return (<CollectionSchemaView key="collview" {...props} />);
- case CollectionViewType.Docking: return (<CollectionDockingView key="collview" {...props} />);
- case CollectionViewType.Tree: return (<CollectionTreeView key="collview" {...props} />);
- //case CollectionViewType.Staff: return (<CollectionStaffView key="collview" {...props} />);
- case CollectionViewType.Multicolumn: return (<CollectionMulticolumnView key="collview" {...props} />);
- case CollectionViewType.Multirow: return (<CollectionMultirowView key="rpwview" {...props} />);
- case CollectionViewType.Linear: { return (<CollectionLinearView key="collview" {...props} />); }
- case CollectionViewType.Pile: { return (<CollectionPileView key="collview" {...props} />); }
- case CollectionViewType.Carousel: { return (<CollectionCarouselView key="collview" {...props} />); }
- case CollectionViewType.Carousel3D: { return (<CollectionCarousel3DView key="collview" {...props} />); }
- case CollectionViewType.Stacking: { this.props.Document._columnsStack = true; return (<CollectionStackingView key="collview" {...props} />); }
- case CollectionViewType.Masonry: { this.props.Document._columnsStack = false; return (<CollectionStackingView key="collview" {...props} />); }
- case CollectionViewType.Time: { return (<CollectionTimeView key="collview" {...props} />); }
- case CollectionViewType.Map: return (<CollectionMapView key="collview" {...props} />);
- case CollectionViewType.Grid: return (<CollectionGridView key="gridview" {...props} />);
- case CollectionViewType.Freeform:
- default: { this.props.Document._freeformLayoutEngine = undefined; return (<CollectionFreeFormView key="collview" {...props} ChildLayoutString={props.ChildLayoutString} />); }
+ default:
+ case CollectionViewType.Freeform: return <CollectionFreeFormView key="collview" {...props} />;
+ case CollectionViewType.Schema: return <CollectionSchemaView key="collview" {...props} />;
+ case CollectionViewType.Docking: return <CollectionDockingView key="collview" {...props} />;
+ case CollectionViewType.Tree: return <CollectionTreeView key="collview" {...props} />;
+ case CollectionViewType.Multicolumn: return <CollectionMulticolumnView key="collview" {...props} />;
+ case CollectionViewType.Multirow: return <CollectionMultirowView key="collview" {...props} />;
+ case CollectionViewType.Linear: return <CollectionLinearView key="collview" {...props} />;
+ case CollectionViewType.Pile: return <CollectionPileView key="collview" {...props} />;
+ case CollectionViewType.Carousel: return <CollectionCarouselView key="collview" {...props} />;
+ case CollectionViewType.Carousel3D: return <CollectionCarousel3DView key="collview" {...props} />;
+ case CollectionViewType.Stacking: return <CollectionStackingView key="collview" {...props} />;
+ case CollectionViewType.Masonry: return <CollectionStackingView key="collview" {...props} />;
+ case CollectionViewType.Time: return <CollectionTimeView key="collview" {...props} />;
+ case CollectionViewType.Map: return <CollectionMapView key="collview" {...props} />;
+ case CollectionViewType.Grid: return <CollectionGridView key="collview" {...props} />;
+ //case CollectionViewType.Staff: return <CollectionStaffView key="collview" {...props} />;
}
}
setupViewTypes(category: string, func: (viewType: CollectionViewType) => Doc, addExtras: boolean) {
-
const subItems: ContextMenuProps[] = [];
subItems.push({ description: "Freeform", event: () => func(CollectionViewType.Freeform), icon: "signature" });
if (addExtras && CollectionView._safeMode) {
@@ -386,7 +369,8 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
render() {
TraceMobx();
- const props: CollectionRenderProps = {
+ const props: SubCollectionViewProps = {
+ ...this.props,
addDocument: this.addDocument,
removeDocument: this.removeDocument,
moveDocument: this.moveDocument,
@@ -395,13 +379,13 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
parentActive: this.props.parentActive,
PanelWidth: this.bodyPanelWidth,
PanelHeight: this.props.PanelHeight,
- ChildLayoutTemplate: this.childLayoutTemplate,
- ChildLayoutString: this.childLayoutString,
+ childLayoutTemplate: this.childLayoutTemplate,
+ childLayoutString: this.childLayoutString,
+ ScreenToLocalTransform: this.screenToLocalTransform,
+ CollectionView: this,
};
- const boxShadow = Doc.UserDoc().renderStyle === "comic" || this.props.Document.treeViewOutlineMode || this.collectionViewType === CollectionViewType.Linear ? undefined :
- this.props.styleProvider?.(this.props.Document, this.props, "boxShadow");
return (<div className={"collectionView"} onContextMenu={this.onContextMenu}
- style={{ pointerEvents: this.props.layerProvider?.(this.props.Document) === false ? "none" : undefined, boxShadow }}>
+ style={{ pointerEvents: this.props.layerProvider?.(this.props.Document) === false ? "none" : undefined }}>
{this.showIsTagged()}
{this.collectionViewType !== undefined ? this.SubView(this.collectionViewType, props) : (null)}
{this.lightbox(DocListCast(this.props.Document[this.props.fieldKey]).filter(d => Cast(d.data, ImageField, null)).map(d =>