mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-29 09:40:10 +02:00
add query param code read mode
This commit is contained in:
@@ -82,6 +82,8 @@ const version = '5.0.3';
|
|||||||
|
|
||||||
// Read forced settings as query parameters
|
// Read forced settings as query parameters
|
||||||
window.forcedSettings = {};
|
window.forcedSettings = {};
|
||||||
|
window.codeHtml = '';
|
||||||
|
window.codeCss = '';
|
||||||
if (location.search) {
|
if (location.search) {
|
||||||
let match = location.search.replace(/^\?/, '').match(/settings=([^=]*)/);
|
let match = location.search.replace(/^\?/, '').match(/settings=([^=]*)/);
|
||||||
if (match) {
|
if (match) {
|
||||||
@@ -93,6 +95,14 @@ if (location.search) {
|
|||||||
window.forcedSettings[pair[0]] = pair[1];
|
window.forcedSettings[pair[0]] = pair[1];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
window.codeHtml = params.get('html')
|
||||||
|
? decodeURIComponent(params.get('html'))
|
||||||
|
: '';
|
||||||
|
window.codeCss = params.get('css')
|
||||||
|
? decodeURIComponent(params.get('css'))
|
||||||
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
@@ -121,7 +131,9 @@ export default class App extends Component {
|
|||||||
prefs: {},
|
prefs: {},
|
||||||
currentItem: {
|
currentItem: {
|
||||||
title: '',
|
title: '',
|
||||||
externalLibs: { js: '', css: '' }
|
externalLibs: { js: '', css: '' },
|
||||||
|
html: window.codeHtml,
|
||||||
|
css: window.codeCss
|
||||||
},
|
},
|
||||||
catalogs: {}
|
catalogs: {}
|
||||||
};
|
};
|
||||||
@@ -219,11 +231,16 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get synced `preserveLastCode` setting to get back last code (or not).
|
// Get synced `preserveLastCode` setting to get back last code (or not).
|
||||||
db.getSettings(this.defaultSettings).then(result => {
|
db.getSettings(this.defaultSettings).then(result => {
|
||||||
if (result.preserveLastCode && lastCode) {
|
if (window.codeHtml || window.codeCss) {
|
||||||
|
log('Load item from query params', lastCode);
|
||||||
|
this.setCurrentItem(this.state.currentItem).then(() => {
|
||||||
|
this.refreshEditor();
|
||||||
|
});
|
||||||
|
} else if (result.preserveLastCode && lastCode) {
|
||||||
this.setState({ unsavedEditCount: 0 });
|
this.setState({ unsavedEditCount: 0 });
|
||||||
|
|
||||||
log('Load last unsaved item', lastCode);
|
log('Load last unsaved item', lastCode);
|
||||||
this.setCurrentItem(lastCode).then(() => this.refreshEditor());
|
this.setCurrentItem(lastCode).then(() => this.refreshEditor());
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user