diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index 8e9049a94..9fde312ed 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -149,7 +149,7 @@ export const openFileWechatNotify = (protyle: IProtyle) => { }); }; -export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { +export const openFileAttr = (attrs: IObject, focusName = "bookmark", protyle?: IProtyle) => { let customHTML = ""; let notifyHTML = ""; let hasAV = false; @@ -187,7 +187,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { ${window.siyuan.languages.builtIn} -
+
${window.siyuan.languages.database} @@ -225,7 +225,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { ${notifyHTML}
-
+
${customHTML}
@@ -252,8 +252,8 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { target.classList.add("item--focus"); dialog.element.querySelectorAll(".custom-attr").forEach((item: HTMLElement) => { if (item.dataset.type === target.dataset.type) { - if (item.dataset.type === "av" && item.innerHTML === "") { - renderAVAttribute(item, attrs.id); + if (item.dataset.type === "NodeAttributeView" && item.innerHTML === "") { + renderAVAttribute(item, attrs.id, protyle); } item.classList.remove("fn__none"); } else { @@ -349,13 +349,13 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { }); }; -export const openAttr = (nodeElement: Element, focusName = "bookmark") => { +export const openAttr = (nodeElement: Element, focusName = "bookmark", protyle?: IProtyle) => { if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") { return; } const id = nodeElement.getAttribute("data-node-id"); fetchPost("/api/attr/getBlockAttrs", {id}, (response) => { - openFileAttr(response.data, focusName); + openFileAttr(response.data, focusName, protyle); }); }; diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index b3357a222..5f326969b 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -88,7 +88,7 @@ export class Breadcrumb { fetchPost("/api/block/getDocInfo", { id: protyle.block.rootID }, (response) => { - openFileAttr(response.data.ial); + openFileAttr(response.data.ial, "bookmark", protyle); }); } else { const targetRect = target.getBoundingClientRect(); diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 63a82ebfd..51cedbdad 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -211,7 +211,7 @@ export class Gutter { } foldElement.classList.remove("protyle-wysiwyg--hl"); } else if (window.siyuan.shiftIsPressed && !protyle.disabled) { - openAttr(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)); + openAttr(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`), "bookmark", protyle); } else { this.renderMenu(protyle, buttonElement); // https://ld246.com/article/1648433751993 @@ -1478,7 +1478,7 @@ export class Gutter { icon: "iconAttr", accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"), click() { - openAttr(nodeElement); + openAttr(nodeElement, "bookmark", protyle); } }).element); } diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index d1e629eff..7a4bf803c 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -140,7 +140,7 @@ export class Title { fetchPost("/api/block/getDocInfo", { id: protyle.block.rootID }, (response) => { - openFileAttr(response.data.ial); + openFileAttr(response.data.ial, "bookmark", protyle); }); event.preventDefault(); event.stopPropagation(); @@ -179,7 +179,7 @@ export class Title { fetchPost("/api/block/getDocInfo", { id: protyle.block.rootID }, (response) => { - openFileAttr(response.data.ial); + openFileAttr(response.data.ial, "bookmark", protyle); }); } else { const iconRect = iconElement.getBoundingClientRect(); diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts index adce9aacc..e54bd4d60 100644 --- a/app/src/protyle/header/openTitleMenu.ts +++ b/app/src/protyle/header/openTitleMenu.ts @@ -92,7 +92,7 @@ export const openTitleMenu = (protyle: IProtyle, position: { icon: "iconAttr", accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"), click() { - openFileAttr(response.data.ial); + openFileAttr(response.data.ial, "bookmark", protyle); } }).element); window.siyuan.menus.menu.append(new MenuItem({ diff --git a/app/src/protyle/render/av/asset.ts b/app/src/protyle/render/av/asset.ts index f8bb618bf..2d3f1e387 100644 --- a/app/src/protyle/render/av/asset.ts +++ b/app/src/protyle/render/av/asset.ts @@ -10,6 +10,7 @@ import {MenuItem} from "../../../menus/Menu"; import {exportAsset} from "../../../menus/util"; import {setPosition} from "../../../util/setPosition"; import {previewImage} from "../../preview/image"; +import {genAVValueHTML} from "./blockAttr"; export const bindAssetEvent = (options: { protyle: IProtyle, @@ -104,14 +105,13 @@ export const updateAssetCell = (options: { addUpdateValue?: IAVCellAssetValue[], removeContent?: string }) => { - let cellIndex = 0; + let cellIndex: number; Array.from(options.cellElements[0].parentElement.querySelectorAll(".av__cell")).find((item: HTMLElement, index) => { if (item.dataset.id === options.cellElements[0].dataset.id) { cellIndex = index; return true; } }); - const colId = options.cellElements[0].dataset.colId; const cellDoOperations: IOperation[] = []; const cellUndoOperations: IOperation[] = []; @@ -121,11 +121,19 @@ export const updateAssetCell = (options: { const rowID = item.parentElement.dataset.id; options.data.view.rows.find(row => { if (row.id === rowID) { - cellData = row.cells[cellIndex]; - // 为空时 cellId 每次请求都不一致 - cellData.id = item.dataset.id; - if (!cellData.value || !cellData.value.mAsset) { - cellData.value = {mAsset: []} as IAVCellValue; + if (typeof cellIndex === "number") { + cellData = row.cells[cellIndex]; + // 为空时 cellId 每次请求都不一致 + cellData.id = item.dataset.id; + if (!cellData.value || !cellData.value.mAsset) { + cellData.value = {mAsset: []} as IAVCellValue; + } + } else { + cellData = row.cells.find(cellItem => { + if (cellItem.id === item.dataset.id) { + return true; + } + }); } return true; } @@ -188,14 +196,18 @@ export const updateAssetCell = (options: { mAsset: oldValue } }); - updateAttrViewCellAnimation(item); + if (item.classList.contains("custom-attr__avvalue")) { + item.innerHTML = genAVValueHTML(cellData.value) + } else { + updateAttrViewCellAnimation(item); + } }); transaction(options.protyle, cellDoOperations, cellUndoOperations); const menuElement = document.querySelector(".av__panel > .b3-menu") as HTMLElement; if (menuElement) { menuElement.innerHTML = getAssetHTML(options.data.view, options.cellElements); bindAssetEvent({protyle: options.protyle, data: options.data, menuElement, cellElements: options.cellElements}); - const cellRect = options.protyle.wysiwyg.element.querySelector(`.av__cell[data-id="${options.cellElements[0].dataset.id}"]`).getBoundingClientRect(); + const cellRect = (options.cellElements[0].classList.contains("custom-attr__avvalue") ? options.cellElements[0] : options.protyle.wysiwyg.element.querySelector(`.av__cell[data-id="${options.cellElements[0].dataset.id}"]`)).getBoundingClientRect(); setTimeout(() => { setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height); }, Constants.TIMEOUT_LOAD); // 等待图片加载 @@ -251,7 +263,7 @@ export const editAssetItem = (protyle: IProtyle, data: IAV, cellElements: HTMLEl }); } }); - openMenu(protyle.app, linkAddress, false, true); + openMenu(protyle ? protyle.app : window.siyuan.ws.app, linkAddress, false, true); /// #if !BROWSER if (linkAddress?.startsWith("assets/")) { window.siyuan.menus.menu.append(new MenuItem(exportAsset(linkAddress)).element); @@ -302,7 +314,7 @@ export const addAssetLink = (protyle: IProtyle, data: IAV, cellElements: HTMLEle const rect = target.getBoundingClientRect(); menu.open({ x: rect.right, - y: rect.bottom, + y: rect.top, w: rect.width, h: rect.height, }); diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts index 1ee8498dc..d5a8b9101 100644 --- a/app/src/protyle/render/av/blockAttr.ts +++ b/app/src/protyle/render/av/blockAttr.ts @@ -5,8 +5,9 @@ import {hasClosestByAttribute} from "../../util/hasClosest"; import {Menu} from "../../../plugin/Menu"; import {Constants} from "../../../constants"; import * as dayjs from "dayjs"; +import {popTextCell} from "./cell"; -const genAVValueHTML = (value: IAVCellValue) => { +export const genAVValueHTML = (value: IAVCellValue) => { let html = ""; switch (value.type) { case "text": @@ -57,7 +58,156 @@ const genAVValueHTML = (value: IAVCellValue) => { return html; }; -export const renderAVAttribute = (element: HTMLElement, id: string) => { +const popDateMenu = (dateElement: HTMLElement) => { + const dateMenu = new Menu("custom-attr-av-date", () => { + const textElements = window.siyuan.menus.menu.element.querySelectorAll(".b3-text-field") as NodeListOf; + const hasEndDate = (window.siyuan.menus.menu.element.querySelector(".b3-switch") as HTMLInputElement).checked; + fetchPost("/api/av/setAttributeViewBlockAttr", { + avID: dateElement.dataset.avId, + keyID: dateElement.dataset.colId, + rowID: dateElement.dataset.blockId, + cellID: dateElement.dataset.id, + value: { + date: { + isNotEmpty: textElements[0].value !== "", + isNotEmpty2: textElements[1].value !== "", + content: new Date(textElements[0].value).getTime(), + content2: new Date(textElements[1].value).getTime(), + hasEndDate + } + } + }); + let dataHTML = ""; + if (textElements[0].value !== "") { + dataHTML = `${dayjs(textElements[0].value).format("YYYY-MM-DD HH:mm")}`; + } + if (hasEndDate && textElements[0].value !== "" && textElements[1].value !== "") { + dataHTML += `${dayjs(textElements[1].value).format("YYYY-MM-DD HH:mm")}`; + } + dateElement.innerHTML = dataHTML; + }); + if (dateMenu.isOpen) { + return; + } + const hasEndDate = dateElement.querySelector("svg"); + const timeElements = dateElement.querySelectorAll("span"); + dateMenu.addItem({ + iconHTML: "", + label: `` + }); + dateMenu.addItem({ + iconHTML: "", + label: `` + }); + dateMenu.addSeparator(); + dateMenu.addItem({ + iconHTML: "", + label: ``, + click(element, event) { + const switchElement = element.querySelector(".b3-switch") as HTMLInputElement; + if ((event.target as HTMLElement).tagName !== "INPUT") { + switchElement.checked = !switchElement.checked; + } else { + switchElement.outerHTML = ``; + } + window.siyuan.menus.menu.element.querySelectorAll('[type="datetime-local"]')[1].classList.toggle("fn__none"); + return true; + } + }); + dateMenu.addSeparator(); + dateMenu.addItem({ + icon: "iconTrashcan", + label: window.siyuan.languages.clear, + click() { + const textElements = window.siyuan.menus.menu.element.querySelectorAll(".b3-text-field") as NodeListOf; + textElements[0].value = ""; + textElements[1].value = ""; + (window.siyuan.menus.menu.element.querySelector(".b3-switch") as HTMLInputElement).checked = false; + } + }); + const datetRect = dateElement.getBoundingClientRect(); + dateMenu.open({ + x: datetRect.left, + y: datetRect.bottom + }); +} + +const popSelectMenu = (mSelectElement: HTMLElement) => { + const mSelectMenu = new Menu("custom-attr-av-select", () => { + const mSelect: { content: string, color: string }[] = []; + let mSelectHTML = ""; + window.siyuan.menus.menu.element.querySelectorAll(".svg").forEach(item => { + const chipElement = item.parentElement.previousElementSibling.firstElementChild as HTMLElement; + const content = chipElement.textContent.trim(); + const color = chipElement.dataset.color; + mSelect.push({ + content, + color + }); + mSelectHTML += `${content}`; + }); + fetchPost("/api/av/setAttributeViewBlockAttr", { + avID: mSelectElement.dataset.avId, + keyID: mSelectElement.dataset.colId, + rowID: mSelectElement.dataset.blockId, + cellID: mSelectElement.dataset.id, + value: { + mSelect + } + }); + mSelectElement.innerHTML = mSelectHTML; + }); + if (mSelectMenu.isOpen) { + return; + } + const names: string[] = []; + mSelectElement.querySelectorAll(".b3-chip").forEach(item => { + names.push(item.textContent.trim()); + }); + JSON.parse(mSelectElement.dataset.options || "").forEach((item: { name: string, color: string }) => { + mSelectMenu.addItem({ + iconHTML: "", + label: ` + ${item.name} +`, + accelerator: names.includes(item.name) ? '' : Constants.ZWSP, + click(element) { + const acceleratorElement = element.querySelector(".b3-menu__accelerator"); + if (mSelectElement.dataset.type === "select") { + window.siyuan.menus.menu.element.querySelectorAll(".b3-menu__accelerator").forEach(itemElement => { + if (itemElement.isSameNode(acceleratorElement)) { + if (acceleratorElement.querySelector("svg")) { + acceleratorElement.innerHTML = ""; + } else { + acceleratorElement.innerHTML = ''; + } + } else { + itemElement.innerHTML = ""; + } + }); + return false; + } + if (acceleratorElement.querySelector("svg")) { + acceleratorElement.innerHTML = ""; + } else { + acceleratorElement.innerHTML = ''; + } + return true; + } + }); + }); + const mSelecttRect = mSelectElement.getBoundingClientRect(); + mSelectMenu.open({ + x: mSelecttRect.left, + y: mSelecttRect.bottom + }); +} + +export const renderAVAttribute = (element: HTMLElement, id: string, protyle?: IProtyle) => { fetchPost("/api/av/getAttributeViewKeys", {id}, (response) => { let html = ""; response.data.forEach((table: { @@ -77,12 +227,12 @@ export const renderAVAttribute = (element: HTMLElement, id: string) => { ${table.avName || window.siyuan.languages.database}
`; table.keyValues?.forEach(item => { - html += `
+ html += `
-
${genAVValueHTML(item.values[0])} @@ -95,155 +245,21 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes const target = event.target as HTMLElement; const dateElement = hasClosestByAttribute(target, "data-type", "date"); if (dateElement) { - const dateMenu = new Menu("custom-attr-av-date", () => { - const textElements = window.siyuan.menus.menu.element.querySelectorAll(".b3-text-field") as NodeListOf; - const hasEndDate = (window.siyuan.menus.menu.element.querySelector(".b3-switch") as HTMLInputElement).checked; - fetchPost("/api/av/setAttributeViewBlockAttr", { - avID: dateElement.dataset.avId, - keyID: dateElement.dataset.keyId, - rowID: dateElement.dataset.blockId, - cellID: dateElement.dataset.id, - value: { - date: { - isNotEmpty: textElements[0].value !== "", - isNotEmpty2: textElements[1].value !== "", - content: new Date(textElements[0].value).getTime(), - content2: new Date(textElements[1].value).getTime(), - hasEndDate - } - } - }); - let dataHTML = ""; - if (textElements[0].value !== "") { - dataHTML = `${dayjs(textElements[0].value).format("YYYY-MM-DD HH:mm")}`; - } - if (hasEndDate && textElements[0].value !== "" && textElements[1].value !== "") { - dataHTML += `${dayjs(textElements[1].value).format("YYYY-MM-DD HH:mm")}`; - } - dateElement.innerHTML = dataHTML; - }); - if (dateMenu.isOpen) { - return; - } - const hasEndDate = dateElement.querySelector("svg"); - const timeElements = dateElement.querySelectorAll("span"); - dateMenu.addItem({ - iconHTML: "", - label: `` - }); - dateMenu.addItem({ - iconHTML: "", - label: `` - }); - dateMenu.addSeparator(); - dateMenu.addItem({ - iconHTML: "", - label: ``, - click(element, event) { - const switchElement = element.querySelector(".b3-switch") as HTMLInputElement; - if ((event.target as HTMLElement).tagName !== "INPUT") { - switchElement.checked = !switchElement.checked; - } else { - switchElement.outerHTML = ``; - } - window.siyuan.menus.menu.element.querySelectorAll('[type="datetime-local"]')[1].classList.toggle("fn__none"); - return true; - } - }); - dateMenu.addSeparator(); - dateMenu.addItem({ - icon: "iconTrashcan", - label: window.siyuan.languages.clear, - click() { - const textElements = window.siyuan.menus.menu.element.querySelectorAll(".b3-text-field") as NodeListOf; - textElements[0].value = ""; - textElements[1].value = ""; - (window.siyuan.menus.menu.element.querySelector(".b3-switch") as HTMLInputElement).checked = false; - } - }); - const datetRect = dateElement.getBoundingClientRect(); - dateMenu.open({ - x: datetRect.left, - y: datetRect.bottom - }); + popDateMenu(dateElement); event.stopPropagation(); event.preventDefault(); return; } const mSelectElement = hasClosestByAttribute(target, "data-type", "select") || hasClosestByAttribute(target, "data-type", "mSelect"); if (mSelectElement) { - const mSelectMenu = new Menu("custom-attr-av-select", () => { - const mSelect: { content: string, color: string }[] = []; - let mSelectHTML = ""; - window.siyuan.menus.menu.element.querySelectorAll(".svg").forEach(item => { - const chipElement = item.parentElement.previousElementSibling.firstElementChild as HTMLElement; - const content = chipElement.textContent.trim(); - const color = chipElement.dataset.color; - mSelect.push({ - content, - color - }); - mSelectHTML += `${content}`; - }); - fetchPost("/api/av/setAttributeViewBlockAttr", { - avID: mSelectElement.dataset.avId, - keyID: mSelectElement.dataset.keyId, - rowID: mSelectElement.dataset.blockId, - cellID: mSelectElement.dataset.id, - value: { - mSelect - } - }); - mSelectElement.innerHTML = mSelectHTML; - }); - if (mSelectMenu.isOpen) { - return; - } - const names: string[] = []; - mSelectElement.querySelectorAll(".b3-chip").forEach(item => { - names.push(item.textContent.trim()); - }); - JSON.parse(mSelectElement.dataset.options || "").forEach((item: { name: string, color: string }) => { - mSelectMenu.addItem({ - iconHTML: "", - label: ` - ${item.name} -`, - accelerator: names.includes(item.name) ? '' : Constants.ZWSP, - click(element) { - const acceleratorElement = element.querySelector(".b3-menu__accelerator"); - if (mSelectElement.dataset.type === "select") { - window.siyuan.menus.menu.element.querySelectorAll(".b3-menu__accelerator").forEach(itemElement => { - if (itemElement.isSameNode(acceleratorElement)) { - if (acceleratorElement.querySelector("svg")) { - acceleratorElement.innerHTML = ""; - } else { - acceleratorElement.innerHTML = ''; - } - } else { - itemElement.innerHTML = ""; - } - }); - return false; - } - if (acceleratorElement.querySelector("svg")) { - acceleratorElement.innerHTML = ""; - } else { - acceleratorElement.innerHTML = ''; - } - return true; - } - }); - }); - const mSelecttRect = mSelectElement.getBoundingClientRect(); - mSelectMenu.open({ - x: mSelecttRect.left, - y: mSelecttRect.bottom - }); + popSelectMenu(mSelectElement); + event.stopPropagation(); + event.preventDefault(); + return; + } + const mAssetElement = hasClosestByAttribute(target, "data-type", "mAsset"); + if (mAssetElement) { + popTextCell(protyle, [mAssetElement], "mAsset"); event.stopPropagation(); event.preventDefault(); return; @@ -267,7 +283,7 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes } fetchPost("/api/av/setAttributeViewBlockAttr", { avID: item.parentElement.dataset.avId, - keyID: item.parentElement.dataset.keyId, + keyID: item.parentElement.dataset.colId, rowID: item.parentElement.dataset.blockId, cellID: item.parentElement.dataset.id, value diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 87ccd69e7..6d60b75f2 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -339,8 +339,10 @@ export const openCalcMenu = (protyle: IProtyle, calcElement: HTMLElement) => { menu.open({x: calcRect.left, y: calcRect.bottom, h: calcRect.height}); }; -export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[]) => { - const type = cellElements[0].parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElements[0].getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol; +export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type?: TAVCol) => { + 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") { return; } diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index f62ddbe44..aa8387dc6 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -58,7 +58,7 @@ export const openMenuPanel = (options: {
`); avPanelElement = document.querySelector(".av__panel"); const menuElement = avPanelElement.lastElementChild as HTMLElement; - const tabRect = options.blockElement.querySelector(".layout-tab-bar").getBoundingClientRect(); + const tabRect = options.blockElement.querySelector(".layout-tab-bar")?.getBoundingClientRect(); if (["select", "date", "asset"].includes(options.type)) { const cellRect = options.cellElements[options.cellElements.length - 1].getBoundingClientRect(); if (options.type === "select") { @@ -94,7 +94,12 @@ export const openMenuPanel = (options: { window.siyuan.dragElement.style.opacity = ""; const sourceElement = window.siyuan.dragElement; window.siyuan.dragElement = undefined; - if (options.protyle.disabled) { + if (options.protyle && options.protyle.disabled) { + event.preventDefault(); + event.stopPropagation(); + return; + } + if (!options.protyle && window.siyuan.config.readonly) { event.preventDefault(); event.stopPropagation(); return; diff --git a/app/src/protyle/upload/index.ts b/app/src/protyle/upload/index.ts index 11188297f..896c0cd50 100644 --- a/app/src/protyle/upload/index.ts +++ b/app/src/protyle/upload/index.ts @@ -152,6 +152,31 @@ export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload: b }; export const uploadFiles = (protyle: IProtyle, files: FileList | DataTransferItemList | File[], element?: HTMLInputElement, successCB?: (res: string) => void) => { + // 文档书中点开属性->数据库后的变更操作 + if (!protyle) { + const formData = new FormData(); + for (let i = 0, iMax = files.length; i < iMax; i++) { + formData.append("file[]", files[i] as File); + } + const xhr = new XMLHttpRequest(); + xhr.open("POST", Constants.UPLOAD_ADDRESS); + xhr.onreadystatechange = () => { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 200) { + successCB(xhr.responseText); + } else if (xhr.status === 0) { + showMessage(window.siyuan.languages.fileTypeError); + } else { + showMessage(xhr.responseText); + } + if (element) { + element.value = ""; + } + } + }; + xhr.send(formData); + return; + } // FileList | DataTransferItemList | File[] => File[] let fileList = []; for (let i = 0; i < files.length; i++) { diff --git a/app/src/protyle/wysiwyg/commonClick.ts b/app/src/protyle/wysiwyg/commonClick.ts index a6851cfa0..25b3ed579 100644 --- a/app/src/protyle/wysiwyg/commonClick.ts +++ b/app/src/protyle/wysiwyg/commonClick.ts @@ -17,9 +17,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, "bookmark"); + openFileAttr(data, "bookmark", protyle); } else { - openAttr(attrBookmarkElement.parentElement.parentElement, "bookmark"); + openAttr(attrBookmarkElement.parentElement.parentElement, "bookmark", protyle); } } event.stopPropagation(); @@ -34,9 +34,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, "name"); + openFileAttr(data, "name", protyle); } else { - openAttr(attrNameElement.parentElement.parentElement, "name"); + openAttr(attrNameElement.parentElement.parentElement, "name", protyle); } } event.stopPropagation(); @@ -51,9 +51,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, "alias"); + openFileAttr(data, "alias", protyle); } else { - openAttr(attrAliasElement.parentElement.parentElement, "alias"); + openAttr(attrAliasElement.parentElement.parentElement, "alias", protyle); } } event.stopPropagation(); @@ -68,9 +68,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, "memo"); + openFileAttr(data, "memo", protyle); } else { - openAttr(attrMemoElement.parentElement.parentElement, "memo"); + openAttr(attrMemoElement.parentElement.parentElement, "memo", protyle); } } event.stopPropagation(); diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 474b9d8a6..ec9225bc3 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1978,7 +1978,7 @@ export class WYSIWYG { } hideElements(["gutter"], protyle); } else if (event.shiftKey && !protyle.disabled) { - openAttr(actionElement.parentElement); + openAttr(actionElement.parentElement, "bookmark", protyle); } else if (ctrlIsPressed) { zoomOut({protyle, id: actionId}); } else { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 2191f7236..faf41962e 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1056,7 +1056,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { } else { actionElement = topElement; } - openAttr(actionElement); + openAttr(actionElement, "bookmark", protyle); } else { const oldHTML = topElement.outerHTML; const name = Lute.EscapeHTMLStr(selectText); diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 3fd175c7b..fe8042fce 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -945,6 +945,18 @@ const updateRef = (protyle: IProtyle, id: string, index = 0) => { let transactionsTimeout: number; export const transaction = (protyle: IProtyle, doOperations: IOperation[], undoOperations?: IOperation[]) => { + if (!protyle) { + // 文档书中点开属性->数据库后的变更操作 + fetchPost("/api/transactions", { + session: Constants.SIYUAN_APPID, + app: Constants.SIYUAN_APPID, + transactions: [{ + doOperations + }] + }); + return; + } + const lastTransaction = window.siyuan.transactions[window.siyuan.transactions.length - 1]; let needDebounce = false; const time = new Date().getTime();