cx 23.5.2 → 23.5.3

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.
@@ -5,6 +5,7 @@ import { WheelComponent } from "./Wheel";
5
5
  import { oneFocusOut, offFocusOut } from "../../ui/FocusManager";
6
6
 
7
7
  import { enableCultureSensitiveFormatting } from "../../ui/Format";
8
+ import { parseDateInvariant } from "../../util";
8
9
  enableCultureSensitiveFormatting();
9
10
 
10
11
  export class DateTimePicker extends Widget {
@@ -37,7 +38,7 @@ DateTimePicker.prototype.showSeconds = false;
37
38
  class DateTimePickerComponent extends VDOM.Component {
38
39
  constructor(props) {
39
40
  super(props);
40
- let date = props.data.value ? new Date(props.data.value) : new Date();
41
+ let date = props.data.value ? parseDateInvariant(props.data.value) : new Date();
41
42
  if (isNaN(date.getTime())) date = new Date();
42
43
  this.state = {
43
44
  date: date,
@@ -67,7 +68,7 @@ class DateTimePickerComponent extends VDOM.Component {
67
68
  }
68
69
 
69
70
  UNSAFE_componentWillReceiveProps(props) {
70
- let date = props.data.value ? new Date(props.data.value) : new Date();
71
+ let date = props.data.value ? parseDateInvariant(props.data.value) : new Date();
71
72
  if (isNaN(date.getTime())) date = new Date();
72
73
  this.setState({ date });
73
74
  }
@@ -160,7 +161,7 @@ class DateTimePickerComponent extends VDOM.Component {
160
161
  (state) => ({
161
162
  date: this.setDateComponent(this.state.date, "year", newIndex + 1970),
162
163
  }),
163
- this.handleChange
164
+ this.handleChange,
164
165
  );
165
166
  }}
166
167
  onPipeKeyDown={(kd) => {
@@ -186,7 +187,7 @@ class DateTimePickerComponent extends VDOM.Component {
186
187
  (state) => ({
187
188
  date: this.setDateComponent(this.state.date, "month", newIndex),
188
189
  }),
189
- this.handleChange
190
+ this.handleChange,
190
191
  );
191
192
  }}
192
193
  onPipeKeyDown={(kd) => {
@@ -214,7 +215,7 @@ class DateTimePickerComponent extends VDOM.Component {
214
215
  (state) => ({
215
216
  date: this.setDateComponent(this.state.date, "date", newIndex + 1),
216
217
  }),
217
- this.handleChange
218
+ this.handleChange,
218
219
  );
219
220
  }}
220
221
  onPipeKeyDown={(kd) => {
@@ -240,7 +241,7 @@ class DateTimePickerComponent extends VDOM.Component {
240
241
  (state) => ({
241
242
  date: this.setDateComponent(this.state.date, "hours", newIndex),
242
243
  }),
243
- this.handleChange
244
+ this.handleChange,
244
245
  );
245
246
  }}
246
247
  onPipeKeyDown={(kd) => {
@@ -266,7 +267,7 @@ class DateTimePickerComponent extends VDOM.Component {
266
267
  (state) => ({
267
268
  date: this.setDateComponent(this.state.date, "minutes", newIndex),
268
269
  }),
269
- this.handleChange
270
+ this.handleChange,
270
271
  );
271
272
  }}
272
273
  onPipeKeyDown={(kd) => {
@@ -292,7 +293,7 @@ class DateTimePickerComponent extends VDOM.Component {
292
293
  (state) => ({
293
294
  date: this.setDateComponent(this.state.date, "seconds", newIndex),
294
295
  }),
295
- this.handleChange
296
+ this.handleChange,
296
297
  );
297
298
  }}
298
299
  onPipeKeyDown={(kd) => {
@@ -41,7 +41,7 @@ export class Field extends PureContainer {
41
41
  }
42
42
 
43
43
  init() {
44
- if (this.validationMode == "tooltip" && isUndefined(this.errorTooltip)) {
44
+ if (this.validationMode == 'tooltip' && isUndefined(this.errorTooltip)) {
45
45
  this.errorTooltip = {
46
46
  text: { bind: "$error" },
47
47
  mod: "error",
@@ -243,11 +243,7 @@ export class Field extends PureContainer {
243
243
  if (!data.error) {
244
244
  if (state.inputError) data.error = state.inputError;
245
245
  else if (state.validating && !empty) data.error = this.validatingText;
246
- else if (
247
- state.validationError &&
248
- data.value === state.lastValidatedValue &&
249
- shallowEquals(data.validationParams, state.lastValidationParams)
250
- )
246
+ else if (state.validationError && data.value === state.lastValidatedValue && shallowEquals(data.validationParams, state.lastValidationParams))
251
247
  data.error = state.validationError;
252
248
  else if (data.required) data.error = this.validateRequired(context, instance);
253
249
  }
@@ -257,9 +253,7 @@ export class Field extends PureContainer {
257
253
  !state.validating &&
258
254
  !data.error &&
259
255
  this.onValidate &&
260
- (!state.previouslyValidated ||
261
- data.value != state.lastValidatedValue ||
262
- data.validationParams != state.lastValidationParams)
256
+ (!state.previouslyValidated || data.value != state.lastValidatedValue || data.validationParams != state.lastValidationParams)
263
257
  ) {
264
258
  let result = instance.invoke("onValidate", data.value, instance, data.validationParams);
265
259
  if (isPromise(result)) {
@@ -268,16 +262,14 @@ export class Field extends PureContainer {
268
262
  validating: true,
269
263
  lastValidatedValue: data.value,
270
264
  previouslyValidated: true,
271
- lastValidationParams: data.validationParams,
265
+ lastValidationParams: data.validationParams
272
266
  });
273
267
  result
274
268
  .then((r) => {
275
269
  let { data, state } = instance;
276
- let error =
277
- data.value == state.lastValidatedValue &&
278
- shallowEquals(data.validationParams, state.lastValidationParams)
279
- ? r
280
- : this.validatingText; //parameters changed, this will be revalidated
270
+ let error = data.value == state.lastValidatedValue && shallowEquals(data.validationParams, state.lastValidationParams)
271
+ ? r
272
+ : this.validatingText; //parameters changed, this will be revalidated
281
273
 
282
274
  instance.setState({
283
275
  validating: false,
@@ -424,3 +416,4 @@ export function getFieldTooltip(instance) {
424
416
  ];
425
417
  return [instance, widget.tooltip];
426
418
  }
419
+
@@ -1,88 +1,86 @@
1
- import { Widget, VDOM } from "../../ui/Widget";
2
- import { HtmlElement } from "../HtmlElement";
3
- import { FocusManager } from "../../ui/FocusManager";
4
- import { isArray } from "../../util/isArray";
5
- import { coalesce } from "../../util/coalesce";
6
-
7
- export class Label extends HtmlElement {
8
- declareData() {
9
- super.declareData(...arguments, {
10
- required: undefined,
11
- disabled: undefined,
12
- htmlFor: undefined,
13
- });
14
- }
15
-
16
- prepareData(context, instance) {
17
- let { data } = instance;
18
- data.stateMods = {
19
- ...data.stateMods,
20
- disabled: data.disabled,
21
- };
22
- data._disabled = data.disabled;
23
- super.prepareData(context, instance);
24
- }
25
-
26
- explore(context, instance) {
27
- let { data } = instance;
28
-
29
- if (!data.htmlFor) data.htmlFor = context.lastFieldId;
30
-
31
- data.disabled = data.stateMods.disabled = coalesce(
32
- context.parentStrict ? context.parentDisabled : null,
33
- data._disabled,
34
- context.parentDisabled
35
- );
36
-
37
- data.asterisk = context.parentAsterisk || this.asterisk;
38
-
39
- if (instance.cache("disabled", data.disabled) || instance.cache("asterisk", data.asterisk)) {
40
- instance.markShouldUpdate(context);
41
- this.prepareCSS(context, instance);
42
- }
43
-
44
- super.explore(context, instance);
45
- }
46
-
47
- isValidHtmlAttribute(attrName) {
48
- switch (attrName) {
49
- case "asterisk":
50
- case "required":
51
- return false;
52
- }
53
- return super.isValidHtmlAttribute(attrName);
54
- }
55
-
56
- attachProps(context, instance, props) {
57
- super.attachProps(context, instance, props);
58
-
59
- let { data } = instance;
60
-
61
- if (data.htmlFor) {
62
- props.htmlFor = data.htmlFor;
63
-
64
- if (!props.onClick)
65
- props.onClick = () => {
66
- //additional focus for LookupFields which are not input based
67
- let el = document.getElementById(instance.data.htmlFor);
68
- if (el) FocusManager.focusFirst(el);
69
- };
70
- }
71
-
72
- if (!props.id && data.htmlFor) props.id = `${data.htmlFor}-label`;
73
-
74
- if (data.required && data.asterisk) {
75
- if (!isArray(props.children)) props.children = [props.children];
76
- props.children.push(" ");
77
- props.children.push(
78
- <span key="asterisk" className={this.CSS.element(this.baseClass, "asterisk")}>
79
- *
80
- </span>
81
- );
82
- }
83
- }
84
- }
85
-
86
- Label.prototype.baseClass = "label";
87
- Label.prototype.tag = "label";
88
- Label.prototype.asterisk = false;
1
+ import { Widget, VDOM } from "../../ui/Widget";
2
+ import { HtmlElement } from "../HtmlElement";
3
+ import { FocusManager } from "../../ui/FocusManager";
4
+ import { isArray } from "../../util/isArray";
5
+ import { coalesce } from "../../util/coalesce";
6
+
7
+ export class Label extends HtmlElement {
8
+ declareData() {
9
+ super.declareData(...arguments, {
10
+ required: undefined,
11
+ disabled: undefined,
12
+ htmlFor: undefined,
13
+ });
14
+ }
15
+
16
+ prepareData(context, instance) {
17
+ let { data } = instance;
18
+ data.stateMods = {
19
+ ...data.stateMods,
20
+ disabled: data.disabled,
21
+ };
22
+ data._disabled = data.disabled;
23
+ super.prepareData(context, instance);
24
+ }
25
+
26
+ explore(context, instance) {
27
+ let { data } = instance;
28
+
29
+ if (!data.htmlFor) data.htmlFor = context.lastFieldId;
30
+
31
+ data.disabled = data.stateMods.disabled = coalesce(
32
+ context.parentStrict ? context.parentDisabled : null,
33
+ data._disabled,
34
+ context.parentDisabled
35
+ );
36
+
37
+ if (instance.cache('disabled', data.disabled)) {
38
+ instance.markShouldUpdate(context);
39
+ this.prepareCSS(context, instance);
40
+ }
41
+
42
+ super.explore(context, instance);
43
+ }
44
+
45
+ isValidHtmlAttribute(attrName) {
46
+ switch (attrName) {
47
+ case "asterisk":
48
+ case "required":
49
+ return false;
50
+ }
51
+ return super.isValidHtmlAttribute(attrName);
52
+ }
53
+
54
+ attachProps(context, instance, props) {
55
+ super.attachProps(context, instance, props);
56
+
57
+ let { data } = instance;
58
+
59
+ if (data.htmlFor) {
60
+ props.htmlFor = data.htmlFor;
61
+
62
+ if (!props.onClick)
63
+ props.onClick = () => {
64
+ //additional focus for LookupFields which are not input based
65
+ let el = document.getElementById(instance.data.htmlFor);
66
+ if (el) FocusManager.focusFirst(el);
67
+ };
68
+ }
69
+
70
+ if (!props.id && data.htmlFor) props.id = `${data.htmlFor}-label`;
71
+
72
+ if (this.asterisk && data.required) {
73
+ if (!isArray(props.children)) props.children = [props.children];
74
+ props.children.push(" ");
75
+ props.children.push(
76
+ <span key="asterisk" className={this.CSS.element(this.baseClass, "asterisk")}>
77
+ *
78
+ </span>
79
+ );
80
+ }
81
+ }
82
+ }
83
+
84
+ Label.prototype.baseClass = "label";
85
+ Label.prototype.tag = "label";
86
+ Label.prototype.asterisk = false;
@@ -1,32 +1,32 @@
1
- import { Widget, VDOM, getContent } from "../../ui/Widget";
2
- import { Cx } from "../../ui/Cx";
3
- import { Field, getFieldTooltip } from "./Field";
4
- import { MonthPicker } from "./MonthPicker";
5
1
  import { DateTimeCulture } from "intl-io";
6
- import { Format } from "../../util/Format";
7
- import { Dropdown } from "../overlay/Dropdown";
8
- import { Console } from "../../util/Console";
9
2
  import { StringTemplate } from "../../data/StringTemplate";
10
- import { monthStart } from "../../util/date/monthStart";
3
+ import { Cx } from "../../ui/Cx";
4
+ import { Localization } from "../../ui/Localization";
5
+ import { VDOM, Widget, getContent } from "../../ui/Widget";
6
+ import { parseDateInvariant } from "../../util";
7
+ import { Console } from "../../util/Console";
8
+ import { Format } from "../../util/Format";
9
+ import { KeyCode } from "../../util/KeyCode";
11
10
  import { dateDiff } from "../../util/date/dateDiff";
11
+ import { monthStart } from "../../util/date/monthStart";
12
+ import { stopPropagation } from "../../util/eventCallbacks";
13
+ import { isDefined } from "../../util/isDefined";
14
+ import { isTouchDevice } from "../../util/isTouchDevice";
15
+ import { isTouchEvent } from "../../util/isTouchEvent";
16
+ import { Icon } from "../Icon";
17
+ import { autoFocus } from "../autoFocus";
18
+ import ClearIcon from "../icons/clear";
19
+ import DropdownIcon from "../icons/drop-down";
20
+ import { Dropdown } from "../overlay/Dropdown";
12
21
  import {
13
- tooltipParentWillReceiveProps,
14
- tooltipParentWillUnmount,
15
- tooltipMouseMove,
16
22
  tooltipMouseLeave,
23
+ tooltipMouseMove,
17
24
  tooltipParentDidMount,
25
+ tooltipParentWillReceiveProps,
26
+ tooltipParentWillUnmount,
18
27
  } from "../overlay/tooltip-ops";
19
- import { stopPropagation } from "../../util/eventCallbacks";
20
- import { Icon } from "../Icon";
21
- import CalendarIcon from "../icons/calendar";
22
- import DropdownIcon from "../icons/drop-down";
23
- import ClearIcon from "../icons/clear";
24
- import { KeyCode } from "../../util/KeyCode";
25
- import { isTouchEvent } from "../../util/isTouchEvent";
26
- import { isTouchDevice } from "../../util/isTouchDevice";
27
- import { Localization } from "../../ui/Localization";
28
- import { isDefined } from "../../util/isDefined";
29
- import { autoFocus } from "../autoFocus";
28
+ import { Field, getFieldTooltip } from "./Field";
29
+ import { MonthPicker } from "./MonthPicker";
30
30
 
31
31
  export class MonthField extends Field {
32
32
  declareData() {
@@ -63,7 +63,7 @@ export class MonthField extends Field {
63
63
  maxExclusive: undefined,
64
64
  icon: undefined,
65
65
  },
66
- ...arguments
66
+ ...arguments,
67
67
  );
68
68
  }
69
69
 
@@ -92,11 +92,11 @@ export class MonthField extends Field {
92
92
  };
93
93
 
94
94
  if (!this.range && data.value) {
95
- data.date = new Date(data.value);
95
+ data.date = parseDateInvariant(data.value);
96
96
  data.formatted = this.culture.format(data.date, formatOptions);
97
97
  } else if (this.range && data.from && data.to) {
98
- data.from = new Date(data.from);
99
- data.to = new Date(data.to);
98
+ data.from = parseDateInvariant(data.from);
99
+ data.to = parseDateInvariant(data.to);
100
100
  data.to.setDate(data.to.getDate() - 1);
101
101
  let fromStr = this.culture.format(data.from, formatOptions);
102
102
  let toStr = this.culture.format(data.to, formatOptions);
@@ -104,11 +104,11 @@ export class MonthField extends Field {
104
104
  else data.formatted = fromStr;
105
105
  }
106
106
 
107
- if (data.refDate) data.refDate = monthStart(new Date(data.refDate));
107
+ if (data.refDate) data.refDate = monthStart(parseDateInvariant(data.refDate));
108
108
 
109
- if (data.maxValue) data.maxValue = monthStart(new Date(data.maxValue));
109
+ if (data.maxValue) data.maxValue = monthStart(parseDateInvariant(data.maxValue));
110
110
 
111
- if (data.minValue) data.minValue = monthStart(new Date(data.minValue));
111
+ if (data.minValue) data.minValue = monthStart(parseDateInvariant(data.minValue));
112
112
 
113
113
  instance.lastDropdown = context.lastDropdown;
114
114
  }
@@ -322,7 +322,7 @@ class MonthInput extends VDOM.Component {
322
322
  icon: !!icon,
323
323
  empty: empty && !data.placeholder,
324
324
  error: data.error && (state.visited || !suppressErrorsUntilVisited || !empty),
325
- })
325
+ }),
326
326
  )}
327
327
  style={data.style}
328
328
  onMouseDown={this.onMouseDown.bind(this)}
@@ -26,6 +26,7 @@ import { isTouchEvent } from "../../util/isTouchEvent";
26
26
  import { getCursorPos } from "../overlay/captureMouse";
27
27
 
28
28
  import { enableCultureSensitiveFormatting } from "../../ui/Format";
29
+ import { parseDateInvariant } from "../../util";
29
30
  enableCultureSensitiveFormatting();
30
31
 
31
32
  export class MonthPicker extends Field {
@@ -59,7 +60,7 @@ export class MonthPicker extends Field {
59
60
  maxValue: undefined,
60
61
  maxExclusive: undefined,
61
62
  },
62
- ...arguments
63
+ ...arguments,
63
64
  );
64
65
  }
65
66
 
@@ -72,19 +73,19 @@ export class MonthPicker extends Field {
72
73
  disabled: data.disabled,
73
74
  };
74
75
 
75
- if (!this.range && data.value) data.date = monthStart(new Date(data.value));
76
+ if (!this.range && data.value) data.date = monthStart(parseDateInvariant(data.value));
76
77
 
77
78
  if (this.range) {
78
- if (data.from) data.from = monthStart(new Date(data.from));
79
+ if (data.from) data.from = monthStart(parseDateInvariant(data.from));
79
80
 
80
- if (data.to) data.to = monthStart(new Date(data.to));
81
+ if (data.to) data.to = monthStart(parseDateInvariant(data.to));
81
82
  }
82
83
 
83
- if (data.refDate) data.refDate = monthStart(new Date(data.refDate));
84
+ if (data.refDate) data.refDate = monthStart(parseDateInvariant(data.refDate));
84
85
 
85
- if (data.maxValue) data.maxValue = monthStart(new Date(data.maxValue));
86
+ if (data.maxValue) data.maxValue = monthStart(parseDateInvariant(data.maxValue));
86
87
 
87
- if (data.minValue) data.minValue = monthStart(new Date(data.minValue));
88
+ if (data.minValue) data.minValue = monthStart(parseDateInvariant(data.minValue));
88
89
 
89
90
  super.prepareData(...arguments);
90
91
  }
@@ -271,7 +272,7 @@ export class MonthPickerComponent extends VDOM.Component {
271
272
  cursorQuarter: (cursorQuarter + 3) % 4,
272
273
  cursorYear: cursorQuarter == 0 ? cursorYear - 1 : cursorYear,
273
274
  },
274
- { ensureVisible: true }
275
+ { ensureVisible: true },
275
276
  );
276
277
  else if (column == "M")
277
278
  if (cursorMonth > 3) this.moveCursor(e, { cursorMonth: cursorMonth - 3 }, { ensureVisible: true });
@@ -279,7 +280,7 @@ export class MonthPickerComponent extends VDOM.Component {
279
280
  this.moveCursor(
280
281
  e,
281
282
  { cursorMonth: cursorMonth + 9, cursorYear: cursorYear - 1 },
282
- { ensureVisible: true }
283
+ { ensureVisible: true },
283
284
  );
284
285
  break;
285
286
 
@@ -292,7 +293,7 @@ export class MonthPickerComponent extends VDOM.Component {
292
293
  cursorQuarter: (cursorQuarter + 1) % 4,
293
294
  cursorYear: cursorQuarter == 3 ? cursorYear + 1 : cursorYear,
294
295
  },
295
- { ensureVisible: true }
296
+ { ensureVisible: true },
296
297
  );
297
298
  else if (column == "M")
298
299
  if (cursorMonth < 10) this.moveCursor(e, { cursorMonth: cursorMonth + 3 }, { ensureVisible: true });
@@ -300,7 +301,7 @@ export class MonthPickerComponent extends VDOM.Component {
300
301
  this.moveCursor(
301
302
  e,
302
303
  { cursorMonth: cursorMonth - 9, cursorYear: cursorYear + 1 },
303
- { ensureVisible: true }
304
+ { ensureVisible: true },
304
305
  );
305
306
  break;
306
307
 
@@ -469,7 +470,7 @@ export class MonthPickerComponent extends VDOM.Component {
469
470
  onMouseUp={this.handleMouseUp}
470
471
  >
471
472
  {y}
472
- </th>
473
+ </th>,
473
474
  );
474
475
 
475
476
  for (let i = 0; i < 3; i++) {
@@ -499,7 +500,7 @@ export class MonthPickerComponent extends VDOM.Component {
499
500
  onTouchEnd={this.handleMouseUp}
500
501
  >
501
502
  {monthNames[m - 1].substr(0, 3)}
502
- </td>
503
+ </td>,
503
504
  );
504
505
  }
505
506
  row.push(
@@ -518,7 +519,7 @@ export class MonthPickerComponent extends VDOM.Component {
518
519
  onMouseUp={this.handleMouseUp}
519
520
  >
520
521
  {`Q${q + 1}`}
521
- </th>
522
+ </th>,
522
523
  );
523
524
  rows.push(row);
524
525
  }
@@ -567,7 +568,7 @@ export class MonthPickerComponent extends VDOM.Component {
567
568
  let visibleItems = ceil5(Math.ceil(this.dom.el.offsetHeight / this.state.yearHeight));
568
569
  let start = Math.max(
569
570
  startYear,
570
- startYear + floor5(Math.floor(this.dom.el.scrollTop / this.state.yearHeight)) - visibleItems
571
+ startYear + floor5(Math.floor(this.dom.el.scrollTop / this.state.yearHeight)) - visibleItems,
571
572
  );
572
573
  if (start != this.state.start && start + bufferSize <= endYear) {
573
574
  this.setState({
@@ -605,7 +606,7 @@ export class MonthPickerComponent extends VDOM.Component {
605
606
  this.dom.el.scrollTop =
606
607
  (this.state.cursorYear - startYear + yearCount / 2) * this.state.yearHeight -
607
608
  this.dom.el.offsetHeight / 2;
608
- }
609
+ },
609
610
  );
610
611
  }
611
612
 
@@ -33,9 +33,6 @@ export interface ValidationGroupProps extends Cx.PureContainerProps {
33
33
 
34
34
  /** Set to `true` to force children to respect disabled, readOnly, viewMode and visited flags set on the group level. */
35
35
  strict?: Cx.BooleanProp;
36
-
37
- /** Set to `true` to add red asterisk for all required fields inside the group. */
38
- asterisk?: boolean;
39
36
  }
40
37
 
41
38
  export class ValidationGroup extends Cx.Widget<ValidationGroupProps> {}
@@ -18,7 +18,6 @@ export class ValidationGroup extends PureContainer {
18
18
  isolated: undefined,
19
19
  visited: undefined,
20
20
  strict: undefined,
21
- asterisk: undefined,
22
21
  });
23
22
  }
24
23
 
@@ -35,7 +34,6 @@ export class ValidationGroup extends PureContainer {
35
34
  context.push("parentViewMode", coalesce(instance.data.viewMode, context.parentViewMode));
36
35
  context.push("parentTabOnEnterKey", coalesce(instance.data.tabOnEnterKey, context.parentTabOnEnterKey));
37
36
  context.push("parentVisited", coalesce(instance.data.visited, context.parentVisited));
38
- context.push("parentAsterisk", coalesce(instance.data.asterisk, context.parentAsterisk));
39
37
  context.push("validation", instance.validation);
40
38
 
41
39
  super.explore(context, instance);
@@ -49,7 +47,6 @@ export class ValidationGroup extends PureContainer {
49
47
  context.pop("parentViewMode");
50
48
  context.pop("parentTabOnEnterKey");
51
49
  context.pop("parentStrict");
52
- context.pop("parentAsterisk");
53
50
 
54
51
  instance.valid = instance.validation.errors.length == 0;
55
52
  if (!instance.valid && !this.isolated && context.validation)