cx 24.11.4 → 25.1.1

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,228 +1,228 @@
1
- import { preventFocusOnTouch, unfocusElement } from "../../ui/FocusManager";
2
- import { VDOM } from "../../ui/Widget";
3
- import { closest } from "../../util/DOM";
4
- import { isTouchEvent } from "../../util/isTouchEvent";
5
- import { KeyCode } from "../../util/KeyCode";
6
- import { ValidationGroup } from "../../widgets/form/ValidationGroup";
7
- import { ddDetect, ddMouseDown, ddMouseUp, isDragHandleEvent } from "../drag-drop/ops";
8
- import { GridRowLine } from "./GridRowLine";
9
-
10
- export class GridRow extends ValidationGroup {
11
- declareData(...args) {
12
- super.declareData(...args, {
13
- hoverId: undefined,
14
- });
15
- }
16
-
17
- init() {
18
- this.items = [];
19
- for (let i = 0; i < 10; i++) {
20
- if (this["line" + i])
21
- this.items.push(
22
- GridRowLine.create(this["line" + i], {
23
- recordName: this.recordName,
24
- }),
25
- );
26
- }
27
- super.init();
28
- }
29
-
30
- explore(context, instance) {
31
- context.push("dragHandles", (instance.dragHandles = []));
32
- super.explore(context, instance);
33
- }
34
-
35
- exploreCleanup(context, instance) {
36
- super.exploreCleanup(context, instance);
37
- context.pop("dragHandles");
38
- }
39
- }
40
-
41
- GridRow.prototype.styled = true; //styles used on the wrapper component
42
-
43
- export class GridRowComponent extends VDOM.Component {
44
- constructor(props) {
45
- super(props);
46
- this.onMouseMove = this.onMouseMove.bind(this);
47
- this.onMouseDown = this.onMouseDown.bind(this);
48
- this.onMouseLeave = this.onMouseLeave.bind(this);
49
- this.onClick = this.onClick.bind(this);
50
- this.onKeyDown = this.onKeyDown.bind(this);
51
-
52
- let { grid, instance } = props;
53
-
54
- if (grid.widget.onRowDoubleClick)
55
- this.onDoubleClick = (e) => {
56
- grid.invoke("onRowDoubleClick", e, instance);
57
- };
58
-
59
- if (grid.widget.cellEditable)
60
- this.onDoubleClick = (e) => {
61
- this.props.parent.moveCursor(this.props.cursorIndex, {
62
- cellEdit: true,
63
- });
64
- e.preventDefault(); //prevent text selection
65
- };
66
-
67
- if (grid.widget.onRowContextMenu)
68
- this.onRowContextMenu = (e) => {
69
- grid.invoke("onRowContextMenu", e, instance);
70
- };
71
- }
72
-
73
- render() {
74
- let { className, dragSource, instance, record, useTrTag, children } = this.props;
75
- let { data, widget } = instance;
76
- let { CSS } = widget;
77
- let move, up, keyDown, leave;
78
-
79
- if (dragSource || data.hoverId) {
80
- move = this.onMouseMove;
81
- up = ddMouseUp;
82
- }
83
-
84
- if (data.hoverId) {
85
- leave = this.onMouseLeave;
86
- }
87
-
88
- if (widget.onRowClick) keyDown = this.onKeyDown;
89
-
90
- return VDOM.createElement(
91
- useTrTag ? "tr" : "tbody",
92
- {
93
- className: CSS.expand(data.classNames, className, this.state && this.state.hover && CSS.state("hover")),
94
- style: data.style,
95
- onClick: this.onClick,
96
- onDoubleClick: this.onDoubleClick,
97
- onTouchStart: this.onMouseDown,
98
- onMouseDown: this.onMouseDown,
99
- onTouchMove: move,
100
- onMouseMove: move,
101
- onMouseLeave: leave,
102
- onTouchEnd: up,
103
- onMouseUp: up,
104
- onKeyDown: keyDown,
105
- onContextMenu: this.onRowContextMenu,
106
- "data-record-key": record.key,
107
- },
108
- children,
109
- );
110
- }
111
-
112
- onMouseDown(e) {
113
- let { grid, record, instance, parent, cursorIndex } = this.props;
114
-
115
- if (this.props.dragSource) {
116
- ddMouseDown(e);
117
- if (isDragHandleEvent(e) || instance.dragHandles.length == 0) {
118
- e.preventDefault();
119
- e.stopPropagation();
120
-
121
- //close context menu
122
- unfocusElement(e.target, false);
123
- }
124
- }
125
-
126
- let { store, widget } = grid;
127
-
128
- if (widget.selectable) preventFocusOnTouch(e);
129
-
130
- parent.moveCursor(cursorIndex, {
131
- select:
132
- !isTouchEvent() &&
133
- (e.shiftKey || e.ctrlKey || !widget.selection.isSelected(store, record.data, record.index)),
134
- selectRange: e.shiftKey,
135
- selectOptions: {
136
- toggle: e.ctrlKey && !e.shiftKey,
137
- add: e.ctrlKey && e.shiftKey,
138
- },
139
- cellIndex: this.getCellIndex(e),
140
- });
141
-
142
- if (e.shiftKey && !isTouchEvent()) e.preventDefault();
143
- }
144
-
145
- onMouseMove(e) {
146
- let { grid, instance, parent, record } = this.props;
147
- if (ddDetect(e) && (isDragHandleEvent(e) || instance.dragHandles.length == 0)) parent.beginDragDrop(e, record);
148
- if (grid.hoverSync && instance.data.hoverId != null)
149
- grid.hoverSync.report(grid.widget.hoverChannel, instance.data.hoverId, true);
150
- }
151
-
152
- onMouseLeave(e) {
153
- let { grid, instance } = this.props;
154
- if (grid.hoverSync && instance.data.hoverId != null)
155
- grid.hoverSync.report(grid.widget.hoverChannel, instance.data.hoverId, false);
156
- }
157
-
158
- getCellIndex(e) {
159
- let td = closest(e.target, (node) => node.tagName == "TD");
160
- if (td)
161
- return (
162
- (this.props.fixed ? 0 : this.props.grid.fixedColumnCount) +
163
- Array.from(td.parentElement.children).indexOf(td)
164
- );
165
- return -1;
166
- }
167
-
168
- onKeyDown(e) {
169
- let { grid, instance } = this.props;
170
-
171
- if (e.keyCode == KeyCode.enter && grid.invoke("onRowClick", e, instance) === false) {
172
- e.stopPropagation();
173
- }
174
- }
175
-
176
- onClick(e) {
177
- let { grid, record, instance, parent, cursorIndex } = this.props;
178
- let { store, widget } = grid;
179
-
180
- if (grid.widget.onRowClick) {
181
- if (grid.invoke("onRowClick", e, instance) === false) return;
182
- }
183
-
184
- e.stopPropagation();
185
-
186
- parent.moveCursor(cursorIndex, {
187
- select:
188
- isTouchEvent() ||
189
- (!e.shiftKey && !e.ctrlKey && widget.selection.isSelected(store, record.data, record.index)),
190
- selectRange: e.shiftKey,
191
- selectOptions: {
192
- toggle: e.ctrlKey && !e.shiftKey,
193
- add: e.ctrlKey && e.shiftKey,
194
- },
195
- cellIndex: this.getCellIndex(e),
196
- });
197
- }
198
-
199
- shouldComponentUpdate(props, state) {
200
- return (
201
- props.shouldUpdate !== false ||
202
- props.record != this.props.record ||
203
- props.cursor != this.props.cursor ||
204
- props.selected != this.props.selected ||
205
- props.isBeingDragged != this.props.isBeingDragged ||
206
- props.cursorIndex !== this.props.cursorIndex ||
207
- props.cursorCellIndex !== this.props.cursorCellIndex ||
208
- props.cellEdit !== this.props.cellEdit ||
209
- props.dimensionsVersion !== this.props.dimensionsVersion ||
210
- props.isDraggedOver !== this.props.isDraggedOver ||
211
- state !== this.state
212
- );
213
- }
214
-
215
- compontentWillUnmount() {
216
- this.unsubscribeHoverSync && this.unsubscribeHoverSync();
217
- }
218
-
219
- componentDidMount() {
220
- let { grid } = this.props;
221
- if (grid.hoverSync) {
222
- this.unsubscribeHoverSync = grid.hoverSync.subscribe(grid.widget.hoverChannel, (hoverId) => {
223
- let hover = hoverId === this.props.instance.data.hoverId;
224
- if (!this.state || hover !== this.state.hover) this.setState({ hover });
225
- });
226
- }
227
- }
228
- }
1
+ import { preventFocusOnTouch, unfocusElement } from "../../ui/FocusManager";
2
+ import { VDOM } from "../../ui/Widget";
3
+ import { closest } from "../../util/DOM";
4
+ import { isTouchEvent } from "../../util/isTouchEvent";
5
+ import { KeyCode } from "../../util/KeyCode";
6
+ import { ValidationGroup } from "../../widgets/form/ValidationGroup";
7
+ import { ddDetect, ddMouseDown, ddMouseUp, isDragHandleEvent } from "../drag-drop/ops";
8
+ import { GridRowLine } from "./GridRowLine";
9
+
10
+ export class GridRow extends ValidationGroup {
11
+ declareData(...args) {
12
+ super.declareData(...args, {
13
+ hoverId: undefined,
14
+ });
15
+ }
16
+
17
+ init() {
18
+ this.items = [];
19
+ for (let i = 0; i < 10; i++) {
20
+ if (this["line" + i])
21
+ this.items.push(
22
+ GridRowLine.create(this["line" + i], {
23
+ recordName: this.recordName,
24
+ }),
25
+ );
26
+ }
27
+ super.init();
28
+ }
29
+
30
+ explore(context, instance) {
31
+ context.push("dragHandles", (instance.dragHandles = []));
32
+ super.explore(context, instance);
33
+ }
34
+
35
+ exploreCleanup(context, instance) {
36
+ super.exploreCleanup(context, instance);
37
+ context.pop("dragHandles");
38
+ }
39
+ }
40
+
41
+ GridRow.prototype.styled = true; //styles used on the wrapper component
42
+
43
+ export class GridRowComponent extends VDOM.Component {
44
+ constructor(props) {
45
+ super(props);
46
+ this.onMouseMove = this.onMouseMove.bind(this);
47
+ this.onMouseDown = this.onMouseDown.bind(this);
48
+ this.onMouseLeave = this.onMouseLeave.bind(this);
49
+ this.onClick = this.onClick.bind(this);
50
+ this.onKeyDown = this.onKeyDown.bind(this);
51
+
52
+ let { grid, instance } = props;
53
+
54
+ if (grid.widget.onRowDoubleClick)
55
+ this.onDoubleClick = (e) => {
56
+ grid.invoke("onRowDoubleClick", e, instance);
57
+ };
58
+
59
+ if (grid.widget.cellEditable)
60
+ this.onDoubleClick = (e) => {
61
+ this.props.parent.moveCursor(this.props.cursorIndex, {
62
+ cellEdit: true,
63
+ });
64
+ e.preventDefault(); //prevent text selection
65
+ };
66
+
67
+ if (grid.widget.onRowContextMenu)
68
+ this.onRowContextMenu = (e) => {
69
+ grid.invoke("onRowContextMenu", e, instance);
70
+ };
71
+ }
72
+
73
+ render() {
74
+ let { className, dragSource, instance, record, useTrTag, children } = this.props;
75
+ let { data, widget } = instance;
76
+ let { CSS } = widget;
77
+ let move, up, keyDown, leave;
78
+
79
+ if (dragSource || data.hoverId != null) {
80
+ move = this.onMouseMove;
81
+ up = ddMouseUp;
82
+ }
83
+
84
+ if (data.hoverId != null) {
85
+ leave = this.onMouseLeave;
86
+ }
87
+
88
+ if (widget.onRowClick) keyDown = this.onKeyDown;
89
+
90
+ return VDOM.createElement(
91
+ useTrTag ? "tr" : "tbody",
92
+ {
93
+ className: CSS.expand(data.classNames, className, this.state && this.state.hover && CSS.state("hover")),
94
+ style: data.style,
95
+ onClick: this.onClick,
96
+ onDoubleClick: this.onDoubleClick,
97
+ onTouchStart: this.onMouseDown,
98
+ onMouseDown: this.onMouseDown,
99
+ onTouchMove: move,
100
+ onMouseMove: move,
101
+ onMouseLeave: leave,
102
+ onTouchEnd: up,
103
+ onMouseUp: up,
104
+ onKeyDown: keyDown,
105
+ onContextMenu: this.onRowContextMenu,
106
+ "data-record-key": record.key,
107
+ },
108
+ children,
109
+ );
110
+ }
111
+
112
+ onMouseDown(e) {
113
+ let { grid, record, instance, parent, cursorIndex } = this.props;
114
+
115
+ if (this.props.dragSource) {
116
+ ddMouseDown(e);
117
+ if (isDragHandleEvent(e) || instance.dragHandles.length == 0) {
118
+ e.preventDefault();
119
+ e.stopPropagation();
120
+
121
+ //close context menu
122
+ unfocusElement(e.target, false);
123
+ }
124
+ }
125
+
126
+ let { store, widget } = grid;
127
+
128
+ if (widget.selectable) preventFocusOnTouch(e);
129
+
130
+ parent.moveCursor(cursorIndex, {
131
+ select:
132
+ !isTouchEvent() &&
133
+ (e.shiftKey || e.ctrlKey || !widget.selection.isSelected(store, record.data, record.index)),
134
+ selectRange: e.shiftKey,
135
+ selectOptions: {
136
+ toggle: e.ctrlKey && !e.shiftKey,
137
+ add: e.ctrlKey && e.shiftKey,
138
+ },
139
+ cellIndex: this.getCellIndex(e),
140
+ });
141
+
142
+ if (e.shiftKey && !isTouchEvent()) e.preventDefault();
143
+ }
144
+
145
+ onMouseMove(e) {
146
+ let { grid, instance, parent, record } = this.props;
147
+ if (ddDetect(e) && (isDragHandleEvent(e) || instance.dragHandles.length == 0)) parent.beginDragDrop(e, record);
148
+ if (grid.hoverSync && instance.data.hoverId != null)
149
+ grid.hoverSync.report(grid.widget.hoverChannel, instance.data.hoverId, true);
150
+ }
151
+
152
+ onMouseLeave(e) {
153
+ let { grid, instance } = this.props;
154
+ if (grid.hoverSync && instance.data.hoverId != null)
155
+ grid.hoverSync.report(grid.widget.hoverChannel, instance.data.hoverId, false);
156
+ }
157
+
158
+ getCellIndex(e) {
159
+ let td = closest(e.target, (node) => node.tagName == "TD");
160
+ if (td)
161
+ return (
162
+ (this.props.fixed ? 0 : this.props.grid.fixedColumnCount) +
163
+ Array.from(td.parentElement.children).indexOf(td)
164
+ );
165
+ return -1;
166
+ }
167
+
168
+ onKeyDown(e) {
169
+ let { grid, instance } = this.props;
170
+
171
+ if (e.keyCode == KeyCode.enter && grid.invoke("onRowClick", e, instance) === false) {
172
+ e.stopPropagation();
173
+ }
174
+ }
175
+
176
+ onClick(e) {
177
+ let { grid, record, instance, parent, cursorIndex } = this.props;
178
+ let { store, widget } = grid;
179
+
180
+ if (grid.widget.onRowClick) {
181
+ if (grid.invoke("onRowClick", e, instance) === false) return;
182
+ }
183
+
184
+ e.stopPropagation();
185
+
186
+ parent.moveCursor(cursorIndex, {
187
+ select:
188
+ isTouchEvent() ||
189
+ (!e.shiftKey && !e.ctrlKey && widget.selection.isSelected(store, record.data, record.index)),
190
+ selectRange: e.shiftKey,
191
+ selectOptions: {
192
+ toggle: e.ctrlKey && !e.shiftKey,
193
+ add: e.ctrlKey && e.shiftKey,
194
+ },
195
+ cellIndex: this.getCellIndex(e),
196
+ });
197
+ }
198
+
199
+ shouldComponentUpdate(props, state) {
200
+ return (
201
+ props.shouldUpdate !== false ||
202
+ props.record != this.props.record ||
203
+ props.cursor != this.props.cursor ||
204
+ props.selected != this.props.selected ||
205
+ props.isBeingDragged != this.props.isBeingDragged ||
206
+ props.cursorIndex !== this.props.cursorIndex ||
207
+ props.cursorCellIndex !== this.props.cursorCellIndex ||
208
+ props.cellEdit !== this.props.cellEdit ||
209
+ props.dimensionsVersion !== this.props.dimensionsVersion ||
210
+ props.isDraggedOver !== this.props.isDraggedOver ||
211
+ state !== this.state
212
+ );
213
+ }
214
+
215
+ compontentWillUnmount() {
216
+ this.unsubscribeHoverSync && this.unsubscribeHoverSync();
217
+ }
218
+
219
+ componentDidMount() {
220
+ let { grid } = this.props;
221
+ if (grid.hoverSync) {
222
+ this.unsubscribeHoverSync = grid.hoverSync.subscribe(grid.widget.hoverChannel, (hoverId) => {
223
+ let hover = hoverId === this.props.instance.data.hoverId;
224
+ if (!this.state || hover !== this.state.hover) this.setState({ hover });
225
+ });
226
+ }
227
+ }
228
+ }