Skip to content

Commit 77c17d2

Browse files
committed
Rename FocusNode interface
1 parent 940ea7e commit 77c17d2

11 files changed

Lines changed: 42 additions & 48 deletions

File tree

packages/demo/src/apps/ConsoleUI/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react"
22
import { useCallback } from "react"
33
import { useHistory } from "react-router-dom"
44

5-
import { defaultGetPreferredChildOnFocus, Direction, FIXMEFocusableNode, Focusable, FocusEvent } from "react-sunbeam"
5+
import { defaultGetPreferredChildOnFocus, Direction, IFocusableNode, Focusable, FocusEvent } from "react-sunbeam"
66

77
import { ProfilesMenu } from "./ProfilesMenu"
88
import { GamesGallery } from "./GamesGallery"
@@ -51,8 +51,8 @@ export function ConsoleUI() {
5151
focusOrigin,
5252
direction,
5353
}: {
54-
focusableChildren: Map<string, FIXMEFocusableNode>
55-
focusOrigin?: FIXMEFocusableNode
54+
focusableChildren: Map<string, IFocusableNode>
55+
focusOrigin?: IFocusableNode
5656
direction?: Direction
5757
}) => {
5858
if (!focusOrigin || !direction) {

packages/react-sunbeam/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ render(
183183
### `<Root>`
184184

185185
`Root` is the root focusable component.
186-
It instantiates the focusable tree and holds its root node, as well as passing some utilities through the React context to other focusable components in the tree.
186+
It instantiates the focusable tree and holds its root node, as well as passing some utilities through React context to other focusable components in the tree.
187187

188188
```ts
189189
function Root(props: {
@@ -217,15 +217,15 @@ function useFocusable(params: {
217217
```
218218

219219
It can be used both for creating a leaf node or a branch node.
220-
If the latter is the goal, the node has to be passed down the tree through the React context.
220+
If the latter is the goal, the node has to be passed down the tree through React context.
221221
In order to do that, the user needs to render a Branch component and pass it the opaque `node` object returned from the `useFocusable()` call:
222222

223223
```ts
224224
const { focused, node } = useFocusable(...)
225225
226226
return (
227227
<Branch node={node}>
228-
...
228+
{/*...*/}
229229
</Branch>
230230
)
231231
```

packages/react-sunbeam/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
],
1111
"main": "./dist/cjs/index.js",
1212
"exports": {
13-
".": "./dist/es/index.js",
14-
"./keyPressManagement": "./dist/es/keyPressManagement/index.js",
15-
"./spatialNavigation": "./dist/es/spatialNavigation/index.js"
13+
".": "./dist/es/index.js"
1614
},
1715
"module": "./dist/es/index.js",
18-
"unpkg": "./dist/es/index.js",
1916
"types": "./dist/es/index.d.ts",
2017
"repository": {
2118
"type": "git",

packages/react-sunbeam/src/focus/FocusManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FocusPath, FocusUpdatesSubscriber, FIXMEFocusableNode, UnsubscribeFromFocusUpdatesFn } from "./types.js"
1+
import type { FocusPath, FocusUpdatesSubscriber, IFocusableNode, UnsubscribeFromFocusUpdatesFn } from "./types.js"
22
import { getNodeByPath, getPathToNode, getSiblings, validateAndFixFocusPathIfNeeded } from "./FocusableTreeUtils.js"
33
import { Direction, getBestCandidate } from "../spatialNavigation/index.js"
44
import { boxesWithinFrustumOfOrigin } from "../spatialNavigation/frustumFilteringUtils.js"
@@ -17,7 +17,7 @@ export class FocusManager {
1717
* path from the focusableRoot to the focusTarget.
1818
*/
1919
private focusPath: readonly string[]
20-
private focusableRoot: FIXMEFocusableNode | undefined
20+
private focusableRoot: IFocusableNode | undefined
2121
private subscribers: Set<FocusUpdatesSubscriber>
2222

2323
public constructor(options: Options = defaultOptions) {
@@ -68,7 +68,7 @@ export class FocusManager {
6868
// ===================================
6969

7070
/** @private */
71-
public setFocusableRoot(focusableRoot: FIXMEFocusableNode): void {
71+
public setFocusableRoot(focusableRoot: IFocusableNode): void {
7272
this.focusableRoot = focusableRoot
7373

7474
this.revalidateFocusPath()
@@ -129,10 +129,10 @@ export class FocusManager {
129129
}
130130

131131
function findBestCandidateAmongSiblingsOf(
132-
treeNode: FIXMEFocusableNode,
133-
focusOrigin: FIXMEFocusableNode,
132+
treeNode: IFocusableNode,
133+
focusOrigin: IFocusableNode,
134134
direction: Direction
135-
): FIXMEFocusableNode | null {
135+
): IFocusableNode | null {
136136
// Focus doesn't move
137137
if (isDirectionLocked(direction, treeNode.getLock())) return null
138138

packages/react-sunbeam/src/focus/FocusableNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { BoundingBox, Direction } from "../spatialNavigation/index.js"
2-
import type { CustomGetPreferredChildFn, FocusKey, FIXMEFocusableNode } from "./types.js"
2+
import type { CustomGetPreferredChildFn, FocusKey, IFocusableNode } from "./types.js"
33
import { assert } from "../shared/assert.js"
44
import getPreferredNode from "./getPreferredNode.js"
55

66
export type FocusableNodesMap = Map<FocusKey, FocusableNode>
77

8-
export class FocusableNode implements FIXMEFocusableNode {
8+
export class FocusableNode implements IFocusableNode {
99
private readonly revalidateFocusPath: () => void
1010
private readonly focusKey: FocusKey
1111
private readonly path: FocusKey[]
@@ -72,7 +72,7 @@ export class FocusableNode implements FIXMEFocusableNode {
7272
this.lock = lock
7373
}
7474

75-
public getPreferredChild(focusOrigin?: FIXMEFocusableNode, direction?: Direction) {
75+
public getPreferredChild(focusOrigin?: IFocusableNode, direction?: Direction) {
7676
return this.customGetPreferredChild
7777
? this.customGetPreferredChild({
7878
focusableChildren: this.children,

packages/react-sunbeam/src/focus/FocusableTreeUtils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { FocusPath, FIXMEFocusableNode } from "./types.js"
1+
import type { FocusPath, IFocusableNode } from "./types.js"
22
import { FOCUSABLE_TREE_ROOT_KEY } from "./Constants.js"
33

4-
export function validateAndFixFocusPathIfNeeded(focusPath: FocusPath, treeRoot: FIXMEFocusableNode): FocusPath | null {
4+
export function validateAndFixFocusPathIfNeeded(focusPath: FocusPath, treeRoot: IFocusableNode): FocusPath | null {
55
let fixedFocusPath: string[] | null = null // only initialize if we need to fix the path
66
let currentNode = treeRoot
77
let focusPathSegmentIndex = 0
@@ -45,18 +45,18 @@ export function validateAndFixFocusPathIfNeeded(focusPath: FocusPath, treeRoot:
4545
return fixedFocusPath ? fixedFocusPath : null
4646
}
4747

48-
export function getNodeByPath(path: FocusPath, treeRoot: FIXMEFocusableNode): FIXMEFocusableNode | undefined {
49-
return path.reduce((node: FIXMEFocusableNode | undefined, focusKey: string) => {
48+
export function getNodeByPath(path: FocusPath, treeRoot: IFocusableNode): IFocusableNode | undefined {
49+
return path.reduce((node: IFocusableNode | undefined, focusKey: string) => {
5050
if (node === undefined) return undefined
5151

5252
return node.getChildren().get(focusKey)
5353
}, treeRoot)
5454
}
5555

56-
export function getPathToNode(treeNode: FIXMEFocusableNode): FocusPath {
56+
export function getPathToNode(treeNode: IFocusableNode): FocusPath {
5757
const path: string[] = []
5858

59-
let currentNode: FIXMEFocusableNode | undefined = treeNode
59+
let currentNode: IFocusableNode | undefined = treeNode
6060
while (currentNode) {
6161
const focusKey = currentNode.getFocusKey()
6262

@@ -71,9 +71,9 @@ export function getPathToNode(treeNode: FIXMEFocusableNode): FocusPath {
7171
return path
7272
}
7373

74-
export function getSiblings(focusableTreeNode: FIXMEFocusableNode): readonly FIXMEFocusableNode[] {
74+
export function getSiblings(focusableTreeNode: IFocusableNode): readonly IFocusableNode[] {
7575
const parent = focusableTreeNode.getParent()
76-
const siblings: FIXMEFocusableNode[] = []
76+
const siblings: IFocusableNode[] = []
7777

7878
if (!parent) return siblings
7979

packages/react-sunbeam/src/focus/getClosestFocusableNodeInDirection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { FIXMEFocusableNode } from "./types.js"
1+
import type { IFocusableNode } from "./types.js"
22
import type { FocusKey } from "./types.js"
33
import type { Direction, BoundingBox } from "../spatialNavigation/index.js"
44
import { getBestCandidate } from "../spatialNavigation/index.js"
55

6-
export function getClosestFocusableNodeInDirection<N extends FIXMEFocusableNode>(
6+
export function getClosestFocusableNodeInDirection<N extends IFocusableNode>(
77
focusableNodes: Map<FocusKey, N>,
88
focusOrigin: BoundingBox,
99
direction: Direction

packages/react-sunbeam/src/focus/getPreferredNode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import type { FocusKey, FIXMEFocusableNode } from "./types.js"
1+
import type { FocusKey, IFocusableNode } from "./types.js"
22
import type { Direction } from "../spatialNavigation/index.js"
33
import { getClosestFocusableNodeInDirection } from "./getClosestFocusableNodeInDirection.js"
44

55
interface Arguments {
6-
nodes: Map<FocusKey, FIXMEFocusableNode>
7-
focusOrigin?: FIXMEFocusableNode
6+
nodes: Map<FocusKey, IFocusableNode>
7+
focusOrigin?: IFocusableNode
88
direction?: Direction
99
}
1010

11-
export default function getPreferredNode({ nodes, focusOrigin, direction }: Arguments): FIXMEFocusableNode | undefined {
11+
export default function getPreferredNode({ nodes, focusOrigin, direction }: Arguments): IFocusableNode | undefined {
1212
if (!focusOrigin || !direction) {
1313
// pick the child that was mounted first
1414
return nodes.values().next().value

packages/react-sunbeam/src/focus/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import getPreferredNode from "./getPreferredNode.js"
2-
import type { FIXMEFocusableNode } from "./types.js"
2+
import type { IFocusableNode } from "./types.js"
33
import type { Direction } from "../spatialNavigation/index.js"
44

5-
export type { FocusEvent, FIXMEFocusableNode } from "./types.js"
5+
export type { FocusEvent, IFocusableNode } from "./types.js"
66
export { FocusManager } from "./FocusManager.js"
77
export { Branch } from "./components/Branch.js"
88
export { Root } from "./components/Root/index.js"
@@ -15,8 +15,8 @@ export function defaultGetPreferredChildOnFocus({
1515
focusOrigin,
1616
direction,
1717
}: {
18-
focusableChildren: Map<string, FIXMEFocusableNode>
19-
focusOrigin?: FIXMEFocusableNode
18+
focusableChildren: Map<string, IFocusableNode>
19+
focusOrigin?: IFocusableNode
2020
direction?: Direction
2121
}) {
2222
return getPreferredNode({ nodes: focusableChildren, focusOrigin, direction })

packages/react-sunbeam/src/focus/types.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@ export type FocusUpdatesSubscriber = (event: { focusPath: FocusPath }) => void
1414
export type UnsubscribeFromFocusUpdatesFn = () => void
1515

1616
export type CustomGetPreferredChildFn = (params: {
17-
focusableChildren: Map<FocusKey, FIXMEFocusableNode>
18-
focusOrigin?: FIXMEFocusableNode
17+
focusableChildren: Map<FocusKey, IFocusableNode>
18+
focusOrigin?: IFocusableNode
1919
direction?: Direction
20-
}) => FIXMEFocusableNode | undefined
20+
}) => IFocusableNode | undefined
2121

22-
export type GetPreferredChildFn = (
23-
focusOrigin?: FIXMEFocusableNode,
24-
direction?: Direction
25-
) => FIXMEFocusableNode | undefined
22+
export type GetPreferredChildFn = (focusOrigin?: IFocusableNode, direction?: Direction) => IFocusableNode | undefined
2623

2724
/**
2825
* The public API version of FocusableNode class's interface.
2926
*/
30-
export interface FIXMEFocusableNode {
27+
export interface IFocusableNode {
3128
getFocusKey(): FocusKey
3229
getPath(): FocusKey[]
3330
getBoundingBox(): BoundingBox
34-
getParent(): FIXMEFocusableNode | undefined
35-
getChildren(): Map<FocusKey, FIXMEFocusableNode>
31+
getParent(): IFocusableNode | undefined
32+
getChildren(): Map<FocusKey, IFocusableNode>
3633
getPreferredChild: GetPreferredChildFn
3734
getLock(): Direction[] | Direction | undefined
3835
}

0 commit comments

Comments
 (0)