This is an automated email from the ASF dual-hosted git repository. wangzx pushed a commit to branch gh-pages in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
commit 2d3576ff8b1a5aecdb951ab8680647887c2eafc4 Author: plainheart <y...@all-my-life.cn> AuthorDate: Wed May 11 21:10:16 2022 +0800 not change url when tool options changes and tweak the source header in downloaded file --- src/common/route.js | 4 ++-- src/editor/Preview.vue | 34 +++++++++++++++++++++++++--------- src/editor/View.vue | 5 ++++- src/editor/downloadExample.js | 4 ++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/common/route.js b/src/common/route.js index 1da66ecb..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 889933f1..2af82368 100644 --- a/src/editor/Preview.vue +++ b/src/editor/Preview.vue @@ -340,7 +340,8 @@ export default { ); }, 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 @@ export default { } }, toolOptions: { - handler(n) { - this.refresh(); - gotoURL(n, true); - }, + handler: 'refresh', deep: true }, isNightlyVersion: { @@ -406,7 +404,11 @@ export default { } }, 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 @@ export default { 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 @@ export default { }, 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 4d9d3828..c0d98f8e 100644 --- a/src/editor/View.vue +++ b/src/editor/View.vue @@ -14,7 +14,10 @@ export default { 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 f33d12ec..824326d3 100644 --- a/src/editor/downloadExample.js +++ b/src/editor/downloadExample.js @@ -2,7 +2,7 @@ import { store } from '../common/store'; 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 @@ export function download(shareHint) { ); 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%"> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org