@contrail/document-generation 2.0.50 → 2.0.51

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.
Files changed (45) hide show
  1. package/README.md +2 -2
  2. package/lib/board-document-generator.d.ts +23 -23
  3. package/lib/board-document-generator.js +241 -241
  4. package/lib/components/component-generator.d.ts +6 -6
  5. package/lib/components/component-generator.js +55 -55
  6. package/lib/components/component-grid-generator.d.ts +7 -7
  7. package/lib/components/component-grid-generator.js +84 -84
  8. package/lib/components/component-util.d.ts +5 -5
  9. package/lib/components/component-util.js +43 -43
  10. package/lib/document-generator.d.ts +6 -6
  11. package/lib/document-generator.js +11 -11
  12. package/lib/frames/frame-generator.d.ts +12 -12
  13. package/lib/frames/frame-generator.js +141 -141
  14. package/lib/frames/frame.d.ts +18 -16
  15. package/lib/frames/frame.js +71 -67
  16. package/lib/frames/index.d.ts +2 -2
  17. package/lib/frames/index.js +18 -18
  18. package/lib/index.d.ts +6 -6
  19. package/lib/index.js +22 -22
  20. package/lib/info-panel/info-panel-generator.d.ts +6 -6
  21. package/lib/info-panel/info-panel-generator.js +56 -56
  22. package/lib/interfaces.d.ts +72 -72
  23. package/lib/interfaces.js +8 -8
  24. package/lib/scripts/test-board.d.ts +1 -1
  25. package/lib/scripts/test-board.js +230 -230
  26. package/lib/scripts/test-showcase.d.ts +1 -1
  27. package/lib/scripts/test-showcase.js +257 -257
  28. package/lib/showcase-frame-generator.d.ts +8 -8
  29. package/lib/showcase-frame-generator.js +44 -44
  30. package/lib/test-data.d.ts +72 -72
  31. package/lib/test-data.js +187 -187
  32. package/lib/util/document-dynamic-text-element-util.d.ts +8 -8
  33. package/lib/util/document-dynamic-text-element-util.js +77 -77
  34. package/lib/util/document-property-util.d.ts +9 -9
  35. package/lib/util/document-property-util.js +102 -102
  36. package/lib/util/document-text-element-util.d.ts +12 -12
  37. package/lib/util/document-text-element-util.js +148 -148
  38. package/lib/util/document-util.d.ts +8 -8
  39. package/lib/util/document-util.js +22 -22
  40. package/lib/util/index.d.ts +2 -2
  41. package/lib/util/index.js +18 -18
  42. package/lib/util/text-util.d.ts +4 -4
  43. package/lib/util/text-util.js +28 -28
  44. package/package.json +1 -1
  45. package/testdocument.json +25972 -25972
@@ -1,77 +1,77 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentDynamicTextElementUtil = void 0;
4
- const documents_1 = require("@contrail/documents");
5
- const util_1 = require("@contrail/util");
6
- const document_text_element_util_1 = require("./document-text-element-util");
7
- const HARD_CODED_PROPS = {
8
- createdBy: 'Created by',
9
- updatedBy: 'Updated by',
10
- 'frame.count': 'Count',
11
- 'frame.name': 'Frame name',
12
- };
13
- class DocumentDynamicTextElementUtil {
14
- static isDynamicText(element) {
15
- return element.type === 'text' && element.propertyBindings && element.propertyBindingsMetaData;
16
- }
17
- static handleDynamicText(element, dataGroup, frameTitle = null) {
18
- var _a;
19
- const displayFunction = element.propertyBindingsMetaData.displayFunction;
20
- const displayLabel = element.propertyBindingsMetaData.displayLabel;
21
- const propertyBindingsText = element.propertyBindings.text;
22
- let text = '';
23
- const entityType = propertyBindingsText.split('.')[0];
24
- const propertySlug = propertyBindingsText.split('.')[1];
25
- let property;
26
- let type;
27
- if (!['showcase', 'board', 'project'].includes(entityType)) {
28
- if (entityType === 'frame') {
29
- if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
30
- text = HARD_CODED_PROPS[propertyBindingsText];
31
- }
32
- else {
33
- if (propertySlug === 'count') {
34
- text = dataGroup.data.length;
35
- }
36
- else {
37
- text = frameTitle || dataGroup.name;
38
- }
39
- }
40
- }
41
- else {
42
- if (dataGroup.data.length === 0) {
43
- return propertyBindingsText;
44
- }
45
- type = this.typeMap[entityType];
46
- property = type.typeProperties.find(p => p.slug === propertySlug);
47
- if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
48
- text = (property === null || property === void 0 ? void 0 : property.label) || HARD_CODED_PROPS[propertySlug] || `${type.label} name`;
49
- }
50
- else {
51
- const elementValues = this.getPropertyValuesForElements(dataGroup.data, propertyBindingsText);
52
- text = documents_1.DynamicTextUtil.getTextFromFrameMemberValues(displayFunction, property, elementValues);
53
- }
54
- }
55
- if (text === undefined || text === null || text === '') {
56
- text = 'n/a';
57
- }
58
- if (displayLabel && displayFunction !== documents_1.DynamicTextDisplayFunction.LABEL) {
59
- text = `${(property === null || property === void 0 ? void 0 : property.label) || `${type === null || type === void 0 ? void 0 : type.label} name` || HARD_CODED_PROPS[propertySlug]}: ${text}`;
60
- }
61
- }
62
- if (((_a = element.text) === null || _a === void 0 ? void 0 : _a.toString().indexOf('</')) > -1) {
63
- const styleDefinition = document_text_element_util_1.DocumentTextElementUtil.extractStyleFromInline(element.text);
64
- text = document_text_element_util_1.DocumentTextElementUtil.applyInLineStyling(text, styleDefinition);
65
- }
66
- element.text = text;
67
- }
68
- static getPropertyValuesForElements(elements, propertyKey) {
69
- const values = [];
70
- elements.forEach(el => {
71
- const propertyValue = util_1.ObjectUtil.getByPath(el, propertyKey);
72
- values.push(propertyValue);
73
- });
74
- return values;
75
- }
76
- }
77
- exports.DocumentDynamicTextElementUtil = DocumentDynamicTextElementUtil;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentDynamicTextElementUtil = void 0;
4
+ const documents_1 = require("@contrail/documents");
5
+ const util_1 = require("@contrail/util");
6
+ const document_text_element_util_1 = require("./document-text-element-util");
7
+ const HARD_CODED_PROPS = {
8
+ createdBy: 'Created by',
9
+ updatedBy: 'Updated by',
10
+ 'frame.count': 'Count',
11
+ 'frame.name': 'Frame name',
12
+ };
13
+ class DocumentDynamicTextElementUtil {
14
+ static isDynamicText(element) {
15
+ return element.type === 'text' && element.propertyBindings && element.propertyBindingsMetaData;
16
+ }
17
+ static handleDynamicText(element, dataGroup, frameTitle = null) {
18
+ var _a;
19
+ const displayFunction = element.propertyBindingsMetaData.displayFunction;
20
+ const displayLabel = element.propertyBindingsMetaData.displayLabel;
21
+ const propertyBindingsText = element.propertyBindings.text;
22
+ let text = '';
23
+ const entityType = propertyBindingsText.split('.')[0];
24
+ const propertySlug = propertyBindingsText.split('.')[1];
25
+ let property;
26
+ let type;
27
+ if (!['showcase', 'board', 'project'].includes(entityType)) {
28
+ if (entityType === 'frame') {
29
+ if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
30
+ text = HARD_CODED_PROPS[propertyBindingsText];
31
+ }
32
+ else {
33
+ if (propertySlug === 'count') {
34
+ text = dataGroup.data.length;
35
+ }
36
+ else {
37
+ text = frameTitle || dataGroup.name;
38
+ }
39
+ }
40
+ }
41
+ else {
42
+ if (dataGroup.data.length === 0) {
43
+ return propertyBindingsText;
44
+ }
45
+ type = this.typeMap[entityType];
46
+ property = type.typeProperties.find((p) => p.slug === propertySlug);
47
+ if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
48
+ text = (property === null || property === void 0 ? void 0 : property.label) || HARD_CODED_PROPS[propertySlug] || `${type.label} name`;
49
+ }
50
+ else {
51
+ const elementValues = this.getPropertyValuesForElements(dataGroup.data, propertyBindingsText);
52
+ text = documents_1.DynamicTextUtil.getTextFromFrameMemberValues(displayFunction, property, elementValues);
53
+ }
54
+ }
55
+ if (text === undefined || text === null || text === '') {
56
+ text = 'n/a';
57
+ }
58
+ if (displayLabel && displayFunction !== documents_1.DynamicTextDisplayFunction.LABEL) {
59
+ text = `${(property === null || property === void 0 ? void 0 : property.label) || `${type === null || type === void 0 ? void 0 : type.label} name` || HARD_CODED_PROPS[propertySlug]}: ${text}`;
60
+ }
61
+ }
62
+ if (((_a = element.text) === null || _a === void 0 ? void 0 : _a.toString().indexOf('</')) > -1) {
63
+ const styleDefinition = document_text_element_util_1.DocumentTextElementUtil.extractStyleFromInline(element.text);
64
+ text = document_text_element_util_1.DocumentTextElementUtil.applyInLineStyling(text, styleDefinition);
65
+ }
66
+ element.text = text;
67
+ }
68
+ static getPropertyValuesForElements(elements, propertyKey) {
69
+ const values = [];
70
+ elements.forEach((el) => {
71
+ const propertyValue = util_1.ObjectUtil.getByPath(el, propertyKey);
72
+ values.push(propertyValue);
73
+ });
74
+ return values;
75
+ }
76
+ }
77
+ exports.DocumentDynamicTextElementUtil = DocumentDynamicTextElementUtil;
@@ -1,9 +1,9 @@
1
- import { DocumentPropertyDefinition } from '../interfaces';
2
- import { DocumentElement, PositionDefinition, SizeDefinition } from '@contrail/documents';
3
- import { PropertyValueFormatter } from '@contrail/types';
4
- export declare class DocumentPropertyUtil {
5
- static generatePropertyElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, imageDimension: SizeDefinition, isComponent?: boolean): Array<DocumentElement>;
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;
8
- static generatePropertyImageElement(data: any, property: DocumentPropertyDefinition, imageDimension: SizeDefinition, position: PositionDefinition): DocumentElement;
9
- }
1
+ import { DocumentPropertyDefinition } from '../interfaces';
2
+ import { DocumentElement, PositionDefinition, SizeDefinition } from '@contrail/documents';
3
+ import { PropertyValueFormatter } from '@contrail/types';
4
+ export declare class DocumentPropertyUtil {
5
+ static generatePropertyElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, imageDimension: SizeDefinition, isComponent?: boolean): Array<DocumentElement>;
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;
8
+ static generatePropertyImageElement(data: any, property: DocumentPropertyDefinition, imageDimension: SizeDefinition, position: PositionDefinition): DocumentElement;
9
+ }
@@ -1,102 +1,102 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentPropertyUtil = void 0;
4
- const util_1 = require("@contrail/util");
5
- const documents_1 = require("@contrail/documents");
6
- const types_1 = require("@contrail/types");
7
- const document_text_element_util_1 = require("./document-text-element-util");
8
- const text_util_1 = require("./text-util");
9
- class DocumentPropertyUtil {
10
- static generatePropertyElements(data, properties, options, startingPosition, imageDimension, isComponent = false) {
11
- var _a, _b;
12
- let yPosition = startingPosition.y || 0;
13
- const xPosition = startingPosition.x || 0;
14
- const elements = [];
15
- const formatter = new types_1.PropertyValueFormatter();
16
- let index = 0;
17
- for (let property of properties) {
18
- let element;
19
- if (index === 0 && property.slug === 'annotation') {
20
- yPosition = -15;
21
- }
22
- if (property.propertyDefinition) {
23
- const fontSize = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
24
- const PT_TO_PX = 1.3;
25
- const LINE_HEIGHT = 1.4;
26
- const PADDING = 1.6;
27
- let height = fontSize * PT_TO_PX * LINE_HEIGHT * PADDING;
28
- options.size = options.size || {};
29
- options.size.height = height;
30
- element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
31
- yPosition += element.size.height - 10;
32
- }
33
- else if (property.slug === 'annotation') {
34
- element = DocumentPropertyUtil.generatePropertyAnnotationElement(data, property, property.size, {
35
- x: xPosition,
36
- y: yPosition,
37
- });
38
- yPosition += element.size.height - 10;
39
- }
40
- else {
41
- const imageHeight = imageDimension.height || imageDimension.width || 125;
42
- const imageWidth = imageDimension.width || 125;
43
- element = DocumentPropertyUtil.generatePropertyImageElement(data, property, { width: imageWidth, height: imageHeight }, { x: xPosition, y: yPosition });
44
- yPosition += imageHeight;
45
- }
46
- elements.push(element);
47
- index++;
48
- }
49
- return elements;
50
- }
51
- static generatePropertyTextElement(model, property, options, formatter, position, isComponent = false) {
52
- var _a;
53
- const modelKey = `${util_1.StringUtil.convertToCamelCase(property.typeRootSlug)}.${property.propertyDefinition.slug}`;
54
- const value = util_1.ObjectUtil.getByPath(model, modelKey);
55
- let display = formatter.formatValueForProperty(value, property.propertyDefinition);
56
- if (!isComponent) {
57
- const height = text_util_1.TextUtil.getHeightByTextWidth(display, property, options.size.width);
58
- options.size.height = height;
59
- }
60
- if (!isComponent && property.includeLabel) {
61
- display = property.propertyDefinition.label + ': ' + display;
62
- }
63
- const mergedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { style: property.style || {} });
64
- mergedOptions.position = position;
65
- const useInlineFormatting = isComponent === false;
66
- let element = document_text_element_util_1.DocumentTextElementUtil.generateTextElement(display, mergedOptions, useInlineFormatting, !isComponent);
67
- if (property.includeLabel) {
68
- element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
69
- }
70
- element.propertyBindings = { text: modelKey };
71
- return element;
72
- }
73
- static generatePropertyAnnotationElement(data, property, size, position) {
74
- const element = {
75
- type: 'annotation',
76
- size: size,
77
- propertyBindings: { annotation: 'annotation' },
78
- position,
79
- };
80
- if (property.isHidden) {
81
- element.isHidden = property.isHidden;
82
- }
83
- return element;
84
- }
85
- static generatePropertyImageElement(data, property, imageDimension, position) {
86
- var _a;
87
- const imageUrl = (_a = data === null || data === void 0 ? void 0 : data.viewable) === null || _a === void 0 ? void 0 : _a.mediumViewableDownloadUrl;
88
- const element = {
89
- type: 'image',
90
- size: imageDimension,
91
- propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
92
- url: imageUrl,
93
- position,
94
- };
95
- if (property.isHidden) {
96
- element.isHidden = property.isHidden;
97
- }
98
- documents_1.DocumentElementPropertyBindingHandler.bindPropertiesToElement(element, data);
99
- return element;
100
- }
101
- }
102
- exports.DocumentPropertyUtil = DocumentPropertyUtil;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentPropertyUtil = void 0;
4
+ const util_1 = require("@contrail/util");
5
+ const documents_1 = require("@contrail/documents");
6
+ const types_1 = require("@contrail/types");
7
+ const document_text_element_util_1 = require("./document-text-element-util");
8
+ const text_util_1 = require("./text-util");
9
+ class DocumentPropertyUtil {
10
+ static generatePropertyElements(data, properties, options, startingPosition, imageDimension, isComponent = false) {
11
+ var _a, _b;
12
+ let yPosition = startingPosition.y || 0;
13
+ const xPosition = startingPosition.x || 0;
14
+ const elements = [];
15
+ const formatter = new types_1.PropertyValueFormatter();
16
+ let index = 0;
17
+ for (let property of properties) {
18
+ let element;
19
+ if (index === 0 && property.slug === 'annotation') {
20
+ yPosition = -15;
21
+ }
22
+ if (property.propertyDefinition) {
23
+ const fontSize = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
24
+ const PT_TO_PX = 1.3;
25
+ const LINE_HEIGHT = 1.4;
26
+ const PADDING = 1.6;
27
+ let height = fontSize * PT_TO_PX * LINE_HEIGHT * PADDING;
28
+ options.size = options.size || {};
29
+ options.size.height = height;
30
+ element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
31
+ yPosition += element.size.height - 10;
32
+ }
33
+ else if (property.slug === 'annotation') {
34
+ element = DocumentPropertyUtil.generatePropertyAnnotationElement(data, property, property.size, {
35
+ x: xPosition,
36
+ y: yPosition,
37
+ });
38
+ yPosition += element.size.height - 10;
39
+ }
40
+ else {
41
+ const imageHeight = imageDimension.height || imageDimension.width || 125;
42
+ const imageWidth = imageDimension.width || 125;
43
+ element = DocumentPropertyUtil.generatePropertyImageElement(data, property, { width: imageWidth, height: imageHeight }, { x: xPosition, y: yPosition });
44
+ yPosition += imageHeight;
45
+ }
46
+ elements.push(element);
47
+ index++;
48
+ }
49
+ return elements;
50
+ }
51
+ static generatePropertyTextElement(model, property, options, formatter, position, isComponent = false) {
52
+ var _a;
53
+ const modelKey = `${util_1.StringUtil.convertToCamelCase(property.typeRootSlug)}.${property.propertyDefinition.slug}`;
54
+ const value = util_1.ObjectUtil.getByPath(model, modelKey);
55
+ let display = formatter.formatValueForProperty(value, property.propertyDefinition);
56
+ if (!isComponent) {
57
+ const height = text_util_1.TextUtil.getHeightByTextWidth(display, property, options.size.width);
58
+ options.size.height = height;
59
+ }
60
+ if (!isComponent && property.includeLabel) {
61
+ display = property.propertyDefinition.label + ': ' + display;
62
+ }
63
+ const mergedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { style: property.style || {} });
64
+ mergedOptions.position = position;
65
+ const useInlineFormatting = isComponent === false;
66
+ let element = document_text_element_util_1.DocumentTextElementUtil.generateTextElement(display, mergedOptions, useInlineFormatting, !isComponent);
67
+ if (property.includeLabel) {
68
+ element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
69
+ }
70
+ element.propertyBindings = { text: modelKey };
71
+ return element;
72
+ }
73
+ static generatePropertyAnnotationElement(data, property, size, position) {
74
+ const element = {
75
+ type: 'annotation',
76
+ size: size,
77
+ propertyBindings: { annotation: 'annotation' },
78
+ position,
79
+ };
80
+ if (property.isHidden) {
81
+ element.isHidden = property.isHidden;
82
+ }
83
+ return element;
84
+ }
85
+ static generatePropertyImageElement(data, property, imageDimension, position) {
86
+ var _a;
87
+ const imageUrl = (_a = data === null || data === void 0 ? void 0 : data.viewable) === null || _a === void 0 ? void 0 : _a.mediumViewableDownloadUrl;
88
+ const element = {
89
+ type: 'image',
90
+ size: imageDimension,
91
+ propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
92
+ url: imageUrl,
93
+ position,
94
+ };
95
+ if (property.isHidden) {
96
+ element.isHidden = property.isHidden;
97
+ }
98
+ documents_1.DocumentElementPropertyBindingHandler.bindPropertiesToElement(element, data);
99
+ return element;
100
+ }
101
+ }
102
+ exports.DocumentPropertyUtil = DocumentPropertyUtil;
@@ -1,12 +1,12 @@
1
- import { DocumentElement, StyleDefinition } from '@contrail/documents';
2
- export declare class DocumentTextElementUtil {
3
- static generateTextElement(textValue: any, options: any, applyInlineFormatting?: boolean, sanitizeHTML?: boolean): DocumentElement;
4
- static applyInLineStyling(text: any, style: StyleDefinition): any;
5
- static extractStyleFromInline(text: string): StyleDefinition;
6
- static extractFontSizeFromHTML(text: any): number;
7
- static extractColorFromHTML(text: any): string;
8
- static extractTextDecorationFromHTML(text: any): string;
9
- static extractFontFromHTML(text: any): any;
10
- static extractTextStyleItalicFromHTML(text: any): string;
11
- static extractTextStyleStrikethroughFromHTML(text: any): string;
12
- }
1
+ import { DocumentElement, StyleDefinition } from '@contrail/documents';
2
+ export declare class DocumentTextElementUtil {
3
+ static generateTextElement(textValue: any, options: any, applyInlineFormatting?: boolean, sanitizeHTML?: boolean): DocumentElement;
4
+ static applyInLineStyling(text: any, style: StyleDefinition): any;
5
+ static extractStyleFromInline(text: string): StyleDefinition;
6
+ static extractFontSizeFromHTML(text: any): number;
7
+ static extractColorFromHTML(text: any): string;
8
+ static extractTextDecorationFromHTML(text: any): string;
9
+ static extractFontFromHTML(text: any): any;
10
+ static extractTextStyleItalicFromHTML(text: any): string;
11
+ static extractTextStyleStrikethroughFromHTML(text: any): string;
12
+ }