@contrail/document-generation 2.0.12 → 2.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,4 +54,5 @@ export interface DocumentPropertyDefinition {
54
54
  typeRootSlug: string;
55
55
  includeLabel?: boolean;
56
56
  isHidden?: boolean;
57
+ size?: SizeDefinition;
57
58
  }
@@ -4,5 +4,6 @@ import { PropertyValueFormatter } from "@contrail/types";
4
4
  export declare class DocumentPropertyUtil {
5
5
  static generatePropertyElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, imageDimension: SizeDefinition, isComponent?: boolean): Array<DocumentElement>;
6
6
  static generatePropertyTextElement(model: any, property: DocumentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter, position: PositionDefinition, isComponent?: boolean): DocumentElement;
7
+ static generatePropertyAnnotationElement(data: any, property: DocumentPropertyDefinition, size: SizeDefinition, position: PositionDefinition): DocumentElement;
7
8
  static generatePropertyImageElement(data: any, property: DocumentPropertyDefinition, imageDimension: SizeDefinition, position: PositionDefinition): DocumentElement;
8
9
  }
@@ -12,8 +12,12 @@ class DocumentPropertyUtil {
12
12
  const xPosition = startingPosition.x || 0;
13
13
  const elements = [];
14
14
  const formatter = new types_1.PropertyValueFormatter();
15
+ let index = 0;
15
16
  for (let property of properties) {
16
17
  let element;
18
+ if (index === 0 && property.slug === 'annotation') {
19
+ yPosition = -15;
20
+ }
17
21
  if (property.propertyDefinition) {
18
22
  const fontSize = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
19
23
  const PT_TO_PX = 1.3;
@@ -25,6 +29,10 @@ class DocumentPropertyUtil {
25
29
  element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
26
30
  yPosition += element.size.height - 10;
27
31
  }
32
+ else if (property.slug === 'annotation') {
33
+ element = DocumentPropertyUtil.generatePropertyAnnotationElement(data, property, property.size, { x: xPosition, y: yPosition });
34
+ yPosition += element.size.height - 10;
35
+ }
28
36
  else {
29
37
  const imageHeight = imageDimension.height || imageDimension.width || 125;
30
38
  const imageWidth = imageDimension.width || 125;
@@ -32,6 +40,7 @@ class DocumentPropertyUtil {
32
40
  yPosition += imageHeight;
33
41
  }
34
42
  elements.push(element);
43
+ index++;
35
44
  }
36
45
  return elements;
37
46
  }
@@ -51,12 +60,24 @@ class DocumentPropertyUtil {
51
60
  mergedOptions.position = position;
52
61
  const useInlineFormatting = isComponent === false;
53
62
  let element = document_text_element_util_1.DocumentTextElementUtil.generateTextElement(display, mergedOptions, useInlineFormatting);
54
- if (isComponent && property.includeLabel) {
63
+ if (property.includeLabel) {
55
64
  element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
56
65
  }
57
66
  element.propertyBindings = { text: modelKey };
58
67
  return element;
59
68
  }
69
+ static generatePropertyAnnotationElement(data, property, size, position) {
70
+ const element = {
71
+ type: "annotation",
72
+ size: size,
73
+ propertyBindings: { annotation: 'annotation' },
74
+ position
75
+ };
76
+ if (property.isHidden) {
77
+ element.isHidden = property.isHidden;
78
+ }
79
+ return element;
80
+ }
60
81
  static generatePropertyImageElement(data, property, imageDimension, position) {
61
82
  const imageUrl = util_1.ObjectUtil.getByPath(data, `viewable.mediumViewableDownloadUrl`);
62
83
  const element = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",