cx 24.0.3 → 24.3.0

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.
@@ -1,9 +1,7 @@
1
- import {Selection} from './Selection';
1
+ import { Selection } from './Selection';
2
2
 
3
3
  export class PropertySelection extends Selection {
4
-
5
- selectMultiple(store, records, indexes, {toggle, add} = {}) {
6
-
4
+ selectMultiple(store, records, indexes, { toggle, add } = {}) {
7
5
  if (this.toggle)
8
6
  toggle = true;
9
7
 
@@ -24,4 +24,4 @@ export class Selection extends Component {
24
24
  isInstanceSelected(instance: Instance): boolean;
25
25
  }
26
26
 
27
- export class SimpleSelection extends Selection {}
27
+ export class SimpleSelection extends Selection { }
@@ -21,6 +21,7 @@ import DropdownIcon from "../icons/drop-down";
21
21
  import ClearIcon from "../icons/clear";
22
22
  import { Localization } from "../../ui/Localization";
23
23
  import { isDefined } from "../../util/isDefined";
24
+ import { getActiveElement } from "../../util/getActiveElement";
24
25
 
25
26
  export class ColorField extends Field {
26
27
  declareData() {
@@ -219,8 +220,8 @@ class ColorInput extends VDOM.Component {
219
220
  tabIndex={data.tabIndex}
220
221
  placeholder={data.placeholder}
221
222
  {...data.inputAttrs}
222
- onInput={(e) => this.onChange(e, "input")}
223
- onChange={(e) => this.onChange(e, "change")}
223
+ onInput={(e) => this.onChange(e.target.value, "input")}
224
+ onChange={(e) => this.onChange(e.target.value, "change")}
224
225
  onKeyDown={(e) => this.onKeyDown(e)}
225
226
  onBlur={(e) => {
226
227
  this.onBlur(e);
@@ -274,7 +275,7 @@ class ColorInput extends VDOM.Component {
274
275
  switch (e.keyCode) {
275
276
  case KeyCode.enter:
276
277
  e.stopPropagation();
277
- this.onChange(e, "enter");
278
+ this.onChange(e.target.value, "enter");
278
279
  break;
279
280
 
280
281
  case KeyCode.esc:
@@ -304,7 +305,7 @@ class ColorInput extends VDOM.Component {
304
305
  this.setState({
305
306
  focus: false,
306
307
  });
307
- this.onChange(e, "blur");
308
+ this.onChange(e.target.value, "blur");
308
309
  }
309
310
 
310
311
  closeDropdown(e, callback) {
@@ -352,6 +353,9 @@ class ColorInput extends VDOM.Component {
352
353
  }
353
354
 
354
355
  componentWillUnmount() {
356
+ if (this.input == getActiveElement()) {
357
+ this.onChange(this.input.value, "blur");
358
+ }
355
359
  tooltipParentWillUnmount(this.props.instance);
356
360
  }
357
361
 
@@ -365,23 +369,24 @@ class ColorInput extends VDOM.Component {
365
369
  e.preventDefault();
366
370
  }
367
371
 
368
- onChange(e, eventType) {
372
+ onChange(inputValue, eventType) {
369
373
  let { instance, data } = this.props;
370
374
  let { widget } = instance;
371
375
 
372
- if (eventType == "blur") instance.setState({ visited: true });
376
+ if (eventType == "blur") {
377
+ instance.setState({ visited: true });
378
+ }
373
379
 
374
- let text = e.target.value;
375
380
  let isValid;
376
381
  try {
377
- parseColor(text);
382
+ parseColor(inputValue);
378
383
  isValid = true;
379
384
  } catch (e) {
380
385
  isValid = false;
381
386
  }
382
387
 
383
388
  if (eventType == "blur" || eventType == "enter") {
384
- let value = text || widget.emptyValue;
389
+ let value = inputValue || widget.emptyValue;
385
390
  if (isValid && value !== data.value) instance.set("value", value);
386
391
 
387
392
  instance.setState({
@@ -26,6 +26,7 @@ import { stopPropagation } from "../../util/eventCallbacks";
26
26
  import { Format } from "../../util/Format";
27
27
  import { TimeList } from "./TimeList";
28
28
  import { autoFocus } from "../autoFocus";
29
+ import { getActiveElement } from "../../util";
29
30
 
30
31
  export class DateTimeField extends Field {
31
32
  declareData() {
@@ -362,8 +363,8 @@ class DateTimeInput extends VDOM.Component {
362
363
  tabIndex={data.tabIndex}
363
364
  placeholder={data.placeholder}
364
365
  {...data.inputAttrs}
365
- onInput={(e) => this.onChange(e, "input")}
366
- onChange={(e) => this.onChange(e, "change")}
366
+ onInput={(e) => this.onChange(e.target.value, "input")}
367
+ onChange={(e) => this.onChange(e.target.value, "change")}
367
368
  onKeyDown={(e) => this.onKeyDown(e)}
368
369
  onBlur={(e) => {
369
370
  this.onBlur(e);
@@ -421,7 +422,7 @@ class DateTimeInput extends VDOM.Component {
421
422
 
422
423
  switch (e.keyCode) {
423
424
  case KeyCode.enter:
424
- this.onChange(e, "enter");
425
+ this.onChange(e.target.value, "enter");
425
426
  break;
426
427
 
427
428
  case KeyCode.esc:
@@ -453,7 +454,7 @@ class DateTimeInput extends VDOM.Component {
453
454
  this.setState({
454
455
  focus: false,
455
456
  });
456
- this.onChange(e, "blur");
457
+ this.onChange(e.target.value, "blur");
457
458
  }
458
459
 
459
460
  closeDropdown(e, callback) {
@@ -509,10 +510,13 @@ class DateTimeInput extends VDOM.Component {
509
510
  }
510
511
 
511
512
  componentWillUnmount() {
513
+ if (this.input == getActiveElement()) {
514
+ this.onChange(this.input.value, "blur");
515
+ }
512
516
  tooltipParentWillUnmount(this.props.instance);
513
517
  }
514
518
 
515
- onChange(e, eventType) {
519
+ onChange(inputValue, eventType) {
516
520
  let { instance, data } = this.props;
517
521
  let { widget } = instance;
518
522
 
@@ -522,7 +526,7 @@ class DateTimeInput extends VDOM.Component {
522
526
 
523
527
  if (eventType == "enter") instance.setState({ visited: true });
524
528
 
525
- this.setValue(e.target.value, data.value);
529
+ this.setValue(inputValue, data.value);
526
530
  }
527
531
 
528
532
  setValue(text, baseValue) {
@@ -8,7 +8,7 @@ export interface LookupBinding {
8
8
  key?: boolean;
9
9
  }
10
10
 
11
- interface LookupFieldProps extends FieldProps {
11
+ interface LookupFieldProps<T = unknown> extends FieldProps {
12
12
  /** Defaults to `false`. Set to `true` to enable multiple selection. */
13
13
  multiple?: Cx.BooleanProp;
14
14
 
@@ -31,7 +31,7 @@ interface LookupFieldProps extends FieldProps {
31
31
  placeholder?: Cx.StringProp;
32
32
 
33
33
  /** A list of available options. */
34
- options?: Cx.RecordsProp;
34
+ options?: Cx.Prop<T[]>;
35
35
 
36
36
  /**
37
37
  * Set to `true` to hide the clear button. It can be used interchangeably with the `showClear` property.
@@ -128,10 +128,9 @@ interface LookupFieldProps extends FieldProps {
128
128
  icon?: Cx.StringProp | Cx.Record;
129
129
 
130
130
  /** Query function. */
131
- onQuery?: (
132
- query: string | { query: string; page: number; pageSize: number },
133
- instance: Instance,
134
- ) => Cx.Record[] | Promise<Cx.Record>;
131
+ onQuery?:
132
+ | string
133
+ | ((query: string | { query: string; page: number; pageSize: number }, instance: Instance) => T[] | Promise<T[]>);
135
134
 
136
135
  /** Set to true to sort dropdown options. */
137
136
  sort?: boolean;
@@ -165,10 +164,10 @@ interface LookupFieldProps extends FieldProps {
165
164
  filterParams?: Cx.StructuredProp;
166
165
 
167
166
  /** Callback to create a filter function for given filter params. */
168
- onCreateVisibleOptionsFilter?: (filterParams: any, instance?: Instance) => (record: Record) => boolean;
167
+ onCreateVisibleOptionsFilter?: (filterParams: any, instance?: Instance) => (record: T) => boolean;
169
168
 
170
169
  /** Used in multiple selection lookups in combination with records, to construct the display text out of multiple fields or when additional formatting is needed. */
171
- onGetRecordDisplayText?: (record: any, instance?: Instance) => string;
170
+ onGetRecordDisplayText?: (record: T, instance?: Instance) => string;
172
171
  }
173
172
 
174
- export class LookupField extends Cx.Widget<LookupFieldProps> {}
173
+ export class LookupField<T = unknown> extends Cx.Widget<LookupFieldProps<T>> {}
@@ -27,6 +27,7 @@ import {
27
27
  } from "../overlay/tooltip-ops";
28
28
  import { Field, getFieldTooltip } from "./Field";
29
29
  import { MonthPicker } from "./MonthPicker";
30
+ import { getActiveElement } from "../../util/getActiveElement";
30
31
 
31
32
  export class MonthField extends Field {
32
33
  declareData() {
@@ -342,8 +343,8 @@ class MonthInput extends VDOM.Component {
342
343
  readOnly={data.readOnly}
343
344
  tabIndex={data.tabIndex}
344
345
  placeholder={data.placeholder}
345
- onInput={(e) => this.onChange(e, "input")}
346
- onChange={(e) => this.onChange(e, "change")}
346
+ onInput={(e) => this.onChange(e.target.value, "input")}
347
+ onChange={(e) => this.onChange(e.target.value, "change")}
347
348
  onKeyDown={(e) => this.onKeyDown(e)}
348
349
  onBlur={(e) => {
349
350
  this.onBlur(e);
@@ -397,7 +398,7 @@ class MonthInput extends VDOM.Component {
397
398
  switch (e.keyCode) {
398
399
  case KeyCode.enter:
399
400
  e.stopPropagation();
400
- this.onChange(e, "enter");
401
+ this.onChange(e.target.value, "enter");
401
402
  break;
402
403
 
403
404
  case KeyCode.esc:
@@ -429,7 +430,7 @@ class MonthInput extends VDOM.Component {
429
430
  this.setState({
430
431
  focus: false,
431
432
  });
432
- this.onChange(e, "blur");
433
+ this.onChange(e.target.value, "blur");
433
434
  }
434
435
 
435
436
  closeDropdown(e, callback) {
@@ -484,16 +485,19 @@ class MonthInput extends VDOM.Component {
484
485
  }
485
486
 
486
487
  componentWillUnmount() {
488
+ if (this.input == getActiveElement()) {
489
+ this.onChange(this.input.value, "blur");
490
+ }
487
491
  tooltipParentWillUnmount(this.props.instance);
488
492
  }
489
493
 
490
- onChange(e, eventType) {
494
+ onChange(inputValue, eventType) {
491
495
  var { instance } = this.props;
492
496
  var { widget } = instance;
493
497
 
494
498
  if (widget.reactOn.indexOf(eventType) == -1) return;
495
499
 
496
- var parts = e.target.value.split("-");
500
+ var parts = inputValue.split("-");
497
501
  var date1 = widget.parseDate(parts[0]);
498
502
  var date2 = widget.parseDate(parts[1]) || date1;
499
503
 
@@ -16,6 +16,7 @@ import ClearIcon from "../icons/clear";
16
16
  import { isString } from "../../util/isString";
17
17
  import { isNumber } from "../../util/isNumber";
18
18
  import { isDefined } from "../../util/isDefined";
19
+ import { getActiveElement } from "../../util/getActiveElement";
19
20
 
20
21
  import { enableCultureSensitiveFormatting } from "../../ui/Format";
21
22
  import { KeyCode } from "../../util/KeyCode";
@@ -248,6 +249,9 @@ class Input extends VDOM.Component {
248
249
  }
249
250
 
250
251
  componentWillUnmount() {
252
+ if (this.input == getActiveElement()) {
253
+ this.onChange({ target: { value: this.input.value } }, "blur");
254
+ }
251
255
  tooltipParentWillUnmount(this.props.instance);
252
256
  }
253
257
 
@@ -409,12 +413,12 @@ class Input extends VDOM.Component {
409
413
  let decimalSeparator = this.getDecimalSeparator(fmt) || Format.value(1.1, "n;1")[1];
410
414
 
411
415
  let formatted = Format.value(value, fmt);
412
- //re-parse to avoid differences between formatted value and value in the store
416
+ // Re-parse to avoid differences between formatted value and value in the store
413
417
 
414
418
  value = widget.parseValue(formatted, instance) * data.scale + data.offset;
415
419
 
416
- //allow users to type numbers like 100.0003 or -0.05 without interruptions
417
- //if the last typed in character is zero or dot (decimal separator) skip processing it
420
+ // Allow users to type numbers like 100.0003 or -0.05 without interruptions
421
+ // If the last typed character is zero or dot (decimal separator), skip processing it
418
422
  if (
419
423
  change == "change" &&
420
424
  this.input.selectionStart == this.input.selectionEnd &&
@@ -426,7 +430,7 @@ class Input extends VDOM.Component {
426
430
  return;
427
431
 
428
432
  if (change != "blur") {
429
- //format, but keep the correct cursor position
433
+ // Format, but keep the correct cursor position
430
434
  let preCursorText = this.getPreCursorDigits(this.input.value, this.input.selectionStart, decimalSeparator);
431
435
  this.input.value = formatted;
432
436
  this.updateCursorPosition(preCursorText);
@@ -11,6 +11,7 @@ import {
11
11
  import { stopPropagation } from "../../util/eventCallbacks";
12
12
  import { KeyCode } from "../../util/KeyCode";
13
13
  import { autoFocus } from "../autoFocus";
14
+ import { getActiveElement } from "../../util/getActiveElement";
14
15
 
15
16
  export class TextArea extends TextField {
16
17
  declareData() {
@@ -93,10 +94,10 @@ class Input extends VDOM.Component {
93
94
  tabIndex={data.tabIndex}
94
95
  placeholder={data.placeholder}
95
96
  {...data.inputAttrs}
96
- onInput={(e) => this.onChange(e, "input")}
97
- onChange={(e) => this.onChange(e, "change")}
97
+ onInput={(e) => this.onChange(e.target.value, "input")}
98
+ onChange={(e) => this.onChange(e.target.value, "change")}
98
99
  onBlur={(e) => {
99
- this.onChange(e, "blur");
100
+ this.onChange(e.target.value, "blur");
100
101
  }}
101
102
  onFocus={(e) => this.onFocus()}
102
103
  onClick={stopPropagation}
@@ -111,6 +112,9 @@ class Input extends VDOM.Component {
111
112
  }
112
113
 
113
114
  componentWillUnmount() {
115
+ if (this.input == getActiveElement()) {
116
+ this.onChange(this.input.value, "blur");
117
+ }
114
118
  tooltipParentWillUnmount(this.props.instance);
115
119
  }
116
120
 
@@ -144,7 +148,7 @@ class Input extends VDOM.Component {
144
148
  tooltipParentWillReceiveProps(this.input, ...getFieldTooltip(instance));
145
149
  }
146
150
 
147
- onChange(e, change) {
151
+ onChange(inputValue, change) {
148
152
  let { instance, data } = this.props;
149
153
  let { widget } = instance;
150
154
 
@@ -158,12 +162,12 @@ class Input extends VDOM.Component {
158
162
 
159
163
  if (data.required) {
160
164
  instance.setState({
161
- empty: !e.target.value,
165
+ empty: !inputValue,
162
166
  });
163
167
  }
164
168
 
165
169
  if (instance.widget.reactOn.indexOf(change) != -1) {
166
- let value = e.target.value || widget.emptyValue;
170
+ let value = inputValue || widget.emptyValue;
167
171
  instance.set("value", value);
168
172
  }
169
173
  }
@@ -15,6 +15,7 @@ import { Localization } from "../../ui/Localization";
15
15
  import ClearIcon from "../icons/clear";
16
16
  import { autoFocus } from "../autoFocus";
17
17
  import { isString } from "../../util/isString";
18
+ import { getActiveElement } from "../../util/getActiveElement";
18
19
 
19
20
  export class TextField extends Field {
20
21
  init() {
@@ -104,7 +105,7 @@ class Input extends VDOM.Component {
104
105
  <div
105
106
  className={CSS.element(baseClass, "left-icon")}
106
107
  onMouseDown={preventDefault}
107
- onClick={(e) => this.onChange(e, "enter")}
108
+ onClick={(e) => this.onChange(e.target.value, "enter")}
108
109
  >
109
110
  {iconVDOM}
110
111
  </div>
@@ -164,8 +165,8 @@ class Input extends VDOM.Component {
164
165
  {...data.inputAttrs}
165
166
  onMouseMove={this.onMouseMove.bind(this)}
166
167
  onMouseLeave={this.onMouseLeave.bind(this)}
167
- onInput={(e) => this.onChange(e, "input")}
168
- onChange={(e) => this.onChange(e, "change")}
168
+ onInput={(e) => this.onChange(e.target.value, "input")}
169
+ onChange={(e) => this.onChange(e.target.value, "change")}
169
170
  onKeyDown={this.onKeyDown.bind(this)}
170
171
  onFocus={this.onFocus.bind(this)}
171
172
  onBlur={this.onBlur.bind(this)}
@@ -198,7 +199,7 @@ class Input extends VDOM.Component {
198
199
  });
199
200
  this.props.instance.set("focused", false);
200
201
  }
201
- this.onChange(e, "blur");
202
+ this.onChange(e.target.value, "blur");
202
203
  }
203
204
 
204
205
  onClearClick(e) {
@@ -223,6 +224,7 @@ class Input extends VDOM.Component {
223
224
  }
224
225
 
225
226
  componentWillUnmount() {
227
+ if (this.input == getActiveElement()) this.onChange(this.input.value, "blur");
226
228
  tooltipParentWillUnmount(this.props.instance);
227
229
  }
228
230
 
@@ -232,7 +234,7 @@ class Input extends VDOM.Component {
232
234
 
233
235
  switch (e.keyCode) {
234
236
  case KeyCode.enter:
235
- this.onChange(e, "enter");
237
+ this.onChange(e.target.value, "enter");
236
238
  break;
237
239
 
238
240
  case KeyCode.left:
@@ -244,13 +246,13 @@ class Input extends VDOM.Component {
244
246
 
245
247
  UNSAFE_componentWillReceiveProps(props) {
246
248
  let { data } = props;
247
- //the second check is required for debouncing, sometimes the value in the store lags after the input
248
- //and update may be caused by some other property, i.e. visited
249
+ // The second check is required for debouncing, sometimes the value in the store lags after the input
250
+ // and update may be caused by some other property, i.e. visited
249
251
  if (data.value != this.input.value && data.value != this.props.data.value) this.input.value = data.value || "";
250
252
  tooltipParentWillReceiveProps(this.input, ...getFieldTooltip(props.instance));
251
253
  }
252
254
 
253
- onChange(e, change) {
255
+ onChange(textValue, change) {
254
256
  let { instance, data } = this.props;
255
257
 
256
258
  let immediate = change == "blur" || change == "enter";
@@ -262,7 +264,7 @@ class Input extends VDOM.Component {
262
264
  let { widget } = instance;
263
265
 
264
266
  if (widget.reactOn.indexOf(change) != -1) {
265
- let text = this.trimmed(e.target.value);
267
+ let text = this.trimmed(textValue);
266
268
  if (data.maxLength != null && text.length > data.maxLength) {
267
269
  text = text.substring(0, data.maxLength);
268
270
  this.input.value = text;
@@ -25,5 +25,4 @@ export * from './DateTimeField';
25
25
  export * from './DateField';
26
26
  export * from './TimeField';
27
27
  export * from './Validator';
28
-
29
-
28
+ export * from './Label';
@@ -54,11 +54,11 @@ interface GridColumnDropEvent extends DragEvent {
54
54
 
55
55
  interface GridGroupingKey {
56
56
  [key: string]:
57
- | Prop<any>
58
- | {
59
- value: Prop<any>;
60
- direction: SortDirection;
61
- };
57
+ | Prop<any>
58
+ | {
59
+ value: Prop<any>;
60
+ direction: SortDirection;
61
+ };
62
62
  }
63
63
 
64
64
  type GridColumnAlignment = "left" | "right" | "center";
@@ -298,6 +298,9 @@ interface GridProps<T = unknown> extends StyledContainerProps {
298
298
  /** Parameters that affect filtering. */
299
299
  filterParams?: StructuredProp;
300
300
 
301
+ /** Callback function to be executed when a row is right-clicked. */
302
+ onRowContextMenu?: string | ((e: React.SyntheticEvent<any>, instance: Instance) => void);
303
+
301
304
  /** Callback to create a filter function for given filter params. */
302
305
  onCreateFilter?: (filterParams: any, instance?: Instance) => (record: T) => boolean;
303
306
 
@@ -316,7 +319,7 @@ interface GridProps<T = unknown> extends StyledContainerProps {
316
319
  sortField?: string;
317
320
  sortDirection?: string;
318
321
  },
319
- instance?: Instance
322
+ instance?: Instance,
320
323
  ) => FetchRecordsResult | Promise<FetchRecordsResult>;
321
324
 
322
325
  /** Callback function to be executed when a row is double-clicked. */
@@ -349,7 +352,7 @@ interface GridProps<T = unknown> extends StyledContainerProps {
349
352
  /** Callback to create a function that can be used to check whether a record is selectable. */
350
353
  onCreateIsRecordSelectable?: (
351
354
  params: any,
352
- instance: Instance
355
+ instance: Instance,
353
356
  ) => (record: T, options?: { range?: boolean; toggle?: boolean }) => boolean;
354
357
 
355
358
  /** Parameters whose change will cause scroll to be reset. */
@@ -404,4 +407,4 @@ interface GridCellEditInfo<T> extends GridCellInfo {
404
407
  newData: T;
405
408
  }
406
409
 
407
- export class Grid<T = unknown> extends Widget<GridProps<T>> { }
410
+ export class Grid<T = unknown> extends Widget<GridProps<T>> {}