From a45fa165e2d1dd2dfdcc901463b5e9c1de3699a5 Mon Sep 17 00:00:00 2001 From: lgersen Date: Tue, 14 May 2024 11:28:08 +0200 Subject: [PATCH] Add getPositions to API types, allow null in types for set methods (#1270, #1271) --- CHANGELOG.MD | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- src/nouislider.ts | 13 ++++++++----- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 5a2cc8a..2c862e8 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -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); diff --git a/package-lock.json b/package-lock.json index 24a5b0d..7712f42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nouislider", - "version": "15.7.1", + "version": "15.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nouislider", - "version": "15.7.1", + "version": "15.7.2", "license": "MIT", "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.10", diff --git a/package.json b/package.json index 349f076..d864294 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/nouislider.ts b/src/nouislider.ts index 3df8bcc..a59b868 100644 --- a/src/nouislider.ts +++ b/src/nouislider.ts @@ -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 }; @@ -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; @@ -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; @@ -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) { @@ -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 {