@@ -27,32 +27,18 @@ interface ListProps extends ComponentProps {
27
27
/** A function defining how to render each list item. */
28
28
renderItem : ( data : any , index : number ) => VNode
29
29
30
- /** A callback function to be called when a new item is selected. */
31
- // onItemSelected?: (data: any, element: ScrollableControl | null, index: number) => void
32
-
33
- /** The container used for scrolling. */
34
- // scrollContainer?: NodeReference<HTMLElement>
35
-
36
30
/** CSS class(es) to add to the root of the list component. */
37
31
class ?: string
38
32
}
39
33
40
34
/** The List component. */
41
35
export class List extends DisplayComponent < ListProps > {
42
36
private readonly _listContainer = FSComponent . createRef < HTMLElement > ( )
43
- // private readonly _itemInstanceRefs: ScrollableControl[] = []
44
-
45
- // private previousSelectedIndex = -1
46
- // private previousSelectedItem: any = undefined
47
37
48
38
/** @inheritdoc */
49
39
public onAfterRender ( ) : void {
50
40
this . renderList ( )
51
- // if (this.props.scrollContainer) {
52
- // this.scrollController.registerScrollContainer(this.props.scrollContainer.instance)
53
- // }
54
41
this . props . data . sub ( this . onDataChanged . bind ( this ) )
55
- // this.scrollController.onScroll = this.onScroll.bind(this)
56
42
}
57
43
58
44
/**
@@ -73,7 +59,6 @@ export class List extends DisplayComponent<ListProps> {
73
59
} else {
74
60
this . addDomNode ( item , index , el )
75
61
}
76
- // this.refreshRegistrations()
77
62
}
78
63
break
79
64
case SubscribableArrayEventType . Removed :
@@ -85,16 +70,10 @@ export class List extends DisplayComponent<ListProps> {
85
70
} else {
86
71
this . removeDomNode ( index )
87
72
}
88
- // this.refreshRegistrations()
89
73
}
90
74
break
91
75
case SubscribableArrayEventType . Cleared :
92
- // this._itemInstanceRefs.length = 0
93
76
this . _listContainer . instance . innerHTML = ""
94
- // this.scrollController.resetCtrls()
95
- // if (this.props.onItemSelected) {
96
- // this.props.onItemSelected(null, null, -1)
97
- // }
98
77
break
99
78
}
100
79
}
@@ -106,15 +85,8 @@ export class List extends DisplayComponent<ListProps> {
106
85
private removeDomNode ( index : number ) : void {
107
86
const child = this . _listContainer . instance . childNodes . item ( index )
108
87
this . _listContainer . instance . removeChild ( child )
109
- // const removed = this._itemInstanceRefs.splice(index, 1)[0]
110
- // removed.destroy()
111
88
}
112
89
113
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
114
- // private registerListItem = (ctrl: UiControl): void => {
115
- // // noop here, we will refresh all registrations on our own
116
- // }
117
-
118
90
/**
119
91
* Adds a list rendered dom node to the collection.
120
92
* @param item Item to render and add.
@@ -129,145 +101,8 @@ export class List extends DisplayComponent<ListProps> {
129
101
el = this . _listContainer . instance
130
102
node && el && FSComponent . render ( node , el as any )
131
103
}
132
-
133
- // if (node !== undefined && node.instance !== null) {
134
- // this._itemInstanceRefs.splice(index, 0, node.instance as ScrollableControl)
135
- // }
136
104
}
137
105
138
- /**
139
- * Refreshs control registrations of all list elements.
140
- */
141
- // private refreshRegistrations(): void {
142
- // this.scrollController.resetCtrls()
143
- // for (let i = 0; i < this._itemInstanceRefs.length; i++) {
144
- // const instance = this._itemInstanceRefs[i]
145
- // if (instance instanceof UiControlGroup) {
146
- // this.register(instance)
147
- // } else if (instance instanceof UiControl) {
148
- // instance.props.onRegister = this.register
149
- // instance.onRegister()
150
- // this.register(instance);
151
- // }
152
- // }
153
- // if (this.getIsFocused()) {
154
- // if (
155
- // this.previousSelectedIndex < 0
156
- // ? this.scrollController.gotoFirst()
157
- // : this.previousSelectedIndex >= this.props.data.length
158
- // ? this.scrollController.gotoLast()
159
- // : this.scrollController.scrollTo("prev", this.previousSelectedIndex + 1)
160
- // ) {
161
- // return
162
- // } else {
163
- // this.previousSelectedIndex = -1
164
- // }
165
- // }
166
- // if (this.previousSelectedIndex < 0 || this.previousSelectedIndex >= this.props.data.length) {
167
- // this.previousSelectedIndex = -1
168
- // }
169
- // const item = this.props.data.tryGet(this.previousSelectedIndex) ?? null
170
- // if (item !== this.previousSelectedItem) {
171
- // this.props.onItemSelected &&
172
- // this.props.onItemSelected(
173
- // item,
174
- // this.getListItemInstance(this.previousSelectedIndex),
175
- // this.previousSelectedIndex,
176
- // )
177
- // }
178
- // this.previousSelectedItem = item
179
- // }
180
-
181
- /**
182
- * Scrolls to an item.
183
- * @param index is the index of the list item to scroll to.
184
- */
185
- // public scrollToIndex(index: number): void {
186
- // this.scrollController.gotoIndex(index)
187
- // }
188
-
189
- /**
190
- * Ensures an indexed list item is in view.
191
- * @param index The index of the list item.
192
- */
193
- //
194
-
195
- /**
196
- * Gets the data object related to the selected DOM element.
197
- * @returns The selected item, if found.
198
- */
199
- // public getSelectedItem(): any | null {
200
- // const selectedIndex = this.getSelectedIndex()
201
- // if (selectedIndex > -1) {
202
- // return this.props.data.get(selectedIndex)
203
- // }
204
- // return null
205
- // }
206
-
207
- /**
208
- * Get the selected HTMLElement.
209
- * @returns The selected element, if found.
210
- */
211
- // public getSelectedElement(): HTMLElement | null {
212
- // return (this._listContainer.instance.children[this.getSelectedIndex()] as HTMLElement) ?? null
213
- // }
214
-
215
- /**
216
- * Gets the index of the currently selected element.
217
- * @returns Selected element index. Returns -1 if nothing found.
218
- */
219
- // public getSelectedIndex(): number {
220
- // const focusedControl = this.scrollController.getFocusedUiControl()
221
- // return focusedControl ? this._itemInstanceRefs.indexOf(focusedControl) : -1
222
- // }
223
-
224
- /**
225
- * Gets the instance of the node at the specified index.
226
- * @param index The index to get the instance for.
227
- * @returns The node instance of specified type.
228
- */
229
- // public getListItemInstance<T>(index: number): T | null {
230
- // return (this._itemInstanceRefs[index] as unknown as T) ?? null
231
- // }
232
-
233
- /**
234
- * Gets index of a item in the list by its node instance.
235
- * @param nodeInstance The node instance to look for.
236
- * @returns list item index
237
- */
238
- // public getListItemIndex(nodeInstance: ScrollableControl): number {
239
- // return this._itemInstanceRefs.indexOf(nodeInstance)
240
- // }
241
-
242
- /** @inheritdoc */
243
- // protected onBlurred(): void {
244
- // if (this.previousSelectedItem && this.props.onItemSelected) {
245
- // this.props.onItemSelected(null, null, -1)
246
- // }
247
-
248
- // this.previousSelectedItem = null
249
- // this.previousSelectedIndex = -1
250
- // }
251
-
252
- /** @inheritdoc */
253
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
254
- // protected onScroll(ctrl: ScrollableControl): void {
255
- // const el = this.getSelectedElement()
256
- // if (el !== null && this.props.scrollContainer) {
257
- // ScrollUtils.ensureInView(el, this.props.scrollContainer.instance)
258
- // }
259
-
260
- // const index = this.getSelectedIndex()
261
- // const item = this.props.data.tryGet(index) ?? null
262
-
263
- // if (this.props.onItemSelected) {
264
- // item !== this.previousSelectedItem && this.props.onItemSelected(item, this.getListItemInstance(index), index)
265
- // }
266
-
267
- // this.previousSelectedItem = item
268
- // this.previousSelectedIndex = index
269
- // }
270
-
271
106
/**
272
107
* Renders a list item
273
108
* @param dataItem The data item to render.
@@ -277,11 +112,6 @@ export class List extends DisplayComponent<ListProps> {
277
112
*/
278
113
private renderListItem ( dataItem : any , index : number ) : VNode {
279
114
return this . props . renderItem ( dataItem , index )
280
- // if (renderedNode.instance instanceof UiControl || renderedNode.instance instanceof UiControlGroup) {
281
- // return renderedNode
282
- // } else {
283
- // throw new Error("A ListItem must be of type UiControl or UiControlGroup!")
284
- // }
285
115
}
286
116
/** Renders the list of data items. */
287
117
private renderList ( ) : void {
@@ -294,10 +124,8 @@ export class List extends DisplayComponent<ListProps> {
294
124
const vnode = this . renderListItem ( this . props . data . get ( i ) , i )
295
125
if ( vnode !== undefined ) {
296
126
FSComponent . render ( vnode , this . _listContainer . instance )
297
- // this._itemInstanceRefs.push(vnode.instance as ScrollableControl)
298
127
}
299
128
}
300
- // this.refreshRegistrations()
301
129
}
302
130
303
131
/** @inheritdoc */
0 commit comments