@contrail/documents 2.4.0-alpha.7e4b381 → 2.4.0-alpha.a01d866

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
@@ -5,7 +5,9 @@ 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
- ## [2.4.0] - 2026-09-24
8
+ ## [2.4.0] - 2026-09-26
9
+
10
+ Also shipped on the 1.x line as 1.21.0.
9
11
 
10
12
  ### Added
11
13
 
@@ -62,8 +64,16 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
62
64
  ### Changed
63
65
 
64
66
  - Container membership measures a scaled element from its scaled box, through the new
65
- `getBoundingClientRectScaled` above. A scaled element previously measured at its unscaled size
66
- and could resolve to the wrong container.
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.
67
77
 
68
78
  ## [2.3.0] - 2026-09-21
69
79
 
@@ -19,7 +19,7 @@ export declare class DocumentContainerUtil {
19
19
  static centerOf(box: CoordinateBox): PositionDefinition;
20
20
  static anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
21
21
  static positionKeepingAnchor(documentElement: DocumentElement, newSize: SizeDefinition): PositionDefinition;
22
- static anchorFor(documentElement: DocumentElement, position?: PositionDefinition): PositionDefinition;
22
+ static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
23
23
  static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
24
24
  static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
25
25
  static isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
@@ -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,14 +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 anchorFor(documentElement, position) {
41
+ static anchorFor(documentElement, position, startElement, endElement) {
41
42
  var _a, _b, _c, _d, _e;
42
43
  const at = position !== null && position !== void 0 ? position : documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
43
44
  if (!at) {
44
45
  return null;
45
46
  }
46
47
  const size = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.size) !== null && _a !== void 0 ? _a : { width: 0, height: 0 };
47
- const box = DocumentContainerUtil.toCoordinateBox(at.x, at.y, size.width * ((_c = (_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1), size.height * ((_e = (_d = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1));
48
+ let width = size.width * ((_c = (_b = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1);
49
+ let height = size.height * ((_e = (_d = documentElement === null || documentElement === void 0 ? void 0 : documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1);
50
+ try {
51
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(Object.assign(Object.assign({}, documentElement), { position: at }), startElement, endElement);
52
+ width = measured.width;
53
+ height = measured.height;
54
+ }
55
+ catch (_f) {
56
+ }
57
+ const box = DocumentContainerUtil.toCoordinateBox(at.x, at.y, width, height);
48
58
  return DocumentContainerUtil.anchorOf(documentElement, box);
49
59
  }
50
60
  static containsPoint(box, point) {
@@ -89,7 +89,21 @@ class DocumentContainerService {
89
89
  ? containers.filter((other) => other !== container && document_container_1.DocumentContainerUtil.encloses(other.box, container.box))
90
90
  : [];
91
91
  ancestorsById.set(container.id, ancestors);
92
- container.depth = ancestors.length;
92
+ }
93
+ const depths = new Map();
94
+ const depthOf = (container) => {
95
+ var _a;
96
+ const cached = depths.get(container.id);
97
+ if (cached !== undefined) {
98
+ return cached;
99
+ }
100
+ const ancestors = (_a = ancestorsById.get(container.id)) !== null && _a !== void 0 ? _a : [];
101
+ const depth = ancestors.length ? 1 + Math.max(...ancestors.map(depthOf)) : 0;
102
+ depths.set(container.id, depth);
103
+ return depth;
104
+ };
105
+ for (const container of containers) {
106
+ container.depth = depthOf(container);
93
107
  }
94
108
  return { containers, ancestorsById };
95
109
  }
@@ -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' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.7e4b381",
3
+ "version": "2.4.0-alpha.a01d866",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",