@quillmark/svelte 0.32.0 → 0.33.0
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.
|
@@ -37,6 +37,7 @@ export declare function scanContent(s: Scan, anchors?: ContentAnchor[]): Content
|
|
|
37
37
|
export declare function pmToContent(doc: PMNode, anchors?: ContentAnchor[]): Content;
|
|
38
38
|
/**
|
|
39
39
|
* The change taking `oldRt` to `newRt`, or `null` where the two are one value: the store's own
|
|
40
|
-
* `diff`,
|
|
40
|
+
* `diff`, carrying the projection's ids and anchors; a commit swaps the block ids the store does
|
|
41
|
+
* not hold for placeholders (`field.ts`).
|
|
41
42
|
*/
|
|
42
43
|
export declare function lower(oldRt: Content, newRt: Content): Change | null;
|
|
@@ -228,7 +228,8 @@ function mergeMarks(raw) {
|
|
|
228
228
|
// ── Lowering ────────────────────────────────────────────────────────────────
|
|
229
229
|
/**
|
|
230
230
|
* The change taking `oldRt` to `newRt`, or `null` where the two are one value: the store's own
|
|
231
|
-
* `diff`,
|
|
231
|
+
* `diff`, carrying the projection's ids and anchors; a commit swaps the block ids the store does
|
|
232
|
+
* not hold for placeholders (`field.ts`).
|
|
232
233
|
*/
|
|
233
234
|
export function lower(oldRt, newRt) {
|
|
234
235
|
const change = core().diff(oldRt, newRt);
|
package/dist/core/codec/field.js
CHANGED
|
@@ -376,8 +376,12 @@ export function createField(opts) {
|
|
|
376
376
|
doc.replace(at, newRt);
|
|
377
377
|
else {
|
|
378
378
|
const change = lower(oldRt, newRt);
|
|
379
|
-
if (change)
|
|
379
|
+
if (change) {
|
|
380
|
+
const asked = askCore(oldRt, change);
|
|
380
381
|
doc.apply(at, change);
|
|
382
|
+
if (asked.size)
|
|
383
|
+
adopt();
|
|
384
|
+
}
|
|
381
385
|
}
|
|
382
386
|
reconciler.commit(readLeaf(reader, addr));
|
|
383
387
|
return true;
|
|
@@ -409,6 +413,57 @@ export function createField(opts) {
|
|
|
409
413
|
}
|
|
410
414
|
}
|
|
411
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Each block id the projection minted for a block the store does not hold, swapped in
|
|
418
|
+
* `change` for a placeholder the write fills, so the store is the one minter of block ids:
|
|
419
|
+
* placeholder → projected id.
|
|
420
|
+
*/
|
|
421
|
+
function askCore(oldRt, change) {
|
|
422
|
+
const held = new Set(oldRt.blocks.map((b) => b.id));
|
|
423
|
+
const asked = new Map();
|
|
424
|
+
const named = new Map();
|
|
425
|
+
for (const step of change.steps) {
|
|
426
|
+
if (!('splice' in step))
|
|
427
|
+
continue;
|
|
428
|
+
for (const b of step.splice.blocks ?? []) {
|
|
429
|
+
if (held.has(b.id))
|
|
430
|
+
continue;
|
|
431
|
+
const p = `?${asked.size}`;
|
|
432
|
+
asked.set(p, b.id);
|
|
433
|
+
named.set(b.id, p);
|
|
434
|
+
b.id = p;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
for (const step of change.steps)
|
|
438
|
+
if ('setBlock' in step && named.has(step.setBlock.id))
|
|
439
|
+
step.setBlock.id = named.get(step.setBlock.id);
|
|
440
|
+
return asked;
|
|
441
|
+
}
|
|
442
|
+
/** Each block node takes the id the store holds for the block it projects to. */
|
|
443
|
+
function adopt() {
|
|
444
|
+
const stored = readLeaf(reader, addr).blocks.map((b) => b.id);
|
|
445
|
+
const nodes = [];
|
|
446
|
+
view.state.doc.descendants((node, pos) => {
|
|
447
|
+
if (node.type.name === 'island_block') {
|
|
448
|
+
nodes.push({ pos, key: 'block', id: node.attrs.block });
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
if (node.isTextblock || node.type.name === 'horizontal_rule') {
|
|
452
|
+
nodes.push({ pos, key: 'id', id: node.attrs.id });
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
return true;
|
|
456
|
+
});
|
|
457
|
+
if (nodes.length !== stored.length)
|
|
458
|
+
return;
|
|
459
|
+
const tr = view.state.tr;
|
|
460
|
+
nodes.forEach((n, i) => {
|
|
461
|
+
if (n.id !== stored[i])
|
|
462
|
+
tr.setNodeAttribute(n.pos, n.key, stored[i]);
|
|
463
|
+
});
|
|
464
|
+
if (tr.docChanged)
|
|
465
|
+
view.updateState(view.state.apply(tr.setMeta('addToHistory', false)));
|
|
466
|
+
}
|
|
412
467
|
/**
|
|
413
468
|
* A `text` leaf's commit: its whole text through the typed writer, resting the field as that
|
|
414
469
|
* literal string (INVARIANTS §"Inline mode"). The content-object rest form would emit markdown
|