@tellplot/vue 0.0.0-bootstrap.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TellPlot contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @tellplot/vue
2
+
3
+ TellPlot 的 Vue 3 薄适配器,支持 `v-model:view`。
4
+
5
+ 在已有 Vue 3.5 项目中安装:
6
+
7
+ ```bash
8
+ pnpm add @tellplot/core @tellplot/vue @antv/g2@5.4.8
9
+ ```
10
+
11
+ ```vue
12
+ <script setup lang="ts">
13
+ import { ChartEditor, type ChartConfig } from '@tellplot/vue';
14
+ import '@tellplot/vue/styles.css';
15
+
16
+ const config = {
17
+ type: 'column',
18
+ data: {
19
+ schemaVersion: '2.0.0',
20
+ dataKind: 'categorical',
21
+ datasetId: 'revenue-by-region',
22
+ items: [
23
+ { id: 'east', label: 'East', amount: 128 },
24
+ { id: 'west', label: 'West', amount: 96 },
25
+ ],
26
+ },
27
+ } as const satisfies ChartConfig;
28
+ </script>
29
+
30
+ <template>
31
+ <ChartEditor :config="config" />
32
+ </template>
33
+ ```
34
+
35
+ 不传 `view` 时组件管理编辑状态;受控接入使用 `v-model:view`,也可以用 `default-view` 指定非受控初值。
36
+ 组件 expose `focus`、`getView` 和 `exportImage`,卸载时自动销毁 imperative instance。
37
+
38
+ `render-error` 在图表渲染失败时发送稳定 issue,并在恢复成功后发送 `null`。
39
+
40
+ 组件只映射 `@tellplot/editor` 生命周期;编辑状态、G2 和 UI 不在本包重复实现。完整 emits、状态和错误合同见
41
+ [入门](https://github.com/iiwish/tellplot/blob/main/docs/getting-started.md)与
42
+ [公共 API](https://github.com/iiwish/tellplot/blob/main/docs/api.md)。License: MIT。
package/dist/index.cjs ADDED
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ var editor = require('@tellplot/editor');
5
+
6
+ // src/index.ts
7
+ var ChartEditorImplementation = vue.defineComponent({
8
+ name: "TellPlotChartEditor",
9
+ inheritAttrs: false,
10
+ props: {
11
+ config: { type: Object, required: true },
12
+ view: { type: Object, required: false },
13
+ defaultView: { type: Object, required: false }
14
+ },
15
+ emits: {
16
+ "update:view": (view) => typeof view === "object",
17
+ viewChange: (view, event) => typeof view === "object" && typeof event === "object",
18
+ command: (event) => typeof event === "object",
19
+ commandRejected: (error) => typeof error === "object",
20
+ configRejected: (issues) => Array.isArray(issues),
21
+ selectionChange: (selection) => selection === null || typeof selection === "object",
22
+ renderError: (issue) => issue === null || typeof issue === "object"
23
+ },
24
+ setup(props, { attrs, emit, expose }) {
25
+ const host = vue.ref(null);
26
+ let instance = null;
27
+ const toOptions = () => ({
28
+ config: props.config,
29
+ ...props.view === void 0 ? {} : { view: props.view },
30
+ ...props.defaultView === void 0 ? {} : { defaultView: props.defaultView },
31
+ onViewChange: (view, event) => {
32
+ emit("update:view", view);
33
+ emit("viewChange", view, event);
34
+ },
35
+ onCommand: (event) => emit("command", event),
36
+ onCommandRejected: (error) => emit("commandRejected", error),
37
+ onConfigRejected: (issues) => emit("configRejected", issues),
38
+ onSelectionChange: (selection) => emit("selectionChange", selection),
39
+ onRenderError: (issue) => emit("renderError", issue)
40
+ });
41
+ const exposed = {
42
+ focus: () => instance?.focus(),
43
+ getView: () => {
44
+ if (instance === null) {
45
+ throw new Error("TellPlot Vue editor is not mounted.");
46
+ }
47
+ return instance.getView();
48
+ },
49
+ exportImage: (options) => instance === null ? Promise.reject(new Error("TellPlot Vue editor is not mounted.")) : instance.exportImage(options)
50
+ };
51
+ expose(exposed);
52
+ vue.onMounted(() => {
53
+ if (host.value !== null) {
54
+ instance = editor.createEditor(host.value, toOptions());
55
+ }
56
+ });
57
+ vue.watch(
58
+ () => [props.config, props.view, props.defaultView],
59
+ () => instance?.update(toOptions())
60
+ );
61
+ vue.onBeforeUnmount(() => {
62
+ instance?.destroy();
63
+ instance = null;
64
+ });
65
+ return () => vue.h("div", {
66
+ ...attrs,
67
+ ref: host,
68
+ class: ["tellplot-vue-host", attrs["class"]]
69
+ });
70
+ }
71
+ });
72
+ var ChartEditor = ChartEditorImplementation;
73
+
74
+ exports.ChartEditor = ChartEditor;
75
+ //# sourceMappingURL=index.cjs.map
76
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["defineComponent","ref","onMounted","createEditor","watch","onBeforeUnmount","h"],"mappings":";;;;;;AAuBA,IAAM,4BAA4BA,mBAAA,CAAgB;AAAA,EAChD,IAAA,EAAM,qBAAA;AAAA,EACN,YAAA,EAAc,KAAA;AAAA,EACd,KAAA,EAAO;AAAA,IACL,MAAA,EAAQ,EAAE,IAAA,EAAM,MAAA,EAAiC,UAAU,IAAA,EAAK;AAAA,IAChE,IAAA,EAAM,EAAE,IAAA,E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A,EAAM,MAAM,WAAW,CAAA;AAAA,MAClD,MAAM,QAAA,EAAU,MAAA,CAAO,SAAA,EAAW;AAAA,KACpC;AACA,IAAAC,mBAAA,CAAgB,MAAM;AACpB,MAAA,QAAA,EAAU,OAAA,EAAQ;AAClB,MAAA,QAAA,GAAW,IAAA;AAAA,IACb,CAAC,CAAA;AAED,IAAA,OAAO,MACLC,MAAE,KAAA,EAAO;AAAA,MACP,GAAG,KAAA;AAAA,MACH,GAAA,EAAK,IAAA;AAAA,MACL,KAAA,EAAO,CAAC,mBAAA,EAAqB,KAAA,CAAM,OAAO,CAAC;AAAA,KAC5C,CAAA;AAAA,EACL;AACF,CAAC,CAAA;AAOM,IAAM,WAAA,GAAc","file":"index.cjs","sourcesContent":["import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch, type PropType } from 'vue';\nimport {\n createEditor,\n type ChartConfig,\n type ChartRenderIssue,\n type CommandError,\n type CommandEvent,\n type EditorInstance,\n type EditorOptions,\n type ExportOptions,\n type ExportResult,\n type SelectionState,\n type ValidationIssue,\n type ViewSpec,\n} from '@tellplot/editor';\n\nexport interface ChartEditorExposed {\n focus(): void;\n getView(): ViewSpec;\n exportImage(options: ExportOptions): Promise<ExportResult>;\n}\n\n/** Vue lifecycle adapter with `v-model:view`; the imperative editor remains the only runtime. */\nconst ChartEditorImplementation = defineComponent({\n name: 'TellPlotChartEditor',\n inheritAttrs: false,\n props: {\n config: { type: Object as PropType<ChartConfig>, required: true },\n view: { type: Object as PropType<ViewSpec>, required: false },\n defaultView: { type: Object as PropType<ViewSpec>, required: false },\n },\n emits: {\n 'update:view': (view: ViewSpec): boolean => typeof view === 'object',\n viewChange: (view: ViewSpec, event: CommandEvent): boolean =>\n typeof view === 'object' && typeof event === 'object',\n command: (event: CommandEvent): boolean => typeof event === 'object',\n commandRejected: (error: CommandError): boolean => typeof error === 'object',\n configRejected: (issues: readonly ValidationIssue[]): boolean => Array.isArray(issues),\n selectionChange: (selection: SelectionState | null): boolean =>\n selection === null || typeof selection === 'object',\n renderError: (issue: ChartRenderIssue | null): boolean =>\n issue === null || typeof issue === 'object',\n },\n setup(props, { attrs, emit, expose }) {\n const host = ref<HTMLElement | null>(null);\n let instance: EditorInstance | null = null;\n\n const toOptions = (): EditorOptions => ({\n config: props.config,\n ...(props.view === undefined ? {} : { view: props.view }),\n ...(props.defaultView === undefined ? {} : { defaultView: props.defaultView }),\n onViewChange: (view, event) => {\n emit('update:view', view);\n emit('viewChange', view, event);\n },\n onCommand: event => emit('command', event),\n onCommandRejected: error => emit('commandRejected', error),\n onConfigRejected: issues => emit('configRejected', issues),\n onSelectionChange: selection => emit('selectionChange', selection),\n onRenderError: issue => emit('renderError', issue),\n });\n\n const exposed: ChartEditorExposed = {\n focus: () => instance?.focus(),\n getView: () => {\n if (instance === null) {\n throw new Error('TellPlot Vue editor is not mounted.');\n }\n return instance.getView();\n },\n exportImage: options =>\n instance === null\n ? Promise.reject(new Error('TellPlot Vue editor is not mounted.'))\n : instance.exportImage(options),\n };\n expose(exposed);\n\n onMounted(() => {\n if (host.value !== null) {\n instance = createEditor(host.value, toOptions());\n }\n });\n watch(\n () => [props.config, props.view, props.defaultView] as const,\n () => instance?.update(toOptions()),\n );\n onBeforeUnmount(() => {\n instance?.destroy();\n instance = null;\n });\n\n return () =>\n h('div', {\n ...attrs,\n ref: host,\n class: ['tellplot-vue-host', attrs['class']],\n });\n },\n});\n\ntype ChartEditorPublicInstance = InstanceType<typeof ChartEditorImplementation> &\n ChartEditorExposed;\n\ntype ChartEditorConstructor = new () => ChartEditorPublicInstance;\n\nexport const ChartEditor = ChartEditorImplementation as typeof ChartEditorImplementation &\n ChartEditorConstructor;\n\nexport type {\n ChartConfig,\n ChartRenderIssue,\n CommandError,\n CommandEvent,\n ExportOptions,\n ExportResult,\n SelectionState,\n ValidationIssue,\n ViewSpec,\n} from '@tellplot/editor';\n"]}
@@ -0,0 +1,61 @@
1
+ import * as vue from 'vue';
2
+ import { PropType } from 'vue';
3
+ import { ChartConfig, ViewSpec, CommandEvent, CommandError, ValidationIssue, SelectionState, ChartRenderIssue, ExportOptions, ExportResult } from '@tellplot/editor';
4
+ export { ChartConfig, ChartRenderIssue, CommandError, CommandEvent, ExportOptions, ExportResult, SelectionState, ValidationIssue, ViewSpec } from '@tellplot/editor';
5
+
6
+ interface ChartEditorExposed {
7
+ focus(): void;
8
+ getView(): ViewSpec;
9
+ exportImage(options: ExportOptions): Promise<ExportResult>;
10
+ }
11
+ /** Vue lifecycle adapter with `v-model:view`; the imperative editor remains the only runtime. */
12
+ declare const ChartEditorImplementation: vue.DefineComponent<vue.ExtractPropTypes<{
13
+ config: {
14
+ type: PropType<ChartConfig>;
15
+ required: true;
16
+ };
17
+ view: {
18
+ type: PropType<ViewSpec>;
19
+ required: false;
20
+ };
21
+ defaultView: {
22
+ type: PropType<ViewSpec>;
23
+ required: false;
24
+ };
25
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
26
+ [key: string]: any;
27
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
28
+ 'update:view': (view: ViewSpec) => boolean;
29
+ viewChange: (view: ViewSpec, event: CommandEvent) => boolean;
30
+ command: (event: CommandEvent) => boolean;
31
+ commandRejected: (error: CommandError) => boolean;
32
+ configRejected: (issues: readonly ValidationIssue[]) => boolean;
33
+ selectionChange: (selection: SelectionState | null) => boolean;
34
+ renderError: (issue: ChartRenderIssue | null) => boolean;
35
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
36
+ config: {
37
+ type: PropType<ChartConfig>;
38
+ required: true;
39
+ };
40
+ view: {
41
+ type: PropType<ViewSpec>;
42
+ required: false;
43
+ };
44
+ defaultView: {
45
+ type: PropType<ViewSpec>;
46
+ required: false;
47
+ };
48
+ }>> & Readonly<{
49
+ "onUpdate:view"?: (view: ViewSpec) => any;
50
+ onViewChange?: (view: ViewSpec, event: CommandEvent) => any;
51
+ onCommand?: (event: CommandEvent) => any;
52
+ onCommandRejected?: (error: CommandError) => any;
53
+ onConfigRejected?: (issues: readonly ValidationIssue[]) => any;
54
+ onSelectionChange?: (selection: SelectionState | null) => any;
55
+ onRenderError?: (issue: ChartRenderIssue | null) => any;
56
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
57
+ type ChartEditorPublicInstance = InstanceType<typeof ChartEditorImplementation> & ChartEditorExposed;
58
+ type ChartEditorConstructor = new () => ChartEditorPublicInstance;
59
+ declare const ChartEditor: typeof ChartEditorImplementation & ChartEditorConstructor;
60
+
61
+ export { ChartEditor, type ChartEditorExposed };
@@ -0,0 +1,61 @@
1
+ import * as vue from 'vue';
2
+ import { PropType } from 'vue';
3
+ import { ChartConfig, ViewSpec, CommandEvent, CommandError, ValidationIssue, SelectionState, ChartRenderIssue, ExportOptions, ExportResult } from '@tellplot/editor';
4
+ export { ChartConfig, ChartRenderIssue, CommandError, CommandEvent, ExportOptions, ExportResult, SelectionState, ValidationIssue, ViewSpec } from '@tellplot/editor';
5
+
6
+ interface ChartEditorExposed {
7
+ focus(): void;
8
+ getView(): ViewSpec;
9
+ exportImage(options: ExportOptions): Promise<ExportResult>;
10
+ }
11
+ /** Vue lifecycle adapter with `v-model:view`; the imperative editor remains the only runtime. */
12
+ declare const ChartEditorImplementation: vue.DefineComponent<vue.ExtractPropTypes<{
13
+ config: {
14
+ type: PropType<ChartConfig>;
15
+ required: true;
16
+ };
17
+ view: {
18
+ type: PropType<ViewSpec>;
19
+ required: false;
20
+ };
21
+ defaultView: {
22
+ type: PropType<ViewSpec>;
23
+ required: false;
24
+ };
25
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
26
+ [key: string]: any;
27
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {
28
+ 'update:view': (view: ViewSpec) => boolean;
29
+ viewChange: (view: ViewSpec, event: CommandEvent) => boolean;
30
+ command: (event: CommandEvent) => boolean;
31
+ commandRejected: (error: CommandError) => boolean;
32
+ configRejected: (issues: readonly ValidationIssue[]) => boolean;
33
+ selectionChange: (selection: SelectionState | null) => boolean;
34
+ renderError: (issue: ChartRenderIssue | null) => boolean;
35
+ }, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
36
+ config: {
37
+ type: PropType<ChartConfig>;
38
+ required: true;
39
+ };
40
+ view: {
41
+ type: PropType<ViewSpec>;
42
+ required: false;
43
+ };
44
+ defaultView: {
45
+ type: PropType<ViewSpec>;
46
+ required: false;
47
+ };
48
+ }>> & Readonly<{
49
+ "onUpdate:view"?: (view: ViewSpec) => any;
50
+ onViewChange?: (view: ViewSpec, event: CommandEvent) => any;
51
+ onCommand?: (event: CommandEvent) => any;
52
+ onCommandRejected?: (error: CommandError) => any;
53
+ onConfigRejected?: (issues: readonly ValidationIssue[]) => any;
54
+ onSelectionChange?: (selection: SelectionState | null) => any;
55
+ onRenderError?: (issue: ChartRenderIssue | null) => any;
56
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
57
+ type ChartEditorPublicInstance = InstanceType<typeof ChartEditorImplementation> & ChartEditorExposed;
58
+ type ChartEditorConstructor = new () => ChartEditorPublicInstance;
59
+ declare const ChartEditor: typeof ChartEditorImplementation & ChartEditorConstructor;
60
+
61
+ export { ChartEditor, type ChartEditorExposed };
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ import { defineComponent, ref, onMounted, watch, onBeforeUnmount, h } from 'vue';
2
+ import { createEditor } from '@tellplot/editor';
3
+
4
+ // src/index.ts
5
+ var ChartEditorImplementation = defineComponent({
6
+ name: "TellPlotChartEditor",
7
+ inheritAttrs: false,
8
+ props: {
9
+ config: { type: Object, required: true },
10
+ view: { type: Object, required: false },
11
+ defaultView: { type: Object, required: false }
12
+ },
13
+ emits: {
14
+ "update:view": (view) => typeof view === "object",
15
+ viewChange: (view, event) => typeof view === "object" && typeof event === "object",
16
+ command: (event) => typeof event === "object",
17
+ commandRejected: (error) => typeof error === "object",
18
+ configRejected: (issues) => Array.isArray(issues),
19
+ selectionChange: (selection) => selection === null || typeof selection === "object",
20
+ renderError: (issue) => issue === null || typeof issue === "object"
21
+ },
22
+ setup(props, { attrs, emit, expose }) {
23
+ const host = ref(null);
24
+ let instance = null;
25
+ const toOptions = () => ({
26
+ config: props.config,
27
+ ...props.view === void 0 ? {} : { view: props.view },
28
+ ...props.defaultView === void 0 ? {} : { defaultView: props.defaultView },
29
+ onViewChange: (view, event) => {
30
+ emit("update:view", view);
31
+ emit("viewChange", view, event);
32
+ },
33
+ onCommand: (event) => emit("command", event),
34
+ onCommandRejected: (error) => emit("commandRejected", error),
35
+ onConfigRejected: (issues) => emit("configRejected", issues),
36
+ onSelectionChange: (selection) => emit("selectionChange", selection),
37
+ onRenderError: (issue) => emit("renderError", issue)
38
+ });
39
+ const exposed = {
40
+ focus: () => instance?.focus(),
41
+ getView: () => {
42
+ if (instance === null) {
43
+ throw new Error("TellPlot Vue editor is not mounted.");
44
+ }
45
+ return instance.getView();
46
+ },
47
+ exportImage: (options) => instance === null ? Promise.reject(new Error("TellPlot Vue editor is not mounted.")) : instance.exportImage(options)
48
+ };
49
+ expose(exposed);
50
+ onMounted(() => {
51
+ if (host.value !== null) {
52
+ instance = createEditor(host.value, toOptions());
53
+ }
54
+ });
55
+ watch(
56
+ () => [props.config, props.view, props.defaultView],
57
+ () => instance?.update(toOptions())
58
+ );
59
+ onBeforeUnmount(() => {
60
+ instance?.destroy();
61
+ instance = null;
62
+ });
63
+ return () => h("div", {
64
+ ...attrs,
65
+ ref: host,
66
+ class: ["tellplot-vue-host", attrs["class"]]
67
+ });
68
+ }
69
+ });
70
+ var ChartEditor = ChartEditorImplementation;
71
+
72
+ export { ChartEditor };
73
+ //# sourceMappingURL=index.js.map
74
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAuBA,IAAM,4BAA4B,eAAA,CAAgB;AAAA,EAChD,IAAA,EAAM,qBAAA;AAA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,IAAA,CAAK,KAAA,EAAO,SAAA,EAAW,CAAA;AAAA,MACjD;AAAA,IACF,CAAC,CAAA;AACD,IAAA,KAAA;AAAA,MACE,MAAM,CAAC,KAAA,CAAM,QAAQ,KAAA,CAAM,IAAA,EAAM,MAAM,WAAW,CAAA;AAAA,MAClD,MAAM,QAAA,EAAU,MAAA,CAAO,SAAA,EAAW;AAAA,KACpC;AACA,IAAA,eAAA,CAAgB,MAAM;AACpB,MAAA,QAAA,EAAU,OAAA,EAAQ;AAClB,MAAA,QAAA,GAAW,IAAA;AAAA,IACb,CAAC,CAAA;AAED,IAAA,OAAO,MACL,EAAE,KAAA,EAAO;AAAA,MACP,GAAG,KAAA;AAAA,MACH,GAAA,EAAK,IAAA;AAAA,MACL,KAAA,EAAO,CAAC,mBAAA,EAAqB,KAAA,CAAM,OAAO,CAAC;AAAA,KAC5C,CAAA;AAAA,EACL;AACF,CAAC,CAAA;AAOM,IAAM,WAAA,GAAc","file":"index.js","sourcesContent":["import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch, type PropType } from 'vue';\nimport {\n createEditor,\n type ChartConfig,\n type ChartRenderIssue,\n type CommandError,\n type CommandEvent,\n type EditorInstance,\n type EditorOptions,\n type ExportOptions,\n type ExportResult,\n type SelectionState,\n type ValidationIssue,\n type ViewSpec,\n} from '@tellplot/editor';\n\nexport interface ChartEditorExposed {\n focus(): void;\n getView(): ViewSpec;\n exportImage(options: ExportOptions): Promise<ExportResult>;\n}\n\n/** Vue lifecycle adapter with `v-model:view`; the imperative editor remains the only runtime. */\nconst ChartEditorImplementation = defineComponent({\n name: 'TellPlotChartEditor',\n inheritAttrs: false,\n props: {\n config: { type: Object as PropType<ChartConfig>, required: true },\n view: { type: Object as PropType<ViewSpec>, required: false },\n defaultView: { type: Object as PropType<ViewSpec>, required: false },\n },\n emits: {\n 'update:view': (view: ViewSpec): boolean => typeof view === 'object',\n viewChange: (view: ViewSpec, event: CommandEvent): boolean =>\n typeof view === 'object' && typeof event === 'object',\n command: (event: CommandEvent): boolean => typeof event === 'object',\n commandRejected: (error: CommandError): boolean => typeof error === 'object',\n configRejected: (issues: readonly ValidationIssue[]): boolean => Array.isArray(issues),\n selectionChange: (selection: SelectionState | null): boolean =>\n selection === null || typeof selection === 'object',\n renderError: (issue: ChartRenderIssue | null): boolean =>\n issue === null || typeof issue === 'object',\n },\n setup(props, { attrs, emit, expose }) {\n const host = ref<HTMLElement | null>(null);\n let instance: EditorInstance | null = null;\n\n const toOptions = (): EditorOptions => ({\n config: props.config,\n ...(props.view === undefined ? {} : { view: props.view }),\n ...(props.defaultView === undefined ? {} : { defaultView: props.defaultView }),\n onViewChange: (view, event) => {\n emit('update:view', view);\n emit('viewChange', view, event);\n },\n onCommand: event => emit('command', event),\n onCommandRejected: error => emit('commandRejected', error),\n onConfigRejected: issues => emit('configRejected', issues),\n onSelectionChange: selection => emit('selectionChange', selection),\n onRenderError: issue => emit('renderError', issue),\n });\n\n const exposed: ChartEditorExposed = {\n focus: () => instance?.focus(),\n getView: () => {\n if (instance === null) {\n throw new Error('TellPlot Vue editor is not mounted.');\n }\n return instance.getView();\n },\n exportImage: options =>\n instance === null\n ? Promise.reject(new Error('TellPlot Vue editor is not mounted.'))\n : instance.exportImage(options),\n };\n expose(exposed);\n\n onMounted(() => {\n if (host.value !== null) {\n instance = createEditor(host.value, toOptions());\n }\n });\n watch(\n () => [props.config, props.view, props.defaultView] as const,\n () => instance?.update(toOptions()),\n );\n onBeforeUnmount(() => {\n instance?.destroy();\n instance = null;\n });\n\n return () =>\n h('div', {\n ...attrs,\n ref: host,\n class: ['tellplot-vue-host', attrs['class']],\n });\n },\n});\n\ntype ChartEditorPublicInstance = InstanceType<typeof ChartEditorImplementation> &\n ChartEditorExposed;\n\ntype ChartEditorConstructor = new () => ChartEditorPublicInstance;\n\nexport const ChartEditor = ChartEditorImplementation as typeof ChartEditorImplementation &\n ChartEditorConstructor;\n\nexport type {\n ChartConfig,\n ChartRenderIssue,\n CommandError,\n CommandEvent,\n ExportOptions,\n ExportResult,\n SelectionState,\n ValidationIssue,\n ViewSpec,\n} from '@tellplot/editor';\n"]}
@@ -0,0 +1,11 @@
1
+ @import "@tellplot/editor/styles.css";
2
+
3
+ /* src/styles.css */
4
+ .tellplot-vue-host {
5
+ display: block;
6
+ width: 100%;
7
+ height: 100%;
8
+ min-width: 0;
9
+ min-height: 0;
10
+ }
11
+ /*# sourceMappingURL=styles.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styles.css"],"sourcesContent":["@import '@tellplot/editor/styles.css';\n\n.tellplot-vue-host {\n display: block;\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n}\n"],"mappings":";;;AAEA,CAAC;AACC,WAAS;AACT,SAAO;AACP,UAAQ;AACR,aAAW;AACX,cAAY;AACd;","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@tellplot/vue",
3
+ "version": "0.0.0-bootstrap.0",
4
+ "description": "Thin Vue 3 adapter for the framework-neutral TellPlot editor",
5
+ "license": "MIT",
6
+ "homepage": "https://tellplot.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/iiwish/tellplot.git",
10
+ "directory": "packages/vue"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/iiwish/tellplot/issues"
14
+ },
15
+ "keywords": [
16
+ "charts",
17
+ "vue",
18
+ "g2",
19
+ "data-visualization"
20
+ ],
21
+ "type": "module",
22
+ "sideEffects": [
23
+ "**/*.css"
24
+ ],
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/index.d.cts",
39
+ "default": "./dist/index.cjs"
40
+ }
41
+ },
42
+ "./styles.css": {
43
+ "types": "./dist/styles.d.ts",
44
+ "default": "./dist/styles.css"
45
+ },
46
+ "./package.json": "./package.json"
47
+ },
48
+ "engines": {
49
+ "node": ">=22.13.0"
50
+ },
51
+ "peerDependencies": {
52
+ "vue": "^3.5.0"
53
+ },
54
+ "devDependencies": {
55
+ "vue": "3.5.27"
56
+ },
57
+ "dependencies": {
58
+ "@tellplot/editor": "0.0.0-bootstrap.0"
59
+ },
60
+ "publishConfig": {
61
+ "access": "public",
62
+ "registry": "https://registry.npmjs.org/"
63
+ },
64
+ "scripts": {
65
+ "build": "tsup",
66
+ "typecheck": "tsc --noEmit -p tsconfig.json",
67
+ "test": "vitest run --root ../.. packages/vue/tests",
68
+ "test:package": "publint && attw --pack . --exclude-entrypoints ./styles.css && tsc -p tests/package/tsconfig.json"
69
+ }
70
+ }