mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 09:30:48 +08:00
This commit is contained in:
parent
4793833f61
commit
89f4c33d88
@ -422,11 +422,17 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||||||
path: pathPosix().join(pathString, realFileName),
|
path: pathPosix().join(pathString, realFileName),
|
||||||
markdown: ""
|
markdown: ""
|
||||||
}, response => {
|
}, response => {
|
||||||
|
let tempElement = document.createElement("div");
|
||||||
let blockRefHTML = `<span data-type="block-ref" data-id="${response.data}" data-subtype="d">${escapeHtml(realFileName)}</span>`;
|
let blockRefHTML = `<span data-type="block-ref" data-id="${response.data}" data-subtype="d">${escapeHtml(realFileName)}</span>`;
|
||||||
if (fileNames.length === 2) {
|
if (fileNames.length === 2) {
|
||||||
blockRefHTML = `<span data-type="block-ref" data-id="${response.data}" data-subtype="s">${escapeHtml(fileNames[0])}</span>`;
|
blockRefHTML = `<span data-type="block-ref" data-id="${response.data}" data-subtype="s">${escapeHtml(fileNames[0])}</span>`;
|
||||||
}
|
}
|
||||||
insertHTML(genEmptyBlock(false, false, blockRefHTML), protyle);
|
tempElement.innerHTML = blockRefHTML;
|
||||||
|
tempElement = tempElement.firstElementChild as HTMLDivElement;
|
||||||
|
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
|
type: "id",
|
||||||
|
color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}`
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -440,17 +446,13 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
range.insertNode(document.createElement("wbr"));
|
|
||||||
html = nodeElement.outerHTML;
|
|
||||||
range.deleteContents();
|
|
||||||
let tempElement = document.createElement("div");
|
let tempElement = document.createElement("div");
|
||||||
tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, "");
|
tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, "");
|
||||||
tempElement = tempElement.firstChild as HTMLDivElement;
|
tempElement = tempElement.firstElementChild as HTMLDivElement;
|
||||||
range.insertNode(tempElement);
|
protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
|
||||||
range.setStartAfter(tempElement);
|
type: "id",
|
||||||
range.collapse(true);
|
color: `${tempElement.getAttribute("data-id")}${Constants.ZWSP}${tempElement.getAttribute("data-subtype")}${Constants.ZWSP}${tempElement.textContent}`
|
||||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
});
|
||||||
focusByWbr(nodeElement, range);
|
|
||||||
return;
|
return;
|
||||||
} else if (this.splitChar === ":") {
|
} else if (this.splitChar === ":") {
|
||||||
addEmoji(value);
|
addEmoji(value);
|
||||||
@ -533,7 +535,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||||||
focusByRange(range);
|
focusByRange(range);
|
||||||
protyle.toolbar.range = range;
|
protyle.toolbar.range = range;
|
||||||
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(value)) {
|
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(value)) {
|
||||||
protyle.toolbar.element.querySelector(`[data-type="${value}"]`).dispatchEvent(new CustomEvent("block-ref" === value? getEventName() : "click"));
|
protyle.toolbar.element.querySelector(`[data-type="${value}"]`).dispatchEvent(new CustomEvent("block-ref" === value ? getEventName() : "click"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
protyle.toolbar.setInlineMark(protyle, value, "range");
|
protyle.toolbar.setInlineMark(protyle, value, "range");
|
||||||
|
@ -151,6 +151,13 @@ export const fontEvent = (protyle: IProtyle, type?: string, color?: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption) => {
|
export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption) => {
|
||||||
|
const setBlockRef = (blockRefOption: string) => {
|
||||||
|
const blockRefData = blockRefOption.split(Constants.ZWSP);
|
||||||
|
textElement.setAttribute("data-id", blockRefData[0]);
|
||||||
|
textElement.setAttribute("data-subtype", blockRefData[1]);
|
||||||
|
textElement.innerText = blockRefData[2];
|
||||||
|
}
|
||||||
|
|
||||||
if (textOption) {
|
if (textOption) {
|
||||||
switch (textOption.type) {
|
switch (textOption.type) {
|
||||||
case "color":
|
case "color":
|
||||||
@ -169,6 +176,9 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
|
|||||||
case "style4":
|
case "style4":
|
||||||
textElement.style.textShadow = "1px 1px var(--b3-border-color), 2px 2px var(--b3-border-color), 3px 3px var(--b3-border-color), 4px 4px var(--b3-border-color)";
|
textElement.style.textShadow = "1px 1px var(--b3-border-color), 2px 2px var(--b3-border-color), 3px 3px var(--b3-border-color), 4px 4px var(--b3-border-color)";
|
||||||
break;
|
break;
|
||||||
|
case "id":
|
||||||
|
setBlockRef(textOption.color)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -177,6 +187,18 @@ export const hasSameTextStyle = (currentElement: HTMLElement, sideElement: HTMLE
|
|||||||
if (!textObj) {
|
if (!textObj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (textObj.type === "id") {
|
||||||
|
if (currentElement.nodeType !== 3) {
|
||||||
|
return currentElement.getAttribute("data-id") === sideElement.getAttribute("data-id") &&
|
||||||
|
currentElement.getAttribute("data-subtype") === sideElement.getAttribute("data-subtype") &&
|
||||||
|
currentElement.textContent === sideElement.textContent;
|
||||||
|
}
|
||||||
|
const blockRefData = textObj.color.split(Constants.ZWSP)
|
||||||
|
return blockRefData[0] === sideElement.getAttribute("data-id") &&
|
||||||
|
blockRefData[1] === sideElement.getAttribute("data-subtype") &&
|
||||||
|
blockRefData[2] === sideElement.textContent;
|
||||||
|
}
|
||||||
|
|
||||||
let color = "";
|
let color = "";
|
||||||
let webkitTextFillColor = "";
|
let webkitTextFillColor = "";
|
||||||
let webkitTextStroke = "";
|
let webkitTextStroke = "";
|
||||||
|
@ -409,7 +409,7 @@ export class Toolbar {
|
|||||||
if (item === "sup") {
|
if (item === "sup") {
|
||||||
types.splice(index, 1);
|
types.splice(index, 1);
|
||||||
if (!this.element.classList.contains("fn__none")) {
|
if (!this.element.classList.contains("fn__none")) {
|
||||||
this.element.querySelector("[data-type=\"sup\"]").classList.remove("protyle-toolbar__item--current");
|
this.element.querySelector('[data-type="sup"]').classList.remove("protyle-toolbar__item--current");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -419,11 +419,19 @@ export class Toolbar {
|
|||||||
if (item === "sub") {
|
if (item === "sub") {
|
||||||
types.splice(index, 1);
|
types.splice(index, 1);
|
||||||
if (!this.element.classList.contains("fn__none")) {
|
if (!this.element.classList.contains("fn__none")) {
|
||||||
this.element.querySelector("[data-type=\"sub\"]").classList.remove("protyle-toolbar__item--current");
|
this.element.querySelector('[data-type="sub"]').classList.remove("protyle-toolbar__item--current");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (type === "block-ref" && types.includes("virtual-block-ref")) {
|
||||||
|
// 虚拟引用和引用不能同时存在
|
||||||
|
types.find((item, index) => {
|
||||||
|
if (item === "virtual-block-ref") {
|
||||||
|
types.splice(index, 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
types = [...new Set(types)];
|
types = [...new Set(types)];
|
||||||
if (index === 0 && previousElement && previousElement.nodeType !== 3 &&
|
if (index === 0 && previousElement && previousElement.nodeType !== 3 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user