aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-05-04 12:22:04 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-05-04 12:22:04 +0530
commit95ec58135f3534640afc0a38d8c4bbbb84bc3434 (patch)
tree2b04fb11d2f821155668c4ebcec3a86229a01acb /src/new_fields
parenta2eb8ba283ce4a8fb7f423a9198e2a5778eba886 (diff)
parent1027f0b2e40df0ca13dfa2db97f278e804dadb68 (diff)
finishing merge
Diffstat (limited to 'src/new_fields')
-rw-r--r--src/new_fields/Doc.ts35
-rw-r--r--src/new_fields/RichTextUtils.ts12
-rw-r--r--src/new_fields/Types.ts4
-rw-r--r--src/new_fields/documentSchemas.ts98
4 files changed, 88 insertions, 61 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 337274774..9efb14d03 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -183,7 +183,7 @@ export class Doc extends RefField {
let renderFieldKey: any;
const layoutField = templateLayoutDoc[StrCast(templateLayoutDoc.layoutKey, "layout")];
if (typeof layoutField === "string") {
- renderFieldKey = layoutField.split("'")[1];
+ renderFieldKey = layoutField.split("fieldKey={'")[1].split("'")[0];//layoutField.split("'")[1];
} else {
return Cast(layoutField, Doc, null);
}
@@ -254,6 +254,7 @@ export namespace Doc {
// return Cast(field, ctor);
// });
// }
+
export function RunCachedUpdate(doc: Doc, field: string) {
const update = doc[CachedUpdates][field];
if (update) {
@@ -291,6 +292,9 @@ export namespace Doc {
export function IsPrototype(doc: Doc) {
return GetT(doc, "isPrototype", "boolean", true);
}
+ export function IsBaseProto(doc: Doc) {
+ return GetT(doc, "baseProto", "boolean", true);
+ }
export async function SetInPlace(doc: Doc, key: string, value: Field | undefined, defaultProto: boolean) {
const hasProto = doc.proto instanceof Doc;
const onDeleg = Object.getOwnPropertyNames(doc).indexOf(key) !== -1;
@@ -580,30 +584,44 @@ export namespace Doc {
return copy;
}
- export function MakeClone(doc: Doc, cloneProto: boolean = true): Doc {
+ export function MakeClone(doc: Doc, cloneMap: Map<Doc, Doc> = new Map()): Doc {
+ if (Doc.IsBaseProto(doc)) return doc;
+ if (cloneMap.get(doc)) return cloneMap.get(doc)!;
const copy = new Doc(undefined, true);
+ cloneMap.set(doc, copy);
const exclude = Cast(doc.excludeFields, listSpec("string"), []);
Object.keys(doc).forEach(key => {
if (exclude.includes(key)) return;
const cfield = ComputedField.WithoutComputed(() => FieldValue(doc[key]));
const field = ProxyField.WithoutProxy(() => doc[key]);
- if (key === "proto" && cloneProto) {
+ if (key === "proto") {
if (doc[key] instanceof Doc) {
- copy[key] = Doc.MakeClone(doc[key]!, false);
+ copy[key] = Doc.MakeClone(doc[key]!, cloneMap);
}
} else {
if (field instanceof RefField) {
copy[key] = field;
} else if (cfield instanceof ComputedField) {
copy[key] = ComputedField.MakeFunction(cfield.script.originalScript);
+ if (field instanceof ObjectField) {
+ const list = Cast(doc[key], listSpec(Doc));
+ if (list !== undefined && !(list instanceof Promise)) {
+ copy[key] = new List<Doc>(list.filter(d => d instanceof Doc).map(d => Doc.MakeClone(d as Doc, cloneMap)));
+ } else {
+ copy[key] = doc[key] instanceof Doc ?
+ key.includes("layout[") ?
+ undefined : Doc.MakeClone(doc[key] as Doc, cloneMap) : // reference documents except copy documents that are expanded teplate fields
+ ObjectField.MakeCopy(field);
+ }
+ }
} else if (field instanceof ObjectField) {
const list = Cast(doc[key], listSpec(Doc));
if (list !== undefined && !(list instanceof Promise)) {
- copy[key] = new List<Doc>(list.filter(d => d instanceof Doc).map(d => Doc.MakeCopy(d as Doc, false)));
+ copy[key] = new List<Doc>(list.filter(d => d instanceof Doc).map(d => Doc.MakeClone(d as Doc, cloneMap)));
} else {
copy[key] = doc[key] instanceof Doc ?
key.includes("layout[") ?
- Doc.MakeCopy(doc[key] as Doc, false) : doc[key] : // reference documents except copy documents that are expanded teplate fields
+ undefined : Doc.MakeClone(doc[key] as Doc, cloneMap) : // reference documents except copy documents that are expanded teplate fields
ObjectField.MakeCopy(field);
}
} else if (field instanceof Promise) {
@@ -615,6 +633,7 @@ export namespace Doc {
});
Doc.SetInPlace(copy, "title", "CLONE: " + doc.title, true);
copy.cloneOf = doc;
+ cloneMap.set(doc, copy);
return copy;
}
@@ -771,7 +790,7 @@ export namespace Doc {
export function LinkOtherAnchor(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? Cast(linkDoc.anchor2, Doc) as Doc : Cast(linkDoc.anchor1, Doc) as Doc; }
- export function LinkEndpoint(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? "layout_key1" : "layout_key2"; }
+ export function LinkEndpoint(linkDoc: Doc, anchorDoc: Doc) { return Doc.AreProtosEqual(anchorDoc, Cast(linkDoc.anchor1, Doc) as Doc) ? "1" : "2"; }
export function linkFollowUnhighlight() {
Doc.UnhighlightAll();
@@ -996,7 +1015,7 @@ export namespace Doc {
//newCollection.borderRounding = "40px";
newCollection._jitterRotation = 10;
newCollection._backgroundColor = "gray";
- newCollection.overflow = "visible";
+ newCollection._overflow = "visible";
return newCollection;
}
diff --git a/src/new_fields/RichTextUtils.ts b/src/new_fields/RichTextUtils.ts
index 635fd053d..c475d0d73 100644
--- a/src/new_fields/RichTextUtils.ts
+++ b/src/new_fields/RichTextUtils.ts
@@ -2,20 +2,20 @@ import { AssertionError } from "assert";
import { docs_v1 } from "googleapis";
import { Fragment, Mark, Node } from "prosemirror-model";
import { sinkListItem } from "prosemirror-schema-list";
-import { EditorState, TextSelection, Transaction } from "prosemirror-state";
-import { GoogleApiClientUtils } from "../client/apis/google_docs/GoogleApiClientUtils";
+import { Utils } from "../Utils";
+import { Docs } from "../client/documents/Documents";
+import { schema } from "../client/views/nodes/formattedText/schema_rts";
import { GooglePhotos } from "../client/apis/google_docs/GooglePhotosClientUtils";
import { DocServer } from "../client/DocServer";
-import { Docs } from "../client/documents/Documents";
import { Networking } from "../client/Network";
-import { schema } from "../client/util/RichTextSchema";
-import { FormattedTextBox } from "../client/views/nodes/FormattedTextBox";
-import { Utils } from "../Utils";
+import { FormattedTextBox } from "../client/views/nodes/formattedText/FormattedTextBox";
import { Doc, Opt } from "./Doc";
import { Id } from "./FieldSymbols";
import { RichTextField } from "./RichTextField";
import { Cast, StrCast } from "./Types";
import Color = require('color');
+import { EditorState, TextSelection, Transaction } from "prosemirror-state";
+import { GoogleApiClientUtils } from "../client/apis/google_docs/GoogleApiClientUtils";
export namespace RichTextUtils {
diff --git a/src/new_fields/Types.ts b/src/new_fields/Types.ts
index aa44cefa0..3d784448d 100644
--- a/src/new_fields/Types.ts
+++ b/src/new_fields/Types.ts
@@ -88,8 +88,8 @@ export function DateCast(field: FieldResult) {
return Cast(field, DateField, null);
}
-export function ScriptCast(field: FieldResult) {
- return Cast(field, ScriptField, null);
+export function ScriptCast(field: FieldResult, defaultVal: ScriptField | null = null) {
+ return Cast(field, ScriptField, defaultVal);
}
type WithoutList<T extends Field> = T extends List<infer R> ? (R extends RefField ? (R | Promise<R>)[] : R[]) : T;
diff --git a/src/new_fields/documentSchemas.ts b/src/new_fields/documentSchemas.ts
index 7a0be8863..e7d27d81e 100644
--- a/src/new_fields/documentSchemas.ts
+++ b/src/new_fields/documentSchemas.ts
@@ -4,13 +4,25 @@ import { Doc } from "./Doc";
import { DateField } from "./DateField";
export const documentSchema = createSchema({
+ // content properties
type: "string", // enumerated type of document -- should be template-specific (ie, start with an '_')
- layout: "string", // this is the native layout string for the document. templates can be added using other fields and setting layoutKey below
- layoutKey: "string", // holds the field key for the field that actually holds the current lyoat
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", "copy", "move")
- targetDropAction: "string", // allows the target of a drop event to specify the dropAction ("alias", "copy", "move")
- 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")
+ isTemplateForField: "string",// if specified, it indicates the document is a template that renders the specified field
+ creationDate: DateField, // when the document was created
+ links: listSpec(Doc), // computed (readonly) list of links associated with this document
+
+ // "Location" properties in a very general sense
+ currentTimecode: "number", // current play back time of a temporal document (video / audio)
+ displayTimecode: "number", // the time that a document should be displayed (e.g., time an annotation should be displayed on a video)
+ inOverlay: "boolean", // whether the document is rendered in an OverlayView which handles selection/dragging differently
+ x: "number", // x coordinate when in a freeform view
+ y: "number", // y coordinate when in a freeform view
+ z: "number", // z "coordinate" - non-zero specifies the overlay layer of a freeformview
+ zIndex: "number", // zIndex of a document in a freeform view
+ scrollY: "number", // "command" to scroll a document to a position on load (the value will be reset to 0 after that )
+ scrollTop: "number", // scroll position of a scrollable document (pdf, text, web)
+
+ // appearance properties on the layout
_autoHeight: "boolean", // whether the height of the document should be computed automatically based on its contents
_nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set
_nativeHeight: "number", // "
@@ -20,72 +32,68 @@ export const documentSchema = createSchema({
_yPadding: "number", // pixels of padding on top/bottom of collectionfreeformview contents when fitToBox is set
_xMargin: "number", // margin added on left/right of most documents to add separation from their container
_yMargin: "number", // margin added on top/bottom of most documents to add separation from their container
+ _overflow: "string", // sets overflow behvavior for CollectionFreeForm views
_showCaption: "string", // whether editable caption text is overlayed at the bottom of the document
_showTitle: "string", // the fieldkey whose contents should be displayed at the top of the document
_showTitleHover: "string", // the showTitle should be shown only on hover
_showAudio: "boolean", // whether to show the audio record icon on documents
_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
- _pivotField: "string", // specifies which field should be used as the timeline/pivot axis
+ _pivotField: "string", // specifies which field key 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'
- _freezeChildDimensions: "boolean", // freezes child document dimensions (e.g., used by time/pivot view to make sure all children will be scaled to fit their display rectangle)
_fontSize: "number",
_fontFamily: "string",
- isInPlaceContainer: "boolean",// whether the marked object will display addDocTab() calls that target "inPlace" destinations
- color: "string", // foreground color of document
+
+ // appearance properties on the data document
backgroundColor: "string", // background color of document
+ borderRounding: "string", // border radius rounding of document
+ boxShadow: "string", // the amount of shadow around the perimeter of a document
+ color: "string", // foreground color of document
+ fitToBox: "boolean", // whether freeform view contents should be zoomed/panned to fill the area of the document view
+ fontSize: "string",
+ layout: "string", // this is the native layout string for the document. templates can be added using other fields and setting layoutKey below
+ layoutKey: "string", // holds the field key for the field that actually holds the current lyoat
+ letterSpacing: "string",
opacity: "number", // opacity of document
- overflow: "string", // sets overflow behvavior for CollectionFreeForm views
- creationDate: DateField, // when the document was created
- links: listSpec(Doc), // computed (readonly) list of links associated with this document
+ strokeWidth: "number",
+ textTransform: "string",
+ 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
+ treeViewPreventOpen: "boolean", // ignores the treeViewOpen flag (for allowing a view to not be slaved to other views of the document)
+
+ // interaction and linking properties
+ ignoreClick: "boolean", // whether documents ignores input clicks (but does not ignore manipulation and other events)
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)
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.
- removeDropProperties: listSpec("string"), // properties that should be removed from the alias/copy/etc of this document when it is dropped
- isTemplateForField: "string",// when specifies a field key, then the containing document is a template that renders the specified field
- isBackground: "boolean", // whether document is a background element and ignores input events (can only selet with marquee)
- 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
- treeViewPreventOpen: "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)
followLinkLocation: "string",// flag for where to place content when following a click interaction (e.g., onRight, inPlace, inTab, )
+ isInPlaceContainer: "boolean",// whether the marked object will display addDocTab() calls that target "inPlace" destinations
+ isLinkButton: "boolean", // whether document functions as a link follow button to follow the first link on the document when clicked
+ isBackground: "boolean", // whether document is a background element and ignores input events (can only select with marquee)
lockedPosition: "boolean", // whether the document can be moved (dragged)
lockedTransform: "boolean", // whether the document can be panned/zoomed
- inOverlay: "boolean", // whether the document is rendered in an OverlayView which handles selection/dragging differently
- borderRounding: "string", // border radius rounding of document
- heading: "number", // the logical layout 'heading' of this document (used by rule provider to stylize h1 header elements, from h2, etc)
- isLinkButton: "boolean", // whether document functions as a link follow button to follow the first link on the document when clicked
- ignoreClick: "boolean", // whether documents ignores input clicks (but does not ignore manipulation and other events)
- scrollToLinkID: "string", // id of link being traversed. allows this doc to scroll/highlight/etc its link anchor. scrollToLinkID should be set to undefined by this doc after it sets up its scroll,etc.
- scrollY: "number", // "command" to scroll a document to a position on load (the value will be reset to 0 after that )
- scrollTop: "number", // scroll position of a scrollable document (pdf, text, web)
- strokeWidth: "number",
- fontSize: "string",
- fitToBox: "boolean", // whether freeform view contents should be zoomed/panned to fill the area of the document view
- letterSpacing: "string",
- textTransform: "string",
- childTemplateName: "string" // the name of a template to use to override the layoutKey when rendering a document in DocHolderBox
-});
-export const positionSchema = createSchema({
- zIndex: "number",
- x: "number",
- y: "number",
- z: "number",
+ // drag drop properties
+ dragFactory: Doc, // the document that serves as the "template" for the onDragStart script. ie, to drag out copies of the dragFactory document.
+ dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias", "copy", "move")
+ targetDropAction: "string", // allows the target of a drop event to specify the dropAction ("alias", "copy", "move") NOTE: if the document is dropped within the same collection, the dropAction is coerced to 'move'
+ 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")
+ removeDropProperties: listSpec("string"), // properties that should be removed from the alias/copy/etc of this document when it is dropped
});
+
export const collectionSchema = createSchema({
- childLayout: Doc, // layout template for children of a collecion
- childDetailView: Doc, // layout template to apply to a child when its clicked on in a collection and opened (requires onChildClick or other script to use this field)
+ childLayoutTemplateName: "string", // the name of a template to use to override the layoutKey when rendering a document -- ONLY used in DocHolderBox
+ childLayoutTemplate: Doc, // layout template to use to render children of a collecion
+ childLayoutString: "string", //layout string to use to render children of a collection
+ childClickedOpenTemplateView: Doc, // layout template to apply to a child when its clicked on in a collection and opened (requires onChildClick or other script to read this value and apply template)
+ dontRegisterChildViews: "boolean", // whether views made of this document are registered so that they can be found when drawing links scrollToLinkID: "string", // id of link being traversed. allows this doc to scroll/highlight/etc its link anchor. scrollToLinkID should be set to undefined by this doc after it sets up its scroll,etc.
onChildClick: ScriptField, // script to run for each child when its clicked
+ onChildDoubleClick: ScriptField, // script to run for each child when its clicked
onCheckedClick: ScriptField, // script to run when a checkbox is clicked next to a child in a tree view
});
export type Document = makeInterface<[typeof documentSchema]>;
export const Document = makeInterface(documentSchema);
-
-export type PositionDocument = makeInterface<[typeof documentSchema, typeof positionSchema]>;
-export const PositionDocument = makeInterface(documentSchema, positionSchema);