@domternal/core 0.7.5 → 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 +10 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -2666,17 +2666,18 @@ interface InsertAsListItemChildArgs {
|
|
|
2666
2666
|
* matching the Tab keyboard behaviour ("indent into last item").
|
|
2667
2667
|
*/
|
|
2668
2668
|
targetItemPos?: number;
|
|
2669
|
-
/** Block node to
|
|
2669
|
+
/** Block node to insert. */
|
|
2670
2670
|
blockNode: Node$1;
|
|
2671
|
-
/**
|
|
2672
|
-
* Optional source range to delete in the SAME transaction (when
|
|
2673
|
-
* MOVING an existing block instead of creating a new one). Position
|
|
2674
|
-
* math handles source-before-vs-after-target ordering automatically.
|
|
2675
|
-
*/
|
|
2671
|
+
/** Optional source range to delete in the same tr (turns insert into a MOVE). */
|
|
2676
2672
|
sourceRange?: {
|
|
2677
2673
|
from: number;
|
|
2678
2674
|
to: number;
|
|
2679
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;
|
|
2680
2681
|
}
|
|
2681
2682
|
interface InsertAsListItemChildResult {
|
|
2682
2683
|
/** True when schema accepted the insertion and `tr` was mutated. */
|
|
@@ -2689,11 +2690,10 @@ interface InsertAsListItemChildResult {
|
|
|
2689
2690
|
insertedAt?: number;
|
|
2690
2691
|
}
|
|
2691
2692
|
/**
|
|
2692
|
-
* Insert `blockNode`
|
|
2693
|
-
*
|
|
2694
|
-
*
|
|
2695
|
-
*
|
|
2696
|
-
* 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.
|
|
2697
2697
|
*/
|
|
2698
2698
|
declare function insertAsListItemChild(args: InsertAsListItemChildArgs): InsertAsListItemChildResult;
|
|
2699
2699
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2666,17 +2666,18 @@ interface InsertAsListItemChildArgs {
|
|
|
2666
2666
|
* matching the Tab keyboard behaviour ("indent into last item").
|
|
2667
2667
|
*/
|
|
2668
2668
|
targetItemPos?: number;
|
|
2669
|
-
/** Block node to
|
|
2669
|
+
/** Block node to insert. */
|
|
2670
2670
|
blockNode: Node$1;
|
|
2671
|
-
/**
|
|
2672
|
-
* Optional source range to delete in the SAME transaction (when
|
|
2673
|
-
* MOVING an existing block instead of creating a new one). Position
|
|
2674
|
-
* math handles source-before-vs-after-target ordering automatically.
|
|
2675
|
-
*/
|
|
2671
|
+
/** Optional source range to delete in the same tr (turns insert into a MOVE). */
|
|
2676
2672
|
sourceRange?: {
|
|
2677
2673
|
from: number;
|
|
2678
2674
|
to: number;
|
|
2679
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;
|
|
2680
2681
|
}
|
|
2681
2682
|
interface InsertAsListItemChildResult {
|
|
2682
2683
|
/** True when schema accepted the insertion and `tr` was mutated. */
|
|
@@ -2689,11 +2690,10 @@ interface InsertAsListItemChildResult {
|
|
|
2689
2690
|
insertedAt?: number;
|
|
2690
2691
|
}
|
|
2691
2692
|
/**
|
|
2692
|
-
* Insert `blockNode`
|
|
2693
|
-
*
|
|
2694
|
-
*
|
|
2695
|
-
*
|
|
2696
|
-
* 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.
|
|
2697
2697
|
*/
|
|
2698
2698
|
declare function insertAsListItemChild(args: InsertAsListItemChildArgs): InsertAsListItemChildResult;
|
|
2699
2699
|
|
package/dist/index.js
CHANGED
|
@@ -4131,7 +4131,7 @@ function defaultBubbleContexts(editor) {
|
|
|
4131
4131
|
var LIST_ITEM_TYPES3 = /* @__PURE__ */ new Set(["listItem", "taskItem"]);
|
|
4132
4132
|
var LIST_WRAPPER_TYPES = /* @__PURE__ */ new Set(["bulletList", "orderedList", "taskList"]);
|
|
4133
4133
|
function insertAsListItemChild(args) {
|
|
4134
|
-
const { tr, wrapperPos, targetItemPos, blockNode, sourceRange } = args;
|
|
4134
|
+
const { tr, wrapperPos, targetItemPos, blockNode, sourceRange, childIndex } = args;
|
|
4135
4135
|
if (wrapperPos < 0 || wrapperPos >= tr.doc.content.size) return { ok: false };
|
|
4136
4136
|
const wrapper = tr.doc.nodeAt(wrapperPos);
|
|
4137
4137
|
if (!wrapper || !LIST_WRAPPER_TYPES.has(wrapper.type.name)) return { ok: false };
|
|
@@ -4157,22 +4157,25 @@ function insertAsListItemChild(args) {
|
|
|
4157
4157
|
targetItem = last;
|
|
4158
4158
|
targetItemStart = pos;
|
|
4159
4159
|
}
|
|
4160
|
-
|
|
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)) {
|
|
4161
4163
|
return { ok: false };
|
|
4162
4164
|
}
|
|
4163
|
-
const
|
|
4165
|
+
const $item = tr.doc.resolve(targetItemStart + 1);
|
|
4166
|
+
const insertPos = $item.posAtIndex(insertIndex, $item.depth);
|
|
4164
4167
|
if (sourceRange) {
|
|
4165
4168
|
const { from, to } = sourceRange;
|
|
4166
|
-
if (
|
|
4169
|
+
if (insertPos >= from && insertPos <= to) {
|
|
4167
4170
|
return { ok: false };
|
|
4168
4171
|
}
|
|
4169
4172
|
tr.delete(from, to);
|
|
4170
|
-
const adjustedInsertPos =
|
|
4173
|
+
const adjustedInsertPos = insertPos > from ? insertPos - (to - from) : insertPos;
|
|
4171
4174
|
tr.insert(adjustedInsertPos, blockNode);
|
|
4172
4175
|
return { ok: true, insertedAt: adjustedInsertPos };
|
|
4173
4176
|
}
|
|
4174
|
-
tr.insert(
|
|
4175
|
-
return { ok: true, insertedAt:
|
|
4177
|
+
tr.insert(insertPos, blockNode);
|
|
4178
|
+
return { ok: true, insertedAt: insertPos };
|
|
4176
4179
|
}
|
|
4177
4180
|
function liftEmptyChildrenZoneParagraph(state, dispatch, ctx) {
|
|
4178
4181
|
if (!ctx.isInChildrenZone || !ctx.paragraphIsEmpty) return false;
|