@wordpress/dom 4.32.0 → 4.32.1-next.b8c8708f3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/data-transfer.js +30 -18
- package/build/data-transfer.js.map +7 -1
- package/build/dom/caret-range-from-point.js +22 -25
- package/build/dom/caret-range-from-point.js.map +7 -1
- package/build/dom/clean-node-list.js +122 -129
- package/build/dom/clean-node-list.js.map +7 -1
- package/build/dom/compute-caret-rect.js +36 -21
- package/build/dom/compute-caret-rect.js.map +7 -1
- package/build/dom/document-has-selection.js +36 -22
- package/build/dom/document-has-selection.js.map +7 -1
- package/build/dom/document-has-text-selection.js +25 -23
- package/build/dom/document-has-text-selection.js.map +7 -1
- package/build/dom/document-has-uncollapsed-selection.js +35 -22
- package/build/dom/document-has-uncollapsed-selection.js.map +7 -1
- package/build/dom/get-computed-style.js +27 -17
- package/build/dom/get-computed-style.js.map +7 -1
- package/build/dom/get-offset-parent.js +43 -32
- package/build/dom/get-offset-parent.js.map +7 -1
- package/build/dom/get-range-height.js +24 -18
- package/build/dom/get-range-height.js.map +7 -1
- package/build/dom/get-rectangle-from-range.js +47 -68
- package/build/dom/get-rectangle-from-range.js.map +7 -1
- package/build/dom/get-scroll-container.js +44 -37
- package/build/dom/get-scroll-container.js.map +7 -1
- package/build/dom/hidden-caret-range-from-point.js +39 -33
- package/build/dom/hidden-caret-range-from-point.js.map +7 -1
- package/build/dom/index.js +116 -195
- package/build/dom/index.js.map +7 -1
- package/build/dom/input-field-has-uncollapsed-selection.js +40 -42
- package/build/dom/input-field-has-uncollapsed-selection.js.map +7 -1
- package/build/dom/insert-after.js +24 -19
- package/build/dom/insert-after.js.map +7 -1
- package/build/dom/is-edge.js +57 -67
- package/build/dom/is-edge.js.map +7 -1
- package/build/dom/is-element.js +22 -11
- package/build/dom/is-element.js.map +7 -1
- package/build/dom/is-empty.js +27 -17
- package/build/dom/is-empty.js.map +7 -1
- package/build/dom/is-entirely-selected.js +46 -50
- package/build/dom/is-entirely-selected.js.map +7 -1
- package/build/dom/is-form-element.js +36 -24
- package/build/dom/is-form-element.js.map +7 -1
- package/build/dom/is-horizontal-edge.js +34 -20
- package/build/dom/is-horizontal-edge.js.map +7 -1
- package/build/dom/is-html-input-element.js +23 -12
- package/build/dom/is-html-input-element.js.map +7 -1
- package/build/dom/is-input-or-text-area.js +23 -12
- package/build/dom/is-input-or-text-area.js.map +7 -1
- package/build/dom/is-number-input.js +38 -29
- package/build/dom/is-number-input.js.map +7 -1
- package/build/dom/is-rtl.js +34 -19
- package/build/dom/is-rtl.js.map +7 -1
- package/build/dom/is-selection-forward.js +26 -40
- package/build/dom/is-selection-forward.js.map +7 -1
- package/build/dom/is-text-field.js +49 -24
- package/build/dom/is-text-field.js.map +7 -1
- package/build/dom/is-vertical-edge.js +34 -20
- package/build/dom/is-vertical-edge.js.map +7 -1
- package/build/dom/place-caret-at-edge.js +52 -55
- package/build/dom/place-caret-at-edge.js.map +7 -1
- package/build/dom/place-caret-at-horizontal-edge.js +34 -18
- package/build/dom/place-caret-at-horizontal-edge.js.map +7 -1
- package/build/dom/place-caret-at-vertical-edge.js +34 -19
- package/build/dom/place-caret-at-vertical-edge.js.map +7 -1
- package/build/dom/remove-invalid-html.js +35 -22
- package/build/dom/remove-invalid-html.js.map +7 -1
- package/build/dom/remove.js +24 -17
- package/build/dom/remove.js.map +7 -1
- package/build/dom/replace-tag.js +24 -19
- package/build/dom/replace-tag.js.map +7 -1
- package/build/dom/replace.js +38 -23
- package/build/dom/replace.js.map +7 -1
- package/build/dom/safe-html.js +39 -28
- package/build/dom/safe-html.js.map +7 -1
- package/build/dom/scroll-if-no-range.js +26 -18
- package/build/dom/scroll-if-no-range.js.map +7 -1
- package/build/dom/strip-html.js +36 -23
- package/build/dom/strip-html.js.map +7 -1
- package/build/dom/unwrap.js +24 -18
- package/build/dom/unwrap.js.map +7 -1
- package/build/dom/wrap.js +24 -17
- package/build/dom/wrap.js.map +7 -1
- package/build/focusable.js +52 -85
- package/build/focusable.js.map +7 -1
- package/build/index.js +44 -58
- package/build/index.js.map +7 -1
- package/build/phrasing-content.js +88 -128
- package/build/phrasing-content.js.map +7 -1
- package/build/tabbable.js +52 -137
- package/build/tabbable.js.map +7 -1
- package/build/utils/assert-is-defined.js +30 -7
- package/build/utils/assert-is-defined.js.map +7 -1
- package/build-module/data-transfer.js +9 -15
- package/build-module/data-transfer.js.map +7 -1
- package/build-module/dom/caret-range-from-point.js +5 -22
- package/build-module/dom/caret-range-from-point.js.map +7 -1
- package/build-module/dom/clean-node-list.js +94 -123
- package/build-module/dom/clean-node-list.js.map +7 -1
- package/build-module/dom/compute-caret-rect.js +8 -16
- package/build-module/dom/compute-caret-rect.js.map +7 -1
- package/build-module/dom/document-has-selection.js +8 -17
- package/build-module/dom/document-has-selection.js.map +7 -1
- package/build-module/dom/document-has-text-selection.js +8 -20
- package/build-module/dom/document-has-text-selection.js.map +7 -1
- package/build-module/dom/document-has-uncollapsed-selection.js +7 -17
- package/build-module/dom/document-has-uncollapsed-selection.js.map +7 -1
- package/build-module/dom/get-computed-style.js +10 -14
- package/build-module/dom/get-computed-style.js.map +7 -1
- package/build-module/dom/get-offset-parent.js +16 -28
- package/build-module/dom/get-offset-parent.js.map +7 -1
- package/build-module/dom/get-range-height.js +7 -15
- package/build-module/dom/get-range-height.js.map +7 -1
- package/build-module/dom/get-rectangle-from-range.js +30 -65
- package/build-module/dom/get-rectangle-from-range.js.map +7 -1
- package/build-module/dom/get-scroll-container.js +16 -32
- package/build-module/dom/get-scroll-container.js.map +7 -1
- package/build-module/dom/hidden-caret-range-from-point.js +11 -28
- package/build-module/dom/hidden-caret-range-from-point.js.map +7 -1
- package/build-module/dom/index.js +57 -28
- package/build-module/dom/index.js.map +7 -1
- package/build-module/dom/input-field-has-uncollapsed-selection.js +12 -37
- package/build-module/dom/input-field-has-uncollapsed-selection.js.map +7 -1
- package/build-module/dom/insert-after.js +7 -16
- package/build-module/dom/insert-after.js.map +7 -1
- package/build-module/dom/is-edge.js +24 -57
- package/build-module/dom/is-edge.js.map +7 -1
- package/build-module/dom/is-element.js +5 -8
- package/build-module/dom/is-element.js.map +7 -1
- package/build-module/dom/is-empty.js +10 -14
- package/build-module/dom/is-empty.js.map +7 -1
- package/build-module/dom/is-entirely-selected.js +18 -45
- package/build-module/dom/is-entirely-selected.js.map +7 -1
- package/build-module/dom/is-form-element.js +8 -19
- package/build-module/dom/is-form-element.js.map +7 -1
- package/build-module/dom/is-horizontal-edge.js +6 -15
- package/build-module/dom/is-horizontal-edge.js.map +7 -1
- package/build-module/dom/is-html-input-element.js +6 -9
- package/build-module/dom/is-html-input-element.js.map +7 -1
- package/build-module/dom/is-input-or-text-area.js +6 -9
- package/build-module/dom/is-input-or-text-area.js.map +7 -1
- package/build-module/dom/is-number-input.js +11 -25
- package/build-module/dom/is-number-input.js.map +7 -1
- package/build-module/dom/is-rtl.js +7 -15
- package/build-module/dom/is-rtl.js.map +7 -1
- package/build-module/dom/is-selection-forward.js +9 -37
- package/build-module/dom/is-selection-forward.js.map +7 -1
- package/build-module/dom/is-text-field.js +22 -20
- package/build-module/dom/is-text-field.js.map +7 -1
- package/build-module/dom/is-vertical-edge.js +6 -15
- package/build-module/dom/is-vertical-edge.js.map +7 -1
- package/build-module/dom/place-caret-at-edge.js +22 -48
- package/build-module/dom/place-caret-at-edge.js.map +7 -1
- package/build-module/dom/place-caret-at-horizontal-edge.js +7 -14
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +7 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +6 -14
- package/build-module/dom/place-caret-at-vertical-edge.js.map +7 -1
- package/build-module/dom/remove-invalid-html.js +7 -17
- package/build-module/dom/remove-invalid-html.js.map +7 -1
- package/build-module/dom/remove.js +7 -14
- package/build-module/dom/remove.js.map +7 -1
- package/build-module/dom/replace-tag.js +7 -16
- package/build-module/dom/replace-tag.js.map +7 -1
- package/build-module/dom/replace.js +9 -17
- package/build-module/dom/replace.js.map +7 -1
- package/build-module/dom/safe-html.js +11 -23
- package/build-module/dom/safe-html.js.map +7 -1
- package/build-module/dom/scroll-if-no-range.js +5 -15
- package/build-module/dom/scroll-if-no-range.js.map +7 -1
- package/build-module/dom/strip-html.js +8 -18
- package/build-module/dom/strip-html.js.map +7 -1
- package/build-module/dom/unwrap.js +7 -15
- package/build-module/dom/unwrap.js.map +7 -1
- package/build-module/dom/wrap.js +7 -14
- package/build-module/dom/wrap.js.map +7 -1
- package/build-module/focusable.js +30 -81
- package/build-module/focusable.js.map +7 -1
- package/build-module/index.js +9 -17
- package/build-module/index.js.map +7 -1
- package/build-module/phrasing-content.js +67 -125
- package/build-module/phrasing-content.js.map +7 -1
- package/build-module/tabbable.js +30 -133
- package/build-module/tabbable.js.map +7 -1
- package/build-module/utils/assert-is-defined.js +9 -4
- package/build-module/utils/assert-is-defined.js.map +7 -1
- package/package.json +11 -4
package/build/data-transfer.js
CHANGED
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var data_transfer_exports = {};
|
|
20
|
+
__export(data_transfer_exports, {
|
|
21
|
+
getFilesFromDataTransfer: () => getFilesFromDataTransfer
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Gets all files from a DataTransfer object.
|
|
9
|
-
*
|
|
10
|
-
* @param {DataTransfer} dataTransfer DataTransfer object to inspect.
|
|
11
|
-
*
|
|
12
|
-
* @return {File[]} An array containing all files.
|
|
13
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(data_transfer_exports);
|
|
14
24
|
function getFilesFromDataTransfer(dataTransfer) {
|
|
15
25
|
const files = Array.from(dataTransfer.files);
|
|
16
|
-
Array.from(dataTransfer.items).forEach(item => {
|
|
26
|
+
Array.from(dataTransfer.items).forEach((item) => {
|
|
17
27
|
const file = item.getAsFile();
|
|
18
|
-
if (file && !files.find(
|
|
19
|
-
name,
|
|
20
|
-
|
|
21
|
-
size
|
|
22
|
-
}) => name === file.name && type === file.type && size === file.size)) {
|
|
28
|
+
if (file && !files.find(
|
|
29
|
+
({ name, type, size }) => name === file.name && type === file.type && size === file.size
|
|
30
|
+
)) {
|
|
23
31
|
files.push(file);
|
|
24
32
|
}
|
|
25
33
|
});
|
|
26
34
|
return files;
|
|
27
35
|
}
|
|
28
|
-
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
getFilesFromDataTransfer
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=data-transfer.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/data-transfer.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Gets all files from a DataTransfer object.\n *\n * @param {DataTransfer} dataTransfer DataTransfer object to inspect.\n *\n * @return {File[]} An array containing all files.\n */\nexport function getFilesFromDataTransfer( dataTransfer ) {\n\tconst files = Array.from( dataTransfer.files );\n\n\tArray.from( dataTransfer.items ).forEach( ( item ) => {\n\t\tconst file = item.getAsFile();\n\n\t\tif (\n\t\t\tfile &&\n\t\t\t! files.find(\n\t\t\t\t( { name, type, size } ) =>\n\t\t\t\t\tname === file.name &&\n\t\t\t\t\ttype === file.type &&\n\t\t\t\t\tsize === file.size\n\t\t\t)\n\t\t) {\n\t\t\tfiles.push( file );\n\t\t}\n\t} );\n\n\treturn files;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,yBAA0B,cAAe;AACxD,QAAM,QAAQ,MAAM,KAAM,aAAa,KAAM;AAE7C,QAAM,KAAM,aAAa,KAAM,EAAE,QAAS,CAAE,SAAU;AACrD,UAAM,OAAO,KAAK,UAAU;AAE5B,QACC,QACA,CAAE,MAAM;AAAA,MACP,CAAE,EAAE,MAAM,MAAM,KAAK,MACpB,SAAS,KAAK,QACd,SAAS,KAAK,QACd,SAAS,KAAK;AAAA,IAChB,GACC;AACD,YAAM,KAAM,IAAK;AAAA,IAClB;AAAA,EACD,CAAE;AAEF,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var caret_range_from_point_exports = {};
|
|
20
|
+
__export(caret_range_from_point_exports, {
|
|
21
|
+
default: () => caretRangeFromPoint
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Polyfill.
|
|
9
|
-
* Get a collapsed range for a given point.
|
|
10
|
-
*
|
|
11
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
|
12
|
-
*
|
|
13
|
-
* @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
|
|
14
|
-
* @param {number} x Horizontal position within the current viewport.
|
|
15
|
-
* @param {number} y Vertical position within the current viewport.
|
|
16
|
-
*
|
|
17
|
-
* @return {Range | null} The best range for the given point.
|
|
18
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(caret_range_from_point_exports);
|
|
19
24
|
function caretRangeFromPoint(doc, x, y) {
|
|
20
25
|
if (doc.caretRangeFromPoint) {
|
|
21
26
|
return doc.caretRangeFromPoint(x, y);
|
|
@@ -24,9 +29,6 @@ function caretRangeFromPoint(doc, x, y) {
|
|
|
24
29
|
return null;
|
|
25
30
|
}
|
|
26
31
|
const point = doc.caretPositionFromPoint(x, y);
|
|
27
|
-
|
|
28
|
-
// If x or y are negative, outside viewport, or there is no text entry node.
|
|
29
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
|
30
32
|
if (!point) {
|
|
31
33
|
return null;
|
|
32
34
|
}
|
|
@@ -35,9 +37,4 @@ function caretRangeFromPoint(doc, x, y) {
|
|
|
35
37
|
range.collapse(true);
|
|
36
38
|
return range;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
|
|
41
|
-
* @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
|
|
42
|
-
*/
|
|
43
|
-
//# sourceMappingURL=caret-range-from-point.js.map
|
|
40
|
+
//# sourceMappingURL=caret-range-from-point.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/caret-range-from-point.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n *\n * @return {Range | null} The best range for the given point.\n */\nexport default function caretRangeFromPoint( doc, x, y ) {\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\tif ( ! doc.caretPositionFromPoint ) {\n\t\treturn null;\n\t}\n\n\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n\tif ( ! point ) {\n\t\treturn null;\n\t}\n\n\tconst range = doc.createRange();\n\n\trange.setStart( point.offsetNode, point.offset );\n\trange.collapse( true );\n\n\treturn range;\n}\n\n/**\n * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint\n * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition\n */\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYe,SAAR,oBAAsC,KAAK,GAAG,GAAI;AACxD,MAAK,IAAI,qBAAsB;AAC9B,WAAO,IAAI,oBAAqB,GAAG,CAAE;AAAA,EACtC;AAEA,MAAK,CAAE,IAAI,wBAAyB;AACnC,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,IAAI,uBAAwB,GAAG,CAAE;AAI/C,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,IAAI,YAAY;AAE9B,QAAM,SAAU,MAAM,YAAY,MAAM,MAAO;AAC/C,QAAM,SAAU,IAAK;AAErB,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,145 +1,138 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var clean_node_list_exports = {};
|
|
30
|
+
__export(clean_node_list_exports, {
|
|
31
|
+
default: () => cleanNodeList
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const noop = () => {};
|
|
19
|
-
|
|
20
|
-
/* eslint-disable jsdoc/valid-types */
|
|
21
|
-
/**
|
|
22
|
-
* @typedef SchemaItem
|
|
23
|
-
* @property {string[]} [attributes] Attributes.
|
|
24
|
-
* @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.
|
|
25
|
-
* @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.
|
|
26
|
-
* @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.
|
|
27
|
-
* @property {boolean} allowEmpty Whether to allow nodes without children.
|
|
28
|
-
* @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/** @typedef {{ [tag: string]: SchemaItem }} Schema */
|
|
32
|
-
/* eslint-enable jsdoc/valid-types */
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Given a schema, unwraps or removes nodes, attributes and classes on a node
|
|
36
|
-
* list.
|
|
37
|
-
*
|
|
38
|
-
* @param {NodeList} nodeList The nodeList to filter.
|
|
39
|
-
* @param {Document} doc The document of the nodeList.
|
|
40
|
-
* @param {Schema} schema An array of functions that can mutate with the provided node.
|
|
41
|
-
* @param {boolean} inline Whether to clean for inline mode.
|
|
42
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(clean_node_list_exports);
|
|
34
|
+
var import_is_empty = __toESM(require("./is-empty"));
|
|
35
|
+
var import_remove = __toESM(require("./remove"));
|
|
36
|
+
var import_unwrap = __toESM(require("./unwrap"));
|
|
37
|
+
var import_phrasing_content = require("../phrasing-content");
|
|
38
|
+
var import_insert_after = __toESM(require("./insert-after"));
|
|
39
|
+
var import_is_element = __toESM(require("./is-element"));
|
|
40
|
+
const noop = () => {
|
|
41
|
+
};
|
|
43
42
|
function cleanNodeList(nodeList, doc, schema, inline) {
|
|
44
|
-
Array.from(nodeList).forEach(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
allowEmpty
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
if (node.hasAttributes()) {
|
|
66
|
-
// Strip invalid attributes.
|
|
67
|
-
Array.from(node.attributes).forEach(({
|
|
68
|
-
name
|
|
69
|
-
}) => {
|
|
70
|
-
if (name !== 'class' && !attributes.includes(name)) {
|
|
71
|
-
node.removeAttribute(name);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Strip invalid classes.
|
|
76
|
-
// In jsdom-jscore, 'node.classList' can be undefined.
|
|
77
|
-
// TODO: Explore patching this in jsdom-jscore.
|
|
78
|
-
if (node.classList && node.classList.length) {
|
|
79
|
-
const mattchers = classes.map(item => {
|
|
80
|
-
if (item === '*') {
|
|
81
|
-
// Keep all classes.
|
|
82
|
-
return () => true;
|
|
83
|
-
} else if (typeof item === 'string') {
|
|
84
|
-
return (/** @type {string} */className) => className === item;
|
|
85
|
-
} else if (item instanceof RegExp) {
|
|
86
|
-
return (/** @type {string} */className) => item.test(className);
|
|
43
|
+
Array.from(nodeList).forEach(
|
|
44
|
+
(node) => {
|
|
45
|
+
const tag = node.nodeName.toLowerCase();
|
|
46
|
+
if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch?.(node))) {
|
|
47
|
+
if ((0, import_is_element.default)(node)) {
|
|
48
|
+
const {
|
|
49
|
+
attributes = [],
|
|
50
|
+
classes = [],
|
|
51
|
+
children,
|
|
52
|
+
require: require2 = [],
|
|
53
|
+
allowEmpty
|
|
54
|
+
} = schema[tag];
|
|
55
|
+
if (children && !allowEmpty && (0, import_is_empty.default)(node)) {
|
|
56
|
+
(0, import_remove.default)(node);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (node.hasAttributes()) {
|
|
60
|
+
Array.from(node.attributes).forEach(({ name }) => {
|
|
61
|
+
if (name !== "class" && !attributes.includes(name)) {
|
|
62
|
+
node.removeAttribute(name);
|
|
87
63
|
}
|
|
88
|
-
return noop;
|
|
89
64
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
65
|
+
if (node.classList && node.classList.length) {
|
|
66
|
+
const mattchers = classes.map((item) => {
|
|
67
|
+
if (item === "*") {
|
|
68
|
+
return () => true;
|
|
69
|
+
} else if (typeof item === "string") {
|
|
70
|
+
return (className) => className === item;
|
|
71
|
+
} else if (item instanceof RegExp) {
|
|
72
|
+
return (className) => item.test(className);
|
|
73
|
+
}
|
|
74
|
+
return noop;
|
|
75
|
+
});
|
|
76
|
+
Array.from(node.classList).forEach((name) => {
|
|
77
|
+
if (!mattchers.some(
|
|
78
|
+
(isMatch) => isMatch(name)
|
|
79
|
+
)) {
|
|
80
|
+
node.classList.remove(name);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (!node.classList.length) {
|
|
84
|
+
node.removeAttribute("class");
|
|
93
85
|
}
|
|
94
|
-
});
|
|
95
|
-
if (!node.classList.length) {
|
|
96
|
-
node.removeAttribute('class');
|
|
97
86
|
}
|
|
98
87
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
(0,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
(
|
|
88
|
+
if (node.hasChildNodes()) {
|
|
89
|
+
if (children === "*") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (children) {
|
|
93
|
+
if (require2.length && !node.querySelector(require2.join(","))) {
|
|
94
|
+
cleanNodeList(
|
|
95
|
+
node.childNodes,
|
|
96
|
+
doc,
|
|
97
|
+
schema,
|
|
98
|
+
inline
|
|
99
|
+
);
|
|
100
|
+
(0, import_unwrap.default)(node);
|
|
101
|
+
} else if (node.parentNode && node.parentNode.nodeName === "BODY" && (0, import_phrasing_content.isPhrasingContent)(node)) {
|
|
102
|
+
cleanNodeList(
|
|
103
|
+
node.childNodes,
|
|
104
|
+
doc,
|
|
105
|
+
schema,
|
|
106
|
+
inline
|
|
107
|
+
);
|
|
108
|
+
if (Array.from(node.childNodes).some(
|
|
109
|
+
(child) => !(0, import_phrasing_content.isPhrasingContent)(child)
|
|
110
|
+
)) {
|
|
111
|
+
(0, import_unwrap.default)(node);
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
cleanNodeList(
|
|
115
|
+
node.childNodes,
|
|
116
|
+
doc,
|
|
117
|
+
children,
|
|
118
|
+
inline
|
|
119
|
+
);
|
|
120
120
|
}
|
|
121
121
|
} else {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
} else {
|
|
126
|
-
while (node.firstChild) {
|
|
127
|
-
(0, _remove.default)(node.firstChild);
|
|
122
|
+
while (node.firstChild) {
|
|
123
|
+
(0, import_remove.default)(node.firstChild);
|
|
124
|
+
}
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
}
|
|
128
|
+
} else {
|
|
129
|
+
cleanNodeList(node.childNodes, doc, schema, inline);
|
|
130
|
+
if (inline && !(0, import_phrasing_content.isPhrasingContent)(node) && node.nextElementSibling) {
|
|
131
|
+
(0, import_insert_after.default)(doc.createElement("br"), node);
|
|
132
|
+
}
|
|
133
|
+
(0, import_unwrap.default)(node);
|
|
131
134
|
}
|
|
132
|
-
// Invalid child. Continue with schema at the same place and unwrap.
|
|
133
|
-
} else {
|
|
134
|
-
cleanNodeList(node.childNodes, doc, schema, inline);
|
|
135
|
-
|
|
136
|
-
// For inline mode, insert a line break when unwrapping nodes that
|
|
137
|
-
// are not phrasing content.
|
|
138
|
-
if (inline && !(0, _phrasingContent.isPhrasingContent)(node) && node.nextElementSibling) {
|
|
139
|
-
(0, _insertAfter.default)(doc.createElement('br'), node);
|
|
140
|
-
}
|
|
141
|
-
(0, _unwrap.default)(node);
|
|
142
135
|
}
|
|
143
|
-
|
|
136
|
+
);
|
|
144
137
|
}
|
|
145
|
-
//# sourceMappingURL=clean-node-list.js.map
|
|
138
|
+
//# sourceMappingURL=clean-node-list.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_isEmpty","_interopRequireDefault","require","_remove","_unwrap","_phrasingContent","_insertAfter","_isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","isElement","attributes","classes","children","allowEmpty","isEmpty","remove","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","unwrap","parentNode","isPhrasingContent","child","firstChild","nextElementSibling","insertAfter","createElement"],"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( item === '*' ) {\n\t\t\t\t\t\t\t\t\t// Keep all classes.\n\t\t\t\t\t\t\t\t\treturn () => true;\n\t\t\t\t\t\t\t\t} else if ( typeof item === 'string' ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => className === item;\n\t\t\t\t\t\t\t\t} else if ( item instanceof RegExp ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => item.test( className );\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn noop;\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tArray.from( node.classList ).forEach( ( name ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! mattchers.some( ( isMatch ) =>\n\t\t\t\t\t\t\t\t\t\tisMatch( name )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnode.classList.remove( name );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tif ( ! node.classList.length ) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( 'class' );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasChildNodes() ) {\n\t\t\t\t\t\t// Do not filter any content.\n\t\t\t\t\t\tif ( children === '*' ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Continue if the node is supposed to have children.\n\t\t\t\t\t\tif ( children ) {\n\t\t\t\t\t\t\t// If a parent requires certain children, but it does\n\t\t\t\t\t\t\t// not have them, drop the parent and continue.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\trequire.length &&\n\t\t\t\t\t\t\t\t! node.querySelector( require.join( ',' ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t// If the node is at the top, phrasing content, and\n\t\t\t\t\t\t\t\t// contains children that are block content, unwrap\n\t\t\t\t\t\t\t\t// the node because it is invalid.\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tnode.parentNode &&\n\t\t\t\t\t\t\t\tnode.parentNode.nodeName === 'BODY' &&\n\t\t\t\t\t\t\t\tisPhrasingContent( node )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tArray.from( node.childNodes ).some(\n\t\t\t\t\t\t\t\t\t\t( child ) =>\n\t\t\t\t\t\t\t\t\t\t\t! isPhrasingContent( child )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Remove children if the node is not supposed to have any.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twhile ( node.firstChild ) {\n\t\t\t\t\t\t\t\tremove( node.firstChild );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid child. Continue with schema at the same place and unwrap.\n\t\t\t} else {\n\t\t\t\tcleanNodeList( node.childNodes, doc, schema, inline );\n\n\t\t\t\t// For inline mode, insert a line break when unwrapping nodes that\n\t\t\t\t// are not phrasing content.\n\t\t\t\tif (\n\t\t\t\t\tinline &&\n\t\t\t\t\t! isPhrasingContent( node ) &&\n\t\t\t\t\tnode.nextElementSibling\n\t\t\t\t) {\n\t\t\t\t\tinsertAfter( doc.createElement( 'br' ), node );\n\t\t\t\t}\n\n\t\t\t\tunwrap( node );\n\t\t\t}\n\t\t}\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IA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C,oBAAW,EAAE1C,GAAG,CAAC2C,aAAa,CAAE,IAAK,CAAC,EAAErC,IAAK,CAAC;MAC/C;MAEA,IAAA8B,eAAM,EAAE9B,IAAK,CAAC;IACf;EACD,CACD,CAAC;AACF","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/clean-node-list.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( item === '*' ) {\n\t\t\t\t\t\t\t\t\t// Keep all classes.\n\t\t\t\t\t\t\t\t\treturn () => true;\n\t\t\t\t\t\t\t\t} else if ( typeof item === 'string' ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => className === item;\n\t\t\t\t\t\t\t\t} else if ( item instanceof RegExp ) {\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t/** @type {string} */ className\n\t\t\t\t\t\t\t\t\t) => item.test( className );\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn noop;\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tArray.from( node.classList ).forEach( ( name ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! mattchers.some( ( isMatch ) =>\n\t\t\t\t\t\t\t\t\t\tisMatch( name )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tnode.classList.remove( name );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tif ( ! node.classList.length ) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( 'class' );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasChildNodes() ) {\n\t\t\t\t\t\t// Do not filter any content.\n\t\t\t\t\t\tif ( children === '*' ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Continue if the node is supposed to have children.\n\t\t\t\t\t\tif ( children ) {\n\t\t\t\t\t\t\t// If a parent requires certain children, but it does\n\t\t\t\t\t\t\t// not have them, drop the parent and continue.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\trequire.length &&\n\t\t\t\t\t\t\t\t! node.querySelector( require.join( ',' ) )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t// If the node is at the top, phrasing content, and\n\t\t\t\t\t\t\t\t// contains children that are block content, unwrap\n\t\t\t\t\t\t\t\t// the node because it is invalid.\n\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\tnode.parentNode &&\n\t\t\t\t\t\t\t\tnode.parentNode.nodeName === 'BODY' &&\n\t\t\t\t\t\t\t\tisPhrasingContent( node )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tArray.from( node.childNodes ).some(\n\t\t\t\t\t\t\t\t\t\t( child ) =>\n\t\t\t\t\t\t\t\t\t\t\t! isPhrasingContent( child )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tunwrap( node );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcleanNodeList(\n\t\t\t\t\t\t\t\t\tnode.childNodes,\n\t\t\t\t\t\t\t\t\tdoc,\n\t\t\t\t\t\t\t\t\tchildren,\n\t\t\t\t\t\t\t\t\tinline\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Remove children if the node is not supposed to have any.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twhile ( node.firstChild ) {\n\t\t\t\t\t\t\t\tremove( node.firstChild );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Invalid child. Continue with schema at the same place and unwrap.\n\t\t\t} else {\n\t\t\t\tcleanNodeList( node.childNodes, doc, schema, inline );\n\n\t\t\t\t// For inline mode, insert a line break when unwrapping nodes that\n\t\t\t\t// are not phrasing content.\n\t\t\t\tif (\n\t\t\t\t\tinline &&\n\t\t\t\t\t! isPhrasingContent( node ) &&\n\t\t\t\t\tnode.nextElementSibling\n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ED,OAAO;AACN,sBAAe,KAAK,YAAY,KAAK,QAAQ,MAAO;AAIpD,YACC,UACA,KAAE,2CAAmB,IAAK,KAC1B,KAAK,oBACJ;AACD,kCAAAE,SAAa,IAAI,cAAe,IAAK,GAAG,IAAK;AAAA,QAC9C;AAEA,0BAAAD,SAAQ,IAAK;AAAA,MACd;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["isElement", "require", "isEmpty", "remove", "unwrap", "insertAfter"]
|
|
7
|
+
}
|
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var compute_caret_rect_exports = {};
|
|
30
|
+
__export(compute_caret_rect_exports, {
|
|
31
|
+
default: () => computeCaretRect
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get the rectangle for the selection in a container.
|
|
16
|
-
*
|
|
17
|
-
* @param {Window} win The window of the selection.
|
|
18
|
-
*
|
|
19
|
-
* @return {DOMRect | null} The rectangle.
|
|
20
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(compute_caret_rect_exports);
|
|
34
|
+
var import_get_rectangle_from_range = __toESM(require("./get-rectangle-from-range"));
|
|
35
|
+
var import_assert_is_defined = require("../utils/assert-is-defined");
|
|
21
36
|
function computeCaretRect(win) {
|
|
22
37
|
const selection = win.getSelection();
|
|
23
|
-
(0,
|
|
38
|
+
(0, import_assert_is_defined.assertIsDefined)(selection, "selection");
|
|
24
39
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
|
25
40
|
if (!range) {
|
|
26
41
|
return null;
|
|
27
42
|
}
|
|
28
|
-
return (0,
|
|
43
|
+
return (0, import_get_rectangle_from_range.default)(range);
|
|
29
44
|
}
|
|
30
|
-
//# sourceMappingURL=compute-caret-rect.js.map
|
|
45
|
+
//# sourceMappingURL=compute-caret-rect.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/compute-caret-rect.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle for the selection in a container.\n *\n * @param {Window} win The window of the selection.\n *\n * @return {DOMRect | null} The rectangle.\n */\nexport default function computeCaretRect( win ) {\n\tconst selection = win.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tconst range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;\n\n\tif ( ! range ) {\n\t\treturn null;\n\t}\n\n\treturn getRectangleFromRange( range );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sCAAkC;AAClC,+BAAgC;AASjB,SAAR,iBAAmC,KAAM;AAC/C,QAAM,YAAY,IAAI,aAAa;AACnC,gDAAiB,WAAW,WAAY;AACxC,QAAM,QAAQ,UAAU,aAAa,UAAU,WAAY,CAAE,IAAI;AAEjE,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,aAAO,gCAAAA,SAAuB,KAAM;AACrC;",
|
|
6
|
+
"names": ["getRectangleFromRange"]
|
|
7
|
+
}
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var document_has_selection_exports = {};
|
|
30
|
+
__export(document_has_selection_exports, {
|
|
31
|
+
default: () => documentHasSelection
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Check whether the current document has a selection. This includes focus in
|
|
17
|
-
* input fields, textareas, and general rich-text selection.
|
|
18
|
-
*
|
|
19
|
-
* @param {Document} doc The document to check.
|
|
20
|
-
*
|
|
21
|
-
* @return {boolean} True if there is selection, false if not.
|
|
22
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(document_has_selection_exports);
|
|
34
|
+
var import_is_text_field = __toESM(require("./is-text-field"));
|
|
35
|
+
var import_is_html_input_element = __toESM(require("./is-html-input-element"));
|
|
36
|
+
var import_document_has_text_selection = __toESM(require("./document-has-text-selection"));
|
|
23
37
|
function documentHasSelection(doc) {
|
|
24
|
-
return !!doc.activeElement && ((0,
|
|
38
|
+
return !!doc.activeElement && ((0, import_is_html_input_element.default)(doc.activeElement) || (0, import_is_text_field.default)(doc.activeElement) || (0, import_document_has_text_selection.default)(doc));
|
|
25
39
|
}
|
|
26
|
-
//# sourceMappingURL=document-has-selection.js.map
|
|
40
|
+
//# sourceMappingURL=document-has-selection.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/document-has-selection.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\nimport documentHasTextSelection from './document-has-text-selection';\n\n/**\n * Check whether the current document has a selection. This includes focus in\n * input fields, textareas, and general rich-text selection.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} True if there is selection, false if not.\n */\nexport default function documentHasSelection( doc ) {\n\treturn (\n\t\t!! doc.activeElement &&\n\t\t( isHTMLInputElement( doc.activeElement ) ||\n\t\t\tisTextField( doc.activeElement ) ||\n\t\t\tdocumentHasTextSelection( doc ) )\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAwB;AACxB,mCAA+B;AAC/B,yCAAqC;AAUtB,SAAR,qBAAuC,KAAM;AACnD,SACC,CAAC,CAAE,IAAI,sBACL,6BAAAA,SAAoB,IAAI,aAAc,SACvC,qBAAAC,SAAa,IAAI,aAAc,SAC/B,mCAAAC,SAA0B,GAAI;AAEjC;",
|
|
6
|
+
"names": ["isHTMLInputElement", "isTextField", "documentHasTextSelection"]
|
|
7
|
+
}
|