UNPKG

fastapi-rtk

Version:

A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.

66 lines (65 loc) 3.18 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("react/jsx-runtime"); const utils = require("fastapi-rtk/utils"); const zustand = require("fastapi-rtk/zustand"); const React = require("react"); const useProvideApi = require("../../fab-react-toolkit-patch/api/hooks/useProvideApi.cjs"); const useProvideBulk = require("../../fab-react-toolkit-patch/api/hooks/useProvideBulk.cjs"); const useInfo = require("../../hooks/auth/useInfo.cjs"); const ApiContext = require("./Contexts/ApiContext.cjs"); const BulkActionsContext = require("./Contexts/BulkActionsContext.cjs"); const FormContext = require("./Contexts/FormContext.cjs"); const useProvideApi$1 = require("./hooks/useProvideApi.cjs"); const useProvideBulk$1 = require("./hooks/useProvideBulk.cjs"); const useProvideForm = require("./hooks/useProvideForm.cjs"); function ApiProvider({ resource_name = "", initialQueryParams, relation, fetchInfo, clearInfoOnRefetch, clearDataOnRefetch, refetchInfoBasedOnLang, refetchDataBasedOnLang, resetQueryParamsOnPathChange, infoQueryProps, dataQueryProps, throwOnError, streaming, children }) { const { baseUrl, fab } = useInfo.useInfo(); const { apiParams, bulkParams } = React.useMemo(() => fab ? { apiParams: useProvideApi.defaultApi, bulkParams: useProvideBulk.defaultBulk } : {}, [fab]); const api = useProvideApi$1.useProvideApi( { path: utils.urlJoin(baseUrl, resource_name), initialQueryParams, relation, fetchInfo, clearInfoOnRefetch, clearDataOnRefetch, refetchInfoBasedOnLang, refetchDataBasedOnLang, resetQueryParamsOnPathChange, infoQueryProps, dataQueryProps, throwOnError, streaming }, apiParams ); const apiProxy = zustand.useProxy(api); const bulkActions = useProvideBulk$1.useProvideBulk(apiProxy, bulkParams); const bulkActionsProxy = zustand.useProxy(bulkActions); const formView = useProvideForm.useProvideForm(); const [formViewProxy] = React.useState(() => zustand.createProxy(formView)); const formAdd = useProvideForm.useProvideForm(); const [formAddProxy] = React.useState(() => zustand.createProxy(formAdd)); const formEdit = useProvideForm.useProvideForm(); const [formEditProxy] = React.useState(() => zustand.createProxy(formEdit)); const formDelete = useProvideForm.useProvideForm(); const [formDeleteProxy] = React.useState(() => zustand.createProxy(formDelete)); return /* @__PURE__ */ jsxRuntime.jsx(ApiContext.ApiContextProvider, { value: apiProxy, children: /* @__PURE__ */ jsxRuntime.jsx(BulkActionsContext.BulkActionsContextProvider, { value: bulkActionsProxy, children: /* @__PURE__ */ jsxRuntime.jsx(FormContext.FormContextViewProvider, { value: formViewProxy, children: /* @__PURE__ */ jsxRuntime.jsx(FormContext.FormContextAddProvider, { value: formAddProxy, children: /* @__PURE__ */ jsxRuntime.jsx(FormContext.FormContextEditProvider, { value: formEditProxy, children: /* @__PURE__ */ jsxRuntime.jsx(FormContext.FormContextDeleteProvider, { value: formDeleteProxy, children }) }) }) }) }) }); } exports.ApiProvider = ApiProvider;