dirk-cfx-react 1.1.55 → 1.1.58

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.
@@ -2548,6 +2548,7 @@ function Modal({
2548
2548
  children
2549
2549
  }) {
2550
2550
  const theme = core.useMantineTheme();
2551
+ const pointerDownOnOverlay = react.useRef(false);
2551
2552
  return /* @__PURE__ */ jsxRuntime.jsx(core.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
2552
2553
  framerMotion.motion.div,
2553
2554
  {
@@ -2563,7 +2564,14 @@ function Modal({
2563
2564
  justifyContent: "center",
2564
2565
  background: "rgba(0,0,0,0.65)"
2565
2566
  },
2566
- onClick: clickOutside ? onClose : void 0,
2567
+ onPointerDown: (e) => {
2568
+ pointerDownOnOverlay.current = e.target === e.currentTarget;
2569
+ },
2570
+ onClick: (e) => {
2571
+ if (clickOutside && e.target === e.currentTarget && pointerDownOnOverlay.current) {
2572
+ onClose();
2573
+ }
2574
+ },
2567
2575
  children: /* @__PURE__ */ jsxRuntime.jsxs(
2568
2576
  framerMotion.motion.div,
2569
2577
  {
@@ -2571,7 +2579,6 @@ function Modal({
2571
2579
  animate: { opacity: 1, scale: 1, y: 0 },
2572
2580
  exit: { opacity: 0, scale: 0.96, y: 8 },
2573
2581
  transition: { duration: 0.18, ease: "easeOut" },
2574
- onClick: (e) => e.stopPropagation(),
2575
2582
  style: {
2576
2583
  background: core.alpha(theme.colors.dark[9], 0.98),
2577
2584
  border: `0.1vh solid ${theme.colors.dark[7]}`,
@@ -3284,6 +3291,13 @@ function useForm() {
3284
3291
  }, [state.values, state.initialValues]);
3285
3292
  return { ...state, changedFields, changedCount: changedFields.length };
3286
3293
  }
3294
+ function useFormActions() {
3295
+ const store = react.useContext(FormContext);
3296
+ if (!store) {
3297
+ throw new Error("useFormActions must be used inside <FormProvider>");
3298
+ }
3299
+ return store.getState();
3300
+ }
3287
3301
  function getScriptSettingsInstance() {
3288
3302
  throw new Error("[dirk-cfx-react] createScriptSettings must be called before using SettingsPanel");
3289
3303
  }
@@ -3814,29 +3828,28 @@ function SettingsPanelInner({
3814
3828
  function cloneSettings(value) {
3815
3829
  return JSON.parse(JSON.stringify(value));
3816
3830
  }
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);
3831
+ function ServerOnlyFetcher() {
3832
+ const { fetchSettings } = getScriptSettingsInstance();
3833
+ const { reinitialize } = useFormActions();
3823
3834
  react.useEffect(() => {
3824
- if (!open) {
3825
- setLoaded(false);
3826
- return;
3827
- }
3828
3835
  let cancelled = false;
3829
- fetchSettings().then(() => {
3830
- if (!cancelled) setLoaded(true);
3836
+ fetchSettings().then((full) => {
3837
+ if (!cancelled && full) reinitialize(full);
3831
3838
  }).catch(() => {
3832
- if (!cancelled) setLoaded(true);
3833
3839
  });
3834
3840
  return () => {
3835
3841
  cancelled = true;
3836
3842
  };
3837
- }, [open]);
3838
- if (!open || !loaded) return null;
3839
- return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: settingsPanelQueryClient, children: /* @__PURE__ */ jsxRuntime.jsx(
3843
+ }, []);
3844
+ return null;
3845
+ }
3846
+ var defaultOnClose = () => fetchNui("CLOSE_ADMIN_SECTION");
3847
+ function SettingsPanel(props) {
3848
+ const { open, onClose = defaultOnClose } = props;
3849
+ const { store, updateSettings, fetchSettings } = getScriptSettingsInstance();
3850
+ const [isSaving, setIsSaving] = react.useState(false);
3851
+ if (!open) return null;
3852
+ return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: settingsPanelQueryClient, children: /* @__PURE__ */ jsxRuntime.jsxs(
3840
3853
  FormProvider,
3841
3854
  {
3842
3855
  initialValues: cloneSettings(store.getState()),
@@ -3858,14 +3871,17 @@ function SettingsPanel(props) {
3858
3871
  setIsSaving(false);
3859
3872
  }
3860
3873
  },
3861
- children: /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: open && /* @__PURE__ */ jsxRuntime.jsx(
3862
- SettingsPanelInner,
3863
- {
3864
- ...props,
3865
- onClose,
3866
- isSaving
3867
- }
3868
- ) })
3874
+ children: [
3875
+ /* @__PURE__ */ jsxRuntime.jsx(ServerOnlyFetcher, {}),
3876
+ /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: open && /* @__PURE__ */ jsxRuntime.jsx(
3877
+ SettingsPanelInner,
3878
+ {
3879
+ ...props,
3880
+ onClose,
3881
+ isSaving
3882
+ }
3883
+ ) })
3884
+ ]
3869
3885
  }
3870
3886
  ) });
3871
3887
  }