mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
7c653d3689
commit
a18e3a585c
9 changed files with 44 additions and 46 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import {BlockPanel} from "./Panel";
|
import {BlockPanel} from "./Panel";
|
||||||
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||||
import {fetchSyncPost} from "../util/fetch";
|
import {fetchSyncPost} from "../util/fetch";
|
||||||
import {getIdFromSiyuanUrl} from "../util/functions";
|
|
||||||
import {hideTooltip, showTooltip} from "../dialog/tooltip";
|
import {hideTooltip, showTooltip} from "../dialog/tooltip";
|
||||||
|
import {getIdFromSYProtocol} from "../util/pathName";
|
||||||
|
|
||||||
let popoverTargetElement: HTMLElement;
|
let popoverTargetElement: HTMLElement;
|
||||||
export const initBlockPopover = () => {
|
export const initBlockPopover = () => {
|
||||||
|
|
@ -200,7 +200,7 @@ export const showPopover = async () => {
|
||||||
}
|
}
|
||||||
} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
|
} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
|
||||||
// 以思源协议开头的链接
|
// 以思源协议开头的链接
|
||||||
ids = [getIdFromSiyuanUrl(popoverTargetElement.getAttribute("data-href"))];
|
ids = [getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))];
|
||||||
} else {
|
} else {
|
||||||
// pdf
|
// pdf
|
||||||
let targetId;
|
let targetId;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import {renderSnippet} from "../config/util/snippets";
|
||||||
import {openFileById} from "../editor/util";
|
import {openFileById} from "../editor/util";
|
||||||
import {focusByRange} from "../protyle/util/selection";
|
import {focusByRange} from "../protyle/util/selection";
|
||||||
import {exitSiYuan} from "../dialog/processSystem";
|
import {exitSiYuan} from "../dialog/processSystem";
|
||||||
import {getSearch, isWindow, isSiyuanUrl, getIdFromSiyuanUrl} from "../util/functions";
|
import {getSearch, isWindow} from "../util/functions";
|
||||||
import {initStatus} from "../layout/status";
|
import {initStatus} from "../layout/status";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
import {replaceLocalPath} from "../editor/rename";
|
import {replaceLocalPath} from "../editor/rename";
|
||||||
|
|
@ -25,6 +25,7 @@ import {setTabPosition} from "../window/setHeader";
|
||||||
import {initBar} from "../layout/topBar";
|
import {initBar} from "../layout/topBar";
|
||||||
import {setProxy} from "../config/util/setProxy";
|
import {setProxy} from "../config/util/setProxy";
|
||||||
import {openChangelog} from "./openChangelog";
|
import {openChangelog} from "./openChangelog";
|
||||||
|
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
||||||
|
|
||||||
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
|
const matchKeymap = (keymap: Record<string, IKeymapItem>, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => {
|
||||||
if (key1 === "general") {
|
if (key1 === "general") {
|
||||||
|
|
@ -212,10 +213,10 @@ export const initWindow = () => {
|
||||||
});
|
});
|
||||||
if (!isWindow()) {
|
if (!isWindow()) {
|
||||||
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
|
ipcRenderer.on(Constants.SIYUAN_OPENURL, (event, url) => {
|
||||||
if (!isSiyuanUrl(url)) {
|
if (!isSYProtocol(url)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const id = getIdFromSiyuanUrl(url);
|
const id = getIdFromSYProtocol(url);
|
||||||
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
||||||
if (existResponse.data) {
|
if (existResponse.data) {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,12 @@ import {getCurrentWindow} from "@electron/remote";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {hideMessage, showMessage} from "./message";
|
import {hideMessage, showMessage} from "./message";
|
||||||
import {Dialog} from "./index";
|
import {Dialog} from "./index";
|
||||||
import {isMobile, redirectToCheckAuth} from "../util/functions";
|
import {isMobile} from "../util/functions";
|
||||||
import {confirmDialog} from "./confirmDialog";
|
import {confirmDialog} from "./confirmDialog";
|
||||||
import {escapeHtml} from "../util/escape";
|
import {escapeHtml} from "../util/escape";
|
||||||
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
||||||
import {needSubscribe} from "../util/needSubscribe";
|
import {needSubscribe} from "../util/needSubscribe";
|
||||||
|
import { redirectToCheckAuth } from "../util/pathName";
|
||||||
|
|
||||||
export const lockScreen = () => {
|
export const lockScreen = () => {
|
||||||
if (window.siyuan.config.readonly) {
|
if (window.siyuan.config.readonly) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {account} from "./config/account";
|
||||||
import {addScript, addScriptSync} from "./protyle/util/addScript";
|
import {addScript, addScriptSync} from "./protyle/util/addScript";
|
||||||
import {genUUID} from "./util/genID";
|
import {genUUID} from "./util/genID";
|
||||||
import {fetchGet, fetchPost} from "./util/fetch";
|
import {fetchGet, fetchPost} from "./util/fetch";
|
||||||
import {addBaseURL, setNoteBook} from "./util/pathName";
|
import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "./util/pathName";
|
||||||
import {registerServiceWorker} from "./util/serviceWorker";
|
import {registerServiceWorker} from "./util/serviceWorker";
|
||||||
import {openFileById} from "./editor/util";
|
import {openFileById} from "./editor/util";
|
||||||
import {
|
import {
|
||||||
|
|
@ -27,12 +27,13 @@ import {resizeDrag} from "./layout/util";
|
||||||
import {getAllTabs} from "./layout/getAll";
|
import {getAllTabs} from "./layout/getAll";
|
||||||
import {getLocalStorage} from "./protyle/util/compatibility";
|
import {getLocalStorage} from "./protyle/util/compatibility";
|
||||||
import {updateEditModeElement} from "./layout/topBar";
|
import {updateEditModeElement} from "./layout/topBar";
|
||||||
import {getIdFromSiyuanUrl, getSearch, isSiyuanUrl} from "./util/functions";
|
import {getSearch} from "./util/functions";
|
||||||
import {hideAllElements} from "./protyle/ui/hideElements";
|
import {hideAllElements} from "./protyle/ui/hideElements";
|
||||||
import {initPluginSystem} from 'siyuan-petal';
|
import {initPluginSystem} from 'siyuan-petal';
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// TODO
|
||||||
/// #if BROWSER
|
/// #if BROWSER
|
||||||
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -183,9 +184,9 @@ class App {
|
||||||
|
|
||||||
new App();
|
new App();
|
||||||
window.openFileByURL = (openURL) => {
|
window.openFileByURL = (openURL) => {
|
||||||
if (openURL && isSiyuanUrl(openURL)) {
|
if (openURL && isSYProtocol(openURL)) {
|
||||||
openFileById({
|
openFileById({
|
||||||
id: getIdFromSiyuanUrl(openURL),
|
id: getIdFromSYProtocol(openURL),
|
||||||
action: getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
action: getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,12 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
import {pdfResize} from "../asset/renderAssets";
|
import {pdfResize} from "../asset/renderAssets";
|
||||||
import {Backlink} from "./dock/Backlink";
|
import {Backlink} from "./dock/Backlink";
|
||||||
import {openFileById} from "../editor/util";
|
import {openFileById} from "../editor/util";
|
||||||
import {getSearch, isWindow, isSiyuanUrl, isWebSiyuanUrl, getIdFromSiyuanUrl, getIdFromWebSiyuanUrl} from "../util/functions";
|
import {getSearch, isWindow} from "../util/functions";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {setTabPosition} from "../window/setHeader";
|
import {setTabPosition} from "../window/setHeader";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
|
import {getIdFromSYProtocol, isSYProtocol} from "../util/pathName";
|
||||||
|
|
||||||
export const setPanelFocus = (element: Element) => {
|
export const setPanelFocus = (element: Element) => {
|
||||||
if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) {
|
if (element.classList.contains("layout__tab--active") || element.classList.contains("layout__wnd--active")) {
|
||||||
|
|
@ -369,17 +370,19 @@ export const JSONToLayout = (isStart: boolean) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// PWA 捕获 siyuan://
|
// TODO PWA 捕获 siyuan://
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
const url = searchParams.get("url");
|
const url = searchParams.get("url");
|
||||||
if (isSiyuanUrl(url) || isWebSiyuanUrl(url)) {
|
|
||||||
|
const isWebSiyuanUrl = /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||||
|
if (isSYProtocol(url) || isWebSiyuanUrl) {
|
||||||
searchParams.delete("url");
|
searchParams.delete("url");
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case isSiyuanUrl(url):
|
case isSYProtocol(url):
|
||||||
searchParams.set("id", getIdFromSiyuanUrl(url));
|
searchParams.set("id", getIdFromSYProtocol(url));
|
||||||
break;
|
break;
|
||||||
case isWebSiyuanUrl(url):
|
case isWebSiyuanUrl:
|
||||||
searchParams.set("id", getIdFromWebSiyuanUrl(url));
|
searchParams.set("id", url.substring(20, 20 + 22));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
||||||
import {Model} from "../layout/Model";
|
import {Model} from "../layout/Model";
|
||||||
import "../assets/scss/mobile.scss";
|
import "../assets/scss/mobile.scss";
|
||||||
import {Menus} from "../menus";
|
import {Menus} from "../menus";
|
||||||
import {addBaseURL, setNoteBook} from "../util/pathName";
|
import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "../util/pathName";
|
||||||
import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
|
import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
|
||||||
import {fetchGet, fetchPost} from "../util/fetch";
|
import {fetchGet, fetchPost} from "../util/fetch";
|
||||||
import {initFramework} from "./util/initFramework";
|
import {initFramework} from "./util/initFramework";
|
||||||
|
|
@ -18,7 +18,7 @@ import {goBack} from "./util/MobileBackFoward";
|
||||||
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
|
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
|
||||||
import {getLocalStorage} from "../protyle/util/compatibility";
|
import {getLocalStorage} from "../protyle/util/compatibility";
|
||||||
import {openMobileFileById} from "./editor";
|
import {openMobileFileById} from "./editor";
|
||||||
import {getSearch, isSiyuanUrl, getIdFromSiyuanUrl} from "../util/functions";
|
import {getSearch} from "../util/functions";
|
||||||
import {initRightMenu} from "./menu";
|
import {initRightMenu} from "./menu";
|
||||||
import {openChangelog} from "../boot/openChangelog";
|
import {openChangelog} from "../boot/openChangelog";
|
||||||
|
|
||||||
|
|
@ -90,8 +90,8 @@ window.showKeyboardToolbar = (height) => {
|
||||||
};
|
};
|
||||||
window.hideKeyboardToolbar = hideKeyboardToolbar;
|
window.hideKeyboardToolbar = hideKeyboardToolbar;
|
||||||
window.openFileByURL = (openURL) => {
|
window.openFileByURL = (openURL) => {
|
||||||
if (openURL && isSiyuanUrl(openURL)) {
|
if (openURL && isSYProtocol(openURL)) {
|
||||||
openMobileFileById(getIdFromSiyuanUrl(openURL),
|
openMobileFileById(getIdFromSYProtocol(openURL),
|
||||||
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,27 +46,3 @@ export const isFileAnnotation = (text: string) => {
|
||||||
export const looseJsonParse = (text: string) => {
|
export const looseJsonParse = (text: string) => {
|
||||||
return Function(`"use strict";return (${text})`)();
|
return Function(`"use strict";return (${text})`)();
|
||||||
};
|
};
|
||||||
|
|
||||||
/* redirect to auth page */
|
|
||||||
export const redirectToCheckAuth = (to: string = window.location.href) => {
|
|
||||||
const url = new URL(window.location.origin);
|
|
||||||
url.pathname = '/check-auth';
|
|
||||||
url.searchParams.set('to', to);
|
|
||||||
window.location.href = url.href;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isSiyuanUrl = (url: string) => {
|
|
||||||
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isWebSiyuanUrl = (url: string) => {
|
|
||||||
return /^web\+siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getIdFromSiyuanUrl = (url: string) => {
|
|
||||||
return url.substring(16, 16 + 22);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getIdFromWebSiyuanUrl = (url: string) => {
|
|
||||||
return url.substring(20, 20 + 22);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,22 @@ import {unicode2Emoji} from "../emoji";
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {showMessage} from "../dialog/message";
|
import {showMessage} from "../dialog/message";
|
||||||
|
|
||||||
|
export const isSYProtocol = (url: string) => {
|
||||||
|
return /^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getIdFromSYProtocol = (url: string) => {
|
||||||
|
return url.substring(16, 16 + 22);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* redirect to auth page */
|
||||||
|
export const redirectToCheckAuth = (to: string = window.location.href) => {
|
||||||
|
const url = new URL(window.location.origin);
|
||||||
|
url.pathname = '/check-auth';
|
||||||
|
url.searchParams.set('to', to);
|
||||||
|
window.location.href = url.href;
|
||||||
|
}
|
||||||
|
|
||||||
export const addBaseURL = () => {
|
export const addBaseURL = () => {
|
||||||
let baseURLElement = document.getElementById("baseURL");
|
let baseURLElement = document.getElementById("baseURL");
|
||||||
if (!baseURLElement) {
|
if (!baseURLElement) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {exportLayout, getInstanceById} from "../layout/util";
|
import {exportLayout, getInstanceById} from "../layout/util";
|
||||||
import {Tab} from "../layout/Tab";
|
import {Tab} from "../layout/Tab";
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {redirectToCheckAuth} from "../util/functions";
|
import {redirectToCheckAuth} from "../util/pathName";
|
||||||
|
|
||||||
const closeTab = (ipcData: IWebSocketData) => {
|
const closeTab = (ipcData: IWebSocketData) => {
|
||||||
const tab = getInstanceById(ipcData.data);
|
const tab = getInstanceById(ipcData.data);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue