Skip to content

Commit

Permalink
add typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Atrue committed Oct 6, 2023
1 parent 1e13083 commit 10ccea5
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 2 deletions.
84 changes: 84 additions & 0 deletions cytoscape-popper.d.ts
Original file line number Diff line number Diff line change
@@ -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<Element, 'getBoundingClientRect'>;

interface Options<Type> {
/*
* 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<Type> = (opts?: Options<Type>) => PopperInstance;

type getPopperRef<Type> = (opts?: Options<Type>) => 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<SingularData>;
/*
* Make a virtual popperRef element from the cytoscape instance
*/
popperRef: cytoscapePopper.getPopperRef<SingularData>;
}

interface Core {
/*
* User-provided popper factory
*/
popperFactory: cytoscapePopper.PopperFactory;
/*
* Make a PopperInstance using provided popperFactory for the specified element.
*/
popper: cytoscapePopper.getPopperInstance<SingularData>;
/*
* Make a virtual popperRef element from the cytoscape instance
*/
popperRef: cytoscapePopper.getPopperRef<SingularData>;
}
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -50,6 +53,5 @@
"peerDependencies": {
"cytoscape": "^3.2.0"
},
"dependencies": {
}
"dependencies": {}
}
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 10ccea5

Please sign in to comment.