@wordpress/block-editor 9.4.0 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +1 -8
- package/build/components/block-list/block-invalid-warning.native.js +54 -6
- package/build/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build/components/block-list/block.js +2 -2
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +2 -1
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/index.native.js +4 -3
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/layout.js +20 -5
- package/build/components/block-list/layout.js.map +1 -1
- package/build/components/block-list/use-block-props/use-block-class-names.js +5 -2
- package/build/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build/components/block-lock/modal.js +35 -5
- package/build/components/block-lock/modal.js.map +1 -1
- package/build/components/block-pattern-setup/index.js +5 -17
- package/build/components/block-pattern-setup/index.js.map +1 -1
- package/build/components/block-popover/inbetween.js +1 -1
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +1 -1
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-settings-menu/block-mode-toggle.js +1 -1
- package/build/components/block-settings-menu/block-mode-toggle.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/preview.native.js +3 -1
- package/build/components/block-styles/preview.native.js.map +1 -1
- package/build/components/block-switcher/index.js +7 -1
- package/build/components/block-switcher/index.js.map +1 -1
- package/build/components/block-title/index.js +8 -2
- package/build/components/block-title/index.js.map +1 -1
- package/build/components/block-title/use-block-display-title.js +12 -5
- package/build/components/block-title/use-block-display-title.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/border-radius-control/index.js +2 -0
- package/build/components/border-radius-control/index.js.map +1 -1
- package/build/components/colors/with-colors.js +1 -1
- package/build/components/colors/with-colors.js.map +1 -1
- package/build/components/colors-gradients/control.js +45 -39
- package/build/components/colors-gradients/control.js.map +1 -1
- package/build/components/date-format-picker/index.js +1 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/iframe/index.js +19 -6
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/link-control/index.js +1 -1
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +15 -7
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +1 -1
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/media-placeholder/index.js +13 -2
- package/build/components/media-placeholder/index.js.map +1 -1
- package/build/components/media-replace-flow/index.js +3 -6
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/url-popover/index.js +2 -1
- package/build/components/url-popover/index.js.map +1 -1
- package/build/components/writing-flow/use-arrow-nav.js +34 -2
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/components/writing-flow/use-multi-selection.js +3 -47
- package/build/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +1 -3
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/color.js +2 -4
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/index.js +8 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/layout.js +41 -14
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/utils.js +5 -3
- package/build/hooks/utils.js.map +1 -1
- package/build/index.js +7 -0
- package/build/index.js.map +1 -1
- package/build/layouts/flex.js +40 -36
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +10 -35
- package/build/layouts/flow.js.map +1 -1
- package/build/layouts/utils.js +35 -3
- package/build/layouts/utils.js.map +1 -1
- package/build/store/actions.js +15 -18
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +0 -4
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +5 -3
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +3 -3
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-list/block-invalid-warning.native.js +50 -6
- package/build-module/components/block-list/block-invalid-warning.native.js.map +1 -1
- package/build-module/components/block-list/block.js +2 -2
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -1
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/index.native.js +3 -1
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/layout.js +19 -4
- package/build-module/components/block-list/layout.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-block-class-names.js +5 -2
- package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build-module/components/block-lock/modal.js +37 -6
- package/build-module/components/block-lock/modal.js.map +1 -1
- package/build-module/components/block-pattern-setup/index.js +6 -18
- package/build-module/components/block-pattern-setup/index.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +1 -1
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +1 -1
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-settings-menu/block-mode-toggle.js +1 -1
- package/build-module/components/block-settings-menu/block-mode-toggle.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/preview.native.js +3 -2
- package/build-module/components/block-styles/preview.native.js.map +1 -1
- package/build-module/components/block-switcher/index.js +7 -1
- package/build-module/components/block-switcher/index.js.map +1 -1
- package/build-module/components/block-title/index.js +8 -2
- package/build-module/components/block-title/index.js.map +1 -1
- package/build-module/components/block-title/use-block-display-title.js +12 -5
- package/build-module/components/block-title/use-block-display-title.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/border-radius-control/index.js +2 -0
- package/build-module/components/border-radius-control/index.js.map +1 -1
- package/build-module/components/colors/with-colors.js +2 -2
- package/build-module/components/colors/with-colors.js.map +1 -1
- package/build-module/components/colors-gradients/control.js +46 -40
- package/build-module/components/colors-gradients/control.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +1 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/iframe/index.js +19 -6
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -1
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +16 -8
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +1 -1
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/media-placeholder/index.js +13 -2
- package/build-module/components/media-placeholder/index.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +4 -7
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/url-popover/index.js +2 -1
- package/build-module/components/url-popover/index.js.map +1 -1
- package/build-module/components/writing-flow/use-arrow-nav.js +35 -3
- package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build-module/components/writing-flow/use-multi-selection.js +3 -45
- package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +1 -3
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/color.js +2 -3
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/layout.js +42 -15
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/utils.js +5 -2
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/flex.js +41 -33
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +11 -36
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/layouts/utils.js +33 -3
- package/build-module/layouts/utils.js.map +1 -1
- package/build-module/store/actions.js +9 -10
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +0 -4
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +5 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +4 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +36 -10
- package/build-style/style.css +36 -10
- package/package.json +28 -28
- package/src/components/block-list/block-invalid-warning.native.js +42 -7
- package/src/components/block-list/block.js +2 -2
- package/src/components/block-list/block.native.js +1 -0
- package/src/components/block-list/index.native.js +1 -1
- package/src/components/block-list/layout.js +15 -3
- package/src/components/block-list/style.scss +1 -1
- package/src/components/block-list/use-block-props/use-block-class-names.js +5 -1
- package/src/components/block-lock/modal.js +42 -4
- package/src/components/block-lock/style.scss +10 -0
- package/src/components/block-pattern-setup/index.js +3 -15
- package/src/components/block-pattern-setup/style.scss +4 -2
- package/src/components/block-popover/inbetween.js +1 -1
- package/src/components/block-popover/index.js +1 -1
- package/src/components/block-settings-menu/block-mode-toggle.js +1 -0
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/src/components/block-styles/preview.native.js +3 -2
- package/src/components/block-switcher/index.js +7 -1
- package/src/components/block-title/index.js +3 -2
- package/src/components/block-title/use-block-display-title.js +11 -5
- package/src/components/block-tools/block-contextual-toolbar.js +3 -1
- package/src/components/border-radius-control/index.js +2 -0
- package/src/components/colors/with-colors.js +2 -2
- package/src/components/colors-gradients/control.js +77 -65
- package/src/components/colors-gradients/style.scss +4 -0
- package/src/components/colors-gradients/test/control.js +16 -23
- package/src/components/date-format-picker/index.js +1 -0
- package/src/components/iframe/index.js +25 -6
- package/src/components/inserter/style.scss +1 -1
- package/src/components/link-control/index.js +1 -0
- package/src/components/link-control/test/index.js +6 -4
- package/src/components/list-view/block-select-button.js +29 -14
- package/src/components/list-view/drop-indicator.js +1 -1
- package/src/components/list-view/style.scss +18 -4
- package/src/components/media-placeholder/index.js +19 -0
- package/src/components/media-replace-flow/index.js +3 -6
- package/src/components/media-replace-flow/test/index.js +14 -4
- package/src/components/url-popover/index.js +1 -0
- package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -0
- package/src/components/writing-flow/use-arrow-nav.js +32 -1
- package/src/components/writing-flow/use-multi-selection.js +1 -48
- package/src/components/writing-flow/use-selection-observer.js +2 -3
- package/src/hooks/color.js +10 -3
- package/src/hooks/index.js +1 -0
- package/src/hooks/layout.js +46 -20
- package/src/hooks/utils.js +7 -3
- package/src/index.js +1 -0
- package/src/layouts/flex.js +47 -41
- package/src/layouts/flow.js +14 -35
- package/src/layouts/test/flex.js +21 -0
- package/src/layouts/test/flow.js +21 -0
- package/src/layouts/test/utils.js +138 -0
- package/src/layouts/utils.js +44 -3
- package/src/store/actions.js +10 -11
- package/src/store/index.js +0 -4
- package/src/store/reducer.js +3 -2
- package/src/store/selectors.js +3 -4
- package/tsconfig.json +2 -1
|
@@ -3,7 +3,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { useRef } from '@wordpress/element';
|
|
7
7
|
import { __ } from '@wordpress/i18n';
|
|
8
8
|
import { speak } from '@wordpress/a11y';
|
|
9
9
|
import { FormFileUpload, NavigableMenu, MenuItem, ToolbarButton, Dropdown, withFilters, Tooltip } from '@wordpress/components';
|
|
@@ -47,7 +47,6 @@ const MediaReplaceFlow = _ref => {
|
|
|
47
47
|
addToGallery,
|
|
48
48
|
handleUpload = true
|
|
49
49
|
} = _ref;
|
|
50
|
-
const [mediaURLValue, setMediaURLValue] = useState(mediaURL);
|
|
51
50
|
const mediaUpload = useSelect(select => {
|
|
52
51
|
return select(blockEditorStore).getSettings().mediaUpload;
|
|
53
52
|
}, []);
|
|
@@ -82,8 +81,7 @@ const MediaReplaceFlow = _ref => {
|
|
|
82
81
|
onToggleFeaturedImage();
|
|
83
82
|
}
|
|
84
83
|
|
|
85
|
-
closeMenu();
|
|
86
|
-
setMediaURLValue(media === null || media === void 0 ? void 0 : media.url); // Calling `onSelect` after the state update since it might unmount the component.
|
|
84
|
+
closeMenu(); // Calling `onSelect` after the state update since it might unmount the component.
|
|
87
85
|
|
|
88
86
|
onSelect(media);
|
|
89
87
|
speak(__('The media file has been replaced'));
|
|
@@ -194,11 +192,11 @@ const MediaReplaceFlow = _ref => {
|
|
|
194
192
|
}, createElement("span", {
|
|
195
193
|
className: "block-editor-media-replace-flow__image-url-label"
|
|
196
194
|
}, __('Current media URL:')), createElement(Tooltip, {
|
|
197
|
-
text:
|
|
195
|
+
text: mediaURL,
|
|
198
196
|
position: "bottom"
|
|
199
197
|
}, createElement("div", null, createElement(LinkControl, {
|
|
200
198
|
value: {
|
|
201
|
-
url:
|
|
199
|
+
url: mediaURL
|
|
202
200
|
},
|
|
203
201
|
settings: [],
|
|
204
202
|
showSuggestions: false,
|
|
@@ -206,7 +204,6 @@ const MediaReplaceFlow = _ref => {
|
|
|
206
204
|
let {
|
|
207
205
|
url
|
|
208
206
|
} = _ref7;
|
|
209
|
-
setMediaURLValue(url);
|
|
210
207
|
onSelectURL(url);
|
|
211
208
|
editMediaButtonRef.current.focus();
|
|
212
209
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/media-replace-flow/index.js"],"names":["useState","useRef","__","speak","FormFileUpload","NavigableMenu","MenuItem","ToolbarButton","Dropdown","withFilters","Tooltip","useSelect","withDispatch","DOWN","postFeaturedImage","upload","media","mediaIcon","compose","__unstableStripHTML","stripHTML","store","noticesStore","MediaUpload","MediaUploadCheck","LinkControl","blockEditorStore","noop","uniqueId","MediaReplaceFlow","mediaURL","mediaId","mediaIds","allowedTypes","accept","onError","onSelect","onSelectURL","onToggleFeaturedImage","useFeaturedImage","onFilesUpload","name","createNotice","removeNotice","children","multiple","addToGallery","handleUpload","mediaURLValue","setMediaURLValue","mediaUpload","select","getSettings","editMediaButtonRef","errorNoticeID","onUploadError","message","safeMessage","setTimeout","id","isDismissible","selectMedia","closeMenu","url","uploadFiles","event","files","target","filesList","onFileChange","openOnArrowDown","keyCode","preventDefault","click","onlyAllowsImages","length","every","allowedType","startsWith","gallery","POPOVER_PROPS","isAlternate","isOpen","onToggle","onClose","open","openFileDialog","current","focus","dispatch"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,QAAiC,oBAAjC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SACCC,cADD,EAECC,aAFD,EAGCC,QAHD,EAICC,aAJD,EAKCC,QALD,EAMCC,WAND,EAOCC,OAPD,QAQO,uBARP;AASA,SAASC,SAAT,EAAoBC,YAApB,QAAwC,iBAAxC;AACA,SAASC,IAAT,QAAqB,qBAArB;AACA,SACCC,iBADD,EAECC,MAFD,EAGCC,KAAK,IAAIC,SAHV,QAIO,kBAJP;AAKA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,mBAAmB,IAAIC,SAAhC,QAAiD,gBAAjD;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,SAASJ,KAAK,IAAIK,gBAAlB,QAA0C,aAA1C;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,IAAIC,QAAQ,GAAG,CAAf;;AAEA,MAAMC,gBAAgB,GAAG,QAmBlB;AAAA,MAnBoB;AAC1BC,IAAAA,QAD0B;AAE1BC,IAAAA,OAF0B;AAG1BC,IAAAA,QAH0B;AAI1BC,IAAAA,YAJ0B;AAK1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AA2BC,KAA3B;AACA;AARF,QADD,CADD,CALD,CAxDF,CADe;AAAA;AAdjB,IADD;AAiGA,CAtMD;AAwMA;AACA;AACA;;;AACA,eAAetE,OAAO,CAAE,CACvBN,YAAY,CAAI6E,QAAF,IAAgB;AAC7B,QAAM;AAAE/C,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAiC8C,QAAQ,CAAEnE,YAAF,CAA/C;AACA,SAAO;AACNoB,IAAAA,YADM;AAENC,IAAAA;AAFM,GAAP;AAIA,CANW,CADW,EAQvBlC,WAAW,CAAE,yBAAF,CARY,CAAF,CAAP,CASVoB,gBATU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport {\n\tFormFileUpload,\n\tNavigableMenu,\n\tMenuItem,\n\tToolbarButton,\n\tDropdown,\n\twithFilters,\n\tTooltip,\n} from '@wordpress/components';\nimport { useSelect, withDispatch } from '@wordpress/data';\nimport { DOWN } from '@wordpress/keycodes';\nimport {\n\tpostFeaturedImage,\n\tupload,\n\tmedia as mediaIcon,\n} from '@wordpress/icons';\nimport { compose } from '@wordpress/compose';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport MediaUpload from '../media-upload';\nimport MediaUploadCheck from '../media-upload/check';\nimport LinkControl from '../link-control';\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\nlet uniqueId = 0;\n\nconst MediaReplaceFlow = ( {\n\tmediaURL,\n\tmediaId,\n\tmediaIds,\n\tallowedTypes,\n\taccept,\n\tonError,\n\tonSelect,\n\tonSelectURL,\n\tonToggleFeaturedImage,\n\tuseFeaturedImage,\n\tonFilesUpload = noop,\n\tname = __( 'Replace' ),\n\tcreateNotice,\n\tremoveNotice,\n\tchildren,\n\tmultiple = false,\n\taddToGallery,\n\thandleUpload = true,\n} ) => {\n\tconst [ mediaURLValue, setMediaURLValue ] = useState( mediaURL );\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst editMediaButtonRef = useRef();\n\tconst errorNoticeID = `block-editor/media-replace-flow/error-notice/${ ++uniqueId }`;\n\n\tconst onUploadError = ( message ) => {\n\t\tconst safeMessage = stripHTML( message );\n\t\tif ( onError ) {\n\t\t\tonError( safeMessage );\n\t\t\treturn;\n\t\t}\n\t\t// We need to set a timeout for showing the notice\n\t\t// so that VoiceOver and possibly other screen readers\n\t\t// can announce the error afer the toolbar button\n\t\t// regains focus once the upload dialog closes.\n\t\t// Otherwise VO simply skips over the notice and announces\n\t\t// the focused element and the open menu.\n\t\tsetTimeout( () => {\n\t\t\tcreateNotice( 'error', safeMessage, {\n\t\t\t\tspeak: true,\n\t\t\t\tid: errorNoticeID,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}, 1000 );\n\t};\n\n\tconst selectMedia = ( media, closeMenu ) => {\n\t\tif ( useFeaturedImage && onToggleFeaturedImage ) {\n\t\t\tonToggleFeaturedImage();\n\t\t}\n\t\tcloseMenu();\n\t\tsetMediaURLValue( media?.url );\n\t\t// Calling `onSelect` after the state update since it might unmount the component.\n\t\tonSelect( media );\n\t\tspeak( __( 'The media file has been replaced' ) );\n\t\tremoveNotice( errorNoticeID );\n\t};\n\n\tconst uploadFiles = ( event, closeMenu ) => {\n\t\tconst files = event.target.files;\n\t\tif ( ! handleUpload ) {\n\t\t\tcloseMenu();\n\t\t\treturn onSelect( files );\n\t\t}\n\t\tonFilesUpload( files );\n\t\tmediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tfilesList: files,\n\t\t\tonFileChange: ( [ media ] ) => {\n\t\t\t\tselectMedia( media, closeMenu );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst openOnArrowDown = ( event ) => {\n\t\tif ( event.keyCode === DOWN ) {\n\t\t\tevent.preventDefault();\n\t\t\tevent.target.click();\n\t\t}\n\t};\n\n\tconst onlyAllowsImages = () => {\n\t\tif ( ! allowedTypes || allowedTypes.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn allowedTypes.every(\n\t\t\t( allowedType ) =>\n\t\t\t\tallowedType === 'image' || allowedType.startsWith( 'image/' )\n\t\t);\n\t};\n\n\tconst gallery = multiple && onlyAllowsImages();\n\n\tconst POPOVER_PROPS = {\n\t\tisAlternate: true,\n\t};\n\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tcontentClassName=\"block-editor-media-replace-flow__options\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tref={ editMediaButtonRef }\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tonKeyDown={ openOnArrowDown }\n\t\t\t\t>\n\t\t\t\t\t{ name }\n\t\t\t\t</ToolbarButton>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<NavigableMenu className=\"block-editor-media-replace-flow__media-upload-menu\">\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\t\tgallery={ gallery }\n\t\t\t\t\t\t\t\taddToGallery={ addToGallery }\n\t\t\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t\t\t\tvalue={ multiple ? mediaIds : mediaId }\n\t\t\t\t\t\t\t\tonSelect={ ( media ) =>\n\t\t\t\t\t\t\t\t\tselectMedia( media, onClose )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={ mediaIcon }\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Open Media Library' ) }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\t\t\t\tonChange={ ( event ) => {\n\t\t\t\t\t\t\t\t\t\tuploadFiles( event, onClose );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t\t\t\t\trender={ ( { openFileDialog } ) => {\n\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\ticon={ upload }\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\t\topenFileDialog();\n\t\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t\t\t</>\n\t\t\t\t\t\t{ onToggleFeaturedImage && (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ postFeaturedImage }\n\t\t\t\t\t\t\t\tonClick={ onToggleFeaturedImage }\n\t\t\t\t\t\t\t\tisPressed={ useFeaturedImage }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Use featured image' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t{ onSelectURL && (\n\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n\t\t\t\t\t\t<form className=\"block-editor-media-flow__url-input\">\n\t\t\t\t\t\t\t<span className=\"block-editor-media-replace-flow__image-url-label\">\n\t\t\t\t\t\t\t\t{ __( 'Current media URL:' ) }\n\t\t\t\t\t\t\t</span>\n\n\t\t\t\t\t\t\t<Tooltip text={ mediaURLValue } position=\"bottom\">\n\t\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t\t<LinkControl\n\t\t\t\t\t\t\t\t\t\tvalue={ { url: mediaURLValue } }\n\t\t\t\t\t\t\t\t\t\tsettings={ [] }\n\t\t\t\t\t\t\t\t\t\tshowSuggestions={ false }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( { url } ) => {\n\t\t\t\t\t\t\t\t\t\t\tsetMediaURLValue( url );\n\t\t\t\t\t\t\t\t\t\t\tonSelectURL( url );\n\t\t\t\t\t\t\t\t\t\t\teditMediaButtonRef.current.focus();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t/>\n\t);\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/media-replace-flow/README.md\n */\nexport default compose( [\n\twithDispatch( ( dispatch ) => {\n\t\tconst { createNotice, removeNotice } = dispatch( noticesStore );\n\t\treturn {\n\t\t\tcreateNotice,\n\t\t\tremoveNotice,\n\t\t};\n\t} ),\n\twithFilters( 'editor.MediaReplaceFlow' ),\n] )( MediaReplaceFlow );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/media-replace-flow/index.js"],"names":["useRef","__","speak","FormFileUpload","NavigableMenu","MenuItem","ToolbarButton","Dropdown","withFilters","Tooltip","useSelect","withDispatch","DOWN","postFeaturedImage","upload","media","mediaIcon","compose","__unstableStripHTML","stripHTML","store","noticesStore","MediaUpload","MediaUploadCheck","LinkControl","blockEditorStore","noop","uniqueId","MediaReplaceFlow","mediaURL","mediaId","mediaIds","allowedTypes","accept","onError","onSelect","onSelectURL","onToggleFeaturedImage","useFeaturedImage","onFilesUpload","name","createNotice","removeNotice","children","multiple","addToGallery","handleUpload","mediaUpload","select","getSettings","editMediaButtonRef","errorNoticeID","onUploadError","message","safeMessage","setTimeout","id","isDismissible","selectMedia","closeMenu","uploadFiles","event","files","target","filesList","onFileChange","openOnArrowDown","keyCode","preventDefault","click","onlyAllowsImages","length","every","allowedType","startsWith","gallery","POPOVER_PROPS","isAlternate","isOpen","onToggle","onClose","open","openFileDialog","url","current","focus","dispatch"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SACCC,cADD,EAECC,aAFD,EAGCC,QAHD,EAICC,aAJD,EAKCC,QALD,EAMCC,WAND,EAOCC,OAPD,QAQO,uBARP;AASA,SAASC,SAAT,EAAoBC,YAApB,QAAwC,iBAAxC;AACA,SAASC,IAAT,QAAqB,qBAArB;AACA,SACCC,iBADD,EAECC,MAFD,EAGCC,KAAK,IAAIC,SAHV,QAIO,kBAJP;AAKA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,mBAAmB,IAAIC,SAAhC,QAAiD,gBAAjD;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,OAAOC,gBAAP,MAA6B,uBAA7B;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,SAASJ,KAAK,IAAIK,gBAAlB,QAA0C,aAA1C;;AAEA,MAAMC,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2BC,KAA3B;AACA;AAPF,QADD,CADD,CALD,CAxDF,CADe;AAAA;AAdjB,IADD;AAgGA,CAnMD;AAqMA;AACA;AACA;;;AACA,eAAepE,OAAO,CAAE,CACvBN,YAAY,CAAI2E,QAAF,IAAgB;AAC7B,QAAM;AAAE7C,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAAiC4C,QAAQ,CAAEjE,YAAF,CAA/C;AACA,SAAO;AACNoB,IAAAA,YADM;AAENC,IAAAA;AAFM,GAAP;AAIA,CANW,CADW,EAQvBlC,WAAW,CAAE,yBAAF,CARY,CAAF,CAAP,CASVoB,gBATU,CAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport {\n\tFormFileUpload,\n\tNavigableMenu,\n\tMenuItem,\n\tToolbarButton,\n\tDropdown,\n\twithFilters,\n\tTooltip,\n} from '@wordpress/components';\nimport { useSelect, withDispatch } from '@wordpress/data';\nimport { DOWN } from '@wordpress/keycodes';\nimport {\n\tpostFeaturedImage,\n\tupload,\n\tmedia as mediaIcon,\n} from '@wordpress/icons';\nimport { compose } from '@wordpress/compose';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport MediaUpload from '../media-upload';\nimport MediaUploadCheck from '../media-upload/check';\nimport LinkControl from '../link-control';\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\nlet uniqueId = 0;\n\nconst MediaReplaceFlow = ( {\n\tmediaURL,\n\tmediaId,\n\tmediaIds,\n\tallowedTypes,\n\taccept,\n\tonError,\n\tonSelect,\n\tonSelectURL,\n\tonToggleFeaturedImage,\n\tuseFeaturedImage,\n\tonFilesUpload = noop,\n\tname = __( 'Replace' ),\n\tcreateNotice,\n\tremoveNotice,\n\tchildren,\n\tmultiple = false,\n\taddToGallery,\n\thandleUpload = true,\n} ) => {\n\tconst mediaUpload = useSelect( ( select ) => {\n\t\treturn select( blockEditorStore ).getSettings().mediaUpload;\n\t}, [] );\n\tconst editMediaButtonRef = useRef();\n\tconst errorNoticeID = `block-editor/media-replace-flow/error-notice/${ ++uniqueId }`;\n\n\tconst onUploadError = ( message ) => {\n\t\tconst safeMessage = stripHTML( message );\n\t\tif ( onError ) {\n\t\t\tonError( safeMessage );\n\t\t\treturn;\n\t\t}\n\t\t// We need to set a timeout for showing the notice\n\t\t// so that VoiceOver and possibly other screen readers\n\t\t// can announce the error afer the toolbar button\n\t\t// regains focus once the upload dialog closes.\n\t\t// Otherwise VO simply skips over the notice and announces\n\t\t// the focused element and the open menu.\n\t\tsetTimeout( () => {\n\t\t\tcreateNotice( 'error', safeMessage, {\n\t\t\t\tspeak: true,\n\t\t\t\tid: errorNoticeID,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}, 1000 );\n\t};\n\n\tconst selectMedia = ( media, closeMenu ) => {\n\t\tif ( useFeaturedImage && onToggleFeaturedImage ) {\n\t\t\tonToggleFeaturedImage();\n\t\t}\n\t\tcloseMenu();\n\t\t// Calling `onSelect` after the state update since it might unmount the component.\n\t\tonSelect( media );\n\t\tspeak( __( 'The media file has been replaced' ) );\n\t\tremoveNotice( errorNoticeID );\n\t};\n\n\tconst uploadFiles = ( event, closeMenu ) => {\n\t\tconst files = event.target.files;\n\t\tif ( ! handleUpload ) {\n\t\t\tcloseMenu();\n\t\t\treturn onSelect( files );\n\t\t}\n\t\tonFilesUpload( files );\n\t\tmediaUpload( {\n\t\t\tallowedTypes,\n\t\t\tfilesList: files,\n\t\t\tonFileChange: ( [ media ] ) => {\n\t\t\t\tselectMedia( media, closeMenu );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst openOnArrowDown = ( event ) => {\n\t\tif ( event.keyCode === DOWN ) {\n\t\t\tevent.preventDefault();\n\t\t\tevent.target.click();\n\t\t}\n\t};\n\n\tconst onlyAllowsImages = () => {\n\t\tif ( ! allowedTypes || allowedTypes.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn allowedTypes.every(\n\t\t\t( allowedType ) =>\n\t\t\t\tallowedType === 'image' || allowedType.startsWith( 'image/' )\n\t\t);\n\t};\n\n\tconst gallery = multiple && onlyAllowsImages();\n\n\tconst POPOVER_PROPS = {\n\t\tisAlternate: true,\n\t};\n\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\tcontentClassName=\"block-editor-media-replace-flow__options\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tref={ editMediaButtonRef }\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\taria-haspopup=\"true\"\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tonKeyDown={ openOnArrowDown }\n\t\t\t\t>\n\t\t\t\t\t{ name }\n\t\t\t\t</ToolbarButton>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<NavigableMenu className=\"block-editor-media-replace-flow__media-upload-menu\">\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\t\tgallery={ gallery }\n\t\t\t\t\t\t\t\taddToGallery={ addToGallery }\n\t\t\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t\t\t\tvalue={ multiple ? mediaIds : mediaId }\n\t\t\t\t\t\t\t\tonSelect={ ( media ) =>\n\t\t\t\t\t\t\t\t\tselectMedia( media, onClose )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tallowedTypes={ allowedTypes }\n\t\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={ mediaIcon }\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Open Media Library' ) }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t\t\t<FormFileUpload\n\t\t\t\t\t\t\t\t\tonChange={ ( event ) => {\n\t\t\t\t\t\t\t\t\t\tuploadFiles( event, onClose );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\taccept={ accept }\n\t\t\t\t\t\t\t\t\tmultiple={ multiple }\n\t\t\t\t\t\t\t\t\trender={ ( { openFileDialog } ) => {\n\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\ticon={ upload }\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\t\topenFileDialog();\n\t\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ __( 'Upload' ) }\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t\t\t</>\n\t\t\t\t\t\t{ onToggleFeaturedImage && (\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ postFeaturedImage }\n\t\t\t\t\t\t\t\tonClick={ onToggleFeaturedImage }\n\t\t\t\t\t\t\t\tisPressed={ useFeaturedImage }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Use featured image' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t{ onSelectURL && (\n\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions\n\t\t\t\t\t\t<form className=\"block-editor-media-flow__url-input\">\n\t\t\t\t\t\t\t<span className=\"block-editor-media-replace-flow__image-url-label\">\n\t\t\t\t\t\t\t\t{ __( 'Current media URL:' ) }\n\t\t\t\t\t\t\t</span>\n\n\t\t\t\t\t\t\t<Tooltip text={ mediaURL } position=\"bottom\">\n\t\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t\t<LinkControl\n\t\t\t\t\t\t\t\t\t\tvalue={ { url: mediaURL } }\n\t\t\t\t\t\t\t\t\t\tsettings={ [] }\n\t\t\t\t\t\t\t\t\t\tshowSuggestions={ false }\n\t\t\t\t\t\t\t\t\t\tonChange={ ( { url } ) => {\n\t\t\t\t\t\t\t\t\t\t\tonSelectURL( url );\n\t\t\t\t\t\t\t\t\t\t\teditMediaButtonRef.current.focus();\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t/>\n\t);\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/media-replace-flow/README.md\n */\nexport default compose( [\n\twithDispatch( ( dispatch ) => {\n\t\tconst { createNotice, removeNotice } = dispatch( noticesStore );\n\t\treturn {\n\t\t\tcreateNotice,\n\t\t\tremoveNotice,\n\t\t};\n\t} ),\n\twithFilters( 'editor.MediaReplaceFlow' ),\n] )( MediaReplaceFlow );\n"]}
|
|
@@ -34,7 +34,8 @@ function URLPopover(_ref) {
|
|
|
34
34
|
return createElement(Popover, _extends({
|
|
35
35
|
className: "block-editor-url-popover",
|
|
36
36
|
focusOnMount: focusOnMount,
|
|
37
|
-
position: position
|
|
37
|
+
position: position,
|
|
38
|
+
__unstableShift: true
|
|
38
39
|
}, popoverProps), createElement("div", {
|
|
39
40
|
className: "block-editor-url-popover__input-container"
|
|
40
41
|
}, createElement("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/index.js"],"names":["__","useState","Button","Popover","chevronDown","LinkViewer","LinkEditor","URLPopover","additionalControls","children","renderSettings","position","focusOnMount","popoverProps","isSettingsExpanded","setIsSettingsExpanded","showSettings","toggleSettingsVisibility"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,MAAT,EAAiBC,OAAjB,QAAgC,uBAAhC;AACA,SAASC,WAAT,QAA4B,kBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,eAAvB;AACA,OAAOC,UAAP,MAAuB,eAAvB;;AAEA,SAASC,UAAT,OAOI;AAAA,MAPiB;AACpBC,IAAAA,kBADoB;AAEpBC,IAAAA,QAFoB;AAGpBC,IAAAA,cAHoB;AAIpBC,IAAAA,QAAQ,GAAG,eAJS;AAKpBC,IAAAA,YAAY,GAAG,cALK;AAMpB,OAAGC;AANiB,GAOjB;AACH,QAAM,CAAEC,kBAAF,EAAsBC,qBAAtB,IAAgDd,QAAQ,CAAE,KAAF,CAA9D;AAEA,QAAMe,YAAY,GAAG,CAAC,CAAEN,cAAH,IAAqBI,kBAA1C;;AAEA,QAAMG,wBAAwB,GAAG,MAAM;AACtCF,IAAAA,qBAAqB,CAAE,CAAED,kBAAJ,CAArB;AACA,GAFD;;AAIA,SACC,cAAC,OAAD;AACC,IAAA,SAAS,EAAC,0BADX;AAEC,IAAA,YAAY,EAAGF,YAFhB;AAGC,IAAA,QAAQ,EAAGD;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/index.js"],"names":["__","useState","Button","Popover","chevronDown","LinkViewer","LinkEditor","URLPopover","additionalControls","children","renderSettings","position","focusOnMount","popoverProps","isSettings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f,KACGN,cAAc,EADjB,CAdF,CAPD,EA0BGF,kBAAkB,IAAI,CAAEQ,YAAxB,IACD;AAAK,IAAA,SAAS,EAAC;AAAf,KACGR,kBADH,CA3BF,CADD;AAkCA;;AAEDD,UAAU,CAACD,UAAX,GAAwBA,UAAxB;AAEAC,UAAU,CAACF,UAAX,GAAwBA,UAAxB;AAEA;AACA;AACA;;AACA,eAAeE,UAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { Button, Popover } from '@wordpress/components';\nimport { chevronDown } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport LinkViewer from './link-viewer';\nimport LinkEditor from './link-editor';\n\nfunction URLPopover( {\n\tadditionalControls,\n\tchildren,\n\trenderSettings,\n\tposition = 'bottom center',\n\tfocusOnMount = 'firstElement',\n\t...popoverProps\n} ) {\n\tconst [ isSettingsExpanded, setIsSettingsExpanded ] = useState( false );\n\n\tconst showSettings = !! renderSettings && isSettingsExpanded;\n\n\tconst toggleSettingsVisibility = () => {\n\t\tsetIsSettingsExpanded( ! isSettingsExpanded );\n\t};\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-url-popover\"\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tposition={ position }\n\t\t\t__unstableShift\n\t\t\t{ ...popoverProps }\n\t\t>\n\t\t\t<div className=\"block-editor-url-popover__input-container\">\n\t\t\t\t<div className=\"block-editor-url-popover__row\">\n\t\t\t\t\t{ children }\n\t\t\t\t\t{ !! renderSettings && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"block-editor-url-popover__settings-toggle\"\n\t\t\t\t\t\t\ticon={ chevronDown }\n\t\t\t\t\t\t\tlabel={ __( 'Link settings' ) }\n\t\t\t\t\t\t\tonClick={ toggleSettingsVisibility }\n\t\t\t\t\t\t\taria-expanded={ isSettingsExpanded }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ showSettings && (\n\t\t\t\t\t<div className=\"block-editor-url-popover__row block-editor-url-popover__settings\">\n\t\t\t\t\t\t{ renderSettings() }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ additionalControls && ! showSettings && (\n\t\t\t\t<div className=\"block-editor-url-popover__additional-controls\">\n\t\t\t\t\t{ additionalControls }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nURLPopover.LinkEditor = LinkEditor;\n\nURLPopover.LinkViewer = LinkViewer;\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-popover/README.md\n */\nexport default URLPopover;\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { computeCaretRect, focus, isHorizontalEdge, isVerticalEdge, placeCaretAtHorizontalEdge, placeCaretAtVerticalEdge, isRTL } from '@wordpress/dom';
|
|
5
5
|
import { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';
|
|
6
|
-
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
7
7
|
import { useRefEffect } from '@wordpress/compose';
|
|
8
8
|
/**
|
|
9
9
|
* Internal dependencies
|
|
@@ -102,12 +102,17 @@ export function getClosestTabbable(target, isReverse, containerElement, onlyVert
|
|
|
102
102
|
export default function useArrowNav() {
|
|
103
103
|
const {
|
|
104
104
|
getSelectedBlockClientId,
|
|
105
|
+
getMultiSelectedBlocksStartClientId,
|
|
105
106
|
getMultiSelectedBlocksEndClientId,
|
|
106
107
|
getPreviousBlockClientId,
|
|
107
108
|
getNextBlockClientId,
|
|
108
109
|
getSettings,
|
|
109
|
-
hasMultiSelection
|
|
110
|
+
hasMultiSelection,
|
|
111
|
+
__unstableIsFullySelected
|
|
110
112
|
} = useSelect(blockEditorStore);
|
|
113
|
+
const {
|
|
114
|
+
selectBlock
|
|
115
|
+
} = useDispatch(blockEditorStore);
|
|
111
116
|
return useRefEffect(node => {
|
|
112
117
|
// Here a DOMRect is stored while moving the caret vertically so
|
|
113
118
|
// vertical position of the start position can be restored. This is to
|
|
@@ -156,9 +161,36 @@ export default function useArrowNav() {
|
|
|
156
161
|
} = node;
|
|
157
162
|
const {
|
|
158
163
|
defaultView
|
|
159
|
-
} = ownerDocument;
|
|
164
|
+
} = ownerDocument; // If there is a multi-selection, the arrow keys should collapse the
|
|
165
|
+
// selection to the start or end of the selection.
|
|
160
166
|
|
|
161
167
|
if (hasMultiSelection()) {
|
|
168
|
+
// Only handle if we have a full selection (not a native partial
|
|
169
|
+
// selection).
|
|
170
|
+
if (!__unstableIsFullySelected()) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (event.defaultPrevented) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!isNav) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isShift) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
|
|
188
|
+
if (isReverse) {
|
|
189
|
+
selectBlock(getMultiSelectedBlocksStartClientId());
|
|
190
|
+
} else {
|
|
191
|
+
selectBlock(getMultiSelectedBlocksEndClientId(), -1);
|
|
192
|
+
}
|
|
193
|
+
|
|
162
194
|
return;
|
|
163
195
|
} // When presing any key other than up or down, the initial vertical
|
|
164
196
|
// position must ALWAYS be reset. The vertical position is saved so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useSelect","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","simpleInputTypes","includes","getAttribute","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","find","reverse","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","defaultPrevented","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","preventDefault","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAAU,GAAGF,OAAO,KAAKX,EAAZ,IAAkBW,OAAO,KAAKV,IAAjD,CADsE,CAGtE;;AACA,MAAKY,UAAU,IAAI,CAAED,WAArB,EAAmC;AAClC,WAAO,IAAP;AACA;;AAED,QAAM;AAAEE,IAAAA;AAAF,MAAcJ,OAApB,CARsE,CAUtE;;AACA,MAAK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B,EAAkC1B,SAAlC;AACA,WAAO,MAAM;AACZnB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,WAA1B,EAAuC9B,WAAvC;AACAhB,MAAAA,IAAI,CAAC8C,mBAAL,CAA0B,SAA1B,EAAqC3B,SAArC;AACA,KAHD;AAIA,GAvJkB,EAuJhB,EAvJgB,CAAnB;AAwJA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\tconst { tagName } = element;\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( element.getAttribute( 'type' ) );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes.reverse();\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t} = useSelect( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId =\n\t\t\t\t\tgetMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-arrow-nav.js"],"names":["computeCaretRect","focus","isHorizontalEdge","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","isRTL","UP","DOWN","LEFT","RIGHT","useDispatch","useSelect","useRefEffect","isInSameBlock","store","blockEditorStore","isNavigationCandidate","element","keyCode","hasModifier","isVertical","tagName","simpleInputTypes","includes","getAttribute","getClosestTabbable","target","isReverse","containerElement","onlyVertical","focusableNodes","focusable","find","reverse","slice","indexOf","targetRect","getBoundingClientRect","isTabCandidate","node","tabbable","isTabbableIndex","isContentEditable","contentEditable","nodeRect","left","right","useArrowNav","getSelectedBlockClientId","getMultiSelectedBlocksStartClientId","getMultiSelectedBlocksEndClientId","getPreviousBlockClientId","getNextBlockClientId","getSettings","hasMultiSelection","__unstableIsFullySelected","selectBlock","verticalRect","onMouseDown","isTabbableEdge","closestTabbable","onKeyDown","event","isUp","isDown","isLeft","isRight","isHorizontal","isNav","isShift","shiftKey","ctrlKey","altKey","metaKey","isNavEdge","ownerDocument","defaultView","defaultPrevented","preventDefault","isReverseDir","keepCaretInsideBlock","selectedBlockClientId","selectionEndClientId","selectionBeforeEndClientId","selectionAfterEndClientId","getSelection","isCollapsed","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,gBADD,EAECC,KAFD,EAGCC,gBAHD,EAICC,cAJD,EAKCC,0BALD,EAMCC,wBAND,EAOCC,KAPD,QAQO,gBARP;AASA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,KAAzB,QAAsC,qBAAtC;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,qBAAT,CAAgCC,OAAhC,EAAyCC,OAAzC,EAAkDC,WAAlD,EAAgE;AACtE,QAAMC,UAA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AAEqD,oBAHI,EAIL;AACD,cAAMpB,eAAe,GAAGnC,kBAAkB,CACzCC,MADyC,EAEzCC,SAFyC,EAGzCY,IAHyC,EAIzC,IAJyC,CAA1C;;AAOA,YAAKqB,eAAL,EAAuB;AACtBxD,UAAAA,wBAAwB,CACvBwD,eADuB,EAEvBjC,SAFuB,EAGvB8B,YAHuB,CAAxB;AAKAK,UAAAA,KAAK,CAACgB,cAAN;AACA;AACD,OApBM,MAoBA,IACNX,YAAY,IACZS,WAAW,CAACS,YAAZ,GAA2BC,WAD3B,IAEArF,gBAAgB,CAAEyB,MAAF,EAAUqD,YAAV,CAFhB,IAGA,CAAEC,oBAJI,EAKL;AACD,cAAMpB,eAAe,GAAGnC,kBAAkB,CACzCC,MADyC,EAEzCqD,YAFyC,EAGzCxC,IAHyC,CAA1C;AAKApC,QAAAA,0BAA0B,CAAEyD,eAAF,EAAmBjC,SAAnB,CAA1B;AACAmC,QAAAA,KAAK,CAACgB,cAAN;AACA;AACD;;AAEDvC,IAAAA,IAAI,CAACgD,gBAAL,CAAuB,WAAvB,EAAoC7B,WAApC;AACAnB,IAAAA,IAAI,CAACgD,gBAAL,CAAuB,SAAvB,EAAkC1B,SAAlC;AACA,WAAO,MAAM;AACZtB,MAAAA,IAAI,CAACiD,mBAAL,CAA0B,WAA1B,EAAuC9B,WAAvC;AACAnB,MAAAA,IAAI,CAACiD,mBAAL,CAA0B,SAA1B,EAAqC3B,SAArC;AACA,KAHD;AAIA,GAnLkB,EAmLhB,EAnLgB,CAAnB;AAoLA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcomputeCaretRect,\n\tfocus,\n\tisHorizontalEdge,\n\tisVerticalEdge,\n\tplaceCaretAtHorizontalEdge,\n\tplaceCaretAtVerticalEdge,\n\tisRTL,\n} from '@wordpress/dom';\nimport { UP, DOWN, LEFT, RIGHT } from '@wordpress/keycodes';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { isInSameBlock } from '../../utils/dom';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Returns true if the element should consider edge navigation upon a keyboard\n * event of the given directional key code, or false otherwise.\n *\n * @param {Element} element HTML element to test.\n * @param {number} keyCode KeyboardEvent keyCode to test.\n * @param {boolean} hasModifier Whether a modifier is pressed.\n *\n * @return {boolean} Whether element should consider edge navigation.\n */\nexport function isNavigationCandidate( element, keyCode, hasModifier ) {\n\tconst isVertical = keyCode === UP || keyCode === DOWN;\n\n\t// Currently, all elements support unmodified vertical navigation.\n\tif ( isVertical && ! hasModifier ) {\n\t\treturn true;\n\t}\n\n\tconst { tagName } = element;\n\n\t// Native inputs should not navigate horizontally, unless they are simple types that don't need left/right arrow keys.\n\tif ( tagName === 'INPUT' ) {\n\t\tconst simpleInputTypes = [\n\t\t\t'button',\n\t\t\t'checkbox',\n\t\t\t'color',\n\t\t\t'file',\n\t\t\t'image',\n\t\t\t'radio',\n\t\t\t'reset',\n\t\t\t'submit',\n\t\t];\n\t\treturn simpleInputTypes.includes( element.getAttribute( 'type' ) );\n\t}\n\n\t// Native textareas should not navigate horizontally.\n\treturn tagName !== 'TEXTAREA';\n}\n\n/**\n * Returns the optimal tab target from the given focused element in the desired\n * direction. A preference is made toward text fields, falling back to the block\n * focus stop if no other candidates exist for the block.\n *\n * @param {Element} target Currently focused text field.\n * @param {boolean} isReverse True if considering as the first field.\n * @param {Element} containerElement Element containing all blocks.\n * @param {boolean} onlyVertical Whether to only consider tabbable elements\n * that are visually above or under the\n * target.\n *\n * @return {?Element} Optimal tab target, if one exists.\n */\nexport function getClosestTabbable(\n\ttarget,\n\tisReverse,\n\tcontainerElement,\n\tonlyVertical\n) {\n\t// Since the current focus target is not guaranteed to be a text field, find\n\t// all focusables. Tabbability is considered later.\n\tlet focusableNodes = focus.focusable.find( containerElement );\n\n\tif ( isReverse ) {\n\t\tfocusableNodes.reverse();\n\t}\n\n\t// Consider as candidates those focusables after the current target. It's\n\t// assumed this can only be reached if the target is focusable (on its\n\t// keydown event), so no need to verify it exists in the set.\n\tfocusableNodes = focusableNodes.slice(\n\t\tfocusableNodes.indexOf( target ) + 1\n\t);\n\n\tlet targetRect;\n\n\tif ( onlyVertical ) {\n\t\ttargetRect = target.getBoundingClientRect();\n\t}\n\n\tfunction isTabCandidate( node ) {\n\t\t// Not a candidate if the node is not tabbable.\n\t\tif ( ! focus.tabbable.isTabbableIndex( node ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Skip focusable elements such as links within content editable nodes.\n\t\tif ( node.isContentEditable && node.contentEditable !== 'true' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( onlyVertical ) {\n\t\t\tconst nodeRect = node.getBoundingClientRect();\n\n\t\t\tif (\n\t\t\t\tnodeRect.left >= targetRect.right ||\n\t\t\t\tnodeRect.right <= targetRect.left\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n\n\treturn focusableNodes.find( isTabCandidate );\n}\n\nexport default function useArrowNav() {\n\tconst {\n\t\tgetSelectedBlockClientId,\n\t\tgetMultiSelectedBlocksStartClientId,\n\t\tgetMultiSelectedBlocksEndClientId,\n\t\tgetPreviousBlockClientId,\n\t\tgetNextBlockClientId,\n\t\tgetSettings,\n\t\thasMultiSelection,\n\t\t__unstableIsFullySelected,\n\t} = useSelect( blockEditorStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\treturn useRefEffect( ( node ) => {\n\t\t// Here a DOMRect is stored while moving the caret vertically so\n\t\t// vertical position of the start position can be restored. This is to\n\t\t// recreate browser behaviour across blocks.\n\t\tlet verticalRect;\n\n\t\tfunction onMouseDown() {\n\t\t\tverticalRect = null;\n\t\t}\n\n\t\t/**\n\t\t * Returns true if the given target field is the last in its block which\n\t\t * can be considered for tab transition. For example, in a block with\n\t\t * two text fields, this would return true when reversing from the first\n\t\t * of the two fields, but false when reversing from the second.\n\t\t *\n\t\t * @param {Element} target Currently focused text field.\n\t\t * @param {boolean} isReverse True if considering as the first field.\n\t\t *\n\t\t * @return {boolean} Whether field is at edge for tab transition.\n\t\t */\n\t\tfunction isTabbableEdge( target, isReverse ) {\n\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\ttarget,\n\t\t\t\tisReverse,\n\t\t\t\tnode\n\t\t\t);\n\t\t\treturn (\n\t\t\t\t! closestTabbable || ! isInSameBlock( target, closestTabbable )\n\t\t\t);\n\t\t}\n\n\t\tfunction onKeyDown( event ) {\n\t\t\tconst { keyCode, target } = event;\n\t\t\tconst isUp = keyCode === UP;\n\t\t\tconst isDown = keyCode === DOWN;\n\t\t\tconst isLeft = keyCode === LEFT;\n\t\t\tconst isRight = keyCode === RIGHT;\n\t\t\tconst isReverse = isUp || isLeft;\n\t\t\tconst isHorizontal = isLeft || isRight;\n\t\t\tconst isVertical = isUp || isDown;\n\t\t\tconst isNav = isHorizontal || isVertical;\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst hasModifier =\n\t\t\t\tisShift || event.ctrlKey || event.altKey || event.metaKey;\n\t\t\tconst isNavEdge = isVertical ? isVerticalEdge : isHorizontalEdge;\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// If there is a multi-selection, the arrow keys should collapse the\n\t\t\t// selection to the start or end of the selection.\n\t\t\tif ( hasMultiSelection() ) {\n\t\t\t\t// Only handle if we have a full selection (not a native partial\n\t\t\t\t// selection).\n\t\t\t\tif ( ! __unstableIsFullySelected() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! isNav ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( isShift ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tif ( isReverse ) {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksStartClientId() );\n\t\t\t\t} else {\n\t\t\t\t\tselectBlock( getMultiSelectedBlocksEndClientId(), -1 );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// When presing any key other than up or down, the initial vertical\n\t\t\t// position must ALWAYS be reset. The vertical position is saved so\n\t\t\t// it can be restored as well as possible on sebsequent vertical\n\t\t\t// arrow key presses. It may not always be possible to restore the\n\t\t\t// exact same position (such as at an empty line), so it wouldn't be\n\t\t\t// good to compute the position right before any vertical arrow key\n\t\t\t// press.\n\t\t\tif ( ! isVertical ) {\n\t\t\t\tverticalRect = null;\n\t\t\t} else if ( ! verticalRect ) {\n\t\t\t\tverticalRect = computeCaretRect( defaultView );\n\t\t\t}\n\n\t\t\t// Abort if navigation has already been handled (e.g. RichText\n\t\t\t// inline boundaries).\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isNav ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Abort if our current target is not a candidate for navigation\n\t\t\t// (e.g. preserve native input behaviors).\n\t\t\tif ( ! isNavigationCandidate( target, keyCode, hasModifier ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In the case of RTL scripts, right means previous and left means\n\t\t\t// next, which is the exact reverse of LTR.\n\t\t\tconst isReverseDir = isRTL( target ) ? ! isReverse : isReverse;\n\t\t\tconst { keepCaretInsideBlock } = getSettings();\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\n\t\t\tif ( isShift ) {\n\t\t\t\tconst selectionEndClientId =\n\t\t\t\t\tgetMultiSelectedBlocksEndClientId();\n\t\t\t\tconst selectionBeforeEndClientId = getPreviousBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\t\t\t\tconst selectionAfterEndClientId = getNextBlockClientId(\n\t\t\t\t\tselectionEndClientId || selectedBlockClientId\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\t// Ensure that there is a target block.\n\t\t\t\t\t( ( isReverse && selectionBeforeEndClientId ) ||\n\t\t\t\t\t\t( ! isReverse && selectionAfterEndClientId ) ) &&\n\t\t\t\t\tisTabbableEdge( target, isReverse ) &&\n\t\t\t\t\tisNavEdge( target, isReverse )\n\t\t\t\t) {\n\t\t\t\t\tnode.contentEditable = true;\n\t\t\t\t\t// Firefox doesn't automatically move focus.\n\t\t\t\t\tnode.focus();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisVertical &&\n\t\t\t\tisVerticalEdge( target, isReverse ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverse,\n\t\t\t\t\tnode,\n\t\t\t\t\ttrue\n\t\t\t\t);\n\n\t\t\t\tif ( closestTabbable ) {\n\t\t\t\t\tplaceCaretAtVerticalEdge(\n\t\t\t\t\t\tclosestTabbable,\n\t\t\t\t\t\tisReverse,\n\t\t\t\t\t\tverticalRect\n\t\t\t\t\t);\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisHorizontal &&\n\t\t\t\tdefaultView.getSelection().isCollapsed &&\n\t\t\t\tisHorizontalEdge( target, isReverseDir ) &&\n\t\t\t\t! keepCaretInsideBlock\n\t\t\t) {\n\t\t\t\tconst closestTabbable = getClosestTabbable(\n\t\t\t\t\ttarget,\n\t\t\t\t\tisReverseDir,\n\t\t\t\t\tnode\n\t\t\t\t);\n\t\t\t\tplaceCaretAtHorizontalEdge( closestTabbable, isReverse );\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tnode.addEventListener( 'mousedown', onMouseDown );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'mousedown', onMouseDown );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { first, last } from 'lodash';
|
|
5
1
|
/**
|
|
6
2
|
* WordPress dependencies
|
|
7
3
|
*/
|
|
8
|
-
|
|
9
4
|
import { useRefEffect } from '@wordpress/compose';
|
|
10
5
|
import { useSelect } from '@wordpress/data';
|
|
11
6
|
/**
|
|
@@ -13,7 +8,6 @@ import { useSelect } from '@wordpress/data';
|
|
|
13
8
|
*/
|
|
14
9
|
|
|
15
10
|
import { store as blockEditorStore } from '../../store';
|
|
16
|
-
import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
|
|
17
11
|
|
|
18
12
|
function selector(select) {
|
|
19
13
|
const {
|
|
@@ -43,10 +37,6 @@ export default function useMultiSelection() {
|
|
|
43
37
|
selectedBlockClientId,
|
|
44
38
|
isFullSelection
|
|
45
39
|
} = useSelect(selector, []);
|
|
46
|
-
const selectedRef = useBlockRef(selectedBlockClientId); // These must be in the right DOM order.
|
|
47
|
-
|
|
48
|
-
const startRef = useBlockRef(first(multiSelectedBlockClientIds));
|
|
49
|
-
const endRef = useBlockRef(last(multiSelectedBlockClientIds));
|
|
50
40
|
/**
|
|
51
41
|
* When the component updates, and there is multi selection, we need to
|
|
52
42
|
* select the entire block contents.
|
|
@@ -67,24 +57,6 @@ export default function useMultiSelection() {
|
|
|
67
57
|
}
|
|
68
58
|
|
|
69
59
|
if (!hasMultiSelection || isMultiSelecting) {
|
|
70
|
-
if (!selectedBlockClientId || isMultiSelecting) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const selection = defaultView.getSelection();
|
|
75
|
-
|
|
76
|
-
if (selection.rangeCount && !selection.isCollapsed) {
|
|
77
|
-
const blockNode = selectedRef.current;
|
|
78
|
-
const {
|
|
79
|
-
startContainer,
|
|
80
|
-
endContainer
|
|
81
|
-
} = selection.getRangeAt(0);
|
|
82
|
-
|
|
83
|
-
if (!!blockNode && (!blockNode.contains(startContainer) || !blockNode.contains(endContainer))) {
|
|
84
|
-
selection.removeAllRanges();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
60
|
return;
|
|
89
61
|
}
|
|
90
62
|
|
|
@@ -104,23 +76,9 @@ export default function useMultiSelection() {
|
|
|
104
76
|
// able to select across instances immediately.
|
|
105
77
|
|
|
106
78
|
|
|
107
|
-
node.contentEditable = true;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
node.focus(); // The block refs might not be immediately available
|
|
111
|
-
// when dragging blocks into another block.
|
|
112
|
-
|
|
113
|
-
if (!startRef.current || !endRef.current) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const selection = defaultView.getSelection();
|
|
118
|
-
const range = ownerDocument.createRange(); // These must be in the right DOM order.
|
|
119
|
-
|
|
120
|
-
range.setStartBefore(startRef.current);
|
|
121
|
-
range.setEndAfter(endRef.current);
|
|
122
|
-
selection.removeAllRanges();
|
|
123
|
-
selection.addRange(range);
|
|
79
|
+
node.contentEditable = true;
|
|
80
|
+
defaultView.getSelection().removeAllRanges();
|
|
81
|
+
node.focus();
|
|
124
82
|
}, [hasMultiSelection, isMultiSelecting, multiSelectedBlockClientIds, selectedBlockClientId, initialPosition, isFullSelection]);
|
|
125
83
|
}
|
|
126
84
|
//# sourceMappingURL=use-multi-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["useRefEffect","useSelect","store","blockEditorStore","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","getSelectedBlocksInitialCaretPosition","__unstableIsFullySelected","multiSelectedBlockClientIds","selectedBlockClientId","initialPosition","isFullSelection","useMultiSelection","node","ownerDocument","defaultView","undefined","length","contentEditable","getSelection","removeAllRanges","focus"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;;AAEA,SAASC,QAAT,CAAmBC,MAAnB,EAA4B;AAC3B,QAAM;AACLC,IAAAA,gBADK;AAELC,IAAAA,8BAFK;AAGLC,IAAAA,iBAHK;AAILC,IAAAA,wBAJK;AAKLC,IAAAA,qCALK;AAMLC,IAAAA;AANK,MAOFN,MAAM,CAAEF,gBAAF,CAPV;AASA,SAAO;AACNG,IAAAA,gBAAgB,EAAEA,gBAAgB,EAD5B;AAENM,IAAAA,2BAA2B,EAAEL,8BAA8B,EAFrD;AAGNC,IAAAA,iBAAiB,EAAEA,iBAAiB,EAH9B;AAINK,IAAAA,qBAAqB,EAAEJ,wBAAwB,EAJzC;AAKNK,IAAAA,eAAe,EAAEJ,qCAAqC,EALhD;AAMNK,IAAAA,eAAe,EAAEJ,yBAAyB;AANpC,GAAP;AAQA;;AAED,eAAe,SAASK,iBAAT,GAA6B;AAC3C,QAAM;AACLF,IAAAA,eADK;AAELR,IAAAA,gBAFK;AAGLM,IAAAA,2BAHK;AAILJ,IAAAA,iBAJK;AAKLK,IAAAA,qBALK;AAMLE,IAAAA;AANK,MAOFd,SAAS,CAAEG,QAAF,EAAY,EAAZ,CAPb;AASA;AACD;AACA;AACA;;AACC,SAAOJ,YAAY,CAChBiB,IAAF,IAAY;AACX,UAAM;AAAEC,MAAAA;AAAF,QAAoBD,IAA1B;AACA,UAAM;AAAEE,MAAAA;AAAF,QAAkBD,aAAxB,CAFW,CAIX;AACA;AACA;;AACA,QAAKJ,eAAe,KAAKM,SAApB,IAAiCN,eAAe,KAAK,IAA1D,EAAiE;AAChE;AACA;;AAED,QAAK,CAAEN,iBAAF,IAAuBF,gBAA5B,EAA+C;AAC9C;AACA;;AAED,UAAM;AAAEe,MAAAA;AAAF,QAAaT,2BAAnB;;AAEA,QAAKS,MAAM,GAAG,CAAd,EAAkB;AACjB;AACA;;AAED,QAAK,CAAEN,eAAP,EAAyB;AACxB;AACA,KAvBU,CAyBX;AACA;AACA;AACA;;;AACAE,IAAAA,IAAI,CAACK,eAAL,GAAuB,IAAvB;AAEAH,IAAAA,WAAW,CAACI,YAAZ,GAA2BC,eAA3B;AACAP,IAAAA,IAAI,CAACQ,KAAL;AACA,GAlCiB,EAmClB,CACCjB,iBADD,EAECF,gBAFD,EAGCM,2BAHD,EAICC,qBAJD,EAKCC,eALD,EAMCC,eAND,CAnCkB,CAAnB;AA4CA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nfunction selector( select ) {\n\tconst {\n\t\tisMultiSelecting,\n\t\tgetMultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t__unstableIsFullySelected,\n\t} = select( blockEditorStore );\n\n\treturn {\n\t\tisMultiSelecting: isMultiSelecting(),\n\t\tmultiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),\n\t\thasMultiSelection: hasMultiSelection(),\n\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t\tinitialPosition: getSelectedBlocksInitialCaretPosition(),\n\t\tisFullSelection: __unstableIsFullySelected(),\n\t};\n}\n\nexport default function useMultiSelection() {\n\tconst {\n\t\tinitialPosition,\n\t\tisMultiSelecting,\n\t\tmultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tselectedBlockClientId,\n\t\tisFullSelection,\n\t} = useSelect( selector, [] );\n\n\t/**\n\t * When the component updates, and there is multi selection, we need to\n\t * select the entire block contents.\n\t */\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t// Allow initialPosition to bypass focus behavior. This is useful\n\t\t\t// for the list view or other areas where we don't want to transfer\n\t\t\t// focus to the editor canvas.\n\t\t\tif ( initialPosition === undefined || initialPosition === null ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! hasMultiSelection || isMultiSelecting ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { length } = multiSelectedBlockClientIds;\n\n\t\t\tif ( length < 2 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! isFullSelection ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Allow cross contentEditable selection by temporarily making\n\t\t\t// all content editable. We can't rely on using the store and\n\t\t\t// React because re-rending happens too slowly. We need to be\n\t\t\t// able to select across instances immediately.\n\t\t\tnode.contentEditable = true;\n\n\t\t\tdefaultView.getSelection().removeAllRanges();\n\t\t\tnode.focus();\n\t\t},\n\t\t[\n\t\t\thasMultiSelection,\n\t\t\tisMultiSelecting,\n\t\t\tmultiSelectedBlockClientIds,\n\t\t\tselectedBlockClientId,\n\t\t\tinitialPosition,\n\t\t\tisFullSelection,\n\t\t]\n\t);\n}\n"]}
|
|
@@ -100,11 +100,9 @@ export default function useSelectionObserver() {
|
|
|
100
100
|
} = ownerDocument;
|
|
101
101
|
|
|
102
102
|
function onSelectionChange(event) {
|
|
103
|
-
const selection = defaultView.getSelection();
|
|
104
|
-
// contentEditable wrapper.
|
|
103
|
+
const selection = defaultView.getSelection();
|
|
105
104
|
|
|
106
105
|
if (!selection.rangeCount) {
|
|
107
|
-
setContentEditableWrapper(node, false);
|
|
108
106
|
return;
|
|
109
107
|
} // If selection is collapsed and we haven't used `shift+click`,
|
|
110
108
|
// end multi selection and disable the contentEditable wrapper.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","getBlockParents","getBlockSelectionStart","ownerDocument","defaultView","onSelectionChange","event","getSelection","rangeCount","isClickShift","shiftKey","type","isCollapsed","startClientId","endClientId","selectedClientId","clickedClientId","target","focusNodeIsNonSelectable","undefined","isSingularSelection","startPath","endPath","addListeners","addEventListener","removeListeners","removeEventListener","resetListeners"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAoCC,SAApC,EAAgD;AAC/C,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA+BF,SAArC;;AAEA,MAAKC,UAAU,CAACE,QAAX,KAAwBF,UAAU,CAACG,SAAxC,EAAoD;AACnD,WAAOH,UAAP;AACA;;AAED,SAAOA,UAAU,CAACI,UAAX,CAAuBH,YAAvB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,uBAAT,CAAkCN,SAAlC,EAA8C;AAC7C,QAAM;AAAEO,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAnC;;AAEA,MAAKO,SAAS,CAACJ,QAAV,KAAuBI,SAAS,CAACH,SAAtC,EAAkD;AACjD,WAAOG,SAAP;AACA;;AAED,SAAOA,SAAS,CAACF,UAAV,CAAsBG,WAAW,GAAG,CAApC,CAAP;AACA;;AAED,SAASC,SAAT,C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S,CAAE9B,KAAF,CAAX,EAAsB+B,OAAO,CAAE/B,KAAF,CAA7B,CAAX;AACA;AACD;;AAED,aAASgC,YAAT,GAAwB;AACvBpB,MAAAA,aAAa,CAACqB,gBAAd,CACC,iBADD,EAECnB,iBAFD;AAIAD,MAAAA,WAAW,CAACoB,gBAAZ,CAA8B,SAA9B,EAAyCnB,iBAAzC;AACA;;AAED,aAASoB,eAAT,GAA2B;AAC1BtB,MAAAA,aAAa,CAACuB,mBAAd,CACC,iBADD,EAECrB,iBAFD;AAIAD,MAAAA,WAAW,CAACsB,mBAAZ,CAAiC,SAAjC,EAA4CrB,iBAA5C;AACA;;AAED,aAASsB,cAAT,GAA0B;AACzBF,MAAAA,eAAe;AACfF,MAAAA,YAAY;AACZ;;AAEDA,IAAAA,YAAY,GAvGD,CAwGX;AACA;AACA;;AACA9B,IAAAA,IAAI,CAAC+B,gBAAL,CAAuB,SAAvB,EAAkCG,cAAlC;AACA,WAAO,MAAM;AACZF,MAAAA,eAAe;AACfhC,MAAAA,IAAI,CAACiC,mBAAL,CAA0B,SAA1B,EAAqCC,cAArC;AACA,KAHD;AAIA,GAjHiB,EAkHlB,CAAE7B,WAAF,EAAeC,WAAf,EAA4BC,eAA5B,EAA6CC,eAA7C,CAlHkB,CAAnB;AAoHA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\n/**\n * Extract the selection start node from the selection. When the anchor node is\n * not a text node, the selection offset is the index of a child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionStartNode( selection ) {\n\tconst { anchorNode, anchorOffset } = selection;\n\n\tif ( anchorNode.nodeType === anchorNode.TEXT_NODE ) {\n\t\treturn anchorNode;\n\t}\n\n\treturn anchorNode.childNodes[ anchorOffset ];\n}\n\n/**\n * Extract the selection end node from the selection. When the focus node is not\n * a text node, the selection offset is the index of a child node. The selection\n * reaches up to but excluding that child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionEndNode( selection ) {\n\tconst { focusNode, focusOffset } = selection;\n\n\tif ( focusNode.nodeType === focusNode.TEXT_NODE ) {\n\t\treturn focusNode;\n\t}\n\n\treturn focusNode.childNodes[ focusOffset - 1 ];\n}\n\nfunction findDepth( a, b ) {\n\tlet depth = 0;\n\n\twhile ( a[ depth ] === b[ depth ] ) {\n\t\tdepth++;\n\t}\n\n\treturn depth;\n}\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useSelectionObserver() {\n\tconst { multiSelect, selectBlock, selectionChange } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { getBlockParents, getBlockSelectionStart } =\n\t\tuseSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tfunction onSelectionChange( event ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\t\t\t\t// If no selection is found, end multi selection and disable the\n\t\t\t\t// contentEditable wrapper.\n\t\t\t\tif ( ! selection.rangeCount ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// If selection is collapsed and we haven't used `shift+click`,\n\t\t\t\t// end multi selection and disable the contentEditable wrapper.\n\t\t\t\t// We have to check about `shift+click` case because elements\n\t\t\t\t// that don't support text selection might be involved, and we might\n\t\t\t\t// update the clientIds to multi-select blocks.\n\t\t\t\t// For now we check if the event is a `mouse` event.\n\t\t\t\tconst isClickShift = event.shiftKey && event.type === 'mouseup';\n\t\t\t\tif ( selection.isCollapsed && ! isClickShift ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet startClientId = getBlockClientId(\n\t\t\t\t\textractSelectionStartNode( selection )\n\t\t\t\t);\n\t\t\t\tlet endClientId = getBlockClientId(\n\t\t\t\t\textractSelectionEndNode( selection )\n\t\t\t\t);\n\t\t\t\t// If the selection has changed and we had pressed `shift+click`,\n\t\t\t\t// we need to check if in an element that doesn't support\n\t\t\t\t// text selection has been clicked.\n\t\t\t\tif ( isClickShift ) {\n\t\t\t\t\tconst selectedClientId = getBlockSelectionStart();\n\t\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\t\t\t\t\t// `endClientId` is not defined if we end the selection by clicking a non-selectable block.\n\t\t\t\t\t// We need to check if there was already a selection with a non-selectable focusNode.\n\t\t\t\t\tconst focusNodeIsNonSelectable =\n\t\t\t\t\t\tclickedClientId !== endClientId;\n\t\t\t\t\tif (\n\t\t\t\t\t\t( startClientId === endClientId &&\n\t\t\t\t\t\t\tselection.isCollapsed ) ||\n\t\t\t\t\t\t! endClientId ||\n\t\t\t\t\t\tfocusNodeIsNonSelectable\n\t\t\t\t\t) {\n\t\t\t\t\t\tendClientId = clickedClientId;\n\t\t\t\t\t}\n\t\t\t\t\t// Handle the case when we have a non-selectable block\n\t\t\t\t\t// selected and click another one.\n\t\t\t\t\tif ( startClientId !== selectedClientId ) {\n\t\t\t\t\t\tstartClientId = selectedClientId;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the selection did not involve a block, return.\n\t\t\t\tif (\n\t\t\t\t\tstartClientId === undefined &&\n\t\t\t\t\tendClientId === undefined\n\t\t\t\t) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst isSingularSelection = startClientId === endClientId;\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( startClientId );\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( startClientId ),\n\t\t\t\t\t\tstartClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth = findDepth( startPath, endPath );\n\n\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction addListeners() {\n\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction removeListeners() {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction resetListeners() {\n\t\t\t\tremoveListeners();\n\t\t\t\taddListeners();\n\t\t\t}\n\n\t\t\taddListeners();\n\t\t\t// We must allow rich text to set selection first. This ensures that\n\t\t\t// our `selectionchange` listener is always reset to be called after\n\t\t\t// the rich text one.\n\t\t\tnode.addEventListener( 'focusin', resetListeners );\n\t\t\treturn () => {\n\t\t\t\tremoveListeners();\n\t\t\t\tnode.removeEventListener( 'focusin', resetListeners );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-selection-observer.js"],"names":["useSelect","useDispatch","useRefEffect","store","blockEditorStore","getBlockClientId","extractSelectionStartNode","selection","anchorNode","anchorOffset","nodeType","TEXT_NODE","childNodes","extractSelectionEndNode","focusNode","focusOffset","findDepth","a","b","depth","setContentEditableWrapper","node","value","contentEditable","focus","useSelectionObserver","multiSelect","selectBlock","selectionChange","getBlockParents","getBlockSelectionStart","ownerDocument","defaultView","onSelectionChange","event","getSelection","rangeCount","isClickShift","shiftKey","type","isCollapsed","startClientId","endClientId","selectedClientId","clickedClientId","target","focusNodeIsNonSelectable","undefined","isSingularSelection","startPath","endPath","addListeners","addEventListener","removeListeners","removeEventListener","resetListeners"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,YAAT,QAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,gBAAT,QAAiC,iBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,yBAAT,CAAoCC,SAApC,EAAgD;AAC/C,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,MAA+BF,SAArC;;AAEA,MAAKC,UAAU,CAACE,QAAX,KAAwBF,UAAU,CAACG,SAAxC,EAAoD;AACnD,WAAOH,UAAP;AACA;;AAED,SAAOA,UAAU,CAACI,UAAX,CAAuBH,YAAvB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,uBAAT,CAAkCN,SAAlC,EAA8C;AAC7C,QAAM;AAAEO,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA6BR,SAAnC;;AAEA,MAAKO,SAAS,CAACJ,QAAV,KAAuBI,SAAS,CAACH,SAAtC,EAAkD;AACjD,WAAOG,SAAP;AACA;;AAED,SAAOA,SAAS,CAACF,UAAV,CAAsBG,WAAW,GAAG,CAApC,CAAP;AACA;;AAED,SAASC,SAAT,CAAoBC,CAApB,EAAuBC,CAAvB,EAA2B;AAC1B,MAAIC,KAAK,GAAG,CAAZ;;AAEA,SAAQF,CAAC,CAAEE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AAAA,WAAW,CAACoB,gBAAZ,CAA8B,SAA9B,EAAyCnB,iBAAzC;AACA;;AAED,aAASoB,eAAT,GAA2B;AAC1BtB,MAAAA,aAAa,CAACuB,mBAAd,CACC,iBADD,EAECrB,iBAFD;AAIAD,MAAAA,WAAW,CAACsB,mBAAZ,CAAiC,SAAjC,EAA4CrB,iBAA5C;AACA;;AAED,aAASsB,cAAT,GAA0B;AACzBF,MAAAA,eAAe;AACfF,MAAAA,YAAY;AACZ;;AAEDA,IAAAA,YAAY,GAtGD,CAuGX;AACA;AACA;;AACA9B,IAAAA,IAAI,CAAC+B,gBAAL,CAAuB,SAAvB,EAAkCG,cAAlC;AACA,WAAO,MAAM;AACZF,MAAAA,eAAe;AACfhC,MAAAA,IAAI,CAACiC,mBAAL,CAA0B,SAA1B,EAAqCC,cAArC;AACA,KAHD;AAIA,GAhHiB,EAiHlB,CAAE7B,WAAF,EAAeC,WAAf,EAA4BC,eAA5B,EAA6CC,eAA7C,CAjHkB,CAAnB;AAmHA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getBlockClientId } from '../../utils/dom';\n\n/**\n * Extract the selection start node from the selection. When the anchor node is\n * not a text node, the selection offset is the index of a child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionStartNode( selection ) {\n\tconst { anchorNode, anchorOffset } = selection;\n\n\tif ( anchorNode.nodeType === anchorNode.TEXT_NODE ) {\n\t\treturn anchorNode;\n\t}\n\n\treturn anchorNode.childNodes[ anchorOffset ];\n}\n\n/**\n * Extract the selection end node from the selection. When the focus node is not\n * a text node, the selection offset is the index of a child node. The selection\n * reaches up to but excluding that child node.\n *\n * @param {Selection} selection The selection.\n *\n * @return {Element} The selection start node.\n */\nfunction extractSelectionEndNode( selection ) {\n\tconst { focusNode, focusOffset } = selection;\n\n\tif ( focusNode.nodeType === focusNode.TEXT_NODE ) {\n\t\treturn focusNode;\n\t}\n\n\treturn focusNode.childNodes[ focusOffset - 1 ];\n}\n\nfunction findDepth( a, b ) {\n\tlet depth = 0;\n\n\twhile ( a[ depth ] === b[ depth ] ) {\n\t\tdepth++;\n\t}\n\n\treturn depth;\n}\n\n/**\n * Sets the `contenteditable` wrapper element to `value`.\n *\n * @param {HTMLElement} node Block element.\n * @param {boolean} value `contentEditable` value (true or false)\n */\nfunction setContentEditableWrapper( node, value ) {\n\tnode.contentEditable = value;\n\t// Firefox doesn't automatically move focus.\n\tif ( value ) node.focus();\n}\n\n/**\n * Sets a multi-selection based on the native selection across blocks.\n */\nexport default function useSelectionObserver() {\n\tconst { multiSelect, selectBlock, selectionChange } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { getBlockParents, getBlockSelectionStart } =\n\t\tuseSelect( blockEditorStore );\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tfunction onSelectionChange( event ) {\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( ! selection.rangeCount ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// If selection is collapsed and we haven't used `shift+click`,\n\t\t\t\t// end multi selection and disable the contentEditable wrapper.\n\t\t\t\t// We have to check about `shift+click` case because elements\n\t\t\t\t// that don't support text selection might be involved, and we might\n\t\t\t\t// update the clientIds to multi-select blocks.\n\t\t\t\t// For now we check if the event is a `mouse` event.\n\t\t\t\tconst isClickShift = event.shiftKey && event.type === 'mouseup';\n\t\t\t\tif ( selection.isCollapsed && ! isClickShift ) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet startClientId = getBlockClientId(\n\t\t\t\t\textractSelectionStartNode( selection )\n\t\t\t\t);\n\t\t\t\tlet endClientId = getBlockClientId(\n\t\t\t\t\textractSelectionEndNode( selection )\n\t\t\t\t);\n\t\t\t\t// If the selection has changed and we had pressed `shift+click`,\n\t\t\t\t// we need to check if in an element that doesn't support\n\t\t\t\t// text selection has been clicked.\n\t\t\t\tif ( isClickShift ) {\n\t\t\t\t\tconst selectedClientId = getBlockSelectionStart();\n\t\t\t\t\tconst clickedClientId = getBlockClientId( event.target );\n\t\t\t\t\t// `endClientId` is not defined if we end the selection by clicking a non-selectable block.\n\t\t\t\t\t// We need to check if there was already a selection with a non-selectable focusNode.\n\t\t\t\t\tconst focusNodeIsNonSelectable =\n\t\t\t\t\t\tclickedClientId !== endClientId;\n\t\t\t\t\tif (\n\t\t\t\t\t\t( startClientId === endClientId &&\n\t\t\t\t\t\t\tselection.isCollapsed ) ||\n\t\t\t\t\t\t! endClientId ||\n\t\t\t\t\t\tfocusNodeIsNonSelectable\n\t\t\t\t\t) {\n\t\t\t\t\t\tendClientId = clickedClientId;\n\t\t\t\t\t}\n\t\t\t\t\t// Handle the case when we have a non-selectable block\n\t\t\t\t\t// selected and click another one.\n\t\t\t\t\tif ( startClientId !== selectedClientId ) {\n\t\t\t\t\t\tstartClientId = selectedClientId;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the selection did not involve a block, return.\n\t\t\t\tif (\n\t\t\t\t\tstartClientId === undefined &&\n\t\t\t\t\tendClientId === undefined\n\t\t\t\t) {\n\t\t\t\t\tsetContentEditableWrapper( node, false );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst isSingularSelection = startClientId === endClientId;\n\t\t\t\tif ( isSingularSelection ) {\n\t\t\t\t\tselectBlock( startClientId );\n\t\t\t\t} else {\n\t\t\t\t\tconst startPath = [\n\t\t\t\t\t\t...getBlockParents( startClientId ),\n\t\t\t\t\t\tstartClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst endPath = [\n\t\t\t\t\t\t...getBlockParents( endClientId ),\n\t\t\t\t\t\tendClientId,\n\t\t\t\t\t];\n\t\t\t\t\tconst depth = findDepth( startPath, endPath );\n\n\t\t\t\t\tmultiSelect( startPath[ depth ], endPath[ depth ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction addListeners() {\n\t\t\t\townerDocument.addEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.addEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction removeListeners() {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'selectionchange',\n\t\t\t\t\tonSelectionChange\n\t\t\t\t);\n\t\t\t\tdefaultView.removeEventListener( 'mouseup', onSelectionChange );\n\t\t\t}\n\n\t\t\tfunction resetListeners() {\n\t\t\t\tremoveListeners();\n\t\t\t\taddListeners();\n\t\t\t}\n\n\t\t\taddListeners();\n\t\t\t// We must allow rich text to set selection first. This ensures that\n\t\t\t// our `selectionchange` listener is always reset to be called after\n\t\t\t// the rich text one.\n\t\t\tnode.addEventListener( 'focusin', resetListeners );\n\t\t\treturn () => {\n\t\t\t\tremoveListeners();\n\t\t\t\tnode.removeEventListener( 'focusin', resetListeners );\n\t\t\t};\n\t\t},\n\t\t[ multiSelect, selectBlock, selectionChange, getBlockParents ]\n\t);\n}\n"]}
|
|
@@ -5,7 +5,6 @@ import { createElement } from "@wordpress/element";
|
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
7
|
import classnames from 'classnames';
|
|
8
|
-
import { isObject } from 'lodash';
|
|
9
8
|
/**
|
|
10
9
|
* WordPress dependencies
|
|
11
10
|
*/
|
|
@@ -37,12 +36,12 @@ const hasLinkColorSupport = blockType => {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
const colorSupport = getBlockSupport(blockType, COLOR_SUPPORT_KEY);
|
|
40
|
-
return
|
|
39
|
+
return colorSupport !== null && typeof colorSupport === 'object' && !!colorSupport.link;
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
const hasGradientSupport = blockType => {
|
|
44
43
|
const colorSupport = getBlockSupport(blockType, COLOR_SUPPORT_KEY);
|
|
45
|
-
return
|
|
44
|
+
return colorSupport !== null && typeof colorSupport === 'object' && !!colorSupport.gradients;
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
const hasBackgroundColorSupport = blockType => {
|