Skip to content

Commit

Permalink
regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
blurymind committed Aug 31, 2024
1 parent eb1951c commit 2fc8161
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
49 changes: 22 additions & 27 deletions src/public/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,21 @@ export var Plugins = function (app) {
</script>
${data.html || data.body || ''}
${getStoryParserModuleCode(data.parser)}
${remoteModules.map(item => `<script src="${item}" id="${item}"></script>`).join("")}
${localModules.map(item => `<script id="${item.id}">${item.body}</script>`).join("")}
<script type="module">
(${data.script || ''})()
</script>
<script id="handle-fallback-message">
const logOfConsole = [];
const logOfErrors = [];
const onUpdateConsoleLogsInternal = () => {
${data.console === false && 'if(logOfErrors.length === 0)return;'}
window.top.dispatchEvent(
new CustomEvent(
"previewErrors",
{detail: {
errorText: logOfErrors.map(item=>item.arguments.join('')).join('')
}
}
)
)
const logMessage = document.querySelector('#logMessage');
logMessage.style.display = 'block'
const colors = {string: '#00ff00', number: 'red', boolean: '#00fff3', warning: '#ffff008a', log: '#33ff0054', error: 'red', info: '#002bff8a'}
Expand All @@ -423,14 +428,14 @@ export var Plugins = function (app) {
logMessage.scrollTop = logMessage.scrollHeight;
}
window.addEventListener("error", (e) => {
const errorMessage = document.querySelector('#errorMessage');
const errorText = e.message + "<br>Line: " + (e.lineno - 60 + 1 + ${data.scriptStartLn}) + "<br>Col: " + (e.colno - 4) + "<br> Please see console for more details..";
errorMessage.innerHTML = errorText;
errorMessage.style.display = 'block';
window.top.dispatchEvent(new CustomEvent("previewErrors", {detail: {errorText, e}}))
logOfConsole.push({type: 'error', arguments: [e.message]});
logOfErrors.push({type: 'error', arguments: [e.message]});
logOfConsole.push({type: 'error', arguments: [errorText]});
logOfErrors.push({type: 'error', arguments: [errorText]});
onUpdateConsoleLogsInternal();
});
window.addEventListener('unhandledrejection', e => {
console.log({e})
logOfErrors.push({type: 'error', arguments: [e.reason.stack]});
onUpdateConsoleLogsInternal();
});
const _log = console.log,
Expand Down Expand Up @@ -458,23 +463,13 @@ export var Plugins = function (app) {
return _info.apply(console, arguments);
};
</script>
${remoteModules.map(item => `<script src="${item}" id="${item}" crossorigin="anonymous"></script>`).join("")}
${localModules.map(item => `<script id="${item.id}" crossorigin="anonymous">${item.body}</script>`).join("")}
<script type="module">
(${data.script || ''})()
</script>
<div style="display:flex">
<div id="errorMessage" style="
position: absolute;
bottom: 3px;
right: 3px;
display: none;
color: yellow;
background: rgb(0 0 0 / 76%);
padding: 12px;
border-radius: 0.2rem;
font-family: 'Courier New', monospace;
max-height: 70%;
max-width: 40%;
overflow: auto;
flex: 1;
"></div>
<div id="logMessage" style="
position: absolute;
bottom: 3px;
Expand Down
46 changes: 25 additions & 21 deletions src/public/plugins/plugin-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export var PluginEditor = function ({

document.getElementById('plugin-output-downloader').style.display = mode === 'test' ? 'block' : 'none';
document.getElementById('plugin-output-linker').style.display = mode === 'test' ? 'block' : 'none';
document.getElementById('js-editor-errors').style.display = mode === 'commit' ? 'none' : 'block';

updateUrlParams('mode', mode);
this.onSetEditingFile();
Expand Down Expand Up @@ -309,7 +310,8 @@ export var PluginEditor = function ({
this.onErrorsInPreview = (errorsInPreview) => {
const errorText = errorsInPreview.detail.errorText;
document.querySelector('#js-editor-errors').innerHTML = errorText;
document.querySelector('#js-editor-errors').style.display = 'block';
document.querySelector('#js-editor-errors').style.display = errorText && this.mode !== 'commit' ? 'block' : 'none';
this.editor.find(errorText);
},
this.onOpenPluginEditor = async () => {
this.beautify = ace.require('ace/ext/beautify');
Expand Down Expand Up @@ -397,27 +399,27 @@ export var PluginEditor = function ({
html: `
<div style="overflow:hidden;">
<div id="js-editor-wrapper" style="position:relative">
<div id="js-editor" style="height: ${HEIGHT}; width: 100%;"></div>
<div id="js-editor-errors" style="
position: absolute;
bottom: 20px;
right: 20px;
display: none;
color: red;
background: rgba(0, 0, 0, 0.66);
padding: 6px;
border-radius: 0.2rem;
font-family: 'Courier New', monospace;
font-size: 0.7rem;
text-align: start;
max-height: 20%;
max-width: 80%;
overflow: auto;
">
error text dkjfghkdfjhgkdfhgkdfjghkdfjghkg
</div>
<div id="js-editor" style="height: ${HEIGHT}; width: 100%;"></div>
</div>
<div id="js-editor-errors" style="
position: absolute;
bottom: 20px;
right: 20px;
display: none;
color: red;
background: rgba(0, 0, 0, 0.66);
padding: 6px;
border-radius: 0.2rem;
font-family: 'Courier New', monospace;
font-size: 0.7rem;
text-align: start;
max-height: 20%;
max-width: 80%;
overflow: auto;
z-index: 9999;
">
error text dkjfghkdfjhgkdfhgkdfjghkdfjghkg
</div>
<div style="position: relative;">
<div id="diff-editor" class="diff-editor" style="height: ${HEIGHT}; width: 100%;"></div>
Expand Down Expand Up @@ -575,6 +577,8 @@ export var PluginEditor = function ({
this.onSetPluginEditMode(localVariables.pluginEditMode || this.mode, getGistPluginsFileUrl());
updateUrlParams('gistPlugins', getGistPluginsId());
});
} else {
this.onSetPluginEditMode(localVariables.pluginEditMode || this.mode, getGistPluginsFileUrl());
}
}, 400)
},
Expand Down

0 comments on commit 2fc8161

Please sign in to comment.