@plasmicapp/host 1.0.224 → 1.0.226
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports.d.ts +2 -2
- package/dist/host.esm.js +1 -1
- package/dist/host.esm.js.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/prop-types.d.ts +6 -478
- package/dist/registerComponent.d.ts +8 -7
- package/dist/registerFunction.d.ts +2 -127
- package/dist/types/choice-type.d.ts +16 -0
- package/dist/types/component-types.d.ts +258 -0
- package/dist/types/container-types.d.ts +35 -0
- package/dist/types/function-types.d.ts +100 -0
- package/dist/types/misc-types.d.ts +38 -0
- package/dist/types/primitive-types.d.ts +123 -0
- package/dist/types/shared-controls.d.ts +40 -0
- package/dist/version.d.ts +1 -1
- package/package.json +4 -3
- package/registerComponent/dist/exports.d.ts +2 -2
- package/registerComponent/dist/index.cjs.js.map +1 -1
- package/registerComponent/dist/index.esm.js.map +1 -1
- package/registerComponent/dist/prop-types.d.ts +6 -478
- package/registerComponent/dist/registerComponent.d.ts +8 -7
- package/registerComponent/dist/registerFunction.d.ts +2 -127
- package/registerComponent/dist/types/choice-type.d.ts +16 -0
- package/registerComponent/dist/types/component-types.d.ts +258 -0
- package/registerComponent/dist/types/container-types.d.ts +35 -0
- package/registerComponent/dist/types/function-types.d.ts +100 -0
- package/registerComponent/dist/types/misc-types.d.ts +38 -0
- package/registerComponent/dist/types/primitive-types.d.ts +123 -0
- package/registerComponent/dist/types/shared-controls.d.ts +40 -0
- package/registerComponent/dist/version.d.ts +1 -1
- package/registerFunction/dist/exports.d.ts +2 -2
- package/registerFunction/dist/index.cjs.js.map +1 -1
- package/registerFunction/dist/index.esm.js.map +1 -1
- package/registerFunction/dist/prop-types.d.ts +6 -478
- package/registerFunction/dist/registerComponent.d.ts +8 -7
- package/registerFunction/dist/registerFunction.d.ts +2 -127
- package/registerFunction/dist/types/choice-type.d.ts +16 -0
- package/registerFunction/dist/types/component-types.d.ts +258 -0
- package/registerFunction/dist/types/container-types.d.ts +35 -0
- package/registerFunction/dist/types/function-types.d.ts +100 -0
- package/registerFunction/dist/types/misc-types.d.ts +38 -0
- package/registerFunction/dist/types/primitive-types.d.ts +123 -0
- package/registerFunction/dist/types/shared-controls.d.ts +40 -0
- package/registerFunction/dist/version.d.ts +1 -1
- package/registerGlobalContext/dist/exports.d.ts +2 -2
- package/registerGlobalContext/dist/prop-types.d.ts +6 -478
- package/registerGlobalContext/dist/registerComponent.d.ts +8 -7
- package/registerGlobalContext/dist/registerFunction.d.ts +2 -127
- package/registerGlobalContext/dist/types/choice-type.d.ts +16 -0
- package/registerGlobalContext/dist/types/component-types.d.ts +258 -0
- package/registerGlobalContext/dist/types/container-types.d.ts +35 -0
- package/registerGlobalContext/dist/types/function-types.d.ts +100 -0
- package/registerGlobalContext/dist/types/misc-types.d.ts +38 -0
- package/registerGlobalContext/dist/types/primitive-types.d.ts +123 -0
- package/registerGlobalContext/dist/types/shared-controls.d.ts +40 -0
- package/registerGlobalContext/dist/version.d.ts +1 -1
- package/registerToken/dist/exports.d.ts +2 -2
- package/registerToken/dist/prop-types.d.ts +6 -478
- package/registerToken/dist/registerComponent.d.ts +8 -7
- package/registerToken/dist/registerFunction.d.ts +2 -127
- package/registerToken/dist/types/choice-type.d.ts +16 -0
- package/registerToken/dist/types/component-types.d.ts +258 -0
- package/registerToken/dist/types/container-types.d.ts +35 -0
- package/registerToken/dist/types/function-types.d.ts +100 -0
- package/registerToken/dist/types/misc-types.d.ts +38 -0
- package/registerToken/dist/types/primitive-types.d.ts +123 -0
- package/registerToken/dist/types/shared-controls.d.ts +40 -0
- package/registerToken/dist/version.d.ts +1 -1
- package/registerTrait/dist/exports.d.ts +2 -2
- package/registerTrait/dist/prop-types.d.ts +6 -478
- package/registerTrait/dist/registerComponent.d.ts +8 -7
- package/registerTrait/dist/registerFunction.d.ts +2 -127
- package/registerTrait/dist/types/choice-type.d.ts +16 -0
- package/registerTrait/dist/types/component-types.d.ts +258 -0
- package/registerTrait/dist/types/container-types.d.ts +35 -0
- package/registerTrait/dist/types/function-types.d.ts +100 -0
- package/registerTrait/dist/types/misc-types.d.ts +38 -0
- package/registerTrait/dist/types/primitive-types.d.ts +123 -0
- package/registerTrait/dist/types/shared-controls.d.ts +40 -0
- package/registerTrait/dist/version.d.ts +1 -1
- /package/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
- /package/registerComponent/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
- /package/registerFunction/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
- /package/registerGlobalContext/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
- /package/registerToken/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
- /package/registerTrait/dist/{type-utils.d.ts → types/type-utils.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import { CodeComponentElement, CSSProperties } from \"./element-types\";\nimport {\n ContextDependentConfig,\n InferDataType,\n ProjectData,\n PropType,\n RestrictPropType,\n StudioOps,\n} from \"./prop-types\";\nimport { TupleUnion } from \"./type-utils\";\nexport type * from \"./prop-types\";\n\nconst root = globalThis as any;\n\nexport interface ActionProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n /**\n * Operations available to the editor that allow modifying the entire component.\n */\n studioOps: StudioOps;\n /**\n * Metadata from the studio project.\n */\n projectData: ProjectData;\n /**\n * The document that the component will be rendered into; instead of using\n * `document` directly (for, say, `document.querySelector()` etc.), you\n * should use this instead.\n */\n studioDocument: typeof document;\n}\n\nexport type Action<P> =\n | {\n type: \"button-action\";\n label: string;\n onClick: (props: ActionProps<P>) => void;\n hidden?: ContextDependentConfig<P, boolean>;\n }\n | {\n type: \"custom-action\";\n control: React.ComponentType<ActionProps<P>>;\n hidden?: ContextDependentConfig<P, boolean>;\n };\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\ninterface ComponentTemplate<P>\n extends Omit<CodeComponentElement<P>, \"type\" | \"name\"> {\n /**\n * A preview picture for the template.\n */\n previewImg?: string;\n}\n\nexport interface ComponentTemplates<P> {\n [name: string]: ComponentTemplate<P>;\n}\n\nexport type StateSpec<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ContextDependentConfig<P, boolean>;\n} & (\n | {\n type: \"readonly\";\n variableType: \"text\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"number\";\n initVal?: number;\n }\n | {\n type: \"readonly\";\n variableType: \"boolean\";\n initVal?: boolean;\n }\n | {\n type: \"readonly\";\n variableType: \"array\";\n initVal?: any[];\n }\n | {\n type: \"readonly\";\n variableType: \"object\";\n initVal?: object;\n }\n | {\n type: \"readonly\";\n variableType: \"dateString\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"dateRangeStrings\";\n initVal?: [string, string];\n }\n | {\n type: \"writable\";\n variableType:\n | \"text\"\n | \"number\"\n | \"boolean\"\n | \"array\"\n | \"object\"\n | \"dateString\"\n | \"dateRangeStrings\";\n valueProp: string;\n }\n);\n\nexport interface StateHelpers<P, T> {\n initFunc?: ($props: P) => T;\n onChangeArgsToValue?: (...args: any) => T;\n onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\n];\n\nexport type ComponentHelpers<P> = {\n states: Record<string, StateHelpers<P, any>>;\n};\n\nexport type ExternalComponentHelpers<P> = {\n helpers: ComponentHelpers<P>;\n importPath: string;\n} & (\n | {\n importName: string;\n }\n | {\n isDefaultExport: true;\n }\n);\n\nexport type StyleSection =\n | \"visibility\"\n | \"typography\"\n | \"sizing\"\n | \"spacing\"\n | \"background\"\n | \"transform\"\n | \"transitions\"\n | \"layout\"\n | \"overflow\"\n | \"border\"\n | \"shadows\"\n | \"effects\";\n\nexport interface CodeComponentMeta<P> {\n /**\n * Any unique string name used to identify that component. Each component\n * should be registered with a different `meta.name`, even if they have the\n * same name in the code.\n */\n name: string;\n /**\n * The name to be displayed for the component in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: string;\n /**\n * The description of the component to be shown in Studio.\n */\n description?: string;\n /**\n * A specific section to which the component should be displayed in Studio. By default, the component will be displayed in the \"Custom Components\" section.\n * A new section will be created to display the components with the same `section` value.\n */\n section?: string;\n /**\n * A link to an image that will be displayed as a thumbnail of the component in the Studio, if the component has a `section` specified.\n */\n thumbnailUrl?: string;\n /**\n * The javascript name to be used when generating code. Optional: if not\n * provided, `meta.name` is used.\n */\n importName?: string;\n /**\n * An object describing the component properties to be used in Studio.\n * For each `prop`, there should be an entry `meta.props[prop]` describing\n * its type.\n */\n props: { [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\n /**\n * An object describing the component states to be used in Studio.\n */\n states?: Record<string, StateSpec<P>>;\n /**\n * An object describing the components helpers to be used in Studio.\n * 1. states helpers: Each state can receive an \"initFunc\" prop to initialize\n * the implicit state in Studio, and an \"onChangeArgsToValue\" prop to\n * transform the event handler arguments into a value\n */\n componentHelpers?: ExternalComponentHelpers<P>;\n /**\n * An array describing the component actions to be used in Studio.\n */\n actions?: Action<P>[];\n /**\n * Whether style sections should be shown in Studio. For styles to work, the\n * component must accept a `className` prop. If unset, defaults to all styles.\n * Set to `false` if this component cannot be styled (for example, if it doesn't\n * render any DOM elements).\n */\n styleSections?: StyleSection[] | boolean;\n /**\n * Whether the element can be repeated in Studio. If unset, defaults to true.\n */\n isRepeatable?: boolean;\n /**\n * The path to be used when importing the component in the generated code.\n * It can be the name of the package that contains the component, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the component is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n /**\n * The prop that expects the CSS classes with styles to be applied to the\n * component. Optional: if not specified, Plasmic will expect it to be\n * `className`. Notice that if the component does not accept CSS classes, the\n * component will not be able to receive styles from the Studio.\n */\n classNameProp?: string;\n /**\n * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`\n * to interact with components, so it's not used in the generated code.\n * Optional: If not provided, the usual `ref` is used.\n */\n refProp?: string;\n /**\n * Default styles to start with when instantiating the component in Plasmic.\n */\n defaultStyles?: CSSProperties;\n /**\n * Component templates to start with on Plasmic.\n */\n templates?: ComponentTemplates<P>;\n /**\n * Registered name of parent component, used for grouping related components.\n */\n parentComponentName?: string;\n /**\n * Whether the component can be used as an attachment to an element.\n */\n isAttachment?: boolean;\n /**\n * Whether the component provides data to its slots using DataProvider.\n */\n providesData?: boolean;\n\n /**\n * If specified, then Figma components with the specified names will be mapped\n * to this component when you paste Figma content into Plasmic\n */\n figmaMappings?: {\n figmaComponentName: string;\n }[];\n\n /**\n * If specified, then Figma components will have their properties transformed\n * before being applied to this component. This is useful for transforming Figma\n * properties to the format expected by the component.\n */\n figmaPropsTransform?: (\n props: Record<string, string | number | boolean>\n ) => Record<\n string,\n string | number | boolean | null | unknown[] | Record<string, unknown>\n >;\n\n /**\n * If true, when an instance of this component is added, the element\n * will always be named by the name of this component.\n */\n alwaysAutoName?: boolean;\n\n /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ContextDependentConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\n\n /**\n * When true, when you click for the first time anywhere in the component including its slots, the component itself is\n * selected, making it easier to select the component instead of slot contents. So for instance, setting this on a\n * Button ensures that clicking on the Button’s text will still select the Button and not the text element in its\n * slot. Clicking again will deep-select the slot content.\n */\n trapsFocus?: boolean;\n\n /**\n * An object registering code component's variants that should be allowed in Studio, when the component is\n * used as the root of a Studio component.\n */\n variants?: Record<\n string,\n {\n cssSelector: string;\n displayName: string;\n }\n >;\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":";;;;;AAYA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0H/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AAwPF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import { CodeComponentElement, CSSProperties } from \"./element-types\";\nimport {\n ComponentContextConfig,\n ProjectData,\n PropType,\n RestrictPropType,\n StudioOps,\n} from \"./types/component-types\";\nimport { InferDataType } from \"./types/shared-controls\";\nimport { TupleUnion } from \"./types/type-utils\";\nexport type * from \"./prop-types\";\n\nconst root = globalThis as any;\n\nexport interface ActionProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n /**\n * Operations available to the editor that allow modifying the entire component.\n */\n studioOps: StudioOps;\n /**\n * Metadata from the studio project.\n */\n projectData: ProjectData;\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?: ComponentContextConfig<P, boolean>;\n }\n | {\n type: \"custom-action\";\n control: React.ComponentType<ActionProps<P>>;\n hidden?: ComponentContextConfig<P, boolean>;\n };\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\ninterface ComponentTemplate<P>\n extends Omit<CodeComponentElement<P>, \"type\" | \"name\"> {\n /**\n * A preview picture for the template.\n */\n previewImg?: string;\n}\n\nexport interface ComponentTemplates<P> {\n [name: string]: ComponentTemplate<P>;\n}\n\nexport type StateSpec<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ComponentContextConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ComponentContextConfig<P, boolean>;\n} & (\n | {\n type: \"readonly\";\n variableType: \"text\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"number\";\n initVal?: number;\n }\n | {\n type: \"readonly\";\n variableType: \"boolean\";\n initVal?: boolean;\n }\n | {\n type: \"readonly\";\n variableType: \"array\";\n initVal?: any[];\n }\n | {\n type: \"readonly\";\n variableType: \"object\";\n initVal?: object;\n }\n | {\n type: \"readonly\";\n variableType: \"dateString\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"dateRangeStrings\";\n initVal?: [string, string];\n }\n | {\n type: \"writable\";\n variableType:\n | \"text\"\n | \"number\"\n | \"boolean\"\n | \"array\"\n | \"object\"\n | \"dateString\"\n | \"dateRangeStrings\";\n valueProp: string;\n }\n);\n\nexport interface StateHelpers<P, T> {\n initFunc?: ($props: P) => T;\n onChangeArgsToValue?: (...args: any) => T;\n onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\n];\n\nexport type ComponentHelpers<P> = {\n states: Record<string, StateHelpers<P, any>>;\n};\n\nexport type ExternalComponentHelpers<P> = {\n helpers: ComponentHelpers<P>;\n importPath: string;\n} & (\n | {\n importName: string;\n }\n | {\n isDefaultExport: true;\n }\n);\n\nexport type StyleSection =\n | \"visibility\"\n | \"typography\"\n | \"sizing\"\n | \"spacing\"\n | \"background\"\n | \"transform\"\n | \"transitions\"\n | \"layout\"\n | \"overflow\"\n | \"border\"\n | \"shadows\"\n | \"effects\";\n\nexport interface CodeComponentMeta<P> {\n /**\n * Any unique string name used to identify that component. Each component\n * should be registered with a different `meta.name`, even if they have the\n * same name in the code.\n */\n name: string;\n /**\n * The name to be displayed for the component in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: string;\n /**\n * The description of the component to be shown in Studio.\n */\n description?: string;\n /**\n * A specific section to which the component should be displayed in Studio. By default, the component will be displayed in the \"Custom Components\" section.\n * A new section will be created to display the components with the same `section` value.\n */\n section?: string;\n /**\n * A link to an image that will be displayed as a thumbnail of the component in the Studio, if the component has a `section` specified.\n */\n thumbnailUrl?: string;\n /**\n * The javascript name to be used when generating code. Optional: if not\n * provided, `meta.name` is used.\n */\n importName?: string;\n /**\n * An object describing the component properties to be used in Studio.\n * For each `prop`, there should be an entry `meta.props[prop]` describing\n * its type.\n */\n props: { [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\n /**\n * An object describing the component states to be used in Studio.\n */\n states?: Record<string, StateSpec<P>>;\n /**\n * An object describing the components helpers to be used in Studio.\n * 1. states helpers: Each state can receive an \"initFunc\" prop to initialize\n * the implicit state in Studio, and an \"onChangeArgsToValue\" prop to\n * transform the event handler arguments into a value\n */\n componentHelpers?: ExternalComponentHelpers<P>;\n /**\n * An array describing the component actions to be used in Studio.\n */\n actions?: Action<P>[];\n /**\n * Whether style sections should be shown in Studio. For styles to work, the\n * component must accept a `className` prop. If unset, defaults to all styles.\n * Set to `false` if this component cannot be styled (for example, if it doesn't\n * render any DOM elements).\n */\n styleSections?: StyleSection[] | boolean;\n /**\n * Whether the element can be repeated in Studio. If unset, defaults to true.\n */\n isRepeatable?: boolean;\n /**\n * The path to be used when importing the component in the generated code.\n * It can be the name of the package that contains the component, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the component is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n /**\n * The prop that expects the CSS classes with styles to be applied to the\n * component. Optional: if not specified, Plasmic will expect it to be\n * `className`. Notice that if the component does not accept CSS classes, the\n * component will not be able to receive styles from the Studio.\n */\n classNameProp?: string;\n /**\n * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`\n * to interact with components, so it's not used in the generated code.\n * Optional: If not provided, the usual `ref` is used.\n */\n refProp?: string;\n /**\n * Default styles to start with when instantiating the component in Plasmic.\n */\n defaultStyles?: CSSProperties;\n /**\n * Component templates to start with on Plasmic.\n */\n templates?: ComponentTemplates<P>;\n /**\n * Registered name of parent component, used for grouping related components.\n */\n parentComponentName?: string;\n /**\n * Whether the component can be used as an attachment to an element.\n */\n isAttachment?: boolean;\n /**\n * Whether the component provides data to its slots using DataProvider.\n */\n providesData?: boolean;\n\n /**\n * If specified, then Figma components with the specified names will be mapped\n * to this component when you paste Figma content into Plasmic\n */\n figmaMappings?: {\n figmaComponentName: string;\n }[];\n\n /**\n * If specified, then Figma components will have their properties transformed\n * before being applied to this component. This is useful for transforming Figma\n * properties to the format expected by the component.\n */\n figmaPropsTransform?: (\n props: Record<string, string | number | boolean>\n ) => Record<\n string,\n string | number | boolean | null | unknown[] | Record<string, unknown>\n >;\n\n /**\n * If true, when an instance of this component is added, the element\n * will always be named by the name of this component.\n */\n alwaysAutoName?: boolean;\n\n /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ComponentContextConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\n\n /**\n * When true, when you click for the first time anywhere in the component including its slots, the component itself is\n * selected, making it easier to select the component instead of slot contents. So for instance, setting this on a\n * Button ensures that clicking on the Button’s text will still select the Button and not the text element in its\n * slot. Clicking again will deep-select the slot content.\n */\n trapsFocus?: boolean;\n\n /**\n * An object registering code component's variants that should be allowed in Studio, when the component is\n * used as the root of a Studio component.\n */\n variants?: Record<\n string,\n {\n cssSelector: string;\n displayName: string;\n }\n >;\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":";;;;;AAYA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0H/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AAwPF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import { CodeComponentElement, CSSProperties } from \"./element-types\";\nimport {\n ContextDependentConfig,\n InferDataType,\n ProjectData,\n PropType,\n RestrictPropType,\n StudioOps,\n} from \"./prop-types\";\nimport { TupleUnion } from \"./type-utils\";\nexport type * from \"./prop-types\";\n\nconst root = globalThis as any;\n\nexport interface ActionProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n /**\n * Operations available to the editor that allow modifying the entire component.\n */\n studioOps: StudioOps;\n /**\n * Metadata from the studio project.\n */\n projectData: ProjectData;\n /**\n * The document that the component will be rendered into; instead of using\n * `document` directly (for, say, `document.querySelector()` etc.), you\n * should use this instead.\n */\n studioDocument: typeof document;\n}\n\nexport type Action<P> =\n | {\n type: \"button-action\";\n label: string;\n onClick: (props: ActionProps<P>) => void;\n hidden?: ContextDependentConfig<P, boolean>;\n }\n | {\n type: \"custom-action\";\n control: React.ComponentType<ActionProps<P>>;\n hidden?: ContextDependentConfig<P, boolean>;\n };\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\ninterface ComponentTemplate<P>\n extends Omit<CodeComponentElement<P>, \"type\" | \"name\"> {\n /**\n * A preview picture for the template.\n */\n previewImg?: string;\n}\n\nexport interface ComponentTemplates<P> {\n [name: string]: ComponentTemplate<P>;\n}\n\nexport type StateSpec<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ContextDependentConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ContextDependentConfig<P, boolean>;\n} & (\n | {\n type: \"readonly\";\n variableType: \"text\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"number\";\n initVal?: number;\n }\n | {\n type: \"readonly\";\n variableType: \"boolean\";\n initVal?: boolean;\n }\n | {\n type: \"readonly\";\n variableType: \"array\";\n initVal?: any[];\n }\n | {\n type: \"readonly\";\n variableType: \"object\";\n initVal?: object;\n }\n | {\n type: \"readonly\";\n variableType: \"dateString\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"dateRangeStrings\";\n initVal?: [string, string];\n }\n | {\n type: \"writable\";\n variableType:\n | \"text\"\n | \"number\"\n | \"boolean\"\n | \"array\"\n | \"object\"\n | \"dateString\"\n | \"dateRangeStrings\";\n valueProp: string;\n }\n);\n\nexport interface StateHelpers<P, T> {\n initFunc?: ($props: P) => T;\n onChangeArgsToValue?: (...args: any) => T;\n onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\n];\n\nexport type ComponentHelpers<P> = {\n states: Record<string, StateHelpers<P, any>>;\n};\n\nexport type ExternalComponentHelpers<P> = {\n helpers: ComponentHelpers<P>;\n importPath: string;\n} & (\n | {\n importName: string;\n }\n | {\n isDefaultExport: true;\n }\n);\n\nexport type StyleSection =\n | \"visibility\"\n | \"typography\"\n | \"sizing\"\n | \"spacing\"\n | \"background\"\n | \"transform\"\n | \"transitions\"\n | \"layout\"\n | \"overflow\"\n | \"border\"\n | \"shadows\"\n | \"effects\";\n\nexport interface CodeComponentMeta<P> {\n /**\n * Any unique string name used to identify that component. Each component\n * should be registered with a different `meta.name`, even if they have the\n * same name in the code.\n */\n name: string;\n /**\n * The name to be displayed for the component in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: string;\n /**\n * The description of the component to be shown in Studio.\n */\n description?: string;\n /**\n * A specific section to which the component should be displayed in Studio. By default, the component will be displayed in the \"Custom Components\" section.\n * A new section will be created to display the components with the same `section` value.\n */\n section?: string;\n /**\n * A link to an image that will be displayed as a thumbnail of the component in the Studio, if the component has a `section` specified.\n */\n thumbnailUrl?: string;\n /**\n * The javascript name to be used when generating code. Optional: if not\n * provided, `meta.name` is used.\n */\n importName?: string;\n /**\n * An object describing the component properties to be used in Studio.\n * For each `prop`, there should be an entry `meta.props[prop]` describing\n * its type.\n */\n props: { [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\n /**\n * An object describing the component states to be used in Studio.\n */\n states?: Record<string, StateSpec<P>>;\n /**\n * An object describing the components helpers to be used in Studio.\n * 1. states helpers: Each state can receive an \"initFunc\" prop to initialize\n * the implicit state in Studio, and an \"onChangeArgsToValue\" prop to\n * transform the event handler arguments into a value\n */\n componentHelpers?: ExternalComponentHelpers<P>;\n /**\n * An array describing the component actions to be used in Studio.\n */\n actions?: Action<P>[];\n /**\n * Whether style sections should be shown in Studio. For styles to work, the\n * component must accept a `className` prop. If unset, defaults to all styles.\n * Set to `false` if this component cannot be styled (for example, if it doesn't\n * render any DOM elements).\n */\n styleSections?: StyleSection[] | boolean;\n /**\n * Whether the element can be repeated in Studio. If unset, defaults to true.\n */\n isRepeatable?: boolean;\n /**\n * The path to be used when importing the component in the generated code.\n * It can be the name of the package that contains the component, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the component is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n /**\n * The prop that expects the CSS classes with styles to be applied to the\n * component. Optional: if not specified, Plasmic will expect it to be\n * `className`. Notice that if the component does not accept CSS classes, the\n * component will not be able to receive styles from the Studio.\n */\n classNameProp?: string;\n /**\n * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`\n * to interact with components, so it's not used in the generated code.\n * Optional: If not provided, the usual `ref` is used.\n */\n refProp?: string;\n /**\n * Default styles to start with when instantiating the component in Plasmic.\n */\n defaultStyles?: CSSProperties;\n /**\n * Component templates to start with on Plasmic.\n */\n templates?: ComponentTemplates<P>;\n /**\n * Registered name of parent component, used for grouping related components.\n */\n parentComponentName?: string;\n /**\n * Whether the component can be used as an attachment to an element.\n */\n isAttachment?: boolean;\n /**\n * Whether the component provides data to its slots using DataProvider.\n */\n providesData?: boolean;\n\n /**\n * If specified, then Figma components with the specified names will be mapped\n * to this component when you paste Figma content into Plasmic\n */\n figmaMappings?: {\n figmaComponentName: string;\n }[];\n\n /**\n * If specified, then Figma components will have their properties transformed\n * before being applied to this component. This is useful for transforming Figma\n * properties to the format expected by the component.\n */\n figmaPropsTransform?: (\n props: Record<string, string | number | boolean>\n ) => Record<\n string,\n string | number | boolean | null | unknown[] | Record<string, unknown>\n >;\n\n /**\n * If true, when an instance of this component is added, the element\n * will always be named by the name of this component.\n */\n alwaysAutoName?: boolean;\n\n /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ContextDependentConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\n\n /**\n * When true, when you click for the first time anywhere in the component including its slots, the component itself is\n * selected, making it easier to select the component instead of slot contents. So for instance, setting this on a\n * Button ensures that clicking on the Button’s text will still select the Button and not the text element in its\n * slot. Clicking again will deep-select the slot content.\n */\n trapsFocus?: boolean;\n\n /**\n * An object registering code component's variants that should be allowed in Studio, when the component is\n * used as the root of a Studio component.\n */\n variants?: Record<\n string,\n {\n cssSelector: string;\n displayName: string;\n }\n >;\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":";AAYA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0H/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AAwPF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import { CodeComponentElement, CSSProperties } from \"./element-types\";\nimport {\n ComponentContextConfig,\n ProjectData,\n PropType,\n RestrictPropType,\n StudioOps,\n} from \"./types/component-types\";\nimport { InferDataType } from \"./types/shared-controls\";\nimport { TupleUnion } from \"./types/type-utils\";\nexport type * from \"./prop-types\";\n\nconst root = globalThis as any;\n\nexport interface ActionProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n /**\n * Operations available to the editor that allow modifying the entire component.\n */\n studioOps: StudioOps;\n /**\n * Metadata from the studio project.\n */\n projectData: ProjectData;\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?: ComponentContextConfig<P, boolean>;\n }\n | {\n type: \"custom-action\";\n control: React.ComponentType<ActionProps<P>>;\n hidden?: ComponentContextConfig<P, boolean>;\n };\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\ninterface ComponentTemplate<P>\n extends Omit<CodeComponentElement<P>, \"type\" | \"name\"> {\n /**\n * A preview picture for the template.\n */\n previewImg?: string;\n}\n\nexport interface ComponentTemplates<P> {\n [name: string]: ComponentTemplate<P>;\n}\n\nexport type StateSpec<P> = {\n onChangeProp: string;\n\n /**\n * If true, will hide the state on studio.\n */\n hidden?: ComponentContextConfig<P, boolean>;\n\n /**\n * If true, will hide the state in a collapsed section; good for states that\n * should not usually be used.\n */\n advanced?: ComponentContextConfig<P, boolean>;\n} & (\n | {\n type: \"readonly\";\n variableType: \"text\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"number\";\n initVal?: number;\n }\n | {\n type: \"readonly\";\n variableType: \"boolean\";\n initVal?: boolean;\n }\n | {\n type: \"readonly\";\n variableType: \"array\";\n initVal?: any[];\n }\n | {\n type: \"readonly\";\n variableType: \"object\";\n initVal?: object;\n }\n | {\n type: \"readonly\";\n variableType: \"dateString\";\n initVal?: string;\n }\n | {\n type: \"readonly\";\n variableType: \"dateRangeStrings\";\n initVal?: [string, string];\n }\n | {\n type: \"writable\";\n variableType:\n | \"text\"\n | \"number\"\n | \"boolean\"\n | \"array\"\n | \"object\"\n | \"dateString\"\n | \"dateRangeStrings\";\n valueProp: string;\n }\n);\n\nexport interface StateHelpers<P, T> {\n initFunc?: ($props: P) => T;\n onChangeArgsToValue?: (...args: any) => T;\n onMutate?: (stateValue: T, $ref: any) => void;\n}\n\n// A compile-time error will occur if a new field is added to the StateHelper\n// interface but not included in the keys array of state helper.\nexport const stateHelpersKeys: TupleUnion<keyof StateHelpers<any, any>> = [\n \"initFunc\",\n \"onChangeArgsToValue\",\n \"onMutate\",\n];\n\nexport type ComponentHelpers<P> = {\n states: Record<string, StateHelpers<P, any>>;\n};\n\nexport type ExternalComponentHelpers<P> = {\n helpers: ComponentHelpers<P>;\n importPath: string;\n} & (\n | {\n importName: string;\n }\n | {\n isDefaultExport: true;\n }\n);\n\nexport type StyleSection =\n | \"visibility\"\n | \"typography\"\n | \"sizing\"\n | \"spacing\"\n | \"background\"\n | \"transform\"\n | \"transitions\"\n | \"layout\"\n | \"overflow\"\n | \"border\"\n | \"shadows\"\n | \"effects\";\n\nexport interface CodeComponentMeta<P> {\n /**\n * Any unique string name used to identify that component. Each component\n * should be registered with a different `meta.name`, even if they have the\n * same name in the code.\n */\n name: string;\n /**\n * The name to be displayed for the component in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: string;\n /**\n * The description of the component to be shown in Studio.\n */\n description?: string;\n /**\n * A specific section to which the component should be displayed in Studio. By default, the component will be displayed in the \"Custom Components\" section.\n * A new section will be created to display the components with the same `section` value.\n */\n section?: string;\n /**\n * A link to an image that will be displayed as a thumbnail of the component in the Studio, if the component has a `section` specified.\n */\n thumbnailUrl?: string;\n /**\n * The javascript name to be used when generating code. Optional: if not\n * provided, `meta.name` is used.\n */\n importName?: string;\n /**\n * An object describing the component properties to be used in Studio.\n * For each `prop`, there should be an entry `meta.props[prop]` describing\n * its type.\n */\n props: { [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\n /**\n * An object describing the component states to be used in Studio.\n */\n states?: Record<string, StateSpec<P>>;\n /**\n * An object describing the components helpers to be used in Studio.\n * 1. states helpers: Each state can receive an \"initFunc\" prop to initialize\n * the implicit state in Studio, and an \"onChangeArgsToValue\" prop to\n * transform the event handler arguments into a value\n */\n componentHelpers?: ExternalComponentHelpers<P>;\n /**\n * An array describing the component actions to be used in Studio.\n */\n actions?: Action<P>[];\n /**\n * Whether style sections should be shown in Studio. For styles to work, the\n * component must accept a `className` prop. If unset, defaults to all styles.\n * Set to `false` if this component cannot be styled (for example, if it doesn't\n * render any DOM elements).\n */\n styleSections?: StyleSection[] | boolean;\n /**\n * Whether the element can be repeated in Studio. If unset, defaults to true.\n */\n isRepeatable?: boolean;\n /**\n * The path to be used when importing the component in the generated code.\n * It can be the name of the package that contains the component, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the component is the default export from that path. Optional: if\n * not specified, it's considered `false`.\n */\n isDefaultExport?: boolean;\n /**\n * The prop that expects the CSS classes with styles to be applied to the\n * component. Optional: if not specified, Plasmic will expect it to be\n * `className`. Notice that if the component does not accept CSS classes, the\n * component will not be able to receive styles from the Studio.\n */\n classNameProp?: string;\n /**\n * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`\n * to interact with components, so it's not used in the generated code.\n * Optional: If not provided, the usual `ref` is used.\n */\n refProp?: string;\n /**\n * Default styles to start with when instantiating the component in Plasmic.\n */\n defaultStyles?: CSSProperties;\n /**\n * Component templates to start with on Plasmic.\n */\n templates?: ComponentTemplates<P>;\n /**\n * Registered name of parent component, used for grouping related components.\n */\n parentComponentName?: string;\n /**\n * Whether the component can be used as an attachment to an element.\n */\n isAttachment?: boolean;\n /**\n * Whether the component provides data to its slots using DataProvider.\n */\n providesData?: boolean;\n\n /**\n * If specified, then Figma components with the specified names will be mapped\n * to this component when you paste Figma content into Plasmic\n */\n figmaMappings?: {\n figmaComponentName: string;\n }[];\n\n /**\n * If specified, then Figma components will have their properties transformed\n * before being applied to this component. This is useful for transforming Figma\n * properties to the format expected by the component.\n */\n figmaPropsTransform?: (\n props: Record<string, string | number | boolean>\n ) => Record<\n string,\n string | number | boolean | null | unknown[] | Record<string, unknown>\n >;\n\n /**\n * If true, when an instance of this component is added, the element\n * will always be named by the name of this component.\n */\n alwaysAutoName?: boolean;\n\n /**\n * If true, then won't be listed in the insert menu for content creators.\n */\n hideFromContentCreators?: boolean;\n\n refActions?: Record<string, RefActionRegistration<P>>;\n\n /**\n * Optional function that takes in component props and context, and returns\n * a string that will be used for labeling this element in the Outline panel\n * on the left of the Studio. This makes it easy to identify an element when\n * looking at the tree.\n */\n treeLabel?: ComponentContextConfig<P, string>;\n\n /**\n * The value of the CSS display property used by this component.\n * Plasmic passes in a class name prop to components to let users style them,\n * but normally this does not include layout properties like display.\n * However, if the user has set the components visibility to be visible\n * (for instance, in the base variant it was set to not visible ie display none,\n * but in a variant it's overridden to be visible), then Plasmic needs to know\n * what display property to set.\n * Defaults to \"flex\".\n */\n defaultDisplay?: string;\n\n /**\n * When true, when you click for the first time anywhere in the component including its slots, the component itself is\n * selected, making it easier to select the component instead of slot contents. So for instance, setting this on a\n * Button ensures that clicking on the Button’s text will still select the Button and not the text element in its\n * slot. Clicking again will deep-select the slot content.\n */\n trapsFocus?: boolean;\n\n /**\n * An object registering code component's variants that should be allowed in Studio, when the component is\n * used as the root of a Studio component.\n */\n variants?: Record<\n string,\n {\n cssSelector: string;\n displayName: string;\n }\n >;\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":";AAYA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA0H/B;AACA;AACa,IAAA,gBAAgB,GAA6C;IACxE,UAAU;IACV,qBAAqB;IACrB,UAAU;EACV;AAwPF,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;AAC3C,IAAA,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;AACtC,CAAA;AAEa,SAAU,iBAAiB,CACvC,SAAY,EACZ,IAAgD,EAAA;;AAGhD,IAAA,IACE,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,UAAC,CAAwB,EAAA;AACvB,QAAA,OAAA,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAA;AAAtD,KAAsD,CACzD,EACD;QACA,OAAO;AACR,KAAA;AACD,IAAA,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,EAAA,SAAA,EAAE,IAAI,EAAA,IAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
@@ -1,478 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
item?: any;
|
|
14
|
-
};
|
|
15
|
-
export type InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;
|
|
16
|
-
/**
|
|
17
|
-
* Context that we pass back to control functions.
|
|
18
|
-
*/
|
|
19
|
-
export type ControlContext<P> = [
|
|
20
|
-
/**
|
|
21
|
-
* props
|
|
22
|
-
*/
|
|
23
|
-
P,
|
|
24
|
-
/**
|
|
25
|
-
* `contextData` can be `null` if the prop controls are rendering before
|
|
26
|
-
* the component instance itself (it will re-render once the component
|
|
27
|
-
* calls `setControlContextData`)
|
|
28
|
-
*/
|
|
29
|
-
InferDataType<P> | null,
|
|
30
|
-
/**
|
|
31
|
-
* Extra information for the control to use
|
|
32
|
-
*/
|
|
33
|
-
ControlExtras
|
|
34
|
-
];
|
|
35
|
-
/**
|
|
36
|
-
* Config option that takes the context (e.g., props) of the component instance
|
|
37
|
-
* to dynamically set its value.
|
|
38
|
-
*/
|
|
39
|
-
export type ContextDependentConfig<P, R> = (...args: ControlContext<P>) => R;
|
|
40
|
-
export interface PropTypeBase<P> {
|
|
41
|
-
displayName?: string;
|
|
42
|
-
description?: string;
|
|
43
|
-
helpText?: string;
|
|
44
|
-
required?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* If the user has chosen to use a dynamic expression for this prop, provide
|
|
47
|
-
* a hint as to the expected values that the expression should evaluate to.
|
|
48
|
-
* This hint will be displayed alongside the code editor. You may use
|
|
49
|
-
* markdown in the text here.
|
|
50
|
-
*/
|
|
51
|
-
exprHint?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Function for whether this prop should be hidden in the right panel,
|
|
54
|
-
* given the current props for this component
|
|
55
|
-
*/
|
|
56
|
-
hidden?: ContextDependentConfig<P, boolean>;
|
|
57
|
-
readOnly?: boolean | ContextDependentConfig<P, boolean>;
|
|
58
|
-
/**
|
|
59
|
-
* If true, will hide the prop in a collapsed section; good for props that
|
|
60
|
-
* should not usually be used.
|
|
61
|
-
*/
|
|
62
|
-
advanced?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* If true, does not allow the user to use a dynamic expression for this prop
|
|
65
|
-
*/
|
|
66
|
-
disableDynamicValue?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* If set to true, the component will be remounted when the prop value is updated.
|
|
69
|
-
* (This behavior only applies to canvas)
|
|
70
|
-
*/
|
|
71
|
-
forceRemount?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* If true, the prop can't be overriden in different variants.
|
|
74
|
-
*/
|
|
75
|
-
invariantable?: boolean;
|
|
76
|
-
}
|
|
77
|
-
export interface Defaultable<P, T> {
|
|
78
|
-
/**
|
|
79
|
-
* Default value to set for this prop when the component is instantiated
|
|
80
|
-
*/
|
|
81
|
-
defaultValue?: T;
|
|
82
|
-
/**
|
|
83
|
-
* If no prop is given, the component uses a default; specify what
|
|
84
|
-
* that default is so the Plasmic user can see it in the studio UI
|
|
85
|
-
*/
|
|
86
|
-
defaultValueHint?: T | ContextDependentConfig<P, T | undefined>;
|
|
87
|
-
/**
|
|
88
|
-
* Use a dynamic value expression as the default instead
|
|
89
|
-
*/
|
|
90
|
-
defaultExpr?: string;
|
|
91
|
-
defaultExprHint?: string;
|
|
92
|
-
/**
|
|
93
|
-
* This function validates whether the prop value is valid.
|
|
94
|
-
* If the value is invalid, it returns an error message. Otherwise, it returns true.
|
|
95
|
-
*/
|
|
96
|
-
validator?: (value: T, ...args: ControlContext<P>) => (string | true) | Promise<string | true>;
|
|
97
|
-
}
|
|
98
|
-
export interface Controllable {
|
|
99
|
-
/**
|
|
100
|
-
* If true, this is a prop that should only be used inside Plasmic
|
|
101
|
-
* Studio for rendering artboards; will not be actually used in
|
|
102
|
-
* generated code.
|
|
103
|
-
*/
|
|
104
|
-
editOnly?: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* If specified, the value used for this prop will instead be
|
|
107
|
-
* mapped to the uncontrolledProp when generating code. This is
|
|
108
|
-
* useful if, for example, in the artboard, you want to use `value`
|
|
109
|
-
* prop to control the component, but in generated code, you want to
|
|
110
|
-
* map it to `defaultValue`.
|
|
111
|
-
*/
|
|
112
|
-
uncontrolledProp?: string;
|
|
113
|
-
}
|
|
114
|
-
export interface PropTypeBaseDefault<P, T> extends PropTypeBase<P>, Defaultable<P, T>, Controllable {
|
|
115
|
-
}
|
|
116
|
-
export interface PlainStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
117
|
-
type: "string";
|
|
118
|
-
control?: "default" | "large";
|
|
119
|
-
isLocalizable?: boolean;
|
|
120
|
-
}
|
|
121
|
-
export interface CodeStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
122
|
-
type: "code";
|
|
123
|
-
lang: "css" | "html" | "javascript" | "json";
|
|
124
|
-
}
|
|
125
|
-
export interface RichTextType<P> extends PropTypeBaseDefault<P, string> {
|
|
126
|
-
type: "richText";
|
|
127
|
-
}
|
|
128
|
-
export interface HrefType<P> extends PropTypeBaseDefault<P, string> {
|
|
129
|
-
type: "href";
|
|
130
|
-
}
|
|
131
|
-
export interface ColorType<P> extends PropTypeBaseDefault<P, string> {
|
|
132
|
-
type: "color";
|
|
133
|
-
/**
|
|
134
|
-
* If specified, and the user picks a color token in the Studio, then
|
|
135
|
-
* the value passed in as prop is a css variable reference, like
|
|
136
|
-
* `var(--TOKEN_ID)`, instead of the resolved hex value of the token.
|
|
137
|
-
* You should take care in using this in the proper css context --
|
|
138
|
-
* the css token is only defined if you are rendering under some
|
|
139
|
-
* Plasmic component in the DOM tree, which is usually the case,
|
|
140
|
-
* unless you are using a React portal.
|
|
141
|
-
*/
|
|
142
|
-
keepCssVar?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Prevent tokens from being selected.
|
|
145
|
-
*/
|
|
146
|
-
disableTokens?: boolean;
|
|
147
|
-
}
|
|
148
|
-
export interface DateStringType<P> extends PropTypeBaseDefault<P, string> {
|
|
149
|
-
type: "dateString";
|
|
150
|
-
}
|
|
151
|
-
export interface DateRangeStringsType<P> extends PropTypeBaseDefault<P, [string, string]> {
|
|
152
|
-
type: "dateRangeStrings";
|
|
153
|
-
}
|
|
154
|
-
export interface ClassType<P> extends PropTypeBase<P> {
|
|
155
|
-
type: "class";
|
|
156
|
-
/**
|
|
157
|
-
* Additional css selectors that can change how this style should look.
|
|
158
|
-
* Some examples:
|
|
159
|
-
*
|
|
160
|
-
* * `:hover` -- on hover
|
|
161
|
-
* * `[data-something="blah"] -- when the element with this class has
|
|
162
|
-
* an html attribute "data-something=blah"
|
|
163
|
-
* * :component[data-something="blah"] :self -- when the root of the
|
|
164
|
-
* component has an html attribute "data-something=blah". Note that
|
|
165
|
-
* the non-standard `:component` selector is used to select the
|
|
166
|
-
* component root, and the non-standard `:self` selector is used
|
|
167
|
-
* to select the element that this class is attached to.
|
|
168
|
-
*/
|
|
169
|
-
selectors?: {
|
|
170
|
-
/**
|
|
171
|
-
* A css selector, like `:hover` or `[data-something="blah"]`.
|
|
172
|
-
*/
|
|
173
|
-
selector: string;
|
|
174
|
-
/**
|
|
175
|
-
* An optional human-friendly label for the selector, so the studio user
|
|
176
|
-
* knows what this selector means.
|
|
177
|
-
*/
|
|
178
|
-
label?: string;
|
|
179
|
-
/**
|
|
180
|
-
* Initial styles to be applied for this selector
|
|
181
|
-
*/
|
|
182
|
-
defaultStyles?: CSSProperties;
|
|
183
|
-
}[];
|
|
184
|
-
/**
|
|
185
|
-
* If specified, then only shows these style sections for styling this class
|
|
186
|
-
*/
|
|
187
|
-
styleSections?: StyleSection[];
|
|
188
|
-
/**
|
|
189
|
-
* Initial styles to be applied for this class
|
|
190
|
-
*/
|
|
191
|
-
defaultStyles?: CSSProperties;
|
|
192
|
-
}
|
|
193
|
-
export interface ThemeResetClassType<P> extends PropTypeBase<P> {
|
|
194
|
-
type: "themeResetClass";
|
|
195
|
-
/**
|
|
196
|
-
* Normally, theme reset class will only target Plasmic-generated tags
|
|
197
|
-
* with the default tag styles. If you also want to target non-Plasmic-generated
|
|
198
|
-
* tags (say, rendered by your code components, or fetched as an HTML blob
|
|
199
|
-
* from somewhere), then specify `true` here.
|
|
200
|
-
*/
|
|
201
|
-
targetAllTags?: boolean;
|
|
202
|
-
}
|
|
203
|
-
export interface CardPickerType<P> extends PropTypeBaseDefault<P, string> {
|
|
204
|
-
type: "cardPicker";
|
|
205
|
-
modalTitle?: React.ReactNode | ContextDependentConfig<P, React.ReactNode>;
|
|
206
|
-
options: {
|
|
207
|
-
value: string;
|
|
208
|
-
label?: string;
|
|
209
|
-
imgUrl: string;
|
|
210
|
-
footer?: React.ReactNode;
|
|
211
|
-
}[] | ContextDependentConfig<P, {
|
|
212
|
-
value: string;
|
|
213
|
-
label?: string;
|
|
214
|
-
imgUrl: string;
|
|
215
|
-
footer?: React.ReactNode;
|
|
216
|
-
}[]>;
|
|
217
|
-
showInput?: boolean | ContextDependentConfig<P, boolean>;
|
|
218
|
-
onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
|
|
219
|
-
}
|
|
220
|
-
export type RichStringType<P> = PlainStringType<P> | CodeStringType<P> | RichTextType<P> | ColorType<P> | ClassType<P> | ThemeResetClassType<P> | CardPickerType<P> | HrefType<P>;
|
|
221
|
-
export type StringType<P> = "string" | "href" | RichStringType<P>;
|
|
222
|
-
export interface RichBooleanType<P> extends PropTypeBaseDefault<P, boolean> {
|
|
223
|
-
type: "boolean";
|
|
224
|
-
}
|
|
225
|
-
export type BooleanType<P> = "boolean" | RichBooleanType<P>;
|
|
226
|
-
export type GraphQLValue = {
|
|
227
|
-
query: string;
|
|
228
|
-
variables?: Record<string, any>;
|
|
229
|
-
};
|
|
230
|
-
export interface GraphQLType<P> extends PropTypeBaseDefault<P, GraphQLValue> {
|
|
231
|
-
type: "code";
|
|
232
|
-
lang: "graphql";
|
|
233
|
-
endpoint: string | ContextDependentConfig<P, string>;
|
|
234
|
-
method?: string | ContextDependentConfig<P, string>;
|
|
235
|
-
headers?: object | ContextDependentConfig<P, object>;
|
|
236
|
-
}
|
|
237
|
-
export interface NumberTypeBase<P> extends PropTypeBaseDefault<P, number> {
|
|
238
|
-
type: "number";
|
|
239
|
-
min?: number | ContextDependentConfig<P, number>;
|
|
240
|
-
max?: number | ContextDependentConfig<P, number>;
|
|
241
|
-
}
|
|
242
|
-
export interface PlainNumberType<P> extends NumberTypeBase<P> {
|
|
243
|
-
control?: "default";
|
|
244
|
-
}
|
|
245
|
-
export interface SliderNumberType<P> extends NumberTypeBase<P> {
|
|
246
|
-
control: "slider";
|
|
247
|
-
step?: number | ContextDependentConfig<P, number>;
|
|
248
|
-
}
|
|
249
|
-
export type RichNumberType<P> = PlainNumberType<P> | SliderNumberType<P>;
|
|
250
|
-
export type NumberType<P> = "number" | RichNumberType<P>;
|
|
251
|
-
export interface ObjectType<P> extends PropTypeBaseDefault<P, Record<string, any>> {
|
|
252
|
-
type: "object";
|
|
253
|
-
fields?: Record<string, PropType<P>>;
|
|
254
|
-
nameFunc?: (item: any, ...args: ControlContext<P>) => string | undefined;
|
|
255
|
-
}
|
|
256
|
-
export interface ArrayType<P> extends PropTypeBaseDefault<P, any[]> {
|
|
257
|
-
type: "array";
|
|
258
|
-
itemType?: ObjectType<P>;
|
|
259
|
-
/**
|
|
260
|
-
* Optional function that determines whether the user can delete a given item.
|
|
261
|
-
*/
|
|
262
|
-
unstable__canDelete?: (item: any, ...args: ControlContext<P>) => boolean;
|
|
263
|
-
/**
|
|
264
|
-
* Specify how to let Plasmic know how to update its own internal representation of the data when the value has
|
|
265
|
-
* changed, or when issuing a minimalValue or shownValue that is different.
|
|
266
|
-
*
|
|
267
|
-
* Important to specify this if you are expecting any nested expression values in this data type!
|
|
268
|
-
*/
|
|
269
|
-
unstable__keyFunc?: (item: any) => any;
|
|
270
|
-
/**
|
|
271
|
-
* Specify what would be the tentative new value that is set if the user makes any changes.
|
|
272
|
-
*
|
|
273
|
-
* Useful for field mappings.
|
|
274
|
-
*
|
|
275
|
-
* For instance, consider a Table where we have a `fields` prop:
|
|
276
|
-
*
|
|
277
|
-
* - Initially, the value is undefined. But if the user makes any changes, we would want to save an array of at
|
|
278
|
-
* least three items (corresponding to, say, three columns inferred from a schema).
|
|
279
|
-
*
|
|
280
|
-
* - Let's say there are 5 columns in the value. The data schema changes, removing a column and adding two new
|
|
281
|
-
* ones. Now we would want a different minimal value, containing 6 items.
|
|
282
|
-
*/
|
|
283
|
-
unstable__minimalValue?: ContextDependentConfig<P, any>;
|
|
284
|
-
}
|
|
285
|
-
export type JSONLikeType<P> = "object" | ObjectType<P> | ArrayType<P>;
|
|
286
|
-
export interface DataSourceType<P> extends PropTypeBase<P> {
|
|
287
|
-
type: "dataSource";
|
|
288
|
-
dataSource: "airtable" | "cms";
|
|
289
|
-
}
|
|
290
|
-
export type DataPickerValueType = string | number | (string | number)[];
|
|
291
|
-
export interface RichDataPickerType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
|
|
292
|
-
type: "dataSelector";
|
|
293
|
-
data?: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
|
|
294
|
-
alwaysShowValuePathAsLabel?: boolean;
|
|
295
|
-
isolateEnv?: boolean;
|
|
296
|
-
}
|
|
297
|
-
export type DataPickerType<P> = "dataPicker" | RichDataPickerType<P>;
|
|
298
|
-
export interface RichExprEditorType<P> extends PropTypeBaseDefault<P, DataPickerValueType> {
|
|
299
|
-
type: "exprEditor";
|
|
300
|
-
data?: Record<string, any> | ContextDependentConfig<P, Record<string, any>>;
|
|
301
|
-
isolateEnv?: boolean;
|
|
302
|
-
}
|
|
303
|
-
export type ExprEditorType<P> = "exprEditor" | RichExprEditorType<P>;
|
|
304
|
-
export interface FormValidationRulesType<P> extends PropTypeBaseDefault<P, any> {
|
|
305
|
-
type: "formValidationRules";
|
|
306
|
-
}
|
|
307
|
-
export interface EventHandlerType<P> extends PropTypeBase<P> {
|
|
308
|
-
type: "eventHandler";
|
|
309
|
-
argTypes: {
|
|
310
|
-
name: string;
|
|
311
|
-
type: ArgType<any>;
|
|
312
|
-
}[];
|
|
313
|
-
}
|
|
314
|
-
export type ChoiceValue = string | number | boolean;
|
|
315
|
-
export type ChoiceObject = {
|
|
316
|
-
label: string;
|
|
317
|
-
value: ChoiceValue;
|
|
318
|
-
};
|
|
319
|
-
export type ChoiceOptions = ChoiceValue[] | ChoiceObject[];
|
|
320
|
-
export interface ChoiceTypeBase<P, T> extends PropTypeBaseDefault<P, T> {
|
|
321
|
-
type: "choice";
|
|
322
|
-
options: ChoiceOptions | ContextDependentConfig<P, string[] | {
|
|
323
|
-
label: string;
|
|
324
|
-
value: string | number | boolean;
|
|
325
|
-
}[]>;
|
|
326
|
-
allowSearch?: boolean;
|
|
327
|
-
filterOption?: boolean;
|
|
328
|
-
onSearch?: ContextDependentConfig<P, ((value: string) => void) | undefined>;
|
|
329
|
-
}
|
|
330
|
-
export interface SingleChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean> {
|
|
331
|
-
multiSelect?: false;
|
|
332
|
-
}
|
|
333
|
-
export interface MultiChoiceType<P> extends ChoiceTypeBase<P, (string | number | boolean)[]> {
|
|
334
|
-
multiSelect: true;
|
|
335
|
-
}
|
|
336
|
-
export interface CustomChoiceType<P> extends ChoiceTypeBase<P, string | number | boolean | (string | number | boolean)[]> {
|
|
337
|
-
multiSelect: ContextDependentConfig<P, boolean>;
|
|
338
|
-
}
|
|
339
|
-
export type ChoiceType<P> = SingleChoiceType<P> | MultiChoiceType<P> | CustomChoiceType<P>;
|
|
340
|
-
export interface RichSlotType<P> {
|
|
341
|
-
type: "slot";
|
|
342
|
-
description?: string;
|
|
343
|
-
/**
|
|
344
|
-
* The unique names of all code components that can be placed in the slot
|
|
345
|
-
*/
|
|
346
|
-
allowedComponents?: string[];
|
|
347
|
-
/**
|
|
348
|
-
* Wheter Plasmic Components with a root component included in the
|
|
349
|
-
* "allowedComponents" list are valid or not.
|
|
350
|
-
* Only used if the "allowedComponents" list is set.
|
|
351
|
-
*/
|
|
352
|
-
allowRootWrapper?: boolean;
|
|
353
|
-
/**
|
|
354
|
-
* Whether the "empty slot" placeholder should be hidden in the canvas.
|
|
355
|
-
*/
|
|
356
|
-
hidePlaceholder?: boolean;
|
|
357
|
-
/**
|
|
358
|
-
* Whether the slot is repeated, i.e., is rendered multiple times using
|
|
359
|
-
* repeatedElement().
|
|
360
|
-
*/
|
|
361
|
-
isRepeated?: boolean;
|
|
362
|
-
/**
|
|
363
|
-
* A nicer, human-readable display name for your slot prop
|
|
364
|
-
*/
|
|
365
|
-
displayName?: string;
|
|
366
|
-
/**
|
|
367
|
-
* Function for whether this slot should be hidden from the left tree,
|
|
368
|
-
* given the current props for this component
|
|
369
|
-
*/
|
|
370
|
-
hidden?: ContextDependentConfig<P, boolean>;
|
|
371
|
-
/**
|
|
372
|
-
* If slot is a render prop (accepts a function that takes in some
|
|
373
|
-
* arguments and returns some JSX), then specify the names of the
|
|
374
|
-
* arguments expected by the render prop function.
|
|
375
|
-
*/
|
|
376
|
-
renderPropParams?: string[];
|
|
377
|
-
/**
|
|
378
|
-
* When inserting top-level "page sections", should this slot be the default target?
|
|
379
|
-
*/
|
|
380
|
-
unstable__isMainContentSlot?: boolean;
|
|
381
|
-
defaultValue?: PlasmicElement | PlasmicElement[];
|
|
382
|
-
/**
|
|
383
|
-
* When true, when you click for the first time in this slot and the component was not selected, the component itself
|
|
384
|
-
* is selected, making it easier to select the component instead of slot contents. So for
|
|
385
|
-
* instance, setting this on a Button slot ensures that clicking on the Button’s text will still select the Button and not
|
|
386
|
-
* the text element in its slot. Clicking again will deep-select the slot content. Similar in this regard to trapsFocus on components.
|
|
387
|
-
*
|
|
388
|
-
* Furthermore, the component further shows the props of whatever is in the slot on
|
|
389
|
-
* the parent component for the user's convenience. Handy for various “wrapper" components, form fields, and so on.
|
|
390
|
-
*/
|
|
391
|
-
mergeWithParent?: boolean | ContextDependentConfig<P, boolean>;
|
|
392
|
-
/**
|
|
393
|
-
* A function that returns true to hide the merged props conditionally.
|
|
394
|
-
*/
|
|
395
|
-
hiddenMergedProps?: ContextDependentConfig<P, boolean>;
|
|
396
|
-
}
|
|
397
|
-
export type SlotType<P> = "slot" | RichSlotType<P>;
|
|
398
|
-
export interface RichImageUrlType<P> extends PropTypeBaseDefault<P, string> {
|
|
399
|
-
type: "imageUrl";
|
|
400
|
-
}
|
|
401
|
-
export type ImageUrlType<P> = "imageUrl" | RichImageUrlType<P>;
|
|
402
|
-
export interface ModalProps {
|
|
403
|
-
show?: boolean;
|
|
404
|
-
children?: React.ReactNode;
|
|
405
|
-
onClose: () => void;
|
|
406
|
-
style?: CSSProperties;
|
|
407
|
-
}
|
|
408
|
-
export interface StudioOps {
|
|
409
|
-
showModal: (modalProps: Omit<ModalProps, "onClose"> & {
|
|
410
|
-
onClose?: () => void;
|
|
411
|
-
}) => void;
|
|
412
|
-
refreshQueryData: () => void;
|
|
413
|
-
appendToSlot: (element: PlasmicElement, slotName: string) => void;
|
|
414
|
-
removeFromSlotAt: (pos: number, slotName: string) => void;
|
|
415
|
-
updateProps: (newValues: any) => void;
|
|
416
|
-
updateStates: (newValues: any) => void;
|
|
417
|
-
}
|
|
418
|
-
export interface ProjectData {
|
|
419
|
-
components: {
|
|
420
|
-
name: string;
|
|
421
|
-
}[];
|
|
422
|
-
pages: {
|
|
423
|
-
name: string;
|
|
424
|
-
pageMeta: {
|
|
425
|
-
path: string;
|
|
426
|
-
};
|
|
427
|
-
}[];
|
|
428
|
-
}
|
|
429
|
-
export interface CustomControlProps<P> {
|
|
430
|
-
componentProps: P;
|
|
431
|
-
/**
|
|
432
|
-
* `contextData` can be `null` if the prop controls are rendering before
|
|
433
|
-
* the component instance itself (it will re-render once the component
|
|
434
|
-
* calls `setControlContextData`)
|
|
435
|
-
*/
|
|
436
|
-
contextData: InferDataType<P> | null;
|
|
437
|
-
/**
|
|
438
|
-
* Operations available to the editor that allow modifying the entire component.
|
|
439
|
-
* Can be null if the custom prop is used in a global context.
|
|
440
|
-
*/
|
|
441
|
-
studioOps: StudioOps | null;
|
|
442
|
-
/**
|
|
443
|
-
* Metadata from the studio project.
|
|
444
|
-
*/
|
|
445
|
-
projectData: ProjectData;
|
|
446
|
-
value: any;
|
|
447
|
-
/**
|
|
448
|
-
* Sets the value to be passed to the prop. Expects a JSON-compatible value.
|
|
449
|
-
*/
|
|
450
|
-
updateValue: (newVal: any) => void;
|
|
451
|
-
/**
|
|
452
|
-
* Full screen modal component
|
|
453
|
-
*/
|
|
454
|
-
FullscreenModal: React.ComponentType<ModalProps>;
|
|
455
|
-
/**
|
|
456
|
-
* Modal component for the side pane
|
|
457
|
-
*/
|
|
458
|
-
SideModal: React.ComponentType<ModalProps>;
|
|
459
|
-
/**
|
|
460
|
-
* The document that the component will be rendered into; instead of using
|
|
461
|
-
* `document` directly (for, say, `document.querySelector()` etc.), you
|
|
462
|
-
* should use this instead.
|
|
463
|
-
*/
|
|
464
|
-
studioDocument: typeof document;
|
|
465
|
-
}
|
|
466
|
-
export type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
|
|
467
|
-
export interface RichCustomType<P> extends PropTypeBaseDefault<P, any> {
|
|
468
|
-
type: "custom";
|
|
469
|
-
control: CustomControl<P>;
|
|
470
|
-
}
|
|
471
|
-
export type CustomType<P> = RichCustomType<P> | CustomControl<P>;
|
|
472
|
-
export type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, string>;
|
|
473
|
-
export type PropType<P> = StringType<P> | BooleanType<P> | GraphQLType<P> | NumberType<P> | JSONLikeType<P> | DataSourceType<P> | DataPickerType<P> | ExprEditorType<P> | FormValidationRulesType<P> | EventHandlerType<P> | ChoiceType<P> | CustomType<P> | ImageUrlType<P> | SlotType<P> | DateStringType<P> | DateRangeStringsType<P>;
|
|
474
|
-
export type ArgType<P> = Exclude<PropType<P>, SlotType<P> | EventHandlerType<P>>;
|
|
475
|
-
export type StringCompatType<P> = DateStringType<P> | StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P> | DataPickerType<P>;
|
|
476
|
-
export type BoolCompatType<P> = BooleanType<P> | CustomType<P> | DataPickerType<P>;
|
|
477
|
-
export type NumberCompatType<P> = NumberType<P> | CustomType<P> | DataPickerType<P>;
|
|
478
|
-
export type RestrictPropType<T, P> = T extends string ? StringCompatType<P> : T extends boolean ? BoolCompatType<P> : T extends number ? NumberCompatType<P> : PropType<P>;
|
|
1
|
+
import { ChoiceObject, ChoiceOptions, ChoiceValue } from "./types/choice-type";
|
|
2
|
+
import { ComponentControlContext, DynamicType } from "./types/component-types";
|
|
3
|
+
import { DataPickerValueType, GraphQLValue } from "./types/misc-types";
|
|
4
|
+
import { CanvasComponentProps, ContextDependentConfig, ControlExtras, InferDataType } from "./types/shared-controls";
|
|
5
|
+
export type { CanvasComponentProps, ChoiceObject, ChoiceOptions, ChoiceValue, ComponentControlContext, ContextDependentConfig, ControlExtras, DataPickerValueType, DynamicType, GraphQLValue, InferDataType, };
|
|
6
|
+
export type * from "./types/component-types";
|