@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.cjs +44 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -16
- package/dist/index.d.ts +38 -16
- package/dist/index.js +44 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -299,7 +299,8 @@ var ExtensionManager = class {
|
|
|
299
299
|
}
|
|
300
300
|
const flattened = this.flattenExtensions(options.extensions);
|
|
301
301
|
const deduped = this.deduplicateExtensions(flattened);
|
|
302
|
-
|
|
302
|
+
const cloned = this.cloneExtensions(deduped);
|
|
303
|
+
this._extensions = this.resolveExtensions(cloned);
|
|
303
304
|
this.detectConflicts();
|
|
304
305
|
this.checkDependencies();
|
|
305
306
|
this.bindEditorToExtensions();
|
|
@@ -407,6 +408,17 @@ var ExtensionManager = class {
|
|
|
407
408
|
}
|
|
408
409
|
return extensions.filter((ext, i) => seen.get(ext.name) === i);
|
|
409
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Clone every extension so this editor owns its instances. Extensions hold
|
|
413
|
+
* per-editor mutable state (`editor`, plus the `nodeType`/`markType` getters
|
|
414
|
+
* derived from it), and the same extension object is commonly reused across
|
|
415
|
+
* editors (one shared `extensions` array). Without cloning, binding a later
|
|
416
|
+
* editor clobbers an earlier one: its list `Enter` then falls back to a plain
|
|
417
|
+
* block split, dropping an indented "child" paragraph instead of a new `<li>`.
|
|
418
|
+
*/
|
|
419
|
+
cloneExtensions(extensions) {
|
|
420
|
+
return extensions.map((ext) => ext.clone());
|
|
421
|
+
}
|
|
410
422
|
/**
|
|
411
423
|
* Sorts extensions by priority (higher priority first)
|
|
412
424
|
* Default priority is 100
|
|
@@ -1539,6 +1551,19 @@ var Extension = class _Extension {
|
|
|
1539
1551
|
};
|
|
1540
1552
|
return new _Extension(newConfig);
|
|
1541
1553
|
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Returns a fresh, unbound copy built from the same `config`: `editor` reset to
|
|
1556
|
+
* null and `options`/`storage` re-derived, while `configure()`/`extend()`
|
|
1557
|
+
* results are preserved (they live in `config`). Polymorphic: a `Node`/`Mark`
|
|
1558
|
+
* clones to its own subclass.
|
|
1559
|
+
*
|
|
1560
|
+
* `ExtensionManager` clones every extension so each editor owns its instances
|
|
1561
|
+
* and binding one editor can't mutate extensions shared with another.
|
|
1562
|
+
*/
|
|
1563
|
+
clone() {
|
|
1564
|
+
const Ctor = this.constructor;
|
|
1565
|
+
return new Ctor(this.config);
|
|
1566
|
+
}
|
|
1542
1567
|
/**
|
|
1543
1568
|
* Creates a new extension with extended configuration
|
|
1544
1569
|
* Original extension is not modified
|
|
@@ -4107,7 +4132,7 @@ function defaultBubbleContexts(editor) {
|
|
|
4107
4132
|
var LIST_ITEM_TYPES3 = /* @__PURE__ */ new Set(["listItem", "taskItem"]);
|
|
4108
4133
|
var LIST_WRAPPER_TYPES = /* @__PURE__ */ new Set(["bulletList", "orderedList", "taskList"]);
|
|
4109
4134
|
function insertAsListItemChild(args) {
|
|
4110
|
-
const { tr, wrapperPos, targetItemPos, blockNode, sourceRange } = args;
|
|
4135
|
+
const { tr, wrapperPos, targetItemPos, blockNode, sourceRange, childIndex } = args;
|
|
4111
4136
|
if (wrapperPos < 0 || wrapperPos >= tr.doc.content.size) return { ok: false };
|
|
4112
4137
|
const wrapper = tr.doc.nodeAt(wrapperPos);
|
|
4113
4138
|
if (!wrapper || !LIST_WRAPPER_TYPES.has(wrapper.type.name)) return { ok: false };
|
|
@@ -4133,22 +4158,25 @@ function insertAsListItemChild(args) {
|
|
|
4133
4158
|
targetItem = last;
|
|
4134
4159
|
targetItemStart = pos;
|
|
4135
4160
|
}
|
|
4136
|
-
|
|
4161
|
+
const childCount = targetItem.childCount;
|
|
4162
|
+
const insertIndex = childIndex === void 0 || childIndex >= childCount ? childCount : Math.max(1, childIndex);
|
|
4163
|
+
if (!targetItem.canReplaceWith(insertIndex, insertIndex, blockNode.type)) {
|
|
4137
4164
|
return { ok: false };
|
|
4138
4165
|
}
|
|
4139
|
-
const
|
|
4166
|
+
const $item = tr.doc.resolve(targetItemStart + 1);
|
|
4167
|
+
const insertPos = $item.posAtIndex(insertIndex, $item.depth);
|
|
4140
4168
|
if (sourceRange) {
|
|
4141
4169
|
const { from, to } = sourceRange;
|
|
4142
|
-
if (
|
|
4170
|
+
if (insertPos >= from && insertPos <= to) {
|
|
4143
4171
|
return { ok: false };
|
|
4144
4172
|
}
|
|
4145
4173
|
tr.delete(from, to);
|
|
4146
|
-
const adjustedInsertPos =
|
|
4174
|
+
const adjustedInsertPos = insertPos > from ? insertPos - (to - from) : insertPos;
|
|
4147
4175
|
tr.insert(adjustedInsertPos, blockNode);
|
|
4148
4176
|
return { ok: true, insertedAt: adjustedInsertPos };
|
|
4149
4177
|
}
|
|
4150
|
-
tr.insert(
|
|
4151
|
-
return { ok: true, insertedAt:
|
|
4178
|
+
tr.insert(insertPos, blockNode);
|
|
4179
|
+
return { ok: true, insertedAt: insertPos };
|
|
4152
4180
|
}
|
|
4153
4181
|
function liftEmptyChildrenZoneParagraph(state$1, dispatch, ctx) {
|
|
4154
4182
|
if (!ctx.isInChildrenZone || !ctx.paragraphIsEmpty) return false;
|
|
@@ -8703,8 +8731,13 @@ var SelectionDecoration = Extension.create(
|
|
|
8703
8731
|
handleDOMEvents: {
|
|
8704
8732
|
blur(view, event) {
|
|
8705
8733
|
const related = event.relatedTarget;
|
|
8706
|
-
if (related instanceof HTMLElement
|
|
8707
|
-
|
|
8734
|
+
if (related instanceof HTMLElement) {
|
|
8735
|
+
const ownContainer = view.dom.closest(".dm-editor");
|
|
8736
|
+
const relatedContainer = related.closest(".dm-editor");
|
|
8737
|
+
const movedToAnotherEditor = ownContainer !== null && relatedContainer !== null && relatedContainer !== ownContainer;
|
|
8738
|
+
if (!movedToAnotherEditor && (related.closest("[data-dm-editor-ui]") || related.closest(".dm-toolbar") || related.closest(".dm-bubble-menu"))) {
|
|
8739
|
+
return false;
|
|
8740
|
+
}
|
|
8708
8741
|
}
|
|
8709
8742
|
const { from, to } = view.state.selection;
|
|
8710
8743
|
if (from !== to) {
|
|
@@ -10057,7 +10090,7 @@ var StarterKit = Extension.create({
|
|
|
10057
10090
|
maybeAdd(Gapcursor, this.options.gapcursor);
|
|
10058
10091
|
maybeAdd(TrailingNode, this.options.trailingNode);
|
|
10059
10092
|
maybeAdd(ListKeymap, this.options.listKeymap);
|
|
10060
|
-
|
|
10093
|
+
if (this.options.listIndent === true) extensions.push(ListIndent);
|
|
10061
10094
|
maybeAdd(LinkPopover, this.options.linkPopover);
|
|
10062
10095
|
maybeAdd(SelectionDecoration, this.options.selectionDecoration);
|
|
10063
10096
|
return extensions;
|