@pixerate/editor-svelte 0.216.8 → 0.217.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,4 +1,4 @@
1
- import type { ResolvedStyle, StyleCheckReport, StyleResolver } from "@pixerate/editor/tools";
1
+ import type { ResolvedStyle, StyleCheckReport, StyleChoiceGroup, StyleChoiceResult, StyleResolver } 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). */
@@ -23,4 +23,20 @@ export declare function useStyle(styles: MaybeGetter<StyleResolver | null | unde
23
23
  * `<StyleFindings>`. Call it during component initialisation. Parity with React's `useStyleFindings`.
24
24
  */
25
25
  export declare function useStyleFindings(styles: MaybeGetter<StyleResolver | null | undefined>, domain: MaybeGetter<string>, subject: MaybeGetter<unknown>): SvelteStyleFindings;
26
+ export interface SvelteStyleChoices {
27
+ /** 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
+ readonly groups: StyleChoiceGroup[] | null;
29
+ /** Why the last read or choice failed, or `null` (reactive). */
30
+ readonly error: string | null;
31
+ /** Chooses a skill of its group (see `StyleResolver.choose`); resolves to what changed, or rejects with the reason. */
32
+ choose(name: string, options?: {
33
+ layer?: string;
34
+ }): Promise<StyleChoiceResult>;
35
+ }
36
+ /**
37
+ * Svelte 5 rune: the house-style choices for a picker, each one-of-a-kind group with the skill
38
+ * that applies and its options, in `scope` when given. Re-reads when the resolver notifies.
39
+ * Call it during component initialisation. Parity with React's `useStyleChoices`.
40
+ */
41
+ export declare function useStyleChoices(styles: MaybeGetter<StyleResolver | null | undefined>, scope?: MaybeGetter<string | undefined>): SvelteStyleChoices;
26
42
  export {};
@@ -87,3 +87,37 @@ export function useStyleFindings(styles, domain, subject) {
87
87
  },
88
88
  };
89
89
  }
90
+ /**
91
+ * Svelte 5 rune: the house-style choices for a picker, each one-of-a-kind group with the skill
92
+ * that applies and its options, in `scope` when given. Re-reads when the resolver notifies.
93
+ * Call it during component initialisation. Parity with React's `useStyleChoices`.
94
+ */
95
+ export function useStyleChoices(styles, scope) {
96
+ let groups = $state.raw(null);
97
+ let error = $state.raw(null);
98
+ resolverTask(() => ({ styles: read(styles), input: scope === undefined ? undefined : read(scope) }), (s, sc) => s.choices(sc !== undefined ? { scope: sc } : {}), (result) => {
99
+ groups = result.value;
100
+ error = result.error;
101
+ });
102
+ return {
103
+ get groups() {
104
+ return groups;
105
+ },
106
+ get error() {
107
+ return error;
108
+ },
109
+ async choose(name, options = {}) {
110
+ const s = read(styles);
111
+ if (!s)
112
+ throw new Error("There is no style resolver to choose with.");
113
+ const sc = scope === undefined ? undefined : read(scope);
114
+ try {
115
+ return await s.choose(name, { ...options, ...(sc !== undefined ? { scope: sc } : {}) });
116
+ }
117
+ catch (e) {
118
+ error = message(e);
119
+ throw e;
120
+ }
121
+ },
122
+ };
123
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.216.8",
3
+ "version": "0.217.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.298.0"
187
+ "@pixerate/editor": "0.299.0"
188
188
  },
189
189
  "peerDependencies": {
190
190
  "@dagrejs/dagre": "^1.1.4",