@contrail/documents 2.4.0-alpha.a01d866 → 2.4.0-alpha.a4d67e4

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
 
@@ -3,7 +3,6 @@ export type ContainerElementType = typeof FRAME_ELEMENT_TYPE | typeof SECTION_EL
3
3
  export interface ContainerKind {
4
4
  elementType: ContainerElementType;
5
5
  nests: boolean;
6
- layer: number;
7
6
  }
8
7
  export declare const SECTION_KIND: ContainerKind;
9
8
  export declare const FRAME_KIND: ContainerKind;
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CONTAINER_KINDS = exports.FRAME_KIND = exports.SECTION_KIND = void 0;
4
4
  const document_element_constants_1 = require("../document-element-constants");
5
- exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true, layer: 0 };
6
- exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false, layer: 1 };
5
+ exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true };
6
+ exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false };
7
7
  exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
@@ -10,6 +10,7 @@ export declare class DocumentContainerIndex {
10
10
  memberIdsByContainerId: Map<string, string[]>;
11
11
  containerIdsByElementType: Map<string, string[]>;
12
12
  });
13
+ static empty(): DocumentContainerIndex;
13
14
  getContainer(containerId: string): DocumentContainer | null;
14
15
  containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
15
16
  containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
@@ -17,7 +18,6 @@ export declare class DocumentContainerIndex {
17
18
  memberIdsOf(containerId: string): readonly string[];
18
19
  memberDocumentElementsOf(containerId: string): DocumentElement[];
19
20
  containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
20
- maxDepth(elementType: ContainerElementType): number;
21
21
  private containersOfType;
22
22
  private resolveAll;
23
23
  private containerPath;
@@ -6,6 +6,15 @@ class DocumentContainerIndex {
6
6
  constructor(data) {
7
7
  this.data = data;
8
8
  }
9
+ static empty() {
10
+ return new DocumentContainerIndex({
11
+ documentElementsById: new Map(),
12
+ containersById: new Map(),
13
+ containerPathsByDocumentElementId: new Map(),
14
+ memberIdsByContainerId: new Map(),
15
+ containerIdsByElementType: new Map(),
16
+ });
17
+ }
9
18
  getContainer(containerId) {
10
19
  var _a;
11
20
  return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
@@ -14,7 +23,7 @@ class DocumentContainerIndex {
14
23
  return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
15
24
  }
16
25
  containerIdsOf(documentElementId, elementType) {
17
- return this.containerPath(documentElementId, elementType);
26
+ return [...this.containerPath(documentElementId, elementType)];
18
27
  }
19
28
  innermostContainerIdOf(documentElementId, elementType) {
20
29
  const path = this.containerPath(documentElementId, elementType);
@@ -22,7 +31,7 @@ class DocumentContainerIndex {
22
31
  }
23
32
  memberIdsOf(containerId) {
24
33
  var _a;
25
- return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
34
+ return [...((_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [])];
26
35
  }
27
36
  memberDocumentElementsOf(containerId) {
28
37
  const members = [];
@@ -35,11 +44,12 @@ class DocumentContainerIndex {
35
44
  return members;
36
45
  }
37
46
  containerPathAtPoint(point, elementType) {
38
- const covering = this.containersOfType(elementType).filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
39
- return document_container_1.DocumentContainerUtil.topmostPerDepth(covering).map((container) => container.id);
40
- }
41
- maxDepth(elementType) {
42
- return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
47
+ 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);
43
53
  }
44
54
  containersOfType(elementType) {
45
55
  var _a;
@@ -3,10 +3,8 @@ import { ContainerKind } from './container-kind';
3
3
  export interface DocumentContainer {
4
4
  id: string;
5
5
  kind: ContainerKind;
6
- name: string;
7
6
  documentElement: DocumentElement;
8
7
  box: CoordinateBox;
9
- depth: number;
10
8
  drawOrder: number;
11
9
  }
12
10
  export interface MeasuredDocumentElement {
@@ -19,9 +17,13 @@ export declare class DocumentContainerUtil {
19
17
  static centerOf(box: CoordinateBox): PositionDefinition;
20
18
  static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
21
19
  static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
20
+ static resizeKeepingAnchor(dynamicTextElement: DocumentElement, entityType: any, text: string): {
21
+ size: SizeDefinition;
22
+ position: PositionDefinition;
23
+ };
22
24
  static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
23
25
  static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
24
26
  static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
25
- static isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
26
- static topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
27
+ static chain(candidates: DocumentContainer[]): DocumentContainer[];
28
+ static topmost(containers: DocumentContainer[]): DocumentContainer[];
27
29
  }
@@ -38,24 +38,20 @@ class DocumentContainerUtil {
38
38
  const after = cornerOffset(newSize);
39
39
  return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
40
40
  }
41
+ static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
42
+ const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
43
+ return { size, position: DocumentContainerUtil.positionKeepingAnchor(dynamicTextElement, size) };
44
+ }
41
45
  static anchorFor(documentElement, position, startElement, endElement) {
42
- var _a, _b, _c, _d, _e;
43
46
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
44
- if (!at) {
45
- return null;
46
- }
47
- const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
48
- let width = size.width * ((_c = (_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1);
49
- let height = size.height * ((_e = (_d = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1);
50
47
  try {
51
- const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
52
- width = measured.width;
53
- height = measured.height;
48
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
49
+ const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
50
+ return DocumentContainerUtil.anchorOf(documentElement, box);
54
51
  }
55
- catch (_f) {
52
+ catch (_a) {
53
+ return null;
56
54
  }
57
- const box = DocumentContainerUtil.toCoordinateBox(at.x, at.y, width, height);
58
- return DocumentContainerUtil.anchorOf(documentElement, box);
59
55
  }
60
56
  static containsPoint(box, point) {
61
57
  return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
@@ -68,18 +64,25 @@ class DocumentContainerUtil {
68
64
  outer.bottom === inner.bottom;
69
65
  return covers && !identical;
70
66
  }
71
- static isWiderAndTallerThan(box, other) {
72
- return box.width > other.width && box.height > other.height;
73
- }
74
- static topmostPerDepth(containers) {
75
- const byDepth = [];
76
- for (const container of containers) {
77
- const existing = byDepth[container.depth];
78
- if (!existing || container.drawOrder > existing.drawOrder) {
79
- byDepth[container.depth] = container;
67
+ static chain(candidates) {
68
+ if (!candidates.length) {
69
+ return [];
70
+ }
71
+ const topmostOf = (of) => of.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
72
+ const path = [topmostOf(candidates)];
73
+ for (;;) {
74
+ const current = path[0];
75
+ const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
76
+ if (!enclosing.length) {
77
+ return path;
80
78
  }
79
+ path.unshift(topmostOf(enclosing));
81
80
  }
82
- return byDepth.filter(Boolean);
81
+ }
82
+ static topmost(containers) {
83
+ return containers.length
84
+ ? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
85
+ : [];
83
86
  }
84
87
  }
85
88
  exports.DocumentContainerUtil = DocumentContainerUtil;
@@ -6,9 +6,8 @@ export declare class DocumentContainerService {
6
6
  static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
7
7
  private static measureDocumentElements;
8
8
  private static measure;
9
- private static buildNesting;
10
- private static resolveContainerPath;
11
- private static resolveInnermostOnTop;
12
- private static toContainerPath;
9
+ private static collectContainers;
10
+ private static resolvePath;
11
+ private static enclosersOf;
13
12
  private static candidateContainers;
14
13
  }
@@ -2,43 +2,58 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentContainerService = void 0;
4
4
  const document_element_factory_1 = require("../document-element-factory");
5
- const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
6
- const document_element_constants_1 = require("../document-element-constants");
7
5
  const container_kind_1 = require("./container-kind");
8
6
  const document_container_index_1 = require("./document-container-index");
9
7
  const document_container_1 = require("./document-container");
10
8
  class DocumentContainerService {
11
9
  static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
12
- const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
13
- const nestingByElementType = new Map(kinds.map((kind) => [kind.elementType, this.buildNesting(measuredDocumentElements, kind)]));
10
+ var _a, _b;
11
+ const elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
12
+ const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
13
+ if (!elements.some((element) => containerElementTypes.has(element.type))) {
14
+ return document_container_index_1.DocumentContainerIndex.empty();
15
+ }
16
+ const documentElementsById = new Map(elements.map((element) => [element.id, element]));
17
+ const measuredDocumentElements = this.measureDocumentElements(elements, documentElementsById);
18
+ const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
14
19
  const containersById = new Map();
15
20
  const containerIdsByElementType = new Map();
16
- nestingByElementType.forEach((nesting, elementType) => {
17
- containerIdsByElementType.set(elementType, nesting.containers.map((container) => container.id));
18
- nesting.containers.forEach((container) => containersById.set(container.id, container));
21
+ containersByElementType.forEach((containers, elementType) => {
22
+ containerIdsByElementType.set(elementType, containers.map((container) => container.id));
23
+ containers.forEach((container) => containersById.set(container.id, container));
19
24
  });
25
+ const pathsByMeasured = new Map();
26
+ for (const measured of measuredDocumentElements) {
27
+ const byElementType = new Map();
28
+ for (const kind of kinds) {
29
+ byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
30
+ }
31
+ pathsByMeasured.set(measured, byElementType);
32
+ }
20
33
  const containerPathsByDocumentElementId = new Map();
21
34
  const memberIdsByContainerId = new Map();
35
+ const memberIdsSeen = new Map();
22
36
  for (const measured of measuredDocumentElements) {
23
37
  const documentElementId = measured.documentElement.id;
24
38
  const pathsByElementType = new Map();
25
- for (const kind of kinds) {
26
- const path = this.resolveContainerPath(measured, kind, kinds, nestingByElementType.get(kind.elementType));
27
- pathsByElementType.set(kind.elementType, path);
39
+ ((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
40
+ for (const path of pathsByElementType.values()) {
28
41
  for (const containerId of path) {
29
- const members = memberIdsByContainerId.get(containerId);
30
- if (members) {
31
- members.push(documentElementId);
32
- }
33
- else {
42
+ const seen = memberIdsSeen.get(containerId);
43
+ if (!seen) {
44
+ memberIdsSeen.set(containerId, new Set([documentElementId]));
34
45
  memberIdsByContainerId.set(containerId, [documentElementId]);
35
46
  }
47
+ else if (!seen.has(documentElementId)) {
48
+ seen.add(documentElementId);
49
+ memberIdsByContainerId.get(containerId).push(documentElementId);
50
+ }
36
51
  }
37
52
  }
38
53
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
39
54
  }
40
55
  return new document_container_index_1.DocumentContainerIndex({
41
- documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
56
+ documentElementsById,
42
57
  containersById,
43
58
  containerPathsByDocumentElementId,
44
59
  memberIdsByContainerId,
@@ -48,8 +63,7 @@ class DocumentContainerService {
48
63
  static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
49
64
  return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
50
65
  }
51
- static measureDocumentElements(documentElements) {
52
- const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
66
+ static measureDocumentElements(documentElements, documentElementsById) {
53
67
  return documentElements.map((documentElement, drawOrder) => ({
54
68
  documentElement,
55
69
  drawOrder,
@@ -58,12 +72,9 @@ class DocumentContainerService {
58
72
  }
59
73
  static measure(documentElement, documentElementsById) {
60
74
  var _a, _b;
61
- if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
62
- return null;
63
- }
64
75
  try {
65
- const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
66
- const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
76
+ 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
+ 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;
67
78
  const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
68
79
  return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
69
80
  }
@@ -71,78 +82,38 @@ class DocumentContainerService {
71
82
  return null;
72
83
  }
73
84
  }
74
- static buildNesting(measuredDocumentElements, kind) {
75
- const containers = measuredDocumentElements
85
+ static collectContainers(measuredDocumentElements, kind) {
86
+ return measuredDocumentElements
76
87
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
77
88
  .map((measured) => ({
78
89
  id: measured.documentElement.id,
79
90
  kind,
80
- name: measured.documentElement.name,
81
91
  documentElement: measured.documentElement,
82
92
  box: measured.box,
83
- depth: 0,
84
93
  drawOrder: measured.drawOrder,
85
94
  }));
86
- const ancestorsById = new Map();
87
- for (const container of containers) {
88
- const ancestors = kind.nests
89
- ? containers.filter((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(other.box, container.box))
90
- : [];
91
- ancestorsById.set(container.id, ancestors);
92
- }
93
- const depths = new Map();
94
- const depthOf = (container) => {
95
- var _a;
96
- const cached = depths.get(container.id);
97
- if (cached !== undefined) {
98
- return cached;
99
- }
100
- const ancestors = (_a = ancestorsById.get(container.id)) !== null && _a !== void 0 ? _a : [];
101
- const depth = ancestors.length ? 1 + Math.max(...ancestors.map(depthOf)) : 0;
102
- depths.set(container.id, depth);
103
- return depth;
104
- };
105
- for (const container of containers) {
106
- container.depth = depthOf(container);
107
- }
108
- return { containers, ancestorsById };
109
95
  }
110
- static resolveContainerPath(measured, kind, kinds, nesting) {
111
- var _a, _b;
112
- if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
96
+ static resolvePath(measured, kind, containers) {
97
+ if (!containers.length || !measured.box) {
113
98
  return [];
114
99
  }
115
- const ownKind = kinds.find((candidate) => candidate.elementType === measured.documentElement.type);
116
- if (ownKind) {
117
- if (ownKind.elementType === kind.elementType) {
118
- return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
119
- }
120
- if (kind.layer > ownKind.layer) {
121
- return [];
122
- }
123
- }
124
- const candidates = this.candidateContainers(measured, nesting.containers);
125
- if (!candidates.length) {
126
- return [];
100
+ if (measured.documentElement.type === kind.elementType) {
101
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
127
102
  }
128
- const innermostOnTop = this.resolveInnermostOnTop(candidates, nesting);
129
- const candidateIds = new Set(candidates.map((container) => container.id));
130
- const ancestors = ((_b = nesting.ancestorsById.get(innermostOnTop.id)) !== null && _b !== void 0 ? _b : []).filter((container) => candidateIds.has(container.id));
131
- return this.toContainerPath([...ancestors, innermostOnTop]);
132
- }
133
- static resolveInnermostOnTop(candidates, nesting) {
134
- const enclosingIds = new Set(candidates.flatMap((container) => { var _a; return (_a = nesting.ancestorsById.get(container.id)) !== null && _a !== void 0 ? _a : []; }).map((ancestor) => ancestor.id));
135
- return candidates
136
- .filter((container) => !enclosingIds.has(container.id))
137
- .reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
103
+ const candidates = this.candidateContainers(measured, containers);
104
+ return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
138
105
  }
139
- static toContainerPath(containers) {
140
- return document_container_1.DocumentContainerUtil.topmostPerDepth(containers).map((container) => container.id);
106
+ static enclosersOf(measured, containers) {
107
+ return containers.filter((container) => {
108
+ var _a;
109
+ return container.id !== measured.documentElement.id &&
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
+ });
141
114
  }
142
115
  static candidateContainers(measured, containers) {
143
116
  const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
144
- const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
145
- !dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
146
117
  return containers.filter((container) => {
147
118
  var _a;
148
119
  if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
@@ -151,7 +122,7 @@ class DocumentContainerService {
151
122
  if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
152
123
  return false;
153
124
  }
154
- if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
125
+ if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
155
126
  return false;
156
127
  }
157
128
  return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
@@ -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;
@@ -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}`;
@@ -176,8 +185,9 @@ class DynamicTextUtil {
176
185
  bold,
177
186
  italic,
178
187
  };
179
- if (!dynamicTextElement.isTextTool) {
180
- measureTextSettings.width = size.width - padding * 2;
188
+ const fixedWidth = size.width - padding * 2;
189
+ if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
190
+ measureTextSettings.width = fixedWidth;
181
191
  }
182
192
  try {
183
193
  const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
@@ -207,7 +217,7 @@ class DynamicTextUtil {
207
217
  }
208
218
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
209
219
  text = Array.from(new Set(memberValues
210
- .filter((e) => e !== null && e !== undefined)
220
+ .filter((e) => e !== null && e !== undefined && e !== '')
211
221
  .flat()
212
222
  .map((e) => formatter.formatValueForProperty(e, property))))
213
223
  .sort()
@@ -222,7 +232,10 @@ class DynamicTextUtil {
222
232
  }
223
233
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
224
234
  displayFunction === DynamicTextDisplayFunction.MAX) {
225
- const present = memberValues.filter((e) => e !== null && e !== undefined);
235
+ const present = memberValues
236
+ .filter((e) => e !== null && e !== undefined && e !== '')
237
+ .map(Number)
238
+ .filter((e) => !Number.isNaN(e));
226
239
  if (!present.length) {
227
240
  return '';
228
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.a01d866",
3
+ "version": "2.4.0-alpha.a4d67e4",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",