mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🚨
This commit is contained in:
parent
6e864a2718
commit
9d94821c62
5 changed files with 13 additions and 17 deletions
|
|
@ -10,27 +10,27 @@ const getObject = (key: string) => {
|
|||
};
|
||||
// @ts-ignore
|
||||
return api[key];
|
||||
}
|
||||
};
|
||||
|
||||
const runCode = (code: string, sourceURL: string) => {
|
||||
return window.eval("(function anonymous(require, module){".concat(code, "\n})\n//# sourceURL=").concat(sourceURL, "\n"))
|
||||
}
|
||||
return window.eval("(function anonymous(require, module){".concat(code, "\n})\n//# sourceURL=").concat(sourceURL, "\n"));
|
||||
};
|
||||
|
||||
export const loadPlugins = (app: App) => {
|
||||
fetchPost("/api/petal/loadPetals", {}, response => {
|
||||
let css = "";
|
||||
response.data.forEach((item: { id: string, name: string, jsCode: string, cssCode: string, lang: IObject }) => {
|
||||
const moduleObj = {}
|
||||
const execResult = runCode(item.jsCode, "plugin:" + encodeURIComponent(item.id))
|
||||
const moduleObj = {};
|
||||
const execResult = runCode(item.jsCode, "plugin:" + encodeURIComponent(item.id));
|
||||
execResult(getObject, moduleObj);
|
||||
// @ts-ignore
|
||||
const plugin: Plugin = new moduleObj.exports.default({app, id: item.id, lang: item.lang})
|
||||
const plugin: Plugin = new moduleObj.exports.default({app, id: item.id, lang: item.lang});
|
||||
app.plugins.push(plugin);
|
||||
plugin.onload();
|
||||
css += item.cssCode + "\n";
|
||||
})
|
||||
});
|
||||
const styleElement = document.createElement("style");
|
||||
styleElement.textContent = css;
|
||||
document.head.append(styleElement);
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue