@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 CHANGED
@@ -4132,7 +4132,7 @@ function defaultBubbleContexts(editor) {
4132
4132
  var LIST_ITEM_TYPES3 = /* @__PURE__ */ new Set(["listItem", "taskItem"]);
4133
4133
  var LIST_WRAPPER_TYPES = /* @__PURE__ */ new Set(["bulletList", "orderedList", "taskList"]);
4134
4134
  function insertAsListItemChild(args) {
4135
- const { tr, wrapperPos, targetItemPos, blockNode, sourceRange } = args;
4135
+ const { tr, wrapperPos, targetItemPos, blockNode, sourceRange, childIndex } = args;
4136
4136
  if (wrapperPos < 0 || wrapperPos >= tr.doc.content.size) return { ok: false };
4137
4137
  const wrapper = tr.doc.nodeAt(wrapperPos);
4138
4138
  if (!wrapper || !LIST_WRAPPER_TYPES.has(wrapper.type.name)) return { ok: false };
@@ -4158,22 +4158,25 @@ function insertAsListItemChild(args) {
4158
4158
  targetItem = last;
4159
4159
  targetItemStart = pos;
4160
4160
  }
4161
- if (!targetItem.canReplaceWith(targetItem.childCount, targetItem.childCount, blockNode.type)) {
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)) {
4162
4164
  return { ok: false };
4163
4165
  }
4164
- const targetItemContentEnd = targetItemStart + targetItem.nodeSize - 1;
4166
+ const $item = tr.doc.resolve(targetItemStart + 1);
4167
+ const insertPos = $item.posAtIndex(insertIndex, $item.depth);
4165
4168
  if (sourceRange) {
4166
4169
  const { from, to } = sourceRange;
4167
- if (targetItemContentEnd >= from && targetItemContentEnd <= to) {
4170
+ if (insertPos >= from && insertPos <= to) {
4168
4171
  return { ok: false };
4169
4172
  }
4170
4173
  tr.delete(from, to);
4171
- const adjustedInsertPos = targetItemContentEnd > from ? targetItemContentEnd - (to - from) : targetItemContentEnd;
4174
+ const adjustedInsertPos = insertPos > from ? insertPos - (to - from) : insertPos;
4172
4175
  tr.insert(adjustedInsertPos, blockNode);
4173
4176
  return { ok: true, insertedAt: adjustedInsertPos };
4174
4177
  }
4175
- tr.insert(targetItemContentEnd, blockNode);
4176
- return { ok: true, insertedAt: targetItemContentEnd };
4178
+ tr.insert(insertPos, blockNode);
4179
+ return { ok: true, insertedAt: insertPos };
4177
4180
  }
4178
4181
  function liftEmptyChildrenZoneParagraph(state$1, dispatch, ctx) {
4179
4182
  if (!ctx.isInChildrenZone || !ctx.paragraphIsEmpty) return false;