mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-06 10:44:33 +08:00
Updated markdown preview to update on diff-basis
Uses vdom system to diff and update the current markdown preview view instead of requiring a full HTML replace change. This should provide better performance, expecially where dynamically loaded content such as iframes were in use. Closes #3454
This commit is contained in:
31
resources/js/services/vdom.js
Normal file
31
resources/js/services/vdom.js
Normal file
@ -0,0 +1,31 @@
|
||||
import {
|
||||
init,
|
||||
attributesModule,
|
||||
toVNode
|
||||
} from "snabbdom";
|
||||
|
||||
let patcher;
|
||||
|
||||
/**
|
||||
* @returns {Function}
|
||||
*/
|
||||
function getPatcher() {
|
||||
if (patcher) return patcher;
|
||||
|
||||
|
||||
patcher = init([
|
||||
attributesModule,
|
||||
]);
|
||||
|
||||
return patcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Element} domTarget
|
||||
* @param {String} html
|
||||
*/
|
||||
export function patchDomFromHtmlString(domTarget, html) {
|
||||
const contentDom = document.createElement('div');
|
||||
contentDom.innerHTML = html;
|
||||
getPatcher()(toVNode(domTarget), toVNode(contentDom));
|
||||
}
|
Reference in New Issue
Block a user