${item.key.name}
-
${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();