diff options
-rw-r--r-- | src/client/documents/Documents.ts | 29 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 2 | ||||
-rw-r--r-- | src/client/views/collections/CollectionFreeFormView.tsx | 12 | ||||
-rw-r--r-- | src/client/views/collections/CollectionViewBase.tsx | 16 |
4 files changed, 42 insertions, 17 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index cc8052d44..d7bc2e3b0 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -59,12 +59,6 @@ export namespace Documents { }); } function assignOptions(doc: Document, options: DocumentOptions): Document { - if (options.x !== undefined) { doc.SetNumber(KeyStore.X, options.x); } - if (options.y !== undefined) { doc.SetNumber(KeyStore.Y, options.y); } - if (options.width !== undefined) { doc.SetNumber(KeyStore.Width, options.width); } - if (options.height !== undefined) { doc.SetNumber(KeyStore.Height, options.height); } - if (options.nativeWidth !== undefined) { doc.SetNumber(KeyStore.NativeWidth, options.nativeWidth); } - if (options.nativeHeight !== undefined) { doc.SetNumber(KeyStore.NativeHeight, options.nativeHeight); } if (options.title !== undefined) { doc.SetText(KeyStore.Title, options.title); } if (options.panx !== undefined) { doc.SetNumber(KeyStore.PanX, options.panx); } if (options.pany !== undefined) { doc.SetNumber(KeyStore.PanY, options.pany); } @@ -74,6 +68,15 @@ export namespace Documents { if (options.layoutKeys !== undefined) { doc.Set(KeyStore.LayoutKeys, new ListField(options.layoutKeys)); } return doc; } + + function assignToDelegate(doc: Document, options: DocumentOptions): Document { + if (options.x !== undefined) { doc.SetNumber(KeyStore.X, options.x); } + if (options.y !== undefined) { doc.SetNumber(KeyStore.Y, options.y); } + if (options.width !== undefined) { doc.SetNumber(KeyStore.Width, options.width); } + if (options.height !== undefined) { doc.SetNumber(KeyStore.Height, options.height); } + return doc + } + function setupPrototypeOptions(protoId: string, title: string, layout: string, options: DocumentOptions): Document { return assignOptions(new Document(protoId), { ...options, title: title, layout: layout }); } @@ -130,8 +133,9 @@ export namespace Documents { doc.SetText(KeyStore.OverlayLayout, FixedCaption()); return doc.MakeDelegate(); } + export function TextDocument(options: DocumentOptions = {}) { - return SetInstanceOptions(GetTextPrototype(), options, "", TextField).MakeDelegate() + return assignToDelegate(SetInstanceOptions(GetTextPrototype(), options, "", TextField).MakeDelegate(), options); } export function PdfDocument(url: string, options: DocumentOptions = {}) { return SetInstanceOptions(GetPdfPrototype(), options, new URL(url), PDFField).MakeDelegate(); @@ -142,19 +146,22 @@ export namespace Documents { export function HtmlDocument(html: string, options: DocumentOptions = {}) { return SetInstanceOptions(GetWebPrototype(), options, html, HtmlField).MakeDelegate(); } - export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string) { + export function FreeformDocument(documents: Array<Document>, options: DocumentOptions, id?: string, makePrototype: boolean = true) { + if (!makePrototype) { + return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, documents, ListField, id) + } return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Freeform }, documents, ListField, id).MakeDelegate() } export function SchemaDocument(documents: Array<Document>, options: DocumentOptions, id?: string) { - return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, documents, ListField, id).MakeDelegate() + return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Schema }, documents, ListField, id) } export function DockDocument(config: string, options: DocumentOptions, id?: string) { - return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, config, TextField, id).MakeDelegate() + return SetInstanceOptions(GetCollectionPrototype(), { ...options, viewType: CollectionViewType.Docking }, config, TextField, id) } export function KVPDocument(document: Document, options: DocumentOptions = {}, id?: string) { var deleg = GetKVPPrototype().MakeDelegate(id); deleg.Set(KeyStore.Data, document); - return assignOptions(deleg, options); + return assignToDelegate(assignOptions(deleg, options).MakeDelegate(), options); } // example of custom display string for an image that shows a caption. diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index c9bdc24c2..020f49528 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -43,7 +43,7 @@ Documents.initProtos(mainDocId, (res?: Document) => { // bcz: strangely, we need a timeout to prevent exceptions/issues initializing GoldenLayout (the rendering engine for Main Container) setTimeout(() => { - mainfreeform = Documents.FreeformDocument([], { x: 0, y: 400, title: "mini collection" }); + mainfreeform = Documents.FreeformDocument([], { x: 0, y: 400, title: "mini collection" }, undefined, false); var dockingLayout = { content: [{ type: 'row', content: [CollectionDockingView.makeDocumentConfig(mainfreeform)] }] }; mainContainer.SetText(KeyStore.Data, JSON.stringify(dockingLayout)); diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx index 95b4f6f19..ea00ce751 100644 --- a/src/client/views/collections/CollectionFreeFormView.tsx +++ b/src/client/views/collections/CollectionFreeFormView.tsx @@ -59,17 +59,23 @@ export class CollectionFreeFormView extends CollectionViewBase { drop = (e: Event, de: DragManager.DropEvent) => { super.drop(e, de); + let screenX = de.x - (de.data["xOffset"] as number || 0); + let screenY = de.y - (de.data["yOffset"] as number || 0); + const [x, y] = this.getTransform().transformPoint(screenX, screenY); if (!de.data["alias"]) { const docView: DocumentView = de.data["documentView"]; const doc = docView ? docView.props.Document : de.data["document"] //this should be able to use translate and scale methods on an Identity transform, no? - let screenX = de.x - (de.data["xOffset"] as number || 0); - let screenY = de.y - (de.data["yOffset"] as number || 0); - const [x, y] = this.getTransform().transformPoint(screenX, screenY); doc.SetNumber(KeyStore.X, x); doc.SetNumber(KeyStore.Y, y); this.bringToFront(doc); } + else { + let newDoc: Document = de.data["newDoc"] + newDoc.SetNumber(KeyStore.X, x) + newDoc.SetNumber(KeyStore.Y, y) + this.bringToFront(newDoc) + } } @action diff --git a/src/client/views/collections/CollectionViewBase.tsx b/src/client/views/collections/CollectionViewBase.tsx index f3770056d..a662447cf 100644 --- a/src/client/views/collections/CollectionViewBase.tsx +++ b/src/client/views/collections/CollectionViewBase.tsx @@ -3,7 +3,7 @@ import { Document } from "../../../fields/Document"; import { ListField } from "../../../fields/ListField"; import React = require("react"); import { KeyStore } from "../../../fields/KeyStore"; -import { FieldWaiting } from "../../../fields/Field"; +import { FieldWaiting, Field } from "../../../fields/Field"; import { undoBatch } from "../../util/UndoManager"; import { DragManager } from "../../util/DragManager"; import { DocumentView } from "../nodes/DocumentView"; @@ -47,11 +47,23 @@ export class CollectionViewBase extends React.Component<SubCollectionViewProps> protected drop(e: Event, de: DragManager.DropEvent) { const docView: DocumentView = de.data["documentView"]; const doc: Document = de.data["document"] + if (de.data["alias"]) { + let newDoc = docView ? docView.props.Document.CreateAlias() : doc.CreateAlias() + de.data["newDoc"] = newDoc + let oldDoc = docView ? docView.props.Document : doc + oldDoc.GetAsync(KeyStore.Width, (f: Field) => { + newDoc.Set(KeyStore.Width, f) + }) + oldDoc.GetAsync(KeyStore.Height, (f: Field) => { + newDoc.Set(KeyStore.Height, f) + }) + } + if (docView && docView.props.ContainingCollectionView && docView.props.ContainingCollectionView !== this.props.CollectionView) { if (docView.props.RemoveDocument && !de.data["alias"]) { docView.props.RemoveDocument(docView.props.Document) } - this.props.addDocument(de.data["alias"] ? docView.props.Document.CreateAlias() : docView.props.Document) + this.props.addDocument(de.data["alias"] ? de.data["newDoc"] : docView.props.Document) } else if (doc) { if (!de.data["alias"]) { this.props.removeDocument(doc) |