@tailorkit/react 0.1.0-beta.25 → 0.1.0-beta.26
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/hooks/use-view-context.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -12
- package/dist/remote-view.d.ts +3 -1
- package/dist/tailorkit.d.ts +17 -6
- package/package.json +6 -6
|
@@ -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,
|
|
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
|
|
@@ -191,9 +193,10 @@ function SlotRenderer(options) {
|
|
|
191
193
|
import {
|
|
192
194
|
createTailorKitClientConfig,
|
|
193
195
|
createComponentRegistry,
|
|
194
|
-
createTailorKitStore
|
|
196
|
+
createTailorKitStore,
|
|
197
|
+
createTailorKitFetchClient
|
|
195
198
|
} from "@tailorkit/client-core";
|
|
196
|
-
import { createElement as createElement2, useEffect as useEffect4, useMemo as useMemo8
|
|
199
|
+
import { createElement as createElement2, useEffect as useEffect4, useMemo as useMemo8 } from "react";
|
|
197
200
|
|
|
198
201
|
// src/hooks/use-view-context.ts
|
|
199
202
|
import { useEffect as useEffect3, useMemo as useMemo4 } from "react";
|
|
@@ -254,10 +257,10 @@ function useViews(options) {
|
|
|
254
257
|
}
|
|
255
258
|
|
|
256
259
|
// src/tailorkit.tsx
|
|
257
|
-
function components(
|
|
260
|
+
function components(_contract, customComponents) {
|
|
258
261
|
return customComponents;
|
|
259
262
|
}
|
|
260
|
-
function
|
|
263
|
+
function createClient(options) {
|
|
261
264
|
return createReactTailorKitClient(options);
|
|
262
265
|
}
|
|
263
266
|
function createReactTailorKitClient(options) {
|
|
@@ -273,18 +276,37 @@ function createReactTailorKitClient(options) {
|
|
|
273
276
|
};
|
|
274
277
|
});
|
|
275
278
|
const clientConfig = createTailorKitClientConfig({ ...options, components: wrappedComponents });
|
|
279
|
+
const subjectClients = /* @__PURE__ */ new Map();
|
|
280
|
+
subjectClients.set(void 0, clientConfig.fetchClient);
|
|
276
281
|
const client = {
|
|
277
282
|
...clientConfig,
|
|
278
|
-
Provider: function TailorKitProvider({ children, apps }) {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
283
|
+
Provider: function TailorKitProvider({ children, apps, subjectId }) {
|
|
284
|
+
const store = useMemo8(() => {
|
|
285
|
+
let fetchClient = subjectClients.get(subjectId);
|
|
286
|
+
if (!fetchClient) {
|
|
287
|
+
fetchClient = createTailorKitFetchClient({ ...options });
|
|
288
|
+
fetchClient.endpoints.setSubject(subjectId);
|
|
289
|
+
subjectClients.set(subjectId, fetchClient);
|
|
290
|
+
}
|
|
291
|
+
return createTailorKitStore({
|
|
292
|
+
baseUrl: client.baseUrl,
|
|
293
|
+
contract: client.contract,
|
|
294
|
+
tools: client.tools,
|
|
295
|
+
apps,
|
|
296
|
+
client: fetchClient,
|
|
297
|
+
assetsBaseUrl: client.assetsBaseUrl
|
|
298
|
+
});
|
|
299
|
+
}, [subjectId]);
|
|
282
300
|
useEffect4(() => {
|
|
283
301
|
store.setProvidedApps(apps);
|
|
284
302
|
}, [store, apps]);
|
|
285
303
|
useEffect4(() => () => store.previews.dispose(), [store]);
|
|
286
304
|
const context = useMemo8(() => ({ store, client }), [store]);
|
|
287
|
-
return createElement2(
|
|
305
|
+
return createElement2(
|
|
306
|
+
TailorkitContext.Provider,
|
|
307
|
+
{ value: context, key: subjectId ?? "installation" },
|
|
308
|
+
children
|
|
309
|
+
);
|
|
288
310
|
},
|
|
289
311
|
RenderSlot: Object.assign(
|
|
290
312
|
function ClientRenderSlot(props) {
|
|
@@ -319,6 +341,6 @@ function createReactTailorKitClient(options) {
|
|
|
319
341
|
export {
|
|
320
342
|
RenderSlot,
|
|
321
343
|
components,
|
|
322
|
-
|
|
344
|
+
createClient,
|
|
323
345
|
primitives
|
|
324
346
|
};
|
package/dist/remote-view.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/tailorkit.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AnyComponentDefinition, ComponentRenderer, ComponentRenderers, CompleteComponentRenderers, TailorKitClientConfig, TailorKitApp,
|
|
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,
|
|
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";
|
|
@@ -11,6 +11,8 @@ import type { RenderSlotComponent } from "./components/render-slot";
|
|
|
11
11
|
export type { TailorKitApp } from "@tailorkit/client-core";
|
|
12
12
|
export interface TailorKitProviderProps {
|
|
13
13
|
apps?: TailorKitApp[];
|
|
14
|
+
/** Cache partition for the authenticated product principal. */
|
|
15
|
+
subjectId?: string;
|
|
14
16
|
children?: ReactNode;
|
|
15
17
|
}
|
|
16
18
|
export interface TailorKitInstance<TViews extends Record<string, ViewDefinition> = Record<string, ViewDefinition>, TSlots extends SlotDefinitions = SlotDefinitions, TScopeNames extends string = string> extends TailorKitClientConfig {
|
|
@@ -26,12 +28,21 @@ type PrimitiveRenderers = typeof primitives;
|
|
|
26
28
|
type CustomComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>> = {
|
|
27
29
|
[TName in Exclude<keyof TComponents, keyof PrimitiveRenderers>]?: ComponentRenderer<TComponents[TName], ReactNode>;
|
|
28
30
|
};
|
|
29
|
-
export declare function components<TComponents extends Record<string, AnyComponentDefinition>>(
|
|
30
|
-
|
|
31
|
+
export declare function components<TComponents extends Record<string, AnyComponentDefinition>>(_contract: {
|
|
32
|
+
components: TComponents;
|
|
33
|
+
}, customComponents: CustomComponentRenderers<TComponents>): ComponentRenderers<TComponents, ReactNode>;
|
|
34
|
+
export declare function createClient<const TContract extends TailorKitContract>(options: {
|
|
35
|
+
contract: TContract;
|
|
36
|
+
tools?: ToolImplementations<NoInfer<TContract["tools"]>, "client">;
|
|
31
37
|
baseUrl: string | URL;
|
|
32
|
-
|
|
38
|
+
assetsBaseUrl?: string | URL;
|
|
39
|
+
components?: CompleteComponentRenderers<NoInfer<TContract["components"]>, ReactNode>;
|
|
33
40
|
theme?: TailorKitTheme;
|
|
34
41
|
cache?: TailorKitCacheOptions;
|
|
35
42
|
fetch?: typeof fetch;
|
|
36
|
-
}
|
|
43
|
+
} & (keyof ToolImplementations<TContract["tools"], "client"> extends never ? {
|
|
44
|
+
tools?: ToolImplementations<TContract["tools"], "client">;
|
|
45
|
+
} : {
|
|
46
|
+
tools: ToolImplementations<TContract["tools"], "client">;
|
|
47
|
+
})): TailorKitInstance<TContract["views"], TContract["slots"], keyof TContract["scopes"] & string>;
|
|
37
48
|
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.
|
|
3
|
+
"version": "0.1.0-beta.26",
|
|
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.
|
|
28
|
-
"@tailorkit/client-core": "0.1.0-beta.
|
|
29
|
-
"@tailorkit/client-platform": "0.1.0-beta.
|
|
30
|
-
"@tailorkit/core": "0.1.0-beta.
|
|
31
|
-
"@tailorkit/sandbox": "0.1.0-beta.
|
|
27
|
+
"@tailorkit/app": "0.1.0-beta.26",
|
|
28
|
+
"@tailorkit/client-core": "0.1.0-beta.26",
|
|
29
|
+
"@tailorkit/client-platform": "0.1.0-beta.26",
|
|
30
|
+
"@tailorkit/core": "0.1.0-beta.26",
|
|
31
|
+
"@tailorkit/sandbox": "0.1.0-beta.26",
|
|
32
32
|
"nanostores": "1.5.4"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|