@@ -27,32 +27,18 @@ interface ListProps extends ComponentProps {
2727 /** A function defining how to render each list item. */
2828 renderItem : ( data : any , index : number ) => VNode
2929
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-
3630 /** CSS class(es) to add to the root of the list component. */
3731 class ?: string
3832}
3933
4034/** The List component. */
4135export class List extends DisplayComponent < ListProps > {
4236 private readonly _listContainer = FSComponent . createRef < HTMLElement > ( )
43- // private readonly _itemInstanceRefs: ScrollableControl[] = []
44-
45- // private previousSelectedIndex = -1
46- // private previousSelectedItem: any = undefined
4737
4838 /** @inheritdoc */
4939 public onAfterRender ( ) : void {
5040 this . renderList ( )
51- // if (this.props.scrollContainer) {
52- // this.scrollController.registerScrollContainer(this.props.scrollContainer.instance)
53- // }
5441 this . props . data . sub ( this . onDataChanged . bind ( this ) )
55- // this.scrollController.onScroll = this.onScroll.bind(this)
5642 }
5743
5844 /**
@@ -73,7 +59,6 @@ export class List extends DisplayComponent<ListProps> {
7359 } else {
7460 this . addDomNode ( item , index , el )
7561 }
76- // this.refreshRegistrations()
7762 }
7863 break
7964 case SubscribableArrayEventType . Removed :
@@ -85,16 +70,10 @@ export class List extends DisplayComponent<ListProps> {
8570 } else {
8671 this . removeDomNode ( index )
8772 }
88- // this.refreshRegistrations()
8973 }
9074 break
9175 case SubscribableArrayEventType . Cleared :
92- // this._itemInstanceRefs.length = 0
9376 this . _listContainer . instance . innerHTML = ""
94- // this.scrollController.resetCtrls()
95- // if (this.props.onItemSelected) {
96- // this.props.onItemSelected(null, null, -1)
97- // }
9877 break
9978 }
10079 }
@@ -106,15 +85,8 @@ export class List extends DisplayComponent<ListProps> {
10685 private removeDomNode ( index : number ) : void {
10786 const child = this . _listContainer . instance . childNodes . item ( index )
10887 this . _listContainer . instance . removeChild ( child )
109- // const removed = this._itemInstanceRefs.splice(index, 1)[0]
110- // removed.destroy()
11188 }
11289
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-
11890 /**
11991 * Adds a list rendered dom node to the collection.
12092 * @param item Item to render and add.
@@ -129,145 +101,8 @@ export class List extends DisplayComponent<ListProps> {
129101 el = this . _listContainer . instance
130102 node && el && FSComponent . render ( node , el as any )
131103 }
132-
133- // if (node !== undefined && node.instance !== null) {
134- // this._itemInstanceRefs.splice(index, 0, node.instance as ScrollableControl)
135- // }
136104 }
137105
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-
271106 /**
272107 * Renders a list item
273108 * @param dataItem The data item to render.
@@ -277,11 +112,6 @@ export class List extends DisplayComponent<ListProps> {
277112 */
278113 private renderListItem ( dataItem : any , index : number ) : VNode {
279114 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- // }
285115 }
286116 /** Renders the list of data items. */
287117 private renderList ( ) : void {
@@ -294,10 +124,8 @@ export class List extends DisplayComponent<ListProps> {
294124 const vnode = this . renderListItem ( this . props . data . get ( i ) , i )
295125 if ( vnode !== undefined ) {
296126 FSComponent . render ( vnode , this . _listContainer . instance )
297- // this._itemInstanceRefs.push(vnode.instance as ScrollableControl)
298127 }
299128 }
300- // this.refreshRegistrations()
301129 }
302130
303131 /** @inheritdoc */
0 commit comments