@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.
@@ -3,7 +3,6 @@
3
3
  * @import { Nabu } from './nabu.svelte.js';
4
4
  */
5
5
 
6
- import { start } from 'happy-dom/lib/PropertySymbol.js';
7
6
  import { MegaBlock } from './megablock.svelte.js';
8
7
 
9
8
  /**
@@ -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 Lowest Common Ancestor of startBlock and endBlock.
465
- // If LCA is a block (nested selection inside a container), serialize from that
466
- // block directly — avoids creating phantom ancestor wrappers for unselected content.
467
- // If LCA is null (selection spans root-level blocks), fall back to nabu-level slice.
468
- const lca = findLCA(startBlock, endBlock);
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 (lca) {
473
- rootBlocks = [/** @type {Block} */ (/** @type {any} */ (lca))];
472
+ if (startBlock === endBlock) {
473
+ rootBlocks = [startBlock];
474
474
  } else {
475
- const startRoot = findDirectChildOf(startBlock, this);
476
- const endRoot = findDirectChildOf(endBlock, this);
477
- if (!startRoot || !endRoot) return;
478
- const si = this.children.indexOf(startRoot);
479
- const ei = this.children.indexOf(endRoot);
480
- if (si === -1 || ei === -1) return;
481
- rootBlocks = this.children.slice(si, ei + 1);
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));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aionbuilders/nabu",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.8",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",