aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/apis/youtube/YoutubeBox.tsx4
-rw-r--r--src/client/cognitive_services/CognitiveServices.ts2
-rw-r--r--src/client/documents/Documents.ts33
-rw-r--r--src/client/util/Import & Export/DirectoryImportBox.tsx2
-rw-r--r--src/client/util/Import & Export/ImageUtils.ts2
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx15
-rw-r--r--src/client/views/nodes/ImageBox.tsx2
7 files changed, 35 insertions, 25 deletions
diff --git a/src/client/apis/youtube/YoutubeBox.tsx b/src/client/apis/youtube/YoutubeBox.tsx
index 4b4145fcc..4e990537f 100644
--- a/src/client/apis/youtube/YoutubeBox.tsx
+++ b/src/client/apis/youtube/YoutubeBox.tsx
@@ -156,14 +156,14 @@ export class YoutubeBox extends React.Component<FieldViewProps> {
@action
processVideoDetails = (videoDetails: any[]) => {
this.videoDetails = videoDetails;
- this.props.Document.cachedDetails = Docs.Get.DocumentHierarchyFromJson(videoDetails, "detailBackUp");
+ this.props.Document.cachedDetails = Docs.Get.DocumentHierarchyFromJson(videoDetails, "detailBackUp", undefined, false);
}
/**
* The function that stores the search results in the props document.
*/
backUpSearchResults = (videos: any[]) => {
- this.props.Document.cachedSearchResults = Docs.Get.DocumentHierarchyFromJson(videos, "videosBackUp");
+ this.props.Document.cachedSearchResults = Docs.Get.DocumentHierarchyFromJson(videos, "videosBackUp", undefined, false);
}
/**
diff --git a/src/client/cognitive_services/CognitiveServices.ts b/src/client/cognitive_services/CognitiveServices.ts
index 3f3726621..e464aff55 100644
--- a/src/client/cognitive_services/CognitiveServices.ts
+++ b/src/client/cognitive_services/CognitiveServices.ts
@@ -192,7 +192,7 @@ export namespace CognitiveServices {
let results = await ExecuteQuery(Service.Handwriting, Manager, inkData);
if (results) {
results.recognitionUnits && (results = results.recognitionUnits);
- target[keys[0]] = Docs.Get.DocumentHierarchyFromJson(results, "Ink Analysis");
+ target[keys[0]] = Docs.Get.DocumentHierarchyFromJson(results, "Ink Analysis", undefined, false);
const recognizedText = results.map((item: any) => item.recognizedText);
const recognizedObjects = results.map((item: any) => item.recognizedObject);
const individualWords = recognizedText.filter((text: string) => text && text.split(" ").length === 1);
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index b5c6dc06a..30f72a6b2 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -116,7 +116,7 @@ export interface DocumentOptions {
borderRounding?: string;
boxShadow?: string;
dontRegisterChildren?: boolean;
- "onClick-rawScript"?:string; // onClick script in raw text form
+ "onClick-rawScript"?: string; // onClick script in raw text form
_pivotField?: string; // field key used to determine headings for sections in stacking, masonry, pivot views
schemaColumns?: List<SchemaHeaderField>;
dockingConfig?: string;
@@ -405,7 +405,7 @@ export namespace Docs {
const doc = StackingDocument(deviceImages, { title: device.title, _LODdisable: true });
const deviceProto = Doc.GetProto(doc);
deviceProto.hero = new ImageField(constructed[0].url);
- Docs.Get.DocumentHierarchyFromJson(device, undefined, deviceProto);
+ Docs.Get.DocumentHierarchyFromJson(device, undefined, deviceProto, false);
Doc.AddDocToList(parentProto, "data", doc);
} else if (errors) {
console.log(errors);
@@ -732,19 +732,21 @@ export namespace Docs {
* @param input for convenience and flexibility, either a valid JSON string to be parsed,
* or the result of any JSON.parse() call.
* @param title an optional title to give to the highest parent document in the hierarchy
+ * @param appendToTarget -???
+ * @param all whether fields should be converted even if they contain no data
*/
- export function DocumentHierarchyFromJson(input: any, title?: string, appendToTarget?: Doc): Opt<Doc> {
+ export function DocumentHierarchyFromJson(input: any, title: string, appendToTarget: Opt<Doc>, all?:boolean): Opt<Doc> {
if (input === undefined || input === null || ![...primitives, "object"].includes(typeof input)) {
return undefined;
}
input = JSON.parse(typeof input === "string" ? input : JSON.stringify(input));
- let converted: Doc;
+ let converted: Opt<Doc>;
if (typeof input === "object" && !(input instanceof Array)) {
- converted = convertObject(input, title, appendToTarget);
+ converted = convertObject(input, title, appendToTarget, all);
} else {
(converted = new Doc).json = toField(input);
}
- title && (converted.title = title);
+ title && converted && (converted.title = title);
return converted;
}
@@ -755,12 +757,15 @@ export namespace Docs {
* @returns the object mapped from JSON to field values, where each mapping
* might involve arbitrary recursion (since toField might itself call convertObject)
*/
- const convertObject = (object: any, title?: string, target?: Doc): Doc => {
- const resolved = target ?? new Doc;
- let result: Opt<Field>;
- Object.keys(object).map(key => (result = toField(object[key], key)) && (resolved[key] = result));
- title && !resolved.title && (resolved.title = title);
- return resolved;
+ const convertObject = (object: any, title?: string, target?: Doc, all?:boolean): Opt<Doc> => {
+ const objkeys = Object.keys(object);
+ if (objkeys.length || all) {
+ const resolved = target ?? new Doc;
+ let result: Opt<Field>;
+ Object.keys(object).map(key => (result = toField(object[key], key)) && (resolved[key] = result));
+ title && !resolved.title && (resolved.title = title);
+ return resolved;
+ }
};
/**
@@ -778,7 +783,7 @@ export namespace Docs {
};
- const toField = (data: any, title?: string): Opt<Field> => {
+ const toField = (data: any, title?: string, all?:boolean): Opt<Field> => {
if (data === null || data === undefined) {
return undefined;
}
@@ -786,7 +791,7 @@ export namespace Docs {
return data;
}
if (typeof data === "object") {
- return data instanceof Array ? convertList(data) : convertObject(data, title);
+ return data instanceof Array ? convertList(data) : convertObject(data, title, undefined, all);
}
throw new Error(`How did ${data} of type ${typeof data} end up in JSON?`);
};
diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx
index 3d8bcbab7..01a0eddf8 100644
--- a/src/client/util/Import & Export/DirectoryImportBox.tsx
+++ b/src/client/util/Import & Export/DirectoryImportBox.tsx
@@ -126,7 +126,7 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps>
const document = await Docs.Get.DocumentFromType(type, path, { _width: 300, title: name });
const { data, error } = exifData;
if (document) {
- Doc.GetProto(document).exif = error || Docs.Get.DocumentHierarchyFromJson(data);
+ Doc.GetProto(document).exif = error || Docs.Get.DocumentHierarchyFromJson(data, "", undefined, false);
docs.push(document);
}
}));
diff --git a/src/client/util/Import & Export/ImageUtils.ts b/src/client/util/Import & Export/ImageUtils.ts
index ab8c73d15..135454a33 100644
--- a/src/client/util/Import & Export/ImageUtils.ts
+++ b/src/client/util/Import & Export/ImageUtils.ts
@@ -20,7 +20,7 @@ export namespace ImageUtils {
nativeHeight,
exifData: { error, data }
} = await Networking.PostToServer("/inspectImage", { source });
- document.exif = error || Docs.Get.DocumentHierarchyFromJson(data);
+ document.exif = error || Docs.Get.DocumentHierarchyFromJson(data, "", undefined, false);
const proto = Doc.GetProto(document);
proto["data-nativeWidth"] = nativeWidth;
proto["data-nativeHeight"] = nativeHeight;
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index ed6286675..f27b37e2c 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -493,17 +493,22 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument, u
onPointerUp = (e: PointerEvent): void => {
if (InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE)) return;
+ document.removeEventListener("pointermove", this.onPointerMove);
+ document.removeEventListener("pointerup", this.onPointerUp);
+ this.removeMoveListeners();
+ this.removeEndListeners();
+ }
+
+ onClick = (e: React.MouseEvent) => {
if (this.layoutDoc.targetScale && (Math.abs(e.pageX - this._downX) < 3 && Math.abs(e.pageY - this._downY) < 3)) {
if (Date.now() - this._lastTap < 300) {
const docpt = this.getTransform().transformPoint(e.clientX, e.clientY);
this.scaleAtPt(docpt, NumCast(this.layoutDoc.targetScale, NumCast(this.layoutDoc.scale)));
+ e.stopPropagation();
+ e.preventDefault();
}
this._lastTap = Date.now();
}
- document.removeEventListener("pointermove", this.onPointerMove);
- document.removeEventListener("pointerup", this.onPointerUp);
- this.removeMoveListeners();
- this.removeEndListeners();
}
@action
@@ -1129,7 +1134,7 @@ export class CollectionFreeFormView extends CollectionSubView(PanZoomDocument, u
// otherwise, they are stored in fieldKey. All annotations to this document are stored in the extension document
return <div className={"collectionfreeformview-container"}
ref={this.createDashEventsTarget}
- onWheel={this.onPointerWheel}//pointerEvents: SelectionManager.GetIsDragging() ? "all" : undefined,
+ onWheel={this.onPointerWheel} onClick={this.onClick} //pointerEvents: SelectionManager.GetIsDragging() ? "all" : undefined,
onPointerDown={this.onPointerDown} onPointerMove={this.onCursorMove} onDrop={this.onExternalDrop.bind(this)} onContextMenu={this.onContextMenu}
style={{
pointerEvents: SelectionManager.GetIsDragging() ? "all" : undefined,
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 5b0edf34f..c45f14975 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -187,7 +187,7 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps, ImageD
extractFaces = () => {
const converter = (results: any) => {
const faceDocs = new List<Doc>();
- results.reduce((face: CognitiveServices.Image.Face, faceDocs: List<Doc>) => faceDocs.push(Docs.Get.DocumentHierarchyFromJson(face, `Face: ${face.faceId}`)!), new List<Doc>());
+ results.reduce((face: CognitiveServices.Image.Face, faceDocs: List<Doc>) => faceDocs.push(Docs.Get.DocumentHierarchyFromJson(face, `Face: ${face.faceId}`, undefined, false)!), new List<Doc>());
return faceDocs;
};
this.url && CognitiveServices.Image.Appliers.ProcessImage(this.dataDoc, [this.fieldKey + "-faces"], this.url, Service.Face, converter);