@contrail/documents 2.4.0-alpha.8be4908 → 2.4.0-alpha.962d425

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,84 +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` and `nests`. An element belongs to
17
- the container whose box covers its anchor point and which is drawn below it, unless the element's
18
- own box encloses that container or the element is a group holding it. `nests` decides the shape of
19
- the answer: sections nest, so an element in a section inside another is in both, and the chain
20
- requires the inner container to be drawn above the outer; frames do not, so an element covered by
21
- two frames is in the topmost. A container of another kind is placed by the same rules as any
22
- element, so a frame can be in a section and a section drawn above a frame is in that frame. The
23
- rule is written out in `src/containers/DOCUMENT_CONTAINERS_SPEC.md`, which the code is measured
24
- against.
25
- - `SECTION_ELEMENT_TYPE` and `FRAME_ELEMENT_TYPE` in `document-element-constants`, so the rule
26
- above has one definition rather than one per app. `SHAPE_ELEMENT_TYPES` moved here with them; no
27
- container rule reads it, and it is exported for the board's own shape handling.
28
- - `DocumentContainerUtil.resizeKeepingAnchor` — the size a value needs and the position that keeps
29
- the element's anchor where it is, returned together. Applying one without the other drags the
30
- drawn corner that membership reads, and `calculateSize` alone let a caller do exactly that.
31
- - `DocumentContainerUtil` — the container geometry as statics, with `anchorFor` for a caller
32
- holding an element rather than a measured box.
33
- - `positionKeepingAnchor` — where an element has to sit for its drawn corner to land where it did
34
- before a resize. Prefer `resizeKeepingAnchor` above, which pairs it with the size. Rotation turns about the centre and the centre moves with the size, so a rotated
35
- element resized about its stored position drags its corner along with it. The board already makes
36
- this move; a server recomputing a dynamic text has to make the same one, or the corner is not the
37
- 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.
38
25
  - `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
39
- with `scale` applied. `getBoundingClientRect` keeps returning the element's own box before scale,
40
- which is what layout works in: `@contrail/document-table` places table members from it, and
41
- scaling it moves a scaled member into a different cell. Anything deciding what an element overlaps
42
- 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.
43
30
 
44
31
  ### Deprecated
45
32
 
46
33
  - `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
47
- for what it decides: whether the binding's value comes from the container rather than a type
48
- 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.
49
35
 
50
36
  ### Fixed
51
37
 
52
- - A dynamic text is now anchored at its drawn top-left corner rather than its centre when deciding
53
- which container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its
54
- size comes from the value it resolves to, and that value depends on the container, so letting its
55
- width feed membership meant its own text could choose its container: near an edge the two answers
56
- disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
57
- else still resolves on its centre.
58
- - The corner is the rotated one (VIBE-9567). A 200x20 text turned on its side draws as a 20x200
59
- column, and its unrotated `position` can sit well clear of the frame it is visibly on, which
60
- reported "Move to a frame" for a vertical text the user could see was placed correctly.
61
- - An element covering a container is not inside it, whatever its type. This replaces a rule that
62
- excluded only shapes wider and taller than the container, which let a background image join the
63
- frame it covered and needed an exemption for dynamic text, whose size the container decides. An
64
- unrotated dynamic text cannot be excluded by enclosure, since its anchor is the corner of the box
65
- it would have to cover with.
66
- - `isDynamicText` requires a `propertyBindings.text` binding, which is the one the value is read
67
- from. The text tool creates an element with empty `propertyBindings` and `propertyBindingsMetaData`
68
- and both are truthy, so an unconfigured text was anchored at its corner while the canvas centred
69
- it.
70
- - A line or callout is measured from the elements it connects even with no stored `position` of its
71
- own, where it was previously left out of the index entirely.
72
- - `min` and `max` rendered an infinity sign when every member value was empty. The early return
73
- checked the list length before the empty values were filtered out, so `Math.min` of nothing
74
- reached the formatter. Both now fall through to `n/a`.
75
- - `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
76
- 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.
77
54
 
78
55
  ### Changed
79
56
 
80
- - Container membership measures a scaled element from its scaled box, through the new
81
- `getBoundingClientRectScaled` above. Only a sticky note, a regular iframe, a text-tool text or a
82
- table carries `scale` at all; for this work the one that matters is a text-tool dynamic text,
83
- which previously measured at its unscaled size and could resolve to the wrong container.
84
- - `DocumentContainerUtil.anchorFor` measures through the same factory call the index uses, so a
85
- caller holding an element gets the answer the index would give it. Reading `size` directly
86
- disagreed for the types whose box is not position plus size: a component's box is built from the
87
- rows it draws, and a line's comes from its `lineDefinition`.
88
- - A container path is a containment chain, walked outward from the container the element sits on.
89
- Two containers that merely cross are not a chain, so the later-drawn one takes the element rather
90
- than both claiming it. `containerPathAtPoint` walks the same chain, so a drop preview agrees with
91
- the drop; it applies only the anchor rule, having no element to compare against a container.
92
- - `buildIndex` scans element types before measuring anything, so a document holding no containers
93
- of the kinds asked for returns an empty index without a geometry pass.
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.
94
64
 
95
65
  ## [2.3.0] - 2026-09-21
96
66
 
@@ -1,10 +1,11 @@
1
1
  import { DocumentElement, PositionDefinition } from '../types';
2
- import { ContainerElementType } from './container-kind';
3
- import { DocumentContainer } from './document-container';
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,9 +18,9 @@ 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[];
21
+ containerPathFor(documentElement: DocumentElement, kind: ContainerKind, at?: PositionDefinition): readonly string[];
20
22
  containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
21
23
  private containersOfType;
22
24
  private resolveAll;
23
25
  private containerPath;
24
- private containerPathCopy;
25
26
  }
@@ -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.containerPathCopy(documentElementId, elementType);
27
+ return [...this.containerPath(documentElementId, elementType)];
27
28
  }
28
29
  innermostContainerIdOf(documentElementId, elementType) {
29
30
  const path = this.containerPath(documentElementId, elementType);
@@ -43,6 +44,20 @@ class DocumentContainerIndex {
43
44
  }
44
45
  return members;
45
46
  }
47
+ containerPathFor(documentElement, kind, at) {
48
+ var _a;
49
+ if (!documentElement) {
50
+ return [];
51
+ }
52
+ const known = this.data.measuredById.get(documentElement.id);
53
+ const positioned = at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement;
54
+ const measured = {
55
+ documentElement: positioned,
56
+ box: at || !known ? document_container_1.DocumentContainerUtil.measureBox(positioned, this.data.documentElementsById) : known.box,
57
+ drawOrder: (_a = known === null || known === void 0 ? void 0 : known.drawOrder) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER,
58
+ };
59
+ return document_container_1.DocumentContainerUtil.pathFor(measured, kind, this.containersOfType(kind.elementType)).map((container) => container.id);
60
+ }
46
61
  containerPathAtPoint(point, elementType) {
47
62
  var _a, _b;
48
63
  const containers = this.containersOfType(elementType);
@@ -69,8 +84,5 @@ class DocumentContainerIndex {
69
84
  var _a, _b;
70
85
  return (_b = (_a = this.data.containerPathsByDocumentElementId.get(documentElementId)) === null || _a === void 0 ? void 0 : _a.get(elementType)) !== null && _b !== void 0 ? _b : [];
71
86
  }
72
- containerPathCopy(documentElementId, elementType) {
73
- return [...this.containerPath(documentElementId, elementType)];
74
- }
75
87
  }
76
88
  exports.DocumentContainerIndex = DocumentContainerIndex;
@@ -25,5 +25,9 @@ export declare class DocumentContainerUtil {
25
25
  static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
26
26
  static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
27
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[];
28
32
  static topmost(containers: DocumentContainer[]): DocumentContainer[];
29
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,7 +39,8 @@ 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);
40
44
  }
41
45
  static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
42
46
  const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
@@ -44,11 +48,8 @@ class DocumentContainerUtil {
44
48
  }
45
49
  static anchorFor(documentElement, position, startElement, endElement) {
46
50
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
47
- if (!at) {
48
- return null;
49
- }
50
51
  try {
51
- const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
52
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
52
53
  const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
53
54
  return DocumentContainerUtil.anchorOf(documentElement, box);
54
55
  }
@@ -82,6 +83,56 @@ class DocumentContainerUtil {
82
83
  path.unshift(topmostOf(enclosing));
83
84
  }
84
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
+ }
85
136
  static topmost(containers) {
86
137
  return containers.length
87
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,7 +1,6 @@
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");
@@ -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,21 +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
- try {
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;
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;
75
- const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
76
- return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
77
- }
78
- catch (_c) {
79
- return null;
80
- }
81
- }
82
77
  static collectContainers(measuredDocumentElements, kind) {
83
78
  return measuredDocumentElements
84
79
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
@@ -90,40 +85,5 @@ class DocumentContainerService {
90
85
  drawOrder: measured.drawOrder,
91
86
  }));
92
87
  }
93
- static resolvePath(measured, kind, containers) {
94
- if (!containers.length || !measured.box) {
95
- return [];
96
- }
97
- if (measured.documentElement.type === kind.elementType) {
98
- return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
99
- }
100
- const candidates = this.candidateContainers(measured, containers);
101
- return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
102
- }
103
- static enclosersOf(measured, containers) {
104
- return containers.filter((container) => {
105
- var _a;
106
- return container.documentElement !== measured.documentElement &&
107
- document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
108
- measured.drawOrder > container.drawOrder &&
109
- !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
110
- });
111
- }
112
- static candidateContainers(measured, containers) {
113
- const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
114
- return containers.filter((container) => {
115
- var _a;
116
- if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
117
- return false;
118
- }
119
- if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
120
- return false;
121
- }
122
- if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
123
- return false;
124
- }
125
- return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
126
- });
127
- }
128
88
  }
129
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',
@@ -98,7 +106,7 @@ class DynamicTextUtil {
98
106
  }
99
107
  else {
100
108
  if (!container && !isSpecRelated) {
101
- text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
109
+ text = placeholderForMissingContainer(entityType);
102
110
  }
103
111
  else {
104
112
  if (CONTAINER_SOURCES.includes(entityType)) {
@@ -141,7 +149,7 @@ class DynamicTextUtil {
141
149
  text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
142
150
  }
143
151
  else if (!container) {
144
- text = exports.MOVE_TO_FRAME_TEXT;
152
+ text = placeholderForMissingContainer(entityType);
145
153
  }
146
154
  else {
147
155
  text = property === null || property === void 0 ? void 0 : property.label;
@@ -151,7 +159,7 @@ class DynamicTextUtil {
151
159
  text = 'n/a';
152
160
  }
153
161
  if (displayLabel &&
154
- ![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
162
+ !isPlaceholderText(text) &&
155
163
  displayFunction !== DynamicTextDisplayFunction.LABEL &&
156
164
  text !== bindingProperty) {
157
165
  text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
@@ -159,16 +167,19 @@ class DynamicTextUtil {
159
167
  return text;
160
168
  }
161
169
  static calculateSize(dynamicTextElement, entityType, text) {
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;
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;
168
179
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
169
180
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
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);
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 : '');
172
183
  const measureTextSettings = {
173
184
  fontFamily,
174
185
  fontSize: fontSizePx,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.8be4908",
3
+ "version": "2.4.0-alpha.962d425",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",