@wordpress/block-editor 14.14.1 → 14.14.2
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/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/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 +2 -2
- 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
|
@@ -65,6 +65,9 @@ function PatternList({
|
|
|
65
65
|
if (selectedCategory === _utils.myPatternsCategory.name && pattern.type === _utils.INSERTER_PATTERN_TYPES.user) {
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
|
+
if (selectedCategory === _utils.starterPatternsCategory.name && pattern.blockTypes?.includes('core/post-content')) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
68
71
|
if (selectedCategory === 'uncategorized') {
|
|
69
72
|
var _pattern$categories$s;
|
|
70
73
|
const hasKnownCategory = (_pattern$categories$s = pattern.categories?.some(category => registeredPatternCategories.includes(category))) !== null && _pattern$categories$s !== void 0 ? _pattern$categories$s : false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_i18n","_compose","_components","_a11y","_blockPatternsList","_interopRequireDefault","_useInsertionPoint","_usePatternsState","_inserterListbox","_searchItems","_blockPatternsPaging","_usePatternsPaging","_utils","_jsxRuntime","PatternsListHeader","filterValue","filteredBlockPatternsLength","jsx","__experimentalHeading","level","lineHeight","className","children","sprintf","_n","PatternList","searchValue","selectedCategory","patternCategories","rootClientId","onModalClose","container","useRef","debouncedSpeak","useDebounce","speak","destinationRootClientId","onInsertBlocks","useInsertionPoint","shouldFocusBlock","patterns","onClickPattern","usePatternsState","registeredPatternCategories","useMemo","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","allPatternsCategory","myPatternsCategory","type","INSERTER_PATTERN_TYPES","user","_pattern$categories$s","hasKnownCategory","categories","some","category","includes","length","searchItems","useEffect","count","resultsFoundMessage","pagingProps","usePatternsPaging","previousSearchValue","setPreviousSearchValue","useState","changePage","hasItems","jsxs","ref","default","Fragment","blockPatterns","categoryPatterns","blocks","isDraggable","_default","exports"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/pattern-list.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useEffect, useRef, useState } from '@wordpress/element';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useDebounce } from '@wordpress/compose';\nimport { __experimentalHeading as Heading } from '@wordpress/components';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport BlockPatternsList from '../../block-patterns-list';\nimport useInsertionPoint from '../hooks/use-insertion-point';\nimport usePatternsState from '../hooks/use-patterns-state';\nimport InserterListbox from '../../inserter-listbox';\nimport { searchItems } from '../search-items';\nimport BlockPatternsPaging from '../../block-patterns-paging';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport {\n\tINSERTER_PATTERN_TYPES,\n\tallPatternsCategory,\n\tmyPatternsCategory,\n} from '../block-patterns-tab/utils';\n\nfunction PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {\n\tif ( ! filterValue ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Heading\n\t\t\tlevel={ 2 }\n\t\t\tlineHeight=\"48px\"\n\t\t\tclassName=\"block-editor-block-patterns-explorer__search-results-count\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d: number of patterns. */\n\t\t\t\t_n(\n\t\t\t\t\t'%d pattern found',\n\t\t\t\t\t'%d patterns found',\n\t\t\t\t\tfilteredBlockPatternsLength\n\t\t\t\t),\n\t\t\t\tfilteredBlockPatternsLength\n\t\t\t) }\n\t\t</Heading>\n\t);\n}\n\nfunction PatternList( {\n\tsearchValue,\n\tselectedCategory,\n\tpatternCategories,\n\trootClientId,\n\tonModalClose,\n} ) {\n\tconst container = useRef();\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\tconst [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {\n\t\trootClientId,\n\t\tshouldFocusBlock: true,\n\t} );\n\tconst [ patterns, , onClickPattern ] = usePatternsState(\n\t\tonInsertBlocks,\n\t\tdestinationRootClientId,\n\t\tselectedCategory\n\t);\n\n\tconst registeredPatternCategories = useMemo(\n\t\t() =>\n\t\t\tpatternCategories.map(\n\t\t\t\t( patternCategory ) => patternCategory.name\n\t\t\t),\n\t\t[ patternCategories ]\n\t);\n\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\tconst filteredPatterns = patterns.filter( ( pattern ) => {\n\t\t\tif ( selectedCategory === allPatternsCategory.name ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tselectedCategory === myPatternsCategory.name &&\n\t\t\t\tpattern.type === INSERTER_PATTERN_TYPES.user\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( selectedCategory === 'uncategorized' ) {\n\t\t\t\tconst hasKnownCategory =\n\t\t\t\t\tpattern.categories?.some( ( category ) =>\n\t\t\t\t\t\tregisteredPatternCategories.includes( category )\n\t\t\t\t\t) ?? false;\n\n\t\t\t\treturn ! pattern.categories?.length || ! hasKnownCategory;\n\t\t\t}\n\n\t\t\treturn pattern.categories?.includes( selectedCategory );\n\t\t} );\n\n\t\tif ( ! searchValue ) {\n\t\t\treturn filteredPatterns;\n\t\t}\n\n\t\treturn searchItems( filteredPatterns, searchValue );\n\t}, [\n\t\tsearchValue,\n\t\tpatterns,\n\t\tselectedCategory,\n\t\tregisteredPatternCategories,\n\t] );\n\n\t// Announce search results on change.\n\tuseEffect( () => {\n\t\tif ( ! searchValue ) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = filteredBlockPatterns.length;\n\t\tconst resultsFoundMessage = sprintf(\n\t\t\t/* translators: %d: number of results. */\n\t\t\t_n( '%d result found.', '%d results found.', count ),\n\t\t\tcount\n\t\t);\n\t\tdebouncedSpeak( resultsFoundMessage );\n\t}, [ searchValue, debouncedSpeak, filteredBlockPatterns.length ] );\n\n\tconst pagingProps = usePatternsPaging(\n\t\tfilteredBlockPatterns,\n\t\tselectedCategory,\n\t\tcontainer\n\t);\n\n\t// Reset page when search value changes.\n\tconst [ previousSearchValue, setPreviousSearchValue ] =\n\t\tuseState( searchValue );\n\tif ( searchValue !== previousSearchValue ) {\n\t\tsetPreviousSearchValue( searchValue );\n\t\tpagingProps.changePage( 1 );\n\t}\n\n\tconst hasItems = !! filteredBlockPatterns?.length;\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-patterns-explorer__list\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<PatternsListHeader\n\t\t\t\tfilterValue={ searchValue }\n\t\t\t\tfilteredBlockPatternsLength={ filteredBlockPatterns.length }\n\t\t\t/>\n\n\t\t\t<InserterListbox>\n\t\t\t\t{ hasItems && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\t\t\tonClickPattern={ ( pattern, blocks ) => {\n\t\t\t\t\t\t\t\tonClickPattern( pattern, blocks );\n\t\t\t\t\t\t\t\tonModalClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisDraggable={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</InserterListbox>\n\t\t</div>\n\t);\n}\n\nexport default PatternList;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,kBAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,kBAAA,GAAAD,sBAAA,CAAAN,OAAA;AACA,IAAAQ,iBAAA,GAAAF,sBAAA,CAAAN,OAAA;AACA,IAAAS,gBAAA,GAAAH,sBAAA,CAAAN,OAAA;AACA,IAAAU,YAAA,GAAAV,OAAA;AACA,IAAAW,oBAAA,GAAAL,sBAAA,CAAAN,OAAA;AACA,IAAAY,kBAAA,GAAAN,sBAAA,CAAAN,OAAA;AACA,IAAAa,MAAA,GAAAb,OAAA;AAIqC,IAAAc,WAAA,GAAAd,OAAA;AAvBrC;AACA;AACA;;AAOA;AACA;AACA;;AAcA,SAASe,kBAAkBA,CAAE;EAAEC,WAAW;EAAEC;AAA4B,CAAC,EAAG;EAC3E,IAAK,CAAED,WAAW,EAAG;IACpB,OAAO,IAAI;EACZ;EAEA,oBACC,IAAAF,WAAA,CAAAI,GAAA,EAACf,WAAA,CAAAgB,qBAAO;IACPC,KAAK,EAAG,CAAG;IACXC,UAAU,EAAC,MAAM;IACjBC,SAAS,EAAC,4DAA4D;IAAAC,QAAA,EAEpE,IAAAC,aAAO,EACR;IACA,IAAAC,QAAE,EACD,kBAAkB,EAClB,mBAAmB,EACnBR,2BACD,CAAC,EACDA,2BACD;EAAC,CACO,CAAC;AAEZ;AAEA,SAASS,WAAWA,CAAE;EACrBC,WAAW;EACXC,gBAAgB;EAChBC,iBAAiB;EACjB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WAAa;MAC3BV,2BAA2B,EAAGgC,qBAAqB,CAACe;IAAQ,CAC5D,CAAC,eAEF,IAAAlD,WAAA,CAAAI,GAAA,EAACT,gBAAA,CAAAqE,OAAe;MAAAvD,QAAA,EACboD,QAAQ,iBACT,IAAA7D,WAAA,CAAA8D,IAAA,EAAA9D,WAAA,CAAAiE,QAAA;QAAAxD,QAAA,gBACC,IAAAT,WAAA,CAAAI,GAAA,EAACb,kBAAA,CAAAyE,OAAiB;UACjBE,aAAa,EAAGX,WAAW,CAACY,gBAAkB;UAC9CvC,cAAc,EAAGA,CAAEU,OAAO,EAAE8B,MAAM,KAAM;YACvCxC,cAAc,CAAEU,OAAO,EAAE8B,MAAO,CAAC;YACjCnD,YAAY,CAAC,CAAC;UACf,CAAG;UACHoD,WAAW,EAAG;QAAO,CACrB,CAAC,eACF,IAAArE,WAAA,CAAAI,GAAA,EAACP,oBAAA,CAAAmE,OAAmB;UAAA,GAAMT;QAAW,CAAI,CAAC;MAAA,CACzC;IACF,CACe,CAAC;EAAA,CACd,CAAC;AAER;AAAC,IAAAe,QAAA,GAAAC,OAAA,CAAAP,OAAA,GAEcpD,WAAW","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_compose","_components","_a11y","_blockPatternsList","_interopRequireDefault","_useInsertionPoint","_usePatternsState","_inserterListbox","_searchItems","_blockPatternsPaging","_usePatternsPaging","_utils","_jsxRuntime","PatternsListHeader","filterValue","filteredBlockPatternsLength","jsx","__experimentalHeading","level","lineHeight","className","children","sprintf","_n","PatternList","searchValue","selectedCategory","patternCategories","rootClientId","onModalClose","container","useRef","debouncedSpeak","useDebounce","speak","destinationRootClientId","onInsertBlocks","useInsertionPoint","shouldFocusBlock","patterns","onClickPattern","usePatternsState","registeredPatternCategories","useMemo","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","allPatternsCategory","myPatternsCategory","type","INSERTER_PATTERN_TYPES","user","starterPatternsCategory","blockTypes","includes","_pattern$categories$s","hasKnownCategory","categories","some","category","length","searchItems","useEffect","count","resultsFoundMessage","pagingProps","usePatternsPaging","previousSearchValue","setPreviousSearchValue","useState","changePage","hasItems","jsxs","ref","default","Fragment","blockPatterns","categoryPatterns","blocks","isDraggable","_default","exports"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/pattern-list.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useEffect, useRef, useState } from '@wordpress/element';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useDebounce } from '@wordpress/compose';\nimport { __experimentalHeading as Heading } from '@wordpress/components';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport BlockPatternsList from '../../block-patterns-list';\nimport useInsertionPoint from '../hooks/use-insertion-point';\nimport usePatternsState from '../hooks/use-patterns-state';\nimport InserterListbox from '../../inserter-listbox';\nimport { searchItems } from '../search-items';\nimport BlockPatternsPaging from '../../block-patterns-paging';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport {\n\tINSERTER_PATTERN_TYPES,\n\tallPatternsCategory,\n\tmyPatternsCategory,\n\tstarterPatternsCategory,\n} from '../block-patterns-tab/utils';\n\nfunction PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {\n\tif ( ! filterValue ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Heading\n\t\t\tlevel={ 2 }\n\t\t\tlineHeight=\"48px\"\n\t\t\tclassName=\"block-editor-block-patterns-explorer__search-results-count\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d: number of patterns. */\n\t\t\t\t_n(\n\t\t\t\t\t'%d pattern found',\n\t\t\t\t\t'%d patterns found',\n\t\t\t\t\tfilteredBlockPatternsLength\n\t\t\t\t),\n\t\t\t\tfilteredBlockPatternsLength\n\t\t\t) }\n\t\t</Heading>\n\t);\n}\n\nfunction PatternList( {\n\tsearchValue,\n\tselectedCategory,\n\tpatternCategories,\n\trootClientId,\n\tonModalClose,\n} ) {\n\tconst container = useRef();\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\tconst [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {\n\t\trootClientId,\n\t\tshouldFocusBlock: true,\n\t} );\n\tconst [ patterns, , onClickPattern ] = usePatternsState(\n\t\tonInsertBlocks,\n\t\tdestinationRootClientId,\n\t\tselectedCategory\n\t);\n\n\tconst registeredPatternCategories = useMemo(\n\t\t() =>\n\t\t\tpatternCategories.map(\n\t\t\t\t( patternCategory ) => patternCategory.name\n\t\t\t),\n\t\t[ patternCategories ]\n\t);\n\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\tconst filteredPatterns = patterns.filter( ( pattern ) => {\n\t\t\tif ( selectedCategory === allPatternsCategory.name ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tselectedCategory === myPatternsCategory.name &&\n\t\t\t\tpattern.type === INSERTER_PATTERN_TYPES.user\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tselectedCategory === starterPatternsCategory.name &&\n\t\t\t\tpattern.blockTypes?.includes( 'core/post-content' )\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( selectedCategory === 'uncategorized' ) {\n\t\t\t\tconst hasKnownCategory =\n\t\t\t\t\tpattern.categories?.some( ( category ) =>\n\t\t\t\t\t\tregisteredPatternCategories.includes( category )\n\t\t\t\t\t) ?? false;\n\n\t\t\t\treturn ! pattern.categories?.length || ! hasKnownCategory;\n\t\t\t}\n\n\t\t\treturn pattern.categories?.includes( selectedCategory );\n\t\t} );\n\n\t\tif ( ! searchValue ) {\n\t\t\treturn filteredPatterns;\n\t\t}\n\n\t\treturn searchItems( filteredPatterns, searchValue );\n\t}, [\n\t\tsearchValue,\n\t\tpatterns,\n\t\tselectedCategory,\n\t\tregisteredPatternCategories,\n\t] );\n\n\t// Announce search results on change.\n\tuseEffect( () => {\n\t\tif ( ! searchValue ) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = filteredBlockPatterns.length;\n\t\tconst resultsFoundMessage = sprintf(\n\t\t\t/* translators: %d: number of results. */\n\t\t\t_n( '%d result found.', '%d results found.', count ),\n\t\t\tcount\n\t\t);\n\t\tdebouncedSpeak( resultsFoundMessage );\n\t}, [ searchValue, debouncedSpeak, filteredBlockPatterns.length ] );\n\n\tconst pagingProps = usePatternsPaging(\n\t\tfilteredBlockPatterns,\n\t\tselectedCategory,\n\t\tcontainer\n\t);\n\n\t// Reset page when search value changes.\n\tconst [ previousSearchValue, setPreviousSearchValue ] =\n\t\tuseState( searchValue );\n\tif ( searchValue !== previousSearchValue ) {\n\t\tsetPreviousSearchValue( searchValue );\n\t\tpagingProps.changePage( 1 );\n\t}\n\n\tconst hasItems = !! filteredBlockPatterns?.length;\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-patterns-explorer__list\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<PatternsListHeader\n\t\t\t\tfilterValue={ searchValue }\n\t\t\t\tfilteredBlockPatternsLength={ filteredBlockPatterns.length }\n\t\t\t/>\n\n\t\t\t<InserterListbox>\n\t\t\t\t{ hasItems && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\t\t\tonClickPattern={ ( pattern, blocks ) => {\n\t\t\t\t\t\t\t\tonClickPattern( pattern, blocks );\n\t\t\t\t\t\t\t\tonModalClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisDraggable={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</InserterListbox>\n\t\t</div>\n\t);\n}\n\nexport default PatternList;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAA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AAe;MAAAzD,QAAA,EACbsD,QAAQ,iBACT,IAAA/D,WAAA,CAAAgE,IAAA,EAAAhE,WAAA,CAAAmE,QAAA;QAAA1D,QAAA,gBACC,IAAAT,WAAA,CAAAI,GAAA,EAACb,kBAAA,CAAA2E,OAAiB;UACjBE,aAAa,EAAGX,WAAW,CAACY,gBAAkB;UAC9CzC,cAAc,EAAGA,CAAEU,OAAO,EAAEgC,MAAM,KAAM;YACvC1C,cAAc,CAAEU,OAAO,EAAEgC,MAAO,CAAC;YACjCrD,YAAY,CAAC,CAAC;UACf,CAAG;UACHsD,WAAW,EAAG;QAAO,CACrB,CAAC,eACF,IAAAvE,WAAA,CAAAI,GAAA,EAACP,oBAAA,CAAAqE,OAAmB;UAAA,GAAMT;QAAW,CAAI,CAAC;MAAA,CACzC;IACF,CACe,CAAC;EAAA,CACd,CAAC;AAER;AAAC,IAAAe,QAAA,GAAAC,OAAA,CAAAP,OAAA,GAEctD,WAAW","ignoreList":[]}
|
|
@@ -102,17 +102,16 @@ const LinkControlSearchInput = (0, _element.forwardRef)(({
|
|
|
102
102
|
}, suggestion);
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
-
const inputLabel = placeholder !== null && placeholder !== void 0 ? placeholder : (0, _i18n.__)('Search or type URL');
|
|
106
105
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
107
106
|
className: "block-editor-link-control__search-input-container",
|
|
108
107
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.URLInput, {
|
|
109
108
|
disableSuggestions: currentLink?.url === value,
|
|
110
|
-
label:
|
|
109
|
+
label: (0, _i18n.__)('Link'),
|
|
111
110
|
hideLabelFromVision: hideLabelFromVision,
|
|
112
111
|
className: className,
|
|
113
112
|
value: value,
|
|
114
113
|
onChange: onInputChange,
|
|
115
|
-
placeholder:
|
|
114
|
+
placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : (0, _i18n.__)('Search or type URL'),
|
|
116
115
|
__experimentalRenderSuggestions: showSuggestions ? handleRenderSuggestions : null,
|
|
117
116
|
__experimentalFetchLinkSuggestions: searchHandler,
|
|
118
117
|
__experimentalHandleURLSuggestions: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_i18n","_","_searchResults","_interopRequireDefault","_constants","_useSearchHandler","_deprecated","_jsxRuntime","noopSearchHandler","Promise","resolve","noop","LinkControlSearchInput","forwardRef","value","children","currentLink","className","placeholder","withCreateSuggestion","onCreateSuggestion","onChange","onSelect","showSuggestions","renderSuggestions","props","jsx","default","fetchSuggestions","allowDirectEntry","showInitialSuggestions","suggestionsQuery","withURLSuggestion","createSuggestionButtonText","hideLabelFromVision","suffix","ref","genericSearchHandler","useSearchHandler","searchHandler","focusedSuggestion","setFocusedSuggestion","useState","onInputChange","selection","suggestion","handleRenderSuggestions","handleSuggestionClick","onSuggestionSelected","selectedSuggestion","CREATE_TYPE","type","title","url","e","Object","keys","length","id","restLinkProps","inputLabel","__","jsxs","URLInput","disableSuggestions","label","__experimentalRenderSuggestions","__experimentalFetchLinkSuggestions","__experimentalHandleURLSuggestions","__experimentalShowInitialSuggestions","onSubmit","event","hasSuggestion","trim","preventDefault","_default","exports","__experimentalLinkControlSearchInput","deprecated","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\tconst inputLabel = placeholder ?? __( 'Search or type URL' );\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={ inputLabel }\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={ inputLabel }\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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,CAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,WAAA,GAAAH,sBAAA,CAAAJ,OAAA;AAA+C,IAAAQ,WAAA,GAAAR,OAAA;AAb/C;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AACA;AACA;AACA,MAAMS,iBAAiB,GAAGA,CAAA,KAAMC,OAAO,CAACC,OAAO,CAAE,EAAG,CAAC;AAErD,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,MAAMC,sBAAsB,GAAG,IAAAC,mBAAU,EACxC,CACC;EACCC,KA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,KAAO;MACfO,QAAQ,EAAGsB,aAAe;MAC1BzB,WAAW,EAAG0C,UAAY;MAC1BM,+BAA+B,EAC9B3C,eAAe,GAAGuB,uBAAuB,GAAG,IAC5C;MACDqB,kCAAkC,EAAG5B,aAAe;MACpD6B,kCAAkC;MAClCC,oCAAoC,EACnCvC,sBACA;MACDwC,QAAQ,EAAGA,CAAEzB,UAAU,EAAE0B,KAAK,KAAM;QACnC,MAAMC,aAAa,GAAG3B,UAAU,IAAIL,iBAAiB;;QAErD;QACA;QACA,IAAK,CAAEgC,aAAa,IAAI,CAAE1D,KAAK,EAAE2D,IAAI,CAAC,CAAC,EAAEhB,MAAM,EAAG;UACjDc,KAAK,CAACG,cAAc,CAAC,CAAC;QACvB,CAAC,MAAM;UACN1B,oBAAoB,CACnBwB,aAAa,IAAI;YAAEnB,GAAG,EAAEvC;UAAM,CAC/B,CAAC;QACF;MACD,CAAG;MACHsB,GAAG,EAAGA,GAAK;MACXD,MAAM,EAAGA;IAAQ,CACjB,CAAC,EACApB,QAAQ;EAAA,CACN,CAAC;AAER,CACD,CAAC;AAAC,IAAA4D,QAAA,GAAAC,OAAA,CAAAjD,OAAA,GAEaf,sBAAsB;AAE9B,MAAMiE,oCAAoC,GAAKpD,KAAK,IAAM;EAChE,IAAAqD,mBAAU,EAAE,qDAAqD,EAAE;IAClEC,KAAK,EAAE;EACR,CAAE,CAAC;EAEH,oBAAO,IAAAxE,WAAA,CAAAmB,GAAA,EAACd,sBAAsB;IAAA,GAAMa;EAAK,CAAI,CAAC;AAC/C,CAAC;AAACmD,OAAA,CAAAC,oCAAA,GAAAA,oCAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_","_searchResults","_interopRequireDefault","_constants","_useSearchHandler","_deprecated","_jsxRuntime","noopSearchHandler","Promise","resolve","noop","LinkControlSearchInput","forwardRef","value","children","currentLink","className","placeholder","withCreateSuggestion","onCreateSuggestion","onChange","onSelect","showSuggestions","renderSuggestions","props","jsx","default","fetchSuggestions","allowDirectEntry","showInitialSuggestions","suggestionsQuery","withURLSuggestion","createSuggestionButtonText","hideLabelFromVision","suffix","ref","genericSearchHandler","useSearchHandler","searchHandler","focusedSuggestion","setFocusedSuggestion","useState","onInputChange","selection","suggestion","handleRenderSuggestions","handleSuggestionClick","onSuggestionSelected","selectedSuggestion","CREATE_TYPE","type","title","url","e","Object","keys","length","id","restLinkProps","jsxs","URLInput","disableSuggestions","label","__","__experimentalRenderSuggestions","__experimentalFetchLinkSuggestions","__experimentalHandleURLSuggestions","__experimentalShowInitialSuggestions","onSubmit","event","hasSuggestion","trim","preventDefault","_default","exports","__experimentalLinkControlSearchInput","deprecated","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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,CAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAF,sBAAA,CAAAJ,OAAA;AACA,IAAAO,WAAA,GAAAH,sBAAA,CAAAJ,OAAA;AAA+C,IAAAQ,WAAA,GAAAR,OAAA;AAb/C;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AACA;AACA;AACA,MAAMS,iBAAiB,GAAGA,CAAA,KAAMC,OAAO,CAACC,OAAO,CAAE,EAAG,CAAC;AAErD,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAErB,MAAMC,sBAAsB,GAAG,IAAAC,mBAAU,EACxC,CACC;EACCC,KAAK;EACLC,QAAQ;EACRC,WAAW,GAAG,CAAC,CAAC;EAChBC,SAAS,GAAG,IAAI;EAChBC,WAAW,GAAG,IAAI;EAClBC,oBAAoB,GAAG,KAAK;EAC5BC,kBAAkB,GAAGT,IAAI;EACzBU,QAAQ,GAAGV,IAAI;EACfW,QAAQ,GAAGX,IAAI;EACfY,eAAe,GAAG,IAAI;EACtBC,iBAAiB,GAAKC,KAAK,iBAC1B,IAAAlB,WAAA,CAAAmB,GAAA,EAACxB,cAAA,CAAAyB,OAAwB;IAAA,GAAMF;EAAK,CAAI,CACxC;EACDG,gBAAg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C,CAAC,EAAEf,MAAM,EAAG;UACjDa,KAAK,CAACG,cAAc,CAAC,CAAC;QACvB,CAAC,MAAM;UACNzB,oBAAoB,CACnBuB,aAAa,IAAI;YAAElB,GAAG,EAAEvC;UAAM,CAC/B,CAAC;QACF;MACD,CAAG;MACHsB,GAAG,EAAGA,GAAK;MACXD,MAAM,EAAGA;IAAQ,CACjB,CAAC,EACApB,QAAQ;EAAA,CACN,CAAC;AAER,CACD,CAAC;AAAC,IAAA2D,QAAA,GAAAC,OAAA,CAAAhD,OAAA,GAEaf,sBAAsB;AAE9B,MAAMgE,oCAAoC,GAAKnD,KAAK,IAAM;EAChE,IAAAoD,mBAAU,EAAE,qDAAqD,EAAE;IAClEC,KAAK,EAAE;EACR,CAAE,CAAC;EAEH,oBAAO,IAAAvE,WAAA,CAAAmB,GAAA,EAACd,sBAAsB;IAAA,GAAMa;EAAK,CAAI,CAAC;AAC/C,CAAC;AAACkD,OAAA,CAAAC,oCAAA,GAAAA,oCAAA","ignoreList":[]}
|
|
@@ -22,7 +22,7 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
function useTabNav() {
|
|
25
|
-
const
|
|
25
|
+
const containerRef = /** @type {typeof useRef<HTMLElement>} */(0, _element.useRef)();
|
|
26
26
|
const focusCaptureBeforeRef = (0, _element.useRef)();
|
|
27
27
|
const focusCaptureAfterRef = (0, _element.useRef)();
|
|
28
28
|
const {
|
|
@@ -42,19 +42,19 @@ function useTabNav() {
|
|
|
42
42
|
// capturing on the focus capture elements.
|
|
43
43
|
const noCaptureRef = (0, _element.useRef)();
|
|
44
44
|
function onFocusCapture(event) {
|
|
45
|
-
const canvasElement =
|
|
45
|
+
const canvasElement = containerRef.current.ownerDocument === event.target.ownerDocument ? containerRef.current : containerRef.current.ownerDocument.defaultView.frameElement;
|
|
46
46
|
|
|
47
47
|
// Do not capture incoming focus if set by us in WritingFlow.
|
|
48
48
|
if (noCaptureRef.current) {
|
|
49
49
|
noCaptureRef.current = null;
|
|
50
50
|
} else if (hasMultiSelection()) {
|
|
51
|
-
|
|
51
|
+
containerRef.current.focus();
|
|
52
52
|
} else if (getSelectedBlockClientId()) {
|
|
53
53
|
if (getLastFocus()?.current) {
|
|
54
54
|
getLastFocus().current.focus();
|
|
55
55
|
} else {
|
|
56
56
|
// Handles when the last focus has not been set yet, or has been cleared by new blocks being added via the inserter.
|
|
57
|
-
|
|
57
|
+
containerRef.current.querySelector(`[data-block="${getSelectedBlockClientId()}"]`).focus();
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
// In "compose" mode without a selected ID, we want to place focus on the section root when tabbing to the canvas.
|
|
@@ -64,11 +64,11 @@ function useTabNav() {
|
|
|
64
64
|
|
|
65
65
|
// If we have section within the section root, focus the first one.
|
|
66
66
|
if (sectionBlocks.length) {
|
|
67
|
-
|
|
67
|
+
containerRef.current.querySelector(`[data-block="${sectionBlocks[0]}"]`).focus();
|
|
68
68
|
}
|
|
69
69
|
// If we don't have any section blocks, focus the section root.
|
|
70
70
|
else if (sectionRootClientId) {
|
|
71
|
-
|
|
71
|
+
containerRef.current.querySelector(`[data-block="${sectionRootClientId}"]`).focus();
|
|
72
72
|
} else {
|
|
73
73
|
// If we don't have any section root, focus the canvas.
|
|
74
74
|
canvasElement.focus();
|
|
@@ -77,7 +77,7 @@ function useTabNav() {
|
|
|
77
77
|
const isBefore =
|
|
78
78
|
// eslint-disable-next-line no-bitwise
|
|
79
79
|
event.target.compareDocumentPosition(canvasElement) & event.target.DOCUMENT_POSITION_FOLLOWING;
|
|
80
|
-
const tabbables = _dom.focus.tabbable.find(
|
|
80
|
+
const tabbables = _dom.focus.tabbable.find(containerRef.current);
|
|
81
81
|
if (tabbables.length) {
|
|
82
82
|
const next = isBefore ? tabbables[0] : tabbables[tabbables.length - 1];
|
|
83
83
|
next.focus();
|
|
@@ -109,19 +109,26 @@ function useTabNav() {
|
|
|
109
109
|
if (event.keyCode !== _keycodes.TAB) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
112
|
+
if (
|
|
113
|
+
// Bails in case the focus capture elements aren’t present. They
|
|
114
|
+
// may be omitted to avoid silent tab stops in preview mode.
|
|
115
|
+
// See: https://github.com/WordPress/gutenberg/pull/59317
|
|
116
|
+
!focusCaptureAfterRef.current || !focusCaptureBeforeRef.current) {
|
|
113
117
|
return;
|
|
114
118
|
}
|
|
115
|
-
const
|
|
119
|
+
const {
|
|
120
|
+
target,
|
|
121
|
+
shiftKey: isShift
|
|
122
|
+
} = event;
|
|
116
123
|
const direction = isShift ? 'findPrevious' : 'findNext';
|
|
117
|
-
const nextTabbable = _dom.focus.tabbable[direction](
|
|
124
|
+
const nextTabbable = _dom.focus.tabbable[direction](target);
|
|
118
125
|
|
|
119
126
|
// We want to constrain the tabbing to the block and its child blocks.
|
|
120
127
|
// If the preceding form element is within a different block,
|
|
121
128
|
// such as two sibling image blocks in the placeholder state,
|
|
122
129
|
// we want shift + tab from the first form element to move to the image
|
|
123
130
|
// block toolbar and not the previous image block's form element.
|
|
124
|
-
const currentBlock =
|
|
131
|
+
const currentBlock = target.closest('[data-block]');
|
|
125
132
|
const isElementPartOfSelectedBlock = currentBlock && nextTabbable && ((0, _dom2.isInSameBlock)(currentBlock, nextTabbable) || (0, _dom2.isInsideRootBlock)(currentBlock, nextTabbable));
|
|
126
133
|
|
|
127
134
|
// Allow tabbing from the block wrapper to a form element,
|
|
@@ -158,7 +165,7 @@ function useTabNav() {
|
|
|
158
165
|
|
|
159
166
|
// If focus disappears due to there being no blocks, move focus to
|
|
160
167
|
// the writing flow wrapper.
|
|
161
|
-
if (!event.relatedTarget && ownerDocument.activeElement === ownerDocument.body && getBlockCount() === 0) {
|
|
168
|
+
if (!event.relatedTarget && event.target.hasAttribute('data-block') && ownerDocument.activeElement === ownerDocument.body && getBlockCount() === 0) {
|
|
162
169
|
node.focus();
|
|
163
170
|
}
|
|
164
171
|
}
|
|
@@ -178,7 +185,7 @@ function useTabNav() {
|
|
|
178
185
|
if (event.target?.getAttribute('role') === 'region') {
|
|
179
186
|
return;
|
|
180
187
|
}
|
|
181
|
-
if (
|
|
188
|
+
if (containerRef.current === event.target) {
|
|
182
189
|
return;
|
|
183
190
|
}
|
|
184
191
|
const isShift = event.shiftKey;
|
|
@@ -207,7 +214,7 @@ function useTabNav() {
|
|
|
207
214
|
node.removeEventListener('focusout', onFocusOut);
|
|
208
215
|
};
|
|
209
216
|
}, []);
|
|
210
|
-
const mergedRefs = (0, _compose.useMergeRefs)([
|
|
217
|
+
const mergedRefs = (0, _compose.useMergeRefs)([containerRef, ref]);
|
|
211
218
|
return [before, mergedRefs, after];
|
|
212
219
|
}
|
|
213
220
|
//# sourceMappingURL=use-tab-nav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dom","require","_keycodes","_data","_compose","_element","_store","_dom2","_lockUnlock","_jsxRuntime","useTabNav","container","useRef","focusCaptureBeforeRef","focusCaptureAfterRef","hasMultiSelection","getSelectedBlockClientId","getBlockCount","getBlockOrder","getLastFocus","getSectionRootClientId","isZoomOut","unlock","useSelect","blockEditorStore","setLastFocus","useDispatch","noCaptureRef","onFocusCapture","event","canvasElement","current","ownerDocument","target","defaultView","frameElement","focus","querySelector","sectionRootClientId","sectionBlocks","length","isBefore","compareDocumentPosition","DOCUMENT_POSITION_FOLLOWING","tabbables","tabbable","find","next","before","jsx","ref","tabIndex","onFocus","after","useRefEffect","node","onKeyDown","defaultPrevented","keyCode","TAB","isShift","shiftKey","direction","nextTabbable","currentBlock","closest","isElementPartOfSelectedBlock","isInSameBlock","isInsideRootBlock","isFormElement","preventScroll","onFocusOut","relatedTarget","activeElement","body","preventScrollOnTab","getAttribute","preventDefault","addEventListener","removeEventListener","mergedRefs","useMergeRefs"],"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":";;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAA2C,IAAAQ,WAAA,GAAAR,OAAA;AAd3C;AACA;AACA;;AAOA;AACA;AACA;;AAKe,SAASS,SAASA,CAAA,EAAG;EACnC,MAAMC,SAAS,GAAG,IAAAC,eAAM,EAAC,CAAC;EAC1B,MAAMC,qBAAqB,GAAG,IAAAD,eAAM,EAAC,CAAC;EACtC,MAAME,oBAAoB,GAAG,IAAAF,eAAM,EAAC,CAAC;EAErC,MAAM;IACLG,iBAAiB;IACjBC,wBAAwB;IACxBC,aAAa;IACbC,aAAa;IACbC,YAAY;IACZC,sBAAsB;IACtBC;EACD,CAAC,GAAG,IAAAC,kBAAM,EAAE,IAAAC,eAAS,EAAEC,YAAiB,CAAE,CAAC;EAC3C,MAAM;IAAEC;EAAa,CAAC,GAAG,IAAAH,kBAAM,EAAE,IAAAI,iBAAW,EAAEF,YAAiB,CAAE,CAAC;;EAElE;EACA;EACA,MAAMG,YAAY,GAA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AAG,CAAG,CAAC;EAErD,OAAO,CAAEF,MAAM,EAAEgC,UAAU,EAAE3B,KAAK,CAAE;AACrC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_dom","require","_keycodes","_data","_compose","_element","_store","_dom2","_lockUnlock","_jsxRuntime","useTabNav","containerRef","useRef","focusCaptureBeforeRef","focusCaptureAfterRef","hasMultiSelection","getSelectedBlockClientId","getBlockCount","getBlockOrder","getLastFocus","getSectionRootClientId","isZoomOut","unlock","useSelect","blockEditorStore","setLastFocus","useDispatch","noCaptureRef","onFocusCapture","event","canvasElement","current","ownerDocument","target","defaultView","frameElement","focus","querySelector","sectionRootClientId","sectionBlocks","length","isBefore","compareDocumentPosition","DOCUMENT_POSITION_FOLLOWING","tabbables","tabbable","find","next","before","jsx","ref","tabIndex","onFocus","after","useRefEffect","node","onKeyDown","defaultPrevented","keyCode","TAB","shiftKey","isShift","direction","nextTabbable","currentBlock","closest","isElementPartOfSelectedBlock","isInSameBlock","isInsideRootBlock","isFormElement","preventScroll","onFocusOut","relatedTarget","hasAttribute","activeElement","body","preventScrollOnTab","getAttribute","preventDefault","addEventListener","removeEventListener","mergedRefs","useMergeRefs"],"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":";;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAA2C,IAAAQ,WAAA,GAAAR,OAAA;AAd3C;AACA;AACA;;AAOA;AACA;AACA;;AAKe,SAASS,SAASA,CAAA,EAAG;EACnC,MAAMC,YAAY,GAAG,yCAA0C,IAAEC,eAAM,EAAG,CAAC;EAC3E,MAAMC,qBAAqB,GAAG,IAAAD,eAAM,EAAC,CAAC;EACtC,MAAME,oBAAoB,GAAG,IAAAF,eAAM,EAAC,CAAC;EAErC,MAAM;IACLG,iBAAiB;IACjBC,wBAAwB;IACxBC,aAAa;IACbC,aAAa;IACbC,YAAY;IACZC,sBAAsB;IACtBC;EACD,CAAC,GAAG,IAAAC,kBAAM,EAAE,IAAAC,eAAS,EAAEC,YAAiB,CAAE,CAAC;EAC3C,MAAM;IAAEC;EAAa,CAAC,GAAG,IAAAH,kBAAM,EAAE,IAAAI,iBAAW,EAAEF,YAAiB,CAAE,CAAC;;EAElE;EACA;EACA,MAAMG,YAAY,GAAG,IAAAf,eAAM,EAAC,CAAC;EAE7B,SAASgB,cAAcA,CAAEC,KAAK,EAAG;IAChC,MAAMC,aAAa,GAClBnB,YAAY,CAACoB,OAAO,CAACC,aAAa,KAA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,EAAE5B,KAAK,CAAE;AACrC","ignoreList":[]}
|
|
@@ -17,7 +17,7 @@ import InserterListbox from '../../inserter-listbox';
|
|
|
17
17
|
import { searchItems } from '../search-items';
|
|
18
18
|
import BlockPatternsPaging from '../../block-patterns-paging';
|
|
19
19
|
import usePatternsPaging from '../hooks/use-patterns-paging';
|
|
20
|
-
import { INSERTER_PATTERN_TYPES, allPatternsCategory, myPatternsCategory } from '../block-patterns-tab/utils';
|
|
20
|
+
import { INSERTER_PATTERN_TYPES, allPatternsCategory, myPatternsCategory, starterPatternsCategory } from '../block-patterns-tab/utils';
|
|
21
21
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
22
|
function PatternsListHeader({
|
|
23
23
|
filterValue,
|
|
@@ -57,6 +57,9 @@ function PatternList({
|
|
|
57
57
|
if (selectedCategory === myPatternsCategory.name && pattern.type === INSERTER_PATTERN_TYPES.user) {
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
|
+
if (selectedCategory === starterPatternsCategory.name && pattern.blockTypes?.includes('core/post-content')) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
60
63
|
if (selectedCategory === 'uncategorized') {
|
|
61
64
|
var _pattern$categories$s;
|
|
62
65
|
const hasKnownCategory = (_pattern$categories$s = pattern.categories?.some(category => registeredPatternCategories.includes(category))) !== null && _pattern$categories$s !== void 0 ? _pattern$categories$s : false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useEffect","useRef","useState","_n","sprintf","useDebounce","__experimentalHeading","Heading","speak","BlockPatternsList","useInsertionPoint","usePatternsState","InserterListbox","searchItems","BlockPatternsPaging","usePatternsPaging","INSERTER_PATTERN_TYPES","allPatternsCategory","myPatternsCategory","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternsListHeader","filterValue","filteredBlockPatternsLength","level","lineHeight","className","children","PatternList","searchValue","selectedCategory","patternCategories","rootClientId","onModalClose","container","debouncedSpeak","destinationRootClientId","onInsertBlocks","shouldFocusBlock","patterns","onClickPattern","registeredPatternCategories","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","type","user","_pattern$categories$s","hasKnownCategory","categories","some","category","
|
|
1
|
+
{"version":3,"names":["useMemo","useEffect","useRef","useState","_n","sprintf","useDebounce","__experimentalHeading","Heading","speak","BlockPatternsList","useInsertionPoint","usePatternsState","InserterListbox","searchItems","BlockPatternsPaging","usePatternsPaging","INSERTER_PATTERN_TYPES","allPatternsCategory","myPatternsCategory","starterPatternsCategory","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","PatternsListHeader","filterValue","filteredBlockPatternsLength","level","lineHeight","className","children","PatternList","searchValue","selectedCategory","patternCategories","rootClientId","onModalClose","container","debouncedSpeak","destinationRootClientId","onInsertBlocks","shouldFocusBlock","patterns","onClickPattern","registeredPatternCategories","map","patternCategory","name","filteredBlockPatterns","filteredPatterns","filter","pattern","type","user","blockTypes","includes","_pattern$categories$s","hasKnownCategory","categories","some","category","length","count","resultsFoundMessage","pagingProps","previousSearchValue","setPreviousSearchValue","changePage","hasItems","ref","blockPatterns","categoryPatterns","blocks","isDraggable"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-explorer/pattern-list.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useEffect, useRef, useState } from '@wordpress/element';\nimport { _n, sprintf } from '@wordpress/i18n';\nimport { useDebounce } from '@wordpress/compose';\nimport { __experimentalHeading as Heading } from '@wordpress/components';\nimport { speak } from '@wordpress/a11y';\n\n/**\n * Internal dependencies\n */\nimport BlockPatternsList from '../../block-patterns-list';\nimport useInsertionPoint from '../hooks/use-insertion-point';\nimport usePatternsState from '../hooks/use-patterns-state';\nimport InserterListbox from '../../inserter-listbox';\nimport { searchItems } from '../search-items';\nimport BlockPatternsPaging from '../../block-patterns-paging';\nimport usePatternsPaging from '../hooks/use-patterns-paging';\nimport {\n\tINSERTER_PATTERN_TYPES,\n\tallPatternsCategory,\n\tmyPatternsCategory,\n\tstarterPatternsCategory,\n} from '../block-patterns-tab/utils';\n\nfunction PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {\n\tif ( ! filterValue ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Heading\n\t\t\tlevel={ 2 }\n\t\t\tlineHeight=\"48px\"\n\t\t\tclassName=\"block-editor-block-patterns-explorer__search-results-count\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %d: number of patterns. */\n\t\t\t\t_n(\n\t\t\t\t\t'%d pattern found',\n\t\t\t\t\t'%d patterns found',\n\t\t\t\t\tfilteredBlockPatternsLength\n\t\t\t\t),\n\t\t\t\tfilteredBlockPatternsLength\n\t\t\t) }\n\t\t</Heading>\n\t);\n}\n\nfunction PatternList( {\n\tsearchValue,\n\tselectedCategory,\n\tpatternCategories,\n\trootClientId,\n\tonModalClose,\n} ) {\n\tconst container = useRef();\n\tconst debouncedSpeak = useDebounce( speak, 500 );\n\tconst [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {\n\t\trootClientId,\n\t\tshouldFocusBlock: true,\n\t} );\n\tconst [ patterns, , onClickPattern ] = usePatternsState(\n\t\tonInsertBlocks,\n\t\tdestinationRootClientId,\n\t\tselectedCategory\n\t);\n\n\tconst registeredPatternCategories = useMemo(\n\t\t() =>\n\t\t\tpatternCategories.map(\n\t\t\t\t( patternCategory ) => patternCategory.name\n\t\t\t),\n\t\t[ patternCategories ]\n\t);\n\n\tconst filteredBlockPatterns = useMemo( () => {\n\t\tconst filteredPatterns = patterns.filter( ( pattern ) => {\n\t\t\tif ( selectedCategory === allPatternsCategory.name ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tselectedCategory === myPatternsCategory.name &&\n\t\t\t\tpattern.type === INSERTER_PATTERN_TYPES.user\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tselectedCategory === starterPatternsCategory.name &&\n\t\t\t\tpattern.blockTypes?.includes( 'core/post-content' )\n\t\t\t) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif ( selectedCategory === 'uncategorized' ) {\n\t\t\t\tconst hasKnownCategory =\n\t\t\t\t\tpattern.categories?.some( ( category ) =>\n\t\t\t\t\t\tregisteredPatternCategories.includes( category )\n\t\t\t\t\t) ?? false;\n\n\t\t\t\treturn ! pattern.categories?.length || ! hasKnownCategory;\n\t\t\t}\n\n\t\t\treturn pattern.categories?.includes( selectedCategory );\n\t\t} );\n\n\t\tif ( ! searchValue ) {\n\t\t\treturn filteredPatterns;\n\t\t}\n\n\t\treturn searchItems( filteredPatterns, searchValue );\n\t}, [\n\t\tsearchValue,\n\t\tpatterns,\n\t\tselectedCategory,\n\t\tregisteredPatternCategories,\n\t] );\n\n\t// Announce search results on change.\n\tuseEffect( () => {\n\t\tif ( ! searchValue ) {\n\t\t\treturn;\n\t\t}\n\t\tconst count = filteredBlockPatterns.length;\n\t\tconst resultsFoundMessage = sprintf(\n\t\t\t/* translators: %d: number of results. */\n\t\t\t_n( '%d result found.', '%d results found.', count ),\n\t\t\tcount\n\t\t);\n\t\tdebouncedSpeak( resultsFoundMessage );\n\t}, [ searchValue, debouncedSpeak, filteredBlockPatterns.length ] );\n\n\tconst pagingProps = usePatternsPaging(\n\t\tfilteredBlockPatterns,\n\t\tselectedCategory,\n\t\tcontainer\n\t);\n\n\t// Reset page when search value changes.\n\tconst [ previousSearchValue, setPreviousSearchValue ] =\n\t\tuseState( searchValue );\n\tif ( searchValue !== previousSearchValue ) {\n\t\tsetPreviousSearchValue( searchValue );\n\t\tpagingProps.changePage( 1 );\n\t}\n\n\tconst hasItems = !! filteredBlockPatterns?.length;\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-patterns-explorer__list\"\n\t\t\tref={ container }\n\t\t>\n\t\t\t<PatternsListHeader\n\t\t\t\tfilterValue={ searchValue }\n\t\t\t\tfilteredBlockPatternsLength={ filteredBlockPatterns.length }\n\t\t\t/>\n\n\t\t\t<InserterListbox>\n\t\t\t\t{ hasItems && (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tblockPatterns={ pagingProps.categoryPatterns }\n\t\t\t\t\t\t\tonClickPattern={ ( pattern, blocks ) => {\n\t\t\t\t\t\t\t\tonClickPattern( pattern, blocks );\n\t\t\t\t\t\t\t\tonModalClose();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisDraggable={ false }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<BlockPatternsPaging { ...pagingProps } />\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</InserterListbox>\n\t\t</div>\n\t);\n}\n\nexport default PatternList;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AACzE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,WAAW,QAAQ,oBAAoB;AAChD,SAASC,qBAAqB,IAAIC,OAAO,QAAQ,uBAAuB;AACxE,SAASC,KAAK,QAAQ,iBAAiB;;AAEvC;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,2BAA2B;AACzD,OAAOC,iBAAiB,MAAM,8BAA8B;AAC5D,OAAOC,gBAAgB,MAAM,6BAA6B;AAC1D,OAAOC,eAAe,MAAM,wBAAwB;AACpD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,mBAAmB,MAAM,6BAA6B;AAC7D,OAAOC,iBAAiB,MAAM,8BAA8B;AAC5D,SACCC,sBAAsB,EACtBC,mBAAmB,EACnBC,kBAAkB,EAClBC,uBAAuB,QACjB,6BAA6B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAErC,SAASC,kBAAkBA,CAAE;EAAEC,WAAW;EAAEC;AAA4B,CAAC,EA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B,mBAAmB,EAAEC,sBAAsB,CAAE,GACpDlE,QAAQ,CAAEgC,WAAY,CAAC;EACxB,IAAKA,WAAW,KAAKiC,mBAAmB,EAAG;IAC1CC,sBAAsB,CAAElC,WAAY,CAAC;IACrCgC,WAAW,CAACG,UAAU,CAAE,CAAE,CAAC;EAC5B;EAEA,MAAMC,QAAQ,GAAG,CAAC,CAAEpB,qBAAqB,EAAEa,MAAM;EACjD,oBACCtC,KAAA;IACCM,SAAS,EAAC,4CAA4C;IACtDwC,GAAG,EAAGhC,SAAW;IAAAP,QAAA,gBAEjBX,IAAA,CAACK,kBAAkB;MAClBC,WAAW,EAAGO,WAAa;MAC3BN,2BAA2B,EAAGsB,qBAAqB,CAACa;IAAQ,CAC5D,CAAC,eAEF1C,IAAA,CAACT,eAAe;MAAAoB,QAAA,EACbsC,QAAQ,iBACT7C,KAAA,CAAAF,SAAA;QAAAS,QAAA,gBACCX,IAAA,CAACZ,iBAAiB;UACjB+D,aAAa,EAAGN,WAAW,CAACO,gBAAkB;UAC9C5B,cAAc,EAAGA,CAAEQ,OAAO,EAAEqB,MAAM,KAAM;YACvC7B,cAAc,CAAEQ,OAAO,EAAEqB,MAAO,CAAC;YACjCpC,YAAY,CAAC,CAAC;UACf,CAAG;UACHqC,WAAW,EAAG;QAAO,CACrB,CAAC,eACFtD,IAAA,CAACP,mBAAmB;UAAA,GAAMoD;QAAW,CAAI,CAAC;MAAA,CACzC;IACF,CACe,CAAC;EAAA,CACd,CAAC;AAER;AAEA,eAAejC,WAAW","ignoreList":[]}
|
|
@@ -95,17 +95,16 @@ const LinkControlSearchInput = forwardRef(({
|
|
|
95
95
|
}, suggestion);
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
const inputLabel = placeholder !== null && placeholder !== void 0 ? placeholder : __('Search or type URL');
|
|
99
98
|
return /*#__PURE__*/_jsxs("div", {
|
|
100
99
|
className: "block-editor-link-control__search-input-container",
|
|
101
100
|
children: [/*#__PURE__*/_jsx(URLInput, {
|
|
102
101
|
disableSuggestions: currentLink?.url === value,
|
|
103
|
-
label:
|
|
102
|
+
label: __('Link'),
|
|
104
103
|
hideLabelFromVision: hideLabelFromVision,
|
|
105
104
|
className: className,
|
|
106
105
|
value: value,
|
|
107
106
|
onChange: onInputChange,
|
|
108
|
-
placeholder:
|
|
107
|
+
placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : __('Search or type URL'),
|
|
109
108
|
__experimentalRenderSuggestions: showSuggestions ? handleRenderSuggestions : null,
|
|
110
109
|
__experimentalFetchLinkSuggestions: searchHandler,
|
|
111
110
|
__experimentalHandleURLSuggestions: true,
|
|
@@ -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;EACRC,WAAW,GAAG,CAAC,CAAC;EAChBC,SAAS,GAAG,IAAI;EAChBC,WAAW,GAAG,IAAI;EAClBC,oBAAoB,GAAG,KAAK;EAC5BC,kBAAkB,GAAGR,IAAI;EACzBS,QAAQ,GAAGT,IAAI;EACfU,QAAQ,GAAGV,IAAI;EACfW,eAAe,GAAG,IAAI;EACtBC,iBAAiB,GAAKC,KAAK,iBAC1BnB,IAAA,CAACL,wBAAwB;IAAA,GAAMwB;EAAK,CAAI,CACxC;EACDC,gBAAgB,GAAG,IAAI;EACvBC,gBAAgB,GAAG,IAAI;EACvBC,sBAAsB,GAAG,KAAK;EAC9BC,gBAAgB,GAAG,CAAC,CAAC;EACrBC,iBAAiB,GAAG,IAAI;EACxBC,0BAA0B;EAC1BC,mBAAmB,GAAG,KAAK;EAC3BC;AACD,CAAC,EACDC,GAAG,KACC;EACJ,MAAMC,oBAAoB,GAAGhC,gBAAgB,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AAoC,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,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,cAAc,CAAC,CAAC;QACtBrC,MAAM,CAACjC,KAAK,CAAE;UAAE+D,aAAa,EAAE;QAAK,CAAE,CAAC;MACxC;IACD;IAEA,MAAM;MAAE/B;IAAc,CAAC,GAAGoB,IAAI;IAC9B,MAAM;MAAElB;IAAY,CAAC,GAAGF,aAAa;IACrCE,WAAW,CAACqC,gBAAgB,CAAE,SAAS,EAAEH,kBAAmB,CAAC;IAC7DhB,IAAI,CAACmB,gBAAgB,CAAE,SAAS,EAAElB,SAAU,CAAC;IAC7CD,IAAI,CAACmB,gBAAgB,CAAE,UAAU,EAAEP,UAAW,CAAC;IAC/C,OAAO,MAAM;MACZ9B,WAAW,CAACsC,mBAAmB,CAAE,SAAS,EAAEJ,kBAAmB,CAAC;MAChEhB,IAAI,CAACoB,mBAAmB,CAAE,SAAS,EAAEnB,SAAU,CAAC;MAChDD,IAAI,CAACoB,mBAAmB,CAAE,UAAU,EAAER,UAAW,CAAC;IACnD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMS,UAAU,GAAGnE,YAAY,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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GoB,IAAI;IAC9B,MAAM;MAAElB;IAAY,CAAC,GAAGF,aAAa;IACrCE,WAAW,CAACsC,gBAAgB,CAAE,SAAS,EAAEH,kBAAmB,CAAC;IAC7DjB,IAAI,CAACoB,gBAAgB,CAAE,SAAS,EAAEnB,SAAU,CAAC;IAC7CD,IAAI,CAACoB,gBAAgB,CAAE,UAAU,EAAER,UAAW,CAAC;IAC/C,OAAO,MAAM;MACZ9B,WAAW,CAACuC,mBAAmB,CAAE,SAAS,EAAEJ,kBAAmB,CAAC;MAChEjB,IAAI,CAACqB,mBAAmB,CAAE,SAAS,EAAEpB,SAAU,CAAC;MAChDD,IAAI,CAACqB,mBAAmB,CAAE,UAAU,EAAET,UAAW,CAAC;IACnD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMU,UAAU,GAAGpE,YAAY,CAAE,CAAEU,YAAY,EAAEgC,GAAG,CAAG,CAAC;EAExD,OAAO,CAAED,MAAM,EAAE2B,UAAU,EAAEvB,KAAK,CAAE;AACrC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "14.14.
|
|
3
|
+
"version": "14.14.2",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "ebddb7a8df3d45e83f318436516d9b6225486703"
|
|
95
95
|
}
|
|
@@ -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
|
}
|
|
@@ -139,7 +139,7 @@ describe( 'Basic rendering', () => {
|
|
|
139
139
|
|
|
140
140
|
// Search Input UI.
|
|
141
141
|
const searchInput = screen.getByRole( 'combobox', {
|
|
142
|
-
name: '
|
|
142
|
+
name: 'Link',
|
|
143
143
|
} );
|
|
144
144
|
|
|
145
145
|
expect( searchInput ).toBeVisible();
|
|
@@ -150,7 +150,7 @@ describe( 'Basic rendering', () => {
|
|
|
150
150
|
|
|
151
151
|
// Search Input UI.
|
|
152
152
|
const searchInput = screen.getByRole( 'combobox', {
|
|
153
|
-
name: '
|
|
153
|
+
name: 'Link',
|
|
154
154
|
} );
|
|
155
155
|
|
|
156
156
|
expect( searchInput ).toBeVisible();
|
|
@@ -175,7 +175,7 @@ describe( 'Basic rendering', () => {
|
|
|
175
175
|
|
|
176
176
|
// Search Input UI.
|
|
177
177
|
const searchInput = screen.getByRole( 'combobox', {
|
|
178
|
-
name: '
|
|
178
|
+
name: 'Link',
|
|
179
179
|
} );
|
|
180
180
|
|
|
181
181
|
// Simulate searching for a term.
|
|
@@ -290,7 +290,7 @@ describe( 'Basic rendering', () => {
|
|
|
290
290
|
|
|
291
291
|
// Search Input UI.
|
|
292
292
|
const searchInput = screen.getByRole( 'combobox', {
|
|
293
|
-
name: '
|
|
293
|
+
name: 'Link',
|
|
294
294
|
} );
|
|
295
295
|
|
|
296
296
|
// Simulate searching for a term.
|
|
@@ -304,7 +304,7 @@ describe( 'Basic rendering', () => {
|
|
|
304
304
|
render( <LinkControl value={ { url: 'https://example.com' } } /> );
|
|
305
305
|
|
|
306
306
|
expect(
|
|
307
|
-
screen.queryByRole( 'combobox', { name: '
|
|
307
|
+
screen.queryByRole( 'combobox', { name: 'Link' } )
|
|
308
308
|
).not.toBeInTheDocument();
|
|
309
309
|
} );
|
|
310
310
|
|
|
@@ -317,7 +317,7 @@ describe( 'Basic rendering', () => {
|
|
|
317
317
|
);
|
|
318
318
|
|
|
319
319
|
expect(
|
|
320
|
-
screen.getByRole( 'combobox', { name: '
|
|
320
|
+
screen.getByRole( 'combobox', { name: 'Link' } )
|
|
321
321
|
).toBeVisible();
|
|
322
322
|
} );
|
|
323
323
|
|
|
@@ -335,7 +335,7 @@ describe( 'Basic rendering', () => {
|
|
|
335
335
|
await user.click( editButton );
|
|
336
336
|
|
|
337
337
|
expect(
|
|
338
|
-
screen.getByRole( 'combobox', { name: '
|
|
338
|
+
screen.getByRole( 'combobox', { name: 'Link' } )
|
|
339
339
|
).toBeVisible();
|
|
340
340
|
|
|
341
341
|
// If passed `forceIsEditingLink` of `false` while editing, should
|
|
@@ -348,7 +348,7 @@ describe( 'Basic rendering', () => {
|
|
|
348
348
|
);
|
|
349
349
|
|
|
350
350
|
expect(
|
|
351
|
-
screen.queryByRole( 'combobox', { name: '
|
|
351
|
+
screen.queryByRole( 'combobox', { name: 'Link' } )
|
|
352
352
|
).not.toBeInTheDocument();
|
|
353
353
|
} );
|
|
354
354
|
|
|
@@ -438,7 +438,7 @@ describe( 'Basic rendering', () => {
|
|
|
438
438
|
|
|
439
439
|
// Should revert back to editing mode.
|
|
440
440
|
expect(
|
|
441
|
-
screen.getByRole( 'combobox', { name: '
|
|
441
|
+
screen.getByRole( 'combobox', { name: 'Link' } )
|
|
442
442
|
).toBeVisible();
|
|
443
443
|
} );
|
|
444
444
|
} );
|
|
@@ -461,7 +461,7 @@ describe( 'Searching for a link', () => {
|
|
|
461
461
|
|
|
462
462
|
// Search Input UI.
|
|
463
463
|
const searchInput = screen.getByRole( 'combobox', {
|
|
464
|
-
name: '
|
|
464
|
+
name: 'Link',
|
|
465
465
|
} );
|
|
466
466
|
|
|
467
467
|
// Simulate searching for a term.
|
|
@@ -487,7 +487,7 @@ describe( 'Searching for a link', () => {
|
|
|
487
487
|
|
|
488
488
|
// Search Input UI.
|
|
489
489
|
const searchInput = screen.getByRole( 'combobox', {
|
|
490
|
-
name: '
|
|
490
|
+
name: 'Link',
|
|
491
491
|
} );
|
|
492
492
|
|
|
493
493
|
// Simulate searching for a term.
|
|
@@ -538,7 +538,7 @@ describe( 'Searching for a link', () => {
|
|
|
538
538
|
|
|
539
539
|
// Search Input UI.
|
|
540
540
|
const searchInput = screen.getByRole( 'combobox', {
|
|
541
|
-
name: '
|
|
541
|
+
name: 'Link',
|
|
542
542
|
} );
|
|
543
543
|
|
|
544
544
|
// Simulate searching for a term.
|
|
@@ -571,7 +571,7 @@ describe( 'Searching for a link', () => {
|
|
|
571
571
|
|
|
572
572
|
// Search Input UI.
|
|
573
573
|
const searchInput = screen.getByRole( 'combobox', {
|
|
574
|
-
name: '
|
|
574
|
+
name: 'Link',
|
|
575
575
|
} );
|
|
576
576
|
|
|
577
577
|
// Simulate searching for a term.
|
|
@@ -616,7 +616,7 @@ describe( 'Searching for a link', () => {
|
|
|
616
616
|
|
|
617
617
|
// Search Input UI.
|
|
618
618
|
const searchInput = screen.getByRole( 'combobox', {
|
|
619
|
-
name: '
|
|
619
|
+
name: 'Link',
|
|
620
620
|
} );
|
|
621
621
|
|
|
622
622
|
// Simulate searching for a term.
|
|
@@ -635,7 +635,7 @@ describe( 'Searching for a link', () => {
|
|
|
635
635
|
|
|
636
636
|
// Search Input UI.
|
|
637
637
|
const searchInput = screen.getByRole( 'combobox', {
|
|
638
|
-
name: '
|
|
638
|
+
name: 'Link',
|
|
639
639
|
} );
|
|
640
640
|
|
|
641
641
|
// Simulate searching for a term.
|
|
@@ -667,7 +667,7 @@ describe( 'Searching for a link', () => {
|
|
|
667
667
|
|
|
668
668
|
// Search Input UI.
|
|
669
669
|
const searchInput = screen.getByRole( 'combobox', {
|
|
670
|
-
name: '
|
|
670
|
+
name: 'Link',
|
|
671
671
|
} );
|
|
672
672
|
|
|
673
673
|
// Simulate searching for a term.
|
|
@@ -699,7 +699,7 @@ describe( 'Manual link entry', () => {
|
|
|
699
699
|
|
|
700
700
|
// Search Input UI.
|
|
701
701
|
const searchInput = screen.getByRole( 'combobox', {
|
|
702
|
-
name: '
|
|
702
|
+
name: 'Link',
|
|
703
703
|
} );
|
|
704
704
|
|
|
705
705
|
// Simulate searching for a term.
|
|
@@ -735,7 +735,7 @@ describe( 'Manual link entry', () => {
|
|
|
735
735
|
|
|
736
736
|
// Search Input UI.
|
|
737
737
|
const searchInput = screen.getByRole( 'combobox', {
|
|
738
|
-
name: '
|
|
738
|
+
name: 'Link',
|
|
739
739
|
} );
|
|
740
740
|
|
|
741
741
|
if ( searchString.length ) {
|
|
@@ -769,7 +769,7 @@ describe( 'Manual link entry', () => {
|
|
|
769
769
|
|
|
770
770
|
// Search Input UI.
|
|
771
771
|
const searchInput = screen.getByRole( 'combobox', {
|
|
772
|
-
name: '
|
|
772
|
+
name: 'Link',
|
|
773
773
|
} );
|
|
774
774
|
|
|
775
775
|
// Remove the existing link.
|
|
@@ -852,7 +852,7 @@ describe( 'Manual link entry', () => {
|
|
|
852
852
|
await toggleSettingsDrawer( user );
|
|
853
853
|
|
|
854
854
|
let searchInput = screen.getByRole( 'combobox', {
|
|
855
|
-
name: '
|
|
855
|
+
name: 'Link',
|
|
856
856
|
} );
|
|
857
857
|
|
|
858
858
|
let textInput = screen.getByRole( 'textbox', {
|
|
@@ -889,7 +889,7 @@ describe( 'Manual link entry', () => {
|
|
|
889
889
|
|
|
890
890
|
// Re-query the inputs as they have been replaced.
|
|
891
891
|
searchInput = screen.getByRole( 'combobox', {
|
|
892
|
-
name: '
|
|
892
|
+
name: 'Link',
|
|
893
893
|
} );
|
|
894
894
|
|
|
895
895
|
textInput = screen.getByRole( 'textbox', {
|
|
@@ -937,7 +937,7 @@ describe( 'Manual link entry', () => {
|
|
|
937
937
|
|
|
938
938
|
// Search Input UI.
|
|
939
939
|
const searchInput = screen.getByRole( 'combobox', {
|
|
940
|
-
name: '
|
|
940
|
+
name: 'Link',
|
|
941
941
|
} );
|
|
942
942
|
|
|
943
943
|
// Simulate searching for a term.
|
|
@@ -973,7 +973,7 @@ describe( 'Link submission', () => {
|
|
|
973
973
|
render( <LinkControlConsumer /> );
|
|
974
974
|
|
|
975
975
|
const searchInput = screen.getByRole( 'combobox', {
|
|
976
|
-
name: '
|
|
976
|
+
name: 'Link',
|
|
977
977
|
} );
|
|
978
978
|
|
|
979
979
|
const submitButton = screen.getByRole( 'button', {
|
|
@@ -1012,7 +1012,7 @@ describe( 'Link submission', () => {
|
|
|
1012
1012
|
render( <LinkControlConsumer /> );
|
|
1013
1013
|
|
|
1014
1014
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1015
|
-
name: '
|
|
1015
|
+
name: 'Link',
|
|
1016
1016
|
} );
|
|
1017
1017
|
|
|
1018
1018
|
const createSubmitButton = screen.queryByRole( 'button', {
|
|
@@ -1059,9 +1059,9 @@ describe( 'Default search suggestions', () => {
|
|
|
1059
1059
|
// Verify input has no value has default suggestions should only show
|
|
1060
1060
|
// when this does not have a value.
|
|
1061
1061
|
// Search Input UI.
|
|
1062
|
-
expect(
|
|
1063
|
-
|
|
1064
|
-
)
|
|
1062
|
+
expect( screen.getByRole( 'combobox', { name: 'Link' } ) ).toHaveValue(
|
|
1063
|
+
''
|
|
1064
|
+
);
|
|
1065
1065
|
|
|
1066
1066
|
// Ensure only called once as a guard against potential infinite
|
|
1067
1067
|
// re-render loop within `componentDidUpdate` calling `updateSuggestions`
|
|
@@ -1091,7 +1091,7 @@ describe( 'Default search suggestions', () => {
|
|
|
1091
1091
|
await user.click( currentLinkBtn );
|
|
1092
1092
|
|
|
1093
1093
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1094
|
-
name: '
|
|
1094
|
+
name: 'Link',
|
|
1095
1095
|
} );
|
|
1096
1096
|
|
|
1097
1097
|
// Search input is set to the URL value.
|
|
@@ -1115,7 +1115,7 @@ describe( 'Default search suggestions', () => {
|
|
|
1115
1115
|
|
|
1116
1116
|
// Search Input UI.
|
|
1117
1117
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1118
|
-
name: '
|
|
1118
|
+
name: 'Link',
|
|
1119
1119
|
} );
|
|
1120
1120
|
|
|
1121
1121
|
// Simulate searching for a term.
|
|
@@ -1155,7 +1155,7 @@ describe( 'Default search suggestions', () => {
|
|
|
1155
1155
|
render( <LinkControl showInitialSuggestions /> );
|
|
1156
1156
|
|
|
1157
1157
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1158
|
-
name: '
|
|
1158
|
+
name: 'Link',
|
|
1159
1159
|
} );
|
|
1160
1160
|
|
|
1161
1161
|
const searchResultsField = screen.queryByRole( 'listbox', {
|
|
@@ -1215,7 +1215,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1215
1215
|
|
|
1216
1216
|
// Search Input UI.
|
|
1217
1217
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1218
|
-
name: '
|
|
1218
|
+
name: 'Link',
|
|
1219
1219
|
} );
|
|
1220
1220
|
|
|
1221
1221
|
// Simulate searching for a term.
|
|
@@ -1285,7 +1285,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1285
1285
|
|
|
1286
1286
|
// Search Input UI.
|
|
1287
1287
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1288
|
-
name: '
|
|
1288
|
+
name: 'Link',
|
|
1289
1289
|
} );
|
|
1290
1290
|
|
|
1291
1291
|
// Simulate searching for a term.
|
|
@@ -1338,7 +1338,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1338
1338
|
|
|
1339
1339
|
// Search Input UI.
|
|
1340
1340
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1341
|
-
name: '
|
|
1341
|
+
name: 'Link',
|
|
1342
1342
|
} );
|
|
1343
1343
|
|
|
1344
1344
|
// Simulate searching for a term.
|
|
@@ -1385,7 +1385,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1385
1385
|
|
|
1386
1386
|
// Search Input UI.
|
|
1387
1387
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1388
|
-
name: '
|
|
1388
|
+
name: 'Link',
|
|
1389
1389
|
} );
|
|
1390
1390
|
|
|
1391
1391
|
// Simulate searching for a term.
|
|
@@ -1410,7 +1410,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1410
1410
|
|
|
1411
1411
|
// Search Input UI.
|
|
1412
1412
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1413
|
-
name: '
|
|
1413
|
+
name: 'Link',
|
|
1414
1414
|
} );
|
|
1415
1415
|
|
|
1416
1416
|
const searchResultsField = screen.queryByRole( 'listbox' );
|
|
@@ -1431,7 +1431,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1431
1431
|
|
|
1432
1432
|
// Search Input UI.
|
|
1433
1433
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1434
|
-
name: '
|
|
1434
|
+
name: 'Link',
|
|
1435
1435
|
} );
|
|
1436
1436
|
|
|
1437
1437
|
const searchResultsField = screen.queryByRole( 'listbox' );
|
|
@@ -1455,7 +1455,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1455
1455
|
|
|
1456
1456
|
// Search Input UI.
|
|
1457
1457
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1458
|
-
name: '
|
|
1458
|
+
name: 'Link',
|
|
1459
1459
|
} );
|
|
1460
1460
|
|
|
1461
1461
|
// Simulate searching for a term.
|
|
@@ -1490,7 +1490,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1490
1490
|
|
|
1491
1491
|
// Search Input UI.
|
|
1492
1492
|
searchInput = screen.getByRole( 'combobox', {
|
|
1493
|
-
name: '
|
|
1493
|
+
name: 'Link',
|
|
1494
1494
|
} );
|
|
1495
1495
|
|
|
1496
1496
|
// Simulate searching for a term.
|
|
@@ -1507,7 +1507,7 @@ describe( 'Creating Entities (eg: Posts, Pages)', () => {
|
|
|
1507
1507
|
await user.click( createButton );
|
|
1508
1508
|
|
|
1509
1509
|
searchInput = screen.getByRole( 'combobox', {
|
|
1510
|
-
name: '
|
|
1510
|
+
name: 'Link',
|
|
1511
1511
|
} );
|
|
1512
1512
|
|
|
1513
1513
|
const errorNotice = screen.getAllByText(
|
|
@@ -1586,7 +1586,7 @@ describe( 'Selecting links', () => {
|
|
|
1586
1586
|
await user.click( currentLinkBtn );
|
|
1587
1587
|
|
|
1588
1588
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1589
|
-
name: '
|
|
1589
|
+
name: 'Link',
|
|
1590
1590
|
} );
|
|
1591
1591
|
currentLinkUI = screen.queryByRole( 'group', {
|
|
1592
1592
|
name: 'Manage link',
|
|
@@ -1630,7 +1630,7 @@ describe( 'Selecting links', () => {
|
|
|
1630
1630
|
|
|
1631
1631
|
// Search Input UI.
|
|
1632
1632
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1633
|
-
name: '
|
|
1633
|
+
name: 'Link',
|
|
1634
1634
|
} );
|
|
1635
1635
|
|
|
1636
1636
|
// Simulate searching for a term.
|
|
@@ -1692,7 +1692,7 @@ describe( 'Selecting links', () => {
|
|
|
1692
1692
|
|
|
1693
1693
|
// Search Input UI.
|
|
1694
1694
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1695
|
-
name: '
|
|
1695
|
+
name: 'Link',
|
|
1696
1696
|
} );
|
|
1697
1697
|
|
|
1698
1698
|
// Simulate searching for a term.
|
|
@@ -1783,7 +1783,7 @@ describe( 'Selecting links', () => {
|
|
|
1783
1783
|
|
|
1784
1784
|
// Search Input UI.
|
|
1785
1785
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1786
|
-
name: '
|
|
1786
|
+
name: 'Link',
|
|
1787
1787
|
} );
|
|
1788
1788
|
|
|
1789
1789
|
// Step down into the search results, highlighting the first result item.
|
|
@@ -1841,7 +1841,7 @@ describe( 'Selecting links', () => {
|
|
|
1841
1841
|
|
|
1842
1842
|
// focus the search input
|
|
1843
1843
|
const searchInput = screen.getByRole( 'combobox', {
|
|
1844
|
-
name: '
|
|
1844
|
+
name: 'Link',
|
|
1845
1845
|
} );
|
|
1846
1846
|
|
|
1847
1847
|
fireEvent.focus( searchInput );
|
|
@@ -2064,7 +2064,7 @@ describe( 'Post types', () => {
|
|
|
2064
2064
|
|
|
2065
2065
|
// Search Input UI.
|
|
2066
2066
|
const searchInput = screen.getByRole( 'combobox', {
|
|
2067
|
-
name: '
|
|
2067
|
+
name: 'Link',
|
|
2068
2068
|
} );
|
|
2069
2069
|
|
|
2070
2070
|
// Simulate searching for a term.
|
|
@@ -2093,7 +2093,7 @@ describe( 'Post types', () => {
|
|
|
2093
2093
|
|
|
2094
2094
|
// Search Input UI.
|
|
2095
2095
|
const searchInput = screen.getByRole( 'combobox', {
|
|
2096
|
-
name: '
|
|
2096
|
+
name: 'Link',
|
|
2097
2097
|
} );
|
|
2098
2098
|
|
|
2099
2099
|
// Simulate searching for a term.
|
|
@@ -15,7 +15,7 @@ import { isInSameBlock, isInsideRootBlock } from '../../utils/dom';
|
|
|
15
15
|
import { unlock } from '../../lock-unlock';
|
|
16
16
|
|
|
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
|
|
|
@@ -36,21 +36,21 @@ export default function useTabNav() {
|
|
|
36
36
|
|
|
37
37
|
function onFocusCapture( event ) {
|
|
38
38
|
const canvasElement =
|
|
39
|
-
|
|
40
|
-
?
|
|
41
|
-
:
|
|
39
|
+
containerRef.current.ownerDocument === event.target.ownerDocument
|
|
40
|
+
? containerRef.current
|
|
41
|
+
: containerRef.current.ownerDocument.defaultView.frameElement;
|
|
42
42
|
|
|
43
43
|
// Do not capture incoming focus if set by us in WritingFlow.
|
|
44
44
|
if ( noCaptureRef.current ) {
|
|
45
45
|
noCaptureRef.current = null;
|
|
46
46
|
} else if ( hasMultiSelection() ) {
|
|
47
|
-
|
|
47
|
+
containerRef.current.focus();
|
|
48
48
|
} else if ( getSelectedBlockClientId() ) {
|
|
49
49
|
if ( getLastFocus()?.current ) {
|
|
50
50
|
getLastFocus().current.focus();
|
|
51
51
|
} else {
|
|
52
52
|
// Handles when the last focus has not been set yet, or has been cleared by new blocks being added via the inserter.
|
|
53
|
-
|
|
53
|
+
containerRef.current
|
|
54
54
|
.querySelector(
|
|
55
55
|
`[data-block="${ getSelectedBlockClientId() }"]`
|
|
56
56
|
)
|
|
@@ -64,13 +64,13 @@ export default function useTabNav() {
|
|
|
64
64
|
|
|
65
65
|
// If we have section within the section root, focus the first one.
|
|
66
66
|
if ( sectionBlocks.length ) {
|
|
67
|
-
|
|
67
|
+
containerRef.current
|
|
68
68
|
.querySelector( `[data-block="${ sectionBlocks[ 0 ] }"]` )
|
|
69
69
|
.focus();
|
|
70
70
|
}
|
|
71
71
|
// If we don't have any section blocks, focus the section root.
|
|
72
72
|
else if ( sectionRootClientId ) {
|
|
73
|
-
|
|
73
|
+
containerRef.current
|
|
74
74
|
.querySelector( `[data-block="${ sectionRootClientId }"]` )
|
|
75
75
|
.focus();
|
|
76
76
|
} else {
|
|
@@ -82,8 +82,7 @@ export default function useTabNav() {
|
|
|
82
82
|
// eslint-disable-next-line no-bitwise
|
|
83
83
|
event.target.compareDocumentPosition( canvasElement ) &
|
|
84
84
|
event.target.DOCUMENT_POSITION_FOLLOWING;
|
|
85
|
-
const tabbables = focus.tabbable.find(
|
|
86
|
-
|
|
85
|
+
const tabbables = focus.tabbable.find( containerRef.current );
|
|
87
86
|
if ( tabbables.length ) {
|
|
88
87
|
const next = isBefore
|
|
89
88
|
? tabbables[ 0 ]
|
|
@@ -125,20 +124,26 @@ export default function useTabNav() {
|
|
|
125
124
|
return;
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
if (
|
|
127
|
+
if (
|
|
128
|
+
// Bails in case the focus capture elements aren’t present. They
|
|
129
|
+
// may be omitted to avoid silent tab stops in preview mode.
|
|
130
|
+
// See: https://github.com/WordPress/gutenberg/pull/59317
|
|
131
|
+
! focusCaptureAfterRef.current ||
|
|
132
|
+
! focusCaptureBeforeRef.current
|
|
133
|
+
) {
|
|
129
134
|
return;
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
const isShift = event
|
|
137
|
+
const { target, shiftKey: isShift } = event;
|
|
133
138
|
const direction = isShift ? 'findPrevious' : 'findNext';
|
|
134
|
-
const nextTabbable = focus.tabbable[ direction ](
|
|
139
|
+
const nextTabbable = focus.tabbable[ direction ]( target );
|
|
135
140
|
|
|
136
141
|
// We want to constrain the tabbing to the block and its child blocks.
|
|
137
142
|
// If the preceding form element is within a different block,
|
|
138
143
|
// such as two sibling image blocks in the placeholder state,
|
|
139
144
|
// we want shift + tab from the first form element to move to the image
|
|
140
145
|
// block toolbar and not the previous image block's form element.
|
|
141
|
-
const currentBlock =
|
|
146
|
+
const currentBlock = target.closest( '[data-block]' );
|
|
142
147
|
const isElementPartOfSelectedBlock =
|
|
143
148
|
currentBlock &&
|
|
144
149
|
nextTabbable &&
|
|
@@ -157,7 +162,6 @@ export default function useTabNav() {
|
|
|
157
162
|
) {
|
|
158
163
|
return;
|
|
159
164
|
}
|
|
160
|
-
|
|
161
165
|
const next = isShift ? focusCaptureBeforeRef : focusCaptureAfterRef;
|
|
162
166
|
|
|
163
167
|
// Disable focus capturing on the focus capture element, so it
|
|
@@ -180,6 +184,7 @@ export default function useTabNav() {
|
|
|
180
184
|
// the writing flow wrapper.
|
|
181
185
|
if (
|
|
182
186
|
! event.relatedTarget &&
|
|
187
|
+
event.target.hasAttribute( 'data-block' ) &&
|
|
183
188
|
ownerDocument.activeElement === ownerDocument.body &&
|
|
184
189
|
getBlockCount() === 0
|
|
185
190
|
) {
|
|
@@ -204,7 +209,7 @@ export default function useTabNav() {
|
|
|
204
209
|
return;
|
|
205
210
|
}
|
|
206
211
|
|
|
207
|
-
if (
|
|
212
|
+
if ( containerRef.current === event.target ) {
|
|
208
213
|
return;
|
|
209
214
|
}
|
|
210
215
|
|
|
@@ -233,7 +238,7 @@ export default function useTabNav() {
|
|
|
233
238
|
};
|
|
234
239
|
}, [] );
|
|
235
240
|
|
|
236
|
-
const mergedRefs = useMergeRefs( [
|
|
241
|
+
const mergedRefs = useMergeRefs( [ containerRef, ref ] );
|
|
237
242
|
|
|
238
243
|
return [ before, mergedRefs, after ];
|
|
239
244
|
}
|