@contrail/documents 2.4.0-alpha.a27dfea → 2.4.0-alpha.a4d67e4

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,80 +13,54 @@ 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, 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.
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.
34
25
  - `DocumentElementFactory.getBoundingClientRectScaled` — the space an element covers on the canvas,
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.
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.
39
30
 
40
31
  ### Deprecated
41
32
 
42
33
  - `isContainerBinding()` in favour of `DynamicTextUtil.takesValueFromContainer()`. Same rule, named
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.
34
+ for what it decides. The old name still works and delegates to the new one.
45
35
 
46
36
  ### Fixed
47
37
 
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.
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.
73
54
 
74
55
  ### Changed
75
56
 
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.
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.
90
64
 
91
65
  ## [2.3.0] - 2026-09-21
92
66
 
@@ -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,6 +17,10 @@ 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
+ };
20
24
  static anchorFor(documentElement: DocumentElement, position?: PositionDefinition, startElement?: DocumentElement, endElement?: DocumentElement): PositionDefinition;
21
25
  static containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
22
26
  static encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
@@ -38,14 +38,20 @@ 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
+ }
41
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
- if (!at) {
47
+ try {
48
+ const measured = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(at ? Object.assign(Object.assign({}, documentElement), { position: at }) : documentElement, startElement, endElement);
49
+ const box = DocumentContainerUtil.toCoordinateBox(measured.x, measured.y, measured.width, measured.height);
50
+ return DocumentContainerUtil.anchorOf(documentElement, box);
51
+ }
52
+ catch (_a) {
44
53
  return null;
45
54
  }
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
55
  }
50
56
  static containsPoint(box, point) {
51
57
  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 : [];
11
+ const elements = (documentElements !== null && documentElements !== void 0 ? documentElements : []).filter((element) => !!element);
12
12
  const containerElementTypes = new Set(kinds.map((kind) => kind.elementType));
13
- if (!elements.some((element) => containerElementTypes.has(element === null || element === void 0 ? void 0 : element.type))) {
13
+ if (!elements.some((element) => containerElementTypes.has(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]));
@@ -32,19 +32,22 @@ class DocumentContainerService {
32
32
  }
33
33
  const containerPathsByDocumentElementId = new Map();
34
34
  const memberIdsByContainerId = new Map();
35
+ const memberIdsSeen = new Map();
35
36
  for (const measured of measuredDocumentElements) {
36
37
  const documentElementId = measured.documentElement.id;
37
38
  const pathsByElementType = new Map();
38
39
  ((_b = pathsByMeasured.get(measured)) !== null && _b !== void 0 ? _b : new Map()).forEach((path, elementType) => pathsByElementType.set(elementType, path.map((container) => container.id)));
39
40
  for (const path of pathsByElementType.values()) {
40
41
  for (const containerId of path) {
41
- const members = memberIdsByContainerId.get(containerId);
42
- if (members) {
43
- members.push(documentElementId);
44
- }
45
- else {
42
+ const seen = memberIdsSeen.get(containerId);
43
+ if (!seen) {
44
+ memberIdsSeen.set(containerId, new Set([documentElementId]));
46
45
  memberIdsByContainerId.set(containerId, [documentElementId]);
47
46
  }
47
+ else if (!seen.has(documentElementId)) {
48
+ seen.add(documentElementId);
49
+ memberIdsByContainerId.get(containerId).push(documentElementId);
50
+ }
48
51
  }
49
52
  }
50
53
  containerPathsByDocumentElementId.set(documentElementId, pathsByElementType);
@@ -69,13 +72,9 @@ class DocumentContainerService {
69
72
  }
70
73
  static measure(documentElement, documentElementsById) {
71
74
  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
- }
76
75
  try {
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;
76
+ 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;
77
+ 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;
79
78
  const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
80
79
  return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
81
80
  }
@@ -107,7 +106,7 @@ class DocumentContainerService {
107
106
  static enclosersOf(measured, containers) {
108
107
  return containers.filter((container) => {
109
108
  var _a;
110
- return container.documentElement !== measured.documentElement &&
109
+ return container.id !== measured.documentElement.id &&
111
110
  document_container_1.DocumentContainerUtil.encloses(container.box, measured.box) &&
112
111
  measured.drawOrder > container.drawOrder &&
113
112
  !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
@@ -117,7 +116,7 @@ class DocumentContainerService {
117
116
  const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
118
117
  return containers.filter((container) => {
119
118
  var _a;
120
- if (container.documentElement === measured.documentElement || measured.drawOrder <= container.drawOrder) {
119
+ if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
121
120
  return false;
122
121
  }
123
122
  if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
@@ -27,6 +27,8 @@ export declare enum DynamicTextDisplayFunction {
27
27
  export declare const MOVE_TO_FRAME_TEXT = "Move to a frame";
28
28
  export declare const MOVE_TO_SECTION_TEXT = "Move to a section";
29
29
  export declare const CLICK_TO_CONFIGURE = "Click to configure";
30
+ export declare function placeholderForMissingContainer(entityType: string): string;
31
+ export declare function isPlaceholderText(text: string): boolean;
30
32
  export declare const HARD_CODED_TEXT: {
31
33
  'project.name': string;
32
34
  'project.createdBy.email': string;
@@ -1,6 +1,8 @@
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.placeholderForMissingContainer = placeholderForMissingContainer;
5
+ exports.isPlaceholderText = isPlaceholderText;
4
6
  exports.isContainerBinding = isContainerBinding;
5
7
  const types_1 = require("@contrail/types");
6
8
  const util_1 = require("@contrail/util");
@@ -28,6 +30,12 @@ var DynamicTextDisplayFunction;
28
30
  exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
29
31
  exports.MOVE_TO_SECTION_TEXT = 'Move to a section';
30
32
  exports.CLICK_TO_CONFIGURE = 'Click to configure';
33
+ function placeholderForMissingContainer(entityType) {
34
+ return entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
35
+ }
36
+ function isPlaceholderText(text) {
37
+ return text === exports.MOVE_TO_FRAME_TEXT || text === exports.MOVE_TO_SECTION_TEXT || text === exports.CLICK_TO_CONFIGURE;
38
+ }
31
39
  exports.HARD_CODED_TEXT = {
32
40
  'project.name': 'Project name',
33
41
  'project.createdBy.email': 'Project created by',
@@ -98,7 +106,7 @@ class DynamicTextUtil {
98
106
  }
99
107
  else {
100
108
  if (!container && !isSpecRelated) {
101
- text = entityType === DYNAMIC_TEXT_DATA_SOURCE.SECTION ? exports.MOVE_TO_SECTION_TEXT : exports.MOVE_TO_FRAME_TEXT;
109
+ text = placeholderForMissingContainer(entityType);
102
110
  }
103
111
  else {
104
112
  if (CONTAINER_SOURCES.includes(entityType)) {
@@ -141,7 +149,7 @@ class DynamicTextUtil {
141
149
  text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
142
150
  }
143
151
  else if (!container) {
144
- text = exports.MOVE_TO_FRAME_TEXT;
152
+ text = placeholderForMissingContainer(entityType);
145
153
  }
146
154
  else {
147
155
  text = property === null || property === void 0 ? void 0 : property.label;
@@ -151,7 +159,7 @@ class DynamicTextUtil {
151
159
  text = 'n/a';
152
160
  }
153
161
  if (displayLabel &&
154
- ![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
162
+ !isPlaceholderText(text) &&
155
163
  displayFunction !== DynamicTextDisplayFunction.LABEL &&
156
164
  text !== bindingProperty) {
157
165
  text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.a27dfea",
3
+ "version": "2.4.0-alpha.a4d67e4",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",