mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-28 20:38:49 +01:00
This commit is contained in:
parent
16e1bf90ac
commit
2cec76fcc5
5 changed files with 80 additions and 45 deletions
|
|
@ -158,15 +158,21 @@ export const bindCardEvent = async (options: {
|
|||
window.siyuan.mobile.popEditor = editor;
|
||||
}
|
||||
if (options.cardsData.cards.length > 0) {
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
fetchPost("/api/block/getDocInfo", {
|
||||
id: options.cardsData.cards[index].blockID,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET_MAX
|
||||
}, (response) => {
|
||||
onGet({
|
||||
data: response,
|
||||
protyle: editor.protyle,
|
||||
action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||
editor.protyle.wysiwyg.renderCustom(response.data.ial);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: options.cardsData.cards[index].blockID,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET_MAX
|
||||
}, (response) => {
|
||||
onGet({
|
||||
updateReadonly: true,
|
||||
data: response,
|
||||
protyle: editor.protyle,
|
||||
action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -531,15 +537,21 @@ const nextCard = (options: {
|
|||
} else {
|
||||
options.actionElements[0].firstElementChild.removeAttribute("disabled");
|
||||
}
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
fetchPost("/api/block/getDocInfo", {
|
||||
id: options.blocks[options.index].blockID,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET_MAX
|
||||
}, (response) => {
|
||||
onGet({
|
||||
data: response,
|
||||
protyle: options.editor.protyle,
|
||||
action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||
options.editor.protyle.wysiwyg.renderCustom(response.data.ial);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: options.blocks[options.index].blockID,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET_MAX
|
||||
}, (response) => {
|
||||
onGet({
|
||||
updateReadonly: true,
|
||||
data: response,
|
||||
protyle: options.editor.protyle,
|
||||
action: response.data.rootID === response.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -288,15 +288,21 @@ const getArticle = (edit: Protyle, id: string) => {
|
|||
edit.protyle.element.nextElementSibling.classList.add("fn__none");
|
||||
edit.protyle.scroll.lastScrollTop = 0;
|
||||
addLoading(edit.protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
fetchPost("/api/block/getDocInfo", {
|
||||
id,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET_MAX,
|
||||
}, getResponse => {
|
||||
onGet({
|
||||
data: getResponse,
|
||||
protyle: edit.protyle,
|
||||
action: getResponse.data.rootID === getResponse.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||
}, (response) => {
|
||||
edit.protyle.wysiwyg.renderCustom(response.data.ial);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id,
|
||||
mode: 0,
|
||||
size: Constants.SIZE_GET_MAX,
|
||||
}, getResponse => {
|
||||
onGet({
|
||||
updateReadonly: true,
|
||||
data: getResponse,
|
||||
protyle: edit.protyle,
|
||||
action: getResponse.data.rootID === getResponse.data.id ? [Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
|
|||
if (window.siyuan.mobile.editor) {
|
||||
pushBack();
|
||||
addLoading(window.siyuan.mobile.editor.protyle);
|
||||
if (window.siyuan.mobile.editor.protyle.block.rootID !== data.data.rootID) {
|
||||
window.siyuan.mobile.editor.protyle.wysiwyg.element.innerHTML = "";
|
||||
}
|
||||
if (action.includes(Constants.CB_GET_SCROLL) && window.siyuan.storage[Constants.LOCAL_FILEPOSITION][data.data.rootID]) {
|
||||
getDocByScroll({
|
||||
protyle: window.siyuan.mobile.editor.protyle,
|
||||
|
|
@ -77,7 +80,11 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
|
|||
size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,
|
||||
}, getResponse => {
|
||||
onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action});
|
||||
onGet({
|
||||
data: getResponse,
|
||||
protyle: window.siyuan.mobile.editor.protyle,
|
||||
action
|
||||
});
|
||||
});
|
||||
}
|
||||
window.siyuan.mobile.editor.protyle.undo.clear();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export const onGet = (options: {
|
|||
protyle: IProtyle,
|
||||
action?: string[],
|
||||
scrollAttr?: IScrollAttr
|
||||
updateReadonly?: boolean
|
||||
afterCB?: () => void
|
||||
}) => {
|
||||
if (!options.action) {
|
||||
|
|
@ -79,6 +80,7 @@ export const onGet = (options: {
|
|||
expand: options.data.data.isBacklinkExpand,
|
||||
action: options.action,
|
||||
scrollAttr: options.scrollAttr,
|
||||
updateReadonly: options.updateReadonly,
|
||||
isSyncing: options.data.data.isSyncing,
|
||||
afterCB: options.afterCB,
|
||||
}, options.protyle);
|
||||
|
|
@ -104,6 +106,7 @@ export const onGet = (options: {
|
|||
expand: options.data.data.isBacklinkExpand,
|
||||
action: options.action,
|
||||
scrollAttr: options.scrollAttr,
|
||||
updateReadonly: options.updateReadonly,
|
||||
isSyncing: options.data.data.isSyncing,
|
||||
afterCB: options.afterCB,
|
||||
}, options.protyle);
|
||||
|
|
@ -116,6 +119,7 @@ const setHTML = (options: {
|
|||
action?: string[],
|
||||
isSyncing: boolean,
|
||||
expand: boolean,
|
||||
updateReadonly?: boolean,
|
||||
scrollAttr?: IScrollAttr
|
||||
afterCB?: () => void
|
||||
}, protyle: IProtyle) => {
|
||||
|
|
@ -124,7 +128,7 @@ const setHTML = (options: {
|
|||
}
|
||||
protyle.block.showAll = options.action.includes(Constants.CB_GET_ALL);
|
||||
const REMOVED_OVER_HEIGHT = protyle.contentElement.clientHeight * 8;
|
||||
const isUpdate = protyle.wysiwyg.element.innerHTML !== "";
|
||||
const updateReadonly = typeof options.updateReadonly === "undefined" ? protyle.wysiwyg.element.innerHTML === "" : options.updateReadonly;
|
||||
if (options.action.includes(Constants.CB_GET_APPEND)) {
|
||||
// 动态加载移除
|
||||
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT) {
|
||||
|
|
@ -199,7 +203,7 @@ const setHTML = (options: {
|
|||
protyle.breadcrumb.element.nextElementSibling.textContent = "";
|
||||
}
|
||||
protyle.element.removeAttribute("disabled-forever");
|
||||
setReadonlyByConfig(protyle, isUpdate);
|
||||
setReadonlyByConfig(protyle, updateReadonly);
|
||||
}
|
||||
|
||||
focusElementById(protyle, options.action, options.scrollAttr);
|
||||
|
|
@ -432,9 +436,9 @@ const focusElementById = (protyle: IProtyle, action: string[], scrollAttr?: IScr
|
|||
}
|
||||
};
|
||||
|
||||
export const setReadonlyByConfig = (protyle: IProtyle, isUpdate: boolean) => {
|
||||
export const setReadonlyByConfig = (protyle: IProtyle, updateReadonly: boolean) => {
|
||||
let readOnly = window.siyuan.config.readonly ? "true" : "false";
|
||||
if (isUpdate) {
|
||||
if (!updateReadonly) {
|
||||
readOnly = protyle.disabled ? "true" : "false";
|
||||
} else if (readOnly === "false") {
|
||||
readOnly = window.siyuan.config.editor.readOnly ? "true" : "false";
|
||||
|
|
|
|||
|
|
@ -1108,26 +1108,32 @@ export const getArticle = (options: {
|
|||
checkFold(options.id, (zoomIn) => {
|
||||
options.edit.protyle.scroll.lastScrollTop = 0;
|
||||
addLoading(options.edit.protyle);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
fetchPost("/api/block/getDocInfo", {
|
||||
id: options.id,
|
||||
query: options.value,
|
||||
queryMethod: options.config.method,
|
||||
queryTypes: options.config.types,
|
||||
mode: zoomIn ? 0 : 3,
|
||||
size: zoomIn ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
zoom: zoomIn,
|
||||
}, getResponse => {
|
||||
onGet({
|
||||
data: getResponse,
|
||||
protyle: options.edit.protyle,
|
||||
action: zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML],
|
||||
}, (response) => {
|
||||
options.edit.protyle.wysiwyg.renderCustom(response.data.ial);
|
||||
fetchPost("/api/filetree/getDoc", {
|
||||
id: options.id,
|
||||
query: options.value,
|
||||
queryMethod: options.config.method,
|
||||
queryTypes: options.config.types,
|
||||
mode: zoomIn ? 0 : 3,
|
||||
size: zoomIn ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
|
||||
zoom: zoomIn,
|
||||
}, getResponse => {
|
||||
onGet({
|
||||
updateReadonly: true,
|
||||
data: getResponse,
|
||||
protyle: options.edit.protyle,
|
||||
action: zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML],
|
||||
});
|
||||
const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`);
|
||||
if (matchElement) {
|
||||
matchElement.classList.add("search-mark--hl");
|
||||
const contentRect = options.edit.protyle.contentElement.getBoundingClientRect();
|
||||
options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + matchElement.getBoundingClientRect().top - contentRect.top - contentRect.height / 2;
|
||||
}
|
||||
});
|
||||
const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`);
|
||||
if (matchElement) {
|
||||
matchElement.classList.add("search-mark--hl");
|
||||
const contentRect = options.edit.protyle.contentElement.getBoundingClientRect();
|
||||
options.edit.protyle.contentElement.scrollTop = options.edit.protyle.contentElement.scrollTop + matchElement.getBoundingClientRect().top - contentRect.top - contentRect.height / 2;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue