@wordpress/block-editor 12.6.0 → 12.7.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 +2 -2
- package/build/autocompleters/block.js +6 -2
- package/build/autocompleters/block.js.map +1 -1
- package/build/components/block-editing-mode/index.js +1 -1
- package/build/components/block-editing-mode/index.js.map +1 -1
- package/build/components/block-list/block.js +4 -2
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/index.js +2 -4
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-parent-selector/index.js +6 -21
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-preview/auto.js +6 -1
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +3 -17
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-toolbar/index.js +4 -34
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/utils.js +56 -51
- package/build/components/block-toolbar/utils.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +4 -2
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-variation-picker/index.native.js +10 -20
- package/build/components/block-variation-picker/index.native.js.map +1 -1
- package/build/components/editor-styles/index.js +2 -2
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +11 -11
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/behaviors-panel.js +66 -0
- package/build/components/global-styles/behaviors-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +118 -4
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +20 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +4 -4
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/inserter/hooks/use-block-types-state.js +6 -2
- package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build/components/inserter/hooks/use-debounced-input.js +5 -7
- package/build/components/inserter/hooks/use-debounced-input.js.map +1 -1
- package/build/components/inserter/hooks/use-patterns-state.js +3 -2
- package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.js +3 -2
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/inserter-list-item/index.js +1 -1
- package/build/components/inserter-list-item/index.js.map +1 -1
- package/build/components/link-control/index.js +47 -6
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/link-preview.js +3 -3
- package/build/components/link-control/link-preview.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +6 -1
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-replace-flow/index.native.js +15 -3
- package/build/components/media-replace-flow/index.native.js.map +1 -1
- package/build/components/rich-text/format-edit.js +57 -28
- package/build/components/rich-text/format-edit.js.map +1 -1
- package/build/components/rich-text/get-rich-text-values.js +11 -18
- package/build/components/rich-text/get-rich-text-values.js.map +1 -1
- package/build/components/spacing-sizes-control/utils.js +2 -2
- package/build/components/spacing-sizes-control/utils.js.map +1 -1
- package/build/hooks/behaviors.js +5 -12
- package/build/hooks/behaviors.js.map +1 -1
- package/build/hooks/border.js +2 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/style.js +11 -2
- package/build/hooks/style.js.map +1 -1
- package/build/private-apis.js +4 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +2 -3
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +4 -71
- package/build/store/selectors.js.map +1 -1
- package/build-module/autocompleters/block.js +7 -3
- package/build-module/autocompleters/block.js.map +1 -1
- package/build-module/components/block-editing-mode/index.js +1 -1
- package/build-module/components/block-editing-mode/index.js.map +1 -1
- package/build-module/components/block-list/block.js +4 -2
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/index.js +2 -3
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -22
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +6 -1
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -18
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +6 -36
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/utils.js +54 -49
- package/build-module/components/block-toolbar/utils.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +4 -2
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-variation-picker/index.native.js +13 -23
- package/build-module/components/block-variation-picker/index.native.js.map +1 -1
- package/build-module/components/editor-styles/index.js +2 -2
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +11 -11
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/behaviors-panel.js +57 -0
- package/build-module/components/global-styles/behaviors-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +115 -5
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -1
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +4 -4
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/inserter/hooks/use-block-types-state.js +7 -3
- package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
- package/build-module/components/inserter/hooks/use-debounced-input.js +5 -7
- package/build-module/components/inserter/hooks/use-debounced-input.js.map +1 -1
- package/build-module/components/inserter/hooks/use-patterns-state.js +3 -2
- package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.js +3 -2
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/inserter-list-item/index.js +1 -1
- package/build-module/components/inserter-list-item/index.js.map +1 -1
- package/build-module/components/link-control/index.js +45 -6
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/link-preview.js +3 -3
- package/build-module/components/link-control/link-preview.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +6 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-replace-flow/index.native.js +15 -3
- package/build-module/components/media-replace-flow/index.native.js.map +1 -1
- package/build-module/components/rich-text/format-edit.js +51 -26
- package/build-module/components/rich-text/format-edit.js.map +1 -1
- package/build-module/components/rich-text/get-rich-text-values.js +13 -18
- package/build-module/components/rich-text/get-rich-text-values.js.map +1 -1
- package/build-module/components/spacing-sizes-control/utils.js +2 -2
- package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
- package/build-module/hooks/behaviors.js +5 -12
- package/build-module/hooks/behaviors.js.map +1 -1
- package/build-module/hooks/border.js +2 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/style.js +11 -2
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +2 -3
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +4 -69
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +18 -5
- package/build-style/style.css +18 -5
- package/package.json +31 -31
- package/src/autocompleters/block.js +21 -6
- package/src/components/block-draggable/test/index.native.js +2 -3
- package/src/components/block-editing-mode/index.js +1 -1
- package/src/components/block-list/block.js +6 -1
- package/src/components/block-list/index.js +3 -6
- package/src/components/block-list/test/block-invalid-warning.native.js +8 -1
- package/src/components/block-mover/test/__snapshots__/index.native.js.snap +24 -0
- package/src/components/block-parent-selector/index.js +30 -42
- package/src/components/block-preview/auto.js +8 -1
- package/src/components/block-preview/style.scss +2 -1
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -13
- package/src/components/block-toolbar/index.js +36 -63
- package/src/components/block-toolbar/utils.js +57 -45
- package/src/components/block-tools/block-contextual-toolbar.js +43 -35
- package/src/components/block-tools/style.scss +17 -5
- package/src/components/block-variation-picker/index.native.js +52 -72
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/editor-styles/index.js +2 -2
- package/src/components/font-sizes/fluid-utils.js +17 -17
- package/src/components/font-sizes/test/fluid-utils.js +6 -6
- package/src/components/global-styles/behaviors-panel.js +71 -0
- package/src/components/global-styles/hooks.js +114 -5
- package/src/components/global-styles/index.js +3 -0
- package/src/components/global-styles/test/typography-utils.js +6 -6
- package/src/components/global-styles/typography-utils.js +4 -4
- package/src/components/global-styles/utils.js +2 -1
- package/src/components/inserter/hooks/use-block-types-state.js +15 -6
- package/src/components/inserter/hooks/use-debounced-input.js +8 -7
- package/src/components/inserter/hooks/use-patterns-state.js +2 -1
- package/src/components/inserter/reusable-blocks-tab.js +4 -1
- package/src/components/inserter-list-item/index.js +3 -1
- package/src/components/link-control/README.md +12 -3
- package/src/components/link-control/index.js +43 -6
- package/src/components/link-control/link-preview.js +6 -4
- package/src/components/link-control/style.scss +3 -2
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/list-view/use-list-view-drop-zone.js +5 -1
- package/src/components/media-replace-flow/index.native.js +12 -3
- package/src/components/media-upload/test/index.native.js +1 -0
- package/src/components/rich-text/format-edit.js +62 -38
- package/src/components/rich-text/get-rich-text-values.js +22 -28
- package/src/components/spacing-sizes-control/test/utils.js +9 -1
- package/src/components/spacing-sizes-control/utils.js +2 -2
- package/src/hooks/behaviors.js +10 -16
- package/src/hooks/border.js +2 -1
- package/src/hooks/style.js +7 -3
- package/src/private-apis.js +2 -0
- package/src/store/actions.js +22 -28
- package/src/store/selectors.js +3 -80
- package/src/store/test/selectors.js +7 -6
|
@@ -21,6 +21,10 @@ var _keycodes = require("@wordpress/keycodes");
|
|
|
21
21
|
|
|
22
22
|
var _isShallowEqual = require("@wordpress/is-shallow-equal");
|
|
23
23
|
|
|
24
|
+
var _data = require("@wordpress/data");
|
|
25
|
+
|
|
26
|
+
var _preferences = require("@wordpress/preferences");
|
|
27
|
+
|
|
24
28
|
var _settingsDrawer = _interopRequireDefault(require("./settings-drawer"));
|
|
25
29
|
|
|
26
30
|
var _searchInput = _interopRequireDefault(require("./search-input"));
|
|
@@ -125,6 +129,9 @@ var _constants = require("./constants");
|
|
|
125
129
|
* @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.
|
|
126
130
|
*/
|
|
127
131
|
const noop = () => {};
|
|
132
|
+
|
|
133
|
+
const PREFERENCE_SCOPE = 'core/block-editor';
|
|
134
|
+
const PREFERENCE_KEY = 'linkControlSettingsDrawer';
|
|
128
135
|
/**
|
|
129
136
|
* Renders a link control. A link control is a controlled input which maintains
|
|
130
137
|
* a value associated with a link (HTML anchor element) and relevant settings
|
|
@@ -133,7 +140,6 @@ const noop = () => {};
|
|
|
133
140
|
* @param {WPLinkControlProps} props Component props.
|
|
134
141
|
*/
|
|
135
142
|
|
|
136
|
-
|
|
137
143
|
function LinkControl({
|
|
138
144
|
searchInputPlaceholder,
|
|
139
145
|
value,
|
|
@@ -159,6 +165,43 @@ function LinkControl({
|
|
|
159
165
|
withCreateSuggestion = true;
|
|
160
166
|
}
|
|
161
167
|
|
|
168
|
+
const [settingsOpen, setSettingsOpen] = (0, _element.useState)(false);
|
|
169
|
+
const {
|
|
170
|
+
advancedSettingsPreference
|
|
171
|
+
} = (0, _data.useSelect)(select => {
|
|
172
|
+
var _prefsStore$get;
|
|
173
|
+
|
|
174
|
+
const prefsStore = select(_preferences.store);
|
|
175
|
+
return {
|
|
176
|
+
advancedSettingsPreference: (_prefsStore$get = prefsStore.get(PREFERENCE_SCOPE, PREFERENCE_KEY)) !== null && _prefsStore$get !== void 0 ? _prefsStore$get : false
|
|
177
|
+
};
|
|
178
|
+
}, []);
|
|
179
|
+
const {
|
|
180
|
+
set: setPreference
|
|
181
|
+
} = (0, _data.useDispatch)(_preferences.store);
|
|
182
|
+
/**
|
|
183
|
+
* Sets the open/closed state of the Advanced Settings Drawer,
|
|
184
|
+
* optionlly persisting the state to the user's preferences.
|
|
185
|
+
*
|
|
186
|
+
* Note that Block Editor components can be consumed by non-WordPress
|
|
187
|
+
* environments which may not have preferences setup.
|
|
188
|
+
* Therefore a local state is also used as a fallback.
|
|
189
|
+
*
|
|
190
|
+
* @param {boolean} prefVal the open/closed state of the Advanced Settings Drawer.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
const setSettingsOpenWithPreference = prefVal => {
|
|
194
|
+
if (setPreference) {
|
|
195
|
+
setPreference(PREFERENCE_SCOPE, PREFERENCE_KEY, prefVal);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
setSettingsOpen(prefVal);
|
|
199
|
+
}; // Block Editor components can be consumed by non-WordPress environments
|
|
200
|
+
// which may not have these preferences setup.
|
|
201
|
+
// Therefore a local state is used as a fallback.
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
const isSettingsOpen = advancedSettingsPreference || settingsOpen;
|
|
162
205
|
const isMounting = (0, _element.useRef)(true);
|
|
163
206
|
const wrapperNode = (0, _element.useRef)();
|
|
164
207
|
const textInputRef = (0, _element.useRef)();
|
|
@@ -166,7 +209,6 @@ function LinkControl({
|
|
|
166
209
|
const settingsKeys = settings.map(({
|
|
167
210
|
id
|
|
168
211
|
}) => id);
|
|
169
|
-
const [settingsOpen, setSettingsOpen] = (0, _element.useState)(false);
|
|
170
212
|
const [internalControlValue, setInternalControlValue, setInternalURLInputValue, setInternalTextInputValue, createSetInternalSettingValueHandler] = (0, _useInternalValue.default)(value);
|
|
171
213
|
const valueHasChanges = value && !(0, _isShallowEqual.isShallowEqualObjects)(internalControlValue, value);
|
|
172
214
|
const [isEditingLink, setIsEditingLink] = (0, _element.useState)(forceIsEditingLink !== undefined ? forceIsEditingLink : !value || !value.url);
|
|
@@ -208,7 +250,6 @@ function LinkControl({
|
|
|
208
250
|
|
|
209
251
|
const stopEditing = () => {
|
|
210
252
|
isEndingEditWithFocus.current = !!wrapperNode.current?.contains(wrapperNode.current.ownerDocument.activeElement);
|
|
211
|
-
setSettingsOpen(false);
|
|
212
253
|
setIsEditingLink(false);
|
|
213
254
|
};
|
|
214
255
|
|
|
@@ -282,7 +323,6 @@ function LinkControl({
|
|
|
282
323
|
const currentUrlInputValue = propInputValue || internalControlValue?.url || '';
|
|
283
324
|
const currentInputIsEmpty = !currentUrlInputValue?.trim()?.length;
|
|
284
325
|
const shownUnlinkControl = onRemove && value && !isEditingLink && !isCreatingPage;
|
|
285
|
-
const showSettings = !!settings?.length && isEditingLink && hasLinkValue;
|
|
286
326
|
const showActions = isEditingLink && hasLinkValue; // Only show text control once a URL value has been committed
|
|
287
327
|
// and it isn't just empty whitespace.
|
|
288
328
|
// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.
|
|
@@ -290,6 +330,7 @@ function LinkControl({
|
|
|
290
330
|
const showTextControl = hasLinkValue && hasTextControl;
|
|
291
331
|
const isEditing = (isEditingLink || !value) && !isCreatingPage;
|
|
292
332
|
const isDisabled = !valueHasChanges || currentInputIsEmpty;
|
|
333
|
+
const showSettings = !!settings?.length && isEditingLink && hasLinkValue;
|
|
293
334
|
return (0, _element.createElement)("div", {
|
|
294
335
|
tabIndex: -1,
|
|
295
336
|
ref: wrapperNode,
|
|
@@ -344,8 +385,8 @@ function LinkControl({
|
|
|
344
385
|
}), showSettings && (0, _element.createElement)("div", {
|
|
345
386
|
className: "block-editor-link-control__tools"
|
|
346
387
|
}, !currentInputIsEmpty && (0, _element.createElement)(_settingsDrawer.default, {
|
|
347
|
-
settingsOpen:
|
|
348
|
-
setSettingsOpen:
|
|
388
|
+
settingsOpen: isSettingsOpen,
|
|
389
|
+
setSettingsOpen: setSettingsOpenWithPreference
|
|
349
390
|
}, (0, _element.createElement)(_settings.default, {
|
|
350
391
|
value: internalControlValue,
|
|
351
392
|
settings: settings,
|
|
@@ -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","settingsKeys","map","id","settingsOpen","setSettingsOpen","internalControlValue","setInternalControlValue","setInternalURLInputValue","setInternalTextInputValue","createSetInternalSettingValueHandler","valueHasChanges","isEditingLink","setIsEditingLink","url","createPage","isCreatingPage","errorMessage","current","nextFocusTarget","focus","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","nonSettingsChanges","Object","keys","reduce","acc","key","includes","title","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","ENTER","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showSettings","showActions","showTextControl","isEditing","isDisabled","ViewerFill"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAUA;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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oBAAD;AACC,IAAA,GAAG,EAAGxC,KAAK,EAAEsC,GADd,CACoB;AADpB;AAEC,IAAA,KAAK,EAAGtC,KAFT;AAGC,IAAA,WAAW,EAAG,MAAMqC,gBAAgB,CAAE,IAAF,CAHrC;AAIC,IAAA,eAAe,EAAGpB,eAJnB;AAKC,IAAA,gBAAgB,EAAG0D,kBALpB;AAMC,IAAA,QAAQ,EAAG,MAAM;AAChBvE,MAAAA,QAAQ;AACRiC,MAAAA,gBAAgB,CAAE,IAAF,CAAhB;AACA;AATF,IAhEF,EA6EGuC,YAAY,IACb;AAAK,IAAA,SAAS,EAAC;AAAf,KACG,CAAEN,mBAAF,IACD,4BAAC,uBAAD;AACC,IAAA,YAAY,EAAG1C,YADhB;AAEC,IAAA,eAAe,EAAGC;AAFnB,KAIC,4BAAC,iBAAD;AACC,IAAA,KAAK,EAAGC,oBADT;AAEC,IAAA,QAAQ,EAAG7B,QAFZ;AAGC,IAAA,QAAQ,EAAGiC,oCAAoC,CAC9CT,YAD8C;AAHhD,IAJD,CAFF,CA9EF,EAgGGoD,WAAW,IACZ;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,OAAO,EAAGG,UAAU,GAAGnF,IAAH,GAAUmE,YAF/B;AAGC,IAAA,SAAS,EAAC,0CAHX;AAIC,qBAAgBgB;AAJjB,KAMG,cAAI,MAAJ,CANH,CADD,EASC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGP;AAArC,KACG,cAAI,QAAJ,CADH,CATD,CAjGF,EAgHGtD,mBAAmB,IAAIA,mBAAmB,EAhH7C,CADD;AAoHA;;AAEDrB,WAAW,CAACmF,UAAZ,GAAyBA,sBAAzB;eAEenF,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';\nimport { isShallowEqualObjects } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport LinkSettings from './settings';\nimport useCreatePage from './use-create-page';\nimport useInternalValue from './use-internal-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 settingsKeys = settings.map( ( { id } ) => id );\n\n\tconst [ settingsOpen, setSettingsOpen ] = useState( false );\n\n\tconst [\n\t\tinternalControlValue,\n\t\tsetInternalControlValue,\n\t\tsetInternalURLInputValue,\n\t\tsetInternalTextInputValue,\n\t\tcreateSetInternalSettingValueHandler,\n\t] = useInternalValue( value );\n\n\tconst valueHasChanges =\n\t\tvalue && ! isShallowEqualObjects( internalControlValue, value );\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\t// Todo: bug if the missing dep is introduced. Will need a fix.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\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\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 )[ 0 ] ||\n\t\t\twrapperNode.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\tsetSettingsOpen( false );\n\t\tsetIsEditingLink( false );\n\t};\n\n\tconst handleSelectSuggestion = ( updatedValue ) => {\n\t\t// Suggestions may contains \"settings\" values (e.g. `opensInNewTab`)\n\t\t// which should not overide any existing settings values set by the\n\t\t// user. This filters out any settings values from the suggestion.\n\t\tconst nonSettingsChanges = Object.keys( updatedValue ).reduce(\n\t\t\t( acc, key ) => {\n\t\t\t\tif ( ! settingsKeys.includes( key ) ) {\n\t\t\t\t\tacc[ key ] = updatedValue[ key ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\n\t\tonChange( {\n\t\t\t...internalControlValue,\n\t\t\t...nonSettingsChanges,\n\t\t\t// As title is not a setting, it must be manually applied\n\t\t\t// in such a way as to preserve the users changes over\n\t\t\t// any \"title\" value provided by the \"suggestion\".\n\t\t\ttitle: internalControlValue?.title || updatedValue?.title,\n\t\t} );\n\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif ( valueHasChanges ) {\n\t\t\t// Submit the original value with new stored values applied\n\t\t\t// on top. URL is a special case as it may also be a prop.\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\t...internalControlValue,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\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\tsetInternalControlValue( value );\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 =\n\t\tpropInputValue || internalControlValue?.url || '';\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showSettings = !! settings?.length && isEditingLink && hasLinkValue;\n\tconst showActions = isEditingLink && hasLinkValue;\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\tconst isDisabled = ! valueHasChanges || currentInputIsEmpty;\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{ 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={ internalControlValue?.title }\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\tsize=\"__unstable-large\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\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\thideLabelFromVision={ ! 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={ () => {\n\t\t\t\t\t\tonRemove();\n\t\t\t\t\t\tsetIsEditingLink( true );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ showSettings && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t{ ! currentInputIsEmpty && (\n\t\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\t\tsettingsOpen={ settingsOpen }\n\t\t\t\t\t\t\tsetSettingsOpen={ setSettingsOpen }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LinkSettings\n\t\t\t\t\t\t\t\tvalue={ internalControlValue }\n\t\t\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\t\t\tonChange={ createSetInternalSettingValueHandler(\n\t\t\t\t\t\t\t\t\tsettingsKeys\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</LinkControlSettingsDrawer>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showActions && (\n\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ isDisabled ? noop : handleSubmit }\n\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button variant=\"tertiary\" onClick={ handleCancel }>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\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","PREFERENCE_SCOPE","PREFERENCE_KEY","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","settingsOpen","setSettingsOpen","advancedSettingsPreference","select","prefsStore","preferencesStore","get","set","setPreference","setSettingsOpenWithPreference","prefVal","isSettingsOpen","isMounting","wrapperNode","textInputRef","isEndingEditWithFocus","settingsKeys","map","id","internalControlValue","setInternalControlValue","setInternalURLInputValue","setInternalTextInputValue","createSetInternalSettingValueHandler","valueHasChanges","isEditingLink","setIsEditingLink","url","createPage","isCreatingPage","errorMessage","current","nextFocusTarget","focus","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","nonSettingsChanges","Object","keys","reduce","acc","key","includes","title","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","ENTER","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showActions","showTextControl","isEditing","isDisabled","showSettings","ViewerFill"],"mappings":";;;;;;;;;AAUA;;AAPA;;AAKA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAC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EAAG,MAAM;AAChBjF,MAAAA,QAAQ;AACR2C,MAAAA,gBAAgB,CAAE,IAAF,CAAhB;AACA;AATF,IAhEF,EA6EG2C,YAAY,IACb;AAAK,IAAA,SAAS,EAAC;AAAf,KACG,CAAEV,mBAAF,IACD,4BAAC,uBAAD;AACC,IAAA,YAAY,EAAGhD,cADhB;AAEC,IAAA,eAAe,EAAGF;AAFnB,KAIC,4BAAC,iBAAD;AACC,IAAA,KAAK,EAAGU,oBADT;AAEC,IAAA,QAAQ,EAAGvC,QAFZ;AAGC,IAAA,QAAQ,EAAG2C,oCAAoC,CAC9CP,YAD8C;AAHhD,IAJD,CAFF,CA9EF,EAgGGiD,WAAW,IACZ;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,OAAO,EAAGG,UAAU,GAAG9F,IAAH,GAAU+E,YAF/B;AAGC,IAAA,SAAS,EAAC,0CAHX;AAIC,qBAAgBe;AAJjB,KAMG,cAAI,MAAJ,CANH,CADD,EASC,4BAAC,kBAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGN;AAArC,KACG,cAAI,QAAJ,CADH,CATD,CAjGF,EAgHGhE,mBAAmB,IAAIA,mBAAmB,EAhH7C,CADD;AAoHA;;AAEDrB,WAAW,CAAC6F,UAAZ,GAAyBA,sBAAzB;eAEe7F,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';\nimport { isShallowEqualObjects } from '@wordpress/is-shallow-equal';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport LinkControlSettingsDrawer from './settings-drawer';\nimport LinkControlSearchInput from './search-input';\nimport LinkPreview from './link-preview';\nimport LinkSettings from './settings';\nimport useCreatePage from './use-create-page';\nimport useInternalValue from './use-internal-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\nconst PREFERENCE_SCOPE = 'core/block-editor';\nconst PREFERENCE_KEY = 'linkControlSettingsDrawer';\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 [ settingsOpen, setSettingsOpen ] = useState( false );\n\n\tconst { advancedSettingsPreference } = useSelect( ( select ) => {\n\t\tconst prefsStore = select( preferencesStore );\n\n\t\treturn {\n\t\t\tadvancedSettingsPreference:\n\t\t\t\tprefsStore.get( PREFERENCE_SCOPE, PREFERENCE_KEY ) ?? false,\n\t\t};\n\t}, [] );\n\n\tconst { set: setPreference } = useDispatch( preferencesStore );\n\n\t/**\n\t * Sets the open/closed state of the Advanced Settings Drawer,\n\t * optionlly persisting the state to the user's preferences.\n\t *\n\t * Note that Block Editor components can be consumed by non-WordPress\n\t * environments which may not have preferences setup.\n\t * Therefore a local state is also used as a fallback.\n\t *\n\t * @param {boolean} prefVal the open/closed state of the Advanced Settings Drawer.\n\t */\n\tconst setSettingsOpenWithPreference = ( prefVal ) => {\n\t\tif ( setPreference ) {\n\t\t\tsetPreference( PREFERENCE_SCOPE, PREFERENCE_KEY, prefVal );\n\t\t}\n\t\tsetSettingsOpen( prefVal );\n\t};\n\n\t// Block Editor components can be consumed by non-WordPress environments\n\t// which may not have these preferences setup.\n\t// Therefore a local state is used as a fallback.\n\tconst isSettingsOpen = advancedSettingsPreference || settingsOpen;\n\n\tconst isMounting = useRef( true );\n\tconst wrapperNode = useRef();\n\tconst textInputRef = useRef();\n\tconst isEndingEditWithFocus = useRef( false );\n\n\tconst settingsKeys = settings.map( ( { id } ) => id );\n\n\tconst [\n\t\tinternalControlValue,\n\t\tsetInternalControlValue,\n\t\tsetInternalURLInputValue,\n\t\tsetInternalTextInputValue,\n\t\tcreateSetInternalSettingValueHandler,\n\t] = useInternalValue( value );\n\n\tconst valueHasChanges =\n\t\tvalue && ! isShallowEqualObjects( internalControlValue, value );\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\t// Todo: bug if the missing dep is introduced. Will need a fix.\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\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\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 )[ 0 ] ||\n\t\t\twrapperNode.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\t// Suggestions may contains \"settings\" values (e.g. `opensInNewTab`)\n\t\t// which should not overide any existing settings values set by the\n\t\t// user. This filters out any settings values from the suggestion.\n\t\tconst nonSettingsChanges = Object.keys( updatedValue ).reduce(\n\t\t\t( acc, key ) => {\n\t\t\t\tif ( ! settingsKeys.includes( key ) ) {\n\t\t\t\t\tacc[ key ] = updatedValue[ key ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\n\t\tonChange( {\n\t\t\t...internalControlValue,\n\t\t\t...nonSettingsChanges,\n\t\t\t// As title is not a setting, it must be manually applied\n\t\t\t// in such a way as to preserve the users changes over\n\t\t\t// any \"title\" value provided by the \"suggestion\".\n\t\t\ttitle: internalControlValue?.title || updatedValue?.title,\n\t\t} );\n\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmit = () => {\n\t\tif ( valueHasChanges ) {\n\t\t\t// Submit the original value with new stored values applied\n\t\t\t// on top. URL is a special case as it may also be a prop.\n\t\t\tonChange( {\n\t\t\t\t...value,\n\t\t\t\t...internalControlValue,\n\t\t\t\turl: currentUrlInputValue,\n\t\t\t} );\n\t\t}\n\t\tstopEditing();\n\t};\n\n\tconst handleSubmitWithEnter = ( event ) => {\n\t\tconst { keyCode } = event;\n\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\tsetInternalControlValue( value );\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 =\n\t\tpropInputValue || internalControlValue?.url || '';\n\n\tconst currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;\n\n\tconst shownUnlinkControl =\n\t\tonRemove && value && ! isEditingLink && ! isCreatingPage;\n\n\tconst showActions = isEditingLink && hasLinkValue;\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\tconst isDisabled = ! valueHasChanges || currentInputIsEmpty;\n\tconst showSettings = !! settings?.length && isEditingLink && hasLinkValue;\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{ 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={ internalControlValue?.title }\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\tsize=\"__unstable-large\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\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\thideLabelFromVision={ ! 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={ () => {\n\t\t\t\t\t\tonRemove();\n\t\t\t\t\t\tsetIsEditingLink( true );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ showSettings && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t{ ! currentInputIsEmpty && (\n\t\t\t\t\t\t<LinkControlSettingsDrawer\n\t\t\t\t\t\t\tsettingsOpen={ isSettingsOpen }\n\t\t\t\t\t\t\tsetSettingsOpen={ setSettingsOpenWithPreference }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<LinkSettings\n\t\t\t\t\t\t\t\tvalue={ internalControlValue }\n\t\t\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t\t\t\tonChange={ createSetInternalSettingValueHandler(\n\t\t\t\t\t\t\t\t\tsettingsKeys\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</LinkControlSettingsDrawer>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ showActions && (\n\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ isDisabled ? noop : handleSubmit }\n\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button variant=\"tertiary\" onClick={ handleCancel }>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\n\n\t\t\t{ renderControlBottom && renderControlBottom() }\n\t\t</div>\n\t);\n}\n\nLinkControl.ViewerFill = ViewerFill;\n\nexport default LinkControl;\n"]}
|
|
@@ -51,10 +51,10 @@ function LinkPreview({
|
|
|
51
51
|
} = (0, _useRichUrlData.default)(showRichPreviews); // Rich data may be an empty object so test for that.
|
|
52
52
|
|
|
53
53
|
const hasRichData = richData && Object.keys(richData).length;
|
|
54
|
-
const displayURL = value && (0, _url.filterURLForDisplay)((0, _url.safeDecodeURI)(value.url), 16) || '';
|
|
55
|
-
const displayTitle = richData?.title || value?.title || displayURL; // url can be undefined if the href attribute is unset
|
|
54
|
+
const displayURL = value && (0, _url.filterURLForDisplay)((0, _url.safeDecodeURI)(value.url), 16) || ''; // url can be undefined if the href attribute is unset
|
|
56
55
|
|
|
57
56
|
const isEmptyURL = !value?.url?.length;
|
|
57
|
+
const displayTitle = !isEmptyURL && (0, _dom.__unstableStripHTML)(richData?.title || value?.title || displayURL);
|
|
58
58
|
let icon;
|
|
59
59
|
|
|
60
60
|
if (richData?.icon) {
|
|
@@ -95,7 +95,7 @@ function LinkPreview({
|
|
|
95
95
|
}, !isEmptyURL ? (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.ExternalLink, {
|
|
96
96
|
className: "block-editor-link-control__search-item-title",
|
|
97
97
|
href: value.url
|
|
98
|
-
},
|
|
98
|
+
}, displayTitle), value?.url && displayTitle !== displayURL && (0, _element.createElement)("span", {
|
|
99
99
|
className: "block-editor-link-control__search-item-info"
|
|
100
100
|
}, displayURL)) : (0, _element.createElement)("span", {
|
|
101
101
|
className: "block-editor-link-control__search-item-error-notice"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/link-preview.js"],"names":["LinkPreview","value","onEditClick","hasRichPreviews","hasUnlinkControl","onRemove","showRichPreviews","url","richData","isFetching","hasRichData","Object","keys","length","displayURL","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/link-preview.js"],"names":["LinkPreview","value","onEditClick","hasRichPreviews","hasUnlinkControl","onRemove","showRichPreviews","url","richData","isFetching","hasRichData","Object","keys","length","displayURL","isEmptyURL","displayTitle","title","icon","info","globe","edit","linkOff","image","description"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAKA;;AAEA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAWA;AACA;AACA;AAKe,SAASA,WAAT,CAAsB;AACpCC,EAAAA,KADoC;AAEpCC,EAAAA,WAFoC;AAGpCC,EAAAA,eAAe,GAAG,KAHkB;AAIpCC,EAAAA,gBAAgB,GAAG,KAJiB;AAKpCC,EAAAA;AALoC,CAAtB,EAMX;AACH;AACA,QAAMC,gBAAg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yBACX,8CADW,EAEX;AACC,wBAAkB,CAAEf,QAAQ,EAAEe;AAD/B,KAFW;AAFb,KASGf,QAAQ,EAAEe,KAAV,IACD;AAAK,IAAA,GAAG,EAAGf,QAAQ,EAAEe,KAArB;AAA6B,IAAA,GAAG,EAAC;AAAjC,IAVF,CAFF,EAiBG,CAAEf,QAAQ,EAAEgB,WAAV,IAAyBf,UAA3B,KACD;AACC,mBAAc,CAAED,QAAQ,EAAEgB,WAD3B;AAEC,IAAA,SAAS,EAAG,yBACX,oDADW,EAEX;AACC,wBAAkB,CAAEhB,QAAQ,EAAEgB;AAD/B,KAFW;AAFb,KASGhB,QAAQ,EAAEgB,WAAV,IACD,4BAAC,8BAAD;AAAM,IAAA,QAAQ,MAAd;AAAe,IAAA,aAAa,EAAC;AAA7B,KACGhB,QAAQ,CAACgB,WADZ,CAVF,CAlBF,CAtEF,CADD;AA6GA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tExternalLink,\n\t__experimentalText as Text,\n} from '@wordpress/components';\nimport { filterURLForDisplay, safeDecodeURI } from '@wordpress/url';\nimport { Icon, globe, info, linkOff, edit } from '@wordpress/icons';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { ViewerSlot } from './viewer-slot';\n\nimport useRichUrlData from './use-rich-url-data';\n\nexport default function LinkPreview( {\n\tvalue,\n\tonEditClick,\n\thasRichPreviews = false,\n\thasUnlinkControl = false,\n\tonRemove,\n} ) {\n\t// Avoid fetching if rich previews are not desired.\n\tconst showRichPreviews = hasRichPreviews ? value?.url : null;\n\n\tconst { richData, isFetching } = useRichUrlData( showRichPreviews );\n\n\t// Rich data may be an empty object so test for that.\n\tconst hasRichData = richData && Object.keys( richData ).length;\n\n\tconst displayURL =\n\t\t( value && filterURLForDisplay( safeDecodeURI( value.url ), 16 ) ) ||\n\t\t'';\n\n\t// url can be undefined if the href attribute is unset\n\tconst isEmptyURL = ! value?.url?.length;\n\n\tconst displayTitle =\n\t\t! isEmptyURL &&\n\t\tstripHTML( richData?.title || value?.title || displayURL );\n\n\tlet icon;\n\n\tif ( richData?.icon ) {\n\t\ticon = <img src={ richData?.icon } alt=\"\" />;\n\t} else if ( isEmptyURL ) {\n\t\ticon = <Icon icon={ info } size={ 32 } />;\n\t} else {\n\t\ticon = <Icon icon={ globe } />;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\taria-label={ __( 'Currently selected' ) }\n\t\t\tclassName={ classnames( 'block-editor-link-control__search-item', {\n\t\t\t\t'is-current': true,\n\t\t\t\t'is-rich': hasRichData,\n\t\t\t\t'is-fetching': !! isFetching,\n\t\t\t\t'is-preview': true,\n\t\t\t\t'is-error': isEmptyURL,\n\t\t\t} ) }\n\t\t>\n\t\t\t<div className=\"block-editor-link-control__search-item-top\">\n\t\t\t\t<span className=\"block-editor-link-control__search-item-header\">\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'block-editor-link-control__search-item-icon',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t'is-image': richData?.icon,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ icon }\n\t\t\t\t\t</span>\n\t\t\t\t\t<span className=\"block-editor-link-control__search-item-details\">\n\t\t\t\t\t\t{ ! isEmptyURL ? (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-item-title\"\n\t\t\t\t\t\t\t\t\thref={ value.url }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ displayTitle }\n\t\t\t\t\t\t\t\t</ExternalLink>\n\n\t\t\t\t\t\t\t\t{ value?.url && displayTitle !== displayURL && (\n\t\t\t\t\t\t\t\t\t<span className=\"block-editor-link-control__search-item-info\">\n\t\t\t\t\t\t\t\t\t\t{ displayURL }\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<span className=\"block-editor-link-control__search-item-error-notice\">\n\t\t\t\t\t\t\t\t{ __( 'Link is empty' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\n\t\t\t\t<Button\n\t\t\t\t\ticon={ edit }\n\t\t\t\t\tlabel={ __( 'Edit' ) }\n\t\t\t\t\tclassName=\"block-editor-link-control__search-item-action\"\n\t\t\t\t\tonClick={ onEditClick }\n\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t/>\n\t\t\t\t{ hasUnlinkControl && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\ticon={ linkOff }\n\t\t\t\t\t\tlabel={ __( 'Unlink' ) }\n\t\t\t\t\t\tclassName=\"block-editor-link-control__search-item-action block-editor-link-control__unlink\"\n\t\t\t\t\t\tonClick={ onRemove }\n\t\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<ViewerSlot fillProps={ value } />\n\t\t\t</div>\n\n\t\t\t{ !! (\n\t\t\t\t( hasRichData &&\n\t\t\t\t\t( richData?.image || richData?.description ) ) ||\n\t\t\t\tisFetching\n\t\t\t) && (\n\t\t\t\t<div className=\"block-editor-link-control__search-item-bottom\">\n\t\t\t\t\t{ ( richData?.image || isFetching ) && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\taria-hidden={ ! richData?.image }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-link-control__search-item-image',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'is-placeholder': ! richData?.image,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ richData?.image && (\n\t\t\t\t\t\t\t\t<img src={ richData?.image } alt=\"\" />\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ ( richData?.description || isFetching ) && (\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\taria-hidden={ ! richData?.description }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-link-control__search-item-description',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'is-placeholder': ! richData?.description,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ richData?.description && (\n\t\t\t\t\t\t\t\t<Text truncate numberOfLines=\"2\">\n\t\t\t\t\t\t\t\t\t{ richData.description }\n\t\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -389,7 +389,12 @@ function useListViewDropZone({
|
|
|
389
389
|
}, [canInsertBlocks, draggedBlockClientIds, getBlockCount, getBlockIndex, getBlockRootClientId, rtl]), 200);
|
|
390
390
|
const ref = (0, _compose.__experimentalUseDropZone)({
|
|
391
391
|
dropZoneElement,
|
|
392
|
-
|
|
392
|
+
|
|
393
|
+
onDrop(event) {
|
|
394
|
+
if (target) {
|
|
395
|
+
onBlockDrop(event);
|
|
396
|
+
}
|
|
397
|
+
},
|
|
393
398
|
|
|
394
399
|
onDragLeave() {
|
|
395
400
|
throttled.cancel();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["NESTING_LEVEL_INDENTATION","isUpGesture","point","rect","nestingLevel","rtl","blockIndentPosition","right","left","x","getDesiredRelativeParentLevel","distanceBetweenPointAndBlockIndentPosition","desiredParentLevel","Math","round","abs","getCandidateBlockParents","candidateBlockData","blocksData","candidateBlockParents","currentBlockData","push","find","blockData","clientId","rootClientId","getNextNonDraggedBlock","index","nextBlockData","isDraggedBlock","isNestingGesture","isNestingHorizontalGesture","y","bottom","ALLOWED_DROP_EDGES","getListViewDropTarget","position","candidateEdge","candidateDistance","candidateRect","candidateBlockIndex","i","length","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","indexOf","previousBlockData","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","isExpanded","newBlockIndex","blockIndex","dropPosition","nextBlock","currentLevel","nextLevel","desiredRelativeLevel","targetParentIndex","max","min","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","dropZoneElement","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","blockEditorStore","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","clientY","isBlockDrag","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","expanded","classList","contains","parseInt","getAttribute","newTarget","ref","onDrop","onDragLeave","cancel","onDragOver","onDragEnd"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAIA;;AAKA;;AAIA;;AACA;;AAnBA;AACA;AACA;;AASA;AACA;AACA;;AAQA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACO,MAAMA,yBAAyB,GAAG,EAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,SAASC,WAAT,CAAsBC,KAAtB,EAA6BC,IAA7B,EAAmCC,YAAY,GAAG,CAAlD,EAAqDC,GAAG,GAAG,KAA3D,EAAmE;AAClE;AACA;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G,GAAG,GAAG,wCAAa;AACxBjC,IAAAA,eADwB;AAExBkC,IAAAA,MAAM,EAAEvB,WAFgB;;AAGxBwB,IAAAA,WAAW,GAAG;AACbtB,MAAAA,SAAS,CAACuB,MAAV;AACA5B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA,KANuB;;AAOxB6B,IAAAA,UAAU,CAAEvB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAZuB;;AAaxBuB,IAAAA,SAAS,GAAG;AACXzB,MAAAA,SAAS,CAACuB,MAAV;AACA5B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAhBuB,GAAb,CAAZ;AAmBA,SAAO;AAAEyB,IAAAA,GAAF;AAAO1B,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An object representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlock\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} isExpanded Whether the block is expanded in the UI.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {WPListViewDropZoneBlock[]} WPListViewDropZoneBlocks\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n// When the indentation level, the corresponding left margin in `style.scss`\n// must be updated as well to ensure the drop zone is aligned with the indentation.\nexport const NESTING_LEVEL_INDENTATION = 28;\n\n/**\n * Determines whether the user is positioning the dragged block to be\n * moved up to a parent level.\n *\n * Determined based on nesting level indentation of the current block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n * @return {boolean} Whether the gesture is an upward gesture.\n */\nfunction isUpGesture( point, rect, nestingLevel = 1, rtl = false ) {\n\t// If the block is nested, and the user is dragging to the bottom\n\t// left of the block (or bottom right in RTL languages), then it is an upward gesture.\n\tconst blockIndentPosition = rtl\n\t\t? rect.right - nestingLevel * NESTING_LEVEL_INDENTATION\n\t\t: rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\treturn rtl ? point.x > blockIndentPosition : point.x < blockIndentPosition;\n}\n\n/**\n * Returns how many nesting levels up the user is attempting to drag to.\n *\n * The relative parent level is calculated based on how far\n * the cursor is from the provided nesting level (e.g. of a candidate block\n * that the user is hovering over). The nesting level is considered \"desired\"\n * because it is not guaranteed that the user will be able to drag to the desired level.\n *\n * The returned integer can be used to access an ascending array\n * of parent blocks, where the first item is the block the user\n * is hovering over, and the last item is the root block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n * @return {number} The desired relative parent level.\n */\nfunction getDesiredRelativeParentLevel(\n\tpoint,\n\trect,\n\tnestingLevel = 1,\n\trtl = false\n) {\n\t// In RTL languages, the block indent position is from the right edge of the block.\n\t// In LTR languages, the block indent position is from the left edge of the block.\n\tconst blockIndentPosition = rtl\n\t\t? rect.right - nestingLevel * NESTING_LEVEL_INDENTATION\n\t\t: rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\n\tconst distanceBetweenPointAndBlockIndentPosition = rtl\n\t\t? blockIndentPosition - point.x\n\t\t: point.x - blockIndentPosition;\n\n\tconst desiredParentLevel = Math.round(\n\t\tdistanceBetweenPointAndBlockIndentPosition / NESTING_LEVEL_INDENTATION\n\t);\n\n\treturn Math.abs( desiredParentLevel );\n}\n\n/**\n * Returns an array of the parent blocks of the block the user is dropping to.\n *\n * @param {WPListViewDropZoneBlock} candidateBlockData The block the user is dropping to.\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @return {WPListViewDropZoneBlocks} An array of block parents, including the block the user is dropping to.\n */\nfunction getCandidateBlockParents( candidateBlockData, blocksData ) {\n\tconst candidateBlockParents = [];\n\tlet currentBlockData = candidateBlockData;\n\n\twhile ( currentBlockData ) {\n\t\tcandidateBlockParents.push( { ...currentBlockData } );\n\t\tcurrentBlockData = blocksData.find(\n\t\t\t( blockData ) =>\n\t\t\t\tblockData.clientId === currentBlockData.rootClientId\n\t\t);\n\t}\n\n\treturn candidateBlockParents;\n}\n\n/**\n * Given a list of blocks data and a block index, return the next non-dragged\n * block. This is used to determine the block that the user is dropping to,\n * while ignoring the dragged block.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {number} index The index to begin searching from.\n * @return {WPListViewDropZoneBlock | undefined} The next non-dragged block.\n */\nfunction getNextNonDraggedBlock( blocksData, index ) {\n\tconst nextBlockData = blocksData[ index + 1 ];\n\tif ( nextBlockData && nextBlockData.isDraggedBlock ) {\n\t\treturn getNextNonDraggedBlock( blocksData, index + 1 );\n\t}\n\n\treturn nextBlockData;\n}\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Determined based on nesting level indentation of the current block, plus\n * the indentation of the next level of nesting. The vertical position of the\n * cursor must also be within the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n */\nfunction isNestingGesture( point, rect, nestingLevel = 1, rtl = false ) {\n\tconst blockIndentPosition = rtl\n\t\t? rect.right - nestingLevel * NESTING_LEVEL_INDENTATION\n\t\t: rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\n\tconst isNestingHorizontalGesture = rtl\n\t\t? point.x < blockIndentPosition - NESTING_LEVEL_INDENTATION\n\t\t: point.x > blockIndentPosition + NESTING_LEVEL_INDENTATION;\n\n\treturn isNestingHorizontalGesture && point.y < rect.bottom;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n *\n * @return {WPListViewDropZoneTarget | undefined} An object containing data about the drop target.\n */\nexport function getListViewDropTarget( blocksData, position, rtl = false ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\tlet candidateBlockIndex;\n\n\tfor ( let i = 0; i < blocksData.length; i++ ) {\n\t\tconst blockData = blocksData[ i ];\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\n\t\t\t\t\tpreviousBlockData.element.getBoundingClientRect();\n\t\t\t\tcandidateBlockIndex = index - 1;\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t\tcandidateBlockIndex = index;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst candidateBlockParents = getCandidateBlockParents(\n\t\tcandidateBlockData,\n\t\tblocksData\n\t);\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, and is expanded, this should be treated\n\t// as nesting since the next block in the tree will be the first child.\n\t// However, if the block is collapsed, dragging beneath the block should\n\t// still be allowed, as the next visible block in the tree will be a sibling.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( ( candidateBlockData.innerBlockCount > 0 &&\n\t\t\tcandidateBlockData.isExpanded ) ||\n\t\t\tisNestingGesture(\n\t\t\t\tposition,\n\t\t\t\tcandidateRect,\n\t\t\t\tcandidateBlockParents.length,\n\t\t\t\trtl\n\t\t\t) )\n\t) {\n\t\t// If the block is expanded, insert the block as the first child.\n\t\t// Otherwise, for collapsed blocks, insert the block as the last child.\n\t\tconst newBlockIndex = candidateBlockData.isExpanded\n\t\t\t? 0\n\t\t\t: candidateBlockData.innerBlockCount || 0;\n\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: newBlockIndex,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to move the block to be at a parent level.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.rootClientId &&\n\t\tisUpGesture(\n\t\t\tposition,\n\t\t\tcandidateRect,\n\t\t\tcandidateBlockParents.length,\n\t\t\trtl\n\t\t)\n\t) {\n\t\tconst nextBlock = getNextNonDraggedBlock(\n\t\t\tblocksData,\n\t\t\tcandidateBlockIndex\n\t\t);\n\t\tconst currentLevel = candidateBlockData.nestingLevel;\n\t\tconst nextLevel = nextBlock ? nextBlock.nestingLevel : 1;\n\n\t\tif ( currentLevel && nextLevel ) {\n\t\t\t// Determine the desired relative level of the block to be dropped.\n\t\t\tconst desiredRelativeLevel = getDesiredRelativeParentLevel(\n\t\t\t\tposition,\n\t\t\t\tcandidateRect,\n\t\t\t\tcandidateBlockParents.length,\n\t\t\t\trtl\n\t\t\t);\n\n\t\t\tconst targetParentIndex = Math.max(\n\t\t\t\tMath.min( desiredRelativeLevel, currentLevel - nextLevel ),\n\t\t\t\t0\n\t\t\t);\n\n\t\t\tif ( candidateBlockParents[ targetParentIndex ] ) {\n\t\t\t\t// Default to the block index of the candidate block.\n\t\t\t\tlet newBlockIndex = candidateBlockData.blockIndex;\n\n\t\t\t\t// If the next block is at the same level, use that as the default\n\t\t\t\t// block index. This ensures that the block is dropped in the correct\n\t\t\t\t// position when dragging to the bottom of a block.\n\t\t\t\tif (\n\t\t\t\t\tcandidateBlockParents[ targetParentIndex ].nestingLevel ===\n\t\t\t\t\tnextBlock?.nestingLevel\n\t\t\t\t) {\n\t\t\t\t\tnewBlockIndex = nextBlock?.blockIndex;\n\t\t\t\t} else {\n\t\t\t\t\t// Otherwise, search from the current block index back\n\t\t\t\t\t// to find the last block index within the same target parent.\n\t\t\t\t\tfor ( let i = candidateBlockIndex; i >= 0; i-- ) {\n\t\t\t\t\t\tconst blockData = blocksData[ i ];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tblockData.rootClientId ===\n\t\t\t\t\t\t\tcandidateBlockParents[ targetParentIndex ]\n\t\t\t\t\t\t\t\t.rootClientId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewBlockIndex = blockData.blockIndex + 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\trootClientId:\n\t\t\t\t\t\tcandidateBlockParents[ targetParentIndex ].rootClientId,\n\t\t\t\t\tclientId: candidateBlockData.clientId,\n\t\t\t\t\tblockIndex: newBlockIndex,\n\t\t\t\t\tdropPosition: candidateEdge,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @param {Object} props Named parameters.\n * @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone( { dropZoneElement } ) {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst rtl = isRTL();\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst isExpanded = blockElement.dataset.expanded === 'true';\n\t\t\t\t\tconst isDraggedBlock =\n\t\t\t\t\t\tblockElement.classList.contains( 'is-dragging' );\n\n\t\t\t\t\t// Get nesting level from `aria-level` attribute because Firefox does not support `element.ariaLevel`.\n\t\t\t\t\tconst nestingLevel = parseInt(\n\t\t\t\t\t\tblockElement.getAttribute( 'aria-level' ),\n\t\t\t\t\t\t10\n\t\t\t\t\t);\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tisExpanded,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tnestingLevel: nestingLevel || undefined,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag ? isDraggedBlock : false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget(\n\t\t\t\t\tblocksData,\n\t\t\t\t\tposition,\n\t\t\t\t\trtl\n\t\t\t\t);\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[\n\t\t\t\tcanInsertBlocks,\n\t\t\t\tdraggedBlockClientIds,\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\trtl,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tdropZoneElement,\n\t\tonDrop: onBlockDrop,\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/list-view/use-list-view-drop-zone.js"],"names":["NESTING_LEVEL_INDENTATION","isUpGesture","point","rect","nestingLevel","rtl","blockIndentPosition","right","left","x","getDesiredRelativeParentLevel","distanceBetweenPointAndBlockIndentPosition","desiredParentLevel","Math","round","abs","getCandidateBlockParents","candidateBlockData","blocksData","candidateBlockParents","currentBlockData","push","find","blockData","clientId","rootClientId","getNextNonDraggedBlock","index","nextBlockData","isDraggedBlock","isNestingGesture","isNestingHorizontalGesture","y","bottom","ALLOWED_DROP_EDGES","getListViewDropTarget","position","candidateEdge","candidateDistance","candidateRect","candidateBlockIndex","i","length","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","indexOf","previousBlockData","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","isExpanded","newBlockIndex","blockIndex","dropPosition","nextBlock","currentLevel","nextLevel","desiredRelativeLevel","targetParentIndex","max","min","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","dropZoneElement","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","blockEditorStore","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","clientY","isBlockDrag","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","expanded","classList","contains","parseInt","getAttribute","newTarget","ref","onDrop","onDragLeave","cancel","onDragOver","onDragEnd"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAIA;;AAKA;;AAIA;;AACA;;AAnBA;AACA;AACA;;AASA;AACA;AACA;;AAQA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AAmBA,KAhCkB,CAAnB;AAkCA,UAAM4E,SAAS,GAAGjE,qBAAqB,CACtCjB,UADsC,EAEtCkB,QAFsC,EAGtC/B,GAHsC,CAAvC;;AAMA,QAAK+F,SAAL,EAAiB;AAChBxB,MAAAA,SAAS,CAAEwB,SAAF,CAAT;AACA;AACD,GApDF,EAqDC,CACC3B,eADD,EAECO,qBAFD,EAGCT,aAHD,EAICD,aAJD,EAKCD,oBALD,EAMChE,GAND,CArDD,CADiB,EA+DjB,GA/DiB,CAAlB;AAkEA,QAAMgG,GAAG,GAAG,wCAAa;AACxBjC,IAAAA,eADwB;;AAExBkC,IAAAA,MAAM,CAAEpB,KAAF,EAAU;AACf,UAAKP,MAAL,EAAc;AACbI,QAAAA,WAAW,CAAEG,KAAF,CAAX;AACA;AACD,KANuB;;AAOxBqB,IAAAA,WAAW,GAAG;AACbtB,MAAAA,SAAS,CAACuB,MAAV;AACA5B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA,KAVuB;;AAWxB6B,IAAAA,UAAU,CAAEvB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAhBuB;;AAiBxBuB,IAAAA,SAAS,GAAG;AACXzB,MAAAA,SAAS,CAACuB,MAAV;AACA5B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AApBuB,GAAb,CAAZ;AAuBA,SAAO;AAAEyB,IAAAA,GAAF;AAAO1B,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\nimport { isRTL } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An object representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlock\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} isExpanded Whether the block is expanded in the UI.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {WPListViewDropZoneBlock[]} WPListViewDropZoneBlocks\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n// When the indentation level, the corresponding left margin in `style.scss`\n// must be updated as well to ensure the drop zone is aligned with the indentation.\nexport const NESTING_LEVEL_INDENTATION = 28;\n\n/**\n * Determines whether the user is positioning the dragged block to be\n * moved up to a parent level.\n *\n * Determined based on nesting level indentation of the current block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n * @return {boolean} Whether the gesture is an upward gesture.\n */\nfunction isUpGesture( point, rect, nestingLevel = 1, rtl = false ) {\n\t// If the block is nested, and the user is dragging to the bottom\n\t// left of the block (or bottom right in RTL languages), then it is an upward gesture.\n\tconst blockIndentPosition = rtl\n\t\t? rect.right - nestingLevel * NESTING_LEVEL_INDENTATION\n\t\t: rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\treturn rtl ? point.x > blockIndentPosition : point.x < blockIndentPosition;\n}\n\n/**\n * Returns how many nesting levels up the user is attempting to drag to.\n *\n * The relative parent level is calculated based on how far\n * the cursor is from the provided nesting level (e.g. of a candidate block\n * that the user is hovering over). The nesting level is considered \"desired\"\n * because it is not guaranteed that the user will be able to drag to the desired level.\n *\n * The returned integer can be used to access an ascending array\n * of parent blocks, where the first item is the block the user\n * is hovering over, and the last item is the root block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n * @return {number} The desired relative parent level.\n */\nfunction getDesiredRelativeParentLevel(\n\tpoint,\n\trect,\n\tnestingLevel = 1,\n\trtl = false\n) {\n\t// In RTL languages, the block indent position is from the right edge of the block.\n\t// In LTR languages, the block indent position is from the left edge of the block.\n\tconst blockIndentPosition = rtl\n\t\t? rect.right - nestingLevel * NESTING_LEVEL_INDENTATION\n\t\t: rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\n\tconst distanceBetweenPointAndBlockIndentPosition = rtl\n\t\t? blockIndentPosition - point.x\n\t\t: point.x - blockIndentPosition;\n\n\tconst desiredParentLevel = Math.round(\n\t\tdistanceBetweenPointAndBlockIndentPosition / NESTING_LEVEL_INDENTATION\n\t);\n\n\treturn Math.abs( desiredParentLevel );\n}\n\n/**\n * Returns an array of the parent blocks of the block the user is dropping to.\n *\n * @param {WPListViewDropZoneBlock} candidateBlockData The block the user is dropping to.\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @return {WPListViewDropZoneBlocks} An array of block parents, including the block the user is dropping to.\n */\nfunction getCandidateBlockParents( candidateBlockData, blocksData ) {\n\tconst candidateBlockParents = [];\n\tlet currentBlockData = candidateBlockData;\n\n\twhile ( currentBlockData ) {\n\t\tcandidateBlockParents.push( { ...currentBlockData } );\n\t\tcurrentBlockData = blocksData.find(\n\t\t\t( blockData ) =>\n\t\t\t\tblockData.clientId === currentBlockData.rootClientId\n\t\t);\n\t}\n\n\treturn candidateBlockParents;\n}\n\n/**\n * Given a list of blocks data and a block index, return the next non-dragged\n * block. This is used to determine the block that the user is dropping to,\n * while ignoring the dragged block.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {number} index The index to begin searching from.\n * @return {WPListViewDropZoneBlock | undefined} The next non-dragged block.\n */\nfunction getNextNonDraggedBlock( blocksData, index ) {\n\tconst nextBlockData = blocksData[ index + 1 ];\n\tif ( nextBlockData && nextBlockData.isDraggedBlock ) {\n\t\treturn getNextNonDraggedBlock( blocksData, index + 1 );\n\t}\n\n\treturn nextBlockData;\n}\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Determined based on nesting level indentation of the current block, plus\n * the indentation of the next level of nesting. The vertical position of the\n * cursor must also be within the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n * @param {number} nestingLevel The nesting level of the block.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n */\nfunction isNestingGesture( point, rect, nestingLevel = 1, rtl = false ) {\n\tconst blockIndentPosition = rtl\n\t\t? rect.right - nestingLevel * NESTING_LEVEL_INDENTATION\n\t\t: rect.left + nestingLevel * NESTING_LEVEL_INDENTATION;\n\n\tconst isNestingHorizontalGesture = rtl\n\t\t? point.x < blockIndentPosition - NESTING_LEVEL_INDENTATION\n\t\t: point.x > blockIndentPosition + NESTING_LEVEL_INDENTATION;\n\n\treturn isNestingHorizontalGesture && point.y < rect.bottom;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n * @param {boolean} rtl Whether the editor is in RTL mode.\n *\n * @return {WPListViewDropZoneTarget | undefined} An object containing data about the drop target.\n */\nexport function getListViewDropTarget( blocksData, position, rtl = false ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\tlet candidateBlockIndex;\n\n\tfor ( let i = 0; i < blocksData.length; i++ ) {\n\t\tconst blockData = blocksData[ i ];\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\n\t\t\t\t\tpreviousBlockData.element.getBoundingClientRect();\n\t\t\t\tcandidateBlockIndex = index - 1;\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t\tcandidateBlockIndex = index;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst candidateBlockParents = getCandidateBlockParents(\n\t\tcandidateBlockData,\n\t\tblocksData\n\t);\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, and is expanded, this should be treated\n\t// as nesting since the next block in the tree will be the first child.\n\t// However, if the block is collapsed, dragging beneath the block should\n\t// still be allowed, as the next visible block in the tree will be a sibling.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( ( candidateBlockData.innerBlockCount > 0 &&\n\t\t\tcandidateBlockData.isExpanded ) ||\n\t\t\tisNestingGesture(\n\t\t\t\tposition,\n\t\t\t\tcandidateRect,\n\t\t\t\tcandidateBlockParents.length,\n\t\t\t\trtl\n\t\t\t) )\n\t) {\n\t\t// If the block is expanded, insert the block as the first child.\n\t\t// Otherwise, for collapsed blocks, insert the block as the last child.\n\t\tconst newBlockIndex = candidateBlockData.isExpanded\n\t\t\t? 0\n\t\t\t: candidateBlockData.innerBlockCount || 0;\n\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: newBlockIndex,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to move the block to be at a parent level.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.rootClientId &&\n\t\tisUpGesture(\n\t\t\tposition,\n\t\t\tcandidateRect,\n\t\t\tcandidateBlockParents.length,\n\t\t\trtl\n\t\t)\n\t) {\n\t\tconst nextBlock = getNextNonDraggedBlock(\n\t\t\tblocksData,\n\t\t\tcandidateBlockIndex\n\t\t);\n\t\tconst currentLevel = candidateBlockData.nestingLevel;\n\t\tconst nextLevel = nextBlock ? nextBlock.nestingLevel : 1;\n\n\t\tif ( currentLevel && nextLevel ) {\n\t\t\t// Determine the desired relative level of the block to be dropped.\n\t\t\tconst desiredRelativeLevel = getDesiredRelativeParentLevel(\n\t\t\t\tposition,\n\t\t\t\tcandidateRect,\n\t\t\t\tcandidateBlockParents.length,\n\t\t\t\trtl\n\t\t\t);\n\n\t\t\tconst targetParentIndex = Math.max(\n\t\t\t\tMath.min( desiredRelativeLevel, currentLevel - nextLevel ),\n\t\t\t\t0\n\t\t\t);\n\n\t\t\tif ( candidateBlockParents[ targetParentIndex ] ) {\n\t\t\t\t// Default to the block index of the candidate block.\n\t\t\t\tlet newBlockIndex = candidateBlockData.blockIndex;\n\n\t\t\t\t// If the next block is at the same level, use that as the default\n\t\t\t\t// block index. This ensures that the block is dropped in the correct\n\t\t\t\t// position when dragging to the bottom of a block.\n\t\t\t\tif (\n\t\t\t\t\tcandidateBlockParents[ targetParentIndex ].nestingLevel ===\n\t\t\t\t\tnextBlock?.nestingLevel\n\t\t\t\t) {\n\t\t\t\t\tnewBlockIndex = nextBlock?.blockIndex;\n\t\t\t\t} else {\n\t\t\t\t\t// Otherwise, search from the current block index back\n\t\t\t\t\t// to find the last block index within the same target parent.\n\t\t\t\t\tfor ( let i = candidateBlockIndex; i >= 0; i-- ) {\n\t\t\t\t\t\tconst blockData = blocksData[ i ];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tblockData.rootClientId ===\n\t\t\t\t\t\t\tcandidateBlockParents[ targetParentIndex ]\n\t\t\t\t\t\t\t\t.rootClientId\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnewBlockIndex = blockData.blockIndex + 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\trootClientId:\n\t\t\t\t\t\tcandidateBlockParents[ targetParentIndex ].rootClientId,\n\t\t\t\t\tclientId: candidateBlockData.clientId,\n\t\t\t\t\tblockIndex: newBlockIndex,\n\t\t\t\t\tdropPosition: candidateEdge,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @param {Object} props Named parameters.\n * @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone( { dropZoneElement } ) {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst rtl = isRTL();\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst isExpanded = blockElement.dataset.expanded === 'true';\n\t\t\t\t\tconst isDraggedBlock =\n\t\t\t\t\t\tblockElement.classList.contains( 'is-dragging' );\n\n\t\t\t\t\t// Get nesting level from `aria-level` attribute because Firefox does not support `element.ariaLevel`.\n\t\t\t\t\tconst nestingLevel = parseInt(\n\t\t\t\t\t\tblockElement.getAttribute( 'aria-level' ),\n\t\t\t\t\t\t10\n\t\t\t\t\t);\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tisExpanded,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tnestingLevel: nestingLevel || undefined,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag ? isDraggedBlock : false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget(\n\t\t\t\t\tblocksData,\n\t\t\t\t\tposition,\n\t\t\t\t\trtl\n\t\t\t\t);\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[\n\t\t\t\tcanInsertBlocks,\n\t\t\t\tdraggedBlockClientIds,\n\t\t\t\tgetBlockCount,\n\t\t\t\tgetBlockIndex,\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\trtl,\n\t\t\t]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tdropZoneElement,\n\t\tonDrop( event ) {\n\t\t\tif ( target ) {\n\t\t\t\tonBlockDrop( event );\n\t\t\t}\n\t\t},\n\t\tonDragLeave() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
|
|
@@ -5,9 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
// so we return an empty component instead.
|
|
10
|
-
var _default = () => null;
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
11
9
|
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* External dependencies
|
|
14
|
+
*/
|
|
15
|
+
// MediaReplaceFlow component is not yet implemented in the native version.
|
|
16
|
+
// For testing purposes, we are using an empty View component with a testID prop.
|
|
17
|
+
const MediaReplaceFlow = () => {
|
|
18
|
+
return (0, _element.createElement)(_reactNative.View, {
|
|
19
|
+
testID: "media-replace-flow"
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var _default = MediaReplaceFlow;
|
|
12
24
|
exports.default = _default;
|
|
13
25
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/media-replace-flow/index.native.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/media-replace-flow/index.native.js"],"names":["MediaReplaceFlow"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGA;AACA;AACA,MAAMA,gBAAgB,GAAG,MAAM;AAC9B,SAAO,4BAAC,iBAAD;AAAM,IAAA,MAAM,EAAC;AAAb,IAAP;AACA,CAFD;;eAIeA,gB","sourcesContent":["/**\n * External dependencies\n */\nimport { View } from 'react-native';\n\n// MediaReplaceFlow component is not yet implemented in the native version.\n// For testing purposes, we are using an empty View component with a testID prop.\nconst MediaReplaceFlow = () => {\n\treturn <View testID=\"media-replace-flow\" />;\n};\n\nexport default MediaReplaceFlow;\n"]}
|
|
@@ -1,49 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.default = FormatEdit;
|
|
9
|
+
exports.usesContextKey = void 0;
|
|
7
10
|
|
|
8
11
|
var _element = require("@wordpress/element");
|
|
9
12
|
|
|
10
13
|
var _richText = require("@wordpress/rich-text");
|
|
11
14
|
|
|
15
|
+
var _blockContext = _interopRequireDefault(require("../block-context"));
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* WordPress dependencies
|
|
14
19
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
const DEFAULT_BLOCK_CONTEXT = {};
|
|
25
|
+
const usesContextKey = Symbol('usesContext');
|
|
26
|
+
exports.usesContextKey = usesContextKey;
|
|
27
|
+
|
|
28
|
+
function Edit({
|
|
17
29
|
onChange,
|
|
18
30
|
onFocus,
|
|
19
31
|
value,
|
|
20
|
-
forwardedRef
|
|
32
|
+
forwardedRef,
|
|
33
|
+
settings
|
|
21
34
|
}) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
35
|
+
const {
|
|
36
|
+
name,
|
|
37
|
+
edit: EditFunction,
|
|
38
|
+
[usesContextKey]: usesContext
|
|
39
|
+
} = settings;
|
|
40
|
+
const blockContext = (0, _element.useContext)(_blockContext.default); // Assign context values using the block type's declared context needs.
|
|
41
|
+
|
|
42
|
+
const context = (0, _element.useMemo)(() => {
|
|
43
|
+
return usesContext ? Object.fromEntries(Object.entries(blockContext).filter(([key]) => usesContext.includes(key))) : DEFAULT_BLOCK_CONTEXT;
|
|
44
|
+
}, [usesContext, blockContext]);
|
|
45
|
+
|
|
46
|
+
if (!EditFunction) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const activeFormat = (0, _richText.getActiveFormat)(value, name);
|
|
51
|
+
const isActive = activeFormat !== undefined;
|
|
52
|
+
const activeObject = (0, _richText.getActiveObject)(value);
|
|
53
|
+
const isObjectActive = activeObject !== undefined && activeObject.type === name;
|
|
54
|
+
return (0, _element.createElement)(EditFunction, {
|
|
55
|
+
key: name,
|
|
56
|
+
isActive: isActive,
|
|
57
|
+
activeAttributes: isActive ? activeFormat.attributes || {} : {},
|
|
58
|
+
isObjectActive: isObjectActive,
|
|
59
|
+
activeObjectAttributes: isObjectActive ? activeObject.attributes || {} : {},
|
|
60
|
+
value: value,
|
|
61
|
+
onChange: onChange,
|
|
62
|
+
onFocus: onFocus,
|
|
63
|
+
contentRef: forwardedRef,
|
|
64
|
+
context: context
|
|
47
65
|
});
|
|
48
66
|
}
|
|
67
|
+
|
|
68
|
+
function FormatEdit({
|
|
69
|
+
formatTypes,
|
|
70
|
+
...props
|
|
71
|
+
}) {
|
|
72
|
+
return formatTypes.map(settings => (0, _element.createElement)(Edit, {
|
|
73
|
+
settings: settings,
|
|
74
|
+
...props,
|
|
75
|
+
key: settings.name
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
49
78
|
//# sourceMappingURL=format-edit.js.map
|