@tailorkit/react 0.1.0-beta.25 → 0.1.0-beta.27

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,6 +1,6 @@
1
1
  import type { ViewDefinition } from "@tailorkit/core/schema";
2
2
  import type { ViewName, ViewState } from "@tailorkit/client-core";
3
- export type { ViewName, ViewContext, ViewOptions, ViewState } from "@tailorkit/client-core";
3
+ export type { ViewName, ViewContext, ViewContextInput, ViewOptions, ViewState, } from "@tailorkit/client-core";
4
4
  type DefaultViews = Record<`/${string}`, ViewDefinition>;
5
5
  export type UseViewContext<TViews extends Record<string, ViewDefinition>> = <TView extends ViewName<TViews>>(view: TView, options: ViewState<TViews, NoInfer<TView>>) => void;
6
6
  export declare function useViewContext<TViews extends Record<string, ViewDefinition> = DefaultViews, TView extends ViewName<TViews> = ViewName<TViews>>(view: TView, options: ViewState<TViews, NoInfer<TView>>): void;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { RenderSlot } from "./components/render-slot";
2
2
  export type { ControlledRenderSlotProps, RenderSlotComponent, RenderSlotContext, RenderSlotProps, } from "./components/render-slot";
3
- export { components, createTailorKitClient } from "./tailorkit";
3
+ export { components, createClient } from "./tailorkit";
4
4
  export type { TailorKitApp, TailorKitClientConfig, TailorKitInstance, TailorKitProviderProps, } from "./tailorkit";
5
5
  export type { UseAppsOptions, UseAppsResult } from "./hooks/use-apps";
6
6
  export type { SlotItem, UseViewsOptions, UseViewsResult } from "./hooks/use-views";
package/dist/index.js CHANGED
@@ -74,6 +74,7 @@ var RemoteErrorBoundary = class extends Component {
74
74
  function RemoteViewHost({
75
75
  appUrl,
76
76
  sourceText,
77
+ toolBridge,
77
78
  getBackendSession,
78
79
  components: components2,
79
80
  createIframe,
@@ -89,8 +90,8 @@ function RemoteViewHost({
89
90
  store.setProps(props);
90
91
  }, [props, store]);
91
92
  useEffect(
92
- () => store.mount({ appUrl, sourceText, getBackendSession, createIframe }),
93
- [appUrl, sourceText, getBackendSession, createIframe, store]
93
+ () => store.mount({ appUrl, sourceText, toolBridge, getBackendSession, createIframe }),
94
+ [appUrl, sourceText, toolBridge, getBackendSession, createIframe, store]
94
95
  );
95
96
  if (snapshot.status === "error" && snapshot.error) {
96
97
  return createElement("div", null, formatError(snapshot.error));
@@ -178,6 +179,7 @@ function SlotRenderer(options) {
178
179
  {
179
180
  appUrl: snapshot.appUrl,
180
181
  sourceText: snapshot.sourceText,
182
+ toolBridge: snapshot.toolBridge,
181
183
  getBackendSession: snapshot.getBackendSession,
182
184
  components: client.components,
183
185
  props: snapshot.props
@@ -193,7 +195,7 @@ import {
193
195
  createComponentRegistry,
194
196
  createTailorKitStore
195
197
  } from "@tailorkit/client-core";
196
- import { createElement as createElement2, useEffect as useEffect4, useMemo as useMemo8, useState } from "react";
198
+ import { createElement as createElement2, useEffect as useEffect4, useMemo as useMemo8 } from "react";
197
199
 
198
200
  // src/hooks/use-view-context.ts
199
201
  import { useEffect as useEffect3, useMemo as useMemo4 } from "react";
@@ -254,10 +256,10 @@ function useViews(options) {
254
256
  }
255
257
 
256
258
  // src/tailorkit.tsx
257
- function components(_schema, customComponents) {
259
+ function components(_contract, customComponents) {
258
260
  return customComponents;
259
261
  }
260
- function createTailorKitClient(options) {
262
+ function createClient(options) {
261
263
  return createReactTailorKitClient(options);
262
264
  }
263
265
  function createReactTailorKitClient(options) {
@@ -276,8 +278,16 @@ function createReactTailorKitClient(options) {
276
278
  const client = {
277
279
  ...clientConfig,
278
280
  Provider: function TailorKitProvider({ children, apps }) {
279
- const [store] = useState(
280
- () => createTailorKitStore(client.baseUrl, apps, client.fetchClient)
281
+ const store = useMemo8(
282
+ () => createTailorKitStore({
283
+ baseUrl: client.baseUrl,
284
+ contract: client.contract,
285
+ tools: client.tools,
286
+ apps,
287
+ client: clientConfig.fetchClient,
288
+ assetsBaseUrl: client.assetsBaseUrl
289
+ }),
290
+ []
281
291
  );
282
292
  useEffect4(() => {
283
293
  store.setProvidedApps(apps);
@@ -319,6 +329,6 @@ function createReactTailorKitClient(options) {
319
329
  export {
320
330
  RenderSlot,
321
331
  components,
322
- createTailorKitClient,
332
+ createClient,
323
333
  primitives
324
334
  };
@@ -1,8 +1,10 @@
1
+ import type { ToolBridge } from "@tailorkit/app/client";
1
2
  import type { Session } from "@tailorkit/app/client";
2
3
  import type { ReactNode } from "react";
3
4
  interface RemoteViewHostProps {
4
5
  appUrl: string | URL;
5
6
  sourceText?: string;
7
+ toolBridge?: ToolBridge;
6
8
  getBackendSession?: (options: {
7
9
  refresh: boolean;
8
10
  }) => Promise<Session>;
@@ -10,7 +12,7 @@ interface RemoteViewHostProps {
10
12
  createIframe?: () => HTMLIFrameElement;
11
13
  props?: Record<string, unknown>;
12
14
  }
13
- export declare function RemoteViewHost({ appUrl, sourceText, getBackendSession, components, createIframe, props, }: RemoteViewHostProps): ReactNode;
15
+ export declare function RemoteViewHost({ appUrl, sourceText, toolBridge, getBackendSession, components, createIframe, props, }: RemoteViewHostProps): ReactNode;
14
16
  interface RemoteViewProps {
15
17
  nodeId: string;
16
18
  }
@@ -1,8 +1,8 @@
1
- import type { AnyComponentDefinition, ComponentRenderer, ComponentRenderers, CompleteComponentRenderers, TailorKitClientConfig, TailorKitApp, TailorKitServerShape, ServerComponents, ServerViews, ServerSlots, ServerScopeNames, SlotMultiple } from "@tailorkit/client-core";
1
+ import type { AnyComponentDefinition, ComponentRenderer, ComponentRenderers, CompleteComponentRenderers, TailorKitClientConfig, TailorKitApp, SlotMultiple } from "@tailorkit/client-core";
2
2
  export type { TailorKitClientConfig } from "@tailorkit/client-core";
3
3
  import type { TailorKitCacheOptions } from "@tailorkit/client-core";
4
4
  import type { ReactNode } from "react";
5
- import type { TailorKitTheme, ViewDefinition, SlotDefinitions, TailorKitSchema } from "@tailorkit/core/schema";
5
+ import type { TailorKitTheme, ViewDefinition, SlotDefinitions, TailorKitContract, ToolImplementations } from "@tailorkit/core/schema";
6
6
  import type { primitives } from "./primitives";
7
7
  import type { UseViewContext } from "./hooks/use-view-context";
8
8
  import type { UseAppsOptions, UseAppsResult } from "./hooks/use-apps";
@@ -26,12 +26,21 @@ type PrimitiveRenderers = typeof primitives;
26
26
  type CustomComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>> = {
27
27
  [TName in Exclude<keyof TComponents, keyof PrimitiveRenderers>]?: ComponentRenderer<TComponents[TName], ReactNode>;
28
28
  };
29
- export declare function components<TComponents extends Record<string, AnyComponentDefinition>>(_schema: TailorKitSchema<TComponents, Record<string, ViewDefinition>>, customComponents: CustomComponentRenderers<TComponents>): ComponentRenderers<TComponents, ReactNode>;
30
- export declare function createTailorKitClient<TTailor extends TailorKitServerShape>(options: {
29
+ export declare function components<TComponents extends Record<string, AnyComponentDefinition>>(_contract: {
30
+ components: TComponents;
31
+ }, customComponents: CustomComponentRenderers<TComponents>): ComponentRenderers<TComponents, ReactNode>;
32
+ export declare function createClient<const TContract extends TailorKitContract>(options: {
33
+ contract: TContract;
34
+ tools?: ToolImplementations<NoInfer<TContract["tools"]>, "client">;
31
35
  baseUrl: string | URL;
32
- components?: CompleteComponentRenderers<ServerComponents<TTailor>, ReactNode>;
36
+ assetsBaseUrl?: string | URL;
37
+ components?: CompleteComponentRenderers<NoInfer<TContract["components"]>, ReactNode>;
33
38
  theme?: TailorKitTheme;
34
39
  cache?: TailorKitCacheOptions;
35
40
  fetch?: typeof fetch;
36
- }): TailorKitInstance<ServerViews<TTailor>, ServerSlots<TTailor>, ServerScopeNames<TTailor>>;
41
+ } & (keyof ToolImplementations<TContract["tools"], "client"> extends never ? {
42
+ tools?: ToolImplementations<TContract["tools"], "client">;
43
+ } : {
44
+ tools: ToolImplementations<TContract["tools"], "client">;
45
+ })): TailorKitInstance<TContract["views"], TContract["slots"], keyof TContract["scopes"] & string>;
37
46
  export type { ViewOptions } from "./hooks/use-view-context";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailorkit/react",
3
- "version": "0.1.0-beta.25",
3
+ "version": "0.1.0-beta.27",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,11 +24,11 @@
24
24
  "@floating-ui/react-dom": "^2.1.9",
25
25
  "@nanostores/react": "2.0.1",
26
26
  "@standard-schema/spec": "^1.1.0",
27
- "@tailorkit/app": "0.1.0-beta.25",
28
- "@tailorkit/client-core": "0.1.0-beta.25",
29
- "@tailorkit/client-platform": "0.1.0-beta.25",
30
- "@tailorkit/core": "0.1.0-beta.25",
31
- "@tailorkit/sandbox": "0.1.0-beta.25",
27
+ "@tailorkit/app": "0.1.0-beta.27",
28
+ "@tailorkit/client-core": "0.1.0-beta.27",
29
+ "@tailorkit/client-platform": "0.1.0-beta.27",
30
+ "@tailorkit/core": "0.1.0-beta.27",
31
+ "@tailorkit/sandbox": "0.1.0-beta.27",
32
32
  "nanostores": "1.5.4"
33
33
  },
34
34
  "devDependencies": {