@tailorkit/app 0.1.0-beta.7 → 0.1.0-beta.9

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/builder.js CHANGED
@@ -117,7 +117,6 @@ var createTailorKitUploadManifest = (logos) => tailorkitUploadManifestSchema.par
117
117
  });
118
118
 
119
119
  // src/builder/index.ts
120
- var preactExternal = /^preact(?:\/.*)?$/u;
121
120
  var preactPackageJson = "preact/package.json";
122
121
  var preactPackageJsonModuleId = "\0tailorkit-preact-package-json";
123
122
  var buildApp = async (options = {}) => {
@@ -139,7 +138,6 @@ var buildApp = async (options = {}) => {
139
138
  watch: options.watch ? {} : null,
140
139
  minify: "oxc",
141
140
  rollupOptions: {
142
- external: (id) => id !== preactPackageJson && id !== preactPackageJsonModuleId && preactExternal.test(id),
143
141
  output: {
144
142
  comments: {
145
143
  annotation: false,
package/dist/index.d.ts CHANGED
@@ -1,71 +1,87 @@
1
1
  import { h } from "preact";
2
2
  import type { ComponentChild, ComponentChildren, VNode } from "preact";
3
- export interface TailorKitScreens {
3
+ export interface TailorKitViews {
4
4
  }
5
- export type ScreenPath = Extract<keyof TailorKitScreens & string, `/${string}`>;
6
- export type AppScreenPath = ScreenPath;
7
- export type ScreenProps<TPath extends ScreenPath> = TailorKitScreens[TPath] extends object ? TailorKitScreens[TPath] : Record<string, never>;
8
- export type ScreenPropsForPath<TPath extends AppScreenPath> = TPath extends ScreenPath ? ScreenProps<TPath> : never;
9
- export type ScreenContext<TPath extends AppScreenPath> = ScreenPropsForPath<TPath> extends {
5
+ export interface TailorKitSlots {
6
+ }
7
+ export type SlotName = keyof TailorKitSlots & string;
8
+ export type ViewPath = Extract<keyof TailorKitViews & string, `/${string}`>;
9
+ export type AppViewPath = ViewPath;
10
+ export type ViewProps<TPath extends ViewPath> = TailorKitViews[TPath] extends object ? TailorKitViews[TPath] : Record<string, never>;
11
+ export type ViewPropsForPath<TPath extends AppViewPath> = TPath extends ViewPath ? ViewProps<TPath> : never;
12
+ export type ViewContext<TPath extends AppViewPath> = ViewPropsForPath<TPath> extends {
10
13
  context: infer TContext;
11
14
  } ? TContext : Record<string, never>;
12
15
  export type View<TProps extends object = Record<string, never>> = (props: TProps) => ComponentChild;
13
- export type ScreenRuntimeProps<TPath extends AppScreenPath> = {
14
- context: ScreenContext<TPath>;
15
- screen: TPath;
16
+ export type ViewRuntimeProps<TPath extends AppViewPath> = {
17
+ context: ViewContext<TPath>;
18
+ view: TPath;
16
19
  status: "ready";
17
20
  } | {
18
21
  context?: never;
19
- screen: TPath;
22
+ view: TPath;
20
23
  status: "loading";
21
24
  } | {
22
25
  context?: never;
23
- screen: TPath;
26
+ view: TPath;
24
27
  status: "error";
25
28
  };
26
- export interface ScreenDefinition<TPath extends AppScreenPath = AppScreenPath> {
27
- component: View<ScreenRuntimeProps<TPath>>;
29
+ export interface ViewDefinition<TPath extends AppViewPath = AppViewPath> {
30
+ component: View<ViewRuntimeProps<TPath>>;
28
31
  path: TPath;
29
- useContext: () => ScreenContext<TPath>;
32
+ useContext: () => ViewContext<TPath>;
30
33
  }
31
- type RegisteredScreens = {
32
- [TPath in AppScreenPath]: ScreenDefinition<TPath>;
34
+ type RegisteredViews = {
35
+ [TPath in AppViewPath]: ViewDefinition<TPath>;
36
+ };
37
+ type ViewDefinitions = Partial<{
38
+ [P in AppViewPath]: RegisteredViews[P] | false;
39
+ }>;
40
+ type InvalidViewPath<TViews> = Exclude<keyof TViews & string, AppViewPath>;
41
+ type RequireViewPaths<TViews> = InvalidViewPath<TViews> extends never ? unknown : {
42
+ readonly __tailorkit_error__: `View paths must be declared by the host. Invalid view: ${InvalidViewPath<TViews>}`;
33
43
  };
34
- type ScreenDefinitions = Partial<RegisteredScreens>;
35
- type InvalidScreenPath<TScreens> = Exclude<keyof TScreens & string, `/${string}`>;
36
- type RequireScreenPaths<TScreens> = InvalidScreenPath<TScreens> extends never ? unknown : {
37
- readonly __tailorkit_error__: `Screen paths must start with "/". Invalid screen: ${InvalidScreenPath<TScreens>}`;
44
+ type ViewKeyPathMismatch<TViews> = {
45
+ [TPath in keyof TViews & string]: TViews[TPath] extends false ? never : TViews[TPath] extends ViewDefinition<infer TViewPath> ? TViewPath extends TPath ? never : TPath : TPath;
46
+ }[keyof TViews & string];
47
+ type RequireMatchingViewKeys<TViews> = ViewKeyPathMismatch<TViews> extends never ? unknown : {
48
+ readonly __tailorkit_error__: `View key must match createView path. Invalid view: ${ViewKeyPathMismatch<TViews>}`;
38
49
  };
39
- type ScreenKeyPathMismatch<TScreens> = {
40
- [TPath in keyof TScreens & string]: TScreens[TPath] extends ScreenDefinition<infer TScreenPath> ? TScreenPath extends TPath ? never : TPath : TPath;
41
- }[keyof TScreens & string];
42
- type RequireMatchingScreenKeys<TScreens> = ScreenKeyPathMismatch<TScreens> extends never ? unknown : {
43
- readonly __tailorkit_error__: `Screen key must match createScreen path. Invalid screen: ${ScreenKeyPathMismatch<TScreens>}`;
50
+ export type SlotView<TSlot extends SlotName> = Extract<TailorKitSlots[TSlot], AppViewPath>;
51
+ type SlotDefinitions = {
52
+ [V in SlotName]?: Pick<ViewDefinitions, SlotView<V>>;
44
53
  };
45
- export interface TailorKitClient<TScreens extends ScreenDefinitions = ScreenDefinitions> {
46
- screens: TScreens;
54
+ type RequireSlotViews<V, S> = V extends SlotName ? Exclude<keyof S, SlotView<V>> extends never ? unknown : {
55
+ readonly __tailorkit_error__: "View is not supported by this slot";
56
+ } : never;
57
+ export interface TailorKitClient<TSlots extends SlotDefinitions = SlotDefinitions> {
58
+ slots: TSlots;
47
59
  }
48
60
  export interface TailorKitClientMeta {
49
61
  preactVersion: string;
50
62
  }
51
63
  export interface TailorKitClientRuntime {
52
64
  h: typeof h;
53
- render: (vnode: VNode, parent: Element | Document | ShadowRoot | DocumentFragment) => void;
65
+ render: (vnode: VNode | null, parent: Element | Document | ShadowRoot | DocumentFragment) => void;
54
66
  }
55
- export type TailorKitClientWithMeta<TScreens extends ScreenDefinitions = ScreenDefinitions> = TailorKitClient<TScreens> & {
67
+ export type TailorKitClientWithMeta<TViews extends SlotDefinitions = SlotDefinitions> = TailorKitClient<TViews> & {
56
68
  $meta: TailorKitClientMeta;
57
69
  $runtime: TailorKitClientRuntime;
58
70
  };
59
- export declare const createScreen: <const TPath extends AppScreenPath>(path: TPath, options: {
71
+ export declare const createView: <const TPath extends AppViewPath>(path: TPath, options: {
60
72
  component: View<Record<string, never>>;
61
73
  error?: View<Record<string, never>>;
62
74
  loading?: View<Record<string, never>>;
63
- }) => ScreenDefinition<TPath>;
64
- export declare const defineClient: <const TScreens extends ScreenDefinitions>(client: TailorKitClient<TScreens> & RequireScreenPaths<TScreens> & RequireMatchingScreenKeys<TScreens>) => TailorKitClientWithMeta<TScreens>;
65
- export declare const createRemoteComponent: <TProps extends object, TSlots extends readonly string[]>(name: string, options: {
75
+ }) => ViewDefinition<TPath>;
76
+ export declare const defineClient: <const TSlots extends SlotDefinitions>(client: TailorKitClient<TSlots> & {
77
+ slots: { [V in keyof TSlots]: TSlots[V] & RequireViewPaths<TSlots[V]> & RequireMatchingViewKeys<TSlots[V]> & RequireSlotViews<V, TSlots[V]>; };
78
+ } & (Exclude<keyof TSlots, SlotName> extends never ? unknown : {
79
+ __tailorkit_error__: "Unknown slot";
80
+ })) => TailorKitClientWithMeta<TSlots>;
81
+ export declare const createRemoteComponent: <TProps extends object, TChildren extends boolean = false>(name: string, options?: {
66
82
  callbacks?: Record<string, number>;
67
- slots: TSlots;
83
+ children?: TChildren;
68
84
  }) => View<TProps & {
69
- children?: ComponentChildren;
85
+ children?: TChildren extends true ? ComponentChildren : never;
70
86
  }>;
71
87
  export {};
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@
2
2
  import { createContext, h, render } from "preact";
3
3
  import { useContext } from "preact/hooks";
4
4
  var preactVersion = "10.29.8";
5
- var createScreen = (path, options) => {
5
+ var createView = (path, options) => {
6
6
  const Context = createContext(null);
7
- const Screen = (props) => {
7
+ const View = (props) => {
8
8
  if (props.status === "loading") {
9
9
  return options.loading ? h(options.loading, {}) : null;
10
10
  }
@@ -18,12 +18,12 @@ var createScreen = (path, options) => {
18
18
  );
19
19
  };
20
20
  return {
21
- component: Screen,
21
+ component: View,
22
22
  path,
23
23
  useContext: () => {
24
24
  const context = useContext(Context);
25
25
  if (context === null) {
26
- throw new Error(`Screen context is only available while rendering "${path}".`);
26
+ throw new Error(`View context is only available while rendering "${path}".`);
27
27
  }
28
28
  return context;
29
29
  }
@@ -31,26 +31,16 @@ var createScreen = (path, options) => {
31
31
  };
32
32
  var defineClient = (client) => ({
33
33
  ...client,
34
- $meta: {
35
- preactVersion
36
- },
37
- $runtime: {
38
- h,
39
- render
40
- }
34
+ $meta: { preactVersion },
35
+ $runtime: { h, render }
41
36
  });
42
37
  var componentTagPrefix = "tailorkit-";
43
38
  var toComponentTagName = (name) => `${componentTagPrefix}${name.replaceAll(/([a-z0-9])([A-Z])/gu, "$1-$2").replaceAll(/[\s_]+/gu, "-").toLowerCase()}`;
44
39
  var toCallbackEventName = (name) => `tailorkitcallback${name.replaceAll(/[^A-Za-z0-9_$]/gu, "").toLowerCase()}`;
45
40
  var toEventProp = (event) => `on${event}`;
46
- var createRemoteComponent = (name, options) => {
41
+ var createRemoteComponent = (name, options = {}) => {
47
42
  const tagName = toComponentTagName(name);
48
- const callbacks = options.callbacks;
49
- if (!callbacks || Object.keys(callbacks).length === 0) {
50
- return function RemoteComponent({ children, ...props }) {
51
- return h(tagName, props, children);
52
- };
53
- }
43
+ const callbacks = options.callbacks ?? {};
54
44
  return function RemoteComponent({ children, ...props }) {
55
45
  const nextProps = { ...props };
56
46
  const callbackMap = {};
@@ -66,14 +56,18 @@ var createRemoteComponent = (name, options) => {
66
56
  callback(...(event.detail ?? []).slice(0, inputCount));
67
57
  };
68
58
  }
59
+ const serializedProps = Object.fromEntries(
60
+ Object.entries(nextProps).filter(([, value]) => typeof value !== "function")
61
+ );
62
+ nextProps["data-tailorkit-props"] = JSON.stringify(serializedProps);
69
63
  if (Object.keys(callbackMap).length > 0) {
70
64
  nextProps["data-tailorkit-callbacks"] = JSON.stringify(callbackMap);
71
65
  }
72
- return h(tagName, nextProps, children);
66
+ return h(tagName, nextProps, options.children ? children : void 0);
73
67
  };
74
68
  };
75
69
  export {
76
70
  createRemoteComponent,
77
- createScreen,
71
+ createView,
78
72
  defineClient
79
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailorkit/app",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.9",
4
4
  "license": "AGPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@tailorkit/core": "0.1.0-beta.7",
36
+ "@tailorkit/core": "0.1.0-beta.9",
37
37
  "cosmiconfig": "^10.0.0",
38
38
  "vite": "^8.2.2",
39
39
  "zod": "^4.4.3"