@nlabs/gothamjs
Version:
Platform
1 lines • 17.2 kB
JavaScript
;(self.webpackChunk_nlabs_gothamjs=self.webpackChunk_nlabs_gothamjs||[]).push([[705],{"./src/actions/GothamActions.ts":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{E:function(){return GothamActions}});var _nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__("./node_modules/@nlabs/arkhamjs/lib/Flux/Flux.js"),_nlabs_utils__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__("./node_modules/@nlabs/utils/lib/index.js"),_config_appConfig__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__("./src/config/appConfig.tsx"),_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__("./src/constants/GothamConstants.ts");const GothamActions={init:()=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.INITIALIZE}),loading:(isLoading,content)=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({content:content,isLoading:isLoading,type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.LOADING}),navBack:()=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.NAV_BACK}),navForward:()=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.NAV_FORWARD}),navGoto:(path,params)=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({params:params,path:path,type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.NAV_GOTO}),navReplace:(path,params)=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({params:params,path:path,type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.NAV_REPLACE}),notify:params=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({...params,type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.NOTIFY_OPEN}),notifyClose:()=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.NOTIFY_CLOSE}),setConfig:config=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({config:config,type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.SET_CONFIG}),signOut:()=>_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.SIGN_OUT}),updateTitle:(title,separator)=>{const appTitle=_config_appConfig__WEBPACK_IMPORTED_MODULE_2__.T.get("app.title",""),titleSeparator=separator||_config_appConfig__WEBPACK_IMPORTED_MODULE_2__.T.get("app.titleBarSeparator","::");return(0,_nlabs_utils__WEBPACK_IMPORTED_MODULE_1__.Im)(title)||appTitle===title?document.title=appTitle:document.title=[title,titleSeparator,appTitle].join(" "),_nlabs_arkhamjs__WEBPACK_IMPORTED_MODULE_0__.Y.dispatch({title:title,type:_constants_GothamConstants__WEBPACK_IMPORTED_MODULE_3__.W.UPDATE_TITLE})}}},"./src/components/Loader/Loader.tsx":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{a:function(){return Loader}});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__("../lex/node_modules/react/jsx-runtime.js");const Loader=({content:content})=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{role:"status",className:"absolute -translate-x-1/2 -translate-y-1/2 top-2/4 left-1/2",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("svg",{"aria-hidden":"true",className:"w-8 h-8 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600",fill:"none",viewBox:"0 0 100 101",xmlns:"http://www.w3.org/2000/svg",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("path",{d:"M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",fill:"currentColor"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("path",{d:"M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",fill:"currentFill"})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:"sr-only",children:content})]});Loader.__docgenInfo={description:"",methods:[],displayName:"Loader",props:{content:{required:!1,tsType:{name:"string"},description:""}}}},"./src/config/appConfig.tsx":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{T:function(){return Config}});var _nlabs_utils__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__("./node_modules/@nlabs/utils/lib/index.js");class Config{static values={};static set(values){return(0,_nlabs_utils__WEBPACK_IMPORTED_MODULE_0__.h1)(this.values,values)}static get(path,defaultValue){const configValues={...this.values,environment:"development"};return(0,_nlabs_utils__WEBPACK_IMPORTED_MODULE_0__.Jt)(configValues,path,defaultValue)}}},"./src/constants/GothamConstants.ts":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{W:function(){return GothamConstants}});class GothamConstants{static ALERT="GOTHAM_ALERT";static CLEAR_EXTERNAL="GOTHAM_APP_CLEAR_EXTERNAL";static GET_EXTERNAL="GOTHAM_APP_GET_EXTERNAL";static INITIALIZE="GOTHAM_APP_INITIALIZE";static LOADING="GOTHAM_APP_LOADING";static NAV_BACK="GOTHAM_APP_NAV_BACK";static NAV_FORWARD="GOTHAM_APP_NAV_FORWARD";static NAV_GOTO="GOTHAM_APP_NAV_GOTO";static NAV_REPLACE="GOTHAM_APP_NAV_REPLACE";static NOTIFY_OPEN="GOTHAM_APP_NOTIFY_OPEN";static NOTIFY_CLOSE="GOTHAM_APP_NOTIFY_CLOSE";static SET_CONFIG="GOTHAM_APP_SET_CONFIG";static SIGN_OUT="GOTHAM_APP_SIGN_OUT";static TOGGLE_MENU="GOTHAM_APP_TOGGLE_MENU";static TOP_BAR_SOLID="GOTHAM_APP_TOP_BAR_SOLID";static UPDATE_MENU="GOTHAM_APP_UPDATE_MENU";static UPDATE_SESSION="GOTHAM_APP_UPDATE_SESSION";static UPDATE_TITLE="GOTHAM_APP_UPDATE_TITLE"}},"./src/views/Gotham/Gotham.stories.tsx":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{Primary:function(){return Primary},__namedExportsOrder:function(){return __namedExportsOrder},default:function(){return Gotham_stories}});var react=__webpack_require__("../lex/node_modules/react/index.js"),lib=__webpack_require__("./node_modules/@nlabs/arkhamjs-middleware-logger/lib/index.js"),BrowserStorage=__webpack_require__("./node_modules/@nlabs/arkhamjs-storage-browser/lib/BrowserStorage/BrowserStorage.js"),arkhamjs_utils_react_lib=__webpack_require__("./node_modules/@nlabs/arkhamjs-utils-react/lib/index.js"),utils_lib=__webpack_require__("./node_modules/@nlabs/utils/lib/index.js"),es=__webpack_require__("./node_modules/react-i18next/dist/es/index.js"),chunk_QMGIS6GS=__webpack_require__("./node_modules/react-router/dist/development/chunk-QMGIS6GS.mjs"),GothamConstants=__webpack_require__("./src/constants/GothamConstants.ts"),jsx_runtime=__webpack_require__("../lex/node_modules/react/jsx-runtime.js");const GothamRoot=()=>{const navigate=(0,chunk_QMGIS6GS.Zp)();var history;return(0,arkhamjs_utils_react_lib.useFluxListener)(GothamConstants.W.NAV_BACK,(history=navigate,()=>{history.goBack()})),(0,arkhamjs_utils_react_lib.useFluxListener)(GothamConstants.W.NAV_FORWARD,(history=>()=>{history.goForward()})(navigate)),(0,arkhamjs_utils_react_lib.useFluxListener)(GothamConstants.W.NAV_GOTO,(navigate=>data=>{const{params:params,path:path=""}=data;navigate(path,params)})(navigate)),(0,arkhamjs_utils_react_lib.useFluxListener)(GothamConstants.W.NAV_REPLACE,(history=>data=>{const{params:params,path:path=""}=data;history.replace(path,params)})(navigate)),(0,jsx_runtime.jsx)(react.Suspense,{fallback:(0,jsx_runtime.jsx)("div",{children:"Loading..."}),children:(0,jsx_runtime.jsx)(chunk_QMGIS6GS.sv,{})})};GothamRoot.__docgenInfo={description:"",methods:[],displayName:"GothamRoot"};var actions_GothamActions=__webpack_require__("./src/actions/GothamActions.ts"),config_appConfig=__webpack_require__("./src/config/appConfig.tsx");class MarkdownConstants{static CLEAR_EXTERNAL="APP_CLEAR_EXTERNAL";static GET_EXTERNAL="APP_GET_EXTERNAL"}const initialState={config:{},currentTitle:"",external:{}},gothamApp=(type,data,state=initialState)=>{switch(type){case GothamConstants.W.INITIALIZE:return(0,utils_lib.hZ)(state,"external",{});case GothamConstants.W.SET_CONFIG:return(0,utils_lib.hZ)(state,"config",data.config);case GothamConstants.W.UPDATE_TITLE:return(0,utils_lib.hZ)(state,"currentTitle",data.title);case MarkdownConstants.CLEAR_EXTERNAL:return(0,utils_lib.hZ)(state,"external",{});case MarkdownConstants.GET_EXTERNAL:{const{content:content,url:url}=data;return(0,utils_lib.hZ)(state,["external",url],content)}default:return state}};const initialContext={Flux:__webpack_require__("./node_modules/@nlabs/arkhamjs/lib/Flux/Flux.js").Y,isAuth:()=>!0,session:{}},GothamContext=(0,react.createContext)(initialContext);var esm_i18next=__webpack_require__("./node_modules/i18next/dist/esm/i18next.js");const i18n=resources=>{const i18next=(0,esm_i18next.Q_)();return i18next.use(es.r9).init({fallbackNS:"translation",interpolation:{escapeValue:!1,format(value,format){if("array"===format&&(null==value?void 0:value.length)>1){const last=` and ${value.pop()}`;return value.join(", ")+last}return value}},lng:"en",react:{transKeepBasicHtmlNodesFor:["br","h1","h2","h3","i","li","p","strong","u","ul"],transSupportBasicHtmlNodes:!0},resources:resources,returnObjects:!0}),i18next},AuthRoute=({children:children})=>{const location=(0,chunk_QMGIS6GS.zy)(),isAuth=config_appConfig.T.get("isAuth",()=>!1);return console.log({isAuth:isAuth&&isAuth()}),isAuth&&isAuth()?children:(0,jsx_runtime.jsx)(chunk_QMGIS6GS.C5,{to:`/signIn?redirect=${location.pathname}${location.search}`,replace:!0})};AuthRoute.__docgenInfo={description:"",methods:[],displayName:"AuthRoute"};const parseRoutes=(routes=[])=>routes.map(route=>{const{authenticate:authenticate,element:element,props:props,routes:nestedRoutes,...standardRouteProps}=route;let routeElement=element;return console.log({authenticate:authenticate}),authenticate&&(routeElement=(0,jsx_runtime.jsx)(AuthRoute,{children:element})),null!=nestedRoutes&&nestedRoutes.length?{...standardRouteProps,children:parseRoutes(nestedRoutes),element:routeElement}:{...standardRouteProps,element:routeElement}}),defaultGothamConfig={app:{name:"gotham",title:"GothamJS"},baseUrl:"",isAuth:()=>!1,middleware:[],routes:[],storageType:"session",stores:[],theme:{},translations:{translation:{}}},GothamProvider=({children:children,config:appConfig})=>{var _config$app;const flux=(0,arkhamjs_utils_react_lib.useFlux)(),config=(0,utils_lib.h1)(defaultGothamConfig,appConfig),{isAuth:isAuth,middleware:middleware,routes:routes=[],storageType:storageType,stores:stores,translations:translations}=config,name=null==config||null===(_config$app=config.app)||void 0===_config$app?void 0:_config$app.name,[session,setSession]=(0,react.useState)({}),[router,setRouter]=(0,react.useState)();return(0,react.useEffect)(()=>{config_appConfig.T.set(config);const router=(0,chunk_QMGIS6GS.Ys)([{children:parseRoutes(routes),element:(0,jsx_runtime.jsx)(GothamRoot,{})}]);if(setRouter(router),flux){const env=config_appConfig.T.get("environment"),logger=new lib.V({debugLevel:"development"===env?lib.G.DISPATCH:lib.G.DISABLED}),storage=new BrowserStorage.s({type:storageType});flux.init({middleware:[logger,...middleware],name:name,storage:storage,stores:[gothamApp,...stores]}),flux.on(GothamConstants.W.SIGN_OUT,(flux=>async()=>{await flux.clearAppData(),await actions_GothamActions.E.loading(!1),actions_GothamActions.E.navGoto("/signIn")})(flux)),flux.on(GothamConstants.W.UPDATE_SESSION,({session:session})=>{setSession(session)})}},[]),(0,jsx_runtime.jsx)(es.xC,{i18n:i18n(translations),children:(0,jsx_runtime.jsxs)(GothamContext.Provider,{value:{Flux:flux,isAuth:isAuth,session:session},children:[router&&(0,jsx_runtime.jsx)(chunk_QMGIS6GS.pg,{router:router}),children]})})};GothamProvider.__docgenInfo={description:"",methods:[],displayName:"GothamProvider",props:{children:{required:!1,tsType:{name:"ReactNode"},description:""},config:{required:!0,tsType:{name:"GothamConfiguration"},description:""},session:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"unknown"}],raw:"Record<string, unknown>"},description:""}}};var Loader=__webpack_require__("./src/components/Loader/Loader.tsx");const LoaderView=()=>{const[isLoading,setLoading]=(0,react.useState)(!1),[content,setLoaderContent]=(0,react.useState)();return(0,arkhamjs_utils_react_lib.useFluxListener)(GothamConstants.W.LOADING,({content:content,isLoading:isLoading})=>{setLoading(isLoading),setLoaderContent(content)}),isLoading?(0,jsx_runtime.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center",children:(0,jsx_runtime.jsx)(Loader.a,{content:content})}):null};LoaderView.__docgenInfo={description:"",methods:[],displayName:"LoaderView"};const onKeyUp=event=>{9===event.which&&document.documentElement.classList.remove("noFocusOutline")},Gotham=({children:children,config:config={}})=>((0,react.useEffect)(()=>{document.body.addEventListener("keyup",onKeyUp)},[]),(0,jsx_runtime.jsxs)(GothamProvider,{config:config,children:[children,(0,jsx_runtime.jsx)(LoaderView,{})]}));Gotham.__docgenInfo={description:"",methods:[],displayName:"Gotham",props:{children:{required:!1,tsType:{name:"ReactNode"},description:""},classes:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"string"}],raw:"Record<string, string>"},description:""},config:{required:!1,tsType:{name:"GothamConfiguration"},description:"",defaultValue:{value:"{}",computed:!1}},isAuth:{required:!1,tsType:{name:"signature",type:"function",raw:"() => boolean",signature:{arguments:[],return:{name:"boolean"}}},description:""}}};var MarkdownView=__webpack_require__("./src/views/MarkdownView/MarkdownView.tsx");var Gotham_stories={component:Gotham};const Primary={args:{config:{routes:[{element:(0,jsx_runtime.jsx)(MarkdownView.p,{}),path:"/",props:{content:"# Hello\n**Bold text**\n*Italic text*\n- List item"}}]}}},__namedExportsOrder=["Primary"];Primary.parameters={...Primary.parameters,docs:{...Primary.parameters?.docs,source:{originalSource:"{\n args: {\n config: {\n routes: [{\n element: <MarkdownView />,\n path: '/',\n props: {\n content: '# Hello\\n**Bold text**\\n*Italic text*\\n- List item'\n }\n }]\n }\n }\n}",...Primary.parameters?.docs?.source}}}},"./src/views/MarkdownView/MarkdownView.tsx":function(__unused_webpack_module,__webpack_exports__,__webpack_require__){__webpack_require__.d(__webpack_exports__,{p:function(){return MarkdownView}});var react=__webpack_require__("../lex/node_modules/react/index.js"),lib=__webpack_require__("./node_modules/react-markdown/lib/index.js"),rip_hunter_lib=__webpack_require__("./node_modules/@nlabs/rip-hunter/lib/index.js");const parseTemplate=(markdown="",values={})=>markdown.replace(/\{\{(\w+)\}\}/g,(match,key)=>{const value=values[key];return void 0!==value?String(value):match});var jsx_runtime=__webpack_require__("../lex/node_modules/react/jsx-runtime.js");const MarkdownView=({className:className="",content:content,url:url,values:values={}})=>{const[markdown,setMarkdown]=(0,react.useState)("");return(0,react.useEffect)(()=>{(async()=>{try{if(url){const data=await(async url=>{try{return(await(0,rip_hunter_lib.Jt)(url)).data}catch(error){throw new Error(`Failed to fetch JSON from ${url}: ${error.message}`)}})(url);setMarkdown(parseTemplate(data,values))}else content&&setMarkdown(parseTemplate(content,values))}catch(error){console.error("Failed to load markdown content:",error),setMarkdown("Error loading content")}})()},[url,content,values]),(0,jsx_runtime.jsx)("div",{className:`markdown-container ${className}`,style:{backgroundColor:"transparent",height:"100%",overflow:"auto",width:"100%"},children:(0,jsx_runtime.jsx)(lib.oz,{children:markdown})})};MarkdownView.__docgenInfo={description:"",methods:[],displayName:"MarkdownView",props:{className:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},content:{required:!1,tsType:{name:"string"},description:""},url:{required:!1,tsType:{name:"string"},description:""},values:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"unknown"}],raw:"Record<string, unknown>"},description:"",defaultValue:{value:"{}",computed:!1}}}}}}]);