cx 24.6.3 → 24.7.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.
package/src/ui/index.d.ts CHANGED
@@ -1,42 +1,42 @@
1
- export * from "./Controller";
2
- export * from "./Widget";
3
- export * from "./Container";
4
- export * from "./PureContainer";
5
- export * from "./Repeater";
6
- export * from "./Rescope";
7
- export * from "./StaticText";
8
- export * from "./Text";
9
- export * from "./CSS";
10
- export * from "./CSSHelper";
11
- export * from "./FocusManager";
12
- export * from "./ResizeManager";
13
- export * from "./ZIndexManager";
14
- export * from "./Format";
15
- export * from "./Culture";
16
- export * from "./Localization";
17
- export * from "./Cx";
18
- export * from "./Instance";
19
- export * from "./RenderingContext";
20
- export * from "./ContentResolver";
21
- export * from "./batchUpdates";
22
- export * from "./IsolatedScope";
23
- export * from "./DetachedScope";
24
- export * from "./Restate";
25
- export * from "./DataProxy";
26
- export * from "./keyboardShortcuts";
27
- export * from "./createFunctionalComponent";
28
- export * from "./StructuredInstanceDataAccessor";
29
- export * from "./HoverSync";
30
-
31
- export * from "./selection/index";
32
- export * from "./layout/index";
33
- export * from "./app/index";
34
- export * from "./adapter/index";
35
-
36
- export * from "./bind";
37
- export * from "./tpl";
38
- export * from "./expr";
39
-
40
- //re-export computable here
41
- import { computable } from "../data/computable";
42
- export { computable };
1
+ export * from "./Controller";
2
+ export * from "./Widget";
3
+ export * from "./Container";
4
+ export * from "./PureContainer";
5
+ export * from "./Repeater";
6
+ export * from "./Rescope";
7
+ export * from "./StaticText";
8
+ export * from "./Text";
9
+ export * from "./CSS";
10
+ export * from "./CSSHelper";
11
+ export * from "./FocusManager";
12
+ export * from "./ResizeManager";
13
+ export * from "./ZIndexManager";
14
+ export * from "./Format";
15
+ export * from "./Culture";
16
+ export * from "./Localization";
17
+ export * from "./Cx";
18
+ export * from "./Instance";
19
+ export * from "./RenderingContext";
20
+ export * from "./ContentResolver";
21
+ export * from "./batchUpdates";
22
+ export * from "./IsolatedScope";
23
+ export * from "./DetachedScope";
24
+ export * from "./Restate";
25
+ export * from "./DataProxy";
26
+ export * from "./keyboardShortcuts";
27
+ export * from "./createFunctionalComponent";
28
+ export * from "./StructuredInstanceDataAccessor";
29
+ export * from "./HoverSync";
30
+
31
+ export * from "./selection/index";
32
+ export * from "./layout/index";
33
+ export * from "./app/index";
34
+ export * from "./adapter/index";
35
+
36
+ export * from "./bind";
37
+ export * from "./tpl";
38
+ export * from "./expr";
39
+
40
+ //re-export computable here
41
+ import { computable } from "../data/computable";
42
+ export { computable };
@@ -1,4 +1,4 @@
1
- export class Console {
2
- static log(...args: unknown[]): void;
3
- static warn(...args: unknown[]): void;
4
- }
1
+ export class Console {
2
+ static log(...args: unknown[]): void;
3
+ static warn(...args: unknown[]): void;
4
+ }
@@ -1,214 +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:
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;
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;
@@ -203,6 +203,7 @@ class Input extends VDOM.Component {
203
203
  }
204
204
 
205
205
  onClearClick(e) {
206
+ this.input.value = ""; // prevent onChange call with old text value on blur or component unmount
206
207
  this.props.instance.set("value", this.props.instance.widget.emptyValue, { immediate: true });
207
208
  }
208
209
 
@@ -1,34 +1,34 @@
1
- import * as Cx from "../../core";
2
- import { FieldProps } from "./Field";
3
-
4
- interface UploadButtonProps extends FieldProps {
5
- /** Text description. */
6
- text?: Cx.StringProp;
7
-
8
- url?: Cx.StringProp;
9
-
10
- /** Base CSS class to be applied to the element. Default is 'uploadbutton'. */
11
- baseClass?: string;
12
-
13
- /** Defaults to `false`. Set to `true` to enable multiple selection. */
14
- multiple?: boolean;
15
-
16
- method?: string;
17
- uploadInProgressText?: string;
18
-
19
- /** Defaults to `false`. Set to `true` to abort uploads if the button is destroyed (unmounted). */
20
- abortOnDestroy?: boolean;
21
-
22
- /** Defines file types that are accepted for upload. */
23
- accept?: Cx.StringProp;
24
-
25
- /** Name of the icon to be put on the left side of the button. */
26
- icon?: Cx.StringProp;
27
-
28
- onUploadStarting?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => boolean) | string;
29
- onUploadComplete?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => void) | string;
30
- onUploadProgress?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
31
- onUploadError?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
32
- }
33
-
34
- export class UploadButton extends Cx.Widget<UploadButtonProps> {}
1
+ import * as Cx from "../../core";
2
+ import { FieldProps } from "./Field";
3
+
4
+ interface UploadButtonProps extends FieldProps {
5
+ /** Text description. */
6
+ text?: Cx.StringProp;
7
+
8
+ url?: Cx.StringProp;
9
+
10
+ /** Base CSS class to be applied to the element. Default is 'uploadbutton'. */
11
+ baseClass?: string;
12
+
13
+ /** Defaults to `false`. Set to `true` to enable multiple selection. */
14
+ multiple?: boolean;
15
+
16
+ method?: string;
17
+ uploadInProgressText?: string;
18
+
19
+ /** Defaults to `false`. Set to `true` to abort uploads if the button is destroyed (unmounted). */
20
+ abortOnDestroy?: boolean;
21
+
22
+ /** Defines file types that are accepted for upload. */
23
+ accept?: Cx.StringProp;
24
+
25
+ /** Name of the icon to be put on the left side of the button. */
26
+ icon?: Cx.StringProp;
27
+
28
+ onUploadStarting?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => boolean) | string;
29
+ onUploadComplete?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => void) | string;
30
+ onUploadProgress?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
31
+ onUploadError?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
32
+ }
33
+
34
+ export class UploadButton extends Cx.Widget<UploadButtonProps> {}