aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/documents')
-rw-r--r--src/client/documents/DocFromField.ts16
-rw-r--r--src/client/documents/Documents.ts16
2 files changed, 15 insertions, 17 deletions
diff --git a/src/client/documents/DocFromField.ts b/src/client/documents/DocFromField.ts
index b65bbbdf5..9acb9c225 100644
--- a/src/client/documents/DocFromField.ts
+++ b/src/client/documents/DocFromField.ts
@@ -1,5 +1,4 @@
import { Doc, DocListCast } from '../../fields/Doc';
-import { InkField } from '../../fields/InkField';
import { List } from '../../fields/List';
import { StrCast } from '../../fields/Types';
import { AudioField, ImageField, PdfField, VideoField } from '../../fields/URLField';
@@ -12,7 +11,17 @@ export function ResetLayoutFieldKey(doc: Doc, fieldKey: string) {
doc.layout = StrCast(doc.layout).replace(/={'.*'}/, `={'${fieldKey}'}`);
return doc;
}
-export function DocumentFromField(target: Doc, fieldKey: string, proto?: Doc, options?: DocumentOptions): Doc | undefined {
+/**
+ * Creates a new document based on the type of (and containing the) data in the specified field of an existing document.
+ * If the field contains a list, then it may be useful to specify a classProto to indicate the type of
+ * collection Doc that gets created.
+ * @param target document to retrive field from
+ * @param fieldKey field key to retrieve
+ * @param classProto optionally a class proto to set on the new document
+ * @param options metadata configuration for new document
+ * @returns
+ */
+export function DocumentFromField(target: Doc, fieldKey: string, classProto?: Doc, options?: DocumentOptions): Doc | undefined {
const field = target[fieldKey];
const resolved = options ?? {};
const nonDocFieldToDoc = () => {
@@ -20,12 +29,11 @@ export function DocumentFromField(target: Doc, fieldKey: string, proto?: Doc, op
if (field instanceof VideoField) return Docs.Create.VideoDocument(field.url.href, resolved);
if (field instanceof PdfField) return Docs.Create.PdfDocument(field.url.href, resolved);
if (field instanceof AudioField) return Docs.Create.AudioDocument(field.url.href, resolved);
- if (field instanceof InkField) return Docs.Create.InkDocument(field.inkData, resolved);
if (field instanceof List && field[0] instanceof Doc) return Docs.Create.StackingDocument(DocListCast(field), resolved);
return Docs.Create.TextDocument('', { ...{ _width: 200, _height: 25, _layout_autoHeight: true }, ...resolved });
};
const created = field instanceof Doc ? field : ResetLayoutFieldKey(nonDocFieldToDoc(), fieldKey);
created.title = fieldKey;
- proto && created.proto && (created.proto = Doc.GetProto(proto));
+ classProto && created.proto && (created.proto = classProto);
return created;
}
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index dc649ec4e..751fe6d91 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -5,7 +5,7 @@ import { reaction } from 'mobx';
import { basename } from 'path';
import { ClientUtils, OmitKeys } from '../../ClientUtils';
import { DateField } from '../../fields/DateField';
-import { ActiveArrowEnd, ActiveArrowStart, ActiveDash, ActiveFillColor, ActiveInkBezierApprox, ActiveInkColor, ActiveInkWidth, ActiveIsInkMask, CreateLinkToActiveAudio, Doc, FieldType, Opt, updateCachedAcls } from '../../fields/Doc';
+import { CreateLinkToActiveAudio, Doc, FieldType, Opt, updateCachedAcls } from '../../fields/Doc';
import { Initializing } from '../../fields/DocSymbols';
import { HtmlField } from '../../fields/HtmlField';
import { InkField } from '../../fields/InkField';
@@ -837,18 +837,7 @@ export namespace Docs {
return linkDoc;
}
- export function InkDocument(
- points: PointData[],
- options: DocumentOptions = {},
- strokeWidth = ActiveInkWidth(),
- color = ActiveInkColor(),
- strokeBezier = ActiveInkBezierApprox(),
- fillColor = ActiveFillColor(),
- arrowStart = ActiveArrowStart(),
- arrowEnd = ActiveArrowEnd(),
- dash = ActiveDash(),
- isInkMask = ActiveIsInkMask()
- ) {
+ export function InkDocument(points: PointData[], options: DocumentOptions = {}, strokeWidth: number, color: string, strokeBezier: string, fillColor: string, arrowStart: string, arrowEnd: string, dash: string, isInkMask: boolean) {
const ink = InstanceFromProto(Prototypes.get(DocumentType.INK), '', { title: 'ink', ...options });
const I = Doc.GetProto(ink);
// I.layout_hideOpenButton = true; // don't show open full screen button when selected
@@ -864,6 +853,7 @@ export namespace Docs {
I.text_align = 'center';
I.rotation = 0;
I.defaultDoubleClick = 'ignore';
+ I.keepZWhenDragged = true;
I.author_date = new DateField();
I.acl_Guest = Doc.defaultAclPrivate ? SharingPermissions.None : SharingPermissions.View;
// I.acl_Override = SharingPermissions.Unset;