@stesura/wordgard-view 0.4.1 → 0.4.3

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,15 @@
1
+ ## 0.4.3 (2026-11-20)
2
+
3
+ ### New features
4
+
5
+ `batch(wg, change)` runs a change and commits what the editor's components draw from it through its renderer before returning; react-wordgard and vue-wordgard re-export it.
6
+
7
+ ## 0.4.2 (2026-11-20)
8
+
9
+ ### Bug fixes
10
+
11
+ 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.
12
+
1
13
  ## 0.4.1 (2026-11-19)
2
14
 
3
15
  ### Bug fixes
package/dist/index.d.ts CHANGED
@@ -343,6 +343,15 @@ type Editor = EditorValue & {
343
343
  flushing: boolean;
344
344
  batch: (change: () => void) => void;
345
345
  };
346
+ /**
347
+ * Runs `change` and commits what the editor's components draw from it before
348
+ * returning, through its renderer (React's `flushSync`, Vue's pending
349
+ * updates): a store set in a bare `wg.scheduleDOMWrite` is in the DOM for the
350
+ * read phase after it. Only the components the editor draws (its document's
351
+ * app context, in Vue) commit. Throws where the renderer can't commit: inside
352
+ * a component's render.
353
+ */
354
+ declare const batch: (wg: Wordgard, change: () => void) => void;
346
355
  declare const editorOf: (wg: Wordgard) => Editor;
347
356
  declare const findEditor: (wg: Wordgard) => EditorValue | undefined;
348
357
 
@@ -408,4 +417,4 @@ declare class RenderedDocTile extends DocTile {
408
417
  declare const viewRoot: (dom: Element | null) => void;
409
418
  declare const drawnRoot: (dom: Element | null) => void;
410
419
 
411
- export { type ChildView, type ComponentShape, type DecoElt, type DecorationHandlers, DocTile, type EditorEvent, type EditorValue, type HostedRenderer, type MarkShape, type NodeCell, type NodeView, type NodeWrappers, RefusedUpdate, RenderedDocTile, RenderedWordgard, type Renderer, type RendererContext, type SelectTypes, type StateField, type Tile, TileFlag, VOID, type Words, type WrapperView, atomRef, attributedWidget, attrsToRecord, cellOf, childViewKeys, createDecorationHandlers, createDocTile, createNodeWrappers, createShapeHandle, createWrapperHandle, decorationRoot, defineMarkShape, defineNodeWrappers, defineShape, defineWidgetType, defineWrapper, drawnRoot, editorOf, findEditor, hostDocTile, idOf, isComponentMark, isComponentShape, isComponentWidget, isComponentWrapper, isTrailingBreak, listenersOf, localTagName, namespaced, nodePos, nodeViewOf, rootReplaced, shapeAttributes, shapeOf, staticCopy, uneditable, viewRoot, widgetRoot };
420
+ export { type ChildView, type ComponentShape, type DecoElt, type DecorationHandlers, DocTile, type EditorEvent, type EditorValue, type HostedRenderer, type MarkShape, type NodeCell, type NodeView, type NodeWrappers, RefusedUpdate, RenderedDocTile, RenderedWordgard, type Renderer, type RendererContext, type SelectTypes, type StateField, type Tile, TileFlag, VOID, type Words, type WrapperView, atomRef, attributedWidget, attrsToRecord, batch, cellOf, childViewKeys, createDecorationHandlers, createDocTile, createNodeWrappers, createShapeHandle, createWrapperHandle, decorationRoot, defineMarkShape, defineNodeWrappers, defineShape, defineWidgetType, defineWrapper, drawnRoot, editorOf, findEditor, hostDocTile, idOf, isComponentMark, isComponentShape, isComponentWidget, isComponentWrapper, isTrailingBreak, listenersOf, localTagName, namespaced, nodePos, nodeViewOf, rootReplaced, shapeAttributes, shapeOf, staticCopy, uneditable, viewRoot, widgetRoot };
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
@@ -1436,6 +1444,7 @@ var notifyFields = (fields, before, after) => {
1436
1444
  for (const listener of pending) listener();
1437
1445
  };
1438
1446
  var editors = /* @__PURE__ */ new WeakMap();
1447
+ var batch = (wg, change) => editorOf(wg).batch(change);
1439
1448
  var editorOf = (wg) => {
1440
1449
  const found = editors.get(wg);
1441
1450
  if (found) return found;
@@ -2727,7 +2736,7 @@ var observeShapes = (wg, queue) => {
2727
2736
  class ShapeObserver extends MutationObserver {
2728
2737
  takeRecords() {
2729
2738
  const settled = settle(wg);
2730
- const kept = sortRecords(super.takeRecords(), changed, holdsText);
2739
+ const kept = sortRecords(super.takeRecords(), changed, holdsText, wg.contentDOM);
2731
2740
  if (settled) rebuildShapes(wg);
2732
2741
  return kept;
2733
2742
  }
@@ -2742,7 +2751,12 @@ var observeShapes = (wg, queue) => {
2742
2751
  }
2743
2752
  const observer = new ShapeObserver((records) => {
2744
2753
  const settled = settle(wg);
2745
- const kept = sortRecords([...records, ...observer.pending()], changed, holdsText);
2754
+ const kept = sortRecords(
2755
+ [...records, ...observer.pending()],
2756
+ changed,
2757
+ holdsText,
2758
+ wg.contentDOM
2759
+ );
2746
2760
  if (kept.length) queue(kept);
2747
2761
  if (settled) rebuildShapes(wg);
2748
2762
  });
@@ -2853,6 +2867,7 @@ export {
2853
2867
  atomRef,
2854
2868
  attributedWidget,
2855
2869
  attrsToRecord,
2870
+ batch,
2856
2871
  cellOf,
2857
2872
  childViewKeys,
2858
2873
  createDecorationHandlers,
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.3",
4
4
  "description": "The core of react-wordgard and vue-wordgard, not for direct use",
5
5
  "keywords": [
6
6
  "wordgard"