@contrail/documents 1.21.0-alpha.fb70961 → 1.22.0-alpha.766acdd

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
@@ -5,6 +5,17 @@ All notable changes to `@contrail/documents` are documented here.
5
5
  Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
  Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.22.0] - 2026-10-10
9
+
10
+ Also shipped on the 2.x line as 2.5.0.
11
+
12
+ ### Added
13
+
14
+ - `clientCreatedOn` on `WriteTransactionRequest`, `DocumentTransactionPayload`, and
15
+ `DocumentTransactionMessage`: when the writing client created the transaction (ISO 8601, client
16
+ clock). The server stores it with the transaction and passes it through in the broadcast, so a
17
+ receiver can measure how long the edit took to reach it.
18
+
8
19
  ## [1.21.0] - 2026-09-26
9
20
 
10
21
  Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
@@ -28,6 +39,18 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
28
39
  member into a different cell. Anything deciding what an element overlaps or sits on wants the
29
40
  scaled one.
30
41
 
42
+ ### Removed
43
+
44
+ - `DocumentContainerIndex.containerPathAtPoint`. It applied the anchor rule alone, because a bare
45
+ point has nothing to compare against a container, and returned the same shape as `containerIdsOf`,
46
+ so it read as a second way to ask one question. `containerPathFor(element, kind)` replaces it and
47
+ applies every rule. Callers that hold a position pass the element with that position on it. This
48
+ is the one removal a consumer has to act on.
49
+ - `ContainerKind.layer`, `DocumentContainer.name` and `DocumentContainer.depth`, and
50
+ `DocumentContainerIndex.maxDepth`. The container API has not shipped in a released version, so
51
+ nothing outside this repository can be holding them. Read a container's name from
52
+ `documentElement.name`.
53
+
31
54
  ### Deprecated
32
55
 
33
56
  - `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
@@ -52,6 +75,12 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
52
75
  `n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
53
76
  the server failed the read for the whole document.
54
77
 
78
+ - `min` and `max` over a date property rendered nothing at all. `Number` of a date string is `NaN`,
79
+ so every member was dropped; they now order by the instant each date names.
80
+ - `uniqueArray` sorted the rendered text rather than the value, so `11/20/2026` came after
81
+ `01/15/2027` and `100` before `9`. It now orders by value, falling back to text order for values
82
+ that are neither a date nor a number.
83
+
55
84
  ### Changed
56
85
 
57
86
  - `anchorFor` and the index measure through the same factory call, so a caller holding an element
@@ -61,6 +90,15 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
61
90
  two containers that merely cross no longer both claim it.
62
91
  - `buildIndex` scans element types before measuring, so a document with no containers of the kinds
63
92
  asked for returns an empty index without a geometry pass.
93
+ - **A section nests inside another only when it is drawn above it.** A section drawn over one it
94
+ encloses hides it, so the hidden section holds nothing and a `section.count` on it reads zero.
95
+ This changes existing boards wherever the outer section was drawn last.
96
+ - `containerIdsOf` and `memberIdsOf` return copies. `readonly` is erased at runtime, and a caller
97
+ sorting what it got back reordered the index's own list for every later read.
98
+ - A member list is a set of ids, so two elements sharing an id count once.
99
+ - `min` and `max` no longer read an empty member as zero, and `uniqueArray` no longer emits one as
100
+ a blank entry. A text box narrower than its own padding measures without a fixed width.
101
+ - A nullish entry in the element list is dropped rather than throwing.
64
102
 
65
103
  ## [1.20.0] - 2026-09-25
66
104
 
@@ -1,10 +1,11 @@
1
- import { DocumentElement, PositionDefinition } from '../types';
2
- import { ContainerElementType } from './container-kind';
3
- import { DocumentContainer } from './document-container';
1
+ import { DocumentElement } from '../types';
2
+ import { ContainerElementType, ContainerKind } from './container-kind';
3
+ import { DocumentContainer, MeasuredDocumentElement } from './document-container';
4
4
  export declare class DocumentContainerIndex {
5
5
  private readonly data;
6
6
  constructor(data: {
7
7
  documentElementsById: Map<string, DocumentElement>;
8
+ measuredById: Map<string, MeasuredDocumentElement>;
8
9
  containersById: Map<string, DocumentContainer>;
9
10
  containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
10
11
  memberIdsByContainerId: Map<string, string[]>;
@@ -17,7 +18,7 @@ export declare class DocumentContainerIndex {
17
18
  innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
18
19
  memberIdsOf(containerId: string): readonly string[];
19
20
  memberDocumentElementsOf(containerId: string): DocumentElement[];
20
- containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
21
+ containerPathFor(documentElement: DocumentElement, kind: ContainerKind): readonly string[];
21
22
  private containersOfType;
22
23
  private resolveAll;
23
24
  private containerPath;
@@ -9,6 +9,7 @@ class DocumentContainerIndex {
9
9
  static empty() {
10
10
  return new DocumentContainerIndex({
11
11
  documentElementsById: new Map(),
12
+ measuredById: new Map(),
12
13
  containersById: new Map(),
13
14
  containerPathsByDocumentElementId: new Map(),
14
15
  memberIdsByContainerId: new Map(),
@@ -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;
@@ -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);
@@ -79,6 +83,56 @@ class DocumentContainerUtil {
79
83
  path.unshift(topmostOf(enclosing));
80
84
  }
81
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
+ }
82
136
  static topmost(containers) {
83
137
  return containers.length
84
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,7 +25,7 @@ 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
  }
@@ -52,8 +51,13 @@ class DocumentContainerService {
52
51
  }
53
52
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
54
53
  }
54
+ const measuredById = new Map();
55
+ for (const measured of measuredDocumentElements) {
56
+ measuredById.set(measured.documentElement.id, measured);
57
+ }
55
58
  return new document_container_index_1.DocumentContainerIndex({
56
59
  documentElementsById,
60
+ measuredById,
57
61
  containersById,
58
62
  containerPathsByDocumentElementId,
59
63
  memberIdsByContainerId,
@@ -67,21 +71,9 @@ class DocumentContainerService {
67
71
  return documentElements.map((documentElement, drawOrder) => ({
68
72
  documentElement,
69
73
  drawOrder,
70
- box: this.measure(documentElement, documentElementsById),
74
+ box: document_container_1.DocumentContainerUtil.measureBox(documentElement, documentElementsById),
71
75
  }));
72
76
  }
73
- static measure(documentElement, documentElementsById) {
74
- var _a, _b;
75
- try {
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;
78
- const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
79
- return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
80
- }
81
- catch (_c) {
82
- return null;
83
- }
84
- }
85
77
  static collectContainers(measuredDocumentElements, kind) {
86
78
  return measuredDocumentElements
87
79
  .filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
@@ -93,40 +85,5 @@ class DocumentContainerService {
93
85
  drawOrder: measured.drawOrder,
94
86
  }));
95
87
  }
96
- static resolvePath(measured, kind, containers) {
97
- if (!containers.length || !measured.box) {
98
- return [];
99
- }
100
- if (measured.documentElement.type === kind.elementType) {
101
- return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
102
- }
103
- const candidates = this.candidateContainers(measured, containers);
104
- return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
105
- }
106
- static enclosersOf(measured, containers) {
107
- return containers.filter((container) => {
108
- var _a;
109
- return container.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
- });
114
- }
115
- static candidateContainers(measured, containers) {
116
- const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
117
- return containers.filter((container) => {
118
- var _a;
119
- if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
120
- return false;
121
- }
122
- if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
123
- return false;
124
- }
125
- if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
126
- return false;
127
- }
128
- return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
129
- });
130
- }
131
88
  }
132
89
  exports.DocumentContainerService = DocumentContainerService;
@@ -13,6 +13,7 @@ export type DocumentOperation = {
13
13
  export type DocumentElementPatch = Partial<Omit<DocumentElement, 'id' | 'documentId'>>;
14
14
  interface WriteTransactionRequestBase {
15
15
  clientTransactionId?: string;
16
+ clientCreatedOn?: string;
16
17
  }
17
18
  export interface InlineWriteTransactionRequest extends WriteTransactionRequestBase {
18
19
  operations: DocumentOperation[];
@@ -53,6 +54,7 @@ interface DocumentTransactionMessageBase {
53
54
  sequenceNumber: number;
54
55
  createdOn: string;
55
56
  clientTransactionId?: string;
57
+ clientCreatedOn?: string;
56
58
  }
57
59
  export type DocumentTransactionMessage = (DocumentTransactionMessageBase & {
58
60
  operations: DocumentOperation[];
@@ -68,6 +70,7 @@ export interface TransactionUploadTarget {
68
70
  }
69
71
  export type DocumentTransactionPayload = {
70
72
  clientTransactionId?: string;
73
+ clientCreatedOn?: string;
71
74
  } & ({
72
75
  operations: DocumentOperation[];
73
76
  operationsS3Key?: never;
@@ -52,10 +52,15 @@ export declare const HARD_CODED_TEXT: {
52
52
  };
53
53
  export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
54
54
  export declare class DynamicTextUtil {
55
+ static componentsBoundTo(componentElements: DocumentElement[], entityType: string): DocumentElement[];
55
56
  static isDynamicText(documentElement: DocumentElement): boolean;
56
57
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
57
58
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
58
- 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;
59
64
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
60
65
  private static getItemCount;
61
66
  }
@@ -63,6 +63,12 @@ function isContainerBinding(bindingProperty) {
63
63
  return DynamicTextUtil.takesValueFromContainer(bindingProperty);
64
64
  }
65
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
+ }
66
72
  static isDynamicText(documentElement) {
67
73
  var _a;
68
74
  return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
@@ -167,16 +173,19 @@ class DynamicTextUtil {
167
173
  return text;
168
174
  }
169
175
  static calculateSize(dynamicTextElement, entityType, text) {
170
- var _a, _b, _c, _d, _e;
171
- let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
172
- 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;
173
- const fontSize = (_e = (dynamicTextElement.isTextTool
174
- ? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
175
- : 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;
176
185
  const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
177
186
  const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
178
- const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
179
- 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 : '');
180
189
  const measureTextSettings = {
181
190
  fontFamily,
182
191
  fontSize: fontSizePx,
@@ -201,6 +210,9 @@ class DynamicTextUtil {
201
210
  catch (e) { }
202
211
  return size;
203
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
+ }
204
216
  static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
205
217
  let text = '';
206
218
  if (memberValues.length === 0) {
@@ -216,11 +228,16 @@ class DynamicTextUtil {
216
228
  text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
217
229
  }
218
230
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
219
- text = Array.from(new Set(memberValues
220
- .filter((e) => e !== null && e !== undefined && e !== '')
221
- .flat()
222
- .map((e) => formatter.formatValueForProperty(e, property))))
223
- .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)
224
241
  .join(', ');
225
242
  }
226
243
  else if (!displayFunction ||
@@ -232,15 +249,17 @@ class DynamicTextUtil {
232
249
  }
233
250
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
234
251
  displayFunction === DynamicTextDisplayFunction.MAX) {
235
- const present = memberValues
252
+ const isDate = (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date;
253
+ const ranked = memberValues
236
254
  .filter((e) => e !== null && e !== undefined && e !== '')
237
- .map(Number)
238
- .filter((e) => !Number.isNaN(e));
239
- if (!present.length) {
255
+ .map((value) => ({ value, rank: DynamicTextUtil.rankValue(value, property) }))
256
+ .filter(({ rank }) => !Number.isNaN(rank));
257
+ if (!ranked.length) {
240
258
  return '';
241
259
  }
242
- const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
243
- 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);
244
263
  }
245
264
  return text;
246
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.21.0-alpha.fb70961",
3
+ "version": "1.22.0-alpha.766acdd",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",