Skip to content

Commit

Permalink
Fixed ts typings (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Apr 29, 2024
1 parent 101c7e7 commit e1f2769
Show file tree
Hide file tree
Showing 193 changed files with 2,346 additions and 717 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ jobs:
- name: Run tests
run: |
npm i
npm run formatCheck
rm -r ./types
npx tsc
npx quick-lint-js ./**/*.mjs ./**/*.ts
npx tsc -p ./test
# ensure that committed and generated types are the same
git diff --exit-code
npx quick-lint-js ./**/*.mjs
npm run formatCheck
NODE_V8_COVERAGE=coverage0 npx c8 -r lcovonly --all --src ./src node --experimental-test-coverage ./test/all.mjs
if: ${{ env.TAG_NAME == '' }}

Expand Down
2 changes: 1 addition & 1 deletion index.d.ts → index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DetailedBlessedProps } from "react-blessed";
import Blessed from "@farjs/blessed";

type ButtonElement = Blessed.Widgets.ButtonElement;
type FormElement = Blessed.Widgets.FormElement;
type FormElement = Blessed.Widgets.FormElement<any>;
type TextElement = Blessed.Widgets.TextElement;

declare module "react" {
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
"license": "MIT",
"description": "Terminal UI React.js components library",
"scripts": {
"lint": "quick-lint-js ./**/*.mjs ./**/*.ts",
"test": "tsc && bun test && node ./test/all.mjs",
"format": "prettier **/*.mjs **/*.ts --write",
"formatCheck": "prettier **/*.mjs **/*.ts --check"
"lint": "quick-lint-js ./**/*.mjs",
"test": "tsc && tsc -p ./test && bun test && node ./test/all.mjs",
"format": "prettier **/*.mjs --write",
"formatCheck": "prettier **/*.mjs --check"
},
"type": "module",
"exports": {
"./*": "./src/*"
"./*": {
"types": "./types/*",
"default": "./src/*"
}
},
"types": "./types/*",
"private": false,
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -47,10 +51,10 @@
"@types/react-blessed": "^0.7.3",
"@types/react-test-renderer": "^17.0.1",
"c8": "^7.13.0",
"mock-fn": "^1.0.0",
"mock-fn": "^1.1.0",
"prettier": "^2.8.8",
"quick-lint-js": "^3.0.0",
"react-assert": "^1.0.3",
"react-assert": "^1.1.0",
"react-test-renderer": "^17.0.1",
"typescript": "^4.9.5"
}
Expand Down
11 changes: 0 additions & 11 deletions src/Button.d.ts

This file was deleted.

13 changes: 10 additions & 3 deletions src/Button.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
/**
* @typedef {import("./Button").ButtonProps} ButtonProps
*/
import React, { useState } from "react";
import * as UI from "./UI.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly left: number;
* readonly top: number;
* readonly label: string;
* readonly style: import("@farjs/blessed").Widgets.Types.TStyle;
* onPress(): void;
* }} ButtonProps
*/

/**
* @param {ButtonProps} props
*/
Expand Down
14 changes: 0 additions & 14 deletions src/ButtonsPanel.d.ts

This file was deleted.

20 changes: 17 additions & 3 deletions src/ButtonsPanel.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
/**
* @typedef {import("./ButtonsPanel").ButtonsPanelProps} ButtonsPanelProps
*/
import React from "react";
import Button from "./Button.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly label: string;
* onAction(): void;
* }} ButtonsPanelAction
*/

/**
* @typedef {{
* readonly top: number;
* readonly actions: ButtonsPanelAction[];
* readonly style: import("@farjs/blessed").Widgets.Types.TStyle;
* readonly padding?: number;
* readonly margin?: number;
* }} ButtonsPanelProps
*/

/**
* @param {ButtonsPanelProps} props
*/
Expand Down
10 changes: 0 additions & 10 deletions src/CheckBox.d.ts

This file was deleted.

14 changes: 11 additions & 3 deletions src/CheckBox.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/**
* @typedef {import("./CheckBox").CheckBoxProps} CheckBoxProps
*/
import React from "react";
import Button from "./Button.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly left: number;
* readonly top: number;
* readonly value: boolean;
* readonly label: string;
* readonly style: import("@farjs/blessed").Widgets.Types.TStyle;
* onChange(): void;
* }} CheckBoxProps
*/

/**
* @param {CheckBoxProps} props
*/
Expand Down
9 changes: 0 additions & 9 deletions src/ComboBox.d.ts

This file was deleted.

17 changes: 14 additions & 3 deletions src/ComboBox.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/**
* @typedef {import("@farjs/blessed").BlessedProgram} BlessedProgram
* @typedef {import("@farjs/blessed").Widgets.BlessedElement} BlessedElement
* @typedef {import("./ListViewport").ListViewport} ListViewport
* @typedef {import("./TextInput").TextInputState} TextInputState
* @typedef {import("./ComboBox").ComboBoxProps} ComboBoxProps
* @typedef {import("./ListViewport.mjs").ListViewport} ListViewport
* @typedef {import("./TextInput.mjs").TextInputState} TextInputState
*/
import React, { useRef, useState } from "react";
import { createListViewport } from "./ListViewport.mjs";
Expand All @@ -14,6 +13,18 @@ import ComboBoxPopup from "./ComboBoxPopup.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly left: number;
* readonly top: number;
* readonly width: number;
* readonly items: string[];
* readonly value: string;
* onChange(value: string): void;
* onEnter?(): void;
* }} ComboBoxProps
*/

/**
* @param {ComboBoxProps} props
*/
Expand Down
13 changes: 0 additions & 13 deletions src/ComboBoxPopup.d.ts

This file was deleted.

15 changes: 14 additions & 1 deletion src/ComboBoxPopup.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import("./ComboBoxPopup").ComboBoxPopupProps} ComboBoxPopupProps
* @typedef {import("./ListViewport.mjs").ListViewport} ListViewport
*/
import React from "react";
import SingleBorder from "./border/SingleBorder.mjs";
Expand All @@ -8,6 +8,19 @@ import ScrollBar from "./ScrollBar.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly left: number;
* readonly top: number;
* readonly width: number;
* readonly items: string[];
* readonly style: import("@farjs/blessed").Widgets.Types.TStyle;
* readonly viewport: ListViewport;
* setViewport(viewport: ListViewport): void;
* onClick(index: number): void;
* }} ComboBoxPopupProps
*/

/**
* @param {ComboBoxPopupProps} props
*/
Expand Down
13 changes: 0 additions & 13 deletions src/ListBox.d.ts

This file was deleted.

15 changes: 14 additions & 1 deletion src/ListBox.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* @typedef {import("@farjs/blessed").Widgets.Events.IKeyEventArg} IKeyEventArg
* @typedef {import("./ListBox").ListBoxProps} ListBoxProps
*/
import React, { useLayoutEffect, useState } from "react";
import { createListViewport } from "./ListViewport.mjs";
Expand All @@ -9,6 +8,20 @@ import ScrollBar from "./ScrollBar.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly left: number;
* readonly top: number;
* readonly width: number;
* readonly height: number;
* readonly style: import("@farjs/blessed").Widgets.Types.TStyle;
* readonly items: string[];
* readonly selected: number;
* onAction(index: number): void;
* onSelect?(index: number): void;
* }} ListBoxProps
*/

/**
* @param {ListBoxProps} props
*/
Expand Down
16 changes: 0 additions & 16 deletions src/ListView.d.ts

This file was deleted.

16 changes: 15 additions & 1 deletion src/ListView.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
* @typedef {import("@farjs/blessed").Widgets.Types.TStyle} BlessedStyle
* @typedef {import("@farjs/blessed").Widgets.BlessedElement} BlessedElement
* @typedef {import("@farjs/blessed").Widgets.Events.IMouseEventArg} MouseEvent
* @typedef {import("./ListView").ListViewProps} ListViewProps
* @typedef {import("./ListViewport.mjs").ListViewport} ListViewport
*/
import React, { useLayoutEffect, useRef } from "react";
import * as UI from "./UI.mjs";
import UiString from "./UiString.mjs";

const h = React.createElement;

/**
* @typedef {{
* readonly left: number;
* readonly top: number;
* readonly width: number;
* readonly height: number;
* readonly items: string[];
* readonly style: BlessedStyle;
* readonly viewport: ListViewport;
* setViewport(viewport: ListViewport): void;
* onClick(index: number): void;
* }} ListViewProps
*/

/**
* @param {number} selected
* @param {string[]} items
Expand Down
15 changes: 0 additions & 15 deletions src/ListViewport.d.ts

This file was deleted.

16 changes: 15 additions & 1 deletion src/ListViewport.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
/**
* @typedef {import("./ListViewport").ListViewport} ListViewport
* @typedef {{
* readonly offset: number;
* readonly focused: number;
* readonly length: number;
* readonly viewLength: number;
* updated(offset: number, focused?: number): ListViewport;
* down(): ListViewport;
* up(): ListViewport;
* pagedown(): ListViewport;
* pageup(): ListViewport;
* end(): ListViewport;
* home(): ListViewport;
* onKeypress(keyFull: string): ListViewport | undefined;
* resize(viewLength: number): ListViewport;
* }} ListViewport
*/

/**
Expand Down
9 changes: 0 additions & 9 deletions src/ProgressBar.d.ts

This file was deleted.

0 comments on commit e1f2769

Please sign in to comment.