@opendata-ai/openchart-svelte 6.3.0 → 6.4.1
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/dist/Chart.svelte +49 -1
- package/dist/Chart.svelte.d.ts +10 -2
- package/dist/Chart.svelte.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Chart.svelte +49 -1
package/dist/Chart.svelte
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
ChartSpec,
|
|
13
13
|
DarkMode,
|
|
14
14
|
ElementEdit,
|
|
15
|
+
ElementRef,
|
|
15
16
|
GraphSpec,
|
|
16
17
|
LayerSpec,
|
|
17
18
|
MarkEvent,
|
|
@@ -33,7 +34,11 @@ let {
|
|
|
33
34
|
onannotationclick,
|
|
34
35
|
onannotationedit,
|
|
35
36
|
onedit,
|
|
37
|
+
onselect,
|
|
38
|
+
ondeselect,
|
|
39
|
+
ontextedit,
|
|
36
40
|
ondatapointclick,
|
|
41
|
+
selectedElement: selectedElementProp,
|
|
37
42
|
class: className,
|
|
38
43
|
style,
|
|
39
44
|
}: {
|
|
@@ -47,7 +52,11 @@ let {
|
|
|
47
52
|
onannotationclick?: (annotation: Annotation, event: MouseEvent) => void;
|
|
48
53
|
onannotationedit?: (annotation: TextAnnotation, offset: AnnotationOffset) => void;
|
|
49
54
|
onedit?: (edit: ElementEdit) => void;
|
|
55
|
+
onselect?: (element: ElementRef) => void;
|
|
56
|
+
ondeselect?: (element: ElementRef) => void;
|
|
57
|
+
ontextedit?: (element: ElementRef, oldText: string, newText: string) => void;
|
|
50
58
|
ondatapointclick?: (data: Record<string, unknown>) => void;
|
|
59
|
+
selectedElement?: ElementRef;
|
|
51
60
|
class?: string;
|
|
52
61
|
style?: string;
|
|
53
62
|
} = $props();
|
|
@@ -84,6 +93,10 @@ const stableHandlers: MountOptions = {
|
|
|
84
93
|
const stableOnAnnotationEdit = (annotation: TextAnnotation, offset: AnnotationOffset) =>
|
|
85
94
|
untrack(() => onannotationedit)?.(annotation, offset);
|
|
86
95
|
const stableOnEdit = (edit: ElementEdit) => untrack(() => onedit)?.(edit);
|
|
96
|
+
const stableOnSelect = (element: ElementRef) => untrack(() => onselect)?.(element);
|
|
97
|
+
const stableOnDeselect = (element: ElementRef) => untrack(() => ondeselect)?.(element);
|
|
98
|
+
const stableOnTextEdit = (element: ElementRef, oldText: string, newText: string) =>
|
|
99
|
+
untrack(() => ontextedit)?.(element, oldText, newText);
|
|
87
100
|
|
|
88
101
|
let prevSpec = '';
|
|
89
102
|
|
|
@@ -99,6 +112,10 @@ $effect(() => {
|
|
|
99
112
|
|
|
100
113
|
const hasAnnotationEdit = untrack(() => onannotationedit) !== undefined;
|
|
101
114
|
const hasEdit = untrack(() => onedit) !== undefined;
|
|
115
|
+
const hasSelect = untrack(() => onselect) !== undefined;
|
|
116
|
+
const hasDeselect = untrack(() => ondeselect) !== undefined;
|
|
117
|
+
const hasTextEdit = untrack(() => ontextedit) !== undefined;
|
|
118
|
+
const currentSelectedElement = untrack(() => selectedElementProp);
|
|
102
119
|
|
|
103
120
|
const options: MountOptions = {
|
|
104
121
|
theme: resolvedTheme,
|
|
@@ -107,6 +124,10 @@ $effect(() => {
|
|
|
107
124
|
...stableHandlers,
|
|
108
125
|
...(hasAnnotationEdit ? { onAnnotationEdit: stableOnAnnotationEdit } : {}),
|
|
109
126
|
...(hasEdit ? { onEdit: stableOnEdit } : {}),
|
|
127
|
+
...(hasSelect ? { onSelect: stableOnSelect } : {}),
|
|
128
|
+
...(hasDeselect ? { onDeselect: stableOnDeselect } : {}),
|
|
129
|
+
...(hasTextEdit ? { onTextEdit: stableOnTextEdit } : {}),
|
|
130
|
+
...(currentSelectedElement ? { selectedElement: currentSelectedElement } : {}),
|
|
110
131
|
};
|
|
111
132
|
|
|
112
133
|
instance = createChart(containerEl, currentSpec, options);
|
|
@@ -121,9 +142,36 @@ $effect(() => {
|
|
|
121
142
|
const specString = JSON.stringify(currentSpec);
|
|
122
143
|
if (specString !== prevSpec) {
|
|
123
144
|
prevSpec = specString;
|
|
124
|
-
instance.update(currentSpec);
|
|
145
|
+
instance.update(currentSpec, { selectedElement: untrack(() => selectedElementProp) });
|
|
125
146
|
}
|
|
126
147
|
});
|
|
148
|
+
|
|
149
|
+
// Effect 3: Watch selectedElement prop changes.
|
|
150
|
+
$effect(() => {
|
|
151
|
+
const sel = selectedElementProp;
|
|
152
|
+
// Read instance without tracking to avoid coupling to Effect 1
|
|
153
|
+
const inst = untrack(() => instance);
|
|
154
|
+
if (!inst) return;
|
|
155
|
+
|
|
156
|
+
if (sel) {
|
|
157
|
+
inst.select(sel);
|
|
158
|
+
} else {
|
|
159
|
+
inst.deselect();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Imperative methods exposed via component exports
|
|
164
|
+
export function getSelectedElement(): ElementRef | null {
|
|
165
|
+
return instance?.getSelectedElement() ?? null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function select(ref: ElementRef): void {
|
|
169
|
+
instance?.select(ref);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function deselect(): void {
|
|
173
|
+
instance?.deselect();
|
|
174
|
+
}
|
|
127
175
|
</script>
|
|
128
176
|
|
|
129
177
|
<div
|
package/dist/Chart.svelte.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Annotation, AnnotationOffset, ChartSpec, DarkMode, ElementEdit, GraphSpec, LayerSpec, MarkEvent, TextAnnotation, ThemeConfig } from '@opendata-ai/openchart-core';
|
|
1
|
+
import type { Annotation, AnnotationOffset, ChartSpec, DarkMode, ElementEdit, ElementRef, GraphSpec, LayerSpec, MarkEvent, TextAnnotation, ThemeConfig } from '@opendata-ai/openchart-core';
|
|
2
2
|
type $$ComponentProps = {
|
|
3
3
|
spec: ChartSpec | LayerSpec | GraphSpec;
|
|
4
4
|
theme?: ThemeConfig;
|
|
@@ -10,11 +10,19 @@ type $$ComponentProps = {
|
|
|
10
10
|
onannotationclick?: (annotation: Annotation, event: MouseEvent) => void;
|
|
11
11
|
onannotationedit?: (annotation: TextAnnotation, offset: AnnotationOffset) => void;
|
|
12
12
|
onedit?: (edit: ElementEdit) => void;
|
|
13
|
+
onselect?: (element: ElementRef) => void;
|
|
14
|
+
ondeselect?: (element: ElementRef) => void;
|
|
15
|
+
ontextedit?: (element: ElementRef, oldText: string, newText: string) => void;
|
|
13
16
|
ondatapointclick?: (data: Record<string, unknown>) => void;
|
|
17
|
+
selectedElement?: ElementRef;
|
|
14
18
|
class?: string;
|
|
15
19
|
style?: string;
|
|
16
20
|
};
|
|
17
|
-
declare const Chart: import("svelte").Component<$$ComponentProps, {
|
|
21
|
+
declare const Chart: import("svelte").Component<$$ComponentProps, {
|
|
22
|
+
getSelectedElement: () => ElementRef | null;
|
|
23
|
+
select: (ref: ElementRef) => void;
|
|
24
|
+
deselect: () => void;
|
|
25
|
+
}, "">;
|
|
18
26
|
type Chart = ReturnType<typeof Chart>;
|
|
19
27
|
export default Chart;
|
|
20
28
|
//# sourceMappingURL=Chart.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chart.svelte.d.ts","sourceRoot":"","sources":["../src/Chart.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,6BAA6B,CAAC;AAKpC,KAAK,gBAAgB,GAAI;IACxB,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IACxC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACzC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IA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,OAAO,KAAK,IAAI,CAAC;IAC5D,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACxE,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAClF,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC;IAC3C,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7E,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC3D,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAiJF,QAAA,MAAM,KAAK;8BAlBqB,UAAU,GAAG,IAAI;kBAI3B,UAAU,KAAG,IAAI;oBAIjB,IAAI;MAUyB,CAAC;AACpD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-svelte",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.1",
|
|
4
4
|
"description": "Svelte components for openchart: <Chart />, <DataTable />, <Graph />, <VizThemeProvider />",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Riley Hilliard",
|
|
@@ -51,16 +51,16 @@
|
|
|
51
51
|
"typecheck": "svelte-check --tsconfig ./tsconfig.json"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@opendata-ai/openchart-core": "6.
|
|
55
|
-
"@opendata-ai/openchart-engine": "6.
|
|
56
|
-
"@opendata-ai/openchart-vanilla": "6.
|
|
54
|
+
"@opendata-ai/openchart-core": "6.4.1",
|
|
55
|
+
"@opendata-ai/openchart-engine": "6.4.1",
|
|
56
|
+
"@opendata-ai/openchart-vanilla": "6.4.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"svelte": ">=5.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@sveltejs/package": "^2.3.0",
|
|
63
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
63
|
+
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
64
64
|
"@testing-library/svelte": "^5.2.0",
|
|
65
65
|
"svelte": "^5.0.0",
|
|
66
66
|
"svelte-check": "^4.0.0"
|
package/src/Chart.svelte
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
ChartSpec,
|
|
13
13
|
DarkMode,
|
|
14
14
|
ElementEdit,
|
|
15
|
+
ElementRef,
|
|
15
16
|
GraphSpec,
|
|
16
17
|
LayerSpec,
|
|
17
18
|
MarkEvent,
|
|
@@ -33,7 +34,11 @@ let {
|
|
|
33
34
|
onannotationclick,
|
|
34
35
|
onannotationedit,
|
|
35
36
|
onedit,
|
|
37
|
+
onselect,
|
|
38
|
+
ondeselect,
|
|
39
|
+
ontextedit,
|
|
36
40
|
ondatapointclick,
|
|
41
|
+
selectedElement: selectedElementProp,
|
|
37
42
|
class: className,
|
|
38
43
|
style,
|
|
39
44
|
}: {
|
|
@@ -47,7 +52,11 @@ let {
|
|
|
47
52
|
onannotationclick?: (annotation: Annotation, event: MouseEvent) => void;
|
|
48
53
|
onannotationedit?: (annotation: TextAnnotation, offset: AnnotationOffset) => void;
|
|
49
54
|
onedit?: (edit: ElementEdit) => void;
|
|
55
|
+
onselect?: (element: ElementRef) => void;
|
|
56
|
+
ondeselect?: (element: ElementRef) => void;
|
|
57
|
+
ontextedit?: (element: ElementRef, oldText: string, newText: string) => void;
|
|
50
58
|
ondatapointclick?: (data: Record<string, unknown>) => void;
|
|
59
|
+
selectedElement?: ElementRef;
|
|
51
60
|
class?: string;
|
|
52
61
|
style?: string;
|
|
53
62
|
} = $props();
|
|
@@ -84,6 +93,10 @@ const stableHandlers: MountOptions = {
|
|
|
84
93
|
const stableOnAnnotationEdit = (annotation: TextAnnotation, offset: AnnotationOffset) =>
|
|
85
94
|
untrack(() => onannotationedit)?.(annotation, offset);
|
|
86
95
|
const stableOnEdit = (edit: ElementEdit) => untrack(() => onedit)?.(edit);
|
|
96
|
+
const stableOnSelect = (element: ElementRef) => untrack(() => onselect)?.(element);
|
|
97
|
+
const stableOnDeselect = (element: ElementRef) => untrack(() => ondeselect)?.(element);
|
|
98
|
+
const stableOnTextEdit = (element: ElementRef, oldText: string, newText: string) =>
|
|
99
|
+
untrack(() => ontextedit)?.(element, oldText, newText);
|
|
87
100
|
|
|
88
101
|
let prevSpec = '';
|
|
89
102
|
|
|
@@ -99,6 +112,10 @@ $effect(() => {
|
|
|
99
112
|
|
|
100
113
|
const hasAnnotationEdit = untrack(() => onannotationedit) !== undefined;
|
|
101
114
|
const hasEdit = untrack(() => onedit) !== undefined;
|
|
115
|
+
const hasSelect = untrack(() => onselect) !== undefined;
|
|
116
|
+
const hasDeselect = untrack(() => ondeselect) !== undefined;
|
|
117
|
+
const hasTextEdit = untrack(() => ontextedit) !== undefined;
|
|
118
|
+
const currentSelectedElement = untrack(() => selectedElementProp);
|
|
102
119
|
|
|
103
120
|
const options: MountOptions = {
|
|
104
121
|
theme: resolvedTheme,
|
|
@@ -107,6 +124,10 @@ $effect(() => {
|
|
|
107
124
|
...stableHandlers,
|
|
108
125
|
...(hasAnnotationEdit ? { onAnnotationEdit: stableOnAnnotationEdit } : {}),
|
|
109
126
|
...(hasEdit ? { onEdit: stableOnEdit } : {}),
|
|
127
|
+
...(hasSelect ? { onSelect: stableOnSelect } : {}),
|
|
128
|
+
...(hasDeselect ? { onDeselect: stableOnDeselect } : {}),
|
|
129
|
+
...(hasTextEdit ? { onTextEdit: stableOnTextEdit } : {}),
|
|
130
|
+
...(currentSelectedElement ? { selectedElement: currentSelectedElement } : {}),
|
|
110
131
|
};
|
|
111
132
|
|
|
112
133
|
instance = createChart(containerEl, currentSpec, options);
|
|
@@ -121,9 +142,36 @@ $effect(() => {
|
|
|
121
142
|
const specString = JSON.stringify(currentSpec);
|
|
122
143
|
if (specString !== prevSpec) {
|
|
123
144
|
prevSpec = specString;
|
|
124
|
-
instance.update(currentSpec);
|
|
145
|
+
instance.update(currentSpec, { selectedElement: untrack(() => selectedElementProp) });
|
|
125
146
|
}
|
|
126
147
|
});
|
|
148
|
+
|
|
149
|
+
// Effect 3: Watch selectedElement prop changes.
|
|
150
|
+
$effect(() => {
|
|
151
|
+
const sel = selectedElementProp;
|
|
152
|
+
// Read instance without tracking to avoid coupling to Effect 1
|
|
153
|
+
const inst = untrack(() => instance);
|
|
154
|
+
if (!inst) return;
|
|
155
|
+
|
|
156
|
+
if (sel) {
|
|
157
|
+
inst.select(sel);
|
|
158
|
+
} else {
|
|
159
|
+
inst.deselect();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Imperative methods exposed via component exports
|
|
164
|
+
export function getSelectedElement(): ElementRef | null {
|
|
165
|
+
return instance?.getSelectedElement() ?? null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function select(ref: ElementRef): void {
|
|
169
|
+
instance?.select(ref);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function deselect(): void {
|
|
173
|
+
instance?.deselect();
|
|
174
|
+
}
|
|
127
175
|
</script>
|
|
128
176
|
|
|
129
177
|
<div
|