@pixerate/editor-svelte 0.218.0 → 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.
@@ -1,3 +1,4 @@
1
+ import type { Editor } from "@tiptap/core";
1
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 {
@@ -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;
@@ -54,4 +55,10 @@ export interface SvelteStyleSwatches {
54
55
  * agent's `get_style` returns the same list. Parity with React's `useStyleSwatches`.
55
56
  */
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;
57
64
  export {};
@@ -1,4 +1,5 @@
1
1
  import { styleSwatches } from "@pixerate/editor/tools";
2
+ import { richTextStyleState } from "@pixerate/editor";
2
3
  const read = (value) => (typeof value === "function" ? value() : value);
3
4
  const message = (error) => (error instanceof Error ? error.message : String(error));
4
5
  /**
@@ -59,11 +60,11 @@ export function useStyle(styles, domain) {
59
60
  * the resolver notifies. Results of older runs that settle late are ignored. Feed `report` to
60
61
  * `<StyleFindings>`. Call it during component initialisation. Parity with React's `useStyleFindings`.
61
62
  */
62
- export function useStyleFindings(styles, domain, subject) {
63
+ export function useStyleFindings(styles, domain, subject, scope) {
63
64
  let report = $state.raw(null);
64
65
  let style = $state.raw(null);
65
66
  let error = $state.raw(null);
66
- 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) => {
67
68
  if (!result.value) {
68
69
  report = null;
69
70
  style = null;
@@ -149,3 +150,28 @@ export function useStyleSwatches(styles, domain, scope) {
149
150
  },
150
151
  };
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.218.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.301.0"
187
+ "@pixerate/editor": "0.302.0"
188
188
  },
189
189
  "peerDependencies": {
190
190
  "@dagrejs/dagre": "^1.1.4",