1
|
{"version":3,"sources":["webpack:///./src/state/reducer.ts","webpack:///./src/state/StateProvider.tsx","webpack:///./src/state/store.ts","webpack:///./src/state/context.ts","webpack:///./src/state/actions.ts","webpack:///./src/logger.ts","webpack:///./src/RenderWorker/index.ts","webpack:///./src/RenderWorker/worker.ts"],"names":["reducer","state","action","type","actionTypes","loading","payload","id","update","board","updating","name","downloading","mode","solo","layerVisibility","otherIds","layers","map","ly","filter","lyId","nextVisibilty","every","reduce","result","savedBoards","prevLayerVisibility","prevVisibility","updatedBoard","b","indexOf","push","INITIAL_STATE","error","nextState","request","StateProvider","props","_dispatch","worker","dispatch","contextValue","useReducer","useRef","useCallback","log","debug","actions","current","postMessage","url","URLSearchParams","window","location","search","slice","get","saveAs","file","useEffect","RenderWorker","onmessage","event","data","terminate","Provider","value","children","StateContext","React","createContext","useAppState","useContext","CREATE_BOARD","CREATE_BOARD_FROM_URL","GET_BOARD","GET_BOARD_PACKAGE","UPDATE_BOARD","DELETE_BOARD","DELETE_ALL_BOARDS","SET_MODE","TOGGLE_VISIBILITY","BOARD_RENDERED","BOARD_UPDATED","BOARD_DELETED","BOARD_PACKAGED","ALL_BOARDS_DELETED","WORKER_INITIALIZED","WORKER_ERRORED","DISMISS_ERROR","createBoard","files","createBoardFromUrl","getBoard","updateBoard","deleteBoard","deleteAllBoards","getBoardPackage","setMode","toggleVisibility","dismissError","minLevel","STORAGE_KEY","DEFAULT_LEVEL","LEVELS","logger","createLogHandler","info","warn","level","localStorage","maybeLevel","getItem","console","readLogLevel","msg","meta","module","exports","Worker"],"mappings":"4mBAIe,SAASA,EAAQC,EAAcC,GAC5C,OAAQA,EAAOC,MACb,KAAKC,IACL,KAAKA,IACH,YAAWH,EAAX,CAAkBI,SAAS,IAG7B,KAAKD,IACL,KAAKA,IACL,KAAKA,IACH,YAAWH,EAAX,CAAkBI,SAAS,IAG7B,KAAKD,IAA0B,MACRF,EAAOI,QAArBC,EADsB,EACtBA,GAAIC,EADkB,EAClBA,OACX,OA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IAA0B","file":"5.13330638c51749a04737.js","sourcesContent":["import * as actionTypes from './actions'\nimport {INITIAL_STATE} from './context'\nimport {Action, State} from './types'\n\nexport default function reducer(state: State, action: Action): State {\n switch (action.type) {\n case actionTypes.CREATE_BOARD:\n case actionTypes.CREATE_BOARD_FROM_URL: {\n return {...state, loading: true}\n }\n\n case actionTypes.GET_BOARD:\n case actionTypes.DELETE_BOARD:\n case actionTypes.DELETE_ALL_BOARDS: {\n return {...state, loading: true}\n }\n\n case actionTypes.UPDATE_BOARD: {\n const {id, update} = action.payload\n if (!state.board || state.board.id !== id) return state\n\n return {\n ...state,\n updating: true,\n board: {\n ...state.board,\n name: update.name || state.board.name,\n },\n }\n }\n\n case actionTypes.GET_BOARD_PACKAGE: {\n return {...state, downloading: true}\n }\n\n case actionTypes.SET_MODE: {\n return {...state, mode: action.payload}\n }\n\n case actionTypes.TOGGLE_VISIBILITY: {\n const {id, solo} = action.payload\n const {board} = state\n let layerVisibility = {\n ...state.layerVisibility,\n [id]: solo || !state.layerVisibility[id],\n }\n\n if (solo) {\n const layers = board ? board.layers : []\n const otherIds = layers.map(ly => ly.id).filter(lyId => lyId !== id)\n const nextVisibilty = otherIds.every(lyId => !layerVisibility[lyId])\n\n layerVisibility = otherIds.reduce(\n (result, id) => ({...result, [id]: nextVisibilty}),\n layerVisibility\n )\n }\n\n return {...state, layerVisibility}\n }\n\n case actionTypes.WORKER_INITIALIZED: {\n return {...state, savedBoards: action.payload}\n }\n\n case actionTypes.BOARD_RENDERED: {\n const {mode, layerVisibility: prevLayerVisibility} = state\n const board = action.payload\n const layerVisibility = board.layers.reduce((result, ly) => {\n const prevVisibility = prevLayerVisibility[ly.id]\n return {\n ...result,\n [ly.id]: prevVisibility != null ? prevVisibility : true,\n }\n }, {})\n\n return {\n ...state,\n board,\n layerVisibility,\n mode: mode || 'top',\n loading: false,\n updating: false,\n }\n }\n\n case actionTypes.BOARD_UPDATED: {\n const updatedBoard = action.payload\n const savedBoards = state.savedBoards.map(b =>\n b.id === updatedBoard.id ? updatedBoard : b\n )\n\n if (savedBoards.indexOf(updatedBoard) < 0) savedBoards.push(updatedBoard)\n\n return {...state, savedBoards}\n }\n\n case actionTypes.BOARD_DELETED: {\n const id = action.payload\n const savedBoards = state.savedBoards.filter(b => b.id !== id)\n let {board, mode} = state\n\n if (board && board.id === id) {\n board = null\n mode = null\n }\n\n return {...state, mode, board, savedBoards, loading: false}\n }\n\n case actionTypes.BOARD_PACKAGED: {\n return {...state, downloading: false}\n }\n\n case actionTypes.ALL_BOARDS_DELETED: {\n return INITIAL_STATE\n }\n\n case actionTypes.DISMISS_ERROR: {\n return {...state, error: null}\n }\n\n case actionTypes.WORKER_ERRORED: {\n const nextState = {...state, error: action.payload.error}\n\n switch (action.payload.request.type) {\n case actionTypes.CREATE_BOARD:\n case actionTypes.CREATE_BOARD_FROM_URL:\n case actionTypes.DELETE_BOARD:\n case actionTypes.DELETE_ALL_BOARDS:\n return {...nextState, loading: false}\n\n case actionTypes.UPDATE_BOARD:\n return {...nextState, updating: false}\n\n case actionTypes.GET_BOARD_PACKAGE:\n return {...nextState, downloading: false}\n }\n\n return nextState\n }\n }\n\n return state\n}\n","import React from 'react'\n\nimport {useStore} from './store'\nimport {StateContext} from './context'\n\nexport type StateProviderProps = {children: React.ReactNode}\n\nexport default function StateProvider(props: StateProviderProps): JSX.Element {\n const contextValue = useStore()\n\n return (\n <StateContext.Provider value={contextValue}>\n {props.children}\n </StateContext.Provider>\n )\n}\n","// application store and side-effects\nimport {useReducer, useCallback, useRef, useEffect} from 'react'\nimport {saveAs} from 'file-saver'\n\nimport log from '../logger'\nimport RenderWorker, {WorkerMessageEvent} from '../RenderWorker'\nimport * as actions from './actions'\nimport {INITIAL_STATE} from './context'\nimport reducer from './reducer'\nimport {ContextProps, Action} from './types'\n\nexport function useStore(): ContextProps {\n const [state, _dispatch] = useReducer(reducer, INITIAL_STATE)\n const worker = useRef<RenderWorker | null>(null)\n\n // dispatch with side-effects\n const dispatch = useCallback(\n (action: Action) => {\n log.debug('dispatch', action)\n _dispatch(action)\n\n switch (action.type) {\n case actions.CREATE_BOARD:\n case actions.CREATE_BOARD_FROM_URL:\n case actions.GET_BOARD:\n case actions.GET_BOARD_PACKAGE:\n case actions.UPDATE_BOARD:\n case actions.DELETE_BOARD:\n case actions.DELETE_ALL_BOARDS: {\n log.debug('sending action to RenderWorker', action.type)\n worker.current && worker.current.postMessage(action)\n break\n }\n\n case actions.WORKER_INITIALIZED: {\n const query = new URLSearchParams(window.location.search.slice(1))\n const url = query.get('boardUrl')\n\n if (url) dispatch(actions.createBoardFromUrl(url))\n break\n }\n\n case actions.BOARD_PACKAGED: {\n saveAs(action.payload.file, `${action.payload.name}.zip`)\n break\n }\n }\n },\n [log]\n )\n\n useEffect(() => {\n worker.current = new RenderWorker()\n worker.current.onmessage = (event: WorkerMessageEvent) => {\n log.debug('action recieved from RenderWorker', event.data.type)\n dispatch(event.data)\n }\n\n return () => {\n worker.current && worker.current.terminate()\n }\n }, [])\n\n return {...state, dispatch}\n}\n","import React, {useContext} from 'react'\n\nimport {State, ContextProps} from './types'\n\nexport const INITIAL_STATE: State = {\n board: null,\n savedBoards: [],\n mode: null,\n loading: false,\n updating: false,\n downloading: false,\n layerVisibility: {},\n error: null,\n}\n\nexport const StateContext = React.createContext<ContextProps>({\n ...INITIAL_STATE,\n dispatch: () => {},\n})\n\nexport const useAppState = (): ContextProps => useContext(StateContext)\n","import {Board, BoardSummary, BoardUpdate, BoardRender, Mode} from '../types'\nimport {Action} from './types'\n\nexport const CREATE_BOARD = 'CREATE_BOARD'\nexport const CREATE_BOARD_FROM_URL = 'CREATE_BOARD_FROM_URL'\nexport const GET_BOARD = 'GET_BOARD'\nexport const GET_BOARD_PACKAGE = 'GET_BOARD_PACKAGE'\nexport const UPDATE_BOARD = 'UPDATE_BOARD'\nexport const DELETE_BOARD = 'DELETE_BOARD'\nexport const DELETE_ALL_BOARDS = 'DELETE_ALL_BOARDS'\nexport const SET_MODE = 'SET_MODE'\nexport const TOGGLE_VISIBILITY = 'TOGGLE_VISIBILITY'\nexport const BOARD_RENDERED = 'BOARD_RENDERED'\nexport const BOARD_UPDATED = 'BOARD_UPDATED'\nexport const BOARD_DELETED = 'BOARD_DELETED'\nexport const BOARD_PACKAGED = 'BOARD_PACKAGED'\nexport const ALL_BOARDS_DELETED = 'ALL_BOARDS_DELETED'\nexport const WORKER_INITIALIZED = 'WORKER_INITIALIZED'\nexport const WORKER_ERRORED = 'WORKER_ERRORED'\nexport const DISMISS_ERROR = 'DISMISS_ERROR'\n\nexport const createBoard = (files: Array<File>): Action => ({\n type: CREATE_BOARD,\n payload: files,\n})\n\nexport const createBoardFromUrl = (url: string): Action => ({\n type: CREATE_BOARD_FROM_URL,\n payload: url,\n})\n\nexport const getBoard = (id: string): Action => ({\n type: GET_BOARD,\n payload: id,\n})\n\nexport const updateBoard = (id: string, update: BoardUpdate): Action => ({\n type: UPDATE_BOARD,\n payload: {id, update},\n})\n\nexport const deleteBoard = (id: string): Action => ({\n type: DELETE_BOARD,\n payload: id,\n})\n\nexport const deleteAllBoards = (): Action => ({\n type: DELETE_ALL_BOARDS,\n})\n\nexport const getBoardPackage = (id: string): Action => ({\n type: GET_BOARD_PACKAGE,\n payload: id,\n})\n\nexport const setMode = (mode: Mode): Action => ({\n type: SET_MODE,\n payload: mode,\n})\n\nexport const toggleVisibility = (id: string, solo: boolean): Action => ({\n type: TOGGLE_VISIBILITY,\n payload: {id, solo},\n})\n\nexport const boardRendered = (render: BoardRender): Action => ({\n type: BOARD_RENDERED,\n payload: render,\n})\n\nexport const boardUpdated = (board: Board): Action => ({\n type: BOARD_UPDATED,\n payload: board,\n})\n\nexport const boardDeleted = (id: string): Action => ({\n type: BOARD_DELETED,\n payload: id,\n})\n\nexport const boardPackaged = (name: string, file: Blob): Action => ({\n type: BOARD_PACKAGED,\n payload: {name, file},\n})\n\nexport const allBoardsDeleted = (): Action => ({\n type: ALL_BOARDS_DELETED,\n})\n\nexport const workerInitialized = (boards: Array<BoardSummary>): Action => ({\n type: WORKER_INITIALIZED,\n payload: boards,\n})\n\nexport const workerErrored = (request: Action, error: Error): Action => ({\n type: WORKER_ERRORED,\n payload: {\n request,\n error: {name: error.name, message: error.message, error: error.toString()},\n },\n})\n\nexport const dismissError = (): Action => ({\n type: DISMISS_ERROR,\n})\n","import {LogLevel, Logger, LogHandler} from './types'\n\nconst STORAGE_KEY = 'logLevel'\nconst DEFAULT_LEVEL = process.env.NODE_ENV !== 'production' ? 'debug' : 'warn'\nconst LEVELS: Array<LogLevel> = ['debug', 'info', 'warn', 'error']\n\nlet minLevel: LogLevel\n\nconst logger: Logger = {\n debug: createLogHandler('debug'),\n info: createLogHandler('info'),\n warn: createLogHandler('warn'),\n error: createLogHandler('error'),\n}\n\nexport default logger\n\nfunction createLogHandler(level: LogLevel): LogHandler {\n if (!minLevel) minLevel = readLogLevel()\n\n return LEVELS.indexOf(level) >= LEVELS.indexOf(minLevel)\n ? (msg, ...meta) => console[level](`${level}: ${msg}`, ...meta)\n : () => {}\n}\n\nfunction readLogLevel(): LogLevel {\n if (typeof window !== 'undefined' && window.localStorage) {\n try {\n const maybeLevel = window.localStorage.getItem(STORAGE_KEY)\n\n if (\n maybeLevel === 'debug' ||\n maybeLevel === 'info' ||\n maybeLevel === 'warn' ||\n maybeLevel === 'error'\n ) {\n return maybeLevel\n }\n } catch (error) {\n console.error('Could not read logLevel from localStorage', error)\n }\n }\n\n return DEFAULT_LEVEL\n}\n","import RenderWorker from './worker'\n\nexport default RenderWorker\nexport * from './types'\n","module.exports = function() {\n return new Worker(__webpack_public_path__ + \"2860b24d78cee11b8d5e.worker.js\");\n};"],"sourceRoot":""}
|