mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-02 10:50:15 +01:00
This commit is contained in:
parent
7ea6f08c21
commit
6e52e78ea4
5 changed files with 128 additions and 87 deletions
|
|
@ -754,87 +754,6 @@ export class Toolbar {
|
|||
}
|
||||
}
|
||||
|
||||
public showFileAnnotationRef(protyle: IProtyle, refElement: HTMLElement) {
|
||||
const nodeElement = hasClosestBlock(refElement);
|
||||
if (!nodeElement) {
|
||||
return;
|
||||
}
|
||||
hideElements(["hint"], protyle);
|
||||
window.siyuan.menus.menu.remove();
|
||||
const id = nodeElement.getAttribute("data-node-id");
|
||||
const html = nodeElement.outerHTML;
|
||||
this.subElement.style.padding = "";
|
||||
this.subElement.innerHTML = `<div class="b3-form__space--small">
|
||||
<label class="fn__flex">
|
||||
<span class="ft__on-surface fn__flex-center" style="width: 64px">ID</span>
|
||||
<div class="fn__space"></div>
|
||||
<input data-type="id" value="${refElement.getAttribute("data-id") || ""}" class="b3-text-field fn__block" readonly />
|
||||
</label>
|
||||
<div class="fn__hr"></div>
|
||||
<label class="fn__flex">
|
||||
<span class="ft__on-surface fn__flex-center" style="width: 64px">${window.siyuan.languages.anchor}</span>
|
||||
<div class="fn__space"></div>
|
||||
<input data-type="anchor" class="b3-text-field fn__block" placeholder="${window.siyuan.languages.anchor}" />
|
||||
</label>
|
||||
<div class="fn__hr"></div>
|
||||
<div class="fn__hr"></div>
|
||||
<div class="fn__flex"><span class="fn__flex-1"></span>
|
||||
<button class="b3-button b3-button--cancel">${window.siyuan.languages.remove}</button>
|
||||
</div></div>`;
|
||||
this.subElement.querySelector(".b3-button--cancel").addEventListener(getEventName(), () => {
|
||||
refElement.outerHTML = refElement.textContent + "<wbr>";
|
||||
hideElements(["util"], protyle);
|
||||
});
|
||||
const anchorElement = this.subElement.querySelector('[data-type="anchor"]') as HTMLInputElement;
|
||||
anchorElement.value = refElement.textContent;
|
||||
anchorElement.addEventListener("input", (event) => {
|
||||
if (anchorElement.value) {
|
||||
refElement.innerHTML = Lute.EscapeHTMLStr(anchorElement.value);
|
||||
} else {
|
||||
refElement.innerHTML = "*";
|
||||
}
|
||||
event.stopPropagation();
|
||||
});
|
||||
anchorElement.addEventListener("keydown", (event: KeyboardEvent) => {
|
||||
event.stopPropagation();
|
||||
if (event.isComposing) {
|
||||
return;
|
||||
}
|
||||
if (event.key === "Enter" || event.key === "Escape") {
|
||||
hideElements(["util"], protyle);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
});
|
||||
this.subElement.classList.remove("fn__none");
|
||||
this.subElementCloseCB = () => {
|
||||
if (refElement.parentElement) {
|
||||
if (anchorElement.value) {
|
||||
refElement.innerHTML = Lute.EscapeHTMLStr(anchorElement.value);
|
||||
} else {
|
||||
refElement.innerHTML = "*";
|
||||
}
|
||||
this.range.setStartAfter(refElement);
|
||||
if (getSelection().rangeCount === 0) {
|
||||
focusByRange(this.range);
|
||||
}
|
||||
} else {
|
||||
if (getSelection().rangeCount === 0) {
|
||||
focusByWbr(nodeElement, this.range);
|
||||
}
|
||||
}
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||
};
|
||||
/// #if !MOBILE
|
||||
this.subElement.style.width = Math.min(480, window.innerWidth) + "px";
|
||||
const nodeRect = refElement.getBoundingClientRect();
|
||||
setPosition(this.subElement, nodeRect.left, nodeRect.bottom, nodeRect.height + 4);
|
||||
/// #endif
|
||||
this.element.classList.add("fn__none");
|
||||
anchorElement.select();
|
||||
}
|
||||
|
||||
public showRender(protyle: IProtyle, renderElement: Element, updateElements?: Element[], oldHTML?: string) {
|
||||
const nodeElement = hasClosestBlock(renderElement);
|
||||
if (!nodeElement) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,16 @@ import {getSearch, isMobile} from "../../util/functions";
|
|||
import {isLocalPath, pathPosix} from "../../util/pathName";
|
||||
import {genEmptyElement} from "../../block/util";
|
||||
import {previewImage} from "../preview/image";
|
||||
import {contentMenu, imgMenu, linkMenu, refMenu, setFold, tagMenu, zoomOut} from "../../menus/protyle";
|
||||
import {
|
||||
contentMenu,
|
||||
fileAnnotationRefMenu,
|
||||
imgMenu,
|
||||
linkMenu,
|
||||
refMenu,
|
||||
setFold,
|
||||
tagMenu,
|
||||
zoomOut
|
||||
} from "../../menus/protyle";
|
||||
import * as dayjs from "dayjs";
|
||||
import {dropEvent} from "../util/editorCommonEvent";
|
||||
import {input} from "./input";
|
||||
|
|
@ -1218,7 +1227,7 @@ export class WYSIWYG {
|
|||
}, 620);
|
||||
return false;
|
||||
} else if (types.includes("file-annotation-ref") && !protyle.disabled) {
|
||||
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
||||
fileAnnotationRefMenu(protyle, target);
|
||||
return false;
|
||||
} else if (types.includes("tag") && !protyle.disabled) {
|
||||
tagMenu(protyle, target);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ import {
|
|||
goHome,
|
||||
upSelect
|
||||
} from "./commonHotkey";
|
||||
import {linkMenu, refMenu, setFold, tagMenu, zoomOut} from "../../menus/protyle";
|
||||
import {fileAnnotationRefMenu, linkMenu, refMenu, setFold, tagMenu, zoomOut} from "../../menus/protyle";
|
||||
import {removeEmbed} from "./removeEmbed";
|
||||
import {openAttr} from "../../menus/commonMenuItem";
|
||||
import {Constants} from "../../constants";
|
||||
|
|
@ -538,7 +538,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
protyle.toolbar.showRender(protyle, inlineElement);
|
||||
return;
|
||||
} else if (types.includes("file-annotation-ref")) {
|
||||
protyle.toolbar.showFileAnnotationRef(protyle, inlineElement);
|
||||
fileAnnotationRefMenu(protyle, inlineElement);
|
||||
return;
|
||||
} else if (types.includes("a")) {
|
||||
linkMenu(protyle, inlineElement);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue