@wordpress/block-editor 8.0.9 → 8.0.12

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 (144) hide show
  1. package/build/components/block-inspector/index.js +12 -2
  2. package/build/components/block-inspector/index.js.map +1 -1
  3. package/build/components/block-list/block.js +1 -1
  4. package/build/components/block-list/block.js.map +1 -1
  5. package/build/components/block-list/block.native.js +2 -3
  6. package/build/components/block-list/block.native.js.map +1 -1
  7. package/build/components/block-list/use-block-props/index.js +1 -3
  8. package/build/components/block-list/use-block-props/index.js.map +1 -1
  9. package/build/components/block-list/use-in-between-inserter.js +1 -1
  10. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  11. package/build/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
  12. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  13. package/build/components/block-mover/button.js +2 -2
  14. package/build/components/block-mover/button.js.map +1 -1
  15. package/build/components/block-mover/index.js +2 -2
  16. package/build/components/block-mover/index.js.map +1 -1
  17. package/build/components/block-mover/index.native.js +2 -2
  18. package/build/components/block-mover/index.native.js.map +1 -1
  19. package/build/components/block-preview/index.js +51 -0
  20. package/build/components/block-preview/index.js.map +1 -1
  21. package/build/components/block-tools/block-selection-button.js +3 -3
  22. package/build/components/block-tools/block-selection-button.js.map +1 -1
  23. package/build/components/colors-gradients/control.js +1 -0
  24. package/build/components/colors-gradients/control.js.map +1 -1
  25. package/build/components/index.js +8 -1
  26. package/build/components/index.js.map +1 -1
  27. package/build/components/inserter/hooks/use-insertion-point.js +2 -2
  28. package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
  29. package/build/components/inserter/index.js +2 -2
  30. package/build/components/inserter/index.js.map +1 -1
  31. package/build/components/inserter/index.native.js +2 -2
  32. package/build/components/inserter/index.native.js.map +1 -1
  33. package/build/components/inserter/quick-inserter.js +1 -1
  34. package/build/components/inserter/quick-inserter.js.map +1 -1
  35. package/build/components/inspector-controls/block-support-tools-panel.js +50 -22
  36. package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  37. package/build/components/list-view/use-list-view-drop-zone.js +1 -1
  38. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  39. package/build/components/provider/use-block-sync.js +37 -10
  40. package/build/components/provider/use-block-sync.js.map +1 -1
  41. package/build/components/use-on-block-drop/index.js +1 -1
  42. package/build/components/use-on-block-drop/index.js.map +1 -1
  43. package/build/components/use-setting/index.js +7 -0
  44. package/build/components/use-setting/index.js.map +1 -1
  45. package/build/layouts/flex.js +3 -27
  46. package/build/layouts/flex.js.map +1 -1
  47. package/build/store/actions.js +3 -3
  48. package/build/store/actions.js.map +1 -1
  49. package/build/store/reducer.js +34 -83
  50. package/build/store/reducer.js.map +1 -1
  51. package/build/store/selectors.js +2 -2
  52. package/build/store/selectors.js.map +1 -1
  53. package/build/utils/transform-styles/index.js +2 -3
  54. package/build/utils/transform-styles/index.js.map +1 -1
  55. package/build-module/components/block-inspector/index.js +12 -2
  56. package/build-module/components/block-inspector/index.js.map +1 -1
  57. package/build-module/components/block-list/block.js +1 -1
  58. package/build-module/components/block-list/block.js.map +1 -1
  59. package/build-module/components/block-list/block.native.js +2 -3
  60. package/build-module/components/block-list/block.native.js.map +1 -1
  61. package/build-module/components/block-list/use-block-props/index.js +1 -3
  62. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  63. package/build-module/components/block-list/use-in-between-inserter.js +1 -1
  64. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  65. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
  66. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  67. package/build-module/components/block-mover/button.js +2 -2
  68. package/build-module/components/block-mover/button.js.map +1 -1
  69. package/build-module/components/block-mover/index.js +2 -2
  70. package/build-module/components/block-mover/index.js.map +1 -1
  71. package/build-module/components/block-mover/index.native.js +2 -2
  72. package/build-module/components/block-mover/index.native.js.map +1 -1
  73. package/build-module/components/block-preview/index.js +46 -0
  74. package/build-module/components/block-preview/index.js.map +1 -1
  75. package/build-module/components/block-tools/block-selection-button.js +3 -3
  76. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  77. package/build-module/components/colors-gradients/control.js +1 -0
  78. package/build-module/components/colors-gradients/control.js.map +1 -1
  79. package/build-module/components/index.js +1 -1
  80. package/build-module/components/index.js.map +1 -1
  81. package/build-module/components/inserter/hooks/use-insertion-point.js +2 -2
  82. package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
  83. package/build-module/components/inserter/index.js +2 -2
  84. package/build-module/components/inserter/index.js.map +1 -1
  85. package/build-module/components/inserter/index.native.js +2 -2
  86. package/build-module/components/inserter/index.native.js.map +1 -1
  87. package/build-module/components/inserter/quick-inserter.js +1 -1
  88. package/build-module/components/inserter/quick-inserter.js.map +1 -1
  89. package/build-module/components/inspector-controls/block-support-tools-panel.js +50 -22
  90. package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  91. package/build-module/components/list-view/use-list-view-drop-zone.js +1 -1
  92. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  93. package/build-module/components/provider/use-block-sync.js +41 -14
  94. package/build-module/components/provider/use-block-sync.js.map +1 -1
  95. package/build-module/components/use-on-block-drop/index.js +1 -1
  96. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  97. package/build-module/components/use-setting/index.js +7 -0
  98. package/build-module/components/use-setting/index.js.map +1 -1
  99. package/build-module/layouts/flex.js +3 -27
  100. package/build-module/layouts/flex.js.map +1 -1
  101. package/build-module/store/actions.js +3 -3
  102. package/build-module/store/actions.js.map +1 -1
  103. package/build-module/store/reducer.js +35 -84
  104. package/build-module/store/reducer.js.map +1 -1
  105. package/build-module/store/selectors.js +2 -2
  106. package/build-module/store/selectors.js.map +1 -1
  107. package/build-module/utils/transform-styles/index.js +2 -3
  108. package/build-module/utils/transform-styles/index.js.map +1 -1
  109. package/build-style/style-rtl.css +17 -2
  110. package/build-style/style.css +17 -2
  111. package/package.json +9 -9
  112. package/src/components/block-inspector/index.js +17 -1
  113. package/src/components/block-list/block.js +1 -1
  114. package/src/components/block-list/block.native.js +2 -2
  115. package/src/components/block-list/use-block-props/index.js +1 -3
  116. package/src/components/block-list/use-in-between-inserter.js +1 -1
  117. package/src/components/block-mobile-toolbar/block-actions-menu.native.js +2 -5
  118. package/src/components/block-mover/button.js +2 -6
  119. package/src/components/block-mover/index.js +2 -5
  120. package/src/components/block-mover/index.native.js +2 -5
  121. package/src/components/block-preview/index.js +60 -0
  122. package/src/components/block-preview/style.scss +23 -0
  123. package/src/components/block-preview/test/index.js +114 -0
  124. package/src/components/block-tools/block-selection-button.js +3 -9
  125. package/src/components/border-style-control/style.scss +3 -2
  126. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -0
  127. package/src/components/colors-gradients/control.js +3 -0
  128. package/src/components/index.js +4 -1
  129. package/src/components/inserter/hooks/use-insertion-point.js +2 -9
  130. package/src/components/inserter/index.js +2 -2
  131. package/src/components/inserter/index.native.js +2 -5
  132. package/src/components/inserter/quick-inserter.js +1 -1
  133. package/src/components/inspector-controls/block-support-tools-panel.js +57 -21
  134. package/src/components/list-view/use-list-view-drop-zone.js +1 -1
  135. package/src/components/provider/use-block-sync.js +45 -11
  136. package/src/components/use-on-block-drop/index.js +1 -4
  137. package/src/components/use-setting/index.js +9 -0
  138. package/src/layouts/flex.js +4 -25
  139. package/src/store/actions.js +3 -4
  140. package/src/store/reducer.js +36 -105
  141. package/src/store/selectors.js +2 -2
  142. package/src/store/test/reducer.js +35 -0
  143. package/src/store/test/selectors.js +1 -1
  144. package/src/utils/transform-styles/index.js +13 -16
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/utils/transform-styles/index.js"],"names":["map","compose","traverse","urlRewrite","wrap","transformStyles","styles","wrapperClassName","css","baseURL","__experimentalNoWrapper","transforms","push","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,YAArB;AACA,OAAOC,UAAP,MAAuB,0BAAvB;AACA,OAAOC,IAAP,MAAiB,mBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,UAAEC,MAAF,EAAqC;AAAA,MAA3BC,gBAA2B,uEAAR,EAAQ;AAC5D,SAAOP,GAAG,CACTM,MADS,EAET,QAAyD;AAAA,QAAvD;AAAEE,MAAAA,GAAF;AAAOC,MAAAA,OAAP;AAAgBC,MAAAA,uBAAuB,GAAG;AAA1C,KAAuD;AACxD,UAAMC,UAAU,GAAG,EAAnB;;AACA,QAAKJ,gBAAgB,IAAI,CAAEG,uBAA3B,EAAqD;AACpDC,MAAAA,UAAU,CAACC,IAAX,CAAiBR,IAAI,CAAEG,gBAAF,CAArB;AACA;;AACD,QAAKE,OAAL,EAAe;AACdE,MAAAA,UAAU,CAACC,IAAX,CAAiBT,UAAU,CAAEM,OAAF,CAA3B;AACA;;AACD,QAAKE,UAAU,CAACE,MAAhB,EAAyB;AACxB,aAAOX,QAAQ,CAAEM,GAAF,EAAOP,OAAO,CAAEU,UAAF,CAAd,CAAf;AACA;;AAED,WAAOH,GAAP;AACA,GAfQ,CAAV;AAiBA,CAlBD;;AAoBA,eAAeH,eAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport traverse from './traverse';\nimport urlRewrite from './transforms/url-rewrite';\nimport wrap from './transforms/wrap';\n\n/**\n * Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.\n *\n * @param {Array} styles CSS rules.\n * @param {string} wrapperClassName Wrapper Class Name.\n * @return {Array} converted rules.\n */\nconst transformStyles = ( styles, wrapperClassName = '' ) => {\n\treturn map(\n\t\tstyles,\n\t\t( { css, baseURL, __experimentalNoWrapper = false } ) => {\n\t\t\tconst transforms = [];\n\t\t\tif ( wrapperClassName && ! __experimentalNoWrapper ) {\n\t\t\t\ttransforms.push( wrap( wrapperClassName ) );\n\t\t\t}\n\t\t\tif ( baseURL ) {\n\t\t\t\ttransforms.push( urlRewrite( baseURL ) );\n\t\t\t}\n\t\t\tif ( transforms.length ) {\n\t\t\t\treturn traverse( css, compose( transforms ) );\n\t\t\t}\n\n\t\t\treturn css;\n\t\t}\n\t);\n};\n\nexport default transformStyles;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/utils/transform-styles/index.js"],"names":["map","compose","traverse","urlRewrite","wrap","transformStyles","styles","wrapperClassName","css","baseURL","transforms","push","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,YAArB;AACA,OAAOC,UAAP,MAAuB,0BAAvB;AACA,OAAOC,IAAP,MAAiB,mBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAG,UAAEC,MAAF,EAAqC;AAAA,MAA3BC,gBAA2B,uEAAR,EAAQ;AAC5D,SAAOP,GAAG,CAAEM,MAAF,EAAU,QAAwB;AAAA,QAAtB;AAAEE,MAAAA,GAAF;AAAOC,MAAAA;AAAP,KAAsB;AAC3C,UAAMC,UAAU,GAAG,EAAnB;;AACA,QAAKH,gBAAL,EAAwB;AACvBG,MAAAA,UAAU,CAACC,IAAX,CAAiBP,IAAI,CAAEG,gBAAF,CAArB;AACA;;AACD,QAAKE,OAAL,EAAe;AACdC,MAAAA,UAAU,CAACC,IAAX,CAAiBR,UAAU,CAAEM,OAAF,CAA3B;AACA;;AACD,QAAKC,UAAU,CAACE,MAAhB,EAAyB;AACxB,aAAOV,QAAQ,CAAEM,GAAF,EAAOP,OAAO,CAAES,UAAF,CAAd,CAAf;AACA;;AAED,WAAOF,GAAP;AACA,GAbS,CAAV;AAcA,CAfD;;AAiBA,eAAeH,eAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport traverse from './traverse';\nimport urlRewrite from './transforms/url-rewrite';\nimport wrap from './transforms/wrap';\n\n/**\n * Applies a series of CSS rule transforms to wrap selectors inside a given class and/or rewrite URLs depending on the parameters passed.\n *\n * @param {Array} styles CSS rules.\n * @param {string} wrapperClassName Wrapper Class Name.\n * @return {Array} converted rules.\n */\nconst transformStyles = ( styles, wrapperClassName = '' ) => {\n\treturn map( styles, ( { css, baseURL } ) => {\n\t\tconst transforms = [];\n\t\tif ( wrapperClassName ) {\n\t\t\ttransforms.push( wrap( wrapperClassName ) );\n\t\t}\n\t\tif ( baseURL ) {\n\t\t\ttransforms.push( urlRewrite( baseURL ) );\n\t\t}\n\t\tif ( transforms.length ) {\n\t\t\treturn traverse( css, compose( transforms ) );\n\t\t}\n\n\t\treturn css;\n\t} );\n};\n\nexport default transformStyles;\n"]}
@@ -1188,6 +1188,20 @@
1188
1188
  display: none;
1189
1189
  }
1190
1190
 
1191
+ .block-editor-block-preview__live-content * {
1192
+ pointer-events: none;
1193
+ }
1194
+ .block-editor-block-preview__live-content .block-list-appender {
1195
+ display: none;
1196
+ }
1197
+ .block-editor-block-preview__live-content .components-button:disabled {
1198
+ opacity: initial;
1199
+ }
1200
+ .block-editor-block-preview__live-content .components-placeholder,
1201
+ .block-editor-block-preview__live-content .block-editor-block-list__block[data-empty=true] {
1202
+ display: none;
1203
+ }
1204
+
1191
1205
  .block-editor-block-settings-menu__popover .components-dropdown-menu__menu {
1192
1206
  padding: 0;
1193
1207
  }
@@ -1698,8 +1712,9 @@
1698
1712
  }
1699
1713
 
1700
1714
  .components-border-style-control legend {
1701
- line-height: 1.2;
1702
- padding-bottom: 4px;
1715
+ line-height: 1.4;
1716
+ margin-bottom: 8px;
1717
+ padding: 0;
1703
1718
  }
1704
1719
  .components-border-style-control .components-border-style-control__buttons {
1705
1720
  display: inline-flex;
@@ -1188,6 +1188,20 @@
1188
1188
  display: none;
1189
1189
  }
1190
1190
 
1191
+ .block-editor-block-preview__live-content * {
1192
+ pointer-events: none;
1193
+ }
1194
+ .block-editor-block-preview__live-content .block-list-appender {
1195
+ display: none;
1196
+ }
1197
+ .block-editor-block-preview__live-content .components-button:disabled {
1198
+ opacity: initial;
1199
+ }
1200
+ .block-editor-block-preview__live-content .components-placeholder,
1201
+ .block-editor-block-preview__live-content .block-editor-block-list__block[data-empty=true] {
1202
+ display: none;
1203
+ }
1204
+
1191
1205
  .block-editor-block-settings-menu__popover .components-dropdown-menu__menu {
1192
1206
  padding: 0;
1193
1207
  }
@@ -1698,8 +1712,9 @@
1698
1712
  }
1699
1713
 
1700
1714
  .components-border-style-control legend {
1701
- line-height: 1.2;
1702
- padding-bottom: 4px;
1715
+ line-height: 1.4;
1716
+ margin-bottom: 8px;
1717
+ padding: 0;
1703
1718
  }
1704
1719
  .components-border-style-control .components-border-style-control__buttons {
1705
1720
  display: inline-flex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-editor",
3
- "version": "8.0.9",
3
+ "version": "8.0.12",
4
4
  "description": "Generic block editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -37,10 +37,10 @@
37
37
  "@wordpress/api-fetch": "^5.2.6",
38
38
  "@wordpress/blob": "^3.2.2",
39
39
  "@wordpress/block-serialization-default-parser": "^4.2.3",
40
- "@wordpress/blocks": "^11.1.4",
41
- "@wordpress/components": "^19.1.3",
42
- "@wordpress/compose": "^5.0.6",
43
- "@wordpress/data": "^6.1.4",
40
+ "@wordpress/blocks": "^11.1.5",
41
+ "@wordpress/components": "^19.1.6",
42
+ "@wordpress/compose": "^5.0.7",
43
+ "@wordpress/data": "^6.1.5",
44
44
  "@wordpress/deprecated": "^3.2.3",
45
45
  "@wordpress/dom": "^3.2.7",
46
46
  "@wordpress/element": "^4.0.4",
@@ -49,10 +49,10 @@
49
49
  "@wordpress/i18n": "^4.2.4",
50
50
  "@wordpress/icons": "^6.1.1",
51
51
  "@wordpress/is-shallow-equal": "^4.2.1",
52
- "@wordpress/keyboard-shortcuts": "^3.0.6",
52
+ "@wordpress/keyboard-shortcuts": "^3.0.7",
53
53
  "@wordpress/keycodes": "^3.2.4",
54
- "@wordpress/notices": "^3.2.7",
55
- "@wordpress/rich-text": "^5.0.6",
54
+ "@wordpress/notices": "^3.2.8",
55
+ "@wordpress/rich-text": "^5.0.7",
56
56
  "@wordpress/shortcode": "^3.2.3",
57
57
  "@wordpress/token-list": "^2.2.2",
58
58
  "@wordpress/url": "^3.3.1",
@@ -75,5 +75,5 @@
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "f8c50499a12f926661103acfaeea6780d85b947b"
78
+ "gitHead": "1081a28b2368fcebd9a14554fbd0e25eb33fbcb6"
79
79
  }
@@ -69,7 +69,19 @@ const BlockInspector = ( {
69
69
  return (
70
70
  <div className="block-editor-block-inspector">
71
71
  <MultiSelectionInspector />
72
- <InspectorControls.Slot bubblesVirtually={ bubblesVirtually } />
72
+ <InspectorControls.Slot />
73
+ <InspectorControls.Slot
74
+ __experimentalGroup="typography"
75
+ label={ __( 'Typography' ) }
76
+ />
77
+ <InspectorControls.Slot
78
+ __experimentalGroup="dimensions"
79
+ label={ __( 'Dimensions' ) }
80
+ />
81
+ <InspectorControls.Slot
82
+ __experimentalGroup="border"
83
+ label={ __( 'Border' ) }
84
+ />
73
85
  </div>
74
86
  );
75
87
  }
@@ -139,6 +151,10 @@ const BlockInspectorSingleBlock = ( {
139
151
  bubblesVirtually={ bubblesVirtually }
140
152
  label={ __( 'Dimensions' ) }
141
153
  />
154
+ <InspectorControls.Slot
155
+ __experimentalGroup="border"
156
+ label={ __( 'Border' ) }
157
+ />
142
158
  <div>
143
159
  <AdvancedControls bubblesVirtually={ bubblesVirtually } />
144
160
  </div>
@@ -259,7 +259,7 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, { select } ) => {
259
259
  onInsertBlocksAfter( blocks ) {
260
260
  const { clientId, rootClientId } = ownProps;
261
261
  const { getBlockIndex } = select( blockEditorStore );
262
- const index = getBlockIndex( clientId, rootClientId );
262
+ const index = getBlockIndex( clientId );
263
263
  insertBlocks( blocks, index + 1, rootClientId );
264
264
  },
265
265
  onMerge( forward ) {
@@ -302,7 +302,7 @@ function getWrapperProps( value, getWrapperPropsFunction ) {
302
302
  }
303
303
 
304
304
  export default compose( [
305
- withSelect( ( select, { clientId, rootClientId } ) => {
305
+ withSelect( ( select, { clientId } ) => {
306
306
  const {
307
307
  getBlockIndex,
308
308
  getSettings,
@@ -314,7 +314,7 @@ export default compose( [
314
314
  hasSelectedInnerBlock,
315
315
  } = select( blockEditorStore );
316
316
 
317
- const order = getBlockIndex( clientId, rootClientId );
317
+ const order = getBlockIndex( clientId );
318
318
  const isSelected = isBlockSelected( clientId );
319
319
  const isInnerBlockSelected = hasSelectedInnerBlock( clientId );
320
320
  const block = getBlock( clientId );
@@ -75,7 +75,6 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
75
75
  } = useSelect(
76
76
  ( select ) => {
77
77
  const {
78
- getBlockRootClientId,
79
78
  getBlockIndex,
80
79
  getBlockMode,
81
80
  getBlockName,
@@ -91,11 +90,10 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
91
90
  isBlockMultiSelected( clientId ) ||
92
91
  isAncestorMultiSelected( clientId );
93
92
  const blockName = getBlockName( clientId );
94
- const rootClientId = getBlockRootClientId( clientId );
95
93
  const blockType = getBlockType( blockName );
96
94
 
97
95
  return {
98
- index: getBlockIndex( clientId, rootClientId ),
96
+ index: getBlockIndex( clientId ),
99
97
  mode: getBlockMode( clientId ),
100
98
  name: blockName,
101
99
  blockApiVersion: blockType?.apiVersion || 1,
@@ -144,7 +144,7 @@ export function useInBetweenInserter() {
144
144
  return;
145
145
  }
146
146
 
147
- const index = getBlockIndex( clientId, rootClientId );
147
+ const index = getBlockIndex( clientId );
148
148
 
149
149
  // Don't show the in-between inserter before the first block in
150
150
  // the list (preserves the original behaviour).
@@ -316,11 +316,8 @@ export default compose(
316
316
  const rootClientId = getBlockRootClientId( firstClientId );
317
317
  const blockOrder = getBlockOrder( rootClientId );
318
318
 
319
- const firstIndex = getBlockIndex( firstClientId, rootClientId );
320
- const lastIndex = getBlockIndex(
321
- last( normalizedClientIds ),
322
- rootClientId
323
- );
319
+ const firstIndex = getBlockIndex( firstClientId );
320
+ const lastIndex = getBlockIndex( last( normalizedClientIds ) );
324
321
 
325
322
  const innerBlocks = getBlocksByClientId( clientIds );
326
323
 
@@ -84,13 +84,9 @@ const BlockMoverButton = forwardRef(
84
84
  const normalizedClientIds = castArray( clientIds );
85
85
  const firstClientId = first( normalizedClientIds );
86
86
  const blockRootClientId = getBlockRootClientId( firstClientId );
87
- const firstBlockIndex = getBlockIndex(
88
- firstClientId,
89
- blockRootClientId
90
- );
87
+ const firstBlockIndex = getBlockIndex( firstClientId );
91
88
  const lastBlockIndex = getBlockIndex(
92
- last( normalizedClientIds ),
93
- blockRootClientId
89
+ last( normalizedClientIds )
94
90
  );
95
91
  const blockOrder = getBlockOrder( blockRootClientId );
96
92
  const block = getBlock( firstClientId );
@@ -108,11 +108,8 @@ export default withSelect( ( select, { clientIds } ) => {
108
108
  const firstClientId = first( normalizedClientIds );
109
109
  const block = getBlock( firstClientId );
110
110
  const rootClientId = getBlockRootClientId( first( normalizedClientIds ) );
111
- const firstIndex = getBlockIndex( firstClientId, rootClientId );
112
- const lastIndex = getBlockIndex(
113
- last( normalizedClientIds ),
114
- rootClientId
115
- );
111
+ const firstIndex = getBlockIndex( firstClientId );
112
+ const lastIndex = getBlockIndex( last( normalizedClientIds ) );
116
113
  const blockOrder = getBlockOrder( rootClientId );
117
114
  const isFirst = firstIndex === 0;
118
115
  const isLast = lastIndex === blockOrder.length - 1;
@@ -138,11 +138,8 @@ export default compose(
138
138
  const firstClientId = first( normalizedClientIds );
139
139
  const rootClientId = getBlockRootClientId( firstClientId );
140
140
  const blockOrder = getBlockOrder( rootClientId );
141
- const firstIndex = getBlockIndex( firstClientId, rootClientId );
142
- const lastIndex = getBlockIndex(
143
- last( normalizedClientIds ),
144
- rootClientId
145
- );
141
+ const firstIndex = getBlockIndex( firstClientId );
142
+ const lastIndex = getBlockIndex( last( normalizedClientIds ) );
146
143
 
147
144
  return {
148
145
  firstIndex,
@@ -2,10 +2,15 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { castArray } from 'lodash';
5
+ import classnames from 'classnames';
5
6
 
6
7
  /**
7
8
  * WordPress dependencies
8
9
  */
10
+ import {
11
+ __experimentalUseDisabled as useDisabled,
12
+ useMergeRefs,
13
+ } from '@wordpress/compose';
9
14
  import { useSelect } from '@wordpress/data';
10
15
  import { memo, useMemo } from '@wordpress/element';
11
16
 
@@ -16,6 +21,7 @@ import BlockEditorProvider from '../provider';
16
21
  import LiveBlockPreview from './live';
17
22
  import AutoHeightBlockPreview from './auto';
18
23
  import { store as blockEditorStore } from '../../store';
24
+ import { BlockListItems } from '../block-list';
19
25
 
20
26
  export function BlockPreview( {
21
27
  blocks,
@@ -63,3 +69,57 @@ export function BlockPreview( {
63
69
  * @return {WPComponent} The component to be rendered.
64
70
  */
65
71
  export default memo( BlockPreview );
72
+
73
+ /**
74
+ * This hook is used to lightly mark an element as a block preview wrapper
75
+ * element. Call this hook and pass the returned props to the element to mark as
76
+ * a block preview wrapper, automatically rendering inner blocks as children. If
77
+ * you define a ref for the element, it is important to pass the ref to this
78
+ * hook, which the hook in turn will pass to the component through the props it
79
+ * returns. Optionally, you can also pass any other props through this hook, and
80
+ * they will be merged and returned.
81
+ *
82
+ * @param {Object} options Preview options.
83
+ * @param {WPBlock[]} options.blocks Block objects.
84
+ * @param {Object} options.props Optional. Props to pass to the element. Must contain
85
+ * the ref if one is defined.
86
+ * @param {Object} options.__experimentalLayout Layout settings to be used in the preview.
87
+ *
88
+ */
89
+ export function useBlockPreview( {
90
+ blocks,
91
+ props = {},
92
+ __experimentalLayout,
93
+ } ) {
94
+ const originalSettings = useSelect(
95
+ ( select ) => select( blockEditorStore ).getSettings(),
96
+ []
97
+ );
98
+ const disabledRef = useDisabled();
99
+ const ref = useMergeRefs( [ props.ref, disabledRef ] );
100
+ const settings = useMemo(
101
+ () => ( { ...originalSettings, __experimentalBlockPatterns: [] } ),
102
+ [ originalSettings ]
103
+ );
104
+ const renderedBlocks = useMemo( () => castArray( blocks ), [ blocks ] );
105
+
106
+ const children = (
107
+ <BlockEditorProvider value={ renderedBlocks } settings={ settings }>
108
+ <BlockListItems
109
+ renderAppender={ false }
110
+ __experimentalLayout={ __experimentalLayout }
111
+ />
112
+ </BlockEditorProvider>
113
+ );
114
+
115
+ return {
116
+ ...props,
117
+ ref,
118
+ className: classnames(
119
+ props.className,
120
+ 'block-editor-block-preview__live-content',
121
+ 'components-disabled'
122
+ ),
123
+ children: blocks?.length ? children : null,
124
+ };
125
+ }
@@ -41,3 +41,26 @@
41
41
  .block-editor-block-preview__content-iframe .block-list-appender {
42
42
  display: none;
43
43
  }
44
+
45
+ .block-editor-block-preview__live-content {
46
+ * {
47
+ pointer-events: none;
48
+ }
49
+
50
+ // Hide the block appender, as the block is not editable in this context.
51
+ .block-list-appender {
52
+ display: none;
53
+ }
54
+
55
+ // Revert button disable styles to ensure that button styles render as they will on the
56
+ // front end of the site. For example, this ensures that Social Links icons display correctly.
57
+ .components-button:disabled {
58
+ opacity: initial;
59
+ }
60
+
61
+ // Hide placeholders.
62
+ .components-placeholder,
63
+ .block-editor-block-list__block[data-empty="true"] {
64
+ display: none;
65
+ }
66
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen, waitFor } from '@testing-library/react';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import {
10
+ registerBlockType,
11
+ unregisterBlockType,
12
+ createBlock,
13
+ } from '@wordpress/blocks';
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+ import { useBlockPreview } from '../';
19
+
20
+ jest.mock( '@wordpress/dom', () => {
21
+ const focus = jest.requireActual( '../../../../../dom/src' ).focus;
22
+
23
+ return {
24
+ focus: {
25
+ ...focus,
26
+ focusable: {
27
+ ...focus.focusable,
28
+ find( context ) {
29
+ // In JSDOM, all elements have zero'd widths and height.
30
+ // This is a metric for focusable's `isVisible`, so find
31
+ // and apply an arbitrary non-zero width.
32
+ Array.from( context.querySelectorAll( '*' ) ).forEach(
33
+ ( element ) => {
34
+ Object.defineProperties( element, {
35
+ offsetWidth: {
36
+ get: () => 1,
37
+ configurable: true,
38
+ },
39
+ } );
40
+ }
41
+ );
42
+
43
+ return focus.focusable.find( ...arguments );
44
+ },
45
+ },
46
+ },
47
+ };
48
+ } );
49
+
50
+ describe( 'useBlockPreview', () => {
51
+ beforeAll( () => {
52
+ registerBlockType( 'core/test-block', {
53
+ save: () => (
54
+ <div>
55
+ Test block save view
56
+ <button>Button</button>
57
+ </div>
58
+ ),
59
+ edit: () => (
60
+ <div>
61
+ Test block edit view
62
+ <button>Button</button>
63
+ </div>
64
+ ),
65
+ category: 'text',
66
+ title: 'test block',
67
+ } );
68
+ } );
69
+
70
+ afterAll( () => {
71
+ unregisterBlockType( 'core/test-block' );
72
+ } );
73
+
74
+ function BlockPreviewComponent( { blocks, className } ) {
75
+ const blockPreviewProps = useBlockPreview( {
76
+ blocks,
77
+ props: { className },
78
+ } );
79
+ return <div { ...blockPreviewProps } />;
80
+ }
81
+
82
+ it( 'will render a block preview with minimal nesting', async () => {
83
+ const blocks = [];
84
+ blocks.push( createBlock( 'core/test-block' ) );
85
+
86
+ const { container } = render(
87
+ <BlockPreviewComponent
88
+ className="test-container-classname"
89
+ blocks={ blocks }
90
+ />
91
+ );
92
+
93
+ // Test block and block contents are rendered.
94
+ const previewedBlock = screen.getByLabelText( 'Block: test block' );
95
+ const previewedBlockContents = screen.getByText(
96
+ 'Test block edit view'
97
+ );
98
+ expect( previewedBlockContents ).toBeInTheDocument();
99
+
100
+ // Test elements within block contents are disabled.
101
+ await waitFor( () => {
102
+ const button = screen.getByText( 'Button' );
103
+ expect( button.hasAttribute( 'disabled' ) ).toBe( true );
104
+ } );
105
+
106
+ // Ensure the block preview class names are merged with the component's class name.
107
+ expect( container.firstChild.className ).toBe(
108
+ 'test-container-classname block-editor-block-preview__live-content components-disabled'
109
+ );
110
+
111
+ // Ensure there is no nesting between the parent component and rendered blocks.
112
+ expect( container.firstChild.firstChild ).toBe( previewedBlock );
113
+ } );
114
+ } );
@@ -59,7 +59,7 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
59
59
  hasBlockMovingClientId,
60
60
  getBlockListSettings,
61
61
  } = select( blockEditorStore );
62
- const index = getBlockIndex( clientId, rootClientId );
62
+ const index = getBlockIndex( clientId );
63
63
  const { name, attributes } = getBlock( clientId );
64
64
  const blockMovingMode = hasBlockMovingClientId();
65
65
  return {
@@ -169,14 +169,8 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
169
169
  if ( ( isEnter || isSpace ) && startingBlockClientId ) {
170
170
  const sourceRoot = getBlockRootClientId( startingBlockClientId );
171
171
  const destRoot = getBlockRootClientId( selectedBlockClientId );
172
- const sourceBlockIndex = getBlockIndex(
173
- startingBlockClientId,
174
- sourceRoot
175
- );
176
- let destinationBlockIndex = getBlockIndex(
177
- selectedBlockClientId,
178
- destRoot
179
- );
172
+ const sourceBlockIndex = getBlockIndex( startingBlockClientId );
173
+ let destinationBlockIndex = getBlockIndex( selectedBlockClientId );
180
174
  if (
181
175
  sourceBlockIndex < destinationBlockIndex &&
182
176
  sourceRoot === destRoot
@@ -1,7 +1,8 @@
1
1
  .components-border-style-control {
2
2
  legend {
3
- line-height: 1.2;
4
- padding-bottom: $grid-unit-05;
3
+ line-height: 1.4;
4
+ margin-bottom: $grid-unit-10;
5
+ padding: 0;
5
6
  }
6
7
 
7
8
  .components-border-style-control__buttons {
@@ -105,6 +105,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
105
105
  style={
106
106
  Object {
107
107
  "background": "#f00",
108
+ "color": "#000",
108
109
  }
109
110
  }
110
111
  >
@@ -132,6 +132,9 @@ function ColorGradientControlInner( {
132
132
  __experimentalHasMultipleOrigins={
133
133
  __experimentalHasMultipleOrigins
134
134
  }
135
+ __experimentalIsRenderedInSidebar={
136
+ __experimentalIsRenderedInSidebar
137
+ }
135
138
  clearable={ clearable }
136
139
  />
137
140
  ) }
@@ -103,7 +103,10 @@ export { default as BlockList } from './block-list';
103
103
  export { useBlockProps } from './block-list/use-block-props';
104
104
  export { LayoutStyle as __experimentalLayoutStyle } from './block-list/layout';
105
105
  export { default as BlockMover } from './block-mover';
106
- export { default as BlockPreview } from './block-preview';
106
+ export {
107
+ default as BlockPreview,
108
+ useBlockPreview as __experimentalUseBlockPreview,
109
+ } from './block-preview';
107
110
  export {
108
111
  default as BlockSelectionClearer,
109
112
  useBlockSelectionClearer as __unstableUseBlockSelectionClearer,
@@ -64,19 +64,12 @@ function useInsertionPoint( {
64
64
  _destinationIndex = insertionIndex;
65
65
  } else if ( clientId ) {
66
66
  // Insert after a specific client ID.
67
- _destinationIndex = getBlockIndex(
68
- clientId,
69
- _destinationRootClientId
70
- );
67
+ _destinationIndex = getBlockIndex( clientId );
71
68
  } else if ( ! isAppender && selectedBlockClientId ) {
72
69
  _destinationRootClientId = getBlockRootClientId(
73
70
  selectedBlockClientId
74
71
  );
75
- _destinationIndex =
76
- getBlockIndex(
77
- selectedBlockClientId,
78
- _destinationRootClientId
79
- ) + 1;
72
+ _destinationIndex = getBlockIndex( selectedBlockClientId ) + 1;
80
73
  } else {
81
74
  // Insert at the end of the list.
82
75
  _destinationIndex = getBlockOrder( _destinationRootClientId )
@@ -265,7 +265,7 @@ export default compose( [
265
265
 
266
266
  // If the clientId is defined, we insert at the position of the block.
267
267
  if ( clientId ) {
268
- return getBlockIndex( clientId, rootClientId );
268
+ return getBlockIndex( clientId );
269
269
  }
270
270
 
271
271
  // If there a selected block, we insert after the selected block.
@@ -275,7 +275,7 @@ export default compose( [
275
275
  end &&
276
276
  getBlockRootClientId( end ) === rootClientId
277
277
  ) {
278
- return getBlockIndex( end, rootClientId ) + 1;
278
+ return getBlockIndex( end ) + 1;
279
279
  }
280
280
 
281
281
  // Otherwise, we insert at the end of the current rootClientId
@@ -343,10 +343,7 @@ export default compose( [
343
343
  const destinationRootClientId = isAnyBlockSelected
344
344
  ? getBlockRootClientId( end )
345
345
  : rootClientId;
346
- const selectedBlockIndex = getBlockIndex(
347
- end,
348
- destinationRootClientId
349
- );
346
+ const selectedBlockIndex = getBlockIndex( end );
350
347
  const endOfRootIndex = getBlockOrder( rootClientId ).length;
351
348
  const isSelectedUnmodifiedDefaultBlock = isAnyBlockSelected
352
349
  ? isUnmodifiedDefaultBlock( getBlock( end ) )
@@ -364,7 +361,7 @@ export default compose( [
364
361
 
365
362
  // If the clientId is defined, we insert at the position of the block.
366
363
  if ( clientId ) {
367
- return getBlockIndex( clientId, rootClientId );
364
+ return getBlockIndex( clientId );
368
365
  }
369
366
 
370
367
  // If there is a selected block,
@@ -56,7 +56,7 @@ export default function QuickInserter( {
56
56
  const { getSettings, getBlockIndex, getBlockCount } = select(
57
57
  blockEditorStore
58
58
  );
59
- const index = getBlockIndex( clientId, rootClientId );
59
+ const index = getBlockIndex( clientId );
60
60
  return {
61
61
  setInserterIsOpened: getSettings()
62
62
  .__experimentalSetIsInserterOpened,