@contrail/documents 1.3.18 → 1.3.20-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,6 +1,9 @@
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;
6
+ static isThumbnailOnlyComponent(element: DocumentElement): boolean;
4
7
  static updateSizeAndPosition(propertyElements: any[], componentElement: DocumentElement, annotatedElements?: any[]): any;
5
8
  private static getYMargin;
6
9
  private static calculateAnnotationHeight;
@@ -1,13 +1,24 @@
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;
8
10
  return element && element.type === 'component' && ((_a = element.modelBindings) === null || _a === void 0 ? void 0 : _a.item);
9
11
  }
12
+ static isThumbnailOnlyComponent(element) {
13
+ var _a;
14
+ if (!((_a = element === null || element === void 0 ? void 0 : element.elements) === null || _a === void 0 ? void 0 : _a.length) || element.elements.length > 2)
15
+ return false;
16
+ const annotationElement = element.elements.find((e) => e.type == 'annotation');
17
+ const imageElement = element.elements.find((e) => e.type == 'image');
18
+ return (!annotationElement || annotationElement.isHidden) && imageElement && !imageElement.isHidden;
19
+ }
10
20
  static updateSizeAndPosition(propertyElements, componentElement, annotatedElements = []) {
21
+ var _a, _b, _c, _d;
11
22
  const newElements = [];
12
23
  let lastYPosition = 0;
13
24
  let width = 200;
@@ -61,6 +72,28 @@ class ItemComponentService {
61
72
  element.size.width = width;
62
73
  newElements.push(element);
63
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
+ }
64
97
  return newElements;
65
98
  }
66
99
  static getYMargin(element) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.3.18",
3
+ "version": "1.3.20-0",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",