Skip to content

Commit

Permalink
🎨 #9294
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Sep 27, 2023
1 parent 7a203ea commit 9c416cb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
8 changes: 5 additions & 3 deletions app/src/assets/scss/business/_av.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
position: absolute;
z-index: 1;
animation: 1s linear infinite keyframes-pulse;
background: linear-gradient(90deg,transparent 0,rgba(255,255,255,.4) 50%,transparent 100%);
background: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, .4) 50%, transparent 100%);
display: block;
height: 100%;
width: 100%;
Expand Down Expand Up @@ -87,7 +87,8 @@
font-size: 87.5%;

&:hover {
[data-type="block-ref"] {
[data-type="block-ref"],
[data-type="createdoc"] {
display: block;
}

Expand Down Expand Up @@ -198,7 +199,8 @@
align-items: center;
transition: var(--b3-transition);

[data-type="block-ref"] {
[data-type="block-ref"],
[data-type="createdoc"] {
display: none;
position: absolute;
right: 5px;
Expand Down
55 changes: 30 additions & 25 deletions app/src/protyle/render/av/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,35 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
return true;
}

const createDocElement = hasClosestByAttribute(event.target, "data-type", "createdoc");
if (createDocElement) {
fetchPost("/api/filetree/getHPathByPath", {
notebook: protyle.notebookId,
path: protyle.path,
}, (response) => {
fetchPost("/api/filetree/createDocWithMd", {
notebook: protyle.notebookId,
path: pathPosix().join(response.data, createDocElement.previousElementSibling.textContent.trim() || "Untitled"),
parentID: protyle.block.rootID,
markdown: ""
}, response => {
transaction(protyle, [{
action: "updateAttrViewCell",
id: createDocElement.parentElement.dataset.id,
avID: blockElement.getAttribute("data-av-id"),
keyID: createDocElement.parentElement.dataset.colId,
rowID: createDocElement.parentElement.parentElement.dataset.id,
data: {
isDetached: false
}
}]);
});
});
event.preventDefault();
event.stopPropagation();
return true;
}

const cellElement = hasClosestByClassName(event.target, "av__cell");
if (cellElement && !cellElement.parentElement.classList.contains("av__row--header")) {
cellElement.parentElement.parentElement.querySelectorAll(".av__row--select").forEach(item => {
Expand All @@ -175,7 +204,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
if (addRowElement) {
const avID = blockElement.getAttribute("data-av-id");
const srcIDs = [Lute.NewNodeID()];
const previousID = addRowElement.getAttribute("data-id") || "";
const previousID = addRowElement.previousElementSibling.getAttribute("data-id") || "";
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
Expand All @@ -193,30 +222,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
return true;
}

const createDocElement = hasClosestByAttribute(event.target, "data-type","createdoc");
if (createDocElement) {
// fetchPost("/api/filetree/createDocWithMd", {
// notebook: protyle.notebookId,
// path: pathPosix().join(pathString, realFileName),
// parentID: protyle.block.rootID,
// markdown: ""
// }, response => {
// transaction(protyle, [{
// action: "updateAttrViewCell",
// id: cellId,
// avID,
// keyID: colId,
// rowID,
// data: {
// isDetached: false
// }
// }]);
// });
event.preventDefault();
event.stopPropagation();
return true;
}

return false;
};

Expand Down
4 changes: 2 additions & 2 deletions app/src/protyle/render/av/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
if (!type) {
type = cellElements[0].parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElements[0].getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol;
}
if (type === "block" && (cellElements.length > 0 || !cellElements[0].getAttribute("data-detached"))) {
if (type === "block" && (cellElements.length > 1 || !cellElements[0].getAttribute("data-detached"))) {
return;
}
const cellRect = cellElements[0].getBoundingClientRect();
Expand Down Expand Up @@ -416,7 +416,7 @@ const updateCellValue = (protyle: IProtyle, type: TAVCol, cellElements: HTMLElem
content: (avMaskElement.querySelector(".b3-text-field") as HTMLInputElement).value
};
const oldValue: { content: string | number, isNotEmpty?: boolean } = {
content: item.textContent.trim()
content: type === "block" ? item.firstElementChild.textContent.trim() : item.textContent.trim()
};
if (type === "number") {
oldValue.content = parseFloat(oldValue.content as string);
Expand Down
3 changes: 2 additions & 1 deletion app/src/protyle/render/av/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`;
}
} else if (cell.valueType === "block") {
text = `<span class="av__celltext"${cell.value.isDetached ? ' data-detached="true""' : ""}>${cell.value.block.content || ""}</span>`;
text = `<span class="av__celltext">${cell.value.block.content || ""}</span>`;
if (cell.value?.isDetached) {
text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="createdoc" >${window.siyuan.languages.new}</span>`;
} else {
Expand Down Expand Up @@ -112,6 +112,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
}
tableHTML += `<div class="av__cell" data-id="${cell.id}" data-col-id="${data.columns[index].id}"
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""}
${cell.value?.isDetached ? ' data-detached="true"' : ""}
style="width: ${data.columns[index].width || "200px"};
${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
${data.columns[index].wrap ? "" : "white-space: nowrap;"}
Expand Down

0 comments on commit 9c416cb

Please sign in to comment.