aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/DropConverter.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/DropConverter.ts')
-rw-r--r--src/client/util/DropConverter.ts39
1 files changed, 7 insertions, 32 deletions
diff --git a/src/client/util/DropConverter.ts b/src/client/util/DropConverter.ts
index 0ede44298..71cdaa58b 100644
--- a/src/client/util/DropConverter.ts
+++ b/src/client/util/DropConverter.ts
@@ -5,7 +5,7 @@ import { RichTextField } from '../../fields/RichTextField';
import { ComputedField, ScriptField } from '../../fields/ScriptField';
import { StrCast } from '../../fields/Types';
import { ImageField } from '../../fields/URLField';
-import { Docs } from '../documents/Documents';
+import { Docs, DocumentOptions } from '../documents/Documents';
import { DocumentType } from '../documents/DocumentTypes';
import { ButtonType, FontIconBox } from '../views/nodes/FontIconBox/FontIconBox';
import { DragManager } from './DragManager';
@@ -64,49 +64,24 @@ export function MakeTemplate(doc: Doc) {
return doc;
}
-export function makeUserTemplateButton(doc: Doc) {
- const layoutDoc = doc; // doc.layout instanceof Doc && doc.layout.isTemplateForField ? doc.layout : doc;
- if (layoutDoc.type !== DocumentType.FONTICON) {
- !layoutDoc.isTemplateDoc && makeTemplate(layoutDoc);
- }
- layoutDoc.isTemplateDoc = true;
- const dbox = Docs.Create.FontIconDocument({
- _nativeWidth: 100,
- _nativeHeight: 100,
- _width: 100,
- _height: 100,
- backgroundColor: StrCast(doc.backgroundColor),
- title: StrCast(layoutDoc.title),
- btnType: ButtonType.ClickButton,
- icon: 'bolt',
- isSystem: false,
- });
- dbox.title = ComputedField.MakeFunction('this.dragFactory.title');
- dbox.dragFactory = layoutDoc;
- dbox.dropPropertiesToRemove = doc.dropPropertiesToRemove instanceof ObjectField ? ObjectField.MakeCopy(doc.dropPropertiesToRemove) : undefined;
- dbox.onDragStart = ScriptField.MakeFunction('getCopy(this.dragFactory)');
- return dbox;
-}
-
/**
- * Similar to makeUserTemplateButton, but rather than creating a draggable button for the template, it takes in
- * an ImageField that will display.
+ * Makes a draggable button or image that will create a template doc Instance
*/
-export function makeUserTemplateImage(doc: Doc, imageHref: string | undefined) {
- const image = imageHref ?? 'http://www.cs.brown.edu/~bcz/noImage.png';
+export function makeUserTemplateButtonOrImage(doc: Doc, image: string | undefined) {
const layoutDoc = doc; // doc.layout instanceof Doc && doc.layout.isTemplateForField ? doc.layout : doc;
if (layoutDoc.type !== DocumentType.FONTICON) {
!layoutDoc.isTemplateDoc && makeTemplate(layoutDoc);
}
layoutDoc.isTemplateDoc = true;
- const dbox = Docs.Create.ImageDocument(image, {
+ const docOptions: DocumentOptions = {
_nativeWidth: 100,
_nativeHeight: 100,
_width: 100,
_height: 100,
title: StrCast(layoutDoc.title),
isSystem: false,
- });
+ };
+ const dbox = image ? Docs.Create.ImageDocument(image, docOptions) : Docs.Create.FontIconDocument({ ...docOptions, backgroundColor: StrCast(doc.backgroundColor), btnType: ButtonType.ClickButton, icon: 'bolt' });
dbox.title = ComputedField.MakeFunction('this.dragFactory.title');
dbox.dragFactory = layoutDoc;
dbox.dropPropertiesToRemove = doc.dropPropertiesToRemove instanceof ObjectField ? ObjectField.MakeCopy(doc.dropPropertiesToRemove) : undefined;
@@ -129,7 +104,7 @@ export function convertDropDataToButtons(data: DragManager.DocumentDragData) {
});
}
} else if (!doc.onDragStart && !doc.isButtonBar) {
- dbox = makeUserTemplateButton(doc);
+ dbox = makeUserTemplateButtonOrImage(doc);
} else if (doc.isButtonBar) {
dbox.ignoreClick = true;
}