Vanessa 2024-10-22 18:13:21 +08:00
parent 20e8b81b8f
commit 5760f7fe4c
11 changed files with 53 additions and 32 deletions

View File

@ -16,6 +16,7 @@
"build:mobile": "webpack --mode production --config webpack.mobile.js", "build:mobile": "webpack --mode production --config webpack.mobile.js",
"build:desktop": "webpack --mode production --config webpack.desktop.js", "build:desktop": "webpack --mode production --config webpack.desktop.js",
"build:export": "webpack --mode production --config webpack.export.js", "build:export": "webpack --mode production --config webpack.export.js",
"build:types": "tsc -d",
"start": "NODE_ENV=development electron ./electron/main.js", "start": "NODE_ENV=development electron ./electron/main.js",
"dist-appx": "ELECTRON_MIRROR=https://cnpmjs.org/mirrors/electron/ electron-builder --config electron-appx-builder.yml", "dist-appx": "ELECTRON_MIRROR=https://cnpmjs.org/mirrors/electron/ electron-builder --config electron-appx-builder.yml",
"dist": "ELECTRON_MIRROR=https://cnpmjs.org/mirrors/electron/ electron-builder --config electron-builder.yml --publish=never", "dist": "ELECTRON_MIRROR=https://cnpmjs.org/mirrors/electron/ electron-builder --config electron-builder.yml --publish=never",

View File

@ -161,7 +161,7 @@ export class BlockPanel {
if (!this.targetElement && typeof this.x === "undefined" && typeof this.y === "undefined") { if (!this.targetElement && typeof this.x === "undefined" && typeof this.y === "undefined") {
return; return;
} }
const action = []; const action: TProtyleAction[] = [];
if (response.data.rootID !== this.nodeIds[index]) { if (response.data.rootID !== this.nodeIds[index]) {
action.push(Constants.CB_GET_ALL); action.push(Constants.CB_GET_ALL);
} else { } else {

View File

@ -20,7 +20,7 @@ export class Editor extends Model {
blockId: string, blockId: string,
rootId: string, rootId: string,
mode?: TEditorMode, mode?: TEditorMode,
action?: string[], action?: TProtyleAction[],
}) { }) {
super({ super({
app: options.app, app: options.app,
@ -36,7 +36,7 @@ export class Editor extends Model {
private initProtyle(options: { private initProtyle(options: {
blockId: string, blockId: string,
action?: string[] action?: TProtyleAction[]
rootId: string, rootId: string,
mode?: TEditorMode, mode?: TEditorMode,
}) { }) {

View File

@ -19,7 +19,7 @@ export const getCurrentEditor = () => {
return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor; return window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
}; };
export const openMobileFileById = (app: App, id: string, action = [Constants.CB_GET_HL]) => { export const openMobileFileById = (app: App, id: string, action: TProtyleAction[] = [Constants.CB_GET_HL]) => {
window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id}; window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id};
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]); setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
const avPanelElement = document.querySelector(".av__panel"); const avPanelElement = document.querySelector(".av__panel");
@ -52,7 +52,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
showMessage(data.msg); showMessage(data.msg);
return; return;
} }
const protyleOptions: IOptions = { const protyleOptions: IProtyleOptions = {
blockId: id, blockId: id,
rootId: data.data.rootID, rootId: data.data.rootID,
action, action,

View File

@ -57,7 +57,7 @@ export class Plugin {
/// #endif /// #endif
} }
} = {}; } = {};
private protyleOptionsValue: IOptions; private protyleOptionsValue: IProtyleOptions;
constructor(options: { constructor(options: {
app: App, app: App,
@ -373,7 +373,7 @@ export class Plugin {
})); }));
}; };
set protyleOptions(options: IOptions) { set protyleOptions(options: IProtyleOptions) {
this.protyleOptionsValue = options; this.protyleOptionsValue = options;
} }

View File

@ -51,9 +51,9 @@ export class Protyle {
* @param id Protyle ID * @param id Protyle ID
* @param options Protyle * @param options Protyle
*/ */
constructor(app: App, id: HTMLElement, options?: IOptions) { constructor(app: App, id: HTMLElement, options?: IProtyleOptions) {
this.version = Constants.SIYUAN_VERSION; this.version = Constants.SIYUAN_VERSION;
let pluginsOptions: IOptions = options; let pluginsOptions: IProtyleOptions = options;
app.plugins.forEach(item => { app.plugins.forEach(item => {
if (item.protyleOptions) { if (item.protyleOptions) {
pluginsOptions = merge(pluginsOptions, item.protyleOptions); pluginsOptions = merge(pluginsOptions, item.protyleOptions);
@ -260,7 +260,7 @@ export class Protyle {
} }
} }
private getDoc(mergedOptions: IOptions) { private getDoc(mergedOptions: IProtyleOptions) {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: mergedOptions.blockId, id: mergedOptions.blockId,
isBacklink: mergedOptions.action.includes(Constants.CB_GET_BACKLINK), isBacklink: mergedOptions.action.includes(Constants.CB_GET_BACKLINK),
@ -279,7 +279,7 @@ export class Protyle {
}); });
} }
private afterOnGet(mergedOptions: IOptions) { private afterOnGet(mergedOptions: IProtyleOptions) {
if (this.protyle.model) { if (this.protyle.model) {
/// #if !MOBILE /// #if !MOBILE
if (mergedOptions.action?.includes(Constants.CB_GET_FOCUS) || mergedOptions.action?.includes(Constants.CB_GET_OPENNEW)) { if (mergedOptions.action?.includes(Constants.CB_GET_FOCUS) || mergedOptions.action?.includes(Constants.CB_GET_OPENNEW)) {

View File

@ -51,7 +51,7 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
export const getDocByScroll = (options: { export const getDocByScroll = (options: {
protyle: IProtyle, protyle: IProtyle,
scrollAttr?: IScrollAttr, scrollAttr?: IScrollAttr,
mergedOptions?: IOptions, mergedOptions?: IProtyleOptions,
cb?: () => void cb?: () => void
focus?: boolean, focus?: boolean,
updateReadonly?: boolean updateReadonly?: boolean

View File

@ -4,8 +4,8 @@ import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
import {isMobile} from "../../util/functions"; import {isMobile} from "../../util/functions";
export class Options { export class Options {
public options: IOptions; public options: IProtyleOptions;
private defaultOptions: IOptions = { private defaultOptions: IProtyleOptions = {
mode: "wysiwyg", mode: "wysiwyg",
blockId: "", blockId: "",
render: { render: {
@ -132,11 +132,11 @@ export class Options {
} }
}; };
constructor(options: IOptions) { constructor(options: IProtyleOptions) {
this.options = options; this.options = options;
} }
public merge(): IOptions { public merge(): IProtyleOptions {
if (this.options) { if (this.options) {
if (this.options.toolbar) { if (this.options.toolbar) {
this.options.toolbar = this.mergeToolbar(this.options.toolbar); this.options.toolbar = this.mergeToolbar(this.options.toolbar);

View File

@ -1,7 +1,6 @@
type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight" type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight"
type TDockPosition = "Left" | "Right" | "Bottom" type TDockPosition = "Left" | "Right" | "Bottom"
type TWS = "main" | "filetree" | "protyle" type TWS = "main" | "filetree" | "protyle"
type TEditorMode = "preview" | "wysiwyg"
type TOperation = type TOperation =
"insert" "insert"
| "update" | "update"
@ -428,17 +427,6 @@ interface ISiyuan {
viewer?: Viewer viewer?: Viewer
} }
interface IScrollAttr {
rootId: string,
startId: string,
endId: string
scrollTop: number,
focusId?: string,
focusStart?: number
focusEnd?: number
zoomInId?: string
}
interface IOperation { interface IOperation {
action: TOperation, // move delete 不需要传 data action: TOperation, // move delete 不需要传 data
id?: string, id?: string,

View File

@ -16,8 +16,27 @@ type TTurnIntoOneSub = "row" | "col"
type TTurnInto = "Blocks2Ps" | "Blocks2Hs" type TTurnInto = "Blocks2Ps" | "Blocks2Hs"
type TEditorMode = "preview" | "wysiwyg"
type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number]; type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number];
type TProtyleAction = "cb-get-append" | // 向下滚动加载
"cb-get-before" | // 向上滚动加载
"cb-get-unchangeid" | // 上下滚动,定位时不修改 blockid
"cb-get-hl" | // 高亮
"cb-get-focus" | // 光标定位
"cb-get-focusfirst" | // 动态定位到第一个块
"cb-get-setid" | // 重置 blockid
"cb-get-all" | // 获取所有块
"cb-get-backlink" | // 悬浮窗为传递型需展示上下文
"cb-get-unundo" | // 不需要记录历史
"cb-get-scroll" | // 滚动到指定位置,用于直接打开文档,必有 rootID
"cb-get-context" | // 包含上下文
"cb-get-rootscroll" | // 如果为 rootID 就滚动到指定位置,必有 rootID
"cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo否则搜索表格无法定位
"cb-get-history" | // 历史渲染
"cb-get-opennew" // 编辑器只读后新建文件需为临时解锁状态 & https://github.com/siyuan-note/siyuan/issues/12197
/** @link https://ld246.com/article/1588412297062 */ /** @link https://ld246.com/article/1588412297062 */
interface ILuteRender { interface ILuteRender {
renderDocument?: ILuteRenderCallback; renderDocument?: ILuteRenderCallback;
@ -313,6 +332,17 @@ interface IUpload {
linkToImgCallback?(responseText: string): void; linkToImgCallback?(responseText: string): void;
} }
interface IScrollAttr {
rootId: string,
startId: string,
endId: string
scrollTop: number,
focusId?: string,
focusStart?: number
focusEnd?: number
zoomInId?: string
}
/** @link https://ld246.com/article/1549638745630#options-toolbar */ /** @link https://ld246.com/article/1549638745630#options-toolbar */
interface IMenuItem { interface IMenuItem {
/** 唯一标示 */ /** 唯一标示 */
@ -398,7 +428,7 @@ interface IHint {
} }
/** @link https://ld246.com/article/1549638745630#options */ /** @link https://ld246.com/article/1549638745630#options */
interface IOptions { interface IProtyleOptions {
history?: { history?: {
created?: string created?: string
snapshot?: string snapshot?: string
@ -408,7 +438,7 @@ interface IOptions {
dom: string dom: string
expand: boolean expand: boolean
}[], }[],
action?: string[], action?: TProtyleAction[],
mode?: TEditorMode, mode?: TEditorMode,
blockId: string blockId: string
rootId?: string rootId?: string
@ -484,7 +514,7 @@ interface IProtyle {
title?: import("../protyle/header/Title").Title, title?: import("../protyle/header/Title").Title,
background?: import("../protyle/header/background").Background, background?: import("../protyle/header/background").Background,
contentElement?: HTMLElement, contentElement?: HTMLElement,
options: IOptions; options: IProtyleOptions;
lute?: Lute; lute?: Lute;
toolbar?: import("../protyle/toolbar").Toolbar, toolbar?: import("../protyle/toolbar").Toolbar,
preview?: import("../protyle/preview").Preview; preview?: import("../protyle/preview").Preview;

View File

@ -10,7 +10,9 @@
"types": [ "types": [
"./src/types", "./src/types",
"node" "node"
] ],
"declaration": true,
"emitDeclarationOnly": true,
}, },
"include": [ "include": [
"src" "src"