@contrail/documents 1.21.0-alpha.68c9ba7 → 1.21.0-alpha.7411393
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 -37
- package/lib/containers/container-kind.d.ts +1 -0
- package/lib/containers/container-kind.js +10 -2
- package/lib/containers/document-container-index.d.ts +0 -1
- package/lib/containers/document-container-index.js +2 -11
- package/lib/containers/document-container.d.ts +0 -4
- package/lib/containers/document-container.js +3 -12
- package/lib/containers/document-container.service.js +23 -13
- package/lib/util/dynamic-text/dynamic-text-util.js +2 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,54 +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.
|
|
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.
|
|
30
36
|
|
|
31
37
|
### Deprecated
|
|
32
38
|
|
|
33
39
|
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
34
|
-
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.
|
|
35
42
|
|
|
36
43
|
### Fixed
|
|
37
44
|
|
|
38
|
-
- A dynamic text is anchored at its drawn top-left corner rather than its centre
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
it
|
|
51
|
-
- `min` and `max` rendered an infinity sign when every member value was empty
|
|
52
|
-
|
|
53
|
-
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.
|
|
54
63
|
|
|
55
64
|
### Changed
|
|
56
65
|
|
|
57
|
-
-
|
|
58
|
-
|
|
59
|
-
is
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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.
|
|
64
77
|
|
|
65
78
|
## [1.20.0] - 2026-09-25
|
|
66
79
|
|
|
@@ -3,6 +3,7 @@ export type ContainerElementType = typeof FRAME_ELEMENT_TYPE | typeof SECTION_EL
|
|
|
3
3
|
export interface ContainerKind {
|
|
4
4
|
elementType: ContainerElementType;
|
|
5
5
|
nests: boolean;
|
|
6
|
+
canBeContentOf: readonly ContainerElementType[];
|
|
6
7
|
}
|
|
7
8
|
export declare const SECTION_KIND: ContainerKind;
|
|
8
9
|
export declare const FRAME_KIND: ContainerKind;
|
|
@@ -2,6 +2,14 @@
|
|
|
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 = {
|
|
6
|
-
|
|
5
|
+
exports.SECTION_KIND = {
|
|
6
|
+
elementType: document_element_constants_1.SECTION_ELEMENT_TYPE,
|
|
7
|
+
nests: true,
|
|
8
|
+
canBeContentOf: [document_element_constants_1.SECTION_ELEMENT_TYPE],
|
|
9
|
+
};
|
|
10
|
+
exports.FRAME_KIND = {
|
|
11
|
+
elementType: document_element_constants_1.FRAME_ELEMENT_TYPE,
|
|
12
|
+
nests: false,
|
|
13
|
+
canBeContentOf: [document_element_constants_1.SECTION_ELEMENT_TYPE],
|
|
14
|
+
};
|
|
7
15
|
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -10,7 +10,6 @@ export declare class DocumentContainerIndex {
|
|
|
10
10
|
memberIdsByContainerId: Map<string, string[]>;
|
|
11
11
|
containerIdsByElementType: Map<string, string[]>;
|
|
12
12
|
});
|
|
13
|
-
static empty(): DocumentContainerIndex;
|
|
14
13
|
getContainer(containerId: string): DocumentContainer | null;
|
|
15
14
|
containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
|
|
16
15
|
containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
|
|
@@ -6,15 +6,6 @@ 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
|
-
containersById: new Map(),
|
|
13
|
-
containerPathsByDocumentElementId: new Map(),
|
|
14
|
-
memberIdsByContainerId: new Map(),
|
|
15
|
-
containerIdsByElementType: new Map(),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
9
|
getContainer(containerId) {
|
|
19
10
|
var _a;
|
|
20
11
|
return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
|
|
@@ -23,7 +14,7 @@ class DocumentContainerIndex {
|
|
|
23
14
|
return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
|
|
24
15
|
}
|
|
25
16
|
containerIdsOf(documentElementId, elementType) {
|
|
26
|
-
return
|
|
17
|
+
return this.containerPath(documentElementId, elementType);
|
|
27
18
|
}
|
|
28
19
|
innermostContainerIdOf(documentElementId, elementType) {
|
|
29
20
|
const path = this.containerPath(documentElementId, elementType);
|
|
@@ -31,7 +22,7 @@ class DocumentContainerIndex {
|
|
|
31
22
|
}
|
|
32
23
|
memberIdsOf(containerId) {
|
|
33
24
|
var _a;
|
|
34
|
-
return
|
|
25
|
+
return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
|
|
35
26
|
}
|
|
36
27
|
memberDocumentElementsOf(containerId) {
|
|
37
28
|
const members = [];
|
|
@@ -17,10 +17,6 @@ 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;
|
|
@@ -38,23 +38,14 @@ class DocumentContainerUtil {
|
|
|
38
38
|
const after = cornerOffset(newSize);
|
|
39
39
|
return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
|
|
40
40
|
}
|
|
41
|
-
static resizeKeepingAnchor(dynamicTextElement, entityType, text) {
|
|
42
|
-
const size = dynamic_text_util_1.DynamicTextUtil.calculateSize(dynamicTextElement, entityType, text);
|
|
43
|
-
return { size, position: DocumentContainerUtil.positionKeepingAnchor(dynamicTextElement, size) };
|
|
44
|
-
}
|
|
45
41
|
static anchorFor(documentElement, position, startElement, endElement) {
|
|
46
42
|
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
47
43
|
if (!at) {
|
|
48
44
|
return null;
|
|
49
45
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
54
|
-
}
|
|
55
|
-
catch (_a) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
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);
|
|
58
49
|
}
|
|
59
50
|
static containsPoint(box, point) {
|
|
60
51
|
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
@@ -8,13 +8,7 @@ const document_container_1 = require("./document-container");
|
|
|
8
8
|
class DocumentContainerService {
|
|
9
9
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
10
10
|
var _a, _b;
|
|
11
|
-
const
|
|
12
|
-
const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
|
|
13
|
-
if (!elements.some((element) => containerElementTypes.has(element.type))) {
|
|
14
|
-
return document_container_index_1.DocumentContainerIndex.empty();
|
|
15
|
-
}
|
|
16
|
-
const documentElementsById = new Map(elements.map((element) => [element.id, element]));
|
|
17
|
-
const measuredDocumentElements = this.measureDocumentElements(elements, documentElementsById);
|
|
11
|
+
const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
|
|
18
12
|
const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
19
13
|
const containersById = new Map();
|
|
20
14
|
const containerIdsByElementType = new Map();
|
|
@@ -30,6 +24,12 @@ class DocumentContainerService {
|
|
|
30
24
|
}
|
|
31
25
|
pathsByMeasured.set(measured, byElementType);
|
|
32
26
|
}
|
|
27
|
+
const measuredById = new Map();
|
|
28
|
+
for (const measured of measuredDocumentElements) {
|
|
29
|
+
if (!measuredById.has(measured.documentElement.id)) {
|
|
30
|
+
measuredById.set(measured.documentElement.id, measured);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
33
|
const containerPathsByDocumentElementId = new Map();
|
|
34
34
|
const memberIdsByContainerId = new Map();
|
|
35
35
|
for (const measured of measuredDocumentElements) {
|
|
@@ -50,7 +50,7 @@ class DocumentContainerService {
|
|
|
50
50
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
51
51
|
}
|
|
52
52
|
return new document_container_index_1.DocumentContainerIndex({
|
|
53
|
-
documentElementsById,
|
|
53
|
+
documentElementsById: new Map([...measuredById].map(([id, measured]) => [id, measured.documentElement])),
|
|
54
54
|
containersById,
|
|
55
55
|
containerPathsByDocumentElementId,
|
|
56
56
|
memberIdsByContainerId,
|
|
@@ -60,7 +60,8 @@ class DocumentContainerService {
|
|
|
60
60
|
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
61
61
|
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
62
62
|
}
|
|
63
|
-
static measureDocumentElements(documentElements
|
|
63
|
+
static measureDocumentElements(documentElements) {
|
|
64
|
+
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
64
65
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
65
66
|
documentElement,
|
|
66
67
|
drawOrder,
|
|
@@ -69,9 +70,12 @@ class DocumentContainerService {
|
|
|
69
70
|
}
|
|
70
71
|
static measure(documentElement, documentElementsById) {
|
|
71
72
|
var _a, _b;
|
|
73
|
+
if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
72
76
|
try {
|
|
73
|
-
const start = ((_a = documentElement
|
|
74
|
-
const end = ((_b = documentElement
|
|
77
|
+
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
78
|
+
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
75
79
|
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
|
|
76
80
|
return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
|
|
77
81
|
}
|
|
@@ -94,8 +98,14 @@ class DocumentContainerService {
|
|
|
94
98
|
if (!containers.length || !measured.box) {
|
|
95
99
|
return [];
|
|
96
100
|
}
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
const ownKind = container_kind_1.CONTAINER_KINDS.find((candidate) => candidate.elementType === measured.documentElement.type);
|
|
102
|
+
if (ownKind) {
|
|
103
|
+
if (ownKind.elementType === kind.elementType) {
|
|
104
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
105
|
+
}
|
|
106
|
+
if (!ownKind.canBeContentOf.includes(kind.elementType)) {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
99
109
|
}
|
|
100
110
|
const candidates = this.candidateContainers(measured, containers);
|
|
101
111
|
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|
|
@@ -56,9 +56,8 @@ function isContainerBinding(bindingProperty) {
|
|
|
56
56
|
}
|
|
57
57
|
class DynamicTextUtil {
|
|
58
58
|
static isDynamicText(documentElement) {
|
|
59
|
-
var _a;
|
|
60
59
|
return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
|
|
61
|
-
!!
|
|
60
|
+
!!documentElement.propertyBindings &&
|
|
62
61
|
!!documentElement.propertyBindingsMetaData);
|
|
63
62
|
}
|
|
64
63
|
static takesValueFromContainer(bindingProperty) {
|
|
@@ -209,7 +208,7 @@ class DynamicTextUtil {
|
|
|
209
208
|
}
|
|
210
209
|
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
211
210
|
text = Array.from(new Set(memberValues
|
|
212
|
-
.filter((e) => e !== null && e !== undefined
|
|
211
|
+
.filter((e) => e !== null && e !== undefined)
|
|
213
212
|
.flat()
|
|
214
213
|
.map((e) => formatter.formatValueForProperty(e, property))))
|
|
215
214
|
.sort()
|