aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Utils.ts15
-rw-r--r--src/client/views/DocumentDecorations.scss81
-rw-r--r--src/client/views/DocumentDecorations.tsx143
-rw-r--r--src/client/views/global/globalEnums.tsx1
-rw-r--r--src/client/views/nodes/CollectionFreeFormDocumentView.tsx1
5 files changed, 159 insertions, 82 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index b87980397..6699aa133 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -677,7 +677,22 @@ export function StopEvent(e: React.PointerEvent | React.MouseEvent) {
e.preventDefault();
}
+/**
+ * Helper method for converting pixel string eg. '32px' into number eg. 32
+ * @param value: string with 'px' ending
+ * @returns value: number
+ *
+ * Example:
+ * '32px' -> 32
+ */
+export function numberValue(value: string | undefined):number {
+ if (value == undefined) return 0;
+ return parseInt(value);
+}
+export function numbersAlmostEqual(num1: number, num2: number) {
+ return Math.abs( num1 - num2 ) < 0.2;
+}
export function setupMoveUpEvents(
target: object,
diff --git a/src/client/views/DocumentDecorations.scss b/src/client/views/DocumentDecorations.scss
index 135d6d001..b490278c3 100644
--- a/src/client/views/DocumentDecorations.scss
+++ b/src/client/views/DocumentDecorations.scss
@@ -1,6 +1,8 @@
@import 'global/globalCssVariables';
$linkGap: 3px;
+$headerHeight: 20px;
+$resizeHandler: 8px;
.documentDecorations-Dark,
.documentDecorations {
@@ -16,8 +18,8 @@ $linkGap: 3px;
top: 0;
left: 0;
display: grid;
- grid-template-rows: 20px 8px 1fr 8px;
- grid-template-columns: 8px 1fr 8px;
+ grid-template-rows: $headerHeight $resizeHandler 1fr $resizeHandler;
+ grid-template-columns: $resizeHandler 1fr $resizeHandler;
pointer-events: none;
.documentDecorations-centerCont {
@@ -82,29 +84,46 @@ $linkGap: 3px;
grid-column: 3;
}
- .documentDecorations-rotation,
+ // Rotation handler
+ .documentDecorations-rotation {
+ border-radius: 100%;
+ height: 30;
+ width: 30;
+ right: -10;
+ top: 50%;
+ z-index: 1000000;
+ position: absolute;
+ pointer-events: all;
+ cursor: pointer;
+ background: white;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ text-align: center;
+ font-size: 30px;
+ }
+
+ // Border radius handler
.documentDecorations-borderRadius {
- grid-column: 3;
- grid-row: 4;
+ position: absolute;
border-radius: 100%;
- background: black;
- height: 8;
- right: -12;
- top: 12;
- position: relative;
+ left: 3px;
+ top: 23px;
+ background: $medium-gray;
+ height: 10;
+ width: 10;
pointer-events: all;
cursor: nwse-resize;
-
- .borderRadiusTooltip {
- width: 10px;
- height: 10px;
- position: absolute;
- }
}
- .documentDecorations-rotation {
- background: transparent;
- right: -15;
+ .documentDecorations-rotationPath {
+ position: absolute;
+ width: 100%;
+ height: 0;
+ transform: translate(0px, -25%);
+ padding-bottom: 100%;
+ border-radius: 100%;
+ border: solid $medium-gray 10px;
}
.documentDecorations-topLeftResizer,
@@ -146,30 +165,6 @@ $linkGap: 3px;
grid-column: 3;
}
- .documentDecorations-rotation,
- .documentDecorations-borderRadius {
- grid-column: 3;
- grid-row: 4;
- border-radius: 100%;
- background: black;
- height: 8;
- right: -12;
- top: 12;
- position: relative;
- pointer-events: all;
- cursor: nwse-resize;
-
- .borderRadiusTooltip {
- width: 10px;
- height: 10px;
- position: absolute;
- }
- }
- .documentDecorations-rotation {
- background: transparent;
- right: -15;
- }
-
.documentDecorations-topLeftResizer,
.documentDecorations-bottomRightResizer {
cursor: nwse-resize;
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx
index 9dc02e3f4..9544c588b 100644
--- a/src/client/views/DocumentDecorations.tsx
+++ b/src/client/views/DocumentDecorations.tsx
@@ -10,7 +10,7 @@ import { InkField } from '../../fields/InkField';
import { ComputedField, ScriptField } from '../../fields/ScriptField';
import { Cast, FieldValue, NumCast, StrCast } from '../../fields/Types';
import { GetEffectiveAcl } from '../../fields/util';
-import { emptyFunction, returnFalse, setupMoveUpEvents } from '../../Utils';
+import { emptyFunction, returnFalse, setupMoveUpEvents, numberValue, numbersAlmostEqual } from '../../Utils';
import { Docs } from '../documents/Documents';
import { DocumentType } from '../documents/DocumentTypes';
import { CurrentUserUtils } from '../util/CurrentUserUtils';
@@ -30,6 +30,7 @@ import { DocumentView } from './nodes/DocumentView';
import { FormattedTextBox } from './nodes/formattedText/FormattedTextBox';
import { ImageBox } from './nodes/ImageBox';
import React = require('react');
+import { Colors } from './global/globalEnums';
@observer
export class DocumentDecorations extends React.Component<{ PanelWidth: number; PanelHeight: number; boundsLeft: number; boundsTop: number }, { value: string }> {
@@ -49,20 +50,23 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
@observable private _accumulatedTitle = '';
@observable private _titleControlString: string = '#title';
- @observable private _edtingTitle = false;
+ @observable private _editingTitle = false;
@observable private _hidden = false;
@observable public AddToSelection = false; // if Shift is pressed, then this should be set so that clicking on the selection background is ignored so overlapped documents can be added to the selection set.
@observable public Interacting = false;
@observable public pushIcon: IconProp = 'arrow-alt-circle-up';
@observable public pullIcon: IconProp = 'arrow-alt-circle-down';
@observable public pullColor: string = 'white';
+ @observable private _isRotating: boolean = false;
+ @observable private _isRounding: boolean = false;
+ @observable private _isResizing: boolean = false;
constructor(props: any) {
super(props);
DocumentDecorations.Instance = this;
reaction(
() => SelectionManager.Views().slice(),
- action(docs => (this._edtingTitle = false))
+ action(docs => (this._editingTitle = false))
);
}
@@ -89,7 +93,7 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
@action
titleBlur = () => {
- this._edtingTitle = false;
+ this._editingTitle = false;
if (this._accumulatedTitle.startsWith('#') || this._accumulatedTitle.startsWith('=')) {
this._titleControlString = this._accumulatedTitle;
} else if (this._titleControlString.startsWith('#')) {
@@ -143,8 +147,8 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
e => this.onBackgroundMove(true, e),
e => {},
action(e => {
- !this._edtingTitle && (this._accumulatedTitle = this._titleControlString.startsWith('#') ? this.selectionTitle : this._titleControlString);
- this._edtingTitle = true;
+ !this._editingTitle && (this._accumulatedTitle = this._titleControlString.startsWith('#') ? this.selectionTitle : this._titleControlString);
+ this._editingTitle = true;
this._keyinput.current && setTimeout(this._keyinput.current.focus);
})
);
@@ -262,30 +266,50 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
};
onSelectorClick = () => SelectionManager.Views()?.[0]?.props.ContainingCollectionView?.props.select(false);
-
+
+ /**
+ * Handles setting up events when user clicks on the border radius editor
+ * @param e PointerEvent
+ */
+ @action
onRadiusDown = (e: React.PointerEvent): void => {
+ this._isRounding = true;
this._resizeUndo = UndoManager.StartBatch('DocDecs set radius');
+ // Call util move event function
setupMoveUpEvents(
- this,
- e,
+ this, // target
+ e, // pointerEvent
(e, down) => {
- const dist = Math.sqrt((e.clientX - down[0]) * (e.clientX - down[0]) + (e.clientY - down[1]) * (e.clientY - down[1]));
+ const x = this.Bounds.x + 3;
+ const y = this.Bounds.y + 3;
+ const maxDist = Math.min((this.Bounds.r - this.Bounds.x) / 2, (this.Bounds.b - this.Bounds.y) / 2);
+ let dist = Math.sqrt((e.clientX - x) * (e.clientX - x) + (e.clientY - y) * (e.clientY - y));
+ if (e.clientX < x && e.clientY < y) dist = 0
SelectionManager.Views()
.map(dv => dv.props.Document)
- .map(doc => (doc.layout instanceof Doc ? doc.layout : doc.isTemplateForField ? doc : Doc.GetProto(doc)))
- .map(d => (d.borderRounding = `${Math.max(0, dist < 3 ? 0 : dist)}px`));
+ .map(doc => {
+ const docMax = Math.min(NumCast(doc.width)/2, NumCast(doc.height)/2);
+ const ratio = dist/maxDist;
+ const radius = Math.min(1, ratio) * docMax;
+ doc.borderRounding = `${radius}px`;
+ }
+ );
return false;
- },
- e => this._resizeUndo?.end(),
- e => {}
+ }, // moveEvent
+ action(e => {
+ this._isRounding = false;
+ this._resizeUndo?.end()
+ }), // upEvent
+ e => {} // clickEvent
);
};
@action
onRotateDown = (e: React.PointerEvent): void => {
+ this._isRotating = true;
const rotateUndo = UndoManager.StartBatch('rotatedown');
const selectedInk = SelectionManager.Views().filter(i => i.ComponentView instanceof InkingStroke);
- const centerPoint = !selectedInk.length ? { X: this.Bounds.x, Y: this.Bounds.y } : { X: this.Bounds.c?.X ?? (this.Bounds.x + this.Bounds.r) / 2, Y: this.Bounds.c?.Y ?? (this.Bounds.y + this.Bounds.b) / 2 };
+ const centerPoint = { X: (this.Bounds.x + this.Bounds.r) / 2, Y: (this.Bounds.y + this.Bounds.b) / 2 };
setupMoveUpEvents(
this,
e,
@@ -296,14 +320,33 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
if (selectedInk.length) {
angle && InkStrokeProperties.Instance.rotateInk(selectedInk, -angle, centerPoint);
} else {
- SelectionManager.Views().forEach(dv => (dv.rootDoc._jitterRotation = NumCast(dv.rootDoc._jitterRotation) - (angle * 180) / Math.PI));
+ SelectionManager.Views().forEach(dv => {
+ const oldRotation = NumCast(dv.rootDoc._jitterRotation);
+ // Rotation between -360 and 360
+ let newRotation = (oldRotation - (angle * 180) / Math.PI) % 360;
+
+ const diff = Math.round(newRotation / 45) - newRotation / 45
+ if (diff < .05) {
+ console.log('show lines');
+ }
+ dv.rootDoc._jitterRotation = newRotation;
+ });
}
return false;
- },
- () => {
+ }, // moveEvent
+ action(() => {
+ SelectionManager.Views().forEach(dv => {
+ const oldRotation = NumCast(dv.rootDoc._jitterRotation);
+ const diff = Math.round(oldRotation / 45) - oldRotation / 45
+ if (diff < .05) {
+ let newRotation = Math.round(oldRotation / 45) * 45;
+ dv.rootDoc._jitterRotation = newRotation;
+ }
+ })
+ this._isRotating = false;
rotateUndo?.end();
UndoManager.FilterBatches(['data', 'x', 'y', 'width', 'height']);
- },
+ }), // upEvent
emptyFunction
);
};
@@ -554,19 +597,23 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
return null;
}
// hide the decorations if the parent chooses to hide it or if the document itself hides it
- const hideResizers = seldoc.props.hideResizeHandles || seldoc.rootDoc.hideResizeHandles || seldoc.rootDoc._isGroup;
- const hideTitle = seldoc.props.hideDecorationTitle || seldoc.rootDoc.hideDecorationTitle;
- const hideDocumentButtonBar = seldoc.props.hideDocumentButtonBar || seldoc.rootDoc.hideDocumentButtonBar;
+ const hideResizers = seldoc.props.hideResizeHandles || seldoc.rootDoc.hideResizeHandles || seldoc.rootDoc._isGroup || this._isRounding || this._isRotating;
+ const hideTitle = seldoc.props.hideDecorationTitle || seldoc.rootDoc.hideDecorationTitle || this._isRounding || this._isRotating;
+ const hideDocumentButtonBar = seldoc.props.hideDocumentButtonBar || seldoc.rootDoc.hideDocumentButtonBar || this._isRounding ||
+ this._isRotating;
// if multiple documents have been opened at the same time, then don't show open button
const hideOpenButton =
- seldoc.props.hideOpenButton || seldoc.rootDoc.hideOpenButton || SelectionManager.Views().some(docView => docView.props.Document._stayInCollection || docView.props.Document.isGroup || docView.props.Document.hideOpenButton);
+ seldoc.props.hideOpenButton || seldoc.rootDoc.hideOpenButton || SelectionManager.Views().some(docView => docView.props.Document._stayInCollection || docView.props.Document.isGroup || docView.props.Document.hideOpenButton) || this._isRounding || this._isRotating;
const hideDeleteButton =
+ this._isRounding ||
+ this._isRotating ||
seldoc.props.hideDeleteButton ||
seldoc.rootDoc.hideDeleteButton ||
SelectionManager.Views().some(docView => {
const collectionAcl = docView.props.ContainingCollectionView ? GetEffectiveAcl(docView.props.ContainingCollectionDoc?.[DataSym]) : AclEdit;
return docView.rootDoc.stayInCollection || (collectionAcl !== AclAdmin && collectionAcl !== AclEdit && GetEffectiveAcl(docView.rootDoc) !== AclAdmin);
});
+
const topBtn = (key: string, icon: string, pointerDown: undefined | ((e: React.PointerEvent) => void), click: undefined | ((e: any) => void), title: string) => (
<Tooltip key={key} title={<div className="dash-tooltip">{title}</div>} placement="top">
<div
@@ -589,7 +636,7 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
);
const colorScheme = StrCast(CurrentUserUtils.ActiveDashboard?.colorScheme);
- const titleArea = hideTitle ? null : this._edtingTitle ? (
+ const titleArea = hideTitle ? null : this._editingTitle ? (
<input
ref={this._keyinput}
className={`documentDecorations-title${colorScheme}`}
@@ -615,11 +662,20 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
bounds.r = Math.max(bounds.x, Math.max(leftBounds, Math.min(window.innerWidth, bounds.r + borderRadiusDraggerWidth + this._resizeBorderWidth / 2) - this._resizeBorderWidth / 2 - borderRadiusDraggerWidth));
bounds.b = Math.max(bounds.y, Math.max(topBounds, Math.min(window.innerHeight, bounds.b + this._resizeBorderWidth / 2 + this._linkBoxHeight) - this._resizeBorderWidth / 2 - this._linkBoxHeight));
+ // Rotation constants: Only allow rotation on ink and images
const useRotation = seldoc.ComponentView instanceof InkingStroke || seldoc.ComponentView instanceof ImageBox;
- const resizerScheme = colorScheme ? 'documentDecorations-resizer' + colorScheme : '';
-
const rotation = NumCast(seldoc.rootDoc._jitterRotation);
+
+
+ const resizerScheme = colorScheme ? 'documentDecorations-resizer' + colorScheme : '';
+ // Radius constants
+ const useRounding = seldoc.ComponentView instanceof ImageBox || seldoc.ComponentView instanceof FormattedTextBox;
+ const borderRadius = numberValue(StrCast(seldoc.rootDoc.borderRounding));
+ const docMax = Math.min(NumCast(seldoc.rootDoc.width)/2, NumCast(seldoc.rootDoc.height)/2);
+ const maxDist = Math.min((this.Bounds.r - this.Bounds.x) / 2, (this.Bounds.b - this.Bounds.y) / 2);
+ const radiusHandle = (borderRadius / docMax) * maxDist;
+ const radiusHandleLocation = Math.min(radiusHandle, maxDist);
return (
<div className={`documentDecorations${colorScheme}`}>
<div
@@ -641,18 +697,18 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
}}
/>
{bounds.r - bounds.x < 15 && bounds.b - bounds.y < 15 ? null : (
- <>
+ <div>
<div
className="documentDecorations-container"
key="container"
style={{
- transform: ` translate(${bounds.x - this._resizeBorderWidth / 2}px, ${bounds.y - this._resizeBorderWidth / 2 - this._titleHeight}px) rotate(${rotation}deg)`,
- transformOrigin: `8px 26px`,
+ transform: `translate(${bounds.x - this._resizeBorderWidth / 2}px, ${bounds.y - this._resizeBorderWidth / 2 - this._titleHeight}px) rotate(${rotation}deg)`,
+ transformOrigin: `50% calc(50% + 10px)`,
width: bounds.r - bounds.x + this._resizeBorderWidth + 'px',
height: bounds.b - bounds.y + this._resizeBorderWidth + this._titleHeight + 'px',
}}>
{hideDeleteButton ? <div /> : topBtn('close', this.hasIcons ? 'times' : 'window-maximize', undefined, e => this.onCloseClick(this.hasIcons ? true : undefined), 'Close')}
- {titleArea}
+ {hideTitle ? null : titleArea}
{hideOpenButton ? null : topBtn('open', 'external-link-alt', this.onMaximizeDown, undefined, 'Open in Tab (ctrl: as alias, shift: in new collection)')}
{hideResizers ? null : (
<>
@@ -666,16 +722,25 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
<div key="b" className={`documentDecorations-bottomResizer ${resizerScheme}`} onPointerDown={this.onPointerDown} onContextMenu={e => e.preventDefault()} />
<div key="br" className={`documentDecorations-bottomRightResizer ${resizerScheme}`} onPointerDown={this.onPointerDown} onContextMenu={e => e.preventDefault()} />
- {seldoc.props.renderDepth <= 1 || !seldoc.props.ContainingCollectionView ? null : topBtn('selector', 'arrow-alt-circle-up', undefined, this.onSelectorClick, 'tap to select containing document')}
- {useRotation && (
- <div key="rot" className={`documentDecorations-rotation`} onPointerDown={this.onRotateDown} onContextMenu={e => e.preventDefault()}>
- {'⟲'}
- </div>
- )}
- <div key="br" className={`documentDecorations-borderRadius`} onPointerDown={this.onRadiusDown} onContextMenu={e => e.preventDefault()} />
+ {seldoc.props.renderDepth <= 1 || !seldoc.props.ContainingCollectionView ? null : topBtn('selector', 'arrow-alt-circle-up', undefined, this.onSelectorClick, 'tap to select containing document')}
</>
)}
+ {useRotation && (
+ <div key="rot" className={`documentDecorations-rotation`} onPointerDown={this.onRotateDown} onContextMenu={e => e.preventDefault()}>
+ {'⟲'}
+ </div>
+ )}
+
+ {useRounding && (
+ <div key="rad" style={{
+ background: `${this._isRounding ? Colors.MEDIUM_BLUE : undefined}`,
+ left:`${radiusHandleLocation + 3}`,
+ top:`${radiusHandleLocation + 23}`
+ }} className={`documentDecorations-borderRadius`} onPointerDown={this.onRadiusDown} onContextMenu={e => e.preventDefault()}
+ />
+ )}
+
{hideDocumentButtonBar ? null : (
<div
className="link-button-container"
@@ -687,7 +752,7 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number; P
</div>
)}
</div>
- </>
+ </div>
)}
</div>
);
diff --git a/src/client/views/global/globalEnums.tsx b/src/client/views/global/globalEnums.tsx
index 56779c37c..610c2b102 100644
--- a/src/client/views/global/globalEnums.tsx
+++ b/src/client/views/global/globalEnums.tsx
@@ -8,6 +8,7 @@ export enum Colors {
MEDIUM_BLUE_ALT = "#4476f73d", // REDUCED OPACITY
LIGHT_BLUE = "#BDDDF5",
PINK = "#E0217D",
+ ERROR_RED = "#ff0033",
YELLOW = "#F5D747",
DROP_SHADOW = "#32323215",
}
diff --git a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx
index bedc97575..284584a3d 100644
--- a/src/client/views/nodes/CollectionFreeFormDocumentView.tsx
+++ b/src/client/views/nodes/CollectionFreeFormDocumentView.tsx
@@ -170,6 +170,7 @@ export class CollectionFreeFormDocumentView extends DocComponent<CollectionFreeF
width: this.panelWidth(),
height: this.panelHeight(),
transform: this.transform,
+ transformOrigin: '50% 50%',
transition: this.dataProvider?.transition ?? (this.props.dataTransition ? this.props.dataTransition : this.dataProvider ? this.dataProvider.transition : StrCast(this.layoutDoc.dataTransition)),
zIndex: this.ZInd,
mixBlendMode: mixBlendMode,