aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/DocumentDecorations.tsx
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-06-28 14:28:47 -0400
committerbob <bcz@cs.brown.edu>2019-06-28 14:28:47 -0400
commit09042b933c843d24a715e8c58414976133b19e41 (patch)
tree9fc983041c0a37763cf18c52f265f8a0bee238e7 /src/client/views/DocumentDecorations.tsx
parentdc4b658639beb21e73fc2411abd147ff6716ba3d (diff)
fixed template application to create expanded documents
Diffstat (limited to 'src/client/views/DocumentDecorations.tsx')
-rw-r--r--src/client/views/DocumentDecorations.tsx55
1 files changed, 24 insertions, 31 deletions
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx
index fdfff86db..76c2d71e8 100644
--- a/src/client/views/DocumentDecorations.tsx
+++ b/src/client/views/DocumentDecorations.tsx
@@ -26,6 +26,7 @@ import { Template, Templates } from "./Templates";
import React = require("react");
import { RichTextField } from '../../new_fields/RichTextField';
import { LinkManager } from '../util/LinkManager';
+import { ObjectField } from '../../new_fields/ObjectField';
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;
@@ -77,39 +78,31 @@ export class DocumentDecorations extends React.Component<{}, { value: string }>
this._fieldKey = text.slice(1, text.length);
this._title = this.selectionTitle;
} else if (text.startsWith(">")) {
- let field = SelectionManager.SelectedDocuments()[0];
- let collection = field.props.ContainingCollectionView!.props.Document;
-
- let collectionKey = field.props.ContainingCollectionView!.props.fieldKey;
- let collectionKeyProp = `fieldKey={"${collectionKey}"}`;
+ let fieldTemplateView = SelectionManager.SelectedDocuments()[0];
+ SelectionManager.DeselectAll();
+ let fieldTemplate = fieldTemplateView.props.Document;
+ let docTemplate = fieldTemplateView.props.ContainingCollectionView!.props.Document;
let metaKey = text.slice(1, text.length);
- let metaKeyProp = `fieldKey={"${metaKey}"}`;
-
- let layoutProto = Doc.GetProto(field.props.Document);
- let template = Doc.MakeAlias(field.props.Document);
- template.proto = collection;
- template.title = metaKey;
- template.nativeWidth = Cast(field.nativeWidth, "number");
- template.nativeHeight = Cast(field.nativeHeight, "number");
- template.width = NumCast(field.props.Document.width);
- template.height = NumCast(field.props.Document.height);
- template.panX = NumCast(field.props.Document.panX);
- template.panY = NumCast(field.props.Document.panY);
- template.x = NumCast(field.props.Document.x);
- template.y = NumCast(field.props.Document.y);
- template.embed = true;
- template.isTemplate = true;
- template.templates = new List<string>([Templates.TitleBar(metaKey)]);
- if (field.props.Document.backgroundLayout) {
- let metaAnoKeyProp = `fieldKey={"${metaKey}"} fieldExt={"annotations"}`;
- let collectionAnoKeyProp = `fieldKey={"annotations"}`;
- template.layout = StrCast(field.props.Document.layout).replace(collectionAnoKeyProp, metaAnoKeyProp);
- template.backgroundLayout = StrCast(field.props.Document.backgroundLayout).replace(collectionKeyProp, metaKeyProp);
- } else {
- template.layout = StrCast(field.props.Document.layout).replace(collectionKeyProp, metaKeyProp);
+
+ // move data doc fields to layout doc as needed (nativeWidth/nativeHeight, data, ??)
+ let backgroundLayout = StrCast(fieldTemplate.backgroundLayout);
+ let layout = StrCast(fieldTemplate.layout).replace(/fieldKey={"[^"]*"}/, `fieldKey={"${metaKey}"}`);
+ if (backgroundLayout) {
+ layout = StrCast(fieldTemplate.layout).replace(/fieldKey={"annotations"}/, `fieldKey={"${metaKey}"} fieldExt={"annotations"}`);
+ backgroundLayout = backgroundLayout.replace(/fieldKey={"[^"]*"}/, `fieldKey={"${metaKey}"}`);
}
- Doc.AddDocToList(collection, collectionKey, template);
- SelectionManager.SelectedDocuments().map(dv => dv.props.removeDocument && dv.props.removeDocument(dv.props.Document));
+ let nw = Cast(fieldTemplate.nativeWidth, "number");
+ let nh = Cast(fieldTemplate.nativeHeight, "number");
+
+ fieldTemplate.title = metaKey;
+ fieldTemplate.layout = layout;
+ fieldTemplate.backgroundLayout = backgroundLayout;
+ fieldTemplate.nativeWidth = nw;
+ fieldTemplate.nativeHeight = nh;
+ fieldTemplate.embed = true;
+ fieldTemplate.isTemplate = true;
+ fieldTemplate.templates = new List<string>([Templates.TitleBar(metaKey)]);
+ fieldTemplate.proto = Doc.GetProto(docTemplate);
}
else {
if (SelectionManager.SelectedDocuments().length > 0) {