@wordpress/edit-widgets 7.0.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/build/blocks/widget-area/edit/index.cjs +106 -116
  2. package/build/blocks/widget-area/edit/index.cjs.map +1 -7
  3. package/build/blocks/widget-area/edit/inner-blocks.cjs +44 -62
  4. package/build/blocks/widget-area/edit/inner-blocks.cjs.map +1 -7
  5. package/build/blocks/widget-area/edit/use-is-dragging-within.cjs +41 -53
  6. package/build/blocks/widget-area/edit/use-is-dragging-within.cjs.map +1 -7
  7. package/build/blocks/widget-area/index.cjs +40 -44
  8. package/build/blocks/widget-area/index.cjs.map +1 -7
  9. package/build/components/error-boundary/index.cjs +115 -155
  10. package/build/components/error-boundary/index.cjs.map +1 -7
  11. package/build/components/header/document-tools/index.cjs +80 -115
  12. package/build/components/header/document-tools/index.cjs.map +1 -7
  13. package/build/components/header/index.cjs +77 -80
  14. package/build/components/header/index.cjs.map +1 -7
  15. package/build/components/header/undo-redo/redo.cjs +30 -52
  16. package/build/components/header/undo-redo/redo.cjs.map +1 -7
  17. package/build/components/header/undo-redo/undo.cjs +29 -51
  18. package/build/components/header/undo-redo/undo.cjs.map +1 -7
  19. package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
  20. package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
  21. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
  22. package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
  23. package/build/components/keyboard-shortcut-help-modal/index.cjs +94 -161
  24. package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
  25. package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +38 -75
  26. package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
  27. package/build/components/keyboard-shortcuts/index.cjs +107 -140
  28. package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
  29. package/build/components/layout/index.cjs +65 -74
  30. package/build/components/layout/index.cjs.map +1 -7
  31. package/build/components/layout/interface.cjs +82 -108
  32. package/build/components/layout/interface.cjs.map +1 -7
  33. package/build/components/layout/unsaved-changes-warning.cjs +41 -48
  34. package/build/components/layout/unsaved-changes-warning.cjs.map +1 -7
  35. package/build/components/more-menu/index.cjs +124 -191
  36. package/build/components/more-menu/index.cjs.map +1 -7
  37. package/build/components/more-menu/tools-more-menu-group.cjs +9 -29
  38. package/build/components/more-menu/tools-more-menu-group.cjs.map +1 -7
  39. package/build/components/notices/index.cjs +19 -39
  40. package/build/components/notices/index.cjs.map +1 -7
  41. package/build/components/save-button/index.cjs +31 -58
  42. package/build/components/save-button/index.cjs.map +1 -7
  43. package/build/components/secondary-sidebar/index.cjs +38 -45
  44. package/build/components/secondary-sidebar/index.cjs.map +1 -7
  45. package/build/components/secondary-sidebar/inserter-sidebar.cjs +50 -51
  46. package/build/components/secondary-sidebar/inserter-sidebar.cjs.map +1 -7
  47. package/build/components/secondary-sidebar/list-view-sidebar.cjs +51 -82
  48. package/build/components/secondary-sidebar/list-view-sidebar.cjs.map +1 -7
  49. package/build/components/sidebar/index.cjs +117 -180
  50. package/build/components/sidebar/index.cjs.map +1 -7
  51. package/build/components/sidebar/widget-areas.cjs +43 -85
  52. package/build/components/sidebar/widget-areas.cjs.map +1 -7
  53. package/build/components/welcome-guide/index.cjs +110 -186
  54. package/build/components/welcome-guide/index.cjs.map +1 -7
  55. package/build/components/widget-areas-block-editor-content/index.cjs +59 -64
  56. package/build/components/widget-areas-block-editor-content/index.cjs.map +1 -7
  57. package/build/components/widget-areas-block-editor-provider/index.cjs +105 -140
  58. package/build/components/widget-areas-block-editor-provider/index.cjs.map +1 -7
  59. package/build/constants.cjs +11 -32
  60. package/build/constants.cjs.map +1 -7
  61. package/build/filters/index.cjs +7 -4
  62. package/build/filters/move-to-widget-area.cjs +38 -53
  63. package/build/filters/move-to-widget-area.cjs.map +1 -7
  64. package/build/filters/replace-media-upload.cjs +11 -9
  65. package/build/filters/replace-media-upload.cjs.map +1 -7
  66. package/build/hooks/use-last-selected-widget-area.cjs +28 -49
  67. package/build/hooks/use-last-selected-widget-area.cjs.map +1 -7
  68. package/build/hooks/use-widget-library-insertion-point.cjs +33 -67
  69. package/build/hooks/use-widget-library-insertion-point.cjs.map +1 -7
  70. package/build/index.cjs +96 -97
  71. package/build/index.cjs.map +1 -7
  72. package/build/lock-unlock.cjs +10 -35
  73. package/build/lock-unlock.cjs.map +1 -7
  74. package/build/store/actions.cjs +276 -278
  75. package/build/store/actions.cjs.map +1 -7
  76. package/build/store/constants.cjs +12 -29
  77. package/build/store/constants.cjs.map +1 -7
  78. package/build/store/index.cjs +61 -52
  79. package/build/store/index.cjs.map +1 -7
  80. package/build/store/private-selectors.cjs +11 -32
  81. package/build/store/private-selectors.cjs.map +1 -7
  82. package/build/store/reducer.cjs +107 -88
  83. package/build/store/reducer.cjs.map +1 -7
  84. package/build/store/resolvers.cjs +60 -91
  85. package/build/store/resolvers.cjs.map +1 -7
  86. package/build/store/selectors.cjs +196 -229
  87. package/build/store/selectors.cjs.map +1 -7
  88. package/build/store/transformers.cjs +51 -82
  89. package/build/store/transformers.cjs.map +1 -7
  90. package/build/store/utils.cjs +76 -63
  91. package/build/store/utils.cjs.map +1 -7
  92. package/build-module/blocks/widget-area/edit/index.mjs +82 -94
  93. package/build-module/blocks/widget-area/edit/index.mjs.map +1 -7
  94. package/build-module/blocks/widget-area/edit/inner-blocks.mjs +19 -35
  95. package/build-module/blocks/widget-area/edit/inner-blocks.mjs.map +1 -7
  96. package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs +36 -33
  97. package/build-module/blocks/widget-area/edit/use-is-dragging-within.mjs.map +1 -7
  98. package/build-module/blocks/widget-area/index.mjs +12 -15
  99. package/build-module/blocks/widget-area/index.mjs.map +1 -7
  100. package/build-module/components/error-boundary/index.mjs +104 -129
  101. package/build-module/components/error-boundary/index.mjs.map +1 -7
  102. package/build-module/components/header/document-tools/index.mjs +51 -84
  103. package/build-module/components/header/document-tools/index.mjs.map +1 -7
  104. package/build-module/components/header/index.mjs +44 -47
  105. package/build-module/components/header/index.mjs.map +1 -7
  106. package/build-module/components/header/undo-redo/redo.mjs +20 -27
  107. package/build-module/components/header/undo-redo/redo.mjs.map +1 -7
  108. package/build-module/components/header/undo-redo/undo.mjs +19 -26
  109. package/build-module/components/header/undo-redo/undo.mjs.map +1 -7
  110. package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
  111. package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
  112. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
  113. package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
  114. package/build-module/components/keyboard-shortcut-help-modal/index.mjs +67 -136
  115. package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
  116. package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +32 -54
  117. package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
  118. package/build-module/components/keyboard-shortcuts/index.mjs +99 -119
  119. package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
  120. package/build-module/components/layout/index.mjs +29 -40
  121. package/build-module/components/layout/index.mjs.map +1 -7
  122. package/build-module/components/layout/interface.mjs +53 -82
  123. package/build-module/components/layout/interface.mjs.map +1 -7
  124. package/build-module/components/layout/unsaved-changes-warning.mjs +35 -27
  125. package/build-module/components/layout/unsaved-changes-warning.mjs.map +1 -7
  126. package/build-module/components/more-menu/index.mjs +94 -162
  127. package/build-module/components/more-menu/index.mjs.map +1 -7
  128. package/build-module/components/more-menu/tools-more-menu-group.mjs +5 -9
  129. package/build-module/components/more-menu/tools-more-menu-group.mjs.map +1 -7
  130. package/build-module/components/notices/index.mjs +12 -17
  131. package/build-module/components/notices/index.mjs.map +1 -7
  132. package/build-module/components/save-button/index.mjs +23 -35
  133. package/build-module/components/save-button/index.mjs.map +1 -7
  134. package/build-module/components/secondary-sidebar/index.mjs +15 -20
  135. package/build-module/components/secondary-sidebar/index.mjs.map +1 -7
  136. package/build-module/components/secondary-sidebar/inserter-sidebar.mjs +27 -25
  137. package/build-module/components/secondary-sidebar/inserter-sidebar.mjs.map +1 -7
  138. package/build-module/components/secondary-sidebar/list-view-sidebar.mjs +39 -55
  139. package/build-module/components/secondary-sidebar/list-view-sidebar.mjs.map +1 -7
  140. package/build-module/components/sidebar/index.mjs +96 -162
  141. package/build-module/components/sidebar/index.mjs.map +1 -7
  142. package/build-module/components/sidebar/widget-areas.mjs +30 -57
  143. package/build-module/components/sidebar/widget-areas.mjs.map +1 -7
  144. package/build-module/components/welcome-guide/index.mjs +103 -164
  145. package/build-module/components/welcome-guide/index.mjs.map +1 -7
  146. package/build-module/components/widget-areas-block-editor-content/index.mjs +34 -44
  147. package/build-module/components/widget-areas-block-editor-content/index.mjs.map +1 -7
  148. package/build-module/components/widget-areas-block-editor-provider/index.mjs +76 -109
  149. package/build-module/components/widget-areas-block-editor-provider/index.mjs.map +1 -7
  150. package/build-module/constants.mjs +5 -7
  151. package/build-module/constants.mjs.map +1 -7
  152. package/build-module/filters/index.mjs +0 -2
  153. package/build-module/filters/move-to-widget-area.mjs +28 -48
  154. package/build-module/filters/move-to-widget-area.mjs.map +1 -7
  155. package/build-module/filters/replace-media-upload.mjs +5 -8
  156. package/build-module/filters/replace-media-upload.mjs.map +1 -7
  157. package/build-module/hooks/use-last-selected-widget-area.mjs +23 -29
  158. package/build-module/hooks/use-last-selected-widget-area.mjs.map +1 -7
  159. package/build-module/hooks/use-widget-library-insertion-point.mjs +28 -47
  160. package/build-module/hooks/use-widget-library-insertion-point.mjs.map +1 -7
  161. package/build-module/index.mjs +62 -79
  162. package/build-module/index.mjs.map +1 -7
  163. package/build-module/lock-unlock.mjs +5 -10
  164. package/build-module/lock-unlock.mjs.map +1 -7
  165. package/build-module/store/actions.mjs +257 -247
  166. package/build-module/store/actions.mjs.map +1 -7
  167. package/build-module/store/constants.mjs +7 -5
  168. package/build-module/store/constants.mjs.map +1 -7
  169. package/build-module/store/index.mjs +18 -16
  170. package/build-module/store/index.mjs.map +1 -7
  171. package/build-module/store/private-selectors.mjs +5 -7
  172. package/build-module/store/private-selectors.mjs.map +1 -7
  173. package/build-module/store/reducer.mjs +95 -58
  174. package/build-module/store/reducer.mjs.map +1 -7
  175. package/build-module/store/resolvers.mjs +52 -71
  176. package/build-module/store/resolvers.mjs.map +1 -7
  177. package/build-module/store/selectors.mjs +178 -199
  178. package/build-module/store/selectors.mjs.map +1 -7
  179. package/build-module/store/transformers.mjs +44 -56
  180. package/build-module/store/transformers.mjs.map +1 -7
  181. package/build-module/store/utils.mjs +64 -32
  182. package/build-module/store/utils.mjs.map +1 -7
  183. package/build-style/style-rtl.css +32 -11
  184. package/build-style/style.css +32 -11
  185. package/package.json +33 -33
  186. package/src/components/error-boundary/index.jsx +2 -2
  187. package/src/components/header/index.jsx +13 -4
  188. package/src/components/header/style.scss +30 -3
  189. package/src/components/keyboard-shortcut-help-modal/shortcut.jsx +1 -0
  190. package/src/components/keyboard-shortcut-help-modal/style.scss +1 -1
  191. package/src/components/layout/style.scss +5 -9
  192. package/src/components/layout/unsaved-changes-warning.js +4 -9
  193. package/src/components/more-menu/index.jsx +0 -1
  194. package/src/components/sidebar/index.jsx +18 -18
  195. package/src/components/welcome-guide/index.jsx +4 -2
  196. package/src/store/actions.js +25 -2
  197. package/src/store/test/actions.jsdom.test.js +230 -0
  198. package/build/filters/index.cjs.map +0 -7
  199. package/build-module/filters/index.mjs.map +0 -7
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/selectors.js"],
4
- "sourcesContent": ["import { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\tif ( ! firstWidgetArea ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns whether widget saving is locked.\n *\n * @param {Object} state Global application state.\n *\n * @example\n * ```jsx\n * import { __ } from '@wordpress/i18n';\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst isSavingLocked = useSelect(\n * \t\t( select ) => select( widgetStore ).isWidgetSavingLocked(),\n * \t\t[]\n * \t);\n *\n * \treturn isSavingLocked ? (\n * \t\t<p>{ __( 'Widget saving is locked' ) }</p>\n * \t) : (\n * \t\t<p>{ __( 'Widget saving is not locked' ) }</p>\n * \t);\n * };\n * ```\n *\n * @return {boolean} Is locked.\n */\nexport function isWidgetSavingLocked( state ) {\n\treturn Object.keys( state.widgetSavingLock ).length > 0;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuD;AACvD,qBAAqC;AACrC,uBAAmC;AACnC,0BAA0C;AAC1C,mBAOO;AACP,uBAAmD;AAEnD,IAAM,wBAAwB;AAAA,EAC7B,cAAc;AAAA,EACd,gBAAgB;AACjB;AAOO,IAAM,iBAAa;AAAA,EAAwB,CAAE,eACnD;AAAA,IACC,MAAM;AACL,YAAM,UAAU,OAAQ,iBAAAA,KAAU,EAAE;AAAA,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,iBAAkB,OAAQ;AACzC,SAAO,MAAM;AACd;AA6BO,SAAS,qBAAsB,OAAQ;AAC7C,SAAO,OAAO,KAAM,MAAM,gBAAiB,EAAE,SAAS;AACvD;",
6
- "names": ["coreStore", "editWidgetsStoreName", "blockEditorStore"]
7
- }
1
+ {"version":3,"file":"selectors.cjs","names":["createRegistrySelector","createSelector","coreStore","buildWidgetsQuery","editWidgetsStoreName","buildWidgetAreasQuery","KIND","WIDGET_AREA_ENTITY_TYPE","POST_TYPE","buildWidgetAreaPostId","getWidgetIdFromBlock","blockEditorStore"],"sources":["../../src/store/selectors.js"],"sourcesContent":["import { createSelector, createRegistrySelector } from '@wordpress/data';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport {\n\tbuildWidgetsQuery,\n\tbuildWidgetAreasQuery,\n\tbuildWidgetAreaPostId,\n\tKIND,\n\tPOST_TYPE,\n\tWIDGET_AREA_ENTITY_TYPE,\n} from './utils';\nimport { STORE_NAME as editWidgetsStoreName } from './constants';\n\nconst EMPTY_INSERTION_POINT = {\n\trootClientId: undefined,\n\tinsertionIndex: undefined,\n};\n\n/**\n * Returns all API widgets.\n *\n * @return {Object[]} API List of widgets.\n */\nexport const getWidgets = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst widgets = select( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t// Key widgets by their ID.\n\t\t\t\twidgets?.reduce(\n\t\t\t\t\t( allWidgets, widget ) => ( {\n\t\t\t\t\t\t...allWidgets,\n\t\t\t\t\t\t[ widget.id ]: widget,\n\t\t\t\t\t} ),\n\t\t\t\t\t{}\n\t\t\t\t) ?? {}\n\t\t\t);\n\t\t},\n\t\t() => [\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'root',\n\t\t\t\t'widget',\n\t\t\t\tbuildWidgetsQuery()\n\t\t\t),\n\t\t]\n\t)\n);\n\n/**\n * Returns API widget data for a particular widget ID.\n *\n * @param {number} id Widget ID.\n *\n * @return {Object} API widget data for a particular widget ID.\n */\nexport const getWidget = createRegistrySelector(\n\t( select ) => ( state, id ) => {\n\t\tconst widgets = select( editWidgetsStoreName ).getWidgets();\n\t\treturn widgets[ id ];\n\t}\n);\n\n/**\n * Returns all API widget areas.\n *\n * @return {Object[]} API List of widget areas.\n */\nexport const getWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst query = buildWidgetAreasQuery();\n\treturn select( coreStore ).getEntityRecords(\n\t\tKIND,\n\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\tquery\n\t);\n} );\n\n/**\n * Returns widgetArea containing a block identify by given widgetId\n *\n * @param {string} widgetId The ID of the widget.\n * @return {Object} Containing widget area.\n */\nexport const getWidgetAreaForWidgetId = createRegistrySelector(\n\t( select ) => ( state, widgetId ) => {\n\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\treturn widgetAreas.find( ( widgetArea ) => {\n\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\tKIND,\n\t\t\t\tPOST_TYPE,\n\t\t\t\tbuildWidgetAreaPostId( widgetArea.id )\n\t\t\t);\n\t\t\tconst blockWidgetIds = post.blocks.map( ( block ) =>\n\t\t\t\tgetWidgetIdFromBlock( block )\n\t\t\t);\n\t\t\treturn blockWidgetIds.includes( widgetId );\n\t\t} );\n\t}\n);\n\n/**\n * Given a child client id, returns the parent widget area block.\n *\n * @param {string} clientId The client id of a block in a widget area.\n *\n * @return {WPBlock} The widget area block.\n */\nexport const getParentWidgetAreaBlock = createRegistrySelector(\n\t( select ) => ( state, clientId ) => {\n\t\tconst { getBlock, getBlockName, getBlockParents } =\n\t\t\tselect( blockEditorStore );\n\t\tconst blockParents = getBlockParents( clientId );\n\t\tconst widgetAreaClientId = blockParents.find(\n\t\t\t( parentClientId ) =>\n\t\t\t\tgetBlockName( parentClientId ) === 'core/widget-area'\n\t\t);\n\t\treturn getBlock( widgetAreaClientId );\n\t}\n);\n\n/**\n * Returns all edited widget area entity records.\n *\n * @return {Object[]} List of edited widget area entity records.\n */\nexport const getEditedWidgetAreas = createRegistrySelector(\n\t( select ) => ( state, ids ) => {\n\t\tlet widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\tif ( ! widgetAreas ) {\n\t\t\treturn [];\n\t\t}\n\t\tif ( ids ) {\n\t\t\twidgetAreas = widgetAreas.filter( ( { id } ) =>\n\t\t\t\tids.includes( id )\n\t\t\t);\n\t\t}\n\t\treturn widgetAreas\n\t\t\t.filter( ( { id } ) =>\n\t\t\t\tselect( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( id )\n\t\t\t\t)\n\t\t\t)\n\t\t\t.map( ( { id } ) =>\n\t\t\t\tselect( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\t\t\tid\n\t\t\t\t)\n\t\t\t);\n\t}\n);\n\n/**\n * Returns all blocks representing reference widgets.\n *\n * @param {string} referenceWidgetName Optional. If given, only reference widgets with this name will be returned.\n * @return {Array} List of all blocks representing reference widgets\n */\nexport const getReferenceWidgetBlocks = createRegistrySelector(\n\t( select ) =>\n\t\t( state, referenceWidgetName = null ) => {\n\t\t\tconst results = [];\n\t\t\tconst widgetAreas = select( editWidgetsStoreName ).getWidgetAreas();\n\t\t\tfor ( const _widgetArea of widgetAreas ) {\n\t\t\t\tconst post = select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tKIND,\n\t\t\t\t\tPOST_TYPE,\n\t\t\t\t\tbuildWidgetAreaPostId( _widgetArea.id )\n\t\t\t\t);\n\t\t\t\tfor ( const block of post.blocks ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tblock.name === 'core/legacy-widget' &&\n\t\t\t\t\t\t( ! referenceWidgetName ||\n\t\t\t\t\t\t\tblock.attributes?.referenceWidgetName ===\n\t\t\t\t\t\t\t\treferenceWidgetName )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresults.push( block );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n);\n\n/**\n * Returns true if any widget area is currently being saved.\n *\n * @return {boolean} True if any widget area is currently being saved. False otherwise.\n */\nexport const isSavingWidgetAreas = createRegistrySelector( ( select ) => () => {\n\tconst widgetAreasIds = select( editWidgetsStoreName )\n\t\t.getWidgetAreas()\n\t\t?.map( ( { id } ) => id );\n\tif ( ! widgetAreasIds ) {\n\t\treturn false;\n\t}\n\n\tfor ( const id of widgetAreasIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\tKIND,\n\t\t\tWIDGET_AREA_ENTITY_TYPE,\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst widgetIds = [\n\t\t...Object.keys( select( editWidgetsStoreName ).getWidgets() ),\n\t\tundefined, // account for new widgets without an ID\n\t];\n\tfor ( const id of widgetIds ) {\n\t\tconst isSaving = select( coreStore ).isSavingEntityRecord(\n\t\t\t'root',\n\t\t\t'widget',\n\t\t\tid\n\t\t);\n\t\tif ( isSaving ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n} );\n\n/**\n * Gets whether the widget area is opened.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} clientId The clientId of the widget area.\n *\n * @return {boolean} True if the widget area is open.\n */\nexport const getIsWidgetAreaOpen = ( state, clientId ) => {\n\tconst { widgetAreasOpenState } = state;\n\treturn !! widgetAreasOpenState[ clientId ];\n};\n\n/**\n * Returns true if the inserter is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the inserter is opened.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID and index to insert at.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tif ( typeof state.blockInserterPanel === 'boolean' ) {\n\t\treturn EMPTY_INSERTION_POINT;\n\t}\n\n\treturn state.blockInserterPanel;\n}\n\n/**\n * Returns true if a block can be inserted into a widget area.\n *\n * @param {Array} state The open state of the widget areas.\n * @param {string} blockName The name of the block being inserted.\n *\n * @return {boolean} True if the block can be inserted in a widget area.\n */\nexport const canInsertBlockInWidgetArea = createRegistrySelector(\n\t( select ) => ( state, blockName ) => {\n\t\t// Widget areas are always top-level blocks, which getBlocks will return.\n\t\tconst widgetAreas = select( blockEditorStore ).getBlocks();\n\n\t\t// Makes an assumption that a block that can be inserted into one\n\t\t// widget area can be inserted into any widget area. Uses the first\n\t\t// widget area for testing whether the block can be inserted.\n\t\tconst [ firstWidgetArea ] = widgetAreas;\n\t\tif ( ! firstWidgetArea ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\tblockName,\n\t\t\tfirstWidgetArea.clientId\n\t\t);\n\t}\n);\n\n/**\n * Returns true if the list view is opened.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} Whether the list view is opened.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns whether widget saving is locked.\n *\n * @param {Object} state Global application state.\n *\n * @example\n * ```jsx\n * import { __ } from '@wordpress/i18n';\n * import { store as widgetStore } from '@wordpress/edit-widgets';\n * import { useSelect } from '@wordpress/data';\n *\n * const ExampleComponent = () => {\n * \tconst isSavingLocked = useSelect(\n * \t\t( select ) => select( widgetStore ).isWidgetSavingLocked(),\n * \t\t[]\n * \t);\n *\n * \treturn isSavingLocked ? (\n * \t\t<p>{ __( 'Widget saving is locked' ) }</p>\n * \t) : (\n * \t\t<p>{ __( 'Widget saving is not locked' ) }</p>\n * \t);\n * };\n * ```\n *\n * @return {boolean} Is locked.\n */\nexport function isWidgetSavingLocked( state ) {\n\treturn Object.keys( state.widgetSavingLock ).length > 0;\n}\n"],"mappings":";;;;;;;;;;;;AAcA,MAAM,wBAAwB;CAC7B,cAAc,KAAA;CACd,gBAAgB,KAAA;AACjB;;;;;;AAOA,MAAa,cAAA,GAAaA,gBAAAA,uBAAAA,EAA0B,YAAA,GACnDC,gBAAAA,eAAAA,OACO;CAOL,OANgB,OAAQC,qBAAAA,KAAU,CAAC,CAAC,iBACnC,QACA,WAAA,GACAC,WAAAA,kBAAAA,CAAkB,CAKZ,CAAC,EAAE,QACN,YAAY,YAAc;EAC3B,GAAG;GACD,OAAO,KAAM;CAChB,IACA,CAAC,CACF,KAAK,CAAC;AAER,SACM,CACL,OAAQD,qBAAAA,KAAU,CAAC,CAAC,iBACnB,QACA,WAAA,GACAC,WAAAA,kBAAAA,CAAkB,CACnB,CACD,CACD,CACD;;;;;;;;AASA,MAAa,aAAA,GAAYH,gBAAAA,uBAAAA,EACtB,YAAc,OAAO,OAAQ;CAE9B,OADgB,OAAQI,eAAAA,UAAqB,CAAC,CAAC,WAClC,CAAC,CAAE;AACjB,CACD;;;;;;AAOA,MAAa,kBAAA,GAAiBJ,gBAAAA,uBAAAA,EAA0B,iBAAkB;CACzE,MAAM,SAAA,GAAQK,WAAAA,sBAAAA,CAAsB;CACpC,OAAO,OAAQH,qBAAAA,KAAU,CAAC,CAAC,iBAC1BI,WAAAA,MACAC,WAAAA,yBACA,KACD;AACD,CAAE;;;;;;;AAQF,MAAa,4BAAA,GAA2BP,gBAAAA,uBAAAA,EACrC,YAAc,OAAO,aAAc;CAEpC,OADoB,OAAQI,eAAAA,UAAqB,CAAC,CAAC,eAClC,CAAC,CAAC,MAAQ,eAAgB;EAS1C,OARa,OAAQF,qBAAAA,KAAU,CAAC,CAAC,sBAChCI,WAAAA,MACAE,WAAAA,YAAAA,GACAC,WA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;;;;AASA,SAAgB,iBAAkB,OAAQ;CACzC,OAAO,MAAM;AACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,qBAAsB,OAAQ;CAC7C,OAAO,OAAO,KAAM,MAAM,gBAAiB,CAAC,CAAC,SAAS;AACvD"}
@@ -1,87 +1,56 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // packages/edit-widgets/src/store/transformers.js
20
- var transformers_exports = {};
21
- __export(transformers_exports, {
22
- transformBlockToWidget: () => transformBlockToWidget,
23
- transformWidgetToBlock: () => transformWidgetToBlock
1
+ "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(transformers_exports);
26
- var import_blocks = require("@wordpress/blocks");
27
- var import_widgets = require("@wordpress/widgets");
6
+ let _wordpress_blocks = require("@wordpress/blocks");
7
+ let _wordpress_widgets = require("@wordpress/widgets");
8
+ // packages/edit-widgets/src/store/transformers.js
9
+ /**
10
+ * Converts a widget entity record into a block.
11
+ *
12
+ * @param {Object} widget The widget entity record.
13
+ * @return {Object} a block (converted from the entity record).
14
+ */
28
15
  function transformWidgetToBlock(widget) {
29
- if (widget.id_base === "block") {
30
- const parsedBlocks = (0, import_blocks.parse)(widget.instance.raw.content, {
31
- __unstableSkipAutop: true
32
- });
33
- if (!parsedBlocks.length) {
34
- return (0, import_widgets.addWidgetIdToBlock)(
35
- (0, import_blocks.createBlock)("core/paragraph", {}, []),
36
- widget.id
37
- );
38
- }
39
- return (0, import_widgets.addWidgetIdToBlock)(parsedBlocks[0], widget.id);
40
- }
41
- let attributes;
42
- if (widget._embedded.about[0].is_multi) {
43
- attributes = {
44
- idBase: widget.id_base,
45
- instance: widget.instance
46
- };
47
- } else {
48
- attributes = {
49
- id: widget.id
50
- };
51
- }
52
- return (0, import_widgets.addWidgetIdToBlock)(
53
- (0, import_blocks.createBlock)("core/legacy-widget", attributes, []),
54
- widget.id
55
- );
16
+ if (widget.id_base === "block") {
17
+ const parsedBlocks = (0, _wordpress_blocks.parse)(widget.instance.raw.content, { __unstableSkipAutop: true });
18
+ if (!parsedBlocks.length) return (0, _wordpress_widgets.addWidgetIdToBlock)((0, _wordpress_blocks.createBlock)("core/paragraph", {}, []), widget.id);
19
+ return (0, _wordpress_widgets.addWidgetIdToBlock)(parsedBlocks[0], widget.id);
20
+ }
21
+ let attributes;
22
+ if (widget._embedded.about[0].is_multi) attributes = {
23
+ idBase: widget.id_base,
24
+ instance: widget.instance
25
+ };
26
+ else attributes = { id: widget.id };
27
+ return (0, _wordpress_widgets.addWidgetIdToBlock)((0, _wordpress_blocks.createBlock)("core/legacy-widget", attributes, []), widget.id);
56
28
  }
29
+ /**
30
+ * Converts a block to a widget entity record.
31
+ *
32
+ * @param {Object} block The block.
33
+ * @param {?Object} relatedWidget A related widget entity record from the API (optional).
34
+ * @return {Object} the widget object (converted from block).
35
+ */
57
36
  function transformBlockToWidget(block, relatedWidget = {}) {
58
- let widget;
59
- const isValidLegacyWidgetBlock = block.name === "core/legacy-widget" && (block.attributes.id || block.attributes.instance);
60
- if (isValidLegacyWidgetBlock) {
61
- widget = {
62
- ...relatedWidget,
63
- id: block.attributes.id ?? relatedWidget.id,
64
- id_base: block.attributes.idBase ?? relatedWidget.id_base,
65
- instance: block.attributes.instance ?? relatedWidget.instance
66
- };
67
- } else {
68
- widget = {
69
- ...relatedWidget,
70
- id_base: "block",
71
- instance: {
72
- raw: {
73
- content: (0, import_blocks.serialize)(block)
74
- }
75
- }
76
- };
77
- }
78
- delete widget.rendered;
79
- delete widget.rendered_form;
80
- return widget;
37
+ let widget;
38
+ if (block.name === "core/legacy-widget" && (block.attributes.id || block.attributes.instance)) widget = {
39
+ ...relatedWidget,
40
+ id: block.attributes.id ?? relatedWidget.id,
41
+ id_base: block.attributes.idBase ?? relatedWidget.id_base,
42
+ instance: block.attributes.instance ?? relatedWidget.instance
43
+ };
44
+ else widget = {
45
+ ...relatedWidget,
46
+ id_base: "block",
47
+ instance: { raw: { content: (0, _wordpress_blocks.serialize)(block) } }
48
+ };
49
+ delete widget.rendered;
50
+ delete widget.rendered_form;
51
+ return widget;
81
52
  }
82
- // Annotate the CommonJS export names for ESM import in node:
83
- 0 && (module.exports = {
84
- transformBlockToWidget,
85
- transformWidgetToBlock
86
- });
87
- //# sourceMappingURL=transformers.cjs.map
53
+ exports.transformBlockToWidget = transformBlockToWidget;
54
+ exports.transformWidgetToBlock = transformWidgetToBlock;
55
+
56
+ //# sourceMappingURL=transformers.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/transformers.js"],
4
- "sourcesContent": ["import { createBlock, parse, serialize } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base === 'block' ) {\n\t\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tif ( ! parsedBlocks.length ) {\n\t\t\treturn addWidgetIdToBlock(\n\t\t\t\tcreateBlock( 'core/paragraph', {}, [] ),\n\t\t\t\twidget.id\n\t\t\t);\n\t\t}\n\t\treturn addWidgetIdToBlock( parsedBlocks[ 0 ], widget.id );\n\t}\n\n\tlet attributes;\n\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\tattributes = {\n\t\t\tidBase: widget.id_base,\n\t\t\tinstance: widget.instance,\n\t\t};\n\t} else {\n\t\tattributes = {\n\t\t\tid: widget.id,\n\t\t};\n\t}\n\n\treturn addWidgetIdToBlock(\n\t\tcreateBlock( 'core/legacy-widget', attributes, [] ),\n\t\twidget.id\n\t);\n}\n\n/**\n * Converts a block to a widget entity record.\n *\n * @param {Object} block The block.\n * @param {?Object} relatedWidget A related widget entity record from the API (optional).\n * @return {Object} the widget object (converted from block).\n */\nexport function transformBlockToWidget( block, relatedWidget = {} ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid: block.attributes.id ?? relatedWidget.id,\n\t\t\tid_base: block.attributes.idBase ?? relatedWidget.id_base,\n\t\t\tinstance: block.attributes.instance ?? relatedWidget.instance,\n\t\t};\n\t} else {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid_base: 'block',\n\t\t\tinstance: {\n\t\t\t\traw: {\n\t\t\t\t\tcontent: serialize( block ),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Delete read-only properties.\n\tdelete widget.rendered;\n\tdelete widget.rendered_form;\n\n\treturn widget;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8C;AAC9C,qBAAmC;AAQ5B,SAAS,uBAAwB,QAAS;AAChD,MAAK,OAAO,YAAY,SAAU;AACjC,UAAM,mBAAe,qBAAO,OAAO,SAAS,IAAI,SAAS;AAAA,MACxD,qBAAqB;AAAA,IACtB,CAAE;AACF,QAAK,CAAE,aAAa,QAAS;AAC5B,iBAAO;AAAA,YACN,2BAAa,kBAAkB,CAAC,GAAG,CAAC,CAAE;AAAA,QACtC,OAAO;AAAA,MACR;AAAA,IACD;AACA,eAAO,mCAAoB,aAAc,CAAE,GAAG,OAAO,EAAG;AAAA,EACzD;AAEA,MAAI;AACJ,MAAK,OAAO,UAAU,MAAO,CAAE,EAAE,UAAW;AAC3C,iBAAa;AAAA,MACZ,QAAQ,OAAO;AAAA,MACf,UAAU,OAAO;AAAA,IAClB;AAAA,EACD,OAAO;AACN,iBAAa;AAAA,MACZ,IAAI,OAAO;AAAA,IACZ;AAAA,EACD;AAEA,aAAO;AAAA,QACN,2BAAa,sBAAsB,YAAY,CAAC,CAAE;AAAA,IAClD,OAAO;AAAA,EACR;AACD;AASO,SAAS,uBAAwB,OAAO,gBAAgB,CAAC,GAAI;AACnE,MAAI;AAEJ,QAAM,2BACL,MAAM,SAAS,yBACb,MAAM,WAAW,MAAM,MAAM,WAAW;AAE3C,MAAK,0BAA2B;AAC/B,aAAS;AAAA,MACR,GAAG;AAAA,MACH,IAAI,MAAM,WAAW,MAAM,cAAc;AAAA,MACzC,SAAS,MAAM,WAAW,UAAU,cAAc;AAAA,MAClD,UAAU,MAAM,WAAW,YAAY,cAAc;AAAA,IACtD;AAAA,EACD,OAAO;AACN,aAAS;AAAA,MACR,GAAG;AAAA,MACH,SAAS;AAAA,MACT,UAAU;AAAA,QACT,KAAK;AAAA,UACJ,aAAS,yBAAW,KAAM;AAAA,QAC3B;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAGA,SAAO,OAAO;AACd,SAAO,OAAO;AAEd,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"transformers.cjs","names":["parse","addWidgetIdToBlock","createBlock","serialize"],"sources":["../../src/store/transformers.js"],"sourcesContent":["import { createBlock, parse, serialize } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Converts a widget entity record into a block.\n *\n * @param {Object} widget The widget entity record.\n * @return {Object} a block (converted from the entity record).\n */\nexport function transformWidgetToBlock( widget ) {\n\tif ( widget.id_base === 'block' ) {\n\t\tconst parsedBlocks = parse( widget.instance.raw.content, {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tif ( ! parsedBlocks.length ) {\n\t\t\treturn addWidgetIdToBlock(\n\t\t\t\tcreateBlock( 'core/paragraph', {}, [] ),\n\t\t\t\twidget.id\n\t\t\t);\n\t\t}\n\t\treturn addWidgetIdToBlock( parsedBlocks[ 0 ], widget.id );\n\t}\n\n\tlet attributes;\n\tif ( widget._embedded.about[ 0 ].is_multi ) {\n\t\tattributes = {\n\t\t\tidBase: widget.id_base,\n\t\t\tinstance: widget.instance,\n\t\t};\n\t} else {\n\t\tattributes = {\n\t\t\tid: widget.id,\n\t\t};\n\t}\n\n\treturn addWidgetIdToBlock(\n\t\tcreateBlock( 'core/legacy-widget', attributes, [] ),\n\t\twidget.id\n\t);\n}\n\n/**\n * Converts a block to a widget entity record.\n *\n * @param {Object} block The block.\n * @param {?Object} relatedWidget A related widget entity record from the API (optional).\n * @return {Object} the widget object (converted from block).\n */\nexport function transformBlockToWidget( block, relatedWidget = {} ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid: block.attributes.id ?? relatedWidget.id,\n\t\t\tid_base: block.attributes.idBase ?? relatedWidget.id_base,\n\t\t\tinstance: block.attributes.instance ?? relatedWidget.instance,\n\t\t};\n\t} else {\n\t\twidget = {\n\t\t\t...relatedWidget,\n\t\t\tid_base: 'block',\n\t\t\tinstance: {\n\t\t\t\traw: {\n\t\t\t\t\tcontent: serialize( block ),\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\n\t// Delete read-only properties.\n\tdelete widget.rendered;\n\tdelete widget.rendered_form;\n\n\treturn widget;\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAgB,uBAAwB,QAAS;CAChD,IAAK,OAAO,YAAY,SAAU;EACjC,MAAM,gBAAA,GAAeA,kBAAAA,MAAAA,CAAO,OAAO,SAAS,IAAI,SAAS,EACxD,qBAAqB,KACtB,CAAE;EACF,IAAK,CAAE,aAAa,QACnB,QAAA,GAAOC,mBAAAA,mBAAAA,EAAAA,GACNC,kBAAAA,YAAAA,CAAa,kBAAkB,CAAC,GAAG,CAAC,CAAE,GACtC,OAAO,EACR;EAED,QAAA,GAAOD,mBAAAA,mBAAAA,CAAoB,aAAc,IAAK,OAAO,EAAG;CACzD;CAEA,IAAI;CACJ,IAAK,OAAO,UAAU,MAAO,EAAG,CAAC,UAChC,aAAa;EACZ,QAAQ,OAAO;EACf,UAAU,OAAO;CAClB;MAEA,aAAa,EACZ,IAAI,OAAO,GACZ;CAGD,QAAA,GAAOA,mBAAAA,mBAAAA,EAAAA,GACNC,kBAAAA,YAAAA,CAAa,sBAAsB,YAAY,CAAC,CAAE,GAClD,OAAO,EACR;AACD;;;;;;;;AASA,SAAgB,uBAAwB,OAAO,gBAAgB,CAAC,GAAI;CACnE,IAAI;CAMJ,IAHC,MAAM,SAAS,yBACb,MAAM,WAAW,MAAM,MAAM,WAAW,WAG1C,SAAS;EACR,GAAG;EACH,IAAI,MAAM,WAAW,MAAM,cAAc;EACzC,SAAS,MAAM,WAAW,UAAU,cAAc;EAClD,UAAU,MAAM,WAAW,YAAY,cAAc;CACtD;MAEA,SAAS;EACR,GAAG;EACH,SAAS;EACT,UAAU,EACT,KAAK,EACJ,UAAA,GAASC,kBAAAA,UAAAA,CAAW,KAAM,EAC3B,EACD;CACD;CAID,OAAO,OAAO;CACd,OAAO,OAAO;CAEd,OAAO;AACR"}
@@ -1,69 +1,82 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // packages/edit-widgets/src/store/utils.js
20
- var utils_exports = {};
21
- __export(utils_exports, {
22
- KIND: () => KIND,
23
- POST_TYPE: () => POST_TYPE,
24
- WIDGET_AREA_ENTITY_TYPE: () => WIDGET_AREA_ENTITY_TYPE,
25
- buildWidgetAreaPostId: () => buildWidgetAreaPostId,
26
- buildWidgetAreasPostId: () => buildWidgetAreasPostId,
27
- buildWidgetAreasQuery: () => buildWidgetAreasQuery,
28
- buildWidgetsQuery: () => buildWidgetsQuery,
29
- createStubPost: () => createStubPost
1
+ "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
30
5
  });
31
- module.exports = __toCommonJS(utils_exports);
32
- var KIND = "root";
33
- var WIDGET_AREA_ENTITY_TYPE = "sidebar";
34
- var POST_TYPE = "postType";
35
- var buildWidgetAreaPostId = (widgetAreaId) => `widget-area-${widgetAreaId}`;
36
- var buildWidgetAreasPostId = () => `widget-areas`;
6
+ // packages/edit-widgets/src/store/utils.js
7
+ /**
8
+ * "Kind" of the navigation post.
9
+ *
10
+ * @type {string}
11
+ */
12
+ const KIND = "root";
13
+ /**
14
+ * "post type" of the navigation post.
15
+ *
16
+ * @type {string}
17
+ */
18
+ const WIDGET_AREA_ENTITY_TYPE = "sidebar";
19
+ /**
20
+ * "post type" of the widget area post.
21
+ *
22
+ * @type {string}
23
+ */
24
+ const POST_TYPE = "postType";
25
+ /**
26
+ * Builds an ID for a new widget area post.
27
+ *
28
+ * @param {number} widgetAreaId Widget area id.
29
+ * @return {string} An ID.
30
+ */
31
+ const buildWidgetAreaPostId = (widgetAreaId) => `widget-area-${widgetAreaId}`;
32
+ /**
33
+ * Builds an ID for a global widget areas post.
34
+ *
35
+ * @return {string} An ID.
36
+ */
37
+ const buildWidgetAreasPostId = () => `widget-areas`;
38
+ /**
39
+ * Builds a query to resolve sidebars.
40
+ *
41
+ * @return {Object} Query.
42
+ */
37
43
  function buildWidgetAreasQuery() {
38
- return {
39
- per_page: -1
40
- };
44
+ return { per_page: -1 };
41
45
  }
46
+ /**
47
+ * Builds a query to resolve widgets.
48
+ *
49
+ * @return {Object} Query.
50
+ */
42
51
  function buildWidgetsQuery() {
43
- return {
44
- per_page: -1,
45
- _embed: "about"
46
- };
52
+ return {
53
+ per_page: -1,
54
+ _embed: "about"
55
+ };
47
56
  }
48
- var createStubPost = (id, blocks) => ({
49
- id,
50
- slug: id,
51
- status: "draft",
52
- type: "page",
53
- blocks,
54
- meta: {
55
- widgetAreaId: id
56
- }
57
+ /**
58
+ * Creates a stub post with given id and set of blocks. Used as a governing entity records
59
+ * for all widget areas.
60
+ *
61
+ * @param {string} id Post ID.
62
+ * @param {Array} blocks The list of blocks.
63
+ * @return {Object} A stub post object formatted in compliance with the data layer.
64
+ */
65
+ const createStubPost = (id, blocks) => ({
66
+ id,
67
+ slug: id,
68
+ status: "draft",
69
+ type: "page",
70
+ blocks,
71
+ meta: { widgetAreaId: id }
57
72
  });
58
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- KIND,
61
- POST_TYPE,
62
- WIDGET_AREA_ENTITY_TYPE,
63
- buildWidgetAreaPostId,
64
- buildWidgetAreasPostId,
65
- buildWidgetAreasQuery,
66
- buildWidgetsQuery,
67
- createStubPost
68
- });
69
- //# sourceMappingURL=utils.cjs.map
73
+ exports.KIND = KIND;
74
+ exports.POST_TYPE = POST_TYPE;
75
+ exports.WIDGET_AREA_ENTITY_TYPE = WIDGET_AREA_ENTITY_TYPE;
76
+ exports.buildWidgetAreaPostId = buildWidgetAreaPostId;
77
+ exports.buildWidgetAreasPostId = buildWidgetAreasPostId;
78
+ exports.buildWidgetAreasQuery = buildWidgetAreasQuery;
79
+ exports.buildWidgetsQuery = buildWidgetsQuery;
80
+ exports.createStubPost = createStubPost;
81
+
82
+ //# sourceMappingURL=utils.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/store/utils.js"],
4
- "sourcesContent": ["/**\n * \"Kind\" of the navigation post.\n *\n * @type {string}\n */\nexport const KIND = 'root';\n\n/**\n * \"post type\" of the navigation post.\n *\n * @type {string}\n */\nexport const WIDGET_AREA_ENTITY_TYPE = 'sidebar';\n\n/**\n * \"post type\" of the widget area post.\n *\n * @type {string}\n */\nexport const POST_TYPE = 'postType';\n\n/**\n * Builds an ID for a new widget area post.\n *\n * @param {number} widgetAreaId Widget area id.\n * @return {string} An ID.\n */\nexport const buildWidgetAreaPostId = ( widgetAreaId ) =>\n\t`widget-area-${ widgetAreaId }`;\n\n/**\n * Builds an ID for a global widget areas post.\n *\n * @return {string} An ID.\n */\nexport const buildWidgetAreasPostId = () => `widget-areas`;\n\n/**\n * Builds a query to resolve sidebars.\n *\n * @return {Object} Query.\n */\nexport function buildWidgetAreasQuery() {\n\treturn {\n\t\tper_page: -1,\n\t};\n}\n\n/**\n * Builds a query to resolve widgets.\n *\n * @return {Object} Query.\n */\nexport function buildWidgetsQuery() {\n\treturn {\n\t\tper_page: -1,\n\t\t_embed: 'about',\n\t};\n}\n\n/**\n * Creates a stub post with given id and set of blocks. Used as a governing entity records\n * for all widget areas.\n *\n * @param {string} id Post ID.\n * @param {Array} blocks The list of blocks.\n * @return {Object} A stub post object formatted in compliance with the data layer.\n */\nexport const createStubPost = ( id, blocks ) => ( {\n\tid,\n\tslug: id,\n\tstatus: 'draft',\n\ttype: 'page',\n\tblocks,\n\tmeta: {\n\t\twidgetAreaId: id,\n\t},\n} );\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,OAAO;AAOb,IAAM,0BAA0B;AAOhC,IAAM,YAAY;AAQlB,IAAM,wBAAwB,CAAE,iBACtC,eAAgB,YAAa;AAOvB,IAAM,yBAAyB,MAAM;AAOrC,SAAS,wBAAwB;AACvC,SAAO;AAAA,IACN,UAAU;AAAA,EACX;AACD;AAOO,SAAS,oBAAoB;AACnC,SAAO;AAAA,IACN,UAAU;AAAA,IACV,QAAQ;AAAA,EACT;AACD;AAUO,IAAM,iBAAiB,CAAE,IAAI,YAAc;AAAA,EACjD;AAAA,EACA,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN;AAAA,EACA,MAAM;AAAA,IACL,cAAc;AAAA,EACf;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"utils.cjs","names":[],"sources":["../../src/store/utils.js"],"sourcesContent":["/**\n * \"Kind\" of the navigation post.\n *\n * @type {string}\n */\nexport const KIND = 'root';\n\n/**\n * \"post type\" of the navigation post.\n *\n * @type {string}\n */\nexport const WIDGET_AREA_ENTITY_TYPE = 'sidebar';\n\n/**\n * \"post type\" of the widget area post.\n *\n * @type {string}\n */\nexport const POST_TYPE = 'postType';\n\n/**\n * Builds an ID for a new widget area post.\n *\n * @param {number} widgetAreaId Widget area id.\n * @return {string} An ID.\n */\nexport const buildWidgetAreaPostId = ( widgetAreaId ) =>\n\t`widget-area-${ widgetAreaId }`;\n\n/**\n * Builds an ID for a global widget areas post.\n *\n * @return {string} An ID.\n */\nexport const buildWidgetAreasPostId = () => `widget-areas`;\n\n/**\n * Builds a query to resolve sidebars.\n *\n * @return {Object} Query.\n */\nexport function buildWidgetAreasQuery() {\n\treturn {\n\t\tper_page: -1,\n\t};\n}\n\n/**\n * Builds a query to resolve widgets.\n *\n * @return {Object} Query.\n */\nexport function buildWidgetsQuery() {\n\treturn {\n\t\tper_page: -1,\n\t\t_embed: 'about',\n\t};\n}\n\n/**\n * Creates a stub post with given id and set of blocks. Used as a governing entity records\n * for all widget areas.\n *\n * @param {string} id Post ID.\n * @param {Array} blocks The list of blocks.\n * @return {Object} A stub post object formatted in compliance with the data layer.\n */\nexport const createStubPost = ( id, blocks ) => ( {\n\tid,\n\tslug: id,\n\tstatus: 'draft',\n\ttype: 'page',\n\tblocks,\n\tmeta: {\n\t\twidgetAreaId: id,\n\t},\n} );\n"],"mappings":";;;;;;;;;;;AAKA,MAAa,OAAO;;;;;;AAOpB,MAAa,0BAA0B;;;;;;AAOvC,MAAa,YAAY;;;;;;;AAQzB,MAAa,yBAA0B,iBACtC,eAAgB;;;;;;AAOjB,MAAa,+BAA+B;;;;;;AAO5C,SAAgB,wBAAwB;CACvC,OAAO,EACN,UAAU,GACX;AACD;;;;;;AAOA,SAAgB,oBAAoB;CACnC,OAAO;EACN,UAAU;EACV,QAAQ;CACT;AACD;;;;;;;;;AAUA,MAAa,kBAAmB,IAAI,YAAc;CACjD;CACA,MAAM;CACN,QAAQ;CACR,MAAM;CACN;CACA,MAAM,EACL,cAAc,GACf;AACD"}
@@ -1,101 +1,89 @@
1
- // packages/edit-widgets/src/blocks/widget-area/edit/index.jsx
2
- import { useEffect, useState, useCallback, useRef } from "@wordpress/element";
3
- import { useSelect, useDispatch } from "@wordpress/data";
1
+ import { useCallback, useEffect, useRef, useState } from "@wordpress/element";
2
+ import { useDispatch, useSelect } from "@wordpress/data";
4
3
  import { EntityProvider } from "@wordpress/core-data";
5
- import {
6
- __unstableDisclosureContent as DisclosureContent,
7
- Panel,
8
- PanelBody
9
- } from "@wordpress/components";
4
+ import { Panel, PanelBody, __unstableDisclosureContent } from "@wordpress/components";
10
5
  import { useBlockProps } from "@wordpress/block-editor";
11
6
  import WidgetAreaInnerBlocks from "./inner-blocks.mjs";
12
- import { store as editWidgetsStore } from "../../../store/index.mjs";
7
+ import { store } from "../../../store/index.mjs";
13
8
  import useIsDraggingWithin from "./use-is-dragging-within.mjs";
14
9
  import { jsx } from "react/jsx-runtime";
15
- function WidgetAreaEdit({
16
- clientId,
17
- attributes: { id, name }
18
- }) {
19
- const isOpen = useSelect(
20
- (select) => select(editWidgetsStore).getIsWidgetAreaOpen(clientId),
21
- [clientId]
22
- );
23
- const { setIsWidgetAreaOpen } = useDispatch(editWidgetsStore);
24
- const wrapper = useRef();
25
- const setOpen = useCallback(
26
- (openState) => setIsWidgetAreaOpen(clientId, openState),
27
- [clientId]
28
- );
29
- const isDragging = useIsDragging(wrapper);
30
- const isDraggingWithin = useIsDraggingWithin(wrapper);
31
- const [openedWhileDragging, setOpenedWhileDragging] = useState(false);
32
- useEffect(() => {
33
- if (!isDragging) {
34
- setOpenedWhileDragging(false);
35
- return;
36
- }
37
- if (isDraggingWithin && !isOpen) {
38
- setOpen(true);
39
- setOpenedWhileDragging(true);
40
- } else if (!isDraggingWithin && isOpen && openedWhileDragging) {
41
- setOpen(false);
42
- }
43
- }, [isOpen, isDragging, isDraggingWithin, openedWhileDragging]);
44
- const blockProps = useBlockProps();
45
- return /* @__PURE__ */ jsx("div", { ...blockProps, children: /* @__PURE__ */ jsx(Panel, { ref: wrapper, children: /* @__PURE__ */ jsx(
46
- PanelBody,
47
- {
48
- title: name,
49
- opened: isOpen,
50
- onToggle: () => {
51
- setIsWidgetAreaOpen(clientId, !isOpen);
52
- },
53
- scrollAfterOpen: !isDragging,
54
- children: ({ opened }) => (
55
- // This is required to ensure LegacyWidget blocks are not
56
- // unmounted when the panel is collapsed. Unmounting legacy
57
- // widgets may have unintended consequences (e.g. TinyMCE
58
- // not being properly reinitialized)
59
- /* @__PURE__ */ jsx(
60
- DisclosureContent,
61
- {
62
- className: "wp-block-widget-area__panel-body-content",
63
- visible: opened,
64
- children: /* @__PURE__ */ jsx(
65
- EntityProvider,
66
- {
67
- kind: "root",
68
- type: "postType",
69
- id: `widget-area-${id}`,
70
- children: /* @__PURE__ */ jsx(WidgetAreaInnerBlocks, { id })
71
- }
72
- )
73
- }
74
- )
75
- )
76
- }
77
- ) }) });
10
+ // packages/edit-widgets/src/blocks/widget-area/edit/index.jsx
11
+ /** @typedef {import('@wordpress/element').RefObject} RefObject */
12
+ function WidgetAreaEdit({ clientId, attributes: { id, name } }) {
13
+ const isOpen = useSelect((select) => select(store).getIsWidgetAreaOpen(clientId), [clientId]);
14
+ const { setIsWidgetAreaOpen } = useDispatch(store);
15
+ const wrapper = useRef();
16
+ const setOpen = useCallback((openState) => setIsWidgetAreaOpen(clientId, openState), [clientId]);
17
+ const isDragging = useIsDragging(wrapper);
18
+ const isDraggingWithin = useIsDraggingWithin(wrapper);
19
+ const [openedWhileDragging, setOpenedWhileDragging] = useState(false);
20
+ useEffect(() => {
21
+ if (!isDragging) {
22
+ setOpenedWhileDragging(false);
23
+ return;
24
+ }
25
+ if (isDraggingWithin && !isOpen) {
26
+ setOpen(true);
27
+ setOpenedWhileDragging(true);
28
+ } else if (!isDraggingWithin && isOpen && openedWhileDragging) setOpen(false);
29
+ }, [
30
+ isOpen,
31
+ isDragging,
32
+ isDraggingWithin,
33
+ openedWhileDragging
34
+ ]);
35
+ const blockProps = useBlockProps();
36
+ return /* @__PURE__ */ jsx("div", {
37
+ ...blockProps,
38
+ children: /* @__PURE__ */ jsx(Panel, {
39
+ ref: wrapper,
40
+ children: /* @__PURE__ */ jsx(PanelBody, {
41
+ title: name,
42
+ opened: isOpen,
43
+ onToggle: () => {
44
+ setIsWidgetAreaOpen(clientId, !isOpen);
45
+ },
46
+ scrollAfterOpen: !isDragging,
47
+ children: ({ opened }) => /* @__PURE__ */ jsx(__unstableDisclosureContent, {
48
+ className: "wp-block-widget-area__panel-body-content",
49
+ visible: opened,
50
+ children: /* @__PURE__ */ jsx(EntityProvider, {
51
+ kind: "root",
52
+ type: "postType",
53
+ id: `widget-area-${id}`,
54
+ children: /* @__PURE__ */ jsx(WidgetAreaInnerBlocks, { id })
55
+ })
56
+ })
57
+ })
58
+ })
59
+ });
78
60
  }
79
- var useIsDragging = (elementRef) => {
80
- const [isDragging, setIsDragging] = useState(false);
81
- useEffect(() => {
82
- const { ownerDocument } = elementRef.current;
83
- function handleDragStart() {
84
- setIsDragging(true);
85
- }
86
- function handleDragEnd() {
87
- setIsDragging(false);
88
- }
89
- ownerDocument.addEventListener("dragstart", handleDragStart);
90
- ownerDocument.addEventListener("dragend", handleDragEnd);
91
- return () => {
92
- ownerDocument.removeEventListener("dragstart", handleDragStart);
93
- ownerDocument.removeEventListener("dragend", handleDragEnd);
94
- };
95
- }, []);
96
- return isDragging;
97
- };
98
- export {
99
- WidgetAreaEdit as default
61
+ /**
62
+ * A React hook to determine if dragging is active.
63
+ *
64
+ * @param {RefObject<HTMLElement>} elementRef The target elementRef object.
65
+ *
66
+ * @return {boolean} Is dragging within the entire document.
67
+ */
68
+ const useIsDragging = (elementRef) => {
69
+ const [isDragging, setIsDragging] = useState(false);
70
+ useEffect(() => {
71
+ const { ownerDocument } = elementRef.current;
72
+ function handleDragStart() {
73
+ setIsDragging(true);
74
+ }
75
+ function handleDragEnd() {
76
+ setIsDragging(false);
77
+ }
78
+ ownerDocument.addEventListener("dragstart", handleDragStart);
79
+ ownerDocument.addEventListener("dragend", handleDragEnd);
80
+ return () => {
81
+ ownerDocument.removeEventListener("dragstart", handleDragStart);
82
+ ownerDocument.removeEventListener("dragend", handleDragEnd);
83
+ };
84
+ }, []);
85
+ return isDragging;
100
86
  };
101
- //# sourceMappingURL=index.mjs.map
87
+ export { WidgetAreaEdit as default };
88
+
89
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/blocks/widget-area/edit/index.jsx"],
4
- "sourcesContent": ["import { useEffect, useState, useCallback, useRef } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { EntityProvider } from '@wordpress/core-data';\nimport {\n\t__unstableDisclosureContent as DisclosureContent,\n\tPanel,\n\tPanelBody,\n} from '@wordpress/components';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport WidgetAreaInnerBlocks from './inner-blocks';\nimport { store as editWidgetsStore } from '../../../store';\nimport useIsDraggingWithin from './use-is-dragging-within';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n\nexport default function WidgetAreaEdit( {\n\tclientId,\n\tattributes: { id, name },\n} ) {\n\tconst isOpen = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editWidgetsStore ).getIsWidgetAreaOpen( clientId ),\n\t\t[ clientId ]\n\t);\n\tconst { setIsWidgetAreaOpen } = useDispatch( editWidgetsStore );\n\n\tconst wrapper = useRef();\n\tconst setOpen = useCallback(\n\t\t( openState ) => setIsWidgetAreaOpen( clientId, openState ),\n\t\t[ clientId ]\n\t);\n\tconst isDragging = useIsDragging( wrapper );\n\tconst isDraggingWithin = useIsDraggingWithin( wrapper );\n\n\tconst [ openedWhileDragging, setOpenedWhileDragging ] = useState( false );\n\tuseEffect( () => {\n\t\tif ( ! isDragging ) {\n\t\t\tsetOpenedWhileDragging( false );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isDraggingWithin && ! isOpen ) {\n\t\t\tsetOpen( true );\n\t\t\tsetOpenedWhileDragging( true );\n\t\t} else if ( ! isDraggingWithin && isOpen && openedWhileDragging ) {\n\t\t\tsetOpen( false );\n\t\t}\n\t}, [ isOpen, isDragging, isDraggingWithin, openedWhileDragging ] );\n\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Panel ref={ wrapper }>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ name }\n\t\t\t\t\topened={ isOpen }\n\t\t\t\t\tonToggle={ () => {\n\t\t\t\t\t\tsetIsWidgetAreaOpen( clientId, ! isOpen );\n\t\t\t\t\t} }\n\t\t\t\t\tscrollAfterOpen={ ! isDragging }\n\t\t\t\t>\n\t\t\t\t\t{ ( { opened } ) => (\n\t\t\t\t\t\t// This is required to ensure LegacyWidget blocks are not\n\t\t\t\t\t\t// unmounted when the panel is collapsed. Unmounting legacy\n\t\t\t\t\t\t// widgets may have unintended consequences (e.g. TinyMCE\n\t\t\t\t\t\t// not being properly reinitialized)\n\t\t\t\t\t\t<DisclosureContent\n\t\t\t\t\t\t\tclassName=\"wp-block-widget-area__panel-body-content\"\n\t\t\t\t\t\t\tvisible={ opened }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<EntityProvider\n\t\t\t\t\t\t\t\tkind=\"root\"\n\t\t\t\t\t\t\t\ttype=\"postType\"\n\t\t\t\t\t\t\t\tid={ `widget-area-${ id }` }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<WidgetAreaInnerBlocks id={ id } />\n\t\t\t\t\t\t\t</EntityProvider>\n\t\t\t\t\t\t</DisclosureContent>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</Panel>\n\t\t</div>\n\t);\n}\n\n/**\n * A React hook to determine if dragging is active.\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the entire document.\n */\nconst useIsDragging = ( elementRef ) => {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart() {\n\t\t\tsetIsDragging( true );\n\t\t}\n\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDragging( false );\n\t\t}\n\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t};\n\t}, [] );\n\n\treturn isDragging;\n};\n"],
5
- "mappings": ";AAAA,SAAS,WAAW,UA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B,WAAE,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,QAKZ;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,SAAU;AAAA,YAEV;AAAA,cAAC;AAAA;AAAA,gBACA,MAAK;AAAA,gBACL,MAAK;AAAA,gBACL,IAAK,eAAgB,EAAG;AAAA,gBAExB,8BAAC,yBAAsB,IAAU;AAAA;AAAA,YAClC;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF,GACD,GACD;AAEF;AASA,IAAM,gBAAgB,CAAE,eAAgB;AACvC,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AAEtD,YAAW,MAAM;AAChB,UAAM,EAAE,cAAc,IAAI,WAAW;AAErC,aAAS,kBAAkB;AAC1B,oBAAe,IAAK;AAAA,IACrB;AAEA,aAAS,gBAAgB;AACxB,oBAAe,KAAM;AAAA,IACtB;AAEA,kBAAc,iBAAkB,aAAa,eAAgB;AAC7D,kBAAc,iBAAkB,WAAW,aAAc;AAEzD,WAAO,MAAM;AACZ,oBAAc,oBAAqB,aAAa,eAAgB;AAChE,oBAAc,oBAAqB,WAAW,aAAc;AAAA,IAC7D;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":["editWidgetsStore","DisclosureContent"],"sources":["../../../../src/blocks/widget-area/edit/index.jsx"],"sourcesContent":["import { useEffect, useState, useCallback, useRef } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { EntityProvider } from '@wordpress/core-data';\nimport {\n\t__unstableDisclosureContent as DisclosureContent,\n\tPanel,\n\tPanelBody,\n} from '@wordpress/components';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport WidgetAreaInnerBlocks from './inner-blocks';\nimport { store as editWidgetsStore } from '../../../store';\nimport useIsDraggingWithin from './use-is-dragging-within';\n\n/** @typedef {import('@wordpress/element').RefObject} RefObject */\n\nexport default function WidgetAreaEdit( {\n\tclientId,\n\tattributes: { id, name },\n} ) {\n\tconst isOpen = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editWidgetsStore ).getIsWidgetAreaOpen( clientId ),\n\t\t[ clientId ]\n\t);\n\tconst { setIsWidgetAreaOpen } = useDispatch( editWidgetsStore );\n\n\tconst wrapper = useRef();\n\tconst setOpen = useCallback(\n\t\t( openState ) => setIsWidgetAreaOpen( clientId, openState ),\n\t\t[ clientId ]\n\t);\n\tconst isDragging = useIsDragging( wrapper );\n\tconst isDraggingWithin = useIsDraggingWithin( wrapper );\n\n\tconst [ openedWhileDragging, setOpenedWhileDragging ] = useState( false );\n\tuseEffect( () => {\n\t\tif ( ! isDragging ) {\n\t\t\tsetOpenedWhileDragging( false );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isDraggingWithin && ! isOpen ) {\n\t\t\tsetOpen( true );\n\t\t\tsetOpenedWhileDragging( true );\n\t\t} else if ( ! isDraggingWithin && isOpen && openedWhileDragging ) {\n\t\t\tsetOpen( false );\n\t\t}\n\t}, [ isOpen, isDragging, isDraggingWithin, openedWhileDragging ] );\n\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Panel ref={ wrapper }>\n\t\t\t\t<PanelBody\n\t\t\t\t\ttitle={ name }\n\t\t\t\t\topened={ isOpen }\n\t\t\t\t\tonToggle={ () => {\n\t\t\t\t\t\tsetIsWidgetAreaOpen( clientId, ! isOpen );\n\t\t\t\t\t} }\n\t\t\t\t\tscrollAfterOpen={ ! isDragging }\n\t\t\t\t>\n\t\t\t\t\t{ ( { opened } ) => (\n\t\t\t\t\t\t// This is required to ensure LegacyWidget blocks are not\n\t\t\t\t\t\t// unmounted when the panel is collapsed. Unmounting legacy\n\t\t\t\t\t\t// widgets may have unintended consequences (e.g. TinyMCE\n\t\t\t\t\t\t// not being properly reinitialized)\n\t\t\t\t\t\t<DisclosureContent\n\t\t\t\t\t\t\tclassName=\"wp-block-widget-area__panel-body-content\"\n\t\t\t\t\t\t\tvisible={ opened }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<EntityProvider\n\t\t\t\t\t\t\t\tkind=\"root\"\n\t\t\t\t\t\t\t\ttype=\"postType\"\n\t\t\t\t\t\t\t\tid={ `widget-area-${ id }` }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<WidgetAreaInnerBlocks id={ id } />\n\t\t\t\t\t\t\t</EntityProvider>\n\t\t\t\t\t\t</DisclosureContent>\n\t\t\t\t\t) }\n\t\t\t\t</PanelBody>\n\t\t\t</Panel>\n\t\t</div>\n\t);\n}\n\n/**\n * A React hook to determine if dragging is active.\n *\n * @param {RefObject<HTMLElement>} elementRef The target elementRef object.\n *\n * @return {boolean} Is dragging within the entire document.\n */\nconst useIsDragging = ( elementRef ) => {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tuseEffect( () => {\n\t\tconst { ownerDocument } = elementRef.current;\n\n\t\tfunction handleDragStart() {\n\t\t\tsetIsDragging( true );\n\t\t}\n\n\t\tfunction handleDragEnd() {\n\t\t\tsetIsDragging( false );\n\t\t}\n\n\t\townerDocument.addEventListener( 'dragstart', handleDragStart );\n\t\townerDocument.addEventListener( 'dragend', handleDragEnd );\n\n\t\treturn () => {\n\t\t\townerDocument.removeEventListener( 'dragstart', handleDragStart );\n\t\t\townerDocument.removeEventListener( 'dragend', handleDragEnd );\n\t\t};\n\t}, [] );\n\n\treturn isDragging;\n};\n"],"mappings":";;;;;;;;;;;AAeA,SAAwB,eAAgB,EACvC,UACA,YAAY,EAAE,IAAI,UACf;CACH,MAAM,SAAS,WACZ,WACD,OAAQA,KAAiB,CAAC,CAAC,oBAAqB,QAAS,GAC1D,CAAE,QAAS,CACZ;CACA,MAAM,EAAE,wBAAwB,YAAaA,KAAiB;CAE9D,MAAM,UAAU,OAAO;CACvB,MAAM,UAAU,aACb,cAAe,oBAAqB,UAAU,SAAU,GAC1D,CAAE,QAAS,CACZ;CACA,MAAM,aA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