@plasmicapp/host 1.0.134 → 1.0.138

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 (79) hide show
  1. package/dist/exports.d.ts +2 -1
  2. package/dist/fetcher.d.ts +1 -1
  3. package/dist/host.esm.js +1 -1
  4. package/dist/host.esm.js.map +1 -1
  5. package/dist/index.cjs.js +1 -1
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/prop-types.d.ts +387 -0
  8. package/dist/registerComponent.d.ts +5 -368
  9. package/dist/registerGlobalContext.d.ts +4 -3
  10. package/dist/version.d.ts +1 -1
  11. package/package.json +2 -2
  12. package/registerComponent/dist/canvas-host.d.ts +41 -0
  13. package/registerComponent/dist/common.d.ts +1 -0
  14. package/registerComponent/dist/data.d.ts +43 -0
  15. package/registerComponent/dist/exports.d.ts +11 -0
  16. package/registerComponent/dist/fetcher.d.ts +40 -0
  17. package/registerComponent/dist/global-actions.d.ts +9 -0
  18. package/registerComponent/dist/index.cjs.js.map +1 -1
  19. package/registerComponent/dist/index.d.ts +1 -0
  20. package/registerComponent/dist/index.esm.js.map +1 -1
  21. package/registerComponent/dist/lang-utils.d.ts +3 -0
  22. package/registerComponent/dist/prop-types.d.ts +387 -0
  23. package/registerComponent/dist/registerComponent.d.ts +5 -368
  24. package/registerComponent/dist/registerGlobalContext.d.ts +76 -0
  25. package/registerComponent/dist/registerToken.d.ts +13 -0
  26. package/registerComponent/dist/registerTrait.d.ts +20 -0
  27. package/registerComponent/dist/repeatedElement.d.ts +15 -0
  28. package/registerComponent/dist/useForceUpdate.d.ts +1 -0
  29. package/registerComponent/dist/version.d.ts +1 -0
  30. package/registerGlobalContext/dist/canvas-host.d.ts +41 -0
  31. package/registerGlobalContext/dist/common.d.ts +1 -0
  32. package/registerGlobalContext/dist/data.d.ts +43 -0
  33. package/registerGlobalContext/dist/exports.d.ts +11 -0
  34. package/registerGlobalContext/dist/fetcher.d.ts +40 -0
  35. package/registerGlobalContext/dist/global-actions.d.ts +9 -0
  36. package/registerGlobalContext/dist/index.cjs.js.map +1 -1
  37. package/registerGlobalContext/dist/index.d.ts +1 -0
  38. package/registerGlobalContext/dist/index.esm.js.map +1 -1
  39. package/registerGlobalContext/dist/lang-utils.d.ts +3 -0
  40. package/registerGlobalContext/dist/prop-types.d.ts +387 -0
  41. package/registerGlobalContext/dist/registerComponent.d.ts +5 -368
  42. package/registerGlobalContext/dist/registerGlobalContext.d.ts +4 -3
  43. package/registerGlobalContext/dist/registerToken.d.ts +13 -0
  44. package/registerGlobalContext/dist/registerTrait.d.ts +20 -0
  45. package/registerGlobalContext/dist/repeatedElement.d.ts +15 -0
  46. package/registerGlobalContext/dist/useForceUpdate.d.ts +1 -0
  47. package/registerGlobalContext/dist/version.d.ts +1 -0
  48. package/registerToken/dist/canvas-host.d.ts +41 -0
  49. package/registerToken/dist/common.d.ts +1 -0
  50. package/registerToken/dist/data.d.ts +43 -0
  51. package/registerToken/dist/element-types.d.ts +115 -0
  52. package/registerToken/dist/exports.d.ts +11 -0
  53. package/registerToken/dist/fetcher.d.ts +40 -0
  54. package/registerToken/dist/global-actions.d.ts +9 -0
  55. package/registerToken/dist/index.d.ts +1 -0
  56. package/registerToken/dist/lang-utils.d.ts +3 -0
  57. package/registerToken/dist/prop-types.d.ts +387 -0
  58. package/registerToken/dist/registerComponent.d.ts +231 -0
  59. package/registerToken/dist/registerGlobalContext.d.ts +76 -0
  60. package/registerToken/dist/registerTrait.d.ts +20 -0
  61. package/registerToken/dist/repeatedElement.d.ts +15 -0
  62. package/registerToken/dist/useForceUpdate.d.ts +1 -0
  63. package/registerToken/dist/version.d.ts +1 -0
  64. package/registerTrait/dist/canvas-host.d.ts +41 -0
  65. package/registerTrait/dist/common.d.ts +1 -0
  66. package/registerTrait/dist/data.d.ts +43 -0
  67. package/registerTrait/dist/element-types.d.ts +115 -0
  68. package/registerTrait/dist/exports.d.ts +11 -0
  69. package/registerTrait/dist/fetcher.d.ts +40 -0
  70. package/registerTrait/dist/global-actions.d.ts +9 -0
  71. package/registerTrait/dist/index.d.ts +1 -0
  72. package/registerTrait/dist/lang-utils.d.ts +3 -0
  73. package/registerTrait/dist/prop-types.d.ts +387 -0
  74. package/registerTrait/dist/registerComponent.d.ts +231 -0
  75. package/registerTrait/dist/registerGlobalContext.d.ts +76 -0
  76. package/registerTrait/dist/registerToken.d.ts +13 -0
  77. package/registerTrait/dist/repeatedElement.d.ts +15 -0
  78. package/registerTrait/dist/useForceUpdate.d.ts +1 -0
  79. package/registerTrait/dist/version.d.ts +1 -0
@@ -0,0 +1,11 @@
1
+ export { PlasmicCanvasContext, PlasmicCanvasHost, usePlasmicCanvasContext, } from "./canvas-host";
2
+ export * from "./data";
3
+ export { PlasmicElement } from "./element-types";
4
+ export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
+ export * from "./global-actions";
6
+ export { Action, ActionProps, CodeComponentMeta, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, StateHelpers, StateSpec, CodeComponentMode, } from "./registerComponent";
7
+ export { PropType, ContextDependentConfig } from "./prop-types";
8
+ export { default as registerGlobalContext, GlobalContextMeta, GlobalContextRegistration, PropType as GlobalContextPropType, } from "./registerGlobalContext";
9
+ export { default as registerToken, TokenRegistration, TokenType, } from "./registerToken";
10
+ export { BasicTrait, ChoiceTrait, default as registerTrait, TraitMeta, TraitRegistration, } from "./registerTrait";
11
+ export { default as repeatedElement } from "./repeatedElement";
@@ -0,0 +1,40 @@
1
+ import { PrimitiveType } from "./prop-types";
2
+ export type Fetcher = (...args: any[]) => Promise<any>;
3
+ export interface FetcherMeta {
4
+ /**
5
+ * Any unique identifying string for this fetcher.
6
+ */
7
+ name: string;
8
+ /**
9
+ * The Studio-user-friendly display name.
10
+ */
11
+ displayName?: string;
12
+ /**
13
+ * The symbol to import from the importPath.
14
+ */
15
+ importName?: string;
16
+ args: {
17
+ name: string;
18
+ type: PrimitiveType;
19
+ }[];
20
+ returns: PrimitiveType;
21
+ /**
22
+ * Either the path to the fetcher relative to `rootDir` or the npm
23
+ * package name
24
+ */
25
+ importPath: string;
26
+ /**
27
+ * Whether it's a default export or named export
28
+ */
29
+ isDefaultExport?: boolean;
30
+ }
31
+ export interface FetcherRegistration {
32
+ fetcher: Fetcher;
33
+ meta: FetcherMeta;
34
+ }
35
+ declare global {
36
+ interface Window {
37
+ __PlasmicFetcherRegistry: FetcherRegistration[];
38
+ }
39
+ }
40
+ export declare function registerFetcher(fetcher: Fetcher, meta: FetcherMeta): void;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ export type GlobalActionDict = Record<string, Function>;
3
+ export declare const GlobalActionsContext: React.Context<GlobalActionDict | undefined>;
4
+ export declare function GlobalActionsProvider(props: {
5
+ contextName: string;
6
+ children?: React.ReactNode;
7
+ actions: GlobalActionDict;
8
+ }): JSX.Element;
9
+ export declare function useGlobalActions(): GlobalActionDict;
@@ -0,0 +1 @@
1
+ export * from "./exports";
@@ -0,0 +1,3 @@
1
+ type StringGen = string | (() => string);
2
+ export declare function ensure<T>(x: T | null | undefined, msg?: StringGen): T;
3
+ export {};
@@ -0,0 +1,387 @@
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
+ };
14
+ export type InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;
15
+ /**
16
+ * Context that we pass back to control functions.
17
+ */
18
+ export type ControlContext<P> = [
19
+ /**
20
+ * props
21
+ */
22
+ P,
23
+ /**
24
+ * `contextData` can be `null` if the prop controls are rendering before
25
+ * the component instance itself (it will re-render once the component
26
+ * calls `setControlContextData`)
27
+ */
28
+ InferDataType<P> | null,
29
+ /**
30
+ * Extra information for the control to use
31
+ */
32
+ ControlExtras
33
+ ];
34
+ /**
35
+ * Config option that takes the context (e.g., props) of the component instance
36
+ * to dynamically set its value.
37
+ */
38
+ export type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;
39
+ export interface PropTypeBase<P> {
40
+ displayName?: string;
41
+ description?: string;
42
+ helpText?: string;
43
+ /**
44
+ * If the user has chosen to use a dynamic expression for this prop, provide
45
+ * a hint as to the expected values that the expression should evaluate to.
46
+ * This hint will be displayed alongside the code editor. You may use
47
+ * markdown in the text here.
48
+ */
49
+ exprHint?: string;
50
+ /**
51
+ * Function for whether this prop should be hidden in the right panel,
52
+ * given the current props for this component
53
+ */
54
+ hidden?: ContextDependentConfig<P, boolean>;
55
+ readOnly?: boolean | ContextDependentConfig<P, boolean>;
56
+ /**
57
+ * If true, will hide the prop in a collapsed section; good for props that
58
+ * should not usually be used.
59
+ */
60
+ advanced?: boolean;
61
+ /**
62
+ * If true, does not allow the user to use a dynamic expression for this prop
63
+ */
64
+ disableDynamicValue?: boolean;
65
+ /**
66
+ * If set to true, the component will be remounted when the prop value is updated.
67
+ * (This behavior only applies to canvas)
68
+ */
69
+ forceRemount?: boolean;
70
+ }
71
+ interface Defaultable<P, T> {
72
+ /**
73
+ * Default value to set for this prop when the component is instantiated
74
+ */
75
+ defaultValue?: T;
76
+ /**
77
+ * If no prop is given, the component uses a default; specify whaat
78
+ * that default is so the Plasmic user can see it in the studio UI
79
+ */
80
+ defaultValueHint?: T | ContextDependentConfig<P, T | undefined>;
81
+ /**
82
+ * Use a dynamic value expression as the default instead
83
+ */
84
+ defaultExpr?: string;
85
+ defaultExprHint?: string;
86
+ }
87
+ interface Controllable {
88
+ /**
89
+ * If true, this is a prop that should only be used inside Plasmic
90
+ * Studio for rendering artboards; will not be actually used in
91
+ * generated code.
92
+ */
93
+ editOnly?: boolean;
94
+ /**
95
+ * If specified, the value used for this prop will instead be
96
+ * mapped to the uncontrolledProp when generating code. This is
97
+ * useful if, for example, in the artboard, you want to use `value`
98
+ * prop to control the component, but in generated code, you want to
99
+ * map it to `defaultValue`.
100
+ */
101
+ uncontrolledProp?: string;
102
+ }
103
+ interface PropTypeBaseDefault<P, T> extends PropTypeBase<P>, Defaultable<P, T>, Controllable {
104
+ }
105
+ interface PlainStringType<P> extends PropTypeBaseDefault<P, string> {
106
+ type: "string";
107
+ control?: "default" | "large";
108
+ }
109
+ interface CodeStringType<P> extends PropTypeBaseDefault<P, string> {
110
+ type: "code";
111
+ lang: "css" | "html" | "javascript" | "json";
112
+ }
113
+ interface RichTextType<P> extends PropTypeBaseDefault<P, string> {
114
+ type: "richText";
115
+ }
116
+ interface ColorType<P> extends PropTypeBaseDefault<P, string> {
117
+ type: "color";
118
+ /**
119
+ * If specified, and the user picks a color token in the Studio, then
120
+ * the value passed in as prop is a css variable reference, like
121
+ * `var(--TOKEN_ID)`, instead of the resolved hex value of the token.
122
+ * You should take care in using this in the proper css context --
123
+ * the css token is only defined if you are rendering under some
124
+ * Plasmic component in the DOM tree, which is usually the case,
125
+ * unless you are using a React portal.
126
+ */
127
+ keepCssVar?: boolean;
128
+ }
129
+ interface ClassType<P> extends PropTypeBase<P> {
130
+ type: "class";
131
+ /**
132
+ * Additional css selectors that can change how this style should look.
133
+ * Some examples:
134
+ *
135
+ * * `:hover` -- on hover
136
+ * * `[data-something="blah"] -- when the element with this class has
137
+ * an html attribute "data-something=blah"
138
+ * * :component[data-something="blah"] :self -- when the root of the
139
+ * component has an html attribute "data-something=blah". Note that
140
+ * the non-standard `:component` selector is used to select the
141
+ * component root, and the non-standard `:self` selector is used
142
+ * to select the element that this class is attached to.
143
+ */
144
+ selectors?: {
145
+ /**
146
+ * A css selector, like `:hover` or `[data-something="blah"]`.
147
+ */
148
+ selector: string;
149
+ /**
150
+ * An optional human-friendly label for the selector, so the studio user
151
+ * knows what this selector means.
152
+ */
153
+ label?: string;
154
+ }[];
155
+ /**
156
+ * If specified, then only shows these style sections for styling this class
157
+ */
158
+ styleSections?: StyleSection[];
159
+ }
160
+ interface ThemeResetClassType<P> extends PropTypeBase<P> {
161
+ type: "themeResetClass";
162
+ /**
163
+ * Normally, theme reset class will only target Plasmic-generated tags
164
+ * with the default tag styles. If you also want to target non-Plasmic-generated
165
+ * tags (say, rendered by your code components, or fetched as an HTML blob
166
+ * from somewhere), then specify `true` here.
167
+ */
168
+ targetAllTags?: boolean;
169
+ }
170
+ interface CardPickerType<P> extends PropTypeBaseDefault<P, string> {
171
+ type: "cardPicker";
172
+ modalTitle?: React.ReactNode | ContextDependentConfig<P, React.ReactNode>;
173
+ options: {
174
+ value: string;
175
+ label?: string;
176
+ imgUrl: string;
177
+ footer?: React.ReactNode;
178
+ }[] | ContextDependentConfig<P, {
179
+ value: string;
180
+ label?: string;
181
+ imgUrl: string;
182
+ footer?: React.ReactNode;
183
+ }[]>;
184
+ showInput?: boolean | ContextDependentConfig<P, boolean>;
185
+ onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
186
+ }
187
+ type RichStringType<P> = PlainStringType<P> | CodeStringType<P> | RichTextType<P> | ColorType<P> | ClassType<P> | ThemeResetClassType<P> | CardPickerType<P>;
188
+ export type StringType<P> = "string" | RichStringType<P>;
189
+ interface RichBooleanType<P> extends PropTypeBaseDefault<P, boolean> {
190
+ type: "boolean";
191
+ }
192
+ export type BooleanType<P> = "boolean" | RichBooleanType<P>;
193
+ type GraphQLValue = {
194
+ query: string;
195
+ variables?: Record<string, any>;
196
+ };
197
+ interface GraphQLType<P> extends PropTypeBaseDefault<P, GraphQLValue> {
198
+ type: "code";
199
+ lang: "graphql";
200
+ endpoint: string | ContextDependentConfig<P, string>;
201
+ method?: string | ContextDependentConfig<P, string>;
202
+ headers?: object | ContextDependentConfig<P, object>;
203
+ }
204
+ interface NumberTypeBase<P> extends PropTypeBaseDefault<P, number> {
205
+ type: "number";
206
+ min?: number | ContextDependentConfig<P, number>;
207
+ max?: number | ContextDependentConfig<P, number>;
208
+ }
209
+ interface PlainNumberType<P> extends NumberTypeBase<P> {
210
+ control?: "default";
211
+ }
212
+ interface SliderNumberType<P> extends NumberTypeBase<P> {
213
+ control: "slider";
214
+ step?: number | ContextDependentConfig<P, number>;
215
+ }
216
+ type RichNumberType<P> = PlainNumberType<P> | SliderNumberType<P>;
217
+ export type NumberType<P> = "number" | RichNumberType<P>;
218
+ interface ObjectType<P> extends PropTypeBaseDefault<P, Record<string, any>> {
219
+ type: "object";
220
+ fields?: Record<string, PropType<P>>;
221
+ nameFunc?: (item: any, ...args: ControlContext<P>) => string | undefined;
222
+ }
223
+ interface ArrayType<P> extends PropTypeBaseDefault<P, any[]> {
224
+ type: "array";
225
+ itemType?: ObjectType<P>;
226
+ /**
227
+ * Optional function that determines whether the user can delete a given item.
228
+ */
229
+ unstable__canDelete?: (item: any, ...args: ControlContext<P>) => boolean;
230
+ /**
231
+ * Specify how to let Plasmic know how to update its own internal representation of the data when the value has
232
+ * changed, or when issuing a minimalValue or shownValue that is different.
233
+ *
234
+ * Important to specify this if you are expecting any nested expression values in this data type!
235
+ */
236
+ unstable__keyFunc?: (item: any) => any;
237
+ /**
238
+ * Specify what would be the tentative new value that is set if the user makes any changes.
239
+ *
240
+ * Useful for field mappings.
241
+ *
242
+ * For instance, consider a Table where we have a `fields` prop:
243
+ *
244
+ * - Initially, the value is undefined. But if the user makes any changes, we would want to save an array of at
245
+ * least three items (corresponding to, say, three columns inferred from a schema).
246
+ *
247
+ * - Let's say there are 5 columns in the value. The data schema changes, removing a column and adding two new
248
+ * ones. Now we would want a different minimal value, containing 6 items.
249
+ */
250
+ unstable__minimalValue?: ContextDependentConfig<P, any>;
251
+ }
252
+ export type JSONLikeType<P> = "object" | ObjectType<P> | ArrayType<P>;
253
+ export interface DataSourceType<P> extends PropTypeBase<P> {
254
+ type: "dataSource";
255
+ dataSource: "airtable" | "cms";
256
+ }
257
+ type DataPickerValueType = string | number | (string | number)[];
258
+ interface DataPickerType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
259
+ type: "dataSelector";
260
+ data: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
261
+ alwaysShowValuePathAsLabel?: boolean;
262
+ }
263
+ interface ExprEditorType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
264
+ type: "exprEditor";
265
+ data: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
266
+ }
267
+ interface FormValidationRulesType<P> extends PropTypeBaseDefault<P, any> {
268
+ type: "formValidationRules";
269
+ }
270
+ interface EventHandlerType<P> extends PropTypeBase<P> {
271
+ type: "eventHandler";
272
+ argTypes: {
273
+ name: string;
274
+ type: PropType<any>;
275
+ }[];
276
+ }
277
+ interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
278
+ type: "choice";
279
+ options: string[] | {
280
+ label: string;
281
+ value: string | number | boolean;
282
+ }[] | ContextDependentConfig<P, string[] | {
283
+ label: string;
284
+ value: string | number | boolean;
285
+ }[]>;
286
+ allowSearch?: boolean;
287
+ filterOption?: boolean;
288
+ onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
289
+ }
290
+ interface SingleChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean> {
291
+ multiSelect?: false;
292
+ }
293
+ interface MultiChoiceType<P> extends ChoiceTypeBase<P, (string | number | boolean)[]> {
294
+ multiSelect: true;
295
+ }
296
+ interface CustomChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean | (string | number | boolean)[]> {
297
+ multiSelect: ContextDependentConfig<P, boolean>;
298
+ }
299
+ export type ChoiceType<P> = SingleChoiceType<P> | MultiChoiceType<P> | CustomChoiceType<P>;
300
+ interface RichSlotType<P> {
301
+ type: "slot";
302
+ /**
303
+ * The unique names of all code components that can be placed in the slot
304
+ */
305
+ allowedComponents?: string[];
306
+ /**
307
+ * Whether the "empty slot" placeholder should be hidden in the canvas.
308
+ */
309
+ hidePlaceholder?: boolean;
310
+ /**
311
+ * Whether the slot is repeated, i.e., is rendered multiple times using
312
+ * repeatedElement().
313
+ */
314
+ isRepeated?: boolean;
315
+ /**
316
+ * A nicer, human-readable display name for your slot prop
317
+ */
318
+ displayName?: string;
319
+ /**
320
+ * Function for whether this slot should be hidden from the left tree,
321
+ * given the current props for this component
322
+ */
323
+ hidden?: ContextDependentConfig<P, boolean>;
324
+ /**
325
+ * If slot is a render prop (accepts a function that takes in some
326
+ * arguments and returns some JSX), then specify the names of the
327
+ * arguments expected by the render prop function.
328
+ */
329
+ renderPropParams?: string[];
330
+ /**
331
+ * When inserting top-level "page sections", should this slot be the default target?
332
+ */
333
+ unstable__isMainContentSlot?: boolean;
334
+ defaultValue?: PlasmicElement | PlasmicElement[];
335
+ }
336
+ type SlotType<P> = "slot" | RichSlotType<P>;
337
+ interface RichImageUrlType<P> extends PropTypeBaseDefault<P, string> {
338
+ type: "imageUrl";
339
+ }
340
+ type ImageUrlType<P> = "imageUrl" | RichImageUrlType<P>;
341
+ export interface ModalProps {
342
+ show?: boolean;
343
+ children?: React.ReactNode;
344
+ onClose: () => void;
345
+ style?: CSSProperties;
346
+ }
347
+ interface CustomControlProps<P> {
348
+ componentProps: P;
349
+ /**
350
+ * `contextData` can be `null` if the prop controls are rendering before
351
+ * the component instance itself (it will re-render once the component
352
+ * calls `setControlContextData`)
353
+ */
354
+ contextData: InferDataType<P> | null;
355
+ value: any;
356
+ /**
357
+ * Sets the value to be passed to the prop. Expects a JSON-compatible value.
358
+ */
359
+ updateValue: (newVal: any) => void;
360
+ /**
361
+ * Full screen modal component
362
+ */
363
+ FullscreenModal: React.ComponentType<ModalProps>;
364
+ /**
365
+ * Modal component for the side pane
366
+ */
367
+ SideModal: React.ComponentType<ModalProps>;
368
+ /**
369
+ * The document that the component will be rendered into; instead of using
370
+ * `document` directly (for, say, `document.querySelector()` etc.), you
371
+ * should use this instead.
372
+ */
373
+ studioDocument: typeof document;
374
+ }
375
+ type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
376
+ interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
377
+ type: "custom";
378
+ control: CustomControl<P>;
379
+ }
380
+ export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
381
+ export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
382
+ 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>;
383
+ type StringCompatType<P> = StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
384
+ type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
385
+ type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
386
+ export type RestrictPropType<T, P> = T extends string ? StringCompatType<P> : T extends boolean ? BoolCompatType<P> : T extends number ? NumberCompatType<P> : PropType<P>;
387
+ export {};
@@ -0,0 +1,231 @@
1
+ /// <reference types="react" />
2
+ import { CodeComponentElement, CSSProperties, PlasmicElement } from "./element-types";
3
+ import { ContextDependentConfig, InferDataType, ModalProps, PropType, RestrictPropType } from "./prop-types";
4
+ export type { CanvasComponentProps, ControlExtras, ControlContext, ContextDependentConfig, PropType, } from "./prop-types";
5
+ export interface ActionProps<P> {
6
+ componentProps: P;
7
+ /**
8
+ * `contextData` can be `null` if the prop controls are rendering before
9
+ * the component instance itself (it will re-render once the component
10
+ * calls `setControlContextData`)
11
+ */
12
+ contextData: InferDataType<P> | null;
13
+ studioOps: {
14
+ showModal: (modalProps: Omit<ModalProps, "onClose"> & {
15
+ onClose?: () => void;
16
+ }) => void;
17
+ refreshQueryData: () => void;
18
+ appendToSlot: (element: PlasmicElement, slotName: string) => void;
19
+ removeFromSlotAt: (pos: number, slotName: string) => void;
20
+ updateProps: (newValues: any) => void;
21
+ };
22
+ /**
23
+ * The document that the component will be rendered into; instead of using
24
+ * `document` directly (for, say, `document.querySelector()` etc.), you
25
+ * should use this instead.
26
+ */
27
+ studioDocument: typeof document;
28
+ }
29
+ export type Action<P> = {
30
+ type: "button-action";
31
+ label: string;
32
+ onClick: (props: ActionProps<P>) => void;
33
+ hidden?: ContextDependentConfig<P, boolean>;
34
+ } | {
35
+ type: "custom-action";
36
+ control: React.ComponentType<ActionProps<P>>;
37
+ hidden?: ContextDependentConfig<P, boolean>;
38
+ };
39
+ type DistributedKeyOf<T> = T extends any ? keyof T : never;
40
+ interface ComponentTemplate<P> extends Omit<CodeComponentElement<P>, "type" | "name"> {
41
+ /**
42
+ * A preview picture for the template.
43
+ */
44
+ previewImg?: string;
45
+ }
46
+ export interface ComponentTemplates<P> {
47
+ [name: string]: ComponentTemplate<P>;
48
+ }
49
+ export type StateSpec = {
50
+ onChangeProp: string;
51
+ } & ({
52
+ type: "readonly";
53
+ variableType: "text";
54
+ initVal?: string;
55
+ } | {
56
+ type: "readonly";
57
+ variableType: "number";
58
+ initVal?: number;
59
+ } | {
60
+ type: "readonly";
61
+ variableType: "boolean";
62
+ initVal?: boolean;
63
+ } | {
64
+ type: "readonly";
65
+ variableType: "array";
66
+ initVal?: any[];
67
+ } | {
68
+ type: "readonly";
69
+ variableType: "object";
70
+ initVal?: object;
71
+ } | {
72
+ type: "writable";
73
+ variableType: "text" | "number" | "boolean" | "array" | "object";
74
+ valueProp: string;
75
+ });
76
+ export interface StateHelpers<P, T> {
77
+ initFunc?: ($props: P) => T;
78
+ onChangeArgsToValue?: (...args: any) => T;
79
+ }
80
+ export type ComponentHelpers<P> = {
81
+ states: Record<string, StateHelpers<P, any>>;
82
+ };
83
+ export type ExternalComponentHelpers<P> = {
84
+ helpers: ComponentHelpers<P>;
85
+ importPath: string;
86
+ } & ({
87
+ importName: string;
88
+ } | {
89
+ isDefaultExport: true;
90
+ });
91
+ export type StyleSection = "visibility" | "typography" | "sizing" | "spacing" | "background" | "transform" | "transitions" | "layout" | "overflow" | "border" | "shadows" | "effects";
92
+ export interface CodeComponentMeta<P> {
93
+ /**
94
+ * Any unique string name used to identify that component. Each component
95
+ * should be registered with a different `meta.name`, even if they have the
96
+ * same name in the code.
97
+ */
98
+ name: string;
99
+ /**
100
+ * The name to be displayed for the component in Studio. Optional: if not
101
+ * specified, `meta.name` is used.
102
+ */
103
+ displayName?: string;
104
+ /**
105
+ * The description of the component to be shown in Studio.
106
+ */
107
+ description?: string;
108
+ /**
109
+ * The javascript name to be used when generating code. Optional: if not
110
+ * provided, `meta.name` is used.
111
+ */
112
+ importName?: string;
113
+ /**
114
+ * An object describing the component properties to be used in Studio.
115
+ * For each `prop`, there should be an entry `meta.props[prop]` describing
116
+ * its type.
117
+ */
118
+ props: {
119
+ [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P>;
120
+ } & {
121
+ [prop: string]: PropType<P>;
122
+ };
123
+ /**
124
+ * An object describing the component states to be used in Studio.
125
+ */
126
+ states?: Record<string, StateSpec>;
127
+ /**
128
+ * An object describing the components helpers to be used in Studio.
129
+ * 1. states helpers: Each state can receive an "initFunc" prop to initialize
130
+ * the implicit state in Studio, and an "onChangeArgsToValue" prop to
131
+ * transform the event handler arguments into a value
132
+ */
133
+ componentHelpers?: ExternalComponentHelpers<P>;
134
+ /**
135
+ * An array describing the component actions to be used in Studio.
136
+ */
137
+ actions?: Action<P>[];
138
+ /**
139
+ * Whether style sections should be shown in Studio. For styles to work, the
140
+ * component must accept a `className` prop. If unset, defaults to all styles.
141
+ * Set to `false` if this component cannot be styled (for example, if it doesn't
142
+ * render any DOM elements).
143
+ */
144
+ styleSections?: StyleSection[] | boolean;
145
+ /**
146
+ * Whether the element can be repeated in Studio. If unset, defaults to true.
147
+ */
148
+ isRepeatable?: boolean;
149
+ /**
150
+ * The path to be used when importing the component in the generated code.
151
+ * It can be the name of the package that contains the component, or the path
152
+ * to the file in the project (relative to the root directory).
153
+ */
154
+ importPath: string;
155
+ /**
156
+ * Whether the component is the default export from that path. Optional: if
157
+ * not specified, it's considered `false`.
158
+ */
159
+ isDefaultExport?: boolean;
160
+ /**
161
+ * The prop that expects the CSS classes with styles to be applied to the
162
+ * component. Optional: if not specified, Plasmic will expect it to be
163
+ * `className`. Notice that if the component does not accept CSS classes, the
164
+ * component will not be able to receive styles from the Studio.
165
+ */
166
+ classNameProp?: string;
167
+ /**
168
+ * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`
169
+ * to interact with components, so it's not used in the generated code.
170
+ * Optional: If not provided, the usual `ref` is used.
171
+ */
172
+ refProp?: string;
173
+ /**
174
+ * Default styles to start with when instantiating the component in Plasmic.
175
+ */
176
+ defaultStyles?: CSSProperties;
177
+ /**
178
+ * Component templates to start with on Plasmic.
179
+ */
180
+ templates?: ComponentTemplates<P>;
181
+ /**
182
+ * Registered name of parent component, used for grouping related components.
183
+ */
184
+ parentComponentName?: string;
185
+ /**
186
+ * Whether the component can be used as an attachment to an element.
187
+ */
188
+ isAttachment?: boolean;
189
+ /**
190
+ * Whether the component provides data to its slots using DataProvider.
191
+ */
192
+ providesData?: boolean;
193
+ /**
194
+ * If specified, then Figma components with the specified names will be mapped
195
+ * to this component when you paste Figma content into Plasmic
196
+ */
197
+ figmaMappings?: {
198
+ figmaComponentName: string;
199
+ }[];
200
+ /**
201
+ * If true, when an instance of this component is added, the element
202
+ * will always be named by the name of this component.
203
+ */
204
+ alwaysAutoName?: boolean;
205
+ refActions?: Record<string, RefActionRegistration<P>>;
206
+ }
207
+ export type CodeComponentMode = "advanced" | "simplified" | "database-schema-driven";
208
+ /**
209
+ * @deprecated use CodeComponentMeta instead
210
+ */
211
+ export type ComponentMeta<P> = CodeComponentMeta<P>;
212
+ export interface FunctionParam<P> {
213
+ name: string;
214
+ displayName?: string;
215
+ type: PropType<P>;
216
+ }
217
+ export interface RefActionRegistration<P> {
218
+ displayName?: string;
219
+ description?: string;
220
+ argTypes: FunctionParam<P>[];
221
+ }
222
+ export interface ComponentRegistration {
223
+ component: React.ComponentType<any>;
224
+ meta: CodeComponentMeta<any>;
225
+ }
226
+ declare global {
227
+ interface Window {
228
+ __PlasmicComponentRegistry: ComponentRegistration[];
229
+ }
230
+ }
231
+ export default function registerComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;