react-ui-basics 0.0.192 → 0.0.194

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.192",
3
+ "version": "0.0.194",
4
4
  "description": "",
5
5
  "module": "index.js",
6
6
  "_main": "index.cjs.js",
@@ -27,8 +27,12 @@ const clearSelection = () => {
27
27
  } else if (getSelection().removeAllRanges) { // Firefox
28
28
  getSelection().removeAllRanges();
29
29
  }
30
- } else if (DOCUMENT.selection) { // IE?
31
- DOCUMENT.selection.empty();
30
+ } else {
31
+ // @ts-ignore
32
+ if (DOCUMENT.selection) { // IE?
33
+ // @ts-ignore
34
+ DOCUMENT.selection.empty();
35
+ }
32
36
  }
33
37
  };
34
38
 
@@ -3,7 +3,7 @@ import ReactDOM from "react-dom";
3
3
  import './DatePicker.css'
4
4
  import TextField from "./TextField";
5
5
  import * as DateTools from "./DateTools";
6
- import {orNoop, classNames, preventDefault, ref} from "./Tools";
6
+ import {orNoop, classNames, preventDefault, ref, WINDOW} from "./Tools";
7
7
  import Button from './Button'
8
8
  import CalendarMonthView from "./CalendarMonthView";
9
9
  import MaterialIcon from "./MaterialIcon";
@@ -92,10 +92,20 @@ class DatePicker extends React.Component<DatePickerProps, DatePickerState> {
92
92
  };
93
93
 
94
94
  private getPopupStyles = () => {
95
- const boundingClientRect = this.el.getBoundingClientRect();
95
+ const textInputBoundingRect = this.el.getBoundingClientRect();
96
+ const popupBoundingRect = this.popup.getBoundingClientRect();
97
+ let left = textInputBoundingRect.left;
98
+ let top = textInputBoundingRect.bottom;
99
+ if (left + popupBoundingRect.width > WINDOW.innerWidth) {
100
+ left = textInputBoundingRect.right - popupBoundingRect.width;
101
+ }
102
+ if (top + popupBoundingRect.height > WINDOW.innerHeight) {
103
+ top = textInputBoundingRect.top - popupBoundingRect.height;
104
+ }
105
+
96
106
  return {
97
- left: boundingClientRect.left + 'px',
98
- top: boundingClientRect.bottom + 'px',
107
+ left: left + 'px',
108
+ top: top + 'px',
99
109
  }
100
110
  };
101
111
 
@@ -47,4 +47,5 @@ class ResizeObserver {
47
47
  }
48
48
  }
49
49
 
50
+ // @ts-ignore
50
51
  WINDOW.ResizeObserver = WINDOW.ResizeObserver || ResizeObserver;
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
@@ -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}
package/src/Tools.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  var global = global || window;
2
- export const WINDOW = global;
2
+ export const WINDOW: Window = global as Window;
3
3
  export const DOCUMENT = WINDOW.document;
4
4
 
5
5
  export function classNames(...classes: Array<string | number | boolean | null | void>) {