@wordpress/dom 4.42.0 → 4.43.1-next.v.202604091042.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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.43.0 (2026-04-01)
6
+
5
7
  ## 4.42.0 (2026-03-18)
6
8
 
7
9
  ## 4.41.0 (2026-03-04)
@@ -24,19 +24,19 @@ __export(caret_range_from_point_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(caret_range_from_point_exports);
26
26
  function caretRangeFromPoint(doc, x, y) {
27
+ if (doc.caretPositionFromPoint) {
28
+ const point = doc.caretPositionFromPoint(x, y);
29
+ if (!point) {
30
+ return null;
31
+ }
32
+ const range = doc.createRange();
33
+ range.setStart(point.offsetNode, point.offset);
34
+ range.collapse(true);
35
+ return range;
36
+ }
27
37
  if (doc.caretRangeFromPoint) {
28
38
  return doc.caretRangeFromPoint(x, y);
29
39
  }
30
- if (!doc.caretPositionFromPoint) {
31
- return null;
32
- }
33
- const point = doc.caretPositionFromPoint(x, y);
34
- if (!point) {
35
- return null;
36
- }
37
- const range = doc.createRange();
38
- range.setStart(point.offsetNode, point.offset);
39
- range.collapse(true);
40
- return range;
40
+ return null;
41
41
  }
42
42
  //# sourceMappingURL=caret-range-from-point.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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;",
4
+ "sourcesContent": ["/**\n * Get a collapsed range for a given point.\n *\n * Prefers the standard `caretPositionFromPoint` API and falls back to the\n * non-standard, WebKit-originated `caretRangeFromPoint` for older browsers.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint\n *\n * @param {Document} 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.caretPositionFromPoint ) {\n\t\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint\n\t\tif ( ! point ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst range = doc.createRange();\n\n\t\trange.setStart( point.offsetNode, point.offset );\n\t\trange.collapse( true );\n\n\t\treturn range;\n\t}\n\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\treturn null;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAce,SAAR,oBAAsC,KAAK,GAAG,GAAI;AACxD,MAAK,IAAI,wBAAyB;AACjC,UAAM,QAAQ,IAAI,uBAAwB,GAAG,CAAE;AAI/C,QAAK,CAAE,OAAQ;AACd,aAAO;AAAA,IACR;AAEA,UAAM,QAAQ,IAAI,YAAY;AAE9B,UAAM,SAAU,MAAM,YAAY,MAAM,MAAO;AAC/C,UAAM,SAAU,IAAK;AAErB,WAAO;AAAA,EACR;AAEA,MAAK,IAAI,qBAAsB;AAC9B,WAAO,IAAI,oBAAqB,GAAG,CAAE;AAAA,EACtC;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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/**\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\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"],
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/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against. Use '*' to keep all classes.\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\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"],
5
5
  "mappings": "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",
6
6
  "names": ["isElement", "require", "isEmpty", "remove", "unwrap", "insertAfter"]
7
7
  }
@@ -51,7 +51,7 @@ function inputFieldHasUncollapsedSelection(element) {
51
51
  selectionStart === null || // when not null, compare the two points
52
52
  selectionStart !== selectionEnd
53
53
  );
54
- } catch (error) {
54
+ } catch {
55
55
  return true;
56
56
  }
57
57
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/input-field-has-uncollapsed-selection.js"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textarea element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch ( error ) {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAwB;AACxB,mCAA+B;AAmBhB,SAAR,kCAAoD,SAAU;AACpE,MAAK,KAAE,6BAAAA,SAAoB,OAAQ,KAAK,KAAE,qBAAAC,SAAa,OAAQ,GAAI;AAClE,WAAO;AAAA,EACR;AAKA,MAAI;AACH,UAAM,EAAE,gBAAgB,aAAa;AAAA;AAAA,MACoB;AAAA;AACzD;AAAA;AAAA;AAAA;AAAA,MAIC,mBAAmB;AAAA,MAEnB,mBAAmB;AAAA;AAAA,EAErB,SAAU,OAAQ;AAGjB,WAAO;AAAA,EACR;AACD;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textarea element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAAwB;AACxB,mCAA+B;AAmBhB,SAAR,kCAAoD,SAAU;AACpE,MAAK,KAAE,6BAAAA,SAAoB,OAAQ,KAAK,KAAE,qBAAAC,SAAa,OAAQ,GAAI;AAClE,WAAO;AAAA,EACR;AAKA,MAAI;AACH,UAAM,EAAE,gBAAgB,aAAa;AAAA;AAAA,MACoB;AAAA;AACzD;AAAA;AAAA;AAAA;AAAA,MAIC,mBAAmB;AAAA,MAEnB,mBAAmB;AAAA;AAAA,EAErB,QAAQ;AAGP,WAAO;AAAA,EACR;AACD;",
6
6
  "names": ["isHTMLInputElement", "isTextField"]
7
7
  }
@@ -1,19 +1,19 @@
1
1
  // packages/dom/src/dom/caret-range-from-point.js
2
2
  function caretRangeFromPoint(doc, x, y) {
3
+ if (doc.caretPositionFromPoint) {
4
+ const point = doc.caretPositionFromPoint(x, y);
5
+ if (!point) {
6
+ return null;
7
+ }
8
+ const range = doc.createRange();
9
+ range.setStart(point.offsetNode, point.offset);
10
+ range.collapse(true);
11
+ return range;
12
+ }
3
13
  if (doc.caretRangeFromPoint) {
4
14
  return doc.caretRangeFromPoint(x, y);
5
15
  }
6
- if (!doc.caretPositionFromPoint) {
7
- return null;
8
- }
9
- const point = doc.caretPositionFromPoint(x, y);
10
- if (!point) {
11
- return null;
12
- }
13
- const range = doc.createRange();
14
- range.setStart(point.offsetNode, point.offset);
15
- range.collapse(true);
16
- return range;
16
+ return null;
17
17
  }
18
18
  export {
19
19
  caretRangeFromPoint as default
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": ";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;",
4
+ "sourcesContent": ["/**\n * Get a collapsed range for a given point.\n *\n * Prefers the standard `caretPositionFromPoint` API and falls back to the\n * non-standard, WebKit-originated `caretRangeFromPoint` for older browsers.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint\n *\n * @param {Document} 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.caretPositionFromPoint ) {\n\t\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint\n\t\tif ( ! point ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst range = doc.createRange();\n\n\t\trange.setStart( point.offsetNode, point.offset );\n\t\trange.collapse( true );\n\n\t\treturn range;\n\t}\n\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\treturn null;\n}\n"],
5
+ "mappings": ";AAce,SAAR,oBAAsC,KAAK,GAAG,GAAI;AACxD,MAAK,IAAI,wBAAyB;AACjC,UAAM,QAAQ,IAAI,uBAAwB,GAAG,CAAE;AAI/C,QAAK,CAAE,OAAQ;AACd,aAAO;AAAA,IACR;AAEA,UAAM,QAAQ,IAAI,YAAY;AAE9B,UAAM,SAAU,MAAM,YAAY,MAAM,MAAO;AAC/C,UAAM,SAAU,IAAK;AAErB,WAAO;AAAA,EACR;AAEA,MAAK,IAAI,qBAAsB;AAC9B,WAAO,IAAI,oBAAqB,GAAG,CAAE;AAAA,EACtC;AAEA,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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/**\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\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"],
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/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against. Use '*' to keep all classes.\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\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"],
5
5
  "mappings": "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",
6
6
  "names": ["require"]
7
7
  }
@@ -17,7 +17,7 @@ function inputFieldHasUncollapsedSelection(element) {
17
17
  selectionStart === null || // when not null, compare the two points
18
18
  selectionStart !== selectionEnd
19
19
  );
20
- } catch (error) {
20
+ } catch {
21
21
  return true;
22
22
  }
23
23
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/dom/input-field-has-uncollapsed-selection.js"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textarea element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch ( error ) {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],
5
- "mappings": ";AAGA,OAAO,iBAAiB;AACxB,OAAO,wBAAwB;AAmBhB,SAAR,kCAAoD,SAAU;AACpE,MAAK,CAAE,mBAAoB,OAAQ,KAAK,CAAE,YAAa,OAAQ,GAAI;AAClE,WAAO;AAAA,EACR;AAKA,MAAI;AACH,UAAM,EAAE,gBAAgB,aAAa;AAAA;AAAA,MACoB;AAAA;AACzD;AAAA;AAAA;AAAA;AAAA,MAIC,mBAAmB;AAAA,MAEnB,mBAAmB;AAAA;AAAA,EAErB,SAAU,OAAQ;AAGjB,WAAO;AAAA,EACR;AACD;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textarea element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],
5
+ "mappings": ";AAGA,OAAO,iBAAiB;AACxB,OAAO,wBAAwB;AAmBhB,SAAR,kCAAoD,SAAU;AACpE,MAAK,CAAE,mBAAoB,OAAQ,KAAK,CAAE,YAAa,OAAQ,GAAI;AAClE,WAAO;AAAA,EACR;AAKA,MAAI;AACH,UAAM,EAAE,gBAAgB,aAAa;AAAA;AAAA,MACoB;AAAA;AACzD;AAAA;AAAA;AAAA;AAAA,MAIC,mBAAmB;AAAA,MAEnB,mBAAmB;AAAA;AAAA,EAErB,QAAQ;AAGP,WAAO;AAAA,EACR;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,22 +1,16 @@
1
1
  /**
2
- * Polyfill.
3
2
  * Get a collapsed range for a given point.
4
3
  *
5
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
4
+ * Prefers the standard `caretPositionFromPoint` API and falls back to the
5
+ * non-standard, WebKit-originated `caretRangeFromPoint` for older browsers.
6
6
  *
7
- * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
8
- * @param {number} x Horizontal position within the current viewport.
9
- * @param {number} y Vertical position within the current viewport.
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint
8
+ *
9
+ * @param {Document} doc The document of the range.
10
+ * @param {number} x Horizontal position within the current viewport.
11
+ * @param {number} y Vertical position within the current viewport.
10
12
  *
11
13
  * @return {Range | null} The best range for the given point.
12
14
  */
13
- export default function caretRangeFromPoint(doc: DocumentMaybeWithCaretPositionFromPoint, x: number, y: number): Range | null;
14
- export type DocumentMaybeWithCaretPositionFromPoint = {
15
- caretPositionFromPoint?: (x: number, y: number) => CaretPosition | null;
16
- } & Document;
17
- export type CaretPosition = {
18
- readonly offset: number;
19
- readonly offsetNode: Node;
20
- getClientRect(): DOMRect | null;
21
- };
15
+ export default function caretRangeFromPoint(doc: Document, x: number, y: number): Range | null;
22
16
  //# sourceMappingURL=caret-range-from-point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"caret-range-from-point.d.ts","sourceRoot":"","sources":["../../src/dom/caret-range-from-point.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,iDANW,uCAAuC,KACvC,MAAM,KACN,MAAM,GAEL,KAAK,GAAG,IAAI,CAyBvB;sDAGY;IAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAI,aAAa,GAAG,IAAI,CAAA;CAAC,GAAG,QAAQ;4BACnF;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAAC,aAAa,IAAI,OAAO,GAAG,IAAI,CAAC;CAAE"}
1
+ {"version":3,"file":"caret-range-from-point.d.ts","sourceRoot":"","sources":["../../src/dom/caret-range-from-point.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,iDANW,QAAQ,KACR,MAAM,KACN,MAAM,GAEL,KAAK,GAAG,IAAI,CAyBvB"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @typedef SchemaItem
3
3
  * @property {string[]} [attributes] Attributes.
4
- * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.
4
+ * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against. Use '*' to keep all classes.
5
5
  * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.
6
6
  * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.
7
7
  * @property {boolean} allowEmpty Whether to allow nodes without children.
@@ -24,7 +24,7 @@ export type SchemaItem = {
24
24
  */
25
25
  attributes?: string[] | undefined;
26
26
  /**
27
- * Classnames or RegExp to test against.
27
+ * Classnames or RegExp to test against. Use '*' to keep all classes.
28
28
  */
29
29
  classes?: (string | RegExp)[] | undefined;
30
30
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dom",
3
- "version": "4.42.0",
3
+ "version": "4.43.1-next.v.202604091042.0+668146787",
4
4
  "description": "DOM utilities module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -45,10 +45,10 @@
45
45
  "types": "build-types",
46
46
  "sideEffects": false,
47
47
  "dependencies": {
48
- "@wordpress/deprecated": "^4.42.0"
48
+ "@wordpress/deprecated": "^4.43.1-next.v.202604091042.0+668146787"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "c20787b1778ae64c2db65643b1c236309d68e6ba"
53
+ "gitHead": "73606df74f1c38a084bfa5db97205259ef817593"
54
54
  }
@@ -1,41 +1,38 @@
1
1
  /**
2
- * Polyfill.
3
2
  * Get a collapsed range for a given point.
4
3
  *
5
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
4
+ * Prefers the standard `caretPositionFromPoint` API and falls back to the
5
+ * non-standard, WebKit-originated `caretRangeFromPoint` for older browsers.
6
6
  *
7
- * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
8
- * @param {number} x Horizontal position within the current viewport.
9
- * @param {number} y Vertical position within the current viewport.
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint
8
+ *
9
+ * @param {Document} doc The document of the range.
10
+ * @param {number} x Horizontal position within the current viewport.
11
+ * @param {number} y Vertical position within the current viewport.
10
12
  *
11
13
  * @return {Range | null} The best range for the given point.
12
14
  */
13
15
  export default function caretRangeFromPoint( doc, x, y ) {
14
- if ( doc.caretRangeFromPoint ) {
15
- return doc.caretRangeFromPoint( x, y );
16
- }
16
+ if ( doc.caretPositionFromPoint ) {
17
+ const point = doc.caretPositionFromPoint( x, y );
17
18
 
18
- if ( ! doc.caretPositionFromPoint ) {
19
- return null;
20
- }
19
+ // If x or y are negative, outside viewport, or there is no text entry node.
20
+ // https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint
21
+ if ( ! point ) {
22
+ return null;
23
+ }
21
24
 
22
- const point = doc.caretPositionFromPoint( x, y );
25
+ const range = doc.createRange();
23
26
 
24
- // If x or y are negative, outside viewport, or there is no text entry node.
25
- // https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
26
- if ( ! point ) {
27
- return null;
28
- }
27
+ range.setStart( point.offsetNode, point.offset );
28
+ range.collapse( true );
29
29
 
30
- const range = doc.createRange();
30
+ return range;
31
+ }
31
32
 
32
- range.setStart( point.offsetNode, point.offset );
33
- range.collapse( true );
33
+ if ( doc.caretRangeFromPoint ) {
34
+ return doc.caretRangeFromPoint( x, y );
35
+ }
34
36
 
35
- return range;
37
+ return null;
36
38
  }
37
-
38
- /**
39
- * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
40
- * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
41
- */
@@ -13,7 +13,7 @@ const noop = () => {};
13
13
  /**
14
14
  * @typedef SchemaItem
15
15
  * @property {string[]} [attributes] Attributes.
16
- * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.
16
+ * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against. Use '*' to keep all classes.
17
17
  * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.
18
18
  * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.
19
19
  * @property {boolean} allowEmpty Whether to allow nodes without children.
@@ -40,7 +40,7 @@ export default function inputFieldHasUncollapsedSelection( element ) {
40
40
  // when not null, compare the two points
41
41
  selectionStart !== selectionEnd
42
42
  );
43
- } catch ( error ) {
43
+ } catch {
44
44
  // This is Safari's way of saying that the input type doesn't implement
45
45
  // selection, so we default to true.
46
46
  return true;