Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 1, 2023
1 parent f965ef0 commit 37892e7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
43 changes: 42 additions & 1 deletion app/src/protyle/render/av/col.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const getEditHTML = (options: {
html += `<button class="b3-menu__separator"></button>
<button class="b3-menu__item">
<svg class="b3-menu__icon" style=""><use xlink:href="#iconAdd"></use></svg>
<span class="b3-menu__label"><input data-type="addOption" style="margin: 4px 0" class="b3-text-field" type="text" placeholder="Enter ${window.siyuan.languages.addAttr}"></span>
<span class="b3-menu__label"><input data-type="addOption" style="margin: 4px 0" class="b3-text-field fn__block" type="text" placeholder="Enter ${window.siyuan.languages.addAttr}"></span>
</button>`;
colData.options.forEach(item => {
html += `<button class="b3-menu__item${html ? "" : " b3-menu__item--current"}" draggable="true" data-name="${item.name}" data-color="${item.color}">
Expand All @@ -129,6 +129,11 @@ export const getEditHTML = (options: {
<svg class="b3-menu__icon"><use xlink:href="#iconFormat"></use></svg>
<span class="b3-menu__label">${window.siyuan.languages.format}</span>
<span class="b3-menu__accelerator">${getLabelByNumberFormat(colData.numberFormat)}</span>
</button>`;
} else if (colData.type === "template") {
html += `<button class="b3-menu__separator"></button>
<button class="b3-menu__item">
<textarea placeholder="${window.siyuan.languages.template}" data-type="updateTemplate" style="margin: 4px 0" cols="1" class="fn__block b3-text-field">${colData.template}</textarea>
</button>`;
}
return `<div class="b3-menu__items">
Expand Down Expand Up @@ -185,6 +190,42 @@ export const bindEditEvent = (options: { protyle: IProtyle, data: IAV, menuEleme
options.menuElement.parentElement.remove();
}
});

const tplElement = options.menuElement.querySelector('[data-type="updateTemplate"]') as HTMLTextAreaElement
if (tplElement) {
tplElement.addEventListener("blur", () => {
const newValue = tplElement.value;
if (newValue === colData.template) {
return;
}
transaction(options.protyle, [{
action: "updateAttrViewColTemplate",
id: colId,
avID,
data: newValue,
type: colData.type,
}], [{
action: "updateAttrViewColTemplate",
id: colId,
avID,
data: colData.template,
type: colData.type,
}]);
colData.template = newValue;
});
tplElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (event.isComposing) {
return;
}
if (event.key === "Escape") {
options.menuElement.parentElement.remove();
} else if (event.key === "Enter") {
tplElement.dispatchEvent(new CustomEvent("blur"));
options.menuElement.parentElement.remove();
}
});
}

const addOptionElement = options.menuElement.querySelector('[data-type="addOption"]') as HTMLInputElement;
if (!addOptionElement) {
return;
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 @@ -63,7 +63,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
}
let text = "";
if (["text", "template"].includes(cell.valueType)) {
text = `<span class="av__celltext">${cell.value ? cell.value[cell.valueType as "text"].content : ""}</span>`;
text = `<span class="av__celltext">${cell.value ? (cell.value[cell.valueType as "text"].content || "") : ""}</span>`;
} else if (["url", "email", "phone"].includes(cell.valueType)) {
const urlContent = cell.value ? cell.value[cell.valueType as "url"].content : "";
// https://github.com/siyuan-note/siyuan/issues/9291
Expand Down
3 changes: 2 additions & 1 deletion app/src/protyle/wysiwyg/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ 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", "replaceAttrViewBlock"].includes(operation.action)) {
"setAttrViewSorts", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat",
"replaceAttrViewBlock", "updateAttrViewColTemplate"].includes(operation.action)) {
refreshAV(protyle, operation);
}
};
Expand Down
2 changes: 2 additions & 0 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TOperation =
| "removeFlashcards"
| "updateAttrViewCell"
| "updateAttrViewCol"
| "updateAttrViewColTemplate"
| "sortAttrViewRow"
| "sortAttrViewCol"
| "setAttrViewColHidden"
Expand Down Expand Up @@ -1022,6 +1023,7 @@ interface IAVColumn {
hidden: boolean,
type: TAVCol,
numberFormat: string,
template: string,
calc: {
operator: string,
result: IAVCellValue
Expand Down

0 comments on commit 37892e7

Please sign in to comment.