@opendata-ai/openchart-core 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/index.d.ts +54 -3
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/types/events.ts +43 -3
- package/src/types/index.ts +2 -0
- package/src/types/layout.ts +2 -0
- package/src/types/spec.ts +2 -0
package/package.json
CHANGED
package/src/types/events.ts
CHANGED
|
@@ -25,13 +25,45 @@ import type {
|
|
|
25
25
|
/** Identifies a specific chrome text element (title, subtitle, source, byline, footer). */
|
|
26
26
|
export type ChromeKey = 'title' | 'subtitle' | 'source' | 'byline' | 'footer';
|
|
27
27
|
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Element references (identity for selection/edit callbacks)
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Reference to an editable chart element.
|
|
34
|
+
* Carries enough info to find the element in both the spec and the DOM.
|
|
35
|
+
* The `annotation` variant uses two-tier identity: `id` (when the consumer provides one)
|
|
36
|
+
* and `index` (always available, position in the spec's annotations array).
|
|
37
|
+
*/
|
|
38
|
+
export type ElementRef =
|
|
39
|
+
| { type: 'annotation'; index: number; id?: string }
|
|
40
|
+
| { type: 'chrome'; key: ChromeKey }
|
|
41
|
+
| { type: 'series-label'; series: string }
|
|
42
|
+
| { type: 'legend' }
|
|
43
|
+
| { type: 'legend-entry'; series: string; index: number };
|
|
44
|
+
|
|
45
|
+
/** Helper constructors for ergonomic ElementRef creation. */
|
|
46
|
+
export const elementRef = {
|
|
47
|
+
annotation: (index: number, id?: string): ElementRef => ({ type: 'annotation', index, id }),
|
|
48
|
+
chrome: (key: ChromeKey): ElementRef => ({ type: 'chrome', key }),
|
|
49
|
+
seriesLabel: (series: string): ElementRef => ({ type: 'series-label', series }),
|
|
50
|
+
legend: (): ElementRef => ({ type: 'legend' }),
|
|
51
|
+
legendEntry: (series: string, index: number): ElementRef => ({
|
|
52
|
+
type: 'legend-entry',
|
|
53
|
+
series,
|
|
54
|
+
index,
|
|
55
|
+
}),
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
28
58
|
// ---------------------------------------------------------------------------
|
|
29
59
|
// Element edit events
|
|
30
60
|
// ---------------------------------------------------------------------------
|
|
31
61
|
|
|
32
62
|
/**
|
|
33
63
|
* Discriminated union of all element edit events.
|
|
34
|
-
* Fired by the `onEdit` callback when any editable chart element is
|
|
64
|
+
* Fired by the `onEdit` callback when any editable chart element is modified.
|
|
65
|
+
* Covers repositioning (drag), deletion (Delete key), and text editing (double-click).
|
|
66
|
+
* Selection events (onSelect/onDeselect) are separate callbacks, not part of this union.
|
|
35
67
|
*/
|
|
36
68
|
export type ElementEdit =
|
|
37
69
|
| { type: 'annotation'; annotation: TextAnnotation; offset: AnnotationOffset }
|
|
@@ -46,7 +78,9 @@ export type ElementEdit =
|
|
|
46
78
|
| { type: 'chrome'; key: ChromeKey; text: string; offset: AnnotationOffset }
|
|
47
79
|
| { type: 'series-label'; series: string; offset: AnnotationOffset }
|
|
48
80
|
| { type: 'legend'; offset: AnnotationOffset }
|
|
49
|
-
| { type: 'legend-toggle'; series: string; hidden: boolean }
|
|
81
|
+
| { type: 'legend-toggle'; series: string; hidden: boolean }
|
|
82
|
+
| { type: 'delete'; element: ElementRef }
|
|
83
|
+
| { type: 'text-edit'; element: ElementRef; oldText: string; newText: string };
|
|
50
84
|
|
|
51
85
|
// ---------------------------------------------------------------------------
|
|
52
86
|
// Mark events
|
|
@@ -92,6 +126,12 @@ export interface ChartEventHandlers {
|
|
|
92
126
|
onAnnotationClick?: (annotation: Annotation, event: MouseEvent) => void;
|
|
93
127
|
/** Called when a text annotation label is dragged to a new position. */
|
|
94
128
|
onAnnotationEdit?: (annotation: TextAnnotation, updatedOffset: AnnotationOffset) => void;
|
|
95
|
-
/** Unified edit callback. Fires for any
|
|
129
|
+
/** Unified edit callback. Fires for any spec-modifying edit (repositioning, deletion, text editing). */
|
|
96
130
|
onEdit?: (edit: ElementEdit) => void;
|
|
131
|
+
/** Fired when an element is selected via click or programmatic select(). */
|
|
132
|
+
onSelect?: (element: ElementRef) => void;
|
|
133
|
+
/** Fired when the current element is deselected (click empty, Escape, or new selection replaces old). */
|
|
134
|
+
onDeselect?: (element: ElementRef) => void;
|
|
135
|
+
/** Fired when inline text editing commits. Also flows through onEdit as a 'text-edit' event. */
|
|
136
|
+
onTextEdit?: (element: ElementRef, oldText: string, newText: string) => void;
|
|
97
137
|
}
|
package/src/types/index.ts
CHANGED
package/src/types/layout.ts
CHANGED
|
@@ -490,6 +490,8 @@ export interface ResolvedLabel {
|
|
|
490
490
|
export interface ResolvedAnnotation {
|
|
491
491
|
/** Original annotation type. */
|
|
492
492
|
type: 'text' | 'range' | 'refline';
|
|
493
|
+
/** Stable identifier from the spec annotation, for selection/edit callbacks. */
|
|
494
|
+
id?: string;
|
|
493
495
|
/** Label text (if any). */
|
|
494
496
|
label?: ResolvedLabel;
|
|
495
497
|
/** For range: the highlighted rectangle in pixel coordinates. */
|
package/src/types/spec.ts
CHANGED
|
@@ -382,6 +382,8 @@ export type AnnotationAnchor = 'top' | 'bottom' | 'left' | 'right' | 'auto';
|
|
|
382
382
|
|
|
383
383
|
/** Base properties shared by all annotation types. */
|
|
384
384
|
interface AnnotationBase {
|
|
385
|
+
/** Stable identifier for selection and edit callbacks. When provided, edit events include this ID for reliable element matching. */
|
|
386
|
+
id?: string;
|
|
385
387
|
/** Human-readable label for the annotation. */
|
|
386
388
|
label?: string;
|
|
387
389
|
/** Fill color for the annotation element. */
|