aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/new_fields')
-rw-r--r--src/new_fields/Doc.ts76
-rw-r--r--src/new_fields/RichTextUtils.ts37
-rw-r--r--src/new_fields/documentSchemas.ts22
3 files changed, 94 insertions, 41 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index b1c1fda05..447dbe3b0 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -14,7 +14,7 @@ import { ComputedField, ScriptField } from "./ScriptField";
import { BoolCast, Cast, FieldValue, NumCast, StrCast, ToConstructor } from "./Types";
import { deleteProperty, getField, getter, makeEditable, makeReadOnly, setter, updateFunction } from "./util";
import { intersectRect } from "../Utils";
-import { UndoManager } from "../client/util/UndoManager";
+import { UndoManager, undoBatch } from "../client/util/UndoManager";
import { computedFn } from "mobx-utils";
import { RichTextField } from "./RichTextField";
import { Script } from "vm";
@@ -178,12 +178,18 @@ export class Doc extends RefField {
private [SelfProxy]: any;
public [WidthSym] = () => NumCast(this[SelfProxy]._width);
public [HeightSym] = () => NumCast(this[SelfProxy]._height);
- public get [DataSym]() { return Cast(this[SelfProxy].resolvedDataDoc, Doc, null) || this[SelfProxy]; }
+ public get [DataSym]() { return Cast(Doc.Layout(this[SelfProxy]).resolvedDataDoc, Doc, null) || this[SelfProxy]; }
public get [LayoutSym]() { return this[SelfProxy].__LAYOUT__; }
@computed get __LAYOUT__() {
const templateLayoutDoc = Cast(Doc.LayoutField(this[SelfProxy]), Doc, null);
if (templateLayoutDoc) {
- const renderFieldKey = (templateLayoutDoc[StrCast(templateLayoutDoc.layoutKey, "layout")] as string).split("'")[1];
+ let renderFieldKey: any;
+ const layoutField = templateLayoutDoc[StrCast(templateLayoutDoc.layoutKey, "layout")];
+ if (typeof layoutField === "string") {
+ renderFieldKey = layoutField.split("'")[1];
+ } else {
+ return Cast(layoutField, Doc, null);
+ }
return Cast(this[SelfProxy][renderFieldKey + "-layout[" + templateLayoutDoc[Id] + "]"], Doc, null) || templateLayoutDoc;
}
return undefined;
@@ -488,6 +494,7 @@ export namespace Doc {
setTimeout(action(() => {
if (!targetDoc[expandedLayoutFieldKey]) {
const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]");
+ newLayoutDoc.lockedPosition = true;
newLayoutDoc.expandedTemplate = targetDoc;
targetDoc[expandedLayoutFieldKey] = newLayoutDoc;
const dataDoc = Doc.GetDataDoc(targetDoc);
@@ -608,8 +615,12 @@ export namespace Doc {
}
if (!Doc.AreProtosEqual(target[targetKey] as Doc, templateDoc)) {
- titleTarget && (Doc.GetProto(target).title = titleTarget);
- Doc.GetProto(target)[targetKey] = new PrefetchProxy(templateDoc);
+ if (target.resolvedDataDoc) {
+ target[targetKey] = new PrefetchProxy(templateDoc);
+ } else {
+ titleTarget && (Doc.GetProto(target).title = titleTarget);
+ Doc.GetProto(target)[targetKey] = new PrefetchProxy(templateDoc);
+ }
}
target.layoutKey = targetKey;
return target;
@@ -690,8 +701,11 @@ export namespace Doc {
}
// the document containing the view layout information - will be the Document itself unless the Document has
- // a layout field. In that case, all layout information comes from there unless overriden by Document
- export function Layout(doc: Doc): Doc { return doc[LayoutSym] || doc; }
+ // a layout field or 'layout' is given.
+ export function Layout(doc: Doc, layout?: Doc): Doc {
+ const overrideLayout = layout && Cast(doc["data-layout[" + layout[Id] + "]"], Doc, null);
+ return overrideLayout || doc[LayoutSym] || doc;
+ }
export function SetLayout(doc: Doc, layout: Doc | string) { doc[StrCast(doc.layoutKey, "layout")] = layout; }
export function LayoutField(doc: Doc) { return doc[StrCast(doc.layoutKey, "layout")]; }
export function LayoutFieldKey(doc: Doc): string { return StrCast(Doc.Layout(doc).layout).split("'")[1]; }
@@ -801,22 +815,57 @@ export namespace Doc {
const prevLayout = StrCast(doc.layoutKey).split("_")[1];
const deiconify = prevLayout === "icon" && StrCast(doc.deiconifyLayout) ? "layout_" + StrCast(doc.deiconifyLayout) : "";
doc.deiconifyLayout = undefined;
- if (StrCast(doc.title).endsWith("_" + prevLayout)) doc.title = StrCast(doc.title).replace("_" + prevLayout, "");
+ if (StrCast(doc.title).endsWith("_" + prevLayout) && deiconify) doc.title = StrCast(doc.title).replace("_" + prevLayout, deiconify);
+ else doc.title = undefined;
doc.layoutKey = deiconify || "layout";
}
- export function setDocFilter(container: Doc, key: string, value: any, modifiers?: string) {
- const docFilters = Cast(container._docFilter, listSpec("string"), []);
+ export function setDocFilterRange(target: Doc, key: string, range?: number[]) {
+ const docRangeFilters = Cast(target._docRangeFilters, listSpec("string"), []);
+ for (let i = 0; i < docRangeFilters.length; i += 3) {
+ if (docRangeFilters[i] === key) {
+ docRangeFilters.splice(i, 3);
+ break;
+ }
+ }
+ if (range !== undefined) {
+ docRangeFilters.push(key);
+ docRangeFilters.push(range[0].toString());
+ docRangeFilters.push(range[1].toString());
+ target._docRangeFilters = new List<string>(docRangeFilters);
+ }
+ }
+ export function setDocFilter(container: Doc, key: string, value: any, modifiers?: string | number) {
+ const docFilters = Cast(container._docFilters, listSpec("string"), []);
for (let i = 0; i < docFilters.length; i += 3) {
if (docFilters[i] === key && docFilters[i + 1] === value) {
docFilters.splice(i, 3);
break;
}
}
- if (modifiers !== undefined) {
+ if (typeof modifiers === "string") {
docFilters.push(key);
docFilters.push(value);
docFilters.push(modifiers);
- container._docFilter = new List<string>(docFilters);
+ container._docFilters = new List<string>(docFilters);
+ }
+ }
+ export function readDocRangeFilter(doc: Doc, key: string) {
+ const docRangeFilters = Cast(doc._docRangeFilters, listSpec("string"), []);
+ for (let i = 0; i < docRangeFilters.length; i += 3) {
+ if (docRangeFilters[i] === key) {
+ return [Number(docRangeFilters[i + 1]), Number(docRangeFilters[i + 2])];
+ }
+ }
+ }
+
+ @undoBatch
+ @action
+ export function freezeNativeDimensions(layoutDoc: Doc, width: number, height: number): void {
+ layoutDoc._autoHeight = false;
+ layoutDoc.ignoreAspect = false;
+ if (!layoutDoc.ignoreAspect && !layoutDoc._nativeWidth) {
+ layoutDoc._nativeWidth = NumCast(layoutDoc._width, width);
+ layoutDoc._nativeHeight = NumCast(layoutDoc._height, height);
}
}
}
@@ -843,4 +892,5 @@ Scripting.addGlobal(function selectedDocs(container: Doc, excludeCollections: bo
const docs = DocListCast(Doc.UserDoc().SelectedDocs).filter(d => !Doc.AreProtosEqual(d, container) && !d.annotationOn && d.type !== DocumentType.DOCUMENT && d.type !== DocumentType.KVP && (!excludeCollections || !Cast(d.data, listSpec(Doc), null)));
return docs.length ? new List(docs) : prevValue;
});
-Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: string) { Doc.setDocFilter(container, key, value, modifiers); }); \ No newline at end of file
+Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: string) { Doc.setDocFilter(container, key, value, modifiers); });
+Scripting.addGlobal(function setDocFilterRange(container: Doc, key: string, range: number[]) { Doc.setDocFilterRange(container, key, range); }); \ No newline at end of file
diff --git a/src/new_fields/RichTextUtils.ts b/src/new_fields/RichTextUtils.ts
index c50f8cc48..7c1fc39d8 100644
--- a/src/new_fields/RichTextUtils.ts
+++ b/src/new_fields/RichTextUtils.ts
@@ -1,5 +1,5 @@
import { EditorState, Transaction, TextSelection } from "prosemirror-state";
-import { Node, Fragment, Mark, MarkType } from "prosemirror-model";
+import { Node, Fragment, Mark } from "prosemirror-model";
import { RichTextField } from "./RichTextField";
import { docs_v1 } from "googleapis";
import { GoogleApiClientUtils } from "../client/apis/google_docs/GoogleApiClientUtils";
@@ -17,6 +17,7 @@ import { Id } from "./FieldSymbols";
import { DocumentView } from "../client/views/nodes/DocumentView";
import { AssertionError } from "assert";
import { Networking } from "../client/Network";
+import { extname } from "path";
export namespace RichTextUtils {
@@ -113,6 +114,7 @@ export namespace RichTextUtils {
width: number;
title: string;
url: string;
+ agnostic: string;
}
const parseInlineObjects = async (document: docs_v1.Schema$Document): Promise<Map<string, ImageTemplate>> => {
@@ -123,9 +125,7 @@ export namespace RichTextUtils {
const objects = Object.keys(inlineObjects).map(objectId => inlineObjects[objectId]);
const mediaItems: MediaItem[] = objects.map(object => {
const embeddedObject = object.inlineObjectProperties!.embeddedObject!;
- const baseUrl = embeddedObject.imageProperties!.contentUri!;
- const filename = `upload_${Utils.GenerateGuid()}.png`;
- return { baseUrl, filename };
+ return { baseUrl: embeddedObject.imageProperties!.contentUri! };
});
const uploads = await Networking.PostToServer("/googlePhotosMediaDownload", { mediaItems });
@@ -136,16 +136,17 @@ export namespace RichTextUtils {
for (let i = 0; i < objects.length; i++) {
const object = objects[i];
- const { fileNames } = uploads[i];
+ const { accessPaths } = uploads[i];
+ const { agnostic, _m } = accessPaths;
const embeddedObject = object.inlineObjectProperties!.embeddedObject!;
const size = embeddedObject.size!;
const width = size.width!.magnitude!;
- const url = Utils.fileUrl(fileNames.clean);
inlineObjectMap.set(object.objectId!, {
title: embeddedObject.title || `Imported Image from ${document.title}`,
width,
- url
+ url: Utils.prepend(_m.client),
+ agnostic: Utils.prepend(agnostic.client)
});
}
}
@@ -156,7 +157,6 @@ export namespace RichTextUtils {
interface MediaItem {
baseUrl: string;
- filename: string;
}
export const Import = async (documentId: GoogleApiClientUtils.Docs.DocumentId, textNote: Doc): Promise<Opt<GoogleApiClientUtils.Docs.ImportResult>> => {
@@ -268,19 +268,19 @@ export namespace RichTextUtils {
};
const imageNode = (schema: any, image: ImageTemplate, textNote: Doc) => {
- const { url: src, width } = image;
+ const { url: src, width, agnostic } = image;
let docid: string;
- const guid = Utils.GenerateDeterministicGuid(src);
+ const guid = Utils.GenerateDeterministicGuid(agnostic);
const backingDocId = StrCast(textNote[guid]);
if (!backingDocId) {
- const backingDoc = Docs.Create.ImageDocument(src, { _width: 300, _height: 300 });
+ const backingDoc = Docs.Create.ImageDocument(agnostic, { _width: 300, _height: 300 });
DocumentView.makeCustomViewClicked(backingDoc, undefined, Docs.Create.FreeformDocument);
docid = backingDoc[Id];
textNote[guid] = docid;
} else {
docid = backingDocId;
}
- return schema.node("image", { src, width, docid, float: null, location: "onRight" });
+ return schema.node("image", { src, agnostic, width, docid, float: null, location: "onRight" });
};
const textNode = (schema: any, run: docs_v1.Schema$TextRun) => {
@@ -436,7 +436,7 @@ export namespace RichTextUtils {
const width = attrs.width;
requests.push(await EncodeImage({
startIndex: position + nodeSize - 1,
- uri: attrs.src,
+ uri: attrs.agnostic,
width: Number(typeof width === "string" ? width.replace("px", "") : width)
}));
}
@@ -499,15 +499,18 @@ export namespace RichTextUtils {
};
};
- const EncodeImage = async (information: ImageInformation) => {
- const source = [Docs.Create.ImageDocument(information.uri)];
+ const EncodeImage = async ({ uri, width, startIndex }: ImageInformation) => {
+ if (!uri) {
+ return {};
+ }
+ const source = [Docs.Create.ImageDocument(uri)];
const baseUrls = await GooglePhotos.Transactions.UploadThenFetch(source);
if (baseUrls) {
return {
insertInlineImage: {
uri: baseUrls[0],
- objectSize: { width: { magnitude: information.width, unit: "PT" } },
- location: { index: information.startIndex }
+ objectSize: { width: { magnitude: width, unit: "PT" } },
+ location: { index: startIndex }
}
};
}
diff --git a/src/new_fields/documentSchemas.ts b/src/new_fields/documentSchemas.ts
index cb35c0681..aac6d4e3e 100644
--- a/src/new_fields/documentSchemas.ts
+++ b/src/new_fields/documentSchemas.ts
@@ -10,22 +10,24 @@ export const documentSchema = createSchema({
title: "string", // document title (can be on either data document or layout)
dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias" or "copy")
childDropAction: "string", // specify the override for what should happen when the child of a collection is dragged from it and dropped (can be "alias" or "copy")
- _nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set
- _nativeHeight: "number", // "
- _width: "number", // width of document in its container's coordinate system
- _height: "number", // "
+ _nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set
+ _nativeHeight: "number", // "
+ _width: "number", // width of document in its container's coordinate system
+ _height: "number", // "
_freeformLayoutEngine: "string",// the string ID for the layout engine to use to layout freeform view documents
- _LODdisable: "boolean", // whether to disbale LOD switching for CollectionFreeFormViews
+ _LODdisable: "boolean", // whether to disbale LOD switching for CollectionFreeFormViews
_pivotField: "string", // specifies which field should be used as the timeline/pivot axis
+ _replacedChrome: "string", // what the default chrome is replaced with. Currently only supports the value of 'replaced' for PresBox's.
+ _chromeStatus: "string", // determines the state of the collection chrome. values allowed are 'replaced', 'enabled', 'disabled', 'collapsed'
color: "string", // foreground color of document
backgroundColor: "string", // background color of document
opacity: "number", // opacity of document
- creationDate: DateField, // when the document was created
+ creationDate: DateField, // when the document was created
links: listSpec(Doc), // computed (readonly) list of links associated with this document
removeDropProperties: listSpec("string"), // properties that should be removed from the alias/copy/etc of this document when it is dropped
onClick: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop)
- onPointerDown: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop)
- onPointerUp: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop)
+ onPointerDown: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop)
+ onPointerUp: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop)
onDragStart: ScriptField, // script to run when document is dragged (without being selected). the script should return the Doc to be dropped.
dragFactory: Doc, // the document that serves as the "template" for the onDragStart script. ie, to drag out copies of the dragFactory document.
ignoreAspect: "boolean", // whether aspect ratio should be ignored when laying out or manipulating the document
@@ -36,9 +38,7 @@ export const documentSchema = createSchema({
treeViewOpen: "boolean", // flag denoting whether the documents sub-tree (contents) is visible or hidden
treeViewExpandedView: "string", // name of field whose contents are being displayed as the document's subtree
preventTreeViewOpen: "boolean", // ignores the treeViewOpen flag (for allowing a view to not be slaved to other views of the document)
- currentTimecode: "number", // current play back time of a temporal document (video / audio)
- summarizedDocs: listSpec(Doc), // documents that are summarized by this document (and which will typically be opened by clicking this document)
- maximizedDocs: listSpec(Doc), // documents to maximize when clicking this document (generally this document will be an icon)
+ currentTimecode: "number", // current play back time of a temporal document (video / audio)
maximizeLocation: "string", // flag for where to place content when following a click interaction (e.g., onRight, inPlace, inTab)
lockedPosition: "boolean", // whether the document can be moved (dragged)
lockedTransform: "boolean", // whether the document can be panned/zoomed