@pixerate/editor-svelte 0.100.1 → 0.101.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.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./fileImport.svelte.js";
15
15
  export * from "./docxExport.svelte.js";
16
16
  export * from "./agentTools.svelte.js";
17
17
  export * from "./toolBridge.svelte.js";
18
+ export * from "./toolRegistryView.svelte.js";
18
19
  export * from "./outline.svelte.js";
19
20
  export * from "./merge.svelte.js";
20
21
  export { DirtyTracker, createDirtyTracker, defaultIsEqual, HistoryManager, createHistoryManager, bindDirtyToHistory, withoutDirty, } from "@pixerate/editor";
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export * from "./fileImport.svelte.js";
6
6
  export * from "./docxExport.svelte.js";
7
7
  export * from "./agentTools.svelte.js";
8
8
  export * from "./toolBridge.svelte.js";
9
+ export * from "./toolRegistryView.svelte.js";
9
10
  export * from "./outline.svelte.js";
10
11
  export * from "./merge.svelte.js";
11
12
  export { DirtyTracker, createDirtyTracker, defaultIsEqual, HistoryManager, createHistoryManager, bindDirtyToHistory, withoutDirty, } from "@pixerate/editor";
@@ -1,4 +1,4 @@
1
- import { type ConnectToolBridgeOptions, type ToolBridgeStatus, type ToolRegistry } from "@pixerate/editor/tools";
1
+ import { type ConnectToolBridgeOptions, type ToolBridgeStatus, type ToolSource } from "@pixerate/editor/tools";
2
2
  type MaybeGetter<T> = T | (() => T);
3
3
  export interface SvelteToolBridge {
4
4
  /** "off" while no options are given (reactive). */
@@ -9,9 +9,9 @@ export interface SvelteToolBridge {
9
9
  readonly editorId: string | null;
10
10
  }
11
11
  /**
12
- * Connects a `ToolRegistry` to a local MCP bridge (`pixerate-mcp-bridge`) for the lifetime of
12
+ * Connects a `ToolRegistry` (or a view of one, see `useToolRegistryView`) to a local MCP bridge (`pixerate-mcp-bridge`) for the lifetime of
13
13
  * the calling component, so an MCP client can call the page's tools. Pass getters to react to
14
14
  * changes; `null` options stay disconnected. Parity with React's `useToolBridge`.
15
15
  */
16
- export declare function useToolBridge(registry: MaybeGetter<ToolRegistry | null | undefined>, options: MaybeGetter<ConnectToolBridgeOptions | null>): SvelteToolBridge;
16
+ export declare function useToolBridge(registry: MaybeGetter<ToolSource | null | undefined>, options: MaybeGetter<ConnectToolBridgeOptions | null>): SvelteToolBridge;
17
17
  export {};
@@ -1,7 +1,7 @@
1
1
  import { connectToolBridge } from "@pixerate/editor/tools";
2
2
  const read = (value) => (typeof value === "function" ? value() : value);
3
3
  /**
4
- * Connects a `ToolRegistry` to a local MCP bridge (`pixerate-mcp-bridge`) for the lifetime of
4
+ * Connects a `ToolRegistry` (or a view of one, see `useToolRegistryView`) to a local MCP bridge (`pixerate-mcp-bridge`) for the lifetime of
5
5
  * the calling component, so an MCP client can call the page's tools. Pass getters to react to
6
6
  * changes; `null` options stay disconnected. Parity with React's `useToolBridge`.
7
7
  */
@@ -0,0 +1,16 @@
1
+ import type { ToolRegistry, ToolRegistryView, ToolViewOptions } from "@pixerate/editor/tools";
2
+ type MaybeGetter<T> = T | (() => T);
3
+ export interface SvelteToolRegistryView {
4
+ /** The view, or `null` while there is no registry (reactive). */
5
+ readonly view: ToolRegistryView | null;
6
+ }
7
+ /**
8
+ * A `registry.view(options)` for the lifetime of the calling component: serve it with
9
+ * `useToolBridge` or `createMcpServer` instead of the registry to show an agent only some
10
+ * toolsets, only read tools, or a discovery surface (`discovery`). Pass getters to react to
11
+ * changes: a new `toolsets` value (e.g. the focused editor's) updates the same view and
12
+ * announces the new tool list; a new registry, `readOnly` or `discovery` makes a new view.
13
+ * Parity with React's `useToolRegistryView`.
14
+ */
15
+ export declare function useToolRegistryView(registry: MaybeGetter<ToolRegistry | null | undefined>, options?: MaybeGetter<ToolViewOptions>): SvelteToolRegistryView;
16
+ export {};
@@ -0,0 +1,37 @@
1
+ const read = (value) => (typeof value === "function" ? value() : value);
2
+ /**
3
+ * A `registry.view(options)` for the lifetime of the calling component: serve it with
4
+ * `useToolBridge` or `createMcpServer` instead of the registry to show an agent only some
5
+ * toolsets, only read tools, or a discovery surface (`discovery`). Pass getters to react to
6
+ * changes: a new `toolsets` value (e.g. the focused editor's) updates the same view and
7
+ * announces the new tool list; a new registry, `readOnly` or `discovery` makes a new view.
8
+ * Parity with React's `useToolRegistryView`.
9
+ */
10
+ export function useToolRegistryView(registry, options = {}) {
11
+ let view = $state.raw(null);
12
+ // Plain (untracked) copies, so the effect never reads the state it writes.
13
+ let current = null;
14
+ let made = null;
15
+ $effect(() => {
16
+ const currentRegistry = read(registry);
17
+ const { readOnly, discovery, toolsets } = read(options);
18
+ if (current && made && made.registry === currentRegistry && made.readOnly === readOnly && made.discovery === discovery) {
19
+ current.setToolsets(toolsets);
20
+ return;
21
+ }
22
+ current?.dispose();
23
+ made = currentRegistry ? { registry: currentRegistry, readOnly, discovery } : null;
24
+ current = currentRegistry ? currentRegistry.view({ readOnly, discovery, toolsets }) : null;
25
+ view = current;
26
+ });
27
+ $effect(() => () => {
28
+ current?.dispose();
29
+ current = null;
30
+ made = null;
31
+ });
32
+ return {
33
+ get view() {
34
+ return view;
35
+ },
36
+ };
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.100.1",
3
+ "version": "0.101.0",
4
4
  "description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -144,7 +144,7 @@
144
144
  "@tiptap/extension-bubble-menu": "^2.11.5",
145
145
  "@tiptap/extension-placeholder": "^2.11.5",
146
146
  "@tiptap/starter-kit": "^2.11.5",
147
- "@pixerate/editor": "0.139.1"
147
+ "@pixerate/editor": "0.140.0"
148
148
  },
149
149
  "peerDependencies": {
150
150
  "@dagrejs/dagre": "^1.1.4",