@wordpress/dom 3.12.0 → 3.15.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 +8 -0
- package/README.md +3 -2
- package/build/dom/clean-node-list.js +1 -7
- package/build/dom/clean-node-list.js.map +1 -1
- package/build/dom/get-rectangle-from-range.js +11 -3
- package/build/dom/get-rectangle-from-range.js.map +1 -1
- package/build/dom/is-form-element.js +4 -0
- package/build/dom/is-form-element.js.map +1 -1
- package/build/dom/place-caret-at-edge.js +6 -0
- package/build/dom/place-caret-at-edge.js.map +1 -1
- package/build/phrasing-content.js +31 -18
- package/build/phrasing-content.js.map +1 -1
- package/build/tabbable.js +6 -9
- package/build/tabbable.js.map +1 -1
- package/build-module/dom/clean-node-list.js +1 -6
- package/build-module/dom/clean-node-list.js.map +1 -1
- package/build-module/dom/get-rectangle-from-range.js +11 -3
- package/build-module/dom/get-rectangle-from-range.js.map +1 -1
- package/build-module/dom/is-form-element.js +4 -0
- package/build-module/dom/is-form-element.js.map +1 -1
- package/build-module/dom/place-caret-at-edge.js +6 -0
- package/build-module/dom/place-caret-at-edge.js.map +1 -1
- package/build-module/phrasing-content.js +30 -16
- package/build-module/phrasing-content.js.map +1 -1
- package/build-module/tabbable.js +6 -8
- package/build-module/tabbable.js.map +1 -1
- package/build-types/dom/clean-node-list.d.ts.map +1 -1
- package/build-types/dom/get-rectangle-from-range.d.ts +4 -3
- package/build-types/dom/get-rectangle-from-range.d.ts.map +1 -1
- package/build-types/dom/is-form-element.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
- package/build-types/phrasing-content.d.ts.map +1 -1
- package/build-types/tabbable.d.ts +2 -0
- package/build-types/tabbable.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/dom/clean-node-list.js +1 -6
- package/src/dom/get-rectangle-from-range.js +12 -3
- package/src/dom/is-form-element.js +4 -0
- package/src/dom/place-caret-at-edge.js +6 -0
- package/src/phrasing-content.js +28 -26
- package/src/tabbable.js +6 -8
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -122,7 +122,8 @@ _Returns_
|
|
122
122
|
|
123
123
|
### getRectangleFromRange
|
124
124
|
|
125
|
-
Get the rectangle of a given Range.
|
125
|
+
Get the rectangle of a given Range. Returns `null` if no suitable rectangle
|
126
|
+
can be found.
|
126
127
|
|
127
128
|
_Parameters_
|
128
129
|
|
@@ -130,7 +131,7 @@ _Parameters_
|
|
130
131
|
|
131
132
|
_Returns_
|
132
133
|
|
133
|
-
- `DOMRect
|
134
|
+
- `DOMRect?`: The rectangle.
|
134
135
|
|
135
136
|
### getScrollContainer
|
136
137
|
|
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = cleanNodeList;
|
9
9
|
|
10
|
-
var _lodash = require("lodash");
|
11
|
-
|
12
10
|
var _isEmpty = _interopRequireDefault(require("./is-empty"));
|
13
11
|
|
14
12
|
var _remove = _interopRequireDefault(require("./remove"));
|
@@ -21,10 +19,6 @@ var _insertAfter = _interopRequireDefault(require("./insert-after"));
|
|
21
19
|
|
22
20
|
var _isElement = _interopRequireDefault(require("./is-element"));
|
23
21
|
|
24
|
-
/**
|
25
|
-
* External dependencies
|
26
|
-
*/
|
27
|
-
|
28
22
|
/**
|
29
23
|
* Internal dependencies
|
30
24
|
*/
|
@@ -88,7 +82,7 @@ function cleanNodeList(nodeList, doc, schema, inline) {
|
|
88
82
|
name
|
89
83
|
} = _ref;
|
90
84
|
|
91
|
-
if (name !== 'class' && !
|
85
|
+
if (name !== 'class' && !attributes.includes(name)) {
|
92
86
|
node.removeAttribute(name);
|
93
87
|
}
|
94
88
|
}); // Strip invalid classes.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"names":["noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","attributes","classes","children","require","allowEmpty","hasAttributes","name","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","remove","hasChildNodes","querySelector","join","childNodes","parentNode","child","firstChild","nextElementSibling","createElement"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;AAQA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASC,aAAT,CAAwBC,QAAxB,EAAkCC,GAAlC,EAAuCC,MAAvC,EAA+CC,MAA/C,EAAwD;AACtEC,EAAAA,KAAK,CAACC,IAAN,CAAYL,QAAZ,EAAuBM,OAAvB,CACC;AAAE;AAAuDC,EAAAA,IAAzD,KAAmE;AAAA;;AAClE,UAAMC,GAAG,GAAGD,IAAI,CAACE,QAAL,CAAcC,WAAd,EAAZ,CADkE,CAGlE;AACA;;AACA,QACCR,MAAM,CAACS,cAAP,CAAuBH,GAAvB,MACE,CAAEN,MAAM,CAAEM,GAAF,CAAN,CAAcI,OAAhB,2BAA2B,eAAAV,MAAM,CAAEM,GAAF,CAAN,EAAcI,OAAzC,gDAA2B,sCAAyBL,IAAzB,CAD7B,CADD,EAGE;AACD,UAAK,wBAAWA,IAAX,CAAL,EAAyB;AACxB,cAAM;AACLM,UAAAA,UAAU,GAAG,EADR;AAELC,UAAAA,OAAO,GAAG,EAFL;AAGLC,UAAAA,QAHK;AAILC,UAAAA,OAAO,GAAG,EAJL;AAKLC,UAAAA;AALK,YAMFf,MAAM,CAAEM,GAAF,CANV,CADwB,CASxB;AACA;;AACA,YAAKO,QAAQ,IAAI,CAAEE,UAAd,IAA4B,sBAASV,IAAT,CAAjC,EAAmD;AAClD,+BAAQA,IAAR;AACA;AACA;;AAED,YA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AAC+B,kBAHN,EAIE;AACD,kCAAarC,GAAG,CAACsC,aAAJ,CAAmB,IAAnB,CAAb,EAAwChC,IAAxC;AACA;;AAED,2BAAQA,IAAR;AACA;AACD,GAnJF;AAqJA","sourcesContent":["/**\n * External dependencies\n */\nimport { includes } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! includes( attributes, 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 ( 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"]}
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"names":["noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","attributes","classes","children","require","allowEmpty","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","remove","hasChildNodes","querySelector","join","childNodes","parentNode","child","firstChild","nextElementSibling","createElement"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AARA;AACA;AACA;AAQA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASC,aAAT,CAAwBC,QAAxB,EAAkCC,GAAlC,EAAuCC,MAAvC,EAA+CC,MAA/C,EAAwD;AACtEC,EAAAA,KAAK,CAACC,IAAN,CAAYL,QAAZ,EAAuBM,OAAvB,CACC;AAAE;AAAuDC,EAAAA,IAAzD,KAAmE;AAAA;;AAClE,UAAMC,GAAG,GAAGD,IAAI,CAACE,QAAL,CAAcC,WAAd,EAAZ,CADkE,CAGlE;AACA;;AACA,QACCR,MAAM,CAACS,cAAP,CAAuBH,GAAvB,MACE,CAAEN,MAAM,CAAEM,GAAF,CAAN,CAAcI,OAAhB,2BAA2B,eAAAV,MAAM,CAAEM,GAAF,CAAN,EAAcI,OAAzC,gDAA2B,sCAAyBL,IAAzB,CAD7B,CADD,EAGE;AACD,UAAK,wBAAWA,IAAX,CAAL,EAAyB;AACxB,cAAM;AACLM,UAAAA,UAAU,GAAG,EADR;AAELC,UAAAA,OAAO,GAAG,EAFL;AAGLC,UAAAA,QAHK;AAILC,UAAAA,OAAO,GAAG,EAJL;AAKLC,UAAAA;AALK,YAMFf,MAAM,CAAEM,GAAF,CANV,CADwB,CASxB;AACA;;AACA,YAAKO,QAAQ,IAAI,CAAEE,UAAd,IAA4B,sBAASV,IAAT,CAAjC,EAAmD;AAClD,+BA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wCAAmBI,IAAnB,CADF,IAEAA,IAAI,CAACgC,kBAHN,EAIE;AACD,kCAAatC,GAAG,CAACuC,aAAJ,CAAmB,IAAnB,CAAb,EAAwCjC,IAAxC;AACA;;AAED,2BAAQA,IAAR;AACA;AACD,GAnJF;AAqJA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( 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"]}
|
@@ -12,11 +12,12 @@ var _assertIsDefined = require("../utils/assert-is-defined");
|
|
12
12
|
*/
|
13
13
|
|
14
14
|
/**
|
15
|
-
* Get the rectangle of a given Range.
|
15
|
+
* Get the rectangle of a given Range. Returns `null` if no suitable rectangle
|
16
|
+
* can be found.
|
16
17
|
*
|
17
18
|
* @param {Range} range The range.
|
18
19
|
*
|
19
|
-
* @return {DOMRect} The rectangle.
|
20
|
+
* @return {DOMRect?} The rectangle.
|
20
21
|
*/
|
21
22
|
function getRectangleFromRange(range) {
|
22
23
|
// For uncollapsed ranges, get the rectangle that bounds the contents of the
|
@@ -88,7 +89,14 @@ function getRectangleFromRange(range) {
|
|
88
89
|
range.setEnd(parentNode, index);
|
89
90
|
}
|
90
91
|
|
91
|
-
|
92
|
+
const rects = range.getClientRects(); // If we have multiple rectangles for a collapsed range, there's no way to
|
93
|
+
// know which it is, so don't return anything.
|
94
|
+
|
95
|
+
if (rects.length > 1) {
|
96
|
+
return null;
|
97
|
+
}
|
98
|
+
|
99
|
+
let rect = rects[0]; // If the collapsed range starts (and therefore ends) at an element node,
|
92
100
|
// `getClientRects` can be empty in some browsers. This can be resolved
|
93
101
|
// by adding a temporary text node with zero-width space to the range.
|
94
102
|
//
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"names":["getRectangleFromRange","range","collapsed","rects","Array","from","getClientRects","length","filteredRects","filter","width","getBoundingClientRect","top","furthestTop","bottom","furthestBottom","left","furthestLeft","right","furthestRight","window","DOMRect","startContainer","ownerDocument","nodeName","parentNode","index","childNodes","indexOf","createRange","setStart","setEnd","rect","padNode","createTextNode","cloneRange","insertNode","removeChild"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,qBAAT,CAAgCC,KAAhC,EAAwC;AACtD;AACA;AACA;AACA,MAAK,CAAEA,KAAK,CAACC,SAAb,EAAyB;AACxB,UAAMC,KAAK,GAAGC,KAAK,CAACC,IAAN,CAAYJ,KAA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A3B;AACA,QAAM;AAAEsB,IAAAA;AAAF,MAAoBD,cAA1B,CA/CsD,CAiDtD;;AACA,MAAKA,cAAc,CAACE,QAAf,KAA4B,IAAjC,EAAwC;AACvC,UAAM;AAAEC,MAAAA;AAAF,QAAiBH,cAAvB;AACA,0CAAiBG,UAAjB,EAA6B,YAA7B;AACA,UAAMC,KAAK;AAAG;AACbtB,IAAAA,KAAK,CAACC,IAAN,CAAYoB,UAAU,CAACE,UAAvB,CADmC,CAElCC,OAFkC,CAEzBN,cAFyB,CAApC;AAIA,0CAAiBC,aAAjB,EAAgC,eAAhC;AACAtB,IAAAA,KAAK,GAAGsB,aAAa,CAACM,WAAd,EAAR;AACA5B,IAAAA,KAAK,CAAC6B,QAAN,CAAgBL,UAAhB,EAA4BC,KAA5B;AACAzB,IAAAA,KAAK,CAAC8B,MAAN,CAAcN,UAAd,EAA0BC,KAA1B;AACA;;AAED,
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"names":["getRectangleFromRange","range","collapsed","rects","Array","from","getClientRects","length","filteredRects","filter","width","getBoundingClientRect","top","furthestTop","bottom","furthestBottom","left","furthestLeft","right","furthestRight","window","DOMRect","startContainer","ownerDocument","nodeName","parentNode","index","childNodes","indexOf","createRange","setStart","setEnd","rect","padNode","createTextNode","cloneRange","insertNode","removeChild"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,qBAAT,CAAgCC,KAAhC,EAAwC;AACtD;AACA;AACA;AACA,MAAK,CAAEA,KAAK,CAACC,SAAb,EAAyB;AACxB,UAAMC,KAAK,GAAGC,KAAK,CAACC,IAAN,CAAYJ,KAAK,CAACK,cAAN,EAAZ,CAAd,CADwB,CAGxB;;AACA,QAAKH,KAAK,CAACI,MAAN,KAAiB,CAAtB,EAA0B;AACzB,aAAOJ,KAAK,CAAE,CAAF,CAAZ;AACA,KANuB,CAQxB;;;AACA,U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BH,cAAvB;AACA,0CAAiBG,UAAjB,EAA6B,YAA7B;AACA,UAAMC,KAAK;AAAG;AACbtB,IAAAA,KAAK,CAACC,IAAN,CAAYoB,UAAU,CAACE,UAAvB,CADmC,CAElCC,OAFkC,CAEzBN,cAFyB,CAApC;AAIA,0CAAiBC,aAAjB,EAAgC,eAAhC;AACAtB,IAAAA,KAAK,GAAGsB,aAAa,CAACM,WAAd,EAAR;AACA5B,IAAAA,KAAK,CAAC6B,QAAN,CAAgBL,UAAhB,EAA4BC,KAA5B;AACAzB,IAAAA,KAAK,CAAC8B,MAAN,CAAcN,UAAd,EAA0BC,KAA1B;AACA;;AAED,QAAMvB,KAAK,GAAGF,KAAK,CAACK,cAAN,EAAd,CA/DsD,CAiEtD;AACA;;AACA,MAAKH,KAAK,CAACI,MAAN,GAAe,CAApB,EAAwB;AACvB,WAAO,IAAP;AACA;;AAED,MAAIyB,IAAI,GAAG7B,KAAK,CAAE,CAAF,CAAhB,CAvEsD,CAyEtD;AACA;AACA;AACA;AACA;;AACA,MAAK,CAAE6B,IAAP,EAAc;AACb,0CAAiBT,aAAjB,EAAgC,eAAhC;AACA,UAAMU,OAAO,GAAGV,aAAa,CAACW,cAAd,CAA8B,QAA9B,CAAhB,CAFa,CAGb;;AACAjC,IAAAA,KAAK,GAAGA,KAAK,CAACkC,UAAN,EAAR;AACAlC,IAAAA,KAAK,CAACmC,UAAN,CAAkBH,OAAlB;AACAD,IAAAA,IAAI,GAAG/B,KAAK,CAACK,cAAN,GAAwB,CAAxB,CAAP;AACA,0CAAiB2B,OAAO,CAACR,UAAzB,EAAqC,oBAArC;AACAQ,IAAAA,OAAO,CAACR,UAAR,CAAmBY,WAAnB,CAAgCJ,OAAhC;AACA;;AAED,SAAOD,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle of a given Range. Returns `null` if no suitable rectangle\n * can be found.\n *\n * @param {Range} range The range.\n *\n * @return {DOMRect?} The rectangle.\n */\nexport default function getRectangleFromRange( range ) {\n\t// For uncollapsed ranges, get the rectangle that bounds the contents of the\n\t// range; this a rectangle enclosing the union of the bounding rectangles\n\t// for all the elements in the range.\n\tif ( ! range.collapsed ) {\n\t\tconst rects = Array.from( range.getClientRects() );\n\n\t\t// If there's just a single rect, return it.\n\t\tif ( rects.length === 1 ) {\n\t\t\treturn rects[ 0 ];\n\t\t}\n\n\t\t// Ignore tiny selection at the edge of a range.\n\t\tconst filteredRects = rects.filter( ( { width } ) => width > 1 );\n\n\t\t// If it's full of tiny selections, return browser default.\n\t\tif ( filteredRects.length === 0 ) {\n\t\t\treturn range.getBoundingClientRect();\n\t\t}\n\n\t\tif ( filteredRects.length === 1 ) {\n\t\t\treturn filteredRects[ 0 ];\n\t\t}\n\n\t\tlet {\n\t\t\ttop: furthestTop,\n\t\t\tbottom: furthestBottom,\n\t\t\tleft: furthestLeft,\n\t\t\tright: furthestRight,\n\t\t} = filteredRects[ 0 ];\n\n\t\tfor ( const { top, bottom, left, right } of filteredRects ) {\n\t\t\tif ( top < furthestTop ) furthestTop = top;\n\t\t\tif ( bottom > furthestBottom ) furthestBottom = bottom;\n\t\t\tif ( left < furthestLeft ) furthestLeft = left;\n\t\t\tif ( right > furthestRight ) furthestRight = right;\n\t\t}\n\n\t\treturn new window.DOMRect(\n\t\t\tfurthestLeft,\n\t\t\tfurthestTop,\n\t\t\tfurthestRight - furthestLeft,\n\t\t\tfurthestBottom - furthestTop\n\t\t);\n\t}\n\n\tconst { startContainer } = range;\n\tconst { ownerDocument } = startContainer;\n\n\t// Correct invalid \"BR\" ranges. The cannot contain any children.\n\tif ( startContainer.nodeName === 'BR' ) {\n\t\tconst { parentNode } = startContainer;\n\t\tassertIsDefined( parentNode, 'parentNode' );\n\t\tconst index = /** @type {Node[]} */ (\n\t\t\tArray.from( parentNode.childNodes )\n\t\t).indexOf( startContainer );\n\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\trange = ownerDocument.createRange();\n\t\trange.setStart( parentNode, index );\n\t\trange.setEnd( parentNode, index );\n\t}\n\n\tconst rects = range.getClientRects();\n\n\t// If we have multiple rectangles for a collapsed range, there's no way to\n\t// know which it is, so don't return anything.\n\tif ( rects.length > 1 ) {\n\t\treturn null;\n\t}\n\n\tlet rect = rects[ 0 ];\n\n\t// If the collapsed range starts (and therefore ends) at an element node,\n\t// `getClientRects` can be empty in some browsers. This can be resolved\n\t// by adding a temporary text node with zero-width space to the range.\n\t//\n\t// See: https://stackoverflow.com/a/6847328/995445\n\tif ( ! rect ) {\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\tconst padNode = ownerDocument.createTextNode( '\\u200b' );\n\t\t// Do not modify the live range.\n\t\trange = range.cloneRange();\n\t\trange.insertNode( padNode );\n\t\trect = range.getClientRects()[ 0 ];\n\t\tassertIsDefined( padNode.parentNode, 'padNode.parentNode' );\n\t\tpadNode.parentNode.removeChild( padNode );\n\t}\n\n\treturn rect;\n}\n"]}
|
@@ -22,6 +22,10 @@ var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area
|
|
22
22
|
* @return {boolean} True if form element and false otherwise.
|
23
23
|
*/
|
24
24
|
function isFormElement(element) {
|
25
|
+
if (!element) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
|
25
29
|
const {
|
26
30
|
tagName
|
27
31
|
} = element;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/is-form-element.js"],"names":["isFormElement","element","tagName","checkForInputTextarea"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAT,CAAwBC,OAAxB,EAAkC;AAChD,QAAM;AAAEC,IAAAA;AAAF,MAAcD,OAApB;AACA,QAAME,qBAAqB,GAAG,gCAAmBF,OAAnB,CAA9B;AACA,SACCE,qBAAqB,IAAID,OAAO,KAAK,QAArC,IAAiDA,OAAO,KAAK,QAD9D;AAGA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isInputOrTextArea from './is-input-or-text-area';\n\n/**\n *\n * Detects if element is a form element.\n *\n * @param {Element} element The element to check.\n *\n * @return {boolean} True if form element and false otherwise.\n */\nexport default function isFormElement( element ) {\n\tconst { tagName } = element;\n\tconst checkForInputTextarea = isInputOrTextArea( element );\n\treturn (\n\t\tcheckForInputTextarea || tagName === 'BUTTON' || tagName === 'SELECT'\n\t);\n}\n"]}
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/is-form-element.js"],"names":["isFormElement","element","tagName","checkForInputTextarea"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAT,CAAwBC,OAAxB,EAAkC;AAChD,MAAK,CAAEA,OAAP,EAAiB;AAChB,WAAO,KAAP;AACA;;AAED,QAAM;AAAEC,IAAAA;AAAF,MAAcD,OAApB;AACA,QAAME,qBAAqB,GAAG,gCAAmBF,OAAnB,CAA9B;AACA,SACCE,qBAAqB,IAAID,OAAO,KAAK,QAArC,IAAiDA,OAAO,KAAK,QAD9D;AAGA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isInputOrTextArea from './is-input-or-text-area';\n\n/**\n *\n * Detects if element is a form element.\n *\n * @param {Element} element The element to check.\n *\n * @return {boolean} True if form element and false otherwise.\n */\nexport default function isFormElement( element ) {\n\tif ( ! element ) {\n\t\treturn false;\n\t}\n\n\tconst { tagName } = element;\n\tconst checkForInputTextarea = isInputOrTextArea( element );\n\treturn (\n\t\tcheckForInputTextarea || tagName === 'BUTTON' || tagName === 'SELECT'\n\t);\n}\n"]}
|
@@ -36,9 +36,15 @@ function getRange(container, isReverse, x) {
|
|
36
36
|
const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
|
37
37
|
const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
|
38
38
|
// right corner. When placing at the start, to the top left corner.
|
39
|
+
// Ensure x is defined and within the container's boundaries. When it's
|
40
|
+
// exactly at the boundary, it's not considered within the boundaries.
|
39
41
|
|
40
42
|
if (x === undefined) {
|
41
43
|
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
44
|
+
} else if (x <= containerRect.left) {
|
45
|
+
x = containerRect.left + 1;
|
46
|
+
} else if (x >= containerRect.right) {
|
47
|
+
x = containerRect.right - 1;
|
42
48
|
}
|
43
49
|
|
44
50
|
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-edge.js"],"names":["getRange","container","isReverse","x","ownerDocument","isReverseDir","containerRect","getBoundingClientRect","undefined","right","left","y","bottom","top","placeCaretAtEdge","focus","selectionStart","value","length","selectionEnd","isContentEditable","range","startContainer","contains","scrollIntoView","defaultView","selection","getSelection","removeAllRanges","addRange"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,CAAmBC,SAAnB,EAA8BC,SAA9B,EAAyCC,CAAzC,EAA6C;AAC5C,QAAM;AAAEC,IAAAA;AAAF,MAAoBH,SAA1B,CAD4C,CAE5C;;AACA,QAAMI,YAAY,GAAG,oBAAOJ,SAAP,IAAqB,CAAEC,SAAvB,GAAmCA,SAAxD;AACA,QAAMI,aAAa,GAAGL,SAAS,CAACM,qBAAV,EAAtB,CAJ4C,CAK5C;AACA;;AACA,MAAKJ,CAAC,KAAKK,SAAX,EAAuB;AACtBL,IAAAA,CAAC,GAAGD,SAAS,GAAGI,aAAa,CAACG,KAAd,GAAsB,CAAzB,GAA6BH,aAAa,CAACI,IAAd,GAAqB,CAA/D;AACA;;AACD,
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-edge.js"],"names":["getRange","container","isReverse","x","ownerDocument","isReverseDir","containerRect","getBoundingClientRect","undefined","right","left","y","bottom","top","placeCaretAtEdge","focus","selectionStart","value","length","selectionEnd","isContentEditable","range","startContainer","contains","scrollIntoView","defaultView","selection","getSelection","removeAllRanges","addRange"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,CAAmBC,SAAnB,EAA8BC,SAA9B,EAAyCC,CAAzC,EAA6C;AAC5C,QAAM;AAAEC,IAAAA;AAAF,MAAoBH,SAA1B,CAD4C,CAE5C;;AACA,QAAMI,YAAY,GAAG,oBAAOJ,SAAP,IAAqB,CAAEC,SAAvB,GAAmCA,SAAxD;AACA,QAAMI,aAAa,GAAGL,SAAS,CAACM,qBAAV,EAAtB,CAJ4C,CAK5C;AACA;AACA;AACA;;AACA,MAAKJ,CAAC,KAAKK,SAAX,EAAuB;AACtBL,IAAAA,CAAC,GAAGD,SAAS,GAAGI,aAAa,CAACG,KAAd,GAAsB,CAAzB,GAA6BH,aAAa,CAACI,IAAd,GAAqB,CAA/D;AACA,GAFD,MAEO,IAAKP,CAAC,IAAIG,aAAa,CAACI,IAAxB,EAA+B;AACrCP,IAAAA,CAAC,GAAGG,aAAa,CAACI,IAAd,GAAqB,CAAzB;AACA,GAFM,MAEA,IAAKP,CAAC,IAAIG,aAAa,CAACG,KAAxB,EAAgC;AACtCN,IAAAA,CAAC,GAAGG,aAAa,CAACG,KAAd,GAAsB,CAA1B;AACA;;AACD,QAAME,CAAC,GAAGN,YAAY,GAAGC,aAAa,CAACM,MAAd,GAAuB,CAA1B,GAA8BN,aAAa,CAACO,GAAd,GAAoB,CAAxE;AACA,SAAO,wCAA2BT,aAA3B,EAA0CD,CAA1C,EAA6CQ,CAA7C,EAAgDV,SAAhD,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASa,gBAAT,CAA2Bb,SAA3B,EAAsCC,S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B,EAA8B,aAA9B;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;AACA,wCAAiBD,SAAjB,EAA4B,WAA5B;AACAA,EAAAA,SAAS,CAACE,eAAV;AACAF,EAAAA,SAAS,CAACG,QAAV,CAAoBR,KAApB;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport isRTL from './is-rtl';\n\n/**\n * Gets the range to place.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n *\n * @return {Range|null} The range to place.\n */\nfunction getRange( container, isReverse, x ) {\n\tconst { ownerDocument } = container;\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\t// When placing at the end (isReverse), find the closest range to the bottom\n\t// right corner. When placing at the start, to the top left corner.\n\t// Ensure x is defined and within the container's boundaries. When it's\n\t// exactly at the boundary, it's not considered within the boundaries.\n\tif ( x === undefined ) {\n\t\tx = isReverse ? containerRect.right - 1 : containerRect.left + 1;\n\t} else if ( x <= containerRect.left ) {\n\t\tx = containerRect.left + 1;\n\t} else if ( x >= containerRect.right ) {\n\t\tx = containerRect.right - 1;\n\t}\n\tconst y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;\n\treturn hiddenCaretRangeFromPoint( ownerDocument, x, y, container );\n}\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n */\nexport default function placeCaretAtEdge( container, isReverse, x ) {\n\tif ( ! container ) {\n\t\treturn;\n\t}\n\n\tcontainer.focus();\n\n\tif ( isInputOrTextArea( container ) ) {\n\t\t// The element may not support selection setting.\n\t\tif ( typeof container.selectionStart !== 'number' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\tcontainer.selectionStart = container.value.length;\n\t\t\tcontainer.selectionEnd = container.value.length;\n\t\t} else {\n\t\t\tcontainer.selectionStart = 0;\n\t\t\tcontainer.selectionEnd = 0;\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn;\n\t}\n\n\tlet range = getRange( container, isReverse, x );\n\n\t// If no range range can be created or it is outside the container, the\n\t// element may be out of view.\n\tif (\n\t\t! range ||\n\t\t! range.startContainer ||\n\t\t! container.contains( range.startContainer )\n\t) {\n\t\tcontainer.scrollIntoView( isReverse );\n\t\trange = range = getRange( container, isReverse, x );\n\n\t\tif (\n\t\t\t! range ||\n\t\t\t! range.startContainer ||\n\t\t\t! container.contains( range.startContainer )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tselection.removeAllRanges();\n\tselection.addRange( range );\n}\n"]}
|
@@ -7,12 +7,6 @@ exports.getPhrasingContentSchema = getPhrasingContentSchema;
|
|
7
7
|
exports.isPhrasingContent = isPhrasingContent;
|
8
8
|
exports.isTextContent = isTextContent;
|
9
9
|
|
10
|
-
var _lodash = require("lodash");
|
11
|
-
|
12
|
-
/**
|
13
|
-
* External dependencies
|
14
|
-
*/
|
15
|
-
|
16
10
|
/**
|
17
11
|
* All phrasing content elements.
|
18
12
|
*
|
@@ -89,8 +83,13 @@ const textContentSchema = {
|
|
89
83
|
// Possible: strong > em > strong.
|
90
84
|
// Impossible: strong > strong.
|
91
85
|
|
92
|
-
|
93
|
-
|
86
|
+
const excludedElements = ['#text', 'br'];
|
87
|
+
Object.keys(textContentSchema).filter(element => !excludedElements.includes(element)).forEach(tag => {
|
88
|
+
const {
|
89
|
+
[tag]: removedTag,
|
90
|
+
...restSchema
|
91
|
+
} = textContentSchema;
|
92
|
+
textContentSchema[tag].children = restSchema;
|
94
93
|
});
|
95
94
|
/**
|
96
95
|
* Embedded content elements.
|
@@ -144,8 +143,28 @@ function getPhrasingContentSchema(context) {
|
|
144
143
|
if (context !== 'paste') {
|
145
144
|
return phrasingContentSchema;
|
146
145
|
}
|
147
|
-
|
148
|
-
|
146
|
+
/**
|
147
|
+
* @type {Partial<ContentSchema>}
|
148
|
+
*/
|
149
|
+
|
150
|
+
|
151
|
+
const {
|
152
|
+
u,
|
153
|
+
// Used to mark misspelling. Shouldn't be pasted.
|
154
|
+
abbr,
|
155
|
+
// Invisible.
|
156
|
+
data,
|
157
|
+
// Invisible.
|
158
|
+
time,
|
159
|
+
// Invisible.
|
160
|
+
wbr,
|
161
|
+
// Invisible.
|
162
|
+
bdi,
|
163
|
+
// Invisible.
|
164
|
+
bdo,
|
165
|
+
// Invisible.
|
166
|
+
...remainingContentSchema
|
167
|
+
} = { ...phrasingContentSchema,
|
149
168
|
// We shouldn't paste potentially sensitive information which is not
|
150
169
|
// visible to the user when pasted, so strip the attributes.
|
151
170
|
ins: {
|
@@ -154,14 +173,8 @@ function getPhrasingContentSchema(context) {
|
|
154
173
|
del: {
|
155
174
|
children: phrasingContentSchema.del.children
|
156
175
|
}
|
157
|
-
}
|
158
|
-
|
159
|
-
'data', // Invisible.
|
160
|
-
'time', // Invisible.
|
161
|
-
'wbr', // Invisible.
|
162
|
-
'bdi', // Invisible.
|
163
|
-
'bdo' // Invisible.
|
164
|
-
]);
|
176
|
+
};
|
177
|
+
return remainingContentSchema;
|
165
178
|
}
|
166
179
|
/**
|
167
180
|
* Find out whether or not the given node is phrasing content.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":";;;;;;;;;
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","excludedElements","Object","keys","filter","element","includes","forEach","tag","removedTag","restSchema","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","remainingContentSchema","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG;AACzBC,EAAAA,MAAM,EAAE,EADiB;AAEzBC,EAAAA,EAAE,EAAE,EAFqB;AAGzBC,EAAAA,CAAC,EAAE,EAHsB;AAIzBC,EAAAA,GAAG,EAAE,EAJoB;AAKzBC,EAAAA,GAAG,EAAE,EALoB;AAMzBC,EAAAA,CAAC,EAAE;AAAEC,IAAAA,UAAU,EAAE,CAAE,MAAF,EAAU,QAAV,EAAoB,KAApB,EAA2B,IAA3B;AAAd,GANsB;AAOzBC,EAAAA,IAAI,EAAE,EAPmB;AAQzBC,EAAAA,IAAI,EAAE;AAAEF,IAAAA,UAAU,EAAE,CAAE,OAAF;AAAd,GARmB;AASzBG,EAAAA,GAAG,EAAE,EAToB;AAUzBC,EAAAA,GAAG,EAAE,EAVoB;AAWzBC,EAAAA,EAAE,EAAE,EAXqB;AAYzBC,EAAAA,KAAK,EAAE,EAZkB;AAazB;AACA;AACAC,EAAAA,CAAC,EAA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AAED;AACD;AACA;;;AACC,QAAM;AACL1B,IAAAA,CADK;AACF;AACHd,IAAAA,IAFK;AAEC;AACNO,IAAAA,IAHK;AAGC;AACNC,IAAAA,IAJK;AAIC;AACNa,IAAAA,GALK;AAKA;AACLF,IAAAA,GANK;AAMA;AACLC,IAAAA,GAPK;AAOA;AACL,OAAGuB;AARE,MASF,EACH,GAAGH,qBADA;AAEH;AACA;AACA5C,IAAAA,GAAG,EAAE;AAAEoC,MAAAA,QAAQ,EAAEQ,qBAAqB,CAAC5C,GAAtB,CAA0BoC;AAAtC,KAJF;AAKHrC,IAAAA,GAAG,EAAE;AAAEqC,MAAAA,QAAQ,EAAEQ,qBAAqB,CAAC7C,GAAtB,CAA0BqC;AAAtC;AALF,GATJ;AAiBA,SAAOW,sBAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMhB,GAAG,GAAGgB,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAON,wBAAwB,GAAGO,cAA3B,CAA2CnB,GAA3C,KAAoDA,GAAG,KAAK,MAAnE;AACA;AAED;AACA;AACA;AACA;;;AACO,SAASoB,aAAT,CAAwBJ,IAAxB,EAA+B;AACrC,QAAMhB,GAAG,GAAGgB,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOxD,iBAAiB,CAACyD,cAAlB,CAAkCnB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', 'id' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nconst excludedElements = [ '#text', 'br' ];\nObject.keys( textContentSchema )\n\t.filter( ( element ) => ! excludedElements.includes( element ) )\n\t.forEach( ( tag ) => {\n\t\tconst { [ tag ]: removedTag, ...restSchema } = textContentSchema;\n\t\ttextContentSchema[ tag ].children = restSchema;\n\t} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\t/**\n\t * @type {Partial<ContentSchema>}\n\t */\n\tconst {\n\t\tu, // Used to mark misspelling. Shouldn't be pasted.\n\t\tabbr, // Invisible.\n\t\tdata, // Invisible.\n\t\ttime, // Invisible.\n\t\twbr, // Invisible.\n\t\tbdi, // Invisible.\n\t\tbdo, // Invisible.\n\t\t...remainingContentSchema\n\t} = {\n\t\t...phrasingContentSchema,\n\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t// visible to the user when pasted, so strip the attributes.\n\t\tins: { children: phrasingContentSchema.ins.children },\n\t\tdel: { children: phrasingContentSchema.del.children },\n\t};\n\n\treturn remainingContentSchema;\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"]}
|
package/build/tabbable.js
CHANGED
@@ -8,14 +8,8 @@ exports.findNext = findNext;
|
|
8
8
|
exports.findPrevious = findPrevious;
|
9
9
|
exports.isTabbableIndex = isTabbableIndex;
|
10
10
|
|
11
|
-
var _lodash = require("lodash");
|
12
|
-
|
13
11
|
var _focusable = require("./focusable");
|
14
12
|
|
15
|
-
/**
|
16
|
-
* External dependencies
|
17
|
-
*/
|
18
|
-
|
19
13
|
/**
|
20
14
|
* Internal dependencies
|
21
15
|
*/
|
@@ -92,7 +86,7 @@ function createStatefulCollapseRadioGroup() {
|
|
92
86
|
|
93
87
|
if (hasChosen) {
|
94
88
|
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
|
95
|
-
result =
|
89
|
+
result = result.filter(e => e !== hadChosenElement);
|
96
90
|
}
|
97
91
|
|
98
92
|
CHOSEN_RADIO_BY_NAME[name] = element;
|
@@ -194,13 +188,16 @@ function findPrevious(element) {
|
|
194
188
|
|
195
189
|
|
196
190
|
focusables.length = index;
|
197
|
-
|
191
|
+
const tabbable = filterTabbable(focusables);
|
192
|
+
return tabbable[tabbable.length - 1];
|
198
193
|
}
|
199
194
|
/**
|
200
195
|
* Given a focusable element, find the next tabbable element.
|
201
196
|
*
|
202
197
|
* @param {Element} element The focusable element after which to look. Defaults
|
203
198
|
* to the active element.
|
199
|
+
*
|
200
|
+
* @return {Element|undefined} Next tabbable element.
|
204
201
|
*/
|
205
202
|
|
206
203
|
|
@@ -209,6 +206,6 @@ function findNext(element) {
|
|
209
206
|
const index = focusables.indexOf(element); // Remove all focusables before and including `element`.
|
210
207
|
|
211
208
|
const remaining = focusables.slice(index + 1);
|
212
|
-
return
|
209
|
+
return filterTabbable(remaining)[0];
|
213
210
|
}
|
214
211
|
//# sourceMappingURL=tabbable.js.map
|
package/build/tabbable.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","filter","e","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","map","sort","reduce","find","context","findPrevious","ownerDocument","body","indexOf","undefined","length","tabbable","findNext","remaining","slice"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAsBC,OAAtB,EAAgC;AAC/B,QAAMC,QAAQ,GAAGD,OAAO,CAACE,YAAR,CAAsB,UAAtB,CAAjB;AACA,SAAOD,QAAQ,KAAK,IAAb,GAAoB,CAApB,GAAwBE,QAAQ,CAAEF,QAAF,EAAY,EAAZ,CAAvC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,eAAT,CAA0BJ,OAA1B,EAAoC;AAC1C,SAAOD,WAAW,CAAEC,OAAF,CAAX,KAA2B,CAAC,C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,GAAGb,cAAc,CAAEC,UAAF,CAA/B;AACA,SAAOY,QAAQ,CAAEA,QAAQ,CAACD,MAAT,GAAkB,CAApB,CAAf;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,QAAT,CAAmB3C,OAAnB,EAA6B;AACnC,QAAM8B,UAAU,GAAG,qBAAe9B,OAAO,CAACqC,aAAR,CAAsBC,IAArC,CAAnB;AACA,QAAMjB,KAAK,GAAGS,UAAU,CAACS,OAAX,CAAoBvC,OAApB,CAAd,CAFmC,CAInC;;AACA,QAAM4C,SAAS,GAAGd,UAAU,CAACe,KAAX,CAAkBxB,KAAK,GAAG,CAA1B,CAAlB;AAEA,SAAOQ,cAAc,CAAEe,SAAF,CAAd,CAA6B,CAA7B,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = result.filter( ( e ) => e !== hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {Element} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: Element, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: Element }} object Mapped object with element.\n *\n * @return {Element} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: Element, index: number }} a First object to compare.\n * @param {{ element: Element, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {Element[]} focusables Focusable elements to filter.\n *\n * @return {Element[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {Element[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n *\n * @return {Element|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\tif ( index === -1 ) {\n\t\treturn undefined;\n\t}\n\n\t// Remove all focusables after and including `element`.\n\tfocusables.length = index;\n\n\tconst tabbable = filterTabbable( focusables );\n\treturn tabbable[ tabbable.length - 1 ];\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n *\n * @return {Element|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables before and including `element`.\n\tconst remaining = focusables.slice( index + 1 );\n\n\treturn filterTabbable( remaining )[ 0 ];\n}\n"]}
|
@@ -1,11 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* External dependencies
|
3
|
-
*/
|
4
|
-
import { includes } from 'lodash';
|
5
1
|
/**
|
6
2
|
* Internal dependencies
|
7
3
|
*/
|
8
|
-
|
9
4
|
import isEmpty from './is-empty';
|
10
5
|
import remove from './remove';
|
11
6
|
import unwrap from './unwrap';
|
@@ -73,7 +68,7 @@ export default function cleanNodeList(nodeList, doc, schema, inline) {
|
|
73
68
|
name
|
74
69
|
} = _ref;
|
75
70
|
|
76
|
-
if (name !== 'class' && !includes(
|
71
|
+
if (name !== 'class' && !attributes.includes(name)) {
|
77
72
|
node.removeAttribute(name);
|
78
73
|
}
|
79
74
|
}); // Strip invalid classes.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"names":["includes","isEmpty","remove","unwrap","isPhrasingContent","insertAfter","isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","attributes","classes","children","require","allowEmpty","hasAttributes","name","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","parentNode","child","firstChild","nextElementSibling","createElement"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,QAAzB;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,YAApB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,SAASC,iBAAT,QAAkC,qBAAlC;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,OAAOC,SAAP,MAAsB,cAAtB;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,aAAT,CAAwBC,QAAxB,EAAkCC,GAAlC,EAAuCC,MAAvC,EAA+CC,MAA/C,EAAwD;AACtEC,E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zB,QAAhB,KAA6B,MAD7B,IAEAd,iBAAiB,CAAEY,IAAF,CAHX,EAIL;AACDR,cAAAA,aAAa,CACZQ,IAAI,CAAC0B,UADO,EAEZhC,GAFY,EAGZC,MAHY,EAIZC,MAJY,CAAb;;AAOA,kBACCC,KAAK,CAACC,IAAN,CAAYE,IAAI,CAAC0B,UAAjB,EAA8BJ,IAA9B,CACGM,KAAF,IACC,CAAExC,iBAAiB,CAAEwC,KAAF,CAFrB,CADD,EAKE;AACDzC,gBAAAA,MAAM,CAAEa,IAAF,CAAN;AACA;AACD,aApBM,MAoBA;AACNR,cAAAA,aAAa,CACZQ,IAAI,CAAC0B,UADO,EAEZhC,GAFY,EAGZc,QAHY,EAIZZ,MAJY,CAAb;AAMA,aA5Cc,CA6Cf;;AACA,WA9CD,MA8CO;AACN,mBAAQI,IAAI,CAAC6B,UAAb,EAA0B;AACzB3C,cAAAA,MAAM,CAAEc,IAAI,CAAC6B,UAAP,CAAN;AACA;AACD;AACD;AACD,OAzHA,CA0HD;;AACA,KA9HD,MA8HO;AACNrC,MAAAA,aAAa,CAAEQ,IAAI,CAAC0B,UAAP,EAAmBhC,GAAnB,EAAwBC,MAAxB,EAAgCC,MAAhC,CAAb,CADM,CAGN;AACA;;AACA,UACCA,MAAM,IACN,CAAER,iBAAiB,CAAEY,IAAF,CADnB,IAEAA,IAAI,CAAC8B,kBAHN,EAIE;AACDzC,QAAAA,WAAW,CAAEK,GAAG,CAACqC,aAAJ,CAAmB,IAAnB,CAAF,EAA6B/B,IAA7B,CAAX;AACA;;AAEDb,MAAAA,MAAM,CAAEa,IAAF,CAAN;AACA;AACD,GAnJF;AAqJA","sourcesContent":["/**\n * External dependencies\n */\nimport { includes } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! includes( attributes, 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 ( 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"]}
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/clean-node-list.js"],"names":["isEmpty","remove","unwrap","isPhrasingContent","insertAfter","isElement","noop","cleanNodeList","nodeList","doc","schema","inline","Array","from","forEach","node","tag","nodeName","toLowerCase","hasOwnProperty","isMatch","attributes","classes","children","require","allowEmpty","hasAttributes","name","includes","removeAttribute","classList","length","mattchers","map","item","className","RegExp","test","some","hasChildNodes","querySelector","join","childNodes","parentNode","child","firstChild","nextElementSibling","createElement"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,YAApB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OA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B,kBAHN,EAIE;AACD1C,QAAAA,WAAW,CAAEK,GAAG,CAACsC,aAAJ,CAAmB,IAAnB,CAAF,EAA6BhC,IAA7B,CAAX;AACA;;AAEDb,MAAAA,MAAM,CAAEa,IAAF,CAAN;AACA;AACD,GAnJF;AAqJA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isEmpty from './is-empty';\nimport remove from './remove';\nimport unwrap from './unwrap';\nimport { isPhrasingContent } from '../phrasing-content';\nimport insertAfter from './insert-after';\nimport isElement from './is-element';\n\nconst noop = () => {};\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @typedef SchemaItem\n * @property {string[]} [attributes] Attributes.\n * @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.\n * @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.\n * @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.\n * @property {boolean} allowEmpty Whether to allow nodes without children.\n * @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.\n */\n\n/** @typedef {{ [tag: string]: SchemaItem }} Schema */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on a node\n * list.\n *\n * @param {NodeList} nodeList The nodeList to filter.\n * @param {Document} doc The document of the nodeList.\n * @param {Schema} schema An array of functions that can mutate with the provided node.\n * @param {boolean} inline Whether to clean for inline mode.\n */\nexport default function cleanNodeList( nodeList, doc, schema, inline ) {\n\tArray.from( nodeList ).forEach(\n\t\t( /** @type {Node & { nextElementSibling?: unknown }} */ node ) => {\n\t\t\tconst tag = node.nodeName.toLowerCase();\n\n\t\t\t// It's a valid child, if the tag exists in the schema without an isMatch\n\t\t\t// function, or with an isMatch function that matches the node.\n\t\t\tif (\n\t\t\t\tschema.hasOwnProperty( tag ) &&\n\t\t\t\t( ! schema[ tag ].isMatch || schema[ tag ].isMatch?.( node ) )\n\t\t\t) {\n\t\t\t\tif ( isElement( node ) ) {\n\t\t\t\t\tconst {\n\t\t\t\t\t\tattributes = [],\n\t\t\t\t\t\tclasses = [],\n\t\t\t\t\t\tchildren,\n\t\t\t\t\t\trequire = [],\n\t\t\t\t\t\tallowEmpty,\n\t\t\t\t\t} = schema[ tag ];\n\n\t\t\t\t\t// If the node is empty and it's supposed to have children,\n\t\t\t\t\t// remove the node.\n\t\t\t\t\tif ( children && ! allowEmpty && isEmpty( node ) ) {\n\t\t\t\t\t\tremove( node );\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( node.hasAttributes() ) {\n\t\t\t\t\t\t// Strip invalid attributes.\n\t\t\t\t\t\tArray.from( node.attributes ).forEach( ( { name } ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tname !== 'class' &&\n\t\t\t\t\t\t\t\t! attributes.includes( name )\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tnode.removeAttribute( name );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Strip invalid classes.\n\t\t\t\t\t\t// In jsdom-jscore, 'node.classList' can be undefined.\n\t\t\t\t\t\t// TODO: Explore patching this in jsdom-jscore.\n\t\t\t\t\t\tif ( node.classList && node.classList.length ) {\n\t\t\t\t\t\t\tconst mattchers = classes.map( ( item ) => {\n\t\t\t\t\t\t\t\tif ( 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"]}
|
@@ -3,11 +3,12 @@
|
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
5
|
/**
|
6
|
-
* Get the rectangle of a given Range.
|
6
|
+
* Get the rectangle of a given Range. Returns `null` if no suitable rectangle
|
7
|
+
* can be found.
|
7
8
|
*
|
8
9
|
* @param {Range} range The range.
|
9
10
|
*
|
10
|
-
* @return {DOMRect} The rectangle.
|
11
|
+
* @return {DOMRect?} The rectangle.
|
11
12
|
*/
|
12
13
|
|
13
14
|
export default function getRectangleFromRange(range) {
|
@@ -80,7 +81,14 @@ export default function getRectangleFromRange(range) {
|
|
80
81
|
range.setEnd(parentNode, index);
|
81
82
|
}
|
82
83
|
|
83
|
-
|
84
|
+
const rects = range.getClientRects(); // If we have multiple rectangles for a collapsed range, there's no way to
|
85
|
+
// know which it is, so don't return anything.
|
86
|
+
|
87
|
+
if (rects.length > 1) {
|
88
|
+
return null;
|
89
|
+
}
|
90
|
+
|
91
|
+
let rect = rects[0]; // If the collapsed range starts (and therefore ends) at an element node,
|
84
92
|
// `getClientRects` can be empty in some browsers. This can be resolved
|
85
93
|
// by adding a temporary text node with zero-width space to the range.
|
86
94
|
//
|