@pixerate/editor-svelte 0.217.1 → 0.219.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 +4 -2
- package/dist/chart/ChartEditor.svelte.d.ts +2 -0
- package/dist/chart/ChartInspector.svelte +18 -1
- package/dist/chart/ChartInspector.svelte.d.ts +2 -0
- package/dist/style/style.svelte.d.ts +24 -2
- package/dist/style/style.svelte.js +56 -2
- package/package.json +2 -2
|
@@ -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,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Editor } from "@tiptap/core";
|
|
2
|
+
import type { ResolvedStyle, StyleCheckReport, StyleChoiceGroup, StyleChoiceResult, StyleResolver, StyleSwatch } from "@pixerate/editor/tools";
|
|
2
3
|
type MaybeGetter<T> = T | (() => T);
|
|
3
4
|
export interface SvelteStyle {
|
|
4
5
|
/** The resolved house style for the domain, or `null` before the first resolve (or without a resolver) (reactive). */
|
|
@@ -22,7 +23,7 @@ export declare function useStyle(styles: MaybeGetter<StyleResolver | null | unde
|
|
|
22
23
|
* the resolver notifies. Results of older runs that settle late are ignored. Feed `report` to
|
|
23
24
|
* `<StyleFindings>`. Call it during component initialisation. Parity with React's `useStyleFindings`.
|
|
24
25
|
*/
|
|
25
|
-
export declare function useStyleFindings(styles: MaybeGetter<StyleResolver | null | undefined>, domain: MaybeGetter<string>, subject: MaybeGetter<unknown>): SvelteStyleFindings;
|
|
26
|
+
export declare function useStyleFindings(styles: MaybeGetter<StyleResolver | null | undefined>, domain: MaybeGetter<string>, subject: MaybeGetter<unknown>, scope?: MaybeGetter<string | undefined>): SvelteStyleFindings;
|
|
26
27
|
export interface SvelteStyleChoices {
|
|
27
28
|
/** The one-of-a-kind groups (a look, a theme) with the chosen skill and every option, or `null` before the first read (reactive). */
|
|
28
29
|
readonly groups: StyleChoiceGroup[] | null;
|
|
@@ -39,4 +40,25 @@ export interface SvelteStyleChoices {
|
|
|
39
40
|
* Call it during component initialisation. Parity with React's `useStyleChoices`.
|
|
40
41
|
*/
|
|
41
42
|
export declare function useStyleChoices(styles: MaybeGetter<StyleResolver | null | undefined>, scope?: MaybeGetter<string | undefined>): SvelteStyleChoices;
|
|
43
|
+
export interface SvelteStyleSwatches {
|
|
44
|
+
/** The house colours, in picker order (feed `ColorPicker`'s `swatches` or `ChartEditor`'s) (reactive). */
|
|
45
|
+
readonly colors: string[];
|
|
46
|
+
/** The same colours with what each is for (`primary`, `palette 2`, ...) (reactive). */
|
|
47
|
+
readonly swatches: StyleSwatch[];
|
|
48
|
+
/** The house fonts (reactive). */
|
|
49
|
+
readonly fonts: string[];
|
|
50
|
+
/** Why the last resolve failed, or `null` (reactive). */
|
|
51
|
+
readonly error: string | null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Svelte 5 rune: the colours and fonts the house style offers for one domain, for pickers. The
|
|
55
|
+
* agent's `get_style` returns the same list. Parity with React's `useStyleSwatches`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useStyleSwatches(styles: MaybeGetter<StyleResolver | null | undefined>, domain: MaybeGetter<string>, scope?: MaybeGetter<string | undefined>): SvelteStyleSwatches;
|
|
58
|
+
/**
|
|
59
|
+
* Svelte 5 rune: the document house-style findings for a TipTap editor (`rich-text` domain),
|
|
60
|
+
* re-checked after every edit. Feed `report` to `<StyleFindings>`. Call it during component
|
|
61
|
+
* initialisation. Parity with React's `useRichTextStyleFindings`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function useRichTextStyleFindings(styles: MaybeGetter<StyleResolver | null | undefined>, editor: MaybeGetter<Editor | null | undefined>, scope?: MaybeGetter<string | undefined>): SvelteStyleFindings;
|
|
42
64
|
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { styleSwatches } from "@pixerate/editor/tools";
|
|
2
|
+
import { richTextStyleState } from "@pixerate/editor";
|
|
1
3
|
const read = (value) => (typeof value === "function" ? value() : value);
|
|
2
4
|
const message = (error) => (error instanceof Error ? error.message : String(error));
|
|
3
5
|
/**
|
|
@@ -58,11 +60,11 @@ export function useStyle(styles, domain) {
|
|
|
58
60
|
* the resolver notifies. Results of older runs that settle late are ignored. Feed `report` to
|
|
59
61
|
* `<StyleFindings>`. Call it during component initialisation. Parity with React's `useStyleFindings`.
|
|
60
62
|
*/
|
|
61
|
-
export function useStyleFindings(styles, domain, subject) {
|
|
63
|
+
export function useStyleFindings(styles, domain, subject, scope) {
|
|
62
64
|
let report = $state.raw(null);
|
|
63
65
|
let style = $state.raw(null);
|
|
64
66
|
let error = $state.raw(null);
|
|
65
|
-
resolverTask(() => ({ styles: read(styles), input: { domain: read(domain), value: read(subject) } }), (s, { domain: d, value }) => s.check(d, value), (result) => {
|
|
67
|
+
resolverTask(() => ({ styles: read(styles), input: { domain: read(domain), value: read(subject), scope: scope === undefined ? undefined : read(scope) } }), (s, { domain: d, value, scope: sc }) => s.check(d, value, sc !== undefined ? { scope: sc } : {}), (result) => {
|
|
66
68
|
if (!result.value) {
|
|
67
69
|
report = null;
|
|
68
70
|
style = null;
|
|
@@ -121,3 +123,55 @@ export function useStyleChoices(styles, scope) {
|
|
|
121
123
|
},
|
|
122
124
|
};
|
|
123
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Svelte 5 rune: the colours and fonts the house style offers for one domain, for pickers. The
|
|
128
|
+
* agent's `get_style` returns the same list. Parity with React's `useStyleSwatches`.
|
|
129
|
+
*/
|
|
130
|
+
export function useStyleSwatches(styles, domain, scope) {
|
|
131
|
+
let style = $state.raw(null);
|
|
132
|
+
let error = $state.raw(null);
|
|
133
|
+
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) => {
|
|
134
|
+
style = result.value;
|
|
135
|
+
error = result.error;
|
|
136
|
+
});
|
|
137
|
+
const swatches = $derived(style ? styleSwatches(style) : { colors: [], fonts: [] });
|
|
138
|
+
return {
|
|
139
|
+
get colors() {
|
|
140
|
+
return swatches.colors.map((c) => c.color);
|
|
141
|
+
},
|
|
142
|
+
get swatches() {
|
|
143
|
+
return swatches.colors;
|
|
144
|
+
},
|
|
145
|
+
get fonts() {
|
|
146
|
+
return swatches.fonts;
|
|
147
|
+
},
|
|
148
|
+
get error() {
|
|
149
|
+
return error;
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Svelte 5 rune: the document house-style findings for a TipTap editor (`rich-text` domain),
|
|
155
|
+
* re-checked after every edit. Feed `report` to `<StyleFindings>`. Call it during component
|
|
156
|
+
* initialisation. Parity with React's `useRichTextStyleFindings`.
|
|
157
|
+
*/
|
|
158
|
+
export function useRichTextStyleFindings(styles, editor, scope) {
|
|
159
|
+
let doc = $state.raw(null);
|
|
160
|
+
$effect(() => {
|
|
161
|
+
const ed = read(editor);
|
|
162
|
+
if (!ed) {
|
|
163
|
+
doc = null;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
doc = ed.state.doc;
|
|
167
|
+
const onUpdate = () => {
|
|
168
|
+
doc = ed.state.doc;
|
|
169
|
+
};
|
|
170
|
+
ed.on("update", onUpdate);
|
|
171
|
+
return () => {
|
|
172
|
+
ed.off("update", onUpdate);
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
const subject = $derived(doc ? richTextStyleState(doc) : null);
|
|
176
|
+
return useStyleFindings(() => (subject ? read(styles) : null), "rich-text", () => subject, scope);
|
|
177
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixerate/editor-svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.219.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.
|
|
187
|
+
"@pixerate/editor": "0.302.0"
|
|
188
188
|
},
|
|
189
189
|
"peerDependencies": {
|
|
190
190
|
"@dagrejs/dagre": "^1.1.4",
|