@contrail/documents 1.21.0-alpha.55b073f → 1.21.0-alpha.6617965

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,59 +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`, `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.
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`.
36
42
 
37
43
  ### Deprecated
38
44
 
39
45
  - `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.
46
+ for what it decides. The old name still works and delegates to the new one.
42
47
 
43
48
  ### Fixed
44
49
 
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.
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.
63
72
 
64
73
  ### Changed
65
74
 
66
- - Container membership measures a scaled element from its scaled box, through the new
67
- `getBoundingClientRectScaled` above. A scaled element previously measured at its unscaled size
68
- and could resolve to the wrong container.
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.
69
91
 
70
92
  ## [1.20.0] - 2026-09-25
71
93
 
@@ -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];
@@ -1,23 +1,24 @@
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[]>;
11
12
  containerIdsByElementType: Map<string, string[]>;
12
13
  });
14
+ static empty(): DocumentContainerIndex;
13
15
  getContainer(containerId: string): DocumentContainer | null;
14
16
  containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
15
17
  containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
16
18
  innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
17
19
  memberIdsOf(containerId: string): readonly string[];
18
20
  memberDocumentElementsOf(containerId: string): DocumentElement[];
19
- containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
20
- maxDepth(elementType: ContainerElementType): number;
21
+ containerPathFor(documentElement: DocumentElement, kind: ContainerKind): readonly string[];
21
22
  private containersOfType;
22
23
  private resolveAll;
23
24
  private containerPath;
@@ -6,6 +6,16 @@ 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
+ measuredById: new Map(),
13
+ containersById: new Map(),
14
+ containerPathsByDocumentElementId: new Map(),
15
+ memberIdsByContainerId: new Map(),
16
+ containerIdsByElementType: new Map(),
17
+ });
18
+ }
9
19
  getContainer(containerId) {
10
20
  var _a;
11
21
  return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
@@ -14,7 +24,7 @@ class DocumentContainerIndex {
14
24
  return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
15
25
  }
16
26
  containerIdsOf(documentElementId, elementType) {
17
- return this.containerPath(documentElementId, elementType);
27
+ return [...this.containerPath(documentElementId, elementType)];
18
28
  }
19
29
  innermostContainerIdOf(documentElementId, elementType) {
20
30
  const path = this.containerPath(documentElementId, elementType);
@@ -22,7 +32,7 @@ class DocumentContainerIndex {
22
32
  }
23
33
  memberIdsOf(containerId) {
24
34
  var _a;
25
- return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
35
+ return [...((_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [])];
26
36
  }
27
37
  memberDocumentElementsOf(containerId) {
28
38
  const members = [];
@@ -34,12 +44,17 @@ class DocumentContainerIndex {
34
44
  }
35
45
  return members;
36
46
  }
37
- 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
+ containerPathFor(documentElement, kind) {
48
+ var _a, _b;
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);
43
58
  }
44
59
  containersOfType(elementType) {
45
60
  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,17 @@ 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;
22
- static anchorFor(documentElement: DocumentElement, position?: PositionDefinition): PositionDefinition;
20
+ static resizeKeepingAnchor(dynamicTextElement: DocumentElement, entityType: any, text: string): {
21
+ size: SizeDefinition;
22
+ position: PositionDefinition;
23
+ };
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 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[];
32
+ static topmost(containers: DocumentContainer[]): DocumentContainer[];
27
33
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentContainerUtil = void 0;
4
4
  const rotation_math_1 = require("../util/mask/rotation-math");
5
5
  const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
6
+ const document_element_factory_1 = require("../document-element-factory");
6
7
  class DocumentContainerUtil {
7
8
  static toCoordinateBox(x, y, width, height) {
8
9
  return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
@@ -23,9 +24,12 @@ class DocumentContainerUtil {
23
24
  var _a, _b, _c, _d, _e;
24
25
  const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
25
26
  const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
26
- if (!position || !angle || !newSize || !documentElement.size) {
27
+ if (!position) {
27
28
  return position;
28
29
  }
30
+ if (!angle || !newSize || !documentElement.size) {
31
+ return Object.assign({}, position);
32
+ }
29
33
  const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
30
34
  const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
31
35
  const cornerOffset = (size) => {
@@ -35,17 +39,23 @@ class DocumentContainerUtil {
35
39
  };
36
40
  const before = cornerOffset(documentElement.size);
37
41
  const after = cornerOffset(newSize);
38
- 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);
39
44
  }
40
- static anchorFor(documentElement, position) {
41
- var _a, _b, _c, _d, _e;
45
+ static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
46
+ const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
47
+ return { size, position: DocumentContainerUtil.positionKeepingAnchor(dynamicTextElement, size) };
48
+ }
49
+ static anchorFor(documentElement, position, startElement, endElement) {
42
50
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
43
- if (!at) {
51
+ try {
52
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
53
+ const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
54
+ return DocumentContainerUtil.anchorOf(documentElement, box);
55
+ }
56
+ catch (_a) {
44
57
  return null;
45
58
  }
46
- const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
47
- const box = DocumentContainerUtil.toCoordinateBox(at.x, at.y, 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), 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));
48
- return DocumentContainerUtil.anchorOf(documentElement, box);
49
59
  }
50
60
  static containsPoint(box, point) {
51
61
  return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
@@ -58,18 +68,75 @@ class DocumentContainerUtil {
58
68
  outer.bottom === inner.bottom;
59
69
  return covers && !identical;
60
70
  }
61
- static isWiderAndTallerThan(box, other) {
62
- return box.width > other.width && box.height > other.height;
71
+ static chain(candidates) {
72
+ if (!candidates.length) {
73
+ return [];
74
+ }
75
+ const topmostOf = (of) => of.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
76
+ const path = [topmostOf(candidates)];
77
+ for (;;) {
78
+ const current = path[0];
79
+ const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
80
+ if (!enclosing.length) {
81
+ return path;
82
+ }
83
+ path.unshift(topmostOf(enclosing));
84
+ }
63
85
  }
64
- static topmostPerDepth(containers) {
65
- const byDepth = [];
66
- for (const container of containers) {
67
- const existing = byDepth[container.depth];
68
- if (!existing || container.drawOrder > existing.drawOrder) {
69
- byDepth[container.depth] = container;
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;
70
94
  }
95
+ return DocumentContainerUtil.toCoordinateBox(x, y, width, height);
96
+ }
97
+ catch (_c) {
98
+ return null;
71
99
  }
72
- return byDepth.filter(Boolean);
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
+ }
136
+ static topmost(containers) {
137
+ return containers.length
138
+ ? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
139
+ : [];
73
140
  }
74
141
  }
75
142
  exports.DocumentContainerUtil = DocumentContainerUtil;
@@ -5,10 +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
- private static buildNesting;
10
- private static resolveContainerPath;
11
- private static resolveInnermostOnTop;
12
- private static toContainerPath;
13
- private static candidateContainers;
8
+ private static collectContainers;
14
9
  }
@@ -1,44 +1,63 @@
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
- const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
6
- const document_element_constants_1 = require("../document-element-constants");
7
4
  const container_kind_1 = require("./container-kind");
8
5
  const document_container_index_1 = require("./document-container-index");
9
6
  const document_container_1 = require("./document-container");
10
7
  class DocumentContainerService {
11
8
  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)]));
9
+ var _a, _b;
10
+ const elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
11
+ const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
12
+ if (!elements.some((element) => containerElementTypes.has(element.type))) {
13
+ return document_container_index_1.DocumentContainerIndex.empty();
14
+ }
15
+ const documentElementsById = new Map(elements.map((element) => [element.id, element]));
16
+ const measuredDocumentElements = this.measureDocumentElements(elements, documentElementsById);
17
+ const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
14
18
  const containersById = new Map();
15
19
  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));
20
+ containersByElementType.forEach((containers, elementType) => {
21
+ containerIdsByElementType.set(elementType, containers.map((container) => container.id));
22
+ containers.forEach((container) => containersById.set(container.id, container));
19
23
  });
24
+ const pathsByMeasured = new Map();
25
+ for (const measured of measuredDocumentElements) {
26
+ const byElementType = new Map();
27
+ for (const kind of kinds) {
28
+ byElementType.set(kind.elementType, document_container_1.DocumentContainerUtil.pathFor(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
29
+ }
30
+ pathsByMeasured.set(measured, byElementType);
31
+ }
20
32
  const containerPathsByDocumentElementId = new Map();
21
33
  const memberIdsByContainerId = new Map();
34
+ const memberIdsSeen = new Map();
22
35
  for (const measured of measuredDocumentElements) {
23
36
  const documentElementId = measured.documentElement.id;
24
37
  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);
38
+ ((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
39
+ for (const path of pathsByElementType.values()) {
28
40
  for (const containerId of path) {
29
- const members = memberIdsByContainerId.get(containerId);
30
- if (members) {
31
- members.push(documentElementId);
32
- }
33
- else {
41
+ const seen = memberIdsSeen.get(containerId);
42
+ if (!seen) {
43
+ memberIdsSeen.set(containerId, new Set([documentElementId]));
34
44
  memberIdsByContainerId.set(containerId, [documentElementId]);
35
45
  }
46
+ else if (!seen.has(documentElementId)) {
47
+ seen.add(documentElementId);
48
+ memberIdsByContainerId.get(containerId).push(documentElementId);
49
+ }
36
50
  }
37
51
  }
38
52
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
39
53
  }
54
+ const measuredById = new Map();
55
+ for (const measured of measuredDocumentElements) {
56
+ measuredById.set(measured.documentElement.id, measured);
57
+ }
40
58
  return new document_container_index_1.DocumentContainerIndex({
41
- documentElementsById: new Map(measuredDocumentElements.map((measured) => [measured.documentElement.id, measured.documentElement])),
59
+ documentElementsById,
60
+ measuredById,
42
61
  containersById,
43
62
  containerPathsByDocumentElementId,
44
63
  memberIdsByContainerId,
@@ -48,100 +67,23 @@ class DocumentContainerService {
48
67
  static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
49
68
  return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
50
69
  }
51
- static measureDocumentElements(documentElements) {
52
- const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
70
+ static measureDocumentElements(documentElements, documentElementsById) {
53
71
  return documentElements.map((documentElement, drawOrder) => ({
54
72
  documentElement,
55
73
  drawOrder,
56
- box: this.measure(documentElement, documentElementsById),
74
+ box: document_container_1.DocumentContainerUtil.measureBox(documentElement, documentElementsById),
57
75
  }));
58
76
  }
59
- static measure(documentElement, documentElementsById) {
60
- var _a, _b;
61
- if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
62
- return null;
63
- }
64
- 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;
67
- const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
68
- return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
69
- }
70
- catch (_c) {
71
- return null;
72
- }
73
- }
74
- static buildNesting(measuredDocumentElements, kind) {
75
- const containers = measuredDocumentElements
77
+ static collectContainers(measuredDocumentElements, kind) {
78
+ return measuredDocumentElements
76
79
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
77
80
  .map((measured) => ({
78
81
  id: measured.documentElement.id,
79
82
  kind,
80
- name: measured.documentElement.name,
81
83
  documentElement: measured.documentElement,
82
84
  box: measured.box,
83
- depth: 0,
84
85
  drawOrder: measured.drawOrder,
85
86
  }));
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
- container.depth = ancestors.length;
93
- }
94
- return { containers, ancestorsById };
95
- }
96
- static resolveContainerPath(measured, kind, kinds, nesting) {
97
- var _a, _b;
98
- if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
99
- return [];
100
- }
101
- const ownKind = kinds.find((candidate) => candidate.elementType === measured.documentElement.type);
102
- if (ownKind) {
103
- if (ownKind.elementType === kind.elementType) {
104
- return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
105
- }
106
- if (kind.layer > ownKind.layer) {
107
- return [];
108
- }
109
- }
110
- const candidates = this.candidateContainers(measured, nesting.containers);
111
- if (!candidates.length) {
112
- return [];
113
- }
114
- const innermostOnTop = this.resolveInnermostOnTop(candidates, nesting);
115
- const candidateIds = new Set(candidates.map((container) => container.id));
116
- const ancestors = ((_b = nesting.ancestorsById.get(innermostOnTop.id)) !== null && _b !== void 0 ? _b : []).filter((container) => candidateIds.has(container.id));
117
- return this.toContainerPath([...ancestors, innermostOnTop]);
118
- }
119
- static resolveInnermostOnTop(candidates, nesting) {
120
- 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));
121
- return candidates
122
- .filter((container) => !enclosingIds.has(container.id))
123
- .reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
124
- }
125
- static toContainerPath(containers) {
126
- return document_container_1.DocumentContainerUtil.topmostPerDepth(containers).map((container) => container.id);
127
- }
128
- static candidateContainers(measured, containers) {
129
- const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
130
- const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
131
- !dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
132
- return containers.filter((container) => {
133
- var _a;
134
- if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
135
- return false;
136
- }
137
- if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
138
- return false;
139
- }
140
- if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
141
- return false;
142
- }
143
- return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
144
- });
145
87
  }
146
88
  }
147
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;
@@ -48,11 +50,17 @@ export declare const HARD_CODED_TEXT: {
48
50
  'section.itemOptionCount': string;
49
51
  'section.colorCount': string;
50
52
  };
53
+ export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
51
54
  export declare class DynamicTextUtil {
55
+ static componentsBoundTo(componentElements: DocumentElement[], entityType: string): DocumentElement[];
52
56
  static isDynamicText(documentElement: DocumentElement): boolean;
53
57
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
54
58
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
55
- 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;
56
64
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
57
65
  private static getItemCount;
58
66
  }
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DynamicTextUtil = exports.HARD_CODED_TEXT = exports.CLICK_TO_CONFIGURE = exports.MOVE_TO_SECTION_TEXT = exports.MOVE_TO_FRAME_TEXT = exports.DynamicTextDisplayFunction = exports.DYNAMIC_TEXT_DATA_SOURCE = void 0;
4
+ exports.placeholderForMissingContainer = placeholderForMissingContainer;
5
+ exports.isPlaceholderText = isPlaceholderText;
6
+ exports.isContainerBinding = isContainerBinding;
4
7
  const types_1 = require("@contrail/types");
5
8
  const util_1 = require("@contrail/util");
6
9
  const document_util_1 = require("@contrail/document-util");
@@ -27,6 +30,12 @@ var DynamicTextDisplayFunction;
27
30
  exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
28
31
  exports.MOVE_TO_SECTION_TEXT = 'Move to a section';
29
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
+ }
30
39
  exports.HARD_CODED_TEXT = {
31
40
  'project.name': 'Project name',
32
41
  'project.createdBy.email': 'Project created by',
@@ -50,10 +59,20 @@ exports.HARD_CODED_TEXT = {
50
59
  };
51
60
  const CONTAINER_PROPERTY_SLUGS = ['name', 'count', 'itemFamilyCount', 'itemOptionCount', 'colorCount'];
52
61
  const CONTAINER_SOURCES = [DYNAMIC_TEXT_DATA_SOURCE.FRAME, DYNAMIC_TEXT_DATA_SOURCE.SECTION];
62
+ function isContainerBinding(bindingProperty) {
63
+ return DynamicTextUtil.takesValueFromContainer(bindingProperty);
64
+ }
53
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
+ }
54
72
  static isDynamicText(documentElement) {
73
+ var _a;
55
74
  return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
56
- !!documentElement.propertyBindings &&
75
+ !!((_a = documentElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text) &&
57
76
  !!documentElement.propertyBindingsMetaData);
58
77
  }
59
78
  static takesValueFromContainer(bindingProperty) {
@@ -93,7 +112,7 @@ class DynamicTextUtil {
93
112
  }
94
113
  else {
95
114
  if (!container && !isSpecRelated) {
96
- text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
115
+ text = placeholderForMissingContainer(entityType);
97
116
  }
98
117
  else {
99
118
  if (CONTAINER_SOURCES.includes(entityType)) {
@@ -136,7 +155,7 @@ class DynamicTextUtil {
136
155
  text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
137
156
  }
138
157
  else if (!container) {
139
- text = exports.MOVE_TO_FRAME_TEXT;
158
+ text = placeholderForMissingContainer(entityType);
140
159
  }
141
160
  else {
142
161
  text = property === null || property === void 0 ? void 0 : property.label;
@@ -146,7 +165,7 @@ class DynamicTextUtil {
146
165
  text = 'n/a';
147
166
  }
148
167
  if (displayLabel &&
149
- ![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
168
+ !isPlaceholderText(text) &&
150
169
  displayFunction !== DynamicTextDisplayFunction.LABEL &&
151
170
  text !== bindingProperty) {
152
171
  text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
@@ -154,16 +173,19 @@ class DynamicTextUtil {
154
173
  return text;
155
174
  }
156
175
  static calculateSize(dynamicTextElement, entityType, text) {
157
- var _a, _b, _c, _d, _e;
158
- let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
159
- 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;
160
- const fontSize = (_e = (dynamicTextElement.isTextTool
161
- ? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
162
- : 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;
163
185
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
164
186
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
165
- const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
166
- 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 : '');
167
189
  const measureTextSettings = {
168
190
  fontFamily,
169
191
  fontSize: fontSizePx,
@@ -172,8 +194,9 @@ class DynamicTextUtil {
172
194
  bold,
173
195
  italic,
174
196
  };
175
- if (!dynamicTextElement.isTextTool) {
176
- measureTextSettings.width = size.width - padding * 2;
197
+ const fixedWidth = size.width - padding * 2;
198
+ if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
199
+ measureTextSettings.width = fixedWidth;
177
200
  }
178
201
  try {
179
202
  const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
@@ -187,6 +210,9 @@ class DynamicTextUtil {
187
210
  catch (e) { }
188
211
  return size;
189
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
+ }
190
216
  static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
191
217
  let text = '';
192
218
  if (memberValues.length === 0) {
@@ -202,11 +228,16 @@ class DynamicTextUtil {
202
228
  text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
203
229
  }
204
230
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
205
- text = Array.from(new Set(memberValues
206
- .filter((e) => e !== null && e !== undefined)
207
- .flat()
208
- .map((e) => formatter.formatValueForProperty(e, property))))
209
- .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)
210
241
  .join(', ');
211
242
  }
212
243
  else if (!displayFunction ||
@@ -218,12 +249,17 @@ class DynamicTextUtil {
218
249
  }
219
250
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
220
251
  displayFunction === DynamicTextDisplayFunction.MAX) {
221
- const present = memberValues.filter((e) => e !== null && e !== undefined);
222
- if (!present.length) {
252
+ const isDate = (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date;
253
+ const ranked = memberValues
254
+ .filter((e) => e !== null && e !== undefined && e !== '')
255
+ .map((value) => ({ value, rank: DynamicTextUtil.rankValue(value, property) }))
256
+ .filter(({ rank }) => !Number.isNaN(rank));
257
+ if (!ranked.length) {
223
258
  return '';
224
259
  }
225
- const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
226
- 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);
227
263
  }
228
264
  return text;
229
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.21.0-alpha.55b073f",
3
+ "version": "1.21.0-alpha.6617965",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",