dirk-cfx-react 1.1.54 → 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.
- package/dist/components/index.cjs +36 -10
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +36 -10
- package/dist/components/index.js.map +1 -1
- package/dist/hooks/index.cjs +26 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +3 -1
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/index.js +26 -2
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +73 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -30
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
|
@@ -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,13 +3821,28 @@ function SettingsPanelInner({
|
|
|
3814
3821
|
function cloneSettings(value) {
|
|
3815
3822
|
return JSON.parse(JSON.stringify(value));
|
|
3816
3823
|
}
|
|
3824
|
+
function ServerOnlyFetcher() {
|
|
3825
|
+
const { fetchSettings } = getScriptSettingsInstance();
|
|
3826
|
+
const { reinitialize } = useFormActions();
|
|
3827
|
+
react.useEffect(() => {
|
|
3828
|
+
let cancelled = false;
|
|
3829
|
+
fetchSettings().then((full) => {
|
|
3830
|
+
if (!cancelled && full) reinitialize(full);
|
|
3831
|
+
}).catch(() => {
|
|
3832
|
+
});
|
|
3833
|
+
return () => {
|
|
3834
|
+
cancelled = true;
|
|
3835
|
+
};
|
|
3836
|
+
}, []);
|
|
3837
|
+
return null;
|
|
3838
|
+
}
|
|
3817
3839
|
var defaultOnClose = () => fetchNui("CLOSE_ADMIN_SECTION");
|
|
3818
3840
|
function SettingsPanel(props) {
|
|
3819
3841
|
const { open, onClose = defaultOnClose } = props;
|
|
3820
|
-
const { store, updateSettings } = getScriptSettingsInstance();
|
|
3842
|
+
const { store, updateSettings, fetchSettings } = getScriptSettingsInstance();
|
|
3821
3843
|
const [isSaving, setIsSaving] = react.useState(false);
|
|
3822
3844
|
if (!open) return null;
|
|
3823
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: settingsPanelQueryClient, children: /* @__PURE__ */ jsxRuntime.
|
|
3845
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client: settingsPanelQueryClient, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3824
3846
|
FormProvider,
|
|
3825
3847
|
{
|
|
3826
3848
|
initialValues: cloneSettings(store.getState()),
|
|
@@ -3831,6 +3853,7 @@ function SettingsPanel(props) {
|
|
|
3831
3853
|
const result = await updateSettings(form.values);
|
|
3832
3854
|
if (result?.success) {
|
|
3833
3855
|
form.reinitialize(cloneSettings(form.values));
|
|
3856
|
+
settingsPanelQueryClient.invalidateQueries({ queryKey: ["scriptSettingsHistory"] });
|
|
3834
3857
|
return;
|
|
3835
3858
|
}
|
|
3836
3859
|
form.reinitialize(cloneSettings(store.getState()));
|
|
@@ -3841,14 +3864,17 @@ function SettingsPanel(props) {
|
|
|
3841
3864
|
setIsSaving(false);
|
|
3842
3865
|
}
|
|
3843
3866
|
},
|
|
3844
|
-
children:
|
|
3845
|
-
|
|
3846
|
-
{
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
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
|
+
]
|
|
3852
3878
|
}
|
|
3853
3879
|
) });
|
|
3854
3880
|
}
|