@wordpress/dom 4.56.0 → 5.0.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/README.md +22 -22
- package/build/data-transfer.cjs +1 -1
- package/build/data-transfer.cjs.map +3 -3
- package/build/dom/caret-range-from-point.cjs +1 -1
- package/build/dom/caret-range-from-point.cjs.map +3 -3
- package/build/dom/clean-node-list.cjs +1 -1
- package/build/dom/clean-node-list.cjs.map +3 -3
- package/build/dom/compute-caret-rect.cjs +1 -1
- package/build/dom/compute-caret-rect.cjs.map +3 -3
- package/build/dom/document-has-selection.cjs +1 -1
- package/build/dom/document-has-selection.cjs.map +3 -3
- package/build/dom/document-has-text-selection.cjs +1 -1
- package/build/dom/document-has-text-selection.cjs.map +3 -3
- package/build/dom/document-has-uncollapsed-selection.cjs +1 -1
- package/build/dom/document-has-uncollapsed-selection.cjs.map +3 -3
- package/build/dom/get-computed-style.cjs +1 -1
- package/build/dom/get-computed-style.cjs.map +3 -3
- package/build/dom/get-offset-parent.cjs +7 -15
- package/build/dom/get-offset-parent.cjs.map +4 -4
- package/build/dom/get-range-height.cjs +1 -1
- package/build/dom/get-range-height.cjs.map +3 -3
- package/build/dom/get-rectangle-from-range.cjs +3 -8
- package/build/dom/get-rectangle-from-range.cjs.map +3 -3
- package/build/dom/get-scroll-container.cjs +2 -6
- package/build/dom/get-scroll-container.cjs.map +3 -3
- package/build/dom/hidden-caret-range-from-point.cjs +1 -1
- package/build/dom/hidden-caret-range-from-point.cjs.map +3 -3
- package/build/dom/index.cjs +1 -1
- package/build/dom/index.cjs.map +1 -1
- package/build/dom/input-field-has-uncollapsed-selection.cjs +2 -5
- package/build/dom/input-field-has-uncollapsed-selection.cjs.map +3 -3
- package/build/dom/insert-after.cjs +1 -1
- package/build/dom/insert-after.cjs.map +3 -3
- package/build/dom/is-edge.cjs +1 -1
- package/build/dom/is-edge.cjs.map +3 -3
- package/build/dom/is-element.cjs +1 -1
- package/build/dom/is-element.cjs.map +3 -3
- package/build/dom/is-empty.cjs +2 -5
- package/build/dom/is-empty.cjs.map +3 -3
- package/build/dom/is-entirely-selected.cjs +2 -5
- package/build/dom/is-entirely-selected.cjs.map +3 -3
- package/build/dom/is-form-element.cjs +1 -1
- package/build/dom/is-form-element.cjs.map +3 -3
- package/build/dom/is-horizontal-edge.cjs +1 -1
- package/build/dom/is-horizontal-edge.cjs.map +3 -3
- package/build/dom/is-html-input-element.cjs +1 -1
- package/build/dom/is-html-input-element.cjs.map +3 -3
- package/build/dom/is-input-or-text-area.cjs +1 -1
- package/build/dom/is-input-or-text-area.cjs.map +3 -3
- package/build/dom/is-number-input.cjs +1 -1
- package/build/dom/is-number-input.cjs.map +3 -3
- package/build/dom/is-rtl.cjs +1 -1
- package/build/dom/is-rtl.cjs.map +3 -3
- package/build/dom/is-selection-forward.cjs +1 -1
- package/build/dom/is-selection-forward.cjs.map +3 -3
- package/build/dom/is-text-field.cjs +2 -3
- package/build/dom/is-text-field.cjs.map +3 -3
- package/build/dom/is-vertical-edge.cjs +1 -1
- package/build/dom/is-vertical-edge.cjs.map +3 -3
- package/build/dom/place-caret-at-edge.cjs +1 -1
- package/build/dom/place-caret-at-edge.cjs.map +3 -3
- package/build/dom/place-caret-at-horizontal-edge.cjs +1 -1
- package/build/dom/place-caret-at-horizontal-edge.cjs.map +3 -3
- package/build/dom/place-caret-at-vertical-edge.cjs +1 -1
- package/build/dom/place-caret-at-vertical-edge.cjs.map +3 -3
- package/build/dom/remove-invalid-html.cjs +1 -1
- package/build/dom/remove-invalid-html.cjs.map +3 -3
- package/build/dom/remove.cjs +1 -1
- package/build/dom/remove.cjs.map +3 -3
- package/build/dom/replace-tag.cjs +1 -1
- package/build/dom/replace-tag.cjs.map +3 -3
- package/build/dom/replace.cjs +1 -1
- package/build/dom/replace.cjs.map +3 -3
- package/build/dom/safe-html.cjs +1 -1
- package/build/dom/safe-html.cjs.map +3 -3
- package/build/dom/scroll-if-no-range.cjs +1 -1
- package/build/dom/scroll-if-no-range.cjs.map +3 -3
- package/build/dom/strip-html.cjs +1 -1
- package/build/dom/strip-html.cjs.map +3 -3
- package/build/dom/types.cjs +19 -0
- package/build/dom/types.cjs.map +7 -0
- package/build/dom/unwrap.cjs +1 -1
- package/build/dom/unwrap.cjs.map +3 -3
- package/build/dom/wrap.cjs +1 -1
- package/build/dom/wrap.cjs.map +3 -3
- package/build/focusable.cjs +5 -6
- package/build/focusable.cjs.map +3 -3
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +2 -2
- package/build/phrasing-content.cjs +1 -1
- package/build/phrasing-content.cjs.map +3 -3
- package/build/tabbable.cjs +1 -1
- package/build/tabbable.cjs.map +3 -3
- package/build/types.cjs +19 -0
- package/build/types.cjs.map +7 -0
- package/build-module/data-transfer.mjs +1 -1
- package/build-module/data-transfer.mjs.map +3 -3
- package/build-module/dom/caret-range-from-point.mjs +1 -1
- package/build-module/dom/caret-range-from-point.mjs.map +3 -3
- package/build-module/dom/clean-node-list.mjs +1 -1
- package/build-module/dom/clean-node-list.mjs.map +3 -3
- package/build-module/dom/compute-caret-rect.mjs +1 -1
- package/build-module/dom/compute-caret-rect.mjs.map +3 -3
- package/build-module/dom/document-has-selection.mjs +1 -1
- package/build-module/dom/document-has-selection.mjs.map +3 -3
- package/build-module/dom/document-has-text-selection.mjs +1 -1
- package/build-module/dom/document-has-text-selection.mjs.map +3 -3
- package/build-module/dom/document-has-uncollapsed-selection.mjs +1 -1
- package/build-module/dom/document-has-uncollapsed-selection.mjs.map +3 -3
- package/build-module/dom/get-computed-style.mjs +1 -1
- package/build-module/dom/get-computed-style.mjs.map +3 -3
- package/build-module/dom/get-offset-parent.mjs +7 -15
- package/build-module/dom/get-offset-parent.mjs.map +3 -3
- package/build-module/dom/get-range-height.mjs +1 -1
- package/build-module/dom/get-range-height.mjs.map +3 -3
- package/build-module/dom/get-rectangle-from-range.mjs +3 -8
- package/build-module/dom/get-rectangle-from-range.mjs.map +3 -3
- package/build-module/dom/get-scroll-container.mjs +2 -6
- package/build-module/dom/get-scroll-container.mjs.map +3 -3
- package/build-module/dom/hidden-caret-range-from-point.mjs +1 -1
- package/build-module/dom/hidden-caret-range-from-point.mjs.map +3 -3
- package/build-module/dom/index.mjs +1 -1
- package/build-module/dom/index.mjs.map +1 -1
- package/build-module/dom/input-field-has-uncollapsed-selection.mjs +2 -5
- package/build-module/dom/input-field-has-uncollapsed-selection.mjs.map +3 -3
- package/build-module/dom/insert-after.mjs +1 -1
- package/build-module/dom/insert-after.mjs.map +3 -3
- package/build-module/dom/is-edge.mjs +1 -1
- package/build-module/dom/is-edge.mjs.map +3 -3
- package/build-module/dom/is-element.mjs +1 -1
- package/build-module/dom/is-element.mjs.map +3 -3
- package/build-module/dom/is-empty.mjs +2 -5
- package/build-module/dom/is-empty.mjs.map +3 -3
- package/build-module/dom/is-entirely-selected.mjs +2 -5
- package/build-module/dom/is-entirely-selected.mjs.map +3 -3
- package/build-module/dom/is-form-element.mjs +1 -1
- package/build-module/dom/is-form-element.mjs.map +3 -3
- package/build-module/dom/is-horizontal-edge.mjs +1 -1
- package/build-module/dom/is-horizontal-edge.mjs.map +3 -3
- package/build-module/dom/is-html-input-element.mjs +1 -1
- package/build-module/dom/is-html-input-element.mjs.map +3 -3
- package/build-module/dom/is-input-or-text-area.mjs +1 -1
- package/build-module/dom/is-input-or-text-area.mjs.map +3 -3
- package/build-module/dom/is-number-input.mjs +1 -1
- package/build-module/dom/is-number-input.mjs.map +3 -3
- package/build-module/dom/is-rtl.mjs +1 -1
- package/build-module/dom/is-rtl.mjs.map +3 -3
- package/build-module/dom/is-selection-forward.mjs +1 -1
- package/build-module/dom/is-selection-forward.mjs.map +3 -3
- package/build-module/dom/is-text-field.mjs +2 -3
- package/build-module/dom/is-text-field.mjs.map +3 -3
- package/build-module/dom/is-vertical-edge.mjs +1 -1
- package/build-module/dom/is-vertical-edge.mjs.map +3 -3
- package/build-module/dom/place-caret-at-edge.mjs +1 -1
- package/build-module/dom/place-caret-at-edge.mjs.map +3 -3
- package/build-module/dom/place-caret-at-horizontal-edge.mjs +1 -1
- package/build-module/dom/place-caret-at-horizontal-edge.mjs.map +3 -3
- package/build-module/dom/place-caret-at-vertical-edge.mjs +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.mjs.map +3 -3
- package/build-module/dom/remove-invalid-html.mjs +1 -1
- package/build-module/dom/remove-invalid-html.mjs.map +3 -3
- package/build-module/dom/remove.mjs +1 -1
- package/build-module/dom/remove.mjs.map +3 -3
- package/build-module/dom/replace-tag.mjs +1 -1
- package/build-module/dom/replace-tag.mjs.map +3 -3
- package/build-module/dom/replace.mjs +1 -1
- package/build-module/dom/replace.mjs.map +3 -3
- package/build-module/dom/safe-html.mjs +1 -1
- package/build-module/dom/safe-html.mjs.map +3 -3
- package/build-module/dom/scroll-if-no-range.mjs +1 -1
- package/build-module/dom/scroll-if-no-range.mjs.map +3 -3
- package/build-module/dom/strip-html.mjs +1 -1
- package/build-module/dom/strip-html.mjs.map +3 -3
- package/build-module/dom/types.mjs +1 -0
- package/build-module/dom/types.mjs.map +7 -0
- package/build-module/dom/unwrap.mjs +1 -1
- package/build-module/dom/unwrap.mjs.map +3 -3
- package/build-module/dom/wrap.mjs +1 -1
- package/build-module/dom/wrap.mjs.map +3 -3
- package/build-module/focusable.mjs +5 -6
- package/build-module/focusable.mjs.map +3 -3
- package/build-module/index.mjs +1 -1
- package/build-module/index.mjs.map +2 -2
- package/build-module/phrasing-content.mjs +1 -1
- package/build-module/phrasing-content.mjs.map +3 -3
- package/build-module/tabbable.mjs +1 -1
- package/build-module/tabbable.mjs.map +3 -3
- package/build-module/types.mjs +1 -0
- package/build-module/types.mjs.map +7 -0
- package/build-types/data-transfer.d.ts +2 -2
- package/build-types/data-transfer.d.ts.map +1 -1
- package/build-types/dom/caret-range-from-point.d.ts +4 -4
- package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
- package/build-types/dom/clean-node-list.d.ts +5 -45
- package/build-types/dom/clean-node-list.d.ts.map +1 -1
- package/build-types/dom/compute-caret-rect.d.ts +2 -2
- package/build-types/dom/compute-caret-rect.d.ts.map +1 -1
- package/build-types/dom/document-has-selection.d.ts +2 -2
- package/build-types/dom/document-has-selection.d.ts.map +1 -1
- package/build-types/dom/document-has-text-selection.d.ts +2 -2
- package/build-types/dom/document-has-text-selection.d.ts.map +1 -1
- package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
- package/build-types/dom/document-has-uncollapsed-selection.d.ts.map +1 -1
- package/build-types/dom/get-computed-style.d.ts +3 -3
- package/build-types/dom/get-computed-style.d.ts.map +1 -1
- package/build-types/dom/get-offset-parent.d.ts +2 -2
- package/build-types/dom/get-offset-parent.d.ts.map +1 -1
- package/build-types/dom/get-range-height.d.ts +2 -2
- package/build-types/dom/get-range-height.d.ts.map +1 -1
- package/build-types/dom/get-rectangle-from-range.d.ts +2 -2
- package/build-types/dom/get-rectangle-from-range.d.ts.map +1 -1
- package/build-types/dom/get-scroll-container.d.ts +5 -5
- package/build-types/dom/get-scroll-container.d.ts.map +1 -1
- package/build-types/dom/hidden-caret-range-from-point.d.ts +5 -5
- package/build-types/dom/hidden-caret-range-from-point.d.ts.map +1 -1
- package/build-types/dom/index.d.ts.map +1 -1
- package/build-types/dom/input-field-has-uncollapsed-selection.d.ts +2 -2
- package/build-types/dom/input-field-has-uncollapsed-selection.d.ts.map +1 -1
- package/build-types/dom/insert-after.d.ts +2 -3
- package/build-types/dom/insert-after.d.ts.map +1 -1
- package/build-types/dom/is-edge.d.ts +4 -4
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/is-element.d.ts.map +1 -1
- package/build-types/dom/is-empty.d.ts +3 -3
- package/build-types/dom/is-empty.d.ts.map +1 -1
- package/build-types/dom/is-entirely-selected.d.ts +2 -2
- package/build-types/dom/is-entirely-selected.d.ts.map +1 -1
- package/build-types/dom/is-form-element.d.ts +3 -3
- package/build-types/dom/is-form-element.d.ts.map +1 -1
- package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/is-html-input-element.d.ts +1 -1
- package/build-types/dom/is-html-input-element.d.ts.map +1 -1
- package/build-types/dom/is-input-or-text-area.d.ts.map +1 -1
- package/build-types/dom/is-number-input.d.ts +2 -2
- package/build-types/dom/is-number-input.d.ts.map +1 -1
- package/build-types/dom/is-rtl.d.ts +2 -2
- package/build-types/dom/is-rtl.d.ts.map +1 -1
- package/build-types/dom/is-selection-forward.d.ts +2 -2
- package/build-types/dom/is-selection-forward.d.ts.map +1 -1
- package/build-types/dom/is-text-field.d.ts +2 -2
- package/build-types/dom/is-text-field.d.ts.map +1 -1
- package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts +3 -3
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/remove-invalid-html.d.ts +5 -4
- package/build-types/dom/remove-invalid-html.d.ts.map +1 -1
- package/build-types/dom/remove.d.ts +1 -2
- package/build-types/dom/remove.d.ts.map +1 -1
- package/build-types/dom/replace-tag.d.ts +3 -3
- package/build-types/dom/replace-tag.d.ts.map +1 -1
- package/build-types/dom/replace.d.ts +2 -3
- package/build-types/dom/replace.d.ts.map +1 -1
- package/build-types/dom/safe-html.d.ts +2 -2
- package/build-types/dom/safe-html.d.ts.map +1 -1
- package/build-types/dom/scroll-if-no-range.d.ts +5 -5
- package/build-types/dom/scroll-if-no-range.d.ts.map +1 -1
- package/build-types/dom/strip-html.d.ts +2 -2
- package/build-types/dom/strip-html.d.ts.map +1 -1
- package/build-types/dom/types.d.ts +32 -0
- package/build-types/dom/types.d.ts.map +1 -0
- package/build-types/dom/unwrap.d.ts +1 -3
- package/build-types/dom/unwrap.d.ts.map +1 -1
- package/build-types/dom/wrap.d.ts +2 -2
- package/build-types/dom/wrap.d.ts.map +1 -1
- package/build-types/focusable.d.ts +11 -30
- package/build-types/focusable.d.ts.map +1 -1
- package/build-types/index.d.ts +17 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/phrasing-content.d.ts +9 -24
- package/build-types/phrasing-content.d.ts.map +1 -1
- package/build-types/tabbable.d.ts +10 -15
- package/build-types/tabbable.d.ts.map +1 -1
- package/build-types/types.d.ts +29 -0
- package/build-types/types.d.ts.map +1 -0
- package/package.json +6 -7
- package/src/{data-transfer.js → data-transfer.ts} +3 -3
- package/src/dom/{caret-range-from-point.js → caret-range-from-point.ts} +9 -5
- package/src/dom/{clean-node-list.js → clean-node-list.ts} +16 -24
- package/src/dom/{compute-caret-rect.js → compute-caret-rect.ts} +3 -3
- package/src/dom/{document-has-selection.js → document-has-selection.ts} +3 -3
- package/src/dom/{document-has-text-selection.js → document-has-text-selection.ts} +3 -3
- package/src/dom/{document-has-uncollapsed-selection.js → document-has-uncollapsed-selection.ts} +5 -3
- package/src/dom/{get-computed-style.js → get-computed-style.ts} +5 -3
- package/src/dom/{get-offset-parent.js → get-offset-parent.ts} +9 -14
- package/src/dom/{get-range-height.js → get-range-height.ts} +3 -3
- package/src/dom/{get-rectangle-from-range.js → get-rectangle-from-range.ts} +6 -12
- package/src/dom/{get-scroll-container.js → get-scroll-container.ts} +9 -9
- package/src/dom/{hidden-caret-range-from-point.js → hidden-caret-range-from-point.ts} +11 -6
- package/src/dom/{input-field-has-uncollapsed-selection.js → input-field-has-uncollapsed-selection.ts} +7 -5
- package/src/dom/{insert-after.js → insert-after.ts} +6 -4
- package/src/dom/{is-edge.js → is-edge.ts} +9 -5
- package/src/dom/{is-element.js → is-element.ts} +3 -1
- package/src/dom/{is-empty.js → is-empty.ts} +5 -7
- package/src/dom/{is-entirely-selected.js → is-entirely-selected.ts} +14 -11
- package/src/dom/{is-form-element.js → is-form-element.ts} +5 -3
- package/src/dom/{is-horizontal-edge.js → is-horizontal-edge.ts} +4 -1
- package/src/dom/{is-html-input-element.js → is-html-input-element.ts} +3 -1
- package/src/dom/{is-input-or-text-area.js → is-input-or-text-area.ts} +3 -1
- package/src/dom/{is-number-input.js → is-number-input.ts} +3 -3
- package/src/dom/{is-rtl.js → is-rtl.ts} +3 -3
- package/src/dom/{is-selection-forward.js → is-selection-forward.ts} +3 -3
- package/src/dom/{is-text-field.js → is-text-field.ts} +4 -4
- package/src/dom/{is-vertical-edge.js → is-vertical-edge.ts} +4 -1
- package/src/dom/{place-caret-at-edge.js → place-caret-at-edge.ts} +17 -9
- package/src/dom/{place-caret-at-horizontal-edge.js → place-caret-at-horizontal-edge.ts} +4 -1
- package/src/dom/{place-caret-at-vertical-edge.js → place-caret-at-vertical-edge.ts} +5 -1
- package/src/dom/{remove-invalid-html.js → remove-invalid-html.ts} +9 -4
- package/src/dom/{remove.js → remove.ts} +2 -3
- package/src/dom/{replace-tag.js → replace-tag.ts} +4 -4
- package/src/dom/{replace.js → replace.ts} +6 -4
- package/src/dom/{safe-html.js → safe-html.ts} +3 -3
- package/src/dom/{scroll-if-no-range.js → scroll-if-no-range.ts} +9 -5
- package/src/dom/{strip-html.js → strip-html.ts} +3 -3
- package/src/dom/types.ts +28 -0
- package/src/dom/{unwrap.js → unwrap.ts} +2 -4
- package/src/dom/{wrap.js → wrap.ts} +3 -3
- package/src/{focusable.js → focusable.ts} +34 -32
- package/src/index.ts +33 -0
- package/src/{phrasing-content.js → phrasing-content.ts} +15 -30
- package/src/{tabbable.js → tabbable.ts} +48 -39
- package/src/test/dom.jsdom.test.js +21 -0
- package/src/types.ts +32 -0
- package/CHANGELOG.md +0 -315
- package/src/index.js +0 -12
- /package/src/dom/{index.js → index.ts} +0 -0
|
@@ -4,11 +4,11 @@ import isHTMLInputElement from './is-html-input-element';
|
|
|
4
4
|
/**
|
|
5
5
|
* Check whether the given element is an input field of type number.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param node The HTML node.
|
|
8
8
|
*
|
|
9
|
-
* @return
|
|
9
|
+
* @return True if the node is number input.
|
|
10
10
|
*/
|
|
11
|
-
export default function isNumberInput( node ) {
|
|
11
|
+
export default function isNumberInput( node: Node ): node is HTMLInputElement {
|
|
12
12
|
deprecated( 'wp.dom.isNumberInput', {
|
|
13
13
|
since: '6.1',
|
|
14
14
|
version: '6.5',
|
|
@@ -3,10 +3,10 @@ import getComputedStyle from './get-computed-style';
|
|
|
3
3
|
/**
|
|
4
4
|
* Whether the element's text direction is right-to-left.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param element The element to check.
|
|
7
7
|
*
|
|
8
|
-
* @return
|
|
8
|
+
* @return True if rtl, false if ltr.
|
|
9
9
|
*/
|
|
10
|
-
export default function isRTL( element ) {
|
|
10
|
+
export default function isRTL( element: Element ): boolean {
|
|
11
11
|
return getComputedStyle( element ).direction === 'rtl';
|
|
12
12
|
}
|
|
@@ -6,11 +6,11 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
|
6
6
|
*
|
|
7
7
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param selection Selection object to check.
|
|
10
10
|
*
|
|
11
|
-
* @return
|
|
11
|
+
* @return Whether the selection is forward.
|
|
12
12
|
*/
|
|
13
|
-
export default function isSelectionForward( selection ) {
|
|
13
|
+
export default function isSelectionForward( selection: Selection ): boolean {
|
|
14
14
|
const { anchorNode, focusNode, anchorOffset, focusOffset } = selection;
|
|
15
15
|
|
|
16
16
|
assertIsDefined( anchorNode, 'anchorNode' );
|
|
@@ -6,10 +6,10 @@ import isHTMLInputElement from './is-html-input-element';
|
|
|
6
6
|
*
|
|
7
7
|
* See: https://html.spec.whatwg.org/#textFieldSelection
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @return
|
|
9
|
+
* @param node The HTML element.
|
|
10
|
+
* @return True if the element is an text field, false if not.
|
|
11
11
|
*/
|
|
12
|
-
export default function isTextField( node ) {
|
|
12
|
+
export default function isTextField( node: Node ): node is HTMLElement {
|
|
13
13
|
const nonTextInputs = [
|
|
14
14
|
'button',
|
|
15
15
|
'checkbox',
|
|
@@ -29,6 +29,6 @@ export default function isTextField( node ) {
|
|
|
29
29
|
node.type &&
|
|
30
30
|
! nonTextInputs.includes( node.type ) ) ||
|
|
31
31
|
node.nodeName === 'TEXTAREA' ||
|
|
32
|
-
|
|
32
|
+
( node as HTMLElement ).contentEditable === 'true'
|
|
33
33
|
);
|
|
34
34
|
}
|
|
@@ -8,6 +8,9 @@ import isEdge from './is-edge';
|
|
|
8
8
|
*
|
|
9
9
|
* @return {boolean} True if at the vertical edge, false if not.
|
|
10
10
|
*/
|
|
11
|
-
export default function isVerticalEdge(
|
|
11
|
+
export default function isVerticalEdge(
|
|
12
|
+
container: HTMLElement,
|
|
13
|
+
isReverse: boolean
|
|
14
|
+
): boolean {
|
|
12
15
|
return isEdge( container, isReverse, true );
|
|
13
16
|
}
|
|
@@ -7,13 +7,17 @@ import { scrollIfNoRange } from './scroll-if-no-range';
|
|
|
7
7
|
/**
|
|
8
8
|
* Gets the range to place.
|
|
9
9
|
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
10
|
+
* @param container Focusable element.
|
|
11
|
+
* @param isReverse True for end, false for start.
|
|
12
|
+
* @param x X coordinate to vertically position.
|
|
13
13
|
*
|
|
14
|
-
* @return
|
|
14
|
+
* @return The range to place.
|
|
15
15
|
*/
|
|
16
|
-
function getRange(
|
|
16
|
+
function getRange(
|
|
17
|
+
container: HTMLElement,
|
|
18
|
+
isReverse: boolean,
|
|
19
|
+
x: number | undefined
|
|
20
|
+
): Range | null {
|
|
17
21
|
const { ownerDocument } = container;
|
|
18
22
|
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
|
19
23
|
const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
|
|
@@ -36,11 +40,15 @@ function getRange( container, isReverse, x ) {
|
|
|
36
40
|
/**
|
|
37
41
|
* Places the caret at start or end of a given element.
|
|
38
42
|
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
43
|
+
* @param container Focusable element.
|
|
44
|
+
* @param isReverse True for end, false for start.
|
|
45
|
+
* @param x X coordinate to vertically position.
|
|
42
46
|
*/
|
|
43
|
-
export default function placeCaretAtEdge(
|
|
47
|
+
export default function placeCaretAtEdge(
|
|
48
|
+
container: HTMLElement,
|
|
49
|
+
isReverse: boolean,
|
|
50
|
+
x: number | undefined
|
|
51
|
+
) {
|
|
44
52
|
if ( ! container ) {
|
|
45
53
|
return;
|
|
46
54
|
}
|
|
@@ -6,6 +6,9 @@ import placeCaretAtEdge from './place-caret-at-edge';
|
|
|
6
6
|
* @param {HTMLElement} container Focusable element.
|
|
7
7
|
* @param {boolean} isReverse True for end, false for start.
|
|
8
8
|
*/
|
|
9
|
-
export default function placeCaretAtHorizontalEdge(
|
|
9
|
+
export default function placeCaretAtHorizontalEdge(
|
|
10
|
+
container: HTMLElement,
|
|
11
|
+
isReverse: boolean
|
|
12
|
+
) {
|
|
10
13
|
return placeCaretAtEdge( container, isReverse, undefined );
|
|
11
14
|
}
|
|
@@ -7,6 +7,10 @@ import placeCaretAtEdge from './place-caret-at-edge';
|
|
|
7
7
|
* @param {boolean} isReverse True for bottom, false for top.
|
|
8
8
|
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
|
9
9
|
*/
|
|
10
|
-
export default function placeCaretAtVerticalEdge(
|
|
10
|
+
export default function placeCaretAtVerticalEdge(
|
|
11
|
+
container: HTMLElement,
|
|
12
|
+
isReverse: boolean,
|
|
13
|
+
rect?: DOMRect
|
|
14
|
+
) {
|
|
11
15
|
return placeCaretAtEdge( container, isReverse, rect?.left );
|
|
12
16
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import cleanNodeList from './clean-node-list';
|
|
2
|
+
import type { Schema } from './types';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Given a schema, unwraps or removes nodes, attributes and classes on HTML.
|
|
5
6
|
*
|
|
6
|
-
* @param {string}
|
|
7
|
-
* @param {
|
|
8
|
-
* @param {boolean}
|
|
7
|
+
* @param {string} HTML The HTML to clean up.
|
|
8
|
+
* @param {Schema} schema Schema for the HTML.
|
|
9
|
+
* @param {boolean} inline Whether to clean for inline mode.
|
|
9
10
|
*
|
|
10
11
|
* @return {string} The cleaned up HTML.
|
|
11
12
|
*/
|
|
12
|
-
export default function removeInvalidHTML(
|
|
13
|
+
export default function removeInvalidHTML(
|
|
14
|
+
HTML: string,
|
|
15
|
+
schema: Schema,
|
|
16
|
+
inline: boolean
|
|
17
|
+
): string {
|
|
13
18
|
const doc = document.implementation.createHTMLDocument( '' );
|
|
14
19
|
|
|
15
20
|
doc.body.innerHTML = HTML;
|
|
@@ -3,10 +3,9 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
|
3
3
|
/**
|
|
4
4
|
* Given a DOM node, removes it from the DOM.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @return {void}
|
|
6
|
+
* @param node Node to be removed.
|
|
8
7
|
*/
|
|
9
|
-
export default function remove( node ) {
|
|
8
|
+
export default function remove( node: Node ): void {
|
|
10
9
|
assertIsDefined( node.parentNode, 'node.parentNode' );
|
|
11
10
|
node.parentNode.removeChild( node );
|
|
12
11
|
}
|
|
@@ -3,12 +3,12 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
|
3
3
|
/**
|
|
4
4
|
* Replaces the given node with a new node with the given tag name.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
6
|
+
* @param node The node to replace
|
|
7
|
+
* @param tagName The new tag name.
|
|
8
8
|
*
|
|
9
|
-
* @return
|
|
9
|
+
* @return The new node.
|
|
10
10
|
*/
|
|
11
|
-
export default function replaceTag( node, tagName ) {
|
|
11
|
+
export default function replaceTag( node: Element, tagName: string ): Element {
|
|
12
12
|
const newNode = node.ownerDocument.createElement( tagName );
|
|
13
13
|
|
|
14
14
|
while ( node.firstChild ) {
|
|
@@ -5,11 +5,13 @@ import remove from './remove';
|
|
|
5
5
|
/**
|
|
6
6
|
* Given two DOM nodes, replaces the former with the latter in the DOM.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @return {void}
|
|
8
|
+
* @param processedNode Node to be removed.
|
|
9
|
+
* @param newNode Node to be inserted in its place.
|
|
11
10
|
*/
|
|
12
|
-
export default function replace(
|
|
11
|
+
export default function replace(
|
|
12
|
+
processedNode: Element,
|
|
13
|
+
newNode: Element
|
|
14
|
+
): void {
|
|
13
15
|
assertIsDefined( processedNode.parentNode, 'processedNode.parentNode' );
|
|
14
16
|
insertAfter( newNode, processedNode.parentNode );
|
|
15
17
|
remove( processedNode );
|
|
@@ -3,11 +3,11 @@ import remove from './remove';
|
|
|
3
3
|
/**
|
|
4
4
|
* Strips scripts and on* attributes from HTML.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param html HTML to sanitize.
|
|
7
7
|
*
|
|
8
|
-
* @return
|
|
8
|
+
* @return The sanitized HTML.
|
|
9
9
|
*/
|
|
10
|
-
export default function safeHTML( html ) {
|
|
10
|
+
export default function safeHTML( html: string ): string {
|
|
11
11
|
const { body } = document.implementation.createHTMLDocument( '' );
|
|
12
12
|
body.innerHTML = html;
|
|
13
13
|
const elements = body.getElementsByTagName( '*' );
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
* If no range range can be created or it is outside the container, the element
|
|
3
3
|
* may be out of view, so scroll it into view and try again.
|
|
4
4
|
*
|
|
5
|
-
* @param
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
5
|
+
* @param container The container to scroll.
|
|
6
|
+
* @param alignToTop True to align to top, false to bottom.
|
|
7
|
+
* @param callback The callback to create the range.
|
|
8
8
|
*
|
|
9
|
-
* @return
|
|
9
|
+
* @return The range returned by the callback.
|
|
10
10
|
*/
|
|
11
|
-
export function scrollIfNoRange(
|
|
11
|
+
export function scrollIfNoRange(
|
|
12
|
+
container: HTMLElement,
|
|
13
|
+
alignToTop: boolean,
|
|
14
|
+
callback: () => Range | null
|
|
15
|
+
): Range | null {
|
|
12
16
|
let range = callback();
|
|
13
17
|
|
|
14
18
|
// If no range range can be created or it is outside the container, the
|
|
@@ -3,11 +3,11 @@ import safeHTML from './safe-html';
|
|
|
3
3
|
/**
|
|
4
4
|
* Removes any HTML tags from the provided string.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
6
|
+
* @param html The string containing html.
|
|
7
7
|
*
|
|
8
|
-
* @return
|
|
8
|
+
* @return The text content with any html removed.
|
|
9
9
|
*/
|
|
10
|
-
export default function stripHTML( html ) {
|
|
10
|
+
export default function stripHTML( html: string ): string {
|
|
11
11
|
// Remove any script tags or on* attributes otherwise their *contents* will be left
|
|
12
12
|
// in place following removal of HTML tags.
|
|
13
13
|
html = safeHTML( html );
|
package/src/dom/types.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface SchemaItem {
|
|
2
|
+
/**
|
|
3
|
+
* Attributes.
|
|
4
|
+
*/
|
|
5
|
+
attributes?: string[];
|
|
6
|
+
/**
|
|
7
|
+
* Classnames or RegExp to test against. Use '*' to keep all classes.
|
|
8
|
+
*/
|
|
9
|
+
classes?: ( string | RegExp )[];
|
|
10
|
+
/**
|
|
11
|
+
* Child schemas.
|
|
12
|
+
*/
|
|
13
|
+
children?: '*' | { [ tag: string ]: SchemaItem };
|
|
14
|
+
/**
|
|
15
|
+
* Selectors to test required children against. Leave empty or undefined if there are no requirements.
|
|
16
|
+
*/
|
|
17
|
+
require?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Whether to allow nodes without children.
|
|
20
|
+
*/
|
|
21
|
+
allowEmpty?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Function to test whether a node is a match. If left undefined any node will be assumed to match.
|
|
24
|
+
*/
|
|
25
|
+
isMatch?: ( node: Node ) => boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type Schema = { [ tag: string ]: SchemaItem };
|
|
@@ -3,11 +3,9 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
|
3
3
|
/**
|
|
4
4
|
* Unwrap the given node. This means any child nodes are moved to the parent.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
*
|
|
8
|
-
* @return {void}
|
|
6
|
+
* @param node The node to unwrap.
|
|
9
7
|
*/
|
|
10
|
-
export default function unwrap( node ) {
|
|
8
|
+
export default function unwrap( node: Node ): void {
|
|
11
9
|
const parent = node.parentNode;
|
|
12
10
|
|
|
13
11
|
assertIsDefined( parent, 'node.parentNode' );
|
|
@@ -3,10 +3,10 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
|
3
3
|
/**
|
|
4
4
|
* Wraps the given node with a new node with the given tag name.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
6
|
+
* @param newNode The node to insert.
|
|
7
|
+
* @param referenceNode The node to wrap.
|
|
8
8
|
*/
|
|
9
|
-
export default function wrap( newNode, referenceNode ) {
|
|
9
|
+
export default function wrap( newNode: Element, referenceNode: Element ) {
|
|
10
10
|
assertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );
|
|
11
11
|
referenceNode.parentNode.insertBefore( newNode, referenceNode );
|
|
12
12
|
newNode.appendChild( referenceNode );
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FindFocusableOptions } from './types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* References:
|
|
3
5
|
*
|
|
@@ -20,15 +22,15 @@
|
|
|
20
22
|
/**
|
|
21
23
|
* Returns a CSS selector used to query for focusable elements.
|
|
22
24
|
*
|
|
23
|
-
* @param
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
25
|
+
* @param sequential If set, only query elements that are sequentially
|
|
26
|
+
* focusable. Non-interactive elements with a
|
|
27
|
+
* negative `tabindex` are focusable but not
|
|
28
|
+
* sequentially focusable.
|
|
29
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
|
28
30
|
*
|
|
29
|
-
* @return
|
|
31
|
+
* @return CSS selector.
|
|
30
32
|
*/
|
|
31
|
-
function buildSelector( sequential ) {
|
|
33
|
+
function buildSelector( sequential: boolean ): string {
|
|
32
34
|
return [
|
|
33
35
|
sequential ? '[tabindex]:not([tabindex^="-"])' : '[tabindex]',
|
|
34
36
|
'a[href]',
|
|
@@ -49,11 +51,11 @@ function buildSelector( sequential ) {
|
|
|
49
51
|
* Returns true if the specified element has a layout box and is not hidden by
|
|
50
52
|
* CSS visibility or content visibility.
|
|
51
53
|
*
|
|
52
|
-
* @param
|
|
54
|
+
* @param element DOM element to test.
|
|
53
55
|
*
|
|
54
|
-
* @return
|
|
56
|
+
* @return Whether element is visible.
|
|
55
57
|
*/
|
|
56
|
-
function isVisible( element ) {
|
|
58
|
+
function isVisible( element: HTMLElement ): boolean {
|
|
57
59
|
if ( typeof element.checkVisibility === 'function' ) {
|
|
58
60
|
if ( ! element.checkVisibility( { visibilityProperty: true } ) ) {
|
|
59
61
|
return false;
|
|
@@ -80,19 +82,17 @@ function isVisible( element ) {
|
|
|
80
82
|
* false otherwise. Area is only focusable if within a map where a named map
|
|
81
83
|
* referenced by an image somewhere in the document.
|
|
82
84
|
*
|
|
83
|
-
* @param
|
|
85
|
+
* @param element DOM area element to test.
|
|
84
86
|
*
|
|
85
|
-
* @return
|
|
87
|
+
* @return Whether area element is valid for focus.
|
|
86
88
|
*/
|
|
87
|
-
function isValidFocusableArea( element ) {
|
|
88
|
-
|
|
89
|
-
const map = element.closest( 'map[name]' );
|
|
89
|
+
function isValidFocusableArea( element: HTMLAreaElement ): boolean {
|
|
90
|
+
const map: HTMLMapElement | null = element.closest( 'map[name]' );
|
|
90
91
|
if ( ! map ) {
|
|
91
92
|
return false;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
const img = element.ownerDocument.querySelector(
|
|
95
|
+
const img: HTMLImageElement | null = element.ownerDocument.querySelector(
|
|
96
96
|
'img[usemap="#' + map.name + '"]'
|
|
97
97
|
);
|
|
98
98
|
return !! img && ! img.closest( '[inert]' ) && isVisible( img );
|
|
@@ -101,28 +101,30 @@ function isValidFocusableArea( element ) {
|
|
|
101
101
|
/**
|
|
102
102
|
* Returns all focusable elements within a given context.
|
|
103
103
|
*
|
|
104
|
-
* @param
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
104
|
+
* @param context Element in which to search.
|
|
105
|
+
* @param options
|
|
106
|
+
* @param [options.sequential] If set, only return elements that are
|
|
107
|
+
* sequentially focusable.
|
|
108
|
+
* Non-interactive elements with a
|
|
109
|
+
* negative `tabindex` are focusable but
|
|
110
|
+
* not sequentially focusable.
|
|
111
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
|
112
112
|
*
|
|
113
|
-
* @return
|
|
113
|
+
* @return Focusable elements.
|
|
114
114
|
*/
|
|
115
|
-
export function find(
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
export function find(
|
|
116
|
+
context: Element,
|
|
117
|
+
{ sequential = false }: FindFocusableOptions = {}
|
|
118
|
+
): HTMLElement[] {
|
|
119
|
+
const elements: NodeListOf< HTMLElement > = context.querySelectorAll(
|
|
120
|
+
buildSelector( sequential )
|
|
121
|
+
);
|
|
118
122
|
|
|
119
123
|
return Array.from( elements ).filter( ( element ) => {
|
|
120
124
|
const { nodeName } = element;
|
|
121
125
|
if ( 'AREA' === nodeName ) {
|
|
122
126
|
// The mapped image determines whether this region is visible or inert.
|
|
123
|
-
return isValidFocusableArea(
|
|
124
|
-
/** @type {HTMLAreaElement} */ ( element )
|
|
125
|
-
);
|
|
127
|
+
return isValidFocusableArea( element as HTMLAreaElement );
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
// Elements inside an inert subtree are not focusable.
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as focusable from './focusable';
|
|
2
|
+
import * as tabbable from './tabbable';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Object grouping `focusable` and `tabbable` utils
|
|
6
|
+
* under the keys with the same name.
|
|
7
|
+
*/
|
|
8
|
+
export const focus = { focusable, tabbable };
|
|
9
|
+
|
|
10
|
+
export * from './dom';
|
|
11
|
+
export * from './phrasing-content';
|
|
12
|
+
export * from './data-transfer';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Schema of the content allowed inside an element, keyed by tag name.
|
|
16
|
+
*/
|
|
17
|
+
export type { ContentSchema } from './types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The attributes and children allowed for an element in a `ContentSchema`.
|
|
21
|
+
*/
|
|
22
|
+
export type { SemanticElementDefinition } from './types';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Schema that `cleanNodeList` and `removeInvalidHTML` clean HTML against,
|
|
26
|
+
* keyed by tag name.
|
|
27
|
+
*/
|
|
28
|
+
export type { Schema } from './dom/types';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The rules for a single tag in a `Schema`.
|
|
32
|
+
*/
|
|
33
|
+
export type { SchemaItem } from './dom/types';
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
+
import type { ContentSchema } from './types';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* All phrasing content elements.
|
|
3
5
|
*
|
|
4
6
|
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
|
|
5
7
|
*/
|
|
6
8
|
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {Record<string,SemanticElementDefinition>} ContentSchema
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @typedef SemanticElementDefinition
|
|
13
|
-
* @property {string[]} [attributes] Content attributes
|
|
14
|
-
* @property {ContentSchema|'*'} [children] Content attributes
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
9
|
/**
|
|
18
10
|
* All text-level semantic elements.
|
|
19
11
|
*
|
|
20
12
|
* @see https://html.spec.whatwg.org/multipage/text-level-semantics.html
|
|
21
|
-
*
|
|
22
|
-
* @type {ContentSchema}
|
|
23
13
|
*/
|
|
24
|
-
const textContentSchema = {
|
|
14
|
+
const textContentSchema: ContentSchema = {
|
|
25
15
|
strong: {},
|
|
26
16
|
em: {},
|
|
27
17
|
s: {},
|
|
@@ -60,10 +50,8 @@ const textContentSchema = {
|
|
|
60
50
|
* Embedded content elements.
|
|
61
51
|
*
|
|
62
52
|
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0
|
|
63
|
-
*
|
|
64
|
-
* @type {ContentSchema}
|
|
65
53
|
*/
|
|
66
|
-
const embeddedContentSchema = {
|
|
54
|
+
const embeddedContentSchema: ContentSchema = {
|
|
67
55
|
audio: {
|
|
68
56
|
attributes: [
|
|
69
57
|
'src',
|
|
@@ -150,19 +138,16 @@ const phrasingContentSchema = {
|
|
|
150
138
|
*
|
|
151
139
|
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
|
|
152
140
|
*
|
|
153
|
-
* @param
|
|
154
|
-
*
|
|
141
|
+
* @param [context] Set to "paste" to exclude invisible elements and
|
|
142
|
+
* sensitive data.
|
|
155
143
|
*
|
|
156
|
-
* @return
|
|
144
|
+
* @return Schema.
|
|
157
145
|
*/
|
|
158
|
-
export function getPhrasingContentSchema( context ) {
|
|
146
|
+
export function getPhrasingContentSchema( context?: string ): ContentSchema {
|
|
159
147
|
if ( context !== 'paste' ) {
|
|
160
148
|
return phrasingContentSchema;
|
|
161
149
|
}
|
|
162
150
|
|
|
163
|
-
/**
|
|
164
|
-
* @type {Partial<ContentSchema>}
|
|
165
|
-
*/
|
|
166
151
|
const {
|
|
167
152
|
u, // Used to mark misspelling. Shouldn't be pasted.
|
|
168
153
|
abbr, // Invisible.
|
|
@@ -172,7 +157,7 @@ export function getPhrasingContentSchema( context ) {
|
|
|
172
157
|
bdi, // Invisible.
|
|
173
158
|
bdo, // Invisible.
|
|
174
159
|
...remainingContentSchema
|
|
175
|
-
} = {
|
|
160
|
+
}: ContentSchema = {
|
|
176
161
|
...phrasingContentSchema,
|
|
177
162
|
// We shouldn't paste potentially sensitive information which is not
|
|
178
163
|
// visible to the user when pasted, so strip the attributes.
|
|
@@ -188,20 +173,20 @@ export function getPhrasingContentSchema( context ) {
|
|
|
188
173
|
*
|
|
189
174
|
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
|
|
190
175
|
*
|
|
191
|
-
* @param
|
|
176
|
+
* @param node The node to test.
|
|
192
177
|
*
|
|
193
|
-
* @return
|
|
178
|
+
* @return True if phrasing content, false if not.
|
|
194
179
|
*/
|
|
195
|
-
export function isPhrasingContent( node ) {
|
|
180
|
+
export function isPhrasingContent( node: Node ): boolean {
|
|
196
181
|
const tag = node.nodeName.toLowerCase();
|
|
197
182
|
return getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';
|
|
198
183
|
}
|
|
199
184
|
|
|
200
185
|
/**
|
|
201
|
-
* @param
|
|
202
|
-
* @return
|
|
186
|
+
* @param node
|
|
187
|
+
* @return Node is text content
|
|
203
188
|
*/
|
|
204
|
-
export function isTextContent( node ) {
|
|
189
|
+
export function isTextContent( node: Node ): boolean {
|
|
205
190
|
const tag = node.nodeName.toLowerCase();
|
|
206
191
|
return textContentSchema.hasOwnProperty( tag ) || tag === 'span';
|
|
207
192
|
}
|