{"version":3,"sources":["../../../src/client/ui/area.tsx"],"names":["Fragment","jsx","jsxs","useEffect","PilotRoute","PilotRenderer","usePilot","importPage","pageRoutes","PilotArea","props","autoLoad","children","config","defaultPath","name","persistPlaceholder","Placeholder","renderContent","renderPlaceholder","tag","logTag","pilot","paths","route","page","declaredRoutes","child","path"],"mappings":"AAiGE,mBAAAA,EAGE,OAAAC,EAHF,QAAAC,MAAA,oBA7FF,OAA0C,aAAAC,MAAiB,QAC3D,OAAS,cAAAC,MAAkB,gBAC3B,OAAS,iBAAAC,MAAqB,aAE9B,OAAS,YAAAC,MAAgB,oBACzB,OAAS,cAAAC,EAAY,cAAAC,MAAkB,yBAchC,MAAMC,EAAgDC,GAA0B,CACtF,KAAM,CACL,SAAAC,EAAW,GACX,SAAAC,EACA,OAAAC,EACA,YAAAC,EAAc,IACd,KAAAC,EACA,mBAAAC,EACA,YAAAC,EACA,cAAAC,EAAgB,SAChB,kBAAAC,EAAoB,SACpB,IAAAC,CACD,EAAIV,EACEW,EAASD,EAAM,IAAIA,IAAQ,GAG3BE,EAAQhB,EAAS,CACtB,GAAIO,GAAU,CAAC,EACf,GAAIE,IAAQF,GAAA,YAAAA,EAAQ,GACrB,CAAC,EAED,OAAAV,EAAU,IAAM,CAEf,GAAI,CAACQ,EACJ,OAAOW,EAAM,IAAI,QAAS,YAAYD,uBAA4B,GAIjE,SAAY,CACb,IAAIE,EAA6B,CAAC,EAIlC,GAAI,CAACR,EAAM,CACV,UAAWS,KAAShB,EAAY,CAC/B,MAAMiB,EAAO,MAAMlB,EAAWiB,EAAM,IAAI,EACxCD,EAAM,KAAK,CACV,UAAWE,EAAK,QAChB,SAAUD,EAAM,aAAeC,EAAKD,EAAM,cAAgB,OAC1D,KAAMA,EAAM,IACb,CAAC,CACF,CACAF,EAAM,IAAI,QAAS,YAAYD,eAAoBE,EAAM,sCAAsC,CAChG,CAGA,IAAIG,EAAsC,CAAC,EACvC,MAAM,QAAQd,CAAQ,EACzBc,EAAiBd,EAAS,OAAQe,GAAUA,EAAM,OAASvB,CAAU,EAAE,IAAKuB,GAAUA,EAAM,KAAK,GACvFf,GAAA,YAAAA,EAAU,QAASR,IAC7BsB,EAAiB,CAACd,EAAS,KAAK,GAG7Bc,EAAe,SAClBH,EAAQA,EAAM,OAAOG,CAAc,EACnCJ,EAAM,IAAI,QAAS,YAAYD,eAAoBK,EAAe,gCAAgC,GAGnG,UAAWE,KAAQL,EAClBD,EAAM,SAASM,CAAI,EAIpBN,EAAM,IACL,QACA,YAAYD,MAAaP,EAAc,4BAA4BA,KAAiB,4BACrF,EACIA,GACHQ,EAAM,IAAIR,CAAW,CAEvB,GAAG,CACJ,EAAG,CAACH,CAAQ,CAAC,EAGZT,EAAAF,EAAA,CACE,UAAAY,EAEAX,EAACI,EAAA,CACA,KAAMU,EACN,mBAAoBC,EACpB,YAAaC,EACb,cAAeC,EACf,kBAAmBC,EACnB,IAAKC,EACN,GAEF,CAEF","sourcesContent":["/**\n * © 2022 WavePlay <dev@waveplay.com>\n */\n'use client'\nimport { FunctionComponent, ReactElement, useEffect } from 'react'\nimport { PilotRoute } from '../core/pilot'\nimport { PilotRenderer } from './renderer'\nimport type { PilotConfig, PilotRouteOptions, PilotStateProps } from '../types'\nimport { usePilot } from '../core/use-pilot'\nimport { importPage, pageRoutes } from '../../_generated/pages'\n\ninterface PilotAreaProps {\n\tautoLoad?: boolean\n\tchildren?: any\n\tconfig?: PilotConfig\n\tdefaultPath?: string | null\n\tname?: string\n\tpersistPlaceholder?: boolean\n\tPlaceholder?: (visible: boolean) => ReactElement<PilotStateProps>\n\trenderContent?: 'always' | 'first-load' | 'never'\n\trenderPlaceholder?: 'always' | 'first-load' | 'never'\n\ttag?: string\n}\nexport const PilotArea: FunctionComponent<PilotAreaProps> = (props: PilotAreaProps) => {\n\tconst {\n\t\tautoLoad = true,\n\t\tchildren,\n\t\tconfig,\n\t\tdefaultPath = '/',\n\t\tname,\n\t\tpersistPlaceholder,\n\t\tPlaceholder,\n\t\trenderContent = 'always',\n\t\trenderPlaceholder = 'always',\n\t\ttag\n\t} = props\n\tconst logTag = tag ? `#${tag}` : ''\n\n\t// Get pilot instance\n\tconst pilot = usePilot({\n\t\t...(config || {}),\n\t\tid: name || config?.id\n\t})\n\n\tuseEffect(() => {\n\t\t// Skip if autoLoad is disabled\n\t\tif (!autoLoad) {\n\t\t\treturn pilot.log('debug', `PilotArea${logTag}: Skipped loading...`)\n\t\t}\n\n\t\t// Register routes and load the default page\n\t\t;(async () => {\n\t\t\tlet paths: PilotRouteOptions[] = []\n\n\t\t\t// Automatically import all pages generated by the `pilot build` command\n\t\t\t// Only do this for PilotArea instances without a name so named areas can be used independently\n\t\t\tif (!name) {\n\t\t\t\tfor (const route of pageRoutes) {\n\t\t\t\t\tconst page = await importPage(route.path)\n\t\t\t\t\tpaths.push({\n\t\t\t\t\t\tComponent: page.default,\n\t\t\t\t\t\tgetProps: route.getPropsType ? page[route.getPropsType] : undefined,\n\t\t\t\t\t\tpath: route.path\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tpilot.log('debug', `PilotArea${logTag}: Imported ${paths.length} automatically generated pages`)\n\t\t\t}\n\n\t\t\t// Add all routes defined by the user using <PilotRoute> components in this area\n\t\t\tlet declaredRoutes: PilotRouteOptions[] = []\n\t\t\tif (Array.isArray(children)) {\n\t\t\t\tdeclaredRoutes = children.filter((child) => child.type === PilotRoute).map((child) => child.props)\n\t\t\t} else if (children?.type === PilotRoute) {\n\t\t\t\tdeclaredRoutes = [children.props]\n\t\t\t}\n\n\t\t\tif (declaredRoutes.length) {\n\t\t\t\tpaths = paths.concat(declaredRoutes)\n\t\t\t\tpilot.log('debug', `PilotArea${logTag}: Imported ${declaredRoutes.length} manually declared pages`)\n\t\t\t}\n\n\t\t\tfor (const path of paths) {\n\t\t\t\tpilot.addRoute(path)\n\t\t\t}\n\n\t\t\t// Automatically load the default path (unless set to null)\n\t\t\tpilot.log(\n\t\t\t\t'debug',\n\t\t\t\t`PilotArea${logTag}: ` + defaultPath ? `Flying to default path: \"${defaultPath}\"` : 'No default route was found'\n\t\t\t)\n\t\t\tif (defaultPath) {\n\t\t\t\tpilot.fly(defaultPath)\n\t\t\t}\n\t\t})()\n\t}, [autoLoad])\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t{\n\t\t\t\t<PilotRenderer\n\t\t\t\t\tname={name}\n\t\t\t\t\tpersistPlaceholder={persistPlaceholder}\n\t\t\t\t\tPlaceholder={Placeholder}\n\t\t\t\t\trenderContent={renderContent}\n\t\t\t\t\trenderPlaceholder={renderPlaceholder}\n\t\t\t\t\ttag={tag}\n\t\t\t\t/>\n\t\t\t}\n\t\t</>\n\t)\n}\n"]}