@plasmicapp/host 1.0.134 → 1.0.138

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