@tailorkit/react 0.1.0-beta.18 → 0.1.0-beta.19

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.
@@ -3,7 +3,7 @@ export interface PreviewSnapshot {
3
3
  revision: number;
4
4
  source: string | null;
5
5
  }
6
- export declare function createPreviewManager(baseUrl: URL, onEnded: () => void): {
6
+ export declare function createPreviewManager(baseUrl: URL, onEnded: () => void, onViews?: (appId: string, views: NonNullable<TailorKitApp["views"]>) => void): {
7
7
  getSnapshot: (sessionId: string) => PreviewSnapshot;
8
8
  updateApp: (app: TailorKitApp) => void;
9
9
  subscribe: (app: TailorKitApp, listener: () => void) => (() => void);
@@ -0,0 +1,22 @@
1
+ import type { ActiveView } from "@tailorkit/core/views";
2
+ import type { TailorKitSchemaSpecType } from "@tailorkit/core/spec";
3
+ import type { TailorKitApp } from "./tailorkit";
4
+ /** Select the supported view without reading or composing its context. */
5
+ export declare function selectSlotView(views: NonNullable<TailorKitApp["views"]>, slot: string, activePath: string, schema: TailorKitSchemaSpecType): {
6
+ slot: string;
7
+ path: string;
8
+ instances?: true;
9
+ disabled?: true;
10
+ } | null;
11
+ /** Match the same path and compose the same ancestor context as the sandbox renderer. */
12
+ export declare function resolveSlotView(views: NonNullable<TailorKitApp["views"]>, slot: string, activeView: ActiveView, schema: TailorKitSchemaSpecType): {
13
+ view: string;
14
+ status: "ready";
15
+ context: Record<string, unknown>;
16
+ instances: boolean;
17
+ } | {
18
+ view: string;
19
+ status: "loading" | "error";
20
+ context?: never;
21
+ instances: boolean;
22
+ } | null;
package/dist/store.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import type { TailorKitSchemaSpecType } from "@tailorkit/core/spec";
2
- import type { TailorKitApp } from "./tailorkit";
2
+ import type { TailorKitApp, TailorKitView } from "./tailorkit";
3
3
  export interface TailorKitAppsSnapshot {
4
4
  apps: TailorKitApp[];
5
+ views: TailorKitView[];
5
6
  error: Error | null;
6
7
  status: "error" | "idle" | "loading" | "ready";
7
8
  }
@@ -23,13 +24,14 @@ export declare function createTailorKitStore(baseUrlInput: string | URL, initial
23
24
  setProvidedApps(apps: TailorKitApp[] | undefined): void;
24
25
  fetchApps: (options?: {
25
26
  force?: boolean;
26
- scopes?: readonly string[];
27
27
  }) => Promise<void>;
28
- fetchMeta: () => Promise<void>;
29
- getAppsSnapshot: (scopes?: readonly string[]) => TailorKitAppsSnapshot;
28
+ fetchMeta: (options?: {
29
+ force?: boolean;
30
+ }) => Promise<void>;
31
+ getAppsSnapshot: () => TailorKitAppsSnapshot;
30
32
  getMetaSnapshot: () => TailorKitMetaSnapshot;
31
33
  subscribe: (listener: () => void) => (() => void);
32
- subscribeApps: (scopes: readonly string[] | undefined, listener: () => void) => (() => void);
34
+ subscribeApps: (listener: () => void) => (() => void);
33
35
  previews: {
34
36
  getSnapshot: (sessionId: string) => import("./preview-manager").PreviewSnapshot;
35
37
  updateApp: (app: TailorKitApp) => void;
@@ -1,8 +1,11 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { TailorKitTheme, CallbackMap, ComponentDefinition, ComponentProps, Schema, ViewDefinition, SlotDefinitions, TailorKitSchema } from "@tailorkit/core/schema";
3
3
  import type { primitives } from "./primitives";
4
- import type { UseView, ViewName, ViewOptions } from "./hooks/use-view";
4
+ import type { UseRegisterView } from "./hooks/use-register-view";
5
5
  import type { UseAppsOptions, UseAppsResult } from "./hooks/use-apps";
6
+ import type { UseViewsOptions, UseViewsResult } from "./hooks/use-views";
7
+ import type { UseSlotInstancesOptions, UseSlotInstancesResult } from "./hooks/use-slot-instances";
8
+ import type { SlotComponent } from "./components/slot";
6
9
  type AnyComponentDefinition = ComponentDefinition<Schema | undefined, CallbackMap, boolean | undefined>;
7
10
  type ComponentRenderer<TComponent extends AnyComponentDefinition> = (args: {
8
11
  props: ComponentProps<TComponent>;
@@ -17,6 +20,15 @@ type CompleteComponentRenderers<TComponents extends Record<string, AnyComponentD
17
20
  [TName in keyof TComponents]-?: ComponentRenderer<TComponents[TName]>;
18
21
  };
19
22
  export interface TailorKitApp {
23
+ scope?: {
24
+ name: string;
25
+ };
26
+ views?: {
27
+ slot: string;
28
+ path: string;
29
+ instances?: true;
30
+ disabled?: true;
31
+ }[];
20
32
  clientPath?: string;
21
33
  description?: string;
22
34
  id: string;
@@ -36,28 +48,13 @@ export interface TailorKitApp {
36
48
  token: string;
37
49
  };
38
50
  }
39
- interface AppViewBaseProps {
51
+ export interface TailorKitView {
52
+ instances?: true;
53
+ id: string;
40
54
  app: TailorKitApp;
41
- createIframe?: () => HTMLIFrameElement;
42
- fallback?: ReactNode;
55
+ slot: string;
56
+ path: string;
43
57
  }
44
- type AppViewViewProps<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews> = ViewName<TViews>> = [ViewName<TViews>] extends [never] ? {
45
- context?: never;
46
- view?: never;
47
- status?: never;
48
- } : {
49
- context?: never;
50
- view?: never;
51
- status?: never;
52
- } | ViewOptions<TViews, TView>;
53
- export type AppViewProps<TViews extends Record<string, ViewDefinition> = Record<`/${string}`, ViewDefinition>, TView extends ViewName<TViews> = ViewName<TViews>, TSlots extends SlotDefinitions = SlotDefinitions> = {
54
- [V in keyof TSlots & string]: AppViewBaseProps & {
55
- slot: V;
56
- } & AppViewViewProps<TViews, Extract<TView, SlotView<TSlots, V>>>;
57
- }[keyof TSlots & string];
58
- type SlotView<TSlots extends SlotDefinitions, V extends keyof TSlots & string> = TSlots[V] extends {
59
- views: readonly (infer P)[];
60
- } ? Extract<P, string> : never;
61
58
  export interface TailorKitClientConfig {
62
59
  readonly baseUrl: string | URL;
63
60
  readonly components: Record<string, unknown>;
@@ -66,9 +63,11 @@ export interface TailorKitClientConfig {
66
63
  export interface TailorKitInstance<TViews extends Record<string, ViewDefinition> = Record<string, ViewDefinition>, TSlots extends SlotDefinitions = SlotDefinitions, TScopeNames extends string = string> extends TailorKitClientConfig {
67
64
  readonly $slots?: TSlots;
68
65
  readonly $views?: TViews;
69
- readonly AppView: (props: AppViewProps<TViews, ViewName<TViews>, TSlots>) => ReactNode;
66
+ readonly Slot: SlotComponent<TViews, TSlots>;
70
67
  readonly useApps: (options?: UseAppsOptions<TScopeNames>) => UseAppsResult;
71
- readonly useView: UseView<TViews>;
68
+ readonly useViews: (options?: UseViewsOptions<TScopeNames, keyof TSlots & string>) => UseViewsResult;
69
+ readonly useSlotInstances: (options: UseSlotInstancesOptions<keyof TSlots & string>) => UseSlotInstancesResult;
70
+ readonly useRegisterView: UseRegisterView<TViews>;
72
71
  }
73
72
  type PrimitiveRenderers = typeof primitives;
74
73
  type CustomComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>> = {
@@ -107,4 +106,4 @@ export declare function createTailorKitClient<TTailor extends TailorKitServerSha
107
106
  }): TailorKitInstance<ServerViews<TTailor>, TTailor extends {
108
107
  readonly $slots?: infer V extends SlotDefinitions;
109
108
  } ? V : SlotDefinitions, ServerScopeNames<TTailor>>;
110
- export type { ViewOptions } from "./hooks/use-view";
109
+ export type { ViewOptions } from "./hooks/use-register-view";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailorkit/react",
3
- "version": "0.1.0-beta.18",
3
+ "version": "0.1.0-beta.19",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,10 +23,10 @@
23
23
  "dependencies": {
24
24
  "@floating-ui/react-dom": "^2.1.9",
25
25
  "@standard-schema/spec": "^1.1.0",
26
- "@tailorkit/app": "0.1.0-beta.18",
27
- "@tailorkit/client-platform": "0.1.0-beta.18",
28
- "@tailorkit/core": "0.1.0-beta.18",
29
- "@tailorkit/sandbox": "0.1.0-beta.18"
26
+ "@tailorkit/app": "0.1.0-beta.19",
27
+ "@tailorkit/client-platform": "0.1.0-beta.19",
28
+ "@tailorkit/core": "0.1.0-beta.19",
29
+ "@tailorkit/sandbox": "0.1.0-beta.19"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@tailorkit/config": "0.0.0",
@@ -1,3 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { AppViewProps } from "../tailorkit";
3
- export declare const AppView: ({ app, slot, createIframe, fallback, ...viewProps }: AppViewProps) => ReactNode;