declare var require ; declare var module ; import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider' ; import * as React from 'react' ; import * as ReactDOM from 'react-dom' ; import { Provider } from 'react-redux' ; import * as Redux from 'redux' ; import { VERSION } from 'shared/schema/Constants' ; import theme from 'shared/Theme' ; import { fetchAnnouncements } from './actions/Announcement' ; import { renderAndPlay } from './actions/Editor' ; import { questLoading , saveQuest } from './actions/Quest' ; import { setSnackbar } from './actions/Snackbar' ; import { loginUser } from './actions/User' ; import { store } from './Store' ; declare var require ; declare var window ; declare var unescape ; const Typo = require ( 'typo-js' ) ; export type ThunkAction < R , S = { } , E = { } , A extends Redux . Action < any > = Redux . AnyAction > = ( dispatch : Redux . Dispatch < A > , getState : ( ) => S , extraArgument : E ) => R ; declare module 'redux' { export interface Dispatch < A extends Redux . Action < any > = Redux . AnyAction > { < R , E > ( asyncAction ) : R ; } } window . onerror = ( message , source , line ) => { console . error ( message , source , line ) ; store . dispatch ( setSnackbar ( true , 'Error! ' + message ) ) ; return true ; } ; const ReactGA = require ( 'react-ga' ) ; ReactGA . initialize ( 'UA-47408800-7' ) ; let questId = '' ; if ( ! window . location . hash && window . location . search . indexOf ( 'ids' ) !== - 1 ) { try { questId = JSON . parse ( unescape ( window . location . search ) . match ( /\?state=(.*)/ ) [ 1 ] ) . ids [ 0 ] ; window . location . href = '/#' + questId ; } catch ( e ) { ReactGA . event ( { action : 'Failed to parse anticipated Drive open URI' , category : 'Error' , label : window . location . search , } ) ; } } else if ( window . location . hash || window . location . href . endsWith ( '#' ) ) { questId = window . location . hash . slice ( 1 ) ; } if ( questId !== '' ) { store . dispatch ( questLoading ( ) ) ; ReactGA . pageview ( '/quest' ) ; } else { store . dispatch ( fetchAnnouncements ( ) ) ; ReactGA . pageview ( '/' ) ; } if ( window . gapi ) { window . gapi . load ( 'client,drive-share' , ( ) => { store . dispatch ( loginUser ( false , questId ) ) ; } ) ; } window . onbeforeunload = ( ) => { if ( store . getState ( ) . editor . dirty === true ) { return false ; } return null ; } ; window . addEventListener ( 'keydown' , ( event ) => { if ( event . ctrlKey || event . metaKey ) { const state = store . getState ( ) ; switch ( String . fromCharCode ( event . which ) . toLowerCase ( ) ) { case 's' : event . preventDefault ( ) ; if ( state . editor . dirty ) { store . dispatch ( saveQuest ( state . quest ) ) ; } break ; case '\n' : case '\r' : if ( state . quest . mdRealtime ) { store . dispatch ( renderAndPlay ( state . quest , state . quest . mdRealtime . getText ( ) , state . editor . line . number , state . editor . worker ) ) ; } break ; default : break ; } } } ) ; window . onOlarkLoad = ( ) => { window . olark ( 'api.chat.onBeginConversation' , ( ) => { window . olark ( 'api.chat.sendNotificationToOperator' , { body : 'Quest name: ' + store . getState ( ) . quest . title , } ) ; } ) ; } ; ( ( ) => { const affPath = '/dictionaries/en_US_aff.txt' ; const dicPath = '/dictionaries/en_US_dic.txt' ; setTimeout ( ( ) => { $ . get ( dicPath , ( dicData ) => { $ . get ( affPath , ( affData ) => { window . dictionary = new Typo ( 'en_US' , affData , dicData ) ; } ) ; } ) ; } , 1000 ) ; setInterval ( ( ) => { $ . ajax ( { dataType : 'json' , success : ( data ) => { if ( data && data . version ) { const newVersion = data . version . split ( '.' ) . map ( Number ) ; const oldVersion = VERSION . split ( '.' ) . map ( Number ) ; if ( newVersion [ 0 ] > oldVersion [ 0 ] || newVersion [ 1 ] > oldVersion [ 1 ] || newVersion [ 2 ] > oldVersion [ 2 ] ) { store . dispatch ( setSnackbar ( true , 'There\'s a new version of the Quest Creator available!' , ( event ) => { location . reload ( ) ; } , 'reload' , true ) ) ; } } } , url : 'https://raw.githubusercontent.com/ExpeditionRPG/expedition/master/services/quests/package.json' , xhrFields : { withCredentials : false } , } ) ; } , 12 * 60 * 60 * 1000 ) ; try { document . cookie = 'cookietest=1' ; const ret = document . cookie . indexOf ( 'cookietest=' ) !== - 1 ; document . cookie = 'cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT' ; if ( ! ret ) { throw new Error ( 'Cookies disabled' ) ; } } catch ( err ) { setTimeout ( ( ) => { store . dispatch ( setSnackbar ( true , 'Please enable cookies for the Quest Creator to function properly.' , ( event ) => { store . dispatch ( setSnackbar ( false ) ) ; } , 'X' , true ) ) ; } , 0 ) ; } } ) ( ) ; $ . ajaxSetup ( { xhrFields : { withCredentials : true , } , } ) ; const setupHotReload = ( ) => { if ( module . hot ) { module . hot . accept ( ) ; module . hot . accept ( './components/Main' , ( ) => { setTimeout ( ( ) => { render ( ) ; } ) ; } ) ; } } ; const render = ( ) => { const MainContainer = require ( './components/MainContainer' ) . default ; const base = document . getElementById ( 'react-app' ) ; if ( ! base ) { throw new Error ( 'Could not find react-app element' ) ; } ReactDOM . unmountComponentAtNode ( base ) ; ReactDOM . render ( < MuiThemeProvider theme = { theme } > < Provider store = { store } > < MainContainer /> < /Provider> < /MuiThemeProvider>, base); } ; setupHotReload ( ) ; render ( ) ;