@plasmicapp/host 0.0.40 → 0.0.41
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/host.cjs.development.js.map +1 -1
- package/dist/host.cjs.production.min.js.map +1 -1
- package/dist/host.esm.js.map +1 -1
- package/dist/registerComponent.d.ts +73 -11
- package/package.json +2 -2
- package/registerComponent/dist/index.cjs.js.map +1 -1
- package/registerComponent/dist/index.esm.js.map +1 -1
- package/registerComponent/dist/registerComponent.d.ts +73 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.cjs.development.js","sources":["../src/data.ts","../src/lang-utils.ts","../src/registerComponent.ts","../src/repeatedElement.ts","../src/useForceUpdate.ts","../src/index.tsx"],"sourcesContent":["import { PrimitiveType } from \"./index\";\nconst root = globalThis as any;\n\nexport type Fetcher = (...args: any[]) => Promise<any>;\n\nexport interface FetcherMeta {\n /**\n * Any unique identifying string for this fetcher.\n */\n name: string;\n /**\n * The Studio-user-friendly display name.\n */\n displayName?: string;\n /**\n * The symbol to import from the importPath.\n */\n importName?: string;\n args: { name: string; type: PrimitiveType }[];\n returns: PrimitiveType;\n /**\n * Either the path to the fetcher relative to `rootDir` or the npm\n * package name\n */\n importPath: string;\n /**\n * Whether it's a default export or named export\n */\n isDefaultExport?: boolean;\n}\n\nexport interface FetcherRegistration {\n fetcher: Fetcher;\n meta: FetcherMeta;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFetcherRegistry: FetcherRegistration[];\n }\n}\n\nroot.__PlasmicFetcherRegistry = [];\n\nexport function registerFetcher(fetcher: Fetcher, meta: FetcherMeta) {\n root.__PlasmicFetcherRegistry.push({ fetcher, meta });\n}\n","function isString(x: any): x is string {\n return typeof x === \"string\";\n}\n\ntype StringGen = string | (() => string);\n\nexport function ensure<T>(x: T | null | undefined, msg: StringGen = \"\"): T {\n if (x === null || x === undefined) {\n debugger;\n msg = (isString(msg) ? msg : msg()) || \"\";\n throw new Error(\n `Value must not be undefined or null${msg ? `- ${msg}` : \"\"}`\n );\n } else {\n return x;\n }\n}\n","import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\ntype PropTypeBase<P> = {\n displayName?: string;\n description?: string;\n hidden?: (props: P) => boolean;\n};\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ntype NumberType<P> =\n | \"number\"\n | ({\n type: \"number\";\n defaultValue?: number;\n } & PropTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype ChoiceType<P> = {\n type: \"choice\";\n options: string[] | ((props: P) => string[]);\n defaultValue?: string;\n} & PropTypeBase<P>;\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String>\n | (Exclude<T, String> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P>\n >\n : T extends boolean\n ? SupportControlled<BooleanType<P> | JSONLikeType<P>>\n : T extends number\n ? SupportControlled<NumberType<P> | JSONLikeType<P>>\n : PropType<P>;\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n","import { cloneElement, isValidElement } from \"react\";\n\n/**\n * Allows a component from Plasmic Studio to be repeated.\n * `isPrimary` should be true for at most one instance of the component, and\n * indicates which copy of the element will be highlighted when the element is\n * selected in Studio.\n * If `isPrimary` is `false`, and `elt` is a React element (or an array of such),\n * it'll be cloned (using React.cloneElement) and ajusted if it's a component\n * from Plasmic Studio. Otherwise, if `elt` is not a React element, the original\n * value is returned.\n */\nexport default function repeatedElement<T,>(isPrimary: boolean, elt: T): T {\n return repeatedElementFn(isPrimary, elt);\n}\n\nlet repeatedElementFn = <T,>(isPrimary: boolean, elt: T): T => {\n if (isPrimary) {\n return elt;\n }\n if (Array.isArray(elt)) {\n return elt.map((v) => repeatedElement(isPrimary, v)) as any as T;\n }\n if (elt && isValidElement(elt) && typeof elt !== \"string\") {\n return cloneElement(elt) as any as T;\n }\n return elt;\n}\n\nexport function setRepeatedElementFn(fn: typeof repeatedElement) {\n repeatedElementFn = fn;\n}\n\n\n","import { useCallback, useState } from \"react\";\n\nexport default function useForceUpdate() {\n const [, setTick] = useState(0);\n const update = useCallback(() => {\n setTick((tick) => tick + 1);\n }, []);\n return update;\n}\n","// tslint:disable:ordered-imports\n// organize-imports-ignore\nimport \"@plasmicapp/preamble\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { registerFetcher as unstable_registerFetcher } from \"./data\";\nimport { PlasmicElement } from \"./element-types\";\nimport { ensure } from \"./lang-utils\";\nimport registerComponent, {\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n} from \"./registerComponent\";\nimport repeatedElement, { setRepeatedElementFn } from \"./repeatedElement\";\nimport useForceUpdate from \"./useForceUpdate\";\nconst root = globalThis as any;\n\nexport { unstable_registerFetcher };\nexport { repeatedElement };\nexport {\n registerComponent,\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n};\nexport { PlasmicElement };\n\ndeclare global {\n interface Window {\n __PlasmicHostVersion: string;\n }\n}\n\nif (root.__PlasmicHostVersion == null) {\n root.__PlasmicHostVersion = \"1\";\n}\n\nconst rootChangeListeners: (() => void)[] = [];\nclass PlasmicRootNodeWrapper {\n constructor(private value: null | React.ReactElement) {}\n set = (val: null | React.ReactElement) => {\n this.value = val;\n rootChangeListeners.forEach((f) => f());\n };\n get = () => this.value;\n}\n\nconst plasmicRootNode = new PlasmicRootNodeWrapper(null);\n\nif (root.__Sub == null) {\n // Creating a side effect here by logging, so that vite won't\n // ignore this block for whatever reason\n console.log(\"Plasmic: Setting up app host dependencies\");\n root.__Sub = {\n React,\n ReactDOM,\n setPlasmicRootNode,\n registerRenderErrorListener,\n repeatedElement,\n setRepeatedElementFn,\n };\n}\n\nfunction getPlasmicOrigin() {\n const params = new URL(`https://fakeurl/${location.hash.replace(/#/, \"?\")}`)\n .searchParams;\n return ensure(\n params.get(\"origin\"),\n \"Missing information from Plasmic window.\"\n );\n}\n\nfunction renderStudioIntoIframe() {\n const script = document.createElement(\"script\");\n const plasmicOrigin = getPlasmicOrigin();\n script.src = plasmicOrigin + \"/static/js/studio.js\";\n document.body.appendChild(script);\n}\n\nlet renderCount = 0;\nfunction setPlasmicRootNode(node: React.ReactElement | null) {\n // Keep track of renderCount, which we use as key to ErrorBoundary, so\n // we can reset the error on each render\n renderCount++;\n plasmicRootNode.set(node);\n}\n\n/**\n * React context to detect whether the component is rendered on Plasmic editor.\n */\nexport const PlasmicCanvasContext = React.createContext<boolean>(false);\n\nfunction _PlasmicCanvasHost() {\n // If window.parent is null, then this is a window whose containing iframe\n // has been detached from the DOM (for the top window, window.parent === window).\n // In that case, we shouldn't do anything. If window.parent is null, by the way,\n // location.hash will also be null.\n const isFrameAttached = !!window.parent;\n const isCanvas = !!location.hash?.match(/\\bcanvas=true\\b/);\n const isLive = !!location.hash?.match(/\\blive=true\\b/) || !isFrameAttached;\n const shouldRenderStudio =\n isFrameAttached &&\n !document.querySelector(\"#plasmic-studio-tag\") &&\n !isCanvas &&\n !isLive;\n const forceUpdate = useForceUpdate();\n React.useLayoutEffect(() => {\n rootChangeListeners.push(forceUpdate);\n return () => {\n const index = rootChangeListeners.indexOf(forceUpdate);\n if (index >= 0) {\n rootChangeListeners.splice(index, 1);\n }\n };\n }, [forceUpdate]);\n React.useEffect(() => {\n if (shouldRenderStudio && isFrameAttached && window.parent !== window) {\n renderStudioIntoIframe();\n }\n }, [shouldRenderStudio, isFrameAttached]);\n React.useEffect(() => {\n if (!shouldRenderStudio && !document.querySelector(\"#getlibs\") && isLive) {\n const scriptElt = document.createElement(\"script\");\n scriptElt.id = \"getlibs\";\n scriptElt.src = getPlasmicOrigin() + \"/static/js/getlibs.js\";\n scriptElt.async = false;\n scriptElt.onload = () => {\n (window as any).__GetlibsReadyResolver?.();\n };\n document.head.append(scriptElt);\n }\n }, [shouldRenderStudio]);\n if (!isFrameAttached) {\n return null;\n }\n if (isCanvas || isLive) {\n let appDiv = document.querySelector(\"#plasmic-app.__wab_user-body\");\n if (!appDiv) {\n appDiv = document.createElement(\"div\");\n appDiv.id = \"plasmic-app\";\n appDiv.classList.add(\"__wab_user-body\");\n document.body.appendChild(appDiv);\n }\n return ReactDOM.createPortal(\n <ErrorBoundary key={`${renderCount}`}>\n <PlasmicCanvasContext.Provider value={isCanvas}>\n {plasmicRootNode.get()}\n </PlasmicCanvasContext.Provider>\n </ErrorBoundary>,\n appDiv,\n \"plasmic-app\"\n );\n }\n if (shouldRenderStudio && window.parent === window) {\n return (\n <p>\n Your app is ready to host Plasmic Studio! <br /> <br />\n On the <a href=\"https://studio.plasmic.app/\">Dashboard</a>, click on the{\" \"}\n <i>Config</i> button, and set{\" \"}\n <code>{location.origin + location.pathname}</code> as the host URL.\n <br />\n <br />\n You can find more information about app-hosting{\" \"}\n <a href=\"https://www.plasmic.app/learn/app-hosting/\">here</a>.\n </p>\n );\n }\n return null;\n}\n\ninterface PlasmicCanvasHostProps {\n /**\n * Webpack hmr uses EventSource to\tlisten to hot reloads, but that\n * resultsin a persistent\tconnection from\teach window. In Plasmic\n * Studio, if a project is configured to use app-hosting with a\n * nextjs or gatsby server running in dev mode, each artboard will\n * be holding a persistent connection to the dev server.\n * Because browsers\thave a limit to\thow many connections can\n * be held\tat a time by domain, this means\tafter X\tartboards, new\n * artboards will freeze and not load.\n *\n * By default, <PlasmicCanvasHost /> will globally mutate\n * window.EventSource to avoid using EventSource for HMR, which you\n * typically don't need for your custom host page. If you do still\n * want to retain HRM, then youc an pass enableWebpackHmr={true}.\n */\n enableWebpackHmr?: boolean;\n}\n\nexport const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps> = (\n props\n) => {\n const { enableWebpackHmr } = props;\n const [node, setNode] = React.useState<React.ReactElement<any, any> | null>(\n null\n );\n React.useEffect(() => {\n setNode(<_PlasmicCanvasHost />);\n }, []);\n return (\n <>\n {!enableWebpackHmr && <DisableWebpackHmr />}\n {node}\n </>\n );\n};\n\ntype RenderErrorListener = (err: Error) => void;\nconst renderErrorListeners: RenderErrorListener[] = [];\nfunction registerRenderErrorListener(listener: RenderErrorListener) {\n renderErrorListeners.push(listener);\n return () => {\n const index = renderErrorListeners.indexOf(listener);\n if (index >= 0) {\n renderErrorListeners.splice(index, 1);\n }\n };\n}\n\ninterface ErrorBoundaryProps {\n children?: React.ReactNode;\n}\n\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\nclass ErrorBoundary extends React.Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n renderErrorListeners.forEach((listener) => listener(error));\n }\n\n render() {\n if (this.state.error) {\n return <div>Error: {`${this.state.error.message}`}</div>;\n } else {\n return this.props.children;\n }\n }\n}\n\nfunction DisableWebpackHmr() {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n return (\n <script\n type=\"text/javascript\"\n dangerouslySetInnerHTML={{\n __html: `\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n `,\n }}\n ></script>\n );\n}\n"],"names":["root","globalThis","__PlasmicFetcherRegistry","registerFetcher","fetcher","meta","push","isString","x","ensure","msg","undefined","Error","__PlasmicComponentRegistry","registerComponent","component","repeatedElement","isPrimary","elt","repeatedElementFn","Array","isArray","map","v","isValidElement","cloneElement","setRepeatedElementFn","fn","useForceUpdate","useState","setTick","update","useCallback","tick","__PlasmicHostVersion","rootChangeListeners","PlasmicRootNodeWrapper","value","val","forEach","f","plasmicRootNode","__Sub","console","log","React","ReactDOM","setPlasmicRootNode","registerRenderErrorListener","getPlasmicOrigin","params","URL","location","hash","replace","searchParams","get","renderStudioIntoIframe","script","document","createElement","plasmicOrigin","src","body","appendChild","renderCount","node","set","PlasmicCanvasContext","_PlasmicCanvasHost","isFrameAttached","window","parent","isCanvas","match","isLive","shouldRenderStudio","querySelector","forceUpdate","index","indexOf","splice","scriptElt","id","async","onload","__GetlibsReadyResolver","head","append","appDiv","classList","add","ErrorBoundary","key","Provider","href","origin","pathname","PlasmicCanvasHost","props","enableWebpackHmr","setNode","DisableWebpackHmr","renderErrorListeners","listener","state","getDerivedStateFromError","error","componentDidCatch","render","message","children","type","dangerouslySetInnerHTML","__html"],"mappings":";;;;;;;;;;;;;;;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oBAAA,2BAAkBD,KAAlB;AACEJ,IAAAA,oBAAoB,CAAChE,OAArB,CAA6B,UAACiE,QAAD;AAAA,aAAcA,QAAQ,CAACG,KAAD,CAAtB;AAAA,KAA7B;AACD;;SAEDE,SAAA;AACE,QAAI,KAAKJ,KAAL,CAAWE,KAAf,EAAsB;AACpB,aAAO9D,mBAAA,MAAA,MAAA,WAAA,OAAgB,KAAK4D,KAAL,CAAWE,KAAX,CAAiBG,OAAjC,CAAP;AACD,KAFD,MAEO;AACL,aAAO,KAAKX,KAAL,CAAWY,QAAlB;AACD;AACF;;;EAvByBlE;;AA0B5B,SAASyD,iBAAT;AACE;AAGA,SACEzD,mBAAA,SAAA;AACEmE,IAAAA,IAAI,EAAC;AACLC,IAAAA,uBAAuB,EAAE;AACvBC,MAAAA,MAAM;AADiB;GAF3B,CADF;AAsBD;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"host.cjs.development.js","sources":["../src/data.ts","../src/lang-utils.ts","../src/registerComponent.ts","../src/repeatedElement.ts","../src/useForceUpdate.ts","../src/index.tsx"],"sourcesContent":["import { PrimitiveType } from \"./index\";\nconst root = globalThis as any;\n\nexport type Fetcher = (...args: any[]) => Promise<any>;\n\nexport interface FetcherMeta {\n /**\n * Any unique identifying string for this fetcher.\n */\n name: string;\n /**\n * The Studio-user-friendly display name.\n */\n displayName?: string;\n /**\n * The symbol to import from the importPath.\n */\n importName?: string;\n args: { name: string; type: PrimitiveType }[];\n returns: PrimitiveType;\n /**\n * Either the path to the fetcher relative to `rootDir` or the npm\n * package name\n */\n importPath: string;\n /**\n * Whether it's a default export or named export\n */\n isDefaultExport?: boolean;\n}\n\nexport interface FetcherRegistration {\n fetcher: Fetcher;\n meta: FetcherMeta;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFetcherRegistry: FetcherRegistration[];\n }\n}\n\nroot.__PlasmicFetcherRegistry = [];\n\nexport function registerFetcher(fetcher: Fetcher, meta: FetcherMeta) {\n root.__PlasmicFetcherRegistry.push({ fetcher, meta });\n}\n","function isString(x: any): x is string {\n return typeof x === \"string\";\n}\n\ntype StringGen = string | (() => string);\n\nexport function ensure<T>(x: T | null | undefined, msg: StringGen = \"\"): T {\n if (x === null || x === undefined) {\n debugger;\n msg = (isString(msg) ? msg : msg()) || \"\";\n throw new Error(\n `Value must not be undefined or null${msg ? `- ${msg}` : \"\"}`\n );\n } else {\n return x;\n }\n}\n","import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\nexport interface CanvasComponentProps<Data = any> {\n /**\n * This prop is only provided within the canvas of Plasmic Studio.\n * Allows the component to set data to be consumed by the props' controls.\n */\n setControlContextData?: (data: Data) => void;\n}\n\ntype InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;\n\n/**\n * Config option that takes the context (e.g., props) of the component instance\n * to dynamically set its value.\n */\ntype ContextDependentConfig<P, R> = (\n props: 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) => R;\n\ninterface PropTypeBase<P> {\n displayName?: string;\n description?: string;\n hidden?: ContextDependentConfig<P, boolean>;\n}\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ninterface NumberTypeBase<P> extends PropTypeBase<P> {\n type: \"number\";\n defaultValue?: number;\n}\n\ntype NumberType<P> =\n | \"number\"\n | ((\n | {\n control?: \"default\";\n min?: number | ContextDependentConfig<P, number>;\n max?: number | ContextDependentConfig<P, number>;\n }\n | {\n control: \"slider\";\n min: number | ContextDependentConfig<P, number>;\n max: number | ContextDependentConfig<P, number>;\n step?: number | ContextDependentConfig<P, number>;\n }\n ) &\n NumberTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ninterface ChoiceTypeBase<P> extends PropTypeBase<P> {\n type: \"choice\";\n options: string[] | ContextDependentConfig<P, string[]>;\n}\n\ntype ChoiceType<P> = (\n | {\n defaultValue?: string;\n multiSelect?: false;\n }\n | {\n defaultValue?: string[];\n multiSelect: true;\n }\n) &\n ChoiceTypeBase<P>;\n\ninterface CustomControlProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n value: any;\n /**\n * Sets the value to be passed to the prop. Expects a JSON-compatible value.\n */\n updateValue: (newVal: any) => void;\n}\nexport type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;\n\nexport type CustomType<P> =\n | CustomControl<P>\n | ({\n type: \"custom\";\n control: CustomControl<P>;\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n /**\n * Whether the \"empty slot\" placeholder should be hidden in the canvas.\n */\n hidePlaceholder?: boolean;\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String | CustomControl<any>>\n | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n | StringType<P>\n | ChoiceType<P>\n | JSONLikeType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\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\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n","import { cloneElement, isValidElement } from \"react\";\n\n/**\n * Allows a component from Plasmic Studio to be repeated.\n * `isPrimary` should be true for at most one instance of the component, and\n * indicates which copy of the element will be highlighted when the element is\n * selected in Studio.\n * If `isPrimary` is `false`, and `elt` is a React element (or an array of such),\n * it'll be cloned (using React.cloneElement) and ajusted if it's a component\n * from Plasmic Studio. Otherwise, if `elt` is not a React element, the original\n * value is returned.\n */\nexport default function repeatedElement<T,>(isPrimary: boolean, elt: T): T {\n return repeatedElementFn(isPrimary, elt);\n}\n\nlet repeatedElementFn = <T,>(isPrimary: boolean, elt: T): T => {\n if (isPrimary) {\n return elt;\n }\n if (Array.isArray(elt)) {\n return elt.map((v) => repeatedElement(isPrimary, v)) as any as T;\n }\n if (elt && isValidElement(elt) && typeof elt !== \"string\") {\n return cloneElement(elt) as any as T;\n }\n return elt;\n}\n\nexport function setRepeatedElementFn(fn: typeof repeatedElement) {\n repeatedElementFn = fn;\n}\n\n\n","import { useCallback, useState } from \"react\";\n\nexport default function useForceUpdate() {\n const [, setTick] = useState(0);\n const update = useCallback(() => {\n setTick((tick) => tick + 1);\n }, []);\n return update;\n}\n","// tslint:disable:ordered-imports\n// organize-imports-ignore\nimport \"@plasmicapp/preamble\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { registerFetcher as unstable_registerFetcher } from \"./data\";\nimport { PlasmicElement } from \"./element-types\";\nimport { ensure } from \"./lang-utils\";\nimport registerComponent, {\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n} from \"./registerComponent\";\nimport repeatedElement, { setRepeatedElementFn } from \"./repeatedElement\";\nimport useForceUpdate from \"./useForceUpdate\";\nconst root = globalThis as any;\n\nexport { unstable_registerFetcher };\nexport { repeatedElement };\nexport {\n registerComponent,\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n};\nexport { PlasmicElement };\n\ndeclare global {\n interface Window {\n __PlasmicHostVersion: string;\n }\n}\n\nif (root.__PlasmicHostVersion == null) {\n root.__PlasmicHostVersion = \"1\";\n}\n\nconst rootChangeListeners: (() => void)[] = [];\nclass PlasmicRootNodeWrapper {\n constructor(private value: null | React.ReactElement) {}\n set = (val: null | React.ReactElement) => {\n this.value = val;\n rootChangeListeners.forEach((f) => f());\n };\n get = () => this.value;\n}\n\nconst plasmicRootNode = new PlasmicRootNodeWrapper(null);\n\nif (root.__Sub == null) {\n // Creating a side effect here by logging, so that vite won't\n // ignore this block for whatever reason\n console.log(\"Plasmic: Setting up app host dependencies\");\n root.__Sub = {\n React,\n ReactDOM,\n setPlasmicRootNode,\n registerRenderErrorListener,\n repeatedElement,\n setRepeatedElementFn,\n };\n}\n\nfunction getPlasmicOrigin() {\n const params = new URL(`https://fakeurl/${location.hash.replace(/#/, \"?\")}`)\n .searchParams;\n return ensure(\n params.get(\"origin\"),\n \"Missing information from Plasmic window.\"\n );\n}\n\nfunction renderStudioIntoIframe() {\n const script = document.createElement(\"script\");\n const plasmicOrigin = getPlasmicOrigin();\n script.src = plasmicOrigin + \"/static/js/studio.js\";\n document.body.appendChild(script);\n}\n\nlet renderCount = 0;\nfunction setPlasmicRootNode(node: React.ReactElement | null) {\n // Keep track of renderCount, which we use as key to ErrorBoundary, so\n // we can reset the error on each render\n renderCount++;\n plasmicRootNode.set(node);\n}\n\n/**\n * React context to detect whether the component is rendered on Plasmic editor.\n */\nexport const PlasmicCanvasContext = React.createContext<boolean>(false);\n\nfunction _PlasmicCanvasHost() {\n // If window.parent is null, then this is a window whose containing iframe\n // has been detached from the DOM (for the top window, window.parent === window).\n // In that case, we shouldn't do anything. If window.parent is null, by the way,\n // location.hash will also be null.\n const isFrameAttached = !!window.parent;\n const isCanvas = !!location.hash?.match(/\\bcanvas=true\\b/);\n const isLive = !!location.hash?.match(/\\blive=true\\b/) || !isFrameAttached;\n const shouldRenderStudio =\n isFrameAttached &&\n !document.querySelector(\"#plasmic-studio-tag\") &&\n !isCanvas &&\n !isLive;\n const forceUpdate = useForceUpdate();\n React.useLayoutEffect(() => {\n rootChangeListeners.push(forceUpdate);\n return () => {\n const index = rootChangeListeners.indexOf(forceUpdate);\n if (index >= 0) {\n rootChangeListeners.splice(index, 1);\n }\n };\n }, [forceUpdate]);\n React.useEffect(() => {\n if (shouldRenderStudio && isFrameAttached && window.parent !== window) {\n renderStudioIntoIframe();\n }\n }, [shouldRenderStudio, isFrameAttached]);\n React.useEffect(() => {\n if (!shouldRenderStudio && !document.querySelector(\"#getlibs\") && isLive) {\n const scriptElt = document.createElement(\"script\");\n scriptElt.id = \"getlibs\";\n scriptElt.src = getPlasmicOrigin() + \"/static/js/getlibs.js\";\n scriptElt.async = false;\n scriptElt.onload = () => {\n (window as any).__GetlibsReadyResolver?.();\n };\n document.head.append(scriptElt);\n }\n }, [shouldRenderStudio]);\n if (!isFrameAttached) {\n return null;\n }\n if (isCanvas || isLive) {\n let appDiv = document.querySelector(\"#plasmic-app.__wab_user-body\");\n if (!appDiv) {\n appDiv = document.createElement(\"div\");\n appDiv.id = \"plasmic-app\";\n appDiv.classList.add(\"__wab_user-body\");\n document.body.appendChild(appDiv);\n }\n return ReactDOM.createPortal(\n <ErrorBoundary key={`${renderCount}`}>\n <PlasmicCanvasContext.Provider value={isCanvas}>\n {plasmicRootNode.get()}\n </PlasmicCanvasContext.Provider>\n </ErrorBoundary>,\n appDiv,\n \"plasmic-app\"\n );\n }\n if (shouldRenderStudio && window.parent === window) {\n return (\n <p>\n Your app is ready to host Plasmic Studio! <br /> <br />\n On the <a href=\"https://studio.plasmic.app/\">Dashboard</a>, click on the{\" \"}\n <i>Config</i> button, and set{\" \"}\n <code>{location.origin + location.pathname}</code> as the host URL.\n <br />\n <br />\n You can find more information about app-hosting{\" \"}\n <a href=\"https://www.plasmic.app/learn/app-hosting/\">here</a>.\n </p>\n );\n }\n return null;\n}\n\ninterface PlasmicCanvasHostProps {\n /**\n * Webpack hmr uses EventSource to\tlisten to hot reloads, but that\n * resultsin a persistent\tconnection from\teach window. In Plasmic\n * Studio, if a project is configured to use app-hosting with a\n * nextjs or gatsby server running in dev mode, each artboard will\n * be holding a persistent connection to the dev server.\n * Because browsers\thave a limit to\thow many connections can\n * be held\tat a time by domain, this means\tafter X\tartboards, new\n * artboards will freeze and not load.\n *\n * By default, <PlasmicCanvasHost /> will globally mutate\n * window.EventSource to avoid using EventSource for HMR, which you\n * typically don't need for your custom host page. If you do still\n * want to retain HRM, then youc an pass enableWebpackHmr={true}.\n */\n enableWebpackHmr?: boolean;\n}\n\nexport const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps> = (\n props\n) => {\n const { enableWebpackHmr } = props;\n const [node, setNode] = React.useState<React.ReactElement<any, any> | null>(\n null\n );\n React.useEffect(() => {\n setNode(<_PlasmicCanvasHost />);\n }, []);\n return (\n <>\n {!enableWebpackHmr && <DisableWebpackHmr />}\n {node}\n </>\n );\n};\n\ntype RenderErrorListener = (err: Error) => void;\nconst renderErrorListeners: RenderErrorListener[] = [];\nfunction registerRenderErrorListener(listener: RenderErrorListener) {\n renderErrorListeners.push(listener);\n return () => {\n const index = renderErrorListeners.indexOf(listener);\n if (index >= 0) {\n renderErrorListeners.splice(index, 1);\n }\n };\n}\n\ninterface ErrorBoundaryProps {\n children?: React.ReactNode;\n}\n\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\nclass ErrorBoundary extends React.Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n renderErrorListeners.forEach((listener) => listener(error));\n }\n\n render() {\n if (this.state.error) {\n return <div>Error: {`${this.state.error.message}`}</div>;\n } else {\n return this.props.children;\n }\n }\n}\n\nfunction DisableWebpackHmr() {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n return (\n <script\n type=\"text/javascript\"\n dangerouslySetInnerHTML={{\n __html: `\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n `,\n }}\n ></script>\n );\n}\n"],"names":["root","globalThis","__PlasmicFetcherRegistry","registerFetcher","fetcher","meta","push","isString","x","ensure","msg","undefined","Error","__PlasmicComponentRegistry","registerComponent","component","repeatedElement","isPrimary","elt","repeatedElementFn","Array","isArray","map","v","isValidElement","cloneElement","setRepeatedElementFn","fn","useForceUpdate","useState","setTick","update","useCallback","tick","__PlasmicHostVersion","rootChangeListeners","PlasmicRootNodeWrapper","value","val","forEach","f","plasmicRootNode","__Sub","console","log","React","ReactDOM","setPlasmicRootNode","registerRenderErrorListener","getPlasmicOrigin","params","URL","location","hash","replace","searchParams","get","renderStudioIntoIframe","script","document","createElement","plasmicOrigin","src","body","appendChild","renderCount","node","set","PlasmicCanvasContext","_PlasmicCanvasHost","isFrameAttached","window","parent","isCanvas","match","isLive","shouldRenderStudio","querySelector","forceUpdate","index","indexOf","splice","scriptElt","id","async","onload","__GetlibsReadyResolver","head","append","appDiv","classList","add","ErrorBoundary","key","Provider","href","origin","pathname","PlasmicCanvasHost","props","enableWebpackHmr","setNode","DisableWebpackHmr","renderErrorListeners","listener","state","getDerivedStateFromError","error","componentDidCatch","render","message","children","type","dangerouslySetInnerHTML","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAMA,IAAI,GAAGC,UAAb;AAyCAD,IAAI,CAACE,wBAAL,GAAgC,EAAhC;SAEgBC,gBAAgBC,SAAkBC;AAChDL,EAAAA,IAAI,CAACE,wBAAL,CAA8BI,IAA9B,CAAmC;AAAEF,IAAAA,OAAO,EAAPA,OAAF;AAAWC,IAAAA,IAAI,EAAJA;AAAX,GAAnC;AACD;;AC9CD,SAASE,QAAT,CAAkBC,CAAlB;AACE,SAAO,OAAOA,CAAP,KAAa,QAApB;AACD;;AAID,SAAgBC,OAAUD,GAAyBE;MAAAA;AAAAA,IAAAA,MAAiB;;;AAClE,MAAIF,CAAC,KAAK,IAAN,IAAcA,CAAC,KAAKG,SAAxB,EAAmC;AACjC;AACAD,IAAAA,GAAG,GAAG,CAACH,QAAQ,CAACG,GAAD,CAAR,GAAgBA,GAAhB,GAAsBA,GAAG,EAA1B,KAAiC,EAAvC;AACA,UAAM,IAAIE,KAAJ,0CACkCF,GAAG,UAAQA,GAAR,GAAgB,EADrD,EAAN;AAGD,GAND,MAMO;AACL,WAAOF,CAAP;AACD;AACF;;ACVD,IAAMR,MAAI,GAAGC,UAAb;;AAiRA,IAAID,MAAI,CAACa,0BAAL,IAAmC,IAAvC,EAA6C;AAC3Cb,EAAAA,MAAI,CAACa,0BAAL,GAAkC,EAAlC;AACD;;AAED,SAAwBC,kBACtBC,WACAV;AAEAL,EAAAA,MAAI,CAACa,0BAAL,CAAgCP,IAAhC,CAAqC;AAAES,IAAAA,SAAS,EAATA,SAAF;AAAaV,IAAAA,IAAI,EAAJA;AAAb,GAArC;AACD;;AC9RD;;;;;;;;;;;AAUA,SAAwBW,gBAAoBC,WAAoBC;AAC9D,SAAOC,iBAAiB,CAACF,SAAD,E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;AACE,yCAAMA,KAAN;AACA,WAAKM,KAAL,GAAa,EAAb;;AACD;;gBAEMC,2BAAP,kCAAgCC,KAAhC;AACE,WAAO;AAAEA,MAAAA,KAAK,EAALA;AAAF,KAAP;AACD;;;;SAEDC,oBAAA,2BAAkBD,KAAlB;AACEJ,IAAAA,oBAAoB,CAAChE,OAArB,CAA6B,UAACiE,QAAD;AAAA,aAAcA,QAAQ,CAACG,KAAD,CAAtB;AAAA,KAA7B;AACD;;SAEDE,SAAA;AACE,QAAI,KAAKJ,KAAL,CAAWE,KAAf,EAAsB;AACpB,aAAO9D,mBAAA,MAAA,MAAA,WAAA,OAAgB,KAAK4D,KAAL,CAAWE,KAAX,CAAiBG,OAAjC,CAAP;AACD,KAFD,MAEO;AACL,aAAO,KAAKX,KAAL,CAAWY,QAAlB;AACD;AACF;;;EAvByBlE;;AA0B5B,SAASyD,iBAAT;AACE;AAGA,SACEzD,mBAAA,SAAA;AACEmE,IAAAA,IAAI,EAAC;AACLC,IAAAA,uBAAuB,EAAE;AACvBC,MAAAA,MAAM;AADiB;GAF3B,CADF;AAsBD;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.cjs.production.min.js","sources":["../src/data.ts","../src/registerComponent.ts","../src/repeatedElement.ts","../src/index.tsx","../src/lang-utils.ts","../src/useForceUpdate.ts"],"sourcesContent":["import { PrimitiveType } from \"./index\";\nconst root = globalThis as any;\n\nexport type Fetcher = (...args: any[]) => Promise<any>;\n\nexport interface FetcherMeta {\n /**\n * Any unique identifying string for this fetcher.\n */\n name: string;\n /**\n * The Studio-user-friendly display name.\n */\n displayName?: string;\n /**\n * The symbol to import from the importPath.\n */\n importName?: string;\n args: { name: string; type: PrimitiveType }[];\n returns: PrimitiveType;\n /**\n * Either the path to the fetcher relative to `rootDir` or the npm\n * package name\n */\n importPath: string;\n /**\n * Whether it's a default export or named export\n */\n isDefaultExport?: boolean;\n}\n\nexport interface FetcherRegistration {\n fetcher: Fetcher;\n meta: FetcherMeta;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFetcherRegistry: FetcherRegistration[];\n }\n}\n\nroot.__PlasmicFetcherRegistry = [];\n\nexport function registerFetcher(fetcher: Fetcher, meta: FetcherMeta) {\n root.__PlasmicFetcherRegistry.push({ fetcher, meta });\n}\n","import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\ntype PropTypeBase<P> = {\n displayName?: string;\n description?: string;\n hidden?: (props: P) => boolean;\n};\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ntype NumberType<P> =\n | \"number\"\n | ({\n type: \"number\";\n defaultValue?: number;\n } & PropTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype ChoiceType<P> = {\n type: \"choice\";\n options: string[] | ((props: P) => string[]);\n defaultValue?: string;\n} & PropTypeBase<P>;\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String>\n | (Exclude<T, String> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P>\n >\n : T extends boolean\n ? SupportControlled<BooleanType<P> | JSONLikeType<P>>\n : T extends number\n ? SupportControlled<NumberType<P> | JSONLikeType<P>>\n : PropType<P>;\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n","import { cloneElement, isValidElement } from \"react\";\n\n/**\n * Allows a component from Plasmic Studio to be repeated.\n * `isPrimary` should be true for at most one instance of the component, and\n * indicates which copy of the element will be highlighted when the element is\n * selected in Studio.\n * If `isPrimary` is `false`, and `elt` is a React element (or an array of such),\n * it'll be cloned (using React.cloneElement) and ajusted if it's a component\n * from Plasmic Studio. Otherwise, if `elt` is not a React element, the original\n * value is returned.\n */\nexport default function repeatedElement<T,>(isPrimary: boolean, elt: T): T {\n return repeatedElementFn(isPrimary, elt);\n}\n\nlet repeatedElementFn = <T,>(isPrimary: boolean, elt: T): T => {\n if (isPrimary) {\n return elt;\n }\n if (Array.isArray(elt)) {\n return elt.map((v) => repeatedElement(isPrimary, v)) as any as T;\n }\n if (elt && isValidElement(elt) && typeof elt !== \"string\") {\n return cloneElement(elt) as any as T;\n }\n return elt;\n}\n\nexport function setRepeatedElementFn(fn: typeof repeatedElement) {\n repeatedElementFn = fn;\n}\n\n\n","// tslint:disable:ordered-imports\n// organize-imports-ignore\nimport \"@plasmicapp/preamble\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { registerFetcher as unstable_registerFetcher } from \"./data\";\nimport { PlasmicElement } from \"./element-types\";\nimport { ensure } from \"./lang-utils\";\nimport registerComponent, {\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n} from \"./registerComponent\";\nimport repeatedElement, { setRepeatedElementFn } from \"./repeatedElement\";\nimport useForceUpdate from \"./useForceUpdate\";\nconst root = globalThis as any;\n\nexport { unstable_registerFetcher };\nexport { repeatedElement };\nexport {\n registerComponent,\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n};\nexport { PlasmicElement };\n\ndeclare global {\n interface Window {\n __PlasmicHostVersion: string;\n }\n}\n\nif (root.__PlasmicHostVersion == null) {\n root.__PlasmicHostVersion = \"1\";\n}\n\nconst rootChangeListeners: (() => void)[] = [];\nclass PlasmicRootNodeWrapper {\n constructor(private value: null | React.ReactElement) {}\n set = (val: null | React.ReactElement) => {\n this.value = val;\n rootChangeListeners.forEach((f) => f());\n };\n get = () => this.value;\n}\n\nconst plasmicRootNode = new PlasmicRootNodeWrapper(null);\n\nif (root.__Sub == null) {\n // Creating a side effect here by logging, so that vite won't\n // ignore this block for whatever reason\n console.log(\"Plasmic: Setting up app host dependencies\");\n root.__Sub = {\n React,\n ReactDOM,\n setPlasmicRootNode,\n registerRenderErrorListener,\n repeatedElement,\n setRepeatedElementFn,\n };\n}\n\nfunction getPlasmicOrigin() {\n const params = new URL(`https://fakeurl/${location.hash.replace(/#/, \"?\")}`)\n .searchParams;\n return ensure(\n params.get(\"origin\"),\n \"Missing information from Plasmic window.\"\n );\n}\n\nfunction renderStudioIntoIframe() {\n const script = document.createElement(\"script\");\n const plasmicOrigin = getPlasmicOrigin();\n script.src = plasmicOrigin + \"/static/js/studio.js\";\n document.body.appendChild(script);\n}\n\nlet renderCount = 0;\nfunction setPlasmicRootNode(node: React.ReactElement | null) {\n // Keep track of renderCount, which we use as key to ErrorBoundary, so\n // we can reset the error on each render\n renderCount++;\n plasmicRootNode.set(node);\n}\n\n/**\n * React context to detect whether the component is rendered on Plasmic editor.\n */\nexport const PlasmicCanvasContext = React.createContext<boolean>(false);\n\nfunction _PlasmicCanvasHost() {\n // If window.parent is null, then this is a window whose containing iframe\n // has been detached from the DOM (for the top window, window.parent === window).\n // In that case, we shouldn't do anything. If window.parent is null, by the way,\n // location.hash will also be null.\n const isFrameAttached = !!window.parent;\n const isCanvas = !!location.hash?.match(/\\bcanvas=true\\b/);\n const isLive = !!location.hash?.match(/\\blive=true\\b/) || !isFrameAttached;\n const shouldRenderStudio =\n isFrameAttached &&\n !document.querySelector(\"#plasmic-studio-tag\") &&\n !isCanvas &&\n !isLive;\n const forceUpdate = useForceUpdate();\n React.useLayoutEffect(() => {\n rootChangeListeners.push(forceUpdate);\n return () => {\n const index = rootChangeListeners.indexOf(forceUpdate);\n if (index >= 0) {\n rootChangeListeners.splice(index, 1);\n }\n };\n }, [forceUpdate]);\n React.useEffect(() => {\n if (shouldRenderStudio && isFrameAttached && window.parent !== window) {\n renderStudioIntoIframe();\n }\n }, [shouldRenderStudio, isFrameAttached]);\n React.useEffect(() => {\n if (!shouldRenderStudio && !document.querySelector(\"#getlibs\") && isLive) {\n const scriptElt = document.createElement(\"script\");\n scriptElt.id = \"getlibs\";\n scriptElt.src = getPlasmicOrigin() + \"/static/js/getlibs.js\";\n scriptElt.async = false;\n scriptElt.onload = () => {\n (window as any).__GetlibsReadyResolver?.();\n };\n document.head.append(scriptElt);\n }\n }, [shouldRenderStudio]);\n if (!isFrameAttached) {\n return null;\n }\n if (isCanvas || isLive) {\n let appDiv = document.querySelector(\"#plasmic-app.__wab_user-body\");\n if (!appDiv) {\n appDiv = document.createElement(\"div\");\n appDiv.id = \"plasmic-app\";\n appDiv.classList.add(\"__wab_user-body\");\n document.body.appendChild(appDiv);\n }\n return ReactDOM.createPortal(\n <ErrorBoundary key={`${renderCount}`}>\n <PlasmicCanvasContext.Provider value={isCanvas}>\n {plasmicRootNode.get()}\n </PlasmicCanvasContext.Provider>\n </ErrorBoundary>,\n appDiv,\n \"plasmic-app\"\n );\n }\n if (shouldRenderStudio && window.parent === window) {\n return (\n <p>\n Your app is ready to host Plasmic Studio! <br /> <br />\n On the <a href=\"https://studio.plasmic.app/\">Dashboard</a>, click on the{\" \"}\n <i>Config</i> button, and set{\" \"}\n <code>{location.origin + location.pathname}</code> as the host URL.\n <br />\n <br />\n You can find more information about app-hosting{\" \"}\n <a href=\"https://www.plasmic.app/learn/app-hosting/\">here</a>.\n </p>\n );\n }\n return null;\n}\n\ninterface PlasmicCanvasHostProps {\n /**\n * Webpack hmr uses EventSource to\tlisten to hot reloads, but that\n * resultsin a persistent\tconnection from\teach window. In Plasmic\n * Studio, if a project is configured to use app-hosting with a\n * nextjs or gatsby server running in dev mode, each artboard will\n * be holding a persistent connection to the dev server.\n * Because browsers\thave a limit to\thow many connections can\n * be held\tat a time by domain, this means\tafter X\tartboards, new\n * artboards will freeze and not load.\n *\n * By default, <PlasmicCanvasHost /> will globally mutate\n * window.EventSource to avoid using EventSource for HMR, which you\n * typically don't need for your custom host page. If you do still\n * want to retain HRM, then youc an pass enableWebpackHmr={true}.\n */\n enableWebpackHmr?: boolean;\n}\n\nexport const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps> = (\n props\n) => {\n const { enableWebpackHmr } = props;\n const [node, setNode] = React.useState<React.ReactElement<any, any> | null>(\n null\n );\n React.useEffect(() => {\n setNode(<_PlasmicCanvasHost />);\n }, []);\n return (\n <>\n {!enableWebpackHmr && <DisableWebpackHmr />}\n {node}\n </>\n );\n};\n\ntype RenderErrorListener = (err: Error) => void;\nconst renderErrorListeners: RenderErrorListener[] = [];\nfunction registerRenderErrorListener(listener: RenderErrorListener) {\n renderErrorListeners.push(listener);\n return () => {\n const index = renderErrorListeners.indexOf(listener);\n if (index >= 0) {\n renderErrorListeners.splice(index, 1);\n }\n };\n}\n\ninterface ErrorBoundaryProps {\n children?: React.ReactNode;\n}\n\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\nclass ErrorBoundary extends React.Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n renderErrorListeners.forEach((listener) => listener(error));\n }\n\n render() {\n if (this.state.error) {\n return <div>Error: {`${this.state.error.message}`}</div>;\n } else {\n return this.props.children;\n }\n }\n}\n\nfunction DisableWebpackHmr() {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n return (\n <script\n type=\"text/javascript\"\n dangerouslySetInnerHTML={{\n __html: `\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n `,\n }}\n ></script>\n );\n}\n","function isString(x: any): x is string {\n return typeof x === \"string\";\n}\n\ntype StringGen = string | (() => string);\n\nexport function ensure<T>(x: T | null | undefined, msg: StringGen = \"\"): T {\n if (x === null || x === undefined) {\n debugger;\n msg = (isString(msg) ? msg : msg()) || \"\";\n throw new Error(\n `Value must not be undefined or null${msg ? `- ${msg}` : \"\"}`\n );\n } else {\n return x;\n }\n}\n","import { useCallback, useState } from \"react\";\n\nexport default function useForceUpdate() {\n const [, setTick] = useState(0);\n const update = useCallback(() => {\n setTick((tick) => tick + 1);\n }, []);\n return update;\n}\n"],"names":["root","globalThis","__PlasmicFetcherRegistry","repeatedElement","isPrimary","elt","repeatedElementFn","__PlasmicComponentRegistry","Array","isArray","map","v","isValidElement","cloneElement","__PlasmicHostVersion","rootChangeListeners","plasmicRootNode","value","val","_this","forEach","f","getPlasmicOrigin","x","msg","isString","Error","ensure","URL","location","hash","replace","searchParams","get","__Sub","console","log","React","ReactDOM","setPlasmicRootNode","node","renderCount","set","registerRenderErrorListener","listener","renderErrorListeners","push","index","indexOf","splice","setRepeatedElementFn","fn","PlasmicCanvasContext","_PlasmicCanvasHost","setTick","isFrameAttached","window","parent","isCanvas","_location$hash","match","isLive","_location$hash2","shouldRenderStudio","document","querySelector","forceUpdate","useState","useCallback","tick","script","plasmicOrigin","createElement","src","body","appendChild","scriptElt","id","async","onload","__GetlibsReadyResolver","head","append","appDiv","classList","add","ErrorBoundary","key","Provider","href","origin","pathname","props","state","getDerivedStateFromError","error","componentDidCatch","render","this","message","children","DisableWebpackHmr","enableWebpackHmr","setNode","component","meta","fetcher"],"mappings":"8OACA,IAAMA,EAAOC,WAyCbD,EAAKE,yBAA2B,GCpChC,IAAMF,EAAOC,oBCMWE,EAAoBC,EAAoBC,UACvDC,EAAkBF,EAAWC,GDoLC,MAAnCL,EAAKO,6BACPP,EAAKO,2BAA6B,IClLpC,IAAID,EAAoB,SAAKF,EAAoBC,UAC3CD,EACKC,EAELG,MAAMC,QAAQJ,GACTA,EAAIK,KAAI,SAACC,UAAMR,EAAgBC,EAAWO,MAE/CN,GAAOO,iBAAeP,IAAuB,iBAARA,EAChCQ,eAAaR,GAEfA,GCRHL,EAAOC,WAoBoB,MAA7BD,EAAKc,uBACPd,EAAKc,qBAAuB,KAG9B,IAAMC,EAAsC,GAUtCC,EAAkB,IARtB,SAAoBC,yBAQ6B,cAP3C,SAACC,GACLC,EAAKF,MAAQC,EACbH,EAAoBK,SAAQ,SAACC,UAAMA,iBAE/B,kBAAMF,EAAKF,OAGK,CAA2B,MAgBnD,SAASK,oBC9DiBC,EAAyBC,eAAAA,IAAAA,EAAiB,IAC9DD,MAAAA,QAEFC,GATJ,SAAkBD,SACI,iBAANA,EAQLE,CAASD,GAAOA,EAAMA,MAAU,GACjC,IAAIE,6CAC8BF,OAAWA,EAAQ,YAGpDD,EDyDFI,CAFQ,IAAIC,uBAAuBC,SAASC,KAAKC,QAAQ,IAAK,MAClEC,aAEMC,IAAI,UACX,4CAnBc,MAAdjC,EAAKkC,QAGPC,QAAQC,IAAI,6CACZpC,EAAKkC,MAAQ,CACXG,MAAAA,EACAC,SAAAA,EACAC,mBAwBJ,SAA4BC,GAG1B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QACzBK,GAAK,cACZM,EAAOC,UAAUC,IAAI,mBACrBrB,SAASU,KAAKC,YAAYQ,IAErB7C,eACLD,gBAACiD,GAAcC,OAAQ9C,GACrBJ,gBAACe,EAAqBoC,UAASvE,MAAOyC,GACnC1C,EAAgBiB,QAGrBkD,EACA,sBAGApB,GAAsBP,OAAOC,SAAWD,OAExCnB,sEAC4CA,+BAAOA,qCAC1CA,qBAAGoD,KAAK,6DAA0D,IACzEpD,sDAA8B,IAC9BA,4BAAOR,SAAS6D,OAAS7D,SAAS8D,8BAClCtD,2BACAA,6EACgD,IAChDA,qBAAGoD,KAAK,2DAIP,SAyCH5C,EAA8C,GAmB9CyC,iCAIQM,8BACJA,UACDC,MAAQ,uFAGRC,yBAAP,SAAgCC,SACvB,CAAEA,MAAAA,+BAGXC,kBAAA,SAAkBD,GAChBlD,EAAqBzB,SAAQ,SAACwB,UAAaA,EAASmD,SAGtDE,OAAA,kBACMC,KAAKL,MAAME,MACN1D,wCAAgB6D,KAAKL,MAAME,MAAMI,SAEjCD,KAAKN,MAAMQ,aArBI/D,aA0B5B,SAASgE,WAEE,8DAlEuE,SAChFT,OAEQU,EAAqBV,EAArBU,mBACgBjE,WACtB,MADKG,OAAM+D,cAGblE,aAAgB,WACdkE,EAAQlE,gBAACgB,WACR,IAEDhB,iCACIiE,GAAoBjE,gBAACgE,QACtB7D,uCFTLgE,EACAC,GAEAzG,EAAKO,2BAA2BuC,KAAK,CAAE0D,UAAAA,EAAWC,KAAAA,yED7JpBC,EAAkBD,GAChDzG,EAAKE,yBAAyB4C,KAAK,CAAE4D,QAAAA,EAASD,KAAAA"}
|
|
1
|
+
{"version":3,"file":"host.cjs.production.min.js","sources":["../src/data.ts","../src/registerComponent.ts","../src/repeatedElement.ts","../src/index.tsx","../src/lang-utils.ts","../src/useForceUpdate.ts"],"sourcesContent":["import { PrimitiveType } from \"./index\";\nconst root = globalThis as any;\n\nexport type Fetcher = (...args: any[]) => Promise<any>;\n\nexport interface FetcherMeta {\n /**\n * Any unique identifying string for this fetcher.\n */\n name: string;\n /**\n * The Studio-user-friendly display name.\n */\n displayName?: string;\n /**\n * The symbol to import from the importPath.\n */\n importName?: string;\n args: { name: string; type: PrimitiveType }[];\n returns: PrimitiveType;\n /**\n * Either the path to the fetcher relative to `rootDir` or the npm\n * package name\n */\n importPath: string;\n /**\n * Whether it's a default export or named export\n */\n isDefaultExport?: boolean;\n}\n\nexport interface FetcherRegistration {\n fetcher: Fetcher;\n meta: FetcherMeta;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFetcherRegistry: FetcherRegistration[];\n }\n}\n\nroot.__PlasmicFetcherRegistry = [];\n\nexport function registerFetcher(fetcher: Fetcher, meta: FetcherMeta) {\n root.__PlasmicFetcherRegistry.push({ fetcher, meta });\n}\n","import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\nexport interface CanvasComponentProps<Data = any> {\n /**\n * This prop is only provided within the canvas of Plasmic Studio.\n * Allows the component to set data to be consumed by the props' controls.\n */\n setControlContextData?: (data: Data) => void;\n}\n\ntype InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;\n\n/**\n * Config option that takes the context (e.g., props) of the component instance\n * to dynamically set its value.\n */\ntype ContextDependentConfig<P, R> = (\n props: 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) => R;\n\ninterface PropTypeBase<P> {\n displayName?: string;\n description?: string;\n hidden?: ContextDependentConfig<P, boolean>;\n}\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ninterface NumberTypeBase<P> extends PropTypeBase<P> {\n type: \"number\";\n defaultValue?: number;\n}\n\ntype NumberType<P> =\n | \"number\"\n | ((\n | {\n control?: \"default\";\n min?: number | ContextDependentConfig<P, number>;\n max?: number | ContextDependentConfig<P, number>;\n }\n | {\n control: \"slider\";\n min: number | ContextDependentConfig<P, number>;\n max: number | ContextDependentConfig<P, number>;\n step?: number | ContextDependentConfig<P, number>;\n }\n ) &\n NumberTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ninterface ChoiceTypeBase<P> extends PropTypeBase<P> {\n type: \"choice\";\n options: string[] | ContextDependentConfig<P, string[]>;\n}\n\ntype ChoiceType<P> = (\n | {\n defaultValue?: string;\n multiSelect?: false;\n }\n | {\n defaultValue?: string[];\n multiSelect: true;\n }\n) &\n ChoiceTypeBase<P>;\n\ninterface CustomControlProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n value: any;\n /**\n * Sets the value to be passed to the prop. Expects a JSON-compatible value.\n */\n updateValue: (newVal: any) => void;\n}\nexport type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;\n\nexport type CustomType<P> =\n | CustomControl<P>\n | ({\n type: \"custom\";\n control: CustomControl<P>;\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n /**\n * Whether the \"empty slot\" placeholder should be hidden in the canvas.\n */\n hidePlaceholder?: boolean;\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String | CustomControl<any>>\n | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n | StringType<P>\n | ChoiceType<P>\n | JSONLikeType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\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\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n","import { cloneElement, isValidElement } from \"react\";\n\n/**\n * Allows a component from Plasmic Studio to be repeated.\n * `isPrimary` should be true for at most one instance of the component, and\n * indicates which copy of the element will be highlighted when the element is\n * selected in Studio.\n * If `isPrimary` is `false`, and `elt` is a React element (or an array of such),\n * it'll be cloned (using React.cloneElement) and ajusted if it's a component\n * from Plasmic Studio. Otherwise, if `elt` is not a React element, the original\n * value is returned.\n */\nexport default function repeatedElement<T,>(isPrimary: boolean, elt: T): T {\n return repeatedElementFn(isPrimary, elt);\n}\n\nlet repeatedElementFn = <T,>(isPrimary: boolean, elt: T): T => {\n if (isPrimary) {\n return elt;\n }\n if (Array.isArray(elt)) {\n return elt.map((v) => repeatedElement(isPrimary, v)) as any as T;\n }\n if (elt && isValidElement(elt) && typeof elt !== \"string\") {\n return cloneElement(elt) as any as T;\n }\n return elt;\n}\n\nexport function setRepeatedElementFn(fn: typeof repeatedElement) {\n repeatedElementFn = fn;\n}\n\n\n","// tslint:disable:ordered-imports\n// organize-imports-ignore\nimport \"@plasmicapp/preamble\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { registerFetcher as unstable_registerFetcher } from \"./data\";\nimport { PlasmicElement } from \"./element-types\";\nimport { ensure } from \"./lang-utils\";\nimport registerComponent, {\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n} from \"./registerComponent\";\nimport repeatedElement, { setRepeatedElementFn } from \"./repeatedElement\";\nimport useForceUpdate from \"./useForceUpdate\";\nconst root = globalThis as any;\n\nexport { unstable_registerFetcher };\nexport { repeatedElement };\nexport {\n registerComponent,\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n};\nexport { PlasmicElement };\n\ndeclare global {\n interface Window {\n __PlasmicHostVersion: string;\n }\n}\n\nif (root.__PlasmicHostVersion == null) {\n root.__PlasmicHostVersion = \"1\";\n}\n\nconst rootChangeListeners: (() => void)[] = [];\nclass PlasmicRootNodeWrapper {\n constructor(private value: null | React.ReactElement) {}\n set = (val: null | React.ReactElement) => {\n this.value = val;\n rootChangeListeners.forEach((f) => f());\n };\n get = () => this.value;\n}\n\nconst plasmicRootNode = new PlasmicRootNodeWrapper(null);\n\nif (root.__Sub == null) {\n // Creating a side effect here by logging, so that vite won't\n // ignore this block for whatever reason\n console.log(\"Plasmic: Setting up app host dependencies\");\n root.__Sub = {\n React,\n ReactDOM,\n setPlasmicRootNode,\n registerRenderErrorListener,\n repeatedElement,\n setRepeatedElementFn,\n };\n}\n\nfunction getPlasmicOrigin() {\n const params = new URL(`https://fakeurl/${location.hash.replace(/#/, \"?\")}`)\n .searchParams;\n return ensure(\n params.get(\"origin\"),\n \"Missing information from Plasmic window.\"\n );\n}\n\nfunction renderStudioIntoIframe() {\n const script = document.createElement(\"script\");\n const plasmicOrigin = getPlasmicOrigin();\n script.src = plasmicOrigin + \"/static/js/studio.js\";\n document.body.appendChild(script);\n}\n\nlet renderCount = 0;\nfunction setPlasmicRootNode(node: React.ReactElement | null) {\n // Keep track of renderCount, which we use as key to ErrorBoundary, so\n // we can reset the error on each render\n renderCount++;\n plasmicRootNode.set(node);\n}\n\n/**\n * React context to detect whether the component is rendered on Plasmic editor.\n */\nexport const PlasmicCanvasContext = React.createContext<boolean>(false);\n\nfunction _PlasmicCanvasHost() {\n // If window.parent is null, then this is a window whose containing iframe\n // has been detached from the DOM (for the top window, window.parent === window).\n // In that case, we shouldn't do anything. If window.parent is null, by the way,\n // location.hash will also be null.\n const isFrameAttached = !!window.parent;\n const isCanvas = !!location.hash?.match(/\\bcanvas=true\\b/);\n const isLive = !!location.hash?.match(/\\blive=true\\b/) || !isFrameAttached;\n const shouldRenderStudio =\n isFrameAttached &&\n !document.querySelector(\"#plasmic-studio-tag\") &&\n !isCanvas &&\n !isLive;\n const forceUpdate = useForceUpdate();\n React.useLayoutEffect(() => {\n rootChangeListeners.push(forceUpdate);\n return () => {\n const index = rootChangeListeners.indexOf(forceUpdate);\n if (index >= 0) {\n rootChangeListeners.splice(index, 1);\n }\n };\n }, [forceUpdate]);\n React.useEffect(() => {\n if (shouldRenderStudio && isFrameAttached && window.parent !== window) {\n renderStudioIntoIframe();\n }\n }, [shouldRenderStudio, isFrameAttached]);\n React.useEffect(() => {\n if (!shouldRenderStudio && !document.querySelector(\"#getlibs\") && isLive) {\n const scriptElt = document.createElement(\"script\");\n scriptElt.id = \"getlibs\";\n scriptElt.src = getPlasmicOrigin() + \"/static/js/getlibs.js\";\n scriptElt.async = false;\n scriptElt.onload = () => {\n (window as any).__GetlibsReadyResolver?.();\n };\n document.head.append(scriptElt);\n }\n }, [shouldRenderStudio]);\n if (!isFrameAttached) {\n return null;\n }\n if (isCanvas || isLive) {\n let appDiv = document.querySelector(\"#plasmic-app.__wab_user-body\");\n if (!appDiv) {\n appDiv = document.createElement(\"div\");\n appDiv.id = \"plasmic-app\";\n appDiv.classList.add(\"__wab_user-body\");\n document.body.appendChild(appDiv);\n }\n return ReactDOM.createPortal(\n <ErrorBoundary key={`${renderCount}`}>\n <PlasmicCanvasContext.Provider value={isCanvas}>\n {plasmicRootNode.get()}\n </PlasmicCanvasContext.Provider>\n </ErrorBoundary>,\n appDiv,\n \"plasmic-app\"\n );\n }\n if (shouldRenderStudio && window.parent === window) {\n return (\n <p>\n Your app is ready to host Plasmic Studio! <br /> <br />\n On the <a href=\"https://studio.plasmic.app/\">Dashboard</a>, click on the{\" \"}\n <i>Config</i> button, and set{\" \"}\n <code>{location.origin + location.pathname}</code> as the host URL.\n <br />\n <br />\n You can find more information about app-hosting{\" \"}\n <a href=\"https://www.plasmic.app/learn/app-hosting/\">here</a>.\n </p>\n );\n }\n return null;\n}\n\ninterface PlasmicCanvasHostProps {\n /**\n * Webpack hmr uses EventSource to\tlisten to hot reloads, but that\n * resultsin a persistent\tconnection from\teach window. In Plasmic\n * Studio, if a project is configured to use app-hosting with a\n * nextjs or gatsby server running in dev mode, each artboard will\n * be holding a persistent connection to the dev server.\n * Because browsers\thave a limit to\thow many connections can\n * be held\tat a time by domain, this means\tafter X\tartboards, new\n * artboards will freeze and not load.\n *\n * By default, <PlasmicCanvasHost /> will globally mutate\n * window.EventSource to avoid using EventSource for HMR, which you\n * typically don't need for your custom host page. If you do still\n * want to retain HRM, then youc an pass enableWebpackHmr={true}.\n */\n enableWebpackHmr?: boolean;\n}\n\nexport const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps> = (\n props\n) => {\n const { enableWebpackHmr } = props;\n const [node, setNode] = React.useState<React.ReactElement<any, any> | null>(\n null\n );\n React.useEffect(() => {\n setNode(<_PlasmicCanvasHost />);\n }, []);\n return (\n <>\n {!enableWebpackHmr && <DisableWebpackHmr />}\n {node}\n </>\n );\n};\n\ntype RenderErrorListener = (err: Error) => void;\nconst renderErrorListeners: RenderErrorListener[] = [];\nfunction registerRenderErrorListener(listener: RenderErrorListener) {\n renderErrorListeners.push(listener);\n return () => {\n const index = renderErrorListeners.indexOf(listener);\n if (index >= 0) {\n renderErrorListeners.splice(index, 1);\n }\n };\n}\n\ninterface ErrorBoundaryProps {\n children?: React.ReactNode;\n}\n\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\nclass ErrorBoundary extends React.Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n renderErrorListeners.forEach((listener) => listener(error));\n }\n\n render() {\n if (this.state.error) {\n return <div>Error: {`${this.state.error.message}`}</div>;\n } else {\n return this.props.children;\n }\n }\n}\n\nfunction DisableWebpackHmr() {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n return (\n <script\n type=\"text/javascript\"\n dangerouslySetInnerHTML={{\n __html: `\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n `,\n }}\n ></script>\n );\n}\n","function isString(x: any): x is string {\n return typeof x === \"string\";\n}\n\ntype StringGen = string | (() => string);\n\nexport function ensure<T>(x: T | null | undefined, msg: StringGen = \"\"): T {\n if (x === null || x === undefined) {\n debugger;\n msg = (isString(msg) ? msg : msg()) || \"\";\n throw new Error(\n `Value must not be undefined or null${msg ? `- ${msg}` : \"\"}`\n );\n } else {\n return x;\n }\n}\n","import { useCallback, useState } from \"react\";\n\nexport default function useForceUpdate() {\n const [, setTick] = useState(0);\n const update = useCallback(() => {\n setTick((tick) => tick + 1);\n }, []);\n return update;\n}\n"],"names":["root","globalThis","__PlasmicFetcherRegistry","repeatedElement","isPrimary","elt","repeatedElementFn","__PlasmicComponentRegistry","Array","isArray","map","v","isValidElement","cloneElement","__PlasmicHostVersion","rootChangeListeners","plasmicRootNode","value","val","_this","forEach","f","getPlasmicOrigin","x","msg","isString","Error","ensure","URL","location","hash","replace","searchParams","get","__Sub","console","log","React","ReactDOM","setPlasmicRootNode","node","renderCount","set","registerRenderErrorListener","listener","renderErrorListeners","push","index","indexOf","splice","setRepeatedElementFn","fn","PlasmicCanvasContext","_PlasmicCanvasHost","setTick","isFrameAttached","window","parent","isCanvas","_location$hash","match","isLive","_location$hash2","shouldRenderStudio","document","querySelector","forceUpdate","useState","useCallback","tick","script","plasmicOrigin","createElement","src","body","appendChild","scriptElt","id","async","onload","__GetlibsReadyResolver","head","append","appDiv","classList","add","ErrorBoundary","key","Provider","href","origin","pathname","props","state","getDerivedStateFromError","error","componentDidCatch","render","this","message","children","DisableWebpackHmr","enableWebpackHmr","setNode","component","meta","fetcher"],"mappings":"8OACA,IAAMA,EAAOC,WAyCbD,EAAKE,yBAA2B,GCpChC,IAAMF,EAAOC,oBCMWE,EAAoBC,EAAoBC,UACvDC,EAAkBF,EAAWC,GD0QC,MAAnCL,EAAKO,6BACPP,EAAKO,2BAA6B,ICxQpC,IAAID,EAAoB,SAAKF,EAAoBC,UAC3CD,EACKC,EAELG,MAAMC,QAAQJ,GACTA,EAAIK,KAAI,SAACC,UAAMR,EAAgBC,EAAWO,MAE/CN,GAAOO,iBAAeP,IAAuB,iBAARA,EAChCQ,eAAaR,GAEfA,GCRHL,EAAOC,WAoBoB,MAA7BD,EAAKc,uBACPd,EAAKc,qBAAuB,KAG9B,IAAMC,EAAsC,GAUtCC,EAAkB,IARtB,SAAoBC,yBAQ6B,cAP3C,SAACC,GACLC,EAAKF,MAAQC,EACbH,EAAoBK,SAAQ,SAACC,UAAMA,iBAE/B,kBAAMF,EAAKF,OAGK,CAA2B,MAgBnD,SAASK,oBC9DiBC,EAAyBC,eAAAA,IAAAA,EAAiB,IAC9DD,MAAAA,QAEFC,GATJ,SAAkBD,SACI,iBAANA,EAQLE,CAASD,GAAOA,EAAMA,MAAU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,CAAE4D,QAAAA,EAASD,KAAAA"}
|
package/dist/host.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.esm.js","sources":["../src/data.ts","../src/lang-utils.ts","../src/registerComponent.ts","../src/repeatedElement.ts","../src/useForceUpdate.ts","../src/index.tsx"],"sourcesContent":["import { PrimitiveType } from \"./index\";\nconst root = globalThis as any;\n\nexport type Fetcher = (...args: any[]) => Promise<any>;\n\nexport interface FetcherMeta {\n /**\n * Any unique identifying string for this fetcher.\n */\n name: string;\n /**\n * The Studio-user-friendly display name.\n */\n displayName?: string;\n /**\n * The symbol to import from the importPath.\n */\n importName?: string;\n args: { name: string; type: PrimitiveType }[];\n returns: PrimitiveType;\n /**\n * Either the path to the fetcher relative to `rootDir` or the npm\n * package name\n */\n importPath: string;\n /**\n * Whether it's a default export or named export\n */\n isDefaultExport?: boolean;\n}\n\nexport interface FetcherRegistration {\n fetcher: Fetcher;\n meta: FetcherMeta;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFetcherRegistry: FetcherRegistration[];\n }\n}\n\nroot.__PlasmicFetcherRegistry = [];\n\nexport function registerFetcher(fetcher: Fetcher, meta: FetcherMeta) {\n root.__PlasmicFetcherRegistry.push({ fetcher, meta });\n}\n","function isString(x: any): x is string {\n return typeof x === \"string\";\n}\n\ntype StringGen = string | (() => string);\n\nexport function ensure<T>(x: T | null | undefined, msg: StringGen = \"\"): T {\n if (x === null || x === undefined) {\n debugger;\n msg = (isString(msg) ? msg : msg()) || \"\";\n throw new Error(\n `Value must not be undefined or null${msg ? `- ${msg}` : \"\"}`\n );\n } else {\n return x;\n }\n}\n","import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\ntype PropTypeBase<P> = {\n displayName?: string;\n description?: string;\n hidden?: (props: P) => boolean;\n};\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ntype NumberType<P> =\n | \"number\"\n | ({\n type: \"number\";\n defaultValue?: number;\n } & PropTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype ChoiceType<P> = {\n type: \"choice\";\n options: string[] | ((props: P) => string[]);\n defaultValue?: string;\n} & PropTypeBase<P>;\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String>\n | (Exclude<T, String> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P>\n >\n : T extends boolean\n ? SupportControlled<BooleanType<P> | JSONLikeType<P>>\n : T extends number\n ? SupportControlled<NumberType<P> | JSONLikeType<P>>\n : PropType<P>;\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n","import { cloneElement, isValidElement } from \"react\";\n\n/**\n * Allows a component from Plasmic Studio to be repeated.\n * `isPrimary` should be true for at most one instance of the component, and\n * indicates which copy of the element will be highlighted when the element is\n * selected in Studio.\n * If `isPrimary` is `false`, and `elt` is a React element (or an array of such),\n * it'll be cloned (using React.cloneElement) and ajusted if it's a component\n * from Plasmic Studio. Otherwise, if `elt` is not a React element, the original\n * value is returned.\n */\nexport default function repeatedElement<T,>(isPrimary: boolean, elt: T): T {\n return repeatedElementFn(isPrimary, elt);\n}\n\nlet repeatedElementFn = <T,>(isPrimary: boolean, elt: T): T => {\n if (isPrimary) {\n return elt;\n }\n if (Array.isArray(elt)) {\n return elt.map((v) => repeatedElement(isPrimary, v)) as any as T;\n }\n if (elt && isValidElement(elt) && typeof elt !== \"string\") {\n return cloneElement(elt) as any as T;\n }\n return elt;\n}\n\nexport function setRepeatedElementFn(fn: typeof repeatedElement) {\n repeatedElementFn = fn;\n}\n\n\n","import { useCallback, useState } from \"react\";\n\nexport default function useForceUpdate() {\n const [, setTick] = useState(0);\n const update = useCallback(() => {\n setTick((tick) => tick + 1);\n }, []);\n return update;\n}\n","// tslint:disable:ordered-imports\n// organize-imports-ignore\nimport \"@plasmicapp/preamble\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { registerFetcher as unstable_registerFetcher } from \"./data\";\nimport { PlasmicElement } from \"./element-types\";\nimport { ensure } from \"./lang-utils\";\nimport registerComponent, {\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n} from \"./registerComponent\";\nimport repeatedElement, { setRepeatedElementFn } from \"./repeatedElement\";\nimport useForceUpdate from \"./useForceUpdate\";\nconst root = globalThis as any;\n\nexport { unstable_registerFetcher };\nexport { repeatedElement };\nexport {\n registerComponent,\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n};\nexport { PlasmicElement };\n\ndeclare global {\n interface Window {\n __PlasmicHostVersion: string;\n }\n}\n\nif (root.__PlasmicHostVersion == null) {\n root.__PlasmicHostVersion = \"1\";\n}\n\nconst rootChangeListeners: (() => void)[] = [];\nclass PlasmicRootNodeWrapper {\n constructor(private value: null | React.ReactElement) {}\n set = (val: null | React.ReactElement) => {\n this.value = val;\n rootChangeListeners.forEach((f) => f());\n };\n get = () => this.value;\n}\n\nconst plasmicRootNode = new PlasmicRootNodeWrapper(null);\n\nif (root.__Sub == null) {\n // Creating a side effect here by logging, so that vite won't\n // ignore this block for whatever reason\n console.log(\"Plasmic: Setting up app host dependencies\");\n root.__Sub = {\n React,\n ReactDOM,\n setPlasmicRootNode,\n registerRenderErrorListener,\n repeatedElement,\n setRepeatedElementFn,\n };\n}\n\nfunction getPlasmicOrigin() {\n const params = new URL(`https://fakeurl/${location.hash.replace(/#/, \"?\")}`)\n .searchParams;\n return ensure(\n params.get(\"origin\"),\n \"Missing information from Plasmic window.\"\n );\n}\n\nfunction renderStudioIntoIframe() {\n const script = document.createElement(\"script\");\n const plasmicOrigin = getPlasmicOrigin();\n script.src = plasmicOrigin + \"/static/js/studio.js\";\n document.body.appendChild(script);\n}\n\nlet renderCount = 0;\nfunction setPlasmicRootNode(node: React.ReactElement | null) {\n // Keep track of renderCount, which we use as key to ErrorBoundary, so\n // we can reset the error on each render\n renderCount++;\n plasmicRootNode.set(node);\n}\n\n/**\n * React context to detect whether the component is rendered on Plasmic editor.\n */\nexport const PlasmicCanvasContext = React.createContext<boolean>(false);\n\nfunction _PlasmicCanvasHost() {\n // If window.parent is null, then this is a window whose containing iframe\n // has been detached from the DOM (for the top window, window.parent === window).\n // In that case, we shouldn't do anything. If window.parent is null, by the way,\n // location.hash will also be null.\n const isFrameAttached = !!window.parent;\n const isCanvas = !!location.hash?.match(/\\bcanvas=true\\b/);\n const isLive = !!location.hash?.match(/\\blive=true\\b/) || !isFrameAttached;\n const shouldRenderStudio =\n isFrameAttached &&\n !document.querySelector(\"#plasmic-studio-tag\") &&\n !isCanvas &&\n !isLive;\n const forceUpdate = useForceUpdate();\n React.useLayoutEffect(() => {\n rootChangeListeners.push(forceUpdate);\n return () => {\n const index = rootChangeListeners.indexOf(forceUpdate);\n if (index >= 0) {\n rootChangeListeners.splice(index, 1);\n }\n };\n }, [forceUpdate]);\n React.useEffect(() => {\n if (shouldRenderStudio && isFrameAttached && window.parent !== window) {\n renderStudioIntoIframe();\n }\n }, [shouldRenderStudio, isFrameAttached]);\n React.useEffect(() => {\n if (!shouldRenderStudio && !document.querySelector(\"#getlibs\") && isLive) {\n const scriptElt = document.createElement(\"script\");\n scriptElt.id = \"getlibs\";\n scriptElt.src = getPlasmicOrigin() + \"/static/js/getlibs.js\";\n scriptElt.async = false;\n scriptElt.onload = () => {\n (window as any).__GetlibsReadyResolver?.();\n };\n document.head.append(scriptElt);\n }\n }, [shouldRenderStudio]);\n if (!isFrameAttached) {\n return null;\n }\n if (isCanvas || isLive) {\n let appDiv = document.querySelector(\"#plasmic-app.__wab_user-body\");\n if (!appDiv) {\n appDiv = document.createElement(\"div\");\n appDiv.id = \"plasmic-app\";\n appDiv.classList.add(\"__wab_user-body\");\n document.body.appendChild(appDiv);\n }\n return ReactDOM.createPortal(\n <ErrorBoundary key={`${renderCount}`}>\n <PlasmicCanvasContext.Provider value={isCanvas}>\n {plasmicRootNode.get()}\n </PlasmicCanvasContext.Provider>\n </ErrorBoundary>,\n appDiv,\n \"plasmic-app\"\n );\n }\n if (shouldRenderStudio && window.parent === window) {\n return (\n <p>\n Your app is ready to host Plasmic Studio! <br /> <br />\n On the <a href=\"https://studio.plasmic.app/\">Dashboard</a>, click on the{\" \"}\n <i>Config</i> button, and set{\" \"}\n <code>{location.origin + location.pathname}</code> as the host URL.\n <br />\n <br />\n You can find more information about app-hosting{\" \"}\n <a href=\"https://www.plasmic.app/learn/app-hosting/\">here</a>.\n </p>\n );\n }\n return null;\n}\n\ninterface PlasmicCanvasHostProps {\n /**\n * Webpack hmr uses EventSource to\tlisten to hot reloads, but that\n * resultsin a persistent\tconnection from\teach window. In Plasmic\n * Studio, if a project is configured to use app-hosting with a\n * nextjs or gatsby server running in dev mode, each artboard will\n * be holding a persistent connection to the dev server.\n * Because browsers\thave a limit to\thow many connections can\n * be held\tat a time by domain, this means\tafter X\tartboards, new\n * artboards will freeze and not load.\n *\n * By default, <PlasmicCanvasHost /> will globally mutate\n * window.EventSource to avoid using EventSource for HMR, which you\n * typically don't need for your custom host page. If you do still\n * want to retain HRM, then youc an pass enableWebpackHmr={true}.\n */\n enableWebpackHmr?: boolean;\n}\n\nexport const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps> = (\n props\n) => {\n const { enableWebpackHmr } = props;\n const [node, setNode] = React.useState<React.ReactElement<any, any> | null>(\n null\n );\n React.useEffect(() => {\n setNode(<_PlasmicCanvasHost />);\n }, []);\n return (\n <>\n {!enableWebpackHmr && <DisableWebpackHmr />}\n {node}\n </>\n );\n};\n\ntype RenderErrorListener = (err: Error) => void;\nconst renderErrorListeners: RenderErrorListener[] = [];\nfunction registerRenderErrorListener(listener: RenderErrorListener) {\n renderErrorListeners.push(listener);\n return () => {\n const index = renderErrorListeners.indexOf(listener);\n if (index >= 0) {\n renderErrorListeners.splice(index, 1);\n }\n };\n}\n\ninterface ErrorBoundaryProps {\n children?: React.ReactNode;\n}\n\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\nclass ErrorBoundary extends React.Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n renderErrorListeners.forEach((listener) => listener(error));\n }\n\n render() {\n if (this.state.error) {\n return <div>Error: {`${this.state.error.message}`}</div>;\n } else {\n return this.props.children;\n }\n }\n}\n\nfunction DisableWebpackHmr() {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n return (\n <script\n type=\"text/javascript\"\n dangerouslySetInnerHTML={{\n __html: `\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n `,\n }}\n ></script>\n );\n}\n"],"names":["root","globalThis","__PlasmicFetcherRegistry","registerFetcher","fetcher","meta","push","isString","x","ensure","msg","undefined","Error","__PlasmicComponentRegistry","registerComponent","component","repeatedElement","isPrimary","elt","repeatedElementFn","Array","isArray","map","v","isValidElement","cloneElement","setRepeatedElementFn","fn","useForceUpdate","useState","setTick","update","useCallback","tick","__PlasmicHostVersion","rootChangeListeners","PlasmicRootNodeWrapper","value","val","forEach","f","plasmicRootNode","__Sub","console","log","React","ReactDOM","setPlasmicRootNode","registerRenderErrorListener","getPlasmicOrigin","params","URL","location","hash","replace","searchParams","get","renderStudioIntoIframe","script","document","createElement","plasmicOrigin","src","body","appendChild","renderCount","node","set","PlasmicCanvasContext","_PlasmicCanvasHost","isFrameAttached","window","parent","isCanvas","match","isLive","shouldRenderStudio","querySelector","forceUpdate","index","indexOf","splice","scriptElt","id","async","onload","__GetlibsReadyResolver","head","append","appDiv","classList","add","ErrorBoundary","key","Provider","href","origin","pathname","PlasmicCanvasHost","props","enableWebpackHmr","setNode","DisableWebpackHmr","renderErrorListeners","listener","state","getDerivedStateFromError","error","componentDidCatch","render","message","children","process","env","NODE_ENV","type","dangerouslySetInnerHTML","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,IAAMA,IAAI,GAAGC,UAAb;AAyCAD,IAAI,CAACE,wBAAL,GAAgC,EAAhC;SAEgBC,gBAAgBC,SAAkBC;AAChDL,EAAAA,IAAI,CAACE,wBAAL,CAA8BI,IAA9B,CAAmC;AAAEF,IAAAA,OAAO,EAAPA,OAAF;AAAWC,IAAAA,IAAI,EAAJA;AAAX,GAAnC;AACD;;AC9CD,SAASE,QAA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AAP;AACD,KAFD,MAEO;AACL,aAAO,KAAKX,KAAL,CAAWY,QAAlB;AACD;AACF;;;EAvByBlE;;AA0B5B,SAASyD,iBAAT;AACE,MAAIU,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,WAAO,IAAP;AACD;;AACD,SACErE,aAAA,SAAA;AACEsE,IAAAA,IAAI,EAAC;AACLC,IAAAA,uBAAuB,EAAE;AACvBC,MAAAA,MAAM;AADiB;GAF3B,CADF;AAsBD;;;;"}
|
|
1
|
+
{"version":3,"file":"host.esm.js","sources":["../src/data.ts","../src/lang-utils.ts","../src/registerComponent.ts","../src/repeatedElement.ts","../src/useForceUpdate.ts","../src/index.tsx"],"sourcesContent":["import { PrimitiveType } from \"./index\";\nconst root = globalThis as any;\n\nexport type Fetcher = (...args: any[]) => Promise<any>;\n\nexport interface FetcherMeta {\n /**\n * Any unique identifying string for this fetcher.\n */\n name: string;\n /**\n * The Studio-user-friendly display name.\n */\n displayName?: string;\n /**\n * The symbol to import from the importPath.\n */\n importName?: string;\n args: { name: string; type: PrimitiveType }[];\n returns: PrimitiveType;\n /**\n * Either the path to the fetcher relative to `rootDir` or the npm\n * package name\n */\n importPath: string;\n /**\n * Whether it's a default export or named export\n */\n isDefaultExport?: boolean;\n}\n\nexport interface FetcherRegistration {\n fetcher: Fetcher;\n meta: FetcherMeta;\n}\n\ndeclare global {\n interface Window {\n __PlasmicFetcherRegistry: FetcherRegistration[];\n }\n}\n\nroot.__PlasmicFetcherRegistry = [];\n\nexport function registerFetcher(fetcher: Fetcher, meta: FetcherMeta) {\n root.__PlasmicFetcherRegistry.push({ fetcher, meta });\n}\n","function isString(x: any): x is string {\n return typeof x === \"string\";\n}\n\ntype StringGen = string | (() => string);\n\nexport function ensure<T>(x: T | null | undefined, msg: StringGen = \"\"): T {\n if (x === null || x === undefined) {\n debugger;\n msg = (isString(msg) ? msg : msg()) || \"\";\n throw new Error(\n `Value must not be undefined or null${msg ? `- ${msg}` : \"\"}`\n );\n } else {\n return x;\n }\n}\n","import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\nexport interface CanvasComponentProps<Data = any> {\n /**\n * This prop is only provided within the canvas of Plasmic Studio.\n * Allows the component to set data to be consumed by the props' controls.\n */\n setControlContextData?: (data: Data) => void;\n}\n\ntype InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;\n\n/**\n * Config option that takes the context (e.g., props) of the component instance\n * to dynamically set its value.\n */\ntype ContextDependentConfig<P, R> = (\n props: 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) => R;\n\ninterface PropTypeBase<P> {\n displayName?: string;\n description?: string;\n hidden?: ContextDependentConfig<P, boolean>;\n}\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ninterface NumberTypeBase<P> extends PropTypeBase<P> {\n type: \"number\";\n defaultValue?: number;\n}\n\ntype NumberType<P> =\n | \"number\"\n | ((\n | {\n control?: \"default\";\n min?: number | ContextDependentConfig<P, number>;\n max?: number | ContextDependentConfig<P, number>;\n }\n | {\n control: \"slider\";\n min: number | ContextDependentConfig<P, number>;\n max: number | ContextDependentConfig<P, number>;\n step?: number | ContextDependentConfig<P, number>;\n }\n ) &\n NumberTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ninterface ChoiceTypeBase<P> extends PropTypeBase<P> {\n type: \"choice\";\n options: string[] | ContextDependentConfig<P, string[]>;\n}\n\ntype ChoiceType<P> = (\n | {\n defaultValue?: string;\n multiSelect?: false;\n }\n | {\n defaultValue?: string[];\n multiSelect: true;\n }\n) &\n ChoiceTypeBase<P>;\n\ninterface CustomControlProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n value: any;\n /**\n * Sets the value to be passed to the prop. Expects a JSON-compatible value.\n */\n updateValue: (newVal: any) => void;\n}\nexport type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;\n\nexport type CustomType<P> =\n | CustomControl<P>\n | ({\n type: \"custom\";\n control: CustomControl<P>;\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n /**\n * Whether the \"empty slot\" placeholder should be hidden in the canvas.\n */\n hidePlaceholder?: boolean;\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String | CustomControl<any>>\n | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n | StringType<P>\n | ChoiceType<P>\n | JSONLikeType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\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\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n","import { cloneElement, isValidElement } from \"react\";\n\n/**\n * Allows a component from Plasmic Studio to be repeated.\n * `isPrimary` should be true for at most one instance of the component, and\n * indicates which copy of the element will be highlighted when the element is\n * selected in Studio.\n * If `isPrimary` is `false`, and `elt` is a React element (or an array of such),\n * it'll be cloned (using React.cloneElement) and ajusted if it's a component\n * from Plasmic Studio. Otherwise, if `elt` is not a React element, the original\n * value is returned.\n */\nexport default function repeatedElement<T,>(isPrimary: boolean, elt: T): T {\n return repeatedElementFn(isPrimary, elt);\n}\n\nlet repeatedElementFn = <T,>(isPrimary: boolean, elt: T): T => {\n if (isPrimary) {\n return elt;\n }\n if (Array.isArray(elt)) {\n return elt.map((v) => repeatedElement(isPrimary, v)) as any as T;\n }\n if (elt && isValidElement(elt) && typeof elt !== \"string\") {\n return cloneElement(elt) as any as T;\n }\n return elt;\n}\n\nexport function setRepeatedElementFn(fn: typeof repeatedElement) {\n repeatedElementFn = fn;\n}\n\n\n","import { useCallback, useState } from \"react\";\n\nexport default function useForceUpdate() {\n const [, setTick] = useState(0);\n const update = useCallback(() => {\n setTick((tick) => tick + 1);\n }, []);\n return update;\n}\n","// tslint:disable:ordered-imports\n// organize-imports-ignore\nimport \"@plasmicapp/preamble\";\n\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { registerFetcher as unstable_registerFetcher } from \"./data\";\nimport { PlasmicElement } from \"./element-types\";\nimport { ensure } from \"./lang-utils\";\nimport registerComponent, {\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n} from \"./registerComponent\";\nimport repeatedElement, { setRepeatedElementFn } from \"./repeatedElement\";\nimport useForceUpdate from \"./useForceUpdate\";\nconst root = globalThis as any;\n\nexport { unstable_registerFetcher };\nexport { repeatedElement };\nexport {\n registerComponent,\n ComponentMeta,\n ComponentRegistration,\n ComponentTemplates,\n PrimitiveType,\n PropType,\n};\nexport { PlasmicElement };\n\ndeclare global {\n interface Window {\n __PlasmicHostVersion: string;\n }\n}\n\nif (root.__PlasmicHostVersion == null) {\n root.__PlasmicHostVersion = \"1\";\n}\n\nconst rootChangeListeners: (() => void)[] = [];\nclass PlasmicRootNodeWrapper {\n constructor(private value: null | React.ReactElement) {}\n set = (val: null | React.ReactElement) => {\n this.value = val;\n rootChangeListeners.forEach((f) => f());\n };\n get = () => this.value;\n}\n\nconst plasmicRootNode = new PlasmicRootNodeWrapper(null);\n\nif (root.__Sub == null) {\n // Creating a side effect here by logging, so that vite won't\n // ignore this block for whatever reason\n console.log(\"Plasmic: Setting up app host dependencies\");\n root.__Sub = {\n React,\n ReactDOM,\n setPlasmicRootNode,\n registerRenderErrorListener,\n repeatedElement,\n setRepeatedElementFn,\n };\n}\n\nfunction getPlasmicOrigin() {\n const params = new URL(`https://fakeurl/${location.hash.replace(/#/, \"?\")}`)\n .searchParams;\n return ensure(\n params.get(\"origin\"),\n \"Missing information from Plasmic window.\"\n );\n}\n\nfunction renderStudioIntoIframe() {\n const script = document.createElement(\"script\");\n const plasmicOrigin = getPlasmicOrigin();\n script.src = plasmicOrigin + \"/static/js/studio.js\";\n document.body.appendChild(script);\n}\n\nlet renderCount = 0;\nfunction setPlasmicRootNode(node: React.ReactElement | null) {\n // Keep track of renderCount, which we use as key to ErrorBoundary, so\n // we can reset the error on each render\n renderCount++;\n plasmicRootNode.set(node);\n}\n\n/**\n * React context to detect whether the component is rendered on Plasmic editor.\n */\nexport const PlasmicCanvasContext = React.createContext<boolean>(false);\n\nfunction _PlasmicCanvasHost() {\n // If window.parent is null, then this is a window whose containing iframe\n // has been detached from the DOM (for the top window, window.parent === window).\n // In that case, we shouldn't do anything. If window.parent is null, by the way,\n // location.hash will also be null.\n const isFrameAttached = !!window.parent;\n const isCanvas = !!location.hash?.match(/\\bcanvas=true\\b/);\n const isLive = !!location.hash?.match(/\\blive=true\\b/) || !isFrameAttached;\n const shouldRenderStudio =\n isFrameAttached &&\n !document.querySelector(\"#plasmic-studio-tag\") &&\n !isCanvas &&\n !isLive;\n const forceUpdate = useForceUpdate();\n React.useLayoutEffect(() => {\n rootChangeListeners.push(forceUpdate);\n return () => {\n const index = rootChangeListeners.indexOf(forceUpdate);\n if (index >= 0) {\n rootChangeListeners.splice(index, 1);\n }\n };\n }, [forceUpdate]);\n React.useEffect(() => {\n if (shouldRenderStudio && isFrameAttached && window.parent !== window) {\n renderStudioIntoIframe();\n }\n }, [shouldRenderStudio, isFrameAttached]);\n React.useEffect(() => {\n if (!shouldRenderStudio && !document.querySelector(\"#getlibs\") && isLive) {\n const scriptElt = document.createElement(\"script\");\n scriptElt.id = \"getlibs\";\n scriptElt.src = getPlasmicOrigin() + \"/static/js/getlibs.js\";\n scriptElt.async = false;\n scriptElt.onload = () => {\n (window as any).__GetlibsReadyResolver?.();\n };\n document.head.append(scriptElt);\n }\n }, [shouldRenderStudio]);\n if (!isFrameAttached) {\n return null;\n }\n if (isCanvas || isLive) {\n let appDiv = document.querySelector(\"#plasmic-app.__wab_user-body\");\n if (!appDiv) {\n appDiv = document.createElement(\"div\");\n appDiv.id = \"plasmic-app\";\n appDiv.classList.add(\"__wab_user-body\");\n document.body.appendChild(appDiv);\n }\n return ReactDOM.createPortal(\n <ErrorBoundary key={`${renderCount}`}>\n <PlasmicCanvasContext.Provider value={isCanvas}>\n {plasmicRootNode.get()}\n </PlasmicCanvasContext.Provider>\n </ErrorBoundary>,\n appDiv,\n \"plasmic-app\"\n );\n }\n if (shouldRenderStudio && window.parent === window) {\n return (\n <p>\n Your app is ready to host Plasmic Studio! <br /> <br />\n On the <a href=\"https://studio.plasmic.app/\">Dashboard</a>, click on the{\" \"}\n <i>Config</i> button, and set{\" \"}\n <code>{location.origin + location.pathname}</code> as the host URL.\n <br />\n <br />\n You can find more information about app-hosting{\" \"}\n <a href=\"https://www.plasmic.app/learn/app-hosting/\">here</a>.\n </p>\n );\n }\n return null;\n}\n\ninterface PlasmicCanvasHostProps {\n /**\n * Webpack hmr uses EventSource to\tlisten to hot reloads, but that\n * resultsin a persistent\tconnection from\teach window. In Plasmic\n * Studio, if a project is configured to use app-hosting with a\n * nextjs or gatsby server running in dev mode, each artboard will\n * be holding a persistent connection to the dev server.\n * Because browsers\thave a limit to\thow many connections can\n * be held\tat a time by domain, this means\tafter X\tartboards, new\n * artboards will freeze and not load.\n *\n * By default, <PlasmicCanvasHost /> will globally mutate\n * window.EventSource to avoid using EventSource for HMR, which you\n * typically don't need for your custom host page. If you do still\n * want to retain HRM, then youc an pass enableWebpackHmr={true}.\n */\n enableWebpackHmr?: boolean;\n}\n\nexport const PlasmicCanvasHost: React.FunctionComponent<PlasmicCanvasHostProps> = (\n props\n) => {\n const { enableWebpackHmr } = props;\n const [node, setNode] = React.useState<React.ReactElement<any, any> | null>(\n null\n );\n React.useEffect(() => {\n setNode(<_PlasmicCanvasHost />);\n }, []);\n return (\n <>\n {!enableWebpackHmr && <DisableWebpackHmr />}\n {node}\n </>\n );\n};\n\ntype RenderErrorListener = (err: Error) => void;\nconst renderErrorListeners: RenderErrorListener[] = [];\nfunction registerRenderErrorListener(listener: RenderErrorListener) {\n renderErrorListeners.push(listener);\n return () => {\n const index = renderErrorListeners.indexOf(listener);\n if (index >= 0) {\n renderErrorListeners.splice(index, 1);\n }\n };\n}\n\ninterface ErrorBoundaryProps {\n children?: React.ReactNode;\n}\n\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\nclass ErrorBoundary extends React.Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n componentDidCatch(error: Error) {\n renderErrorListeners.forEach((listener) => listener(error));\n }\n\n render() {\n if (this.state.error) {\n return <div>Error: {`${this.state.error.message}`}</div>;\n } else {\n return this.props.children;\n }\n }\n}\n\nfunction DisableWebpackHmr() {\n if (process.env.NODE_ENV === \"production\") {\n return null;\n }\n return (\n <script\n type=\"text/javascript\"\n dangerouslySetInnerHTML={{\n __html: `\n if (typeof window !== \"undefined\") {\n const RealEventSource = window.EventSource;\n window.EventSource = function(url, config) {\n if (/[^a-zA-Z]hmr($|[^a-zA-Z])/.test(url)) {\n console.warn(\"Plasmic: disabled EventSource request for\", url);\n return {\n onerror() {}, onmessage() {}, onopen() {}, close() {}\n };\n } else {\n return new RealEventSource(url, config);\n }\n }\n }\n `,\n }}\n ></script>\n );\n}\n"],"names":["root","globalThis","__PlasmicFetcherRegistry","registerFetcher","fetcher","meta","push","isString","x","ensure","msg","undefined","Error","__PlasmicComponentRegistry","registerComponent","component","repeatedElement","isPrimary","elt","repeatedElementFn","Array","isArray","map","v","isValidElement","cloneElement","setRepeatedElementFn","fn","useForceUpdate","useState","setTick","update","useCallback","tick","__PlasmicHostVersion","rootChangeListeners","PlasmicRootNodeWrapper","value","val","forEach","f","plasmicRootNode","__Sub","console","log","React","ReactDOM","setPlasmicRootNode","registerRenderErrorListener","getPlasmicOrigin","params","URL","location","hash","replace","searchParams","get","renderStudioIntoIframe","script","document","createElement","plasmicOrigin","src","body","appendChild","renderCount","node","set","PlasmicCanvasContext","_PlasmicCanvasHost","isFrameAttached","window","parent","isCanvas","match","isLive","shouldRenderStudio","querySelector","forceUpdate","index","indexOf","splice","scriptElt","id","async","onload","__GetlibsReadyResolver","head","append","appDiv","classList","add","ErrorBoundary","key","Provider","href","origin","pathname","PlasmicCanvasHost","props","enableWebpackHmr","setNode","DisableWebpackHmr","renderErrorListeners","listener","state","getDerivedStateFromError","error","componentDidCatch","render","message","children","process","env","NODE_ENV","type","dangerouslySetInnerHTML","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,IAAMA,IAAI,GAAGC,UAAb;AAyCAD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,QAAD;AAAA,aAAcA,QAAQ,CAACG,KAAD,CAAtB;AAAA,KAA7B;AACD;;SAEDE,SAAA;AACE,QAAI,KAAKJ,KAAL,CAAWE,KAAf,EAAsB;AACpB,aAAO9D,aAAA,MAAA,MAAA,WAAA,OAAgB,KAAK4D,KAAL,CAAWE,KAAX,CAAiBG,OAAjC,CAAP;AACD,KAFD,MAEO;AACL,aAAO,KAAKX,KAAL,CAAWY,QAAlB;AACD;AACF;;;EAvByBlE;;AA0B5B,SAASyD,iBAAT;AACE,MAAIU,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,WAAO,IAAP;AACD;;AACD,SACErE,aAAA,SAAA;AACEsE,IAAAA,IAAI,EAAC;AACLC,IAAAA,uBAAuB,EAAE;AACvBC,MAAAA,MAAM;AADiB;GAF3B,CADF;AAsBD;;;;"}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CodeComponentElement, CSSProperties, PlasmicElement } from "./element-types";
|
|
3
|
-
|
|
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> {
|
|
4
23
|
displayName?: string;
|
|
5
24
|
description?: string;
|
|
6
|
-
hidden?:
|
|
7
|
-
}
|
|
25
|
+
hidden?: ContextDependentConfig<P, boolean>;
|
|
26
|
+
}
|
|
8
27
|
declare type StringType<P> = "string" | ({
|
|
9
28
|
type: "string";
|
|
10
29
|
defaultValue?: string;
|
|
@@ -13,10 +32,20 @@ declare type BooleanType<P> = "boolean" | ({
|
|
|
13
32
|
type: "boolean";
|
|
14
33
|
defaultValue?: boolean;
|
|
15
34
|
} & PropTypeBase<P>);
|
|
16
|
-
|
|
35
|
+
interface NumberTypeBase<P> extends PropTypeBase<P> {
|
|
17
36
|
type: "number";
|
|
18
37
|
defaultValue?: number;
|
|
19
|
-
}
|
|
38
|
+
}
|
|
39
|
+
declare type NumberType<P> = "number" | (({
|
|
40
|
+
control?: "default";
|
|
41
|
+
min?: number | ContextDependentConfig<P, number>;
|
|
42
|
+
max?: number | ContextDependentConfig<P, number>;
|
|
43
|
+
} | {
|
|
44
|
+
control: "slider";
|
|
45
|
+
min: number | ContextDependentConfig<P, number>;
|
|
46
|
+
max: number | ContextDependentConfig<P, number>;
|
|
47
|
+
step?: number | ContextDependentConfig<P, number>;
|
|
48
|
+
}) & NumberTypeBase<P>);
|
|
20
49
|
declare type JSONLikeType<P> = "object" | ({
|
|
21
50
|
type: "object";
|
|
22
51
|
/**
|
|
@@ -24,11 +53,40 @@ declare type JSONLikeType<P> = "object" | ({
|
|
|
24
53
|
*/
|
|
25
54
|
defaultValue?: any;
|
|
26
55
|
} & PropTypeBase<P>);
|
|
27
|
-
|
|
56
|
+
interface ChoiceTypeBase<P> extends PropTypeBase<P> {
|
|
28
57
|
type: "choice";
|
|
29
|
-
options: string[] |
|
|
58
|
+
options: string[] | ContextDependentConfig<P, string[]>;
|
|
59
|
+
}
|
|
60
|
+
declare type ChoiceType<P> = ({
|
|
30
61
|
defaultValue?: string;
|
|
31
|
-
|
|
62
|
+
multiSelect?: false;
|
|
63
|
+
} | {
|
|
64
|
+
defaultValue?: string[];
|
|
65
|
+
multiSelect: true;
|
|
66
|
+
}) & ChoiceTypeBase<P>;
|
|
67
|
+
interface CustomControlProps<P> {
|
|
68
|
+
componentProps: P;
|
|
69
|
+
/**
|
|
70
|
+
* `contextData` can be `null` if the prop controls are rendering before
|
|
71
|
+
* the component instance itself (it will re-render once the component
|
|
72
|
+
* calls `setControlContextData`)
|
|
73
|
+
*/
|
|
74
|
+
contextData: InferDataType<P> | null;
|
|
75
|
+
value: any;
|
|
76
|
+
/**
|
|
77
|
+
* Sets the value to be passed to the prop. Expects a JSON-compatible value.
|
|
78
|
+
*/
|
|
79
|
+
updateValue: (newVal: any) => void;
|
|
80
|
+
}
|
|
81
|
+
export declare type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
|
|
82
|
+
export declare type CustomType<P> = CustomControl<P> | ({
|
|
83
|
+
type: "custom";
|
|
84
|
+
control: CustomControl<P>;
|
|
85
|
+
/**
|
|
86
|
+
* Expects a JSON-compatible value
|
|
87
|
+
*/
|
|
88
|
+
defaultValue?: any;
|
|
89
|
+
} & PropTypeBase<P>);
|
|
32
90
|
declare type SlotType = "slot" | {
|
|
33
91
|
type: "slot";
|
|
34
92
|
/**
|
|
@@ -36,6 +94,10 @@ declare type SlotType = "slot" | {
|
|
|
36
94
|
*/
|
|
37
95
|
allowedComponents?: string[];
|
|
38
96
|
defaultValue?: PlasmicElement | PlasmicElement[];
|
|
97
|
+
/**
|
|
98
|
+
* Whether the "empty slot" placeholder should be hidden in the canvas.
|
|
99
|
+
*/
|
|
100
|
+
hidePlaceholder?: boolean;
|
|
39
101
|
};
|
|
40
102
|
declare type ImageUrlType<P> = "imageUrl" | ({
|
|
41
103
|
type: "imageUrl";
|
|
@@ -51,9 +113,9 @@ declare type ControlTypeBase = {
|
|
|
51
113
|
*/
|
|
52
114
|
uncontrolledProp?: string;
|
|
53
115
|
};
|
|
54
|
-
declare type SupportControlled<T> = Extract<T, String
|
|
55
|
-
export declare type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | ImageUrlType<P>> | SlotType;
|
|
56
|
-
declare type RestrictPropType<T, P> = T extends string ? SupportControlled<StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P>> : T extends boolean ? SupportControlled<BooleanType<P> | JSONLikeType<P>> : T extends number ? SupportControlled<NumberType<P> | JSONLikeType<P>> : PropType<P>;
|
|
116
|
+
declare type SupportControlled<T> = Extract<T, String | CustomControl<any>> | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);
|
|
117
|
+
export declare type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | ImageUrlType<P> | CustomType<P>> | SlotType;
|
|
118
|
+
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>;
|
|
57
119
|
interface ComponentTemplate<P> extends Omit<CodeComponentElement<P>, "type" | "name"> {
|
|
58
120
|
/**
|
|
59
121
|
* A preview picture for the template.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/host",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
4
4
|
"description": "plasmic library for app hosting",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"analyze": "size-limit --why"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@plasmicapp/preamble": "0.0.
|
|
32
|
+
"@plasmicapp/preamble": "0.0.25",
|
|
33
33
|
"window-or-global": "^1.0.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\ntype
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\nexport interface CanvasComponentProps<Data = any> {\n /**\n * This prop is only provided within the canvas of Plasmic Studio.\n * Allows the component to set data to be consumed by the props' controls.\n */\n setControlContextData?: (data: Data) => void;\n}\n\ntype InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;\n\n/**\n * Config option that takes the context (e.g., props) of the component instance\n * to dynamically set its value.\n */\ntype ContextDependentConfig<P, R> = (\n props: 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) => R;\n\ninterface PropTypeBase<P> {\n displayName?: string;\n description?: string;\n hidden?: ContextDependentConfig<P, boolean>;\n}\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ninterface NumberTypeBase<P> extends PropTypeBase<P> {\n type: \"number\";\n defaultValue?: number;\n}\n\ntype NumberType<P> =\n | \"number\"\n | ((\n | {\n control?: \"default\";\n min?: number | ContextDependentConfig<P, number>;\n max?: number | ContextDependentConfig<P, number>;\n }\n | {\n control: \"slider\";\n min: number | ContextDependentConfig<P, number>;\n max: number | ContextDependentConfig<P, number>;\n step?: number | ContextDependentConfig<P, number>;\n }\n ) &\n NumberTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ninterface ChoiceTypeBase<P> extends PropTypeBase<P> {\n type: \"choice\";\n options: string[] | ContextDependentConfig<P, string[]>;\n}\n\ntype ChoiceType<P> = (\n | {\n defaultValue?: string;\n multiSelect?: false;\n }\n | {\n defaultValue?: string[];\n multiSelect: true;\n }\n) &\n ChoiceTypeBase<P>;\n\ninterface CustomControlProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n value: any;\n /**\n * Sets the value to be passed to the prop. Expects a JSON-compatible value.\n */\n updateValue: (newVal: any) => void;\n}\nexport type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;\n\nexport type CustomType<P> =\n | CustomControl<P>\n | ({\n type: \"custom\";\n control: CustomControl<P>;\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n /**\n * Whether the \"empty slot\" placeholder should be hidden in the canvas.\n */\n hidePlaceholder?: boolean;\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String | CustomControl<any>>\n | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n | StringType<P>\n | ChoiceType<P>\n | JSONLikeType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\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\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n"],"names":[],"mappings":";;;;AAMA,IAAM,IAAI,GAAG,UAAiB,CAAC;AAiR/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;IAC3C,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;CACtC;SAEuB,iBAAiB,CACvC,SAAY,EACZ,IAA4C;IAE5C,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\ntype
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/registerComponent.ts"],"sourcesContent":["import {\n CodeComponentElement,\n CSSProperties,\n PlasmicElement,\n} from \"./element-types\";\n\nconst root = globalThis as any;\n\nexport interface CanvasComponentProps<Data = any> {\n /**\n * This prop is only provided within the canvas of Plasmic Studio.\n * Allows the component to set data to be consumed by the props' controls.\n */\n setControlContextData?: (data: Data) => void;\n}\n\ntype InferDataType<P> = P extends CanvasComponentProps<infer Data> ? Data : any;\n\n/**\n * Config option that takes the context (e.g., props) of the component instance\n * to dynamically set its value.\n */\ntype ContextDependentConfig<P, R> = (\n props: 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) => R;\n\ninterface PropTypeBase<P> {\n displayName?: string;\n description?: string;\n hidden?: ContextDependentConfig<P, boolean>;\n}\n\ntype StringType<P> =\n | \"string\"\n | ({\n type: \"string\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\ntype BooleanType<P> =\n | \"boolean\"\n | ({\n type: \"boolean\";\n defaultValue?: boolean;\n } & PropTypeBase<P>);\n\ninterface NumberTypeBase<P> extends PropTypeBase<P> {\n type: \"number\";\n defaultValue?: number;\n}\n\ntype NumberType<P> =\n | \"number\"\n | ((\n | {\n control?: \"default\";\n min?: number | ContextDependentConfig<P, number>;\n max?: number | ContextDependentConfig<P, number>;\n }\n | {\n control: \"slider\";\n min: number | ContextDependentConfig<P, number>;\n max: number | ContextDependentConfig<P, number>;\n step?: number | ContextDependentConfig<P, number>;\n }\n ) &\n NumberTypeBase<P>);\n\ntype JSONLikeType<P> =\n | \"object\"\n | ({\n type: \"object\";\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ninterface ChoiceTypeBase<P> extends PropTypeBase<P> {\n type: \"choice\";\n options: string[] | ContextDependentConfig<P, string[]>;\n}\n\ntype ChoiceType<P> = (\n | {\n defaultValue?: string;\n multiSelect?: false;\n }\n | {\n defaultValue?: string[];\n multiSelect: true;\n }\n) &\n ChoiceTypeBase<P>;\n\ninterface CustomControlProps<P> {\n componentProps: P;\n /**\n * `contextData` can be `null` if the prop controls are rendering before\n * the component instance itself (it will re-render once the component\n * calls `setControlContextData`)\n */\n contextData: InferDataType<P> | null;\n value: any;\n /**\n * Sets the value to be passed to the prop. Expects a JSON-compatible value.\n */\n updateValue: (newVal: any) => void;\n}\nexport type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;\n\nexport type CustomType<P> =\n | CustomControl<P>\n | ({\n type: \"custom\";\n control: CustomControl<P>;\n /**\n * Expects a JSON-compatible value\n */\n defaultValue?: any;\n } & PropTypeBase<P>);\n\ntype SlotType =\n | \"slot\"\n | {\n type: \"slot\";\n /**\n * The unique names of all code components that can be placed in the slot\n */\n allowedComponents?: string[];\n defaultValue?: PlasmicElement | PlasmicElement[];\n /**\n * Whether the \"empty slot\" placeholder should be hidden in the canvas.\n */\n hidePlaceholder?: boolean;\n };\n\ntype ImageUrlType<P> =\n | \"imageUrl\"\n | ({\n type: \"imageUrl\";\n defaultValue?: string;\n } & PropTypeBase<P>);\n\nexport type PrimitiveType<P = any> = Extract<\n StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P>,\n String\n>;\n\ntype ControlTypeBase =\n | {\n editOnly?: false;\n }\n | {\n editOnly: true;\n /**\n * The prop where the values should be mapped to\n */\n uncontrolledProp?: string;\n };\n\ntype SupportControlled<T> =\n | Extract<T, String | CustomControl<any>>\n | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);\n\nexport type PropType<P> =\n | SupportControlled<\n | StringType<P>\n | BooleanType<P>\n | NumberType<P>\n | JSONLikeType<P>\n | ChoiceType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\n | SlotType;\n\ntype RestrictPropType<T, P> = T extends string\n ? SupportControlled<\n | StringType<P>\n | ChoiceType<P>\n | JSONLikeType<P>\n | ImageUrlType<P>\n | CustomType<P>\n >\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\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 interface ComponentMeta<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 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 keyof Partial<P>]: RestrictPropType<P[prop], P> } & {\n [prop: string]: PropType<P>;\n };\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\nexport interface ComponentRegistration {\n component: React.ComponentType<any>;\n meta: ComponentMeta<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: ComponentMeta<React.ComponentProps<T>>\n) {\n root.__PlasmicComponentRegistry.push({ component, meta });\n}\n"],"names":[],"mappings":"AAMA,IAAM,IAAI,GAAG,UAAiB,CAAC;AAiR/B,IAAI,IAAI,CAAC,0BAA0B,IAAI,IAAI,EAAE;IAC3C,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC;CACtC;SAEuB,iBAAiB,CACvC,SAAY,EACZ,IAA4C;IAE5C,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,SAAS,WAAA,EAAE,IAAI,MAAA,EAAE,CAAC,CAAC;AAC5D;;;;"}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { CodeComponentElement, CSSProperties, PlasmicElement } from "./element-types";
|
|
3
|
-
|
|
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> {
|
|
4
23
|
displayName?: string;
|
|
5
24
|
description?: string;
|
|
6
|
-
hidden?:
|
|
7
|
-
}
|
|
25
|
+
hidden?: ContextDependentConfig<P, boolean>;
|
|
26
|
+
}
|
|
8
27
|
declare type StringType<P> = "string" | ({
|
|
9
28
|
type: "string";
|
|
10
29
|
defaultValue?: string;
|
|
@@ -13,10 +32,20 @@ declare type BooleanType<P> = "boolean" | ({
|
|
|
13
32
|
type: "boolean";
|
|
14
33
|
defaultValue?: boolean;
|
|
15
34
|
} & PropTypeBase<P>);
|
|
16
|
-
|
|
35
|
+
interface NumberTypeBase<P> extends PropTypeBase<P> {
|
|
17
36
|
type: "number";
|
|
18
37
|
defaultValue?: number;
|
|
19
|
-
}
|
|
38
|
+
}
|
|
39
|
+
declare type NumberType<P> = "number" | (({
|
|
40
|
+
control?: "default";
|
|
41
|
+
min?: number | ContextDependentConfig<P, number>;
|
|
42
|
+
max?: number | ContextDependentConfig<P, number>;
|
|
43
|
+
} | {
|
|
44
|
+
control: "slider";
|
|
45
|
+
min: number | ContextDependentConfig<P, number>;
|
|
46
|
+
max: number | ContextDependentConfig<P, number>;
|
|
47
|
+
step?: number | ContextDependentConfig<P, number>;
|
|
48
|
+
}) & NumberTypeBase<P>);
|
|
20
49
|
declare type JSONLikeType<P> = "object" | ({
|
|
21
50
|
type: "object";
|
|
22
51
|
/**
|
|
@@ -24,11 +53,40 @@ declare type JSONLikeType<P> = "object" | ({
|
|
|
24
53
|
*/
|
|
25
54
|
defaultValue?: any;
|
|
26
55
|
} & PropTypeBase<P>);
|
|
27
|
-
|
|
56
|
+
interface ChoiceTypeBase<P> extends PropTypeBase<P> {
|
|
28
57
|
type: "choice";
|
|
29
|
-
options: string[] |
|
|
58
|
+
options: string[] | ContextDependentConfig<P, string[]>;
|
|
59
|
+
}
|
|
60
|
+
declare type ChoiceType<P> = ({
|
|
30
61
|
defaultValue?: string;
|
|
31
|
-
|
|
62
|
+
multiSelect?: false;
|
|
63
|
+
} | {
|
|
64
|
+
defaultValue?: string[];
|
|
65
|
+
multiSelect: true;
|
|
66
|
+
}) & ChoiceTypeBase<P>;
|
|
67
|
+
interface CustomControlProps<P> {
|
|
68
|
+
componentProps: P;
|
|
69
|
+
/**
|
|
70
|
+
* `contextData` can be `null` if the prop controls are rendering before
|
|
71
|
+
* the component instance itself (it will re-render once the component
|
|
72
|
+
* calls `setControlContextData`)
|
|
73
|
+
*/
|
|
74
|
+
contextData: InferDataType<P> | null;
|
|
75
|
+
value: any;
|
|
76
|
+
/**
|
|
77
|
+
* Sets the value to be passed to the prop. Expects a JSON-compatible value.
|
|
78
|
+
*/
|
|
79
|
+
updateValue: (newVal: any) => void;
|
|
80
|
+
}
|
|
81
|
+
export declare type CustomControl<P> = React.ComponentType<CustomControlProps<P>>;
|
|
82
|
+
export declare type CustomType<P> = CustomControl<P> | ({
|
|
83
|
+
type: "custom";
|
|
84
|
+
control: CustomControl<P>;
|
|
85
|
+
/**
|
|
86
|
+
* Expects a JSON-compatible value
|
|
87
|
+
*/
|
|
88
|
+
defaultValue?: any;
|
|
89
|
+
} & PropTypeBase<P>);
|
|
32
90
|
declare type SlotType = "slot" | {
|
|
33
91
|
type: "slot";
|
|
34
92
|
/**
|
|
@@ -36,6 +94,10 @@ declare type SlotType = "slot" | {
|
|
|
36
94
|
*/
|
|
37
95
|
allowedComponents?: string[];
|
|
38
96
|
defaultValue?: PlasmicElement | PlasmicElement[];
|
|
97
|
+
/**
|
|
98
|
+
* Whether the "empty slot" placeholder should be hidden in the canvas.
|
|
99
|
+
*/
|
|
100
|
+
hidePlaceholder?: boolean;
|
|
39
101
|
};
|
|
40
102
|
declare type ImageUrlType<P> = "imageUrl" | ({
|
|
41
103
|
type: "imageUrl";
|
|
@@ -51,9 +113,9 @@ declare type ControlTypeBase = {
|
|
|
51
113
|
*/
|
|
52
114
|
uncontrolledProp?: string;
|
|
53
115
|
};
|
|
54
|
-
declare type SupportControlled<T> = Extract<T, String
|
|
55
|
-
export declare type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | ImageUrlType<P>> | SlotType;
|
|
56
|
-
declare type RestrictPropType<T, P> = T extends string ? SupportControlled<StringType<P> | ChoiceType<P> | JSONLikeType<P> | ImageUrlType<P>> : T extends boolean ? SupportControlled<BooleanType<P> | JSONLikeType<P>> : T extends number ? SupportControlled<NumberType<P> | JSONLikeType<P>> : PropType<P>;
|
|
116
|
+
declare type SupportControlled<T> = Extract<T, String | CustomControl<any>> | (Exclude<T, String | CustomControl<any>> & ControlTypeBase);
|
|
117
|
+
export declare type PropType<P> = SupportControlled<StringType<P> | BooleanType<P> | NumberType<P> | JSONLikeType<P> | ChoiceType<P> | ImageUrlType<P> | CustomType<P>> | SlotType;
|
|
118
|
+
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>;
|
|
57
119
|
interface ComponentTemplate<P> extends Omit<CodeComponentElement<P>, "type" | "name"> {
|
|
58
120
|
/**
|
|
59
121
|
* A preview picture for the template.
|