Skip to content

Commit

Permalink
Add getPositions to API types, allow null in types for set methods (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lgersen committed May 14, 2024
1 parent d647612 commit a45fa16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 15.7.2 (*2024-05-14*)
- Added: `getPositions` to Typescript definitions (#1270);
- Added: Allow `null` in `set` Typescript definitions (#1271);

### 15.7.1 (*2023-06-14*)
- Added: `module` field to `package.json` (#1247, #1248);

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nouislider",
"version": "15.7.1",
"version": "15.7.2",
"main": "dist/nouislider.js",
"module": "dist/nouislider.mjs",
"style": "dist/nouislider.min.css",
Expand Down
13 changes: 8 additions & 5 deletions src/nouislider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ type Pips = PositionsPips | ValuesPips | CountPips | StepsPips | RangePips;

//endregion

type StartValues = string | number | (string | number)[];
type ValueArgument = number | string | null;

type StartValues = ValueArgument | ValueArgument[];

type HandleAttributes = { [key: string]: string };

Expand Down Expand Up @@ -202,8 +204,8 @@ export interface API {
on: (eventName: string, callback: EventCallback) => void;
off: (eventName: string) => void;
get: (unencoded?: boolean) => GetResult;
set: (input: number | string | (number | string)[], fireSetEvent?: boolean, exactInput?: boolean) => void;
setHandle: (handleNumber: number, value: number | string, fireSetEvent?: boolean, exactInput?: boolean) => void;
set: (input: ValueArgument | ValueArgument[], fireSetEvent?: boolean, exactInput?: boolean) => void;
setHandle: (handleNumber: number, value: ValueArgument, fireSetEvent?: boolean, exactInput?: boolean) => void;
reset: (fireSetEvent?: boolean) => void;
disable: (handleNumber?: number) => void;
enable: (handleNumber?: number) => void;
Expand All @@ -212,6 +214,7 @@ export interface API {
target: HTMLElement;
removePips: () => void;
removeTooltips: () => void;
getPositions: () => number[];
getTooltips: () => { [handleNumber: number]: HTMLElement | false };
getOrigins: () => { [handleNumber: number]: HTMLElement };
pips: (grid: Pips) => HTMLElement;
Expand Down Expand Up @@ -2740,7 +2743,7 @@ function scope(target: TargetElement, options: ParsedOptions, originalOptions: O
}

// Parses value passed to .set method. Returns current value if not parse-able.
function resolveToValue(to: null | false | undefined | string | number, handleNumber: number): number {
function resolveToValue(to: ValueArgument | false | undefined, handleNumber: number): number {
// Setting with null indicates an 'ignore'.
// Inputting 'false' is invalid.
if (to === null || to === false || to === undefined) {
Expand Down Expand Up @@ -2830,7 +2833,7 @@ function scope(target: TargetElement, options: ParsedOptions, originalOptions: O
// Set value for a single handle
function valueSetHandle(
handleNumber: number,
value: string | number,
value: ValueArgument,
fireSetEvent?: boolean,
exactInput?: boolean
): void {
Expand Down

0 comments on commit a45fa16

Please sign in to comment.