@nubitio/devextreme 0.6.8 → 0.7.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/index.cjs +80 -85
- package/dist/index.mjs +80 -85
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -122,16 +122,17 @@ function mergeGridFilters(routingFilters, dxFilter, fields) {
|
|
|
122
122
|
}
|
|
123
123
|
//#endregion
|
|
124
124
|
//#region packages/devextreme/mapFieldsToDxColumns.ts
|
|
125
|
+
const DX_DATA_TYPE_BY_KIND = {
|
|
126
|
+
number: "number",
|
|
127
|
+
date: "date",
|
|
128
|
+
datetime: "datetime",
|
|
129
|
+
checkbox: "boolean",
|
|
130
|
+
switch: "boolean"
|
|
131
|
+
};
|
|
125
132
|
function resolveDataType(field) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
case _nubitio_crud.FieldType.DATE: return "date";
|
|
130
|
-
case _nubitio_crud.FieldType.DATETIME: return "datetime";
|
|
131
|
-
case _nubitio_crud.FieldType.CHECKBOX:
|
|
132
|
-
case _nubitio_crud.FieldType.SWITCH: return "boolean";
|
|
133
|
-
default: return field.valueType === "number" ? "number" : field.valueType === "date" ? "date" : field.valueType === "datetime" ? "datetime" : field.valueType === "boolean" ? "boolean" : "string";
|
|
134
|
-
}
|
|
133
|
+
const fromKind = DX_DATA_TYPE_BY_KIND[(0, _nubitio_crud.getFieldTypeModule)(field.type).controlKind ?? "text"];
|
|
134
|
+
if (fromKind) return fromKind;
|
|
135
|
+
return field.valueType === "number" ? "number" : field.valueType === "date" ? "date" : field.valueType === "datetime" ? "datetime" : field.valueType === "boolean" ? "boolean" : "string";
|
|
135
136
|
}
|
|
136
137
|
function mapFieldsToDxColumns(fields, visibleColumns) {
|
|
137
138
|
return fields.filter((field) => field.visible && !field.hidden).filter((field) => visibleColumns == null || visibleColumns.includes(field.name)).sort((left, right) => (left.order ?? Number.MAX_SAFE_INTEGER) - (right.order ?? Number.MAX_SAFE_INTEGER)).map((field) => ({
|
|
@@ -648,38 +649,47 @@ function DevExtremeFormDetailGrid({ fields, rows, allowAdding = false, allowUpda
|
|
|
648
649
|
}
|
|
649
650
|
//#endregion
|
|
650
651
|
//#region packages/devextreme/mapFieldsToDxFormItems.ts
|
|
652
|
+
const DX_EDITOR_BY_KIND = {
|
|
653
|
+
text: "dxTextBox",
|
|
654
|
+
password: "dxTextBox",
|
|
655
|
+
textarea: "dxTextArea",
|
|
656
|
+
number: "dxNumberBox",
|
|
657
|
+
date: "dxDateBox",
|
|
658
|
+
datetime: "dxDateBox",
|
|
659
|
+
select: "dxSelectBox",
|
|
660
|
+
radio: "dxSelectBox",
|
|
661
|
+
switch: "dxSwitch",
|
|
662
|
+
checkbox: "dxCheckBox",
|
|
663
|
+
file: "dxTextBox",
|
|
664
|
+
tags: "dxSelectBox",
|
|
665
|
+
html: "dxTextBox",
|
|
666
|
+
none: "dxTextBox"
|
|
667
|
+
};
|
|
668
|
+
const OPTION_LIST_KINDS = new Set([
|
|
669
|
+
"select",
|
|
670
|
+
"radio",
|
|
671
|
+
"tags"
|
|
672
|
+
]);
|
|
673
|
+
function controlKind(field) {
|
|
674
|
+
return (0, _nubitio_crud.getFieldTypeModule)(field.type).controlKind ?? "text";
|
|
675
|
+
}
|
|
651
676
|
function resolveEditorType(field) {
|
|
652
|
-
|
|
653
|
-
case _nubitio_crud.FieldType.TEXT:
|
|
654
|
-
case _nubitio_crud.FieldType.PASSWORD: return "dxTextBox";
|
|
655
|
-
case _nubitio_crud.FieldType.TEXTAREA: return "dxTextArea";
|
|
656
|
-
case _nubitio_crud.FieldType.NUMBER:
|
|
657
|
-
case _nubitio_crud.FieldType.CURRENCY: return "dxNumberBox";
|
|
658
|
-
case _nubitio_crud.FieldType.DATE: return "dxDateBox";
|
|
659
|
-
case _nubitio_crud.FieldType.DATETIME: return "dxDateBox";
|
|
660
|
-
case _nubitio_crud.FieldType.CHECKBOX: return "dxCheckBox";
|
|
661
|
-
case _nubitio_crud.FieldType.SWITCH: return "dxSwitch";
|
|
662
|
-
case _nubitio_crud.FieldType.SELECT:
|
|
663
|
-
case _nubitio_crud.FieldType.ENUM:
|
|
664
|
-
case _nubitio_crud.FieldType.ENTITY:
|
|
665
|
-
case _nubitio_crud.FieldType.RADIO:
|
|
666
|
-
case _nubitio_crud.FieldType.TAGS: return "dxSelectBox";
|
|
667
|
-
default: return "dxTextBox";
|
|
668
|
-
}
|
|
677
|
+
return DX_EDITOR_BY_KIND[controlKind(field)];
|
|
669
678
|
}
|
|
670
679
|
function resolveEditorOptions(field) {
|
|
680
|
+
const kind = controlKind(field);
|
|
671
681
|
const options = {};
|
|
672
|
-
if (
|
|
673
|
-
if (
|
|
682
|
+
if (kind === "password") options.mode = "password";
|
|
683
|
+
if (kind === "textarea") options.height = field.height ?? 96;
|
|
674
684
|
if (field.maxLength != null) options.maxLength = field.maxLength;
|
|
675
|
-
if (
|
|
685
|
+
if (OPTION_LIST_KINDS.has(kind)) {
|
|
676
686
|
options.dataSource = field.data ?? [];
|
|
677
687
|
options.displayExpr = field.textField || "label";
|
|
678
688
|
options.valueExpr = field.valueField || "value";
|
|
679
689
|
options.searchEnabled = field.searchEnabled;
|
|
680
690
|
}
|
|
681
691
|
if (field.format) options.format = field.format;
|
|
682
|
-
if (field.precision > 0 &&
|
|
692
|
+
if (field.precision > 0 && kind === "number") options.format = field.format || `#,##0.${"0".repeat(field.precision)}`;
|
|
683
693
|
return options;
|
|
684
694
|
}
|
|
685
695
|
function mapFieldsToDxFormItems(fields) {
|
|
@@ -736,63 +746,50 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
736
746
|
const scopedFormErrorsEvent = `${_nubitio_crud.FORM_ERRORS_EVENT}:${(0, react.useId)()}`;
|
|
737
747
|
const appliedOperationRef = (0, react.useRef)(null);
|
|
738
748
|
const [detailDirty, setDetailDirty] = (0, react.useState)(false);
|
|
739
|
-
const {
|
|
749
|
+
const { accessors, formData, detailRows, fieldState, setFieldState, errors, setErrors, detailErrors, setDetailErrors, setNextFormData, setNextDetailRows, setFieldValue, setEditMode, resetUploadSession, resetPrependData, setExistingMedia, clearExistingMedia, upsertUploadedFile } = (0, _nubitio_crud.useFormState)({
|
|
740
750
|
fields: options.fields,
|
|
741
751
|
onFieldDataChanged: options.onFieldDataChanged
|
|
742
752
|
});
|
|
743
753
|
const detailPropertyName = options.detailPropertyName ?? "items";
|
|
744
754
|
const formItems = (0, react.useMemo)(() => mapFieldsToDxFormItems(options.fields), [options.fields]);
|
|
745
755
|
const detailRowsWithKeys = (0, react.useMemo)(() => withDetailRowKeys(detailRows), [detailRows]);
|
|
756
|
+
const validateForm = (0, react.useCallback)(() => {
|
|
757
|
+
const nextErrors = {};
|
|
758
|
+
options.fields.forEach((field) => {
|
|
759
|
+
const state = fieldState[field.name];
|
|
760
|
+
if (field.isIdentity || state?.validationEnabled === false || state?.hidden === true || field.hidden || field.visibleOnForm === false) return;
|
|
761
|
+
let value = accessors.getFieldValue(field.name);
|
|
762
|
+
if (field.type === _nubitio_crud.FieldType.FILE) {
|
|
763
|
+
const uploaded = accessors.getUploadedFile(field.name);
|
|
764
|
+
const hasExisting = accessors.getExistingMedia(field.name) !== null;
|
|
765
|
+
value = uploaded?.iri != null || hasExisting && uploaded === void 0 ? "present" : null;
|
|
766
|
+
}
|
|
767
|
+
const error = validateField(field, value, accessors.getFormData(), t);
|
|
768
|
+
if (error) nextErrors[field.name] = error;
|
|
769
|
+
});
|
|
770
|
+
setErrors(nextErrors);
|
|
771
|
+
setDetailErrors({});
|
|
772
|
+
return Object.keys(nextErrors).length === 0;
|
|
773
|
+
}, [
|
|
774
|
+
accessors,
|
|
775
|
+
fieldState,
|
|
776
|
+
options.fields,
|
|
777
|
+
setDetailErrors,
|
|
778
|
+
setErrors,
|
|
779
|
+
t
|
|
780
|
+
]);
|
|
746
781
|
const validate = (0, _nubitio_crud.useFormValidation)({
|
|
747
782
|
accessors: {
|
|
748
|
-
getDetailRowCount: () =>
|
|
749
|
-
getDetailRows:
|
|
783
|
+
getDetailRowCount: () => accessors.getDetailRows().length,
|
|
784
|
+
getDetailRows: accessors.getDetailRows,
|
|
750
785
|
hasPendingDetailEdits: () => detailDirty,
|
|
751
|
-
validateForm
|
|
752
|
-
const nextErrors = {};
|
|
753
|
-
options.fields.forEach((field) => {
|
|
754
|
-
const state = fieldState[field.name];
|
|
755
|
-
if (field.isIdentity || state?.validationEnabled === false || state?.hidden === true || field.hidden || field.visibleOnForm === false) return;
|
|
756
|
-
let value = formDataRef.current[field.name];
|
|
757
|
-
if (field.type === _nubitio_crud.FieldType.FILE) {
|
|
758
|
-
const uploaded = uploadedFiles.current.find((file) => file.name === field.name);
|
|
759
|
-
const hasExisting = !!existingMediaByField.current[field.name];
|
|
760
|
-
value = uploaded?.iri != null || hasExisting && uploaded === void 0 ? "present" : null;
|
|
761
|
-
}
|
|
762
|
-
const error = validateField(field, value, formDataRef.current, t);
|
|
763
|
-
if (error) nextErrors[field.name] = error;
|
|
764
|
-
});
|
|
765
|
-
setErrors(nextErrors);
|
|
766
|
-
setDetailErrors({});
|
|
767
|
-
return Object.keys(nextErrors).length === 0;
|
|
768
|
-
}, [
|
|
769
|
-
existingMediaByField,
|
|
770
|
-
fieldState,
|
|
771
|
-
formDataRef,
|
|
772
|
-
options.fields,
|
|
773
|
-
setDetailErrors,
|
|
774
|
-
setErrors,
|
|
775
|
-
t,
|
|
776
|
-
uploadedFiles
|
|
777
|
-
])
|
|
786
|
+
validateForm
|
|
778
787
|
},
|
|
779
788
|
detailFields: options.detailFields,
|
|
780
789
|
detailNoDataText: options.requiredDetail ? t("form.detailRequired") : t("form.detailEmpty"),
|
|
781
790
|
requiredDetail: options.requiredDetail,
|
|
782
791
|
validationErrorText: t("form.validationError")
|
|
783
792
|
});
|
|
784
|
-
const submitAccessors = (0, react.useMemo)(() => ({
|
|
785
|
-
getDetailRows: () => detailRowsRef.current,
|
|
786
|
-
getFieldValue: (field) => formDataRef.current[field],
|
|
787
|
-
getFormData: () => formDataRef.current,
|
|
788
|
-
getUploadedFiles: () => uploadedFiles.current,
|
|
789
|
-
isEditMode: () => isEdit.current
|
|
790
|
-
}), [
|
|
791
|
-
detailRowsRef,
|
|
792
|
-
formDataRef,
|
|
793
|
-
isEdit,
|
|
794
|
-
uploadedFiles
|
|
795
|
-
]);
|
|
796
793
|
const { handleSave, handleDelete } = (0, _nubitio_crud.useFormSubmit)({
|
|
797
794
|
url: options.url,
|
|
798
795
|
detailUrl: options.detailUrl,
|
|
@@ -809,7 +806,7 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
809
806
|
onDeleteSuccess: options.onDeleteSuccess,
|
|
810
807
|
onDeleteError: options.onDeleteError,
|
|
811
808
|
onLoadingChange: options.onLoadingChange
|
|
812
|
-
},
|
|
809
|
+
}, accessors, emit, validate);
|
|
813
810
|
const handleSaveRef = (0, react.useRef)(handleSave);
|
|
814
811
|
handleSaveRef.current = handleSave;
|
|
815
812
|
const handleDeleteRef = (0, react.useRef)(handleDelete);
|
|
@@ -831,12 +828,12 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
831
828
|
setNextDetailRows([]);
|
|
832
829
|
setDetailDirty(false);
|
|
833
830
|
resetPrependData();
|
|
834
|
-
setNextFormData(payload ? (0, _nubitio_crud.normalizeFormData)(payload, options.fields, options.adapter,
|
|
831
|
+
setNextFormData(payload ? (0, _nubitio_crud.normalizeFormData)(payload, options.fields, options.adapter, accessors.getPrependDataMap()) : (0, _nubitio_crud.buildEmptyRow)(options.fields));
|
|
835
832
|
setEditMode(false);
|
|
836
833
|
}, [
|
|
834
|
+
accessors,
|
|
837
835
|
options.adapter,
|
|
838
836
|
options.fields,
|
|
839
|
-
prependDataRef,
|
|
840
837
|
resetPrependData,
|
|
841
838
|
resetUploadSession,
|
|
842
839
|
setDetailErrors,
|
|
@@ -849,7 +846,7 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
849
846
|
const applyEditPayload = (0, react.useCallback)((payload) => {
|
|
850
847
|
resetPrependData();
|
|
851
848
|
captureExistingMedia(payload.row);
|
|
852
|
-
const row = (0, _nubitio_crud.normalizeFormData)(payload.row, options.fields, options.adapter,
|
|
849
|
+
const row = (0, _nubitio_crud.normalizeFormData)(payload.row, options.fields, options.adapter, accessors.getPrependDataMap());
|
|
853
850
|
resetUploadSession();
|
|
854
851
|
setErrors({});
|
|
855
852
|
setDetailErrors({});
|
|
@@ -862,13 +859,13 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
862
859
|
emit(_nubitio_crud.FORM_EVENTS.LOADING, true);
|
|
863
860
|
(0, _nubitio_crud.loadDetailRows)(httpClient, detailUrl, options.adapter).then((rows) => setNextDetailRows(withDetailRowKeys(rows))).finally(() => emit(_nubitio_crud.FORM_EVENTS.LOADING, false));
|
|
864
861
|
}, [
|
|
862
|
+
accessors,
|
|
865
863
|
captureExistingMedia,
|
|
866
864
|
emit,
|
|
867
865
|
httpClient,
|
|
868
866
|
options.adapter,
|
|
869
867
|
options.detailUrl,
|
|
870
868
|
options.fields,
|
|
871
|
-
prependDataRef,
|
|
872
869
|
resetPrependData,
|
|
873
870
|
resetUploadSession,
|
|
874
871
|
setDetailErrors,
|
|
@@ -917,16 +914,16 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
917
914
|
setDetailDirty(true);
|
|
918
915
|
}, [setNextDetailRows]);
|
|
919
916
|
(0, react.useImperativeHandle)(ref, () => ({
|
|
920
|
-
getFormData:
|
|
921
|
-
getFieldValue:
|
|
917
|
+
getFormData: accessors.getFormData,
|
|
918
|
+
getFieldValue: accessors.getFieldValue,
|
|
922
919
|
setFieldValue,
|
|
923
|
-
getDetailData:
|
|
920
|
+
getDetailData: accessors.getDetailRows,
|
|
924
921
|
setDetailData: (data) => setNextDetailRows(data),
|
|
925
922
|
saveDetailData: () => void 0,
|
|
926
923
|
reloadDetailData: () => void 0,
|
|
927
924
|
setValues: (data) => {
|
|
928
925
|
resetPrependData();
|
|
929
|
-
setNextFormData((0, _nubitio_crud.normalizeFormData)(data, options.fields, void 0,
|
|
926
|
+
setNextFormData((0, _nubitio_crud.normalizeFormData)(data, options.fields, void 0, accessors.getPrependDataMap()));
|
|
930
927
|
},
|
|
931
928
|
save: () => handleSaveRef.current(),
|
|
932
929
|
deleteRow: (row) => handleDeleteRef.current({ row }),
|
|
@@ -979,10 +976,8 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
979
976
|
validate,
|
|
980
977
|
setIsEdit: (value) => setEditMode(value)
|
|
981
978
|
}), [
|
|
982
|
-
|
|
983
|
-
formDataRef,
|
|
979
|
+
accessors,
|
|
984
980
|
options.fields,
|
|
985
|
-
prependDataRef,
|
|
986
981
|
resetPrependData,
|
|
987
982
|
setEditMode,
|
|
988
983
|
setErrors,
|
|
@@ -1034,7 +1029,7 @@ const DevExtremeFormView = (0, react.forwardRef)((options, ref) => {
|
|
|
1034
1029
|
}),
|
|
1035
1030
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nubitio_crud.FileUploadField, {
|
|
1036
1031
|
field,
|
|
1037
|
-
existingMedia:
|
|
1032
|
+
existingMedia: accessors.getExistingMedia(field.name),
|
|
1038
1033
|
disabled: fieldState[field.name]?.disabled ?? field.disabled ?? options.editable === false,
|
|
1039
1034
|
readOnly: fieldState[field.name]?.readonly ?? field.readonly ?? options.editable === false,
|
|
1040
1035
|
invalid: !!errors[field.name],
|
package/dist/index.mjs
CHANGED
|
@@ -95,16 +95,17 @@ function mergeGridFilters(routingFilters, dxFilter, fields) {
|
|
|
95
95
|
}
|
|
96
96
|
//#endregion
|
|
97
97
|
//#region packages/devextreme/mapFieldsToDxColumns.ts
|
|
98
|
+
const DX_DATA_TYPE_BY_KIND = {
|
|
99
|
+
number: "number",
|
|
100
|
+
date: "date",
|
|
101
|
+
datetime: "datetime",
|
|
102
|
+
checkbox: "boolean",
|
|
103
|
+
switch: "boolean"
|
|
104
|
+
};
|
|
98
105
|
function resolveDataType(field) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
case FieldType.DATE: return "date";
|
|
103
|
-
case FieldType.DATETIME: return "datetime";
|
|
104
|
-
case FieldType.CHECKBOX:
|
|
105
|
-
case FieldType.SWITCH: return "boolean";
|
|
106
|
-
default: return field.valueType === "number" ? "number" : field.valueType === "date" ? "date" : field.valueType === "datetime" ? "datetime" : field.valueType === "boolean" ? "boolean" : "string";
|
|
107
|
-
}
|
|
106
|
+
const fromKind = DX_DATA_TYPE_BY_KIND[getFieldTypeModule(field.type).controlKind ?? "text"];
|
|
107
|
+
if (fromKind) return fromKind;
|
|
108
|
+
return field.valueType === "number" ? "number" : field.valueType === "date" ? "date" : field.valueType === "datetime" ? "datetime" : field.valueType === "boolean" ? "boolean" : "string";
|
|
108
109
|
}
|
|
109
110
|
function mapFieldsToDxColumns(fields, visibleColumns) {
|
|
110
111
|
return fields.filter((field) => field.visible && !field.hidden).filter((field) => visibleColumns == null || visibleColumns.includes(field.name)).sort((left, right) => (left.order ?? Number.MAX_SAFE_INTEGER) - (right.order ?? Number.MAX_SAFE_INTEGER)).map((field) => ({
|
|
@@ -621,38 +622,47 @@ function DevExtremeFormDetailGrid({ fields, rows, allowAdding = false, allowUpda
|
|
|
621
622
|
}
|
|
622
623
|
//#endregion
|
|
623
624
|
//#region packages/devextreme/mapFieldsToDxFormItems.ts
|
|
625
|
+
const DX_EDITOR_BY_KIND = {
|
|
626
|
+
text: "dxTextBox",
|
|
627
|
+
password: "dxTextBox",
|
|
628
|
+
textarea: "dxTextArea",
|
|
629
|
+
number: "dxNumberBox",
|
|
630
|
+
date: "dxDateBox",
|
|
631
|
+
datetime: "dxDateBox",
|
|
632
|
+
select: "dxSelectBox",
|
|
633
|
+
radio: "dxSelectBox",
|
|
634
|
+
switch: "dxSwitch",
|
|
635
|
+
checkbox: "dxCheckBox",
|
|
636
|
+
file: "dxTextBox",
|
|
637
|
+
tags: "dxSelectBox",
|
|
638
|
+
html: "dxTextBox",
|
|
639
|
+
none: "dxTextBox"
|
|
640
|
+
};
|
|
641
|
+
const OPTION_LIST_KINDS = new Set([
|
|
642
|
+
"select",
|
|
643
|
+
"radio",
|
|
644
|
+
"tags"
|
|
645
|
+
]);
|
|
646
|
+
function controlKind(field) {
|
|
647
|
+
return getFieldTypeModule(field.type).controlKind ?? "text";
|
|
648
|
+
}
|
|
624
649
|
function resolveEditorType(field) {
|
|
625
|
-
|
|
626
|
-
case FieldType.TEXT:
|
|
627
|
-
case FieldType.PASSWORD: return "dxTextBox";
|
|
628
|
-
case FieldType.TEXTAREA: return "dxTextArea";
|
|
629
|
-
case FieldType.NUMBER:
|
|
630
|
-
case FieldType.CURRENCY: return "dxNumberBox";
|
|
631
|
-
case FieldType.DATE: return "dxDateBox";
|
|
632
|
-
case FieldType.DATETIME: return "dxDateBox";
|
|
633
|
-
case FieldType.CHECKBOX: return "dxCheckBox";
|
|
634
|
-
case FieldType.SWITCH: return "dxSwitch";
|
|
635
|
-
case FieldType.SELECT:
|
|
636
|
-
case FieldType.ENUM:
|
|
637
|
-
case FieldType.ENTITY:
|
|
638
|
-
case FieldType.RADIO:
|
|
639
|
-
case FieldType.TAGS: return "dxSelectBox";
|
|
640
|
-
default: return "dxTextBox";
|
|
641
|
-
}
|
|
650
|
+
return DX_EDITOR_BY_KIND[controlKind(field)];
|
|
642
651
|
}
|
|
643
652
|
function resolveEditorOptions(field) {
|
|
653
|
+
const kind = controlKind(field);
|
|
644
654
|
const options = {};
|
|
645
|
-
if (
|
|
646
|
-
if (
|
|
655
|
+
if (kind === "password") options.mode = "password";
|
|
656
|
+
if (kind === "textarea") options.height = field.height ?? 96;
|
|
647
657
|
if (field.maxLength != null) options.maxLength = field.maxLength;
|
|
648
|
-
if (
|
|
658
|
+
if (OPTION_LIST_KINDS.has(kind)) {
|
|
649
659
|
options.dataSource = field.data ?? [];
|
|
650
660
|
options.displayExpr = field.textField || "label";
|
|
651
661
|
options.valueExpr = field.valueField || "value";
|
|
652
662
|
options.searchEnabled = field.searchEnabled;
|
|
653
663
|
}
|
|
654
664
|
if (field.format) options.format = field.format;
|
|
655
|
-
if (field.precision > 0 &&
|
|
665
|
+
if (field.precision > 0 && kind === "number") options.format = field.format || `#,##0.${"0".repeat(field.precision)}`;
|
|
656
666
|
return options;
|
|
657
667
|
}
|
|
658
668
|
function mapFieldsToDxFormItems(fields) {
|
|
@@ -709,63 +719,50 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
709
719
|
const scopedFormErrorsEvent = `${FORM_ERRORS_EVENT}:${useId()}`;
|
|
710
720
|
const appliedOperationRef = useRef(null);
|
|
711
721
|
const [detailDirty, setDetailDirty] = useState(false);
|
|
712
|
-
const {
|
|
722
|
+
const { accessors, formData, detailRows, fieldState, setFieldState, errors, setErrors, detailErrors, setDetailErrors, setNextFormData, setNextDetailRows, setFieldValue, setEditMode, resetUploadSession, resetPrependData, setExistingMedia, clearExistingMedia, upsertUploadedFile } = useFormState({
|
|
713
723
|
fields: options.fields,
|
|
714
724
|
onFieldDataChanged: options.onFieldDataChanged
|
|
715
725
|
});
|
|
716
726
|
const detailPropertyName = options.detailPropertyName ?? "items";
|
|
717
727
|
const formItems = useMemo(() => mapFieldsToDxFormItems(options.fields), [options.fields]);
|
|
718
728
|
const detailRowsWithKeys = useMemo(() => withDetailRowKeys(detailRows), [detailRows]);
|
|
729
|
+
const validateForm = useCallback(() => {
|
|
730
|
+
const nextErrors = {};
|
|
731
|
+
options.fields.forEach((field) => {
|
|
732
|
+
const state = fieldState[field.name];
|
|
733
|
+
if (field.isIdentity || state?.validationEnabled === false || state?.hidden === true || field.hidden || field.visibleOnForm === false) return;
|
|
734
|
+
let value = accessors.getFieldValue(field.name);
|
|
735
|
+
if (field.type === FieldType.FILE) {
|
|
736
|
+
const uploaded = accessors.getUploadedFile(field.name);
|
|
737
|
+
const hasExisting = accessors.getExistingMedia(field.name) !== null;
|
|
738
|
+
value = uploaded?.iri != null || hasExisting && uploaded === void 0 ? "present" : null;
|
|
739
|
+
}
|
|
740
|
+
const error = validateField(field, value, accessors.getFormData(), t);
|
|
741
|
+
if (error) nextErrors[field.name] = error;
|
|
742
|
+
});
|
|
743
|
+
setErrors(nextErrors);
|
|
744
|
+
setDetailErrors({});
|
|
745
|
+
return Object.keys(nextErrors).length === 0;
|
|
746
|
+
}, [
|
|
747
|
+
accessors,
|
|
748
|
+
fieldState,
|
|
749
|
+
options.fields,
|
|
750
|
+
setDetailErrors,
|
|
751
|
+
setErrors,
|
|
752
|
+
t
|
|
753
|
+
]);
|
|
719
754
|
const validate = useFormValidation({
|
|
720
755
|
accessors: {
|
|
721
|
-
getDetailRowCount: () =>
|
|
722
|
-
getDetailRows:
|
|
756
|
+
getDetailRowCount: () => accessors.getDetailRows().length,
|
|
757
|
+
getDetailRows: accessors.getDetailRows,
|
|
723
758
|
hasPendingDetailEdits: () => detailDirty,
|
|
724
|
-
validateForm
|
|
725
|
-
const nextErrors = {};
|
|
726
|
-
options.fields.forEach((field) => {
|
|
727
|
-
const state = fieldState[field.name];
|
|
728
|
-
if (field.isIdentity || state?.validationEnabled === false || state?.hidden === true || field.hidden || field.visibleOnForm === false) return;
|
|
729
|
-
let value = formDataRef.current[field.name];
|
|
730
|
-
if (field.type === FieldType.FILE) {
|
|
731
|
-
const uploaded = uploadedFiles.current.find((file) => file.name === field.name);
|
|
732
|
-
const hasExisting = !!existingMediaByField.current[field.name];
|
|
733
|
-
value = uploaded?.iri != null || hasExisting && uploaded === void 0 ? "present" : null;
|
|
734
|
-
}
|
|
735
|
-
const error = validateField(field, value, formDataRef.current, t);
|
|
736
|
-
if (error) nextErrors[field.name] = error;
|
|
737
|
-
});
|
|
738
|
-
setErrors(nextErrors);
|
|
739
|
-
setDetailErrors({});
|
|
740
|
-
return Object.keys(nextErrors).length === 0;
|
|
741
|
-
}, [
|
|
742
|
-
existingMediaByField,
|
|
743
|
-
fieldState,
|
|
744
|
-
formDataRef,
|
|
745
|
-
options.fields,
|
|
746
|
-
setDetailErrors,
|
|
747
|
-
setErrors,
|
|
748
|
-
t,
|
|
749
|
-
uploadedFiles
|
|
750
|
-
])
|
|
759
|
+
validateForm
|
|
751
760
|
},
|
|
752
761
|
detailFields: options.detailFields,
|
|
753
762
|
detailNoDataText: options.requiredDetail ? t("form.detailRequired") : t("form.detailEmpty"),
|
|
754
763
|
requiredDetail: options.requiredDetail,
|
|
755
764
|
validationErrorText: t("form.validationError")
|
|
756
765
|
});
|
|
757
|
-
const submitAccessors = useMemo(() => ({
|
|
758
|
-
getDetailRows: () => detailRowsRef.current,
|
|
759
|
-
getFieldValue: (field) => formDataRef.current[field],
|
|
760
|
-
getFormData: () => formDataRef.current,
|
|
761
|
-
getUploadedFiles: () => uploadedFiles.current,
|
|
762
|
-
isEditMode: () => isEdit.current
|
|
763
|
-
}), [
|
|
764
|
-
detailRowsRef,
|
|
765
|
-
formDataRef,
|
|
766
|
-
isEdit,
|
|
767
|
-
uploadedFiles
|
|
768
|
-
]);
|
|
769
766
|
const { handleSave, handleDelete } = useFormSubmit({
|
|
770
767
|
url: options.url,
|
|
771
768
|
detailUrl: options.detailUrl,
|
|
@@ -782,7 +779,7 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
782
779
|
onDeleteSuccess: options.onDeleteSuccess,
|
|
783
780
|
onDeleteError: options.onDeleteError,
|
|
784
781
|
onLoadingChange: options.onLoadingChange
|
|
785
|
-
},
|
|
782
|
+
}, accessors, emit, validate);
|
|
786
783
|
const handleSaveRef = useRef(handleSave);
|
|
787
784
|
handleSaveRef.current = handleSave;
|
|
788
785
|
const handleDeleteRef = useRef(handleDelete);
|
|
@@ -804,12 +801,12 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
804
801
|
setNextDetailRows([]);
|
|
805
802
|
setDetailDirty(false);
|
|
806
803
|
resetPrependData();
|
|
807
|
-
setNextFormData(payload ? normalizeFormData(payload, options.fields, options.adapter,
|
|
804
|
+
setNextFormData(payload ? normalizeFormData(payload, options.fields, options.adapter, accessors.getPrependDataMap()) : buildEmptyRow(options.fields));
|
|
808
805
|
setEditMode(false);
|
|
809
806
|
}, [
|
|
807
|
+
accessors,
|
|
810
808
|
options.adapter,
|
|
811
809
|
options.fields,
|
|
812
|
-
prependDataRef,
|
|
813
810
|
resetPrependData,
|
|
814
811
|
resetUploadSession,
|
|
815
812
|
setDetailErrors,
|
|
@@ -822,7 +819,7 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
822
819
|
const applyEditPayload = useCallback((payload) => {
|
|
823
820
|
resetPrependData();
|
|
824
821
|
captureExistingMedia(payload.row);
|
|
825
|
-
const row = normalizeFormData(payload.row, options.fields, options.adapter,
|
|
822
|
+
const row = normalizeFormData(payload.row, options.fields, options.adapter, accessors.getPrependDataMap());
|
|
826
823
|
resetUploadSession();
|
|
827
824
|
setErrors({});
|
|
828
825
|
setDetailErrors({});
|
|
@@ -835,13 +832,13 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
835
832
|
emit(FORM_EVENTS.LOADING, true);
|
|
836
833
|
loadDetailRows(httpClient, detailUrl, options.adapter).then((rows) => setNextDetailRows(withDetailRowKeys(rows))).finally(() => emit(FORM_EVENTS.LOADING, false));
|
|
837
834
|
}, [
|
|
835
|
+
accessors,
|
|
838
836
|
captureExistingMedia,
|
|
839
837
|
emit,
|
|
840
838
|
httpClient,
|
|
841
839
|
options.adapter,
|
|
842
840
|
options.detailUrl,
|
|
843
841
|
options.fields,
|
|
844
|
-
prependDataRef,
|
|
845
842
|
resetPrependData,
|
|
846
843
|
resetUploadSession,
|
|
847
844
|
setDetailErrors,
|
|
@@ -890,16 +887,16 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
890
887
|
setDetailDirty(true);
|
|
891
888
|
}, [setNextDetailRows]);
|
|
892
889
|
useImperativeHandle(ref, () => ({
|
|
893
|
-
getFormData:
|
|
894
|
-
getFieldValue:
|
|
890
|
+
getFormData: accessors.getFormData,
|
|
891
|
+
getFieldValue: accessors.getFieldValue,
|
|
895
892
|
setFieldValue,
|
|
896
|
-
getDetailData:
|
|
893
|
+
getDetailData: accessors.getDetailRows,
|
|
897
894
|
setDetailData: (data) => setNextDetailRows(data),
|
|
898
895
|
saveDetailData: () => void 0,
|
|
899
896
|
reloadDetailData: () => void 0,
|
|
900
897
|
setValues: (data) => {
|
|
901
898
|
resetPrependData();
|
|
902
|
-
setNextFormData(normalizeFormData(data, options.fields, void 0,
|
|
899
|
+
setNextFormData(normalizeFormData(data, options.fields, void 0, accessors.getPrependDataMap()));
|
|
903
900
|
},
|
|
904
901
|
save: () => handleSaveRef.current(),
|
|
905
902
|
deleteRow: (row) => handleDeleteRef.current({ row }),
|
|
@@ -952,10 +949,8 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
952
949
|
validate,
|
|
953
950
|
setIsEdit: (value) => setEditMode(value)
|
|
954
951
|
}), [
|
|
955
|
-
|
|
956
|
-
formDataRef,
|
|
952
|
+
accessors,
|
|
957
953
|
options.fields,
|
|
958
|
-
prependDataRef,
|
|
959
954
|
resetPrependData,
|
|
960
955
|
setEditMode,
|
|
961
956
|
setErrors,
|
|
@@ -1007,7 +1002,7 @@ const DevExtremeFormView = forwardRef((options, ref) => {
|
|
|
1007
1002
|
}),
|
|
1008
1003
|
/* @__PURE__ */ jsx(FileUploadField, {
|
|
1009
1004
|
field,
|
|
1010
|
-
existingMedia:
|
|
1005
|
+
existingMedia: accessors.getExistingMedia(field.name),
|
|
1011
1006
|
disabled: fieldState[field.name]?.disabled ?? field.disabled ?? options.editable === false,
|
|
1012
1007
|
readOnly: fieldState[field.name]?.readonly ?? field.readonly ?? options.editable === false,
|
|
1013
1008
|
invalid: !!errors[field.name],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nubitio/devextreme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "DevExtreme-backed CRUD views for @nubitio/crud — optional drop-in for licensed DevExtreme customers.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"devextreme-react": ">=24.0.0",
|
|
55
55
|
"react": "^18.2.0 || ^19.0.0",
|
|
56
56
|
"react-dom": "^18.2.0 || ^19.0.0",
|
|
57
|
-
"@nubitio/
|
|
58
|
-
"@nubitio/
|
|
59
|
-
"@nubitio/
|
|
57
|
+
"@nubitio/crud": "^0.7.0",
|
|
58
|
+
"@nubitio/ui": "^0.7.0",
|
|
59
|
+
"@nubitio/core": "^0.7.0"
|
|
60
60
|
}
|
|
61
61
|
}
|