@aionbuilders/nabu 0.1.0-alpha.6 → 0.1.0-alpha.8
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.
|
@@ -461,24 +461,29 @@ export class Nabu {
|
|
|
461
461
|
const startFrom = this.selection.start?.from ?? 0;
|
|
462
462
|
const endTo = this.selection.end?.to ?? null;
|
|
463
463
|
|
|
464
|
-
// Find the
|
|
465
|
-
//
|
|
466
|
-
//
|
|
467
|
-
//
|
|
468
|
-
|
|
469
|
-
|
|
464
|
+
// Find the root block(s) to serialize.
|
|
465
|
+
// - Same block: serialize it directly (partial 'both'). Going up to its parent
|
|
466
|
+
// would wrap it in its container (e.g. List), producing a fragment with children
|
|
467
|
+
// that bypasses the inline paste path on the receiving end.
|
|
468
|
+
// - Cross-block: use LCA so nested containers are serialized as a unit.
|
|
469
|
+
// - LCA is null: selection spans root-level blocks, fall back to nabu-level slice.
|
|
470
470
|
/** @type {Block[]} */
|
|
471
471
|
let rootBlocks;
|
|
472
|
-
if (
|
|
473
|
-
rootBlocks = [
|
|
472
|
+
if (startBlock === endBlock) {
|
|
473
|
+
rootBlocks = [startBlock];
|
|
474
474
|
} else {
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
475
|
+
const lca = findLCA(startBlock, endBlock);
|
|
476
|
+
if (lca) {
|
|
477
|
+
rootBlocks = [/** @type {Block} */ (/** @type {any} */ (lca))];
|
|
478
|
+
} else {
|
|
479
|
+
const startRoot = findDirectChildOf(startBlock, this);
|
|
480
|
+
const endRoot = findDirectChildOf(endBlock, this);
|
|
481
|
+
if (!startRoot || !endRoot) return;
|
|
482
|
+
const si = this.children.indexOf(startRoot);
|
|
483
|
+
const ei = this.children.indexOf(endRoot);
|
|
484
|
+
if (si === -1 || ei === -1) return;
|
|
485
|
+
rootBlocks = this.children.slice(si, ei + 1);
|
|
486
|
+
}
|
|
482
487
|
}
|
|
483
488
|
|
|
484
489
|
const lastI = rootBlocks.length - 1;
|
|
@@ -609,16 +614,6 @@ export class Nabu {
|
|
|
609
614
|
const delta = pb.delta || [];
|
|
610
615
|
const len = delta.reduce((s, op) => s + (typeof op.insert === 'string' ? op.insert.length : 0), 0);
|
|
611
616
|
|
|
612
|
-
// If the pasted block has a different type (e.g. heading pasted into paragraph),
|
|
613
|
-
// transform the anchor block in the same transaction before applying the delta.
|
|
614
|
-
if (pb.type !== anchorBlock.type) {
|
|
615
|
-
const data = /** @type {any} */ (anchorBlock.node.data);
|
|
616
|
-
data.set('type', pb.type);
|
|
617
|
-
for (const [key, value] of Object.entries(pb.props || {})) {
|
|
618
|
-
data.set(key, value);
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
617
|
textBehavior.applyDelta([{ retain: offset }, ...delta]);
|
|
623
618
|
this.commit();
|
|
624
619
|
tick().then(() => this.selection.setCursor(anchorBlock, offset + len));
|