Skip to content

Commit e6ac578

Browse files
authored
Exporting top level core service (#147)
1 parent 06cc026 commit e6ac578

7 files changed

Lines changed: 45 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [2.2.2]
8+
## Added
9+
- New export for `SpatialNavigation` core service with types
10+
11+
## Fixed
12+
- Some Prettier formatting issues
13+
714
# [2.2.1]
815
## Added
916
- New init config option `distanceCalculationMethod` that allows switching between edge-based, center-based and corner-based (default) distance calculations.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ IMPORTANT TO NOTE:
272272

273273
# API
274274
## Top Level exports
275+
### `SpatialNavigation` (advanced)
276+
Top level API class singleton that provides access to the Navigation Service and its methods. Not recommended for beginners as it provides access to all internal methods of the core navigation service.
277+
275278
### `init`
276279
#### Init options
277280
##### `debug`: boolean (default: false)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@noriginmedia/norigin-spatial-navigation",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "React hooks based Spatial Navigation solution",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/SpatialNavigation.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,6 @@ class SpatialNavigationService {
17211721
/**
17221722
* Export singleton
17231723
*/
1724-
/** @internal */
17251724
export const SpatialNavigation = new SpatialNavigationService();
17261725

17271726
export const {

src/VisualDebugger.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import WritingDirection from "./WritingDirection";
1+
import WritingDirection from './WritingDirection';
22

33
// We'll make VisualDebugger no-op for any environments lacking a DOM (e.g. SSR and React Native non-web platforms).
44
const hasDOM = typeof window !== 'undefined' && window.document;
@@ -24,18 +24,33 @@ class VisualDebugger {
2424

2525
constructor(writingDirection: WritingDirection) {
2626
if (hasDOM) {
27-
this.debugCtx = VisualDebugger.createCanvas('sn-debug', '1010', writingDirection);
28-
this.layoutsCtx = VisualDebugger.createCanvas('sn-layouts', '1000', writingDirection);
27+
this.debugCtx = VisualDebugger.createCanvas(
28+
'sn-debug',
29+
'1010',
30+
writingDirection
31+
);
32+
this.layoutsCtx = VisualDebugger.createCanvas(
33+
'sn-layouts',
34+
'1000',
35+
writingDirection
36+
);
2937
this.writingDirection = writingDirection;
3038
}
3139
}
3240

33-
static createCanvas(id: string, zIndex: string, writingDirection: WritingDirection) {
41+
static createCanvas(
42+
id: string,
43+
zIndex: string,
44+
writingDirection: WritingDirection
45+
) {
3446
const canvas: HTMLCanvasElement =
3547
document.querySelector(`#${id}`) || document.createElement('canvas');
3648

3749
canvas.setAttribute('id', id);
38-
canvas.setAttribute('dir', writingDirection === WritingDirection.LTR ? "ltr" : "rtl");
50+
canvas.setAttribute(
51+
'dir',
52+
writingDirection === WritingDirection.LTR ? 'ltr' : 'rtl'
53+
);
3954

4055
const ctx = canvas.getContext('2d');
4156

@@ -82,11 +97,20 @@ class VisualDebugger {
8297
this.layoutsCtx.font = '8px monospace';
8398
this.layoutsCtx.fillStyle = 'red';
8499

85-
const horizontalStartDirection = this.writingDirection === WritingDirection.LTR ? "left" : "right";
100+
const horizontalStartDirection =
101+
this.writingDirection === WritingDirection.LTR ? 'left' : 'right';
86102
const horizontalStartCoordinate = layout[horizontalStartDirection];
87103

88-
this.layoutsCtx.fillText(focusKey, horizontalStartCoordinate, layout.top + 10);
89-
this.layoutsCtx.fillText(parentFocusKey, horizontalStartCoordinate, layout.top + 25);
104+
this.layoutsCtx.fillText(
105+
focusKey,
106+
horizontalStartCoordinate,
107+
layout.top + 10
108+
);
109+
this.layoutsCtx.fillText(
110+
parentFocusKey,
111+
horizontalStartCoordinate,
112+
layout.top + 25
113+
);
90114
this.layoutsCtx.fillText(
91115
`${horizontalStartDirection}: ${horizontalStartCoordinate}`,
92116
horizontalStartCoordinate,

src/WritingDirection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
enum WritingDirection {
22
LTR,
33
RTL
4-
};
4+
}
55

66
export default WritingDirection;

0 commit comments

Comments
 (0)