not change url when tool options changes and tweak the source header in downloaded file
diff --git a/src/common/route.js b/src/common/route.js
index 1da66ec..ed36ee5f 100644
--- a/src/common/route.js
+++ b/src/common/route.js
@@ -1,9 +1,9 @@
-export function getURL(params) {
+export function getURL(params, raw) {
const url = new URL(location.href);
Object.entries(params).forEach(([k, v]) =>
v == null ? url.searchParams.delete(k) : url.searchParams.set(k, v)
);
- return url.toString();
+ return raw ? url : url.toString();
}
export function gotoURL(params, pushHistory) {
diff --git a/src/editor/Preview.vue b/src/editor/Preview.vue
index 889933f..2af8236 100644
--- a/src/editor/Preview.vue
+++ b/src/editor/Preview.vue
@@ -340,7 +340,8 @@
);
},
editLink() {
- return './editor.html' + location.search;
+ const url = this.getSharableURL(true);
+ return './editor.html' + url.search;
},
versionList() {
return this.nightly ? this.nightlyVersions : this.allEChartsVersions;
@@ -373,10 +374,7 @@
}
},
toolOptions: {
- handler(n) {
- this.refresh();
- gotoURL(n, true);
- },
+ handler: 'refresh',
deep: true
},
isNightlyVersion: {
@@ -406,7 +404,11 @@
}
},
download() {
- download(store.isSharedCode && this.$t('editor.share.hint'));
+ const url = this.getSharableURL(true);
+ const isShared = store.isSharedCode || url.searchParams.has('code');
+ const headers = [`\tTHIS EXAMPLE WAS DOWNLOADED FROM ${url.toString()}`];
+ isShared && headers.push('\t' + this.$t('editor.share.hint'));
+ download(headers.join('\n'));
},
screenshot() {
this.sandbox &&
@@ -426,12 +428,21 @@
showClose: true
});
},
- share() {
+ getSharableURL(raw) {
const params = {};
if (store.initialCode !== store.sourceCode) {
params.code = compressStr(store.sourceCode);
}
- const sharableURL = getURL(params);
+ return getURL(
+ {
+ ...this.toolOptions,
+ ...params
+ },
+ raw
+ );
+ },
+ share() {
+ const sharableURL = this.getSharableURL();
navigator.clipboard
.writeText(sharableURL)
.then(() => {
@@ -453,7 +464,12 @@
},
changeVersion() {
saveExampleCodeToLocal();
- setTimeout(() => gotoURL({ version: store.echartsVersion }));
+ setTimeout(() =>
+ gotoURL({
+ version: store.echartsVersion,
+ ...this.toolOptions
+ })
+ );
},
changeRandomSeed() {
updateRandomSeed();
diff --git a/src/editor/View.vue b/src/editor/View.vue
index 4d9d382..c0d98f8 100644
--- a/src/editor/View.vue
+++ b/src/editor/View.vue
@@ -14,7 +14,10 @@
mounted() {
loadExampleCode().then((code) => {
// set sourceCode here as there is no editor in view mode
- store.sourceCode = store.runCode = parseSourceCode(code);
+ store.sourceCode =
+ store.initialCode =
+ store.runCode =
+ parseSourceCode(code);
});
}
};
diff --git a/src/editor/downloadExample.js b/src/editor/downloadExample.js
index f33d12e..824326d 100644
--- a/src/editor/downloadExample.js
+++ b/src/editor/downloadExample.js
@@ -2,7 +2,7 @@
import { URL_PARAMS, SCRIPT_URLS } from '../common/config';
import { downloadBlob } from '../common/helper';
-export function download(shareHint) {
+export function download(sourceHeader) {
const hasRootPath = store.sourceCode.indexOf('ROOT_PATH') > -1;
const rootPathCode = hasRootPath ? `var ROOT_PATH = '${store.cdnRoot}';` : '';
const lang = store.locale && store.locale.indexOf('zh') > -1 ? 'zh-CN' : 'en';
@@ -18,7 +18,7 @@
);
const echarts4Dir = SCRIPT_URLS.echartsDir.replace('{{version}}', '4.9.0');
const code = `<!--
- ${shareHint || `THIS EXAMPLE WAS DOWNLOADED FROM ${window.location.href}`}
+${sourceHeader}
-->
<!DOCTYPE html>
<html lang="${lang}" style="height: 100%">