Skip to content

Commit

Permalink
🎨 #9294
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Sep 28, 2023
1 parent 92467f2 commit 14d88d6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 44 deletions.
4 changes: 2 additions & 2 deletions app/src/assets/scss/business/_av.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

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

Expand Down Expand Up @@ -200,7 +200,7 @@
transition: var(--b3-transition);

[data-type="block-ref"],
[data-type="createdoc"] {
[data-type="block-more"] {
display: none;
position: absolute;
right: 5px;
Expand Down
38 changes: 23 additions & 15 deletions app/src/protyle/hint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ ${unicode2Emoji(emoji.unicode)}</button>`;
}
this.element.style.width = Math.max(protyle.element.clientWidth / 2, 320) + "px";
if (this.source === "av") {
const blockElement = hasClosestBlock(protyle.toolbar.range.startContainer);
if (blockElement) {
const rowAddRect = blockElement.querySelector(".av__row--add").getBoundingClientRect();
setPosition(this.element, rowAddRect.left, rowAddRect.bottom, rowAddRect.height);
const cellElement = hasClosestByClassName(protyle.toolbar.range.startContainer, "av__cell");
if (cellElement) {
const cellRect = cellElement.getBoundingClientRect();
setPosition(this.element, cellRect.left, cellRect.bottom, cellRect.height);
}
} else {
const textareaPosition = getSelectionPosition(protyle.wysiwyg.element);
Expand Down Expand Up @@ -411,9 +411,12 @@ ${genHintItemHTML(item)}
return;
}
if (this.source === "av") {
const cellElement = hasClosestByClassName(protyle.toolbar.range.startContainer, "av__cell");
if (!cellElement) {
return;
}
const previousID = cellElement.dataset.blockId
const avID = nodeElement.getAttribute("data-av-id");
const rowsElement = nodeElement.querySelectorAll(".av__row");
const previousID = rowsElement[rowsElement.length - 1].getAttribute("data-id");
let tempElement = document.createElement("div");
tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, "");
tempElement = tempElement.firstElementChild as HTMLDivElement;
Expand All @@ -428,31 +431,36 @@ ${genHintItemHTML(item)}
markdown: ""
}, response => {
transaction(protyle, [{
action: "insertAttrViewBlock",
action: "replaceAttrViewBlock",
avID,
previousID,
srcIDs: [response.data],
nextID: response.data,
isDetached: false,
}], [{
action: "removeAttrViewBlock",
srcIDs: [response.data],
action: "replaceAttrViewBlock",
avID,
previousID: response.data,
nextID: previousID,
isDetached: true,
}]);
});
});
} else {
const sourceId = tempElement.getAttribute("data-id");
transaction(protyle, [{
action: "insertAttrViewBlock",
action: "replaceAttrViewBlock",
avID,
previousID,
srcIDs: [sourceId],
nextID: sourceId,
isDetached: false,
}], [{
action: "removeAttrViewBlock",
srcIDs: [sourceId],
action: "replaceAttrViewBlock",
avID,
previousID: sourceId,
nextID: previousID,
isDetached: true,
}]);
}
insertAttrViewBlockAnimation(nodeElement, 1, previousID);
return;
}
this.enableExtend = false;
Expand Down
32 changes: 7 additions & 25 deletions app/src/protyle/render/av/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
if (protyle.disabled) {
return false;
}

const addElement = hasClosestByAttribute(event.target, "data-type", "av-header-add");
if (addElement) {
const addMenu = addCol(protyle, blockElement);
Expand Down Expand Up @@ -151,31 +152,12 @@ 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: "",
id: createDocElement.parentElement.dataset.blockId,
}, 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
}
}]);
});
});
const blockMoreElement = hasClosestByAttribute(event.target, "data-type", "block-more");
if (blockMoreElement) {
protyle.toolbar.range = document.createRange();
protyle.toolbar.range.selectNodeContents(blockMoreElement);
focusByRange(protyle.toolbar.range);
hintRef(blockMoreElement.previousElementSibling.textContent.trim(), protyle, "av");
event.preventDefault();
event.stopPropagation();
return true;
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/render/av/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
} else if (cell.valueType === "block") {
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>`;
text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="block-more" >${window.siyuan.languages.more}</span>`;
} else {
text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="block-ref" data-id="${cell.value.block.id}" data-subtype="s">${window.siyuan.languages.openBy}</span>`;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/wysiwyg/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
} else if (["addAttrViewCol", "insertAttrViewBlock", "updateAttrViewCol", "updateAttrViewColOptions",
"updateAttrViewColOption", "updateAttrViewCell", "sortAttrViewRow", "sortAttrViewCol", "setAttrViewColHidden",
"setAttrViewColWrap", "setAttrViewColWidth", "removeAttrViewColOption", "setAttrViewName", "setAttrViewFilters",
"setAttrViewSorts", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat"].includes(operation.action)) {
"setAttrViewSorts", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat", "replaceAttrViewBlock"].includes(operation.action)) {
refreshAV(protyle, operation);
}
};
Expand Down
1 change: 1 addition & 0 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type TOperation =
| "setAttrViewSorts"
| "setAttrViewColCalc"
| "updateAttrViewColNumberFormat"
| "replaceAttrViewBlock"
type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins"
type TCardType = "doc" | "notebook" | "all"
type TEventBus = "ws-main" |
Expand Down

0 comments on commit 14d88d6

Please sign in to comment.