@domternal/core 0.7.4 → 0.8.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.
package/dist/index.d.cts CHANGED
@@ -814,6 +814,15 @@ declare class ExtensionManager {
814
814
  * while letting users override with explicitly configured versions.
815
815
  */
816
816
  private deduplicateExtensions;
817
+ /**
818
+ * Clone every extension so this editor owns its instances. Extensions hold
819
+ * per-editor mutable state (`editor`, plus the `nodeType`/`markType` getters
820
+ * derived from it), and the same extension object is commonly reused across
821
+ * editors (one shared `extensions` array). Without cloning, binding a later
822
+ * editor clobbers an earlier one: its list `Enter` then falls back to a plain
823
+ * block split, dropping an indented "child" paragraph instead of a new `<li>`.
824
+ */
825
+ private cloneExtensions;
817
826
  /**
818
827
  * Sorts extensions by priority (higher priority first)
819
828
  * Default priority is 100
@@ -2657,17 +2666,18 @@ interface InsertAsListItemChildArgs {
2657
2666
  * matching the Tab keyboard behaviour ("indent into last item").
2658
2667
  */
2659
2668
  targetItemPos?: number;
2660
- /** Block node to append as the LAST child of the target item. */
2669
+ /** Block node to insert. */
2661
2670
  blockNode: Node$1;
2662
- /**
2663
- * Optional source range to delete in the SAME transaction (when
2664
- * MOVING an existing block instead of creating a new one). Position
2665
- * math handles source-before-vs-after-target ordering automatically.
2666
- */
2671
+ /** Optional source range to delete in the same tr (turns insert into a MOVE). */
2667
2672
  sourceRange?: {
2668
2673
  from: number;
2669
2674
  to: number;
2670
2675
  };
2676
+ /**
2677
+ * Child index to insert at. Clamped to `>= 1` (index 0 is the label
2678
+ * paragraph). Omitted or `>= childCount` appends as the last child.
2679
+ */
2680
+ childIndex?: number;
2671
2681
  }
2672
2682
  interface InsertAsListItemChildResult {
2673
2683
  /** True when schema accepted the insertion and `tr` was mutated. */
@@ -2680,11 +2690,10 @@ interface InsertAsListItemChildResult {
2680
2690
  insertedAt?: number;
2681
2691
  }
2682
2692
  /**
2683
- * Insert `blockNode` as the LAST child of a list item (target item or, when
2684
- * omitted, the wrapper's last item). When `sourceRange` is set, the source
2685
- * range is removed in the same transaction so the op is a clean MOVE.
2686
- * Returns `{ ok: false }` WITHOUT mutating `tr` on schema reject so callers
2687
- * can fall through to a sibling-mode fallback.
2693
+ * Insert `blockNode` into a list item's children at `childIndex` (default:
2694
+ * append last; target item defaults to the wrapper's last item). `sourceRange`
2695
+ * makes it a MOVE. Returns `{ ok: false }` without mutating `tr` on schema
2696
+ * reject or self-drop so callers can fall back to a sibling move.
2688
2697
  */
2689
2698
  declare function insertAsListItemChild(args: InsertAsListItemChildArgs): InsertAsListItemChildResult;
2690
2699
 
@@ -3480,6 +3489,16 @@ declare class Extension<Options = unknown, Storage = unknown> {
3480
3489
  * // configure({ nested: { ...original.options.nested, b: 3 } })
3481
3490
  */
3482
3491
  configure(options: Partial<Options>): Extension<Options, Storage>;
3492
+ /**
3493
+ * Returns a fresh, unbound copy built from the same `config`: `editor` reset to
3494
+ * null and `options`/`storage` re-derived, while `configure()`/`extend()`
3495
+ * results are preserved (they live in `config`). Polymorphic: a `Node`/`Mark`
3496
+ * clones to its own subclass.
3497
+ *
3498
+ * `ExtensionManager` clones every extension so each editor owns its instances
3499
+ * and binding one editor can't mutate extensions shared with another.
3500
+ */
3501
+ clone(): Extension<Options, Storage>;
3483
3502
  /**
3484
3503
  * Creates a new extension with extended configuration
3485
3504
  * Original extension is not modified
@@ -6304,12 +6323,15 @@ interface StarterKitOptions {
6304
6323
  */
6305
6324
  listKeymap?: false | Partial<ListKeymapOptions>;
6306
6325
  /**
6307
- * Set to false to disable the ListIndent extension. ListIndent adds
6308
- * Tab / Shift-Tab keymap that indents a top-level block under the
6309
- * previous list (and outdents back). Registered AFTER ListKeymap so
6310
- * the in-list-item Tab/Shift-Tab keep priority.
6326
+ * Off by default. Set to `true` to enable the ListIndent extension, which
6327
+ * adds a Tab / Shift-Tab keymap that indents a top-level block under the
6328
+ * previous list (and outdents back). Kept off by default because it captures
6329
+ * Tab on a paragraph that merely follows a list, so Tab no longer moves focus
6330
+ * to the next field in embedded / form usage, and the same nesting is
6331
+ * reachable via the block-menu drag. Registered AFTER ListKeymap so the
6332
+ * in-list-item Tab/Shift-Tab keep priority.
6311
6333
  */
6312
- listIndent?: false;
6334
+ listIndent?: boolean;
6313
6335
  /**
6314
6336
  * Set to false to disable the LinkPopover extension, or pass options to configure it.
6315
6337
  */
package/dist/index.d.ts CHANGED
@@ -814,6 +814,15 @@ declare class ExtensionManager {
814
814
  * while letting users override with explicitly configured versions.
815
815
  */
816
816
  private deduplicateExtensions;
817
+ /**
818
+ * Clone every extension so this editor owns its instances. Extensions hold
819
+ * per-editor mutable state (`editor`, plus the `nodeType`/`markType` getters
820
+ * derived from it), and the same extension object is commonly reused across
821
+ * editors (one shared `extensions` array). Without cloning, binding a later
822
+ * editor clobbers an earlier one: its list `Enter` then falls back to a plain
823
+ * block split, dropping an indented "child" paragraph instead of a new `<li>`.
824
+ */
825
+ private cloneExtensions;
817
826
  /**
818
827
  * Sorts extensions by priority (higher priority first)
819
828
  * Default priority is 100
@@ -2657,17 +2666,18 @@ interface InsertAsListItemChildArgs {
2657
2666
  * matching the Tab keyboard behaviour ("indent into last item").
2658
2667
  */
2659
2668
  targetItemPos?: number;
2660
- /** Block node to append as the LAST child of the target item. */
2669
+ /** Block node to insert. */
2661
2670
  blockNode: Node$1;
2662
- /**
2663
- * Optional source range to delete in the SAME transaction (when
2664
- * MOVING an existing block instead of creating a new one). Position
2665
- * math handles source-before-vs-after-target ordering automatically.
2666
- */
2671
+ /** Optional source range to delete in the same tr (turns insert into a MOVE). */
2667
2672
  sourceRange?: {
2668
2673
  from: number;
2669
2674
  to: number;
2670
2675
  };
2676
+ /**
2677
+ * Child index to insert at. Clamped to `>= 1` (index 0 is the label
2678
+ * paragraph). Omitted or `>= childCount` appends as the last child.
2679
+ */
2680
+ childIndex?: number;
2671
2681
  }
2672
2682
  interface InsertAsListItemChildResult {
2673
2683
  /** True when schema accepted the insertion and `tr` was mutated. */
@@ -2680,11 +2690,10 @@ interface InsertAsListItemChildResult {
2680
2690
  insertedAt?: number;
2681
2691
  }
2682
2692
  /**
2683
- * Insert `blockNode` as the LAST child of a list item (target item or, when
2684
- * omitted, the wrapper's last item). When `sourceRange` is set, the source
2685
- * range is removed in the same transaction so the op is a clean MOVE.
2686
- * Returns `{ ok: false }` WITHOUT mutating `tr` on schema reject so callers
2687
- * can fall through to a sibling-mode fallback.
2693
+ * Insert `blockNode` into a list item's children at `childIndex` (default:
2694
+ * append last; target item defaults to the wrapper's last item). `sourceRange`
2695
+ * makes it a MOVE. Returns `{ ok: false }` without mutating `tr` on schema
2696
+ * reject or self-drop so callers can fall back to a sibling move.
2688
2697
  */
2689
2698
  declare function insertAsListItemChild(args: InsertAsListItemChildArgs): InsertAsListItemChildResult;
2690
2699
 
@@ -3480,6 +3489,16 @@ declare class Extension<Options = unknown, Storage = unknown> {
3480
3489
  * // configure({ nested: { ...original.options.nested, b: 3 } })
3481
3490
  */
3482
3491
  configure(options: Partial<Options>): Extension<Options, Storage>;
3492
+ /**
3493
+ * Returns a fresh, unbound copy built from the same `config`: `editor` reset to
3494
+ * null and `options`/`storage` re-derived, while `configure()`/`extend()`
3495
+ * results are preserved (they live in `config`). Polymorphic: a `Node`/`Mark`
3496
+ * clones to its own subclass.
3497
+ *
3498
+ * `ExtensionManager` clones every extension so each editor owns its instances
3499
+ * and binding one editor can't mutate extensions shared with another.
3500
+ */
3501
+ clone(): Extension<Options, Storage>;
3483
3502
  /**
3484
3503
  * Creates a new extension with extended configuration
3485
3504
  * Original extension is not modified
@@ -6304,12 +6323,15 @@ interface StarterKitOptions {
6304
6323
  */
6305
6324
  listKeymap?: false | Partial<ListKeymapOptions>;
6306
6325
  /**
6307
- * Set to false to disable the ListIndent extension. ListIndent adds
6308
- * Tab / Shift-Tab keymap that indents a top-level block under the
6309
- * previous list (and outdents back). Registered AFTER ListKeymap so
6310
- * the in-list-item Tab/Shift-Tab keep priority.
6326
+ * Off by default. Set to `true` to enable the ListIndent extension, which
6327
+ * adds a Tab / Shift-Tab keymap that indents a top-level block under the
6328
+ * previous list (and outdents back). Kept off by default because it captures
6329
+ * Tab on a paragraph that merely follows a list, so Tab no longer moves focus
6330
+ * to the next field in embedded / form usage, and the same nesting is
6331
+ * reachable via the block-menu drag. Registered AFTER ListKeymap so the
6332
+ * in-list-item Tab/Shift-Tab keep priority.
6311
6333
  */
6312
- listIndent?: false;
6334
+ listIndent?: boolean;
6313
6335
  /**
6314
6336
  * Set to false to disable the LinkPopover extension, or pass options to configure it.
6315
6337
  */
package/dist/index.js CHANGED
@@ -298,7 +298,8 @@ var ExtensionManager = class {
298
298
  }
299
299
  const flattened = this.flattenExtensions(options.extensions);
300
300
  const deduped = this.deduplicateExtensions(flattened);
301
- this._extensions = this.resolveExtensions(deduped);
301
+ const cloned = this.cloneExtensions(deduped);
302
+ this._extensions = this.resolveExtensions(cloned);
302
303
  this.detectConflicts();
303
304
  this.checkDependencies();
304
305
  this.bindEditorToExtensions();
@@ -406,6 +407,17 @@ var ExtensionManager = class {
406
407
  }
407
408
  return extensions.filter((ext, i) => seen.get(ext.name) === i);
408
409
  }
410
+ /**
411
+ * Clone every extension so this editor owns its instances. Extensions hold
412
+ * per-editor mutable state (`editor`, plus the `nodeType`/`markType` getters
413
+ * derived from it), and the same extension object is commonly reused across
414
+ * editors (one shared `extensions` array). Without cloning, binding a later
415
+ * editor clobbers an earlier one: its list `Enter` then falls back to a plain
416
+ * block split, dropping an indented "child" paragraph instead of a new `<li>`.
417
+ */
418
+ cloneExtensions(extensions) {
419
+ return extensions.map((ext) => ext.clone());
420
+ }
409
421
  /**
410
422
  * Sorts extensions by priority (higher priority first)
411
423
  * Default priority is 100
@@ -1538,6 +1550,19 @@ var Extension = class _Extension {
1538
1550
  };
1539
1551
  return new _Extension(newConfig);
1540
1552
  }
1553
+ /**
1554
+ * Returns a fresh, unbound copy built from the same `config`: `editor` reset to
1555
+ * null and `options`/`storage` re-derived, while `configure()`/`extend()`
1556
+ * results are preserved (they live in `config`). Polymorphic: a `Node`/`Mark`
1557
+ * clones to its own subclass.
1558
+ *
1559
+ * `ExtensionManager` clones every extension so each editor owns its instances
1560
+ * and binding one editor can't mutate extensions shared with another.
1561
+ */
1562
+ clone() {
1563
+ const Ctor = this.constructor;
1564
+ return new Ctor(this.config);
1565
+ }
1541
1566
  /**
1542
1567
  * Creates a new extension with extended configuration
1543
1568
  * Original extension is not modified
@@ -4106,7 +4131,7 @@ function defaultBubbleContexts(editor) {
4106
4131
  var LIST_ITEM_TYPES3 = /* @__PURE__ */ new Set(["listItem", "taskItem"]);
4107
4132
  var LIST_WRAPPER_TYPES = /* @__PURE__ */ new Set(["bulletList", "orderedList", "taskList"]);
4108
4133
  function insertAsListItemChild(args) {
4109
- const { tr, wrapperPos, targetItemPos, blockNode, sourceRange } = args;
4134
+ const { tr, wrapperPos, targetItemPos, blockNode, sourceRange, childIndex } = args;
4110
4135
  if (wrapperPos < 0 || wrapperPos >= tr.doc.content.size) return { ok: false };
4111
4136
  const wrapper = tr.doc.nodeAt(wrapperPos);
4112
4137
  if (!wrapper || !LIST_WRAPPER_TYPES.has(wrapper.type.name)) return { ok: false };
@@ -4132,22 +4157,25 @@ function insertAsListItemChild(args) {
4132
4157
  targetItem = last;
4133
4158
  targetItemStart = pos;
4134
4159
  }
4135
- if (!targetItem.canReplaceWith(targetItem.childCount, targetItem.childCount, blockNode.type)) {
4160
+ const childCount = targetItem.childCount;
4161
+ const insertIndex = childIndex === void 0 || childIndex >= childCount ? childCount : Math.max(1, childIndex);
4162
+ if (!targetItem.canReplaceWith(insertIndex, insertIndex, blockNode.type)) {
4136
4163
  return { ok: false };
4137
4164
  }
4138
- const targetItemContentEnd = targetItemStart + targetItem.nodeSize - 1;
4165
+ const $item = tr.doc.resolve(targetItemStart + 1);
4166
+ const insertPos = $item.posAtIndex(insertIndex, $item.depth);
4139
4167
  if (sourceRange) {
4140
4168
  const { from, to } = sourceRange;
4141
- if (targetItemContentEnd >= from && targetItemContentEnd <= to) {
4169
+ if (insertPos >= from && insertPos <= to) {
4142
4170
  return { ok: false };
4143
4171
  }
4144
4172
  tr.delete(from, to);
4145
- const adjustedInsertPos = targetItemContentEnd > from ? targetItemContentEnd - (to - from) : targetItemContentEnd;
4173
+ const adjustedInsertPos = insertPos > from ? insertPos - (to - from) : insertPos;
4146
4174
  tr.insert(adjustedInsertPos, blockNode);
4147
4175
  return { ok: true, insertedAt: adjustedInsertPos };
4148
4176
  }
4149
- tr.insert(targetItemContentEnd, blockNode);
4150
- return { ok: true, insertedAt: targetItemContentEnd };
4177
+ tr.insert(insertPos, blockNode);
4178
+ return { ok: true, insertedAt: insertPos };
4151
4179
  }
4152
4180
  function liftEmptyChildrenZoneParagraph(state, dispatch, ctx) {
4153
4181
  if (!ctx.isInChildrenZone || !ctx.paragraphIsEmpty) return false;
@@ -8702,8 +8730,13 @@ var SelectionDecoration = Extension.create(
8702
8730
  handleDOMEvents: {
8703
8731
  blur(view, event) {
8704
8732
  const related = event.relatedTarget;
8705
- if (related instanceof HTMLElement && (related.closest("[data-dm-editor-ui]") || related.closest(".dm-toolbar") || related.closest(".dm-bubble-menu"))) {
8706
- return false;
8733
+ if (related instanceof HTMLElement) {
8734
+ const ownContainer = view.dom.closest(".dm-editor");
8735
+ const relatedContainer = related.closest(".dm-editor");
8736
+ const movedToAnotherEditor = ownContainer !== null && relatedContainer !== null && relatedContainer !== ownContainer;
8737
+ if (!movedToAnotherEditor && (related.closest("[data-dm-editor-ui]") || related.closest(".dm-toolbar") || related.closest(".dm-bubble-menu"))) {
8738
+ return false;
8739
+ }
8707
8740
  }
8708
8741
  const { from, to } = view.state.selection;
8709
8742
  if (from !== to) {
@@ -10056,7 +10089,7 @@ var StarterKit = Extension.create({
10056
10089
  maybeAdd(Gapcursor, this.options.gapcursor);
10057
10090
  maybeAdd(TrailingNode, this.options.trailingNode);
10058
10091
  maybeAdd(ListKeymap, this.options.listKeymap);
10059
- maybeAdd(ListIndent, this.options.listIndent);
10092
+ if (this.options.listIndent === true) extensions.push(ListIndent);
10060
10093
  maybeAdd(LinkPopover, this.options.linkPopover);
10061
10094
  maybeAdd(SelectionDecoration, this.options.selectionDecoration);
10062
10095
  return extensions;