@contrail/documents 1.21.0-alpha.3614d20 → 1.21.0-alpha.47c1213

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,81 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.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.
30
+
31
+ ### Removed
32
+
33
+ - `DocumentContainerIndex.containerPathAtPoint`. It applied the anchor rule alone, because a bare
34
+ point has nothing to compare against a container, and returned the same shape as `containerIdsOf`,
35
+ so it read as a second way to ask one question. `containerPathFor(element, kind)` replaces it and
36
+ applies every rule. Callers that hold a position pass the element with that position on it. This
37
+ is the one removal a consumer has to act on.
38
+ - `ContainerKind.layer`, `DocumentContainer.name` and `DocumentContainer.depth`, and
39
+ `DocumentContainerIndex.maxDepth`. The container API has not shipped in a released version, so
40
+ nothing outside this repository can be holding them. Read a container's name from
41
+ `documentElement.name`.
43
42
 
44
43
  ### Deprecated
45
44
 
46
45
  - `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.
46
+ for what it decides. The old name still works and delegates to the new one.
49
47
 
50
48
  ### Fixed
51
49
 
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.
50
+ - A dynamic text is anchored at its drawn top-left corner rather than its centre. Its size comes
51
+ from the value it resolves to and that value comes from its container, so an anchor that moved
52
+ with the size let the two choose each other: near an edge they never settled, flipping between a
53
+ value and "Move to a frame" on every read. The corner is the rotated one, so a text turned on its
54
+ side anchors where it appears (VIBE-9567).
55
+ - `isDynamicText` requires a `propertyBindings.text` binding, the one the value is read from. The
56
+ text tool creates an element with empty bindings and empty metadata, both truthy, so an
57
+ unconfigured text was anchored at its corner while the canvas centred it.
58
+ - An element covering a container is not inside it, whatever its type. The rule it replaces looked
59
+ only at shapes wider and taller than the container, so a background image joined the frame it
60
+ covered.
61
+ - A line or callout is measured from the elements it connects even with no stored `position`, where
62
+ it was previously left out of the index entirely.
63
+ - `min` and `max` rendered an infinity sign when every member value was empty; both fall through to
64
+ `n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
65
+ the server failed the read for the whole document.
66
+
67
+ - `min` and `max` over a date property rendered nothing at all. `Number` of a date string is `NaN`,
68
+ so every member was dropped; they now order by the instant each date names.
69
+ - `uniqueArray` sorted the rendered text rather than the value, so `11/20/2026` came after
70
+ `01/15/2027` and `100` before `9`. It now orders by value, falling back to text order for values
71
+ that are neither a date nor a number.
77
72
 
78
73
  ### Changed
79
74
 
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.
75
+ - `anchorFor` and the index measure through the same factory call, so a caller holding an element
76
+ gets the answer the index would give it. Reading `size` directly disagreed for the types whose box
77
+ is not position plus size.
78
+ - A container path is a containment chain, walked outward from the container the element sits on, so
79
+ two containers that merely cross no longer both claim it.
80
+ - `buildIndex` scans element types before measuring, so a document with no containers of the kinds
81
+ asked for returns an empty index without a geometry pass.
82
+ - **A section nests inside another only when it is drawn above it.** A section drawn over one it
83
+ encloses hides it, so the hidden section holds nothing and a `section.count` on it reads zero.
84
+ This changes existing boards wherever the outer section was drawn last.
85
+ - `containerIdsOf` and `memberIdsOf` return copies. `readonly` is erased at runtime, and a caller
86
+ sorting what it got back reordered the index's own list for every later read.
87
+ - A member list is a set of ids, so two elements sharing an id count once.
88
+ - `min` and `max` no longer read an empty member as zero, and `uniqueArray` no longer emits one as
89
+ a blank entry. A text box narrower than its own padding measures without a fixed width.
90
+ - A nullish entry in the element list is dropped rather than throwing.
94
91
 
95
92
  ## [1.20.0] - 2026-09-25
96
93
 
@@ -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,9 +18,8 @@ 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;
24
- private containerPathCopy;
25
25
  }
@@ -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,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;
@@ -69,8 +74,5 @@ class DocumentContainerIndex {
69
74
  var _a, _b;
70
75
  return (_b = (_a = this.data.containerPathsByDocumentElementId.get(documentElementId)) === null || _a === void 0 ? void 0 : _a.get(elementType)) !== null && _b !== void 0 ? _b : [];
71
76
  }
72
- containerPathCopy(documentElementId, elementType) {
73
- return [...this.containerPath(documentElementId, elementType)];
74
- }
75
77
  }
76
78
  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 && !x && !y) {
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;
@@ -50,10 +52,15 @@ export declare const HARD_CODED_TEXT: {
50
52
  };
51
53
  export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
52
54
  export declare class DynamicTextUtil {
55
+ static componentsBoundTo(componentElements: DocumentElement[], entityType: string): DocumentElement[];
53
56
  static isDynamicText(documentElement: DocumentElement): boolean;
54
57
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
55
58
  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;
59
+ static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): {
60
+ width: number;
61
+ height: number;
62
+ };
63
+ private static rankValue;
57
64
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
58
65
  private static getItemCount;
59
66
  }
@@ -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',
@@ -55,6 +63,12 @@ function isContainerBinding(bindingProperty) {
55
63
  return DynamicTextUtil.takesValueFromContainer(bindingProperty);
56
64
  }
57
65
  class DynamicTextUtil {
66
+ static componentsBoundTo(componentElements, entityType) {
67
+ if (CONTAINER_SOURCES.includes(entityType)) {
68
+ return componentElements;
69
+ }
70
+ return (componentElements !== null && componentElements !== void 0 ? componentElements : []).filter((element) => { var _a; return Object.keys((_a = element === null || element === void 0 ? void 0 : element.modelBindings) !== null && _a !== void 0 ? _a : {}).includes(entityType); });
71
+ }
58
72
  static isDynamicText(documentElement) {
59
73
  var _a;
60
74
  return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
@@ -98,7 +112,7 @@ class DynamicTextUtil {
98
112
  }
99
113
  else {
100
114
  if (!container && !isSpecRelated) {
101
- text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
115
+ text = placeholderForMissingContainer(entityType);
102
116
  }
103
117
  else {
104
118
  if (CONTAINER_SOURCES.includes(entityType)) {
@@ -141,7 +155,7 @@ class DynamicTextUtil {
141
155
  text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
142
156
  }
143
157
  else if (!container) {
144
- text = exports.MOVE_TO_FRAME_TEXT;
158
+ text = placeholderForMissingContainer(entityType);
145
159
  }
146
160
  else {
147
161
  text = property === null || property === void 0 ? void 0 : property.label;
@@ -151,7 +165,7 @@ class DynamicTextUtil {
151
165
  text = 'n/a';
152
166
  }
153
167
  if (displayLabel &&
154
- ![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
168
+ !isPlaceholderText(text) &&
155
169
  displayFunction !== DynamicTextDisplayFunction.LABEL &&
156
170
  text !== bindingProperty) {
157
171
  text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
@@ -159,16 +173,19 @@ class DynamicTextUtil {
159
173
  return text;
160
174
  }
161
175
  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;
176
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
177
+ let size = {
178
+ width: (_b = (_a = dynamicTextElement.size) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0,
179
+ height: (_d = (_c = dynamicTextElement.size) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0,
180
+ };
181
+ 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;
182
+ const fontSize = (_j = (dynamicTextElement.isTextTool
183
+ ? (_h = (_g = dynamicTextElement.style) === null || _g === void 0 ? void 0 : _g.font) === null || _h === void 0 ? void 0 : _h.size
184
+ : 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
185
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
169
186
  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);
187
+ const bold = document_util_1.DocumentStyleUtil.isBold((_k = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _k !== void 0 ? _k : '', fontFamily);
188
+ const italic = document_util_1.DocumentStyleUtil.isItalic((_l = dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text) !== null && _l !== void 0 ? _l : '');
172
189
  const measureTextSettings = {
173
190
  fontFamily,
174
191
  fontSize: fontSizePx,
@@ -193,6 +210,9 @@ class DynamicTextUtil {
193
210
  catch (e) { }
194
211
  return size;
195
212
  }
213
+ static rankValue(value, property) {
214
+ return (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date ? Date.parse(value) : Number(value);
215
+ }
196
216
  static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
197
217
  let text = '';
198
218
  if (memberValues.length === 0) {
@@ -208,11 +228,16 @@ class DynamicTextUtil {
208
228
  text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
209
229
  }
210
230
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
211
- text = Array.from(new Set(memberValues
212
- .filter((e) => e !== null && e !== undefined && e !== '')
213
- .flat()
214
- .map((e) => formatter.formatValueForProperty(e, property))))
215
- .sort()
231
+ const byValue = new Map();
232
+ for (const value of memberValues.filter((e) => e !== null && e !== undefined && e !== '').flat()) {
233
+ const formatted = formatter.formatValueForProperty(value, property);
234
+ if (!byValue.has(formatted)) {
235
+ byValue.set(formatted, DynamicTextUtil.rankValue(value, property));
236
+ }
237
+ }
238
+ text = Array.from(byValue)
239
+ .sort(([leftText, leftRank], [rightText, rightRank]) => Number.isNaN(leftRank) || Number.isNaN(rightRank) ? leftText.localeCompare(rightText) : leftRank - rightRank)
240
+ .map(([formatted]) => formatted)
216
241
  .join(', ');
217
242
  }
218
243
  else if (!displayFunction ||
@@ -224,15 +249,17 @@ class DynamicTextUtil {
224
249
  }
225
250
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
226
251
  displayFunction === DynamicTextDisplayFunction.MAX) {
227
- const present = memberValues
252
+ const isDate = (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date;
253
+ const ranked = memberValues
228
254
  .filter((e) => e !== null && e !== undefined && e !== '')
229
- .map(Number)
230
- .filter((e) => !Number.isNaN(e));
231
- if (!present.length) {
255
+ .map((value) => ({ value, rank: DynamicTextUtil.rankValue(value, property) }))
256
+ .filter(({ rank }) => !Number.isNaN(rank));
257
+ if (!ranked.length) {
232
258
  return '';
233
259
  }
234
- const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
235
- text = formatter.formatValueForProperty(extreme, property);
260
+ const wantsLower = displayFunction === DynamicTextDisplayFunction.MIN;
261
+ const extreme = ranked.reduce((best, candidate) => (wantsLower ? candidate.rank < best.rank : candidate.rank > best.rank) ? candidate : best);
262
+ text = formatter.formatValueForProperty(isDate ? extreme.value : extreme.rank, property);
236
263
  }
237
264
  return text;
238
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.21.0-alpha.3614d20",
3
+ "version": "1.21.0-alpha.47c1213",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",