This commit is contained in:
Vanessa 2024-03-08 12:37:54 +08:00
parent 1c4718fcb9
commit 67f095c522
7 changed files with 26 additions and 26 deletions

View file

@ -81,7 +81,7 @@ const editDialog = (customName: string, customMemo: string) => {
dialog.destroy(); dialog.destroy();
}); });
nameElement.focus(); nameElement.focus();
} };
const customDialog = (protyle: IProtyle, ids: string[], elements: Element[]) => { const customDialog = (protyle: IProtyle, ids: string[], elements: Element[]) => {
const dialog = new Dialog({ const dialog = new Dialog({
@ -134,7 +134,7 @@ const customDialog = (protyle: IProtyle, ids: string[], elements: Element[]) =>
dialog.destroy(); dialog.destroy();
}); });
nameElement.focus(); nameElement.focus();
} };
const filterAI = (element: HTMLElement, inputElement: HTMLInputElement) => { const filterAI = (element: HTMLElement, inputElement: HTMLInputElement) => {
element.querySelectorAll(".b3-list-item").forEach(item => { element.querySelectorAll(".b3-list-item").forEach(item => {
@ -143,17 +143,17 @@ const filterAI = (element: HTMLElement, inputElement: HTMLInputElement) => {
} else { } else {
item.classList.add("fn__none"); item.classList.add("fn__none");
} }
}) });
element.querySelectorAll('.b3-menu__separator').forEach(item => { element.querySelectorAll(".b3-menu__separator").forEach(item => {
if (inputElement.value) { if (inputElement.value) {
item.classList.add("fn__none"); item.classList.add("fn__none");
} else { } else {
item.classList.remove("fn__none"); item.classList.remove("fn__none");
} }
}) });
element.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus"); element.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
element.querySelector(".b3-list-item:not(.fn__none)").classList.add("b3-list-item--focus"); element.querySelector(".b3-list-item:not(.fn__none)").classList.add("b3-list-item--focus");
} };
export const AIActions = (elements: Element[], protyle: IProtyle) => { export const AIActions = (elements: Element[], protyle: IProtyle) => {
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
@ -164,7 +164,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
const menu = new Menu("ai", () => { const menu = new Menu("ai", () => {
focusByRange(protyle.toolbar.range); focusByRange(protyle.toolbar.range);
}); });
let customHTML = "" let customHTML = "";
window.siyuan.storage[Constants.LOCAL_AI].forEach((item: { name: string, memo: string }) => { window.siyuan.storage[Constants.LOCAL_AI].forEach((item: { name: string, memo: string }) => {
customHTML += `<div data-action="${item.memo || item.name}" class="b3-list-item b3-list-item--narrow ariaLabel" aria-label="${escapeAriaLabel(item.memo)}"> customHTML += `<div data-action="${item.memo || item.name}" class="b3-list-item b3-list-item--narrow ariaLabel" aria-label="${escapeAriaLabel(item.memo)}">
<span class="b3-list-item__text">${escapeHtml(item.name)}</span> <span class="b3-list-item__text">${escapeHtml(item.name)}</span>
@ -258,7 +258,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
}); });
inputElement.addEventListener("compositionend", () => { inputElement.addEventListener("compositionend", () => {
filterAI(element, inputElement); filterAI(element, inputElement);
}) });
inputElement.addEventListener("input", (event: KeyboardEvent) => { inputElement.addEventListener("input", (event: KeyboardEvent) => {
if (event.isComposing) { if (event.isComposing) {
return; return;

View file

@ -160,12 +160,12 @@ export const ai = {
</div>`; </div>`;
}, },
bindEvent: () => { bindEvent: () => {
const togglePassword = ai.element.querySelector('.b3-form__icona-icon[data-action="togglePassword"]') const togglePassword = ai.element.querySelector('.b3-form__icona-icon[data-action="togglePassword"]');
togglePassword.addEventListener("click", () => { togglePassword.addEventListener("click", () => {
const isEye = togglePassword.firstElementChild.getAttribute("xlink:href") === "#iconEye"; const isEye = togglePassword.firstElementChild.getAttribute("xlink:href") === "#iconEye";
togglePassword.firstElementChild.setAttribute("xlink:href", isEye ? "#iconEyeoff" : "#iconEye"); togglePassword.firstElementChild.setAttribute("xlink:href", isEye ? "#iconEyeoff" : "#iconEye");
togglePassword.previousElementSibling.setAttribute("type", isEye ? "text" : "password"); togglePassword.previousElementSibling.setAttribute("type", isEye ? "text" : "password");
}) });
ai.element.querySelectorAll("input, select").forEach((item) => { ai.element.querySelectorAll("input, select").forEach((item) => {
item.addEventListener("change", () => { item.addEventListener("change", () => {
fetchPost("/api/setting/setAI", { fetchPost("/api/setting/setAI", {

View file

@ -140,9 +140,9 @@ export const setFilter = async (options: {
contents: [newValue], contents: [newValue],
}, },
type: "rollup" type: "rollup"
} };
} else { } else {
newFilter.value = newValue newFilter.value = newValue;
} }
let isSame = false; let isSame = false;
options.data.view.filters.find((filter, index) => { options.data.view.filters.find((filter, index) => {
@ -225,7 +225,7 @@ export const setFilter = async (options: {
type: filterValue.type type: filterValue.type
}; };
} else { } else {
filterValue = item.value.rollup.contents[0] filterValue = item.value.rollup.contents[0];
} }
return true; return true;
} }

View file

@ -366,10 +366,10 @@ export const openMenuPanel = (options: {
} }
targetElement.classList.remove("dragover__bottom", "dragover__top"); targetElement.classList.remove("dragover__bottom", "dragover__top");
const blockIDs: string[] = []; const blockIDs: string[] = [];
const contents: IAVCellValue[] = [] const contents: IAVCellValue[] = [];
targetElement.parentElement.querySelectorAll(".fn__grab").forEach(item => { targetElement.parentElement.querySelectorAll(".fn__grab").forEach(item => {
const dateElement = item.nextElementSibling as HTMLElement const dateElement = item.nextElementSibling as HTMLElement;
blockIDs.push(dateElement.dataset.id) blockIDs.push(dateElement.dataset.id);
contents.push({ contents.push({
isDetached: !dateElement.style.color, isDetached: !dateElement.style.color,
type: "block", type: "block",
@ -377,8 +377,8 @@ export const openMenuPanel = (options: {
content: dateElement.textContent, content: dateElement.textContent,
id: dateElement.dataset.id id: dateElement.dataset.id
} }
}) });
}) });
updateCellsValue(options.protyle, options.blockElement as HTMLElement, { updateCellsValue(options.protyle, options.blockElement as HTMLElement, {
blockIDs, blockIDs,
contents, contents,

View file

@ -237,11 +237,11 @@ const filterItem = (menuElement: Element, cellElement: HTMLElement, keyword: str
const cells = response.data.rows.values as IAVCellValue[] || []; const cells = response.data.rows.values as IAVCellValue[] || [];
let html = ""; let html = "";
let selectHTML = ""; let selectHTML = "";
const hasIds: string[] = [] const hasIds: string[] = [];
cellElement.querySelectorAll("span").forEach((item) => { cellElement.querySelectorAll("span").forEach((item) => {
hasIds.push(item.dataset.id); hasIds.push(item.dataset.id);
selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item${item.textContent.indexOf(keyword) > -1 ? "" : " fn__none"}" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || "Untitled")}</button>`; selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item${item.textContent.indexOf(keyword) > -1 ? "" : " fn__none"}" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || "Untitled")}</button>`;
}) });
cells.forEach((item) => { cells.forEach((item) => {
if (!hasIds.includes(item.block.id)) { if (!hasIds.includes(item.block.id)) {
html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || "Untitled"); html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || "Untitled");
@ -267,11 +267,11 @@ export const bindRelationEvent = (options: {
const cells = response.data.rows.values as IAVCellValue[] || []; const cells = response.data.rows.values as IAVCellValue[] || [];
let html = ""; let html = "";
let selectHTML = ""; let selectHTML = "";
const hasIds: string[] = [] const hasIds: string[] = [];
options.cellElements[0].querySelectorAll("span").forEach((item) => { options.cellElements[0].querySelectorAll("span").forEach((item) => {
hasIds.push(item.dataset.id); hasIds.push(item.dataset.id);
selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || "Untitled")}</button>`; selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || "Untitled")}</button>`;
}) });
cells.forEach((item) => { cells.forEach((item) => {
if (!hasIds.includes(item.block.id)) { if (!hasIds.includes(item.block.id)) {
html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || "Untitled"); html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || "Untitled");

View file

@ -79,10 +79,10 @@ export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, v
if (!hasFilter) { if (!hasFilter) {
data.filters.find(filterItem => { data.filters.find(filterItem => {
if (filterItem.value.type === item.type && item.id === filterItem.column) { if (filterItem.value.type === item.type && item.id === filterItem.column) {
hasFilter = true hasFilter = true;
return true return true;
} }
}) });
} }
if (!item.hidden) { if (!item.hidden) {
if (item.pin) { if (item.pin) {

View file

@ -1412,7 +1412,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (selectsElement.length === 0) { if (selectsElement.length === 0) {
selectsElement = [nodeElement]; selectsElement = [nodeElement];
} }
AIActions(selectsElement, protyle) AIActions(selectsElement, protyle);
return; return;
} }