jazz-tools 0.13.10 → 0.13.12
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +18 -0
- package/dist/{chunk-NFVKGXSH.js → chunk-GIZWJXSR.js} +51 -418
- package/dist/chunk-GIZWJXSR.js.map +1 -0
- package/dist/coValues/coMap.d.ts +4 -4
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coPlainText.d.ts +7 -0
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/coRichText.d.ts +2 -257
- package/dist/coValues/coRichText.d.ts.map +1 -1
- package/dist/exports.d.ts +1 -1
- package/dist/exports.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/package.json +2 -2
- package/src/coValues/coMap.ts +35 -20
- package/src/coValues/coPlainText.ts +23 -1
- package/src/coValues/coRichText.ts +2 -660
- package/src/exports.ts +1 -7
- package/src/implementation/refs.ts +1 -1
- package/src/implementation/subscriptionScope.ts +2 -2
- package/src/tests/coMap.test.ts +65 -0
- package/src/tests/coPlainText.test.ts +21 -3
- package/dist/chunk-NFVKGXSH.js.map +0 -1
- package/dist/tests/coRichText.test.d.ts +0 -2
- package/dist/tests/coRichText.test.d.ts.map +0 -1
- package/src/tests/coRichText.test.ts +0 -937
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.13.
|
2
|
+
> jazz-tools@0.13.12 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup && pnpm types
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -9,14 +9,14 @@
|
|
9
9
|
[34mCLI[39m Target: es2021
|
10
10
|
[34mCLI[39m Cleaning output folder
|
11
11
|
[34mESM[39m Build start
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[32m1.
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m1.48 KB[39m
|
13
13
|
[32mESM[39m [1mdist/testing.js [22m[32m6.26 KB[39m
|
14
|
-
[32mESM[39m [1mdist/chunk-
|
15
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
14
|
+
[32mESM[39m [1mdist/chunk-GIZWJXSR.js [22m[32m118.19 KB[39m
|
15
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m258.00 B[39m
|
16
16
|
[32mESM[39m [1mdist/testing.js.map [22m[32m12.37 KB[39m
|
17
|
-
[32mESM[39m [1mdist/chunk-
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
17
|
+
[32mESM[39m [1mdist/chunk-GIZWJXSR.js.map [22m[32m277.09 KB[39m
|
18
|
+
[32mESM[39m ⚡️ Build success in 64ms
|
19
19
|
|
20
|
-
> jazz-tools@0.13.
|
20
|
+
> jazz-tools@0.13.12 types /home/runner/_work/jazz/jazz/packages/jazz-tools
|
21
21
|
> tsc --outDir dist
|
22
22
|
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# jazz-tools
|
2
2
|
|
3
|
+
## 0.13.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 4547525: Skip non-schema related keys when calling CoMap.toJSON
|
8
|
+
- Updated dependencies [65719f2]
|
9
|
+
- cojson@0.13.12
|
10
|
+
|
11
|
+
## 0.13.11
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- 17273a6: CoRichText released
|
16
|
+
- Updated dependencies [17273a6]
|
17
|
+
- Updated dependencies [3396ed4]
|
18
|
+
- Updated dependencies [267ea4c]
|
19
|
+
- cojson@0.13.11
|
20
|
+
|
3
21
|
## 0.13.10
|
4
22
|
|
5
23
|
### Patch Changes
|
@@ -323,7 +323,7 @@ var Ref = class _Ref {
|
|
323
323
|
const entry = node.coValuesStore.get(
|
324
324
|
this.id
|
325
325
|
);
|
326
|
-
if (entry.
|
326
|
+
if (entry.highLevelState === "available") {
|
327
327
|
return new _Ref(this.id, this.controlledAccount, this.schema).value;
|
328
328
|
}
|
329
329
|
return void 0;
|
@@ -592,8 +592,8 @@ var SubscriptionScope = class {
|
|
592
592
|
};
|
593
593
|
function loadCoValue(node, id, callback, syncResolution) {
|
594
594
|
const entry = node.coValuesStore.get(id);
|
595
|
-
if (entry.
|
596
|
-
callback(entry.
|
595
|
+
if (entry.isAvailable() && syncResolution) {
|
596
|
+
callback(entry.core);
|
597
597
|
} else {
|
598
598
|
void node.loadCoValueCore(id).then((core) => {
|
599
599
|
callback(core);
|
@@ -1525,30 +1525,38 @@ var _CoMap = class _CoMap extends CoValueBase {
|
|
1525
1525
|
* @category Content
|
1526
1526
|
*/
|
1527
1527
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
1528
|
-
toJSON(_key,
|
1529
|
-
const
|
1528
|
+
toJSON(_key, processedValues) {
|
1529
|
+
const result = {
|
1530
|
+
id: this.id,
|
1531
|
+
_type: this._type
|
1532
|
+
};
|
1533
|
+
for (const key of this._raw.keys()) {
|
1530
1534
|
const tKey = key;
|
1531
1535
|
const descriptor = this._schema[tKey] || this._schema[ItemsSym];
|
1536
|
+
if (!descriptor) {
|
1537
|
+
continue;
|
1538
|
+
}
|
1532
1539
|
if (descriptor == "json" || "encoded" in descriptor) {
|
1533
|
-
|
1540
|
+
result[key] = this._raw.get(key);
|
1534
1541
|
} else if (isRefEncoded(descriptor)) {
|
1535
|
-
|
1536
|
-
|
1542
|
+
const id = this._raw.get(key);
|
1543
|
+
if (processedValues?.includes(id) || id === this.id) {
|
1544
|
+
result[key] = { _circular: id };
|
1545
|
+
continue;
|
1546
|
+
}
|
1547
|
+
const ref2 = this[tKey];
|
1548
|
+
if (ref2 && typeof ref2 === "object" && "toJSON" in ref2 && typeof ref2.toJSON === "function") {
|
1549
|
+
const jsonedRef = ref2.toJSON(tKey, [
|
1550
|
+
...processedValues || [],
|
1551
|
+
this.id
|
1552
|
+
]);
|
1553
|
+
result[key] = jsonedRef;
|
1537
1554
|
}
|
1538
|
-
const jsonedRef = this[tKey]?.toJSON(tKey, [
|
1539
|
-
...seenAbove || [],
|
1540
|
-
this.id
|
1541
|
-
]);
|
1542
|
-
return [key, jsonedRef];
|
1543
1555
|
} else {
|
1544
|
-
|
1556
|
+
result[key] = void 0;
|
1545
1557
|
}
|
1546
|
-
}
|
1547
|
-
return
|
1548
|
-
id: this.id,
|
1549
|
-
_type: this._type,
|
1550
|
-
...Object.fromEntries(jsonedFields)
|
1551
|
-
};
|
1558
|
+
}
|
1559
|
+
return result;
|
1552
1560
|
}
|
1553
1561
|
[inspect]() {
|
1554
1562
|
return this.toJSON();
|
@@ -3215,6 +3223,7 @@ import {
|
|
3215
3223
|
RawAccount as RawAccount7,
|
3216
3224
|
stringifyOpID
|
3217
3225
|
} from "cojson";
|
3226
|
+
import { calcPatch as calcPatch2 } from "fast-myers-diff";
|
3218
3227
|
var CoPlainText = class extends String {
|
3219
3228
|
get _owner() {
|
3220
3229
|
return this._raw.group instanceof RawAccount7 ? Account.fromRaw(this._raw.group) : Group.fromRaw(this._raw.group);
|
@@ -3223,7 +3232,7 @@ var CoPlainText = class extends String {
|
|
3223
3232
|
return Account.fromNode(this._raw.core.node);
|
3224
3233
|
}
|
3225
3234
|
constructor(options) {
|
3226
|
-
super();
|
3235
|
+
super("fromRaw" in options ? options.fromRaw.toString() : options.text);
|
3227
3236
|
let raw;
|
3228
3237
|
if ("fromRaw" in options) {
|
3229
3238
|
raw = options.fromRaw;
|
@@ -3254,6 +3263,9 @@ var CoPlainText = class extends String {
|
|
3254
3263
|
[inspect]() {
|
3255
3264
|
return this.toJSON();
|
3256
3265
|
}
|
3266
|
+
insertBefore(idx, text) {
|
3267
|
+
this._raw.insertBefore(idx, text);
|
3268
|
+
}
|
3257
3269
|
insertAfter(idx, text) {
|
3258
3270
|
this._raw.insertAfter(idx, text);
|
3259
3271
|
}
|
@@ -3275,6 +3287,22 @@ var CoPlainText = class extends String {
|
|
3275
3287
|
static fromRaw(raw) {
|
3276
3288
|
return new this({ fromRaw: raw });
|
3277
3289
|
}
|
3290
|
+
/**
|
3291
|
+
* Apply text, modifying the text in place. Calculates the diff and applies it to the CoValue.
|
3292
|
+
*
|
3293
|
+
* @category Mutation
|
3294
|
+
*/
|
3295
|
+
applyDiff(other) {
|
3296
|
+
const current = this._raw.toString();
|
3297
|
+
for (const [from, to, insert] of [...calcPatch2(current, other)].reverse()) {
|
3298
|
+
if (to > from) {
|
3299
|
+
this.deleteRange({ from, to });
|
3300
|
+
}
|
3301
|
+
if (insert.length > 0) {
|
3302
|
+
this.insertBefore(from, insert);
|
3303
|
+
}
|
3304
|
+
}
|
3305
|
+
}
|
3278
3306
|
/**
|
3279
3307
|
* Load a `CoPlainText` with a given ID, as a given account.
|
3280
3308
|
*
|
@@ -3302,401 +3330,7 @@ var CoPlainText = class extends String {
|
|
3302
3330
|
};
|
3303
3331
|
|
3304
3332
|
// src/coValues/coRichText.ts
|
3305
|
-
var
|
3306
|
-
constructor() {
|
3307
|
-
super(...arguments);
|
3308
|
-
this.startAfter = co.json();
|
3309
|
-
this.startBefore = co.json();
|
3310
|
-
this.endAfter = co.json();
|
3311
|
-
this.endBefore = co.json();
|
3312
|
-
this.tag = co.string;
|
3313
|
-
}
|
3314
|
-
/**
|
3315
|
-
* Validates and clamps mark positions to ensure they are in the correct order
|
3316
|
-
* @returns Normalized positions or null if invalid
|
3317
|
-
*/
|
3318
|
-
validatePositions(textLength, idxAfter, idxBefore) {
|
3319
|
-
if (!textLength) {
|
3320
|
-
console.error("Cannot validate positions for empty text");
|
3321
|
-
return null;
|
3322
|
-
}
|
3323
|
-
const positions = {
|
3324
|
-
startAfter: this.startAfter ? idxBefore(this.startAfter) ?? 0 : 0,
|
3325
|
-
startBefore: this.startBefore ? idxAfter(this.startBefore) ?? 0 : 0,
|
3326
|
-
endAfter: this.endAfter ? idxBefore(this.endAfter) ?? textLength : textLength,
|
3327
|
-
endBefore: this.endBefore ? idxAfter(this.endBefore) ?? textLength : textLength
|
3328
|
-
};
|
3329
|
-
return {
|
3330
|
-
startAfter: Math.max(0, positions.startAfter),
|
3331
|
-
startBefore: Math.max(positions.startAfter + 1, positions.startBefore),
|
3332
|
-
endAfter: Math.min(textLength - 1, positions.endAfter),
|
3333
|
-
endBefore: Math.min(textLength, positions.endBefore)
|
3334
|
-
};
|
3335
|
-
}
|
3336
|
-
};
|
3337
|
-
var CoRichText = class extends CoMap {
|
3338
|
-
constructor() {
|
3339
|
-
super(...arguments);
|
3340
|
-
this.text = co.ref(CoPlainText);
|
3341
|
-
this.marks = co.ref(CoList.Of(co.ref(Mark)));
|
3342
|
-
}
|
3343
|
-
/**
|
3344
|
-
* Create a CoRichText from plain text.
|
3345
|
-
*/
|
3346
|
-
static createFromPlainText(text, options) {
|
3347
|
-
return this.create(
|
3348
|
-
{
|
3349
|
-
text: CoPlainText.create(text, { owner: options.owner }),
|
3350
|
-
marks: CoList.Of(co.ref(Mark)).create([], {
|
3351
|
-
owner: options.owner
|
3352
|
-
})
|
3353
|
-
},
|
3354
|
-
{ owner: options.owner }
|
3355
|
-
);
|
3356
|
-
}
|
3357
|
-
/**
|
3358
|
-
* Create a CoRichText from plain text and a mark.
|
3359
|
-
*/
|
3360
|
-
static createFromPlainTextAndMark(text, WrapIn, extraArgs, options) {
|
3361
|
-
const richtext = this.createFromPlainText(text, options);
|
3362
|
-
richtext.insertMark(0, text.length, WrapIn, extraArgs);
|
3363
|
-
return richtext;
|
3364
|
-
}
|
3365
|
-
/**
|
3366
|
-
* Insert text at a specific index.
|
3367
|
-
*/
|
3368
|
-
insertAfter(idx, text) {
|
3369
|
-
if (!this.text)
|
3370
|
-
throw new Error("Cannot insert into a CoRichText without loaded text");
|
3371
|
-
this.text.insertAfter(idx, text);
|
3372
|
-
}
|
3373
|
-
/**
|
3374
|
-
* Delete a range of text.
|
3375
|
-
*/
|
3376
|
-
deleteRange(range) {
|
3377
|
-
if (!this.text)
|
3378
|
-
throw new Error("Cannot delete from a CoRichText without loaded text");
|
3379
|
-
this.text.deleteRange(range);
|
3380
|
-
}
|
3381
|
-
/**
|
3382
|
-
* Get the position of a specific index.
|
3383
|
-
*/
|
3384
|
-
posBefore(idx) {
|
3385
|
-
if (!this.text)
|
3386
|
-
throw new Error(
|
3387
|
-
"Cannot get posBefore in a CoRichText without loaded text"
|
3388
|
-
);
|
3389
|
-
return this.text.posBefore(idx);
|
3390
|
-
}
|
3391
|
-
/**
|
3392
|
-
* Get the position of a specific index.
|
3393
|
-
*/
|
3394
|
-
posAfter(idx) {
|
3395
|
-
if (!this.text)
|
3396
|
-
throw new Error(
|
3397
|
-
"Cannot get posAfter in a CoRichText without loaded text"
|
3398
|
-
);
|
3399
|
-
return this.text.posAfter(idx);
|
3400
|
-
}
|
3401
|
-
/**
|
3402
|
-
* Get the index of a specific position.
|
3403
|
-
*/
|
3404
|
-
idxBefore(pos) {
|
3405
|
-
if (!this.text)
|
3406
|
-
throw new Error(
|
3407
|
-
"Cannot get idxBefore in a CoRichText without loaded text"
|
3408
|
-
);
|
3409
|
-
return this.text.idxBefore(pos);
|
3410
|
-
}
|
3411
|
-
/**
|
3412
|
-
* Get the index of a specific position.
|
3413
|
-
*/
|
3414
|
-
idxAfter(pos) {
|
3415
|
-
if (!this.text)
|
3416
|
-
throw new Error(
|
3417
|
-
"Cannot get idxAfter in a CoRichText without loaded text"
|
3418
|
-
);
|
3419
|
-
return this.text.idxAfter(pos);
|
3420
|
-
}
|
3421
|
-
/**
|
3422
|
-
* Insert a mark at a specific range.
|
3423
|
-
*/
|
3424
|
-
insertMark(start, end, RangeClass, extraArgs, options) {
|
3425
|
-
if (!this.text || !this.marks) {
|
3426
|
-
throw new Error("Cannot insert a range without loaded ranges");
|
3427
|
-
}
|
3428
|
-
const textLength = this.length;
|
3429
|
-
start = Math.max(start, 0);
|
3430
|
-
end = Math.min(end, textLength);
|
3431
|
-
const owner = options?.markOwner || this._owner;
|
3432
|
-
if (!owner) {
|
3433
|
-
throw new Error("No owner specified for mark");
|
3434
|
-
}
|
3435
|
-
const range = RangeClass.create(
|
3436
|
-
{
|
3437
|
-
...extraArgs,
|
3438
|
-
startAfter: this.posBefore(start),
|
3439
|
-
startBefore: this.posAfter(start),
|
3440
|
-
endAfter: this.posBefore(end),
|
3441
|
-
endBefore: this.posAfter(end)
|
3442
|
-
},
|
3443
|
-
{ owner }
|
3444
|
-
);
|
3445
|
-
this.marks.push(range);
|
3446
|
-
}
|
3447
|
-
/**
|
3448
|
-
* Remove a mark at a specific range.
|
3449
|
-
*/
|
3450
|
-
removeMark(start, end, RangeClass, options) {
|
3451
|
-
if (!this.marks) {
|
3452
|
-
throw new Error("Cannot remove marks without loaded marks");
|
3453
|
-
}
|
3454
|
-
const resolvedMarks = this.resolveMarks();
|
3455
|
-
for (const mark of resolvedMarks) {
|
3456
|
-
if (mark.endBefore < start || mark.startAfter > end) {
|
3457
|
-
continue;
|
3458
|
-
}
|
3459
|
-
if (options.tag && mark.sourceMark.tag !== options.tag) {
|
3460
|
-
continue;
|
3461
|
-
}
|
3462
|
-
const markIndex = this.marks.findIndex((m) => m === mark.sourceMark);
|
3463
|
-
if (markIndex === -1) {
|
3464
|
-
continue;
|
3465
|
-
}
|
3466
|
-
if (mark.startBefore >= start && mark.endAfter <= end) {
|
3467
|
-
this.marks.splice(markIndex, 1);
|
3468
|
-
continue;
|
3469
|
-
}
|
3470
|
-
if (mark.startBefore < start && mark.endAfter >= start && mark.endAfter <= end) {
|
3471
|
-
const endAfterPos = this.posBefore(start);
|
3472
|
-
const endBeforePos = this.posBefore(start);
|
3473
|
-
if (endAfterPos && endBeforePos) {
|
3474
|
-
mark.sourceMark.endAfter = endAfterPos;
|
3475
|
-
mark.sourceMark.endBefore = endBeforePos;
|
3476
|
-
}
|
3477
|
-
continue;
|
3478
|
-
}
|
3479
|
-
if (mark.startBefore >= start && mark.startBefore <= end && mark.endAfter > end) {
|
3480
|
-
const startAfterPos = this.posAfter(end);
|
3481
|
-
const startBeforePos = this.posAfter(end);
|
3482
|
-
if (startAfterPos && startBeforePos) {
|
3483
|
-
mark.sourceMark.startAfter = startAfterPos;
|
3484
|
-
mark.sourceMark.startBefore = startBeforePos;
|
3485
|
-
}
|
3486
|
-
continue;
|
3487
|
-
}
|
3488
|
-
if (mark.startBefore <= start && mark.endAfter >= end) {
|
3489
|
-
const endAfterPos = this.posBefore(start);
|
3490
|
-
const endBeforePos = this.posBefore(start);
|
3491
|
-
if (endAfterPos && endBeforePos) {
|
3492
|
-
mark.sourceMark.endAfter = endAfterPos;
|
3493
|
-
mark.sourceMark.endBefore = endBeforePos;
|
3494
|
-
}
|
3495
|
-
this.insertMark(
|
3496
|
-
end + 1,
|
3497
|
-
mark.endBefore,
|
3498
|
-
RangeClass,
|
3499
|
-
// @ts-ignore Some Typescript versions flag this as an error
|
3500
|
-
{},
|
3501
|
-
{
|
3502
|
-
markOwner: mark.sourceMark._owner || this._owner
|
3503
|
-
}
|
3504
|
-
);
|
3505
|
-
continue;
|
3506
|
-
}
|
3507
|
-
}
|
3508
|
-
}
|
3509
|
-
/**
|
3510
|
-
* Resolve the positions of all marks.
|
3511
|
-
*/
|
3512
|
-
resolveMarks() {
|
3513
|
-
if (!this.text || !this.marks) {
|
3514
|
-
throw new Error("Cannot resolve ranges without loaded text and ranges");
|
3515
|
-
}
|
3516
|
-
const textLength = this.length;
|
3517
|
-
return this.marks.flatMap((mark) => {
|
3518
|
-
if (!mark) return [];
|
3519
|
-
const positions = mark.validatePositions(
|
3520
|
-
textLength,
|
3521
|
-
(pos) => this.idxAfter(pos),
|
3522
|
-
(pos) => this.idxBefore(pos)
|
3523
|
-
);
|
3524
|
-
if (!positions) return [];
|
3525
|
-
return [
|
3526
|
-
{
|
3527
|
-
sourceMark: mark,
|
3528
|
-
...positions,
|
3529
|
-
tag: mark.tag
|
3530
|
-
}
|
3531
|
-
];
|
3532
|
-
});
|
3533
|
-
}
|
3534
|
-
/**
|
3535
|
-
* Resolve and diffuse the positions of all marks.
|
3536
|
-
*/
|
3537
|
-
resolveAndDiffuseMarks() {
|
3538
|
-
return this.resolveMarks().flatMap((range) => [
|
3539
|
-
...range.startAfter < range.startBefore - 1 ? [
|
3540
|
-
{
|
3541
|
-
start: range.startAfter,
|
3542
|
-
end: range.startBefore - 1,
|
3543
|
-
side: "uncertainStart",
|
3544
|
-
sourceMark: range.sourceMark
|
3545
|
-
}
|
3546
|
-
] : [],
|
3547
|
-
{
|
3548
|
-
start: range.startBefore - 1,
|
3549
|
-
end: range.endAfter + 1,
|
3550
|
-
side: "certainMiddle",
|
3551
|
-
sourceMark: range.sourceMark
|
3552
|
-
},
|
3553
|
-
...range.endAfter + 1 < range.endBefore ? [
|
3554
|
-
{
|
3555
|
-
start: range.endAfter + 1,
|
3556
|
-
end: range.endBefore,
|
3557
|
-
side: "uncertainEnd",
|
3558
|
-
sourceMark: range.sourceMark
|
3559
|
-
}
|
3560
|
-
] : []
|
3561
|
-
]);
|
3562
|
-
}
|
3563
|
-
/**
|
3564
|
-
* Resolve, diffuse, and focus the positions of all marks.
|
3565
|
-
*/
|
3566
|
-
resolveAndDiffuseAndFocusMarks() {
|
3567
|
-
return this.resolveAndDiffuseMarks().filter(
|
3568
|
-
(range) => range.side === "certainMiddle"
|
3569
|
-
);
|
3570
|
-
}
|
3571
|
-
/**
|
3572
|
-
* Convert a CoRichText to a tree structure useful for client libraries.
|
3573
|
-
*/
|
3574
|
-
toTree(tagPrecedence) {
|
3575
|
-
const ranges = this.resolveAndDiffuseAndFocusMarks();
|
3576
|
-
const text = this.text?.toString() || "";
|
3577
|
-
let currentNodes = [
|
3578
|
-
{
|
3579
|
-
type: "leaf",
|
3580
|
-
start: 0,
|
3581
|
-
end: text.length
|
3582
|
-
}
|
3583
|
-
];
|
3584
|
-
const rangesSortedLowToHighPrecedence = ranges.sort((a, b) => {
|
3585
|
-
const aPrecedence = tagPrecedence.indexOf(a.sourceMark.tag);
|
3586
|
-
const bPrecedence = tagPrecedence.indexOf(b.sourceMark.tag);
|
3587
|
-
return bPrecedence - aPrecedence;
|
3588
|
-
});
|
3589
|
-
for (const range of rangesSortedLowToHighPrecedence) {
|
3590
|
-
const newNodes = currentNodes.flatMap((node) => {
|
3591
|
-
const [before, inOrAfter] = splitNode(node, range.start);
|
3592
|
-
const [inside, after] = inOrAfter ? splitNode(inOrAfter, range.end) : [void 0, void 0];
|
3593
|
-
return [
|
3594
|
-
...before ? [before] : [],
|
3595
|
-
...inside ? [
|
3596
|
-
{
|
3597
|
-
type: "node",
|
3598
|
-
tag: range.sourceMark.tag,
|
3599
|
-
start: inside.start,
|
3600
|
-
end: inside.end,
|
3601
|
-
children: [inside]
|
3602
|
-
}
|
3603
|
-
] : [],
|
3604
|
-
...after ? [after] : []
|
3605
|
-
];
|
3606
|
-
});
|
3607
|
-
currentNodes = newNodes;
|
3608
|
-
}
|
3609
|
-
return {
|
3610
|
-
type: "node",
|
3611
|
-
tag: "root",
|
3612
|
-
start: 0,
|
3613
|
-
end: text.length,
|
3614
|
-
children: currentNodes
|
3615
|
-
};
|
3616
|
-
}
|
3617
|
-
get length() {
|
3618
|
-
return this.text?.toString().length || 0;
|
3619
|
-
}
|
3620
|
-
/**
|
3621
|
-
* Convert a CoRichText to plain text.
|
3622
|
-
*/
|
3623
|
-
toString() {
|
3624
|
-
if (!this.text) return "";
|
3625
|
-
return this.text.toString();
|
3626
|
-
}
|
3627
|
-
};
|
3628
|
-
function splitNode(node, at) {
|
3629
|
-
if (node.type === "leaf") {
|
3630
|
-
return [
|
3631
|
-
at > node.start ? {
|
3632
|
-
type: "leaf",
|
3633
|
-
start: node.start,
|
3634
|
-
end: Math.min(at, node.end)
|
3635
|
-
} : void 0,
|
3636
|
-
at < node.end ? {
|
3637
|
-
type: "leaf",
|
3638
|
-
start: Math.max(at, node.start),
|
3639
|
-
end: node.end
|
3640
|
-
} : void 0
|
3641
|
-
];
|
3642
|
-
} else {
|
3643
|
-
const children = node.children;
|
3644
|
-
return [
|
3645
|
-
at > node.start ? {
|
3646
|
-
type: "node",
|
3647
|
-
tag: node.tag,
|
3648
|
-
start: node.start,
|
3649
|
-
end: Math.min(at, node.end),
|
3650
|
-
children: children.map((child) => splitNode(child, at)[0]).filter((c) => !!c)
|
3651
|
-
} : void 0,
|
3652
|
-
at < node.end ? {
|
3653
|
-
type: "node",
|
3654
|
-
tag: node.tag,
|
3655
|
-
start: Math.max(at, node.start),
|
3656
|
-
end: node.end,
|
3657
|
-
children: children.map((child) => splitNode(child, at)[1]).filter((c) => !!c)
|
3658
|
-
} : void 0
|
3659
|
-
];
|
3660
|
-
}
|
3661
|
-
}
|
3662
|
-
var Heading = class extends Mark {
|
3663
|
-
constructor() {
|
3664
|
-
super(...arguments);
|
3665
|
-
this.tag = co.literal("heading");
|
3666
|
-
this.level = co.number;
|
3667
|
-
}
|
3668
|
-
};
|
3669
|
-
var Paragraph = class extends Mark {
|
3670
|
-
constructor() {
|
3671
|
-
super(...arguments);
|
3672
|
-
this.tag = co.literal("paragraph");
|
3673
|
-
}
|
3674
|
-
};
|
3675
|
-
var Link = class extends Mark {
|
3676
|
-
constructor() {
|
3677
|
-
super(...arguments);
|
3678
|
-
this.tag = co.literal("link");
|
3679
|
-
this.url = co.string;
|
3680
|
-
}
|
3681
|
-
};
|
3682
|
-
var Strong = class extends Mark {
|
3683
|
-
constructor() {
|
3684
|
-
super(...arguments);
|
3685
|
-
this.tag = co.literal("strong");
|
3686
|
-
}
|
3687
|
-
};
|
3688
|
-
var Em = class extends Mark {
|
3689
|
-
constructor() {
|
3690
|
-
super(...arguments);
|
3691
|
-
this.tag = co.literal("em");
|
3692
|
-
}
|
3693
|
-
};
|
3694
|
-
var Marks = {
|
3695
|
-
Heading,
|
3696
|
-
Paragraph,
|
3697
|
-
Link,
|
3698
|
-
Strong,
|
3699
|
-
Em
|
3333
|
+
var CoRichText = class extends CoPlainText {
|
3700
3334
|
};
|
3701
3335
|
|
3702
3336
|
// src/coValues/extensions/imageDef.ts
|
@@ -4442,7 +4076,6 @@ export {
|
|
4442
4076
|
Group,
|
4443
4077
|
CoPlainText,
|
4444
4078
|
CoRichText,
|
4445
|
-
Marks,
|
4446
4079
|
ImageDefinition,
|
4447
4080
|
SchemaUnion,
|
4448
4081
|
KvStoreContext,
|
@@ -4456,4 +4089,4 @@ export {
|
|
4456
4089
|
consumeInviteLink
|
4457
4090
|
};
|
4458
4091
|
/* istanbul ignore file -- @preserve */
|
4459
|
-
//# sourceMappingURL=chunk-
|
4092
|
+
//# sourceMappingURL=chunk-GIZWJXSR.js.map
|