dirk-cfx-react 1.1.9 → 1.1.11

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, createFormStore, createScriptSettings, useForm, useNuiEvent, useTornEdges } from './hooks/index.cjs';
3
+ export { FormProvider, FormState, NuiHandlerSignature, NuiMessageData, TornEdgeSVGFilter, ValidationRules, ValidatorFn, createFormStore, createScriptSettings, useForm, 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, createFormStore, createScriptSettings, useForm, useNuiEvent, useTornEdges } from './hooks/index.js';
3
+ export { FormProvider, FormState, NuiHandlerSignature, NuiMessageData, TornEdgeSVGFilter, ValidationRules, ValidatorFn, createFormStore, createScriptSettings, useForm, 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
@@ -2012,6 +2012,10 @@ function flattenRules(rules, prefix = "") {
2012
2012
  }
2013
2013
  return result;
2014
2014
  }
2015
+ async function runRule(rule, value, values) {
2016
+ const result = rule(value, values);
2017
+ return result instanceof Promise ? await result : result;
2018
+ }
2015
2019
  function createFormStore(initialValues, validationRules, onSubmit) {
2016
2020
  const flatRules = validationRules ? flattenRules(validationRules) : {};
2017
2021
  const history = [];
@@ -2026,17 +2030,16 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2026
2030
  changedFields: [],
2027
2031
  changedCount: 0,
2028
2032
  onSubmit,
2029
- submit: () => {
2033
+ submit: async () => {
2030
2034
  const state = get();
2031
- const isValid = state.validate();
2032
- if (isValid && state.onSubmit) state.onSubmit(get());
2035
+ const isValid = await state.validate();
2036
+ if (isValid && state.onSubmit) {
2037
+ state.onSubmit(get());
2038
+ }
2033
2039
  },
2034
2040
  resetChangeCount: () => {
2035
2041
  changed.clear();
2036
- set(() => ({
2037
- changedFields: [],
2038
- changedCount: 0
2039
- }));
2042
+ set({ changedFields: [], changedCount: 0 });
2040
2043
  },
2041
2044
  setInitialValues: (newInitialValues) => set({ initialValues: newInitialValues }),
2042
2045
  setValue: (path, value) => {
@@ -2055,37 +2058,37 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2055
2058
  changedCount: changed.size
2056
2059
  });
2057
2060
  const rule = flatRules[path];
2058
- if (rule) {
2059
- const error2 = rule(value, newValues);
2061
+ if (!rule) return;
2062
+ Promise.resolve(runRule(rule, value, newValues)).then((error2) => {
2060
2063
  if (error2)
2061
- set((state) => ({ errors: setNested(state.errors, path, error2) }));
2062
- else set((state) => ({ errors: deleteNested(state.errors, path) }));
2063
- }
2064
+ set((s) => ({ errors: setNested(s.errors, path, error2) }));
2065
+ else
2066
+ set((s) => ({ errors: deleteNested(s.errors, path) }));
2067
+ });
2064
2068
  },
2065
- setError: (path, message) => set((state) => ({ errors: setNested(state.errors, path, message) })),
2066
- clearError: (path) => set((state) => ({ errors: deleteNested(state.errors, path) })),
2067
- validateField: (path) => {
2069
+ setError: (path, message) => set((s) => ({ errors: setNested(s.errors, path, message) })),
2070
+ clearError: (path) => set((s) => ({ errors: deleteNested(s.errors, path) })),
2071
+ validateField: async (path) => {
2068
2072
  const state = get();
2069
2073
  const rule = flatRules[path];
2070
2074
  if (!rule) return true;
2071
2075
  const value = getNested(state.values, path);
2072
- const error2 = rule(value, state.values);
2076
+ const error2 = await runRule(rule, value, state.values);
2073
2077
  if (error2) {
2074
- set((state2) => ({ errors: setNested(state2.errors, path, error2) }));
2078
+ set((s) => ({ errors: setNested(s.errors, path, error2) }));
2075
2079
  return false;
2076
- } else {
2077
- set((state2) => ({ errors: deleteNested(state2.errors, path) }));
2078
- return true;
2079
2080
  }
2081
+ set((s) => ({ errors: deleteNested(s.errors, path) }));
2082
+ return true;
2080
2083
  },
2081
- validate: () => {
2084
+ validate: async () => {
2082
2085
  const state = get();
2083
2086
  let isValid = true;
2084
2087
  let newErrors = {};
2085
2088
  for (const path in flatRules) {
2086
2089
  const rule = flatRules[path];
2087
2090
  const value = getNested(state.values, path);
2088
- const error2 = rule(value, state.values);
2091
+ const error2 = await runRule(rule, value, state.values);
2089
2092
  if (error2) {
2090
2093
  isValid = false;
2091
2094
  newErrors = setNested(newErrors, path, error2);
@@ -2108,15 +2111,13 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2108
2111
  });
2109
2112
  },
2110
2113
  back: () => {
2111
- const state = get();
2112
- if (history.length === 0) return;
2114
+ if (!history.length) return;
2113
2115
  const prev = history.pop();
2114
- future.push(state.values);
2116
+ future.push(get().values);
2115
2117
  changed.clear();
2116
- const current = prev;
2117
2118
  const initial = get().initialValues;
2118
- for (const key in current) {
2119
- if (JSON.stringify(current[key]) !== JSON.stringify(initial[key]))
2119
+ for (const key in prev) {
2120
+ if (JSON.stringify(prev[key]) !== JSON.stringify(initial[key]))
2120
2121
  changed.add(key);
2121
2122
  }
2122
2123
  set({
@@ -2128,15 +2129,13 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2128
2129
  });
2129
2130
  },
2130
2131
  forward: () => {
2131
- const state = get();
2132
- if (future.length === 0) return;
2132
+ if (!future.length) return;
2133
2133
  const next = future.pop();
2134
- history.push(state.values);
2134
+ history.push(get().values);
2135
2135
  changed.clear();
2136
- const current = next;
2137
2136
  const initial = get().initialValues;
2138
- for (const key in current) {
2139
- if (JSON.stringify(current[key]) !== JSON.stringify(initial[key]))
2137
+ for (const key in next) {
2138
+ if (JSON.stringify(next[key]) !== JSON.stringify(initial[key]))
2140
2139
  changed.add(key);
2141
2140
  }
2142
2141
  set({
@@ -2156,12 +2155,16 @@ function FormProvider({
2156
2155
  onSubmit,
2157
2156
  children
2158
2157
  }) {
2159
- const storeRef = useRef(createFormStore(initialValues, validate, onSubmit));
2158
+ const storeRef = useRef(
2159
+ createFormStore(initialValues, validate, onSubmit)
2160
+ );
2160
2161
  return /* @__PURE__ */ jsx(FormContext.Provider, { value: storeRef.current, children });
2161
2162
  }
2162
2163
  function useForm() {
2163
2164
  const store = useContext(FormContext);
2164
- if (!store) throw new Error("useForm must be used inside a <FormProvider>");
2165
+ if (!store) {
2166
+ throw new Error("useForm must be used inside <FormProvider>");
2167
+ }
2165
2168
  return useStore(store);
2166
2169
  }
2167
2170
  function useTornEdges() {
@@ -2238,6 +2241,20 @@ var error = {
2238
2241
  fontSize: "var(--mantine-font-size-xs)",
2239
2242
  fontFamily: "Akrobat Regular"
2240
2243
  };
2244
+ var description = {
2245
+ fontSize: "var(--mantine-font-size-xs)"
2246
+ };
2247
+ var genericInputStyles = {
2248
+ styles: {
2249
+ label,
2250
+ error,
2251
+ description,
2252
+ input: {
2253
+ backgroundColor: "rgba(76, 76, 76, 0.3)",
2254
+ minHeight: "4vh"
2255
+ }
2256
+ }
2257
+ };
2241
2258
  var theme = createTheme({
2242
2259
  primaryColor: "dirk",
2243
2260
  primaryShade: 9,
@@ -2291,27 +2308,14 @@ var theme = createTheme({
2291
2308
  }
2292
2309
  }
2293
2310
  },
2294
- Textarea: {
2295
- styles: {
2296
- label,
2297
- error
2298
- }
2299
- },
2300
- Button: {
2301
- styles: {
2302
- root: {
2303
- fontSize: "var(--mantine-font-size-xs)"
2304
- }
2305
- }
2306
- },
2307
- Select: {
2308
- styles: {
2309
- label,
2310
- input: {
2311
- padding: "var(--mantine-spacing-sm)"
2312
- }
2313
- }
2314
- },
2311
+ Input: genericInputStyles,
2312
+ TextInput: genericInputStyles,
2313
+ NumberInput: genericInputStyles,
2314
+ Select: genericInputStyles,
2315
+ MultiSelect: genericInputStyles,
2316
+ Textarea: genericInputStyles,
2317
+ ColorInput: genericInputStyles,
2318
+ DateInput: genericInputStyles,
2315
2319
  Pill: {
2316
2320
  styles: (theme2) => ({
2317
2321
  root: {
@@ -2323,52 +2327,12 @@ var theme = createTheme({
2323
2327
  textTransform: "uppercase",
2324
2328
  letterSpacing: "0.05em",
2325
2329
  fontFamily: "Akrobat Bold",
2326
- fontSize: theme2.fontSizes.xs,
2330
+ fontSize: "1.25vh",
2327
2331
  borderRadius: theme2.defaultRadius,
2328
- padding: `${theme2.spacing.xs} ${theme2.spacing.sm}`
2332
+ paddingBottom: "0.5vh",
2333
+ paddingTop: "0.5vh"
2329
2334
  }
2330
2335
  })
2331
- },
2332
- Input: {
2333
- styles: {
2334
- label,
2335
- error,
2336
- input: {
2337
- padding: "var(--mantine-spacing-sm)",
2338
- backgroundColor: "rgba(76, 76, 76, 0.3)"
2339
- }
2340
- }
2341
- },
2342
- ColorInput: {
2343
- styles: {
2344
- label,
2345
- input: {
2346
- padding: "var(--mantine-spacing-sm)"
2347
- }
2348
- }
2349
- },
2350
- TextInput: {
2351
- styles: {
2352
- label,
2353
- wrapper: {},
2354
- section: {
2355
- marginRight: "0.2vh"
2356
- },
2357
- input: {
2358
- padding: "var(--mantine-spacing-sm)"
2359
- }
2360
- }
2361
- },
2362
- NumberInput: {
2363
- styles: {
2364
- label,
2365
- input: {
2366
- padding: "var(--mantine-spacing-sm)"
2367
- },
2368
- section: {
2369
- pointerEvents: "all"
2370
- }
2371
- }
2372
2336
  }
2373
2337
  },
2374
2338
  colors: {