This commit is contained in:
Vanessa 2023-02-24 15:25:04 +08:00
parent 9dd686c58c
commit 7334b5f615
12 changed files with 52 additions and 10 deletions

View file

@ -1,4 +1,5 @@
{ {
"pdfIsLoading": "PDF is loading, please try again later",
"addToDeck": "Add to Deck...", "addToDeck": "Add to Deck...",
"quickMakeCard": "Quick make card", "quickMakeCard": "Quick make card",
"allAttrs": "All attribute names and attribute values", "allAttrs": "All attribute names and attribute values",

View file

@ -1,4 +1,5 @@
{ {
"pdfIsLoading": "El PDF se está cargando, inténtalo de nuevo más tarde",
"addToDeck": "Agregar a la plataforma...", "addToDeck": "Agregar a la plataforma...",
"quickMakeCard": "Tarjeta de creación rápida", "quickMakeCard": "Tarjeta de creación rápida",
"allAttrs": "Todos los nombres de atributos y valores de atributos", "allAttrs": "Todos los nombres de atributos y valores de atributos",

View file

@ -1,4 +1,5 @@
{ {
"pdfIsLoading": "Le PDF est en cours de chargement, veuillez réessayer plus tard",
"addToDeck": "Ajouter au deck...", "addToDeck": "Ajouter au deck...",
"quickMakeCard": "Carte de création rapide", "quickMakeCard": "Carte de création rapide",
"allAttrs": "Tous les noms d'attributs et les valeurs d'attributs", "allAttrs": "Tous les noms d'attributs et les valeurs d'attributs",

View file

@ -1,4 +1,5 @@
{ {
"pdfIsLoading": "PDF 正在加載中,請稍後再試",
"addToDeck": "添加到卡包...", "addToDeck": "添加到卡包...",
"quickMakeCard": "快速制卡", "quickMakeCard": "快速制卡",
"allAttrs": "所有屬性名和屬性值", "allAttrs": "所有屬性名和屬性值",

View file

@ -1,4 +1,5 @@
{ {
"pdfIsLoading": "PDF 正在加载中,请稍后再试",
"addToDeck": "添加到卡包...", "addToDeck": "添加到卡包...",
"quickMakeCard": "快速制卡", "quickMakeCard": "快速制卡",
"allAttrs": "所有属性名和属性值", "allAttrs": "所有属性名和属性值",

View file

@ -467,14 +467,16 @@ export class Asset extends Model {
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
this.pdfObject = webViewerLoad(this.path.startsWith("file") ? this.path : document.getElementById("baseURL").getAttribute("href") + "/" + this.path, this.pdfObject = webViewerLoad(this.path.startsWith("file") ? this.path : document.getElementById("baseURL").getAttribute("href") + "/" + this.path,
this.element, this.pdfPage, this.pdfId); this.element, this.pdfPage, this.pdfId);
this.element.setAttribute("data-loading", "true")
observer.disconnect(); observer.disconnect();
}); });
observer.observe(this.element, {attributeFilter: ["class"]}); observer.observe(this.element, {attributeFilter: ["class"]});
} else { } else {
this.pdfObject = webViewerLoad(this.path.startsWith("file") ? this.path : document.getElementById("baseURL").getAttribute("href") + "/" + this.path, this.pdfObject = webViewerLoad(this.path.startsWith("file") ? this.path : document.getElementById("baseURL").getAttribute("href") + "/" + this.path,
this.element, this.pdfPage, this.pdfId); this.element, this.pdfPage, this.pdfId);
this.element.setAttribute("data-loading", "true")
} }
}); }, Constants.TIMEOUT_BLOCKLOAD);
/// #endif /// #endif
} }
} }

View file

@ -80,6 +80,7 @@ import { ViewHistory } from './view_history.js'
import { Constants } from '../../constants' import { Constants } from '../../constants'
import { GenericExternalServices } from './genericcom' import { GenericExternalServices } from './genericcom'
import { getPdfInstance, hlPDFRect } from '../anno' import { getPdfInstance, hlPDFRect } from '../anno'
import {hasClosestByClassName} from "../../protyle/util/hasClosest";
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000 // ms const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000 // ms
const FORCE_PAGES_LOADED_TIMEOUT = 10000 // ms const FORCE_PAGES_LOADED_TIMEOUT = 10000 // ms
@ -1294,6 +1295,11 @@ class PDFViewerApplication {
// To prevent any future issues, e.g. the document being completely // To prevent any future issues, e.g. the document being completely
// blank on load, always trigger rendering here. // blank on load, always trigger rendering here.
pdfViewer.update() pdfViewer.update()
// NOTE: 没有渲染完就切换页签导致 https://ld246.com/article/1677072688346
const tabElement = hasClosestByClassName(pdfViewer.container, "fn__flex-1")
if (tabElement) {
tabElement.removeAttribute("data-loading")
}
}) })
}) })
@ -1698,6 +1704,10 @@ class PDFViewerApplication {
this.pdfViewer.cleanup() this.pdfViewer.cleanup()
this.pdfThumbnailViewer.cleanup() this.pdfThumbnailViewer.cleanup()
// NOTE: 防止定时任务导致 PDF this.messageHandler.sendWithPromise 报错
if (this.pdfLoadingTask.destroyed) {
return;
}
if ( if (
typeof PDFJSDev === 'undefined' || typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('!PRODUCTION || GENERIC') PDFJSDev.test('!PRODUCTION || GENERIC')

View file

@ -13,6 +13,8 @@
* limitations under the License. * limitations under the License.
*/ */
import {hasClosestByAttribute} from "../../protyle/util/hasClosest";
const DEFAULT_SCALE_VALUE = "auto"; const DEFAULT_SCALE_VALUE = "auto";
const DEFAULT_SCALE = 1.0; const DEFAULT_SCALE = 1.0;
const DEFAULT_SCALE_DELTA = 1.1; const DEFAULT_SCALE_DELTA = 1.1;

View file

@ -251,6 +251,7 @@
border-bottom: 1px solid var(--b3-theme-surface-lighter); border-bottom: 1px solid var(--b3-theme-surface-lighter);
transition-duration: 200ms; transition-duration: 200ms;
transition-timing-function: ease; transition-timing-function: ease;
z-index: 1;
} }
#loadingBar { #loadingBar {

View file

@ -1,7 +1,7 @@
import {Tab} from "../layout/Tab"; import {Tab} from "../layout/Tab";
import {Editor} from "./index"; import {Editor} from "./index";
import {Wnd} from "../layout/Wnd"; import {Wnd} from "../layout/Wnd";
import {getDockByType, getInstanceById, getWndByLayout} from "../layout/util"; import {getDockByType, getInstanceById, getWndByLayout, pdfIsLoading} from "../layout/util";
import {getAllModels, getAllTabs} from "../layout/getAll"; import {getAllModels, getAllTabs} from "../layout/getAll";
import {highlightById, scrollCenter} from "../util/highlightById"; import {highlightById, scrollCenter} from "../util/highlightById";
import {getDisplayName, pathPosix} from "../util/pathName"; import {getDisplayName, pathPosix} from "../util/pathName";
@ -77,9 +77,11 @@ const openFile = (options: IOpenFileOptions) => {
if (options.assetPath) { if (options.assetPath) {
const asset = allModels.asset.find((item) => { const asset = allModels.asset.find((item) => {
if (item.path == options.assetPath) { if (item.path == options.assetPath) {
if (!pdfIsLoading(item.parent.parent.element)) {
item.parent.parent.switchTab(item.parent.headElement); item.parent.parent.switchTab(item.parent.headElement);
item.parent.parent.showHeading(); item.parent.parent.showHeading();
item.goToPage(options.page); item.goToPage(options.page);
}
return true; return true;
} }
}); });
@ -104,7 +106,9 @@ const openFile = (options: IOpenFileOptions) => {
editor = activeEditor; editor = activeEditor;
} }
if (editor) { if (editor) {
if (!pdfIsLoading(editor.parent.parent.element)) {
switchEditor(editor, options, allModels); switchEditor(editor, options, allModels);
}
return true; return true;
} }
// 没有初始化的页签无法检测到 // 没有初始化的页签无法检测到
@ -141,6 +145,9 @@ const openFile = (options: IOpenFileOptions) => {
}); });
} }
if (targetWnd) { if (targetWnd) {
if (pdfIsLoading(targetWnd.element)) {
return;
}
// 在右侧/下侧打开已有页签将进行页签切换 https://github.com/siyuan-note/siyuan/issues/5366 // 在右侧/下侧打开已有页签将进行页签切换 https://github.com/siyuan-note/siyuan/issues/5366
let hasEditor = targetWnd.children.find(item => { let hasEditor = targetWnd.children.find(item => {
if (item.model && item.model instanceof Editor && item.model.editor.protyle.block.rootID === options.rootID) { if (item.model && item.model instanceof Editor && item.model.editor.protyle.block.rootID === options.rootID) {
@ -157,7 +164,13 @@ const openFile = (options: IOpenFileOptions) => {
} else { } else {
wnd.split(direction).addTab(newTab(options)); wnd.split(direction).addTab(newTab(options));
} }
} else if (options.keepCursor && wnd.children[0].headElement) { wnd.showHeading();
return;
}
if (pdfIsLoading(wnd.element)) {
return;
}
if (options.keepCursor && wnd.children[0].headElement) {
const tab = newTab(options); const tab = newTab(options);
tab.headElement.setAttribute("keep-cursor", options.id); tab.headElement.setAttribute("keep-cursor", options.id);
wnd.addTab(tab, options.keepCursor); wnd.addTab(tab, options.keepCursor);

View file

@ -3,7 +3,7 @@ import {genUUID} from "../util/genID";
import { import {
getInstanceById, getInstanceById,
getWndByLayout, JSONToCenter, getWndByLayout, JSONToCenter,
newCenterEmptyTab, newCenterEmptyTab, pdfIsLoading,
resizeTabs, resizeTabs,
setPanelFocus, setPanelFocus,
switchWnd switchWnd
@ -100,7 +100,7 @@ export class Wnd {
} else if (target.classList.contains("item__close") && target.getAttribute("data-type") === "more") { } else if (target.classList.contains("item__close") && target.getAttribute("data-type") === "more") {
this.renderTabList(event); this.renderTabList(event);
break; break;
} else if (target.tagName === "LI" && target.getAttribute("data-id")) { } else if (target.tagName === "LI" && target.getAttribute("data-id") && !pdfIsLoading(this.element)) {
this.switchTab(target, true); this.switchTab(target, true);
break; break;
} }
@ -441,7 +441,7 @@ export class Wnd {
if (currentTab && target === currentTab.headElement) { if (currentTab && target === currentTab.headElement) {
if (currentTab.model instanceof Graph) { if (currentTab.model instanceof Graph) {
currentTab.model.onGraph(false); currentTab.model.onGraph(false);
} else if (currentTab.model instanceof Asset && currentTab.model.pdfObject) { } else if (currentTab.model instanceof Asset && currentTab.model.pdfObject && currentTab.model.pdfObject.pdfViewer) {
// https://github.com/siyuan-note/siyuan/issues/5655 // https://github.com/siyuan-note/siyuan/issues/5655
currentTab.model.pdfObject.pdfViewer.container.focus(); currentTab.model.pdfObject.pdfViewer.container.focus();
} }

View file

@ -28,6 +28,7 @@ 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} from "../util/functions"; import {getSearch, isWindow} from "../util/functions";
import {showMessage} from "../dialog/message";
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")) {
@ -579,6 +580,14 @@ export const copyTab = (tab: Tab) => {
}); });
}; };
export const pdfIsLoading = (element: HTMLElement) => {
const isLoading = element.querySelector('.layout-tab-container > [data-loading="true"]') ? true : false
if (isLoading) {
showMessage(window.siyuan.languages.pdfIsLoading);
}
return isLoading;
}
export const getInstanceById = (id: string, layout = window.siyuan.layout.centerLayout) => { export const getInstanceById = (id: string, layout = window.siyuan.layout.centerLayout) => {
const _getInstanceById = (item: Layout | Wnd, id: string) => { const _getInstanceById = (item: Layout | Wnd, id: string) => {
if (item.id === id) { if (item.id === id) {