@contrail/documents 2.4.0-alpha.cb23d8e → 2.4.0-alpha.e296d62

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.
package/CHANGELOG.md CHANGED
@@ -13,67 +13,54 @@ Also shipped on the 1.x line as 1.21.0.
13
13
 
14
14
  - `DocumentContainerService.buildIndex` and `DocumentContainerIndex` — which containers hold which
15
15
  elements, for one document, resolved once and read back by lookup. A container is a frame or a
16
- section, described by a `ContainerKind` carrying `elementType`, `nests` and `layer`. An element
17
- belongs to the container whose box covers its anchor point and which is drawn below it. Nesting
18
- gives a path with one container per depth, the later-drawn one winning where two cross. A
19
- container is only ever content of a kind layered behind it, so a frame belongs to a section and a
20
- section never to a frame. Shapes wider and taller than the container, and groups holding it, are
21
- excluded.
22
- - `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
23
- `document-element-constants`, so the rule above has one definition rather than one per app.
24
- - `DocumentContainerUtil` — the container geometry as statics, with `anchorFor` for a caller
25
- holding an element rather than a measured box.
26
- - `positionKeepingAnchor` — where an element has to sit for its drawn corner to land where it did
27
- before a resize. Rotation turns about the centre and the centre moves with the size, so a rotated
28
- element resized about its stored position drags its corner along with it. The board already makes
29
- this move; a server recomputing a dynamic text has to make the same one, or the corner is not the
30
- fixed point the anchor rule needs.
16
+ section; membership is geometry, draw order and kind, with nothing inherited and nothing stored.
17
+ The rule is written out in `src/containers/DOCUMENT_CONTAINERS_SPEC.md`, which the code is
18
+ measured against.
19
+ - `DocumentContainerUtil` — the container geometry as statics. `anchorFor` answers "which point is
20
+ this element placed by" for a caller holding an element rather than a measured box, and
21
+ `resizeKeepingAnchor` returns the size a new value needs with the position that keeps that point
22
+ still. Applying one without the other drags the corner membership reads.
23
+ - `SECTION_ELEMENT_TYPE` and `FRAME_ELEMENT_TYPE` in `document-element-constants`, alongside
24
+ `SHAPE_ELEMENT_TYPES`, which moved here for the board's shape handling.
31
25
  - `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
32
- with `scale` applied. `getBoundingClientRect` keeps returning the element's own box before scale,
33
- which is what layout works in: `@contrail/document-table` places table members from it, and
34
- scaling it moves a scaled member into a different cell. Anything deciding what an element overlaps
35
- or sits on wants the scaled one.
26
+ with `scale` applied. `getBoundingClientRect` still returns the unscaled box, which is what layout
27
+ works in: `@contrail/document-table` places table members from it, and scaling it moves a scaled
28
+ member into a different cell. Anything deciding what an element overlaps or sits on wants the
29
+ scaled one.
36
30
 
37
31
  ### Deprecated
38
32
 
39
33
  - `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
40
- for what it decides: whether the binding's value comes from the container rather than a type
41
- property. The old name still works and delegates to the new one.
34
+ for what it decides. The old name still works and delegates to the new one.
42
35
 
43
36
  ### Fixed
44
37
 
45
- - A dynamic text is now anchored at its drawn top-left corner rather than its centre when deciding
46
- which container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its
47
- size comes from the value it resolves to, and that value depends on the container, so letting its
48
- width feed membership meant its own text could choose its container: near an edge the two answers
49
- disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
50
- else still resolves on its centre.
51
- - The corner is the rotated one (VIBE-9567). A 200x20 text turned on its side draws as a 20x200
52
- column, and its unrotated `position` can sit well clear of the frame it is visibly on, which
53
- reported "Move to a frame" for a vertical text the user could see was placed correctly.
54
- - A dynamic text is also exempt from the oversized-shape exclusion, which keeps a shape wider and
55
- taller than a container off it. That rule reads size too, so a dynamic text larger than its frame
56
- in both directions had two self-consistent answers and kept whichever it started from. The rule
57
- exists to keep a backdrop shape off a frame it covers, which is not what a dynamic text is doing.
58
- - `min` and `max` rendered an infinity sign when every member value was empty. The early return
59
- checked the list length before the empty values were filtered out, so `Math.min` of nothing
60
- reached the formatter. Both now fall through to `n/a`.
61
- - `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
62
- the server failed the read for the whole document. It now measures from a zero size instead.
38
+ - A dynamic text is anchored at its drawn top-left corner rather than its centre. Its size comes
39
+ from the value it resolves to and that value comes from its container, so an anchor that moved
40
+ with the size let the two choose each other: near an edge they never settled, flipping between a
41
+ value and "Move to a frame" on every read. The corner is the rotated one, so a text turned on its
42
+ side anchors where it appears (VIBE-9567).
43
+ - `isDynamicText` requires a `propertyBindings.text` binding, the one the value is read from. The
44
+ text tool creates an element with empty bindings and empty metadata, both truthy, so an
45
+ unconfigured text was anchored at its corner while the canvas centred it.
46
+ - An element covering a container is not inside it, whatever its type. The rule it replaces looked
47
+ only at shapes wider and taller than the container, so a background image joined the frame it
48
+ covered.
49
+ - A line or callout is measured from the elements it connects even with no stored `position`, where
50
+ it was previously left out of the index entirely.
51
+ - `min` and `max` rendered an infinity sign when every member value was empty; both fall through to
52
+ `n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
53
+ the server failed the read for the whole document.
63
54
 
64
55
  ### Changed
65
56
 
66
- - Container membership measures a scaled element from its scaled box, through the new
67
- `getBoundingClientRectScaled` above. Only a sticky note, a regular iframe, a text-tool text or a
68
- table carries `scale` at all; for this work the one that matters is a text-tool dynamic text,
69
- which previously measured at its unscaled size and could resolve to the wrong container.
70
- - `DocumentContainerUtil.anchorFor` measures through the same factory call the index uses, so a
71
- caller holding an element gets the answer the index would give it. Reading `size` directly
72
- disagreed for the types whose box is not position plus size: a component's box is built from the
73
- rows it draws, and a line's comes from its `lineDefinition`.
74
- - Container depth counts nesting levels rather than enclosing boxes. Two containers that merely
75
- cross both enclose anything inside the overlap, so counting ancestors put that inner container a
76
- level too deep and made `maxDepth` report a level no path could reach.
57
+ - `anchorFor` and the index measure through the same factory call, so a caller holding an element
58
+ gets the answer the index would give it. Reading `size` directly disagreed for the types whose box
59
+ is not position plus size.
60
+ - A container path is a containment chain, walked outward from the container the element sits on, so
61
+ two containers that merely cross no longer both claim it.
62
+ - `buildIndex` scans element types before measuring, so a document with no containers of the kinds
63
+ asked for returns an empty index without a geometry pass.
77
64
 
78
65
  ## [2.3.0] - 2026-09-21
79
66
 
@@ -1,10 +1,11 @@
1
- import { DocumentElement, PositionDefinition } from '../types';
2
- import { ContainerElementType } from './container-kind';
3
- import { DocumentContainer } from './document-container';
1
+ import { DocumentElement } from '../types';
2
+ import { ContainerElementType, ContainerKind } from './container-kind';
3
+ import { DocumentContainer, MeasuredDocumentElement } from './document-container';
4
4
  export declare class DocumentContainerIndex {
5
5
  private readonly data;
6
6
  constructor(data: {
7
7
  documentElementsById: Map<string, DocumentElement>;
8
+ measuredById: Map<string, MeasuredDocumentElement>;
8
9
  containersById: Map<string, DocumentContainer>;
9
10
  containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
10
11
  memberIdsByContainerId: Map<string, string[]>;
@@ -17,7 +18,7 @@ export declare class DocumentContainerIndex {
17
18
  innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
18
19
  memberIdsOf(containerId: string): readonly string[];
19
20
  memberDocumentElementsOf(containerId: string): DocumentElement[];
20
- containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
21
+ containerPathFor(documentElement: DocumentElement, kind: ContainerKind): readonly string[];
21
22
  private containersOfType;
22
23
  private resolveAll;
23
24
  private containerPath;
@@ -9,6 +9,7 @@ class DocumentContainerIndex {
9
9
  static empty() {
10
10
  return new DocumentContainerIndex({
11
11
  documentElementsById: new Map(),
12
+ measuredById: new Map(),
12
13
  containersById: new Map(),
13
14
  containerPathsByDocumentElementId: new Map(),
14
15
  memberIdsByContainerId: new Map(),
@@ -23,7 +24,7 @@ class DocumentContainerIndex {
23
24
  return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
24
25
  }
25
26
  containerIdsOf(documentElementId, elementType) {
26
- return this.containerPath(documentElementId, elementType);
27
+ return [...this.containerPath(documentElementId, elementType)];
27
28
  }
28
29
  innermostContainerIdOf(documentElementId, elementType) {
29
30
  const path = this.containerPath(documentElementId, elementType);
@@ -31,7 +32,7 @@ class DocumentContainerIndex {
31
32
  }
32
33
  memberIdsOf(containerId) {
33
34
  var _a;
34
- return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
35
+ return [...((_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [])];
35
36
  }
36
37
  memberDocumentElementsOf(containerId) {
37
38
  const members = [];
@@ -43,13 +44,17 @@ class DocumentContainerIndex {
43
44
  }
44
45
  return members;
45
46
  }
46
- containerPathAtPoint(point, elementType) {
47
+ containerPathFor(documentElement, kind) {
47
48
  var _a, _b;
48
- const containers = this.containersOfType(elementType);
49
- const covering = containers.filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
50
- const nests = (_b = (_a = containers[0]) === null || _a === void 0 ? void 0 : _a.kind.nests) !== null && _b !== void 0 ? _b : true;
51
- const path = nests ? document_container_1.DocumentContainerUtil.chain(covering) : document_container_1.DocumentContainerUtil.topmost(covering);
52
- return path.map((container) => container.id);
49
+ if (!documentElement) {
50
+ return [];
51
+ }
52
+ const measured = {
53
+ documentElement,
54
+ box: document_container_1.DocumentContainerUtil.measureBox(documentElement, this.data.documentElementsById),
55
+ drawOrder: (_b = (_a = this.data.measuredById.get(documentElement.id)) === null || _a === void 0 ? void 0 : _a.drawOrder) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER,
56
+ };
57
+ return document_container_1.DocumentContainerUtil.pathFor(measured, kind, this.containersOfType(kind.elementType)).map((container) => container.id);
53
58
  }
54
59
  containersOfType(elementType) {
55
60
  var _a;
@@ -17,9 +17,17 @@ export declare class DocumentContainerUtil {
17
17
  static centerOf(box: CoordinateBox): PositionDefinition;
18
18
  static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
19
19
  static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
20
+ static resizeKeepingAnchor(dynamicTextElement: DocumentElement, entityType: any, text: string): {
21
+ size: SizeDefinition;
22
+ position: PositionDefinition;
23
+ };
20
24
  static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
21
25
  static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
22
26
  static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
23
27
  static chain(candidates: DocumentContainer[]): DocumentContainer[];
28
+ static measureBox(documentElement: DocumentElement, documentElementsById: Map<string, DocumentElement>): CoordinateBox | null;
29
+ static pathFor(measured: MeasuredDocumentElement, kind: ContainerKind, containers: DocumentContainer[]): DocumentContainer[];
30
+ static enclosersOf(measured: MeasuredDocumentElement, containers: DocumentContainer[]): DocumentContainer[];
31
+ static candidatesFor(measured: MeasuredDocumentElement, containers: DocumentContainer[]): DocumentContainer[];
24
32
  static topmost(containers: DocumentContainer[]): DocumentContainer[];
25
33
  }
@@ -24,9 +24,12 @@ 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 || !angle || !newSize || !documentElement.size) {
27
+ if (!position) {
28
28
  return position;
29
29
  }
30
+ if (!angle || !newSize || !documentElement.size) {
31
+ return Object.assign({}, position);
32
+ }
30
33
  const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
31
34
  const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
32
35
  const cornerOffset = (size) => {
@@ -36,16 +39,23 @@ class DocumentContainerUtil {
36
39
  };
37
40
  const before = cornerOffset(documentElement.size);
38
41
  const after = cornerOffset(newSize);
39
- return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
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);
44
+ }
45
+ static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
46
+ const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
47
+ return { size, position: DocumentContainerUtil.positionKeepingAnchor(dynamicTextElement, size) };
40
48
  }
41
49
  static anchorFor(documentElement, position, startElement, endElement) {
42
50
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
43
- if (!at) {
51
+ try {
52
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
53
+ const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
54
+ return DocumentContainerUtil.anchorOf(documentElement, box);
55
+ }
56
+ catch (_a) {
44
57
  return null;
45
58
  }
46
- const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
47
- const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
48
- return DocumentContainerUtil.anchorOf(documentElement, box);
49
59
  }
50
60
  static containsPoint(box, point) {
51
61
  return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
@@ -73,6 +83,56 @@ class DocumentContainerUtil {
73
83
  path.unshift(topmostOf(enclosing));
74
84
  }
75
85
  }
86
+ static measureBox(documentElement, documentElementsById) {
87
+ var _a, _b;
88
+ try {
89
+ 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;
90
+ 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;
91
+ const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
92
+ if (!width && !height && !documentElement.position) {
93
+ return null;
94
+ }
95
+ return DocumentContainerUtil.toCoordinateBox(x, y, width, height);
96
+ }
97
+ catch (_c) {
98
+ return null;
99
+ }
100
+ }
101
+ static pathFor(measured, kind, containers) {
102
+ if (!containers.length || !measured.box) {
103
+ return [];
104
+ }
105
+ if (measured.documentElement.type === kind.elementType) {
106
+ return kind.nests ? DocumentContainerUtil.chain(DocumentContainerUtil.enclosersOf(measured, containers)) : [];
107
+ }
108
+ const candidates = DocumentContainerUtil.candidatesFor(measured, containers);
109
+ return kind.nests ? DocumentContainerUtil.chain(candidates) : DocumentContainerUtil.topmost(candidates);
110
+ }
111
+ static enclosersOf(measured, containers) {
112
+ return containers.filter((container) => {
113
+ var _a;
114
+ return container.id !== measured.documentElement.id &&
115
+ DocumentContainerUtil.encloses(container.box, measured.box) &&
116
+ measured.drawOrder > container.drawOrder &&
117
+ !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
118
+ });
119
+ }
120
+ static candidatesFor(measured, containers) {
121
+ const anchor = DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
122
+ return containers.filter((container) => {
123
+ var _a;
124
+ if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
125
+ return false;
126
+ }
127
+ if (!DocumentContainerUtil.containsPoint(container.box, anchor)) {
128
+ return false;
129
+ }
130
+ if (DocumentContainerUtil.encloses(measured.box, container.box)) {
131
+ return false;
132
+ }
133
+ return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
134
+ });
135
+ }
76
136
  static topmost(containers) {
77
137
  return containers.length
78
138
  ? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
@@ -5,9 +5,5 @@ export declare class DocumentContainerService {
5
5
  static buildIndex(documentElements: readonly DocumentElement[], kinds?: ContainerKind[]): DocumentContainerIndex;
6
6
  static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
7
7
  private static measureDocumentElements;
8
- private static measure;
9
8
  private static collectContainers;
10
- private static resolvePath;
11
- private static enclosersOf;
12
- private static candidateContainers;
13
9
  }
@@ -1,16 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentContainerService = void 0;
4
- const document_element_factory_1 = require("../document-element-factory");
5
4
  const container_kind_1 = require("./container-kind");
6
5
  const document_container_index_1 = require("./document-container-index");
7
6
  const document_container_1 = require("./document-container");
8
7
  class DocumentContainerService {
9
8
  static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
10
9
  var _a, _b;
11
- const elements = documentElements !== null && documentElements !== void 0 ? documentElements : [];
10
+ const elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
12
11
  const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
13
- if (!elements.some((element) => containerElementTypes.has(element === null || element === void 0 ? void 0 : element.type))) {
12
+ if (!elements.some((element) => containerElementTypes.has(element.type))) {
14
13
  return document_container_index_1.DocumentContainerIndex.empty();
15
14
  }
16
15
  const documentElementsById = new Map(elements.map((element) => [element.id, element]));
@@ -26,31 +25,39 @@ class DocumentContainerService {
26
25
  for (const measured of measuredDocumentElements) {
27
26
  const byElementType = new Map();
28
27
  for (const kind of kinds) {
29
- byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
28
+ byElementType.set(kind.elementType, document_container_1.DocumentContainerUtil.pathFor(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
30
29
  }
31
30
  pathsByMeasured.set(measured, byElementType);
32
31
  }
33
32
  const containerPathsByDocumentElementId = new Map();
34
33
  const memberIdsByContainerId = new Map();
34
+ const memberIdsSeen = new Map();
35
35
  for (const measured of measuredDocumentElements) {
36
36
  const documentElementId = measured.documentElement.id;
37
37
  const pathsByElementType = new Map();
38
38
  ((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
39
39
  for (const path of pathsByElementType.values()) {
40
40
  for (const containerId of path) {
41
- const members = memberIdsByContainerId.get(containerId);
42
- if (members) {
43
- members.push(documentElementId);
44
- }
45
- else {
41
+ const seen = memberIdsSeen.get(containerId);
42
+ if (!seen) {
43
+ memberIdsSeen.set(containerId, new Set([documentElementId]));
46
44
  memberIdsByContainerId.set(containerId, [documentElementId]);
47
45
  }
46
+ else if (!seen.has(documentElementId)) {
47
+ seen.add(documentElementId);
48
+ memberIdsByContainerId.get(containerId).push(documentElementId);
49
+ }
48
50
  }
49
51
  }
50
52
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
51
53
  }
54
+ const measuredById = new Map();
55
+ for (const measured of measuredDocumentElements) {
56
+ measuredById.set(measured.documentElement.id, measured);
57
+ }
52
58
  return new document_container_index_1.DocumentContainerIndex({
53
59
  documentElementsById,
60
+ measuredById,
54
61
  containersById,
55
62
  containerPathsByDocumentElementId,
56
63
  memberIdsByContainerId,
@@ -64,24 +71,9 @@ class DocumentContainerService {
64
71
  return documentElements.map((documentElement, drawOrder) => ({
65
72
  documentElement,
66
73
  drawOrder,
67
- box: this.measure(documentElement, documentElementsById),
74
+ box: document_container_1.DocumentContainerUtil.measureBox(documentElement, documentElementsById),
68
75
  }));
69
76
  }
70
- static measure(documentElement, documentElementsById) {
71
- var _a, _b;
72
- if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
73
- return null;
74
- }
75
- try {
76
- const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
77
- const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
78
- const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
79
- return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
80
- }
81
- catch (_c) {
82
- return null;
83
- }
84
- }
85
77
  static collectContainers(measuredDocumentElements, kind) {
86
78
  return measuredDocumentElements
87
79
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
@@ -93,40 +85,5 @@ class DocumentContainerService {
93
85
  drawOrder: measured.drawOrder,
94
86
  }));
95
87
  }
96
- static resolvePath(measured, kind, containers) {
97
- if (!containers.length || !measured.box) {
98
- return [];
99
- }
100
- if (measured.documentElement.type === kind.elementType) {
101
- return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
102
- }
103
- const candidates = this.candidateContainers(measured, containers);
104
- return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
105
- }
106
- static enclosersOf(measured, containers) {
107
- return containers.filter((container) => {
108
- var _a;
109
- return container.documentElement !== measured.documentElement &&
110
- document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
111
- measured.drawOrder > container.drawOrder &&
112
- !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
113
- });
114
- }
115
- static candidateContainers(measured, containers) {
116
- const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
117
- return containers.filter((container) => {
118
- var _a;
119
- if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
120
- return false;
121
- }
122
- if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
123
- return false;
124
- }
125
- if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
126
- return false;
127
- }
128
- return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
129
- });
130
- }
131
88
  }
132
89
  exports.DocumentContainerService = DocumentContainerService;
@@ -27,6 +27,8 @@ 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;
30
32
  export declare const HARD_CODED_TEXT: {
31
33
  'project.name': string;
32
34
  'project.createdBy.email': string;
@@ -53,7 +55,10 @@ export declare class DynamicTextUtil {
53
55
  static isDynamicText(documentElement: DocumentElement): boolean;
54
56
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
55
57
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
56
- static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
58
+ static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): {
59
+ width: number;
60
+ height: number;
61
+ };
57
62
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
58
63
  private static getItemCount;
59
64
  }
@@ -1,6 +1,8 @@
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;
4
6
  exports.isContainerBinding = isContainerBinding;
5
7
  const types_1 = require("@contrail/types");
6
8
  const util_1 = require("@contrail/util");
@@ -28,6 +30,12 @@ var DynamicTextDisplayFunction;
28
30
  exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
29
31
  exports.MOVE_TO_SECTION_TEXT = 'Move to a section';
30
32
  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
+ }
31
39
  exports.HARD_CODED_TEXT = {
32
40
  'project.name': 'Project name',
33
41
  'project.createdBy.email': 'Project created by',
@@ -56,8 +64,9 @@ function isContainerBinding(bindingProperty) {
56
64
  }
57
65
  class DynamicTextUtil {
58
66
  static isDynamicText(documentElement) {
67
+ var _a;
59
68
  return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
60
- !!documentElement.propertyBindings &&
69
+ !!((_a = documentElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text) &&
61
70
  !!documentElement.propertyBindingsMetaData);
62
71
  }
63
72
  static takesValueFromContainer(bindingProperty) {
@@ -97,7 +106,7 @@ class DynamicTextUtil {
97
106
  }
98
107
  else {
99
108
  if (!container && !isSpecRelated) {
100
- text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
109
+ text = placeholderForMissingContainer(entityType);
101
110
  }
102
111
  else {
103
112
  if (CONTAINER_SOURCES.includes(entityType)) {
@@ -140,7 +149,7 @@ class DynamicTextUtil {
140
149
  text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
141
150
  }
142
151
  else if (!container) {
143
- text = exports.MOVE_TO_FRAME_TEXT;
152
+ text = placeholderForMissingContainer(entityType);
144
153
  }
145
154
  else {
146
155
  text = property === null || property === void 0 ? void 0 : property.label;
@@ -150,7 +159,7 @@ class DynamicTextUtil {
150
159
  text = 'n/a';
151
160
  }
152
161
  if (displayLabel &&
153
- ![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
162
+ !isPlaceholderText(text) &&
154
163
  displayFunction !== DynamicTextDisplayFunction.LABEL &&
155
164
  text !== bindingProperty) {
156
165
  text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
@@ -158,16 +167,19 @@ class DynamicTextUtil {
158
167
  return text;
159
168
  }
160
169
  static calculateSize(dynamicTextElement, entityType, text) {
161
- var _a, _b, _c, _d, _e;
162
- let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
163
- 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;
164
- const fontSize = (_e = (dynamicTextElement.isTextTool
165
- ? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
166
- : 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;
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;
167
179
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
168
180
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
169
- const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
170
- const italic = document_util_1.DocumentStyleUtil.isItalic(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text);
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 : '');
171
183
  const measureTextSettings = {
172
184
  fontFamily,
173
185
  fontSize: fontSizePx,
@@ -208,7 +220,7 @@ class DynamicTextUtil {
208
220
  }
209
221
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
210
222
  text = Array.from(new Set(memberValues
211
- .filter((e) => e !== null && e !== undefined)
223
+ .filter((e) => e !== null && e !== undefined && e !== '')
212
224
  .flat()
213
225
  .map((e) => formatter.formatValueForProperty(e, property))))
214
226
  .sort()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.cb23d8e",
3
+ "version": "2.4.0-alpha.e296d62",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",