fix(): 列表回车无效果、复制自定义列表首行不带卡片
This commit is contained in:
parent
407de59619
commit
5c513e470d
|
@ -554,7 +554,7 @@ class Block implements BlockModelInterface {
|
|||
) {
|
||||
const fragment = doc.createDocumentFragment();
|
||||
fragment.appendChild(block[0]);
|
||||
list.insert(fragment, range);
|
||||
list.insert(fragment, safeRange);
|
||||
if (!range) change.apply(safeRange);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -61,28 +61,7 @@ class Enter {
|
|||
}
|
||||
// 列表
|
||||
if (block.name === 'li') {
|
||||
if (node.isCustomize(block)) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
if (blockApi.isLastOffset(range, 'end')) {
|
||||
if (range.collapsed && blockApi.isFirstOffset(range, 'end')) {
|
||||
const listRoot = block.closest('ul,ol');
|
||||
blockApi.unwrap('<'.concat(listRoot.name!, ' />'));
|
||||
blockApi.setBlocks('<p />');
|
||||
} else {
|
||||
const li = $('<li><br /></li>');
|
||||
const attributes = block.attributes();
|
||||
delete attributes[DATA_ID];
|
||||
li.attributes(attributes);
|
||||
blockApi.insertEmptyBlock(range, li);
|
||||
}
|
||||
} else {
|
||||
blockApi.split();
|
||||
}
|
||||
list.merge();
|
||||
range.scrollIntoView();
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -244,6 +244,20 @@ export default class Clipboard implements ClipboardInterface {
|
|||
const curentElement = document.querySelector(
|
||||
`[${DATA_ID}=${dataId}]`,
|
||||
);
|
||||
// 补充自定义列表丢失的卡片
|
||||
if (
|
||||
node.isCustomize(childElement) &&
|
||||
!childElement.first()?.isCard() &&
|
||||
curentElement?.firstChild
|
||||
) {
|
||||
childElement.prepend(
|
||||
node.clone(
|
||||
$(curentElement.firstChild),
|
||||
true,
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
let parent: NodeInterface | Node | null | undefined =
|
||||
curentElement?.parentElement;
|
||||
parent = parent ? $(parent.cloneNode(false)) : null;
|
||||
|
|
|
@ -58,21 +58,25 @@ class List implements ListModelInterface {
|
|||
* @param node 节点
|
||||
*/
|
||||
isEmptyItem(node: NodeInterface): boolean {
|
||||
const children = node
|
||||
.children()
|
||||
.toArray()
|
||||
.filter((child) => !child.isCursor());
|
||||
const nodeApi = this.editor.node;
|
||||
return (
|
||||
//节点名称必须为li
|
||||
'li' === node.name &&
|
||||
//空节点
|
||||
(this.editor.node.isEmpty(node) ||
|
||||
(nodeApi.isEmpty(node) ||
|
||||
//子节点只有一个,如果是自定义列表并且第一个是卡片 或者第一个节点是 br标签,就是空节点
|
||||
(1 === node.children().length
|
||||
? (node.hasClass(this.CUSTOMZIE_LI_CLASS) &&
|
||||
node.first()?.isCard()) ||
|
||||
'br' === node.first()?.name
|
||||
(1 === children.length
|
||||
? (nodeApi.isCustomize(node) && children[0].isCard()) ||
|
||||
'br' === children[0].name
|
||||
: //子节点有两个,并且是自定义列表而且第一个是卡片,并且第二个节点是br标签
|
||||
2 === node.children().length &&
|
||||
node.hasClass(this.CUSTOMZIE_LI_CLASS) &&
|
||||
!!node.first()?.isCard() &&
|
||||
'br' === node.last()?.name))
|
||||
2 === children.length &&
|
||||
nodeApi.isCustomize(node) &&
|
||||
!!children[0].isCard() &&
|
||||
'br' === children[1].name))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -404,7 +408,11 @@ class List implements ListModelInterface {
|
|||
let afterListElementClone: NodeInterface | undefined;
|
||||
|
||||
if (rightList.length > 0 && afterListElement) {
|
||||
afterListElementClone = node.clone(afterListElement, false);
|
||||
afterListElementClone = node.clone(
|
||||
afterListElement,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
rightList.forEach((li) => {
|
||||
afterListElementClone?.append(li[0]);
|
||||
});
|
||||
|
@ -414,7 +422,11 @@ class List implements ListModelInterface {
|
|||
let beforeListElementClone: NodeInterface | undefined;
|
||||
//将 middleList 集合添加到前方列表节点内
|
||||
if (middleList.length > 0 && beforeListElement) {
|
||||
beforeListElementClone = node.clone(beforeListElement, false);
|
||||
beforeListElementClone = node.clone(
|
||||
beforeListElement,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
middleList.forEach((li) => {
|
||||
beforeListElementClone?.append(li[0]);
|
||||
});
|
||||
|
@ -849,6 +861,12 @@ class List implements ListModelInterface {
|
|||
parent?.prev()?.last()?.append(startLi.children());
|
||||
parent?.remove();
|
||||
} else if (parent) {
|
||||
if (
|
||||
this.isEmptyItem(startLi) &&
|
||||
parent.children().length === 1
|
||||
) {
|
||||
parent.remove();
|
||||
}
|
||||
const mergeNodes = [parent];
|
||||
const prev = beginNode.prev();
|
||||
if (prev && node.isList(prev)) mergeNodes.push(prev);
|
||||
|
|
|
@ -139,6 +139,7 @@ class NodeId implements NodeIdInterface {
|
|||
// 不符合规则
|
||||
const nodeRules = rules[node.name];
|
||||
if (
|
||||
!nodeRules ||
|
||||
nodeRules.length === 0 ||
|
||||
!nodeRules.some((rule) =>
|
||||
this.editor.schema.checkNode(
|
||||
|
|
|
@ -916,14 +916,14 @@ class NodeModel implements NodeModelInterface {
|
|||
clone(
|
||||
node: NodeInterface,
|
||||
deep?: boolean,
|
||||
copyId: boolean = false,
|
||||
copyId: boolean = true,
|
||||
): NodeInterface {
|
||||
const { nodeId } = this.editor;
|
||||
const nodes: Array<Node> = [];
|
||||
node.each((node) => {
|
||||
const cloneNode = node.cloneNode(deep);
|
||||
const nodeDom = $(cloneNode);
|
||||
if (copyId) {
|
||||
if (!copyId) {
|
||||
nodeId.generateAll(nodeDom, true);
|
||||
if (nodeId.isNeed(nodeDom)) {
|
||||
nodeId.generate(nodeDom, true);
|
||||
|
|
Loading…
Reference in New Issue