@pixerate/editor-svelte 0.45.0 → 0.47.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/dist/chart/ChartEditor.svelte +20 -9
- package/dist/chart/ChartEditor.svelte.d.ts +4 -2
- package/dist/chart/ChartEditor.svelte.d.ts.map +1 -1
- package/dist/chart/createChartEditor.svelte.d.ts +14 -3
- package/dist/chart/createChartEditor.svelte.d.ts.map +1 -1
- package/dist/chart/createChartEditor.svelte.js +18 -3
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { ComponentProps } from 'svelte';
|
|
3
|
-
import { describeChartSelection, type ChartController } from '@pixerate/editor/chart';
|
|
3
|
+
import { describeChartSelection, downloadChartPng, type ChartController, type DownloadChartPngOptions } from '@pixerate/editor/chart';
|
|
4
4
|
import ChartCanvas from './ChartCanvas.svelte';
|
|
5
5
|
import ChartDataGrid from './ChartDataGrid.svelte';
|
|
6
6
|
import ChartInspector from './ChartInspector.svelte';
|
|
@@ -13,31 +13,42 @@
|
|
|
13
13
|
showInspector?: boolean;
|
|
14
14
|
/** The data grid under the chart (default `true`). */
|
|
15
15
|
showDataGrid?: boolean;
|
|
16
|
-
/** Undo / redo and the selection readout (default `true`). */
|
|
16
|
+
/** Undo / redo, Download PNG and the selection readout (default `true`). */
|
|
17
17
|
showToolbar?: boolean;
|
|
18
|
+
/** Size, theme, scale and file name for the toolbar's Download PNG (default 800 × 450, light theme). */
|
|
19
|
+
pngOptions?: DownloadChartPngOptions;
|
|
18
20
|
/** Chart height in pixels (default 380). */
|
|
19
21
|
height?: number;
|
|
20
22
|
canvasProps?: Omit<ComponentProps<typeof ChartCanvas>, 'controller' | 'height'>;
|
|
21
23
|
class?: string;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
let { controller, showInspector = true, showDataGrid = true, showToolbar = true, height = 380, canvasProps = {}, class: className = '' }: Props = $props();
|
|
26
|
+
let { controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps = {}, class: className = '' }: Props = $props();
|
|
25
27
|
|
|
26
28
|
const view = chartStateOf(() => controller);
|
|
27
|
-
const
|
|
29
|
+
const chart = $derived(view.current);
|
|
30
|
+
let pngError = $state<string | null>(null);
|
|
31
|
+
function downloadPng() {
|
|
32
|
+
pngError = null;
|
|
33
|
+
downloadChartPng(controller.toJSON(), pngOptions).catch((error: unknown) => (pngError = error instanceof Error ? error.message : String(error)));
|
|
34
|
+
}
|
|
28
35
|
</script>
|
|
29
36
|
|
|
30
37
|
<div class="flex flex-col gap-2 {className}" data-chart-editor="">
|
|
31
38
|
{#if showToolbar}
|
|
32
39
|
<div class="flex items-center gap-1" data-chart-toolbar="">
|
|
33
|
-
<button type="button" class={chartButtonClass} disabled={!
|
|
34
|
-
<button type="button" class={chartButtonClass} disabled={!
|
|
35
|
-
<
|
|
40
|
+
<button type="button" class={chartButtonClass} disabled={!chart.canUndo} title={chart.undoLabel ? `Undo ${chart.undoLabel}` : 'Undo'} data-action="undo" onclick={() => controller.undo()}>Undo</button>
|
|
41
|
+
<button type="button" class={chartButtonClass} disabled={!chart.canRedo} title={chart.redoLabel ? `Redo ${chart.redoLabel}` : 'Redo'} data-action="redo" onclick={() => controller.redo()}>Redo</button>
|
|
42
|
+
<button type="button" class={chartButtonClass} title="Download the chart as a PNG image" data-action="download-png" onclick={downloadPng}>Download PNG</button>
|
|
43
|
+
<span class="ml-2 truncate text-xs text-muted-foreground" data-chart-selection="" aria-live="polite">{describeChartSelection(controller, chart.selection)}</span>
|
|
36
44
|
</div>
|
|
37
45
|
{/if}
|
|
38
|
-
{#if
|
|
46
|
+
{#if pngError}
|
|
47
|
+
<p role="alert" class="rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive" data-chart-png-error="">{pngError}</p>
|
|
48
|
+
{/if}
|
|
49
|
+
{#if chart.issues.length > 0}
|
|
39
50
|
<p role="alert" class="rounded-md border border-destructive/40 bg-destructive/10 px-2 py-1 text-xs text-destructive" data-chart-issues="">
|
|
40
|
-
{
|
|
51
|
+
{chart.issues.map((i) => i.message).join(' ')}
|
|
41
52
|
</p>
|
|
42
53
|
{/if}
|
|
43
54
|
<div class="flex min-h-0 flex-col gap-2 md:flex-row">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentProps } from 'svelte';
|
|
2
|
-
import { type ChartController } from '@pixerate/editor/chart';
|
|
2
|
+
import { type ChartController, type DownloadChartPngOptions } from '@pixerate/editor/chart';
|
|
3
3
|
import ChartCanvas from './ChartCanvas.svelte';
|
|
4
4
|
interface Props {
|
|
5
5
|
controller: ChartController;
|
|
@@ -7,8 +7,10 @@ interface Props {
|
|
|
7
7
|
showInspector?: boolean;
|
|
8
8
|
/** The data grid under the chart (default `true`). */
|
|
9
9
|
showDataGrid?: boolean;
|
|
10
|
-
/** Undo / redo and the selection readout (default `true`). */
|
|
10
|
+
/** Undo / redo, Download PNG and the selection readout (default `true`). */
|
|
11
11
|
showToolbar?: boolean;
|
|
12
|
+
/** Size, theme, scale and file name for the toolbar's Download PNG (default 800 × 450, light theme). */
|
|
13
|
+
pngOptions?: DownloadChartPngOptions;
|
|
12
14
|
/** Chart height in pixels (default 380). */
|
|
13
15
|
height?: number;
|
|
14
16
|
canvasProps?: Omit<ComponentProps<typeof ChartCanvas>, 'controller' | 'height'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartEditor.svelte.d.ts","sourceRoot":"","sources":["../../src/chart/ChartEditor.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"ChartEditor.svelte.d.ts","sourceRoot":"","sources":["../../src/chart/ChartEditor.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAA4C,KAAK,eAAe,EAAE,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtI,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAO7C,UAAU,KAAK;IACb,UAAU,EAAE,eAAe,CAAC;IAC5B,6CAA6C;IAC7C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sDAAsD;IACtD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wGAAwG;IACxG,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAC,CAAC;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAsDH,QAAA,MAAM,WAAW,2CAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ToolRegistry } from "@pixerate/editor/tools";
|
|
2
|
-
import { ChartController, ChartDirector, ChartPresence, type ChartScene, type ChartToolProviderOptions, type ChartActionResult, type ChartCommandOptions, type ChartControllerOptions, type ChartSelection, type ChartSpecPatch, type ChartState, type ChartType } from "@pixerate/editor/chart";
|
|
2
|
+
import { ChartController, ChartDirector, ChartPresence, type OfficeChartToolProviderOptions, type ChartScene, type ChartToolProviderOptions, type ChartActionResult, type ChartCommandOptions, type ChartControllerOptions, type ChartSelection, type ChartSpecPatch, type ChartState, type ChartType } from "@pixerate/editor/chart";
|
|
3
3
|
export interface SvelteChartEditor {
|
|
4
4
|
readonly controller: ChartController;
|
|
5
5
|
/** The controller's state (reactive). */
|
|
@@ -36,11 +36,22 @@ export interface ChartCommandTarget {
|
|
|
36
36
|
* initialisation). Pass a getter to follow a changing registry.
|
|
37
37
|
*/
|
|
38
38
|
export declare function useChartCommands(registry: ChartCommandTarget | null | undefined | (() => ChartCommandTarget | null | undefined), controller: ChartController, options?: ChartCommandOptions): void;
|
|
39
|
+
/** `useChartToolProvider` options: `rasterize` defaults to a canvas rasterizer in the browser (`false` turns PNG off). */
|
|
40
|
+
export type ChartToolProviderHookOptions = Omit<ChartToolProviderOptions, "rasterize"> & {
|
|
41
|
+
rasterize?: ChartToolProviderOptions["rasterize"] | false;
|
|
42
|
+
};
|
|
39
43
|
/**
|
|
40
44
|
* Registers the chart's agent tools (`createChartToolProvider`) with a `ToolRegistry` for the
|
|
41
|
-
* lifetime of the calling component. Pass a getter to follow a changing registry.
|
|
45
|
+
* lifetime of the calling component. Pass a getter to follow a changing registry. In the
|
|
46
|
+
* browser, `render_chart { format: "png" }` works out of the box (`createChartRasterizer`).
|
|
47
|
+
*/
|
|
48
|
+
export declare function useChartToolProvider(registry: ToolRegistry | null | undefined | (() => ToolRegistry | null | undefined), controller: ChartController, options?: ChartToolProviderHookOptions): void;
|
|
49
|
+
/**
|
|
50
|
+
* Registers the Office-file chart tools (`createOfficeChartToolProvider`: `list_file_charts`,
|
|
51
|
+
* `get_file_chart`, and `load_file_chart` with a `controller`) for the lifetime of the calling
|
|
52
|
+
* component. Pass a getter to follow a changing registry.
|
|
42
53
|
*/
|
|
43
|
-
export declare function
|
|
54
|
+
export declare function useOfficeChartToolProvider(registry: ToolRegistry | null | undefined | (() => ToolRegistry | null | undefined), options?: OfficeChartToolProviderOptions): void;
|
|
44
55
|
/**
|
|
45
56
|
* A `ChartPresence` and `ChartDirector` for a chart: pass `presence` and `sceneRef` to
|
|
46
57
|
* `ChartCanvas`, and `director` to `useChartToolProvider` so agent edits are acted out with a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createChartEditor.svelte.d.ts","sourceRoot":"","sources":["../../src/chart/createChartEditor.svelte.ts"],"names":[],"mappings":"AACA,OAAO,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MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO;;;;iBAC9G,UAAU,GAAG,IAAI;;EAK7C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { untrack } from "svelte";
|
|
2
|
-
import { ChartController, ChartDirector, ChartPresence, createChartCommands, createChartToolProvider, layoutChart, } from "@pixerate/editor/chart";
|
|
2
|
+
import { ChartController, ChartDirector, ChartPresence, createChartCommands, createChartRasterizer, createChartToolProvider, createOfficeChartToolProvider, layoutChart, } from "@pixerate/editor/chart";
|
|
3
3
|
/**
|
|
4
4
|
* Svelte 5 rune: subscribes to a `ChartController` (or creates one from options) and
|
|
5
5
|
* exposes its state reactively with bound actions.
|
|
@@ -61,14 +61,29 @@ export function useChartCommands(registry, controller, options = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Registers the chart's agent tools (`createChartToolProvider`) with a `ToolRegistry` for the
|
|
64
|
-
* lifetime of the calling component. Pass a getter to follow a changing registry.
|
|
64
|
+
* lifetime of the calling component. Pass a getter to follow a changing registry. In the
|
|
65
|
+
* browser, `render_chart { format: "png" }` works out of the box (`createChartRasterizer`).
|
|
65
66
|
*/
|
|
66
67
|
export function useChartToolProvider(registry, controller, options = {}) {
|
|
67
68
|
$effect(() => {
|
|
68
69
|
const target = typeof registry === "function" ? registry() : registry;
|
|
69
70
|
if (!target)
|
|
70
71
|
return;
|
|
71
|
-
|
|
72
|
+
const { rasterize, ...rest } = options;
|
|
73
|
+
return target.register(createChartToolProvider(controller, { ...rest, rasterize: rasterize === false ? undefined : (rasterize ?? createChartRasterizer()) }));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Registers the Office-file chart tools (`createOfficeChartToolProvider`: `list_file_charts`,
|
|
78
|
+
* `get_file_chart`, and `load_file_chart` with a `controller`) for the lifetime of the calling
|
|
79
|
+
* component. Pass a getter to follow a changing registry.
|
|
80
|
+
*/
|
|
81
|
+
export function useOfficeChartToolProvider(registry, options = {}) {
|
|
82
|
+
$effect(() => {
|
|
83
|
+
const target = typeof registry === "function" ? registry() : registry;
|
|
84
|
+
if (!target)
|
|
85
|
+
return;
|
|
86
|
+
return target.register(createOfficeChartToolProvider(untrack(() => options)));
|
|
72
87
|
});
|
|
73
88
|
}
|
|
74
89
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0",
|
|
4
4
|
"description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
|
|
5
5
|
"author": "Pixerate",
|
|
6
6
|
"license": "MIT",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"@tiptap/extension-bubble-menu": "^2.11.5",
|
|
116
116
|
"@tiptap/extension-placeholder": "^2.11.5",
|
|
117
117
|
"@tiptap/starter-kit": "^2.11.5",
|
|
118
|
-
"@pixerate/editor": "0.
|
|
118
|
+
"@pixerate/editor": "0.52.0"
|
|
119
119
|
},
|
|
120
120
|
"peerDependencies": {
|
|
121
121
|
"@dagrejs/dagre": "^1.1.4",
|