aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-07-29 09:46:31 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-07-29 09:46:31 -0400
commit57c07152904762c790e3a3bb2003d389983990d8 (patch)
tree159efabfbafd2a1334f494436eab4dfac5b4c88e
parente3ead6afe43ce24caf58382bcb5fad294750dfa4 (diff)
streamlined settin link follow tarets a bit by addin a follow link draggable UI button
-rw-r--r--src/client/views/collections/CollectionMenu.tsx19
-rw-r--r--src/fields/ScriptField.ts4
2 files changed, 22 insertions, 1 deletions
diff --git a/src/client/views/collections/CollectionMenu.tsx b/src/client/views/collections/CollectionMenu.tsx
index 47670eb26..3eda2e2f2 100644
--- a/src/client/views/collections/CollectionMenu.tsx
+++ b/src/client/views/collections/CollectionMenu.tsx
@@ -25,6 +25,7 @@ import { SelectionManager } from "../../util/SelectionManager";
import { DocumentView } from "../nodes/DocumentView";
import { ColorState } from "react-color";
import { ObjectField } from "../../../fields/ObjectField";
+import { ScriptField } from "../../../fields/ScriptField";
@observer
export default class CollectionMenu extends AntimodeMenu {
@@ -116,6 +117,22 @@ export class CollectionViewBaseChrome extends React.Component<CollectionMenuProp
immediate: undoBatch((source: Doc[]) => { }),
initialize: emptyFunction,
};
+ _openLinkInCommand = {
+ params: ["target", "container"], title: "link follow target",
+ script: `{ if (self.container?.length) {
+ getProto(self.target).linkContainer = self.container[0];
+ getProto(self.target).isLinkButton = true;
+ getProto(self.target).onClick = makeScript("getProto(self.linkContainer).data = new List([self.links[0]?.anchor2])");
+ }}`,
+ immediate: undoBatch((container: Doc[]) => {
+ if (container.length) {
+ Doc.GetProto(this.target).linkContainer = container[0];
+ Doc.GetProto(this.target).isLinkButton = true;
+ Doc.GetProto(this.target).onClick = ScriptField.MakeScript("getProto(self.linkContainer).data = new List([self.links[0]?.anchor2])");
+ }
+ }),
+ initialize: emptyFunction,
+ };
_viewCommand = {
params: ["target"], title: "bookmark view",
script: "self.target._panX = self['target-panX']; self.target._panY = self['target-panY']; self.target._viewScale = self['target-viewScale'];",
@@ -145,7 +162,7 @@ export class CollectionViewBaseChrome extends React.Component<CollectionMenuProp
_stacking_commands = [this._contentCommand, this._templateCommand];
_masonry_commands = [this._contentCommand, this._templateCommand];
_schema_commands = [this._templateCommand, this._narrativeCommand];
- _doc_commands = [this._onClickCommand];
+ _doc_commands = [this._openLinkInCommand, this._onClickCommand];
_tree_commands = [];
private get _buttonizableCommands() {
switch (this.props.type) {
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index bd08b2f32..f55483a5b 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -183,6 +183,10 @@ Scripting.addGlobal(function getIndexVal(list: any[], index: number) {
return list.reduce((p, x, i) => (i <= index && x !== undefined) || p === undefined ? x : p, undefined as any);
}, "returns the value at a given index of a list", "(list: any[], index: number)");
+Scripting.addGlobal(function makeScript(script: string) {
+ return ScriptField.MakeScript(script);
+}, "returns the value at a given index of a list", "(list: any[], index: number)");
+
export namespace ComputedField {
let useComputed = true;
export function DisableComputedFields() {