fix file state changing bug
This commit is contained in:
parent
57568f6504
commit
7e6bbb1fae
2 changed files with 17 additions and 5 deletions
|
@ -32,19 +32,30 @@ class PreviewFrame extends React.Component {
|
||||||
|
|
||||||
injectLocalFiles() {
|
injectLocalFiles() {
|
||||||
let htmlFile = this.props.htmlFile.content;
|
let htmlFile = this.props.htmlFile.content;
|
||||||
const jsFiles = this.props.jsFiles.map(jsFile => {
|
|
||||||
const jsFileStrings = jsFile.content.match(/(['"])((\\\1|.)*?)\1/gm);
|
// have to build the array manually because the spread operator is only
|
||||||
|
// one level down...
|
||||||
|
const jsFiles = [];
|
||||||
|
this.props.jsFiles.forEach(jsFile => {
|
||||||
|
const newJSFile = { ...jsFile };
|
||||||
|
const jsFileStrings = newJSFile.content.match(/(['"])((\\\1|.)*?)\1/gm);
|
||||||
jsFileStrings.forEach(jsFileString => {
|
jsFileStrings.forEach(jsFileString => {
|
||||||
if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp)('|")$/)) {
|
if (jsFileString.match(/^('|")(?!(http:\/\/|https:\/\/)).*\.(png|jpg|jpeg|gif|bmp)('|")$/)) {
|
||||||
const fileName = jsFileString.substr(1, jsFileString.length - 2);
|
const filePath = jsFileString.substr(1, jsFileString.length - 2);
|
||||||
|
let fileName = filePath;
|
||||||
|
if (fileName.match(/^\.\//)) {
|
||||||
|
fileName = fileName.substr(2, fileName.length - 1);
|
||||||
|
} else if (fileName.match(/^\//)) {
|
||||||
|
fileName = fileName.substr(1, fileName.length - 1);
|
||||||
|
}
|
||||||
this.props.files.forEach(file => {
|
this.props.files.forEach(file => {
|
||||||
if (file.name === fileName) {
|
if (file.name === fileName) {
|
||||||
jsFile.content = jsFile.content.replace(fileName, file.blobURL); // eslint-disable-line
|
newJSFile.content = newJSFile.content.replace(filePath, file.blobURL); // eslint-disable-line
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return jsFile;
|
jsFiles.push(newJSFile);
|
||||||
});
|
});
|
||||||
|
|
||||||
jsFiles.forEach(jsFile => {
|
jsFiles.forEach(jsFile => {
|
||||||
|
|
|
@ -82,5 +82,6 @@ export const getFile = (state, id) => state.filter(file => file.id === id)[0];
|
||||||
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0];
|
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0];
|
||||||
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/));
|
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/));
|
||||||
export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/));
|
export const getCSSFiles = (state) => state.filter(file => file.name.match(/.*\.css$/));
|
||||||
|
export const getLinkedFiles = (state) => state.filter(file => file.url);
|
||||||
|
|
||||||
export default files;
|
export default files;
|
||||||
|
|
Loading…
Reference in a new issue