dirk-cfx-react 1.1.10 → 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/hooks/index.cjs +39 -36
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +6 -6
- package/dist/hooks/index.d.ts +6 -6
- package/dist/hooks/index.js +39 -36
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +39 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +39 -36
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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)
|
|
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
|
-
|
|
2061
|
+
if (!rule) return;
|
|
2062
|
+
Promise.resolve(runRule(rule, value, newValues)).then((error2) => {
|
|
2060
2063
|
if (error2)
|
|
2061
|
-
set((
|
|
2062
|
-
else
|
|
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((
|
|
2066
|
-
clearError: (path) => set((
|
|
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
|
|
2076
|
+
const error2 = await runRule(rule, value, state.values);
|
|
2073
2077
|
if (error2) {
|
|
2074
|
-
set((
|
|
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
|
|
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
|
-
|
|
2112
|
-
if (history.length === 0) return;
|
|
2114
|
+
if (!history.length) return;
|
|
2113
2115
|
const prev = history.pop();
|
|
2114
|
-
future.push(
|
|
2116
|
+
future.push(get().values);
|
|
2115
2117
|
changed.clear();
|
|
2116
|
-
const current = prev;
|
|
2117
2118
|
const initial = get().initialValues;
|
|
2118
|
-
for (const key in
|
|
2119
|
-
if (JSON.stringify(
|
|
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
|
-
|
|
2132
|
-
if (future.length === 0) return;
|
|
2132
|
+
if (!future.length) return;
|
|
2133
2133
|
const next = future.pop();
|
|
2134
|
-
history.push(
|
|
2134
|
+
history.push(get().values);
|
|
2135
2135
|
changed.clear();
|
|
2136
|
-
const current = next;
|
|
2137
2136
|
const initial = get().initialValues;
|
|
2138
|
-
for (const key in
|
|
2139
|
-
if (JSON.stringify(
|
|
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(
|
|
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)
|
|
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() {
|