aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents/Documents.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r--src/client/documents/Documents.ts228
1 files changed, 160 insertions, 68 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index ed4c99d70..57a24b304 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -31,7 +31,7 @@ import { CollectionView } from '../views/collections/CollectionView';
import { ContextMenu } from '../views/ContextMenu';
import { ContextMenuProps } from '../views/ContextMenuItem';
import { DFLT_IMAGE_NATIVE_DIM } from '../views/global/globalCssVariables.scss';
-import { ActiveArrowEnd, ActiveArrowStart, ActiveDash, ActiveFillColor, ActiveInkBezierApprox, ActiveInkColor, ActiveInkWidth, InkingStroke } from '../views/InkingStroke';
+import { ActiveArrowEnd, ActiveArrowStart, ActiveDash, ActiveFillColor, ActiveInkBezierApprox, ActiveInkColor, ActiveInkWidth, ActiveIsInkMask, InkingStroke } from '../views/InkingStroke';
import { AudioBox } from '../views/nodes/AudioBox';
import { FontIconBox } from '../views/nodes/button/FontIconBox';
import { ColorBox } from '../views/nodes/ColorBox';
@@ -48,6 +48,7 @@ import { KeyValueBox } from '../views/nodes/KeyValueBox';
import { LabelBox } from '../views/nodes/LabelBox';
import { LinkBox } from '../views/nodes/LinkBox';
import { LinkDescriptionPopup } from '../views/nodes/LinkDescriptionPopup';
+import { LoadingBox } from '../views/nodes/LoadingBox';
import { MapBox } from '../views/nodes/MapBox/MapBox';
import { PDFBox } from '../views/nodes/PDFBox';
import { RecordingBox } from '../views/nodes/RecordingBox/RecordingBox';
@@ -264,12 +265,6 @@ export class DocumentOptions {
baseProto?: boolean; // is this a base prototoype
dontRegisterView?: boolean;
lookupField?: ScriptField; // script that returns the value of a field. This script is passed the rootDoc, layoutDoc, field, and container of the document. see PresBox.
- 'onDoubleClick-rawScript'?: string; // onDoubleClick script in raw text form
- 'onChildDoubleClick-rawScript'?: string; // onChildDoubleClick script in raw text form
- 'onChildClick-rawScript'?: string; // on ChildClick script in raw text form
- 'onClick-rawScript'?: string; // onClick script in raw text form
- 'onCheckedClick-rawScript'?: string; // onChecked script in raw text form
- 'onCheckedClick-params'?: List<string>; // parameter list for onChecked treeview functions
columnHeaders?: List<SchemaHeaderField>; // headers for stacking views
schemaHeaders?: List<SchemaHeaderField>; // headers for schema view
clipWidth?: number; // percent transition from before to after in comparisonBox
@@ -465,7 +460,7 @@ export namespace Docs {
DocumentType.AUDIO,
{
layout: { view: AudioBox, dataField: defaultDataKey },
- options: { _height: 100, backgroundColor: 'lightGray', forceReflow: true, nativeDimModifiable: true, links: '@links(self)' },
+ options: { _height: 100, backgroundColor: 'lightGray', _fitWidth: true, forceReflow: true, nativeDimModifiable: true, links: '@links(self)' },
},
],
[
@@ -654,6 +649,13 @@ export namespace Docs {
options: { _fitWidth: true, nativeDimModifiable: true, links: '@links(self)' },
},
],
+ [
+ DocumentType.LOADING,
+ {
+ layout: { view: LoadingBox, dataField: '' },
+ options: { _fitWidth: true, _fitHeight: true, nativeDimModifiable: true, links: '@links(self)' },
+ },
+ ],
]);
const suffix = 'Proto';
@@ -792,7 +794,7 @@ export namespace Docs {
* only when creating a DockDocument from the current user's already existing
* main document.
*/
- function InstanceFromProto(proto: Doc, data: Field | undefined, options: DocumentOptions, delegId?: string, fieldKey: string = 'data', protoId?: string) {
+ function InstanceFromProto(proto: Doc, data: Field | undefined, options: DocumentOptions, delegId?: string, fieldKey: string = 'data', protoId?: string, placeholderDoc?: Doc) {
const viewKeys = ['x', 'y', 'system']; // keys that should be addded to the view document even though they don't begin with an "_"
const { omit: dataProps, extract: viewProps } = OmitKeys(options, viewKeys, '^_');
@@ -803,21 +805,36 @@ export namespace Docs {
dataProps.isPrototype = true;
dataProps.author = Doc.CurrentUserEmail;
dataProps.creationDate = new DateField();
- dataProps[`${fieldKey}-lastModified`] = new DateField();
+ if (fieldKey) {
+ dataProps[`${fieldKey}-lastModified`] = new DateField();
+ dataProps[fieldKey] = data;
+
+ // so that the list of annotations is already initialised, prevents issues in addonly.
+ // without this, if a doc has no annotations but the user has AddOnly privileges, they won't be able to add an annotation because they would have needed to create the field's list which they don't have permissions to do.
+ dataProps[fieldKey + '-annotations'] = new List<Doc>();
+ dataProps[fieldKey + '-sidebar'] = new List<Doc>();
+ }
- dataProps[fieldKey] = data;
+ // users placeholderDoc as proto if it exists
+ const dataDoc = Doc.assign(placeholderDoc ? Doc.GetProto(placeholderDoc) : Doc.MakeDelegate(proto, protoId), dataProps, undefined, true);
- // so that the list of annotations is already initialised, prevents issues in addonly.
- // without this, if a doc has no annotations but the user has AddOnly privileges, they won't be able to add an annotation because they would have needed to create the field's list which they don't have permissions to do.
- dataProps[fieldKey + '-annotations'] = new List<Doc>();
- dataProps[fieldKey + '-sidebar'] = new List<Doc>();
- const dataDoc = Doc.assign(Doc.MakeDelegate(proto, protoId), dataProps, undefined, true);
+ if (placeholderDoc) {
+ dataDoc.proto = proto;
+ }
const viewFirstProps: { [id: string]: any } = {};
viewFirstProps['acl-Public'] = options['_acl-Public'] ? options['_acl-Public'] : Doc.defaultAclPrivate ? SharingPermissions.None : SharingPermissions.Augment;
viewFirstProps['acl-Override'] = 'None';
viewFirstProps.author = Doc.CurrentUserEmail;
- const viewDoc = Doc.assign(Doc.MakeDelegate(dataDoc, delegId), viewFirstProps, true, true);
+ let viewDoc: Doc;
+ // determines whether viewDoc should be created using placeholder Doc or default
+ if (placeholderDoc) {
+ placeholderDoc._height = options._height !== undefined ? Number(options._height) : undefined;
+ placeholderDoc._width = options._width !== undefined ? Number(options._width) : undefined;
+ viewDoc = Doc.assign(placeholderDoc, viewFirstProps, true, true);
+ } else {
+ viewDoc = Doc.assign(Doc.MakeDelegate(dataDoc, delegId), viewFirstProps, true, true);
+ }
Doc.assign(viewDoc, viewProps, true, true);
![DocumentType.LINK, DocumentType.MARKER, DocumentType.LABEL].includes(viewDoc.type as any) && DocUtils.MakeLinkToActiveAudio(() => viewDoc);
@@ -829,12 +846,13 @@ export namespace Docs {
updateCachedAcls(dataDoc);
updateCachedAcls(viewDoc);
+
return viewDoc;
}
- export function ImageDocument(url: string | ImageField, options: DocumentOptions = {}) {
+ export function ImageDocument(url: string | ImageField, options: DocumentOptions = {}, overwriteDoc?: Doc) {
const imgField = url instanceof ImageField ? url : new ImageField(url);
- return InstanceFromProto(Prototypes.get(DocumentType.IMG), imgField, { title: basename(imgField.url.href), ...options });
+ return InstanceFromProto(Prototypes.get(DocumentType.IMG), imgField, { title: basename(imgField.url.href), ...options }, undefined, undefined, undefined, overwriteDoc);
}
export function PresDocument(options: DocumentOptions = {}) {
@@ -845,12 +863,12 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.SCRIPTING), script ? script : undefined, { ...options, layout: fieldKey ? ScriptingBox.LayoutString(fieldKey) : undefined });
}
- export function VideoDocument(url: string, options: DocumentOptions = {}) {
- return InstanceFromProto(Prototypes.get(DocumentType.VID), new VideoField(url), options);
+ export function VideoDocument(url: string, options: DocumentOptions = {}, overwriteDoc?: Doc) {
+ return InstanceFromProto(Prototypes.get(DocumentType.VID), new VideoField(url), options, undefined, undefined, undefined, overwriteDoc);
}
- export function YoutubeDocument(url: string, options: DocumentOptions = {}) {
- return InstanceFromProto(Prototypes.get(DocumentType.YOUTUBE), new YoutubeField(url), options);
+ export function YoutubeDocument(url: string, options: DocumentOptions = {}, overwriteDoc?: Doc) {
+ return InstanceFromProto(Prototypes.get(DocumentType.YOUTUBE), new YoutubeField(url), options, undefined, undefined, undefined, overwriteDoc);
}
export function WebCamDocument(url: string, options: DocumentOptions = {}) {
@@ -865,8 +883,16 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.COMPARISON), '', options);
}
- export function AudioDocument(url: string, options: DocumentOptions = {}) {
- return InstanceFromProto(Prototypes.get(DocumentType.AUDIO), new AudioField(url), { ...options, backgroundColor: ComputedField.MakeFunction("this._mediaState === 'playing' ? 'green':'gray'") as any });
+ export function AudioDocument(url: string, options: DocumentOptions = {}, overwriteDoc?: Doc) {
+ return InstanceFromProto(
+ Prototypes.get(DocumentType.AUDIO),
+ new AudioField(url),
+ { ...options, backgroundColor: ComputedField.MakeFunction("this._mediaState === 'playing' ? 'green':'gray'") as any },
+ undefined,
+ undefined,
+ undefined,
+ overwriteDoc
+ );
}
export function RecordingDocument(url: string, options: DocumentOptions = {}) {
@@ -880,6 +906,9 @@ export namespace Docs {
export function ColorDocument(options: DocumentOptions = {}) {
return InstanceFromProto(Prototypes.get(DocumentType.COLOR), '', options);
}
+ export function LoadingDocument(file: File | string, options: DocumentOptions, ytString?: string) {
+ return InstanceFromProto(Prototypes.get(DocumentType.LOADING), undefined, { _height: 150, _width: 200, title: typeof file == 'string' ? file : file.name, ...options }, undefined, '');
+ }
export function RTFDocument(field: RichTextField, options: DocumentOptions = {}, fieldKey: string = 'text') {
return InstanceFromProto(Prototypes.get(DocumentType.RTF), field, options, undefined, fieldKey);
@@ -924,9 +953,22 @@ export namespace Docs {
return linkDoc;
}
- export function InkDocument(color: string, tool: string, strokeWidth: number, strokeBezier: string, fillColor: string, arrowStart: string, arrowEnd: string, dash: string, points: PointData[], options: DocumentOptions = {}) {
+ export function InkDocument(
+ color: string,
+ tool: string,
+ strokeWidth: number,
+ strokeBezier: string,
+ fillColor: string,
+ arrowStart: string,
+ arrowEnd: string,
+ dash: string,
+ points: PointData[],
+ isInkMask: boolean,
+ options: DocumentOptions = {}
+ ) {
const I = new Doc();
I[Initializing] = true;
+ I.isInkMask = isInkMask;
I.type = DocumentType.INK;
I.layout = InkingStroke.LayoutString('data');
I.color = color;
@@ -957,13 +999,13 @@ export namespace Docs {
return I;
}
- export function PdfDocument(url: string, options: DocumentOptions = {}) {
+ export function PdfDocument(url: string, options: DocumentOptions = {}, overwriteDoc?: Doc) {
const width = options._width || undefined;
const height = options._height || undefined;
const nwid = options._nativeWidth || undefined;
const nhght = options._nativeHeight || undefined;
if (!nhght && width && height && nwid) options._nativeHeight = (Number(nwid) * Number(height)) / Number(width);
- return InstanceFromProto(Prototypes.get(DocumentType.PDF), new PdfField(url), options);
+ return InstanceFromProto(Prototypes.get(DocumentType.PDF), new PdfField(url), options, undefined, undefined, undefined, overwriteDoc);
}
export function WebDocument(url: string, options: DocumentOptions = {}) {
@@ -1041,6 +1083,17 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _viewType: CollectionViewType.Stacking }, id, undefined, protoId);
}
+ export function NoteTakingDocument(documents: Array<Doc>, options: DocumentOptions, id?: string, protoId?: string) {
+ return InstanceFromProto(
+ Prototypes.get(DocumentType.COL),
+ new List(documents),
+ { columnHeaders: new List<SchemaHeaderField>([new SchemaHeaderField('Untitled')]), ...options, _viewType: CollectionViewType.NoteTaking },
+ id,
+ undefined,
+ protoId
+ );
+ }
+
export function MulticolumnDocument(documents: Array<Doc>, options: DocumentOptions) {
return InstanceFromProto(Prototypes.get(DocumentType.COL), new List(documents), { ...options, _viewType: CollectionViewType.Multicolumn });
}
@@ -1065,7 +1118,7 @@ export namespace Docs {
}
export function ButtonDocument(options?: DocumentOptions) {
- return InstanceFromProto(Prototypes.get(DocumentType.BUTTON), undefined, { ...(options || {}), 'onClick-rawScript': '-script-' });
+ return InstanceFromProto(Prototypes.get(DocumentType.BUTTON), undefined, { ...(options || {}) });
}
export function SliderDocument(options?: DocumentOptions) {
@@ -1083,8 +1136,8 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.PRESELEMENT), undefined, { ...(options || {}) });
}
- export function DataVizDocument(url: string, options?: DocumentOptions) {
- return InstanceFromProto(Prototypes.get(DocumentType.DATAVIZ), new CsvField(url), { title: 'Data Viz', ...options });
+ export function DataVizDocument(url: string, options?: DocumentOptions, overwriteDoc?: Doc) {
+ return InstanceFromProto(Prototypes.get(DocumentType.DATAVIZ), new CsvField(url), { title: 'Data Viz', ...options }, undefined, undefined, undefined, overwriteDoc);
}
export function DockDocument(documents: Array<Doc>, config: string, options: DocumentOptions, id?: string) {
@@ -1125,30 +1178,6 @@ export namespace Docs {
}
export namespace DocUtils {
- export function Excluded(d: Doc, docFilters: string[]) {
- const filterFacets: { [key: string]: { [value: string]: string } } = {}; // maps each filter key to an object with value=>modifier fields
- docFilters.forEach(filter => {
- const fields = filter.split(':');
- const key = fields[0];
- const value = fields[1];
- const modifiers = fields[2];
- if (!filterFacets[key]) {
- filterFacets[key] = {};
- }
- filterFacets[key][value] = modifiers;
- });
-
- if (d.z) return false;
- for (const facetKey of Object.keys(filterFacets)) {
- const facet = filterFacets[facetKey];
- const xs = Object.keys(facet).filter(value => facet[value] === 'x');
- const failsNotEqualFacets = xs?.some(value => Doc.matchFieldValue(d, facetKey, value));
- if (failsNotEqualFacets) {
- return true;
- }
- }
- return false;
- }
/**
* @param docs
* @param docFilters
@@ -1182,7 +1211,7 @@ export namespace DocUtils {
return false;
}
- for (const facetKey of Object.keys(filterFacets).filter(fkey => fkey !== 'cookies')) {
+ for (const facetKey of Object.keys(filterFacets).filter(fkey => fkey !== 'cookies' && fkey !== Utils.noDragsDocFilter.split(':')[0])) {
const facet = filterFacets[facetKey];
// facets that match some value in the field of the document (e.g. some text field)
@@ -1282,10 +1311,11 @@ export namespace DocUtils {
export let ActiveRecordings: { props: FieldViewProps; getAnchor: () => Doc }[] = [];
- export function MakeLinkToActiveAudio(getSourceDoc: () => Doc, broadcastEvent = true) {
+ export function MakeLinkToActiveAudio(getSourceDoc: () => Doc | undefined, broadcastEvent = true) {
broadcastEvent && runInAction(() => (DocumentManager.Instance.RecordingEvent = DocumentManager.Instance.RecordingEvent + 1));
return DocUtils.ActiveRecordings.map(audio => {
- const link = DocUtils.MakeLink({ doc: getSourceDoc() }, { doc: audio.getAnchor() || audio.props.Document }, 'recording annotation:linked recording', 'recording timeline');
+ const sourceDoc = getSourceDoc();
+ const link = sourceDoc && DocUtils.MakeLink({ doc: sourceDoc }, { doc: audio.getAnchor() || audio.props.Document }, 'recording annotation:linked recording', 'recording timeline');
link && (link.followLinkLocation = 'add:right');
return link;
});
@@ -1356,7 +1386,17 @@ export namespace DocUtils {
scripts &&
Object.keys(scripts).map(key => {
if (ScriptCast(doc[key])?.script.originalScript !== scripts[key] && scripts[key]) {
- doc[key] = ScriptField.MakeScript(scripts[key], { dragData: DragManager.DocumentDragData.name, value: 'any', scriptContext: 'any', documentView: Doc.name }, { _readOnly_: true });
+ doc[key] = ScriptField.MakeScript(scripts[key], {
+ dragData: DragManager.DocumentDragData.name,
+ value: 'any',
+ _readOnly_: 'boolean',
+ scriptContext: 'any',
+ thisContainer: Doc.name,
+ documentView: Doc.name,
+ heading: Doc.name,
+ checked: 'boolean',
+ containingTreeView: Doc.name,
+ });
}
});
funcs &&
@@ -1414,7 +1454,7 @@ export namespace DocUtils {
created = Docs.Create.RecordingDocument(field.url.href, resolved);
layout = RecordingBox.LayoutString;
} else if (field instanceof InkField) {
- created = Docs.Create.InkDocument(ActiveInkColor(), Doc.ActiveTool, ActiveInkWidth(), ActiveInkBezierApprox(), ActiveFillColor(), ActiveArrowStart(), ActiveArrowEnd(), ActiveDash(), field.inkData, resolved);
+ created = Docs.Create.InkDocument(ActiveInkColor(), Doc.ActiveTool, ActiveInkWidth(), ActiveInkBezierApprox(), ActiveFillColor(), ActiveArrowStart(), ActiveArrowEnd(), ActiveDash(), field.inkData, ActiveIsInkMask(), resolved);
layout = InkingStroke.LayoutString;
} else if (field instanceof List && field[0] instanceof Doc) {
created = Docs.Create.StackingDocument(DocListCast(field), resolved);
@@ -1434,8 +1474,16 @@ export namespace DocUtils {
return created;
}
- export async function DocumentFromType(type: string, path: string, options: DocumentOptions): Promise<Opt<Doc>> {
- let ctor: ((path: string, options: DocumentOptions) => Doc | Promise<Doc | undefined>) | undefined = undefined;
+ /**
+ *
+ * @param type the type of file.
+ * @param path the path to the file.
+ * @param options the document options.
+ * @param overwriteDoc the placeholder loading doc.
+ * @returns
+ */
+ export async function DocumentFromType(type: string, path: string, options: DocumentOptions, overwriteDoc?: Doc): Promise<Opt<Doc>> {
+ let ctor: ((path: string, options: DocumentOptions, overwriteDoc?: Doc) => Doc | Promise<Doc | undefined>) | undefined = undefined;
if (type.indexOf('image') !== -1) {
ctor = Docs.Create.ImageDocument;
if (!options._width) options._width = 300;
@@ -1484,10 +1532,10 @@ export namespace DocUtils {
options = { ...options, _width: 400, _height: 512, title: path };
}
- return ctor ? ctor(path, options) : undefined;
+ return ctor ? ctor(path, options, overwriteDoc) : undefined;
}
- export function addDocumentCreatorMenuItems(docTextAdder: (d: Doc) => void, docAdder: (d: Doc) => void, x: number, y: number, simpleMenu: boolean = false): void {
+ export function addDocumentCreatorMenuItems(docTextAdder: (d: Doc) => void, docAdder: (d: Doc) => void, x: number, y: number, simpleMenu: boolean = false, pivotField?: string, pivotValue?: string): void {
!simpleMenu &&
ContextMenu.Instance.addItem({
description: 'Quick Notes',
@@ -1503,6 +1551,9 @@ export namespace DocUtils {
});
textDoc.layoutKey = 'layout_' + note.title;
textDoc[textDoc.layoutKey] = note;
+ if (pivotField) {
+ textDoc[pivotField] = pivotValue;
+ }
docTextAdder(textDoc);
}),
icon: StrCast(note.icon) as IconProp,
@@ -1523,6 +1574,9 @@ export namespace DocUtils {
newDoc.y = y;
EquationBox.SelectOnLoad = newDoc[Id];
if (newDoc.type === DocumentType.RTF) FormattedTextBox.SelectOnLoad = newDoc[Id];
+ if (pivotField) {
+ newDoc[pivotField] = pivotValue;
+ }
docAdder?.(newDoc);
}
}),
@@ -1694,14 +1748,15 @@ export namespace DocUtils {
return dd;
}
- async function processFileupload(generatedDocuments: Doc[], name: string, type: string, result: Error | Upload.FileInformation, options: DocumentOptions) {
+ async function processFileupload(generatedDocuments: Doc[], name: string, type: string, result: Error | Upload.FileInformation, options: DocumentOptions, rootDoc?: Doc) {
if (result instanceof Error) {
alert(`Upload failed: ${result.message}`);
return;
}
const full = { ...options, _width: 400, title: name };
const pathname = Utils.prepend(result.accessPaths.agnostic.client);
- const doc = await DocUtils.DocumentFromType(type, pathname, full);
+ const doc = await DocUtils.DocumentFromType(type, pathname, full, rootDoc);
+ rootDoc && (rootDoc.isLoading = undefined);
if (doc) {
const proto = Doc.GetProto(doc);
proto.text = result.rawText;
@@ -1711,7 +1766,8 @@ export namespace DocUtils {
.replace(/\.[a-z0-9]*$/, '');
if (Upload.isImageInformation(result)) {
const maxNativeDim = Math.min(Math.max(result.nativeHeight, result.nativeWidth), defaultNativeImageDim);
- proto['data-nativeOrientation'] = result.exifData?.data?.image?.Orientation ?? (StrCast((result.exifData?.data as any)?.Orientation).includes('Rotate 90') ? 5 : undefined);
+ const exifRotation = StrCast((result.exifData?.data as any)?.Orientation).toLowerCase();
+ proto['data-nativeOrientation'] = result.exifData?.data?.image?.Orientation ?? (exifRotation.includes('rotate 90') || exifRotation.includes('rotate 270') ? 5 : undefined);
proto['data-nativeWidth'] = result.nativeWidth < result.nativeHeight ? (maxNativeDim * result.nativeWidth) / result.nativeHeight : maxNativeDim;
proto['data-nativeHeight'] = result.nativeWidth < result.nativeHeight ? maxNativeDim : maxNativeDim / (result.nativeWidth / result.nativeHeight);
if (NumCast(proto['data-nativeOrientation']) >= 5) {
@@ -1729,6 +1785,9 @@ export namespace DocUtils {
proto.lng = ConvertDMSToDD(longitude[0], longitude[1], longitude[2], longitudeDirection);
}
}
+ if (Upload.isVideoInformation(result)) {
+ proto['data-duration'] = result.duration;
+ }
generatedDocuments.push(doc);
}
}
@@ -1763,10 +1822,27 @@ export namespace DocUtils {
source: { name, type },
result,
} of await Networking.UploadYoutubeToServer(videoId)) {
- name && type && processFileupload(generatedDocuments, name, type, result, options);
+ name && processFileupload(generatedDocuments, name, type, result, options);
}
return generatedDocuments;
}
+
+ export function uploadYoutubeVideoLoading(videoId: string, options: DocumentOptions, overwriteDoc?: Doc) {
+ const generatedDocuments: Doc[] = [];
+ Networking.UploadYoutubeToServer(videoId).then(upfiles => {
+ const {
+ source: { name, type },
+ result,
+ } = upfiles.lastElement();
+ if ((result as any).message) {
+ if (overwriteDoc) {
+ overwriteDoc.isLoading = false;
+ overwriteDoc.errorMessage = (result as any).message;
+ }
+ } else name && processFileupload(generatedDocuments, name, type, result, options, overwriteDoc);
+ });
+ }
+
export async function uploadFilesToDocs(files: File[], options: DocumentOptions) {
const generatedDocuments: Doc[] = [];
const upfiles = await Networking.UploadFilesToServer(files);
@@ -1779,6 +1855,22 @@ export namespace DocUtils {
return generatedDocuments;
}
+ export function uploadFileToDoc(file: File, options: DocumentOptions, overwriteDoc: Doc) {
+ const generatedDocuments: Doc[] = [];
+ Networking.UploadFilesToServer([file]).then(upfiles => {
+ const {
+ source: { name, type },
+ result,
+ } = upfiles.lastElement();
+ if ((result as any).message) {
+ if (overwriteDoc) {
+ overwriteDoc.isLoading = false;
+ overwriteDoc.errorMessage = (result as any).message;
+ }
+ } else name && type && processFileupload(generatedDocuments, name, type, result, options, overwriteDoc);
+ });
+ }
+
// copies the specified drag factory document
export function copyDragFactory(dragFactory: Doc) {
if (!dragFactory) return undefined;