aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/LinkBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-03-29 17:44:26 -0400
committerbobzel <zzzman@gmail.com>2024-03-29 17:44:26 -0400
commitd38f8a80cff0e7e6140fd3ff815210077718746d (patch)
tree43e6f8bcab09fa73e8ee17192466be9afbcdcb2a /src/client/views/nodes/LinkBox.tsx
parent7ae6431a59604085c4117622c4f5e466daf541a3 (diff)
fixed capture offset to target in link following. fixed links to appear in lightbox and to not disappear when dragged.
Diffstat (limited to 'src/client/views/nodes/LinkBox.tsx')
-rw-r--r--src/client/views/nodes/LinkBox.tsx49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/client/views/nodes/LinkBox.tsx b/src/client/views/nodes/LinkBox.tsx
index b5cb7a9ae..7ad250714 100644
--- a/src/client/views/nodes/LinkBox.tsx
+++ b/src/client/views/nodes/LinkBox.tsx
@@ -17,6 +17,7 @@ import { StyleProp } from '../StyleProvider';
import { ComparisonBox } from './ComparisonBox';
import { FieldView, FieldViewProps } from './FieldView';
import './LinkBox.scss';
+import { DocumentView } from './DocumentView';
@observer
export class LinkBox extends ViewBoxBaseComponent<FieldViewProps>() {
@@ -47,31 +48,27 @@ export class LinkBox extends ViewBoxBaseComponent<FieldViewProps>() {
componentDidMount() {
this._props.setContentViewBox?.(this);
this._disposers.deleting = reaction(
- () => !this.anchor1 || !this.anchor2,
- empty => empty && (this._hackToSeeIfDeleted = setTimeout(() => this._props.removeDocument?.(this.Document), 1000))
+ () => (!this.anchor1 || !this.anchor2) && this.DocumentView?.() && (!LightboxView.LightboxDoc || LightboxView.Contains(this.DocumentView!())),
+ empty => empty && ((this._hackToSeeIfDeleted = setTimeout(() =>
+ (!this.anchor1 || !this.anchor2) && this._props.removeDocument?.(this.Document)
+ )), 1000) // prettier-ignore
);
this._disposers.dragging = reaction(
- () => ({ drag: SnappingManager.IsDragging }),
- ({ drag }) => {
- !LightboxView.Contains(this.DocumentView?.()) &&
- setTimeout(
- // need to wait for drag manager to set 'hidden' flag on dragged DOM elements
- action(() => {
- const a = this.anchor1,
- b = this.anchor2;
- let a1 = a && document.getElementById(a.Guid);
- let a2 = b && document.getElementById(b.Guid);
- // test whether the anchors themselves are hidden,...
- if (!a1 || !a2 || (a?.ContentDiv as any)?.hidden || (b?.ContentDiv as any)?.hidden) this._hide = true;
- else {
- // .. or whether and of their DOM parents are hidden
- for (; a1 && !a1.hidden; a1 = a1.parentElement);
- for (; a2 && !a2.hidden; a2 = a2.parentElement);
- this._hide = a1 || a2 ? true : false;
- }
- })
- );
- }
+ () => SnappingManager.IsDragging,
+ () => setTimeout( action(() => {// need to wait for drag manager to set 'hidden' flag on dragged DOM elements
+ const a = this.anchor1,
+ b = this.anchor2;
+ let a1 = a && document.getElementById(a.ViewGuid);
+ let a2 = b && document.getElementById(b.ViewGuid);
+ // test whether the anchors themselves are hidden,...
+ if (!a1 || !a2 || (a?.ContentDiv as any)?.hidden || (b?.ContentDiv as any)?.hidden) this._hide = true;
+ else {
+ // .. or whether any of their DOM parents are hidden
+ for (; a1 && !a1.hidden; a1 = a1.parentElement);
+ for (; a2 && !a2.hidden; a2 = a2.parentElement);
+ this._hide = a1 || a2 ? true : false;
+ }
+ })) // prettier-ignore
);
}
@@ -84,7 +81,7 @@ export class LinkBox extends ViewBoxBaseComponent<FieldViewProps>() {
this._forceAnimate;
const docView = this._props.docViewPath().lastElement();
- if (a && b && !LightboxView.Contains(docView)) {
+ if (a && b) {
// text selection bounds are not directly observable, so we have to
// force an update when anything that could affect them changes (text edits causing reflow, scrolling)
a.Document[a.LayoutFieldKey];
@@ -104,7 +101,7 @@ export class LinkBox extends ViewBoxBaseComponent<FieldViewProps>() {
const getAnchor = (field: FieldResult): Element[] => {
const docField = DocCast(field);
const doc = docField?.layout_unrendered ? DocCast(docField.annotationOn, docField) : docField;
- const ele = document.getElementById(doc[Id]);
+ const ele = document.getElementById(DocumentView.UniquifyId(LightboxView.Contains(this.DocumentView?.()), doc[Id]));
if (ele?.className === 'linkBox-label') foundParent = true;
if (ele?.getBoundingClientRect().width) return [ele];
const eles = Array.from(document.getElementsByClassName(doc[Id])).filter(ele => ele?.getBoundingClientRect().width);
@@ -178,7 +175,7 @@ export class LinkBox extends ViewBoxBaseComponent<FieldViewProps>() {
color={color}
labels={
<div
- id={this.Document[Id]}
+ id={this.DocumentView?.().DocUniqueId}
className={'linkBox-label'}
style={{
borderRadius: '8px',