fix: sub-cards cannot be selected in editable cards

This commit is contained in:
yanmao 2021-12-25 20:12:27 +08:00
parent c0b8fe9dfa
commit ba9cd4542e
3 changed files with 26 additions and 10 deletions

View File

@ -431,7 +431,10 @@ class CardModel implements CardModelInterface {
) {
const range = editor.change.range.get().cloneRange();
if (
range.startNode.closest(EDITABLE_SELECTOR).length > 0 ||
(range.startNode.closest(EDITABLE_SELECTOR).length > 0 &&
(!event ||
!event?.target ||
!this.closest(event.target as Node, false))) ||
(card.isEditable && range.collapsed) ||
card.isMaximize
)
@ -659,14 +662,27 @@ class CardModel implements CardModelInterface {
this.gc();
const asyncRenderCards: Array<CardInterface> = [];
cards.each((node) => {
const cardNode = $(node);
cardNode.find(`${CARD_SELECTOR},${READY_CARD_SELECTOR}`).remove();
cardNode.empty();
const readyCards: NodeInterface[] = [];
const allCards = cards.toArray();
// 卡片内的子节点卡片移除
allCards.forEach((cardNode) => {
if (!readyCards.find((node) => node.equal(cardNode))) {
readyCards.push(cardNode);
}
const childCards = cardNode
.find(`${CARD_SELECTOR},${READY_CARD_SELECTOR}`)
.toArray();
childCards.forEach((childCard) => {
if (childCard.equal(cardNode)) return;
const index = readyCards.findIndex((node) =>
node.equal(childCard),
);
if (index > -1) {
readyCards.splice(index, 1);
}
});
});
cards.each((node) => {
const cardNode = $(node);
if (cardNode.length === 0 || !cardNode[0].parentNode) return;
readyCards.forEach((cardNode) => {
const readyKey = cardNode.attributes(READY_CARD_KEY);
const key = cardNode.attributes(CARD_KEY);
const name = readyKey || key;

View File

@ -261,7 +261,6 @@ class Producer extends EventEmitter2 {
? removedNode['__index']
: this.getRemoveNodeIndex(record, records);
const rIndex = _index + JSON0_INDEX.ELEMENT;
console.log(removedNode, removedNode['test']);
// 删除的情况下,目标节点也应该获取 __index 不然在还有新增的情况会导致path不正确
const newPath = path?.concat();
if (newPath && newPath.length > 0) {

View File

@ -227,7 +227,7 @@ class ControllBar extends EventEmitter2 implements ControllBarInterface {
)
.on('click', (event) => this.onClickRowsHeader(event))
.on('dragstart', (event) => this.onDragStartRowsHeader(event));
this.tableHeader?.on('click', (event) =>
this.tableHeader?.on('mousedown', (event) =>
this.onClickTableHeader(event),
);
this.table.wrapper?.on('contextmenu', (event) =>
@ -524,6 +524,7 @@ class ControllBar extends EventEmitter2 implements ControllBarInterface {
* @param event
*/
onClickTableHeader(event: MouseEvent) {
event.preventDefault();
const { selection } = this.table;
if (this.tableHeader?.hasClass('selected')) {
selection.clearSelect();