react-better-html 1.1.71 → 1.1.73
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.mts +686 -0
- package/dist/index.d.ts +686 -34
- package/dist/index.js +6302 -101
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6231 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -5
- package/dist/components/BetterHtmlProvider.d.ts +0 -29
- package/dist/components/BetterHtmlProvider.js +0 -161
- package/dist/components/Button.d.ts +0 -65
- package/dist/components/Button.js +0 -166
- package/dist/components/Chip.d.ts +0 -20
- package/dist/components/Chip.js +0 -20
- package/dist/components/ColorThemeSwitch.d.ts +0 -15
- package/dist/components/ColorThemeSwitch.js +0 -54
- package/dist/components/Div.d.ts +0 -30
- package/dist/components/Div.js +0 -60
- package/dist/components/Divider.d.ts +0 -21
- package/dist/components/Divider.js +0 -20
- package/dist/components/Dropdown.d.ts +0 -48
- package/dist/components/Dropdown.js +0 -160
- package/dist/components/ExampleComponent.d.ts +0 -5
- package/dist/components/ExampleComponent.js +0 -10
- package/dist/components/Form.d.ts +0 -25
- package/dist/components/Form.js +0 -27
- package/dist/components/FormRow.d.ts +0 -32
- package/dist/components/FormRow.js +0 -28
- package/dist/components/Icon.d.ts +0 -13
- package/dist/components/Icon.js +0 -36
- package/dist/components/Image.d.ts +0 -18
- package/dist/components/Image.js +0 -44
- package/dist/components/InputField.d.ts +0 -44
- package/dist/components/InputField.js +0 -270
- package/dist/components/Label.d.ts +0 -11
- package/dist/components/Label.js +0 -14
- package/dist/components/Loader.d.ts +0 -34
- package/dist/components/Loader.js +0 -43
- package/dist/components/Modal.d.ts +0 -46
- package/dist/components/Modal.js +0 -123
- package/dist/components/PageHeader.d.ts +0 -18
- package/dist/components/PageHeader.js +0 -19
- package/dist/components/PageHolder.d.ts +0 -8
- package/dist/components/PageHolder.js +0 -15
- package/dist/components/Table.d.ts +0 -45
- package/dist/components/Table.js +0 -159
- package/dist/components/Text.d.ts +0 -18
- package/dist/components/Text.js +0 -38
- package/dist/components/ToggleInput.d.ts +0 -20
- package/dist/components/ToggleInput.js +0 -161
- package/dist/constants/app.d.ts +0 -2
- package/dist/constants/app.js +0 -6
- package/dist/constants/assets.d.ts +0 -2
- package/dist/constants/assets.js +0 -6
- package/dist/constants/countries.d.ts +0 -2
- package/dist/constants/countries.js +0 -1482
- package/dist/constants/css.d.ts +0 -1
- package/dist/constants/css.js +0 -1291
- package/dist/constants/icons.d.ts +0 -2
- package/dist/constants/icons.js +0 -85
- package/dist/constants/theme.d.ts +0 -2
- package/dist/constants/theme.js +0 -50
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -4
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.js +0 -17
- package/dist/plugins/react-router-dom.d.ts +0 -2
- package/dist/plugins/react-router-dom.js +0 -14
- package/dist/types/app.d.ts +0 -15
- package/dist/types/app.js +0 -2
- package/dist/types/asset.d.ts +0 -4
- package/dist/types/asset.js +0 -2
- package/dist/types/components.d.ts +0 -13
- package/dist/types/components.js +0 -2
- package/dist/types/config.d.ts +0 -23
- package/dist/types/config.js +0 -2
- package/dist/types/countries.d.ts +0 -7
- package/dist/types/countries.js +0 -2
- package/dist/types/icon.d.ts +0 -11
- package/dist/types/icon.js +0 -2
- package/dist/types/loader.d.ts +0 -4
- package/dist/types/loader.js +0 -2
- package/dist/types/other.d.ts +0 -1
- package/dist/types/other.js +0 -2
- package/dist/types/plugin.d.ts +0 -7
- package/dist/types/plugin.js +0 -2
- package/dist/types/theme.d.ts +0 -19
- package/dist/types/theme.js +0 -2
- package/dist/utils/functions.d.ts +0 -16
- package/dist/utils/functions.js +0 -77
- package/dist/utils/hooks.d.ts +0 -86
- package/dist/utils/hooks.js +0 -450
- package/dist/utils/logger.d.ts +0 -41
- package/dist/utils/logger.js +0 -66
- package/dist/utils/variableFunctions.d.ts +0 -6
- package/dist/utils/variableFunctions.js +0 -28
- package/dist/utils/withPlugin.d.ts +0 -4
- package/dist/utils/withPlugin.js +0 -15
package/dist/utils/hooks.js
DELETED
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useStyledComponentStyles = useStyledComponentStyles;
|
|
4
|
-
exports.useComponentPropsWithPrefix = useComponentPropsWithPrefix;
|
|
5
|
-
exports.useComponentPropsWithExcludedStyle = useComponentPropsWithExcludedStyle;
|
|
6
|
-
exports.useComponentPropsWithoutStyle = useComponentPropsWithoutStyle;
|
|
7
|
-
exports.useComponentInputFieldDateProps = useComponentInputFieldDateProps;
|
|
8
|
-
exports.usePageResize = usePageResize;
|
|
9
|
-
exports.usePageScroll = usePageScroll;
|
|
10
|
-
exports.useMediaQuery = useMediaQuery;
|
|
11
|
-
exports.useBooleanState = useBooleanState;
|
|
12
|
-
exports.useDebounceState = useDebounceState;
|
|
13
|
-
exports.useForm = useForm;
|
|
14
|
-
exports.useUrlQuery = useUrlQuery;
|
|
15
|
-
const react_1 = require("react");
|
|
16
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
17
|
-
const css_1 = require("../constants/css");
|
|
18
|
-
const BetterHtmlProvider_1 = require("../components/BetterHtmlProvider");
|
|
19
|
-
const cssPropsToExclude = [
|
|
20
|
-
"position",
|
|
21
|
-
"top",
|
|
22
|
-
"right",
|
|
23
|
-
"bottom",
|
|
24
|
-
"left",
|
|
25
|
-
"width",
|
|
26
|
-
"height",
|
|
27
|
-
"minWidth",
|
|
28
|
-
"minHeight",
|
|
29
|
-
"maxWidth",
|
|
30
|
-
"maxHeight",
|
|
31
|
-
"margin",
|
|
32
|
-
"marginTop",
|
|
33
|
-
"marginBottom",
|
|
34
|
-
"marginLeft",
|
|
35
|
-
"marginRight",
|
|
36
|
-
"marginBlock",
|
|
37
|
-
"marginInline",
|
|
38
|
-
"marginBlockStart",
|
|
39
|
-
"marginBlockEnd",
|
|
40
|
-
"marginInlineStart",
|
|
41
|
-
"marginInlineEnd",
|
|
42
|
-
"marginTrim",
|
|
43
|
-
"zIndex",
|
|
44
|
-
];
|
|
45
|
-
function useStyledComponentStyles(props, theme,
|
|
46
|
-
/** @default false */
|
|
47
|
-
excludeProps) {
|
|
48
|
-
return (0, react_1.useMemo)(() => {
|
|
49
|
-
const normalStyle = {};
|
|
50
|
-
const hoverStyle = {};
|
|
51
|
-
let haveHover = false;
|
|
52
|
-
for (const key in props) {
|
|
53
|
-
if (excludeProps && cssPropsToExclude.includes(key))
|
|
54
|
-
continue;
|
|
55
|
-
if (key.endsWith("Hover")) {
|
|
56
|
-
haveHover = true;
|
|
57
|
-
const normalKey = key.slice(0, -5);
|
|
58
|
-
hoverStyle[normalKey] = props[key];
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
if (!css_1.cssProps[key.toLowerCase()])
|
|
62
|
-
continue;
|
|
63
|
-
normalStyle[key] = props[key];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (haveHover)
|
|
67
|
-
normalStyle.transition = theme?.styles.transition ?? "";
|
|
68
|
-
return {
|
|
69
|
-
normalStyle,
|
|
70
|
-
hoverStyle,
|
|
71
|
-
};
|
|
72
|
-
}, [props, theme]);
|
|
73
|
-
}
|
|
74
|
-
function useComponentPropsWithPrefix(props, prefix) {
|
|
75
|
-
return (0, react_1.useMemo)(() => {
|
|
76
|
-
const returnValue = {};
|
|
77
|
-
for (const key in props) {
|
|
78
|
-
if (key.startsWith(`${prefix}-`)) {
|
|
79
|
-
returnValue[key] = props[key];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return returnValue;
|
|
83
|
-
}, [props, prefix]);
|
|
84
|
-
}
|
|
85
|
-
function useComponentPropsWithExcludedStyle(props) {
|
|
86
|
-
return (0, react_1.useMemo)(() => Object.keys(props).reduce((previousValue, currentValue) => {
|
|
87
|
-
const key = currentValue;
|
|
88
|
-
if (!cssPropsToExclude.includes(key))
|
|
89
|
-
return previousValue;
|
|
90
|
-
previousValue[key] = props[key];
|
|
91
|
-
return previousValue;
|
|
92
|
-
}, {}), [props]);
|
|
93
|
-
}
|
|
94
|
-
function useComponentPropsWithoutStyle(props) {
|
|
95
|
-
return (0, react_1.useMemo)(() => Object.keys(props).reduce((previousValue, currentValue) => {
|
|
96
|
-
if (!css_1.cssProps[currentValue.toLowerCase()])
|
|
97
|
-
previousValue[currentValue] = props[currentValue];
|
|
98
|
-
return previousValue;
|
|
99
|
-
}, {}), [props]);
|
|
100
|
-
}
|
|
101
|
-
function useComponentInputFieldDateProps(props, holderRef) {
|
|
102
|
-
const theme = (0, BetterHtmlProvider_1.useTheme)();
|
|
103
|
-
const [isOpen, setIsOpen] = useBooleanState();
|
|
104
|
-
const [isOpenLate, setIsOpenLate] = useBooleanState();
|
|
105
|
-
const [isFocused, setIsFocused] = useBooleanState();
|
|
106
|
-
const [internalValue, setInternalValue] = (0, react_1.useState)(props.value?.toString() ?? "");
|
|
107
|
-
const inputFieldProps = (0, react_1.useMemo)(() => ({
|
|
108
|
-
value: internalValue,
|
|
109
|
-
className: `${isOpen ? "react-better-html-inputField-dateTime-opened" : ""}${isOpenLate ? " react-better-html-inputField-dateTime-opened-late" : ""}${props.className ? ` ${props.className}` : ""}`,
|
|
110
|
-
onClick: (event) => {
|
|
111
|
-
if (props.disabled)
|
|
112
|
-
return;
|
|
113
|
-
setIsOpen.setTrue();
|
|
114
|
-
props.onClick?.(event);
|
|
115
|
-
},
|
|
116
|
-
onFocus: (event) => {
|
|
117
|
-
setIsFocused.setTrue();
|
|
118
|
-
props.onFocus?.(event);
|
|
119
|
-
},
|
|
120
|
-
onBlur: (event) => {
|
|
121
|
-
setIsFocused.setFalse();
|
|
122
|
-
props.onBlur?.(event);
|
|
123
|
-
},
|
|
124
|
-
onChangeValue: (value) => {
|
|
125
|
-
setInternalValue(value);
|
|
126
|
-
props.onChangeValue?.(value);
|
|
127
|
-
},
|
|
128
|
-
}), [props, internalValue, isOpen, isOpenLate]);
|
|
129
|
-
const insideInputFieldComponentProps = (0, react_1.useMemo)(() => ({
|
|
130
|
-
border: `1px solid ${isFocused ? theme.colors.primary : theme.colors.border}`,
|
|
131
|
-
borderTop: "none",
|
|
132
|
-
opacity: !isOpen ? 0 : undefined,
|
|
133
|
-
pointerEvents: !isOpen ? "none" : undefined,
|
|
134
|
-
transform: `translateY(${!isOpen ? -10 : 0}px)`,
|
|
135
|
-
zIndex: 1000,
|
|
136
|
-
transition: theme.styles.transition,
|
|
137
|
-
}), [isOpen, isFocused]);
|
|
138
|
-
(0, react_1.useEffect)(() => {
|
|
139
|
-
if (props.value === undefined || props.value === null)
|
|
140
|
-
return;
|
|
141
|
-
setInternalValue(props.value.toString());
|
|
142
|
-
}, [props.value]);
|
|
143
|
-
(0, react_1.useEffect)(() => {
|
|
144
|
-
if (isOpen) {
|
|
145
|
-
setIsOpenLate.setTrue();
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
const timeout = setTimeout(setIsOpenLate.setFalse, 0.2 * 1000);
|
|
149
|
-
return () => {
|
|
150
|
-
clearTimeout(timeout);
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}, [isOpen]);
|
|
154
|
-
(0, react_1.useEffect)(() => {
|
|
155
|
-
const handleClickOutside = (event) => {
|
|
156
|
-
if (holderRef.current && !holderRef.current.contains(event.target)) {
|
|
157
|
-
setIsOpen.setFalse();
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
if (isOpen) {
|
|
161
|
-
document.addEventListener("mousedown", handleClickOutside);
|
|
162
|
-
}
|
|
163
|
-
return () => {
|
|
164
|
-
document.removeEventListener("mousedown", handleClickOutside);
|
|
165
|
-
};
|
|
166
|
-
}, [isOpen]);
|
|
167
|
-
return {
|
|
168
|
-
internalValue,
|
|
169
|
-
setInternalValue,
|
|
170
|
-
inputFieldProps,
|
|
171
|
-
insideInputFieldComponentProps,
|
|
172
|
-
isOpen,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function usePageResize() {
|
|
176
|
-
const [width, setWidth] = (0, react_1.useState)(window.innerWidth);
|
|
177
|
-
const [height, setHeight] = (0, react_1.useState)(window.innerHeight);
|
|
178
|
-
(0, react_1.useEffect)(() => {
|
|
179
|
-
const onResize = () => {
|
|
180
|
-
setWidth(window.innerWidth);
|
|
181
|
-
setHeight(window.innerHeight);
|
|
182
|
-
};
|
|
183
|
-
window.addEventListener("resize", onResize);
|
|
184
|
-
return () => {
|
|
185
|
-
window.removeEventListener("resize", onResize);
|
|
186
|
-
};
|
|
187
|
-
}, []);
|
|
188
|
-
return {
|
|
189
|
-
width,
|
|
190
|
-
height,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function usePageScroll() {
|
|
194
|
-
const [scrollX, setScrollX] = (0, react_1.useState)(window.scrollX ?? 0);
|
|
195
|
-
const [scrollY, setScrollY] = (0, react_1.useState)(window.scrollY ?? 0);
|
|
196
|
-
(0, react_1.useEffect)(() => {
|
|
197
|
-
const onScroll = () => {
|
|
198
|
-
setScrollX(window.scrollX);
|
|
199
|
-
setScrollY(window.scrollY);
|
|
200
|
-
};
|
|
201
|
-
window.addEventListener("scroll", onScroll);
|
|
202
|
-
return () => {
|
|
203
|
-
window.removeEventListener("scroll", onScroll);
|
|
204
|
-
};
|
|
205
|
-
}, []);
|
|
206
|
-
return {
|
|
207
|
-
scrollX,
|
|
208
|
-
scrollY,
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function useMediaQuery() {
|
|
212
|
-
const { width } = usePageResize();
|
|
213
|
-
return {
|
|
214
|
-
size320: width <= 320,
|
|
215
|
-
size400: width <= 400,
|
|
216
|
-
size500: width <= 500,
|
|
217
|
-
size600: width <= 600,
|
|
218
|
-
size700: width <= 700,
|
|
219
|
-
size800: width <= 800,
|
|
220
|
-
size900: width <= 900,
|
|
221
|
-
size1000: width <= 1000,
|
|
222
|
-
size1100: width <= 1100,
|
|
223
|
-
size1200: width <= 1200,
|
|
224
|
-
size1300: width <= 1300,
|
|
225
|
-
size1400: width <= 1400,
|
|
226
|
-
size1500: width <= 1500,
|
|
227
|
-
size1600: width <= 1600,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function useBooleanState(initialValue = false) {
|
|
231
|
-
const [state, setState] = (0, react_1.useState)(initialValue);
|
|
232
|
-
const setTrue = (0, react_1.useCallback)(() => setState(true), []);
|
|
233
|
-
const setFalse = (0, react_1.useCallback)(() => setState(false), []);
|
|
234
|
-
const toggle = (0, react_1.useCallback)(() => setState((oldValue) => !oldValue), []);
|
|
235
|
-
return [state, { setState, setTrue, setFalse, toggle }];
|
|
236
|
-
}
|
|
237
|
-
function useDebounceState(initialValue, delay = 0.5) {
|
|
238
|
-
const [value, setValue] = (0, react_1.useState)(initialValue);
|
|
239
|
-
const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(initialValue);
|
|
240
|
-
const [isLoading, setIsLoading] = useBooleanState();
|
|
241
|
-
(0, react_1.useEffect)(() => {
|
|
242
|
-
setIsLoading.setTrue();
|
|
243
|
-
const timer = setTimeout(() => {
|
|
244
|
-
setDebouncedValue(value);
|
|
245
|
-
setIsLoading.setFalse();
|
|
246
|
-
}, delay * 1000);
|
|
247
|
-
return () => {
|
|
248
|
-
clearTimeout(timer);
|
|
249
|
-
};
|
|
250
|
-
}, [value, delay]);
|
|
251
|
-
return [value, debouncedValue, setValue, isLoading];
|
|
252
|
-
}
|
|
253
|
-
function useForm(options) {
|
|
254
|
-
const { defaultValues, requiredFields, onSubmit, validate } = options;
|
|
255
|
-
const inputFieldRefs = (0, react_1.useRef)({});
|
|
256
|
-
const [inputTypes, setInputTypes] = (0, react_1.useState)({});
|
|
257
|
-
const [values, setValues] = (0, react_1.useState)(defaultValues);
|
|
258
|
-
const [errors, setErrors] = (0, react_1.useState)({});
|
|
259
|
-
const [isSubmitting, setIsSubmitting] = useBooleanState();
|
|
260
|
-
const setFieldValue = (0, react_1.useCallback)((field, value) => {
|
|
261
|
-
setValues((oldValue) => ({
|
|
262
|
-
...oldValue,
|
|
263
|
-
[field]: value,
|
|
264
|
-
}));
|
|
265
|
-
setErrors((oldValue) => ({
|
|
266
|
-
...oldValue,
|
|
267
|
-
[field]: undefined,
|
|
268
|
-
}));
|
|
269
|
-
}, []);
|
|
270
|
-
const setFieldsValue = (0, react_1.useCallback)((values) => {
|
|
271
|
-
setValues((oldValue) => ({
|
|
272
|
-
...oldValue,
|
|
273
|
-
...values,
|
|
274
|
-
}));
|
|
275
|
-
setErrors((oldValue) => {
|
|
276
|
-
const newErrors = {};
|
|
277
|
-
for (const key in values)
|
|
278
|
-
newErrors[key] = undefined;
|
|
279
|
-
return newErrors;
|
|
280
|
-
});
|
|
281
|
-
}, []);
|
|
282
|
-
const getInputFieldProps = (0, react_1.useCallback)((field) => {
|
|
283
|
-
const type = inputTypes[field] ?? "text";
|
|
284
|
-
return {
|
|
285
|
-
required: requiredFields?.includes(field),
|
|
286
|
-
value: values[field]?.toString() ?? "",
|
|
287
|
-
onChangeValue: (newValue) => {
|
|
288
|
-
const readyValue = type === "number" ? (newValue ? Number(newValue) : undefined) : newValue;
|
|
289
|
-
setFieldValue(field, readyValue);
|
|
290
|
-
},
|
|
291
|
-
ref: (element) => {
|
|
292
|
-
if (!element)
|
|
293
|
-
return;
|
|
294
|
-
inputFieldRefs.current[field] = element;
|
|
295
|
-
if (inputTypes[field] === undefined)
|
|
296
|
-
setInputTypes((oldValue) => ({
|
|
297
|
-
...oldValue,
|
|
298
|
-
[field]: element.getAttribute("type"),
|
|
299
|
-
}));
|
|
300
|
-
},
|
|
301
|
-
errorText: errors[field],
|
|
302
|
-
};
|
|
303
|
-
}, [values, setFieldValue, inputTypes, errors]);
|
|
304
|
-
const getTextAreaProps = (0, react_1.useCallback)((field) => {
|
|
305
|
-
return {
|
|
306
|
-
required: requiredFields?.includes(field),
|
|
307
|
-
value: values[field]?.toString() ?? "",
|
|
308
|
-
onChangeValue: (newValue) => {
|
|
309
|
-
setFieldValue(field, newValue);
|
|
310
|
-
},
|
|
311
|
-
errorText: errors[field],
|
|
312
|
-
};
|
|
313
|
-
}, [values, setFieldValue, inputTypes, errors]);
|
|
314
|
-
const getDropdownFieldProps = (0, react_1.useCallback)((field) => {
|
|
315
|
-
return {
|
|
316
|
-
required: requiredFields?.includes(field),
|
|
317
|
-
value: values[field],
|
|
318
|
-
onChange: (value) => {
|
|
319
|
-
setFieldValue(field, value);
|
|
320
|
-
},
|
|
321
|
-
errorText: errors[field],
|
|
322
|
-
};
|
|
323
|
-
}, [values, errors, setFieldValue]);
|
|
324
|
-
const getCheckboxProps = (0, react_1.useCallback)((field) => {
|
|
325
|
-
return {
|
|
326
|
-
required: requiredFields?.includes(field),
|
|
327
|
-
checked: values[field],
|
|
328
|
-
onChange: (checked) => {
|
|
329
|
-
setFieldValue(field, checked);
|
|
330
|
-
},
|
|
331
|
-
errorText: errors[field],
|
|
332
|
-
};
|
|
333
|
-
}, [values, errors, setFieldValue]);
|
|
334
|
-
const getRadioButtonProps = (0, react_1.useCallback)((field, value) => {
|
|
335
|
-
return {
|
|
336
|
-
required: requiredFields?.includes(field),
|
|
337
|
-
checked: values[field] === value,
|
|
338
|
-
name: field.toString(),
|
|
339
|
-
value,
|
|
340
|
-
onChange: (checked, newValue) => {
|
|
341
|
-
setFieldValue(field, checked ? newValue : undefined);
|
|
342
|
-
},
|
|
343
|
-
errorText: errors[field],
|
|
344
|
-
};
|
|
345
|
-
}, [values, errors, setFieldValue]);
|
|
346
|
-
const getSwitchProps = (0, react_1.useCallback)((field) => {
|
|
347
|
-
return {
|
|
348
|
-
required: requiredFields?.includes(field),
|
|
349
|
-
checked: values[field],
|
|
350
|
-
onChange: (checked) => {
|
|
351
|
-
setFieldValue(field, checked);
|
|
352
|
-
},
|
|
353
|
-
errorText: errors[field],
|
|
354
|
-
};
|
|
355
|
-
}, [values, errors, setFieldValue]);
|
|
356
|
-
const focusField = (0, react_1.useCallback)((field) => {
|
|
357
|
-
inputFieldRefs.current[field]?.focus();
|
|
358
|
-
}, []);
|
|
359
|
-
const onSubmitFunction = (0, react_1.useCallback)(async (event) => {
|
|
360
|
-
event.preventDefault();
|
|
361
|
-
setIsSubmitting.setTrue();
|
|
362
|
-
try {
|
|
363
|
-
const validationErrors = validate?.(values) || {};
|
|
364
|
-
setErrors(validationErrors);
|
|
365
|
-
if (Object.keys(validationErrors).length === 0) {
|
|
366
|
-
await onSubmit?.(values);
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
const firstErrorField = Object.keys(validationErrors)[0];
|
|
370
|
-
focusField(firstErrorField);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
finally {
|
|
374
|
-
setIsSubmitting.setFalse();
|
|
375
|
-
}
|
|
376
|
-
}, [values, validate, onSubmit, focusField]);
|
|
377
|
-
const reset = (0, react_1.useCallback)(() => {
|
|
378
|
-
setValues(defaultValues);
|
|
379
|
-
setErrors({});
|
|
380
|
-
}, [defaultValues]);
|
|
381
|
-
const isDirty = (0, react_1.useMemo)(() => Object.keys(defaultValues).some((key) => defaultValues[key] !== values[key]), [defaultValues, values]);
|
|
382
|
-
const isValid = (0, react_1.useMemo)(() => {
|
|
383
|
-
const validationErrors = validate?.(values) || {};
|
|
384
|
-
return Object.keys(validationErrors).length === 0;
|
|
385
|
-
}, [validate, values]);
|
|
386
|
-
const canSubmit = (0, react_1.useMemo)(() => {
|
|
387
|
-
const requiredFieldsHaveValues = requiredFields?.every((field) => values[field] !== undefined && values[field] !== "") ?? true;
|
|
388
|
-
return isValid && requiredFieldsHaveValues;
|
|
389
|
-
}, [isValid, requiredFields]);
|
|
390
|
-
return {
|
|
391
|
-
values,
|
|
392
|
-
errors,
|
|
393
|
-
isSubmitting,
|
|
394
|
-
setFieldValue,
|
|
395
|
-
setFieldsValue,
|
|
396
|
-
getInputFieldProps,
|
|
397
|
-
getTextAreaProps,
|
|
398
|
-
getDropdownFieldProps,
|
|
399
|
-
getCheckboxProps,
|
|
400
|
-
getRadioButtonProps,
|
|
401
|
-
getSwitchProps,
|
|
402
|
-
focusField,
|
|
403
|
-
onSubmit: onSubmitFunction,
|
|
404
|
-
reset,
|
|
405
|
-
requiredFields,
|
|
406
|
-
isDirty,
|
|
407
|
-
isValid,
|
|
408
|
-
canSubmit,
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
function useUrlQuery() {
|
|
412
|
-
const reactRouterDomPlugin = (0, BetterHtmlProvider_1.usePlugin)("react-router-dom");
|
|
413
|
-
if (!reactRouterDomPlugin) {
|
|
414
|
-
throw new Error("`useUrlQuery` hook requires the `react-router-dom` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`.");
|
|
415
|
-
}
|
|
416
|
-
const isInRouterContext = (0, react_router_dom_1.useInRouterContext)();
|
|
417
|
-
if (!isInRouterContext) {
|
|
418
|
-
throw new Error("`useUrlQuery` hook must be used inside a React Router context. Make sure your component is wrapped in a `<BrowserRouter>`, or another Router component.");
|
|
419
|
-
}
|
|
420
|
-
const navigate = (0, react_router_dom_1.useNavigate)();
|
|
421
|
-
const [searchParams] = (0, react_router_dom_1.useSearchParams)();
|
|
422
|
-
const setQuery = (0, react_1.useCallback)((query, keepHistory = true) => {
|
|
423
|
-
const currentSearchParams = {};
|
|
424
|
-
searchParams.forEach((value, key) => {
|
|
425
|
-
currentSearchParams[key] = value;
|
|
426
|
-
});
|
|
427
|
-
navigate({
|
|
428
|
-
search: (0, react_router_dom_1.createSearchParams)({
|
|
429
|
-
...currentSearchParams,
|
|
430
|
-
...Object.fromEntries(Object.entries(query).map(([key, value]) => [key, value.toString()])),
|
|
431
|
-
}).toString(),
|
|
432
|
-
}, {
|
|
433
|
-
replace: !keepHistory,
|
|
434
|
-
});
|
|
435
|
-
}, [navigate, searchParams]);
|
|
436
|
-
const getQuery = (0, react_1.useCallback)((name) => searchParams.get(name), [searchParams]);
|
|
437
|
-
const removeQuery = (0, react_1.useCallback)((name, keepHistory = true) => {
|
|
438
|
-
searchParams.delete(name);
|
|
439
|
-
navigate({
|
|
440
|
-
search: searchParams.toString(),
|
|
441
|
-
}, {
|
|
442
|
-
replace: !keepHistory,
|
|
443
|
-
});
|
|
444
|
-
}, [navigate, searchParams]);
|
|
445
|
-
return {
|
|
446
|
-
setQuery,
|
|
447
|
-
getQuery,
|
|
448
|
-
removeQuery,
|
|
449
|
-
};
|
|
450
|
-
}
|
package/dist/utils/logger.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
type TextColor = keyof typeof textColors;
|
|
2
|
-
type BackgroundColor = keyof typeof backgroundColors;
|
|
3
|
-
type Options = {
|
|
4
|
-
color?: TextColor;
|
|
5
|
-
backgroundColor?: BackgroundColor;
|
|
6
|
-
bold?: boolean;
|
|
7
|
-
};
|
|
8
|
-
declare const textColors: {
|
|
9
|
-
black: string;
|
|
10
|
-
red: string;
|
|
11
|
-
green: string;
|
|
12
|
-
yellow: string;
|
|
13
|
-
blue: string;
|
|
14
|
-
magenta: string;
|
|
15
|
-
cyan: string;
|
|
16
|
-
white: string;
|
|
17
|
-
};
|
|
18
|
-
declare const backgroundColors: {
|
|
19
|
-
black: string;
|
|
20
|
-
red: string;
|
|
21
|
-
green: string;
|
|
22
|
-
yellow: string;
|
|
23
|
-
blue: string;
|
|
24
|
-
magenta: string;
|
|
25
|
-
cyan: string;
|
|
26
|
-
white: string;
|
|
27
|
-
};
|
|
28
|
-
export declare const log: {
|
|
29
|
-
/** @description Default log function */
|
|
30
|
-
log: (text?: string, options?: Options) => void;
|
|
31
|
-
/** @description Logs the value in pretty json format */
|
|
32
|
-
json: (jsonObject?: any, options?: Options) => void;
|
|
33
|
-
/** @description Logs a -=-= pattern */
|
|
34
|
-
divider: (color?: TextColor) => void;
|
|
35
|
-
trace: () => void;
|
|
36
|
-
success: (text?: string, bold?: boolean) => void;
|
|
37
|
-
info: (text?: string, bold?: boolean) => void;
|
|
38
|
-
warn: (text?: string, bold?: boolean) => void;
|
|
39
|
-
error: (text?: string, bold?: boolean) => void;
|
|
40
|
-
};
|
|
41
|
-
export {};
|
package/dist/utils/logger.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.log = void 0;
|
|
4
|
-
const textColors = {
|
|
5
|
-
black: "#111111",
|
|
6
|
-
red: "#f83e4b",
|
|
7
|
-
green: "#5ac53a",
|
|
8
|
-
yellow: "#f8d770",
|
|
9
|
-
blue: "#3d6fdf",
|
|
10
|
-
magenta: "#9648eb",
|
|
11
|
-
cyan: "#53b2c8",
|
|
12
|
-
white: "#f8f8f8",
|
|
13
|
-
};
|
|
14
|
-
const backgroundColors = {
|
|
15
|
-
black: "#111111",
|
|
16
|
-
red: "#f83e4b",
|
|
17
|
-
green: "#5ac53a",
|
|
18
|
-
yellow: "#f8d770",
|
|
19
|
-
blue: "#3d6fdf",
|
|
20
|
-
magenta: "#9648eb",
|
|
21
|
-
cyan: "#53b2c8",
|
|
22
|
-
white: "#f8f8f8",
|
|
23
|
-
};
|
|
24
|
-
const logTypes = {
|
|
25
|
-
info: "cyan",
|
|
26
|
-
success: "green",
|
|
27
|
-
warn: "yellow",
|
|
28
|
-
error: "red",
|
|
29
|
-
};
|
|
30
|
-
function getCssString(options) {
|
|
31
|
-
const color = options.color ? textColors[options.color] : undefined;
|
|
32
|
-
const backgroundColor = options.backgroundColor ? backgroundColors[options.backgroundColor] : undefined;
|
|
33
|
-
const fontWeight = options.bold ? "bold" : "normal";
|
|
34
|
-
return `${color ? `color: ${color};` : ""}${backgroundColor ? `background-color: ${backgroundColor};` : ""}${fontWeight ? `font-weight: ${fontWeight};` : ""}`;
|
|
35
|
-
}
|
|
36
|
-
function logText(text, options) {
|
|
37
|
-
console.log(`%c${text}`, getCssString(options ?? {}));
|
|
38
|
-
}
|
|
39
|
-
exports.log = {
|
|
40
|
-
...Object.entries(logTypes).reduce((previousValue, [logType, color]) => {
|
|
41
|
-
previousValue[logType] = (text = "", bold) => {
|
|
42
|
-
logText(text, {
|
|
43
|
-
color,
|
|
44
|
-
bold,
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
return previousValue;
|
|
48
|
-
}, {}),
|
|
49
|
-
/** @description Default log function */
|
|
50
|
-
log: (text, options) => {
|
|
51
|
-
logText(text, options);
|
|
52
|
-
},
|
|
53
|
-
/** @description Logs the value in pretty json format */
|
|
54
|
-
json: (jsonObject, options) => {
|
|
55
|
-
logText(`\n${JSON.stringify(jsonObject, null, 4)}`, options);
|
|
56
|
-
},
|
|
57
|
-
/** @description Logs a -=-= pattern */
|
|
58
|
-
divider: (color) => {
|
|
59
|
-
logText("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", {
|
|
60
|
-
color,
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
trace: () => {
|
|
64
|
-
console.trace();
|
|
65
|
-
},
|
|
66
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { AnyOtherString } from "../types/app";
|
|
2
|
-
import { LoaderName } from "../types/loader";
|
|
3
|
-
export declare const loaderControls: {
|
|
4
|
-
startLoading: (loaderName: LoaderName | AnyOtherString) => void;
|
|
5
|
-
stopLoading: (loaderName: LoaderName | AnyOtherString) => void;
|
|
6
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loaderControls = void 0;
|
|
4
|
-
const BetterHtmlProvider_1 = require("../components/BetterHtmlProvider");
|
|
5
|
-
const checkBetterHtmlContextValue = (value, functionsName) => {
|
|
6
|
-
if (value === undefined) {
|
|
7
|
-
throw new Error(`\`${functionsName}()\` must be used within a \`<BetterHtmlProvider>\`. Make sure to add one at the root of your component tree.`);
|
|
8
|
-
}
|
|
9
|
-
return value !== undefined;
|
|
10
|
-
};
|
|
11
|
-
exports.loaderControls = {
|
|
12
|
-
startLoading: (loaderName) => {
|
|
13
|
-
if (!checkBetterHtmlContextValue(BetterHtmlProvider_1.externalBetterHtmlContextValue, "loaderControls.startLoading"))
|
|
14
|
-
return;
|
|
15
|
-
BetterHtmlProvider_1.externalBetterHtmlContextValue.setLoaders((oldValue) => ({
|
|
16
|
-
...oldValue,
|
|
17
|
-
[loaderName.toString()]: true,
|
|
18
|
-
}));
|
|
19
|
-
},
|
|
20
|
-
stopLoading: (loaderName) => {
|
|
21
|
-
if (!checkBetterHtmlContextValue(BetterHtmlProvider_1.externalBetterHtmlContextValue, "loaderControls.stopLoading"))
|
|
22
|
-
return;
|
|
23
|
-
BetterHtmlProvider_1.externalBetterHtmlContextValue.setLoaders((oldValue) => ({
|
|
24
|
-
...oldValue,
|
|
25
|
-
[loaderName.toString()]: false,
|
|
26
|
-
}));
|
|
27
|
-
},
|
|
28
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from "react";
|
|
2
|
-
import { PluginName } from "../types/plugin";
|
|
3
|
-
import { ComponentPropWithPlugin } from "../types/components";
|
|
4
|
-
export declare function withPlugin<ComponentProps extends object>(pluginName: PluginName, WrappedComponent: ComponentType<ComponentPropWithPlugin<ComponentProps>>): ComponentType<ComponentProps>;
|
package/dist/utils/withPlugin.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withPlugin = withPlugin;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const BetterHtmlProvider_1 = require("../components/BetterHtmlProvider");
|
|
6
|
-
function withPlugin(pluginName, WrappedComponent) {
|
|
7
|
-
const WithPlugin = (props) => {
|
|
8
|
-
const plugin = (0, BetterHtmlProvider_1.usePlugin)(pluginName);
|
|
9
|
-
if (!plugin)
|
|
10
|
-
throw new Error(`\`${pluginName}\` must be added to the \`plugins\` prop in \`<BetterHtmlProvider>\` for the component to work.`);
|
|
11
|
-
return (0, jsx_runtime_1.jsx)(WrappedComponent, { ...props, plugin: plugin });
|
|
12
|
-
};
|
|
13
|
-
WithPlugin.displayName = `WithPlugin(${pluginName})`;
|
|
14
|
-
return WithPlugin;
|
|
15
|
-
}
|