drf-react-by-schema 0.6.5 → 0.7.1
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/api.d.ts +7 -13
- package/dist/api.js +77 -77
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable.js +5 -7
- package/dist/components/DialogActions.d.ts +3 -3
- package/dist/components/DialogActions.js +2 -4
- package/dist/components/forms/DialogFormBySchema.d.ts +14 -0
- package/dist/components/forms/DialogFormBySchema.js +61 -0
- package/dist/components/forms/FieldBySchema.d.ts +3 -0
- package/dist/components/forms/FieldBySchema.js +65 -0
- package/dist/components/forms/FormBySchema.d.ts +19 -0
- package/dist/components/forms/FormBySchema.js +164 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +86 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.js +41 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +49 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +41 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +203 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.js +60 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/TextFieldBySchema.js +44 -0
- package/dist/context/APIWrapper.d.ts +5 -5
- package/dist/context/APIWrapper.js +135 -87
- package/dist/context/APIWrapperContext.d.ts +22 -9
- package/dist/context/APIWrapperContext.js +42 -9
- package/dist/context/DRFReactBySchemaContext.d.ts +4 -4
- package/dist/context/DRFReactBySchemaContext.js +5 -5
- package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
- package/dist/context/DRFReactBySchemaProvider.js +7 -10
- package/dist/context/Form.d.ts +1 -1
- package/dist/context/Form.js +13 -14
- package/dist/context/FormContext.js +0 -7
- package/dist/context/Overlays.js +11 -12
- package/dist/index.d.ts +16 -6
- package/dist/index.js +31 -7
- package/dist/styles/layout.d.ts +7 -0
- package/dist/styles/layout.js +2 -1
- package/dist/styles/theme.js +77 -42
- package/dist/utils.d.ts +42 -4
- package/dist/utils.js +22 -18
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -23,12 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.buildDateFormatBySchema = exports.getPatternFormat = exports.reducer = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
26
|
+
exports.slugToCamelCase = exports.buildDateFormatBySchema = exports.getPatternFormat = exports.reducer = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
27
27
|
const Yup = __importStar(require("yup"));
|
|
28
|
-
;
|
|
29
|
-
;
|
|
30
|
-
;
|
|
31
|
-
;
|
|
32
28
|
const emptyByType = (field, forDatabase = false) => {
|
|
33
29
|
if (field.model_default) {
|
|
34
30
|
return field.model_default;
|
|
@@ -41,9 +37,7 @@ const emptyByType = (field, forDatabase = false) => {
|
|
|
41
37
|
if (field.child) {
|
|
42
38
|
return [];
|
|
43
39
|
}
|
|
44
|
-
return
|
|
45
|
-
? undefined
|
|
46
|
-
: null;
|
|
40
|
+
return forDatabase ? undefined : null;
|
|
47
41
|
case 'string':
|
|
48
42
|
case 'email':
|
|
49
43
|
return '';
|
|
@@ -85,7 +79,7 @@ const populateValues = ({ data, schema }) => {
|
|
|
85
79
|
for (const row of data[key]) {
|
|
86
80
|
const value = (0, exports.populateValues)({
|
|
87
81
|
data: row,
|
|
88
|
-
schema: field.child.children
|
|
82
|
+
schema: field.child.children,
|
|
89
83
|
});
|
|
90
84
|
arValues.push(value);
|
|
91
85
|
}
|
|
@@ -94,7 +88,7 @@ const populateValues = ({ data, schema }) => {
|
|
|
94
88
|
}
|
|
95
89
|
values[key] = (0, exports.populateValues)({
|
|
96
90
|
data: data[key],
|
|
97
|
-
schema: field.child.children
|
|
91
|
+
schema: field.child.children,
|
|
98
92
|
});
|
|
99
93
|
continue;
|
|
100
94
|
}
|
|
@@ -102,7 +96,7 @@ const populateValues = ({ data, schema }) => {
|
|
|
102
96
|
values[key] = data[key]
|
|
103
97
|
? {
|
|
104
98
|
value: data[key],
|
|
105
|
-
display_name: (0, exports.getChoiceByValue)(data[key], field.choices)
|
|
99
|
+
display_name: (0, exports.getChoiceByValue)(data[key], field.choices),
|
|
106
100
|
}
|
|
107
101
|
: (0, exports.emptyByType)(field);
|
|
108
102
|
continue;
|
|
@@ -164,7 +158,7 @@ const getYupValidator = (type) => {
|
|
|
164
158
|
}
|
|
165
159
|
return yupFunc.nullable();
|
|
166
160
|
};
|
|
167
|
-
const buildGenericYupValidationSchema = ({ data, schema, many = false, skipFields = [], extraValidators = {} }) => {
|
|
161
|
+
const buildGenericYupValidationSchema = ({ data, schema, many = false, skipFields = [], extraValidators = {}, }) => {
|
|
168
162
|
const yupValidator = {};
|
|
169
163
|
for (const entry of Object.entries(schema)) {
|
|
170
164
|
const [key, field] = entry;
|
|
@@ -180,7 +174,7 @@ const buildGenericYupValidationSchema = ({ data, schema, many = false, skipField
|
|
|
180
174
|
data: data[key],
|
|
181
175
|
extraValidators: Object.prototype.hasOwnProperty.call(extraValidators, key)
|
|
182
176
|
? extraValidators[key]
|
|
183
|
-
: {}
|
|
177
|
+
: {},
|
|
184
178
|
});
|
|
185
179
|
continue;
|
|
186
180
|
}
|
|
@@ -224,16 +218,19 @@ const buildGenericYupValidationSchema = ({ data, schema, many = false, skipField
|
|
|
224
218
|
}
|
|
225
219
|
}
|
|
226
220
|
// console.log({ yupValidator });
|
|
227
|
-
return
|
|
221
|
+
return many
|
|
228
222
|
? Yup.array().of(Yup.object().shape(yupValidator))
|
|
229
223
|
: Yup.object().shape(yupValidator);
|
|
230
224
|
};
|
|
231
225
|
exports.buildGenericYupValidationSchema = buildGenericYupValidationSchema;
|
|
232
|
-
const errorProps = ({
|
|
226
|
+
const errorProps = ({ errors, fieldKey, fieldKeyProp, index, }) => {
|
|
233
227
|
let error;
|
|
234
228
|
let helperText;
|
|
235
229
|
if (index) {
|
|
236
|
-
const hasErrors = errors &&
|
|
230
|
+
const hasErrors = errors &&
|
|
231
|
+
errors[fieldKey] &&
|
|
232
|
+
errors[fieldKey][index] &&
|
|
233
|
+
Boolean(errors[fieldKey][index][fieldKeyProp]);
|
|
237
234
|
error = hasErrors;
|
|
238
235
|
helperText = hasErrors ? errors[fieldKey][index][fieldKeyProp].message : null;
|
|
239
236
|
return { error, helperText };
|
|
@@ -255,7 +252,7 @@ const isTmpId = (id) => {
|
|
|
255
252
|
return id.toString().slice(0, 3) === 'tmp';
|
|
256
253
|
};
|
|
257
254
|
exports.isTmpId = isTmpId;
|
|
258
|
-
|
|
255
|
+
function reducer(state, newState) {
|
|
259
256
|
if (newState === null) {
|
|
260
257
|
return null;
|
|
261
258
|
}
|
|
@@ -263,7 +260,7 @@ const reducer = (state, newState) => {
|
|
|
263
260
|
return newState;
|
|
264
261
|
}
|
|
265
262
|
return Object.assign(Object.assign({}, state), newState);
|
|
266
|
-
}
|
|
263
|
+
}
|
|
267
264
|
exports.reducer = reducer;
|
|
268
265
|
const getPatternFormat = (type) => {
|
|
269
266
|
let format = '';
|
|
@@ -314,3 +311,10 @@ function buildDateFormatBySchema(dateViews) {
|
|
|
314
311
|
return defaultFormat;
|
|
315
312
|
}
|
|
316
313
|
exports.buildDateFormatBySchema = buildDateFormatBySchema;
|
|
314
|
+
const slugToCamelCase = (str) => {
|
|
315
|
+
const ret = str.replace(/_([a-z])/g, function (g) {
|
|
316
|
+
return g[1].toUpperCase();
|
|
317
|
+
});
|
|
318
|
+
return ret;
|
|
319
|
+
};
|
|
320
|
+
exports.slugToCamelCase = slugToCamelCase;
|
package/package.json
CHANGED