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

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # TailorKit React
2
+
3
+ React components and hooks for integrating TailorKit into your SaaS.
@@ -1,4 +1,4 @@
1
- import type { TailorKitStore } from "../store";
1
+ import type { TailorKitStore } from "@tailorkit/client-core";
2
2
  import type { TailorKitClientConfig } from "../tailorkit";
3
3
  export interface TailorRootContextValue {
4
4
  store: TailorKitStore;
@@ -1,7 +1,7 @@
1
+ import type { ViewInstance } from "@tailorkit/app/client";
1
2
  import type { SlotDefinitions, ViewDefinition } from "@tailorkit/core/schema";
2
3
  import type { ReactNode } from "react";
3
4
  import type { ViewContext, ViewName } from "../hooks/use-register-view";
4
- import type { SlotInstance } from "../hooks/use-slot-instances";
5
5
  import type { TailorKitApp } from "../tailorkit";
6
6
  type DefaultViews = Record<`/${string}`, ViewDefinition>;
7
7
  type ContextPaths<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> = {
@@ -11,24 +11,33 @@ type ContextFields<TView> = undefined extends ViewContext<TView> ? Partial<Exclu
11
11
  export type SlotContext<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> = {
12
12
  [P in ContextPaths<TViews, TView>]: (context: ContextFields<TViews[P]>) => void;
13
13
  }[ContextPaths<TViews, TView>] extends (context: infer TContext) => void ? TContext : never;
14
- export interface SlotProps<TSlots extends SlotDefinitions = SlotDefinitions> {
15
- app: TailorKitApp;
16
- /** The host slot to render in. */
17
- name: keyof TSlots & string;
18
- /** Select an instance of the matching view. */
19
- instanceKey?: string;
20
- }
14
+ type InstanceProps<TSlot, TKey extends string, TValue> = boolean extends (TSlot extends {
15
+ multiple?: infer T;
16
+ } ? T : false) ? {
17
+ [K in TKey]?: TValue;
18
+ } : TSlot extends {
19
+ multiple: true;
20
+ } ? {
21
+ [K in TKey]: TValue;
22
+ } : {
23
+ [K in TKey]?: never;
24
+ };
25
+ export type SlotProps<TSlots extends SlotDefinitions = SlotDefinitions> = {
26
+ [TSlot in keyof TSlots & string]: {
27
+ app: TailorKitApp;
28
+ name: TSlot;
29
+ } & InstanceProps<TSlots[TSlot], "instanceKey", string>;
30
+ }[keyof TSlots & string];
21
31
  export type ControlledSlotProps<TViews extends Record<string, ViewDefinition> = DefaultViews, TSlots extends SlotDefinitions = SlotDefinitions> = {
22
32
  [TSlot in keyof TSlots & string]: {
23
33
  [TView in Extract<ViewName<TViews>, TSlots[TSlot]["views"][number]>]: {
24
34
  app: TailorKitApp;
25
35
  name: TSlot;
26
36
  view: TView;
27
- } & ({
37
+ } & (({
28
38
  context: SlotContext<TViews, TView>;
29
39
  status: "ready";
30
- instance?: SlotInstance;
31
- } | {
40
+ } & InstanceProps<TSlots[TSlot], "instance", ViewInstance>) | {
32
41
  context?: never;
33
42
  status: "loading" | "error";
34
43
  instance?: never;
@@ -1,12 +1,13 @@
1
1
  import type { TailorKitApp } from "../tailorkit";
2
- import type { TailorKitAppsSnapshot, TailorKitStore } from "../store";
3
- export interface UseAppsOptions<TScopeNames extends string = string> {
2
+ import type { FetchCacheOptions, TailorKitAppsSnapshot, TailorKitStore } from "@tailorkit/client-core";
3
+ export interface UseAppsOptions<TScopeNames extends string = string> extends Pick<FetchCacheOptions, "staleTime"> {
4
4
  scopes?: readonly TScopeNames[];
5
5
  appIds?: readonly string[];
6
6
  }
7
7
  export interface UseAppsResult {
8
8
  data: TailorKitApp[] | undefined;
9
9
  error: Error | null;
10
+ isFetching: boolean;
10
11
  isError: boolean;
11
12
  isLoading: boolean;
12
13
  isPending: boolean;
@@ -16,6 +17,6 @@ export interface UseAppsResult {
16
17
  }
17
18
  export declare function useApps(options?: UseAppsOptions): UseAppsResult;
18
19
  export declare function useAppsStore(store: TailorKitStore, options?: UseAppsOptions): UseAppsResult;
19
- export declare function matchesApp(app: TailorKitApp, scopes?: readonly string[], appIds?: readonly string[]): boolean;
20
- export declare function useAppsSnapshot(store: TailorKitStore): TailorKitAppsSnapshot;
20
+ export { matchesApp } from "@tailorkit/client-core";
21
+ export declare function useAppsSnapshot(store: TailorKitStore, options?: Pick<FetchCacheOptions, "staleTime">): TailorKitAppsSnapshot;
21
22
  export declare function toUseAppsResult(snapshot: TailorKitAppsSnapshot, refetch: () => Promise<void>): UseAppsResult;
@@ -1,13 +1,13 @@
1
- import type { ViewInstance } from "@tailorkit/app/client";
2
- import type { TailorKitApp } from "../tailorkit";
1
+ import type { FetchCacheOptions, TailorKitApp, SlotInstance } from "@tailorkit/client-core";
3
2
  import type { UseAppsResult } from "./use-apps";
4
- export type SlotInstance = ViewInstance;
5
- export interface UseSlotInstancesOptions<TSlot extends string = string> {
6
- app: TailorKitApp;
3
+ export type { SlotInstance } from "@tailorkit/client-core";
4
+ export interface UseSlotInstancesOptions<TSlot extends string = string> extends FetchCacheOptions {
7
5
  slot: TSlot;
8
6
  }
9
7
  export interface UseSlotInstancesResult extends Omit<UseAppsResult, "data"> {
10
8
  data: SlotInstance[] | undefined;
11
9
  }
12
- /** Fetch instances for the app's matching slot view using registered host context. */
13
- export declare function useSlotInstances({ app, slot }: UseSlotInstancesOptions): UseSlotInstancesResult;
10
+ /** Resolve instances across discovered apps while sharing endpoint state in client-core. */
11
+ export declare function useSlotInstances({ slot, staleTime, gcTime, }: UseSlotInstancesOptions): UseSlotInstancesResult;
12
+ /** Managed Slot resolves only its explicitly supplied app. */
13
+ export declare function useAppSlotInstances(app: TailorKitApp, slot: string): UseSlotInstancesResult;