Skip to content

Commit

Permalink
add jquery, jQuery.textSelection() types
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Dec 22, 2020
1 parent 23a73b0 commit dd51629
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ This project is still a **work in progress**.

The intention is to cover all functions in the `mw` global object, as well as the custom jQuery plugins used in MediaWiki core. The doc-comments (copied from MW source code) and the types of the function parameters and return values should be included, ideally.

[![Download stats](https://nodei.co/npm/types-mediawiki.png?downloads=true&downloadRank=true)](https://nodei.co/npm/types-mediawiki/)

----

TODO:
- [ ] Add doc comments for everything
- [x] Finish mw.Api
- [ ] Add jQuery plugins (use [@types/jquery](https://www.npmjs.com/package/@types/jquery) as a dependency)
- [ ] Publish on NPM.
- [x] Publish on NPM.
37 changes: 37 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* @author Siddharth VP (2020)
*/

import 'jquery';

type title = string | mw.Title
type namespaceId = number

Expand Down Expand Up @@ -315,3 +317,38 @@ declare namespace mw {
const widgets: any
}

// XXX: split into multiple files?

declare global {
interface JQuery {
// one overload for each command
textSelection(command: 'getContents'): string
textSelection(command: 'setContents'): JQuery
textSelection(command: 'getSelection'): string
textSelection(command: 'replaceSelection'): JQuery
textSelection(command: 'encapsulateSelection', commandOptions: {
pre?: string
peri?: string
post?: string
ownline?: boolean
replace?: boolean
selectPeri?: boolean
splitlines?: boolean
selectionStart?: number
selectionEnd?: number
}): JQuery
textSelection(command: 'getCaretPosition', commandOptions?: {
startAndEnd?: false
}): number
textSelection(command: 'getCaretPosition', commandOptions: {
startAndEnd: true
}): [number, number]
textSelection(command: 'setSelection', commandOptions: {
start?: number
end?: number
}): JQuery
textSelection(command: 'scrollToCaretPosition', commandOptions: {
force?: boolean
}): JQuery
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types-mediawiki",
"version": "0.1.0",
"version": "0.2.0",
"description": "TypeScript definitions for MediaWiki JS interface",
"types": "index.d.ts",
"repository": {
Expand All @@ -11,5 +11,8 @@
"bugs": {
"url": "https://github.com/wikimedia-gadgets/types-mediawiki/issues"
},
"homepage": "https://github.com/wikimedia-gadgets/types-mediawiki#readme"
"homepage": "https://github.com/wikimedia-gadgets/types-mediawiki#readme",
"dependencies": {
"@types/jquery": "^3.5.5"
}
}

0 comments on commit dd51629

Please sign in to comment.