@contrail/documents 2.4.0-alpha.275a7a9 → 2.4.0-alpha.2f408d6

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 CHANGED
@@ -13,54 +13,80 @@ Also shipped on the 1.x line as 1.21.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; 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.
16
+ section, described by a `ContainerKind` carrying `elementType` and `nests`. An element belongs to
17
+ the container whose box covers its anchor point and which is drawn below it, unless the element's
18
+ own box encloses that container or the element is a group holding it. `nests` decides the shape of
19
+ the answer: sections nest, so an element in a section inside another is in both, and the chain
20
+ requires the inner container to be drawn above the outer; frames do not, so an element covered by
21
+ two frames is in the topmost. A container of another kind is placed by the same rules as any
22
+ element, so a frame can be in a section and a section drawn above a frame is in that frame. The
23
+ rule is written out in `src/containers/DOCUMENT_CONTAINERS_SPEC.md`, which the code is measured
24
+ against.
25
+ - `SECTION_ELEMENT_TYPE`, `FRAME_ELEMENT_TYPE` and `SHAPE_ELEMENT_TYPES` in
26
+ `document-element-constants`, so the rule above has one definition rather than one per app.
27
+ - `DocumentContainerUtil` — the container geometry as statics, with `anchorFor` for a caller
28
+ holding an element rather than a measured box.
29
+ - `positionKeepingAnchor` — where an element has to sit for its drawn corner to land where it did
30
+ before a resize. Rotation turns about the centre and the centre moves with the size, so a rotated
31
+ element resized about its stored position drags its corner along with it. The board already makes
32
+ this move; a server recomputing a dynamic text has to make the same one, or the corner is not the
33
+ fixed point the anchor rule needs.
25
34
  - `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
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.
35
+ with `scale` applied. `getBoundingClientRect` keeps returning the element's own box before scale,
36
+ which is what layout works in: `@contrail/document-table` places table members from it, and
37
+ scaling it moves a scaled member into a different cell. Anything deciding what an element overlaps
38
+ or sits on wants the scaled one.
30
39
 
31
40
  ### Deprecated
32
41
 
33
42
  - `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
34
- for what it decides. The old name still works and delegates to the new one.
43
+ for what it decides: whether the binding's value comes from the container rather than a type
44
+ property. The old name still works and delegates to the new one.
35
45
 
36
46
  ### Fixed
37
47
 
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.
48
+ - A dynamic text is now anchored at its drawn top-left corner rather than its centre when deciding
49
+ which container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its
50
+ size comes from the value it resolves to, and that value depends on the container, so letting its
51
+ width feed membership meant its own text could choose its container: near an edge the two answers
52
+ disagreed indefinitely, flipping between a value and "Move to a frame" on every read. Everything
53
+ else still resolves on its centre.
54
+ - The corner is the rotated one (VIBE-9567). A 200x20 text turned on its side draws as a 20x200
55
+ column, and its unrotated `position` can sit well clear of the frame it is visibly on, which
56
+ reported "Move to a frame" for a vertical text the user could see was placed correctly.
57
+ - An element covering a container is not inside it, whatever its type. This replaces a rule that
58
+ excluded only shapes wider and taller than the container, which let a background image join the
59
+ frame it covered and needed an exemption for dynamic text, whose size the container decides. An
60
+ unrotated dynamic text cannot be excluded by enclosure, since its anchor is the corner of the box
61
+ it would have to cover with.
62
+ - `isDynamicText` requires a `propertyBindings.text` binding, which is the one the value is read
63
+ from. The text tool creates an element with empty `propertyBindings` and `propertyBindingsMetaData`
64
+ and both are truthy, so an unconfigured text was anchored at its corner while the canvas centred
65
+ it.
66
+ - A line or callout is measured from the elements it connects even with no stored `position` of its
67
+ own, where it was previously left out of the index entirely.
68
+ - `min` and `max` rendered an infinity sign when every member value was empty. The early return
69
+ checked the list length before the empty values were filtered out, so `Math.min` of nothing
70
+ reached the formatter. Both now fall through to `n/a`.
71
+ - `DynamicTextUtil.calculateSize` threw on an element that reached it without a `size`, which on
72
+ the server failed the read for the whole document. It now measures from a zero size instead.
54
73
 
55
74
  ### Changed
56
75
 
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.
76
+ - Container membership measures a scaled element from its scaled box, through the new
77
+ `getBoundingClientRectScaled` above. Only a sticky note, a regular iframe, a text-tool text or a
78
+ table carries `scale` at all; for this work the one that matters is a text-tool dynamic text,
79
+ which previously measured at its unscaled size and could resolve to the wrong container.
80
+ - `DocumentContainerUtil.anchorFor` measures through the same factory call the index uses, so a
81
+ caller holding an element gets the answer the index would give it. Reading `size` directly
82
+ disagreed for the types whose box is not position plus size: a component's box is built from the
83
+ rows it draws, and a line's comes from its `lineDefinition`.
84
+ - A container path is a containment chain, walked outward from the container the element sits on.
85
+ Two containers that merely cross are not a chain, so the later-drawn one takes the element rather
86
+ than both claiming it. `containerPathAtPoint` walks the same chain, so a drop preview agrees with
87
+ the drop; it applies only the anchor rule, having no element to compare against a container.
88
+ - `buildIndex` scans element types before measuring anything, so a document holding no containers
89
+ of the kinds asked for returns an empty index without a geometry pass.
64
90
 
65
91
  ## [2.3.0] - 2026-09-21
66
92
 
@@ -23,7 +23,7 @@ class DocumentContainerIndex {
23
23
  return this.resolveAll(this.containerIdsOf(documentElementId, elementType));
24
24
  }
25
25
  containerIdsOf(documentElementId, elementType) {
26
- return [...this.containerPath(documentElementId, elementType)];
26
+ return this.containerPath(documentElementId, elementType);
27
27
  }
28
28
  innermostContainerIdOf(documentElementId, elementType) {
29
29
  const path = this.containerPath(documentElementId, elementType);
@@ -31,7 +31,7 @@ class DocumentContainerIndex {
31
31
  }
32
32
  memberIdsOf(containerId) {
33
33
  var _a;
34
- 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 : [];
35
35
  }
36
36
  memberDocumentElementsOf(containerId) {
37
37
  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
- 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
- }
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,9 +8,9 @@ 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 elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
11
+ const elements = documentElements !== null && documentElements !== void 0 ? documentElements : [];
12
12
  const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
13
- if (!elements.some((element) => containerElementTypes.has(element.type))) {
13
+ if (!elements.some((element) => containerElementTypes.has(element === null || element === void 0 ? void 0 : element.type))) {
14
14
  return document_container_index_1.DocumentContainerIndex.empty();
15
15
  }
16
16
  const documentElementsById = new Map(elements.map((element) => [element.id, element]));
@@ -69,9 +69,13 @@ class DocumentContainerService {
69
69
  }
70
70
  static measure(documentElement, documentElementsById) {
71
71
  var _a, _b;
72
+ const isDerivedFromEndpoints = (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'line' || (documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'callout';
73
+ if (!(documentElement === null || documentElement === void 0 ? void 0 : documentElement.position) && !isDerivedFromEndpoints) {
74
+ return null;
75
+ }
72
76
  try {
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;
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
  }
@@ -209,7 +209,7 @@ class DynamicTextUtil {
209
209
  }
210
210
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
211
211
  text = Array.from(new Set(memberValues
212
- .filter((e) => e !== null && e !== undefined && e !== '')
212
+ .filter((e) => e !== null && e !== undefined)
213
213
  .flat()
214
214
  .map((e) => formatter.formatValueForProperty(e, property))))
215
215
  .sort()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.275a7a9",
3
+ "version": "2.4.0-alpha.2f408d6",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",