cx 24.4.5 → 24.4.7

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,213 +1,214 @@
1
- import { Widget, VDOM } from "../../ui/Widget";
2
- import { Container } from "../../ui/Container";
3
- import { parseStyle } from "../../util/parseStyle";
4
- import { registerDropZone, DragDropContext } from "./ops";
5
- import { findScrollableParent } from "../../util/findScrollableParent";
6
- import { isNumber } from "../../util/isNumber";
7
- import { getTopLevelBoundingClientRect } from "../../util/getTopLevelBoundingClientRect";
8
-
9
- export class DropZone extends Container {
10
- init() {
11
- this.overStyle = parseStyle(this.overStyle);
12
- this.nearStyle = parseStyle(this.nearStyle);
13
- this.farStyle = parseStyle(this.farStyle);
14
-
15
- if (isNumber(this.inflate)) {
16
- this.hinflate = this.inflate;
17
- this.vinflate = this.inflate;
18
- }
19
-
20
- super.init();
21
- }
22
-
23
- declareData() {
24
- return super.declareData(...arguments, {
25
- overClass: { structured: true },
26
- nearClass: { structured: true },
27
- farClass: { structured: true },
28
- overStyle: { structured: true },
29
- nearStyle: { structured: true },
30
- farStyle: { structured: true },
31
- data: { structured: true },
32
- });
33
- }
34
-
35
- render(context, instance, key) {
36
- return (
37
- <DropZoneComponent key={key} instance={instance}>
38
- {this.renderChildren(context, instance)}
39
- </DropZoneComponent>
40
- );
41
- }
42
- }
43
-
44
- DropZone.prototype.styled = true;
45
- DropZone.prototype.nearDistance = 0;
46
- DropZone.prototype.hinflate = 0;
47
- DropZone.prototype.vinflate = 0;
48
- DropZone.prototype.baseClass = "dropzone";
49
-
50
- Widget.alias("dropzone", DropZone);
51
-
52
- class DropZoneComponent extends VDOM.Component {
53
- constructor(props) {
54
- super(props);
55
- this.state = {
56
- state: false,
57
- };
58
- }
59
-
60
- render() {
61
- let { instance, children } = this.props;
62
- let { data, widget } = instance;
63
- let { CSS } = widget;
64
-
65
- let classes = [data.classNames, CSS.state(this.state.state)];
66
-
67
- let stateStyle;
68
-
69
- switch (this.state.state) {
70
- case "over":
71
- classes.push(data.overClass);
72
- stateStyle = parseStyle(data.overStyle);
73
- break;
74
- case "near":
75
- classes.push(data.nearClass);
76
- stateStyle = parseStyle(data.nearStyle);
77
- break;
78
- case "far":
79
- classes.push(data.farClass);
80
- stateStyle = parseStyle(data.farStyle);
81
- break;
82
- }
83
-
84
- return (
85
- <div
86
- className={CSS.expand(classes)}
87
- style={{ ...data.style, ...this.state.style, ...stateStyle }}
88
- ref={(el) => {
89
- this.el = el;
90
- }}
91
- >
92
- {children}
93
- </div>
94
- );
95
- }
96
-
97
- componentDidMount() {
98
- let dragDropOptions = this.context;
99
- let disabled = dragDropOptions && dragDropOptions.disabled;
100
- if (!disabled) this.unregister = registerDropZone(this);
101
- }
102
-
103
- componentWillUnmount() {
104
- this.unregister && this.unregister();
105
- }
106
-
107
- onDropTest(e) {
108
- let { instance } = this.props;
109
- let { widget } = instance;
110
- return !widget.onDropTest || instance.invoke("onDropTest", e, instance);
111
- }
112
-
113
- onDragStart(e) {
114
- this.setState({
115
- state: "far",
116
- });
117
- }
118
-
119
- onDragNear(e) {
120
- this.setState({
121
- state: "near",
122
- });
123
- }
124
-
125
- onDragAway(e) {
126
- this.setState({
127
- state: "far",
128
- });
129
- }
130
-
131
- onDragLeave(e) {
132
- let { nearDistance } = this.props.instance.widget;
133
- this.setState({
134
- state: nearDistance ? "near" : "far",
135
- style: null,
136
- });
137
- }
138
-
139
- onDragMeasure(e) {
140
- let rect = getTopLevelBoundingClientRect(this.el);
141
-
142
- let { instance } = this.props;
143
- let { widget } = instance;
144
-
145
- let { clientX, clientY } = e.cursor;
146
- let distance =
147
- Math.max(0, rect.left - clientX, clientX - rect.right) +
148
- Math.max(0, rect.top - clientY, clientY - rect.bottom);
149
-
150
- if (widget.hinflate > 0) {
151
- rect.left -= widget.hinflate;
152
- rect.right += widget.hinflate;
153
- }
154
-
155
- if (widget.vinflate > 0) {
156
- rect.top -= widget.vinflate;
157
- rect.bottom += widget.vinflate;
158
- }
159
-
160
- let { nearDistance } = widget;
161
-
162
- let over = rect.left <= clientX && clientX < rect.right && rect.top <= clientY && clientY < rect.bottom;
163
-
164
- return {
165
- over: over && distance,
166
- near: nearDistance && (over || distance < nearDistance),
167
- };
168
- }
169
-
170
- onDragEnter(e) {
171
- let { instance } = this.props;
172
- let { widget } = instance;
173
- let style = {};
174
-
175
- if (widget.matchWidth) style.width = `${e.source.width}px`;
176
-
177
- if (widget.matchHeight) style.height = `${e.source.height}px`;
178
-
179
- if (widget.matchMargin) style.margin = e.source.margin.join(" ");
180
-
181
- if (this.state != "over")
182
- this.setState({
183
- state: "over",
184
- style,
185
- });
186
- }
187
-
188
- onDragOver(e) {}
189
-
190
- onGetHScrollParent() {
191
- return findScrollableParent(this.el, true);
192
- }
193
-
194
- onGetVScrollParent() {
195
- return findScrollableParent(this.el);
196
- }
197
-
198
- onDrop(e) {
199
- let { instance } = this.props;
200
- let { widget } = instance;
201
-
202
- if (this.state.state == "over" && widget.onDrop) instance.invoke("onDrop", e, instance);
203
- }
204
-
205
- onDragEnd(e) {
206
- this.setState({
207
- state: false,
208
- style: null,
209
- });
210
- }
211
- }
212
-
213
- DropZoneComponent.contextType = DragDropContext;
1
+ import { Widget, VDOM } from "../../ui/Widget";
2
+ import { Container } from "../../ui/Container";
3
+ import { parseStyle } from "../../util/parseStyle";
4
+ import { registerDropZone, DragDropContext } from "./ops";
5
+ import { findScrollableParent } from "../../util/findScrollableParent";
6
+ import { isNumber } from "../../util/isNumber";
7
+ import { getTopLevelBoundingClientRect } from "../../util/getTopLevelBoundingClientRect";
8
+
9
+ export class DropZone extends Container {
10
+ init() {
11
+ this.overStyle = parseStyle(this.overStyle);
12
+ this.nearStyle = parseStyle(this.nearStyle);
13
+ this.farStyle = parseStyle(this.farStyle);
14
+
15
+ if (isNumber(this.inflate)) {
16
+ this.hinflate = this.inflate;
17
+ this.vinflate = this.inflate;
18
+ }
19
+
20
+ super.init();
21
+ }
22
+
23
+ declareData() {
24
+ return super.declareData(...arguments, {
25
+ overClass: { structured: true },
26
+ nearClass: { structured: true },
27
+ farClass: { structured: true },
28
+ overStyle: { structured: true },
29
+ nearStyle: { structured: true },
30
+ farStyle: { structured: true },
31
+ data: { structured: true },
32
+ });
33
+ }
34
+
35
+ render(context, instance, key) {
36
+ return (
37
+ <DropZoneComponent key={key} instance={instance}>
38
+ {this.renderChildren(context, instance)}
39
+ </DropZoneComponent>
40
+ );
41
+ }
42
+ }
43
+
44
+ DropZone.prototype.styled = true;
45
+ DropZone.prototype.nearDistance = 0;
46
+ DropZone.prototype.hinflate = 0;
47
+ DropZone.prototype.vinflate = 0;
48
+ DropZone.prototype.baseClass = "dropzone";
49
+
50
+ Widget.alias("dropzone", DropZone);
51
+
52
+ class DropZoneComponent extends VDOM.Component {
53
+ constructor(props) {
54
+ super(props);
55
+ this.state = {
56
+ state: false,
57
+ };
58
+ }
59
+
60
+ render() {
61
+ let { instance, children } = this.props;
62
+ let { data, widget } = instance;
63
+ let { CSS } = widget;
64
+
65
+ let classes = [data.classNames, CSS.state(this.state.state)];
66
+
67
+ let stateStyle;
68
+
69
+ switch (this.state.state) {
70
+ case "over":
71
+ classes.push(data.overClass);
72
+ stateStyle = parseStyle(data.overStyle);
73
+ break;
74
+ case "near":
75
+ classes.push(data.nearClass);
76
+ stateStyle = parseStyle(data.nearStyle);
77
+ break;
78
+ case "far":
79
+ classes.push(data.farClass);
80
+ stateStyle = parseStyle(data.farStyle);
81
+ break;
82
+ }
83
+
84
+ return (
85
+ <div
86
+ className={CSS.expand(classes)}
87
+ style={{ ...data.style, ...this.state.style, ...stateStyle }}
88
+ ref={(el) => {
89
+ this.el = el;
90
+ }}
91
+ >
92
+ {children}
93
+ </div>
94
+ );
95
+ }
96
+
97
+ componentDidMount() {
98
+ let dragDropOptions = this.context;
99
+ let disabled = dragDropOptions && dragDropOptions.disabled;
100
+ if (!disabled) this.unregister = registerDropZone(this);
101
+ }
102
+
103
+ componentWillUnmount() {
104
+ this.unregister && this.unregister();
105
+ }
106
+
107
+ onDropTest(e) {
108
+ let { instance } = this.props;
109
+ let { widget } = instance;
110
+ return !widget.onDropTest || instance.invoke("onDropTest", e, instance);
111
+ }
112
+
113
+ onDragStart(e) {
114
+ this.setState({
115
+ state: "far",
116
+ });
117
+ }
118
+
119
+ onDragNear(e) {
120
+ this.setState({
121
+ state: "near",
122
+ });
123
+ }
124
+
125
+ onDragAway(e) {
126
+ this.setState({
127
+ state: "far",
128
+ });
129
+ }
130
+
131
+ onDragLeave(e) {
132
+ let { nearDistance } = this.props.instance.widget;
133
+ this.setState({
134
+ state: nearDistance ? "near" : "far",
135
+ style: null,
136
+ });
137
+ }
138
+
139
+ onDragMeasure(e) {
140
+ let rect = getTopLevelBoundingClientRect(this.el);
141
+
142
+ let { instance } = this.props;
143
+ let { widget } = instance;
144
+
145
+ let { clientX, clientY } = e.cursor;
146
+ let distance =
147
+ Math.max(0, rect.left - clientX, clientX - rect.right) +
148
+ Math.max(0, rect.top - clientY, clientY - rect.bottom);
149
+
150
+ if (widget.hinflate > 0) {
151
+ rect.left -= widget.hinflate;
152
+ rect.right += widget.hinflate;
153
+ }
154
+
155
+ if (widget.vinflate > 0) {
156
+ rect.top -= widget.vinflate;
157
+ rect.bottom += widget.vinflate;
158
+ }
159
+
160
+ let { nearDistance } = widget;
161
+
162
+ let over = rect.left <= clientX && clientX < rect.right && rect.top <= clientY && clientY < rect.bottom;
163
+
164
+ return {
165
+ over:
166
+ over && Math.abs(clientX - (rect.left + rect.right) / 2) + Math.abs(clientY - (rect.top + rect.bottom) / 2),
167
+ near: nearDistance && (over || distance < nearDistance),
168
+ };
169
+ }
170
+
171
+ onDragEnter(e) {
172
+ let { instance } = this.props;
173
+ let { widget } = instance;
174
+ let style = {};
175
+
176
+ if (widget.matchWidth) style.width = `${e.source.width}px`;
177
+
178
+ if (widget.matchHeight) style.height = `${e.source.height}px`;
179
+
180
+ if (widget.matchMargin) style.margin = e.source.margin.join(" ");
181
+
182
+ if (this.state != "over")
183
+ this.setState({
184
+ state: "over",
185
+ style,
186
+ });
187
+ }
188
+
189
+ onDragOver(e) {}
190
+
191
+ onGetHScrollParent() {
192
+ return findScrollableParent(this.el, true);
193
+ }
194
+
195
+ onGetVScrollParent() {
196
+ return findScrollableParent(this.el);
197
+ }
198
+
199
+ onDrop(e) {
200
+ let { instance } = this.props;
201
+ let { widget } = instance;
202
+
203
+ if (this.state.state == "over" && widget.onDrop) instance.invoke("onDrop", e, instance);
204
+ }
205
+
206
+ onDragEnd(e) {
207
+ this.setState({
208
+ state: false,
209
+ style: null,
210
+ });
211
+ }
212
+ }
213
+
214
+ DropZoneComponent.contextType = DragDropContext;
@@ -96,6 +96,24 @@ interface GridColumnHeaderConfig {
96
96
  resizable?: boolean;
97
97
  }
98
98
 
99
+ interface GridColumnFooterConfig {
100
+ value?: Prop<any>;
101
+ format?: StringProp;
102
+ style?: StyleProp;
103
+ class?: StyleProp;
104
+ expand?: boolean;
105
+ }
106
+
107
+ interface GridColumnCaptionConfig {
108
+ value?: Prop<any>;
109
+ format?: StringProp;
110
+ style?: StyleProp;
111
+ class?: StyleProp;
112
+ children?: React.ReactNode;
113
+ items?: React.ReactNode;
114
+ expand?: boolean;
115
+ }
116
+
99
117
  interface GridColumnConfig {
100
118
  align?: GridColumnAlignment;
101
119
  field?: string;
@@ -110,13 +128,13 @@ interface GridColumnConfig {
110
128
  aggregateAlias?: string;
111
129
  aggregateField?: string;
112
130
  aggregateValue?: UnknownProp;
113
- caption?: StringProp;
131
+ caption?: GridColumnCaptionConfig | StringProp | false;
114
132
  class?: ClassProp;
115
133
  className?: ClassProp;
116
134
  draggable?: boolean;
117
135
  editable?: boolean;
118
136
  editor?: React.ReactNode;
119
- footer?: StringProp | false;
137
+ footer?: GridColumnFooterConfig | StringProp | false;
120
138
  items?: React.ReactNode;
121
139
  children?: React.ReactNode;
122
140
  key?: string;
@@ -323,7 +341,7 @@ interface GridProps<T = unknown> extends StyledContainerProps {
323
341
  sortField?: string;
324
342
  sortDirection?: string;
325
343
  },
326
- instance?: Instance,
344
+ instance?: Instance
327
345
  ) => FetchRecordsResult | Promise<FetchRecordsResult>;
328
346
 
329
347
  /** Callback function to be executed when a row is double-clicked. */
@@ -356,7 +374,7 @@ interface GridProps<T = unknown> extends StyledContainerProps {
356
374
  /** Callback to create a function that can be used to check whether a record is selectable. */
357
375
  onCreateIsRecordSelectable?: (
358
376
  params: any,
359
- instance: Instance,
377
+ instance: Instance
360
378
  ) => (record: T, options?: { range?: boolean; toggle?: boolean }) => boolean;
361
379
 
362
380
  /** Parameters whose change will cause scroll to be reset. */