mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
9950848a4e
commit
beb590259a
3 changed files with 14 additions and 10 deletions
|
|
@ -40,8 +40,8 @@ export const initRightMenu = () => {
|
||||||
<svg class="b3-menu__icon"><use xlink:href="#iconSparkles"></use></svg><span class="b3-menu__label">AI</span>
|
<svg class="b3-menu__icon"><use xlink:href="#iconSparkles"></use></svg><span class="b3-menu__label">AI</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
const isHuawei = () => {
|
const isHuawei = () => {
|
||||||
return 0 < window.siyuan.config.system.osPlatform.toLowerCase().indexOf("huawei")
|
return 0 < window.siyuan.config.system.osPlatform.toLowerCase().indexOf("huawei");
|
||||||
}
|
};
|
||||||
if (isHuawei()) {
|
if (isHuawei()) {
|
||||||
// Access to the OpenAI API is no longer supported on Huawei devices https://github.com/siyuan-note/siyuan/issues/8192
|
// Access to the OpenAI API is no longer supported on Huawei devices https://github.com/siyuan-note/siyuan/issues/8192
|
||||||
aiHTML = "";
|
aiHTML = "";
|
||||||
|
|
|
||||||
|
|
@ -4,23 +4,24 @@ import {showMessage} from "../dialog/message";
|
||||||
import {Dialog} from "../dialog";
|
import {Dialog} from "../dialog";
|
||||||
import {MenuItem} from "../menus/Menu";
|
import {MenuItem} from "../menus/Menu";
|
||||||
import {Menu as SiyuanMenu} from "../menus/Menu";
|
import {Menu as SiyuanMenu} from "../menus/Menu";
|
||||||
|
import {fetchGet, fetchPost, fetchSyncPost} from "../util/fetch";
|
||||||
|
|
||||||
export class Menu {
|
export class Menu {
|
||||||
private menu: SiyuanMenu;
|
private menu: SiyuanMenu;
|
||||||
private isOpen: boolean
|
private isOpen: boolean;
|
||||||
|
|
||||||
constructor(id?: string, closeCB?: () => void) {
|
constructor(id?: string, closeCB?: () => void) {
|
||||||
this.menu = window.siyuan.menus.menu;
|
this.menu = window.siyuan.menus.menu;
|
||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
if (id) {
|
if (id) {
|
||||||
const dataName = this.menu.element.getAttribute('data-name');
|
const dataName = this.menu.element.getAttribute("data-name");
|
||||||
if (dataName && dataName === id) {
|
if (dataName && dataName === id) {
|
||||||
this.isOpen = true
|
this.isOpen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.menu.remove();
|
this.menu.remove();
|
||||||
if (!this.isOpen) {
|
if (!this.isOpen) {
|
||||||
this.menu.element.setAttribute('data-name', id);
|
this.menu.element.setAttribute("data-name", id);
|
||||||
this.menu.removeCB = closeCB;
|
this.menu.removeCB = closeCB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +43,7 @@ export class Menu {
|
||||||
if (this.isOpen) {
|
if (this.isOpen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.addItem({type: 'separator'});
|
this.addItem({type: "separator"});
|
||||||
}
|
}
|
||||||
|
|
||||||
open(options: { x: number, y: number, h?: number, w?: number, isLeft: false }) {
|
open(options: { x: number, y: number, h?: number, w?: number, isLeft: false }) {
|
||||||
|
|
@ -65,9 +66,12 @@ export class Menu {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const API = {
|
export const API = {
|
||||||
Plugin: Plugin,
|
|
||||||
confirm: confirmDialog,
|
confirm: confirmDialog,
|
||||||
showMessage,
|
showMessage,
|
||||||
|
fetchPost,
|
||||||
|
fetchSyncPost,
|
||||||
|
fetchGet,
|
||||||
|
Plugin: Plugin,
|
||||||
Dialog,
|
Dialog,
|
||||||
Menu,
|
Menu,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -128,13 +128,13 @@ export const selectAll = (protyle: IProtyle, nodeElement: Element, range: Range)
|
||||||
// https://github.com/siyuan-note/siyuan/issues/8196
|
// https://github.com/siyuan-note/siyuan/issues/8196
|
||||||
export const getRangeByPoint = (x: number, y: number) => {
|
export const getRangeByPoint = (x: number, y: number) => {
|
||||||
const range = document.caretRangeFromPoint(x, y);
|
const range = document.caretRangeFromPoint(x, y);
|
||||||
const imgElement = hasClosestByAttribute(range.startContainer, "data-type", "img")
|
const imgElement = hasClosestByAttribute(range.startContainer, "data-type", "img");
|
||||||
if (imgElement) {
|
if (imgElement) {
|
||||||
range.setStart(imgElement.nextSibling, 0);
|
range.setStart(imgElement.nextSibling, 0);
|
||||||
range.collapse();
|
range.collapse();
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const getEditorRange = (element: Element) => {
|
export const getEditorRange = (element: Element) => {
|
||||||
let range: Range;
|
let range: Range;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue