@plasmicapp/host 1.0.136 → 1.0.140
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.
- package/dist/exports.d.ts +2 -1
- package/dist/fetcher.d.ts +1 -1
- package/dist/host.esm.js +1 -1
- package/dist/host.esm.js.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/prop-types.d.ts +388 -0
- package/dist/registerComponent.d.ts +2 -368
- package/dist/registerGlobalContext.d.ts +4 -3
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/registerComponent/dist/canvas-host.d.ts +41 -0
- package/registerComponent/dist/common.d.ts +1 -0
- package/registerComponent/dist/data.d.ts +43 -0
- package/registerComponent/dist/exports.d.ts +11 -0
- package/registerComponent/dist/fetcher.d.ts +40 -0
- package/registerComponent/dist/global-actions.d.ts +9 -0
- package/registerComponent/dist/index.cjs.js.map +1 -1
- package/registerComponent/dist/index.d.ts +1 -0
- package/registerComponent/dist/index.esm.js.map +1 -1
- package/registerComponent/dist/lang-utils.d.ts +3 -0
- package/registerComponent/dist/prop-types.d.ts +388 -0
- package/registerComponent/dist/registerComponent.d.ts +2 -368
- package/registerComponent/dist/registerGlobalContext.d.ts +76 -0
- package/registerComponent/dist/registerToken.d.ts +13 -0
- package/registerComponent/dist/registerTrait.d.ts +20 -0
- package/registerComponent/dist/repeatedElement.d.ts +15 -0
- package/registerComponent/dist/useForceUpdate.d.ts +1 -0
- package/registerComponent/dist/version.d.ts +1 -0
- package/registerGlobalContext/dist/canvas-host.d.ts +41 -0
- package/registerGlobalContext/dist/common.d.ts +1 -0
- package/registerGlobalContext/dist/data.d.ts +43 -0
- package/registerGlobalContext/dist/exports.d.ts +11 -0
- package/registerGlobalContext/dist/fetcher.d.ts +40 -0
- package/registerGlobalContext/dist/global-actions.d.ts +9 -0
- package/registerGlobalContext/dist/index.cjs.js.map +1 -1
- package/registerGlobalContext/dist/index.d.ts +1 -0
- package/registerGlobalContext/dist/index.esm.js.map +1 -1
- package/registerGlobalContext/dist/lang-utils.d.ts +3 -0
- package/registerGlobalContext/dist/prop-types.d.ts +388 -0
- package/registerGlobalContext/dist/registerComponent.d.ts +2 -368
- package/registerGlobalContext/dist/registerGlobalContext.d.ts +4 -3
- package/registerGlobalContext/dist/registerToken.d.ts +13 -0
- package/registerGlobalContext/dist/registerTrait.d.ts +20 -0
- package/registerGlobalContext/dist/repeatedElement.d.ts +15 -0
- package/registerGlobalContext/dist/useForceUpdate.d.ts +1 -0
- package/registerGlobalContext/dist/version.d.ts +1 -0
- package/registerToken/dist/canvas-host.d.ts +41 -0
- package/registerToken/dist/common.d.ts +1 -0
- package/registerToken/dist/data.d.ts +43 -0
- package/registerToken/dist/element-types.d.ts +115 -0
- package/registerToken/dist/exports.d.ts +11 -0
- package/registerToken/dist/fetcher.d.ts +40 -0
- package/registerToken/dist/global-actions.d.ts +9 -0
- package/registerToken/dist/index.d.ts +1 -0
- package/registerToken/dist/lang-utils.d.ts +3 -0
- package/registerToken/dist/prop-types.d.ts +388 -0
- package/registerToken/dist/registerComponent.d.ts +231 -0
- package/registerToken/dist/registerGlobalContext.d.ts +76 -0
- package/registerToken/dist/registerTrait.d.ts +20 -0
- package/registerToken/dist/repeatedElement.d.ts +15 -0
- package/registerToken/dist/useForceUpdate.d.ts +1 -0
- package/registerToken/dist/version.d.ts +1 -0
- package/registerTrait/dist/canvas-host.d.ts +41 -0
- package/registerTrait/dist/common.d.ts +1 -0
- package/registerTrait/dist/data.d.ts +43 -0
- package/registerTrait/dist/element-types.d.ts +115 -0
- package/registerTrait/dist/exports.d.ts +11 -0
- package/registerTrait/dist/fetcher.d.ts +40 -0
- package/registerTrait/dist/global-actions.d.ts +9 -0
- package/registerTrait/dist/index.d.ts +1 -0
- package/registerTrait/dist/lang-utils.d.ts +3 -0
- package/registerTrait/dist/prop-types.d.ts +388 -0
- package/registerTrait/dist/registerComponent.d.ts +231 -0
- package/registerTrait/dist/registerGlobalContext.d.ts +76 -0
- package/registerTrait/dist/registerToken.d.ts +13 -0
- package/registerTrait/dist/repeatedElement.d.ts +15 -0
- package/registerTrait/dist/useForceUpdate.d.ts +1 -0
- package/registerTrait/dist/version.d.ts +1 -0
|
@@ -1,372 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CodeComponentElement, CSSProperties, PlasmicElement } from "./element-types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* This prop is only provided within the canvas of Plasmic Studio.
|
|
6
|
-
* Allows the component to set data to be consumed by the props' controls.
|
|
7
|
-
*/
|
|
8
|
-
setControlContextData?: (data: Data) => void;
|
|
9
|
-
}
|
|
10
|
-
type InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;
|
|
11
|
-
export type ControlExtras = {
|
|
12
|
-
path: (string | number)[];
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Context that we pass back to control functions.
|
|
16
|
-
*/
|
|
17
|
-
export type ControlContext<P> = [
|
|
18
|
-
/**
|
|
19
|
-
* props
|
|
20
|
-
*/
|
|
21
|
-
P,
|
|
22
|
-
/**
|
|
23
|
-
* `contextData` can be `null` if the prop controls are rendering before
|
|
24
|
-
* the component instance itself (it will re-render once the component
|
|
25
|
-
* calls `setControlContextData`)
|
|
26
|
-
*/
|
|
27
|
-
InferDataType<P> | null,
|
|
28
|
-
/**
|
|
29
|
-
* Extra information for the control to use
|
|
30
|
-
*/
|
|
31
|
-
ControlExtras
|
|
32
|
-
];
|
|
33
|
-
/**
|
|
34
|
-
* Config option that takes the context (e.g., props) of the component instance
|
|
35
|
-
* to dynamically set its value.
|
|
36
|
-
*/
|
|
37
|
-
export type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;
|
|
38
|
-
export interface PropTypeBase<P> {
|
|
39
|
-
displayName?: string;
|
|
40
|
-
description?: string;
|
|
41
|
-
helpText?: string;
|
|
42
|
-
/**
|
|
43
|
-
* If the user has chosen to use a dynamic expression for this prop, provide
|
|
44
|
-
* a hint as to the expected values that the expression should evaluate to.
|
|
45
|
-
* This hint will be displayed alongside the code editor. You may use
|
|
46
|
-
* markdown in the text here.
|
|
47
|
-
*/
|
|
48
|
-
exprHint?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Function for whether this prop should be hidden in the right panel,
|
|
51
|
-
* given the current props for this component
|
|
52
|
-
*/
|
|
53
|
-
hidden?: ContextDependentConfig<P, boolean>;
|
|
54
|
-
readOnly?: boolean | ContextDependentConfig<P, boolean>;
|
|
55
|
-
/**
|
|
56
|
-
* If true, will hide the prop in a collapsed section; good for props that
|
|
57
|
-
* should not usually be used.
|
|
58
|
-
*/
|
|
59
|
-
advanced?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* If true, does not allow the user to use a dynamic expression for this prop
|
|
62
|
-
*/
|
|
63
|
-
disableDynamicValue?: boolean;
|
|
64
|
-
/**
|
|
65
|
-
* If set to true, the component will be remounted when the prop value is updated.
|
|
66
|
-
* (This behavior only appliees to canvas)
|
|
67
|
-
*/
|
|
68
|
-
forceRemount?: boolean;
|
|
69
|
-
}
|
|
70
|
-
export type DefaultValueOrExpr<P, T> = {
|
|
71
|
-
defaultExpr?: undefined;
|
|
72
|
-
defaultExprHint?: undefined;
|
|
73
|
-
defaultValue?: T;
|
|
74
|
-
defaultValueHint?: T | ContextDependentConfig<P, T | undefined>;
|
|
75
|
-
} | {
|
|
76
|
-
defaultValue?: undefined;
|
|
77
|
-
defaultValueHint?: undefined;
|
|
78
|
-
defaultExpr?: string;
|
|
79
|
-
defaultExprHint?: string;
|
|
80
|
-
};
|
|
81
|
-
type StringTypeBase<P> = PropTypeBase<P> & DefaultValueOrExpr<P, string>;
|
|
82
|
-
export type StringType<P> = "string" | (({
|
|
83
|
-
type: "string";
|
|
84
|
-
control?: "default" | "large";
|
|
85
|
-
} | {
|
|
86
|
-
type: "code";
|
|
87
|
-
lang: "css" | "html" | "javascript" | "json";
|
|
88
|
-
} | {
|
|
89
|
-
type: "richText";
|
|
90
|
-
} | {
|
|
91
|
-
type: "color";
|
|
92
|
-
/**
|
|
93
|
-
* If specified, and the user picks a color token in the Studio, then
|
|
94
|
-
* the value passed in as prop is a css variable reference, like
|
|
95
|
-
* `var(--TOKEN_ID)`, instead of the resolved hex value of the token.
|
|
96
|
-
* You should take care in using this in the proper css context --
|
|
97
|
-
* the css token is only defined if you are rendering under some
|
|
98
|
-
* Plasmic component in the DOM tree, which is usually the case,
|
|
99
|
-
* unless you are using a React portal.
|
|
100
|
-
*/
|
|
101
|
-
keepCssVar?: boolean;
|
|
102
|
-
} | {
|
|
103
|
-
type: "class";
|
|
104
|
-
/**
|
|
105
|
-
* Additional css selectors that can change how this style should look.
|
|
106
|
-
* Some examples:
|
|
107
|
-
*
|
|
108
|
-
* * `:hover` -- on hover
|
|
109
|
-
* * `[data-something="blah"] -- when the element with this class has
|
|
110
|
-
* an html attribute "data-something=blah"
|
|
111
|
-
* * :component[data-something="blah"] :self -- when the root of the
|
|
112
|
-
* component has an html attribute "data-something=blah". Note that
|
|
113
|
-
* the non-standard `:component` selector is used to select the
|
|
114
|
-
* component root, and the non-standard `:self` selector is used
|
|
115
|
-
* to select the element that this class is attached to.
|
|
116
|
-
*/
|
|
117
|
-
selectors?: {
|
|
118
|
-
/**
|
|
119
|
-
* A css selector, like `:hover` or `[data-something="blah"]`.
|
|
120
|
-
*/
|
|
121
|
-
selector: string;
|
|
122
|
-
/**
|
|
123
|
-
* An optional human-friendly label for the selector, so the studio user
|
|
124
|
-
* knows what this selector means.
|
|
125
|
-
*/
|
|
126
|
-
label?: string;
|
|
127
|
-
}[];
|
|
128
|
-
/**
|
|
129
|
-
* If specified, then only shows these style sections for styling this class
|
|
130
|
-
*/
|
|
131
|
-
styleSections?: StyleSection[];
|
|
132
|
-
} | {
|
|
133
|
-
type: "themeResetClass";
|
|
134
|
-
/**
|
|
135
|
-
* Normally, theme reset class will only target Plasmic-generated tags
|
|
136
|
-
* with the default tag styles. If you also want to target non-Plasmic-generated
|
|
137
|
-
* tags (say, rendered by your code components, or fetched as an HTML blob
|
|
138
|
-
* from somewhere), then specify `true` here.
|
|
139
|
-
*/
|
|
140
|
-
targetAllTags?: boolean;
|
|
141
|
-
} | {
|
|
142
|
-
type: "cardPicker";
|
|
143
|
-
modalTitle?: React.ReactNode | ContextDependentConfig<P, React.ReactNode>;
|
|
144
|
-
options: {
|
|
145
|
-
value: string;
|
|
146
|
-
label?: string;
|
|
147
|
-
imgUrl: string;
|
|
148
|
-
footer?: React.ReactNode;
|
|
149
|
-
}[] | ContextDependentConfig<P, {
|
|
150
|
-
value: string;
|
|
151
|
-
label?: string;
|
|
152
|
-
imgUrl: string;
|
|
153
|
-
footer?: React.ReactNode;
|
|
154
|
-
}[]>;
|
|
155
|
-
showInput?: boolean | ContextDependentConfig<P, boolean>;
|
|
156
|
-
onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
|
|
157
|
-
}) & StringTypeBase<P>);
|
|
158
|
-
export type BooleanType<P> = "boolean" | ({
|
|
159
|
-
type: "boolean";
|
|
160
|
-
} & DefaultValueOrExpr<P, boolean> & PropTypeBase<P>);
|
|
161
|
-
type GraphQLValue = {
|
|
162
|
-
query: string;
|
|
163
|
-
variables?: Record<string, any>;
|
|
164
|
-
};
|
|
165
|
-
export type GraphQLType<P> = {
|
|
166
|
-
type: "code";
|
|
167
|
-
lang: "graphql";
|
|
168
|
-
endpoint: string | ContextDependentConfig<P, string>;
|
|
169
|
-
method?: string | ContextDependentConfig<P, string>;
|
|
170
|
-
headers?: object | ContextDependentConfig<P, object>;
|
|
171
|
-
} & DefaultValueOrExpr<P, GraphQLValue> & PropTypeBase<P>;
|
|
172
|
-
type NumberTypeBase<P> = PropTypeBase<P> & DefaultValueOrExpr<P, number> & {
|
|
173
|
-
type: "number";
|
|
174
|
-
};
|
|
175
|
-
export type NumberType<P> = "number" | (({
|
|
176
|
-
control?: "default";
|
|
177
|
-
min?: number | ContextDependentConfig<P, number>;
|
|
178
|
-
max?: number | ContextDependentConfig<P, number>;
|
|
179
|
-
} | {
|
|
180
|
-
control: "slider";
|
|
181
|
-
min: number | ContextDependentConfig<P, number>;
|
|
182
|
-
max: number | ContextDependentConfig<P, number>;
|
|
183
|
-
step?: number | ContextDependentConfig<P, number>;
|
|
184
|
-
}) & NumberTypeBase<P>);
|
|
185
|
-
/**
|
|
186
|
-
* Expects defaultValue to be a JSON-compatible value
|
|
187
|
-
*/
|
|
188
|
-
export type JSONLikeType<P> = "object" | ({
|
|
189
|
-
type: "object";
|
|
190
|
-
fields?: {
|
|
191
|
-
[p: string]: PropType<P>;
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* Optional function that generates a name for this item in the array
|
|
195
|
-
*/
|
|
196
|
-
nameFunc?: (item: any, ...args: ControlContext<P>) => string | undefined;
|
|
197
|
-
} & DefaultValueOrExpr<P, any> & PropTypeBase<P>) | ({
|
|
198
|
-
type: "array";
|
|
199
|
-
itemType?: {
|
|
200
|
-
type: "object";
|
|
201
|
-
fields: {
|
|
202
|
-
[p: string]: PropType<P>;
|
|
203
|
-
};
|
|
204
|
-
/**
|
|
205
|
-
* Optional function that generates a name for this item in the array
|
|
206
|
-
*/
|
|
207
|
-
nameFunc?: (item: any, ...args: ControlContext<P>) => string | undefined;
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Optional function that determines whether the user can delete a given item.
|
|
211
|
-
*/
|
|
212
|
-
unstable__canDelete?: (item: any, ...args: ControlContext<P>) => boolean;
|
|
213
|
-
/**
|
|
214
|
-
* Specify how to let Plasmic know how to update its own internal representation of the data when the value has
|
|
215
|
-
* changed, or when issuing a minimalValue or shownValue that is different.
|
|
216
|
-
*
|
|
217
|
-
* Important to specify this if you are expecting any nested expression values in this data type!
|
|
218
|
-
*/
|
|
219
|
-
unstable__keyFunc?: (item: any) => any;
|
|
220
|
-
/**
|
|
221
|
-
* Specify what would be the tentative new value that is set if the user makes any changes.
|
|
222
|
-
*
|
|
223
|
-
* Useful for field mappings.
|
|
224
|
-
*
|
|
225
|
-
* For instance, consider a Table where we have a `fields` prop:
|
|
226
|
-
*
|
|
227
|
-
* - Initially, the value is undefined. But if the user makes any changes, we would want to save an array of at
|
|
228
|
-
* least three items (corresponding to, say, three columns inferred from a schema).
|
|
229
|
-
*
|
|
230
|
-
* - Let's say there are 5 columns in the value. The data schema changes, removing a column and adding two new
|
|
231
|
-
* ones. Now we would want a different minimal value, containing 6 items.
|
|
232
|
-
*/
|
|
233
|
-
unstable__minimalValue?: ContextDependentConfig<P, any>;
|
|
234
|
-
} & DefaultValueOrExpr<P, any[]> & PropTypeBase<P>) | ({
|
|
235
|
-
type: "dataSource";
|
|
236
|
-
dataSource: "airtable" | "cms";
|
|
237
|
-
} & PropTypeBase<P>);
|
|
238
|
-
type DataPickerValueType = string | number | (string | number)[];
|
|
239
|
-
export type DataPickerType<P> = ({
|
|
240
|
-
type: "dataSelector";
|
|
241
|
-
data: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
|
|
242
|
-
alwaysShowValuePathAsLabel?: boolean;
|
|
243
|
-
} & DefaultValueOrExpr<P, DataPickerValueType> & PropTypeBase<P>) | ({
|
|
244
|
-
type: "exprEditor";
|
|
245
|
-
data: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
|
|
246
|
-
} & DefaultValueOrExpr<P, DataPickerValueType> & PropTypeBase<P>);
|
|
247
|
-
export type FormValidationRulesType<P> = {
|
|
248
|
-
type: "formValidationRules";
|
|
249
|
-
} & DefaultValueOrExpr<P, any> & PropTypeBase<P>;
|
|
250
|
-
export type EventHandlerType<P> = {
|
|
251
|
-
type: "eventHandler";
|
|
252
|
-
argTypes: {
|
|
253
|
-
name: string;
|
|
254
|
-
type: PropType<any>;
|
|
255
|
-
}[];
|
|
256
|
-
} & DefaultValueOrExpr<P, (...args: any) => any> & PropTypeBase<P>;
|
|
257
|
-
interface ChoiceTypeBase<P> extends PropTypeBase<P> {
|
|
258
|
-
type: "choice";
|
|
259
|
-
options: string[] | {
|
|
260
|
-
label: string;
|
|
261
|
-
value: string | number | boolean;
|
|
262
|
-
}[] | ContextDependentConfig<P, string[] | {
|
|
263
|
-
label: string;
|
|
264
|
-
value: string | number | boolean;
|
|
265
|
-
}[]>;
|
|
266
|
-
allowSearch?: boolean;
|
|
267
|
-
filterOption?: boolean;
|
|
268
|
-
onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
|
|
269
|
-
}
|
|
270
|
-
export type ChoiceType<P> = (({
|
|
271
|
-
multiSelect?: false;
|
|
272
|
-
} & DefaultValueOrExpr<P, string | number | boolean>) | ({
|
|
273
|
-
multiSelect: true;
|
|
274
|
-
} & DefaultValueOrExpr<P, (string | number | boolean)[]>) | ({
|
|
275
|
-
multiSelect: ContextDependentConfig<P, boolean>;
|
|
276
|
-
} & DefaultValueOrExpr<P, string | number | boolean | (string | number | boolean)[]>)) & ChoiceTypeBase<P>;
|
|
277
|
-
export interface ModalProps {
|
|
278
|
-
show?: boolean;
|
|
279
|
-
children?: React.ReactNode;
|
|
280
|
-
onClose: () => void;
|
|
281
|
-
style?: CSSProperties;
|
|
282
|
-
}
|
|
283
|
-
interface CustomControlProps<P> {
|
|
284
|
-
componentProps: P;
|
|
285
|
-
/**
|
|
286
|
-
* `contextData` can be `null` if the prop controls are rendering before
|
|
287
|
-
* the component instance itself (it will re-render once the component
|
|
288
|
-
* calls `setControlContextData`)
|
|
289
|
-
*/
|
|
290
|
-
contextData: InferDataType<P> | null;
|
|
291
|
-
value: any;
|
|
292
|
-
/**
|
|
293
|
-
* Sets the value to be passed to the prop. Expects a JSON-compatible value.
|
|
294
|
-
*/
|
|
295
|
-
updateValue: (newVal: any) => void;
|
|
296
|
-
/**
|
|
297
|
-
* Full screen modal component
|
|
298
|
-
*/
|
|
299
|
-
FullscreenModal: React.ComponentType<ModalProps>;
|
|
300
|
-
/**
|
|
301
|
-
* Modal component for the side pane
|
|
302
|
-
*/
|
|
303
|
-
SideModal: React.ComponentType<ModalProps>;
|
|
304
|
-
/**
|
|
305
|
-
* The document that the component will be rendered into; instead of using
|
|
306
|
-
* `document` directly (for, say, `document.querySelector()` etc.), you
|
|
307
|
-
* should use this instead.
|
|
308
|
-
*/
|
|
309
|
-
studioDocument: typeof document;
|
|
310
|
-
}
|
|
311
|
-
export type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
|
|
312
|
-
/**
|
|
313
|
-
* Expects defaultValue to be a JSON-compatible value
|
|
314
|
-
*/
|
|
315
|
-
export type CustomType<P> = CustomControl<P> | ({
|
|
316
|
-
type: "custom";
|
|
317
|
-
control: CustomControl<P>;
|
|
318
|
-
} & PropTypeBase<P> & DefaultValueOrExpr<P, any>);
|
|
319
|
-
type SlotType<P> = "slot" | ({
|
|
320
|
-
type: "slot";
|
|
321
|
-
/**
|
|
322
|
-
* The unique names of all code components that can be placed in the slot
|
|
323
|
-
*/
|
|
324
|
-
allowedComponents?: string[];
|
|
325
|
-
/**
|
|
326
|
-
* Whether the "empty slot" placeholder should be hidden in the canvas.
|
|
327
|
-
*/
|
|
328
|
-
hidePlaceholder?: boolean;
|
|
329
|
-
/**
|
|
330
|
-
* Whether the slot is repeated, i.e., is rendered multiple times using
|
|
331
|
-
* repeatedElement().
|
|
332
|
-
*/
|
|
333
|
-
isRepeated?: boolean;
|
|
334
|
-
/**
|
|
335
|
-
* A nicer, human-readable display name for your slot prop
|
|
336
|
-
*/
|
|
337
|
-
displayName?: string;
|
|
338
|
-
/**
|
|
339
|
-
* Function for whether this slot should be hidden from the left tree,
|
|
340
|
-
* given the current props for this component
|
|
341
|
-
*/
|
|
342
|
-
hidden?: ContextDependentConfig<P, boolean>;
|
|
343
|
-
/**
|
|
344
|
-
* If slot is a render prop (accepts a function that takes in some
|
|
345
|
-
* arguments and returns some JSX), then specify the names of the
|
|
346
|
-
* arguments expected by the render prop function.
|
|
347
|
-
*/
|
|
348
|
-
renderPropParams?: string[];
|
|
349
|
-
/**
|
|
350
|
-
* When inserting top-level "page sections", should this slot be the default target?
|
|
351
|
-
*/
|
|
352
|
-
unstable__isMainContentSlot?: boolean;
|
|
353
|
-
} & Omit<DefaultValueOrExpr<P, PlasmicElement | PlasmicElement[]>, "defaultValueHint" | "defaultExpr" | "defaultExprHint">);
|
|
354
|
-
type ImageUrlType<P> = "imageUrl" | ({
|
|
355
|
-
type: "imageUrl";
|
|
356
|
-
} & DefaultValueOrExpr<P, string> & PropTypeBase<P>);
|
|
357
|
-
export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
|
|
358
|
-
type ControlTypeBase = {
|
|
359
|
-
editOnly?: false;
|
|
360
|
-
} | {
|
|
361
|
-
editOnly: true;
|
|
362
|
-
/**
|
|
363
|
-
* The prop where the values should be mapped to
|
|
364
|
-
*/
|
|
365
|
-
uncontrolledProp?: string;
|
|
366
|
-
};
|
|
367
|
-
export type SupportControlled<T> = Extract<T, string | CustomControl<any>> | (Exclude<T, string | CustomControl<any>> & ControlTypeBase);
|
|
368
|
-
export type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | ImageUrlType<P> | CustomType<P> | GraphQLType<P> | DataPickerType<P> | FormValidationRulesType<P> | EventHandlerType<P>> | SlotType<P>;
|
|
369
|
-
type RestrictPropType<T, P> = T extends string ? SupportControlled<StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>> : T extends boolean ? SupportControlled<BooleanType<P> | JSONLikeType<P> | CustomType<P> | DataPickerType<P>> : T extends number ? SupportControlled<NumberType<P> | JSONLikeType<P> | CustomType<P> | DataPickerType<P>> : PropType<P>;
|
|
3
|
+
import { ContextDependentConfig, InferDataType, ModalProps, PropType, RestrictPropType } from "./prop-types";
|
|
4
|
+
export type { CanvasComponentProps, ControlExtras, ControlContext, ContextDependentConfig, PropType, } from "./prop-types";
|
|
370
5
|
export interface ActionProps<P> {
|
|
371
6
|
componentProps: P;
|
|
372
7
|
/**
|
|
@@ -594,4 +229,3 @@ declare global {
|
|
|
594
229
|
}
|
|
595
230
|
}
|
|
596
231
|
export default function registerComponent<T extends React.ComponentType<any>>(component: T, meta: CodeComponentMeta<React.ComponentProps<T>>): void;
|
|
597
|
-
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { BooleanType, ChoiceType, CustomType,
|
|
3
|
-
|
|
4
|
-
type
|
|
2
|
+
import { BooleanType, ChoiceType, CustomType, JSONLikeType, NumberType, StringType, DataSourceType } from "./prop-types";
|
|
3
|
+
import { FunctionParam } from "./registerComponent";
|
|
4
|
+
export type PropType<P> = StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | CustomType<P> | DataSourceType<P>;
|
|
5
|
+
type RestrictPropType<T, P> = T extends string ? StringType<P> | ChoiceType<P> | JSONLikeType<P> | CustomType<P> : T extends boolean ? BooleanType<P> | JSONLikeType<P> | CustomType<P> : T extends number ? NumberType<P> | JSONLikeType<P> | CustomType<P> : PropType<P>;
|
|
5
6
|
type DistributedKeyOf<T> = T extends any ? keyof T : never;
|
|
6
7
|
export interface GlobalContextMeta<P> {
|
|
7
8
|
/**
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const hostVersion = "1.0.
|
|
1
|
+
export declare const hostVersion = "1.0.140";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/host",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.140",
|
|
4
4
|
"description": "plasmic library for app hosting",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"react": ">=16.8.0",
|
|
81
81
|
"react-dom": ">=16.8.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "a9f2eda1e2d7d4aa9bb169cee7bc1fb00061a941"
|
|
84
84
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
__PlasmicHostVersion: string;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare function setPlasmicRootNode(node: React.ReactElement | null): void;
|
|
8
|
+
export interface PlasmicCanvasContextValue {
|
|
9
|
+
componentName: string | null;
|
|
10
|
+
globalVariants: Record<string, string>;
|
|
11
|
+
interactive?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* React context to detect whether the component is rendered on Plasmic editor.
|
|
15
|
+
* If not, return false.
|
|
16
|
+
* If so, return an object with more information about the component
|
|
17
|
+
*/
|
|
18
|
+
export declare const PlasmicCanvasContext: React.Context<false | PlasmicCanvasContextValue>;
|
|
19
|
+
export declare const usePlasmicCanvasContext: () => false | PlasmicCanvasContextValue;
|
|
20
|
+
interface PlasmicCanvasHostProps {
|
|
21
|
+
/**
|
|
22
|
+
* Webpack hmr uses EventSource to listen to hot reloads, but that
|
|
23
|
+
* resultsin a persistent connection from each window. In Plasmic
|
|
24
|
+
* Studio, if a project is configured to use app-hosting with a
|
|
25
|
+
* nextjs or gatsby server running in dev mode, each artboard will
|
|
26
|
+
* be holding a persistent connection to the dev server.
|
|
27
|
+
* Because browsers have a limit to how many connections can
|
|
28
|
+
* be held at a time by domain, this means after X artboards, new
|
|
29
|
+
* artboards will freeze and not load.
|
|
30
|
+
*
|
|
31
|
+
* By default, <PlasmicCanvasHost /> will globally mutate
|
|
32
|
+
* window.EventSource to avoid using EventSource for HMR, which you
|
|
33
|
+
* typically don't need for your custom host page. If you do still
|
|
34
|
+
* want to retain HRM, then youc an pass enableWebpackHmr={true}.
|
|
35
|
+
*/
|
|
36
|
+
enableWebpackHmr?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps>;
|
|
39
|
+
type RenderErrorListener = (err: Error) => void;
|
|
40
|
+
export declare function registerRenderErrorListener(listener: RenderErrorListener): () => void;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const tuple: <T extends any[]>(...args: T) => T;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
export type DataDict = Record<string, any>;
|
|
3
|
+
export declare const DataContext: React.Context<DataDict | undefined>;
|
|
4
|
+
export type DataMeta = {
|
|
5
|
+
hidden?: boolean;
|
|
6
|
+
label?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function mkMetaName(name: string): string;
|
|
9
|
+
export declare function mkMetaValue(meta: Partial<DataMeta>): DataMeta;
|
|
10
|
+
export declare function applySelector(rawData: DataDict | undefined, selector: string | undefined): any;
|
|
11
|
+
export type SelectorDict = Record<string, string | undefined>;
|
|
12
|
+
export declare function useSelector(selector: string | undefined): any;
|
|
13
|
+
export declare function useSelectors(selectors?: SelectorDict): any;
|
|
14
|
+
export declare function useDataEnv(): DataDict | undefined;
|
|
15
|
+
export interface DataProviderProps {
|
|
16
|
+
/**
|
|
17
|
+
* Key to set in data context.
|
|
18
|
+
*/
|
|
19
|
+
name?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Value to set for `name` in data context.
|
|
22
|
+
*/
|
|
23
|
+
data?: any;
|
|
24
|
+
/**
|
|
25
|
+
* If true, hide this entry in studio (data binding).
|
|
26
|
+
*/
|
|
27
|
+
hidden?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Label to be shown in the studio data picker for easier navigation (data binding).
|
|
30
|
+
*/
|
|
31
|
+
label?: string;
|
|
32
|
+
children?: ReactNode;
|
|
33
|
+
}
|
|
34
|
+
export declare function DataProvider({ name, data, hidden, label, children, }: DataProviderProps): JSX.Element;
|
|
35
|
+
export interface PageParamsProviderProps {
|
|
36
|
+
params?: Record<string, string | string[] | undefined>;
|
|
37
|
+
query?: Record<string, string | string[] | undefined>;
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
}
|
|
40
|
+
export declare function PageParamsProvider({ children, params, query, }: PageParamsProviderProps): JSX.Element;
|
|
41
|
+
export declare function DataCtxReader({ children, }: {
|
|
42
|
+
children: ($ctx: DataDict | undefined) => ReactNode;
|
|
43
|
+
}): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
|
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\nexport interface CanvasComponentProps<Data = any> {\n /**\n * This prop is only provided within the canvas of Plasmic Studio.\n * Allows the component to set data to be consumed by the props' controls.\n */\n setControlContextData?: (data: Data) => void;\n}\n\ntype InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;\n\nexport type ControlExtras = { path: (string | number)[] };\n\n/**\n * Context that we pass back to control functions.\n */\nexport type ControlContext<P> = [\n /**\n * props\n */\n P,\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n InferDataType<P> | null,\n /**\n * Extra information for the control to use\n */\n ControlExtras\n];\n\n/**\n * Config option that takes the context (e.g., props) of the component instance\n * to dynamically set its value.\n */\nexport type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;\n\nexport interface PropTypeBase<P> {\n displayName?: string;\n description?: string;\n helpText?: string;\n /**\n * If the user has chosen to use a dynamic expression for this prop, provide\n * a hint as to the expected values that the expression should evaluate to.\n * This hint will be displayed alongside the code editor. You may use\n * markdown in the text here.\n */\n exprHint?: string;\n /**\n * Function for whether this prop should be hidden in the right panel,\n * given the current props for this component\n */\n hidden?: ContextDependentConfig<P, boolean>;\n readOnly?: boolean | ContextDependentConfig<P, boolean>;\n /**\n * If true, will hide the prop in a collapsed section; good for props that\n * should not usually be used.\n */\n advanced?: boolean;\n /**\n * If true, does not allow the user to use a dynamic expression for this prop\n */\n disableDynamicValue?: boolean;\n /**\n * If set to true, the component will be remounted when the prop value is updated.\n * (This behavior only appliees to canvas)\n */\n forceRemount?: boolean;\n}\n\nexport type DefaultValueOrExpr<P, T> =\n | {\n defaultExpr?: undefined;\n defaultExprHint?: undefined;\n defaultValue?: T;\n defaultValueHint?: T | ContextDependentConfig<P, T | undefined>;\n }\n | {\n defaultValue?: undefined;\n defaultValueHint?: undefined;\n defaultExpr?: string;\n defaultExprHint?: string;\n };\n\ntype StringTypeBase<P> = PropTypeBase<P> & DefaultValueOrExpr<P, string>;\n\nexport type StringType<P> =\n | \"string\"\n | ((\n | {\n type: \"string\";\n control?: \"default\" | \"large\";\n }\n | {\n type: \"code\";\n lang: \"css\" | \"html\" | \"javascript\" | \"json\";\n }\n | {\n type: \"richText\";\n }\n | {\n type: \"color\";\n /**\n * If specified, and the user picks a color token in the Studio, then\n * the value passed in as prop is a css variable reference, like\n * `var(--TOKEN_ID)`, instead of the resolved hex value of the token.\n * You should take care in using this in the proper css context --\n * the css token is only defined if you are rendering under some\n * Plasmic component in the DOM tree, which is usually the case,\n * unless you are using a React portal.\n */\n keepCssVar?: boolean;\n }\n | {\n type: \"class\";\n /**\n * Additional css selectors that can change how this style should look.\n * Some examples:\n *\n * * `:hover` -- on hover\n * * `[data-something=\"blah\"] -- when the element with this class has\n * an html attribute \"data-something=blah\"\n * * :component[data-something=\"blah\"] :self -- when the root of the\n * component has an html attribute \"data-something=blah\". Note that\n * the non-standard `:component` selector is used to select the\n * component root, and the non-standard `:self` selector is used\n * to select the element that this class is attached to.\n */\n selectors?: {\n /**\n * A css selector, like `:hover` or `[data-something=\"blah\"]`.\n */\n selector: string;\n /**\n * An optional human-friendly label for the selector, so the studio user\n * knows what this selector means.\n */\n label?: string;\n }[];\n /**\n * If specified, then only shows these style sections for styling this class\n */\n styleSections?: StyleSection[];\n }\n | {\n type: \"themeResetClass\";\n /**\n * Normally, theme reset class will only target Plasmic-generated tags\n * with the default tag styles. If you also want to target non-Plasmic-generated\n * tags (say, rendered by your code components, or fetched as an HTML blob\n * from somewhere), then specify `true` here.\n */\n targetAllTags?: boolean;\n }\n | {\n type: \"cardPicker\";\n modalTitle?:\n | React.ReactNode\n | ContextDependentConfig<P, React.ReactNode>;\n options:\n | {\n value: string;\n label?: string;\n imgUrl: string;\n footer?: React.ReactNode;\n }[]\n | ContextDependentConfig<\n P,\n {\n value: string;\n label?: string;\n imgUrl: string;\n footer?: React.ReactNode;\n }[]\n >;\n showInput?: boolean | ContextDependentConfig<P, boolean>;\n onSearch?: ContextDependentConfig<\n P,\n ((value: string) => void) | undefined\n >;\n }\n ) &\n StringTypeBase<P>);\n\nexport type BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n } & DefaultValueOrExpr<P, boolean> &\n PropTypeBase<P>);\n\ntype GraphQLValue = {\n query: string;\n variables?: Record<string, any>;\n};\n\nexport type GraphQLType<P> = {\n type: \"code\";\n lang: \"graphql\";\n endpoint: string | ContextDependentConfig<P, string>;\n method?: string | ContextDependentConfig<P, string>;\n headers?: object | ContextDependentConfig<P, object>;\n} & DefaultValueOrExpr<P, GraphQLValue> &\n PropTypeBase<P>;\n\ntype NumberTypeBase<P> = PropTypeBase<P> &\n DefaultValueOrExpr<P, number> & {\n type: \"number\";\n };\n\nexport type NumberType<P> =\n | \"number\"\n | ((\n | {\n control?: \"default\";\n min?: number | ContextDependentConfig<P, number>;\n max?: number | ContextDependentConfig<P, number>;\n }\n | {\n control: \"slider\";\n min: number | ContextDependentConfig<P, number>;\n max: number | ContextDependentConfig<P, number>;\n step?: number | ContextDependentConfig<P, number>;\n }\n ) &\n NumberTypeBase<P>);\n\n/**\n * Expects defaultValue to be a JSON-compatible value\n */\nexport type JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n fields?: {\n [p: string]: PropType<P>;\n };\n /**\n * Optional function that generates a name for this item in the array\n */\n nameFunc?: (item: any, ...args: ControlContext<P>) => string | undefined;\n } & DefaultValueOrExpr<P, any> &\n PropTypeBase<P>)\n | ({\n type: \"array\";\n itemType?: {\n type: \"object\";\n fields: {\n [p: string]: PropType<P>;\n };\n /**\n * Optional function that generates a name for this item in the array\n */\n nameFunc?: (\n item: any,\n ...args: ControlContext<P>\n ) => string | undefined;\n };\n /**\n * Optional function that determines whether the user can delete a given item.\n */\n unstable__canDelete?: (item: any, ...args: ControlContext<P>) => boolean;\n /**\n * Specify how to let Plasmic know how to update its own internal representation of the data when the value has\n * changed, or when issuing a minimalValue or shownValue that is different.\n *\n * Important to specify this if you are expecting any nested expression values in this data type!\n */\n unstable__keyFunc?: (item: any) => any;\n /**\n * Specify what would be the tentative new value that is set if the user makes any changes.\n *\n * Useful for field mappings.\n *\n * For instance, consider a Table where we have a `fields` prop:\n *\n * - Initially, the value is undefined. But if the user makes any changes, we would want to save an array of at\n * least three items (corresponding to, say, three columns inferred from a schema).\n *\n * - Let's say there are 5 columns in the value. The data schema changes, removing a column and adding two new\n * ones. Now we would want a different minimal value, containing 6 items.\n */\n unstable__minimalValue?: ContextDependentConfig<P, any>;\n } & DefaultValueOrExpr<P, any[]> &\n PropTypeBase<P>)\n | ({\n type: \"dataSource\";\n dataSource: \"airtable\" | \"cms\";\n } & PropTypeBase<P>);\n\ntype DataPickerValueType = string | number | (string | number)[];\n\nexport type DataPickerType<P> =\n | ({\n type: \"dataSelector\";\n data:\n | Record<string, any>\n | ContextDependentConfig<P, Record<string, any>>;\n alwaysShowValuePathAsLabel?: boolean;\n } & DefaultValueOrExpr<P, DataPickerValueType> &\n PropTypeBase<P>)\n | ({\n type: \"exprEditor\";\n data:\n | Record<string, any>\n | ContextDependentConfig<P, Record<string, any>>;\n } & DefaultValueOrExpr<P, DataPickerValueType> &\n PropTypeBase<P>);\n\nexport type FormValidationRulesType<P> = {\n type: \"formValidationRules\";\n} & DefaultValueOrExpr<P, any> &\n PropTypeBase<P>;\n\nexport type EventHandlerType<P> = {\n type: \"eventHandler\";\n argTypes: { name: string; type: PropType<any> }[];\n} & DefaultValueOrExpr<P, (...args: any) => any> &\n PropTypeBase<P>;\n\ninterface ChoiceTypeBase<P> extends PropTypeBase<P> {\n type: \"choice\";\n options:\n | string[]\n | {\n label: string;\n value: string | number | boolean;\n }[]\n | ContextDependentConfig<\n P,\n | string[]\n | {\n label: string;\n value: string | number | boolean;\n }[]\n >;\n allowSearch?: boolean;\n filterOption?: boolean;\n onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;\n}\n\nexport type ChoiceType<P> = (\n | ({\n multiSelect?: false;\n } & DefaultValueOrExpr<P, string | number | boolean>)\n | ({\n multiSelect: true;\n } & DefaultValueOrExpr<P, (string | number | boolean)[]>)\n | ({\n multiSelect: ContextDependentConfig<P, boolean>;\n } & DefaultValueOrExpr<\n P,\n string | number | boolean | (string | number | boolean)[]\n >)\n) &\n ChoiceTypeBase<P>;\n\nexport interface ModalProps {\n show?: boolean;\n children?: React.ReactNode;\n onClose: () => void;\n style?: CSSProperties;\n}\n\ninterface CustomControlProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n value: any;\n /**\n * Sets the value to be passed to the prop. Expects a JSON-compatible value.\n */\n updateValue: (newVal: any) => void;\n /**\n * Full screen modal component\n */\n FullscreenModal: React.ComponentType<ModalProps>;\n /**\n * Modal component for the side pane\n */\n SideModal: React.ComponentType<ModalProps>;\n\n /**\n * The document that the component will be rendered into; instead of using\n * `document` directly (for, say, `document.querySelector()` etc.), you\n * should use this instead.\n */\n studioDocument: typeof document;\n}\nexport type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;\n\n/**\n * Expects defaultValue to be a JSON-compatible value\n */\nexport type CustomType<P> =\n | CustomControl<P>\n | ({\n type: \"custom\";\n control: CustomControl<P>;\n } & PropTypeBase<P> &\n DefaultValueOrExpr<P, any>);\n\ntype SlotType<P> =\n | \"slot\"\n | ({\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n /**\n * Whether the \"empty slot\" placeholder should be hidden in the canvas.\n */\n hidePlaceholder?: boolean;\n /**\n * Whether the slot is repeated, i.e., is rendered multiple times using\n * repeatedElement().\n */\n isRepeated?: boolean;\n\n /**\n * A nicer, human-readable display name for your slot prop\n */\n displayName?: string;\n\n /**\n * Function for whether this slot should be hidden from the left tree,\n * given the current props for this component\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If slot is a render prop (accepts a function that takes in some\n * arguments and returns some JSX), then specify the names of the\n * arguments expected by the render prop function.\n */\n renderPropParams?: string[];\n\n /**\n * When inserting top-level \"page sections\", should this slot be the default target?\n */\n unstable__isMainContentSlot?: boolean;\n } & Omit<\n DefaultValueOrExpr<P, PlasmicElement | PlasmicElement[]>,\n \"defaultValueHint\" | \"defaultExpr\" | \"defaultExprHint\"\n >);\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n } & DefaultValueOrExpr<P, string> &\n PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n string\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\nexport type SupportControlled<T> =\n | Extract<T, string | CustomControl<any>>\n | (Exclude<T, string | CustomControl<any>> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n | CustomType<P>\n | GraphQLType<P>\n | DataPickerType<P>\n | FormValidationRulesType<P>\n | EventHandlerType<P>\n >\n | SlotType<P>;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n | StringType<P>\n | ChoiceType<P>\n | JSONLikeType<P>\n | ImageUrlType<P>\n | CustomType<P>\n | DataPickerType<P>\n >\n : T extends boolean\n ? SupportControlled<\n BooleanType<P> | JSONLikeType<P> | CustomType<P> | DataPickerType<P>\n >\n : T extends number\n ? SupportControlled<\n NumberType<P> | JSONLikeType<P> | CustomType<P> | DataPickerType<P>\n >\n : PropType<P>;\n\nexport interface ActionProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n studioOps: {\n showModal: (\n modalProps: Omit<ModalProps, \"onClose\"> & { onClose?: () => void }\n ) => void;\n refreshQueryData: () => void;\n appendToSlot: (element: PlasmicElement, slotName: string) => void;\n removeFromSlotAt: (pos: number, slotName: string) => void;\n updateProps: (newValues: any) => void;\n };\n /**\n * The document that the component will be rendered into; instead of using\n * `document` directly (for, say, `document.querySelector()` etc.), you\n * should use this instead.\n */\n studioDocument: typeof document;\n}\n\nexport type Action<P> =\n | {\n type: \"button-action\";\n label: string;\n onClick: (props: ActionProps<P>) => void;\n hidden?: ContextDependentConfig<P, boolean>;\n }\n | {\n type: \"custom-action\";\n control: React.ComponentType<ActionProps<P>>;\n hidden?: ContextDependentConfig<P, boolean>;\n };\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\ninterface ComponentTemplate<P>\n extends Omit<CodeComponentElement<P>, \"type\" | \"name\"> {\n /**\n * A preview picture for the template.\n */\n previewImg?: string;\n}\n\nexport interface ComponentTemplates<P> {\n [name: string]: ComponentTemplate<P>;\n}\n\nexport type StateSpec = {\n onChangeProp: string;\n} & (\n | {\n type: \"readonly\";\n variableType: \"text\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"number\";\n initVal?: number;\n }\n | {\n type: \"readonly\";\n variableType: \"boolean\";\n initVal?: boolean;\n }\n | {\n type: \"readonly\";\n variableType: \"array\";\n initVal?: any[];\n }\n | {\n type: \"readonly\";\n variableType: \"object\";\n initVal?: object;\n }\n | {\n type: \"writable\";\n variableType: \"text\" | \"number\" | \"boolean\" | \"array\" | \"object\";\n valueProp: string;\n }\n);\n\nexport interface StateHelpers<P, T> {\n initFunc?: ($props: P) => T;\n onChangeArgsToValue?: (...args: any) => T;\n}\n\nexport type ComponentHelpers<P> = {\n states: Record<string, StateHelpers<P, any>>;\n};\n\nexport type ExternalComponentHelpers<P> = {\n helpers: ComponentHelpers<P>;\n importPath: string;\n} & (\n | {\n importName: string;\n }\n | {\n isDefaultExport: true;\n }\n);\n\nexport type StyleSection =\n | \"visibility\"\n | \"typography\"\n | \"sizing\"\n | \"spacing\"\n | \"background\"\n | \"transform\"\n | \"transitions\"\n | \"layout\"\n | \"overflow\"\n | \"border\"\n | \"shadows\"\n | \"effects\";\n\nexport interface CodeComponentMeta<P> {\n /**\n * Any unique string name used to identify that component. Each component\n * should be registered with a different `meta.name`, even if they have the\n * same name in the code.\n */\n name: string;\n /**\n * The name to be displayed for the component in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: string;\n /**\n * The description of the component to be shown in Studio.\n */\n description?: string;\n /**\n * The javascript name to be used when generating code. Optional: if not\n * provided, `meta.name` is used.\n */\n importName?: string;\n /**\n * An object describing the component properties to be used in Studio.\n * For each `prop`, there should be an entry `meta.props[prop]` describing\n * its type.\n */\n props: { [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\n /**\n * An object describing the component states to be used in Studio.\n */\n states?: Record<string, StateSpec>;\n /**\n * An object describing the components helpers to be used in Studio.\n * 1. states helpers: Each state can receive an \"initFunc\" prop to initialize\n * the implicit state in Studio, and an \"onChangeArgsToValue\" prop to\n * transform the event handler arguments into a value\n */\n componentHelpers?: ExternalComponentHelpers<P>;\n /**\n * An array describing the component actions to be used in Studio.\n */\n actions?: Action<P>[];\n /**\n * Whether style sections should be shown in Studio. For styles to work, the\n * component must accept a `className` prop. If unset, defaults to all styles.\n * Set to `false` if this component cannot be styled (for example, if it doesn't\n * render any DOM elements).\n */\n styleSections?: StyleSection[] | boolean;\n /**\n * Whether the element can be repeated in Studio. If unset, defaults to true.\n */\n isRepeatable?: boolean;\n /**\n * The path to be used when importing the component in the generated code.\n * It can be the name of the package that contains the component, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the component is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n /**\n * The prop that expects the CSS classes with styles to be applied to the\n * component. Optional: if not specified, Plasmic will expect it to be\n * `className`. Notice that if the component does not accept CSS classes, the\n * component will not be able to receive styles from the Studio.\n */\n classNameProp?: string;\n /**\n * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`\n * to interact with components, so it's not used in the generated code.\n * Optional: If not provided, the usual `ref` is used.\n */\n refProp?: string;\n /**\n * Default styles to start with when instantiating the component in Plasmic.\n */\n defaultStyles?: CSSProperties;\n /**\n * Component templates to start with on Plasmic.\n */\n templates?: ComponentTemplates<P>;\n /**\n * Registered name of parent component, used for grouping related components.\n */\n parentComponentName?: string;\n /**\n * Whether the component can be used as an attachment to an element.\n */\n isAttachment?: boolean;\n /**\n * Whether the component provides data to its slots using DataProvider.\n */\n providesData?: boolean;\n\n /**\n * If specified, then Figma components with the specified names will be mapped\n * to this component when you paste Figma content into Plasmic\n */\n figmaMappings?: {\n figmaComponentName: string;\n }[];\n\n /**\n * If true, when an instance of this component is added, the element\n * will always be named by the name of this component.\n */\n alwaysAutoName?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n}\n\nexport type CodeComponentMode =\n | \"advanced\"\n | \"simplified\"\n | \"database-schema-driven\";\n\n/**\n * @deprecated use CodeComponentMeta instead\n */\nexport type ComponentMeta<P> = CodeComponentMeta<P>;\n\nexport interface FunctionParam<P> {\n name: string;\n displayName?: string;\n type: PropType<P>;\n}\n\nexport interface RefActionRegistration<P> {\n displayName?: string;\n description?: string;\n argTypes: FunctionParam<P>[];\n}\n\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: CodeComponentMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicComponentRegistry: ComponentRegistration[];\n }\n}\n\nif (root.__PlasmicComponentRegistry == null) {\n root.__PlasmicComponentRegistry = [];\n}\n\nexport default function registerComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n // Check for duplicates\n if (\n root.__PlasmicComponentRegistry.some(\n (r: ComponentRegistration) =>\n r.component === component && r.meta.name === meta.name\n )\n ) {\n return;\n }\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n"],"names":[],"mappings":";;;;;AAMA,IAAM,IAAI,GAAG,UAAiB,CAAC;AAqxB/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;IAC3C,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;CACtC;SAEuB,iBAAiB,CACvC,SAAY,EACZ,IAAgD;;IAGhD,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB;QACvB,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;KAAA,CACzD,EACD;QACA,OAAO;KACR;IACD,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\nimport {\n ContextDependentConfig,\n InferDataType,\n ModalProps,\n PropType,\n RestrictPropType,\n} from \"./prop-types\";\nexport type {\n CanvasComponentProps,\n ControlExtras,\n ControlContext,\n ContextDependentConfig,\n PropType,\n} from \"./prop-types\";\n\nconst root = globalThis as any;\n\nexport interface ActionProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n studioOps: {\n showModal: (\n modalProps: Omit<ModalProps, \"onClose\"> & { onClose?: () => void }\n ) => void;\n refreshQueryData: () => void;\n appendToSlot: (element: PlasmicElement, slotName: string) => void;\n removeFromSlotAt: (pos: number, slotName: string) => void;\n updateProps: (newValues: any) => void;\n };\n /**\n * The document that the component will be rendered into; instead of using\n * `document` directly (for, say, `document.querySelector()` etc.), you\n * should use this instead.\n */\n studioDocument: typeof document;\n}\n\nexport type Action<P> =\n | {\n type: \"button-action\";\n label: string;\n onClick: (props: ActionProps<P>) => void;\n hidden?: ContextDependentConfig<P, boolean>;\n }\n | {\n type: \"custom-action\";\n control: React.ComponentType<ActionProps<P>>;\n hidden?: ContextDependentConfig<P, boolean>;\n };\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\ninterface ComponentTemplate<P>\n extends Omit<CodeComponentElement<P>, \"type\" | \"name\"> {\n /**\n * A preview picture for the template.\n */\n previewImg?: string;\n}\n\nexport interface ComponentTemplates<P> {\n [name: string]: ComponentTemplate<P>;\n}\n\nexport type StateSpec = {\n onChangeProp: string;\n} & (\n | {\n type: \"readonly\";\n variableType: \"text\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"number\";\n initVal?: number;\n }\n | {\n type: \"readonly\";\n variableType: \"boolean\";\n initVal?: boolean;\n }\n | {\n type: \"readonly\";\n variableType: \"array\";\n initVal?: any[];\n }\n | {\n type: \"readonly\";\n variableType: \"object\";\n initVal?: object;\n }\n | {\n type: \"writable\";\n variableType: \"text\" | \"number\" | \"boolean\" | \"array\" | \"object\";\n valueProp: string;\n }\n);\n\nexport interface StateHelpers<P, T> {\n initFunc?: ($props: P) => T;\n onChangeArgsToValue?: (...args: any) => T;\n}\n\nexport type ComponentHelpers<P> = {\n states: Record<string, StateHelpers<P, any>>;\n};\n\nexport type ExternalComponentHelpers<P> = {\n helpers: ComponentHelpers<P>;\n importPath: string;\n} & (\n | {\n importName: string;\n }\n | {\n isDefaultExport: true;\n }\n);\n\nexport type StyleSection =\n | \"visibility\"\n | \"typography\"\n | \"sizing\"\n | \"spacing\"\n | \"background\"\n | \"transform\"\n | \"transitions\"\n | \"layout\"\n | \"overflow\"\n | \"border\"\n | \"shadows\"\n | \"effects\";\n\nexport interface CodeComponentMeta<P> {\n /**\n * Any unique string name used to identify that component. Each component\n * should be registered with a different `meta.name`, even if they have the\n * same name in the code.\n */\n name: string;\n /**\n * The name to be displayed for the component in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: string;\n /**\n * The description of the component to be shown in Studio.\n */\n description?: string;\n /**\n * The javascript name to be used when generating code. Optional: if not\n * provided, `meta.name` is used.\n */\n importName?: string;\n /**\n * An object describing the component properties to be used in Studio.\n * For each `prop`, there should be an entry `meta.props[prop]` describing\n * its type.\n */\n props: { [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\n /**\n * An object describing the component states to be used in Studio.\n */\n states?: Record<string, StateSpec>;\n /**\n * An object describing the components helpers to be used in Studio.\n * 1. states helpers: Each state can receive an \"initFunc\" prop to initialize\n * the implicit state in Studio, and an \"onChangeArgsToValue\" prop to\n * transform the event handler arguments into a value\n */\n componentHelpers?: ExternalComponentHelpers<P>;\n /**\n * An array describing the component actions to be used in Studio.\n */\n actions?: Action<P>[];\n /**\n * Whether style sections should be shown in Studio. For styles to work, the\n * component must accept a `className` prop. If unset, defaults to all styles.\n * Set to `false` if this component cannot be styled (for example, if it doesn't\n * render any DOM elements).\n */\n styleSections?: StyleSection[] | boolean;\n /**\n * Whether the element can be repeated in Studio. If unset, defaults to true.\n */\n isRepeatable?: boolean;\n /**\n * The path to be used when importing the component in the generated code.\n * It can be the name of the package that contains the component, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the component is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n /**\n * The prop that expects the CSS classes with styles to be applied to the\n * component. Optional: if not specified, Plasmic will expect it to be\n * `className`. Notice that if the component does not accept CSS classes, the\n * component will not be able to receive styles from the Studio.\n */\n classNameProp?: string;\n /**\n * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`\n * to interact with components, so it's not used in the generated code.\n * Optional: If not provided, the usual `ref` is used.\n */\n refProp?: string;\n /**\n * Default styles to start with when instantiating the component in Plasmic.\n */\n defaultStyles?: CSSProperties;\n /**\n * Component templates to start with on Plasmic.\n */\n templates?: ComponentTemplates<P>;\n /**\n * Registered name of parent component, used for grouping related components.\n */\n parentComponentName?: string;\n /**\n * Whether the component can be used as an attachment to an element.\n */\n isAttachment?: boolean;\n /**\n * Whether the component provides data to its slots using DataProvider.\n */\n providesData?: boolean;\n\n /**\n * If specified, then Figma components with the specified names will be mapped\n * to this component when you paste Figma content into Plasmic\n */\n figmaMappings?: {\n figmaComponentName: string;\n }[];\n\n /**\n * If true, when an instance of this component is added, the element\n * will always be named by the name of this component.\n */\n alwaysAutoName?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n}\n\nexport type CodeComponentMode =\n | \"advanced\"\n | \"simplified\"\n | \"database-schema-driven\";\n\n/**\n * @deprecated use CodeComponentMeta instead\n */\nexport type ComponentMeta<P> = CodeComponentMeta<P>;\n\nexport interface FunctionParam<P> {\n name: string;\n displayName?: string;\n type: PropType<P>;\n}\n\nexport interface RefActionRegistration<P> {\n displayName?: string;\n description?: string;\n argTypes: FunctionParam<P>[];\n}\n\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: CodeComponentMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicComponentRegistry: ComponentRegistration[];\n }\n}\n\nif (root.__PlasmicComponentRegistry == null) {\n root.__PlasmicComponentRegistry = [];\n}\n\nexport default function registerComponent<T extends React.ComponentType<any>>(\n component: T,\n meta: CodeComponentMeta<React.ComponentProps<T>>\n) {\n // Check for duplicates\n if (\n root.__PlasmicComponentRegistry.some(\n (r: ComponentRegistration) =>\n r.component === component && r.meta.name === meta.name\n )\n ) {\n return;\n }\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n"],"names":[],"mappings":";;;;;AAoBA,IAAM,IAAI,GAAG,UAAiB,CAAC;AAkR/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;IAC3C,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;CACtC;SAEuB,iBAAiB,CACvC,SAAY,EACZ,IAAgD;;IAGhD,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB;QACvB,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;KAAA,CACzD,EACD;QACA,OAAO;KACR;IACD,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./exports";
|