cx 25.5.1 → 25.6.0
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/dist/charts.js +40 -21
- package/dist/manifest.js +771 -771
- package/dist/ui.js +0 -15
- package/dist/widgets.js +34 -25
- package/package.json +1 -1
- package/src/charts/LineGraph.js +1 -1
- package/src/charts/axis/NumericAxis.d.ts +46 -46
- package/src/charts/helpers/PointReducer.d.ts +9 -0
- package/src/charts/helpers/PointReducer.js +36 -22
- package/src/data/AugmentedViewBase.js +77 -77
- package/src/data/ExposedRecordView.js +75 -75
- package/src/data/ExposedValueView.js +73 -73
- package/src/data/Ref.d.ts +24 -24
- package/src/data/Ref.spec.js +79 -79
- package/src/data/StoreRef.spec.js +24 -24
- package/src/data/StructuredDataAccessor.d.ts +7 -7
- package/src/data/SubscribableView.js +54 -54
- package/src/ui/Container.js +154 -154
- package/src/ui/DataProxy.js +31 -45
- package/src/ui/DetachedScope.js +98 -98
- package/src/ui/Instance.d.ts +72 -72
- package/src/ui/Instance.js +623 -623
- package/src/ui/IsolatedScope.js +30 -30
- package/src/ui/Repeater.js +109 -109
- package/src/ui/Rescope.js +35 -35
- package/src/ui/Restate.js +167 -167
- package/src/ui/Widget.js +184 -184
- package/src/ui/adapter/ArrayAdapter.js +152 -152
- package/src/ui/adapter/TreeAdapter.js +101 -101
- package/src/ui/createFunctionalComponent.d.ts +1 -1
- package/src/ui/index.d.ts +42 -42
- package/src/ui/layout/exploreChildren.d.ts +12 -12
- package/src/ui/layout/exploreChildren.js +27 -27
- package/src/util/debounce.js +18 -18
- package/src/util/validatedDebounce.js +19 -19
- package/src/widgets/Button.js +118 -118
- package/src/widgets/List.js +594 -594
- package/src/widgets/form/Calendar.d.ts +86 -86
- package/src/widgets/form/Checkbox.js +5 -2
- package/src/widgets/form/MonthField.d.ts +5 -0
- package/src/widgets/form/MonthField.js +1 -0
- package/src/widgets/form/MonthPicker.d.ts +13 -0
- package/src/widgets/form/MonthPicker.js +25 -21
- package/src/widgets/grid/Grid.js +3421 -3421
- package/src/widgets/nav/Route.js +102 -102
package/src/widgets/List.js
CHANGED
|
@@ -1,594 +1,594 @@
|
|
|
1
|
-
import { Widget, VDOM, getContent } from "../ui/Widget";
|
|
2
|
-
import { PureContainer } from "../ui/PureContainer";
|
|
3
|
-
import { GroupAdapter } from "../ui/adapter/GroupAdapter";
|
|
4
|
-
import { Binding, isBinding } from "../data/Binding";
|
|
5
|
-
import { Selection } from "../ui/selection/Selection";
|
|
6
|
-
import { KeyCode } from "../util/KeyCode";
|
|
7
|
-
import { scrollElementIntoView } from "../util/scrollElementIntoView";
|
|
8
|
-
import { FocusManager, oneFocusOut, offFocusOut, preventFocusOnTouch } from "../ui/FocusManager";
|
|
9
|
-
import { isString } from "../util/isString";
|
|
10
|
-
import { isArray } from "../util/isArray";
|
|
11
|
-
import { getAccessor } from "../data/getAccessor";
|
|
12
|
-
import { batchUpdates } from "../ui/batchUpdates";
|
|
13
|
-
import { Container } from "../ui/Container";
|
|
14
|
-
import { addEventListenerWithOptions } from "../util/addEventListenerWithOptions";
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
- renders list of items
|
|
18
|
-
- focusable (keyboard navigation)
|
|
19
|
-
- selection
|
|
20
|
-
- fake focus - list appears focused and receives keyboard inputs redirected from other control (dropdown scenario)
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export class List extends Widget {
|
|
24
|
-
init() {
|
|
25
|
-
if (this.recordAlias) this.recordName = this.recordAlias;
|
|
26
|
-
|
|
27
|
-
if (this.indexAlias) this.indexName = this.indexAlias;
|
|
28
|
-
|
|
29
|
-
this.adapter = GroupAdapter.create(this.adapter || GroupAdapter, {
|
|
30
|
-
recordName: this.recordName,
|
|
31
|
-
indexName: this.indexName,
|
|
32
|
-
recordsAccessor: getAccessor(this.records),
|
|
33
|
-
keyField: this.keyField,
|
|
34
|
-
sortOptions: this.sortOptions,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
this.child = ListItem.create({
|
|
38
|
-
layout: this.layout,
|
|
39
|
-
items: this.items,
|
|
40
|
-
children: this.children,
|
|
41
|
-
styled: true,
|
|
42
|
-
class: this.itemClass,
|
|
43
|
-
className: this.itemClassName,
|
|
44
|
-
style: this.itemStyle,
|
|
45
|
-
disabled: this.itemDisabled,
|
|
46
|
-
...this.item,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
delete this.children;
|
|
50
|
-
|
|
51
|
-
this.selection = Selection.create(this.selection, {
|
|
52
|
-
records: this.records,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
super.init();
|
|
56
|
-
|
|
57
|
-
if (this.grouping) {
|
|
58
|
-
this.groupBy(this.grouping);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
initInstance(context, instance) {
|
|
63
|
-
this.adapter.initInstance(context, instance);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
declareData() {
|
|
67
|
-
let selection = this.selection.configureWidget(this);
|
|
68
|
-
|
|
69
|
-
super.declareData(
|
|
70
|
-
selection,
|
|
71
|
-
{
|
|
72
|
-
records: undefined,
|
|
73
|
-
sorters: undefined,
|
|
74
|
-
sortField: undefined,
|
|
75
|
-
sortDirection: undefined,
|
|
76
|
-
filterParams: {
|
|
77
|
-
structured: true,
|
|
78
|
-
},
|
|
79
|
-
itemStyle: {
|
|
80
|
-
structured: true,
|
|
81
|
-
},
|
|
82
|
-
emptyText: undefined,
|
|
83
|
-
tabIndex: undefined,
|
|
84
|
-
},
|
|
85
|
-
...arguments,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
prepareData(context, instance) {
|
|
90
|
-
let { data } = instance;
|
|
91
|
-
|
|
92
|
-
if (data.sortField)
|
|
93
|
-
data.sorters = [
|
|
94
|
-
{
|
|
95
|
-
field: data.sortField,
|
|
96
|
-
direction: data.sortDirection || "ASC",
|
|
97
|
-
},
|
|
98
|
-
];
|
|
99
|
-
this.adapter.sort(data.sorters);
|
|
100
|
-
|
|
101
|
-
let filter = null;
|
|
102
|
-
if (this.onCreateFilter) filter = instance.invoke("onCreateFilter", data.filterParams, instance);
|
|
103
|
-
else if (this.filter) filter = (item) => this.filter(item, data.filterParams);
|
|
104
|
-
this.adapter.setFilter(filter);
|
|
105
|
-
instance.mappedRecords = this.adapter.getRecords(context, instance, data.records, instance.store);
|
|
106
|
-
|
|
107
|
-
data.stateMods = Object.assign(data.stateMods || {}, {
|
|
108
|
-
selectable: !this.selection.isDummy || this.onItemClick,
|
|
109
|
-
empty: instance.mappedRecords.length == 0,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
super.prepareData(context, instance);
|
|
113
|
-
}
|
|
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
|
-
|
|
122
|
-
explore(context, instance, data) {
|
|
123
|
-
let instances = [];
|
|
124
|
-
let isSelected = this.selection.getIsSelectedDelegate(instance.store);
|
|
125
|
-
instance.mappedRecords.forEach((record) => {
|
|
126
|
-
if (record.type == "data") {
|
|
127
|
-
let itemInstance = instance.getChild(context, this.child, record.key, record.store);
|
|
128
|
-
itemInstance.record = record;
|
|
129
|
-
itemInstance.selected = isSelected(record.data, record.index);
|
|
130
|
-
|
|
131
|
-
let changed = false;
|
|
132
|
-
if (itemInstance.cache("recordData", record.data)) changed = true;
|
|
133
|
-
if (itemInstance.cache("selected", itemInstance.selected)) changed = true;
|
|
134
|
-
|
|
135
|
-
if (this.cached && !changed && itemInstance.visible && !itemInstance.childStateDirty) {
|
|
136
|
-
instances.push(itemInstance);
|
|
137
|
-
itemInstance.shouldUpdate = false;
|
|
138
|
-
} else if (itemInstance.scheduleExploreIfVisible(context)) instances.push(itemInstance);
|
|
139
|
-
} else if (record.type == "group-header" && record.grouping.header) {
|
|
140
|
-
let itemInstance = instance.getChild(context, record.grouping.header, record.key, record.store);
|
|
141
|
-
itemInstance.record = record;
|
|
142
|
-
if (itemInstance.scheduleExploreIfVisible(context)) instances.push(itemInstance);
|
|
143
|
-
} else if (record.type == "group-footer" && record.grouping.footer) {
|
|
144
|
-
let itemInstance = instance.getChild(context, record.grouping.footer, record.key, record.store);
|
|
145
|
-
itemInstance.record = record;
|
|
146
|
-
if (itemInstance.scheduleExploreIfVisible(context)) instances.push(itemInstance);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
instance.instances = instances;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
render(context, instance, key) {
|
|
153
|
-
let items = instance.instances.map((x, i) => ({
|
|
154
|
-
instance: x,
|
|
155
|
-
key: x.record.key,
|
|
156
|
-
type: x.record.type,
|
|
157
|
-
content: getContent(x.render(context)),
|
|
158
|
-
}));
|
|
159
|
-
return (
|
|
160
|
-
<ListComponent
|
|
161
|
-
key={key}
|
|
162
|
-
instance={instance}
|
|
163
|
-
items={items}
|
|
164
|
-
selectable={!this.selection.isDummy || this.onItemClick}
|
|
165
|
-
/>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
groupBy(grouping) {
|
|
170
|
-
if (!isArray(grouping)) {
|
|
171
|
-
if (isString(grouping) || typeof grouping == "object") return this.groupBy([grouping]);
|
|
172
|
-
throw new Error("DynamicGrouping should be an array of grouping objects");
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
grouping = grouping.map((g, i) => {
|
|
176
|
-
if (isString(g)) {
|
|
177
|
-
return {
|
|
178
|
-
key: {
|
|
179
|
-
[g]: {
|
|
180
|
-
bind: this.recordName + "." + g,
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return g;
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
grouping.forEach((g) => {
|
|
189
|
-
if (g.header) g.header = Widget.create(g.header);
|
|
190
|
-
|
|
191
|
-
if (g.footer) g.footer = Widget.create(g.footer);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
this.adapter.groupBy(grouping);
|
|
195
|
-
this.update();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
List.prototype.recordName = "$record";
|
|
200
|
-
List.prototype.indexName = "$index";
|
|
201
|
-
List.prototype.baseClass = "list";
|
|
202
|
-
List.prototype.focusable = true;
|
|
203
|
-
List.prototype.focused = false;
|
|
204
|
-
List.prototype.itemPad = true;
|
|
205
|
-
List.prototype.cached = false;
|
|
206
|
-
List.prototype.styled = true;
|
|
207
|
-
List.prototype.scrollSelectionIntoView = false;
|
|
208
|
-
List.prototype.selectMode = false;
|
|
209
|
-
List.prototype.selectOnTab = false;
|
|
210
|
-
|
|
211
|
-
Widget.alias("list", List);
|
|
212
|
-
|
|
213
|
-
class ListComponent extends VDOM.Component {
|
|
214
|
-
constructor(props) {
|
|
215
|
-
super(props);
|
|
216
|
-
let { widget } = props.instance;
|
|
217
|
-
let { focused } = widget;
|
|
218
|
-
this.state = {
|
|
219
|
-
cursor: focused && props.selectable ? 0 : -1,
|
|
220
|
-
focused: focused,
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
this.handleItemMouseDown = this.handleItemMouseDown.bind(this);
|
|
224
|
-
this.handleItemDoubleClick = this.handleItemDoubleClick.bind(this);
|
|
225
|
-
this.handleItemClick = this.handleItemClick.bind(this);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
shouldComponentUpdate(props, state) {
|
|
229
|
-
return props.instance.shouldUpdate || state != this.state;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
componentDidMount() {
|
|
233
|
-
let { instance } = this.props;
|
|
234
|
-
let { widget } = instance;
|
|
235
|
-
if (widget.pipeKeyDown) {
|
|
236
|
-
instance.invoke("pipeKeyDown", this.handleKeyDown.bind(this), instance);
|
|
237
|
-
this.showCursor();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (widget.autoFocus) FocusManager.focus(this.el);
|
|
241
|
-
|
|
242
|
-
if (widget.onScroll) {
|
|
243
|
-
this.unsubscribeScroll = addEventListenerWithOptions(
|
|
244
|
-
this.el,
|
|
245
|
-
"scroll",
|
|
246
|
-
(event) => {
|
|
247
|
-
instance.invoke("onScroll", event, instance);
|
|
248
|
-
},
|
|
249
|
-
{ passive: true },
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
this.componentDidUpdate();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
UNSAFE_componentWillReceiveProps(props) {
|
|
257
|
-
if (this.state.focused && props.instance.widget.selectMode) this.showCursor(true, props.items);
|
|
258
|
-
else if (this.state.cursor >= props.items.length) this.moveCursor(props.items.length - 1);
|
|
259
|
-
else if (this.state.focused && this.state.cursor < 0) this.moveCursor(0);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
componentWillUnmount() {
|
|
263
|
-
let { instance } = this.props;
|
|
264
|
-
let { widget } = instance;
|
|
265
|
-
offFocusOut(this);
|
|
266
|
-
if (widget.pipeKeyDown) instance.invoke("pipeKeyDown", null, instance);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
handleItemMouseDown(e) {
|
|
270
|
-
let index = Number(e.currentTarget.dataset.recordIndex);
|
|
271
|
-
this.moveCursor(index);
|
|
272
|
-
if (e.shiftKey) e.preventDefault();
|
|
273
|
-
|
|
274
|
-
this.moveCursor(index, {
|
|
275
|
-
select: true,
|
|
276
|
-
selectOptions: {
|
|
277
|
-
toggle: e.ctrlKey && !e.shiftKey,
|
|
278
|
-
add: e.ctrlKey && e.shiftKey,
|
|
279
|
-
},
|
|
280
|
-
selectRange: e.shiftKey,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
handleItemClick(e) {
|
|
285
|
-
let { instance, items } = this.props;
|
|
286
|
-
let index = Number(e.currentTarget.dataset.recordIndex);
|
|
287
|
-
let item = items[this.cursorChildIndex[index]];
|
|
288
|
-
if (instance.invoke("onItemClick", e, item.instance) === false) return;
|
|
289
|
-
|
|
290
|
-
this.moveCursor(index, {
|
|
291
|
-
select: true,
|
|
292
|
-
selectOptions: {
|
|
293
|
-
toggle: e.ctrlKey && !e.shiftKey,
|
|
294
|
-
add: e.ctrlKey && e.shiftKey,
|
|
295
|
-
},
|
|
296
|
-
selectRange: e.shiftKey,
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
handleItemDoubleClick(e) {
|
|
301
|
-
let { instance, items } = this.props;
|
|
302
|
-
let index = Number(e.currentTarget.dataset.recordIndex);
|
|
303
|
-
let item = items[this.cursorChildIndex[index]];
|
|
304
|
-
instance.invoke("onItemDoubleClick", e, item.instance);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
render() {
|
|
308
|
-
let { instance, items, selectable } = this.props;
|
|
309
|
-
let { data, widget } = instance;
|
|
310
|
-
let { CSS, baseClass } = widget;
|
|
311
|
-
let itemStyle = CSS.parseStyle(data.itemStyle);
|
|
312
|
-
this.cursorChildIndex = [];
|
|
313
|
-
let cursorIndex = 0;
|
|
314
|
-
|
|
315
|
-
let onDblClick, onClick;
|
|
316
|
-
|
|
317
|
-
if (widget.onItemClick) onClick = this.handleItemClick;
|
|
318
|
-
|
|
319
|
-
if (widget.onItemDoubleClick) onDblClick = this.handleItemDoubleClick;
|
|
320
|
-
|
|
321
|
-
let children =
|
|
322
|
-
items.length > 0 &&
|
|
323
|
-
items.map((x, i) => {
|
|
324
|
-
let { data, selected } = x.instance;
|
|
325
|
-
let className;
|
|
326
|
-
|
|
327
|
-
if (x.type == "data") {
|
|
328
|
-
let ind = cursorIndex++;
|
|
329
|
-
|
|
330
|
-
this.cursorChildIndex.push(i);
|
|
331
|
-
className = CSS.element(baseClass, "item", {
|
|
332
|
-
selected: selected,
|
|
333
|
-
cursor: ind == this.state.cursor,
|
|
334
|
-
pad: widget.itemPad,
|
|
335
|
-
disabled: data.disabled,
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
return (
|
|
339
|
-
<li
|
|
340
|
-
key={x.key}
|
|
341
|
-
className={CSS.expand(className, data.classNames)}
|
|
342
|
-
style={itemStyle}
|
|
343
|
-
data-record-index={ind}
|
|
344
|
-
onMouseDown={this.handleItemMouseDown}
|
|
345
|
-
onClick={onClick}
|
|
346
|
-
onDoubleClick={onDblClick}
|
|
347
|
-
>
|
|
348
|
-
{x.content}
|
|
349
|
-
</li>
|
|
350
|
-
);
|
|
351
|
-
} else {
|
|
352
|
-
return (
|
|
353
|
-
<li key={x.key} className={CSS.element(baseClass, x.type)}>
|
|
354
|
-
{x.content}
|
|
355
|
-
</li>
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
if (!children && data.emptyText) {
|
|
361
|
-
children = <li className={CSS.element(baseClass, "empty-text")}>{data.emptyText}</li>;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return (
|
|
365
|
-
<ul
|
|
366
|
-
ref={(el) => {
|
|
367
|
-
this.el = el;
|
|
368
|
-
}}
|
|
369
|
-
className={CSS.expand(data.classNames, CSS.state({ focused: this.state.focused }))}
|
|
370
|
-
style={data.style}
|
|
371
|
-
tabIndex={widget.focusable && selectable && items.length > 0 ? data.tabIndex || 0 : null}
|
|
372
|
-
onMouseDown={preventFocusOnTouch}
|
|
373
|
-
onKeyDown={this.handleKeyDown.bind(this)}
|
|
374
|
-
onMouseLeave={this.handleMouseLeave.bind(this)}
|
|
375
|
-
onFocus={this.onFocus.bind(this)}
|
|
376
|
-
onBlur={this.onBlur.bind(this)}
|
|
377
|
-
>
|
|
378
|
-
{children}
|
|
379
|
-
</ul>
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
componentDidUpdate() {
|
|
384
|
-
let { widget } = this.props.instance;
|
|
385
|
-
if (widget.scrollSelectionIntoView) {
|
|
386
|
-
//The timeout is reqired for use-cases when parent needs to do some measuring that affect scrollbars, i.e. LookupField.
|
|
387
|
-
setTimeout(() => this.scrollElementIntoView(), 0);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
scrollElementIntoView() {
|
|
392
|
-
if (!this.el) return; //unmount
|
|
393
|
-
let { widget } = this.props.instance;
|
|
394
|
-
let { CSS, baseClass } = widget;
|
|
395
|
-
let selectedRowSelector = `.${CSS.element(baseClass, "item")}.${CSS.state("selected")}`;
|
|
396
|
-
let firstSelectedRow = this.el.querySelector(selectedRowSelector);
|
|
397
|
-
if (firstSelectedRow != this.selectedEl) {
|
|
398
|
-
if (firstSelectedRow) scrollElementIntoView(firstSelectedRow, true, false, 0, this.el);
|
|
399
|
-
this.selectedEl = firstSelectedRow;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
moveCursor(index, { focused, hover, scrollIntoView, select, selectRange, selectOptions } = {}) {
|
|
404
|
-
let { instance, selectable } = this.props;
|
|
405
|
-
if (!selectable) return;
|
|
406
|
-
|
|
407
|
-
let { widget } = instance;
|
|
408
|
-
let newState = {};
|
|
409
|
-
if (widget.focused) focused = true;
|
|
410
|
-
|
|
411
|
-
if (focused != null && this.state.focused != focused) newState.focused = focused;
|
|
412
|
-
|
|
413
|
-
//ignore mouse enter/leave events (support with a flag if a feature request comes)
|
|
414
|
-
if (!hover) newState.cursor = index;
|
|
415
|
-
|
|
416
|
-
//batch updates to avoid flickering between selection and cursor changes
|
|
417
|
-
batchUpdates(() => {
|
|
418
|
-
if (select || widget.selectMode) {
|
|
419
|
-
let start = selectRange && this.state.selectionStart >= 0 ? this.state.selectionStart : index;
|
|
420
|
-
if (start < 0) start = index;
|
|
421
|
-
this.selectRange(start, index, selectOptions);
|
|
422
|
-
if (!selectRange) newState.selectionStart = index;
|
|
423
|
-
}
|
|
424
|
-
if (Object.keys(newState).length > 0) {
|
|
425
|
-
this.setState(newState, () => {
|
|
426
|
-
if (scrollIntoView) {
|
|
427
|
-
let item = this.el.children[this.cursorChildIndex[index]];
|
|
428
|
-
if (item) scrollElementIntoView(item);
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
selectRange(from, to, options) {
|
|
436
|
-
let { instance, items } = this.props;
|
|
437
|
-
let { widget } = instance;
|
|
438
|
-
|
|
439
|
-
if (from > to) {
|
|
440
|
-
let tmp = from;
|
|
441
|
-
from = to;
|
|
442
|
-
to = tmp;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
let selection = [],
|
|
446
|
-
indexes = [];
|
|
447
|
-
|
|
448
|
-
for (let cursor = from; cursor <= to; cursor++) {
|
|
449
|
-
let item = items[this.cursorChildIndex[cursor]];
|
|
450
|
-
if (item) {
|
|
451
|
-
let { record, data } = item.instance;
|
|
452
|
-
if (data.disabled) continue;
|
|
453
|
-
selection.push(record.data);
|
|
454
|
-
indexes.push(record.index);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
widget.selection.selectMultiple(instance.store, selection, indexes, options);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
showCursor(force, newItems) {
|
|
462
|
-
if (!force && this.state.cursor >= 0) return;
|
|
463
|
-
|
|
464
|
-
let items = newItems || this.props.items;
|
|
465
|
-
let index = -1,
|
|
466
|
-
firstSelected = -1,
|
|
467
|
-
firstValid = -1;
|
|
468
|
-
for (let i = 0; i < items.length; i++) {
|
|
469
|
-
let item = items[i];
|
|
470
|
-
if (isDataItem(item)) {
|
|
471
|
-
index++;
|
|
472
|
-
|
|
473
|
-
if (!isItemDisabled(item) && firstValid == -1) firstValid = index;
|
|
474
|
-
if (item.instance.selected) {
|
|
475
|
-
firstSelected = index;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
this.moveCursor(firstSelected != -1 ? firstSelected : firstValid, {
|
|
481
|
-
focusedport: true,
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
onFocus() {
|
|
486
|
-
let { widget } = this.props.instance;
|
|
487
|
-
|
|
488
|
-
FocusManager.nudge();
|
|
489
|
-
this.showCursor(widget.selectMode);
|
|
490
|
-
|
|
491
|
-
if (!widget.focused)
|
|
492
|
-
oneFocusOut(this, this.el, () => {
|
|
493
|
-
this.moveCursor(-1, { focused: false });
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
this.setState({
|
|
497
|
-
focused: true,
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
onBlur() {
|
|
502
|
-
FocusManager.nudge();
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
handleMouseLeave() {
|
|
506
|
-
let { widget } = this.props.instance;
|
|
507
|
-
if (!widget.focused) this.moveCursor(-1, { hover: true });
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
handleKeyDown(e) {
|
|
511
|
-
let { instance, items } = this.props;
|
|
512
|
-
let { widget } = instance;
|
|
513
|
-
|
|
514
|
-
if (this.onKeyDown && instance.invoke("onKeyDown", e, instance) === false) return;
|
|
515
|
-
|
|
516
|
-
switch (e.keyCode) {
|
|
517
|
-
case KeyCode.tab:
|
|
518
|
-
case KeyCode.enter:
|
|
519
|
-
if (!widget.selectOnTab && e.keyCode == KeyCode.tab) break;
|
|
520
|
-
let item = items[this.cursorChildIndex[this.state.cursor]];
|
|
521
|
-
if (item && widget.onItemClick && instance.invoke("onItemClick", e, item.instance) === false) return;
|
|
522
|
-
this.moveCursor(this.state.cursor, {
|
|
523
|
-
select: true,
|
|
524
|
-
selectOptions: {
|
|
525
|
-
toggle: e.ctrlKey && !e.shiftKey,
|
|
526
|
-
add: e.ctrlKey && e.shiftKey,
|
|
527
|
-
},
|
|
528
|
-
selectRange: e.shiftKey,
|
|
529
|
-
});
|
|
530
|
-
break;
|
|
531
|
-
|
|
532
|
-
case KeyCode.down:
|
|
533
|
-
for (let index = this.state.cursor + 1; index < this.cursorChildIndex.length; index++) {
|
|
534
|
-
let item = items[this.cursorChildIndex[index]];
|
|
535
|
-
if (!isItemSelectable(item)) continue;
|
|
536
|
-
this.moveCursor(index, {
|
|
537
|
-
focused: true,
|
|
538
|
-
scrollIntoView: true,
|
|
539
|
-
select: e.shiftKey,
|
|
540
|
-
selectRange: e.shiftKey,
|
|
541
|
-
});
|
|
542
|
-
e.stopPropagation();
|
|
543
|
-
e.preventDefault();
|
|
544
|
-
break;
|
|
545
|
-
}
|
|
546
|
-
break;
|
|
547
|
-
|
|
548
|
-
case KeyCode.up:
|
|
549
|
-
for (let index = this.state.cursor - 1; index >= 0; index--) {
|
|
550
|
-
let item = items[this.cursorChildIndex[index]];
|
|
551
|
-
if (!isItemSelectable(item)) continue;
|
|
552
|
-
this.moveCursor(index, {
|
|
553
|
-
focused: true,
|
|
554
|
-
scrollIntoView: true,
|
|
555
|
-
select: e.shiftKey,
|
|
556
|
-
selectRange: e.shiftKey,
|
|
557
|
-
});
|
|
558
|
-
e.stopPropagation();
|
|
559
|
-
e.preventDefault();
|
|
560
|
-
break;
|
|
561
|
-
}
|
|
562
|
-
break;
|
|
563
|
-
|
|
564
|
-
case KeyCode.a:
|
|
565
|
-
if (!e.ctrlKey || !widget.selection.multiple) return;
|
|
566
|
-
|
|
567
|
-
this.selectRange(0, this.cursorChildIndex.length);
|
|
568
|
-
|
|
569
|
-
e.stopPropagation();
|
|
570
|
-
e.preventDefault();
|
|
571
|
-
break;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
class ListItem extends Container {
|
|
577
|
-
declareData(...args) {
|
|
578
|
-
super.declareData(...args, {
|
|
579
|
-
disabled: undefined,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function isItemSelectable(item) {
|
|
585
|
-
return isDataItem(item) && !isItemDisabled(item);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
function isDataItem(item) {
|
|
589
|
-
return item?.type == "data";
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
function isItemDisabled(item) {
|
|
593
|
-
return item?.instance.data.disabled;
|
|
594
|
-
}
|
|
1
|
+
import { Widget, VDOM, getContent } from "../ui/Widget";
|
|
2
|
+
import { PureContainer } from "../ui/PureContainer";
|
|
3
|
+
import { GroupAdapter } from "../ui/adapter/GroupAdapter";
|
|
4
|
+
import { Binding, isBinding } from "../data/Binding";
|
|
5
|
+
import { Selection } from "../ui/selection/Selection";
|
|
6
|
+
import { KeyCode } from "../util/KeyCode";
|
|
7
|
+
import { scrollElementIntoView } from "../util/scrollElementIntoView";
|
|
8
|
+
import { FocusManager, oneFocusOut, offFocusOut, preventFocusOnTouch } from "../ui/FocusManager";
|
|
9
|
+
import { isString } from "../util/isString";
|
|
10
|
+
import { isArray } from "../util/isArray";
|
|
11
|
+
import { getAccessor } from "../data/getAccessor";
|
|
12
|
+
import { batchUpdates } from "../ui/batchUpdates";
|
|
13
|
+
import { Container } from "../ui/Container";
|
|
14
|
+
import { addEventListenerWithOptions } from "../util/addEventListenerWithOptions";
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
- renders list of items
|
|
18
|
+
- focusable (keyboard navigation)
|
|
19
|
+
- selection
|
|
20
|
+
- fake focus - list appears focused and receives keyboard inputs redirected from other control (dropdown scenario)
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export class List extends Widget {
|
|
24
|
+
init() {
|
|
25
|
+
if (this.recordAlias) this.recordName = this.recordAlias;
|
|
26
|
+
|
|
27
|
+
if (this.indexAlias) this.indexName = this.indexAlias;
|
|
28
|
+
|
|
29
|
+
this.adapter = GroupAdapter.create(this.adapter || GroupAdapter, {
|
|
30
|
+
recordName: this.recordName,
|
|
31
|
+
indexName: this.indexName,
|
|
32
|
+
recordsAccessor: getAccessor(this.records),
|
|
33
|
+
keyField: this.keyField,
|
|
34
|
+
sortOptions: this.sortOptions,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
this.child = ListItem.create({
|
|
38
|
+
layout: this.layout,
|
|
39
|
+
items: this.items,
|
|
40
|
+
children: this.children,
|
|
41
|
+
styled: true,
|
|
42
|
+
class: this.itemClass,
|
|
43
|
+
className: this.itemClassName,
|
|
44
|
+
style: this.itemStyle,
|
|
45
|
+
disabled: this.itemDisabled,
|
|
46
|
+
...this.item,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
delete this.children;
|
|
50
|
+
|
|
51
|
+
this.selection = Selection.create(this.selection, {
|
|
52
|
+
records: this.records,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
super.init();
|
|
56
|
+
|
|
57
|
+
if (this.grouping) {
|
|
58
|
+
this.groupBy(this.grouping);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
initInstance(context, instance) {
|
|
63
|
+
this.adapter.initInstance(context, instance);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declareData() {
|
|
67
|
+
let selection = this.selection.configureWidget(this);
|
|
68
|
+
|
|
69
|
+
super.declareData(
|
|
70
|
+
selection,
|
|
71
|
+
{
|
|
72
|
+
records: undefined,
|
|
73
|
+
sorters: undefined,
|
|
74
|
+
sortField: undefined,
|
|
75
|
+
sortDirection: undefined,
|
|
76
|
+
filterParams: {
|
|
77
|
+
structured: true,
|
|
78
|
+
},
|
|
79
|
+
itemStyle: {
|
|
80
|
+
structured: true,
|
|
81
|
+
},
|
|
82
|
+
emptyText: undefined,
|
|
83
|
+
tabIndex: undefined,
|
|
84
|
+
},
|
|
85
|
+
...arguments,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
prepareData(context, instance) {
|
|
90
|
+
let { data } = instance;
|
|
91
|
+
|
|
92
|
+
if (data.sortField)
|
|
93
|
+
data.sorters = [
|
|
94
|
+
{
|
|
95
|
+
field: data.sortField,
|
|
96
|
+
direction: data.sortDirection || "ASC",
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
this.adapter.sort(data.sorters);
|
|
100
|
+
|
|
101
|
+
let filter = null;
|
|
102
|
+
if (this.onCreateFilter) filter = instance.invoke("onCreateFilter", data.filterParams, instance);
|
|
103
|
+
else if (this.filter) filter = (item) => this.filter(item, data.filterParams);
|
|
104
|
+
this.adapter.setFilter(filter);
|
|
105
|
+
instance.mappedRecords = this.adapter.getRecords(context, instance, data.records, instance.store);
|
|
106
|
+
|
|
107
|
+
data.stateMods = Object.assign(data.stateMods || {}, {
|
|
108
|
+
selectable: !this.selection.isDummy || this.onItemClick,
|
|
109
|
+
empty: instance.mappedRecords.length == 0,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
super.prepareData(context, instance);
|
|
113
|
+
}
|
|
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
|
+
|
|
122
|
+
explore(context, instance, data) {
|
|
123
|
+
let instances = [];
|
|
124
|
+
let isSelected = this.selection.getIsSelectedDelegate(instance.store);
|
|
125
|
+
instance.mappedRecords.forEach((record) => {
|
|
126
|
+
if (record.type == "data") {
|
|
127
|
+
let itemInstance = instance.getChild(context, this.child, record.key, record.store);
|
|
128
|
+
itemInstance.record = record;
|
|
129
|
+
itemInstance.selected = isSelected(record.data, record.index);
|
|
130
|
+
|
|
131
|
+
let changed = false;
|
|
132
|
+
if (itemInstance.cache("recordData", record.data)) changed = true;
|
|
133
|
+
if (itemInstance.cache("selected", itemInstance.selected)) changed = true;
|
|
134
|
+
|
|
135
|
+
if (this.cached && !changed && itemInstance.visible && !itemInstance.childStateDirty) {
|
|
136
|
+
instances.push(itemInstance);
|
|
137
|
+
itemInstance.shouldUpdate = false;
|
|
138
|
+
} else if (itemInstance.scheduleExploreIfVisible(context)) instances.push(itemInstance);
|
|
139
|
+
} else if (record.type == "group-header" && record.grouping.header) {
|
|
140
|
+
let itemInstance = instance.getChild(context, record.grouping.header, record.key, record.store);
|
|
141
|
+
itemInstance.record = record;
|
|
142
|
+
if (itemInstance.scheduleExploreIfVisible(context)) instances.push(itemInstance);
|
|
143
|
+
} else if (record.type == "group-footer" && record.grouping.footer) {
|
|
144
|
+
let itemInstance = instance.getChild(context, record.grouping.footer, record.key, record.store);
|
|
145
|
+
itemInstance.record = record;
|
|
146
|
+
if (itemInstance.scheduleExploreIfVisible(context)) instances.push(itemInstance);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
instance.instances = instances;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
render(context, instance, key) {
|
|
153
|
+
let items = instance.instances.map((x, i) => ({
|
|
154
|
+
instance: x,
|
|
155
|
+
key: x.record.key,
|
|
156
|
+
type: x.record.type,
|
|
157
|
+
content: getContent(x.render(context)),
|
|
158
|
+
}));
|
|
159
|
+
return (
|
|
160
|
+
<ListComponent
|
|
161
|
+
key={key}
|
|
162
|
+
instance={instance}
|
|
163
|
+
items={items}
|
|
164
|
+
selectable={!this.selection.isDummy || this.onItemClick}
|
|
165
|
+
/>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
groupBy(grouping) {
|
|
170
|
+
if (!isArray(grouping)) {
|
|
171
|
+
if (isString(grouping) || typeof grouping == "object") return this.groupBy([grouping]);
|
|
172
|
+
throw new Error("DynamicGrouping should be an array of grouping objects");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
grouping = grouping.map((g, i) => {
|
|
176
|
+
if (isString(g)) {
|
|
177
|
+
return {
|
|
178
|
+
key: {
|
|
179
|
+
[g]: {
|
|
180
|
+
bind: this.recordName + "." + g,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return g;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
grouping.forEach((g) => {
|
|
189
|
+
if (g.header) g.header = Widget.create(g.header);
|
|
190
|
+
|
|
191
|
+
if (g.footer) g.footer = Widget.create(g.footer);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
this.adapter.groupBy(grouping);
|
|
195
|
+
this.update();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
List.prototype.recordName = "$record";
|
|
200
|
+
List.prototype.indexName = "$index";
|
|
201
|
+
List.prototype.baseClass = "list";
|
|
202
|
+
List.prototype.focusable = true;
|
|
203
|
+
List.prototype.focused = false;
|
|
204
|
+
List.prototype.itemPad = true;
|
|
205
|
+
List.prototype.cached = false;
|
|
206
|
+
List.prototype.styled = true;
|
|
207
|
+
List.prototype.scrollSelectionIntoView = false;
|
|
208
|
+
List.prototype.selectMode = false;
|
|
209
|
+
List.prototype.selectOnTab = false;
|
|
210
|
+
|
|
211
|
+
Widget.alias("list", List);
|
|
212
|
+
|
|
213
|
+
class ListComponent extends VDOM.Component {
|
|
214
|
+
constructor(props) {
|
|
215
|
+
super(props);
|
|
216
|
+
let { widget } = props.instance;
|
|
217
|
+
let { focused } = widget;
|
|
218
|
+
this.state = {
|
|
219
|
+
cursor: focused && props.selectable ? 0 : -1,
|
|
220
|
+
focused: focused,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
this.handleItemMouseDown = this.handleItemMouseDown.bind(this);
|
|
224
|
+
this.handleItemDoubleClick = this.handleItemDoubleClick.bind(this);
|
|
225
|
+
this.handleItemClick = this.handleItemClick.bind(this);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
shouldComponentUpdate(props, state) {
|
|
229
|
+
return props.instance.shouldUpdate || state != this.state;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
componentDidMount() {
|
|
233
|
+
let { instance } = this.props;
|
|
234
|
+
let { widget } = instance;
|
|
235
|
+
if (widget.pipeKeyDown) {
|
|
236
|
+
instance.invoke("pipeKeyDown", this.handleKeyDown.bind(this), instance);
|
|
237
|
+
this.showCursor();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (widget.autoFocus) FocusManager.focus(this.el);
|
|
241
|
+
|
|
242
|
+
if (widget.onScroll) {
|
|
243
|
+
this.unsubscribeScroll = addEventListenerWithOptions(
|
|
244
|
+
this.el,
|
|
245
|
+
"scroll",
|
|
246
|
+
(event) => {
|
|
247
|
+
instance.invoke("onScroll", event, instance);
|
|
248
|
+
},
|
|
249
|
+
{ passive: true },
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
this.componentDidUpdate();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
UNSAFE_componentWillReceiveProps(props) {
|
|
257
|
+
if (this.state.focused && props.instance.widget.selectMode) this.showCursor(true, props.items);
|
|
258
|
+
else if (this.state.cursor >= props.items.length) this.moveCursor(props.items.length - 1);
|
|
259
|
+
else if (this.state.focused && this.state.cursor < 0) this.moveCursor(0);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
componentWillUnmount() {
|
|
263
|
+
let { instance } = this.props;
|
|
264
|
+
let { widget } = instance;
|
|
265
|
+
offFocusOut(this);
|
|
266
|
+
if (widget.pipeKeyDown) instance.invoke("pipeKeyDown", null, instance);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
handleItemMouseDown(e) {
|
|
270
|
+
let index = Number(e.currentTarget.dataset.recordIndex);
|
|
271
|
+
this.moveCursor(index);
|
|
272
|
+
if (e.shiftKey) e.preventDefault();
|
|
273
|
+
|
|
274
|
+
this.moveCursor(index, {
|
|
275
|
+
select: true,
|
|
276
|
+
selectOptions: {
|
|
277
|
+
toggle: e.ctrlKey && !e.shiftKey,
|
|
278
|
+
add: e.ctrlKey && e.shiftKey,
|
|
279
|
+
},
|
|
280
|
+
selectRange: e.shiftKey,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
handleItemClick(e) {
|
|
285
|
+
let { instance, items } = this.props;
|
|
286
|
+
let index = Number(e.currentTarget.dataset.recordIndex);
|
|
287
|
+
let item = items[this.cursorChildIndex[index]];
|
|
288
|
+
if (instance.invoke("onItemClick", e, item.instance) === false) return;
|
|
289
|
+
|
|
290
|
+
this.moveCursor(index, {
|
|
291
|
+
select: true,
|
|
292
|
+
selectOptions: {
|
|
293
|
+
toggle: e.ctrlKey && !e.shiftKey,
|
|
294
|
+
add: e.ctrlKey && e.shiftKey,
|
|
295
|
+
},
|
|
296
|
+
selectRange: e.shiftKey,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
handleItemDoubleClick(e) {
|
|
301
|
+
let { instance, items } = this.props;
|
|
302
|
+
let index = Number(e.currentTarget.dataset.recordIndex);
|
|
303
|
+
let item = items[this.cursorChildIndex[index]];
|
|
304
|
+
instance.invoke("onItemDoubleClick", e, item.instance);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
render() {
|
|
308
|
+
let { instance, items, selectable } = this.props;
|
|
309
|
+
let { data, widget } = instance;
|
|
310
|
+
let { CSS, baseClass } = widget;
|
|
311
|
+
let itemStyle = CSS.parseStyle(data.itemStyle);
|
|
312
|
+
this.cursorChildIndex = [];
|
|
313
|
+
let cursorIndex = 0;
|
|
314
|
+
|
|
315
|
+
let onDblClick, onClick;
|
|
316
|
+
|
|
317
|
+
if (widget.onItemClick) onClick = this.handleItemClick;
|
|
318
|
+
|
|
319
|
+
if (widget.onItemDoubleClick) onDblClick = this.handleItemDoubleClick;
|
|
320
|
+
|
|
321
|
+
let children =
|
|
322
|
+
items.length > 0 &&
|
|
323
|
+
items.map((x, i) => {
|
|
324
|
+
let { data, selected } = x.instance;
|
|
325
|
+
let className;
|
|
326
|
+
|
|
327
|
+
if (x.type == "data") {
|
|
328
|
+
let ind = cursorIndex++;
|
|
329
|
+
|
|
330
|
+
this.cursorChildIndex.push(i);
|
|
331
|
+
className = CSS.element(baseClass, "item", {
|
|
332
|
+
selected: selected,
|
|
333
|
+
cursor: ind == this.state.cursor,
|
|
334
|
+
pad: widget.itemPad,
|
|
335
|
+
disabled: data.disabled,
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
return (
|
|
339
|
+
<li
|
|
340
|
+
key={x.key}
|
|
341
|
+
className={CSS.expand(className, data.classNames)}
|
|
342
|
+
style={itemStyle}
|
|
343
|
+
data-record-index={ind}
|
|
344
|
+
onMouseDown={this.handleItemMouseDown}
|
|
345
|
+
onClick={onClick}
|
|
346
|
+
onDoubleClick={onDblClick}
|
|
347
|
+
>
|
|
348
|
+
{x.content}
|
|
349
|
+
</li>
|
|
350
|
+
);
|
|
351
|
+
} else {
|
|
352
|
+
return (
|
|
353
|
+
<li key={x.key} className={CSS.element(baseClass, x.type)}>
|
|
354
|
+
{x.content}
|
|
355
|
+
</li>
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
if (!children && data.emptyText) {
|
|
361
|
+
children = <li className={CSS.element(baseClass, "empty-text")}>{data.emptyText}</li>;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<ul
|
|
366
|
+
ref={(el) => {
|
|
367
|
+
this.el = el;
|
|
368
|
+
}}
|
|
369
|
+
className={CSS.expand(data.classNames, CSS.state({ focused: this.state.focused }))}
|
|
370
|
+
style={data.style}
|
|
371
|
+
tabIndex={widget.focusable && selectable && items.length > 0 ? data.tabIndex || 0 : null}
|
|
372
|
+
onMouseDown={preventFocusOnTouch}
|
|
373
|
+
onKeyDown={this.handleKeyDown.bind(this)}
|
|
374
|
+
onMouseLeave={this.handleMouseLeave.bind(this)}
|
|
375
|
+
onFocus={this.onFocus.bind(this)}
|
|
376
|
+
onBlur={this.onBlur.bind(this)}
|
|
377
|
+
>
|
|
378
|
+
{children}
|
|
379
|
+
</ul>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
componentDidUpdate() {
|
|
384
|
+
let { widget } = this.props.instance;
|
|
385
|
+
if (widget.scrollSelectionIntoView) {
|
|
386
|
+
//The timeout is reqired for use-cases when parent needs to do some measuring that affect scrollbars, i.e. LookupField.
|
|
387
|
+
setTimeout(() => this.scrollElementIntoView(), 0);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
scrollElementIntoView() {
|
|
392
|
+
if (!this.el) return; //unmount
|
|
393
|
+
let { widget } = this.props.instance;
|
|
394
|
+
let { CSS, baseClass } = widget;
|
|
395
|
+
let selectedRowSelector = `.${CSS.element(baseClass, "item")}.${CSS.state("selected")}`;
|
|
396
|
+
let firstSelectedRow = this.el.querySelector(selectedRowSelector);
|
|
397
|
+
if (firstSelectedRow != this.selectedEl) {
|
|
398
|
+
if (firstSelectedRow) scrollElementIntoView(firstSelectedRow, true, false, 0, this.el);
|
|
399
|
+
this.selectedEl = firstSelectedRow;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
moveCursor(index, { focused, hover, scrollIntoView, select, selectRange, selectOptions } = {}) {
|
|
404
|
+
let { instance, selectable } = this.props;
|
|
405
|
+
if (!selectable) return;
|
|
406
|
+
|
|
407
|
+
let { widget } = instance;
|
|
408
|
+
let newState = {};
|
|
409
|
+
if (widget.focused) focused = true;
|
|
410
|
+
|
|
411
|
+
if (focused != null && this.state.focused != focused) newState.focused = focused;
|
|
412
|
+
|
|
413
|
+
//ignore mouse enter/leave events (support with a flag if a feature request comes)
|
|
414
|
+
if (!hover) newState.cursor = index;
|
|
415
|
+
|
|
416
|
+
//batch updates to avoid flickering between selection and cursor changes
|
|
417
|
+
batchUpdates(() => {
|
|
418
|
+
if (select || widget.selectMode) {
|
|
419
|
+
let start = selectRange && this.state.selectionStart >= 0 ? this.state.selectionStart : index;
|
|
420
|
+
if (start < 0) start = index;
|
|
421
|
+
this.selectRange(start, index, selectOptions);
|
|
422
|
+
if (!selectRange) newState.selectionStart = index;
|
|
423
|
+
}
|
|
424
|
+
if (Object.keys(newState).length > 0) {
|
|
425
|
+
this.setState(newState, () => {
|
|
426
|
+
if (scrollIntoView) {
|
|
427
|
+
let item = this.el.children[this.cursorChildIndex[index]];
|
|
428
|
+
if (item) scrollElementIntoView(item);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
selectRange(from, to, options) {
|
|
436
|
+
let { instance, items } = this.props;
|
|
437
|
+
let { widget } = instance;
|
|
438
|
+
|
|
439
|
+
if (from > to) {
|
|
440
|
+
let tmp = from;
|
|
441
|
+
from = to;
|
|
442
|
+
to = tmp;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
let selection = [],
|
|
446
|
+
indexes = [];
|
|
447
|
+
|
|
448
|
+
for (let cursor = from; cursor <= to; cursor++) {
|
|
449
|
+
let item = items[this.cursorChildIndex[cursor]];
|
|
450
|
+
if (item) {
|
|
451
|
+
let { record, data } = item.instance;
|
|
452
|
+
if (data.disabled) continue;
|
|
453
|
+
selection.push(record.data);
|
|
454
|
+
indexes.push(record.index);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
widget.selection.selectMultiple(instance.store, selection, indexes, options);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
showCursor(force, newItems) {
|
|
462
|
+
if (!force && this.state.cursor >= 0) return;
|
|
463
|
+
|
|
464
|
+
let items = newItems || this.props.items;
|
|
465
|
+
let index = -1,
|
|
466
|
+
firstSelected = -1,
|
|
467
|
+
firstValid = -1;
|
|
468
|
+
for (let i = 0; i < items.length; i++) {
|
|
469
|
+
let item = items[i];
|
|
470
|
+
if (isDataItem(item)) {
|
|
471
|
+
index++;
|
|
472
|
+
|
|
473
|
+
if (!isItemDisabled(item) && firstValid == -1) firstValid = index;
|
|
474
|
+
if (item.instance.selected) {
|
|
475
|
+
firstSelected = index;
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
this.moveCursor(firstSelected != -1 ? firstSelected : firstValid, {
|
|
481
|
+
focusedport: true,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
onFocus() {
|
|
486
|
+
let { widget } = this.props.instance;
|
|
487
|
+
|
|
488
|
+
FocusManager.nudge();
|
|
489
|
+
this.showCursor(widget.selectMode);
|
|
490
|
+
|
|
491
|
+
if (!widget.focused)
|
|
492
|
+
oneFocusOut(this, this.el, () => {
|
|
493
|
+
this.moveCursor(-1, { focused: false });
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
this.setState({
|
|
497
|
+
focused: true,
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
onBlur() {
|
|
502
|
+
FocusManager.nudge();
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
handleMouseLeave() {
|
|
506
|
+
let { widget } = this.props.instance;
|
|
507
|
+
if (!widget.focused) this.moveCursor(-1, { hover: true });
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
handleKeyDown(e) {
|
|
511
|
+
let { instance, items } = this.props;
|
|
512
|
+
let { widget } = instance;
|
|
513
|
+
|
|
514
|
+
if (this.onKeyDown && instance.invoke("onKeyDown", e, instance) === false) return;
|
|
515
|
+
|
|
516
|
+
switch (e.keyCode) {
|
|
517
|
+
case KeyCode.tab:
|
|
518
|
+
case KeyCode.enter:
|
|
519
|
+
if (!widget.selectOnTab && e.keyCode == KeyCode.tab) break;
|
|
520
|
+
let item = items[this.cursorChildIndex[this.state.cursor]];
|
|
521
|
+
if (item && widget.onItemClick && instance.invoke("onItemClick", e, item.instance) === false) return;
|
|
522
|
+
this.moveCursor(this.state.cursor, {
|
|
523
|
+
select: true,
|
|
524
|
+
selectOptions: {
|
|
525
|
+
toggle: e.ctrlKey && !e.shiftKey,
|
|
526
|
+
add: e.ctrlKey && e.shiftKey,
|
|
527
|
+
},
|
|
528
|
+
selectRange: e.shiftKey,
|
|
529
|
+
});
|
|
530
|
+
break;
|
|
531
|
+
|
|
532
|
+
case KeyCode.down:
|
|
533
|
+
for (let index = this.state.cursor + 1; index < this.cursorChildIndex.length; index++) {
|
|
534
|
+
let item = items[this.cursorChildIndex[index]];
|
|
535
|
+
if (!isItemSelectable(item)) continue;
|
|
536
|
+
this.moveCursor(index, {
|
|
537
|
+
focused: true,
|
|
538
|
+
scrollIntoView: true,
|
|
539
|
+
select: e.shiftKey,
|
|
540
|
+
selectRange: e.shiftKey,
|
|
541
|
+
});
|
|
542
|
+
e.stopPropagation();
|
|
543
|
+
e.preventDefault();
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
break;
|
|
547
|
+
|
|
548
|
+
case KeyCode.up:
|
|
549
|
+
for (let index = this.state.cursor - 1; index >= 0; index--) {
|
|
550
|
+
let item = items[this.cursorChildIndex[index]];
|
|
551
|
+
if (!isItemSelectable(item)) continue;
|
|
552
|
+
this.moveCursor(index, {
|
|
553
|
+
focused: true,
|
|
554
|
+
scrollIntoView: true,
|
|
555
|
+
select: e.shiftKey,
|
|
556
|
+
selectRange: e.shiftKey,
|
|
557
|
+
});
|
|
558
|
+
e.stopPropagation();
|
|
559
|
+
e.preventDefault();
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
break;
|
|
563
|
+
|
|
564
|
+
case KeyCode.a:
|
|
565
|
+
if (!e.ctrlKey || !widget.selection.multiple) return;
|
|
566
|
+
|
|
567
|
+
this.selectRange(0, this.cursorChildIndex.length);
|
|
568
|
+
|
|
569
|
+
e.stopPropagation();
|
|
570
|
+
e.preventDefault();
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
class ListItem extends Container {
|
|
577
|
+
declareData(...args) {
|
|
578
|
+
super.declareData(...args, {
|
|
579
|
+
disabled: undefined,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function isItemSelectable(item) {
|
|
585
|
+
return isDataItem(item) && !isItemDisabled(item);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function isDataItem(item) {
|
|
589
|
+
return item?.type == "data";
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function isItemDisabled(item) {
|
|
593
|
+
return item?.instance.data.disabled;
|
|
594
|
+
}
|