@contrail/documents 1.0.120 → 1.0.122

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.
@@ -218,9 +218,6 @@ export declare const ITEM_VIEW_TEMPLATE_V3: {
218
218
  };
219
219
  })[];
220
220
  };
221
- export declare const COLOR_PADDING = 5;
222
- export declare const COLOR_FONT_SIZE = 8;
223
- export declare const COLOR_WIDTH = 140;
224
221
  export declare const COLOR_VIEW_TEMPLATE: {
225
222
  elements: ({
226
223
  type: string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComponentRegistry = exports.PATTERN_VIEW = exports.COLOR_VIEW = exports.ITEM_VIEW_V3 = exports.ITEM_VIEW_V2 = exports.ITEM_VIEW = exports.PATTERN_VIEW_TEMPLATE = exports.COLOR_VIEW_TEMPLATE = exports.COLOR_WIDTH = exports.COLOR_FONT_SIZE = exports.COLOR_PADDING = exports.ITEM_VIEW_TEMPLATE_V3 = exports.ITEM_VIEW_TEMPLATE_V2 = exports.ITEM_VIEW_TEMPLATE = void 0;
3
+ exports.ComponentRegistry = exports.PATTERN_VIEW = exports.COLOR_VIEW = exports.ITEM_VIEW_V3 = exports.ITEM_VIEW_V2 = exports.ITEM_VIEW = exports.PATTERN_VIEW_TEMPLATE = exports.COLOR_VIEW_TEMPLATE = exports.ITEM_VIEW_TEMPLATE_V3 = exports.ITEM_VIEW_TEMPLATE_V2 = exports.ITEM_VIEW_TEMPLATE = void 0;
4
+ const document_element_constants_1 = require("../document-element-constants");
4
5
  const types_1 = require("../types");
5
6
  exports.ITEM_VIEW_TEMPLATE = {
6
7
  elements: [
@@ -114,17 +115,14 @@ exports.ITEM_VIEW_TEMPLATE_V3 = {
114
115
  },
115
116
  ],
116
117
  };
117
- exports.COLOR_PADDING = 5;
118
- exports.COLOR_FONT_SIZE = 8;
119
- exports.COLOR_WIDTH = 140;
120
118
  exports.COLOR_VIEW_TEMPLATE = {
121
119
  elements: [
122
120
  {
123
121
  type: 'rectangle',
124
122
  position: { x: 0, y: 0 },
125
123
  size: {
126
- width: exports.COLOR_WIDTH + exports.COLOR_PADDING * 2,
127
- height: exports.COLOR_WIDTH + exports.COLOR_FONT_SIZE + exports.COLOR_PADDING * 4,
124
+ width: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_PADDING * 2,
125
+ height: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_FONT_SIZE + document_element_constants_1.COLOR_PADDING * 4,
128
126
  },
129
127
  style: {
130
128
  backgroundColor: '#FFFFFF',
@@ -137,8 +135,8 @@ exports.COLOR_VIEW_TEMPLATE = {
137
135
  },
138
136
  {
139
137
  type: 'rectangle',
140
- position: { x: exports.COLOR_PADDING, y: exports.COLOR_PADDING },
141
- size: { height: exports.COLOR_WIDTH, width: exports.COLOR_WIDTH },
138
+ position: { x: document_element_constants_1.COLOR_PADDING, y: document_element_constants_1.COLOR_PADDING },
139
+ size: { height: document_element_constants_1.COLOR_WIDTH, width: document_element_constants_1.COLOR_WIDTH },
142
140
  style: {
143
141
  border: {
144
142
  width: 0,
@@ -149,14 +147,14 @@ exports.COLOR_VIEW_TEMPLATE = {
149
147
  },
150
148
  {
151
149
  type: 'text',
152
- position: { x: exports.COLOR_PADDING, y: exports.COLOR_WIDTH + exports.COLOR_PADDING * 2 },
150
+ position: { x: document_element_constants_1.COLOR_PADDING, y: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_PADDING * 2 },
153
151
  size: {
154
- height: exports.COLOR_FONT_SIZE + exports.COLOR_PADDING,
155
- width: exports.COLOR_WIDTH,
152
+ height: document_element_constants_1.COLOR_FONT_SIZE + document_element_constants_1.COLOR_PADDING,
153
+ width: document_element_constants_1.COLOR_WIDTH,
156
154
  },
157
155
  style: {
158
156
  font: {
159
- size: exports.COLOR_FONT_SIZE,
157
+ size: document_element_constants_1.COLOR_FONT_SIZE,
160
158
  },
161
159
  },
162
160
  propertyBindings: { text: 'color.name' },
@@ -169,8 +167,8 @@ exports.PATTERN_VIEW_TEMPLATE = {
169
167
  type: 'rectangle',
170
168
  position: { x: 0, y: 0 },
171
169
  size: {
172
- width: exports.COLOR_WIDTH + exports.COLOR_PADDING * 2,
173
- height: exports.COLOR_WIDTH + exports.COLOR_FONT_SIZE + exports.COLOR_PADDING * 4,
170
+ width: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_PADDING * 2,
171
+ height: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_FONT_SIZE + document_element_constants_1.COLOR_PADDING * 4,
174
172
  },
175
173
  style: {
176
174
  backgroundColor: '#FFFFFF',
@@ -183,21 +181,21 @@ exports.PATTERN_VIEW_TEMPLATE = {
183
181
  },
184
182
  {
185
183
  type: 'image',
186
- position: { x: exports.COLOR_PADDING, y: exports.COLOR_PADDING },
187
- size: { height: exports.COLOR_WIDTH, width: exports.COLOR_WIDTH },
184
+ position: { x: document_element_constants_1.COLOR_PADDING, y: document_element_constants_1.COLOR_PADDING },
185
+ size: { height: document_element_constants_1.COLOR_WIDTH, width: document_element_constants_1.COLOR_WIDTH },
188
186
  style: { background: { size: types_1.BackgroundSizeType.CONTAIN } },
189
187
  propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
190
188
  },
191
189
  {
192
190
  type: 'text',
193
- position: { x: exports.COLOR_PADDING, y: exports.COLOR_WIDTH + exports.COLOR_PADDING * 2 },
191
+ position: { x: document_element_constants_1.COLOR_PADDING, y: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_PADDING * 2 },
194
192
  size: {
195
- height: exports.COLOR_FONT_SIZE + exports.COLOR_PADDING,
196
- width: exports.COLOR_WIDTH,
193
+ height: document_element_constants_1.COLOR_FONT_SIZE + document_element_constants_1.COLOR_PADDING,
194
+ width: document_element_constants_1.COLOR_WIDTH,
197
195
  },
198
196
  style: {
199
197
  font: {
200
- size: exports.COLOR_FONT_SIZE,
198
+ size: document_element_constants_1.COLOR_FONT_SIZE,
201
199
  },
202
200
  },
203
201
  propertyBindings: { text: 'color.name' },
@@ -1,4 +1,10 @@
1
+ import { SizeDefinition } from './types';
2
+ import { DocumentElement } from './types/document-element';
1
3
  export declare class DocumentElementComponentSizeHandler {
2
- static updateSizeAndPositionForPropertyElements(propertyElements: any[]): any;
4
+ static updateSizeAndPositionForPropertyElements(propertyElements: any[], componentElement: DocumentElement, annotatedElements?: any[]): any;
3
5
  private static getYMargin;
6
+ private static calculateAnnotationHeight;
7
+ static getColorRectangle(element: DocumentElement): DocumentElement;
8
+ static getColorContainer(element: DocumentElement): DocumentElement;
9
+ static updateSizeAndPositionForColorElements(elements: any, size?: SizeDefinition): any;
4
10
  }
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentElementComponentSizeHandler = void 0;
4
+ const document_element_constants_1 = require("./document-element-constants");
4
5
  class DocumentElementComponentSizeHandler {
5
- static updateSizeAndPositionForPropertyElements(propertyElements) {
6
+ static updateSizeAndPositionForPropertyElements(propertyElements, componentElement, annotatedElements = []) {
6
7
  const newElements = [];
7
8
  let lastYPosition = 0;
8
9
  let width = 200;
@@ -10,10 +11,15 @@ class DocumentElementComponentSizeHandler {
10
11
  return element.type === 'image';
11
12
  });
12
13
  if (imageElements.length > 0) {
13
- width = imageElements[0].size.width;
14
+ if (imageElements[0].size) {
15
+ width = imageElements[0].size.width;
16
+ }
17
+ else {
18
+ imageElements[0].size = { width: 200, height: 200 };
19
+ }
14
20
  }
15
- propertyElements.forEach((element) => {
16
- var _a;
21
+ propertyElements.forEach((element, index) => {
22
+ var _a, _b;
17
23
  if (element.enabled === false) {
18
24
  return;
19
25
  }
@@ -31,6 +37,23 @@ class DocumentElementComponentSizeHandler {
31
37
  }
32
38
  element.size.height = element.style.font.size + 6;
33
39
  }
40
+ else if (element.type === 'annotation') {
41
+ if (!((_b = element.style) === null || _b === void 0 ? void 0 : _b.font)) {
42
+ element.style = Object.assign(Object.assign({}, element.style), { font: { size: document_element_constants_1.ANNOTATION_IMG_SIZE } });
43
+ }
44
+ if (index === 0) {
45
+ element.position = {
46
+ x: 0,
47
+ y: -15,
48
+ };
49
+ lastYPosition = element.position.y;
50
+ }
51
+ const annotationHeight = this.calculateAnnotationHeight(element, componentElement, width, annotatedElements);
52
+ lastYPosition = lastYPosition + annotationHeight;
53
+ if (annotationHeight === 0 && index === 0) {
54
+ lastYPosition = lastYPosition + document_element_constants_1.ANNOTATION_IMG_SIZE;
55
+ }
56
+ }
34
57
  element.size.width = width;
35
58
  newElements.push(element);
36
59
  });
@@ -51,5 +74,83 @@ class DocumentElementComponentSizeHandler {
51
74
  }
52
75
  return marginY;
53
76
  }
77
+ static calculateAnnotationHeight(element, componentElement, width, annotatedElements = []) {
78
+ var _a, _b;
79
+ const annotationSize = ((_b = (_a = element.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || document_element_constants_1.ANNOTATION_IMG_SIZE;
80
+ let height = annotationSize + document_element_constants_1.ANNOTATION_PADDING_Y;
81
+ let xPos = 0;
82
+ const annotatedElement = annotatedElements.find((elem) => elem.id === componentElement.id);
83
+ if (!annotatedElement || element.isHidden) {
84
+ return height;
85
+ }
86
+ const annotations = annotatedElement.annotations.filter((annotation) => annotation.category === 'property');
87
+ if (annotations.length > 0) {
88
+ let count = 0;
89
+ annotations === null || annotations === void 0 ? void 0 : annotations.forEach((annotation) => {
90
+ if ((count + 1) * annotationSize * 1.25 > width) {
91
+ count = 0;
92
+ xPos = -width * 0.5;
93
+ height = height + annotationSize + document_element_constants_1.ANNOTATION_PADDING_Y;
94
+ }
95
+ xPos = xPos + annotationSize * 1.25;
96
+ count++;
97
+ });
98
+ }
99
+ return height;
100
+ }
101
+ static getColorRectangle(element) {
102
+ var _a;
103
+ return (_a = element.elements) === null || _a === void 0 ? void 0 : _a.find((e) => ['rectangle', 'image'].indexOf(e.type) !== -1 && e.propertyBindings);
104
+ }
105
+ static getColorContainer(element) {
106
+ var _a;
107
+ return (_a = element.elements) === null || _a === void 0 ? void 0 : _a.find((e) => ['rectangle'].indexOf(e.type) !== -1 && !e.propertyBindings);
108
+ }
109
+ static updateSizeAndPositionForColorElements(elements, size) {
110
+ var _a, _b, _c, _d;
111
+ const padding = document_element_constants_1.COLOR_PADDING;
112
+ const container = this.getColorContainer(elements);
113
+ const colorRect = this.getColorRectangle(elements);
114
+ if (!container || !colorRect)
115
+ throw new Error('Invalid color element');
116
+ const width = (_a = size === null || size === void 0 ? void 0 : size.width) !== null && _a !== void 0 ? _a : (_b = colorRect === null || colorRect === void 0 ? void 0 : colorRect.size) === null || _b === void 0 ? void 0 : _b.width;
117
+ const height = (_c = size === null || size === void 0 ? void 0 : size.height) !== null && _c !== void 0 ? _c : (_d = colorRect === null || colorRect === void 0 ? void 0 : colorRect.size) === null || _d === void 0 ? void 0 : _d.height;
118
+ const newElements = [];
119
+ let lastYPosition = 0;
120
+ elements.forEach((element) => {
121
+ var _a;
122
+ if ((element === null || element === void 0 ? void 0 : element.enabled) === false) {
123
+ return;
124
+ }
125
+ element.position = { x: padding, y: lastYPosition };
126
+ if (element.type === 'rectangle' || element.type === 'image') {
127
+ if (!(element === null || element === void 0 ? void 0 : element.propertyBindings)) {
128
+ lastYPosition = lastYPosition + padding;
129
+ return;
130
+ }
131
+ element.size = { width, height };
132
+ lastYPosition = lastYPosition + height + padding;
133
+ }
134
+ else if (element.type === 'text') {
135
+ if (!((_a = element.style) === null || _a === void 0 ? void 0 : _a.font)) {
136
+ element.style = Object.assign(Object.assign({}, element.style), { font: { size: document_element_constants_1.COLOR_FONT_SIZE } });
137
+ }
138
+ if (!(element === null || element === void 0 ? void 0 : element.size)) {
139
+ element.size = {};
140
+ }
141
+ element.size.height = element.style.font.size + padding;
142
+ element.size.width = width;
143
+ lastYPosition = lastYPosition + element.size.height;
144
+ }
145
+ newElements.push(element);
146
+ });
147
+ container.size = {
148
+ width: width + padding * 2,
149
+ height: lastYPosition + padding,
150
+ };
151
+ container.position = { x: 0, y: 0 };
152
+ newElements.unshift(container);
153
+ return newElements;
154
+ }
54
155
  }
55
156
  exports.DocumentElementComponentSizeHandler = DocumentElementComponentSizeHandler;
@@ -0,0 +1,5 @@
1
+ export declare const ANNOTATION_IMG_SIZE = 15;
2
+ export declare const ANNOTATION_PADDING_Y = 8;
3
+ export declare const COLOR_PADDING = 5;
4
+ export declare const COLOR_FONT_SIZE = 8;
5
+ export declare const COLOR_WIDTH = 140;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.COLOR_WIDTH = exports.COLOR_FONT_SIZE = exports.COLOR_PADDING = exports.ANNOTATION_PADDING_Y = exports.ANNOTATION_IMG_SIZE = void 0;
4
+ exports.ANNOTATION_IMG_SIZE = 15;
5
+ exports.ANNOTATION_PADDING_Y = 8;
6
+ exports.COLOR_PADDING = 5;
7
+ exports.COLOR_FONT_SIZE = 8;
8
+ exports.COLOR_WIDTH = 140;
@@ -6,6 +6,7 @@ const nanoid_1 = require("nanoid");
6
6
  const components_1 = require("./components/components");
7
7
  const document_element_property_binding_handler_1 = require("./document-element-property-binding-handler");
8
8
  const document_table_1 = require("@contrail/document-table");
9
+ const document_element_constants_1 = require("./document-element-constants");
9
10
  class DocumentElementFactory {
10
11
  static initNewElement(type) {
11
12
  const element = {
@@ -55,8 +56,10 @@ class DocumentElementFactory {
55
56
  static createColorComponent(model, modelBindings, options) {
56
57
  var _a;
57
58
  return DocumentElementFactory.createComponent(((_a = model === null || model === void 0 ? void 0 : model.color) === null || _a === void 0 ? void 0 : _a.primaryViewableId) ? 'pattern-view' : 'color-view', model, modelBindings, Object.assign({
58
- size: components_1.COLOR_WIDTH + components_1.COLOR_PADDING * 2,
59
- height: components_1.COLOR_WIDTH + components_1.COLOR_FONT_SIZE + components_1.COLOR_PADDING * 4,
59
+ size: {
60
+ width: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_PADDING * 2,
61
+ height: document_element_constants_1.COLOR_WIDTH + document_element_constants_1.COLOR_FONT_SIZE + document_element_constants_1.COLOR_PADDING * 4,
62
+ },
60
63
  }, options));
61
64
  }
62
65
  static createComponent(componentType, model, modelBindings, options) {
package/lib/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './document-element-component-size-handler';
6
6
  export * from './document-action';
7
7
  export * from './util/measure-text/measure-text';
8
8
  export * from './util/dynamic-text/dynamic-text-util';
9
+ export * from './document-element-constants';
package/lib/index.js CHANGED
@@ -22,3 +22,4 @@ __exportStar(require("./document-element-component-size-handler"), exports);
22
22
  __exportStar(require("./document-action"), exports);
23
23
  __exportStar(require("./util/measure-text/measure-text"), exports);
24
24
  __exportStar(require("./util/dynamic-text/dynamic-text-util"), exports);
25
+ __exportStar(require("./document-element-constants"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.0.120",
3
+ "version": "1.0.122",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",