From b5e3aa33d7a2be12884a920043620b36f71772a9 Mon Sep 17 00:00:00 2001 From: aminya Date: Fri, 13 Mar 2020 21:14:51 -0500 Subject: [PATCH 01/50] Create tsconfig.json --- src_src/tsconfig.json | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src_src/tsconfig.json diff --git a/src_src/tsconfig.json b/src_src/tsconfig.json new file mode 100644 index 0000000..ee0a446 --- /dev/null +++ b/src_src/tsconfig.json @@ -0,0 +1,38 @@ +{ + "compilerOptions": { + //// Linting Options - Uncomment options to get more features (usually more restrictive) + "strict": true, + "strictNullChecks": true, + // "forceConsistentCasingInFileNames": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noFallthroughCasesInSwitch": true, + "allowJs": true, + //// Compilation options + "declaration": true, + "emitDecoratorMetadata": true, + "esModuleInterop": true, + "experimentalDecorators": true, + "incremental": true, + "inlineSourceMap": true, + // "preserveConstEnums": true, + // "sourceMap": true, + "preserveSymlinks": true, + // "removeComments": true, + // "jsx": "react", + "jsxFactory": "etch.dom", + "lib": ["ES2018", "dom"], + "target": "ES2018", + "module": "commonjs", + "moduleResolution": "node", + // "noLib": false, + // "importHelpers": true, // if true you should add tslib to deps + // "skipLibCheck": false, + + "outDir": "../src/" + }, + "compileOnSave": false +} From c9e300619d76be107f35c5ddfde3668d8b4610e1 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 15 Mar 2020 02:28:26 -0500 Subject: [PATCH 02/50] Add dev deps + Add Eslint/TsLint + prettier config --- .eslintrc.json | 61 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 27 +++++++++++++++++--- src_src/tslint.json | 22 ++++++++++++++++ tslint.json | 22 ++++++++++++++++ 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 .eslintrc.json create mode 100644 src_src/tslint.json create mode 100644 tslint.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..55e9c8a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,61 @@ +{ + // JS Files + "root": true, + "env": { + "atomtest": true, + "es6": true, + "node": true, + "browser": true, + "jasmine": true + }, + "globals": { "atom": "readonly" }, + "parser": "babel-eslint", + "parserOptions": { + "ecmaFeatures": { "jsx": true }, + "ecmaVersion": 2018, + "sourceType": "module" + }, + "plugins": ["only-warn"], + "extends": ["eslint:recommended"], + "overrides": [ + { // Bundled node version with atom has an old ESLint + // TypeScript files + "files": ["**/*.ts", "**/*.tsx"], + "env": { + "atomtest": true, + "es6": true, + "node": true, + "browser": true + }, + "globals": { "atom": "readonly" }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { "jsx": true }, + "ecmaVersion": 2018, + "sourceType": "module" + }, + "plugins": ["@typescript-eslint", "only-warn"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/camelcase": "off", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/member-delimiter-style": "off", + "no-prototype-builtins": "off" + } + }, + { + // JSON files + "files": ["*.json"], + "plugins": ["json"], + "extends": ["plugin:json/recommended"], + "rules": { + "json/*": ["error", {"allowComments": true}] + } + } + ] +} diff --git a/package.json b/package.json index d809b22..c0933b4 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.7.2", "description": "A general-purpose select list for use in Atom packages", "main": "./src/select-list-view.js", + "files": [ + "lib/**/*" + ], "scripts": { "test": "atom --test test" }, @@ -10,15 +13,33 @@ "license": "MIT", "atomTestRunner": "atom-mocha-test-runner", "devDependencies": { - "atom-mocha-test-runner": "^0.3.0", - "sinon": "^2.1.0" + "atom-mocha-test-runner": "^1.2.0", + "sinon": "^9.0.2", + "typescript": "^3.8.3", + "@types/atom": "^1.40.2", + "@types/fuzzaldrin": "^2.1.2", + "eslint": "latest", + "@typescript-eslint/eslint-plugin": "latest", + "@typescript-eslint/parser": "latest", + "babel-eslint": "latest", + "eslint-plugin-json": "latest", + "eslint-plugin-only-warn": "latest", + "prettier": "latest", + "tslint": "latest", + "tslint-config-prettier": "latest" }, "dependencies": { - "etch": "^0.12.6", + "etch": "^0.14.0", "fuzzaldrin": "^2.1.0" }, "repository": { "type": "git", "url": "git+https://github.com/atom/atom-select-list.git" + }, + "prettier": { + "printWidth": 120, + "semi": false, + "tabWidth": 2, + "singleQuote": true } } diff --git a/src_src/tslint.json b/src_src/tslint.json new file mode 100644 index 0000000..81d4bdd --- /dev/null +++ b/src_src/tslint.json @@ -0,0 +1,22 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended", + "tslint-config-prettier" + ], + "jsRules": {}, + "rules": { + "array-type": false, + "only-arrow-functions": false, + "ordered-imports": false, + "no-console": false, + "curly": false, + "variable-name": false, + "arrow-parens": false, + "object-literal-sort-keys": false, + "object-literal-shorthand": false, + "member-access": false, + "interface-name": false + }, + "rulesDirectory": [] +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..81d4bdd --- /dev/null +++ b/tslint.json @@ -0,0 +1,22 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended", + "tslint-config-prettier" + ], + "jsRules": {}, + "rules": { + "array-type": false, + "only-arrow-functions": false, + "ordered-imports": false, + "no-console": false, + "curly": false, + "variable-name": false, + "arrow-parens": false, + "object-literal-sort-keys": false, + "object-literal-shorthand": false, + "member-access": false, + "interface-name": false + }, + "rulesDirectory": [] +} From 06f8a4edc2fce82fe17a3161fd3fab20aeafe77c Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 07:25:22 -0500 Subject: [PATCH 03/50] Add scripts up scripts --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index c0933b4..7ddeb56 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,11 @@ "lib/**/*" ], "scripts": { + "typescript": "tsc -p ./src_src/tsconfig.json || echo 'tsc is done'", + "prettier_src": "prettier --write ./src_src/**/*.ts", + "prettier_out": "prettier --write ./src/**/*.js", + "build": "npm run typescript -s & npm run prettier_out -s", + "lint": "eslint . --ext js,ts,json", "test": "atom --test test" }, "author": "", From 361cbb9474c82eb47f55dd14deeee6c0d2727bba Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 8 May 2020 07:12:39 -0500 Subject: [PATCH 04/50] js-to-ts-converter . --- src/select-list-view.js => src_src/select-list-view.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) rename src/select-list-view.js => src_src/select-list-view.ts (98%) diff --git a/src/select-list-view.js b/src_src/select-list-view.ts similarity index 98% rename from src/select-list-view.js rename to src_src/select-list-view.ts index f55d038..1be8ed2 100644 --- a/src/select-list-view.js +++ b/src_src/select-list-view.ts @@ -286,7 +286,7 @@ module.exports = class SelectListView { this.confirmSelection() } - computeItems (updateComponent) { + computeItems (updateComponent?) { this.listItems = null if (this.visibilityObserver) this.visibilityObserver.disconnect() const filterFn = this.props.filter || this.fuzzyFilter.bind(this) @@ -301,7 +301,7 @@ module.exports = class SelectListView { this.selectIndex(this.props.initialSelectionIndex, updateComponent) } - fuzzyFilter (items, query) { + fuzzyFilter (items, query?) { if (query.length === 0) { return items } else { @@ -414,6 +414,11 @@ module.exports = class SelectListView { } class ListItemView { + public selected: any; + public onclick: any; + public element: any; + public domEventsDisposable: any; + constructor (props) { this.mouseDown = this.mouseDown.bind(this) this.mouseUp = this.mouseUp.bind(this) From 9642dda24a010a252d539dba72a3f2c50dc15dee Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 08:00:01 -0500 Subject: [PATCH 05/50] import instead of require for atom/fuzzaldrin --- src_src/select-list-view.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 1be8ed2..f9b8399 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -1,7 +1,7 @@ -const {Disposable, CompositeDisposable, TextEditor} = require('atom') const etch = require('etch') +import {Disposable, CompositeDisposable, TextEditor} from 'atom' const $ = etch.dom -const fuzzaldrin = require('fuzzaldrin') +import fuzzaldrin from 'fuzzaldrin' module.exports = class SelectListView { static setScheduler (scheduler) { From ef4bba66a18b33619d2dc6d82b4a8ab53bee0811 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 07:58:39 -0500 Subject: [PATCH 06/50] global not needed for atom --- src_src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index f9b8399..8941a5c 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -84,7 +84,7 @@ module.exports = class SelectListView { } registerAtomCommands () { - return global.atom.commands.add(this.element, { + return atom.commands.add(this.element, { 'core:move-up': (event) => { this.selectPrevious() event.stopPropagation() From db55db1e8252a397a5716c863faddddeb019d6e5 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 07:58:28 -0500 Subject: [PATCH 07/50] SelectListView members + SelectListProperties interface Update select-list-view.ts Update select-list-view.ts Update select-list-view.ts Update select-list-view.ts Update select-list-view.ts Update select-list-view.ts object | string object | string Update select-list-view.ts --- src_src/select-list-view.ts | 110 +++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 8 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 8941a5c..2fdde3a 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -1,9 +1,101 @@ const etch = require('etch') -import {Disposable, CompositeDisposable, TextEditor} from 'atom' +import {Disposable, CompositeDisposable, TextEditor } from 'atom' const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' +declare interface SelectListProperties { + + // an array containing the objects you want to show in the select list. + items: Array + + // a function that is called whenever an item needs to be displayed. + // + // `options: { selected: boolean, index: number, visible: boolean }` + // + // - `selected`: indicating whether item is selected or not. + // - `index`: item's index. + // - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. + elementForItem: (item: object | string, options: { selected: boolean, index: number, visible: boolean }) => HTMLElement // TODO: HTMLElement + + // (Optional) the number of maximum items that are shown. + maxResults?: number + + // (Optional) a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results. + filter?: (items: Array, query: string) => Array + + // (Optional) when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them. + filterKeyForItem?: (item: object | string) => string + + // (Optional) a function that allows to apply a transformation to the user query and whose return value will be used to filter items. + filterQuery?: (query: string) => string + + // (Optional) a string that will replace the contents of the query editor. + query?: string + + // (Optional) a boolean indicating whether the query text should be selected or not. + selectQuery?: boolean + + // (Optional) a function that allows to change the order in which items are shown. + order?: (item1: object | string, item2: object | string) => number + + // (Optional) a string shown when the list is empty. + emptyMessage?: string + + // (Optional) a string that needs to be set when you want to notify the user that an error occurred. + errorMessage?: string + + // (Optional) a string that needs to be set when you want to provide some information to the user. + infoMessage?: string + + // (Optional) a string that needs to be set when you are loading items in the background. + loadingMessage?: string + + // (Optional) a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far). + loadingBadge?: string | number + + // (Optional) an array of strings that will be added as class names to the items element. + itemsClassList?: Array + + // (Optional) the index of the item to initially select and automatically select after query changes; defaults to 0. + initialSelectionIndex?: number + + // (Optional) a function that is called when the query changes. + didChangeQuery?: (query: string) => void + + // (Optional) a function that is called when the selected item changes. + didChangeSelection?: (item: object | string) => void + + // (Optional) a function that is called when the user clicks or presses Enter on an item. + didConfirmSelection?: (item: object | string) => void + + // (Optional) a function that is called when the user presses Enter but the list is empty. + didConfirmEmptySelection?: () => void + + // (Optional) a function that is called when the user presses Esc or the list loses focus. + didCancelSelection?: () => void + + // (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. + initiallyVisibleItemCount?: number + + skipCommandsRegistration: boolean +} + module.exports = class SelectListView { + + // When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties + props: SelectListProperties + + // an array containing the objects you want to show in the select list. + items: Array // TODO: Added initializer! Either fix this.items or assign it in constructor + + private disposables: CompositeDisposable + private element: EtchElement + private didClickItemsList: boolean + private visibilityObserver: IntersectionObserver + private listItems: any[] | null + private selectionIndex: number | undefined + private refs: any; + static setScheduler (scheduler) { etch.setScheduler(scheduler) } @@ -12,7 +104,7 @@ module.exports = class SelectListView { return etch.getScheduler() } - constructor (props) { + constructor (props: SelectListProperties) { this.props = props if (!this.props.hasOwnProperty('initialSelectionIndex')) { this.props.initialSelectionIndex = 0 @@ -112,7 +204,9 @@ module.exports = class SelectListView { }) } - update (props = {}) { + update (props: SelectListProperties = {}) { + // TODO: default value {} + let shouldComputeItems = false if (props.hasOwnProperty('items')) { @@ -384,7 +478,7 @@ module.exports = class SelectListView { } } - selectItem (item) { + selectItem (item: object | string) { const index = this.items.indexOf(item) if (index === -1) { throw new Error('Cannot select the specified item because it does not exist.') @@ -414,10 +508,10 @@ module.exports = class SelectListView { } class ListItemView { - public selected: any; - public onclick: any; - public element: any; - public domEventsDisposable: any; + public element: EtchElement + public selected: boolean + public onclick: () => void + public domEventsDisposable: Disposable constructor (props) { this.mouseDown = this.mouseDown.bind(this) From c3bf30e9505a91cc3bcac0be1d6b8c6c68d53bac Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:06:51 -0500 Subject: [PATCH 08/50] etch type temporarily --- src_src/select-list-view.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 2fdde3a..00cded7 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -3,6 +3,9 @@ import {Disposable, CompositeDisposable, TextEditor } from 'atom' const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' +// TODO: etch types +type EtchElement = HTMLElement + declare interface SelectListProperties { // an array containing the objects you want to show in the select list. @@ -15,7 +18,7 @@ declare interface SelectListProperties { // - `selected`: indicating whether item is selected or not. // - `index`: item's index. // - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. - elementForItem: (item: object | string, options: { selected: boolean, index: number, visible: boolean }) => HTMLElement // TODO: HTMLElement + elementForItem: (item: object | string, options: { selected: boolean, index: number, visible: boolean }) => EtchElement // TODO: HTMLElement // (Optional) the number of maximum items that are shown. maxResults?: number From 7a6850ae352b2b1e60d19142d6c8a1c49578cb63 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:08:09 -0500 Subject: [PATCH 09/50] TODO: fix redundant returns in methods --- src_src/select-list-view.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 00cded7..5a8685c 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -1,3 +1,5 @@ +// TODO: fix redundant returns in methods + const etch = require('etch') import {Disposable, CompositeDisposable, TextEditor } from 'atom' const $ = etch.dom From 89a593a7e4a85429fe5028b84f6e86f3d8ba2fe6 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:08:22 -0500 Subject: [PATCH 10/50] this.items = props.items + TODO --- src_src/select-list-view.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 5a8685c..6916204 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -111,6 +111,8 @@ module.exports = class SelectListView { constructor (props: SelectListProperties) { this.props = props + this.items = props.items // TODO: Added initializer! Either fix this.items or assign it in constructor + if (!this.props.hasOwnProperty('initialSelectionIndex')) { this.props.initialSelectionIndex = 0 } From fc980cd2428e169d3f445b78d910c9b463178f20 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:09:00 -0500 Subject: [PATCH 11/50] CommandEvent --- src_src/select-list-view.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 6916204..5c6e780 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -1,7 +1,7 @@ // TODO: fix redundant returns in methods const etch = require('etch') -import {Disposable, CompositeDisposable, TextEditor } from 'atom' +import {Disposable, CompositeDisposable, TextEditor, CommandEvent } from 'atom' const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' @@ -184,27 +184,27 @@ module.exports = class SelectListView { registerAtomCommands () { return atom.commands.add(this.element, { - 'core:move-up': (event) => { + 'core:move-up': (event: CommandEvent) => { this.selectPrevious() event.stopPropagation() }, - 'core:move-down': (event) => { + 'core:move-down': (event: CommandEvent) => { this.selectNext() event.stopPropagation() }, - 'core:move-to-top': (event) => { + 'core:move-to-top': (event: CommandEvent) => { this.selectFirst() event.stopPropagation() }, - 'core:move-to-bottom': (event) => { + 'core:move-to-bottom': (event: CommandEvent) => { this.selectLast() event.stopPropagation() }, - 'core:confirm': (event) => { + 'core:confirm': (event: CommandEvent) => { this.confirmSelection() event.stopPropagation() }, - 'core:cancel': (event) => { + 'core:cancel': (event: CommandEvent) => { this.cancelSelection() event.stopPropagation() } From 84471b7945b9673c9776cb6bd07490d7133bfb3c Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:09:25 -0500 Subject: [PATCH 12/50] itemIndex: number --- src_src/select-list-view.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 5c6e780..0bf730f 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -382,7 +382,7 @@ module.exports = class SelectListView { this.computeItems() } - didClickItem (itemIndex) { + didClickItem (itemIndex: number) { this.selectIndex(itemIndex) this.confirmSelection() } @@ -424,7 +424,7 @@ module.exports = class SelectListView { return this.items[this.selectionIndex] } - renderItemAtIndex (index) { + renderItemAtIndex (index: number) { const item = this.items[index] const selected = this.getSelectedItem() === item const component = this.listItems[index].component @@ -458,7 +458,7 @@ module.exports = class SelectListView { return this.selectIndex(undefined) } - selectIndex (index, updateComponent = true) { + selectIndex (index: number, updateComponent = true) { if (index >= this.items.length) { index = 0 } else if (index < 0) { From fb0e26518c2f022e3702f5f7bf7a4a1ac239d4d2 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:10:47 -0500 Subject: [PATCH 13/50] updateComponent?: boolean --- src_src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 0bf730f..1e813b8 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -387,7 +387,7 @@ module.exports = class SelectListView { this.confirmSelection() } - computeItems (updateComponent?) { + computeItems (updateComponent?: boolean) { this.listItems = null if (this.visibilityObserver) this.visibilityObserver.disconnect() const filterFn = this.props.filter || this.fuzzyFilter.bind(this) From 3aae572fa14f0dd5118bcdf609bbf2d2e33d58cc Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:21:05 -0500 Subject: [PATCH 14/50] fuzzyFilter types --- src_src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 1e813b8..9920e0f 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -402,7 +402,7 @@ module.exports = class SelectListView { this.selectIndex(this.props.initialSelectionIndex, updateComponent) } - fuzzyFilter (items, query?) { + fuzzyFilter (items: Array, query?: string) { if (query.length === 0) { return items } else { From bc68e9c462b6254aef86dd84b33de76c1545fe5b Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:21:18 -0500 Subject: [PATCH 15/50] const score --- src_src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 9920e0f..03159a7 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -409,7 +409,7 @@ module.exports = class SelectListView { const scoredItems = [] for (const item of items) { const string = this.props.filterKeyForItem ? this.props.filterKeyForItem(item) : item - let score = fuzzaldrin.score(string, query) + const score = fuzzaldrin.score(string, query) if (score > 0) { scoredItems.push({item, score}) } From def1ee72885d2b7dccf3509a5848e674b398b48c Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:22:22 -0500 Subject: [PATCH 16/50] props types --- src_src/select-list-view.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index 03159a7..ef919ab 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -520,7 +520,7 @@ class ListItemView { public onclick: () => void public domEventsDisposable: Disposable - constructor (props) { + constructor (props: { element: EtchElement ; selected: boolean; onclick: () => void } ) { this.mouseDown = this.mouseDown.bind(this) this.mouseUp = this.mouseUp.bind(this) this.didClick = this.didClick.bind(this) @@ -559,7 +559,7 @@ class ListItemView { this.domEventsDisposable.dispose() } - update (props) { + update (props: { element: EtchElement ; selected: boolean; onclick: () => void }) { this.element.removeEventListener('mousedown', this.mouseDown) this.element.removeEventListener('mouseup', this.mouseUp) this.element.removeEventListener('click', this.didClick) From b969819fa49f480f2b83a9e1a23b1ced4fc776f2 Mon Sep 17 00:00:00 2001 From: aminya Date: Sun, 29 Mar 2020 10:22:29 -0500 Subject: [PATCH 17/50] MouseEvent --- src_src/select-list-view.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index ef919ab..d995000 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -541,15 +541,15 @@ class ListItemView { etch.getScheduler().updateDocument(this.scrollIntoViewIfNeeded.bind(this)) } - mouseDown (event) { + mouseDown (event: MouseEvent) { event.preventDefault() } - mouseUp (event) { + mouseUp (event: MouseEvent) { event.preventDefault() } - didClick (event) { + didClick (event: MouseEvent) { event.preventDefault() this.onclick() } From fae6b9ab429d4552d4d2c4ee0d012ae159b8d3a2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 16:35:34 -0600 Subject: [PATCH 18/50] export update --- src_src/select-list-view.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index d995000..a10ed66 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -85,7 +85,7 @@ declare interface SelectListProperties { skipCommandsRegistration: boolean } -module.exports = class SelectListView { +export default class SelectListView { // When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties props: SelectListProperties @@ -112,7 +112,7 @@ module.exports = class SelectListView { constructor (props: SelectListProperties) { this.props = props this.items = props.items // TODO: Added initializer! Either fix this.items or assign it in constructor - + if (!this.props.hasOwnProperty('initialSelectionIndex')) { this.props.initialSelectionIndex = 0 } From 9ee731d5dc41c98b8e2c143b82e017acef12a581 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 16:26:38 -0600 Subject: [PATCH 19/50] JSDoc style doc strings --- src_src/select-list-view.ts | 91 +++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/src_src/select-list-view.ts b/src_src/select-list-view.ts index a10ed66..744a4a2 100644 --- a/src_src/select-list-view.ts +++ b/src_src/select-list-view.ts @@ -1,7 +1,7 @@ // TODO: fix redundant returns in methods const etch = require('etch') -import {Disposable, CompositeDisposable, TextEditor, CommandEvent } from 'atom' +import { Disposable, CompositeDisposable, TextEditor, CommandEvent } from 'atom' const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' @@ -9,89 +9,92 @@ import fuzzaldrin from 'fuzzaldrin' type EtchElement = HTMLElement declare interface SelectListProperties { - - // an array containing the objects you want to show in the select list. + /** an array containing the objects you want to show in the select list. */ items: Array - // a function that is called whenever an item needs to be displayed. - // - // `options: { selected: boolean, index: number, visible: boolean }` - // - // - `selected`: indicating whether item is selected or not. - // - `index`: item's index. - // - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. - elementForItem: (item: object | string, options: { selected: boolean, index: number, visible: boolean }) => EtchElement // TODO: HTMLElement - - // (Optional) the number of maximum items that are shown. + /** + * a function that is called whenever an item needs to be displayed. + * + * `options: { selected: boolean, index: number, visible: boolean }` + * + * - `selected`: indicating whether item is selected or not. + * - `index`: item's index. + * - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. + */ + elementForItem: ( + item: object | string, + options: { selected: boolean; index: number; visible: boolean } + ) => EtchElement // TODO: HTMLElement + + /** (Optional) the number of maximum items that are shown. */ maxResults?: number - // (Optional) a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results. + /** (Optional) a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results. */ filter?: (items: Array, query: string) => Array - // (Optional) when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them. + /** (Optional) when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them. */ filterKeyForItem?: (item: object | string) => string - // (Optional) a function that allows to apply a transformation to the user query and whose return value will be used to filter items. + /** (Optional) a function that allows to apply a transformation to the user query and whose return value will be used to filter items. */ filterQuery?: (query: string) => string - // (Optional) a string that will replace the contents of the query editor. + /** (Optional) a string that will replace the contents of the query editor. */ query?: string - // (Optional) a boolean indicating whether the query text should be selected or not. + /** (Optional) a boolean indicating whether the query text should be selected or not. */ selectQuery?: boolean - // (Optional) a function that allows to change the order in which items are shown. + /** (Optional) a function that allows to change the order in which items are shown. */ order?: (item1: object | string, item2: object | string) => number - // (Optional) a string shown when the list is empty. + /** (Optional) a string shown when the list is empty. */ emptyMessage?: string - // (Optional) a string that needs to be set when you want to notify the user that an error occurred. + /** (Optional) a string that needs to be set when you want to notify the user that an error occurred. */ errorMessage?: string - // (Optional) a string that needs to be set when you want to provide some information to the user. + /** (Optional) a string that needs to be set when you want to provide some information to the user. */ infoMessage?: string - // (Optional) a string that needs to be set when you are loading items in the background. + /** (Optional) a string that needs to be set when you are loading items in the background. */ loadingMessage?: string - // (Optional) a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far). + /** (Optional) a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far). */ loadingBadge?: string | number - // (Optional) an array of strings that will be added as class names to the items element. + /** (Optional) an array of strings that will be added as class names to the items element. */ itemsClassList?: Array - // (Optional) the index of the item to initially select and automatically select after query changes; defaults to 0. + /** (Optional) the index of the item to initially select and automatically select after query changes; defaults to 0. */ initialSelectionIndex?: number - // (Optional) a function that is called when the query changes. + /** (Optional) a function that is called when the query changes. */ didChangeQuery?: (query: string) => void - // (Optional) a function that is called when the selected item changes. + /** (Optional) a function that is called when the selected item changes. */ didChangeSelection?: (item: object | string) => void - // (Optional) a function that is called when the user clicks or presses Enter on an item. + /** (Optional) a function that is called when the user clicks or presses Enter on an item. */ didConfirmSelection?: (item: object | string) => void - // (Optional) a function that is called when the user presses Enter but the list is empty. + /** (Optional) a function that is called when the user presses Enter but the list is empty. */ didConfirmEmptySelection?: () => void - // (Optional) a function that is called when the user presses Esc or the list loses focus. + /** (Optional) a function that is called when the user presses Esc or the list loses focus. */ didCancelSelection?: () => void - // (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. + /** (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. */ initiallyVisibleItemCount?: number skipCommandsRegistration: boolean } export default class SelectListView { - - // When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties + /** When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties */ props: SelectListProperties - // an array containing the objects you want to show in the select list. - items: Array // TODO: Added initializer! Either fix this.items or assign it in constructor + /** an array containing the objects you want to show in the select list. */ + items: Array // TODO: Added initializer! Either fix this.items or assign it in constructor private disposables: CompositeDisposable private element: EtchElement @@ -131,10 +134,12 @@ export default class SelectListView { const didLoseFocus = this.didLoseFocus.bind(this) editorElement.addEventListener('blur', didLoseFocus) - // When clicking the scrollbar of the items list, a blur event will be triggered - // on the query editor element, but we don't want to treat that as a cancellation. - // This mousedown listener allows us to detect this case and restore focus to the - // query editor. This is based on https://stackoverflow.com/a/1480178. + /** + * When clicking the scrollbar of the items list, a blur event will be triggered + * on the query editor element, but we don't want to treat that as a cancellation. + * This mousedown listener allows us to detect this case and restore focus to the + * query editor. This is based on https://stackoverflow.com/a/1480178. + */ this.didClickItemsList = false this.element.addEventListener('mousedown', event => { if (event.target === this.refs.items) { @@ -212,7 +217,7 @@ export default class SelectListView { } update (props: SelectListProperties = {}) { - // TODO: default value {} + /** TODO: default value {} */ let shouldComputeItems = false @@ -237,8 +242,8 @@ export default class SelectListView { } if (props.hasOwnProperty('query')) { - // Items will be recomputed as part of the change event handler, so we - // don't need to recompute them again at the end of this function. + /** Items will be recomputed as part of the change event handler, so we */ + /** don't need to recompute them again at the end of this function. */ this.refs.queryEditor.setText(props.query) shouldComputeItems = false } From 533da241748ef7a3cd4000f16807560acd84a325 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 8 May 2020 07:09:33 -0500 Subject: [PATCH 20/50] Rename src_src to src - output in lib --- .gitignore | 1 + package.json | 13 +++++++------ {src_src => src}/select-list-view.ts | 0 {src_src => src}/tsconfig.json | 2 +- {src_src => src}/tslint.json | 0 test/select-list-view.test.js | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) rename {src_src => src}/select-list-view.ts (100%) rename {src_src => src}/tsconfig.json (97%) rename {src_src => src}/tslint.json (100%) diff --git a/.gitignore b/.gitignore index e2979fa..21d44dc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .DS_Store npm-debug.log package-lock.json +lib \ No newline at end of file diff --git a/package.json b/package.json index 7ddeb56..34d3437 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,18 @@ "name": "atom-select-list", "version": "0.7.2", "description": "A general-purpose select list for use in Atom packages", - "main": "./src/select-list-view.js", + "main": "lib/select-list-view.js", "files": [ "lib/**/*" ], "scripts": { - "typescript": "tsc -p ./src_src/tsconfig.json || echo 'tsc is done'", - "prettier_src": "prettier --write ./src_src/**/*.ts", - "prettier_out": "prettier --write ./src/**/*.js", - "build": "npm run typescript -s & npm run prettier_out -s", + "typescript": "tsc -p src/tsconfig.json || echo 'tsc is done'", + "prettier_src": "prettier --write src/*.ts", + "prettier_out": "prettier --write lib/*.js", + "build": "npm run typescript -s", "lint": "eslint . --ext js,ts,json", - "test": "atom --test test" + "test": "atom --test test", + "prepare": "npm run build" }, "author": "", "license": "MIT", diff --git a/src_src/select-list-view.ts b/src/select-list-view.ts similarity index 100% rename from src_src/select-list-view.ts rename to src/select-list-view.ts diff --git a/src_src/tsconfig.json b/src/tsconfig.json similarity index 97% rename from src_src/tsconfig.json rename to src/tsconfig.json index ee0a446..fa4d2fb 100644 --- a/src_src/tsconfig.json +++ b/src/tsconfig.json @@ -32,7 +32,7 @@ // "importHelpers": true, // if true you should add tslib to deps // "skipLibCheck": false, - "outDir": "../src/" + "outDir": "../lib/" }, "compileOnSave": false } diff --git a/src_src/tslint.json b/src/tslint.json similarity index 100% rename from src_src/tslint.json rename to src/tslint.json diff --git a/test/select-list-view.test.js b/test/select-list-view.test.js index 6d45d23..df26db6 100644 --- a/test/select-list-view.test.js +++ b/test/select-list-view.test.js @@ -4,7 +4,7 @@ const assert = require('assert') const etch = require('etch') const sinon = require('sinon') const sandbox = sinon.sandbox.create() -const SelectListView = require('../src/select-list-view') +const SelectListView = require('../lib/select-list-view') describe('SelectListView', () => { let containerNode = null From b2722a9ad0255c17aff085ada93cfe469cd7451d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 8 May 2020 06:36:31 -0500 Subject: [PATCH 21/50] separate file for SelectListProperties --- src/select-list-properties.ts | 82 ++++++++++++++++++++++++++++++++++ src/select-list-view.ts | 83 +---------------------------------- 2 files changed, 84 insertions(+), 81 deletions(-) create mode 100644 src/select-list-properties.ts diff --git a/src/select-list-properties.ts b/src/select-list-properties.ts new file mode 100644 index 0000000..d065aa4 --- /dev/null +++ b/src/select-list-properties.ts @@ -0,0 +1,82 @@ +import { EtchElement } from './select-list-view' // TODO: etch types + +export interface SelectListProperties { + /** an array containing the objects you want to show in the select list. */ + items: Array + + /** + * a function that is called whenever an item needs to be displayed. + * + * `options: { selected: boolean, index: number, visible: boolean }` + * + * - `selected`: indicating whether item is selected or not. + * - `index`: item's index. + * - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. + */ + elementForItem: ( + item: object | string, + options: { selected: boolean; index: number; visible: boolean } + ) => EtchElement // TODO: HTMLElement + + /** (Optional) the number of maximum items that are shown. */ + maxResults?: number + + /** (Optional) a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results. */ + filter?: (items: Array, query: string) => Array + + /** (Optional) when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them. */ + filterKeyForItem?: (item: object | string) => string + + /** (Optional) a function that allows to apply a transformation to the user query and whose return value will be used to filter items. */ + filterQuery?: (query: string) => string + + /** (Optional) a string that will replace the contents of the query editor. */ + query?: string + + /** (Optional) a boolean indicating whether the query text should be selected or not. */ + selectQuery?: boolean + + /** (Optional) a function that allows to change the order in which items are shown. */ + order?: (item1: object | string, item2: object | string) => number + + /** (Optional) a string shown when the list is empty. */ + emptyMessage?: string + + /** (Optional) a string that needs to be set when you want to notify the user that an error occurred. */ + errorMessage?: string + + /** (Optional) a string that needs to be set when you want to provide some information to the user. */ + infoMessage?: string + + /** (Optional) a string that needs to be set when you are loading items in the background. */ + loadingMessage?: string + + /** (Optional) a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far). */ + loadingBadge?: string | number + + /** (Optional) an array of strings that will be added as class names to the items element. */ + itemsClassList?: Array + + /** (Optional) the index of the item to initially select and automatically select after query changes; defaults to 0. */ + initialSelectionIndex?: number + + /** (Optional) a function that is called when the query changes. */ + didChangeQuery?: (query: string) => void + + /** (Optional) a function that is called when the selected item changes. */ + didChangeSelection?: (item: object | string) => void + + /** (Optional) a function that is called when the user clicks or presses Enter on an item. */ + didConfirmSelection?: (item: object | string) => void + + /** (Optional) a function that is called when the user presses Enter but the list is empty. */ + didConfirmEmptySelection?: () => void + + /** (Optional) a function that is called when the user presses Esc or the list loses focus. */ + didCancelSelection?: () => void + + /** (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. */ + initiallyVisibleItemCount?: number + + skipCommandsRegistration: boolean +} diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 744a4a2..a148ba3 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -6,88 +6,9 @@ const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' // TODO: etch types -type EtchElement = HTMLElement +export type EtchElement = HTMLElement -declare interface SelectListProperties { - /** an array containing the objects you want to show in the select list. */ - items: Array - - /** - * a function that is called whenever an item needs to be displayed. - * - * `options: { selected: boolean, index: number, visible: boolean }` - * - * - `selected`: indicating whether item is selected or not. - * - `index`: item's index. - * - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. - */ - elementForItem: ( - item: object | string, - options: { selected: boolean; index: number; visible: boolean } - ) => EtchElement // TODO: HTMLElement - - /** (Optional) the number of maximum items that are shown. */ - maxResults?: number - - /** (Optional) a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results. */ - filter?: (items: Array, query: string) => Array - - /** (Optional) when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them. */ - filterKeyForItem?: (item: object | string) => string - - /** (Optional) a function that allows to apply a transformation to the user query and whose return value will be used to filter items. */ - filterQuery?: (query: string) => string - - /** (Optional) a string that will replace the contents of the query editor. */ - query?: string - - /** (Optional) a boolean indicating whether the query text should be selected or not. */ - selectQuery?: boolean - - /** (Optional) a function that allows to change the order in which items are shown. */ - order?: (item1: object | string, item2: object | string) => number - - /** (Optional) a string shown when the list is empty. */ - emptyMessage?: string - - /** (Optional) a string that needs to be set when you want to notify the user that an error occurred. */ - errorMessage?: string - - /** (Optional) a string that needs to be set when you want to provide some information to the user. */ - infoMessage?: string - - /** (Optional) a string that needs to be set when you are loading items in the background. */ - loadingMessage?: string - - /** (Optional) a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far). */ - loadingBadge?: string | number - - /** (Optional) an array of strings that will be added as class names to the items element. */ - itemsClassList?: Array - - /** (Optional) the index of the item to initially select and automatically select after query changes; defaults to 0. */ - initialSelectionIndex?: number - - /** (Optional) a function that is called when the query changes. */ - didChangeQuery?: (query: string) => void - - /** (Optional) a function that is called when the selected item changes. */ - didChangeSelection?: (item: object | string) => void - - /** (Optional) a function that is called when the user clicks or presses Enter on an item. */ - didConfirmSelection?: (item: object | string) => void - - /** (Optional) a function that is called when the user presses Enter but the list is empty. */ - didConfirmEmptySelection?: () => void - - /** (Optional) a function that is called when the user presses Esc or the list loses focus. */ - didCancelSelection?: () => void - - /** (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. */ - initiallyVisibleItemCount?: number - - skipCommandsRegistration: boolean -} +import { SelectListProperties } from './select-list-properties' export default class SelectListView { /** When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties */ From 93718c21c3a0f34105eabc2212afcb06aac50dcf Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 16:30:13 -0600 Subject: [PATCH 22/50] Remoev tslint, eslint, prettier --- .eslintrc.json | 61 ------------------------------------------------- package.json | 20 +--------------- src/tslint.json | 22 ------------------ tslint.json | 22 ------------------ 4 files changed, 1 insertion(+), 124 deletions(-) delete mode 100644 .eslintrc.json delete mode 100644 src/tslint.json delete mode 100644 tslint.json diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 55e9c8a..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - // JS Files - "root": true, - "env": { - "atomtest": true, - "es6": true, - "node": true, - "browser": true, - "jasmine": true - }, - "globals": { "atom": "readonly" }, - "parser": "babel-eslint", - "parserOptions": { - "ecmaFeatures": { "jsx": true }, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": ["only-warn"], - "extends": ["eslint:recommended"], - "overrides": [ - { // Bundled node version with atom has an old ESLint - // TypeScript files - "files": ["**/*.ts", "**/*.tsx"], - "env": { - "atomtest": true, - "es6": true, - "node": true, - "browser": true - }, - "globals": { "atom": "readonly" }, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaFeatures": { "jsx": true }, - "ecmaVersion": 2018, - "sourceType": "module" - }, - "plugins": ["@typescript-eslint", "only-warn"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/camelcase": "off", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/member-delimiter-style": "off", - "no-prototype-builtins": "off" - } - }, - { - // JSON files - "files": ["*.json"], - "plugins": ["json"], - "extends": ["plugin:json/recommended"], - "rules": { - "json/*": ["error", {"allowComments": true}] - } - } - ] -} diff --git a/package.json b/package.json index 34d3437..5d14357 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,7 @@ ], "scripts": { "typescript": "tsc -p src/tsconfig.json || echo 'tsc is done'", - "prettier_src": "prettier --write src/*.ts", - "prettier_out": "prettier --write lib/*.js", "build": "npm run typescript -s", - "lint": "eslint . --ext js,ts,json", "test": "atom --test test", "prepare": "npm run build" }, @@ -23,16 +20,7 @@ "sinon": "^9.0.2", "typescript": "^3.8.3", "@types/atom": "^1.40.2", - "@types/fuzzaldrin": "^2.1.2", - "eslint": "latest", - "@typescript-eslint/eslint-plugin": "latest", - "@typescript-eslint/parser": "latest", - "babel-eslint": "latest", - "eslint-plugin-json": "latest", - "eslint-plugin-only-warn": "latest", - "prettier": "latest", - "tslint": "latest", - "tslint-config-prettier": "latest" + "@types/fuzzaldrin": "^2.1.2" }, "dependencies": { "etch": "^0.14.0", @@ -41,11 +29,5 @@ "repository": { "type": "git", "url": "git+https://github.com/atom/atom-select-list.git" - }, - "prettier": { - "printWidth": 120, - "semi": false, - "tabWidth": 2, - "singleQuote": true } } diff --git a/src/tslint.json b/src/tslint.json deleted file mode 100644 index 81d4bdd..0000000 --- a/src/tslint.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "defaultSeverity": "error", - "extends": [ - "tslint:recommended", - "tslint-config-prettier" - ], - "jsRules": {}, - "rules": { - "array-type": false, - "only-arrow-functions": false, - "ordered-imports": false, - "no-console": false, - "curly": false, - "variable-name": false, - "arrow-parens": false, - "object-literal-sort-keys": false, - "object-literal-shorthand": false, - "member-access": false, - "interface-name": false - }, - "rulesDirectory": [] -} diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 81d4bdd..0000000 --- a/tslint.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "defaultSeverity": "error", - "extends": [ - "tslint:recommended", - "tslint-config-prettier" - ], - "jsRules": {}, - "rules": { - "array-type": false, - "only-arrow-functions": false, - "ordered-imports": false, - "no-console": false, - "curly": false, - "variable-name": false, - "arrow-parens": false, - "object-literal-sort-keys": false, - "object-literal-shorthand": false, - "member-access": false, - "interface-name": false - }, - "rulesDirectory": [] -} From beb3f3f2ba550fd86a0f821f624e16c66436c657 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 16:31:34 -0600 Subject: [PATCH 23/50] Update tsconfig --- src/tsconfig.json | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/tsconfig.json b/src/tsconfig.json index fa4d2fb..11ff569 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,38 +1,31 @@ { "compilerOptions": { - //// Linting Options - Uncomment options to get more features (usually more restrictive) - "strict": true, - "strictNullChecks": true, - // "forceConsistentCasingInFileNames": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noImplicitAny": true, - "noImplicitThis": true, - "noFallthroughCasesInSwitch": true, - "allowJs": true, - //// Compilation options + "strict": false, + "strictNullChecks": false, + "noUnusedLocals": false, + "noUnusedParameters": false, + "noImplicitReturns": false, + "noImplicitAny": false, + "noImplicitThis": false, + "noFallthroughCasesInSwitch": false, "declaration": true, "emitDecoratorMetadata": true, - "esModuleInterop": true, "experimentalDecorators": true, "incremental": true, - "inlineSourceMap": true, - // "preserveConstEnums": true, - // "sourceMap": true, + "sourceMap": true, + "inlineSourceMap": false, + "inlineSources": true, "preserveSymlinks": true, - // "removeComments": true, - // "jsx": "react", - "jsxFactory": "etch.dom", + "removeComments": true, + "jsx": "react", "lib": ["ES2018", "dom"], "target": "ES2018", + "allowJs": true, + "esModuleInterop": true, "module": "commonjs", "moduleResolution": "node", - // "noLib": false, - // "importHelpers": true, // if true you should add tslib to deps - // "skipLibCheck": false, - - "outDir": "../lib/" + "importHelpers": false, + "outDir": "../lib" }, "compileOnSave": false } From a37549cde6322cd0d0745811a0e58a0b548f8358 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:13:38 -0600 Subject: [PATCH 24/50] Break on tsc errors --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5d14357..01b492b 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "lib/**/*" ], "scripts": { - "typescript": "tsc -p src/tsconfig.json || echo 'tsc is done'", - "build": "npm run typescript -s", + "typescript": "tsc -p src/tsconfig.json", + "build": "npm run typescript", "test": "atom --test test", "prepare": "npm run build" }, From af6f304c7ae6072e8d253f0da918f6801a05b84d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:19:38 -0600 Subject: [PATCH 25/50] Wrap long docs --- src/select-list-properties.ts | 18 ++++++++++++------ src/select-list-view.ts | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/select-list-properties.ts b/src/select-list-properties.ts index d065aa4..8d335aa 100644 --- a/src/select-list-properties.ts +++ b/src/select-list-properties.ts @@ -11,7 +11,8 @@ export interface SelectListProperties { * * - `selected`: indicating whether item is selected or not. * - `index`: item's index. - * - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true. + * - `visible`: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, + this value is always true. */ elementForItem: ( item: object | string, @@ -21,13 +22,16 @@ export interface SelectListProperties { /** (Optional) the number of maximum items that are shown. */ maxResults?: number - /** (Optional) a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results. */ + /** (Optional) a function that allows to decide which items to show whenever the query changes. + By default, it uses fuzzaldrin to filter results. */ filter?: (items: Array, query: string) => Array - /** (Optional) when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them. */ + /** (Optional) when filter is not provided, this function will be called to retrieve a string property on each item, + and that will be used to filter them. */ filterKeyForItem?: (item: object | string) => string - /** (Optional) a function that allows to apply a transformation to the user query and whose return value will be used to filter items. */ + /** (Optional) a function that allows to apply a transformation to the user query and whose return value + will be used to filter items. */ filterQuery?: (query: string) => string /** (Optional) a string that will replace the contents of the query editor. */ @@ -51,7 +55,8 @@ export interface SelectListProperties { /** (Optional) a string that needs to be set when you are loading items in the background. */ loadingMessage?: string - /** (Optional) a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far). */ + /** (Optional) a string or number that needs to be set when the progress status changes + (e.g. a percentage showing how many items have been loaded so far). */ loadingBadge?: string | number /** (Optional) an array of strings that will be added as class names to the items element. */ @@ -75,7 +80,8 @@ export interface SelectListProperties { /** (Optional) a function that is called when the user presses Esc or the list loses focus. */ didCancelSelection?: () => void - /** (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. */ + /** (Optional) When this options was provided, SelectList observe visibility of items in viewport, visibility state is + passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. */ initiallyVisibleItemCount?: number skipCommandsRegistration: boolean diff --git a/src/select-list-view.ts b/src/select-list-view.ts index a148ba3..869c276 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -11,7 +11,8 @@ export type EtchElement = HTMLElement import { SelectListProperties } from './select-list-properties' export default class SelectListView { - /** When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties */ + /** When creating a new instance of a select list, or when calling `update` on an existing one, + you can supply an object with the typeof SelectListProperties */ props: SelectListProperties /** an array containing the objects you want to show in the select list. */ From e5df058b6b014c6708eb6cb173ff25c8ef0cff4e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:24:46 -0600 Subject: [PATCH 26/50] Use // for normal comments --- src/select-list-view.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 869c276..dc6d580 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -56,12 +56,11 @@ export default class SelectListView { const didLoseFocus = this.didLoseFocus.bind(this) editorElement.addEventListener('blur', didLoseFocus) - /** - * When clicking the scrollbar of the items list, a blur event will be triggered - * on the query editor element, but we don't want to treat that as a cancellation. - * This mousedown listener allows us to detect this case and restore focus to the - * query editor. This is based on https://stackoverflow.com/a/1480178. - */ + + // When clicking the scrollbar of the items list, a blur event will be triggered + // on the query editor element, but we don't want to treat that as a cancellation. + // This mousedown listener allows us to detect this case and restore focus to the + // query editor. This is based on https://stackoverflow.com/a/1480178. this.didClickItemsList = false this.element.addEventListener('mousedown', event => { if (event.target === this.refs.items) { @@ -164,8 +163,8 @@ export default class SelectListView { } if (props.hasOwnProperty('query')) { - /** Items will be recomputed as part of the change event handler, so we */ - /** don't need to recompute them again at the end of this function. */ + // Items will be recomputed as part of the change event handler, so we + // don't need to recompute them again at the end of this function. this.refs.queryEditor.setText(props.query) shouldComputeItems = false } From 5abb4f0ef1e1a20ea56a4fa531da48de137718aa Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:27:46 -0600 Subject: [PATCH 27/50] Factor out ListItemViewProps --- src/select-list-view.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index dc6d580..eb36b6f 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -440,13 +440,15 @@ export default class SelectListView { } } +type ListItemViewProps = { element: EtchElement ; selected: boolean; onclick: () => void } + class ListItemView { public element: EtchElement public selected: boolean public onclick: () => void public domEventsDisposable: Disposable - constructor (props: { element: EtchElement ; selected: boolean; onclick: () => void } ) { + constructor (props: ListItemViewProps) { this.mouseDown = this.mouseDown.bind(this) this.mouseUp = this.mouseUp.bind(this) this.didClick = this.didClick.bind(this) @@ -485,7 +487,7 @@ class ListItemView { this.domEventsDisposable.dispose() } - update (props: { element: EtchElement ; selected: boolean; onclick: () => void }) { + update (props: ListItemViewProps) { this.element.removeEventListener('mousedown', this.mouseDown) this.element.removeEventListener('mouseup', this.mouseUp) this.element.removeEventListener('click', this.didClick) From 4b5e63b73cce3f3ec560dfe1467a816dd20f93d9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:35:13 -0600 Subject: [PATCH 28/50] Update and move tsconfig --- package.json | 2 +- src/tsconfig.json => tsconfig.json | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) rename src/tsconfig.json => tsconfig.json (70%) diff --git a/package.json b/package.json index 01b492b..0c9fb7a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "lib/**/*" ], "scripts": { - "typescript": "tsc -p src/tsconfig.json", + "typescript": "tsc -p ./tsconfig.json", "build": "npm run typescript", "test": "atom --test test", "prepare": "npm run build" diff --git a/src/tsconfig.json b/tsconfig.json similarity index 70% rename from src/tsconfig.json rename to tsconfig.json index 11ff569..13a346b 100644 --- a/src/tsconfig.json +++ b/tsconfig.json @@ -9,23 +9,21 @@ "noImplicitThis": false, "noFallthroughCasesInSwitch": false, "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, "incremental": true, "sourceMap": true, - "inlineSourceMap": false, "inlineSources": true, - "preserveSymlinks": true, - "removeComments": true, + "removeComments": false, "jsx": "react", + "jsxFactory": "etch.dom", "lib": ["ES2018", "dom"], "target": "ES2018", "allowJs": true, "esModuleInterop": true, "module": "commonjs", "moduleResolution": "node", - "importHelpers": false, - "outDir": "../lib" + "outDir": "lib" }, - "compileOnSave": false + "include": [ + "src" + ] } From eaf175ddfce7bc0c96ab5c5324d3be3c991efa98 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:37:48 -0600 Subject: [PATCH 29/50] Move and change import/require --- src/select-list-view.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index eb36b6f..02bef79 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -1,7 +1,5 @@ -// TODO: fix redundant returns in methods - -const etch = require('etch') import { Disposable, CompositeDisposable, TextEditor, CommandEvent } from 'atom' +import etch from 'etch' const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' From 31f366586af3d3de564f6c353e13e5130870f3d8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:39:36 -0600 Subject: [PATCH 30/50] Add dev script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 0c9fb7a..c1c4c67 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "lib/**/*" ], "scripts": { + "dev": "npm run typescript -- --watch", "typescript": "tsc -p ./tsconfig.json", "build": "npm run typescript", "test": "atom --test test", From 72f9d0187148f2e6638b49062a66df5e907ec50c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:42:08 -0600 Subject: [PATCH 31/50] Remove unused locals --- src/select-list-view.ts | 2 +- tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 02bef79..5b18711 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -28,7 +28,7 @@ export default class SelectListView { etch.setScheduler(scheduler) } - static getScheduler (scheduler) { + static getScheduler () { return etch.getScheduler() } diff --git a/tsconfig.json b/tsconfig.json index 13a346b..6ed1a8d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "strict": false, "strictNullChecks": false, - "noUnusedLocals": false, + "noUnusedLocals": true, "noUnusedParameters": false, "noImplicitReturns": false, "noImplicitAny": false, From 43b1d7574c16c40805d73a69f1cc02949d58ed92 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:42:47 -0600 Subject: [PATCH 32/50] Move strict tsconfig --- tsconfig.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 6ed1a8d..f1d9d11 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,11 +3,11 @@ "strict": false, "strictNullChecks": false, "noUnusedLocals": true, - "noUnusedParameters": false, - "noImplicitReturns": false, + "noUnusedParameters": true, + "noImplicitReturns": true, "noImplicitAny": false, - "noImplicitThis": false, - "noFallthroughCasesInSwitch": false, + "noImplicitThis": true, + "noFallthroughCasesInSwitch": true, "declaration": true, "incremental": true, "sourceMap": true, From cf1cac735bd227273c418e23cd10d464afc30de7 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:47:55 -0600 Subject: [PATCH 33/50] noImplicitAny and strict --- src/select-list-view.ts | 7 ++++--- tsconfig.json | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 5b18711..7ed0184 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -1,10 +1,11 @@ import { Disposable, CompositeDisposable, TextEditor, CommandEvent } from 'atom' +// @ts-ignore Merge https://github.com/atom/etch/pull/90 import etch from 'etch' const $ = etch.dom import fuzzaldrin from 'fuzzaldrin' -// TODO: etch types export type EtchElement = HTMLElement +type EtchScheduler = any import { SelectListProperties } from './select-list-properties' @@ -24,7 +25,7 @@ export default class SelectListView { private selectionIndex: number | undefined private refs: any; - static setScheduler (scheduler) { + static setScheduler (scheduler: EtchScheduler) { etch.setScheduler(scheduler) } @@ -87,7 +88,7 @@ export default class SelectListView { this.refs.queryEditor.element.focus() } - didLoseFocus (event) { + didLoseFocus (event: {relatedTarget: Node}) { if (this.didClickItemsList || this.element.contains(event.relatedTarget)) { this.didClickItemsList = false this.refs.queryEditor.element.focus() diff --git a/tsconfig.json b/tsconfig.json index f1d9d11..1845672 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { - "strict": false, + "strict": true, "strictNullChecks": false, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "noImplicitAny": false, + "noImplicitAny": true, "noImplicitThis": true, "noFallthroughCasesInSwitch": true, "declaration": true, From d5d37369f9bd105f98cadc9603885985fa63a0ec Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:55:00 -0600 Subject: [PATCH 34/50] Fix fuzzaldrin types --- src/select-list-view.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 7ed0184..ba160cf 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -232,7 +232,7 @@ export default class SelectListView { if (this.visibilityObserver) { etch.getScheduler().updateDocument(() => { - Array.from(this.refs.items.children).slice(this.props.initiallyVisibleItemCount).forEach(element => { + Array.from(this.refs.items.children).slice(this.props.initiallyVisibleItemCount).forEach((element: any) => { this.visibilityObserver.observe(element) }) }) @@ -316,6 +316,7 @@ export default class SelectListView { this.listItems = null if (this.visibilityObserver) this.visibilityObserver.disconnect() const filterFn = this.props.filter || this.fuzzyFilter.bind(this) + // @ts-ignore fuzzaldrin types should be fixed this.items = filterFn(this.props.items.slice(), this.getFilterQuery()) if (this.props.order) { this.items.sort(this.props.order) @@ -327,7 +328,7 @@ export default class SelectListView { this.selectIndex(this.props.initialSelectionIndex, updateComponent) } - fuzzyFilter (items: Array, query?: string) { + fuzzyFilter (items: Array, query?: string) { if (query.length === 0) { return items } else { From cc81360d3399edc71aa2a25e50f3efdbc26e95ca Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:57:00 -0600 Subject: [PATCH 35/50] Use in instead of hasOwnProperty Allows TypeScript to infer the types --- src/select-list-view.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index ba160cf..9143d30 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -136,39 +136,39 @@ export default class SelectListView { }) } - update (props: SelectListProperties = {}) { + update (props: SelectListProperties | {} = {}) { /** TODO: default value {} */ let shouldComputeItems = false - if (props.hasOwnProperty('items')) { + if ('items' in props) { this.props.items = props.items shouldComputeItems = true } - if (props.hasOwnProperty('maxResults')) { + if ('maxResults' in props) { this.props.maxResults = props.maxResults shouldComputeItems = true } - if (props.hasOwnProperty('filter')) { + if ('filter' in props) { this.props.filter = props.filter shouldComputeItems = true } - if (props.hasOwnProperty('filterQuery')) { + if ('filterQuery' in props) { this.props.filterQuery = props.filterQuery shouldComputeItems = true } - if (props.hasOwnProperty('query')) { + if ('query' in props) { // Items will be recomputed as part of the change event handler, so we // don't need to recompute them again at the end of this function. this.refs.queryEditor.setText(props.query) shouldComputeItems = false } - if (props.hasOwnProperty('selectQuery')) { + if ('selectQuery' in props) { if (props.selectQuery) { this.refs.queryEditor.selectAll() } else { @@ -176,35 +176,35 @@ export default class SelectListView { } } - if (props.hasOwnProperty('order')) { + if ('order' in props) { this.props.order = props.order } - if (props.hasOwnProperty('emptyMessage')) { + if ('emptyMessage' in props) { this.props.emptyMessage = props.emptyMessage } - if (props.hasOwnProperty('errorMessage')) { + if ('errorMessage' in props) { this.props.errorMessage = props.errorMessage } - if (props.hasOwnProperty('infoMessage')) { + if ('infoMessage' in props) { this.props.infoMessage = props.infoMessage } - if (props.hasOwnProperty('loadingMessage')) { + if ('loadingMessage' in props) { this.props.loadingMessage = props.loadingMessage } - if (props.hasOwnProperty('loadingBadge')) { + if ('loadingBadge' in props) { this.props.loadingBadge = props.loadingBadge } - if (props.hasOwnProperty('itemsClassList')) { + if ('itemsClassList' in props) { this.props.itemsClassList = props.itemsClassList } - if (props.hasOwnProperty('initialSelectionIndex')) { + if ('initialSelectionIndex' in props) { this.props.initialSelectionIndex = props.initialSelectionIndex } From 231df2c1c9c33cef43d1ffbc0e4187c4befaa587 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 22:57:58 -0600 Subject: [PATCH 36/50] Replace the deprecated scrollIntoViewIfNeeded --- src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 9143d30..43ea970 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -508,7 +508,7 @@ class ListItemView { scrollIntoViewIfNeeded () { if (this.selected) { - this.element.scrollIntoViewIfNeeded(false) + this.element.scrollIntoView(false) } } } From fd8902ffe91f714bdb79a82122f7d4469ce5ca8d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 23:05:30 -0600 Subject: [PATCH 37/50] Downgrade sinon --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c1c4c67..11c1ea0 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "atomTestRunner": "atom-mocha-test-runner", "devDependencies": { "atom-mocha-test-runner": "^1.2.0", - "sinon": "^9.0.2", + "sinon": "^2", "typescript": "^3.8.3", "@types/atom": "^1.40.2", "@types/fuzzaldrin": "^2.1.2" From c021cc99b3157abb0d9f189bd1c652b305b63ca6 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 23:06:28 -0600 Subject: [PATCH 38/50] Bump typescript deps --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 11c1ea0..92fdc9b 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ "devDependencies": { "atom-mocha-test-runner": "^1.2.0", "sinon": "^2", - "typescript": "^3.8.3", - "@types/atom": "^1.40.2", - "@types/fuzzaldrin": "^2.1.2" + "typescript": "^4.1.3", + "@types/atom": "^1.40.5", + "@types/fuzzaldrin": "^2.1.3" }, "dependencies": { "etch": "^0.14.0", From cdf3129b6bd1f84cc28f70283c5a618a5e0aff45 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Mon, 4 Jan 2021 23:12:26 -0600 Subject: [PATCH 39/50] Use ES5 export style (to prevent exports.default) --- src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 43ea970..a58dc53 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -9,7 +9,7 @@ type EtchScheduler = any import { SelectListProperties } from './select-list-properties' -export default class SelectListView { +module.exports = class SelectListView { /** When creating a new instance of a select list, or when calling `update` on an existing one, you can supply an object with the typeof SelectListProperties */ props: SelectListProperties From 8818ab07a04e7b773560c543f634f5c9672fed9d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 5 Jan 2021 23:55:55 -0600 Subject: [PATCH 40/50] Depend on strict for noImplicitAny and noImplicitThis --- tsconfig.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 1845672..2795896 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,6 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "noImplicitAny": true, - "noImplicitThis": true, "noFallthroughCasesInSwitch": true, "declaration": true, "incremental": true, From e2bff3a3cac53b532efbb6e0d423ac815647e89c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 5 Jan 2021 23:58:32 -0600 Subject: [PATCH 41/50] Make skipCommandsRegistration optional --- src/select-list-properties.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select-list-properties.ts b/src/select-list-properties.ts index 8d335aa..db32b39 100644 --- a/src/select-list-properties.ts +++ b/src/select-list-properties.ts @@ -84,5 +84,5 @@ export interface SelectListProperties { passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items. */ initiallyVisibleItemCount?: number - skipCommandsRegistration: boolean + skipCommandsRegistration?: boolean } From f43e9207575cbf3afd3a474593efaba439ad1a6d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 5 Jan 2021 23:59:38 -0600 Subject: [PATCH 42/50] remove space Co-authored-by: Winston Liu --- src/select-list-view.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index a58dc53..f9a3047 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -55,7 +55,6 @@ module.exports = class SelectListView { const didLoseFocus = this.didLoseFocus.bind(this) editorElement.addEventListener('blur', didLoseFocus) - // When clicking the scrollbar of the items list, a blur event will be triggered // on the query editor element, but we don't want to treat that as a cancellation. // This mousedown listener allows us to detect this case and restore focus to the From 246ff18d92bdbf2e5f81a9936817e01c4fa8d851 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 00:03:19 -0600 Subject: [PATCH 43/50] Make items private --- src/select-list-view.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index f9a3047..80032df 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -15,7 +15,7 @@ module.exports = class SelectListView { props: SelectListProperties /** an array containing the objects you want to show in the select list. */ - items: Array // TODO: Added initializer! Either fix this.items or assign it in constructor + private items: Array private disposables: CompositeDisposable private element: EtchElement @@ -35,7 +35,7 @@ module.exports = class SelectListView { constructor (props: SelectListProperties) { this.props = props - this.items = props.items // TODO: Added initializer! Either fix this.items or assign it in constructor + this.items = props.items if (!this.props.hasOwnProperty('initialSelectionIndex')) { this.props.initialSelectionIndex = 0 From 0e9dc1f1c547b8b243b9f9fdf83d4fa6c650c8fe Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 17:38:21 -0600 Subject: [PATCH 44/50] Revert "Replace the deprecated scrollIntoViewIfNeeded" This reverts commit 231df2c1c9c33cef43d1ffbc0e4187c4befaa587. --- src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 80032df..922ef59 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -507,7 +507,7 @@ class ListItemView { scrollIntoViewIfNeeded () { if (this.selected) { - this.element.scrollIntoView(false) + this.element.scrollIntoViewIfNeeded(false) } } } From 80c3e14eb0fd8198285319cf4ebc1f822cafd516 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 17:39:34 -0600 Subject: [PATCH 45/50] Add ts-ignore for scrollIntoViewIfNeeded --- src/select-list-view.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 922ef59..eefc126 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -507,6 +507,7 @@ class ListItemView { scrollIntoViewIfNeeded () { if (this.selected) { + // @ts-ignore: this function is a non-standard API. this.element.scrollIntoViewIfNeeded(false) } } From 180f2240940f2911aa0703214e6803071f32f85b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 18:14:27 -0600 Subject: [PATCH 46/50] Remove initial assignment to this.items --- src/select-list-view.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index eefc126..bd6c978 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -35,7 +35,6 @@ module.exports = class SelectListView { constructor (props: SelectListProperties) { this.props = props - this.items = props.items if (!this.props.hasOwnProperty('initialSelectionIndex')) { this.props.initialSelectionIndex = 0 From 414607f8f8bafd2758c1d0931e8b0917b2346cf2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 18:16:40 -0600 Subject: [PATCH 47/50] update the docstring for items Co-authored-by: Winston Liu --- src/select-list-view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index bd6c978..6dc8ffc 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -14,7 +14,7 @@ module.exports = class SelectListView { you can supply an object with the typeof SelectListProperties */ props: SelectListProperties - /** an array containing the objects you want to show in the select list. */ + /** An array containing the filtered and ordered items to be shown in the select list. */ private items: Array private disposables: CompositeDisposable From 3c11348aaafe761894b3f9ee9b2ea3e23a5347af Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 18:23:41 -0600 Subject: [PATCH 48/50] Fix the type for this.refs.items.children --- src/select-list-view.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 6dc8ffc..8f50567 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -71,9 +71,9 @@ module.exports = class SelectListView { this.visibilityObserver = new IntersectionObserver(changes => { for (const change of changes) { if (change.intersectionRatio > 0) { - const element = change.target + const element = change.target as EtchElement this.visibilityObserver.unobserve(element) - const index = Array.from(this.refs.items.children).indexOf(element) + const index = Array.from(this.refs.items.children as EtchElement[]).indexOf(element) if (index >= 0) { this.renderItemAtIndex(index) } @@ -230,7 +230,7 @@ module.exports = class SelectListView { if (this.visibilityObserver) { etch.getScheduler().updateDocument(() => { - Array.from(this.refs.items.children).slice(this.props.initiallyVisibleItemCount).forEach((element: any) => { + Array.from(this.refs.items.children as EtchElement[]).slice(this.props.initiallyVisibleItemCount).forEach((element) => { this.visibilityObserver.observe(element) }) }) From b4a58f7b1b7e564e3505027f961d8a90e5216566 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 6 Jan 2021 19:46:49 -0600 Subject: [PATCH 49/50] Remove {} from the default value for props https://github.com/atom/atom-select-list/pull/28#discussion_r553014066 --- src/select-list-view.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 8f50567..1f9c447 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -134,9 +134,7 @@ module.exports = class SelectListView { }) } - update (props: SelectListProperties | {} = {}) { - /** TODO: default value {} */ - + update (props: SelectListProperties) { let shouldComputeItems = false if ('items' in props) { From b07cbecb62e0cb14ac07a6dbabdb49fa02de745c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 7 Jan 2021 18:44:12 -0600 Subject: [PATCH 50/50] remove space Co-authored-by: Winston Liu --- src/select-list-view.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/select-list-view.ts b/src/select-list-view.ts index 1f9c447..8a9bf72 100644 --- a/src/select-list-view.ts +++ b/src/select-list-view.ts @@ -35,7 +35,6 @@ module.exports = class SelectListView { constructor (props: SelectListProperties) { this.props = props - if (!this.props.hasOwnProperty('initialSelectionIndex')) { this.props.initialSelectionIndex = 0 }