@contrail/documents 1.14.1 → 1.15.0-alpha.4626e64
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 +6 -0
- package/lib/document-element-factory.js +18 -17
- package/lib/sort-index.d.ts +1 -0
- package/lib/sort-index.js +21 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +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-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `isValidSortIndex` — whether a value is a usable fractional-indexing key. `fractional-indexing` keeps its own `validateOrderKey` private, so callers that need to check a key before storing it had no way to do so beyond a non-empty-string test. A key that passes that test but breaks the grammar still sorts, so ordering looks fine; the failure surfaces later, when the next insert beside it calls `generateKeyBetween` and throws. One point is stricter than the library: every character must be in the base-62 digit set, since a key holding anything else can sort below the integer part it claims.
|
|
13
|
+
|
|
8
14
|
## [1.14.0] - 2026-07-29
|
|
9
15
|
|
|
10
16
|
### Added
|
|
@@ -38,7 +38,7 @@ class DocumentElementFactory {
|
|
|
38
38
|
let element = this.initNewElement(type);
|
|
39
39
|
element = Object.assign(element, options);
|
|
40
40
|
if (((_a = element === null || element === void 0 ? void 0 : element.elements) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
41
|
-
element.elements = element.elements.map(e => {
|
|
41
|
+
element.elements = element.elements.map((e) => {
|
|
42
42
|
e.id = (0, nanoid_1.nanoid)(16);
|
|
43
43
|
return e;
|
|
44
44
|
});
|
|
@@ -82,7 +82,7 @@ class DocumentElementFactory {
|
|
|
82
82
|
element.elements = elements;
|
|
83
83
|
element.modelBindings = modelBindings;
|
|
84
84
|
if (((_a = element === null || element === void 0 ? void 0 : element.elements) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
85
|
-
element.elements = element.elements.map(e => {
|
|
85
|
+
element.elements = element.elements.map((e) => {
|
|
86
86
|
e.id = (0, nanoid_1.nanoid)(16);
|
|
87
87
|
return e;
|
|
88
88
|
});
|
|
@@ -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;
|
|
94
94
|
const oldIdToNewId = new Map();
|
|
95
95
|
const newElements = [];
|
|
96
96
|
const groupElements = [];
|
|
@@ -115,17 +115,18 @@ class DocumentElementFactory {
|
|
|
115
115
|
}
|
|
116
116
|
const newInnerElements = [];
|
|
117
117
|
if (newElement.type === 'table') {
|
|
118
|
-
const oldChildElements = elements.filter(e => e.tableId === element.id && ['cell', 'column', 'row'].indexOf(e.type) !== -1);
|
|
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(newElement, oldChildElements);
|
|
122
122
|
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
|
|
123
|
+
catch (e) { }
|
|
124
|
+
if (oldChildElements.length > newChildElements.length || oldChildElements.length === 0) {
|
|
125
|
+
telemetry_1.logger.warn({ newElement, oldChildElements, newChildElements }, 'Invalid table element to copy');
|
|
125
126
|
continue;
|
|
126
127
|
}
|
|
127
128
|
newElement = newTableElement;
|
|
128
|
-
newChildElements.forEach(newChildElement => {
|
|
129
|
+
newChildElements.forEach((newChildElement) => {
|
|
129
130
|
var _a;
|
|
130
131
|
let oldChildId;
|
|
131
132
|
if (newChildElement.type === 'row') {
|
|
@@ -137,7 +138,7 @@ class DocumentElementFactory {
|
|
|
137
138
|
else if (newChildElement.type === 'cell') {
|
|
138
139
|
const oldRowId = element.rowIds[newTableElement.rowIds.indexOf(newChildElement.rowId)];
|
|
139
140
|
const oldColumnId = element.columnIds[newTableElement.columnIds.indexOf(newChildElement.columnId)];
|
|
140
|
-
oldChildId = (_a = elements.find(e => e.type === 'cell' && e.rowId === oldRowId && e.columnId === oldColumnId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
141
|
+
oldChildId = (_a = elements.find((e) => e.type === 'cell' && e.rowId === oldRowId && e.columnId === oldColumnId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
141
142
|
}
|
|
142
143
|
newChildElement.documentId = documentId;
|
|
143
144
|
newChildElement.specifiedId = newChildElement.id;
|
|
@@ -158,7 +159,7 @@ class DocumentElementFactory {
|
|
|
158
159
|
newElement.position.x = newElement.position.x + positionOffset.x;
|
|
159
160
|
newElement.position.y = newElement.position.y + positionOffset.y;
|
|
160
161
|
}
|
|
161
|
-
if (['line', 'callout'].includes(newElement.type) && ((
|
|
162
|
+
if (['line', 'callout'].includes(newElement.type) && ((_b = newElement.points) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
162
163
|
newElement.points = newElement.points.map(([x, y]) => [x + positionOffset.x, y + positionOffset.y]);
|
|
163
164
|
}
|
|
164
165
|
}
|
|
@@ -175,18 +176,18 @@ class DocumentElementFactory {
|
|
|
175
176
|
if (DocumentElementFactory.isMask(newElement))
|
|
176
177
|
maskElements.push(newElement);
|
|
177
178
|
}
|
|
178
|
-
groupElements.forEach(groupElement => {
|
|
179
|
+
groupElements.forEach((groupElement) => {
|
|
179
180
|
groupElement.elementIds = groupElement.elementIds
|
|
180
|
-
.map(oldElementId => oldIdToNewId.get(oldElementId))
|
|
181
|
-
.filter(id => !!id);
|
|
181
|
+
.map((oldElementId) => oldIdToNewId.get(oldElementId))
|
|
182
|
+
.filter((id) => !!id);
|
|
182
183
|
});
|
|
183
|
-
maskElements.forEach(maskElement => {
|
|
184
|
+
maskElements.forEach((maskElement) => {
|
|
184
185
|
const newElementIds = maskElement.elementIds
|
|
185
|
-
.map(oldElementId => oldIdToNewId.get(oldElementId))
|
|
186
|
-
.filter(id => !!id);
|
|
186
|
+
.map((oldElementId) => oldIdToNewId.get(oldElementId))
|
|
187
|
+
.filter((id) => !!id);
|
|
187
188
|
maskElement.elementIds = (newElementIds === null || newElementIds === void 0 ? void 0 : newElementIds.length) > 0 ? newElementIds : null;
|
|
188
189
|
});
|
|
189
|
-
calloutElements.forEach(calloutElement => {
|
|
190
|
+
calloutElements.forEach((calloutElement) => {
|
|
190
191
|
if (calloutElement.start.id) {
|
|
191
192
|
const startId = oldIdToNewId.get(calloutElement.start.id);
|
|
192
193
|
if (startId) {
|
package/lib/sort-index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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;
|
|
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[];
|
|
5
6
|
export declare function compareSortIndex(a: DocumentElement, b: DocumentElement): number;
|
package/lib/sort-index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.allElementsHaveSortIndex = allElementsHaveSortIndex;
|
|
4
|
+
exports.isValidSortIndex = isValidSortIndex;
|
|
4
5
|
exports.buildKeyBetween = buildKeyBetween;
|
|
5
6
|
exports.buildNKeysBetween = buildNKeysBetween;
|
|
6
7
|
exports.compareSortIndex = compareSortIndex;
|
|
@@ -9,6 +10,26 @@ function allElementsHaveSortIndex(elements) {
|
|
|
9
10
|
return elements.every((element) => typeof element.sortIndex === 'string' &&
|
|
10
11
|
element.sortIndex.length > 0);
|
|
11
12
|
}
|
|
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
|
+
}
|
|
12
33
|
function buildKeyBetween(a, b) {
|
|
13
34
|
return (0, fractional_indexing_1.generateKeyBetween)(a, b);
|
|
14
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/documents",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0-alpha.4626e64",
|
|
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.1.0",
|
|
44
44
|
"@contrail/document-util": "^1.2.0",
|
|
45
45
|
"@contrail/types": "^3.4.0",
|
|
46
46
|
"fractional-indexing": "^2.1.0",
|