@contrail/documents 1.21.0-alpha.fb70961 → 1.22.0-alpha.cf41460
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 +36 -0
- package/lib/containers/document-container-index.d.ts +5 -4
- package/lib/containers/document-container-index.js +11 -6
- package/lib/containers/document-container.d.ts +4 -0
- package/lib/containers/document-container.js +56 -2
- package/lib/containers/document-container.service.d.ts +0 -4
- package/lib/containers/document-container.service.js +7 -50
- package/lib/types/document-change.d.ts +1 -0
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +6 -1
- package/lib/util/dynamic-text/dynamic-text-util.js +38 -19
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ 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-07
|
|
9
|
+
|
|
10
|
+
Maintenance release on the 1.x line; the same change ships on 2.x as 2.5.0.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `DocumentChange.keepSortIndex`: set on an add to keep the sortIndex its element carries when no
|
|
15
|
+
element holds it, instead of appending it on top.
|
|
16
|
+
|
|
8
17
|
## [1.21.0] - 2026-09-26
|
|
9
18
|
|
|
10
19
|
Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
|
|
@@ -28,6 +37,18 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
|
|
|
28
37
|
member into a different cell. Anything deciding what an element overlaps or sits on wants the
|
|
29
38
|
scaled one.
|
|
30
39
|
|
|
40
|
+
### Removed
|
|
41
|
+
|
|
42
|
+
- `DocumentContainerIndex.containerPathAtPoint`. It applied the anchor rule alone, because a bare
|
|
43
|
+
point has nothing to compare against a container, and returned the same shape as `containerIdsOf`,
|
|
44
|
+
so it read as a second way to ask one question. `containerPathFor(element, kind)` replaces it and
|
|
45
|
+
applies every rule. Callers that hold a position pass the element with that position on it. This
|
|
46
|
+
is the one removal a consumer has to act on.
|
|
47
|
+
- `ContainerKind.layer`, `DocumentContainer.name` and `DocumentContainer.depth`, and
|
|
48
|
+
`DocumentContainerIndex.maxDepth`. The container API has not shipped in a released version, so
|
|
49
|
+
nothing outside this repository can be holding them. Read a container's name from
|
|
50
|
+
`documentElement.name`.
|
|
51
|
+
|
|
31
52
|
### Deprecated
|
|
32
53
|
|
|
33
54
|
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
@@ -52,6 +73,12 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
|
|
|
52
73
|
`n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
|
|
53
74
|
the server failed the read for the whole document.
|
|
54
75
|
|
|
76
|
+
- `min` and `max` over a date property rendered nothing at all. `Number` of a date string is `NaN`,
|
|
77
|
+
so every member was dropped; they now order by the instant each date names.
|
|
78
|
+
- `uniqueArray` sorted the rendered text rather than the value, so `11/20/2026` came after
|
|
79
|
+
`01/15/2027` and `100` before `9`. It now orders by value, falling back to text order for values
|
|
80
|
+
that are neither a date nor a number.
|
|
81
|
+
|
|
55
82
|
### Changed
|
|
56
83
|
|
|
57
84
|
- `anchorFor` and the index measure through the same factory call, so a caller holding an element
|
|
@@ -61,6 +88,15 @@ Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
|
|
|
61
88
|
two containers that merely cross no longer both claim it.
|
|
62
89
|
- `buildIndex` scans element types before measuring, so a document with no containers of the kinds
|
|
63
90
|
asked for returns an empty index without a geometry pass.
|
|
91
|
+
- **A section nests inside another only when it is drawn above it.** A section drawn over one it
|
|
92
|
+
encloses hides it, so the hidden section holds nothing and a `section.count` on it reads zero.
|
|
93
|
+
This changes existing boards wherever the outer section was drawn last.
|
|
94
|
+
- `containerIdsOf` and `memberIdsOf` return copies. `readonly` is erased at runtime, and a caller
|
|
95
|
+
sorting what it got back reordered the index's own list for every later read.
|
|
96
|
+
- A member list is a set of ids, so two elements sharing an id count once.
|
|
97
|
+
- `min` and `max` no longer read an empty member as zero, and `uniqueArray` no longer emits one as
|
|
98
|
+
a blank entry. A text box narrower than its own padding measures without a fixed width.
|
|
99
|
+
- A nullish entry in the element list is dropped rather than throwing.
|
|
64
100
|
|
|
65
101
|
## [1.20.0] - 2026-09-25
|
|
66
102
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { DocumentElement
|
|
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
|
-
|
|
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
|
-
|
|
47
|
+
containerPathFor(documentElement, kind) {
|
|
47
48
|
var _a, _b;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
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
|
|
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
|
-
|
|
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,
|
|
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:
|
|
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;
|
|
@@ -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):
|
|
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 =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
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
|
|
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(
|
|
238
|
-
.filter((
|
|
239
|
-
if (!
|
|
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
|
|
243
|
-
|
|
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
|
}
|