@plasmicapp/host 1.0.166 → 1.0.168

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.
Files changed (50) hide show
  1. package/dist/exports.d.ts +4 -3
  2. package/dist/host.esm.js +48 -31
  3. package/dist/host.esm.js.map +1 -1
  4. package/dist/index.cjs.js +48 -30
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/prop-types.d.ts +2 -1
  7. package/dist/registerFunction.d.ts +105 -0
  8. package/dist/version.d.ts +1 -1
  9. package/package.json +6 -4
  10. package/registerComponent/dist/exports.d.ts +4 -3
  11. package/registerComponent/dist/prop-types.d.ts +2 -1
  12. package/registerComponent/dist/registerFunction.d.ts +105 -0
  13. package/registerComponent/dist/version.d.ts +1 -1
  14. package/registerFunction/dist/canvas-host.d.ts +41 -0
  15. package/registerFunction/dist/common.d.ts +1 -0
  16. package/registerFunction/dist/data.d.ts +48 -0
  17. package/registerFunction/dist/element-types.d.ts +115 -0
  18. package/registerFunction/dist/exports.d.ts +13 -0
  19. package/registerFunction/dist/fetcher.d.ts +40 -0
  20. package/registerFunction/dist/global-actions.d.ts +9 -0
  21. package/registerFunction/dist/index.cjs.js +23 -0
  22. package/registerFunction/dist/index.cjs.js.map +1 -0
  23. package/registerFunction/dist/index.d.ts +1 -0
  24. package/registerFunction/dist/index.esm.js +19 -0
  25. package/registerFunction/dist/index.esm.js.map +1 -0
  26. package/registerFunction/dist/lang-utils.d.ts +3 -0
  27. package/registerFunction/dist/link.d.ts +7 -0
  28. package/registerFunction/dist/prop-types.d.ts +426 -0
  29. package/registerFunction/dist/registerComponent.d.ts +272 -0
  30. package/registerFunction/dist/registerFunction.d.ts +105 -0
  31. package/registerFunction/dist/registerGlobalContext.d.ts +76 -0
  32. package/registerFunction/dist/registerToken.d.ts +34 -0
  33. package/registerFunction/dist/registerTrait.d.ts +20 -0
  34. package/registerFunction/dist/repeatedElement.d.ts +15 -0
  35. package/registerFunction/dist/type-utils.d.ts +6 -0
  36. package/registerFunction/dist/useForceUpdate.d.ts +1 -0
  37. package/registerFunction/dist/version.d.ts +1 -0
  38. package/registerFunction/package.json +5 -0
  39. package/registerGlobalContext/dist/exports.d.ts +4 -3
  40. package/registerGlobalContext/dist/prop-types.d.ts +2 -1
  41. package/registerGlobalContext/dist/registerFunction.d.ts +105 -0
  42. package/registerGlobalContext/dist/version.d.ts +1 -1
  43. package/registerToken/dist/exports.d.ts +4 -3
  44. package/registerToken/dist/prop-types.d.ts +2 -1
  45. package/registerToken/dist/registerFunction.d.ts +105 -0
  46. package/registerToken/dist/version.d.ts +1 -1
  47. package/registerTrait/dist/exports.d.ts +4 -3
  48. package/registerTrait/dist/prop-types.d.ts +2 -1
  49. package/registerTrait/dist/registerFunction.d.ts +105 -0
  50. package/registerTrait/dist/version.d.ts +1 -1
@@ -0,0 +1,105 @@
1
+ export type StringType<T extends string = string> = "string" | `'${T}'`;
2
+ export type NumberType<T extends number = number> = "number" | `${number extends T ? number : T}`;
3
+ export type BooleanType<T extends boolean = boolean> = "boolean" | `${boolean extends T ? boolean : T}`;
4
+ export type NullType = "null";
5
+ export type UndefinedType = "undefined";
6
+ export type ArrayType = "array";
7
+ export type ObjectType = "object";
8
+ export type AnyType = "any";
9
+ export type VoidType = "void";
10
+ export type RestrictedType<T> = T extends string ? StringType<T> : T extends number ? NumberType<T> : T extends boolean ? BooleanType<T> : T extends null ? NullType : T extends undefined ? UndefinedType : T extends Array<any> ? ArrayType : T extends object ? ObjectType : AnyType;
11
+ export type OrType<T> = RestrictedType<T>[];
12
+ export type ParamType<T> = AnyType | RestrictedType<T> | OrType<T>;
13
+ export interface BaseParam<T> {
14
+ name: string;
15
+ type?: ParamType<T>;
16
+ description?: string;
17
+ isOptional?: boolean;
18
+ isRestParam?: boolean;
19
+ }
20
+ export interface RequiredParam<T> extends BaseParam<T> {
21
+ isOptional?: false;
22
+ isRestParameter?: false;
23
+ }
24
+ export interface OptionalParam<T> extends BaseParam<T | undefined> {
25
+ isRestParameter?: false;
26
+ }
27
+ export interface RestParam<T> extends BaseParam<T> {
28
+ isOptional?: false;
29
+ isRestParameter: true;
30
+ }
31
+ type RequiredParams<T extends any[], U extends any[] = []> = Partial<T> extends T ? U : T extends [infer F, ...infer R] ? RequiredParams<R, [...U, F]> : U;
32
+ type OptionalParams<T extends any[]> = T extends [
33
+ ...RequiredParams<T>,
34
+ ...infer R
35
+ ] ? [...R] : [];
36
+ type HandleRequiredParams<P extends any[]> = P extends [infer H, ...infer T] ? [string | RequiredParam<H>, ...HandleRequiredParams<T>] : [];
37
+ type HandleOptionalParams<P extends any[]> = P extends [infer H, ...infer T] ? [] | [string | OptionalParam<H | undefined>, ...HandleOptionalParams<T>] : P extends [] ? [] : P extends Array<infer T> ? [] | [RestParam<T[]>] : [];
38
+ export type HandleParams<P extends any[]> = [
39
+ ...HandleRequiredParams<RequiredParams<P>>,
40
+ ...HandleOptionalParams<Required<OptionalParams<P>>>
41
+ ];
42
+ export type HandleReturnType<T> = VoidType | ParamType<T>;
43
+ export interface CustomFunctionMeta<F extends (...args: any[]) => any> {
44
+ /**
45
+ * The javascript name of the function. Notice it must be unique across all
46
+ * other functions and function namespaces. If two functions have the same
47
+ * name, they should be registered with different `meta.namespace`.
48
+ */
49
+ name: string;
50
+ /**
51
+ * A namespace for organizing groups of functions. It's also used to handle
52
+ * function name collisions. If a function has a namespace, it will be used
53
+ * whenever accessing the function.
54
+ */
55
+ namespace?: string;
56
+ /**
57
+ * Documentation for the registered function.
58
+ */
59
+ description?: string;
60
+ /**
61
+ * An array containing the list of parameters names the function takes.
62
+ * Optionally they can also be registered with the expected param types.
63
+ */
64
+ params?: HandleParams<Parameters<F>>;
65
+ /**
66
+ * Return value information.
67
+ */
68
+ returnValue?: {
69
+ /**
70
+ * The function return type.
71
+ */
72
+ type?: HandleReturnType<ReturnType<F>>;
73
+ /**
74
+ * The function return value description.
75
+ */
76
+ description?: string;
77
+ };
78
+ /**
79
+ * Typescript function declaration. If specified, it ignores the types
80
+ * provided by `params` and `returnValue`.
81
+ */
82
+ typescriptDeclaration?: string;
83
+ /**
84
+ * The path to be used when importing the function in the generated code.
85
+ * It can be the name of the package that contains the function, or the path
86
+ * to the file in the project (relative to the root directory).
87
+ */
88
+ importPath: string;
89
+ /**
90
+ * Whether the function is the default export from that path. Optional: if
91
+ * not specified, it's considered `false`.
92
+ */
93
+ isDefaultExport?: boolean;
94
+ }
95
+ export interface CustomFunctionRegistration {
96
+ function: (...args: any[]) => any;
97
+ meta: CustomFunctionMeta<any>;
98
+ }
99
+ declare global {
100
+ interface Window {
101
+ __PlasmicFunctionsRegistry: CustomFunctionRegistration[];
102
+ }
103
+ }
104
+ export default function unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
105
+ export {};
@@ -0,0 +1,76 @@
1
+ /// <reference types="react" />
2
+ import { BooleanType, ChoiceType, CustomType, JSONLikeType, NumberType, StringType, DataSourceType } from "./prop-types";
3
+ import { FunctionParam } from "./registerComponent";
4
+ export type PropType<P> = StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | CustomType<P> | DataSourceType<P>;
5
+ type RestrictPropType<T, P> = T extends string ? StringType<P> | ChoiceType<P> | JSONLikeType<P> | CustomType<P> : T extends boolean ? BooleanType<P> | JSONLikeType<P> | CustomType<P> : T extends number ? NumberType<P> | JSONLikeType<P> | CustomType<P> : PropType<P>;
6
+ type DistributedKeyOf<T> = T extends any ? keyof T : never;
7
+ export interface GlobalContextMeta<P> {
8
+ /**
9
+ * Any unique string name used to identify that context. Each context
10
+ * should be registered with a different `meta.name`, even if they have the
11
+ * same name in the code.
12
+ */
13
+ name: string;
14
+ /**
15
+ * The name to be displayed for the context in Studio. Optional: if not
16
+ * specified, `meta.name` is used.
17
+ */
18
+ displayName?: string;
19
+ /**
20
+ * The description of the context to be shown in Studio.
21
+ */
22
+ description?: string;
23
+ /**
24
+ * The javascript name to be used when generating code. Optional: if not
25
+ * provided, `meta.name` is used.
26
+ */
27
+ importName?: string;
28
+ /**
29
+ * An object describing the context properties to be used in Studio.
30
+ * For each `prop`, there should be an entry `meta.props[prop]` describing
31
+ * its type.
32
+ */
33
+ props: {
34
+ [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P>;
35
+ } & {
36
+ [prop: string]: PropType<P>;
37
+ };
38
+ /**
39
+ * The path to be used when importing the context in the generated code.
40
+ * It can be the name of the package that contains the context, or the path
41
+ * to the file in the project (relative to the root directory).
42
+ */
43
+ importPath: string;
44
+ /**
45
+ * Whether the context is the default export from that path. Optional: if
46
+ * not specified, it's considered `false`.
47
+ */
48
+ isDefaultExport?: boolean;
49
+ /**
50
+ * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`
51
+ * to interact with components, so it's not used in the generated code.
52
+ * Optional: If not provided, the usual `ref` is used.
53
+ */
54
+ refProp?: string;
55
+ /**
56
+ * Whether the global context provides data to its children using DataProvider.
57
+ */
58
+ providesData?: boolean;
59
+ unstable__globalActions?: Record<string, GlobalActionRegistration<P>>;
60
+ }
61
+ export interface GlobalContextRegistration {
62
+ component: React.ComponentType<any>;
63
+ meta: GlobalContextMeta<any>;
64
+ }
65
+ export interface GlobalActionRegistration<P> {
66
+ displayName?: string;
67
+ description?: string;
68
+ parameters: FunctionParam<P>[];
69
+ }
70
+ declare global {
71
+ interface Window {
72
+ __PlasmicContextRegistry: GlobalContextRegistration[];
73
+ }
74
+ }
75
+ export default function registerGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
76
+ export {};
@@ -0,0 +1,34 @@
1
+ export type TokenType = "color" | "spacing" | "font-family" | "font-size" | "line-height" | "opacity";
2
+ export interface TokenRegistration {
3
+ /**
4
+ * Name for this token; should be stable across updates
5
+ */
6
+ name: string;
7
+ /**
8
+ * Value for the token, which can either be a valid css value or a css reference
9
+ * to a css variable provided by your host app, like `var(--my-token)`
10
+ */
11
+ value: string;
12
+ /**
13
+ * Type of token
14
+ */
15
+ type: TokenType;
16
+ /**
17
+ * Optional display name to use for this token, if you'd like to use a friendlier
18
+ * name to display to Studio users
19
+ */
20
+ displayName?: string;
21
+ /**
22
+ * By default, if this token is a css variable reference like `var(--my-token)`,
23
+ * then it is assumed that `--my-token` is defined on `:root`. If it is defined
24
+ * in another element, then you can pass in a selector for that element,
25
+ * like `.themeRoot`.
26
+ */
27
+ selector?: string;
28
+ }
29
+ declare global {
30
+ interface Window {
31
+ __PlasmicTokenRegistry: TokenRegistration[];
32
+ }
33
+ }
34
+ export default function registerToken(token: TokenRegistration): void;
@@ -0,0 +1,20 @@
1
+ export interface BasicTrait {
2
+ label?: string;
3
+ type: "text" | "number" | "boolean";
4
+ }
5
+ export interface ChoiceTrait {
6
+ label?: string;
7
+ type: "choice";
8
+ options: string[];
9
+ }
10
+ export type TraitMeta = BasicTrait | ChoiceTrait;
11
+ export interface TraitRegistration {
12
+ trait: string;
13
+ meta: TraitMeta;
14
+ }
15
+ declare global {
16
+ interface Window {
17
+ __PlasmicTraitRegistry: TraitRegistration[];
18
+ }
19
+ }
20
+ export default function registerTrait(trait: string, meta: TraitMeta): void;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Allows elements to be repeated in Plasmic Studio.
3
+ * @param index The index of the copy (starting at 0).
4
+ * @param elt the React element to be repeated (or an array of such).
5
+ */
6
+ export default function repeatedElement<T>(index: number, elt: T): T;
7
+ /**
8
+ * Allows elements to be repeated in Plasmic Studio.
9
+ * @param isPrimary should be true for at most one instance of the element, and
10
+ * indicates which copy of the element will be highlighted when the element is
11
+ * selected in Studio.
12
+ * @param elt the React element to be repeated (or an array of such).
13
+ */
14
+ export default function repeatedElement<T>(isPrimary: boolean, elt: T): T;
15
+ export declare const setRepeatedElementFn: (fn: typeof repeatedElement) => void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a union type to a tuple type of the same members
3
+ */
4
+ export type TupleUnion<U extends string, R extends string[] = []> = {
5
+ [S in U]: Exclude<U, S> extends never ? [...R, S] : TupleUnion<Exclude<U, S>, [...R, S]>;
6
+ }[U] & string[];
@@ -0,0 +1 @@
1
+ export default function useForceUpdate(): () => void;
@@ -0,0 +1 @@
1
+ export declare const hostVersion = "1.0.168";
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "dist/index.cjs.js",
3
+ "types": "dist/registerFunction.d.ts",
4
+ "module": "dist/index.esm.js"
5
+ }
@@ -3,10 +3,11 @@ export * from "./data";
3
3
  export { PlasmicElement } from "./element-types";
4
4
  export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
5
  export * from "./global-actions";
6
- export { Action, ActionProps, CodeComponentMeta, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, stateHelpersKeys, StateHelpers, StateSpec, CodeComponentMode, } from "./registerComponent";
7
- export { PropType, ContextDependentConfig } from "./prop-types";
6
+ export * from "./link";
7
+ export { ContextDependentConfig, PropType } from "./prop-types";
8
+ export { Action, ActionProps, CodeComponentMeta, CodeComponentMode, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, StateHelpers, stateHelpersKeys, StateSpec, } from "./registerComponent";
9
+ export { CustomFunctionMeta, CustomFunctionRegistration, default as unstable_registerFunction, ParamType, } from "./registerFunction";
8
10
  export { default as registerGlobalContext, GlobalContextMeta, GlobalContextRegistration, PropType as GlobalContextPropType, } from "./registerGlobalContext";
9
11
  export { default as registerToken, TokenRegistration, TokenType, } from "./registerToken";
10
12
  export { BasicTrait, ChoiceTrait, default as registerTrait, TraitMeta, TraitRegistration, } from "./registerTrait";
11
13
  export { default as repeatedElement } from "./repeatedElement";
12
- export * from "./link";
@@ -296,7 +296,7 @@ export interface EventHandlerType<P> extends PropTypeBase<P> {
296
296
  type: "eventHandler";
297
297
  argTypes: {
298
298
  name: string;
299
- type: PropType<any>;
299
+ type: ArgType<any>;
300
300
  }[];
301
301
  }
302
302
  export interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
@@ -419,6 +419,7 @@ export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
419
419
  export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
420
420
  export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
421
421
  export type PropType<P> = StringType<P> | BooleanType<P> | GraphQLType<P> | NumberType<P> | JSONLikeType<P> | DataSourceType<P> | DataPickerType<P> | ExprEditorType<P> | FormValidationRulesType<P> | EventHandlerType<P> | ChoiceType<P> | CustomType<P> | ImageUrlType<P> | SlotType<P> | DateStringType<P> | DateRangeStringsType<P>;
422
+ export type ArgType<P> = Exclude<PropType<P>, SlotType<P> | EventHandlerType<P>>;
422
423
  export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
423
424
  export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
424
425
  export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
@@ -0,0 +1,105 @@
1
+ export type StringType<T extends string = string> = "string" | `'${T}'`;
2
+ export type NumberType<T extends number = number> = "number" | `${number extends T ? number : T}`;
3
+ export type BooleanType<T extends boolean = boolean> = "boolean" | `${boolean extends T ? boolean : T}`;
4
+ export type NullType = "null";
5
+ export type UndefinedType = "undefined";
6
+ export type ArrayType = "array";
7
+ export type ObjectType = "object";
8
+ export type AnyType = "any";
9
+ export type VoidType = "void";
10
+ export type RestrictedType<T> = T extends string ? StringType<T> : T extends number ? NumberType<T> : T extends boolean ? BooleanType<T> : T extends null ? NullType : T extends undefined ? UndefinedType : T extends Array<any> ? ArrayType : T extends object ? ObjectType : AnyType;
11
+ export type OrType<T> = RestrictedType<T>[];
12
+ export type ParamType<T> = AnyType | RestrictedType<T> | OrType<T>;
13
+ export interface BaseParam<T> {
14
+ name: string;
15
+ type?: ParamType<T>;
16
+ description?: string;
17
+ isOptional?: boolean;
18
+ isRestParam?: boolean;
19
+ }
20
+ export interface RequiredParam<T> extends BaseParam<T> {
21
+ isOptional?: false;
22
+ isRestParameter?: false;
23
+ }
24
+ export interface OptionalParam<T> extends BaseParam<T | undefined> {
25
+ isRestParameter?: false;
26
+ }
27
+ export interface RestParam<T> extends BaseParam<T> {
28
+ isOptional?: false;
29
+ isRestParameter: true;
30
+ }
31
+ type RequiredParams<T extends any[], U extends any[] = []> = Partial<T> extends T ? U : T extends [infer F, ...infer R] ? RequiredParams<R, [...U, F]> : U;
32
+ type OptionalParams<T extends any[]> = T extends [
33
+ ...RequiredParams<T>,
34
+ ...infer R
35
+ ] ? [...R] : [];
36
+ type HandleRequiredParams<P extends any[]> = P extends [infer H, ...infer T] ? [string | RequiredParam<H>, ...HandleRequiredParams<T>] : [];
37
+ type HandleOptionalParams<P extends any[]> = P extends [infer H, ...infer T] ? [] | [string | OptionalParam<H | undefined>, ...HandleOptionalParams<T>] : P extends [] ? [] : P extends Array<infer T> ? [] | [RestParam<T[]>] : [];
38
+ export type HandleParams<P extends any[]> = [
39
+ ...HandleRequiredParams<RequiredParams<P>>,
40
+ ...HandleOptionalParams<Required<OptionalParams<P>>>
41
+ ];
42
+ export type HandleReturnType<T> = VoidType | ParamType<T>;
43
+ export interface CustomFunctionMeta<F extends (...args: any[]) => any> {
44
+ /**
45
+ * The javascript name of the function. Notice it must be unique across all
46
+ * other functions and function namespaces. If two functions have the same
47
+ * name, they should be registered with different `meta.namespace`.
48
+ */
49
+ name: string;
50
+ /**
51
+ * A namespace for organizing groups of functions. It's also used to handle
52
+ * function name collisions. If a function has a namespace, it will be used
53
+ * whenever accessing the function.
54
+ */
55
+ namespace?: string;
56
+ /**
57
+ * Documentation for the registered function.
58
+ */
59
+ description?: string;
60
+ /**
61
+ * An array containing the list of parameters names the function takes.
62
+ * Optionally they can also be registered with the expected param types.
63
+ */
64
+ params?: HandleParams<Parameters<F>>;
65
+ /**
66
+ * Return value information.
67
+ */
68
+ returnValue?: {
69
+ /**
70
+ * The function return type.
71
+ */
72
+ type?: HandleReturnType<ReturnType<F>>;
73
+ /**
74
+ * The function return value description.
75
+ */
76
+ description?: string;
77
+ };
78
+ /**
79
+ * Typescript function declaration. If specified, it ignores the types
80
+ * provided by `params` and `returnValue`.
81
+ */
82
+ typescriptDeclaration?: string;
83
+ /**
84
+ * The path to be used when importing the function in the generated code.
85
+ * It can be the name of the package that contains the function, or the path
86
+ * to the file in the project (relative to the root directory).
87
+ */
88
+ importPath: string;
89
+ /**
90
+ * Whether the function is the default export from that path. Optional: if
91
+ * not specified, it's considered `false`.
92
+ */
93
+ isDefaultExport?: boolean;
94
+ }
95
+ export interface CustomFunctionRegistration {
96
+ function: (...args: any[]) => any;
97
+ meta: CustomFunctionMeta<any>;
98
+ }
99
+ declare global {
100
+ interface Window {
101
+ __PlasmicFunctionsRegistry: CustomFunctionRegistration[];
102
+ }
103
+ }
104
+ export default function unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
105
+ export {};
@@ -1 +1 @@
1
- export declare const hostVersion = "1.0.166";
1
+ export declare const hostVersion = "1.0.168";
@@ -3,10 +3,11 @@ export * from "./data";
3
3
  export { PlasmicElement } from "./element-types";
4
4
  export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
5
  export * from "./global-actions";
6
- export { Action, ActionProps, CodeComponentMeta, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, stateHelpersKeys, StateHelpers, StateSpec, CodeComponentMode, } from "./registerComponent";
7
- export { PropType, ContextDependentConfig } from "./prop-types";
6
+ export * from "./link";
7
+ export { ContextDependentConfig, PropType } from "./prop-types";
8
+ export { Action, ActionProps, CodeComponentMeta, CodeComponentMode, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, StateHelpers, stateHelpersKeys, StateSpec, } from "./registerComponent";
9
+ export { CustomFunctionMeta, CustomFunctionRegistration, default as unstable_registerFunction, ParamType, } from "./registerFunction";
8
10
  export { default as registerGlobalContext, GlobalContextMeta, GlobalContextRegistration, PropType as GlobalContextPropType, } from "./registerGlobalContext";
9
11
  export { default as registerToken, TokenRegistration, TokenType, } from "./registerToken";
10
12
  export { BasicTrait, ChoiceTrait, default as registerTrait, TraitMeta, TraitRegistration, } from "./registerTrait";
11
13
  export { default as repeatedElement } from "./repeatedElement";
12
- export * from "./link";
@@ -296,7 +296,7 @@ export interface EventHandlerType<P> extends PropTypeBase<P> {
296
296
  type: "eventHandler";
297
297
  argTypes: {
298
298
  name: string;
299
- type: PropType<any>;
299
+ type: ArgType<any>;
300
300
  }[];
301
301
  }
302
302
  export interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
@@ -419,6 +419,7 @@ export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
419
419
  export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
420
420
  export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
421
421
  export type PropType<P> = StringType<P> | BooleanType<P> | GraphQLType<P> | NumberType<P> | JSONLikeType<P> | DataSourceType<P> | DataPickerType<P> | ExprEditorType<P> | FormValidationRulesType<P> | EventHandlerType<P> | ChoiceType<P> | CustomType<P> | ImageUrlType<P> | SlotType<P> | DateStringType<P> | DateRangeStringsType<P>;
422
+ export type ArgType<P> = Exclude<PropType<P>, SlotType<P> | EventHandlerType<P>>;
422
423
  export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
423
424
  export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
424
425
  export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
@@ -0,0 +1,105 @@
1
+ export type StringType<T extends string = string> = "string" | `'${T}'`;
2
+ export type NumberType<T extends number = number> = "number" | `${number extends T ? number : T}`;
3
+ export type BooleanType<T extends boolean = boolean> = "boolean" | `${boolean extends T ? boolean : T}`;
4
+ export type NullType = "null";
5
+ export type UndefinedType = "undefined";
6
+ export type ArrayType = "array";
7
+ export type ObjectType = "object";
8
+ export type AnyType = "any";
9
+ export type VoidType = "void";
10
+ export type RestrictedType<T> = T extends string ? StringType<T> : T extends number ? NumberType<T> : T extends boolean ? BooleanType<T> : T extends null ? NullType : T extends undefined ? UndefinedType : T extends Array<any> ? ArrayType : T extends object ? ObjectType : AnyType;
11
+ export type OrType<T> = RestrictedType<T>[];
12
+ export type ParamType<T> = AnyType | RestrictedType<T> | OrType<T>;
13
+ export interface BaseParam<T> {
14
+ name: string;
15
+ type?: ParamType<T>;
16
+ description?: string;
17
+ isOptional?: boolean;
18
+ isRestParam?: boolean;
19
+ }
20
+ export interface RequiredParam<T> extends BaseParam<T> {
21
+ isOptional?: false;
22
+ isRestParameter?: false;
23
+ }
24
+ export interface OptionalParam<T> extends BaseParam<T | undefined> {
25
+ isRestParameter?: false;
26
+ }
27
+ export interface RestParam<T> extends BaseParam<T> {
28
+ isOptional?: false;
29
+ isRestParameter: true;
30
+ }
31
+ type RequiredParams<T extends any[], U extends any[] = []> = Partial<T> extends T ? U : T extends [infer F, ...infer R] ? RequiredParams<R, [...U, F]> : U;
32
+ type OptionalParams<T extends any[]> = T extends [
33
+ ...RequiredParams<T>,
34
+ ...infer R
35
+ ] ? [...R] : [];
36
+ type HandleRequiredParams<P extends any[]> = P extends [infer H, ...infer T] ? [string | RequiredParam<H>, ...HandleRequiredParams<T>] : [];
37
+ type HandleOptionalParams<P extends any[]> = P extends [infer H, ...infer T] ? [] | [string | OptionalParam<H | undefined>, ...HandleOptionalParams<T>] : P extends [] ? [] : P extends Array<infer T> ? [] | [RestParam<T[]>] : [];
38
+ export type HandleParams<P extends any[]> = [
39
+ ...HandleRequiredParams<RequiredParams<P>>,
40
+ ...HandleOptionalParams<Required<OptionalParams<P>>>
41
+ ];
42
+ export type HandleReturnType<T> = VoidType | ParamType<T>;
43
+ export interface CustomFunctionMeta<F extends (...args: any[]) => any> {
44
+ /**
45
+ * The javascript name of the function. Notice it must be unique across all
46
+ * other functions and function namespaces. If two functions have the same
47
+ * name, they should be registered with different `meta.namespace`.
48
+ */
49
+ name: string;
50
+ /**
51
+ * A namespace for organizing groups of functions. It's also used to handle
52
+ * function name collisions. If a function has a namespace, it will be used
53
+ * whenever accessing the function.
54
+ */
55
+ namespace?: string;
56
+ /**
57
+ * Documentation for the registered function.
58
+ */
59
+ description?: string;
60
+ /**
61
+ * An array containing the list of parameters names the function takes.
62
+ * Optionally they can also be registered with the expected param types.
63
+ */
64
+ params?: HandleParams<Parameters<F>>;
65
+ /**
66
+ * Return value information.
67
+ */
68
+ returnValue?: {
69
+ /**
70
+ * The function return type.
71
+ */
72
+ type?: HandleReturnType<ReturnType<F>>;
73
+ /**
74
+ * The function return value description.
75
+ */
76
+ description?: string;
77
+ };
78
+ /**
79
+ * Typescript function declaration. If specified, it ignores the types
80
+ * provided by `params` and `returnValue`.
81
+ */
82
+ typescriptDeclaration?: string;
83
+ /**
84
+ * The path to be used when importing the function in the generated code.
85
+ * It can be the name of the package that contains the function, or the path
86
+ * to the file in the project (relative to the root directory).
87
+ */
88
+ importPath: string;
89
+ /**
90
+ * Whether the function is the default export from that path. Optional: if
91
+ * not specified, it's considered `false`.
92
+ */
93
+ isDefaultExport?: boolean;
94
+ }
95
+ export interface CustomFunctionRegistration {
96
+ function: (...args: any[]) => any;
97
+ meta: CustomFunctionMeta<any>;
98
+ }
99
+ declare global {
100
+ interface Window {
101
+ __PlasmicFunctionsRegistry: CustomFunctionRegistration[];
102
+ }
103
+ }
104
+ export default function unstable_registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
105
+ export {};
@@ -1 +1 @@
1
- export declare const hostVersion = "1.0.166";
1
+ export declare const hostVersion = "1.0.168";
@@ -3,10 +3,11 @@ export * from "./data";
3
3
  export { PlasmicElement } from "./element-types";
4
4
  export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
5
  export * from "./global-actions";
6
- export { Action, ActionProps, CodeComponentMeta, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, stateHelpersKeys, StateHelpers, StateSpec, CodeComponentMode, } from "./registerComponent";
7
- export { PropType, ContextDependentConfig } from "./prop-types";
6
+ export * from "./link";
7
+ export { ContextDependentConfig, PropType } from "./prop-types";
8
+ export { Action, ActionProps, CodeComponentMeta, CodeComponentMode, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, StateHelpers, stateHelpersKeys, StateSpec, } from "./registerComponent";
9
+ export { CustomFunctionMeta, CustomFunctionRegistration, default as unstable_registerFunction, ParamType, } from "./registerFunction";
8
10
  export { default as registerGlobalContext, GlobalContextMeta, GlobalContextRegistration, PropType as GlobalContextPropType, } from "./registerGlobalContext";
9
11
  export { default as registerToken, TokenRegistration, TokenType, } from "./registerToken";
10
12
  export { BasicTrait, ChoiceTrait, default as registerTrait, TraitMeta, TraitRegistration, } from "./registerTrait";
11
13
  export { default as repeatedElement } from "./repeatedElement";
12
- export * from "./link";
@@ -296,7 +296,7 @@ export interface EventHandlerType<P> extends PropTypeBase<P> {
296
296
  type: "eventHandler";
297
297
  argTypes: {
298
298
  name: string;
299
- type: PropType<any>;
299
+ type: ArgType<any>;
300
300
  }[];
301
301
  }
302
302
  export interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
@@ -419,6 +419,7 @@ export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
419
419
  export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
420
420
  export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
421
421
  export type PropType<P> = StringType<P> | BooleanType<P> | GraphQLType<P> | NumberType<P> | JSONLikeType<P> | DataSourceType<P> | DataPickerType<P> | ExprEditorType<P> | FormValidationRulesType<P> | EventHandlerType<P> | ChoiceType<P> | CustomType<P> | ImageUrlType<P> | SlotType<P> | DateStringType<P> | DateRangeStringsType<P>;
422
+ export type ArgType<P> = Exclude<PropType<P>, SlotType<P> | EventHandlerType<P>>;
422
423
  export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
423
424
  export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
424
425
  export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;