@ahmadmubarak98/namozaj 1.1.18 → 1.3.0
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/main.d.ts +9 -0
- package/dist/namozaj.js +93 -31
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare type BaseFieldConfig = {
|
|
|
13
13
|
style?: React.CSSProperties;
|
|
14
14
|
placeholder?: string;
|
|
15
15
|
tooltip?: TooltipConfig;
|
|
16
|
+
translated?: boolean;
|
|
16
17
|
helperText?: HelperTextConfig;
|
|
17
18
|
validations?: ValidationRule[];
|
|
18
19
|
grid?: GridColumnConfig;
|
|
@@ -89,6 +90,7 @@ export declare type DynamicFormField = TextFieldConfig | NumberFieldConfig | Sli
|
|
|
89
90
|
|
|
90
91
|
export declare interface DynamicFormProps {
|
|
91
92
|
fields: DynamicFormField[];
|
|
93
|
+
localization?: NamozajLocalizationOptions;
|
|
92
94
|
emptyFormMessage?: string;
|
|
93
95
|
defaultValues?: Record<string, FieldValueType>;
|
|
94
96
|
defaultSubmitButtonProps?: DefaultSubmitButtonProps;
|
|
@@ -228,6 +230,13 @@ export declare type ModalSize = "small" | "medium" | "large" | "full";
|
|
|
228
230
|
|
|
229
231
|
export declare const Namozaj: default_2.ForwardRefExoticComponent<DynamicFormProps & default_2.RefAttributes<any>>;
|
|
230
232
|
|
|
233
|
+
export declare interface NamozajLocalizationOptions {
|
|
234
|
+
locales: string[];
|
|
235
|
+
translatedLabelSuffix?: (label: string, locale: string) => string;
|
|
236
|
+
translatedFieldNameSuffix?: (locale: string) => string;
|
|
237
|
+
translatedFieldGrid?: (field: DynamicFormField, locale: string) => GridColumnConfig;
|
|
238
|
+
}
|
|
239
|
+
|
|
231
240
|
export declare type NumberFieldConfig = BaseFieldConfig & {
|
|
232
241
|
type: "number";
|
|
233
242
|
meta: BaseFieldConfig["meta"] & {
|
package/dist/namozaj.js
CHANGED
|
@@ -4,7 +4,7 @@ var Zn = (e, t, a) => tm(e, typeof t != "symbol" ? t + "" : t, a);
|
|
|
4
4
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import React__default, { useState, useEffect, useMemo, createContext, useContext, createElement, useCallback, isValidElement, cloneElement, Children, useRef, forwardRef, useImperativeHandle, useReducer, Fragment as Fragment$1, Component as Component$1, memo, useLayoutEffect } from "react";
|
|
7
|
-
import { Stack, Box, TextField as TextField$2, IconButton as IconButton$1, InputLabel as InputLabel$1, Autocomplete, InputAdornment as InputAdornment$1, Select as Select$1, MenuItem as MenuItem$1, Tooltip as Tooltip$1, FormControlLabel, Checkbox, FormGroup, FormControl as FormControl$1, RadioGroup, Radio, Switch, Typography as Typography$1, Avatar, Button as Button$1, Slider, Portal as Portal$1, Dialog as Dialog$1, DialogTitle as DialogTitle$1, DialogContent as DialogContent$1, DialogActions as DialogActions$1, FormHelperText as FormHelperText$1, Grid
|
|
7
|
+
import { Stack, Box, TextField as TextField$2, IconButton as IconButton$1, InputLabel as InputLabel$1, Autocomplete, InputAdornment as InputAdornment$1, Select as Select$1, MenuItem as MenuItem$1, Tooltip as Tooltip$1, FormControlLabel, Checkbox, FormGroup, FormControl as FormControl$1, RadioGroup, Radio, Switch, Typography as Typography$1, Avatar, Button as Button$1, Slider, Portal as Portal$1, Dialog as Dialog$1, DialogTitle as DialogTitle$1, DialogContent as DialogContent$1, DialogActions as DialogActions$1, FormHelperText as FormHelperText$1, Grid } from "@mui/material";
|
|
8
8
|
import emStyled from "@emotion/styled";
|
|
9
9
|
import { Global, ThemeContext, keyframes, css } from "@emotion/react";
|
|
10
10
|
const defaultContextValue = {
|
|
@@ -18,7 +18,7 @@ const defaultContextValue = {
|
|
|
18
18
|
}, p = () => {
|
|
19
19
|
t.fields.forEach((f) => {
|
|
20
20
|
var m, y, v;
|
|
21
|
-
|
|
21
|
+
"optionsFetchFnc" in f.meta && ((m = f.meta) != null && m.optionsFetchFnc) && (!(c != null && c[f.name]) || ((y = c == null ? void 0 : c[f.name]) == null ? void 0 : y.length) === 0) && ((v = f.meta) == null || v.optionsFetchFnc().then((b) => {
|
|
22
22
|
u(f.name, b);
|
|
23
23
|
}));
|
|
24
24
|
});
|
|
@@ -4574,6 +4574,32 @@ const getDefaultValue = (e) => {
|
|
|
4574
4574
|
default:
|
|
4575
4575
|
return a;
|
|
4576
4576
|
}
|
|
4577
|
+
}, getTranslatedFieldName = (e, t, a) => {
|
|
4578
|
+
if (a)
|
|
4579
|
+
return `${e.name}${a(t)}`;
|
|
4580
|
+
{
|
|
4581
|
+
const l = t.charAt(0).toUpperCase() + t.slice(1);
|
|
4582
|
+
return `${e.name}${l}`;
|
|
4583
|
+
}
|
|
4584
|
+
}, getTranslatedFieldLabel = (e, t, a) => {
|
|
4585
|
+
if (a)
|
|
4586
|
+
return a(e.meta.label, t);
|
|
4587
|
+
{
|
|
4588
|
+
const l = t.charAt(0).toUpperCase() + t.slice(1);
|
|
4589
|
+
return `${e.meta.label} (${l})`;
|
|
4590
|
+
}
|
|
4591
|
+
}, getTranslatedFieldGrid = (e, t, a) => {
|
|
4592
|
+
var l;
|
|
4593
|
+
return a ? a(e, t) : e.type === "text" && ((l = e.meta) != null && l.multiline) ? {
|
|
4594
|
+
xs: 12,
|
|
4595
|
+
sm: 12,
|
|
4596
|
+
md: 12,
|
|
4597
|
+
lg: 12,
|
|
4598
|
+
xl: 12
|
|
4599
|
+
} : {
|
|
4600
|
+
xs: 12,
|
|
4601
|
+
md: 6
|
|
4602
|
+
};
|
|
4577
4603
|
};
|
|
4578
4604
|
function chainPropTypes(e, t) {
|
|
4579
4605
|
return process.env.NODE_ENV === "production" ? () => null : function(...l) {
|
|
@@ -82434,35 +82460,45 @@ function o(e, t, a) {
|
|
|
82434
82460
|
ModuleRegistry.registerModules([AllCommunityModule]);
|
|
82435
82461
|
const Form = React__default.forwardRef(
|
|
82436
82462
|
(e, t) => {
|
|
82437
|
-
var h, f;
|
|
82463
|
+
var h, f, m;
|
|
82438
82464
|
const a = useMemo(
|
|
82439
82465
|
() => createYupSchema(e.fields),
|
|
82440
|
-
[e, createYupSchema]
|
|
82466
|
+
[e, e.fields, (h = e.localization) == null ? void 0 : h.locales, createYupSchema]
|
|
82441
82467
|
), l = useForm({
|
|
82442
82468
|
resolver: o(a),
|
|
82443
82469
|
defaultValues: e.defaultValues ? e.defaultValues : getDefaultValues(e.fields),
|
|
82444
82470
|
mode: e.validationMode || "onChange"
|
|
82445
|
-
})
|
|
82446
|
-
|
|
82447
|
-
|
|
82471
|
+
});
|
|
82472
|
+
useEffect(() => {
|
|
82473
|
+
const y = Object.keys(l.getValues()), v = e.fields.map((w) => w.name), b = y.filter(
|
|
82474
|
+
(w) => !v.includes(w)
|
|
82475
|
+
);
|
|
82476
|
+
if (b.length > 0) {
|
|
82477
|
+
const w = { ...l.getValues() };
|
|
82478
|
+
b.forEach((S) => {
|
|
82479
|
+
delete w[S];
|
|
82480
|
+
}), l.reset(w);
|
|
82481
|
+
}
|
|
82482
|
+
}, [e.fields]);
|
|
82483
|
+
const c = (y) => {
|
|
82484
|
+
var v;
|
|
82485
|
+
(v = e.onSubmit) == null || v.call(e, y);
|
|
82448
82486
|
}, d = async () => (await l.trigger()).valueOf();
|
|
82449
82487
|
useEffect(() => {
|
|
82450
|
-
const
|
|
82451
|
-
(
|
|
82452
|
-
var
|
|
82453
|
-
if (
|
|
82454
|
-
const
|
|
82455
|
-
(
|
|
82488
|
+
const y = l.watch(
|
|
82489
|
+
(v, { name: b, type: w }) => {
|
|
82490
|
+
var S;
|
|
82491
|
+
if (w === "change" && b) {
|
|
82492
|
+
const x = v[b];
|
|
82493
|
+
(S = e.onChange) == null || S.call(e, {
|
|
82456
82494
|
...l.getValues(),
|
|
82457
|
-
[
|
|
82495
|
+
[b]: x
|
|
82458
82496
|
});
|
|
82459
82497
|
}
|
|
82460
82498
|
}
|
|
82461
82499
|
);
|
|
82462
|
-
return () =>
|
|
82463
|
-
}, [l.watch]),
|
|
82464
|
-
console.log("Form State:", l.watch());
|
|
82465
|
-
}, [l.watch()]), useImperativeHandle(
|
|
82500
|
+
return () => y.unsubscribe();
|
|
82501
|
+
}, [l.watch]), useImperativeHandle(
|
|
82466
82502
|
t,
|
|
82467
82503
|
() => ({
|
|
82468
82504
|
submit: l.handleSubmit(c),
|
|
@@ -82472,38 +82508,64 @@ const Form = React__default.forwardRef(
|
|
|
82472
82508
|
);
|
|
82473
82509
|
const u = e.isNested ? "div" : "form", p = e.isNested ? {} : { onSubmit: l.handleSubmit(c) };
|
|
82474
82510
|
return useEffect(() => {
|
|
82475
|
-
e.error && Object.keys(e.error).forEach((
|
|
82476
|
-
var
|
|
82477
|
-
l.setError(
|
|
82511
|
+
e.error && Object.keys(e.error).forEach((v) => {
|
|
82512
|
+
var b;
|
|
82513
|
+
l.setError(v, {
|
|
82478
82514
|
type: "manual",
|
|
82479
|
-
message: (
|
|
82515
|
+
message: (b = e.error[v]) == null ? void 0 : b.message
|
|
82480
82516
|
});
|
|
82481
82517
|
});
|
|
82482
82518
|
}, [e.error]), useEffect(() => {
|
|
82483
82519
|
}, [l.formState.errors]), /* @__PURE__ */ jsx(FormProvider, { ...l, children: /* @__PURE__ */ jsxs(u, { ...p, children: [
|
|
82484
|
-
/* @__PURE__ */ jsx(Grid, { container: !0, spacing: 2, children: (e.fields || []).map((
|
|
82520
|
+
/* @__PURE__ */ jsx(Grid, { container: !0, spacing: 2, children: (e.fields || []).map((y, v) => /* @__PURE__ */ jsx(
|
|
82485
82521
|
FieldRenderer,
|
|
82486
82522
|
{
|
|
82487
|
-
...
|
|
82523
|
+
...y,
|
|
82488
82524
|
control: l.control
|
|
82489
82525
|
},
|
|
82490
|
-
y
|
|
82526
|
+
y.name || v
|
|
82491
82527
|
)) }),
|
|
82492
|
-
!((
|
|
82528
|
+
!((f = e.defaultSubmitButtonProps) != null && f.hidden) && /* @__PURE__ */ jsx(Box, { mt: 2, children: /* @__PURE__ */ jsx(Button$1, { variant: "contained", color: "primary", type: "submit", children: ((m = e.defaultSubmitButtonProps) == null ? void 0 : m.label) || "Submit" }) })
|
|
82493
82529
|
] }) });
|
|
82494
82530
|
}
|
|
82495
82531
|
), Namozaj = forwardRef(
|
|
82496
82532
|
(e, t) => {
|
|
82497
|
-
|
|
82498
|
-
|
|
82499
|
-
|
|
82533
|
+
const a = useMemo(() => {
|
|
82534
|
+
const l = [];
|
|
82535
|
+
return e.fields.forEach((c) => {
|
|
82536
|
+
var p, h;
|
|
82537
|
+
const d = c.meta || {};
|
|
82538
|
+
if (!(d.translated || !1)) {
|
|
82539
|
+
l.push(c);
|
|
82540
|
+
return;
|
|
82541
|
+
}
|
|
82542
|
+
(h = (p = e.localization) == null ? void 0 : p.locales) == null || h.forEach((f) => {
|
|
82543
|
+
var v, b, w;
|
|
82544
|
+
const m = { ...c }, y = { ...d };
|
|
82545
|
+
m.name = getTranslatedFieldName(
|
|
82546
|
+
c,
|
|
82547
|
+
f,
|
|
82548
|
+
(v = e.localization) == null ? void 0 : v.translatedFieldNameSuffix
|
|
82549
|
+
), y.label = getTranslatedFieldLabel(
|
|
82550
|
+
c,
|
|
82551
|
+
f,
|
|
82552
|
+
(b = e.localization) == null ? void 0 : b.translatedLabelSuffix
|
|
82553
|
+
), y.grid = getTranslatedFieldGrid(
|
|
82554
|
+
c,
|
|
82555
|
+
f,
|
|
82556
|
+
(w = e.localization) == null ? void 0 : w.translatedFieldGrid
|
|
82557
|
+
), m.meta = y, l.push(m);
|
|
82558
|
+
});
|
|
82559
|
+
}), l;
|
|
82560
|
+
}, [e.fields]);
|
|
82561
|
+
return /* @__PURE__ */ jsx(
|
|
82500
82562
|
DynamicFormLocalProvider,
|
|
82501
82563
|
{
|
|
82502
82564
|
value: {
|
|
82503
82565
|
enableRtl: e.enableRtl,
|
|
82504
|
-
fields:
|
|
82566
|
+
fields: a
|
|
82505
82567
|
},
|
|
82506
|
-
children: /* @__PURE__ */ jsx(Form, { ref: t, ...e })
|
|
82568
|
+
children: /* @__PURE__ */ jsx(Form, { ref: t, ...e, fields: a })
|
|
82507
82569
|
}
|
|
82508
82570
|
);
|
|
82509
82571
|
}
|