{"version":3,"file":"PageContext.mjs","names":["React","createContext","useReducer","initialState","pageContext","state","dispatch","Dispatch","type","value","Provider","reducer","action","operator","substr","indexOf","prop","newState","Error","PageContextProvider","t0","$","_c","children","t1","t2"],"sources":["../../src/contexts/PageContext.tsx"],"sourcesContent":["import React, { createContext, useReducer } from 'react';\n\nconst initialState: any = {};\n\n/**\n * The Page context, shared amongst the Page\n * and all children. Generally used to share state between\n * Widgets. Call dispatch() to update the state. Currently\n * only supports dispatch types of \"set <state_property>\".\n * Example: dispatch({ type: \"set mySharedProperty\", value: oldSharedProperty + 1 });\n */\nconst pageContext = createContext(\n  {} as { state: any; dispatch: React.Dispatch<{ type: string; value?: any }> }\n);\nconst { Provider } = pageContext;\n\n/**\n * Sets shared state based on an action type and a value.\n * action.type is in the format: <operator> <prop>\n * Currently the only supported action type is \"set <prop>\",\n * which will set state.prop to action.value.\n * @param state The current state\n * @param action A type and value to alter the current state\n * @returns The new state\n */\nconst reducer = (state: any, action: { type: string; value?: any }) => {\n  // Action.type should be in the format: <operator> <prop>. Ex: set sharedId\n  const operator = action.type.substr(0, action.type.indexOf(' '));\n  const prop = action.type.substr(action.type.indexOf(' ') + 1);\n\n  switch (operator) {\n    case 'set':\n      const newState = { ...state, [prop]: action.value };\n      return newState;\n    default:\n      throw new Error('Unknown operator');\n  }\n};\n\n/**\n * A Context component to wrap around a Page. Allows\n * sharing of state amongst sibling Widgets.\n * @returns\n */\nconst PageContextProvider = ({ children }: any) => {\n  const [state, dispatch] = useReducer(reducer, initialState);\n\n  return <Provider value={{ state, dispatch }}>{children}</Provider>;\n};\n\nexport { pageContext, PageContextProvider };\n"],"mappings":";;;AAEA,MAAMG,eAAoB,EAAE;;;;;;;;AAS5B,MAAMC,cAAcH,cAClB,EAAE,CACH;AACD,MAAM,EAAES,aAAaN;;;;;;;;;;AAWrB,MAAMO,WAAWN,OAAYO,WAA0C;CAErE,MAAMC,WAAWD,OAAOJ,KAAKM,OAAO,GAAGF,OAAOJ,KAAKO,QAAQ,IAAI,CAAC;CAChE,MAAMC,OAAOJ,OAAOJ,KAAKM,OAAOF,OAAOJ,KAAKO,QAAQ,IAAI,GAAG,EAAE;AAE7D,SAAQF,UAAR;EACE,KAAK,MAEH,QADiB;GAAE,GAAGR;IAAQW,OAAOJ,OAAOH;GAAO;EAErD,QACE,OAAM,IAAIS,MAAM,mBAAmB;;;;;;;;AASzC,MAAMC,uBAAsBC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,aAAAH;CAC3B,MAAA,CAAAf,OAAAC,YAA0BJ,WAAWS,SAASR,aAAa;CAAC,IAAAqB;AAAA,KAAAH,EAAA,OAAAhB,OAAA;AAEpCmB,OAAA;GAAAnB;GAAAC;GAAmB;AAAAe,IAAA,KAAAhB;AAAAgB,IAAA,KAAAG;OAAAA,MAAAH,EAAA;CAAA,IAAAI;AAAA,KAAAJ,EAAA,OAAAE,YAAAF,EAAA,OAAAG,IAAA;AAApCC,OAAA,sBAAA,cAAC,UAAD,EAAiB,OAAAD,IAA0C,EAApBD,SAAoB;AAAAF,IAAA,KAAAE;AAAAF,IAAA,KAAAG;AAAAH,IAAA,KAAAI;OAAAA,MAAAJ,EAAA;AAAA,QAA3DI"}