@contrail/documents 1.21.0-alpha.0c990fd → 1.21.0-alpha.11da477

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.
@@ -24,12 +24,9 @@ class DocumentContainerUtil {
24
24
  var _a, _b, _c, _d, _e;
25
25
  const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
26
26
  const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
27
- if (!position) {
27
+ if (!position || !angle || !newSize || !documentElement.size) {
28
28
  return position;
29
29
  }
30
- if (!angle || !newSize || !documentElement.size) {
31
- return Object.assign({}, position);
32
- }
33
30
  const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
34
31
  const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
35
32
  const cornerOffset = (size) => {
@@ -39,8 +36,7 @@ class DocumentContainerUtil {
39
36
  };
40
37
  const before = cornerOffset(documentElement.size);
41
38
  const after = cornerOffset(newSize);
42
- const moved = { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
43
- return Number.isFinite(moved.x) && Number.isFinite(moved.y) ? moved : Object.assign({}, position);
39
+ return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
44
40
  }
45
41
  static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
46
42
  const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
@@ -48,8 +44,11 @@ class DocumentContainerUtil {
48
44
  }
49
45
  static anchorFor(documentElement, position, startElement, endElement) {
50
46
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
47
+ if (!at) {
48
+ return null;
49
+ }
51
50
  try {
52
- const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
51
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
53
52
  const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
54
53
  return DocumentContainerUtil.anchorOf(documentElement, box);
55
54
  }
@@ -32,21 +32,18 @@ class DocumentContainerService {
32
32
  }
33
33
  const containerPathsByDocumentElementId = new Map();
34
34
  const memberIdsByContainerId = new Map();
35
- const memberIdsSeen = new Map();
36
35
  for (const measured of measuredDocumentElements) {
37
36
  const documentElementId = measured.documentElement.id;
38
37
  const pathsByElementType = new Map();
39
38
  ((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
40
39
  for (const path of pathsByElementType.values()) {
41
40
  for (const containerId of path) {
42
- const seen = memberIdsSeen.get(containerId);
43
- if (!seen) {
44
- memberIdsSeen.set(containerId, new Set([documentElementId]));
45
- memberIdsByContainerId.set(containerId, [documentElementId]);
41
+ const members = memberIdsByContainerId.get(containerId);
42
+ if (members) {
43
+ members.push(documentElementId);
46
44
  }
47
- else if (!seen.has(documentElementId)) {
48
- seen.add(documentElementId);
49
- memberIdsByContainerId.get(containerId).push(documentElementId);
45
+ else {
46
+ memberIdsByContainerId.set(containerId, [documentElementId]);
50
47
  }
51
48
  }
52
49
  }
@@ -76,9 +73,6 @@ class DocumentContainerService {
76
73
  const start = ((_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
77
74
  const end = ((_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
78
75
  const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
79
- if (!width && !height && !documentElement.position) {
80
- return null;
81
- }
82
76
  return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
83
77
  }
84
78
  catch (_c) {
@@ -109,7 +103,7 @@ class DocumentContainerService {
109
103
  static enclosersOf(measured, containers) {
110
104
  return containers.filter((container) => {
111
105
  var _a;
112
- return container.id !== measured.documentElement.id &&
106
+ return container.documentElement !== measured.documentElement &&
113
107
  document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
114
108
  measured.drawOrder > container.drawOrder &&
115
109
  !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
@@ -119,7 +113,7 @@ class DocumentContainerService {
119
113
  const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
120
114
  return containers.filter((container) => {
121
115
  var _a;
122
- if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
116
+ if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
123
117
  return false;
124
118
  }
125
119
  if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
@@ -27,8 +27,6 @@ export declare enum DynamicTextDisplayFunction {
27
27
  export declare const MOVE_TO_FRAME_TEXT = "Move to a frame";
28
28
  export declare const MOVE_TO_SECTION_TEXT = "Move to a section";
29
29
  export declare const CLICK_TO_CONFIGURE = "Click to configure";
30
- export declare function placeholderForMissingContainer(entityType: string): string;
31
- export declare function isPlaceholderText(text: string): boolean;
32
30
  export declare const HARD_CODED_TEXT: {
33
31
  'project.name': string;
34
32
  'project.createdBy.email': string;
@@ -55,10 +53,7 @@ export declare class DynamicTextUtil {
55
53
  static isDynamicText(documentElement: DocumentElement): boolean;
56
54
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
57
55
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
58
- static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): {
59
- width: number;
60
- height: number;
61
- };
56
+ static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
62
57
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
63
58
  private static getItemCount;
64
59
  }
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DynamicTextUtil = exports.HARD_CODED_TEXT = exports.CLICK_TO_CONFIGURE = exports.MOVE_TO_SECTION_TEXT = exports.MOVE_TO_FRAME_TEXT = exports.DynamicTextDisplayFunction = exports.DYNAMIC_TEXT_DATA_SOURCE = void 0;
4
- exports.placeholderForMissingContainer = placeholderForMissingContainer;
5
- exports.isPlaceholderText = isPlaceholderText;
6
4
  exports.isContainerBinding = isContainerBinding;
7
5
  const types_1 = require("@contrail/types");
8
6
  const util_1 = require("@contrail/util");
@@ -30,12 +28,6 @@ var DynamicTextDisplayFunction;
30
28
  exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
31
29
  exports.MOVE_TO_SECTION_TEXT = 'Move to a section';
32
30
  exports.CLICK_TO_CONFIGURE = 'Click to configure';
33
- function placeholderForMissingContainer(entityType) {
34
- return entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
35
- }
36
- function isPlaceholderText(text) {
37
- return text === exports.MOVE_TO_FRAME_TEXT || text === exports.MOVE_TO_SECTION_TEXT || text === exports.CLICK_TO_CONFIGURE;
38
- }
39
31
  exports.HARD_CODED_TEXT = {
40
32
  'project.name': 'Project name',
41
33
  'project.createdBy.email': 'Project created by',
@@ -106,7 +98,7 @@ class DynamicTextUtil {
106
98
  }
107
99
  else {
108
100
  if (!container && !isSpecRelated) {
109
- text = placeholderForMissingContainer(entityType);
101
+ text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
110
102
  }
111
103
  else {
112
104
  if (CONTAINER_SOURCES.includes(entityType)) {
@@ -149,7 +141,7 @@ class DynamicTextUtil {
149
141
  text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
150
142
  }
151
143
  else if (!container) {
152
- text = placeholderForMissingContainer(entityType);
144
+ text = exports.MOVE_TO_FRAME_TEXT;
153
145
  }
154
146
  else {
155
147
  text = property === null || property === void 0 ? void 0 : property.label;
@@ -159,7 +151,7 @@ class DynamicTextUtil {
159
151
  text = 'n/a';
160
152
  }
161
153
  if (displayLabel &&
162
- !isPlaceholderText(text) &&
154
+ ![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
163
155
  displayFunction !== DynamicTextDisplayFunction.LABEL &&
164
156
  text !== bindingProperty) {
165
157
  text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
@@ -167,19 +159,16 @@ class DynamicTextUtil {
167
159
  return text;
168
160
  }
169
161
  static calculateSize(dynamicTextElement, entityType, text) {
170
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
171
- let size = {
172
- width: (_b = (_a = dynamicTextElement.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0,
173
- height: (_d = (_c = dynamicTextElement.size) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0,
174
- };
175
- const fontFamily = (_f = document_util_1.DocumentStyleUtil.getFirstFontFamily((_e = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _e !== void 0 ? _e : '')) !== null && _f !== void 0 ? _f : document_util_1.DEFAULT_TEXT_FONT_FAMILY;
176
- const fontSize = (_j = (dynamicTextElement.isTextTool
177
- ? (_h = (_g = dynamicTextElement.style) === null || _g === void 0 ? void 0 : _g.font) === null || _h === void 0 ? void 0 : _h.size
178
- : document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null && _j !== void 0 ? _j : document_util_1.DEFAULT_TEXT_FONT_SIZE;
162
+ var _a, _b, _c, _d, _e;
163
+ let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
164
+ const fontFamily = (_b = document_util_1.DocumentStyleUtil.getFirstFontFamily(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text)) !== null && _b !== void 0 ? _b : document_util_1.DEFAULT_TEXT_FONT_FAMILY;
165
+ const fontSize = (_e = (dynamicTextElement.isTextTool
166
+ ? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
167
+ : document_util_1.DocumentStyleUtil.getFirstFontSize(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, true))) !== null && _e !== void 0 ? _e : document_util_1.DEFAULT_TEXT_FONT_SIZE;
179
168
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
180
169
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
181
- const bold = document_util_1.DocumentStyleUtil.isBold((_k = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _k !== void 0 ? _k : '', fontFamily);
182
- const italic = document_util_1.DocumentStyleUtil.isItalic((_l = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _l !== void 0 ? _l : '');
170
+ const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
171
+ const italic = document_util_1.DocumentStyleUtil.isItalic(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text);
183
172
  const measureTextSettings = {
184
173
  fontFamily,
185
174
  fontSize: fontSizePx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.21.0-alpha.0c990fd",
3
+ "version": "1.21.0-alpha.11da477",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",