@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.
Files changed (102) hide show
  1. package/README.md +1 -0
  2. package/build/components/block-lock/toolbar.js +25 -6
  3. package/build/components/block-lock/toolbar.js.map +1 -1
  4. package/build/components/block-toolbar/index.js +8 -5
  5. package/build/components/block-toolbar/index.js.map +1 -1
  6. package/build/components/dimensions-tool/aspect-ratio-tool.js +99 -0
  7. package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
  8. package/build/components/dimensions-tool/index.js +207 -0
  9. package/build/components/dimensions-tool/index.js.map +1 -0
  10. package/build/components/dimensions-tool/scale-tool.js +111 -0
  11. package/build/components/dimensions-tool/scale-tool.js.map +1 -0
  12. package/build/components/dimensions-tool/width-height-tool.js +125 -0
  13. package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
  14. package/build/components/image-editor/aspect-ratio-dropdown.js +1 -1
  15. package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  16. package/build/components/image-editor/use-save-image.js +1 -2
  17. package/build/components/image-editor/use-save-image.js.map +1 -1
  18. package/build/components/image-size-control/index.js +6 -0
  19. package/build/components/image-size-control/index.js.map +1 -1
  20. package/build/components/link-control/index.js +17 -15
  21. package/build/components/link-control/index.js.map +1 -1
  22. package/build/components/link-control/search-input.js +4 -4
  23. package/build/components/link-control/search-input.js.map +1 -1
  24. package/build/components/link-control/settings-drawer.js +2 -3
  25. package/build/components/link-control/settings-drawer.js.map +1 -1
  26. package/build/components/provider/use-block-sync.js +21 -0
  27. package/build/components/provider/use-block-sync.js.map +1 -1
  28. package/build/components/resolution-tool/index.js +55 -0
  29. package/build/components/resolution-tool/index.js.map +1 -0
  30. package/build/components/url-input/index.js +4 -2
  31. package/build/components/url-input/index.js.map +1 -1
  32. package/build/private-apis.js +7 -1
  33. package/build/private-apis.js.map +1 -1
  34. package/build/store/defaults.js +1 -0
  35. package/build/store/defaults.js.map +1 -1
  36. package/build-module/components/block-lock/toolbar.js +25 -7
  37. package/build-module/components/block-lock/toolbar.js.map +1 -1
  38. package/build-module/components/block-toolbar/index.js +8 -5
  39. package/build-module/components/block-toolbar/index.js.map +1 -1
  40. package/build-module/components/dimensions-tool/aspect-ratio-tool.js +87 -0
  41. package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
  42. package/build-module/components/dimensions-tool/index.js +195 -0
  43. package/build-module/components/dimensions-tool/index.js.map +1 -0
  44. package/build-module/components/dimensions-tool/scale-tool.js +103 -0
  45. package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
  46. package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
  47. package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
  48. package/build-module/components/image-editor/aspect-ratio-dropdown.js +1 -1
  49. package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  50. package/build-module/components/image-editor/use-save-image.js +1 -2
  51. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  52. package/build-module/components/image-size-control/index.js +5 -0
  53. package/build-module/components/image-size-control/index.js.map +1 -1
  54. package/build-module/components/link-control/index.js +17 -15
  55. package/build-module/components/link-control/index.js.map +1 -1
  56. package/build-module/components/link-control/search-input.js +4 -4
  57. package/build-module/components/link-control/search-input.js.map +1 -1
  58. package/build-module/components/link-control/settings-drawer.js +4 -5
  59. package/build-module/components/link-control/settings-drawer.js.map +1 -1
  60. package/build-module/components/provider/use-block-sync.js +21 -0
  61. package/build-module/components/provider/use-block-sync.js.map +1 -1
  62. package/build-module/components/resolution-tool/index.js +45 -0
  63. package/build-module/components/resolution-tool/index.js.map +1 -0
  64. package/build-module/components/url-input/index.js +4 -2
  65. package/build-module/components/url-input/index.js.map +1 -1
  66. package/build-module/private-apis.js +5 -1
  67. package/build-module/private-apis.js.map +1 -1
  68. package/build-module/store/defaults.js +1 -0
  69. package/build-module/store/defaults.js.map +1 -1
  70. package/build-style/style-rtl.css +42 -46
  71. package/build-style/style.css +42 -46
  72. package/package.json +6 -5
  73. package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
  74. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
  75. package/src/components/block-lock/toolbar.js +34 -6
  76. package/src/components/block-toolbar/index.js +9 -6
  77. package/src/components/block-tools/style.scss +4 -0
  78. package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
  79. package/src/components/dimensions-tool/index.js +212 -0
  80. package/src/components/dimensions-tool/scale-tool.js +124 -0
  81. package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
  82. package/src/components/dimensions-tool/stories/index.js +54 -0
  83. package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
  84. package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
  85. package/src/components/dimensions-tool/test/index.js +641 -0
  86. package/src/components/dimensions-tool/width-height-tool.js +113 -0
  87. package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
  88. package/src/components/image-editor/use-save-image.js +0 -1
  89. package/src/components/image-size-control/index.js +6 -0
  90. package/src/components/link-control/index.js +32 -28
  91. package/src/components/link-control/search-input.js +4 -3
  92. package/src/components/link-control/settings-drawer.js +6 -5
  93. package/src/components/link-control/style.scss +33 -55
  94. package/src/components/link-control/test/index.js +129 -116
  95. package/src/components/media-replace-flow/test/index.js +1 -1
  96. package/src/components/provider/test/use-block-sync.js +21 -6
  97. package/src/components/provider/use-block-sync.js +19 -0
  98. package/src/components/resolution-tool/index.js +56 -0
  99. package/src/components/resolution-tool/stories/index.js +48 -0
  100. package/src/components/url-input/index.js +2 -0
  101. package/src/private-apis.js +4 -0
  102. package/src/store/defaults.js +1 -0
package/README.md CHANGED
@@ -711,6 +711,7 @@ _Properties_
711
711
  - _maxWidth_ `number`: Max width to constraint resizing
712
712
  - _allowedBlockTypes_ `boolean|Array`: Allowed block types
713
713
  - _hasFixedToolbar_ `boolean`: Whether or not the editor toolbar is fixed
714
+ - _distractionFree_ `boolean`: Whether or not the editor UI is distraction free
714
715
  - _focusMode_ `boolean`: Whether the focus mode is enabled or not
715
716
  - _styles_ `Array`: Editor Styles
716
717
  - _keepCaretInsideBlock_ `boolean`: Whether caret should move between blocks in edit mode
@@ -13,6 +13,8 @@ var _i18n = require("@wordpress/i18n");
13
13
 
14
14
  var _components = require("@wordpress/components");
15
15
 
16
+ var _dom = require("@wordpress/dom");
17
+
16
18
  var _icons = require("@wordpress/icons");
17
19
 
18
20
  var _modal = _interopRequireDefault(require("./modal"));
@@ -27,7 +29,8 @@ var _useBlockLock = _interopRequireDefault(require("./use-block-lock"));
27
29
  * Internal dependencies
28
30
  */
29
31
  function BlockLockToolbar({
30
- clientId
32
+ clientId,
33
+ wrapperRef
31
34
  }) {
32
35
  const {
33
36
  canEdit,
@@ -36,12 +39,27 @@ function BlockLockToolbar({
36
39
  canLock
37
40
  } = (0, _useBlockLock.default)(clientId);
38
41
  const [isModalOpen, toggleModal] = (0, _element.useReducer)(isActive => !isActive, false);
42
+ const lockButtonRef = (0, _element.useRef)(null);
43
+ const isFirstRender = (0, _element.useRef)(true);
44
+ const shouldHideBlockLockUI = !canLock || canEdit && canMove && canRemove; // Restore focus manually on the first focusable element in the toolbar
45
+ // when the block lock modal is closed and the block is not locked anymore.
46
+ // See https://github.com/WordPress/gutenberg/issues/51447
39
47
 
40
- if (!canLock) {
41
- return null;
42
- }
48
+ (0, _element.useEffect)(() => {
49
+ if (isFirstRender.current) {
50
+ isFirstRender.current = false;
51
+ return;
52
+ }
53
+
54
+ if (!isModalOpen && shouldHideBlockLockUI) {
55
+ _dom.focus.focusable.find(wrapperRef.current, {
56
+ sequential: false
57
+ }).find(element => element.tagName === 'BUTTON' && element !== lockButtonRef.current)?.focus();
58
+ } // wrapperRef is a reference object and should be stable
59
+
60
+ }, [isModalOpen, shouldHideBlockLockUI, wrapperRef]);
43
61
 
44
- if (canEdit && canMove && canRemove) {
62
+ if (shouldHideBlockLockUI) {
45
63
  return null;
46
64
  }
47
65
 
@@ -50,7 +68,8 @@ function BlockLockToolbar({
50
68
  }, (0, _element.createElement)(_components.ToolbarButton, {
51
69
  icon: _icons.lock,
52
70
  label: (0, _i18n.__)('Unlock'),
53
- onClick: toggleModal
71
+ onClick: toggleModal,
72
+ ref: lockButtonRef
54
73
  })), isModalOpen && (0, _element.createElement)(_modal.default, {
55
74
  clientId: clientId,
56
75
  onClose: toggleModal
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-lock/toolbar.js"],"names":["BlockLockToolbar","clientId","canEdit","canMove","canRemove","canLock","isModalOpen","toggleModal","isActive","lock"],"mappings":";;;;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;AAIe,SAASA,gBAAT,CAA2B;AAAEC,EAAAA;AAAF,CAA3B,EAA0C;AACxD,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA,OAAX;AAAoBC,IAAAA,SAApB;AAA+BC,IAAAA;AAA/B,MAA2C,2BAAcJ,QAAd,CAAjD;AAEA,QAAM,CAAEK,WAAF,EAAeC,WAAf,IAA+B,yBAClCC,QAAF,IAAgB,CAAEA,QADkB,EAEpC,KAFoC,CAArC;;AAKA,MAAK,CAAEH,OAAP,EAAiB;AAChB,WAAO,IAAP;AACA;;AAED,MAAKH,OAAO,IAAIC,OAAX,IAAsBC,SAA3B,EAAuC;AACtC,WAAO,IAAP;AACA;;AAED,SACC,qDACC,4BAAC,wBAAD;AAAc,IAAA,SAAS,EAAC;AAAxB,KACC,4BAAC,yBAAD;AACC,IAAA,IAAI,EAAGK,WADR;AAEC,IAAA,KAAK,EAAG,cAAI,QAAJ,CAFT;AAGC,IAAA,OAAO,EAAGF;AAHX,IADD,CADD,EAQGD,WAAW,IACZ,4BAAC,cAAD;AAAgB,IAAA,QAAQ,EAAGL,QAA3B;AAAsC,IAAA,OAAO,EAAGM;AAAhD,IATF,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { useReducer } from '@wordpress/element';\nimport { lock } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport BlockLockModal from './modal';\nimport useBlockLock from './use-block-lock';\n\nexport default function BlockLockToolbar( { clientId } ) {\n\tconst { canEdit, canMove, canRemove, canLock } = useBlockLock( clientId );\n\n\tconst [ isModalOpen, toggleModal ] = useReducer(\n\t\t( isActive ) => ! isActive,\n\t\tfalse\n\t);\n\n\tif ( ! canLock ) {\n\t\treturn null;\n\t}\n\n\tif ( canEdit && canMove && canRemove ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarGroup className=\"block-editor-block-lock-toolbar\">\n\t\t\t\t<ToolbarButton\n\t\t\t\t\ticon={ lock }\n\t\t\t\t\tlabel={ __( 'Unlock' ) }\n\t\t\t\t\tonClick={ toggleModal }\n\t\t\t\t/>\n\t\t\t</ToolbarGroup>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<BlockLockModal clientId={ clientId } onClose={ toggleModal } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-lock/toolbar.js"],"names":["BlockLockToolbar","clientId","wrapperRef","canEdit","canMove","canRemove","canLock","isModalOpen","toggleModal","isActive","lockButtonRef","isFirstRender","shouldHideBlockLockUI","current","focus","focusable","find","sequential","element","tagName","lock"],"mappings":";;;;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AAKA;;AACA;;AAbA;AACA;AACA;;AAOA;AACA;AACA;AAIe,SAASA,gBAAT,CAA2B;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAA3B,EAAsD;AACpE,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA,OAAX;AAAoBC,IAAAA,SAApB;AAA+BC,IAAAA;AAA/B,MAA2C,2BAAcL,QAAd,CAAjD;AAEA,QA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Button, ToolbarGroup } from '@wordpress/components';\nimport { focus } from '@wordpress/dom';\nimport { useReducer, useRef, useEffect } from '@wordpress/element';\nimport { lock } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport BlockLockModal from './modal';\nimport useBlockLock from './use-block-lock';\n\nexport default function BlockLockToolbar( { clientId, wrapperRef } ) {\n\tconst { canEdit, canMove, canRemove, canLock } = useBlockLock( clientId );\n\n\tconst [ isModalOpen, toggleModal ] = useReducer(\n\t\t( isActive ) => ! isActive,\n\t\tfalse\n\t);\n\n\tconst lockButtonRef = useRef( null );\n\tconst isFirstRender = useRef( true );\n\n\tconst shouldHideBlockLockUI =\n\t\t! canLock || ( canEdit && canMove && canRemove );\n\n\t// Restore focus manually on the first focusable element in the toolbar\n\t// when the block lock modal is closed and the block is not locked anymore.\n\t// See https://github.com/WordPress/gutenberg/issues/51447\n\tuseEffect( () => {\n\t\tif ( isFirstRender.current ) {\n\t\t\tisFirstRender.current = false;\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ! isModalOpen && shouldHideBlockLockUI ) {\n\t\t\tfocus.focusable\n\t\t\t\t.find( wrapperRef.current, {\n\t\t\t\t\tsequential: false,\n\t\t\t\t} )\n\t\t\t\t.find(\n\t\t\t\t\t( element ) =>\n\t\t\t\t\t\telement.tagName === 'BUTTON' &&\n\t\t\t\t\t\telement !== lockButtonRef.current\n\t\t\t\t)\n\t\t\t\t?.focus();\n\t\t}\n\t\t// wrapperRef is a reference object and should be stable\n\t}, [ isModalOpen, shouldHideBlockLockUI, wrapperRef ] );\n\n\tif ( shouldHideBlockLockUI ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<ToolbarGroup className=\"block-editor-block-lock-toolbar\">\n\t\t\t\t<ToolbarButton\n\t\t\t\t\ticon={ lock }\n\t\t\t\t\tlabel={ __( 'Unlock' ) }\n\t\t\t\t\tonClick={ toggleModal }\n\t\t\t\t\tref={ lockButtonRef }\n\t\t\t\t/>\n\t\t\t</ToolbarGroup>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<BlockLockModal clientId={ clientId } onClose={ toggleModal } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
@@ -93,7 +93,8 @@ const BlockToolbar = ({
93
93
  isVisual: selectedBlockClientIds.every(id => getBlockMode(id) === 'visual'),
94
94
  blockEditingMode: getBlockEditingMode(selectedBlockClientId)
95
95
  };
96
- }, []); // Handles highlighting the current block outline on hover or focus of the
96
+ }, []);
97
+ const toolbarWrapperRef = (0, _element.useRef)(null); // Handles highlighting the current block outline on hover or focus of the
97
98
  // block type toolbar area.
98
99
 
99
100
  const {
@@ -140,16 +141,18 @@ const BlockToolbar = ({
140
141
  'is-synced': isSynced
141
142
  });
142
143
  return (0, _element.createElement)("div", {
143
- className: classes
144
- }, !isMultiToolbar && isLargeViewport && blockEditingMode === 'default' && (0, _element.createElement)(_blockParentSelector.default, null), (0, _element.createElement)("div", {
144
+ className: classes,
145
+ ref: toolbarWrapperRef
146
+ }, !isMultiToolbar && isLargeViewport && blockEditingMode === 'default' && (0, _element.createElement)(_blockParentSelector.default, null), (shouldShowVisualToolbar || isMultiToolbar) && blockEditingMode === 'default' && (0, _element.createElement)("div", {
145
147
  ref: nodeRef,
146
148
  ...showMoversGestures
147
- }, (shouldShowVisualToolbar || isMultiToolbar) && blockEditingMode === 'default' && (0, _element.createElement)(_components.ToolbarGroup, {
149
+ }, (0, _element.createElement)(_components.ToolbarGroup, {
148
150
  className: "block-editor-block-toolbar__block-controls"
149
151
  }, (0, _element.createElement)(_blockSwitcher.default, {
150
152
  clientIds: blockClientIds
151
153
  }), !isMultiToolbar && (0, _element.createElement)(_blockLock.BlockLockToolbar, {
152
- clientId: blockClientIds[0]
154
+ clientId: blockClientIds[0],
155
+ wrapperRef: toolbarWrapperRef
153
156
  }), (0, _element.createElement)(_blockMover.default, {
154
157
  clientIds: blockClientIds,
155
158
  hideDragHandle: hideDragHandle
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-toolbar/index.js"],"names":["BlockToolbar","hideDragHandle","blockClientIds","blockClientId","blockType","hasFixedToolbar","isDistractionFree","isValid","isVisual","blockEditingMode","select","getBlockName","getBlockMode","getSelectedBlockClientIds","isBlockValid","getBlockRootClientId","getSettings","getBlockEditingMode","blockEditorStore","selectedBlockClientIds","selectedBlockClientId","blockRootClientId","settings","rootClientId","every","id","toggleBlockHighlight","nodeRef","showMovers","gestures","showMoversGestures","ref","onChange","isFocused","displayHeaderToolbar","isLargeViewport","shouldShowMovers","length","shouldShowVisualToolbar","isMultiToolbar","isSynced","classes","name"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AAMA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAlCA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AAeA,MAAMA,YAAY,GAAG,CAAE;AAAEC,EAAAA;AAAF,CAAF,KAA0B;AAC9C,QAAM;AACLC,IAAAA,cADK;AAELC,IAAAA,aAFK;AAGLC,IAAAA,SAHK;AAILC,IAAAA,eAJK;AAKLC,IAAAA,iBALK;AAMLC,IAAAA,OANK;AAOLC,IAAAA,QAPK;AAQLC,IAAAA;AARK,MASF,qBAAaC,MAAF,IAAc;AAC5B,UAAM;AACLC,MAAAA,YADK;AAELC,MAAAA,YAFK;AAGLC,MAAAA,yBAHK;AAILC,MAAAA,YAJK;AAKLC,MAAAA,oBALK;AAMLC,MAAAA,WANK;AAOLC,MAAAA;AAPK,QAQF,wBAAQP,MAAM,CAAEQ,YAAF,CAAd,CARJ;AASA,UAAMC,sBAAsB,GAAGN,yBAAyB,EAAxD;AACA,UAAMO,qBAAqB,GAAGD,sBAAsB,CAAE,CAAF,CAApD;AACA,UAAME,iBAAiB,GAAGN,oBAAoB,CAAEK,qBAAF,CAA9C;AACA,UAAME,QAAQ,GAAGN,WAAW,EAA5B;AAEA,WAAO;AAC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AAC;AAFX,IADD,EAKC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,OADP;AAEC,IAAA,SAAS,EAAC;AAFX,IALD,EASC,4BAAC,sBAAD,CAAe,IAAf;AAAoB,IAAA,SAAS,EAAC;AAA9B,IATD,EAUC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,QADP;AAEC,IAAA,SAAS,EAAC;AAFX,IAVD,EAcC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,OADP;AAEC,IAAA,SAAS,EAAC;AAFX,IAdD,EAkBC,4BAAC,yBAAD,CAA4B,QAA5B;AACC,IAAA,KAAK,EAAGlC,SAAS,EAAEsC;AADpB,KAGC,4BAAC,6BAAD,CAAgC,IAAhC,OAHD,CAlBD,CAzBF,EAkDC,4BAAC,gCAAD;AAAyB,IAAA,SAAS,EAAGxC;AAArC,IAlDD,EAmDGO,gBAAgB,KAAK,SAArB,IACD,4BAAC,0BAAD;AAAmB,IAAA,SAAS,EAAGP;AAA/B,IApDF,CADD;AAyDA,CAjJD;AAmJA;AACA;AACA;;;eACeF,Y","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tgetBlockType,\n\thasBlockSupport,\n\tisReusableBlock,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { ToolbarGroup } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport BlockMover from '../block-mover';\nimport BlockParentSelector from '../block-parent-selector';\nimport BlockSwitcher from '../block-switcher';\nimport BlockControls from '../block-controls';\nimport __unstableBlockToolbarLastItem from './block-toolbar-last-item';\nimport BlockSettingsMenu from '../block-settings-menu';\nimport { BlockLockToolbar } from '../block-lock';\nimport { BlockGroupToolbar } from '../convert-to-group-buttons';\nimport BlockEditVisuallyButton from '../block-edit-visually-button';\nimport { useShowMoversGestures } from './utils';\nimport { store as blockEditorStore } from '../../store';\nimport __unstableBlockNameContext from './block-name-context';\nimport { unlock } from '../../lock-unlock';\n\nconst BlockToolbar = ( { hideDragHandle } ) => {\n\tconst {\n\t\tblockClientIds,\n\t\tblockClientId,\n\t\tblockType,\n\t\thasFixedToolbar,\n\t\tisDistractionFree,\n\t\tisValid,\n\t\tisVisual,\n\t\tblockEditingMode,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockName,\n\t\t\tgetBlockMode,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tisBlockValid,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetSettings,\n\t\t\tgetBlockEditingMode,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\tconst selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\tconst blockRootClientId = getBlockRootClientId( selectedBlockClientId );\n\t\tconst settings = getSettings();\n\n\t\treturn {\n\t\t\tblockClientIds: selectedBlockClientIds,\n\t\t\tblockClientId: selectedBlockClientId,\n\t\t\tblockType:\n\t\t\t\tselectedBlockClientId &&\n\t\t\t\tgetBlockType( getBlockName( selectedBlockClientId ) ),\n\t\t\thasFixedToolbar: settings.hasFixedToolbar,\n\t\t\tisDistractionFree: settings.isDistractionFree,\n\t\t\trootClientId: blockRootClientId,\n\t\t\tisValid: selectedBlockClientIds.every( ( id ) =>\n\t\t\t\tisBlockValid( id )\n\t\t\t),\n\t\t\tisVisual: selectedBlockClientIds.every(\n\t\t\t\t( id ) => getBlockMode( id ) === 'visual'\n\t\t\t),\n\t\t\tblockEditingMode: getBlockEditingMode( selectedBlockClientId ),\n\t\t};\n\t}, [] );\n\n\t// Handles highlighting the current block outline on hover or focus of the\n\t// block type toolbar area.\n\tconst { toggleBlockHighlight } = useDispatch( blockEditorStore );\n\tconst nodeRef = useRef();\n\tconst { showMovers, gestures: showMoversGestures } = useShowMoversGestures(\n\t\t{\n\t\t\tref: nodeRef,\n\t\t\tonChange( isFocused ) {\n\t\t\t\tif ( isFocused && isDistractionFree ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttoggleBlockHighlight( blockClientId, isFocused );\n\t\t\t},\n\t\t}\n\t);\n\n\t// Account for the cases where the block toolbar is rendered within the\n\t// header area and not contextually to the block.\n\tconst displayHeaderToolbar =\n\t\tuseViewportMatch( 'medium', '<' ) || hasFixedToolbar;\n\tconst isLargeViewport = ! useViewportMatch( 'medium', '<' );\n\n\tif ( blockType ) {\n\t\tif ( ! hasBlockSupport( blockType, '__experimentalToolbar', true ) ) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst shouldShowMovers = displayHeaderToolbar || showMovers;\n\n\tif ( blockClientIds.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst shouldShowVisualToolbar = isValid && isVisual;\n\tconst isMultiToolbar = blockClientIds.length > 1;\n\tconst isSynced =\n\t\tisReusableBlock( blockType ) || isTemplatePart( blockType );\n\n\tconst classes = classnames( 'block-editor-block-toolbar', {\n\t\t'is-showing-movers': shouldShowMovers,\n\t\t'is-synced': isSynced,\n\t} );\n\n\treturn (\n\t\t<div className={ classes }>\n\t\t\t{ ! isMultiToolbar &&\n\t\t\t\tisLargeViewport &&\n\t\t\t\tblockEditingMode === 'default' && <BlockParentSelector /> }\n\t\t\t<div ref={ nodeRef } { ...showMoversGestures }>\n\t\t\t\t{ ( shouldShowVisualToolbar || isMultiToolbar ) &&\n\t\t\t\t\tblockEditingMode === 'default' && (\n\t\t\t\t\t\t<ToolbarGroup className=\"block-editor-block-toolbar__block-controls\">\n\t\t\t\t\t\t\t<BlockSwitcher clientIds={ blockClientIds } />\n\t\t\t\t\t\t\t{ ! isMultiToolbar && (\n\t\t\t\t\t\t\t\t<BlockLockToolbar\n\t\t\t\t\t\t\t\t\tclientId={ blockClientIds[ 0 ] }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t<BlockMover\n\t\t\t\t\t\t\t\tclientIds={ blockClientIds }\n\t\t\t\t\t\t\t\thideDragHandle={ hideDragHandle }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ shouldShowVisualToolbar && isMultiToolbar && (\n\t\t\t\t<BlockGroupToolbar />\n\t\t\t) }\n\t\t\t{ shouldShowVisualToolbar && (\n\t\t\t\t<>\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"parent\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"block\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<BlockControls.Slot className=\"block-editor-block-toolbar__slot\" />\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"inline\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"other\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<__unstableBlockNameContext.Provider\n\t\t\t\t\t\tvalue={ blockType?.name }\n\t\t\t\t\t>\n\t\t\t\t\t\t<__unstableBlockToolbarLastItem.Slot />\n\t\t\t\t\t</__unstableBlockNameContext.Provider>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<BlockEditVisuallyButton clientIds={ blockClientIds } />\n\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t<BlockSettingsMenu clientIds={ blockClientIds } />\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-toolbar/README.md\n */\nexport default BlockToolbar;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-toolbar/index.js"],"names":["BlockToolbar","hideDragHandle","blockClientIds","blockClientId","blockType","hasFixedToolbar","isDistractionFree","isValid","isVisual","blockEditingMode","select","getBlockName","getBlockMode","getSelectedBlockClientIds","isBlockValid","getBlockRootClientId","getSettings","getBlockEditingMode","blockEditorStore","selectedBlockClientIds","selectedBlockClientId","blockRootClientId","settings","rootClientId","every","id","toolbarWrapperRef","toggleBlockHighlight","nodeRef","showMovers","gestures","showMoversGestures","ref","onChange","isFocused","displayHeaderToolbar","isLargeViewport","shouldShowMovers","length","shouldShowVisualToolbar","isMultiToolbar","isSynced","classes","name"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AAMA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAlCA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AAeA,MAAMA,YAAY,GAAG,CAAE;AAAEC,EAAAA;AAAF,CAAF,KAA0B;AAC9C,QAAM;AACLC,IAAAA,cADK;AAELC,IAAAA,aAFK;AAGLC,IAAAA,SAHK;AAILC,IAAAA,eAJK;AAKLC,IAAAA,iBALK;AAMLC,IAAAA,OANK;AAOLC,IAAAA,QAPK;AAQLC,IAAAA;AARK,MASF,qBAAaC,MAAF,IAAc;AAC5B,UAAM;AACLC,MAAAA,YADK;AAELC,MAAAA,YAFK;AAGLC,MAAAA,yBAHK;AAILC,MAAAA,YAJK;AAKLC,MAAAA,oBALK;AAMLC,MAAAA,WANK;AAOLC,MAAAA;AAPK,QAQF,wBAAQP,MAAM,CAAEQ,YAAF,CAAd,CARJ;AASA,UAAMC,sBAAsB,GAAGN,yBAAyB,EAAxD;AACA,UAAMO,qBAAqB,GAAGD,sBAAsB,CAAE,CAAF,CAApD;AACA,UAAME,iBAAiB,GAAGN,oBAAoB,CAAEK,qBAAF,CA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ARD,CADD,CANH,EAsBGsC,uBAAuB,IAAIC,cAA3B,IACD,4BAAC,wCAAD,OAvBF,EAyBGD,uBAAuB,IACxB,qDACC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,QADP;AAEC,IAAA,SAAS,EAAC;AAFX,IADD,EAKC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,OADP;AAEC,IAAA,SAAS,EAAC;AAFX,IALD,EASC,4BAAC,sBAAD,CAAe,IAAf;AAAoB,IAAA,SAAS,EAAC;AAA9B,IATD,EAUC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,QADP;AAEC,IAAA,SAAS,EAAC;AAFX,IAVD,EAcC,4BAAC,sBAAD,CAAe,IAAf;AACC,IAAA,KAAK,EAAC,OADP;AAEC,IAAA,SAAS,EAAC;AAFX,IAdD,EAkBC,4BAAC,yBAAD,CAA4B,QAA5B;AACC,IAAA,KAAK,EAAGnC,SAAS,EAAEuC;AADpB,KAGC,4BAAC,6BAAD,CAAgC,IAAhC,OAHD,CAlBD,CA1BF,EAmDC,4BAAC,gCAAD;AAAyB,IAAA,SAAS,EAAGzC;AAArC,IAnDD,EAoDGO,gBAAgB,KAAK,SAArB,IACD,4BAAC,0BAAD;AAAmB,IAAA,SAAS,EAAGP;AAA/B,IArDF,CADD;AA0DA,CApJD;AAsJA;AACA;AACA;;;eACeF,Y","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tgetBlockType,\n\thasBlockSupport,\n\tisReusableBlock,\n\tisTemplatePart,\n} from '@wordpress/blocks';\nimport { ToolbarGroup } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport BlockMover from '../block-mover';\nimport BlockParentSelector from '../block-parent-selector';\nimport BlockSwitcher from '../block-switcher';\nimport BlockControls from '../block-controls';\nimport __unstableBlockToolbarLastItem from './block-toolbar-last-item';\nimport BlockSettingsMenu from '../block-settings-menu';\nimport { BlockLockToolbar } from '../block-lock';\nimport { BlockGroupToolbar } from '../convert-to-group-buttons';\nimport BlockEditVisuallyButton from '../block-edit-visually-button';\nimport { useShowMoversGestures } from './utils';\nimport { store as blockEditorStore } from '../../store';\nimport __unstableBlockNameContext from './block-name-context';\nimport { unlock } from '../../lock-unlock';\n\nconst BlockToolbar = ( { hideDragHandle } ) => {\n\tconst {\n\t\tblockClientIds,\n\t\tblockClientId,\n\t\tblockType,\n\t\thasFixedToolbar,\n\t\tisDistractionFree,\n\t\tisValid,\n\t\tisVisual,\n\t\tblockEditingMode,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetBlockName,\n\t\t\tgetBlockMode,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\tisBlockValid,\n\t\t\tgetBlockRootClientId,\n\t\t\tgetSettings,\n\t\t\tgetBlockEditingMode,\n\t\t} = unlock( select( blockEditorStore ) );\n\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\tconst selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\tconst blockRootClientId = getBlockRootClientId( selectedBlockClientId );\n\t\tconst settings = getSettings();\n\n\t\treturn {\n\t\t\tblockClientIds: selectedBlockClientIds,\n\t\t\tblockClientId: selectedBlockClientId,\n\t\t\tblockType:\n\t\t\t\tselectedBlockClientId &&\n\t\t\t\tgetBlockType( getBlockName( selectedBlockClientId ) ),\n\t\t\thasFixedToolbar: settings.hasFixedToolbar,\n\t\t\tisDistractionFree: settings.isDistractionFree,\n\t\t\trootClientId: blockRootClientId,\n\t\t\tisValid: selectedBlockClientIds.every( ( id ) =>\n\t\t\t\tisBlockValid( id )\n\t\t\t),\n\t\t\tisVisual: selectedBlockClientIds.every(\n\t\t\t\t( id ) => getBlockMode( id ) === 'visual'\n\t\t\t),\n\t\t\tblockEditingMode: getBlockEditingMode( selectedBlockClientId ),\n\t\t};\n\t}, [] );\n\n\tconst toolbarWrapperRef = useRef( null );\n\n\t// Handles highlighting the current block outline on hover or focus of the\n\t// block type toolbar area.\n\tconst { toggleBlockHighlight } = useDispatch( blockEditorStore );\n\tconst nodeRef = useRef();\n\tconst { showMovers, gestures: showMoversGestures } = useShowMoversGestures(\n\t\t{\n\t\t\tref: nodeRef,\n\t\t\tonChange( isFocused ) {\n\t\t\t\tif ( isFocused && isDistractionFree ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\ttoggleBlockHighlight( blockClientId, isFocused );\n\t\t\t},\n\t\t}\n\t);\n\n\t// Account for the cases where the block toolbar is rendered within the\n\t// header area and not contextually to the block.\n\tconst displayHeaderToolbar =\n\t\tuseViewportMatch( 'medium', '<' ) || hasFixedToolbar;\n\tconst isLargeViewport = ! useViewportMatch( 'medium', '<' );\n\n\tif ( blockType ) {\n\t\tif ( ! hasBlockSupport( blockType, '__experimentalToolbar', true ) ) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst shouldShowMovers = displayHeaderToolbar || showMovers;\n\n\tif ( blockClientIds.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst shouldShowVisualToolbar = isValid && isVisual;\n\tconst isMultiToolbar = blockClientIds.length > 1;\n\tconst isSynced =\n\t\tisReusableBlock( blockType ) || isTemplatePart( blockType );\n\n\tconst classes = classnames( 'block-editor-block-toolbar', {\n\t\t'is-showing-movers': shouldShowMovers,\n\t\t'is-synced': isSynced,\n\t} );\n\n\treturn (\n\t\t<div className={ classes } ref={ toolbarWrapperRef }>\n\t\t\t{ ! isMultiToolbar &&\n\t\t\t\tisLargeViewport &&\n\t\t\t\tblockEditingMode === 'default' && <BlockParentSelector /> }\n\t\t\t{ ( shouldShowVisualToolbar || isMultiToolbar ) &&\n\t\t\t\tblockEditingMode === 'default' && (\n\t\t\t\t\t<div ref={ nodeRef } { ...showMoversGestures }>\n\t\t\t\t\t\t<ToolbarGroup className=\"block-editor-block-toolbar__block-controls\">\n\t\t\t\t\t\t\t<BlockSwitcher clientIds={ blockClientIds } />\n\t\t\t\t\t\t\t{ ! isMultiToolbar && (\n\t\t\t\t\t\t\t\t<BlockLockToolbar\n\t\t\t\t\t\t\t\t\tclientId={ blockClientIds[ 0 ] }\n\t\t\t\t\t\t\t\t\twrapperRef={ toolbarWrapperRef }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t<BlockMover\n\t\t\t\t\t\t\t\tclientIds={ blockClientIds }\n\t\t\t\t\t\t\t\thideDragHandle={ hideDragHandle }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolbarGroup>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t{ shouldShowVisualToolbar && isMultiToolbar && (\n\t\t\t\t<BlockGroupToolbar />\n\t\t\t) }\n\t\t\t{ shouldShowVisualToolbar && (\n\t\t\t\t<>\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"parent\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"block\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<BlockControls.Slot className=\"block-editor-block-toolbar__slot\" />\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"inline\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<BlockControls.Slot\n\t\t\t\t\t\tgroup=\"other\"\n\t\t\t\t\t\tclassName=\"block-editor-block-toolbar__slot\"\n\t\t\t\t\t/>\n\t\t\t\t\t<__unstableBlockNameContext.Provider\n\t\t\t\t\t\tvalue={ blockType?.name }\n\t\t\t\t\t>\n\t\t\t\t\t\t<__unstableBlockToolbarLastItem.Slot />\n\t\t\t\t\t</__unstableBlockNameContext.Provider>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t<BlockEditVisuallyButton clientIds={ blockClientIds } />\n\t\t\t{ blockEditingMode === 'default' && (\n\t\t\t\t<BlockSettingsMenu clientIds={ blockClientIds } />\n\t\t\t) }\n\t\t</div>\n\t);\n};\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/block-toolbar/README.md\n */\nexport default BlockToolbar;\n"]}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DEFAULT_ASPECT_RATIO_OPTIONS = void 0;
7
+ exports.default = AspectRatioTool;
8
+
9
+ var _element = require("@wordpress/element");
10
+
11
+ var _components = require("@wordpress/components");
12
+
13
+ var _i18n = require("@wordpress/i18n");
14
+
15
+ /**
16
+ * WordPress dependencies
17
+ */
18
+
19
+ /**
20
+ * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps
21
+ */
22
+
23
+ /**
24
+ * @type {SelectControlProps[]}
25
+ */
26
+ const DEFAULT_ASPECT_RATIO_OPTIONS = [{
27
+ label: (0, _i18n._x)('Original', 'Aspect ratio option for dimensions control'),
28
+ value: 'auto'
29
+ }, {
30
+ label: (0, _i18n._x)('Square - 1:1', 'Aspect ratio option for dimensions control'),
31
+ value: '1'
32
+ }, {
33
+ label: (0, _i18n._x)('Standard - 4:3', 'Aspect ratio option for dimensions control'),
34
+ value: '4/3'
35
+ }, {
36
+ label: (0, _i18n._x)('Portrait - 3:4', 'Aspect ratio option for dimensions control'),
37
+ value: '3/4'
38
+ }, {
39
+ label: (0, _i18n._x)('Classic - 3:2', 'Aspect ratio option for dimensions control'),
40
+ value: '3/2'
41
+ }, {
42
+ label: (0, _i18n._x)('Classic Portrait - 2:3', 'Aspect ratio option for dimensions control'),
43
+ value: '2/3'
44
+ }, {
45
+ label: (0, _i18n._x)('Wide - 16:9', 'Aspect ratio option for dimensions control'),
46
+ value: '16/9'
47
+ }, {
48
+ label: (0, _i18n._x)('Tall - 9:16', 'Aspect ratio option for dimensions control'),
49
+ value: '9/16'
50
+ }, {
51
+ label: (0, _i18n._x)('Custom', 'Aspect ratio option for dimensions control'),
52
+ value: 'custom',
53
+ disabled: true,
54
+ hidden: true
55
+ }];
56
+ /**
57
+ * @callback AspectRatioToolPropsOnChange
58
+ * @param {string} [value] New aspect ratio value.
59
+ * @return {void} No return.
60
+ */
61
+
62
+ /**
63
+ * @typedef {Object} AspectRatioToolProps
64
+ * @property {string} [panelId] ID of the panel this tool is associated with.
65
+ * @property {string} [value] Current aspect ratio value.
66
+ * @property {AspectRatioToolPropsOnChange} [onChange] Callback to update the aspect ratio value.
67
+ * @property {SelectControlProps[]} [options] Aspect ratio options.
68
+ * @property {string} [defaultValue] Default aspect ratio value.
69
+ * @property {boolean} [isShownByDefault] Whether the tool is shown by default.
70
+ */
71
+
72
+ exports.DEFAULT_ASPECT_RATIO_OPTIONS = DEFAULT_ASPECT_RATIO_OPTIONS;
73
+
74
+ function AspectRatioTool({
75
+ panelId,
76
+ value,
77
+ onChange = () => {},
78
+ options = DEFAULT_ASPECT_RATIO_OPTIONS,
79
+ defaultValue = DEFAULT_ASPECT_RATIO_OPTIONS[0].value,
80
+ isShownByDefault = true
81
+ }) {
82
+ // Match the CSS default so if the value is used directly in CSS it will look correct in the control.
83
+ const displayValue = value !== null && value !== void 0 ? value : 'auto';
84
+ return (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
85
+ hasValue: () => displayValue !== defaultValue,
86
+ label: (0, _i18n.__)('Aspect ratio'),
87
+ onDeselect: () => onChange(undefined),
88
+ isShownByDefault: isShownByDefault,
89
+ panelId: panelId
90
+ }, (0, _element.createElement)(_components.SelectControl, {
91
+ label: (0, _i18n.__)('Aspect ratio'),
92
+ value: displayValue,
93
+ options: options,
94
+ onChange: onChange,
95
+ size: '__unstable-large',
96
+ __nextHasNoMarginBottom: true
97
+ }));
98
+ }
99
+ //# sourceMappingURL=aspect-ratio-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/dimensions-tool/aspect-ratio-tool.js"],"names":["DEFAULT_ASPECT_RATIO_OPTIONS","label","value","disabled","hidden","AspectRatioTool","panelId","onChange","options","defaultValue","isShownByDefault","displayValue","undefined"],"mappings":";;;;;;;;;;AAGA;;AAIA;;AAPA;AACA;AACA;;AAOA;AACA;AACA;;AAEA;AACA;AACA;AACO,MAAMA,4BAA4B,GAAG,CAC3C;AACCC,EAAAA,KAAK,EAAE,cAAI,UAAJ,EAAgB,4CAAhB,CADR;AAECC,EAAAA,KAAK,EAAE;AAFR,CAD2C,EAK3C;AACCD,EAAAA,KAAK,EAAE,cACN,cADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CAL2C,EAY3C;AACCD,EAAAA,KAAK,EAAE,cACN,gBADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CAZ2C,EAmB3C;AACCD,EAAAA,KAAK,EAAE,cACN,gBADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CAnB2C,EA0B3C;AACCD,EAAAA,KAAK,EAAE,cACN,eADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CA1B2C,EAiC3C;AACCD,EAAAA,KAAK,EAAE,cACN,wBADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CAjC2C,EAwC3C;AACCD,EAAAA,KAAK,EAAE,cACN,aADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CAxC2C,EA+C3C;AACCD,EAAAA,KAAK,EAAE,cACN,aADM,EAEN,4CAFM,CADR;AAKCC,EAAAA,KAAK,EAAE;AALR,CA/C2C,EAsD3C;AACCD,EAAAA,KAAK,EAAE,cAAI,QAAJ,EAAc,4CAAd,CADR;AAECC,EAAAA,KAAK,EAAE,QAFR;AAGCC,EAAAA,QAAQ,EAAE,IAHX;AAICC,EAAAA,MAAM,EAAE;AAJT,CAtD2C,CAArC;AA8DP;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AAEe,SAASC,eAAT,CAA0B;AACxCC,EAAAA,OADwC;AAExCJ,EAAAA,KAFwC;AAGxCK,EAAAA,QAAQ,GAAG,MAAM,CAAE,CAHqB;AAIxCC,EAAAA,OAAO,GAAGR,4BAJ8B;AAKxCS,EAAAA,YAAY,GAAGT,4BAA4B,CAAE,CAAF,CAA5B,CAAkCE,KALT;AAMxCQ,EAAAA,gBAAgB,GAAG;AANqB,CAA1B,EAOX;AACH;AACA,QAAMC,YAAY,GAAGT,KAAH,aAAGA,KAAH,cAAGA,KAAH,GAAY,MAA9B;AAEA,SACC,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAG,MAAMS,YAAY,KAAKF,YADnC;AAEC,IAAA,KAAK,EAAG,cAAI,cAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MAAMF,QAAQ,CAAEK,SAAF,CAH5B;AAIC,IAAA,gBAAgB,EAAGF,gBAJpB;AAKC,IAAA,OAAO,EAAGJ;AALX,KAOC,4BAAC,yBAAD;AACC,IAAA,KAAK,EAAG,cAAI,cAAJ,CADT;AAEC,IAAA,KAAK,EAAGK,YAFT;AAGC,IAAA,OAAO,EAAGH,OAHX;AAIC,IAAA,QAAQ,EAAGD,QAJZ;AAKC,IAAA,IAAI,EAAG,kBALR;AAMC,IAAA,uBAAuB;AANxB,IAPD,CADD;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tSelectControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\n\n/**\n * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps\n */\n\n/**\n * @type {SelectControlProps[]}\n */\nexport const DEFAULT_ASPECT_RATIO_OPTIONS = [\n\t{\n\t\tlabel: _x( 'Original', 'Aspect ratio option for dimensions control' ),\n\t\tvalue: 'auto',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Square - 1:1',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '1',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Standard - 4:3',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '4/3',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Portrait - 3:4',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '3/4',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Classic - 3:2',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '3/2',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Classic Portrait - 2:3',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '2/3',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Wide - 16:9',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '16/9',\n\t},\n\t{\n\t\tlabel: _x(\n\t\t\t'Tall - 9:16',\n\t\t\t'Aspect ratio option for dimensions control'\n\t\t),\n\t\tvalue: '9/16',\n\t},\n\t{\n\t\tlabel: _x( 'Custom', 'Aspect ratio option for dimensions control' ),\n\t\tvalue: 'custom',\n\t\tdisabled: true,\n\t\thidden: true,\n\t},\n];\n\n/**\n * @callback AspectRatioToolPropsOnChange\n * @param {string} [value] New aspect ratio value.\n * @return {void} No return.\n */\n\n/**\n * @typedef {Object} AspectRatioToolProps\n * @property {string} [panelId] ID of the panel this tool is associated with.\n * @property {string} [value] Current aspect ratio value.\n * @property {AspectRatioToolPropsOnChange} [onChange] Callback to update the aspect ratio value.\n * @property {SelectControlProps[]} [options] Aspect ratio options.\n * @property {string} [defaultValue] Default aspect ratio value.\n * @property {boolean} [isShownByDefault] Whether the tool is shown by default.\n */\n\nexport default function AspectRatioTool( {\n\tpanelId,\n\tvalue,\n\tonChange = () => {},\n\toptions = DEFAULT_ASPECT_RATIO_OPTIONS,\n\tdefaultValue = DEFAULT_ASPECT_RATIO_OPTIONS[ 0 ].value,\n\tisShownByDefault = true,\n} ) {\n\t// Match the CSS default so if the value is used directly in CSS it will look correct in the control.\n\tconst displayValue = value ?? 'auto';\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => displayValue !== defaultValue }\n\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\tonDeselect={ () => onChange( undefined ) }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Aspect ratio' ) }\n\t\t\t\tvalue={ displayValue }\n\t\t\t\toptions={ options }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t/>\n\t\t</ToolsPanelItem>\n\t);\n}\n"]}
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _aspectRatioTool = _interopRequireDefault(require("./aspect-ratio-tool"));
13
+
14
+ var _scaleTool = _interopRequireDefault(require("./scale-tool"));
15
+
16
+ var _widthHeightTool = _interopRequireDefault(require("./width-height-tool"));
17
+
18
+ /**
19
+ * WordPress dependencies
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+
26
+ /**
27
+ * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps
28
+ */
29
+
30
+ /**
31
+ * @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit
32
+ */
33
+
34
+ /**
35
+ * @typedef {Object} Dimensions
36
+ * @property {string} [width] CSS width property.
37
+ * @property {string} [height] CSS height property.
38
+ * @property {string} [scale] CSS object-fit property.
39
+ * @property {string} [aspectRatio] CSS aspect-ratio property.
40
+ */
41
+
42
+ /**
43
+ * @callback DimensionsControlsOnChange
44
+ * @param {Dimensions} nextValue
45
+ * @return {void}
46
+ */
47
+
48
+ /**
49
+ * @typedef {Object} DimensionsControlsProps
50
+ * @property {string} [panelId] ID of the panel that contains the controls.
51
+ * @property {Dimensions} [value] Current dimensions values.
52
+ * @property {DimensionsControlsOnChange} [onChange] Callback to update the dimensions values.
53
+ * @property {SelectControlProps[]} [aspectRatioOptions] Aspect ratio options.
54
+ * @property {SelectControlProps[]} [scaleOptions] Scale options.
55
+ * @property {WPUnitControlUnit[]} [unitsOptions] Units options.
56
+ */
57
+
58
+ /**
59
+ * Component that renders controls to edit the dimensions of an image or container.
60
+ *
61
+ * @param {DimensionsControlsProps} props The component props.
62
+ *
63
+ * @return {WPElement} The dimensions controls.
64
+ */
65
+ function DimensionsTool({
66
+ panelId,
67
+ value = {},
68
+ onChange = () => {},
69
+ aspectRatioOptions,
70
+ // Default options handled by AspectRatioTool.
71
+ defaultAspectRatio = 'auto',
72
+ // Match CSS default value for aspect-ratio.
73
+ scaleOptions,
74
+ // Default options handled by ScaleTool.
75
+ defaultScale = 'fill',
76
+ // Match CSS default value for object-fit.
77
+ unitsOptions // Default options handled by UnitControl.
78
+
79
+ }) {
80
+ // Coerce undefined and CSS default values to be null.
81
+ const width = value.width === undefined || value.width === 'auto' ? null : value.width;
82
+ const height = value.height === undefined || value.height === 'auto' ? null : value.height;
83
+ const aspectRatio = value.aspectRatio === undefined || value.aspectRatio === 'auto' ? null : value.aspectRatio;
84
+ const scale = value.scale === undefined || value.scale === 'fill' ? null : value.scale; // Keep track of state internally, so when the value is cleared by means
85
+ // other than directly editing that field, it's easier to restore the
86
+ // previous value.
87
+
88
+ const [lastScale, setLastScale] = (0, _element.useState)(scale);
89
+ const [lastAspectRatio, setLastAspectRatio] = (0, _element.useState)(aspectRatio); // 'custom' is not a valid value for CSS aspect-ratio, but it is used in the
90
+ // dropdown to indicate that setting both the width and height is the same
91
+ // as a custom aspect ratio.
92
+
93
+ const aspectRatioValue = width && height ? 'custom' : lastAspectRatio;
94
+ const showScaleControl = aspectRatio || width && height;
95
+ return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_aspectRatioTool.default, {
96
+ panelId: panelId,
97
+ options: aspectRatioOptions,
98
+ defaultValue: defaultAspectRatio,
99
+ value: aspectRatioValue,
100
+ onChange: nextAspectRatio => {
101
+ const nextValue = { ...value
102
+ }; // 'auto' is CSS default, so it gets treated as null.
103
+
104
+ nextAspectRatio = nextAspectRatio === 'auto' ? null : nextAspectRatio;
105
+ setLastAspectRatio(nextAspectRatio); // Update aspectRatio.
106
+
107
+ if (!nextAspectRatio) {
108
+ delete nextValue.aspectRatio;
109
+ } else {
110
+ nextValue.aspectRatio = nextAspectRatio;
111
+ } // Auto-update scale.
112
+
113
+
114
+ if (!nextAspectRatio) {
115
+ delete nextValue.scale;
116
+ } else if (lastScale) {
117
+ nextValue.scale = lastScale;
118
+ } else {
119
+ nextValue.scale = defaultScale;
120
+ setLastScale(defaultScale);
121
+ } // Auto-update width and height.
122
+
123
+
124
+ if (nextAspectRatio && width && height) {
125
+ delete nextValue.height;
126
+ }
127
+
128
+ onChange(nextValue);
129
+ }
130
+ }), showScaleControl && (0, _element.createElement)(_scaleTool.default, {
131
+ panelId: panelId,
132
+ options: scaleOptions,
133
+ defaultValue: defaultScale,
134
+ value: lastScale,
135
+ onChange: nextScale => {
136
+ const nextValue = { ...value
137
+ }; // 'fill' is CSS default, so it gets treated as null.
138
+
139
+ nextScale = nextScale === 'fill' ? null : nextScale;
140
+ setLastScale(nextScale); // Update scale.
141
+
142
+ if (!nextScale) {
143
+ delete nextValue.scale;
144
+ } else {
145
+ nextValue.scale = nextScale;
146
+ }
147
+
148
+ onChange(nextValue);
149
+ }
150
+ }), (0, _element.createElement)(_widthHeightTool.default, {
151
+ panelId: panelId,
152
+ units: unitsOptions,
153
+ value: {
154
+ width,
155
+ height
156
+ },
157
+ onChange: ({
158
+ width: nextWidth,
159
+ height: nextHeight
160
+ }) => {
161
+ const nextValue = { ...value
162
+ }; // 'auto' is CSS default, so it gets treated as null.
163
+
164
+ nextWidth = nextWidth === 'auto' ? null : nextWidth;
165
+ nextHeight = nextHeight === 'auto' ? null : nextHeight; // Update width.
166
+
167
+ if (!nextWidth) {
168
+ delete nextValue.width;
169
+ } else {
170
+ nextValue.width = nextWidth;
171
+ } // Update height.
172
+
173
+
174
+ if (!nextHeight) {
175
+ delete nextValue.height;
176
+ } else {
177
+ nextValue.height = nextHeight;
178
+ } // Auto-update aspectRatio.
179
+
180
+
181
+ if (nextWidth && nextHeight) {
182
+ delete nextValue.aspectRatio;
183
+ } else if (lastAspectRatio) {
184
+ nextValue.aspectRatio = lastAspectRatio;
185
+ } else {// No setting defaultAspectRatio here, because
186
+ // aspectRatio is optional in this scenario,
187
+ // unlike scale.
188
+ } // Auto-update scale.
189
+
190
+
191
+ if (!lastAspectRatio && !!nextWidth !== !!nextHeight) {
192
+ delete nextValue.scale;
193
+ } else if (lastScale) {
194
+ nextValue.scale = lastScale;
195
+ } else {
196
+ nextValue.scale = defaultScale;
197
+ setLastScale(defaultScale);
198
+ }
199
+
200
+ onChange(nextValue);
201
+ }
202
+ }));
203
+ }
204
+
205
+ var _default = DimensionsTool;
206
+ exports.default = _default;
207
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/dimensions-tool/index.js"],"names":["DimensionsTool","panelId","value","onChange","aspectRatioOptions","defaultAspectRatio","scaleOptions","defaultScale","unitsOptions","width","undefined","height","aspectRatio","scale","lastScale","setLastScale","lastAspectRatio","setLastAspectRatio","aspectRatioValue","showScaleControl","nextAspectRatio","nextValue","nextScale","nextWidth","nextHeight"],"mappings":";;;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AAS,CAACV,MAAjB;AACA,OAFD,MAEO;AACNU,QAAAA,SAAS,CAACV,MAAV,GAAmBa,UAAnB;AACA,OAnByD,CAqB1D;;;AACA,UAAKD,SAAS,IAAIC,UAAlB,EAA+B;AAC9B,eAAOH,SAAS,CAACT,WAAjB;AACA,OAFD,MAEO,IAAKI,eAAL,EAAuB;AAC7BK,QAAAA,SAAS,CAACT,WAAV,GAAwBI,eAAxB;AACA,OAFM,MAEA,CACN;AACA;AACA;AACA,OA9ByD,CAgC1D;;;AACA,UAAK,CAAEA,eAAF,IAAqB,CAAC,CAAEO,SAAH,KAAiB,CAAC,CAAEC,UAA9C,EAA2D;AAC1D,eAAOH,SAAS,CAACR,KAAjB;AACA,OAFD,MAEO,IAAKC,SAAL,EAAiB;AACvBO,QAAAA,SAAS,CAACR,KAAV,GAAkBC,SAAlB;AACA,OAFM,MAEA;AACNO,QAAAA,SAAS,CAACR,KAAV,GAAkBN,YAAlB;AACAQ,QAAAA,YAAY,CAAER,YAAF,CAAZ;AACA;;AAEDJ,MAAAA,QAAQ,CAAEkB,SAAF,CAAR;AACA;AA/CF,IAjED,CADD;AAqHA;;eAEcrB,c","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport AspectRatioTool from './aspect-ratio-tool';\nimport ScaleTool from './scale-tool';\nimport WidthHeightTool from './width-height-tool';\n\n/**\n * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps\n */\n\n/**\n * @typedef {import('@wordpress/components/build-types/unit-control/types').WPUnitControlUnit} WPUnitControlUnit\n */\n\n/**\n * @typedef {Object} Dimensions\n * @property {string} [width] CSS width property.\n * @property {string} [height] CSS height property.\n * @property {string} [scale] CSS object-fit property.\n * @property {string} [aspectRatio] CSS aspect-ratio property.\n */\n\n/**\n * @callback DimensionsControlsOnChange\n * @param {Dimensions} nextValue\n * @return {void}\n */\n\n/**\n * @typedef {Object} DimensionsControlsProps\n * @property {string} [panelId] ID of the panel that contains the controls.\n * @property {Dimensions} [value] Current dimensions values.\n * @property {DimensionsControlsOnChange} [onChange] Callback to update the dimensions values.\n * @property {SelectControlProps[]} [aspectRatioOptions] Aspect ratio options.\n * @property {SelectControlProps[]} [scaleOptions] Scale options.\n * @property {WPUnitControlUnit[]} [unitsOptions] Units options.\n */\n\n/**\n * Component that renders controls to edit the dimensions of an image or container.\n *\n * @param {DimensionsControlsProps} props The component props.\n *\n * @return {WPElement} The dimensions controls.\n */\nfunction DimensionsTool( {\n\tpanelId,\n\tvalue = {},\n\tonChange = () => {},\n\taspectRatioOptions, // Default options handled by AspectRatioTool.\n\tdefaultAspectRatio = 'auto', // Match CSS default value for aspect-ratio.\n\tscaleOptions, // Default options handled by ScaleTool.\n\tdefaultScale = 'fill', // Match CSS default value for object-fit.\n\tunitsOptions, // Default options handled by UnitControl.\n} ) {\n\t// Coerce undefined and CSS default values to be null.\n\tconst width =\n\t\tvalue.width === undefined || value.width === 'auto'\n\t\t\t? null\n\t\t\t: value.width;\n\tconst height =\n\t\tvalue.height === undefined || value.height === 'auto'\n\t\t\t? null\n\t\t\t: value.height;\n\tconst aspectRatio =\n\t\tvalue.aspectRatio === undefined || value.aspectRatio === 'auto'\n\t\t\t? null\n\t\t\t: value.aspectRatio;\n\tconst scale =\n\t\tvalue.scale === undefined || value.scale === 'fill'\n\t\t\t? null\n\t\t\t: value.scale;\n\n\t// Keep track of state internally, so when the value is cleared by means\n\t// other than directly editing that field, it's easier to restore the\n\t// previous value.\n\tconst [ lastScale, setLastScale ] = useState( scale );\n\tconst [ lastAspectRatio, setLastAspectRatio ] = useState( aspectRatio );\n\n\t// 'custom' is not a valid value for CSS aspect-ratio, but it is used in the\n\t// dropdown to indicate that setting both the width and height is the same\n\t// as a custom aspect ratio.\n\tconst aspectRatioValue = width && height ? 'custom' : lastAspectRatio;\n\n\tconst showScaleControl = aspectRatio || ( width && height );\n\n\treturn (\n\t\t<>\n\t\t\t<AspectRatioTool\n\t\t\t\tpanelId={ panelId }\n\t\t\t\toptions={ aspectRatioOptions }\n\t\t\t\tdefaultValue={ defaultAspectRatio }\n\t\t\t\tvalue={ aspectRatioValue }\n\t\t\t\tonChange={ ( nextAspectRatio ) => {\n\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t// 'auto' is CSS default, so it gets treated as null.\n\t\t\t\t\tnextAspectRatio =\n\t\t\t\t\t\tnextAspectRatio === 'auto' ? null : nextAspectRatio;\n\n\t\t\t\t\tsetLastAspectRatio( nextAspectRatio );\n\n\t\t\t\t\t// Update aspectRatio.\n\t\t\t\t\tif ( ! nextAspectRatio ) {\n\t\t\t\t\t\tdelete nextValue.aspectRatio;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextValue.aspectRatio = nextAspectRatio;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Auto-update scale.\n\t\t\t\t\tif ( ! nextAspectRatio ) {\n\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t} else if ( lastScale ) {\n\t\t\t\t\t\tnextValue.scale = lastScale;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextValue.scale = defaultScale;\n\t\t\t\t\t\tsetLastScale( defaultScale );\n\t\t\t\t\t}\n\n\t\t\t\t\t// Auto-update width and height.\n\t\t\t\t\tif ( nextAspectRatio && width && height ) {\n\t\t\t\t\t\tdelete nextValue.height;\n\t\t\t\t\t}\n\n\t\t\t\t\tonChange( nextValue );\n\t\t\t\t} }\n\t\t\t/>\n\t\t\t{ showScaleControl && (\n\t\t\t\t<ScaleTool\n\t\t\t\t\tpanelId={ panelId }\n\t\t\t\t\toptions={ scaleOptions }\n\t\t\t\t\tdefaultValue={ defaultScale }\n\t\t\t\t\tvalue={ lastScale }\n\t\t\t\t\tonChange={ ( nextScale ) => {\n\t\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t\t// 'fill' is CSS default, so it gets treated as null.\n\t\t\t\t\t\tnextScale = nextScale === 'fill' ? null : nextScale;\n\n\t\t\t\t\t\tsetLastScale( nextScale );\n\n\t\t\t\t\t\t// Update scale.\n\t\t\t\t\t\tif ( ! nextScale ) {\n\t\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnextValue.scale = nextScale;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tonChange( nextValue );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<WidthHeightTool\n\t\t\t\tpanelId={ panelId }\n\t\t\t\tunits={ unitsOptions }\n\t\t\t\tvalue={ { width, height } }\n\t\t\t\tonChange={ ( { width: nextWidth, height: nextHeight } ) => {\n\t\t\t\t\tconst nextValue = { ...value };\n\n\t\t\t\t\t// 'auto' is CSS default, so it gets treated as null.\n\t\t\t\t\tnextWidth = nextWidth === 'auto' ? null : nextWidth;\n\t\t\t\t\tnextHeight = nextHeight === 'auto' ? null : nextHeight;\n\n\t\t\t\t\t// Update width.\n\t\t\t\t\tif ( ! nextWidth ) {\n\t\t\t\t\t\tdelete nextValue.width;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextValue.width = nextWidth;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Update height.\n\t\t\t\t\tif ( ! nextHeight ) {\n\t\t\t\t\t\tdelete nextValue.height;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextValue.height = nextHeight;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Auto-update aspectRatio.\n\t\t\t\t\tif ( nextWidth && nextHeight ) {\n\t\t\t\t\t\tdelete nextValue.aspectRatio;\n\t\t\t\t\t} else if ( lastAspectRatio ) {\n\t\t\t\t\t\tnextValue.aspectRatio = lastAspectRatio;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// No setting defaultAspectRatio here, because\n\t\t\t\t\t\t// aspectRatio is optional in this scenario,\n\t\t\t\t\t\t// unlike scale.\n\t\t\t\t\t}\n\n\t\t\t\t\t// Auto-update scale.\n\t\t\t\t\tif ( ! lastAspectRatio && !! nextWidth !== !! nextHeight ) {\n\t\t\t\t\t\tdelete nextValue.scale;\n\t\t\t\t\t} else if ( lastScale ) {\n\t\t\t\t\t\tnextValue.scale = lastScale;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnextValue.scale = defaultScale;\n\t\t\t\t\t\tsetLastScale( defaultScale );\n\t\t\t\t\t}\n\n\t\t\t\t\tonChange( nextValue );\n\t\t\t\t} }\n\t\t\t/>\n\t\t</>\n\t);\n}\n\nexport default DimensionsTool;\n"]}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ScaleTool;
7
+
8
+ var _element = require("@wordpress/element");
9
+
10
+ var _components = require("@wordpress/components");
11
+
12
+ var _i18n = require("@wordpress/i18n");
13
+
14
+ /**
15
+ * WordPress dependencies
16
+ */
17
+
18
+ /**
19
+ * @typedef {import('@wordpress/components/build-types/select-control/types').SelectControlProps} SelectControlProps
20
+ */
21
+
22
+ /**
23
+ * The descriptions are purposely made generic as object-fit could be used for
24
+ * any replaced element. Provide your own set of options if you need different
25
+ * help text or labels.
26
+ *
27
+ * @see https://developer.mozilla.org/en-US/docs/Web/CSS/Replaced_element
28
+ *
29
+ * @type {SelectControlProps[]}
30
+ */
31
+ const DEFAULT_SCALE_OPTIONS = [{
32
+ value: 'fill',
33
+ label: (0, _i18n._x)('Fill', 'Scale option for dimensions control'),
34
+ help: (0, _i18n.__)('Fill the space by stretching the content.')
35
+ }, {
36
+ value: 'contain',
37
+ label: (0, _i18n._x)('Contain', 'Scale option for dimensions control'),
38
+ help: (0, _i18n.__)('Fit the content to the space without clipping.')
39
+ }, {
40
+ value: 'cover',
41
+ label: (0, _i18n._x)('Cover', 'Scale option for dimensions control'),
42
+ help: (0, _i18n.__)("Fill the space by clipping what doesn't fit.")
43
+ }, {
44
+ value: 'none',
45
+ label: (0, _i18n._x)('None', 'Scale option for dimensions control'),
46
+ help: (0, _i18n.__)('Do not adjust the sizing of the content. Content that is too large will be clipped, and content that is too small will have additional padding.')
47
+ }, {
48
+ value: 'scale-down',
49
+ label: (0, _i18n._x)('Scale down', 'Scale option for dimensions control'),
50
+ help: (0, _i18n.__)('Scale down the content to fit the space if it is too big. Content that is too small will have additional padding.')
51
+ }];
52
+ /**
53
+ * @callback ScaleToolPropsOnChange
54
+ * @param {string} nextValue New scale value.
55
+ * @return {void}
56
+ */
57
+
58
+ /**
59
+ * @typedef {Object} ScaleToolProps
60
+ * @property {string} [panelId] ID of the panel that contains the controls.
61
+ * @property {string} [value] Current scale value.
62
+ * @property {ScaleToolPropsOnChange} [onChange] Callback to update the scale value.
63
+ * @property {SelectControlProps[]} [options] Scale options.
64
+ * @property {string} [defaultValue] Default scale value.
65
+ * @property {boolean} [showControl=true] Whether to show the control.
66
+ * @property {boolean} [isShownByDefault=true] Whether the tool panel is shown by default.
67
+ */
68
+
69
+ /**
70
+ * A tool to select the CSS object-fit property for the image.
71
+ *
72
+ * @param {ScaleToolProps} props
73
+ *
74
+ * @return {import('@wordpress/element').WPElement} The scale tool.
75
+ */
76
+
77
+ function ScaleTool({
78
+ panelId,
79
+ value,
80
+ onChange,
81
+ options = DEFAULT_SCALE_OPTIONS,
82
+ defaultValue = DEFAULT_SCALE_OPTIONS[0].value,
83
+ isShownByDefault = true
84
+ }) {
85
+ // Match the CSS default so if the value is used directly in CSS it will look correct in the control.
86
+ const displayValue = value !== null && value !== void 0 ? value : 'fill';
87
+ const scaleHelp = (0, _element.useMemo)(() => {
88
+ return options.reduce((acc, option) => {
89
+ acc[option.value] = option.help;
90
+ return acc;
91
+ }, {});
92
+ }, [options]);
93
+ return (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
94
+ label: (0, _i18n.__)('Scale'),
95
+ isShownByDefault: isShownByDefault,
96
+ hasValue: () => displayValue !== defaultValue,
97
+ onDeselect: () => onChange(defaultValue),
98
+ panelId: panelId
99
+ }, (0, _element.createElement)(_components.__experimentalToggleGroupControl, {
100
+ label: (0, _i18n.__)('Scale'),
101
+ isBlock: true,
102
+ help: scaleHelp[displayValue],
103
+ value: displayValue,
104
+ onChange: onChange,
105
+ __nextHasNoMarginBottom: true
106
+ }, options.map(option => (0, _element.createElement)(_components.__experimentalToggleGroupControlOption, {
107
+ key: option.value,
108
+ ...option
109
+ }))));
110
+ }
111
+ //# sourceMappingURL=scale-tool.js.map