@trafica/editor 1.0.44 → 1.0.45

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.js CHANGED
@@ -2203,6 +2203,10 @@ function mergeAtCursor(state, pastedDoc, sel) {
2203
2203
  const lastIdx = mergedDoc.children.length - 1;
2204
2204
  return { mergedDoc, cursorPos: endOfBlock(mergedDoc.children[lastIdx], lastIdx) };
2205
2205
  }
2206
+ const LIST_CONTAINERS = /* @__PURE__ */ new Set(["bullet_list", "ordered_list", "check_list"]);
2207
+ if (LIST_CONTAINERS.has(currentBlock.type) && relPath.length > 0) {
2208
+ return mergeIntoListContainer(state, pasted, existingBlocks, blockIdx, currentBlock, relPath, charOffset);
2209
+ }
2206
2210
  const [beforeChildren, afterChildren] = splitBlockChildren(currentBlock, relPath, charOffset);
2207
2211
  let newBlocks;
2208
2212
  let cursorBlockOffset;
@@ -2260,6 +2264,85 @@ function mergeAtCursor(state, pastedDoc, sel) {
2260
2264
  cursorPos: cursorInBlock
2261
2265
  };
2262
2266
  }
2267
+ function mergeIntoListContainer(state, pasted, existingBlocks, blockIdx, listBlock, relPath, charOffset) {
2268
+ var _a, _b, _c, _d, _e;
2269
+ const itemIdx = relPath[0];
2270
+ const itemRelPath = relPath.slice(1);
2271
+ const listItems = listBlock.children;
2272
+ const currentItem = listItems[itemIdx];
2273
+ const isCheckList = listBlock.type === "check_list";
2274
+ const itemType = isCheckList ? "check_list_item" : "list_item";
2275
+ if (!currentItem) {
2276
+ const newBlocks = [...existingBlocks, ...pasted];
2277
+ const lastIdx = newBlocks.length - 1;
2278
+ return {
2279
+ mergedDoc: { ...state.doc, children: newBlocks },
2280
+ cursorPos: endOfBlock(newBlocks[lastIdx], lastIdx)
2281
+ };
2282
+ }
2283
+ const [beforeChildren, afterChildren] = splitBlockChildren(currentItem, itemRelPath, charOffset);
2284
+ const makeItem = (children) => ({
2285
+ type: itemType,
2286
+ attrs: isCheckList ? { checked: false } : {},
2287
+ children: children.length > 0 ? children : [{ type: "text", text: "", marks: [] }]
2288
+ });
2289
+ let newItems;
2290
+ let cursorItemIdx;
2291
+ if (pasted.length === 1) {
2292
+ const pastedChildren = (_a = pasted[0].children) != null ? _a : [];
2293
+ const merged = [...beforeChildren, ...pastedChildren, ...afterChildren];
2294
+ newItems = [
2295
+ ...listItems.slice(0, itemIdx),
2296
+ { ...currentItem, children: merged.length > 0 ? merged : [{ type: "text", text: "", marks: [] }] },
2297
+ ...listItems.slice(itemIdx + 1)
2298
+ ];
2299
+ cursorItemIdx = itemIdx;
2300
+ } else {
2301
+ const firstPasted = pasted[0];
2302
+ const lastPasted = pasted[pasted.length - 1];
2303
+ const middlePasted = pasted.slice(1, -1);
2304
+ const firstItem = { ...currentItem, children: [...beforeChildren, ...(_b = firstPasted.children) != null ? _b : []] };
2305
+ const lastItem = makeItem([...(_c = lastPasted.children) != null ? _c : [], ...afterChildren]);
2306
+ const midItems = middlePasted.map((p) => {
2307
+ var _a2;
2308
+ return makeItem((_a2 = p.children) != null ? _a2 : []);
2309
+ });
2310
+ newItems = [
2311
+ ...listItems.slice(0, itemIdx),
2312
+ firstItem,
2313
+ ...midItems,
2314
+ lastItem,
2315
+ ...listItems.slice(itemIdx + 1)
2316
+ ];
2317
+ cursorItemIdx = itemIdx + 1 + midItems.length;
2318
+ }
2319
+ const newList = { ...listBlock, children: newItems };
2320
+ const mergedBlocks = [
2321
+ ...existingBlocks.slice(0, blockIdx),
2322
+ newList,
2323
+ ...existingBlocks.slice(blockIdx + 1)
2324
+ ];
2325
+ const targetItem = newItems[cursorItemIdx];
2326
+ let cursorPos;
2327
+ if (pasted.length === 1) {
2328
+ const pastedChildren = (_d = pasted[0].children) != null ? _d : [];
2329
+ const cursorChildIdx = beforeChildren.length + pastedChildren.length;
2330
+ const nodeBefore = targetItem == null ? void 0 : targetItem.children[cursorChildIdx - 1];
2331
+ cursorPos = nodeBefore && isTextNode(nodeBefore) ? { path: [blockIdx, cursorItemIdx, cursorChildIdx - 1], offset: nodeBefore.text.length } : { path: [blockIdx, cursorItemIdx], offset: 0 };
2332
+ } else {
2333
+ const lpChildren = (_e = pasted[pasted.length - 1].children) != null ? _e : [];
2334
+ if (lpChildren.length > 0) {
2335
+ const lastNode = lpChildren[lpChildren.length - 1];
2336
+ cursorPos = {
2337
+ path: [blockIdx, cursorItemIdx, lpChildren.length - 1],
2338
+ offset: isTextNode(lastNode) ? lastNode.text.length : 0
2339
+ };
2340
+ } else {
2341
+ cursorPos = { path: [blockIdx, cursorItemIdx], offset: 0 };
2342
+ }
2343
+ }
2344
+ return { mergedDoc: { ...state.doc, children: mergedBlocks }, cursorPos };
2345
+ }
2263
2346
  function splitBlockChildren(block, relPath, offset) {
2264
2347
  const children = block.children;
2265
2348
  if (children.length === 0) return [[], []];
@@ -9068,7 +9151,9 @@ ${text}
9068
9151
  }
9069
9152
  }
9070
9153
  function serializeMDInline(children) {
9154
+ if (!children) return "";
9071
9155
  return children.map((child) => {
9156
+ if (!child) return "";
9072
9157
  if (!isTextNode(child)) return serializeMDBlock(child, 0);
9073
9158
  return serializeMDText(child);
9074
9159
  }).join("");