@wordpress/dom 3.38.0 → 3.40.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 +4 -0
- package/README.md +2 -2
- package/build/data-transfer.js +0 -2
- package/build/data-transfer.js.map +1 -1
- package/build/dom/caret-range-from-point.js +3 -5
- package/build/dom/caret-range-from-point.js.map +1 -1
- package/build/dom/clean-node-list.js +25 -42
- package/build/dom/clean-node-list.js.map +1 -1
- package/build/dom/compute-caret-rect.js +0 -6
- package/build/dom/compute-caret-rect.js.map +1 -1
- package/build/dom/document-has-selection.js +0 -5
- package/build/dom/document-has-selection.js.map +1 -1
- package/build/dom/document-has-text-selection.js +0 -2
- package/build/dom/document-has-text-selection.js.map +1 -1
- package/build/dom/document-has-uncollapsed-selection.js +0 -4
- package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build/dom/get-computed-style.js +0 -3
- package/build/dom/get-computed-style.js.map +1 -1
- package/build/dom/get-offset-parent.js +8 -19
- package/build/dom/get-offset-parent.js.map +1 -1
- package/build/dom/get-range-height.js +0 -3
- package/build/dom/get-range-height.js.map +1 -1
- package/build/dom/get-rectangle-from-range.js +15 -22
- package/build/dom/get-rectangle-from-range.js.map +1 -1
- package/build/dom/get-scroll-container.js +3 -13
- package/build/dom/get-scroll-container.js.map +1 -1
- package/build/dom/hidden-caret-range-from-point.js +2 -6
- package/build/dom/hidden-caret-range-from-point.js.map +1 -1
- package/build/dom/index.js +0 -27
- package/build/dom/index.js.map +1 -1
- package/build/dom/input-field-has-uncollapsed-selection.js +8 -12
- package/build/dom/input-field-has-uncollapsed-selection.js.map +1 -1
- package/build/dom/insert-after.js +0 -2
- package/build/dom/insert-after.js.map +1 -1
- package/build/dom/is-edge.js +18 -40
- package/build/dom/is-edge.js.map +1 -1
- package/build/dom/is-element.js +0 -2
- package/build/dom/is-element.js.map +1 -1
- package/build/dom/is-empty.js +1 -7
- package/build/dom/is-empty.js.map +1 -1
- package/build/dom/is-entirely-selected.js +2 -18
- package/build/dom/is-entirely-selected.js.map +1 -1
- package/build/dom/is-form-element.js +0 -4
- package/build/dom/is-form-element.js.map +1 -1
- package/build/dom/is-horizontal-edge.js +2 -5
- package/build/dom/is-horizontal-edge.js.map +1 -1
- package/build/dom/is-html-input-element.js +0 -2
- package/build/dom/is-html-input-element.js.map +1 -1
- package/build/dom/is-input-or-text-area.js +0 -2
- package/build/dom/is-input-or-text-area.js.map +1 -1
- package/build/dom/is-number-input.js +0 -6
- package/build/dom/is-number-input.js.map +1 -1
- package/build/dom/is-rtl.js +0 -3
- package/build/dom/is-rtl.js.map +1 -1
- package/build/dom/is-selection-forward.js +6 -10
- package/build/dom/is-selection-forward.js.map +1 -1
- package/build/dom/is-text-field.js +1 -7
- package/build/dom/is-text-field.js.map +1 -1
- package/build/dom/is-vertical-edge.js +2 -5
- package/build/dom/is-vertical-edge.js.map +1 -1
- package/build/dom/place-caret-at-edge.js +8 -31
- package/build/dom/place-caret-at-edge.js.map +1 -1
- package/build/dom/place-caret-at-horizontal-edge.js +0 -3
- package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build/dom/place-caret-at-vertical-edge.js +0 -3
- package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build/dom/remove-invalid-html.js +0 -3
- package/build/dom/remove-invalid-html.js.map +1 -1
- package/build/dom/remove.js +0 -2
- package/build/dom/remove.js.map +1 -1
- package/build/dom/replace-tag.js +0 -4
- package/build/dom/replace-tag.js.map +1 -1
- package/build/dom/replace.js +0 -5
- package/build/dom/replace.js.map +1 -1
- package/build/dom/safe-html.js +0 -8
- package/build/dom/safe-html.js.map +1 -1
- package/build/dom/scroll-if-no-range.js +31 -0
- package/build/dom/scroll-if-no-range.js.map +1 -0
- package/build/dom/strip-html.js +0 -3
- package/build/dom/strip-html.js.map +1 -1
- package/build/dom/unwrap.js +0 -4
- package/build/dom/unwrap.js.map +1 -1
- package/build/dom/wrap.js +0 -2
- package/build/dom/wrap.js.map +1 -1
- package/build/focusable.js +5 -18
- package/build/focusable.js.map +1 -1
- package/build/index.js +0 -11
- package/build/index.js.map +1 -1
- package/build/phrasing-content.js +13 -14
- package/build/phrasing-content.js.map +1 -1
- package/build/tabbable.js +21 -37
- package/build/tabbable.js.map +1 -1
- package/build/utils/assert-is-defined.js +0 -1
- package/build/utils/assert-is-defined.js.map +1 -1
- package/build-module/data-transfer.js +0 -1
- package/build-module/data-transfer.js.map +1 -1
- package/build-module/dom/caret-range-from-point.js +3 -4
- package/build-module/dom/caret-range-from-point.js.map +1 -1
- package/build-module/dom/clean-node-list.js +24 -35
- package/build-module/dom/clean-node-list.js.map +1 -1
- package/build-module/dom/compute-caret-rect.js +1 -3
- package/build-module/dom/compute-caret-rect.js.map +1 -1
- package/build-module/dom/document-has-selection.js +1 -1
- package/build-module/dom/document-has-selection.js.map +1 -1
- package/build-module/dom/document-has-text-selection.js +1 -1
- package/build-module/dom/document-has-text-selection.js.map +1 -1
- package/build-module/dom/document-has-uncollapsed-selection.js +1 -1
- package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build-module/dom/get-computed-style.js +1 -2
- package/build-module/dom/get-computed-style.js.map +1 -1
- package/build-module/dom/get-offset-parent.js +9 -17
- package/build-module/dom/get-offset-parent.js.map +1 -1
- package/build-module/dom/get-range-height.js +0 -2
- package/build-module/dom/get-range-height.js.map +1 -1
- package/build-module/dom/get-rectangle-from-range.js +16 -21
- package/build-module/dom/get-rectangle-from-range.js.map +1 -1
- package/build-module/dom/get-scroll-container.js +4 -11
- package/build-module/dom/get-scroll-container.js.map +1 -1
- package/build-module/dom/hidden-caret-range-from-point.js +3 -3
- package/build-module/dom/hidden-caret-range-from-point.js.map +1 -1
- package/build-module/dom/index.js.map +1 -1
- package/build-module/dom/input-field-has-uncollapsed-selection.js +9 -9
- package/build-module/dom/input-field-has-uncollapsed-selection.js.map +1 -1
- package/build-module/dom/insert-after.js +1 -1
- package/build-module/dom/insert-after.js.map +1 -1
- package/build-module/dom/is-edge.js +19 -32
- package/build-module/dom/is-edge.js.map +1 -1
- package/build-module/dom/is-element.js +0 -1
- package/build-module/dom/is-element.js.map +1 -1
- package/build-module/dom/is-empty.js +1 -6
- package/build-module/dom/is-empty.js.map +1 -1
- package/build-module/dom/is-entirely-selected.js +3 -14
- package/build-module/dom/is-entirely-selected.js.map +1 -1
- package/build-module/dom/is-form-element.js +1 -2
- package/build-module/dom/is-form-element.js.map +1 -1
- package/build-module/dom/is-horizontal-edge.js +3 -3
- package/build-module/dom/is-horizontal-edge.js.map +1 -1
- package/build-module/dom/is-html-input-element.js +0 -1
- package/build-module/dom/is-html-input-element.js.map +1 -1
- package/build-module/dom/is-input-or-text-area.js +0 -1
- package/build-module/dom/is-input-or-text-area.js.map +1 -1
- package/build-module/dom/is-number-input.js +2 -4
- package/build-module/dom/is-number-input.js.map +1 -1
- package/build-module/dom/is-rtl.js +1 -1
- package/build-module/dom/is-rtl.js.map +1 -1
- package/build-module/dom/is-selection-forward.js +7 -9
- package/build-module/dom/is-selection-forward.js.map +1 -1
- package/build-module/dom/is-text-field.js +2 -5
- package/build-module/dom/is-text-field.js.map +1 -1
- package/build-module/dom/is-vertical-edge.js +3 -3
- package/build-module/dom/is-vertical-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-edge.js +9 -26
- package/build-module/dom/place-caret-at-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-horizontal-edge.js +1 -1
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build-module/dom/remove-invalid-html.js +1 -1
- package/build-module/dom/remove-invalid-html.js.map +1 -1
- package/build-module/dom/remove.js +1 -1
- package/build-module/dom/remove.js.map +1 -1
- package/build-module/dom/replace-tag.js +1 -3
- package/build-module/dom/replace-tag.js.map +1 -1
- package/build-module/dom/replace.js +1 -1
- package/build-module/dom/replace.js.map +1 -1
- package/build-module/dom/safe-html.js +1 -6
- package/build-module/dom/safe-html.js.map +1 -1
- package/build-module/dom/scroll-if-no-range.js +25 -0
- package/build-module/dom/scroll-if-no-range.js.map +1 -0
- package/build-module/dom/strip-html.js +1 -1
- package/build-module/dom/strip-html.js.map +1 -1
- package/build-module/dom/unwrap.js +1 -3
- package/build-module/dom/unwrap.js.map +1 -1
- package/build-module/dom/wrap.js +1 -1
- package/build-module/dom/wrap.js.map +1 -1
- package/build-module/focusable.js +5 -17
- package/build-module/focusable.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/phrasing-content.js +13 -11
- package/build-module/phrasing-content.js.map +1 -1
- package/build-module/tabbable.js +22 -33
- package/build-module/tabbable.js.map +1 -1
- package/build-module/utils/assert-is-defined.js.map +1 -1
- package/build-types/dom/is-edge.d.ts +4 -4
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/is-horizontal-edge.d.ts +3 -3
- package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/is-vertical-edge.d.ts +3 -3
- package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
- package/build-types/dom/scroll-if-no-range.d.ts +12 -0
- package/build-types/dom/scroll-if-no-range.d.ts.map +1 -0
- package/build-types/index.d.ts +2 -2
- package/build-types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/dom/is-edge.js +6 -8
- package/src/dom/is-horizontal-edge.js +2 -2
- package/src/dom/is-vertical-edge.js +2 -2
- package/src/dom/place-caret-at-edge.js +5 -19
- package/src/dom/scroll-if-no-range.js +34 -0
- package/tsconfig.tsbuildinfo +1 -1
@@ -70,10 +70,11 @@ const textContentSchema = {
|
|
70
70
|
},
|
71
71
|
wbr: {},
|
72
72
|
'#text': {}
|
73
|
-
};
|
73
|
+
};
|
74
|
+
|
75
|
+
// Recursion is needed.
|
74
76
|
// Possible: strong > em > strong.
|
75
77
|
// Impossible: strong > strong.
|
76
|
-
|
77
78
|
const excludedElements = ['#text', 'br'];
|
78
79
|
Object.keys(textContentSchema).filter(element => !excludedElements.includes(element)).forEach(tag => {
|
79
80
|
const {
|
@@ -82,6 +83,7 @@ Object.keys(textContentSchema).filter(element => !excludedElements.includes(elem
|
|
82
83
|
} = textContentSchema;
|
83
84
|
textContentSchema[tag].children = restSchema;
|
84
85
|
});
|
86
|
+
|
85
87
|
/**
|
86
88
|
* Embedded content elements.
|
87
89
|
*
|
@@ -89,7 +91,6 @@ Object.keys(textContentSchema).filter(element => !excludedElements.includes(elem
|
|
89
91
|
*
|
90
92
|
* @type {ContentSchema}
|
91
93
|
*/
|
92
|
-
|
93
94
|
const embeddedContentSchema = {
|
94
95
|
audio: {
|
95
96
|
attributes: ['src', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted']
|
@@ -110,15 +111,17 @@ const embeddedContentSchema = {
|
|
110
111
|
attributes: ['src', 'poster', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted', 'controls', 'width', 'height']
|
111
112
|
}
|
112
113
|
};
|
114
|
+
|
113
115
|
/**
|
114
116
|
* Phrasing content elements.
|
115
117
|
*
|
116
118
|
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
|
117
119
|
*/
|
118
|
-
|
119
|
-
|
120
|
+
const phrasingContentSchema = {
|
121
|
+
...textContentSchema,
|
120
122
|
...embeddedContentSchema
|
121
123
|
};
|
124
|
+
|
122
125
|
/**
|
123
126
|
* Get schema of possible paths for phrasing content.
|
124
127
|
*
|
@@ -129,16 +132,14 @@ const phrasingContentSchema = { ...textContentSchema,
|
|
129
132
|
*
|
130
133
|
* @return {Partial<ContentSchema>} Schema.
|
131
134
|
*/
|
132
|
-
|
133
135
|
export function getPhrasingContentSchema(context) {
|
134
136
|
if (context !== 'paste') {
|
135
137
|
return phrasingContentSchema;
|
136
138
|
}
|
139
|
+
|
137
140
|
/**
|
138
141
|
* @type {Partial<ContentSchema>}
|
139
142
|
*/
|
140
|
-
|
141
|
-
|
142
143
|
const {
|
143
144
|
u,
|
144
145
|
// Used to mark misspelling. Shouldn't be pasted.
|
@@ -155,7 +156,8 @@ export function getPhrasingContentSchema(context) {
|
|
155
156
|
bdo,
|
156
157
|
// Invisible.
|
157
158
|
...remainingContentSchema
|
158
|
-
} = {
|
159
|
+
} = {
|
160
|
+
...phrasingContentSchema,
|
159
161
|
// We shouldn't paste potentially sensitive information which is not
|
160
162
|
// visible to the user when pasted, so strip the attributes.
|
161
163
|
ins: {
|
@@ -167,6 +169,7 @@ export function getPhrasingContentSchema(context) {
|
|
167
169
|
};
|
168
170
|
return remainingContentSchema;
|
169
171
|
}
|
172
|
+
|
170
173
|
/**
|
171
174
|
* Find out whether or not the given node is phrasing content.
|
172
175
|
*
|
@@ -176,16 +179,15 @@ export function getPhrasingContentSchema(context) {
|
|
176
179
|
*
|
177
180
|
* @return {boolean} True if phrasing content, false if not.
|
178
181
|
*/
|
179
|
-
|
180
182
|
export function isPhrasingContent(node) {
|
181
183
|
const tag = node.nodeName.toLowerCase();
|
182
184
|
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === 'span';
|
183
185
|
}
|
186
|
+
|
184
187
|
/**
|
185
188
|
* @param {Node} node
|
186
189
|
* @return {boolean} Node is text content
|
187
190
|
*/
|
188
|
-
|
189
191
|
export function isTextContent(node) {
|
190
192
|
const tag = node.nodeName.toLowerCase();
|
191
193
|
return textContentSchema.hasOwnProperty(tag) || tag === 'span';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"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"],"sources":["@wordpress/dom/src/phrasing-content.js"],"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"],"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;EACzBC,MAAM,EAAE,CAAC,CAAC;EACVC,EAAE,EAAE,CAAC,CAAC;EACNC,CAAC,EAAE,CAAC,CAAC;EACLC,GAAG,EAAE,CAAC,CAAC;EACPC,GAAG,EAAE,CAAC,CAAC;EACPC,CAAC,EAAE;IAAEC,UAAU,EAAE,CAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI;EAAG,CAAC;EACpDC,IAAI,EAAE,CAAC,CAAC;EACRC,IAAI,EAAE;IAAEF,UAAU,EAAE,CAAE,OAAO;EAAG,CAAC;EACjCG,GAAG,EAAE,CAAC,CAAC;EACPC,GAAG,EAAE,CAAC,CAAC;EACPC,EAAE,EAAE,CAAC,CAAC;EACNC,KAAK,EAAE,CAAC,CAAC;EACT;EACA;EACAC,CAAC,EAAE;IAAEP,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C,GAAG,CAACoC;IAAS,CAAC;IACrDrC,GAAG,EAAE;MAAEqC,QAAQ,EAAEQ,qBAAqB,CAAC7C,GAAG,CAACqC;IAAS;EACrD,CAAC;EAED,OAAOW,sBAAsB;AAC9B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAAEC,IAAI,EAAG;EACzC,MAAMhB,GAAG,GAAGgB,IAAI,CAACC,QAAQ,CAACC,WAAW,CAAC,CAAC;EACvC,OAAON,wBAAwB,CAAC,CAAC,CAACO,cAAc,CAAEnB,GAAI,CAAC,IAAIA,GAAG,KAAK,MAAM;AAC1E;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASoB,aAAaA,CAAEJ,IAAI,EAAG;EACrC,MAAMhB,GAAG,GAAGgB,IAAI,CAACC,QAAQ,CAACC,WAAW,CAAC,CAAC;EACvC,OAAOxD,iBAAiB,CAACyD,cAAc,CAAEnB,GAAI,CAAC,IAAIA,GAAG,KAAK,MAAM;AACjE"}
|
package/build-module/tabbable.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { find as findFocusable } from './focusable';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Returns the tab index of the given element. In contrast with the tabIndex
|
7
8
|
* property, this normalizes the default (0) to avoid browser inconsistencies,
|
@@ -14,11 +15,11 @@ import { find as findFocusable } from './focusable';
|
|
14
15
|
*
|
15
16
|
* @return {number} Tab index of element (default 0).
|
16
17
|
*/
|
17
|
-
|
18
18
|
function getTabIndex(element) {
|
19
19
|
const tabIndex = element.getAttribute('tabindex');
|
20
20
|
return tabIndex === null ? 0 : parseInt(tabIndex, 10);
|
21
21
|
}
|
22
|
+
|
22
23
|
/**
|
23
24
|
* Returns true if the specified element is tabbable, or false otherwise.
|
24
25
|
*
|
@@ -26,11 +27,10 @@ function getTabIndex(element) {
|
|
26
27
|
*
|
27
28
|
* @return {boolean} Whether element is tabbable.
|
28
29
|
*/
|
29
|
-
|
30
|
-
|
31
30
|
export function isTabbableIndex(element) {
|
32
31
|
return getTabIndex(element) !== -1;
|
33
32
|
}
|
33
|
+
|
34
34
|
/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */
|
35
35
|
|
36
36
|
/**
|
@@ -41,46 +41,41 @@ export function isTabbableIndex(element) {
|
|
41
41
|
*
|
42
42
|
* @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.
|
43
43
|
*/
|
44
|
-
|
45
44
|
function createStatefulCollapseRadioGroup() {
|
46
45
|
/** @type {Record<string, MaybeHTMLInputElement>} */
|
47
46
|
const CHOSEN_RADIO_BY_NAME = {};
|
48
|
-
return function collapseRadioGroup(
|
49
|
-
/** @type {MaybeHTMLInputElement[]} */
|
50
|
-
result,
|
51
|
-
/** @type {MaybeHTMLInputElement} */
|
52
|
-
element) {
|
47
|
+
return function collapseRadioGroup( /** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
|
53
48
|
const {
|
54
49
|
nodeName,
|
55
50
|
type,
|
56
51
|
checked,
|
57
52
|
name
|
58
|
-
} = element;
|
53
|
+
} = element;
|
59
54
|
|
55
|
+
// For all non-radio tabbables, construct to array by concatenating.
|
60
56
|
if (nodeName !== 'INPUT' || type !== 'radio' || !name) {
|
61
57
|
return result.concat(element);
|
62
58
|
}
|
59
|
+
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
|
63
60
|
|
64
|
-
|
65
|
-
|
61
|
+
// Omit by skipping concatenation if the radio element is not chosen.
|
66
62
|
const isChosen = checked || !hasChosen;
|
67
|
-
|
68
63
|
if (!isChosen) {
|
69
64
|
return result;
|
70
|
-
}
|
65
|
+
}
|
66
|
+
|
67
|
+
// At this point, if there had been a chosen element, the current
|
71
68
|
// element is checked and should take priority. Retroactively remove
|
72
69
|
// the element which had previously been considered the chosen one.
|
73
|
-
|
74
|
-
|
75
70
|
if (hasChosen) {
|
76
71
|
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
|
77
72
|
result = result.filter(e => e !== hadChosenElement);
|
78
73
|
}
|
79
|
-
|
80
74
|
CHOSEN_RADIO_BY_NAME[name] = element;
|
81
75
|
return result.concat(element);
|
82
76
|
};
|
83
77
|
}
|
78
|
+
|
84
79
|
/**
|
85
80
|
* An array map callback, returning an object with the element value and its
|
86
81
|
* array index location as properties. This is used to emulate a proper stable
|
@@ -92,14 +87,13 @@ function createStatefulCollapseRadioGroup() {
|
|
92
87
|
*
|
93
88
|
* @return {{ element: Element, index: number }} Mapped object with element, index.
|
94
89
|
*/
|
95
|
-
|
96
|
-
|
97
90
|
function mapElementToObjectTabbable(element, index) {
|
98
91
|
return {
|
99
92
|
element,
|
100
93
|
index
|
101
94
|
};
|
102
95
|
}
|
96
|
+
|
103
97
|
/**
|
104
98
|
* An array map callback, returning an element of the given mapped object's
|
105
99
|
* element value.
|
@@ -108,11 +102,10 @@ function mapElementToObjectTabbable(element, index) {
|
|
108
102
|
*
|
109
103
|
* @return {Element} Mapped object element.
|
110
104
|
*/
|
111
|
-
|
112
|
-
|
113
105
|
function mapObjectTabbableToElement(object) {
|
114
106
|
return object.element;
|
115
107
|
}
|
108
|
+
|
116
109
|
/**
|
117
110
|
* A sort comparator function used in comparing two objects of mapped elements.
|
118
111
|
*
|
@@ -123,18 +116,15 @@ function mapObjectTabbableToElement(object) {
|
|
123
116
|
*
|
124
117
|
* @return {number} Comparator result.
|
125
118
|
*/
|
126
|
-
|
127
|
-
|
128
119
|
function compareObjectTabbables(a, b) {
|
129
120
|
const aTabIndex = getTabIndex(a.element);
|
130
121
|
const bTabIndex = getTabIndex(b.element);
|
131
|
-
|
132
122
|
if (aTabIndex === bTabIndex) {
|
133
123
|
return a.index - b.index;
|
134
124
|
}
|
135
|
-
|
136
125
|
return aTabIndex - bTabIndex;
|
137
126
|
}
|
127
|
+
|
138
128
|
/**
|
139
129
|
* Givin focusable elements, filters out tabbable element.
|
140
130
|
*
|
@@ -142,20 +132,18 @@ function compareObjectTabbables(a, b) {
|
|
142
132
|
*
|
143
133
|
* @return {Element[]} Tabbable elements.
|
144
134
|
*/
|
145
|
-
|
146
|
-
|
147
135
|
function filterTabbable(focusables) {
|
148
136
|
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
|
149
137
|
}
|
138
|
+
|
150
139
|
/**
|
151
140
|
* @param {Element} context
|
152
141
|
* @return {Element[]} Tabbable elements within the context.
|
153
142
|
*/
|
154
|
-
|
155
|
-
|
156
143
|
export function find(context) {
|
157
144
|
return filterTabbable(findFocusable(context));
|
158
145
|
}
|
146
|
+
|
159
147
|
/**
|
160
148
|
* Given a focusable element, find the preceding tabbable element.
|
161
149
|
*
|
@@ -164,14 +152,15 @@ export function find(context) {
|
|
164
152
|
*
|
165
153
|
* @return {Element|undefined} Preceding tabbable element.
|
166
154
|
*/
|
167
|
-
|
168
155
|
export function findPrevious(element) {
|
169
156
|
return filterTabbable(findFocusable(element.ownerDocument.body)).reverse().find(focusable => {
|
170
|
-
return (
|
157
|
+
return (
|
158
|
+
// eslint-disable-next-line no-bitwise
|
171
159
|
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
|
172
160
|
);
|
173
161
|
});
|
174
162
|
}
|
163
|
+
|
175
164
|
/**
|
176
165
|
* Given a focusable element, find the next tabbable element.
|
177
166
|
*
|
@@ -180,10 +169,10 @@ export function findPrevious(element) {
|
|
180
169
|
*
|
181
170
|
* @return {Element|undefined} Next tabbable element.
|
182
171
|
*/
|
183
|
-
|
184
172
|
export function findNext(element) {
|
185
173
|
return filterTabbable(findFocusable(element.ownerDocument.body)).find(focusable => {
|
186
|
-
return (
|
174
|
+
return (
|
175
|
+
// eslint-disable-next-line no-bitwise
|
187
176
|
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
|
188
177
|
);
|
189
178
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["find","findFocusable","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","context","findPrevious","ownerDocument","body","reverse","focusable","compareDocumentPosition","DOCUMENT_POSITION_PRECEDING","findNext","DOCUMENT_POSITION_FOLLOWING"],"sources":["@wordpress/dom/src/tabbable.js"],"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\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find( ( focusable ) => {\n\t\t\treturn (\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t\t);\n\t\t} );\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\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) => {\n\t\t\treturn (\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t\t\t);\n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AAO,EAAG;EAC/B,OAAOL,cAAc,CAAE/B,aAAa,CAAEoC,OAAQ,CAAE,CAAC;AAClD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAAEnC,OAAO,EAAG;EACvC,OAAO6B,cAAc,CAAE/B,aAAa,CAAEE,OAAO,CAACoC,aAAa,CAACC,IAAK,CAAE,CAAC,CAClEC,OAAO,CAAC,CAAC,CACTzC,IAAI,CAAI0C,SAAS,IAAM;IACvB;MACC;MACAvC,OAAO,CAACwC,uBAAuB,CAAED,SAAU,CAAC,GAC5CvC,OAAO,CAACyC;IAA2B;EAErC,CAAE,CAAC;AACL;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAAE1C,OAAO,EAAG;EACnC,OAAO6B,cAAc,CAAE/B,aAAa,CAAEE,OAAO,CAACoC,aAAa,CAACC,IAAK,CAAE,CAAC,CAACxC,IAAI,CACtE0C,SAAS,IAAM;IAChB;MACC;MACAvC,OAAO,CAACwC,uBAAuB,CAAED,SAAU,CAAC,GAC5CvC,OAAO,CAAC2C;IAA2B;EAErC,CACD,CAAC;AACF"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","val","name","process","env","NODE_ENV","undefined","Error"],"sources":["@wordpress/dom/src/utils/assert-is-defined.ts"],"sourcesContent":["export function assertIsDefined< T >(\n\tval: T,\n\tname: string\n): asserts val is NonNullable< T > {\n\tif (\n\t\tprocess.env.NODE_ENV !== 'production' &&\n\t\t( val === undefined || val === null )\n\t) {\n\t\tthrow new Error(\n\t\t\t`Expected '${ name }' to be defined, but received ${ val }`\n\t\t);\n\t}\n}\n"],"mappings":"AAAA,OAAO,SAASA,eAAeA,CAC9BC,GAAM,EACNC,IAAY,EACsB;EAClC,IACCC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,KACnCJ,GAAG,KAAKK,SAAS,IAAIL,GAAG,KAAK,IAAI,CAAE,EACpC;IACD,MAAM,IAAIM,KAAK,CACb,aAAaL,IAAM,iCAAiCD,GAAK,EAC3D,CAAC;EACF;AACD"}
|
@@ -3,11 +3,11 @@
|
|
3
3
|
* horizontal position by default. Set `onlyVertical` to true to check only
|
4
4
|
* vertically.
|
5
5
|
*
|
6
|
-
* @param {
|
7
|
-
* @param {boolean}
|
8
|
-
* @param {boolean}
|
6
|
+
* @param {HTMLElement} container Focusable element.
|
7
|
+
* @param {boolean} isReverse Set to true to check left, false to check right.
|
8
|
+
* @param {boolean} [onlyVertical=false] Set to true to check only vertical position.
|
9
9
|
*
|
10
10
|
* @return {boolean} True if at the edge, false if not.
|
11
11
|
*/
|
12
|
-
export default function isEdge(container:
|
12
|
+
export default function isEdge(container: HTMLElement, isReverse: boolean, onlyVertical?: boolean | undefined): boolean;
|
13
13
|
//# sourceMappingURL=is-edge.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,0CANW,WAAW,aACX,OAAO,uCAGN,OAAO,CAyGlB"}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* Check whether the selection is horizontally at the edge of the container.
|
3
3
|
*
|
4
|
-
* @param {
|
5
|
-
* @param {boolean}
|
4
|
+
* @param {HTMLElement} container Focusable element.
|
5
|
+
* @param {boolean} isReverse Set to true to check left, false for right.
|
6
6
|
*
|
7
7
|
* @return {boolean} True if at the horizontal edge, false if not.
|
8
8
|
*/
|
9
|
-
export default function isHorizontalEdge(container:
|
9
|
+
export default function isHorizontalEdge(container: HTMLElement, isReverse: boolean): boolean;
|
10
10
|
//# sourceMappingURL=is-horizontal-edge.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-horizontal-edge.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,oDALW,
|
1
|
+
{"version":3,"file":"is-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-horizontal-edge.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,oDALW,WAAW,aACX,OAAO,GAEN,OAAO,CAIlB"}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* Check whether the selection is vertically at the edge of the container.
|
3
3
|
*
|
4
|
-
* @param {
|
5
|
-
* @param {boolean}
|
4
|
+
* @param {HTMLElement} container Focusable element.
|
5
|
+
* @param {boolean} isReverse Set to true to check top, false for bottom.
|
6
6
|
*
|
7
7
|
* @return {boolean} True if at the vertical edge, false if not.
|
8
8
|
*/
|
9
|
-
export default function isVerticalEdge(container:
|
9
|
+
export default function isVerticalEdge(container: HTMLElement, isReverse: boolean): boolean;
|
10
10
|
//# sourceMappingURL=is-vertical-edge.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-vertical-edge.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,kDALW,
|
1
|
+
{"version":3,"file":"is-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-vertical-edge.js"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,kDALW,WAAW,aACX,OAAO,GAEN,OAAO,CAIlB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"place-caret-at-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-edge.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"place-caret-at-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-edge.js"],"names":[],"mappings":"AAsCA;;;;;;GAMG;AACH,oDAJW,WAAW,aACX,OAAO,KACP,MAAM,GAAC,SAAS,QA2C1B"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* If no range range can be created or it is outside the container, the element
|
3
|
+
* may be out of view, so scroll it into view and try again.
|
4
|
+
*
|
5
|
+
* @param {HTMLElement} container The container to scroll.
|
6
|
+
* @param {boolean} alignToTop True to align to top, false to bottom.
|
7
|
+
* @param {Function} callback The callback to create the range.
|
8
|
+
*
|
9
|
+
* @return {?Range} The range returned by the callback.
|
10
|
+
*/
|
11
|
+
export function scrollIfNoRange(container: HTMLElement, alignToTop: boolean, callback: Function): Range | null;
|
12
|
+
//# sourceMappingURL=scroll-if-no-range.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"scroll-if-no-range.d.ts","sourceRoot":"","sources":["../../src/dom/scroll-if-no-range.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,2CANW,WAAW,cACX,OAAO,uBAGL,KAAK,QAyBjB"}
|
package/build-types/index.d.ts
CHANGED
@@ -5,6 +5,6 @@ export namespace focus {
|
|
5
5
|
export * from "./dom";
|
6
6
|
export * from "./phrasing-content";
|
7
7
|
export * from "./data-transfer";
|
8
|
-
import * as focusable from
|
9
|
-
import * as tabbable from
|
8
|
+
import * as focusable from './focusable';
|
9
|
+
import * as tabbable from './tabbable';
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;2BAG2B,aAAa;0BACd,YAAY"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wordpress/dom",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.40.0",
|
4
4
|
"description": "DOM utilities module for WordPress.",
|
5
5
|
"author": "The WordPress Contributors",
|
6
6
|
"license": "GPL-2.0-or-later",
|
@@ -29,10 +29,10 @@
|
|
29
29
|
"sideEffects": false,
|
30
30
|
"dependencies": {
|
31
31
|
"@babel/runtime": "^7.16.0",
|
32
|
-
"@wordpress/deprecated": "^3.
|
32
|
+
"@wordpress/deprecated": "^3.40.0"
|
33
33
|
},
|
34
34
|
"publishConfig": {
|
35
35
|
"access": "public"
|
36
36
|
},
|
37
|
-
"gitHead": "
|
37
|
+
"gitHead": "78a288d55b83a713b2f7d98d5a855c0771a2afc6"
|
38
38
|
}
|
package/src/dom/is-edge.js
CHANGED
@@ -8,15 +8,16 @@ import isSelectionForward from './is-selection-forward';
|
|
8
8
|
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
|
9
9
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
10
10
|
import isInputOrTextArea from './is-input-or-text-area';
|
11
|
+
import { scrollIfNoRange } from './scroll-if-no-range';
|
11
12
|
|
12
13
|
/**
|
13
14
|
* Check whether the selection is at the edge of the container. Checks for
|
14
15
|
* horizontal position by default. Set `onlyVertical` to true to check only
|
15
16
|
* vertically.
|
16
17
|
*
|
17
|
-
* @param {
|
18
|
-
* @param {boolean}
|
19
|
-
* @param {boolean}
|
18
|
+
* @param {HTMLElement} container Focusable element.
|
19
|
+
* @param {boolean} isReverse Set to true to check left, false to check right.
|
20
|
+
* @param {boolean} [onlyVertical=false] Set to true to check only vertical position.
|
20
21
|
*
|
21
22
|
* @return {boolean} True if at the edge, false if not.
|
22
23
|
*/
|
@@ -96,11 +97,8 @@ export default function isEdge( container, isReverse, onlyVertical = false ) {
|
|
96
97
|
// pixels. `getComputedStyle` may return a value with different units.
|
97
98
|
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
|
98
99
|
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
|
99
|
-
const testRange =
|
100
|
-
ownerDocument,
|
101
|
-
x,
|
102
|
-
y,
|
103
|
-
/** @type {HTMLElement} */ ( container )
|
100
|
+
const testRange = scrollIfNoRange( container, isReverse, () =>
|
101
|
+
hiddenCaretRangeFromPoint( ownerDocument, x, y, container )
|
104
102
|
);
|
105
103
|
|
106
104
|
if ( ! testRange ) {
|
@@ -6,8 +6,8 @@ import isEdge from './is-edge';
|
|
6
6
|
/**
|
7
7
|
* Check whether the selection is horizontally at the edge of the container.
|
8
8
|
*
|
9
|
-
* @param {
|
10
|
-
* @param {boolean}
|
9
|
+
* @param {HTMLElement} container Focusable element.
|
10
|
+
* @param {boolean} isReverse Set to true to check left, false for right.
|
11
11
|
*
|
12
12
|
* @return {boolean} True if at the horizontal edge, false if not.
|
13
13
|
*/
|
@@ -6,8 +6,8 @@ import isEdge from './is-edge';
|
|
6
6
|
/**
|
7
7
|
* Check whether the selection is vertically at the edge of the container.
|
8
8
|
*
|
9
|
-
* @param {
|
10
|
-
* @param {boolean}
|
9
|
+
* @param {HTMLElement} container Focusable element.
|
10
|
+
* @param {boolean} isReverse Set to true to check top, false for bottom.
|
11
11
|
*
|
12
12
|
* @return {boolean} True if at the vertical edge, false if not.
|
13
13
|
*/
|
@@ -5,6 +5,7 @@ import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
|
|
5
5
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
6
6
|
import isInputOrTextArea from './is-input-or-text-area';
|
7
7
|
import isRTL from './is-rtl';
|
8
|
+
import { scrollIfNoRange } from './scroll-if-no-range';
|
8
9
|
|
9
10
|
/**
|
10
11
|
* Gets the range to place.
|
@@ -70,26 +71,11 @@ export default function placeCaretAtEdge( container, isReverse, x ) {
|
|
70
71
|
return;
|
71
72
|
}
|
72
73
|
|
73
|
-
|
74
|
+
const range = scrollIfNoRange( container, isReverse, () =>
|
75
|
+
getRange( container, isReverse, x )
|
76
|
+
);
|
74
77
|
|
75
|
-
|
76
|
-
// element may be out of view.
|
77
|
-
if (
|
78
|
-
! range ||
|
79
|
-
! range.startContainer ||
|
80
|
-
! container.contains( range.startContainer )
|
81
|
-
) {
|
82
|
-
container.scrollIntoView( isReverse );
|
83
|
-
range = range = getRange( container, isReverse, x );
|
84
|
-
|
85
|
-
if (
|
86
|
-
! range ||
|
87
|
-
! range.startContainer ||
|
88
|
-
! container.contains( range.startContainer )
|
89
|
-
) {
|
90
|
-
return;
|
91
|
-
}
|
92
|
-
}
|
78
|
+
if ( ! range ) return;
|
93
79
|
|
94
80
|
const { ownerDocument } = container;
|
95
81
|
const { defaultView } = ownerDocument;
|