Skip to content

Commit 45bc8e4

Browse files
authored
Framework: Replace element-closest with registered vendor script (#9750)
* Framework: Replace element-closest with registered vendor script * Scripts: Add support for license ignore * Framework: Re-pin to newer version of JSDOM Newer version is SemVer-compatible with jest-environment-jsdom and includes support for Element#closest out of the box. jsdom/jsdom#1555 Required to ignore license validation for abab because while it is a compatible license (BSD 3-clause), the package's `license` field is malformed for parse. https://github.com/jsdom/abab/blob/4327de3aae348710094d9f3c1f0c1477d9feb865/package.json#L26 https://github.com/jsdom/abab/blob/master/LICENSE.md * Testing: Add dummy testURL for Jest config Avoids issues with localStorage in JSDOM 11.12 Can be removed when running Jest 23.5.0 or newer See: jestjs/jest#6766 See: jestjs/jest#6792 * Licenses: Add BSD-3-Clause W3C variant as an allowed license Also, check if the license defined in package.json is telling us to look in the license file, instead. * Package: Scripts: Use String#includes for improved code clarity * Package: Scripts: Add CHANGELOG notes for improved license file detection
1 parent cd6ae73 commit 45bc8e4

17 files changed

Lines changed: 128 additions & 73 deletions

File tree

lib/client-assets.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ function gutenberg_register_scripts_and_styles() {
114114
'\'fetch\' in window' => 'wp-polyfill-fetch',
115115
'document.contains' => 'wp-polyfill-node-contains',
116116
'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
117+
'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
117118
)
118119
)
119120
);
@@ -871,6 +872,10 @@ function gutenberg_register_vendor_scripts() {
871872
'wp-polyfill-node-contains',
872873
'https://unpkg.com/polyfill-library@3.26.0-0/polyfills/Node/prototype/contains/polyfill.js'
873874
);
875+
gutenberg_register_vendor_script(
876+
'wp-polyfill-element-closest',
877+
'https://unpkg.com/element-closest@2.0.2/element-closest.js'
878+
);
874879
gutenberg_register_vendor_script(
875880
'wp-polyfill-ecmascript',
876881
'https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.0.0/polyfill' . $suffix . '.js'

package-lock.json

Lines changed: 43 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/blocks/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"@wordpress/i18n": "file:../i18n",
3434
"@wordpress/is-shallow-equal": "file:../is-shallow-equal",
3535
"@wordpress/shortcode": "file:../shortcode",
36-
"element-closest": "^2.0.2",
3736
"hpq": "^1.2.0",
3837
"lodash": "^4.17.10",
3938
"rememo": "^3.0.0",

packages/blocks/src/api/raw-handling/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* External dependencies
33
*/
44
import { flatMap, filter, compact } from 'lodash';
5-
// Also polyfills Element#matches.
6-
import 'element-closest';
75

86
/**
97
* Internal dependencies

packages/components/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"clipboard": "^1.7.1",
3737
"diff": "^3.5.0",
3838
"dom-scroll-into-view": "^1.2.1",
39-
"element-closest": "^2.0.2",
4039
"lodash": "^4.17.10",
4140
"memize": "^1.0.5",
4241
"moment": "^2.22.1",

packages/components/src/autocomplete/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
import classnames from 'classnames';
55
import { escapeRegExp, find, filter, map, debounce } from 'lodash';
6-
import 'element-closest';
76

87
/**
98
* WordPress dependencies

packages/dom/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"module": "build-module/index.js",
2222
"dependencies": {
2323
"@babel/runtime": "^7.0.0",
24-
"element-closest": "^2.0.2",
2524
"lodash": "^4.17.10"
2625
},
2726
"publishConfig": {

packages/dom/src/focusable.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* External dependencies
3-
*/
4-
import 'element-closest';
5-
61
/**
72
* References:
83
*

packages/editor/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@wordpress/wordcount": "file:../wordcount",
4646
"classnames": "^2.2.5",
4747
"dom-scroll-into-view": "^1.2.1",
48-
"element-closest": "^2.0.2",
4948
"inherits": "^2.0.3",
5049
"lodash": "^4.17.10",
5150
"memize": "^1.0.5",

packages/editor/src/components/block-list/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
last,
1212
} from 'lodash';
1313
import classnames from 'classnames';
14-
import 'element-closest';
1514

1615
/**
1716
* WordPress dependencies

0 commit comments

Comments
 (0)