@plasmicapp/host 1.0.136 → 1.0.138

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/exports.d.ts +2 -1
  2. package/dist/fetcher.d.ts +1 -1
  3. package/dist/host.esm.js +1 -1
  4. package/dist/host.esm.js.map +1 -1
  5. package/dist/index.cjs.js +1 -1
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/prop-types.d.ts +387 -0
  8. package/dist/registerComponent.d.ts +2 -368
  9. package/dist/registerGlobalContext.d.ts +4 -3
  10. package/dist/version.d.ts +1 -1
  11. package/package.json +2 -2
  12. package/registerComponent/dist/canvas-host.d.ts +41 -0
  13. package/registerComponent/dist/common.d.ts +1 -0
  14. package/registerComponent/dist/data.d.ts +43 -0
  15. package/registerComponent/dist/exports.d.ts +11 -0
  16. package/registerComponent/dist/fetcher.d.ts +40 -0
  17. package/registerComponent/dist/global-actions.d.ts +9 -0
  18. package/registerComponent/dist/index.cjs.js.map +1 -1
  19. package/registerComponent/dist/index.d.ts +1 -0
  20. package/registerComponent/dist/index.esm.js.map +1 -1
  21. package/registerComponent/dist/lang-utils.d.ts +3 -0
  22. package/registerComponent/dist/prop-types.d.ts +387 -0
  23. package/registerComponent/dist/registerComponent.d.ts +2 -368
  24. package/registerComponent/dist/registerGlobalContext.d.ts +76 -0
  25. package/registerComponent/dist/registerToken.d.ts +13 -0
  26. package/registerComponent/dist/registerTrait.d.ts +20 -0
  27. package/registerComponent/dist/repeatedElement.d.ts +15 -0
  28. package/registerComponent/dist/useForceUpdate.d.ts +1 -0
  29. package/registerComponent/dist/version.d.ts +1 -0
  30. package/registerGlobalContext/dist/canvas-host.d.ts +41 -0
  31. package/registerGlobalContext/dist/common.d.ts +1 -0
  32. package/registerGlobalContext/dist/data.d.ts +43 -0
  33. package/registerGlobalContext/dist/exports.d.ts +11 -0
  34. package/registerGlobalContext/dist/fetcher.d.ts +40 -0
  35. package/registerGlobalContext/dist/global-actions.d.ts +9 -0
  36. package/registerGlobalContext/dist/index.cjs.js.map +1 -1
  37. package/registerGlobalContext/dist/index.d.ts +1 -0
  38. package/registerGlobalContext/dist/index.esm.js.map +1 -1
  39. package/registerGlobalContext/dist/lang-utils.d.ts +3 -0
  40. package/registerGlobalContext/dist/prop-types.d.ts +387 -0
  41. package/registerGlobalContext/dist/registerComponent.d.ts +2 -368
  42. package/registerGlobalContext/dist/registerGlobalContext.d.ts +4 -3
  43. package/registerGlobalContext/dist/registerToken.d.ts +13 -0
  44. package/registerGlobalContext/dist/registerTrait.d.ts +20 -0
  45. package/registerGlobalContext/dist/repeatedElement.d.ts +15 -0
  46. package/registerGlobalContext/dist/useForceUpdate.d.ts +1 -0
  47. package/registerGlobalContext/dist/version.d.ts +1 -0
  48. package/registerToken/dist/canvas-host.d.ts +41 -0
  49. package/registerToken/dist/common.d.ts +1 -0
  50. package/registerToken/dist/data.d.ts +43 -0
  51. package/registerToken/dist/element-types.d.ts +115 -0
  52. package/registerToken/dist/exports.d.ts +11 -0
  53. package/registerToken/dist/fetcher.d.ts +40 -0
  54. package/registerToken/dist/global-actions.d.ts +9 -0
  55. package/registerToken/dist/index.d.ts +1 -0
  56. package/registerToken/dist/lang-utils.d.ts +3 -0
  57. package/registerToken/dist/prop-types.d.ts +387 -0
  58. package/registerToken/dist/registerComponent.d.ts +231 -0
  59. package/registerToken/dist/registerGlobalContext.d.ts +76 -0
  60. package/registerToken/dist/registerTrait.d.ts +20 -0
  61. package/registerToken/dist/repeatedElement.d.ts +15 -0
  62. package/registerToken/dist/useForceUpdate.d.ts +1 -0
  63. package/registerToken/dist/version.d.ts +1 -0
  64. package/registerTrait/dist/canvas-host.d.ts +41 -0
  65. package/registerTrait/dist/common.d.ts +1 -0
  66. package/registerTrait/dist/data.d.ts +43 -0
  67. package/registerTrait/dist/element-types.d.ts +115 -0
  68. package/registerTrait/dist/exports.d.ts +11 -0
  69. package/registerTrait/dist/fetcher.d.ts +40 -0
  70. package/registerTrait/dist/global-actions.d.ts +9 -0
  71. package/registerTrait/dist/index.d.ts +1 -0
  72. package/registerTrait/dist/lang-utils.d.ts +3 -0
  73. package/registerTrait/dist/prop-types.d.ts +387 -0
  74. package/registerTrait/dist/registerComponent.d.ts +231 -0
  75. package/registerTrait/dist/registerGlobalContext.d.ts +76 -0
  76. package/registerTrait/dist/registerToken.d.ts +13 -0
  77. package/registerTrait/dist/repeatedElement.d.ts +15 -0
  78. package/registerTrait/dist/useForceUpdate.d.ts +1 -0
  79. package/registerTrait/dist/version.d.ts +1 -0
@@ -0,0 +1,76 @@
1
+ /// <reference types="react" />
2
+ import { BooleanType, ChoiceType, CustomType, JSONLikeType, NumberType, StringType, DataSourceType } from "./prop-types";
3
+ import { FunctionParam } from "./registerComponent";
4
+ export type PropType<P> = StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | CustomType<P> | DataSourceType<P>;
5
+ type RestrictPropType<T, P> = T extends string ? StringType<P> | ChoiceType<P> | JSONLikeType<P> | CustomType<P> : T extends boolean ? BooleanType<P> | JSONLikeType<P> | CustomType<P> : T extends number ? NumberType<P> | JSONLikeType<P> | CustomType<P> : PropType<P>;
6
+ type DistributedKeyOf<T> = T extends any ? keyof T : never;
7
+ export interface GlobalContextMeta<P> {
8
+ /**
9
+ * Any unique string name used to identify that context. Each context
10
+ * should be registered with a different `meta.name`, even if they have the
11
+ * same name in the code.
12
+ */
13
+ name: string;
14
+ /**
15
+ * The name to be displayed for the context in Studio. Optional: if not
16
+ * specified, `meta.name` is used.
17
+ */
18
+ displayName?: string;
19
+ /**
20
+ * The description of the context to be shown in Studio.
21
+ */
22
+ description?: string;
23
+ /**
24
+ * The javascript name to be used when generating code. Optional: if not
25
+ * provided, `meta.name` is used.
26
+ */
27
+ importName?: string;
28
+ /**
29
+ * An object describing the context properties to be used in Studio.
30
+ * For each `prop`, there should be an entry `meta.props[prop]` describing
31
+ * its type.
32
+ */
33
+ props: {
34
+ [prop in DistributedKeyOf<P>]?: RestrictPropType<P[prop], P>;
35
+ } & {
36
+ [prop: string]: PropType<P>;
37
+ };
38
+ /**
39
+ * The path to be used when importing the context in the generated code.
40
+ * It can be the name of the package that contains the context, or the path
41
+ * to the file in the project (relative to the root directory).
42
+ */
43
+ importPath: string;
44
+ /**
45
+ * Whether the context is the default export from that path. Optional: if
46
+ * not specified, it's considered `false`.
47
+ */
48
+ isDefaultExport?: boolean;
49
+ /**
50
+ * The prop that receives and forwards a React `ref`. Plasmic only uses `ref`
51
+ * to interact with components, so it's not used in the generated code.
52
+ * Optional: If not provided, the usual `ref` is used.
53
+ */
54
+ refProp?: string;
55
+ /**
56
+ * Whether the global context provides data to its children using DataProvider.
57
+ */
58
+ providesData?: boolean;
59
+ unstable__globalActions?: Record<string, GlobalActionRegistration<P>>;
60
+ }
61
+ export interface GlobalContextRegistration {
62
+ component: React.ComponentType<any>;
63
+ meta: GlobalContextMeta<any>;
64
+ }
65
+ export interface GlobalActionRegistration<P> {
66
+ displayName?: string;
67
+ description?: string;
68
+ parameters: FunctionParam<P>[];
69
+ }
70
+ declare global {
71
+ interface Window {
72
+ __PlasmicContextRegistry: GlobalContextRegistration[];
73
+ }
74
+ }
75
+ export default function registerGlobalContext<T extends React.ComponentType<any>>(component: T, meta: GlobalContextMeta<React.ComponentProps<T>>): void;
76
+ export {};
@@ -0,0 +1,20 @@
1
+ export interface BasicTrait {
2
+ label?: string;
3
+ type: "text" | "number" | "boolean";
4
+ }
5
+ export interface ChoiceTrait {
6
+ label?: string;
7
+ type: "choice";
8
+ options: string[];
9
+ }
10
+ export type TraitMeta = BasicTrait | ChoiceTrait;
11
+ export interface TraitRegistration {
12
+ trait: string;
13
+ meta: TraitMeta;
14
+ }
15
+ declare global {
16
+ interface Window {
17
+ __PlasmicTraitRegistry: TraitRegistration[];
18
+ }
19
+ }
20
+ export default function registerTrait(trait: string, meta: TraitMeta): void;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Allows elements to be repeated in Plasmic Studio.
3
+ * @param index The index of the copy (starting at 0).
4
+ * @param elt the React element to be repeated (or an array of such).
5
+ */
6
+ export default function repeatedElement<T>(index: number, elt: T): T;
7
+ /**
8
+ * Allows elements to be repeated in Plasmic Studio.
9
+ * @param isPrimary should be true for at most one instance of the element, and
10
+ * indicates which copy of the element will be highlighted when the element is
11
+ * selected in Studio.
12
+ * @param elt the React element to be repeated (or an array of such).
13
+ */
14
+ export default function repeatedElement<T>(isPrimary: boolean, elt: T): T;
15
+ export declare const setRepeatedElementFn: (fn: typeof repeatedElement) => void;
@@ -0,0 +1 @@
1
+ export default function useForceUpdate(): () => void;
@@ -0,0 +1 @@
1
+ export declare const hostVersion = "1.0.138";
@@ -0,0 +1,41 @@
1
+ import * as React from "react";
2
+ declare global {
3
+ interface Window {
4
+ __PlasmicHostVersion: string;
5
+ }
6
+ }
7
+ export declare function setPlasmicRootNode(node: React.ReactElement | null): void;
8
+ export interface PlasmicCanvasContextValue {
9
+ componentName: string | null;
10
+ globalVariants: Record<string, string>;
11
+ interactive?: boolean;
12
+ }
13
+ /**
14
+ * React context to detect whether the component is rendered on Plasmic editor.
15
+ * If not, return false.
16
+ * If so, return an object with more information about the component
17
+ */
18
+ export declare const PlasmicCanvasContext: React.Context<false | PlasmicCanvasContextValue>;
19
+ export declare const usePlasmicCanvasContext: () => false | PlasmicCanvasContextValue;
20
+ interface PlasmicCanvasHostProps {
21
+ /**
22
+ * Webpack hmr uses EventSource to listen to hot reloads, but that
23
+ * resultsin a persistent connection from each window. In Plasmic
24
+ * Studio, if a project is configured to use app-hosting with a
25
+ * nextjs or gatsby server running in dev mode, each artboard will
26
+ * be holding a persistent connection to the dev server.
27
+ * Because browsers have a limit to how many connections can
28
+ * be held at a time by domain, this means after X artboards, new
29
+ * artboards will freeze and not load.
30
+ *
31
+ * By default, <PlasmicCanvasHost /> will globally mutate
32
+ * window.EventSource to avoid using EventSource for HMR, which you
33
+ * typically don't need for your custom host page. If you do still
34
+ * want to retain HRM, then youc an pass enableWebpackHmr={true}.
35
+ */
36
+ enableWebpackHmr?: boolean;
37
+ }
38
+ export declare const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps>;
39
+ type RenderErrorListener = (err: Error) => void;
40
+ export declare function registerRenderErrorListener(listener: RenderErrorListener): () => void;
41
+ export {};
@@ -0,0 +1 @@
1
+ export declare const tuple: <T extends any[]>(...args: T) => T;
@@ -0,0 +1,43 @@
1
+ import React, { ReactNode } from "react";
2
+ export type DataDict = Record<string, any>;
3
+ export declare const DataContext: React.Context<DataDict | undefined>;
4
+ export type DataMeta = {
5
+ hidden?: boolean;
6
+ label?: string;
7
+ };
8
+ export declare function mkMetaName(name: string): string;
9
+ export declare function mkMetaValue(meta: Partial<DataMeta>): DataMeta;
10
+ export declare function applySelector(rawData: DataDict | undefined, selector: string | undefined): any;
11
+ export type SelectorDict = Record<string, string | undefined>;
12
+ export declare function useSelector(selector: string | undefined): any;
13
+ export declare function useSelectors(selectors?: SelectorDict): any;
14
+ export declare function useDataEnv(): DataDict | undefined;
15
+ export interface DataProviderProps {
16
+ /**
17
+ * Key to set in data context.
18
+ */
19
+ name?: string;
20
+ /**
21
+ * Value to set for `name` in data context.
22
+ */
23
+ data?: any;
24
+ /**
25
+ * If true, hide this entry in studio (data binding).
26
+ */
27
+ hidden?: boolean;
28
+ /**
29
+ * Label to be shown in the studio data picker for easier navigation (data binding).
30
+ */
31
+ label?: string;
32
+ children?: ReactNode;
33
+ }
34
+ export declare function DataProvider({ name, data, hidden, label, children, }: DataProviderProps): JSX.Element;
35
+ export interface PageParamsProviderProps {
36
+ params?: Record<string, string | string[] | undefined>;
37
+ query?: Record<string, string | string[] | undefined>;
38
+ children?: ReactNode;
39
+ }
40
+ export declare function PageParamsProvider({ children, params, query, }: PageParamsProviderProps): JSX.Element;
41
+ export declare function DataCtxReader({ children, }: {
42
+ children: ($ctx: DataDict | undefined) => ReactNode;
43
+ }): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
@@ -0,0 +1,115 @@
1
+ import type { Properties } from "csstype";
2
+ export type CSSProperties = Properties<string | number> & {
3
+ layout?: "vbox" | "hbox" | "box" | "page-section";
4
+ };
5
+ 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";
6
+ type CommonAttrKeys = "title" | "tabIndex" | "className" | "id" | "aria-label" | "aria-hidden" | "aria-labelledby" | "aria-describedby" | "role";
7
+ type PictureAttrKeys = "alt" | "loading" | CommonAttrKeys;
8
+ type LinkAttrKeys = "href" | "target" | CommonAttrKeys;
9
+ type TextAreaAttrKeys = "disabled" | "value" | "cols" | "rows" | "placeholder" | CommonAttrKeys;
10
+ type InputAttrKeys = "disabled" | "value" | "defaultValue" | "name" | "autoComplete" | "checked" | "placeholder" | CommonAttrKeys;
11
+ type ButtonAttrKeys = "disabled" | CommonAttrKeys;
12
+ type Attrs<Keys extends string> = Partial<Record<Keys, string>>;
13
+ export interface PictureElement {
14
+ type: "img";
15
+ src: string;
16
+ styles?: CSSProperties;
17
+ attrs?: Attrs<PictureAttrKeys>;
18
+ }
19
+ export type ImageElement = PictureElement;
20
+ interface LinkTextElement {
21
+ type: "text";
22
+ tag: "a";
23
+ value: string;
24
+ styles?: CSSProperties;
25
+ attrs?: Attrs<LinkAttrKeys>;
26
+ }
27
+ interface ButtonTextElement {
28
+ type: "text";
29
+ tag: "button";
30
+ value: string;
31
+ styles?: CSSProperties;
32
+ attrs?: Attrs<ButtonAttrKeys>;
33
+ }
34
+ interface GenericTextElement {
35
+ type: "text";
36
+ /**
37
+ * Default: "div"
38
+ */
39
+ tag?: Exclude<ContainerTags, "a" | "button">;
40
+ value: string;
41
+ styles?: CSSProperties;
42
+ attrs?: Attrs<CommonAttrKeys>;
43
+ }
44
+ export type TextElement = string | LinkTextElement | ButtonTextElement | GenericTextElement;
45
+ interface LinkContainerElement {
46
+ type: "box" | "vbox" | "hbox";
47
+ tag: "a";
48
+ children?: PlasmicElement | PlasmicElement[];
49
+ styles?: CSSProperties;
50
+ attrs?: Attrs<LinkAttrKeys>;
51
+ }
52
+ interface ButtonContainerElement {
53
+ type: "box" | "vbox" | "hbox";
54
+ tag: "button";
55
+ children?: PlasmicElement | PlasmicElement[];
56
+ styles?: CSSProperties;
57
+ attrs?: Attrs<ButtonAttrKeys>;
58
+ }
59
+ interface GenericContainerElement {
60
+ type: "box" | "vbox" | "hbox" | "page-section";
61
+ /**
62
+ * Default: "div"
63
+ */
64
+ tag?: Exclude<ContainerTags, "a" | "button">;
65
+ children?: PlasmicElement | PlasmicElement[];
66
+ styles?: CSSProperties;
67
+ attrs?: Attrs<CommonAttrKeys>;
68
+ }
69
+ export type ContainerElement = LinkContainerElement | ButtonContainerElement | GenericContainerElement;
70
+ export interface ButtonElement {
71
+ type: "button";
72
+ value: string;
73
+ styles?: CSSProperties;
74
+ attrs?: Attrs<ButtonAttrKeys>;
75
+ }
76
+ interface InputElement {
77
+ type: "input" | "password";
78
+ styles?: CSSProperties;
79
+ attrs?: Attrs<InputAttrKeys>;
80
+ }
81
+ interface TextAreaElement {
82
+ type: "textarea";
83
+ styles?: CSSProperties;
84
+ attrs?: Attrs<TextAreaAttrKeys>;
85
+ }
86
+ export type TextInputElement = InputElement | TextAreaElement;
87
+ interface JsonElement {
88
+ type: "json";
89
+ value: any;
90
+ }
91
+ export interface DefaultComponentElement<P> {
92
+ type: "default-component";
93
+ kind: "button" | "text-input";
94
+ props?: {
95
+ [prop in keyof Partial<P>]: number | string | boolean | null | undefined | JsonElement | PlasmicElement | PlasmicElement[];
96
+ } & {
97
+ [prop: string]: number | string | boolean | null | undefined | JsonElement | PlasmicElement | PlasmicElement[];
98
+ };
99
+ styles?: CSSProperties;
100
+ }
101
+ export interface CodeComponentElement<P> {
102
+ type: "component";
103
+ /**
104
+ * The registered component name
105
+ */
106
+ name: string;
107
+ styles?: CSSProperties;
108
+ props?: {
109
+ [prop in keyof Partial<P>]: number | string | boolean | null | undefined | JsonElement | PlasmicElement | PlasmicElement[];
110
+ } & {
111
+ [prop: string]: number | string | boolean | null | undefined | JsonElement | PlasmicElement | PlasmicElement[];
112
+ };
113
+ }
114
+ export type PlasmicElement = ImageElement | TextElement | ContainerElement | ButtonElement | TextInputElement | CodeComponentElement<{}> | DefaultComponentElement<{}>;
115
+ export {};
@@ -0,0 +1,11 @@
1
+ export { PlasmicCanvasContext, PlasmicCanvasHost, usePlasmicCanvasContext, } from "./canvas-host";
2
+ export * from "./data";
3
+ export { PlasmicElement } from "./element-types";
4
+ export { registerFetcher as unstable_registerFetcher } from "./fetcher";
5
+ export * from "./global-actions";
6
+ export { Action, ActionProps, CodeComponentMeta, ComponentHelpers, ComponentMeta, ComponentRegistration, ComponentTemplates, default as registerComponent, StateHelpers, StateSpec, CodeComponentMode, } from "./registerComponent";
7
+ export { PropType, ContextDependentConfig } from "./prop-types";
8
+ export { default as registerGlobalContext, GlobalContextMeta, GlobalContextRegistration, PropType as GlobalContextPropType, } from "./registerGlobalContext";
9
+ export { default as registerToken, TokenRegistration, TokenType, } from "./registerToken";
10
+ export { BasicTrait, ChoiceTrait, default as registerTrait, TraitMeta, TraitRegistration, } from "./registerTrait";
11
+ export { default as repeatedElement } from "./repeatedElement";
@@ -0,0 +1,40 @@
1
+ import { PrimitiveType } from "./prop-types";
2
+ export type Fetcher = (...args: any[]) => Promise<any>;
3
+ export interface FetcherMeta {
4
+ /**
5
+ * Any unique identifying string for this fetcher.
6
+ */
7
+ name: string;
8
+ /**
9
+ * The Studio-user-friendly display name.
10
+ */
11
+ displayName?: string;
12
+ /**
13
+ * The symbol to import from the importPath.
14
+ */
15
+ importName?: string;
16
+ args: {
17
+ name: string;
18
+ type: PrimitiveType;
19
+ }[];
20
+ returns: PrimitiveType;
21
+ /**
22
+ * Either the path to the fetcher relative to `rootDir` or the npm
23
+ * package name
24
+ */
25
+ importPath: string;
26
+ /**
27
+ * Whether it's a default export or named export
28
+ */
29
+ isDefaultExport?: boolean;
30
+ }
31
+ export interface FetcherRegistration {
32
+ fetcher: Fetcher;
33
+ meta: FetcherMeta;
34
+ }
35
+ declare global {
36
+ interface Window {
37
+ __PlasmicFetcherRegistry: FetcherRegistration[];
38
+ }
39
+ }
40
+ export declare function registerFetcher(fetcher: Fetcher, meta: FetcherMeta): void;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ export type GlobalActionDict = Record<string, Function>;
3
+ export declare const GlobalActionsContext: React.Context<GlobalActionDict | undefined>;
4
+ export declare function GlobalActionsProvider(props: {
5
+ contextName: string;
6
+ children?: React.ReactNode;
7
+ actions: GlobalActionDict;
8
+ }): JSX.Element;
9
+ export declare function useGlobalActions(): GlobalActionDict;
@@ -0,0 +1 @@
1
+ export * from "./exports";
@@ -0,0 +1,3 @@
1
+ type StringGen = string | (() => string);
2
+ export declare function ensure<T>(x: T | null | undefined, msg?: StringGen): T;
3
+ export {};