@plasmicapp/host 1.0.14 → 1.0.17
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/package.json +6 -5
- package/registerGlobalContext/dist/element-types.d.ts +103 -0
- package/registerGlobalContext/dist/index.cjs.js +14 -0
- package/registerGlobalContext/dist/index.cjs.js.map +1 -0
- package/registerGlobalContext/dist/index.esm.js +10 -0
- package/registerGlobalContext/dist/index.esm.js.map +1 -0
- package/registerGlobalContext/dist/registerComponent.d.ts +244 -0
- package/registerGlobalContext/dist/registerGlobalContext.d.ts +61 -0
- package/registerGlobalContext/package.json +5 -0
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/host",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "plasmic library for app hosting",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"module": "dist/host.esm.js",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"registerComponent"
|
|
10
|
+
"registerComponent",
|
|
11
|
+
"registerGlobalContext"
|
|
11
12
|
],
|
|
12
13
|
"size-limit": [
|
|
13
14
|
{
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"analyze": "size-limit --why"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@plasmicapp/preamble": "0.0.
|
|
33
|
+
"@plasmicapp/preamble": "0.0.50",
|
|
33
34
|
"window-or-global": "^1.0.1"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
@@ -39,8 +40,8 @@
|
|
|
39
40
|
"@size-limit/preset-small-lib": "^4.11.0",
|
|
40
41
|
"@types/classnames": "^2.2.9",
|
|
41
42
|
"@types/node": "^14.0.26",
|
|
42
|
-
"@types/react": "^
|
|
43
|
-
"@types/react-dom": "^
|
|
43
|
+
"@types/react": "^17.0.39",
|
|
44
|
+
"@types/react-dom": "^17.0.11",
|
|
44
45
|
"csstype": "^3.0.8",
|
|
45
46
|
"rollup": "^2.47.0",
|
|
46
47
|
"rollup-plugin-dts": "^3.0.1",
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Properties } from "csstype";
|
|
2
|
+
export declare type CSSProperties = Properties<string | number>;
|
|
3
|
+
declare type ContainerTags = "a" | "address" | "article" | "aside" | "blockquote" | "button" | "code" | "dd" | "div" | "dl" | "dt" | "form" | "footer" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "header" | "hgroup" | "label" | "li" | "main" | "nav" | "ol" | "p" | "pre" | "section" | "span" | "ul";
|
|
4
|
+
declare type CommonAttrKeys = "title" | "tabIndex" | "className" | "id" | "aria-label" | "aria-hidden" | "aria-labelledby" | "aria-describedby" | "role";
|
|
5
|
+
declare type PictureAttrKeys = "alt" | "loading" | CommonAttrKeys;
|
|
6
|
+
declare type LinkAttrKeys = "href" | "target" | CommonAttrKeys;
|
|
7
|
+
declare type TextAreaAttrKeys = "disabled" | "value" | "cols" | "rows" | "placeholder" | CommonAttrKeys;
|
|
8
|
+
declare type InputAttrKeys = "disabled" | "value" | "defaultValue" | "name" | "autoComplete" | "checked" | "placeholder" | CommonAttrKeys;
|
|
9
|
+
declare type ButtonAttrKeys = "disabled" | CommonAttrKeys;
|
|
10
|
+
declare type Attrs<Keys extends string> = Partial<Record<Keys, string>>;
|
|
11
|
+
export interface PictureElement {
|
|
12
|
+
type: "img";
|
|
13
|
+
src: string;
|
|
14
|
+
styles?: CSSProperties;
|
|
15
|
+
attrs?: Attrs<PictureAttrKeys>;
|
|
16
|
+
}
|
|
17
|
+
export declare type ImageElement = PictureElement;
|
|
18
|
+
interface LinkTextElement {
|
|
19
|
+
type: "text";
|
|
20
|
+
tag: "a";
|
|
21
|
+
value: string;
|
|
22
|
+
styles?: CSSProperties;
|
|
23
|
+
attrs?: Attrs<LinkAttrKeys>;
|
|
24
|
+
}
|
|
25
|
+
interface ButtonTextElement {
|
|
26
|
+
type: "text";
|
|
27
|
+
tag: "button";
|
|
28
|
+
value: string;
|
|
29
|
+
styles?: CSSProperties;
|
|
30
|
+
attrs?: Attrs<ButtonAttrKeys>;
|
|
31
|
+
}
|
|
32
|
+
interface GenericTextElement {
|
|
33
|
+
type: "text";
|
|
34
|
+
/**
|
|
35
|
+
* Default: "div"
|
|
36
|
+
*/
|
|
37
|
+
tag?: Exclude<ContainerTags, "a" | "button">;
|
|
38
|
+
value: string;
|
|
39
|
+
styles?: CSSProperties;
|
|
40
|
+
attrs?: Attrs<CommonAttrKeys>;
|
|
41
|
+
}
|
|
42
|
+
export declare type TextElement = string | LinkTextElement | ButtonTextElement | GenericTextElement;
|
|
43
|
+
interface LinkContainerElement {
|
|
44
|
+
type: "box" | "vbox" | "hbox";
|
|
45
|
+
tag: "a";
|
|
46
|
+
children?: PlasmicElement | PlasmicElement[];
|
|
47
|
+
styles?: CSSProperties;
|
|
48
|
+
attrs?: Attrs<LinkAttrKeys>;
|
|
49
|
+
}
|
|
50
|
+
interface ButtonContainerElement {
|
|
51
|
+
type: "box" | "vbox" | "hbox";
|
|
52
|
+
tag: "button";
|
|
53
|
+
children?: PlasmicElement | PlasmicElement[];
|
|
54
|
+
styles?: CSSProperties;
|
|
55
|
+
attrs?: Attrs<ButtonAttrKeys>;
|
|
56
|
+
}
|
|
57
|
+
interface GenericContainerElement {
|
|
58
|
+
type: "box" | "vbox" | "hbox";
|
|
59
|
+
/**
|
|
60
|
+
* Default: "div"
|
|
61
|
+
*/
|
|
62
|
+
tag?: Exclude<ContainerTags, "a" | "button">;
|
|
63
|
+
children?: PlasmicElement | PlasmicElement[];
|
|
64
|
+
styles?: CSSProperties;
|
|
65
|
+
attrs?: Attrs<CommonAttrKeys>;
|
|
66
|
+
}
|
|
67
|
+
export declare type ContainerElement = LinkContainerElement | ButtonContainerElement | GenericContainerElement;
|
|
68
|
+
export interface ButtonElement {
|
|
69
|
+
type: "button";
|
|
70
|
+
value: string;
|
|
71
|
+
styles?: CSSProperties;
|
|
72
|
+
attrs?: Attrs<ButtonAttrKeys>;
|
|
73
|
+
}
|
|
74
|
+
interface InputElement {
|
|
75
|
+
type: "input" | "password";
|
|
76
|
+
styles?: CSSProperties;
|
|
77
|
+
attrs?: Attrs<InputAttrKeys>;
|
|
78
|
+
}
|
|
79
|
+
interface TextAreaElement {
|
|
80
|
+
type: "textarea";
|
|
81
|
+
styles?: CSSProperties;
|
|
82
|
+
attrs?: Attrs<TextAreaAttrKeys>;
|
|
83
|
+
}
|
|
84
|
+
export declare type TextInputElement = InputElement | TextAreaElement;
|
|
85
|
+
interface JsonElement {
|
|
86
|
+
type: "json";
|
|
87
|
+
value: any;
|
|
88
|
+
}
|
|
89
|
+
export interface CodeComponentElement<P> {
|
|
90
|
+
type: "component";
|
|
91
|
+
/**
|
|
92
|
+
* The registered component name
|
|
93
|
+
*/
|
|
94
|
+
name: string;
|
|
95
|
+
styles?: CSSProperties;
|
|
96
|
+
props?: {
|
|
97
|
+
[prop in keyof Partial<P>]: number | string | boolean | null | undefined | JsonElement | PlasmicElement | PlasmicElement[];
|
|
98
|
+
} & {
|
|
99
|
+
[prop: string]: number | string | boolean | null | undefined | JsonElement | PlasmicElement | PlasmicElement[];
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export declare type PlasmicElement = ImageElement | TextElement | ContainerElement | ButtonElement | TextInputElement | CodeComponentElement<{}>;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var root = globalThis;
|
|
6
|
+
if (root.__PlasmicContextRegistry == null) {
|
|
7
|
+
root.__PlasmicContextRegistry = [];
|
|
8
|
+
}
|
|
9
|
+
function registerGlobalContext(component, meta) {
|
|
10
|
+
root.__PlasmicContextRegistry.push({ component: component, meta: meta });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports['default'] = registerGlobalContext;
|
|
14
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/registerGlobalContext.ts"],"sourcesContent":["import {\n BooleanType,\n ChoiceType,\n CustomType,\n JSONLikeType,\n NumberType,\n StringType,\n SupportControlled,\n} from \"./registerComponent\";\n\nconst root = globalThis as any;\n\nexport type PropType<P> = SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | CustomType<P>\n>;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n StringType<P> | ChoiceType<P> | JSONLikeType<P> | CustomType<P>\n >\n : T extends boolean\n ? SupportControlled<BooleanType<P> | JSONLikeType<P> | CustomType<P>>\n : T extends number\n ? SupportControlled<NumberType<P> | JSONLikeType<P> | CustomType<P>>\n : PropType<P>;\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\nexport interface GlobalContextMeta<P> {\n /**\n * Any unique string name used to identify that context. Each context\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 context in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: 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 context 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 * The path to be used when importing the context in the generated code.\n * It can be the name of the package that contains the context, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the context 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 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\nexport interface GlobalContextRegistration {\n component: React.ComponentType<any>;\n meta: GlobalContextMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicContextRegistry: GlobalContextRegistration[];\n }\n}\n\nif (root.__PlasmicContextRegistry == null) {\n root.__PlasmicContextRegistry = [];\n}\n\nexport default function registerGlobalContext<\n T extends React.ComponentType<any>\n>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>) {\n root.__PlasmicContextRegistry.push({ component, meta });\n}\n"],"names":[],"mappings":";;;;AAUA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA8E/B,IAAI,IAAI,CAAC,wBAAwB,IAAI,IAAI,EAAE;IACzC,IAAI,CAAC,wBAAwB,GAAG,EAAE,CAAC;CACpC;SAEuB,qBAAqB,CAE3C,SAAY,EAAE,IAAgD;IAC9D,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;AAC1D;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var root = globalThis;
|
|
2
|
+
if (root.__PlasmicContextRegistry == null) {
|
|
3
|
+
root.__PlasmicContextRegistry = [];
|
|
4
|
+
}
|
|
5
|
+
function registerGlobalContext(component, meta) {
|
|
6
|
+
root.__PlasmicContextRegistry.push({ component: component, meta: meta });
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { registerGlobalContext as default };
|
|
10
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/registerGlobalContext.ts"],"sourcesContent":["import {\n BooleanType,\n ChoiceType,\n CustomType,\n JSONLikeType,\n NumberType,\n StringType,\n SupportControlled,\n} from \"./registerComponent\";\n\nconst root = globalThis as any;\n\nexport type PropType<P> = SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | CustomType<P>\n>;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n StringType<P> | ChoiceType<P> | JSONLikeType<P> | CustomType<P>\n >\n : T extends boolean\n ? SupportControlled<BooleanType<P> | JSONLikeType<P> | CustomType<P>>\n : T extends number\n ? SupportControlled<NumberType<P> | JSONLikeType<P> | CustomType<P>>\n : PropType<P>;\n\ntype DistributedKeyOf<T> = T extends any ? keyof T : never;\n\nexport interface GlobalContextMeta<P> {\n /**\n * Any unique string name used to identify that context. Each context\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 context in Studio. Optional: if not\n * specified, `meta.name` is used.\n */\n displayName?: 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 context 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 * The path to be used when importing the context in the generated code.\n * It can be the name of the package that contains the context, or the path\n * to the file in the project (relative to the root directory).\n */\n importPath: string;\n /**\n * Whether the context 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 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\nexport interface GlobalContextRegistration {\n component: React.ComponentType<any>;\n meta: GlobalContextMeta<any>;\n}\n\ndeclare global {\n interface Window {\n __PlasmicContextRegistry: GlobalContextRegistration[];\n }\n}\n\nif (root.__PlasmicContextRegistry == null) {\n root.__PlasmicContextRegistry = [];\n}\n\nexport default function registerGlobalContext<\n T extends React.ComponentType<any>\n>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>) {\n root.__PlasmicContextRegistry.push({ component, meta });\n}\n"],"names":[],"mappings":"AAUA,IAAM,IAAI,GAAG,UAAiB,CAAC;AA8E/B,IAAI,IAAI,CAAC,wBAAwB,IAAI,IAAI,EAAE;IACzC,IAAI,CAAC,wBAAwB,GAAG,EAAE,CAAC;CACpC;SAEuB,qBAAqB,CAE3C,SAAY,EAAE,IAAgD;IAC9D,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;AAC1D;;;;"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CodeComponentElement, CSSProperties, PlasmicElement } from "./element-types";
|
|
3
|
+
export interface CanvasComponentProps<Data = any> {
|
|
4
|
+
/**
|
|
5
|
+
* This prop is only provided within the canvas of Plasmic Studio.
|
|
6
|
+
* Allows the component to set data to be consumed by the props' controls.
|
|
7
|
+
*/
|
|
8
|
+
setControlContextData?: (data: Data) => void;
|
|
9
|
+
}
|
|
10
|
+
declare type InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;
|
|
11
|
+
/**
|
|
12
|
+
* Config option that takes the context (e.g., props) of the component instance
|
|
13
|
+
* to dynamically set its value.
|
|
14
|
+
*/
|
|
15
|
+
declare type ContextDependentConfig<P, R> = (props: P,
|
|
16
|
+
/**
|
|
17
|
+
* `contextData` can be `null` if the prop controls are rendering before
|
|
18
|
+
* the component instance itself (it will re-render once the component
|
|
19
|
+
* calls `setControlContextData`)
|
|
20
|
+
*/
|
|
21
|
+
contextData: InferDataType<P> | null) => R;
|
|
22
|
+
interface PropTypeBase<P> {
|
|
23
|
+
displayName?: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
hidden?: ContextDependentConfig<P, boolean>;
|
|
26
|
+
}
|
|
27
|
+
interface StringTypeBase<P> extends PropTypeBase<P> {
|
|
28
|
+
defaultValue?: string;
|
|
29
|
+
defaultValueHint?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare type StringType<P> = "string" | (({
|
|
32
|
+
type: "string";
|
|
33
|
+
control?: "default" | "large";
|
|
34
|
+
} | {
|
|
35
|
+
type: "code";
|
|
36
|
+
lang: "css" | "html" | "javascript" | "json";
|
|
37
|
+
}) & StringTypeBase<P>);
|
|
38
|
+
export declare type BooleanType<P> = "boolean" | ({
|
|
39
|
+
type: "boolean";
|
|
40
|
+
defaultValue?: boolean;
|
|
41
|
+
defaultValueHint?: boolean;
|
|
42
|
+
} & PropTypeBase<P>);
|
|
43
|
+
interface NumberTypeBase<P> extends PropTypeBase<P> {
|
|
44
|
+
type: "number";
|
|
45
|
+
defaultValue?: number;
|
|
46
|
+
defaultValueHint?: number;
|
|
47
|
+
}
|
|
48
|
+
export declare type NumberType<P> = "number" | (({
|
|
49
|
+
control?: "default";
|
|
50
|
+
min?: number | ContextDependentConfig<P, number>;
|
|
51
|
+
max?: number | ContextDependentConfig<P, number>;
|
|
52
|
+
} | {
|
|
53
|
+
control: "slider";
|
|
54
|
+
min: number | ContextDependentConfig<P, number>;
|
|
55
|
+
max: number | ContextDependentConfig<P, number>;
|
|
56
|
+
step?: number | ContextDependentConfig<P, number>;
|
|
57
|
+
}) & NumberTypeBase<P>);
|
|
58
|
+
export declare type JSONLikeType<P> = "object" | ({
|
|
59
|
+
type: "object";
|
|
60
|
+
/**
|
|
61
|
+
* Expects a JSON-compatible value
|
|
62
|
+
*/
|
|
63
|
+
defaultValue?: any;
|
|
64
|
+
defaultValueHint?: any;
|
|
65
|
+
} & PropTypeBase<P>);
|
|
66
|
+
interface ChoiceTypeBase<P> extends PropTypeBase<P> {
|
|
67
|
+
type: "choice";
|
|
68
|
+
options: string[] | {
|
|
69
|
+
label: string;
|
|
70
|
+
value: string | number | boolean;
|
|
71
|
+
}[] | ContextDependentConfig<P, string[] | {
|
|
72
|
+
label: string;
|
|
73
|
+
value: string | number | boolean;
|
|
74
|
+
}[]>;
|
|
75
|
+
}
|
|
76
|
+
export declare type ChoiceType<P> = ({
|
|
77
|
+
defaultValue?: string;
|
|
78
|
+
defaultValueHint?: string;
|
|
79
|
+
multiSelect?: false;
|
|
80
|
+
} | {
|
|
81
|
+
defaultValue?: string[];
|
|
82
|
+
defaultValueHint?: string[];
|
|
83
|
+
multiSelect: true;
|
|
84
|
+
}) & ChoiceTypeBase<P>;
|
|
85
|
+
export interface ModalProps {
|
|
86
|
+
show?: boolean;
|
|
87
|
+
children?: React.ReactNode;
|
|
88
|
+
onClose: () => void;
|
|
89
|
+
style?: CSSProperties;
|
|
90
|
+
}
|
|
91
|
+
interface CustomControlProps<P> {
|
|
92
|
+
componentProps: P;
|
|
93
|
+
/**
|
|
94
|
+
* `contextData` can be `null` if the prop controls are rendering before
|
|
95
|
+
* the component instance itself (it will re-render once the component
|
|
96
|
+
* calls `setControlContextData`)
|
|
97
|
+
*/
|
|
98
|
+
contextData: InferDataType<P> | null;
|
|
99
|
+
value: any;
|
|
100
|
+
/**
|
|
101
|
+
* Sets the value to be passed to the prop. Expects a JSON-compatible value.
|
|
102
|
+
*/
|
|
103
|
+
updateValue: (newVal: any) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Full screen modal component
|
|
106
|
+
*/
|
|
107
|
+
FullscreenModal: React.ComponentType<ModalProps>;
|
|
108
|
+
/**
|
|
109
|
+
* Modal component for the side pane
|
|
110
|
+
*/
|
|
111
|
+
SideModal: React.ComponentType<ModalProps>;
|
|
112
|
+
}
|
|
113
|
+
export declare type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
|
|
114
|
+
export declare type CustomType<P> = CustomControl<P> | ({
|
|
115
|
+
type: "custom";
|
|
116
|
+
control: CustomControl<P>;
|
|
117
|
+
/**
|
|
118
|
+
* Expects a JSON-compatible value
|
|
119
|
+
*/
|
|
120
|
+
defaultValue?: any;
|
|
121
|
+
} & PropTypeBase<P>);
|
|
122
|
+
declare type SlotType = "slot" | {
|
|
123
|
+
type: "slot";
|
|
124
|
+
/**
|
|
125
|
+
* The unique names of all code components that can be placed in the slot
|
|
126
|
+
*/
|
|
127
|
+
allowedComponents?: string[];
|
|
128
|
+
defaultValue?: PlasmicElement | PlasmicElement[];
|
|
129
|
+
/**
|
|
130
|
+
* Whether the "empty slot" placeholder should be hidden in the canvas.
|
|
131
|
+
*/
|
|
132
|
+
hidePlaceholder?: boolean;
|
|
133
|
+
};
|
|
134
|
+
declare type ImageUrlType<P> = "imageUrl" | ({
|
|
135
|
+
type: "imageUrl";
|
|
136
|
+
defaultValue?: string;
|
|
137
|
+
defaultValueHint?: string;
|
|
138
|
+
} & PropTypeBase<P>);
|
|
139
|
+
export declare type PrimitiveType<P = any> = Extract<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>, String>;
|
|
140
|
+
declare type ControlTypeBase = {
|
|
141
|
+
editOnly?: false;
|
|
142
|
+
} | {
|
|
143
|
+
editOnly: true;
|
|
144
|
+
/**
|
|
145
|
+
* The prop where the values should be mapped to
|
|
146
|
+
*/
|
|
147
|
+
uncontrolledProp?: string;
|
|
148
|
+
};
|
|
149
|
+
export declare type SupportControlled<T> = Extract<T, String | CustomControl<any>> | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);
|
|
150
|
+
export declare type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | ImageUrlType<P> | CustomType<P>> | SlotType;
|
|
151
|
+
declare type RestrictPropType<T, P> = T extends string ? SupportControlled<StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P> | CustomType<P>> : T extends boolean ? SupportControlled<BooleanType<P> | JSONLikeType<P> | CustomType<P>> : T extends number ? SupportControlled<NumberType<P> | JSONLikeType<P> | CustomType<P>> : PropType<P>;
|
|
152
|
+
declare type DistributedKeyOf<T> = T extends any ? keyof T : never;
|
|
153
|
+
interface ComponentTemplate<P> extends Omit<CodeComponentElement<P>, "type" | "name"> {
|
|
154
|
+
/**
|
|
155
|
+
* A preview picture for the template.
|
|
156
|
+
*/
|
|
157
|
+
previewImg?: string;
|
|
158
|
+
}
|
|
159
|
+
export interface ComponentTemplates<P> {
|
|
160
|
+
[name: string]: ComponentTemplate<P>;
|
|
161
|
+
}
|
|
162
|
+
export interface ComponentMeta<P> {
|
|
163
|
+
/**
|
|
164
|
+
* Any unique string name used to identify that component. Each component
|
|
165
|
+
* should be registered with a different `meta.name`, even if they have the
|
|
166
|
+
* same name in the code.
|
|
167
|
+
*/
|
|
168
|
+
name: string;
|
|
169
|
+
/**
|
|
170
|
+
* The name to be displayed for the component in Studio. Optional: if not
|
|
171
|
+
* specified, `meta.name` is used.
|
|
172
|
+
*/
|
|
173
|
+
displayName?: string;
|
|
174
|
+
/**
|
|
175
|
+
* The description of the component to be shown in Studio.
|
|
176
|
+
*/
|
|
177
|
+
description?: string;
|
|
178
|
+
/**
|
|
179
|
+
* The javascript name to be used when generating code. Optional: if not
|
|
180
|
+
* provided, `meta.name` is used.
|
|
181
|
+
*/
|
|
182
|
+
importName?: string;
|
|
183
|
+
/**
|
|
184
|
+
* An object describing the component properties to be used in Studio.
|
|
185
|
+
* For each `prop`, there should be an entry `meta.props[prop]` describing
|
|
186
|
+
* its type.
|
|
187
|
+
*/
|
|
188
|
+
props: {
|
|
189
|
+
[prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P>;
|
|
190
|
+
} & {
|
|
191
|
+
[prop: string]: PropType<P>;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* The path to be used when importing the component in the generated code.
|
|
195
|
+
* It can be the name of the package that contains the component, or the path
|
|
196
|
+
* to the file in the project (relative to the root directory).
|
|
197
|
+
*/
|
|
198
|
+
importPath: string;
|
|
199
|
+
/**
|
|
200
|
+
* Whether the component is the default export from that path. Optional: if
|
|
201
|
+
* not specified, it's considered `false`.
|
|
202
|
+
*/
|
|
203
|
+
isDefaultExport?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* The prop that expects the CSS classes with styles to be applied to the
|
|
206
|
+
* component. Optional: if not specified, Plasmic will expect it to be
|
|
207
|
+
* `className`. Notice that if the component does not accept CSS classes, the
|
|
208
|
+
* component will not be able to receive styles from the Studio.
|
|
209
|
+
*/
|
|
210
|
+
classNameProp?: string;
|
|
211
|
+
/**
|
|
212
|
+
* The prop that receives and forwards a React `ref`. Plasmic only uses `ref`
|
|
213
|
+
* to interact with components, so it's not used in the generated code.
|
|
214
|
+
* Optional: If not provided, the usual `ref` is used.
|
|
215
|
+
*/
|
|
216
|
+
refProp?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Default styles to start with when instantiating the component in Plasmic.
|
|
219
|
+
*/
|
|
220
|
+
defaultStyles?: CSSProperties;
|
|
221
|
+
/**
|
|
222
|
+
* Component templates to start with on Plasmic.
|
|
223
|
+
*/
|
|
224
|
+
templates?: ComponentTemplates<P>;
|
|
225
|
+
/**
|
|
226
|
+
* Registered name of parent component, used for grouping related components.
|
|
227
|
+
*/
|
|
228
|
+
parentComponentName?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Whether the component can be used as an attachment to an element.
|
|
231
|
+
*/
|
|
232
|
+
isAttachment?: boolean;
|
|
233
|
+
}
|
|
234
|
+
export interface ComponentRegistration {
|
|
235
|
+
component: React.ComponentType<any>;
|
|
236
|
+
meta: ComponentMeta<any>;
|
|
237
|
+
}
|
|
238
|
+
declare global {
|
|
239
|
+
interface Window {
|
|
240
|
+
__PlasmicComponentRegistry: ComponentRegistration[];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
export default function registerComponent<T extends React.ComponentType<any>>(component: T, meta: ComponentMeta<React.ComponentProps<T>>): void;
|
|
244
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { BooleanType, ChoiceType, CustomType, JSONLikeType, NumberType, StringType, SupportControlled } from "./registerComponent";
|
|
3
|
+
export declare type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | CustomType<P>>;
|
|
4
|
+
declare type RestrictPropType<T, P> = T extends string ? SupportControlled<StringType<P> | ChoiceType<P> | JSONLikeType<P> | CustomType<P>> : T extends boolean ? SupportControlled<BooleanType<P> | JSONLikeType<P> | CustomType<P>> : T extends number ? SupportControlled<NumberType<P> | JSONLikeType<P> | CustomType<P>> : PropType<P>;
|
|
5
|
+
declare type DistributedKeyOf<T> = T extends any ? keyof T : never;
|
|
6
|
+
export interface GlobalContextMeta<P> {
|
|
7
|
+
/**
|
|
8
|
+
* Any unique string name used to identify that context. Each context
|
|
9
|
+
* should be registered with a different `meta.name`, even if they have the
|
|
10
|
+
* same name in the code.
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* The name to be displayed for the context in Studio. Optional: if not
|
|
15
|
+
* specified, `meta.name` is used.
|
|
16
|
+
*/
|
|
17
|
+
displayName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The javascript name to be used when generating code. Optional: if not
|
|
20
|
+
* provided, `meta.name` is used.
|
|
21
|
+
*/
|
|
22
|
+
importName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* An object describing the context properties to be used in Studio.
|
|
25
|
+
* For each `prop`, there should be an entry `meta.props[prop]` describing
|
|
26
|
+
* its type.
|
|
27
|
+
*/
|
|
28
|
+
props: {
|
|
29
|
+
[prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P>;
|
|
30
|
+
} & {
|
|
31
|
+
[prop: string]: PropType<P>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* The path to be used when importing the context in the generated code.
|
|
35
|
+
* It can be the name of the package that contains the context, or the path
|
|
36
|
+
* to the file in the project (relative to the root directory).
|
|
37
|
+
*/
|
|
38
|
+
importPath: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the context is the default export from that path. Optional: if
|
|
41
|
+
* not specified, it's considered `false`.
|
|
42
|
+
*/
|
|
43
|
+
isDefaultExport?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The prop that receives and forwards a React `ref`. Plasmic only uses `ref`
|
|
46
|
+
* to interact with components, so it's not used in the generated code.
|
|
47
|
+
* Optional: If not provided, the usual `ref` is used.
|
|
48
|
+
*/
|
|
49
|
+
refProp?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface GlobalContextRegistration {
|
|
52
|
+
component: React.ComponentType<any>;
|
|
53
|
+
meta: GlobalContextMeta<any>;
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
interface Window {
|
|
57
|
+
__PlasmicContextRegistry: GlobalContextRegistration[];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export default function registerGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
|
|
61
|
+
export {};
|