You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by wa...@apache.org on 2022/08/18 09:50:24 UTC

[echarts] branch feat-extension-type created (now 5c6290646)

This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a change to branch feat-extension-type
in repository https://gitbox.apache.org/repos/asf/echarts.git


      at 5c6290646 feat(type): export helpful types and APIs for extension developers.

This branch includes the following new commits:

     new 5c6290646 feat(type): export helpful types and APIs for extension developers.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org


[echarts] 01/01: feat(type): export helpful types and APIs for extension developers.

Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch feat-extension-type
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 5c6290646f62bcae15779b1755a925203512ff05
Author: plainheart <yh...@all-my-life.cn>
AuthorDate: Thu Aug 18 15:05:34 2022 +0800

    feat(type): export helpful types and APIs for extension developers.
---
 .gitignore                             |  2 ++
 build/pre-publish.js                   | 10 +++---
 build/template/extensionHelper.d.ts    | 20 ++++++++++++
 build/template/extensionHelper.js      | 20 ++++++++++++
 src/export/api.ts                      | 58 ++--------------------------------
 src/export/core.ts                     |  2 +-
 src/export/{api.ts => extensionAPI.ts} | 36 ++-------------------
 src/export/extensionHelper.ts          | 22 +++++++++++++
 src/extension.ts                       |  2 +-
 test/types/importPartial.ts            | 18 +++++++++--
 10 files changed, 91 insertions(+), 99 deletions(-)

diff --git a/.gitignore b/.gitignore
index ba7541926..a974b3ad8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -205,4 +205,6 @@ todo
 /renderers.d.ts
 /features.js
 /features.d.ts
+/extensionHelper.js
+/extensionHelper.d.ts
 *.tgz
diff --git a/build/pre-publish.js b/build/pre-publish.js
index 75d7c771a..18eff2693 100644
--- a/build/pre-publish.js
+++ b/build/pre-publish.js
@@ -169,9 +169,9 @@ module.exports = async function () {
         process.stdout.write(chalk.green.dim(` done \n`));
     }
 
-    process.stdout.write(chalk.green.dim(`Generating entries ...`));
+    process.stdout.write(chalk.green.dim(`Generating entries ...\n`));
     generateEntries();
-    process.stdout.write(chalk.green.dim(`Bundling DTS ...`));
+    process.stdout.write(chalk.green.dim(`Bundling DTS ...\n`));
     await bundleDTS();
 
     console.log(chalk.green.dim('All done.'));
@@ -372,7 +372,7 @@ async function bundleDTS() {
 
     // Bundle chunks.
     const parts = [
-        'core', 'charts', 'components', 'renderers', 'option', 'features'
+        'core', 'charts', 'components', 'renderers', 'option', 'features', 'extensionHelper'
     ];
     const inputs = {};
     parts.forEach(partName => {
@@ -383,7 +383,7 @@ async function bundleDTS() {
         input: inputs,
         ...commonConfig
     });
-    let idx = 1;
+
     await bundle.write({
         dir: outDir,
         minifyInternalExports: false,
@@ -414,7 +414,7 @@ function readTSConfig() {
 
 
 function generateEntries() {
-    ['charts', 'components', 'renderers', 'core', 'features'].forEach(entryName => {
+    ['charts', 'components', 'renderers', 'core', 'features', 'extensionHelper'].forEach(entryName => {
         if (entryName !== 'option') {
             const jsCode = fs.readFileSync(nodePath.join(__dirname, `template/${entryName}.js`), 'utf-8');
             fs.writeFileSync(nodePath.join(__dirname, `../${entryName}.js`), jsCode, 'utf-8');
diff --git a/build/template/extensionHelper.d.ts b/build/template/extensionHelper.d.ts
new file mode 100644
index 000000000..a40a51cea
--- /dev/null
+++ b/build/template/extensionHelper.d.ts
@@ -0,0 +1,20 @@
+/*
+* 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.
+*/
+
+export * from './types/dist/extensionHelper';
\ No newline at end of file
diff --git a/build/template/extensionHelper.js b/build/template/extensionHelper.js
new file mode 100644
index 000000000..f2b9fc387
--- /dev/null
+++ b/build/template/extensionHelper.js
@@ -0,0 +1,20 @@
+/*
+* 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.
+*/
+
+export * from './lib/export/extensionHelper';
\ No newline at end of file
diff --git a/src/export/api.ts b/src/export/api.ts
index 4b777a237..6693384db 100644
--- a/src/export/api.ts
+++ b/src/export/api.ts
@@ -17,15 +17,6 @@
 * under the License.
 */
 
-// These APIs are for more advanced usages
-// For example extend charts and components, creating graphic elements, formatting.
-import ComponentModel, { ComponentModelConstructor } from '../model/Component';
-import ComponentView, { ComponentViewConstructor } from '../view/Component';
-import SeriesModel, { SeriesModelConstructor } from '../model/Series';
-import ChartView, { ChartViewConstructor } from '../view/Chart';
-
-import SeriesData from '../data/SeriesData';
-
 // Provide utilities API in echarts. It will be in echarts namespace.
 // Like echarts.util, echarts.graphic
 export * as zrender from 'zrender/src/zrender';
@@ -55,50 +46,5 @@ export * as util from './api/util';
 
 export {default as env} from 'zrender/src/core/env';
 
-//////////////// Export for Exension Usage ////////////////
-// export {SeriesData};
-export {SeriesData as List};    // TODO: Compatitable with exists echarts-gl code
-export {default as Model} from '../model/Model';
-export {default as Axis} from '../coord/Axis';
-
-export {
-    ComponentModel,
-    ComponentView,
-    SeriesModel,
-    ChartView
-};
-
-// Only for GL
-export {brushSingle as innerDrawElementOnCanvas} from 'zrender/src/canvas/graphic';
-
-
-//////////////// Deprecated Extension Methods ////////////////
-
-// Should use `ComponentModel.extend` or `class XXXX extend ComponentModel` to create class.
-// Then use `registerComponentModel` in `install` parameter when `use` this extension. For example:
-// class Bar3DModel extends ComponentModel {}
-// export function install(registers) { regsiters.registerComponentModel(Bar3DModel); }
-// echarts.use(install);
-export function extendComponentModel(proto: object): ComponentModel {
-    const Model = (ComponentModel as ComponentModelConstructor).extend(proto) as any;
-    ComponentModel.registerClass(Model);
-    return Model;
-}
-
-export function extendComponentView(proto: object): ChartView {
-    const View = (ComponentView as ComponentViewConstructor).extend(proto) as any;
-    ComponentView.registerClass(View);
-    return View;
-}
-
-export function extendSeriesModel(proto: object): SeriesModel {
-    const Model = (SeriesModel as SeriesModelConstructor).extend(proto) as any;
-    SeriesModel.registerClass(Model);
-    return Model;
-}
-
-export function extendChartView(proto: object): ChartView {
-    const View = (ChartView as ChartViewConstructor).extend(proto) as any;
-    ChartView.registerClass(View);
-    return View;
-}
+//////////////// Extension APIs /////////////////////
+export * from './extensionAPI';
diff --git a/src/export/core.ts b/src/export/core.ts
index d17b784b0..655bbf1b8 100644
--- a/src/export/core.ts
+++ b/src/export/core.ts
@@ -114,4 +114,4 @@ export type ComposeOption<OptionUnion extends ComponentOption> =
     ComposeUnitOption<OptionUnion> & {
         baseOption?: ComposeUnitOption<OptionUnion>
         options?: ComposeUnitOption<OptionUnion>[]
-    };
\ No newline at end of file
+    };
diff --git a/src/export/api.ts b/src/export/extensionAPI.ts
similarity index 70%
copy from src/export/api.ts
copy to src/export/extensionAPI.ts
index 4b777a237..7b602d3b3 100644
--- a/src/export/api.ts
+++ b/src/export/extensionAPI.ts
@@ -26,38 +26,7 @@ import ChartView, { ChartViewConstructor } from '../view/Chart';
 
 import SeriesData from '../data/SeriesData';
 
-// Provide utilities API in echarts. It will be in echarts namespace.
-// Like echarts.util, echarts.graphic
-export * as zrender from 'zrender/src/zrender';
-
-export * as matrix from 'zrender/src/core/matrix';
-export * as vector from 'zrender/src/core/vector';
-export * as zrUtil from 'zrender/src/core/util';
-export * as color from 'zrender/src/tool/color';
-export {throttle} from '../util/throttle';
-export * as helper from './api/helper';
-
-export {use} from '../extension';
-
-export {setPlatformAPI} from 'zrender/src/core/platform';
-
-//////////////// Helper Methods /////////////////////
-export {default as parseGeoJSON} from '../coord/geo/parseGeoJson';
-export {default as parseGeoJson} from '../coord/geo/parseGeoJson';
-
-export * as number from './api/number';
-export * as time from './api/time';
-export * as graphic from './api/graphic';
-
-export * as format from './api/format';
-
-export * as util from './api/util';
-
-export {default as env} from 'zrender/src/core/env';
-
-//////////////// Export for Exension Usage ////////////////
-// export {SeriesData};
-export {SeriesData as List};    // TODO: Compatitable with exists echarts-gl code
+export {SeriesData as List};    // TODO: Compatible with exists echarts-gl code
 export {default as Model} from '../model/Model';
 export {default as Axis} from '../coord/Axis';
 
@@ -71,7 +40,6 @@ export {
 // Only for GL
 export {brushSingle as innerDrawElementOnCanvas} from 'zrender/src/canvas/graphic';
 
-
 //////////////// Deprecated Extension Methods ////////////////
 
 // Should use `ComponentModel.extend` or `class XXXX extend ComponentModel` to create class.
@@ -101,4 +69,4 @@ export function extendChartView(proto: object): ChartView {
     const View = (ChartView as ChartViewConstructor).extend(proto) as any;
     ChartView.registerClass(View);
     return View;
-}
+}
\ No newline at end of file
diff --git a/src/export/extensionHelper.ts b/src/export/extensionHelper.ts
new file mode 100644
index 000000000..ea1748472
--- /dev/null
+++ b/src/export/extensionHelper.ts
@@ -0,0 +1,22 @@
+/*
+* 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.
+*/
+
+// export helpful types and APIs for extension developers
+export * from '../extension';
+export * from './extensionAPI';
\ No newline at end of file
diff --git a/src/extension.ts b/src/extension.ts
index a04ef54e9..f90dc6084 100644
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -119,5 +119,5 @@ export function use(
 
 // A simpler use type for exporting to reduce exported inner modules.
 export type EChartsExtensionInstallerSimple = (registers: any) => void;
-type SimpleEChartsExtensionType = EChartsExtensionInstallerSimple | { install: EChartsExtensionInstallerSimple };
+export type SimpleEChartsExtensionType = EChartsExtensionInstallerSimple | { install: EChartsExtensionInstallerSimple };
 export declare function useSimple(ext: SimpleEChartsExtensionType | (SimpleEChartsExtensionType)[]): void;
diff --git a/test/types/importPartial.ts b/test/types/importPartial.ts
index c4eb8c7dd..92e1bcec4 100644
--- a/test/types/importPartial.ts
+++ b/test/types/importPartial.ts
@@ -34,8 +34,22 @@ import {
 import {
     CanvasRenderer
 } from '../../renderers';
+import { EChartsExtension, EChartsExtensionInstaller } from '../../extensionHelper';
 
-use([BarChart, LineChart, GridComponent, DataZoomComponent, CanvasRenderer]);
+const customExtension: EChartsExtension = {
+    install(registers) {}
+}
+const customExtensionInstaller: EChartsExtensionInstaller = (registers)  => {}
+
+use([
+    BarChart,
+    LineChart,
+    GridComponent,
+    DataZoomComponent,
+    CanvasRenderer,
+    customExtension,
+    customExtensionInstaller
+]);
 
 type Option = ComposeOption<
     GridComponentOption | DataZoomComponentOption
@@ -61,4 +75,4 @@ const dom = document.createElement('div');
 dom.className = 'chart';
 
 const chart = init(dom);
-chart.setOption(option);
\ No newline at end of file
+chart.setOption(option);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org