Vanessa 2024-10-23 11:47:06 +08:00
parent 72d1a059ac
commit d10b25c2ca
18 changed files with 44 additions and 45 deletions

1
.gitignore vendored
View file

@ -11,6 +11,7 @@
app/node_modules
app/stage/build
app/build
app/src/types/dist
app/kernel*
ios
pprof

View file

@ -1,7 +1,6 @@
build
dist
node_modules
public
src/asset/pdf
src/types/dist
stage
appearance

View file

@ -85,10 +85,10 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "par
openFileById({
app: protyle.app,
id: targetId,
action: [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]
action: targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]
});
/// #else
openMobileFileById(protyle.app, targetId, [Constants.CB_GET_FOCUS, targetId !== protyle.block.rootID && protyle.block.showAll ? Constants.CB_GET_ALL : ""]);
openMobileFileById(protyle.app, targetId, targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);
/// #endif
});
};

View file

@ -262,10 +262,10 @@ export const globalCommand = (command: string, app: App) => {
if (command === "closeTab") {
const activeTabElement = document.querySelector(".layout__tab--active");
if (activeTabElement && activeTabElement.getBoundingClientRect().width > 0) {
let type = "";
let type: TDock;
Array.from(activeTabElement.classList).find(item => {
if (item.startsWith("sy__")) {
type = item.replace("sy__", "");
type = item.replace("sy__", "") as TDock;
return true;
}
});

View file

@ -41,7 +41,7 @@ export const openFileById = async (options: {
id: string,
position?: string,
mode?: TEditorMode,
action?: string[]
action?: TProtyleAction[]
keepCursor?: boolean
zoomIn?: boolean
removeCurrentTab?: boolean

View file

@ -85,7 +85,7 @@ export class Bookmark extends Model {
}
}
const id = element.getAttribute("data-node-id");
checkFold(id, (zoomIn, action: string[]) => {
checkFold(id, (zoomIn, action: TProtyleAction[]) => {
openFileById({
app,
id,
@ -111,7 +111,7 @@ export class Bookmark extends Model {
},
altClick: (element: HTMLElement,) => {
const id = element.getAttribute("data-node-id");
checkFold(id, (zoomIn, action: string[]) => {
checkFold(id, (zoomIn, action: TProtyleAction[]) => {
openFileById({
app,
id,
@ -123,7 +123,7 @@ export class Bookmark extends Model {
},
shiftClick: (element: HTMLElement) => {
const id = element.getAttribute("data-node-id");
checkFold(id, (zoomIn, action: string[]) => {
checkFold(id, (zoomIn, action: TProtyleAction[]) => {
openFileById({
app,
id,

View file

@ -667,7 +667,7 @@ export class Graph extends Model {
return;
}
if (window.siyuan.shiftIsPressed) {
checkFold(node.id, (zoomIn, action: string[]) => {
checkFold(node.id, (zoomIn, action: TProtyleAction[]) => {
openFileById({
app: this.app,
id: node.id,
@ -677,7 +677,7 @@ export class Graph extends Model {
});
});
} else if (window.siyuan.altIsPressed) {
checkFold(node.id, (zoomIn, action: string[]) => {
checkFold(node.id, (zoomIn, action: TProtyleAction[]) => {
openFileById({
app: this.app,
id: node.id,
@ -695,7 +695,7 @@ export class Graph extends Model {
nodeIds: [node.id],
}));
} else {
checkFold(node.id, (zoomIn, action: string[]) => {
checkFold(node.id, (zoomIn, action: TProtyleAction[]) => {
openFileById({
app: this.app,
id: node.id,

View file

@ -29,7 +29,7 @@ export class Dock {
private app: App;
public resizeElement: HTMLElement;
public pin = true;
public data: { [key: string]: Model | boolean };
public data: { [key in TDock | string]?: Model | boolean };
private hideResizeTimeout: number;
constructor(options: {
@ -112,13 +112,13 @@ export class Dock {
this.resizeElement.classList.add("fn__none");
} else {
activeElements.forEach(item => {
this.toggleModel(item.getAttribute("data-type"), true, false, false, false);
this.toggleModel(item.getAttribute("data-type") as TDock, true, false, false, false);
});
}
this.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(this.element)) {
const type = target.getAttribute("data-type");
const type = target.getAttribute("data-type") as TDock;
if (type) {
this.toggleModel(type, false, true);
event.preventDefault();
@ -359,7 +359,7 @@ export class Dock {
documentSelf.onselect = null;
this.setSize();
this.element.querySelectorAll(".dock__item--active").forEach(item => {
const customModel = this.data[item.getAttribute("data-type")];
const customModel = this.data[item.getAttribute("data-type") as TDock];
if (customModel && customModel instanceof Custom && customModel.resize) {
customModel.resize();
}
@ -491,7 +491,7 @@ export class Dock {
this.layout.element.querySelector(".layout__tab--active")?.classList.remove("layout__tab--active");
}
public toggleModel(type: string, show = false, close = false, hide = false, isSaveLayout = true) {
public toggleModel(type: TDock | string, show = false, close = false, hide = false, isSaveLayout = true) {
if (!type) {
return;
}
@ -757,7 +757,7 @@ export class Dock {
public add(index: number, sourceElement: Element, previousType?: string) {
sourceElement.setAttribute("data-height", "");
sourceElement.setAttribute("data-width", "");
const type = sourceElement.getAttribute("data-type");
const type = sourceElement.getAttribute("data-type") as TDock;
const sourceDock = getDockByType(type);
if (sourceDock.element.querySelectorAll(".dock__item").length === 2) {
sourceDock.element.classList.add("fn__none");
@ -794,7 +794,7 @@ export class Dock {
saveLayout();
}
public remove(key: string) {
public remove(key: TDock|string) {
this.toggleModel(key, false, true, true);
this.element.querySelector(`[data-type="${key}"]`).remove();
const custom = this.data[key] as Custom;
@ -809,12 +809,12 @@ export class Dock {
activesElement.forEach((item) => {
if (this.position === "Left" || this.position === "Right") {
if (item.getAttribute("data-index") === "1" && activesElement.length > 1) {
item.setAttribute("data-height", (this.data[item.getAttribute("data-type")] as Model).parent.parent.element.clientHeight.toString());
item.setAttribute("data-height", (this.data[item.getAttribute("data-type") as TDock] as Model).parent.parent.element.clientHeight.toString());
}
item.setAttribute("data-width", this.layout.element.clientWidth.toString());
} else {
if (item.getAttribute("data-index") === "1" && activesElement.length > 1) {
item.setAttribute("data-width", (this.data[item.getAttribute("data-type")] as Model).parent.parent.element.clientWidth.toString());
item.setAttribute("data-width", (this.data[item.getAttribute("data-type") as TDock] as Model).parent.parent.element.clientWidth.toString());
}
item.setAttribute("data-height", this.layout.element.clientHeight.toString());
}

View file

@ -66,7 +66,7 @@ export const switchTabByIndex = (index: number) => {
indexElement = activeDockIcoElement.parentElement.firstElementChild;
}
}
const type = indexElement?.getAttribute("data-type");
const type = indexElement?.getAttribute("data-type") as TDock;
if (type) {
getDockByType(type)?.toggleModel(type, true, false);
}
@ -142,7 +142,7 @@ export const resizeTabs = (isSaveLayout = true) => {
}, 200);
};
export const getDockByType = (type: string) => {
export const getDockByType = (type: TDock | string) => {
if (!window.siyuan.layout.leftDock) {
return undefined;
}
@ -253,7 +253,7 @@ export const copyTab = (app: App, tab: Tab) => {
callback(newTab: Tab) {
let model: Model;
if (tab.model instanceof Editor) {
const newAction: string[] = [];
const newAction: TProtyleAction[] = [];
// https://github.com/siyuan-note/siyuan/issues/12132
tab.model.editor.protyle.block.action.forEach(item => {
if (item !== Constants.CB_GET_APPEND && item !== Constants.CB_GET_BEFORE && item !== Constants.CB_GET_HTML) {

View file

@ -18,6 +18,7 @@ import {Protyle} from "../protyle";
import {openMobileFileById} from "../mobile/editor";
import {lockScreen, exitSiYuan} from "../dialog/processSystem";
import {Model} from "../layout/Model";
import {getDockByType} from "../layout/tabUtil";
let openTab;
let openWindow;
@ -52,7 +53,7 @@ openTab = (options: {
app: App,
doc?: {
id: string, // 块 id
action?: string [] // cb-get-all获取所有内容cb-get-focus打开后光标定位在 id 所在的块cb-get-hl: 打开后 id 块高亮
action?: TProtyleAction [] // cb-get-all获取所有内容cb-get-focus打开后光标定位在 id 所在的块cb-get-hl: 打开后 id 块高亮
zoomIn?: boolean // 是否缩放
},
pdf?: {
@ -166,23 +167,24 @@ openTab = (options: {
/// #endif
export const API = {
confirm: confirmDialog,
showMessage,
adaptHotkey: updateHotkeyTip,
confirm: confirmDialog,
Constants,
showMessage,
fetchPost,
fetchSyncPost,
fetchGet,
getFrontend,
getBackend,
lockScreen,
exitSiYuan,
openMobileFileById,
getDockByType,
openTab,
openWindow,
openMobileFileById,
lockScreen,
exitSiYuan,
Protyle,
Plugin,
Dialog,
Menu,
Setting,
Constants,
};

View file

@ -8,9 +8,6 @@ export class EventBus<DetailType = any> {
}
on(type: TEventBus, listener: (event: CustomEvent<DetailType>) => void) {
if (type ==="loaded-protyle") {
console.warn("0.8.8 将移除 loaded-protyle, 请使用 loaded-protyle-static 进行替代");
}
this.eventTarget.addEventListener(type, listener);
}

View file

@ -56,7 +56,7 @@ export const getDocByScroll = (options: {
focus?: boolean,
updateReadonly?: boolean
}) => {
let actions: string[] = [];
let actions: TProtyleAction[] = [];
if (options.mergedOptions) {
actions = options.mergedOptions.action;
} else {

View file

@ -24,7 +24,7 @@ import {getContenteditableElement} from "../wysiwyg/getBlock";
export const onGet = (options: {
data: IWebSocketData,
protyle: IProtyle,
action?: string[],
action?: TProtyleAction[],
scrollAttr?: IScrollAttr
updateReadonly?: boolean
afterCB?: () => void
@ -290,7 +290,6 @@ const setHTML = (options: {
}
protyle.app.plugins.forEach(item => {
item.eventBus.emit("loaded-protyle", protyle); // 准备废弃
item.eventBus.emit("loaded-protyle-static", {protyle});
});
};

View file

@ -1646,7 +1646,7 @@ declare namespace Config {
/**
* Tab type
*/
type: string;
type: TDock | string;
}
/**

View file

@ -1,6 +1,7 @@
type TPluginDockPosition = "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight"
type TDockPosition = "Left" | "Right" | "Bottom"
type TWS = "main" | "filetree" | "protyle"
type TDock = "file" | "outline" | "inbox" | "bookmark" | "tag" | "graph" | "globalGraph" | "backlink"
type TOperation =
"insert"
| "update"
@ -63,7 +64,7 @@ type TEventBus = "ws-main" | "sync-start" | "sync-end" | "sync-fail" |
"closed-notebook" |
"paste" |
"input-search" |
"loaded-protyle" | "loaded-protyle-dynamic" | "loaded-protyle-static" |
"loaded-protyle-dynamic" | "loaded-protyle-static" |
"switch-protyle" |
"destroy-protyle" |
"lock-screen" |
@ -316,7 +317,7 @@ interface IBackStack {
notebookId: string
},
scrollTop?: number,
callback?: string[],
callback?: TProtyleAction[],
position?: {
start: number,
end: number
@ -543,7 +544,7 @@ interface IOpenFileOptions {
position?: string, // file 或者 asset打开位置
page?: number | string, // asset
mode?: TEditorMode // file
action?: string[]
action?: TProtyleAction[]
keepCursor?: boolean // file是否跳转到新 tab 上
zoomIn?: boolean // 是否缩放
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签

View file

@ -498,7 +498,7 @@ interface IProtyle {
showAll?: boolean
mode?: number
blockCount?: number
action?: string[]
action?: TProtyleAction[]
},
disabled: boolean,
selectElement?: HTMLElement,

View file

@ -35,7 +35,7 @@ export const getWorkspaceName = () => {
return pathPosix().basename(window.siyuan.config.system.workspaceDir.replace(/\\/g, "/"));
};
export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[], isRoot: boolean) => void) => {
export const checkFold = (id: string, cb: (zoomIn: boolean, action: TProtyleAction[], isRoot: boolean) => void) => {
if (!id) {
return;
}

View file

@ -1,6 +1,6 @@
{
"compilerOptions": {
"outDir": "./dist/",
"outDir": "./src/types/dist",
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",