@contrail/documents 1.20.0-alpha.d734088 → 1.21.0-alpha.55b073f

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,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.20.0] - 2026-09-20
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 measured centre and which is drawn below it.
16
- Nesting gives a path with one container per depth, the later-drawn one winning where two cross.
17
- A container is only ever content of a kind layered behind it, so a frame belongs to a section and
18
- a section never to a frame. Shapes wider and taller than the container, and groups holding it,
19
- are excluded.
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 position rather than its centre when deciding which
37
- container it belongs to, and `DynamicTextUtil.isDynamicText` is the shared test for one. Its size
38
- comes from the value it resolves to, and that value depends on the container, so letting its width
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
@@ -55,26 +67,18 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55
67
  `getBoundingClientRectScaled` above. A scaled element previously measured at its unscaled size
56
68
  and could resolve to the wrong container.
57
69
 
58
- ## [2.2.1] - 2026-09-15
59
-
60
- ### Changed
70
+ ## [1.20.0] - 2026-09-25
61
71
 
62
- - The DESIGN-150 annotation-row collapse is reverted, to go out in a later release alongside the rest of the change. `calculateAnnotationHeight` returns its flat `fontSize + ANNOTATION_PADDING_Y` minimum again whether or not the row draws anything, and `getComponentSize` reserves a flat 18px row in every item card's height.
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
72
+ Maintenance release on the 1.x line; the same change ships on 2.x as 2.3.0.
69
73
 
70
74
  ### Added
71
75
 
72
- - `ItemComponentService.isAnnotationRowEmpty(annotationElement, annotations)` — whether an item card's annotation row will render nothing, because the row is hidden or the item has no `category === 'property'` annotations. The single predicate behind the reservation, so the layout service and the canvas renderers cannot drift apart on the question. A missing row element is not treated as hidden: renderers supply a default row for item components that have none stored, so only the annotation data decides there.
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.
76
+ - `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
77
 
75
- ### Fixed
78
+ ### Changed
76
79
 
77
- - `updateSizeAndPosition` no longer reserves space above the thumbnail for an annotation row that renders nothing. `calculateAnnotationHeight` returned a flat `fontSize + ANNOTATION_PADDING_Y` minimum even when the row was hidden or the item had no annotations, pushing the thumbnail down ~8px on every such card (DESIGN-150). It now returns `0` in those cases and the thumbnail sits at the card origin. Cards whose row does show a badge are unchanged.
80
+ - `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.
81
+ - `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
82
 
79
83
  ## [1.19.0] - 2026-09-11
80
84
 
@@ -35,8 +35,8 @@ class DocumentContainerIndex {
35
35
  return members;
36
36
  }
37
37
  containerPathAtPoint(point, elementType) {
38
- const covering = this.containersOfType(elementType).filter((container) => (0, document_container_1.containsPoint)(container.box, point));
39
- return (0, document_container_1.topmostPerDepth)(covering).map((container) => container.id);
38
+ const covering = this.containersOfType(elementType).filter((container) => document_container_1.DocumentContainerUtil.containsPoint(container.box, point));
39
+ return document_container_1.DocumentContainerUtil.topmostPerDepth(covering).map((container) => container.id);
40
40
  }
41
41
  maxDepth(elementType) {
42
42
  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,14 @@ export interface MeasuredDocumentElement {
14
14
  box: CoordinateBox | null;
15
15
  drawOrder: number;
16
16
  }
17
- export declare function toCoordinateBox(x: number, y: number, width: number, height: number): CoordinateBox;
18
- export declare function centerOf(box: CoordinateBox): PositionDefinition;
19
- export declare function anchorOf(documentElement: DocumentElement, box: CoordinateBox): PositionDefinition;
20
- export declare function containsPoint(box: CoordinateBox, point: PositionDefinition): boolean;
21
- export declare function encloses(outer: CoordinateBox, inner: CoordinateBox): boolean;
22
- export declare function isWiderAndTallerThan(box: CoordinateBox, other: CoordinateBox): boolean;
23
- export declare function topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
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): 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 topmostPerDepth(containers: DocumentContainer[]): DocumentContainer[];
27
+ }
@@ -1,43 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toCoordinateBox = toCoordinateBox;
4
- exports.centerOf = centerOf;
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
- function toCoordinateBox(x, y, width, height) {
12
- return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
13
- }
14
- function centerOf(box) {
15
- return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
16
- }
17
- function anchorOf(documentElement, box) {
18
- return dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement) ? { x: box.left, y: box.top } : centerOf(box);
19
- }
20
- function containsPoint(box, point) {
21
- return point.x >= box.left && point.x <= box.right && point.y >= box.top && point.y <= box.bottom;
22
- }
23
- function encloses(outer, inner) {
24
- const covers = outer.left <= inner.left && outer.right >= inner.right && outer.top <= inner.top && outer.bottom >= inner.bottom;
25
- const identical = outer.left === inner.left &&
26
- outer.right === inner.right &&
27
- outer.top === inner.top &&
28
- outer.bottom === inner.bottom;
29
- return covers && !identical;
30
- }
31
- function isWiderAndTallerThan(box, other) {
32
- return box.width > other.width && box.height > other.height;
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
+ class DocumentContainerUtil {
7
+ static toCoordinateBox(x, y, width, height) {
8
+ return { x, y, width, height, left: x, right: x + width, top: y, bottom: y + height };
9
+ }
10
+ static centerOf(box) {
11
+ return { x: box.left + box.width / 2, y: box.top + box.height / 2 };
12
+ }
13
+ static anchorOf(documentElement, box) {
14
+ var _a;
15
+ if (!dynamic_text_util_1.DynamicTextUtil.isDynamicText(documentElement)) {
16
+ return DocumentContainerUtil.centerOf(box);
17
+ }
18
+ const angle = (_a = documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
19
+ const corner = { x: box.left, y: box.top };
20
+ return angle ? (0, rotation_math_1.rotatePoint)(corner, angle, DocumentContainerUtil.centerOf(box)) : corner;
21
+ }
22
+ static positionKeepingAnchor(documentElement, newSize) {
23
+ var _a, _b, _c, _d, _e;
24
+ const position = documentElement === null || documentElement === void 0 ? void 0 : documentElement.position;
25
+ const angle = (_a = documentElement === null || documentElement === void 0 ? void 0 : documentElement.rotate) === null || _a === void 0 ? void 0 : _a.angle;
26
+ if (!position || !angle || !newSize || !documentElement.size) {
27
+ return position;
28
+ }
29
+ const scaleX = (_c = (_b = documentElement.scale) === null || _b === void 0 ? void 0 : _b.x) !== null && _c !== void 0 ? _c : 1;
30
+ const scaleY = (_e = (_d = documentElement.scale) === null || _d === void 0 ? void 0 : _d.y) !== null && _e !== void 0 ? _e : 1;
31
+ const cornerOffset = (size) => {
32
+ const half = { x: (size.width * scaleX) / 2, y: (size.height * scaleY) / 2 };
33
+ const turned = (0, rotation_math_1.rotatePoint)(half, angle);
34
+ return { x: half.x - turned.x, y: half.y - turned.y };
35
+ };
36
+ const before = cornerOffset(documentElement.size);
37
+ const after = cornerOffset(newSize);
38
+ return { x: position.x + before.x - after.x, y: position.y + before.y - after.y };
39
+ }
40
+ static anchorFor(documentElement, position) {
41
+ var _a, _b, _c, _d, _e;
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 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
+ 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 topmostPerDepth(containers) {
65
+ const byDepth = [];
66
+ for (const container of containers) {
67
+ const existing = byDepth[container.depth];
68
+ if (!existing || container.drawOrder > existing.drawOrder) {
69
+ byDepth[container.depth] = container;
70
+ }
40
71
  }
72
+ return byDepth.filter(Boolean);
41
73
  }
42
- return byDepth.filter(Boolean);
43
74
  }
75
+ exports.DocumentContainerUtil = DocumentContainerUtil;
@@ -65,7 +65,7 @@ class DocumentContainerService {
65
65
  const start = ((_a = documentElement.start) === null || _a === void 0 ? void 0 : _a.id) ? documentElementsById.get(documentElement.start.id) : undefined;
66
66
  const end = ((_b = documentElement.end) === null || _b === void 0 ? void 0 : _b.id) ? documentElementsById.get(documentElement.end.id) : undefined;
67
67
  const { x, y, width, height } = document_element_factory_1.DocumentElementFactory.getBoundingClientRectScaled(documentElement, start, end);
68
- return (0, document_container_1.toCoordinateBox)(x, y, width, height);
68
+ return document_container_1.DocumentContainerUtil.toCoordinateBox(x, y, width, height);
69
69
  }
70
70
  catch (_c) {
71
71
  return null;
@@ -86,7 +86,7 @@ class DocumentContainerService {
86
86
  const ancestorsById = new Map();
87
87
  for (const container of containers) {
88
88
  const ancestors = kind.nests
89
- ? containers.filter((other) => other !== container && (0, document_container_1.encloses)(other.box, container.box))
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
92
  container.depth = ancestors.length;
@@ -123,10 +123,10 @@ class DocumentContainerService {
123
123
  .reduce((topmost, container) => (container.drawOrder > topmost.drawOrder ? container : topmost));
124
124
  }
125
125
  static toContainerPath(containers) {
126
- return (0, document_container_1.topmostPerDepth)(containers).map((container) => container.id);
126
+ return document_container_1.DocumentContainerUtil.topmostPerDepth(containers).map((container) => container.id);
127
127
  }
128
128
  static candidateContainers(measured, containers) {
129
- const anchor = (0, document_container_1.anchorOf)(measured.documentElement, measured.box);
129
+ const anchor = document_container_1.DocumentContainerUtil.anchorOf(measured.documentElement, measured.box);
130
130
  const isShape = document_element_constants_1.SHAPE_ELEMENT_TYPES.includes(measured.documentElement.type) &&
131
131
  !dynamic_text_util_1.DynamicTextUtil.isDynamicText(measured.documentElement);
132
132
  return containers.filter((container) => {
@@ -134,10 +134,10 @@ class DocumentContainerService {
134
134
  if (container.id === measured.documentElement.id || measured.drawOrder <= container.drawOrder) {
135
135
  return false;
136
136
  }
137
- if (!(0, document_container_1.containsPoint)(container.box, anchor)) {
137
+ if (!document_container_1.DocumentContainerUtil.containsPoint(container.box, anchor)) {
138
138
  return false;
139
139
  }
140
- if (isShape && (0, document_container_1.isWiderAndTallerThan)(measured.box, container.box)) {
140
+ if (isShape && document_container_1.DocumentContainerUtil.isWiderAndTallerThan(measured.box, container.box)) {
141
141
  return false;
142
142
  }
143
143
  return !((_a = measured.documentElement.elementIds) === null || _a === void 0 ? void 0 : _a.includes(container.id));
@@ -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) => typeof element.sortIndex === 'string' &&
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 non-empty string"
9
+ SORT_INDEX_NOT_USABLE = "sortIndex must be a valid fractional index"
10
10
  }
@@ -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 non-empty string";
14
+ SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a valid fractional index";
15
15
  })(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.20.0-alpha.d734088",
3
+ "version": "1.21.0-alpha.55b073f",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",