@wordpress/block-editor 11.3.4 → 11.3.6

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/build/components/block-inspector/index.js +11 -10
  3. package/build/components/block-inspector/index.js.map +1 -1
  4. package/build/components/block-inspector/useBlockInspectorAnimationSettings.js +46 -0
  5. package/build/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
  6. package/build/components/inserter/media-tab/hooks.js +10 -11
  7. package/build/components/inserter/media-tab/hooks.js.map +1 -1
  8. package/build/components/inserter/media-tab/media-list.js +5 -108
  9. package/build/components/inserter/media-tab/media-list.js.map +1 -1
  10. package/build/components/inserter/media-tab/media-preview.js +242 -0
  11. package/build/components/inserter/media-tab/media-preview.js.map +1 -0
  12. package/build/components/link-control/index.js +17 -44
  13. package/build/components/link-control/index.js.map +1 -1
  14. package/build/components/list-view/block.js +14 -2
  15. package/build/components/list-view/block.js.map +1 -1
  16. package/build/components/list-view/branch.js +2 -2
  17. package/build/components/list-view/branch.js.map +1 -1
  18. package/build/components/list-view/leaf.js +10 -6
  19. package/build/components/list-view/leaf.js.map +1 -1
  20. package/build/components/list-view/use-list-view-scroll-into-view.js +51 -0
  21. package/build/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
  22. package/build/components/off-canvas-editor/leaf-more-menu.js +126 -0
  23. package/build/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
  24. package/build/private-apis.js +3 -0
  25. package/build/private-apis.js.map +1 -1
  26. package/build/store/defaults.js +28 -1
  27. package/build/store/defaults.js.map +1 -1
  28. package/build/store/selectors.js +1 -1
  29. package/build/store/selectors.js.map +1 -1
  30. package/build-module/components/block-inspector/index.js +9 -9
  31. package/build-module/components/block-inspector/index.js.map +1 -1
  32. package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js +37 -0
  33. package/build-module/components/block-inspector/useBlockInspectorAnimationSettings.js.map +1 -0
  34. package/build-module/components/inserter/media-tab/hooks.js +10 -11
  35. package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
  36. package/build-module/components/inserter/media-tab/media-list.js +6 -105
  37. package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
  38. package/build-module/components/inserter/media-tab/media-preview.js +222 -0
  39. package/build-module/components/inserter/media-tab/media-preview.js.map +1 -0
  40. package/build-module/components/link-control/index.js +16 -44
  41. package/build-module/components/link-control/index.js.map +1 -1
  42. package/build-module/components/list-view/block.js +13 -2
  43. package/build-module/components/list-view/block.js.map +1 -1
  44. package/build-module/components/list-view/branch.js +2 -2
  45. package/build-module/components/list-view/branch.js.map +1 -1
  46. package/build-module/components/list-view/leaf.js +8 -4
  47. package/build-module/components/list-view/leaf.js.map +1 -1
  48. package/build-module/components/list-view/use-list-view-scroll-into-view.js +42 -0
  49. package/build-module/components/list-view/use-list-view-scroll-into-view.js.map +1 -0
  50. package/build-module/components/off-canvas-editor/leaf-more-menu.js +108 -0
  51. package/build-module/components/off-canvas-editor/leaf-more-menu.js.map +1 -0
  52. package/build-module/private-apis.js +2 -0
  53. package/build-module/private-apis.js.map +1 -1
  54. package/build-module/store/defaults.js +28 -1
  55. package/build-module/store/defaults.js.map +1 -1
  56. package/build-module/store/selectors.js +1 -1
  57. package/build-module/store/selectors.js.map +1 -1
  58. package/build-style/style-rtl.css +43 -8
  59. package/build-style/style.css +43 -8
  60. package/package.json +12 -12
  61. package/src/components/block-inspector/index.js +11 -14
  62. package/src/components/block-inspector/useBlockInspectorAnimationSettings.js +53 -0
  63. package/src/components/inserter/media-tab/hooks.js +9 -8
  64. package/src/components/inserter/media-tab/media-list.js +3 -122
  65. package/src/components/inserter/media-tab/media-preview.js +268 -0
  66. package/src/components/inserter/style.scss +22 -0
  67. package/src/components/link-control/index.js +23 -58
  68. package/src/components/link-control/style.scss +23 -7
  69. package/src/components/link-control/test/index.js +5 -134
  70. package/src/components/list-view/block.js +12 -0
  71. package/src/components/list-view/branch.js +1 -2
  72. package/src/components/list-view/leaf.js +43 -29
  73. package/src/components/list-view/use-list-view-scroll-into-view.js +48 -0
  74. package/src/components/media-replace-flow/test/index.js +1 -1
  75. package/src/components/off-canvas-editor/leaf-more-menu.js +120 -0
  76. package/src/components/spacing-sizes-control/style.scss +1 -1
  77. package/src/private-apis.js +2 -0
  78. package/src/store/defaults.js +14 -1
  79. package/src/store/selectors.js +4 -1
  80. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.MediaPreview = MediaPreview;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var _classnames = _interopRequireDefault(require("classnames"));
15
+
16
+ var _components = require("@wordpress/components");
17
+
18
+ var _i18n = require("@wordpress/i18n");
19
+
20
+ var _blocks = require("@wordpress/blocks");
21
+
22
+ var _icons = require("@wordpress/icons");
23
+
24
+ var _data = require("@wordpress/data");
25
+
26
+ var _notices = require("@wordpress/notices");
27
+
28
+ var _blob = require("@wordpress/blob");
29
+
30
+ var _inserterDraggableBlocks = _interopRequireDefault(require("../../inserter-draggable-blocks"));
31
+
32
+ var _utils = require("./utils");
33
+
34
+ var _store = require("../../../store");
35
+
36
+ /**
37
+ * External dependencies
38
+ */
39
+
40
+ /**
41
+ * WordPress dependencies
42
+ */
43
+
44
+ /**
45
+ * Internal dependencies
46
+ */
47
+ const ALLOWED_MEDIA_TYPES = ['image'];
48
+ const MAXIMUM_TITLE_LENGTH = 25;
49
+ const MEDIA_OPTIONS_POPOVER_PROPS = {
50
+ position: 'bottom left',
51
+ className: 'block-editor-inserter__media-list__item-preview-options__popover'
52
+ };
53
+
54
+ function MediaPreviewOptions(_ref) {
55
+ let {
56
+ category,
57
+ media
58
+ } = _ref;
59
+
60
+ if (!category.getReportUrl) {
61
+ return null;
62
+ }
63
+
64
+ const reportUrl = category.getReportUrl(media);
65
+ return (0, _element.createElement)(_components.DropdownMenu, {
66
+ className: "block-editor-inserter__media-list__item-preview-options",
67
+ label: (0, _i18n.__)('Options'),
68
+ popoverProps: MEDIA_OPTIONS_POPOVER_PROPS,
69
+ icon: _icons.moreVertical
70
+ }, () => (0, _element.createElement)(_components.MenuGroup, null, (0, _element.createElement)(_components.MenuItem, {
71
+ onClick: () => window.open(reportUrl, '_blank').focus(),
72
+ icon: _icons.external
73
+ }, (0, _i18n.sprintf)(
74
+ /* translators: %s: The media type to report e.g: "image", "video", "audio" */
75
+ (0, _i18n.__)('Report %s'), category.mediaType))));
76
+ }
77
+
78
+ function InsertExternalImageModal(_ref2) {
79
+ let {
80
+ onClose,
81
+ onSubmit
82
+ } = _ref2;
83
+ return (0, _element.createElement)(_components.Modal, {
84
+ title: (0, _i18n.__)('Insert external image'),
85
+ onRequestClose: onClose,
86
+ className: "block-editor-inserter-media-tab-media-preview-inserter-external-image-modal"
87
+ }, (0, _element.createElement)(_components.__experimentalVStack, {
88
+ spacing: 3
89
+ }, (0, _element.createElement)("p", null, (0, _i18n.__)('This image cannot be uploaded to your Media Library, but it can still be inserted as an external image.')), (0, _element.createElement)("p", null, (0, _i18n.__)('External images can be removed by the external provider without warning and could even have legal compliance issues related to privacy legislation.'))), (0, _element.createElement)(_components.Flex, {
90
+ className: "block-editor-block-lock-modal__actions",
91
+ justify: "flex-end",
92
+ expanded: false
93
+ }, (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
94
+ variant: "tertiary",
95
+ onClick: onClose
96
+ }, (0, _i18n.__)('Cancel'))), (0, _element.createElement)(_components.FlexItem, null, (0, _element.createElement)(_components.Button, {
97
+ variant: "primary",
98
+ onClick: onSubmit
99
+ }, (0, _i18n.__)('Insert')))));
100
+ }
101
+
102
+ function MediaPreview(_ref3) {
103
+ var _media$title;
104
+
105
+ let {
106
+ media,
107
+ onClick,
108
+ composite,
109
+ category
110
+ } = _ref3;
111
+ const [showExternalUploadModal, setShowExternalUploadModal] = (0, _element.useState)(false);
112
+ const [isHovered, setIsHovered] = (0, _element.useState)(false);
113
+ const [isInserting, setIsInserting] = (0, _element.useState)(false);
114
+ const [block, preview] = (0, _element.useMemo)(() => (0, _utils.getBlockAndPreviewFromMedia)(media, category.mediaType), [media, category.mediaType]);
115
+ const {
116
+ createErrorNotice,
117
+ createSuccessNotice
118
+ } = (0, _data.useDispatch)(_notices.store);
119
+ const mediaUpload = (0, _data.useSelect)(select => select(_store.store).getSettings().mediaUpload, []);
120
+ const onMediaInsert = (0, _element.useCallback)(previewBlock => {
121
+ // Prevent multiple uploads when we're in the process of inserting.
122
+ if (isInserting) {
123
+ return;
124
+ }
125
+
126
+ const clonedBlock = (0, _blocks.cloneBlock)(previewBlock);
127
+ const {
128
+ id,
129
+ url,
130
+ caption
131
+ } = clonedBlock.attributes; // Media item already exists in library, so just insert it.
132
+
133
+ if (!!id) {
134
+ onClick(clonedBlock);
135
+ return;
136
+ }
137
+
138
+ setIsInserting(true); // Media item does not exist in library, so try to upload it.
139
+ // Fist fetch the image data. This may fail if the image host
140
+ // doesn't allow CORS with the domain.
141
+ // If this happens, we insert the image block using the external
142
+ // URL and let the user know about the possible implications.
143
+
144
+ window.fetch(url).then(response => response.blob()).then(blob => {
145
+ mediaUpload({
146
+ filesList: [blob],
147
+ additionalData: {
148
+ caption
149
+ },
150
+
151
+ onFileChange(_ref4) {
152
+ let [img] = _ref4;
153
+
154
+ if ((0, _blob.isBlobURL)(img.url)) {
155
+ return;
156
+ }
157
+
158
+ onClick({ ...clonedBlock,
159
+ attributes: { ...clonedBlock.attributes,
160
+ id: img.id,
161
+ url: img.url
162
+ }
163
+ });
164
+ createSuccessNotice((0, _i18n.__)('Image uploaded and inserted.'), {
165
+ type: 'snackbar'
166
+ });
167
+ setIsInserting(false);
168
+ },
169
+
170
+ allowedTypes: ALLOWED_MEDIA_TYPES,
171
+
172
+ onError(message) {
173
+ createErrorNotice(message, {
174
+ type: 'snackbar'
175
+ });
176
+ setIsInserting(false);
177
+ }
178
+
179
+ });
180
+ }).catch(() => {
181
+ setShowExternalUploadModal(true);
182
+ setIsInserting(false);
183
+ });
184
+ }, [isInserting, onClick, mediaUpload, createErrorNotice, createSuccessNotice]);
185
+ const title = ((_media$title = media.title) === null || _media$title === void 0 ? void 0 : _media$title.rendered) || media.title;
186
+ let truncatedTitle;
187
+
188
+ if (title.length > MAXIMUM_TITLE_LENGTH) {
189
+ const omission = '...';
190
+ truncatedTitle = title.slice(0, MAXIMUM_TITLE_LENGTH - omission.length) + omission;
191
+ }
192
+
193
+ const onMouseEnter = (0, _element.useCallback)(() => setIsHovered(true), []);
194
+ const onMouseLeave = (0, _element.useCallback)(() => setIsHovered(false), []);
195
+ return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_inserterDraggableBlocks.default, {
196
+ isEnabled: true,
197
+ blocks: [block]
198
+ }, _ref5 => {
199
+ let {
200
+ draggable,
201
+ onDragStart,
202
+ onDragEnd
203
+ } = _ref5;
204
+ return (0, _element.createElement)("div", {
205
+ className: (0, _classnames.default)('block-editor-inserter__media-list__list-item', {
206
+ 'is-hovered': isHovered
207
+ }),
208
+ draggable: draggable,
209
+ onDragStart: onDragStart,
210
+ onDragEnd: onDragEnd
211
+ }, (0, _element.createElement)(_components.Tooltip, {
212
+ text: truncatedTitle || title
213
+ }, (0, _element.createElement)("div", {
214
+ onMouseEnter: onMouseEnter,
215
+ onMouseLeave: onMouseLeave
216
+ }, (0, _element.createElement)(_components.__unstableCompositeItem, (0, _extends2.default)({
217
+ role: "option",
218
+ as: "div"
219
+ }, composite, {
220
+ className: "block-editor-inserter__media-list__item",
221
+ onClick: () => onMediaInsert(block),
222
+ "aria-label": title
223
+ }), (0, _element.createElement)("div", {
224
+ className: "block-editor-inserter__media-list__item-preview"
225
+ }, preview, isInserting && (0, _element.createElement)("div", {
226
+ className: "block-editor-inserter__media-list__item-preview-spinner"
227
+ }, (0, _element.createElement)(_components.Spinner, null)))), !isInserting && (0, _element.createElement)(MediaPreviewOptions, {
228
+ category: category,
229
+ media: media
230
+ }))));
231
+ }), showExternalUploadModal && (0, _element.createElement)(InsertExternalImageModal, {
232
+ onClose: () => setShowExternalUploadModal(false),
233
+ onSubmit: () => {
234
+ onClick((0, _blocks.cloneBlock)(block));
235
+ createSuccessNotice((0, _i18n.__)('Image inserted.'), {
236
+ type: 'snackbar'
237
+ });
238
+ setShowExternalUploadModal(false);
239
+ }
240
+ }));
241
+ }
242
+ //# sourceMappingURL=media-preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/inserter/media-tab/media-preview.js"],"names":["ALLOWED_MEDIA_TYPES","MAXIMUM_TITLE_LENGTH","MEDIA_OPTIONS_POPOVER_PROPS","position","className","MediaPreviewOptions","category","media","getReportUrl","reportUrl","moreVertical","window","open","focus","external","mediaType","InsertExternalImageModal","onClose","onSubmit","MediaPreview","onClick","composite","showExternalUploadModal","setShowExternalUploadModal","isHovered","setIsHovered","isInserting","setIsInserting","block","preview","createErrorNotice","createSuccessNotice","noticesStore","mediaUpload","select","blockEditorStore","getSettings","onMediaInsert","previewBlock","clonedBlock","id","url","caption","attributes","fetch","then","response","blob","filesList","additionalData","onFileChange","img","type","allowedTypes","onError","message","catch","title","rendered","truncatedTitle","length","omission","slice","onMouseEnter","onMouseLeave","draggable","onDragStart","onDragEnd"],"mappings":";;;;;;;;;AAsBA;;;;AAnBA;;AAKA;;AAaA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAlCA;AACA;AACA;;AAGA;AACA;AACA;;AAsBA;AACA;AACA;AAKA,MAAMA,mBAAmB,GAAG,CAAE,OAAF,CAA5B;AACA,MAAMC,oBAAoB,GAAG,EAA7B;AACA,MAAMC,2BAA2B,GAAG;AACnCC,EAAAA,QAAQ,EAAE,aADyB;AAEnCC,EAAAA,SAAS,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,MAAMgB,aAAa,CAAET,KAAF,CAL9B;AAMC,oBAAa6B;AANd,QAQC;AAAK,MAAA,SAAS,EAAC;AAAf,OACG5B,OADH,EAEGH,WAAW,IACZ;AAAK,MAAA,SAAS,EAAC;AAAf,OACC,4BAAC,mBAAD,OADD,CAHF,CARD,CAJD,EAqBG,CAAEA,WAAF,IACD,4BAAC,mBAAD;AACC,MAAA,QAAQ,EAAGpB,QADZ;AAEC,MAAA,KAAK,EAAGC;AAFT,MAtBF,CAHD,CAXD,CADC;AAAA,GADH,CADD,EAiDGe,uBAAuB,IACxB,4BAAC,wBAAD;AACC,IAAA,OAAO,EAAG,MAAMC,0BAA0B,CAAE,KAAF,CAD3C;AAEC,IAAA,QAAQ,EAAG,MAAM;AAChBH,MAAAA,OAAO,CAAE,wBAAYQ,KAAZ,CAAF,CAAP;AACAG,MAAAA,mBAAmB,CAAE,cAAI,iBAAJ,CAAF,EAA2B;AAC7CqB,QAAAA,IAAI,EAAE;AADuC,OAA3B,CAAnB;AAGA7B,MAAAA,0BAA0B,CAAE,KAAF,CAA1B;AACA;AARF,IAlDF,CADD;AAgEA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__unstableCompositeItem as CompositeItem,\n\tTooltip,\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tSpinner,\n\tModal,\n\tFlex,\n\tFlexItem,\n\tButton,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo, useCallback, useState } from '@wordpress/element';\nimport { cloneBlock } from '@wordpress/blocks';\nimport { moreVertical, external } from '@wordpress/icons';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { isBlobURL } from '@wordpress/blob';\n\n/**\n * Internal dependencies\n */\nimport InserterDraggableBlocks from '../../inserter-draggable-blocks';\nimport { getBlockAndPreviewFromMedia } from './utils';\nimport { store as blockEditorStore } from '../../../store';\n\nconst ALLOWED_MEDIA_TYPES = [ 'image' ];\nconst MAXIMUM_TITLE_LENGTH = 25;\nconst MEDIA_OPTIONS_POPOVER_PROPS = {\n\tposition: 'bottom left',\n\tclassName:\n\t\t'block-editor-inserter__media-list__item-preview-options__popover',\n};\n\nfunction MediaPreviewOptions( { category, media } ) {\n\tif ( ! category.getReportUrl ) {\n\t\treturn null;\n\t}\n\tconst reportUrl = category.getReportUrl( media );\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"block-editor-inserter__media-list__item-preview-options\"\n\t\t\tlabel={ __( 'Options' ) }\n\t\t\tpopoverProps={ MEDIA_OPTIONS_POPOVER_PROPS }\n\t\t\ticon={ moreVertical }\n\t\t>\n\t\t\t{ () => (\n\t\t\t\t<MenuGroup>\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\twindow.open( reportUrl, '_blank' ).focus()\n\t\t\t\t\t\t}\n\t\t\t\t\t\ticon={ external }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t/* translators: %s: The media type to report e.g: \"image\", \"video\", \"audio\" */\n\t\t\t\t\t\t\t__( 'Report %s' ),\n\t\t\t\t\t\t\tcategory.mediaType\n\t\t\t\t\t\t) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t</MenuGroup>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n\nfunction InsertExternalImageModal( { onClose, onSubmit } ) {\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Insert external image' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t\tclassName=\"block-editor-inserter-media-tab-media-preview-inserter-external-image-modal\"\n\t\t>\n\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t<p>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'This image cannot be uploaded to your Media Library, but it can still be inserted as an external image.'\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t\t<p>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'External images can be removed by the external provider without warning and could even have legal compliance issues related to privacy legislation.'\n\t\t\t\t\t) }\n\t\t\t\t</p>\n\t\t\t</VStack>\n\t\t\t<Flex\n\t\t\t\tclassName=\"block-editor-block-lock-modal__actions\"\n\t\t\t\tjustify=\"flex-end\"\n\t\t\t\texpanded={ false }\n\t\t\t>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<Button variant=\"tertiary\" onClick={ onClose }>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t\t<FlexItem>\n\t\t\t\t\t<Button variant=\"primary\" onClick={ onSubmit }>\n\t\t\t\t\t\t{ __( 'Insert' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</FlexItem>\n\t\t\t</Flex>\n\t\t</Modal>\n\t);\n}\n\nexport function MediaPreview( { media, onClick, composite, category } ) {\n\tconst [ showExternalUploadModal, setShowExternalUploadModal ] =\n\t\tuseState( false );\n\tconst [ isHovered, setIsHovered ] = useState( false );\n\tconst [ isInserting, setIsInserting ] = useState( false );\n\tconst [ block, preview ] = useMemo(\n\t\t() => getBlockAndPreviewFromMedia( media, category.mediaType ),\n\t\t[ media, category.mediaType ]\n\t);\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst mediaUpload = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst onMediaInsert = useCallback(\n\t\t( previewBlock ) => {\n\t\t\t// Prevent multiple uploads when we're in the process of inserting.\n\t\t\tif ( isInserting ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst clonedBlock = cloneBlock( previewBlock );\n\t\t\tconst { id, url, caption } = clonedBlock.attributes;\n\t\t\t// Media item already exists in library, so just insert it.\n\t\t\tif ( !! id ) {\n\t\t\t\tonClick( clonedBlock );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetIsInserting( true );\n\t\t\t// Media item does not exist in library, so try to upload it.\n\t\t\t// Fist fetch the image data. This may fail if the image host\n\t\t\t// doesn't allow CORS with the domain.\n\t\t\t// If this happens, we insert the image block using the external\n\t\t\t// URL and let the user know about the possible implications.\n\t\t\twindow\n\t\t\t\t.fetch( url )\n\t\t\t\t.then( ( response ) => response.blob() )\n\t\t\t\t.then( ( blob ) => {\n\t\t\t\t\tmediaUpload( {\n\t\t\t\t\t\tfilesList: [ blob ],\n\t\t\t\t\t\tadditionalData: { caption },\n\t\t\t\t\t\tonFileChange( [ img ] ) {\n\t\t\t\t\t\t\tif ( isBlobURL( img.url ) ) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tonClick( {\n\t\t\t\t\t\t\t\t...clonedBlock,\n\t\t\t\t\t\t\t\tattributes: {\n\t\t\t\t\t\t\t\t\t...clonedBlock.attributes,\n\t\t\t\t\t\t\t\t\tid: img.id,\n\t\t\t\t\t\t\t\t\turl: img.url,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\t\t\t\t__( 'Image uploaded and inserted.' ),\n\t\t\t\t\t\t\t\t{ type: 'snackbar' }\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tsetIsInserting( false );\n\t\t\t\t\t\t},\n\t\t\t\t\t\tallowedTypes: ALLOWED_MEDIA_TYPES,\n\t\t\t\t\t\tonError( message ) {\n\t\t\t\t\t\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t\t\t\t\t\t\tsetIsInserting( false );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => {\n\t\t\t\t\tsetShowExternalUploadModal( true );\n\t\t\t\t\tsetIsInserting( false );\n\t\t\t\t} );\n\t\t},\n\t\t[\n\t\t\tisInserting,\n\t\t\tonClick,\n\t\t\tmediaUpload,\n\t\t\tcreateErrorNotice,\n\t\t\tcreateSuccessNotice,\n\t\t]\n\t);\n\tconst title = media.title?.rendered || media.title;\n\tlet truncatedTitle;\n\tif ( title.length > MAXIMUM_TITLE_LENGTH ) {\n\t\tconst omission = '...';\n\t\ttruncatedTitle =\n\t\t\ttitle.slice( 0, MAXIMUM_TITLE_LENGTH - omission.length ) + omission;\n\t}\n\tconst onMouseEnter = useCallback( () => setIsHovered( true ), [] );\n\tconst onMouseLeave = useCallback( () => setIsHovered( false ), [] );\n\treturn (\n\t\t<>\n\t\t\t<InserterDraggableBlocks isEnabled={ true } blocks={ [ block ] }>\n\t\t\t\t{ ( { draggable, onDragStart, onDragEnd } ) => (\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-inserter__media-list__list-item',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-hovered': isHovered,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tdraggable={ draggable }\n\t\t\t\t\t\tonDragStart={ onDragStart }\n\t\t\t\t\t\tonDragEnd={ onDragEnd }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Tooltip text={ truncatedTitle || title }>\n\t\t\t\t\t\t\t{ /* Adding `is-hovered` class to the wrapper element is needed\n\t\t\t\t\t\t\tbecause the options Popover is rendered outside of this node. */ }\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tonMouseEnter={ onMouseEnter }\n\t\t\t\t\t\t\t\tonMouseLeave={ onMouseLeave }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<CompositeItem\n\t\t\t\t\t\t\t\t\trole=\"option\"\n\t\t\t\t\t\t\t\t\tas=\"div\"\n\t\t\t\t\t\t\t\t\t{ ...composite }\n\t\t\t\t\t\t\t\t\tclassName=\"block-editor-inserter__media-list__item\"\n\t\t\t\t\t\t\t\t\tonClick={ () => onMediaInsert( block ) }\n\t\t\t\t\t\t\t\t\taria-label={ title }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<div className=\"block-editor-inserter__media-list__item-preview\">\n\t\t\t\t\t\t\t\t\t\t{ preview }\n\t\t\t\t\t\t\t\t\t\t{ isInserting && (\n\t\t\t\t\t\t\t\t\t\t\t<div className=\"block-editor-inserter__media-list__item-preview-spinner\">\n\t\t\t\t\t\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</CompositeItem>\n\t\t\t\t\t\t\t\t{ ! isInserting && (\n\t\t\t\t\t\t\t\t\t<MediaPreviewOptions\n\t\t\t\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t\t\t\t\tmedia={ media }\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</div>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</InserterDraggableBlocks>\n\t\t\t{ showExternalUploadModal && (\n\t\t\t\t<InsertExternalImageModal\n\t\t\t\t\tonClose={ () => setShowExternalUploadModal( false ) }\n\t\t\t\t\tonSubmit={ () => {\n\t\t\t\t\t\tonClick( cloneBlock( block ) );\n\t\t\t\t\t\tcreateSuccessNotice( __( 'Image inserted.' ), {\n\t\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\t} );\n\t\t\t\t\t\tsetShowExternalUploadModal( false );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
@@ -13,6 +13,8 @@ var _classnames = _interopRequireDefault(require("classnames"));
13
13
 
14
14
  var _components = require("@wordpress/components");
15
15
 
16
+ var _icons = require("@wordpress/icons");
17
+
16
18
  var _i18n = require("@wordpress/i18n");
17
19
 
18
20
  var _dom = require("@wordpress/dom");
@@ -131,7 +133,7 @@ const noop = () => {};
131
133
 
132
134
 
133
135
  function LinkControl(_ref) {
134
- var _value$url, _value$url$trim, _currentUrlInputValue;
136
+ var _currentUrlInputValue, _value$url, _value$url$trim;
135
137
 
136
138
  let {
137
139
  searchInputPlaceholder,
@@ -139,7 +141,6 @@ function LinkControl(_ref) {
139
141
  settings = _constants.DEFAULT_LINK_SETTINGS,
140
142
  onChange = noop,
141
143
  onRemove,
142
- onCancel,
143
144
  noDirectEntry = false,
144
145
  showSuggestions = true,
145
146
  showInitialSuggestions,
@@ -200,7 +201,6 @@ function LinkControl(_ref) {
200
201
  nextFocusTarget.focus();
201
202
  isEndingEditWithFocus.current = false;
202
203
  }, [isEditingLink, isCreatingPage]);
203
- const hasLinkValue = (value === null || value === void 0 ? void 0 : (_value$url = value.url) === null || _value$url === void 0 ? void 0 : (_value$url$trim = _value$url.trim()) === null || _value$url$trim === void 0 ? void 0 : _value$url$trim.length) > 0;
204
204
  /**
205
205
  * Cancels editing state and marks that focus may need to be restored after
206
206
  * the next render, if focus was within the wrapper when editing finished.
@@ -243,28 +243,6 @@ function LinkControl(_ref) {
243
243
  }
244
244
  };
245
245
 
246
- const resetInternalValues = () => {
247
- setInternalUrlInputValue(value === null || value === void 0 ? void 0 : value.url);
248
- setInternalTextInputValue(value === null || value === void 0 ? void 0 : value.title);
249
- };
250
-
251
- const handleCancel = event => {
252
- event.preventDefault();
253
- event.stopPropagation(); // Ensure that any unsubmitted input changes are reset.
254
-
255
- resetInternalValues();
256
-
257
- if (hasLinkValue) {
258
- // If there is a link then exist editing mode and show preview.
259
- stopEditing();
260
- } else {
261
- // If there is no link value, then remove the link entirely.
262
- onRemove === null || onRemove === void 0 ? void 0 : onRemove();
263
- }
264
-
265
- onCancel === null || onCancel === void 0 ? void 0 : onCancel();
266
- };
267
-
268
246
  const currentUrlInputValue = propInputValue || internalUrlInputValue;
269
247
  const currentInputIsEmpty = !(currentUrlInputValue !== null && currentUrlInputValue !== void 0 && (_currentUrlInputValue = currentUrlInputValue.trim()) !== null && _currentUrlInputValue !== void 0 && _currentUrlInputValue.length);
270
248
  const shownUnlinkControl = onRemove && value && !isEditingLink && !isCreatingPage;
@@ -272,15 +250,14 @@ function LinkControl(_ref) {
272
250
  // and it isn't just empty whitespace.
273
251
  // See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.
274
252
 
275
- const showTextControl = hasLinkValue && hasTextControl;
276
- const isEditing = (isEditingLink || !value) && !isCreatingPage;
253
+ const showTextControl = (value === null || value === void 0 ? void 0 : (_value$url = value.url) === null || _value$url === void 0 ? void 0 : (_value$url$trim = _value$url.trim()) === null || _value$url$trim === void 0 ? void 0 : _value$url$trim.length) > 0 && hasTextControl;
277
254
  return (0, _element.createElement)("div", {
278
255
  tabIndex: -1,
279
256
  ref: wrapperNode,
280
257
  className: "block-editor-link-control"
281
258
  }, isCreatingPage && (0, _element.createElement)("div", {
282
259
  className: "block-editor-link-control__loading"
283
- }, (0, _element.createElement)(_components.Spinner, null), " ", (0, _i18n.__)('Creating'), "\u2026"), isEditing && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", {
260
+ }, (0, _element.createElement)(_components.Spinner, null), " ", (0, _i18n.__)('Creating'), "\u2026"), (isEditingLink || !value) && !isCreatingPage && (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("div", {
284
261
  className: (0, _classnames.default)({
285
262
  'block-editor-link-control__search-input-wrapper': true,
286
263
  'has-text-control': showTextControl
@@ -309,7 +286,16 @@ function LinkControl(_ref) {
309
286
  withURLSuggestion: !noURLSuggestion,
310
287
  createSuggestionButtonText: createSuggestionButtonText,
311
288
  useLabel: showTextControl
312
- })), errorMessage && (0, _element.createElement)(_components.Notice, {
289
+ }, (0, _element.createElement)("div", {
290
+ className: "block-editor-link-control__search-actions"
291
+ }, (0, _element.createElement)(_components.Button, {
292
+ onClick: handleSubmit,
293
+ label: (0, _i18n.__)('Submit'),
294
+ icon: _icons.keyboardReturn,
295
+ className: "block-editor-link-control__search-submit",
296
+ disabled: currentInputIsEmpty // Disallow submitting empty values.
297
+
298
+ })))), errorMessage && (0, _element.createElement)(_components.Notice, {
313
299
  className: "block-editor-link-control__search-error",
314
300
  status: "error",
315
301
  isDismissible: false
@@ -321,26 +307,13 @@ function LinkControl(_ref) {
321
307
  hasRichPreviews: hasRichPreviews,
322
308
  hasUnlinkControl: shownUnlinkControl,
323
309
  onRemove: onRemove
324
- }), (0, _element.createElement)("div", {
325
- className: "block-editor-link-control__drawer"
326
- }, showSettingsDrawer && (0, _element.createElement)("div", {
310
+ }), showSettingsDrawer && (0, _element.createElement)("div", {
327
311
  className: "block-editor-link-control__tools"
328
312
  }, (0, _element.createElement)(_settingsDrawer.default, {
329
313
  value: value,
330
314
  settings: settings,
331
315
  onChange: onChange
332
- })), isEditing && (0, _element.createElement)("div", {
333
- className: "block-editor-link-control__search-actions"
334
- }, (0, _element.createElement)(_components.Button, {
335
- variant: "primary",
336
- onClick: handleSubmit,
337
- className: "xblock-editor-link-control__search-submit",
338
- disabled: currentInputIsEmpty // Disallow submitting empty values.
339
-
340
- }, (0, _i18n.__)('Apply')), (0, _element.createElement)(_components.Button, {
341
- variant: "tertiary",
342
- onClick: handleCancel
343
- }, (0, _i18n.__)('Cancel')))), renderControlBottom && renderControlBottom());
316
+ })), renderControlBottom && renderControlBottom());
344
317
  }
345
318
 
346
319
  LinkControl.ViewerFill = _viewerSlot.ViewerFill;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/link-control/index.js"],"names":["noop","LinkControl","searchInputPlaceholder","value","settings","DEFAULT_LINK_SETTINGS","onChange","onRemove","onCancel","noDirectEntry","showSuggestions","showInitialSuggestions","forceIsEditingLink","createSuggestion","withCreateSuggestion","inputValue","propInputValue","suggestionsQuery","noURLSuggestion","createSuggestionButtonText","hasRichPreviews","hasTextControl","renderControlBottom","undefined","isMounting","wrapperNode","textInputRef","isEndingEditWithFocus","internalUrlInputValue","setInternalUrlInputValue","url","internalTextInputValue","setInternalTextInputValue","title","isEditingLink","setIsEditingLink","createPage","isCreatingPage","errorMessage","current","whichFocusTargetIndex","nextFocusTarget","focus","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","ENTER","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showSettingsDrawer","showTextControl","isEditing","ViewerFill"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,WAAT,OAoBI;AAAA;;AAAA,MApBkB;AACrBC,IAAAA,sBADqB;AAErBC,IAAAA,KAFqB;AAGrBC,IAAAA,QAAQ,GAAGC,gCAHU;AAIrBC,IAAAA,QAAQ,GAAGN,IAJU;AAKrBO,IAAAA,QALqB;AAMrBC,IAAAA,QANqB;AAOrBC,IAAAA,aAAa,GAAG,KAPK;AAQrBC,IAAAA,eAAe,GAAG,IARG;AASrBC,IAAAA,sBATqB;AAUrBC,IAAAA,kBAVqB;AAWrBC,IAAAA,gBAXqB;AAYrBC,IAAAA,oBAZq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AA,OAAO,EAAGd,YAFX;AAGC,IAAA,SAAS,EAAC,2CAHX;AAIC,IAAA,QAAQ,EAAGM,mBAJZ,CAIkC;;AAJlC,KAMG,cAAI,OAAJ,CANH,CADD,EASC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGG;AAArC,KACG,cAAI,QAAJ,CADH,CATD,CAZF,CA1ED,EAsGGzC,mBAAmB,IAAIA,mBAAmB,EAtG7C,CADD;AA0GA;;AAEDrB,WAAW,CAACoE,UAAZ,GAAyBA,sBAAzB;eAEepE,W","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Spinner, Notice, TextControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useEffect } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\nimport { ENTER } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport useCreatePage from './use-create-page';\nimport useInternalInputValue from './use-internal-input-value';\nimport { ViewerFill } from './viewer-slot';\nimport { DEFAULT_LINK_SETTINGS } from './constants';\n\n/**\n * Default properties associated with a link control value.\n *\n * @typedef WPLinkControlDefaultValue\n *\n * @property {string} url Link URL.\n * @property {string=} title Link title.\n * @property {boolean=} opensInNewTab Whether link should open in a new browser\n * tab. This value is only assigned if not\n * providing a custom `settings` prop.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Custom settings values associated with a link.\n *\n * @typedef {{[setting:string]:any}} WPLinkControlSettingsValue\n */\n/* eslint-enable */\n\n/**\n * Custom settings values associated with a link.\n *\n * @typedef WPLinkControlSetting\n *\n * @property {string} id Identifier to use as property for setting value.\n * @property {string} title Human-readable label to show in user interface.\n */\n\n/**\n * Properties associated with a link control value, composed as a union of the\n * default properties and any custom settings values.\n *\n * @typedef {WPLinkControlDefaultValue&WPLinkControlSettingsValue} WPLinkControlValue\n */\n\n/** @typedef {(nextValue:WPLinkControlValue)=>void} WPLinkControlOnChangeProp */\n\n/**\n * Properties associated with a search suggestion used within the LinkControl.\n *\n * @typedef WPLinkControlSuggestion\n *\n * @property {string} id Identifier to use to uniquely identify the suggestion.\n * @property {string} type Identifies the type of the suggestion (eg: `post`,\n * `page`, `url`...etc)\n * @property {string} title Human-readable label to show in user interface.\n * @property {string} url A URL for the suggestion.\n */\n\n/** @typedef {(title:string)=>WPLinkControlSuggestion} WPLinkControlCreateSuggestionProp */\n\n/**\n * @typedef WPLinkControlProps\n *\n * @property {(WPLinkControlSetting[])=} settings An array of settings objects. Each object will used to\n * render a `ToggleControl` for that setting.\n * @property {boolean=} forceIsEditingLink If passed as either `true` or `false`, controls the\n * internal editing state of the component to respective\n * show or not show the URL input field.\n * @property {WPLinkControlValue=} value Current link value.\n * @property {WPLinkControlOnChangeProp=} onChange Value change handler, called with the updated value if\n * the user selects a new link or updates settings.\n * @property {boolean=} noDirectEntry Whether to allow turning a URL-like search query directly into a link.\n * @property {boolean=} showSuggestions Whether to present suggestions when typing the URL.\n * @property {boolean=} showInitialSuggestions Whether to present initial suggestions immediately.\n * @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.\n * @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.\n * @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.\n * @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title.\n * @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.\n * @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.\n */\n\nconst noop = () => {};\n\n/**\n * Renders a link control. A link control is a controlled input which maintains\n * a value associated with a link (HTML anchor element) and relevant settings\n * for how that link is expected to behave.\n *\n * @param {WPLinkControlProps} props Component props.\n */\nfunction LinkControl( {\n\tsearchInputPlaceholder,\n\tvalue,\n\tsettings = DEFAULT_LINK_SETTINGS,\n\tonChange = noop,\n\tonRemove,\n\tonCancel,\n\tnoDirectEntry = false,\n\tshowSuggestions = true,\n\tshowInitialSuggestions,\n\tforceIsEditingLink,\n\tcreateSuggestion,\n\twithCreateSuggestion,\n\tinputValue: propInputValue = '',\n\tsuggestionsQuery = {},\n\tnoURLSuggestion = false,\n\tcreateSuggestionButtonText,\n\thasRichPreviews = false,\n\thasTextControl = false,\n\trenderControlBottom = null,\n} ) {\n\tif ( withCreateSuggestion === undefined && createSuggestion ) {\n\t\twithCreateSuggestion = true;\n\t}\n\n\tconst isMounting = useRef( true );\n\tconst wrapperNode = useRef();\n\tconst textInputRef = useRef();\n\tconst isEndingEditWithFocus = useRef( false );\n\n\tconst [ internalUrlInputValue, setInternalUrlInputValue ] =\n\t\tuseInternalInputValue( value?.url || '' );\n\n\tconst [ internalTextInputValue, setInternalTextInputValue ] =\n\t\tuseInternalInputValue( value?.title || '' );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState(\n\t\tforceIsEditingLink !== undefined\n\t\t\t? forceIsEditingLink\n\t\t\t: ! value || ! value.url\n\t);\n\n\tconst { createPage, isCreatingPage, errorMessage } =\n\t\tuseCreatePage( createSuggestion );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tforceIsEditingLink !== undefined &&\n\t\t\tforceIsEditingLink !== isEditingLink\n\t\t) {\n\t\t\tsetIsEditingLink( forceIsEditingLink );\n\t\t}\n\t}, [ forceIsEditingLink ] );\n\n\tuseEffect( () => {\n\t\t// We don't auto focus into the Link UI on mount\n\t\t// because otherwise using the keyboard to select text\n\t\t// *within* the link format is not possible.\n\t\tif ( isMounting.current ) {\n\t\t\tisMounting.current = false;\n\t\t\treturn;\n\t\t}\n\t\t// Unless we are mounting, we always want to focus either:\n\t\t// - the URL input\n\t\t// - the first focusable element in the Link UI.\n\t\t// But in editing mode if there is a text input present then\n\t\t// the URL input is at index 1. If not then it is at index 0.\n\t\tconst whichFocusTargetIndex = textInputRef?.current ? 1 : 0;\n\n\t\t// Scenario - when:\n\t\t// - switching between editable and non editable LinkControl\n\t\t// - clicking on a link\n\t\t// ...then move focus to the *first* element to avoid focus loss\n\t\t// and to ensure focus is *within* the Link UI.\n\t\tconst nextFocusTarget =\n\t\t\tfocus.focusable.find( wrapperNode.current )[\n\t\t\t\twhichFocusTargetIndex\n\t\t\t] || wrapperNode.current;\n\n\t\tnextFocusTarget.focus();\n\n\t\tisEndingEditWithFocus.current = false;\n\t}, [ isEditingLink, isCreatingPage ] );\n\n\tconst hasLinkValue = value?.url?.trim()?.length > 0;\n\n\t/**\n\t * Cancels editing state and marks that focus may need to be restored after\n\t * the next render, if focus was within the wrapper when editing finished.\n\t */\n\tconst stopEditing = () => {\n\t\tisEndingEditWithFocus.current = !! wrapperNode.current?.contains(\n\t\t\twrapperNode.current.ownerDocument.activeElement\n\t\t);\n\n\t\tsetIsEditingLink( false );\n\t};\n\n\tconst handleSelectSuggestion = ( updatedValue ) => {\n\t\tonChange( {\n\t\t\t...updatedValue,\n\t\t\ttitle: internalTextInputValue || updatedValue?.title,\n\t\t} );\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif (\n\t\t\tcurrentUrlInputValue !== value?.url ||\n\t\t\tinternalTextInputValue !== value?.title\n\t\t) {\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t\ttitle: internalTextInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t! currentInputIsEmpty // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\thandleSubmit();\n\t\t}\n\t};\n\n\tconst resetInternalValues = () => {\n\t\tsetInternalUrlInputValue( value?.url );\n\t\tsetInternalTextInputValue( value?.title );\n\t};\n\n\tconst handleCancel = ( event ) => {\n\t\tevent.preventDefault();\n\t\tevent.stopPropagation();\n\n\t\t// Ensure that any unsubmitted input changes are reset.\n\t\tresetInternalValues();\n\n\t\tif ( hasLinkValue ) {\n\t\t\t// If there is a link then exist editing mode and show preview.\n\t\t\tstopEditing();\n\t\t} else {\n\t\t\t// If there is no link value, then remove the link entirely.\n\t\t\tonRemove?.();\n\t\t}\n\n\t\tonCancel?.();\n\t};\n\n\tconst currentUrlInputValue = propInputValue || internalUrlInputValue;\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showSettingsDrawer = !! settings?.length;\n\n\t// Only show text control once a URL value has been committed\n\t// and it isn't just empty whitespace.\n\t// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.\n\tconst showTextControl = hasLinkValue && hasTextControl;\n\n\tconst isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;\n\treturn (\n\t\t<div\n\t\t\ttabIndex={ -1 }\n\t\t\tref={ wrapperNode }\n\t\t\tclassName=\"block-editor-link-control\"\n\t\t>\n\t\t\t{ isCreatingPage && (\n\t\t\t\t<div className=\"block-editor-link-control__loading\">\n\t\t\t\t\t<Spinner /> { __( 'Creating' ) }…\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ isEditing && (\n\t\t\t\t<>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t\t'block-editor-link-control__search-input-wrapper': true,\n\t\t\t\t\t\t\t'has-text-control': showTextControl,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showTextControl && (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tref={ textInputRef }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__text-content\"\n\t\t\t\t\t\t\t\tlabel=\"Text\"\n\t\t\t\t\t\t\t\tvalue={ internalTextInputValue }\n\t\t\t\t\t\t\t\tonChange={ setInternalTextInputValue }\n\t\t\t\t\t\t\t\tonKeyDown={ handleSubmitWithEnter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\n\t\t\t\t\t\t<LinkControlSearchInput\n\t\t\t\t\t\t\tcurrentLink={ value }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__search-input\"\n\t\t\t\t\t\t\tplaceholder={ searchInputPlaceholder }\n\t\t\t\t\t\t\tvalue={ currentUrlInputValue }\n\t\t\t\t\t\t\twithCreateSuggestion={ withCreateSuggestion }\n\t\t\t\t\t\t\tonCreateSuggestion={ createPage }\n\t\t\t\t\t\t\tonChange={ setInternalUrlInputValue }\n\t\t\t\t\t\t\tonSelect={ handleSelectSuggestion }\n\t\t\t\t\t\t\tshowInitialSuggestions={ showInitialSuggestions }\n\t\t\t\t\t\t\tallowDirectEntry={ ! noDirectEntry }\n\t\t\t\t\t\t\tshowSuggestions={ showSuggestions }\n\t\t\t\t\t\t\tsuggestionsQuery={ suggestionsQuery }\n\t\t\t\t\t\t\twithURLSuggestion={ ! noURLSuggestion }\n\t\t\t\t\t\t\tcreateSuggestionButtonText={\n\t\t\t\t\t\t\t\tcreateSuggestionButtonText\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tuseLabel={ showTextControl }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ errorMessage && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-error\"\n\t\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t{ value && ! isEditingLink && ! isCreatingPage && (\n\t\t\t\t<LinkPreview\n\t\t\t\t\tkey={ value?.url } // force remount when URL changes to avoid race conditions for rich previews\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonEditClick={ () => setIsEditingLink( true ) }\n\t\t\t\t\thasRichPreviews={ hasRichPreviews }\n\t\t\t\t\thasUnlinkControl={ shownUnlinkControl }\n\t\t\t\t\tonRemove={ onRemove }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t<div className=\"block-editor-link-control__drawer\">\n\t\t\t\t{ showSettingsDrawer && (\n\t\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\n\t\t\t\t{ isEditing && (\n\t\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ handleSubmit }\n\t\t\t\t\t\t\tclassName=\"xblock-editor-link-control__search-submit\"\n\t\t\t\t\t\t\tdisabled={ currentInputIsEmpty } // Disallow submitting empty values.\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Apply' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ handleCancel }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\n\t\t\t{ renderControlBottom && renderControlBottom() }\n\t\t</div>\n\t);\n}\n\nLinkControl.ViewerFill = ViewerFill;\n\nexport default LinkControl;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/link-control/index.js"],"names":["noop","LinkControl","searchInputPlaceholder","value","settings","DEFAULT_LINK_SETTINGS","onChange","onRemove","noDirectEntry","showSuggestions","showInitialSuggestions","forceIsEditingLink","createSuggestion","withCreateSuggestion","inputValue","propInputValue","suggestionsQuery","noURLSuggestion","createSuggestionButtonText","hasRichPreviews","hasTextControl","renderControlBottom","undefined","isMounting","wrapperNode","textInputRef","isEndingEditWithFocus","internalUrlInputValue","setInternalUrlInputValue","url","internalTextInputValue","setInternalTextInputValue","title","isEditingLink","setIsEditingLink","createPage","isCreatingPage","errorMessage","current","whichFocusTargetIndex","nextFocusTarget","focus","focusable","find","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","ENTER","currentInputIsEmpty","preventDefault","trim","length","shownUnlinkControl","showSettingsDrawer","showTextControl","keyboardReturn","ViewerFill"],"mappings":";;;;;;;;;AAWA;;AARA;;AAKA;;AACA;;AACA;;AAEA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AACA;AACA;AACA;AACA;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,WAAT,OAmBI;AAAA;;AAAA,MAnBkB;AACrBC,IAAAA,sBADqB;AAErBC,IAAAA,KAFqB;AAGrBC,IAAAA,QAAQ,GAAGC,gCAHU;AAIrBC,IAAAA,QAAQ,GAAGN,IAJU;AAKrBO,I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AAG,cAAI,QAAJ,CAFT;AAGC,IAAA,IAAI,EAAGa,qBAHR;AAIC,IAAA,SAAS,EAAC,0CAJX;AAKC,IAAA,QAAQ,EAAGP,mBALZ,CAKkC;;AALlC,IADD,CAnBD,CAlBD,CADD,EAiDGnB,YAAY,IACb,4BAAC,kBAAD;AACC,IAAA,SAAS,EAAC,yCADX;AAEC,IAAA,MAAM,EAAC,OAFR;AAGC,IAAA,aAAa,EAAG;AAHjB,KAKGA,YALH,CAlDF,CAZF,EAyEGlC,KAAK,IAAI,CAAE8B,aAAX,IAA4B,CAAEG,cAA9B,IACD,4BAAC,oBAAD;AACC,IAAA,GAAG,EAAGjC,KAAH,aAAGA,KAAH,uBAAGA,KAAK,CAAE0B,GADd,CACoB;AADpB;AAEC,IAAA,KAAK,EAAG1B,KAFT;AAGC,IAAA,WAAW,EAAG,MAAM+B,gBAAgB,CAAE,IAAF,CAHrC;AAIC,IAAA,eAAe,EAAGf,eAJnB;AAKC,IAAA,gBAAgB,EAAGyC,kBALpB;AAMC,IAAA,QAAQ,EAAGrD;AANZ,IA1EF,EAoFGsD,kBAAkB,IACnB;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,uBAAD;AACC,IAAA,KAAK,EAAG1D,KADT;AAEC,IAAA,QAAQ,EAAGC,QAFZ;AAGC,IAAA,QAAQ,EAAGE;AAHZ,IADD,CArFF,EA6FGe,mBAAmB,IAAIA,mBAAmB,EA7F7C,CADD;AAiGA;;AAEDpB,WAAW,CAAC+D,UAAZ,GAAyBA,sBAAzB;eAEe/D,W","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Spinner, Notice, TextControl } from '@wordpress/components';\nimport { keyboardReturn } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { useRef, useState, useEffect } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\nimport { ENTER } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport useCreatePage from './use-create-page';\nimport useInternalInputValue from './use-internal-input-value';\nimport { ViewerFill } from './viewer-slot';\nimport { DEFAULT_LINK_SETTINGS } from './constants';\n\n/**\n * Default properties associated with a link control value.\n *\n * @typedef WPLinkControlDefaultValue\n *\n * @property {string} url Link URL.\n * @property {string=} title Link title.\n * @property {boolean=} opensInNewTab Whether link should open in a new browser\n * tab. This value is only assigned if not\n * providing a custom `settings` prop.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Custom settings values associated with a link.\n *\n * @typedef {{[setting:string]:any}} WPLinkControlSettingsValue\n */\n/* eslint-enable */\n\n/**\n * Custom settings values associated with a link.\n *\n * @typedef WPLinkControlSetting\n *\n * @property {string} id Identifier to use as property for setting value.\n * @property {string} title Human-readable label to show in user interface.\n */\n\n/**\n * Properties associated with a link control value, composed as a union of the\n * default properties and any custom settings values.\n *\n * @typedef {WPLinkControlDefaultValue&WPLinkControlSettingsValue} WPLinkControlValue\n */\n\n/** @typedef {(nextValue:WPLinkControlValue)=>void} WPLinkControlOnChangeProp */\n\n/**\n * Properties associated with a search suggestion used within the LinkControl.\n *\n * @typedef WPLinkControlSuggestion\n *\n * @property {string} id Identifier to use to uniquely identify the suggestion.\n * @property {string} type Identifies the type of the suggestion (eg: `post`,\n * `page`, `url`...etc)\n * @property {string} title Human-readable label to show in user interface.\n * @property {string} url A URL for the suggestion.\n */\n\n/** @typedef {(title:string)=>WPLinkControlSuggestion} WPLinkControlCreateSuggestionProp */\n\n/**\n * @typedef WPLinkControlProps\n *\n * @property {(WPLinkControlSetting[])=} settings An array of settings objects. Each object will used to\n * render a `ToggleControl` for that setting.\n * @property {boolean=} forceIsEditingLink If passed as either `true` or `false`, controls the\n * internal editing state of the component to respective\n * show or not show the URL input field.\n * @property {WPLinkControlValue=} value Current link value.\n * @property {WPLinkControlOnChangeProp=} onChange Value change handler, called with the updated value if\n * the user selects a new link or updates settings.\n * @property {boolean=} noDirectEntry Whether to allow turning a URL-like search query directly into a link.\n * @property {boolean=} showSuggestions Whether to present suggestions when typing the URL.\n * @property {boolean=} showInitialSuggestions Whether to present initial suggestions immediately.\n * @property {boolean=} withCreateSuggestion Whether to allow creation of link value from suggestion.\n * @property {Object=} suggestionsQuery Query parameters to pass along to wp.blockEditor.__experimentalFetchLinkSuggestions.\n * @property {boolean=} noURLSuggestion Whether to add a fallback suggestion which treats the search query as a URL.\n * @property {boolean=} hasTextControl Whether to add a text field to the UI to update the value.title.\n * @property {string|Function|undefined} createSuggestionButtonText The text to use in the button that calls createSuggestion.\n * @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.\n */\n\nconst noop = () => {};\n\n/**\n * Renders a link control. A link control is a controlled input which maintains\n * a value associated with a link (HTML anchor element) and relevant settings\n * for how that link is expected to behave.\n *\n * @param {WPLinkControlProps} props Component props.\n */\nfunction LinkControl( {\n\tsearchInputPlaceholder,\n\tvalue,\n\tsettings = DEFAULT_LINK_SETTINGS,\n\tonChange = noop,\n\tonRemove,\n\tnoDirectEntry = false,\n\tshowSuggestions = true,\n\tshowInitialSuggestions,\n\tforceIsEditingLink,\n\tcreateSuggestion,\n\twithCreateSuggestion,\n\tinputValue: propInputValue = '',\n\tsuggestionsQuery = {},\n\tnoURLSuggestion = false,\n\tcreateSuggestionButtonText,\n\thasRichPreviews = false,\n\thasTextControl = false,\n\trenderControlBottom = null,\n} ) {\n\tif ( withCreateSuggestion === undefined && createSuggestion ) {\n\t\twithCreateSuggestion = true;\n\t}\n\n\tconst isMounting = useRef( true );\n\tconst wrapperNode = useRef();\n\tconst textInputRef = useRef();\n\tconst isEndingEditWithFocus = useRef( false );\n\n\tconst [ internalUrlInputValue, setInternalUrlInputValue ] =\n\t\tuseInternalInputValue( value?.url || '' );\n\n\tconst [ internalTextInputValue, setInternalTextInputValue ] =\n\t\tuseInternalInputValue( value?.title || '' );\n\n\tconst [ isEditingLink, setIsEditingLink ] = useState(\n\t\tforceIsEditingLink !== undefined\n\t\t\t? forceIsEditingLink\n\t\t\t: ! value || ! value.url\n\t);\n\n\tconst { createPage, isCreatingPage, errorMessage } =\n\t\tuseCreatePage( createSuggestion );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tforceIsEditingLink !== undefined &&\n\t\t\tforceIsEditingLink !== isEditingLink\n\t\t) {\n\t\t\tsetIsEditingLink( forceIsEditingLink );\n\t\t}\n\t}, [ forceIsEditingLink ] );\n\n\tuseEffect( () => {\n\t\t// We don't auto focus into the Link UI on mount\n\t\t// because otherwise using the keyboard to select text\n\t\t// *within* the link format is not possible.\n\t\tif ( isMounting.current ) {\n\t\t\tisMounting.current = false;\n\t\t\treturn;\n\t\t}\n\t\t// Unless we are mounting, we always want to focus either:\n\t\t// - the URL input\n\t\t// - the first focusable element in the Link UI.\n\t\t// But in editing mode if there is a text input present then\n\t\t// the URL input is at index 1. If not then it is at index 0.\n\t\tconst whichFocusTargetIndex = textInputRef?.current ? 1 : 0;\n\n\t\t// Scenario - when:\n\t\t// - switching between editable and non editable LinkControl\n\t\t// - clicking on a link\n\t\t// ...then move focus to the *first* element to avoid focus loss\n\t\t// and to ensure focus is *within* the Link UI.\n\t\tconst nextFocusTarget =\n\t\t\tfocus.focusable.find( wrapperNode.current )[\n\t\t\t\twhichFocusTargetIndex\n\t\t\t] || wrapperNode.current;\n\n\t\tnextFocusTarget.focus();\n\n\t\tisEndingEditWithFocus.current = false;\n\t}, [ isEditingLink, isCreatingPage ] );\n\n\t/**\n\t * Cancels editing state and marks that focus may need to be restored after\n\t * the next render, if focus was within the wrapper when editing finished.\n\t */\n\tconst stopEditing = () => {\n\t\tisEndingEditWithFocus.current = !! wrapperNode.current?.contains(\n\t\t\twrapperNode.current.ownerDocument.activeElement\n\t\t);\n\n\t\tsetIsEditingLink( false );\n\t};\n\n\tconst handleSelectSuggestion = ( updatedValue ) => {\n\t\tonChange( {\n\t\t\t...updatedValue,\n\t\t\ttitle: internalTextInputValue || updatedValue?.title,\n\t\t} );\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif (\n\t\t\tcurrentUrlInputValue !== value?.url ||\n\t\t\tinternalTextInputValue !== value?.title\n\t\t) {\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t\ttitle: internalTextInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\t\tif (\n\t\t\tkeyCode === ENTER &&\n\t\t\t! currentInputIsEmpty // Disallow submitting empty values.\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\thandleSubmit();\n\t\t}\n\t};\n\n\tconst currentUrlInputValue = propInputValue || internalUrlInputValue;\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showSettingsDrawer = !! settings?.length;\n\n\t// Only show text control once a URL value has been committed\n\t// and it isn't just empty whitespace.\n\t// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.\n\tconst showTextControl = value?.url?.trim()?.length > 0 && hasTextControl;\n\n\treturn (\n\t\t<div\n\t\t\ttabIndex={ -1 }\n\t\t\tref={ wrapperNode }\n\t\t\tclassName=\"block-editor-link-control\"\n\t\t>\n\t\t\t{ isCreatingPage && (\n\t\t\t\t<div className=\"block-editor-link-control__loading\">\n\t\t\t\t\t<Spinner /> { __( 'Creating' ) }…\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ ( isEditingLink || ! value ) && ! isCreatingPage && (\n\t\t\t\t<>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t\t\t'block-editor-link-control__search-input-wrapper': true,\n\t\t\t\t\t\t\t'has-text-control': showTextControl,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showTextControl && (\n\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\tref={ textInputRef }\n\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__text-content\"\n\t\t\t\t\t\t\t\tlabel=\"Text\"\n\t\t\t\t\t\t\t\tvalue={ internalTextInputValue }\n\t\t\t\t\t\t\t\tonChange={ setInternalTextInputValue }\n\t\t\t\t\t\t\t\tonKeyDown={ handleSubmitWithEnter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\n\t\t\t\t\t\t<LinkControlSearchInput\n\t\t\t\t\t\t\tcurrentLink={ value }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__search-input\"\n\t\t\t\t\t\t\tplaceholder={ searchInputPlaceholder }\n\t\t\t\t\t\t\tvalue={ currentUrlInputValue }\n\t\t\t\t\t\t\twithCreateSuggestion={ withCreateSuggestion }\n\t\t\t\t\t\t\tonCreateSuggestion={ createPage }\n\t\t\t\t\t\t\tonChange={ setInternalUrlInputValue }\n\t\t\t\t\t\t\tonSelect={ handleSelectSuggestion }\n\t\t\t\t\t\t\tshowInitialSuggestions={ showInitialSuggestions }\n\t\t\t\t\t\t\tallowDirectEntry={ ! noDirectEntry }\n\t\t\t\t\t\t\tshowSuggestions={ showSuggestions }\n\t\t\t\t\t\t\tsuggestionsQuery={ suggestionsQuery }\n\t\t\t\t\t\t\twithURLSuggestion={ ! noURLSuggestion }\n\t\t\t\t\t\t\tcreateSuggestionButtonText={\n\t\t\t\t\t\t\t\tcreateSuggestionButtonText\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tuseLabel={ showTextControl }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\tonClick={ handleSubmit }\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Submit' ) }\n\t\t\t\t\t\t\t\t\ticon={ keyboardReturn }\n\t\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\t\t\t\tdisabled={ currentInputIsEmpty } // Disallow submitting empty values.\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</LinkControlSearchInput>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ errorMessage && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-error\"\n\t\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t{ value && ! isEditingLink && ! isCreatingPage && (\n\t\t\t\t<LinkPreview\n\t\t\t\t\tkey={ value?.url } // force remount when URL changes to avoid race conditions for rich previews\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonEditClick={ () => setIsEditingLink( true ) }\n\t\t\t\t\thasRichPreviews={ hasRichPreviews }\n\t\t\t\t\thasUnlinkControl={ shownUnlinkControl }\n\t\t\t\t\tonRemove={ onRemove }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ showSettingsDrawer && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ renderControlBottom && renderControlBottom() }\n\t\t</div>\n\t);\n}\n\nLinkControl.ViewerFill = ViewerFill;\n\nexport default LinkControl;\n"]}
@@ -25,6 +25,8 @@ var _i18n = require("@wordpress/i18n");
25
25
 
26
26
  var _leaf = _interopRequireDefault(require("./leaf"));
27
27
 
28
+ var _useListViewScrollIntoView = _interopRequireDefault(require("./use-list-view-scroll-into-view"));
29
+
28
30
  var _button = require("../block-mover/button");
29
31
 
30
32
  var _blockContents = _interopRequireDefault(require("./block-contents"));
@@ -71,6 +73,7 @@ function ListViewBlock(_ref) {
71
73
  isSyncedBranch
72
74
  } = _ref;
73
75
  const cellRef = (0, _element.useRef)(null);
76
+ const rowRef = (0, _element.useRef)(null);
74
77
  const [isHovered, setIsHovered] = (0, _element.useState)(false);
75
78
  const {
76
79
  clientId
@@ -185,7 +188,15 @@ function ListViewBlock(_ref) {
185
188
  // to alter a block that isn't part of the selection, they're still able
186
189
  // to do so.
187
190
 
188
- const dropdownClientIds = selectedClientIds.includes(clientId) ? selectedClientIds : [clientId];
191
+ const dropdownClientIds = selectedClientIds.includes(clientId) ? selectedClientIds : [clientId]; // Pass in a ref to the row, so that it can be scrolled
192
+ // into view when selected. For long lists, the placeholder for the
193
+ // selected block is also observed, within ListViewLeafPlaceholder.
194
+
195
+ (0, _useListViewScrollIntoView.default)({
196
+ isSelected,
197
+ rowItemRef: rowRef,
198
+ selectedClientIds
199
+ });
189
200
  return (0, _element.createElement)(_leaf.default, {
190
201
  className: classes,
191
202
  onMouseEnter: onMouseEnter,
@@ -199,7 +210,8 @@ function ListViewBlock(_ref) {
199
210
  id: `list-view-block-${clientId}`,
200
211
  "data-block": clientId,
201
212
  isExpanded: canExpand ? isExpanded : undefined,
202
- "aria-selected": !!isSelected || forceSelectionContentLock
213
+ "aria-selected": !!isSelected || forceSelectionContentLock,
214
+ ref: rowRef
203
215
  }, (0, _element.createElement)(_components.__experimentalTreeGridCell, {
204
216
  className: "block-editor-list-view-block__contents-cell",
205
217
  colSpan: colSpan,