@dooherceg/material-react-table 3.2.16 → 3.2.18
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.ts +14 -2
- package/dist/index.esm.js +60 -21
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +61 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6947,6 +6947,8 @@ const resolveFormFields = (table) => {
|
|
|
6947
6947
|
});
|
|
6948
6948
|
};
|
|
6949
6949
|
// Groups form fields by their sectionId, returning an id → entries map.
|
|
6950
|
+
// Generic over any entry shape carrying a sectionId — used for column-only entries
|
|
6951
|
+
// (MRT_FormFieldEntry) and for merged column + additional field entries (MRT_FormRenderEntry) alike.
|
|
6950
6952
|
const groupFieldsBySection = (formFields) => formFields.reduce((acc, field) => {
|
|
6951
6953
|
var _a;
|
|
6952
6954
|
if (field.sectionId === undefined)
|
|
@@ -6954,6 +6956,17 @@ const groupFieldsBySection = (formFields) => formFields.reduce((acc, field) => {
|
|
|
6954
6956
|
const existingFields = (_a = acc[field.sectionId]) !== null && _a !== void 0 ? _a : [];
|
|
6955
6957
|
return Object.assign(Object.assign({}, acc), { [field.sectionId]: [...existingFields, field] });
|
|
6956
6958
|
}, {});
|
|
6959
|
+
// ─── Merging column fields with additional fields ────────────────────────────
|
|
6960
|
+
// Wraps resolved column fields as MRT_FormRenderEntry — tags each with kind: 'column'.
|
|
6961
|
+
const toColumnRenderEntries = (formFields) => formFields.map((formField) => (Object.assign(Object.assign({}, formField), { kind: 'column' })));
|
|
6962
|
+
// Wraps additionalFields as MRT_FormRenderEntry, carrying over their own order/section
|
|
6963
|
+
// so they sort and group alongside column fields instead of always rendering last.
|
|
6964
|
+
const toAdditionalRenderEntries = (additionalFields) => additionalFields.map((additionalField) => ({
|
|
6965
|
+
additionalField,
|
|
6966
|
+
kind: 'additional',
|
|
6967
|
+
order: additionalField.order,
|
|
6968
|
+
sectionId: additionalField.section,
|
|
6969
|
+
}));
|
|
6957
6970
|
// ─── Default Values ───────────────────────────────────────────────────────────
|
|
6958
6971
|
// Resolves a defaultValue that may be a static value or a zero-argument factory function.
|
|
6959
6972
|
const resolveDefaultValue = (defaultValue) => {
|
|
@@ -7016,19 +7029,26 @@ const MRT_NewEntryFormSectionBlock = ({ expandMoreIcon: ExpandIcon, sectionConfi
|
|
|
7016
7029
|
// Uses the same MRT_NewEntryFormSectionBlock and Stack/grid containers as MRT_NewEntryForm
|
|
7017
7030
|
// so the skeleton is pixel-identical to the real form — only the inputs are replaced by Skeletons.
|
|
7018
7031
|
const MRT_NewEntryFormSkeleton = ({ table, }) => {
|
|
7019
|
-
var _a;
|
|
7032
|
+
var _a, _b;
|
|
7020
7033
|
const { formConfig, icons } = table.options;
|
|
7021
7034
|
const sections = (_a = formConfig === null || formConfig === void 0 ? void 0 : formConfig.sections) !== null && _a !== void 0 ? _a : [];
|
|
7022
|
-
|
|
7023
|
-
//
|
|
7024
|
-
|
|
7025
|
-
//
|
|
7026
|
-
const
|
|
7027
|
-
|
|
7035
|
+
// Merge column fields and additional fields — additionalFields are placed into
|
|
7036
|
+
// sections/unsectioned alongside column fields in the real form (MRT_NewEntryForm),
|
|
7037
|
+
// so the skeleton must count them the same way to avoid a cell-count mismatch
|
|
7038
|
+
// once loading finishes.
|
|
7039
|
+
const allEntries = [
|
|
7040
|
+
...toColumnRenderEntries(resolveFormFields(table)),
|
|
7041
|
+
...toAdditionalRenderEntries((_b = formConfig === null || formConfig === void 0 ? void 0 : formConfig.additionalFields) !== null && _b !== void 0 ? _b : []),
|
|
7042
|
+
];
|
|
7043
|
+
// Group entries by section for accurate per-section skeleton cell counts.
|
|
7044
|
+
const entriesBySectionId = groupFieldsBySection(allEntries);
|
|
7045
|
+
// Entries with no section assignment — rendered after all sections, same as the real form.
|
|
7046
|
+
const unsectionedEntries = allEntries.filter(({ sectionId }) => sectionId === undefined);
|
|
7047
|
+
const unsectionedCells = Array.from({ length: unsectionedEntries.length });
|
|
7028
7048
|
return (jsxRuntime.jsxs(Stack, { gap: 2, children: [sections.map((section) => {
|
|
7029
7049
|
var _a, _b;
|
|
7030
7050
|
const fieldCells = Array.from({
|
|
7031
|
-
length: (_b = (_a =
|
|
7051
|
+
length: (_b = (_a = entriesBySectionId[section.id]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
|
|
7032
7052
|
});
|
|
7033
7053
|
return (jsxRuntime.jsx(MRT_NewEntryFormSectionBlock, { expandMoreIcon: icons.ExpandMoreIcon, sectionConfig: section, children: fieldCells.map((_, index) => (jsxRuntime.jsx(Skeleton, { height: '40px', variant: "rounded" }, index))) }, section.id));
|
|
7034
7054
|
}), unsectionedCells.length > 0 && (jsxRuntime.jsx(Stack, { gap: 2, sx: (formConfig === null || formConfig === void 0 ? void 0 : formConfig.columns)
|
|
@@ -7083,27 +7103,32 @@ const MRT_NewEntryForm = ({ table, }) => {
|
|
|
7083
7103
|
if (newEntryModal.isLoading) {
|
|
7084
7104
|
return jsxRuntime.jsx(MRT_NewEntryFormSkeleton, { table: table });
|
|
7085
7105
|
}
|
|
7086
|
-
// Collect all eligible form fields from the table's leaf columns
|
|
7106
|
+
// Collect all eligible form fields from the table's leaf columns.
|
|
7087
7107
|
const allFormFields = resolveFormFields(table);
|
|
7088
7108
|
const additionalFields = (_b = formConfig === null || formConfig === void 0 ? void 0 : formConfig.additionalFields) !== null && _b !== void 0 ? _b : [];
|
|
7109
|
+
// Merge column fields and additional fields into one list so they can be sorted and
|
|
7110
|
+
// grouped together by their shared order/section — an additionalField's order is
|
|
7111
|
+
// otherwise only ever compared against other additional fields, never column fields.
|
|
7112
|
+
const allEntries = [
|
|
7113
|
+
...toColumnRenderEntries(allFormFields),
|
|
7114
|
+
...toAdditionalRenderEntries(additionalFields),
|
|
7115
|
+
];
|
|
7089
7116
|
// Sections sorted by their order value — lower numbers appear first.
|
|
7090
7117
|
const sortedSections = sortByOrder((_c = formConfig === null || formConfig === void 0 ? void 0 : formConfig.sections) !== null && _c !== void 0 ? _c : []);
|
|
7091
|
-
//
|
|
7092
|
-
const
|
|
7093
|
-
// Map of sectionId → its
|
|
7094
|
-
const
|
|
7095
|
-
// Additional fields sorted by order — rendered after all column fields.
|
|
7096
|
-
const sortedAdditionalFields = sortByOrder(additionalFields);
|
|
7118
|
+
// Entries without a section assignment — rendered after all sections.
|
|
7119
|
+
const unsectionedEntries = sortByOrder(allEntries.filter(({ sectionId }) => sectionId === undefined));
|
|
7120
|
+
// Map of sectionId → its entries, used when rendering each section block.
|
|
7121
|
+
const entriesBySection = groupFieldsBySection(allEntries);
|
|
7097
7122
|
return (jsxRuntime.jsxs(Stack, { gap: 2, children: [sortedSections.map((sectionConfig) => {
|
|
7098
7123
|
var _a;
|
|
7099
|
-
const
|
|
7100
|
-
return (jsxRuntime.jsx(MRT_NewEntryFormSectionBlock, { expandMoreIcon: ExpandMoreIcon, sectionConfig: sectionConfig, children:
|
|
7101
|
-
}),
|
|
7124
|
+
const sectionEntries = sortByOrder((_a = entriesBySection[sectionConfig.id]) !== null && _a !== void 0 ? _a : []);
|
|
7125
|
+
return (jsxRuntime.jsx(MRT_NewEntryFormSectionBlock, { expandMoreIcon: ExpandMoreIcon, sectionConfig: sectionConfig, children: sectionEntries.map((entry) => entry.kind === 'column' ? (jsxRuntime.jsx(FormFieldControl, { columnDef: entry.columnDef, columnId: entry.columnId, fieldConfig: entry.fieldConfig, table: table }, entry.columnId)) : (jsxRuntime.jsx(MRT_NewEntryFormAdditionalFieldControl, { additionalField: entry.additionalField, table: table }, entry.additionalField.name))) }, sectionConfig.id));
|
|
7126
|
+
}), unsectionedEntries.length > 0 && (jsxRuntime.jsx(Stack, { gap: 2, sx: (formConfig === null || formConfig === void 0 ? void 0 : formConfig.columns)
|
|
7102
7127
|
? {
|
|
7103
7128
|
display: 'grid',
|
|
7104
7129
|
gridTemplateColumns: `repeat(${formConfig.columns}, 1fr)`,
|
|
7105
7130
|
}
|
|
7106
|
-
: undefined, children:
|
|
7131
|
+
: undefined, children: unsectionedEntries.map((entry) => entry.kind === 'column' ? (jsxRuntime.jsx(FormFieldControl, { columnDef: entry.columnDef, columnId: entry.columnId, fieldConfig: entry.fieldConfig, table: table }, entry.columnId)) : (jsxRuntime.jsx(MRT_NewEntryFormAdditionalFieldControl, { additionalField: entry.additionalField, table: table }, entry.additionalField.name))) }))] }));
|
|
7107
7132
|
};
|
|
7108
7133
|
|
|
7109
7134
|
const MRT_NewEntryFormActionsContext = react.createContext(null);
|
|
@@ -7151,6 +7176,20 @@ const MRT_NewEntryFormProvider = ({ table, children, }) => {
|
|
|
7151
7176
|
const mode = (_a = newEntryModal.mode) !== null && _a !== void 0 ? _a : 'create';
|
|
7152
7177
|
const defaultValues = buildDefaultValues(table, newEntryModal.initialValues, mode);
|
|
7153
7178
|
const methods = reactHookForm.useForm({ defaultValues });
|
|
7179
|
+
// useForm's `defaultValues` is only read once, at first mount. The modal is
|
|
7180
|
+
// opened before the backend data arrives (newEntryModal.isLoading: true,
|
|
7181
|
+
// initialValues: undefined) and stays mounted through the whole loading ->
|
|
7182
|
+
// loaded transition, so once initialValues actually arrives it would
|
|
7183
|
+
// otherwise never reach the already-initialized form. Reset once loading
|
|
7184
|
+
// finishes to pick up the real values.
|
|
7185
|
+
react.useEffect(() => {
|
|
7186
|
+
if (!newEntryModal.isLoading) {
|
|
7187
|
+
methods.reset(defaultValues);
|
|
7188
|
+
}
|
|
7189
|
+
// Only re-run when the loading flag flips — defaultValues is recomputed
|
|
7190
|
+
// every render and must not itself retrigger this (that would wipe out
|
|
7191
|
+
// in-progress user edits on every keystroke-driven re-render).
|
|
7192
|
+
}, [newEntryModal.isLoading]);
|
|
7154
7193
|
// Validates the form and calls the consumer's onSave on success.
|
|
7155
7194
|
const handleSave = methods.handleSubmit(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
7156
7195
|
var _a;
|
|
@@ -7163,7 +7202,7 @@ const MRT_NewEntryFormProvider = ({ table, children, }) => {
|
|
|
7163
7202
|
yield ((_a = formConfig === null || formConfig === void 0 ? void 0 : formConfig.onCancel) === null || _a === void 0 ? void 0 : _a.call(formConfig, { form: methods, mode, table }));
|
|
7164
7203
|
setNewEntryModal({ open: false });
|
|
7165
7204
|
});
|
|
7166
|
-
return (jsxRuntime.jsx(MRT_NewEntryFormActionsContext.Provider, { value: { handleCancel, handleSave }, children: jsxRuntime.jsx(RHF_FormProvider, { methods: methods, onSubmit: handleSave, children: children }) }));
|
|
7205
|
+
return (jsxRuntime.jsx(MRT_NewEntryFormActionsContext.Provider, { value: { handleCancel, handleSave }, children: jsxRuntime.jsx(RHF_FormProvider, { methods: methods, onSubmit: handleSave, style: { display: 'flex', flexDirection: 'column', overflow: 'auto' }, children: children }) }));
|
|
7167
7206
|
};
|
|
7168
7207
|
|
|
7169
7208
|
// Maps TModalPosition.vertical to a CSS alignItems value.
|
|
@@ -9076,6 +9115,8 @@ exports.showRowPinningColumn = showRowPinningColumn;
|
|
|
9076
9115
|
exports.showRowSelectionColumn = showRowSelectionColumn;
|
|
9077
9116
|
exports.showRowSpacerColumn = showRowSpacerColumn;
|
|
9078
9117
|
exports.sortByOrder = sortByOrder;
|
|
9118
|
+
exports.toAdditionalRenderEntries = toAdditionalRenderEntries;
|
|
9119
|
+
exports.toColumnRenderEntries = toColumnRenderEntries;
|
|
9079
9120
|
exports.useDropdownOptions = useDropdownOptions;
|
|
9080
9121
|
exports.useMRT_ColumnVirtualizer = useMRT_ColumnVirtualizer;
|
|
9081
9122
|
exports.useMRT_Effects = useMRT_Effects;
|