@uiw/react-json-view
Version:
JSON viewer for react.
70 lines • 2.47 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import React, { createContext, useContext, useEffect, useReducer } from 'react';
import { useShowTools, ShowTools } from "./store/ShowTools.js";
import { useExpands, Expands } from "./store/Expands.js";
import { useTypes, Types } from "./store/Types.js";
import { useSymbols, Symbols } from "./store/Symbols.js";
import { useSection, Section } from "./store/Section.js";
import { jsx as _jsx } from "react/jsx-runtime";
export var initialState = {
objectSortKeys: false,
indentWidth: 15
};
export var Context = /*#__PURE__*/createContext(initialState);
Context.displayName = 'JVR.Context';
var DispatchContext = /*#__PURE__*/createContext(() => {});
DispatchContext.displayName = 'JVR.DispatchContext';
export function reducer(state, action) {
return _extends({}, state, action);
}
export var useStore = () => {
return useContext(Context);
};
export var useDispatchStore = () => {
return useContext(DispatchContext);
};
export var Provider = _ref => {
var {
children,
initialState: init,
initialTypes
} = _ref;
var [state, dispatch] = useReducer(reducer, Object.assign({}, initialState, init));
var [showTools, showToolsDispatch] = useShowTools();
var [expands, expandsDispatch] = useExpands();
var [types, typesDispatch] = useTypes();
var [symbols, symbolsDispatch] = useSymbols();
var [section, sectionDispatch] = useSection();
useEffect(() => dispatch(_extends({}, init)), [init]);
return /*#__PURE__*/_jsx(Context.Provider, {
value: state,
children: /*#__PURE__*/_jsx(DispatchContext.Provider, {
value: dispatch,
children: /*#__PURE__*/_jsx(ShowTools, {
initial: showTools,
dispatch: showToolsDispatch,
children: /*#__PURE__*/_jsx(Expands, {
initial: expands,
dispatch: expandsDispatch,
children: /*#__PURE__*/_jsx(Types, {
initial: _extends({}, types, initialTypes),
dispatch: typesDispatch,
children: /*#__PURE__*/_jsx(Symbols, {
initial: symbols,
dispatch: symbolsDispatch,
children: /*#__PURE__*/_jsx(Section, {
initial: section,
dispatch: sectionDispatch,
children: children
})
})
})
})
})
})
});
};
export function useDispatch() {
return useContext(DispatchContext);
}
Provider.displayName = 'JVR.Provider';