react-table-edit 1.4.9 → 1.4.10

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.mjs CHANGED
@@ -22988,7 +22988,7 @@ const SelectTable = forwardRef((props, ref) => {
22988
22988
  }, children: jsxs("div", { className: 'r-select-grid', children: [jsx("div", { className: classnames('r-select-gridtable', { 'no-header': noHeader || (columns?.length ?? 0) === 0 }), ref: selectMenuTableRef, style: { width: menuWidth, minWidth: selectTableRef?.current?.clientWidth, maxHeight: maxHeight ?? defaultMaxHeight$1 }, children: jsx(RenderTable, {}) }), jsxs("div", { className: classnames('r-select-footer', { 'd-none': !(showFooter === true || handleAdd) }), children: [jsxs(Button$1, { outline: true, color: "primary", onClick: () => handleAdd?.(), className: classnames('r-btn d-flex align-items-center', { 'd-none': !handleAdd }), children: [jsx(SvgPlus, { className: "me-50", fontSize: 16 }), t('AddNew'), " (F9)"] }), footerComponent ? footerComponent() : null] })] }) }) }) })] }) }) }));
22989
22989
  });
22990
22990
 
22991
- const SelectTableBox = (props) => {
22991
+ const SelectTableBox$1 = (props) => {
22992
22992
  const { isMulti, isLabel, confirmHandle, id, fieldValue, fieldLabel, labelComponent, options, loadOptions, control, placeholder, disabled, name, label, labelSize, required, errors, inLine, callback, desciptionLabel, classLabel, isClearable, defaultValue, handleAddNew, columns, ...rest } = props;
22993
22993
  const handChange = ({ onChange, val }) => {
22994
22994
  onChange((!isNullOrUndefined$1(val) && isMulti) ? val.map((item) => item.value) : ((!isNullOrUndefined$1(val) && !isMulti) ? (fieldValue ? val[fieldValue] : val?.value) : undefined));
@@ -23189,7 +23189,7 @@ const EditForm = forwardRef((props, ref) => {
23189
23189
  return (jsx(Col$1, { xl: 12, onKeyDown: e => formItemKeyDown(e, index), children: jsx(TextInput, { id: `form-element-${field}-${index}`, control: control, name: item.name, label: item.label ? item.label : '', labelSize: `text-left ${labelSize}`, errors: errors[item.name], disabled: item.disabled, callback: () => { elementChange(item.name); } }, index) }, index));
23190
23190
  }
23191
23191
  else if (item.type === 'select') {
23192
- return (jsx(Col$1, { xl: 12, onKeyDown: e => formItemKeyDown(e, index), children: jsx(SelectTableBox, { id: `form-element-${field}-${index}`, options: item.options ?? [], control: control, name: item.name, label: item.label ? item.label : '', labelSize: `text-left ${labelSize}`, errors: errors[item.name], disabled: item.disabled, callback: () => { elementChange(item.name); } }, index) }, index));
23192
+ return (jsx(Col$1, { xl: 12, onKeyDown: e => formItemKeyDown(e, index), children: jsx(SelectTableBox$1, { id: `form-element-${field}-${index}`, options: item.options ?? [], control: control, name: item.name, label: item.label ? item.label : '', labelSize: `text-left ${labelSize}`, errors: errors[item.name], disabled: item.disabled, callback: () => { elementChange(item.name); } }, index) }, index));
23193
23193
  }
23194
23194
  }) }));
23195
23195
  };
@@ -42319,6 +42319,131 @@ const handleCtrlD = (e, params) => {
42319
42319
  }
42320
42320
  };
42321
42321
 
42322
+ const SelectTableBox = (props) => {
42323
+ const { isMulti, isLabel, confirmHandle, id, fieldValue, fieldLabel, labelComponent, options, loadOptions, control, placeholder, disabled, name, label, labelSize, required, errors, inLine, callback, desciptionLabel, classLabel, isClearable, defaultValue, handleAddNew, columns, ...rest } = props;
42324
+ const handChange = ({ onChange, val }) => {
42325
+ onChange((!isNullOrUndefined$1(val) && isMulti) ? val.map((item) => item.value) : ((!isNullOrUndefined$1(val) && !isMulti) ? (fieldValue ? val[fieldValue] : val?.value) : undefined));
42326
+ if (callback) {
42327
+ callback(val);
42328
+ }
42329
+ };
42330
+ const renderLabel = (props) => {
42331
+ const { t } = useTranslation();
42332
+ const { isLabel, desciptionLabel, id, classLabel, name, label, required } = props;
42333
+ return (jsxs(Fragment, { children: [isLabel === false ? '' : jsxs(Label$1, { id: `label-${id}`, className: classLabel, for: name, children: [t(label ? label : ''), " ", required ? jsx("span", { className: "text-danger", children: "*" }) : ''] }), (!isNullOrUndefined$1(desciptionLabel) && desciptionLabel !== '') ?? jsx(Fragment$1, { children: jsx(UncontrolledTooltip, { target: `label-${id}`, children: t(desciptionLabel ?? '') }) })] }));
42334
+ };
42335
+ return (jsx(Fragment, { children: jsxs("div", { className: classnames(inLine === false ? 'form-group ' : 'form-row-inline d-flex', 'align', {
42336
+ [labelSize ? labelSize : '']: labelSize,
42337
+ 'form-row-inline-error': errors
42338
+ }), children: [renderLabel({ isLabel, desciptionLabel, classLabel, name, label, required, id: id ?? '' }), jsxs("div", { className: classnames('form-input-content', { 'hidden-label': isLabel === false }), children: [jsx(Controller, { name: name, control: control, render: ({ field: { value, onChange } }) => {
42339
+ return (jsx(SelectTable, { ...rest, id: id, value: (isMulti ? value?.length > 0 : value) ? (!isMulti ? (options.find((val) => val[fieldValue ?? 'value'] === value) ?? (defaultValue ?? '')) : value) : (isMulti ? [] : undefined),
42340
+ // Giá trị của SelectTable, nếu isMulti là true và value có độ dài lớn hơn 0, hoặc nếu isMulti là false và value có giá trị,
42341
+ // thì tìm giá trị tương ứng trong options hoặc sử dụng defaultValue. Nếu không, sử dụng giá trị mặc định tùy thuộc vào isMulti.
42342
+ onChange: (val) => {
42343
+ if (isMulti || (fieldValue && val ? val[fieldValue] : val?.value) !== value) { // Kiểm tra nếu giá trị mới khác với giá trị hiện tại
42344
+ if (confirmHandle) { // Nếu có hàm confirmHandle
42345
+ confirmHandle(handChange, onChange, val); // Gọi hàm confirmHandle với các tham số tương ứng
42346
+ }
42347
+ else {
42348
+ if (isMulti) {
42349
+ onChange(!isNullOrUndefined$1(val) ? val.map((item) => item[fieldValue ?? 'value']) : []);
42350
+ }
42351
+ else {
42352
+ onChange(!isNullOrUndefined$1(val) ? val[fieldValue ?? 'value'] : undefined);
42353
+ }
42354
+ // Nếu giá trị mới không null hoặc undefined và isMulti là true, thì lấy mảng các giá trị.
42355
+ // Nếu isMulti là false, lấy giá trị mới hoặc giá trị của fieldValue.
42356
+ if (callback) { // Nếu có hàm callback
42357
+ callback(val); // Gọi hàm callback với giá trị mới
42358
+ }
42359
+ }
42360
+ }
42361
+ }, handleAdd: handleAddNew, isClearable: isClearable, isMulti: isMulti, placeholder: placeholder, invalid: errors, loadOptions: loadOptions, options: options, isDisabled: disabled, columns: columns, fieldValue: fieldValue, fieldLabel: fieldLabel, formatOptionLabel: labelComponent ? labelComponent : undefined }));
42362
+ } }), errors && jsx(FormFeedback$1, { children: errors?.message })] })] }) }));
42363
+ };
42364
+
42365
+ const EditFormInline = forwardRef((props, ref) => {
42366
+ const { id, field, rowData, onChange, onChangeField, onKeyDown, defaultValues, schema, indexRow, template, displayValue, onFormOpen, labelSize = 'label-small' } = props;
42367
+ useRef(null);
42368
+ useRef(null);
42369
+ const [itemsField, setItemsField] = useState([]);
42370
+ const [onFocus, setOnFocus] = useState(false);
42371
+ useTranslation();
42372
+ const { control, handleSubmit, getValues, reset, setValue, formState: { errors } } = useForm({
42373
+ mode: 'onChange',
42374
+ defaultValues,
42375
+ resolver: o(schema)
42376
+ });
42377
+ const focusElement = (id, focus) => {
42378
+ const element = document.getElementById(id);
42379
+ if (element) {
42380
+ if (element.className.includes('react-select')) {
42381
+ element.getElementsByTagName('input')[0]?.focus();
42382
+ }
42383
+ else {
42384
+ element.focus();
42385
+ if (focus) {
42386
+ element.setSelectionRange(0, element.innerText.length - 1);
42387
+ }
42388
+ }
42389
+ }
42390
+ };
42391
+ const handleOnKeyDown = (e) => {
42392
+ };
42393
+ const formKeyDown = (e, handSubmit) => {
42394
+ if (e.code === 'Enter') {
42395
+ handSubmit();
42396
+ e.preventDefault();
42397
+ e.stopPropagation();
42398
+ }
42399
+ };
42400
+ const formItemKeyDown = (e, index) => {
42401
+ if (e.code === 'ArrowRight' && index < itemsField.length - 1) {
42402
+ focusElement(`form-element-${field}-${index + 1}`);
42403
+ e.preventDefault();
42404
+ e.stopPropagation();
42405
+ }
42406
+ else if (e.code === 'ArrowLeft' && index > 0) {
42407
+ focusElement(`form-element-${field}-${index - 1}`);
42408
+ e.preventDefault();
42409
+ e.stopPropagation();
42410
+ }
42411
+ };
42412
+ const elementChange = (field) => {
42413
+ if (onChangeField) {
42414
+ onChangeField(rowData, field, setValue, getValues);
42415
+ const rs = getValues();
42416
+ if (rs) {
42417
+ onChange(rs);
42418
+ }
42419
+ }
42420
+ };
42421
+ useEffect(() => {
42422
+ if (onFocus && itemsField.length > 0) {
42423
+ itemsField.forEach((ele) => {
42424
+ setValue(ele.name, (rowData[ele.name] ?? ""));
42425
+ });
42426
+ focusElement(`form-element-${field}-${0}`);
42427
+ }
42428
+ }, [onFocus, itemsField]);
42429
+ return (jsxs("div", { className: "form-edit-inline", ref: ref, id: id, children: [!onFocus && jsx("div", { className: "form__display", onClick: () => {
42430
+ if (onFormOpen && itemsField.length === 0) {
42431
+ onFormOpen(rowData, itemsField, setItemsField);
42432
+ }
42433
+ setOnFocus(true);
42434
+ }, onKeyDown: e => formKeyDown(e, handleSubmit), children: template ? template(rowData, indexRow) : displayValue }), jsx("div", { className: `form__edit ${onFocus ? 'active' : ''}`, onKeyDown: e => handleOnKeyDown(), children: itemsField.map((item, index) => {
42435
+ if (item.type === 'numeric') {
42436
+ return (jsx("div", { className: "form__element", onKeyDown: e => formItemKeyDown(e, index), children: jsx(NumberInput, { id: `form-element-${field}-${index}`, control: control, name: item.name, label: item.label ? item.label : '', labelSize: `${labelSize}`, errors: errors[item.name], disabled: item.disabled, min: item.min, max: item.max, inLine: false, fractionCurrency: item.fraction, callback: () => { elementChange(item.name); } }, index) }, index));
42437
+ }
42438
+ else if (item.type === 'text') {
42439
+ return (jsx("div", { className: "form__element", onKeyDown: e => formItemKeyDown(e, index), children: jsx(TextInput, { id: `form-element-${field}-${index}`, control: control, name: item.name, label: item.label ? item.label : '', labelSize: `${labelSize}`, inLine: false, errors: errors[item.name], disabled: item.disabled, callback: () => { elementChange(item.name); } }, index) }, index));
42440
+ }
42441
+ else if (item.type === 'select') {
42442
+ return (jsx("div", { className: "form__element", onKeyDown: e => formItemKeyDown(e, index), children: jsx(SelectTableBox, { id: `form-element-${field}-${index}`, options: item.options ?? [], control: control, name: item.name, label: item.label ? item.label : '', labelSize: `${labelSize}`, inLine: false, errors: errors[item.name], disabled: item.disabled, callback: () => { elementChange(item.name); } }, index) }, index));
42443
+ }
42444
+ }) })] }));
42445
+ });
42446
+
42322
42447
  const TableEdit = forwardRef((props, ref) => {
42323
42448
  const { t } = useTranslation();
42324
42449
  const { idTable, dataSource, columns, commandClick, dataSourceChange, rowChange, pagingSetting, setDataSource, height, maxHeight, minHeight, defaultValue, toolbarSetting, searchSetting, setSelectedItem, selectedItem, selectEnable, editDisable, addDisable, buttonSetting, formatSetting, handleSelect, haveSum, isMulti, disableAutoKey, onDuplicate } = props;
@@ -42703,6 +42828,18 @@ const TableEdit = forwardRef((props, ref) => {
42703
42828
  e.preventDefault();
42704
42829
  }
42705
42830
  } }));
42831
+ case 'formInline':
42832
+ return (jsx(EditFormInline, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, ...col.formSettings, field: col.field, displayValue: col.formSettings?.displayValue ? col.formSettings?.displayValue(row) : '', placeholder: col.placeholder ? t(col.placeholder) : '', rowData: row, indexRow: indexRow, onChange: (val) => {
42833
+ Object.assign(row, val);
42834
+ handleDataChange(row, col, indexRow);
42835
+ }, invalid: col.validate && col.validate(row[col.field], row), textAlign: col.textAlign, template: col.template, onKeyDown: (e) => {
42836
+ return checkKeyDown(e, row, col, indexRow + 1, indexCol + 1);
42837
+ }, onPaste: (e) => {
42838
+ if (toolbarSetting?.showBottomToolbar && !editDisable && !addDisable && !col.disablePaste) {
42839
+ pasteDataFromExcel(indexRow, indexCol, e);
42840
+ e.preventDefault();
42841
+ }
42842
+ } }));
42706
42843
  default:
42707
42844
  return (jsx(Input$1, { id: `${idTable}-col${indexCol + 1}-row${indexRow + 1}`, style: { textAlign: col.textAlign, height: 29 }, value: isNullOrUndefined$1(row[col.field]) ? '' : row[col.field], className: classnames('border-0 rounded-0 input-element', { 'is-invalid': col.validate && col.validate(row[col.field], row) }), onChange: (val) => {
42708
42845
  if (row[col.field] != val.target?.value) {
@@ -43118,9 +43255,7 @@ const TableEdit = forwardRef((props, ref) => {
43118
43255
  const errorMessage = typeDis === 1 || col.field === '' || !col.validate ? '' : col.validate(row[col.field], row);
43119
43256
  return (jsx(Fragment, { children: col.visible !== false && jsx("td", { className: classnames(`r-rowcell fix-${col.fixedType}`, { 'cell-fixed': col.fixedType }, { 'r-active': (isSelected && editDisable) || indexFocus === indexRow }), style: {
43120
43257
  left: col.fixedType === 'left' ? objWidthFix[indexCol] : undefined,
43121
- right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined,
43122
- padding: 0,
43123
- textAlign: col.textAlign ? col.textAlign : 'left'
43258
+ right: col.fixedType === 'right' ? objWidthFix[indexCol] : undefined
43124
43259
  }, onClick: (e) => {
43125
43260
  if (e.target.nodeName === 'DIV' || e.target.nodeName === 'TD') {
43126
43261
  if (!editDisable && indexRow != indexFocus) {
@@ -43150,8 +43285,8 @@ const TableEdit = forwardRef((props, ref) => {
43150
43285
  e.stopPropagation();
43151
43286
  }
43152
43287
  }, children: jsx("div", { className: classnames('r-rowcell-div'), children: jsxs("div", { id: indexFocus === indexRow && typeDis !== 1 ? `${idTable}-col${indexCol + 1}-row${indexRow + 1}` : '', className: classnames('r-rowcell-content', { 'r-is-invalid': errorMessage }), style: {
43153
- margin: typeDis === 1 ? 2 : !errorMessage ? '7px 9px' : 2
43154
- }, children: [typeDis === 1 && !refreshRow ? RenderEdit(row, col, indexCol, indexRow) : jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsx(SvgAlertCircle, { fontSize: 15.5 }) }), (!(typeDis === 1 && !refreshRow)) && jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
43288
+ textAlign: col.textAlign ? col.textAlign : 'left'
43289
+ }, children: [typeDis === 1 && !refreshRow ? RenderEdit(row, col, indexCol, indexRow) : jsx(Fragment$1, { children: typeDis === 2 ? (col.template && col.template(row, indexRow)) ?? '' : jsx("div", { id: `content-${idTable}-row${indexRow}col-${indexCol}`, className: "r-cell-text", children: (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }) }), jsx("span", { id: `error-${indexRow}-${indexCol}`, className: classnames('cursor-pointer text-primary icon-table', { 'd-none': !errorMessage }), children: jsx(SvgAlertCircle, { fontSize: 15.5 }) }), (!(typeDis === 1 && !refreshRow) && typeDis !== 2) && jsx(UncontrolledTooltip, { className: "r-tooltip", autohide: false, target: `content-${idTable}-row${indexRow}col-${indexCol}`, children: (col.editType === 'numeric' && Number(row[col.field]) < 0 ? jsxs("div", { style: { color: formatSetting?.colorNegative ?? 'red' }, children: [" ", `${formatSetting?.prefixNegative ?? '-'}${value}${formatSetting?.suffixNegative ?? ''}`] }) : value) }), jsx(UncontrolledTooltip, { target: `error-${indexRow}-${indexCol}`, className: "r-tooltip tooltip-error", children: errorMessage?.toString() ?? '' })] }) }) }, `col-${indexRow}-${indexCol}`) }, indexCol));
43155
43290
  }
43156
43291
  };
43157
43292
  const renderFooterCol = (col, indexCol) => {
@@ -64942,7 +65077,7 @@ const TabSelectFileImportExcel = (props) => {
64942
65077
  getSheetsExcel(e.target.files[0], setValue, setOptionSheetName);
64943
65078
  }, hidden: true, accept: '.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel' })] })] }) : jsxs(Fragment$1, { children: [jsx("div", { className: 'fs-4 bolder', children: t('Drag and drop files here') }), jsx("div", { className: 'my-50', children: t('or') }), jsxs(Button$1, { tag: Label$1, outline: true, className: 'me-75', size: 'md', color: 'primary', children: [jsx(SvgArrowLeftCircle, { fontSize: 18, className: 'me-50' }), t('Select file'), jsx(Input$1, { type: 'file', onChange: (e) => {
64944
65079
  getSheetsExcel(e.target.files[0], setValue, setOptionSheetName);
64945
- }, hidden: true, accept: '.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel' })] }), jsx("div", { className: 'mt-1', children: t('Accepts .xls, .xlsx, .csv files') })] }) }), jsxs(Row$1, { className: `${getValues('file') ? '' : 'd-none'} m-0 gy-1`, children: [jsx(Col$1, { lg: 6, md: 12, xs: 12, children: jsx(SelectTableBox, { labelSize: "d-flex form-row-inline label-medium", control: control, name: "sheetId", label: t("Sheet name"), required: true, errors: errors.sheetId, placeholder: t("Select"), options: optionSheetName }) }), jsx(Col$1, { lg: 6, md: 12, xs: 12, children: jsx(NumberInput, { control: control, name: "headerRow", labelSize: "d-flex form-row-inline label-medium", label: t("Header row"), errors: errors.headerRow }) })] })] }));
65080
+ }, hidden: true, accept: '.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel' })] }), jsx("div", { className: 'mt-1', children: t('Accepts .xls, .xlsx, .csv files') })] }) }), jsxs(Row$1, { className: `${getValues('file') ? '' : 'd-none'} m-0 gy-1`, children: [jsx(Col$1, { lg: 6, md: 12, xs: 12, children: jsx(SelectTableBox$1, { labelSize: "d-flex form-row-inline label-medium", control: control, name: "sheetId", label: t("Sheet name"), required: true, errors: errors.sheetId, placeholder: t("Select"), options: optionSheetName }) }), jsx(Col$1, { lg: 6, md: 12, xs: 12, children: jsx(NumberInput, { control: control, name: "headerRow", labelSize: "d-flex form-row-inline label-medium", label: t("Header row"), errors: errors.headerRow }) })] })] }));
64946
65081
  };
64947
65082
 
64948
65083
  const TabMergeImportExcel = (props) => {