Skip to content

Commit 978f141

Browse files
committed
🎨 #10049
1 parent 98180f2 commit 978f141

File tree

3 files changed

+24
-37
lines changed

3 files changed

+24
-37
lines changed

app/src/protyle/render/av/action.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
214214
}
215215
const cellType = getTypeByCellElement(target);
216216
// TODO 点击单元格的时候, lineNumber 选中整行
217-
if (cellType === "updated" || cellType === "created" || cellType === "lineNumber" || (cellType === "block" && !target.getAttribute("data-detached"))) {
217+
if (cellType === "updated" || cellType === "created" || cellType === "lineNumber") {
218218
selectRow(rowElement.querySelector(".av__firstcol"), "toggle");
219219
} else {
220220
scrollElement.querySelectorAll(".av__row--select").forEach(item => {
@@ -584,18 +584,9 @@ ${window.siyuan.languages.insertRowAfter.replace("${x}", `<span class="fn__space
584584
});
585585
const editAttrSubmenu: IMenu[] = [];
586586
rowElement.parentElement.querySelectorAll(".av__row--header .av__cell").forEach((cellElement: HTMLElement) => {
587-
let hideBlock = false;
588587
const selectElements: HTMLElement[] = Array.from(blockElement.querySelectorAll(`.av__row--select:not(.av__row--header) .av__cell[data-col-id="${cellElement.dataset.colId}"]`));
589-
if (cellElement.dataset.dtype === "block") {
590-
selectElements.find(item => {
591-
if (!item.dataset.detached) {
592-
hideBlock = true;
593-
return true;
594-
}
595-
});
596-
}
597588
const type = cellElement.getAttribute("data-dtype") as TAVCol;
598-
if (!hideBlock && !["updated", "created"].includes(type)) {
589+
if (!["updated", "created"].includes(type)) {
599590
const icon = cellElement.dataset.icon;
600591
editAttrSubmenu.push({
601592
iconHTML: icon ? unicode2Emoji(icon, "b3-menu__icon", true) : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(type)}"></use></svg>`,

app/src/protyle/render/av/blockAttr.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const genAVValueHTML = (value: IAVCellValue) => {
6161
let html = "";
6262
switch (value.type) {
6363
case "block":
64-
html = `<div class="fn__flex-1" placeholder="${window.siyuan.languages.empty}">${value.block.content}</div>`;
64+
html = `<input value="${value.block.content}" type="text" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">`;
6565
break;
6666
case "text":
6767
html = `<textarea style="resize: vertical" rows="${value.text.content.split("\n").length}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">${value.text.content}</textarea>`;
@@ -198,7 +198,7 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
198198
<div data-av-id="${table.avID}" data-col-id="${item.values[0].keyID}" data-block-id="${item.values[0].blockID}" data-id="${item.values[0].id}" data-type="${item.values[0].type}"
199199
data-options="${item.key?.options ? escapeAttr(JSON.stringify(item.key.options)) : "[]"}"
200200
${["text", "number", "date", "url", "phone", "template", "email"].includes(item.values[0].type) ? "" : `placeholder="${window.siyuan.languages.empty}"`}
201-
class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes(item.values[0].type) ? "" : " custom-attr__avvalue"}${["block", "created", "updated"].includes(item.values[0].type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(item.values[0])}</div>
201+
class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"].includes(item.values[0].type) ? "" : " custom-attr__avvalue"}${["created", "updated"].includes(item.values[0].type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(item.values[0])}</div>
202202
</div>`;
203203
});
204204
innerHTML += `<div class="fn__hr"></div>

app/src/protyle/render/av/cell.ts

+20-24
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ export const genCellValue = (colType: TAVCol, value: string | any) => {
275275
}
276276
}
277277
if (colType === "block") {
278-
cellValue.isDetached = true;
278+
if (typeof value === "object" && value.id) {
279+
cellValue.isDetached = false;
280+
} else {
281+
cellValue.isDetached = true;
282+
}
279283
}
280284
return cellValue;
281285
};
@@ -365,9 +369,6 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
365369
if (type === "updated" || type === "created" || document.querySelector(".av__mask")) {
366370
return;
367371
}
368-
if (type === "block" && (cellElements.length > 1 || !cellElements[0].getAttribute("data-detached"))) {
369-
return;
370-
}
371372
const blockElement = hasClosestBlock(cellElements[0]);
372373
if (!blockElement) {
373374
return;
@@ -688,6 +689,11 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
688689
});
689690
newValue = oldValue.mSelect.concat(newMSelectValue);
690691
}
692+
} else if (type === "block" && typeof value === "string" && oldValue.block.id) {
693+
newValue = {
694+
content: value,
695+
id: oldValue.block.id
696+
};
691697
}
692698
const cellValue = genCellValue(type, newValue);
693699
cellValue.id = cellId;
@@ -703,26 +709,16 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
703709
if (objEquals(cellValue, oldValue)) {
704710
return;
705711
}
706-
if (type === "block" && !item.dataset.detached) {
707-
const newId = Lute.NewNodeID();
708-
doOperations.push({
709-
action: "unbindAttrViewBlock",
710-
id: rowID,
711-
nextID: newId,
712-
avID,
713-
});
714-
rowElement.dataset.id = newId;
715-
item.dataset.blockId = newId;
716-
} else {
717-
doOperations.push({
718-
action: "updateAttrViewCell",
719-
id: cellId,
720-
avID,
721-
keyID: colId,
722-
rowID,
723-
data: cellValue
724-
});
725-
}
712+
713+
doOperations.push({
714+
action: "updateAttrViewCell",
715+
id: cellId,
716+
avID,
717+
keyID: colId,
718+
rowID,
719+
data: cellValue
720+
});
721+
726722
undoOperations.push({
727723
action: "updateAttrViewCell",
728724
id: cellId,

0 commit comments

Comments
 (0)