@contrail/documents 1.15.0-alpha.567dcf0 → 1.15.0-alpha.88778e9
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 +3 -6
- package/lib/document-element-factory.js +5 -6
- package/lib/element-order.d.ts +6 -0
- package/lib/element-order.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/sort-index.d.ts +0 -1
- package/lib/sort-index.js +0 -21
- package/lib/sort-order-errors.d.ts +1 -1
- package/lib/sort-order-errors.js +1 -1
- package/lib/types/document.d.ts +7 -2
- package/lib/types/document.js +7 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,15 +5,12 @@ 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.15.0] - 2026-08-
|
|
8
|
+
## [1.15.0] - 2026-08-21
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- `
|
|
13
|
-
|
|
14
|
-
### Changed
|
|
15
|
-
|
|
16
|
-
- `SortOrderErrorMessage.SORT_INDEX_NOT_USABLE` now reads "sortIndex must be a valid fractional-indexing key". The code is unchanged; the old text described only the non-empty-string half of the condition a caller can now check with `isValidSortIndex`.
|
|
12
|
+
- `sortElementsByArrayOrder(elements, sortOrder)` and `assignSortIndexes(orderedElements)` — the two ordering transforms that convert, restore and the document read path had each grown their own copy of. `sortElementsByArrayOrder` puts elements missing from the array last, keeping their relative order.
|
|
13
|
+
- `SORT_MODE` — the named constants for `DocumentSortMode`. `DocumentSortMode` and `DOCUMENT_SORT_MODES` are now derived from it, so the mode values are declared in exactly one place. `DOCUMENT_SORT_MODES` is now `readonly DocumentSortMode[]` rather than a literal tuple; it stays exported because it is the runtime list behind the entity's `@IsIn` validation.
|
|
17
14
|
|
|
18
15
|
## [1.14.0] - 2026-07-29
|
|
19
16
|
|
|
@@ -90,7 +90,7 @@ class DocumentElementFactory {
|
|
|
90
90
|
return element;
|
|
91
91
|
}
|
|
92
92
|
static copyElements(elements, documentId, commonOptions = {}, positionOffset, lastFrameNumber) {
|
|
93
|
-
var _a, _b;
|
|
93
|
+
var _a, _b, _c;
|
|
94
94
|
const oldIdToNewId = new Map();
|
|
95
95
|
const newElements = [];
|
|
96
96
|
const groupElements = [];
|
|
@@ -118,11 +118,10 @@ class DocumentElementFactory {
|
|
|
118
118
|
const oldChildElements = elements.filter((e) => e.tableId === element.id && ['cell', 'column', 'row'].indexOf(e.type) !== -1);
|
|
119
119
|
let newTableElement, newChildElements = [];
|
|
120
120
|
try {
|
|
121
|
-
[newTableElement, ...newChildElements] = document_table_1.TableCopyService.copy(
|
|
121
|
+
[newTableElement, ...newChildElements] = document_table_1.TableCopyService.copy(element, oldChildElements);
|
|
122
122
|
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
|
|
125
|
-
telemetry_1.logger.warn({ newElement, oldChildElements, newChildElements }, 'Invalid table element to copy');
|
|
123
|
+
catch (e) {
|
|
124
|
+
telemetry_1.logger.warn({ element, oldChildElements, newChildElements }, (_b = e === null || e === void 0 ? void 0 : e.message) !== null && _b !== void 0 ? _b : 'Invalid table element to copy');
|
|
126
125
|
continue;
|
|
127
126
|
}
|
|
128
127
|
newElement = newTableElement;
|
|
@@ -159,7 +158,7 @@ class DocumentElementFactory {
|
|
|
159
158
|
newElement.position.x = newElement.position.x + positionOffset.x;
|
|
160
159
|
newElement.position.y = newElement.position.y + positionOffset.y;
|
|
161
160
|
}
|
|
162
|
-
if (['line', 'callout'].includes(newElement.type) && ((
|
|
161
|
+
if (['line', 'callout'].includes(newElement.type) && ((_c = newElement.points) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
163
162
|
newElement.points = newElement.points.map(([x, y]) => [x + positionOffset.x, y + positionOffset.y]);
|
|
164
163
|
}
|
|
165
164
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface OrderableElement {
|
|
2
|
+
id?: string;
|
|
3
|
+
sortIndex?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function sortElementsByArrayOrder<T extends OrderableElement>(elements: T[], sortOrder?: string[]): T[];
|
|
6
|
+
export declare function assignSortIndexes<T extends OrderableElement>(orderedElements: T[]): T[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortElementsByArrayOrder = sortElementsByArrayOrder;
|
|
4
|
+
exports.assignSortIndexes = assignSortIndexes;
|
|
5
|
+
const sort_index_1 = require("./sort-index");
|
|
6
|
+
function sortElementsByArrayOrder(elements, sortOrder) {
|
|
7
|
+
if (!(sortOrder === null || sortOrder === void 0 ? void 0 : sortOrder.length)) {
|
|
8
|
+
return [...elements];
|
|
9
|
+
}
|
|
10
|
+
const positionById = new Map(sortOrder.map((id, index) => [id, index]));
|
|
11
|
+
const unorderedPosition = sortOrder.length;
|
|
12
|
+
return [...elements].sort((a, b) => { var _a, _b; return ((_a = positionById.get(a.id)) !== null && _a !== void 0 ? _a : unorderedPosition) - ((_b = positionById.get(b.id)) !== null && _b !== void 0 ? _b : unorderedPosition); });
|
|
13
|
+
}
|
|
14
|
+
function assignSortIndexes(orderedElements) {
|
|
15
|
+
const sortIndexes = (0, sort_index_1.buildNKeysBetween)(null, null, orderedElements.length);
|
|
16
|
+
return orderedElements.map((element, index) => (Object.assign(Object.assign({}, element), { sortIndex: sortIndexes[index] })));
|
|
17
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./types"), exports);
|
|
18
18
|
__exportStar(require("./sort-index"), exports);
|
|
19
|
+
__exportStar(require("./element-order"), exports);
|
|
19
20
|
__exportStar(require("./sort-order-errors"), exports);
|
|
20
21
|
__exportStar(require("./components"), exports);
|
|
21
22
|
__exportStar(require("./document-element-factory"), exports);
|
package/lib/sort-index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DocumentElement } from './types';
|
|
2
2
|
export declare function allElementsHaveSortIndex(elements: unknown[]): boolean;
|
|
3
|
-
export declare function isValidSortIndex(sortIndex: unknown): sortIndex is string;
|
|
4
3
|
export declare function buildKeyBetween(a: string | null, b: string | null): string;
|
|
5
4
|
export declare function buildNKeysBetween(a: string | null, b: string | null, n: number): string[];
|
|
6
5
|
export declare function compareSortIndex(a: DocumentElement, b: DocumentElement): number;
|
package/lib/sort-index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
|
|
4
|
-
exports.isValidSortIndex = isValidSortIndex;
|
|
5
4
|
exports.buildKeyBetween = buildKeyBetween;
|
|
6
5
|
exports.buildNKeysBetween = buildNKeysBetween;
|
|
7
6
|
exports.compareSortIndex = compareSortIndex;
|
|
@@ -10,26 +9,6 @@ function allElementsHaveSortIndex(elements) {
|
|
|
10
9
|
return elements.every((element) => typeof element.sortIndex === 'string' &&
|
|
11
10
|
element.sortIndex.length > 0);
|
|
12
11
|
}
|
|
13
|
-
const SMALLEST_INTEGER = 'A00000000000000000000000000';
|
|
14
|
-
function getIntegerPartLength(head) {
|
|
15
|
-
if (head >= 'a' && head <= 'z')
|
|
16
|
-
return head.charCodeAt(0) - 'a'.charCodeAt(0) + 2;
|
|
17
|
-
if (head >= 'A' && head <= 'Z')
|
|
18
|
-
return 'Z'.charCodeAt(0) - head.charCodeAt(0) + 2;
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
function isValidSortIndex(sortIndex) {
|
|
22
|
-
if (typeof sortIndex !== 'string' || sortIndex.length === 0)
|
|
23
|
-
return false;
|
|
24
|
-
if (sortIndex === SMALLEST_INTEGER)
|
|
25
|
-
return false;
|
|
26
|
-
if (![...sortIndex].every((character) => fractional_indexing_1.BASE_62_DIGITS.includes(character)))
|
|
27
|
-
return false;
|
|
28
|
-
const integerPartLength = getIntegerPartLength(sortIndex[0]);
|
|
29
|
-
if (integerPartLength === null || integerPartLength > sortIndex.length)
|
|
30
|
-
return false;
|
|
31
|
-
return !sortIndex.slice(integerPartLength).endsWith('0');
|
|
32
|
-
}
|
|
33
12
|
function buildKeyBetween(a, b) {
|
|
34
13
|
return (0, fractional_indexing_1.generateKeyBetween)(a, b);
|
|
35
14
|
}
|
|
@@ -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
|
|
9
|
+
SORT_INDEX_NOT_USABLE = "sortIndex must be a non-empty string"
|
|
10
10
|
}
|
package/lib/sort-order-errors.js
CHANGED
|
@@ -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
|
|
14
|
+
SortOrderErrorMessage["SORT_INDEX_NOT_USABLE"] = "sortIndex must be a non-empty string";
|
|
15
15
|
})(SortOrderErrorMessage || (exports.SortOrderErrorMessage = SortOrderErrorMessage = {}));
|
package/lib/types/document.d.ts
CHANGED
|
@@ -5,8 +5,13 @@ export interface ImportReferenceDetail {
|
|
|
5
5
|
importedFileReference?: string;
|
|
6
6
|
}
|
|
7
7
|
export type DocumentWriteMode = 'transactional' | 'legacy';
|
|
8
|
-
export declare const
|
|
9
|
-
|
|
8
|
+
export declare const SORT_MODE: {
|
|
9
|
+
readonly ARRAY: "array";
|
|
10
|
+
readonly ELEMENT_INDEXING: "elementIndexing";
|
|
11
|
+
readonly MIGRATING: "migrating";
|
|
12
|
+
};
|
|
13
|
+
export type DocumentSortMode = (typeof SORT_MODE)[keyof typeof SORT_MODE];
|
|
14
|
+
export declare const DOCUMENT_SORT_MODES: readonly DocumentSortMode[];
|
|
10
15
|
export interface Document {
|
|
11
16
|
id?: string;
|
|
12
17
|
name?: string;
|
package/lib/types/document.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DOCUMENT_SORT_MODES = void 0;
|
|
4
|
-
exports.
|
|
3
|
+
exports.DOCUMENT_SORT_MODES = exports.SORT_MODE = void 0;
|
|
4
|
+
exports.SORT_MODE = {
|
|
5
|
+
ARRAY: 'array',
|
|
6
|
+
ELEMENT_INDEXING: 'elementIndexing',
|
|
7
|
+
MIGRATING: 'migrating',
|
|
8
|
+
};
|
|
9
|
+
exports.DOCUMENT_SORT_MODES = Object.values(exports.SORT_MODE);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/documents",
|
|
3
|
-
"version": "1.15.0-alpha.
|
|
3
|
+
"version": "1.15.0-alpha.88778e9",
|
|
4
4
|
"description": "Documents library for contrail platform",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@contrail/actions": "^1.0.18",
|
|
43
|
-
"@contrail/document-table": "^1.
|
|
43
|
+
"@contrail/document-table": "^1.2.3",
|
|
44
44
|
"@contrail/document-util": "^1.2.0",
|
|
45
45
|
"@contrail/types": "^3.4.0",
|
|
46
46
|
"fractional-indexing": "^2.1.0",
|