@pixerate/editor-svelte 0.45.0 → 0.46.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.
@@ -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 state = $derived(view.current);
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={!state.canUndo} title={state.undoLabel ? `Undo ${state.undoLabel}` : 'Undo'} data-action="undo" onclick={() => controller.undo()}>Undo</button>
34
- <button type="button" class={chartButtonClass} disabled={!state.canRedo} title={state.redoLabel ? `Redo ${state.redoLabel}` : 'Redo'} data-action="redo" onclick={() => controller.redo()}>Redo</button>
35
- <span class="ml-2 truncate text-xs text-muted-foreground" data-chart-selection="" aria-live="polite">{describeChartSelection(controller, state.selection)}</span>
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 state.issues.length > 0}
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
- {state.issues.map((i) => i.message).join(' ')}
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,EAA0B,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACtF,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,8DAA8D;IAC9D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,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;AA6CH,QAAA,MAAM,WAAW,2CAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
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"}
@@ -36,11 +36,16 @@ 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`).
42
47
  */
43
- export declare function useChartToolProvider(registry: ToolRegistry | null | undefined | (() => ToolRegistry | null | undefined), controller: ChartController, options?: ChartToolProviderOptions): void;
48
+ export declare function useChartToolProvider(registry: ToolRegistry | null | undefined | (() => ToolRegistry | null | undefined), controller: ChartController, options?: ChartToolProviderHookOptions): void;
44
49
  /**
45
50
  * A `ChartPresence` and `ChartDirector` for a chart: pass `presence` and `sceneRef` to
46
51
  * `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,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EAIb,KAAK,UAAU,EACf,KAAK,wBAAwB,EAC7B,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,yCAAyC;IACzC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,6CAA6C;IAC7C,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAClC,kDAAkD;IAClD,QAAQ,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC;IAC1C,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,iBAAiB,CAAC;IACjD,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,CAAC;IAC5C,QAAQ,CAAC,QA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,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,eAAe,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;CAAE,CAgBnG;AAED,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,IAAI,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,MAAM,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAAC,EAC/F,UAAU,EAAE,eAAe,EAC3B,OAAO,GAAE,mBAAwB,GAChC,IAAI,CAMN;AAED,0HAA0H;AAC1H,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,wBAAwB,EAAE,WAAW,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,wBAAwB,CAAC,WAAW,CAAC,GAAG,KAAK,CAAA;CAAE,CAAC;AAEvJ;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,EACnF,UAAU,EAAE,eAAe,EAC3B,OAAO,GAAE,4BAAiC,GACzC,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,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, 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,16 @@ 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
- return target.register(createChartToolProvider(controller, options));
72
+ const { rasterize, ...rest } = options;
73
+ return target.register(createChartToolProvider(controller, { ...rest, rasterize: rasterize === false ? undefined : (rasterize ?? createChartRasterizer()) }));
72
74
  });
73
75
  }
74
76
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.45.0",
3
+ "version": "0.46.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.50.0"
118
+ "@pixerate/editor": "0.51.0"
119
119
  },
120
120
  "peerDependencies": {
121
121
  "@dagrejs/dagre": "^1.1.4",