/// import { CSSProperties, PlasmicElement } from "../element-types"; import { ChoiceCore, ChoiceValue } from "./choice-type"; import { ArrayTypeBaseCore, ObjectTypeBaseCore } from "./container-types"; import { DataPickerValueType, DataSourceCore, DynamicCore, GraphQLCore, GraphQLValue, RichDataPickerCore, RichExprEditorCore } from "./misc-types"; import { CardPickerCore, ClassCore, CodeStringCore, ColorCore, DateRangeStringsCore, DateStringCore, HrefCore, NumberTypeBaseCore, PlainNumberCore, PlainStringCore, RichBooleanCore, RichTextCore, SliderNumberCore, ThemeResetClassCore } from "./primitive-types"; import { CommonTypeBase, ContextDependentConfig, ControlExtras, Defaultable, GenericContext, InferDataType } from "./shared-controls"; export type ComponentControlContext

= GenericContext | null, // Canvas data ControlExtras>; export type ComponentContextConfig = ContextDependentConfig, R>; export interface PropTypeBase extends CommonTypeBase { displayName?: string; required?: boolean; readOnly?: boolean | ContextDependentConfig; /** * If set to true, the component will be remounted when the prop value is updated. * (This behavior only applies to canvas) */ forceRemount?: boolean; /** * If true, the prop can't be overriden in different variants. */ invariantable?: boolean; /** * Function for whether this prop should be hidden in the right panel, * given the current props for this component */ hidden?: ContextDependentConfig; } interface ExtendedDefaultable extends Defaultable { /** * Use a dynamic value expression as the default instead */ defaultExpr?: string; defaultExprHint?: string; /** * This function validates whether the prop value is valid. * If the value is invalid, it returns an error message. Otherwise, it returns true. */ validator?: (value: T, ...args: Ctx) => (string | true) | Promise; } export interface Controllable { /** * If true, this is a prop that should only be used inside Plasmic * Studio for rendering artboards; will not be actually used in * generated code. */ editOnly?: boolean; /** * If specified, the value used for this prop will instead be * mapped to the uncontrolledProp when generating code. This is * useful if, for example, in the artboard, you want to use `value` * prop to control the component, but in generated code, you want to * map it to `defaultValue`. */ uncontrolledProp?: string; } export type PropTypeBaseDefault = PropTypeBase> & ExtendedDefaultable, T> & Controllable; export type PlainStringType

= PropTypeBaseDefault & PlainStringCore; export type CodeStringType

= PropTypeBaseDefault & CodeStringCore; export type RichTextType

= PropTypeBaseDefault & RichTextCore; export type HrefType

= PropTypeBaseDefault & HrefCore; export type ColorType

= PropTypeBaseDefault & ColorCore; export type DateStringType

= PropTypeBaseDefault & DateStringCore; export type DateRangeStringsType

= PropTypeBaseDefault & DateRangeStringsCore; export type ClassType

= PropTypeBase> & ClassCore; export type ThemeResetClassType

= PropTypeBase> & ThemeResetClassCore; export type CardPickerType

= PropTypeBaseDefault & CardPickerCore>; export type RichStringType

= PlainStringType

| CodeStringType

| RichTextType

| ColorType

| ClassType

| ThemeResetClassType

| CardPickerType

| HrefType

; export type StringType

= "string" | "href" | RichStringType

; export type RichBooleanType

= PropTypeBaseDefault & RichBooleanCore; export type BooleanType

= "boolean" | RichBooleanType

; export type GraphQLType

= PropTypeBaseDefault & GraphQLCore>; export type NumberTypeBase

= PropTypeBaseDefault & NumberTypeBaseCore>; export type PlainNumberType

= NumberTypeBase

& PlainNumberCore>; export type SliderNumberType

= NumberTypeBase

& SliderNumberCore>; export type RichNumberType

= PlainNumberType

| SliderNumberType

; export type NumberType

= "number" | RichNumberType

; export type ObjectType

= PropTypeBaseDefault> & ObjectTypeBaseCore, PropType

>; export type ArrayType

= PropTypeBaseDefault & ArrayTypeBaseCore, PropType

>; export type JSONLikeType

= "object" | ObjectType

| ArrayType

; export type DataSourceType

= PropTypeBase> & DataSourceCore; export type RichDataPickerType

= PropTypeBaseDefault & RichDataPickerCore>; export type DataPickerType

= "dataPicker" | RichDataPickerType

; export type RichExprEditorType

= PropTypeBaseDefault & RichExprEditorCore>; export type ExprEditorType

= "exprEditor" | RichExprEditorType

; export type ComponentChoiceType = PropTypeBaseDefault & ChoiceCore, Opt>; export interface SingleChoiceType extends ComponentChoiceType { multiSelect?: false; } export interface MultiChoiceType extends ComponentChoiceType { multiSelect: true; } export interface CustomChoiceType

extends ComponentChoiceType { multiSelect: ComponentContextConfig; } export type ChoiceType

= SingleChoiceType

| MultiChoiceType

| CustomChoiceType

; export interface FormValidationRulesType

extends PropTypeBaseDefault { type: "formValidationRules"; } export interface EventHandlerType

extends PropTypeBase> { type: "eventHandler"; argTypes: { name: string; type: ArgType; }[]; } export interface RichSlotType

{ type: "slot"; description?: string; /** * The unique names of all code components that can be placed in the slot */ allowedComponents?: string[]; /** * Wheter Plasmic Components with a root component included in the * "allowedComponents" list are valid or not. * Only used if the "allowedComponents" list is set. */ allowRootWrapper?: boolean; /** * Whether the "empty slot" placeholder should be hidden in the canvas. */ hidePlaceholder?: boolean; /** * Whether the slot is repeated, i.e., is rendered multiple times using * repeatedElement(). */ isRepeated?: boolean; /** * A nicer, human-readable display name for your slot prop */ displayName?: string; /** * Function for whether this slot should be hidden from the left tree, * given the current props for this component */ hidden?: ComponentContextConfig; /** * If slot is a render prop (accepts a function that takes in some * arguments and returns some JSX), then specify the names of the * arguments expected by the render prop function. */ renderPropParams?: string[]; /** * When inserting top-level "page sections", should this slot be the default target? */ unstable__isMainContentSlot?: boolean; defaultValue?: PlasmicElement | PlasmicElement[]; /** * When true, when you click for the first time in this slot and the component was not selected, the component itself * is selected, making it easier to select the component instead of slot contents. So for * instance, setting this on a Button slot ensures that clicking on the Button’s text will still select the Button and not * the text element in its slot. Clicking again will deep-select the slot content. Similar in this regard to trapsFocus on components. * * Furthermore, the component further shows the props of whatever is in the slot on * the parent component for the user's convenience. Handy for various “wrapper" components, form fields, and so on. */ mergeWithParent?: boolean | ComponentContextConfig; /** * A function that returns true to hide the merged props conditionally. */ hiddenMergedProps?: ComponentContextConfig; } export type SlotType

= "slot" | RichSlotType

; export interface RichImageUrlType

extends PropTypeBaseDefault { type: "imageUrl"; } export type ImageUrlType

= "imageUrl" | RichImageUrlType

; export interface ModalProps { show?: boolean; children?: React.ReactNode; onClose: () => void; style?: CSSProperties; } export interface StudioOps { showModal: (modalProps: Omit & { onClose?: () => void; }) => void; refreshQueryData: () => void; appendToSlot: (element: PlasmicElement, slotName: string) => void; removeFromSlotAt: (pos: number, slotName: string) => void; updateProps: (newValues: any) => void; updateStates: (newValues: any) => void; } export interface ProjectData { components: { name: string; }[]; pages: { name: string; pageMeta: { path: string; }; }[]; } export interface CustomControlProps

{ componentProps: P; /** * `contextData` can be `null` if the prop controls are rendering before * the component instance itself (it will re-render once the component * calls `setControlContextData`) */ contextData: InferDataType

| null; /** * Operations available to the editor that allow modifying the entire component. * Can be null if the custom prop is used in a global context. */ studioOps: StudioOps | null; /** * Metadata from the studio project. */ projectData: ProjectData; value: any; /** * Sets the value to be passed to the prop. Expects a JSON-compatible value. */ updateValue: (newVal: any) => void; /** * Full screen modal component */ FullscreenModal: React.ComponentType; /** * Modal component for the side pane */ SideModal: React.ComponentType; /** * The document that the component will be rendered into; instead of using * `document` directly (for, say, `document.querySelector()` etc.), you * should use this instead. */ studioDocument: typeof document; } export type CustomControl

= React.ComponentType>; export interface RichCustomType

extends PropTypeBaseDefault { type: "custom"; control: CustomControl

; } export type CustomType

= RichCustomType

| CustomControl

; export interface DynamicType

extends PropTypeBase>, DynamicCore, PropType

> { } export type PrimitiveType

= Extract | BooleanType

| NumberType

| JSONLikeType

, string>; export type PropType

= StringType

| BooleanType

| GraphQLType

| NumberType

| JSONLikeType

| DataSourceType

| DataPickerType

| ExprEditorType

| FormValidationRulesType

| EventHandlerType

| ChoiceType

| CustomType

| DynamicType

| ImageUrlType

| SlotType

| DateStringType

| DateRangeStringsType

; export type ArgType

= Exclude, SlotType

| EventHandlerType

>; export type StringCompatType

= DateStringType

| StringType

| ChoiceType

| JSONLikeType

| ImageUrlType

| CustomType

| DataPickerType

; export type BoolCompatType

= BooleanType

| CustomType

| DataPickerType

; export type NumberCompatType

= NumberType

| CustomType

| DataPickerType

; export type RestrictPropType = T extends string ? StringCompatType

: T extends boolean ? BoolCompatType

: T extends number ? NumberCompatType

: PropType

; export {};