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:desktop": "webpack --mode production --config webpack.desktop.js",
"build:export": "webpack --mode production --config webpack.export.js",
"build:types": "tsc -d",
"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": "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") {
return;
}
const action = [];
const action: TProtyleAction[] = [];
if (response.data.rootID !== this.nodeIds[index]) {
action.push(Constants.CB_GET_ALL);
} else {

View file

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

View file

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

View file

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

View file

@ -51,9 +51,9 @@ export class Protyle {
* @param id Protyle ID
* @param options Protyle
*/
constructor(app: App, id: HTMLElement, options?: IOptions) {
constructor(app: App, id: HTMLElement, options?: IProtyleOptions) {
this.version = Constants.SIYUAN_VERSION;
let pluginsOptions: IOptions = options;
let pluginsOptions: IProtyleOptions = options;
app.plugins.forEach(item => {
if (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", {
id: mergedOptions.blockId,
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 !MOBILE
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: {
protyle: IProtyle,
scrollAttr?: IScrollAttr,
mergedOptions?: IOptions,
mergedOptions?: IProtyleOptions,
cb?: () => void
focus?: boolean,
updateReadonly?: boolean

View file

@ -4,8 +4,8 @@ import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
import {isMobile} from "../../util/functions";
export class Options {
public options: IOptions;
private defaultOptions: IOptions = {
public options: IProtyleOptions;
private defaultOptions: IProtyleOptions = {
mode: "wysiwyg",
blockId: "",
render: {
@ -132,11 +132,11 @@ export class Options {
}
};
constructor(options: IOptions) {
constructor(options: IProtyleOptions) {
this.options = options;
}
public merge(): IOptions {
public merge(): IProtyleOptions {
if (this.options) {
if (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 TDockPosition = "Left" | "Right" | "Bottom"
type TWS = "main" | "filetree" | "protyle"
type TEditorMode = "preview" | "wysiwyg"
type TOperation =
"insert"
| "update"
@ -428,17 +427,6 @@ interface ISiyuan {
viewer?: Viewer
}
interface IScrollAttr {
rootId: string,
startId: string,
endId: string
scrollTop: number,
focusId?: string,
focusStart?: number
focusEnd?: number
zoomInId?: string
}
interface IOperation {
action: TOperation, // move delete 不需要传 data
id?: string,

View file

@ -16,8 +16,27 @@ type TTurnIntoOneSub = "row" | "col"
type TTurnInto = "Blocks2Ps" | "Blocks2Hs"
type TEditorMode = "preview" | "wysiwyg"
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 */
interface ILuteRender {
renderDocument?: ILuteRenderCallback;
@ -313,6 +332,17 @@ interface IUpload {
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 */
interface IMenuItem {
/** 唯一标示 */
@ -398,7 +428,7 @@ interface IHint {
}
/** @link https://ld246.com/article/1549638745630#options */
interface IOptions {
interface IProtyleOptions {
history?: {
created?: string
snapshot?: string
@ -408,7 +438,7 @@ interface IOptions {
dom: string
expand: boolean
}[],
action?: string[],
action?: TProtyleAction[],
mode?: TEditorMode,
blockId: string
rootId?: string
@ -484,7 +514,7 @@ interface IProtyle {
title?: import("../protyle/header/Title").Title,
background?: import("../protyle/header/background").Background,
contentElement?: HTMLElement,
options: IOptions;
options: IProtyleOptions;
lute?: Lute;
toolbar?: import("../protyle/toolbar").Toolbar,
preview?: import("../protyle/preview").Preview;

View file

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