mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
🚨
This commit is contained in:
parent
3452521ec5
commit
0878260361
12 changed files with 79 additions and 81 deletions
|
|
@ -24,7 +24,7 @@ const genCardCount = (unreviewedNewCardCount: number, unreviewedOldCardCount: nu
|
||||||
<span class="ariaLabel ft__primary" aria-label="${window.siyuan.languages.flashcardNewCard}">${unreviewedNewCardCount}</span>
|
<span class="ariaLabel ft__primary" aria-label="${window.siyuan.languages.flashcardNewCard}">${unreviewedNewCardCount}</span>
|
||||||
<span class="fn__space"></span>+<span class="fn__space"></span>
|
<span class="fn__space"></span>+<span class="fn__space"></span>
|
||||||
<span class="ariaLabel ft__success" aria-label="${window.siyuan.languages.flashcardReviewCard}">${unreviewedOldCardCount}</span>`;
|
<span class="ariaLabel ft__success" aria-label="${window.siyuan.languages.flashcardReviewCard}">${unreviewedOldCardCount}</span>`;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const genCardHTML = (options: {
|
export const genCardHTML = (options: {
|
||||||
id: string,
|
id: string,
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ export class Dialog {
|
||||||
window.siyuan.dialogs.push(this);
|
window.siyuan.dialogs.push(this);
|
||||||
this.destroyCallback = options.destroyCallback;
|
this.destroyCallback = options.destroyCallback;
|
||||||
this.element = document.createElement("div") as HTMLElement;
|
this.element = document.createElement("div") as HTMLElement;
|
||||||
let left
|
let left;
|
||||||
let top
|
let top;
|
||||||
if (!isMobile() && options.positionId) {
|
if (!isMobile() && options.positionId) {
|
||||||
const dialogPosition = window.siyuan.storage[Constants.LOCAL_DIALOGPOSITION][options.positionId];
|
const dialogPosition = window.siyuan.storage[Constants.LOCAL_DIALOGPOSITION][options.positionId];
|
||||||
if (dialogPosition) {
|
if (dialogPosition) {
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,8 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voi
|
||||||
documentSelf.ondragstart = null;
|
documentSelf.ondragstart = null;
|
||||||
documentSelf.onselectstart = null;
|
documentSelf.onselectstart = null;
|
||||||
documentSelf.onselect = null;
|
documentSelf.onselect = null;
|
||||||
hideAllElements(["gutter"])
|
hideAllElements(["gutter"]);
|
||||||
const dialogElement = hasClosestByClassName(element, "b3-dialog--open")
|
const dialogElement = hasClosestByClassName(element, "b3-dialog--open");
|
||||||
if (dialogElement) {
|
if (dialogElement) {
|
||||||
const dialogId = dialogElement.dataset.key;
|
const dialogId = dialogElement.dataset.key;
|
||||||
if (dialogId && element.offsetWidth) {
|
if (dialogId && element.offsetWidth) {
|
||||||
|
|
@ -143,7 +143,7 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voi
|
||||||
height: element.offsetHeight,
|
height: element.offsetHeight,
|
||||||
left: parseInt(element.style.left),
|
left: parseInt(element.style.left),
|
||||||
top: parseInt(element.style.top),
|
top: parseInt(element.style.top),
|
||||||
}
|
};
|
||||||
setStorageVal(Constants.LOCAL_DIALOGPOSITION, window.siyuan.storage[Constants.LOCAL_DIALOGPOSITION]);
|
setStorageVal(Constants.LOCAL_DIALOGPOSITION, window.siyuan.storage[Constants.LOCAL_DIALOGPOSITION]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,10 @@ import {getSearch} from "../util/functions";
|
||||||
import {initRightMenu} from "./menu";
|
import {initRightMenu} from "./menu";
|
||||||
import {openChangelog} from "../boot/openChangelog";
|
import {openChangelog} from "../boot/openChangelog";
|
||||||
import {registerServiceWorker} from "../util/serviceWorker";
|
import {registerServiceWorker} from "../util/serviceWorker";
|
||||||
import {afterLoadPlugin, loadPlugins} from "../plugin/loader";
|
import {loadPlugins} from "../plugin/loader";
|
||||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
import {removeBlock} from "../protyle/wysiwyg/remove";
|
import {removeBlock} from "../protyle/wysiwyg/remove";
|
||||||
import {isNotEditBlock} from "../protyle/wysiwyg/getBlock";
|
import {isNotEditBlock} from "../protyle/wysiwyg/getBlock";
|
||||||
import {Menu} from "../plugin/Menu";
|
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
public plugins: import("../plugin").Plugin[] = [];
|
public plugins: import("../plugin").Plugin[] = [];
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,14 @@ const openDockMenu = (app: App) => {
|
||||||
custom = plugin.docks[dockId].mobileModel(document.querySelector('#sidebar [data-type="sidebar-plugin"]'));
|
custom = plugin.docks[dockId].mobileModel(document.querySelector('#sidebar [data-type="sidebar-plugin"]'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
menu.fullscreen("bottom");
|
menu.fullscreen("bottom");
|
||||||
if (menu.element.lastElementChild.innerHTML === "") {
|
if (menu.element.lastElementChild.innerHTML === "") {
|
||||||
showMessage(window.siyuan.languages._kernel[122]);
|
showMessage(window.siyuan.languages._kernel[122]);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const initFramework = (app: App, isStart: boolean) => {
|
export const initFramework = (app: App, isStart: boolean) => {
|
||||||
setInlineStyle();
|
setInlineStyle();
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ id="preview"></div>
|
||||||
if (item.src.endsWith(".svg")) {
|
if (item.src.endsWith(".svg")) {
|
||||||
fetchGet(item.src, (response: string) => {
|
fetchGet(item.src, (response: string) => {
|
||||||
item.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(response)))}`;
|
item.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(response)))}`;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
btnsElement[0].removeAttribute("disabled");
|
btnsElement[0].removeAttribute("disabled");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import {fetchPost} from "../../../util/fetch";
|
import {fetchPost} from "../../../util/fetch";
|
||||||
import {getColIconByType} from "./col";
|
import {getColIconByType} from "./col";
|
||||||
import {escapeAttr} from "../../../util/escape";
|
import {escapeAttr} from "../../../util/escape";
|
||||||
import {hasClosestByAttribute} from "../../util/hasClosest";
|
|
||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
import {popTextCell} from "./cell";
|
import {popTextCell} from "./cell";
|
||||||
|
|
||||||
|
|
@ -129,27 +128,27 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone"].includes
|
||||||
popTextCell(protyle, [target], "date");
|
popTextCell(protyle, [target], "date");
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break
|
break;
|
||||||
} else if (type === "select" || type === "mSelect") {
|
} else if (type === "select" || type === "mSelect") {
|
||||||
popTextCell(protyle, [target], target.getAttribute("data-type") as TAVCol);
|
popTextCell(protyle, [target], target.getAttribute("data-type") as TAVCol);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break
|
break;
|
||||||
} else if (type === "mAsset") {
|
} else if (type === "mAsset") {
|
||||||
popTextCell(protyle, [target], "mAsset");
|
popTextCell(protyle, [target], "mAsset");
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break
|
break;
|
||||||
} else if (type === "checkbox") {
|
} else if (type === "checkbox") {
|
||||||
popTextCell(protyle, [target], "checkbox");
|
popTextCell(protyle, [target], "checkbox");
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break
|
break;
|
||||||
} else if (type === "relation") {
|
} else if (type === "relation") {
|
||||||
popTextCell(protyle, [target], "relation");
|
popTextCell(protyle, [target], "relation");
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
target = target.parentElement;
|
target = target.parentElement;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
|
||||||
if (!hasClosestByClassName(cellElements[0], "custom-attr")) {
|
if (!hasClosestByClassName(cellElements[0], "custom-attr")) {
|
||||||
updateAttrViewCellAnimation(item, cellValue);
|
updateAttrViewCellAnimation(item, cellValue);
|
||||||
} else {
|
} else {
|
||||||
item.innerHTML = genAVValueHTML(cellValue)
|
item.innerHTML = genAVValueHTML(cellValue);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (doOperations.length > 0) {
|
if (doOperations.length > 0) {
|
||||||
|
|
@ -615,7 +615,7 @@ export const renderCell = (cellValue: IAVCellValue, wrap: boolean) => {
|
||||||
} else if (cellValue.type === "relation") {
|
} else if (cellValue.type === "relation") {
|
||||||
cellValue?.relation?.contents?.forEach((item, index) => {
|
cellValue?.relation?.contents?.forEach((item, index) => {
|
||||||
text += `<span class="av__celltext--ref" style="margin-right: 8px" data-id="${cellValue?.relation?.blockIDs[index]}">${item}</span>`;
|
text += `<span class="av__celltext--ref" style="margin-right: 8px" data-id="${cellValue?.relation?.blockIDs[index]}">${item}</span>`;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (["text", "template", "url", "email", "phone", "number", "date", "created", "updated"].includes(cellValue.type) &&
|
if (["text", "template", "url", "email", "phone", "number", "date", "created", "updated"].includes(cellValue.type) &&
|
||||||
cellValue && cellValue[cellValue.type as "url"].content) {
|
cellValue && cellValue[cellValue.type as "url"].content) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {getLabelByNumberFormat} from "./number";
|
||||||
import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action";
|
import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action";
|
||||||
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
||||||
import {focusBlock} from "../../util/selection";
|
import {focusBlock} from "../../util/selection";
|
||||||
import {openSearchAV, toggleUpdateRelationBtn} from "./relation";
|
import {toggleUpdateRelationBtn} from "./relation";
|
||||||
|
|
||||||
export const duplicateCol = (options: {
|
export const duplicateCol = (options: {
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
|
|
@ -334,21 +334,21 @@ export const bindEditEvent = (options: {
|
||||||
toggleUpdateRelationBtn(options.menuElement, avID);
|
toggleUpdateRelationBtn(options.menuElement, avID);
|
||||||
});
|
});
|
||||||
const goSearchElement = options.menuElement.querySelector('[data-type="goSearchAV"]') as HTMLElement;
|
const goSearchElement = options.menuElement.querySelector('[data-type="goSearchAV"]') as HTMLElement;
|
||||||
const oldValue = JSON.parse(goSearchElement.getAttribute("data-old-value"))
|
const oldValue = JSON.parse(goSearchElement.getAttribute("data-old-value"));
|
||||||
const inputElement = options.menuElement.querySelector('[data-type="colName"]') as HTMLInputElement
|
const inputElement = options.menuElement.querySelector('[data-type="colName"]') as HTMLInputElement;
|
||||||
inputElement.addEventListener("input", () => {
|
inputElement.addEventListener("input", () => {
|
||||||
toggleUpdateRelationBtn(options.menuElement, avID);
|
toggleUpdateRelationBtn(options.menuElement, avID);
|
||||||
})
|
});
|
||||||
if (oldValue.avID) {
|
if (oldValue.avID) {
|
||||||
fetchPost("/api/av/getAttributeView", {id: oldValue.avID}, (response) => {
|
fetchPost("/api/av/getAttributeView", {id: oldValue.avID}, (response) => {
|
||||||
goSearchElement.querySelector(".b3-menu__accelerator").textContent = oldValue.avID === avID ? window.siyuan.languages.thisDatabase : (response.data.av.name || window.siyuan.languages.title)
|
goSearchElement.querySelector(".b3-menu__accelerator").textContent = oldValue.avID === avID ? window.siyuan.languages.thisDatabase : (response.data.av.name || window.siyuan.languages.title);
|
||||||
response.data.av.keyValues.find((item: { key: { id: string, name: string } }) => {
|
response.data.av.keyValues.find((item: { key: { id: string, name: string } }) => {
|
||||||
if (item.key.id === oldValue.backKeyID) {
|
if (item.key.id === oldValue.backKeyID) {
|
||||||
inputElement.setAttribute("data-old-value", item.key.name || window.siyuan.languages.title);
|
inputElement.setAttribute("data-old-value", item.key.name || window.siyuan.languages.title);
|
||||||
inputElement.value = item.key.name || window.siyuan.languages.title;
|
inputElement.value = item.key.name || window.siyuan.languages.title;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
toggleUpdateRelationBtn(options.menuElement, avID);
|
toggleUpdateRelationBtn(options.menuElement, avID);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -241,12 +241,12 @@ export const setFilter = (options: {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (["text", "url", "block", "email", "phone", "template", "relation"].includes(colData.type)) {
|
} else if (["text", "url", "block", "email", "phone", "template", "relation"].includes(colData.type)) {
|
||||||
let value = ""
|
let value = "";
|
||||||
if (options.filter.value) {
|
if (options.filter.value) {
|
||||||
if (colData.type === "relation") {
|
if (colData.type === "relation") {
|
||||||
value = options.filter.value.relation.contents[0] || ""
|
value = options.filter.value.relation.contents[0] || "";
|
||||||
} else {
|
} else {
|
||||||
value = options.filter.value[colData.type as "text"].content || ""
|
value = options.filter.value[colData.type as "text"].content || "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
|
|
|
||||||
|
|
@ -25,24 +25,24 @@ const genSearchList = (element: Element, keyword: string, avId: string, cb?: ()
|
||||||
<div class="b3-list-item__meta b3-list-item__showall">${escapeHtml(item.hPath)}</div>
|
<div class="b3-list-item__meta b3-list-item__showall">${escapeHtml(item.hPath)}</div>
|
||||||
</div>
|
</div>
|
||||||
<svg aria-label="${window.siyuan.languages.thisDatabase}" style="margin: 0 0 0 4px" class="b3-list-item__hinticon ariaLabel${item.avID === avId ? "" : " fn__none"}"><use xlink:href="#iconInfo"></use></svg>
|
<svg aria-label="${window.siyuan.languages.thisDatabase}" style="margin: 0 0 0 4px" class="b3-list-item__hinticon ariaLabel${item.avID === avId ? "" : " fn__none"}"><use xlink:href="#iconInfo"></use></svg>
|
||||||
</div>`
|
</div>`;
|
||||||
});
|
});
|
||||||
element.innerHTML = html;
|
element.innerHTML = html;
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb()
|
cb();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const setDatabase = (avId: string, element: HTMLElement, item: HTMLElement) => {
|
const setDatabase = (avId: string, element: HTMLElement, item: HTMLElement) => {
|
||||||
element.dataset.avId = item.dataset.avId;
|
element.dataset.avId = item.dataset.avId;
|
||||||
element.dataset.blockId = item.dataset.blockId;
|
element.dataset.blockId = item.dataset.blockId;
|
||||||
element.querySelector(".b3-menu__accelerator").textContent = item.querySelector(".b3-list-item__hinticon").classList.contains("fn__none") ? item.querySelector(".b3-list-item__text").textContent : window.siyuan.languages.thisDatabase
|
element.querySelector(".b3-menu__accelerator").textContent = item.querySelector(".b3-list-item__hinticon").classList.contains("fn__none") ? item.querySelector(".b3-list-item__text").textContent : window.siyuan.languages.thisDatabase;
|
||||||
const menuElement = hasClosestByClassName(element, "b3-menu__items")
|
const menuElement = hasClosestByClassName(element, "b3-menu__items");
|
||||||
if (menuElement) {
|
if (menuElement) {
|
||||||
toggleUpdateRelationBtn(menuElement, avId, true);
|
toggleUpdateRelationBtn(menuElement, avId, true);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const openSearchAV = (avId: string, target: HTMLElement) => {
|
export const openSearchAV = (avId: string, target: HTMLElement) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
|
|
@ -83,7 +83,7 @@ export const openSearchAV = (avId: string, target: HTMLElement) => {
|
||||||
const listItemElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
|
const listItemElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item");
|
||||||
if (listItemElement) {
|
if (listItemElement) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
setDatabase(avId, target, listItemElement)
|
setDatabase(avId, target, listItemElement);
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -93,13 +93,13 @@ export const openSearchAV = (avId: string, target: HTMLElement) => {
|
||||||
x: rect.left,
|
x: rect.left,
|
||||||
y: rect.bottom,
|
y: rect.bottom,
|
||||||
h: rect.height,
|
h: rect.height,
|
||||||
})
|
});
|
||||||
element.querySelector("input").focus();
|
element.querySelector("input").focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.element.querySelector(".b3-menu__items").setAttribute("style", "overflow: initial");
|
menu.element.querySelector(".b3-menu__items").setAttribute("style", "overflow: initial");
|
||||||
}
|
};
|
||||||
|
|
||||||
export const updateRelation = (options: {
|
export const updateRelation = (options: {
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
|
|
@ -110,18 +110,18 @@ export const updateRelation = (options: {
|
||||||
}) => {
|
}) => {
|
||||||
const inputElement = options.avElement.querySelector('input[data-type="colName"]') as HTMLInputElement;
|
const inputElement = options.avElement.querySelector('input[data-type="colName"]') as HTMLInputElement;
|
||||||
const goSearchAVElement = options.avElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement;
|
const goSearchAVElement = options.avElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement;
|
||||||
const newAVId = goSearchAVElement.getAttribute("data-av-id")
|
const newAVId = goSearchAVElement.getAttribute("data-av-id");
|
||||||
const colId = options.avElement.querySelector(".b3-menu__item").getAttribute("data-col-id")
|
const colId = options.avElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
||||||
let colData: IAVColumn;
|
let colData: IAVColumn;
|
||||||
options.colsData.find(item => {
|
options.colsData.find(item => {
|
||||||
if (item.id === colId) {
|
if (item.id === colId) {
|
||||||
if (!item.relation) {
|
if (!item.relation) {
|
||||||
item.relation = {}
|
item.relation = {};
|
||||||
}
|
}
|
||||||
colData = item;
|
colData = item;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
const colNewName = (options.avElement.querySelector('[data-type="name"]') as HTMLInputElement).value;
|
const colNewName = (options.avElement.querySelector('[data-type="name"]') as HTMLInputElement).value;
|
||||||
transaction(options.protyle, [{
|
transaction(options.protyle, [{
|
||||||
action: "updateAttrViewColRelation",
|
action: "updateAttrViewColRelation",
|
||||||
|
|
@ -145,10 +145,10 @@ export const updateRelation = (options: {
|
||||||
options.avElement.remove();
|
options.avElement.remove();
|
||||||
updateAttrViewCellAnimation(options.blockElement.querySelector(`.av__row--header .av__cell[data-col-id="${colId}"]`), undefined, {name: colNewName});
|
updateAttrViewCellAnimation(options.blockElement.querySelector(`.av__row--header .av__cell[data-col-id="${colId}"]`), undefined, {name: colNewName});
|
||||||
focusBlock(options.blockElement);
|
focusBlock(options.blockElement);
|
||||||
}
|
};
|
||||||
|
|
||||||
export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: string, resetData = false) => {
|
export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: string, resetData = false) => {
|
||||||
const searchElement = menuItemsElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement
|
const searchElement = menuItemsElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement;
|
||||||
const switchItemElement = searchElement.nextElementSibling;
|
const switchItemElement = searchElement.nextElementSibling;
|
||||||
const switchElement = switchItemElement.querySelector(".b3-switch") as HTMLInputElement;
|
const switchElement = switchItemElement.querySelector(".b3-switch") as HTMLInputElement;
|
||||||
const inputItemElement = switchItemElement.nextElementSibling;
|
const inputItemElement = switchItemElement.nextElementSibling;
|
||||||
|
|
@ -161,7 +161,7 @@ export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: str
|
||||||
inputElement.value = "";
|
inputElement.value = "";
|
||||||
switchElement.checked = false;
|
switchElement.checked = false;
|
||||||
} else {
|
} else {
|
||||||
inputElement.value = inputElement.dataset.oldValue
|
inputElement.value = inputElement.dataset.oldValue;
|
||||||
switchElement.checked = oldValue.isTwoWay;
|
switchElement.checked = oldValue.isTwoWay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +190,7 @@ export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: str
|
||||||
}
|
}
|
||||||
btnElement.classList.remove("fn__none");
|
btnElement.classList.remove("fn__none");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const genSelectItemHTML = (type: "selected" | "empty" | "unselect", id?: string, text?: string) => {
|
const genSelectItemHTML = (type: "selected" | "empty" | "unselect", id?: string, text?: string) => {
|
||||||
if (type === "selected") {
|
if (type === "selected") {
|
||||||
|
|
@ -198,20 +198,20 @@ const genSelectItemHTML = (type: "selected" | "empty" | "unselect", id?: string,
|
||||||
<svg class="b3-menu__icon"><use xlink:href="#iconDrag"></use></svg>
|
<svg class="b3-menu__icon"><use xlink:href="#iconDrag"></use></svg>
|
||||||
<span class="b3-menu__label">${text}</span>
|
<span class="b3-menu__label">${text}</span>
|
||||||
<svg class="b3-menu__action"><use xlink:href="#iconMin"></use></svg>
|
<svg class="b3-menu__action"><use xlink:href="#iconMin"></use></svg>
|
||||||
</button>`
|
</button>`;
|
||||||
}
|
}
|
||||||
if (type === "empty") {
|
if (type === "empty") {
|
||||||
return `<button class="b3-menu__item">
|
return `<button class="b3-menu__item">
|
||||||
<span class="b3-menu__label">${window.siyuan.languages.emptyContent}</span>
|
<span class="b3-menu__label">${window.siyuan.languages.emptyContent}</span>
|
||||||
</button>`
|
</button>`;
|
||||||
}
|
}
|
||||||
if (type == "unselect") {
|
if (type == "unselect") {
|
||||||
return `<button data-id="${id}" class="b3-menu__item" data-type="setRelationCell">
|
return `<button data-id="${id}" class="b3-menu__item" data-type="setRelationCell">
|
||||||
<span class="b3-menu__label">${text}</span>
|
<span class="b3-menu__label">${text}</span>
|
||||||
<svg class="b3-menu__action"><use xlink:href="#iconAdd"></use></svg>
|
<svg class="b3-menu__action"><use xlink:href="#iconAdd"></use></svg>
|
||||||
</button>`
|
</button>`;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const bindRelationEvent = (options: {
|
export const bindRelationEvent = (options: {
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
|
|
@ -224,59 +224,59 @@ export const bindRelationEvent = (options: {
|
||||||
id: options.menuElement.firstElementChild.getAttribute("data-av-id"),
|
id: options.menuElement.firstElementChild.getAttribute("data-av-id"),
|
||||||
}, response => {
|
}, response => {
|
||||||
const avData = response.data as IAV;
|
const avData = response.data as IAV;
|
||||||
let cellIndex = 0
|
let cellIndex = 0;
|
||||||
avData.view.columns.find((item, index) => {
|
avData.view.columns.find((item, index) => {
|
||||||
if (item.type === "block") {
|
if (item.type === "block") {
|
||||||
cellIndex = index
|
cellIndex = index;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
let html = ""
|
let html = "";
|
||||||
let selectHTML = ""
|
let selectHTML = "";
|
||||||
hasIds.forEach(hasId => {
|
hasIds.forEach(hasId => {
|
||||||
if (hasId) {
|
if (hasId) {
|
||||||
avData.view.rows.find((item) => {
|
avData.view.rows.find((item) => {
|
||||||
if (item.id === hasId) {
|
if (item.id === hasId) {
|
||||||
selectHTML += genSelectItemHTML("selected", item.id, item.cells[cellIndex].value.block.content || item.cells[cellIndex].value.block.id)
|
selectHTML += genSelectItemHTML("selected", item.id, item.cells[cellIndex].value.block.content || item.cells[cellIndex].value.block.id);
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
avData.view.rows.forEach((item) => {
|
|
||||||
if (!hasIds.includes(item.id)) {
|
|
||||||
html += genSelectItemHTML("unselect", item.id, item.cells[cellIndex].value.block.content || item.cells[cellIndex].value.block.id)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
options.menuElement.innerHTML = `<div class="b3-menu__items">${selectHTML || genSelectItemHTML("empty")}
|
|
||||||
<button class="b3-menu__separator"></button>
|
|
||||||
${html || genSelectItemHTML("empty")}</div>`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getRelationHTML = (data: IAV, cellElements?: HTMLElement[]) => {
|
|
||||||
let colRelationData: IAVCellRelationValue
|
|
||||||
data.view.columns.find(item => {
|
|
||||||
if (item.id === cellElements[0].dataset.colId) {
|
|
||||||
colRelationData = item.relation
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
avData.view.rows.forEach((item) => {
|
||||||
|
if (!hasIds.includes(item.id)) {
|
||||||
|
html += genSelectItemHTML("unselect", item.id, item.cells[cellIndex].value.block.content || item.cells[cellIndex].value.block.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
options.menuElement.innerHTML = `<div class="b3-menu__items">${selectHTML || genSelectItemHTML("empty")}
|
||||||
|
<button class="b3-menu__separator"></button>
|
||||||
|
${html || genSelectItemHTML("empty")}</div>`;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getRelationHTML = (data: IAV, cellElements?: HTMLElement[]) => {
|
||||||
|
let colRelationData: IAVCellRelationValue;
|
||||||
|
data.view.columns.find(item => {
|
||||||
|
if (item.id === cellElements[0].dataset.colId) {
|
||||||
|
colRelationData = item.relation;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
if (colRelationData && colRelationData.avID) {
|
if (colRelationData && colRelationData.avID) {
|
||||||
let ids = ""
|
let ids = "";
|
||||||
cellElements[0].querySelectorAll("span").forEach((item) => {
|
cellElements[0].querySelectorAll("span").forEach((item) => {
|
||||||
ids += `${item.getAttribute("data-id")},`;
|
ids += `${item.getAttribute("data-id")},`;
|
||||||
});
|
});
|
||||||
return `<span data-av-id="${colRelationData.avID}">${ids}</span>`
|
return `<span data-av-id="${colRelationData.avID}">${ids}</span>`;
|
||||||
} else {
|
} else {
|
||||||
return ""
|
return "";
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const setRelationCell = (protyle: IProtyle, nodeElement: HTMLElement, target: HTMLElement, cellElements: HTMLElement[]) => {
|
export const setRelationCell = (protyle: IProtyle, nodeElement: HTMLElement, target: HTMLElement, cellElements: HTMLElement[]) => {
|
||||||
const menuElement = hasClosestByClassName(target, "b3-menu__items");
|
const menuElement = hasClosestByClassName(target, "b3-menu__items");
|
||||||
if (!menuElement) {
|
if (!menuElement) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
const newValue: {
|
const newValue: {
|
||||||
blockIDs: string[]
|
blockIDs: string[]
|
||||||
|
|
@ -284,16 +284,16 @@ export const setRelationCell = (protyle: IProtyle, nodeElement: HTMLElement, tar
|
||||||
} = {
|
} = {
|
||||||
blockIDs: [],
|
blockIDs: [],
|
||||||
contents: []
|
contents: []
|
||||||
}
|
};
|
||||||
Array.from(menuElement.children).forEach((item) => {
|
Array.from(menuElement.children).forEach((item) => {
|
||||||
const id = item.getAttribute("data-id")
|
const id = item.getAttribute("data-id");
|
||||||
if (item.getAttribute("draggable") && id) {
|
if (item.getAttribute("draggable") && id) {
|
||||||
newValue.blockIDs.push(id);
|
newValue.blockIDs.push(id);
|
||||||
newValue.contents.push(item.textContent.trim());
|
newValue.contents.push(item.textContent.trim());
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
if (target.classList.contains("b3-menu__item")) {
|
if (target.classList.contains("b3-menu__item")) {
|
||||||
const targetId = target.getAttribute("data-id")
|
const targetId = target.getAttribute("data-id");
|
||||||
const separatorElement = menuElement.querySelector(".b3-menu__separator");
|
const separatorElement = menuElement.querySelector(".b3-menu__separator");
|
||||||
if (target.getAttribute("draggable")) {
|
if (target.getAttribute("draggable")) {
|
||||||
if (!separatorElement.nextElementSibling.getAttribute("data-id")) {
|
if (!separatorElement.nextElementSibling.getAttribute("data-id")) {
|
||||||
|
|
|
||||||
|
|
@ -392,12 +392,12 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
|
||||||
action: "update",
|
action: "update",
|
||||||
data: blockElement.outerHTML,
|
data: blockElement.outerHTML,
|
||||||
id,
|
id,
|
||||||
})
|
});
|
||||||
undoOperation.push({
|
undoOperation.push({
|
||||||
action: "update",
|
action: "update",
|
||||||
data: html,
|
data: html,
|
||||||
id,
|
id,
|
||||||
})
|
});
|
||||||
mathRender(editableElement);
|
mathRender(editableElement);
|
||||||
} else {
|
} else {
|
||||||
doOperation.push({
|
doOperation.push({
|
||||||
|
|
@ -405,15 +405,15 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
|
||||||
data: item.outerHTML,
|
data: item.outerHTML,
|
||||||
id: item.dataset.nodeId,
|
id: item.dataset.nodeId,
|
||||||
nextID: id,
|
nextID: id,
|
||||||
})
|
});
|
||||||
blockElement.insertAdjacentElement("beforebegin", item);
|
blockElement.insertAdjacentElement("beforebegin", item);
|
||||||
undoOperation.push({
|
undoOperation.push({
|
||||||
action: "delete",
|
action: "delete",
|
||||||
id: item.dataset.nodeId,
|
id: item.dataset.nodeId,
|
||||||
})
|
});
|
||||||
mathRender(item);
|
mathRender(item);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
let previousElement = blockElement;
|
let previousElement = blockElement;
|
||||||
Array.from(newElement.children).forEach((item: HTMLElement) => {
|
Array.from(newElement.children).forEach((item: HTMLElement) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue