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