@wordpress/block-editor 12.3.1 → 12.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/components/block-lock/toolbar.js +25 -6
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-toolbar/index.js +8 -5
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/dimensions-tool/aspect-ratio-tool.js +99 -0
- package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build/components/dimensions-tool/index.js +207 -0
- package/build/components/dimensions-tool/index.js.map +1 -0
- package/build/components/dimensions-tool/scale-tool.js +111 -0
- package/build/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build/components/dimensions-tool/width-height-tool.js +125 -0
- package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build/components/image-editor/use-save-image.js +1 -2
- package/build/components/image-editor/use-save-image.js.map +1 -1
- package/build/components/image-size-control/index.js +6 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/link-control/index.js +17 -15
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/link-control/search-input.js +4 -4
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/link-control/settings-drawer.js +2 -3
- package/build/components/link-control/settings-drawer.js.map +1 -1
- package/build/components/provider/use-block-sync.js +21 -0
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/resolution-tool/index.js +55 -0
- package/build/components/resolution-tool/index.js.map +1 -0
- package/build/components/url-input/index.js +4 -2
- package/build/components/url-input/index.js.map +1 -1
- package/build/private-apis.js +7 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/defaults.js +1 -0
- package/build/store/defaults.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +25 -7
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +8 -5
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js +87 -0
- package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/index.js +195 -0
- package/build-module/components/dimensions-tool/index.js.map +1 -0
- package/build-module/components/dimensions-tool/scale-tool.js +103 -0
- package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
- package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
- package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
- package/build-module/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
- package/build-module/components/image-editor/use-save-image.js +1 -2
- package/build-module/components/image-editor/use-save-image.js.map +1 -1
- package/build-module/components/image-size-control/index.js +5 -0
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/link-control/index.js +17 -15
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/link-control/search-input.js +4 -4
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/link-control/settings-drawer.js +4 -5
- package/build-module/components/link-control/settings-drawer.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +21 -0
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/resolution-tool/index.js +45 -0
- package/build-module/components/resolution-tool/index.js.map +1 -0
- package/build-module/components/url-input/index.js +4 -2
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/private-apis.js +5 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/defaults.js +1 -0
- package/build-module/store/defaults.js.map +1 -1
- package/build-style/style-rtl.css +42 -46
- package/build-style/style.css +42 -46
- package/package.json +6 -5
- package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
- package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
- package/src/components/block-lock/toolbar.js +34 -6
- package/src/components/block-toolbar/index.js +9 -6
- package/src/components/block-tools/style.scss +4 -0
- package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
- package/src/components/dimensions-tool/index.js +212 -0
- package/src/components/dimensions-tool/scale-tool.js +124 -0
- package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
- package/src/components/dimensions-tool/stories/index.js +54 -0
- package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
- package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
- package/src/components/dimensions-tool/test/index.js +641 -0
- package/src/components/dimensions-tool/width-height-tool.js +113 -0
- package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
- package/src/components/image-editor/use-save-image.js +0 -1
- package/src/components/image-size-control/index.js +6 -0
- package/src/components/link-control/index.js +32 -28
- package/src/components/link-control/search-input.js +4 -3
- package/src/components/link-control/settings-drawer.js +6 -5
- package/src/components/link-control/style.scss +33 -55
- package/src/components/link-control/test/index.js +129 -116
- package/src/components/media-replace-flow/test/index.js +1 -1
- package/src/components/provider/test/use-block-sync.js +21 -6
- package/src/components/provider/use-block-sync.js +19 -0
- package/src/components/resolution-tool/index.js +56 -0
- package/src/components/resolution-tool/stories/index.js +48 -0
- package/src/components/url-input/index.js +2 -0
- package/src/private-apis.js +4 -0
- package/src/store/defaults.js +1 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import _styled from "@emotion/styled/base";
|
|
2
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
3
|
+
|
|
4
|
+
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* External dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { __experimentalToolsPanelItem as ToolsPanelItem, __experimentalUnitControl as UnitControl } from '@wordpress/components';
|
|
14
|
+
import { __ } from '@wordpress/i18n';
|
|
15
|
+
|
|
16
|
+
const SingleColumnToolsPanelItem = /*#__PURE__*/_styled(ToolsPanelItem, process.env.NODE_ENV === "production" ? {
|
|
17
|
+
target: "ef8pe3d0"
|
|
18
|
+
} : {
|
|
19
|
+
target: "ef8pe3d0",
|
|
20
|
+
label: "SingleColumnToolsPanelItem"
|
|
21
|
+
})(process.env.NODE_ENV === "production" ? {
|
|
22
|
+
name: "957xgf",
|
|
23
|
+
styles: "grid-column:span 1"
|
|
24
|
+
} : {
|
|
25
|
+
name: "957xgf",
|
|
26
|
+
styles: "grid-column:span 1",
|
|
27
|
+
map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIkB3b3JkcHJlc3MvYmxvY2stZWRpdG9yL3NyYy9jb21wb25lbnRzL2RpbWVuc2lvbnMtdG9vbC93aWR0aC1oZWlnaHQtdG9vbC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFjMkQiLCJmaWxlIjoiQHdvcmRwcmVzcy9ibG9jay1lZGl0b3Ivc3JjL2NvbXBvbmVudHMvZGltZW5zaW9ucy10b29sL3dpZHRoLWhlaWdodC10b29sLmpzIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBFeHRlcm5hbCBkZXBlbmRlbmNpZXNcbiAqL1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnO1xuXG4vKipcbiAqIFdvcmRQcmVzcyBkZXBlbmRlbmNpZXNcbiAqL1xuaW1wb3J0IHtcblx0X19leHBlcmltZW50YWxUb29sc1BhbmVsSXRlbSBhcyBUb29sc1BhbmVsSXRlbSxcblx0X19leHBlcmltZW50YWxVbml0Q29udHJvbCBhcyBVbml0Q29udHJvbCxcbn0gZnJvbSAnQHdvcmRwcmVzcy9jb21wb25lbnRzJztcbmltcG9ydCB7IF9fIH0gZnJvbSAnQHdv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G9vbHNQYW5lbEl0ZW0+XG5cdFx0PC8+XG5cdCk7XG59XG4iXX0= */",
|
|
28
|
+
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {Object} WidthHeightToolValue
|
|
36
|
+
* @property {string} [width] Width CSS value.
|
|
37
|
+
* @property {string} [height] Height CSS value.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @callback WidthHeightToolOnChange
|
|
42
|
+
* @param {WidthHeightToolValue} nextValue Next dimensions value.
|
|
43
|
+
* @return {void}
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {Object} WidthHeightToolProps
|
|
48
|
+
* @property {string} [panelId] ID of the panel that contains the controls.
|
|
49
|
+
* @property {WidthHeightToolValue} [value] Current dimensions values.
|
|
50
|
+
* @property {WidthHeightToolOnChange} [onChange] Callback to update the dimensions values.
|
|
51
|
+
* @property {WPUnitControlUnit[]} [units] Units options.
|
|
52
|
+
* @property {boolean} [isShownByDefault] Whether the panel is shown by default.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Component that renders controls to edit the dimensions of an image or container.
|
|
57
|
+
*
|
|
58
|
+
* @param {WidthHeightToolProps} props The component props.
|
|
59
|
+
*
|
|
60
|
+
* @return {import('@wordpress/element').WPElement} The width and height tool.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export default function WidthHeightTool({
|
|
65
|
+
panelId,
|
|
66
|
+
value = {},
|
|
67
|
+
onChange = () => {},
|
|
68
|
+
units,
|
|
69
|
+
isShownByDefault = true
|
|
70
|
+
}) {
|
|
71
|
+
var _value$width, _value$height;
|
|
72
|
+
|
|
73
|
+
// null, undefined, and 'auto' all represent the default value.
|
|
74
|
+
const width = value.width === 'auto' ? '' : (_value$width = value.width) !== null && _value$width !== void 0 ? _value$width : '';
|
|
75
|
+
const height = value.height === 'auto' ? '' : (_value$height = value.height) !== null && _value$height !== void 0 ? _value$height : '';
|
|
76
|
+
|
|
77
|
+
const onDimensionChange = dimension => nextDimension => {
|
|
78
|
+
const nextValue = { ...value
|
|
79
|
+
}; // Empty strings or undefined may be passed and both represent removing the value.
|
|
80
|
+
|
|
81
|
+
if (!nextDimension) {
|
|
82
|
+
delete nextValue[dimension];
|
|
83
|
+
} else {
|
|
84
|
+
nextValue[dimension] = nextDimension;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onChange(nextValue);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return createElement(Fragment, null, createElement(SingleColumnToolsPanelItem, {
|
|
91
|
+
label: __('Width'),
|
|
92
|
+
isShownByDefault: isShownByDefault,
|
|
93
|
+
hasValue: () => width !== '',
|
|
94
|
+
onDeselect: onDimensionChange('width'),
|
|
95
|
+
panelId: panelId
|
|
96
|
+
}, createElement(UnitControl, {
|
|
97
|
+
label: __('Width'),
|
|
98
|
+
placeholder: __('Auto'),
|
|
99
|
+
labelPosition: "top",
|
|
100
|
+
units: units,
|
|
101
|
+
min: 0,
|
|
102
|
+
value: width,
|
|
103
|
+
onChange: onDimensionChange('width'),
|
|
104
|
+
size: '__unstable-large'
|
|
105
|
+
})), createElement(SingleColumnToolsPanelItem, {
|
|
106
|
+
label: __('Height'),
|
|
107
|
+
isShownByDefault: isShownByDefault,
|
|
108
|
+
hasValue: () => height !== '',
|
|
109
|
+
onDeselect: onDimensionChange('height'),
|
|
110
|
+
panelId: panelId
|
|
111
|
+
}, createElement(UnitControl, {
|
|
112
|
+
label: __('Height'),
|
|
113
|
+
placeholder: __('Auto'),
|
|
114
|
+
labelPosition: "top",
|
|
115
|
+
units: units,
|
|
116
|
+
min: 0,
|
|
117
|
+
value: height,
|
|
118
|
+
onChange: onDimensionChange('height'),
|
|
119
|
+
size: '__unstable-large'
|
|
120
|
+
})));
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=width-height-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/dimensions-tool/width-height-tool.js"],"names":["__experimentalToolsPanelItem","ToolsPanelItem","__experimentalUnitControl","UnitControl","__","SingleColumnToolsPanelItem","WidthHeightTool","panelId","value","onChange","units","isShownByDefault","width","height","onDimensionChange","dimension","nextDimension","nextValue"],"mappings":";;;;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SACCA,4BAA4B,IAAIC,cADjC,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,uBAHP;AAIA,SAASC,EAAT,QAAmB,iBAAnB;;AAEA,MAAMC,0BAA0B,GAAG,qBAAQJ,cAAR;AAAA;AAAA;AAAA;AAAA;AAAA,EAAH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAhC;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASK,eAAT,CAA0B;AACxCC,EAAAA,OADwC;AAExCC,EAAAA,KAAK,GAAG,EAFgC;AAGxCC,EAAAA,QAAQ,GAAG,MAAM,CAAE,CAHqB;AAIxCC,EAAAA,KAJwC;AAKxCC,EAAAA,gBAAgB,GAAG;AALqB,CAA1B,EAMX;AAAA;;AACH;AACA,QAAMC,KAAK,GAAGJ,KAAK,CAACI,KAAN,KAAgB,MAAhB,GAAyB,EAAzB,mBAA8BJ,KAAK,CAACI,KAApC,uDAA6C,EAA3D;AACA,QAAMC,MAAM,GAAGL,KAAK,CAACK,MAAN,KAAiB,MAAjB,GAA0B,EAA1B,oBAA+BL,KAAK,CAACK,MAArC,yDAA+C,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W,EAAGA,EAAE,CAAE,MAAF,CAFjB;AAGC,IAAA,aAAa,EAAC,KAHf;AAIC,IAAA,KAAK,EAAGM,KAJT;AAKC,IAAA,GAAG,EAAG,CALP;AAMC,IAAA,KAAK,EAAGG,MANT;AAOC,IAAA,QAAQ,EAAGC,iBAAiB,CAAE,QAAF,CAP7B;AAQC,IAAA,IAAI,EAAG;AARR,IAPD,CAnBD,CADD;AAwCA","sourcesContent":["/**\n * External dependencies\n */\nimport styled from '@emotion/styled';\n\n/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalUnitControl as UnitControl,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nconst SingleColumnToolsPanelItem = styled( ToolsPanelItem )`\n\tgrid-column: span 1;\n`;\n\n/**\n * @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit\n */\n\n/**\n * @typedef {Object} WidthHeightToolValue\n * @property {string} [width] Width CSS value.\n * @property {string} [height] Height CSS value.\n */\n\n/**\n * @callback WidthHeightToolOnChange\n * @param {WidthHeightToolValue} nextValue Next dimensions value.\n * @return {void}\n */\n\n/**\n * @typedef {Object} WidthHeightToolProps\n * @property {string} [panelId] ID of the panel that contains the controls.\n * @property {WidthHeightToolValue} [value] Current dimensions values.\n * @property {WidthHeightToolOnChange} [onChange] Callback to update the dimensions values.\n * @property {WPUnitControlUnit[]} [units] Units options.\n * @property {boolean} [isShownByDefault] Whether the panel is shown by default.\n */\n\n/**\n * Component that renders controls to edit the dimensions of an image or container.\n *\n * @param {WidthHeightToolProps} props The component props.\n *\n * @return {import('@wordpress/element').WPElement} The width and height tool.\n */\nexport default function WidthHeightTool( {\n\tpanelId,\n\tvalue = {},\n\tonChange = () => {},\n\tunits,\n\tisShownByDefault = true,\n} ) {\n\t// null, undefined, and 'auto' all represent the default value.\n\tconst width = value.width === 'auto' ? '' : value.width ?? '';\n\tconst height = value.height === 'auto' ? '' : value.height ?? '';\n\n\tconst onDimensionChange = ( dimension ) => ( nextDimension ) => {\n\t\tconst nextValue = { ...value };\n\t\t// Empty strings or undefined may be passed and both represent removing the value.\n\t\tif ( ! nextDimension ) {\n\t\t\tdelete nextValue[ dimension ];\n\t\t} else {\n\t\t\tnextValue[ dimension ] = nextDimension;\n\t\t}\n\t\tonChange( nextValue );\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<SingleColumnToolsPanelItem\n\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\thasValue={ () => width !== '' }\n\t\t\t\tonDeselect={ onDimensionChange( 'width' ) }\n\t\t\t\tpanelId={ panelId }\n\t\t\t>\n\t\t\t\t<UnitControl\n\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\tplaceholder={ __( 'Auto' ) }\n\t\t\t\t\tlabelPosition=\"top\"\n\t\t\t\t\tunits={ units }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tvalue={ width }\n\t\t\t\t\tonChange={ onDimensionChange( 'width' ) }\n\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t/>\n\t\t\t</SingleColumnToolsPanelItem>\n\t\t\t<SingleColumnToolsPanelItem\n\t\t\t\tlabel={ __( 'Height' ) }\n\t\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\t\thasValue={ () => height !== '' }\n\t\t\t\tonDeselect={ onDimensionChange( 'height' ) }\n\t\t\t\tpanelId={ panelId }\n\t\t\t>\n\t\t\t\t<UnitControl\n\t\t\t\t\tlabel={ __( 'Height' ) }\n\t\t\t\t\tplaceholder={ __( 'Auto' ) }\n\t\t\t\t\tlabelPosition=\"top\"\n\t\t\t\t\tunits={ units }\n\t\t\t\t\tmin={ 0 }\n\t\t\t\t\tvalue={ height }\n\t\t\t\t\tonChange={ onDimensionChange( 'height' ) }\n\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t/>\n\t\t\t</SingleColumnToolsPanelItem>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -61,7 +61,7 @@ export default function AspectRatioDropdown({
|
|
|
61
61
|
onClose();
|
|
62
62
|
},
|
|
63
63
|
value: aspect,
|
|
64
|
-
aspectRatios: [// All ratios should be mirrored in
|
|
64
|
+
aspectRatios: [// All ratios should be mirrored in AspectRatioTool in @wordpress/block-editor.
|
|
65
65
|
{
|
|
66
66
|
title: __('Original'),
|
|
67
67
|
aspect: defaultAspect
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/aspect-ratio-dropdown.js"],"names":["check","aspectRatio","aspectRatioIcon","DropdownMenu","MenuGroup","MenuItem","__","POPOVER_PROPS","useImageEditingContext","AspectGroup","aspectRatios","isDisabled","label","onClick","value","map","title","aspect","undefined","AspectRatioDropdown","toggleProps","isInProgress","setAspect","defaultAspect","onClose","newAspect"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,WAAW,IAAIC,eAA/B,QAAsD,kBAAtD;AACA,SAASC,YAAT,EAAuBC,SAAvB,EAAkCC,QAAlC,QAAkD,uBAAlD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,aAA9B;AACA,SAASC,sBAAT,QAAuC,WAAvC;;AAEA,SAASC,WAAT,CAAsB;AAAEC,EAAAA,YAAF;AAAgBC,EAAAA,UAAhB;AAA4BC,EAAAA,KAA5B;AAAmCC,EAAAA,OAAnC;AAA4CC,EAAAA;AAA5C,CAAtB,EAA4E;AAC3E,SACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGF;AAAnB,KACGF,YAAY,CAACK,GAAb,CAAkB,CAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF,KACnB,cAAC,QAAD;AACC,IAAA,GAAG,EAAGA,MADP;AAEC,IAAA,QAAQ,EAAGN,UAFZ;AAGC,IAAA,OAAO,EAAG,MAAM;AACfE,MAAAA,OA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;AACAD,MAAAA,OAAO;AACP,KANF;AAOC,IAAA,KAAK,EAAGP,MAPT;AAQC,IAAA,YAAY,EAAG,CACd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,OAAF,CADV;AAECW,MAAAA,MAAM,EAAE,KAAK;AAFd,KADc,EAKd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,MAAF,CADV;AAECW,MAAAA,MAAM,EAAE,KAAK;AAFd,KALc,EASd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KATc,EAad;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KAbc;AARhB,IApBD,EA+CC,cAAC,WAAD;AACC,IAAA,KAAK,EAAGX,EAAE,CAAE,UAAF,CADX;AAEC,IAAA,UAAU,EAAGe,YAFd;AAGC,IAAA,OAAO,EAAKI,SAAF,IAAiB;AAC1BH,MAAAA,SAAS,CAAEG,SAAF,CAAT;AACAD,MAAAA,OAAO;AACP,KANF;AAOC,IAAA,KAAK,EAAGP,MAPT;AAQC,IAAA,YAAY,EAAG,CACd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,OAAF,CADV;AAECW,MAAAA,MAAM,EAAE,KAAK;AAFd,KADc,EAKd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,MAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KALc,EASd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KATc,EAad;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KAbc;AARhB,IA/CD,CARF,CADD;AAuFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { check, aspectRatio as aspectRatioIcon } from '@wordpress/icons';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { POPOVER_PROPS } from './constants';\nimport { useImageEditingContext } from './context';\n\nfunction AspectGroup( { aspectRatios, isDisabled, label, onClick, value } ) {\n\treturn (\n\t\t<MenuGroup label={ label }>\n\t\t\t{ aspectRatios.map( ( { title, aspect } ) => (\n\t\t\t\t<MenuItem\n\t\t\t\t\tkey={ aspect }\n\t\t\t\t\tdisabled={ isDisabled }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tonClick( aspect );\n\t\t\t\t\t} }\n\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\tisSelected={ aspect === value }\n\t\t\t\t\ticon={ aspect === value ? check : undefined }\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</MenuItem>\n\t\t\t) ) }\n\t\t</MenuGroup>\n\t);\n}\n\nexport default function AspectRatioDropdown( { toggleProps } ) {\n\tconst { isInProgress, aspect, setAspect, defaultAspect } =\n\t\tuseImageEditingContext();\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ aspectRatioIcon }\n\t\t\tlabel={ __( 'Aspect Ratio' ) }\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\ttoggleProps={ toggleProps }\n\t\t\tclassName=\"wp-block-image__aspect-ratio\"\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<AspectGroup\n\t\t\t\t\t\tisDisabled={ isInProgress }\n\t\t\t\t\t\tonClick={ ( newAspect ) => {\n\t\t\t\t\t\t\tsetAspect( newAspect );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ aspect }\n\t\t\t\t\t\taspectRatios={ [\n\t\t\t\t\t\t\t// All ratios should be mirrored in
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/aspect-ratio-dropdown.js"],"names":["check","aspectRatio","aspectRatioIcon","DropdownMenu","MenuGroup","MenuItem","__","POPOVER_PROPS","useImageEditingContext","AspectGroup","aspectRatios","isDisabled","label","onClick","value","map","title","aspect","undefined","AspectRatioDropdown","toggleProps","isInProgress","setAspect","defaultAspect","onClose","newAspect"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,WAAW,IAAIC,eAA/B,QAAsD,kBAAtD;AACA,SAASC,YAAT,EAAuBC,SAAvB,EAAkCC,QAAlC,QAAkD,uBAAlD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,aAA9B;AACA,SAASC,sBAAT,QAAuC,WAAvC;;AAEA,SAASC,WAAT,CAAsB;AAAEC,EAAAA,YAAF;AAAgBC,EAAAA,UAAhB;AAA4BC,EAAAA,KAA5B;AAAmCC,EAAAA,OAAnC;AAA4CC,EAAAA;AAA5C,CAAtB,EAA4E;AAC3E,SACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGF;AAAnB,KACGF,YAAY,CAACK,GAAb,CAAkB,CAAE;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAF,KACnB,cAAC,QAAD;AACC,IAAA,GAAG,EAAGA,MADP;AAEC,IAAA,QAAQ,EAAGN,UAFZ;AAGC,IAAA,OAAO,EAAG,MAAM;AACfE,MAAAA,OAAO,CAAEI,MAAF,CAAP;AACA,KALF;AAMC,IAAA,IAAI,EAAC,eANN;AAOC,IAAA,UAAU,EAAGA,MAAM,KAAKH,KAPzB;AAQC,IAAA,IAAI,EAAGG,MAAM,KAAKH,KAAX,GAAmBd,KAAnB,GAA2BkB;AARnC,KAUGF,KAVH,CADC,CADH,CADD;AAkBA;;AAED,eAAe,SAASG,mBAAT,CAA8B;AAAEC,EAAAA;AAAF,CAA9B,EAAgD;AAC9D,QAAM;AAAEC,IAAAA,YAAF;AAAgBJ,IAAAA,MAAhB;AAAwBK,IAAAA,SAAxB;AAAmCC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c,EAad;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KAbc;AARhB,IApBD,EA+CC,cAAC,WAAD;AACC,IAAA,KAAK,EAAGX,EAAE,CAAE,UAAF,CADX;AAEC,IAAA,UAAU,EAAGe,YAFd;AAGC,IAAA,OAAO,EAAKI,SAAF,IAAiB;AAC1BH,MAAAA,SAAS,CAAEG,SAAF,CAAT;AACAD,MAAAA,OAAO;AACP,KANF;AAOC,IAAA,KAAK,EAAGP,MAPT;AAQC,IAAA,YAAY,EAAG,CACd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,OAAF,CADV;AAECW,MAAAA,MAAM,EAAE,KAAK;AAFd,KADc,EAKd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,MAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KALc,EASd;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KATc,EAad;AACCD,MAAAA,KAAK,EAAEV,EAAE,CAAE,KAAF,CADV;AAECW,MAAAA,MAAM,EAAE,IAAI;AAFb,KAbc;AARhB,IA/CD,CARF,CADD;AAuFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { check, aspectRatio as aspectRatioIcon } from '@wordpress/icons';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { POPOVER_PROPS } from './constants';\nimport { useImageEditingContext } from './context';\n\nfunction AspectGroup( { aspectRatios, isDisabled, label, onClick, value } ) {\n\treturn (\n\t\t<MenuGroup label={ label }>\n\t\t\t{ aspectRatios.map( ( { title, aspect } ) => (\n\t\t\t\t<MenuItem\n\t\t\t\t\tkey={ aspect }\n\t\t\t\t\tdisabled={ isDisabled }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tonClick( aspect );\n\t\t\t\t\t} }\n\t\t\t\t\trole=\"menuitemradio\"\n\t\t\t\t\tisSelected={ aspect === value }\n\t\t\t\t\ticon={ aspect === value ? check : undefined }\n\t\t\t\t>\n\t\t\t\t\t{ title }\n\t\t\t\t</MenuItem>\n\t\t\t) ) }\n\t\t</MenuGroup>\n\t);\n}\n\nexport default function AspectRatioDropdown( { toggleProps } ) {\n\tconst { isInProgress, aspect, setAspect, defaultAspect } =\n\t\tuseImageEditingContext();\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\ticon={ aspectRatioIcon }\n\t\t\tlabel={ __( 'Aspect Ratio' ) }\n\t\t\tpopoverProps={ POPOVER_PROPS }\n\t\t\ttoggleProps={ toggleProps }\n\t\t\tclassName=\"wp-block-image__aspect-ratio\"\n\t\t>\n\t\t\t{ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<AspectGroup\n\t\t\t\t\t\tisDisabled={ isInProgress }\n\t\t\t\t\t\tonClick={ ( newAspect ) => {\n\t\t\t\t\t\t\tsetAspect( newAspect );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ aspect }\n\t\t\t\t\t\taspectRatios={ [\n\t\t\t\t\t\t\t// All ratios should be mirrored in AspectRatioTool in @wordpress/block-editor.\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( 'Original' ),\n\t\t\t\t\t\t\t\taspect: defaultAspect,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( 'Square' ),\n\t\t\t\t\t\t\t\taspect: 1,\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<AspectGroup\n\t\t\t\t\t\tlabel={ __( 'Landscape' ) }\n\t\t\t\t\t\tisDisabled={ isInProgress }\n\t\t\t\t\t\tonClick={ ( newAspect ) => {\n\t\t\t\t\t\t\tsetAspect( newAspect );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ aspect }\n\t\t\t\t\t\taspectRatios={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '16:10' ),\n\t\t\t\t\t\t\t\taspect: 16 / 10,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '16:9' ),\n\t\t\t\t\t\t\t\taspect: 16 / 9,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '4:3' ),\n\t\t\t\t\t\t\t\taspect: 4 / 3,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '3:2' ),\n\t\t\t\t\t\t\t\taspect: 3 / 2,\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<AspectGroup\n\t\t\t\t\t\tlabel={ __( 'Portrait' ) }\n\t\t\t\t\t\tisDisabled={ isInProgress }\n\t\t\t\t\t\tonClick={ ( newAspect ) => {\n\t\t\t\t\t\t\tsetAspect( newAspect );\n\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tvalue={ aspect }\n\t\t\t\t\t\taspectRatios={ [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '10:16' ),\n\t\t\t\t\t\t\t\taspect: 10 / 16,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '9:16' ),\n\t\t\t\t\t\t\t\taspect: 9 / 16,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '3:4' ),\n\t\t\t\t\t\t\t\taspect: 3 / 4,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttitle: __( '2:3' ),\n\t\t\t\t\t\t\t\taspect: 2 / 3,\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</>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"]}
|
|
@@ -65,8 +65,7 @@ export default function useSaveImage({
|
|
|
65
65
|
}).then(response => {
|
|
66
66
|
onSaveImage({
|
|
67
67
|
id: response.id,
|
|
68
|
-
url: response.source_url
|
|
69
|
-
height: height && width ? width / aspect : undefined
|
|
68
|
+
url: response.source_url
|
|
70
69
|
});
|
|
71
70
|
}).catch(error => {
|
|
72
71
|
createErrorNotice(sprintf(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"names":["apiFetch","useDispatch","useCallback","useMemo","useState","__","sprintf","store","noticesStore","__unstableStripHTML","stripHTML","useSaveImage","crop","rotation","height","width","aspect","url","id","onSaveImage","onFinishEditing","createErrorNotice","isInProgress","setIsInProgress","cancel","apply","modifiers","push","type","args","angle","left","x","top","y","path","method","data","src","then","response","source_url","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/image-editor/use-save-image.js"],"names":["apiFetch","useDispatch","useCallback","useMemo","useState","__","sprintf","store","noticesStore","__unstableStripHTML","stripHTML","useSaveImage","crop","rotation","height","width","aspect","url","id","onSaveImage","onFinishEditing","createErrorNotice","isInProgress","setIsInProgress","cancel","apply","modifiers","push","type","args","angle","left","x","top","y","path","method","data","src","then","response","source_url","catch","error","message","finally"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,QAA/B,QAA+C,oBAA/C;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AACA,SAASC,mBAAmB,IAAIC,S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D,UAAAA,MAAM,EAAEF,IAAI,CAACE;AAJR;AAFS,OAAhB;AASA;;AAEDd,IAAAA,QAAQ,CAAE;AACTmC,MAAAA,IAAI,EAAG,gBAAgBjB,EAAI,OADlB;AAETkB,MAAAA,MAAM,EAAE,MAFC;AAGTC,MAAAA,IAAI,EAAE;AAAEC,QAAAA,GAAG,EAAErB,GAAP;AAAYS,QAAAA;AAAZ;AAHG,KAAF,CAAR,CAKEa,IALF,CAKUC,QAAF,IAAgB;AACtBrB,MAAAA,WAAW,CAAE;AACZD,QAAAA,EAAE,EAAEsB,QAAQ,CAACtB,EADD;AAEZD,QAAAA,GAAG,EAAEuB,QAAQ,CAACC;AAFF,OAAF,CAAX;AAIA,KAVF,EAWEC,KAXF,CAWWC,KAAF,IAAa;AACpBtB,MAAAA,iBAAiB,CAChBf,OAAO;AACN;AACAD,MAAAA,EAAE,CAAE,0BAAF,CAFI,EAGNK,SAAS,CAAEiC,KAAK,CAACC,OAAR,CAHH,CADS,EAMhB;AACC1B,QAAAA,EAAE,EAAE,qBADL;AAECU,QAAAA,IAAI,EAAE;AAFP,OANgB,CAAjB;AAWA,KAvBF,EAwBEiB,OAxBF,CAwBW,MAAM;AACftB,MAAAA,eAAe,CAAE,KAAF,CAAf;AACAH,MAAAA,eAAe;AACf,KA3BF;AA4BA,GAxDwB,EAwDtB,CACFG,eADE,EAEFX,IAFE,EAGFC,QAHE,EAIFC,MAJE,EAKFC,KALE,EAMFC,MANE,EAOFC,GAPE,EAQFE,WARE,EASFE,iBATE,EAUFE,eAVE,EAWFH,eAXE,CAxDsB,CAAzB;AAsEA,SAAOjB,OAAO,CACb,OAAQ;AACPmB,IAAAA,YADO;AAEPG,IAAAA,KAFO;AAGPD,IAAAA;AAHO,GAAR,CADa,EAMb,CAAEF,YAAF,EAAgBG,KAAhB,EAAuBD,MAAvB,CANa,CAAd;AAQA","sourcesContent":["/**\n * WordPress dependencies\n */\n// Disable Reason: Needs to be refactored.\n// eslint-disable-next-line no-restricted-imports\nimport apiFetch from '@wordpress/api-fetch';\nimport { useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\n\nexport default function useSaveImage( {\n\tcrop,\n\trotation,\n\theight,\n\twidth,\n\taspect,\n\turl,\n\tid,\n\tonSaveImage,\n\tonFinishEditing,\n} ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst [ isInProgress, setIsInProgress ] = useState( false );\n\n\tconst cancel = useCallback( () => {\n\t\tsetIsInProgress( false );\n\t\tonFinishEditing();\n\t}, [ setIsInProgress, onFinishEditing ] );\n\n\tconst apply = useCallback( () => {\n\t\tsetIsInProgress( true );\n\n\t\tconst modifiers = [];\n\n\t\tif ( rotation > 0 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'rotate',\n\t\t\t\targs: {\n\t\t\t\t\tangle: rotation,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t// The crop script may return some very small, sub-pixel values when the image was not cropped.\n\t\t// Crop only when the new size has changed by more than 0.1%.\n\t\tif ( crop.width < 99.9 || crop.height < 99.9 ) {\n\t\t\tmodifiers.push( {\n\t\t\t\ttype: 'crop',\n\t\t\t\targs: {\n\t\t\t\t\tleft: crop.x,\n\t\t\t\t\ttop: crop.y,\n\t\t\t\t\twidth: crop.width,\n\t\t\t\t\theight: crop.height,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\tapiFetch( {\n\t\t\tpath: `/wp/v2/media/${ id }/edit`,\n\t\t\tmethod: 'POST',\n\t\t\tdata: { src: url, modifiers },\n\t\t} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tonSaveImage( {\n\t\t\t\t\tid: response.id,\n\t\t\t\t\turl: response.source_url,\n\t\t\t\t} );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: 1. Error message */\n\t\t\t\t\t\t__( 'Could not edit image. %s' ),\n\t\t\t\t\t\tstripHTML( error.message )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'image-editing-error',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tsetIsInProgress( false );\n\t\t\t\tonFinishEditing();\n\t\t\t} );\n\t}, [\n\t\tsetIsInProgress,\n\t\tcrop,\n\t\trotation,\n\t\theight,\n\t\twidth,\n\t\taspect,\n\t\turl,\n\t\tonSaveImage,\n\t\tcreateErrorNotice,\n\t\tsetIsInProgress,\n\t\tonFinishEditing,\n\t] );\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tisInProgress,\n\t\t\tapply,\n\t\t\tcancel,\n\t\t} ),\n\t\t[ isInProgress, apply, cancel ]\n\t);\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { Button, ButtonGroup, SelectControl, __experimentalNumberControl as NumberControl, __experimentalHStack as HStack } from '@wordpress/components';
|
|
7
|
+
import deprecated from '@wordpress/deprecated';
|
|
7
8
|
import { __ } from '@wordpress/i18n';
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
@@ -26,6 +27,10 @@ export default function ImageSizeControl({
|
|
|
26
27
|
onChange,
|
|
27
28
|
onChangeImage = noop
|
|
28
29
|
}) {
|
|
30
|
+
deprecated('wp.blockEditor.__experimentalImageSizeControl', {
|
|
31
|
+
since: '6.3',
|
|
32
|
+
alternative: 'wp.blockEditor.privateApis.DimensionsTool and wp.blockEditor.privateApis.ResolutionTool'
|
|
33
|
+
});
|
|
29
34
|
const {
|
|
30
35
|
currentHeight,
|
|
31
36
|
currentWidth,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/image-size-control/index.js"],"names":["Button","ButtonGroup","SelectControl","__experimentalNumberControl","NumberControl","__experimentalHStack","HStack","__","useDimensionHandler","IMAGE_SIZE_PRESETS","noop","ImageSizeControl","imageSizeHelp","imageWidth","imageHeight","imageSizeOptions","isResizable","slug","width","height","onChange","onChangeImage","currentHeight","currentWidth","updateDimension","updateDimensions","length","value","map","scale","scaledWidth","Math","round","scaledHeight","isCurrent","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,MADD,EAECC,WAFD,EAGCC,aAHD,EAICC,2BAA2B,IAAIC,aAJhC,EAKCC,oBAAoB,IAAIC,MALzB,QAMO,uBANP;AAOA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,yBAAhC;AAEA,MAAMC,kBAAkB,GAAG,CAAE,EAAF,EAAM,EAAN,EAAU,EAAV,EAAc,GAAd,CAA3B;;AACA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEA,eAAe,SAASC,gBAAT,CAA2B;AACzCC,EAAAA,aADyC;AAEzCC,EAAAA,UAFyC;AAGzCC,EAAAA,WAHyC;AAIzCC,EAAAA,gBAAgB,GAAG,EAJsB;AAKzCC,EAAAA,WAAW,GAAG,IAL2B;AAMzCC,EAAAA,IANyC;AAOzCC,EAAAA,KAPyC;AAQzCC,EAAAA,MARyC;AASzCC,EAAAA,QATyC;AAUzCC,EAAAA,aAAa,GAAGX;AAVyB,CAA3B,EAWX;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/image-size-control/index.js"],"names":["Button","ButtonGroup","SelectControl","__experimentalNumberControl","NumberControl","__experimentalHStack","HStack","deprecated","__","useDimensionHandler","IMAGE_SIZE_PRESETS","noop","ImageSizeControl","imageSizeHelp","imageWidth","imageHeight","imageSizeOptions","isResizable","slug","width","height","onChange","onChangeImage","since","alternative","currentHeight","currentWidth","updateDimension","updateDimensions","length","value","map","scale","scaledWidth","Math","round","scaledHeight","isCurrent","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SACCA,MADD,EAECC,WAFD,EAGCC,aAHD,EAICC,2BAA2B,IAAIC,aAJhC,EAKCC,oBAAoB,IAAIC,MALzB,QAMO,uBANP;AAOA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,yBAAhC;AAEA,MAAMC,kBAAkB,GAAG,CAAE,EAAF,EAAM,EAAN,EAAU,EAAV,EAAc,GAAd,CAA3B;;AACA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEA,eAAe,SAASC,gBAAT,CAA2B;AACzCC,EAAAA,aADyC;AAEzCC,EAAAA,UAFyC;AAGzCC,EAAAA,WAHyC;AAIzCC,EAAAA,gBAAgB,GAAG,EAJsB;AAKzCC,EAAAA,WAAW,GAAG,IAL2B;AAMzCC,EAAAA,IANyC;AAOzCC,EAAAA,KAPyC;AAQzCC,EAAAA,MARyC;AASzCC,EAAAA,QATyC;AAUzCC,EAAAA,aAAa,GAAGX;AAVyB,CAA3B,EAWX;AACHJ,EAAAA,UAAU,CAAE,+CAAF,EAAmD;AAC5DgB,IAAAA,KAAK,EAAE,KADqD;AAE5DC,IAAAA,WAAW,EACV;AAH2D,GAAnD,CAAV;AAKA,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,YAAjB;AAA+BC,IAAAA,eAA/B;AAAgDC,IAAAA;AAAhD,MACLnB,mBAAmB,CAAEW,MAAF,EAAUD,KAAV,EAAiBJ,WAAjB,EAA8BD,UAA9B,EAA0CO,QAA1C,CADpB;AAGA,SACC,8BACGL,gBAAgB,IAAIA,gBAAgB,CAACa,MAAjB,GAA0B,CAA9C,IACD,cAAC,aAAD;AACC,IAAA,uBAAuB,MADxB;AAEC,IAAA,KAAK,EAAGrB,EAAE,CAAE,YAAF,CAFX;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,WACC,cAAC,MAAD;AACC,MAAA,GAAG,EAAGJ,KADP;AAEC,MAAA,OAAO,MAFR;AAGC,MAAA,OAAO,EACNK,SAAS,GAAG,SAAH,GAAeC,SAJ1B;AAMC,MAAA,SAAS,EAAGD,SANb;AAOC,MAAA,OAAO,EAAG,MACTT,gBAAgB,CACfQ,YADe,EAEfH,WAFe;AARlB,OAcGD,KAdH,MADD;AAkBA,GA9BC,CADH,CADD,EAkCC,cAAC,MAAD;AAAQ,IAAA,OAAO,MAAf;AAAgB,IAAA,OAAO,EAAG,MAAMJ,gBAAgB;AAAhD,KACGpB,EAAE,CAAE,OAAF,CADL,CAlCD,CAvBD,CAbF,CADD;AA+EA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tButtonGroup,\n\tSelectControl,\n\t__experimentalNumberControl as NumberControl,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport deprecated from '@wordpress/deprecated';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport useDimensionHandler from './use-dimension-handler';\n\nconst IMAGE_SIZE_PRESETS = [ 25, 50, 75, 100 ];\nconst noop = () => {};\n\nexport default function ImageSizeControl( {\n\timageSizeHelp,\n\timageWidth,\n\timageHeight,\n\timageSizeOptions = [],\n\tisResizable = true,\n\tslug,\n\twidth,\n\theight,\n\tonChange,\n\tonChangeImage = noop,\n} ) {\n\tdeprecated( 'wp.blockEditor.__experimentalImageSizeControl', {\n\t\tsince: '6.3',\n\t\talternative:\n\t\t\t'wp.blockEditor.privateApis.DimensionsTool and wp.blockEditor.privateApis.ResolutionTool',\n\t} );\n\tconst { currentHeight, currentWidth, updateDimension, updateDimensions } =\n\t\tuseDimensionHandler( height, width, imageHeight, imageWidth, onChange );\n\n\treturn (\n\t\t<>\n\t\t\t{ imageSizeOptions && imageSizeOptions.length > 0 && (\n\t\t\t\t<SelectControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Resolution' ) }\n\t\t\t\t\tvalue={ slug }\n\t\t\t\t\toptions={ imageSizeOptions }\n\t\t\t\t\tonChange={ onChangeImage }\n\t\t\t\t\thelp={ imageSizeHelp }\n\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ isResizable && (\n\t\t\t\t<div className=\"block-editor-image-size-control\">\n\t\t\t\t\t<HStack align=\"baseline\" spacing=\"3\">\n\t\t\t\t\t\t<NumberControl\n\t\t\t\t\t\t\tclassName=\"block-editor-image-size-control__width\"\n\t\t\t\t\t\t\tlabel={ __( 'Width' ) }\n\t\t\t\t\t\t\tvalue={ currentWidth }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tupdateDimension( 'width', value )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<NumberControl\n\t\t\t\t\t\t\tclassName=\"block-editor-image-size-control__height\"\n\t\t\t\t\t\t\tlabel={ __( 'Height' ) }\n\t\t\t\t\t\t\tvalue={ currentHeight }\n\t\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tupdateDimension( 'height', value )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsize=\"__unstable-large\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t<HStack>\n\t\t\t\t\t\t<ButtonGroup aria-label={ __( 'Image size presets' ) }>\n\t\t\t\t\t\t\t{ IMAGE_SIZE_PRESETS.map( ( scale ) => {\n\t\t\t\t\t\t\t\tconst scaledWidth = Math.round(\n\t\t\t\t\t\t\t\t\timageWidth * ( scale / 100 )\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst scaledHeight = Math.round(\n\t\t\t\t\t\t\t\t\timageHeight * ( scale / 100 )\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tconst isCurrent =\n\t\t\t\t\t\t\t\t\tcurrentWidth === scaledWidth &&\n\t\t\t\t\t\t\t\t\tcurrentHeight === scaledHeight;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tkey={ scale }\n\t\t\t\t\t\t\t\t\t\tisSmall\n\t\t\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\t\t\tisCurrent ? 'primary' : undefined\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tisPressed={ isCurrent }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tupdateDimensions(\n\t\t\t\t\t\t\t\t\t\t\t\tscaledHeight,\n\t\t\t\t\t\t\t\t\t\t\t\tscaledWidth\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ scale }%\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</ButtonGroup>\n\t\t\t\t\t\t<Button isSmall onClick={ () => updateDimensions() }>\n\t\t\t\t\t\t\t{ __( 'Reset' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -260,7 +260,8 @@ function LinkControl({
|
|
|
260
260
|
const currentUrlInputValue = propInputValue || internalControlValue?.url || '';
|
|
261
261
|
const currentInputIsEmpty = !currentUrlInputValue?.trim()?.length;
|
|
262
262
|
const shownUnlinkControl = onRemove && value && !isEditingLink && !isCreatingPage;
|
|
263
|
-
const showSettings = !!settings?.length
|
|
263
|
+
const showSettings = !!settings?.length && isEditingLink && hasLinkValue;
|
|
264
|
+
const showActions = isEditingLink && hasLinkValue; // Only show text control once a URL value has been committed
|
|
264
265
|
// and it isn't just empty whitespace.
|
|
265
266
|
// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.
|
|
266
267
|
|
|
@@ -278,7 +279,16 @@ function LinkControl({
|
|
|
278
279
|
'block-editor-link-control__search-input-wrapper': true,
|
|
279
280
|
'has-text-control': showTextControl
|
|
280
281
|
})
|
|
281
|
-
}, createElement(
|
|
282
|
+
}, showTextControl && createElement(TextControl, {
|
|
283
|
+
__nextHasNoMarginBottom: true,
|
|
284
|
+
ref: textInputRef,
|
|
285
|
+
className: "block-editor-link-control__field block-editor-link-control__text-content",
|
|
286
|
+
label: __('Text'),
|
|
287
|
+
value: internalControlValue?.title,
|
|
288
|
+
onChange: setInternalTextInputValue,
|
|
289
|
+
onKeyDown: handleSubmitWithEnter,
|
|
290
|
+
size: "__unstable-large"
|
|
291
|
+
}), createElement(LinkControlSearchInput, {
|
|
282
292
|
currentLink: value,
|
|
283
293
|
className: "block-editor-link-control__field block-editor-link-control__search-input",
|
|
284
294
|
placeholder: searchInputPlaceholder,
|
|
@@ -293,15 +303,7 @@ function LinkControl({
|
|
|
293
303
|
suggestionsQuery: suggestionsQuery,
|
|
294
304
|
withURLSuggestion: !noURLSuggestion,
|
|
295
305
|
createSuggestionButtonText: createSuggestionButtonText,
|
|
296
|
-
|
|
297
|
-
}), showTextControl && createElement(TextControl, {
|
|
298
|
-
__nextHasNoMarginBottom: true,
|
|
299
|
-
ref: textInputRef,
|
|
300
|
-
className: "block-editor-link-control__field block-editor-link-control__text-content",
|
|
301
|
-
label: __('Text'),
|
|
302
|
-
value: internalControlValue?.title,
|
|
303
|
-
onChange: setInternalTextInputValue,
|
|
304
|
-
onKeyDown: handleSubmitWithEnter
|
|
306
|
+
hideLabelFromVision: !showTextControl
|
|
305
307
|
})), errorMessage && createElement(Notice, {
|
|
306
308
|
className: "block-editor-link-control__search-error",
|
|
307
309
|
status: "error",
|
|
@@ -314,16 +316,16 @@ function LinkControl({
|
|
|
314
316
|
hasRichPreviews: hasRichPreviews,
|
|
315
317
|
hasUnlinkControl: shownUnlinkControl,
|
|
316
318
|
onRemove: onRemove
|
|
317
|
-
}),
|
|
319
|
+
}), showSettings && createElement("div", {
|
|
318
320
|
className: "block-editor-link-control__tools"
|
|
319
|
-
},
|
|
321
|
+
}, !currentInputIsEmpty && createElement(LinkControlSettingsDrawer, {
|
|
320
322
|
settingsOpen: settingsOpen,
|
|
321
323
|
setSettingsOpen: setSettingsOpen
|
|
322
324
|
}, createElement(LinkSettings, {
|
|
323
325
|
value: internalControlValue,
|
|
324
326
|
settings: settings,
|
|
325
327
|
onChange: createSetInternalSettingValueHandler(settingsKeys)
|
|
326
|
-
})), createElement("div", {
|
|
328
|
+
}))), showActions && createElement("div", {
|
|
327
329
|
className: "block-editor-link-control__search-actions"
|
|
328
330
|
}, createElement(Button, {
|
|
329
331
|
variant: "primary",
|
|
@@ -333,7 +335,7 @@ function LinkControl({
|
|
|
333
335
|
}, __('Save')), createElement(Button, {
|
|
334
336
|
variant: "tertiary",
|
|
335
337
|
onClick: handleCancel
|
|
336
|
-
}, __('Cancel')))
|
|
338
|
+
}, __('Cancel'))), renderControlBottom && renderControlBottom());
|
|
337
339
|
}
|
|
338
340
|
|
|
339
341
|
LinkControl.ViewerFill = ViewerFill;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/index.js"],"names":["classnames","Button","Spinner","Notice","TextControl","__","useRef","useState","useEffect","focus","ENTER","isShallowEqualObjects","LinkControlSettingsDrawer","LinkControlSearchInput","LinkPreview","LinkSettings","useCreatePage","useInternalValue","ViewerFill","DEFAULT_LINK_SETTINGS","noop","LinkControl","searchInputPlaceholder","value","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","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","nonSettingsChanges","Object","keys","reduce","acc","key","includes","title","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showSettings","showTextControl","isEditing","isDisabled"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,EAAiBC,OAAjB,EAA0BC,MAA1B,EAAkCC,WAAlC,QAAqD,uBAArD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,EAAiBC,QAAjB,EAA2BC,SAA3B,QAA4C,oBAA5C;AACA,SAASC,KAAT,QAAsB,gBAAtB;AACA,SAASC,KAAT,QAAsB,qBAAtB;AACA,SAASC,qBAAT,QAAsC,6BAAtC;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,mBAAtC;AACA,OAAOC,sBAAP,MAAmC,gBAAnC;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,OAAOC,YAAP,MAAyB,YAAzB;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AACA,SAASC,UAAT,QAA2B,eAA3B;AACA,SAASC,qBAAT,QAAsC,aAAtC;AAEA;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;AAC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AAG;AAHjB,KAKGA,YALH,CAvCF,CAZF,EA8DGxC,KAAK,IAAI,CAAEmC,aAAX,IAA4B,CAAEI,cAA9B,IACD,cAAC,WAAD;AACC,IAAA,GAAG,EAAGvC,KAAK,EAAEqC,GADd,CACoB;AADpB;AAEC,IAAA,KAAK,EAAGrC,KAFT;AAGC,IAAA,WAAW,EAAG,MAAMoC,gBAAgB,CAAE,IAAF,CAHrC;AAIC,IAAA,eAAe,EAAGpB,eAJnB;AAKC,IAAA,gBAAgB,EAAGwD,kBALpB;AAMC,IAAA,QAAQ,EAAGrE;AANZ,IA/DF,EAyEGwE,SAAS,IACV;AAAK,IAAA,SAAS,EAAC;AAAf,KACGF,YAAY,IACb,cAAC,yBAAD;AACC,IAAA,YAAY,EAAG9C,YADhB;AAEC,IAAA,eAAe,EAAGC;AAFnB,KAIC,cAAC,YAAD;AACC,IAAA,KAAK,EAAGC,oBADT;AAEC,IAAA,QAAQ,EAAG5B,QAFZ;AAGC,IAAA,QAAQ,EAAGgC,oCAAoC,CAC9CT,YAD8C;AAHhD,IAJD,CAFF,EAgBC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,OAAO,EAAGoD,UAAU,GAAG/E,IAAH,GAAUiE,YAF/B;AAGC,IAAA,SAAS,EAAC,0CAHX;AAIC,qBAAgBc;AAJjB,KAMG9F,EAAE,CAAE,MAAF,CANL,CADD,EASC,cAAC,MAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGwF;AAArC,KACGxF,EAAE,CAAE,QAAF,CADL,CATD,CAhBD,CA1EF,EA0GGoC,mBAAmB,IAAIA,mBAAmB,EA1G7C,CADD;AA8GA;;AAEDpB,WAAW,CAACH,UAAZ,GAAyBA,UAAzB;AAEA,eAAeG,WAAf","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;\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<LinkControlSearchInput\n\t\t\t\t\t\t\tcurrentLink={ value }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__field block-editor-link-control__search-input\"\n\t\t\t\t\t\t\tplaceholder={ searchInputPlaceholder }\n\t\t\t\t\t\t\tvalue={ currentUrlInputValue }\n\t\t\t\t\t\t\twithCreateSuggestion={ withCreateSuggestion }\n\t\t\t\t\t\t\tonCreateSuggestion={ createPage }\n\t\t\t\t\t\t\tonChange={ setInternalURLInputValue }\n\t\t\t\t\t\t\tonSelect={ handleSelectSuggestion }\n\t\t\t\t\t\t\tshowInitialSuggestions={ showInitialSuggestions }\n\t\t\t\t\t\t\tallowDirectEntry={ ! noDirectEntry }\n\t\t\t\t\t\t\tshowSuggestions={ showSuggestions }\n\t\t\t\t\t\t\tsuggestionsQuery={ suggestionsQuery }\n\t\t\t\t\t\t\twithURLSuggestion={ ! noURLSuggestion }\n\t\t\t\t\t\t\tcreateSuggestionButtonText={\n\t\t\t\t\t\t\t\tcreateSuggestionButtonText\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tuseLabel={ showTextControl }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ 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/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t\t{ errorMessage && (\n\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-error\"\n\t\t\t\t\t\t\tstatus=\"error\"\n\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ errorMessage }\n\t\t\t\t\t\t</Notice>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\n\t\t\t{ value && ! isEditingLink && ! isCreatingPage && (\n\t\t\t\t<LinkPreview\n\t\t\t\t\tkey={ value?.url } // force remount when URL changes to avoid race conditions for rich previews\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonEditClick={ () => setIsEditingLink( true ) }\n\t\t\t\t\thasRichPreviews={ hasRichPreviews }\n\t\t\t\t\thasUnlinkControl={ shownUnlinkControl }\n\t\t\t\t\tonRemove={ onRemove }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ isEditing && (\n\t\t\t\t<div className=\"block-editor-link-control__tools\">\n\t\t\t\t\t{ showSettings && (\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\n\t\t\t\t\t<div className=\"block-editor-link-control__search-actions\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ isDisabled ? noop : handleSubmit }\n\t\t\t\t\t\t\tclassName=\"block-editor-link-control__search-submit\"\n\t\t\t\t\t\t\taria-disabled={ isDisabled }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button variant=\"tertiary\" onClick={ handleCancel }>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t</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":["classnames","Button","Spinner","Notice","TextControl","__","useRef","useState","useEffect","focus","ENTER","isShallowEqualObjects","LinkControlSettingsDrawer","LinkControlSearchInput","LinkPreview","LinkSettings","useCreatePage","useInternalValue","ViewerFill","DEFAULT_LINK_SETTINGS","noop","LinkControl","searchInputPlaceholder","value","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","focusable","find","hasLinkValue","trim","length","stopEditing","contains","ownerDocument","activeElement","handleSelectSuggestion","updatedValue","nonSettingsChanges","Object","keys","reduce","acc","key","includes","title","handleSubmit","currentUrlInputValue","handleSubmitWithEnter","event","keyCode","currentInputIsEmpty","preventDefault","resetInternalValues","handleCancel","stopPropagation","shownUnlinkControl","showSettings","showActions","showTextControl","isEditing","isDisabled"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,MAAT,EAAiBC,OAAjB,EAA0BC,MAA1B,EAAkCC,WAAlC,QAAqD,uBAArD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,EAAiBC,QAAjB,EAA2BC,SAA3B,QAA4C,oBAA5C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AQ,EAAG5B,QAFZ;AAGC,IAAA,QAAQ,EAAGgC,oCAAoC,CAC9CT,YAD8C;AAHhD,IAJD,CAFF,CA3EF,EA6FGkD,WAAW,IACZ;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,OAAO,EAAGG,UAAU,GAAGhF,IAAH,GAAUiE,YAF/B;AAGC,IAAA,SAAS,EAAC,0CAHX;AAIC,qBAAgBe;AAJjB,KAMG/F,EAAE,CAAE,MAAF,CANL,CADD,EASC,cAAC,MAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGwF;AAArC,KACGxF,EAAE,CAAE,QAAF,CADL,CATD,CA9FF,EA6GGoC,mBAAmB,IAAIA,mBAAmB,EA7G7C,CADD;AAiHA;;AAEDpB,WAAW,CAACH,UAAZ,GAAyBA,UAAzB;AAEA,eAAeG,WAAf","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={ onRemove }\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"]}
|
|
@@ -45,7 +45,7 @@ const LinkControlSearchInput = forwardRef(({
|
|
|
45
45
|
suggestionsQuery = {},
|
|
46
46
|
withURLSuggestion = true,
|
|
47
47
|
createSuggestionButtonText,
|
|
48
|
-
|
|
48
|
+
hideLabelFromVision = false
|
|
49
49
|
}, ref) => {
|
|
50
50
|
const genericSearchHandler = useSearchHandler(suggestionsQuery, allowDirectEntry, withCreateSuggestion, withURLSuggestion);
|
|
51
51
|
const searchHandler = showSuggestions ? fetchSuggestions || genericSearchHandler : noopSearchHandler;
|
|
@@ -107,15 +107,15 @@ const LinkControlSearchInput = forwardRef(({
|
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
const inputClasses = classnames(className, {
|
|
111
|
-
'has-no-label': !useLabel
|
|
110
|
+
const inputClasses = classnames(className, {// 'has-no-label': ! hideLabelFromVision,
|
|
112
111
|
});
|
|
113
112
|
return createElement("div", {
|
|
114
113
|
className: "block-editor-link-control__search-input-container"
|
|
115
114
|
}, createElement(URLInput, {
|
|
116
115
|
disableSuggestions: currentLink?.url === value,
|
|
117
116
|
__nextHasNoMarginBottom: true,
|
|
118
|
-
label:
|
|
117
|
+
label: __('Link'),
|
|
118
|
+
hideLabelFromVision: hideLabelFromVision,
|
|
119
119
|
className: inputClasses,
|
|
120
120
|
value: value,
|
|
121
121
|
onChange: onInputChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/search-input.js"],"names":["classnames","useInstanceId","forwardRef","useState","__","URLInput","LinkControlSearchResults","CREATE_TYPE","useSearchHandler","noopSearchHandler","Promise","resolve","noop","LinkControlSearchInput","value","children","currentLink","className","placeholder","withCreateSuggestion","onCreateSuggestion","onChange","onSelect","showSuggestions","renderSuggestions","props","fetchSuggestions","allowDirectEntry","showInitialSuggestions","suggestionsQuery","withURLSuggestion","createSuggestionButtonText","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/link-control/search-input.js"],"names":["classnames","useInstanceId","forwardRef","useState","__","URLInput","LinkControlSearchResults","CREATE_TYPE","useSearchHandler","noopSearchHandler","Promise","resolve","noop","LinkControlSearchInput","value","children","currentLink","className","placeholder","withCreateSuggestion","onCreateSuggestion","onChange","onSelect","showSuggestions","renderSuggestions","props","fetchSuggestions","allowDirectEntry","showInitialSuggestions","suggestionsQuery","withURLSuggestion","createSuggestionButtonText","hideLabelFromVision","ref","genericSearchHandler","searchHandler","instanceId","focusedSuggestion","setFocusedSuggestion","onInputChange","selection","suggestion","handleRenderSuggestions","handleSuggestionClick","onSuggestionSelected","selectedSuggestion","type","title","url","e","Object","keys","length","id","restLinkProps","inputClasses","event","hasSuggestion","trim","preventDefault"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,oBAA9B;AACA,SAASC,UAAT,EAAqBC,QAArB,QAAqC,oBAArC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,QAAyB,KAAzB;AACA,OAAOC,wBAAP,MAAqC,kBAArC;AACA,SAASC,WAAT,QAA4B,aAA5B;AACA,OAAOC,gBAAP,MAA6B,sBAA7B,C,CAEA;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAG,MAAMC,OAAO,CAACC,OAAR,CAAiB,EAAjB,CAAhC;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAEA,MAAMC,sBAAsB,GAAGX,UAAU,CACxC,CACC;AACCY,EAAAA,KADD;AAECC,EAAAA,QAFD;AAGCC,EAAAA,WAAW,GAAG,EAHf;AAICC,EAAAA,SAAS,GAAG,IAJb;AAKCC,EAAAA,WAAW,GAAG,IALf;AAMCC,EAAAA,oBAAoB,GAAG,KANxB;AAOCC,EAAAA,kBAAkB,GAAGR,IAPtB;AAQCS,EAAAA,QAAQ,GAAGT,IARZ;AASCU,EAAAA,QAAQ,GAAGV,IATZ;AAUCW,EAAAA,eAAe,GAAG,IAVnB;AAWCC,EAAAA,iBAAiB,GAAKC,KAAF,IACnB,cAAC,wBAAD,OAA+BA;AAA/B,IAZF;AAcCC,EAAAA,gBAAgB,GAAG,IAdpB;AAeCC,EAAAA,gBAAgB,GAAG,IAfpB;AAgBCC,EAAAA,sBAAsB,GAAG,KAhB1B;AAiBCC,EAAAA,gBAAgB,GAAG,EAjBpB;AAkBCC,EAAAA,iBAAiB,GAAG,IAlBrB;AAmBCC,EAAAA,0BAnBD;A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IAAIJ,iBAApC,CADmC,CAGnC;AACA;;AACA,UAAK,CAAEoB,aAAF,IAAmB,CAAE3C,KAAK,EAAE4C,IAAP,IAAeN,MAAzC,EAAkD;AACjDI,QAAAA,KAAK,CAACG,cAAN;AACA,OAFD,MAEO;AACNf,QAAAA,oBAAoB,CACnBa,aAAa,IAAI;AAAET,UAAAA,GAAG,EAAElC;AAAP,SADE,CAApB;AAGA;AACD,KA7BF;AA8BC,IAAA,GAAG,EAAGmB;AA9BP,IADD,EAiCGlB,QAjCH,CADD;AAqCA,CAxIuC,CAAzC;AA2IA,eAAeF,sBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { forwardRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { URLInput } from '../';\nimport LinkControlSearchResults from './search-results';\nimport { CREATE_TYPE } from './constants';\nimport useSearchHandler from './use-search-handler';\n\n// Must be a function as otherwise URLInput will default\n// to the fetchLinkSuggestions passed in block editor settings\n// which will cause an unintended http request.\nconst noopSearchHandler = () => Promise.resolve( [] );\n\nconst noop = () => {};\n\nconst LinkControlSearchInput = forwardRef(\n\t(\n\t\t{\n\t\t\tvalue,\n\t\t\tchildren,\n\t\t\tcurrentLink = {},\n\t\t\tclassName = null,\n\t\t\tplaceholder = null,\n\t\t\twithCreateSuggestion = false,\n\t\t\tonCreateSuggestion = noop,\n\t\t\tonChange = noop,\n\t\t\tonSelect = noop,\n\t\t\tshowSuggestions = true,\n\t\t\trenderSuggestions = ( props ) => (\n\t\t\t\t<LinkControlSearchResults { ...props } />\n\t\t\t),\n\t\t\tfetchSuggestions = null,\n\t\t\tallowDirectEntry = true,\n\t\t\tshowInitialSuggestions = false,\n\t\t\tsuggestionsQuery = {},\n\t\t\twithURLSuggestion = true,\n\t\t\tcreateSuggestionButtonText,\n\t\t\thideLabelFromVision = false,\n\t\t},\n\t\tref\n\t) => {\n\t\tconst genericSearchHandler = useSearchHandler(\n\t\t\tsuggestionsQuery,\n\t\t\tallowDirectEntry,\n\t\t\twithCreateSuggestion,\n\t\t\twithURLSuggestion\n\t\t);\n\n\t\tconst searchHandler = showSuggestions\n\t\t\t? fetchSuggestions || genericSearchHandler\n\t\t\t: noopSearchHandler;\n\n\t\tconst instanceId = useInstanceId( LinkControlSearchInput );\n\t\tconst [ focusedSuggestion, setFocusedSuggestion ] = useState();\n\n\t\t/**\n\t\t * Handles the user moving between different suggestions. Does not handle\n\t\t * choosing an individual item.\n\t\t *\n\t\t * @param {string} selection the url of the selected suggestion.\n\t\t * @param {Object} suggestion the suggestion object.\n\t\t */\n\t\tconst onInputChange = ( selection, suggestion ) => {\n\t\t\tonChange( selection );\n\t\t\tsetFocusedSuggestion( suggestion );\n\t\t};\n\n\t\tconst handleRenderSuggestions = ( props ) =>\n\t\t\trenderSuggestions( {\n\t\t\t\t...props,\n\t\t\t\tinstanceId,\n\t\t\t\twithCreateSuggestion,\n\t\t\t\tcreateSuggestionButtonText,\n\t\t\t\tsuggestionsQuery,\n\t\t\t\thandleSuggestionClick: ( suggestion ) => {\n\t\t\t\t\tif ( props.handleSuggestionClick ) {\n\t\t\t\t\t\tprops.handleSuggestionClick( suggestion );\n\t\t\t\t\t}\n\t\t\t\t\tonSuggestionSelected( suggestion );\n\t\t\t\t},\n\t\t\t} );\n\n\t\tconst onSuggestionSelected = async ( selectedSuggestion ) => {\n\t\t\tlet suggestion = selectedSuggestion;\n\t\t\tif ( CREATE_TYPE === selectedSuggestion.type ) {\n\t\t\t\t// Create a new page and call onSelect with the output from the onCreateSuggestion callback.\n\t\t\t\ttry {\n\t\t\t\t\tsuggestion = await onCreateSuggestion(\n\t\t\t\t\t\tselectedSuggestion.title\n\t\t\t\t\t);\n\t\t\t\t\tif ( suggestion?.url ) {\n\t\t\t\t\t\tonSelect( suggestion );\n\t\t\t\t\t}\n\t\t\t\t} catch ( e ) {}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tallowDirectEntry ||\n\t\t\t\t( suggestion && Object.keys( suggestion ).length >= 1 )\n\t\t\t) {\n\t\t\t\tconst { id, url, ...restLinkProps } = currentLink ?? {};\n\t\t\t\tonSelect(\n\t\t\t\t\t// Some direct entries don't have types or IDs, and we still need to clear the previous ones.\n\t\t\t\t\t{ ...restLinkProps, ...suggestion },\n\t\t\t\t\tsuggestion\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\n\t\tconst inputClasses = classnames( className, {\n\t\t\t// 'has-no-label': ! hideLabelFromVision,\n\t\t} );\n\n\t\treturn (\n\t\t\t<div className=\"block-editor-link-control__search-input-container\">\n\t\t\t\t<URLInput\n\t\t\t\t\tdisableSuggestions={ currentLink?.url === value }\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Link' ) }\n\t\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t\t\tclassName={ inputClasses }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\tonChange={ onInputChange }\n\t\t\t\t\tplaceholder={ placeholder ?? __( 'Search or type url' ) }\n\t\t\t\t\t__experimentalRenderSuggestions={\n\t\t\t\t\t\tshowSuggestions ? handleRenderSuggestions : null\n\t\t\t\t\t}\n\t\t\t\t\t__experimentalFetchLinkSuggestions={ searchHandler }\n\t\t\t\t\t__experimentalHandleURLSuggestions={ true }\n\t\t\t\t\t__experimentalShowInitialSuggestions={\n\t\t\t\t\t\tshowInitialSuggestions\n\t\t\t\t\t}\n\t\t\t\t\tonSubmit={ ( suggestion, event ) => {\n\t\t\t\t\t\tconst hasSuggestion = suggestion || focusedSuggestion;\n\n\t\t\t\t\t\t// If there is no suggestion and the value (ie: any manually entered URL) is empty\n\t\t\t\t\t\t// then don't allow submission otherwise we get empty links.\n\t\t\t\t\t\tif ( ! hasSuggestion && ! value?.trim()?.length ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tonSuggestionSelected(\n\t\t\t\t\t\t\t\thasSuggestion || { url: value }\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tref={ ref }\n\t\t\t\t/>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n);\n\nexport default LinkControlSearchInput;\n"]}
|
|
@@ -4,9 +4,9 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { Button, __unstableMotion as motion, __unstableAnimatePresence as AnimatePresence } from '@wordpress/components';
|
|
7
|
-
import {
|
|
7
|
+
import { chevronLeftSmall, chevronRightSmall } from '@wordpress/icons';
|
|
8
8
|
import { useReducedMotion, useInstanceId } from '@wordpress/compose';
|
|
9
|
-
import {
|
|
9
|
+
import { _x, isRTL } from '@wordpress/i18n';
|
|
10
10
|
import { Fragment } from '@wordpress/element';
|
|
11
11
|
|
|
12
12
|
function LinkSettingsDrawer({
|
|
@@ -23,10 +23,9 @@ function LinkSettingsDrawer({
|
|
|
23
23
|
className: "block-editor-link-control__drawer-toggle",
|
|
24
24
|
"aria-expanded": settingsOpen,
|
|
25
25
|
onClick: () => setSettingsOpen(!settingsOpen),
|
|
26
|
-
icon:
|
|
27
|
-
label: __('Link Settings'),
|
|
26
|
+
icon: isRTL() ? chevronLeftSmall : chevronRightSmall,
|
|
28
27
|
"aria-controls": settingsDrawerId
|
|
29
|
-
}), createElement(MaybeAnimatePresence, null, settingsOpen && createElement(MaybeMotionDiv, {
|
|
28
|
+
}, _x('Advanced', 'Additional link settings')), createElement(MaybeAnimatePresence, null, settingsOpen && createElement(MaybeMotionDiv, {
|
|
30
29
|
className: "block-editor-link-control__drawer",
|
|
31
30
|
hidden: !settingsOpen,
|
|
32
31
|
id: settingsDrawerId,
|