@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
|
@@ -1,49 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns true if the given selection object is in the forward direction, or
|
|
8
|
-
* false otherwise.
|
|
9
|
-
*
|
|
10
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
|
|
11
|
-
*
|
|
12
|
-
* @param {Selection} selection Selection object to check.
|
|
13
|
-
*
|
|
14
|
-
* @return {boolean} Whether the selection is forward.
|
|
15
|
-
*/
|
|
16
|
-
export default function isSelectionForward(selection) {
|
|
17
|
-
const {
|
|
18
|
-
anchorNode,
|
|
19
|
-
focusNode,
|
|
20
|
-
anchorOffset,
|
|
21
|
-
focusOffset
|
|
22
|
-
} = selection;
|
|
23
|
-
assertIsDefined(anchorNode, 'anchorNode');
|
|
24
|
-
assertIsDefined(focusNode, 'focusNode');
|
|
1
|
+
import { assertIsDefined } from "../utils/assert-is-defined";
|
|
2
|
+
function isSelectionForward(selection) {
|
|
3
|
+
const { anchorNode, focusNode, anchorOffset, focusOffset } = selection;
|
|
4
|
+
assertIsDefined(anchorNode, "anchorNode");
|
|
5
|
+
assertIsDefined(focusNode, "focusNode");
|
|
25
6
|
const position = anchorNode.compareDocumentPosition(focusNode);
|
|
26
|
-
|
|
27
|
-
// Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
|
|
28
|
-
// so bitwise operators are intended.
|
|
29
|
-
/* eslint-disable no-bitwise */
|
|
30
|
-
// Compare whether anchor node precedes focus node. If focus node (where
|
|
31
|
-
// end of selection occurs) is after the anchor node, it is forward.
|
|
32
7
|
if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
|
|
33
8
|
return false;
|
|
34
9
|
}
|
|
35
10
|
if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
|
|
36
11
|
return true;
|
|
37
12
|
}
|
|
38
|
-
/* eslint-enable no-bitwise */
|
|
39
|
-
|
|
40
|
-
// `compareDocumentPosition` returns 0 when passed the same node, in which
|
|
41
|
-
// case compare offsets.
|
|
42
13
|
if (position === 0) {
|
|
43
14
|
return anchorOffset <= focusOffset;
|
|
44
15
|
}
|
|
45
|
-
|
|
46
|
-
// This should never be reached, but return true as default case.
|
|
47
16
|
return true;
|
|
48
17
|
}
|
|
49
|
-
|
|
18
|
+
export {
|
|
19
|
+
isSelectionForward as default
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=is-selection-forward.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/is-selection-forward.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Returns true if the given selection object is in the forward direction, or\n * false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition\n *\n * @param {Selection} selection Selection object to check.\n *\n * @return {boolean} Whether the selection is forward.\n */\nexport default function isSelectionForward( selection ) {\n\tconst { anchorNode, focusNode, anchorOffset, focusOffset } = selection;\n\n\tassertIsDefined( anchorNode, 'anchorNode' );\n\tassertIsDefined( focusNode, 'focusNode' );\n\tconst position = anchorNode.compareDocumentPosition( focusNode );\n\n\t// Disable reason: `Node#compareDocumentPosition` returns a bitmask value,\n\t// so bitwise operators are intended.\n\t/* eslint-disable no-bitwise */\n\t// Compare whether anchor node precedes focus node. If focus node (where\n\t// end of selection occurs) is after the anchor node, it is forward.\n\tif ( position & anchorNode.DOCUMENT_POSITION_PRECEDING ) {\n\t\treturn false;\n\t}\n\n\tif ( position & anchorNode.DOCUMENT_POSITION_FOLLOWING ) {\n\t\treturn true;\n\t}\n\t/* eslint-enable no-bitwise */\n\n\t// `compareDocumentPosition` returns 0 when passed the same node, in which\n\t// case compare offsets.\n\tif ( position === 0 ) {\n\t\treturn anchorOffset <= focusOffset;\n\t}\n\n\t// This should never be reached, but return true as default case.\n\treturn true;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,uBAAuB;AAYjB,SAAR,mBAAqC,WAAY;AACvD,QAAM,EAAE,YAAY,WAAW,cAAc,YAAY,IAAI;AAE7D,kBAAiB,YAAY,YAAa;AAC1C,kBAAiB,WAAW,WAAY;AACxC,QAAM,WAAW,WAAW,wBAAyB,SAAU;AAO/D,MAAK,WAAW,WAAW,6BAA8B;AACxD,WAAO;AAAA,EACR;AAEA,MAAK,WAAW,WAAW,6BAA8B;AACxD,WAAO;AAAA,EACR;AAKA,MAAK,aAAa,GAAI;AACrB,WAAO,gBAAgB;AAAA,EACxB;AAGA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' || /** @type {HTMLElement} */node.contentEditable === 'true';
|
|
1
|
+
import isHTMLInputElement from "./is-html-input-element";
|
|
2
|
+
function isTextField(node) {
|
|
3
|
+
const nonTextInputs = [
|
|
4
|
+
"button",
|
|
5
|
+
"checkbox",
|
|
6
|
+
"hidden",
|
|
7
|
+
"file",
|
|
8
|
+
"radio",
|
|
9
|
+
"image",
|
|
10
|
+
"range",
|
|
11
|
+
"reset",
|
|
12
|
+
"submit",
|
|
13
|
+
"number",
|
|
14
|
+
"email",
|
|
15
|
+
"time"
|
|
16
|
+
];
|
|
17
|
+
return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === "TEXTAREA" || /** @type {HTMLElement} */
|
|
18
|
+
node.contentEditable === "true";
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
export {
|
|
21
|
+
isTextField as default
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=is-text-field.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/is-text-field.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isHTMLInputElement from './is-html-input-element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Check whether the given element is a text field, where text field is defined\n * by the ability to select within the input, or that it is contenteditable.\n *\n * See: https://html.spec.whatwg.org/#textFieldSelection\n *\n * @param {Node} node The HTML element.\n * @return {node is HTMLElement} True if the element is an text field, false if not.\n */\nexport default function isTextField( node ) {\n\t/* eslint-enable jsdoc/valid-types */\n\tconst nonTextInputs = [\n\t\t'button',\n\t\t'checkbox',\n\t\t'hidden',\n\t\t'file',\n\t\t'radio',\n\t\t'image',\n\t\t'range',\n\t\t'reset',\n\t\t'submit',\n\t\t'number',\n\t\t'email',\n\t\t'time',\n\t];\n\treturn (\n\t\t( isHTMLInputElement( node ) &&\n\t\t\tnode.type &&\n\t\t\t! nonTextInputs.includes( node.type ) ) ||\n\t\tnode.nodeName === 'TEXTAREA' ||\n\t\t/** @type {HTMLElement} */ ( node ).contentEditable === 'true'\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,wBAAwB;AAYhB,SAAR,YAA8B,MAAO;AAE3C,QAAM,gBAAgB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,SACG,mBAAoB,IAAK,KAC1B,KAAK,QACL,CAAE,cAAc,SAAU,KAAK,IAAK,KACrC,KAAK,aAAa;AAAA,EACW,KAAO,oBAAoB;AAE1D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import isEdge from './is-edge';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Check whether the selection is vertically at the edge of the container.
|
|
8
|
-
*
|
|
9
|
-
* @param {HTMLElement} container Focusable element.
|
|
10
|
-
* @param {boolean} isReverse Set to true to check top, false for bottom.
|
|
11
|
-
*
|
|
12
|
-
* @return {boolean} True if at the vertical edge, false if not.
|
|
13
|
-
*/
|
|
14
|
-
export default function isVerticalEdge(container, isReverse) {
|
|
1
|
+
import isEdge from "./is-edge";
|
|
2
|
+
function isVerticalEdge(container, isReverse) {
|
|
15
3
|
return isEdge(container, isReverse, true);
|
|
16
4
|
}
|
|
17
|
-
|
|
5
|
+
export {
|
|
6
|
+
isVerticalEdge as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=is-vertical-edge.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/is-vertical-edge.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isEdge from './is-edge';\n\n/**\n * Check whether the selection is vertically at the edge of the container.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check top, false for bottom.\n *\n * @return {boolean} True if at the vertical edge, false if not.\n */\nexport default function isVerticalEdge( container, isReverse ) {\n\treturn isEdge( container, isReverse, true );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,YAAY;AAUJ,SAAR,eAAiC,WAAW,WAAY;AAC9D,SAAO,OAAQ,WAAW,WAAW,IAAK;AAC3C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import isInputOrTextArea from './is-input-or-text-area';
|
|
7
|
-
import isRTL from './is-rtl';
|
|
8
|
-
import { scrollIfNoRange } from './scroll-if-no-range';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Gets the range to place.
|
|
12
|
-
*
|
|
13
|
-
* @param {HTMLElement} container Focusable element.
|
|
14
|
-
* @param {boolean} isReverse True for end, false for start.
|
|
15
|
-
* @param {number|undefined} x X coordinate to vertically position.
|
|
16
|
-
*
|
|
17
|
-
* @return {Range|null} The range to place.
|
|
18
|
-
*/
|
|
1
|
+
import hiddenCaretRangeFromPoint from "./hidden-caret-range-from-point";
|
|
2
|
+
import { assertIsDefined } from "../utils/assert-is-defined";
|
|
3
|
+
import isInputOrTextArea from "./is-input-or-text-area";
|
|
4
|
+
import isRTL from "./is-rtl";
|
|
5
|
+
import { scrollIfNoRange } from "./scroll-if-no-range";
|
|
19
6
|
function getRange(container, isReverse, x) {
|
|
20
|
-
const {
|
|
21
|
-
ownerDocument
|
|
22
|
-
} = container;
|
|
23
|
-
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
|
7
|
+
const { ownerDocument } = container;
|
|
24
8
|
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
|
|
25
9
|
const containerRect = container.getBoundingClientRect();
|
|
26
|
-
|
|
27
|
-
// right corner. When placing at the start, to the top left corner.
|
|
28
|
-
// Ensure x is defined and within the container's boundaries. When it's
|
|
29
|
-
// exactly at the boundary, it's not considered within the boundaries.
|
|
30
|
-
if (x === undefined) {
|
|
10
|
+
if (x === void 0) {
|
|
31
11
|
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
|
32
12
|
} else if (x <= containerRect.left) {
|
|
33
13
|
x = containerRect.left + 1;
|
|
@@ -37,22 +17,13 @@ function getRange(container, isReverse, x) {
|
|
|
37
17
|
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
|
38
18
|
return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
|
|
39
19
|
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Places the caret at start or end of a given element.
|
|
43
|
-
*
|
|
44
|
-
* @param {HTMLElement} container Focusable element.
|
|
45
|
-
* @param {boolean} isReverse True for end, false for start.
|
|
46
|
-
* @param {number|undefined} x X coordinate to vertically position.
|
|
47
|
-
*/
|
|
48
|
-
export default function placeCaretAtEdge(container, isReverse, x) {
|
|
20
|
+
function placeCaretAtEdge(container, isReverse, x) {
|
|
49
21
|
if (!container) {
|
|
50
22
|
return;
|
|
51
23
|
}
|
|
52
24
|
container.focus();
|
|
53
25
|
if (isInputOrTextArea(container)) {
|
|
54
|
-
|
|
55
|
-
if (typeof container.selectionStart !== 'number') {
|
|
26
|
+
if (typeof container.selectionStart !== "number") {
|
|
56
27
|
return;
|
|
57
28
|
}
|
|
58
29
|
if (isReverse) {
|
|
@@ -67,20 +38,23 @@ export default function placeCaretAtEdge(container, isReverse, x) {
|
|
|
67
38
|
if (!container.isContentEditable) {
|
|
68
39
|
return;
|
|
69
40
|
}
|
|
70
|
-
const range = scrollIfNoRange(
|
|
41
|
+
const range = scrollIfNoRange(
|
|
42
|
+
container,
|
|
43
|
+
isReverse,
|
|
44
|
+
() => getRange(container, isReverse, x)
|
|
45
|
+
);
|
|
71
46
|
if (!range) {
|
|
72
47
|
return;
|
|
73
48
|
}
|
|
74
|
-
const {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const {
|
|
78
|
-
defaultView
|
|
79
|
-
} = ownerDocument;
|
|
80
|
-
assertIsDefined(defaultView, 'defaultView');
|
|
49
|
+
const { ownerDocument } = container;
|
|
50
|
+
const { defaultView } = ownerDocument;
|
|
51
|
+
assertIsDefined(defaultView, "defaultView");
|
|
81
52
|
const selection = defaultView.getSelection();
|
|
82
|
-
assertIsDefined(selection,
|
|
53
|
+
assertIsDefined(selection, "selection");
|
|
83
54
|
selection.removeAllRanges();
|
|
84
55
|
selection.addRange(range);
|
|
85
56
|
}
|
|
86
|
-
|
|
57
|
+
export {
|
|
58
|
+
placeCaretAtEdge as default
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=place-caret-at-edge.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/place-caret-at-edge.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport isRTL from './is-rtl';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Gets the range to place.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n *\n * @return {Range|null} The range to place.\n */\nfunction getRange( container, isReverse, x ) {\n\tconst { ownerDocument } = container;\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\t// When placing at the end (isReverse), find the closest range to the bottom\n\t// right corner. When placing at the start, to the top left corner.\n\t// Ensure x is defined and within the container's boundaries. When it's\n\t// exactly at the boundary, it's not considered within the boundaries.\n\tif ( x === undefined ) {\n\t\tx = isReverse ? containerRect.right - 1 : containerRect.left + 1;\n\t} else if ( x <= containerRect.left ) {\n\t\tx = containerRect.left + 1;\n\t} else if ( x >= containerRect.right ) {\n\t\tx = containerRect.right - 1;\n\t}\n\tconst y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;\n\treturn hiddenCaretRangeFromPoint( ownerDocument, x, y, container );\n}\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n */\nexport default function placeCaretAtEdge( container, isReverse, x ) {\n\tif ( ! container ) {\n\t\treturn;\n\t}\n\n\tcontainer.focus();\n\n\tif ( isInputOrTextArea( container ) ) {\n\t\t// The element may not support selection setting.\n\t\tif ( typeof container.selectionStart !== 'number' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\tcontainer.selectionStart = container.value.length;\n\t\t\tcontainer.selectionEnd = container.value.length;\n\t\t} else {\n\t\t\tcontainer.selectionStart = 0;\n\t\t\tcontainer.selectionEnd = 0;\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn;\n\t}\n\n\tconst range = scrollIfNoRange( container, isReverse, () =>\n\t\tgetRange( container, isReverse, x )\n\t);\n\n\tif ( ! range ) {\n\t\treturn;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tselection.removeAllRanges();\n\tselection.addRange( range );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,+BAA+B;AACtC,SAAS,uBAAuB;AAChC,OAAO,uBAAuB;AAC9B,OAAO,WAAW;AAClB,SAAS,uBAAuB;AAWhC,SAAS,SAAU,WAAW,WAAW,GAAI;AAC5C,QAAM,EAAE,cAAc,IAAI;AAE1B,QAAM,eAAe,MAAO,SAAU,IAAI,CAAE,YAAY;AACxD,QAAM,gBAAgB,UAAU,sBAAsB;AAKtD,MAAK,MAAM,QAAY;AACtB,QAAI,YAAY,cAAc,QAAQ,IAAI,cAAc,OAAO;AAAA,EAChE,WAAY,KAAK,cAAc,MAAO;AACrC,QAAI,cAAc,OAAO;AAAA,EAC1B,WAAY,KAAK,cAAc,OAAQ;AACtC,QAAI,cAAc,QAAQ;AAAA,EAC3B;AACA,QAAM,IAAI,eAAe,cAAc,SAAS,IAAI,cAAc,MAAM;AACxE,SAAO,0BAA2B,eAAe,GAAG,GAAG,SAAU;AAClE;AASe,SAAR,iBAAmC,WAAW,WAAW,GAAI;AACnE,MAAK,CAAE,WAAY;AAClB;AAAA,EACD;AAEA,YAAU,MAAM;AAEhB,MAAK,kBAAmB,SAAU,GAAI;AAErC,QAAK,OAAO,UAAU,mBAAmB,UAAW;AACnD;AAAA,IACD;AAEA,QAAK,WAAY;AAChB,gBAAU,iBAAiB,UAAU,MAAM;AAC3C,gBAAU,eAAe,UAAU,MAAM;AAAA,IAC1C,OAAO;AACN,gBAAU,iBAAiB;AAC3B,gBAAU,eAAe;AAAA,IAC1B;AAEA;AAAA,EACD;AAEA,MAAK,CAAE,UAAU,mBAAoB;AACpC;AAAA,EACD;AAEA,QAAM,QAAQ;AAAA,IAAiB;AAAA,IAAW;AAAA,IAAW,MACpD,SAAU,WAAW,WAAW,CAAE;AAAA,EACnC;AAEA,MAAK,CAAE,OAAQ;AACd;AAAA,EACD;AAEA,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,EAAE,YAAY,IAAI;AACxB,kBAAiB,aAAa,aAAc;AAC5C,QAAM,YAAY,YAAY,aAAa;AAC3C,kBAAiB,WAAW,WAAY;AACxC,YAAU,gBAAgB;AAC1B,YAAU,SAAU,KAAM;AAC3B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import placeCaretAtEdge from './place-caret-at-edge';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Places the caret at start or end of a given element.
|
|
8
|
-
*
|
|
9
|
-
* @param {HTMLElement} container Focusable element.
|
|
10
|
-
* @param {boolean} isReverse True for end, false for start.
|
|
11
|
-
*/
|
|
12
|
-
export default function placeCaretAtHorizontalEdge(container, isReverse) {
|
|
13
|
-
return placeCaretAtEdge(container, isReverse, undefined);
|
|
1
|
+
import placeCaretAtEdge from "./place-caret-at-edge";
|
|
2
|
+
function placeCaretAtHorizontalEdge(container, isReverse) {
|
|
3
|
+
return placeCaretAtEdge(container, isReverse, void 0);
|
|
14
4
|
}
|
|
15
|
-
|
|
5
|
+
export {
|
|
6
|
+
placeCaretAtHorizontalEdge as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=place-caret-at-horizontal-edge.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/place-caret-at-horizontal-edge.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport placeCaretAtEdge from './place-caret-at-edge';\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n */\nexport default function placeCaretAtHorizontalEdge( container, isReverse ) {\n\treturn placeCaretAtEdge( container, isReverse, undefined );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,sBAAsB;AAQd,SAAR,2BAA6C,WAAW,WAAY;AAC1E,SAAO,iBAAkB,WAAW,WAAW,MAAU;AAC1D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import placeCaretAtEdge from './place-caret-at-edge';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Places the caret at the top or bottom of a given element.
|
|
8
|
-
*
|
|
9
|
-
* @param {HTMLElement} container Focusable element.
|
|
10
|
-
* @param {boolean} isReverse True for bottom, false for top.
|
|
11
|
-
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
|
12
|
-
*/
|
|
13
|
-
export default function placeCaretAtVerticalEdge(container, isReverse, rect) {
|
|
1
|
+
import placeCaretAtEdge from "./place-caret-at-edge";
|
|
2
|
+
function placeCaretAtVerticalEdge(container, isReverse, rect) {
|
|
14
3
|
return placeCaretAtEdge(container, isReverse, rect?.left);
|
|
15
4
|
}
|
|
16
|
-
|
|
5
|
+
export {
|
|
6
|
+
placeCaretAtVerticalEdge as default
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=place-caret-at-vertical-edge.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/place-caret-at-vertical-edge.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport placeCaretAtEdge from './place-caret-at-edge';\n\n/**\n * Places the caret at the top or bottom of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for bottom, false for top.\n * @param {DOMRect} [rect] The rectangle to position the caret with.\n */\nexport default function placeCaretAtVerticalEdge( container, isReverse, rect ) {\n\treturn placeCaretAtEdge( container, isReverse, rect?.left );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,sBAAsB;AASd,SAAR,yBAA2C,WAAW,WAAW,MAAO;AAC9E,SAAO,iBAAkB,WAAW,WAAW,MAAM,IAAK;AAC3D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import cleanNodeList from './clean-node-list';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Given a schema, unwraps or removes nodes, attributes and classes on HTML.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} HTML The HTML to clean up.
|
|
10
|
-
* @param {import('./clean-node-list').Schema} schema Schema for the HTML.
|
|
11
|
-
* @param {boolean} inline Whether to clean for inline mode.
|
|
12
|
-
*
|
|
13
|
-
* @return {string} The cleaned up HTML.
|
|
14
|
-
*/
|
|
15
|
-
export default function removeInvalidHTML(HTML, schema, inline) {
|
|
16
|
-
const doc = document.implementation.createHTMLDocument('');
|
|
1
|
+
import cleanNodeList from "./clean-node-list";
|
|
2
|
+
function removeInvalidHTML(HTML, schema, inline) {
|
|
3
|
+
const doc = document.implementation.createHTMLDocument("");
|
|
17
4
|
doc.body.innerHTML = HTML;
|
|
18
5
|
cleanNodeList(doc.body.childNodes, doc, schema, inline);
|
|
19
6
|
return doc.body.innerHTML;
|
|
20
7
|
}
|
|
21
|
-
|
|
8
|
+
export {
|
|
9
|
+
removeInvalidHTML as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=remove-invalid-html.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/remove-invalid-html.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport cleanNodeList from './clean-node-list';\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on HTML.\n *\n * @param {string} HTML The HTML to clean up.\n * @param {import('./clean-node-list').Schema} schema Schema for the HTML.\n * @param {boolean} inline Whether to clean for inline mode.\n *\n * @return {string} The cleaned up HTML.\n */\nexport default function removeInvalidHTML( HTML, schema, inline ) {\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\n\tdoc.body.innerHTML = HTML;\n\n\tcleanNodeList( doc.body.childNodes, doc, schema, inline );\n\n\treturn doc.body.innerHTML;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,mBAAmB;AAWX,SAAR,kBAAoC,MAAM,QAAQ,QAAS;AACjE,QAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;AAE3D,MAAI,KAAK,YAAY;AAErB,gBAAe,IAAI,KAAK,YAAY,KAAK,QAAQ,MAAO;AAExD,SAAO,IAAI,KAAK;AACjB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { assertIsDefined } from '../utils/assert-is-defined';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Given a DOM node, removes it from the DOM.
|
|
8
|
-
*
|
|
9
|
-
* @param {Node} node Node to be removed.
|
|
10
|
-
* @return {void}
|
|
11
|
-
*/
|
|
12
|
-
export default function remove(node) {
|
|
13
|
-
assertIsDefined(node.parentNode, 'node.parentNode');
|
|
1
|
+
import { assertIsDefined } from "../utils/assert-is-defined";
|
|
2
|
+
function remove(node) {
|
|
3
|
+
assertIsDefined(node.parentNode, "node.parentNode");
|
|
14
4
|
node.parentNode.removeChild(node);
|
|
15
5
|
}
|
|
16
|
-
|
|
6
|
+
export {
|
|
7
|
+
remove as default
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/remove.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given a DOM node, removes it from the DOM.\n *\n * @param {Node} node Node to be removed.\n * @return {void}\n */\nexport default function remove( node ) {\n\tassertIsDefined( node.parentNode, 'node.parentNode' );\n\tnode.parentNode.removeChild( node );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,uBAAuB;AAQjB,SAAR,OAAyB,MAAO;AACtC,kBAAiB,KAAK,YAAY,iBAAkB;AACpD,OAAK,WAAW,YAAa,IAAK;AACnC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { assertIsDefined } from '../utils/assert-is-defined';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Replaces the given node with a new node with the given tag name.
|
|
8
|
-
*
|
|
9
|
-
* @param {Element} node The node to replace
|
|
10
|
-
* @param {string} tagName The new tag name.
|
|
11
|
-
*
|
|
12
|
-
* @return {Element} The new node.
|
|
13
|
-
*/
|
|
14
|
-
export default function replaceTag(node, tagName) {
|
|
1
|
+
import { assertIsDefined } from "../utils/assert-is-defined";
|
|
2
|
+
function replaceTag(node, tagName) {
|
|
15
3
|
const newNode = node.ownerDocument.createElement(tagName);
|
|
16
4
|
while (node.firstChild) {
|
|
17
5
|
newNode.appendChild(node.firstChild);
|
|
18
6
|
}
|
|
19
|
-
assertIsDefined(node.parentNode,
|
|
7
|
+
assertIsDefined(node.parentNode, "node.parentNode");
|
|
20
8
|
node.parentNode.replaceChild(newNode, node);
|
|
21
9
|
return newNode;
|
|
22
10
|
}
|
|
23
|
-
|
|
11
|
+
export {
|
|
12
|
+
replaceTag as default
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=replace-tag.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/replace-tag.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Replaces the given node with a new node with the given tag name.\n *\n * @param {Element} node The node to replace\n * @param {string} tagName The new tag name.\n *\n * @return {Element} The new node.\n */\nexport default function replaceTag( node, tagName ) {\n\tconst newNode = node.ownerDocument.createElement( tagName );\n\n\twhile ( node.firstChild ) {\n\t\tnewNode.appendChild( node.firstChild );\n\t}\n\n\tassertIsDefined( node.parentNode, 'node.parentNode' );\n\tnode.parentNode.replaceChild( newNode, node );\n\n\treturn newNode;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,uBAAuB;AAUjB,SAAR,WAA6B,MAAM,SAAU;AACnD,QAAM,UAAU,KAAK,cAAc,cAAe,OAAQ;AAE1D,SAAQ,KAAK,YAAa;AACzB,YAAQ,YAAa,KAAK,UAAW;AAAA,EACtC;AAEA,kBAAiB,KAAK,YAAY,iBAAkB;AACpD,OAAK,WAAW,aAAc,SAAS,IAAK;AAE5C,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import remove from './remove';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Given two DOM nodes, replaces the former with the latter in the DOM.
|
|
10
|
-
*
|
|
11
|
-
* @param {Element} processedNode Node to be removed.
|
|
12
|
-
* @param {Element} newNode Node to be inserted in its place.
|
|
13
|
-
* @return {void}
|
|
14
|
-
*/
|
|
15
|
-
export default function replace(processedNode, newNode) {
|
|
16
|
-
assertIsDefined(processedNode.parentNode, 'processedNode.parentNode');
|
|
1
|
+
import { assertIsDefined } from "../utils/assert-is-defined";
|
|
2
|
+
import insertAfter from "./insert-after";
|
|
3
|
+
import remove from "./remove";
|
|
4
|
+
function replace(processedNode, newNode) {
|
|
5
|
+
assertIsDefined(processedNode.parentNode, "processedNode.parentNode");
|
|
17
6
|
insertAfter(newNode, processedNode.parentNode);
|
|
18
7
|
remove(processedNode);
|
|
19
8
|
}
|
|
20
|
-
|
|
9
|
+
export {
|
|
10
|
+
replace as default
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=replace.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/replace.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport insertAfter from './insert-after';\nimport remove from './remove';\n\n/**\n * Given two DOM nodes, replaces the former with the latter in the DOM.\n *\n * @param {Element} processedNode Node to be removed.\n * @param {Element} newNode Node to be inserted in its place.\n * @return {void}\n */\nexport default function replace( processedNode, newNode ) {\n\tassertIsDefined( processedNode.parentNode, 'processedNode.parentNode' );\n\tinsertAfter( newNode, processedNode.parentNode );\n\tremove( processedNode );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,uBAAuB;AAChC,OAAO,iBAAiB;AACxB,OAAO,YAAY;AASJ,SAAR,QAA0B,eAAe,SAAU;AACzD,kBAAiB,cAAc,YAAY,0BAA2B;AACtE,cAAa,SAAS,cAAc,UAAW;AAC/C,SAAQ,aAAc;AACvB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,33 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import remove from './remove';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Strips scripts and on* attributes from HTML.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} html HTML to sanitize.
|
|
10
|
-
*
|
|
11
|
-
* @return {string} The sanitized HTML.
|
|
12
|
-
*/
|
|
13
|
-
export default function safeHTML(html) {
|
|
14
|
-
const {
|
|
15
|
-
body
|
|
16
|
-
} = document.implementation.createHTMLDocument('');
|
|
1
|
+
import remove from "./remove";
|
|
2
|
+
function safeHTML(html) {
|
|
3
|
+
const { body } = document.implementation.createHTMLDocument("");
|
|
17
4
|
body.innerHTML = html;
|
|
18
|
-
const elements = body.getElementsByTagName(
|
|
5
|
+
const elements = body.getElementsByTagName("*");
|
|
19
6
|
let elementIndex = elements.length;
|
|
20
7
|
while (elementIndex--) {
|
|
21
8
|
const element = elements[elementIndex];
|
|
22
|
-
if (element.tagName ===
|
|
9
|
+
if (element.tagName === "SCRIPT") {
|
|
23
10
|
remove(element);
|
|
24
11
|
} else {
|
|
25
12
|
let attributeIndex = element.attributes.length;
|
|
26
13
|
while (attributeIndex--) {
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
} = element.attributes[attributeIndex];
|
|
30
|
-
if (key.startsWith('on')) {
|
|
14
|
+
const { name: key } = element.attributes[attributeIndex];
|
|
15
|
+
if (key.startsWith("on")) {
|
|
31
16
|
element.removeAttribute(key);
|
|
32
17
|
}
|
|
33
18
|
}
|
|
@@ -35,4 +20,7 @@ export default function safeHTML(html) {
|
|
|
35
20
|
}
|
|
36
21
|
return body.innerHTML;
|
|
37
22
|
}
|
|
38
|
-
|
|
23
|
+
export {
|
|
24
|
+
safeHTML as default
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=safe-html.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/dom/safe-html.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport remove from './remove';\n\n/**\n * Strips scripts and on* attributes from HTML.\n *\n * @param {string} html HTML to sanitize.\n *\n * @return {string} The sanitized HTML.\n */\nexport default function safeHTML( html ) {\n\tconst { body } = document.implementation.createHTMLDocument( '' );\n\tbody.innerHTML = html;\n\tconst elements = body.getElementsByTagName( '*' );\n\tlet elementIndex = elements.length;\n\n\twhile ( elementIndex-- ) {\n\t\tconst element = elements[ elementIndex ];\n\n\t\tif ( element.tagName === 'SCRIPT' ) {\n\t\t\tremove( element );\n\t\t} else {\n\t\t\tlet attributeIndex = element.attributes.length;\n\n\t\t\twhile ( attributeIndex-- ) {\n\t\t\t\tconst { name: key } = element.attributes[ attributeIndex ];\n\n\t\t\t\tif ( key.startsWith( 'on' ) ) {\n\t\t\t\t\telement.removeAttribute( key );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn body.innerHTML;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,YAAY;AASJ,SAAR,SAA2B,MAAO;AACxC,QAAM,EAAE,KAAK,IAAI,SAAS,eAAe,mBAAoB,EAAG;AAChE,OAAK,YAAY;AACjB,QAAM,WAAW,KAAK,qBAAsB,GAAI;AAChD,MAAI,eAAe,SAAS;AAE5B,SAAQ,gBAAiB;AACxB,UAAM,UAAU,SAAU,YAAa;AAEvC,QAAK,QAAQ,YAAY,UAAW;AACnC,aAAQ,OAAQ;AAAA,IACjB,OAAO;AACN,UAAI,iBAAiB,QAAQ,WAAW;AAExC,aAAQ,kBAAmB;AAC1B,cAAM,EAAE,MAAM,IAAI,IAAI,QAAQ,WAAY,cAAe;AAEzD,YAAK,IAAI,WAAY,IAAK,GAAI;AAC7B,kBAAQ,gBAAiB,GAAI;AAAA,QAC9B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SAAO,KAAK;AACb;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|