@pixerate/editor-react 0.201.1 → 0.202.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/index.cjs CHANGED
@@ -148,6 +148,7 @@ __export(src_exports, {
148
148
  useSpreadsheetEditor: () => useSpreadsheetEditor,
149
149
  useSpreadsheetViewport: () => useSpreadsheetViewport,
150
150
  useStyle: () => useStyle,
151
+ useStyleChoices: () => useStyleChoices,
151
152
  useStyleFindings: () => useStyleFindings,
152
153
  useTableMenu: () => useTableMenu,
153
154
  useToolBridge: () => useToolBridge,
@@ -14583,6 +14584,28 @@ function useStyleFindings(styles, domain, state) {
14583
14584
  );
14584
14585
  return result;
14585
14586
  }
14587
+ function useStyleChoices(styles, scope) {
14588
+ const [state, setState] = (0, import_react104.useState)({ groups: null, error: null });
14589
+ useResolverTask(
14590
+ styles,
14591
+ (s) => s.choices(scope !== void 0 ? { scope } : {}),
14592
+ ({ value, error }) => setState({ groups: value, error }),
14593
+ [scope]
14594
+ );
14595
+ const choose = (0, import_react104.useCallback)(
14596
+ async (name, options = {}) => {
14597
+ if (!styles) throw new Error("There is no style resolver to choose with.");
14598
+ try {
14599
+ return await styles.choose(name, { ...options, ...scope !== void 0 ? { scope } : {} });
14600
+ } catch (error) {
14601
+ setState((prev) => ({ ...prev, error: message(error) }));
14602
+ throw error;
14603
+ }
14604
+ },
14605
+ [styles, scope]
14606
+ );
14607
+ return { ...state, choose };
14608
+ }
14586
14609
 
14587
14610
  // src/style/StyleFindings.tsx
14588
14611
  var import_jsx_runtime80 = require("react/jsx-runtime");
@@ -14756,6 +14779,7 @@ function StyleFindings({ report, onSelect, title = "House style", className = ""
14756
14779
  useSpreadsheetEditor,
14757
14780
  useSpreadsheetViewport,
14758
14781
  useStyle,
14782
+ useStyleChoices,
14759
14783
  useStyleFindings,
14760
14784
  useTableMenu,
14761
14785
  useToolBridge,
package/dist/index.js CHANGED
@@ -2264,7 +2264,7 @@ function createReactChartNodeView(options = {}) {
2264
2264
  }
2265
2265
 
2266
2266
  // src/style/useStyle.ts
2267
- import { useEffect as useEffect13, useState as useState14 } from "react";
2267
+ import { useCallback as useCallback9, useEffect as useEffect13, useState as useState14 } from "react";
2268
2268
  var message = (error) => error instanceof Error ? error.message : String(error);
2269
2269
  function useResolverTask(styles, run, deliver, deps) {
2270
2270
  useEffect13(() => {
@@ -2319,6 +2319,28 @@ function useStyleFindings(styles, domain, state) {
2319
2319
  );
2320
2320
  return result;
2321
2321
  }
2322
+ function useStyleChoices(styles, scope) {
2323
+ const [state, setState] = useState14({ groups: null, error: null });
2324
+ useResolverTask(
2325
+ styles,
2326
+ (s) => s.choices(scope !== void 0 ? { scope } : {}),
2327
+ ({ value, error }) => setState({ groups: value, error }),
2328
+ [scope]
2329
+ );
2330
+ const choose = useCallback9(
2331
+ async (name, options = {}) => {
2332
+ if (!styles) throw new Error("There is no style resolver to choose with.");
2333
+ try {
2334
+ return await styles.choose(name, { ...options, ...scope !== void 0 ? { scope } : {} });
2335
+ } catch (error) {
2336
+ setState((prev) => ({ ...prev, error: message(error) }));
2337
+ throw error;
2338
+ }
2339
+ },
2340
+ [styles, scope]
2341
+ );
2342
+ return { ...state, choose };
2343
+ }
2322
2344
 
2323
2345
  // src/style/StyleFindings.tsx
2324
2346
  import { Fragment as Fragment2, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
@@ -2491,6 +2513,7 @@ export {
2491
2513
  useSpreadsheetEditor,
2492
2514
  useSpreadsheetViewport,
2493
2515
  useStyle,
2516
+ useStyleChoices,
2494
2517
  useStyleFindings,
2495
2518
  useTableMenu,
2496
2519
  useToolBridge,
@@ -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
  export interface UseStyleResult {
3
3
  /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver). */
4
4
  style: ResolvedStyle | null;
@@ -20,3 +20,19 @@ export declare function useStyle(styles: StyleResolver | null | undefined, domai
20
20
  * older runs that settle late are ignored. Feed `report` to `<StyleFindings>`.
21
21
  */
22
22
  export declare function useStyleFindings(styles: StyleResolver | null | undefined, domain: string, state: unknown): UseStyleFindingsResult;
23
+ export interface UseStyleChoicesResult {
24
+ /** The one-of-a-kind groups (a look, a theme) with the chosen skill and every option, or `null` before the first read. */
25
+ groups: StyleChoiceGroup[] | null;
26
+ /** Why the last read or choice failed, or `null`. */
27
+ error: string | null;
28
+ /** Chooses a skill of its group (see `StyleResolver.choose`); resolves to what changed, or rejects with the reason. */
29
+ choose(name: string, options?: {
30
+ layer?: string;
31
+ }): Promise<StyleChoiceResult>;
32
+ }
33
+ /**
34
+ * The house-style choices for a picker: each one-of-a-kind group with the skill that applies
35
+ * and its options, in `scope` when given. Re-reads when the resolver notifies, so a choice an
36
+ * agent makes with `choose_style` shows at once. Parity with Svelte's `useStyleChoices`.
37
+ */
38
+ export declare function useStyleChoices(styles: StyleResolver | null | undefined, scope?: string): UseStyleChoicesResult;
@@ -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
  export interface UseStyleResult {
3
3
  /** The resolved house style for the domain, or `null` before the first resolve (or without a resolver). */
4
4
  style: ResolvedStyle | null;
@@ -20,3 +20,19 @@ export declare function useStyle(styles: StyleResolver | null | undefined, domai
20
20
  * older runs that settle late are ignored. Feed `report` to `<StyleFindings>`.
21
21
  */
22
22
  export declare function useStyleFindings(styles: StyleResolver | null | undefined, domain: string, state: unknown): UseStyleFindingsResult;
23
+ export interface UseStyleChoicesResult {
24
+ /** The one-of-a-kind groups (a look, a theme) with the chosen skill and every option, or `null` before the first read. */
25
+ groups: StyleChoiceGroup[] | null;
26
+ /** Why the last read or choice failed, or `null`. */
27
+ error: string | null;
28
+ /** Chooses a skill of its group (see `StyleResolver.choose`); resolves to what changed, or rejects with the reason. */
29
+ choose(name: string, options?: {
30
+ layer?: string;
31
+ }): Promise<StyleChoiceResult>;
32
+ }
33
+ /**
34
+ * The house-style choices for a picker: each one-of-a-kind group with the skill that applies
35
+ * and its options, in `scope` when given. Re-reads when the resolver notifies, so a choice an
36
+ * agent makes with `choose_style` shows at once. Parity with Svelte's `useStyleChoices`.
37
+ */
38
+ export declare function useStyleChoices(styles: StyleResolver | null | undefined, scope?: string): UseStyleChoicesResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.201.1",
3
+ "version": "0.202.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -283,7 +283,7 @@
283
283
  "dependencies": {},
284
284
  "peerDependencies": {
285
285
  "@dagrejs/dagre": "^1.1.8",
286
- "@pixerate/editor": ">=0.294.0 <1.0.0-0",
286
+ "@pixerate/editor": ">=0.299.0 <1.0.0-0",
287
287
  "@tiptap/core": "^2.27.3",
288
288
  "@tiptap/extension-bubble-menu": "^2.27.3",
289
289
  "@tiptap/extension-placeholder": "^2.27.3",
@@ -334,7 +334,7 @@
334
334
  "tsup": "^9.0.0",
335
335
  "typescript": "^5.7.3",
336
336
  "vitest": "^5.1.0",
337
- "@pixerate/editor": "0.294.0"
337
+ "@pixerate/editor": "0.299.0"
338
338
  },
339
339
  "scripts": {
340
340
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",