react-ui-basics 0.0.193 → 0.0.195

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-ui-basics",
3
- "version": "0.0.193",
3
+ "version": "0.0.195",
4
4
  "description": "",
5
5
  "module": "index.js",
6
6
  "_main": "index.cjs.js",
package/src/Table.tsx CHANGED
@@ -43,7 +43,7 @@ export interface RowProps<T> {
43
43
  onFinishEditing: () => void,
44
44
  handleInputChange: (e: ChangeEvent) => void,
45
45
  setValue: (v: any, t: T, field: keyof T) => void,
46
- setEditing: (t: T, i: number, value?: any, focused?: boolean) => void,
46
+ setEditing: (t: T, row: number, column: number, value?: any, focused?: boolean) => void,
47
47
  onMouseDown?: (e: SyntheticEvent, row: number, column: number) => void,
48
48
  onMouseUp?: (e: SyntheticEvent, row: number, column: number) => void,
49
49
  onMouseEnter?: (e: SyntheticEvent, row: number, column: number) => void,
@@ -88,7 +88,7 @@ export interface TableProps<T> {
88
88
  onRowClick?: (t: T, e: SyntheticEvent) => void,
89
89
  disabled?: (t: T) => boolean,
90
90
  toKey?: (t: T) => number | string,
91
- onChange?: (t: T, cancel: () => void) => void,
91
+ onChange?: (t: T, cancel: () => void, rowIndex: number) => void,
92
92
  rowClassName?: string | ((t: T) => string),
93
93
  onMouseDown?: (e: SyntheticEvent, row: number, column: number) => void,
94
94
  onMouseUp?: (e: SyntheticEvent, row: number, column: number) => void,
@@ -107,6 +107,7 @@ export interface TableState<T> {
107
107
  export interface EditingState<T> {
108
108
  id: number | string
109
109
  value: any
110
+ rowIndex: number
110
111
  columnIndex: number
111
112
  item: T
112
113
  field: keyof T
@@ -114,7 +115,7 @@ export interface EditingState<T> {
114
115
  }
115
116
 
116
117
  class Table<T> extends Component<TableProps<T>, TableState<T>> {
117
- startEditing: (item: T, columnIndex: number, value?, focused?: boolean) => void;
118
+ startEditing: (item: T, rowIndex: number, columnIndex: number, value?, focused?: boolean) => void;
118
119
  finishEditing: () => void;
119
120
  getEditingState: () => EditingState<T>;
120
121
 
@@ -141,10 +142,10 @@ class Table<T> extends Component<TableProps<T>, TableState<T>> {
141
142
  editingState(null)
142
143
  };
143
144
 
144
- const setEditing = (item, columnIndex, value, focused = true) => {
145
+ const setEditing = (item, rowIndex, columnIndex, value, focused = true) => {
145
146
  const {columns} = props()
146
147
  const field = columns[columnIndex].field
147
- editingState({id: item.id, value: (value != null ? value : item[field]), columnIndex, item, field, focused: !!focused})
148
+ editingState({id: item.id, value: (value != null ? value : item[field]), rowIndex, columnIndex, item, field, focused: !!focused})
148
149
  };
149
150
  this.startEditing = setEditing
150
151
  this.getEditingState = () => editingState()
@@ -171,7 +172,7 @@ class Table<T> extends Component<TableProps<T>, TableState<T>> {
171
172
  ...editing.item,
172
173
  [editing.field]: value
173
174
  };
174
- props().onChange(updated, cancelEditing)
175
+ props().onChange(updated, cancelEditing, editing.rowIndex)
175
176
  };
176
177
  this.finishEditing = onFinishEditing
177
178
 
@@ -314,7 +315,7 @@ class Row<T> extends PureComponent<RowProps<T>> {
314
315
  {columns.filter(it => !!it).map((column, j) => {
315
316
  const isEditing = editing && editing.columnIndex === j;
316
317
  const editable = isFunction(column.editable) ? (column.editable as ((t: T) => boolean))(item) : !!column.editable;
317
- const startEditing = !isEditing && editable ? () => setEditing(item, j) : NOOP;
318
+ const startEditing = !isEditing && editable ? () => setEditing(item, i, j) : NOOP;
318
319
  const onClick = (!!column.onClick ? (e) => column.onClick(e, startEditing, item, column.field, i, j) : startEditing)
319
320
 
320
321
  let displayEditor = isEditing || column.displayEditor;
@@ -341,7 +342,7 @@ class Row<T> extends PureComponent<RowProps<T>> {
341
342
  value={value}
342
343
  focused={editing.focused}
343
344
  onFocus={() => {
344
- setEditing(item, j, value, true)
345
+ setEditing(item, i, j, value, true)
345
346
  }}
346
347
  onBlur={onFinishEditing}
347
348
  onChange={handleInputChange}