From 10ccea5b167f85a4e52287a3ac5abb162340daa2 Mon Sep 17 00:00:00 2001 From: Atrue Date: Fri, 6 Oct 2023 09:07:55 +0300 Subject: [PATCH] add typings --- cytoscape-popper.d.ts | 84 +++++++++++++++++++++++++++++++++++++++++++ package.json | 6 ++-- tsconfig.json | 23 ++++++++++++ yarn.lock | 10 ++++++ 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 cytoscape-popper.d.ts create mode 100644 tsconfig.json diff --git a/cytoscape-popper.d.ts b/cytoscape-popper.d.ts new file mode 100644 index 00000000..3772c9c7 --- /dev/null +++ b/cytoscape-popper.d.ts @@ -0,0 +1,84 @@ +import * as cy from "cytoscape"; + +declare const cytoscapePopper: cy.Ext; +export = cytoscapePopper; +export as namespace cytoscapePopper; + +declare namespace cytoscapePopper { + interface Dimensions { + w: number; + h: number; + } + + interface PopperOptions { + } + interface PopperInstance { + } + + type RefElement = Pick; + + interface Options { + /* + * The HTML content of the popper. May be a DOM Element reference or a function that returns one. + */ + content?: HTMLElement | (() => HTMLElement); + /* + * A function that can be used to override the [rendered](http://js.cytoscape.org/#notation/position) Cytoscape position of the Popper target. + * This option is mandatory when using Popper on the core. + * For an element, the centre of its bounding box is used by default. + */ + renderedPosition?: (el: Type) => cytoscape.Position; + /* + * A function that can be used to override the [rendered](http://js.cytoscape.org/#notation/position) Cytoscape bounding box dimensions + * considered for the popper target (i.e. `cy` or `ele`). + * It defines only the effective `width` and `height` (`bb.w` and `bb.h`) of the Popper target. + * This option is more often useful for elements rather than for the core. + */ + renderedDimensions?: (el: Type) => Dimensions; + /* + * The PopperOptions object. + * You may use this to override Popper options. + */ + popper?: PopperOptions; + } + + type getPopperInstance = (opts?: Options) => PopperInstance; + + type getPopperRef = (opts?: Options) => RefElement; + + type PopperFactory = (ref: RefElement, content: HTMLElement, options: PopperOptions) => PopperInstance; +} + +declare global { + namespace cytoscape { + interface SingularData { + /* + * User-provided popper factory + */ + popperFactory: cytoscapePopper.PopperFactory; + /* + * Make a PopperInstance using provided popperFactory for the specified element. + */ + popper: cytoscapePopper.getPopperInstance; + /* + * Make a virtual popperRef element from the cytoscape instance + */ + popperRef: cytoscapePopper.getPopperRef; + } + + interface Core { + /* + * User-provided popper factory + */ + popperFactory: cytoscapePopper.PopperFactory; + /* + * Make a PopperInstance using provided popperFactory for the specified element. + */ + popper: cytoscapePopper.getPopperInstance; + /* + * Make a virtual popperRef element from the cytoscape instance + */ + popperRef: cytoscapePopper.getPopperRef; + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 1c33a10a..532cf988 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.0.0", "description": "A Cytoscape.js extension for Popper.js", "main": "cytoscape-popper.js", + "types": "cytoscape-popper.d.ts", "author": "Cytoscape", "scripts": { "postpublish": "run-s gh-pages", @@ -30,6 +31,7 @@ }, "homepage": "https://github.com/cytoscape/cytoscape.js-popper", "devDependencies": { + "@types/cytoscape": "^3.2.0", "babel-core": "^6.24.1", "babel-loader": "^7.0.0", "babel-preset-env": "^1.5.1", @@ -42,6 +44,7 @@ "mocha": "3.4.2", "npm-run-all": "^4.1.2", "rimraf": "^2.6.2", + "typescript": "^3.8.0", "update": "^0.7.4", "updater-license": "^1.0.0", "webpack": "^2.6.1", @@ -50,6 +53,5 @@ "peerDependencies": { "cytoscape": "^3.2.0" }, - "dependencies": { - } + "dependencies": {} } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..88909ee8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "cytoscape-popper.d.ts" + ] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2cd7e902..87666114 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,11 @@ # yarn lockfile v1 +"@types/cytoscape@^3.2.0": + version "3.19.11" + resolved "https://registry.yarnpkg.com/@types/cytoscape/-/cytoscape-3.19.11.tgz#69cc512c4cbadfcd2e84a1f7b84593dc4b8fb258" + integrity sha512-ny4i4BOoZxdc9DrSa9RrasXHPRFgt0PeINgj/CegzKu7CJO+UQP0KnjebYJ+KoLymyUbCX86vmqz5B3LK10w5Q== + accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" @@ -8491,6 +8496,11 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA== +typescript@^3.8.0: + version "3.9.10" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" + integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== + uglify-js@^2.8.27: version "2.8.29" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"