From a448640f4cb5c8f473780674ec5a480d48d9f37f Mon Sep 17 00:00:00 2001 From: janstoff Date: Mon, 14 Oct 2024 09:36:18 +0100 Subject: [PATCH 1/2] add types for npm import with types --- index.d.ts | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 29 +++++++++++++--------- 2 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..34db507 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,69 @@ +declare module "addsearch-search-ui" { + export default class AddSearchUI { + constructor(client: any, settings?: any); + start(): void; + executeSearch( + keyword: string, + options?: any, + appendResults?: boolean, + fieldForInstantRedirect?: string, + fieldForInstantRedirectInConfiguration?: string + ): void; + fetchRecommendation(containerId: string): void; + searchField(conf: any): void; + autocomplete(conf: any): void; + searchResults(conf: any): void; + segmentedSearchResults(conf: any): void; + facets(conf: any): void; + hierarchicalFacets(conf: any): void; + rangeFacets(conf: any): void; + filters(conf: any): void; + sortBy(conf: any): void; + pagination(conf: any): void; + loadMore(conf: any): void; + activeFilters(conf: any): void; + recommendations(conf: any): void; + search(keyword: string): void; + hideAutocomplete(): void; + clear(): void; + registerHandlebarsHelper(name: string, helper: Function): void; + registerHandlebarsPartial(name: string, partial: string): void; + } + + export const AUTOCOMPLETE_TYPE: { + SEARCH: string; + SUGGESTIONS: string; + CUSTOM_FIELDS: string; + }; + + export const FILTER_TYPE: { + CHECKBOX_GROUP: string; + RADIO_GROUP: string; + SELECT_LIST: string; + RANGE: string; + TABS: string; + TAGS: string; + }; + + export const SORTBY_TYPE: { + SELECT_LIST: string; + RADIO_GROUP: string; + }; + + export const LOAD_MORE_TYPE: { + BUTTON: string; + INFINITE_SCROLL: string; + }; + + export const RECOMMENDATION_TYPE: { + FREQUENTLY_BOUGHT_TOGETHER: string; + RELATED_ITEMS: string; + }; + + export const RANGE_FACETS_TYPE: { + CHECKBOX: string; + SLIDER: string; + }; + + export const Handlebars_runtime: any; +} diff --git a/package.json b/package.json index 4c2fb4d..ee655ad 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,6 @@ "name": "addsearch-search-ui", "version": "0.8.15", "description": "JavaScript library to develop Search UIs for the web", - "main": "./dist/addsearch-search-ui.min.js", - "jsdelivr": "./dist/addsearch-search-ui.min.js", - "scripts": { - "test": "node node_modules/.bin/mocha --recursive --require @babel/register --require ignore-styles", - "build": "npm run test && ./node_modules/webpack-cli/bin/cli.js", - "watch": "./node_modules/webpack-cli/bin/cli.js --watch --env development" - }, - "repository": { - "type": "git", - "url": "git://github.com/AddSearch/search-ui.git" - }, "keywords": [ "addsearch", "search", @@ -24,6 +13,11 @@ ], "homepage": "https://www.addsearch.com/", "bugs": "https://github.com/AddSearch/search-ui/issues", + "repository": { + "type": "git", + "url": "git://github.com/AddSearch/search-ui.git" + }, + "license": "MIT", "author": { "name": "AddSearch", "url": "https://www.addsearch.com" @@ -34,13 +28,24 @@ "url": "https://www.addsearch.com" } ], + "main": "./dist/addsearch-search-ui.min.js", + "jsdelivr": "./dist/addsearch-search-ui.min.js", + "types": "index.d.ts", + "files": [ + "dist", + "index.d.ts" + ], + "scripts": { + "build": "npm run test && ./node_modules/webpack-cli/bin/cli.js", + "test": "node node_modules/.bin/mocha --recursive --require @babel/register --require ignore-styles", + "watch": "./node_modules/webpack-cli/bin/cli.js --watch --env development" + }, "browserslist": [ "> 0.1%", "IE 9", "last 2 versions", "not dead" ], - "license": "MIT", "dependencies": { "es6-object-assign": "^1.1.0", "handlebars": "^4.7.7", From 95d800fb899ce356a07183cb0822412dacef238f Mon Sep 17 00:00:00 2001 From: janstoff Date: Tue, 15 Oct 2024 08:36:02 +0100 Subject: [PATCH 2/2] export as namespace --- index.d.ts | 66 +++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/index.d.ts b/index.d.ts index 34db507..36d4a2c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,5 +1,5 @@ declare module "addsearch-search-ui" { - export default class AddSearchUI { + class AddSearchUI { constructor(client: any, settings?: any); start(): void; executeSearch( @@ -30,40 +30,44 @@ declare module "addsearch-search-ui" { registerHandlebarsPartial(name: string, partial: string): void; } - export const AUTOCOMPLETE_TYPE: { - SEARCH: string; - SUGGESTIONS: string; - CUSTOM_FIELDS: string; - }; + namespace AddSearchUI { + const AUTOCOMPLETE_TYPE: { + SEARCH: string; + SUGGESTIONS: string; + CUSTOM_FIELDS: string; + }; - export const FILTER_TYPE: { - CHECKBOX_GROUP: string; - RADIO_GROUP: string; - SELECT_LIST: string; - RANGE: string; - TABS: string; - TAGS: string; - }; + const FILTER_TYPE: { + CHECKBOX_GROUP: string; + RADIO_GROUP: string; + SELECT_LIST: string; + RANGE: string; + TABS: string; + TAGS: string; + }; - export const SORTBY_TYPE: { - SELECT_LIST: string; - RADIO_GROUP: string; - }; + const SORTBY_TYPE: { + SELECT_LIST: string; + RADIO_GROUP: string; + }; - export const LOAD_MORE_TYPE: { - BUTTON: string; - INFINITE_SCROLL: string; - }; + const LOAD_MORE_TYPE: { + BUTTON: string; + INFINITE_SCROLL: string; + }; - export const RECOMMENDATION_TYPE: { - FREQUENTLY_BOUGHT_TOGETHER: string; - RELATED_ITEMS: string; - }; + const RECOMMENDATION_TYPE: { + FREQUENTLY_BOUGHT_TOGETHER: string; + RELATED_ITEMS: string; + }; - export const RANGE_FACETS_TYPE: { - CHECKBOX: string; - SLIDER: string; - }; + const RANGE_FACETS_TYPE: { + CHECKBOX: string; + SLIDER: string; + }; - export const Handlebars_runtime: any; + const Handlebars_runtime: any; + } + + export = AddSearchUI; }