@contrail/documents 1.21.0-alpha.55b073f → 1.21.0-alpha.68c9ba7
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 +37 -42
- package/lib/containers/container-kind.d.ts +0 -1
- package/lib/containers/container-kind.js +2 -2
- package/lib/containers/document-container-index.d.ts +1 -1
- package/lib/containers/document-container-index.js +17 -7
- package/lib/containers/document-container.d.ts +7 -5
- package/lib/containers/document-container.js +31 -15
- package/lib/containers/document-container.service.d.ts +3 -4
- package/lib/containers/document-container.service.js +44 -62
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +1 -0
- package/lib/util/dynamic-text/dynamic-text-util.js +14 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -13,59 +13,54 @@ 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
|
-
|
|
25
|
-
holding an element rather than a measured box.
|
|
26
|
-
- `positionKeepingAnchor` — where an element has to sit for its drawn corner to land where it did
|
|
27
|
-
before a resize. Rotation turns about the centre and the centre moves with the size, so a rotated
|
|
28
|
-
element resized about its stored position drags its corner along with it. The board already makes
|
|
29
|
-
this move; a server recomputing a dynamic text has to make the same one, or the corner is not the
|
|
30
|
-
fixed point the anchor rule needs.
|
|
16
|
+
section; membership is geometry, draw order and kind, with nothing inherited and nothing stored.
|
|
17
|
+
The rule is written out in `src/containers/DOCUMENT_CONTAINERS_SPEC.md`, which the code is
|
|
18
|
+
measured against.
|
|
19
|
+
- `DocumentContainerUtil` — the container geometry as statics. `anchorFor` answers "which point is
|
|
20
|
+
this element placed by" for a caller holding an element rather than a measured box, and
|
|
21
|
+
`resizeKeepingAnchor` returns the size a new value needs with the position that keeps that point
|
|
22
|
+
still. Applying one without the other drags the corner membership reads.
|
|
23
|
+
- `SECTION_ELEMENT_TYPE` and `FRAME_ELEMENT_TYPE` in `document-element-constants`, alongside
|
|
24
|
+
`SHAPE_ELEMENT_TYPES`, which moved here for the board's shape handling.
|
|
31
25
|
- `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
|
|
32
|
-
with `scale` applied. `getBoundingClientRect`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
with `scale` applied. `getBoundingClientRect` still returns the unscaled box, which is what layout
|
|
27
|
+
works in: `@contrail/document-table` places table members from it, and scaling it moves a scaled
|
|
28
|
+
member into a different cell. Anything deciding what an element overlaps or sits on wants the
|
|
29
|
+
scaled one.
|
|
36
30
|
|
|
37
31
|
### Deprecated
|
|
38
32
|
|
|
39
33
|
- `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
|
|
40
|
-
for what it decides
|
|
41
|
-
property. The old name still works and delegates to the new one.
|
|
34
|
+
for what it decides. The old name still works and delegates to the new one.
|
|
42
35
|
|
|
43
36
|
### Fixed
|
|
44
37
|
|
|
45
|
-
- A dynamic text is
|
|
46
|
-
|
|
47
|
-
size
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- `min` and `max` rendered an infinity sign when every member value was empty
|
|
59
|
-
|
|
60
|
-
|
|
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.
|
|
38
|
+
- A dynamic text is anchored at its drawn top-left corner rather than its centre. Its size comes
|
|
39
|
+
from the value it resolves to and that value comes from its container, so an anchor that moved
|
|
40
|
+
with the size let the two choose each other: near an edge they never settled, flipping between a
|
|
41
|
+
value and "Move to a frame" on every read. The corner is the rotated one, so a text turned on its
|
|
42
|
+
side anchors where it appears (VIBE-9567).
|
|
43
|
+
- `isDynamicText` requires a `propertyBindings.text` binding, the one the value is read from. The
|
|
44
|
+
text tool creates an element with empty bindings and empty metadata, both truthy, so an
|
|
45
|
+
unconfigured text was anchored at its corner while the canvas centred it.
|
|
46
|
+
- An element covering a container is not inside it, whatever its type. The rule it replaces looked
|
|
47
|
+
only at shapes wider and taller than the container, so a background image joined the frame it
|
|
48
|
+
covered.
|
|
49
|
+
- A line or callout is measured from the elements it connects even with no stored `position`, where
|
|
50
|
+
it was previously left out of the index entirely.
|
|
51
|
+
- `min` and `max` rendered an infinity sign when every member value was empty; both fall through to
|
|
52
|
+
`n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
|
|
53
|
+
the server failed the read for the whole document.
|
|
63
54
|
|
|
64
55
|
### Changed
|
|
65
56
|
|
|
66
|
-
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
- `anchorFor` and the index measure through the same factory call, so a caller holding an element
|
|
58
|
+
gets the answer the index would give it. Reading `size` directly disagreed for the types whose box
|
|
59
|
+
is not position plus size.
|
|
60
|
+
- A container path is a containment chain, walked outward from the container the element sits on, so
|
|
61
|
+
two containers that merely cross no longer both claim it.
|
|
62
|
+
- `buildIndex` scans element types before measuring, so a document with no containers of the kinds
|
|
63
|
+
asked for returns an empty index without a geometry pass.
|
|
69
64
|
|
|
70
65
|
## [1.20.0] - 2026-09-25
|
|
71
66
|
|
|
@@ -3,7 +3,6 @@ export type ContainerElementType = typeof FRAME_ELEMENT_TYPE | typeof SECTION_EL
|
|
|
3
3
|
export interface ContainerKind {
|
|
4
4
|
elementType: ContainerElementType;
|
|
5
5
|
nests: boolean;
|
|
6
|
-
layer: number;
|
|
7
6
|
}
|
|
8
7
|
export declare const SECTION_KIND: ContainerKind;
|
|
9
8
|
export declare const FRAME_KIND: ContainerKind;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CONTAINER_KINDS = exports.FRAME_KIND = exports.SECTION_KIND = void 0;
|
|
4
4
|
const document_element_constants_1 = require("../document-element-constants");
|
|
5
|
-
exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true
|
|
6
|
-
exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false
|
|
5
|
+
exports.SECTION_KIND = { elementType: document_element_constants_1.SECTION_ELEMENT_TYPE, nests: true };
|
|
6
|
+
exports.FRAME_KIND = { elementType: document_element_constants_1.FRAME_ELEMENT_TYPE, nests: false };
|
|
7
7
|
exports.CONTAINER_KINDS = [exports.SECTION_KIND, exports.FRAME_KIND];
|
|
@@ -10,6 +10,7 @@ export declare class DocumentContainerIndex {
|
|
|
10
10
|
memberIdsByContainerId: Map<string, string[]>;
|
|
11
11
|
containerIdsByElementType: Map<string, string[]>;
|
|
12
12
|
});
|
|
13
|
+
static empty(): DocumentContainerIndex;
|
|
13
14
|
getContainer(containerId: string): DocumentContainer | null;
|
|
14
15
|
containersOf(documentElementId: string, elementType: ContainerElementType): DocumentContainer[];
|
|
15
16
|
containerIdsOf(documentElementId: string, elementType: ContainerElementType): readonly string[];
|
|
@@ -17,7 +18,6 @@ export declare class DocumentContainerIndex {
|
|
|
17
18
|
memberIdsOf(containerId: string): readonly string[];
|
|
18
19
|
memberDocumentElementsOf(containerId: string): DocumentElement[];
|
|
19
20
|
containerPathAtPoint(point: PositionDefinition, elementType: ContainerElementType): readonly string[];
|
|
20
|
-
maxDepth(elementType: ContainerElementType): number;
|
|
21
21
|
private containersOfType;
|
|
22
22
|
private resolveAll;
|
|
23
23
|
private containerPath;
|
|
@@ -6,6 +6,15 @@ 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
|
+
}
|
|
9
18
|
getContainer(containerId) {
|
|
10
19
|
var _a;
|
|
11
20
|
return (_a = this.data.containersById.get(containerId)) !== null && _a !== void 0 ? _a : null;
|
|
@@ -14,7 +23,7 @@ class DocumentContainerIndex {
|
|
|
14
23
|
return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
|
|
15
24
|
}
|
|
16
25
|
containerIdsOf(documentElementId, elementType) {
|
|
17
|
-
return this.containerPath(documentElementId, elementType);
|
|
26
|
+
return [...this.containerPath(documentElementId, elementType)];
|
|
18
27
|
}
|
|
19
28
|
innermostContainerIdOf(documentElementId, elementType) {
|
|
20
29
|
const path = this.containerPath(documentElementId, elementType);
|
|
@@ -22,7 +31,7 @@ class DocumentContainerIndex {
|
|
|
22
31
|
}
|
|
23
32
|
memberIdsOf(containerId) {
|
|
24
33
|
var _a;
|
|
25
|
-
return (_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [];
|
|
34
|
+
return [...((_a = this.data.memberIdsByContainerId.get(containerId)) !== null && _a !== void 0 ? _a : [])];
|
|
26
35
|
}
|
|
27
36
|
memberDocumentElementsOf(containerId) {
|
|
28
37
|
const members = [];
|
|
@@ -35,11 +44,12 @@ class DocumentContainerIndex {
|
|
|
35
44
|
return members;
|
|
36
45
|
}
|
|
37
46
|
containerPathAtPoint(point, elementType) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
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);
|
|
43
53
|
}
|
|
44
54
|
containersOfType(elementType) {
|
|
45
55
|
var _a;
|
|
@@ -3,10 +3,8 @@ import { ContainerKind } from './container-kind';
|
|
|
3
3
|
export interface DocumentContainer {
|
|
4
4
|
id: string;
|
|
5
5
|
kind: ContainerKind;
|
|
6
|
-
name: string;
|
|
7
6
|
documentElement: DocumentElement;
|
|
8
7
|
box: CoordinateBox;
|
|
9
|
-
depth: number;
|
|
10
8
|
drawOrder: number;
|
|
11
9
|
}
|
|
12
10
|
export interface MeasuredDocumentElement {
|
|
@@ -19,9 +17,13 @@ export declare class DocumentContainerUtil {
|
|
|
19
17
|
static centerOf(box: CoordinateBox): PositionDefinition;
|
|
20
18
|
static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
21
19
|
static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
|
|
22
|
-
static
|
|
20
|
+
static resizeKeepingAnchor(dynamicTextElement: DocumentElement, entityType: any, text: string): {
|
|
21
|
+
size: SizeDefinition;
|
|
22
|
+
position: PositionDefinition;
|
|
23
|
+
};
|
|
24
|
+
static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
|
|
23
25
|
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
24
26
|
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
25
|
-
static
|
|
26
|
-
static
|
|
27
|
+
static chain(candidates: DocumentContainer[]): DocumentContainer[];
|
|
28
|
+
static topmost(containers: DocumentContainer[]): DocumentContainer[];
|
|
27
29
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DocumentContainerUtil = void 0;
|
|
4
4
|
const rotation_math_1 = require("../util/mask/rotation-math");
|
|
5
5
|
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
6
|
+
const document_element_factory_1 = require("../document-element-factory");
|
|
6
7
|
class DocumentContainerUtil {
|
|
7
8
|
static toCoordinateBox(x, y, width, height) {
|
|
8
9
|
return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
|
|
@@ -37,15 +38,23 @@ class DocumentContainerUtil {
|
|
|
37
38
|
const after = cornerOffset(newSize);
|
|
38
39
|
return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
|
|
39
40
|
}
|
|
40
|
-
static
|
|
41
|
-
|
|
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
|
+
static anchorFor(documentElement, position, startElement, endElement) {
|
|
42
46
|
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
43
47
|
if (!at) {
|
|
44
48
|
return null;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
try {
|
|
51
|
+
const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
|
|
52
|
+
const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
|
|
53
|
+
return DocumentContainerUtil.anchorOf(documentElement, box);
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
static containsPoint(box, point) {
|
|
51
60
|
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
@@ -58,18 +67,25 @@ class DocumentContainerUtil {
|
|
|
58
67
|
outer.bottom === inner.bottom;
|
|
59
68
|
return covers && !identical;
|
|
60
69
|
}
|
|
61
|
-
static
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
static chain(candidates) {
|
|
71
|
+
if (!candidates.length) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const topmostOf = (of) => of.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
75
|
+
const path = [topmostOf(candidates)];
|
|
76
|
+
for (;;) {
|
|
77
|
+
const current = path[0];
|
|
78
|
+
const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
|
|
79
|
+
if (!enclosing.length) {
|
|
80
|
+
return path;
|
|
70
81
|
}
|
|
82
|
+
path.unshift(topmostOf(enclosing));
|
|
71
83
|
}
|
|
72
|
-
|
|
84
|
+
}
|
|
85
|
+
static topmost(containers) {
|
|
86
|
+
return containers.length
|
|
87
|
+
? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
|
|
88
|
+
: [];
|
|
73
89
|
}
|
|
74
90
|
}
|
|
75
91
|
exports.DocumentContainerUtil = DocumentContainerUtil;
|
|
@@ -6,9 +6,8 @@ export declare class DocumentContainerService {
|
|
|
6
6
|
static isContainer(documentElement: DocumentElement, kinds?: ContainerKind[]): boolean;
|
|
7
7
|
private static measureDocumentElements;
|
|
8
8
|
private static measure;
|
|
9
|
-
private static
|
|
10
|
-
private static
|
|
11
|
-
private static
|
|
12
|
-
private static toContainerPath;
|
|
9
|
+
private static collectContainers;
|
|
10
|
+
private static resolvePath;
|
|
11
|
+
private static enclosersOf;
|
|
13
12
|
private static candidateContainers;
|
|
14
13
|
}
|
|
@@ -2,29 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentContainerService = void 0;
|
|
4
4
|
const document_element_factory_1 = require("../document-element-factory");
|
|
5
|
-
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
6
|
-
const document_element_constants_1 = require("../document-element-constants");
|
|
7
5
|
const container_kind_1 = require("./container-kind");
|
|
8
6
|
const document_container_index_1 = require("./document-container-index");
|
|
9
7
|
const document_container_1 = require("./document-container");
|
|
10
8
|
class DocumentContainerService {
|
|
11
9
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
12
|
-
|
|
13
|
-
const
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
|
|
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);
|
|
18
|
+
const containersByElementType = new Map(kinds.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
14
19
|
const containersById = new Map();
|
|
15
20
|
const containerIdsByElementType = new Map();
|
|
16
|
-
|
|
17
|
-
containerIdsByElementType.set(elementType,
|
|
18
|
-
|
|
21
|
+
containersByElementType.forEach((containers, elementType) => {
|
|
22
|
+
containerIdsByElementType.set(elementType, containers.map((container) => container.id));
|
|
23
|
+
containers.forEach((container) => containersById.set(container.id, container));
|
|
19
24
|
});
|
|
25
|
+
const pathsByMeasured = new Map();
|
|
26
|
+
for (const measured of measuredDocumentElements) {
|
|
27
|
+
const byElementType = new Map();
|
|
28
|
+
for (const kind of kinds) {
|
|
29
|
+
byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
|
|
30
|
+
}
|
|
31
|
+
pathsByMeasured.set(measured, byElementType);
|
|
32
|
+
}
|
|
20
33
|
const containerPathsByDocumentElementId = new Map();
|
|
21
34
|
const memberIdsByContainerId = new Map();
|
|
22
35
|
for (const measured of measuredDocumentElements) {
|
|
23
36
|
const documentElementId = measured.documentElement.id;
|
|
24
37
|
const pathsByElementType = new Map();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pathsByElementType.set(kind.elementType, path);
|
|
38
|
+
((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
|
|
39
|
+
for (const path of pathsByElementType.values()) {
|
|
28
40
|
for (const containerId of path) {
|
|
29
41
|
const members = memberIdsByContainerId.get(containerId);
|
|
30
42
|
if (members) {
|
|
@@ -38,7 +50,7 @@ class DocumentContainerService {
|
|
|
38
50
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
39
51
|
}
|
|
40
52
|
return new document_container_index_1.DocumentContainerIndex({
|
|
41
|
-
documentElementsById
|
|
53
|
+
documentElementsById,
|
|
42
54
|
containersById,
|
|
43
55
|
containerPathsByDocumentElementId,
|
|
44
56
|
memberIdsByContainerId,
|
|
@@ -48,8 +60,7 @@ class DocumentContainerService {
|
|
|
48
60
|
static isContainer(documentElement, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
49
61
|
return kinds.some((kind) => kind.elementType === (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type));
|
|
50
62
|
}
|
|
51
|
-
static measureDocumentElements(documentElements) {
|
|
52
|
-
const documentElementsById = new Map(documentElements.map((documentElement) => [documentElement.id, documentElement]));
|
|
63
|
+
static measureDocumentElements(documentElements, documentElementsById) {
|
|
53
64
|
return documentElements.map((documentElement, drawOrder) => ({
|
|
54
65
|
documentElement,
|
|
55
66
|
drawOrder,
|
|
@@ -58,12 +69,9 @@ class DocumentContainerService {
|
|
|
58
69
|
}
|
|
59
70
|
static measure(documentElement, documentElementsById) {
|
|
60
71
|
var _a, _b;
|
|
61
|
-
if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position)) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
72
|
try {
|
|
65
|
-
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
66
|
-
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
73
|
+
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;
|
|
74
|
+
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;
|
|
67
75
|
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
|
|
68
76
|
return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
|
|
69
77
|
}
|
|
@@ -71,73 +79,47 @@ class DocumentContainerService {
|
|
|
71
79
|
return null;
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
|
-
static
|
|
75
|
-
|
|
82
|
+
static collectContainers(measuredDocumentElements, kind) {
|
|
83
|
+
return measuredDocumentElements
|
|
76
84
|
.filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
|
|
77
85
|
.map((measured) => ({
|
|
78
86
|
id: measured.documentElement.id,
|
|
79
87
|
kind,
|
|
80
|
-
name: measured.documentElement.name,
|
|
81
88
|
documentElement: measured.documentElement,
|
|
82
89
|
box: measured.box,
|
|
83
|
-
depth: 0,
|
|
84
90
|
drawOrder: measured.drawOrder,
|
|
85
91
|
}));
|
|
86
|
-
const ancestorsById = new Map();
|
|
87
|
-
for (const container of containers) {
|
|
88
|
-
const ancestors = kind.nests
|
|
89
|
-
? containers.filter((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(other.box, container.box))
|
|
90
|
-
: [];
|
|
91
|
-
ancestorsById.set(container.id, ancestors);
|
|
92
|
-
container.depth = ancestors.length;
|
|
93
|
-
}
|
|
94
|
-
return { containers, ancestorsById };
|
|
95
92
|
}
|
|
96
|
-
static
|
|
97
|
-
|
|
98
|
-
if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
|
|
93
|
+
static resolvePath(measured, kind, containers) {
|
|
94
|
+
if (!containers.length || !measured.box) {
|
|
99
95
|
return [];
|
|
100
96
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (ownKind.elementType === kind.elementType) {
|
|
104
|
-
return kind.nests ? this.toContainerPath((_a = nesting.ancestorsById.get(measured.documentElement.id)) !== null && _a !== void 0 ? _a : []) : [];
|
|
105
|
-
}
|
|
106
|
-
if (kind.layer > ownKind.layer) {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const candidates = this.candidateContainers(measured, nesting.containers);
|
|
111
|
-
if (!candidates.length) {
|
|
112
|
-
return [];
|
|
97
|
+
if (measured.documentElement.type === kind.elementType) {
|
|
98
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
113
99
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const ancestors = ((_b = nesting.ancestorsById.get(innermostOnTop.id)) !== null && _b !== void 0 ? _b : []).filter((container) => candidateIds.has(container.id));
|
|
117
|
-
return this.toContainerPath([...ancestors, innermostOnTop]);
|
|
100
|
+
const candidates = this.candidateContainers(measured, containers);
|
|
101
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|
|
118
102
|
}
|
|
119
|
-
static
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
103
|
+
static enclosersOf(measured, containers) {
|
|
104
|
+
return containers.filter((container) => {
|
|
105
|
+
var _a;
|
|
106
|
+
return container.documentElement !== measured.documentElement &&
|
|
107
|
+
document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
|
|
108
|
+
measured.drawOrder > container.drawOrder &&
|
|
109
|
+
!((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
110
|
+
});
|
|
127
111
|
}
|
|
128
112
|
static candidateContainers(measured, containers) {
|
|
129
113
|
const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
|
|
130
|
-
const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
|
|
131
|
-
!dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
|
|
132
114
|
return containers.filter((container) => {
|
|
133
115
|
var _a;
|
|
134
|
-
if (container.
|
|
116
|
+
if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
|
|
135
117
|
return false;
|
|
136
118
|
}
|
|
137
119
|
if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
|
|
138
120
|
return false;
|
|
139
121
|
}
|
|
140
|
-
if (
|
|
122
|
+
if (document_container_1.DocumentContainerUtil.encloses(measured.box, container.box)) {
|
|
141
123
|
return false;
|
|
142
124
|
}
|
|
143
125
|
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
@@ -48,6 +48,7 @@ export declare const HARD_CODED_TEXT: {
|
|
|
48
48
|
'section.itemOptionCount': string;
|
|
49
49
|
'section.colorCount': string;
|
|
50
50
|
};
|
|
51
|
+
export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
|
|
51
52
|
export declare class DynamicTextUtil {
|
|
52
53
|
static isDynamicText(documentElement: DocumentElement): boolean;
|
|
53
54
|
static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
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.isContainerBinding = isContainerBinding;
|
|
4
5
|
const types_1 = require("@contrail/types");
|
|
5
6
|
const util_1 = require("@contrail/util");
|
|
6
7
|
const document_util_1 = require("@contrail/document-util");
|
|
@@ -50,10 +51,14 @@ exports.HARD_CODED_TEXT = {
|
|
|
50
51
|
};
|
|
51
52
|
const CONTAINER_PROPERTY_SLUGS = ['name', 'count', 'itemFamilyCount', 'itemOptionCount', 'colorCount'];
|
|
52
53
|
const CONTAINER_SOURCES = [DYNAMIC_TEXT_DATA_SOURCE.FRAME, DYNAMIC_TEXT_DATA_SOURCE.SECTION];
|
|
54
|
+
function isContainerBinding(bindingProperty) {
|
|
55
|
+
return DynamicTextUtil.takesValueFromContainer(bindingProperty);
|
|
56
|
+
}
|
|
53
57
|
class DynamicTextUtil {
|
|
54
58
|
static isDynamicText(documentElement) {
|
|
59
|
+
var _a;
|
|
55
60
|
return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
|
|
56
|
-
!!documentElement.propertyBindings &&
|
|
61
|
+
!!((_a = documentElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text) &&
|
|
57
62
|
!!documentElement.propertyBindingsMetaData);
|
|
58
63
|
}
|
|
59
64
|
static takesValueFromContainer(bindingProperty) {
|
|
@@ -172,8 +177,9 @@ class DynamicTextUtil {
|
|
|
172
177
|
bold,
|
|
173
178
|
italic,
|
|
174
179
|
};
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
const fixedWidth = size.width - padding * 2;
|
|
181
|
+
if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
|
|
182
|
+
measureTextSettings.width = fixedWidth;
|
|
177
183
|
}
|
|
178
184
|
try {
|
|
179
185
|
const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
|
|
@@ -203,7 +209,7 @@ class DynamicTextUtil {
|
|
|
203
209
|
}
|
|
204
210
|
else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
|
|
205
211
|
text = Array.from(new Set(memberValues
|
|
206
|
-
.filter((e) => e !== null && e !== undefined)
|
|
212
|
+
.filter((e) => e !== null && e !== undefined && e !== '')
|
|
207
213
|
.flat()
|
|
208
214
|
.map((e) => formatter.formatValueForProperty(e, property))))
|
|
209
215
|
.sort()
|
|
@@ -218,7 +224,10 @@ class DynamicTextUtil {
|
|
|
218
224
|
}
|
|
219
225
|
else if (displayFunction === DynamicTextDisplayFunction.MIN ||
|
|
220
226
|
displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
221
|
-
const present = memberValues
|
|
227
|
+
const present = memberValues
|
|
228
|
+
.filter((e) => e !== null && e !== undefined && e !== '')
|
|
229
|
+
.map(Number)
|
|
230
|
+
.filter((e) => !Number.isNaN(e));
|
|
222
231
|
if (!present.length) {
|
|
223
232
|
return '';
|
|
224
233
|
}
|