@plasmicapp/host 1.0.223 → 1.0.225

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 (87) hide show
  1. package/dist/exports.d.ts +2 -2
  2. package/dist/host.esm.js +1 -1
  3. package/dist/host.esm.js.map +1 -1
  4. package/dist/index.cjs.js +1 -1
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/prop-types.d.ts +6 -478
  7. package/dist/registerComponent.d.ts +8 -7
  8. package/dist/registerFunction.d.ts +2 -127
  9. package/dist/types/choice-type.d.ts +16 -0
  10. package/dist/types/component-types.d.ts +256 -0
  11. package/dist/types/container-types.d.ts +35 -0
  12. package/dist/types/function-types.d.ts +98 -0
  13. package/dist/types/misc-types.d.ts +28 -0
  14. package/dist/types/primitive-types.d.ts +123 -0
  15. package/dist/types/shared-controls.d.ts +40 -0
  16. package/dist/version.d.ts +1 -1
  17. package/package.json +5 -4
  18. package/registerComponent/dist/exports.d.ts +2 -2
  19. package/registerComponent/dist/index.cjs.js.map +1 -1
  20. package/registerComponent/dist/index.esm.js.map +1 -1
  21. package/registerComponent/dist/prop-types.d.ts +6 -478
  22. package/registerComponent/dist/registerComponent.d.ts +8 -7
  23. package/registerComponent/dist/registerFunction.d.ts +2 -127
  24. package/registerComponent/dist/types/choice-type.d.ts +16 -0
  25. package/registerComponent/dist/types/component-types.d.ts +256 -0
  26. package/registerComponent/dist/types/container-types.d.ts +35 -0
  27. package/registerComponent/dist/types/function-types.d.ts +98 -0
  28. package/registerComponent/dist/types/misc-types.d.ts +28 -0
  29. package/registerComponent/dist/types/primitive-types.d.ts +123 -0
  30. package/registerComponent/dist/types/shared-controls.d.ts +40 -0
  31. package/registerComponent/dist/version.d.ts +1 -1
  32. package/registerFunction/dist/exports.d.ts +2 -2
  33. package/registerFunction/dist/index.cjs.js.map +1 -1
  34. package/registerFunction/dist/index.esm.js.map +1 -1
  35. package/registerFunction/dist/prop-types.d.ts +6 -478
  36. package/registerFunction/dist/registerComponent.d.ts +8 -7
  37. package/registerFunction/dist/registerFunction.d.ts +2 -127
  38. package/registerFunction/dist/types/choice-type.d.ts +16 -0
  39. package/registerFunction/dist/types/component-types.d.ts +256 -0
  40. package/registerFunction/dist/types/container-types.d.ts +35 -0
  41. package/registerFunction/dist/types/function-types.d.ts +98 -0
  42. package/registerFunction/dist/types/misc-types.d.ts +28 -0
  43. package/registerFunction/dist/types/primitive-types.d.ts +123 -0
  44. package/registerFunction/dist/types/shared-controls.d.ts +40 -0
  45. package/registerFunction/dist/version.d.ts +1 -1
  46. package/registerGlobalContext/dist/exports.d.ts +2 -2
  47. package/registerGlobalContext/dist/prop-types.d.ts +6 -478
  48. package/registerGlobalContext/dist/registerComponent.d.ts +8 -7
  49. package/registerGlobalContext/dist/registerFunction.d.ts +2 -127
  50. package/registerGlobalContext/dist/types/choice-type.d.ts +16 -0
  51. package/registerGlobalContext/dist/types/component-types.d.ts +256 -0
  52. package/registerGlobalContext/dist/types/container-types.d.ts +35 -0
  53. package/registerGlobalContext/dist/types/function-types.d.ts +98 -0
  54. package/registerGlobalContext/dist/types/misc-types.d.ts +28 -0
  55. package/registerGlobalContext/dist/types/primitive-types.d.ts +123 -0
  56. package/registerGlobalContext/dist/types/shared-controls.d.ts +40 -0
  57. package/registerGlobalContext/dist/version.d.ts +1 -1
  58. package/registerToken/dist/exports.d.ts +2 -2
  59. package/registerToken/dist/prop-types.d.ts +6 -478
  60. package/registerToken/dist/registerComponent.d.ts +8 -7
  61. package/registerToken/dist/registerFunction.d.ts +2 -127
  62. package/registerToken/dist/types/choice-type.d.ts +16 -0
  63. package/registerToken/dist/types/component-types.d.ts +256 -0
  64. package/registerToken/dist/types/container-types.d.ts +35 -0
  65. package/registerToken/dist/types/function-types.d.ts +98 -0
  66. package/registerToken/dist/types/misc-types.d.ts +28 -0
  67. package/registerToken/dist/types/primitive-types.d.ts +123 -0
  68. package/registerToken/dist/types/shared-controls.d.ts +40 -0
  69. package/registerToken/dist/version.d.ts +1 -1
  70. package/registerTrait/dist/exports.d.ts +2 -2
  71. package/registerTrait/dist/prop-types.d.ts +6 -478
  72. package/registerTrait/dist/registerComponent.d.ts +8 -7
  73. package/registerTrait/dist/registerFunction.d.ts +2 -127
  74. package/registerTrait/dist/types/choice-type.d.ts +16 -0
  75. package/registerTrait/dist/types/component-types.d.ts +256 -0
  76. package/registerTrait/dist/types/container-types.d.ts +35 -0
  77. package/registerTrait/dist/types/function-types.d.ts +98 -0
  78. package/registerTrait/dist/types/misc-types.d.ts +28 -0
  79. package/registerTrait/dist/types/primitive-types.d.ts +123 -0
  80. package/registerTrait/dist/types/shared-controls.d.ts +40 -0
  81. package/registerTrait/dist/version.d.ts +1 -1
  82. /package/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
  83. /package/registerComponent/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
  84. /package/registerFunction/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
  85. /package/registerGlobalContext/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
  86. /package/registerToken/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
  87. /package/registerTrait/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
@@ -0,0 +1,123 @@
1
+ /// <reference types="react" />
2
+ import { CSSProperties } from "../element-types";
3
+ import { StyleSection } from "../registerComponent";
4
+ import { ContextDependentConfig } from "./shared-controls";
5
+ export interface RichBooleanCore {
6
+ type: "boolean";
7
+ }
8
+ export interface NumberTypeBaseCore<Ctx extends any[]> {
9
+ type: "number";
10
+ min?: number | ContextDependentConfig<Ctx, number>;
11
+ max?: number | ContextDependentConfig<Ctx, number>;
12
+ }
13
+ export interface PlainNumberCore<Ctx extends any[]> extends NumberTypeBaseCore<Ctx> {
14
+ control?: "default";
15
+ }
16
+ export interface SliderNumberCore<Ctx extends any[]> extends NumberTypeBaseCore<Ctx> {
17
+ control: "slider";
18
+ step?: number | ContextDependentConfig<Ctx, number>;
19
+ }
20
+ export interface PlainStringCore {
21
+ type: "string";
22
+ control?: "default" | "large";
23
+ isLocalizable?: boolean;
24
+ }
25
+ export interface CodeStringCore {
26
+ type: "code";
27
+ lang: "css" | "html" | "javascript" | "json";
28
+ }
29
+ export interface RichTextCore {
30
+ type: "richText";
31
+ }
32
+ export interface HrefCore {
33
+ type: "href";
34
+ }
35
+ export interface ColorCore {
36
+ type: "color";
37
+ /**
38
+ * If specified, and the user picks a color token in the Studio, then
39
+ * the value passed in as prop is a css variable reference, like
40
+ * `var(--TOKEN_ID)`, instead of the resolved hex value of the token.
41
+ * You should take care in using this in the proper css context --
42
+ * the css token is only defined if you are rendering under some
43
+ * Plasmic component in the DOM tree, which is usually the case,
44
+ * unless you are using a React portal.
45
+ */
46
+ keepCssVar?: boolean;
47
+ /**
48
+ * Prevent tokens from being selected.
49
+ */
50
+ disableTokens?: boolean;
51
+ }
52
+ export interface DateStringCore {
53
+ type: "dateString";
54
+ }
55
+ export interface DateRangeStringsCore {
56
+ type: "dateRangeStrings";
57
+ }
58
+ export interface ClassCore {
59
+ type: "class";
60
+ /**
61
+ * Additional css selectors that can change how this style should look.
62
+ * Some examples:
63
+ *
64
+ * * `:hover` -- on hover
65
+ * * `[data-something="blah"] -- when the element with this class has
66
+ * an html attribute "data-something=blah"
67
+ * * :component[data-something="blah"] :self -- when the root of the
68
+ * component has an html attribute "data-something=blah". Note that
69
+ * the non-standard `:component` selector is used to select the
70
+ * component root, and the non-standard `:self` selector is used
71
+ * to select the element that this class is attached to.
72
+ */
73
+ selectors?: {
74
+ /**
75
+ * A css selector, like `:hover` or `[data-something="blah"]`.
76
+ */
77
+ selector: string;
78
+ /**
79
+ * An optional human-friendly label for the selector, so the studio user
80
+ * knows what this selector means.
81
+ */
82
+ label?: string;
83
+ /**
84
+ * Initial styles to be applied for this selector
85
+ */
86
+ defaultStyles?: CSSProperties;
87
+ }[];
88
+ /**
89
+ * If specified, then only shows these style sections for styling this class
90
+ */
91
+ styleSections?: StyleSection[];
92
+ /**
93
+ * Initial styles to be applied for this class
94
+ */
95
+ defaultStyles?: CSSProperties;
96
+ }
97
+ export interface ThemeResetClassCore {
98
+ type: "themeResetClass";
99
+ /**
100
+ * Normally, theme reset class will only target Plasmic-generated tags
101
+ * with the default tag styles. If you also want to target non-Plasmic-generated
102
+ * tags (say, rendered by your code components, or fetched as an HTML blob
103
+ * from somewhere), then specify `true` here.
104
+ */
105
+ targetAllTags?: boolean;
106
+ }
107
+ export interface CardPickerCore<Ctx extends any[]> {
108
+ type: "cardPicker";
109
+ modalTitle?: React.ReactNode | ContextDependentConfig<Ctx, React.ReactNode>;
110
+ options: {
111
+ value: string;
112
+ label?: string;
113
+ imgUrl: string;
114
+ footer?: React.ReactNode;
115
+ }[] | ContextDependentConfig<Ctx, {
116
+ value: string;
117
+ label?: string;
118
+ imgUrl: string;
119
+ footer?: React.ReactNode;
120
+ }[]>;
121
+ showInput?: boolean | ContextDependentConfig<Ctx, boolean>;
122
+ onSearch?: ContextDependentConfig<Ctx, ((value: string) => void) | undefined>;
123
+ }
@@ -0,0 +1,40 @@
1
+ export type GenericContext<Props, Data, Extra = unknown> = [Props, Data, Extra];
2
+ /**
3
+ * Config option that takes the context (e.g., props) of the component instance
4
+ * or function to dynamically set its value.
5
+ */
6
+ export type ContextDependentConfig<Ctx extends any[], R> = (...args: Ctx) => R;
7
+ export type MaybeContextDependentConfig<Ctx extends any[], V> = V | ContextDependentConfig<Ctx, V>;
8
+ export interface CanvasComponentProps<Data = any> {
9
+ /**
10
+ * This prop is only provided within the canvas of Plasmic Studio.
11
+ * Allows the component to set data to be consumed by the props' controls.
12
+ */
13
+ setControlContextData?: (data: Data) => void;
14
+ }
15
+ export type ControlExtras = {
16
+ path: (string | number)[];
17
+ item?: any;
18
+ };
19
+ export type InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;
20
+ export interface CommonTypeBase<Ctx extends any[]> {
21
+ description?: string;
22
+ helpText?: string;
23
+ required?: boolean;
24
+ /**
25
+ * If the user has chosen to use a dynamic expression for this prop, provide
26
+ * a hint as to the expected values that the expression should evaluate to.
27
+ * This hint will be displayed alongside the code editor. You may use
28
+ * markdown in the text here.
29
+ */
30
+ exprHint?: string;
31
+ /**
32
+ * Function for whether this prop should be hidden in the right panel,
33
+ * given the current props for this component
34
+ */
35
+ hidden?: ContextDependentConfig<Ctx, boolean>;
36
+ /**
37
+ * If true, does not allow the user to use a dynamic expression for this prop
38
+ */
39
+ disableDynamicValue?: boolean;
40
+ }
@@ -1 +1 @@
1
- export declare const hostVersion = "1.0.223";
1
+ export declare const hostVersion = "1.0.225";
@@ -4,9 +4,9 @@ export { PlasmicElement } from "./element-types";
4
4
  export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
5
  export * from "./global-actions";
6
6
  export * from "./link";
7
- export { ChoiceObject, ChoiceOptions, ChoiceValue, ContextDependentConfig, CustomControlProps, ProjectData, PropType, StudioOps, } from "./prop-types";
7
+ export { ChoiceObject, ChoiceOptions, ChoiceValue, ComponentContextConfig, ComponentControlContext, ContextDependentConfig, ControlExtras, CustomControlProps, ProjectData, PropType, StudioOps, } from "./prop-types";
8
8
  export { Action, ActionProps, CodeComponentMeta, CodeComponentMode, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, StateHelpers, StateSpec, default as registerComponent, stateHelpersKeys, } from "./registerComponent";
9
- export { CustomFunctionMeta, CustomFunctionRegistration, ParamType, default as registerFunction, } from "./registerFunction";
9
+ export { CustomFunctionMeta, CustomFunctionRegistration, FunctionContextConfig, FunctionControlContext, ParamType, default as registerFunction, } from "./registerFunction";
10
10
  export { GlobalContextMeta, PropType as GlobalContextPropType, GlobalContextRegistration, default as registerGlobalContext, } from "./registerGlobalContext";
11
11
  export { TokenRegistration, TokenType, default as registerToken, } from "./registerToken";
12
12
  export { BasicTrait, ChoiceTrait, TraitMeta, TraitRegistration, default as registerTrait, } from "./registerTrait";
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../src/registerFunction.ts"],"sourcesContent":["import { Nullish } from \"./type-utils\";\n\nconst root = globalThis as any;\n\n/**\n * Context that we pass back to control functions.\n */\nexport type ControlContext<P> = [\n /**\n * props\n */\n Partial<P>,\n /**\n * context data\n */\n any\n];\n\n/**\n * Config option that takes the context (e.g., props) of the function call\n * to dynamically set its value.\n */\nexport type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;\n\nexport interface BaseParam {\n name: string;\n description?: string;\n isOptional?: boolean;\n isRestParameter?: boolean;\n}\n\nexport interface ChoiceTypeBase<P, T> extends BaseParam {\n type: \"choice\";\n options:\n | T[]\n | {\n label: string;\n value: T;\n }[]\n | ContextDependentConfig<\n P,\n | T[]\n | {\n label: string;\n value: T;\n }[]\n >;\n allowSearch?: boolean;\n filterOption?: boolean;\n onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;\n}\n\nexport interface SingleChoiceType<P, T> extends ChoiceTypeBase<P, T> {\n multiSelect?: false;\n}\n\nexport interface MultiChoiceType<P, T> extends ChoiceTypeBase<P, T[]> {\n multiSelect: true;\n}\n\nexport interface CustomChoiceType<P, T> extends ChoiceTypeBase<P, T | T[]> {\n multiSelect: ContextDependentConfig<P, boolean>;\n}\n\nexport type ChoiceType<P, T> =\n | SingleChoiceType<P, T>\n | MultiChoiceType<P, T>\n | CustomChoiceType<P, T>;\n\nexport interface PlainStringType<T extends Nullish<string> = string>\n extends BaseParam {\n type: \"string\" | `'${T}'`;\n}\n\nexport type StringType<P, T extends Nullish<string> = string> =\n | \"string\"\n | PlainStringType<T>\n | ChoiceType<P, T>\n | AnyType;\n\nexport interface PlainNumberType<T extends Nullish<number> = number>\n extends BaseParam {\n type: \"number\" | `${number extends T ? number : T}`;\n}\n\nexport type NumberType<P, T extends Nullish<number> = number> =\n | PlainNumberType<T>\n | ChoiceType<P, T>\n | AnyType;\n\nexport interface PlainBooleanType<T extends Nullish<boolean> = boolean>\n extends BaseParam {\n type: \"boolean\" | `${boolean extends T ? boolean : T}`;\n}\n\nexport type BooleanType<P, T extends Nullish<boolean> = boolean> =\n | PlainBooleanType<T>\n | ChoiceType<P, T>\n | AnyType;\n\nexport type GraphQLValue = {\n query: string;\n variables?: Record<string, any>;\n};\n\nexport interface GraphQLType<P> extends BaseParam {\n type: \"code\";\n lang: \"graphql\";\n endpoint: string | ContextDependentConfig<P, string>;\n method?: string | ContextDependentConfig<P, string>;\n headers?: object | ContextDependentConfig<P, object>;\n}\n\nexport interface PlainNullType extends BaseParam {\n type: \"null\";\n}\nexport type NullType = PlainNullType | AnyType;\n\nexport interface PlainUndefinedType extends BaseParam {\n type: \"undefined\";\n}\nexport type UndefinedType = PlainUndefinedType | AnyType;\n\nexport interface PlainArrayType extends BaseParam {\n type: \"array\";\n}\nexport type ArrayType = PlainArrayType | AnyType;\n\nexport interface PlainObjectType extends BaseParam {\n type: \"object\";\n}\nexport type ObjectType = PlainObjectType | AnyType;\n\nexport interface PlainAnyType extends BaseParam {\n type: \"any\";\n}\nexport type AnyType = PlainAnyType;\n\nexport interface PlainVoidType extends BaseParam {\n type: \"void\";\n}\nexport type VoidType = PlainVoidType | AnyType;\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\ntype CommonType<P, T> = T extends GraphQLValue\n ? GraphQLType<P>\n : T extends null\n ? NullType\n : T extends undefined\n ? UndefinedType\n : T extends Array<any>\n ? ArrayType\n : T extends object\n ? ObjectType\n : AnyType;\n\ntype AnyTyping<P, T> = T extends string\n ? StringType<P, T>\n : T extends number\n ? NumberType<P, T>\n : T extends boolean\n ? BooleanType<P, T>\n : CommonType<P, T>;\n\nexport type RestrictedType<P, T> = IsAny<T> extends true\n ? AnyTyping<P, T>\n : [T] extends [Nullish<string>]\n ? StringType<P, T>\n : [T] extends [Nullish<number>]\n ? NumberType<P, T>\n : [T] extends [Nullish<boolean>]\n ? BooleanType<P, T>\n : CommonType<P, T>;\n\nexport type ParamType<P, T> = RestrictedType<P, T>;\n\nexport type RequiredParam<P, T> = ParamType<P, T> & {\n isOptional?: false;\n isRestParameter?: false;\n};\n\nexport type OptionalParam<P, T> = ParamType<P, T> & {\n isRestParameter?: false;\n};\n\nexport type RestParam<P, T> = ParamType<P, T> & {\n isOptional?: false;\n isRestParameter: true;\n};\n\n// https://stackoverflow.com/questions/70684030/remove-all-optional-items-from-a-tuple-type\ntype RequiredParams<\n T extends any[],\n U extends any[] = []\n> = Partial<T> extends T\n ? U\n : T extends [infer F, ...infer R]\n ? RequiredParams<R, [...U, F]>\n : U;\n\ntype OptionalParams<T extends any[]> = T extends [\n ...RequiredParams<T>,\n ...infer R\n]\n ? [...R]\n : [];\n\ntype HandleRequiredParams<P, R extends any[]> = R extends [infer H, ...infer T]\n ? [string | RequiredParam<P, H>, ...HandleRequiredParams<P, T>]\n : [];\n\ntype HandleOptionalParams<P, R extends any[]> = R extends [infer H, ...infer T]\n ?\n | []\n | [\n string | OptionalParam<P, H | undefined>,\n ...HandleOptionalParams<P, T>\n ]\n : R extends []\n ? []\n : R extends Array<infer T>\n ? [] | [RestParam<P, T[]>]\n : [];\n\nexport type HandleParams<P extends any[]> = [\n ...HandleRequiredParams<P, RequiredParams<P>>,\n ...HandleOptionalParams<P, Required<OptionalParams<P>>>\n];\n\nexport type HandleReturnType<P, T> = VoidType | ParamType<P, T>;\n\nexport interface CustomFunctionMeta<F extends (...args: any[]) => any> {\n /**\n * The javascript name of the function. Notice it must be unique across all\n * other functions and function namespaces. If two functions have the same\n * name, they should be registered with different `meta.namespace`.\n */\n name: string;\n /**\n * A namespace for organizing groups of functions. It's also used to handle\n * function name collisions. If a function has a namespace, it will be used\n * whenever accessing the function.\n */\n namespace?: string;\n /**\n * A display name for the function. It will be shown only in studio.\n */\n displayName?: string;\n /**\n * Documentation for the registered function.\n */\n description?: string;\n /**\n * An array containing the list of parameters names the function takes.\n * Optionally they can also be registered with the expected param types.\n */\n params?: HandleParams<Parameters<F>>;\n /**\n * Return value information.\n */\n returnValue?: {\n /**\n * The function return type.\n */\n type?: HandleReturnType<Parameters<F>, ReturnType<F>>;\n /**\n * The function return value description.\n */\n description?: string;\n };\n /**\n * Typescript function declaration. If specified, it ignores the types\n * provided by `params` and `returnValue`.\n */\n typescriptDeclaration?: string;\n\n /**\n * Whether this function can be used as a query in the editor.\n */\n isQuery?: boolean;\n /**\n * The path to be used when importing the function in the generated code.\n * It can be the name of the package that contains the function, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the function is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n\n /**\n * A function that takes the function arguments and returns a data key\n * and a fetcher function.\n * The data key is used to cache the result of the fetcher, and should only\n * include the arguments that are used to fetch the data.\n * The result of the fetcher will be used as the context of the function\n * in studio and should return a promise.\n */\n fnContext?: (...args: Partial<Parameters<F>>) => {\n dataKey: string;\n fetcher: () => Promise<any>;\n };\n}\n\nexport interface CustomFunctionRegistration {\n function: (...args: any[]) => any;\n meta: CustomFunctionMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFunctionsRegistry: CustomFunctionRegistration[];\n }\n}\n\nif (root.__PlasmicFunctionsRegistry == null) {\n root.__PlasmicFunctionsRegistry = [];\n}\n\nexport default function registerFunction<F extends (...args: any[]) => any>(\n fn: F,\n meta: CustomFunctionMeta<F>\n) {\n // Check for duplicates\n if (\n root.__PlasmicFunctionsRegistry.some(\n (r: CustomFunctionRegistration) =>\n r.function === fn &&\n r.meta.name === meta.name &&\n r.meta.namespace == meta.namespace\n )\n ) {\n return;\n }\n root.__PlasmicFunctionsRegistry.push({ function: fn, meta });\n}\n"],"names":[],"mappings":";;;;;AAEA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA4T/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,gBAAgB,CACtC,EAAK,EACL,IAA2B,EAAA;;AAG3B,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAA6B,EAAA;AAC5B,QAAA,OAAA,CAAC,CAAC,QAAQ,KAAK,EAAE;AACjB,YAAA,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;AACzB,YAAA,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAA;AAFlC,KAEkC,CACrC,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC/D;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../../src/registerFunction.ts"],"sourcesContent":["const root = globalThis as any;\n\nimport { HandleParams, HandleReturnType } from \"./types/function-types\";\nexport type * from \"./types/function-types\";\n\nexport interface CustomFunctionMeta<F extends (...args: any[]) => any> {\n /**\n * The javascript name of the function. Notice it must be unique across all\n * other functions and function namespaces. If two functions have the same\n * name, they should be registered with different `meta.namespace`.\n */\n name: string;\n /**\n * A namespace for organizing groups of functions. It's also used to handle\n * function name collisions. If a function has a namespace, it will be used\n * whenever accessing the function.\n */\n namespace?: string;\n /**\n * A display name for the function. It will be shown only in studio.\n */\n displayName?: string;\n /**\n * Documentation for the registered function.\n */\n description?: string;\n /**\n * An array containing the list of parameters names the function takes.\n * Optionally they can also be registered with the expected param types.\n */\n params?: HandleParams<Parameters<F>>;\n /**\n * Return value information.\n */\n returnValue?: {\n /**\n * The function return type.\n */\n type?: HandleReturnType<Parameters<F>, ReturnType<F>>;\n /**\n * The function return value description.\n */\n description?: string;\n };\n /**\n * Typescript function declaration. If specified, it ignores the types\n * provided by `params` and `returnValue`.\n */\n typescriptDeclaration?: string;\n\n /**\n * Whether this function can be used as a query in the editor.\n */\n isQuery?: boolean;\n /**\n * The path to be used when importing the function in the generated code.\n * It can be the name of the package that contains the function, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the function is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n\n /**\n * A function that takes the function arguments and returns a data key\n * and a fetcher function.\n * The data key is used to cache the result of the fetcher, and should only\n * include the arguments that are used to fetch the data.\n * The result of the fetcher will be used as the context of the function\n * in studio and should return a promise.\n */\n fnContext?: (...args: Partial<Parameters<F>>) => {\n dataKey: string;\n fetcher: () => Promise<any>;\n };\n}\n\nexport interface CustomFunctionRegistration {\n function: (...args: any[]) => any;\n meta: CustomFunctionMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFunctionsRegistry: CustomFunctionRegistration[];\n }\n}\n\nif (root.__PlasmicFunctionsRegistry == null) {\n root.__PlasmicFunctionsRegistry = [];\n}\n\nexport default function registerFunction<F extends (...args: any[]) => any>(\n fn: F,\n meta: CustomFunctionMeta<F>\n) {\n // Check for duplicates\n if (\n root.__PlasmicFunctionsRegistry.some(\n (r: CustomFunctionRegistration) =>\n r.function === fn &&\n r.meta.name === meta.name &&\n r.meta.namespace == meta.namespace\n )\n ) {\n return;\n }\n root.__PlasmicFunctionsRegistry.push({ function: fn, meta });\n}\n"],"names":[],"mappings":";;;;;AAAA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA2F/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,gBAAgB,CACtC,EAAK,EACL,IAA2B,EAAA;;AAG3B,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAA6B,EAAA;AAC5B,QAAA,OAAA,CAAC,CAAC,QAAQ,KAAK,EAAE;AACjB,YAAA,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;AACzB,YAAA,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAA;AAFlC,KAEkC,CACrC,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC/D;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../src/registerFunction.ts"],"sourcesContent":["import { Nullish } from \"./type-utils\";\n\nconst root = globalThis as any;\n\n/**\n * Context that we pass back to control functions.\n */\nexport type ControlContext<P> = [\n /**\n * props\n */\n Partial<P>,\n /**\n * context data\n */\n any\n];\n\n/**\n * Config option that takes the context (e.g., props) of the function call\n * to dynamically set its value.\n */\nexport type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;\n\nexport interface BaseParam {\n name: string;\n description?: string;\n isOptional?: boolean;\n isRestParameter?: boolean;\n}\n\nexport interface ChoiceTypeBase<P, T> extends BaseParam {\n type: \"choice\";\n options:\n | T[]\n | {\n label: string;\n value: T;\n }[]\n | ContextDependentConfig<\n P,\n | T[]\n | {\n label: string;\n value: T;\n }[]\n >;\n allowSearch?: boolean;\n filterOption?: boolean;\n onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;\n}\n\nexport interface SingleChoiceType<P, T> extends ChoiceTypeBase<P, T> {\n multiSelect?: false;\n}\n\nexport interface MultiChoiceType<P, T> extends ChoiceTypeBase<P, T[]> {\n multiSelect: true;\n}\n\nexport interface CustomChoiceType<P, T> extends ChoiceTypeBase<P, T | T[]> {\n multiSelect: ContextDependentConfig<P, boolean>;\n}\n\nexport type ChoiceType<P, T> =\n | SingleChoiceType<P, T>\n | MultiChoiceType<P, T>\n | CustomChoiceType<P, T>;\n\nexport interface PlainStringType<T extends Nullish<string> = string>\n extends BaseParam {\n type: \"string\" | `'${T}'`;\n}\n\nexport type StringType<P, T extends Nullish<string> = string> =\n | \"string\"\n | PlainStringType<T>\n | ChoiceType<P, T>\n | AnyType;\n\nexport interface PlainNumberType<T extends Nullish<number> = number>\n extends BaseParam {\n type: \"number\" | `${number extends T ? number : T}`;\n}\n\nexport type NumberType<P, T extends Nullish<number> = number> =\n | PlainNumberType<T>\n | ChoiceType<P, T>\n | AnyType;\n\nexport interface PlainBooleanType<T extends Nullish<boolean> = boolean>\n extends BaseParam {\n type: \"boolean\" | `${boolean extends T ? boolean : T}`;\n}\n\nexport type BooleanType<P, T extends Nullish<boolean> = boolean> =\n | PlainBooleanType<T>\n | ChoiceType<P, T>\n | AnyType;\n\nexport type GraphQLValue = {\n query: string;\n variables?: Record<string, any>;\n};\n\nexport interface GraphQLType<P> extends BaseParam {\n type: \"code\";\n lang: \"graphql\";\n endpoint: string | ContextDependentConfig<P, string>;\n method?: string | ContextDependentConfig<P, string>;\n headers?: object | ContextDependentConfig<P, object>;\n}\n\nexport interface PlainNullType extends BaseParam {\n type: \"null\";\n}\nexport type NullType = PlainNullType | AnyType;\n\nexport interface PlainUndefinedType extends BaseParam {\n type: \"undefined\";\n}\nexport type UndefinedType = PlainUndefinedType | AnyType;\n\nexport interface PlainArrayType extends BaseParam {\n type: \"array\";\n}\nexport type ArrayType = PlainArrayType | AnyType;\n\nexport interface PlainObjectType extends BaseParam {\n type: \"object\";\n}\nexport type ObjectType = PlainObjectType | AnyType;\n\nexport interface PlainAnyType extends BaseParam {\n type: \"any\";\n}\nexport type AnyType = PlainAnyType;\n\nexport interface PlainVoidType extends BaseParam {\n type: \"void\";\n}\nexport type VoidType = PlainVoidType | AnyType;\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\ntype CommonType<P, T> = T extends GraphQLValue\n ? GraphQLType<P>\n : T extends null\n ? NullType\n : T extends undefined\n ? UndefinedType\n : T extends Array<any>\n ? ArrayType\n : T extends object\n ? ObjectType\n : AnyType;\n\ntype AnyTyping<P, T> = T extends string\n ? StringType<P, T>\n : T extends number\n ? NumberType<P, T>\n : T extends boolean\n ? BooleanType<P, T>\n : CommonType<P, T>;\n\nexport type RestrictedType<P, T> = IsAny<T> extends true\n ? AnyTyping<P, T>\n : [T] extends [Nullish<string>]\n ? StringType<P, T>\n : [T] extends [Nullish<number>]\n ? NumberType<P, T>\n : [T] extends [Nullish<boolean>]\n ? BooleanType<P, T>\n : CommonType<P, T>;\n\nexport type ParamType<P, T> = RestrictedType<P, T>;\n\nexport type RequiredParam<P, T> = ParamType<P, T> & {\n isOptional?: false;\n isRestParameter?: false;\n};\n\nexport type OptionalParam<P, T> = ParamType<P, T> & {\n isRestParameter?: false;\n};\n\nexport type RestParam<P, T> = ParamType<P, T> & {\n isOptional?: false;\n isRestParameter: true;\n};\n\n// https://stackoverflow.com/questions/70684030/remove-all-optional-items-from-a-tuple-type\ntype RequiredParams<\n T extends any[],\n U extends any[] = []\n> = Partial<T> extends T\n ? U\n : T extends [infer F, ...infer R]\n ? RequiredParams<R, [...U, F]>\n : U;\n\ntype OptionalParams<T extends any[]> = T extends [\n ...RequiredParams<T>,\n ...infer R\n]\n ? [...R]\n : [];\n\ntype HandleRequiredParams<P, R extends any[]> = R extends [infer H, ...infer T]\n ? [string | RequiredParam<P, H>, ...HandleRequiredParams<P, T>]\n : [];\n\ntype HandleOptionalParams<P, R extends any[]> = R extends [infer H, ...infer T]\n ?\n | []\n | [\n string | OptionalParam<P, H | undefined>,\n ...HandleOptionalParams<P, T>\n ]\n : R extends []\n ? []\n : R extends Array<infer T>\n ? [] | [RestParam<P, T[]>]\n : [];\n\nexport type HandleParams<P extends any[]> = [\n ...HandleRequiredParams<P, RequiredParams<P>>,\n ...HandleOptionalParams<P, Required<OptionalParams<P>>>\n];\n\nexport type HandleReturnType<P, T> = VoidType | ParamType<P, T>;\n\nexport interface CustomFunctionMeta<F extends (...args: any[]) => any> {\n /**\n * The javascript name of the function. Notice it must be unique across all\n * other functions and function namespaces. If two functions have the same\n * name, they should be registered with different `meta.namespace`.\n */\n name: string;\n /**\n * A namespace for organizing groups of functions. It's also used to handle\n * function name collisions. If a function has a namespace, it will be used\n * whenever accessing the function.\n */\n namespace?: string;\n /**\n * A display name for the function. It will be shown only in studio.\n */\n displayName?: string;\n /**\n * Documentation for the registered function.\n */\n description?: string;\n /**\n * An array containing the list of parameters names the function takes.\n * Optionally they can also be registered with the expected param types.\n */\n params?: HandleParams<Parameters<F>>;\n /**\n * Return value information.\n */\n returnValue?: {\n /**\n * The function return type.\n */\n type?: HandleReturnType<Parameters<F>, ReturnType<F>>;\n /**\n * The function return value description.\n */\n description?: string;\n };\n /**\n * Typescript function declaration. If specified, it ignores the types\n * provided by `params` and `returnValue`.\n */\n typescriptDeclaration?: string;\n\n /**\n * Whether this function can be used as a query in the editor.\n */\n isQuery?: boolean;\n /**\n * The path to be used when importing the function in the generated code.\n * It can be the name of the package that contains the function, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the function is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n\n /**\n * A function that takes the function arguments and returns a data key\n * and a fetcher function.\n * The data key is used to cache the result of the fetcher, and should only\n * include the arguments that are used to fetch the data.\n * The result of the fetcher will be used as the context of the function\n * in studio and should return a promise.\n */\n fnContext?: (...args: Partial<Parameters<F>>) => {\n dataKey: string;\n fetcher: () => Promise<any>;\n };\n}\n\nexport interface CustomFunctionRegistration {\n function: (...args: any[]) => any;\n meta: CustomFunctionMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFunctionsRegistry: CustomFunctionRegistration[];\n }\n}\n\nif (root.__PlasmicFunctionsRegistry == null) {\n root.__PlasmicFunctionsRegistry = [];\n}\n\nexport default function registerFunction<F extends (...args: any[]) => any>(\n fn: F,\n meta: CustomFunctionMeta<F>\n) {\n // Check for duplicates\n if (\n root.__PlasmicFunctionsRegistry.some(\n (r: CustomFunctionRegistration) =>\n r.function === fn &&\n r.meta.name === meta.name &&\n r.meta.namespace == meta.namespace\n )\n ) {\n return;\n }\n root.__PlasmicFunctionsRegistry.push({ function: fn, meta });\n}\n"],"names":[],"mappings":";AAEA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA4T/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,gBAAgB,CACtC,EAAK,EACL,IAA2B,EAAA;;AAG3B,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAA6B,EAAA;AAC5B,QAAA,OAAA,CAAC,CAAC,QAAQ,KAAK,EAAE;AACjB,YAAA,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;AACzB,YAAA,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAA;AAFlC,KAEkC,CACrC,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC/D;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../../src/registerFunction.ts"],"sourcesContent":["const root = globalThis as any;\n\nimport { HandleParams, HandleReturnType } from \"./types/function-types\";\nexport type * from \"./types/function-types\";\n\nexport interface CustomFunctionMeta<F extends (...args: any[]) => any> {\n /**\n * The javascript name of the function. Notice it must be unique across all\n * other functions and function namespaces. If two functions have the same\n * name, they should be registered with different `meta.namespace`.\n */\n name: string;\n /**\n * A namespace for organizing groups of functions. It's also used to handle\n * function name collisions. If a function has a namespace, it will be used\n * whenever accessing the function.\n */\n namespace?: string;\n /**\n * A display name for the function. It will be shown only in studio.\n */\n displayName?: string;\n /**\n * Documentation for the registered function.\n */\n description?: string;\n /**\n * An array containing the list of parameters names the function takes.\n * Optionally they can also be registered with the expected param types.\n */\n params?: HandleParams<Parameters<F>>;\n /**\n * Return value information.\n */\n returnValue?: {\n /**\n * The function return type.\n */\n type?: HandleReturnType<Parameters<F>, ReturnType<F>>;\n /**\n * The function return value description.\n */\n description?: string;\n };\n /**\n * Typescript function declaration. If specified, it ignores the types\n * provided by `params` and `returnValue`.\n */\n typescriptDeclaration?: string;\n\n /**\n * Whether this function can be used as a query in the editor.\n */\n isQuery?: boolean;\n /**\n * The path to be used when importing the function in the generated code.\n * It can be the name of the package that contains the function, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the function is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n\n /**\n * A function that takes the function arguments and returns a data key\n * and a fetcher function.\n * The data key is used to cache the result of the fetcher, and should only\n * include the arguments that are used to fetch the data.\n * The result of the fetcher will be used as the context of the function\n * in studio and should return a promise.\n */\n fnContext?: (...args: Partial<Parameters<F>>) => {\n dataKey: string;\n fetcher: () => Promise<any>;\n };\n}\n\nexport interface CustomFunctionRegistration {\n function: (...args: any[]) => any;\n meta: CustomFunctionMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFunctionsRegistry: CustomFunctionRegistration[];\n }\n}\n\nif (root.__PlasmicFunctionsRegistry == null) {\n root.__PlasmicFunctionsRegistry = [];\n}\n\nexport default function registerFunction<F extends (...args: any[]) => any>(\n fn: F,\n meta: CustomFunctionMeta<F>\n) {\n // Check for duplicates\n if (\n root.__PlasmicFunctionsRegistry.some(\n (r: CustomFunctionRegistration) =>\n r.function === fn &&\n r.meta.name === meta.name &&\n r.meta.namespace == meta.namespace\n )\n ) {\n return;\n }\n root.__PlasmicFunctionsRegistry.push({ function: fn, meta });\n}\n"],"names":[],"mappings":";AAAA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA2F/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,gBAAgB,CACtC,EAAK,EACL,IAA2B,EAAA;;AAG3B,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAA6B,EAAA;AAC5B,QAAA,OAAA,CAAC,CAAC,QAAQ,KAAK,EAAE;AACjB,YAAA,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;AACzB,YAAA,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAA;AAFlC,KAEkC,CACrC,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC/D;;;;"}