dirk-cfx-react 1.1.55 → 1.1.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3284,6 +3284,13 @@ function useForm() {
3284
3284
  }, [state.values, state.initialValues]);
3285
3285
  return { ...state, changedFields, changedCount: changedFields.length };
3286
3286
  }
3287
+ function useFormActions() {
3288
+ const store = react.useContext(FormContext);
3289
+ if (!store) {
3290
+ throw new Error("useFormActions must be used inside <FormProvider>");
3291
+ }
3292
+ return store.getState();
3293
+ }
3287
3294
  function getScriptSettingsInstance() {
3288
3295
  throw new Error("[dirk-cfx-react] createScriptSettings must be called before using SettingsPanel");
3289
3296
  }
@@ -3814,29 +3821,28 @@ function SettingsPanelInner({
3814
3821
  function cloneSettings(value) {
3815
3822
  return JSON.parse(JSON.stringify(value));
3816
3823
  }
3817
- var defaultOnClose = () => fetchNui("CLOSE_ADMIN_SECTION");
3818
- function SettingsPanel(props) {
3819
- const { open, onClose = defaultOnClose } = props;
3820
- const { store, updateSettings, fetchSettings } = getScriptSettingsInstance();
3821
- const [isSaving, setIsSaving] = react.useState(false);
3822
- const [loaded, setLoaded] = react.useState(false);
3824
+ function ServerOnlyFetcher() {
3825
+ const { fetchSettings } = getScriptSettingsInstance();
3826
+ const { reinitialize } = useFormActions();
3823
3827
  react.useEffect(() => {
3824
- if (!open) {
3825
- setLoaded(false);
3826
- return;
3827
- }
3828
3828
  let cancelled = false;
3829
- fetchSettings().then(() => {
3830
- if (!cancelled) setLoaded(true);
3829
+ fetchSettings().then((full) => {
3830
+ if (!cancelled && full) reinitialize(full);
3831
3831
  }).catch(() => {
3832
- if (!cancelled) setLoaded(true);
3833
3832
  });
3834
3833
  return () => {
3835
3834
  cancelled = true;
3836
3835
  };
3837
- }, [open]);
3838
- if (!open || !loaded) return null;
3839
- return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: settingsPanelQueryClient, children: /* @__PURE__ */ jsxRuntime.jsx(
3836
+ }, []);
3837
+ return null;
3838
+ }
3839
+ var defaultOnClose = () => fetchNui("CLOSE_ADMIN_SECTION");
3840
+ function SettingsPanel(props) {
3841
+ const { open, onClose = defaultOnClose } = props;
3842
+ const { store, updateSettings, fetchSettings } = getScriptSettingsInstance();
3843
+ const [isSaving, setIsSaving] = react.useState(false);
3844
+ if (!open) return null;
3845
+ return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: settingsPanelQueryClient, children: /* @__PURE__ */ jsxRuntime.jsxs(
3840
3846
  FormProvider,
3841
3847
  {
3842
3848
  initialValues: cloneSettings(store.getState()),
@@ -3858,14 +3864,17 @@ function SettingsPanel(props) {
3858
3864
  setIsSaving(false);
3859
3865
  }
3860
3866
  },
3861
- children: /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: open && /* @__PURE__ */ jsxRuntime.jsx(
3862
- SettingsPanelInner,
3863
- {
3864
- ...props,
3865
- onClose,
3866
- isSaving
3867
- }
3868
- ) })
3867
+ children: [
3868
+ /* @__PURE__ */ jsxRuntime.jsx(ServerOnlyFetcher, {}),
3869
+ /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: open && /* @__PURE__ */ jsxRuntime.jsx(
3870
+ SettingsPanelInner,
3871
+ {
3872
+ ...props,
3873
+ onClose,
3874
+ isSaving
3875
+ }
3876
+ ) })
3877
+ ]
3869
3878
  }
3870
3879
  ) });
3871
3880
  }