cx 25.5.0 → 25.5.2

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,200 +1,203 @@
1
- import { Widget, VDOM, getContent } from "../../ui/Widget";
2
- import { Field, getFieldTooltip } from "./Field";
3
- import { tooltipMouseMove, tooltipMouseLeave } from "../overlay/tooltip-ops";
4
- import { stopPropagation } from "../../util/eventCallbacks";
5
- import { KeyCode } from "../../util/KeyCode";
6
- import CheckIcon from "../icons/check";
7
- import SquareIcon from "../icons/square";
8
-
9
- export class Checkbox extends Field {
10
- init() {
11
- if (this.checked) this.value = this.checked;
12
-
13
- super.init();
14
- }
15
-
16
- declareData() {
17
- super.declareData(
18
- {
19
- value: !this.indeterminate ? false : undefined,
20
- text: undefined,
21
- readOnly: undefined,
22
- disabled: undefined,
23
- enabled: undefined,
24
- required: undefined,
25
- viewText: undefined,
26
- },
27
- ...arguments
28
- );
29
- }
30
-
31
- renderWrap(context, instance, key, content) {
32
- let { data } = instance;
33
- return (
34
- <label
35
- key={key}
36
- className={data.classNames}
37
- onMouseDown={stopPropagation}
38
- onMouseMove={(e) => tooltipMouseMove(e, ...getFieldTooltip(instance))}
39
- onMouseLeave={(e) => tooltipMouseLeave(e, ...getFieldTooltip(instance))}
40
- onClick={(e) => {
41
- this.handleClick(e, instance);
42
- }}
43
- style={data.style}
44
- >
45
- {content}
46
- {this.labelPlacement && getContent(this.renderLabel(context, instance, "label"))}
47
- </label>
48
- );
49
- }
50
-
51
- validateRequired(context, instance) {
52
- let { data } = instance;
53
- if (!data.value) return this.requiredText;
54
- }
55
-
56
- renderNativeCheck(context, instance) {
57
- let { CSS, baseClass } = this;
58
- let { data } = instance;
59
- return (
60
- <input
61
- key="input"
62
- className={CSS.element(baseClass, "checkbox")}
63
- id={data.id}
64
- type="checkbox"
65
- checked={data.value || false}
66
- disabled={data.disabled}
67
- {...data.inputAttrs}
68
- onClick={stopPropagation}
69
- onChange={(e) => {
70
- this.handleChange(e, instance);
71
- }}
72
- />
73
- );
74
- }
75
-
76
- renderCheck(context, instance) {
77
- return <CheckboxCmp key="check" instance={instance} data={instance.data} />;
78
- }
79
-
80
- renderInput(context, instance, key) {
81
- let { data } = instance;
82
- let text = data.text || this.renderChildren(context, instance);
83
- let { CSS, baseClass } = this;
84
- return this.renderWrap(context, instance, key, [
85
- this.native ? this.renderNativeCheck(context, instance) : this.renderCheck(context, instance),
86
- text ? (
87
- <div key="text" className={CSS.element(baseClass, "text")}>
88
- {text}
89
- </div>
90
- ) : (
91
- <span key="baseline" className={CSS.element(baseClass, "baseline")}>
92
- &nbsp;
93
- </span>
94
- ),
95
- ]);
96
- }
97
-
98
- renderValue(context, { data }) {
99
- if (!data.viewText) return super.renderValue(...arguments);
100
- return <span className={this.CSS.element(this.baseClass, "view-text")}>{data.viewText}</span>;
101
- }
102
-
103
- formatValue(context, instance) {
104
- let { data } = instance;
105
- return data.value && (data.text || this.renderChildren(context, instance));
106
- }
107
-
108
- handleClick(e, instance) {
109
- if (this.native) e.stopPropagation();
110
- else {
111
- var el = document.getElementById(instance.data.id);
112
- if (el) el.focus();
113
- if (!instance.data.viewMode) {
114
- e.preventDefault();
115
- e.stopPropagation();
116
- this.handleChange(e, instance, !instance.data.value);
117
- }
118
- }
119
- }
120
-
121
- handleChange(e, instance, checked) {
122
- let { data } = instance;
123
-
124
- if (data.readOnly || data.disabled || data.viewMode) return;
125
-
126
- instance.set("value", checked != null ? checked : e.target.checked);
127
- }
128
- }
129
-
130
- Checkbox.prototype.baseClass = "checkbox";
131
- Checkbox.prototype.native = false;
132
- Checkbox.prototype.indeterminate = false;
133
- Checkbox.prototype.unfocusable = false;
134
-
135
- Widget.alias("checkbox", Checkbox);
136
-
137
- class CheckboxCmp extends VDOM.Component {
138
- constructor(props) {
139
- super(props);
140
- this.state = {
141
- value: props.data.value,
142
- };
143
- }
144
-
145
- UNSAFE_componentWillReceiveProps(props) {
146
- this.setState({
147
- value: props.data.value,
148
- });
149
- }
150
-
151
- render() {
152
- let { instance, data } = this.props;
153
- let { widget } = instance;
154
- let { baseClass, CSS } = widget;
155
-
156
- let check = false;
157
-
158
- if (this.state.value == null && widget.indeterminate) check = "indeterminate";
159
- else if (this.state.value) check = "check";
160
-
161
- return (
162
- <span
163
- key="check"
164
- tabIndex={widget.unfocusable || data.disabled ? null : data.tabIndex || 0}
165
- className={CSS.element(baseClass, "input", {
166
- checked: check,
167
- })}
168
- style={CSS.parseStyle(data.inputStyle)}
169
- id={data.id}
170
- onClick={this.onClick.bind(this)}
171
- onKeyDown={this.onKeyDown.bind(this)}
172
- >
173
- {check == "check" && <CheckIcon className={CSS.element(baseClass, "input-check")} />}
174
- {check == "indeterminate" && <SquareIcon className={CSS.element(baseClass, "input-check")} />}
175
- </span>
176
- );
177
- }
178
-
179
- onClick(e) {
180
- let { instance, data } = this.props;
181
- let { widget } = instance;
182
- if (!data.disabled && !data.readOnly) {
183
- e.stopPropagation();
184
- e.preventDefault();
185
- this.setState({ value: !this.state.value });
186
- widget.handleChange(e, instance, !this.state.value);
187
- }
188
- }
189
-
190
- onKeyDown(e) {
191
- let { instance } = this.props;
192
- if (instance.widget.handleKeyDown(e, instance) === false) return;
193
-
194
- switch (e.keyCode) {
195
- case KeyCode.space:
196
- this.onClick(e);
197
- break;
198
- }
199
- }
200
- }
1
+ import { Widget, VDOM, getContent } from "../../ui/Widget";
2
+ import { Field, getFieldTooltip } from "./Field";
3
+ import { tooltipMouseMove, tooltipMouseLeave } from "../overlay/tooltip-ops";
4
+ import { stopPropagation } from "../../util/eventCallbacks";
5
+ import { KeyCode } from "../../util/KeyCode";
6
+ import CheckIcon from "../icons/check";
7
+ import SquareIcon from "../icons/square";
8
+
9
+ export class Checkbox extends Field {
10
+ init() {
11
+ if (this.checked) this.value = this.checked;
12
+
13
+ super.init();
14
+ }
15
+
16
+ declareData() {
17
+ super.declareData(
18
+ {
19
+ value: !this.indeterminate ? false : undefined,
20
+ text: undefined,
21
+ readOnly: undefined,
22
+ disabled: undefined,
23
+ enabled: undefined,
24
+ required: undefined,
25
+ viewText: undefined,
26
+ },
27
+ ...arguments,
28
+ );
29
+ }
30
+
31
+ renderWrap(context, instance, key, content) {
32
+ let { data } = instance;
33
+ return (
34
+ <label
35
+ key={key}
36
+ className={data.classNames}
37
+ onMouseDown={(e) => {
38
+ e.stopPropagation();
39
+ if (this.unfocusable) e.preventDefault();
40
+ }}
41
+ onMouseMove={(e) => tooltipMouseMove(e, ...getFieldTooltip(instance))}
42
+ onMouseLeave={(e) => tooltipMouseLeave(e, ...getFieldTooltip(instance))}
43
+ onClick={(e) => {
44
+ this.handleClick(e, instance);
45
+ }}
46
+ style={data.style}
47
+ >
48
+ {content}
49
+ {this.labelPlacement && getContent(this.renderLabel(context, instance, "label"))}
50
+ </label>
51
+ );
52
+ }
53
+
54
+ validateRequired(context, instance) {
55
+ let { data } = instance;
56
+ if (!data.value) return this.requiredText;
57
+ }
58
+
59
+ renderNativeCheck(context, instance) {
60
+ let { CSS, baseClass } = this;
61
+ let { data } = instance;
62
+ return (
63
+ <input
64
+ key="input"
65
+ className={CSS.element(baseClass, "checkbox")}
66
+ id={data.id}
67
+ type="checkbox"
68
+ checked={data.value || false}
69
+ disabled={data.disabled}
70
+ {...data.inputAttrs}
71
+ onClick={stopPropagation}
72
+ onChange={(e) => {
73
+ this.handleChange(e, instance);
74
+ }}
75
+ />
76
+ );
77
+ }
78
+
79
+ renderCheck(context, instance) {
80
+ return <CheckboxCmp key="check" instance={instance} data={instance.data} />;
81
+ }
82
+
83
+ renderInput(context, instance, key) {
84
+ let { data } = instance;
85
+ let text = data.text || this.renderChildren(context, instance);
86
+ let { CSS, baseClass } = this;
87
+ return this.renderWrap(context, instance, key, [
88
+ this.native ? this.renderNativeCheck(context, instance) : this.renderCheck(context, instance),
89
+ text ? (
90
+ <div key="text" className={CSS.element(baseClass, "text")}>
91
+ {text}
92
+ </div>
93
+ ) : (
94
+ <span key="baseline" className={CSS.element(baseClass, "baseline")}>
95
+ &nbsp;
96
+ </span>
97
+ ),
98
+ ]);
99
+ }
100
+
101
+ renderValue(context, { data }) {
102
+ if (!data.viewText) return super.renderValue(...arguments);
103
+ return <span className={this.CSS.element(this.baseClass, "view-text")}>{data.viewText}</span>;
104
+ }
105
+
106
+ formatValue(context, instance) {
107
+ let { data } = instance;
108
+ return data.value && (data.text || this.renderChildren(context, instance));
109
+ }
110
+
111
+ handleClick(e, instance) {
112
+ if (this.native) e.stopPropagation();
113
+ else {
114
+ var el = document.getElementById(instance.data.id);
115
+ if (el) el.focus();
116
+ if (!instance.data.viewMode) {
117
+ e.preventDefault();
118
+ e.stopPropagation();
119
+ this.handleChange(e, instance, !instance.data.value);
120
+ }
121
+ }
122
+ }
123
+
124
+ handleChange(e, instance, checked) {
125
+ let { data } = instance;
126
+
127
+ if (data.readOnly || data.disabled || data.viewMode) return;
128
+
129
+ instance.set("value", checked != null ? checked : e.target.checked);
130
+ }
131
+ }
132
+
133
+ Checkbox.prototype.baseClass = "checkbox";
134
+ Checkbox.prototype.native = false;
135
+ Checkbox.prototype.indeterminate = false;
136
+ Checkbox.prototype.unfocusable = false;
137
+
138
+ Widget.alias("checkbox", Checkbox);
139
+
140
+ class CheckboxCmp extends VDOM.Component {
141
+ constructor(props) {
142
+ super(props);
143
+ this.state = {
144
+ value: props.data.value,
145
+ };
146
+ }
147
+
148
+ UNSAFE_componentWillReceiveProps(props) {
149
+ this.setState({
150
+ value: props.data.value,
151
+ });
152
+ }
153
+
154
+ render() {
155
+ let { instance, data } = this.props;
156
+ let { widget } = instance;
157
+ let { baseClass, CSS } = widget;
158
+
159
+ let check = false;
160
+
161
+ if (this.state.value == null && widget.indeterminate) check = "indeterminate";
162
+ else if (this.state.value) check = "check";
163
+
164
+ return (
165
+ <span
166
+ key="check"
167
+ tabIndex={widget.unfocusable || data.disabled ? null : data.tabIndex || 0}
168
+ className={CSS.element(baseClass, "input", {
169
+ checked: check,
170
+ })}
171
+ style={CSS.parseStyle(data.inputStyle)}
172
+ id={data.id}
173
+ onClick={this.onClick.bind(this)}
174
+ onKeyDown={this.onKeyDown.bind(this)}
175
+ >
176
+ {check == "check" && <CheckIcon className={CSS.element(baseClass, "input-check")} />}
177
+ {check == "indeterminate" && <SquareIcon className={CSS.element(baseClass, "input-check")} />}
178
+ </span>
179
+ );
180
+ }
181
+
182
+ onClick(e) {
183
+ let { instance, data } = this.props;
184
+ let { widget } = instance;
185
+ if (!data.disabled && !data.readOnly) {
186
+ e.stopPropagation();
187
+ e.preventDefault();
188
+ this.setState({ value: !this.state.value });
189
+ widget.handleChange(e, instance, !this.state.value);
190
+ }
191
+ }
192
+
193
+ onKeyDown(e) {
194
+ let { instance } = this.props;
195
+ if (instance.widget.handleKeyDown(e, instance) === false) return;
196
+
197
+ switch (e.keyCode) {
198
+ case KeyCode.space:
199
+ this.onClick(e);
200
+ break;
201
+ }
202
+ }
203
+ }
@@ -112,6 +112,13 @@ export class Grid extends Container {
112
112
  };
113
113
  }
114
114
 
115
+ applyParentStore(instance) {
116
+ super.applyParentStore(instance);
117
+
118
+ // force prepareData to execute again and propagate the store change to the records
119
+ if (instance.cached) delete instance.cached.rawData;
120
+ }
121
+
115
122
  createRowTemplate(context, columnParams, instance, groupingData) {
116
123
  var row = this.row || {};
117
124
  let columns = this.columns;
@@ -1,102 +1,102 @@
1
- import { Widget } from "../../ui/Widget";
2
- import { PureContainer } from "../../ui/PureContainer";
3
- import RouteMatcher from "route-parser";
4
- import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
5
- import { routeAppend } from "../../util/routeAppend";
6
-
7
- export class Route extends PureContainer {
8
- init() {
9
- if (this.path) this.route = this.path;
10
-
11
- super.init();
12
-
13
- if (this.route && this.route[0] !== "+")
14
- this.matcher = new RouteMatcher(this.route + (this.prefix ? "(*remainder)" : ""));
15
- }
16
-
17
- initInstance(context, instance) {
18
- instance.store = new ReadOnlyDataView({
19
- store: instance.parentStore,
20
- });
21
- super.initInstance(context, instance);
22
- }
23
-
24
- applyParentStore(instance) {
25
- instance.store.setStore(instance.parentStore);
26
- }
27
-
28
- declareData() {
29
- super.declareData(...arguments, {
30
- url: undefined,
31
- });
32
- }
33
-
34
- checkVisible(context, instance, data) {
35
- if (!data.visible) return false;
36
-
37
- if (data.url !== instance.cached.url) {
38
- instance.cached.url = data.url;
39
- let matcher = this.matcher;
40
- let route = this.route;
41
- if (this.route[0] === "+") {
42
- route = routeAppend(context.lastRoute.route, this.route.substring(1));
43
- if (!instance.cached.matcher || instance.cached.route !== route)
44
- instance.cached.matcher = new RouteMatcher(route + (this.prefix ? "(*remainder)" : ""));
45
- matcher = instance.cached.matcher;
46
- }
47
- instance.cached.result = matcher.match(data.url);
48
- instance.cached.matcher = matcher;
49
- instance.cached.route = data.route = route;
50
- }
51
- if (!instance.cached.result) return false;
52
-
53
- return super.checkVisible(context, instance, data);
54
- }
55
-
56
- prepareData(context, { data, store, cached }) {
57
- super.prepareData(...arguments);
58
-
59
- store.setData({
60
- [this.recordName]: cached.result,
61
- });
62
-
63
- //TODO: Replace comparison with deepEquals
64
- if (this.params && this.params.bind) {
65
- var params = store.get(this.params.bind);
66
- if (JSON.stringify(params) != JSON.stringify(cached.result)) {
67
- store.set(this.params.bind, cached.result);
68
- }
69
- }
70
-
71
- if (this.map) {
72
- for (var key in result) {
73
- var binding = this.map[key];
74
- if (binding) store.set(binding, result[key]);
75
- }
76
- }
77
- }
78
-
79
- explore(context, instance) {
80
- context.push("lastRoute", {
81
- route: instance.cached.route,
82
- result: instance.cached.result,
83
- reverse: function (data) {
84
- return instance.cached.matcher.reverse({
85
- ...instance.cached.result,
86
- remainder: "",
87
- ...data,
88
- });
89
- },
90
- });
91
- super.explore(context, instance);
92
- }
93
-
94
- exploreCleanup(context, instance) {
95
- context.pop("lastRoute");
96
- }
97
- }
98
-
99
- Route.prototype.recordName = "$route";
100
- Route.prototype.prefix = false;
101
-
102
- Widget.alias("route", Route);
1
+ import { Widget } from "../../ui/Widget";
2
+ import { PureContainer } from "../../ui/PureContainer";
3
+ import RouteMatcher from "route-parser";
4
+ import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
5
+ import { routeAppend } from "../../util/routeAppend";
6
+
7
+ export class Route extends PureContainer {
8
+ init() {
9
+ if (this.path) this.route = this.path;
10
+
11
+ super.init();
12
+
13
+ if (this.route && this.route[0] !== "+")
14
+ this.matcher = new RouteMatcher(this.route + (this.prefix ? "(*remainder)" : ""));
15
+ }
16
+
17
+ initInstance(context, instance) {
18
+ instance.store = new ReadOnlyDataView({
19
+ store: instance.parentStore,
20
+ });
21
+ super.initInstance(context, instance);
22
+ }
23
+
24
+ applyParentStore(instance) {
25
+ instance.store.setStore(instance.parentStore);
26
+ }
27
+
28
+ declareData() {
29
+ super.declareData(...arguments, {
30
+ url: undefined,
31
+ });
32
+ }
33
+
34
+ checkVisible(context, instance, data) {
35
+ if (!data.visible) return false;
36
+
37
+ if (data.url !== instance.cached.url) {
38
+ instance.cached.url = data.url;
39
+ let matcher = this.matcher;
40
+ let route = this.route;
41
+ if (this.route[0] === "+") {
42
+ route = routeAppend(context.lastRoute.route, this.route.substring(1));
43
+ if (!instance.cached.matcher || instance.cached.route !== route)
44
+ instance.cached.matcher = new RouteMatcher(route + (this.prefix ? "(*remainder)" : ""));
45
+ matcher = instance.cached.matcher;
46
+ }
47
+ instance.cached.result = matcher.match(data.url);
48
+ instance.cached.matcher = matcher;
49
+ instance.cached.route = data.route = route;
50
+ }
51
+ if (!instance.cached.result) return false;
52
+
53
+ return super.checkVisible(context, instance, data);
54
+ }
55
+
56
+ prepareData(context, { data, store, cached }) {
57
+ super.prepareData(...arguments);
58
+
59
+ store.setData({
60
+ [this.recordName]: cached.result,
61
+ });
62
+
63
+ //TODO: Replace comparison with deepEquals
64
+ if (this.params && this.params.bind) {
65
+ var params = store.get(this.params.bind);
66
+ if (JSON.stringify(params) != JSON.stringify(cached.result)) {
67
+ store.set(this.params.bind, cached.result);
68
+ }
69
+ }
70
+
71
+ if (this.map) {
72
+ for (var key in result) {
73
+ var binding = this.map[key];
74
+ if (binding) store.set(binding, result[key]);
75
+ }
76
+ }
77
+ }
78
+
79
+ explore(context, instance) {
80
+ context.push("lastRoute", {
81
+ route: instance.cached.route,
82
+ result: instance.cached.result,
83
+ reverse: function (data) {
84
+ return instance.cached.matcher.reverse({
85
+ ...instance.cached.result,
86
+ remainder: "",
87
+ ...data,
88
+ });
89
+ },
90
+ });
91
+ super.explore(context, instance);
92
+ }
93
+
94
+ exploreCleanup(context, instance) {
95
+ context.pop("lastRoute");
96
+ }
97
+ }
98
+
99
+ Route.prototype.recordName = "$route";
100
+ Route.prototype.prefix = false;
101
+
102
+ Widget.alias("route", Route);