@plasmicapp/host 2.0.0-alpha.0 → 2.0.0-alpha.1

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 (99) hide show
  1. package/dist/data.d.ts +1 -5
  2. package/dist/exports.d.ts +3 -4
  3. package/dist/host.esm.js +6 -17
  4. package/dist/host.esm.js.map +1 -1
  5. package/dist/index.cjs.js +5 -17
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/prop-types.d.ts +6 -475
  8. package/dist/registerComponent.d.ts +8 -11
  9. package/dist/registerFunction.d.ts +2 -127
  10. package/dist/types/choice-type.d.ts +16 -0
  11. package/dist/types/component-types.d.ts +251 -0
  12. package/dist/types/container-types.d.ts +42 -0
  13. package/dist/types/function-types.d.ts +101 -0
  14. package/dist/types/misc-types.d.ts +38 -0
  15. package/dist/types/primitive-types.d.ts +123 -0
  16. package/dist/types/query-builder-types.d.ts +51 -0
  17. package/dist/types/shared-controls.d.ts +50 -0
  18. package/dist/types/type-utils.d.ts +7 -0
  19. package/dist/version.d.ts +1 -1
  20. package/package.json +4 -3
  21. package/registerComponent/dist/data.d.ts +1 -5
  22. package/registerComponent/dist/exports.d.ts +3 -4
  23. package/registerComponent/dist/index.cjs.js.map +1 -1
  24. package/registerComponent/dist/index.esm.js.map +1 -1
  25. package/registerComponent/dist/prop-types.d.ts +6 -475
  26. package/registerComponent/dist/registerComponent.d.ts +8 -11
  27. package/registerComponent/dist/registerFunction.d.ts +2 -127
  28. package/registerComponent/dist/types/choice-type.d.ts +16 -0
  29. package/registerComponent/dist/types/component-types.d.ts +251 -0
  30. package/registerComponent/dist/types/container-types.d.ts +42 -0
  31. package/registerComponent/dist/types/function-types.d.ts +101 -0
  32. package/registerComponent/dist/types/misc-types.d.ts +38 -0
  33. package/registerComponent/dist/types/primitive-types.d.ts +123 -0
  34. package/registerComponent/dist/types/query-builder-types.d.ts +51 -0
  35. package/registerComponent/dist/types/shared-controls.d.ts +50 -0
  36. package/registerComponent/dist/types/type-utils.d.ts +7 -0
  37. package/registerComponent/dist/version.d.ts +1 -1
  38. package/registerFunction/dist/data.d.ts +1 -5
  39. package/registerFunction/dist/exports.d.ts +3 -4
  40. package/registerFunction/dist/index.cjs.js.map +1 -1
  41. package/registerFunction/dist/index.esm.js.map +1 -1
  42. package/registerFunction/dist/prop-types.d.ts +6 -475
  43. package/registerFunction/dist/registerComponent.d.ts +8 -11
  44. package/registerFunction/dist/registerFunction.d.ts +2 -127
  45. package/registerFunction/dist/types/choice-type.d.ts +16 -0
  46. package/registerFunction/dist/types/component-types.d.ts +251 -0
  47. package/registerFunction/dist/types/container-types.d.ts +42 -0
  48. package/registerFunction/dist/types/function-types.d.ts +101 -0
  49. package/registerFunction/dist/types/misc-types.d.ts +38 -0
  50. package/registerFunction/dist/types/primitive-types.d.ts +123 -0
  51. package/registerFunction/dist/types/query-builder-types.d.ts +51 -0
  52. package/registerFunction/dist/types/shared-controls.d.ts +50 -0
  53. package/registerFunction/dist/types/type-utils.d.ts +7 -0
  54. package/registerFunction/dist/version.d.ts +1 -1
  55. package/registerGlobalContext/dist/data.d.ts +1 -5
  56. package/registerGlobalContext/dist/exports.d.ts +3 -4
  57. package/registerGlobalContext/dist/prop-types.d.ts +6 -475
  58. package/registerGlobalContext/dist/registerComponent.d.ts +8 -11
  59. package/registerGlobalContext/dist/registerFunction.d.ts +2 -127
  60. package/registerGlobalContext/dist/types/choice-type.d.ts +16 -0
  61. package/registerGlobalContext/dist/types/component-types.d.ts +251 -0
  62. package/registerGlobalContext/dist/types/container-types.d.ts +42 -0
  63. package/registerGlobalContext/dist/types/function-types.d.ts +101 -0
  64. package/registerGlobalContext/dist/types/misc-types.d.ts +38 -0
  65. package/registerGlobalContext/dist/types/primitive-types.d.ts +123 -0
  66. package/registerGlobalContext/dist/types/query-builder-types.d.ts +51 -0
  67. package/registerGlobalContext/dist/types/shared-controls.d.ts +50 -0
  68. package/registerGlobalContext/dist/types/type-utils.d.ts +7 -0
  69. package/registerGlobalContext/dist/version.d.ts +1 -1
  70. package/registerToken/dist/data.d.ts +1 -5
  71. package/registerToken/dist/exports.d.ts +3 -4
  72. package/registerToken/dist/prop-types.d.ts +6 -475
  73. package/registerToken/dist/registerComponent.d.ts +8 -11
  74. package/registerToken/dist/registerFunction.d.ts +2 -127
  75. package/registerToken/dist/types/choice-type.d.ts +16 -0
  76. package/registerToken/dist/types/component-types.d.ts +251 -0
  77. package/registerToken/dist/types/container-types.d.ts +42 -0
  78. package/registerToken/dist/types/function-types.d.ts +101 -0
  79. package/registerToken/dist/types/misc-types.d.ts +38 -0
  80. package/registerToken/dist/types/primitive-types.d.ts +123 -0
  81. package/registerToken/dist/types/query-builder-types.d.ts +51 -0
  82. package/registerToken/dist/types/shared-controls.d.ts +50 -0
  83. package/registerToken/dist/types/type-utils.d.ts +7 -0
  84. package/registerToken/dist/version.d.ts +1 -1
  85. package/registerTrait/dist/data.d.ts +1 -5
  86. package/registerTrait/dist/exports.d.ts +3 -4
  87. package/registerTrait/dist/prop-types.d.ts +6 -475
  88. package/registerTrait/dist/registerComponent.d.ts +8 -11
  89. package/registerTrait/dist/registerFunction.d.ts +2 -127
  90. package/registerTrait/dist/types/choice-type.d.ts +16 -0
  91. package/registerTrait/dist/types/component-types.d.ts +251 -0
  92. package/registerTrait/dist/types/container-types.d.ts +42 -0
  93. package/registerTrait/dist/types/function-types.d.ts +101 -0
  94. package/registerTrait/dist/types/misc-types.d.ts +38 -0
  95. package/registerTrait/dist/types/primitive-types.d.ts +123 -0
  96. package/registerTrait/dist/types/query-builder-types.d.ts +51 -0
  97. package/registerTrait/dist/types/shared-controls.d.ts +50 -0
  98. package/registerTrait/dist/types/type-utils.d.ts +7 -0
  99. package/registerTrait/dist/version.d.ts +1 -1
@@ -0,0 +1,50 @@
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 {
21
+ description?: string;
22
+ helpText?: string;
23
+ /**
24
+ * If true, will hide the prop in a collapsed section; good for props that
25
+ * should not usually be used.
26
+ */
27
+ advanced?: boolean;
28
+ /**
29
+ * If the user has chosen to use a dynamic expression for this prop, provide
30
+ * a hint as to the expected values that the expression should evaluate to.
31
+ * This hint will be displayed alongside the code editor. You may use
32
+ * markdown in the text here.
33
+ */
34
+ exprHint?: string;
35
+ /**
36
+ * If true, does not allow the user to use a dynamic expression for this prop
37
+ */
38
+ disableDynamicValue?: boolean;
39
+ }
40
+ export interface Defaultable<Ctx extends any[], T> {
41
+ /**
42
+ * Default value to set for this prop when the component is instantiated
43
+ */
44
+ defaultValue?: T;
45
+ /**
46
+ * Specify that default when no prop/param is provided,
47
+ * so the Plasmic user can see it in the studio UI
48
+ */
49
+ defaultValueHint?: T | ContextDependentConfig<Ctx, T | undefined>;
50
+ }
@@ -0,0 +1,7 @@
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[];
7
+ export type Nullish<T> = T | null | undefined;
@@ -1 +1 @@
1
- export declare const hostVersion = "2.0.0-alpha.0";
1
+ export declare const hostVersion = "2.0.0-alpha.1";
@@ -51,12 +51,8 @@ export interface PageParamsProviderProps {
51
51
  * Page query params (e.g. { q: "search term" })
52
52
  */
53
53
  query?: Record<string, string | string[] | undefined>;
54
- /**
55
- * @deprecated Use `route` instead.
56
- */
57
- path?: string;
58
54
  }
59
- export declare function PageParamsProvider({ children, route, path: deprecatedRoute, params, query, }: PageParamsProviderProps): React.JSX.Element;
55
+ export declare function PageParamsProvider({ children, route, params, query, }: PageParamsProviderProps): React.JSX.Element;
60
56
  export declare function DataCtxReader({ children, }: {
61
57
  children: ($ctx: DataDict | undefined) => ReactNode;
62
58
  }): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
@@ -1,12 +1,11 @@
1
1
  export { PlasmicCanvasContext, PlasmicCanvasHost, usePlasmicCanvasComponentInfo, usePlasmicCanvasContext, } from "./canvas-host";
2
2
  export * from "./data";
3
3
  export { PlasmicElement } from "./element-types";
4
- export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
4
  export * from "./global-actions";
6
5
  export * from "./link";
7
- export { ContextDependentConfig, CustomControlProps, ProjectData, PropType, StudioOps, } from "./prop-types";
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";
6
+ export { ChoiceObject, ChoiceOptions, ChoiceValue, ComponentContextConfig, ComponentControlContext, ContextDependentConfig, ControlExtras, CustomControlProps, ProjectData, PropType, StudioOps, } from "./prop-types";
7
+ export { Action, ActionProps, CodeComponentMeta, CodeComponentMode, ComponentHelpers, ComponentRegistration, ComponentTemplates, StateHelpers, StateSpec, default as registerComponent, stateHelpersKeys, } from "./registerComponent";
8
+ export { CustomFunctionMeta, CustomFunctionRegistration, FunctionContextConfig, FunctionControlContext, ParamType, default as registerFunction, } from "./registerFunction";
10
9
  export { GlobalContextMeta, PropType as GlobalContextPropType, GlobalContextRegistration, default as registerGlobalContext, } from "./registerGlobalContext";
11
10
  export { TokenRegistration, TokenType, default as registerToken, } from "./registerToken";
12
11
  export { BasicTrait, ChoiceTrait, TraitMeta, TraitRegistration, default as registerTrait, } from "./registerTrait";
@@ -1,475 +1,6 @@
1
- /// <reference types="react" />
2
- import { CSSProperties, PlasmicElement } from "./element-types";
3
- import { StyleSection } from "./registerComponent";
4
- export interface CanvasComponentProps<Data = any> {
5
- /**
6
- * This prop is only provided within the canvas of Plasmic Studio.
7
- * Allows the component to set data to be consumed by the props' controls.
8
- */
9
- setControlContextData?: (data: Data) => void;
10
- }
11
- export type ControlExtras = {
12
- path: (string | number)[];
13
- item?: any;
14
- };
15
- export type InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;
16
- /**
17
- * Context that we pass back to control functions.
18
- */
19
- export type ControlContext<P> = [
20
- /**
21
- * props
22
- */
23
- P,
24
- /**
25
- * `contextData` can be `null` if the prop controls are rendering before
26
- * the component instance itself (it will re-render once the component
27
- * calls `setControlContextData`)
28
- */
29
- InferDataType<P> | null,
30
- /**
31
- * Extra information for the control to use
32
- */
33
- ControlExtras
34
- ];
35
- /**
36
- * Config option that takes the context (e.g., props) of the component instance
37
- * to dynamically set its value.
38
- */
39
- export type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;
40
- export interface PropTypeBase<P> {
41
- displayName?: string;
42
- description?: string;
43
- helpText?: string;
44
- required?: boolean;
45
- /**
46
- * If the user has chosen to use a dynamic expression for this prop, provide
47
- * a hint as to the expected values that the expression should evaluate to.
48
- * This hint will be displayed alongside the code editor. You may use
49
- * markdown in the text here.
50
- */
51
- exprHint?: string;
52
- /**
53
- * Function for whether this prop should be hidden in the right panel,
54
- * given the current props for this component
55
- */
56
- hidden?: ContextDependentConfig<P, boolean>;
57
- readOnly?: boolean | ContextDependentConfig<P, boolean>;
58
- /**
59
- * If true, will hide the prop in a collapsed section; good for props that
60
- * should not usually be used.
61
- */
62
- advanced?: boolean;
63
- /**
64
- * If true, does not allow the user to use a dynamic expression for this prop
65
- */
66
- disableDynamicValue?: boolean;
67
- /**
68
- * If set to true, the component will be remounted when the prop value is updated.
69
- * (This behavior only applies to canvas)
70
- */
71
- forceRemount?: boolean;
72
- /**
73
- * If true, the prop can't be overriden in different variants.
74
- */
75
- invariantable?: boolean;
76
- }
77
- export interface Defaultable<P, T> {
78
- /**
79
- * Default value to set for this prop when the component is instantiated
80
- */
81
- defaultValue?: T;
82
- /**
83
- * If no prop is given, the component uses a default; specify what
84
- * that default is so the Plasmic user can see it in the studio UI
85
- */
86
- defaultValueHint?: T | ContextDependentConfig<P, T | undefined>;
87
- /**
88
- * Use a dynamic value expression as the default instead
89
- */
90
- defaultExpr?: string;
91
- defaultExprHint?: string;
92
- /**
93
- * This function validates whether the prop value is valid.
94
- * If the value is invalid, it returns an error message. Otherwise, it returns true.
95
- */
96
- validator?: (value: T, ...args: ControlContext<P>) => (string | true) | Promise<string | true>;
97
- }
98
- export interface Controllable {
99
- /**
100
- * If true, this is a prop that should only be used inside Plasmic
101
- * Studio for rendering artboards; will not be actually used in
102
- * generated code.
103
- */
104
- editOnly?: boolean;
105
- /**
106
- * If specified, the value used for this prop will instead be
107
- * mapped to the uncontrolledProp when generating code. This is
108
- * useful if, for example, in the artboard, you want to use `value`
109
- * prop to control the component, but in generated code, you want to
110
- * map it to `defaultValue`.
111
- */
112
- uncontrolledProp?: string;
113
- }
114
- export interface PropTypeBaseDefault<P, T> extends PropTypeBase<P>, Defaultable<P, T>, Controllable {
115
- }
116
- export interface PlainStringType<P> extends PropTypeBaseDefault<P, string> {
117
- type: "string";
118
- control?: "default" | "large";
119
- isLocalizable?: boolean;
120
- }
121
- export interface CodeStringType<P> extends PropTypeBaseDefault<P, string> {
122
- type: "code";
123
- lang: "css" | "html" | "javascript" | "json";
124
- }
125
- export interface RichTextType<P> extends PropTypeBaseDefault<P, string> {
126
- type: "richText";
127
- }
128
- export interface HrefType<P> extends PropTypeBaseDefault<P, string> {
129
- type: "href";
130
- }
131
- export interface ColorType<P> extends PropTypeBaseDefault<P, string> {
132
- type: "color";
133
- /**
134
- * If specified, and the user picks a color token in the Studio, then
135
- * the value passed in as prop is a css variable reference, like
136
- * `var(--TOKEN_ID)`, instead of the resolved hex value of the token.
137
- * You should take care in using this in the proper css context --
138
- * the css token is only defined if you are rendering under some
139
- * Plasmic component in the DOM tree, which is usually the case,
140
- * unless you are using a React portal.
141
- */
142
- keepCssVar?: boolean;
143
- /**
144
- * Prevent tokens from being selected.
145
- */
146
- disableTokens?: boolean;
147
- }
148
- export interface DateStringType<P> extends PropTypeBaseDefault<P, string> {
149
- type: "dateString";
150
- }
151
- export interface DateRangeStringsType<P> extends PropTypeBaseDefault<P, [string, string]> {
152
- type: "dateRangeStrings";
153
- }
154
- export interface ClassType<P> extends PropTypeBase<P> {
155
- type: "class";
156
- /**
157
- * Additional css selectors that can change how this style should look.
158
- * Some examples:
159
- *
160
- * * `:hover` -- on hover
161
- * * `[data-something="blah"] -- when the element with this class has
162
- * an html attribute "data-something=blah"
163
- * * :component[data-something="blah"] :self -- when the root of the
164
- * component has an html attribute "data-something=blah". Note that
165
- * the non-standard `:component` selector is used to select the
166
- * component root, and the non-standard `:self` selector is used
167
- * to select the element that this class is attached to.
168
- */
169
- selectors?: {
170
- /**
171
- * A css selector, like `:hover` or `[data-something="blah"]`.
172
- */
173
- selector: string;
174
- /**
175
- * An optional human-friendly label for the selector, so the studio user
176
- * knows what this selector means.
177
- */
178
- label?: string;
179
- /**
180
- * Initial styles to be applied for this selector
181
- */
182
- defaultStyles?: CSSProperties;
183
- }[];
184
- /**
185
- * If specified, then only shows these style sections for styling this class
186
- */
187
- styleSections?: StyleSection[];
188
- /**
189
- * Initial styles to be applied for this class
190
- */
191
- defaultStyles?: CSSProperties;
192
- }
193
- export interface ThemeResetClassType<P> extends PropTypeBase<P> {
194
- type: "themeResetClass";
195
- /**
196
- * Normally, theme reset class will only target Plasmic-generated tags
197
- * with the default tag styles. If you also want to target non-Plasmic-generated
198
- * tags (say, rendered by your code components, or fetched as an HTML blob
199
- * from somewhere), then specify `true` here.
200
- */
201
- targetAllTags?: boolean;
202
- }
203
- export interface CardPickerType<P> extends PropTypeBaseDefault<P, string> {
204
- type: "cardPicker";
205
- modalTitle?: React.ReactNode | ContextDependentConfig<P, React.ReactNode>;
206
- options: {
207
- value: string;
208
- label?: string;
209
- imgUrl: string;
210
- footer?: React.ReactNode;
211
- }[] | ContextDependentConfig<P, {
212
- value: string;
213
- label?: string;
214
- imgUrl: string;
215
- footer?: React.ReactNode;
216
- }[]>;
217
- showInput?: boolean | ContextDependentConfig<P, boolean>;
218
- onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
219
- }
220
- export type RichStringType<P> = PlainStringType<P> | CodeStringType<P> | RichTextType<P> | ColorType<P> | ClassType<P> | ThemeResetClassType<P> | CardPickerType<P> | HrefType<P>;
221
- export type StringType<P> = "string" | "href" | RichStringType<P>;
222
- export interface RichBooleanType<P> extends PropTypeBaseDefault<P, boolean> {
223
- type: "boolean";
224
- }
225
- export type BooleanType<P> = "boolean" | RichBooleanType<P>;
226
- export type GraphQLValue = {
227
- query: string;
228
- variables?: Record<string, any>;
229
- };
230
- export interface GraphQLType<P> extends PropTypeBaseDefault<P, GraphQLValue> {
231
- type: "code";
232
- lang: "graphql";
233
- endpoint: string | ContextDependentConfig<P, string>;
234
- method?: string | ContextDependentConfig<P, string>;
235
- headers?: object | ContextDependentConfig<P, object>;
236
- }
237
- export interface NumberTypeBase<P> extends PropTypeBaseDefault<P, number> {
238
- type: "number";
239
- min?: number | ContextDependentConfig<P, number>;
240
- max?: number | ContextDependentConfig<P, number>;
241
- }
242
- export interface PlainNumberType<P> extends NumberTypeBase<P> {
243
- control?: "default";
244
- }
245
- export interface SliderNumberType<P> extends NumberTypeBase<P> {
246
- control: "slider";
247
- step?: number | ContextDependentConfig<P, number>;
248
- }
249
- export type RichNumberType<P> = PlainNumberType<P> | SliderNumberType<P>;
250
- export type NumberType<P> = "number" | RichNumberType<P>;
251
- export interface ObjectType<P> extends PropTypeBaseDefault<P, Record<string, any>> {
252
- type: "object";
253
- fields?: Record<string, PropType<P>>;
254
- nameFunc?: (item: any, ...args: ControlContext<P>) => string | undefined;
255
- }
256
- export interface ArrayType<P> extends PropTypeBaseDefault<P, any[]> {
257
- type: "array";
258
- itemType?: ObjectType<P>;
259
- /**
260
- * Optional function that determines whether the user can delete a given item.
261
- */
262
- unstable__canDelete?: (item: any, ...args: ControlContext<P>) => boolean;
263
- /**
264
- * Specify how to let Plasmic know how to update its own internal representation of the data when the value has
265
- * changed, or when issuing a minimalValue or shownValue that is different.
266
- *
267
- * Important to specify this if you are expecting any nested expression values in this data type!
268
- */
269
- unstable__keyFunc?: (item: any) => any;
270
- /**
271
- * Specify what would be the tentative new value that is set if the user makes any changes.
272
- *
273
- * Useful for field mappings.
274
- *
275
- * For instance, consider a Table where we have a `fields` prop:
276
- *
277
- * - Initially, the value is undefined. But if the user makes any changes, we would want to save an array of at
278
- * least three items (corresponding to, say, three columns inferred from a schema).
279
- *
280
- * - Let's say there are 5 columns in the value. The data schema changes, removing a column and adding two new
281
- * ones. Now we would want a different minimal value, containing 6 items.
282
- */
283
- unstable__minimalValue?: ContextDependentConfig<P, any>;
284
- }
285
- export type JSONLikeType<P> = "object" | ObjectType<P> | ArrayType<P>;
286
- export interface DataSourceType<P> extends PropTypeBase<P> {
287
- type: "dataSource";
288
- dataSource: "airtable" | "cms";
289
- }
290
- export type DataPickerValueType = string | number | (string | number)[];
291
- export interface RichDataPickerType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
292
- type: "dataSelector";
293
- data?: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
294
- alwaysShowValuePathAsLabel?: boolean;
295
- isolateEnv?: boolean;
296
- }
297
- export type DataPickerType<P> = "dataPicker" | RichDataPickerType<P>;
298
- export interface RichExprEditorType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
299
- type: "exprEditor";
300
- data?: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
301
- isolateEnv?: boolean;
302
- }
303
- export type ExprEditorType<P> = "exprEditor" | RichExprEditorType<P>;
304
- export interface FormValidationRulesType<P> extends PropTypeBaseDefault<P, any> {
305
- type: "formValidationRules";
306
- }
307
- export interface EventHandlerType<P> extends PropTypeBase<P> {
308
- type: "eventHandler";
309
- argTypes: {
310
- name: string;
311
- type: ArgType<any>;
312
- }[];
313
- }
314
- export interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
315
- type: "choice";
316
- options: (string | number | boolean)[] | {
317
- label: string;
318
- value: string | number | boolean;
319
- }[] | ContextDependentConfig<P, string[] | {
320
- label: string;
321
- value: string | number | boolean;
322
- }[]>;
323
- allowSearch?: boolean;
324
- filterOption?: boolean;
325
- onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
326
- }
327
- export interface SingleChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean> {
328
- multiSelect?: false;
329
- }
330
- export interface MultiChoiceType<P> extends ChoiceTypeBase<P, (string | number | boolean)[]> {
331
- multiSelect: true;
332
- }
333
- export interface CustomChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean | (string | number | boolean)[]> {
334
- multiSelect: ContextDependentConfig<P, boolean>;
335
- }
336
- export type ChoiceType<P> = SingleChoiceType<P> | MultiChoiceType<P> | CustomChoiceType<P>;
337
- export interface RichSlotType<P> {
338
- type: "slot";
339
- description?: string;
340
- /**
341
- * The unique names of all code components that can be placed in the slot
342
- */
343
- allowedComponents?: string[];
344
- /**
345
- * Wheter Plasmic Components with a root component included in the
346
- * "allowedComponents" list are valid or not.
347
- * Only used if the "allowedComponents" list is set.
348
- */
349
- allowRootWrapper?: boolean;
350
- /**
351
- * Whether the "empty slot" placeholder should be hidden in the canvas.
352
- */
353
- hidePlaceholder?: boolean;
354
- /**
355
- * Whether the slot is repeated, i.e., is rendered multiple times using
356
- * repeatedElement().
357
- */
358
- isRepeated?: boolean;
359
- /**
360
- * A nicer, human-readable display name for your slot prop
361
- */
362
- displayName?: string;
363
- /**
364
- * Function for whether this slot should be hidden from the left tree,
365
- * given the current props for this component
366
- */
367
- hidden?: ContextDependentConfig<P, boolean>;
368
- /**
369
- * If slot is a render prop (accepts a function that takes in some
370
- * arguments and returns some JSX), then specify the names of the
371
- * arguments expected by the render prop function.
372
- */
373
- renderPropParams?: string[];
374
- /**
375
- * When inserting top-level "page sections", should this slot be the default target?
376
- */
377
- unstable__isMainContentSlot?: boolean;
378
- defaultValue?: PlasmicElement | PlasmicElement[];
379
- /**
380
- * When true, when you click for the first time in this slot and the component was not selected, the component itself
381
- * is selected, making it easier to select the component instead of slot contents. So for
382
- * instance, setting this on a Button slot ensures that clicking on the Button’s text will still select the Button and not
383
- * the text element in its slot. Clicking again will deep-select the slot content. Similar in this regard to trapsFocus on components.
384
- *
385
- * Furthermore, the component further shows the props of whatever is in the slot on
386
- * the parent component for the user's convenience. Handy for various “wrapper" components, form fields, and so on.
387
- */
388
- mergeWithParent?: boolean | ContextDependentConfig<P, boolean>;
389
- /**
390
- * A function that returns true to hide the merged props conditionally.
391
- */
392
- hiddenMergedProps?: ContextDependentConfig<P, boolean>;
393
- }
394
- export type SlotType<P> = "slot" | RichSlotType<P>;
395
- export interface RichImageUrlType<P> extends PropTypeBaseDefault<P, string> {
396
- type: "imageUrl";
397
- }
398
- export type ImageUrlType<P> = "imageUrl" | RichImageUrlType<P>;
399
- export interface ModalProps {
400
- show?: boolean;
401
- children?: React.ReactNode;
402
- onClose: () => void;
403
- style?: CSSProperties;
404
- }
405
- export interface StudioOps {
406
- showModal: (modalProps: Omit<ModalProps, "onClose"> & {
407
- onClose?: () => void;
408
- }) => void;
409
- refreshQueryData: () => void;
410
- appendToSlot: (element: PlasmicElement, slotName: string) => void;
411
- removeFromSlotAt: (pos: number, slotName: string) => void;
412
- updateProps: (newValues: any) => void;
413
- updateStates: (newValues: any) => void;
414
- }
415
- export interface ProjectData {
416
- components: {
417
- name: string;
418
- }[];
419
- pages: {
420
- name: string;
421
- pageMeta: {
422
- path: string;
423
- };
424
- }[];
425
- }
426
- export interface CustomControlProps<P> {
427
- componentProps: P;
428
- /**
429
- * `contextData` can be `null` if the prop controls are rendering before
430
- * the component instance itself (it will re-render once the component
431
- * calls `setControlContextData`)
432
- */
433
- contextData: InferDataType<P> | null;
434
- /**
435
- * Operations available to the editor that allow modifying the entire component.
436
- * Can be null if the custom prop is used in a global context.
437
- */
438
- studioOps: StudioOps | null;
439
- /**
440
- * Metadata from the studio project.
441
- */
442
- projectData: ProjectData;
443
- value: any;
444
- /**
445
- * Sets the value to be passed to the prop. Expects a JSON-compatible value.
446
- */
447
- updateValue: (newVal: any) => void;
448
- /**
449
- * Full screen modal component
450
- */
451
- FullscreenModal: React.ComponentType<ModalProps>;
452
- /**
453
- * Modal component for the side pane
454
- */
455
- SideModal: React.ComponentType<ModalProps>;
456
- /**
457
- * The document that the component will be rendered into; instead of using
458
- * `document` directly (for, say, `document.querySelector()` etc.), you
459
- * should use this instead.
460
- */
461
- studioDocument: typeof document;
462
- }
463
- export type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
464
- export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
465
- type: "custom";
466
- control: CustomControl<P>;
467
- }
468
- export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
469
- export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
470
- 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>;
471
- export type ArgType<P> = Exclude<PropType<P>, SlotType<P> | EventHandlerType<P>>;
472
- export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
473
- export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
474
- export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
475
- export type RestrictPropType<T, P> = T extends string ? StringCompatType<P> : T extends boolean ? BoolCompatType<P> : T extends number ? NumberCompatType<P> : PropType<P>;
1
+ import { ChoiceObject, ChoiceOptions, ChoiceValue } from "./types/choice-type";
2
+ import { ComponentControlContext, DynamicType } from "./types/component-types";
3
+ import { DataPickerValueType, GraphQLValue } from "./types/misc-types";
4
+ import { CanvasComponentProps, ContextDependentConfig, ControlExtras, InferDataType } from "./types/shared-controls";
5
+ export type { CanvasComponentProps, ChoiceObject, ChoiceOptions, ChoiceValue, ComponentControlContext, ContextDependentConfig, ControlExtras, DataPickerValueType, DynamicType, GraphQLValue, InferDataType, };
6
+ export type * from "./types/component-types";
@@ -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,
@@ -276,10 +277,6 @@ export interface CodeComponentMeta<P> {
276
277
  }>;
277
278
  }
278
279
  export type CodeComponentMode = "advanced" | "simplified" | "database-schema-driven";
279
- /**
280
- * @deprecated use CodeComponentMeta instead
281
- */
282
- export type ComponentMeta<P> = CodeComponentMeta<P>;
283
280
  export interface FunctionParam<P> {
284
281
  name: string;
285
282
  displayName?: string;