@plasmicapp/host 1.0.164 → 1.0.166
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/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 +54 -41
- package/dist/registerComponent.d.ts +7 -0
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/registerComponent/dist/index.cjs.js.map +1 -1
- package/registerComponent/dist/index.esm.js.map +1 -1
- package/registerComponent/dist/prop-types.d.ts +54 -41
- package/registerComponent/dist/registerComponent.d.ts +7 -0
- package/registerComponent/dist/version.d.ts +1 -1
- package/registerGlobalContext/dist/prop-types.d.ts +54 -41
- package/registerGlobalContext/dist/registerComponent.d.ts +7 -0
- package/registerGlobalContext/dist/version.d.ts +1 -1
- package/registerToken/dist/prop-types.d.ts +54 -41
- package/registerToken/dist/registerComponent.d.ts +7 -0
- package/registerToken/dist/version.d.ts +1 -1
- package/registerTrait/dist/prop-types.d.ts +54 -41
- package/registerTrait/dist/registerComponent.d.ts +7 -0
- package/registerTrait/dist/version.d.ts +1 -1
package/dist/prop-types.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export interface PropTypeBase<P> {
|
|
|
70
70
|
*/
|
|
71
71
|
forceRemount?: boolean;
|
|
72
72
|
}
|
|
73
|
-
interface Defaultable<P, T> {
|
|
73
|
+
export interface Defaultable<P, T> {
|
|
74
74
|
/**
|
|
75
75
|
* Default value to set for this prop when the component is instantiated
|
|
76
76
|
*/
|
|
@@ -91,7 +91,7 @@ interface Defaultable<P, T> {
|
|
|
91
91
|
*/
|
|
92
92
|
validator?: (value: T, ...args: ControlContext<P>) => (string | true) | Promise<string | true>;
|
|
93
93
|
}
|
|
94
|
-
interface Controllable {
|
|
94
|
+
export interface Controllable {
|
|
95
95
|
/**
|
|
96
96
|
* If true, this is a prop that should only be used inside Plasmic
|
|
97
97
|
* Studio for rendering artboards; will not be actually used in
|
|
@@ -109,22 +109,22 @@ interface Controllable {
|
|
|
109
109
|
}
|
|
110
110
|
export interface PropTypeBaseDefault<P, T> extends PropTypeBase<P>, Defaultable<P, T>, Controllable {
|
|
111
111
|
}
|
|
112
|
-
interface PlainStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
112
|
+
export interface PlainStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
113
113
|
type: "string";
|
|
114
114
|
control?: "default" | "large";
|
|
115
115
|
isLocalizable?: boolean;
|
|
116
116
|
}
|
|
117
|
-
interface CodeStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
117
|
+
export interface CodeStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
118
118
|
type: "code";
|
|
119
119
|
lang: "css" | "html" | "javascript" | "json";
|
|
120
120
|
}
|
|
121
|
-
interface RichTextType<P> extends PropTypeBaseDefault<P, string> {
|
|
121
|
+
export interface RichTextType<P> extends PropTypeBaseDefault<P, string> {
|
|
122
122
|
type: "richText";
|
|
123
123
|
}
|
|
124
|
-
interface HrefType<P> extends PropTypeBaseDefault<P, string> {
|
|
124
|
+
export interface HrefType<P> extends PropTypeBaseDefault<P, string> {
|
|
125
125
|
type: "href";
|
|
126
126
|
}
|
|
127
|
-
interface ColorType<P> extends PropTypeBaseDefault<P, string> {
|
|
127
|
+
export interface ColorType<P> extends PropTypeBaseDefault<P, string> {
|
|
128
128
|
type: "color";
|
|
129
129
|
/**
|
|
130
130
|
* If specified, and the user picks a color token in the Studio, then
|
|
@@ -141,13 +141,13 @@ interface ColorType<P> extends PropTypeBaseDefault<P, string> {
|
|
|
141
141
|
*/
|
|
142
142
|
disableTokens?: boolean;
|
|
143
143
|
}
|
|
144
|
-
interface DateStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
144
|
+
export interface DateStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
145
145
|
type: "dateString";
|
|
146
146
|
}
|
|
147
|
-
interface DateRangeStringsType<P> extends PropTypeBaseDefault<P, [string, string]> {
|
|
147
|
+
export interface DateRangeStringsType<P> extends PropTypeBaseDefault<P, [string, string]> {
|
|
148
148
|
type: "dateRangeStrings";
|
|
149
149
|
}
|
|
150
|
-
interface ClassType<P> extends PropTypeBase<P> {
|
|
150
|
+
export interface ClassType<P> extends PropTypeBase<P> {
|
|
151
151
|
type: "class";
|
|
152
152
|
/**
|
|
153
153
|
* Additional css selectors that can change how this style should look.
|
|
@@ -178,7 +178,7 @@ interface ClassType<P> extends PropTypeBase<P> {
|
|
|
178
178
|
*/
|
|
179
179
|
styleSections?: StyleSection[];
|
|
180
180
|
}
|
|
181
|
-
interface ThemeResetClassType<P> extends PropTypeBase<P> {
|
|
181
|
+
export interface ThemeResetClassType<P> extends PropTypeBase<P> {
|
|
182
182
|
type: "themeResetClass";
|
|
183
183
|
/**
|
|
184
184
|
* Normally, theme reset class will only target Plasmic-generated tags
|
|
@@ -188,7 +188,7 @@ interface ThemeResetClassType<P> extends PropTypeBase<P> {
|
|
|
188
188
|
*/
|
|
189
189
|
targetAllTags?: boolean;
|
|
190
190
|
}
|
|
191
|
-
interface CardPickerType<P> extends PropTypeBaseDefault<P, string> {
|
|
191
|
+
export interface CardPickerType<P> extends PropTypeBaseDefault<P, string> {
|
|
192
192
|
type: "cardPicker";
|
|
193
193
|
modalTitle?: React.ReactNode | ContextDependentConfig<P, React.ReactNode>;
|
|
194
194
|
options: {
|
|
@@ -205,36 +205,36 @@ interface CardPickerType<P> extends PropTypeBaseDefault<P, string> {
|
|
|
205
205
|
showInput?: boolean | ContextDependentConfig<P, boolean>;
|
|
206
206
|
onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
|
|
207
207
|
}
|
|
208
|
-
type RichStringType<P> = PlainStringType<P> | CodeStringType<P> | RichTextType<P> | ColorType<P> | ClassType<P> | ThemeResetClassType<P> | CardPickerType<P> | HrefType<P>;
|
|
208
|
+
export type RichStringType<P> = PlainStringType<P> | CodeStringType<P> | RichTextType<P> | ColorType<P> | ClassType<P> | ThemeResetClassType<P> | CardPickerType<P> | HrefType<P>;
|
|
209
209
|
export type StringType<P> = "string" | "href" | RichStringType<P>;
|
|
210
|
-
interface RichBooleanType<P> extends PropTypeBaseDefault<P, boolean> {
|
|
210
|
+
export interface RichBooleanType<P> extends PropTypeBaseDefault<P, boolean> {
|
|
211
211
|
type: "boolean";
|
|
212
212
|
}
|
|
213
213
|
export type BooleanType<P> = "boolean" | RichBooleanType<P>;
|
|
214
|
-
type GraphQLValue = {
|
|
214
|
+
export type GraphQLValue = {
|
|
215
215
|
query: string;
|
|
216
216
|
variables?: Record<string, any>;
|
|
217
217
|
};
|
|
218
|
-
interface GraphQLType<P> extends PropTypeBaseDefault<P, GraphQLValue> {
|
|
218
|
+
export interface GraphQLType<P> extends PropTypeBaseDefault<P, GraphQLValue> {
|
|
219
219
|
type: "code";
|
|
220
220
|
lang: "graphql";
|
|
221
221
|
endpoint: string | ContextDependentConfig<P, string>;
|
|
222
222
|
method?: string | ContextDependentConfig<P, string>;
|
|
223
223
|
headers?: object | ContextDependentConfig<P, object>;
|
|
224
224
|
}
|
|
225
|
-
interface NumberTypeBase<P> extends PropTypeBaseDefault<P, number> {
|
|
225
|
+
export interface NumberTypeBase<P> extends PropTypeBaseDefault<P, number> {
|
|
226
226
|
type: "number";
|
|
227
227
|
min?: number | ContextDependentConfig<P, number>;
|
|
228
228
|
max?: number | ContextDependentConfig<P, number>;
|
|
229
229
|
}
|
|
230
|
-
interface PlainNumberType<P> extends NumberTypeBase<P> {
|
|
230
|
+
export interface PlainNumberType<P> extends NumberTypeBase<P> {
|
|
231
231
|
control?: "default";
|
|
232
232
|
}
|
|
233
|
-
interface SliderNumberType<P> extends NumberTypeBase<P> {
|
|
233
|
+
export interface SliderNumberType<P> extends NumberTypeBase<P> {
|
|
234
234
|
control: "slider";
|
|
235
235
|
step?: number | ContextDependentConfig<P, number>;
|
|
236
236
|
}
|
|
237
|
-
type RichNumberType<P> = PlainNumberType<P> | SliderNumberType<P>;
|
|
237
|
+
export type RichNumberType<P> = PlainNumberType<P> | SliderNumberType<P>;
|
|
238
238
|
export type NumberType<P> = "number" | RichNumberType<P>;
|
|
239
239
|
export interface ObjectType<P> extends PropTypeBaseDefault<P, Record<string, any>> {
|
|
240
240
|
type: "object";
|
|
@@ -275,31 +275,31 @@ export interface DataSourceType<P> extends PropTypeBase<P> {
|
|
|
275
275
|
type: "dataSource";
|
|
276
276
|
dataSource: "airtable" | "cms";
|
|
277
277
|
}
|
|
278
|
-
type DataPickerValueType = string | number | (string | number)[];
|
|
279
|
-
interface RichDataPickerType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
|
|
278
|
+
export type DataPickerValueType = string | number | (string | number)[];
|
|
279
|
+
export interface RichDataPickerType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
|
|
280
280
|
type: "dataSelector";
|
|
281
281
|
data?: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
|
|
282
282
|
alwaysShowValuePathAsLabel?: boolean;
|
|
283
283
|
isolateEnv?: boolean;
|
|
284
284
|
}
|
|
285
|
-
type DataPickerType<P> = "dataPicker" | RichDataPickerType<P>;
|
|
286
|
-
interface RichExprEditorType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
|
|
285
|
+
export type DataPickerType<P> = "dataPicker" | RichDataPickerType<P>;
|
|
286
|
+
export interface RichExprEditorType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
|
|
287
287
|
type: "exprEditor";
|
|
288
288
|
data?: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
|
|
289
289
|
isolateEnv?: boolean;
|
|
290
290
|
}
|
|
291
|
-
type ExprEditorType<P> = "exprEditor" | RichExprEditorType<P>;
|
|
292
|
-
interface FormValidationRulesType<P> extends PropTypeBaseDefault<P, any> {
|
|
291
|
+
export type ExprEditorType<P> = "exprEditor" | RichExprEditorType<P>;
|
|
292
|
+
export interface FormValidationRulesType<P> extends PropTypeBaseDefault<P, any> {
|
|
293
293
|
type: "formValidationRules";
|
|
294
294
|
}
|
|
295
|
-
interface EventHandlerType<P> extends PropTypeBase<P> {
|
|
295
|
+
export interface EventHandlerType<P> extends PropTypeBase<P> {
|
|
296
296
|
type: "eventHandler";
|
|
297
297
|
argTypes: {
|
|
298
298
|
name: string;
|
|
299
299
|
type: PropType<any>;
|
|
300
300
|
}[];
|
|
301
301
|
}
|
|
302
|
-
interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
|
|
302
|
+
export interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
|
|
303
303
|
type: "choice";
|
|
304
304
|
options: string[] | {
|
|
305
305
|
label: string;
|
|
@@ -312,17 +312,17 @@ interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
|
|
|
312
312
|
filterOption?: boolean;
|
|
313
313
|
onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
|
|
314
314
|
}
|
|
315
|
-
interface SingleChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean> {
|
|
315
|
+
export interface SingleChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean> {
|
|
316
316
|
multiSelect?: false;
|
|
317
317
|
}
|
|
318
|
-
interface MultiChoiceType<P> extends ChoiceTypeBase<P, (string | number | boolean)[]> {
|
|
318
|
+
export interface MultiChoiceType<P> extends ChoiceTypeBase<P, (string | number | boolean)[]> {
|
|
319
319
|
multiSelect: true;
|
|
320
320
|
}
|
|
321
|
-
interface CustomChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean | (string | number | boolean)[]> {
|
|
321
|
+
export interface CustomChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean | (string | number | boolean)[]> {
|
|
322
322
|
multiSelect: ContextDependentConfig<P, boolean>;
|
|
323
323
|
}
|
|
324
324
|
export type ChoiceType<P> = SingleChoiceType<P> | MultiChoiceType<P> | CustomChoiceType<P>;
|
|
325
|
-
interface RichSlotType<P> {
|
|
325
|
+
export interface RichSlotType<P> {
|
|
326
326
|
type: "slot";
|
|
327
327
|
/**
|
|
328
328
|
* The unique names of all code components that can be placed in the slot
|
|
@@ -357,19 +357,33 @@ interface RichSlotType<P> {
|
|
|
357
357
|
*/
|
|
358
358
|
unstable__isMainContentSlot?: boolean;
|
|
359
359
|
defaultValue?: PlasmicElement | PlasmicElement[];
|
|
360
|
+
/**
|
|
361
|
+
* When true, when you click for the first time in this slot and the component was not selected, the component itself
|
|
362
|
+
* is selected, making it easier to select the component instead of slot contents. So for
|
|
363
|
+
* instance, setting this on a Button slot ensures that clicking on the Button’s text will still select the Button and not
|
|
364
|
+
* the text element in its slot. Clicking again will deep-select the slot content. Similar in this regard to trapsFocus on components.
|
|
365
|
+
*
|
|
366
|
+
* Furthermore, the component further shows the props of whatever is in the slot on
|
|
367
|
+
* the parent component for the user's convenience. Handy for various “wrapper" components, form fields, and so on.
|
|
368
|
+
*/
|
|
369
|
+
mergeWithParent?: ContextDependentConfig<P, boolean>;
|
|
370
|
+
/**
|
|
371
|
+
* A function that returns true to hide the merged props conditionally.
|
|
372
|
+
*/
|
|
373
|
+
hiddenMergedProps?: ContextDependentConfig<P, boolean>;
|
|
360
374
|
}
|
|
361
|
-
type SlotType<P> = "slot" | RichSlotType<P>;
|
|
362
|
-
interface RichImageUrlType<P> extends PropTypeBaseDefault<P, string> {
|
|
375
|
+
export type SlotType<P> = "slot" | RichSlotType<P>;
|
|
376
|
+
export interface RichImageUrlType<P> extends PropTypeBaseDefault<P, string> {
|
|
363
377
|
type: "imageUrl";
|
|
364
378
|
}
|
|
365
|
-
type ImageUrlType<P> = "imageUrl" | RichImageUrlType<P>;
|
|
379
|
+
export type ImageUrlType<P> = "imageUrl" | RichImageUrlType<P>;
|
|
366
380
|
export interface ModalProps {
|
|
367
381
|
show?: boolean;
|
|
368
382
|
children?: React.ReactNode;
|
|
369
383
|
onClose: () => void;
|
|
370
384
|
style?: CSSProperties;
|
|
371
385
|
}
|
|
372
|
-
interface CustomControlProps<P> {
|
|
386
|
+
export interface CustomControlProps<P> {
|
|
373
387
|
componentProps: P;
|
|
374
388
|
/**
|
|
375
389
|
* `contextData` can be `null` if the prop controls are rendering before
|
|
@@ -398,15 +412,14 @@ interface CustomControlProps<P> {
|
|
|
398
412
|
studioDocument: typeof document;
|
|
399
413
|
}
|
|
400
414
|
export type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
|
|
401
|
-
interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
|
|
415
|
+
export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
|
|
402
416
|
type: "custom";
|
|
403
417
|
control: CustomControl<P>;
|
|
404
418
|
}
|
|
405
419
|
export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
|
|
406
420
|
export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
|
|
407
421
|
export type PropType<P> = StringType<P> | BooleanType<P> | GraphQLType<P> | NumberType<P> | JSONLikeType<P> | DataSourceType<P> | DataPickerType<P> | ExprEditorType<P> | FormValidationRulesType<P> | EventHandlerType<P> | ChoiceType<P> | CustomType<P> | ImageUrlType<P> | SlotType<P> | DateStringType<P> | DateRangeStringsType<P>;
|
|
408
|
-
type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
|
|
409
|
-
type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
|
|
410
|
-
type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
|
|
422
|
+
export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
|
|
423
|
+
export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
|
|
424
|
+
export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
|
|
411
425
|
export type RestrictPropType<T, P> = T extends string ? StringCompatType<P> : T extends boolean ? BoolCompatType<P> : T extends number ? NumberCompatType<P> : PropType<P>;
|
|
412
|
-
export {};
|
|
@@ -237,6 +237,13 @@ export interface CodeComponentMeta<P> {
|
|
|
237
237
|
* Defaults to "flex".
|
|
238
238
|
*/
|
|
239
239
|
defaultDisplay?: string;
|
|
240
|
+
/**
|
|
241
|
+
* When true, when you click for the first time anywhere in the component including its slots, the component itself is
|
|
242
|
+
* selected, making it easier to select the component instead of slot contents. So for instance, setting this on a
|
|
243
|
+
* Button ensures that clicking on the Button’s text will still select the Button and not the text element in its
|
|
244
|
+
* slot. Clicking again will deep-select the slot content.
|
|
245
|
+
*/
|
|
246
|
+
trapsFocus?: boolean;
|
|
240
247
|
}
|
|
241
248
|
export type CodeComponentMode = "advanced" | "simplified" | "database-schema-driven";
|
|
242
249
|
/**
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const hostVersion = "1.0.
|
|
1
|
+
export declare const hostVersion = "1.0.166";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/host",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.166",
|
|
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": "dbe6519e32e754c106a17535505bd1ae7cff082d"
|
|
84
84
|
}
|
|
@@ -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\";\nimport {\n ContextDependentConfig,\n InferDataType,\n ModalProps,\n PropType,\n RestrictPropType,\n} from \"./prop-types\";\nimport { TupleUnion } from \"./type-utils\";\nexport type * 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<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ContextDependentConfig<P, boolean>;\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 onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\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<P>>;\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 /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ContextDependentConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\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":";;;;;AAeA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0G/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AA+MF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,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\";\nimport { TupleUnion } from \"./type-utils\";\nexport type * 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<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ContextDependentConfig<P, boolean>;\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 onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\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<P>>;\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 /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ContextDependentConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\n\n /**\n * When true, when you click for the first time anywhere in the component including its slots, the component itself is\n * selected, making it easier to select the component instead of slot contents. So for instance, setting this on a\n * Button ensures that clicking on the Button’s text will still select the Button and not the text element in its\n * slot. Clicking again will deep-select the slot content.\n */\n trapsFocus?: boolean;\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":";;;;;AAeA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0G/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AAuNF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.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\";\nimport { TupleUnion } from \"./type-utils\";\nexport type * 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<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ContextDependentConfig<P, boolean>;\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 onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\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<P>>;\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 /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ContextDependentConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\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":";AAeA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0G/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AA+MF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.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\";\nimport { TupleUnion } from \"./type-utils\";\nexport type * 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<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ContextDependentConfig<P, boolean>;\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 onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\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<P>>;\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 /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ContextDependentConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\n\n /**\n * When true, when you click for the first time anywhere in the component including its slots, the component itself is\n * selected, making it easier to select the component instead of slot contents. So for instance, setting this on a\n * Button ensures that clicking on the Button’s text will still select the Button and not the text element in its\n * slot. Clicking again will deep-select the slot content.\n */\n trapsFocus?: boolean;\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":";AAeA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0G/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AAuNF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|