@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
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { CodeComponentElement, CSSProperties } from "./element-types";
3
- import { ContextDependentConfig, InferDataType, ProjectData, PropType, RestrictPropType, StudioOps } from "./prop-types";
4
- import { TupleUnion } from "./type-utils";
3
+ import { ComponentContextConfig, ProjectData, PropType, RestrictPropType, StudioOps } from "./types/component-types";
4
+ import { InferDataType } from "./types/shared-controls";
5
+ import { TupleUnion } from "./types/type-utils";
5
6
  export type * from "./prop-types";
6
7
  export interface ActionProps<P> {
7
8
  componentProps: P;
@@ -30,11 +31,11 @@ export type Action<P> = {
30
31
  type: "button-action";
31
32
  label: string;
32
33
  onClick: (props: ActionProps<P>) => void;
33
- hidden?: ContextDependentConfig<P, boolean>;
34
+ hidden?: ComponentContextConfig<P, boolean>;
34
35
  } | {
35
36
  type: "custom-action";
36
37
  control: React.ComponentType<ActionProps<P>>;
37
- hidden?: ContextDependentConfig<P, boolean>;
38
+ hidden?: ComponentContextConfig<P, boolean>;
38
39
  };
39
40
  type DistributedKeyOf<T> = T extends any ? keyof T : never;
40
41
  interface ComponentTemplate<P> extends Omit<CodeComponentElement<P>, "type" | "name"> {
@@ -51,12 +52,12 @@ export type StateSpec<P> = {
51
52
  /**
52
53
  * If true, will hide the state on studio.
53
54
  */
54
- hidden?: ContextDependentConfig<P, boolean>;
55
+ hidden?: ComponentContextConfig<P, boolean>;
55
56
  /**
56
57
  * If true, will hide the state in a collapsed section; good for states that
57
58
  * should not usually be used.
58
59
  */
59
- advanced?: ContextDependentConfig<P, boolean>;
60
+ advanced?: ComponentContextConfig<P, boolean>;
60
61
  } & ({
61
62
  type: "readonly";
62
63
  variableType: "text";
@@ -247,7 +248,7 @@ export interface CodeComponentMeta<P> {
247
248
  * on the left of the Studio. This makes it easy to identify an element when
248
249
  * looking at the tree.
249
250
  */
250
- treeLabel?: ContextDependentConfig<P, string>;
251
+ treeLabel?: ComponentContextConfig<P, string>;
251
252
  /**
252
253
  * The value of the CSS display property used by this component.
253
254
  * Plasmic passes in a class name prop to components to let users style them,
@@ -1,129 +1,5 @@
1
- import { Nullish } from "./type-utils";
2
- /**
3
- * Context that we pass back to control functions.
4
- */
5
- export type ControlContext<P> = [
6
- /**
7
- * props
8
- */
9
- Partial<P>,
10
- /**
11
- * context data
12
- */
13
- any
14
- ];
15
- /**
16
- * Config option that takes the context (e.g., props) of the function call
17
- * to dynamically set its value.
18
- */
19
- export type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;
20
- export interface BaseParam {
21
- name: string;
22
- description?: string;
23
- isOptional?: boolean;
24
- isRestParameter?: boolean;
25
- }
26
- export interface ChoiceTypeBase<P, T> extends BaseParam {
27
- type: "choice";
28
- options: T[] | {
29
- label: string;
30
- value: T;
31
- }[] | ContextDependentConfig<P, T[] | {
32
- label: string;
33
- value: T;
34
- }[]>;
35
- allowSearch?: boolean;
36
- filterOption?: boolean;
37
- onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
38
- }
39
- export interface SingleChoiceType<P, T> extends ChoiceTypeBase<P, T> {
40
- multiSelect?: false;
41
- }
42
- export interface MultiChoiceType<P, T> extends ChoiceTypeBase<P, T[]> {
43
- multiSelect: true;
44
- }
45
- export interface CustomChoiceType<P, T> extends ChoiceTypeBase<P, T | T[]> {
46
- multiSelect: ContextDependentConfig<P, boolean>;
47
- }
48
- export type ChoiceType<P, T> = SingleChoiceType<P, T> | MultiChoiceType<P, T> | CustomChoiceType<P, T>;
49
- export interface PlainStringType<T extends Nullish<string> = string> extends BaseParam {
50
- type: "string" | `'${T}'`;
51
- }
52
- export type StringType<P, T extends Nullish<string> = string> = "string" | PlainStringType<T> | ChoiceType<P, T> | AnyType;
53
- export interface PlainNumberType<T extends Nullish<number> = number> extends BaseParam {
54
- type: "number" | `${number extends T ? number : T}`;
55
- }
56
- export type NumberType<P, T extends Nullish<number> = number> = PlainNumberType<T> | ChoiceType<P, T> | AnyType;
57
- export interface PlainBooleanType<T extends Nullish<boolean> = boolean> extends BaseParam {
58
- type: "boolean" | `${boolean extends T ? boolean : T}`;
59
- }
60
- export type BooleanType<P, T extends Nullish<boolean> = boolean> = PlainBooleanType<T> | ChoiceType<P, T> | AnyType;
61
- export type GraphQLValue = {
62
- query: string;
63
- variables?: Record<string, any>;
64
- };
65
- export interface GraphQLType<P> extends BaseParam {
66
- type: "code";
67
- lang: "graphql";
68
- endpoint: string | ContextDependentConfig<P, string>;
69
- method?: string | ContextDependentConfig<P, string>;
70
- headers?: object | ContextDependentConfig<P, object>;
71
- }
72
- export interface PlainNullType extends BaseParam {
73
- type: "null";
74
- }
75
- export type NullType = PlainNullType | AnyType;
76
- export interface PlainUndefinedType extends BaseParam {
77
- type: "undefined";
78
- }
79
- export type UndefinedType = PlainUndefinedType | AnyType;
80
- export interface PlainArrayType extends BaseParam {
81
- type: "array";
82
- }
83
- export type ArrayType = PlainArrayType | AnyType;
84
- export interface PlainObjectType extends BaseParam {
85
- type: "object";
86
- }
87
- export type ObjectType = PlainObjectType | AnyType;
88
- export interface PlainAnyType extends BaseParam {
89
- type: "any";
90
- }
91
- export type AnyType = PlainAnyType;
92
- export interface PlainVoidType extends BaseParam {
93
- type: "void";
94
- }
95
- export type VoidType = PlainVoidType | AnyType;
96
- type IsAny<T> = 0 extends 1 & T ? true : false;
97
- type CommonType<P, T> = T extends GraphQLValue ? GraphQLType<P> : T extends null ? NullType : T extends undefined ? UndefinedType : T extends Array<any> ? ArrayType : T extends object ? ObjectType : AnyType;
98
- type AnyTyping<P, T> = T extends string ? StringType<P, T> : T extends number ? NumberType<P, T> : T extends boolean ? BooleanType<P, T> : CommonType<P, T>;
99
- export type RestrictedType<P, T> = IsAny<T> extends true ? AnyTyping<P, T> : [T] extends [Nullish<string>] ? StringType<P, T> : [T] extends [Nullish<number>] ? NumberType<P, T> : [T] extends [Nullish<boolean>] ? BooleanType<P, T> : CommonType<P, T>;
100
- export type ParamType<P, T> = RestrictedType<P, T>;
101
- export type RequiredParam<P, T> = ParamType<P, T> & {
102
- isOptional?: false;
103
- isRestParameter?: false;
104
- };
105
- export type OptionalParam<P, T> = ParamType<P, T> & {
106
- isRestParameter?: false;
107
- };
108
- export type RestParam<P, T> = ParamType<P, T> & {
109
- isOptional?: false;
110
- isRestParameter: true;
111
- };
112
- type RequiredParams<T extends any[], U extends any[] = []> = Partial<T> extends T ? U : T extends [infer F, ...infer R] ? RequiredParams<R, [...U, F]> : U;
113
- type OptionalParams<T extends any[]> = T extends [
114
- ...RequiredParams<T>,
115
- ...infer R
116
- ] ? [...R] : [];
117
- type HandleRequiredParams<P, R extends any[]> = R extends [infer H, ...infer T] ? [string | RequiredParam<P, H>, ...HandleRequiredParams<P, T>] : [];
118
- type HandleOptionalParams<P, R extends any[]> = R extends [infer H, ...infer T] ? [] | [
119
- string | OptionalParam<P, H | undefined>,
120
- ...HandleOptionalParams<P, T>
121
- ] : R extends [] ? [] : R extends Array<infer T> ? [] | [RestParam<P, T[]>] : [];
122
- export type HandleParams<P extends any[]> = [
123
- ...HandleRequiredParams<P, RequiredParams<P>>,
124
- ...HandleOptionalParams<P, Required<OptionalParams<P>>>
125
- ];
126
- export type HandleReturnType<P, T> = VoidType | ParamType<P, T>;
1
+ import { HandleParams, HandleReturnType } from "./types/function-types";
2
+ export type * from "./types/function-types";
127
3
  export interface CustomFunctionMeta<F extends (...args: any[]) => any> {
128
4
  /**
129
5
  * The javascript name of the function. Notice it must be unique across all
@@ -206,4 +82,3 @@ declare global {
206
82
  }
207
83
  }
208
84
  export default function registerFunction<F extends (...args: any[]) => any>(fn: F, meta: CustomFunctionMeta<F>): void;
209
- export {};
@@ -0,0 +1,16 @@
1
+ import { MaybeContextDependentConfig } from "./shared-controls";
2
+ export type ChoiceValue = string | number | boolean;
3
+ export type ChoiceObject<T = ChoiceValue> = {
4
+ label: string;
5
+ value: T;
6
+ };
7
+ export type ChoiceOption<T extends ChoiceValue = ChoiceValue> = T | ChoiceObject<T>;
8
+ export type ChoiceOptions<T extends ChoiceValue = ChoiceValue> = T[] | ChoiceObject<T>[];
9
+ export interface ChoiceCore<Ctx extends any[], T extends ChoiceValue> {
10
+ type: "choice";
11
+ options: MaybeContextDependentConfig<Ctx, ChoiceOptions<T>>;
12
+ multiSelect?: MaybeContextDependentConfig<Ctx, boolean>;
13
+ allowSearch?: boolean;
14
+ filterOption?: boolean;
15
+ onSearch?: MaybeContextDependentConfig<Ctx, ((v: string) => void) | undefined>;
16
+ }
@@ -0,0 +1,256 @@
1
+ /// <reference types="react" />
2
+ import { CSSProperties, PlasmicElement } from "../element-types";
3
+ import { ChoiceCore, ChoiceValue } from "./choice-type";
4
+ import { ArrayTypeBaseCore, ObjectTypeBaseCore } from "./container-types";
5
+ import { DataPickerValueType, DataSourceCore, GraphQLCore, GraphQLValue, RichDataPickerCore, RichExprEditorCore } from "./misc-types";
6
+ import { CardPickerCore, ClassCore, CodeStringCore, ColorCore, DateRangeStringsCore, DateStringCore, HrefCore, NumberTypeBaseCore, PlainNumberCore, PlainStringCore, RichBooleanCore, RichTextCore, SliderNumberCore, ThemeResetClassCore } from "./primitive-types";
7
+ import { CommonTypeBase, ContextDependentConfig, ControlExtras, GenericContext, InferDataType } from "./shared-controls";
8
+ export type ComponentControlContext<P> = GenericContext<P, // Full component props
9
+ // Full component props
10
+ InferDataType<P> | null, // Canvas data
11
+ ControlExtras>;
12
+ export type ComponentContextConfig<Props, R> = ContextDependentConfig<ComponentControlContext<Props>, R>;
13
+ export interface PropTypeBase<Ctx extends any[]> extends CommonTypeBase<Ctx> {
14
+ displayName?: string;
15
+ readOnly?: boolean | ContextDependentConfig<Ctx, boolean>;
16
+ /**
17
+ * If true, will hide the prop in a collapsed section; good for props that
18
+ * should not usually be used.
19
+ */
20
+ advanced?: boolean;
21
+ /**
22
+ * If set to true, the component will be remounted when the prop value is updated.
23
+ * (This behavior only applies to canvas)
24
+ */
25
+ forceRemount?: boolean;
26
+ /**
27
+ * If true, the prop can't be overriden in different variants.
28
+ */
29
+ invariantable?: boolean;
30
+ }
31
+ export interface Defaultable<Ctx extends any[], T> {
32
+ /**
33
+ * Default value to set for this prop when the component is instantiated
34
+ */
35
+ defaultValue?: T;
36
+ /**
37
+ * If no prop is given, the component uses a default; specify what
38
+ * that default is so the Plasmic user can see it in the studio UI
39
+ */
40
+ defaultValueHint?: T | ContextDependentConfig<Ctx, T | undefined>;
41
+ /**
42
+ * Use a dynamic value expression as the default instead
43
+ */
44
+ defaultExpr?: string;
45
+ defaultExprHint?: string;
46
+ /**
47
+ * This function validates whether the prop value is valid.
48
+ * If the value is invalid, it returns an error message. Otherwise, it returns true.
49
+ */
50
+ validator?: (value: T, ...args: Ctx) => (string | true) | Promise<string | true>;
51
+ }
52
+ export interface Controllable {
53
+ /**
54
+ * If true, this is a prop that should only be used inside Plasmic
55
+ * Studio for rendering artboards; will not be actually used in
56
+ * generated code.
57
+ */
58
+ editOnly?: boolean;
59
+ /**
60
+ * If specified, the value used for this prop will instead be
61
+ * mapped to the uncontrolledProp when generating code. This is
62
+ * useful if, for example, in the artboard, you want to use `value`
63
+ * prop to control the component, but in generated code, you want to
64
+ * map it to `defaultValue`.
65
+ */
66
+ uncontrolledProp?: string;
67
+ }
68
+ export type PropTypeBaseDefault<P, T> = PropTypeBase<ComponentControlContext<P>> & Defaultable<ComponentControlContext<P>, T> & Controllable;
69
+ export type PlainStringType<P> = PropTypeBaseDefault<P, string> & PlainStringCore;
70
+ export type CodeStringType<P> = PropTypeBaseDefault<P, string> & CodeStringCore;
71
+ export type RichTextType<P> = PropTypeBaseDefault<P, string> & RichTextCore;
72
+ export type HrefType<P> = PropTypeBaseDefault<P, string> & HrefCore;
73
+ export type ColorType<P> = PropTypeBaseDefault<P, string> & ColorCore;
74
+ export type DateStringType<P> = PropTypeBaseDefault<P, string> & DateStringCore;
75
+ export type DateRangeStringsType<P> = PropTypeBaseDefault<P, [string, string]> & DateRangeStringsCore;
76
+ export type ClassType<P> = PropTypeBase<ComponentControlContext<P>> & ClassCore;
77
+ export type ThemeResetClassType<P> = PropTypeBase<ComponentControlContext<P>> & ThemeResetClassCore;
78
+ export type CardPickerType<P> = PropTypeBaseDefault<P, string> & CardPickerCore<ComponentControlContext<P>>;
79
+ export type RichStringType<P> = PlainStringType<P> | CodeStringType<P> | RichTextType<P> | ColorType<P> | ClassType<P> | ThemeResetClassType<P> | CardPickerType<P> | HrefType<P>;
80
+ export type StringType<P> = "string" | "href" | RichStringType<P>;
81
+ export type RichBooleanType<P> = PropTypeBaseDefault<P, boolean> & RichBooleanCore;
82
+ export type BooleanType<P> = "boolean" | RichBooleanType<P>;
83
+ export type GraphQLType<P> = PropTypeBaseDefault<P, GraphQLValue> & GraphQLCore<ComponentControlContext<P>>;
84
+ export type NumberTypeBase<P> = PropTypeBaseDefault<P, number> & NumberTypeBaseCore<ComponentControlContext<P>>;
85
+ export type PlainNumberType<P> = NumberTypeBase<P> & PlainNumberCore<ComponentControlContext<P>>;
86
+ export type SliderNumberType<P> = NumberTypeBase<P> & SliderNumberCore<ComponentControlContext<P>>;
87
+ export type RichNumberType<P> = PlainNumberType<P> | SliderNumberType<P>;
88
+ export type NumberType<P> = "number" | RichNumberType<P>;
89
+ export type ObjectType<P> = PropTypeBaseDefault<P, Record<string, any>> & ObjectTypeBaseCore<ComponentControlContext<P>, PropType<P>>;
90
+ export type ArrayType<P> = PropTypeBaseDefault<P, any[]> & ArrayTypeBaseCore<ComponentControlContext<P>, PropType<P>>;
91
+ export type JSONLikeType<P> = "object" | ObjectType<P> | ArrayType<P>;
92
+ export type DataSourceType<P> = PropTypeBase<ComponentControlContext<P>> & DataSourceCore;
93
+ export type RichDataPickerType<P> = PropTypeBaseDefault<P, DataPickerValueType> & RichDataPickerCore<ComponentControlContext<P>>;
94
+ export type DataPickerType<P> = "dataPicker" | RichDataPickerType<P>;
95
+ export type RichExprEditorType<P> = PropTypeBaseDefault<P, DataPickerValueType> & RichExprEditorCore<ComponentControlContext<P>>;
96
+ export type ExprEditorType<P> = "exprEditor" | RichExprEditorType<P>;
97
+ export type ComponentChoiceType<P, Opt extends ChoiceValue = ChoiceValue, Val = Opt | Opt[]> = PropTypeBaseDefault<P, Val> & ChoiceCore<ComponentControlContext<P>, Opt>;
98
+ export interface SingleChoiceType<P, Opt extends ChoiceValue = ChoiceValue> extends ComponentChoiceType<P, Opt, Opt> {
99
+ multiSelect?: false;
100
+ }
101
+ export interface MultiChoiceType<P, Opt extends ChoiceValue = ChoiceValue> extends ComponentChoiceType<P, Opt, Opt[]> {
102
+ multiSelect: true;
103
+ }
104
+ export interface CustomChoiceType<P> extends ComponentChoiceType<P, ChoiceValue, ChoiceValue | ChoiceValue[]> {
105
+ multiSelect: ComponentContextConfig<P, boolean>;
106
+ }
107
+ export type ChoiceType<P> = SingleChoiceType<P> | MultiChoiceType<P> | CustomChoiceType<P>;
108
+ export interface FormValidationRulesType<P> extends PropTypeBaseDefault<P, any> {
109
+ type: "formValidationRules";
110
+ }
111
+ export interface EventHandlerType<P> extends PropTypeBase<ComponentControlContext<P>> {
112
+ type: "eventHandler";
113
+ argTypes: {
114
+ name: string;
115
+ type: ArgType<any>;
116
+ }[];
117
+ }
118
+ export interface RichSlotType<P> {
119
+ type: "slot";
120
+ description?: string;
121
+ /**
122
+ * The unique names of all code components that can be placed in the slot
123
+ */
124
+ allowedComponents?: string[];
125
+ /**
126
+ * Wheter Plasmic Components with a root component included in the
127
+ * "allowedComponents" list are valid or not.
128
+ * Only used if the "allowedComponents" list is set.
129
+ */
130
+ allowRootWrapper?: boolean;
131
+ /**
132
+ * Whether the "empty slot" placeholder should be hidden in the canvas.
133
+ */
134
+ hidePlaceholder?: boolean;
135
+ /**
136
+ * Whether the slot is repeated, i.e., is rendered multiple times using
137
+ * repeatedElement().
138
+ */
139
+ isRepeated?: boolean;
140
+ /**
141
+ * A nicer, human-readable display name for your slot prop
142
+ */
143
+ displayName?: string;
144
+ /**
145
+ * Function for whether this slot should be hidden from the left tree,
146
+ * given the current props for this component
147
+ */
148
+ hidden?: ComponentContextConfig<P, boolean>;
149
+ /**
150
+ * If slot is a render prop (accepts a function that takes in some
151
+ * arguments and returns some JSX), then specify the names of the
152
+ * arguments expected by the render prop function.
153
+ */
154
+ renderPropParams?: string[];
155
+ /**
156
+ * When inserting top-level "page sections", should this slot be the default target?
157
+ */
158
+ unstable__isMainContentSlot?: boolean;
159
+ defaultValue?: PlasmicElement | PlasmicElement[];
160
+ /**
161
+ * When true, when you click for the first time in this slot and the component was not selected, the component itself
162
+ * is selected, making it easier to select the component instead of slot contents. So for
163
+ * instance, setting this on a Button slot ensures that clicking on the Button’s text will still select the Button and not
164
+ * the text element in its slot. Clicking again will deep-select the slot content. Similar in this regard to trapsFocus on components.
165
+ *
166
+ * Furthermore, the component further shows the props of whatever is in the slot on
167
+ * the parent component for the user's convenience. Handy for various “wrapper" components, form fields, and so on.
168
+ */
169
+ mergeWithParent?: boolean | ComponentContextConfig<P, boolean>;
170
+ /**
171
+ * A function that returns true to hide the merged props conditionally.
172
+ */
173
+ hiddenMergedProps?: ComponentContextConfig<P, boolean>;
174
+ }
175
+ export type SlotType<P> = "slot" | RichSlotType<P>;
176
+ export interface RichImageUrlType<P> extends PropTypeBaseDefault<P, string> {
177
+ type: "imageUrl";
178
+ }
179
+ export type ImageUrlType<P> = "imageUrl" | RichImageUrlType<P>;
180
+ export interface ModalProps {
181
+ show?: boolean;
182
+ children?: React.ReactNode;
183
+ onClose: () => void;
184
+ style?: CSSProperties;
185
+ }
186
+ export interface StudioOps {
187
+ showModal: (modalProps: Omit<ModalProps, "onClose"> & {
188
+ onClose?: () => void;
189
+ }) => void;
190
+ refreshQueryData: () => void;
191
+ appendToSlot: (element: PlasmicElement, slotName: string) => void;
192
+ removeFromSlotAt: (pos: number, slotName: string) => void;
193
+ updateProps: (newValues: any) => void;
194
+ updateStates: (newValues: any) => void;
195
+ }
196
+ export interface ProjectData {
197
+ components: {
198
+ name: string;
199
+ }[];
200
+ pages: {
201
+ name: string;
202
+ pageMeta: {
203
+ path: string;
204
+ };
205
+ }[];
206
+ }
207
+ export interface CustomControlProps<P> {
208
+ componentProps: P;
209
+ /**
210
+ * `contextData` can be `null` if the prop controls are rendering before
211
+ * the component instance itself (it will re-render once the component
212
+ * calls `setControlContextData`)
213
+ */
214
+ contextData: InferDataType<P> | null;
215
+ /**
216
+ * Operations available to the editor that allow modifying the entire component.
217
+ * Can be null if the custom prop is used in a global context.
218
+ */
219
+ studioOps: StudioOps | null;
220
+ /**
221
+ * Metadata from the studio project.
222
+ */
223
+ projectData: ProjectData;
224
+ value: any;
225
+ /**
226
+ * Sets the value to be passed to the prop. Expects a JSON-compatible value.
227
+ */
228
+ updateValue: (newVal: any) => void;
229
+ /**
230
+ * Full screen modal component
231
+ */
232
+ FullscreenModal: React.ComponentType<ModalProps>;
233
+ /**
234
+ * Modal component for the side pane
235
+ */
236
+ SideModal: React.ComponentType<ModalProps>;
237
+ /**
238
+ * The document that the component will be rendered into; instead of using
239
+ * `document` directly (for, say, `document.querySelector()` etc.), you
240
+ * should use this instead.
241
+ */
242
+ studioDocument: typeof document;
243
+ }
244
+ export type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
245
+ export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
246
+ type: "custom";
247
+ control: CustomControl<P>;
248
+ }
249
+ export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
250
+ export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
251
+ 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>;
252
+ export type ArgType<P> = Exclude<PropType<P>, SlotType<P> | EventHandlerType<P>>;
253
+ export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
254
+ export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
255
+ export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
256
+ export type RestrictPropType<T, P> = T extends string ? StringCompatType<P> : T extends boolean ? BoolCompatType<P> : T extends number ? NumberCompatType<P> : PropType<P>;
@@ -0,0 +1,35 @@
1
+ import { ContextDependentConfig } from "./shared-controls";
2
+ export interface ObjectTypeBaseCore<Ctx extends any[], Fields> {
3
+ type: "object";
4
+ fields?: Record<string, Fields>;
5
+ nameFunc?: (item: any, ...args: Ctx) => string | undefined;
6
+ }
7
+ export interface ArrayTypeBaseCore<Ctx extends any[], Fields> {
8
+ type: "array";
9
+ itemType?: ObjectTypeBaseCore<Ctx, Fields>;
10
+ /**
11
+ * Optional function that determines whether the user can delete a given item.
12
+ */
13
+ unstable__canDelete?: (item: any, ...args: Ctx) => boolean;
14
+ /**
15
+ * Specify how to let Plasmic know how to update its own internal representation of the data when the value has
16
+ * changed, or when issuing a minimalValue or shownValue that is different.
17
+ *
18
+ * Important to specify this if you are expecting any nested expression values in this data type!
19
+ */
20
+ unstable__keyFunc?: (item: any) => any;
21
+ /**
22
+ * Specify what would be the tentative new value that is set if the user makes any changes.
23
+ *
24
+ * Useful for field mappings.
25
+ *
26
+ * For instance, consider a Table where we have a `fields` prop:
27
+ *
28
+ * - Initially, the value is undefined. But if the user makes any changes, we would want to save an array of at
29
+ * least three items (corresponding to, say, three columns inferred from a schema).
30
+ *
31
+ * - Let's say there are 5 columns in the value. The data schema changes, removing a column and adding two new
32
+ * ones. Now we would want a different minimal value, containing 6 items.
33
+ */
34
+ unstable__minimalValue?: ContextDependentConfig<Ctx, any>;
35
+ }
@@ -0,0 +1,98 @@
1
+ import { ChoiceCore, ChoiceValue } from "./choice-type";
2
+ import { ArrayTypeBaseCore, ObjectTypeBaseCore } from "./container-types";
3
+ import { GraphQLCore, GraphQLValue } from "./misc-types";
4
+ import { DateRangeStringsCore, DateStringCore, NumberTypeBaseCore, RichBooleanCore } from "./primitive-types";
5
+ import { CommonTypeBase, ContextDependentConfig, GenericContext } from "./shared-controls";
6
+ import { Nullish } from "./type-utils";
7
+ export type FunctionControlContext<P> = GenericContext<Partial<P>, // Partial function props
8
+ any>;
9
+ export type FunctionContextConfig<Args extends any[], R> = ContextDependentConfig<FunctionControlContext<Args>, R>;
10
+ export interface BaseParam {
11
+ name: string;
12
+ description?: string;
13
+ isOptional?: boolean;
14
+ isRestParameter?: boolean;
15
+ }
16
+ export interface FunctionMeta<Args extends any[] = any> extends CommonTypeBase<FunctionControlContext<Args>> {
17
+ name: string;
18
+ rest?: boolean;
19
+ }
20
+ export interface PlainStringType<T extends Nullish<string> = string> extends BaseParam {
21
+ type: "string" | `'${T}'`;
22
+ }
23
+ export type StringType<P, T extends string = string> = "string" | PlainStringType<T> | ChoiceType<P, T> | DateStringType | DateRangeStringsType | AnyType;
24
+ export interface PlainNumberType<T extends Nullish<number> = number> extends BaseParam {
25
+ type: "number" | `${number extends T ? number : T}`;
26
+ }
27
+ export type NumberType<P, T extends number = number> = PlainNumberType<T> | (BaseParam & NumberTypeBaseCore<FunctionControlContext<P>>) | ChoiceType<P, T> | AnyType;
28
+ export interface PlainBooleanType<T extends Nullish<boolean> = boolean> extends BaseParam {
29
+ type: "boolean" | `${boolean extends T ? boolean : T}`;
30
+ }
31
+ export type BooleanType<P, T extends boolean = boolean> = PlainBooleanType<T> | (BaseParam & RichBooleanCore) | ChoiceType<P, T> | AnyType;
32
+ export type GraphQLType<P> = BaseParam & GraphQLCore<FunctionControlContext<P>>;
33
+ export interface PlainNullType extends BaseParam {
34
+ type: "null";
35
+ }
36
+ export type NullType = PlainNullType | AnyType;
37
+ export interface PlainUndefinedType extends BaseParam {
38
+ type: "undefined";
39
+ }
40
+ export type UndefinedType = PlainUndefinedType | AnyType;
41
+ export type ObjectType<P> = BaseParam & ObjectTypeBaseCore<FunctionControlContext<P>, AnyTyping<P, any>>;
42
+ export type ArrayType<P> = BaseParam & ArrayTypeBaseCore<FunctionControlContext<P>, AnyTyping<P, any>>;
43
+ export interface PlainAnyType extends BaseParam {
44
+ type: "any";
45
+ }
46
+ export type AnyType = PlainAnyType;
47
+ export interface PlainVoidType extends BaseParam {
48
+ type: "void";
49
+ }
50
+ export type VoidType = PlainVoidType | AnyType;
51
+ type IsAny<T> = 0 extends 1 & T ? true : false;
52
+ type CommonType<P, T> = T extends GraphQLValue ? GraphQLType<P> : T extends null ? NullType : T extends undefined ? UndefinedType : T extends Array<any> ? ArrayType<P> : T extends object ? ObjectType<P> : AnyType;
53
+ type AnyTyping<P, T> = T extends string ? StringType<P, T> : T extends number ? NumberType<P, T> : T extends boolean ? BooleanType<P, T> : CommonType<P, T>;
54
+ export type ToTuple<T> = T extends any[] ? T : never;
55
+ export type FunctionChoiceType<Args, Opt extends ChoiceValue = ChoiceValue> = FunctionMeta<ToTuple<Args>> & ChoiceCore<FunctionControlContext<ToTuple<Args>>, Opt>;
56
+ export interface SingleChoiceType<P, Opt extends ChoiceValue = ChoiceValue> extends FunctionChoiceType<P, Opt> {
57
+ multiSelect?: false;
58
+ }
59
+ export interface MultiChoiceType<P, Opt extends ChoiceValue = ChoiceValue> extends FunctionChoiceType<P, Opt> {
60
+ multiSelect: true;
61
+ }
62
+ export interface CustomChoiceType<P, Opt extends ChoiceValue = ChoiceValue> extends FunctionChoiceType<P, Opt> {
63
+ multiSelect: FunctionContextConfig<ToTuple<P>, boolean>;
64
+ }
65
+ export type ChoiceType<P, T extends ChoiceValue = ChoiceValue> = SingleChoiceType<P, T> | MultiChoiceType<P, T> | CustomChoiceType<P, T>;
66
+ export type DateStringType = BaseParam & DateStringCore;
67
+ export type DateRangeStringsType = BaseParam & DateRangeStringsCore;
68
+ export type RestrictedType<P, T> = IsAny<T> extends true ? AnyTyping<P, T> : [
69
+ T
70
+ ] extends [string] ? StringType<P, T> : [T] extends [number] ? NumberType<P, T> : [T] extends [boolean] ? BooleanType<P, T> : T extends string | null | undefined ? Exclude<T, null | undefined> extends string ? StringType<P, T extends string ? T : string> : CommonType<P, T> : T extends number | null | undefined ? Exclude<T, null | undefined> extends number ? NumberType<P, T extends number ? T : number> : CommonType<P, T> : T extends boolean | null | undefined ? Exclude<T, null | undefined> extends boolean ? BooleanType<P, T extends boolean ? T : boolean> : CommonType<P, T> : CommonType<P, T>;
71
+ export type ParamType<P, T> = RestrictedType<P, T>;
72
+ export type RequiredParam<P, T> = ParamType<P, T> & {
73
+ isOptional?: false;
74
+ isRestParameter?: false;
75
+ };
76
+ export type OptionalParam<P, T> = ParamType<P, T> & {
77
+ isRestParameter?: false;
78
+ };
79
+ export type RestParam<P, T> = ParamType<P, T> & {
80
+ isOptional?: false;
81
+ isRestParameter: true;
82
+ };
83
+ type RequiredParams<T extends any[], U extends any[] = []> = Partial<T> extends T ? U : T extends [infer F, ...infer R] ? RequiredParams<R, [...U, F]> : U;
84
+ type OptionalParams<T extends any[]> = T extends [
85
+ ...RequiredParams<T>,
86
+ ...infer R
87
+ ] ? [...R] : [];
88
+ type HandleRequiredParams<P, R extends any[]> = R extends [infer H, ...infer T] ? [string | RequiredParam<P, H>, ...HandleRequiredParams<P, T>] : [];
89
+ type HandleOptionalParams<P, R extends any[]> = R extends [infer H, ...infer T] ? [] | [
90
+ string | OptionalParam<P, H | undefined>,
91
+ ...HandleOptionalParams<P, T>
92
+ ] : R extends [] ? [] : R extends Array<infer T> ? [] | [RestParam<P, T[]>] : [];
93
+ export type HandleParams<P extends any[]> = [
94
+ ...HandleRequiredParams<P, RequiredParams<P>>,
95
+ ...HandleOptionalParams<P, Required<OptionalParams<P>>>
96
+ ];
97
+ export type HandleReturnType<P, T> = VoidType | ParamType<P, T>;
98
+ export {};
@@ -0,0 +1,28 @@
1
+ import { ContextDependentConfig } from "./shared-controls";
2
+ export interface RichExprEditorCore<Ctx extends any[]> {
3
+ type: "exprEditor";
4
+ data?: Record<string, any> | ContextDependentConfig<Ctx, Record<string, any>>;
5
+ isolateEnv?: boolean;
6
+ }
7
+ export interface DataSourceCore {
8
+ type: "dataSource";
9
+ dataSource: "airtable" | "cms";
10
+ }
11
+ export type DataPickerValueType = string | number | (string | number)[];
12
+ export interface RichDataPickerCore<Ctx extends any[]> {
13
+ type: "dataSelector";
14
+ data?: Record<string, any> | ContextDependentConfig<Ctx, Record<string, any>>;
15
+ alwaysShowValuePathAsLabel?: boolean;
16
+ isolateEnv?: boolean;
17
+ }
18
+ export type GraphQLValue = {
19
+ query: string;
20
+ variables?: Record<string, any>;
21
+ };
22
+ export interface GraphQLCore<Ctx extends any[]> {
23
+ type: "code";
24
+ lang: "graphql";
25
+ endpoint: string | ContextDependentConfig<Ctx, string>;
26
+ method?: string | ContextDependentConfig<Ctx, string>;
27
+ headers?: object | ContextDependentConfig<Ctx, object>;
28
+ }