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

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,8 +1,8 @@
1
1
  import type { TailorKitStore } from "@tailorkit/client-core";
2
2
  import type { TailorKitClientConfig } from "../tailorkit";
3
- export interface TailorRootContextValue {
3
+ export interface TailorkitContextValue {
4
4
  store: TailorKitStore;
5
5
  client: TailorKitClientConfig;
6
6
  }
7
- export declare const TailorRootContext: import("react").Context<TailorRootContextValue | null>;
8
- export declare function useTailorRootContext(component: string, expectedClient?: TailorKitClientConfig): TailorRootContextValue;
7
+ export declare const TailorkitContext: import("react").Context<TailorkitContextValue | null>;
8
+ export declare function useTailorkitContext(component: string, expectedClient?: TailorKitClientConfig): TailorkitContextValue;
@@ -1,2 +1 @@
1
- export { Root } from "./root";
2
- export { Slot } from "./slot";
1
+ export { RenderSlot } from "./render-slot";
@@ -0,0 +1,9 @@
1
+ import type { ControlledRenderSlotProps, RenderSlotProps } from "@tailorkit/client-core";
2
+ import type { SlotDefinitions, ViewDefinition } from "@tailorkit/core/schema";
3
+ import type { ReactNode } from "react";
4
+ export type { ControlledRenderSlotProps, RenderSlotProps, RenderSlotContext, } from "@tailorkit/client-core";
5
+ type DefaultViews = Record<`/${string}`, ViewDefinition>;
6
+ export type RenderSlotComponent<TViews extends Record<string, ViewDefinition> = DefaultViews, TSlots extends SlotDefinitions = SlotDefinitions> = ((props: RenderSlotProps<TSlots>) => ReactNode) & {
7
+ Controlled: (props: ControlledRenderSlotProps<TViews, TSlots>) => ReactNode;
8
+ };
9
+ export declare const RenderSlot: RenderSlotComponent;
@@ -1,22 +1,6 @@
1
- import type { TailorKitApp } from "../tailorkit";
2
- import type { TailorKitAppsSnapshot, TailorKitStore } from "@tailorkit/client-core";
3
- export interface UseAppsOptions<TScopeNames extends string = string> {
4
- scopes?: readonly TScopeNames[];
5
- appIds?: readonly string[];
6
- }
7
- export interface UseAppsResult {
8
- data: TailorKitApp[] | undefined;
9
- error: Error | null;
10
- isFetching: boolean;
11
- isError: boolean;
12
- isLoading: boolean;
13
- isPending: boolean;
14
- isSuccess: boolean;
15
- refetch: () => Promise<void>;
16
- status: "error" | "idle" | "loading" | "ready";
17
- }
1
+ import type { AppsQueryOptions, TailorKitApp, TailorKitStore } from "@tailorkit/client-core";
2
+ import type { UseQueryResult } from "./use-query-result";
3
+ export type UseAppsOptions<TScopeNames extends string = string> = AppsQueryOptions<TScopeNames>;
4
+ export type UseAppsResult = UseQueryResult<TailorKitApp[]>;
18
5
  export declare function useApps(options?: UseAppsOptions): UseAppsResult;
19
6
  export declare function useAppsStore(store: TailorKitStore, options?: UseAppsOptions): UseAppsResult;
20
- export { matchesApp } from "@tailorkit/client-core";
21
- export declare function useAppsSnapshot(store: TailorKitStore): TailorKitAppsSnapshot;
22
- export declare function toUseAppsResult(snapshot: TailorKitAppsSnapshot, refetch: () => Promise<void>): UseAppsResult;
@@ -0,0 +1,9 @@
1
+ import type { QueryResult } from "@tailorkit/client-core";
2
+ import type { ReadableAtom } from "nanostores";
3
+ export type UseQueryResult<T> = Pick<QueryResult<T>, "data" | "isPending" | "error"> & {
4
+ /** Whether a background fetch is running after the initial pending state. */
5
+ isRefetching: boolean;
6
+ /** Fetch fresh data, bypassing the cache's freshness window. */
7
+ fetch: () => Promise<void>;
8
+ };
9
+ export declare function useQueryResult<T>(state: ReadableAtom<QueryResult<T>>): UseQueryResult<T>;
@@ -1,25 +1,6 @@
1
- import type { StandardJSONSchemaV1 } from "@standard-schema/spec";
2
1
  import type { ViewDefinition } from "@tailorkit/core/schema";
2
+ import type { ViewName, ViewState } from "@tailorkit/client-core";
3
+ export type { ViewName, ViewContext, ViewOptions, ViewState } from "@tailorkit/client-core";
3
4
  type DefaultViews = Record<`/${string}`, ViewDefinition>;
4
- export type ViewName<TViews extends Record<string, ViewDefinition>> = keyof TViews & string;
5
- export type ViewContext<TView> = TView extends StandardJSONSchemaV1 ? StandardJSONSchemaV1.InferOutput<TView> : Record<string, never>;
6
- interface ReadyViewOptions<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> {
7
- context: ViewContext<TViews[TView]>;
8
- view: TView;
9
- status?: "ready";
10
- }
11
- interface LoadingViewOptions<TView extends string> {
12
- context?: never;
13
- view: TView;
14
- status: "loading";
15
- }
16
- interface ErrorViewOptions<TView extends string> {
17
- context?: never;
18
- view: TView;
19
- status: "error";
20
- }
21
- export type ViewOptions<TViews extends Record<string, ViewDefinition> = DefaultViews, TView extends ViewName<TViews> = ViewName<TViews>> = TView extends ViewName<TViews> ? ReadyViewOptions<TViews, TView> | LoadingViewOptions<TView> | ErrorViewOptions<TView> : never;
22
- export type ViewState<TViews extends Record<string, ViewDefinition> = DefaultViews, TView extends ViewName<TViews> = ViewName<TViews>> = Omit<ReadyViewOptions<TViews, TView>, "view"> | Omit<LoadingViewOptions<TView>, "view"> | Omit<ErrorViewOptions<TView>, "view">;
23
5
  export type UseViewContext<TViews extends Record<string, ViewDefinition>> = <TView extends ViewName<TViews>>(view: TView, options: ViewState<TViews, NoInfer<TView>>) => void;
24
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;
25
- export {};
@@ -1,13 +1,7 @@
1
- import type { TailorKitApp, SlotItem } from "@tailorkit/client-core";
2
- import type { UseAppsOptions, UseAppsResult } from "./use-apps";
1
+ import type { SlotItem, ViewsQueryOptions } from "@tailorkit/client-core";
2
+ import type { UseQueryResult } from "./use-query-result";
3
3
  export type { SlotItem } from "@tailorkit/client-core";
4
- export interface UseViewsOptions<TScopeNames extends string = string, TSlot extends string = string> extends UseAppsOptions<TScopeNames> {
5
- slot: TSlot;
6
- }
7
- export interface UseViewsResult<TMultiple extends boolean = boolean> extends Omit<UseAppsResult, "data"> {
8
- data: SlotItem<TMultiple>[] | undefined;
9
- }
10
- /** List apps for single-view slots or resolve instances for multiple-view slots. */
11
- export declare function useViews({ slot, scopes, appIds }: UseViewsOptions): UseViewsResult;
12
- /** Managed Slot resolves only its explicitly supplied app. */
13
- export declare function useAppSlot(app: TailorKitApp, slot: string): UseViewsResult;
4
+ export type UseViewsOptions<TScopeNames extends string = string, TSlot extends string = string> = ViewsQueryOptions<TScopeNames, TSlot>;
5
+ export type UseViewsResult<TMultiple extends boolean = boolean> = UseQueryResult<SlotItem<TMultiple>[]>;
6
+ /** Subscribe to the shared views query using React's lifecycle. */
7
+ export declare function useViews(options: UseViewsOptions): UseViewsResult;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- export { Slot } from "./components/slot";
2
- export type { ControlledSlotProps, SlotComponent, SlotContext, SlotProps } from "./components/slot";
1
+ export { RenderSlot } from "./components/render-slot";
2
+ export type { ControlledRenderSlotProps, RenderSlotComponent, RenderSlotContext, RenderSlotProps, } from "./components/render-slot";
3
3
  export { components, createTailorKitClient } from "./tailorkit";
4
- export type { TailorKitApp, TailorKitClientConfig, TailorKitInstance } from "./tailorkit";
5
- export { Root } from "./components/root";
4
+ export type { TailorKitApp, TailorKitClientConfig, TailorKitInstance, TailorKitProviderProps, } from "./tailorkit";
6
5
  export type { UseAppsOptions, UseAppsResult } from "./hooks/use-apps";
7
6
  export type { SlotItem, UseViewsOptions, UseViewsResult } from "./hooks/use-views";
8
7
  export type { UseViewContext, ViewOptions, ViewState } from "./hooks/use-view-context";