diff options
| -rw-r--r-- | src/client/DocServer.ts | 4 | ||||
| -rw-r--r-- | src/client/util/Import & Export/DirectoryImportBox.tsx | 1 | ||||
| -rw-r--r-- | src/client/views/collections/CollectionSubView.tsx | 9 | ||||
| -rw-r--r-- | src/client/views/nodes/KeyValueBox.tsx | 81 |
4 files changed, 66 insertions, 29 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index cbcf751ee..652a9b701 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -12,7 +12,9 @@ export namespace DocServer { const GUID: string = Utils.GenerateGuid(); export function makeReadOnly() { - _CreateField = emptyFunction; + _CreateField = field => { + _cache[field[Id]] = field; + }; _UpdateField = emptyFunction; _respondToUpdate = emptyFunction; } diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx index 1a939882c..ce95ba90e 100644 --- a/src/client/util/Import & Export/DirectoryImportBox.tsx +++ b/src/client/util/Import & Export/DirectoryImportBox.tsx @@ -79,7 +79,6 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps> let validated: File[] = []; for (let i = 0; i < files.length; i++) { let file = files.item(i); - console.log(file); file && !unsupported.includes(file.type) && validated.push(file); } diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index bf17088ae..a8810f336 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -19,6 +19,7 @@ import { CollectionPDFView } from "./CollectionPDFView"; import { CollectionVideoView } from "./CollectionVideoView"; import { CollectionView } from "./CollectionView"; import React = require("react"); +import { MainView } from "../MainView"; export interface CollectionViewProps extends FieldViewProps { addDocument: (document: Doc, allowDuplicates?: boolean) => boolean; @@ -67,10 +68,16 @@ export function CollectionSubView<T>(schemaCtor: (doc: Doc) => T) { let email = CurrentUserUtils.email; let pos = { x: position[0], y: position[1] }; if (id && email) { - const proto = await doc.proto; + const proto = Doc.GetProto(doc); if (!proto) { return; } + if (proto[Id] === "collectionProto") { + alert("COLLECTION PROTO CURSOR ISSUE DETECTED! Check console for more info..."); + console.log(doc); + console.log(proto); + throw new Error(`AHA! You were trying to set a cursor on a collection's proto, which is the original collection proto! Look at the two previously printed lines for document values!`); + } let cursors = Cast(proto.cursors, listSpec(CursorField)); if (!cursors) { proto.cursors = cursors = new List<CursorField>(); diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index 9407d742c..fbabe224e 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -18,6 +18,7 @@ import { List } from "../../../new_fields/List"; import { TextField } from "../../util/ProsemirrorCopy/prompt"; import { RichTextField } from "../../../new_fields/RichTextField"; import { ImageField } from "../../../new_fields/URLField"; +import { SelectionManager } from "../../util/SelectionManager"; @observer export class KeyValueBox extends React.Component<FieldViewProps> { @@ -167,44 +168,72 @@ export class KeyValueBox extends React.Component<FieldViewProps> { return parent; } - createTemplateField = async (parent: Doc, row: KeyValuePair) => { - let collectionKeyProp = `fieldKey={"data"}`; - let metaKey = row.props.keyName; - let metaKeyProp = `fieldKey={"${metaKey}"}`; + createTemplateField = async (parentStackingDoc: Doc, row: KeyValuePair) => { + // let collectionKeyProp = `fieldKey={"data"}`; + // let metaKey = row.props.keyName; + // let metaKeyProp = `fieldKey={"${metaKey}"}`; + + // let sourceDoc = await Cast(this.props.Document.data, Doc); + // if (!sourceDoc) { + // return; + // } + // let target = this.inferType(sourceDoc[metaKey], metaKey); + // let template = Doc.MakeAlias(target); + // template.proto = parent; + // template.title = metaKey; + // template.nativeWidth = 0; + // template.nativeHeight = 0; + // template.embed = true; + // template.isTemplate = true; + // template.templates = new List<string>([Templates.TitleBar(metaKey)]); + // if (target.backgroundLayout) { + // let metaAnoKeyProp = `fieldKey={"${metaKey}"} fieldExt={"annotations"}`; + // let collectionAnoKeyProp = `fieldKey={"annotations"}`; + // template.layout = StrCast(target.layout).replace(collectionAnoKeyProp, metaAnoKeyProp); + // template.backgroundLayout = StrCast(target.backgroundLayout).replace(collectionKeyProp, metaKeyProp); + // } else { + // template.layout = StrCast(target.layout).replace(collectionKeyProp, metaKeyProp); + // } + + let metaKey = row.props.keyName; let sourceDoc = await Cast(this.props.Document.data, Doc); if (!sourceDoc) { return; } - let target = this.inferType(sourceDoc[metaKey], metaKey); - - let template = Doc.MakeAlias(target); - template.proto = parent; - template.title = metaKey; - template.nativeWidth = 0; - template.nativeHeight = 0; - template.embed = true; - template.isTemplate = true; - template.templates = new List<string>([Templates.TitleBar(metaKey)]); - if (target.backgroundLayout) { - let metaAnoKeyProp = `fieldKey={"${metaKey}"} fieldExt={"annotations"}`; - let collectionAnoKeyProp = `fieldKey={"annotations"}`; - template.layout = StrCast(target.layout).replace(collectionAnoKeyProp, metaAnoKeyProp); - template.backgroundLayout = StrCast(target.backgroundLayout).replace(collectionKeyProp, metaKeyProp); - } else { - template.layout = StrCast(target.layout).replace(collectionKeyProp, metaKeyProp); + let fieldTemplate = this.inferType(sourceDoc[metaKey], metaKey); + + // 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(parent, "data", template); + let nw = NumCast(fieldTemplate.nativeWidth); + let nh = NumCast(fieldTemplate.nativeHeight); + + 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(parentStackingDoc); + + Doc.AddDocToList(parentStackingDoc, "data", fieldTemplate); row.uncheck(); } - inferType = (field: FieldResult, metaKey: string) => { + inferType = (data: FieldResult, metaKey: string) => { let options = { width: 300, height: 300, title: metaKey }; - if (field instanceof RichTextField || typeof field === "string" || typeof field === "number") { + if (data instanceof RichTextField || typeof data === "string" || typeof data === "number") { return Docs.TextDocument(options); - } else if (field instanceof List) { + } else if (data instanceof List) { return Docs.StackingDocument([], options); - } else if (field instanceof ImageField) { + } else if (data instanceof ImageField) { return Docs.ImageDocument("https://www.freepik.com/free-icon/picture-frame-with-mountain-image_748687.htm", options); } return new Doc; |
