@contrail/documents 1.3.19 → 1.3.20-alpha.0

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.
@@ -1,4 +1,6 @@
1
1
  import { DocumentElement } from '../types';
2
+ export declare const DEFAULT_THUMBNAIL_WIDTH = 200;
3
+ export declare const MAX_CARD_WIDTH = 600;
2
4
  export declare class ItemComponentService {
3
5
  static isItemComponent(element: DocumentElement): boolean;
4
6
  static isThumbnailOnlyComponent(element: DocumentElement): boolean;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ItemComponentService = void 0;
3
+ exports.ItemComponentService = exports.MAX_CARD_WIDTH = exports.DEFAULT_THUMBNAIL_WIDTH = void 0;
4
4
  const document_element_constants_1 = require("../document-element-constants");
5
+ exports.DEFAULT_THUMBNAIL_WIDTH = 200;
6
+ exports.MAX_CARD_WIDTH = 600;
5
7
  class ItemComponentService {
6
8
  static isItemComponent(element) {
7
9
  var _a;
@@ -16,6 +18,7 @@ class ItemComponentService {
16
18
  return (!annotationElement || annotationElement.isHidden) && imageElement && !imageElement.isHidden;
17
19
  }
18
20
  static updateSizeAndPosition(propertyElements, componentElement, annotatedElements = []) {
21
+ var _a, _b, _c, _d;
19
22
  const newElements = [];
20
23
  let lastYPosition = 0;
21
24
  let width = 200;
@@ -69,6 +72,28 @@ class ItemComponentService {
69
72
  element.size.width = width;
70
73
  newElements.push(element);
71
74
  });
75
+ const cardWidth = (_a = componentElement === null || componentElement === void 0 ? void 0 : componentElement.size) === null || _a === void 0 ? void 0 : _a.width;
76
+ const imageElement = newElements === null || newElements === void 0 ? void 0 : newElements.find((e) => e.type === 'image');
77
+ const thumbnailWidth = ((_b = imageElement === null || imageElement === void 0 ? void 0 : imageElement.size) === null || _b === void 0 ? void 0 : _b.width) || exports.DEFAULT_THUMBNAIL_WIDTH;
78
+ const align = ((_d = (_c = imageElement === null || imageElement === void 0 ? void 0 : imageElement.style) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d.align) || 'center';
79
+ if (cardWidth && cardWidth > thumbnailWidth) {
80
+ let thumbnailXOffset = 0;
81
+ if (align === 'center') {
82
+ thumbnailXOffset = (cardWidth - thumbnailWidth) / 2;
83
+ }
84
+ else if (align === 'right') {
85
+ thumbnailXOffset = cardWidth - thumbnailWidth;
86
+ }
87
+ for (const element of newElements) {
88
+ if (element.type === 'image') {
89
+ element.position = Object.assign(Object.assign({}, element.position), { x: thumbnailXOffset });
90
+ }
91
+ else if (element.type === 'text' || element.type === 'annotation') {
92
+ element.size = Object.assign(Object.assign({}, element.size), { width: cardWidth });
93
+ element.position = Object.assign(Object.assign({}, element.position), { x: 0 });
94
+ }
95
+ }
96
+ }
72
97
  return newElements;
73
98
  }
74
99
  static getYMargin(element) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.3.19",
3
+ "version": "1.3.20-alpha.0",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",