This is an automated email from the ASF dual-hosted git repository. ovilia pushed a commit to branch ssr in repository https://gitbox.apache.org/repos/asf/echarts.git
The following commit(s) were added to refs/heads/ssr by this push: new 6bca1329b chore(ssr): update building of ssr client 6bca1329b is described below commit 6bca1329b195b7851eb19ce1e43d866c0ba05a8f Author: Ovilia <zwl.s...@gmail.com> AuthorDate: Tue Jun 27 14:20:29 2023 +0800 chore(ssr): update building of ssr client --- .github/workflows/source-release.yml | 1 + build/build-ssr-client.js | 36 ------------ build/pre-publish.js | 2 +- ssr/client/dist/index.js | 109 +++++++++++++++++++++++++++++++++++ ssr/client/dist/index.js.map | 1 + ssr/client/src/index.ts | 4 +- test/lib/config.js | 2 +- test/ssr.html | 9 +-- 8 files changed, 120 insertions(+), 44 deletions(-) diff --git a/.github/workflows/source-release.yml b/.github/workflows/source-release.yml index 87b85d5cc..959bc99c6 100644 --- a/.github/workflows/source-release.yml +++ b/.github/workflows/source-release.yml @@ -87,6 +87,7 @@ jobs: index.d.ts src/ extension-src/ + ssr/client/src/ licenses/ theme/ build/ diff --git a/build/build-ssr-client.js b/build/build-ssr-client.js deleted file mode 100644 index 6f89a4432..000000000 --- a/build/build-ssr-client.js +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env node - -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - -const rollup = require('rollup'); -const chalk = require('chalk'); -const createSSRClient = require('./config').createSSRClient; - -async function run() { - const config = createSSRClient({ min: true }); - console.log(chalk.cyan.dim(`Bundling ${config.input}`)) - - console.time('rollup build ssr-client'); - const bundle = await rollup.rollup(config); - await bundle.write(config.output); - console.timeEnd('rollup build ssr-client'); -} - -run(); diff --git a/build/pre-publish.js b/build/pre-publish.js index 91914e576..6975c2744 100644 --- a/build/pre-publish.js +++ b/build/pre-publish.js @@ -249,7 +249,7 @@ async function tsCompile(compilerOptionsOverride, srcPathList) { && compilerOptionsOverride.rootDir && compilerOptionsOverride.outDir ); - console.log(compilerOptionsOverride, srcPathList) + let compilerOptions = { ...tsConfig.compilerOptions, ...compilerOptionsOverride, diff --git a/ssr/client/dist/index.js b/ssr/client/dist/index.js new file mode 100644 index 000000000..818242b77 --- /dev/null +++ b/ssr/client/dist/index.js @@ -0,0 +1,109 @@ + +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['echarts-ssr-client'] = {})); +}(this, (function (exports) { 'use strict'; + + /** + * AUTO-GENERATED FILE. DO NOT MODIFY. + */ + + /* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + function hydrate(dom, options) { + var svgRoot = dom.querySelector('svg'); + + if (!svgRoot) { + console.error('No SVG element found in the DOM.'); + return; + } + + var children = svgRoot.children; + + function getIndex(child, attr) { + var index = child.getAttribute(attr); + + if (index) { + return parseInt(index, 10); + } else { + return null; + } + } + + var events = options.on; + + if (events) { + var _loop_1 = function (eventName) { + if (typeof events[eventName] === 'function') { + var _loop_2 = function (i) { + var child = children[i]; + var type = child.getAttribute('ecmeta_ssr_type'); + var silent = child.getAttribute('ecmeta_silent') === 'true'; + + if (type && !silent) { + child.addEventListener(eventName, function (e) { + events[eventName]({ + type: eventName, + ssrType: type, + seriesIndex: getIndex(child, 'ecmeta_series_index'), + dataIndex: getIndex(child, 'ecmeta_data_index'), + event: e + }); + }); + } + }; + + for (var i = 0; i < children.length; i++) { + _loop_2(i); + } + } + }; + + for (var eventName in events) { + _loop_1(eventName); + } + } + } + + exports.hydrate = hydrate; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); +//# sourceMappingURL=index.js.map diff --git a/ssr/client/dist/index.js.map b/ssr/client/dist/index.js.map new file mode 100644 index 000000000..e4fabbce7 --- /dev/null +++ b/ssr/client/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../lib/index.js"],"sourcesContent":["\n/**\n * AUTO-GENERATED FILE. DO NOT MODIFY.\n */\n\n/*\n* Licensed to the Apache Software Foundation (ASF) under one\n* or more contributor license agreements. See the NOTICE file\n* distributed with this work for additional information\n* regarding copyright ownership. The ASF licenses this file\n* to you under the Apache License, Version 2.0 (the\n* \"License\"); you may not use this file except in comp [...] \ No newline at end of file diff --git a/ssr/client/src/index.ts b/ssr/client/src/index.ts index dabda9a96..d56a1e323 100644 --- a/ssr/client/src/index.ts +++ b/ssr/client/src/index.ts @@ -29,7 +29,7 @@ export interface ECSSRClientOptions { export type ECSSREvent = 'mouseover' | 'mouseout' | 'click'; -export function initEChartsSSRClient(dom: HTMLElement, options: ECSSRClientOptions) { +export function hydrate(dom: HTMLElement, options: ECSSRClientOptions) { const svgRoot = dom.querySelector('svg'); if (!svgRoot) { console.error('No SVG element found in the DOM.'); @@ -58,7 +58,7 @@ export function initEChartsSSRClient(dom: HTMLElement, options: ECSSRClientOptio const silent = child.getAttribute('ecmeta_silent') === 'true'; if (type && !silent) { child.addEventListener(eventName, e => { - events[eventName as ECSSREvent]({ + (events[eventName as ECSSREvent] as Function)({ type: eventName, ssrType: type, seriesIndex: getIndex(child, 'ecmeta_series_index'), diff --git a/test/lib/config.js b/test/lib/config.js index 69bda4ae8..462b31420 100644 --- a/test/lib/config.js +++ b/test/lib/config.js @@ -82,7 +82,7 @@ 'map': 'data/map', 'i18n': '../i18n', 'extension': '../dist/extension', - 'ssrClient': '../ssr-client/index' + 'ssrClient': '../ssr/client/dist/index.js' } }); } diff --git a/test/ssr.html b/test/ssr.html index e582f9385..7516f7cbc 100644 --- a/test/ssr.html +++ b/test/ssr.html @@ -63,7 +63,8 @@ under the License. <div id="big-data"></div> <script> - require(['echarts', 'ssrClient'], function (echarts) { + require(['echarts', 'ssrClient'], function (echarts, ssrClient) { + console.log(ssrClient) // During transition const serverChart = echarts.init(null, null, { width: 500, @@ -114,10 +115,10 @@ under the License. function update() { main.innerHTML = serverChart.renderToSVGString(); - const clientChart = ssrClient(main, { + const clientChart = ssrClient.hydrate(main, { on: { mouseover: (params) => { - console.log(params); + // console.log(params); }, mouseout: (params) => { // console.log(params); @@ -154,7 +155,7 @@ under the License. </script> <script> - require(['echarts'/*, 'map/js/china' */], function (echarts) { + require(['echarts', 'ssrClient'], function (echarts, ssrClient) { // During transition const serverChart = echarts.init(null, null, { width: 500, --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org