@wordpress/block-editor 14.14.1 → 14.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +14 -11
- package/build/components/block-list/use-block-props/use-firefox-draggable-compatibility.js.map +1 -1
- package/build/components/inserter/block-patterns-explorer/pattern-list.js +3 -0
- package/build/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build/components/link-control/search-input.js +2 -3
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/writing-flow/use-tab-nav.js +21 -14
- package/build/components/writing-flow/use-tab-nav.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +14 -11
- package/build-module/components/block-list/use-block-props/use-firefox-draggable-compatibility.js.map +1 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js +4 -1
- package/build-module/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -1
- package/build-module/components/link-control/search-input.js +2 -3
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/writing-flow/use-tab-nav.js +21 -14
- package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
- package/package.json +6 -6
- package/src/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +14 -11
- package/src/components/inserter/block-patterns-explorer/pattern-list.js +7 -0
- package/src/components/link-control/search-input.js +2 -4
- package/src/components/link-control/test/index.js +46 -46
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/writing-flow/use-tab-nav.js +22 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useState","__","URLInput","LinkControlSearchResults","CREATE_TYPE","useSearchHandler","deprecated","jsx","_jsx","jsxs","_jsxs","noopSearchHandler","Promise","resolve","noop","LinkControlSearchInput","value","children","currentLink","className","placeholder","withCreateSuggestion","onCreateSuggestion","onChange","onSelect","showSuggestions","renderSuggestions","props","fetchSuggestions","allowDirectEntry","showInitialSuggestions","suggestionsQuery","withURLSuggestion","createSuggestionButtonText","hideLabelFromVision","suffix","ref","genericSearchHandler","searchHandler","focusedSuggestion","setFocusedSuggestion","onInputChange","selection","suggestion","handleRenderSuggestions","handleSuggestionClick","onSuggestionSelected","selectedSuggestion","type","title","url","e","Object","keys","length","id","restLinkProps","
|
|
1
|
+
{"version":3,"names":["forwardRef","useState","__","URLInput","LinkControlSearchResults","CREATE_TYPE","useSearchHandler","deprecated","jsx","_jsx","jsxs","_jsxs","noopSearchHandler","Promise","resolve","noop","LinkControlSearchInput","value","children","currentLink","className","placeholder","withCreateSuggestion","onCreateSuggestion","onChange","onSelect","showSuggestions","renderSuggestions","props","fetchSuggestions","allowDirectEntry","showInitialSuggestions","suggestionsQuery","withURLSuggestion","createSuggestionButtonText","hideLabelFromVision","suffix","ref","genericSearchHandler","searchHandler","focusedSuggestion","setFocusedSuggestion","onInputChange","selection","suggestion","handleRenderSuggestions","handleSuggestionClick","onSuggestionSelected","selectedSuggestion","type","title","url","e","Object","keys","length","id","restLinkProps","disableSuggestions","label","__experimentalRenderSuggestions","__experimentalFetchLinkSuggestions","__experimentalHandleURLSuggestions","__experimentalShowInitialSuggestions","onSubmit","event","hasSuggestion","trim","preventDefault","__experimentalLinkControlSearchInput","since"],"sources":["@wordpress/block-editor/src/components/link-control/search-input.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { forwardRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { URLInput } from '../';\nimport LinkControlSearchResults from './search-results';\nimport { CREATE_TYPE } from './constants';\nimport useSearchHandler from './use-search-handler';\nimport deprecated from '@wordpress/deprecated';\n\n// Must be a function as otherwise URLInput will default\n// to the fetchLinkSuggestions passed in block editor settings\n// which will cause an unintended http request.\nconst noopSearchHandler = () => Promise.resolve( [] );\n\nconst noop = () => {};\n\nconst LinkControlSearchInput = forwardRef(\n\t(\n\t\t{\n\t\t\tvalue,\n\t\t\tchildren,\n\t\t\tcurrentLink = {},\n\t\t\tclassName = null,\n\t\t\tplaceholder = null,\n\t\t\twithCreateSuggestion = false,\n\t\t\tonCreateSuggestion = noop,\n\t\t\tonChange = noop,\n\t\t\tonSelect = noop,\n\t\t\tshowSuggestions = true,\n\t\t\trenderSuggestions = ( props ) => (\n\t\t\t\t<LinkControlSearchResults { ...props } />\n\t\t\t),\n\t\t\tfetchSuggestions = null,\n\t\t\tallowDirectEntry = true,\n\t\t\tshowInitialSuggestions = false,\n\t\t\tsuggestionsQuery = {},\n\t\t\twithURLSuggestion = true,\n\t\t\tcreateSuggestionButtonText,\n\t\t\thideLabelFromVision = false,\n\t\t\tsuffix,\n\t\t},\n\t\tref\n\t) => {\n\t\tconst genericSearchHandler = useSearchHandler(\n\t\t\tsuggestionsQuery,\n\t\t\tallowDirectEntry,\n\t\t\twithCreateSuggestion,\n\t\t\twithURLSuggestion\n\t\t);\n\n\t\tconst searchHandler = showSuggestions\n\t\t\t? fetchSuggestions || genericSearchHandler\n\t\t\t: noopSearchHandler;\n\n\t\tconst [ focusedSuggestion, setFocusedSuggestion ] = useState();\n\n\t\t/**\n\t\t * Handles the user moving between different suggestions. Does not handle\n\t\t * choosing an individual item.\n\t\t *\n\t\t * @param {string} selection the url of the selected suggestion.\n\t\t * @param {Object} suggestion the suggestion object.\n\t\t */\n\t\tconst onInputChange = ( selection, suggestion ) => {\n\t\t\tonChange( selection );\n\t\t\tsetFocusedSuggestion( suggestion );\n\t\t};\n\n\t\tconst handleRenderSuggestions = ( props ) =>\n\t\t\trenderSuggestions( {\n\t\t\t\t...props,\n\t\t\t\twithCreateSuggestion,\n\t\t\t\tcreateSuggestionButtonText,\n\t\t\t\tsuggestionsQuery,\n\t\t\t\thandleSuggestionClick: ( suggestion ) => {\n\t\t\t\t\tif ( props.handleSuggestionClick ) {\n\t\t\t\t\t\tprops.handleSuggestionClick( suggestion );\n\t\t\t\t\t}\n\t\t\t\t\tonSuggestionSelected( suggestion );\n\t\t\t\t},\n\t\t\t} );\n\n\t\tconst onSuggestionSelected = async ( selectedSuggestion ) => {\n\t\t\tlet suggestion = selectedSuggestion;\n\t\t\tif ( CREATE_TYPE === selectedSuggestion.type ) {\n\t\t\t\t// Create a new page and call onSelect with the output from the onCreateSuggestion callback.\n\t\t\t\ttry {\n\t\t\t\t\tsuggestion = await onCreateSuggestion(\n\t\t\t\t\t\tselectedSuggestion.title\n\t\t\t\t\t);\n\t\t\t\t\tif ( suggestion?.url ) {\n\t\t\t\t\t\tonSelect( suggestion );\n\t\t\t\t\t}\n\t\t\t\t} catch ( e ) {}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tallowDirectEntry ||\n\t\t\t\t( suggestion && Object.keys( suggestion ).length >= 1 )\n\t\t\t) {\n\t\t\t\tconst { id, url, ...restLinkProps } = currentLink ?? {};\n\t\t\t\tonSelect(\n\t\t\t\t\t// Some direct entries don't have types or IDs, and we still need to clear the previous ones.\n\t\t\t\t\t{ ...restLinkProps, ...suggestion },\n\t\t\t\t\tsuggestion\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\treturn (\n\t\t\t<div className=\"block-editor-link-control__search-input-container\">\n\t\t\t\t<URLInput\n\t\t\t\t\tdisableSuggestions={ currentLink?.url === value }\n\t\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t\t\tclassName={ className }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onInputChange }\n\t\t\t\t\tplaceholder={ placeholder ?? __( 'Search or type URL' ) }\n\t\t\t\t\t__experimentalRenderSuggestions={\n\t\t\t\t\t\tshowSuggestions ? handleRenderSuggestions : null\n\t\t\t\t\t}\n\t\t\t\t\t__experimentalFetchLinkSuggestions={ searchHandler }\n\t\t\t\t\t__experimentalHandleURLSuggestions\n\t\t\t\t\t__experimentalShowInitialSuggestions={\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t}\n\t\t\t\t\tonSubmit={ ( suggestion, event ) => {\n\t\t\t\t\t\tconst hasSuggestion = suggestion || focusedSuggestion;\n\n\t\t\t\t\t\t// If there is no suggestion and the value (ie: any manually entered URL) is empty\n\t\t\t\t\t\t// then don't allow submission otherwise we get empty links.\n\t\t\t\t\t\tif ( ! hasSuggestion && ! value?.trim()?.length ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tonSuggestionSelected(\n\t\t\t\t\t\t\t\thasSuggestion || { url: value }\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\tref={ ref }\n\t\t\t\t\tsuffix={ suffix }\n\t\t\t\t/>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n);\n\nexport default LinkControlSearchInput;\n\nexport const __experimentalLinkControlSearchInput = ( props ) => {\n\tdeprecated( 'wp.blockEditor.__experimentalLinkControlSearchInput', {\n\t\tsince: '6.8',\n\t} );\n\n\treturn <LinkControlSearchInput { ...props } />;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,QAAQ,QAAQ,oBAAoB;AACzD,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,SAASC,QAAQ,QAAQ,KAAK;AAC9B,OAAOC,wBAAwB,MAAM,kBAAkB;AACvD,SAASC,WAAW,QAAQ,aAAa;AACzC,OAAOC,gBAAgB,MAAM,sBAAsB;AACnD,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AACA,MAAMC,iBAAiB,GAAGA,CAAA,KAAMC,OAAO,CAACC,OAAO,CAAE,EAAG,CAAC;AAErD,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,MAAMC,sBAAsB,GAAGhB,UAAU,CACxC,CACC;EACCiB,KAAK;EACLC,QAAQ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,EAAGtB,aAAe;MACpDuB,kCAAkC;MAClCC,oCAAoC,EACnChC,sBACA;MACDiC,QAAQ,EAAGA,CAAEpB,UAAU,EAAEqB,KAAK,KAAM;QACnC,MAAMC,aAAa,GAAGtB,UAAU,IAAIJ,iBAAiB;;QAErD;QACA;QACA,IAAK,CAAE0B,aAAa,IAAI,CAAEjD,KAAK,EAAEkD,IAAI,CAAC,CAAC,EAAEZ,MAAM,EAAG;UACjDU,KAAK,CAACG,cAAc,CAAC,CAAC;QACvB,CAAC,MAAM;UACNrB,oBAAoB,CACnBmB,aAAa,IAAI;YAAEf,GAAG,EAAElC;UAAM,CAC/B,CAAC;QACF;MACD,CAAG;MACHoB,GAAG,EAAGA,GAAK;MACXD,MAAM,EAAGA;IAAQ,CACjB,CAAC,EACAlB,QAAQ;EAAA,CACN,CAAC;AAER,CACD,CAAC;AAED,eAAeF,sBAAsB;AAErC,OAAO,MAAMqD,oCAAoC,GAAKzC,KAAK,IAAM;EAChErB,UAAU,CAAE,qDAAqD,EAAE;IAClE+D,KAAK,EAAE;EACR,CAAE,CAAC;EAEH,oBAAO7D,IAAA,CAACO,sBAAsB;IAAA,GAAMY;EAAK,CAAI,CAAC;AAC/C,CAAC","ignoreList":[]}
|
|
@@ -15,7 +15,7 @@ import { isInSameBlock, isInsideRootBlock } from '../../utils/dom';
|
|
|
15
15
|
import { unlock } from '../../lock-unlock';
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
export default function useTabNav() {
|
|
18
|
-
const
|
|
18
|
+
const containerRef = /** @type {typeof useRef<HTMLElement>} */useRef();
|
|
19
19
|
const focusCaptureBeforeRef = useRef();
|
|
20
20
|
const focusCaptureAfterRef = useRef();
|
|
21
21
|
const {
|
|
@@ -35,19 +35,19 @@ export default function useTabNav() {
|
|
|
35
35
|
// capturing on the focus capture elements.
|
|
36
36
|
const noCaptureRef = useRef();
|
|
37
37
|
function onFocusCapture(event) {
|
|
38
|
-
const canvasElement =
|
|
38
|
+
const canvasElement = containerRef.current.ownerDocument === event.target.ownerDocument ? containerRef.current : containerRef.current.ownerDocument.defaultView.frameElement;
|
|
39
39
|
|
|
40
40
|
// Do not capture incoming focus if set by us in WritingFlow.
|
|
41
41
|
if (noCaptureRef.current) {
|
|
42
42
|
noCaptureRef.current = null;
|
|
43
43
|
} else if (hasMultiSelection()) {
|
|
44
|
-
|
|
44
|
+
containerRef.current.focus();
|
|
45
45
|
} else if (getSelectedBlockClientId()) {
|
|
46
46
|
if (getLastFocus()?.current) {
|
|
47
47
|
getLastFocus().current.focus();
|
|
48
48
|
} else {
|
|
49
49
|
// Handles when the last focus has not been set yet, or has been cleared by new blocks being added via the inserter.
|
|
50
|
-
|
|
50
|
+
containerRef.current.querySelector(`[data-block="${getSelectedBlockClientId()}"]`).focus();
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
// In "compose" mode without a selected ID, we want to place focus on the section root when tabbing to the canvas.
|
|
@@ -57,11 +57,11 @@ export default function useTabNav() {
|
|
|
57
57
|
|
|
58
58
|
// If we have section within the section root, focus the first one.
|
|
59
59
|
if (sectionBlocks.length) {
|
|
60
|
-
|
|
60
|
+
containerRef.current.querySelector(`[data-block="${sectionBlocks[0]}"]`).focus();
|
|
61
61
|
}
|
|
62
62
|
// If we don't have any section blocks, focus the section root.
|
|
63
63
|
else if (sectionRootClientId) {
|
|
64
|
-
|
|
64
|
+
containerRef.current.querySelector(`[data-block="${sectionRootClientId}"]`).focus();
|
|
65
65
|
} else {
|
|
66
66
|
// If we don't have any section root, focus the canvas.
|
|
67
67
|
canvasElement.focus();
|
|
@@ -70,7 +70,7 @@ export default function useTabNav() {
|
|
|
70
70
|
const isBefore =
|
|
71
71
|
// eslint-disable-next-line no-bitwise
|
|
72
72
|
event.target.compareDocumentPosition(canvasElement) & event.target.DOCUMENT_POSITION_FOLLOWING;
|
|
73
|
-
const tabbables = focus.tabbable.find(
|
|
73
|
+
const tabbables = focus.tabbable.find(containerRef.current);
|
|
74
74
|
if (tabbables.length) {
|
|
75
75
|
const next = isBefore ? tabbables[0] : tabbables[tabbables.length - 1];
|
|
76
76
|
next.focus();
|
|
@@ -102,19 +102,26 @@ export default function useTabNav() {
|
|
|
102
102
|
if (event.keyCode !== TAB) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
|
-
if (
|
|
105
|
+
if (
|
|
106
|
+
// Bails in case the focus capture elements aren’t present. They
|
|
107
|
+
// may be omitted to avoid silent tab stops in preview mode.
|
|
108
|
+
// See: https://github.com/WordPress/gutenberg/pull/59317
|
|
109
|
+
!focusCaptureAfterRef.current || !focusCaptureBeforeRef.current) {
|
|
106
110
|
return;
|
|
107
111
|
}
|
|
108
|
-
const
|
|
112
|
+
const {
|
|
113
|
+
target,
|
|
114
|
+
shiftKey: isShift
|
|
115
|
+
} = event;
|
|
109
116
|
const direction = isShift ? 'findPrevious' : 'findNext';
|
|
110
|
-
const nextTabbable = focus.tabbable[direction](
|
|
117
|
+
const nextTabbable = focus.tabbable[direction](target);
|
|
111
118
|
|
|
112
119
|
// We want to constrain the tabbing to the block and its child blocks.
|
|
113
120
|
// If the preceding form element is within a different block,
|
|
114
121
|
// such as two sibling image blocks in the placeholder state,
|
|
115
122
|
// we want shift + tab from the first form element to move to the image
|
|
116
123
|
// block toolbar and not the previous image block's form element.
|
|
117
|
-
const currentBlock =
|
|
124
|
+
const currentBlock = target.closest('[data-block]');
|
|
118
125
|
const isElementPartOfSelectedBlock = currentBlock && nextTabbable && (isInSameBlock(currentBlock, nextTabbable) || isInsideRootBlock(currentBlock, nextTabbable));
|
|
119
126
|
|
|
120
127
|
// Allow tabbing from the block wrapper to a form element,
|
|
@@ -151,7 +158,7 @@ export default function useTabNav() {
|
|
|
151
158
|
|
|
152
159
|
// If focus disappears due to there being no blocks, move focus to
|
|
153
160
|
// the writing flow wrapper.
|
|
154
|
-
if (!event.relatedTarget && ownerDocument.activeElement === ownerDocument.body && getBlockCount() === 0) {
|
|
161
|
+
if (!event.relatedTarget && event.target.hasAttribute('data-block') && ownerDocument.activeElement === ownerDocument.body && getBlockCount() === 0) {
|
|
155
162
|
node.focus();
|
|
156
163
|
}
|
|
157
164
|
}
|
|
@@ -171,7 +178,7 @@ export default function useTabNav() {
|
|
|
171
178
|
if (event.target?.getAttribute('role') === 'region') {
|
|
172
179
|
return;
|
|
173
180
|
}
|
|
174
|
-
if (
|
|
181
|
+
if (containerRef.current === event.target) {
|
|
175
182
|
return;
|
|
176
183
|
}
|
|
177
184
|
const isShift = event.shiftKey;
|
|
@@ -200,7 +207,7 @@ export default function useTabNav() {
|
|
|
200
207
|
node.removeEventListener('focusout', onFocusOut);
|
|
201
208
|
};
|
|
202
209
|
}, []);
|
|
203
|
-
const mergedRefs = useMergeRefs([
|
|
210
|
+
const mergedRefs = useMergeRefs([containerRef, ref]);
|
|
204
211
|
return [before, mergedRefs, after];
|
|
205
212
|
}
|
|
206
213
|
//# sourceMappingURL=use-tab-nav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["focus","isFormElement","TAB","useSelect","useDispatch","useRefEffect","useMergeRefs","useRef","store","blockEditorStore","isInSameBlock","isInsideRootBlock","unlock","jsx","_jsx","useTabNav","container","focusCaptureBeforeRef","focusCaptureAfterRef","hasMultiSelection","getSelectedBlockClientId","getBlockCount","getBlockOrder","getLastFocus","getSectionRootClientId","isZoomOut","setLastFocus","noCaptureRef","onFocusCapture","event","canvasElement","current","ownerDocument","target","defaultView","frameElement","querySelector","sectionRootClientId","sectionBlocks","length","isBefore","compareDocumentPosition","DOCUMENT_POSITION_FOLLOWING","tabbables","tabbable","find","next","before","ref","tabIndex","onFocus","after","node","onKeyDown","defaultPrevented","keyCode","isShift","shiftKey","direction","nextTabbable","currentBlock","closest","isElementPartOfSelectedBlock","preventScroll","onFocusOut","relatedTarget","activeElement","body","preventScrollOnTab","getAttribute","preventDefault","addEventListener","removeEventListener","mergedRefs"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-tab-nav.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { focus, isFormElement } from '@wordpress/dom';\nimport { TAB } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect, useMergeRefs } from '@wordpress/compose';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { isInSameBlock, isInsideRootBlock } from '../../utils/dom';\nimport { unlock } from '../../lock-unlock';\n\nexport default function useTabNav() {\n\tconst container = useRef();\n\tconst focusCaptureBeforeRef = useRef();\n\tconst focusCaptureAfterRef = useRef();\n\n\tconst {\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t\tgetBlockCount,\n\t\tgetBlockOrder,\n\t\tgetLastFocus,\n\t\tgetSectionRootClientId,\n\t\tisZoomOut,\n\t} = unlock( useSelect( blockEditorStore ) );\n\tconst { setLastFocus } = unlock( useDispatch( blockEditorStore ) );\n\n\t// Reference that holds the a flag for enabling or disabling\n\t// capturing on the focus capture elements.\n\tconst noCaptureRef = useRef();\n\n\tfunction onFocusCapture( event ) {\n\t\tconst canvasElement =\n\t\t\tcontainer.current.ownerDocument === event.target.ownerDocument\n\t\t\t\t? container.current\n\t\t\t\t: container.current.ownerDocument.defaultView.frameElement;\n\n\t\t// Do not capture incoming focus if set by us in WritingFlow.\n\t\tif ( noCaptureRef.current ) {\n\t\t\tnoCaptureRef.current = null;\n\t\t} else if ( hasMultiSelection() ) {\n\t\t\tcontainer.current.focus();\n\t\t} else if ( getSelectedBlockClientId() ) {\n\t\t\tif ( getLastFocus()?.current ) {\n\t\t\t\tgetLastFocus().current.focus();\n\t\t\t} else {\n\t\t\t\t// Handles when the last focus has not been set yet, or has been cleared by new blocks being added via the inserter.\n\t\t\t\tcontainer.current\n\t\t\t\t\t.querySelector(\n\t\t\t\t\t\t`[data-block=\"${ getSelectedBlockClientId() }\"]`\n\t\t\t\t\t)\n\t\t\t\t\t.focus();\n\t\t\t}\n\t\t}\n\t\t// In \"compose\" mode without a selected ID, we want to place focus on the section root when tabbing to the canvas.\n\t\telse if ( isZoomOut() ) {\n\t\t\tconst sectionRootClientId = getSectionRootClientId();\n\t\t\tconst sectionBlocks = getBlockOrder( sectionRootClientId );\n\n\t\t\t// If we have section within the section root, focus the first one.\n\t\t\tif ( sectionBlocks.length ) {\n\t\t\t\tcontainer.current\n\t\t\t\t\t.querySelector( `[data-block=\"${ sectionBlocks[ 0 ] }\"]` )\n\t\t\t\t\t.focus();\n\t\t\t}\n\t\t\t// If we don't have any section blocks, focus the section root.\n\t\t\telse if ( sectionRootClientId ) {\n\t\t\t\tcontainer.current\n\t\t\t\t\t.querySelector( `[data-block=\"${ sectionRootClientId }\"]` )\n\t\t\t\t\t.focus();\n\t\t\t} else {\n\t\t\t\t// If we don't have any section root, focus the canvas.\n\t\t\t\tcanvasElement.focus();\n\t\t\t}\n\t\t} else {\n\t\t\tconst isBefore =\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tevent.target.compareDocumentPosition( canvasElement ) &\n\t\t\t\tevent.target.DOCUMENT_POSITION_FOLLOWING;\n\t\t\tconst tabbables = focus.tabbable.find( container.current );\n\n\t\t\tif ( tabbables.length ) {\n\t\t\t\tconst next = isBefore\n\t\t\t\t\t? tabbables[ 0 ]\n\t\t\t\t\t: tabbables[ tabbables.length - 1 ];\n\t\t\t\tnext.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\tconst before = (\n\t\t<div\n\t\t\tref={ focusCaptureBeforeRef }\n\t\t\ttabIndex=\"0\"\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst after = (\n\t\t<div\n\t\t\tref={ focusCaptureAfterRef }\n\t\t\ttabIndex=\"0\"\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst ref = useRefEffect( ( node ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In Edit mode, Tab should focus the first tabbable element after\n\t\t\t// the content, which is normally the sidebar (with block controls)\n\t\t\t// and Shift+Tab should focus the first tabbable element before the\n\t\t\t// content, which is normally the block toolbar.\n\t\t\t// Arrow keys can be used, and Tab and arrow keys can be used in\n\t\t\t// Navigation mode (press Esc), to navigate through blocks.\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\t\t\tconst nextTabbable = focus.tabbable[ direction ]( event.target );\n\n\t\t\t// We want to constrain the tabbing to the block and its child blocks.\n\t\t\t// If the preceding form element is within a different block,\n\t\t\t// such as two sibling image blocks in the placeholder state,\n\t\t\t// we want shift + tab from the first form element to move to the image\n\t\t\t// block toolbar and not the previous image block's form element.\n\t\t\tconst currentBlock = event.target.closest( '[data-block]' );\n\t\t\tconst isElementPartOfSelectedBlock =\n\t\t\t\tcurrentBlock &&\n\t\t\t\tnextTabbable &&\n\t\t\t\t( isInSameBlock( currentBlock, nextTabbable ) ||\n\t\t\t\t\tisInsideRootBlock( currentBlock, nextTabbable ) );\n\n\t\t\t// Allow tabbing from the block wrapper to a form element,\n\t\t\t// and between form elements rendered in a block and its child blocks,\n\t\t\t// such as inside a placeholder. Form elements are generally\n\t\t\t// meant to be UI rather than part of the content. Ideally\n\t\t\t// these are not rendered in the content and perhaps in the\n\t\t\t// future they can be rendered in an iframe or shadow DOM.\n\t\t\tif (\n\t\t\t\tisFormElement( nextTabbable ) &&\n\t\t\t\tisElementPartOfSelectedBlock\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst next = isShift ? focusCaptureBeforeRef : focusCaptureAfterRef;\n\n\t\t\t// Disable focus capturing on the focus capture element, so it\n\t\t\t// doesn't refocus this block and so it allows default behaviour\n\t\t\t// (moving focus to the next tabbable element).\n\t\t\tnoCaptureRef.current = true;\n\n\t\t\t// Focusing the focus capture element, which is located above and\n\t\t\t// below the editor, should not scroll the page all the way up or\n\t\t\t// down.\n\t\t\tnext.current.focus( { preventScroll: true } );\n\t\t}\n\n\t\tfunction onFocusOut( event ) {\n\t\t\tsetLastFocus( { ...getLastFocus(), current: event.target } );\n\n\t\t\tconst { ownerDocument } = node;\n\n\t\t\t// If focus disappears due to there being no blocks, move focus to\n\t\t\t// the writing flow wrapper.\n\t\t\tif (\n\t\t\t\t! event.relatedTarget &&\n\t\t\t\townerDocument.activeElement === ownerDocument.body &&\n\t\t\t\tgetBlockCount() === 0\n\t\t\t) {\n\t\t\t\tnode.focus();\n\t\t\t}\n\t\t}\n\n\t\t// When tabbing back to an element in block list, this event handler prevents scrolling if the\n\t\t// focus capture divs (before/after) are outside of the viewport. (For example shift+tab back to a paragraph\n\t\t// when focus is on a sidebar element. This prevents the scrollable writing area from jumping either to the\n\t\t// top or bottom of the document.\n\t\t//\n\t\t// Note that it isn't possible to disable scrolling in the onFocus event. We need to intercept this\n\t\t// earlier in the keypress handler, and call focus( { preventScroll: true } ) instead.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus#parameters\n\t\tfunction preventScrollOnTab( event ) {\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.target?.getAttribute( 'role' ) === 'region' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( container.current === event.target ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\t\t\tconst target = focus.tabbable[ direction ]( event.target );\n\t\t\t// Only do something when the next tabbable is a focus capture div (before/after)\n\t\t\tif (\n\t\t\t\ttarget === focusCaptureBeforeRef.current ||\n\t\t\t\ttarget === focusCaptureAfterRef.current\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttarget.focus( { preventScroll: true } );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\t\tconst { defaultView } = ownerDocument;\n\t\tdefaultView.addEventListener( 'keydown', preventScrollOnTab );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'focusout', onFocusOut );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'keydown', preventScrollOnTab );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'focusout', onFocusOut );\n\t\t};\n\t}, [] );\n\n\tconst mergedRefs = useMergeRefs( [ container, ref ] );\n\n\treturn [ before, mergedRefs, after ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,aAAa,QAAQ,gBAAgB;AACrD,SAASC,GAAG,QAAQ,qBAAqB;AACzC,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,EAAEC,YAAY,QAAQ,oBAAoB;AAC/D,SAASC,MAAM,QAAQ,oBAAoB;;AAE3C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,aAAa,EAAEC,iBAAiB,QAAQ,iBAAiB;AAClE,SAASC,MAAM,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3C,eAAe,SAASC,SAASA,CAAA,EAAG;EACnC,MAAMC,SAAS,GAAGT,MAAM,CAAC,CAAC;EAC1B,MAAMU,qBAAqB,GAAGV,MAAM,CAAC,CAAC;EACtC,MAAMW,oBAAoB,GAAGX,MAAM,CAAC,CAAC;EAErC,MAAM;IACLY,iBAAiB;IACjBC,wBAAwB;IACxBC,aAAa;IACbC,aAAa;IACbC,YAAY;IACZC,sBAAsB;IACtBC;EACD,CAAC,GAAGb,MAAM,CAAET,SAAS,CAAEM,gBAAiB,CAAE,CAAC;EAC3C,MAAM;IAAEi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AAY,CAAE,CAAEU,SAAS,EAAEgC,GAAG,CAAG,CAAC;EAErD,OAAO,CAAED,MAAM,EAAE0B,UAAU,EAAEtB,KAAK,CAAE;AACrC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["focus","isFormElement","TAB","useSelect","useDispatch","useRefEffect","useMergeRefs","useRef","store","blockEditorStore","isInSameBlock","isInsideRootBlock","unlock","jsx","_jsx","useTabNav","containerRef","focusCaptureBeforeRef","focusCaptureAfterRef","hasMultiSelection","getSelectedBlockClientId","getBlockCount","getBlockOrder","getLastFocus","getSectionRootClientId","isZoomOut","setLastFocus","noCaptureRef","onFocusCapture","event","canvasElement","current","ownerDocument","target","defaultView","frameElement","querySelector","sectionRootClientId","sectionBlocks","length","isBefore","compareDocumentPosition","DOCUMENT_POSITION_FOLLOWING","tabbables","tabbable","find","next","before","ref","tabIndex","onFocus","after","node","onKeyDown","defaultPrevented","keyCode","shiftKey","isShift","direction","nextTabbable","currentBlock","closest","isElementPartOfSelectedBlock","preventScroll","onFocusOut","relatedTarget","hasAttribute","activeElement","body","preventScrollOnTab","getAttribute","preventDefault","addEventListener","removeEventListener","mergedRefs"],"sources":["@wordpress/block-editor/src/components/writing-flow/use-tab-nav.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { focus, isFormElement } from '@wordpress/dom';\nimport { TAB } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect, useMergeRefs } from '@wordpress/compose';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { isInSameBlock, isInsideRootBlock } from '../../utils/dom';\nimport { unlock } from '../../lock-unlock';\n\nexport default function useTabNav() {\n\tconst containerRef = /** @type {typeof useRef<HTMLElement>} */ ( useRef )();\n\tconst focusCaptureBeforeRef = useRef();\n\tconst focusCaptureAfterRef = useRef();\n\n\tconst {\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t\tgetBlockCount,\n\t\tgetBlockOrder,\n\t\tgetLastFocus,\n\t\tgetSectionRootClientId,\n\t\tisZoomOut,\n\t} = unlock( useSelect( blockEditorStore ) );\n\tconst { setLastFocus } = unlock( useDispatch( blockEditorStore ) );\n\n\t// Reference that holds the a flag for enabling or disabling\n\t// capturing on the focus capture elements.\n\tconst noCaptureRef = useRef();\n\n\tfunction onFocusCapture( event ) {\n\t\tconst canvasElement =\n\t\t\tcontainerRef.current.ownerDocument === event.target.ownerDocument\n\t\t\t\t? containerRef.current\n\t\t\t\t: containerRef.current.ownerDocument.defaultView.frameElement;\n\n\t\t// Do not capture incoming focus if set by us in WritingFlow.\n\t\tif ( noCaptureRef.current ) {\n\t\t\tnoCaptureRef.current = null;\n\t\t} else if ( hasMultiSelection() ) {\n\t\t\tcontainerRef.current.focus();\n\t\t} else if ( getSelectedBlockClientId() ) {\n\t\t\tif ( getLastFocus()?.current ) {\n\t\t\t\tgetLastFocus().current.focus();\n\t\t\t} else {\n\t\t\t\t// Handles when the last focus has not been set yet, or has been cleared by new blocks being added via the inserter.\n\t\t\t\tcontainerRef.current\n\t\t\t\t\t.querySelector(\n\t\t\t\t\t\t`[data-block=\"${ getSelectedBlockClientId() }\"]`\n\t\t\t\t\t)\n\t\t\t\t\t.focus();\n\t\t\t}\n\t\t}\n\t\t// In \"compose\" mode without a selected ID, we want to place focus on the section root when tabbing to the canvas.\n\t\telse if ( isZoomOut() ) {\n\t\t\tconst sectionRootClientId = getSectionRootClientId();\n\t\t\tconst sectionBlocks = getBlockOrder( sectionRootClientId );\n\n\t\t\t// If we have section within the section root, focus the first one.\n\t\t\tif ( sectionBlocks.length ) {\n\t\t\t\tcontainerRef.current\n\t\t\t\t\t.querySelector( `[data-block=\"${ sectionBlocks[ 0 ] }\"]` )\n\t\t\t\t\t.focus();\n\t\t\t}\n\t\t\t// If we don't have any section blocks, focus the section root.\n\t\t\telse if ( sectionRootClientId ) {\n\t\t\t\tcontainerRef.current\n\t\t\t\t\t.querySelector( `[data-block=\"${ sectionRootClientId }\"]` )\n\t\t\t\t\t.focus();\n\t\t\t} else {\n\t\t\t\t// If we don't have any section root, focus the canvas.\n\t\t\t\tcanvasElement.focus();\n\t\t\t}\n\t\t} else {\n\t\t\tconst isBefore =\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tevent.target.compareDocumentPosition( canvasElement ) &\n\t\t\t\tevent.target.DOCUMENT_POSITION_FOLLOWING;\n\t\t\tconst tabbables = focus.tabbable.find( containerRef.current );\n\t\t\tif ( tabbables.length ) {\n\t\t\t\tconst next = isBefore\n\t\t\t\t\t? tabbables[ 0 ]\n\t\t\t\t\t: tabbables[ tabbables.length - 1 ];\n\t\t\t\tnext.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\tconst before = (\n\t\t<div\n\t\t\tref={ focusCaptureBeforeRef }\n\t\t\ttabIndex=\"0\"\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst after = (\n\t\t<div\n\t\t\tref={ focusCaptureAfterRef }\n\t\t\ttabIndex=\"0\"\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst ref = useRefEffect( ( node ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In Edit mode, Tab should focus the first tabbable element after\n\t\t\t// the content, which is normally the sidebar (with block controls)\n\t\t\t// and Shift+Tab should focus the first tabbable element before the\n\t\t\t// content, which is normally the block toolbar.\n\t\t\t// Arrow keys can be used, and Tab and arrow keys can be used in\n\t\t\t// Navigation mode (press Esc), to navigate through blocks.\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t// Bails in case the focus capture elements aren’t present. They\n\t\t\t\t// may be omitted to avoid silent tab stops in preview mode.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/59317\n\t\t\t\t! focusCaptureAfterRef.current ||\n\t\t\t\t! focusCaptureBeforeRef.current\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { target, shiftKey: isShift } = event;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\t\t\tconst nextTabbable = focus.tabbable[ direction ]( target );\n\n\t\t\t// We want to constrain the tabbing to the block and its child blocks.\n\t\t\t// If the preceding form element is within a different block,\n\t\t\t// such as two sibling image blocks in the placeholder state,\n\t\t\t// we want shift + tab from the first form element to move to the image\n\t\t\t// block toolbar and not the previous image block's form element.\n\t\t\tconst currentBlock = target.closest( '[data-block]' );\n\t\t\tconst isElementPartOfSelectedBlock =\n\t\t\t\tcurrentBlock &&\n\t\t\t\tnextTabbable &&\n\t\t\t\t( isInSameBlock( currentBlock, nextTabbable ) ||\n\t\t\t\t\tisInsideRootBlock( currentBlock, nextTabbable ) );\n\n\t\t\t// Allow tabbing from the block wrapper to a form element,\n\t\t\t// and between form elements rendered in a block and its child blocks,\n\t\t\t// such as inside a placeholder. Form elements are generally\n\t\t\t// meant to be UI rather than part of the content. Ideally\n\t\t\t// these are not rendered in the content and perhaps in the\n\t\t\t// future they can be rendered in an iframe or shadow DOM.\n\t\t\tif (\n\t\t\t\tisFormElement( nextTabbable ) &&\n\t\t\t\tisElementPartOfSelectedBlock\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst next = isShift ? focusCaptureBeforeRef : focusCaptureAfterRef;\n\n\t\t\t// Disable focus capturing on the focus capture element, so it\n\t\t\t// doesn't refocus this block and so it allows default behaviour\n\t\t\t// (moving focus to the next tabbable element).\n\t\t\tnoCaptureRef.current = true;\n\n\t\t\t// Focusing the focus capture element, which is located above and\n\t\t\t// below the editor, should not scroll the page all the way up or\n\t\t\t// down.\n\t\t\tnext.current.focus( { preventScroll: true } );\n\t\t}\n\n\t\tfunction onFocusOut( event ) {\n\t\t\tsetLastFocus( { ...getLastFocus(), current: event.target } );\n\n\t\t\tconst { ownerDocument } = node;\n\n\t\t\t// If focus disappears due to there being no blocks, move focus to\n\t\t\t// the writing flow wrapper.\n\t\t\tif (\n\t\t\t\t! event.relatedTarget &&\n\t\t\t\tevent.target.hasAttribute( 'data-block' ) &&\n\t\t\t\townerDocument.activeElement === ownerDocument.body &&\n\t\t\t\tgetBlockCount() === 0\n\t\t\t) {\n\t\t\t\tnode.focus();\n\t\t\t}\n\t\t}\n\n\t\t// When tabbing back to an element in block list, this event handler prevents scrolling if the\n\t\t// focus capture divs (before/after) are outside of the viewport. (For example shift+tab back to a paragraph\n\t\t// when focus is on a sidebar element. This prevents the scrollable writing area from jumping either to the\n\t\t// top or bottom of the document.\n\t\t//\n\t\t// Note that it isn't possible to disable scrolling in the onFocus event. We need to intercept this\n\t\t// earlier in the keypress handler, and call focus( { preventScroll: true } ) instead.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus#parameters\n\t\tfunction preventScrollOnTab( event ) {\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.target?.getAttribute( 'role' ) === 'region' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( containerRef.current === event.target ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\t\t\tconst target = focus.tabbable[ direction ]( event.target );\n\t\t\t// Only do something when the next tabbable is a focus capture div (before/after)\n\t\t\tif (\n\t\t\t\ttarget === focusCaptureBeforeRef.current ||\n\t\t\t\ttarget === focusCaptureAfterRef.current\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttarget.focus( { preventScroll: true } );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\t\tconst { defaultView } = ownerDocument;\n\t\tdefaultView.addEventListener( 'keydown', preventScrollOnTab );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'focusout', onFocusOut );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'keydown', preventScrollOnTab );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'focusout', onFocusOut );\n\t\t};\n\t}, [] );\n\n\tconst mergedRefs = useMergeRefs( [ containerRef, ref ] );\n\n\treturn [ before, mergedRefs, after ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,aAAa,QAAQ,gBAAgB;AACrD,SAASC,GAAG,QAAQ,qBAAqB;AACzC,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,YAAY,EAAEC,YAAY,QAAQ,oBAAoB;AAC/D,SAASC,MAAM,QAAQ,oBAAoB;;AAE3C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,aAAa;AACvD,SAASC,aAAa,EAAEC,iBAAiB,QAAQ,iBAAiB;AAClE,SAASC,MAAM,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3C,eAAe,SAASC,SAASA,CAAA,EAAG;EACnC,MAAMC,YAAY,GAAG,yCAA4CT,MAAM,CAAG,CAAC;EAC3E,MAAMU,qBAAqB,GAAGV,MAAM,CAAC,CAAC;EACtC,MAAMW,oBAAoB,GAAGX,MAAM,CAAC,CAAC;EAErC,MAAM;IACLY,iBAAiB;IACjBC,wBAAwB;IACxBC,aAAa;IACbC,aAAa;IACbC,YAAY;IACZC,sBAAsB;IACtBC;EACD,CAAC,GAAGb,MAAM,CAAET,SAAS,CAAEM,gBAAiB,CAAE,CAAC;EAC3C,MAAM;IAAEiB;EAAa,CAAC,GAAGd,MAAM,CAAER,WAAW,CAAEK,gBAAiB,CAAE,CAAC;;EAElE;EACA;EACA,MAAMkB,YAAY,GAAGpB,MAAM,CAAC,CAAC;EAE7B,SAASqB,cAAcA,CAAEC,KAAK,EAAG;IAChC,MAAMC,aAAa,GAClBd,YAAY,CAACe,OAAO,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HANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "14.14.
|
|
3
|
+
"version": "14.14.3",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@wordpress/blob": "^4.19.1",
|
|
43
43
|
"@wordpress/block-serialization-default-parser": "^5.19.1",
|
|
44
44
|
"@wordpress/blocks": "^14.8.1",
|
|
45
|
-
"@wordpress/commands": "^1.19.
|
|
46
|
-
"@wordpress/components": "^29.5.
|
|
45
|
+
"@wordpress/commands": "^1.19.2",
|
|
46
|
+
"@wordpress/components": "^29.5.2",
|
|
47
47
|
"@wordpress/compose": "^7.19.1",
|
|
48
48
|
"@wordpress/data": "^10.19.1",
|
|
49
49
|
"@wordpress/date": "^5.19.1",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
"@wordpress/keyboard-shortcuts": "^5.19.1",
|
|
60
60
|
"@wordpress/keycodes": "^4.19.1",
|
|
61
61
|
"@wordpress/notices": "^5.19.1",
|
|
62
|
-
"@wordpress/preferences": "^4.19.
|
|
62
|
+
"@wordpress/preferences": "^4.19.2",
|
|
63
63
|
"@wordpress/priority-queue": "^3.19.1",
|
|
64
64
|
"@wordpress/private-apis": "^1.19.1",
|
|
65
65
|
"@wordpress/rich-text": "^7.19.1",
|
|
66
66
|
"@wordpress/style-engine": "^2.19.1",
|
|
67
67
|
"@wordpress/token-list": "^3.19.1",
|
|
68
|
-
"@wordpress/upload-media": "^0.4.
|
|
68
|
+
"@wordpress/upload-media": "^0.4.2",
|
|
69
69
|
"@wordpress/url": "^4.19.1",
|
|
70
70
|
"@wordpress/warning": "^3.19.1",
|
|
71
71
|
"@wordpress/wordcount": "^4.19.1",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "0750912b313e3e488ec2cad0c084e548cedd6b95"
|
|
95
95
|
}
|
|
@@ -41,12 +41,15 @@ function restore( node ) {
|
|
|
41
41
|
|
|
42
42
|
function down( event ) {
|
|
43
43
|
const { target } = event;
|
|
44
|
-
const { ownerDocument, isContentEditable } = target;
|
|
44
|
+
const { ownerDocument, isContentEditable, tagName } = target;
|
|
45
|
+
const isInputOrTextArea = [ 'INPUT', 'TEXTAREA' ].includes( tagName );
|
|
46
|
+
|
|
45
47
|
const nodes = nodesByDocument.get( ownerDocument );
|
|
46
48
|
|
|
47
|
-
if ( isContentEditable ) {
|
|
48
|
-
// Whenever an editable element is clicked,
|
|
49
|
-
// blocks contain this element, and temporarily
|
|
49
|
+
if ( isContentEditable || isInputOrTextArea ) {
|
|
50
|
+
// Whenever an editable element or an input or textarea is clicked,
|
|
51
|
+
// check which draggable blocks contain this element, and temporarily
|
|
52
|
+
// disable draggability.
|
|
50
53
|
for ( const node of nodes ) {
|
|
51
54
|
if (
|
|
52
55
|
node.getAttribute( 'draggable' ) === 'true' &&
|
|
@@ -57,8 +60,8 @@ function down( event ) {
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
} else {
|
|
60
|
-
// Whenever a non-editable element is clicked,
|
|
61
|
-
// for any blocks that were previously disabled.
|
|
63
|
+
// Whenever a non-editable element or an input or textarea is clicked,
|
|
64
|
+
// re-enable draggability for any blocks that were previously disabled.
|
|
62
65
|
for ( const node of nodes ) {
|
|
63
66
|
restore( node );
|
|
64
67
|
}
|
|
@@ -66,11 +69,11 @@ function down( event ) {
|
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
/**
|
|
69
|
-
* In Firefox, the `draggable` and `contenteditable`
|
|
70
|
-
* together. When
|
|
71
|
-
* doesn't get set in the right place. The only
|
|
72
|
-
* remove the `draggable` attribute clicking inside
|
|
73
|
-
*
|
|
72
|
+
* In Firefox, the `draggable` and `contenteditable` or `input` or `textarea`
|
|
73
|
+
* elements don't play well together. When these elements are within a
|
|
74
|
+
* `draggable` element, selection doesn't get set in the right place. The only
|
|
75
|
+
* solution is to temporarily remove the `draggable` attribute clicking inside
|
|
76
|
+
* these elements.
|
|
74
77
|
* @return {Function} Cleanup function.
|
|
75
78
|
*/
|
|
76
79
|
export function useFirefoxDraggableCompatibility() {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
INSERTER_PATTERN_TYPES,
|
|
22
22
|
allPatternsCategory,
|
|
23
23
|
myPatternsCategory,
|
|
24
|
+
starterPatternsCategory,
|
|
24
25
|
} from '../block-patterns-tab/utils';
|
|
25
26
|
|
|
26
27
|
function PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {
|
|
@@ -85,6 +86,12 @@ function PatternList( {
|
|
|
85
86
|
) {
|
|
86
87
|
return true;
|
|
87
88
|
}
|
|
89
|
+
if (
|
|
90
|
+
selectedCategory === starterPatternsCategory.name &&
|
|
91
|
+
pattern.blockTypes?.includes( 'core/post-content' )
|
|
92
|
+
) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
88
95
|
if ( selectedCategory === 'uncategorized' ) {
|
|
89
96
|
const hasKnownCategory =
|
|
90
97
|
pattern.categories?.some( ( category ) =>
|
|
@@ -114,18 +114,16 @@ const LinkControlSearchInput = forwardRef(
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
-
const inputLabel = placeholder ?? __( 'Search or type URL' );
|
|
118
|
-
|
|
119
117
|
return (
|
|
120
118
|
<div className="block-editor-link-control__search-input-container">
|
|
121
119
|
<URLInput
|
|
122
120
|
disableSuggestions={ currentLink?.url === value }
|
|
123
|
-
label={
|
|
121
|
+
label={ __( 'Link' ) }
|
|
124
122
|
hideLabelFromVision={ hideLabelFromVision }
|
|
125
123
|
className={ className }
|
|
126
124
|
value={ value }
|
|
127
125
|
onChange={ onInputChange }
|
|
128
|
-
placeholder={
|
|
126
|
+
placeholder={ placeholder ?? __( 'Search or type URL' ) }
|
|
129
127
|
__experimentalRenderSuggestions={
|
|
130
128
|
showSuggestions ? handleRenderSuggestions : null
|
|
131
129
|
}
|