@dooherceg/material-react-table 3.2.15 → 3.2.17

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.js CHANGED
@@ -4597,7 +4597,7 @@ const MRT_IconSingleValueEditor = ({ availableIcons, column, iconsList, onChange
4597
4597
  return null;
4598
4598
  return (jsxRuntime.jsxs(Stack, { direction: "row", gap: 1, alignItems: "center", children: [renderIconOption(option, iconsList), jsxRuntime.jsx(Typography, { variant: "body2", children: option.tooltip })] }));
4599
4599
  };
4600
- return (jsxRuntime.jsxs(FormControl, { fullWidth: true, size: "small", children: [jsxRuntime.jsx(InputLabel, { htmlFor: inputId, id: labelId, sx: { '&.Mui-focused': { color: 'text.primary' } }, children: columnLabel }), jsxRuntime.jsx(Select, { displayEmpty: true, id: inputId, label: columnLabel, labelId: labelId, MenuProps: { sx: { zIndex: 9999 } }, name: inputId, onChange: (event) => onChange(event.target.value), renderValue: renderSelectedValue, size: "small", sx: { '& .MuiSelect-Select': { height: 'initial' } }, SelectDisplayProps: {
4600
+ return (jsxRuntime.jsxs(FormControl, { fullWidth: true, size: "small", children: [jsxRuntime.jsx(InputLabel, { htmlFor: inputId, id: labelId, children: columnLabel }), jsxRuntime.jsx(Select, { id: inputId, label: columnLabel, labelId: labelId, MenuProps: { sx: { zIndex: 9999 } }, name: inputId, onChange: (event) => onChange(event.target.value), renderValue: renderSelectedValue, size: "small", sx: { '& .MuiSelect-Select': { height: 'initial' } }, SelectDisplayProps: {
4601
4601
  style: { display: 'flex', alignItems: 'center' },
4602
4602
  }, value: currentValue, children: availableIcons.map((icon) => (jsxRuntime.jsxs(MenuItem, { sx: {
4603
4603
  alignItems: 'center',
@@ -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
- const allFields = resolveFormFields(table);
7023
- // Group field entries by section for accurate per-section skeleton cell counts.
7024
- const fieldsBySectionId = groupFieldsBySection(allFields);
7025
- // Fields with no section assignment — rendered after all sections, same as the real form.
7026
- const unsectionedFields = allFields.filter(({ sectionId }) => sectionId === undefined);
7027
- const unsectionedCells = Array.from({ length: unsectionedFields.length });
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 = fieldsBySectionId[section.id]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
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 sorted by order.
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
- // Fields without a section assignment — rendered after all sections.
7092
- const unsectionedFields = sortByOrder(allFormFields.filter(({ sectionId }) => sectionId === undefined));
7093
- // Map of sectionId → its fields, used when rendering each section block.
7094
- const fieldsBySection = groupFieldsBySection(allFormFields);
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 sectionFields = sortByOrder((_a = fieldsBySection[sectionConfig.id]) !== null && _a !== void 0 ? _a : []);
7100
- return (jsxRuntime.jsx(MRT_NewEntryFormSectionBlock, { expandMoreIcon: ExpandMoreIcon, sectionConfig: sectionConfig, children: sectionFields.map(({ columnId, columnDef, fieldConfig }) => (jsxRuntime.jsx(FormFieldControl, { columnDef: columnDef, columnId: columnId, fieldConfig: fieldConfig, table: table }, columnId))) }, sectionConfig.id));
7101
- }), unsectionedFields.length > 0 && (jsxRuntime.jsx(Stack, { gap: 2, sx: (formConfig === null || formConfig === void 0 ? void 0 : formConfig.columns)
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: unsectionedFields.map(({ columnId, columnDef, fieldConfig }) => (jsxRuntime.jsx(FormFieldControl, { columnDef: columnDef, columnId: columnId, fieldConfig: fieldConfig, table: table }, columnId))) })), sortedAdditionalFields.map((additionalField) => (jsxRuntime.jsx(MRT_NewEntryFormAdditionalFieldControl, { additionalField: additionalField, table: table }, additionalField.name)))] }));
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;
@@ -8591,7 +8630,7 @@ const MRT_TablePaper = (_a) => {
8591
8630
  //@ts-expect-error
8592
8631
  paperProps.ref.current = ref;
8593
8632
  }
8594
- }, style: Object.assign({}, paperProps === null || paperProps === void 0 ? void 0 : paperProps.style), sx: (theme) => (Object.assign({ backgroundImage: 'unset', borderRadius: 0, display: 'flex', flexDirection: 'column', height: '100%', overflow: 'hidden', transition: 'all 100ms ease-in-out' }, parseFromValuesOrFunc(paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx, theme))), children: [jsxRuntime.jsxs(FormControl, { children: [jsxRuntime.jsx(InputLabel, { children: "Test" }), jsxRuntime.jsxs(Select, { children: [jsxRuntime.jsx(MenuItem, { children: "Test 1" }), jsxRuntime.jsx(MenuItem, { children: "Test 2" }), jsxRuntime.jsx(MenuItem, { children: "Test 3" })] })] }), jsxRuntime.jsx(MRT_QuickFiltersBar, { table: table }), jsxRuntime.jsx(MRT_ActiveFilters, { table: table }), enableTopToolbar &&
8633
+ }, style: Object.assign({}, paperProps === null || paperProps === void 0 ? void 0 : paperProps.style), sx: (theme) => (Object.assign({ backgroundImage: 'unset', borderRadius: 0, display: 'flex', flexDirection: 'column', height: '100%', overflow: 'hidden', transition: 'all 100ms ease-in-out' }, parseFromValuesOrFunc(paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx, theme))), children: [jsxRuntime.jsx(MRT_QuickFiltersBar, { table: table }), jsxRuntime.jsx(MRT_ActiveFilters, { table: table }), enableTopToolbar &&
8595
8634
  ((_b = parseFromValuesOrFunc(renderTopToolbar, { table })) !== null && _b !== void 0 ? _b : (jsxRuntime.jsx(MRT_TopToolbar, { table: table }))), jsxRuntime.jsx(MRT_TableContainer, { table: table }), enableBottomToolbar &&
8596
8635
  ((_c = parseFromValuesOrFunc(renderBottomToolbar, { table })) !== null && _c !== void 0 ? _c : (jsxRuntime.jsx(MRT_BottomToolbar, { table: table })))] })));
8597
8636
  };
@@ -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;