dirk-cfx-react 1.1.18 → 1.1.19

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/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { BorderedIcon, BorderedIconProps, ButtonProps, Counter, FloatingParticles, FloatingParticlesProps, InfoBox, InfoBoxProps, InputContainer, InputContainerProps, LevelBanner, LevelPanel, ModalContext, ModalProvider, MotionFlex, MotionIcon, MotionImage, MotionText, NavBar, NavigationContext, NavigationProvider, NavigationStore, ParticleState, ProgressProps, Prompt, PromptButton, PromptModal, SegmentProps, SegmentedControl, SegmentedControlProps, SegmentedProgress, Title, TitleProps, useModal, useModalActions, useNavigation, useNavigationStore } from './components/index.cjs';
2
2
  export { InitialFetch, InternalEvent, SettingsState, SkillSettings, UploadImageProps, colorWithAlpha, copyToClipboard, createSkill, fetchNui, gameToMap, getImageShape, initialFetches, internalEvent, isEnvBrowser, isProfanity, latPr100, locale, localeStore, mapCenter, mapToGame, noop, numberToRoman, openLink, registerInitialFetch, runFetches, splitFAString, updatePresignedURL, uploadImage, useAutoFetcher, useProfanityStore, useSettings } from './utils/index.cjs';
3
- export { FormProvider, FormState, NuiHandlerSignature, NuiMessageData, TornEdgeSVGFilter, ValidationRules, ValidatorFn, createFormStore, createScriptSettings, useForm, useNuiEvent, useTornEdges } from './hooks/index.cjs';
3
+ export { FormProvider, FormState, NuiHandlerSignature, NuiMessageData, TornEdgeSVGFilter, ValidationRules, ValidatorFn, createFormStore, createScriptSettings, useForm, useFormActions, useFormField, useNuiEvent, useTornEdges } from './hooks/index.cjs';
4
4
  export { DirkProvider, DirkProviderProps } from './providers/index.cjs';
5
5
  import 'react/jsx-runtime';
6
6
  import 'react';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { BorderedIcon, BorderedIconProps, ButtonProps, Counter, FloatingParticles, FloatingParticlesProps, InfoBox, InfoBoxProps, InputContainer, InputContainerProps, LevelBanner, LevelPanel, ModalContext, ModalProvider, MotionFlex, MotionIcon, MotionImage, MotionText, NavBar, NavigationContext, NavigationProvider, NavigationStore, ParticleState, ProgressProps, Prompt, PromptButton, PromptModal, SegmentProps, SegmentedControl, SegmentedControlProps, SegmentedProgress, Title, TitleProps, useModal, useModalActions, useNavigation, useNavigationStore } from './components/index.js';
2
2
  export { InitialFetch, InternalEvent, SettingsState, SkillSettings, UploadImageProps, colorWithAlpha, copyToClipboard, createSkill, fetchNui, gameToMap, getImageShape, initialFetches, internalEvent, isEnvBrowser, isProfanity, latPr100, locale, localeStore, mapCenter, mapToGame, noop, numberToRoman, openLink, registerInitialFetch, runFetches, splitFAString, updatePresignedURL, uploadImage, useAutoFetcher, useProfanityStore, useSettings } from './utils/index.js';
3
- export { FormProvider, FormState, NuiHandlerSignature, NuiMessageData, TornEdgeSVGFilter, ValidationRules, ValidatorFn, createFormStore, createScriptSettings, useForm, useNuiEvent, useTornEdges } from './hooks/index.js';
3
+ export { FormProvider, FormState, NuiHandlerSignature, NuiMessageData, TornEdgeSVGFilter, ValidationRules, ValidatorFn, createFormStore, createScriptSettings, useForm, useFormActions, useFormField, useNuiEvent, useTornEdges } from './hooks/index.js';
4
4
  export { DirkProvider, DirkProviderProps } from './providers/index.js';
5
5
  import 'react/jsx-runtime';
6
6
  import 'react';
package/dist/index.js CHANGED
@@ -2054,8 +2054,6 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2054
2054
  setInitialValues: (newInitialValues) => set({ initialValues: newInitialValues }),
2055
2055
  setValue: (path, value, options) => {
2056
2056
  const state = get();
2057
- const currentValue = getNested(state.values, path);
2058
- if (currentValue === value) return;
2059
2057
  const currentValues = state.values;
2060
2058
  const newValues = setNested(currentValues, path, value);
2061
2059
  const oldValue = getNested(state.initialValues, path);
@@ -2070,27 +2068,22 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2070
2068
  changed.delete(path);
2071
2069
  newPartial = deleteNested(newPartial, path);
2072
2070
  }
2073
- const newSize = changed.size;
2074
- const changedFields = newSize !== state.changedCount ? Array.from(changed) : state.changedFields;
2075
2071
  set({
2076
2072
  values: newValues,
2077
2073
  partialChanged: newPartial,
2078
2074
  canBack: history.length > 0,
2079
2075
  canForward: false,
2080
- changedFields,
2081
- changedCount: newSize
2076
+ changedFields: Array.from(changed),
2077
+ changedCount: changed.size
2082
2078
  });
2083
2079
  if (!options?.validate) return;
2084
2080
  const rule = flatRules[path];
2085
2081
  if (!rule) return;
2086
- queueMicrotask(() => {
2087
- runRule(rule, value, newValues).then((error2) => {
2088
- if (error2) {
2089
- set((s) => ({ errors: setNested(s.errors, path, error2) }));
2090
- } else {
2091
- set((s) => ({ errors: deleteNested(s.errors, path) }));
2092
- }
2093
- });
2082
+ Promise.resolve(runRule(rule, value, newValues)).then((error2) => {
2083
+ if (error2)
2084
+ set((s) => ({ errors: setNested(s.errors, path, error2) }));
2085
+ else
2086
+ set((s) => ({ errors: deleteNested(s.errors, path) }));
2094
2087
  });
2095
2088
  },
2096
2089
  setError: (path, message) => set((s) => ({ errors: setNested(s.errors, path, message) })),
@@ -2205,6 +2198,20 @@ function useForm() {
2205
2198
  }
2206
2199
  return useStore(store);
2207
2200
  }
2201
+ function useFormField(path) {
2202
+ const store = useContext(FormContext);
2203
+ if (!store) {
2204
+ throw new Error("useFormField must be used inside <FormProvider>");
2205
+ }
2206
+ return useStore(store, (s) => getNested(s.values, path));
2207
+ }
2208
+ function useFormActions() {
2209
+ const store = useContext(FormContext);
2210
+ if (!store) {
2211
+ throw new Error("useFormActions must be used inside <FormProvider>");
2212
+ }
2213
+ return store.getState();
2214
+ }
2208
2215
  function useTornEdges() {
2209
2216
  const game = useSettings((state) => state.game);
2210
2217
  return game === "rdr3" ? "torn-edge-wrapper" : "";
@@ -2461,6 +2468,6 @@ function DirkProvider({ children, themeOverride }) {
2461
2468
  return /* @__PURE__ */ jsx(DirkErrorBoundary, { children: /* @__PURE__ */ jsx(MantineProvider, { theme: mergedTheme, defaultColorScheme: "dark", children: content }) });
2462
2469
  }
2463
2470
 
2464
- export { BorderedIcon, Counter, DirkProvider, FloatingParticles, FormProvider, InfoBox, InputContainer, LevelBanner, LevelPanel, ModalContext, ModalProvider, MotionFlex, MotionIcon, MotionImage, MotionText, NavBar, NavigationContext, NavigationProvider, PromptModal, SegmentedControl, SegmentedProgress, Title, TornEdgeSVGFilter, colorWithAlpha, copyToClipboard, createFormStore, createScriptSettings, createSkill, fetchNui, gameToMap, getImageShape, initialFetches, internalEvent, isEnvBrowser, isProfanity, latPr100, locale, localeStore, mapCenter, mapToGame, noop, numberToRoman, openLink, registerInitialFetch, runFetches, splitFAString, updatePresignedURL, uploadImage, useAutoFetcher, useForm, useModal, useModalActions, useNavigation, useNavigationStore, useNuiEvent, useProfanityStore, useSettings, useTornEdges };
2471
+ export { BorderedIcon, Counter, DirkProvider, FloatingParticles, FormProvider, InfoBox, InputContainer, LevelBanner, LevelPanel, ModalContext, ModalProvider, MotionFlex, MotionIcon, MotionImage, MotionText, NavBar, NavigationContext, NavigationProvider, PromptModal, SegmentedControl, SegmentedProgress, Title, TornEdgeSVGFilter, colorWithAlpha, copyToClipboard, createFormStore, createScriptSettings, createSkill, fetchNui, gameToMap, getImageShape, initialFetches, internalEvent, isEnvBrowser, isProfanity, latPr100, locale, localeStore, mapCenter, mapToGame, noop, numberToRoman, openLink, registerInitialFetch, runFetches, splitFAString, updatePresignedURL, uploadImage, useAutoFetcher, useForm, useFormActions, useFormField, useModal, useModalActions, useNavigation, useNavigationStore, useNuiEvent, useProfanityStore, useSettings, useTornEdges };
2465
2472
  //# sourceMappingURL=index.js.map
2466
2473
  //# sourceMappingURL=index.js.map