mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
BREAKING: The new project layout might break in some tooling setups. We've added an exports field to `package.json` to specify where statements like `import ... from 'docsify'` will import from, and left the `main` and `unpkg` fields as-is for backwards compatibility with the global <script> import method. Most people who use a non-module `<script>` tag to import Docsify will not notice a difference. Anyone else who is importing Docsify into a specilized build setup using `import` statements has a chance of being broken, so we've marked this as BREAKING.
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
import { Router } from './router/index.js';
|
|
import { Render } from './render/index.js';
|
|
import { Fetch } from './fetch/index.js';
|
|
import { Events } from './event/index.js';
|
|
import { VirtualRoutes } from './virtual-routes/index.js';
|
|
import initGlobalAPI from './global-api.js';
|
|
|
|
import config from './config.js';
|
|
import { isFn } from './util/core.js';
|
|
import { Lifecycle } from './init/lifecycle.js';
|
|
|
|
/** @typedef {new (...args: any[]) => any} Constructor */
|
|
|
|
// eslint-disable-next-line new-cap
|
|
export class Docsify extends Fetch(
|
|
// eslint-disable-next-line new-cap
|
|
Events(Render(VirtualRoutes(Router(Lifecycle(Object)))))
|
|
) {
|
|
constructor() {
|
|
super();
|
|
|
|
this.config = config(this);
|
|
|
|
this.initLifecycle(); // Init hooks
|
|
this.initPlugin(); // Install plugins
|
|
this.callHook('init');
|
|
this.initRouter(); // Add router
|
|
this.initRender(); // Render base DOM
|
|
this.initEvent(); // Bind events
|
|
this.initFetch(); // Fetch data
|
|
this.callHook('mounted');
|
|
}
|
|
|
|
initPlugin() {
|
|
[].concat(this.config.plugins).forEach(fn => {
|
|
try {
|
|
isFn(fn) && fn(this._lifecycle, this);
|
|
} catch (err) {
|
|
if (this.config.catchPluginErrors) {
|
|
const errTitle = 'Docsify plugin error';
|
|
console.error(errTitle, err);
|
|
} else {
|
|
throw err;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Global API
|
|
*/
|
|
initGlobalAPI();
|