Skip to content

Commit adfdf71

Browse files
Johann-SXhmikosR
authored andcommitted
Update to popper.js v2.x
1 parent 5f89ea3 commit adfdf71

26 files changed

+145
-297
lines changed

build/build-plugins.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const rollup = require('rollup')
1414
const { babel } = require('@rollup/plugin-babel')
1515
const banner = require('./banner.js')
1616

17+
const rootPath = path.resolve(__dirname, '../js/dist/')
1718
const plugins = [
1819
babel({
1920
// Only transpile our source code
@@ -39,7 +40,6 @@ const bsPlugins = {
3940
Toast: path.resolve(__dirname, '../js/src/toast.js'),
4041
Tooltip: path.resolve(__dirname, '../js/src/tooltip.js')
4142
}
42-
const rootPath = path.resolve(__dirname, '../js/dist/')
4343

4444
const defaultPluginConfig = {
4545
external: [
@@ -87,9 +87,9 @@ const getConfigByPluginKey = pluginKey => {
8787

8888
if (pluginKey === 'Dropdown' || pluginKey === 'Tooltip') {
8989
const config = Object.assign(defaultPluginConfig)
90-
config.external.push(bsPlugins.Manipulator, 'popper.js')
90+
config.external.push(bsPlugins.Manipulator, '@popperjs/core')
9191
config.globals[bsPlugins.Manipulator] = 'Manipulator'
92-
config.globals['popper.js'] = 'Popper'
92+
config.globals['@popperjs/core'] = 'Popper'
9393
return config
9494
}
9595

build/generate-sri.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const files = [
4242
configPropertyName: 'js_bundle_hash'
4343
},
4444
{
45-
file: 'node_modules/popper.js/dist/umd/popper.min.js',
45+
file: 'node_modules/@popperjs/core/dist/umd/popper.min.js',
4646
configPropertyName: 'popper_hash'
4747
}
4848
]

build/rollup.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
const path = require('path')
44
const { babel } = require('@rollup/plugin-babel')
55
const { nodeResolve } = require('@rollup/plugin-node-resolve')
6+
const replace = require('@rollup/plugin-replace')
67
const banner = require('./banner.js')
78

89
const BUNDLE = process.env.BUNDLE === 'true'
910
const ESM = process.env.ESM === 'true'
1011

1112
let fileDest = `bootstrap${ESM ? '.esm' : ''}`
12-
const external = ['popper.js']
13+
const external = ['@popperjs/core']
1314
const plugins = [
1415
babel({
1516
// Only transpile our source code
@@ -19,15 +20,15 @@ const plugins = [
1920
})
2021
]
2122
const globals = {
22-
'popper.js': 'Popper'
23+
'@popperjs/core': 'Popper'
2324
}
2425

2526
if (BUNDLE) {
2627
fileDest += '.bundle'
2728
// Remove last entry in external array to bundle Popper
2829
external.pop()
29-
delete globals['popper.js']
30-
plugins.push(nodeResolve())
30+
delete globals['@popperjs/core']
31+
plugins.push(replace({ 'process.env.NODE_ENV': '"production"' }), nodeResolve())
3132
}
3233

3334
const rollupConfig = {

config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ params:
7575
js_hash: "sha384-supZtwqjyYg6XvvTCi4/w6J6Hm6IKqXaaeoyGhIhonCdkSvA70sSucW7OqXIo4lZ"
7676
js_bundle: "https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-alpha3/dist/js/bootstrap.bundle.min.js"
7777
js_bundle_hash: "sha384-G/J8d6sz9bTod37AsZzNtTwT77J24FKjJEO1YsU2vW7iPcmYP3/tznu+LcK824t9"
78-
popper: "https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
79-
popper_hash: "sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
78+
popper: "https://cdn.jsdelivr.net/npm/@popperjs/core@2.4.2/dist/umd/popper.min.js"
79+
popper_hash: "sha384-a46n7BtEJaPKKs2SeVxZzwKkapYzBUr8c7DyCLEpkRrs4LE03nlh53ZSOPgkJB7U"

js/src/dropdown.js

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* --------------------------------------------------------------------------
66
*/
77

8+
import * as Popper from '@popperjs/core'
9+
810
import {
911
getjQuery,
1012
onDOMContentLoaded,
@@ -18,7 +20,6 @@ import {
1820
import Data from './dom/data'
1921
import EventHandler from './dom/event-handler'
2022
import Manipulator from './dom/manipulator'
21-
import Popper from 'popper.js'
2223
import SelectorEngine from './dom/selector-engine'
2324
import BaseComponent from './base-component'
2425

@@ -58,7 +59,6 @@ const CLASS_NAME_DROPEND = 'dropend'
5859
const CLASS_NAME_DROPSTART = 'dropstart'
5960
const CLASS_NAME_MENUEND = 'dropdown-menu-end'
6061
const CLASS_NAME_NAVBAR = 'navbar'
61-
const CLASS_NAME_POSITION_STATIC = 'position-static'
6262

6363
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]'
6464
const SELECTOR_FORM_CHILD = '.dropdown form'
@@ -76,7 +76,7 @@ const PLACEMENT_LEFT = isRTL ? 'right-start' : 'left-start'
7676
const Default = {
7777
offset: 0,
7878
flip: true,
79-
boundary: 'scrollParent',
79+
boundary: 'clippingParents',
8080
reference: 'toggle',
8181
display: 'dynamic',
8282
popperConfig: null
@@ -176,14 +176,7 @@ class Dropdown extends BaseComponent {
176176
}
177177
}
178178

179-
// If boundary is not `scrollParent`, then set position to `static`
180-
// to allow the menu to "escape" the scroll parent's boundaries
181-
// https://github.com/twbs/bootstrap/issues/24251
182-
if (this._config.boundary !== 'scrollParent') {
183-
parent.classList.add(CLASS_NAME_POSITION_STATIC)
184-
}
185-
186-
this._popper = new Popper(referenceElement, this._menu, this._getPopperConfig())
179+
this._popper = Popper.createPopper(referenceElement, this._menu, this._getPopperConfig())
187180
}
188181

189182
// If this is a touch-enabled device we add extra
@@ -233,6 +226,7 @@ class Dropdown extends BaseComponent {
233226
super.dispose()
234227
EventHandler.off(this._element, EVENT_KEY)
235228
this._menu = null
229+
236230
if (this._popper) {
237231
this._popper.destroy()
238232
this._popper = null
@@ -242,7 +236,7 @@ class Dropdown extends BaseComponent {
242236
update() {
243237
this._inNavbar = this._detectNavbar()
244238
if (this._popper) {
245-
this._popper.scheduleUpdate()
239+
this._popper.update()
246240
}
247241
}
248242

@@ -296,44 +290,24 @@ class Dropdown extends BaseComponent {
296290
return Boolean(this._element.closest(`.${CLASS_NAME_NAVBAR}`))
297291
}
298292

299-
_getOffset() {
300-
const offset = {}
301-
302-
if (typeof this._config.offset === 'function') {
303-
offset.fn = data => {
304-
data.offsets = {
305-
...data.offsets,
306-
...(this._config.offset(data.offsets, this._element) || {})
307-
}
308-
309-
return data
310-
}
311-
} else {
312-
offset.offset = this._config.offset
313-
}
314-
315-
return offset
316-
}
317-
318293
_getPopperConfig() {
319294
const popperConfig = {
320295
placement: this._getPlacement(),
321-
modifiers: {
322-
offset: this._getOffset(),
323-
flip: {
324-
enabled: this._config.flip
325-
},
326-
preventOverflow: {
327-
boundariesElement: this._config.boundary
296+
modifiers: [{
297+
name: 'preventOverflow',
298+
options: {
299+
altBoundary: this._config.flip,
300+
rootBoundary: this._config.boundary
328301
}
329-
}
302+
}]
330303
}
331304

332305
// Disable Popper if we have a static display
333306
if (this._config.display === 'static') {
334-
popperConfig.modifiers.applyStyle = {
307+
popperConfig.modifiers = [{
308+
name: 'applyStyles',
335309
enabled: false
336-
}
310+
}]
337311
}
338312

339313
return {

0 commit comments

Comments
 (0)