@stesura/wordgard-view 0.4.1 → 0.4.2

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 CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.2 (2026-11-20)
2
+
3
+ ### Bug fixes
4
+
5
+ An editor drawn inside another editor's shape (a sub-editor in an atom's chrome) keeps the user's typing: the outer editor's shape no longer claims the inner editor's DOM changes, which left typed text doubled or threw.
6
+
1
7
  ## 0.4.1 (2026-11-19)
2
8
 
3
9
  ### Bug fixes
package/dist/index.js CHANGED
@@ -582,8 +582,12 @@ var nodePos = (handle, name) => () => {
582
582
  if (!tile) throw new Error(`This ${name} shape or wrapper isn't drawn`);
583
583
  return tile.posBefore;
584
584
  };
585
+ var editorAround = (node) => {
586
+ for (let cur = node; cur; cur = cur.parentNode) if (cur.wgTile?.isDoc) return cur;
587
+ return null;
588
+ };
585
589
  var shapeAround = (node) => {
586
- for (let cur = node; cur; cur = cur.parentNode) {
590
+ for (let cur = node; cur && !cur.wgTile?.isDoc; cur = cur.parentNode) {
587
591
  if (!(cur instanceof Element)) continue;
588
592
  if (contents.has(cur)) return null;
589
593
  const root = roots2.get(cur);
@@ -597,7 +601,7 @@ var contentShape = (dom) => {
597
601
  return handle && contentOf(handle) == dom ? handle : null;
598
602
  };
599
603
  var shapeOf = (node) => {
600
- for (let cur = node; cur; cur = cur.parentNode) {
604
+ for (let cur = node; cur && !cur.wgTile?.isDoc; cur = cur.parentNode) {
601
605
  const handle = cur instanceof Element ? roots2.get(cur) : void 0;
602
606
  if (handle) return handle;
603
607
  }
@@ -606,9 +610,13 @@ var shapeOf = (node) => {
606
610
  var movesContent = (record) => record.target instanceof Element && formerContents.has(record.target) || [...record.addedNodes, ...record.removedNodes].some(
607
611
  (node) => node instanceof Element && everContent.has(node)
608
612
  );
609
- var sortRecords = (records, changed, inline) => {
613
+ var sortRecords = (records, changed, inline, contentDOM) => {
614
+ const own = records.filter((record) => {
615
+ const editor = editorAround(record.target);
616
+ return !editor || editor == contentDOM;
617
+ });
610
618
  const moved = /* @__PURE__ */ new Set();
611
- for (const record of records)
619
+ for (const record of own)
612
620
  if (record.type == "childList" && movesContent(record)) {
613
621
  const handle = shapeOf(record.target);
614
622
  if (handle) moved.add(handle);
@@ -623,10 +631,10 @@ var sortRecords = (records, changed, inline) => {
623
631
  if (!(target instanceof Element)) return true;
624
632
  return !contents.has(target) && !roots2.has(target) && !isDrawnRoot(target) && !shapeAround(target);
625
633
  }
626
- const own = record.type == "childList" && target instanceof Element && contentShape(target);
627
- if (own) {
628
- if (own.root && inline(own.root) && !moved.has(own)) return true;
629
- if (own.root) changed.add(own.root);
634
+ const own2 = record.type == "childList" && target instanceof Element && contentShape(target);
635
+ if (own2) {
636
+ if (own2.root && inline(own2.root) && !moved.has(own2)) return true;
637
+ if (own2.root) changed.add(own2.root);
630
638
  return false;
631
639
  }
632
640
  const handle = shapeAround(target);
@@ -636,7 +644,7 @@ var sortRecords = (records, changed, inline) => {
636
644
  changed.add(handle.root);
637
645
  return false;
638
646
  };
639
- return records.filter((record) => keeps(record) && !ignoresMutation(record));
647
+ return own.filter((record) => keeps(record) && !ignoresMutation(record));
640
648
  };
641
649
 
642
650
  // src/decorations/widgetType.ts
@@ -2727,7 +2735,7 @@ var observeShapes = (wg, queue) => {
2727
2735
  class ShapeObserver extends MutationObserver {
2728
2736
  takeRecords() {
2729
2737
  const settled = settle(wg);
2730
- const kept = sortRecords(super.takeRecords(), changed, holdsText);
2738
+ const kept = sortRecords(super.takeRecords(), changed, holdsText, wg.contentDOM);
2731
2739
  if (settled) rebuildShapes(wg);
2732
2740
  return kept;
2733
2741
  }
@@ -2742,7 +2750,12 @@ var observeShapes = (wg, queue) => {
2742
2750
  }
2743
2751
  const observer = new ShapeObserver((records) => {
2744
2752
  const settled = settle(wg);
2745
- const kept = sortRecords([...records, ...observer.pending()], changed, holdsText);
2753
+ const kept = sortRecords(
2754
+ [...records, ...observer.pending()],
2755
+ changed,
2756
+ holdsText,
2757
+ wg.contentDOM
2758
+ );
2746
2759
  if (kept.length) queue(kept);
2747
2760
  if (settled) rebuildShapes(wg);
2748
2761
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stesura/wordgard-view",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "The core of react-wordgard and vue-wordgard, not for direct use",
5
5
  "keywords": [
6
6
  "wordgard"