You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Cytoscape.js extension for integrating [Popper.js](https://popper.js.org/) ([demo](https://cytoscape.github.io/cytoscape.js-popper)) ([tippy demo](https://cytoscape.github.io/cytoscape.js-popper/demo-tippy.html))
8
+
Popper allows you to dynamically align a div, e.g. a tooltip, to another element in the page. This extension allows you to use any popper library on Cytoscape elements. This allows you to create DOM elements positioned on or around Cytoscape elements. It is useful for tooltips and overlays, for example.
Since `Popper.js` has become `@floating-ui` (https://floating-ui.com/docs/migration) and the API has changed a lot it becomes harder to support both versions
19
+
(for example TippyJS, that supports only the previous version), so instead of depending on a specific external version
20
+
this extension allows users to use any Popper library with providing `popperFactory` function during initializing.
21
+
22
+
See [FloatingUI](#usage-with-floating-ui) or [Popper.js](#usage-with-popperjs--deprecated-) sections.
23
+
9
24
10
-
Popper allows you to dynamically align a div, e.g. a tooltip, to another element in the page. This extension allows you to use any popper library (mostly `@floating-ui` (previously `Popper.js`) or `Tippy.js`) on Cytoscape elements. This allows you to create DOM elements positioned on or around Cytoscape elements. It is useful for tooltips and overlays, for example.
11
25
12
26
## Dependencies
13
27
@@ -30,8 +44,7 @@ import cytoscape from 'cytoscape';
30
44
importcytoscapePopperfrom'cytoscape-popper';
31
45
32
46
functionpopperFactory(ref, content, opts) {
33
-
// use floating-ui or Tippy here. See demo
34
-
return {}
47
+
// See integration sections
35
48
}
36
49
37
50
cytoscape.use( cytoscapePopper(popperFactory) );
@@ -44,8 +57,7 @@ let cytoscape = require('cytoscape');
Plain HTML/JS has the extension registered for you automatically, because no `require()` is needed.
68
-
69
78
## API
70
79
71
80
This extension exposes `popper()` and `popperRef()` functions and provided `popperFactory()`. These functions are defined for both the core and for elements, so you can call `cy.popper()` or `ele.popper()` for example.
@@ -84,15 +93,30 @@ Each function takes an options object, as follows:
84
93
85
94
## Usage with @floating-ui
86
95
87
-
88
96
### Initializing
89
97
90
98
```js
91
99
importcytoscapefrom'cytoscape';
92
100
importcytoscapePopperfrom'cytoscape-popper';
93
-
import {computePosition} from'@floating-ui/dom';
101
+
import {
102
+
computePosition,
103
+
flip,
104
+
shift,
105
+
limitShift,
106
+
} from'@floating-ui/dom';
94
107
95
108
functionpopperFactory(ref, content, opts) {
109
+
// see https://floating-ui.com/docs/computePosition#options
This extension can also be used to enable [Tippy.js](https://github.com/atomiks/tippyjs) tooltip functionality with Cytoscape. Any version of Tippy that is compatible with Popper v2 is compatible with this extension.
@@ -237,17 +343,6 @@ tip.show();
237
343
238
344
Refer to [Tippy.js](https://atomiks.github.io/tippyjs/) documentation for more details.
239
345
240
-
## v3 changes
241
-
242
-
Since `Popper.js` has become `@floating-ui` and the API has changed a lot it becomes harder to support both versions
243
-
(for example TippyJS, that supports only the previous version), so instead of depending on a specific external version
244
-
this extension allows users to use any Popper library with providing `popperFactory` function during initializing.
245
-
246
-
This version dropped the external dependency and changed the initializing api from `cytoscape.use(cytoscapePopper)` to `cytoscape.use(cytoscapePopper(popperFactory))`
247
-
248
-
See popperFactory examples to save backward-compatibility with v2
249
-
250
-
251
346
## Typescript
252
347
253
348
This extension exports empty `PopperInstance` and `PopperOptions` interfaces allows to extend them according to the final Popper implementation.
0 commit comments