mirror of https://github.com/fantasticit/think.git
tiptap: update preload
This commit is contained in:
parent
e382686b3b
commit
4966dfc509
|
@ -10,7 +10,7 @@ import App from 'next/app';
|
|||
import Head from 'next/head';
|
||||
import React from 'react';
|
||||
import { Hydrate, QueryClient, QueryClientProvider } from 'react-query';
|
||||
import { preload } from 'tiptap/preload';
|
||||
import { preloadTiptapResources } from 'tiptap/preload';
|
||||
|
||||
class MyApp extends App<{ isMobile: boolean }> {
|
||||
state = {
|
||||
|
@ -45,7 +45,7 @@ class MyApp extends App<{ isMobile: boolean }> {
|
|||
// @ts-ignore
|
||||
import('requestidlecallback-polyfill'),
|
||||
]).then(() => {
|
||||
preload();
|
||||
preloadTiptapResources();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,13 @@
|
|||
import { DOCUMENT_COVERS } from '@think/constants';
|
||||
|
||||
const preloadImage = (url) => {
|
||||
// @ts-ignore
|
||||
window.requestIdleCallback =
|
||||
window.requestIdleCallback ||
|
||||
function (cb) {
|
||||
const start = Date.now();
|
||||
return setTimeout(function () {
|
||||
cb({
|
||||
didTimeout: false,
|
||||
timeRemaining: function () {
|
||||
return Math.max(0, 50 - (Date.now() - start));
|
||||
},
|
||||
});
|
||||
}, 1);
|
||||
};
|
||||
|
||||
window.cancelIdleCallback =
|
||||
window.cancelIdleCallback ||
|
||||
function (id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
|
||||
requestIdleCallback(() => {
|
||||
const image = document.createElement('img');
|
||||
image.src = url;
|
||||
});
|
||||
};
|
||||
|
||||
export function preload() {
|
||||
export function preloadTiptapResources() {
|
||||
if (typeof window === 'undefined') return;
|
||||
DOCUMENT_COVERS.forEach(preloadImage);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue