@pixerate/editor-svelte 0.217.0 → 0.218.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.
@@ -13,6 +13,8 @@
13
13
  interface Props {
14
14
  controller: ChartController;
15
15
  /** The settings sidebar (default `true`). */
16
+ /** House colours the inspector offers beside each series colour (e.g. from `useStyleSwatches`). */
17
+ swatches?: readonly string[];
16
18
  showInspector?: boolean;
17
19
  /** The data grid under the chart (default `true`). */
18
20
  showDataGrid?: boolean;
@@ -36,7 +38,7 @@
36
38
  onplaybackreveal?: () => void | Promise<void>;
37
39
  }
38
40
 
39
- let { controller, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps = {}, class: className = '', playback, playbackId = 'chart', onplaybackreveal }: Props = $props();
41
+ let { controller, swatches, showInspector = true, showDataGrid = true, showToolbar = true, pngOptions, height = 380, canvasProps = {}, class: className = '', playback, playbackId = 'chart', onplaybackreveal }: Props = $props();
40
42
 
41
43
  // Agent playback in the chart's scene coordinates, so a director's drags (in the same presence
42
44
  // store) and the editor's own controls share one cursor. Controls outside the chart are mapped
@@ -139,7 +141,7 @@
139
141
  {#if showInspector}
140
142
  <!-- Side by side, the canvas sets the row's height and the inspector scrolls within it. -->
141
143
  <div class="relative w-full shrink-0 md:w-64">
142
- <ChartInspector {controller} class="overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" />
144
+ <ChartInspector {controller} {swatches} class="overflow-y-auto rounded-md border border-border p-3 md:absolute md:inset-0" />
143
145
  </div>
144
146
  {/if}
145
147
  </div>
@@ -5,6 +5,8 @@ import ChartCanvas from './ChartCanvas.svelte';
5
5
  interface Props {
6
6
  controller: ChartController;
7
7
  /** The settings sidebar (default `true`). */
8
+ /** House colours the inspector offers beside each series colour (e.g. from `useStyleSwatches`). */
9
+ swatches?: readonly string[];
8
10
  showInspector?: boolean;
9
11
  /** The data grid under the chart (default `true`). */
10
12
  showDataGrid?: boolean;
@@ -64,9 +64,11 @@
64
64
  /** Prefix for the inspector's element ids. */
65
65
  idPrefix?: string;
66
66
  class?: string;
67
+ /** House colours offered beside the series colour (e.g. from `useStyleSwatches`). */
68
+ swatches?: readonly string[];
67
69
  }
68
70
 
69
- let { controller, sections, idPrefix = `pixerate-chart-${++nextId}`, class: className = '' }: Props = $props();
71
+ let { controller, sections, idPrefix = `pixerate-chart-${++nextId}`, class: className = '', swatches }: Props = $props();
70
72
 
71
73
  const view = chartStateOf(() => controller);
72
74
  const spec = $derived(view.current.spec);
@@ -689,6 +691,21 @@
689
691
  {/if}
690
692
  </div>
691
693
  </div>
694
+ {#if swatches && swatches.length > 0}
695
+ <div class="flex flex-wrap gap-1 pl-[5.5rem]" role="group" aria-label="House colours" data-option="series.swatches">
696
+ {#each swatches as color (color)}
697
+ <button
698
+ type="button"
699
+ title={color}
700
+ aria-label="Use {color}"
701
+ aria-pressed={chartColorInputValue(chartSeriesColor(spec, seriesIndex)) === chartColorInputValue(color)}
702
+ class="h-5 w-5 rounded border border-border"
703
+ style:background={color}
704
+ onclick={() => controller.updateSeries(series.id, { color })}
705
+ ></button>
706
+ {/each}
707
+ </div>
708
+ {/if}
692
709
  {#if cartesian}
693
710
  <div class="flex items-center gap-2">
694
711
  <label for="{idPrefix}-series-type" class="{chartLabelClass} w-20 shrink-0">Draw as</label>
@@ -8,6 +8,8 @@ interface Props {
8
8
  /** Prefix for the inspector's element ids. */
9
9
  idPrefix?: string;
10
10
  class?: string;
11
+ /** House colours offered beside the series colour (e.g. from `useStyleSwatches`). */
12
+ swatches?: readonly string[];
11
13
  }
12
14
  declare const ChartInspector: import("svelte").Component<Props, {}, "">;
13
15
  type ChartInspector = ReturnType<typeof ChartInspector>;
@@ -1,4 +1,4 @@
1
- import type { ResolvedStyle, StyleCheckReport, StyleChoiceGroup, StyleChoiceResult, StyleResolver } from "@pixerate/editor/tools";
1
+ import type { ResolvedStyle, StyleCheckReport, StyleChoiceGroup, StyleChoiceResult, StyleResolver, StyleSwatch } from "@pixerate/editor/tools";
2
2
  type MaybeGetter<T> = T | (() => T);
3
3
  export interface SvelteStyle {
4
4
  /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver) (reactive). */
@@ -39,4 +39,19 @@ export interface SvelteStyleChoices {
39
39
  * Call it during component initialisation. Parity with React's `useStyleChoices`.
40
40
  */
41
41
  export declare function useStyleChoices(styles: MaybeGetter<StyleResolver | null | undefined>, scope?: MaybeGetter<string | undefined>): SvelteStyleChoices;
42
+ export interface SvelteStyleSwatches {
43
+ /** The house colours, in picker order (feed `ColorPicker`'s `swatches` or `ChartEditor`'s) (reactive). */
44
+ readonly colors: string[];
45
+ /** The same colours with what each is for (`primary`, `palette 2`, ...) (reactive). */
46
+ readonly swatches: StyleSwatch[];
47
+ /** The house fonts (reactive). */
48
+ readonly fonts: string[];
49
+ /** Why the last resolve failed, or `null` (reactive). */
50
+ readonly error: string | null;
51
+ }
52
+ /**
53
+ * Svelte 5 rune: the colours and fonts the house style offers for one domain, for pickers. The
54
+ * agent's `get_style` returns the same list. Parity with React's `useStyleSwatches`.
55
+ */
56
+ export declare function useStyleSwatches(styles: MaybeGetter<StyleResolver | null | undefined>, domain: MaybeGetter<string>, scope?: MaybeGetter<string | undefined>): SvelteStyleSwatches;
42
57
  export {};
@@ -1,3 +1,4 @@
1
+ import { styleSwatches } from "@pixerate/editor/tools";
1
2
  const read = (value) => (typeof value === "function" ? value() : value);
2
3
  const message = (error) => (error instanceof Error ? error.message : String(error));
3
4
  /**
@@ -121,3 +122,30 @@ export function useStyleChoices(styles, scope) {
121
122
  },
122
123
  };
123
124
  }
125
+ /**
126
+ * Svelte 5 rune: the colours and fonts the house style offers for one domain, for pickers. The
127
+ * agent's `get_style` returns the same list. Parity with React's `useStyleSwatches`.
128
+ */
129
+ export function useStyleSwatches(styles, domain, scope) {
130
+ let style = $state.raw(null);
131
+ let error = $state.raw(null);
132
+ resolverTask(() => ({ styles: read(styles), input: { domain: read(domain), scope: scope === undefined ? undefined : read(scope) } }), (s, { domain: d, scope: sc }) => s.resolve(d, sc !== undefined ? { scope: sc } : {}), (result) => {
133
+ style = result.value;
134
+ error = result.error;
135
+ });
136
+ const swatches = $derived(style ? styleSwatches(style) : { colors: [], fonts: [] });
137
+ return {
138
+ get colors() {
139
+ return swatches.colors.map((c) => c.color);
140
+ },
141
+ get swatches() {
142
+ return swatches.colors;
143
+ },
144
+ get fonts() {
145
+ return swatches.fonts;
146
+ },
147
+ get error() {
148
+ return error;
149
+ },
150
+ };
151
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.217.0",
3
+ "version": "0.218.0",
4
4
  "description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -184,7 +184,7 @@
184
184
  "**/*.css"
185
185
  ],
186
186
  "dependencies": {
187
- "@pixerate/editor": "0.299.0"
187
+ "@pixerate/editor": "0.301.0"
188
188
  },
189
189
  "peerDependencies": {
190
190
  "@dagrejs/dagre": "^1.1.4",