@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,12 +1,11 @@
1
1
  import type { CSSProperties, ReactNode } from "react";
2
2
  import type { TailorKitTheme } from "@tailorkit/core/schema";
3
- type PrimitiveProps = Record<string, unknown>;
3
+ import type { PrimitiveProps } from "@tailorkit/client-core";
4
4
  interface PrimitiveThemeContextValue {
5
5
  viewId: string;
6
6
  theme: TailorKitTheme;
7
7
  }
8
8
  export declare const PrimitiveThemeContext: import("react").Context<PrimitiveThemeContextValue | null>;
9
- export declare const buildThemeCss: (viewId: string, theme: TailorKitTheme) => string;
10
9
  export declare const primitives: {
11
10
  readonly Box: ({ props, children }: {
12
11
  props: PrimitiveProps;
@@ -1,81 +1,37 @@
1
- import type { TailorKitFetchClient, TailorKitCacheOptions } from "@tailorkit/client-core";
1
+ import type { AnyComponentDefinition, ComponentRenderer, ComponentRenderers, CompleteComponentRenderers, TailorKitClientConfig, TailorKitApp, TailorKitServerShape, ServerComponents, ServerViews, ServerSlots, ServerScopeNames, SlotMultiple } from "@tailorkit/client-core";
2
+ export type { TailorKitClientConfig } from "@tailorkit/client-core";
3
+ import type { TailorKitCacheOptions } from "@tailorkit/client-core";
2
4
  import type { ReactNode } from "react";
3
- import type { TailorKitTheme, CallbackMap, ComponentDefinition, ComponentProps, Schema, ViewDefinition, SlotDefinitions, TailorKitSchema } from "@tailorkit/core/schema";
5
+ import type { TailorKitTheme, ViewDefinition, SlotDefinitions, TailorKitSchema } from "@tailorkit/core/schema";
4
6
  import type { primitives } from "./primitives";
5
7
  import type { UseViewContext } from "./hooks/use-view-context";
6
8
  import type { UseAppsOptions, UseAppsResult } from "./hooks/use-apps";
7
9
  import type { UseViewsOptions, UseViewsResult } from "./hooks/use-views";
8
- import type { SlotComponent } from "./components/slot";
9
- type AnyComponentDefinition = ComponentDefinition<Schema | undefined, CallbackMap, boolean | undefined>;
10
- type ComponentRenderer<TComponent extends AnyComponentDefinition> = (args: {
11
- props: ComponentProps<TComponent>;
12
- children?: TComponent extends {
13
- children: true;
14
- } ? ReactNode : never;
15
- }) => ReactNode;
16
- type ComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>> = {
17
- [TName in keyof TComponents]?: ComponentRenderer<TComponents[TName]>;
18
- };
19
- type CompleteComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>> = {
20
- [TName in keyof TComponents]-?: ComponentRenderer<TComponents[TName]>;
21
- };
10
+ import type { RenderSlotComponent } from "./components/render-slot";
22
11
  export type { TailorKitApp } from "@tailorkit/client-core";
23
- export interface TailorKitClientConfig {
24
- readonly baseUrl: string | URL;
25
- readonly fetchClient?: TailorKitFetchClient;
26
- readonly components: Record<string, unknown>;
27
- readonly theme: TailorKitTheme;
12
+ export interface TailorKitProviderProps {
13
+ apps?: TailorKitApp[];
14
+ children?: ReactNode;
28
15
  }
29
16
  export interface TailorKitInstance<TViews extends Record<string, ViewDefinition> = Record<string, ViewDefinition>, TSlots extends SlotDefinitions = SlotDefinitions, TScopeNames extends string = string> extends TailorKitClientConfig {
30
17
  readonly $slots?: TSlots;
31
18
  readonly $views?: TViews;
32
- readonly Slot: SlotComponent<TViews, TSlots>;
19
+ readonly Provider: (props: TailorKitProviderProps) => ReactNode;
20
+ readonly RenderSlot: RenderSlotComponent<TViews, TSlots>;
33
21
  readonly useApps: (options?: UseAppsOptions<TScopeNames>) => UseAppsResult;
34
22
  readonly useViews: <TSlot extends keyof TSlots & string>(options: UseViewsOptions<TScopeNames, TSlot>) => UseViewsResult<SlotMultiple<TSlots[TSlot]>>;
35
23
  readonly useViewContext: UseViewContext<TViews>;
36
24
  }
37
- type SlotMultiple<TSlot> = TSlot extends {
38
- multiple: infer TMultiple extends boolean;
39
- } ? TMultiple : TSlot extends {
40
- multiple?: infer TMultiple extends boolean;
41
- } ? TMultiple | false : false;
42
25
  type PrimitiveRenderers = typeof primitives;
43
26
  type CustomComponentRenderers<TComponents extends Record<string, AnyComponentDefinition>> = {
44
- [TName in Exclude<keyof TComponents, keyof PrimitiveRenderers>]?: ComponentRenderer<TComponents[TName]>;
45
- };
46
- export declare function components<TComponents extends Record<string, AnyComponentDefinition>>(_schema: TailorKitSchema<TComponents, Record<string, ViewDefinition>>, customComponents: CustomComponentRenderers<TComponents>): ComponentRenderers<TComponents>;
47
- interface TailorKitServerShape {
48
- $internal: {
49
- schema: {
50
- components: Record<string, unknown>;
51
- views: Record<string, unknown>;
52
- };
53
- };
54
- }
55
- type ServerComponentMap<TTailor extends TailorKitServerShape> = TTailor["$internal"]["schema"]["components"];
56
- type ServerComponents<TTailor extends TailorKitServerShape> = {
57
- [TName in keyof ServerComponentMap<TTailor>]: ServerComponentMap<TTailor>[TName] extends AnyComponentDefinition ? ServerComponentMap<TTailor>[TName] : never;
58
- };
59
- type ServerViewMap<TTailor extends TailorKitServerShape> = TTailor["$internal"]["schema"]["views"];
60
- type ServerScopeNames<TTailor extends TailorKitServerShape> = TTailor extends {
61
- handler: (request: Request, options: infer TOptions) => unknown;
62
- } ? TOptions extends {
63
- authenticate: infer TAuthenticate;
64
- } ? TAuthenticate extends (...args: infer _TArgs) => infer TResult ? Extract<Awaited<TResult>, {
65
- scopes: unknown;
66
- }> extends {
67
- scopes: infer TScopes;
68
- } ? keyof TScopes & string : never : never : never : never;
69
- type ServerViews<TTailor extends TailorKitServerShape> = {
70
- [TName in keyof ServerViewMap<TTailor>]: ServerViewMap<TTailor>[TName] extends ViewDefinition ? ServerViewMap<TTailor>[TName] : never;
27
+ [TName in Exclude<keyof TComponents, keyof PrimitiveRenderers>]?: ComponentRenderer<TComponents[TName], ReactNode>;
71
28
  };
29
+ export declare function components<TComponents extends Record<string, AnyComponentDefinition>>(_schema: TailorKitSchema<TComponents, Record<string, ViewDefinition>>, customComponents: CustomComponentRenderers<TComponents>): ComponentRenderers<TComponents, ReactNode>;
72
30
  export declare function createTailorKitClient<TTailor extends TailorKitServerShape>(options: {
73
31
  baseUrl: string | URL;
74
- components?: CompleteComponentRenderers<ServerComponents<TTailor>>;
32
+ components?: CompleteComponentRenderers<ServerComponents<TTailor>, ReactNode>;
75
33
  theme?: TailorKitTheme;
76
34
  cache?: TailorKitCacheOptions;
77
35
  fetch?: typeof fetch;
78
- }): TailorKitInstance<ServerViews<TTailor>, TTailor extends {
79
- readonly $slots?: infer V extends SlotDefinitions;
80
- } ? V : SlotDefinitions, ServerScopeNames<TTailor>>;
36
+ }): TailorKitInstance<ServerViews<TTailor>, ServerSlots<TTailor>, ServerScopeNames<TTailor>>;
81
37
  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.23",
3
+ "version": "0.1.0-beta.25",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,12 +22,14 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@floating-ui/react-dom": "^2.1.9",
25
+ "@nanostores/react": "2.0.1",
25
26
  "@standard-schema/spec": "^1.1.0",
26
- "@tailorkit/app": "0.1.0-beta.23",
27
- "@tailorkit/client-core": "0.1.0-beta.23",
28
- "@tailorkit/client-platform": "0.1.0-beta.23",
29
- "@tailorkit/core": "0.1.0-beta.23",
30
- "@tailorkit/sandbox": "0.1.0-beta.23"
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",
32
+ "nanostores": "1.5.4"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@tailorkit/config": "0.0.0",
@@ -1,19 +0,0 @@
1
- import type { ComponentPropsWithoutRef, ElementType, HTMLAttributes, ReactElement, ReactNode, Ref } from "react";
2
- type ElementProps<TTagName extends ElementType> = ComponentPropsWithoutRef<TTagName> & {
3
- ref?: Ref<unknown>;
4
- };
5
- export interface RenderProps {
6
- render?: ReactElement<Record<string, unknown>>;
7
- }
8
- export type ComponentProps<TTagName extends ElementType> = ElementProps<TTagName> & RenderProps;
9
- export declare function useRender<TTagName extends ElementType>({ defaultTagName, props, render, }: {
10
- defaultTagName: TTagName;
11
- props: ElementProps<TTagName>;
12
- render?: ReactElement<Record<string, unknown>>;
13
- }): ReactNode;
14
- export declare function mergeProps<TProps extends Record<string, unknown>>(...propSets: (TProps | Record<string, unknown> | undefined)[]): TProps;
15
- export declare function composeRefs<T>(...refs: (Ref<T> | undefined)[]): Ref<T>;
16
- export type HtmlProps<TElement extends HTMLElement> = HTMLAttributes<TElement> & {
17
- ref?: Ref<TElement>;
18
- };
19
- export {};
@@ -1,9 +0,0 @@
1
- import type { ReactNode } from "react";
2
- import type { TailorKitApp, TailorKitClientConfig } from "../tailorkit";
3
- import type { ComponentProps } from "./render";
4
- export interface RootProps extends ComponentProps<"div"> {
5
- apps?: TailorKitApp[];
6
- children?: ReactNode;
7
- client: TailorKitClientConfig;
8
- }
9
- export declare function Root({ apps: appsProp, children, render, client, ...props }: RootProps): ReactNode;
@@ -1,51 +0,0 @@
1
- import type { ViewInstance } from "@tailorkit/app/client";
2
- import type { SlotDefinitions, ViewDefinition } from "@tailorkit/core/schema";
3
- import type { ReactNode } from "react";
4
- import type { ViewContext, ViewName } from "../hooks/use-view-context";
5
- import type { TailorKitApp } from "../tailorkit";
6
- type DefaultViews = Record<`/${string}`, ViewDefinition>;
7
- type ContextPaths<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> = {
8
- [P in ViewName<TViews>]: P extends "/" | TView ? P : TView extends `${P}/${string}` ? P : never;
9
- }[ViewName<TViews>];
10
- type ContextFields<TView> = undefined extends ViewContext<TView> ? Partial<Exclude<ViewContext<TView>, undefined>> : ViewContext<TView>;
11
- export type SlotContext<TViews extends Record<string, ViewDefinition>, TView extends ViewName<TViews>> = {
12
- [P in ContextPaths<TViews, TView>]: (context: ContextFields<TViews[P]>) => void;
13
- }[ContextPaths<TViews, TView>] extends (context: infer TContext) => void ? TContext : never;
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];
31
- export type ControlledSlotProps<TViews extends Record<string, ViewDefinition> = DefaultViews, TSlots extends SlotDefinitions = SlotDefinitions> = {
32
- [TSlot in keyof TSlots & string]: {
33
- [TView in Extract<ViewName<TViews>, TSlots[TSlot]["views"][number]>]: {
34
- app: TailorKitApp;
35
- name: TSlot;
36
- view: TView;
37
- } & (({
38
- context: SlotContext<TViews, TView>;
39
- status: "ready";
40
- } & InstanceProps<TSlots[TSlot], "instance", ViewInstance>) | {
41
- context?: never;
42
- status: "loading" | "error";
43
- instance?: never;
44
- });
45
- }[Extract<ViewName<TViews>, TSlots[TSlot]["views"][number]>];
46
- }[keyof TSlots & string];
47
- export type SlotComponent<TViews extends Record<string, ViewDefinition> = DefaultViews, TSlots extends SlotDefinitions = SlotDefinitions> = ((props: SlotProps<TSlots>) => ReactNode) & {
48
- Controlled: (props: ControlledSlotProps<TViews, TSlots>) => ReactNode;
49
- };
50
- export declare const Slot: SlotComponent;
51
- export {};
@@ -1,2 +0,0 @@
1
- /** Keep equivalent JSON context values stable without requiring callers to memoize. */
2
- export declare function useStableContext<T>(value: T): T;
@@ -1,8 +0,0 @@
1
- import type { HostToIframePayload } from "@tailorkit/sandbox/protocol";
2
- import type { NodeStore } from "@tailorkit/client-core";
3
- export interface RemoteViewContext {
4
- components: Record<string, unknown>;
5
- dispatch: (payload: HostToIframePayload) => void;
6
- store: NodeStore;
7
- }
8
- export declare const RemoteUIContext: import("react").Context<RemoteViewContext | null>;
@@ -1 +0,0 @@
1
- export { appendScopeSelection, normalizeScopeSelection } from "@tailorkit/client-core";
@@ -1 +0,0 @@
1
- export { resolveSlotView, selectSlotView } from "@tailorkit/client-core";