@contrail/documents 1.21.0-alpha.a727550 → 1.21.0-alpha.adaec42
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 +50 -58
- package/lib/containers/document-container-index.d.ts +4 -5
- package/lib/containers/document-container-index.js +8 -13
- package/lib/containers/document-container.d.ts +0 -8
- package/lib/containers/document-container.js +6 -66
- package/lib/containers/document-container.service.d.ts +4 -0
- package/lib/containers/document-container.service.js +60 -17
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +1 -6
- package/lib/util/dynamic-text/dynamic-text-util.js +13 -25
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,75 +13,67 @@ 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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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.
|
|
25
31
|
- `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
|
|
26
|
-
with `scale` applied. `getBoundingClientRect`
|
|
27
|
-
works in: `@contrail/document-table` places table members from it, and
|
|
28
|
-
member into a different cell. Anything deciding what an element overlaps
|
|
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`.
|
|
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.
|
|
42
36
|
|
|
43
37
|
### Deprecated
|
|
44
38
|
|
|
45
39
|
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
46
|
-
for what it decides
|
|
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.
|
|
47
42
|
|
|
48
43
|
### Fixed
|
|
49
44
|
|
|
50
|
-
- A dynamic text is anchored at its drawn top-left corner rather than its centre
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
it
|
|
63
|
-
- `min` and `max` rendered an infinity sign when every member value was empty
|
|
64
|
-
|
|
65
|
-
the
|
|
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.
|
|
66
63
|
|
|
67
64
|
### Changed
|
|
68
65
|
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
is
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
sorting what it got back reordered the index's own list for every later read.
|
|
81
|
-
- A member list is a set of ids, so two elements sharing an id count once.
|
|
82
|
-
- `min` and `max` no longer read an empty member as zero, and `uniqueArray` no longer emits one as
|
|
83
|
-
a blank entry. A text box narrower than its own padding measures without a fixed width.
|
|
84
|
-
- A nullish entry in the element list is dropped rather than throwing.
|
|
66
|
+
- Container membership measures a scaled element from its scaled box, through the new
|
|
67
|
+
`getBoundingClientRectScaled` above. Only a sticky note, a regular iframe, a text-tool text or a
|
|
68
|
+
table carries `scale` at all; for this work the one that matters is a text-tool dynamic text,
|
|
69
|
+
which previously measured at its unscaled size and could resolve to the wrong container.
|
|
70
|
+
- `DocumentContainerUtil.anchorFor` measures through the same factory call the index uses, so a
|
|
71
|
+
caller holding an element gets the answer the index would give it. Reading `size` directly
|
|
72
|
+
disagreed for the types whose box is not position plus size: a component's box is built from the
|
|
73
|
+
rows it draws, and a line's comes from its `lineDefinition`.
|
|
74
|
+
- Container depth counts nesting levels rather than enclosing boxes. Two containers that merely
|
|
75
|
+
cross both enclose anything inside the overlap, so counting ancestors put that inner container a
|
|
76
|
+
level too deep and made `maxDepth` report a level no path could reach.
|
|
85
77
|
|
|
86
78
|
## [1.20.0] - 2026-09-25
|
|
87
79
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { DocumentElement } from '../types';
|
|
2
|
-
import { ContainerElementType
|
|
3
|
-
import { DocumentContainer
|
|
1
|
+
import { DocumentElement, PositionDefinition } from '../types';
|
|
2
|
+
import { ContainerElementType } from './container-kind';
|
|
3
|
+
import { DocumentContainer } 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>;
|
|
9
8
|
containersById: Map<string, DocumentContainer>;
|
|
10
9
|
containerPathsByDocumentElementId: Map<string, Map<string, string[]>>;
|
|
11
10
|
memberIdsByContainerId: Map<string, string[]>;
|
|
@@ -18,7 +17,7 @@ export declare class DocumentContainerIndex {
|
|
|
18
17
|
innermostContainerIdOf(documentElementId: string, elementType: ContainerElementType): string | null;
|
|
19
18
|
memberIdsOf(containerId: string): readonly string[];
|
|
20
19
|
memberDocumentElementsOf(containerId: string): DocumentElement[];
|
|
21
|
-
|
|
20
|
+
containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
|
|
22
21
|
private containersOfType;
|
|
23
22
|
private resolveAll;
|
|
24
23
|
private containerPath;
|
|
@@ -9,7 +9,6 @@ class DocumentContainerIndex {
|
|
|
9
9
|
static empty() {
|
|
10
10
|
return new DocumentContainerIndex({
|
|
11
11
|
documentElementsById: new Map(),
|
|
12
|
-
measuredById: new Map(),
|
|
13
12
|
containersById: new Map(),
|
|
14
13
|
containerPathsByDocumentElementId: new Map(),
|
|
15
14
|
memberIdsByContainerId: new Map(),
|
|
@@ -24,7 +23,7 @@ class DocumentContainerIndex {
|
|
|
24
23
|
return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
|
|
25
24
|
}
|
|
26
25
|
containerIdsOf(documentElementId, elementType) {
|
|
27
|
-
return
|
|
26
|
+
return this.containerPath(documentElementId, elementType);
|
|
28
27
|
}
|
|
29
28
|
innermostContainerIdOf(documentElementId, elementType) {
|
|
30
29
|
const path = this.containerPath(documentElementId, elementType);
|
|
@@ -32,7 +31,7 @@ class DocumentContainerIndex {
|
|
|
32
31
|
}
|
|
33
32
|
memberIdsOf(containerId) {
|
|
34
33
|
var _a;
|
|
35
|
-
return
|
|
34
|
+
return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
|
|
36
35
|
}
|
|
37
36
|
memberDocumentElementsOf(containerId) {
|
|
38
37
|
const members = [];
|
|
@@ -44,17 +43,13 @@ class DocumentContainerIndex {
|
|
|
44
43
|
}
|
|
45
44
|
return members;
|
|
46
45
|
}
|
|
47
|
-
|
|
46
|
+
containerPathAtPoint(point, elementType) {
|
|
48
47
|
var _a, _b;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
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);
|
|
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);
|
|
58
53
|
}
|
|
59
54
|
containersOfType(elementType) {
|
|
60
55
|
var _a;
|
|
@@ -17,17 +17,9 @@ export declare class DocumentContainerUtil {
|
|
|
17
17
|
static centerOf(box: CoordinateBox): PositionDefinition;
|
|
18
18
|
static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
19
19
|
static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
|
|
20
|
-
static resizeKeepingAnchor(dynamicTextElement: DocumentElement, entityType: any, text: string): {
|
|
21
|
-
size: SizeDefinition;
|
|
22
|
-
position: PositionDefinition;
|
|
23
|
-
};
|
|
24
20
|
static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
|
|
25
21
|
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
26
22
|
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
27
23
|
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
24
|
static topmost(containers: DocumentContainer[]): DocumentContainer[];
|
|
33
25
|
}
|
|
@@ -24,12 +24,9 @@ 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 || !angle || !newSize || !documentElement.size) {
|
|
28
28
|
return position;
|
|
29
29
|
}
|
|
30
|
-
if (!angle || !newSize || !documentElement.size) {
|
|
31
|
-
return Object.assign({}, position);
|
|
32
|
-
}
|
|
33
30
|
const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
|
|
34
31
|
const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
|
|
35
32
|
const cornerOffset = (size) => {
|
|
@@ -39,23 +36,16 @@ class DocumentContainerUtil {
|
|
|
39
36
|
};
|
|
40
37
|
const before = cornerOffset(documentElement.size);
|
|
41
38
|
const after = cornerOffset(newSize);
|
|
42
|
-
|
|
43
|
-
return Number.isFinite(moved.x) && Number.isFinite(moved.y) ? moved : Object.assign({}, position);
|
|
44
|
-
}
|
|
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) };
|
|
39
|
+
return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
|
|
48
40
|
}
|
|
49
41
|
static anchorFor(documentElement, position, startElement, endElement) {
|
|
50
42
|
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
51
|
-
|
|
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) {
|
|
43
|
+
if (!at) {
|
|
57
44
|
return null;
|
|
58
45
|
}
|
|
46
|
+
const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
|
|
47
|
+
const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
|
|
48
|
+
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
59
49
|
}
|
|
60
50
|
static containsPoint(box, point) {
|
|
61
51
|
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
@@ -83,56 +73,6 @@ class DocumentContainerUtil {
|
|
|
83
73
|
path.unshift(topmostOf(enclosing));
|
|
84
74
|
}
|
|
85
75
|
}
|
|
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
|
-
}
|
|
136
76
|
static topmost(containers) {
|
|
137
77
|
return containers.length
|
|
138
78
|
? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
|
|
@@ -5,5 +5,9 @@ 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;
|
|
8
9
|
private static collectContainers;
|
|
10
|
+
private static resolvePath;
|
|
11
|
+
private static enclosersOf;
|
|
12
|
+
private static candidateContainers;
|
|
9
13
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
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");
|
|
4
5
|
const container_kind_1 = require("./container-kind");
|
|
5
6
|
const document_container_index_1 = require("./document-container-index");
|
|
6
7
|
const document_container_1 = require("./document-container");
|
|
7
8
|
class DocumentContainerService {
|
|
8
9
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
9
10
|
var _a, _b;
|
|
10
|
-
const elements =
|
|
11
|
+
const elements = documentElements !== null && documentElements !== void 0 ? documentElements : [];
|
|
11
12
|
const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
|
|
12
|
-
if (!elements.some((element) => containerElementTypes.has(element.type))) {
|
|
13
|
+
if (!elements.some((element) => containerElementTypes.has(element === null || element === void 0 ? void 0 : element.type))) {
|
|
13
14
|
return document_container_index_1.DocumentContainerIndex.empty();
|
|
14
15
|
}
|
|
15
16
|
const documentElementsById = new Map(elements.map((element) => [element.id, element]));
|
|
@@ -25,39 +26,31 @@ class DocumentContainerService {
|
|
|
25
26
|
for (const measured of measuredDocumentElements) {
|
|
26
27
|
const byElementType = new Map();
|
|
27
28
|
for (const kind of kinds) {
|
|
28
|
-
byElementType.set(kind.elementType,
|
|
29
|
+
byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
|
|
29
30
|
}
|
|
30
31
|
pathsByMeasured.set(measured, byElementType);
|
|
31
32
|
}
|
|
32
33
|
const containerPathsByDocumentElementId = new Map();
|
|
33
34
|
const memberIdsByContainerId = new Map();
|
|
34
|
-
const memberIdsSeen = new Map();
|
|
35
35
|
for (const measured of measuredDocumentElements) {
|
|
36
36
|
const documentElementId = measured.documentElement.id;
|
|
37
37
|
const pathsByElementType = new Map();
|
|
38
38
|
((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
|
|
39
39
|
for (const path of pathsByElementType.values()) {
|
|
40
40
|
for (const containerId of path) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
memberIdsByContainerId.set(containerId, [documentElementId]);
|
|
41
|
+
const members = memberIdsByContainerId.get(containerId);
|
|
42
|
+
if (members) {
|
|
43
|
+
members.push(documentElementId);
|
|
45
44
|
}
|
|
46
|
-
else
|
|
47
|
-
|
|
48
|
-
memberIdsByContainerId.get(containerId).push(documentElementId);
|
|
45
|
+
else {
|
|
46
|
+
memberIdsByContainerId.set(containerId, [documentElementId]);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
50
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
53
51
|
}
|
|
54
|
-
const measuredById = new Map();
|
|
55
|
-
for (const measured of measuredDocumentElements) {
|
|
56
|
-
measuredById.set(measured.documentElement.id, measured);
|
|
57
|
-
}
|
|
58
52
|
return new document_container_index_1.DocumentContainerIndex({
|
|
59
53
|
documentElementsById,
|
|
60
|
-
measuredById,
|
|
61
54
|
containersById,
|
|
62
55
|
containerPathsByDocumentElementId,
|
|
63
56
|
memberIdsByContainerId,
|
|
@@ -71,9 +64,24 @@ class DocumentContainerService {
|
|
|
71
64
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
72
65
|
documentElement,
|
|
73
66
|
drawOrder,
|
|
74
|
-
box:
|
|
67
|
+
box: this.measure(documentElement, documentElementsById),
|
|
75
68
|
}));
|
|
76
69
|
}
|
|
70
|
+
static measure(documentElement, documentElementsById) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
77
|
+
const end = ((_b = 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
|
+
}
|
|
77
85
|
static collectContainers(measuredDocumentElements, kind) {
|
|
78
86
|
return measuredDocumentElements
|
|
79
87
|
.filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
|
|
@@ -85,5 +93,40 @@ class DocumentContainerService {
|
|
|
85
93
|
drawOrder: measured.drawOrder,
|
|
86
94
|
}));
|
|
87
95
|
}
|
|
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.documentElement !== measured.documentElement &&
|
|
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.documentElement === measured.documentElement || 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
|
+
}
|
|
88
131
|
}
|
|
89
132
|
exports.DocumentContainerService = DocumentContainerService;
|
|
@@ -27,8 +27,6 @@ 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;
|
|
32
30
|
export declare const HARD_CODED_TEXT: {
|
|
33
31
|
'project.name': string;
|
|
34
32
|
'project.createdBy.email': string;
|
|
@@ -55,10 +53,7 @@ export declare class DynamicTextUtil {
|
|
|
55
53
|
static isDynamicText(documentElement: DocumentElement): boolean;
|
|
56
54
|
static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
|
|
57
55
|
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
|
-
width: number;
|
|
60
|
-
height: number;
|
|
61
|
-
};
|
|
56
|
+
static calculateSize(dynamicTextElement: DocumentElement, entityType: any, text: string): import("../..").SizeDefinition;
|
|
62
57
|
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
63
58
|
private static getItemCount;
|
|
64
59
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
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
4
|
exports.isContainerBinding = isContainerBinding;
|
|
7
5
|
const types_1 = require("@contrail/types");
|
|
8
6
|
const util_1 = require("@contrail/util");
|
|
@@ -30,12 +28,6 @@ var DynamicTextDisplayFunction;
|
|
|
30
28
|
exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
|
|
31
29
|
exports.MOVE_TO_SECTION_TEXT = 'Move to a section';
|
|
32
30
|
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
|
-
}
|
|
39
31
|
exports.HARD_CODED_TEXT = {
|
|
40
32
|
'project.name': 'Project name',
|
|
41
33
|
'project.createdBy.email': 'Project created by',
|
|
@@ -64,9 +56,8 @@ function isContainerBinding(bindingProperty) {
|
|
|
64
56
|
}
|
|
65
57
|
class DynamicTextUtil {
|
|
66
58
|
static isDynamicText(documentElement) {
|
|
67
|
-
var _a;
|
|
68
59
|
return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
|
|
69
|
-
!!
|
|
60
|
+
!!documentElement.propertyBindings &&
|
|
70
61
|
!!documentElement.propertyBindingsMetaData);
|
|
71
62
|
}
|
|
72
63
|
static takesValueFromContainer(bindingProperty) {
|
|
@@ -106,7 +97,7 @@ class DynamicTextUtil {
|
|
|
106
97
|
}
|
|
107
98
|
else {
|
|
108
99
|
if (!container && !isSpecRelated) {
|
|
109
|
-
text =
|
|
100
|
+
text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
|
|
110
101
|
}
|
|
111
102
|
else {
|
|
112
103
|
if (CONTAINER_SOURCES.includes(entityType)) {
|
|
@@ -149,7 +140,7 @@ class DynamicTextUtil {
|
|
|
149
140
|
text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
|
|
150
141
|
}
|
|
151
142
|
else if (!container) {
|
|
152
|
-
text =
|
|
143
|
+
text = exports.MOVE_TO_FRAME_TEXT;
|
|
153
144
|
}
|
|
154
145
|
else {
|
|
155
146
|
text = property === null || property === void 0 ? void 0 : property.label;
|
|
@@ -159,7 +150,7 @@ class DynamicTextUtil {
|
|
|
159
150
|
text = 'n/a';
|
|
160
151
|
}
|
|
161
152
|
if (displayLabel &&
|
|
162
|
-
!
|
|
153
|
+
![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
|
|
163
154
|
displayFunction !== DynamicTextDisplayFunction.LABEL &&
|
|
164
155
|
text !== bindingProperty) {
|
|
165
156
|
text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
|
|
@@ -167,19 +158,16 @@ class DynamicTextUtil {
|
|
|
167
158
|
return text;
|
|
168
159
|
}
|
|
169
160
|
static calculateSize(dynamicTextElement, entityType, text) {
|
|
170
|
-
var _a, _b, _c, _d, _e
|
|
171
|
-
let size = {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const fontSize = (_j = (dynamicTextElement.isTextTool
|
|
177
|
-
? (_h = (_g = dynamicTextElement.style) === null || _g === void 0 ? void 0 : _g.font) === null || _h === void 0 ? void 0 : _h.size
|
|
178
|
-
: 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;
|
|
161
|
+
var _a, _b, _c, _d, _e;
|
|
162
|
+
let size = (_a = dynamicTextElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
|
|
163
|
+
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;
|
|
164
|
+
const fontSize = (_e = (dynamicTextElement.isTextTool
|
|
165
|
+
? (_d = (_c = dynamicTextElement.style) === null || _c === void 0 ? void 0 : _c.font) === null || _d === void 0 ? void 0 : _d.size
|
|
166
|
+
: 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;
|
|
179
167
|
const fontSizePx = document_util_1.DocumentStyleUtil.toPx(fontSize, 4);
|
|
180
168
|
const padding = dynamicTextElement.isTextTool ? document_util_1.TEXT_TOOL_PADDING : document_util_1.TEXT_BOX_PADDING;
|
|
181
|
-
const bold = document_util_1.DocumentStyleUtil.isBold(
|
|
182
|
-
const italic = document_util_1.DocumentStyleUtil.isItalic(
|
|
169
|
+
const bold = document_util_1.DocumentStyleUtil.isBold(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text, fontFamily);
|
|
170
|
+
const italic = document_util_1.DocumentStyleUtil.isItalic(dynamicTextElement === null || dynamicTextElement === void 0 ? void 0 : dynamicTextElement.text);
|
|
183
171
|
const measureTextSettings = {
|
|
184
172
|
fontFamily,
|
|
185
173
|
fontSize: fontSizePx,
|
|
@@ -220,7 +208,7 @@ class DynamicTextUtil {
|
|
|
220
208
|
}
|
|
221
209
|
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
222
210
|
text = Array.from(new Set(memberValues
|
|
223
|
-
.filter((e) => e !== null && e !== undefined
|
|
211
|
+
.filter((e) => e !== null && e !== undefined)
|
|
224
212
|
.flat()
|
|
225
213
|
.map((e) => formatter.formatValueForProperty(e, property))))
|
|
226
214
|
.sort()
|