luke-chang / js-spatial-navigation

A javascript-based implementation of Spatial Navigation.
Mozilla Public License 2.0
370 stars 117 forks source link

Typescript definitions HERE: please help to publish it :) #62

Open hinsxd opened 10 months ago

hinsxd commented 10 months ago

I just wrote some definitions for my use but I don't know how to use bower. If anyone knows how to include a .d.ts file, please open a PR for that. :)

If you want to use the types, put the code below in a .d.ts included in your project!

declare module "js-spatial-navigation" {
  export default SpatialNavigation;
}

declare namespace SpatialNavigation {
  interface Config {
    id: string;
    selector: string;
    straightOnly: boolean;
    straightOverlapThreshold: number;
    rememberSource: boolean;
    disabled: boolean;
    defaultElement: string;
    enterTo: "last-focused" | "default-element";
    leaveFor: null | Record<"left" | "right" | "up" | "down", string>;
    restrict: "self-first" | "self-only" | "none";
    tabIndexIgnoreList: string;
    navigableFilter: null | ((el: HTMLElement) => void);
  }

  function init(): void;
  function uninit(): void;
  function clear(): void;

  function set(config: Partial<SpatialNavigation.Config>): void;
  function set(
    sectionId: string,
    config: Partial<SpatialNavigation.Config>
  ): void;

  function add(config: Partial<SpatialNavigation.Config>): string;
  function add(
    sectionId: string,
    config: Partial<SpatialNavigation.Config>
  ): string;

  function remove(sectionId: string): boolean;

  function disable(sectionId: string): boolean;

  function enable(sectionId: string): void;

  function pause(): void;

  function resume(): void;

  function focus(silent?: boolean): boolean;
  function focus(sectionId: string, silent?: boolean): boolean;
  function focus(extSelector: string, silent?: boolean): boolean;

  function move(direction: string): boolean;
  function move(direction: string, selector: string): boolean;

  function makeFocusable(sectionId?: string): void;
  function setDefaultSection(sectionId: string): void;
}