@contrail/documents 1.20.0-alpha.d734088 → 1.21.0-alpha.0a5e682
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 +38 -26
- package/lib/containers/document-container-index.js +6 -2
- package/lib/containers/document-container.d.ts +13 -8
- package/lib/containers/document-container.js +81 -37
- package/lib/containers/document-container.service.d.ts +3 -4
- package/lib/containers/document-container.service.js +50 -45
- package/lib/sort-index.d.ts +1 -0
- package/lib/sort-index.js +15 -2
- package/lib/sort-order-errors.d.ts +1 -1
- package/lib/sort-order-errors.js +1 -1
- package/lib/util/dynamic-text/dynamic-text-util.d.ts +1 -0
- package/lib/util/dynamic-text/dynamic-text-util.js +11 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,20 +5,29 @@ 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.
|
|
8
|
+
## [1.21.0] - 2026-09-26
|
|
9
|
+
|
|
10
|
+
Maintenance release on the 1.x line; the same change ships on 2.x as 2.4.0.
|
|
9
11
|
|
|
10
12
|
### Added
|
|
11
13
|
|
|
12
14
|
- `DocumentContainerService.buildIndex` and `DocumentContainerIndex` — which containers hold which
|
|
13
15
|
elements, for one document, resolved once and read back by lookup. A container is a frame or a
|
|
14
16
|
section, described by a `ContainerKind` carrying `elementType`, `nests` and `layer`. An element
|
|
15
|
-
belongs to the container whose box covers its
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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.
|
|
20
22
|
- `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
|
|
21
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.
|
|
22
31
|
- `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
|
|
23
32
|
with `scale` applied. `getBoundingClientRect` keeps returning the element's own box before scale,
|
|
24
33
|
which is what layout works in: `@contrail/document-table` places table members from it, and
|
|
@@ -33,12 +42,15 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
33
42
|
|
|
34
43
|
### Fixed
|
|
35
44
|
|
|
36
|
-
- A dynamic text is now anchored at its
|
|
37
|
-
container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its
|
|
38
|
-
comes from the value it resolves to, and that value depends on the container, so letting its
|
|
39
|
-
feed membership meant its own text could choose its container: near an edge the two answers
|
|
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
|
|
40
49
|
disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
|
|
41
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.
|
|
42
54
|
- A dynamic text is also exempt from the oversized-shape exclusion, which keeps a shape wider and
|
|
43
55
|
taller than a container off it. That rule reads size too, so a dynamic text larger than its frame
|
|
44
56
|
in both directions had two self-consistent answers and kept whichever it started from. The rule
|
|
@@ -52,29 +64,29 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
52
64
|
### Changed
|
|
53
65
|
|
|
54
66
|
- Container membership measures a scaled element from its scaled box, through the new
|
|
55
|
-
`getBoundingClientRectScaled` above.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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.
|
|
59
77
|
|
|
60
|
-
|
|
78
|
+
## [1.20.0] - 2026-09-25
|
|
61
79
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Removed
|
|
65
|
-
|
|
66
|
-
- `ItemComponentService.isAnnotationRowEmpty` and `ItemComponentService.getAnnotationRowHeight`, both added in 2.2.0, and the optional `annotations` parameter they were reached through on `DocumentElementFactory.getBoundingClientRect` and `getSize`. Removed under a patch because 2.2.0 published hours earlier and nothing had consumed them: the canvas renderer mirrors the predicate privately rather than importing it, and every `contrail-apps` app pins this package on its 1.x range.
|
|
67
|
-
|
|
68
|
-
## [2.2.0] - 2026-09-15
|
|
80
|
+
Maintenance release on the 1.x line; the same change ships on 2.x as 2.3.0.
|
|
69
81
|
|
|
70
82
|
### Added
|
|
71
83
|
|
|
72
|
-
- `
|
|
73
|
-
- `ItemComponentService.getAnnotationRowHeight(annotationElement, annotations, width)` — the row's reserved height, wrapping onto further rows when the badges do not fit `width`, and `0` when the row is empty. Every creation path must size the row through here so a card laid out by the Item Chooser and one laid out by board generation agree.
|
|
84
|
+
- `isValidSortIndex(sortIndex)` — whether a value is a key `fractional-indexing` could have produced, so every client writing a sort index is held to one definition of valid rather than each caller inventing its own. `fractional-indexing` keeps its `validateOrderKey` private, so the check asks the generator to mint a key after the candidate: that path validates its bound first and cannot fail for any other reason. The generator's own grammar check ignores the digit alphabet, and accepts `a0!` or `a0 `, so the candidate is screened against the exported `BASE_62_DIGITS` first. Costs ~130ns for a short key and ~350ns for a 387-character one.
|
|
74
85
|
|
|
75
|
-
###
|
|
86
|
+
### Changed
|
|
76
87
|
|
|
77
|
-
- `
|
|
88
|
+
- `allElementsHaveSortIndex` now requires each element's key to be valid, not merely a non-empty string. Callers that treat an unkeyed collection as needing fresh keys — board snapshot restore is the one today — now also re-key a collection whose keys are present but malformed, instead of restoring ordering that cannot sort.
|
|
89
|
+
- `SortOrderErrorMessage.SORT_INDEX_NOT_USABLE` describes the real rule ("sortIndex must be a valid fractional index") rather than "must be a non-empty string". The `SORT_INDEX_NOT_USABLE` code is unchanged.
|
|
78
90
|
|
|
79
91
|
## [1.19.0] - 2026-09-11
|
|
80
92
|
|
|
@@ -35,8 +35,12 @@ class DocumentContainerIndex {
|
|
|
35
35
|
return members;
|
|
36
36
|
}
|
|
37
37
|
containerPathAtPoint(point, elementType) {
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const containers = this.containersOfType(elementType);
|
|
40
|
+
const covering = containers.filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
|
|
41
|
+
const nests = (_b = (_a = containers[0]) === null || _a === void 0 ? void 0 : _a.kind.nests) !== null && _b !== void 0 ? _b : true;
|
|
42
|
+
const path = nests ? document_container_1.DocumentContainerUtil.chain(covering) : document_container_1.DocumentContainerUtil.topmost(covering);
|
|
43
|
+
return path.map((container) => container.id);
|
|
40
44
|
}
|
|
41
45
|
maxDepth(elementType) {
|
|
42
46
|
return this.containersOfType(elementType).reduce((max, container) => Math.max(max, container.depth + 1), 0);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CoordinateBox, DocumentElement, PositionDefinition } from '../types';
|
|
1
|
+
import { CoordinateBox, DocumentElement, PositionDefinition, SizeDefinition } from '../types';
|
|
2
2
|
import { ContainerKind } from './container-kind';
|
|
3
3
|
export interface DocumentContainer {
|
|
4
4
|
id: string;
|
|
@@ -14,10 +14,15 @@ export interface MeasuredDocumentElement {
|
|
|
14
14
|
box: CoordinateBox | null;
|
|
15
15
|
drawOrder: number;
|
|
16
16
|
}
|
|
17
|
-
export declare
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export declare class DocumentContainerUtil {
|
|
18
|
+
static toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
|
|
19
|
+
static centerOf(box: CoordinateBox): PositionDefinition;
|
|
20
|
+
static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
|
|
21
|
+
static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
|
|
22
|
+
static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
|
|
23
|
+
static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
|
|
24
|
+
static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
|
|
25
|
+
static isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
|
|
26
|
+
static chain(candidates: DocumentContainer[]): DocumentContainer[];
|
|
27
|
+
static topmost(containers: DocumentContainer[]): DocumentContainer[];
|
|
28
|
+
}
|
|
@@ -1,43 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
exports.anchorOf = anchorOf;
|
|
6
|
-
exports.containsPoint = containsPoint;
|
|
7
|
-
exports.encloses = encloses;
|
|
8
|
-
exports.isWiderAndTallerThan = isWiderAndTallerThan;
|
|
9
|
-
exports.topmostPerDepth = topmostPerDepth;
|
|
3
|
+
exports.DocumentContainerUtil = void 0;
|
|
4
|
+
const rotation_math_1 = require("../util/mask/rotation-math");
|
|
10
5
|
const dynamic_text_util_1 = require("../util/dynamic-text/dynamic-text-util");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function topmostPerDepth(containers) {
|
|
35
|
-
const byDepth = [];
|
|
36
|
-
for (const container of containers) {
|
|
37
|
-
const existing = byDepth[container.depth];
|
|
38
|
-
if (!existing || container.drawOrder > existing.drawOrder) {
|
|
39
|
-
byDepth[container.depth] = container;
|
|
6
|
+
const document_element_factory_1 = require("../document-element-factory");
|
|
7
|
+
class DocumentContainerUtil {
|
|
8
|
+
static toCoordinateBox(x, y, width, height) {
|
|
9
|
+
return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
|
|
10
|
+
}
|
|
11
|
+
static centerOf(box) {
|
|
12
|
+
return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
|
|
13
|
+
}
|
|
14
|
+
static anchorOf(documentElement, box) {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement)) {
|
|
17
|
+
return DocumentContainerUtil.centerOf(box);
|
|
18
|
+
}
|
|
19
|
+
const angle = (_a = documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
20
|
+
const corner = { x: box.left, y: box.top };
|
|
21
|
+
return angle ? (0, rotation_math_1.rotatePoint)(corner, angle, DocumentContainerUtil.centerOf(box)) : corner;
|
|
22
|
+
}
|
|
23
|
+
static positionKeepingAnchor(documentElement, newSize) {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
25
|
+
const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
26
|
+
const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
|
|
27
|
+
if (!position || !angle || !newSize || !documentElement.size) {
|
|
28
|
+
return position;
|
|
40
29
|
}
|
|
30
|
+
const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
|
|
31
|
+
const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
|
|
32
|
+
const cornerOffset = (size) => {
|
|
33
|
+
const half = { x: (size.width * scaleX) / 2, y: (size.height * scaleY) / 2 };
|
|
34
|
+
const turned = (0, rotation_math_1.rotatePoint)(half, angle);
|
|
35
|
+
return { x: half.x - turned.x, y: half.y - turned.y };
|
|
36
|
+
};
|
|
37
|
+
const before = cornerOffset(documentElement.size);
|
|
38
|
+
const after = cornerOffset(newSize);
|
|
39
|
+
return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
|
|
40
|
+
}
|
|
41
|
+
static anchorFor(documentElement, position, startElement, endElement) {
|
|
42
|
+
const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
|
|
43
|
+
if (!at) {
|
|
44
|
+
return null;
|
|
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);
|
|
49
|
+
}
|
|
50
|
+
static containsPoint(box, point) {
|
|
51
|
+
return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
|
|
52
|
+
}
|
|
53
|
+
static encloses(outer, inner) {
|
|
54
|
+
const covers = outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
|
|
55
|
+
const identical = outer.left === inner.left &&
|
|
56
|
+
outer.right === inner.right &&
|
|
57
|
+
outer.top === inner.top &&
|
|
58
|
+
outer.bottom === inner.bottom;
|
|
59
|
+
return covers && !identical;
|
|
60
|
+
}
|
|
61
|
+
static isWiderAndTallerThan(box, other) {
|
|
62
|
+
return box.width > other.width && box.height > other.height;
|
|
63
|
+
}
|
|
64
|
+
static chain(candidates) {
|
|
65
|
+
if (!candidates.length) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
const innermostOf = (of) => of
|
|
69
|
+
.filter((container) => !of.some((other) => other !== container && this.encloses(container.box, other.box)))
|
|
70
|
+
.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
|
|
71
|
+
const path = [innermostOf(candidates)];
|
|
72
|
+
for (;;) {
|
|
73
|
+
const current = path[0];
|
|
74
|
+
const enclosing = candidates.filter((container) => !path.includes(container) && this.encloses(container.box, current.box));
|
|
75
|
+
if (!enclosing.length) {
|
|
76
|
+
return path;
|
|
77
|
+
}
|
|
78
|
+
path.unshift(innermostOf(enclosing));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static topmost(containers) {
|
|
82
|
+
return containers.length
|
|
83
|
+
? [containers.reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost))]
|
|
84
|
+
: [];
|
|
41
85
|
}
|
|
42
|
-
return byDepth.filter(Boolean);
|
|
43
86
|
}
|
|
87
|
+
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
|
}
|
|
@@ -9,22 +9,43 @@ const document_container_index_1 = require("./document-container-index");
|
|
|
9
9
|
const document_container_1 = require("./document-container");
|
|
10
10
|
class DocumentContainerService {
|
|
11
11
|
static buildIndex(documentElements, kinds = container_kind_1.CONTAINER_KINDS) {
|
|
12
|
+
var _a, _b, _c, _d;
|
|
12
13
|
const measuredDocumentElements = this.measureDocumentElements(documentElements !== null && documentElements !== void 0 ? documentElements : []);
|
|
13
|
-
const
|
|
14
|
+
const kindsByLayer = [...kinds].sort((first, second) => second.layer - first.layer);
|
|
15
|
+
const containersByElementType = new Map(kindsByLayer.map((kind) => [kind.elementType, this.collectContainers(measuredDocumentElements, kind)]));
|
|
14
16
|
const containersById = new Map();
|
|
15
17
|
const containerIdsByElementType = new Map();
|
|
16
|
-
|
|
17
|
-
containerIdsByElementType.set(elementType,
|
|
18
|
-
|
|
18
|
+
containersByElementType.forEach((containers, elementType) => {
|
|
19
|
+
containerIdsByElementType.set(elementType, containers.map((container) => container.id));
|
|
20
|
+
containers.forEach((container) => containersById.set(container.id, container));
|
|
19
21
|
});
|
|
22
|
+
const pathsByMeasured = new Map();
|
|
23
|
+
for (const measured of measuredDocumentElements) {
|
|
24
|
+
const byElementType = new Map();
|
|
25
|
+
for (const kind of kindsByLayer) {
|
|
26
|
+
byElementType.set(kind.elementType, this.resolvePath(measured, kind, (_a = containersByElementType.get(kind.elementType)) !== null && _a !== void 0 ? _a : []));
|
|
27
|
+
}
|
|
28
|
+
pathsByMeasured.set(measured, byElementType);
|
|
29
|
+
}
|
|
30
|
+
for (const measured of measuredDocumentElements) {
|
|
31
|
+
const container = containersById.get(measured.documentElement.id);
|
|
32
|
+
if (container && container.documentElement === measured.documentElement) {
|
|
33
|
+
container.depth = ((_c = (_b = pathsByMeasured.get(measured)) === null || _b === void 0 ? void 0 : _b.get(container.kind.elementType)) !== null && _c !== void 0 ? _c : []).length;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const measuredById = new Map();
|
|
37
|
+
for (const measured of measuredDocumentElements) {
|
|
38
|
+
if (!measuredById.has(measured.documentElement.id)) {
|
|
39
|
+
measuredById.set(measured.documentElement.id, measured);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
20
42
|
const containerPathsByDocumentElementId = new Map();
|
|
21
43
|
const memberIdsByContainerId = new Map();
|
|
22
44
|
for (const measured of measuredDocumentElements) {
|
|
23
45
|
const documentElementId = measured.documentElement.id;
|
|
24
46
|
const pathsByElementType = new Map();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
pathsByElementType.set(kind.elementType, path);
|
|
47
|
+
((_d = pathsByMeasured.get(measured)) !== null && _d !== void 0 ? _d : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
|
|
48
|
+
for (const path of pathsByElementType.values()) {
|
|
28
49
|
for (const containerId of path) {
|
|
29
50
|
const members = memberIdsByContainerId.get(containerId);
|
|
30
51
|
if (members) {
|
|
@@ -38,7 +59,7 @@ class DocumentContainerService {
|
|
|
38
59
|
containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
|
|
39
60
|
}
|
|
40
61
|
return new document_container_index_1.DocumentContainerIndex({
|
|
41
|
-
documentElementsById: new Map(
|
|
62
|
+
documentElementsById: new Map([...measuredById].map(([id, measured]) => [id, measured.documentElement])),
|
|
42
63
|
containersById,
|
|
43
64
|
containerPathsByDocumentElementId,
|
|
44
65
|
memberIdsByContainerId,
|
|
@@ -65,14 +86,14 @@ class DocumentContainerService {
|
|
|
65
86
|
const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
|
|
66
87
|
const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
|
|
67
88
|
const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
|
|
68
|
-
return
|
|
89
|
+
return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
|
|
69
90
|
}
|
|
70
91
|
catch (_c) {
|
|
71
92
|
return null;
|
|
72
93
|
}
|
|
73
94
|
}
|
|
74
|
-
static
|
|
75
|
-
|
|
95
|
+
static collectContainers(measuredDocumentElements, kind) {
|
|
96
|
+
return measuredDocumentElements
|
|
76
97
|
.filter((measured) => measured.documentElement.type === kind.elementType && measured.box)
|
|
77
98
|
.map((measured) => ({
|
|
78
99
|
id: measured.documentElement.id,
|
|
@@ -83,61 +104,45 @@ class DocumentContainerService {
|
|
|
83
104
|
depth: 0,
|
|
84
105
|
drawOrder: measured.drawOrder,
|
|
85
106
|
}));
|
|
86
|
-
const ancestorsById = new Map();
|
|
87
|
-
for (const container of containers) {
|
|
88
|
-
const ancestors = kind.nests
|
|
89
|
-
? containers.filter((other) => other !== container && (0, document_container_1.encloses)(other.box, container.box))
|
|
90
|
-
: [];
|
|
91
|
-
ancestorsById.set(container.id, ancestors);
|
|
92
|
-
container.depth = ancestors.length;
|
|
93
|
-
}
|
|
94
|
-
return { containers, ancestorsById };
|
|
95
107
|
}
|
|
96
|
-
static
|
|
97
|
-
|
|
98
|
-
if (!(nesting === null || nesting === void 0 ? void 0 : nesting.containers.length) || !measured.box) {
|
|
108
|
+
static resolvePath(measured, kind, containers) {
|
|
109
|
+
if (!containers.length || !measured.box) {
|
|
99
110
|
return [];
|
|
100
111
|
}
|
|
101
|
-
const ownKind =
|
|
112
|
+
const ownKind = container_kind_1.CONTAINER_KINDS.find((candidate) => candidate.elementType === measured.documentElement.type);
|
|
102
113
|
if (ownKind) {
|
|
103
114
|
if (ownKind.elementType === kind.elementType) {
|
|
104
|
-
return kind.nests ?
|
|
115
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(this.enclosersOf(measured, containers)) : [];
|
|
105
116
|
}
|
|
106
117
|
if (kind.layer > ownKind.layer) {
|
|
107
118
|
return [];
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
|
-
const candidates = this.candidateContainers(measured,
|
|
111
|
-
|
|
112
|
-
return [];
|
|
113
|
-
}
|
|
114
|
-
const innermostOnTop = this.resolveInnermostOnTop(candidates, nesting);
|
|
115
|
-
const candidateIds = new Set(candidates.map((container) => container.id));
|
|
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]);
|
|
121
|
+
const candidates = this.candidateContainers(measured, containers);
|
|
122
|
+
return kind.nests ? document_container_1.DocumentContainerUtil.chain(candidates) : document_container_1.DocumentContainerUtil.topmost(candidates);
|
|
118
123
|
}
|
|
119
|
-
static
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
static enclosersOf(measured, containers) {
|
|
125
|
+
return containers.filter((container) => {
|
|
126
|
+
var _a;
|
|
127
|
+
return container.documentElement !== measured.documentElement &&
|
|
128
|
+
document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
|
|
129
|
+
measured.drawOrder > container.drawOrder &&
|
|
130
|
+
!((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
|
131
|
+
});
|
|
127
132
|
}
|
|
128
133
|
static candidateContainers(measured, containers) {
|
|
129
|
-
const anchor =
|
|
134
|
+
const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
|
|
130
135
|
const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
|
|
131
136
|
!dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
|
|
132
137
|
return containers.filter((container) => {
|
|
133
138
|
var _a;
|
|
134
|
-
if (container.
|
|
139
|
+
if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
|
|
135
140
|
return false;
|
|
136
141
|
}
|
|
137
|
-
if (!
|
|
142
|
+
if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
|
|
138
143
|
return false;
|
|
139
144
|
}
|
|
140
|
-
if (isShape &&
|
|
145
|
+
if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
|
|
141
146
|
return false;
|
|
142
147
|
}
|
|
143
148
|
return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
|
package/lib/sort-index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DocumentElement } from './types';
|
|
2
|
+
export declare function isValidSortIndex(sortIndex: unknown): sortIndex is string;
|
|
2
3
|
export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
|
|
3
4
|
export declare function buildKeyBetween(a: string | null, b: string | null): string;
|
|
4
5
|
export declare function buildNKeysBetween(a: string | null, b: string | null, n: number): string[];
|
package/lib/sort-index.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidSortIndex = isValidSortIndex;
|
|
3
4
|
exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
|
|
4
5
|
exports.buildKeyBetween = buildKeyBetween;
|
|
5
6
|
exports.buildNKeysBetween = buildNKeysBetween;
|
|
6
7
|
exports.compareSortIndex = compareSortIndex;
|
|
7
8
|
const fractional_indexing_1 = require("fractional-indexing");
|
|
9
|
+
const SORT_INDEX_DIGITS = new RegExp(`^[${fractional_indexing_1.BASE_62_DIGITS.replace(/[\\\]^-]/g, (digit) => `\\${digit}`)}]+$`);
|
|
10
|
+
function isValidSortIndex(sortIndex) {
|
|
11
|
+
if (typeof sortIndex !== 'string' || !SORT_INDEX_DIGITS.test(sortIndex)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
(0, fractional_indexing_1.generateKeyBetween)(sortIndex, null);
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
8
22
|
function allElementsHaveSortIndex(elements) {
|
|
9
|
-
return elements.every((element) =>
|
|
10
|
-
element.sortIndex.length > 0);
|
|
23
|
+
return elements.every((element) => isValidSortIndex(element.sortIndex));
|
|
11
24
|
}
|
|
12
25
|
function buildKeyBetween(a, b) {
|
|
13
26
|
return (0, fractional_indexing_1.generateKeyBetween)(a, b);
|
|
@@ -6,5 +6,5 @@ export declare enum SortOrderErrorCode {
|
|
|
6
6
|
export declare enum SortOrderErrorMessage {
|
|
7
7
|
SORT_MIGRATION_IN_PROGRESS = "Sort order is being migrated for this document; editing is briefly locked",
|
|
8
8
|
SORT_MODE_MISMATCH = "Ordering write does not match the document's sort mode",
|
|
9
|
-
SORT_INDEX_NOT_USABLE = "sortIndex must be a
|
|
9
|
+
SORT_INDEX_NOT_USABLE = "sortIndex must be a valid fractional index"
|
|
10
10
|
}
|
package/lib/sort-order-errors.js
CHANGED
|
@@ -11,5 +11,5 @@ var SortOrderErrorMessage;
|
|
|
11
11
|
(function (SortOrderErrorMessage) {
|
|
12
12
|
SortOrderErrorMessage["SORT_MIGRATION_IN_PROGRESS"] = "Sort order is being migrated for this document; editing is briefly locked";
|
|
13
13
|
SortOrderErrorMessage["SORT_MODE_MISMATCH"] = "Ordering write does not match the document's sort mode";
|
|
14
|
-
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a
|
|
14
|
+
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a valid fractional index";
|
|
15
15
|
})(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
|
|
@@ -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,6 +51,9 @@ 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) {
|
|
55
59
|
return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
|
|
@@ -172,8 +176,9 @@ class DynamicTextUtil {
|
|
|
172
176
|
bold,
|
|
173
177
|
italic,
|
|
174
178
|
};
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
const fixedWidth = size.width - padding * 2;
|
|
180
|
+
if (!dynamicTextElement.isTextTool && fixedWidth > 0) {
|
|
181
|
+
measureTextSettings.width = fixedWidth;
|
|
177
182
|
}
|
|
178
183
|
try {
|
|
179
184
|
const dimensions = document_util_1.DocumentTextUtil.measureText(text, measureTextSettings);
|
|
@@ -218,7 +223,10 @@ class DynamicTextUtil {
|
|
|
218
223
|
}
|
|
219
224
|
else if (displayFunction === DynamicTextDisplayFunction.MIN ||
|
|
220
225
|
displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
221
|
-
const present = memberValues
|
|
226
|
+
const present = memberValues
|
|
227
|
+
.filter((e) => e !== null && e !== undefined && e !== '')
|
|
228
|
+
.map(Number)
|
|
229
|
+
.filter((e) => !Number.isNaN(e));
|
|
222
230
|
if (!present.length) {
|
|
223
231
|
return '';
|
|
224
232
|
}
|