cx 22.1.0 → 22.1.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.
@@ -162,16 +162,16 @@ export class Grid extends Widget {
162
162
  value: isDefined(c.aggregateValue)
163
163
  ? c.aggregateValue
164
164
  : isDefined(c.value)
165
- ? c.value
166
- : c.aggregateField
167
- ? { bind: this.recordName + "." + c.aggregateField }
168
- : null,
165
+ ? c.value
166
+ : c.aggregateField
167
+ ? { bind: this.recordName + "." + c.aggregateField }
168
+ : null,
169
169
  weight:
170
170
  c.weight != null
171
171
  ? c.weight
172
172
  : c.weightField && {
173
- bind: this.recordName + "." + c.weightField,
174
- },
173
+ bind: this.recordName + "." + c.weightField,
174
+ },
175
175
  type: c.aggregate,
176
176
  };
177
177
  }
@@ -486,6 +486,100 @@ export class Grid extends Widget {
486
486
  );
487
487
  }
488
488
 
489
+ renderResizer(instance, hdinst, header, colIndex, forPreviousColumn) {
490
+ let { widget } = instance;
491
+
492
+ let { CSS, baseClass } = widget;
493
+
494
+ let hdwidget = hdinst.widget;
495
+
496
+ let resizerClassName = "col-resizer";
497
+ if (forPreviousColumn) resizerClassName += "-prev-col";
498
+
499
+ return (
500
+ <div
501
+ className={CSS.element(baseClass, resizerClassName)}
502
+ onClick={(e) => {
503
+ e.stopPropagation();
504
+ }}
505
+ onMouseDown={(e) => {
506
+ if (e.buttons != 1) return;
507
+ let resizeOverlayEl = document.createElement("div");
508
+ let headerCell = e.target.parentElement;
509
+ if (forPreviousColumn) headerCell = headerCell.previousSibling;
510
+
511
+ let scrollAreaEl = headerCell.parentElement.parentElement.parentElement.parentElement;
512
+ let gridEl = scrollAreaEl.parentElement;
513
+ let initialWidth = headerCell.offsetWidth;
514
+ let initialPosition = getCursorPos(e);
515
+ resizeOverlayEl.className = CSS.element(baseClass, "resize-overlay");
516
+ resizeOverlayEl.style.width = `${initialWidth}px`;
517
+ resizeOverlayEl.style.left = `${
518
+ headerCell.getBoundingClientRect().left - gridEl.getBoundingClientRect().left
519
+ }px`;
520
+ gridEl.appendChild(resizeOverlayEl);
521
+ captureMouse2(e, {
522
+ onMouseMove: (e) => {
523
+ let cursor = getCursorPos(e);
524
+ let width = Math.max(30, Math.round(initialWidth + cursor.clientX - initialPosition.clientX));
525
+ resizeOverlayEl.style.width = `${width}px`;
526
+ },
527
+ onMouseUp: (e) => {
528
+ if (!resizeOverlayEl) return; //dblclick
529
+ let width = resizeOverlayEl.offsetWidth;
530
+ hdinst.assignedWidth = width;
531
+ gridEl.removeChild(resizeOverlayEl);
532
+ resizeOverlayEl = null;
533
+ if (widget.onColumnResize) instance.invoke("onColumnResize", { width, column: hdwidget }, hdinst);
534
+ header.set("width", width);
535
+ instance.setState({
536
+ dimensionsVersion: instance.state.dimensionsVersion + 1,
537
+ colWidth: {
538
+ ...instance.state.colWidth,
539
+ [hdwidget.uniqueColumnId]: width,
540
+ },
541
+ });
542
+ },
543
+ onDblClick: () => {
544
+ let table = gridEl.querySelector("table");
545
+ let parentEl = table.parentElement;
546
+ let tableClone = table.cloneNode(true);
547
+ tableClone.childNodes.forEach((tbody) => {
548
+ tbody.childNodes.forEach((tr) => {
549
+ tr.childNodes.forEach((td, index) => {
550
+ if (index == colIndex) {
551
+ td.style.maxWidth = null;
552
+ td.style.minWidth = null;
553
+ td.style.width = "auto";
554
+ } else {
555
+ td.style.display = "none";
556
+ }
557
+ });
558
+ });
559
+ });
560
+ tableClone.style.position = "absolute";
561
+ tableClone.style.visibility = "hidden";
562
+ tableClone.style.top = 0;
563
+ tableClone.style.left = 0;
564
+ tableClone.style.width = "auto";
565
+ parentEl.appendChild(tableClone);
566
+ let width = tableClone.offsetWidth;
567
+ parentEl.removeChild(tableClone);
568
+ header.set("width", width);
569
+ instance.setState({
570
+ dimensionsVersion: instance.state.dimensionsVersion + 1,
571
+ colWidth: {
572
+ ...instance.state.colWidth,
573
+ [hdwidget.uniqueColumnId]: width,
574
+ },
575
+ });
576
+ },
577
+ });
578
+ }}
579
+ />
580
+ );
581
+ }
582
+
489
583
  renderHeader(context, instance, key, fixed, fixedColumns) {
490
584
  let { data, widget, header } = instance;
491
585
 
@@ -520,7 +614,8 @@ export class Grid extends Widget {
520
614
  sortIcon,
521
615
  tool;
522
616
 
523
- let resizer = null;
617
+ let resizer = null,
618
+ prevColumnResizer = null;
524
619
 
525
620
  if (header) {
526
621
  empty[l] = false;
@@ -578,89 +673,12 @@ export class Grid extends Widget {
578
673
  }
579
674
 
580
675
  if ((hdwidget.resizable || header.data.resizable) && header.data.colSpan < 2) {
581
- resizer = (
582
- <div
583
- className={CSS.element(baseClass, "col-resizer")}
584
- onClick={(e) => {
585
- e.stopPropagation();
586
- }}
587
- onMouseDown={(e) => {
588
- if (e.buttons != 1) return;
589
- let resizeOverlayEl = document.createElement("div");
590
- let headerCell = e.target.parentElement;
591
- let scrollAreaEl = headerCell.parentElement.parentElement.parentElement.parentElement;
592
- let gridEl = scrollAreaEl.parentElement;
593
- let initialWidth = headerCell.offsetWidth;
594
- let initialPosition = getCursorPos(e);
595
- resizeOverlayEl.className = CSS.element(baseClass, "resize-overlay");
596
- resizeOverlayEl.style.width = `${initialWidth}px`;
597
- resizeOverlayEl.style.left = `${headerCell.getBoundingClientRect().left - gridEl.getBoundingClientRect().left
598
- }px`;
599
- gridEl.appendChild(resizeOverlayEl);
600
- captureMouse2(e, {
601
- onMouseMove: (e) => {
602
- let cursor = getCursorPos(e);
603
- let width = Math.max(
604
- 30,
605
- Math.round(initialWidth + cursor.clientX - initialPosition.clientX)
606
- );
607
- resizeOverlayEl.style.width = `${width}px`;
608
- },
609
- onMouseUp: (e) => {
610
- if (!resizeOverlayEl) return; //dblclick
611
- let width = resizeOverlayEl.offsetWidth;
612
- hdinst.assignedWidth = width;
613
- gridEl.removeChild(resizeOverlayEl);
614
- resizeOverlayEl = null;
615
- if (widget.onColumnResize)
616
- instance.invoke("onColumnResize", { width, column: hdwidget }, hdinst);
617
- header.set("width", width);
618
- instance.setState({
619
- dimensionsVersion: instance.state.dimensionsVersion + 1,
620
- colWidth: {
621
- ...instance.state.colWidth,
622
- [hdwidget.uniqueColumnId]: width,
623
- },
624
- });
625
- },
626
- onDblClick: () => {
627
- let table = gridEl.querySelector("table");
628
- let parentEl = table.parentElement;
629
- let tableClone = table.cloneNode(true);
630
- tableClone.childNodes.forEach((tbody) => {
631
- tbody.childNodes.forEach((tr) => {
632
- tr.childNodes.forEach((td, index) => {
633
- if (index == colIndex) {
634
- td.style.maxWidth = null;
635
- td.style.minWidth = null;
636
- td.style.width = "auto";
637
- } else {
638
- td.style.display = "none";
639
- }
640
- });
641
- });
642
- });
643
- tableClone.style.position = "absolute";
644
- tableClone.style.visibility = "hidden";
645
- tableClone.style.top = 0;
646
- tableClone.style.left = 0;
647
- tableClone.style.width = "auto";
648
- parentEl.appendChild(tableClone);
649
- let width = tableClone.offsetWidth;
650
- parentEl.removeChild(tableClone);
651
- header.set("width", width);
652
- instance.setState({
653
- dimensionsVersion: instance.state.dimensionsVersion + 1,
654
- colWidth: {
655
- ...instance.state.colWidth,
656
- [hdwidget.uniqueColumnId]: width,
657
- },
658
- });
659
- },
660
- });
661
- }}
662
- />
663
- );
676
+ resizer = this.renderResizer(instance, hdinst, header, colIndex);
677
+ if (colIndex > 0) {
678
+ let hdinstPrev = line.children[colIndex - 1];
679
+ let headerPrev = hdinstPrev.components[`header${l + 1}`];
680
+ prevColumnResizer = this.renderResizer(instance, hdinstPrev, headerPrev, colIndex, true);
681
+ }
664
682
  }
665
683
  }
666
684
 
@@ -686,6 +704,7 @@ export class Grid extends Widget {
686
704
  {getContent(content)}
687
705
  {sortIcon}
688
706
  {tool}
707
+ {prevColumnResizer}
689
708
  {resizer}
690
709
  </th>
691
710
  );
@@ -743,7 +762,7 @@ export class Grid extends Widget {
743
762
  widget: () => <div className={CSS.element(baseClass, "col-header-drag-clone")}>{data.text}</div>,
744
763
  },
745
764
  },
746
- () => { }
765
+ () => {}
747
766
  );
748
767
  }
749
768
  }
@@ -769,14 +788,14 @@ export class Grid extends Widget {
769
788
 
770
789
  let sorters = direction
771
790
  ? [
772
- {
773
- field,
774
- direction,
775
- value,
776
- comparer,
777
- sortOptions,
778
- },
779
- ]
791
+ {
792
+ field,
793
+ direction,
794
+ value,
795
+ comparer,
796
+ sortOptions,
797
+ },
798
+ ]
780
799
  : null;
781
800
 
782
801
  instance.set("sorters", sorters);
@@ -1018,7 +1037,6 @@ export class Grid extends Widget {
1018
1037
  )
1019
1038
  );
1020
1039
 
1021
-
1022
1040
  if (g.showHeader) {
1023
1041
  record.vdom.push(this.renderHeader(context, instance, record.key + "-header", false, false));
1024
1042
  if (hasFixedColumns)
@@ -1076,7 +1094,7 @@ export class Grid extends Widget {
1076
1094
  instance,
1077
1095
  record.grouping,
1078
1096
  record.level,
1079
- record.group || { "$key": "fixed-footer" },
1097
+ record.group || { $key: "fixed-footer" },
1080
1098
  record.key + "-footer",
1081
1099
  record.store,
1082
1100
  true,
@@ -1089,7 +1107,7 @@ export class Grid extends Widget {
1089
1107
  instance,
1090
1108
  record.grouping,
1091
1109
  record.level,
1092
- record.group || { "$key": "fixed-footer" },
1110
+ record.group || { $key: "fixed-footer" },
1093
1111
  record.key + "-footer",
1094
1112
  record.store,
1095
1113
  true,
@@ -1215,8 +1233,8 @@ class GridComponent extends VDOM.Component {
1215
1233
  style={
1216
1234
  this.rowHeight > 0
1217
1235
  ? {
1218
- height: this.rowHeight + 1,
1219
- }
1236
+ height: this.rowHeight + 1,
1237
+ }
1220
1238
  : null
1221
1239
  }
1222
1240
  >
@@ -1484,8 +1502,6 @@ class GridComponent extends VDOM.Component {
1484
1502
  true
1485
1503
  )
1486
1504
  );
1487
-
1488
-
1489
1505
  }
1490
1506
  }
1491
1507
  }
@@ -1915,8 +1931,7 @@ class GridComponent extends VDOM.Component {
1915
1931
  };
1916
1932
  instance.invoke("onColumnDrop", e, instance);
1917
1933
  }
1918
- }
1919
- catch (err) {
1934
+ } catch (err) {
1920
1935
  console.error("Grid drop operation failed. Please fix this error:", err);
1921
1936
  }
1922
1937
 
@@ -2483,8 +2498,26 @@ class GridComponent extends VDOM.Component {
2483
2498
  }
2484
2499
  }
2485
2500
 
2486
- if (futureState.cellEdit && !wasCellEditing)
2487
- this.cellEditUndoData = this.getRecordAt(futureState.cursor).data;
2501
+ if (futureState.cellEdit && !wasCellEditing) {
2502
+ let record = this.getRecordAt(futureState.cursor);
2503
+ let cellEditUndoData = record.data;
2504
+
2505
+ if (
2506
+ widget.onBeforeCellEdit &&
2507
+ this.props.instance.invoke(
2508
+ "onBeforeCellEdit",
2509
+ {
2510
+ column: visibleColumns[futureState.cursorCellIndex],
2511
+ data: cellEditUndoData,
2512
+ field: visibleColumns[futureState.cursorCellIndex].field,
2513
+ },
2514
+ record
2515
+ ) === false
2516
+ )
2517
+ return;
2518
+
2519
+ this.cellEditUndoData = cellEditUndoData;
2520
+ }
2488
2521
 
2489
2522
  this.setState(newState, () => {
2490
2523
  if (this.state.focused && !this.state.cellEdit && wasCellEditing) FocusManager.focus(this.dom.el);
@@ -2501,7 +2534,7 @@ class GridComponent extends VDOM.Component {
2501
2534
  hscroll = true;
2502
2535
  item =
2503
2536
  item.firstChild.children[
2504
- this.state.cursorCellIndex - this.props.instance.fixedColumnCount
2537
+ this.state.cursorCellIndex - this.props.instance.fixedColumnCount
2505
2538
  ];
2506
2539
  } else {
2507
2540
  let fixedItem = this.dom.fixedTable.querySelector(`tbody[data-record-key="${record.key}"]`);
@@ -3155,7 +3188,6 @@ class AvgHeight {
3155
3188
  }
3156
3189
  }
3157
3190
 
3158
-
3159
3191
  function getDragDropEvent(ev) {
3160
3192
  return {
3161
3193
  event: ev,
@@ -3164,7 +3196,7 @@ function getDragDropEvent(ev) {
3164
3196
  source: {
3165
3197
  width: 32,
3166
3198
  height: 32,
3167
- margin: []
3168
- }
3199
+ margin: [],
3200
+ },
3169
3201
  };
3170
- }
3202
+ }
@@ -613,6 +613,15 @@
613
613
  cursor: col-resize;
614
614
  }
615
615
 
616
+ .#{$element}#{$name}-col-resizer-prev-col {
617
+ position: absolute;
618
+ left: 0;
619
+ top: 0;
620
+ bottom: 0;
621
+ width: 5px;
622
+ cursor: col-resize;
623
+ }
624
+
616
625
  .#{$element}#{$name}-resize-overlay {
617
626
  position: absolute;
618
627
  display: block;
@@ -1,38 +1,39 @@
1
- import {Widget, VDOM} from '../../ui/Widget';
2
- import {HtmlElement} from '../HtmlElement';
3
- import {preventFocusOnTouch} from '../../ui/FocusManager';
4
- import {isUndefined} from '../../util/isUndefined';
1
+ import { Widget, VDOM } from "../../ui/Widget";
2
+ import { HtmlElement } from "../HtmlElement";
3
+ import { preventFocusOnTouch } from "../../ui/FocusManager";
4
+ import { isUndefined } from "../../util/isUndefined";
5
5
 
6
6
  export class Tab extends HtmlElement {
7
-
8
7
  declareData() {
9
- super.declareData({
10
- tab: undefined,
11
- value: undefined,
12
- disabled: undefined,
13
- text: undefined
14
- }, ...arguments);
8
+ super.declareData(
9
+ {
10
+ tab: undefined,
11
+ value: undefined,
12
+ disabled: undefined,
13
+ text: undefined,
14
+ },
15
+ ...arguments
16
+ );
15
17
  }
16
18
 
17
19
  prepareData(context, instance) {
18
- let {data} = instance;
20
+ let { data } = instance;
19
21
  data.stateMods = {
20
22
  active: data.tab == data.value,
21
23
  disabled: data.disabled,
22
- shape: this.shape
24
+ shape: this.shape,
23
25
  };
24
- if (this.default && isUndefined(data.value))
25
- instance.set('value', data.tab);
26
+ if (this.default && isUndefined(data.value)) instance.set("value", data.tab);
26
27
  super.prepareData(context, instance);
27
28
  }
28
29
 
29
30
  isValidHtmlAttribute(attrName) {
30
31
  switch (attrName) {
31
- case 'value':
32
- case 'tab':
33
- case 'text':
34
- case 'disabled':
35
- case 'default':
32
+ case "value":
33
+ case "tab":
34
+ case "text":
35
+ case "disabled":
36
+ case "default":
36
37
  return false;
37
38
 
38
39
  default:
@@ -43,41 +44,39 @@ export class Tab extends HtmlElement {
43
44
  attachProps(context, instance, props) {
44
45
  super.attachProps(context, instance, props);
45
46
 
46
- let {data} = instance;
47
+ let { data } = instance;
47
48
  if (!data.disabled) {
48
- props.href = '#';
49
+ props.href = "#";
49
50
  delete props.value;
50
51
 
51
- props.onMouseDown = e => {
52
- if (this.onMouseDown)
53
- instance.invoke('onMouseDown', e, instance);
52
+ props.onMouseDown = (e) => {
53
+ if (this.onMouseDown) instance.invoke("onMouseDown", e, instance);
54
54
  preventFocusOnTouch(e);
55
55
  };
56
56
 
57
- props.onClick = e => this.handleClick(e, instance);
57
+ props.onClick = (e) => this.handleClick(e, instance);
58
58
  }
59
59
  }
60
60
 
61
61
  handleClick(e, instance) {
62
-
63
- if (this.onClick)
64
- instance.invoke('onClick', e, instance);
62
+ if (this.onClick && instance.invoke("onClick", e, instance) === false) {
63
+ return;
64
+ }
65
65
 
66
66
  e.preventDefault();
67
67
  e.stopPropagation();
68
68
 
69
- let {data} = instance;
69
+ let { data } = instance;
70
70
 
71
- if (data.disabled)
72
- return;
71
+ if (data.disabled) return;
73
72
 
74
- instance.set('value', data.tab);
73
+ instance.set("value", data.tab);
75
74
  }
76
75
  }
77
76
 
78
77
  Tab.prototype.baseClass = "tab";
79
- Tab.prototype.tag = 'a';
78
+ Tab.prototype.tag = "a";
80
79
  Tab.prototype.focusOnMouseDown = false;
81
80
  Tab.prototype.default = false;
82
81
 
83
- Widget.alias('tab', Tab);
82
+ Widget.alias("tab", Tab);