@contrail/documents 1.11.0 → 1.12.0-alpha.aad6f60

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,6 +5,14 @@ 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.12.0] - 2026-07-21
9
+
10
+ ### Added
11
+
12
+ - Reliable sort-order surface (PLAT-1270): `Document.sortMode` (`'array' | 'elementIndexing' | 'migrating'`, `undefined` = `array`; `'migrating'` is the transient mid-convert state where ordering edits are rejected); `DocumentElement.sortIndex` (fractional-indexing key).
13
+ - Sort utilities: `buildKeyBetween` / `buildNKeysBetween` (generate index key(s) between two neighbours), `compareSortIndex` (`(sortIndex, id)` comparator), and `allElementsHaveSortIndex`.
14
+ - `SortOrderErrorCode` / `SortOrderErrorMessage` — structured code for the mid-convert freeze (`SORT_MIGRATION_IN_PROGRESS`).
15
+
8
16
  ## [1.11.0] - 2026-06-29
9
17
 
10
18
  ### Added
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './types';
2
+ export * from './sort-index';
3
+ export * from './sort-order-errors';
2
4
  export * from './components';
3
5
  export * from './document-element-factory';
4
6
  export * from './document-element-property-binding-handler';
package/lib/index.js CHANGED
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
+ __exportStar(require("./sort-index"), exports);
19
+ __exportStar(require("./sort-order-errors"), exports);
18
20
  __exportStar(require("./components"), exports);
19
21
  __exportStar(require("./document-element-factory"), exports);
20
22
  __exportStar(require("./document-element-property-binding-handler"), exports);
@@ -0,0 +1,5 @@
1
+ import { DocumentElement } from './types';
2
+ export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
3
+ export declare function buildKeyBetween(a: string | null, b: string | null): string;
4
+ export declare function buildNKeysBetween(a: string | null, b: string | null, n: number): string[];
5
+ export declare function compareSortIndex(a: DocumentElement, b: DocumentElement): number;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
4
+ exports.buildKeyBetween = buildKeyBetween;
5
+ exports.buildNKeysBetween = buildNKeysBetween;
6
+ exports.compareSortIndex = compareSortIndex;
7
+ const fractional_indexing_1 = require("fractional-indexing");
8
+ function allElementsHaveSortIndex(elements) {
9
+ return elements.every((element) => typeof element.sortIndex === 'string' &&
10
+ element.sortIndex.length > 0);
11
+ }
12
+ function buildKeyBetween(a, b) {
13
+ return (0, fractional_indexing_1.generateKeyBetween)(a, b);
14
+ }
15
+ function buildNKeysBetween(a, b, n) {
16
+ return (0, fractional_indexing_1.generateNKeysBetween)(a, b, n);
17
+ }
18
+ function compareSortIndex(a, b) {
19
+ var _a, _b, _c, _d;
20
+ const ai = (_a = a.sortIndex) !== null && _a !== void 0 ? _a : '';
21
+ const bi = (_b = b.sortIndex) !== null && _b !== void 0 ? _b : '';
22
+ if (ai !== bi)
23
+ return ai < bi ? -1 : 1;
24
+ const aid = (_c = a.id) !== null && _c !== void 0 ? _c : '';
25
+ const bid = (_d = b.id) !== null && _d !== void 0 ? _d : '';
26
+ return aid === bid ? 0 : aid < bid ? -1 : 1;
27
+ }
@@ -0,0 +1,6 @@
1
+ export declare enum SortOrderErrorCode {
2
+ SORT_MIGRATION_IN_PROGRESS = "SORT_MIGRATION_IN_PROGRESS"
3
+ }
4
+ export declare enum SortOrderErrorMessage {
5
+ SORT_MIGRATION_IN_PROGRESS = "Sort order is being migrated for this document; editing is briefly locked"
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SortOrderErrorMessage = exports.SortOrderErrorCode = void 0;
4
+ var SortOrderErrorCode;
5
+ (function (SortOrderErrorCode) {
6
+ SortOrderErrorCode["SORT_MIGRATION_IN_PROGRESS"] = "SORT_MIGRATION_IN_PROGRESS";
7
+ })(SortOrderErrorCode || (exports.SortOrderErrorCode = SortOrderErrorCode = {}));
8
+ var SortOrderErrorMessage;
9
+ (function (SortOrderErrorMessage) {
10
+ SortOrderErrorMessage["SORT_MIGRATION_IN_PROGRESS"] = "Sort order is being migrated for this document; editing is briefly locked";
11
+ })(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
@@ -17,6 +17,7 @@ export interface DocumentElement extends Document {
17
17
  id?: string;
18
18
  specifiedId?: string;
19
19
  documentId?: string;
20
+ sortIndex?: string;
20
21
  type?: string;
21
22
  rotate?: RotationDefinition;
22
23
  scale?: ScaleTransformation;
@@ -5,6 +5,7 @@ export interface ImportReferenceDetail {
5
5
  importedFileReference?: string;
6
6
  }
7
7
  export type DocumentWriteMode = 'transactional' | 'legacy';
8
+ export type DocumentSortMode = 'array' | 'elementIndexing' | 'migrating';
8
9
  export interface Document {
9
10
  id?: string;
10
11
  name?: string;
@@ -25,4 +26,5 @@ export interface Document {
25
26
  ownedByReference?: string;
26
27
  writeMode?: DocumentWriteMode;
27
28
  lastSequenceNumber?: number;
29
+ sortMode?: DocumentSortMode;
28
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.11.0",
3
+ "version": "1.12.0-alpha.aad6f60",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -43,6 +43,7 @@
43
43
  "@contrail/document-table": "^1.1.0",
44
44
  "@contrail/document-util": "^1.2.0",
45
45
  "@contrail/types": "^3.4.0",
46
+ "fractional-indexing": "^2.1.0",
46
47
  "reflect-metadata": "^0.1.13"
47
48
  },
48
49
  "peerDependencies": {